summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/files/cacerts.bksbin113861 -> 142973 bytes
-rw-r--r--luni/src/main/files/cacerts/0d188d89.080
-rw-r--r--luni/src/main/files/cacerts/119afc2e.098
-rw-r--r--luni/src/main/files/cacerts/1eb37bdf.0140
-rw-r--r--luni/src/main/files/cacerts/256fd83b.063
-rw-r--r--luni/src/main/files/cacerts/27af790d.055
-rw-r--r--luni/src/main/files/cacerts/3d441de8.0125
-rw-r--r--luni/src/main/files/cacerts/418595b9.087
-rw-r--r--luni/src/main/files/cacerts/524d9b43.088
-rw-r--r--luni/src/main/files/cacerts/54edfa5d.063
-rw-r--r--luni/src/main/files/cacerts/5e4e69e7.061
-rw-r--r--luni/src/main/files/cacerts/60afe812.082
-rw-r--r--luni/src/main/files/cacerts/67495436.083
-rw-r--r--luni/src/main/files/cacerts/72f369af.077
-rw-r--r--luni/src/main/files/cacerts/7651b327.036
-rw-r--r--luni/src/main/files/cacerts/882de061.078
-rw-r--r--luni/src/main/files/cacerts/895cad1a.082
-rw-r--r--luni/src/main/files/cacerts/89c02a45.054
-rw-r--r--luni/src/main/files/cacerts/9685a493.075
-rw-r--r--luni/src/main/files/cacerts/9d6523ce.0123
-rw-r--r--luni/src/main/files/cacerts/9f533518.0139
-rw-r--r--luni/src/main/files/cacerts/a7d2cf64.054
-rw-r--r--luni/src/main/files/cacerts/ab5346f4.078
-rw-r--r--luni/src/main/files/cacerts/c7e2a638.082
-rw-r--r--luni/src/main/files/cacerts/d16a5865.0130
-rw-r--r--luni/src/main/files/cacerts/d64f06f3.090
-rw-r--r--luni/src/main/files/cacerts/e8651083.087
-rw-r--r--luni/src/main/files/cacerts/ea169617.0129
-rw-r--r--luni/src/main/files/cacerts/eb375c3e.077
-rw-r--r--luni/src/main/files/cacerts/f80cc7f6.0126
-rw-r--r--luni/src/main/files/cacerts/fac084d7.081
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java318
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java431
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java40
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java143
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java205
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java40
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java220
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/CollationKey.java122
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/Collator.java247
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java161
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/NativeCollation.java228
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java643
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java546
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/util/ICU.java155
-rw-r--r--luni/src/main/java/com/ibm/icu4jni/util/LocaleData.java343
-rw-r--r--luni/src/main/java/java/awt/font/TextAttribute.java28
-rw-r--r--luni/src/main/java/java/beans/PropertyChangeSupport.java437
-rw-r--r--luni/src/main/java/java/io/BufferedInputStream.java75
-rw-r--r--luni/src/main/java/java/io/BufferedOutputStream.java13
-rw-r--r--luni/src/main/java/java/io/BufferedReader.java41
-rw-r--r--luni/src/main/java/java/io/BufferedWriter.java15
-rw-r--r--luni/src/main/java/java/io/ByteArrayInputStream.java38
-rw-r--r--luni/src/main/java/java/io/ByteArrayOutputStream.java19
-rw-r--r--luni/src/main/java/java/io/CharArrayReader.java30
-rw-r--r--luni/src/main/java/java/io/CharArrayWriter.java57
-rw-r--r--luni/src/main/java/java/io/Closeable.java11
-rw-r--r--luni/src/main/java/java/io/DataInput.java68
-rw-r--r--luni/src/main/java/java/io/DataInputStream.java290
-rw-r--r--luni/src/main/java/java/io/DataOutput.java32
-rw-r--r--luni/src/main/java/java/io/DataOutputStream.java227
-rw-r--r--luni/src/main/java/java/io/EmulatedFieldsForDumping.java41
-rw-r--r--luni/src/main/java/java/io/File.java208
-rw-r--r--luni/src/main/java/java/io/FileInputStream.java271
-rw-r--r--luni/src/main/java/java/io/FileOutputStream.java297
-rw-r--r--luni/src/main/java/java/io/FilterInputStream.java12
-rw-r--r--luni/src/main/java/java/io/FilterOutputStream.java12
-rw-r--r--luni/src/main/java/java/io/FilterReader.java10
-rw-r--r--luni/src/main/java/java/io/InputStream.java20
-rw-r--r--luni/src/main/java/java/io/InputStreamReader.java13
-rw-r--r--luni/src/main/java/java/io/LineNumberInputStream.java31
-rw-r--r--luni/src/main/java/java/io/LineNumberReader.java20
-rw-r--r--luni/src/main/java/java/io/ObjectInput.java7
-rw-r--r--luni/src/main/java/java/io/ObjectInputStream.java664
-rw-r--r--luni/src/main/java/java/io/ObjectOutputStream.java522
-rw-r--r--luni/src/main/java/java/io/ObjectStreamClass.java325
-rw-r--r--luni/src/main/java/java/io/ObjectStreamField.java110
-rw-r--r--luni/src/main/java/java/io/OutputStream.java20
-rw-r--r--luni/src/main/java/java/io/OutputStreamWriter.java17
-rw-r--r--luni/src/main/java/java/io/PipedInputStream.java35
-rw-r--r--luni/src/main/java/java/io/PipedReader.java32
-rw-r--r--luni/src/main/java/java/io/PipedWriter.java10
-rw-r--r--luni/src/main/java/java/io/PrintStream.java26
-rw-r--r--luni/src/main/java/java/io/PrintWriter.java11
-rw-r--r--luni/src/main/java/java/io/PushbackInputStream.java32
-rw-r--r--luni/src/main/java/java/io/PushbackReader.java47
-rw-r--r--luni/src/main/java/java/io/RandomAccessFile.java346
-rw-r--r--luni/src/main/java/java/io/Reader.java27
-rw-r--r--luni/src/main/java/java/io/SequenceInputStream.java15
-rw-r--r--luni/src/main/java/java/io/SerializationHandleMap.java173
-rw-r--r--luni/src/main/java/java/io/StreamTokenizer.java6
-rw-r--r--luni/src/main/java/java/io/StringBufferInputStream.java35
-rw-r--r--luni/src/main/java/java/io/StringReader.java30
-rw-r--r--luni/src/main/java/java/io/StringWriter.java27
-rw-r--r--luni/src/main/java/java/io/Writer.java25
-rw-r--r--luni/src/main/java/java/lang/AbstractStringBuilder.java120
-rw-r--r--luni/src/main/java/java/lang/Byte.java43
-rw-r--r--luni/src/main/java/java/lang/CaseMapper.java12
-rw-r--r--luni/src/main/java/java/lang/Character.java115
-rw-r--r--luni/src/main/java/java/lang/Class.java77
-rw-r--r--luni/src/main/java/java/lang/ClassCache.java47
-rw-r--r--luni/src/main/java/java/lang/ClassCastException.java14
-rw-r--r--luni/src/main/java/java/lang/ClassLoader.java21
-rw-r--r--luni/src/main/java/java/lang/Compiler.java3
-rw-r--r--luni/src/main/java/java/lang/Double.java8
-rw-r--r--luni/src/main/java/java/lang/EmptyEnumeration.java56
-rw-r--r--luni/src/main/java/java/lang/Enum.java22
-rw-r--r--luni/src/main/java/java/lang/Float.java8
-rw-r--r--luni/src/main/java/java/lang/Integer.java93
-rw-r--r--luni/src/main/java/java/lang/IntegralToString.java6
-rw-r--r--luni/src/main/java/java/lang/Long.java60
-rw-r--r--luni/src/main/java/java/lang/Math.java42
-rw-r--r--luni/src/main/java/java/lang/Object.java2
-rw-r--r--luni/src/main/java/java/lang/Package.java17
-rw-r--r--luni/src/main/java/java/lang/Process.java48
-rw-r--r--luni/src/main/java/java/lang/ProcessBuilder.java20
-rw-r--r--luni/src/main/java/java/lang/ProcessManager.java10
-rw-r--r--luni/src/main/java/java/lang/Runtime.java140
-rw-r--r--luni/src/main/java/java/lang/Short.java34
-rw-r--r--luni/src/main/java/java/lang/StackOverflowError.java4
-rw-r--r--luni/src/main/java/java/lang/StrictMath.java26
-rw-r--r--luni/src/main/java/java/lang/String.java375
-rw-r--r--luni/src/main/java/java/lang/StringBuffer.java5
-rw-r--r--luni/src/main/java/java/lang/StringBuilder.java2
-rw-r--r--luni/src/main/java/java/lang/StringIndexOutOfBoundsException.java8
-rw-r--r--luni/src/main/java/java/lang/System.java2
-rw-r--r--luni/src/main/java/java/lang/Thread.java3
-rw-r--r--luni/src/main/java/java/lang/ThreadDeath.java2
-rw-r--r--luni/src/main/java/java/lang/ThreadGroup.java359
-rw-r--r--luni/src/main/java/java/lang/ThreadLocal.java12
-rw-r--r--luni/src/main/java/java/lang/VMClassLoader.java67
-rw-r--r--luni/src/main/java/java/lang/VMThread.java16
-rw-r--r--luni/src/main/java/java/lang/Void.java11
-rw-r--r--luni/src/main/java/java/lang/reflect/AccessibleObject.java77
-rw-r--r--luni/src/main/java/java/lang/reflect/Array.java6
-rw-r--r--luni/src/main/java/java/lang/reflect/Constructor.java10
-rw-r--r--luni/src/main/java/java/lang/reflect/Field.java34
-rw-r--r--luni/src/main/java/java/lang/reflect/InvocationHandler.java8
-rw-r--r--luni/src/main/java/java/lang/reflect/Method.java92
-rw-r--r--luni/src/main/java/java/lang/reflect/ParameterizedType.java2
-rw-r--r--luni/src/main/java/java/lang/reflect/TypeVariable.java6
-rw-r--r--luni/src/main/java/java/lang/reflect/WildcardType.java19
-rw-r--r--luni/src/main/java/java/math/BigDecimal.java96
-rw-r--r--luni/src/main/java/java/math/BigInt.java125
-rw-r--r--luni/src/main/java/java/math/BigInteger.java4
-rw-r--r--luni/src/main/java/java/math/MathContext.java6
-rw-r--r--luni/src/main/java/java/net/AddressCache.java55
-rw-r--r--luni/src/main/java/java/net/Authenticator.java4
-rw-r--r--luni/src/main/java/java/net/CookieHandler.java4
-rw-r--r--luni/src/main/java/java/net/DatagramPacket.java47
-rw-r--r--luni/src/main/java/java/net/DatagramSocket.java73
-rw-r--r--luni/src/main/java/java/net/DatagramSocketImpl.java2
-rw-r--r--luni/src/main/java/java/net/HttpCookie.java19
-rw-r--r--luni/src/main/java/java/net/Inet4Address.java37
-rw-r--r--luni/src/main/java/java/net/Inet6Address.java79
-rw-r--r--luni/src/main/java/java/net/InetAddress.java201
-rw-r--r--luni/src/main/java/java/net/InetSocketAddress.java47
-rw-r--r--luni/src/main/java/java/net/InterfaceAddress.java2
-rw-r--r--luni/src/main/java/java/net/JarURLConnection.java2
-rw-r--r--luni/src/main/java/java/net/MulticastSocket.java49
-rw-r--r--luni/src/main/java/java/net/NetworkInterface.java26
-rw-r--r--luni/src/main/java/java/net/Proxy.java14
-rw-r--r--luni/src/main/java/java/net/ProxySelector.java165
-rw-r--r--luni/src/main/java/java/net/ProxySelectorImpl.java340
-rw-r--r--luni/src/main/java/java/net/ResponseCache.java4
-rw-r--r--luni/src/main/java/java/net/ServerSocket.java26
-rw-r--r--luni/src/main/java/java/net/Socket.java198
-rw-r--r--luni/src/main/java/java/net/SocketImpl.java7
-rw-r--r--luni/src/main/java/java/net/SocketOptions.java74
-rw-r--r--luni/src/main/java/java/net/SocketPermission.java4
-rw-r--r--luni/src/main/java/java/net/URI.java33
-rw-r--r--luni/src/main/java/java/net/URL.java15
-rw-r--r--luni/src/main/java/java/net/URLClassLoader.java30
-rw-r--r--luni/src/main/java/java/net/URLStreamHandler.java161
-rw-r--r--luni/src/main/java/java/net/UnknownHostException.java11
-rw-r--r--luni/src/main/java/java/nio/BaseByteBuffer.java24
-rw-r--r--luni/src/main/java/java/nio/Buffer.java112
-rw-r--r--luni/src/main/java/java/nio/BufferFactory.java206
-rw-r--r--luni/src/main/java/java/nio/ByteBuffer.java155
-rw-r--r--luni/src/main/java/java/nio/ByteOrder.java26
-rw-r--r--luni/src/main/java/java/nio/CharArrayBuffer.java21
-rw-r--r--luni/src/main/java/java/nio/CharBuffer.java104
-rw-r--r--luni/src/main/java/java/nio/CharSequenceAdapter.java38
-rw-r--r--luni/src/main/java/java/nio/CharToByteBufferAdapter.java129
-rw-r--r--luni/src/main/java/java/nio/DatagramChannelImpl.java729
-rw-r--r--luni/src/main/java/java/nio/DirectByteBuffer.java257
-rw-r--r--luni/src/main/java/java/nio/DirectByteBuffers.java81
-rw-r--r--luni/src/main/java/java/nio/DoubleArrayBuffer.java16
-rw-r--r--luni/src/main/java/java/nio/DoubleBuffer.java94
-rw-r--r--luni/src/main/java/java/nio/DoubleToByteBufferAdapter.java125
-rw-r--r--luni/src/main/java/java/nio/FileChannelImpl.java623
-rw-r--r--luni/src/main/java/java/nio/FloatArrayBuffer.java16
-rw-r--r--luni/src/main/java/java/nio/FloatBuffer.java95
-rw-r--r--luni/src/main/java/java/nio/FloatToByteBufferAdapter.java129
-rw-r--r--luni/src/main/java/java/nio/HeapByteBuffer.java205
-rw-r--r--luni/src/main/java/java/nio/IntArrayBuffer.java16
-rw-r--r--luni/src/main/java/java/nio/IntBuffer.java95
-rw-r--r--luni/src/main/java/java/nio/IntToByteBufferAdapter.java129
-rw-r--r--luni/src/main/java/java/nio/LongArrayBuffer.java16
-rw-r--r--luni/src/main/java/java/nio/LongBuffer.java96
-rw-r--r--luni/src/main/java/java/nio/LongToByteBufferAdapter.java124
-rw-r--r--luni/src/main/java/java/nio/MappedByteBuffer.java21
-rw-r--r--luni/src/main/java/java/nio/MappedByteBufferAdapter.java331
-rw-r--r--luni/src/main/java/java/nio/MemoryBlock.java208
-rw-r--r--luni/src/main/java/java/nio/NIOAccess.java28
-rw-r--r--luni/src/main/java/java/nio/NioUtils.java87
-rw-r--r--luni/src/main/java/java/nio/PipeImpl.java133
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java15
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java26
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java17
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyFileChannel.java96
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java11
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java14
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java11
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java11
-rw-r--r--luni/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java11
-rw-r--r--luni/src/main/java/java/nio/ReadWriteCharArrayBuffer.java28
-rw-r--r--luni/src/main/java/java/nio/ReadWriteDirectByteBuffer.java282
-rw-r--r--luni/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java34
-rw-r--r--luni/src/main/java/java/nio/ReadWriteFileChannel.java37
-rw-r--r--luni/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java34
-rw-r--r--luni/src/main/java/java/nio/ReadWriteHeapByteBuffer.java129
-rw-r--r--luni/src/main/java/java/nio/ReadWriteIntArrayBuffer.java28
-rw-r--r--luni/src/main/java/java/nio/ReadWriteLongArrayBuffer.java28
-rw-r--r--luni/src/main/java/java/nio/ReadWriteShortArrayBuffer.java31
-rw-r--r--luni/src/main/java/java/nio/SelectionKeyImpl.java110
-rw-r--r--luni/src/main/java/java/nio/SelectorImpl.java451
-rw-r--r--luni/src/main/java/java/nio/SelectorProviderImpl.java51
-rw-r--r--luni/src/main/java/java/nio/ServerSocketChannelImpl.java194
-rw-r--r--luni/src/main/java/java/nio/ShortArrayBuffer.java16
-rw-r--r--luni/src/main/java/java/nio/ShortBuffer.java93
-rw-r--r--luni/src/main/java/java/nio/ShortToByteBufferAdapter.java130
-rw-r--r--luni/src/main/java/java/nio/SocketChannelImpl.java734
-rw-r--r--luni/src/main/java/java/nio/WriteOnlyFileChannel.java100
-rw-r--r--luni/src/main/java/java/nio/channels/Channels.java334
-rw-r--r--luni/src/main/java/java/nio/channels/SocketChannel.java2
-rw-r--r--luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java19
-rw-r--r--luni/src/main/java/java/nio/channels/spi/SelectorProvider.java5
-rw-r--r--luni/src/main/java/java/nio/charset/Charset.java4
-rw-r--r--luni/src/main/java/java/nio/charset/CharsetDecoder.java7
-rw-r--r--luni/src/main/java/java/nio/charset/CharsetEncoder.java2
-rw-r--r--luni/src/main/java/java/nio/charset/Charsets.java16
-rw-r--r--luni/src/main/java/java/nio/charset/CoderResult.java4
-rw-r--r--luni/src/main/java/java/nio/charset/ModifiedUtf8.java63
-rw-r--r--luni/src/main/java/java/security/AlgorithmParameterGenerator.java26
-rw-r--r--luni/src/main/java/java/security/AlgorithmParameters.java24
-rw-r--r--luni/src/main/java/java/security/KeyFactory.java29
-rw-r--r--luni/src/main/java/java/security/KeyPairGenerator.java49
-rw-r--r--luni/src/main/java/java/security/KeyStore.java100
-rw-r--r--luni/src/main/java/java/security/MessageDigest.java39
-rw-r--r--luni/src/main/java/java/security/Policy.java92
-rw-r--r--luni/src/main/java/java/security/Provider.java4
-rw-r--r--luni/src/main/java/java/security/SecureRandom.java56
-rw-r--r--luni/src/main/java/java/security/Security.java2
-rw-r--r--luni/src/main/java/java/security/Signature.java44
-rw-r--r--luni/src/main/java/java/security/cert/CertPathBuilder.java18
-rw-r--r--luni/src/main/java/java/security/cert/CertPathValidator.java16
-rw-r--r--luni/src/main/java/java/security/cert/CertStore.java16
-rw-r--r--luni/src/main/java/java/security/cert/CertificateFactory.java16
-rw-r--r--luni/src/main/java/java/security/cert/PKIXParameters.java56
-rw-r--r--luni/src/main/java/java/security/cert/X509CertSelector.java19
-rw-r--r--luni/src/main/java/java/security/security.properties2
-rw-r--r--luni/src/main/java/java/sql/DriverManager.java8
-rw-r--r--luni/src/main/java/java/sql/Timestamp.java2
-rw-r--r--luni/src/main/java/java/text/AttributedCharacterIterator.java31
-rw-r--r--luni/src/main/java/java/text/AttributedString.java7
-rw-r--r--luni/src/main/java/java/text/BreakIterator.java4
-rw-r--r--luni/src/main/java/java/text/ChoiceFormat.java5
-rw-r--r--luni/src/main/java/java/text/CollationElementIterator.java14
-rw-r--r--luni/src/main/java/java/text/Collator.java78
-rw-r--r--luni/src/main/java/java/text/DateFormat.java41
-rw-r--r--luni/src/main/java/java/text/DateFormatSymbols.java4
-rw-r--r--luni/src/main/java/java/text/DecimalFormat.java16
-rw-r--r--luni/src/main/java/java/text/DecimalFormatSymbols.java4
-rw-r--r--luni/src/main/java/java/text/MessageFormat.java20
-rw-r--r--luni/src/main/java/java/text/NumberFormat.java50
-rw-r--r--luni/src/main/java/java/text/RuleBasedBreakIterator.java127
-rw-r--r--luni/src/main/java/java/text/RuleBasedCollator.java22
-rw-r--r--luni/src/main/java/java/text/SimpleDateFormat.java2
-rw-r--r--luni/src/main/java/java/util/AbstractList.java16
-rw-r--r--luni/src/main/java/java/util/AbstractQueue.java212
-rw-r--r--luni/src/main/java/java/util/ArrayDeque.java1285
-rw-r--r--luni/src/main/java/java/util/ArrayList.java28
-rw-r--r--luni/src/main/java/java/util/Arrays.java147
-rw-r--r--luni/src/main/java/java/util/BitSet.java6
-rw-r--r--luni/src/main/java/java/util/Calendar.java18
-rw-r--r--luni/src/main/java/java/util/Collections.java20
-rw-r--r--luni/src/main/java/java/util/ComparableTimSort.java23
-rw-r--r--luni/src/main/java/java/util/Currency.java4
-rw-r--r--luni/src/main/java/java/util/Deque.java611
-rw-r--r--luni/src/main/java/java/util/DualPivotQuicksort.java31
-rw-r--r--luni/src/main/java/java/util/EnumMap.java38
-rw-r--r--luni/src/main/java/java/util/EnumSet.java2
-rw-r--r--luni/src/main/java/java/util/FormatFlagsConversionMismatchException.java2
-rw-r--r--luni/src/main/java/java/util/Formatter.java28
-rw-r--r--luni/src/main/java/java/util/HashMap.java4
-rw-r--r--luni/src/main/java/java/util/Hashtable.java4
-rw-r--r--luni/src/main/java/java/util/HugeEnumSet.java9
-rw-r--r--luni/src/main/java/java/util/IdentityHashMap.java16
-rw-r--r--luni/src/main/java/java/util/LinkedList.java10
-rw-r--r--luni/src/main/java/java/util/Locale.java115
-rw-r--r--luni/src/main/java/java/util/MiniEnumSet.java9
-rw-r--r--luni/src/main/java/java/util/MissingFormatArgumentException.java2
-rw-r--r--luni/src/main/java/java/util/MissingFormatWidthException.java2
-rw-r--r--luni/src/main/java/java/util/NavigableMap.java488
-rw-r--r--luni/src/main/java/java/util/NavigableSet.java385
-rw-r--r--luni/src/main/java/java/util/PriorityQueue.java6
-rw-r--r--luni/src/main/java/java/util/Properties.java24
-rw-r--r--luni/src/main/java/java/util/Queue.java221
-rw-r--r--luni/src/main/java/java/util/Random.java2
-rw-r--r--luni/src/main/java/java/util/ResourceBundle.java277
-rw-r--r--luni/src/main/java/java/util/Scanner.java36
-rw-r--r--luni/src/main/java/java/util/ServiceLoader.java8
-rw-r--r--luni/src/main/java/java/util/SimpleTimeZone.java16
-rw-r--r--luni/src/main/java/java/util/TimSort.java31
-rw-r--r--luni/src/main/java/java/util/TreeMap.java2
-rw-r--r--luni/src/main/java/java/util/TreeSet.java6
-rw-r--r--luni/src/main/java/java/util/UUID.java70
-rw-r--r--luni/src/main/java/java/util/Vector.java33
-rw-r--r--luni/src/main/java/java/util/WeakHashMap.java2
-rw-r--r--luni/src/main/java/java/util/concurrent/AbstractExecutorService.java28
-rw-r--r--luni/src/main/java/java/util/concurrent/ArrayBlockingQueue.java446
-rw-r--r--luni/src/main/java/java/util/concurrent/BlockingDeque.java51
-rw-r--r--luni/src/main/java/java/util/concurrent/BlockingQueue.java4
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java24
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentLinkedDeque.java824
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentLinkedQueue.java373
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentNavigableMap.java7
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentSkipListMap.java187
-rw-r--r--luni/src/main/java/java/util/concurrent/ConcurrentSkipListSet.java17
-rw-r--r--luni/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java1437
-rw-r--r--luni/src/main/java/java/util/concurrent/CopyOnWriteArraySet.java32
-rw-r--r--luni/src/main/java/java/util/concurrent/CountDownLatch.java6
-rw-r--r--luni/src/main/java/java/util/concurrent/CyclicBarrier.java4
-rw-r--r--luni/src/main/java/java/util/concurrent/DelayQueue.java25
-rw-r--r--luni/src/main/java/java/util/concurrent/Delayed.java2
-rw-r--r--luni/src/main/java/java/util/concurrent/Exchanger.java16
-rw-r--r--luni/src/main/java/java/util/concurrent/Executor.java48
-rw-r--r--luni/src/main/java/java/util/concurrent/ExecutorCompletionService.java3
-rw-r--r--luni/src/main/java/java/util/concurrent/ExecutorService.java5
-rw-r--r--luni/src/main/java/java/util/concurrent/Executors.java30
-rw-r--r--luni/src/main/java/java/util/concurrent/Future.java20
-rw-r--r--luni/src/main/java/java/util/concurrent/FutureTask.java5
-rw-r--r--luni/src/main/java/java/util/concurrent/LinkedBlockingDeque.java120
-rw-r--r--luni/src/main/java/java/util/concurrent/LinkedBlockingQueue.java80
-rw-r--r--luni/src/main/java/java/util/concurrent/PriorityBlockingQueue.java613
-rw-r--r--luni/src/main/java/java/util/concurrent/ScheduledExecutorService.java31
-rw-r--r--luni/src/main/java/java/util/concurrent/ScheduledThreadPoolExecutor.java35
-rw-r--r--luni/src/main/java/java/util/concurrent/Semaphore.java22
-rw-r--r--luni/src/main/java/java/util/concurrent/SynchronousQueue.java148
-rw-r--r--luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java79
-rw-r--r--luni/src/main/java/java/util/concurrent/TimeUnit.java42
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java15
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java8
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicLong.java13
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java15
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java18
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicMarkableReference.java98
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java15
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java18
-rw-r--r--luni/src/main/java/java/util/concurrent/atomic/AtomicStampedReference.java111
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java34
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java82
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/Condition.java75
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/LockSupport.java6
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/ReentrantLock.java17
-rw-r--r--luni/src/main/java/java/util/concurrent/locks/ReentrantReadWriteLock.java29
-rw-r--r--luni/src/main/java/java/util/concurrent/package-info.java4
-rw-r--r--luni/src/main/java/java/util/jar/Attributes.java2
-rw-r--r--luni/src/main/java/java/util/jar/JarEntry.java16
-rw-r--r--luni/src/main/java/java/util/jar/JarFile.java34
-rw-r--r--luni/src/main/java/java/util/jar/JarVerifier.java2
-rw-r--r--luni/src/main/java/java/util/jar/Manifest.java107
-rw-r--r--luni/src/main/java/java/util/logging/FileHandler.java23
-rw-r--r--luni/src/main/java/java/util/logging/Formatter.java7
-rw-r--r--luni/src/main/java/java/util/logging/Handler.java23
-rw-r--r--luni/src/main/java/java/util/logging/LogManager.java51
-rw-r--r--luni/src/main/java/java/util/logging/LogRecord.java8
-rw-r--r--luni/src/main/java/java/util/logging/MemoryHandler.java8
-rw-r--r--luni/src/main/java/java/util/logging/SimpleFormatter.java11
-rw-r--r--luni/src/main/java/java/util/logging/SocketHandler.java2
-rw-r--r--luni/src/main/java/java/util/logging/StreamHandler.java18
-rw-r--r--luni/src/main/java/java/util/logging/XMLFormatter.java14
-rw-r--r--luni/src/main/java/java/util/prefs/AbstractPreferences.java28
-rw-r--r--luni/src/main/java/java/util/prefs/FilePreferencesImpl.java4
-rw-r--r--luni/src/main/java/java/util/prefs/Preferences.java5
-rw-r--r--luni/src/main/java/java/util/prefs/XMLParser.java45
-rw-r--r--luni/src/main/java/java/util/zip/Adler32.java29
-rw-r--r--luni/src/main/java/java/util/zip/CRC32.java32
-rw-r--r--luni/src/main/java/java/util/zip/CheckedInputStream.java30
-rw-r--r--luni/src/main/java/java/util/zip/Checksum.java3
-rw-r--r--luni/src/main/java/java/util/zip/Deflater.java369
-rw-r--r--luni/src/main/java/java/util/zip/DeflaterInputStream.java59
-rw-r--r--luni/src/main/java/java/util/zip/DeflaterOutputStream.java35
-rw-r--r--luni/src/main/java/java/util/zip/GZIPInputStream.java68
-rw-r--r--luni/src/main/java/java/util/zip/GZIPOutputStream.java15
-rw-r--r--luni/src/main/java/java/util/zip/Inflater.java320
-rw-r--r--luni/src/main/java/java/util/zip/InflaterInputStream.java45
-rw-r--r--luni/src/main/java/java/util/zip/InflaterOutputStream.java18
-rw-r--r--luni/src/main/java/java/util/zip/ZipEntry.java182
-rw-r--r--luni/src/main/java/java/util/zip/ZipFile.java99
-rw-r--r--luni/src/main/java/java/util/zip/ZipInputStream.java238
-rw-r--r--luni/src/main/java/java/util/zip/ZipOutputStream.java96
-rw-r--r--luni/src/main/java/javax/crypto/Cipher.java99
-rw-r--r--luni/src/main/java/javax/crypto/CipherInputStream.java26
-rw-r--r--luni/src/main/java/javax/crypto/ExemptionMechanism.java18
-rw-r--r--luni/src/main/java/javax/crypto/KeyAgreement.java22
-rw-r--r--luni/src/main/java/javax/crypto/KeyGenerator.java22
-rw-r--r--luni/src/main/java/javax/crypto/Mac.java14
-rw-r--r--luni/src/main/java/javax/crypto/SecretKeyFactory.java16
-rw-r--r--luni/src/main/java/javax/crypto/spec/IvParameterSpec.java25
-rw-r--r--luni/src/main/java/javax/crypto/spec/PBEKeySpec.java7
-rw-r--r--luni/src/main/java/javax/crypto/spec/PSource.java4
-rw-r--r--luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java2
-rw-r--r--luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java283
-rw-r--r--luni/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java5
-rw-r--r--luni/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java5
-rw-r--r--luni/src/main/java/javax/net/ssl/KeyManagerFactory.java22
-rw-r--r--luni/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java2
-rw-r--r--luni/src/main/java/javax/net/ssl/SSLContext.java12
-rw-r--r--luni/src/main/java/javax/net/ssl/TrustManagerFactory.java18
-rw-r--r--luni/src/main/java/javax/xml/datatype/FactoryFinder.java14
-rw-r--r--luni/src/main/java/javax/xml/transform/ErrorListener.java2
-rw-r--r--luni/src/main/java/javax/xml/transform/Transformer.java2
-rw-r--r--luni/src/main/java/javax/xml/validation/SchemaFactory.java2
-rw-r--r--luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java8
-rw-r--r--luni/src/main/java/javax/xml/xpath/XPathFactoryFinder.java8
-rw-r--r--luni/src/main/java/libcore/base/CollectionUtils.java76
-rw-r--r--luni/src/main/java/libcore/base/EmptyArray.java31
-rw-r--r--luni/src/main/java/libcore/base/Objects.java4
-rw-r--r--luni/src/main/java/libcore/base/Streams.java59
-rw-r--r--luni/src/main/java/libcore/icu/CharsetDecoderICU.java313
-rw-r--r--luni/src/main/java/libcore/icu/CharsetEncoderICU.java378
-rw-r--r--luni/src/main/java/libcore/icu/CharsetICU.java40
-rw-r--r--luni/src/main/java/libcore/icu/CollationElementIteratorICU.java215
-rw-r--r--luni/src/main/java/libcore/icu/CollationKeyICU.java117
-rw-r--r--luni/src/main/java/libcore/icu/ErrorCode.java71
-rw-r--r--luni/src/main/java/libcore/icu/ICU.java155
-rw-r--r--luni/src/main/java/libcore/icu/LocaleData.java343
-rw-r--r--luni/src/main/java/libcore/icu/NativeBreakIterator.java161
-rw-r--r--luni/src/main/java/libcore/icu/NativeCollation.java43
-rw-r--r--luni/src/main/java/libcore/icu/NativeConverter.java143
-rw-r--r--luni/src/main/java/libcore/icu/NativeDecimalFormat.java642
-rw-r--r--luni/src/main/java/libcore/icu/RuleBasedCollatorICU.java154
-rw-r--r--luni/src/main/java/libcore/internal/StringPool.java52
-rw-r--r--luni/src/main/java/libcore/io/BufferIterator.java62
-rw-r--r--luni/src/main/java/libcore/io/HeapBufferIterator.java86
-rw-r--r--luni/src/main/java/libcore/io/IoUtils.java29
-rw-r--r--luni/src/main/java/libcore/io/MemoryMappedFile.java100
-rw-r--r--luni/src/main/java/libcore/io/NioBufferIterator.java75
-rw-r--r--luni/src/main/java/libcore/io/SizeOf.java29
-rw-r--r--luni/src/main/java/libcore/net/RawSocket.java127
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java8
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLInputStream.java17
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpInputStream.java48
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpOutputStream.java7
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedOutputStream.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthInputStream.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthOutputStream.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java257
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java34
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeaders.java211
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java289
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/RetryableOutputStream.java5
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java58
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java20
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java117
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfoDB.java161
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java68
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java88
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java25
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java14
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java32
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java8
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java56
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java564
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/Platform.java38
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java295
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java143
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java118
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/Base64.java22
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java566
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java42
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java191
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java103
-rw-r--r--luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/AddressUtil.java51
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/FileChannelFactory.java52
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java747
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java33
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java636
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/FileLockImpl.java76
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/IOUtil.java225
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/LockManager.java80
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java134
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java106
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/ReadWriteFileChannel.java44
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java128
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java453
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java74
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java197
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java760
-rw-r--r--luni/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java115
-rw-r--r--luni/src/main/java/org/apache/harmony/security/PolicyEntry.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/security/asn1/ASN1Choice.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java7
-rw-r--r--luni/src/main/java/org/apache/harmony/security/fortress/Engine.java167
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java17
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java240
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertPathImpl.java22
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPrivateKeyImpl.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPublicKeyImpl.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1PRNG_SecureRandomImpl.java12
-rw-r--r--luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1_MessageDigestImpl.java13
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValue.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x501/AttributeValue.java9
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x501/Name.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/AlgorithmIdentifier.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/DNParser.java6
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/Extension.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/Extensions.java29
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/GeneralName.java34
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/ReasonCode.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/security/x509/TBSCertList.java11
-rw-r--r--luni/src/main/java/org/apache/harmony/text/BidiRun.java8
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/ExpatParser.java9
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/ExpatPullParser.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/ExpatReader.java9
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/AttrImpl.java23
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/DOMConfigurationImpl.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java154
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/ElementImpl.java63
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java105
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/NamedNodeMapImpl.java175
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/dom/NodeImpl.java118
-rw-r--r--luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java72
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java26
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java703
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java97
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java5
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java11
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCache.java16
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java2
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java5
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java140
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java5
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java90
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java4
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java139
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java70
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketFactoryImpl.java18
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java351
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java17
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java10
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParametersImpl.java9
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java27
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLServerSocketFactoryImpl.java6
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java3
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketFactoryImpl.java24
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java17
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java106
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java14
-rw-r--r--luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java262
-rw-r--r--luni/src/main/java/org/apache/xml/serializer/ToHTMLStream.java4
-rw-r--r--luni/src/main/java/org/xml/sax/ext/Attributes2Impl.java6
-rw-r--r--luni/src/main/java/sun/misc/Unsafe.java16
-rw-r--r--luni/src/main/native/ICU.cpp33
-rw-r--r--luni/src/main/native/JniConstants.cpp8
-rw-r--r--luni/src/main/native/JniConstants.h1
-rw-r--r--luni/src/main/native/NativeBN.cpp9
-rw-r--r--luni/src/main/native/NativeBreakIterator.cpp5
-rw-r--r--luni/src/main/native/NativeCollation.cpp20
-rw-r--r--luni/src/main/native/NativeConverter.cpp7
-rw-r--r--luni/src/main/native/NativeCrypto.cpp295
-rw-r--r--luni/src/main/native/NativeDecimalFormat.cpp11
-rw-r--r--luni/src/main/native/Register.cpp36
-rw-r--r--luni/src/main/native/cbigint.cpp43
-rw-r--r--luni/src/main/native/ifaddrs-android.cpp217
-rw-r--r--luni/src/main/native/ifaddrs-android.h186
-rw-r--r--luni/src/main/native/java_io_File.cpp81
-rw-r--r--luni/src/main/native/java_io_ObjectInputStream.cpp91
-rw-r--r--luni/src/main/native/java_io_ObjectOutputStream.cpp80
-rw-r--r--luni/src/main/native/java_io_ObjectStreamClass.cpp10
-rw-r--r--luni/src/main/native/java_lang_Character.cpp34
-rw-r--r--luni/src/main/native/java_lang_Double.cpp25
-rw-r--r--luni/src/main/native/java_lang_Double.h41
-rw-r--r--luni/src/main/native/java_lang_Float.cpp24
-rw-r--r--luni/src/main/native/java_lang_Float.h41
-rw-r--r--luni/src/main/native/java_lang_StrictMath.cpp12
-rw-r--r--luni/src/main/native/java_net_InetAddress.cpp27
-rw-r--r--luni/src/main/native/java_util_zip_Deflater.cpp97
-rw-r--r--luni/src/main/native/java_util_zip_Inflater.cpp58
-rw-r--r--luni/src/main/native/libcore_io_IoUtils.cpp5
-rw-r--r--luni/src/main/native/libcore_net_RawSocket.cpp240
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp99
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp469
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp46
-rw-r--r--luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp35
-rw-r--r--luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp16
-rw-r--r--luni/src/main/native/readlink.cpp42
-rw-r--r--luni/src/main/native/readlink.h25
-rw-r--r--luni/src/main/native/realpath.cpp125
-rw-r--r--luni/src/main/native/sub.mk6
-rw-r--r--luni/src/main/native/zip.h1
-rw-r--r--luni/src/test/etc/loading-test-jar/README.txt8
-rw-r--r--luni/src/test/etc/loading-test-jar/Target.java45
-rw-r--r--luni/src/test/etc/loading-test-jar/Test1.java26
-rw-r--r--luni/src/test/etc/loading-test-jar/TestMethods.java190
-rwxr-xr-xluni/src/test/etc/loading-test-jar/build.sh56
-rw-r--r--luni/src/test/etc/loading-test-jar/resources/test/Resource1.txt1
-rw-r--r--luni/src/test/etc/loading-test2-jar/README.txt8
-rw-r--r--luni/src/test/etc/loading-test2-jar/Target2.java45
-rwxr-xr-xluni/src/test/etc/loading-test2-jar/build.sh49
-rw-r--r--luni/src/test/etc/loading-test2-jar/resources/test2/Resource2.txt1
-rw-r--r--luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java136
-rw-r--r--luni/src/test/java/com/android/org/bouncycastle/jce/provider/AllTests.java28
-rw-r--r--luni/src/test/java/com/android/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java79
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestDummy.java72
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestIsolator.java120
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestPrinter.java180
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestResult.java170
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestRunnable.java172
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestRunner.java329
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestSuite.java357
-rw-r--r--luni/src/test/java/com/google/coretests/CoreTestTimeout.java32
-rw-r--r--luni/src/test/java/com/google/coretests/Main.java50
-rw-r--r--luni/src/test/java/com/google/coretests/PerfStatCollector.java257
-rw-r--r--luni/src/test/java/com/google/coretests/ResultPrinter.java157
-rw-r--r--luni/src/test/java/com/google/coretests/StatTestRunner.java230
-rw-r--r--luni/src/test/java/com/google/coretests/StatsStore.java309
-rw-r--r--luni/src/test/java/com/google/coretests/Version.java30
-rw-r--r--luni/src/test/java/com/google/coretests/XmlReportPrinter.java257
-rw-r--r--luni/src/test/java/com/ibm/icu4jni/util/ICUTest.java56
-rw-r--r--luni/src/test/java/dalvik/system/DexClassLoaderTest.java465
-rw-r--r--luni/src/test/java/libcore/base/CollectionUtilsTest.java80
-rw-r--r--luni/src/test/java/libcore/icu/ICUTest.java56
-rw-r--r--luni/src/test/java/libcore/internal/StringPoolTest.java44
-rw-r--r--luni/src/test/java/libcore/java/io/DataOutputStreamTest.java150
-rw-r--r--luni/src/test/java/libcore/java/io/FileInputStreamTest.java96
-rw-r--r--luni/src/test/java/libcore/java/io/FileTest.java14
-rw-r--r--luni/src/test/java/libcore/java/io/ObjectOutputStreamTest.java35
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidBufferedInputStreamTest.java113
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidBufferedOutputStreamTest.java47
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidBufferedReaderTest.java115
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidBufferedWriterTest.java50
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidByteArrayInputStreamTest.java93
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidByteArrayOutputStreamTest.java40
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidCharArrayReaderTest.java92
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidDataInputStreamTest.java157
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidDataOutputStreamTest.java48
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidFileTest.java34
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidInputStreamReaderTest.java109
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidLineNumberReaderTest.java129
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidOutputStreamWriterTest.java45
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidPipedStreamTest.java291
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidPrintWriterTest.java72
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidPushbackInputStreamTest.java107
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidPushbackReaderTest.java89
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidSerializationTest.java44
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidStreamTokenizerTest.java93
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidStringReaderTest.java90
-rw-r--r--luni/src/test/java/libcore/java/io/OldAndroidStringWriterTest.java39
-rw-r--r--luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java228
-rw-r--r--luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java198
-rw-r--r--luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java321
-rw-r--r--luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java316
-rw-r--r--luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java220
-rw-r--r--luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java113
-rw-r--r--luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java259
-rw-r--r--luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java140
-rw-r--r--luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java344
-rw-r--r--luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java380
-rw-r--r--luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java199
-rw-r--r--luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java209
-rw-r--r--luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java204
-rw-r--r--luni/src/test/java/libcore/java/io/OldFilePermissionTest.java191
-rw-r--r--luni/src/test/java/libcore/java/io/OldFileReaderTest.java46
-rw-r--r--luni/src/test/java/libcore/java/io/OldFileTest.java241
-rw-r--r--luni/src/test/java/libcore/java/io/OldFileWriterTest.java164
-rw-r--r--luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java323
-rw-r--r--luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java203
-rw-r--r--luni/src/test/java/libcore/java/io/OldFilterReaderTest.java176
-rw-r--r--luni/src/test/java/libcore/java/io/OldFilterWriterTest.java148
-rw-r--r--luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java295
-rw-r--r--luni/src/test/java/libcore/java/io/OldInputStreamTest.java272
-rw-r--r--luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java179
-rw-r--r--luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java186
-rw-r--r--luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java272
-rw-r--r--luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java259
-rw-r--r--luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java140
-rw-r--r--luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java435
-rw-r--r--luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java179
-rw-r--r--luni/src/test/java/libcore/java/io/OldOutputStreamTest.java129
-rw-r--r--luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java589
-rw-r--r--luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java270
-rw-r--r--luni/src/test/java/libcore/java/io/OldPipedWriterTest.java277
-rw-r--r--luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java356
-rw-r--r--luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java385
-rw-r--r--luni/src/test/java/libcore/java/io/OldRandomAccessFileTest.java1210
-rw-r--r--luni/src/test/java/libcore/java/io/OldReaderTest.java124
-rw-r--r--luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java160
-rw-r--r--luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java124
-rw-r--r--luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java53
-rw-r--r--luni/src/test/java/libcore/java/io/OldStringReaderTest.java68
-rw-r--r--luni/src/test/java/libcore/java/io/OldStringWriterTest.java47
-rw-r--r--luni/src/test/java/libcore/java/io/OldWriterTest.java194
-rw-r--r--luni/src/test/java/libcore/java/io/RandomAccessFileTest.java40
-rw-r--r--luni/src/test/java/libcore/java/lang/ArrayIndexOutOfBoundsExceptionTest.java81
-rw-r--r--luni/src/test/java/libcore/java/lang/ArrayStoreExceptionTest.java33
-rw-r--r--luni/src/test/java/libcore/java/lang/ClassCastExceptionTest.java123
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidBooleanTest.java44
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidEnumTest.java62
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidFloatDoubleTest.java148
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidInstanceofTest.java131
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidMathTest.java653
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidMonitorTest.java464
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidParseIntTest.java108
-rw-r--r--luni/src/test/java/libcore/java/lang/OldAndroidStrictMathTest.java677
-rw-r--r--luni/src/test/java/libcore/java/lang/OldCharacterSubsetTest.java39
-rw-r--r--luni/src/test/java/libcore/java/lang/OldCharacterTest.java152
-rw-r--r--luni/src/test/java/libcore/java/lang/OldClassTest.java1024
-rw-r--r--luni/src/test/java/libcore/java/lang/OldDoubleTest.java79
-rw-r--r--luni/src/test/java/libcore/java/lang/OldFloatTest.java92
-rw-r--r--luni/src/test/java/libcore/java/lang/OldInheritableThreadLocalTest.java66
-rw-r--r--luni/src/test/java/libcore/java/lang/OldIntegerTest.java69
-rw-r--r--luni/src/test/java/libcore/java/lang/OldLongTest.java83
-rw-r--r--luni/src/test/java/libcore/java/lang/OldObjectTest.java250
-rw-r--r--luni/src/test/java/libcore/java/lang/OldRuntimeExceptionTest.java46
-rw-r--r--luni/src/test/java/libcore/java/lang/OldRuntimeTest.java550
-rw-r--r--luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java214
-rw-r--r--luni/src/test/java/libcore/java/lang/OldStringBufferTest.java329
-rw-r--r--luni/src/test/java/libcore/java/lang/OldStringTest.java26
-rw-r--r--luni/src/test/java/libcore/java/lang/OldSystemTest.java362
-rw-r--r--luni/src/test/java/libcore/java/lang/OldThreadStateTest.java60
-rw-r--r--luni/src/test/java/libcore/java/lang/OldThreadTest.java22
-rw-r--r--luni/src/test/java/libcore/java/lang/OldThrowableTest.java131
-rw-r--r--luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java50
-rw-r--r--luni/src/test/java/libcore/java/lang/StringIndexOutOfBoundsExceptionTest.java36
-rw-r--r--luni/src/test/java/libcore/java/lang/ThreadTest.java59
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/ClassLoaderReflectionTest.java70
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/MethodTest.java35
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/MissingClassesTest.java76
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/OldAndroidArrayTest.java130
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/ProxyTest.java66
-rw-r--r--luni/src/test/java/libcore/java/lang/reflect/ReflectionTest.java130
-rw-r--r--luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java11
-rw-r--r--luni/src/test/java/libcore/java/net/CookiesTest.java26
-rw-r--r--luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java37
-rw-r--r--luni/src/test/java/libcore/java/net/OldAndroidDatagramTest.java188
-rw-r--r--luni/src/test/java/libcore/java/net/OldAndroidURITest.java49
-rw-r--r--luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java2
-rw-r--r--luni/src/test/java/libcore/java/net/OldResponseCacheTest.java16
-rw-r--r--luni/src/test/java/libcore/java/net/OldURLStreamHandlerTest.java48
-rw-r--r--luni/src/test/java/libcore/java/net/ProxySelectorTest.java207
-rw-r--r--luni/src/test/java/libcore/java/net/SocketTest.java83
-rw-r--r--luni/src/test/java/libcore/java/net/URLConnectionTest.java428
-rw-r--r--luni/src/test/java/libcore/java/net/URLTest.java43
-rw-r--r--luni/src/test/java/libcore/java/nio/BufferTest.java419
-rw-r--r--luni/src/test/java/libcore/java/nio/NoArrayTest.java51
-rw-r--r--luni/src/test/java/libcore/java/nio/OldAndroidNIOTest.java704
-rw-r--r--luni/src/test/java/libcore/java/nio/OldDirectIntBufferTest.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/OldDirectShortBufferTest.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/channels/ChannelsTest.java60
-rw-r--r--luni/src/test/java/libcore/java/nio/channels/OldFileChannelTest.java71
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/CharsetDecoderTest.java98
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/CharsetEncoderTest.java12
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/Charset_TestGenerator.java261
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharsetDecoderTest.java98
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharsetEncoderDecoderBufferTest.java143
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_AbstractTest.java306
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_GSM0338.java57
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_10.java62
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_14.java64
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_16.java62
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5.java421
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5_Android.java301
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP.java525
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP_Android.java523
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_KR.java477
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GB2312.java193
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK.java511
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK_Android.java513
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_ISO_2022_JP.java381
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16.java382
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16BE.java378
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16LE.java378
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16_Android.java374
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_8.java466
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_x_windows_950.java242
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByteAbstractTest.java193
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_IBM864.java79
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_1.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_11.java46
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_13.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_15.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_2.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_3.java76
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_4.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_5.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_6.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_7.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_8.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_9.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_KOI8_R.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_US_ASCII.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1250.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1251.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1252.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1253.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1254.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1255.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1256.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1257.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1258.java42
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_x_IBM874.java46
-rw-r--r--luni/src/test/java/libcore/java/nio/charset/OldCharset_macintosh.java62
-rw-r--r--luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java139
-rw-r--r--luni/src/test/java/libcore/java/security/KeyStoreTest.java28
-rw-r--r--luni/src/test/java/libcore/java/security/ProviderTest.java18
-rw-r--r--luni/src/test/java/libcore/java/security/SignatureTest.java113
-rw-r--r--luni/src/test/java/libcore/java/security/cert/PKIXParametersTest.java57
-rw-r--r--luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java66
-rw-r--r--luni/src/test/java/libcore/java/sql/OldTimestampTest.java41
-rw-r--r--luni/src/test/java/libcore/java/text/AttributedCharacterIteratorAttributeTest.java69
-rw-r--r--luni/src/test/java/libcore/java/text/CollatorTest.java4
-rw-r--r--luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java6
-rw-r--r--luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java5
-rw-r--r--luni/src/test/java/libcore/java/util/OldAndroidArrayListTest.java91
-rw-r--r--luni/src/test/java/libcore/java/util/OldAndroidHashMapTest.java239
-rw-r--r--luni/src/test/java/libcore/java/util/OldAndroidLocaleTest.java231
-rw-r--r--luni/src/test/java/libcore/java/util/OldAndroidTreeMapTest.java103
-rw-r--r--luni/src/test/java/libcore/java/util/OldScannerTest.java559
-rw-r--r--luni/src/test/java/libcore/java/util/OldTimeZoneTest.java4
-rw-r--r--luni/src/test/java/libcore/java/util/OldTreeMapTest.java14
-rw-r--r--luni/src/test/java/libcore/java/util/SerializableTester.java18
-rw-r--r--luni/src/test/java/libcore/java/util/beans/PropertyChangeSupportTest.java286
-rw-r--r--luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java270
-rw-r--r--luni/src/test/java/libcore/java/util/jar/DalvikExecTest.java253
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldAttributesNameTest.java63
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldAttributesTest.java104
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldJarEntryTest.java138
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldJarExceptionTest.java43
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldJarFileTest.java293
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldJarInputStreamTest.java92
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldJarOutputStreamTest.java43
-rw-r--r--luni/src/test/java/libcore/java/util/jar/OldManifestTest.java144
-rw-r--r--luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java1144
-rw-r--r--luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java73
-rw-r--r--luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java168
-rw-r--r--luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java156
-rw-r--r--luni/src/test/java/libcore/java/util/prefs/OldPreferencesTest.java1177
-rw-r--r--luni/src/test/java/libcore/java/util/zip/DeflaterInputStreamTest.java112
-rw-r--r--luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java3
-rw-r--r--luni/src/test/java/libcore/java/util/zip/DeflaterTest.java10
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java73
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java50
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GzipTest.java78
-rw-r--r--luni/src/test/java/libcore/java/util/zip/InflaterTest.java113
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldAndroidChecksumTest.java95
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldAndroidDeflateTest.java197
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldAndroidGZIPStreamTest.java112
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldAndroidZipFileTest.java196
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldAndroidZipStreamTest.java168
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldDataFormatExceptionTest.java35
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldZipExceptionTest.java35
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java196
-rw-r--r--luni/src/test/java/libcore/java/util/zip/OldZipInputStreamTest.java176
-rw-r--r--luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java20
-rw-r--r--luni/src/test/java/libcore/java/util/zip/ZipFileTest.java2
-rw-r--r--luni/src/test/java/libcore/java/util/zip/ZipInputStreamTest.java62
-rw-r--r--luni/src/test/java/libcore/java/util/zip/ZipOutputStreamTest.java63
-rw-r--r--luni/src/test/java/libcore/javax/crypto/CipherInputStreamTest.java74
-rw-r--r--luni/src/test/java/libcore/javax/crypto/CipherTest.java115
-rw-r--r--luni/src/test/java/libcore/javax/crypto/KeyGeneratorTest.java153
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java232
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java84
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java3
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java103
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSessionContextTest.java37
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java24
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSocketFactoryTest.java2
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java234
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/TrustManagerFactoryTest.java257
-rw-r--r--luni/src/test/java/libcore/javax/sql/OldConnectionEventTest.java61
-rw-r--r--luni/src/test/java/libcore/xml/ExpatPullParserDtdTest.java26
-rw-r--r--luni/src/test/java/libcore/xml/ExpatPullParserTest.java27
-rw-r--r--luni/src/test/java/libcore/xml/ExpatSaxParserTest.java741
-rw-r--r--luni/src/test/java/libcore/xml/JaxenXPathTestSuite.java306
-rw-r--r--luni/src/test/java/libcore/xml/KxmlPullParserDtdTest.java29
-rw-r--r--luni/src/test/java/libcore/xml/KxmlPullParserTest.java27
-rw-r--r--luni/src/test/java/libcore/xml/NamespacedAttributesLookupTest.java139
-rw-r--r--luni/src/test/java/libcore/xml/PullParserDtdTest.java541
-rw-r--r--luni/src/test/java/libcore/xml/PullParserTest.java734
-rw-r--r--luni/src/test/java/libcore/xml/XsltXPathConformanceTestSuite.java635
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesNameTest.java74
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java391
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/DalvikExecTest.java259
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java251
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java46
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExecTest.java276
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java533
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java180
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java500
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ZipExecTest.java275
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java169
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java50
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java186
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java144
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java165
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DataFormatExceptionTest.java35
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java378
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java402
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java1102
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java297
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java182
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java416
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterOutputStreamTest.java392
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java1031
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java500
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipExceptionTest.java35
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java378
-rw-r--r--luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java290
-rw-r--r--luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java2
-rw-r--r--luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java4
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HeaderTest.java55
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeadersTest.java54
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/platform/OSMemoryTest.java123
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java12
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java50
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java592
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java222
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java2262
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java537
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java45
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java703
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/PushBackInputStreamTest.java108
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java984
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java379
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java148
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AllTests.java115
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java41
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java52
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AssertionErrorTest.java78
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/BooleanTest.java157
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java672
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_SubsetTest.java95
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_UnicodeBlockTest.java879
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCircularityErrorTest.java39
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassFormatErrorTest.java43
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java269
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java60
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java1806
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest2.java99
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CompilerTest.java65
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java1661
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumConstantNotPresentExceptionTest.java55
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java53
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass.java29
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass1.java21
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java1293
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalArgumentExceptionTest.java87
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalMonitorStateExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalStateExceptionTest.java95
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalThreadStateExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IncompatibleClassChangeErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IndexOutOfBoundsExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InheritableThreadLocalTest.java78
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java1531
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InternalErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InterruptedExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LinkageErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java1332
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java1987
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum.java57
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum2.java61
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockSecurityManager.java69
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java102
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NegativeArraySizeExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoClassDefFoundErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NullPointerExceptionTest.java41
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberFormatExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java66
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ObjectTest.java673
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OldCharacterTest.java153
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OutOfMemoryErrorTest.java46
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicClassLoader.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicTestClass.java73
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeExceptionTest.java95
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java44
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeTest.java830
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityExceptionTest.java81
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java510
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java660
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementOriginal.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementTest.java285
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java1490
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java1106
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBufferTest.java622
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuilderTest.java1984
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringIndexOutOfBoundsExceptionTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SystemTest.java896
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAnnotation.java25
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions.java29
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions1.java29
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1.java25
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1B.java25
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1C.java25
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass2.java24
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass3.java21
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass4.java0
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadDeathTest.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java217
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadStateTest.java80
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java413
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TypeNotPresentExceptionTest.java54
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedClassVersionErrorTest.java46
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java100
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java42
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java43
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java118
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java193
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java105
-rw-r--r--luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java18
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java392
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java92
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java95
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java2822
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteOrderTest.java57
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java1601
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java113
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectDoubleBufferTest.java96
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectFloatBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java166
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectLongBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java167
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java971
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateDirectByteBufferTest.java33
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateHeapByteBufferTest.java34
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateWrappedByteBufferTest.java34
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java978
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java53
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java48
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java954
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java74
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java936
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java194
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java91
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java289
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDirectByteBufferTest.java56
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDoubleBufferTest.java231
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyFloatBufferTest.java232
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapByteBufferTest.java103
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapCharBufferTest.java31
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapDoubleBufferTest.java31
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapFloatBufferTest.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapIntBufferTest.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapLongBufferTest.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapShortBufferTest.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyIntBufferTest.java232
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyLongBufferTest.java232
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyShortBufferTest.java232
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedByteBufferTest.java105
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java38
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java947
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java35
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java36
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java36
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java96
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java94
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java185
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java97
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AllTests.java58
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AlreadyConnectedExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AsynchronousCloseExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/CancelledKeyExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java1141
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedByInterruptExceptionTest.java87
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedChannelExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedSelectorExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ConnectionPendingExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java4703
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockInterruptionExceptionTest.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java284
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalBlockingModeExceptionTest.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalSelectorExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MapModeTest.java69
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockDatagramChannel.java81
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSecurityManager.java69
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockServerSocketChannel.java46
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSocketChannel.java75
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NoConnectionPendingExceptionTest.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonReadableChannelExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonWritableChannelExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetBoundExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetConnectedExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/OverlappingFileLockExceptionTest.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java87
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectableChannelTest.java110
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectionKeyTest.java463
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java736
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java751
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SourceChannelTest.java721
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnresolvedAddressExceptionTest.java88
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnsupportedAddressTypeExceptionTest.java89
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractInterruptibleChannelTest.java199
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectableChannelTest.java437
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectionKeyTest.java104
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectorTest.java281
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AllTests.java36
-rw-r--r--luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/MockAbstractSelector.java134
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java620
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java39
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java77
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java323
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java225
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java178
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java92
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java126
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java123
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java124
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java125
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java30
-rw-r--r--luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java63
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java1484
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java43
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java96
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java208
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java119
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java254
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java132
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java118
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java160
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java85
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java204
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java65
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java78
-rw-r--r--luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java1919
-rw-r--r--luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java110
-rw-r--r--luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandomSpiTest.java36
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/AllTests.java52
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/BatchUpdateExceptionTest.java438
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ConnectionTest.java101
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DataTruncationTest.java555
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java105
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java474
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java713
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java160
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ParameterMetaDataTest.java106
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetMetaDataTest.java96
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetTest.java113
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java619
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java91
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java474
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java104
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java219
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java243
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java117
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java50
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java35
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java133
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java44
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java112
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java402
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java873
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TypesTest.java113
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/AllTests.java37
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/ConnectionEventTest.java178
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_PooledConnection.java46
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_RowSet.java1272
-rw-r--r--luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/RowSetEventTest.java55
-rw-r--r--luni/src/test/java/org/apache/harmony/xml/AllTests.java29
-rw-r--r--luni/src/test/java/org/apache/harmony/xml/ExpatParserTest.java892
-rw-r--r--luni/src/test/java/org/apache/harmony/xml/JaxenXPathTestSuite.java306
-rw-r--r--luni/src/test/java/org/apache/harmony/xml/NamespacedAttributesLookupTest.java139
-rw-r--r--luni/src/test/java/org/apache/harmony/xml/XsltXPathConformanceTestSuite.java635
-rw-r--r--luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java167
-rw-r--r--luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java15
-rw-r--r--luni/src/test/java/org/bouncycastle/crypto/digests/DigestTest.java136
-rw-r--r--luni/src/test/java/org/bouncycastle/jce/provider/AllTests.java28
-rw-r--r--luni/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java79
-rw-r--r--luni/src/test/java/tests/AllTests.java6
-rw-r--r--luni/src/test/java/tests/api/java/io/AllTests.java70
-rw-r--r--luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java578
-rw-r--r--luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java253
-rw-r--r--luni/src/test/java/tests/api/java/io/BufferedReaderTest.java544
-rw-r--r--luni/src/test/java/tests/api/java/io/BufferedWriterTest.java412
-rw-r--r--luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java325
-rw-r--r--luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java327
-rw-r--r--luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java342
-rw-r--r--luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java436
-rw-r--r--luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java529
-rw-r--r--luni/src/test/java/tests/api/java/io/DataInputStreamTest.java517
-rw-r--r--luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java297
-rw-r--r--luni/src/test/java/tests/api/java/io/EOFExceptionTest.java84
-rw-r--r--luni/src/test/java/tests/api/java/io/ExternalizableTest.java33
-rw-r--r--luni/src/test/java/tests/api/java/io/FileDescriptorTest.java152
-rw-r--r--luni/src/test/java/tests/api/java/io/FileFilterTest.java25
-rw-r--r--luni/src/test/java/tests/api/java/io/FileInputStreamTest.java511
-rw-r--r--luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java451
-rw-r--r--luni/src/test/java/tests/api/java/io/FilePermissionTest.java251
-rw-r--r--luni/src/test/java/tests/api/java/io/FileReaderTest.java169
-rw-r--r--luni/src/test/java/tests/api/java/io/FileTest.java2532
-rw-r--r--luni/src/test/java/tests/api/java/io/FileWriterTest.java409
-rw-r--r--luni/src/test/java/tests/api/java/io/FilenameFilterTest.java25
-rw-r--r--luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java454
-rw-r--r--luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java269
-rw-r--r--luni/src/test/java/tests/api/java/io/FilterReaderTest.java279
-rw-r--r--luni/src/test/java/tests/api/java/io/FilterWriterTest.java228
-rw-r--r--luni/src/test/java/tests/api/java/io/IOExceptionTest.java68
-rw-r--r--luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java756
-rw-r--r--luni/src/test/java/tests/api/java/io/InputStreamTest.java402
-rw-r--r--luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java86
-rw-r--r--luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java101
-rw-r--r--luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java49
-rw-r--r--luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java308
-rw-r--r--luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java359
-rw-r--r--luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java67
-rw-r--r--luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java468
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java400
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java793
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java23
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java209
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java1518
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java263
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java78
-rw-r--r--luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java537
-rw-r--r--luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java83
-rw-r--r--luni/src/test/java/tests/api/java/io/OutputStreamTest.java172
-rw-r--r--luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java878
-rw-r--r--luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java451
-rw-r--r--luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java339
-rw-r--r--luni/src/test/java/tests/api/java/io/PipedReaderTest.java427
-rw-r--r--luni/src/test/java/tests/api/java/io/PipedWriterTest.java502
-rw-r--r--luni/src/test/java/tests/api/java/io/PrintStreamTest.java663
-rw-r--r--luni/src/test/java/tests/api/java/io/PrintWriterTest.java778
-rw-r--r--luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java466
-rw-r--r--luni/src/test/java/tests/api/java/io/PushbackReaderTest.java673
-rw-r--r--luni/src/test/java/tests/api/java/io/RandomAccessFileTest.java1524
-rw-r--r--luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java357
-rw-r--r--luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java77
-rw-r--r--luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java757
-rw-r--r--luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java176
-rw-r--r--luni/src/test/java/tests/api/java/io/StringReaderTest.java279
-rw-r--r--luni/src/test/java/tests/api/java/io/StringWriterTest.java306
-rw-r--r--luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java47
-rw-r--r--luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java66
-rw-r--r--luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java102
-rw-r--r--luni/src/test/java/tests/api/java/io/WriterTest.java338
-rw-r--r--luni/src/test/java/tests/api/java/lang/reflect/ProxyTest.java24
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetDecoderTestCase.java762
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetEncoderTestCase.java1048
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/AllTests.java85
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/CharsetEncoderDecoderBufferTest.java182
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_AbstractTest.java342
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_GSM0338.java68
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_10.java65
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_14.java79
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_16.java65
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_.java52
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5.java435
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5_Android.java304
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP.java540
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP_Android.java534
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_KR.java491
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GB2312.java218
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK.java525
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK_Android.java516
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_ISO_2022_JP.java401
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16.java396
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16BE.java392
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16LE.java392
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16_Android.java377
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_8.java480
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_x_windows_950.java267
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByteAbstractTest.java215
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_.java41
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_IBM864.java89
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_1.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_11.java61
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_13.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_15.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_2.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_3.java108
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_4.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_5.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_6.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_7.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_8.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_9.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_KOI8_R.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_US_ASCII.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1250.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1251.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1252.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1253.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1254.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1255.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1256.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1257.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1258.java56
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_x_IBM874.java53
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator.java267
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator_Res.java2672
-rw-r--r--luni/src/test/java/tests/api/java/nio/charset/Charset_macintosh.java77
-rw-r--r--luni/src/test/java/tests/api/java/util/AllTests.java1
-rw-r--r--luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java3
-rw-r--r--luni/src/test/java/tests/api/java/util/ResourceBundleTest.java64
-rw-r--r--luni/src/test/java/tests/api/java/util/ScannerTest.java6918
-rw-r--r--luni/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java135
-rw-r--r--luni/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java127
-rw-r--r--luni/src/test/java/tests/api/javax/xml/parsers/AllTests.java3
-rw-r--r--luni/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java271
-rw-r--r--luni/src/test/java/tests/api/org/xml/sax/support/BrokenInputStream.java4
-rw-r--r--luni/src/test/java/tests/archive/AllTests.java34
-rw-r--r--luni/src/test/java/tests/java/security/SecureRandomTest.java75
-rw-r--r--luni/src/test/java/tests/luni/AllTestsIo.java4
-rw-r--r--luni/src/test/java/tests/luni/AllTestsLang.java2
-rw-r--r--luni/src/test/java/tests/nio/AllTests.java35
-rw-r--r--luni/src/test/java/tests/nio_char/AllTests.java35
-rw-r--r--luni/src/test/java/tests/org/w3c/dom/GetElementsByTagNameNS.java2
-rw-r--r--luni/src/test/java/tests/prefs/AllTests.java34
-rw-r--r--luni/src/test/java/tests/security/AllTests.java2
-rw-r--r--luni/src/test/java/tests/security/SecureRandomTest.java55
-rw-r--r--luni/src/test/java/tests/sql/AllTests.java2
-rw-r--r--luni/src/test/java/tests/targets/security/AllTests.java7
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestMD5withRSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestNONEwithDSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestSHA1withDSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestSHA1withRSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestSHA256withRSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestSHA384withRSA.java25
-rw-r--r--luni/src/test/java/tests/targets/security/SignatureTestSHA512withRSA.java25
-rw-r--r--luni/src/test/java/tests/xml/AllTests.java1
-rw-r--r--luni/src/test/java/tests/xml/DomTest.java216
-rw-r--r--luni/src/test/resources/META-INF/services/java.util.ServiceLoaderTestInterface7
-rw-r--r--luni/src/test/resources/META-INF/services/libcore.java.util.ServiceLoaderTestInterface7
-rw-r--r--luni/src/test/resources/dalvik/system/loading-test.dexbin0 -> 3972 bytes
-rw-r--r--luni/src/test/resources/dalvik/system/loading-test.jarbin0 -> 2551 bytes
-rw-r--r--luni/src/test/resources/dalvik/system/loading-test2.dexbin0 -> 904 bytes
-rw-r--r--luni/src/test/resources/dalvik/system/loading-test2.jarbin0 -> 1197 bytes
-rw-r--r--luni/src/test/resources/libcore/java/lang/HelloWorld.txt (renamed from luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt)0
-rw-r--r--luni/src/test/resources/libcore/java/lang/HelloWorld1.txt (renamed from luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld1.txt)0
-rw-r--r--luni/src/test/resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jarbin0 -> 1900 bytes
-rw-r--r--luni/src/test/resources/tests/api/java/net/file1.cache1
1391 files changed, 70573 insertions, 164968 deletions
diff --git a/luni/src/main/files/cacerts.bks b/luni/src/main/files/cacerts.bks
index 3dbbe49..e5ccf53 100644
--- a/luni/src/main/files/cacerts.bks
+++ b/luni/src/main/files/cacerts.bks
Binary files differ
diff --git a/luni/src/main/files/cacerts/0d188d89.0 b/luni/src/main/files/cacerts/0d188d89.0
new file mode 100644
index 0000000..1f150e4
--- /dev/null
+++ b/luni/src/main/files/cacerts/0d188d89.0
@@ -0,0 +1,80 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 44:99:8d:3c:c0:03:27:bd:9c:76:95:b9:ea:db:ac:b5
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=TR, O=Elektronik Bilgi Guvenligi A.S., CN=e-Guven Kok Elektronik Sertifika Hizmet Saglayicisi
+ Validity
+ Not Before: Jan 4 11:32:48 2007 GMT
+ Not After : Jan 4 11:32:48 2017 GMT
+ Subject: C=TR, O=Elektronik Bilgi Guvenligi A.S., CN=e-Guven Kok Elektronik Sertifika Hizmet Saglayicisi
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:c3:12:20:9e:b0:5e:00:65:8d:4e:46:bb:80:5c:
+ e9:2c:06:97:d5:f3:72:c9:70:b9:e7:4b:65:80:c1:
+ 4b:be:7e:3c:d7:54:31:94:de:d5:12:ba:53:16:02:
+ ea:58:63:ef:5b:d8:f3:ed:2a:1a:aa:71:48:a3:dc:
+ 10:2d:5f:5f:eb:5c:4b:9c:96:08:42:25:28:11:cc:
+ 8a:5a:62:01:50:d5:eb:09:53:2f:f8:c3:8f:fe:b3:
+ fc:fd:9d:a2:e3:5f:7d:be:ed:0b:e0:60:eb:69:ec:
+ 33:ed:d8:8d:fb:12:49:83:00:c9:8b:97:8c:3b:73:
+ 2a:32:b3:12:f7:b9:4d:f2:f4:4d:6d:c7:e6:d6:26:
+ 37:08:f2:d9:fd:6b:5c:a3:e5:48:5c:58:bc:42:be:
+ 03:5a:81:ba:1c:35:0c:00:d3:f5:23:7e:71:30:08:
+ 26:38:dc:25:11:47:2d:f3:ba:23:10:a5:bf:bc:02:
+ f7:43:5e:c7:fe:b0:37:50:99:7b:0f:93:ce:e6:43:
+ 2c:c3:7e:0d:f2:1c:43:66:60:cb:61:31:47:87:a3:
+ 4f:ae:bd:56:6c:4c:bc:bc:f8:05:ca:64:f4:e9:34:
+ a1:2c:b5:73:e1:c2:3e:e8:c8:c9:34:25:08:5c:f3:
+ ed:a6:c7:94:9f:ad:88:43:25:d7:e1:39:60:fe:ac:
+ 39:59
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Subject Key Identifier:
+ 9F:EE:44:B3:94:D5:FA:91:4F:2E:D9:55:9A:04:56:DB:2D:C4:DB:A5
+ Signature Algorithm: sha1WithRSAEncryption
+ 7f:5f:b9:53:5b:63:3d:75:32:e7:fa:c4:74:1a:cb:46:df:46:
+ 69:1c:52:cf:aa:4f:c2:68:eb:ff:80:a9:51:e8:3d:62:77:89:
+ 3d:0a:75:39:f1:6e:5d:17:87:6f:68:05:c1:94:6c:d9:5d:df:
+ da:b2:59:cb:a5:10:8a:ca:cc:39:cd:9f:eb:4e:de:52:ff:0c:
+ f0:f4:92:a9:f2:6c:53:ab:9b:d2:47:a0:1f:74:f7:9b:9a:f1:
+ 2f:15:9f:7a:64:30:18:07:3c:2a:0f:67:ca:fc:0f:89:61:9d:
+ 65:a5:3c:e5:bc:13:5b:08:db:e3:ff:ed:bb:06:bb:6a:06:b1:
+ 7a:4f:65:c6:82:fd:1e:9c:8b:b5:0d:ee:48:bb:b8:bd:aa:08:
+ b4:fb:a3:7c:cb:9f:cd:90:76:5c:86:96:78:57:0a:66:f9:58:
+ 1a:9d:fd:97:29:60:de:11:a6:90:1c:19:1c:ee:01:96:22:34:
+ 34:2e:91:f9:b7:c4:27:d1:7b:e6:bf:fb:80:44:5a:16:e5:eb:
+ e0:d4:0a:38:bc:e4:91:e3:d5:eb:5c:c1:ac:df:1b:6a:7c:9e:
+ e5:75:d2:b6:97:87:db:cc:87:2b:43:3a:84:08:af:ab:3c:db:
+ f7:3c:66:31:86:b0:9d:53:79:ed:f8:23:de:42:e3:2d:82:f1:
+ 0f:e5:fa:97
+SHA1 Fingerprint=DD:E1:D2:A9:01:80:2E:1D:87:5E:84:B3:80:7E:4B:B1:FD:99:41:34
+-----BEGIN CERTIFICATE-----
+MIIDtjCCAp6gAwIBAgIQRJmNPMADJ72cdpW56tustTANBgkqhkiG9w0BAQUFADB1
+MQswCQYDVQQGEwJUUjEoMCYGA1UEChMfRWxla3Ryb25payBCaWxnaSBHdXZlbmxp
+Z2kgQS5TLjE8MDoGA1UEAxMzZS1HdXZlbiBLb2sgRWxla3Ryb25payBTZXJ0aWZp
+a2EgSGl6bWV0IFNhZ2xheWljaXNpMB4XDTA3MDEwNDExMzI0OFoXDTE3MDEwNDEx
+MzI0OFowdTELMAkGA1UEBhMCVFIxKDAmBgNVBAoTH0VsZWt0cm9uaWsgQmlsZ2kg
+R3V2ZW5saWdpIEEuUy4xPDA6BgNVBAMTM2UtR3V2ZW4gS29rIEVsZWt0cm9uaWsg
+U2VydGlmaWthIEhpem1ldCBTYWdsYXlpY2lzaTCCASIwDQYJKoZIhvcNAQEBBQAD
+ggEPADCCAQoCggEBAMMSIJ6wXgBljU5Gu4Bc6SwGl9XzcslwuedLZYDBS75+PNdU
+MZTe1RK6UxYC6lhj71vY8+0qGqpxSKPcEC1fX+tcS5yWCEIlKBHMilpiAVDV6wlT
+L/jDj/6z/P2douNffb7tC+Bg62nsM+3YjfsSSYMAyYuXjDtzKjKzEve5TfL0TW3H
+5tYmNwjy2f1rXKPlSFxYvEK+A1qBuhw1DADT9SN+cTAIJjjcJRFHLfO6IxClv7wC
+90Nex/6wN1CZew+TzuZDLMN+DfIcQ2Zgy2ExR4ejT669VmxMvLz4Bcpk9Ok0oSy1
+c+HCPujIyTQlCFzz7abHlJ+tiEMl1+E5YP6sOVkCAwEAAaNCMEAwDgYDVR0PAQH/
+BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wHQYDVR0OBBYEFJ/uRLOU1fqRTy7ZVZoE
+VtstxNulMA0GCSqGSIb3DQEBBQUAA4IBAQB/X7lTW2M9dTLn+sR0GstG30ZpHFLP
+qk/CaOv/gKlR6D1id4k9CnU58W5dF4dvaAXBlGzZXd/aslnLpRCKysw5zZ/rTt5S
+/wzw9JKp8mxTq5vSR6AfdPebmvEvFZ96ZDAYBzwqD2fK/A+JYZ1lpTzlvBNbCNvj
+/+27BrtqBrF6T2XGgv0enIu1De5Iu7i9qgi0+6N8y5/NkHZchpZ4Vwpm+Vganf2X
+KWDeEaaQHBkc7gGWIjQ0LpH5t8Qn0Xvmv/uARFoW5evg1Ao4vOSR49XrXMGs3xtq
+fJ7lddK2l4fbzIcrQzqECK+rPNv3PGYxhrCdU3nt+CPeQuMtgvEP5fqX
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/119afc2e.0 b/luni/src/main/files/cacerts/119afc2e.0
new file mode 100644
index 0000000..46f51b8
--- /dev/null
+++ b/luni/src/main/files/cacerts/119afc2e.0
@@ -0,0 +1,98 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 999181308 (0x3b8e4bfc)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: emailAddress=pki@sk.ee, C=EE, O=AS Sertifitseerimiskeskus, CN=Juur-SK
+ Validity
+ Not Before: Aug 30 14:23:01 2001 GMT
+ Not After : Aug 26 14:23:01 2016 GMT
+ Subject: emailAddress=pki@sk.ee, C=EE, O=AS Sertifitseerimiskeskus, CN=Juur-SK
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:81:71:36:3e:33:07:d6:e3:30:8d:13:7e:77:32:
+ 46:cb:cf:19:b2:60:31:46:97:86:f4:98:46:a4:c2:
+ 65:45:cf:d3:40:7c:e3:5a:22:a8:10:78:33:cc:88:
+ b1:d3:81:4a:f6:62:17:7b:5f:4d:0a:2e:d0:cf:8b:
+ 23:ee:4f:02:4e:bb:eb:0e:ca:bd:18:63:e8:80:1c:
+ 8d:e1:1c:8d:3d:e0:ff:5b:5f:ea:64:e5:97:e8:3f:
+ 99:7f:0c:0a:09:33:00:1a:53:a7:21:e1:38:4b:d6:
+ 83:1b:ad:af:64:c2:f9:1c:7a:8c:66:48:4d:66:1f:
+ 18:0a:e2:3e:bb:1f:07:65:93:85:b9:1a:b0:b9:c4:
+ fb:0d:11:f6:f5:d6:f9:1b:c7:2c:2b:b7:18:51:fe:
+ e0:7b:f6:a8:48:af:6c:3b:4f:2f:ef:f8:d1:47:1e:
+ 26:57:f0:51:1d:33:96:ff:ef:59:3d:da:4d:d1:15:
+ 34:c7:ea:3f:16:48:7b:91:1c:80:43:0f:3d:b8:05:
+ 3e:d1:b3:95:cd:d8:ca:0f:c2:43:67:db:b7:93:e0:
+ 22:82:2e:be:f5:68:28:83:b9:c1:3b:69:7b:20:da:
+ 4e:9c:6d:e1:ba:cd:8f:7a:6c:b0:09:22:d7:8b:0b:
+ db:1c:d5:5a:26:5b:0d:c0:ea:e5:60:d0:9f:fe:35:
+ df:3f
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Certificate Policies:
+ Policy: 1.3.6.1.4.1.10015.1.1.1
+ User Notice:
+ Explicit Text:
+ CPS: http://www.sk.ee/cps/
+
+ X509v3 CRL Distribution Points:
+ URI:http://www.sk.ee/juur/crl/
+
+ X509v3 Subject Key Identifier:
+ 04:AA:7A:47:A3:E4:89:AF:1A:CF:0A:40:A7:18:3F:6F:EF:E9:7D:BE
+ X509v3 Authority Key Identifier:
+ keyid:04:AA:7A:47:A3:E4:89:AF:1A:CF:0A:40:A7:18:3F:6F:EF:E9:7D:BE
+
+ X509v3 Key Usage: critical
+ Digital Signature, Non Repudiation, Key Encipherment, Certificate Sign, CRL Sign
+ Signature Algorithm: sha1WithRSAEncryption
+ 7b:c1:18:94:53:a2:09:f3:fe:26:67:9a:50:e4:c3:05:2f:2b:
+ 35:78:91:4c:7c:a8:11:11:79:4c:49:59:ac:c8:f7:85:65:5c:
+ 46:bb:3b:10:a0:02:af:cd:4f:b5:cc:36:2a:ec:5d:fe:ef:a0:
+ 91:c9:b6:93:6f:7c:80:54:ec:c7:08:70:0d:8e:fb:82:ec:2a:
+ 60:78:69:36:36:d1:c5:9c:8b:69:b5:40:c8:94:65:77:f2:57:
+ 21:66:3b:ce:85:40:b6:33:63:1a:bf:79:1e:fc:5c:1d:d3:1d:
+ 93:1b:8b:0c:5d:85:bd:99:30:32:18:09:91:52:e9:7c:a1:ba:
+ ff:64:92:9a:ec:fe:35:ee:8c:2f:ae:fc:20:86:ec:4a:de:1b:
+ 78:32:37:a6:81:d2:9d:af:5a:12:16:ca:99:5b:fc:6f:6d:0e:
+ c5:a0:1e:86:c9:91:d0:5c:98:82:5f:63:0c:8a:5a:ab:d8:95:
+ a6:cc:cb:8a:d6:bf:64:4b:8e:ca:8a:b2:b0:e9:21:32:9e:aa:
+ a8:85:98:34:81:39:21:3b:a8:3a:52:32:3d:f6:6b:37:86:06:
+ 5a:15:98:dc:f0:11:66:fe:34:20:b7:03:f4:41:10:7d:39:84:
+ 79:96:72:63:b6:96:02:e5:6b:b9:ad:19:4d:bb:c6:44:db:36:
+ cb:2a:9c:8e
+SHA1 Fingerprint=40:9D:4B:D9:17:B5:5C:27:B6:9B:64:CB:98:22:44:0D:CD:09:B8:89
+-----BEGIN CERTIFICATE-----
+MIIE5jCCA86gAwIBAgIEO45L/DANBgkqhkiG9w0BAQUFADBdMRgwFgYJKoZIhvcN
+AQkBFglwa2lAc2suZWUxCzAJBgNVBAYTAkVFMSIwIAYDVQQKExlBUyBTZXJ0aWZp
+dHNlZXJpbWlza2Vza3VzMRAwDgYDVQQDEwdKdXVyLVNLMB4XDTAxMDgzMDE0MjMw
+MVoXDTE2MDgyNjE0MjMwMVowXTEYMBYGCSqGSIb3DQEJARYJcGtpQHNrLmVlMQsw
+CQYDVQQGEwJFRTEiMCAGA1UEChMZQVMgU2VydGlmaXRzZWVyaW1pc2tlc2t1czEQ
+MA4GA1UEAxMHSnV1ci1TSzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
+AIFxNj4zB9bjMI0TfncyRsvPGbJgMUaXhvSYRqTCZUXP00B841oiqBB4M8yIsdOB
+SvZiF3tfTQou0M+LI+5PAk676w7KvRhj6IAcjeEcjT3g/1tf6mTll+g/mX8MCgkz
+ABpTpyHhOEvWgxutr2TC+Rx6jGZITWYfGAriPrsfB2WThbkasLnE+w0R9vXW+RvH
+LCu3GFH+4Hv2qEivbDtPL+/40UceJlfwUR0zlv/vWT3aTdEVNMfqPxZIe5EcgEMP
+PbgFPtGzlc3Yyg/CQ2fbt5PgIoIuvvVoKIO5wTtpeyDaTpxt4brNj3pssAki14sL
+2xzVWiZbDcDq5WDQn/413z8CAwEAAaOCAawwggGoMA8GA1UdEwEB/wQFMAMBAf8w
+ggEWBgNVHSAEggENMIIBCTCCAQUGCisGAQQBzh8BAQEwgfYwgdAGCCsGAQUFBwIC
+MIHDHoHAAFMAZQBlACAAcwBlAHIAdABpAGYAaQBrAGEAYQB0ACAAbwBuACAAdgDk
+AGwAagBhAHMAdABhAHQAdQBkACAAQQBTAC0AaQBzACAAUwBlAHIAdABpAGYAaQB0
+AHMAZQBlAHIAaQBtAGkAcwBrAGUAcwBrAHUAcwAgAGEAbABhAG0ALQBTAEsAIABz
+AGUAcgB0AGkAZgBpAGsAYQBhAHQAaQBkAGUAIABrAGkAbgBuAGkAdABhAG0AaQBz
+AGUAawBzMCEGCCsGAQUFBwIBFhVodHRwOi8vd3d3LnNrLmVlL2Nwcy8wKwYDVR0f
+BCQwIjAgoB6gHIYaaHR0cDovL3d3dy5zay5lZS9qdXVyL2NybC8wHQYDVR0OBBYE
+FASqekej5ImvGs8KQKcYP2/v6X2+MB8GA1UdIwQYMBaAFASqekej5ImvGs8KQKcY
+P2/v6X2+MA4GA1UdDwEB/wQEAwIB5jANBgkqhkiG9w0BAQUFAAOCAQEAe8EYlFOi
+CfP+JmeaUOTDBS8rNXiRTHyoERF5TElZrMj3hWVcRrs7EKACr81Ptcw2Kuxd/u+g
+kcm2k298gFTsxwhwDY77guwqYHhpNjbRxZyLabVAyJRld/JXIWY7zoVAtjNjGr95
+HvxcHdMdkxuLDF2FvZkwMhgJkVLpfKG6/2SSmuz+Ne6ML678IIbsSt4beDI3poHS
+na9aEhbKmVv8b20OxaAehsmR0FyYgl9jDIpaq9iVpszLita/ZEuOyoqysOkhMp6q
+qIWYNIE5ITuoOlIyPfZrN4YGWhWY3PARZv40ILcD9EEQfTmEeZZyY7aWAuVrua0Z
+TbvGRNs2yyqcjg==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/1eb37bdf.0 b/luni/src/main/files/cacerts/1eb37bdf.0
new file mode 100644
index 0000000..3f3287b
--- /dev/null
+++ b/luni/src/main/files/cacerts/1eb37bdf.0
@@ -0,0 +1,140 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ a3:da:42:7e:a4:b1:ae:da
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=EU, L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287, O=AC Camerfirma S.A., CN=Chambers of Commerce Root - 2008
+ Validity
+ Not Before: Aug 1 12:29:50 2008 GMT
+ Not After : Jul 31 12:29:50 2038 GMT
+ Subject: C=EU, L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287, O=AC Camerfirma S.A., CN=Chambers of Commerce Root - 2008
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:af:00:cb:70:37:2b:80:5a:4a:3a:6c:78:94:7d:
+ a3:7f:1a:1f:f6:35:d5:bd:db:cb:0d:44:72:3e:26:
+ b2:90:52:ba:63:3b:28:58:6f:a5:b3:6d:94:a6:f3:
+ dd:64:0c:55:f6:f6:e7:f2:22:22:80:5e:e1:62:c6:
+ b6:29:e1:81:6c:f2:bf:e5:7d:32:6a:54:a0:32:19:
+ 59:fe:1f:8b:d7:3d:60:86:85:24:6f:e3:11:b3:77:
+ 3e:20:96:35:21:6b:b3:08:d9:70:2e:64:f7:84:92:
+ 53:d6:0e:b0:90:8a:8a:e3:87:8d:06:d3:bd:90:0e:
+ e2:99:a1:1b:86:0e:da:9a:0a:bb:0b:61:50:06:52:
+ f1:9e:7f:76:ec:cb:0f:d0:1e:0d:cf:99:30:3d:1c:
+ c4:45:10:58:ac:d6:d3:e8:d7:e5:ea:c5:01:07:77:
+ d6:51:e6:03:7f:8a:48:a5:4d:68:75:b9:e9:bc:9e:
+ 4e:19:71:f5:32:4b:9c:6d:60:19:0b:fb:cc:9d:75:
+ dc:bf:26:cd:8f:93:78:39:79:73:5e:25:0e:ca:5c:
+ eb:77:12:07:cb:64:41:47:72:93:ab:50:c3:eb:09:
+ 76:64:34:d2:39:b7:76:11:09:0d:76:45:c4:a9:ae:
+ 3d:6a:af:b5:7d:65:2f:94:58:10:ec:5c:7c:af:7e:
+ e2:b6:18:d9:d0:9b:4e:5a:49:df:a9:66:0b:cc:3c:
+ c6:78:7c:a7:9c:1d:e3:ce:8e:53:be:05:de:60:0f:
+ 6b:e5:1a:db:3f:e3:e1:21:c9:29:c1:f1:eb:07:9c:
+ 52:1b:01:44:51:3c:7b:25:d7:c4:e5:52:54:5d:25:
+ 07:ca:16:20:b8:ad:e4:41:ee:7a:08:fe:99:6f:83:
+ a6:91:02:b0:6c:36:55:6a:e7:7d:f5:96:e6:ca:81:
+ d6:97:f1:94:83:e9:ed:b0:b1:6b:12:69:1e:ac:fb:
+ 5d:a9:c5:98:e9:b4:5b:58:7a:be:3d:a2:44:3a:63:
+ 59:d4:0b:25:de:1b:4f:bd:e5:01:9e:cd:d2:29:d5:
+ 9f:17:19:0a:6f:bf:0c:90:d3:09:5f:d9:e3:8a:35:
+ cc:79:5a:4d:19:37:92:b7:c4:c1:ad:af:f4:79:24:
+ 9a:b2:01:0b:b1:af:5c:96:f3:80:32:fb:5c:3d:98:
+ f1:a0:3f:4a:de:be:af:94:2e:d9:55:9a:17:6e:60:
+ 9d:63:6c:b8:63:c9:ae:81:5c:18:35:e0:90:bb:be:
+ 3c:4f:37:22:b9:7e:eb:cf:9e:77:21:a6:3d:38:81:
+ fb:48:da:31:3d:2b:e3:89:f5:d0:b5:bd:7e:e0:50:
+ c4:12:89:b3:23:9a:10:31:85:db:ae:6f:ef:38:33:
+ 18:76:11
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE, pathlen:12
+ X509v3 Subject Key Identifier:
+ F9:24:AC:0F:B2:B5:F8:79:C0:FA:60:88:1B:C4:D9:4D:02:9E:17:19
+ X509v3 Authority Key Identifier:
+ keyid:F9:24:AC:0F:B2:B5:F8:79:C0:FA:60:88:1B:C4:D9:4D:02:9E:17:19
+ DirName:/C=EU/L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287/O=AC Camerfirma S.A./CN=Chambers of Commerce Root - 2008
+ serial:A3:DA:42:7E:A4:B1:AE:DA
+
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Certificate Policies:
+ Policy: X509v3 Any Policy
+ CPS: http://policy.camerfirma.com
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 90:12:af:22:35:c2:a3:39:f0:2e:de:e9:b5:e9:78:7c:48:be:
+ 3f:7d:45:92:5e:e9:da:b1:19:fc:16:3c:9f:b4:5b:66:9e:6a:
+ e7:c3:b9:5d:88:e8:0f:ad:cf:23:0f:de:25:3a:5e:cc:4f:a5:
+ c1:b5:2d:ac:24:d2:58:07:de:a2:cf:69:84:60:33:e8:10:0d:
+ 13:a9:23:d0:85:e5:8e:7b:a6:9e:3d:72:13:72:33:f5:aa:7d:
+ c6:63:1f:08:f4:fe:01:7f:24:cf:2b:2c:54:09:de:e2:2b:6d:
+ 92:c6:39:4f:16:ea:3c:7e:7a:46:d4:45:6a:46:a8:eb:75:82:
+ 56:a7:ab:a0:7c:68:13:33:f6:9d:30:f0:6f:27:39:24:23:2a:
+ 90:fd:90:29:35:f2:93:df:34:a5:c6:f7:f8:ef:8c:0f:62:4a:
+ 7c:ae:d3:f5:54:f8:8d:b6:9a:56:87:16:82:3a:33:ab:5a:22:
+ 08:f7:82:ba:ea:2e:e0:47:9a:b4:b5:45:a3:05:3b:d9:dc:2e:
+ 45:40:3b:ea:dc:7f:e8:3b:eb:d1:ec:26:d8:35:a4:30:c5:3a:
+ ac:57:9e:b3:76:a5:20:7b:f9:1e:4a:05:62:01:a6:28:75:60:
+ 97:92:0d:6e:3e:4d:37:43:0d:92:15:9c:18:22:cd:51:99:a0:
+ 29:1a:3c:5f:8a:32:33:5b:30:c7:89:2f:47:98:0f:a3:03:c6:
+ f6:f1:ac:df:32:f0:d9:81:1a:e4:9c:bd:f6:80:14:f0:d1:2c:
+ b9:85:f5:d8:a3:b1:c8:a5:21:e5:1c:13:97:ee:0e:bd:df:29:
+ a9:ef:34:53:5b:d3:e4:6a:13:84:06:b6:32:02:c4:52:ae:22:
+ d2:dc:b2:21:42:1a:da:40:f0:29:c9:ec:0a:0c:5c:e2:d0:ba:
+ cc:48:d3:37:0a:cc:12:0a:8a:79:b0:3d:03:7f:69:4b:f4:34:
+ 20:7d:b3:34:ea:8e:4b:64:f5:3e:fd:b3:23:67:15:0d:04:b8:
+ f0:2d:c1:09:51:3c:b2:6c:15:f0:a5:23:d7:83:74:e4:e5:2e:
+ c9:fe:98:27:42:c6:ab:c6:9e:b0:d0:5b:38:a5:9b:50:de:7e:
+ 18:98:b5:45:3b:f6:79:b4:e8:f7:1a:7b:06:83:fb:d0:8b:da:
+ bb:c7:bd:18:ab:08:6f:3c:80:6b:40:3f:19:19:ba:65:8a:e6:
+ be:d5:5c:d3:36:d7:ef:40:52:24:60:38:67:04:31:ec:8f:f3:
+ 82:c6:de:b9:55:f3:3b:31:91:5a:dc:b5:08:15:ad:76:25:0a:
+ 0d:7b:2e:87:e2:0c:a6:06:bc:26:10:6d:37:9d:ec:dd:78:8c:
+ 7c:80:c5:f0:d9:77:48:d0
+SHA1 Fingerprint=78:6A:74:AC:76:AB:14:7F:9C:6A:30:50:BA:9E:A8:7E:FE:9A:CE:3C
+-----BEGIN CERTIFICATE-----
+MIIHTzCCBTegAwIBAgIJAKPaQn6ksa7aMA0GCSqGSIb3DQEBBQUAMIGuMQswCQYD
+VQQGEwJFVTFDMEEGA1UEBxM6TWFkcmlkIChzZWUgY3VycmVudCBhZGRyZXNzIGF0
+IHd3dy5jYW1lcmZpcm1hLmNvbS9hZGRyZXNzKTESMBAGA1UEBRMJQTgyNzQzMjg3
+MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMuQS4xKTAnBgNVBAMTIENoYW1iZXJz
+IG9mIENvbW1lcmNlIFJvb3QgLSAyMDA4MB4XDTA4MDgwMTEyMjk1MFoXDTM4MDcz
+MTEyMjk1MFowga4xCzAJBgNVBAYTAkVVMUMwQQYDVQQHEzpNYWRyaWQgKHNlZSBj
+dXJyZW50IGFkZHJlc3MgYXQgd3d3LmNhbWVyZmlybWEuY29tL2FkZHJlc3MpMRIw
+EAYDVQQFEwlBODI3NDMyODcxGzAZBgNVBAoTEkFDIENhbWVyZmlybWEgUy5BLjEp
+MCcGA1UEAxMgQ2hhbWJlcnMgb2YgQ29tbWVyY2UgUm9vdCAtIDIwMDgwggIiMA0G
+CSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCvAMtwNyuAWko6bHiUfaN/Gh/2NdW9
+28sNRHI+JrKQUrpjOyhYb6WzbZSm891kDFX29ufyIiKAXuFixrYp4YFs8r/lfTJq
+VKAyGVn+H4vXPWCGhSRv4xGzdz4gljUha7MI2XAuZPeEklPWDrCQiorjh40G072Q
+DuKZoRuGDtqaCrsLYVAGUvGef3bsyw/QHg3PmTA9HMRFEFis1tPo1+XqxQEHd9ZR
+5gN/ikilTWh1uem8nk4ZcfUyS5xtYBkL+8ydddy/Js2Pk3g5eXNeJQ7KXOt3EgfL
+ZEFHcpOrUMPrCXZkNNI5t3YRCQ12RcSprj1qr7V9ZS+UWBDsXHyvfuK2GNnQm05a
+Sd+pZgvMPMZ4fKecHePOjlO+Bd5gD2vlGts/4+EhySnB8esHnFIbAURRPHsl18Tl
+UlRdJQfKFiC4reRB7noI/plvg6aRArBsNlVq5331lubKgdaX8ZSD6e2wsWsSaR6s
++12pxZjptFtYer49okQ6Y1nUCyXeG0+95QGezdIp1Z8XGQpvvwyQ0wlf2eOKNcx5
+Wk0ZN5K3xMGtr/R5JJqyAQuxr1yW84Ay+1w9mPGgP0revq+ULtlVmhduYJ1jbLhj
+ya6BXBg14JC7vjxPNyK5fuvPnnchpj04gftI2jE9K+OJ9dC1vX7gUMQSibMjmhAx
+hduub+84Mxh2EQIDAQABo4IBbDCCAWgwEgYDVR0TAQH/BAgwBgEB/wIBDDAdBgNV
+HQ4EFgQU+SSsD7K1+HnA+mCIG8TZTQKeFxkwgeMGA1UdIwSB2zCB2IAU+SSsD7K1
++HnA+mCIG8TZTQKeFxmhgbSkgbEwga4xCzAJBgNVBAYTAkVVMUMwQQYDVQQHEzpN
+YWRyaWQgKHNlZSBjdXJyZW50IGFkZHJlc3MgYXQgd3d3LmNhbWVyZmlybWEuY29t
+L2FkZHJlc3MpMRIwEAYDVQQFEwlBODI3NDMyODcxGzAZBgNVBAoTEkFDIENhbWVy
+ZmlybWEgUy5BLjEpMCcGA1UEAxMgQ2hhbWJlcnMgb2YgQ29tbWVyY2UgUm9vdCAt
+IDIwMDiCCQCj2kJ+pLGu2jAOBgNVHQ8BAf8EBAMCAQYwPQYDVR0gBDYwNDAyBgRV
+HSAAMCowKAYIKwYBBQUHAgEWHGh0dHA6Ly9wb2xpY3kuY2FtZXJmaXJtYS5jb20w
+DQYJKoZIhvcNAQEFBQADggIBAJASryI1wqM58C7e6bXpeHxIvj99RZJe6dqxGfwW
+PJ+0W2aeaufDuV2I6A+tzyMP3iU6XsxPpcG1Lawk0lgH3qLPaYRgM+gQDROpI9CF
+5Y57pp49chNyM/WqfcZjHwj0/gF/JM8rLFQJ3uIrbZLGOU8W6jx+ekbURWpGqOt1
+glanq6B8aBMz9p0w8G8nOSQjKpD9kCk18pPfNKXG9/jvjA9iSnyu0/VU+I22mlaH
+FoI6M6taIgj3grrqLuBHmrS1RaMFO9ncLkVAO+rcf+g769HsJtg1pDDFOqxXnrN2
+pSB7+R5KBWIBpih1YJeSDW4+TTdDDZIVnBgizVGZoCkaPF+KMjNbMMeJL0eYD6MD
+xvbxrN8y8NmBGuScvfaAFPDRLLmF9dijscilIeUcE5fuDr3fKanvNFNb0+RqE4QG
+tjICxFKuItLcsiFCGtpA8CnJ7AoMXOLQusxI0zcKzBIKinmwPQN/aUv0NCB9szTq
+jktk9T79syNnFQ0EuPAtwQlRPLJsFfClI9eDdOTlLsn+mCdCxqvGnrDQWzilm1De
+fhiYtUU79nm06PcaewaD+9CL2rvHvRirCG88gGtAPxkZumWK5r7VXNM21+9AUiRg
+OGcEMeyP84LG3rlV8zsxkVrctQgVrXYlCg17LofiDKYGvCYQbTed7N14jHyAxfDZ
+d0jQ
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/256fd83b.0 b/luni/src/main/files/cacerts/256fd83b.0
deleted file mode 100644
index 39ef065..0000000
--- a/luni/src/main/files/cacerts/256fd83b.0
+++ /dev/null
@@ -1,63 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1002 (0x3ea)
- Signature Algorithm: md5WithRSAEncryption
- Issuer: C=DE, ST=Hamburg, L=Hamburg, O=TC TrustCenter for Security in Data Networks GmbH, OU=TC TrustCenter Class 2 CA/emailAddress=certificate@trustcenter.de
- Validity
- Not Before: Mar 9 11:59:59 1998 GMT
- Not After : Jan 1 11:59:59 2011 GMT
- Subject: C=DE, ST=Hamburg, L=Hamburg, O=TC TrustCenter for Security in Data Networks GmbH, OU=TC TrustCenter Class 2 CA/emailAddress=certificate@trustcenter.de
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public Key: (1024 bit)
- Modulus (1024 bit):
- 00:da:38:e8:ed:32:00:29:71:83:01:0d:bf:8c:01:
- dc:da:c6:ad:39:a4:a9:8a:2f:d5:8b:5c:68:5f:50:
- c6:62:f5:66:bd:ca:91:22:ec:aa:1d:51:d7:3d:b3:
- 51:b2:83:4e:5d:cb:49:b0:f0:4c:55:e5:6b:2d:c7:
- 85:0b:30:1c:92:4e:82:d4:ca:02:ed:f7:6f:be:dc:
- e0:e3:14:b8:05:53:f2:9a:f4:56:8b:5a:9e:85:93:
- d1:b4:82:56:ae:4d:bb:a8:4b:57:16:bc:fe:f8:58:
- 9e:f8:29:8d:b0:7b:cd:78:c9:4f:ac:8b:67:0c:f1:
- 9c:fb:fc:57:9b:57:5c:4f:0d
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints: critical
- CA:TRUE
- X509v3 Key Usage: critical
- Digital Signature, Certificate Sign, CRL Sign
- Netscape CA Policy Url:
- http://www.trustcenter.de/guidelines
- Netscape Cert Type:
- SSL CA, S/MIME CA, Object Signing CA
- Signature Algorithm: md5WithRSAEncryption
- 84:52:fb:28:df:ff:1f:75:01:bc:01:be:04:56:97:6a:74:42:
- 24:31:83:f9:46:b1:06:8a:89:cf:96:2c:33:bf:8c:b5:5f:7a:
- 72:a1:85:06:ce:86:f8:05:8e:e8:f9:25:ca:da:83:8c:06:ac:
- eb:36:6d:85:91:34:04:36:f4:42:f0:f8:79:2e:0a:48:5c:ab:
- cc:51:4f:78:76:a0:d9:ac:19:bd:2a:d1:69:04:28:91:ca:36:
- 10:27:80:57:5b:d2:5c:f5:c2:5b:ab:64:81:63:74:51:f4:97:
- bf:cd:12:28:f7:4d:66:7f:a7:f0:1c:01:26:78:b2:66:47:70:
- 51:64
-SHA1 Fingerprint=83:8E:30:F7:7F:DD:14:AA:38:5E:D1:45:00:9C:0E:22:36:49:4F:AA
------BEGIN CERTIFICATE-----
-MIIDXDCCAsWgAwIBAgICA+owDQYJKoZIhvcNAQEEBQAwgbwxCzAJBgNVBAYTAkRF
-MRAwDgYDVQQIEwdIYW1idXJnMRAwDgYDVQQHEwdIYW1idXJnMTowOAYDVQQKEzFU
-QyBUcnVzdENlbnRlciBmb3IgU2VjdXJpdHkgaW4gRGF0YSBOZXR3b3JrcyBHbWJI
-MSIwIAYDVQQLExlUQyBUcnVzdENlbnRlciBDbGFzcyAyIENBMSkwJwYJKoZIhvcN
-AQkBFhpjZXJ0aWZpY2F0ZUB0cnVzdGNlbnRlci5kZTAeFw05ODAzMDkxMTU5NTla
-Fw0xMTAxMDExMTU5NTlaMIG8MQswCQYDVQQGEwJERTEQMA4GA1UECBMHSGFtYnVy
-ZzEQMA4GA1UEBxMHSGFtYnVyZzE6MDgGA1UEChMxVEMgVHJ1c3RDZW50ZXIgZm9y
-IFNlY3VyaXR5IGluIERhdGEgTmV0d29ya3MgR21iSDEiMCAGA1UECxMZVEMgVHJ1
-c3RDZW50ZXIgQ2xhc3MgMiBDQTEpMCcGCSqGSIb3DQEJARYaY2VydGlmaWNhdGVA
-dHJ1c3RjZW50ZXIuZGUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANo46O0y
-AClxgwENv4wB3NrGrTmkqYov1YtcaF9QxmL1Zr3KkSLsqh1R1z2zUbKDTl3LSbDw
-TFXlay3HhQswHJJOgtTKAu33b77c4OMUuAVT8pr0VotanoWT0bSCVq5Nu6hLVxa8
-/vhYnvgpjbB7zXjJT6yLZwzxnPv8V5tXXE8NAgMBAAGjazBpMA8GA1UdEwEB/wQF
-MAMBAf8wDgYDVR0PAQH/BAQDAgGGMDMGCWCGSAGG+EIBCAQmFiRodHRwOi8vd3d3
-LnRydXN0Y2VudGVyLmRlL2d1aWRlbGluZXMwEQYJYIZIAYb4QgEBBAQDAgAHMA0G
-CSqGSIb3DQEBBAUAA4GBAIRS+yjf/x91AbwBvgRWl2p0QiQxg/lGsQaKic+WLDO/
-jLVfenKhhQbOhvgFjuj5Jcrag4wGrOs2bYWRNAQ29ELw+HkuCkhcq8xRT3h2oNms
-Gb0q0WkEKJHKNhAngFdb0lz1wlurZIFjdFH0l7/NEij3TWZ/p/AcASZ4smZHcFFk
------END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/27af790d.0 b/luni/src/main/files/cacerts/27af790d.0
new file mode 100644
index 0000000..8b1448b
--- /dev/null
+++ b/luni/src/main/files/cacerts/27af790d.0
@@ -0,0 +1,55 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 3c:b2:f4:48:0a:00:e2:fe:eb:24:3b:5e:60:3e:c3:6b
+ Signature Algorithm: ecdsa-with-SHA384
+ Issuer: C=US, O=GeoTrust Inc., OU=(c) 2007 GeoTrust Inc. - For authorized use only, CN=GeoTrust Primary Certification Authority - G2
+ Validity
+ Not Before: Nov 5 00:00:00 2007 GMT
+ Not After : Jan 18 23:59:59 2038 GMT
+ Subject: C=US, O=GeoTrust Inc., OU=(c) 2007 GeoTrust Inc. - For authorized use only, CN=GeoTrust Primary Certification Authority - G2
+ Subject Public Key Info:
+ Public Key Algorithm: id-ecPublicKey
+ EC Public Key:
+ pub:
+ 04:15:b1:e8:fd:03:15:43:e5:ac:eb:87:37:11:62:
+ ef:d2:83:36:52:7d:45:57:0b:4a:8d:7b:54:3b:3a:
+ 6e:5f:15:02:c0:50:a6:cf:25:2f:7d:ca:48:b8:c7:
+ 50:63:1c:2a:21:08:7c:9a:36:d8:0b:fe:d1:26:c5:
+ 58:31:30:28:25:f3:5d:5d:a3:b8:b6:a5:b4:92:ed:
+ 6c:2c:9f:eb:dd:43:89:a2:3c:4b:48:91:1d:50:ec:
+ 26:df:d6:60:2e:bd:21
+ ASN1 OID: secp384r1
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ 15:5F:35:57:51:55:FB:25:B2:AD:03:69:FC:01:A3:FA:BE:11:55:D5
+ Signature Algorithm: ecdsa-with-SHA384
+ 30:64:02:30:64:96:59:a6:e8:09:de:8b:ba:fa:5a:88:88:f0:
+ 1f:91:d3:46:a8:f2:4a:4c:02:63:fb:6c:5f:38:db:2e:41:93:
+ a9:0e:e6:9d:dc:31:1c:b2:a0:a7:18:1c:79:e1:c7:36:02:30:
+ 3a:56:af:9a:74:6c:f6:fb:83:e0:33:d3:08:5f:a1:9c:c2:5b:
+ 9f:46:d6:b6:cb:91:06:63:a2:06:e7:33:ac:3e:a8:81:12:d0:
+ cb:ba:d0:92:0b:b6:9e:96:aa:04:0f:8a
+SHA1 Fingerprint=8D:17:84:D5:37:F3:03:7D:EC:70:FE:57:8B:51:9A:99:E6:10:D7:B0
+-----BEGIN CERTIFICATE-----
+MIICrjCCAjWgAwIBAgIQPLL0SAoA4v7rJDteYD7DazAKBggqhkjOPQQDAzCBmDEL
+MAkGA1UEBhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsTMChj
+KSAyMDA3IEdlb1RydXN0IEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25seTE2
+MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0
+eSAtIEcyMB4XDTA3MTEwNTAwMDAwMFoXDTM4MDExODIzNTk1OVowgZgxCzAJBgNV
+BAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAoYykgMjAw
+NyBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0BgNV
+BAMTLUdlb1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgLSBH
+MjB2MBAGByqGSM49AgEGBSuBBAAiA2IABBWx6P0DFUPlrOuHNxFi79KDNlJ9RVcL
+So17VDs6bl8VAsBQps8lL33KSLjHUGMcKiEIfJo22Av+0SbFWDEwKCXzXV2juLal
+tJLtbCyf691DiaI8S0iRHVDsJt/WYC69IaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAO
+BgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFBVfNVdRVfslsq0DafwBo/q+EVXVMAoG
+CCqGSM49BAMDA2cAMGQCMGSWWaboCd6LuvpaiIjwH5HTRqjySkwCY/tsXzjbLkGT
+qQ7mndwxHLKgpxgceeHHNgIwOlavmnRs9vuD4DPTCF+hnMJbn0bWtsuRBmOiBucz
+rD6ogRLQy7rQkgu2npaqBA+K
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/3d441de8.0 b/luni/src/main/files/cacerts/3d441de8.0
new file mode 100644
index 0000000..3d68ea4
--- /dev/null
+++ b/luni/src/main/files/cacerts/3d441de8.0
@@ -0,0 +1,125 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 10000012 (0x98968c)
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=NL, O=Staat der Nederlanden, CN=Staat der Nederlanden Root CA - G2
+ Validity
+ Not Before: Mar 26 11:18:17 2008 GMT
+ Not After : Mar 25 11:03:10 2020 GMT
+ Subject: C=NL, O=Staat der Nederlanden, CN=Staat der Nederlanden Root CA - G2
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:c5:59:e7:6f:75:aa:3e:4b:9c:b5:b8:ac:9e:0b:
+ e4:f9:d9:ca:ab:5d:8f:b5:39:10:82:d7:af:51:e0:
+ 3b:e1:00:48:6a:cf:da:e1:06:43:11:99:aa:14:25:
+ 12:ad:22:e8:00:6d:43:c4:a9:b8:e5:1f:89:4b:67:
+ bd:61:48:ef:fd:d2:e0:60:88:e5:b9:18:60:28:c3:
+ 77:2b:ad:b0:37:aa:37:de:64:59:2a:46:57:e4:4b:
+ b9:f8:37:7c:d5:36:e7:80:c1:b6:f3:d4:67:9b:96:
+ e8:ce:d7:c6:0a:53:d0:6b:49:96:f3:a3:0b:05:77:
+ 48:f7:25:e5:70:ac:30:14:20:25:e3:7f:75:5a:e5:
+ 48:f8:4e:7b:03:07:04:fa:82:61:87:6e:f0:3b:c4:
+ a4:c7:d0:f5:74:3e:a5:5d:1a:08:f2:9b:25:d2:f6:
+ ac:04:26:3e:55:3a:62:28:a5:7b:b2:30:af:f8:37:
+ c2:d1:ba:d6:38:fd:f4:ef:49:30:37:99:26:21:48:
+ 85:01:a9:e5:16:e7:dc:90:55:df:0f:e8:38:cd:99:
+ 37:21:4f:5d:f5:22:6f:6a:c5:12:16:60:17:55:f2:
+ 65:66:a6:a7:30:91:38:c1:38:1d:86:04:84:ba:1a:
+ 25:78:5e:9d:af:cc:50:60:d6:13:87:52:ed:63:1f:
+ 6d:65:7d:c2:15:18:74:ca:e1:7e:64:29:8c:72:d8:
+ 16:13:7d:0b:49:4a:f1:28:1b:20:74:6b:c5:3d:dd:
+ b0:aa:48:09:3d:2e:82:94:cd:1a:65:d9:2b:88:9a:
+ 99:bc:18:7e:9f:ee:7d:66:7c:3e:bd:94:b8:81:ce:
+ cd:98:30:78:c1:6f:67:d0:be:5f:e0:68:ed:de:e2:
+ b1:c9:2c:59:78:92:aa:df:2b:60:63:f2:e5:5e:b9:
+ e3:ca:fa:7f:50:86:3e:a2:34:18:0c:09:68:28:11:
+ 1c:e4:e1:b9:5c:3e:47:ba:32:3f:18:cc:5b:84:f5:
+ f3:6b:74:c4:72:74:e1:e3:8b:a0:4a:bd:8d:66:2f:
+ ea:ad:35:da:20:d3:88:82:61:f0:12:22:b6:bc:d0:
+ d5:a4:ec:af:54:88:25:24:3c:a7:6d:b1:72:29:3f:
+ 3e:57:a6:7f:55:af:6e:26:c6:fe:e7:cc:40:5c:51:
+ 44:81:0a:78:de:4a:ce:55:bf:1d:d5:d9:b7:56:ef:
+ f0:76:ff:0b:79:b5:af:bd:fb:a9:69:91:46:97:68:
+ 80:14:36:1d:b3:7f:bb:29:98:36:a5:20:fa:82:60:
+ 62:33:a4:ec:d6:ba:07:a7:6e:c5:cf:14:a6:e7:d6:
+ 92:34:d8:81:f5:fc:1d:5d:aa:5c:1e:f6:a3:4d:3b:
+ b8:f7:39
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Certificate Policies:
+ Policy: X509v3 Any Policy
+ CPS: http://www.pkioverheid.nl/policies/root-policy-G2
+
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ 91:68:32:87:15:1D:89:E2:B5:F1:AC:36:28:34:8D:0B:7C:62:88:EB
+ Signature Algorithm: sha256WithRSAEncryption
+ a8:41:4a:67:2a:92:81:82:50:6e:e1:d7:d8:b3:39:3b:f3:02:
+ 15:09:50:51:ef:2d:bd:24:7b:88:86:3b:f9:b4:bc:92:09:96:
+ b9:f6:c0:ab:23:60:06:79:8c:11:4e:51:d2:79:80:33:fb:9d:
+ 48:be:ec:41:43:81:1f:7e:47:40:1c:e5:7a:08:ca:aa:8b:75:
+ ad:14:c4:c2:e8:66:3c:82:07:a7:e6:27:82:5b:18:e6:0f:6e:
+ d9:50:3e:8a:42:18:29:c6:b4:56:fc:56:10:a0:05:17:bd:0c:
+ 23:7f:f4:93:ed:9c:1a:51:be:dd:45:41:bf:91:24:b4:1f:8c:
+ e9:5f:cf:7b:21:99:9f:95:9f:39:3a:46:1c:6c:f9:cd:7b:9c:
+ 90:cd:28:a9:c7:a9:55:bb:ac:62:34:62:35:13:4b:14:3a:55:
+ 83:b9:86:8d:92:a6:c6:f4:07:25:54:cc:16:57:12:4a:82:78:
+ c8:14:d9:17:82:26:2d:5d:20:1f:79:ae:fe:d4:70:16:16:95:
+ 83:d8:35:39:ff:52:5d:75:1c:16:c5:13:55:cf:47:cc:75:65:
+ 52:4a:de:f0:b0:a7:e4:0a:96:0b:fb:ad:c2:e2:25:84:b2:dd:
+ e4:bd:7e:59:6c:9b:f0:f0:d8:e7:ca:f2:e9:97:38:7e:89:be:
+ cc:fb:39:17:61:3f:72:db:3a:91:d8:65:01:19:1d:ad:50:a4:
+ 57:0a:7c:4b:bc:9c:71:73:2a:45:51:19:85:cc:8e:fd:47:a7:
+ 74:95:1d:a8:d1:af:4e:17:b1:69:26:c2:aa:78:57:5b:c5:4d:
+ a7:e5:9e:05:17:94:ca:b2:5f:a0:49:18:8d:34:e9:26:6c:48:
+ 1e:aa:68:92:05:e1:82:73:5a:9b:dc:07:5b:08:6d:7d:9d:d7:
+ 8d:21:d9:fc:14:20:aa:c2:45:df:3f:e7:00:b2:51:e4:c2:f8:
+ 05:b9:79:1a:8c:34:f3:9e:5b:e4:37:5b:6b:4a:df:2c:57:8a:
+ 40:5a:36:ba:dd:75:44:08:37:42:70:0c:fe:dc:5e:21:a0:a3:
+ 8a:c0:90:9c:68:da:50:e6:45:10:47:78:b6:4e:d2:65:c9:c3:
+ 37:df:e1:42:63:b0:57:37:45:2d:7b:8a:9c:bf:05:ea:65:55:
+ 33:f7:39:10:c5:28:2a:21:7a:1b:8a:c4:24:f9:3f:15:c8:9a:
+ 15:20:f5:55:62:96:ed:6d:93:50:bc:e4:aa:78:ad:d9:cb:0a:
+ 65:87:a6:66:c1:c4:81:a3:77:3a:58:1e:0b:ee:83:8b:9d:1e:
+ d2:52:a4:cc:1d:6f:b0:98:6d:94:31:b5:f8:71:0a:dc:b9:fc:
+ 7d:32:60:e6:eb:af:8a:01
+SHA1 Fingerprint=59:AF:82:79:91:86:C7:B4:75:07:CB:CF:03:57:46:EB:04:DD:B7:16
+-----BEGIN CERTIFICATE-----
+MIIFyjCCA7KgAwIBAgIEAJiWjDANBgkqhkiG9w0BAQsFADBaMQswCQYDVQQGEwJO
+TDEeMBwGA1UECgwVU3RhYXQgZGVyIE5lZGVybGFuZGVuMSswKQYDVQQDDCJTdGFh
+dCBkZXIgTmVkZXJsYW5kZW4gUm9vdCBDQSAtIEcyMB4XDTA4MDMyNjExMTgxN1oX
+DTIwMDMyNTExMDMxMFowWjELMAkGA1UEBhMCTkwxHjAcBgNVBAoMFVN0YWF0IGRl
+ciBOZWRlcmxhbmRlbjErMCkGA1UEAwwiU3RhYXQgZGVyIE5lZGVybGFuZGVuIFJv
+b3QgQ0EgLSBHMjCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAMVZ5291
+qj5LnLW4rJ4L5PnZyqtdj7U5EILXr1HgO+EASGrP2uEGQxGZqhQlEq0i6ABtQ8Sp
+uOUfiUtnvWFI7/3S4GCI5bkYYCjDdyutsDeqN95kWSpGV+RLufg3fNU254DBtvPU
+Z5uW6M7XxgpT0GtJlvOjCwV3SPcl5XCsMBQgJeN/dVrlSPhOewMHBPqCYYdu8DvE
+pMfQ9XQ+pV0aCPKbJdL2rAQmPlU6Yiile7Iwr/g3wtG61jj99O9JMDeZJiFIhQGp
+5Rbn3JBV3w/oOM2ZNyFPXfUib2rFEhZgF1XyZWampzCROME4HYYEhLoaJXhena/M
+UGDWE4dS7WMfbWV9whUYdMrhfmQpjHLYFhN9C0lK8SgbIHRrxT3dsKpICT0ugpTN
+GmXZK4iambwYfp/ufWZ8Pr2UuIHOzZgweMFvZ9C+X+Bo7d7iscksWXiSqt8rYGPy
+5V6548r6f1CGPqI0GAwJaCgRHOThuVw+R7oyPxjMW4T182t0xHJ04eOLoEq9jWYv
+6q012iDTiIJh8BIitrzQ1aTsr1SIJSQ8p22xcik/Plemf1WvbibG/ufMQFxRRIEK
+eN5KzlW/HdXZt1bv8Hb/C3m1r737qWmRRpdogBQ2HbN/uymYNqUg+oJgYjOk7Na6
+B6duxc8UpufWkjTYgfX8HV2qXB72o007uPc5AgMBAAGjgZcwgZQwDwYDVR0TAQH/
+BAUwAwEB/zBSBgNVHSAESzBJMEcGBFUdIAAwPzA9BggrBgEFBQcCARYxaHR0cDov
+L3d3dy5wa2lvdmVyaGVpZC5ubC9wb2xpY2llcy9yb290LXBvbGljeS1HMjAOBgNV
+HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFJFoMocVHYnitfGsNig0jQt8YojrMA0GCSqG
+SIb3DQEBCwUAA4ICAQCoQUpnKpKBglBu4dfYszk78wIVCVBR7y29JHuIhjv5tLyS
+CZa59sCrI2AGeYwRTlHSeYAz+51IvuxBQ4EffkdAHOV6CMqqi3WtFMTC6GY8ggen
+5ieCWxjmD27ZUD6KQhgpxrRW/FYQoAUXvQwjf/ST7ZwaUb7dRUG/kSS0H4zpX897
+IZmflZ85OkYcbPnNe5yQzSipx6lVu6xiNGI1E0sUOlWDuYaNkqbG9AclVMwWVxJK
+gnjIFNkXgiYtXSAfea7+1HAWFpWD2DU5/1JddRwWxRNVz0fMdWVSSt7wsKfkCpYL
++63C4iWEst3kvX5ZbJvw8NjnyvLplzh+ib7M+zkXYT9y2zqR2GUBGR2tUKRXCnxL
+vJxxcypFURmFzI79R6d0lR2o0a9OF7FpJsKqeFdbxU2n5Z4FF5TKsl+gSRiNNOkm
+bEgeqmiSBeGCc1qb3AdbCG19ndeNIdn8FCCqwkXfP+cAslHkwvgFuXkajDTznlvk
+N1trSt8sV4pAWja63XVECDdCcAz+3F4hoKOKwJCcaNpQ5kUQR3i2TtJlycM33+FC
+Y7BXN0Ute4qcvwXqZVUz9zkQxSgqIXobisQk+T8VyJoVIPVVYpbtbZNQvOSqeK3Z
+ywplh6ZmwcSBo3c6WB4L7oOLnR7SUqTMHW+wmG2UMbX4cQrcufx9MmDm66+KAQ==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/418595b9.0 b/luni/src/main/files/cacerts/418595b9.0
new file mode 100644
index 0000000..a55863e
--- /dev/null
+++ b/luni/src/main/files/cacerts/418595b9.0
@@ -0,0 +1,87 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 17 (0x11)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=TR, L=Gebze - Kocaeli, O=T\xC3\xBCrkiye Bilimsel ve Teknolojik Ara\xC5\x9Ft\xC4\xB1rma Kurumu - T\xC3\x9CB\xC4\xB0TAK, OU=Ulusal Elektronik ve Kriptoloji Ara\xC5\x9Ft\xC4\xB1rma Enstit\xC3\xBCs\xC3\xBC - UEKAE, OU=Kamu Sertifikasyon Merkezi, CN=T\xC3\x9CB\xC4\xB0TAK UEKAE K\xC3\xB6k Sertifika Hizmet Sa\xC4\x9Flay\xC4\xB1c\xC4\xB1s\xC4\xB1 - S\xC3\xBCr\xC3\xBCm 3
+ Validity
+ Not Before: Aug 24 11:37:07 2007 GMT
+ Not After : Aug 21 11:37:07 2017 GMT
+ Subject: C=TR, L=Gebze - Kocaeli, O=T\xC3\xBCrkiye Bilimsel ve Teknolojik Ara\xC5\x9Ft\xC4\xB1rma Kurumu - T\xC3\x9CB\xC4\xB0TAK, OU=Ulusal Elektronik ve Kriptoloji Ara\xC5\x9Ft\xC4\xB1rma Enstit\xC3\xBCs\xC3\xBC - UEKAE, OU=Kamu Sertifikasyon Merkezi, CN=T\xC3\x9CB\xC4\xB0TAK UEKAE K\xC3\xB6k Sertifika Hizmet Sa\xC4\x9Flay\xC4\xB1c\xC4\xB1s\xC4\xB1 - S\xC3\xBCr\xC3\xBCm 3
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:8a:6d:4b:ff:10:88:3a:c3:f6:7e:94:e8:ea:20:
+ 64:70:ae:21:81:be:3a:7b:3c:db:f1:1d:52:7f:59:
+ fa:f3:22:4c:95:a0:90:bc:48:4e:11:ab:fb:b7:b5:
+ 8d:7a:83:28:8c:26:46:d8:4e:95:40:87:61:9f:c5:
+ 9e:6d:81:87:57:6c:8a:3b:b4:66:ea:cc:40:fc:e3:
+ aa:6c:b2:cb:01:db:32:bf:d2:eb:85:cf:a1:0d:55:
+ c3:5b:38:57:70:b8:75:c6:79:d1:14:30:ed:1b:58:
+ 5b:6b:ef:35:f2:a1:21:4e:c5:ce:7c:99:5f:6c:b9:
+ b8:22:93:50:a7:cd:4c:70:6a:be:6a:05:7f:13:9c:
+ 2b:1e:ea:fe:47:ce:04:a5:6f:ac:93:2e:7c:2b:9f:
+ 9e:79:13:91:e8:ea:9e:ca:38:75:8e:62:b0:95:93:
+ 2a:e5:df:e9:5e:97:6e:20:5f:5f:84:7a:44:39:19:
+ 40:1c:ba:55:2b:fb:30:b2:81:ef:84:e3:dc:ec:98:
+ 38:39:03:85:08:a9:54:03:05:29:f0:c9:8f:8b:ea:
+ 0b:86:65:19:11:d3:e9:09:23:de:68:93:03:c9:36:
+ 1c:21:6e:ce:8c:66:f1:99:30:d8:d7:b3:c3:1d:f8:
+ 81:2e:a8:bd:82:0b:66:fe:82:cb:e1:e0:1a:82:c3:
+ 40:81
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ BD:88:87:C9:8F:F6:A4:0A:0B:AA:EB:C5:FE:91:23:9D:AB:4A:8A:32
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ Signature Algorithm: sha1WithRSAEncryption
+ 1d:7c:fa:49:8f:34:e9:b7:26:92:16:9a:05:74:e7:4b:d0:6d:
+ 39:6c:c3:26:f6:ce:b8:31:bc:c4:df:bc:2a:f8:37:91:18:dc:
+ 04:c8:64:99:2b:18:6d:80:03:59:c9:ae:f8:58:d0:3e:ed:c3:
+ 23:9f:69:3c:86:38:1c:9e:ef:da:27:78:d1:84:37:71:8a:3c:
+ 4b:39:cf:7e:45:06:d6:2d:d8:8a:4d:78:12:d6:ad:c2:d3:cb:
+ d2:d0:41:f3:26:36:4a:9b:95:6c:0c:ee:e5:d1:43:27:66:c1:
+ 88:f7:7a:b3:20:6c:ea:b0:69:2b:c7:20:e8:0c:03:c4:41:05:
+ 99:e2:3f:e4:6b:f8:a0:86:81:c7:84:c6:1f:d5:4b:81:12:b2:
+ 16:21:2c:13:a1:80:b2:5e:0c:4a:13:9e:20:d8:62:40:ab:90:
+ ea:64:4a:2f:ac:0d:01:12:79:45:a8:2f:87:19:68:c8:e2:85:
+ c7:30:b2:75:f9:38:3f:b2:c0:93:b4:6b:e2:03:44:ce:67:a0:
+ df:89:d6:ad:8c:76:a3:13:c3:94:61:2b:6b:d9:6c:c1:07:0a:
+ 22:07:85:6c:85:24:46:a9:be:3f:8b:78:84:82:7e:24:0c:9d:
+ fd:81:37:e3:25:a8:ed:36:4e:95:2c:c9:9c:90:da:ec:a9:42:
+ 3c:ad:b6:02
+SHA1 Fingerprint=1B:4B:39:61:26:27:6B:64:91:A2:68:6D:D7:02:43:21:2D:1F:1D:96
+-----BEGIN CERTIFICATE-----
+MIIFFzCCA/+gAwIBAgIBETANBgkqhkiG9w0BAQUFADCCASsxCzAJBgNVBAYTAlRS
+MRgwFgYDVQQHDA9HZWJ6ZSAtIEtvY2FlbGkxRzBFBgNVBAoMPlTDvHJraXllIEJp
+bGltc2VsIHZlIFRla25vbG9qaWsgQXJhxZ90xLFybWEgS3VydW11IC0gVMOcQsSw
+VEFLMUgwRgYDVQQLDD9VbHVzYWwgRWxla3Ryb25payB2ZSBLcmlwdG9sb2ppIEFy
+YcWfdMSxcm1hIEVuc3RpdMO8c8O8IC0gVUVLQUUxIzAhBgNVBAsMGkthbXUgU2Vy
+dGlmaWthc3lvbiBNZXJrZXppMUowSAYDVQQDDEFUw5xCxLBUQUsgVUVLQUUgS8O2
+ayBTZXJ0aWZpa2EgSGl6bWV0IFNhxJ9sYXnEsWPEsXPEsSAtIFPDvHLDvG0gMzAe
+Fw0wNzA4MjQxMTM3MDdaFw0xNzA4MjExMTM3MDdaMIIBKzELMAkGA1UEBhMCVFIx
+GDAWBgNVBAcMD0dlYnplIC0gS29jYWVsaTFHMEUGA1UECgw+VMO8cmtpeWUgQmls
+aW1zZWwgdmUgVGVrbm9sb2ppayBBcmHFn3TEsXJtYSBLdXJ1bXUgLSBUw5xCxLBU
+QUsxSDBGBgNVBAsMP1VsdXNhbCBFbGVrdHJvbmlrIHZlIEtyaXB0b2xvamkgQXJh
+xZ90xLFybWEgRW5zdGl0w7xzw7wgLSBVRUtBRTEjMCEGA1UECwwaS2FtdSBTZXJ0
+aWZpa2FzeW9uIE1lcmtlemkxSjBIBgNVBAMMQVTDnELEsFRBSyBVRUtBRSBLw7Zr
+IFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sxc8SxIC0gU8O8csO8bSAzMIIB
+IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAim1L/xCIOsP2fpTo6iBkcK4h
+gb46ezzb8R1Sf1n68yJMlaCQvEhOEav7t7WNeoMojCZG2E6VQIdhn8WebYGHV2yK
+O7Rm6sxA/OOqbLLLAdsyv9Lrhc+hDVXDWzhXcLh1xnnRFDDtG1hba+818qEhTsXO
+fJlfbLm4IpNQp81McGq+agV/E5wrHur+R84EpW+sky58K5+eeROR6Oqeyjh1jmKw
+lZMq5d/pXpduIF9fhHpEORlAHLpVK/swsoHvhOPc7Jg4OQOFCKlUAwUp8MmPi+oL
+hmUZEdPpCSPeaJMDyTYcIW7OjGbxmTDY17PDHfiBLqi9ggtm/oLL4eAagsNAgQID
+AQABo0IwQDAdBgNVHQ4EFgQUvYiHyY/2pAoLquvF/pEjnatKijIwDgYDVR0PAQH/
+BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBAB18+kmP
+NOm3JpIWmgV050vQbTlswyb2zrgxvMTfvCr4N5EY3ATIZJkrGG2AA1nJrvhY0D7t
+wyOfaTyGOBye79oneNGEN3GKPEs5z35FBtYt2IpNeBLWrcLTy9LQQfMmNkqblWwM
+7uXRQydmwYj3erMgbOqwaSvHIOgMA8RBBZniP+Rr+KCGgceExh/VS4ESshYhLBOh
+gLJeDEoTniDYYkCrkOpkSi+sDQESeUWoL4cZaMjihccwsnX5OD+ywJO0a+IDRM5n
+oN+J1q2MdqMTw5RhK2vZbMEHCiIHhWyFJEapvj+LeISCfiQMnf2BN+MlqO02TpUs
+yZyQ2uypQjyttgI=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/524d9b43.0 b/luni/src/main/files/cacerts/524d9b43.0
new file mode 100644
index 0000000..07bbf11
--- /dev/null
+++ b/luni/src/main/files/cacerts/524d9b43.0
@@ -0,0 +1,88 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 40:1a:c4:64:21:b3:13:21:03:0e:bb:e4:12:1a:c5:1d
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=US, O=VeriSign, Inc., OU=VeriSign Trust Network, OU=(c) 2008 VeriSign, Inc. - For authorized use only, CN=VeriSign Universal Root Certification Authority
+ Validity
+ Not Before: Apr 2 00:00:00 2008 GMT
+ Not After : Dec 1 23:59:59 2037 GMT
+ Subject: C=US, O=VeriSign, Inc., OU=VeriSign Trust Network, OU=(c) 2008 VeriSign, Inc. - For authorized use only, CN=VeriSign Universal Root Certification Authority
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:c7:61:37:5e:b1:01:34:db:62:d7:15:9b:ff:58:
+ 5a:8c:23:23:d6:60:8e:91:d7:90:98:83:7a:e6:58:
+ 19:38:8c:c5:f6:e5:64:85:b4:a2:71:fb:ed:bd:b9:
+ da:cd:4d:00:b4:c8:2d:73:a5:c7:69:71:95:1f:39:
+ 3c:b2:44:07:9c:e8:0e:fa:4d:4a:c4:21:df:29:61:
+ 8f:32:22:61:82:c5:87:1f:6e:8c:7c:5f:16:20:51:
+ 44:d1:70:4f:57:ea:e3:1c:e3:cc:79:ee:58:d8:0e:
+ c2:b3:45:93:c0:2c:e7:9a:17:2b:7b:00:37:7a:41:
+ 33:78:e1:33:e2:f3:10:1a:7f:87:2c:be:f6:f5:f7:
+ 42:e2:e5:bf:87:62:89:5f:00:4b:df:c5:dd:e4:75:
+ 44:32:41:3a:1e:71:6e:69:cb:0b:75:46:08:d1:ca:
+ d2:2b:95:d0:cf:fb:b9:40:6b:64:8c:57:4d:fc:13:
+ 11:79:84:ed:5e:54:f6:34:9f:08:01:f3:10:25:06:
+ 17:4a:da:f1:1d:7a:66:6b:98:60:66:a4:d9:ef:d2:
+ 2e:82:f1:f0:ef:09:ea:44:c9:15:6a:e2:03:6e:33:
+ d3:ac:9f:55:00:c7:f6:08:6a:94:b9:5f:dc:e0:33:
+ f1:84:60:f9:5b:27:11:b4:fc:16:f2:bb:56:6a:80:
+ 25:8d
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ 1.3.6.1.5.5.7.1.12:
+ 0_.].[0Y0W0U..image/gif0!0.0...+..............k...j.H.,{..0%.#http://logo.verisign.com/vslogo.gif
+ X509v3 Subject Key Identifier:
+ B6:77:FA:69:48:47:9F:53:12:D5:C2:EA:07:32:76:07:D1:97:07:19
+ Signature Algorithm: sha256WithRSAEncryption
+ 4a:f8:f8:b0:03:e6:2c:67:7b:e4:94:77:63:cc:6e:4c:f9:7d:
+ 0e:0d:dc:c8:b9:35:b9:70:4f:63:fa:24:fa:6c:83:8c:47:9d:
+ 3b:63:f3:9a:f9:76:32:95:91:b1:77:bc:ac:9a:be:b1:e4:31:
+ 21:c6:81:95:56:5a:0e:b1:c2:d4:b1:a6:59:ac:f1:63:cb:b8:
+ 4c:1d:59:90:4a:ef:90:16:28:1f:5a:ae:10:fb:81:50:38:0c:
+ 6c:cc:f1:3d:c3:f5:63:e3:b3:e3:21:c9:24:39:e9:fd:15:66:
+ 46:f4:1b:11:d0:4d:73:a3:7d:46:f9:3d:ed:a8:5f:62:d4:f1:
+ 3f:f8:e0:74:57:2b:18:9d:81:b4:c4:28:da:94:97:a5:70:eb:
+ ac:1d:be:07:11:f0:d5:db:dd:e5:8c:f0:d5:32:b0:83:e6:57:
+ e2:8f:bf:be:a1:aa:bf:3d:1d:b5:d4:38:ea:d7:b0:5c:3a:4f:
+ 6a:3f:8f:c0:66:6c:63:aa:e9:d9:a4:16:f4:81:d1:95:14:0e:
+ 7d:cd:95:34:d9:d2:8f:70:73:81:7b:9c:7e:bd:98:61:d8:45:
+ 87:98:90:c5:eb:86:30:c6:35:bf:f0:ff:c3:55:88:83:4b:ef:
+ 05:92:06:71:f2:b8:98:93:b7:ec:cd:82:61:f1:38:e6:4f:97:
+ 98:2a:5a:8d
+SHA1 Fingerprint=36:79:CA:35:66:87:72:30:4D:30:A5:FB:87:3B:0F:A7:7B:B7:0D:54
+-----BEGIN CERTIFICATE-----
+MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCB
+vTELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
+ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwOCBWZXJp
+U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MTgwNgYDVQQDEy9W
+ZXJpU2lnbiBVbml2ZXJzYWwgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
+Fw0wODA0MDIwMDAwMDBaFw0zNzEyMDEyMzU5NTlaMIG9MQswCQYDVQQGEwJVUzEX
+MBUGA1UEChMOVmVyaVNpZ24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
+IE5ldHdvcmsxOjA4BgNVBAsTMShjKSAyMDA4IFZlcmlTaWduLCBJbmMuIC0gRm9y
+IGF1dGhvcml6ZWQgdXNlIG9ubHkxODA2BgNVBAMTL1ZlcmlTaWduIFVuaXZlcnNh
+bCBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEF
+AAOCAQ8AMIIBCgKCAQEAx2E3XrEBNNti1xWb/1hajCMj1mCOkdeQmIN65lgZOIzF
+9uVkhbSicfvtvbnazU0AtMgtc6XHaXGVHzk8skQHnOgO+k1KxCHfKWGPMiJhgsWH
+H26MfF8WIFFE0XBPV+rjHOPMee5Y2A7Cs0WTwCznmhcrewA3ekEzeOEz4vMQGn+H
+LL729fdC4uW/h2KJXwBL38Xd5HVEMkE6HnFuacsLdUYI0crSK5XQz/u5QGtkjFdN
+/BMReYTtXlT2NJ8IAfMQJQYXStrxHXpma5hgZqTZ79IugvHw7wnqRMkVauIDbjPT
+rJ9VAMf2CGqUuV/c4DPxhGD5WycRtPwW8rtWaoAljQIDAQABo4GyMIGvMA8GA1Ud
+EwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMG0GCCsGAQUFBwEMBGEwX6FdoFsw
+WTBXMFUWCWltYWdlL2dpZjAhMB8wBwYFKw4DAhoEFI/l0xqGrI2Oa8PPgGrUSBgs
+exkuMCUWI2h0dHA6Ly9sb2dvLnZlcmlzaWduLmNvbS92c2xvZ28uZ2lmMB0GA1Ud
+DgQWBBS2d/ppSEefUxLVwuoHMnYH0ZcHGTANBgkqhkiG9w0BAQsFAAOCAQEASvj4
+sAPmLGd75JR3Y8xuTPl9Dg3cyLk1uXBPY/ok+myDjEedO2Pzmvl2MpWRsXe8rJq+
+seQxIcaBlVZaDrHC1LGmWazxY8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz
+4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTxP/jgdFcrGJ2BtMQo2pSXpXDrrB2+
+BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+PwGZsY6rp2aQW9IHR
+lRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4mJO3
+7M2CYfE45k+XmCpajQ==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/54edfa5d.0 b/luni/src/main/files/cacerts/54edfa5d.0
deleted file mode 100644
index e2530a4..0000000
--- a/luni/src/main/files/cacerts/54edfa5d.0
+++ /dev/null
@@ -1,63 +0,0 @@
-Certificate:
- Data:
- Version: 3 (0x2)
- Serial Number: 1003 (0x3eb)
- Signature Algorithm: md5WithRSAEncryption
- Issuer: C=DE, ST=Hamburg, L=Hamburg, O=TC TrustCenter for Security in Data Networks GmbH, OU=TC TrustCenter Class 3 CA/emailAddress=certificate@trustcenter.de
- Validity
- Not Before: Mar 9 11:59:59 1998 GMT
- Not After : Jan 1 11:59:59 2011 GMT
- Subject: C=DE, ST=Hamburg, L=Hamburg, O=TC TrustCenter for Security in Data Networks GmbH, OU=TC TrustCenter Class 3 CA/emailAddress=certificate@trustcenter.de
- Subject Public Key Info:
- Public Key Algorithm: rsaEncryption
- RSA Public Key: (1024 bit)
- Modulus (1024 bit):
- 00:b6:b4:c1:35:05:2e:0d:8d:ec:a0:40:6a:1c:0e:
- 27:a6:50:92:6b:50:1b:07:de:2e:e7:76:cc:e0:da:
- fc:84:a8:5e:8c:63:6a:2b:4d:d9:4e:02:76:11:c1:
- 0b:f2:8d:79:ca:00:b6:f1:b0:0e:d7:fb:a4:17:3d:
- af:ab:69:7a:96:27:bf:af:33:a1:9a:2a:59:aa:c4:
- b5:37:08:f2:12:a5:31:b6:43:f5:32:96:71:28:28:
- ab:8d:28:86:df:bb:ee:e3:0c:7d:30:d6:c3:52:ab:
- 8f:5d:27:9c:6b:c0:a3:e7:05:6b:57:49:44:b3:6e:
- ea:64:cf:d2:8e:7a:50:77:77
- Exponent: 65537 (0x10001)
- X509v3 extensions:
- X509v3 Basic Constraints: critical
- CA:TRUE
- X509v3 Key Usage: critical
- Digital Signature, Certificate Sign, CRL Sign
- Netscape CA Policy Url:
- http://www.trustcenter.de/guidelines
- Netscape Cert Type:
- SSL CA, S/MIME CA, Object Signing CA
- Signature Algorithm: md5WithRSAEncryption
- 16:3d:c6:cd:c1:bb:85:71:85:46:9f:3e:20:8f:51:28:99:ec:
- 2d:45:21:63:23:5b:04:bb:4c:90:b8:88:92:04:4d:bd:7d:01:
- a3:3f:f6:ec:ce:f1:de:fe:7d:e5:e1:3e:bb:c6:ab:5e:0b:dd:
- 3d:96:c4:cb:a9:d4:f9:26:e6:06:4e:9e:0c:a5:7a:ba:6e:c3:
- 7c:82:19:d1:c7:b1:b1:c3:db:0d:8e:9b:40:7c:37:0b:f1:5d:
- e8:fd:1f:90:88:a5:0e:4e:37:64:21:a8:4e:8d:b4:9f:f1:de:
- 48:ad:d5:56:18:52:29:8b:47:34:12:09:d4:bb:92:35:ef:0f:
- db:34
-SHA1 Fingerprint=9F:C7:96:E8:F8:52:4F:86:3A:E1:49:6D:38:12:42:10:5F:1B:78:F5
------BEGIN CERTIFICATE-----
-MIIDXDCCAsWgAwIBAgICA+swDQYJKoZIhvcNAQEEBQAwgbwxCzAJBgNVBAYTAkRF
-MRAwDgYDVQQIEwdIYW1idXJnMRAwDgYDVQQHEwdIYW1idXJnMTowOAYDVQQKEzFU
-QyBUcnVzdENlbnRlciBmb3IgU2VjdXJpdHkgaW4gRGF0YSBOZXR3b3JrcyBHbWJI
-MSIwIAYDVQQLExlUQyBUcnVzdENlbnRlciBDbGFzcyAzIENBMSkwJwYJKoZIhvcN
-AQkBFhpjZXJ0aWZpY2F0ZUB0cnVzdGNlbnRlci5kZTAeFw05ODAzMDkxMTU5NTla
-Fw0xMTAxMDExMTU5NTlaMIG8MQswCQYDVQQGEwJERTEQMA4GA1UECBMHSGFtYnVy
-ZzEQMA4GA1UEBxMHSGFtYnVyZzE6MDgGA1UEChMxVEMgVHJ1c3RDZW50ZXIgZm9y
-IFNlY3VyaXR5IGluIERhdGEgTmV0d29ya3MgR21iSDEiMCAGA1UECxMZVEMgVHJ1
-c3RDZW50ZXIgQ2xhc3MgMyBDQTEpMCcGCSqGSIb3DQEJARYaY2VydGlmaWNhdGVA
-dHJ1c3RjZW50ZXIuZGUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALa0wTUF
-Lg2N7KBAahwOJ6ZQkmtQGwfeLud2zODa/ISoXoxjaitN2U4CdhHBC/KNecoAtvGw
-Dtf7pBc9r6tpepYnv68zoZoqWarEtTcI8hKlMbZD9TKWcSgoq40oht+77uMMfTDW
-w1Krj10nnGvAo+cFa1dJRLNu6mTP0o56UHd3AgMBAAGjazBpMA8GA1UdEwEB/wQF
-MAMBAf8wDgYDVR0PAQH/BAQDAgGGMDMGCWCGSAGG+EIBCAQmFiRodHRwOi8vd3d3
-LnRydXN0Y2VudGVyLmRlL2d1aWRlbGluZXMwEQYJYIZIAYb4QgEBBAQDAgAHMA0G
-CSqGSIb3DQEBBAUAA4GBABY9xs3Bu4VxhUafPiCPUSiZ7C1FIWMjWwS7TJC4iJIE
-Tb19AaM/9uzO8d7+feXhPrvGq14L3T2WxMup1Pkm5gZOngylerpuw3yCGdHHsbHD
-2w2Om0B8NwvxXej9H5CIpQ5ON2QhqE6NtJ/x3kit1VYYUimLRzQSCdS7kjXvD9s0
------END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/5e4e69e7.0 b/luni/src/main/files/cacerts/5e4e69e7.0
new file mode 100644
index 0000000..5149cbc
--- /dev/null
+++ b/luni/src/main/files/cacerts/5e4e69e7.0
@@ -0,0 +1,61 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 2f:80:fe:23:8c:0e:22:0f:48:67:12:28:91:87:ac:b3
+ Signature Algorithm: ecdsa-with-SHA384
+ Issuer: C=US, O=VeriSign, Inc., OU=VeriSign Trust Network, OU=(c) 2007 VeriSign, Inc. - For authorized use only, CN=VeriSign Class 3 Public Primary Certification Authority - G4
+ Validity
+ Not Before: Nov 5 00:00:00 2007 GMT
+ Not After : Jan 18 23:59:59 2038 GMT
+ Subject: C=US, O=VeriSign, Inc., OU=VeriSign Trust Network, OU=(c) 2007 VeriSign, Inc. - For authorized use only, CN=VeriSign Class 3 Public Primary Certification Authority - G4
+ Subject Public Key Info:
+ Public Key Algorithm: id-ecPublicKey
+ EC Public Key:
+ pub:
+ 04:a7:56:7a:7c:52:da:64:9b:0e:2d:5c:d8:5e:ac:
+ 92:3d:fe:01:e6:19:4a:3d:14:03:4b:fa:60:27:20:
+ d9:83:89:69:fa:54:c6:9a:18:5e:55:2a:64:de:06:
+ f6:8d:4a:3b:ad:10:3c:65:3d:90:88:04:89:e0:30:
+ 61:b3:ae:5d:01:a7:7b:de:7c:b2:be:ca:65:61:00:
+ 86:ae:da:8f:7b:d0:89:ad:4d:1d:59:9a:41:b1:bc:
+ 47:80:dc:9e:62:c3:f9
+ ASN1 OID: secp384r1
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ 1.3.6.1.5.5.7.1.12:
+ 0_.].[0Y0W0U..image/gif0!0.0...+..............k...j.H.,{..0%.#http://logo.verisign.com/vslogo.gif
+ X509v3 Subject Key Identifier:
+ B3:16:91:FD:EE:A6:6E:E4:B5:2E:49:8F:87:78:81:80:EC:E5:B1:B5
+ Signature Algorithm: ecdsa-with-SHA384
+ 30:65:02:30:66:21:0c:18:26:60:5a:38:7b:56:42:e0:a7:fc:
+ 36:84:51:91:20:2c:76:4d:43:3d:c4:1d:84:23:d0:ac:d6:7c:
+ 35:06:ce:cd:69:bd:90:0d:db:6c:48:42:1d:0e:aa:42:02:31:
+ 00:9c:3d:48:39:23:39:58:1a:15:12:59:6a:9e:ef:d5:59:b2:
+ 1d:52:2c:99:71:cd:c7:29:df:1b:2a:61:7b:71:d1:de:f3:c0:
+ e5:0d:3a:4a:aa:2d:a7:d8:86:2a:dd:2e:10
+SHA1 Fingerprint=22:D5:D8:DF:8F:02:31:D1:8D:F7:9D:B7:CF:8A:2D:64:C9:3F:6C:3A
+-----BEGIN CERTIFICATE-----
+MIIDhDCCAwqgAwIBAgIQL4D+I4wOIg9IZxIokYesszAKBggqhkjOPQQDAzCByjEL
+MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
+ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2ln
+biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp
+U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y
+aXR5IC0gRzQwHhcNMDcxMTA1MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCByjELMAkG
+A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZWZXJp
+U2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNyBWZXJpU2lnbiwg
+SW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJpU2ln
+biBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5
+IC0gRzQwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAASnVnp8Utpkmw4tXNherJI9/gHm
+GUo9FANL+mAnINmDiWn6VMaaGF5VKmTeBvaNSjutEDxlPZCIBIngMGGzrl0Bp3ve
+fLK+ymVhAIau2o970ImtTR1ZmkGxvEeA3J5iw/mjgbIwga8wDwYDVR0TAQH/BAUw
+AwEB/zAOBgNVHQ8BAf8EBAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJ
+aW1hZ2UvZ2lmMCEwHzAHBgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYj
+aHR0cDovL2xvZ28udmVyaXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFLMW
+kf3upm7ktS5Jj4d4gYDs5bG1MAoGCCqGSM49BAMDA2gAMGUCMGYhDBgmYFo4e1ZC
+4Kf8NoRRkSAsdk1DPcQdhCPQrNZ8NQbOzWm9kA3bbEhCHQ6qQgIxAJw9SDkjOVga
+FRJZap7v1VmyHVIsmXHNxynfGyphe3HR3vPA5Q06Sqotp9iGKt0uEA==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/60afe812.0 b/luni/src/main/files/cacerts/60afe812.0
new file mode 100644
index 0000000..78ad01c
--- /dev/null
+++ b/luni/src/main/files/cacerts/60afe812.0
@@ -0,0 +1,82 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 49:41:2c:e4:00:10
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=HU, L=Budapest, O=NetLock Kft., OU=Tan\xC3\xBAs\xC3\xADtv\xC3\xA1nykiad\xC3\xB3k (Certification Services), CN=NetLock Arany (Class Gold) F\xC5\x91tan\xC3\xBAs\xC3\xADtv\xC3\xA1ny
+ Validity
+ Not Before: Dec 11 15:08:21 2008 GMT
+ Not After : Dec 6 15:08:21 2028 GMT
+ Subject: C=HU, L=Budapest, O=NetLock Kft., OU=Tan\xC3\xBAs\xC3\xADtv\xC3\xA1nykiad\xC3\xB3k (Certification Services), CN=NetLock Arany (Class Gold) F\xC5\x91tan\xC3\xBAs\xC3\xADtv\xC3\xA1ny
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:c4:24:5e:73:be:4b:6d:14:c3:a1:f4:e3:97:90:
+ 6e:d2:30:45:1e:3c:ee:67:d9:64:e0:1a:8a:7f:ca:
+ 30:ca:83:e3:20:c1:e3:f4:3a:d3:94:5f:1a:7c:5b:
+ 6d:bf:30:4f:84:27:f6:9f:1f:49:bc:c6:99:0a:90:
+ f2:0f:f5:7f:43:84:37:63:51:8b:7a:a5:70:fc:7a:
+ 58:cd:8e:9b:ed:c3:46:6c:84:70:5d:da:f3:01:90:
+ 23:fc:4e:30:a9:7e:e1:27:63:e7:ed:64:3c:a0:b8:
+ c9:33:63:fe:16:90:ff:b0:b8:fd:d7:a8:c0:c0:94:
+ 43:0b:b6:d5:59:a6:9e:56:d0:24:1f:70:79:af:db:
+ 39:54:0d:65:75:d9:15:41:94:01:af:5e:ec:f6:8d:
+ f1:ff:ad:64:fe:20:9a:d7:5c:eb:fe:a6:1f:08:64:
+ a3:8b:76:55:ad:1e:3b:28:60:2e:87:25:e8:aa:af:
+ 1f:c6:64:46:20:b7:70:7f:3c:de:48:db:96:53:b7:
+ 39:77:e4:1a:e2:c7:16:84:76:97:5b:2f:bb:19:15:
+ 85:f8:69:85:f5:99:a7:a9:f2:34:a7:a9:b6:a6:03:
+ fc:6f:86:3d:54:7c:76:04:9b:6b:f9:40:5d:00:34:
+ c7:2e:99:75:9d:e5:88:03:aa:4d:f8:03:d2:42:76:
+ c0:1b
+ Exponent: 43147 (0xa88b)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE, pathlen:4
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ CC:FA:67:93:F0:B6:B8:D0:A5:C0:1E:F3:53:FD:8C:53:DF:83:D7:96
+ Signature Algorithm: sha256WithRSAEncryption
+ ab:7f:ee:1c:16:a9:9c:3c:51:00:a0:c0:11:08:05:a7:99:e6:
+ 6f:01:88:54:61:6e:f1:b9:18:ad:4a:ad:fe:81:40:23:94:2f:
+ fb:75:7c:2f:28:4b:62:24:81:82:0b:f5:61:f1:1c:6e:b8:61:
+ 38:eb:81:fa:62:a1:3b:5a:62:d3:94:65:c4:e1:e6:6d:82:f8:
+ 2f:25:70:b2:21:26:c1:72:51:1f:8c:2c:c3:84:90:c3:5a:8f:
+ ba:cf:f4:a7:65:a5:eb:98:d1:fb:05:b2:46:75:15:23:6a:6f:
+ 85:63:30:80:f0:d5:9e:1f:29:1c:c2:6c:b0:50:59:5d:90:5b:
+ 3b:a8:0d:30:cf:bf:7d:7f:ce:f1:9d:83:bd:c9:46:6e:20:a6:
+ f9:61:51:ba:21:2f:7b:be:a5:15:63:a1:d4:95:87:f1:9e:b9:
+ f3:89:f3:3d:85:b8:b8:db:be:b5:b9:29:f9:da:37:05:00:49:
+ 94:03:84:44:e7:bf:43:31:cf:75:8b:25:d1:f4:a6:64:f5:92:
+ f6:ab:05:eb:3d:e9:a5:0b:36:62:da:cc:06:5f:36:8b:b6:5e:
+ 31:b8:2a:fb:5e:f6:71:df:44:26:9e:c4:e6:0d:91:b4:2e:75:
+ 95:80:51:6a:4b:30:a6:b0:62:a1:93:f1:9b:d8:ce:c4:63:75:
+ 3f:59:47:b1
+SHA1 Fingerprint=06:08:3F:59:3F:15:A1:04:A0:69:A4:6B:A9:03:D0:06:B7:97:09:91
+-----BEGIN CERTIFICATE-----
+MIIEFTCCAv2gAwIBAgIGSUEs5AAQMA0GCSqGSIb3DQEBCwUAMIGnMQswCQYDVQQG
+EwJIVTERMA8GA1UEBwwIQnVkYXBlc3QxFTATBgNVBAoMDE5ldExvY2sgS2Z0LjE3
+MDUGA1UECwwuVGFuw7pzw610dsOhbnlraWFkw7NrIChDZXJ0aWZpY2F0aW9uIFNl
+cnZpY2VzKTE1MDMGA1UEAwwsTmV0TG9jayBBcmFueSAoQ2xhc3MgR29sZCkgRsWR
+dGFuw7pzw610dsOhbnkwHhcNMDgxMjExMTUwODIxWhcNMjgxMjA2MTUwODIxWjCB
+pzELMAkGA1UEBhMCSFUxETAPBgNVBAcMCEJ1ZGFwZXN0MRUwEwYDVQQKDAxOZXRM
+b2NrIEtmdC4xNzA1BgNVBAsMLlRhbsO6c8OtdHbDoW55a2lhZMOzayAoQ2VydGlm
+aWNhdGlvbiBTZXJ2aWNlcykxNTAzBgNVBAMMLE5ldExvY2sgQXJhbnkgKENsYXNz
+IEdvbGQpIEbFkXRhbsO6c8OtdHbDoW55MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A
+MIIBCgKCAQEAxCRec75LbRTDofTjl5Bu0jBFHjzuZ9lk4BqKf8owyoPjIMHj9DrT
+lF8afFttvzBPhCf2nx9JvMaZCpDyD/V/Q4Q3Y1GLeqVw/HpYzY6b7cNGbIRwXdrz
+AZAj/E4wqX7hJ2Pn7WQ8oLjJM2P+FpD/sLj916jAwJRDC7bVWaaeVtAkH3B5r9s5
+VA1lddkVQZQBr17s9o3x/61k/iCa11zr/qYfCGSji3ZVrR47KGAuhyXoqq8fxmRG
+ILdwfzzeSNuWU7c5d+Qa4scWhHaXWy+7GRWF+GmF9ZmnqfI0p6m2pgP8b4Y9VHx2
+BJtr+UBdADTHLpl1neWIA6pN+APSQnbAGwIDAKiLo0UwQzASBgNVHRMBAf8ECDAG
+AQH/AgEEMA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUzPpnk/C2uNClwB7zU/2M
+U9+D15YwDQYJKoZIhvcNAQELBQADggEBAKt/7hwWqZw8UQCgwBEIBaeZ5m8BiFRh
+bvG5GK1Krf6BQCOUL/t1fC8oS2IkgYIL9WHxHG64YTjrgfpioTtaYtOUZcTh5m2C
++C8lcLIhJsFyUR+MLMOEkMNaj7rP9KdlpeuY0fsFskZ1FSNqb4VjMIDw1Z4fKRzC
+bLBQWV2QWzuoDTDPv31/zvGdg73JRm4gpvlhUbohL3u+pRVjodSVh/GeufOJ8z2F
+uLjbvrW5KfnaNwUASZQDhETnv0Mxz3WLJdH0pmT1kvarBes96aULNmLazAZfNou2
+XjG4Kvte9nHfRCaexOYNkbQudZWAUWpLMKawYqGT8ZvYzsRjdT9ZR7E=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/67495436.0 b/luni/src/main/files/cacerts/67495436.0
new file mode 100644
index 0000000..35df1f8
--- /dev/null
+++ b/luni/src/main/files/cacerts/67495436.0
@@ -0,0 +1,83 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 60:01:97:b7:46:a7:ea:b4:b4:9a:d6:4b:2f:f7:90:fb
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=US, O=thawte, Inc., OU=Certification Services Division, OU=(c) 2008 thawte, Inc. - For authorized use only, CN=thawte Primary Root CA - G3
+ Validity
+ Not Before: Apr 2 00:00:00 2008 GMT
+ Not After : Dec 1 23:59:59 2037 GMT
+ Subject: C=US, O=thawte, Inc., OU=Certification Services Division, OU=(c) 2008 thawte, Inc. - For authorized use only, CN=thawte Primary Root CA - G3
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:b2:bf:27:2c:fb:db:d8:5b:dd:78:7b:1b:9e:77:
+ 66:81:cb:3e:bc:7c:ae:f3:a6:27:9a:34:a3:68:31:
+ 71:38:33:62:e4:f3:71:66:79:b1:a9:65:a3:a5:8b:
+ d5:8f:60:2d:3f:42:cc:aa:6b:32:c0:23:cb:2c:41:
+ dd:e4:df:fc:61:9c:e2:73:b2:22:95:11:43:18:5f:
+ c4:b6:1f:57:6c:0a:05:58:22:c8:36:4c:3a:7c:a5:
+ d1:cf:86:af:88:a7:44:02:13:74:71:73:0a:42:59:
+ 02:f8:1b:14:6b:42:df:6f:5f:ba:6b:82:a2:9d:5b:
+ e7:4a:bd:1e:01:72:db:4b:74:e8:3b:7f:7f:7d:1f:
+ 04:b4:26:9b:e0:b4:5a:ac:47:3d:55:b8:d7:b0:26:
+ 52:28:01:31:40:66:d8:d9:24:bd:f6:2a:d8:ec:21:
+ 49:5c:9b:f6:7a:e9:7f:55:35:7e:96:6b:8d:93:93:
+ 27:cb:92:bb:ea:ac:40:c0:9f:c2:f8:80:cf:5d:f4:
+ 5a:dc:ce:74:86:a6:3e:6c:0b:53:ca:bd:92:ce:19:
+ 06:72:e6:0c:5c:38:69:c7:04:d6:bc:6c:ce:5b:f6:
+ f7:68:9c:dc:25:15:48:88:a1:e9:a9:f8:98:9c:e0:
+ f3:d5:31:28:61:11:6c:67:96:8d:39:99:cb:c2:45:
+ 24:39
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ AD:6C:AA:94:60:9C:ED:E4:FF:FA:3E:0A:74:2B:63:03:F7:B6:59:BF
+ Signature Algorithm: sha256WithRSAEncryption
+ 1a:40:d8:95:65:ac:09:92:89:c6:39:f4:10:e5:a9:0e:66:53:
+ 5d:78:de:fa:24:91:bb:e7:44:51:df:c6:16:34:0a:ef:6a:44:
+ 51:ea:2b:07:8a:03:7a:c3:eb:3f:0a:2c:52:16:a0:2b:43:b9:
+ 25:90:3f:70:a9:33:25:6d:45:1a:28:3b:27:cf:aa:c3:29:42:
+ 1b:df:3b:4c:c0:33:34:5b:41:88:bf:6b:2b:65:af:28:ef:b2:
+ f5:c3:aa:66:ce:7b:56:ee:b7:c8:cb:67:c1:c9:9c:1a:18:b8:
+ c4:c3:49:03:f1:60:0e:50:cd:46:c5:f3:77:79:f7:b6:15:e0:
+ 38:db:c7:2f:28:a0:0c:3f:77:26:74:d9:25:12:da:31:da:1a:
+ 1e:dc:29:41:91:22:3c:69:a7:bb:02:f2:b6:5c:27:03:89:f4:
+ 06:ea:9b:e4:72:82:e3:a1:09:c1:e9:00:19:d3:3e:d4:70:6b:
+ ba:71:a6:aa:58:ae:f4:bb:e9:6c:b6:ef:87:cc:9b:bb:ff:39:
+ e6:56:61:d3:0a:a7:c4:5c:4c:60:7b:05:77:26:7a:bf:d8:07:
+ 52:2c:62:f7:70:63:d9:39:bc:6f:1c:c2:79:dc:76:29:af:ce:
+ c5:2c:64:04:5e:88:36:6e:31:d4:40:1a:62:34:36:3f:35:01:
+ ae:ac:63:a0
+SHA1 Fingerprint=F1:8B:53:8D:1B:E9:03:B6:A6:F0:56:43:5B:17:15:89:CA:F3:6B:F2
+-----BEGIN CERTIFICATE-----
+MIIEKjCCAxKgAwIBAgIQYAGXt0an6rS0mtZLL/eQ+zANBgkqhkiG9w0BAQsFADCB
+rjELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjEoMCYGA1UECxMf
+Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYGA1UECxMvKGMpIDIw
+MDggdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAiBgNV
+BAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMzAeFw0wODA0MDIwMDAwMDBa
+Fw0zNzEyMDEyMzU5NTlaMIGuMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3Rl
+LCBJbmMuMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlzaW9u
+MTgwNgYDVQQLEy8oYykgMjAwOCB0aGF3dGUsIEluYy4gLSBGb3IgYXV0aG9yaXpl
+ZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9vdCBDQSAtIEcz
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr8nLPvb2FvdeHsbnndm
+gcs+vHyu86YnmjSjaDFxODNi5PNxZnmxqWWjpYvVj2AtP0LMqmsywCPLLEHd5N/8
+YZzic7IilRFDGF/Eth9XbAoFWCLINkw6fKXRz4aviKdEAhN0cXMKQlkC+BsUa0Lf
+b1+6a4KinVvnSr0eAXLbS3ToO39/fR8EtCab4LRarEc9VbjXsCZSKAExQGbY2SS9
+9irY7CFJXJv2eul/VTV+lmuNk5Mny5K76qxAwJ/C+IDPXfRa3M50hqY+bAtTyr2S
+zhkGcuYMXDhpxwTWvGzOW/b3aJzcJRVIiKHpqfiYnODz1TEoYRFsZ5aNOZnLwkUk
+OQIDAQABo0IwQDAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNV
+HQ4EFgQUrWyqlGCc7eT/+j4KdCtjA/e2Wb8wDQYJKoZIhvcNAQELBQADggEBABpA
+2JVlrAmSicY59BDlqQ5mU1143vokkbvnRFHfxhY0Cu9qRFHqKweKA3rD6z8KLFIW
+oCtDuSWQP3CpMyVtRRooOyfPqsMpQhvfO0zAMzRbQYi/aytlryjvsvXDqmbOe1bu
+t8jLZ8HJnBoYuMTDSQPxYA5QzUbF83d597YV4Djbxy8ooAw/dyZ02SUS2jHaGh7c
+KUGRIjxpp7sC8rZcJwOJ9Abqm+RyguOhCcHpABnTPtRwa7pxpqpYrvS76Wy274fM
+m7v/OeZWYdMKp8RcTGB7BXcmer/YB1IsYvdwY9k5vG8cwnncdimvzsUsZAReiDZu
+MdRAGmI0Nj81Aa6sY6A=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/72f369af.0 b/luni/src/main/files/cacerts/72f369af.0
new file mode 100644
index 0000000..969e680
--- /dev/null
+++ b/luni/src/main/files/cacerts/72f369af.0
@@ -0,0 +1,77 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1 (0x1)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=NO, O=Buypass AS-983163327, CN=Buypass Class 2 CA 1
+ Validity
+ Not Before: Oct 13 10:25:09 2006 GMT
+ Not After : Oct 13 10:25:09 2016 GMT
+ Subject: C=NO, O=Buypass AS-983163327, CN=Buypass Class 2 CA 1
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:8b:3c:07:45:d8:f6:df:e6:c7:ca:ba:8d:43:c5:
+ 47:8d:b0:5a:c1:38:db:92:84:1c:af:13:d4:0f:6f:
+ 36:46:20:c4:2e:cc:71:70:34:a2:34:d3:37:2e:d8:
+ dd:3a:77:2f:c0:eb:29:e8:5c:d2:b5:a9:91:34:87:
+ 22:59:fe:cc:db:e7:99:af:96:c1:a8:c7:40:dd:a5:
+ 15:8c:6e:c8:7c:97:03:cb:e6:20:f2:d7:97:5f:31:
+ a1:2f:37:d2:be:ee:be:a9:ad:a8:4c:9e:21:66:43:
+ 3b:a8:bc:f3:09:a3:38:d5:59:24:c1:c2:47:76:b1:
+ 88:5c:82:3b:bb:2b:a6:04:d7:8c:07:8f:cd:d5:41:
+ 1d:f0:ae:b8:29:2c:94:52:60:34:94:3b:da:e0:38:
+ d1:9d:33:3e:15:f4:93:32:c5:00:da:b5:29:66:0e:
+ 3a:78:0f:21:52:5f:02:e5:92:7b:25:d3:92:1e:2f:
+ 15:9d:81:e4:9d:8e:e8:ef:89:ce:14:4c:54:1d:1c:
+ 81:12:4d:70:a8:be:10:05:17:7e:1f:d1:b8:57:55:
+ ed:cd:bb:52:c2:b0:1e:78:c2:4d:36:68:cb:56:26:
+ c1:52:c1:bd:76:f7:58:d5:72:7e:1f:44:76:bb:00:
+ 89:1d:16:9d:51:35:ef:4d:c2:56:ef:6b:e0:8c:3b:
+ 0d:e9
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Subject Key Identifier:
+ 3F:8D:9A:59:8B:FC:7B:7B:9C:A3:AF:38:B0:39:ED:90:71:80:D6:C8
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ Signature Algorithm: sha1WithRSAEncryption
+ 15:1a:7e:13:8a:b9:e8:07:a3:4b:27:32:b2:40:91:f2:21:d1:
+ 64:85:be:63:6a:d2:cf:81:c2:15:d5:7a:7e:0c:29:ac:37:1e:
+ 1c:7c:76:52:95:da:b5:7f:23:a1:29:77:65:c9:32:9d:a8:2e:
+ 56:ab:60:76:ce:16:b4:8d:7f:78:c0:d5:99:51:83:7f:5e:d9:
+ be:0c:a8:50:ed:22:c7:ad:05:4c:76:fb:ed:ee:1e:47:64:f6:
+ f7:27:7d:5c:28:0f:45:c5:5c:62:5e:a6:9a:91:91:b7:53:17:
+ 2e:dc:ad:60:9d:96:64:39:bd:67:68:b2:ae:05:cb:4d:e7:5f:
+ 1f:57:86:d5:20:9c:28:fb:6f:13:38:f5:f6:11:92:f6:7d:99:
+ 5e:1f:0c:e8:ab:44:24:29:72:40:3d:36:52:af:8c:58:90:73:
+ c1:ec:61:2c:79:a1:ec:87:b5:3f:da:4d:d9:21:00:30:de:90:
+ da:0e:d3:1a:48:a9:3e:85:0b:14:8b:8c:bc:41:9e:6a:f7:0e:
+ 70:c0:35:f7:39:a2:5d:66:d0:7b:59:9f:a8:47:12:9a:27:23:
+ a4:2d:8e:27:83:92:20:a1:d7:15:7f:f1:2e:18:ee:f4:48:7f:
+ 2f:7f:f1:a1:18:b5:a1:0b:94:a0:62:20:32:9c:1d:f6:d4:ef:
+ bf:4c:88:68
+SHA1 Fingerprint=A0:A1:AB:90:C9:FC:84:7B:3B:12:61:E8:97:7D:5F:D3:22:61:D3:CC
+-----BEGIN CERTIFICATE-----
+MIIDUzCCAjugAwIBAgIBATANBgkqhkiG9w0BAQUFADBLMQswCQYDVQQGEwJOTzEd
+MBsGA1UECgwUQnV5cGFzcyBBUy05ODMxNjMzMjcxHTAbBgNVBAMMFEJ1eXBhc3Mg
+Q2xhc3MgMiBDQSAxMB4XDTA2MTAxMzEwMjUwOVoXDTE2MTAxMzEwMjUwOVowSzEL
+MAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1eXBhc3MgQVMtOTgzMTYzMzI3MR0wGwYD
+VQQDDBRCdXlwYXNzIENsYXNzIDIgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEP
+ADCCAQoCggEBAIs8B0XY9t/mx8q6jUPFR42wWsE425KEHK8T1A9vNkYgxC7McXA0
+ojTTNy7Y3Tp3L8DrKehc0rWpkTSHIln+zNvnma+WwajHQN2lFYxuyHyXA8vmIPLX
+l18xoS830r7uvqmtqEyeIWZDO6i88wmjONVZJMHCR3axiFyCO7srpgTXjAePzdVB
+HfCuuCkslFJgNJQ72uA40Z0zPhX0kzLFANq1KWYOOngPIVJfAuWSeyXTkh4vFZ2B
+5J2O6O+JzhRMVB0cgRJNcKi+EAUXfh/RuFdV7c27UsKwHnjCTTZoy1YmwVLBvXb3
+WNVyfh9EdrsAiR0WnVE1703CVu9r4Iw7DekCAwEAAaNCMEAwDwYDVR0TAQH/BAUw
+AwEB/zAdBgNVHQ4EFgQUP42aWYv8e3uco684sDntkHGA1sgwDgYDVR0PAQH/BAQD
+AgEGMA0GCSqGSIb3DQEBBQUAA4IBAQAVGn4TirnoB6NLJzKyQJHyIdFkhb5jatLP
+gcIV1Xp+DCmsNx4cfHZSldq1fyOhKXdlyTKdqC5Wq2B2zha0jX94wNWZUYN/Xtm+
+DKhQ7SLHrQVMdvvt7h5HZPb3J31cKA9FxVxiXqaakZG3Uxcu3K1gnZZkOb1naLKu
+BctN518fV4bVIJwo+28TOPX2EZL2fZleHwzoq0QkKXJAPTZSr4xYkHPB7GEseaHs
+h7U/2k3ZIQAw3pDaDtMaSKk+hQsUi4y8QZ5q9w5wwDX3OaJdZtB7WZ+oRxKaJyOk
+LY4ng5IgodcVf/EuGO70SH8vf/GhGLWhC5SgYiAynB321O+/TIho
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/7651b327.0 b/luni/src/main/files/cacerts/7651b327.0
index c0cee71..e2efa82 100644
--- a/luni/src/main/files/cacerts/7651b327.0
+++ b/luni/src/main/files/cacerts/7651b327.0
@@ -2,12 +2,12 @@ Certificate:
Data:
Version: 1 (0x0)
Serial Number:
- 70:ba:e4:1d:10:d9:29:34:b6:38:ca:7b:03:cc:ba:bf
- Signature Algorithm: md2WithRSAEncryption
+ 3c:91:31:cb:1f:f6:d0:1b:0e:9a:b8:d0:44:bf:12:be
+ Signature Algorithm: sha1WithRSAEncryption
Issuer: C=US, O=VeriSign, Inc., OU=Class 3 Public Primary Certification Authority
Validity
Not Before: Jan 29 00:00:00 1996 GMT
- Not After : Aug 1 23:59:59 2028 GMT
+ Not After : Aug 2 23:59:59 2028 GMT
Subject: C=US, O=VeriSign, Inc., OU=Class 3 Public Primary Certification Authority
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
@@ -23,27 +23,27 @@ Certificate:
e7:3d:be:7d:9a:fe:24:45:33:dc:76:15:ed:0f:a2:
71:64:4c:65:2e:81:68:45:a7
Exponent: 65537 (0x10001)
- Signature Algorithm: md2WithRSAEncryption
- bb:4c:12:2b:cf:2c:26:00:4f:14:13:dd:a6:fb:fc:0a:11:84:
- 8c:f3:28:1c:67:92:2f:7c:b6:c5:fa:df:f0:e8:95:bc:1d:8f:
- 6c:2c:a8:51:cc:73:d8:a4:c0:53:f0:4e:d6:26:c0:76:01:57:
- 81:92:5e:21:f1:d1:b1:ff:e7:d0:21:58:cd:69:17:e3:44:1c:
- 9c:19:44:39:89:5c:dc:9c:00:0f:56:8d:02:99:ed:a2:90:45:
- 4c:e4:bb:10:a4:3d:f0:32:03:0e:f1:ce:f8:e8:c9:51:8c:e6:
- 62:9f:e6:9f:c0:7d:b7:72:9c:c9:36:3a:6b:9f:4e:a8:ff:64:
- 0d:64
-SHA1 Fingerprint=74:2C:31:92:E6:07:E4:24:EB:45:49:54:2B:E1:BB:C5:3E:61:74:E2
+ Signature Algorithm: sha1WithRSAEncryption
+ 10:72:52:a9:05:14:19:32:08:41:f0:c5:6b:0a:cc:7e:0f:21:
+ 19:cd:e4:67:dc:5f:a9:1b:e6:ca:e8:73:9d:22:d8:98:6e:73:
+ 03:61:91:c5:7c:b0:45:40:6e:44:9d:8d:b0:b1:96:74:61:2d:
+ 0d:a9:45:d2:a4:92:2a:d6:9a:75:97:6e:3f:53:fd:45:99:60:
+ 1d:a8:2b:4c:f9:5e:a7:09:d8:75:30:d7:d2:65:60:3d:67:d6:
+ 48:55:75:69:3f:91:f5:48:0b:47:69:22:69:82:96:be:c9:c8:
+ 38:86:4a:7a:2c:73:19:48:69:4e:6b:7c:65:bf:0f:fc:70:ce:
+ 88:90
+SHA1 Fingerprint=A1:DB:63:93:91:6F:17:E4:18:55:09:40:04:15:C7:02:40:B0:AE:6B
-----BEGIN CERTIFICATE-----
-MIICPDCCAaUCEHC65B0Q2Sk0tjjKewPMur8wDQYJKoZIhvcNAQECBQAwXzELMAkG
+MIICPDCCAaUCEDyRMcsf9tAbDpq40ES/Er4wDQYJKoZIhvcNAQEFBQAwXzELMAkG
A1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFz
cyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2
-MDEyOTAwMDAwMFoXDTI4MDgwMTIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
+MDEyOTAwMDAwMFoXDTI4MDgwMjIzNTk1OVowXzELMAkGA1UEBhMCVVMxFzAVBgNV
BAoTDlZlcmlTaWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAzIFB1YmxpYyBQcmlt
YXJ5IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIGfMA0GCSqGSIb3DQEBAQUAA4GN
ADCBiQKBgQDJXFme8huKARS0EN8EQNvjV69qRUCPhAwL0TPZ2RHP7gJYHyX3KqhE
BarsAx94f56TuZoAqiN91qyFomNFx3InzPRMxnVx0jnvT0Lwdd8KkMaOIG+YD/is
I19wKTakyYbnsZogy1Olhec9vn2a/iRFM9x2Fe0PonFkTGUugWhFpwIDAQABMA0G
-CSqGSIb3DQEBAgUAA4GBALtMEivPLCYATxQT3ab7/AoRhIzzKBxnki98tsX63/Do
-lbwdj2wsqFHMc9ikwFPwTtYmwHYBV4GSXiHx0bH/59AhWM1pF+NEHJwZRDmJXNyc
-AA9WjQKZ7aKQRUzkuxCkPfAyAw7xzvjoyVGM5mKf5p/AfbdynMk2OmufTqj/ZA1k
+CSqGSIb3DQEBBQUAA4GBABByUqkFFBkyCEHwxWsKzH4PIRnN5GfcX6kb5sroc50i
+2JhucwNhkcV8sEVAbkSdjbCxlnRhLQ2pRdKkkirWmnWXbj9T/UWZYB2oK0z5XqcJ
+2HUw19JlYD1n1khVdWk/kfVIC0dpImmClr7JyDiGSnoscxlIaU5rfGW/D/xwzoiQ
-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/882de061.0 b/luni/src/main/files/cacerts/882de061.0
new file mode 100644
index 0000000..959b9ea
--- /dev/null
+++ b/luni/src/main/files/cacerts/882de061.0
@@ -0,0 +1,78 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 20:06:05:16:70:02
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=RO, O=certSIGN, OU=certSIGN ROOT CA
+ Validity
+ Not Before: Jul 4 17:20:04 2006 GMT
+ Not After : Jul 4 17:20:04 2031 GMT
+ Subject: C=RO, O=certSIGN, OU=certSIGN ROOT CA
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:b7:33:b9:7e:c8:25:4a:8e:b5:db:b4:28:1b:aa:
+ 57:90:e8:d1:22:d3:64:ba:d3:93:e8:d4:ac:86:61:
+ 40:6a:60:57:68:54:84:4d:bc:6a:54:02:05:ff:df:
+ 9b:9a:2a:ae:5d:07:8f:4a:c3:28:7f:ef:fb:2b:fa:
+ 79:f1:c7:ad:f0:10:53:24:90:8b:66:c9:a8:88:ab:
+ af:5a:a3:00:e9:be:ba:46:ee:5b:73:7b:2c:17:82:
+ 81:5e:62:2c:a1:02:65:b3:bd:c5:2b:00:7e:c4:fc:
+ 03:33:57:0d:ed:e2:fa:ce:5d:45:d6:38:cd:35:b6:
+ b2:c1:d0:9c:81:4a:aa:e4:b2:01:5c:1d:8f:5f:99:
+ c4:b1:ad:db:88:21:eb:90:08:82:80:f3:30:a3:43:
+ e6:90:82:ae:55:28:49:ed:5b:d7:a9:10:38:0e:fe:
+ 8f:4c:5b:9b:46:ea:41:f5:b0:08:74:c3:d0:88:33:
+ b6:7c:d7:74:df:dc:84:d1:43:0e:75:39:a1:25:40:
+ 28:ea:78:cb:0e:2c:2e:39:9d:8c:8b:6e:16:1c:2f:
+ 26:82:10:e2:e3:65:94:0a:04:c0:5e:f7:5d:5b:f8:
+ 10:e2:d0:ba:7a:4b:fb:de:37:00:00:1a:5b:28:e3:
+ d2:9c:73:3e:32:87:98:a1:c9:51:2f:d7:de:ac:33:
+ b3:4f
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Digital Signature, Non Repudiation, Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ E0:8C:9B:DB:25:49:B3:F1:7C:86:D6:B2:42:87:0B:D0:6B:A0:D9:E4
+ Signature Algorithm: sha1WithRSAEncryption
+ 3e:d2:1c:89:2e:35:fc:f8:75:dd:e6:7f:65:88:f4:72:4c:c9:
+ 2c:d7:32:4e:f3:dd:19:79:47:bd:8e:3b:5b:93:0f:50:49:24:
+ 13:6b:14:06:72:ef:09:d3:a1:a1:e3:40:84:c9:e7:18:32:74:
+ 3c:48:6e:0f:9f:4b:d4:f7:1e:d3:93:86:64:54:97:63:72:50:
+ d5:55:cf:fa:20:93:02:a2:9b:c3:23:93:4e:16:55:76:a0:70:
+ 79:6d:cd:21:1f:cf:2f:2d:bc:19:e3:88:31:f8:59:1a:81:09:
+ c8:97:a6:74:c7:60:c4:5b:cc:57:8e:b2:75:fd:1b:02:09:db:
+ 59:6f:72:93:69:f7:31:41:d6:88:38:bf:87:b2:bd:16:79:f9:
+ aa:e4:be:88:25:dd:61:27:23:1c:b5:31:07:04:36:b4:1a:90:
+ bd:a0:74:71:50:89:6d:bc:14:e3:0f:86:ae:f1:ab:3e:c7:a0:
+ 09:cc:a3:48:d1:e0:db:64:e7:92:b5:cf:af:72:43:70:8b:f9:
+ c3:84:3c:13:aa:7e:92:9b:57:53:93:fa:70:c2:91:0e:31:f9:
+ 9b:67:5d:e9:96:38:5e:5f:b3:73:4e:88:15:67:de:9e:76:10:
+ 62:20:be:55:69:95:43:00:39:4d:f6:ee:b0:5a:4e:49:44:54:
+ 58:5f:42:83
+SHA1 Fingerprint=FA:B7:EE:36:97:26:62:FB:2D:B0:2A:F6:BF:03:FD:E8:7C:4B:2F:9B
+-----BEGIN CERTIFICATE-----
+MIIDODCCAiCgAwIBAgIGIAYFFnACMA0GCSqGSIb3DQEBBQUAMDsxCzAJBgNVBAYT
+AlJPMREwDwYDVQQKEwhjZXJ0U0lHTjEZMBcGA1UECxMQY2VydFNJR04gUk9PVCBD
+QTAeFw0wNjA3MDQxNzIwMDRaFw0zMTA3MDQxNzIwMDRaMDsxCzAJBgNVBAYTAlJP
+MREwDwYDVQQKEwhjZXJ0U0lHTjEZMBcGA1UECxMQY2VydFNJR04gUk9PVCBDQTCC
+ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALczuX7IJUqOtdu0KBuqV5Do
+0SLTZLrTk+jUrIZhQGpgV2hUhE28alQCBf/fm5oqrl0Hj0rDKH/v+yv6efHHrfAQ
+UySQi2bJqIirr1qjAOm+ukbuW3N7LBeCgV5iLKECZbO9xSsAfsT8AzNXDe3i+s5d
+RdY4zTW2ssHQnIFKquSyAVwdj1+ZxLGt24gh65AIgoDzMKND5pCCrlUoSe1b16kQ
+OA7+j0xbm0bqQfWwCHTD0IgztnzXdN/chNFDDnU5oSVAKOp4yw4sLjmdjItuFhwv
+JoIQ4uNllAoEwF73XVv4EOLQunpL+943AAAaWyjj0pxzPjKHmKHJUS/X3qwzs08C
+AwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAcYwHQYDVR0O
+BBYEFOCMm9slSbPxfIbWskKHC9BroNnkMA0GCSqGSIb3DQEBBQUAA4IBAQA+0hyJ
+LjX8+HXd5n9liPRyTMks1zJO890ZeUe9jjtbkw9QSSQTaxQGcu8J06Gh40CEyecY
+MnQ8SG4Pn0vU9x7Tk4ZkVJdjclDVVc/6IJMCopvDI5NOFlV2oHB5bc0hH88vLbwZ
+44gx+FkagQnIl6Z0x2DEW8xXjrJ1/RsCCdtZb3KTafcxQdaIOL+Hsr0Wefmq5L6I
+Jd1hJyMctTEHBDa0GpC9oHRxUIltvBTjD4au8as+x6AJzKNI0eDbZOeStc+vckNw
+i/nDhDwTqn6Sm1dTk/pwwpEOMfmbZ13pljheX7NzTogVZ96edhBiIL5VaZVDADlN
+9u6wWk5JRFRYX0KD
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/895cad1a.0 b/luni/src/main/files/cacerts/895cad1a.0
new file mode 100644
index 0000000..d620e48
--- /dev/null
+++ b/luni/src/main/files/cacerts/895cad1a.0
@@ -0,0 +1,82 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1228079105 (0x49330001)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=CN, O=CNNIC, CN=CNNIC ROOT
+ Validity
+ Not Before: Apr 16 07:09:14 2007 GMT
+ Not After : Apr 16 07:09:14 2027 GMT
+ Subject: C=CN, O=CNNIC, CN=CNNIC ROOT
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:d3:35:f7:3f:73:77:ad:e8:5b:73:17:c2:d1:6f:
+ ed:55:bc:6e:ea:e8:a4:79:b2:6c:c3:a3:ef:e1:9f:
+ b1:3b:48:85:f5:9a:5c:21:22:10:2c:c5:82:ce:da:
+ e3:9a:6e:37:e1:87:2c:dc:b9:0c:5a:ba:88:55:df:
+ fd:aa:db:1f:31:ea:01:f1:df:39:01:c1:13:fd:48:
+ 52:21:c4:55:df:da:d8:b3:54:76:ba:74:b1:b7:7d:
+ d7:c0:e8:f6:59:c5:4d:c8:bd:ad:1f:14:da:df:58:
+ 44:25:32:19:2a:c7:7e:7e:8e:ae:38:b0:30:7b:47:
+ 72:09:31:f0:30:db:c3:1b:76:29:bb:69:76:4e:57:
+ f9:1b:64:a2:93:56:b7:6f:99:6e:db:0a:04:9c:11:
+ e3:80:1f:cb:63:94:10:0a:a9:e1:64:82:31:f9:8c:
+ 27:ed:a6:99:00:f6:70:93:18:f8:a1:34:86:a3:dd:
+ 7a:c2:18:79:f6:7a:65:35:cf:90:eb:bd:33:93:9f:
+ 53:ab:73:3b:e6:9b:34:20:2f:1d:ef:a9:1d:63:1a:
+ a0:80:db:03:2f:f9:26:1a:86:d2:8d:bb:a9:be:52:
+ 3a:87:67:48:0d:bf:b4:a0:d8:26:be:23:5f:73:37:
+ 7f:26:e6:92:04:a3:7f:cf:20:a7:b7:f3:3a:ca:cb:
+ 99:cb
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ Netscape Cert Type:
+ SSL CA, S/MIME CA, Object Signing CA
+ X509v3 Authority Key Identifier:
+ keyid:65:F2:31:AD:2A:F7:F7:DD:52:96:0A:C7:02:C1:0E:EF:A6:D5:3B:11
+
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage:
+ Digital Signature, Non Repudiation, Key Encipherment, Data Encipherment, Key Agreement, Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ 65:F2:31:AD:2A:F7:F7:DD:52:96:0A:C7:02:C1:0E:EF:A6:D5:3B:11
+ Signature Algorithm: sha1WithRSAEncryption
+ 4b:35:ee:cc:e4:ae:bf:c3:6e:ad:9f:95:3b:4b:3f:5b:1e:df:
+ 57:29:a2:59:ca:38:e2:b9:1a:ff:9e:e6:6e:32:dd:1e:ae:ea:
+ 35:b7:f5:93:91:4e:da:42:e1:c3:17:60:50:f2:d1:5c:26:b9:
+ 82:b7:ea:6d:e4:9c:84:e7:03:79:17:af:98:3d:94:db:c7:ba:
+ 00:e7:b8:bf:01:57:c1:77:45:32:0c:3b:f1:b4:1c:08:b0:fd:
+ 51:a0:a1:dd:9a:1d:13:36:9a:6d:b7:c7:3c:b9:e1:c5:d9:17:
+ fa:83:d5:3d:15:a0:3c:bb:1e:0b:e2:c8:90:3f:a8:86:0c:fc:
+ f9:8b:5e:85:cb:4f:5b:4b:62:11:47:c5:45:7c:05:2f:41:b1:
+ 9e:10:69:1b:99:96:e0:55:79:fb:4e:86:99:b8:94:da:86:38:
+ 6a:93:a3:e7:cb:6e:e5:df:ea:21:55:89:9c:7d:7d:7f:98:f5:
+ 00:89:ee:e3:84:c0:5c:96:b5:c5:46:ea:46:e0:85:55:b6:1b:
+ c9:12:d6:c1:cd:cd:80:f3:02:01:3c:c8:69:cb:45:48:63:d8:
+ 94:d0:ec:85:0e:3b:4e:11:65:f4:82:8c:a6:3d:ae:2e:22:94:
+ 09:c8:5c:ea:3c:81:5d:16:2a:03:97:16:55:09:db:8a:41:82:
+ 9e:66:9b:11
+SHA1 Fingerprint=8B:AF:4C:9B:1D:F0:2A:92:F7:DA:12:8E:B9:1B:AC:F4:98:60:4B:6F
+-----BEGIN CERTIFICATE-----
+MIIDVTCCAj2gAwIBAgIESTMAATANBgkqhkiG9w0BAQUFADAyMQswCQYDVQQGEwJD
+TjEOMAwGA1UEChMFQ05OSUMxEzARBgNVBAMTCkNOTklDIFJPT1QwHhcNMDcwNDE2
+MDcwOTE0WhcNMjcwNDE2MDcwOTE0WjAyMQswCQYDVQQGEwJDTjEOMAwGA1UEChMF
+Q05OSUMxEzARBgNVBAMTCkNOTklDIFJPT1QwggEiMA0GCSqGSIb3DQEBAQUAA4IB
+DwAwggEKAoIBAQDTNfc/c3et6FtzF8LRb+1VvG7q6KR5smzDo+/hn7E7SIX1mlwh
+IhAsxYLO2uOabjfhhyzcuQxauohV3/2q2x8x6gHx3zkBwRP9SFIhxFXf2tizVHa6
+dLG3fdfA6PZZxU3Iva0fFNrfWEQlMhkqx35+jq44sDB7R3IJMfAw28Mbdim7aXZO
+V/kbZKKTVrdvmW7bCgScEeOAH8tjlBAKqeFkgjH5jCftppkA9nCTGPihNIaj3XrC
+GHn2emU1z5DrvTOTn1OrczvmmzQgLx3vqR1jGqCA2wMv+SYahtKNu6m+UjqHZ0gN
+v7Sg2Ca+I19zN38m5pIEo3/PIKe38zrKy5nLAgMBAAGjczBxMBEGCWCGSAGG+EIB
+AQQEAwIABzAfBgNVHSMEGDAWgBRl8jGtKvf33VKWCscCwQ7vptU7ETAPBgNVHRMB
+Af8EBTADAQH/MAsGA1UdDwQEAwIB/jAdBgNVHQ4EFgQUZfIxrSr3991SlgrHAsEO
+76bVOxEwDQYJKoZIhvcNAQEFBQADggEBAEs17szkrr/Dbq2flTtLP1se31cpolnK
+OOK5Gv+e5m4y3R6u6jW39ZORTtpC4cMXYFDy0VwmuYK36m3knITnA3kXr5g9lNvH
+ugDnuL8BV8F3RTIMO/G0HAiw/VGgod2aHRM2mm23xzy54cXZF/qD1T0VoDy7Hgvi
+yJA/qIYM/PmLXoXLT1tLYhFHxUV8BS9BsZ4QaRuZluBVeftOhpm4lNqGOGqTo+fL
+buXf6iFViZx9fX+Y9QCJ7uOEwFyWtcVG6kbghVW2G8kS1sHNzYDzAgE8yGnLRUhj
+2JTQ7IUOO04RZfSCjKY9ri4ilAnIXOo8gV0WKgOXFlUJ24pBgp5mmxE=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/89c02a45.0 b/luni/src/main/files/cacerts/89c02a45.0
new file mode 100644
index 0000000..e6c7d6e
--- /dev/null
+++ b/luni/src/main/files/cacerts/89c02a45.0
@@ -0,0 +1,54 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 1f:47:af:aa:62:00:70:50:54:4c:01:9e:9b:63:99:2a
+ Signature Algorithm: ecdsa-with-SHA384
+ Issuer: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO ECC Certification Authority
+ Validity
+ Not Before: Mar 6 00:00:00 2008 GMT
+ Not After : Jan 18 23:59:59 2038 GMT
+ Subject: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO ECC Certification Authority
+ Subject Public Key Info:
+ Public Key Algorithm: id-ecPublicKey
+ EC Public Key:
+ pub:
+ 04:03:47:7b:2f:75:c9:82:15:85:fb:75:e4:91:16:
+ d4:ab:62:99:f5:3e:52:0b:06:ce:41:00:7f:97:e1:
+ 0a:24:3c:1d:01:04:ee:3d:d2:8d:09:97:0c:e0:75:
+ e4:fa:fb:77:8a:2a:f5:03:60:4b:36:8b:16:23:16:
+ ad:09:71:f4:4a:f4:28:50:b4:fe:88:1c:6e:3f:6c:
+ 2f:2f:09:59:5b:a5:5b:0b:33:99:e2:c3:3d:89:f9:
+ 6a:2c:ef:b2:d3:06:e9
+ ASN1 OID: secp384r1
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ 75:71:A7:19:48:19:BC:9D:9D:EA:41:47:DF:94:C4:48:77:99:D3:79
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ Signature Algorithm: ecdsa-with-SHA384
+ 30:65:02:31:00:ef:03:5b:7a:ac:b7:78:0a:72:b7:88:df:ff:
+ b5:46:14:09:0a:fa:a0:e6:7d:08:c6:1a:87:bd:18:a8:73:bd:
+ 26:ca:60:0c:9d:ce:99:9f:cf:5c:0f:30:e1:be:14:31:ea:02:
+ 30:14:f4:93:3c:49:a7:33:7a:90:46:47:b3:63:7d:13:9b:4e:
+ b7:6f:18:37:80:53:fe:dd:20:e0:35:9a:36:d1:c7:01:b9:e6:
+ dc:dd:f3:ff:1d:2c:3a:16:57:d9:92:39:d6
+SHA1 Fingerprint=9F:74:4E:9F:2B:4D:BA:EC:0F:31:2C:50:B6:56:3B:8E:2D:93:C3:11
+-----BEGIN CERTIFICATE-----
+MIICiTCCAg+gAwIBAgIQH0evqmIAcFBUTAGem2OZKjAKBggqhkjOPQQDAzCBhTEL
+MAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UE
+BxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMT
+IkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDgwMzA2MDAw
+MDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdy
+ZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09N
+T0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBFQ0MgQ2VydGlmaWNhdGlv
+biBBdXRob3JpdHkwdjAQBgcqhkjOPQIBBgUrgQQAIgNiAAQDR3svdcmCFYX7deSR
+FtSrYpn1PlILBs5BAH+X4QokPB0BBO490o0JlwzgdeT6+3eKKvUDYEs2ixYjFq0J
+cfRK9ChQtP6IHG4/bC8vCVlbpVsLM5niwz2J+Wos77LTBumjQjBAMB0GA1UdDgQW
+BBR1cacZSBm8nZ3qQUfflMRId5nTeTAOBgNVHQ8BAf8EBAMCAQYwDwYDVR0TAQH/
+BAUwAwEB/zAKBggqhkjOPQQDAwNoADBlAjEA7wNbeqy3eApyt4jf/7VGFAkK+qDm
+fQjGGoe9GKhzvSbKYAydzpmfz1wPMOG+FDHqAjAU9JM8SaczepBGR7NjfRObTrdv
+GDeAU/7dIOA1mjbRxwG55tzd8/8dLDoWV9mSOdY=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/9685a493.0 b/luni/src/main/files/cacerts/9685a493.0
new file mode 100644
index 0000000..5d1f7ed
--- /dev/null
+++ b/luni/src/main/files/cacerts/9685a493.0
@@ -0,0 +1,75 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1000 (0x3e8)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=HK, O=Hongkong Post, CN=Hongkong Post Root CA 1
+ Validity
+ Not Before: May 15 05:13:14 2003 GMT
+ Not After : May 15 04:52:29 2023 GMT
+ Subject: C=HK, O=Hongkong Post, CN=Hongkong Post Root CA 1
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:ac:ff:38:b6:e9:66:02:49:e3:a2:b4:e1:90:f9:
+ 40:8f:79:f9:e2:bd:79:fe:02:bd:ee:24:92:1d:22:
+ f6:da:85:72:69:fe:d7:3f:09:d4:dd:91:b5:02:9c:
+ d0:8d:5a:e1:55:c3:50:86:b9:29:26:c2:e3:d9:a0:
+ f1:69:03:28:20:80:45:22:2d:56:a7:3b:54:95:56:
+ 22:59:1f:28:df:1f:20:3d:6d:a2:36:be:23:a0:b1:
+ 6e:b5:b1:27:3f:39:53:09:ea:ab:6a:e8:74:b2:c2:
+ 65:5c:8e:bf:7c:c3:78:84:cd:9e:16:fc:f5:2e:4f:
+ 20:2a:08:9f:77:f3:c5:1e:c4:9a:52:66:1e:48:5e:
+ e3:10:06:8f:22:98:e1:65:8e:1b:5d:23:66:3b:b8:
+ a5:32:51:c8:86:aa:a1:a9:9e:7f:76:94:c2:a6:6c:
+ b7:41:f0:d5:c8:06:38:e6:d4:0c:e2:f3:3b:4c:6d:
+ 50:8c:c4:83:27:c1:13:84:59:3d:9e:75:74:b6:d8:
+ 02:5e:3a:90:7a:c0:42:36:72:ec:6a:4d:dc:ef:c4:
+ 00:df:13:18:57:5f:26:78:c8:d6:0a:79:77:bf:f7:
+ af:b7:76:b9:a5:0b:84:17:5d:10:ea:6f:e1:ab:95:
+ 11:5f:6d:3c:a3:5c:4d:83:5b:f2:b3:19:8a:80:8b:
+ 0b:87
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE, pathlen:3
+ X509v3 Key Usage: critical
+ Digital Signature, Non Repudiation, Certificate Sign, CRL Sign
+ Signature Algorithm: sha1WithRSAEncryption
+ 0e:46:d5:3c:ae:e2:87:d9:5e:81:8b:02:98:41:08:8c:4c:bc:
+ da:db:ee:27:1b:82:e7:6a:45:ec:16:8b:4f:85:a0:f3:b2:70:
+ bd:5a:96:ba:ca:6e:6d:ee:46:8b:6e:e7:2a:2e:96:b3:19:33:
+ eb:b4:9f:a8:b2:37:ee:98:a8:97:b6:2e:b6:67:27:d4:a6:49:
+ fd:1c:93:65:76:9e:42:2f:dc:22:6c:9a:4f:f2:5a:15:39:b1:
+ 71:d7:2b:51:e8:6d:1c:98:c0:d9:2a:f4:a1:82:7b:d5:c9:41:
+ a2:23:01:74:38:55:8b:0f:b9:2e:67:a2:20:04:37:da:9c:0b:
+ d3:17:21:e0:8f:97:79:34:6f:84:48:02:20:33:1b:e6:34:44:
+ 9f:91:70:f4:80:5e:84:43:c2:29:d2:6c:12:14:e4:61:8d:ac:
+ 10:90:9e:84:50:bb:f0:96:6f:45:9f:8a:f3:ca:6c:4f:fa:11:
+ 3a:15:15:46:c3:cd:1f:83:5b:2d:41:12:ed:50:67:41:13:3d:
+ 21:ab:94:8a:aa:4e:7c:c1:b1:fb:a7:d6:b5:27:2f:97:ab:6e:
+ e0:1d:e2:d1:1c:2c:1f:44:e2:fc:be:91:a1:9c:fb:d6:29:53:
+ 73:86:9f:53:d8:43:0e:5d:d6:63:82:71:1d:80:74:ca:f6:e2:
+ 02:6b:d9:5a
+SHA1 Fingerprint=D6:DA:A8:20:8D:09:D2:15:4D:24:B5:2F:CB:34:6E:B2:58:B2:8A:58
+-----BEGIN CERTIFICATE-----
+MIIDMDCCAhigAwIBAgICA+gwDQYJKoZIhvcNAQEFBQAwRzELMAkGA1UEBhMCSEsx
+FjAUBgNVBAoTDUhvbmdrb25nIFBvc3QxIDAeBgNVBAMTF0hvbmdrb25nIFBvc3Qg
+Um9vdCBDQSAxMB4XDTAzMDUxNTA1MTMxNFoXDTIzMDUxNTA0NTIyOVowRzELMAkG
+A1UEBhMCSEsxFjAUBgNVBAoTDUhvbmdrb25nIFBvc3QxIDAeBgNVBAMTF0hvbmdr
+b25nIFBvc3QgUm9vdCBDQSAxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
+AQEArP84tulmAknjorThkPlAj3n54r15/gK97iSSHSL22oVyaf7XPwnU3ZG1ApzQ
+jVrhVcNQhrkpJsLj2aDxaQMoIIBFIi1WpztUlVYiWR8o3x8gPW2iNr4joLFutbEn
+PzlTCeqrauh0ssJlXI6/fMN4hM2eFvz1Lk8gKgifd/PFHsSaUmYeSF7jEAaPIpjh
+ZY4bXSNmO7ilMlHIhqqhqZ5/dpTCpmy3QfDVyAY45tQM4vM7TG1QjMSDJ8EThFk9
+nnV0ttgCXjqQesBCNnLsak3c78QA3xMYV18meMjWCnl3v/evt3a5pQuEF10Q6m/h
+q5URX208o1xNg1vysxmKgIsLhwIDAQABoyYwJDASBgNVHRMBAf8ECDAGAQH/AgED
+MA4GA1UdDwEB/wQEAwIBxjANBgkqhkiG9w0BAQUFAAOCAQEADkbVPK7ih9legYsC
+mEEIjEy82tvuJxuC52pF7BaLT4Wg87JwvVqWuspube5Gi27nKi6Wsxkz67SfqLI3
+7piol7Yutmcn1KZJ/RyTZXaeQi/cImyaT/JaFTmxcdcrUehtHJjA2Sr0oYJ71clB
+oiMBdDhViw+5LmeiIAQ32pwL0xch4I+XeTRvhEgCIDMb5jREn5Fw9IBehEPCKdJs
+EhTkYY2sEJCehFC78JZvRZ+K88psT/oROhUVRsPNH4NbLUES7VBnQRM9IauUiqpO
+fMGx+6fWtScvl6tu4B3i0RwsH0Ti/L6RoZz71ilTc4afU9hDDl3WY4JxHYB0yvbi
+AmvZWg==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/9d6523ce.0 b/luni/src/main/files/cacerts/9d6523ce.0
new file mode 100644
index 0000000..94078c4
--- /dev/null
+++ b/luni/src/main/files/cacerts/9d6523ce.0
@@ -0,0 +1,123 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 15:c8:bd:65:47:5c:af:b8:97:00:5e:e4:06:d2:bc:9d
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
+ Validity
+ Not Before: Dec 20 02:31:27 2004 GMT
+ Not After : Dec 20 02:31:27 2034 GMT
+ Subject: C=TW, O=Chunghwa Telecom Co., Ltd., OU=ePKI Root Certification Authority
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:e1:25:0f:ee:8d:db:88:33:75:67:cd:ad:1f:7d:
+ 3a:4e:6d:9d:d3:2f:14:f3:63:74:cb:01:21:6a:37:
+ ea:84:50:07:4b:26:5b:09:43:6c:21:9e:6a:c8:d5:
+ 03:f5:60:69:8f:cc:f0:22:e4:1f:e7:f7:6a:22:31:
+ b7:2c:15:f2:e0:fe:00:6a:43:ff:87:65:c6:b5:1a:
+ c1:a7:4c:6d:22:70:21:8a:31:f2:97:74:89:09:12:
+ 26:1c:9e:ca:d9:12:a2:95:3c:da:e9:67:bf:08:a0:
+ 64:e3:d6:42:b7:45:ef:97:f4:f6:f5:d7:b5:4a:15:
+ 02:58:7d:98:58:4b:60:bc:cd:d7:0d:9a:13:33:53:
+ d1:61:f9:7a:d5:d7:78:b3:9a:33:f7:00:86:ce:1d:
+ 4d:94:38:af:a8:ec:78:51:70:8a:5c:10:83:51:21:
+ f7:11:3d:34:86:5e:e5:48:cd:97:81:82:35:4c:19:
+ ec:65:f6:6b:c5:05:a1:ee:47:13:d6:b3:21:27:94:
+ 10:0a:d9:24:3b:ba:be:44:13:46:30:3f:97:3c:d8:
+ d7:d7:6a:ee:3b:38:e3:2b:d4:97:0e:b9:1b:e7:07:
+ 49:7f:37:2a:f9:77:78:cf:54:ed:5b:46:9d:a3:80:
+ 0e:91:43:c1:d6:5b:5f:14:ba:9f:a6:8d:24:47:40:
+ 59:bf:72:38:b2:36:6c:37:ff:99:d1:5d:0e:59:0a:
+ ab:69:f7:c0:b2:04:45:7a:54:00:ae:be:53:f6:b5:
+ e7:e1:f8:3c:a3:31:d2:a9:fe:21:52:64:c5:a6:67:
+ f0:75:07:06:94:14:81:55:c6:27:e4:01:8f:17:c1:
+ 6a:71:d7:be:4b:fb:94:58:7d:7e:11:33:b1:42:f7:
+ 62:6c:18:d6:cf:09:68:3e:7f:6c:f6:1e:8f:62:ad:
+ a5:63:db:09:a7:1f:22:42:41:1e:6f:99:8a:3e:d7:
+ f9:3f:40:7a:79:b0:a5:01:92:d2:9d:3d:08:15:a5:
+ 10:01:2d:b3:32:76:a8:95:0d:b3:7a:9a:fb:07:10:
+ 78:11:6f:e1:8f:c7:ba:0f:25:1a:74:2a:e5:1c:98:
+ 41:99:df:21:87:e8:95:06:6a:0a:b3:6a:47:76:65:
+ f6:3a:cf:8f:62:17:19:7b:0a:28:cd:1a:d2:83:1e:
+ 21:c7:2c:bf:be:ff:61:68:b7:67:1b:bb:78:4d:8d:
+ ce:67:e5:e4:c1:8e:b7:23:66:e2:9d:90:75:34:98:
+ a9:36:2b:8a:9a:94:b9:9d:ec:cc:8a:b1:f8:25:89:
+ 5c:5a:b6:2f:8c:1f:6d:79:24:a7:52:68:c3:84:35:
+ e2:66:8d:63:0e:25:4d:d5:19:b2:e6:79:37:a7:22:
+ 9d:54:31
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ 1E:0C:F7:B6:67:F2:E1:92:26:09:45:C0:55:39:2E:77:3F:42:4A:A2
+ X509v3 Basic Constraints:
+ CA:TRUE
+ setCext-hashedRoot:
+ 0/0-...0...+......0...g*.....E...
+V|.[x....S.....
+ Signature Algorithm: sha1WithRSAEncryption
+ 09:b3:83:53:59:01:3e:95:49:b9:f1:81:ba:f9:76:20:23:b5:
+ 27:60:74:d4:6a:99:34:5e:6c:00:53:d9:9f:f2:a6:b1:24:07:
+ 44:6a:2a:c6:a5:8e:78:12:e8:47:d9:58:1b:13:2a:5e:79:9b:
+ 9f:0a:2a:67:a6:25:3f:06:69:56:73:c3:8a:66:48:fb:29:81:
+ 57:74:06:ca:9c:ea:28:e8:38:67:26:2b:f1:d5:b5:3f:65:93:
+ f8:36:5d:8e:8d:8d:40:20:87:19:ea:ef:27:c0:3d:b4:39:0f:
+ 25:7b:68:50:74:55:9c:0c:59:7d:5a:3d:41:94:25:52:08:e0:
+ 47:2c:15:31:19:d5:bf:07:55:c6:bb:12:b5:97:f4:5f:83:85:
+ ba:71:c1:d9:6c:81:11:76:0a:0a:b0:bf:82:97:f7:ea:3d:fa:
+ fa:ec:2d:a9:28:94:3b:56:dd:d2:51:2e:ae:c0:bd:08:15:8c:
+ 77:52:34:96:d6:9b:ac:d3:1d:8e:61:0f:35:7b:9b:ae:39:69:
+ 0b:62:60:40:20:36:8f:af:fb:36:ee:2d:08:4a:1d:b8:bf:9b:
+ 5c:f8:ea:a5:1b:a0:73:a6:d8:f8:6e:e0:33:04:5f:68:aa:27:
+ 87:ed:d9:c1:90:9c:ed:bd:e3:6a:35:af:63:df:ab:18:d9:ba:
+ e6:e9:4a:ea:50:8a:0f:61:93:1e:e2:2d:19:e2:30:94:35:92:
+ 5d:0e:b6:07:af:19:80:8f:47:90:51:4b:2e:4d:dd:85:e2:d2:
+ 0a:52:0a:17:9a:fc:1a:b0:50:02:e5:01:a3:63:37:21:4c:44:
+ c4:9b:51:99:11:0e:73:9c:06:8f:54:2e:a7:28:5e:44:39:87:
+ 56:2d:37:bd:85:44:94:e1:0c:4b:2c:9c:c3:92:85:34:61:cb:
+ 0f:b8:9b:4a:43:52:fe:34:3a:7d:b8:e9:29:dc:76:a9:c8:30:
+ f8:14:71:80:c6:1e:36:48:74:22:41:5c:87:82:e8:18:71:8b:
+ 41:89:44:e7:7e:58:5b:a8:b8:8d:13:e9:a7:6c:c3:47:ed:b3:
+ 1a:9d:62:ae:8d:82:ea:94:9e:dd:59:10:c3:ad:dd:e2:4d:e3:
+ 31:d5:c7:ec:e8:f2:b0:fe:92:1e:16:0a:1a:fc:d9:f3:f8:27:
+ b6:c9:be:1d:b4:6c:64:90:7f:f4:e4:c4:5b:d7:37:ae:42:0e:
+ dd:a4:1a:6f:7c:88:54:c5:16:6e:e1:7a:68:2e:f8:3a:bf:0d:
+ a4:3c:89:3b:78:a7:4e:63:83:04:21:08:67:8d:f2:82:49:d0:
+ 5b:fd:b1:cd:0f:83:84:d4:3e:20:85:f7:4a:3d:2b:9c:fd:2a:
+ 0a:09:4d:ea:81:f8:11:9c
+SHA1 Fingerprint=67:65:0D:F1:7E:8E:7E:5B:82:40:A4:F4:56:4B:CF:E2:3D:69:C6:F0
+-----BEGIN CERTIFICATE-----
+MIIFsDCCA5igAwIBAgIQFci9ZUdcr7iXAF7kBtK8nTANBgkqhkiG9w0BAQUFADBe
+MQswCQYDVQQGEwJUVzEjMCEGA1UECgwaQ2h1bmdod2EgVGVsZWNvbSBDby4sIEx0
+ZC4xKjAoBgNVBAsMIWVQS0kgUm9vdCBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAe
+Fw0wNDEyMjAwMjMxMjdaFw0zNDEyMjAwMjMxMjdaMF4xCzAJBgNVBAYTAlRXMSMw
+IQYDVQQKDBpDaHVuZ2h3YSBUZWxlY29tIENvLiwgTHRkLjEqMCgGA1UECwwhZVBL
+SSBSb290IENlcnRpZmljYXRpb24gQXV0aG9yaXR5MIICIjANBgkqhkiG9w0BAQEF
+AAOCAg8AMIICCgKCAgEA4SUP7o3biDN1Z82tH306Tm2d0y8U82N0ywEhajfqhFAH
+SyZbCUNsIZ5qyNUD9WBpj8zwIuQf5/dqIjG3LBXy4P4AakP/h2XGtRrBp0xtInAh
+ijHyl3SJCRImHJ7K2RKilTza6We/CKBk49ZCt0Xvl/T29de1ShUCWH2YWEtgvM3X
+DZoTM1PRYfl61dd4s5oz9wCGzh1NlDivqOx4UXCKXBCDUSH3ET00hl7lSM2XgYI1
+TBnsZfZrxQWh7kcT1rMhJ5QQCtkkO7q+RBNGMD+XPNjX12ruOzjjK9SXDrkb5wdJ
+fzcq+Xd4z1TtW0ado4AOkUPB1ltfFLqfpo0kR0BZv3I4sjZsN/+Z0V0OWQqraffA
+sgRFelQArr5T9rXn4fg8ozHSqf4hUmTFpmfwdQcGlBSBVcYn5AGPF8Fqcde+S/uU
+WH1+ETOxQvdibBjWzwloPn9s9h6PYq2lY9sJpx8iQkEeb5mKPtf5P0B6ebClAZLS
+nT0IFaUQAS2zMnaolQ2zepr7BxB4EW/hj8e6DyUadCrlHJhBmd8hh+iVBmoKs2pH
+dmX2Os+PYhcZewoozRrSgx4hxyy/vv9haLdnG7t4TY3OZ+XkwY63I2binZB1NJip
+NiuKmpS5nezMirH4JYlcWrYvjB9teSSnUmjDhDXiZo1jDiVN1Rmy5nk3pyKdVDEC
+AwEAAaNqMGgwHQYDVR0OBBYEFB4M97Zn8uGSJglFwFU5Lnc/QkqiMAwGA1UdEwQF
+MAMBAf8wOQYEZyoHAAQxMC8wLQIBADAJBgUrDgMCGgUAMAcGBWcqAwAABBRFsMLH
+ClZ87lt4DJX5GFPBphzYEDANBgkqhkiG9w0BAQUFAAOCAgEACbODU1kBPpVJufGB
+uvl2ICO1J2B01GqZNF5sAFPZn/KmsSQHRGoqxqWOeBLoR9lYGxMqXnmbnwoqZ6Yl
+PwZpVnPDimZI+ymBV3QGypzqKOg4ZyYr8dW1P2WT+DZdjo2NQCCHGervJ8A9tDkP
+JXtoUHRVnAxZfVo9QZQlUgjgRywVMRnVvwdVxrsStZf0X4OFunHB2WyBEXYKCrC/
+gpf36j36+uwtqSiUO1bd0lEursC9CBWMd1I0ltabrNMdjmEPNXubrjlpC2JgQCA2
+j6/7Nu4tCEoduL+bXPjqpRugc6bY+G7gMwRfaKonh+3ZwZCc7b3jajWvY9+rGNm6
+5ulK6lCKD2GTHuItGeIwlDWSXQ62B68ZgI9HkFFLLk3dheLSClIKF5r8GrBQAuUB
+o2M3IUxExJtRmREOc5wGj1QupyheRDmHVi03vYVElOEMSyycw5KFNGHLD7ibSkNS
+/jQ6fbjpKdx2qcgw+BRxgMYeNkh0IkFch4LoGHGLQYlE535YW6i4jRPpp2zDR+2z
+Gp1iro2C6pSe3VkQw63d4k3jMdXH7OjysP6SHhYKGvzZ8/gntsm+HbRsZJB/9OTE
+W9c3rkIO3aQab3yIVMUWbuF6aC74Or8NpDyJO3inTmODBCEIZ43ygknQW/2xzQ+D
+hNQ+IIX3Sj0rnP0qCglN6oH4EZw=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/9f533518.0 b/luni/src/main/files/cacerts/9f533518.0
new file mode 100644
index 0000000..c05a115
--- /dev/null
+++ b/luni/src/main/files/cacerts/9f533518.0
@@ -0,0 +1,139 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ c9:cd:d3:e9:d5:7d:23:ce
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=EU, L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287, O=AC Camerfirma S.A., CN=Global Chambersign Root - 2008
+ Validity
+ Not Before: Aug 1 12:31:40 2008 GMT
+ Not After : Jul 31 12:31:40 2038 GMT
+ Subject: C=EU, L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287, O=AC Camerfirma S.A., CN=Global Chambersign Root - 2008
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:c0:df:56:d3:e4:3a:9b:76:45:b4:13:db:ff:c1:
+ b6:19:8b:37:41:18:95:52:47:eb:17:9d:29:88:8e:
+ 35:6c:06:32:2e:47:62:f3:49:04:bf:7d:44:36:b1:
+ 71:cc:bd:5a:09:73:d5:d9:85:44:ff:91:57:25:df:
+ 5e:36:8e:70:d1:5c:71:43:1d:d9:da:ef:5c:d2:fb:
+ 1b:bd:3a:b5:cb:ad:a3:cc:44:a7:0d:ae:21:15:3f:
+ b9:7a:5b:92:75:d8:a4:12:38:89:19:8a:b7:80:d2:
+ e2:32:6f:56:9c:91:d6:88:10:0b:b3:74:64:92:74:
+ 60:f3:f6:cf:18:4f:60:b2:23:d0:c7:3b:ce:61:4b:
+ 99:8f:c2:0c:d0:40:b2:98:dc:0d:a8:4e:a3:b9:0a:
+ ae:60:a0:ad:45:52:63:ba:66:bd:68:e0:f9:be:1a:
+ a8:81:bb:1e:41:78:75:d3:c1:fe:00:55:b0:87:54:
+ e8:27:90:35:1d:4c:33:ad:97:fc:97:2e:98:84:bf:
+ 2c:c9:a3:bf:d1:98:11:14:ed:63:f8:ca:98:88:58:
+ 17:99:ed:45:03:97:7e:3c:86:1e:88:8c:be:f2:91:
+ 84:8f:65:34:d8:00:4c:7d:b7:31:17:5a:29:7a:0a:
+ 18:24:30:a3:37:b5:7a:a9:01:7d:26:d6:f9:0e:8e:
+ 59:f1:fd:1b:33:b5:29:3b:17:3b:41:b6:21:dd:d4:
+ c0:3d:a5:9f:9f:1f:43:50:c9:bb:bc:6c:7a:97:98:
+ ee:cd:8c:1f:fb:9c:51:ae:8b:70:bd:27:9f:71:c0:
+ 6b:ac:7d:90:66:e8:d7:5d:3a:0d:b0:d5:c2:8d:d5:
+ c8:9d:9d:c1:6d:d0:d0:bf:51:e4:e3:f8:c3:38:36:
+ ae:d6:a7:75:e6:af:84:43:5d:93:92:0c:6a:07:de:
+ 3b:1d:98:22:d6:ac:c1:35:db:a3:a0:25:ff:72:b5:
+ 76:1d:de:6d:e9:2c:66:2c:52:84:d0:45:92:ce:1c:
+ e5:e5:33:1d:dc:07:53:54:a3:aa:82:3b:9a:37:2f:
+ dc:dd:a0:64:e9:e6:dd:bd:ae:fc:64:85:1d:3c:a7:
+ c9:06:de:84:ff:6b:e8:6b:1a:3c:c5:a2:b3:42:fb:
+ 8b:09:3e:5f:08:52:c7:62:c4:d4:05:71:bf:c4:64:
+ e4:f8:a1:83:e8:3e:12:9b:a8:1e:d4:36:4d:2f:71:
+ f6:8d:28:f6:83:a9:13:d2:61:c1:91:bb:48:c0:34:
+ 8f:41:8c:4b:4c:db:69:12:ff:50:94:9c:20:83:59:
+ 73:ed:7c:a1:f2:f1:fd:dd:f7:49:d3:43:58:a0:56:
+ 63:ca:3d:3d:e5:35:56:59:e9:0e:ca:20:cc:2b:4b:
+ 93:29:0f
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE, pathlen:12
+ X509v3 Subject Key Identifier:
+ B9:09:CA:9C:1E:DB:D3:6C:3A:6B:AE:ED:54:F1:5B:93:06:35:2E:5E
+ X509v3 Authority Key Identifier:
+ keyid:B9:09:CA:9C:1E:DB:D3:6C:3A:6B:AE:ED:54:F1:5B:93:06:35:2E:5E
+ DirName:/C=EU/L=Madrid (see current address at www.camerfirma.com/address)/serialNumber=A82743287/O=AC Camerfirma S.A./CN=Global Chambersign Root - 2008
+ serial:C9:CD:D3:E9:D5:7D:23:CE
+
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Certificate Policies:
+ Policy: X509v3 Any Policy
+ CPS: http://policy.camerfirma.com
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 80:88:7f:70:de:92:28:d9:05:94:46:ff:90:57:a9:f1:2f:df:
+ 1a:0d:6b:fa:7c:0e:1c:49:24:79:27:d8:46:aa:6f:29:59:52:
+ 88:70:12:ea:dd:3d:f5:9b:53:54:6f:e1:60:a2:a8:09:b9:ec:
+ eb:59:7c:c6:35:f1:dc:18:e9:f1:67:e5:af:ba:45:e0:09:de:
+ ca:44:0f:c2:17:0e:77:91:45:7a:33:5f:5f:96:2c:68:8b:c1:
+ 47:8f:98:9b:3d:c0:ec:cb:f5:d5:82:92:84:35:d1:be:36:38:
+ 56:72:31:5b:47:2d:aa:17:a4:63:51:eb:0a:01:ad:7f:ec:75:
+ 9e:cb:a1:1f:f1:7f:12:b1:b9:e4:64:7f:67:d6:23:2a:f4:b8:
+ 39:5d:98:e8:21:a7:e1:bd:3d:42:1a:74:9a:70:af:68:6c:50:
+ 5d:49:cf:ff:fb:0e:5d:e6:2c:47:d7:81:3a:59:00:b5:73:6b:
+ 63:20:f6:31:45:08:39:0e:f4:70:7e:40:70:5a:3f:d0:6b:42:
+ a9:74:3d:28:2f:02:6d:75:72:95:09:8d:48:63:c6:c6:23:57:
+ 92:93:5e:35:c1:8d:f9:0a:f7:2c:9d:62:1c:f6:ad:7c:dd:a6:
+ 31:1e:b6:b1:c7:7e:85:26:fa:a4:6a:b5:da:63:30:d1:ef:93:
+ 37:b2:66:2f:7d:05:f7:e7:b7:4b:98:94:35:c0:d9:3a:29:c1:
+ 9d:b2:50:33:1d:4a:a9:5a:a6:c9:03:ef:ed:f4:e7:a8:6e:8a:
+ b4:57:84:eb:a4:3f:d0:ee:aa:aa:87:5b:63:e8:93:e2:6b:a8:
+ d4:b8:72:78:6b:1b:ed:39:e4:5d:cb:9b:aa:87:d5:4f:4e:00:
+ fe:d9:6a:9f:3c:31:0f:28:02:01:7d:98:e8:a7:b0:a2:64:9e:
+ 79:f8:48:f2:15:a9:cc:e6:c8:44:eb:3f:78:99:f2:7b:71:3e:
+ 3c:f1:98:a7:c5:18:12:3f:e6:bb:28:33:42:e9:45:0a:7c:6d:
+ f2:86:79:2f:c5:82:19:7d:09:89:7c:b2:54:76:88:ae:de:c1:
+ f3:cc:e1:6e:db:31:d6:93:ae:99:a0:ef:25:6a:73:98:89:5b:
+ 3a:2e:13:88:1e:bf:c0:92:94:34:1b:e3:27:b7:8b:1e:6f:42:
+ ff:e7:e9:37:9b:50:1d:2d:a2:f9:02:ee:cb:58:58:3a:71:bc:
+ 68:e3:aa:c1:af:1c:28:1f:a2:dc:23:65:3f:81:ea:ae:99:d3:
+ d8:30:cf:13:0d:4f:15:c9:84:bc:a7:48:2d:f8:30:23:77:d8:
+ 46:4b:79:6d:f6:8c:ed:3a:7f:60:11:78:f4:e9:9b:ae:d5:54:
+ c0:74:80:d1:0b:42:9f:c1
+SHA1 Fingerprint=4A:BD:EE:EC:95:0D:35:9C:89:AE:C7:52:A1:2C:5B:29:F6:D6:AA:0C
+-----BEGIN CERTIFICATE-----
+MIIHSTCCBTGgAwIBAgIJAMnN0+nVfSPOMA0GCSqGSIb3DQEBBQUAMIGsMQswCQYD
+VQQGEwJFVTFDMEEGA1UEBxM6TWFkcmlkIChzZWUgY3VycmVudCBhZGRyZXNzIGF0
+IHd3dy5jYW1lcmZpcm1hLmNvbS9hZGRyZXNzKTESMBAGA1UEBRMJQTgyNzQzMjg3
+MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMuQS4xJzAlBgNVBAMTHkdsb2JhbCBD
+aGFtYmVyc2lnbiBSb290IC0gMjAwODAeFw0wODA4MDExMjMxNDBaFw0zODA3MzEx
+MjMxNDBaMIGsMQswCQYDVQQGEwJFVTFDMEEGA1UEBxM6TWFkcmlkIChzZWUgY3Vy
+cmVudCBhZGRyZXNzIGF0IHd3dy5jYW1lcmZpcm1hLmNvbS9hZGRyZXNzKTESMBAG
+A1UEBRMJQTgyNzQzMjg3MRswGQYDVQQKExJBQyBDYW1lcmZpcm1hIFMuQS4xJzAl
+BgNVBAMTHkdsb2JhbCBDaGFtYmVyc2lnbiBSb290IC0gMjAwODCCAiIwDQYJKoZI
+hvcNAQEBBQADggIPADCCAgoCggIBAMDfVtPkOpt2RbQT2//BthmLN0EYlVJH6xed
+KYiONWwGMi5HYvNJBL99RDaxccy9Wglz1dmFRP+RVyXfXjaOcNFccUMd2drvXNL7
+G706tcuto8xEpw2uIRU/uXpbknXYpBI4iRmKt4DS4jJvVpyR1ogQC7N0ZJJ0YPP2
+zxhPYLIj0Mc7zmFLmY/CDNBAspjcDahOo7kKrmCgrUVSY7pmvWjg+b4aqIG7HkF4
+ddPB/gBVsIdU6CeQNR1MM62X/JcumIS/LMmjv9GYERTtY/jKmIhYF5ntRQOXfjyG
+HoiMvvKRhI9lNNgATH23MRdaKXoKGCQwoze1eqkBfSbW+Q6OWfH9GzO1KTsXO0G2
+Id3UwD2ln58fQ1DJu7xsepeY7s2MH/ucUa6LcL0nn3HAa6x9kGbo1106DbDVwo3V
+yJ2dwW3Q0L9R5OP4wzg2rtandeavhENdk5IMagfeOx2YItaswTXbo6Al/3K1dh3e
+beksZixShNBFks4c5eUzHdwHU1SjqoI7mjcv3N2gZOnm3b2u/GSFHTynyQbehP9r
+6GsaPMWis0L7iwk+XwhSx2LE1AVxv8Rk5Pihg+g+EpuoHtQ2TS9x9o0o9oOpE9Jh
+wZG7SMA0j0GMS0zbaRL/UJScIINZc+18ofLx/d33SdNDWKBWY8o9PeU1VlnpDsog
+zCtLkykPAgMBAAGjggFqMIIBZjASBgNVHRMBAf8ECDAGAQH/AgEMMB0GA1UdDgQW
+BBS5CcqcHtvTbDprru1U8VuTBjUuXjCB4QYDVR0jBIHZMIHWgBS5CcqcHtvTbDpr
+ru1U8VuTBjUuXqGBsqSBrzCBrDELMAkGA1UEBhMCRVUxQzBBBgNVBAcTOk1hZHJp
+ZCAoc2VlIGN1cnJlbnQgYWRkcmVzcyBhdCB3d3cuY2FtZXJmaXJtYS5jb20vYWRk
+cmVzcykxEjAQBgNVBAUTCUE4Mjc0MzI4NzEbMBkGA1UEChMSQUMgQ2FtZXJmaXJt
+YSBTLkEuMScwJQYDVQQDEx5HbG9iYWwgQ2hhbWJlcnNpZ24gUm9vdCAtIDIwMDiC
+CQDJzdPp1X0jzjAOBgNVHQ8BAf8EBAMCAQYwPQYDVR0gBDYwNDAyBgRVHSAAMCow
+KAYIKwYBBQUHAgEWHGh0dHA6Ly9wb2xpY3kuY2FtZXJmaXJtYS5jb20wDQYJKoZI
+hvcNAQEFBQADggIBAICIf3DekijZBZRG/5BXqfEv3xoNa/p8DhxJJHkn2EaqbylZ
+UohwEurdPfWbU1Rv4WCiqAm57OtZfMY18dwY6fFn5a+6ReAJ3spED8IXDneRRXoz
+X1+WLGiLwUePmJs9wOzL9dWCkoQ10b42OFZyMVtHLaoXpGNR6woBrX/sdZ7LoR/x
+fxKxueRkf2fWIyr0uDldmOghp+G9PUIadJpwr2hsUF1Jz//7Dl3mLEfXgTpZALVz
+a2Mg9jFFCDkO9HB+QHBaP9BrQql0PSgvAm11cpUJjUhjxsYjV5KTXjXBjfkK9yyd
+Yhz2rXzdpjEetrHHfoUm+qRqtdpjMNHvkzeyZi99Bffnt0uYlDXA2TopwZ2yUDMd
+SqlapskD7+3056huirRXhOukP9DuqqqHW2Pok+JrqNS4cnhrG+055F3Lm6qH1U9O
+AP7Zap88MQ8oAgF9mOinsKJknnn4SPIVqczmyETrP3iZ8ntxPjzxmKfFGBI/5rso
+M0LpRQp8bfKGeS/Fghl9CYl8slR2iK7ewfPM4W7bMdaTrpmg7yVqc5iJWzouE4ge
+v8CSlDQb4ye3ix5vQv/n6TebUB0tovkC7stYWDpxvGjjqsGvHCgfotwjZT+B6q6Z
+09gwzxMNTxXJhLynSC34MCN32EZLeW32jO06f2ARePTpm67VVMB0gNELQp/B
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/a7d2cf64.0 b/luni/src/main/files/cacerts/a7d2cf64.0
new file mode 100644
index 0000000..1ad657a
--- /dev/null
+++ b/luni/src/main/files/cacerts/a7d2cf64.0
@@ -0,0 +1,54 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 35:fc:26:5c:d9:84:4f:c9:3d:26:3d:57:9b:ae:d7:56
+ Signature Algorithm: ecdsa-with-SHA384
+ Issuer: C=US, O=thawte, Inc., OU=(c) 2007 thawte, Inc. - For authorized use only, CN=thawte Primary Root CA - G2
+ Validity
+ Not Before: Nov 5 00:00:00 2007 GMT
+ Not After : Jan 18 23:59:59 2038 GMT
+ Subject: C=US, O=thawte, Inc., OU=(c) 2007 thawte, Inc. - For authorized use only, CN=thawte Primary Root CA - G2
+ Subject Public Key Info:
+ Public Key Algorithm: id-ecPublicKey
+ EC Public Key:
+ pub:
+ 04:a2:d5:9c:82:7b:95:9d:f1:52:78:87:fe:8a:16:
+ bf:05:e6:df:a3:02:4f:0d:07:c6:00:51:ba:0c:02:
+ 52:2d:22:a4:42:39:c4:fe:8f:ea:c9:c1:be:d4:4d:
+ ff:9f:7a:9e:e2:b1:7c:9a:ad:a7:86:09:73:87:d1:
+ e7:9a:e3:7a:a5:aa:6e:fb:ba:b3:70:c0:67:88:a2:
+ 35:d4:a3:9a:b1:fd:ad:c2:ef:31:fa:a8:b9:f3:fb:
+ 08:c6:91:d1:fb:29:95
+ ASN1 OID: secp384r1
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ 9A:D8:00:30:00:E7:6B:7F:85:18:EE:8B:B6:CE:8A:0C:F8:11:E1:BB
+ Signature Algorithm: ecdsa-with-SHA384
+ 30:66:02:31:00:dd:f8:e0:57:47:5b:a7:e6:0a:c3:bd:f5:80:
+ 8a:97:35:0d:1b:89:3c:54:86:77:28:ca:a1:f4:79:de:b5:e6:
+ 38:b0:f0:65:70:8c:7f:02:54:c2:bf:ff:d8:a1:3e:d9:cf:02:
+ 31:00:c4:8d:94:fc:dc:53:d2:dc:9d:78:16:1f:15:33:23:53:
+ 52:e3:5a:31:5d:9d:ca:ae:bd:13:29:44:0d:27:5b:a8:e7:68:
+ 9c:12:f7:58:3f:2e:72:02:57:a3:8f:a1:14:2e
+SHA1 Fingerprint=AA:DB:BC:22:23:8F:C4:01:A1:27:BB:38:DD:F4:1D:DB:08:9E:F0:12
+-----BEGIN CERTIFICATE-----
+MIICiDCCAg2gAwIBAgIQNfwmXNmET8k9Jj1Xm67XVjAKBggqhkjOPQQDAzCBhDEL
+MAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjE4MDYGA1UECxMvKGMp
+IDIwMDcgdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAi
+BgNVBAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMjAeFw0wNzExMDUwMDAw
+MDBaFw0zODAxMTgyMzU5NTlaMIGEMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhh
+d3RlLCBJbmMuMTgwNgYDVQQLEy8oYykgMjAwNyB0aGF3dGUsIEluYy4gLSBGb3Ig
+YXV0aG9yaXplZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9v
+dCBDQSAtIEcyMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEotWcgnuVnfFSeIf+iha/
+BebfowJPDQfGAFG6DAJSLSKkQjnE/o/qycG+1E3/n3qe4rF8mq2nhglzh9HnmuN6
+papu+7qzcMBniKI11KOasf2twu8x+qi58/sIxpHR+ymVo0IwQDAPBgNVHRMBAf8E
+BTADAQH/MA4GA1UdDwEB/wQEAwIBBjAdBgNVHQ4EFgQUmtgAMADna3+FGO6Lts6K
+DPgR4bswCgYIKoZIzj0EAwMDaQAwZgIxAN344FdHW6fmCsO99YCKlzUNG4k8VIZ3
+KMqh9HneteY4sPBlcIx/AlTCv//YoT7ZzwIxAMSNlPzcU9LcnXgWHxUzI1NS41ox
+XZ3Krr0TKUQNJ1uo52icEvdYPy5yAlejj6EULg==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/ab5346f4.0 b/luni/src/main/files/cacerts/ab5346f4.0
new file mode 100644
index 0000000..1dbed66
--- /dev/null
+++ b/luni/src/main/files/cacerts/ab5346f4.0
@@ -0,0 +1,78 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1 (0x1)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=JP, O=Japan Certification Services, Inc., CN=SecureSign RootCA11
+ Validity
+ Not Before: Apr 8 04:56:47 2009 GMT
+ Not After : Apr 8 04:56:47 2029 GMT
+ Subject: C=JP, O=Japan Certification Services, Inc., CN=SecureSign RootCA11
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:fd:77:aa:a5:1c:90:05:3b:cb:4c:9b:33:8b:5a:
+ 14:45:a4:e7:90:16:d1:df:57:d2:21:10:a4:17:fd:
+ df:ac:d6:1f:a7:e4:db:7c:f7:ec:df:b8:03:da:94:
+ 58:fd:5d:72:7c:8c:3f:5f:01:67:74:15:96:e3:02:
+ 3c:87:db:ae:cb:01:8e:c2:f3:66:c6:85:45:f4:02:
+ c6:3a:b5:62:b2:af:fa:9c:bf:a4:e6:d4:80:30:98:
+ f3:0d:b6:93:8f:a9:d4:d8:36:f2:b0:fc:8a:ca:2c:
+ a1:15:33:95:31:da:c0:1b:f2:ee:62:99:86:63:3f:
+ bf:dd:93:2a:83:a8:76:b9:13:1f:b7:ce:4e:42:85:
+ 8f:22:e7:2e:1a:f2:95:09:b2:05:b5:44:4e:77:a1:
+ 20:bd:a9:f2:4e:0a:7d:50:ad:f5:05:0d:45:4f:46:
+ 71:fd:28:3e:53:fb:04:d8:2d:d7:65:1d:4a:1b:fa:
+ cf:3b:b0:31:9a:35:6e:c8:8b:06:d3:00:91:f2:94:
+ 08:65:4c:b1:34:06:00:7a:89:e2:f0:c7:03:59:cf:
+ d5:d6:e8:a7:32:b3:e6:98:40:86:c5:cd:27:12:8b:
+ cc:7b:ce:b7:11:3c:62:60:07:23:3e:2b:40:6e:94:
+ 80:09:6d:b6:b3:6f:77:6f:35:08:50:fb:02:87:c5:
+ 3e:89
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ 5B:F8:4D:4F:B2:A5:86:D4:3A:D2:F1:63:9A:A0:BE:09:F6:57:B7:DE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ Signature Algorithm: sha1WithRSAEncryption
+ a0:a1:38:16:66:2e:a7:56:1f:21:9c:06:fa:1d:ed:b9:22:c5:
+ 38:26:d8:4e:4f:ec:a3:7f:79:de:46:21:a1:87:77:8f:07:08:
+ 9a:b2:a4:c5:af:0f:32:98:0b:7c:66:29:b6:9b:7d:25:52:49:
+ 43:ab:4c:2e:2b:6e:7a:70:af:16:0e:e3:02:6c:fb:42:e6:18:
+ 9d:45:d8:55:c8:e8:3b:dd:e7:e1:f4:2e:0b:1c:34:5c:6c:58:
+ 4a:fb:8c:88:50:5f:95:1c:bf:ed:ab:22:b5:65:b3:85:ba:9e:
+ 0f:b8:ad:e5:7a:1b:8a:50:3a:1d:bd:0d:bc:7b:54:50:0b:b9:
+ 42:af:55:a0:18:81:ad:65:99:ef:be:e4:9c:bf:c4:85:ab:41:
+ b2:54:6f:dc:25:cd:ed:78:e2:8e:0c:8d:09:49:dd:63:7b:5a:
+ 69:96:02:21:a8:bd:52:59:e9:7d:35:cb:c8:52:ca:7f:81:fe:
+ d9:6b:d3:f7:11:ed:25:df:f8:e7:f9:a4:fa:72:97:84:53:0d:
+ a5:d0:32:18:51:76:59:14:6c:0f:eb:ec:5f:80:8c:75:43:83:
+ c3:85:98:ff:4c:9e:2d:0d:e4:77:83:93:4e:b5:96:07:8b:28:
+ 13:9b:8c:19:8d:41:27:49:40:ee:de:e6:23:44:39:dc:a1:22:
+ d6:ba:03:f2
+SHA1 Fingerprint=3B:C4:9F:48:F8:F3:73:A0:9C:1E:BD:F8:5B:B1:C3:65:C7:D8:11:B3
+-----BEGIN CERTIFICATE-----
+MIIDbTCCAlWgAwIBAgIBATANBgkqhkiG9w0BAQUFADBYMQswCQYDVQQGEwJKUDEr
+MCkGA1UEChMiSmFwYW4gQ2VydGlmaWNhdGlvbiBTZXJ2aWNlcywgSW5jLjEcMBoG
+A1UEAxMTU2VjdXJlU2lnbiBSb290Q0ExMTAeFw0wOTA0MDgwNDU2NDdaFw0yOTA0
+MDgwNDU2NDdaMFgxCzAJBgNVBAYTAkpQMSswKQYDVQQKEyJKYXBhbiBDZXJ0aWZp
+Y2F0aW9uIFNlcnZpY2VzLCBJbmMuMRwwGgYDVQQDExNTZWN1cmVTaWduIFJvb3RD
+QTExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA/XeqpRyQBTvLTJsz
+i1oURaTnkBbR31fSIRCkF/3frNYfp+TbfPfs37gD2pRY/V1yfIw/XwFndBWW4wI8
+h9uuywGOwvNmxoVF9ALGOrVisq/6nL+k5tSAMJjzDbaTj6nU2DbysPyKyiyhFTOV
+MdrAG/LuYpmGYz+/3ZMqg6h2uRMft85OQoWPIucuGvKVCbIFtUROd6EgvanyTgp9
+UK31BQ1FT0Zx/Sg+U/sE2C3XZR1KG/rPO7AxmjVuyIsG0wCR8pQIZUyxNAYAeoni
+8McDWc/V1uinMrPmmECGxc0nEovMe863ETxiYAcjPitAbpSACW22s293bzUIUPsC
+h8U+iQIDAQABo0IwQDAdBgNVHQ4EFgQUW/hNT7KlhtQ60vFjmqC+CfZXt94wDgYD
+VR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEB
+AKChOBZmLqdWHyGcBvod7bkixTgm2E5P7KN/ed5GIaGHd48HCJqypMWvDzKYC3xm
+KbabfSVSSUOrTC4rbnpwrxYO4wJs+0LmGJ1F2FXI6Dvd5+H0LgscNFxsWEr7jIhQ
+X5Ucv+2rIrVls4W6ng+4reV6G4pQOh29Dbx7VFALuUKvVaAYga1lme++5Jy/xIWr
+QbJUb9wlze144o4MjQlJ3WN7WmmWAiGovVJZ6X01y8hSyn+B/tlr0/cR7SXf+Of5
+pPpyl4RTDaXQMhhRdlkUbA/r7F+AjHVDg8OFmP9Mni0N5HeDk061lgeLKBObjBmN
+QSdJQO7e5iNEOdyhIta6A/I=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/c7e2a638.0 b/luni/src/main/files/cacerts/c7e2a638.0
new file mode 100644
index 0000000..e1f961b
--- /dev/null
+++ b/luni/src/main/files/cacerts/c7e2a638.0
@@ -0,0 +1,82 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 15:ac:6e:94:19:b2:79:4b:41:f6:27:a9:c3:18:0f:1f
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=US, O=GeoTrust Inc., OU=(c) 2008 GeoTrust Inc. - For authorized use only, CN=GeoTrust Primary Certification Authority - G3
+ Validity
+ Not Before: Apr 2 00:00:00 2008 GMT
+ Not After : Dec 1 23:59:59 2037 GMT
+ Subject: C=US, O=GeoTrust Inc., OU=(c) 2008 GeoTrust Inc. - For authorized use only, CN=GeoTrust Primary Certification Authority - G3
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:dc:e2:5e:62:58:1d:33:57:39:32:33:fa:eb:cb:
+ 87:8c:a7:d4:4a:dd:06:88:ea:64:8e:31:98:a5:38:
+ 90:1e:98:cf:2e:63:2b:f0:46:bc:44:b2:89:a1:c0:
+ 28:0c:49:70:21:95:9f:64:c0:a6:93:12:02:65:26:
+ 86:c6:a5:89:f0:fa:d7:84:a0:70:af:4f:1a:97:3f:
+ 06:44:d5:c9:eb:72:10:7d:e4:31:28:fb:1c:61:e6:
+ 28:07:44:73:92:22:69:a7:03:88:6c:9d:63:c8:52:
+ da:98:27:e7:08:4c:70:3e:b4:c9:12:c1:c5:67:83:
+ 5d:33:f3:03:11:ec:6a:d0:53:e2:d1:ba:36:60:94:
+ 80:bb:61:63:6c:5b:17:7e:df:40:94:1e:ab:0d:c2:
+ 21:28:70:88:ff:d6:26:6c:6c:60:04:25:4e:55:7e:
+ 7d:ef:bf:94:48:de:b7:1d:dd:70:8d:05:5f:88:a5:
+ 9b:f2:c2:ee:ea:d1:40:41:6d:62:38:1d:56:06:c5:
+ 03:47:51:20:19:fc:7b:10:0b:0e:62:ae:76:55:bf:
+ 5f:77:be:3e:49:01:53:3d:98:25:03:76:24:5a:1d:
+ b4:db:89:ea:79:e5:b6:b3:3b:3f:ba:4c:28:41:7f:
+ 06:ac:6a:8e:c1:d0:f6:05:1d:7d:e6:42:86:e3:a5:
+ d5:47
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ C4:79:CA:8E:A1:4E:03:1D:1C:DC:6B:DB:31:5B:94:3E:3F:30:7F:2D
+ Signature Algorithm: sha256WithRSAEncryption
+ 2d:c5:13:cf:56:80:7b:7a:78:bd:9f:ae:2c:99:e7:ef:da:df:
+ 94:5e:09:69:a7:e7:6e:68:8c:bd:72:be:47:a9:0e:97:12:b8:
+ 4a:f1:64:d3:39:df:25:34:d4:c1:cd:4e:81:f0:0f:04:c4:24:
+ b3:34:96:c6:a6:aa:30:df:68:61:73:d7:f9:8e:85:89:ef:0e:
+ 5e:95:28:4a:2a:27:8f:10:8e:2e:7c:86:c4:02:9e:da:0c:77:
+ 65:0e:44:0d:92:fd:fd:b3:16:36:fa:11:0d:1d:8c:0e:07:89:
+ 6a:29:56:f7:72:f4:dd:15:9c:77:35:66:57:ab:13:53:d8:8e:
+ c1:40:c5:d7:13:16:5a:72:c7:b7:69:01:c4:7a:b1:83:01:68:
+ 7d:8d:41:a1:94:18:c1:25:5c:fc:f0:fe:83:02:87:7c:0d:0d:
+ cf:2e:08:5c:4a:40:0d:3e:ec:81:61:e6:24:db:ca:e0:0e:2d:
+ 07:b2:3e:56:dc:8d:f5:41:85:07:48:9b:0c:0b:cb:49:3f:7d:
+ ec:b7:fd:cb:8d:67:89:1a:ab:ed:bb:1e:a3:00:08:08:17:2a:
+ 82:5c:31:5d:46:8a:2d:0f:86:9b:74:d9:45:fb:d4:40:b1:7a:
+ aa:68:2d:86:b2:99:22:e1:c1:2b:c7:9c:f8:f3:5f:a8:82:12:
+ eb:19:11:2d
+SHA1 Fingerprint=03:9E:ED:B8:0B:E7:A0:3C:69:53:89:3B:20:D2:D9:32:3A:4C:2A:FD
+-----BEGIN CERTIFICATE-----
+MIID/jCCAuagAwIBAgIQFaxulBmyeUtB9iepwxgPHzANBgkqhkiG9w0BAQsFADCB
+mDELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUdlb1RydXN0IEluYy4xOTA3BgNVBAsT
+MChjKSAyMDA4IEdlb1RydXN0IEluYy4gLSBGb3IgYXV0aG9yaXplZCB1c2Ugb25s
+eTE2MDQGA1UEAxMtR2VvVHJ1c3QgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhv
+cml0eSAtIEczMB4XDTA4MDQwMjAwMDAwMFoXDTM3MTIwMTIzNTk1OVowgZgxCzAJ
+BgNVBAYTAlVTMRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMTkwNwYDVQQLEzAoYykg
+MjAwOCBHZW9UcnVzdCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxNjA0
+BgNVBAMTLUdlb1RydXN0IFByaW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkg
+LSBHMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANziXmJYHTNXOTIz
++uvLh4yn1ErdBojqZI4xmKU4kB6Yzy5jK/BGvESyiaHAKAxJcCGVn2TAppMSAmUm
+hsalifD614SgcK9PGpc/BkTVyetyEH3kMSj7HGHmKAdEc5IiaacDiGydY8hS2pgn
+5whMcD60yRLBxWeDXTPzAxHsatBT4tG6NmCUgLthY2xbF37fQJQeqw3CIShwiP/W
+JmxsYAQlTlV+fe+/lEjetx3dcI0FX4ilm/LC7urRQEFtYjgdVgbFA0dRIBn8exAL
+DmKudlW/X3e+PkkBUz2YJQN2JFodtNuJ6nnltrM7P7pMKEF/BqxqjsHQ9gUdfeZC
+huOl1UcCAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYw
+HQYDVR0OBBYEFMR5yo6hTgMdHNxr2zFblD4/MH8tMA0GCSqGSIb3DQEBCwUAA4IB
+AQAtxRPPVoB7eni9n64smefv2t+UXglpp+duaIy9cr5HqQ6XErhK8WTTOd8lNNTB
+zU6B8A8ExCSzNJbGpqow32hhc9f5joWJ7w5elShKKiePEI4ufIbEAp7aDHdlDkQN
+kv39sxY2+hENHYwOB4lqKVb3cvTdFZx3NWZXqxNT2I7BQMXXExZacse3aQHEerGD
+AWh9jUGhlBjBJVz88P6DAod8DQ3PLghcSkANPuyBYeYk28rgDi0Hsj5W3I31QYUH
+SJsMC8tJP33st/3LjWeJGqvtux6jAAgIFyqCXDFdRootD4abdNlF+9RAsXqqaC2G
+spki4cErx5z481+oghLrGREt
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/d16a5865.0 b/luni/src/main/files/cacerts/d16a5865.0
new file mode 100644
index 0000000..8811ddf
--- /dev/null
+++ b/luni/src/main/files/cacerts/d16a5865.0
@@ -0,0 +1,130 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 53:ec:3b:ee:fb:b2:48:5f
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=ES, CN=Autoridad de Certificacion Firmaprofesional CIF A62634068
+ Validity
+ Not Before: May 20 08:38:15 2009 GMT
+ Not After : Dec 31 08:38:15 2030 GMT
+ Subject: C=ES, CN=Autoridad de Certificacion Firmaprofesional CIF A62634068
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:ca:96:6b:8e:ea:f8:fb:f1:a2:35:e0:7f:4c:da:
+ e0:c3:52:d7:7d:b6:10:c8:02:5e:b3:43:2a:c4:4f:
+ 6a:b2:ca:1c:5d:28:9a:78:11:1a:69:59:57:af:b5:
+ 20:42:e4:8b:0f:e6:df:5b:a6:03:92:2f:f5:11:e4:
+ 62:d7:32:71:38:d9:04:0c:71:ab:3d:51:7e:0f:07:
+ df:63:05:5c:e9:bf:94:6f:c1:29:82:c0:b4:da:51:
+ b0:c1:3c:bb:ad:37:4a:5c:ca:f1:4b:36:0e:24:ab:
+ bf:c3:84:77:fd:a8:50:f4:b1:e7:c6:2f:d2:2d:59:
+ 8d:7a:0a:4e:96:69:52:02:aa:36:98:ec:fc:fa:14:
+ 83:0c:37:1f:c9:92:37:7f:d7:81:2d:e5:c4:b9:e0:
+ 3e:34:fe:67:f4:3e:66:d1:d3:f4:40:cf:5e:62:34:
+ 0f:70:06:3e:20:18:5a:ce:f7:72:1b:25:6c:93:74:
+ 14:93:a3:73:b1:0e:aa:87:10:23:59:5f:20:05:19:
+ 47:ed:68:8e:92:12:ca:5d:fc:d6:2b:b2:92:3c:20:
+ cf:e1:5f:af:20:be:a0:76:7f:76:e5:ec:1a:86:61:
+ 33:3e:e7:7b:b4:3f:a0:0f:8e:a2:b9:6a:6f:b9:87:
+ 26:6f:41:6c:88:a6:50:fd:6a:63:0b:f5:93:16:1b:
+ 19:8f:b2:ed:9b:9b:c9:90:f5:01:0c:df:19:3d:0f:
+ 3e:38:23:c9:2f:8f:0c:d1:02:fe:1b:55:d6:4e:d0:
+ 8d:3c:af:4f:a4:f3:fe:af:2a:d3:05:9d:79:08:a1:
+ cb:57:31:b4:9c:c8:90:b2:67:f4:18:16:93:3a:fc:
+ 47:d8:d1:78:96:31:1f:ba:2b:0c:5f:5d:99:ad:63:
+ 89:5a:24:20:76:d8:df:fd:ab:4e:a6:22:aa:9d:5e:
+ e6:27:8a:7d:68:29:a3:e7:8a:b8:da:11:bb:17:2d:
+ 99:9d:13:24:46:f7:c5:e2:d8:9f:8e:7f:c7:8f:74:
+ 6d:5a:b2:e8:72:f5:ac:ee:24:10:ad:2f:14:da:ff:
+ 2d:9a:46:71:47:be:42:df:bb:01:db:f4:7f:d3:28:
+ 8f:31:59:5b:d3:c9:02:a6:b4:52:ca:6e:97:fb:43:
+ c5:08:26:6f:8a:f4:bb:fd:9f:28:aa:0d:d5:45:f3:
+ 13:3a:1d:d8:c0:78:8f:41:67:3c:1e:94:64:ae:7b:
+ 0b:c5:e8:d9:01:88:39:1a:97:86:64:41:d5:3b:87:
+ 0c:6e:fa:0f:c6:bd:48:14:bf:39:4d:d4:9e:41:b6:
+ 8f:96:1d:63:96:93:d9:95:06:78:31:68:9e:37:06:
+ 3b:80:89:45:61:39:23:c7:1b:44:a3:15:e5:1c:f8:
+ 92:30:bb
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE, pathlen:1
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ 65:CD:EB:AB:35:1E:00:3E:7E:D5:74:C0:1C:B4:73:47:0E:1A:64:2F
+ X509v3 Certificate Policies:
+ Policy: X509v3 Any Policy
+ CPS: http://www.firmaprofesional.com/cps
+ User Notice:
+ Explicit Text:
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 17:7d:a0:f9:b4:dd:c5:c5:eb:ad:4b:24:b5:a1:02:ab:dd:a5:
+ 88:4a:b2:0f:55:4b:2b:57:8c:3b:e5:31:dd:fe:c4:32:f1:e7:
+ 5b:64:96:36:32:18:ec:a5:32:77:d7:e3:44:b6:c0:11:2a:80:
+ b9:3d:6a:6e:7c:9b:d3:ad:fc:c3:d6:a3:e6:64:29:7c:d1:e1:
+ 38:1e:82:2b:ff:27:65:af:fb:16:15:c4:2e:71:84:e5:b5:ff:
+ fa:a4:47:bd:64:32:bb:f6:25:84:a2:27:42:f5:20:b0:c2:13:
+ 10:11:cd:10:15:ba:42:90:2a:d2:44:e1:96:26:eb:31:48:12:
+ fd:2a:da:c9:06:cf:74:1e:a9:4b:d5:87:28:f9:79:34:92:3e:
+ 2e:44:e8:f6:8f:4f:8f:35:3f:25:b3:39:dc:63:2a:90:6b:20:
+ 5f:c4:52:12:4e:97:2c:2a:ac:9d:97:de:48:f2:a3:66:db:c2:
+ d2:83:95:a6:66:a7:9e:25:0f:e9:0b:33:91:65:0a:5a:c3:d9:
+ 54:12:dd:af:c3:4e:0e:1f:26:5e:0d:dc:b3:8d:ec:d5:81:70:
+ de:d2:4f:24:05:f3:6c:4e:f5:4c:49:66:8d:d1:ff:d2:0b:25:
+ 41:48:fe:51:84:c6:42:af:80:04:cf:d0:7e:64:49:e4:f2:df:
+ a2:ec:b1:4c:c0:2a:1d:e7:b4:b1:65:a2:c4:bc:f1:98:f4:aa:
+ 70:07:63:b4:b8:da:3b:4c:fa:40:22:30:5b:11:a6:f0:05:0e:
+ c6:02:03:48:ab:86:9b:85:dd:db:dd:ea:a2:76:80:73:7d:f5:
+ 9c:04:c4:45:8d:e7:b9:1c:8b:9e:ea:d7:75:d1:72:b1:de:75:
+ 44:e7:42:7d:e2:57:6b:7d:dc:99:bc:3d:83:28:ea:80:93:8d:
+ c5:4c:65:c1:70:81:b8:38:fc:43:31:b2:f6:03:34:47:b2:ac:
+ fb:22:06:cb:1e:dd:17:47:1c:5f:66:b9:d3:1a:a2:da:11:b1:
+ a4:bc:23:c9:e4:be:87:ff:b9:94:b6:f8:5d:20:4a:d4:5f:e7:
+ bd:68:7b:65:f2:15:1e:d2:3a:a9:2d:e9:d8:6b:24:ac:97:58:
+ 44:47:ad:59:18:f1:21:65:70:de:ce:34:60:a8:40:f1:f3:3c:
+ a4:c3:28:23:8c:fe:27:33:43:40:a0:17:3c:eb:ea:3b:b0:72:
+ a6:a3:b9:4a:4b:5e:16:48:f4:b2:bc:c8:8c:92:c5:9d:9f:ac:
+ 72:36:bc:34:80:34:6b:a9:8b:92:c0:b8:17:ed:ec:76:53:f5:
+ 24:01:8c:b3:22:e8:4b:7c:55:c6:9d:fa:a3:14:bb:65:85:6e:
+ 6e:4f:12:7e:0a:3c:9d:95
+SHA1 Fingerprint=AE:C5:FB:3F:C8:E1:BF:C4:E5:4F:03:07:5A:9A:E8:00:B7:F7:B6:FA
+-----BEGIN CERTIFICATE-----
+MIIGFDCCA/ygAwIBAgIIU+w77vuySF8wDQYJKoZIhvcNAQEFBQAwUTELMAkGA1UE
+BhMCRVMxQjBABgNVBAMMOUF1dG9yaWRhZCBkZSBDZXJ0aWZpY2FjaW9uIEZpcm1h
+cHJvZmVzaW9uYWwgQ0lGIEE2MjYzNDA2ODAeFw0wOTA1MjAwODM4MTVaFw0zMDEy
+MzEwODM4MTVaMFExCzAJBgNVBAYTAkVTMUIwQAYDVQQDDDlBdXRvcmlkYWQgZGUg
+Q2VydGlmaWNhY2lvbiBGaXJtYXByb2Zlc2lvbmFsIENJRiBBNjI2MzQwNjgwggIi
+MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDKlmuO6vj78aI14H9M2uDDUtd9
+thDIAl6zQyrET2qyyhxdKJp4ERppWVevtSBC5IsP5t9bpgOSL/UR5GLXMnE42QQM
+cas9UX4PB99jBVzpv5RvwSmCwLTaUbDBPLutN0pcyvFLNg4kq7/DhHf9qFD0sefG
+L9ItWY16Ck6WaVICqjaY7Pz6FIMMNx/Jkjd/14Et5cS54D40/mf0PmbR0/RAz15i
+NA9wBj4gGFrO93IbJWyTdBSTo3OxDqqHECNZXyAFGUftaI6SEspd/NYrspI8IM/h
+X68gvqB2f3bl7BqGYTM+53u0P6APjqK5am+5hyZvQWyIplD9amML9ZMWGxmPsu2b
+m8mQ9QEM3xk9Dz44I8kvjwzRAv4bVdZO0I08r0+k8/6vKtMFnXkIoctXMbScyJCy
+Z/QYFpM6/EfY0XiWMR+6KwxfXZmtY4laJCB22N/9q06mIqqdXuYnin1oKaPnirja
+EbsXLZmdEyRG98Xi2J+Of8ePdG1asuhy9azuJBCtLxTa/y2aRnFHvkLfuwHb9H/T
+KI8xWVvTyQKmtFLKbpf7Q8UIJm+K9Lv9nyiqDdVF8xM6HdjAeI9BZzwelGSuewvF
+6NkBiDkal4ZkQdU7hwxu+g/GvUgUvzlN1J5Bto+WHWOWk9mVBngxaJ43BjuAiUVh
+OSPHG0SjFeUc+JIwuwIDAQABo4HvMIHsMBIGA1UdEwEB/wQIMAYBAf8CAQEwDgYD
+VR0PAQH/BAQDAgEGMB0GA1UdDgQWBBRlzeurNR4APn7VdMActHNHDhpkLzCBpgYD
+VR0gBIGeMIGbMIGYBgRVHSAAMIGPMC8GCCsGAQUFBwIBFiNodHRwOi8vd3d3LmZp
+cm1hcHJvZmVzaW9uYWwuY29tL2NwczBcBggrBgEFBQcCAjBQHk4AUABhAHMAZQBv
+ACAAZABlACAAbABhACAAQgBvAG4AYQBuAG8AdgBhACAANAA3ACAAQgBhAHIAYwBl
+AGwAbwBuAGEAIAAwADgAMAAxADcwDQYJKoZIhvcNAQEFBQADggIBABd9oPm03cXF
+661LJLWhAqvdpYhKsg9VSytXjDvlMd3+xDLx51tkljYyGOylMnfX40S2wBEqgLk9
+am58m9Ot/MPWo+ZkKXzR4Tgegiv/J2Wv+xYVxC5xhOW1//qkR71kMrv2JYSiJ0L1
+ILDCExARzRAVukKQKtJE4ZYm6zFIEv0q2skGz3QeqUvVhyj5eTSSPi5E6PaPT481
+PyWzOdxjKpBrIF/EUhJOlywqrJ2X3kjyo2bbwtKDlaZmp54lD+kLM5FlClrD2VQS
+3a/DTg4fJl4N3LON7NWBcN7STyQF82xO9UxJZo3R/9ILJUFI/lGExkKvgATP0H5k
+SeTy36LssUzAKh3ntLFlosS88Zj0qnAHY7S42jtM+kAiMFsRpvAFDsYCA0irhpuF
+3dvd6qJ2gHN99ZwExEWN57kci57q13XRcrHedUTnQn3iV2t93Jm8PYMo6oCTjcVM
+ZcFwgbg4/EMxsvYDNEeyrPsiBsse3RdHHF9mudMaotoRsaS8I8nkvof/uZS2+F0g
+StRf571oe2XyFR7SOqkt6dhrJKyXWERHrVkY8SFlcN7ONGCoQPHzPKTDKCOM/icz
+Q0CgFzzr6juwcqajuUpLXhZI9LK8yIySxZ2frHI2vDSANGupi5LAuBft7HZT9SQB
+jLMi6Et8Vcad+qMUu2WFbm5PEn4KPJ2V
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/d64f06f3.0 b/luni/src/main/files/cacerts/d64f06f3.0
new file mode 100644
index 0000000..ba28a2c
--- /dev/null
+++ b/luni/src/main/files/cacerts/d64f06f3.0
@@ -0,0 +1,90 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 1 (0x1)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=SK, L=Bratislava, O=Disig a.s., CN=CA Disig
+ Validity
+ Not Before: Mar 22 01:39:34 2006 GMT
+ Not After : Mar 22 01:39:34 2016 GMT
+ Subject: C=SK, L=Bratislava, O=Disig a.s., CN=CA Disig
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:92:f6:31:c1:7d:88:fd:99:01:a9:d8:7b:f2:71:
+ 75:f1:31:c6:f3:75:66:fa:51:28:46:84:97:78:34:
+ bc:6c:fc:bc:45:59:88:26:18:4a:c4:37:1f:a1:4a:
+ 44:bd:e3:71:04:f5:44:17:e2:3f:fc:48:58:6f:5c:
+ 9e:7a:09:ba:51:37:22:23:66:43:21:b0:3c:64:a2:
+ f8:6a:15:0e:3f:eb:51:e1:54:a9:dd:06:99:d7:9a:
+ 3c:54:8b:39:03:3f:0f:c5:ce:c6:eb:83:72:02:a8:
+ 1f:71:f3:2d:f8:75:08:db:62:4c:e8:fa:ce:f9:e7:
+ 6a:1f:b6:6b:35:82:ba:e2:8f:16:92:7d:05:0c:6c:
+ 46:03:5d:c0:ed:69:bf:3a:c1:8a:a0:e8:8e:d9:b9:
+ 45:28:87:08:ec:b4:ca:15:be:82:dd:b5:44:8b:2d:
+ ad:86:0c:68:62:6d:85:56:f2:ac:14:63:3a:c6:d1:
+ 99:ac:34:78:56:4b:cf:b6:ad:3f:8c:8a:d7:04:e5:
+ e3:78:4c:f5:86:aa:f5:8f:fa:3d:6c:71:a3:2d:ca:
+ 67:eb:68:7b:6e:33:a9:0c:82:28:a8:4c:6a:21:40:
+ 15:20:0c:26:5b:83:c2:a9:16:15:c0:24:82:5d:2b:
+ 16:ad:ca:63:f6:74:00:b0:df:43:c4:10:60:56:67:
+ 63:45
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Subject Key Identifier:
+ 8D:B2:49:68:9D:72:08:25:B9:C0:27:F5:50:93:56:48:46:71:F9:8F
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Alternative Name:
+ email:caoperator@disig.sk, URI:http://www.disig.sk/ca
+ X509v3 CRL Distribution Points:
+ URI:http://www.disig.sk/ca/crl/ca_disig.crl
+ URI:http://ca.disig.sk/ca/crl/ca_disig.crl
+
+ X509v3 Certificate Policies:
+ Policy: 1.3.158.35975946.0.0.0.1.1.1
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 5d:34:74:61:4c:af:3b:d8:ff:9f:6d:58:36:1c:3d:0b:81:0d:
+ 12:2b:46:10:80:fd:e7:3c:27:d0:7a:c8:a9:b6:7e:74:30:33:
+ a3:3a:8a:7b:74:c0:79:79:42:93:6d:ff:b1:29:14:82:ab:21:
+ 8c:2f:17:f9:3f:26:2f:f5:59:c6:ef:80:06:b7:9a:49:29:ec:
+ ce:7e:71:3c:6a:10:41:c0:f6:d3:9a:b2:7c:5a:91:9c:c0:ac:
+ 5b:c8:4d:5e:f7:e1:53:ff:43:77:fc:9e:4b:67:6c:d7:f3:83:
+ d1:a0:e0:7f:25:df:b8:98:0b:9a:32:38:6c:30:a0:f3:ff:08:
+ 15:33:f7:50:4a:7b:3e:a3:3e:20:a9:dc:2f:56:80:0a:ed:41:
+ 50:b0:c9:f4:ec:b2:e3:26:44:00:0e:6f:9e:06:bc:22:96:53:
+ 70:65:c4:50:0a:46:6b:a4:2f:27:81:12:27:13:5f:10:a1:76:
+ ce:8a:7b:37:ea:c3:39:61:03:95:98:3a:e7:6c:88:25:08:fc:
+ 79:68:0d:87:7d:62:f8:b4:5f:fb:c5:d8:4c:bd:58:bc:3f:43:
+ 5b:d4:1e:01:4d:3c:63:be:23:ef:8c:cd:5a:50:b8:68:54:f9:
+ 0a:99:33:11:00:e1:9e:c2:46:77:82:f5:59:06:8c:21:4c:87:
+ 09:cd:e5:a8
+SHA1 Fingerprint=2A:C8:D5:8B:57:CE:BF:2F:49:AF:F2:FC:76:8F:51:14:62:90:7A:41
+-----BEGIN CERTIFICATE-----
+MIIEDzCCAvegAwIBAgIBATANBgkqhkiG9w0BAQUFADBKMQswCQYDVQQGEwJTSzET
+MBEGA1UEBxMKQnJhdGlzbGF2YTETMBEGA1UEChMKRGlzaWcgYS5zLjERMA8GA1UE
+AxMIQ0EgRGlzaWcwHhcNMDYwMzIyMDEzOTM0WhcNMTYwMzIyMDEzOTM0WjBKMQsw
+CQYDVQQGEwJTSzETMBEGA1UEBxMKQnJhdGlzbGF2YTETMBEGA1UEChMKRGlzaWcg
+YS5zLjERMA8GA1UEAxMIQ0EgRGlzaWcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
+ggEKAoIBAQCS9jHBfYj9mQGp2HvycXXxMcbzdWb6UShGhJd4NLxs/LxFWYgmGErE
+Nx+hSkS943EE9UQX4j/8SFhvXJ56CbpRNyIjZkMhsDxkovhqFQ4/61HhVKndBpnX
+mjxUizkDPw/Fzsbrg3ICqB9x8y34dQjbYkzo+s7552oftms1grrijxaSfQUMbEYD
+XcDtab86wYqg6I7ZuUUohwjstMoVvoLdtUSLLa2GDGhibYVW8qwUYzrG0ZmsNHhW
+S8+2rT+MitcE5eN4TPWGqvWP+j1scaMtymfraHtuM6kMgiioTGohQBUgDCZbg8Kp
+FhXAJIJdKxatymP2dACw30PEEGBWZ2NFAgMBAAGjgf8wgfwwDwYDVR0TAQH/BAUw
+AwEB/zAdBgNVHQ4EFgQUjbJJaJ1yCCW5wCf1UJNWSEZx+Y8wDgYDVR0PAQH/BAQD
+AgEGMDYGA1UdEQQvMC2BE2Nhb3BlcmF0b3JAZGlzaWcuc2uGFmh0dHA6Ly93d3cu
+ZGlzaWcuc2svY2EwZgYDVR0fBF8wXTAtoCugKYYnaHR0cDovL3d3dy5kaXNpZy5z
+ay9jYS9jcmwvY2FfZGlzaWcuY3JsMCygKqAohiZodHRwOi8vY2EuZGlzaWcuc2sv
+Y2EvY3JsL2NhX2Rpc2lnLmNybDAaBgNVHSAEEzARMA8GDSuBHpGT5goAAAABAQEw
+DQYJKoZIhvcNAQEFBQADggEBAF00dGFMrzvY/59tWDYcPQuBDRIrRhCA/ec8J9B6
+yKm2fnQwM6M6int0wHl5QpNt/7EpFIKrIYwvF/k/Ji/1WcbvgAa3mkkp7M5+cTxq
+EEHA9tOasnxakZzArFvITV734VP/Q3f8nktnbNfzg9Gg4H8l37iYC5oyOGwwoPP/
+CBUz91BKez6jPiCp3C9WgArtQVCwyfTssuMmRAAOb54GvCKWU3BlxFAKRmukLyeB
+EicTXxChds6KezfqwzlhA5WYOudsiCUI/HloDYd9Yvi0X/vF2Ey9WLw/Q1vUHgFN
+PGO+I++MzVpQuGhU+QqZMxEA4Z7CRneC9VkGjCFMhwnN5ag=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/e8651083.0 b/luni/src/main/files/cacerts/e8651083.0
new file mode 100644
index 0000000..98d6b34
--- /dev/null
+++ b/luni/src/main/files/cacerts/e8651083.0
@@ -0,0 +1,87 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ c2:7e:43:04:4e:47:3f:19
+ Signature Algorithm: sha256WithRSAEncryption
+ Issuer: C=HU, L=Budapest, O=Microsec Ltd., CN=Microsec e-Szigno Root CA 2009/emailAddress=info@e-szigno.hu
+ Validity
+ Not Before: Jun 16 11:30:18 2009 GMT
+ Not After : Dec 30 11:30:18 2029 GMT
+ Subject: C=HU, L=Budapest, O=Microsec Ltd., CN=Microsec e-Szigno Root CA 2009/emailAddress=info@e-szigno.hu
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:e9:f8:8f:f3:63:ad:da:86:d8:a7:e0:42:fb:cf:
+ 91:de:a6:26:f8:99:a5:63:70:ad:9b:ae:ca:33:40:
+ 7d:6d:96:6e:a1:0e:44:ee:e1:13:9d:94:42:52:9a:
+ bd:75:85:74:2c:a8:0e:1d:93:b6:18:b7:8c:2c:a8:
+ cf:fb:5c:71:b9:da:ec:fe:e8:7e:8f:e4:2f:1d:b2:
+ a8:75:87:d8:b7:a1:e5:3b:cf:99:4a:46:d0:83:19:
+ 7d:c0:a1:12:1c:95:6d:4a:f4:d8:c7:a5:4d:33:2e:
+ 85:39:40:75:7e:14:7c:80:12:98:50:c7:41:67:b8:
+ a0:80:61:54:a6:6c:4e:1f:e0:9d:0e:07:e9:c9:ba:
+ 33:e7:fe:c0:55:28:2c:02:80:a7:19:f5:9e:dc:55:
+ 53:03:97:7b:07:48:ff:99:fb:37:8a:24:c4:59:cc:
+ 50:10:63:8e:aa:a9:1a:b0:84:1a:86:f9:5f:bb:b1:
+ 50:6e:a4:d1:0a:cc:d5:71:7e:1f:a7:1b:7c:f5:53:
+ 6e:22:5f:cb:2b:e6:d4:7c:5d:ae:d6:c2:c6:4c:e5:
+ 05:01:d9:ed:57:fc:c1:23:79:fc:fa:c8:24:83:95:
+ f3:b5:6a:51:01:d0:77:d6:e9:12:a1:f9:1a:83:fb:
+ 82:1b:b9:b0:97:f4:76:06:33:43:49:a0:ff:0b:b5:
+ fa:b5
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ CB:0F:C6:DF:42:43:CC:3D:CB:B5:48:23:A1:1A:7A:A6:2A:BB:34:68
+ X509v3 Authority Key Identifier:
+ keyid:CB:0F:C6:DF:42:43:CC:3D:CB:B5:48:23:A1:1A:7A:A6:2A:BB:34:68
+
+ X509v3 Subject Alternative Name:
+ email:info@e-szigno.hu
+ Signature Algorithm: sha256WithRSAEncryption
+ c9:d1:0e:5e:2e:d5:cc:b3:7c:3e:cb:fc:3d:ff:0d:28:95:93:
+ 04:c8:bf:da:cd:79:b8:43:90:f0:a4:be:ef:f2:ef:21:98:bc:
+ d4:d4:5d:06:f6:ee:42:ec:30:6c:a0:aa:a9:ca:f1:af:8a:fa:
+ 3f:0b:73:6a:3e:ea:2e:40:7e:1f:ae:54:61:79:eb:2e:08:37:
+ d7:23:f3:8c:9f:be:1d:b1:e1:a4:75:db:a0:e2:54:14:b1:ba:
+ 1c:29:a4:18:f6:12:ba:a2:14:14:e3:31:35:c8:40:ff:b7:e0:
+ 05:76:57:c1:1c:59:f2:f8:bf:e4:ed:25:62:5c:84:f0:7e:7e:
+ 1f:b3:be:f9:b7:21:11:cc:03:01:56:70:a7:10:92:1e:1b:34:
+ 81:1e:ad:9c:1a:c3:04:3c:ed:02:61:d6:1e:06:f3:5f:3a:87:
+ f2:2b:f1:45:87:e5:3d:ac:d1:c7:57:84:bd:6b:ae:dc:d8:f9:
+ b6:1b:62:70:0b:3d:36:c9:42:f2:32:d7:7a:61:e6:d2:db:3d:
+ cf:c8:a9:c9:9b:dc:db:58:44:d7:6f:38:af:7f:78:d3:a3:ad:
+ 1a:75:ba:1c:c1:36:7c:8f:1e:6d:1c:c3:75:46:ae:35:05:a6:
+ f6:5c:3d:21:ee:56:f0:c9:82:22:2d:7a:54:ab:70:c3:7d:22:
+ 65:82:70:96
+SHA1 Fingerprint=89:DF:74:FE:5C:F4:0F:4A:80:F9:E3:37:7D:54:DA:91:E1:01:31:8E
+-----BEGIN CERTIFICATE-----
+MIIECjCCAvKgAwIBAgIJAMJ+QwRORz8ZMA0GCSqGSIb3DQEBCwUAMIGCMQswCQYD
+VQQGEwJIVTERMA8GA1UEBwwIQnVkYXBlc3QxFjAUBgNVBAoMDU1pY3Jvc2VjIEx0
+ZC4xJzAlBgNVBAMMHk1pY3Jvc2VjIGUtU3ppZ25vIFJvb3QgQ0EgMjAwOTEfMB0G
+CSqGSIb3DQEJARYQaW5mb0BlLXN6aWduby5odTAeFw0wOTA2MTYxMTMwMThaFw0y
+OTEyMzAxMTMwMThaMIGCMQswCQYDVQQGEwJIVTERMA8GA1UEBwwIQnVkYXBlc3Qx
+FjAUBgNVBAoMDU1pY3Jvc2VjIEx0ZC4xJzAlBgNVBAMMHk1pY3Jvc2VjIGUtU3pp
+Z25vIFJvb3QgQ0EgMjAwOTEfMB0GCSqGSIb3DQEJARYQaW5mb0BlLXN6aWduby5o
+dTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAOn4j/NjrdqG2KfgQvvP
+kd6mJviZpWNwrZuuyjNAfW2WbqEORO7hE52UQlKavXWFdCyoDh2Tthi3jCyoz/tc
+cbna7P7ofo/kLx2yqHWH2Leh5TvPmUpG0IMZfcChEhyVbUr02MelTTMuhTlAdX4U
+fIASmFDHQWe4oIBhVKZsTh/gnQ4H6cm6M+f+wFUoLAKApxn1ntxVUwOXewdI/5n7
+N4okxFnMUBBjjqqpGrCEGob5X7uxUG6k0QrM1XF+H6cbfPVTbiJfyyvm1HxdrtbC
+xkzlBQHZ7Vf8wSN5/PrIJIOV87VqUQHQd9bpEqH5GoP7ghu5sJf0dgYzQ0mg/wu1
++rUCAwEAAaOBgDB+MA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMB0G
+A1UdDgQWBBTLD8bfQkPMPcu1SCOhGnqmKrs0aDAfBgNVHSMEGDAWgBTLD8bfQkPM
+Pcu1SCOhGnqmKrs0aDAbBgNVHREEFDASgRBpbmZvQGUtc3ppZ25vLmh1MA0GCSqG
+SIb3DQEBCwUAA4IBAQDJ0Q5eLtXMs3w+y/w9/w0olZMEyL/azXm4Q5DwpL7v8u8h
+mLzU1F0G9u5C7DBsoKqpyvGvivo/C3NqPuouQH4frlRheesuCDfXI/OMn74dseGk
+ddug4lQUsbocKaQY9hK6ohQU4zE1yED/t+AFdlfBHFny+L/k7SViXITwfn4fs775
+tyERzAMBVnCnEJIeGzSBHq2cGsMEPO0CYdYeBvNfOofyK/FFh+U9rNHHV4S9a67c
+2Pm2G2JwCz02yULyMtd6YebS2z3PyKnJm9zbWETXbzivf3jTo60adbocwTZ8jx5t
+HMN1Rq41Bab2XD0h7lbwyYIiLXpUq3DDfSJlgnCW
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/ea169617.0 b/luni/src/main/files/cacerts/ea169617.0
new file mode 100644
index 0000000..2586ed4
--- /dev/null
+++ b/luni/src/main/files/cacerts/ea169617.0
@@ -0,0 +1,129 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 61:8d:c7:86:3b:01:82:05
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: CN=ACEDICOM Root, OU=PKI, O=EDICOM, C=ES
+ Validity
+ Not Before: Apr 18 16:24:22 2008 GMT
+ Not After : Apr 13 16:24:22 2028 GMT
+ Subject: CN=ACEDICOM Root, OU=PKI, O=EDICOM, C=ES
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:ff:92:95:e1:68:06:76:b4:2c:c8:58:48:ca:fd:
+ 80:54:29:55:63:24:ff:90:65:9b:10:75:7b:c3:6a:
+ db:62:02:01:f2:18:86:b5:7c:5a:38:b1:e4:58:b9:
+ fb:d3:d8:2d:9f:bd:32:37:bf:2c:15:6d:be:b5:f4:
+ 21:d2:13:91:d9:07:ad:01:05:d6:f3:bd:77:ce:5f:
+ 42:81:0a:f9:6a:e3:83:00:a8:2b:2e:55:13:63:81:
+ ca:47:1c:7b:5c:16:57:7a:1b:83:60:04:3a:3e:65:
+ c3:cd:01:de:de:a4:d6:0c:ba:8e:de:d9:04:ee:17:
+ 56:22:9b:8f:63:fd:4d:16:0b:b7:7b:77:8c:f9:25:
+ b5:d1:6d:99:12:2e:4f:1a:b8:e6:ea:04:92:ae:3d:
+ 11:b9:51:42:3d:87:b0:31:85:af:79:5a:9c:fe:e7:
+ 4e:5e:92:4f:43:fc:ab:3a:ad:a5:12:26:66:b9:e2:
+ 0c:d7:98:ce:d4:58:a5:95:40:0a:b7:44:9d:13:74:
+ 2b:c2:a5:eb:22:15:98:10:d8:8b:c5:04:9f:1d:8f:
+ 60:e5:06:1b:9b:cf:b9:79:a0:3d:a2:23:3f:42:3f:
+ 6b:fa:1c:03:7b:30:8d:ce:6c:c0:bf:e6:1b:5f:bf:
+ 67:b8:84:19:d5:15:ef:7b:cb:90:36:31:62:c9:bc:
+ 02:ab:46:5f:9b:fe:1a:68:94:34:3d:90:8e:ad:f6:
+ e4:1d:09:7f:4a:88:38:3f:be:67:fd:34:96:f5:1d:
+ bc:30:74:cb:38:ee:d5:6c:ab:d4:fc:f4:00:b7:00:
+ 5b:85:32:16:76:33:e9:d8:a3:99:9d:05:00:aa:16:
+ e6:f3:81:7d:6f:7d:aa:86:6d:ad:15:74:d3:c4:a2:
+ 71:aa:f4:14:7d:e7:32:b8:1f:bc:d5:f1:4e:bd:6f:
+ 17:02:39:d7:0e:95:42:3a:c7:00:3e:e9:26:63:11:
+ ea:0b:d1:4a:ff:18:9d:b2:d7:7b:2f:3a:d9:96:fb:
+ e8:1e:92:ae:13:55:c8:d9:27:f6:dc:48:1b:b0:24:
+ c1:85:e3:77:9d:9a:a4:f3:0c:11:1d:0d:c8:b4:14:
+ ee:b5:82:57:09:bf:20:58:7f:2f:22:23:d8:70:cb:
+ 79:6c:c9:4b:f2:a9:2a:c8:fc:87:2b:d7:1a:50:f8:
+ 27:e8:2f:43:e3:3a:bd:d8:57:71:fd:ce:a6:52:5b:
+ f9:dd:4d:ed:e5:f6:6f:89:ed:bb:93:9c:76:21:75:
+ f0:92:4c:29:f7:2f:9c:01:2e:fe:50:46:9e:64:0c:
+ 14:b3:07:5b:c5:c2:73:6c:f1:07:5c:45:24:14:35:
+ ae:83:f1:6a:4d:89:7a:fa:b3:d8:2d:66:f0:36:87:
+ f5:2b:53
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Authority Key Identifier:
+ keyid:A6:B3:E1:2B:2B:49:B6:D7:73:A1:AA:94:F5:01:E7:73:65:4C:AC:50
+
+ X509v3 Key Usage: critical
+ Digital Signature, Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ A6:B3:E1:2B:2B:49:B6:D7:73:A1:AA:94:F5:01:E7:73:65:4C:AC:50
+ X509v3 Certificate Policies:
+ Policy: X509v3 Any Policy
+ CPS: http://acedicom.edicomgroup.com/doc
+
+ Signature Algorithm: sha1WithRSAEncryption
+ ce:2c:0b:52:51:62:26:7d:0c:27:83:8f:c5:f6:da:a0:68:7b:
+ 4f:92:5e:ea:a4:73:32:11:53:44:b2:44:cb:9d:ec:0f:79:42:
+ b3:10:a6:c7:0d:9d:cb:b6:fa:3f:3a:7c:ea:bf:88:53:1b:3c:
+ f7:82:fa:05:35:33:e1:35:a8:57:c0:e7:fd:8d:4f:3f:93:32:
+ 4f:78:66:03:77:07:58:e9:95:c8:7e:3e:d0:79:00:8c:f2:1b:
+ 51:33:9b:bc:94:e9:3a:7b:6e:52:2d:32:9e:23:a4:45:fb:b6:
+ 2e:13:b0:8b:18:b1:dd:ce:d5:1d:a7:42:7f:55:be:fb:5b:bb:
+ 47:d4:fc:24:cd:04:ae:96:05:15:d6:ac:ce:30:f3:ca:0b:c5:
+ ba:e2:22:e0:a6:ad:22:e4:02:ee:74:11:7f:4c:ff:78:1d:35:
+ da:e6:02:34:eb:18:12:61:77:06:09:16:63:ea:18:ad:a2:87:
+ 1f:f2:c7:80:09:09:75:4e:10:a8:8f:3d:86:b8:75:11:c0:24:
+ 62:8a:96:7b:4a:45:e9:ec:59:c5:be:6b:83:e6:e1:e8:ac:b5:
+ 30:1e:fe:05:07:80:f9:e1:23:0d:50:8f:05:98:ff:2c:5f:e8:
+ 3b:b6:ad:cf:81:b5:21:87:ca:08:2a:23:27:30:20:2b:cf:ed:
+ 94:5b:ac:b2:7a:d2:c7:28:a1:8a:0b:9b:4d:4a:2c:6d:85:3f:
+ 09:72:3c:67:e2:d9:dc:07:ba:eb:65:7b:5a:01:63:d6:90:5b:
+ 4f:17:66:3d:7f:0b:19:a3:93:63:10:52:2a:9f:14:16:58:e2:
+ dc:a5:f4:a1:16:8b:0e:91:8b:81:ca:9b:59:fa:d8:6b:91:07:
+ 65:55:5f:52:1f:af:3a:fb:90:dd:69:a5:5b:9c:6d:0e:2c:b6:
+ fa:ce:ac:a5:7c:32:4a:67:40:dc:30:34:23:dd:d7:04:23:66:
+ f0:fc:55:80:a7:fb:66:19:82:35:67:62:70:39:5e:6f:c7:ea:
+ 90:40:44:08:1e:b8:b2:d6:db:ee:59:a7:0d:18:79:34:bc:54:
+ 18:5e:53:ca:34:51:ed:45:0a:e6:8e:c7:82:36:3e:a7:38:63:
+ a9:30:2c:17:10:60:92:9f:55:87:12:59:10:c2:0f:67:69:11:
+ cc:4e:1e:7e:4a:9a:ad:af:40:a8:75:ac:56:90:74:b8:a0:9c:
+ a5:79:6f:dc:e9:1a:c8:69:05:e9:ba:fa:03:b3:7c:e4:e0:4e:
+ c2:ce:9d:e8:b6:46:0d:6e:7e:57:3a:67:94:c2:cb:1f:9c:77:
+ 4a:67:4e:69:86:43:93:38:fb:b6:db:4f:83:91:d4:60:7e:4b:
+ 3e:2b:38:07:55:98:5e:a4
+SHA1 Fingerprint=E0:B4:32:2E:B2:F6:A5:68:B6:54:53:84:48:18:4A:50:36:87:43:84
+-----BEGIN CERTIFICATE-----
+MIIFtTCCA52gAwIBAgIIYY3HhjsBggUwDQYJKoZIhvcNAQEFBQAwRDEWMBQGA1UE
+AwwNQUNFRElDT00gUm9vdDEMMAoGA1UECwwDUEtJMQ8wDQYDVQQKDAZFRElDT00x
+CzAJBgNVBAYTAkVTMB4XDTA4MDQxODE2MjQyMloXDTI4MDQxMzE2MjQyMlowRDEW
+MBQGA1UEAwwNQUNFRElDT00gUm9vdDEMMAoGA1UECwwDUEtJMQ8wDQYDVQQKDAZF
+RElDT00xCzAJBgNVBAYTAkVTMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC
+AgEA/5KV4WgGdrQsyFhIyv2AVClVYyT/kGWbEHV7w2rbYgIB8hiGtXxaOLHkWLn7
+09gtn70yN78sFW2+tfQh0hOR2QetAQXW8713zl9CgQr5auODAKgrLlUTY4HKRxx7
+XBZXehuDYAQ6PmXDzQHe3qTWDLqO3tkE7hdWIpuPY/1NFgu3e3eM+SW10W2ZEi5P
+Grjm6gSSrj0RuVFCPYewMYWveVqc/udOXpJPQ/yrOq2lEiZmueIM15jO1FillUAK
+t0SdE3QrwqXrIhWYENiLxQSfHY9g5QYbm8+5eaA9oiM/Qj9r+hwDezCNzmzAv+Yb
+X79nuIQZ1RXve8uQNjFiybwCq0Zfm/4aaJQ0PZCOrfbkHQl/Sog4P75n/TSW9R28
+MHTLOO7VbKvU/PQAtwBbhTIWdjPp2KOZnQUAqhbm84F9b32qhm2tFXTTxKJxqvQU
+fecyuB+81fFOvW8XAjnXDpVCOscAPukmYxHqC9FK/xidstd7LzrZlvvoHpKuE1XI
+2Sf23EgbsCTBheN3nZqk8wwRHQ3ItBTutYJXCb8gWH8vIiPYcMt5bMlL8qkqyPyH
+K9caUPgn6C9D4zq92Fdx/c6mUlv53U3t5fZvie27k5x2IXXwkkwp9y+cAS7+UEae
+ZAwUswdbxcJzbPEHXEUkFDWug/FqTYl6+rPYLWbwNof1K1MCAwEAAaOBqjCBpzAP
+BgNVHRMBAf8EBTADAQH/MB8GA1UdIwQYMBaAFKaz4SsrSbbXc6GqlPUB53NlTKxQ
+MA4GA1UdDwEB/wQEAwIBhjAdBgNVHQ4EFgQUprPhKytJttdzoaqU9QHnc2VMrFAw
+RAYDVR0gBD0wOzA5BgRVHSAAMDEwLwYIKwYBBQUHAgEWI2h0dHA6Ly9hY2VkaWNv
+bS5lZGljb21ncm91cC5jb20vZG9jMA0GCSqGSIb3DQEBBQUAA4ICAQDOLAtSUWIm
+fQwng4/F9tqgaHtPkl7qpHMyEVNEskTLnewPeUKzEKbHDZ3Ltvo/Onzqv4hTGzz3
+gvoFNTPhNahXwOf9jU8/kzJPeGYDdwdY6ZXIfj7QeQCM8htRM5u8lOk6e25SLTKe
+I6RF+7YuE7CLGLHdztUdp0J/Vb77W7tH1PwkzQSulgUV1qzOMPPKC8W64iLgpq0i
+5ALudBF/TP94HTXa5gI06xgSYXcGCRZj6hitoocf8seACQl1ThCojz2GuHURwCRi
+ipZ7SkXp7FnFvmuD5uHorLUwHv4FB4D54SMNUI8FmP8sX+g7tq3PgbUhh8oIKiMn
+MCArz+2UW6yyetLHKKGKC5tNSixthT8Jcjxn4tncB7rrZXtaAWPWkFtPF2Y9fwsZ
+o5NjEFIqnxQWWOLcpfShFosOkYuByptZ+thrkQdlVV9SH686+5DdaaVbnG0OLLb6
+zqylfDJKZ0DcMDQj3dcEI2bw/FWAp/tmGYI1Z2JwOV5vx+qQQEQIHriy1tvuWacN
+GHk0vFQYXlPKNFHtRQrmjseCNj6nOGOpMCwXEGCSn1WHElkQwg9naRHMTh5+Spqt
+r0CodaxWkHS4oJyleW/c6RrIaQXpuvoDs3zk4E7Czp3otkYNbn5XOmeUwssfnHdK
+Z05phkOTOPu220+DkdRgfks+KzgHVZhepA==
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/eb375c3e.0 b/luni/src/main/files/cacerts/eb375c3e.0
new file mode 100644
index 0000000..d4c69d3
--- /dev/null
+++ b/luni/src/main/files/cacerts/eb375c3e.0
@@ -0,0 +1,77 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 2 (0x2)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=NO, O=Buypass AS-983163327, CN=Buypass Class 3 CA 1
+ Validity
+ Not Before: May 9 14:13:03 2005 GMT
+ Not After : May 9 14:13:03 2015 GMT
+ Subject: C=NO, O=Buypass AS-983163327, CN=Buypass Class 3 CA 1
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:a4:8e:d7:74:d9:29:64:de:5f:1f:87:80:91:ea:
+ 4e:39:e6:19:c6:44:0b:80:d5:0b:af:53:07:8b:12:
+ bd:e6:67:f0:02:b1:89:f6:60:8a:c4:5b:b0:42:d1:
+ c0:21:a8:cb:e1:9b:ef:64:51:b6:a7:cf:15:f5:74:
+ 80:68:04:90:a0:58:a2:e6:74:a6:53:53:55:48:63:
+ 3f:92:56:dd:24:4e:8e:f8:ba:2b:ff:f3:34:8a:9e:
+ 28:d7:34:9f:ac:2f:d6:0f:f1:a4:2f:bd:52:b2:49:
+ 85:6d:39:35:f0:44:30:93:46:24:f3:b6:e7:53:fb:
+ bc:61:af:a9:a3:14:fb:c2:17:17:84:6c:e0:7c:88:
+ f8:c9:1c:57:2c:f0:3d:7e:94:bc:25:93:84:e8:9a:
+ 00:9a:45:05:42:57:80:f4:4e:ce:d9:ae:39:f6:c8:
+ 53:10:0c:65:3a:47:7b:60:c2:d6:fa:91:c9:c6:71:
+ 6c:bd:91:87:3c:91:86:49:ab:f3:0f:a0:6c:26:76:
+ 5e:1c:ac:9b:71:e5:8d:bc:9b:21:1e:9c:d6:38:7e:
+ 24:80:15:31:82:96:b1:49:d3:62:37:5b:88:0c:0a:
+ 62:34:fe:a7:48:7e:99:b1:30:8b:90:37:95:1c:a8:
+ 1f:a5:2c:8d:f4:55:c8:db:dd:59:0a:c2:ad:78:a0:
+ f4:8b
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Subject Key Identifier:
+ 38:14:E6:C8:F0:A9:A4:03:F4:4E:3E:22:A3:5B:F2:D6:E0:AD:40:74
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ Signature Algorithm: sha1WithRSAEncryption
+ 01:67:a3:8c:c9:25:3d:13:63:5d:16:6f:ec:a1:3e:09:5c:91:
+ 15:2a:2a:d9:80:21:4f:05:dc:bb:a5:89:ab:13:33:2a:9e:38:
+ b7:8c:6f:02:72:63:c7:73:77:1e:09:06:ba:3b:28:7b:a4:47:
+ c9:61:6b:08:08:20:fc:8a:05:8a:1f:bc:ba:c6:c2:fe:cf:6e:
+ ec:13:33:71:67:2e:69:fa:a9:2c:3f:66:c0:12:59:4d:0b:54:
+ 02:92:84:bb:db:12:ef:83:70:70:78:c8:53:fa:df:c6:c6:ff:
+ dc:88:2f:07:c0:49:9d:32:57:60:d3:f2:f6:99:29:5f:e7:aa:
+ 01:cc:ac:33:a8:1c:0a:bb:91:c4:03:a0:6f:b6:34:f9:86:d3:
+ b3:76:54:98:f4:4a:81:b3:53:9d:4d:40:ec:e5:77:13:45:af:
+ 5b:aa:1f:d8:2f:4c:82:7b:fe:2a:c4:58:bb:4f:fc:9e:fd:03:
+ 65:1a:2a:0e:c3:a5:20:16:94:6b:79:a6:a2:12:b4:bb:1a:a4:
+ 23:7a:5f:f0:ae:84:24:e4:f3:2b:fb:8a:24:a3:27:98:65:da:
+ 30:75:76:fc:19:91:e8:db:eb:9b:3f:32:bf:40:97:07:26:ba:
+ cc:f3:94:85:4a:7a:27:93:cf:90:42:d4:b8:5b:16:a6:e7:cb:
+ 40:03:dd:79
+SHA1 Fingerprint=61:57:3A:11:DF:0E:D8:7E:D5:92:65:22:EA:D0:56:D7:44:B3:23:71
+-----BEGIN CERTIFICATE-----
+MIIDUzCCAjugAwIBAgIBAjANBgkqhkiG9w0BAQUFADBLMQswCQYDVQQGEwJOTzEd
+MBsGA1UECgwUQnV5cGFzcyBBUy05ODMxNjMzMjcxHTAbBgNVBAMMFEJ1eXBhc3Mg
+Q2xhc3MgMyBDQSAxMB4XDTA1MDUwOTE0MTMwM1oXDTE1MDUwOTE0MTMwM1owSzEL
+MAkGA1UEBhMCTk8xHTAbBgNVBAoMFEJ1eXBhc3MgQVMtOTgzMTYzMzI3MR0wGwYD
+VQQDDBRCdXlwYXNzIENsYXNzIDMgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEP
+ADCCAQoCggEBAKSO13TZKWTeXx+HgJHqTjnmGcZEC4DVC69TB4sSveZn8AKxifZg
+isRbsELRwCGoy+Gb72RRtqfPFfV0gGgEkKBYouZ0plNTVUhjP5JW3SROjvi6K//z
+NIqeKNc0n6wv1g/xpC+9UrJJhW05NfBEMJNGJPO251P7vGGvqaMU+8IXF4Rs4HyI
++MkcVyzwPX6UvCWThOiaAJpFBUJXgPROztmuOfbIUxAMZTpHe2DC1vqRycZxbL2R
+hzyRhkmr8w+gbCZ2Xhysm3HljbybIR6c1jh+JIAVMYKWsUnTYjdbiAwKYjT+p0h+
+mbEwi5A3lRyoH6UsjfRVyNvdWQrCrXig9IsCAwEAAaNCMEAwDwYDVR0TAQH/BAUw
+AwEB/zAdBgNVHQ4EFgQUOBTmyPCppAP0Tj4io1vy1uCtQHQwDgYDVR0PAQH/BAQD
+AgEGMA0GCSqGSIb3DQEBBQUAA4IBAQABZ6OMySU9E2NdFm/soT4JXJEVKirZgCFP
+Bdy7pYmrEzMqnji3jG8CcmPHc3ceCQa6Oyh7pEfJYWsICCD8igWKH7y6xsL+z27s
+EzNxZy5p+qksP2bAEllNC1QCkoS72xLvg3BweMhT+t/Gxv/ciC8HwEmdMldg0/L2
+mSlf56oBzKwzqBwKu5HEA6BvtjT5htOzdlSY9EqBs1OdTUDs5XcTRa9bqh/YL0yC
+e/4qxFi7T/ye/QNlGioOw6UgFpRreaaiErS7GqQjel/wroQk5PMr+4okoyeYZdow
+dXb8GZHo2+ubPzK/QJcHJrrM85SFSnonk8+QQtS4Wxam58tAA915
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/f80cc7f6.0 b/luni/src/main/files/cacerts/f80cc7f6.0
new file mode 100644
index 0000000..5f1b777
--- /dev/null
+++ b/luni/src/main/files/cacerts/f80cc7f6.0
@@ -0,0 +1,126 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number:
+ 4c:af:73:42:1c:8e:74:02
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: CN=EBG Elektronik Sertifika Hizmet Sa\xC4\x9Flay\xC4\xB1c\xC4\xB1s\xC4\xB1, O=EBG Bili\xC5\x9Fim Teknolojileri ve Hizmetleri A.\xC5\x9E., C=TR
+ Validity
+ Not Before: Aug 17 00:21:09 2006 GMT
+ Not After : Aug 14 00:31:09 2016 GMT
+ Subject: CN=EBG Elektronik Sertifika Hizmet Sa\xC4\x9Flay\xC4\xB1c\xC4\xB1s\xC4\xB1, O=EBG Bili\xC5\x9Fim Teknolojileri ve Hizmetleri A.\xC5\x9E., C=TR
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (4096 bit)
+ Modulus (4096 bit):
+ 00:ee:a0:84:61:d0:3a:6a:66:10:32:d8:31:38:7f:
+ a7:a7:e5:fd:a1:e1:fb:97:77:b8:71:96:e8:13:96:
+ 46:83:4f:b6:f2:5f:72:56:6e:13:60:a5:01:91:e2:
+ 5b:c5:cd:57:1f:77:63:51:ff:2f:3d:db:b9:3f:aa:
+ a9:35:e7:79:d0:f5:d0:24:b6:21:ea:eb:23:94:fe:
+ 29:bf:fb:89:91:0c:64:9a:05:4a:2b:cc:0c:ee:f1:
+ 3d:9b:82:69:a4:4c:f8:9a:6f:e7:22:da:10:ba:5f:
+ 92:fc:18:27:0a:a8:aa:44:fa:2e:2c:b4:fb:46:9a:
+ 08:03:83:72:ab:88:e4:6a:72:c9:e5:65:1f:6e:2a:
+ 0f:9d:b3:e8:3b:e4:0c:6e:7a:da:57:fd:d7:eb:79:
+ 8b:5e:20:06:d3:76:0b:6c:02:95:a3:96:e4:cb:76:
+ 51:d1:28:9d:a1:1a:fc:44:a2:4d:cc:7a:76:a8:0d:
+ 3d:bf:17:4f:22:88:50:fd:ae:b6:ec:90:50:4a:5b:
+ 9f:95:41:aa:ca:0f:b2:4a:fe:80:99:4e:a3:46:15:
+ ab:f8:73:42:6a:c2:66:76:b1:0a:26:15:dd:93:92:
+ ec:db:a9:5f:54:22:52:91:70:5d:13:ea:48:ec:6e:
+ 03:6c:d9:dd:6c:fc:eb:0d:03:ff:a6:83:12:9b:f1:
+ a9:93:0f:c5:26:4c:31:b2:63:99:61:72:e7:2a:64:
+ 99:d2:b8:e9:75:e2:7c:a9:a9:9a:1a:aa:c3:56:db:
+ 10:9a:3c:83:52:b6:7b:96:b7:ac:87:77:a8:b9:f2:
+ 67:0b:94:43:b3:af:3e:73:fa:42:36:b1:25:c5:0a:
+ 31:26:37:56:67:ba:a3:0b:7d:d6:f7:89:cd:67:a1:
+ b7:3a:1e:66:4f:f6:a0:55:14:25:4c:2c:33:0d:a6:
+ 41:8c:bd:04:31:6a:10:72:0a:9d:0e:2e:76:bd:5e:
+ f3:51:89:8b:a8:3f:55:73:bf:db:3a:c6:24:05:96:
+ 92:48:aa:4b:8d:2a:03:e5:57:91:10:f4:6a:28:15:
+ 6e:47:77:84:5c:51:74:9f:19:e9:e6:1e:63:16:39:
+ e3:11:15:e3:58:1a:44:bd:cb:c4:6c:66:d7:84:06:
+ df:30:f4:37:a2:43:22:79:d2:10:6c:df:bb:e6:13:
+ 11:fc:9d:84:0a:13:7b:f0:3b:d0:fc:a3:0a:d7:89:
+ ea:96:7e:8d:48:85:1e:64:5f:db:54:a2:ac:d5:7a:
+ 02:79:6b:d2:8a:f0:67:da:65:72:0d:14:70:e4:e9:
+ 8e:78:8f:32:74:7c:57:f2:d6:d6:f4:36:89:1b:f8:
+ 29:6c:8b:b9:f6:97:d1:a4:2e:aa:be:0b:19:c2:45:
+ e9:70:5d
+ Exponent: 40409 (0x9dd9)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Key Identifier:
+ E7:CE:C6:4F:FC:16:67:96:FA:4A:A3:07:C1:04:A7:CB:6A:DE:DA:47
+ X509v3 Authority Key Identifier:
+ keyid:E7:CE:C6:4F:FC:16:67:96:FA:4A:A3:07:C1:04:A7:CB:6A:DE:DA:47
+
+ Signature Algorithm: sha1WithRSAEncryption
+ 9b:98:9a:5d:be:f3:28:23:76:c6:6c:f7:7f:e6:40:9e:c0:36:
+ dc:95:0d:1d:ad:15:c5:36:d8:d5:39:ef:f2:1e:22:5e:b3:82:
+ b4:5d:bb:4c:1a:ca:92:0d:df:47:24:1e:b3:24:da:91:88:e9:
+ 83:70:dd:93:d7:e9:ba:b3:df:16:5a:3e:de:e0:c8:fb:d3:fd:
+ 6c:29:f8:15:46:a0:68:26:cc:93:52:ae:82:01:93:90:ca:77:
+ ca:4d:49:ef:e2:5a:d9:2a:bd:30:ce:4c:b2:81:b6:30:ce:59:
+ 4f:da:59:1d:6a:7a:a4:45:b0:82:26:81:86:76:f5:f5:10:00:
+ b8:ee:b3:09:e8:4f:87:02:07:ae:24:5c:f0:5f:ac:0a:30:cc:
+ 8a:40:a0:73:04:c1:fb:89:24:f6:9a:1c:5c:b7:3c:0a:67:36:
+ 05:08:31:b3:af:d8:01:68:2a:e0:78:8f:74:de:b8:51:a4:8c:
+ 6c:20:3d:a2:fb:b3:d4:09:fd:7b:c2:80:aa:93:6c:29:98:21:
+ a8:bb:16:f3:a9:12:5f:74:b5:87:98:f2:95:26:df:34:ef:8a:
+ 53:91:88:5d:1a:94:a3:3f:7c:22:f8:d7:88:ba:a6:8c:96:a8:
+ 3d:52:34:62:9f:00:1e:54:55:42:67:c6:4d:46:8f:bb:14:45:
+ 3d:0a:96:16:8e:10:a1:97:99:d5:d3:30:85:cc:de:b4:72:b7:
+ bc:8a:3c:18:29:68:fd:dc:71:07:ee:24:39:6a:fa:ed:a5:ac:
+ 38:2f:f9:1e:10:0e:06:71:1a:10:4c:fe:75:7e:ff:1e:57:39:
+ 42:ca:d7:e1:15:a1:56:55:59:1b:d1:a3:af:11:d8:4e:c3:a5:
+ 2b:ef:90:bf:c0:ec:82:13:5b:8d:d6:72:2c:93:4e:8f:6a:29:
+ df:85:3c:d3:0d:e0:a2:18:12:cc:55:2f:47:b7:a7:9b:02:fe:
+ 41:f6:88:4c:6d:da:a9:01:47:83:64:27:62:10:82:d6:12:7b:
+ 5e:03:1f:34:a9:c9:91:fe:af:5d:6d:86:27:b7:23:aa:75:18:
+ ca:20:e7:b0:0f:d7:89:0e:a6:67:22:63:f4:83:41:2b:06:4b:
+ bb:58:d5:d1:d7:b7:b9:10:63:d8:89:4a:b4:aa:dd:16:63:f5:
+ 6e:be:60:a1:f8:ed:e8:d6:90:4f:1a:c6:c5:a0:29:d3:a7:21:
+ a8:f5:5a:3c:f7:c7:49:a2:21:9a:4a:95:52:20:96:72:9a:66:
+ cb:f7:d2:86:43:7c:22:be:96:f9:bd:01:a8:47:dd:e5:3b:40:
+ f9:75:2b:9b:2b:46:64:86:8d:1e:f4:8f:fb:07:77:d0:ea:49:
+ a2:1c:8d:52:14:a6:0a:93
+SHA1 Fingerprint=8C:96:BA:EB:DD:2B:07:07:48:EE:30:32:66:A0:F3:98:6E:7C:AE:58
+-----BEGIN CERTIFICATE-----
+MIIF5zCCA8+gAwIBAgIITK9zQhyOdAIwDQYJKoZIhvcNAQEFBQAwgYAxODA2BgNV
+BAMML0VCRyBFbGVrdHJvbmlrIFNlcnRpZmlrYSBIaXptZXQgU2HEn2xhecSxY8Sx
+c8SxMTcwNQYDVQQKDC5FQkcgQmlsacWfaW0gVGVrbm9sb2ppbGVyaSB2ZSBIaXpt
+ZXRsZXJpIEEuxZ4uMQswCQYDVQQGEwJUUjAeFw0wNjA4MTcwMDIxMDlaFw0xNjA4
+MTQwMDMxMDlaMIGAMTgwNgYDVQQDDC9FQkcgRWxla3Ryb25payBTZXJ0aWZpa2Eg
+SGl6bWV0IFNhxJ9sYXnEsWPEsXPEsTE3MDUGA1UECgwuRUJHIEJpbGnFn2ltIFRl
+a25vbG9qaWxlcmkgdmUgSGl6bWV0bGVyaSBBLsWeLjELMAkGA1UEBhMCVFIwggIi
+MA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDuoIRh0DpqZhAy2DE4f6en5f2h
+4fuXd7hxlugTlkaDT7byX3JWbhNgpQGR4lvFzVcfd2NR/y8927k/qqk153nQ9dAk
+tiHq6yOU/im/+4mRDGSaBUorzAzu8T2bgmmkTPiab+ci2hC6X5L8GCcKqKpE+i4s
+tPtGmggDg3KriORqcsnlZR9uKg+ds+g75AxuetpX/dfreYteIAbTdgtsApWjluTL
+dlHRKJ2hGvxEok3MenaoDT2/F08iiFD9rrbskFBKW5+VQarKD7JK/oCZTqNGFav4
+c0JqwmZ2sQomFd2TkuzbqV9UIlKRcF0T6kjsbgNs2d1s/OsNA/+mgxKb8amTD8Um
+TDGyY5lhcucqZJnSuOl14nypqZoaqsNW2xCaPINStnuWt6yHd6i58mcLlEOzrz5z
++kI2sSXFCjEmN1ZnuqMLfdb3ic1nobc6HmZP9qBVFCVMLDMNpkGMvQQxahByCp0O
+Lna9XvNRiYuoP1Vzv9s6xiQFlpJIqkuNKgPlV5EQ9GooFW5Hd4RcUXSfGenmHmMW
+OeMRFeNYGkS9y8RsZteEBt8w9DeiQyJ50hBs37vmExH8nYQKE3vwO9D8owrXieqW
+fo1IhR5kX9tUoqzVegJ5a9KK8GfaZXINFHDk6Y54jzJ0fFfy1tb0Nokb+Clsi7n2
+l9GkLqq+CxnCRelwXQIDAJ3Zo2MwYTAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB
+/wQEAwIBBjAdBgNVHQ4EFgQU587GT/wWZ5b6SqMHwQSny2re2kcwHwYDVR0jBBgw
+FoAU587GT/wWZ5b6SqMHwQSny2re2kcwDQYJKoZIhvcNAQEFBQADggIBAJuYml2+
+8ygjdsZs93/mQJ7ANtyVDR2tFcU22NU57/IeIl6zgrRdu0waypIN30ckHrMk2pGI
+6YNw3ZPX6bqz3xZaPt7gyPvT/Wwp+BVGoGgmzJNSroIBk5DKd8pNSe/iWtkqvTDO
+TLKBtjDOWU/aWR1qeqRFsIImgYZ29fUQALjuswnoT4cCB64kXPBfrAowzIpAoHME
+wfuJJPaaHFy3PApnNgUIMbOv2AFoKuB4j3TeuFGkjGwgPaL7s9QJ/XvCgKqTbCmY
+Iai7FvOpEl90tYeY8pUm3zTvilORiF0alKM/fCL414i6poyWqD1SNGKfAB5UVUJn
+xk1Gj7sURT0KlhaOEKGXmdXTMIXM3rRyt7yKPBgpaP3ccQfuJDlq+u2lrDgv+R4Q
+DgZxGhBM/nV+/x5XOULK1+EVoVZVWRvRo68R2E7DpSvvkL/A7IITW43WciyTTo9q
+Kd+FPNMN4KIYEsxVL0e3p5sC/kH2iExt2qkBR4NkJ2IQgtYSe14DHzSpyZH+r11t
+hie3I6p1GMog57AP14kOpmciY/SDQSsGS7tY1dHXt7kQY9iJSrSq3RZj9W6+YKH4
+7ejWkE8axsWgKdOnIaj1Wjz3x0miIZpKlVIglnKaZsv30oZDfCK+lvm9AahH3eU7
+QPl1K5srRmSGjR70j/sHd9DqSaIcjVIUpgqT
+-----END CERTIFICATE-----
diff --git a/luni/src/main/files/cacerts/fac084d7.0 b/luni/src/main/files/cacerts/fac084d7.0
new file mode 100644
index 0000000..282ce58
--- /dev/null
+++ b/luni/src/main/files/cacerts/fac084d7.0
@@ -0,0 +1,81 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 49 (0x31)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=JP, O=Japanese Government, OU=ApplicationCA
+ Validity
+ Not Before: Dec 12 15:00:00 2007 GMT
+ Not After : Dec 12 15:00:00 2017 GMT
+ Subject: C=JP, O=Japanese Government, OU=ApplicationCA
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ RSA Public Key: (2048 bit)
+ Modulus (2048 bit):
+ 00:a7:6d:e0:74:4e:87:8f:a5:06:de:68:a2:db:86:
+ 99:4b:64:0d:71:f0:0a:05:9b:8e:aa:e1:cc:2e:d2:
+ 6a:3b:c1:7a:b4:97:61:8d:8a:be:c6:9a:9c:06:b4:
+ 86:51:e4:37:0e:74:78:7e:5f:8a:7f:94:a4:d7:47:
+ 08:fd:50:5a:56:e4:68:ac:28:73:a0:7b:e9:7f:18:
+ 92:40:4f:2d:9d:f5:ae:44:48:73:36:06:9e:64:2c:
+ 3b:34:23:db:5c:26:e4:71:79:8f:d4:6e:79:22:b9:
+ 93:c1:ca:cd:c1:56:ed:88:6a:d7:a0:39:21:04:57:
+ 2c:a2:f5:bc:47:41:4f:5e:34:22:95:b5:1f:29:6d:
+ 5e:4a:f3:4d:72:be:41:56:20:87:fc:e9:50:47:d7:
+ 30:14:ee:5c:8c:55:ba:59:8d:87:fc:23:de:93:d0:
+ 04:8c:fd:ef:6d:bd:d0:7a:c9:a5:3a:6a:72:33:c6:
+ 4a:0d:05:17:2a:2d:7b:b1:a7:d8:d6:f0:be:f4:3f:
+ ea:0e:28:6d:41:61:23:76:78:c3:b8:65:a4:f3:5a:
+ ae:cc:c2:aa:d9:e7:58:de:b6:7e:9d:85:6e:9f:2a:
+ 0a:6f:9f:03:29:30:97:28:1d:bc:b7:cf:54:29:4e:
+ 51:31:f9:27:b6:28:26:fe:a2:63:e6:41:16:f0:33:
+ 98:47
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Subject Key Identifier:
+ 54:5A:CB:26:3F:71:CC:94:46:0D:96:53:EA:6B:48:D0:93:FE:42:75
+ X509v3 Key Usage: critical
+ Certificate Sign, CRL Sign
+ X509v3 Subject Alternative Name:
+ DirName:/C=JP/O=\xE6\x97\xA5\xE6\x9C\xAC\xE5\x9B\xBD\xE6\x94\xBF\xE5\xBA\x9C/OU=\xE3\x82\xA2\xE3\x83\x97\xE3\x83\xAA\xE3\x82\xB1\xE3\x83\xBC\xE3\x82\xB7\xE3\x83\xA7\xE3\x83\xB3CA
+ X509v3 Basic Constraints: critical
+ CA:TRUE
+ Signature Algorithm: sha1WithRSAEncryption
+ 39:6a:44:76:77:38:3a:ec:a3:67:46:0f:f9:8b:06:a8:fb:6a:
+ 90:31:ce:7e:ec:da:d1:89:7c:7a:eb:2e:0c:bd:99:32:e7:b0:
+ 24:d6:c3:ff:f5:b2:88:09:87:2c:e3:54:e1:a3:a6:b2:08:0b:
+ c0:85:a8:c8:d2:9c:71:f6:1d:9f:60:fc:38:33:13:e1:9e:dc:
+ 0b:5f:da:16:50:29:7b:2f:70:91:0f:99:ba:34:34:8d:95:74:
+ c5:7e:78:a9:66:5d:bd:ca:21:77:42:10:ac:66:26:3d:de:91:
+ ab:fd:15:f0:6f:ed:6c:5f:10:f8:f3:16:f6:03:8a:8f:a7:12:
+ 11:0c:cb:fd:3f:79:c1:9c:fd:62:ee:a3:cf:54:0c:d1:2b:5f:
+ 17:3e:e3:3e:bf:c0:2b:3e:09:9b:fe:88:a6:7e:b4:92:17:fc:
+ 23:94:81:bd:6e:a7:c5:8c:c2:eb:11:45:db:f8:41:c9:96:76:
+ ea:70:5f:79:12:6b:e4:a3:07:5a:05:ef:27:49:cf:21:9f:8a:
+ 4c:09:70:66:a9:26:c1:2b:11:4e:33:d2:0e:fc:d6:6c:d2:0e:
+ 32:64:68:ff:ad:05:78:5f:03:1d:a8:e3:90:ac:24:e0:0f:40:
+ a7:4b:ae:8b:28:b7:82:ca:18:07:e6:b7:5b:74:e9:20:19:7f:
+ b2:1b:89:54
+SHA1 Fingerprint=7F:8A:B0:CF:D0:51:87:6A:66:F3:36:0F:47:C8:8D:8C:D3:35:FC:74
+-----BEGIN CERTIFICATE-----
+MIIDoDCCAoigAwIBAgIBMTANBgkqhkiG9w0BAQUFADBDMQswCQYDVQQGEwJKUDEc
+MBoGA1UEChMTSmFwYW5lc2UgR292ZXJubWVudDEWMBQGA1UECxMNQXBwbGljYXRp
+b25DQTAeFw0wNzEyMTIxNTAwMDBaFw0xNzEyMTIxNTAwMDBaMEMxCzAJBgNVBAYT
+AkpQMRwwGgYDVQQKExNKYXBhbmVzZSBHb3Zlcm5tZW50MRYwFAYDVQQLEw1BcHBs
+aWNhdGlvbkNBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp23gdE6H
+j6UG3mii24aZS2QNcfAKBZuOquHMLtJqO8F6tJdhjYq+xpqcBrSGUeQ3DnR4fl+K
+f5Sk10cI/VBaVuRorChzoHvpfxiSQE8tnfWuREhzNgaeZCw7NCPbXCbkcXmP1G55
+IrmTwcrNwVbtiGrXoDkhBFcsovW8R0FPXjQilbUfKW1eSvNNcr5BViCH/OlQR9cw
+FO5cjFW6WY2H/CPek9AEjP3vbb3QesmlOmpyM8ZKDQUXKi17safY1vC+9D/qDiht
+QWEjdnjDuGWk81quzMKq2edY3rZ+nYVunyoKb58DKTCXKB28t89UKU5RMfkntigm
+/qJj5kEW8DOYRwIDAQABo4GeMIGbMB0GA1UdDgQWBBRUWssmP3HMlEYNllPqa0jQ
+k/5CdTAOBgNVHQ8BAf8EBAMCAQYwWQYDVR0RBFIwUKROMEwxCzAJBgNVBAYTAkpQ
+MRgwFgYDVQQKDA/ml6XmnKzlm73mlL/lupwxIzAhBgNVBAsMGuOCouODl+ODquOC
+seODvOOCt+ODp+ODs0NBMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEFBQAD
+ggEBADlqRHZ3ODrso2dGD/mLBqj7apAxzn7s2tGJfHrrLgy9mTLnsCTWw//1sogJ
+hyzjVOGjprIIC8CFqMjSnHH2HZ9g/DgzE+Ge3Atf2hZQKXsvcJEPmbo0NI2VdMV+
+eKlmXb3KIXdCEKxmJj3ekav9FfBv7WxfEPjzFvYDio+nEhEMy/0/ecGc/WLuo89U
+DNErXxc+4z6/wCs+CZv+iKZ+tJIX/COUgb1up8WMwusRRdv4QcmWdupwX3kSa+Sj
+B1oF7ydJzyGfikwJcGapJsErEU4z0g781mzSDjJkaP+tBXhfAx2o45CsJOAPQKdL
+rosot4LKGAfmt1t06SAZf7IbiVQ=
+-----END CERTIFICATE-----
diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java
deleted file mode 100644
index 6ab0b22..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetDecoderICU.java
+++ /dev/null
@@ -1,318 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
- /**
- * A JNI interface for ICU converters.
- *
- *
- * @author Ram Viswanadha, IBM
- */
-package com.ibm.icu4jni.charset;
-
-import com.ibm.icu4jni.common.ErrorCode;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-
-public final class CharsetDecoderICU extends CharsetDecoder {
- private static final int MAX_CHARS_PER_BYTE = 2;
-
- private static final int INPUT_OFFSET = 0;
- private static final int OUTPUT_OFFSET = 1;
- private static final int INVALID_BYTES = 2;
- private static final int INPUT_HELD = 3;
- /*
- * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input bytes consumed
- * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output chars written
- * data[INVALID_BYTES] = number of invalid bytes
- * data[INPUT_HELD] = number of input bytes held in the converter's state
- */
- private int[] data = new int[4];
-
- /* handle to the ICU converter that is opened */
- private long converterHandle = 0;
-
- private byte[] input = null;
- private char[] output= null;
-
- // BEGIN android-added
- private byte[] allocatedInput = null;
- private char[] allocatedOutput = null;
- // END android-added
-
- // These instance variables are
- // always assigned in the methods
- // before being used. This class
- // inhrently multithread unsafe
- // so we dont have to worry about
- // synchronization
- private int inEnd;
- private int outEnd;
- private int ec;
- private int savedInputHeldLen;
-
- public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) {
- // This complexity is necessary to ensure that even if the constructor, superclass
- // constructor, or call to updateCallback throw, we still free the native peer.
- long address = 0;
- try {
- address = NativeConverter.openConverter(icuCanonicalName);
- float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address);
- CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address);
- address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free.
- result.updateCallback();
- return result;
- } finally {
- if (address != 0) {
- NativeConverter.closeConverter(address);
- }
- }
- }
-
- private CharsetDecoderICU(Charset cs, float averageCharsPerByte, long address) {
- super(cs, averageCharsPerByte, MAX_CHARS_PER_BYTE);
- this.converterHandle = address;
- }
-
- /**
- * Sets this decoders replacement string. Substitutes the string in input if an
- * unmappable or illegal sequence is encountered
- * @param newReplacement to replace the error bytes with
- * @stable ICU 2.4
- */
- protected void implReplaceWith(String newReplacement) {
- if (converterHandle > 0) {
- if (newReplacement.length() > NativeConverter.getMaxBytesPerChar(converterHandle)) {
- throw new IllegalArgumentException();
- }
- updateCallback();
- }
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected final void implOnMalformedInput(CodingErrorAction newAction) {
- updateCallback();
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected final void implOnUnmappableCharacter(CodingErrorAction newAction) {
- updateCallback();
- }
-
- private void updateCallback() {
- ec = NativeConverter.setCallbackDecode(converterHandle, this);
- if (ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Flushes any characters saved in the converter's internal buffer and
- * resets the converter.
- * @param out action to be taken
- * @return result of flushing action and completes the decoding all input.
- * Returns CoderResult.UNDERFLOW if the action succeeds.
- * @stable ICU 2.4
- */
- protected final CoderResult implFlush(CharBuffer out) {
- try {
- data[OUTPUT_OFFSET] = getArray(out);
- ec = NativeConverter.flushByteToChar(
- converterHandle, /* Handle to ICU Converter */
- output, /* input array of chars */
- outEnd, /* input index+1 to be written */
- data /* contains data, inOff,outOff */
- );
-
- /* If we don't have room for the output, throw an exception*/
- if (ErrorCode.isFailure(ec)) {
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- } else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND) {//CSDL: add this truncated character error handling
- if (data[INPUT_OFFSET] > 0) {
- return CoderResult.malformedForLength(data[INPUT_OFFSET]);
- }
- } else {
- ErrorCode.getException(ec);
- }
- }
- return CoderResult.UNDERFLOW;
- } finally {
- /* save the flushed data */
- setPosition(out);
- implReset();
- }
- }
-
- protected void implReset() {
- NativeConverter.resetByteToChar(converterHandle);
- data[INPUT_OFFSET] = 0;
- data[OUTPUT_OFFSET] = 0;
- data[INVALID_BYTES] = 0;
- data[INPUT_HELD] = 0;
- savedInputHeldLen = 0;
- output = null;
- input = null;
- allocatedInput = null;
- allocatedOutput = null;
- ec = 0;
- inEnd = 0;
- outEnd = 0;
- }
-
- /**
- * Decodes one or more bytes. The default behaviour of the converter
- * is stop and report if an error in input stream is encountered.
- * To set different behaviour use @see CharsetDecoder.onMalformedInput()
- * This method allows a buffer by buffer conversion of a data stream.
- * The state of the conversion is saved between calls to convert.
- * Among other things, this means multibyte input sequences can be
- * split between calls. If a call to convert results in an Error, the
- * conversion may be continued by calling convert again with suitably
- * modified parameters.All conversions should be finished with a call to
- * the flush method.
- * @param in buffer to decode
- * @param out buffer to populate with decoded result
- * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
- * action succeeds or more input is needed for completing the decoding action.
- * @stable ICU 2.4
- */
- protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out){
- if (!in.hasRemaining()){
- return CoderResult.UNDERFLOW;
- }
-
- data[INPUT_OFFSET] = getArray(in);
- data[OUTPUT_OFFSET]= getArray(out);
- data[INPUT_HELD] = 0;
-
- try{
- ec = NativeConverter.decode(
- converterHandle, /* Handle to ICU Converter */
- input, /* input array of bytes */
- inEnd, /* last index+1 to be converted */
- output, /* input array of chars */
- outEnd, /* input index+1 to be written */
- data, /* contains data, inOff,outOff */
- false /* don't flush the data */
- );
-
- // Return an error.
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- } else if (ec == ErrorCode.U_INVALID_CHAR_FOUND) {
- return CoderResult.unmappableForLength(data[INVALID_BYTES]);
- } else if (ec == ErrorCode.U_ILLEGAL_CHAR_FOUND) {
- return CoderResult.malformedForLength(data[INVALID_BYTES]);
- }
- // Decoding succeeded: give us more data.
- return CoderResult.UNDERFLOW;
- } finally {
- setPosition(in);
- setPosition(out);
- }
- }
-
- /**
- * Releases the system resources by cleanly closing ICU converter opened
- * @stable ICU 2.4
- */
- @Override protected void finalize() throws Throwable {
- try {
- NativeConverter.closeConverter(converterHandle);
- converterHandle = 0;
- } finally {
- super.finalize();
- }
- }
-
- //------------------------------------------
- // private utility methods
- //------------------------------------------
-
- private final int getArray(CharBuffer out){
- if (out.hasArray()) {
- // BEGIN android-changed: take arrayOffset into account
- output = out.array();
- outEnd = out.arrayOffset() + out.limit();
- return out.arrayOffset() + out.position();
- // END android-changed
- } else {
- outEnd = out.remaining();
- // BEGIN android-added
- if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
- allocatedOutput = new char[outEnd];
- }
- output = allocatedOutput;
- // END android-added
- //since the new
- // buffer start position
- // is 0
- return 0;
- }
- }
-
- private final int getArray(ByteBuffer in){
- if (in.hasArray()) {
- // BEGIN android-changed: take arrayOffset into account
- input = in.array();
- inEnd = in.arrayOffset() + in.limit();
- return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
- // END android-changed
- } else {
- inEnd = in.remaining();
- // BEGIN android-added
- if (allocatedInput == null || (inEnd > allocatedInput.length)) {
- allocatedInput = new byte[inEnd];
- }
- input = allocatedInput;
- // END android-added
- // save the current position
- int pos = in.position();
- in.get(input,0,inEnd);
- // reset the position
- in.position(pos);
- // the start position
- // of the new buffer
- // is whatever is savedInputLen
- return savedInputHeldLen;
- }
- }
-
- private final void setPosition(CharBuffer out) {
- if (out.hasArray()) {
- out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
- } else {
- out.put(output, 0, data[OUTPUT_OFFSET]);
- }
- // release reference to output array, which may not be ours
- output = null;
- }
-
- private final void setPosition(ByteBuffer in) {
- // ok was there input held in the previous invocation of decodeLoop
- // that resulted in output in this invocation?
- in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen - data[INPUT_HELD]);
- savedInputHeldLen = data[INPUT_HELD];
- // release reference to input array, which may not be ours
- input = null;
- }
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java
deleted file mode 100644
index 6704b1a..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetEncoderICU.java
+++ /dev/null
@@ -1,431 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-/**
- * A JNI interface for ICU converters.
- *
- *
- * @author Ram Viswanadha, IBM
- */
-package com.ibm.icu4jni.charset;
-
-import com.ibm.icu4jni.common.ErrorCode;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class CharsetEncoderICU extends CharsetEncoder {
- private static final Map<String, byte[]> DEFAULT_REPLACEMENTS = new HashMap<String, byte[]>();
- static {
- // ICU has different default replacements to the RI in some cases. There are many
- // additional cases, but this covers all the charsets that Java guarantees will be
- // available, which is where compatibility seems most important. (The RI even uses
- // the byte corresponding to '?' in ASCII as the replacement byte for charsets where that
- // byte corresponds to an entirely different character.)
- // It's odd that UTF-8 doesn't use U+FFFD, given that (unlike ISO-8859-1 and US-ASCII) it
- // can represent it, but this is what the RI does...
- byte[] questionMark = new byte[] { (byte) '?' };
- DEFAULT_REPLACEMENTS.put("UTF-8", questionMark);
- DEFAULT_REPLACEMENTS.put("ISO-8859-1", questionMark);
- DEFAULT_REPLACEMENTS.put("US-ASCII", questionMark);
- }
-
- private static final int INPUT_OFFSET = 0;
- private static final int OUTPUT_OFFSET = 1;
- private static final int INVALID_CHARS = 2;
- private static final int INPUT_HELD = 3;
- /*
- * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input chars consumed
- * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output bytes written
- * data[INVALID_CHARS] = number of invalid chars
- * data[INPUT_HELD] = number of input chars held in the converter's state
- */
- private int[] data = new int[4];
- /* handle to the ICU converter that is opened */
- private long converterHandle=0;
-
- private char[] input = null;
- private byte[] output = null;
-
- // BEGIN android-added
- private char[] allocatedInput = null;
- private byte[] allocatedOutput = null;
- // END android-added
-
- // These instance variables are
- // always assigned in the methods
- // before being used. This class
- // inhrently multithread unsafe
- // so we dont have to worry about
- // synchronization
- private int inEnd;
- private int outEnd;
- private int ec;
- private int savedInputHeldLen;
-
- public static CharsetEncoderICU newInstance(Charset cs, String icuCanonicalName) {
- // This complexity is necessary to ensure that even if the constructor, superclass
- // constructor, or call to updateCallback throw, we still free the native peer.
- long address = 0;
- try {
- address = NativeConverter.openConverter(icuCanonicalName);
- float averageBytesPerChar = NativeConverter.getAveBytesPerChar(address);
- float maxBytesPerChar = NativeConverter.getMaxBytesPerChar(address);
- byte[] replacement = makeReplacement(icuCanonicalName, address);
- CharsetEncoderICU result = new CharsetEncoderICU(cs, averageBytesPerChar, maxBytesPerChar, replacement, address);
- address = 0; // CharsetEncoderICU has taken ownership; its finalizer will do the free.
- result.updateCallback();
- return result;
- } finally {
- if (address != 0) {
- NativeConverter.closeConverter(address);
- }
- }
- }
-
- private static byte[] makeReplacement(String icuCanonicalName, long address) {
- // We have our own map of RI-compatible default replacements (where ICU disagrees)...
- byte[] replacement = DEFAULT_REPLACEMENTS.get(icuCanonicalName);
- if (replacement != null) {
- return replacement.clone();
- }
- // ...but fall back to asking ICU.
- return NativeConverter.getSubstitutionBytes(address);
- }
-
- private CharsetEncoderICU(Charset cs, float averageBytesPerChar, float maxBytesPerChar, byte[] replacement, long address) {
- super(cs, averageBytesPerChar, maxBytesPerChar, replacement);
- this.converterHandle = address;
- }
-
- /**
- * Sets this encoders replacement string. Substitutes the string in output if an
- * unmappable or illegal sequence is encountered
- * @param newReplacement to replace the error chars with
- * @stable ICU 2.4
- */
- protected void implReplaceWith(byte[] newReplacement) {
- if (converterHandle != 0) {
- if (newReplacement.length > NativeConverter.getMaxBytesPerChar(converterHandle)) {
- throw new IllegalArgumentException("Number of replacement Bytes are greater than max bytes per char");
- }
- updateCallback();
- }
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected void implOnMalformedInput(CodingErrorAction newAction) {
- updateCallback();
- }
-
- /**
- * Sets the action to be taken if an illegal sequence is encountered
- * @param newAction action to be taken
- * @exception IllegalArgumentException
- * @stable ICU 2.4
- */
- protected void implOnUnmappableCharacter(CodingErrorAction newAction) {
- updateCallback();
- }
-
- private void updateCallback() {
- ec = NativeConverter.setCallbackEncode(converterHandle, this);
- if (ErrorCode.isFailure(ec)){
- throw ErrorCode.getException(ec);
- }
- }
-
- /**
- * Flushes any characters saved in the converter's internal buffer and
- * resets the converter.
- * @param out action to be taken
- * @return result of flushing action and completes the decoding all input.
- * Returns CoderResult.UNDERFLOW if the action succeeds.
- * @stable ICU 2.4
- */
- protected CoderResult implFlush(ByteBuffer out) {
- try {
- data[OUTPUT_OFFSET] = getArray(out);
- ec = NativeConverter.flushCharToByte(converterHandle,/* Handle to ICU Converter */
- output, /* output array of chars */
- outEnd, /* output index+1 to be written */
- data /* contains data, inOff,outOff */
- );
-
- /* If we don't have room for the output, throw an exception*/
- if (ErrorCode.isFailure(ec)) {
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- } else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND) {//CSDL: add this truncated character error handling
- if (data[INPUT_OFFSET] > 0) {
- return CoderResult.malformedForLength(data[INPUT_OFFSET]);
- }
- } else {
- ErrorCode.getException(ec);
- }
- }
- return CoderResult.UNDERFLOW;
- } finally {
- setPosition(out);
- implReset();
- }
- }
-
- /**
- * Resets the from Unicode mode of converter
- * @stable ICU 2.4
- */
- protected void implReset() {
- NativeConverter.resetCharToByte(converterHandle);
- data[INPUT_OFFSET] = 0;
- data[OUTPUT_OFFSET] = 0;
- data[INVALID_CHARS] = 0;
- data[INPUT_HELD] = 0;
- savedInputHeldLen = 0;
- }
-
- /**
- * Encodes one or more chars. The default behaviour of the
- * converter is stop and report if an error in input stream is encountered.
- * To set different behaviour use @see CharsetEncoder.onMalformedInput()
- * @param in buffer to decode
- * @param out buffer to populate with decoded result
- * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
- * action succeeds or more input is needed for completing the decoding action.
- * @stable ICU 2.4
- */
- protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
- if (!in.hasRemaining()) {
- return CoderResult.UNDERFLOW;
- }
-
- data[INPUT_OFFSET] = getArray(in);
- data[OUTPUT_OFFSET]= getArray(out);
- data[INPUT_HELD] = 0;
- // BEGIN android-added
- data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors.
- // END android added
-
- try {
- /* do the conversion */
- ec = NativeConverter.encode(converterHandle,/* Handle to ICU Converter */
- input, /* input array of bytes */
- inEnd, /* last index+1 to be converted */
- output, /* output array of chars */
- outEnd, /* output index+1 to be written */
- data, /* contains data, inOff,outOff */
- false /* donot flush the data */
- );
- if (ErrorCode.isFailure(ec)) {
- /* If we don't have room for the output return error */
- if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
- return CoderResult.OVERFLOW;
- } else if (ec == ErrorCode.U_INVALID_CHAR_FOUND) {
- return CoderResult.unmappableForLength(data[INVALID_CHARS]);
- } else if (ec == ErrorCode.U_ILLEGAL_CHAR_FOUND) {
- // in.position(in.position() - 1);
- return CoderResult.malformedForLength(data[INVALID_CHARS]);
- }
- }
- return CoderResult.UNDERFLOW;
- } finally {
- /* save state */
- setPosition(in);
- setPosition(out);
- }
- }
-
- /**
- * Ascertains if a given Unicode character can
- * be converted to the target encoding
- *
- * @param c the character to be converted
- * @return true if a character can be converted
- * @stable ICU 2.4
- *
- */
- public boolean canEncode(char c) {
- return canEncode((int) c);
- }
-
- /**
- * Ascertains if a given Unicode code point (32bit value for handling surrogates)
- * can be converted to the target encoding. If the caller wants to test if a
- * surrogate pair can be converted to target encoding then the
- * responsibility of assembling the int value lies with the caller.
- * For assembling a code point the caller can use UTF16 class of ICU4J and do something like:
- * <pre>
- * while(i<mySource.length){
- * if(UTF16.isLeadSurrogate(mySource[i])&& i+1< mySource.length){
- * if(UTF16.isTrailSurrogate(mySource[i+1])){
- * int temp = UTF16.charAt(mySource,i,i+1,0);
- * if(!((CharsetEncoderICU) myConv).canEncode(temp)){
- * passed=false;
- * }
- * i++;
- * i++;
- * }
- * }
- * }
- * </pre>
- * or
- * <pre>
- * String src = new String(mySource);
- * int i,codepoint;
- * boolean passed = false;
- * while(i<src.length()){
- * codepoint = UTF16.charAt(src,i);
- * i+= (codepoint>0xfff)? 2:1;
- * if(!(CharsetEncoderICU) myConv).canEncode(codepoint)){
- * passed = false;
- * }
- * }
- * </pre>
- *
- * @param codepoint Unicode code point as int value
- * @return true if a character can be converted
- * @obsolete ICU 2.4
- * @deprecated ICU 3.4
- */
- public boolean canEncode(int codepoint) {
- return NativeConverter.canEncode(converterHandle, codepoint);
- }
-
- /**
- * Releases the system resources by cleanly closing ICU converter opened
- * @exception Throwable exception thrown by super class' finalize method
- * @stable ICU 2.4
- */
- @Override protected void finalize() throws Throwable {
- try {
- NativeConverter.closeConverter(converterHandle);
- converterHandle=0;
- } finally {
- super.finalize();
- }
- }
-
- //------------------------------------------
- // private utility methods
- //------------------------------------------
- private final int getArray(ByteBuffer out) {
- if(out.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- output = out.array();
- outEnd = out.arrayOffset() + out.limit();
- return out.arrayOffset() + out.position();
- // END android-changed
- }else{
- outEnd = out.remaining();
- // BEGIN android-added
- if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
- allocatedOutput = new byte[outEnd];
- }
- output = allocatedOutput;
- // END android-added
- //since the new
- // buffer start position
- // is 0
- return 0;
- }
- }
-
- private final int getArray(CharBuffer in) {
- if(in.hasArray()){
- // BEGIN android-changed: take arrayOffset into account
- input = in.array();
- inEnd = in.arrayOffset() + in.limit();
- return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
- // END android-changed
- }else{
- inEnd = in.remaining();
- // BEGIN android-added
- if (allocatedInput == null || (inEnd > allocatedInput.length)) {
- allocatedInput = new char[inEnd];
- }
- input = allocatedInput;
- // END android-added
- // save the current position
- int pos = in.position();
- in.get(input,0,inEnd);
- // reset the position
- in.position(pos);
- // the start position
- // of the new buffer
- // is whatever is savedInputLen
- return savedInputHeldLen;
- }
-
- }
- private final void setPosition(ByteBuffer out) {
-
- if (out.hasArray()) {
- // in getArray method we accessed the
- // array backing the buffer directly and wrote to
- // it, so just just set the position and return.
- // This is done to avoid the creation of temp array.
- // BEGIN android-changed: take arrayOffset into account
- out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
- // END android-changed
- } else {
- out.put(output, 0, data[OUTPUT_OFFSET]);
- }
- // BEGIN android-added
- // release reference to output array, which may not be ours
- output = null;
- // END android-added
- }
- private final void setPosition(CharBuffer in){
-
-// BEGIN android-removed
-// // was there input held in the previous invocation of encodeLoop
-// // that resulted in output in this invocation?
-// if(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0){
-// int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
-// in.position(len);
-// savedInputHeldLen = data[INPUT_HELD];
-// }else{
-// in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen);
-// savedInputHeldLen = data[INPUT_HELD];
-// in.position(in.position() - savedInputHeldLen);
-// }
-// END android-removed
-
-// BEGIN android-added
- // Slightly rewired original code to make it cleaner. Also
- // added a fix for the problem where input charatcers got
- // lost when invalid characters were encountered. Not sure
- // what happens when data[INVALID_CHARS] is > 1, though,
- // since we never saw that happening.
- int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
- len -= data[INVALID_CHARS]; // Otherwise position becomes wrong.
- in.position(len);
- savedInputHeldLen = data[INPUT_HELD];
- // was there input held in the previous invocation of encodeLoop
- // that resulted in output in this invocation?
- if(!(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0)){
- in.position(in.position() - savedInputHeldLen);
- }
-// END android-added
-
- // BEGIN android-added
- // release reference to input array, which may not be ours
- input = null;
- // END android-added
- }
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java b/luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java
deleted file mode 100644
index cab7a52..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/charset/CharsetICU.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.charset;
-
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-
-public final class CharsetICU extends Charset {
- private final String icuCanonicalName;
-
- protected CharsetICU(String canonicalName, String icuCanonName, String[] aliases) {
- super(canonicalName, aliases);
- icuCanonicalName = icuCanonName;
- }
-
- public CharsetDecoder newDecoder() {
- return CharsetDecoderICU.newInstance(this, icuCanonicalName);
- }
-
- public CharsetEncoder newEncoder() {
- return CharsetEncoderICU.newInstance(this, icuCanonicalName);
- }
-
- public boolean contains(Charset cs) {
- if (cs == null) {
- return false;
- } else if (this.equals(cs)) {
- return true;
- }
- return NativeConverter.contains(this.name(), cs.name());
- }
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java b/luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java
deleted file mode 100644
index 2e37f32..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/charset/NativeConverter.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2006, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.charset;
-
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public final class NativeConverter {
- /**
- * Converts an array of bytes containing characters in an external
- * encoding into an array of Unicode characters. This method allows
- * buffer-by-buffer conversion of a data stream. The state of the
- * conversion is saved between calls. Among other things,
- * this means multibyte input sequences can be split between calls.
- * If a call to results in an error, the conversion may be
- * continued by calling this method again with suitably modified parameters.
- * All conversions should be finished with a call to the flush method.
- *
- * @param converterHandle Address of converter object created by C code
- * @param input byte array containing text to be converted.
- * @param inEnd stop conversion at this offset in input array (exclusive).
- * @param output character array to receive conversion result.
- * @param outEnd stop writing to output array at this offset (exclusive).
- * @param data integer array containing the following data
- * data[0] = inputOffset
- * data[1] = outputOffset
- * @return int error code returned by ICU
- * @internal ICU 2.4
- */
- public static native int decode(long converterHandle, byte[] input, int inEnd,
- char[] output, int outEnd, int[] data, boolean flush);
-
- /**
- * Converts an array of Unicode chars to an array of bytes in an external encoding.
- * This method allows a buffer by buffer conversion of a data stream. The state of the
- * conversion is saved between calls to convert. Among other things,
- * this means multibyte input sequences can be split between calls.
- * If a call results in an error, the conversion may be
- * continued by calling this method again with suitably modified parameters.
- * All conversions should be finished with a call to the flush method.
- *
- * @param converterHandle Address of converter object created by C code
- * @param input char array containing text to be converted.
- * @param inEnd stop conversion at this offset in input array (exclusive).
- * @param output byte array to receive conversion result.
- * @param outEnd stop writing to output array at this offset (exclusive).
- * @param data integer array containing the following data
- * data[0] = inputOffset
- * data[1] = outputOffset
- * @return int error code returned by ICU
- * @internal ICU 2.4
- */
- public static native int encode(long converterHandle, char[] input, int inEnd,
- byte[] output, int outEnd, int[] data, boolean flush);
-
- /**
- * Writes any remaining output to the output buffer and resets the
- * converter to its initial state.
- *
- * @param converterHandle Address of converter object created by C code
- * @param output byte array to receive flushed output.
- * @param outEnd stop writing to output array at this offset (exclusive).
- * @return int error code returned by ICU
- * @param data integer array containing the following data
- * data[0] = inputOffset
- * data[1] = outputOffset
- * @internal ICU 2.4
- */
- public static native int flushCharToByte(long converterHandle, byte[] output, int outEnd, int[] data);
-
- /**
- * Writes any remaining output to the output buffer and resets the
- * converter to its initial state.
- *
- * @param converterHandle Address of converter object created by the native code
- * @param output char array to receive flushed output.
- * @param outEnd stop writing to output array at this offset (exclusive).
- * @return int error code returned by ICU
- * @param data integer array containing the following data
- * data[0] = inputOffset
- * data[1] = outputOffset
- * @internal ICU 2.4
- */
- public static native int flushByteToChar(long converterHandle, char[] output, int outEnd, int[] data);
-
- public static native long openConverter(String encoding);
- public static native void closeConverter(long converterHandle);
-
- public static native void resetByteToChar(long converterHandle);
- public static native void resetCharToByte(long converterHandle);
-
- public static native byte[] getSubstitutionBytes(long converterHandle);
-
- public static native int getMaxBytesPerChar(long converterHandle);
- public static native int getMinBytesPerChar(long converterHandle);
- public static native float getAveBytesPerChar(long converterHandle);
- public static native float getAveCharsPerByte(long converterHandle);
-
- public static native boolean contains(String converterName1, String converterName2);
-
- public static native boolean canEncode(long converterHandle, int codeUnit);
-
- public static native String[] getAvailableCharsetNames();
- public static native Charset charsetForName(String charsetName);
-
- // Translates from Java's enum to the magic numbers #defined in "NativeConverter.cpp".
- private static int translateCodingErrorAction(CodingErrorAction action) {
- if (action == CodingErrorAction.REPORT) {
- return 0;
- } else if (action == CodingErrorAction.IGNORE) {
- return 1;
- } else if (action == CodingErrorAction.REPLACE) {
- return 2;
- } else {
- throw new AssertionError(); // Someone changed the enum.
- }
- }
-
- public static int setCallbackDecode(long converterHandle, CharsetDecoder decoder) {
- return setCallbackDecode(converterHandle,
- translateCodingErrorAction(decoder.malformedInputAction()),
- translateCodingErrorAction(decoder.unmappableCharacterAction()),
- decoder.replacement().toCharArray());
- }
- private static native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars);
-
- public static int setCallbackEncode(long converterHandle, CharsetEncoder encoder) {
- return setCallbackEncode(converterHandle,
- translateCodingErrorAction(encoder.malformedInputAction()),
- translateCodingErrorAction(encoder.unmappableCharacterAction()),
- encoder.replacement());
- }
- private static native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes);
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java b/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java
deleted file mode 100644
index 42d1750..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/common/ErrorCode.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
-******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-******************************************************************************
-*
-******************************************************************************
-*/
-
-package com.ibm.icu4jni.common;
-
-/**
-* Error exception class mapping ICU error codes of the enum UErrorCode
-* @author syn wee quek
-* @internal
-*/
-public final class ErrorCode extends Exception
-{
-
- // public methods --------------------------------------------------------
-
- /**
- * Generic mapping from the error codes to java default exceptions.
- * @param error error code
- * @return java default exception that maps to the argument error code,
- * otherwise if error is not a valid error code, null is returned.
- * @stable ICU 2.4
- */
- public static final RuntimeException getException(int error)
- {
- if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
- return null;
- }
- String errorname = ERROR_NAMES_[U_ILLEGAL_ARGUMENT_ERROR];
- switch (error) {
- case U_ILLEGAL_ARGUMENT_ERROR :
- return new IllegalArgumentException(errorname);
- case U_INDEX_OUTOFBOUNDS_ERROR :
- return new ArrayIndexOutOfBoundsException(errorname);
- case U_BUFFER_OVERFLOW_ERROR :
- return new ArrayIndexOutOfBoundsException(errorname);
- case U_UNSUPPORTED_ERROR :
- return new UnsupportedOperationException(errorname);
- default :
- return new RuntimeException(errorname);
- }
- }
-
- // public static data member ---------------------------------------------
-
- /**
- * Start of information results (semantically successful)
- */
- public static final int U_ERROR_INFO_START = -128;
- /**
- * A resource bundle lookup returned a fallback result (not an error)
- */
- public static final int U_USING_FALLBACK_ERROR = -128;
- /**
- * A resource bundle lookup returned a result from the root locale (not an
- * error)
- */
- public static final int U_USING_DEFAULT_ERROR = -127;
- /**
- * A SafeClone operation required allocating memory (informational
- * only
- */
- public static final int U_SAFECLONE_ALLOCATED_ERROR = -126;
- /**
- * This must always be the last warning value to indicate the limit for
- * UErrorCode warnings (last warning code +1)
- */
- public static final int U_ERROR_INFO_LIMIT = -125;
-
- /**
- * No error, no warning
- */
- public static final int U_ZERO_ERROR = 0;
- /**
- * Start of codes indicating failure
- */
- public static final int U_ILLEGAL_ARGUMENT_ERROR = 1;
- public static final int U_MISSING_RESOURCE_ERROR = 2;
- public static final int U_INVALID_FORMAT_ERROR = 3;
- public static final int U_FILE_ACCESS_ERROR = 4;
- /**
- * Indicates a bug in the library code
- */
- public static final int U_INTERNAL_PROGRAM_ERROR = 5;
- public static final int U_MESSAGE_PARSE_ERROR = 6;
- /**
- * Memory allocation error
- */
- public static final int U_MEMORY_ALLOCATION_ERROR = 7;
- public static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
- /**
- * Equivalent to Java ParseException
- */
- public static final int U_PARSE_ERROR = 9;
- /**
- * In the Character conversion routines: Invalid character or sequence was
- * encountered
- */
- public static final int U_INVALID_CHAR_FOUND = 10;
- /**
- * In the Character conversion routines: More bytes are required to complete
- * the conversion successfully
- */
- public static final int U_TRUNCATED_CHAR_FOUND = 11;
- /**
- * In codeset conversion: a sequence that does NOT belong in the codepage has
- * been encountered
- */
- public static final int U_ILLEGAL_CHAR_FOUND = 12;
- /**
- * Conversion table file found, but corrupted
- */
- public static final int U_INVALID_TABLE_FORMAT = 13;
- /**
- * Conversion table file not found
- */
- public static final int U_INVALID_TABLE_FILE = 14;
- /**
- * A result would not fit in the supplied buffer
- */
- public static final int U_BUFFER_OVERFLOW_ERROR = 15;
- /**
- * Requested operation not supported in current context
- */
- public static final int U_UNSUPPORTED_ERROR = 16;
- /**
- * an operation is requested over a resource that does not support it
- */
- public static final int U_RESOURCE_TYPE_MISMATCH = 17;
- /**
- * ISO-2022 illlegal escape sequence
- */
- public static final int U_ILLEGAL_ESCAPE_SEQUENCE = 18;
- /**
- * ISO-2022 unsupported escape sequence
- */
- public static final int U_UNSUPPORTED_ESCAPE_SEQUENCE = 19;
- /**
- * No space available for in-buffer expansion for Arabic shaping
- */
- public static final int U_NO_SPACE_AVAILABLE = 20;
- /**
- * This must always be the last value to indicate the limit for UErrorCode
- * (last error code +1)
- */
- public static final int U_ERROR_LIMIT = 21;
- /**
- * Load library flag
- */
- public static boolean LIBRARY_LOADED = false;
-
- // private data member ----------------------------------------------------
-
- /**
- * Array of error code names corresponding to the errorcodes.
- * ie ERROR_NAMES_[0] = name of U_ZERO_ERROR
- */
- private static final String ERROR_NAMES_[] = {
- "U_ZERO_ERROR", "U_ILLEGAL_ARGUMENT_ERROR",
- "U_MISSING_RESOURCE_ERROR", "U_INVALID_FORMAT_ERROR",
- "U_FILE_ACCESS_ERROR", "U_INTERNAL_PROGRAM_ERROR",
- "U_MESSAGE_PARSE_ERROR", "U_MEMORY_ALLOCATION_ERROR",
- "U_INDEX_OUTOFBOUNDS_ERROR", "U_PARSE_ERROR",
- "U_INVALID_CHAR_FOUND", "U_TRUNCATED_CHAR_FOUND",
- "U_ILLEGAL_CHAR_FOUND", "U_INVALID_TABLE_FORMAT",
- "U_INVALID_TABLE_FILE", "U_BUFFER_OVERFLOW_ERROR",
- "U_UNSUPPORTED_ERROR", "U_RESOURCE_TYPE_MISMATCH",
- "U_ILLEGAL_ESCAPE_SEQUENCE", "U_UNSUPPORTED_ESCAPE_SEQUENCE"
- };
- /**
- * Returns the error name of the input error code
- * @param ec int value of the error code
- * @return String name of the error code
- * @stable ICU 2.4
- */
- public static String getErrorName(int ec){
- return ERROR_NAMES_[ec];
- }
-
- /**
- * Returns true if the input error code denotes success
- * @param ec int value of the error code
- * @return boolean
- * @stable ICU 2.4
- */
- public static boolean isSuccess(int ec){
- return (ec<=U_ZERO_ERROR);
- }
-
- /**
- * Returns true if the input error code denotes failure
- * @param ec int value of the error code
- * @return boolean
- * @stable ICU 2.4
- */
- public static boolean isFailure(int ec){
- return (ec>U_ZERO_ERROR);
- }
-}
-
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java b/luni/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java
deleted file mode 100644
index eaf626f..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/CollationAttribute.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
- * TODO: move these constants into NativeCollation.
- */
-public final class CollationAttribute {
- // Values from the native UColAttributeValue enum.
- public static final int VALUE_DEFAULT = -1;
- public static final int VALUE_PRIMARY = 0;
- public static final int VALUE_SECONDARY = 1;
- public static final int VALUE_TERTIARY = 2;
- public static final int VALUE_DEFAULT_STRENGTH = VALUE_TERTIARY;
- public static final int VALUE_QUATERNARY = 3;
- public static final int VALUE_IDENTICAL = 15;
- public static final int VALUE_OFF = 16;
- public static final int VALUE_ON = 17;
- public static final int VALUE_SHIFTED = 20;
- public static final int VALUE_NON_IGNORABLE = 21;
- public static final int VALUE_LOWER_FIRST = 24;
- public static final int VALUE_UPPER_FIRST = 25;
- public static final int VALUE_ON_WITHOUT_HANGUL = 28;
- public static final int VALUE_ATTRIBUTE_VALUE_COUNT = 29;
- // Values from the UColAttribute enum.
- public static final int FRENCH_COLLATION = 0;
- public static final int ALTERNATE_HANDLING = 1;
- public static final int CASE_FIRST = 2;
- public static final int CASE_LEVEL = 3;
- public static final int NORMALIZATION_MODE = 4;
- public static final int DECOMPOSITION_MODE = NORMALIZATION_MODE;
- public static final int STRENGTH = 5;
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java b/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java
deleted file mode 100644
index e84e438..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/CollationElementIterator.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import java.text.CharacterIterator;
-
-
-/**
-* Collation element iterator JNI wrapper.
-* Iterates over the collation elements of a data string.
-* The iterator supports both forward and backwards full iteration, ie if
-* backwards iteration is performed in the midst of a forward iteration, the
-* result is undefined.
-* To perform a backwards iteration in the midst of a forward iteration,
-* reset() has to be called.
-* This will shift the position to either the start or the last character in the
-* data string depending on whether next() is called or previous().
-* <pre>
-* RuleBasedCollator coll = Collator.getInstance();
-* CollationElementIterator iterator = coll.getCollationElementIterator("abc");
-* int ce = 0;
-* while (ce != CollationElementIterator.NULLORDER) {
-* ce = iterator.next();
-* }
-* iterator.reset();
-* while (ce != CollationElementIterator.NULLORDER) {
-* ce = iterator.previous();
-* }
-* </pre>
-* @author syn wee quek
-* @stable ICU 2.4
-*/
-
-public final class CollationElementIterator {
- // public data member -------------------------------------------
-
- /**
- * @stable ICU 2.4
- */
- public static final int NULLORDER = 0xFFFFFFFF;
-
- // public methods -----------------------------------------------
-
- /**
- * Reset the collation elements to their initial state.
- * This will move the 'cursor' to the beginning of the text.
- * @stable ICU 2.4
- */
- public void reset() {
- NativeCollation.reset(m_collelemiterator_);
- }
-
- /**
- * Get the ordering priority of the next collation element in the text.
- * A single character may contain more than one collation element.
- * @return next collation elements ordering, or NULLORDER if the end of the
- * text is reached.
- * @stable ICU 2.4
- */
- public int next() {
- return NativeCollation.next(m_collelemiterator_);
- }
-
- /**
- * Get the ordering priority of the previous collation element in the text.
- * A single character may contain more than one collation element.
- * @return previous collation element ordering, or NULLORDER if the end of
- * the text is reached.
- * @stable ICU 2.4
- */
- public int previous() {
- return NativeCollation.previous(m_collelemiterator_);
- }
-
- /**
- * Get the maximum length of any expansion sequences that end with the
- * specified comparison order.
- * @param order collation order returned by previous or next.
- * @return maximum size of the expansion sequences ending with the collation
- * element or 1 if collation element does not occur at the end of
- * any expansion sequence
- * @stable ICU 2.4
- */
- public int getMaxExpansion(int order) {
- return NativeCollation.getMaxExpansion(m_collelemiterator_, order);
- }
-
- /**
- * Set the text containing the collation elements.
- * @param source text containing the collation elements.
- * @stable ICU 2.4
- */
- public void setText(String source) {
- NativeCollation.setText(m_collelemiterator_, source);
- }
-
- // BEGIN android-added
- public void setText(CharacterIterator source) {
- NativeCollation.setText(m_collelemiterator_, source.toString());
- }
- // END android-added
-
- /**
- * Get the offset of the current source character.
- * This is an offset into the text of the character containing the current
- * collation elements.
- * @return offset of the current source character.
- * @stable ICU 2.4
- */
- public int getOffset() {
- return NativeCollation.getOffset(m_collelemiterator_);
- }
-
- /**
- * Set the offset of the current source character.
- * This is an offset into the text of the character to be processed.
- * @param offset The desired character offset.
- * @stable ICU 2.4
- */
- public void setOffset(int offset) {
- NativeCollation.setOffset(m_collelemiterator_, offset);
- }
-
- /**
- * Gets the primary order of a collation order.
- * @param order the collation order
- * @return the primary order of a collation order.
- * @stable ICU 2.4
- */
- public static int primaryOrder(int order) {
- return ((order & PRIMARY_ORDER_MASK_) >> PRIMARY_ORDER_SHIFT_) &
- UNSIGNED_16_BIT_MASK_;
- }
-
- /**
- * Gets the secondary order of a collation order.
- * @param order the collation order
- * @return the secondary order of a collation order.
- * @stable ICU 2.4
- */
- public static int secondaryOrder(int order) {
- return (order & SECONDARY_ORDER_MASK_) >> SECONDARY_ORDER_SHIFT_;
- }
-
- /**
- * Gets the tertiary order of a collation order.
- * @param order the collation order
- * @return the tertiary order of a collation order.
- * @stable ICU 2.4
- */
- public static int tertiaryOrder(int order) {
- return order & TERTIARY_ORDER_MASK_;
- }
-
- // protected constructor ----------------------------------------
-
- /**
- * CollationElementIteratorJNI constructor.
- * The only caller of this class should be
- * RuleBasedCollator.getCollationElementIterator().
- * @param collelemiteratoraddress address of C collationelementiterator
- */
- CollationElementIterator(int collelemiteratoraddress) {
- m_collelemiterator_ = collelemiteratoraddress;
- }
-
- // protected methods --------------------------------------------
-
- /**
- * Garbage collection.
- * Close C collator and reclaim memory.
- * @stable ICU 2.4
- */
- @Override protected void finalize() throws Throwable {
- try {
- NativeCollation.closeElements(m_collelemiterator_);
- } finally {
- super.finalize();
- }
- }
-
- // private data members -----------------------------------------
-
- /**
- * C collator
- */
- private int m_collelemiterator_;
-
- /**
- * ICU constant primary order mask for collation elements
- */
- private static final int PRIMARY_ORDER_MASK_ = 0xffff0000;
- /**
- * ICU constant secondary order mask for collation elements
- */
- private static final int SECONDARY_ORDER_MASK_ = 0x0000ff00;
- /**
- * ICU constant tertiary order mask for collation elements
- */
- private static final int TERTIARY_ORDER_MASK_ = 0x000000ff;
- /**
- * ICU constant primary order shift for collation elements
- */
- private static final int PRIMARY_ORDER_SHIFT_ = 16;
- /**
- * ICU constant secondary order shift for collation elements
- */
- private static final int SECONDARY_ORDER_SHIFT_ = 8;
- /**
- * Unsigned 16 bit mask
- */
- private static final int UNSIGNED_16_BIT_MASK_ = 0x0000FFFF;
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/CollationKey.java b/luni/src/main/java/com/ibm/icu4jni/text/CollationKey.java
deleted file mode 100644
index dbd714c..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/CollationKey.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
- * A concrete implementation of the abstract java.text.CollationKey.
- */
-public final class CollationKey extends java.text.CollationKey {
- /**
- * The key.
- */
- private final byte[] bytes;
-
- /**
- * Cached hash value.
- */
- private int hashCode;
-
- CollationKey(String source, byte[] bytes) {
- super(source);
- this.bytes = bytes;
- }
-
- public int compareTo(java.text.CollationKey other) {
- // Get the bytes from the other collation key.
- final byte[] rhsBytes;
- if (other instanceof CollationKey) {
- rhsBytes = ((CollationKey) other).bytes;
- } else {
- rhsBytes = other.toByteArray();
- }
-
- if (bytes == null || bytes.length == 0) {
- if (rhsBytes == null || rhsBytes.length == 0) {
- return 0;
- }
- return -1;
- } else {
- if (rhsBytes == null || rhsBytes.length == 0) {
- return 1;
- }
- }
-
- int count = Math.min(bytes.length, rhsBytes.length);
- for (int i = 0; i < count; ++i) {
- int s = bytes[i] & 0xff;
- int t = rhsBytes[i] & 0xff;
- if (s < t) {
- return -1;
- }
- if (s > t) {
- return 1;
- }
- }
- if (bytes.length < rhsBytes.length) {
- return -1;
- }
- if (bytes.length > rhsBytes.length) {
- return 1;
- }
- return 0;
- }
-
- /**
- * Checks if target object is equal to this object.
- * Target is first casted to CollationKey and bitwise compared.
- * @param target comparison object
- * @return true if both objects are equal, false otherwise
- * @stable ICU 2.4
- */
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof CollationKey)) {
- return false;
- }
- return compareTo((CollationKey) object) == 0;
- }
-
- /**
- * Creates a hash code for this CollationKey.
- * Compute the hash by iterating sparsely over about 32 (up to 63) bytes
- * spaced evenly through the string. For each byte, multiply the previous
- * hash value by a prime number and add the new byte in, like a linear
- * congruential random number generator, producing a pseudo-random
- * deterministic value well distributed over the output range.
- * @return hash value of collation key. Hash value is never 0.
- * @stable ICU 2.4
- */
- public int hashCode() {
- if (hashCode == 0) {
- if (bytes != null && bytes.length != 0) {
- int len = bytes.length;
- int inc = ((len - 32) / 32) + 1;
- for (int i = 0; i < len;) {
- hashCode = (hashCode * 37) + bytes[i];
- i += inc;
- }
- }
- if (hashCode == 0) {
- hashCode = 1;
- }
- }
- return hashCode;
- }
-
- public byte[] toByteArray() {
- if (bytes == null || bytes.length == 0) {
- return null;
- }
- return bytes.clone();
- }
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/Collator.java b/luni/src/main/java/com/ibm/icu4jni/text/Collator.java
deleted file mode 100644
index 9c6ad3a..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/Collator.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import java.util.Locale;
-
-public abstract class Collator implements Cloneable {
- /**
- * Strongest collator strength value. Typically used to denote differences
- * between base characters. See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int PRIMARY = CollationAttribute.VALUE_PRIMARY;
-
- /**
- * Second level collator strength value.
- * Accents in the characters are considered secondary differences.
- * Other differences between letters can also be considered secondary
- * differences, depending on the language.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int SECONDARY = CollationAttribute.VALUE_SECONDARY;
-
- /**
- * Third level collator strength value.
- * Upper and lower case differences in characters are distinguished at this
- * strength level. In addition, a variant of a letter differs from the base
- * form on the tertiary level.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int TERTIARY = CollationAttribute.VALUE_TERTIARY;
-
- /**
- * Fourth level collator strength value.
- * When punctuation is ignored
- * <a href="http://www-124.ibm.com/icu/userguide/Collate_Concepts.html#Ignoring_Punctuation">
- * (see Ignoring Punctuations in the user guide)</a> at PRIMARY to TERTIARY
- * strength, an additional strength level can
- * be used to distinguish words with and without punctuation.
- * See class documentation for more explanation.
- * @see #setStrength
- * @see #getStrength
- * @stable ICU 2.4
- */
- public final static int QUATERNARY = CollationAttribute.VALUE_QUATERNARY;
-
- /**
- * <p>
- * Smallest Collator strength value. When all other strengths are equal,
- * the IDENTICAL strength is used as a tiebreaker. The Unicode code point
- * values of the NFD form of each string are compared, just in case there
- * is no difference.
- * See class documentation for more explanation.
- * </p>
- * <p>
- * Note this value is different from JDK's
- * </p>
- * @stable ICU 2.4
- */
- public final static int IDENTICAL = CollationAttribute.VALUE_IDENTICAL;
-
- /**
- * <p>Decomposition mode value. With NO_DECOMPOSITION set, Strings
- * will not be decomposed for collation. This is the default
- * decomposition setting unless otherwise specified by the locale
- * used to create the Collator.</p>
- *
- * <p><strong>Note</strong> this value is different from the JDK's.</p>
- * @see #CANONICAL_DECOMPOSITION
- * @see #getDecomposition
- * @see #setDecomposition
- * @stable ICU 2.4
- */
- public final static int NO_DECOMPOSITION = CollationAttribute.VALUE_OFF;
-
- /**
- * <p>Decomposition mode value. With CANONICAL_DECOMPOSITION set,
- * characters that are canonical variants according to the Unicode standard
- * will be decomposed for collation.</p>
- *
- * <p>CANONICAL_DECOMPOSITION corresponds to Normalization Form D as
- * described in <a href="http://www.unicode.org/unicode/reports/tr15/">
- * Unicode Technical Report #15</a>.
- * </p>
- * @see #NO_DECOMPOSITION
- * @see #getDecomposition
- * @see #setDecomposition
- * @stable ICU 2.4
- */
- public final static int CANONICAL_DECOMPOSITION = CollationAttribute.VALUE_ON;
-
- public static Collator getInstance(Locale locale) {
- return new RuleBasedCollator(locale);
- }
-
- public boolean equals(String source, String target) {
- return (compare(source, target) == 0);
- }
-
- public abstract boolean equals(Object target);
-
- public abstract Object clone() throws CloneNotSupportedException;
-
- /**
- * The comparison function compares the character data stored in two
- * different strings. Returns information about whether a string is less
- * than, greater than or equal to another string.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.getInstance(Locale::US);
- * . myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
- * . // result would be CollationAttribute.VALUE_EQUAL
- * . // ("abc" == "ABC")
- * . // (no primary difference between "abc" and "ABC")
- * . int result = myCollation.compare("abc", "ABC",3);
- * . myCollation.setStrength(CollationAttribute.VALUE_TERTIARY);
- * . // result would be Collation.LESS (abc" &lt;&lt;&lt; "ABC")
- * . // (with tertiary difference between "abc" and "ABC")
- * . int result = myCollation.compare("abc", "ABC",3);
- * </pre>
- * @stable ICU 2.4
- */
- public abstract int compare(String source, String target);
-
- /**
- * Get the decomposition mode of this Collator.
- * @return the decomposition mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public abstract int getDecomposition();
-
- /**
- * Set the normalization mode used int this object
- * The normalization mode influences how strings are compared.
- * @param mode desired normalization mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public abstract void setDecomposition(int mode);
-
- /**
- * Determines the minimum strength that will be use in comparison or
- * transformation.
- * <p>
- * E.g. with strength == SECONDARY, the tertiary difference is ignored
- * </p>
- * <p>
- * E.g. with strength == PRIMARY, the secondary and tertiary difference
- * are ignored.
- * </p>
- * @return the current comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public abstract int getStrength();
-
- /**
- * Gets the attribute to be used in comparison or transformation.
- * @param type the attribute to be set from CollationAttribute
- * @return value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public abstract int getAttribute(int type);
-
- /**
- * Sets the minimum strength to be used in comparison or transformation.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.createInstance(Locale::US);
- * . myCollation.setStrength(PRIMARY);
- * . // result will be "abc" == "ABC"
- * . // tertiary differences will be ignored
- * . int result = myCollation->compare("abc", "ABC");
- * </pre>
- * @param strength the new comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public abstract void setStrength(int strength);
-
- /**
- * Sets the attribute to be used in comparison or transformation.
- * <p>Example of use:
- * <pre>
- * . Collator myCollation = Collator.createInstance(Locale::US);
- * . myCollation.setAttribute(CollationAttribute.CASE_LEVEL,
- * . CollationAttribute.VALUE_ON);
- * . int result = myCollation->compare("\\u30C3\\u30CF",
- * . "\\u30C4\\u30CF");
- * . // result will be -1.
- * </pre>
- * @param type the attribute to be set from CollationAttribute
- * @param value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public abstract void setAttribute(int type, int value);
-
- /**
- * Get the sort key as an CollationKey object from the argument string.
- * To retrieve sort key in terms of byte arrays, use the method as below<br>
- * <code>
- * Collator collator = Collator.getInstance();
- * CollationKey collationKey = collator.getCollationKey("string");
- * byte[] array = collationKey.toByteArray();
- * </code><br>
- * Byte array result are zero-terminated and can be compared using
- * java.util.Arrays.equals();
- * @param source string to be processed.
- * @return the sort key
- * @stable ICU 2.4
- */
- public abstract CollationKey getCollationKey(String source);
-
- /**
- * Returns a hash of this collation object
- * @return hash of this collation object
- * @stable ICU 2.4
- */
- public abstract int hashCode();
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java b/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
deleted file mode 100644
index bbe45af..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/NativeBreakIterator.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.text;
-
-import java.text.CharacterIterator;
-import java.text.StringCharacterIterator;
-import java.util.Locale;
-
-public final class NativeBreakIterator implements Cloneable {
- // Acceptable values for the 'type' field.
- private static final int BI_CHAR_INSTANCE = 1;
- private static final int BI_WORD_INSTANCE = 2;
- private static final int BI_LINE_INSTANCE = 3;
- private static final int BI_SENT_INSTANCE = 4;
-
- private final int addr;
- private final int type;
- private CharacterIterator charIter;
-
- private NativeBreakIterator(int iterAddr, int type) {
- this.addr = iterAddr;
- this.type = type;
- this.charIter = new StringCharacterIterator("");
- }
-
- @Override
- public Object clone() {
- int cloneAddr = cloneImpl(this.addr);
- NativeBreakIterator clone = new NativeBreakIterator(cloneAddr, this.type);
- // The RI doesn't clone the CharacterIterator.
- clone.charIter = this.charIter;
- return clone;
- }
-
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof NativeBreakIterator)) {
- return false;
- }
- // TODO: is this sufficient? shouldn't we be checking the underlying rules?
- NativeBreakIterator rhs = (NativeBreakIterator) object;
- return type == rhs.type && charIter.equals(rhs.charIter);
- }
-
- @Override
- public int hashCode() {
- return 42; // No-one uses BreakIterator as a hash key.
- }
-
- @Override protected void finalize() throws Throwable {
- try {
- closeBreakIteratorImpl(this.addr);
- } finally {
- super.finalize();
- }
- }
-
- public int current() {
- return currentImpl(this.addr);
- }
-
- public int first() {
- return firstImpl(this.addr);
- }
-
- public int following(int offset) {
- return followingImpl(this.addr, offset);
- }
-
- public CharacterIterator getText() {
- int newLoc = currentImpl(this.addr);
- this.charIter.setIndex(newLoc);
- return this.charIter;
- }
-
- public int last() {
- return lastImpl(this.addr);
- }
-
- public int next(int n) {
- return nextImpl(this.addr, n);
- }
-
- public int next() {
- return nextImpl(this.addr, 1);
- }
-
- public int previous() {
- return previousImpl(this.addr);
- }
-
- public void setText(CharacterIterator newText) {
- this.charIter = newText;
- StringBuilder sb = new StringBuilder();
- for (char c = newText.first(); c != CharacterIterator.DONE; c = newText.next()) {
- sb.append(c);
- }
- setTextImpl(this.addr, sb.toString());
- }
-
- public void setText(String newText) {
- setText(new StringCharacterIterator(newText));
- }
-
- public boolean isBoundary(int offset) {
- return isBoundaryImpl(this.addr, offset);
- }
-
- public int preceding(int offset) {
- return precedingImpl(this.addr, offset);
- }
-
- public static NativeBreakIterator getCharacterInstance(Locale where) {
- return new NativeBreakIterator(getCharacterInstanceImpl(where.toString()), BI_CHAR_INSTANCE);
- }
-
- public static NativeBreakIterator getLineInstance(Locale where) {
- return new NativeBreakIterator(getLineInstanceImpl(where.toString()), BI_LINE_INSTANCE);
- }
-
- public static NativeBreakIterator getSentenceInstance(Locale where) {
- return new NativeBreakIterator(getSentenceInstanceImpl(where.toString()), BI_SENT_INSTANCE);
- }
-
- public static NativeBreakIterator getWordInstance(Locale where) {
- return new NativeBreakIterator(getWordInstanceImpl(where.toString()), BI_WORD_INSTANCE);
- }
-
- private static native int getCharacterInstanceImpl(String locale);
- private static native int getWordInstanceImpl(String locale);
- private static native int getLineInstanceImpl(String locale);
- private static native int getSentenceInstanceImpl(String locale);
- private static native void closeBreakIteratorImpl(int addr);
- private static native void setTextImpl(int addr, String text);
- private static native int cloneImpl(int addr);
- private static native int precedingImpl(int addr, int offset);
- private static native boolean isBoundaryImpl(int addr, int offset);
- private static native int nextImpl(int addr, int n);
- private static native int previousImpl(int addr);
- private static native int currentImpl(int addr);
- private static native int firstImpl(int addr);
- private static native int followingImpl(int addr, int offset);
- private static native int lastImpl(int addr);
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/NativeCollation.java b/luni/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
deleted file mode 100644
index 6ff6535..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/NativeCollation.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-/**
-* Package static class for declaring all native methods for collation use.
-* @author syn wee quek
-* @internal ICU 2.4
-*/
-
-final class NativeCollation {
- private NativeCollation() {
- }
-
- /**
- * Method to create a new C Collator using the argument locale rules.
- * @param locale locale name
- * @return new c collator
- * @internal ICU 2.4
- */
- static native int openCollator(String locale);
-
- /**
- * Method to create a new C Collator using the argument rules.
- * @param rules , set of collation rules
- * @param normalizationmode default normalization mode
- * @param collationstrength default collation strength
- * @return new c collator
- * @internal ICU 2.4
- */
- static native int openCollatorFromRules(String rules,
- int normalizationmode,
- int collationstrength);
-
- /**
- * Close a C collator
- * Once closed, a UCollatorOld should not be used.
- * @param collatoraddress The UCollatorOld to close
- * @internal ICU 2.4
- */
- static native void closeCollator(int collatoraddress);
-
- /**
- * Compare two strings.
- * The strings will be compared using the normalization mode and options
- * specified in openCollator or openCollatorFromRules
- * @param collatoraddress address of the c collator
- * @param source The source string.
- * @param target The target string.
- * @return result of the comparison, Collation.EQUAL,
- * Collation.GREATER or Collation.LESS
- * @internal ICU 2.4
- */
- static native int compare(int collatoraddress, String source,
- String target);
-
- /**
- * Get the normalization mode for this object.
- * The normalization mode influences how strings are compared.
- * @param collatoraddress
- * @return normalization mode; one of the values from Normalization
- * @internal ICU 2.4
- */
- static native int getNormalization(int collatoraddress);
-
- /**
- * Set the normalization mode used int this object
- * The normalization mode influences how strings are compared.
- * @param collatoraddress the address of the C collator
- * @param normalizationmode desired normalization mode; one of the values
- * from Normalization
- * @internal ICU 2.4
- */
- static native void setNormalization(int collatoraddress,
- int normalizationmode);
-
- /**
- * Get the collation rules from a UCollator.
- * The rules will follow the rule syntax.
- * @param collatoraddress the address of the C collator
- * @return collation rules.
- * @internal ICU 2.4
- */
- static native String getRules(int collatoraddress);
-
- /**
- * Get a sort key for the argument string
- * Sort keys may be compared using java.util.Arrays.equals
- * @param collatoraddress address of the C collator
- * @param source string for key to be generated
- * @return sort key
- * @internal ICU 2.4
- */
- static native byte[] getSortKey(int collatoraddress, String source);
-
- /**
- * Gets the version information for collation.
- * @param collatoraddress address of the C collator
- * @return version information
- * @internal ICU 2.4
- */
- // private native String getVersion(int collatoraddress);
-
- /**
- * Universal attribute setter.
- * @param collatoraddress address of the C collator
- * @param type type of attribute to be set
- * @param value attribute value
- * @exception RuntimeException when error occurs while setting attribute value
- * @internal ICU 2.4
- */
- static native void setAttribute(int collatoraddress, int type, int value);
-
- /**
- * Universal attribute getter
- * @param collatoraddress address of the C collator
- * @param type type of attribute to be set
- * @return attribute value
- * @exception RuntimeException thrown when error occurs while getting attribute value
- * @internal ICU 2.4
- */
- static native int getAttribute(int collatoraddress, int type);
-
- /**
- * Thread safe cloning operation
- * @param collatoraddress address of C collator to be cloned
- * @return address of the new clone
- * @exception RuntimeException thrown when error occurs while cloning
- * @internal ICU 2.4
- */
- static native int safeClone(int collatoraddress);
-
- /**
- * Create a CollationElementIterator object that will iterator over the
- * elements in a string, using the collation rules defined in this
- * RuleBasedCollator
- * @param collatoraddress address of C collator
- * @param source string to iterate over
- * @return address of C collationelementiterator
- * @internal ICU 2.4
- */
- static native int getCollationElementIterator(int collatoraddress,
- String source);
-
-
- // collationelementiterator methods -------------------------------------
-
- /**
- * Close a C collation element iterator.
- * @param address of C collation element iterator to close.
- * @internal ICU 2.4
- */
- static native void closeElements(int address);
-
- /**
- * Reset the collation elements to their initial state.
- * This will move the 'cursor' to the beginning of the text.
- * @param address of C collation element iterator to reset.
- * @internal ICU 2.4
- */
- static native void reset(int address);
-
- /**
- * Get the ordering priority of the next collation element in the text.
- * A single character may contain more than one collation element.
- * @param address if C collation elements containing the text.
- * @return next collation elements ordering, or NULLORDER if the end of the
- * text is reached.
- * @internal ICU 2.4
- */
- static native int next(int address);
-
- /**
- * Get the ordering priority of the previous collation element in the text.
- * A single character may contain more than one collation element.
- * @param address of the C collation element iterator containing the text.
- * @return previous collation element ordering, or NULLORDER if the end of
- * the text is reached.
- * @internal ICU 2.4
- */
- static native int previous(int address);
-
- /**
- * Get the maximum length of any expansion sequences that end with the
- * specified comparison order.
- * @param address of the C collation element iterator containing the text.
- * @param order collation order returned by previous or next.
- * @return maximum length of any expansion sequences ending with the
- * specified order.
- * @internal ICU 2.4
- */
- static native int getMaxExpansion(int address, int order);
-
- /**
- * Set the text containing the collation elements.
- * @param address of the C collation element iterator to be set
- * @param source text containing the collation elements.
- * @internal ICU 2.4
- */
- static native void setText(int address, String source);
-
- /**
- * Get the offset of the current source character.
- * This is an offset into the text of the character containing the current
- * collation elements.
- * @param address of the C collation elements iterator to query.
- * @return offset of the current source character.
- * @internal ICU 2.4
- */
- static native int getOffset(int address);
-
- /**
- * Set the offset of the current source character.
- * This is an offset into the text of the character to be processed.
- * @param address of the C collation element iterator to set.
- * @param offset The desired character offset.
- * @internal ICU 2.4
- */
- static native void setOffset(int address, int offset);
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java b/luni/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
deleted file mode 100644
index 3138237..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/NativeDecimalFormat.java
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.text;
-
-import com.ibm.icu4jni.util.LocaleData;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.math.RoundingMode;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.text.DecimalFormatSymbols;
-import java.text.FieldPosition;
-import java.text.Format;
-import java.text.NumberFormat;
-import java.text.ParsePosition;
-import java.util.Currency;
-import java.util.NoSuchElementException;
-
-public final class NativeDecimalFormat {
- /**
- * Constants corresponding to the native type UNumberFormatSymbol, for setSymbol.
- */
- private static final int UNUM_DECIMAL_SEPARATOR_SYMBOL = 0;
- private static final int UNUM_GROUPING_SEPARATOR_SYMBOL = 1;
- private static final int UNUM_PATTERN_SEPARATOR_SYMBOL = 2;
- private static final int UNUM_PERCENT_SYMBOL = 3;
- private static final int UNUM_ZERO_DIGIT_SYMBOL = 4;
- private static final int UNUM_DIGIT_SYMBOL = 5;
- private static final int UNUM_MINUS_SIGN_SYMBOL = 6;
- private static final int UNUM_PLUS_SIGN_SYMBOL = 7;
- private static final int UNUM_CURRENCY_SYMBOL = 8;
- private static final int UNUM_INTL_CURRENCY_SYMBOL = 9;
- private static final int UNUM_MONETARY_SEPARATOR_SYMBOL = 10;
- private static final int UNUM_EXPONENTIAL_SYMBOL = 11;
- private static final int UNUM_PERMILL_SYMBOL = 12;
- private static final int UNUM_PAD_ESCAPE_SYMBOL = 13;
- private static final int UNUM_INFINITY_SYMBOL = 14;
- private static final int UNUM_NAN_SYMBOL = 15;
- private static final int UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16;
- private static final int UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17;
- private static final int UNUM_FORMAT_SYMBOL_COUNT = 18;
-
- /**
- * Constants corresponding to the native type UNumberFormatAttribute, for
- * getAttribute/setAttribute.
- */
- private static final int UNUM_PARSE_INT_ONLY = 0;
- private static final int UNUM_GROUPING_USED = 1;
- private static final int UNUM_DECIMAL_ALWAYS_SHOWN = 2;
- private static final int UNUM_MAX_INTEGER_DIGITS = 3;
- private static final int UNUM_MIN_INTEGER_DIGITS = 4;
- private static final int UNUM_INTEGER_DIGITS = 5;
- private static final int UNUM_MAX_FRACTION_DIGITS = 6;
- private static final int UNUM_MIN_FRACTION_DIGITS = 7;
- private static final int UNUM_FRACTION_DIGITS = 8;
- private static final int UNUM_MULTIPLIER = 9;
- private static final int UNUM_GROUPING_SIZE = 10;
- private static final int UNUM_ROUNDING_MODE = 11;
- private static final int UNUM_ROUNDING_INCREMENT = 12;
- private static final int UNUM_FORMAT_WIDTH = 13;
- private static final int UNUM_PADDING_POSITION = 14;
- private static final int UNUM_SECONDARY_GROUPING_SIZE = 15;
- private static final int UNUM_SIGNIFICANT_DIGITS_USED = 16;
- private static final int UNUM_MIN_SIGNIFICANT_DIGITS = 17;
- private static final int UNUM_MAX_SIGNIFICANT_DIGITS = 18;
- private static final int UNUM_LENIENT_PARSE = 19;
-
- /**
- * Constants corresponding to the native type UNumberFormatTextAttribute, for
- * getTextAttribute/setTextAttribute.
- */
- private static final int UNUM_POSITIVE_PREFIX = 0;
- private static final int UNUM_POSITIVE_SUFFIX = 1;
- private static final int UNUM_NEGATIVE_PREFIX = 2;
- private static final int UNUM_NEGATIVE_SUFFIX = 3;
- private static final int UNUM_PADDING_CHARACTER = 4;
- private static final int UNUM_CURRENCY_CODE = 5;
- private static final int UNUM_DEFAULT_RULESET = 6;
- private static final int UNUM_PUBLIC_RULESETS = 7;
-
- /**
- * The address of the ICU DecimalFormat* on the native heap.
- */
- private int addr;
-
- /**
- * The last pattern we gave to ICU, so we can make repeated applications cheap.
- * This helps in cases like String.format("%.2f,%.2f\n", x, y) where the DecimalFormat is
- * reused.
- */
- private String lastPattern;
-
- // TODO: store all these in DecimalFormat instead!
- private boolean negPrefNull;
- private boolean negSuffNull;
- private boolean posPrefNull;
- private boolean posSuffNull;
-
- private transient boolean parseBigDecimal;
-
- /**
- * Cache the BigDecimal form of the multiplier. This is null until we've
- * formatted a BigDecimal (with a multiplier that is not 1), or the user has
- * explicitly called {@link #setMultiplier(int)} with any multiplier.
- */
- private BigDecimal multiplierBigDecimal = null;
-
- public NativeDecimalFormat(String pattern, DecimalFormatSymbols dfs) {
- try {
- this.addr = open(pattern, dfs.getCurrencySymbol(),
- dfs.getDecimalSeparator(), dfs.getDigit(), dfs.getExponentSeparator(),
- dfs.getGroupingSeparator(), dfs.getInfinity(),
- dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
- dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
- this.lastPattern = pattern;
- } catch (NullPointerException npe) {
- throw npe;
- } catch (RuntimeException re) {
- throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
- }
- }
-
- // Used so java.util.Formatter doesn't need to allocate DecimalFormatSymbols instances.
- public NativeDecimalFormat(String pattern, LocaleData data) {
- this.addr = open(pattern, data.currencySymbol,
- data.decimalSeparator, data.digit, data.exponentSeparator, data.groupingSeparator,
- data.infinity, data.internationalCurrencySymbol, data.minusSign,
- data.monetarySeparator, data.NaN, data.patternSeparator,
- data.percent, data.perMill, data.zeroDigit);
- this.lastPattern = pattern;
- }
-
- // Used to implement clone.
- private NativeDecimalFormat(NativeDecimalFormat other) {
- this.addr = cloneImpl(other.addr);
- this.lastPattern = other.lastPattern;
- this.negPrefNull = other.negPrefNull;
- this.negSuffNull = other.negSuffNull;
- this.posPrefNull = other.posPrefNull;
- this.posSuffNull = other.posSuffNull;
- }
-
- // TODO: remove this and just have DecimalFormat.hashCode do the right thing itself.
- @Override
- public int hashCode() {
- return this.getPositivePrefix().hashCode();
- }
-
- public synchronized void close() {
- if (addr != 0) {
- close(addr);
- addr = 0;
- }
- }
-
- @Override
- public Object clone() {
- return new NativeDecimalFormat(this);
- }
-
- /**
- * Note: this doesn't check that the underlying native DecimalFormat objects' configured
- * native DecimalFormatSymbols objects are equal. It is assumed that the
- * caller (DecimalFormat) will check the DecimalFormatSymbols objects
- * instead, for performance.
- *
- * This is also unreasonably expensive, calling down to JNI multiple times.
- *
- * TODO: remove this and just have DecimalFormat.equals do the right thing itself.
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof NativeDecimalFormat)) {
- return false;
- }
- NativeDecimalFormat obj = (NativeDecimalFormat) object;
- if (obj.addr == this.addr) {
- return true;
- }
- return obj.toPattern().equals(this.toPattern()) &&
- obj.isDecimalSeparatorAlwaysShown() == this.isDecimalSeparatorAlwaysShown() &&
- obj.getGroupingSize() == this.getGroupingSize() &&
- obj.getMultiplier() == this.getMultiplier() &&
- obj.getNegativePrefix().equals(this.getNegativePrefix()) &&
- obj.getNegativeSuffix().equals(this.getNegativeSuffix()) &&
- obj.getPositivePrefix().equals(this.getPositivePrefix()) &&
- obj.getPositiveSuffix().equals(this.getPositiveSuffix()) &&
- obj.getMaximumIntegerDigits() == this.getMaximumIntegerDigits() &&
- obj.getMaximumFractionDigits() == this.getMaximumFractionDigits() &&
- obj.getMinimumIntegerDigits() == this.getMinimumIntegerDigits() &&
- obj.getMinimumFractionDigits() == this.getMinimumFractionDigits() &&
- obj.isGroupingUsed() == this.isGroupingUsed();
- }
-
- /**
- * Copies the DecimalFormatSymbols settings into our native peer in bulk.
- */
- public void setDecimalFormatSymbols(final DecimalFormatSymbols dfs) {
- setDecimalFormatSymbols(this.addr, dfs.getCurrencySymbol(), dfs.getDecimalSeparator(),
- dfs.getDigit(), dfs.getExponentSeparator(), dfs.getGroupingSeparator(),
- dfs.getInfinity(), dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
- dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
- dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
- }
-
- public void setDecimalFormatSymbols(final LocaleData localeData) {
- setDecimalFormatSymbols(this.addr, localeData.currencySymbol, localeData.decimalSeparator,
- localeData.digit, localeData.exponentSeparator, localeData.groupingSeparator,
- localeData.infinity, localeData.internationalCurrencySymbol, localeData.minusSign,
- localeData.monetarySeparator, localeData.NaN, localeData.patternSeparator,
- localeData.percent, localeData.perMill, localeData.zeroDigit);
- }
-
- public char[] formatBigDecimal(BigDecimal value, FieldPosition field) {
- FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
- char[] result = formatDigitList(this.addr, value.toString(), fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
- }
- return result;
- }
-
- public char[] formatBigInteger(BigInteger value, FieldPosition field) {
- FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
- char[] result = formatDigitList(this.addr, value.toString(10), fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
- }
- return result;
- }
-
- public char[] formatLong(long value, FieldPosition field) {
- FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
- char[] result = formatLong(this.addr, value, fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
- }
- return result;
- }
-
- public char[] formatDouble(double value, FieldPosition field) {
- FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
- char[] result = formatDouble(this.addr, value, fpi);
- if (fpi != null) {
- FieldPositionIterator.setFieldPosition(fpi, field);
- }
- return result;
- }
-
- public void applyLocalizedPattern(String pattern) {
- applyPattern(this.addr, true, pattern);
- lastPattern = null;
- }
-
- public void applyPattern(String pattern) {
- if (lastPattern != null && pattern.equals(lastPattern)) {
- return;
- }
- applyPattern(this.addr, false, pattern);
- lastPattern = pattern;
- }
-
- public AttributedCharacterIterator formatToCharacterIterator(Object object) {
- if (!(object instanceof Number)) {
- throw new IllegalArgumentException();
- }
- Number number = (Number) object;
- FieldPositionIterator fpIter = new FieldPositionIterator();
- String text;
- if (number instanceof BigInteger || number instanceof BigDecimal) {
- text = new String(formatDigitList(this.addr, number.toString(), fpIter));
- } else if (number instanceof Double || number instanceof Float) {
- double dv = number.doubleValue();
- text = new String(formatDouble(this.addr, dv, fpIter));
- } else {
- long lv = number.longValue();
- text = new String(formatLong(this.addr, lv, fpIter));
- }
-
- AttributedString as = new AttributedString(text);
-
- while (fpIter.next()) {
- Format.Field field = fpIter.field();
- as.addAttribute(field, field, fpIter.start(), fpIter.limit());
- }
-
- // return the CharacterIterator from AttributedString
- return as.getIterator();
- }
-
- private int makeScalePositive(int scale, StringBuilder val) {
- if (scale < 0) {
- scale = -scale;
- for (int i = scale; i > 0; i--) {
- val.append('0');
- }
- scale = 0;
- }
- return scale;
- }
-
- public String toLocalizedPattern() {
- return toPatternImpl(this.addr, true);
- }
-
- public String toPattern() {
- return toPatternImpl(this.addr, false);
- }
-
- public Number parse(String string, ParsePosition position) {
- return parse(addr, string, position, parseBigDecimal);
- }
-
- // start getter and setter
-
- public int getMaximumFractionDigits() {
- return getAttribute(this.addr, UNUM_MAX_FRACTION_DIGITS);
- }
-
- public int getMaximumIntegerDigits() {
- return getAttribute(this.addr, UNUM_MAX_INTEGER_DIGITS);
- }
-
- public int getMinimumFractionDigits() {
- return getAttribute(this.addr, UNUM_MIN_FRACTION_DIGITS);
- }
-
- public int getMinimumIntegerDigits() {
- return getAttribute(this.addr, UNUM_MIN_INTEGER_DIGITS);
- }
-
- public int getGroupingSize() {
- return getAttribute(this.addr, UNUM_GROUPING_SIZE);
- }
-
- public int getMultiplier() {
- return getAttribute(this.addr, UNUM_MULTIPLIER);
- }
-
- public String getNegativePrefix() {
- if (negPrefNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_NEGATIVE_PREFIX);
- }
-
- public String getNegativeSuffix() {
- if (negSuffNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_NEGATIVE_SUFFIX);
- }
-
- public String getPositivePrefix() {
- if (posPrefNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_POSITIVE_PREFIX);
- }
-
- public String getPositiveSuffix() {
- if (posSuffNull) {
- return null;
- }
- return getTextAttribute(this.addr, UNUM_POSITIVE_SUFFIX);
- }
-
- public boolean isDecimalSeparatorAlwaysShown() {
- return getAttribute(this.addr, UNUM_DECIMAL_ALWAYS_SHOWN) != 0;
- }
-
- public boolean isParseBigDecimal() {
- return parseBigDecimal;
- }
-
- public boolean isParseIntegerOnly() {
- return getAttribute(this.addr, UNUM_PARSE_INT_ONLY) != 0;
- }
-
- public boolean isGroupingUsed() {
- return getAttribute(this.addr, UNUM_GROUPING_USED) != 0;
- }
-
- public void setDecimalSeparatorAlwaysShown(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_DECIMAL_ALWAYS_SHOWN, i);
- }
-
- public void setCurrency(Currency currency) {
- setSymbol(this.addr, UNUM_CURRENCY_SYMBOL, currency.getSymbol());
- setSymbol(this.addr, UNUM_INTL_CURRENCY_SYMBOL, currency.getCurrencyCode());
- }
-
- public void setGroupingSize(int value) {
- setAttribute(this.addr, UNUM_GROUPING_SIZE, value);
- }
-
- public void setGroupingUsed(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_GROUPING_USED, i);
- }
-
- public void setMaximumFractionDigits(int value) {
- setAttribute(this.addr, UNUM_MAX_FRACTION_DIGITS, value);
- }
-
- public void setMaximumIntegerDigits(int value) {
- setAttribute(this.addr, UNUM_MAX_INTEGER_DIGITS, value);
- }
-
- public void setMinimumFractionDigits(int value) {
- setAttribute(this.addr, UNUM_MIN_FRACTION_DIGITS, value);
- }
-
- public void setMinimumIntegerDigits(int value) {
- setAttribute(this.addr, UNUM_MIN_INTEGER_DIGITS, value);
- }
-
- public void setMultiplier(int value) {
- setAttribute(this.addr, UNUM_MULTIPLIER, value);
- // Update the cached BigDecimal for multiplier.
- multiplierBigDecimal = BigDecimal.valueOf(value);
- }
-
- public void setNegativePrefix(String value) {
- negPrefNull = value == null;
- if (!negPrefNull) {
- setTextAttribute(this.addr, UNUM_NEGATIVE_PREFIX, value);
- }
- }
-
- public void setNegativeSuffix(String value) {
- negSuffNull = value == null;
- if (!negSuffNull) {
- setTextAttribute(this.addr, UNUM_NEGATIVE_SUFFIX, value);
- }
- }
-
- public void setPositivePrefix(String value) {
- posPrefNull = value == null;
- if (!posPrefNull) {
- setTextAttribute(this.addr, UNUM_POSITIVE_PREFIX, value);
- }
- }
-
- public void setPositiveSuffix(String value) {
- posSuffNull = value == null;
- if (!posSuffNull) {
- setTextAttribute(this.addr, UNUM_POSITIVE_SUFFIX, value);
- }
- }
-
- public void setParseBigDecimal(boolean value) {
- parseBigDecimal = value;
- }
-
- public void setParseIntegerOnly(boolean value) {
- int i = value ? -1 : 0;
- setAttribute(this.addr, UNUM_PARSE_INT_ONLY, i);
- }
-
- private static void applyPattern(int addr, boolean localized, String pattern) {
- try {
- applyPatternImpl(addr, localized, pattern);
- } catch (NullPointerException npe) {
- throw npe;
- } catch (RuntimeException re) {
- throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
- }
- }
-
- public void setRoundingMode(RoundingMode roundingMode, double roundingIncrement) {
- final int nativeRoundingMode;
- switch (roundingMode) {
- case CEILING: nativeRoundingMode = 0; break;
- case FLOOR: nativeRoundingMode = 1; break;
- case DOWN: nativeRoundingMode = 2; break;
- case UP: nativeRoundingMode = 3; break;
- case HALF_EVEN: nativeRoundingMode = 4; break;
- case HALF_DOWN: nativeRoundingMode = 5; break;
- case HALF_UP: nativeRoundingMode = 6; break;
- default: throw new AssertionError();
- }
- setRoundingMode(addr, nativeRoundingMode, roundingIncrement);
- }
-
- // Utility to get information about field positions from native (ICU) code.
- private static class FieldPositionIterator {
- private int[] data;
- private int pos = -3; // so first call to next() leaves pos at 0
-
- private FieldPositionIterator() {
- }
-
- public static FieldPositionIterator forFieldPosition(FieldPosition fp) {
- if (fp != null && fp.getField() != -1) {
- return new FieldPositionIterator();
- }
- return null;
- }
-
- private static int getNativeFieldPositionId(FieldPosition fp) {
- // NOTE: -1, 0, and 1 were the only valid original java field values
- // for NumberFormat. They take precedence. This assumes any other
- // value is a mistake and the actual value is in the attribute.
- // Clients can construct FieldPosition combining any attribute with any field
- // value, which is just wrong, but there you go.
-
- int id = fp.getField();
- if (id < -1 || id > 1) {
- id = -1;
- }
- if (id == -1) {
- Format.Field attr = fp.getFieldAttribute();
- if (attr != null) {
- for (int i = 0; i < fields.length; ++i) {
- if (fields[i].equals(attr)) {
- id = i;
- break;
- }
- }
- }
- }
- return id;
- }
-
- private static void setFieldPosition(FieldPositionIterator fpi, FieldPosition fp) {
- if (fpi != null && fp != null) {
- int field = getNativeFieldPositionId(fp);
- if (field != -1) {
- while (fpi.next()) {
- if (fpi.fieldId() == field) {
- fp.setBeginIndex(fpi.start());
- fp.setEndIndex(fpi.limit());
- break;
- }
- }
- }
- }
- }
-
- public boolean next() {
- // if pos == data.length, we've already returned false once
- if (data == null || pos == data.length) {
- throw new NoSuchElementException();
- }
- pos += 3;
- return pos < data.length;
- }
-
- private void checkValid() {
- if (data == null || pos < 0 || pos == data.length) {
- throw new NoSuchElementException();
- }
- }
-
- public int fieldId() {
- return data[pos];
- }
-
- public Format.Field field() {
- checkValid();
- return fields[data[pos]];
- }
-
- public int start() {
- checkValid();
- return data[pos + 1];
- }
-
- public int limit() {
- checkValid();
- return data[pos + 2];
- }
-
- private static Format.Field fields[] = {
- // The old java field values were 0 for integer and 1 for fraction.
- // The new java field attributes are all objects. ICU assigns the values
- // starting from 0 in the following order; note that integer and
- // fraction positions match the old field values.
- NumberFormat.Field.INTEGER,
- NumberFormat.Field.FRACTION,
- NumberFormat.Field.DECIMAL_SEPARATOR,
- NumberFormat.Field.EXPONENT_SYMBOL,
- NumberFormat.Field.EXPONENT_SIGN,
- NumberFormat.Field.EXPONENT,
- NumberFormat.Field.GROUPING_SEPARATOR,
- NumberFormat.Field.CURRENCY,
- NumberFormat.Field.PERCENT,
- NumberFormat.Field.PERMILLE,
- NumberFormat.Field.SIGN,
- };
-
- // called by native
- private void setData(int[] data) {
- this.data = data;
- this.pos = -3;
- }
- }
-
- private static native void applyPatternImpl(int addr, boolean localized, String pattern);
- private static native int cloneImpl(int addr);
- private static native void close(int addr);
- private static native char[] formatLong(int addr, long value, FieldPositionIterator iter);
- private static native char[] formatDouble(int addr, double value, FieldPositionIterator iter);
- private static native char[] formatDigitList(int addr, String value, FieldPositionIterator iter);
- private static native int getAttribute(int addr, int symbol);
- private static native String getTextAttribute(int addr, int symbol);
- private static native int open(String pattern, String currencySymbol,
- char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
- String infinity, String internationalCurrencySymbol, char minusSign,
- char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
- char perMill, char zeroDigit);
- private static native Number parse(int addr, String string, ParsePosition position, boolean parseBigDecimal);
- private static native void setDecimalFormatSymbols(int addr, String currencySymbol,
- char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
- String infinity, String internationalCurrencySymbol, char minusSign,
- char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
- char perMill, char zeroDigit);
- private static native void setSymbol(int addr, int symbol, String str);
- private static native void setAttribute(int addr, int symbol, int i);
- private static native void setRoundingMode(int addr, int roundingMode, double roundingIncrement);
- private static native void setTextAttribute(int addr, int symbol, String str);
- private static native String toPatternImpl(int addr, boolean localized);
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java b/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
deleted file mode 100644
index b2397bf..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/text/RuleBasedCollator.java
+++ /dev/null
@@ -1,546 +0,0 @@
-/**
-*******************************************************************************
-* Copyright (C) 1996-2005, International Business Machines Corporation and *
-* others. All Rights Reserved. *
-*******************************************************************************
-*
-*
-*******************************************************************************
-*/
-
-package com.ibm.icu4jni.text;
-
-import java.text.CharacterIterator;
-import java.text.ParseException;
-import java.util.Locale;
-
-/**
-* Concrete implementation class for Collation.
-* <p>
-* The collation table is composed of a list of collation rules, where each
-* rule is of three forms:
-* <pre>
-* < modifier >
-* < relation > < text-argument >
-* < reset > < text-argument >
-* </pre>
-* <p>
-* <code>RuleBasedCollator</code> has the following restrictions for efficiency
-* (other subclasses may be used for more complex languages) :
-* <ol>
-* <li> If a French secondary ordering is specified it applies to the whole
-* collator object.
-* <li> All non-mentioned Unicode characters are at the end of the collation
-* order.
-* <li> If a character is not located in the RuleBasedCollator, the default
-* Unicode Collation Algorithm (UCA) rule-based table is automatically
-* searched as a backup.
-* </ol>
-*
-* The following demonstrates how to create your own collation rules:
-* <UL Type=disc>
-* <LI><strong>Text-Argument</strong>: A text-argument is any sequence of
-* characters, excluding special characters (that is, common whitespace
-* characters [0009-000D, 0020] and rule syntax characters [0021-002F,
-* 003A-0040, 005B-0060, 007B-007E]). If those characters are desired,
-* you can put them in single quotes (e.g. ampersand => '&'). Note that
-* unquoted white space characters are ignored; e.g. <code>b c</code> is
-* treated as <code>bc</code>.
-* <LI><strong>Modifier</strong>: There is a single modifier which is used
-* to specify that all accents (secondary differences) are backwards.
-* <p>'@' : Indicates that accents are sorted backwards, as in French.
-* <LI><strong>Relation</strong>: The relations are the following:
-* <UL Type=square>
-* <LI>'<' : Greater, as a letter difference (primary)
-* <LI>';' : Greater, as an accent difference (secondary)
-* <LI>',' : Greater, as a case difference (tertiary)
-* <LI>'=' : Equal
-* </UL>
-* <LI><strong>Reset</strong>: There is a single reset which is used
-* primarily for contractions and expansions, but which can also be used
-* to add a modification at the end of a set of rules.
-* <p>'&' : Indicates that the next rule follows the position to where
-* the reset text-argument would be sorted.
-* </UL>
-*
-* <p>
-* This sounds more complicated than it is in practice. For example, the
-* following are equivalent ways of expressing the same thing:
-* <blockquote>
-* <pre>
-* a < b < c
-* a < b & b < c
-* a < c & a < b
-* </pre>
-* </blockquote>
-* Notice that the order is important, as the subsequent item goes immediately
-* after the text-argument. The following are not equivalent:
-* <blockquote>
-* <pre>
-* a < b & a < c
-* a < c & a < b
-* </pre>
-* </blockquote>
-* Either the text-argument must already be present in the sequence, or some
-* initial substring of the text-argument must be present. (e.g. "a < b & ae <
-* e" is valid since "a" is present in the sequence before "ae" is reset). In
-* this latter case, "ae" is not entered and treated as a single character;
-* instead, "e" is sorted as if it were expanded to two characters: "a"
-* followed by an "e". This difference appears in natural languages: in
-* traditional Spanish "ch" is treated as though it contracts to a single
-* character (expressed as "c < ch < d"), while in traditional German a-umlaut
-* is treated as though it expanded to two characters (expressed as "a,A < b,B
-* ... & ae;? & AE;?"). [? and ? are, of course, the escape sequences for
-* a-umlaut.]
-* <p>
-* <strong>Ignorable Characters</strong>
-* <p>
-* For ignorable characters, the first rule must start with a relation (the
-* examples we have used above are really fragments; "a < b" really should be
-* "< a < b"). If, however, the first relation is not "<", then all the all
-* text-arguments up to the first "<" are ignorable. For example, ", - < a < b"
-* makes "-" an ignorable character, as we saw earlier in the word
-* "black-birds". In the samples for different languages, you see that most
-* accents are ignorable.
-*
-* <p><strong>Normalization and Accents</strong>
-* <p>
-* <code>RuleBasedCollator</code> automatically processes its rule table to
-* include both pre-composed and combining-character versions of accented
-* characters. Even if the provided rule string contains only base characters
-* and separate combining accent characters, the pre-composed accented
-* characters matching all canonical combinations of characters from the rule
-* string will be entered in the table.
-* <p>
-* This allows you to use a RuleBasedCollator to compare accented strings even
-* when the collator is set to NO_DECOMPOSITION. However, if the strings to be
-* collated contain combining sequences that may not be in canonical order, you
-* should set the collator to CANONICAL_DECOMPOSITION to enable sorting of
-* combining sequences.
-* For more information, see
-* <A HREF="http://www.aw.com/devpress">The Unicode Standard, Version 3.0</A>.)
-*
-* <p><strong>Errors</strong>
-* <p>
-* The following are errors:
-* <UL Type=disc>
-* <LI>A text-argument contains unquoted punctuation symbols
-* (e.g. "a < b-c < d").
-* <LI>A relation or reset character not followed by a text-argument
-* (e.g. "a < , b").
-* <LI>A reset where the text-argument (or an initial substring of the
-* text-argument) is not already in the sequence or allocated in the
-* default UCA table.
-* (e.g. "a < b & e < f")
-* </UL>
-* If you produce one of these errors, a <code>RuleBasedCollator</code> throws
-* a <code>ParseException</code>.
-*
-* <p><strong>Examples</strong>
-* <p>Simple: "< a < b < c < d"
-* <p>Norwegian: "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J
-* < k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T
-* < u,U< v,V< w,W< x,X< y,Y< z,Z
-* < ?=a?,?=A?
-* ;aa,AA< ?,?< ?,?"
-*
-* <p>
-* Normally, to create a rule-based Collator object, you will use
-* <code>Collator</code>'s factory method <code>getInstance</code>.
-* However, to create a rule-based Collator object with specialized rules
-* tailored to your needs, you construct the <code>RuleBasedCollator</code>
-* with the rules contained in a <code>String</code> object. For example:
-* <blockquote>
-* <pre>
-* String Simple = "< a < b < c < d";
-* RuleBasedCollator mySimple = new RuleBasedCollator(Simple);
-* </pre>
-* </blockquote>
-* Or:
-* <blockquote>
-* <pre>
-* String Norwegian = "< a,A< b,B< c,C< d,D< e,E< f,F< g,G< h,H< i,I< j,J" +
-* "< k,K< l,L< m,M< n,N< o,O< p,P< q,Q< r,R< s,S< t,T" +
-* "< u,U< v,V< w,W< x,X< y,Y< z,Z" +
-* "< ?=a?,?=A?" +
-* ";aa,AA< ?,?< ?,?";
-* RuleBasedCollator myNorwegian = new RuleBasedCollator(Norwegian);
-* </pre>
-* </blockquote>
-*
-* <p>
-* Combining <code>Collator</code>s is as simple as concatenating strings.
-* Here's an example that combines two <code>Collator</code>s from two
-* different locales:
-* <blockquote>
-* <pre>
-* // Create an en_US Collator object
-* RuleBasedCollator en_USCollator = (RuleBasedCollator)
-* Collator.getInstance(new Locale("en", "US", ""));
-* // Create a da_DK Collator object
-* RuleBasedCollator da_DKCollator = (RuleBasedCollator)
-* Collator.getInstance(new Locale("da", "DK", ""));
-* // Combine the two
-* // First, get the collation rules from en_USCollator
-* String en_USRules = en_USCollator.getRules();
-* // Second, get the collation rules from da_DKCollator
-* String da_DKRules = da_DKCollator.getRules();
-* RuleBasedCollator newCollator =
-* new RuleBasedCollator(en_USRules + da_DKRules);
-* // newCollator has the combined rules
-* </pre>
-* </blockquote>
-*
-* <p>
-* Another more interesting example would be to make changes on an existing
-* table to create a new <code>Collator</code> object. For example, add
-* "& C < ch, cH, Ch, CH" to the <code>en_USCollator</code> object to create
-* your own:
-* <blockquote>
-* <pre>
-* // Create a new Collator object with additional rules
-* String addRules = "& C < ch, cH, Ch, CH";
-* RuleBasedCollator myCollator =
-* new RuleBasedCollator(en_USCollator + addRules);
-* // myCollator contains the new rules
-* </pre>
-* </blockquote>
-*
-* <p>
-* The following example demonstrates how to change the order of
-* non-spacing accents,
-* <blockquote>
-* <pre>
-* // old rule
-* String oldRules = "=?;?;?" // main accents Diaeresis 00A8, Macron 00AF
-* // Acute 00BF
-* + "< a , A ; ae, AE ; ? , ?"
-* + "< b , B < c, C < e, E & C < d, D";
-* // change the order of accent characters
-* String addOn = "& ?;?;?;"; // Acute 00BF, Macron 00AF, Diaeresis 00A8
-* RuleBasedCollator myCollator = new RuleBasedCollator(oldRules + addOn);
-* </pre>
-* </blockquote>
-*
-* <p>
-* The last example shows how to put new primary ordering in before the
-* default setting. For example, in Japanese <code>Collator</code>, you
-* can either sort English characters before or after Japanese characters,
-* <blockquote>
-* <pre>
-* // get en_US Collator rules
-* RuleBasedCollator en_USCollator =
-* (RuleBasedCollator)Collator.getInstance(Locale.US);
-* // add a few Japanese character to sort before English characters
-* // suppose the last character before the first base letter 'a' in
-* // the English collation rule is ?
-* String jaString = "& \\u30A2 , \\u30FC < \\u30C8";
-* RuleBasedCollator myJapaneseCollator = new
-* RuleBasedCollator(en_USCollator.getRules() + jaString);
-* </pre>
-* </blockquote>
-* <P>
-* @author syn wee quek
-* @stable ICU 2.4
-*/
-public final class RuleBasedCollator extends Collator {
- private int m_collator_;
- private int m_hashcode_ = 0;
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * @param rules the collation rules to build the collation table from.
- * @exception ParseException thrown if rules are empty or a Runtime error
- * if collator can not be created.
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules) throws ParseException {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules,
- CollationAttribute.VALUE_OFF, CollationAttribute.VALUE_DEFAULT_STRENGTH);
- }
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * @param rules the collation rules to build the collation table from.
- * @param strength collation strength
- * @exception ParseException thrown if rules are empty or a Runtime error
- * if collator can not be created.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules, int strength) throws ParseException {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules, CollationAttribute.VALUE_OFF, strength);
- }
-
- /**
- * RuleBasedCollator constructor. This takes the table rules and builds a
- * collation table out of them. Please see RuleBasedCollator class
- * description for more details on the collation rule syntax.
- * <p>Note API change starting from release 2.4. Prior to release 2.4, the
- * normalizationMode argument values are from the class
- * com.ibm.icu4jni.text.Normalization. In 2.4,
- * the valid normalizationMode arguments for this API are
- * CollationAttribute.VALUE_ON and CollationAttribute.VALUE_OFF.
- * </p>
- * @param rules the collation rules to build the collation table from.
- * @param strength collation strength
- * @param normalizationMode normalization mode
- * @exception IllegalArgumentException thrown when constructor error occurs
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public RuleBasedCollator(String rules, int normalizationMode, int strength) {
- if (rules == null) {
- throw new NullPointerException();
- }
- m_collator_ = NativeCollation.openCollatorFromRules(rules, normalizationMode, strength);
- }
-
- /**
- * Makes a complete copy of the current object.
- * @return a copy of this object if data clone is a success, otherwise null
- * @stable ICU 2.4
- */
- public Object clone() {
- RuleBasedCollator result = null;
- int collatoraddress = NativeCollation.safeClone(m_collator_);
- result = new RuleBasedCollator(collatoraddress);
- return (Collator)result;
- }
-
- /**
- * The comparison function compares the character data stored in two
- * different strings. Returns information about whether a string is less
- * than, greater than or equal to another string.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setStrength(CollationAttribute.VALUE_PRIMARY);
- * // result would be 0 ("abc" == "ABC")
- * // (no primary difference between "abc" and "ABC")
- * int result = myCollation.compare("abc", "ABC",3);
- * myCollation.setStrength(CollationAttribute.VALUE_TERTIARY);
- * // result would be -1 (abc" &lt;&lt;&lt; "ABC")
- * // (with tertiary difference between "abc" and "ABC")
- * int result = myCollation.compare("abc", "ABC",3);
- * </code>
- */
- public int compare(String source, String target) {
- return NativeCollation.compare(m_collator_, source, target);
- }
-
- /**
- * Get the normalization mode for this object.
- * The normalization mode influences how strings are compared.
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public int getDecomposition() {
- return NativeCollation.getNormalization(m_collator_);
- }
-
- /**
- * <p>Sets the decomposition mode of the Collator object on or off.
- * If the decomposition mode is set to on, string would be decomposed into
- * NFD format where necessary before sorting.</p>
- * </p>
- * @param decompositionmode the new decomposition mode
- * @see #CANONICAL_DECOMPOSITION
- * @see #NO_DECOMPOSITION
- * @stable ICU 2.4
- */
- public void setDecomposition(int decompositionmode) {
- NativeCollation.setAttribute(m_collator_,
- CollationAttribute.NORMALIZATION_MODE, decompositionmode);
- }
-
- /**
- * Determines the minimum strength that will be use in comparison or
- * transformation.
- * <p>
- * E.g. with strength == CollationAttribute.VALUE_SECONDARY, the tertiary difference
- * is ignored
- * </p>
- * <p>
- * E.g. with strength == PRIMARY, the secondary and tertiary difference are
- * ignored.
- * </p>
- * @return the current comparison level.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public int getStrength() {
- return NativeCollation.getAttribute(m_collator_, CollationAttribute.STRENGTH);
- }
-
- /**
- * Sets the minimum strength to be used in comparison or transformation.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setStrength(PRIMARY);
- * // result will be "abc" == "ABC"
- * // tertiary differences will be ignored
- * int result = myCollation->compare("abc", "ABC");
- * </code>
- * @param strength the new comparison level.
- * @exception IllegalArgumentException when argument does not belong to any collation strength
- * mode or error occurs while setting data.
- * @see #PRIMARY
- * @see #SECONDARY
- * @see #TERTIARY
- * @see #QUATERNARY
- * @see #IDENTICAL
- * @stable ICU 2.4
- */
- public void setStrength(int strength) {
- NativeCollation.setAttribute(m_collator_, CollationAttribute.STRENGTH, strength);
- }
-
- /**
- * Sets the attribute to be used in comparison or transformation.
- * <p>Example of use:
- * <br>
- * <code>
- * Collator myCollation = Collator.createInstance(Locale::US);
- * myCollation.setAttribute(CollationAttribute.CASE_LEVEL,
- * CollationAttribute.VALUE_ON);
- * int result = myCollation->compare("\\u30C3\\u30CF",
- * "\\u30C4\\u30CF");
- * // result will be -1
- * </code>
- * @param type the attribute to be set from CollationAttribute
- * @param value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public void setAttribute(int type, int value) {
- NativeCollation.setAttribute(m_collator_, type, value);
- }
-
- /**
- * Gets the attribute to be used in comparison or transformation.
- * @param type the attribute to be set from CollationAttribute
- * @return value attribute value from CollationAttribute
- * @stable ICU 2.4
- */
- public int getAttribute(int type) {
- return NativeCollation.getAttribute(m_collator_, type);
- }
-
- public CollationKey getCollationKey(String source) {
- if (source == null) {
- return null;
- }
- byte[] key = NativeCollation.getSortKey(m_collator_, source);
- if (key == null) {
- return null;
- }
- return new CollationKey(source, key);
- }
-
- /**
- * Get the collation rules of this Collation object
- * The rules will follow the rule syntax.
- * @return collation rules.
- * @stable ICU 2.4
- */
- public String getRules() {
- return NativeCollation.getRules(m_collator_);
- }
-
- /**
- * Create a CollationElementIterator object that will iterator over the
- * elements in a string, using the collation rules defined in this
- * RuleBasedCollator
- * @param source string to iterate over
- * @return address of C collationelement
- * @exception IllegalArgumentException thrown when error occurs
- * @stable ICU 2.4
- */
- public CollationElementIterator getCollationElementIterator(String source) {
- CollationElementIterator result = new CollationElementIterator(
- NativeCollation.getCollationElementIterator(m_collator_, source));
- // result.setOwnCollationElementIterator(true);
- return result;
- }
-
- public CollationElementIterator getCollationElementIterator(CharacterIterator it) {
- // We only implement the String-based API, so build a string from the iterator.
- return getCollationElementIterator(characterIteratorToString(it));
- }
-
- private String characterIteratorToString(CharacterIterator it) {
- StringBuilder result = new StringBuilder();
- for (char ch = it.current(); ch != CharacterIterator.DONE; ch = it.next()) {
- result.append(ch);
- }
- return result.toString();
- }
-
- @Override
- public int hashCode() {
- return 42; // No-one uses RuleBasedCollator as a hash key.
- }
-
- /**
- * Checks if argument object is equals to this object.
- * @param target object
- * @return true if source is equivalent to target, false otherwise
- * @stable ICU 2.4
- */
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof RuleBasedCollator)) {
- return false;
- }
- RuleBasedCollator rhs = (RuleBasedCollator) object;
- return getRules().equals(rhs.getRules()) &&
- getStrength() == rhs.getStrength() &&
- getDecomposition() == rhs.getDecomposition();
- }
-
- RuleBasedCollator(Locale locale) {
- m_collator_ = NativeCollation.openCollator(locale.toString());
- }
-
- @Override protected void finalize() throws Throwable {
- try {
- NativeCollation.closeCollator(m_collator_);
- } finally {
- super.finalize();
- }
- }
-
- private RuleBasedCollator(int addr) {
- m_collator_ = addr;
- }
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/util/ICU.java b/luni/src/main/java/com/ibm/icu4jni/util/ICU.java
deleted file mode 100644
index 78e9a1f..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/util/ICU.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.util;
-
-import java.util.Locale;
-
-/**
- * Makes ICU data accessible to Java.
- */
-public final class ICU {
- /**
- * Cache for ISO language names.
- */
- private static String[] isoLanguages;
-
- /**
- * Cache for ISO country names.
- */
- private static String[] isoCountries;
-
- /**
- * Returns an array of ISO language names (two-letter codes), fetched either
- * from ICU's database or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getISOLanguages() {
- if (isoLanguages == null) {
- isoLanguages = getISOLanguagesNative();
- }
- return isoLanguages.clone();
- }
-
- /**
- * Returns an array of ISO country names (two-letter codes), fetched either
- * from ICU's database or from our memory cache.
- *
- * @return The array.
- */
- public static String[] getISOCountries() {
- if (isoCountries == null) {
- isoCountries = getISOCountriesNative();
- }
- return isoCountries.clone();
- }
-
- /**
- * Returns the appropriate {@code Locale} given a {@code String} of the form returned
- * by {@code toString}. This is very lenient, and doesn't care what's between the underscores:
- * this method can parse strings that {@code Locale.toString} won't produce.
- * Used to remove duplication.
- */
- public static Locale localeFromString(String localeName) {
- int first = localeName.indexOf('_');
- int second = localeName.indexOf('_', first + 1);
- if (first == -1) {
- // Language only ("ja").
- return new Locale(localeName);
- } else if (second == -1) {
- // Language and country ("ja_JP").
- return new Locale(localeName.substring(0, first), localeName.substring(first + 1));
- } else {
- // Language and country and variant ("ja_JP_TRADITIONAL").
- return new Locale(localeName.substring(0, first), localeName.substring(first + 1, second), localeName.substring(second + 1));
- }
- }
-
- public static Locale[] localesFromStrings(String[] localeNames) {
- Locale[] result = new Locale[localeNames.length];
- for (int i = 0; i < result.length; ++i) {
- result[i] = localeFromString(localeNames[i]);
- }
- return result;
- }
-
- private static Locale[] availableLocalesCache;
- public static Locale[] getAvailableLocales() {
- if (availableLocalesCache == null) {
- availableLocalesCache = localesFromStrings(getAvailableLocalesNative());
- }
- return availableLocalesCache.clone();
- }
-
- public static Locale[] getAvailableBreakIteratorLocales() {
- return localesFromStrings(getAvailableBreakIteratorLocalesNative());
- }
-
- public static Locale[] getAvailableCalendarLocales() {
- return localesFromStrings(getAvailableCalendarLocalesNative());
- }
-
- public static Locale[] getAvailableCollatorLocales() {
- return localesFromStrings(getAvailableCollatorLocalesNative());
- }
-
- public static Locale[] getAvailableDateFormatLocales() {
- return localesFromStrings(getAvailableDateFormatLocalesNative());
- }
-
- public static Locale[] getAvailableDateFormatSymbolsLocales() {
- return getAvailableDateFormatLocales();
- }
-
- public static Locale[] getAvailableDecimalFormatSymbolsLocales() {
- return getAvailableNumberFormatLocales();
- }
-
- public static Locale[] getAvailableNumberFormatLocales() {
- return localesFromStrings(getAvailableNumberFormatLocalesNative());
- }
-
- // --- Case mapping.
-
- public static native String toLowerCase(String s, String localeName);
- public static native String toUpperCase(String s, String localeName);
-
- // --- Native methods accessing ICU's database.
-
- private static native String[] getAvailableBreakIteratorLocalesNative();
- private static native String[] getAvailableCalendarLocalesNative();
- private static native String[] getAvailableCollatorLocalesNative();
- private static native String[] getAvailableDateFormatLocalesNative();
- private static native String[] getAvailableLocalesNative();
- private static native String[] getAvailableNumberFormatLocalesNative();
-
- public static native String getCurrencyCodeNative(String locale);
- public static native int getCurrencyFractionDigitsNative(String currencyCode);
- public static native String getCurrencySymbolNative(String locale, String currencyCode);
-
- public static native String getDisplayCountryNative(String countryCode, String locale);
- public static native String getDisplayLanguageNative(String languageCode, String locale);
- public static native String getDisplayVariantNative(String variantCode, String locale);
-
- public static native String getISO3CountryNative(String locale);
- public static native String getISO3LanguageNative(String locale);
-
- private static native String[] getISOLanguagesNative();
- private static native String[] getISOCountriesNative();
-
- static native boolean initLocaleDataImpl(String locale, LocaleData result);
-}
diff --git a/luni/src/main/java/com/ibm/icu4jni/util/LocaleData.java b/luni/src/main/java/com/ibm/icu4jni/util/LocaleData.java
deleted file mode 100644
index 67112b6..0000000
--- a/luni/src/main/java/com/ibm/icu4jni/util/LocaleData.java
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.util;
-
-import java.text.DateFormat;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Locale;
-
-/**
- * Passes locale-specific from ICU native code to Java.
- * <p>
- * Note that you share these; you must not alter any of the fields, nor their array elements
- * in the case of arrays. If you ever expose any of these things to user code, you must give
- * them a clone rather than the original.
- */
-public final class LocaleData {
- // A cache for the locale-specific data.
- private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
-
- // Used by Calendar.
- public Integer firstDayOfWeek;
- public Integer minimalDaysInFirstWeek;
-
- // Used by DateFormatSymbols.
- public String[] amPm;
- public String[] eras;
-
- public String[] longMonthNames;
- public String[] shortMonthNames;
- public String[] longStandAloneMonthNames;
- public String[] shortStandAloneMonthNames;
-
- public String[] longWeekdayNames;
- public String[] shortWeekdayNames;
- public String[] longStandAloneWeekdayNames;
- public String[] shortStandAloneWeekdayNames;
-
- public String fullTimeFormat;
- public String longTimeFormat;
- public String mediumTimeFormat;
- public String shortTimeFormat;
-
- public String fullDateFormat;
- public String longDateFormat;
- public String mediumDateFormat;
- public String shortDateFormat;
-
- // Used by DecimalFormatSymbols.
- public char zeroDigit;
- public char digit;
- public char decimalSeparator;
- public char groupingSeparator;
- public char patternSeparator;
- public char percent;
- public char perMill;
- public char monetarySeparator;
- public char minusSign;
- public String exponentSeparator;
- public String infinity;
- public String NaN;
- // Also used by Currency.
- public String currencySymbol;
- public String internationalCurrencySymbol;
-
- // Used by DecimalFormat and NumberFormat.
- public String numberPattern;
- public String integerPattern;
- public String currencyPattern;
- public String percentPattern;
-
- private LocaleData() {
- }
-
- /**
- * Returns a shared LocaleData for the given locale.
- */
- public static LocaleData get(Locale locale) {
- if (locale == null) {
- locale = Locale.getDefault();
- }
- String localeName = locale.toString();
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- }
- LocaleData newLocaleData = makeLocaleData(locale);
- synchronized (localeDataCache) {
- LocaleData localeData = localeDataCache.get(localeName);
- if (localeData != null) {
- return localeData;
- }
- localeDataCache.put(localeName, newLocaleData);
- return newLocaleData;
- }
- }
-
- private static LocaleData makeLocaleData(Locale locale) {
- String language = locale.getLanguage();
- String country = locale.getCountry();
- String variant = locale.getVariant();
- // Start with data from the parent (next-most-specific) locale...
- LocaleData result = new LocaleData();
- if (!variant.isEmpty()) {
- result.overrideWithDataFrom(get(new Locale(language, country, "")));
- } else if (!country.isEmpty()) {
- result.overrideWithDataFrom(get(new Locale(language, "", "")));
- } else if (!language.isEmpty()) {
- result.overrideWithDataFrom(get(Locale.ROOT));
- }
- // Override with data from this locale.
- result.overrideWithDataFrom(initLocaleData(locale));
- return result;
- }
-
- @Override public String toString() {
- return "LocaleData[" +
- "firstDayOfWeek=" + firstDayOfWeek + "," +
- "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
- "amPm=" + Arrays.toString(amPm) + "," +
- "eras=" + Arrays.toString(eras) + "," +
- "longMonthNames=" + Arrays.toString(longMonthNames) + "," +
- "shortMonthNames=" + Arrays.toString(shortMonthNames) + "," +
- "longStandAloneMonthNames=" + Arrays.toString(longStandAloneMonthNames) + "," +
- "shortStandAloneMonthNames=" + Arrays.toString(shortStandAloneMonthNames) + "," +
- "longWeekdayNames=" + Arrays.toString(longWeekdayNames) + "," +
- "shortWeekdayNames=" + Arrays.toString(shortWeekdayNames) + "," +
- "longStandAloneWeekdayNames=" + Arrays.toString(longStandAloneWeekdayNames) + "," +
- "shortStandAloneWeekdayNames=" + Arrays.toString(shortStandAloneWeekdayNames) + "," +
- "fullTimeFormat=" + fullTimeFormat + "," +
- "longTimeFormat=" + longTimeFormat + "," +
- "mediumTimeFormat=" + mediumTimeFormat + "," +
- "shortTimeFormat=" + shortTimeFormat + "," +
- "fullDateFormat=" + fullDateFormat + "," +
- "longDateFormat=" + longDateFormat + "," +
- "mediumDateFormat=" + mediumDateFormat + "," +
- "shortDateFormat=" + shortDateFormat + "," +
- "zeroDigit=" + zeroDigit + "," +
- "digit=" + digit + "," +
- "decimalSeparator=" + decimalSeparator + "," +
- "groupingSeparator=" + groupingSeparator + "," +
- "patternSeparator=" + patternSeparator + "," +
- "percent=" + percent + "," +
- "perMill=" + perMill + "," +
- "monetarySeparator=" + monetarySeparator + "," +
- "minusSign=" + minusSign + "," +
- "exponentSeparator=" + exponentSeparator + "," +
- "infinity=" + infinity + "," +
- "NaN=" + NaN + "," +
- "currencySymbol=" + currencySymbol + "," +
- "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
- "numberPattern=" + numberPattern + "," +
- "integerPattern=" + integerPattern + "," +
- "currencyPattern=" + currencyPattern + "," +
- "percentPattern=" + percentPattern + "]";
- }
-
- private void overrideWithDataFrom(LocaleData overrides) {
- if (overrides.firstDayOfWeek != null) {
- firstDayOfWeek = overrides.firstDayOfWeek;
- }
- if (overrides.minimalDaysInFirstWeek != null) {
- minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
- }
- if (overrides.amPm != null) {
- amPm = overrides.amPm;
- }
- if (overrides.eras != null) {
- eras = overrides.eras;
- }
- if (overrides.longMonthNames != null) {
- longMonthNames = overrides.longMonthNames;
- }
- if (overrides.shortMonthNames != null) {
- shortMonthNames = overrides.shortMonthNames;
- }
- if (overrides.longStandAloneMonthNames != null) {
- longStandAloneMonthNames = overrides.longStandAloneMonthNames;
- }
- if (overrides.shortStandAloneMonthNames != null) {
- shortStandAloneMonthNames = overrides.shortStandAloneMonthNames;
- }
- if (overrides.longWeekdayNames != null) {
- longWeekdayNames = overrides.longWeekdayNames;
- }
- if (overrides.shortWeekdayNames != null) {
- shortWeekdayNames = overrides.shortWeekdayNames;
- }
- if (overrides.longStandAloneWeekdayNames != null) {
- longStandAloneWeekdayNames = overrides.longStandAloneWeekdayNames;
- }
- if (overrides.shortStandAloneWeekdayNames != null) {
- shortStandAloneWeekdayNames = overrides.shortStandAloneWeekdayNames;
- }
- if (overrides.fullTimeFormat != null) {
- fullTimeFormat = overrides.fullTimeFormat;
- }
- if (overrides.longTimeFormat != null) {
- longTimeFormat = overrides.longTimeFormat;
- }
- if (overrides.mediumTimeFormat != null) {
- mediumTimeFormat = overrides.mediumTimeFormat;
- }
- if (overrides.shortTimeFormat != null) {
- shortTimeFormat = overrides.shortTimeFormat;
- }
- if (overrides.fullDateFormat != null) {
- fullDateFormat = overrides.fullDateFormat;
- }
- if (overrides.longDateFormat != null) {
- longDateFormat = overrides.longDateFormat;
- }
- if (overrides.mediumDateFormat != null) {
- mediumDateFormat = overrides.mediumDateFormat;
- }
- if (overrides.shortDateFormat != null) {
- shortDateFormat = overrides.shortDateFormat;
- }
- if (overrides.zeroDigit != '\0') {
- zeroDigit = overrides.zeroDigit;
- }
- if (overrides.digit != '\0') {
- digit = overrides.digit;
- }
- if (overrides.decimalSeparator != '\0') {
- decimalSeparator = overrides.decimalSeparator;
- }
- if (overrides.groupingSeparator != '\0') {
- groupingSeparator = overrides.groupingSeparator;
- }
- if (overrides.patternSeparator != '\0') {
- patternSeparator = overrides.patternSeparator;
- }
- if (overrides.percent != '\0') {
- percent = overrides.percent;
- }
- if (overrides.perMill != '\0') {
- perMill = overrides.perMill;
- }
- if (overrides.monetarySeparator != '\0') {
- monetarySeparator = overrides.monetarySeparator;
- }
- if (overrides.minusSign != '\0') {
- minusSign = overrides.minusSign;
- }
- if (overrides.exponentSeparator != null) {
- exponentSeparator = overrides.exponentSeparator;
- }
- if (overrides.NaN != null) {
- NaN = overrides.NaN;
- }
- if (overrides.infinity != null) {
- infinity = overrides.infinity;
- }
- if (overrides.currencySymbol != null) {
- currencySymbol = overrides.currencySymbol;
- }
- if (overrides.internationalCurrencySymbol != null) {
- internationalCurrencySymbol = overrides.internationalCurrencySymbol;
- }
- if (overrides.numberPattern != null) {
- numberPattern = overrides.numberPattern;
- }
- if (overrides.integerPattern != null) {
- integerPattern = overrides.integerPattern;
- }
- if (overrides.currencyPattern != null) {
- currencyPattern = overrides.currencyPattern;
- }
- if (overrides.percentPattern != null) {
- percentPattern = overrides.percentPattern;
- }
- }
-
- public String getDateFormat(int style) {
- switch (style) {
- case DateFormat.SHORT:
- return shortDateFormat;
- case DateFormat.MEDIUM:
- return mediumDateFormat;
- case DateFormat.LONG:
- return longDateFormat;
- case DateFormat.FULL:
- return fullDateFormat;
- }
- throw new AssertionError();
- }
-
- public String getTimeFormat(int style) {
- switch (style) {
- case DateFormat.SHORT:
- return shortTimeFormat;
- case DateFormat.MEDIUM:
- return mediumTimeFormat;
- case DateFormat.LONG:
- return longTimeFormat;
- case DateFormat.FULL:
- return fullTimeFormat;
- }
- throw new AssertionError();
- }
-
- private static LocaleData initLocaleData(Locale locale) {
- LocaleData localeData = new LocaleData();
- if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
- throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
- }
- if (localeData.fullTimeFormat != null) {
- // There are some full time format patterns in ICU that use the pattern character 'v'.
- // Java doesn't accept this, so we replace it with 'z' which has about the same result
- // as 'v', the timezone name.
- // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
- // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
- localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
- }
- if (localeData.numberPattern != null) {
- // The number pattern might contain positive and negative subpatterns. Arabic, for
- // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
- // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
- // (The negative subpattern is optional, though, and not present in most locales.)
- // By only swallowing '#'es and ','s after the '.', we ensure that we don't
- // accidentally eat too much.
- localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
- }
- return localeData;
- }
-}
diff --git a/luni/src/main/java/java/awt/font/TextAttribute.java b/luni/src/main/java/java/awt/font/TextAttribute.java
index 4a17e4d..3929fdb 100644
--- a/luni/src/main/java/java/awt/font/TextAttribute.java
+++ b/luni/src/main/java/java/awt/font/TextAttribute.java
@@ -20,10 +20,7 @@
*/
package java.awt.font;
-import java.io.InvalidObjectException;
import java.text.AttributedCharacterIterator.Attribute;
-import java.util.HashMap;
-import java.util.Map;
/**
* The TextAttribute class defines attribute keys and attribute values
@@ -42,10 +39,6 @@ public final class TextAttribute extends Attribute {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 7744112784117861702L;
- // set of available text attributes
- /** The Constant attrMap. */
- private static final Map<String, TextAttribute> attrMap = new HashMap<String, TextAttribute>();
-
/**
* Instantiates a new TextAttribute with the specified name.
*
@@ -53,23 +46,6 @@ public final class TextAttribute extends Attribute {
*/
protected TextAttribute(String name) {
super(name);
- attrMap.put(name, this);
- }
-
- /**
- * Resolves the instance being deserialized.
- *
- * @return the Object.
- *
- * @throws InvalidObjectException the InvalidObjectException.
- */
- @Override
- protected Object readResolve() throws InvalidObjectException {
- TextAttribute result = attrMap.get(this.getName());
- if (result != null) {
- return result;
- }
- throw new InvalidObjectException("Unknown attribute name");
}
/**
@@ -194,9 +170,9 @@ public final class TextAttribute extends Attribute {
public static final TextAttribute TRACKING = new TextAttribute("tracking");
/** @since 1.6 */
- public static final Float TRACKING_LOOSE = -1f;
+ public static final Float TRACKING_LOOSE = 0.04f;
/** @since 1.6 */
- public static final Float TRACKING_TIGHT = -1f;
+ public static final Float TRACKING_TIGHT = -0.04f;
/** The TRANSFORM text attribute. */
public static final TextAttribute TRANSFORM = new TextAttribute("transform");
diff --git a/luni/src/main/java/java/beans/PropertyChangeSupport.java b/luni/src/main/java/java/beans/PropertyChangeSupport.java
index 487dcc6..ef10b73 100644
--- a/luni/src/main/java/java/beans/PropertyChangeSupport.java
+++ b/luni/src/main/java/java/beans/PropertyChangeSupport.java
@@ -20,36 +20,43 @@ package java.beans;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.io.ObjectStreamField;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.EventListener;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import libcore.base.Objects;
/**
- * This utility class
+ * Manages a list of listeners to be notified when a property changes. Listeners
+ * subscribe to be notified of all property changes, or of changes to a single
+ * named property.
*
+ * <p>This class is thread safe. No locking is necessary when subscribing or
+ * unsubscribing listeners, or when publishing events. Callers should be careful
+ * when publishing events because listeners may not be thread safe.
*/
public class PropertyChangeSupport implements Serializable {
private static final long serialVersionUID = 6401253773779951803l;
+ private static final ObjectStreamField[] serialPersistentFields = {
+ new ObjectStreamField("source", Object.class),
+ new ObjectStreamField("children", Object.class),
+ new ObjectStreamField("propertyChangeSupportSerializedDataVersion", int.class)
+ };
private transient Object sourceBean;
- private transient List<PropertyChangeListener> allPropertiesChangeListeners =
- new ArrayList<PropertyChangeListener>();
-
- private transient Map<String, List<PropertyChangeListener>>
- selectedPropertiesChangeListeners =
- new HashMap<String, List<PropertyChangeListener>>();
-
- // fields for serialization compatibility
- private Hashtable<String, List<PropertyChangeListener>> children;
-
- private Object source;
-
- private int propertyChangeSupportSerializedDataVersion = 1;
+ /**
+ * All listeners, including PropertyChangeListenerProxy listeners that are
+ * only be notified when the assigned property is changed. This list may be
+ * modified concurrently!
+ */
+ private transient List<PropertyChangeListener> listeners
+ = new CopyOnWriteArrayList<PropertyChangeListener>();
/**
* Creates a new instance that uses the source bean as source for any event.
@@ -77,11 +84,8 @@ public class PropertyChangeSupport implements Serializable {
* @param newValue
* the new value of the property
*/
- public void firePropertyChange(String propertyName, Object oldValue,
- Object newValue) {
- PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
- oldValue, newValue);
- doFirePropertyChange(event);
+ public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
+ firePropertyChange(new PropertyChangeEvent(sourceBean, propertyName, oldValue, newValue));
}
/**
@@ -101,88 +105,84 @@ public class PropertyChangeSupport implements Serializable {
*/
public void fireIndexedPropertyChange(String propertyName, int index,
Object oldValue, Object newValue) {
-
- // nulls and equals check done in doFire...
- doFirePropertyChange(new IndexedPropertyChangeEvent(sourceBean,
+ firePropertyChange(new IndexedPropertyChangeEvent(sourceBean,
propertyName, oldValue, newValue, index));
}
/**
- * Removes the listener from the specific property. This only happens if it
- * was registered to this property. Nothing happens if it was not
- * registered with this property or if the property name or the listener is
- * null.
- *
- * @param propertyName
- * the property name the listener is listening to
- * @param listener
- * the listener to remove
+ * Unsubscribes {@code listener} from change notifications for the property
+ * named {@code propertyName}. If multiple subscriptions exist for {@code
+ * listener}, it will receive one fewer notifications when the property
+ * changes. If the property name or listener is null or not subscribed, this
+ * method silently does nothing.
*/
- public synchronized void removePropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- if ((propertyName != null) && (listener != null)) {
- List<PropertyChangeListener> listeners =
- selectedPropertiesChangeListeners.get(propertyName);
-
- if (listeners != null) {
- listeners.remove(listener);
+ public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ for (PropertyChangeListener p : listeners) {
+ if (equals(propertyName, listener, p)) {
+ listeners.remove(p);
+ return;
}
}
}
/**
- * Adds a listener to a specific property. Nothing happens if the property
- * name or the listener is null.
- *
- * @param propertyName
- * the name of the property
- * @param listener
- * the listener to register for the property with the given name
+ * Returns true if two chains of PropertyChangeListenerProxies have the same
+ * names in the same order and bottom out in the same event listener. This
+ * method's signature is asymmetric to avoid allocating a proxy: if
+ * non-null, {@code aName} represents the first property name and {@code a}
+ * is its listener.
*/
- public synchronized void addPropertyChangeListener(String propertyName,
- PropertyChangeListener listener) {
- if ((listener != null) && (propertyName != null)) {
- List<PropertyChangeListener> listeners =
- selectedPropertiesChangeListeners.get(propertyName);
-
- if (listeners == null) {
- listeners = new ArrayList<PropertyChangeListener>();
- selectedPropertiesChangeListeners.put(propertyName, listeners);
+ private boolean equals(String aName, EventListener a, EventListener b) {
+ /*
+ * Each iteration of the loop attempts to match a pair of property names
+ * from a and b. If they don't match, the chains must not be equal!
+ */
+ while (b instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy bProxy = (PropertyChangeListenerProxy) b; // unwrap b
+ String bName = bProxy.getPropertyName();
+ b = bProxy.getListener();
+ if (aName == null) {
+ if (!(a instanceof PropertyChangeListenerProxy)) {
+ return false;
+ }
+ PropertyChangeListenerProxy aProxy = (PropertyChangeListenerProxy) a; // unwrap a
+ aName = aProxy.getPropertyName();
+ a = aProxy.getListener();
}
-
- // RI compatibility
- if (listener instanceof PropertyChangeListenerProxy) {
- PropertyChangeListenerProxy proxy =
- (PropertyChangeListenerProxy) listener;
-
- listeners.add(new PropertyChangeListenerProxy(
- proxy.getPropertyName(),
- (PropertyChangeListener) proxy.getListener()));
- } else {
- listeners.add(listener);
+ if (!Objects.equal(aName, bName)) {
+ return false; // not equal; a and b subscribe to different properties
}
+ aName = null;
}
+ return aName == null && Objects.equal(a, b);
}
/**
- * Returns an array of listeners that registered to the property with the
- * given name. If the property name is null an empty array is returned.
- *
- * @param propertyName
- * the name of the property whose listeners should be returned
- * @return the array of listeners to the property with the given name.
+ * Subscribes {@code listener} to change notifications for the property
+ * named {@code propertyName}. If the listener is already subscribed, it
+ * will receive an additional notification when the property changes. If the
+ * property name or listener is null, this method silently does nothing.
*/
- public synchronized PropertyChangeListener[] getPropertyChangeListeners(
- String propertyName) {
- List<PropertyChangeListener> listeners = null;
-
- if (propertyName != null) {
- listeners = selectedPropertiesChangeListeners.get(propertyName);
+ public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ if (listener != null && propertyName != null) {
+ listeners.add(new PropertyChangeListenerProxy(propertyName, listener));
}
+ }
- return (listeners == null) ? new PropertyChangeListener[] {}
- : listeners.toArray(
- new PropertyChangeListener[listeners.size()]);
+ /**
+ * Returns the subscribers to be notified when {@code propertyName} changes.
+ * This includes both listeners subscribed to all property changes and
+ * listeners subscribed to the named property only.
+ */
+ public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
+ List<PropertyChangeListener> result = new ArrayList<PropertyChangeListener>();
+ for (PropertyChangeListener p : listeners) {
+ if (p instanceof PropertyChangeListenerProxy && Objects.equal(
+ propertyName, ((PropertyChangeListenerProxy) p).getPropertyName())) {
+ result.add(p);
+ }
+ }
+ return result.toArray(new PropertyChangeListener[result.size()]);
}
/**
@@ -197,11 +197,8 @@ public class PropertyChangeSupport implements Serializable {
* @param newValue
* the new value
*/
- public void firePropertyChange(String propertyName, boolean oldValue,
- boolean newValue) {
- PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
- oldValue, newValue);
- doFirePropertyChange(event);
+ public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
+ firePropertyChange(propertyName, Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
}
/**
@@ -220,10 +217,9 @@ public class PropertyChangeSupport implements Serializable {
*/
public void fireIndexedPropertyChange(String propertyName, int index,
boolean oldValue, boolean newValue) {
-
if (oldValue != newValue) {
- fireIndexedPropertyChange(propertyName, index, Boolean
- .valueOf(oldValue), Boolean.valueOf(newValue));
+ fireIndexedPropertyChange(propertyName, index,
+ Boolean.valueOf(oldValue), Boolean.valueOf(newValue));
}
}
@@ -239,11 +235,8 @@ public class PropertyChangeSupport implements Serializable {
* @param newValue
* the new value
*/
- public void firePropertyChange(String propertyName, int oldValue,
- int newValue) {
- PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
- oldValue, newValue);
- doFirePropertyChange(event);
+ public void firePropertyChange(String propertyName, int oldValue, int newValue) {
+ firePropertyChange(propertyName, Integer.valueOf(oldValue), Integer.valueOf(newValue));
}
/**
@@ -262,7 +255,6 @@ public class PropertyChangeSupport implements Serializable {
*/
public void fireIndexedPropertyChange(String propertyName, int index,
int oldValue, int newValue) {
-
if (oldValue != newValue) {
fireIndexedPropertyChange(propertyName, index,
Integer.valueOf(oldValue), Integer.valueOf(newValue));
@@ -278,223 +270,130 @@ public class PropertyChangeSupport implements Serializable {
* @return true if there are listeners registered to that property, false
* otherwise.
*/
- public synchronized boolean hasListeners(String propertyName) {
- boolean result = allPropertiesChangeListeners.size() > 0;
- if (!result && (propertyName != null)) {
- List<PropertyChangeListener> listeners =
- selectedPropertiesChangeListeners.get(propertyName);
- if (listeners != null) {
- result = listeners.size() > 0;
+ public boolean hasListeners(String propertyName) {
+ for (PropertyChangeListener p : listeners) {
+ if (!(p instanceof PropertyChangeListenerProxy) || Objects.equal(
+ propertyName, ((PropertyChangeListenerProxy) p).getPropertyName())) {
+ return true;
}
}
- return result;
+ return false;
}
/**
- * removes a property change listener that was registered to all properties.
- *
- * @param listener
- * the listener to remove
+ * Unsubscribes {@code listener} from change notifications for all
+ * properties. If the listener has multiple subscriptions, it will receive
+ * one fewer notification when properties change. If the property name or
+ * listener is null or not subscribed, this method silently does nothing.
*/
- public synchronized void removePropertyChangeListener(
- PropertyChangeListener listener) {
- if (listener != null) {
- if (listener instanceof PropertyChangeListenerProxy) {
- String name = ((PropertyChangeListenerProxy) listener)
- .getPropertyName();
- PropertyChangeListener lst = (PropertyChangeListener)
- ((PropertyChangeListenerProxy) listener).getListener();
-
- removePropertyChangeListener(name, lst);
- } else {
- allPropertiesChangeListeners.remove(listener);
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ for (PropertyChangeListener p : listeners) {
+ if (equals(null, listener, p)) {
+ listeners.remove(p);
+ return;
}
}
}
/**
- * Registers a listener with all properties.
- *
- * @param listener
- * the listener to register
+ * Subscribes {@code listener} to change notifications for all properties.
+ * If the listener is already subscribed, it will receive an additional
+ * notification. If the listener is null, this method silently does nothing.
*/
- public synchronized void addPropertyChangeListener(
- PropertyChangeListener listener) {
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
if (listener != null) {
- if (listener instanceof PropertyChangeListenerProxy) {
- String name = ((PropertyChangeListenerProxy) listener)
- .getPropertyName();
- PropertyChangeListener lst = (PropertyChangeListener)
- ((PropertyChangeListenerProxy) listener).getListener();
- addPropertyChangeListener(name, lst);
- } else {
- allPropertiesChangeListeners.add(listener);
- }
+ listeners.add(listener);
}
}
/**
- * Returns an array with the listeners that registered to all properties.
- *
- * @return the array of listeners
+ * Returns all subscribers. This includes both listeners subscribed to all
+ * property changes and listeners subscribed to a single property.
*/
- public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
- ArrayList<PropertyChangeListener> result =
- new ArrayList<PropertyChangeListener>(
- allPropertiesChangeListeners);
-
- for (String propertyName : selectedPropertiesChangeListeners.keySet()) {
- List<PropertyChangeListener> selectedListeners =
- selectedPropertiesChangeListeners.get(propertyName);
-
- if (selectedListeners != null) {
-
- for (PropertyChangeListener listener : selectedListeners) {
- result.add(new PropertyChangeListenerProxy(propertyName,
- listener));
- }
- }
- }
-
- return result.toArray(new PropertyChangeListener[result.size()]);
+ public PropertyChangeListener[] getPropertyChangeListeners() {
+ return listeners.toArray(new PropertyChangeListener[0]); // 0 to avoid synchronization
}
- private void writeObject(ObjectOutputStream oos) throws IOException {
- List<PropertyChangeListener> allSerializedPropertiesChangeListeners =
- new ArrayList<PropertyChangeListener>();
-
- for (PropertyChangeListener pcl : allPropertiesChangeListeners) {
- if (pcl instanceof Serializable) {
- allSerializedPropertiesChangeListeners.add(pcl);
- }
- }
-
- Map<String, List<PropertyChangeListener>>
- selectedSerializedPropertiesChangeListeners =
- new HashMap<String, List<PropertyChangeListener>>();
-
- for (String propertyName : selectedPropertiesChangeListeners.keySet()) {
- List<PropertyChangeListener> keyValues =
- selectedPropertiesChangeListeners.get(propertyName);
-
- if (keyValues != null) {
- List<PropertyChangeListener> serializedPropertiesChangeListeners
- = new ArrayList<PropertyChangeListener>();
-
- for (PropertyChangeListener pcl : keyValues) {
- if (pcl instanceof Serializable) {
- serializedPropertiesChangeListeners.add(pcl);
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ /*
+ * The serialized form of this class uses PropertyChangeSupport to group
+ * PropertyChangeListeners subscribed to the same property name.
+ */
+ Map<String, PropertyChangeSupport> map = new Hashtable<String, PropertyChangeSupport>();
+ for (PropertyChangeListener p : listeners) {
+ if (p instanceof PropertyChangeListenerProxy && !(p instanceof Serializable)) {
+ PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) p;
+ PropertyChangeListener listener = (PropertyChangeListener) proxy.getListener();
+ if (listener instanceof Serializable) {
+ PropertyChangeSupport list = map.get(proxy.getPropertyName());
+ if (list == null) {
+ list = new PropertyChangeSupport(sourceBean);
+ map.put(proxy.getPropertyName(), list);
}
- }
-
- if (!serializedPropertiesChangeListeners.isEmpty()) {
- selectedSerializedPropertiesChangeListeners.put(
- propertyName, serializedPropertiesChangeListeners);
+ list.listeners.add(listener);
}
}
}
- children = new Hashtable<String, List<PropertyChangeListener>>(
- selectedSerializedPropertiesChangeListeners);
- children.put("", allSerializedPropertiesChangeListeners);
- oos.writeObject(children);
+ ObjectOutputStream.PutField putFields = out.putFields();
+ putFields.put("source", sourceBean);
+ putFields.put("children", map);
+ out.writeFields();
- Object source = null;
- if (sourceBean instanceof Serializable) {
- source = sourceBean;
+ for (PropertyChangeListener p : listeners) {
+ if (p instanceof Serializable) {
+ out.writeObject(p);
+ }
}
- oos.writeObject(source);
-
- oos.writeInt(propertyChangeSupportSerializedDataVersion);
+ out.writeObject(null);
}
@SuppressWarnings("unchecked")
- private void readObject(ObjectInputStream ois) throws IOException,
- ClassNotFoundException {
- children = (Hashtable<String, List<PropertyChangeListener>>) ois
- .readObject();
-
- selectedPropertiesChangeListeners = new HashMap<String, List<PropertyChangeListener>>(
- children);
- allPropertiesChangeListeners = selectedPropertiesChangeListeners
- .remove("");
- if (allPropertiesChangeListeners == null) {
- allPropertiesChangeListeners = new ArrayList<PropertyChangeListener>();
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ ObjectInputStream.GetField readFields = in.readFields();
+ sourceBean = readFields.get("source", null);
+ listeners = new CopyOnWriteArrayList<PropertyChangeListener>();
+
+ Map<String, PropertyChangeSupport> children
+ = (Map<String, PropertyChangeSupport>) readFields.get("children", null);
+ if (children != null) {
+ for (Map.Entry<String, PropertyChangeSupport> entry : children.entrySet()) {
+ for (PropertyChangeListener p : entry.getValue().listeners) {
+ listeners.add(new PropertyChangeListenerProxy(entry.getKey(), p));
+ }
+ }
}
- sourceBean = ois.readObject();
- propertyChangeSupportSerializedDataVersion = ois.readInt();
+ PropertyChangeListener listener;
+ while ((listener = (PropertyChangeListener) in.readObject()) != null) {
+ listeners.add(listener);
+ }
}
/**
- * Fires a property change event to all listeners of that property.
- *
- * @param event
- * the event to fire
+ * Publishes a property change event to all listeners of that property. If
+ * the event's old and new values are equal (but non-null), no event will be
+ * published.
*/
public void firePropertyChange(PropertyChangeEvent event) {
- doFirePropertyChange(event);
- }
-
- private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
- Object oldValue, Object newValue) {
- return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
- newValue);
- }
-
- private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
- boolean oldValue, boolean newValue) {
- return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
- newValue);
- }
-
- private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
- int oldValue, int newValue) {
- return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
- newValue);
- }
-
- private void doFirePropertyChange(PropertyChangeEvent event) {
String propertyName = event.getPropertyName();
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
-
- if ((newValue != null) && (oldValue != null)
- && newValue.equals(oldValue)) {
+ if (newValue != null && oldValue != null && newValue.equals(oldValue)) {
return;
}
- /*
- * Copy the listeners collections so they can be modified while we fire
- * events.
- */
-
- // Listeners to all property change events
- PropertyChangeListener[] listensToAll;
- // Listens to a given property change
- PropertyChangeListener[] listensToOne = null;
- synchronized (this) {
- listensToAll = allPropertiesChangeListeners
- .toArray(new PropertyChangeListener[allPropertiesChangeListeners
- .size()]);
-
- List<PropertyChangeListener> listeners = selectedPropertiesChangeListeners
- .get(propertyName);
- if (listeners != null) {
- listensToOne = listeners
- .toArray(new PropertyChangeListener[listeners.size()]);
- }
- }
-
- // Fire the listeners
- for (PropertyChangeListener listener : listensToAll) {
- listener.propertyChange(event);
- }
- if (listensToOne != null) {
- for (PropertyChangeListener listener : listensToOne) {
- listener.propertyChange(event);
+ notifyEachListener:
+ for (PropertyChangeListener p : listeners) {
+ // unwrap listener proxies until we get a mismatched name or the real listener
+ while (p instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) p;
+ if (!Objects.equal(proxy.getPropertyName(), propertyName)) {
+ continue notifyEachListener;
+ }
+ p = (PropertyChangeListener) proxy.getListener();
}
+ p.propertyChange(event);
}
}
-
}
diff --git a/luni/src/main/java/java/io/BufferedInputStream.java b/luni/src/main/java/java/io/BufferedInputStream.java
index 788761f..bfd18cf 100644
--- a/luni/src/main/java/java/io/BufferedInputStream.java
+++ b/luni/src/main/java/java/io/BufferedInputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Wraps an existing {@link InputStream} and <em>buffers</em> the input.
* Expensive interaction with the underlying input stream is minimized, since
@@ -241,7 +243,7 @@ public class BufferedInputStream extends FilterInputStream {
}
/**
- * Reads at most {@code length} bytes from this stream and stores them in
+ * Reads at most {@code byteCount} bytes from this stream and stores them in
* byte array {@code buffer} starting at offset {@code offset}. Returns the
* number of bytes actually read or -1 if no bytes were read and the end of
* the stream was encountered. If all the buffered bytes have been used, a
@@ -251,42 +253,25 @@ public class BufferedInputStream extends FilterInputStream {
*
* @param buffer
* the byte array in which to store the bytes read.
- * @param offset
- * the initial position in {@code buffer} to store the bytes read
- * from this stream.
- * @param length
- * the maximum number of bytes to store in {@code buffer}.
* @return the number of bytes actually read or -1 if end of stream.
* @throws IndexOutOfBoundsException
- * if {@code offset < 0} or {@code length < 0}, or if
- * {@code offset + length} is greater than the size of
+ * if {@code offset < 0} or {@code byteCount < 0}, or if
+ * {@code offset + byteCount} is greater than the size of
* {@code buffer}.
* @throws IOException
* if the stream is already closed or another IOException
* occurs.
*/
@Override
- public synchronized int read(byte[] buffer, int offset, int length) throws IOException {
+ public synchronized int read(byte[] buffer, int offset, int byteCount) throws IOException {
// Use local ref since buf may be invalidated by an unsynchronized
// close()
byte[] localBuf = buf;
if (localBuf == null) {
throw streamClosed();
}
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit, used (offset | length) < 0
- // instead of (offset < 0) || (length < 0) to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | length) < 0 || offset > buffer.length - length) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
- if (length == 0) {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (byteCount == 0) {
return 0;
}
InputStream localIn = in;
@@ -297,16 +282,16 @@ public class BufferedInputStream extends FilterInputStream {
int required;
if (pos < count) {
/* There are bytes available in the buffer. */
- int copylength = count - pos >= length ? length : count - pos;
+ int copylength = count - pos >= byteCount ? byteCount : count - pos;
System.arraycopy(localBuf, pos, buffer, offset, copylength);
pos += copylength;
- if (copylength == length || localIn.available() == 0) {
+ if (copylength == byteCount || localIn.available() == 0) {
return copylength;
}
offset += copylength;
- required = length - copylength;
+ required = byteCount - copylength;
} else {
- required = length;
+ required = byteCount;
}
while (true) {
@@ -318,11 +303,11 @@ public class BufferedInputStream extends FilterInputStream {
if (markpos == -1 && required >= localBuf.length) {
read = localIn.read(buffer, offset, required);
if (read == -1) {
- return required == length ? -1 : length - required;
+ return required == byteCount ? -1 : byteCount - required;
}
} else {
if (fillbuf(localIn, localBuf) == -1) {
- return required == length ? -1 : length - required;
+ return required == byteCount ? -1 : byteCount - required;
}
// localBuf may have been invalidated by fillbuf
if (localBuf != buf) {
@@ -338,10 +323,10 @@ public class BufferedInputStream extends FilterInputStream {
}
required -= read;
if (required == 0) {
- return length;
+ return byteCount;
}
if (localIn.available() == 0) {
- return length - required;
+ return byteCount - required;
}
offset += read;
}
@@ -375,19 +360,19 @@ public class BufferedInputStream extends FilterInputStream {
}
/**
- * Skips {@code amount} number of bytes in this stream. Subsequent
- * {@code read()}'s will not return these bytes unless {@code reset()} is
+ * Skips {@code byteCount} bytes in this stream. Subsequent calls to
+ * {@code read} will not return these bytes unless {@code reset} is
* used.
*
- * @param amount
+ * @param byteCount
* the number of bytes to skip. {@code skip} does nothing and
- * returns 0 if {@code amount} is less than zero.
+ * returns 0 if {@code byteCount} is less than zero.
* @return the number of bytes actually skipped.
* @throws IOException
* if this stream is closed or another IOException occurs.
*/
@Override
- public synchronized long skip(long amount) throws IOException {
+ public synchronized long skip(long byteCount) throws IOException {
// Use local refs since buf and in may be invalidated by an
// unsynchronized close()
byte[] localBuf = buf;
@@ -395,28 +380,28 @@ public class BufferedInputStream extends FilterInputStream {
if (localBuf == null) {
throw streamClosed();
}
- if (amount < 1) {
+ if (byteCount < 1) {
return 0;
}
if (localIn == null) {
throw streamClosed();
}
- if (count - pos >= amount) {
- pos += amount;
- return amount;
+ if (count - pos >= byteCount) {
+ pos += byteCount;
+ return byteCount;
}
long read = count - pos;
pos = count;
if (markpos != -1) {
- if (amount <= marklimit) {
+ if (byteCount <= marklimit) {
if (fillbuf(localIn, localBuf) == -1) {
return read;
}
- if (count - pos >= amount - read) {
- pos += amount - read;
- return amount;
+ if (count - pos >= byteCount - read) {
+ pos += byteCount - read;
+ return byteCount;
}
// Couldn't get all the bytes, skip what we read
read += (count - pos);
@@ -424,6 +409,6 @@ public class BufferedInputStream extends FilterInputStream {
return read;
}
}
- return read + localIn.skip(amount - read);
+ return read + localIn.skip(byteCount - read);
}
}
diff --git a/luni/src/main/java/java/io/BufferedOutputStream.java b/luni/src/main/java/java/io/BufferedOutputStream.java
index 9937629..6bbf596 100644
--- a/luni/src/main/java/java/io/BufferedOutputStream.java
+++ b/luni/src/main/java/java/io/BufferedOutputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Wraps an existing {@link OutputStream} and <em>buffers</em> the output.
* Expensive interaction with the underlying input stream is minimized, since
@@ -130,20 +132,13 @@ public class BufferedOutputStream extends FilterOutputStream {
return;
}
- if (offset < 0 || offset > buffer.length - length) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
-
- }
- if (length < 0) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
// flush the internal buffer first if we have not enough space left
- if (length >= (internalBuffer.length - count)) {
+ if (length > (internalBuffer.length - count)) {
flushInternal();
}
- // the length is always less than (internalBuffer.length - count) here so arraycopy is safe
System.arraycopy(buffer, offset, internalBuffer, count, length);
count += length;
}
diff --git a/luni/src/main/java/java/io/BufferedReader.java b/luni/src/main/java/java/io/BufferedReader.java
index cfe3b5e..0d77735 100644
--- a/luni/src/main/java/java/io/BufferedReader.java
+++ b/luni/src/main/java/java/io/BufferedReader.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Wraps an existing {@link Reader} and <em>buffers</em> the input. Expensive
* interaction with the underlying reader is minimized, since most (smaller)
@@ -270,9 +272,7 @@ public class BufferedReader extends Reader {
public int read(char[] buffer, int offset, int length) throws IOException {
synchronized (lock) {
checkNotClosed();
- if (offset < 0 || offset > buffer.length - length || length < 0) {
- throw new IndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
int outstanding = length;
while (outstanding > 0) {
@@ -470,16 +470,17 @@ public class BufferedReader extends Reader {
}
/**
- * Skips {@code amount} characters in this reader. Subsequent
- * {@code read()}s will not return these characters unless {@code reset()}
- * is used. Skipping characters may invalidate a mark if {@code markLimit}
+ * Skips {@code byteCount} bytes in this stream. Subsequent calls to
+ * {@code read} will not return these bytes unless {@code reset} is
+ * used.
+ * Skipping characters may invalidate a mark if {@code markLimit}
* is surpassed.
*
- * @param amount
+ * @param byteCount
* the maximum number of characters to skip.
* @return the number of characters actually skipped.
* @throws IllegalArgumentException
- * if {@code amount < 0}.
+ * if {@code byteCount < 0}.
* @throws IOException
* if this reader is closed or some other I/O error occurs.
* @see #mark(int)
@@ -487,35 +488,35 @@ public class BufferedReader extends Reader {
* @see #reset()
*/
@Override
- public long skip(long amount) throws IOException {
- if (amount < 0) {
- throw new IllegalArgumentException();
+ public long skip(long byteCount) throws IOException {
+ if (byteCount < 0) {
+ throw new IllegalArgumentException("byteCount < 0: " + byteCount);
}
synchronized (lock) {
checkNotClosed();
- if (amount < 1) {
+ if (byteCount < 1) {
return 0;
}
- if (end - pos >= amount) {
- pos += amount;
- return amount;
+ if (end - pos >= byteCount) {
+ pos += byteCount;
+ return byteCount;
}
long read = end - pos;
pos = end;
- while (read < amount) {
+ while (read < byteCount) {
if (fillBuf() == -1) {
return read;
}
- if (end - pos >= amount - read) {
- pos += amount - read;
- return amount;
+ if (end - pos >= byteCount - read) {
+ pos += byteCount - read;
+ return byteCount;
}
// Couldn't get all the characters, skip what we read
read += (end - pos);
pos = end;
}
- return amount;
+ return byteCount;
}
}
}
diff --git a/luni/src/main/java/java/io/BufferedWriter.java b/luni/src/main/java/java/io/BufferedWriter.java
index a91c0fa..3017065 100644
--- a/luni/src/main/java/java/io/BufferedWriter.java
+++ b/luni/src/main/java/java/io/BufferedWriter.java
@@ -18,6 +18,7 @@
package java.io;
import java.security.AccessController;
+import java.util.Arrays;
import org.apache.harmony.luni.util.PriviAction;
import org.apache.harmony.luni.util.SneakyThrow;
@@ -189,18 +190,10 @@ public class BufferedWriter extends Writer {
public void write(char[] cbuf, int offset, int count) throws IOException {
synchronized (lock) {
checkNotClosed();
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to safe one operation
if (cbuf == null) {
throw new NullPointerException("buffer == null");
}
- if ((offset | count) < 0 || offset > cbuf.length - count) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(cbuf.length, offset, count);
if (pos == 0 && count >= this.buf.length) {
out.write(cbuf, offset, count);
return;
@@ -280,8 +273,8 @@ public class BufferedWriter extends Writer {
if (count <= 0) {
return;
}
- if (offset > str.length() - count || offset < 0) {
- throw new StringIndexOutOfBoundsException();
+ if (offset < 0 || offset > str.length() - count) {
+ throw new StringIndexOutOfBoundsException(str, offset, count);
}
if (pos == 0 && count >= buf.length) {
char[] chars = new char[count];
diff --git a/luni/src/main/java/java/io/ByteArrayInputStream.java b/luni/src/main/java/java/io/ByteArrayInputStream.java
index 8765e9a..642ba01 100644
--- a/luni/src/main/java/java/io/ByteArrayInputStream.java
+++ b/luni/src/main/java/java/io/ByteArrayInputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link InputStream } for reading the contents of a byte array.
*
@@ -98,7 +100,7 @@ public class ByteArrayInputStream extends InputStream {
*/
@Override
public void close() throws IOException {
- // Do nothing on close, this matches JDK behaviour.
+ // Do nothing on close, this matches JDK behavior.
}
/**
@@ -165,22 +167,8 @@ public class ByteArrayInputStream extends InputStream {
*/
@Override
public synchronized int read(byte[] buffer, int offset, int length) {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- // BEGIN android-changed
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- // avoid int overflow
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, used (offset | length) < 0 instead of
- // (offset < 0) || (length < 0) to safe one operation
- if ((offset | length) < 0 || length > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
+
// Are there any bytes available?
if (this.pos >= this.count) {
return -1;
@@ -208,22 +196,20 @@ public class ByteArrayInputStream extends InputStream {
}
/**
- * Skips {@code count} number of bytes in this InputStream. Subsequent
- * {@code read()}s will not return these bytes unless {@code reset()} is
- * used. This implementation skips {@code count} number of bytes in the
- * target stream. It does nothing and returns 0 if {@code n} is negative.
+ * Skips {@code byteCount} bytes in this InputStream. Subsequent
+ * calls to {@code read} will not return these bytes unless {@code reset} is
+ * used. This implementation skips {@code byteCount} number of bytes in the
+ * target stream. It does nothing and returns 0 if {@code byteCount} is negative.
*
- * @param n
- * the number of bytes to skip.
* @return the number of bytes actually skipped.
*/
@Override
- public synchronized long skip(long n) {
- if (n <= 0) {
+ public synchronized long skip(long byteCount) {
+ if (byteCount <= 0) {
return 0;
}
int temp = pos;
- pos = this.count - pos < n ? this.count : (int) (pos + n);
+ pos = this.count - pos < byteCount ? this.count : (int) (pos + byteCount);
return pos - temp;
}
}
diff --git a/luni/src/main/java/java/io/ByteArrayOutputStream.java b/luni/src/main/java/java/io/ByteArrayOutputStream.java
index 358a705..6c6c8f5 100644
--- a/luni/src/main/java/java/io/ByteArrayOutputStream.java
+++ b/luni/src/main/java/java/io/ByteArrayOutputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link OutputStream} for class for writing content to an
* (internal) byte array. As bytes are written to this stream, the byte array
@@ -194,25 +196,10 @@ public class ByteArrayOutputStream extends OutputStream {
*/
@Override
public synchronized void write(byte[] buffer, int offset, int len) {
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, made implicit null check explicit,
- // used (offset | len) < 0 instead of (offset < 0) || (len < 0)
- // to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | len) < 0 || len > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, len);
if (len == 0) {
return;
}
-
- /* Expand if necessary */
expand(len);
System.arraycopy(buffer, offset, buf, this.count, len);
this.count += len;
diff --git a/luni/src/main/java/java/io/CharArrayReader.java b/luni/src/main/java/java/io/CharArrayReader.java
index 41369d2..366efcf 100644
--- a/luni/src/main/java/java/io/CharArrayReader.java
+++ b/luni/src/main/java/java/io/CharArrayReader.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link Reader} for reading the contents of a char array.
*
@@ -205,15 +207,7 @@ public class CharArrayReader extends Reader {
*/
@Override
public int read(char[] buffer, int offset, int len) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- if (offset < 0 || offset > buffer.length) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (len < 0 || len > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + len);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, len);
synchronized (lock) {
checkNotClosed();
if (pos < this.count) {
@@ -264,27 +258,25 @@ public class CharArrayReader extends Reader {
}
/**
- * Skips {@code count} number of characters in this reader. Subsequent
- * {@code read()}s will not return these characters unless {@code reset()}
- * is used. This method does nothing and returns 0 if {@code n} is negative.
+ * Skips {@code charCount} characters in this reader. Subsequent calls to
+ * {@code read} will not return these characters unless {@code reset}
+ * is used. This method does nothing and returns 0 if {@code charCount <= 0}.
*
- * @param n
- * the number of characters to skip.
* @return the number of characters actually skipped.
* @throws IOException
* if this reader is closed.
*/
@Override
- public long skip(long n) throws IOException {
+ public long skip(long charCount) throws IOException {
synchronized (lock) {
checkNotClosed();
- if (n <= 0) {
+ if (charCount <= 0) {
return 0;
}
long skipped = 0;
- if (n < this.count - pos) {
- pos = pos + (int) n;
- skipped = n;
+ if (charCount < this.count - pos) {
+ pos = pos + (int) charCount;
+ skipped = charCount;
} else {
skipped = this.count - pos;
pos = this.count;
diff --git a/luni/src/main/java/java/io/CharArrayWriter.java b/luni/src/main/java/java/io/CharArrayWriter.java
index 03cfeba..ea5e10e 100644
--- a/luni/src/main/java/java/io/CharArrayWriter.java
+++ b/luni/src/main/java/java/io/CharArrayWriter.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link Writer} for class for writing content to an (internal)
* char array. As bytes are written to this writer, the char array may be
@@ -164,21 +166,7 @@ public class CharArrayWriter extends Writer {
*/
@Override
public void write(char[] buffer, int offset, int len) {
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit,
- // removed redundant check,
- // added null check, used (offset | len) < 0 instead of
- // (offset < 0) || (len < 0) to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | len) < 0 || len > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, len);
synchronized (lock) {
expand(len);
System.arraycopy(buffer, offset, this.buf, this.count, len);
@@ -203,24 +191,18 @@ public class CharArrayWriter extends Writer {
}
/**
- * Writes {@code count} number of characters starting at {@code offset} from
+ * Writes {@code count} characters starting at {@code offset} from
* the string {@code str} to this CharArrayWriter.
*
- * @param str
- * the non-null string containing the characters to write.
- * @param offset
- * the index of the first character in {@code str} to write.
- * @param len
- * the number of characters to retrieve and write.
* @throws NullPointerException
* if {@code str} is {@code null}.
* @throws StringIndexOutOfBoundsException
- * if {@code offset < 0} or {@code len < 0}, or if
- * {@code offset + len} is bigger than the length of
+ * if {@code offset < 0} or {@code count < 0}, or if
+ * {@code offset + count} is bigger than the length of
* {@code str}.
*/
@Override
- public void write(String str, int offset, int len) {
+ public void write(String str, int offset, int count) {
if (str == null) {
throw new NullPointerException("str == null");
}
@@ -228,16 +210,16 @@ public class CharArrayWriter extends Writer {
// BEGIN android-changed
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
- // removed redundant check, used (offset | len) < 0
- // instead of (offset < 0) || (len < 0) to safe one operation
- if ((offset | len) < 0 || len > str.length() - offset) {
- throw new StringIndexOutOfBoundsException();
+ // removed redundant check, used (offset | count) < 0
+ // instead of (offset < 0) || (count < 0) to safe one operation
+ if ((offset | count) < 0 || offset > str.length() - count) {
+ throw new StringIndexOutOfBoundsException(str, offset, count);
}
// END android-changed
synchronized (lock) {
- expand(len);
- str.getChars(offset, offset + len, buf, this.count);
- this.count += len;
+ expand(count);
+ str.getChars(offset, offset + count, buf, this.count);
+ this.count += count;
}
}
@@ -285,11 +267,10 @@ public class CharArrayWriter extends Writer {
*/
@Override
public CharArrayWriter append(CharSequence csq) {
- if (null == csq) {
- append(TOKEN_NULL, 0, TOKEN_NULL.length());
- } else {
- append(csq, 0, csq.length());
+ if (csq == null) {
+ csq = "null";
}
+ append(csq, 0, csq.length());
return this;
}
@@ -318,8 +299,8 @@ public class CharArrayWriter extends Writer {
*/
@Override
public CharArrayWriter append(CharSequence csq, int start, int end) {
- if (null == csq) {
- csq = TOKEN_NULL;
+ if (csq == null) {
+ csq = "null";
}
String output = csq.subSequence(start, end).toString();
write(output, 0, output.length());
diff --git a/luni/src/main/java/java/io/Closeable.java b/luni/src/main/java/java/io/Closeable.java
index 623b656..56c2b3c 100644
--- a/luni/src/main/java/java/io/Closeable.java
+++ b/luni/src/main/java/java/io/Closeable.java
@@ -21,6 +21,15 @@ package java.io;
* are not used any longer. This usually includes all sorts of
* {@link InputStream}s and {@link OutputStream}s. Calling the {@code close}
* method releases resources that the object holds.
+ * <p>
+ * A common pattern for using a {@code Closeable} resource: <pre> {@code
+ * Closable foo = new Foo();
+ * try {
+ * ...;
+ * } finally {
+ * foo.close();
+ * }
+ * }</pre>
*/
public interface Closeable {
@@ -32,4 +41,4 @@ public interface Closeable {
* if any error occurs when closing the object.
*/
public void close() throws IOException;
-} \ No newline at end of file
+}
diff --git a/luni/src/main/java/java/io/DataInput.java b/luni/src/main/java/java/io/DataInput.java
index b6f3c72..e02d27c 100644
--- a/luni/src/main/java/java/io/DataInput.java
+++ b/luni/src/main/java/java/io/DataInput.java
@@ -18,7 +18,7 @@
package java.io;
/**
- * Defines an interface for classes that are able to read typed data from some
+ * Defines an interface for classes that are able to read big-endian typed data from some
* source. Typically, this data has been written by a class which implements
* {@link DataOutput}. Types that can be read include byte, 16-bit short, 32-bit
* int, 32-bit float, 64-bit long, 64-bit double, byte strings, and MUTF-8
@@ -71,7 +71,7 @@ public interface DataInput {
public abstract byte readByte() throws IOException;
/**
- * Reads a 16-bit character value.
+ * Reads a big-endian 16-bit character value.
*
* @return the next char value.
* @throws EOFException if the end of the input is reached before the read
@@ -83,7 +83,7 @@ public interface DataInput {
public abstract char readChar() throws IOException;
/**
- * Reads a 64-bit double value.
+ * Reads a big-endian 64-bit double value.
*
* @return the next double value.
* @throws EOFException if the end of the input is reached before the read
@@ -95,7 +95,7 @@ public interface DataInput {
public abstract double readDouble() throws IOException;
/**
- * Reads a 32-bit float value.
+ * Reads a big-endian 32-bit float value.
*
* @return the next float value.
* @throws EOFException if the end of the input is reached before the read
@@ -107,44 +107,40 @@ public interface DataInput {
public abstract float readFloat() throws IOException;
/**
- * Reads bytes into the byte array {@code buffer}. This method will block
- * until {@code buffer.length} number of bytes have been read.
- *
- * @param buffer
- * the buffer to read bytes into.
- * @throws EOFException if the end of the input is reached before the read
- * request can be satisfied.
- * @throws IOException
- * if an I/O error occurs while reading.
- * @see DataOutput#write(byte[])
- * @see DataOutput#write(byte[], int, int)
+ * Equivalent to {@code readFully(dst, 0, dst.length);}.
*/
- public abstract void readFully(byte[] buffer) throws IOException;
+ public abstract void readFully(byte[] dst) throws IOException;
/**
- * Reads bytes and stores them in the byte array {@code buffer} starting at
- * offset {@code offset}. This method blocks until {@code count} number of
- * bytes have been read.
+ * Reads {@code byteCount} bytes from this stream and stores them in the byte
+ * array {@code dst} starting at {@code offset}. If {@code byteCount} is zero, then this
+ * method returns without reading any bytes. Otherwise, this method blocks until
+ * {@code byteCount} bytes have been read. If insufficient bytes are available,
+ * {@code EOFException} is thrown. If an I/O error occurs, {@code IOException} is
+ * thrown. When an exception is thrown, some bytes may have been consumed from the stream
+ * and written into the array.
*
- * @param buffer
- * the byte array in which to store the bytes read.
+ * @param dst
+ * the byte array into which the data is read.
* @param offset
- * the initial position in {@code buffer} to store the bytes
- * read.
- * @param count
- * the maximum number of bytes to store in {@code buffer}.
- * @throws EOFException if the end of the input is reached before the read
- * request can be satisfied.
+ * the offset in {@code dst} at which to store the bytes.
+ * @param byteCount
+ * the number of bytes to read.
+ * @throws EOFException
+ * if the end of the source stream is reached before enough
+ * bytes have been read.
+ * @throws IndexOutOfBoundsException
+ * if {@code offset < 0} or {@code byteCount < 0}, or
+ * {@code offset + byteCount > dst.length}.
* @throws IOException
- * if an I/O error occurs while reading.
- * @see DataOutput#write(byte[])
- * @see DataOutput#write(byte[], int, int)
+ * if a problem occurs while reading from this stream.
+ * @throws NullPointerException
+ * if {@code dst} is null.
*/
- public abstract void readFully(byte[] buffer, int offset, int count)
- throws IOException;
+ public abstract void readFully(byte[] dst, int offset, int byteCount) throws IOException;
/**
- * Reads a 32-bit integer value.
+ * Reads a big-endian 32-bit integer value.
*
* @return the next int value.
* @throws EOFException if the end of the input is reached before the read
@@ -171,7 +167,7 @@ public interface DataInput {
public abstract String readLine() throws IOException;
/**
- * Reads a 64-bit long value.
+ * Reads a big-endian 64-bit long value.
*
* @return the next long value.
* @throws EOFException if the end of the input is reached before the read
@@ -183,7 +179,7 @@ public interface DataInput {
public abstract long readLong() throws IOException;
/**
- * Reads a 16-bit short value.
+ * Reads a big-endian 16-bit short value.
*
* @return the next short value.
* @throws EOFException if the end of the input is reached before the read
@@ -207,7 +203,7 @@ public interface DataInput {
public abstract int readUnsignedByte() throws IOException;
/**
- * Reads a 16-bit unsigned short value and returns it as an int.
+ * Reads a big-endian 16-bit unsigned short value and returns it as an int.
*
* @return the next unsigned short value.
* @throws EOFException if the end of the input is reached before the read
diff --git a/luni/src/main/java/java/io/DataInputStream.java b/luni/src/main/java/java/io/DataInputStream.java
index 8ebcafd..935867a 100644
--- a/luni/src/main/java/java/io/DataInputStream.java
+++ b/luni/src/main/java/java/io/DataInputStream.java
@@ -17,10 +17,14 @@
package java.io;
+import java.nio.ByteOrder;
import java.nio.charset.ModifiedUtf8;
+import libcore.base.Streams;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
/**
- * Wraps an existing {@link InputStream} and reads typed data from it.
+ * Wraps an existing {@link InputStream} and reads big-endian typed data from it.
* Typically, this stream has been written by a DataOutputStream. Types that can
* be read include byte, 16-bit short, 32-bit int, 32-bit float, 64-bit long,
* 64-bit double, byte strings, and strings encoded in
@@ -30,7 +34,7 @@ import java.nio.charset.ModifiedUtf8;
*/
public class DataInputStream extends FilterInputStream implements DataInput {
- byte[] buff;
+ private final byte[] scratch = new byte[8];
/**
* Constructs a new DataInputStream on the InputStream {@code in}. All
@@ -48,7 +52,6 @@ public class DataInputStream extends FilterInputStream implements DataInput {
*/
public DataInputStream(InputStream in) {
super(in);
- buff = new byte[8];
}
/**
@@ -90,22 +93,10 @@ public class DataInputStream extends FilterInputStream implements DataInput {
* @see DataOutput#write(byte[], int, int)
*/
@Override
- public final int read(byte[] buffer, int offset, int length)
- throws IOException {
+ public final int read(byte[] buffer, int offset, int length) throws IOException {
return in.read(buffer, offset, length);
}
- /**
- * Reads a boolean from this stream.
- *
- * @return the next boolean value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before one byte
- * has been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeBoolean(boolean)
- */
public final boolean readBoolean() throws IOException {
int temp = in.read();
if (temp < 0) {
@@ -114,17 +105,6 @@ public class DataInputStream extends FilterInputStream implements DataInput {
return temp != 0;
}
- /**
- * Reads an 8-bit byte value from this stream.
- *
- * @return the next byte value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before one byte
- * has been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeByte(int)
- */
public final byte readByte() throws IOException {
int temp = in.read();
if (temp < 0) {
@@ -133,175 +113,31 @@ public class DataInputStream extends FilterInputStream implements DataInput {
return (byte) temp;
}
- /**
- * Reads a 16-bit character value from this stream.
- *
- * @return the next char value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before two bytes
- * have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeChar(int)
- */
public final char readChar() throws IOException {
- if (readToBuff(2) < 0){
- throw new EOFException();
- }
- return (char) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
-
+ return (char) readShort();
}
- private int readToBuff(int count) throws IOException {
- int offset = 0;
-
- while(offset < count) {
- int bytesRead = in.read(buff, offset, count - offset);
- if(bytesRead == -1) return bytesRead;
- offset += bytesRead;
- }
- return offset;
- }
-
- /**
- * Reads a 64-bit double value from this stream.
- *
- * @return the next double value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before eight
- * bytes have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeDouble(double)
- */
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
- /**
- * Reads a 32-bit float value from this stream.
- *
- * @return the next float value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before four
- * bytes have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeFloat(float)
- */
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
- /**
- * Reads bytes from this stream into the byte array {@code buffer}. This
- * method will block until {@code buffer.length} number of bytes have been
- * read.
- *
- * @param buffer
- * to read bytes into.
- * @throws EOFException
- * if the end of the source stream is reached before enough
- * bytes have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#write(byte[])
- * @see DataOutput#write(byte[], int, int)
- */
- public final void readFully(byte[] buffer) throws IOException {
- readFully(buffer, 0, buffer.length);
+ public final void readFully(byte[] dst) throws IOException {
+ readFully(dst, 0, dst.length);
}
- /**
- * Reads bytes from this stream and stores them in the byte array {@code
- * buffer} starting at the position {@code offset}. This method blocks until
- * {@code length} bytes have been read. If {@code length} is zero, then this
- * method returns without reading any bytes.
- *
- * @param buffer
- * the byte array into which the data is read.
- * @param offset
- * the offset in {@code buffer} from where to store the bytes
- * read.
- * @param length
- * the maximum number of bytes to read.
- * @throws EOFException
- * if the end of the source stream is reached before enough
- * bytes have been read.
- * @throws IndexOutOfBoundsException
- * if {@code offset < 0} or {@code length < 0}, or if {@code
- * offset + length} is greater than the size of {@code buffer}.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @throws NullPointerException
- * if {@code buffer} or the source stream are null.
- * @see java.io.DataInput#readFully(byte[], int, int)
- */
- public final void readFully(byte[] buffer, int offset, int length) throws IOException {
- // BEGIN android-removed
- // if (length < 0) {
- // throw new IndexOutOfBoundsException();
- // }
- // END android-removed
- if (length == 0) {
- return;
- }
- if (in == null) {
- throw new NullPointerException("in == null");
- }
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // used (offset | length) < 0 instead of separate (offset < 0) and
- // (length < 0) check to safe one operation
- if ((offset | length) < 0 || offset > buffer.length - length) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
- while (length > 0) {
- int result = in.read(buffer, offset, length);
- if (result < 0) {
- throw new EOFException();
- }
- offset += result;
- length -= result;
- }
+ public final void readFully(byte[] dst, int offset, int byteCount) throws IOException {
+ Streams.readFully(in, dst, offset, byteCount);
}
- /**
- * Reads a 32-bit integer value from this stream.
- *
- * @return the next int value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before four
- * bytes have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeInt(int)
- */
public final int readInt() throws IOException {
- if (readToBuff(4) < 0){
- throw new EOFException();
- }
- return ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16) |
- ((buff[2] & 0xff) << 8) | (buff[3] & 0xff);
+ Streams.readFully(in, scratch, 0, SizeOf.INT);
+ return OSMemory.peekInt(scratch, 0, ByteOrder.BIG_ENDIAN);
}
- /**
- * Returns a string that contains the next line of text available from the
- * source stream. A line is represented by zero or more characters followed
- * by {@code '\n'}, {@code '\r'}, {@code "\r\n"} or the end of the stream.
- * The string does not include the newline sequence.
- *
- * @return the contents of the line or {@code null} if no characters were
- * read before the end of the source stream has been reached.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @deprecated Use {@link BufferedReader}
- */
@Deprecated
public final String readLine() throws IOException {
StringBuilder line = new StringBuilder(80); // Typical line length
@@ -337,59 +173,16 @@ public class DataInputStream extends FilterInputStream implements DataInput {
}
}
- /**
- * Reads a 64-bit long value from this stream.
- *
- * @return the next long value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before eight
- * bytes have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeLong(long)
- */
public final long readLong() throws IOException {
- if (readToBuff(8) < 0){
- throw new EOFException();
- }
- int i1 = ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16) |
- ((buff[2] & 0xff) << 8) | (buff[3] & 0xff);
- int i2 = ((buff[4] & 0xff) << 24) | ((buff[5] & 0xff) << 16) |
- ((buff[6] & 0xff) << 8) | (buff[7] & 0xff);
-
- return ((i1 & 0xffffffffL) << 32) | (i2 & 0xffffffffL);
+ Streams.readFully(in, scratch, 0, SizeOf.LONG);
+ return OSMemory.peekLong(scratch, 0, ByteOrder.BIG_ENDIAN);
}
- /**
- * Reads a 16-bit short value from this stream.
- *
- * @return the next short value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before two bytes
- * have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeShort(int)
- */
public final short readShort() throws IOException {
- if (readToBuff(2) < 0){
- throw new EOFException();
- }
- return (short) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
+ Streams.readFully(in, scratch, 0, SizeOf.SHORT);
+ return OSMemory.peekShort(scratch, 0, ByteOrder.BIG_ENDIAN);
}
- /**
- * Reads an unsigned 8-bit byte value from this stream and returns it as an
- * int.
- *
- * @return the next unsigned byte value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream has been reached before one
- * byte has been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeByte(int)
- */
public final int readUnsignedByte() throws IOException {
int temp = in.read();
if (temp < 0) {
@@ -398,42 +191,14 @@ public class DataInputStream extends FilterInputStream implements DataInput {
return temp;
}
- /**
- * Reads a 16-bit unsigned short value from this stream and returns it as an
- * int.
- *
- * @return the next unsigned short value from the source stream.
- * @throws EOFException
- * if the end of the filtered stream is reached before two bytes
- * have been read.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeShort(int)
- */
public final int readUnsignedShort() throws IOException {
- if (readToBuff(2) < 0){
- throw new EOFException();
- }
- return (char) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
+ return ((int) readShort()) & 0xffff;
}
- /**
- * Reads an string encoded in {@link DataInput modified UTF-8} from this
- * stream.
- *
- * @return the next {@link DataInput MUTF-8} encoded string read from the
- * source stream.
- * @throws EOFException if the end of the input is reached before the read
- * request can be satisfied.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutput#writeUTF(java.lang.String)
- */
public final String readUTF() throws IOException {
return decodeUTF(readUnsignedShort());
}
-
String decodeUTF(int utfSize) throws IOException {
return decodeUTF(utfSize, this);
}
@@ -444,18 +209,6 @@ public class DataInputStream extends FilterInputStream implements DataInput {
return ModifiedUtf8.decode(buf, new char[utfSize], 0, utfSize);
}
- /**
- * Reads a string encoded in {@link DataInput modified UTF-8} from the
- * {@code DataInput} stream {@code in}.
- *
- * @param in
- * the input stream to read from.
- * @return the next {@link DataInput MUTF-8} encoded string from the source
- * stream.
- * @throws IOException
- * if a problem occurs while reading from this stream.
- * @see DataOutputStream#writeUTF(java.lang.String)
- */
public static final String readUTF(DataInput in) throws IOException {
return decodeUTF(in.readUnsignedShort(), in);
}
@@ -481,11 +234,6 @@ public class DataInputStream extends FilterInputStream implements DataInput {
while (skipped < count && (skip = in.skip(count - skipped)) != 0) {
skipped += skip;
}
- // BEGIN android-removed
- // if (skipped < 0) {
- // throw new EOFException();
- // }
- // END android-removed
return skipped;
}
}
diff --git a/luni/src/main/java/java/io/DataOutput.java b/luni/src/main/java/java/io/DataOutput.java
index 8275958..62a5cd2 100644
--- a/luni/src/main/java/java/io/DataOutput.java
+++ b/luni/src/main/java/java/io/DataOutput.java
@@ -18,7 +18,7 @@
package java.io;
/**
- * Defines an interface for classes that are able to write typed data to some
+ * Defines an interface for classes that are able to write big-endian typed data to some
* target. Typically, this data can be read in by a class which implements
* DataInput. Types that can be written include byte, 16-bit short, 32-bit int,
* 32-bit float, 64-bit long, 64-bit double, byte strings, and {@link DataInput
@@ -37,8 +37,6 @@ public interface DataOutput {
* the buffer to write.
* @throws IOException
* if an I/O error occurs while writing.
- * @see DataInput#readFully(byte[])
- * @see DataInput#readFully(byte[], int, int)
*/
public abstract void write(byte[] buffer) throws IOException;
@@ -54,13 +52,8 @@ public interface DataOutput {
* the number of bytes from the {@code buffer} to write.
* @throws IOException
* if an I/O error occurs while writing.
- * @see DataInput#readFully(byte[])
- * @see DataInput#readFully(byte[], int, int)
*/
public abstract void write(byte[] buffer, int offset, int count) throws IOException;
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
/**
* Writes the specified 8-bit byte.
@@ -103,15 +96,12 @@ public interface DataOutput {
* the string containing the bytes to write.
* @throws IOException
* if an I/O error occurs while writing.
- * @see DataInput#readFully(byte[])
- * @see DataInput#readFully(byte[],int,int)
*/
public abstract void writeBytes(String str) throws IOException;
/**
- * Writes the specified 16-bit character. Only the two least significant
- * bytes of the integer {@code oneByte} are written, with the higher one
- * written first. This represents the Unicode value of the char.
+ * Writes the specified 16-bit character in big-endian order. Only the two least significant
+ * bytes of the integer {@code oneByte} are written.
*
* @param val
* the character to write.
@@ -122,7 +112,7 @@ public interface DataOutput {
public abstract void writeChar(int val) throws IOException;
/**
- * Writes the 16-bit characters contained in {@code str}.
+ * Writes the 16-bit characters contained in {@code str} in big-endian order.
*
* @param str
* the string that contains the characters to write.
@@ -133,7 +123,7 @@ public interface DataOutput {
public abstract void writeChars(String str) throws IOException;
/**
- * Writes the specified 64-bit double. The resulting output is the eight
+ * Writes the specified 64-bit double in big-endian order. The resulting output is the eight
* bytes returned by {@link Double#doubleToLongBits(double)}.
*
* @param val
@@ -145,7 +135,7 @@ public interface DataOutput {
public abstract void writeDouble(double val) throws IOException;
/**
- * Writes the specified 32-bit float. The resulting output is the four bytes
+ * Writes the specified 32-bit float in big-endian order. The resulting output is the four bytes
* returned by {@link Float#floatToIntBits(float)}.
*
* @param val
@@ -157,8 +147,7 @@ public interface DataOutput {
public abstract void writeFloat(float val) throws IOException;
/**
- * Writes the specified 32-bit int. The resulting output is the four bytes,
- * highest order first, of {@code val}.
+ * Writes the specified 32-bit int in big-endian order.
*
* @param val
* the int to write.
@@ -169,8 +158,7 @@ public interface DataOutput {
public abstract void writeInt(int val) throws IOException;
/**
- * Writes the specified 64-bit long. The resulting output is the eight
- * bytes, highest order first, of {@code val}.
+ * Writes the specified 64-bit long in big-endian order.
*
* @param val
* the long to write.
@@ -181,8 +169,8 @@ public interface DataOutput {
public abstract void writeLong(long val) throws IOException;
/**
- * Writes the specified 16-bit short. Only the lower two bytes of {@code
- * val} are written with the higher one written first.
+ * Writes the specified 16-bit short in big-endian order. Only the lower two bytes of {@code
+ * val} are written.
*
* @param val
* the short to write.
diff --git a/luni/src/main/java/java/io/DataOutputStream.java b/luni/src/main/java/java/io/DataOutputStream.java
index c96b7bf..cc34278 100644
--- a/luni/src/main/java/java/io/DataOutputStream.java
+++ b/luni/src/main/java/java/io/DataOutputStream.java
@@ -17,8 +17,13 @@
package java.io;
+import java.nio.ByteOrder;
+import java.nio.charset.ModifiedUtf8;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
+
/**
- * Wraps an existing {@link OutputStream} and writes typed data to it.
+ * Wraps an existing {@link OutputStream} and writes big-endian typed data to it.
* Typically, this stream can be read in by DataInputStream. Types that can be
* written include byte, 16-bit short, 32-bit int, 32-bit float, 64-bit long,
* 64-bit double, byte strings, and {@link DataInput MUTF-8} encoded strings.
@@ -26,12 +31,12 @@ package java.io;
* @see DataInputStream
*/
public class DataOutputStream extends FilterOutputStream implements DataOutput {
+ private final byte[] scratch = new byte[8];
/**
* The number of bytes written out so far.
*/
protected int written;
- byte[] buff;
/**
* Constructs a new {@code DataOutputStream} on the {@code OutputStream}
@@ -44,7 +49,6 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
*/
public DataOutputStream(OutputStream out) {
super(out);
- buff = new byte[8];
}
/**
@@ -85,14 +89,9 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
* if an error occurs while writing to the target stream.
* @throws NullPointerException
* if {@code buffer} is {@code null}.
- * @see DataInputStream#readFully(byte[])
- * @see DataInputStream#readFully(byte[], int, int)
*/
@Override
public void write(byte[] buffer, int offset, int count) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
if (buffer == null) {
throw new NullPointerException("buffer == null");
}
@@ -146,16 +145,6 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
written++;
}
- /**
- * Writes the low order bytes from a string to the target stream.
- *
- * @param str
- * the string containing the bytes to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readFully(byte[])
- * @see DataInputStream#readFully(byte[],int,int)
- */
public final void writeBytes(String str) throws IOException {
if (str.length() == 0) {
return;
@@ -168,217 +157,43 @@ public class DataOutputStream extends FilterOutputStream implements DataOutput {
written += bytes.length;
}
- /**
- * Writes a 16-bit character to the target stream. Only the two lower bytes
- * of the integer {@code val} are written, with the higher one written
- * first. This corresponds to the Unicode value of {@code val}.
- *
- * @param val
- * the character to write to the target stream
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readChar()
- */
public final void writeChar(int val) throws IOException {
- buff[0] = (byte) (val >> 8);
- buff[1] = (byte) val;
- out.write(buff, 0, 2);
- written += 2;
+ writeShort(val);
}
- /**
- * Writes the 16-bit characters contained in {@code str} to the target
- * stream.
- *
- * @param str
- * the string that contains the characters to write to this
- * stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readChar()
- */
public final void writeChars(String str) throws IOException {
- byte[] newBytes = new byte[str.length() * 2];
- for (int index = 0; index < str.length(); index++) {
- int newIndex = index == 0 ? index : index * 2;
- newBytes[newIndex] = (byte) (str.charAt(index) >> 8);
- newBytes[newIndex + 1] = (byte) str.charAt(index);
- }
- out.write(newBytes);
- written += newBytes.length;
+ byte[] bytes = str.getBytes("UTF-16BE");
+ out.write(bytes);
+ written += bytes.length;
}
- /**
- * Writes a 64-bit double to the target stream. The resulting output is the
- * eight bytes resulting from calling Double.doubleToLongBits().
- *
- * @param val
- * the double to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readDouble()
- */
public final void writeDouble(double val) throws IOException {
writeLong(Double.doubleToLongBits(val));
}
- /**
- * Writes a 32-bit float to the target stream. The resulting output is the
- * four bytes resulting from calling Float.floatToIntBits().
- *
- * @param val
- * the float to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readFloat()
- */
public final void writeFloat(float val) throws IOException {
writeInt(Float.floatToIntBits(val));
}
- /**
- * Writes a 32-bit int to the target stream. The resulting output is the
- * four bytes, highest order first, of {@code val}.
- *
- * @param val
- * the int to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readInt()
- */
public final void writeInt(int val) throws IOException {
- buff[0] = (byte) (val >> 24);
- buff[1] = (byte) (val >> 16);
- buff[2] = (byte) (val >> 8);
- buff[3] = (byte) val;
- out.write(buff, 0, 4);
- written += 4;
+ OSMemory.pokeInt(scratch, 0, val, ByteOrder.BIG_ENDIAN);
+ out.write(scratch, 0, SizeOf.INT);
+ written += SizeOf.INT;
}
- /**
- * Writes a 64-bit long to the target stream. The resulting output is the
- * eight bytes, highest order first, of {@code val}.
- *
- * @param val
- * the long to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readLong()
- */
public final void writeLong(long val) throws IOException {
- buff[0] = (byte) (val >> 56);
- buff[1] = (byte) (val >> 48);
- buff[2] = (byte) (val >> 40);
- buff[3] = (byte) (val >> 32);
- buff[4] = (byte) (val >> 24);
- buff[5] = (byte) (val >> 16);
- buff[6] = (byte) (val >> 8);
- buff[7] = (byte) val;
- out.write(buff, 0, 8);
- written += 8;
- }
-
- int writeLongToBuffer(long val,
- byte[] buffer, int offset) throws IOException {
- buffer[offset++] = (byte) (val >> 56);
- buffer[offset++] = (byte) (val >> 48);
- buffer[offset++] = (byte) (val >> 40);
- buffer[offset++] = (byte) (val >> 32);
- buffer[offset++] = (byte) (val >> 24);
- buffer[offset++] = (byte) (val >> 16);
- buffer[offset++] = (byte) (val >> 8);
- buffer[offset++] = (byte) val;
- return offset;
+ OSMemory.pokeLong(scratch, 0, val, ByteOrder.BIG_ENDIAN);
+ out.write(scratch, 0, SizeOf.LONG);
+ written += SizeOf.LONG;
}
- /**
- * Writes the specified 16-bit short to the target stream. Only the lower
- * two bytes of the integer {@code val} are written, with the higher one
- * written first.
- *
- * @param val
- * the short to write to the target stream.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @see DataInputStream#readShort()
- * @see DataInputStream#readUnsignedShort()
- */
public final void writeShort(int val) throws IOException {
- buff[0] = (byte) (val >> 8);
- buff[1] = (byte) val;
- out.write(buff, 0, 2);
- written += 2;
- }
-
- int writeShortToBuffer(int val,
- byte[] buffer, int offset) throws IOException {
- buffer[offset++] = (byte) (val >> 8);
- buffer[offset++] = (byte) val;
- return offset;
+ OSMemory.pokeShort(scratch, 0, (short) val, ByteOrder.BIG_ENDIAN);
+ out.write(scratch, 0, SizeOf.SHORT);
+ written += SizeOf.SHORT;
}
- /**
- * Writes the specified encoded in {@link DataInput modified UTF-8} to this
- * stream.
- *
- * @param str
- * the string to write to the target stream encoded in
- * {@link DataInput modified UTF-8}.
- * @throws IOException
- * if an error occurs while writing to the target stream.
- * @throws UTFDataFormatException
- * if the encoded string is longer than 65535 bytes.
- * @see DataInputStream#readUTF()
- */
public final void writeUTF(String str) throws IOException {
- long utfCount = countUTFBytes(str);
- if (utfCount > 65535) {
- throw new UTFDataFormatException("String more than 65535 UTF bytes long");
- }
- byte[] buffer = new byte[(int)utfCount + 2];
- int offset = 0;
- offset = writeShortToBuffer((int) utfCount, buffer, offset);
- // BEGIN android-changed
- // removed unused parameter count
- offset = writeUTFBytesToBuffer(str, buffer, offset);
- // BEGIN android-changed
- write(buffer, 0, offset);
- }
-
- long countUTFBytes(String str) {
- int utfCount = 0, length = str.length();
- for (int i = 0; i < length; i++) {
- int charValue = str.charAt(i);
- if (charValue > 0 && charValue <= 127) {
- utfCount++;
- } else if (charValue <= 2047) {
- utfCount += 2;
- } else {
- utfCount += 3;
- }
- }
- return utfCount;
- }
-
- int writeUTFBytesToBuffer(String str,
- byte[] buffer, int offset) throws IOException {
- // BEGIN android-note
- // removed unused parameter count
- // END android-note
- int length = str.length();
- for (int i = 0; i < length; i++) {
- int charValue = str.charAt(i);
- if (charValue > 0 && charValue <= 127) {
- buffer[offset++] = (byte) charValue;
- } else if (charValue <= 2047) {
- buffer[offset++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
- buffer[offset++] = (byte) (0x80 | (0x3f & charValue));
- } else {
- buffer[offset++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
- buffer[offset++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
- buffer[offset++] = (byte) (0x80 | (0x3f & charValue));
- }
- }
- return offset;
+ write(ModifiedUtf8.encode(str));
}
}
diff --git a/luni/src/main/java/java/io/EmulatedFieldsForDumping.java b/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
index 8903537..9b51dc1 100644
--- a/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
+++ b/luni/src/main/java/java/io/EmulatedFieldsForDumping.java
@@ -27,6 +27,8 @@ package java.io;
* @see EmulatedFieldsForLoading
*/
class EmulatedFieldsForDumping extends ObjectOutputStream.PutField {
+ // Record the ObjectOutputStream that created this PutField for checking in 'write'.
+ private final ObjectOutputStream oos;
// The actual representation, with a more powerful API (set&get)
private EmulatedFields emulatedFields;
@@ -38,10 +40,9 @@ class EmulatedFieldsForDumping extends ObjectOutputStream.PutField {
* a ObjectStreamClass, which describe the fields to be emulated
* (names, types, etc).
*/
- EmulatedFieldsForDumping(ObjectStreamClass streamClass) {
- super();
- emulatedFields = new EmulatedFields(streamClass.fields(),
- (ObjectStreamField[]) null);
+ EmulatedFieldsForDumping(ObjectOutputStream oos, ObjectStreamClass streamClass) {
+ this.oos = oos;
+ this.emulatedFields = new EmulatedFields(streamClass.fields(), (ObjectStreamField[]) null);
}
/**
@@ -193,36 +194,28 @@ class EmulatedFieldsForDumping extends ObjectOutputStream.PutField {
@Override
@Deprecated
public void write(ObjectOutput output) throws IOException {
- EmulatedFields.ObjectSlot[] slots = emulatedFields.slots();
- for (int i = 0; i < slots.length; i++) {
- EmulatedFields.ObjectSlot slot = slots[i];
+ if (!output.equals(oos)) {
+ throw new IllegalArgumentException("Attempting to write to a different stream than the one that created this PutField");
+ }
+ for (EmulatedFields.ObjectSlot slot : emulatedFields.slots()) {
Object fieldValue = slot.getFieldValue();
Class<?> type = slot.getField().getType();
- // WARNING - default values exist for each primitive type
if (type == Integer.TYPE) {
- output.writeInt(fieldValue != null ? ((Integer) fieldValue)
- .intValue() : 0);
+ output.writeInt(fieldValue != null ? ((Integer) fieldValue).intValue() : 0);
} else if (type == Byte.TYPE) {
- output.writeByte(fieldValue != null ? ((Byte) fieldValue)
- .byteValue() : (byte) 0);
+ output.writeByte(fieldValue != null ? ((Byte) fieldValue).byteValue() : 0);
} else if (type == Character.TYPE) {
- output.writeChar(fieldValue != null ? ((Character) fieldValue)
- .charValue() : (char) 0);
+ output.writeChar(fieldValue != null ? ((Character) fieldValue).charValue() : 0);
} else if (type == Short.TYPE) {
- output.writeShort(fieldValue != null ? ((Short) fieldValue)
- .shortValue() : (short) 0);
+ output.writeShort(fieldValue != null ? ((Short) fieldValue).shortValue() : 0);
} else if (type == Boolean.TYPE) {
- output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue)
- .booleanValue() : false);
+ output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue).booleanValue() : false);
} else if (type == Long.TYPE) {
- output.writeLong(fieldValue != null ? ((Long) fieldValue)
- .longValue() : (long) 0);
+ output.writeLong(fieldValue != null ? ((Long) fieldValue).longValue() : 0);
} else if (type == Float.TYPE) {
- output.writeFloat(fieldValue != null ? ((Float) fieldValue)
- .floatValue() : (float) 0);
+ output.writeFloat(fieldValue != null ? ((Float) fieldValue).floatValue() : 0);
} else if (type == Double.TYPE) {
- output.writeDouble(fieldValue != null ? ((Double) fieldValue)
- .doubleValue() : (double) 0);
+ output.writeDouble(fieldValue != null ? ((Double) fieldValue).doubleValue() : 0);
} else {
// Either array or Object
output.writeObject(fieldValue);
diff --git a/luni/src/main/java/java/io/File.java b/luni/src/main/java/java/io/File.java
index ffc20aa..1e1d625 100644
--- a/luni/src/main/java/java/io/File.java
+++ b/luni/src/main/java/java/io/File.java
@@ -105,7 +105,7 @@ public class File implements Serializable, Comparable<File> {
/**
* The path we return from getAbsolutePath, and pass down to native code.
*/
- private String absolutePath;
+ private transient String absolutePath;
static {
// The default protection domain grants access to these properties.
@@ -262,8 +262,8 @@ public class File implements Serializable, Comparable<File> {
/**
* Lists the file system roots. The Java platform may support zero or more
* file systems, each with its own platform-dependent root. Further, the
- * canonical pathname of any file on the system will always begin with one
- * of the returned file system roots.
+ * {@link #getCanonicalPath canonical} path of any file on the system will
+ * always begin with one of the returned file system roots.
*
* @return the array of file system roots.
*/
@@ -436,9 +436,12 @@ public class File implements Serializable, Comparable<File> {
private static native boolean existsImpl(String path);
/**
- * Returns the absolute path of this file.
+ * Returns the absolute path of this file. An absolute path is a path that starts at a root
+ * of the file system. On Android, there is only one root: {@code /}.
*
- * @return the absolute file path.
+ * <p>A common use for absolute paths is when passing paths to a {@code Process} as
+ * command-line arguments, to remove the requirement implied by relative paths, that the
+ * child must have the same working directory as its parent.
*/
public String getAbsolutePath() {
return absolutePath;
@@ -446,191 +449,46 @@ public class File implements Serializable, Comparable<File> {
/**
* Returns a new file constructed using the absolute path of this file.
- *
- * @return a new file from this file's absolute path.
- * @see java.lang.SecurityManager#checkPropertyAccess
+ * Equivalent to {@code new File(this.getAbsolutePath())}.
*/
public File getAbsoluteFile() {
return new File(this.getAbsolutePath());
}
/**
- * Returns the absolute path of this file with all references resolved. An
- * <em>absolute</em> path is one that begins at the root of the file
- * system. The canonical path is one in which all references have been
- * resolved. For the cases of '..' and '.', where the file system supports
- * parent and working directory respectively, these are removed and replaced
- * with a direct directory reference. If the file does not exist,
- * getCanonicalPath() may not resolve any references and simply returns an
- * absolute path name or throws an IOException.
+ * Returns the canonical path of this file.
+ * An <i>absolute</i> path is one that begins at the root of the file system.
+ * A <i>canonical</i> path is an absolute path with symbolic links
+ * and references to "." or ".." resolved. If a path element does not exist (or
+ * is not searchable), there is a conflict between interpreting canonicalization
+ * as a textual operation (where "a/../b" is "b" even if "a" does not exist) .
+ *
+ * <p>Most callers should use {@link #getAbsolutePath} instead. A canonical path is
+ * significantly more expensive to compute, and not generally useful. The primary
+ * use for canonical paths is determining whether two paths point to the same file by
+ * comparing the canonicalized paths.
+ *
+ * <p>It can be actively harmful to use a canonical path, specifically because
+ * canonicalization removes symbolic links. It's wise to assume that a symbolic link
+ * is present for a reason, and that that reason is because the link may need to change.
+ * Canonicalization removes this layer of indirection. Good code should generally avoid
+ * caching canonical paths.
*
* @return the canonical path of this file.
* @throws IOException
* if an I/O error occurs.
*/
public String getCanonicalPath() throws IOException {
- // BEGIN android-removed
- // Caching the canonical path is bogus. Users facing specific
- // performance problems can perform their own caching, with
- // eviction strategies that are appropriate for their application.
- // A VM-wide cache with no mechanism to evict stale elements is a
- // disservice to applications that need up-to-date data.
- // String canonPath = FileCanonPathCache.get(absPath);
- // if (canonPath != null) {
- // return canonPath;
- // }
- // END android-removed
-
- // TODO: rewrite getCanonicalPath, resolve, and resolveLink.
-
- String result = absolutePath;
- if (separatorChar == '/') {
- // resolve the full path first
- result = resolveLink(result, result.length(), false);
- // resolve the parent directories
- result = resolve(result);
- }
- int numSeparators = 1;
- for (int i = 0; i < result.length(); ++i) {
- if (result.charAt(i) == separatorChar) {
- numSeparators++;
- }
- }
- int[] sepLocations = new int[numSeparators];
- int rootLoc = 0;
- if (separatorChar != '/') {
- if (result.charAt(0) == '\\') {
- rootLoc = (result.length() > 1 && result.charAt(1) == '\\') ? 1 : 0;
- } else {
- rootLoc = 2; // skip drive i.e. c:
- }
- }
-
- char[] newResult = new char[result.length() + 1];
- int newLength = 0, lastSlash = 0, foundDots = 0;
- sepLocations[lastSlash] = rootLoc;
- for (int i = 0; i <= result.length(); ++i) {
- if (i < rootLoc) {
- newResult[newLength++] = result.charAt(i);
- } else {
- if (i == result.length() || result.charAt(i) == separatorChar) {
- if (i == result.length() && foundDots == 0) {
- break;
- }
- if (foundDots == 1) {
- /* Don't write anything, just reset and continue */
- foundDots = 0;
- continue;
- }
- if (foundDots > 1) {
- /* Go back N levels */
- lastSlash = lastSlash > (foundDots - 1) ? lastSlash - (foundDots - 1) : 0;
- newLength = sepLocations[lastSlash] + 1;
- foundDots = 0;
- continue;
- }
- sepLocations[++lastSlash] = newLength;
- newResult[newLength++] = separatorChar;
- continue;
- }
- if (result.charAt(i) == '.') {
- foundDots++;
- continue;
- }
- /* Found some dots within text, write them out */
- if (foundDots > 0) {
- for (int j = 0; j < foundDots; j++) {
- newResult[newLength++] = '.';
- }
- }
- newResult[newLength++] = result.charAt(i);
- foundDots = 0;
- }
- }
- // remove trailing slash
- if (newLength > (rootLoc + 1) && newResult[newLength - 1] == separatorChar) {
- newLength--;
- }
- return new String(newResult, 0, newLength);
- }
-
- /*
- * Resolve symbolic links in the parent directories.
- */
- private static String resolve(String path) throws IOException {
- int last = 1;
- String linkPath = path;
- String bytes;
- boolean done;
- for (int i = 1; i <= path.length(); i++) {
- if (i == path.length() || path.charAt(i) == separatorChar) {
- done = i >= path.length() - 1;
- // if there is only one segment, do nothing
- if (done && linkPath.length() == 1) {
- return path;
- }
- boolean inPlace = false;
- if (linkPath.equals(path)) {
- bytes = path;
- // if there are no symbolic links, truncate the path instead of copying
- if (!done) {
- inPlace = true;
- path = path.substring(0, i);
- }
- } else {
- int nextSize = i - last + 1;
- int linkSize = linkPath.length();
- if (linkPath.charAt(linkSize - 1) == separatorChar) {
- linkSize--;
- }
- bytes = linkPath.substring(0, linkSize) +
- path.substring(last - 1, last - 1 + nextSize);
- // the full path has already been resolved
- }
- if (done) {
- return bytes;
- }
- linkPath = resolveLink(bytes, inPlace ? i : bytes.length(), true);
- if (inPlace) {
- // path[i] = '/';
- path = path.substring(0, i) + '/' + (i + 1 < path.length() ? path.substring(i + 1) : "");
- }
- last = i + 1;
- }
- }
- throw new InternalError();
+ return realpath(absolutePath);
}
- /*
- * Resolve a symbolic link. While the path resolves to an existing path,
- * keep resolving. If an absolute link is found, resolve the parent
- * directories if resolveAbsolute is true.
+ /**
+ * TODO: move this stuff to libcore.os.
+ * @hide
*/
- private static String resolveLink(String path, int length, boolean resolveAbsolute) throws IOException {
- boolean restart = false;
- do {
- String fragment = path.substring(0, length);
- String target = readlink(fragment);
- if (target.equals(fragment)) {
- break;
- }
- if (target.charAt(0) == separatorChar) {
- // The link target was an absolute path, so we may need to start again.
- restart = resolveAbsolute;
- path = target + path.substring(length);
- } else {
- path = path.substring(0, path.lastIndexOf(separatorChar, length - 1) + 1) + target;
- }
- length = path.length();
- } while (existsImpl(path));
- // resolve the parent directories
- if (restart) {
- return resolve(path);
- }
- return path;
- }
-
- private static native String readlink(String filePath);
+ public static native void symlink(String oldPath, String newPath);
+ private static native String realpath(String path);
+ private static native String readlink(String path);
/**
* Returns a new file created using the canonical path of this file.
diff --git a/luni/src/main/java/java/io/FileInputStream.java b/luni/src/main/java/java/io/FileInputStream.java
index bb8829d..7cdc235 100644
--- a/luni/src/main/java/java/io/FileInputStream.java
+++ b/luni/src/main/java/java/io/FileInputStream.java
@@ -17,44 +17,55 @@
package java.io;
+import dalvik.system.CloseGuard;
+
+import java.nio.NioUtils;
import java.nio.channels.FileChannel;
+import java.util.Arrays;
+
import libcore.io.IoUtils;
import org.apache.harmony.luni.platform.IFileSystem;
import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.nio.FileChannelFactory;
/**
- * A specialized {@link InputStream} that reads from a file in the file system.
- * All read requests made by calling methods in this class are directly
- * forwarded to the equivalent function of the underlying operating system.
- * Since this may induce some performance penalty, in particular if many small
- * read requests are made, a FileInputStream is often wrapped by a
- * BufferedInputStream.
+ * An input stream that reads bytes from a file.
+ * <pre> {@code
+ * File file = ...
+ * InputStream in = null;
+ * try {
+ * in = new BufferedInputStream(new FileInputStream(file));
+ * ...
+ * } finally {
+ * if (in != null) {
+ * in.close();
+ * }
+ * }
+ * }</pre>
+ *
+ * <p>This stream is <strong>not buffered</strong>. Most callers should wrap
+ * this stream with a {@link BufferedInputStream}.
+ *
+ * <p>Use {@link FileReader} to read characters, as opposed to bytes, from a
+ * file.
*
* @see BufferedInputStream
* @see FileOutputStream
*/
public class FileInputStream extends InputStream implements Closeable {
- /**
- * The {@link FileDescriptor} representing this {@code FileInputStream}.
- */
- FileDescriptor fd;
- // The unique file channel associated with this FileInputStream (lazily
- // initialized).
- private FileChannel channel;
+ private final FileDescriptor fd;
- boolean innerFD;
+ /** The unique file channel. Lazily initialized because it's rarely needed. */
+ private FileChannel channel;
- private IFileSystem fileSystem = Platform.getFileSystem();
+ private final boolean shouldCloseFd;
- private static class RepositioningLock {
- }
+ private final Object repositioningLock = new Object();
- private Object repositioningLock = new RepositioningLock();
+ private final CloseGuard guard = CloseGuard.get();
/**
- * Constructs a new {@code FileInputStream} based on {@code file}.
+ * Constructs a new {@code FileInputStream} that reads from {@code file}.
*
* @param file
* the file from which this stream reads.
@@ -65,30 +76,22 @@ public class FileInputStream extends InputStream implements Closeable {
* read request.
*/
public FileInputStream(File file) throws FileNotFoundException {
- super();
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- // For compatibility, nulls are passed to the manager.
- String filePath = (null == file ? null : file.getPath());
- security.checkRead(filePath);
- }
if (file == null) {
throw new NullPointerException("file == null");
}
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ securityManager.checkRead(file.getPath());
+ }
fd = new FileDescriptor();
fd.readOnly = true;
- fd.descriptor = fileSystem.open(file.getAbsolutePath(), IFileSystem.O_RDONLY);
- innerFD = true;
- // BEGIN android-removed
- // channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- // IFileSystem.O_RDONLY);
- // END android-removed
+ fd.descriptor = Platform.FILE_SYSTEM.open(file.getAbsolutePath(), IFileSystem.O_RDONLY);
+ shouldCloseFd = true;
+ guard.open("close");
}
/**
- * Constructs a new {@code FileInputStream} on the {@link FileDescriptor}
- * {@code fd}. The file must already be open, therefore no
- * {@code FileNotFoundException} will be thrown.
+ * Constructs a new {@code FileInputStream} that reads from {@code fd}.
*
* @param fd
* the FileDescriptor from which this stream reads.
@@ -99,64 +102,43 @@ public class FileInputStream extends InputStream implements Closeable {
* read request.
*/
public FileInputStream(FileDescriptor fd) {
- super();
if (fd == null) {
throw new NullPointerException("fd == null");
}
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkRead(fd);
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ securityManager.checkRead(fd);
}
this.fd = fd;
- innerFD = false;
- // BEGIN android-removed
- // channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- // IFileSystem.O_RDONLY);
- // END android-removed
+ this.shouldCloseFd = false;
+ // Note that we do not call guard.open here because the
+ // FileDescriptor is not owned by the stream.
}
/**
- * Constructs a new {@code FileInputStream} on the file named
- * {@code fileName}. The path of {@code fileName} may be absolute or
- * relative to the system property {@code "user.dir"}.
- *
- * @param fileName
- * the path and name of the file from which this stream reads.
- * @throws FileNotFoundException
- * if there is no file named {@code fileName}.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * read request.
+ * Equivalent to {@code new FileInputStream(new File(path))}.
*/
- public FileInputStream(String fileName) throws FileNotFoundException {
- this(null == fileName ? (File) null : new File(fileName));
+ public FileInputStream(String path) throws FileNotFoundException {
+ this(new File(path));
}
@Override
public int available() throws IOException {
- openCheck();
- return fileSystem.ioctlAvailable(fd);
+ checkOpen();
+ return Platform.FILE_SYSTEM.ioctlAvailable(fd);
}
- /**
- * Closes this stream.
- *
- * @throws IOException
- * if an error occurs attempting to close this stream.
- */
@Override
public void close() throws IOException {
- // BEGIN android-changed
+ guard.close();
synchronized (this) {
- if (channel != null && channel.isOpen()) {
+ if (channel != null) {
channel.close();
- channel = null;
}
- if (fd != null && fd.valid() && innerFD) {
+ if (shouldCloseFd && fd.valid()) {
IoUtils.close(fd);
}
}
- // END android-changed
}
/**
@@ -168,168 +150,91 @@ public class FileInputStream extends InputStream implements Closeable {
*/
@Override protected void finalize() throws IOException {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
close();
} finally {
try {
super.finalize();
} catch (Throwable t) {
+ // for consistency with the RI, we must override Object.finalize() to
+ // remove the 'throws Throwable' clause.
throw new AssertionError(t);
}
}
}
/**
- * Returns the {@link FileChannel} equivalent to this input stream.
- * <p>
- * The file channel is read-only and has an initial position within the file
- * that is the same as the current position of this stream within the file.
- * All changes made to the underlying file descriptor state via the channel
- * are visible by the input stream and vice versa.
- *
- * @return the file channel for this stream.
+ * Returns a read-only {@link FileChannel} that shares its position with
+ * this stream.
*/
public FileChannel getChannel() {
- // BEGIN android-changed
- synchronized(this) {
+ synchronized (this) {
if (channel == null) {
- channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- IFileSystem.O_RDONLY);
+ channel = NioUtils.newFileChannel(this, fd.descriptor, IFileSystem.O_RDONLY);
}
return channel;
}
- // END android-changed
}
/**
- * Returns the {@link FileDescriptor} representing the operating system
- * resource for this stream.
- *
- * @return the {@code FileDescriptor} for this stream.
- * @throws IOException
- * if an error occurs while getting this stream's
- * {@code FileDescriptor}.
+ * Returns the underlying file descriptor.
*/
public final FileDescriptor getFD() throws IOException {
return fd;
}
- /**
- * Reads a single byte from this stream and returns it as an integer in the
- * range from 0 to 255. Returns -1 if the end of this stream has been
- * reached.
- *
- * @return the byte read or -1 if the end of this stream has been reached.
- * @throws IOException
- * if this stream is closed or another I/O error occurs.
- */
@Override
public int read() throws IOException {
- byte[] readed = new byte[1];
- int result = read(readed, 0, 1);
- return result == -1 ? -1 : readed[0] & 0xff;
+ byte[] buffer = new byte[1];
+ int result = read(buffer, 0, 1);
+ return result == -1 ? -1 : buffer[0] & 0xff;
}
- /**
- * Reads bytes from this stream and stores them in the byte array
- * {@code buffer}.
- *
- * @param buffer
- * the byte array in which to store the bytes read.
- * @return the number of bytes actually read or -1 if the end of the stream
- * has been reached.
- * @throws IOException
- * if this stream is closed or another I/O error occurs.
- */
@Override
public int read(byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length);
}
- /**
- * Reads at most {@code count} bytes from this stream and stores them in the
- * byte array {@code buffer} starting at {@code offset}.
- *
- * @param buffer
- * the byte array in which to store the bytes read.
- * @param offset
- * the initial position in {@code buffer} to store the bytes read
- * from this stream.
- * @param count
- * the maximum number of bytes to store in {@code buffer}.
- * @return the number of bytes actually read or -1 if the end of the stream
- * has been reached.
- * @throws IndexOutOfBoundsException
- * if {@code offset < 0} or {@code count < 0}, or if
- * {@code offset + count} is greater than the size of
- * {@code buffer}.
- * @throws IOException
- * if the stream is closed or another IOException occurs.
- */
@Override
- public int read(byte[] buffer, int offset, int count) throws IOException {
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit,
- // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
- // to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((count | offset) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
- if (0 == count) {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (byteCount == 0) {
return 0;
}
- openCheck();
+ checkOpen();
synchronized (repositioningLock) {
- // BEGIN android-changed
- // If you only support Linux, there's nothing special about stdin.
- return (int) fileSystem.read(fd.descriptor, buffer, offset, count);
- // END android-changed
+ return (int) Platform.FILE_SYSTEM.read(fd.descriptor, buffer, offset, byteCount);
}
}
- /**
- * Skips {@code count} number of bytes in this stream. Subsequent
- * {@code read()}s will not return these bytes unless {@code reset()} is
- * used. If the underlying stream is unseekable, an IOException is thrown.
- *
- * @param count
- * the number of bytes to skip.
- * @return the number of bytes actually skipped.
- * @throws IOException
- * if {@code count < 0}, this stream is closed or unseekable,
- * or another IOException occurs.
- */
@Override
- public long skip(long count) throws IOException {
- openCheck();
+ public long skip(long byteCount) throws IOException {
+ checkOpen();
- if (count == 0) {
+ if (byteCount == 0) {
return 0;
}
- if (count < 0) {
- throw new IOException("count < 0");
+ if (byteCount < 0) {
+ throw new IOException("byteCount < 0: " + byteCount);
}
- // The RI doesn't treat stdin as special. It throws IOException for
- // all non-seekable streams, so we do too. If you did want to support
- // non-seekable streams, the best way to do it would be to recognize
- // when lseek(2) fails with ESPIPE and call super.skip(count).
- synchronized (repositioningLock) {
- // Our seek returns the new offset, but we know it will throw an
- // exception if it couldn't perform exactly the seek we asked for.
- fileSystem.seek(fd.descriptor, count, IFileSystem.SEEK_CUR);
- return count;
+ try {
+ synchronized (repositioningLock) {
+ // Our seek returns the new offset, but we know it will throw an
+ // exception if it couldn't perform exactly the seek we asked for.
+ Platform.FILE_SYSTEM.seek(fd.descriptor, byteCount, IFileSystem.SEEK_CUR);
+ return byteCount;
+ }
+ } catch (IFileSystem.SeekPipeException e) {
+ return super.skip(byteCount);
}
}
- private synchronized void openCheck() throws IOException {
- if (fd.descriptor < 0) {
- throw new IOException();
+ private synchronized void checkOpen() throws IOException {
+ if (!fd.valid()) {
+ throw new IOException("stream is closed");
}
}
}
diff --git a/luni/src/main/java/java/io/FileOutputStream.java b/luni/src/main/java/java/io/FileOutputStream.java
index 7c73c2e..0c73d0b 100644
--- a/luni/src/main/java/java/io/FileOutputStream.java
+++ b/luni/src/main/java/java/io/FileOutputStream.java
@@ -17,49 +17,60 @@
package java.io;
+import dalvik.system.CloseGuard;
+import java.nio.NioUtils;
import java.nio.channels.FileChannel;
+import java.util.Arrays;
import libcore.io.IoUtils;
import org.apache.harmony.luni.platform.IFileSystem;
import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.nio.FileChannelFactory;
/**
- * A specialized {@link OutputStream} that writes to a file in the file system.
- * All write requests made by calling methods in this class are directly
- * forwarded to the equivalent function of the underlying operating system.
- * Since this may induce some performance penalty, in particular if many small
- * write requests are made, a FileOutputStream is often wrapped by a
- * BufferedOutputStream.
+ * An output stream that writes bytes to a file. If the output file exists, it
+ * can be replaced or appended to. If it does not exist, a new file will be
+ * created.
+ * <pre> {@code
+ * File file = ...
+ * OutputStream out = null;
+ * try {
+ * out = new BufferedOutputStream(new FileOutputStream(file));
+ * ...
+ * } finally {
+ * if (out != null) {
+ * out.close();
+ * }
+ * }
+ * }</pre>
+ *
+ * <p>This stream is <strong>not buffered</strong>. Most callers should wrap
+ * this stream with a {@link BufferedOutputStream}.
+ *
+ * <p>Use {@link FileWriter} to write characters, as opposed to bytes, to a file.
*
* @see BufferedOutputStream
* @see FileInputStream
*/
public class FileOutputStream extends OutputStream implements Closeable {
- /**
- * The FileDescriptor representing this FileOutputStream.
- */
- FileDescriptor fd;
+ private final FileDescriptor fd;
- boolean innerFD;
+ private final boolean shouldCloseFd;
- // The unique file channel associated with this FileInputStream (lazily
- // initialized).
+ /** The unique file channel. Lazily initialized because it's rarely needed. */
private FileChannel channel;
- private IFileSystem fileSystem = Platform.getFileSystem();
+ /** File access mode */
+ private final int mode;
+
+ private final CloseGuard guard = CloseGuard.get();
/**
- * Constructs a new FileOutputStream on the File {@code file}. If the file
- * exists, it is overwritten.
+ * Constructs a new {@code FileOutputStream} that writes to {@code file}.
*
- * @param file
- * the file to which this stream writes.
- * @throws FileNotFoundException
- * if {@code file} cannot be opened for writing.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * write request.
+ * @param file the file to which this stream writes.
+ * @throws FileNotFoundException if file cannot be opened for writing.
+ * @throws SecurityException if a {@code SecurityManager} is installed and
+ * it denies the write request.
* @see java.lang.SecurityManager#checkWrite(FileDescriptor)
*/
public FileOutputStream(File file) throws FileNotFoundException {
@@ -67,129 +78,78 @@ public class FileOutputStream extends OutputStream implements Closeable {
}
/**
- * Constructs a new FileOutputStream on the File {@code file}. The
- * parameter {@code append} determines whether or not the file is opened and
- * appended to or just opened and overwritten.
+ * Constructs a new {@code FileOutputStream} that writes to {@code file},
+ * creating it if necessary. If {@code append} is true and the file already
+ * exists, it will be appended to. Otherwise a new file will be created.
*
- * @param file
- * the file to which this stream writes.
- * @param append
- * indicates whether or not to append to an existing file.
- * @throws FileNotFoundException
- * if the {@code file} cannot be opened for writing.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * write request.
+ * @param file the file to which this stream writes.
+ * @param append true to append to an existing file.
+ * @throws FileNotFoundException if the file cannot be opened for writing.
+ * @throws SecurityException if a {@code SecurityManager} is installed and
+ * it denies the write request.
* @see java.lang.SecurityManager#checkWrite(FileDescriptor)
* @see java.lang.SecurityManager#checkWrite(String)
*/
public FileOutputStream(File file, boolean append)
throws FileNotFoundException {
- super();
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkWrite(file.getPath());
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ securityManager.checkWrite(file.getPath());
}
- fd = new FileDescriptor();
- fd.descriptor = fileSystem.open(file.getAbsolutePath(),
- append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
- innerFD = true;
- channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY);
+ this.fd = new FileDescriptor();
+ this.mode = append ? IFileSystem.O_APPEND : IFileSystem.O_WRONLY;
+ this.fd.descriptor = Platform.FILE_SYSTEM.open(file.getAbsolutePath(), mode);
+ this.shouldCloseFd = true;
+ this.guard.open("close");
}
/**
- * Constructs a new FileOutputStream on the FileDescriptor {@code fd}. The
- * file must already be open, therefore no {@code FileNotFoundException}
- * will be thrown.
+ * Constructs a new {@code FileOutputStream} that writes to {@code fd}.
*
- * @param fd
- * the FileDescriptor to which this stream writes.
- * @throws NullPointerException
- * if {@code fd} is {@code null}.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * write request.
+ * @param fd the FileDescriptor to which this stream writes.
+ * @throws NullPointerException if {@code fd} is null.
+ * @throws SecurityException if a {@code SecurityManager} is installed and
+ * it denies the write request.
* @see java.lang.SecurityManager#checkWrite(FileDescriptor)
*/
public FileOutputStream(FileDescriptor fd) {
- super();
if (fd == null) {
throw new NullPointerException();
}
- SecurityManager security = System.getSecurityManager();
- if (security != null) {
- security.checkWrite(fd);
+ SecurityManager securityManager = System.getSecurityManager();
+ if (securityManager != null) {
+ securityManager.checkWrite(fd);
}
this.fd = fd;
- innerFD = false;
- channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- IFileSystem.O_WRONLY);
+ this.shouldCloseFd = false;
+ this.channel = NioUtils.newFileChannel(this, fd.descriptor, IFileSystem.O_WRONLY);
+ this.mode = IFileSystem.O_WRONLY;
+ // Note that we do not call guard.open here because the
+ // FileDescriptor is not owned by the stream.
}
/**
- * Constructs a new FileOutputStream on the file named {@code filename}. If
- * the file exists, it is overwritten. The {@code filename} may be absolute
- * or relative to the system property {@code "user.dir"}.
- *
- * @param filename
- * the name of the file to which this stream writes.
- * @throws FileNotFoundException
- * if the file cannot be opened for writing.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * write request.
+ * Equivalent to {@code new FileOutputStream(new File(path), false)}.
*/
- public FileOutputStream(String filename) throws FileNotFoundException {
- this(filename, false);
+ public FileOutputStream(String path) throws FileNotFoundException {
+ this(path, false);
}
/**
- * Constructs a new FileOutputStream on the file named {@code filename}.
- * The parameter {@code append} determines whether or not the file is opened
- * and appended to or just opened and overwritten. The {@code filename} may
- * be absolute or relative to the system property {@code "user.dir"}.
- *
- * @param filename
- * the name of the file to which this stream writes.
- * @param append
- * indicates whether or not to append to an existing file.
- * @throws FileNotFoundException
- * if the file cannot be opened for writing.
- * @throws SecurityException
- * if a {@code SecurityManager} is installed and it denies the
- * write request.
+ * Equivalent to {@code new FileOutputStream(new File(path), append)}.
*/
- public FileOutputStream(String filename, boolean append)
- throws FileNotFoundException {
- this(new File(filename), append);
+ public FileOutputStream(String path, boolean append) throws FileNotFoundException {
+ this(new File(path), append);
}
- /**
- * Closes this stream. This implementation closes the underlying operating
- * system resources allocated to represent this stream.
- *
- * @throws IOException
- * if an error occurs attempting to close this stream.
- */
@Override
public void close() throws IOException {
- if (fd == null) {
- // if fd is null, then the underlying file is not opened, so nothing
- // to close
- return;
- }
-
- if (channel != null) {
- synchronized (channel) {
- if (channel.isOpen() && fd.descriptor >= 0) {
- channel.close();
- }
- }
- }
-
+ guard.close();
synchronized (this) {
- if (fd.valid() && innerFD) {
+ if (channel != null) {
+ channel.close();
+ }
+ if (shouldCloseFd && fd.valid()) {
IoUtils.close(fd);
}
}
@@ -204,123 +164,66 @@ public class FileOutputStream extends OutputStream implements Closeable {
*/
@Override protected void finalize() throws IOException {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
close();
} finally {
try {
super.finalize();
} catch (Throwable t) {
+ // for consistency with the RI, we must override Object.finalize() to
+ // remove the 'throws Throwable' clause.
throw new AssertionError(t);
}
}
}
/**
- * Returns the FileChannel equivalent to this output stream.
- * <p>
- * The file channel is write-only and has an initial position within the
- * file that is the same as the current position of this stream within the
- * file. All changes made to the underlying file descriptor state via the
- * channel are visible by the output stream and vice versa.
- *
- * @return the file channel representation for this stream.
+ * Returns a write-only {@link FileChannel} that shares its position with
+ * this stream.
*/
public FileChannel getChannel() {
- return channel;
+ synchronized (this) {
+ if (channel == null) {
+ channel = NioUtils.newFileChannel(this, fd.descriptor, mode);
+ }
+ return channel;
+ }
}
/**
- * Returns a FileDescriptor which represents the lowest level representation
- * of an operating system stream resource.
- *
- * @return a FileDescriptor representing this stream.
- * @throws IOException
- * if an error occurs attempting to get the FileDescriptor of
- * this stream.
+ * Returns the underlying file descriptor.
*/
public final FileDescriptor getFD() throws IOException {
return fd;
}
- /**
- * Writes the entire contents of the byte array {@code buffer} to this
- * stream.
- *
- * @param buffer
- * the buffer to be written to the file.
- * @throws IOException
- * if this stream is closed or an error occurs attempting to
- * write to this stream.
- */
@Override
public void write(byte[] buffer) throws IOException {
write(buffer, 0, buffer.length);
}
- /**
- * Writes {@code count} bytes from the byte array {@code buffer} starting at
- * {@code offset} to this stream.
- *
- * @param buffer
- * the buffer to write to this stream.
- * @param offset
- * the index of the first byte in {@code buffer} to write.
- * @param count
- * the number of bytes from {@code buffer} to write.
- * @throws IndexOutOfBoundsException
- * if {@code count < 0} or {@code offset < 0}, or if
- * {@code count + offset} is greater than the length of
- * {@code buffer}.
- * @throws IOException
- * if this stream is closed or an error occurs attempting to
- * write to this stream.
- * @throws NullPointerException
- * if {@code buffer} is {@code null}.
- */
@Override
- public void write(byte[] buffer, int offset, int count) throws IOException {
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, made implicit null check explicit,
- // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
- // to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((count | offset) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
-
- if (count == 0) {
+ public void write(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (byteCount == 0) {
return;
}
-
- openCheck();
- fileSystem.write(fd.descriptor, buffer, offset, count);
+ checkOpen();
+ Platform.FILE_SYSTEM.write(fd.descriptor, buffer, offset, byteCount);
}
- /**
- * Writes the specified byte {@code oneByte} to this stream. Only the low
- * order byte of the integer {@code oneByte} is written.
- *
- * @param oneByte
- * the byte to be written.
- * @throws IOException
- * if this stream is closed an error occurs attempting to write
- * to this stream.
- */
@Override
public void write(int oneByte) throws IOException {
- openCheck();
- byte[] byteArray = new byte[1];
- byteArray[0] = (byte) oneByte;
- fileSystem.write(fd.descriptor, byteArray, 0, 1);
+ checkOpen();
+ byte[] buffer = { (byte) oneByte };
+ Platform.FILE_SYSTEM.write(fd.descriptor, buffer, 0, 1);
}
- private synchronized void openCheck() throws IOException {
- if (fd.descriptor < 0) {
- throw new IOException();
+ private synchronized void checkOpen() throws IOException {
+ if (!fd.valid()) {
+ throw new IOException("stream is closed");
}
}
}
diff --git a/luni/src/main/java/java/io/FilterInputStream.java b/luni/src/main/java/java/io/FilterInputStream.java
index 75b312c..a6f6852 100644
--- a/luni/src/main/java/java/io/FilterInputStream.java
+++ b/luni/src/main/java/java/io/FilterInputStream.java
@@ -174,13 +174,11 @@ public class FilterInputStream extends InputStream {
}
/**
- * Skips {@code count} number of bytes in this stream. Subsequent
- * {@code read()}'s will not return these bytes unless {@code reset()} is
- * used. This implementation skips {@code count} number of bytes in the
+ * Skips {@code byteCount} bytes in this stream. Subsequent
+ * calls to {@code read} will not return these bytes unless {@code reset} is
+ * used. This implementation skips {@code byteCount} bytes in the
* filtered stream.
*
- * @param count
- * the number of bytes to skip.
* @return the number of bytes actually skipped.
* @throws IOException
* if this stream is closed or another IOException occurs.
@@ -188,7 +186,7 @@ public class FilterInputStream extends InputStream {
* @see #reset()
*/
@Override
- public long skip(long count) throws IOException {
- return in.skip(count);
+ public long skip(long byteCount) throws IOException {
+ return in.skip(byteCount);
}
}
diff --git a/luni/src/main/java/java/io/FilterOutputStream.java b/luni/src/main/java/java/io/FilterOutputStream.java
index d8f7a49..24adf87 100644
--- a/luni/src/main/java/java/io/FilterOutputStream.java
+++ b/luni/src/main/java/java/io/FilterOutputStream.java
@@ -17,6 +17,7 @@
package java.io;
+import java.util.Arrays;
import org.apache.harmony.luni.util.SneakyThrow;
/**
@@ -124,16 +125,7 @@ public class FilterOutputStream extends OutputStream {
*/
@Override
public void write(byte[] buffer, int offset, int length) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- // Force null buffer check first!
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
for (int i = 0; i < length; i++) {
// Call write() instead of out.write() since subclasses could
// override the write() method.
diff --git a/luni/src/main/java/java/io/FilterReader.java b/luni/src/main/java/java/io/FilterReader.java
index 09ace31..43beb8c 100644
--- a/luni/src/main/java/java/io/FilterReader.java
+++ b/luni/src/main/java/java/io/FilterReader.java
@@ -179,12 +179,10 @@ public abstract class FilterReader extends Reader {
}
/**
- * Skips {@code count} characters in this reader. Subsequent {@code read()}'s
- * will not return these characters unless {@code reset()} is used. The
+ * Skips {@code charCount} characters in this reader. Subsequent calls to {@code read}
+ * will not return these characters unless {@code reset} is used. The
* default implementation is to skip characters in the filtered reader.
*
- * @param count
- * the maximum number of characters to skip.
* @return the number of characters actually skipped.
* @throws IOException
* if the filtered reader is closed or some other I/O error
@@ -194,9 +192,9 @@ public abstract class FilterReader extends Reader {
* @see #reset()
*/
@Override
- public long skip(long count) throws IOException {
+ public long skip(long charCount) throws IOException {
synchronized (lock) {
- return in.skip(count);
+ return in.skip(charCount);
}
}
}
diff --git a/luni/src/main/java/java/io/InputStream.java b/luni/src/main/java/java/io/InputStream.java
index 6e4f561..182bf95 100644
--- a/luni/src/main/java/java/io/InputStream.java
+++ b/luni/src/main/java/java/io/InputStream.java
@@ -17,6 +17,7 @@
package java.io;
+import java.util.Arrays;
import libcore.base.Streams;
/**
@@ -161,7 +162,7 @@ public abstract class InputStream extends Object implements Closeable {
* Reads at most {@code length} bytes from this stream and stores them in
* the byte array {@code b} starting at {@code offset}.
*
- * @param b
+ * @param buffer
* the byte array in which to store the bytes read.
* @param offset
* the initial position in {@code buffer} to store the bytes read
@@ -177,17 +178,8 @@ public abstract class InputStream extends Object implements Closeable {
* @throws IOException
* if the stream is closed or another IOException occurs.
*/
- public int read(byte[] b, int offset, int length) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- // Force null check for b first!
- if (offset > b.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > b.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ public int read(byte[] buffer, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
for (int i = 0; i < length; i++) {
int c;
try {
@@ -200,7 +192,7 @@ public abstract class InputStream extends Object implements Closeable {
}
throw e;
}
- b[offset + i] = (byte) c;
+ buffer[offset + i] = (byte) c;
}
return length;
}
@@ -223,7 +215,7 @@ public abstract class InputStream extends Object implements Closeable {
/**
* Skips at most {@code n} bytes in this stream. This method does nothing and returns
- * 0 if {@code n} is negative.
+ * 0 if {@code n} is negative, but some subclasses may throw.
*
* <p>Note the "at most" in the description of this method: this method may choose to skip
* fewer bytes than requested. Callers should <i>always</i> check the return value.
diff --git a/luni/src/main/java/java/io/InputStreamReader.java b/luni/src/main/java/java/io/InputStreamReader.java
index 4402d1d..28091e3 100644
--- a/luni/src/main/java/java/io/InputStreamReader.java
+++ b/luni/src/main/java/java/io/InputStreamReader.java
@@ -25,6 +25,7 @@ import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.MalformedInputException;
import java.nio.charset.UnmappableCharacterException;
+import java.util.Arrays;
import org.apache.harmony.luni.util.HistoricalNamesUtil;
/**
@@ -217,16 +218,8 @@ public class InputStreamReader extends Reader {
if (!isOpen()) {
throw new IOException("InputStreamReader is closed");
}
- // RI exception compatibility so we can run more tests.
- if (offset < 0) {
- throw new IndexOutOfBoundsException();
- }
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if (length < 0 || offset > buffer.length - length) {
- throw new IndexOutOfBoundsException();
- }
+
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
if (length == 0) {
return 0;
}
diff --git a/luni/src/main/java/java/io/LineNumberInputStream.java b/luni/src/main/java/java/io/LineNumberInputStream.java
index 31828e9..f8b1006 100644
--- a/luni/src/main/java/java/io/LineNumberInputStream.java
+++ b/luni/src/main/java/java/io/LineNumberInputStream.java
@@ -17,6 +17,9 @@
package java.io;
+import java.util.Arrays;
+import libcore.base.Streams;
+
/**
* Wraps an existing {@link InputStream} and counts the line terminators
* encountered while reading the data. Line numbering starts at 0. Recognized
@@ -165,14 +168,7 @@ public class LineNumberInputStream extends FilterInputStream {
*/
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
- // Force buffer null check first!
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
-
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
for (int i = 0; i < length; i++) {
int currentChar;
try {
@@ -225,12 +221,12 @@ public class LineNumberInputStream extends FilterInputStream {
/**
* Skips {@code count} number of bytes in this stream. Subsequent
- * {@code read()}'s will not return these bytes unless {@code reset()} is
- * used. This implementation skips {@code count} number of bytes in the
+ * calls to {@code read} will not return these bytes unless {@code reset} is
+ * used. This implementation skips {@code byteCount} bytes in the
* filtered stream and increments the line number count whenever line
* terminator sequences are skipped.
*
- * @param count
+ * @param byteCount
* the number of bytes to skip.
* @return the number of bytes actually skipped.
* @throws IOException
@@ -240,16 +236,7 @@ public class LineNumberInputStream extends FilterInputStream {
* @see #reset()
*/
@Override
- public long skip(long count) throws IOException {
- if (count <= 0) {
- return 0;
- }
- for (int i = 0; i < count; i++) {
- int currentChar = read();
- if (currentChar == -1) {
- return i;
- }
- }
- return count;
+ public long skip(long byteCount) throws IOException {
+ return Streams.skipByReading(this, byteCount);
}
}
diff --git a/luni/src/main/java/java/io/LineNumberReader.java b/luni/src/main/java/java/io/LineNumberReader.java
index 3b1c8ca..03d02a2 100644
--- a/luni/src/main/java/java/io/LineNumberReader.java
+++ b/luni/src/main/java/java/io/LineNumberReader.java
@@ -242,17 +242,15 @@ public class LineNumberReader extends BufferedReader {
}
/**
- * Skips {@code count} number of characters in this reader. Subsequent
- * {@code read()}'s will not return these characters unless {@code reset()}
- * is used. This implementation skips {@code count} number of characters in
+ * Skips {@code charCount} characters in this reader. Subsequent calls to
+ * {@code read} will not return these characters unless {@code reset}
+ * is used. This implementation skips {@code charCount} number of characters in
* the source reader and increments the line number count whenever line
* terminator sequences are skipped.
*
- * @param count
- * the number of characters to skip.
* @return the number of characters actually skipped.
* @throws IllegalArgumentException
- * if {@code count < 0}.
+ * if {@code charCount < 0}.
* @throws IOException
* if this reader is closed or another IOException occurs.
* @see #mark(int)
@@ -260,17 +258,17 @@ public class LineNumberReader extends BufferedReader {
* @see #reset()
*/
@Override
- public long skip(long count) throws IOException {
- if (count < 0) {
- throw new IllegalArgumentException();
+ public long skip(long charCount) throws IOException {
+ if (charCount < 0) {
+ throw new IllegalArgumentException("charCount < 0: " + charCount);
}
synchronized (lock) {
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < charCount; i++) {
if (read() == -1) {
return i;
}
}
- return count;
+ return charCount;
}
}
}
diff --git a/luni/src/main/java/java/io/ObjectInput.java b/luni/src/main/java/java/io/ObjectInput.java
index a86a6a4..a10ddfe 100644
--- a/luni/src/main/java/java/io/ObjectInput.java
+++ b/luni/src/main/java/java/io/ObjectInput.java
@@ -99,16 +99,13 @@ public interface ObjectInput extends DataInput {
public Object readObject() throws ClassNotFoundException, IOException;
/**
- * Skips {@code toSkip} bytes on this stream. Less than {@code toSkip} byte are
+ * Skips {@code byteCount} bytes on this stream. Less than {@code byteCount} byte are
* skipped if the end of this stream is reached before the operation
* completes.
*
- * @param toSkip
- * the number of bytes to skip.
* @return the number of bytes actually skipped.
- *
* @throws IOException
* if this stream is closed or another I/O error occurs.
*/
- public long skip(long toSkip) throws IOException;
+ public long skip(long byteCount) throws IOException;
}
diff --git a/luni/src/main/java/java/io/ObjectInputStream.java b/luni/src/main/java/java/io/ObjectInputStream.java
index 749eb29..d20e233 100644
--- a/luni/src/main/java/java/io/ObjectInputStream.java
+++ b/luni/src/main/java/java/io/ObjectInputStream.java
@@ -26,6 +26,7 @@ import dalvik.system.VMStack;
import java.io.EmulatedFields.ObjectSlot;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
@@ -33,8 +34,11 @@ import java.lang.reflect.Proxy;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
+import libcore.base.EmptyArray;
import org.apache.harmony.luni.util.PriviAction;
/**
@@ -47,14 +51,12 @@ import org.apache.harmony.luni.util.PriviAction;
* @see Serializable
* @see Externalizable
*/
-public class ObjectInputStream extends InputStream implements ObjectInput,
- ObjectStreamConstants {
+public class ObjectInputStream extends InputStream implements ObjectInput, ObjectStreamConstants {
// BEGIN android-note
// this is non-static to avoid sync contention. Would static be faster?
// END android-note
- private InputStream emptyStream = new ByteArrayInputStream(
- new byte[0]);
+ private InputStream emptyStream = new ByteArrayInputStream(EmptyArray.BYTE);
// To put into objectsRead when reading unsharedObject
private static final Object UNSHARED_OBJ = new Object(); // $NON-LOCK-1$
@@ -70,7 +72,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
private int nestedLevels;
// All objects are assigned an ID (integer handle)
- private int currentHandle;
+ private int nextHandle;
// Where we read from
private DataInputStream input;
@@ -84,8 +86,10 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
// Resolve object is a mechanism for replacement
private boolean enableResolve;
- // Table mapping Integer (handle) -> Object
- private HashMap<Integer, Object> objectsRead;
+ /**
+ * All the objects we've read, indexed by their serialization handle (minus the base offset).
+ */
+ private ArrayList<Object> objectsRead;
// Used by defaultReadObject
private Object currentObject;
@@ -107,20 +111,19 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
private boolean mustResolve = true;
// Handle for the current class descriptor
- private Integer descriptorHandle;
-
- private static final HashMap<String, Class<?>> PRIMITIVE_CLASSES =
- new HashMap<String, Class<?>>();
+ private int descriptorHandle = -1;
+ private static final HashMap<String, Class<?>> PRIMITIVE_CLASSES = new HashMap<String, Class<?>>();
static {
- PRIMITIVE_CLASSES.put("byte", byte.class);
- PRIMITIVE_CLASSES.put("short", short.class);
- PRIMITIVE_CLASSES.put("int", int.class);
- PRIMITIVE_CLASSES.put("long", long.class);
PRIMITIVE_CLASSES.put("boolean", boolean.class);
+ PRIMITIVE_CLASSES.put("byte", byte.class);
PRIMITIVE_CLASSES.put("char", char.class);
- PRIMITIVE_CLASSES.put("float", float.class);
PRIMITIVE_CLASSES.put("double", double.class);
+ PRIMITIVE_CLASSES.put("float", float.class);
+ PRIMITIVE_CLASSES.put("int", int.class);
+ PRIMITIVE_CLASSES.put("long", long.class);
+ PRIMITIVE_CLASSES.put("short", short.class);
+ PRIMITIVE_CLASSES.put("void", void.class);
}
// BEGIN android-removed
@@ -388,32 +391,28 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
final Class<?> thisClass = ObjectInputStream.class;
SecurityManager sm = System.getSecurityManager();
if (sm != null && implementationClass != thisClass) {
- boolean mustCheck = (AccessController
+ boolean mustCheck = AccessController
.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
try {
- Method method = implementationClass
- .getMethod(
- "readFields",
- ObjectStreamClass.EMPTY_CONSTRUCTOR_PARAM_TYPES);
+ Method method = implementationClass.getMethod("readFields",
+ EmptyArray.CLASS);
if (method.getDeclaringClass() != thisClass) {
return Boolean.TRUE;
}
- } catch (NoSuchMethodException e) {
+ } catch (NoSuchMethodException ignored) {
}
try {
- Method method = implementationClass
- .getMethod(
- "readUnshared",
- ObjectStreamClass.EMPTY_CONSTRUCTOR_PARAM_TYPES);
+ Method method = implementationClass.getMethod("readUnshared",
+ EmptyArray.CLASS);
if (method.getDeclaringClass() != thisClass) {
return Boolean.TRUE;
}
- } catch (NoSuchMethodException e) {
+ } catch (NoSuchMethodException ignored) {
}
return Boolean.FALSE;
}
- })).booleanValue();
+ });
if (mustCheck) {
sm
.checkPermission(ObjectStreamConstants.SUBCLASS_IMPLEMENTATION_PERMISSION);
@@ -471,8 +470,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
primitiveData = new ByteArrayInputStream(readBlockData());
return;
case TC_BLOCKDATALONG:
- primitiveData = new ByteArrayInputStream(
- readBlockDataLong());
+ primitiveData = new ByteArrayInputStream(readBlockDataLong());
return;
case TC_RESET:
resetState();
@@ -513,7 +511,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
*/
public void defaultReadObject() throws IOException, ClassNotFoundException,
NotActiveException {
- // We can't be called from just anywhere. There are rules.
if (currentObject != null || !mustResolve) {
readFieldValues(currentObject, currentClass);
} else {
@@ -540,7 +537,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
throws SecurityException {
if (enable) {
// The Stream has to be trusted for this feature to be enabled.
- // trusted means the stream's classloader has to be null
+ // trusted means the stream's class loader has to be null
SecurityManager currentManager = System.getSecurityManager();
if (currentManager != null) {
currentManager.checkPermission(SUBSTITUTION_PERMISSION);
@@ -552,60 +549,13 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
/**
- * Checks if two classes belong to the same package.
- *
- * @param c1
- * one of the classes to test.
- * @param c2
- * the other class to test.
- * @return {@code true} if the two classes belong to the same package,
- * {@code false} otherwise.
- */
- private boolean inSamePackage(Class<?> c1, Class<?> c2) {
- String nameC1 = c1.getName();
- String nameC2 = c2.getName();
- int indexDotC1 = nameC1.lastIndexOf('.');
- int indexDotC2 = nameC2.lastIndexOf('.');
- if (indexDotC1 != indexDotC2) {
- return false; // cannot be in the same package if indices are not
- }
- // the same
- if (indexDotC1 < 0) {
- return true; // both of them are in default package
- }
- return nameC1.substring(0, indexDotC1).equals(
- nameC2.substring(0, indexDotC2));
- }
-
- // BEGIN android-added
- /**
- * Create and return a new instance of class {@code instantiationClass}
- * but running the constructor defined in class
- * {@code constructorClass} (same as {@code instantiationClass}
- * or a superclass).
- *
- * Has to be native to avoid visibility rules and to be able to have
- * {@code instantiationClass} not the same as
- * {@code constructorClass} (no such API in java.lang.reflect).
- *
- * @param instantiationClass
- * The new object will be an instance of this class
- * @param constructorClass
- * The empty constructor to run will be in this class
- * @return the object created from {@code instantiationClass}
- */
- private static native Object newInstance(Class<?> instantiationClass,
- Class<?> constructorClass);
- // END android-added
-
- /**
* Return the next {@code int} handle to be used to indicate cyclic
* references being loaded from the stream.
*
* @return the next handle to represent the next cyclic reference
*/
- private Integer nextHandle() {
- return Integer.valueOf(this.currentHandle++);
+ private int nextHandle() {
+ return nextHandle++;
}
/**
@@ -679,13 +629,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
*/
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
- // Force buffer null check first!
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
if (length == 0) {
return 0;
}
@@ -811,9 +755,8 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
return readNewClassDesc(false);
case TC_PROXYCLASSDESC:
Class<?> proxyClass = readNewProxyClassDesc();
- ObjectStreamClass streamClass = ObjectStreamClass
- .lookup(proxyClass);
- streamClass.setLoadFields(new ObjectStreamField[0]);
+ ObjectStreamClass streamClass = ObjectStreamClass.lookup(proxyClass);
+ streamClass.setLoadFields(ObjectStreamClass.NO_FIELDS);
registerObjectRead(streamClass, nextHandle(), false);
checkedSetSuperClassDesc(streamClass, readClassDesc());
return streamClass;
@@ -958,8 +901,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
* @throws InvalidObjectException
* If the cyclic reference is not valid.
*/
- private Object readCyclicReference() throws InvalidObjectException,
- IOException {
+ private Object readCyclicReference() throws InvalidObjectException, IOException {
return registeredObjectRead(readNewHandle());
}
@@ -1116,14 +1058,11 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
* @throws NotActiveException
* if this stream is currently not reading an object.
*/
- public GetField readFields() throws IOException, ClassNotFoundException,
- NotActiveException {
- // We can't be called from just anywhere. There are rules.
+ public GetField readFields() throws IOException, ClassNotFoundException, NotActiveException {
if (currentObject == null) {
throw new NotActiveException();
}
- EmulatedFieldsForLoading result = new EmulatedFieldsForLoading(
- currentClass);
+ EmulatedFieldsForLoading result = new EmulatedFieldsForLoading(currentClass);
readFieldValues(result);
return result;
}
@@ -1150,27 +1089,26 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
*/
private void readFieldValues(EmulatedFieldsForLoading emulatedFields)
throws OptionalDataException, InvalidClassException, IOException {
- EmulatedFields.ObjectSlot[] slots = emulatedFields.emulatedFields()
- .slots();
+ EmulatedFields.ObjectSlot[] slots = emulatedFields.emulatedFields().slots();
for (ObjectSlot element : slots) {
element.defaulted = false;
Class<?> type = element.field.getType();
if (type == Integer.TYPE) {
- element.fieldValue = Integer.valueOf(input.readInt());
+ element.fieldValue = input.readInt();
} else if (type == Byte.TYPE) {
- element.fieldValue = Byte.valueOf(input.readByte());
+ element.fieldValue = input.readByte();
} else if (type == Character.TYPE) {
- element.fieldValue = Character.valueOf(input.readChar());
+ element.fieldValue = input.readChar();
} else if (type == Short.TYPE) {
- element.fieldValue = Short.valueOf(input.readShort());
+ element.fieldValue = input.readShort();
} else if (type == Boolean.TYPE) {
- element.fieldValue = Boolean.valueOf(input.readBoolean());
+ element.fieldValue = input.readBoolean();
} else if (type == Long.TYPE) {
- element.fieldValue = Long.valueOf(input.readLong());
+ element.fieldValue = input.readLong();
} else if (type == Float.TYPE) {
- element.fieldValue = Float.valueOf(input.readFloat());
+ element.fieldValue = input.readFloat();
} else if (type == Double.TYPE) {
- element.fieldValue = Double.valueOf(input.readDouble());
+ element.fieldValue = input.readDouble();
} else {
// Either array or Object
try {
@@ -1212,111 +1150,97 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
* @see #readFields
* @see #readObject()
*/
- private void readFieldValues(Object obj, ObjectStreamClass classDesc)
- throws OptionalDataException, ClassNotFoundException, IOException {
+ private void readFieldValues(Object obj, ObjectStreamClass classDesc) throws OptionalDataException, ClassNotFoundException, IOException {
// Now we must read all fields and assign them to the receiver
ObjectStreamField[] fields = classDesc.getLoadFields();
- fields = (null == fields ? new ObjectStreamField[] {} : fields);
+ fields = (fields == null) ? ObjectStreamClass.NO_FIELDS : fields;
Class<?> declaringClass = classDesc.forClass();
if (declaringClass == null && mustResolve) {
throw new ClassNotFoundException(classDesc.getName());
}
for (ObjectStreamField fieldDesc : fields) {
-
- // BEGIN android-removed
- // // get associated Field
- // long fieldID = fieldDesc.getFieldID(accessor, declaringClass);
- // END android-removed
-
- // Code duplication starts, just because Java is typed
- if (fieldDesc.isPrimitive()) {
- try {
- // BEGIN android-changed
- switch (fieldDesc.getTypeCode()) {
- case 'B':
- setFieldByte(obj, declaringClass, fieldDesc.getName(),
- input.readByte());
- break;
- case 'C':
- setFieldChar(obj, declaringClass, fieldDesc.getName(),
- input.readChar());
- break;
- case 'D':
- setFieldDouble(obj, declaringClass, fieldDesc.getName(),
- input.readDouble());
- break;
- case 'F':
- setFieldFloat(obj, declaringClass, fieldDesc.getName(),
- input.readFloat());
- break;
- case 'I':
- setFieldInt(obj, declaringClass, fieldDesc.getName(),
- input.readInt());
- break;
- case 'J':
- setFieldLong(obj, declaringClass, fieldDesc.getName(),
- input.readLong());
- break;
- case 'S':
- setFieldShort(obj, declaringClass, fieldDesc.getName(),
- input.readShort());
- break;
- case 'Z':
- setFieldBool(obj, declaringClass, fieldDesc.getName(),
- input.readBoolean());
- break;
- default:
- throw new StreamCorruptedException("Invalid typecode: " +
- fieldDesc.getTypeCode());
+ Field field = classDesc.getReflectionField(fieldDesc);
+ // We may not have been able to find the field, but we still need to read the value
+ // and do the other checking, so there's no null check on 'field' here.
+ try {
+ Class<?> type = fieldDesc.getTypeInternal();
+ if (type == Byte.TYPE) {
+ byte b = input.readByte();
+ if (field != null) {
+ field.setByte(obj, b);
+ }
+ } else if (type == Character.TYPE) {
+ char c = input.readChar();
+ if (field != null) {
+ field.setChar(obj, c);
+ }
+ } else if (type == Double.TYPE) {
+ double d = input.readDouble();
+ if (field != null) {
+ field.setDouble(obj, d);
+ }
+ } else if (type == Float.TYPE) {
+ float f = input.readFloat();
+ if (field != null) {
+ field.setFloat(obj, f);
+ }
+ } else if (type == Integer.TYPE) {
+ int i = input.readInt();
+ if (field != null) {
+ field.setInt(obj, i);
+ }
+ } else if (type == Long.TYPE) {
+ long j = input.readLong();
+ if (field != null) {
+ field.setLong(obj, j);
+ }
+ } else if (type == Short.TYPE) {
+ short s = input.readShort();
+ if (field != null) {
+ field.setShort(obj, s);
+ }
+ } else if (type == Boolean.TYPE) {
+ boolean z = input.readBoolean();
+ if (field != null) {
+ field.setBoolean(obj, z);
}
- // END android-changed
- } catch (NoSuchFieldError err) {
- }
- } else {
- // Object type (array included).
- String fieldName = fieldDesc.getName();
- boolean setBack = false;
- // BEGIN android-added
- ObjectStreamField field = classDesc.getField(fieldName);
- // END android-added
- if (mustResolve && fieldDesc == null) {
- setBack = true;
- mustResolve = false;
- }
- Object toSet;
- if (fieldDesc != null && fieldDesc.isUnshared()) {
- toSet = readUnshared();
} else {
- toSet = readObject();
- }
- if (setBack) {
- mustResolve = true;
- }
- if (fieldDesc != null) {
- if (toSet != null) {
- // BEGIN android-changed
- // Get the field type from the local field rather than
- // from the stream's supplied data. That's the field
- // we'll be setting, so that's the one that needs to be
- // validated.
- Class<?> fieldType = field.getTypeInternal();
- // END android-added
- Class<?> valueType = toSet.getClass();
- if (!fieldType.isAssignableFrom(valueType)) {
- throw new ClassCastException(classDesc.getName() + "." + fieldName +
- " - " + fieldType + " not compatible with " + valueType);
- }
- try {
+ String fieldName = fieldDesc.getName();
+ boolean setBack = false;
+ ObjectStreamField localFieldDesc = classDesc.getField(fieldName);
+ if (mustResolve && fieldDesc == null) {
+ setBack = true;
+ mustResolve = false;
+ }
+ boolean unshared = fieldDesc != null && fieldDesc.isUnshared();
+ Object toSet = unshared ? readUnshared() : readObject();
+ if (setBack) {
+ mustResolve = true;
+ }
+ if (fieldDesc != null) {
+ if (toSet != null) {
// BEGIN android-changed
- setFieldObject(obj, declaringClass, fieldName, field.getTypeString(),
- toSet);
- // END android-changed
- } catch (NoSuchFieldError e) {
- // Ignored
+ // Get the field type from the local field rather than
+ // from the stream's supplied data. That's the field
+ // we'll be setting, so that's the one that needs to be
+ // validated.
+ Class<?> fieldType = localFieldDesc.getTypeInternal();
+ // END android-added
+ Class<?> valueType = toSet.getClass();
+ if (!fieldType.isAssignableFrom(valueType)) {
+ throw new ClassCastException(classDesc.getName() + "." + fieldName + " - " + fieldType + " not compatible with " + valueType);
+ }
+ if (field != null) {
+ field.set(obj, toSet);
+ }
}
}
}
+ } catch (IllegalAccessException iae) {
+ // ObjectStreamField should have called setAccessible(true).
+ throw new AssertionError(iae);
+ } catch (NoSuchFieldError ignored) {
}
}
}
@@ -1336,10 +1260,10 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
/**
- * Reads bytes from the source stream into the byte array {@code buffer}.
- * This method will block until {@code buffer.length} bytes have been read.
+ * Reads bytes from the source stream into the byte array {@code dst}.
+ * This method will block until {@code dst.length} bytes have been read.
*
- * @param buffer
+ * @param dst
* the array in which to store the bytes read.
* @throws EOFException
* if the end of the input is reached before the read
@@ -1347,31 +1271,28 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
* @throws IOException
* if an error occurs while reading from the source stream.
*/
- public void readFully(byte[] buffer) throws IOException {
- primitiveTypes.readFully(buffer);
+ public void readFully(byte[] dst) throws IOException {
+ primitiveTypes.readFully(dst);
}
/**
- * Reads bytes from the source stream into the byte array {@code buffer}.
- * This method will block until {@code length} number of bytes have been
- * read.
+ * Reads {@code byteCount} bytes from the source stream into the byte array {@code dst}.
*
- * @param buffer
+ * @param dst
* the byte array in which to store the bytes read.
* @param offset
- * the initial position in {@code buffer} to store the bytes
+ * the initial position in {@code dst} to store the bytes
* read from the source stream.
- * @param length
- * the maximum number of bytes to store in {@code buffer}.
+ * @param byteCount
+ * the number of bytes to read.
* @throws EOFException
* if the end of the input is reached before the read
* request can be satisfied.
* @throws IOException
* if an error occurs while reading from the source stream.
*/
- public void readFully(byte[] buffer, int offset, int length)
- throws IOException {
- primitiveTypes.readFully(buffer, offset, length);
+ public void readFully(byte[] dst, int offset, int byteCount) throws IOException {
+ primitiveTypes.readFully(dst, offset, byteCount);
}
/**
@@ -1403,41 +1324,28 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
*/
private void readHierarchy(Object object, ObjectStreamClass classDesc)
throws IOException, ClassNotFoundException, NotActiveException {
- // We can't be called from just anywhere. There are rules.
if (object == null && mustResolve) {
throw new NotActiveException();
}
- ArrayList<ObjectStreamClass> streamClassList = new ArrayList<ObjectStreamClass>(
- 32);
- ObjectStreamClass nextStreamClass = classDesc;
- while (nextStreamClass != null) {
- streamClassList.add(0, nextStreamClass);
- nextStreamClass = nextStreamClass.getSuperclass();
- }
+ List<ObjectStreamClass> streamClassList = classDesc.getHierarchy();
if (object == null) {
- Iterator<ObjectStreamClass> streamIt = streamClassList.iterator();
- while (streamIt.hasNext()) {
- ObjectStreamClass streamClass = streamIt.next();
- readObjectForClass(null, streamClass);
+ for (ObjectStreamClass objectStreamClass : streamClassList) {
+ readObjectForClass(null, objectStreamClass);
}
} else {
- ArrayList<Class<?>> classList = new ArrayList<Class<?>>(32);
- Class<?> nextClass = object.getClass();
- while (nextClass != null) {
- Class<?> testClass = nextClass.getSuperclass();
- if (testClass != null) {
- classList.add(0, nextClass);
- }
- nextClass = testClass;
+ List<Class<?>> superclasses = cachedSuperclasses.get(object.getClass());
+ if (superclasses == null) {
+ superclasses = cacheSuperclassesFor(object.getClass());
}
+
int lastIndex = 0;
- for (int i = 0; i < classList.size(); i++) {
- Class<?> superclass = classList.get(i);
- int index = findStreamSuperclass(superclass, streamClassList,
- lastIndex);
+ for (int i = 0, end = superclasses.size(); i < end; ++i) {
+ Class<?> superclass = superclasses.get(i);
+ int index = findStreamSuperclass(superclass, streamClassList, lastIndex);
if (index == -1) {
- readObjectNoData(object, superclass, ObjectStreamClass.lookupStreamClass(superclass));
+ readObjectNoData(object, superclass,
+ ObjectStreamClass.lookupStreamClass(superclass));
} else {
for (int j = lastIndex; j <= index; j++) {
readObjectForClass(object, streamClassList.get(j));
@@ -1448,14 +1356,26 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
}
- private int findStreamSuperclass(Class<?> cl,
- ArrayList<ObjectStreamClass> classList, int lastIndex) {
- ObjectStreamClass objCl;
- String forName;
+ private HashMap<Class<?>, List<Class<?>>> cachedSuperclasses = new HashMap<Class<?>, List<Class<?>>>();
+
+ private List<Class<?>> cacheSuperclassesFor(Class<?> c) {
+ ArrayList<Class<?>> result = new ArrayList<Class<?>>();
+ Class<?> nextClass = c;
+ while (nextClass != null) {
+ Class<?> testClass = nextClass.getSuperclass();
+ if (testClass != null) {
+ result.add(0, nextClass);
+ }
+ nextClass = testClass;
+ }
+ cachedSuperclasses.put(c, result);
+ return result;
+ }
- for (int i = lastIndex; i < classList.size(); i++) {
- objCl = classList.get(i);
- forName = objCl.forClass().getName();
+ private int findStreamSuperclass(Class<?> cl, List<ObjectStreamClass> classList, int lastIndex) {
+ for (int i = lastIndex, end = classList.size(); i < end; i++) {
+ ObjectStreamClass objCl = classList.get(i);
+ String forName = objCl.forClass().getName();
if (objCl.getName().equals(forName)) {
if (cl.getName().equals(objCl.getName())) {
@@ -1479,7 +1399,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
if (classDesc.hasMethodReadObjectNoData()){
final Method readMethod = classDesc.getMethodReadObjectNoData();
try {
- readMethod.invoke(object, new Object[0]);
+ readMethod.invoke(object);
} catch (InvocationTargetException e) {
Throwable ex = e.getTargetException();
if (ex instanceof RuntimeException) {
@@ -1502,7 +1422,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
currentObject = object;
currentClass = classDesc;
- boolean hadWriteMethod = (classDesc.getFlags() & SC_WRITE_METHOD) > 0;
+ boolean hadWriteMethod = (classDesc.getFlags() & SC_WRITE_METHOD) != 0;
Class<?> targetClass = classDesc.forClass();
final Method readMethod;
@@ -1517,7 +1437,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
AccessController.doPrivileged(new PriviAction<Object>(
readMethod));
try {
- readMethod.invoke(object, new Object[] { this });
+ readMethod.invoke(object, this);
} catch (InvocationTargetException e) {
Throwable ex = e.getTargetException();
if (ex instanceof ClassNotFoundException) {
@@ -1608,10 +1528,10 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
ObjectStreamClass classDesc = readClassDesc();
if (classDesc == null) {
- missingClassDescriptor();
+ throw missingClassDescriptor();
}
- Integer newHandle = nextHandle();
+ int newHandle = nextHandle();
// Array size
int size = input.readInt();
@@ -1701,7 +1621,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
private Class<?> readNewClass(boolean unshared) throws ClassNotFoundException, IOException {
ObjectStreamClass classDesc = readClassDesc();
if (classDesc == null) {
- missingClassDescriptor();
+ throw missingClassDescriptor();
}
Class<?> localClass = classDesc.forClass();
if (localClass != null) {
@@ -1729,11 +1649,10 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
}
- private ObjectStreamClass readEnumDescInternal() throws IOException,
- ClassNotFoundException {
+ private ObjectStreamClass readEnumDescInternal() throws IOException, ClassNotFoundException {
ObjectStreamClass classDesc;
primitiveData = input;
- Integer oldHandle = descriptorHandle;
+ int oldHandle = descriptorHandle;
descriptorHandle = nextHandle();
classDesc = readClassDescriptor();
registerObjectRead(classDesc, descriptorHandle, false);
@@ -1766,7 +1685,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
ClassNotFoundException, IOException {
// read classdesc for Enum first
ObjectStreamClass classDesc = readEnumDesc();
- Integer newHandle = nextHandle();
+ int newHandle = nextHandle();
// read name after class desc
String name;
byte tc = nextTC();
@@ -1811,7 +1730,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
// So read...() methods can be used by
// subclasses during readClassDescriptor()
primitiveData = input;
- Integer oldHandle = descriptorHandle;
+ int oldHandle = descriptorHandle;
descriptorHandle = nextHandle();
ObjectStreamClass newClassDesc = readClassDescriptor();
registerObjectRead(newClassDesc, descriptorHandle, unshared);
@@ -1833,7 +1752,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
// Resolve the field signatures using the class loader of the
// resolved class
ObjectStreamField[] fields = newClassDesc.getLoadFields();
- fields = (null == fields ? new ObjectStreamField[] {} : fields);
+ fields = (fields == null) ? ObjectStreamClass.NO_FIELDS : fields;
ClassLoader loader = newClassDesc.forClass() == null ? callerClassLoader
: newClassDesc.forClass().getClassLoader();
for (ObjectStreamField element : fields) {
@@ -1894,9 +1813,11 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
/*
* We must register the class descriptor before reading field
* descriptors. If called outside of readObject, the descriptorHandle
- * might be null.
+ * might be unset.
*/
- descriptorHandle = (null == descriptorHandle ? nextHandle() : descriptorHandle);
+ if (descriptorHandle == -1) {
+ descriptorHandle = nextHandle();
+ }
registerObjectRead(newClassDesc, descriptorHandle, false);
readFieldDescriptors(newClassDesc);
@@ -1936,82 +1857,10 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
}
- /**
- * Write a new handle describing a cyclic reference from the stream.
- *
- * @return the handle read
- *
- * @throws IOException
- * If an IO exception happened when reading the handle
- */
private int readNewHandle() throws IOException {
return input.readInt();
}
- private Class<?> resolveConstructorClass(Class<?> objectClass, boolean wasSerializable, boolean wasExternalizable)
- throws OptionalDataException, ClassNotFoundException, IOException {
-
- // The class of the instance may not be the same as the class of the
- // constructor to run
- // This is the constructor to run if Externalizable
- Class<?> constructorClass = objectClass;
-
- // WARNING - What if the object is serializable and externalizable ?
- // Is that possible ?
- if (wasSerializable) {
- // Now we must run the constructor of the class just above the
- // one that implements Serializable so that slots that were not
- // dumped can be initialized properly
- while (constructorClass != null
- && ObjectStreamClass.isSerializable(constructorClass)) {
- constructorClass = constructorClass.getSuperclass();
- }
- }
-
- // Fetch the empty constructor, or null if none.
- Constructor<?> constructor = null;
- if (constructorClass != null) {
- try {
- constructor = constructorClass
- .getDeclaredConstructor(ObjectStreamClass.EMPTY_CONSTRUCTOR_PARAM_TYPES);
- } catch (NoSuchMethodException nsmEx) {
- // Ignored
- }
- }
-
- // Has to have an empty constructor
- if (constructor == null) {
- throw new InvalidClassException(constructorClass.getName(),
- "IllegalAccessException");
- }
-
- int constructorModifiers = constructor.getModifiers();
-
- // Now we must check if the empty constructor is visible to the
- // instantiation class
- if (Modifier.isPrivate(constructorModifiers)
- || (wasExternalizable && !Modifier.isPublic(constructorModifiers))) {
- throw new InvalidClassException(constructorClass.getName(),
- "IllegalAccessException");
- }
-
- // We know we are testing from a subclass, so the only other case
- // where the visibility is not allowed is when the constructor has
- // default visibility and the instantiation class is in a different
- // package than the constructor class
- if (!Modifier.isPublic(constructorModifiers)
- && !Modifier.isProtected(constructorModifiers)) {
- // Not public, not private and not protected...means default
- // visibility. Check if same package
- if (!inSamePackage(constructorClass, objectClass)) {
- throw new InvalidClassException(constructorClass.getName(),
- "IllegalAccessException");
- }
- }
-
- return constructorClass;
- }
-
/**
* Read a new object from the stream. It is assumed the object has not been
* loaded yet (not a cyclic reference). Return the object read.
@@ -2042,40 +1891,15 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
throw missingClassDescriptor();
}
- Integer newHandle = nextHandle();
-
- // Note that these values come from the Stream, and in fact it could be
- // that the classes have been changed so that the info below now
- // conflicts with the newer class
- boolean wasExternalizable = (classDesc.getFlags() & SC_EXTERNALIZABLE) > 0;
- boolean wasSerializable = (classDesc.getFlags() & SC_SERIALIZABLE) > 0;
-
-
- // Maybe we should cache the values above in classDesc ? It may be the
- // case that when reading classDesc we may need to read more stuff
- // depending on the values above
+ int newHandle = nextHandle();
Class<?> objectClass = classDesc.forClass();
-
- Object result, registeredResult = null;
+ Object result = null;
+ Object registeredResult = null;
if (objectClass != null) {
-
- // BEGIN android-changed
- // long constructor = classDesc.getConstructor();
- // if (constructor == ObjectStreamClass.CONSTRUCTOR_IS_NOT_RESOLVED) {
- // constructor = accessor.getMethodID(resolveConstructorClass(objectClass, wasSerializable, wasExternalizable), null, new Class[0]);
- // classDesc.setConstructor(constructor);
- // }
- Class constructorClass = resolveConstructorClass(objectClass, wasSerializable, wasExternalizable);
- // END android-changed
-
// Now we know which class to instantiate and which constructor to
// run. We are allowed to run the constructor.
- // BEGIN android-changed
- // result = accessor.newInstance(objectClass, constructor, null);
- result = newInstance(objectClass, constructorClass);
- // END android-changed
+ result = classDesc.newInstance(objectClass);
registerObjectRead(result, newHandle, unshared);
-
registeredResult = result;
} else {
result = null;
@@ -2090,8 +1914,12 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
currentClass = classDesc;
// If Externalizable, just let the object read itself
+ // Note that this value comes from the Stream, and in fact it could be
+ // that the classes have been changed so that the info below now
+ // conflicts with the newer class
+ boolean wasExternalizable = (classDesc.getFlags() & SC_EXTERNALIZABLE) != 0;
if (wasExternalizable) {
- boolean blockData = (classDesc.getFlags() & SC_BLOCK_DATA) > 0;
+ boolean blockData = (classDesc.getFlags() & SC_BLOCK_DATA) != 0;
if (!blockData) {
primitiveData = input;
}
@@ -2124,7 +1952,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
Method methodReadResolve = classDesc.getMethodReadResolve();
try {
result = methodReadResolve.invoke(result, (Object[]) null);
- } catch (IllegalAccessException iae) {
+ } catch (IllegalAccessException ignored) {
} catch (InvocationTargetException ite) {
Throwable target = ite.getTargetException();
if (target instanceof ObjectStreamException) {
@@ -2318,7 +2146,7 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
// END android-added
/**
- * Method to be overriden by subclasses to read the next object from the
+ * Method to be overridden by subclasses to read the next object from the
* source stream.
*
* @return the object read from the source stream.
@@ -2416,17 +2244,12 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
/**
- * Return the object previously read tagged with handle {@code handle}.
- *
- * @param handle
- * The handle that this object was assigned when it was read.
- * @return the object previously read.
- *
+ * Returns the previously-read object corresponding to the given serialization handle.
* @throws InvalidObjectException
- * If there is no previously read object with this handle
+ * If there is no previously-read object with this handle
*/
- private Object registeredObjectRead(Integer handle) throws InvalidObjectException {
- Object res = objectsRead.get(handle);
+ private Object registeredObjectRead(int handle) throws InvalidObjectException {
+ Object res = objectsRead.get(handle - ObjectStreamConstants.baseWireHandle);
if (res == UNSHARED_OBJ) {
throw new InvalidObjectException("Cannot read back reference to unshared object");
}
@@ -2434,20 +2257,26 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
}
/**
- * Assume object {@code obj} has been read, and assign a handle to
- * it, {@code handle}.
- *
- * @param obj
- * Non-null object being loaded.
- * @param handle
- * An Integer, the handle to this object
- * @param unshared
- * Boolean, indicates that caller is reading in unshared mode
- *
- * @see #nextHandle
+ * Associates a read object with the its serialization handle.
*/
- private void registerObjectRead(Object obj, Integer handle, boolean unshared) {
- objectsRead.put(handle, unshared ? UNSHARED_OBJ : obj);
+ private void registerObjectRead(Object obj, int handle, boolean unshared) throws IOException {
+ if (unshared) {
+ obj = UNSHARED_OBJ;
+ }
+ int index = handle - ObjectStreamConstants.baseWireHandle;
+ int size = objectsRead.size();
+ // ObjectOutputStream sometimes wastes a handle. I've compared hex dumps of the RI
+ // and it seems like that's a 'feature'. Look for calls to objectsWritten.put that
+ // are guarded by !unshared tests.
+ while (index > size) {
+ objectsRead.add(null);
+ ++size;
+ }
+ if (index == size) {
+ objectsRead.add(obj);
+ } else {
+ objectsRead.set(index, obj);
+ }
}
/**
@@ -2475,7 +2304,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
// Validation can only be registered when inside readObject calls
Object instanceBeingRead = this.currentObject;
- // We can't be called from just anywhere. There are rules.
if (instanceBeingRead == null && nestedLevels == 0) {
throw new NotActiveException();
}
@@ -2516,8 +2344,8 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
* Reset the collection of objects already loaded by the receiver.
*/
private void resetSeenObjects() {
- objectsRead = new HashMap<Integer, Object>();
- currentHandle = baseWireHandle;
+ objectsRead = new ArrayList<Object>();
+ nextHandle = baseWireHandle;
primitiveData = emptyStream;
}
@@ -2550,14 +2378,14 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
throws IOException, ClassNotFoundException {
// fastpath: obtain cached value
Class<?> cls = osClass.forClass();
- if (null == cls) {
+ if (cls == null) {
// slowpath: resolve the class
String className = osClass.getName();
// if it is primitive class, for example, long.class
cls = PRIMITIVE_CLASSES.get(className);
- if (null == cls) {
+ if (cls == null) {
// not primitive class
// Use the first non-null ClassLoader on the stack. If null, use
// the system class loader
@@ -2588,60 +2416,6 @@ public class ObjectInputStream extends InputStream implements ObjectInput,
return object;
}
- // BEGIN android-added
-
- /*
- * These methods set the value of a field named fieldName of instance. The
- * field is declared by declaringClass. The field is the same type as the
- * value parameter.
- *
- * these methods could be implemented non-natively on top of
- * java.lang.reflect at the expense of extra object creation
- * (java.lang.reflect.Field). Otherwise Serialization could not fetch
- * private fields, except by the use of a native method like this one.
- *
- * @throws NoSuchFieldError If the field does not exist.
- */
- private static native void setFieldByte(Object instance,
- Class<?> declaringClass, String fieldName, byte value)
- throws NoSuchFieldError;
-
-
- private static native void setFieldChar(Object instance,
- Class<?> declaringClass, String fieldName, char value)
- throws NoSuchFieldError;
-
-
- private static native void setFieldDouble(Object instance,
- Class<?> declaringClass, String fieldName, double value)
- throws NoSuchFieldError;
-
- private static native void setFieldFloat(Object instance,
- Class<?> declaringClass, String fieldName, float value)
- throws NoSuchFieldError;
-
- private static native void setFieldInt(Object instance,
- Class<?> declaringClass, String fieldName, int value)
- throws NoSuchFieldError;
-
- private static native void setFieldLong(Object instance,
- Class<?> declaringClass, String fieldName, long value)
- throws NoSuchFieldError;
-
- private static native void setFieldObject(Object instance,
- Class<?> declaringClass, String fieldName, String fieldTypeName,
- Object value) throws NoSuchFieldError;
-
- private static native void setFieldShort(Object instance,
- Class<?> declaringClass, String fieldName, short value)
- throws NoSuchFieldError;
-
- private static native void setFieldBool(Object instance,
- Class<?> declaringClass, String fieldName, boolean value)
- throws NoSuchFieldError;
-
- // END android-added
-
/**
* Skips {@code length} bytes on the source stream. This method should not
* be used to skip bytes at any arbitrary position, just when reading
diff --git a/luni/src/main/java/java/io/ObjectOutputStream.java b/luni/src/main/java/java/io/ObjectOutputStream.java
index cde98f7..d72dee4 100644
--- a/luni/src/main/java/java/io/ObjectOutputStream.java
+++ b/luni/src/main/java/java/io/ObjectOutputStream.java
@@ -17,16 +17,16 @@
package java.io;
+import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import java.util.IdentityHashMap;
-
-
-// BEGIN android-note
-// Harmony uses ObjectAccessors to access fields through JNI. Android has not
-// yet migrated that API. As a consequence, there's a lot of changes here...
-// END android-note
+import java.nio.ByteOrder;
+import java.nio.charset.ModifiedUtf8;
+import java.util.List;
+import libcore.base.EmptyArray;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* A specialized {@link OutputStream} that is able to write (serialize) Java
@@ -38,8 +38,9 @@ import java.util.IdentityHashMap;
* @see Serializable
* @see Externalizable
*/
-public class ObjectOutputStream extends OutputStream implements ObjectOutput,
- ObjectStreamConstants {
+public class ObjectOutputStream extends OutputStream implements ObjectOutput, ObjectStreamConstants {
+
+ private static final Class<?>[] WRITE_UNSHARED_PARAM_TYPES = new Class[] { Object.class };
/*
* Mask to zero SC_BLOC_DATA bit.
@@ -74,7 +75,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/*
* Table mapping Object -> Integer (handle)
*/
- private IdentityHashMap<Object, Integer> objectsWritten;
+ private SerializationHandleMap objectsWritten;
/*
* All objects are assigned an ID (integer handle)
@@ -286,16 +287,14 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
if (implementationClass != thisClass) {
boolean mustCheck = false;
try {
- Method method = implementationClass.getMethod("putFields",
- ObjectStreamClass.EMPTY_CONSTRUCTOR_PARAM_TYPES);
+ Method method = implementationClass.getMethod("putFields", EmptyArray.CLASS);
mustCheck = method.getDeclaringClass() != thisClass;
} catch (NoSuchMethodException e) {
}
if (!mustCheck) {
try {
- Method method = implementationClass.getMethod(
- "writeUnshared",
- ObjectStreamClass.UNSHARED_PARAM_TYPES);
+ Method method = implementationClass.getMethod("writeUnshared",
+ WRITE_UNSHARED_PARAM_TYPES);
mustCheck = method.getDeclaringClass() != thisClass;
} catch (NoSuchMethodException e) {
}
@@ -391,7 +390,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @see #writeFieldValues(EmulatedFieldsForDumping)
*/
private void computePutField() {
- currentPutField = new EmulatedFieldsForDumping(currentClass);
+ currentPutField = new EmulatedFieldsForDumping(this, currentClass);
}
/**
@@ -406,7 +405,6 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @see ObjectInputStream#defaultReadObject
*/
public void defaultWriteObject() throws IOException {
- // We can't be called from just anywhere. There are rules.
if (currentObject == null) {
throw new NotActiveException();
}
@@ -457,23 +455,22 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @param obj
* Object to check if an instance previously dumped by this
* stream.
- * @return null if it is an instance which has not been dumped yet (and this
- * method does nothing). Integer, if {@code obj} is an
- * instance which has been dumped already. In this case this method
- * saves the cyclic reference.
+ * @return -1 if it is an instance which has not been dumped yet (and this
+ * method does nothing). The handle if {@code obj} is an
+ * instance which has been dumped already.
*
* @throws IOException
* If an error occurs attempting to save {@code null} or
* a cyclic reference.
*/
- private Integer dumpCycle(Object obj) throws IOException {
+ private int dumpCycle(Object obj) throws IOException {
// If the object has been saved already, save its handle only
- Integer handle = objectsWritten.get(obj);
- if (handle != null) {
+ int handle = objectsWritten.get(obj);
+ if (handle != -1) {
writeCyclicReference(handle);
return handle;
}
- return null;
+ return -1;
}
/**
@@ -520,7 +517,6 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
output.flush();
}
- // BEGIN android-added
/*
* These methods get the value of a field named fieldName of object
* instance. The field is declared by declaringClass. The field is the same
@@ -533,43 +529,16 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*
* @throws NoSuchFieldError If the field does not exist.
*/
-
- private static native boolean getFieldBool(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native byte getFieldByte(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native char getFieldChar(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native double getFieldDouble(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native float getFieldFloat(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native int getFieldInt(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native long getFieldLong(Object instance,
- Class<?> declaringClass, String fieldName);
-
- private static native Object getFieldObj(Object instance,
- Class<?> declaringClass, String fieldName, String fieldTypeName);
-
- private static native short getFieldShort(Object instance,
- Class<?> declaringClass, String fieldName);
- // END android-added
+ private static native Object getFieldL(Object instance, Class<?> declaringClass, String fieldName, String fieldTypeName);
/**
- * Return the next <code>Integer</code> handle to be used to indicate cyclic
+ * Return the next handle to be used to indicate cyclic
* references being saved to the stream.
*
* @return the next handle to represent the next cyclic reference
*/
- private Integer nextHandle() {
- return Integer.valueOf(this.currentHandle++);
+ private int nextHandle() {
+ return currentHandle++;
}
/**
@@ -587,7 +556,6 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @see ObjectInputStream#defaultReadObject
*/
public PutField putFields() throws IOException {
- // We can't be called from just anywhere. There are rules.
if (currentObject == null) {
throw new NotActiveException();
}
@@ -597,18 +565,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
return currentPutField;
}
- /**
- * Assume object {@code obj} has not been dumped yet, and assign a
- * handle to it
- *
- * @param obj
- * Non-null object being dumped.
- * @return the handle that this object is being assigned.
- *
- * @see #nextHandle
- */
- private Integer registerObjectWritten(Object obj) {
- Integer handle = nextHandle();
+ private int registerObjectWritten(Object obj) {
+ int handle = nextHandle();
objectsWritten.put(obj, handle);
return handle;
}
@@ -622,8 +580,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @param previousHandle
* The handle of the previous identical object dumped
*/
- private void removeUnsharedReference(Object obj, Integer previousHandle) {
- if (previousHandle != null) {
+ private void removeUnsharedReference(Object obj, int previousHandle) {
+ if (previousHandle != -1) {
objectsWritten.put(obj, previousHandle);
} else {
objectsWritten.remove(obj);
@@ -681,7 +639,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*
*/
private void resetSeenObjects() {
- objectsWritten = new IdentityHashMap<Object, Integer>();
+ objectsWritten = new SerializationHandleMap();
currentHandle = baseWireHandle;
}
@@ -856,26 +814,24 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* If an IO exception happened when writing the class
* descriptor.
*/
- private Integer writeClassDesc(ObjectStreamClass classDesc, boolean unshared)
- throws IOException {
+ private int writeClassDesc(ObjectStreamClass classDesc, boolean unshared) throws IOException {
if (classDesc == null) {
writeNull();
- return null;
+ return -1;
}
- Integer handle = null;
+ int handle = -1;
if (!unshared) {
handle = dumpCycle(classDesc);
}
- if (handle == null) {
+ if (handle == -1) {
Class<?> classToWrite = classDesc.forClass();
- Integer previousHandle = null;
+ int previousHandle = -1;
if (unshared) {
previousHandle = objectsWritten.get(classDesc);
}
// If we got here, it is a new (non-null) classDesc that will have
// to be registered as well
- handle = nextHandle();
- objectsWritten.put(classDesc, handle);
+ handle = registerObjectWritten(classDesc);
if (classDesc.isProxy()) {
output.writeByte(TC_PROXYCLASSDESC);
@@ -920,17 +876,10 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Writes a handle representing a cyclic reference (object previously
* dumped).
- *
- * @param handle
- * The Integer handle that represents an object previously seen
- *
- * @throws IOException
- * If an IO exception happened when writing the cyclic
- * reference.
*/
- private void writeCyclicReference(Integer handle) throws IOException {
+ private void writeCyclicReference(int handle) throws IOException {
output.writeByte(TC_REFERENCE);
- output.writeInt(handle.intValue());
+ output.writeInt(handle);
}
/**
@@ -963,8 +912,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*
* @see #writeObject(Object)
*/
- private void writeFieldDescriptors(ObjectStreamClass classDesc,
- boolean externalizable) throws IOException {
+ private void writeFieldDescriptors(ObjectStreamClass classDesc, boolean externalizable) throws IOException {
Class<?> loadedClass = classDesc.forClass();
ObjectStreamField[] fields = null;
int fieldCount = 0;
@@ -981,9 +929,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
// Field names
for (int i = 0; i < fieldCount; i++) {
ObjectStreamField f = fields[i];
- output.writeByte(f.getTypeCode());
- output.writeUTF(f.getName());
- if (!f.isPrimitive()) {
+ boolean wasPrimitive = f.writeField(output);
+ if (!wasPrimitive) {
writeObject(f.getTypeString());
}
}
@@ -1022,41 +969,29 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @see #writeFields
* @see #writeObject(Object)
*/
- private void writeFieldValues(EmulatedFieldsForDumping emulatedFields)
- throws IOException {
- EmulatedFields accessibleSimulatedFields = emulatedFields
- .emulatedFields(); // Access internal fields which we can
- // set/get. Users can't do this.
+ private void writeFieldValues(EmulatedFieldsForDumping emulatedFields) throws IOException {
+ // Access internal fields which we can set/get. Users can't do this.
+ EmulatedFields accessibleSimulatedFields = emulatedFields.emulatedFields();
EmulatedFields.ObjectSlot[] slots = accessibleSimulatedFields.slots();
- for (int i = 0; i < slots.length; i++) {
- EmulatedFields.ObjectSlot slot = slots[i];
+ for (EmulatedFields.ObjectSlot slot : accessibleSimulatedFields.slots()) {
Object fieldValue = slot.getFieldValue();
Class<?> type = slot.getField().getType();
- // WARNING - default values exist for each primitive type
if (type == Integer.TYPE) {
- output.writeInt(fieldValue != null ? ((Integer) fieldValue)
- .intValue() : 0);
+ output.writeInt(fieldValue != null ? ((Integer) fieldValue).intValue() : 0);
} else if (type == Byte.TYPE) {
- output.writeByte(fieldValue != null ? ((Byte) fieldValue)
- .byteValue() : (byte) 0);
+ output.writeByte(fieldValue != null ? ((Byte) fieldValue).byteValue() : 0);
} else if (type == Character.TYPE) {
- output.writeChar(fieldValue != null ? ((Character) fieldValue)
- .charValue() : (char) 0);
+ output.writeChar(fieldValue != null ? ((Character) fieldValue).charValue() : 0);
} else if (type == Short.TYPE) {
- output.writeShort(fieldValue != null ? ((Short) fieldValue)
- .shortValue() : (short) 0);
+ output.writeShort(fieldValue != null ? ((Short) fieldValue).shortValue() : 0);
} else if (type == Boolean.TYPE) {
- output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue)
- .booleanValue() : false);
+ output.writeBoolean(fieldValue != null ? ((Boolean) fieldValue).booleanValue() : false);
} else if (type == Long.TYPE) {
- output.writeLong(fieldValue != null ? ((Long) fieldValue)
- .longValue() : (long) 0);
+ output.writeLong(fieldValue != null ? ((Long) fieldValue).longValue() : 0);
} else if (type == Float.TYPE) {
- output.writeFloat(fieldValue != null ? ((Float) fieldValue)
- .floatValue() : (float) 0);
+ output.writeFloat(fieldValue != null ? ((Float) fieldValue).floatValue() : 0);
} else if (type == Double.TYPE) {
- output.writeDouble(fieldValue != null ? ((Double) fieldValue)
- .doubleValue() : (double) 0);
+ output.writeDouble(fieldValue != null ? ((Double) fieldValue).doubleValue() : 0);
} else {
// Either array or Object
writeObject(fieldValue);
@@ -1064,7 +999,6 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
}
}
-
/**
* Writes a collection of field values for the fields described by class
* descriptor {@code classDesc} (an {@code ObjectStreamClass}).
@@ -1083,72 +1017,46 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*
* @see #writeObject(Object)
*/
- private void writeFieldValues(Object obj, ObjectStreamClass classDesc)
- throws IOException {
- ObjectStreamField[] fields = classDesc.fields();
- Class<?> declaringClass = classDesc.forClass();
- for(ObjectStreamField fieldDesc : fields) {
+ private void writeFieldValues(Object obj, ObjectStreamClass classDesc) throws IOException {
+ for (ObjectStreamField fieldDesc : classDesc.fields()) {
try {
-
- // BEGIN android-changed
- // // get associated Field
- // long fieldID = fieldDesc.getFieldID(accessor, declaringClass);
-
- // Code duplication starts, just because Java is typed
- if (fieldDesc.isPrimitive()) {
- switch (fieldDesc.getTypeCode()) {
- case 'B':
- output.writeByte(getFieldByte(obj, declaringClass,
- fieldDesc.getName()));
- break;
- case 'C':
- output.writeChar(getFieldChar(obj, declaringClass,
- fieldDesc.getName()));
- break;
- case 'D':
- output.writeDouble(getFieldDouble(obj,
- declaringClass, fieldDesc.getName()));
- break;
- case 'F':
- output.writeFloat(getFieldFloat(obj,
- declaringClass, fieldDesc.getName()));
- break;
- case 'I':
- output.writeInt(getFieldInt(obj, declaringClass,
- fieldDesc.getName()));
- break;
- case 'J':
- output.writeLong(getFieldLong(obj, declaringClass,
- fieldDesc.getName()));
- break;
- case 'S':
- output.writeShort(getFieldShort(obj,
- declaringClass, fieldDesc.getName()));
- break;
- case 'Z':
- output.writeBoolean(getFieldBool(obj,
- declaringClass, fieldDesc.getName()));
- break;
- default:
- throw new IOException("Invalid typecode: " +
- fieldDesc.getTypeCode());
- }
+ Class<?> type = fieldDesc.getTypeInternal();
+ Field field = classDesc.getReflectionField(fieldDesc);
+ if (field == null) {
+ throw new InvalidClassException(classDesc.getName() + " doesn't have a field " + fieldDesc.getName() + " of type " + type);
+ }
+ if (type == Byte.TYPE) {
+ output.writeByte(field.getByte(obj));
+ } else if (type == Character.TYPE) {
+ output.writeChar(field.getChar(obj));
+ } else if (type == Double.TYPE) {
+ output.writeDouble(field.getDouble(obj));
+ } else if (type == Float.TYPE) {
+ output.writeFloat(field.getFloat(obj));
+ } else if (type == Integer.TYPE) {
+ output.writeInt(field.getInt(obj));
+ } else if (type == Long.TYPE) {
+ output.writeLong(field.getLong(obj));
+ } else if (type == Short.TYPE) {
+ output.writeShort(field.getShort(obj));
+ } else if (type == Boolean.TYPE) {
+ output.writeBoolean(field.getBoolean(obj));
} else {
- // Object type (array included).
- Object objField = getFieldObj(obj, declaringClass, fieldDesc
- .getName(), fieldDesc.getTypeString());
+ // Reference types (including arrays).
+ Object objField = field.get(obj);
if (fieldDesc.isUnshared()) {
writeUnshared(objField);
} else {
writeObject(objField);
}
}
- // END android-changed
+ } catch (IllegalAccessException iae) {
+ // ObjectStreamField should have called setAccessible(true).
+ throw new AssertionError(iae);
} catch (NoSuchFieldError nsf) {
// The user defined serialPersistentFields but did not provide
- // the glue to transfer values,
- // (in writeObject) so we end up using the default mechanism and
- // fail to set the emulated field
+ // the glue to transfer values in writeObject, so we ended up using
+ // the default mechanism but failed to set the emulated field.
throw new InvalidClassException(classDesc.getName());
}
}
@@ -1193,59 +1101,56 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*/
private void writeHierarchy(Object object, ObjectStreamClass classDesc)
throws IOException, NotActiveException {
- // We can't be called from just anywhere. There are rules.
if (object == null) {
throw new NotActiveException();
}
// Fields are written from class closest to Object to leaf class
// (down the chain)
- if (classDesc.getSuperclass() != null) {
- // first
- writeHierarchy(object, classDesc.getSuperclass());
- }
-
- // Have to do this before calling defaultWriteObject or anything
- // that calls defaultWriteObject
- currentObject = object;
- currentClass = classDesc;
-
- // See if the object has a writeObject method. If so, run it
- boolean executed = false;
- try {
- if (classDesc.hasMethodWriteObject()){
- final Method method = classDesc.getMethodWriteObject();
- try {
- method.invoke(object, new Object[] { this });
- executed = true;
- } catch (InvocationTargetException e) {
- Throwable ex = e.getTargetException();
- if (ex instanceof RuntimeException) {
- throw (RuntimeException) ex;
- } else if (ex instanceof Error) {
- throw (Error) ex;
+ List<ObjectStreamClass> hierarchy = classDesc.getHierarchy();
+ for (int i = 0, end = hierarchy.size(); i < end; ++i) {
+ ObjectStreamClass osc = hierarchy.get(i);
+ // Have to do this before calling defaultWriteObject or anything
+ // that calls defaultWriteObject
+ currentObject = object;
+ currentClass = osc;
+
+ // See if the object has a writeObject method. If so, run it
+ try {
+ boolean executed = false;
+ if (osc.hasMethodWriteObject()) {
+ final Method method = osc.getMethodWriteObject();
+ try {
+ method.invoke(object, new Object[] { this });
+ executed = true;
+ } catch (InvocationTargetException e) {
+ Throwable ex = e.getTargetException();
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException) ex;
+ } else if (ex instanceof Error) {
+ throw (Error) ex;
+ }
+ throw (IOException) ex;
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e.toString());
}
- throw (IOException) ex;
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e.toString());
}
- }
-
- if (executed) {
- drain();
- output.writeByte(TC_ENDBLOCKDATA);
- } else {
- // If the object did not have a writeMethod, call
- // defaultWriteObject
- defaultWriteObject();
+ if (executed) {
+ drain();
+ output.writeByte(TC_ENDBLOCKDATA);
+ } else {
+ // If the object did not have a writeMethod, call
+ // defaultWriteObject
+ defaultWriteObject();
+ }
+ } finally {
+ // Cleanup, needs to run always so that we can later detect
+ // invalid calls to defaultWriteObject
+ currentObject = null;
+ currentClass = null;
+ currentPutField = null;
}
- } finally {
- // Cleanup, needs to run always so that we can later detect
- // invalid calls to defaultWriteObject
- currentObject = null;
- currentClass = null;
- currentPutField = null;
}
}
@@ -1278,8 +1183,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Write array {@code array} of class {@code arrayClass} with
* component type {@code componentType} into the receiver. It is
- * assumed the array has not been dumped yet. Return an {@code Integer}
- * that represents the handle for this object (array) which is dumped here.
+ * assumed the array has not been dumped yet. Returns
+ * the handle for this object (array) which is dumped here.
*
* @param array
* The array object to dump
@@ -1294,13 +1199,12 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @throws IOException
* If an IO exception happened when writing the array.
*/
- private Integer writeNewArray(Object array, Class<?> arrayClass, ObjectStreamClass arrayClDesc,
+ private int writeNewArray(Object array, Class<?> arrayClass, ObjectStreamClass arrayClDesc,
Class<?> componentType, boolean unshared) throws IOException {
output.writeByte(TC_ARRAY);
writeClassDesc(arrayClDesc, false);
- Integer handle = nextHandle();
-
+ int handle = nextHandle();
if (!unshared) {
objectsWritten.put(array, handle);
}
@@ -1379,8 +1283,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* Write class {@code object} into the receiver. It is assumed the
* class has not been dumped yet. Classes are not really dumped, but a class
* descriptor ({@code ObjectStreamClass}) that corresponds to them.
- * Return an {@code Integer} that represents the handle for this
- * object (class) which is dumped here.
+ * Returns the handle for this object (class) which is dumped here.
*
* @param object
* The {@code java.lang.Class} object to dump
@@ -1389,8 +1292,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @throws IOException
* If an IO exception happened when writing the class.
*/
- private Integer writeNewClass(Class<?> object, boolean unshared)
- throws IOException {
+ private int writeNewClass(Class<?> object, boolean unshared) throws IOException {
output.writeByte(TC_CLASS);
// Instances of java.lang.Class are always Serializable, even if their
@@ -1408,8 +1310,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
writeClassDesc(clDesc, unshared);
}
- Integer handle = nextHandle();
-
+ int handle = nextHandle();
if (!unshared) {
objectsWritten.put(object, handle);
}
@@ -1420,9 +1321,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Write class descriptor {@code classDesc} into the receiver. It is
* assumed the class descriptor has not been dumped yet. The class
- * descriptors for the superclass chain will be dumped as well. Return an
- * {@code Integer} that represents the handle for this object (class
- * descriptor) which is dumped here.
+ * descriptors for the superclass chain will be dumped as well. Returns
+ * the handle for this object (class descriptor) which is dumped here.
*
* @param classDesc
* The {@code ObjectStreamClass} object to dump
@@ -1472,8 +1372,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Write exception {@code ex} into the receiver. It is assumed the
- * exception has not been dumped yet. Return an {@code Integer} that
- * represents the handle for this object (exception) which is dumped here.
+ * exception has not been dumped yet. Returns
+ * the handle for this object (exception) which is dumped here.
* This is used to dump the exception instance that happened (if any) when
* dumping the original object graph. The set of seen objects will be reset
* just before and just after dumping this exception object.
@@ -1498,8 +1398,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Write object {@code object} of class {@code theClass} into
- * the receiver. It is assumed the object has not been dumped yet. Return an
- * {@code Integer} that represents the handle for this object which
+ * the receiver. It is assumed the object has not been dumped yet.
+ * Return the handle for this object which
* is dumped here.
*
* If the object implements {@code Externalizable} its
@@ -1520,7 +1420,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @throws IOException
* If an IO exception happened when writing the object.
*/
- private Integer writeNewObject(Object object, Class<?> theClass, ObjectStreamClass clDesc,
+ private int writeNewObject(Object object, Class<?> theClass, ObjectStreamClass clDesc,
boolean unshared) throws IOException {
// Not String, not null, not array, not cyclic reference
@@ -1538,12 +1438,12 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
// Either serializable or externalizable, now we can save info
output.writeByte(TC_OBJECT);
writeClassDesc(clDesc, false);
- Integer previousHandle = null;
+ int previousHandle = -1;
if (unshared) {
previousHandle = objectsWritten.get(object);
}
- Integer handle = nextHandle();
- objectsWritten.put(object, handle);
+
+ int handle = registerObjectWritten(object);
// This is how we know what to do in defaultWriteObject. And it is also
// used by defaultWriteObject to check if it was called from an invalid
@@ -1591,8 +1491,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
/**
* Write String {@code object} into the receiver. It is assumed the
- * String has not been dumped yet. Return an {@code Integer} that
- * represents the handle for this object (String) which is dumped here.
+ * String has not been dumped yet. Returns the handle for this object (String) which is dumped here.
* Strings are saved encoded with {@link DataInput modified UTF-8}.
*
* @param object
@@ -1602,25 +1501,25 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
* @throws IOException
* If an IO exception happened when writing the String.
*/
- private Integer writeNewString(String object, boolean unshared)
- throws IOException {
- long count = output.countUTFBytes(object);
+ private int writeNewString(String object, boolean unshared) throws IOException {
+ long count = ModifiedUtf8.countBytes(object, false);
byte[] buffer;
int offset = 0;
if (count <= 0xffff) {
- buffer = new byte[(int)count+3];
+ buffer = new byte[1 + SizeOf.SHORT + (int) count];
buffer[offset++] = TC_STRING;
- offset = output.writeShortToBuffer((short) count, buffer, offset);
+ OSMemory.pokeShort(buffer, offset, (short) count, ByteOrder.BIG_ENDIAN);
+ offset += SizeOf.SHORT;
} else {
- buffer = new byte[(int)count+9];
+ buffer = new byte[1 + SizeOf.LONG + (int) count];
buffer[offset++] = TC_LONGSTRING;
- offset = output.writeLongToBuffer(count, buffer, offset);
+ OSMemory.pokeLong(buffer, offset, count, ByteOrder.BIG_ENDIAN);
+ offset += SizeOf.LONG;
}
- offset = output.writeUTFBytesToBuffer(object, buffer, offset);
- output.write(buffer, 0, offset);
-
- Integer handle = nextHandle();
+ ModifiedUtf8.encode(buffer, offset, object);
+ output.write(buffer, 0, buffer.length);
+ int handle = nextHandle();
if (!unshared) {
objectsWritten.put(object, handle);
}
@@ -1669,40 +1568,39 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
writeObject(object, true);
}
- private void writeObject(Object object, boolean unshared)
- throws IOException {
+ private void writeObject(Object object, boolean unshared) throws IOException {
boolean setOutput = (primitiveTypes == output);
if (setOutput) {
primitiveTypes = null;
}
- // This is the spec'ed behavior in JDK 1.2. Very bizarre way to allow
+ // This is the specified behavior in JDK 1.2. Very bizarre way to allow
// behavior overriding.
if (subclassOverridingImplementation && !unshared) {
writeObjectOverride(object);
- } else {
+ return;
+ }
- try {
- // First we need to flush primitive types if they were written
- drain();
- // Actual work, and class-based replacement should be computed
- // if needed.
- writeObjectInternal(object, unshared, true, true);
- if (setOutput) {
- primitiveTypes = output;
- }
- } catch (IOException ioEx1) {
- // This will make it pass through until the top caller. It also
- // lets it pass through the nested exception.
- if (nestedLevels == 0 && ioEx1 != nestedException) {
- try {
- writeNewException(ioEx1);
- } catch (IOException ioEx2) {
- nestedException.fillInStackTrace();
- throw nestedException;
- }
+ try {
+ // First we need to flush primitive types if they were written
+ drain();
+ // Actual work, and class-based replacement should be computed
+ // if needed.
+ writeObjectInternal(object, unshared, true, true);
+ if (setOutput) {
+ primitiveTypes = output;
+ }
+ } catch (IOException ioEx1) {
+ // This will make it pass through until the top caller. It also
+ // lets it pass through the nested exception.
+ if (nestedLevels == 0 && ioEx1 != nestedException) {
+ try {
+ writeNewException(ioEx1);
+ } catch (IOException ioEx2) {
+ nestedException.fillInStackTrace();
+ throw nestedException;
}
- throw ioEx1; // and then we propagate the original exception
}
+ throw ioEx1; // and then we propagate the original exception
}
}
@@ -1726,18 +1624,18 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
*
* @see ObjectInputStream#readObject()
*/
- private Integer writeObjectInternal(Object object, boolean unshared,
+ private int writeObjectInternal(Object object, boolean unshared,
boolean computeClassBasedReplacement,
boolean computeStreamReplacement) throws IOException {
if (object == null) {
writeNull();
- return null;
+ return -1;
}
- Integer handle = null;
+ int handle = -1;
if (!unshared) {
handle = dumpCycle(object);
- if (handle != null) {
+ if (handle != -1) {
return handle; // cyclic reference
}
}
@@ -1760,9 +1658,8 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
}
}
- if (clDesc.isSerializable()
- && computeClassBasedReplacement) {
- if(clDesc.hasMethodWriteReplace()){
+ if (clDesc.isSerializable() && computeClassBasedReplacement) {
+ if (clDesc.hasMethodWriteReplace()){
Method methodWriteReplace = clDesc.getMethodWriteReplace();
Object replObj = null;
try {
@@ -1783,12 +1680,11 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
}
if (replObj != object) {
// All over, class-based replacement off this time.
- Integer replacementHandle = writeObjectInternal(
- replObj, false, false,
+ int replacementHandle = writeObjectInternal(replObj, false, false,
computeStreamReplacement);
// Make the original object also map to the same
// handle.
- if (replacementHandle != null) {
+ if (replacementHandle != -1) {
objectsWritten.put(object, replacementHandle);
}
return replacementHandle;
@@ -1805,11 +1701,10 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
Object streamReplacement = replaceObject(object);
if (streamReplacement != object) {
// All over, class-based replacement off this time.
- Integer replacementHandle = writeObjectInternal(
- streamReplacement, false,
+ int replacementHandle = writeObjectInternal(streamReplacement, false,
computeClassBasedReplacement, false);
// Make the original object also map to the same handle.
- if (replacementHandle != null) {
+ if (replacementHandle != -1) {
objectsWritten.put(object, replacementHandle);
}
return replacementHandle;
@@ -1857,19 +1752,19 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
// set flag for enum, the flag is (SC_SERIALIZABLE | SC_ENUM)
classDesc.setFlags((byte) (SC_SERIALIZABLE | SC_ENUM));
- Integer previousHandle = null;
+ int previousHandle = -1;
if (unshared) {
previousHandle = objectsWritten.get(classDesc);
}
- Integer handle = null;
+ int handle = -1;
if (!unshared) {
handle = dumpCycle(classDesc);
}
- if (handle == null) {
+ if (handle == -1) {
Class<?> classToWrite = classDesc.forClass();
// If we got here, it is a new (non-null) classDesc that will have
// to be registered as well
- objectsWritten.put(classDesc, nextHandle());
+ registerObjectWritten(classDesc);
output.writeByte(TC_CLASSDESC);
if (protocolVersion == PROTOCOL_VERSION_1) {
@@ -1887,7 +1782,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
output.writeByte(TC_ENDBLOCKDATA);
// write super class
ObjectStreamClass superClassDesc = classDesc.getSuperclass();
- if (null != superClassDesc) {
+ if (superClassDesc != null) {
// super class is also enum
superClassDesc.setFlags((byte) (SC_SERIALIZABLE | SC_ENUM));
writeEnumDesc(superClassDesc.forClass(), superClassDesc, unshared);
@@ -1902,8 +1797,7 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
return classDesc;
}
- private Integer writeNewEnum(Object object, Class<?> theClass,
- boolean unshared) throws IOException {
+ private int writeNewEnum(Object object, Class<?> theClass, boolean unshared) throws IOException {
// write new Enum
EmulatedFieldsForDumping originalCurrentPutField = currentPutField; // save
// null it, to make sure one will be computed if needed
@@ -1917,29 +1811,31 @@ public class ObjectOutputStream extends OutputStream implements ObjectOutput,
ObjectStreamClass classDesc = ObjectStreamClass.lookup(theClass);
writeEnumDesc(theClass, classDesc, unshared);
- Integer previousHandle = null;
+ int previousHandle = -1;
if (unshared) {
previousHandle = objectsWritten.get(object);
}
- Integer handle = nextHandle();
- objectsWritten.put(object, handle);
+ int handle = registerObjectWritten(object);
ObjectStreamField[] fields = classDesc.getSuperclass().fields();
- Class<?> declaringClass = classDesc.getSuperclass().forClass();
// Only write field "name" for enum class, which is the second field of
// enum, that is fields[1]. Ignore all non-fields and fields.length < 2
- if (null != fields && fields.length > 1) {
- // BEGIN android-changed
- String str = (String) getFieldObj(object, declaringClass, fields[1]
- .getName(), fields[1].getTypeString());
- // END android-changed
-
- Integer strhandle = null;
- if (!unshared) {
- strhandle = dumpCycle(str);
+ if (fields != null && fields.length > 1) {
+ Field field = classDesc.getSuperclass().getReflectionField(fields[1]);
+ if (field == null) {
+ throw new NoSuchFieldError();
}
- if (null == strhandle) {
- writeNewString(str, unshared);
+ try {
+ String str = (String) field.get(object);
+ int strHandle = -1;
+ if (!unshared) {
+ strHandle = dumpCycle(str);
+ }
+ if (strHandle == -1) {
+ writeNewString(str, unshared);
+ }
+ } catch (IllegalAccessException iae) {
+ throw new AssertionError(iae);
}
}
diff --git a/luni/src/main/java/java/io/ObjectStreamClass.java b/luni/src/main/java/java/io/ObjectStreamClass.java
index 7f968af..9e6b86a 100644
--- a/luni/src/main/java/java/io/ObjectStreamClass.java
+++ b/luni/src/main/java/java/io/ObjectStreamClass.java
@@ -17,22 +17,25 @@
package java.io;
-import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
+import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
import java.util.WeakHashMap;
+import libcore.base.EmptyArray;
+import org.apache.harmony.luni.platform.OSMemory;
import org.apache.harmony.luni.util.PriviAction;
-import org.apache.harmony.luni.util.ThreadLocalCache;
/**
* Represents a descriptor for identifying a class during serialization and
@@ -55,42 +58,19 @@ public class ObjectStreamClass implements Serializable {
static final long CONSTRUCTOR_IS_NOT_RESOLVED = -1;
- private static final int CLASS_MODIFIERS_MASK;
+ private static final int CLASS_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.FINAL |
+ Modifier.INTERFACE | Modifier.ABSTRACT;
- private static final int FIELD_MODIFIERS_MASK;
+ private static final int FIELD_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.PRIVATE |
+ Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL | Modifier.VOLATILE |
+ Modifier.TRANSIENT;
- private static final int METHOD_MODIFIERS_MASK;
+ private static final int METHOD_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.PRIVATE |
+ Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL | Modifier.SYNCHRONIZED |
+ Modifier.NATIVE | Modifier.ABSTRACT | Modifier.STRICT;
- private static final Class<?>[] READ_PARAM_TYPES;
-
- private static final Class<?>[] WRITE_PARAM_TYPES;
-
- static final Class<?>[] EMPTY_CONSTRUCTOR_PARAM_TYPES;
-
- private static final Class<Void> VOID_CLASS;
-
- static final Class<?>[] UNSHARED_PARAM_TYPES;
-
- static {
- CLASS_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.FINAL
- | Modifier.INTERFACE | Modifier.ABSTRACT;
- FIELD_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.PRIVATE
- | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
- | Modifier.VOLATILE | Modifier.TRANSIENT;
- METHOD_MODIFIERS_MASK = Modifier.PUBLIC | Modifier.PRIVATE
- | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL
- | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.ABSTRACT
- | Modifier.STRICT;
-
- READ_PARAM_TYPES = new Class[1];
- WRITE_PARAM_TYPES = new Class[1];
- READ_PARAM_TYPES[0] = ObjectInputStream.class;
- WRITE_PARAM_TYPES[0] = ObjectOutputStream.class;
- EMPTY_CONSTRUCTOR_PARAM_TYPES = new Class[0];
- VOID_CLASS = Void.TYPE;
- UNSHARED_PARAM_TYPES = new Class[1];
- UNSHARED_PARAM_TYPES[0] = Object.class;
- }
+ private static final Class<?>[] READ_PARAM_TYPES = new Class[] { ObjectInputStream.class };
+ private static final Class<?>[] WRITE_PARAM_TYPES = new Class[] { ObjectOutputStream.class };
/**
* Constant indicating that the class has no Serializable fields.
@@ -166,7 +146,10 @@ public class ObjectStreamClass implements Serializable {
private transient String className;
// Corresponding loaded class with the name above
- private transient WeakReference<Class<?>> resolvedClass;
+ private transient Class<?> resolvedClass;
+
+ private transient Class<?> resolvedConstructorClass;
+ private transient int resolvedConstructorMethodId;
// Serial version UID of the class the descriptor represents
private transient long svUID;
@@ -188,6 +171,11 @@ public class ObjectStreamClass implements Serializable {
// Array of ObjectStreamField describing the serialized fields of this class
private transient ObjectStreamField[] loadFields;
+ // ObjectStreamField doesn't override hashCode or equals, so this is equivalent to an
+ // IdentityHashMap, which is fine for our purposes.
+ private transient HashMap<ObjectStreamField, Field> reflectionFields =
+ new HashMap<ObjectStreamField, Field>();
+
// MethodID for deserialization constructor
private transient long constructor = CONSTRUCTOR_IS_NOT_RESOLVED;
@@ -199,6 +187,28 @@ public class ObjectStreamClass implements Serializable {
return constructor;
}
+ Field getReflectionField(ObjectStreamField osf) {
+ synchronized (reflectionFields) {
+ Field field = reflectionFields.get(osf);
+ if (field != null) {
+ return field;
+ }
+ }
+
+ try {
+ Class<?> declaringClass = forClass();
+ Field field = declaringClass.getDeclaredField(osf.getName());
+ field.setAccessible(true);
+ synchronized (reflectionFields) {
+ reflectionFields.put(osf, field);
+ }
+ return reflectionFields.get(osf);
+ } catch (NoSuchFieldException ex) {
+ // The caller messed up. We'll return null and won't try to resolve this again.
+ return null;
+ }
+ }
+
/*
* If an ObjectStreamClass describes an Externalizable class, it (the
* descriptor) should not have field descriptors (ObjectStreamField) at all.
@@ -244,13 +254,12 @@ public class ObjectStreamClass implements Serializable {
Field[] declaredFields = null;
// Compute the SUID
- if(serializable || externalizable) {
+ if (serializable || externalizable) {
if (result.isEnum() || result.isProxy()) {
result.setSerialVersionUID(0L);
} else {
declaredFields = cl.getDeclaredFields();
- result.setSerialVersionUID(computeSerialVersionUID(cl,
- declaredFields));
+ result.setSerialVersionUID(computeSerialVersionUID(cl, declaredFields));
}
}
@@ -292,12 +301,9 @@ public class ObjectStreamClass implements Serializable {
}
result.methodWriteReplace = findMethod(cl, "writeReplace");
result.methodReadResolve = findMethod(cl, "readResolve");
- result.methodWriteObject = findPrivateMethod(cl, "writeObject",
- WRITE_PARAM_TYPES);
- result.methodReadObject = findPrivateMethod(cl, "readObject",
- READ_PARAM_TYPES);
- result.methodReadObjectNoData = findPrivateMethod(cl,
- "readObjectNoData", EMPTY_CONSTRUCTOR_PARAM_TYPES);
+ result.methodWriteObject = findPrivateMethod(cl, "writeObject", WRITE_PARAM_TYPES);
+ result.methodReadObject = findPrivateMethod(cl, "readObject", READ_PARAM_TYPES);
+ result.methodReadObjectNoData = findPrivateMethod(cl, "readObjectNoData", EmptyArray.CLASS);
if (result.hasMethodWriteObject()) {
flags |= ObjectStreamConstants.SC_WRITE_METHOD;
}
@@ -316,8 +322,7 @@ public class ObjectStreamClass implements Serializable {
void buildFieldDescriptors(Field[] declaredFields) {
// We could find the field ourselves in the collection, but calling
// reflect is easier. Optimize if needed.
- final Field f = ObjectStreamClass.fieldSerialPersistentFields(this
- .forClass());
+ final Field f = ObjectStreamClass.fieldSerialPersistentFields(this.forClass());
// If we could not find the emulated fields, we'll have to compute
// dumpable fields from reflect fields
boolean useReflectFields = f == null; // Assume we will compute the
@@ -333,23 +338,18 @@ public class ObjectStreamClass implements Serializable {
// static field, pass null
_fields = (ObjectStreamField[]) f.get(null);
} catch (IllegalAccessException ex) {
- // WARNING - what should we do if we have no access ? This
- // should not happen.
- throw new RuntimeException(ex);
+ throw new AssertionError(ex);
}
} else {
// Compute collection of dumpable fields based on reflect fields
- List<ObjectStreamField> serializableFields = new ArrayList<ObjectStreamField>(
- declaredFields.length);
+ List<ObjectStreamField> serializableFields =
+ new ArrayList<ObjectStreamField>(declaredFields.length);
// Filter, we are only interested in fields that are serializable
- for (int i = 0; i < declaredFields.length; i++) {
- Field declaredField = declaredFields[i];
+ for (Field declaredField : declaredFields) {
int modifiers = declaredField.getModifiers();
- boolean shouldBeSerialized = !(Modifier.isStatic(modifiers) || Modifier
- .isTransient(modifiers));
- if (shouldBeSerialized) {
- ObjectStreamField field = new ObjectStreamField(
- declaredField.getName(), declaredField.getType());
+ if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) {
+ ObjectStreamField field = new ObjectStreamField(declaredField.getName(),
+ declaredField.getType());
serializableFields.add(field);
}
}
@@ -358,12 +358,10 @@ public class ObjectStreamClass implements Serializable {
_fields = NO_FIELDS; // If no serializable fields, share the
// special value so that users can test
} else {
- // Now convert from Vector to array
- _fields = new ObjectStreamField[serializableFields.size()];
- _fields = serializableFields.toArray(_fields);
+ _fields = serializableFields.toArray(new ObjectStreamField[serializableFields.size()]);
}
}
- ObjectStreamField.sortFields(_fields);
+ Arrays.sort(_fields);
// assign offsets
int primOffset = 0, objectOffset = 0;
for (int i = 0; i < _fields.length; i++) {
@@ -588,12 +586,11 @@ public class ObjectStreamClass implements Serializable {
// now compute the UID based on the SHA
byte[] hash = digest.digest(sha.toByteArray());
-
- return littleEndianLongAt(hash, 0);
+ return OSMemory.peekLong(hash, 0, ByteOrder.LITTLE_ENDIAN);
}
/**
- * Returns what the serializaton specification calls "descriptor" given a
+ * Returns what the serialization specification calls "descriptor" given a
* field signature.
*
* @param signature
@@ -605,7 +602,7 @@ public class ObjectStreamClass implements Serializable {
}
/**
- * Return what the serializaton specification calls "descriptor" given a
+ * Return what the serialization specification calls "descriptor" given a
* method/constructor signature.
*
* @param signature
@@ -649,10 +646,110 @@ public class ObjectStreamClass implements Serializable {
* {@code null} if there is no corresponding class.
*/
public Class<?> forClass() {
- if (resolvedClass != null) {
- return resolvedClass.get();
+ return resolvedClass;
+ }
+
+ /**
+ * Create and return a new instance of class 'instantiationClass'
+ * using JNI to call the constructor chosen by resolveConstructorClass.
+ *
+ * The returned instance may have uninitialized fields, including final fields.
+ */
+ Object newInstance(Class<?> instantiationClass) throws InvalidClassException {
+ resolveConstructorClass(instantiationClass);
+ return newInstance(instantiationClass, resolvedConstructorMethodId);
+ }
+ private static native Object newInstance(Class<?> instantiationClass, int methodId);
+
+ private Class<?> resolveConstructorClass(Class<?> objectClass) throws InvalidClassException {
+ if (resolvedConstructorClass != null) {
+ return resolvedConstructorClass;
}
- return null;
+
+ // The class of the instance may not be the same as the class of the
+ // constructor to run
+ // This is the constructor to run if Externalizable
+ Class<?> constructorClass = objectClass;
+
+ // WARNING - What if the object is serializable and externalizable ?
+ // Is that possible ?
+ boolean wasSerializable = (flags & ObjectStreamConstants.SC_SERIALIZABLE) != 0;
+ if (wasSerializable) {
+ // Now we must run the constructor of the class just above the
+ // one that implements Serializable so that slots that were not
+ // dumped can be initialized properly
+ while (constructorClass != null && ObjectStreamClass.isSerializable(constructorClass)) {
+ constructorClass = constructorClass.getSuperclass();
+ }
+ }
+
+ // Fetch the empty constructor, or null if none.
+ Constructor<?> constructor = null;
+ if (constructorClass != null) {
+ try {
+ constructor = constructorClass.getDeclaredConstructor(EmptyArray.CLASS);
+ } catch (NoSuchMethodException ignored) {
+ }
+ }
+
+ // Has to have an empty constructor
+ if (constructor == null) {
+ String className = constructorClass != null ? constructorClass.getName() : null;
+ throw new InvalidClassException(className, "IllegalAccessException");
+ }
+
+ int constructorModifiers = constructor.getModifiers();
+ boolean isPublic = Modifier.isPublic(constructorModifiers);
+ boolean isProtected = Modifier.isProtected(constructorModifiers);
+ boolean isPrivate = Modifier.isPrivate(constructorModifiers);
+
+ // Now we must check if the empty constructor is visible to the
+ // instantiation class
+ boolean wasExternalizable = (flags & ObjectStreamConstants.SC_EXTERNALIZABLE) != 0;
+ if (isPrivate || (wasExternalizable && !isPublic)) {
+ throw new InvalidClassException(constructorClass.getName(), "IllegalAccessException");
+ }
+
+ // We know we are testing from a subclass, so the only other case
+ // where the visibility is not allowed is when the constructor has
+ // default visibility and the instantiation class is in a different
+ // package than the constructor class
+ if (!isPublic && !isProtected) {
+ // Not public, not private and not protected...means default
+ // visibility. Check if same package
+ if (!inSamePackage(constructorClass, objectClass)) {
+ throw new InvalidClassException(constructorClass.getName(), "IllegalAccessException");
+ }
+ }
+
+ resolvedConstructorClass = constructorClass;
+ resolvedConstructorMethodId = getConstructorId(resolvedConstructorClass);
+ return constructorClass;
+ }
+ private static native int getConstructorId(Class<?> c);
+
+ /**
+ * Checks if two classes belong to the same package.
+ *
+ * @param c1
+ * one of the classes to test.
+ * @param c2
+ * the other class to test.
+ * @return {@code true} if the two classes belong to the same package,
+ * {@code false} otherwise.
+ */
+ private boolean inSamePackage(Class<?> c1, Class<?> c2) {
+ String nameC1 = c1.getName();
+ String nameC2 = c2.getName();
+ int indexDotC1 = nameC1.lastIndexOf('.');
+ int indexDotC2 = nameC2.lastIndexOf('.');
+ if (indexDotC1 != indexDotC2) {
+ return false; // cannot be in the same package if indices are not the same
+ }
+ if (indexDotC1 == -1) {
+ return true; // both of them are in default package
+ }
+ return nameC1.regionMatches(0, nameC2, 0, indexDotC1);
}
/**
@@ -717,6 +814,24 @@ public class ObjectStreamClass implements Serializable {
return loadFields == null ? fields().clone() : loadFields.clone();
}
+ private volatile List<ObjectStreamClass> cachedHierarchy;
+
+ List<ObjectStreamClass> getHierarchy() {
+ List<ObjectStreamClass> result = cachedHierarchy;
+ if (result == null) {
+ cachedHierarchy = result = makeHierarchy();
+ }
+ return result;
+ }
+
+ private List<ObjectStreamClass> makeHierarchy() {
+ ArrayList<ObjectStreamClass> result = new ArrayList<ObjectStreamClass>();
+ for (ObjectStreamClass osc = this; osc != null; osc = osc.getSuperclass()) {
+ result.add(0, osc);
+ }
+ return result;
+ }
+
/**
* If a Class uses "serialPersistentFields" to define the serialized fields,
* this.loadFields cannot get the "unshared" information when deserializing
@@ -913,23 +1028,6 @@ public class ObjectStreamClass implements Serializable {
}
/**
- * Return a little endian long stored in a given position of the buffer
- *
- * @param buffer
- * a byte array with the byte representation of the number
- * @param position
- * index where the number starts in the byte array
- * @return the number that was stored in little endian format
- */
- private static long littleEndianLongAt(byte[] buffer, int position) {
- long result = 0;
- for (int i = position + 7; i >= position; i--) {
- result = (result << 8) + (buffer[i] & 0xff);
- }
- return result;
- }
-
- /**
* Returns the descriptor for a serializable class.
* Returns null if the class doesn't implement {@code Serializable} or {@code Externalizable}.
*
@@ -941,12 +1039,7 @@ public class ObjectStreamClass implements Serializable {
*/
public static ObjectStreamClass lookup(Class<?> cl) {
ObjectStreamClass osc = lookupStreamClass(cl);
-
- if (osc.isSerializable() || osc.isExternalizable()) {
- return osc;
- }
-
- return null;
+ return (osc.isSerializable() || osc.isExternalizable()) ? osc : null;
}
/**
@@ -960,7 +1053,7 @@ public class ObjectStreamClass implements Serializable {
* @since 1.6
*/
public static ObjectStreamClass lookupAny(Class<?> cl) {
- return lookupStreamClass(cl);
+ return lookupStreamClass(cl);
}
/**
@@ -974,9 +1067,7 @@ public class ObjectStreamClass implements Serializable {
* @return the corresponding descriptor
*/
static ObjectStreamClass lookupStreamClass(Class<?> cl) {
-
- WeakHashMap<Class<?>,ObjectStreamClass> tlc = OSCThreadLocalCache.oscWeakHashMap.get();
-
+ WeakHashMap<Class<?>, ObjectStreamClass> tlc = getCache();
ObjectStreamClass cachedValue = tlc.get(cl);
if (cachedValue == null) {
cachedValue = createClassDesc(cl);
@@ -987,6 +1078,26 @@ public class ObjectStreamClass implements Serializable {
}
/**
+ * A ThreadLocal cache for lookupStreamClass, with the possibility of discarding the thread
+ * local storage content when the heap is exhausted.
+ */
+ private static SoftReference<ThreadLocal<WeakHashMap<Class<?>, ObjectStreamClass>>> storage =
+ new SoftReference<ThreadLocal<WeakHashMap<Class<?>, ObjectStreamClass>>>(null);
+
+ private static WeakHashMap<Class<?>, ObjectStreamClass> getCache() {
+ ThreadLocal<WeakHashMap<Class<?>, ObjectStreamClass>> tls = storage.get();
+ if (tls == null) {
+ tls = new ThreadLocal<WeakHashMap<Class<?>, ObjectStreamClass>>() {
+ public WeakHashMap<Class<?>, ObjectStreamClass> initialValue() {
+ return new WeakHashMap<Class<?>, ObjectStreamClass>();
+ }
+ };
+ storage = new SoftReference<ThreadLocal<WeakHashMap<Class<?>, ObjectStreamClass>>>(tls);
+ }
+ return tls.get();
+ }
+
+ /**
* Return the java.lang.reflect.Method if class <code>cl</code> implements
* <code>methodName</code> . Return null otherwise.
*
@@ -1028,8 +1139,7 @@ public class ObjectStreamClass implements Serializable {
Class<?>[] param) {
try {
Method method = cl.getDeclaredMethod(methodName, param);
- if (Modifier.isPrivate(method.getModifiers())
- && method.getReturnType() == VOID_CLASS) {
+ if (Modifier.isPrivate(method.getModifiers()) && method.getReturnType() == Void.TYPE) {
method.setAccessible(true);
return method;
}
@@ -1094,7 +1204,7 @@ public class ObjectStreamClass implements Serializable {
* aClass, the new class that the receiver describes
*/
void setClass(Class<?> c) {
- resolvedClass = new WeakReference<Class<?>>(c);
+ resolvedClass = c;
}
/**
@@ -1192,19 +1302,6 @@ public class ObjectStreamClass implements Serializable {
*/
@Override
public String toString() {
- return getName() + ": static final long serialVersionUID ="
- + getSerialVersionUID() + "L;";
- }
-
- static class OSCThreadLocalCache extends ThreadLocalCache {
-
- // thread-local cache for ObjectStreamClass.lookup
- public static ThreadLocalCache<WeakHashMap<Class<?>,ObjectStreamClass>> oscWeakHashMap = new ThreadLocalCache<WeakHashMap<Class<?>,ObjectStreamClass>>() {
- protected WeakHashMap<Class<?>,ObjectStreamClass> initialValue() {
- return new WeakHashMap<Class<?>,ObjectStreamClass>();
- }
- };
-
+ return getName() + ": static final long serialVersionUID =" + getSerialVersionUID() + "L;";
}
-
}
diff --git a/luni/src/main/java/java/io/ObjectStreamField.java b/luni/src/main/java/java/io/ObjectStreamField.java
index 686ea15..3ae34e6 100644
--- a/luni/src/main/java/java/io/ObjectStreamField.java
+++ b/luni/src/main/java/java/io/ObjectStreamField.java
@@ -17,19 +17,10 @@
package java.io;
-// BEGIN android-note
-// Harmony uses ObjectAccessors to access fields through JNI. Android has not
-// yet migrated that API.
-// END android-note
-
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Comparator;
-// BEGIN android-removed
-// import org.apache.harmony.misc.accessors.ObjectAccessor;
-// END android-removed
-
/**
* Describes a field for the purpose of serialization. Classes can define the
* collection of fields that are serialized, which may be different from the set
@@ -40,9 +31,6 @@ import java.util.Comparator;
*/
public class ObjectStreamField implements Comparable<Object> {
- static final int FIELD_IS_NOT_RESOLVED = -1;
- static final int FIELD_IS_ABSENT = -2;
-
// Declared name of the field
private String name;
@@ -59,23 +47,6 @@ public class ObjectStreamField implements Comparable<Object> {
private boolean isDeserialized;
- private long assocFieldID = FIELD_IS_NOT_RESOLVED;
-
- // BEGIN android-removed
- // long getFieldID(ObjectAccessor accessor, Class<?> declaringClass) {
- // if (assocFieldID != FIELD_IS_NOT_RESOLVED) {
- // return assocFieldID;
- // } else {
- // try {
- // assocFieldID = accessor.getFieldID(declaringClass, name);
- // } catch(NoSuchFieldError e) {
- // assocFieldID = FIELD_IS_ABSENT;
- // }
- // return assocFieldID;
- // }
- // }
- // END android-removed
-
/**
* Constructs an ObjectStreamField with the specified name and type.
*
@@ -114,8 +85,7 @@ public class ObjectStreamField implements Comparable<Object> {
throw new NullPointerException();
}
this.name = name;
- this.type = (cl.getClassLoader() == null) ? cl
- : new WeakReference<Class<?>>(cl);
+ this.type = (cl.getClassLoader() == null) ? cl : new WeakReference<Class<?>>(cl);
this.unshared = unshared;
}
@@ -165,19 +135,6 @@ public class ObjectStreamField implements Comparable<Object> {
return this.getName().compareTo(f.getName());
}
- // BEGIN android-removed
- // There shouldn't be an implementation of these methods.
- // @Override
- // public boolean equals(Object arg0) {
- // return (arg0 instanceof ObjectStreamField) && (compareTo(arg0) == 0);
- // }
- //
- // @Override
- // public int hashCode() {
- // return getName().hashCode();
- // }
- // END android-removed
-
/**
* Gets the name of this field.
*
@@ -245,35 +202,31 @@ public class ObjectStreamField implements Comparable<Object> {
* @return the field's type code.
*/
public char getTypeCode() {
- Class<?> t = getTypeInternal();
- if (t == Integer.TYPE) {
+ return typeCodeOf(getTypeInternal());
+ }
+
+ private char typeCodeOf(Class<?> type) {
+ if (type == Integer.TYPE) {
return 'I';
- }
- if (t == Byte.TYPE) {
+ } else if (type == Byte.TYPE) {
return 'B';
- }
- if (t == Character.TYPE) {
+ } else if (type == Character.TYPE) {
return 'C';
- }
- if (t == Short.TYPE) {
+ } else if (type == Short.TYPE) {
return 'S';
- }
- if (t == Boolean.TYPE) {
+ } else if (type == Boolean.TYPE) {
return 'Z';
- }
- if (t == Long.TYPE) {
+ } else if (type == Long.TYPE) {
return 'J';
- }
- if (t == Float.TYPE) {
+ } else if (type == Float.TYPE) {
return 'F';
- }
- if (t == Double.TYPE) {
+ } else if (type == Double.TYPE) {
return 'D';
- }
- if (t.isArray()) {
+ } else if (type.isArray()) {
return '[';
+ } else {
+ return 'L';
}
- return 'L';
}
/**
@@ -307,6 +260,13 @@ public class ObjectStreamField implements Comparable<Object> {
return t != null && t.isPrimitive();
}
+ boolean writeField(DataOutputStream out) throws IOException {
+ Class<?> t = getTypeInternal();
+ out.writeByte(typeCodeOf(t));
+ out.writeUTF(name);
+ return (t != null && t.isPrimitive());
+ }
+
/**
* Sets this field's offset in the object.
*
@@ -325,31 +285,11 @@ public class ObjectStreamField implements Comparable<Object> {
*/
@Override
public String toString() {
- return this.getClass().getName() + '(' + getName() + ':'
- + getTypeInternal() + ')';
- }
-
- /**
- * Sorts the fields for dumping. Primitive types come first, then regular
- * types.
- *
- * @param fields
- * ObjectStreamField[] fields to be sorted
- */
- static void sortFields(ObjectStreamField[] fields) {
- // Sort if necessary
- if (fields.length > 1) {
- Comparator<ObjectStreamField> fieldDescComparator = new Comparator<ObjectStreamField>() {
- public int compare(ObjectStreamField f1, ObjectStreamField f2) {
- return f1.compareTo(f2);
- }
- };
- Arrays.sort(fields, fieldDescComparator);
- }
+ return this.getClass().getName() + '(' + getName() + ':' + getTypeInternal() + ')';
}
void resolve(ClassLoader loader) {
- if (typeString == null && isPrimitive()){
+ if (typeString == null && isPrimitive()) {
// primitive type declared in a serializable class
typeString = String.valueOf(getTypeCode());
}
diff --git a/luni/src/main/java/java/io/OutputStream.java b/luni/src/main/java/java/io/OutputStream.java
index 425ab82..95f6102 100644
--- a/luni/src/main/java/java/io/OutputStream.java
+++ b/luni/src/main/java/java/io/OutputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* The base class for all output streams. An output stream is a means of writing
* data to a target in a byte-wise manner. Most output streams expect the
@@ -99,23 +101,7 @@ public abstract class OutputStream implements Closeable, Flushable {
* {@code buffer}.
*/
public void write(byte[] buffer, int offset, int count) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- // avoid int overflow, check null buffer
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, made implicit null check explicit,
- // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
- // to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
for (int i = offset; i < offset + count; i++) {
write(buffer[i]);
}
diff --git a/luni/src/main/java/java/io/OutputStreamWriter.java b/luni/src/main/java/java/io/OutputStreamWriter.java
index e1a515b..699263d 100644
--- a/luni/src/main/java/java/io/OutputStreamWriter.java
+++ b/luni/src/main/java/java/io/OutputStreamWriter.java
@@ -23,6 +23,7 @@ import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
import java.nio.charset.CodingErrorAction;
+import java.util.Arrays;
import org.apache.harmony.luni.util.HistoricalNamesUtil;
/**
@@ -212,15 +213,7 @@ public class OutputStreamWriter extends Writer {
public void write(char[] buffer, int offset, int count) throws IOException {
synchronized (lock) {
checkStatus();
- if (offset < 0) {
- throw new IndexOutOfBoundsException();
- }
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if (count < 0 || offset > buffer.length - count) {
- throw new IndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
CharBuffer chars = CharBuffer.wrap(buffer, offset, count);
convert(chars);
}
@@ -285,13 +278,13 @@ public class OutputStreamWriter extends Writer {
public void write(String str, int offset, int count) throws IOException {
synchronized (lock) {
if (count < 0) {
- throw new StringIndexOutOfBoundsException();
+ throw new StringIndexOutOfBoundsException(str, offset, count);
}
if (str == null) {
throw new NullPointerException("str == null");
}
- if (offset < 0 || offset > str.length() - count) {
- throw new StringIndexOutOfBoundsException();
+ if ((offset | count) < 0 || offset > str.length() - count) {
+ throw new StringIndexOutOfBoundsException(str, offset, count);
}
checkStatus();
CharBuffer chars = CharBuffer.wrap(str, offset, count + offset);
diff --git a/luni/src/main/java/java/io/PipedInputStream.java b/luni/src/main/java/java/io/PipedInputStream.java
index c7e5060..aa77e6e 100644
--- a/luni/src/main/java/java/io/PipedInputStream.java
+++ b/luni/src/main/java/java/io/PipedInputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Receives information from a communications pipe. When two threads want to
* pass data back and forth, one creates a piped output stream and the other one
@@ -253,7 +255,7 @@ public class PipedInputStream extends InputStream {
}
/**
- * Reads at most {@code count} bytes from this stream and stores them in the
+ * Reads at most {@code byteCount} bytes from this stream and stores them in the
* byte array {@code bytes} starting at {@code offset}. Blocks until at
* least one byte has been read, the end of the stream is detected or an
* exception is thrown.
@@ -262,18 +264,11 @@ public class PipedInputStream extends InputStream {
* and to write to the connected {@link PipedOutputStream}. If the same
* thread is used, a deadlock may occur.
*
- * @param bytes
- * the array in which to store the bytes read.
- * @param offset
- * the initial position in {@code bytes} to store the bytes
- * read from this stream.
- * @param count
- * the maximum number of bytes to store in {@code bytes}.
* @return the number of bytes actually read or -1 if the end of the stream
* has been reached.
* @throws IndexOutOfBoundsException
- * if {@code offset < 0} or {@code count < 0}, or if {@code
- * offset + count} is greater than the size of {@code bytes}.
+ * if {@code offset < 0} or {@code byteCount < 0}, or if {@code
+ * offset + byteCount} is greater than the size of {@code bytes}.
* @throws InterruptedIOException
* if the thread reading from this stream is interrupted.
* @throws IOException
@@ -284,17 +279,9 @@ public class PipedInputStream extends InputStream {
* if {@code bytes} is {@code null}.
*/
@Override
- public synchronized int read(byte[] bytes, int offset, int count)
- throws IOException {
- if (bytes == null) {
- throw new NullPointerException("bytes == null");
- }
-
- if ((offset | count) < 0 || count > bytes.length - offset) {
- throw new IndexOutOfBoundsException();
- }
-
- if (count == 0) {
+ public synchronized int read(byte[] bytes, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(bytes.length, offset, byteCount);
+ if (byteCount == 0) {
return 0;
}
@@ -335,7 +322,7 @@ public class PipedInputStream extends InputStream {
// copy bytes from out thru the end of buffer
if (out >= in) {
int leftInBuffer = buffer.length - out;
- int length = leftInBuffer < count ? leftInBuffer : count;
+ int length = leftInBuffer < byteCount ? leftInBuffer : byteCount;
System.arraycopy(buffer, out, bytes, offset, length);
out += length;
if (out == buffer.length) {
@@ -350,9 +337,9 @@ public class PipedInputStream extends InputStream {
}
// copy bytes from out thru in
- if (totalCopied < count && in != -1) {
+ if (totalCopied < byteCount && in != -1) {
int leftInBuffer = in - out;
- int leftToCopy = count - totalCopied;
+ int leftToCopy = byteCount - totalCopied;
int length = leftToCopy < leftInBuffer ? leftToCopy : leftInBuffer;
System.arraycopy(buffer, out, bytes, offset + totalCopied, length);
out += length;
diff --git a/luni/src/main/java/java/io/PipedReader.java b/luni/src/main/java/java/io/PipedReader.java
index 1a9b9e2..6190c86 100644
--- a/luni/src/main/java/java/io/PipedReader.java
+++ b/luni/src/main/java/java/io/PipedReader.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Receives information on a communications pipe. When two threads want to pass
* data back and forth, one creates a piped writer and the other creates a piped
@@ -233,12 +235,7 @@ public class PipedReader extends Reader {
if (this.buffer == null) {
throw new IOException("Pipe is closed");
}
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
if (count == 0) {
return 0;
}
@@ -270,8 +267,7 @@ public class PipedReader extends Reader {
int copyLength = 0;
/* Copy chars from out to end of buffer first */
if (out >= in) {
- copyLength = count > this.buffer.length - out ? this.buffer.length - out
- : count;
+ copyLength = count > this.buffer.length - out ? this.buffer.length - out : count;
System.arraycopy(this.buffer, out, buffer, offset, copyLength);
out += copyLength;
if (out == this.buffer.length) {
@@ -294,10 +290,8 @@ public class PipedReader extends Reader {
int charsCopied = copyLength;
/* Copy bytes from 0 to the number of available bytes */
- copyLength = in - out > count - copyLength ? count - copyLength
- : in - out;
- System.arraycopy(this.buffer, out, buffer, offset + charsCopied,
- copyLength);
+ copyLength = in - out > count - copyLength ? count - copyLength : in - out;
+ System.arraycopy(this.buffer, out, buffer, offset + charsCopied, copyLength);
out += copyLength;
if (out == in) {
// empty buffer
@@ -389,24 +383,12 @@ public class PipedReader extends Reader {
* If the buffer is full and the thread sending #receive is interrupted, the
* InterruptedIOException will be thrown.
*
- * @param chars
- * the char array to store into the pipe.
- * @param offset
- * offset to start reading from
- * @param count
- * total characters to read
- *
* @throws IOException
* If the stream is already closed or another IOException
* occurs.
*/
synchronized void receive(char[] chars, int offset, int count) throws IOException {
- if (chars == null) {
- throw new NullPointerException("chars == null");
- }
- if ((offset | count) < 0 || count > chars.length - offset) {
- throw new IndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(chars.length, offset, count);
if (buffer == null) {
throw new IOException("Pipe is closed");
}
diff --git a/luni/src/main/java/java/io/PipedWriter.java b/luni/src/main/java/java/io/PipedWriter.java
index 5e6ec68..adb1733 100644
--- a/luni/src/main/java/java/io/PipedWriter.java
+++ b/luni/src/main/java/java/io/PipedWriter.java
@@ -15,16 +15,10 @@
* limitations under the License.
*/
-// BEGIN android-note
-// We've made several changes including:
-// - move checks into the synchronized method in PipedReader
-// - reply on PipedReader's isClosed field (rather than having 2 flags)
-// - avoid shallow concurrency problems
-// - improved consistency with PipedOutputStream
-// END android-note
-
package java.io;
+import java.util.Arrays;
+
/**
* Places information on a communications pipe. When two threads want to pass
* data back and forth, one creates a piped writer and the other creates a piped
diff --git a/luni/src/main/java/java/io/PrintStream.java b/luni/src/main/java/java/io/PrintStream.java
index bae7740..42e6750 100644
--- a/luni/src/main/java/java/io/PrintStream.java
+++ b/luni/src/main/java/java/io/PrintStream.java
@@ -20,6 +20,7 @@ package java.io;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.security.AccessController;
+import java.util.Arrays;
import java.util.Formatter;
import java.util.IllegalFormatException;
import java.util.Locale;
@@ -33,11 +34,7 @@ import org.apache.harmony.luni.util.PriviAction;
* class. Instead, callers should use {@link #checkError()} to see if a problem
* has occurred in this stream.
*/
-public class PrintStream extends FilterOutputStream implements Appendable,
- Closeable {
-
- private static final String TOKEN_NULL = "null";
-
+public class PrintStream extends FilterOutputStream implements Appendable, Closeable {
/**
* indicates whether or not this PrintStream has incurred an error.
*/
@@ -662,13 +659,7 @@ public class PrintStream extends FilterOutputStream implements Appendable,
*/
@Override
public void write(byte[] buffer, int offset, int length) {
- // Force buffer null check first!
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
synchronized (this) {
if (out == null) {
setError();
@@ -740,8 +731,8 @@ public class PrintStream extends FilterOutputStream implements Appendable,
* @return this stream.
*/
public PrintStream append(CharSequence csq) {
- if (null == csq) {
- print(TOKEN_NULL);
+ if (csq == null) {
+ print("null");
} else {
print(csq.toString());
}
@@ -770,11 +761,10 @@ public class PrintStream extends FilterOutputStream implements Appendable,
* the length of {@code csq}.
*/
public PrintStream append(CharSequence csq, int start, int end) {
- if (null == csq) {
- print(TOKEN_NULL.substring(start, end));
- } else {
- print(csq.subSequence(start, end).toString());
+ if (csq == null) {
+ csq = "null";
}
+ print(csq.subSequence(start, end).toString());
return this;
}
}
diff --git a/luni/src/main/java/java/io/PrintWriter.java b/luni/src/main/java/java/io/PrintWriter.java
index da54b48..3bc14b8 100644
--- a/luni/src/main/java/java/io/PrintWriter.java
+++ b/luni/src/main/java/java/io/PrintWriter.java
@@ -752,11 +752,10 @@ public class PrintWriter extends Writer {
*/
@Override
public PrintWriter append(CharSequence csq) {
- if (null == csq) {
- append(TOKEN_NULL, 0, TOKEN_NULL.length());
- } else {
- append(csq, 0, csq.length());
+ if (csq == null) {
+ csq = "null";
}
+ append(csq, 0, csq.length());
return this;
}
@@ -783,8 +782,8 @@ public class PrintWriter extends Writer {
*/
@Override
public PrintWriter append(CharSequence csq, int start, int end) {
- if (null == csq) {
- csq = TOKEN_NULL;
+ if (csq == null) {
+ csq = "null";
}
String output = csq.subSequence(start, end).toString();
write(output, 0, output.length());
diff --git a/luni/src/main/java/java/io/PushbackInputStream.java b/luni/src/main/java/java/io/PushbackInputStream.java
index 8ce7232..61ca2a7 100644
--- a/luni/src/main/java/java/io/PushbackInputStream.java
+++ b/luni/src/main/java/java/io/PushbackInputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Wraps an existing {@link InputStream} and adds functionality to "push back"
* bytes that have been read, so that they can be read again. Parsers may find
@@ -175,14 +177,7 @@ public class PushbackInputStream extends FilterInputStream {
if (buf == null) {
throw streamClosed();
}
- // Force buffer null check first!
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
-
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
int copiedBytes = 0, copyLength = 0, newOffset = offset;
// Are there pushback bytes available?
if (pos < buf.length) {
@@ -213,30 +208,28 @@ public class PushbackInputStream extends FilterInputStream {
}
/**
- * Skips {@code count} bytes in this stream. This implementation skips bytes
+ * Skips {@code byteCount} bytes in this stream. This implementation skips bytes
* in the pushback buffer first and then in the source stream if necessary.
*
- * @param count
- * the number of bytes to skip.
* @return the number of bytes actually skipped.
* @throws IOException
* if this stream is closed or another I/O error occurs.
*/
@Override
- public long skip(long count) throws IOException {
+ public long skip(long byteCount) throws IOException {
if (in == null) {
throw streamClosed();
}
- if (count <= 0) {
+ if (byteCount <= 0) {
return 0;
}
int numSkipped = 0;
if (pos < buf.length) {
- numSkipped += (count < buf.length - pos) ? count : buf.length - pos;
+ numSkipped += (byteCount < buf.length - pos) ? byteCount : buf.length - pos;
pos += numSkipped;
}
- if (numSkipped < count) {
- numSkipped += in.skip(count - numSkipped);
+ if (numSkipped < byteCount) {
+ numSkipped += in.skip(byteCount - numSkipped);
}
return numSkipped;
}
@@ -291,12 +284,7 @@ public class PushbackInputStream extends FilterInputStream {
if (length > pos) {
throw new IOException("Pushback buffer full");
}
- if (offset > buffer.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
if (buf == null) {
throw streamClosed();
}
diff --git a/luni/src/main/java/java/io/PushbackReader.java b/luni/src/main/java/java/io/PushbackReader.java
index b8de732..2e3cf83 100644
--- a/luni/src/main/java/java/io/PushbackReader.java
+++ b/luni/src/main/java/java/io/PushbackReader.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* Wraps an existing {@link Reader} and adds functionality to "push back"
* characters that have been read, so that they can be read again. Parsers may
@@ -181,19 +183,7 @@ public class PushbackReader extends FilterReader {
public int read(char[] buffer, int offset, int count) throws IOException {
synchronized (lock) {
checkNotClosed();
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | count) < 0 || offset > buffer.length - count) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
int copiedChars = 0;
int copyLength = 0;
@@ -317,14 +307,7 @@ public class PushbackReader extends FilterReader {
if (length > pos) {
throw new IOException("Pushback buffer full");
}
- // Force buffer null check first!
- if (offset > buffer.length - length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
-
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
for (int i = offset + length - 1; i >= offset; i--) {
unread(buffer[i]);
}
@@ -356,39 +339,37 @@ public class PushbackReader extends FilterReader {
}
/**
- * Skips {@code count} characters in this reader. This implementation skips
+ * Skips {@code charCount} characters in this reader. This implementation skips
* characters in the pushback buffer first and then in the source reader if
* necessary.
*
- * @param count
- * the number of characters to skip.
* @return the number of characters actually skipped.
- * @throws IllegalArgumentException if {@code count < 0}.
+ * @throws IllegalArgumentException if {@code charCount < 0}.
* @throws IOException
* if this reader is closed or another I/O error occurs.
*/
@Override
- public long skip(long count) throws IOException {
- if (count < 0) {
- throw new IllegalArgumentException();
+ public long skip(long charCount) throws IOException {
+ if (charCount < 0) {
+ throw new IllegalArgumentException("charCount < 0: " + charCount);
}
synchronized (lock) {
checkNotClosed();
- if (count == 0) {
+ if (charCount == 0) {
return 0;
}
long inSkipped;
int availableFromBuffer = buf.length - pos;
if (availableFromBuffer > 0) {
- long requiredFromIn = count - availableFromBuffer;
+ long requiredFromIn = charCount - availableFromBuffer;
if (requiredFromIn <= 0) {
- pos += count;
- return count;
+ pos += charCount;
+ return charCount;
}
pos += availableFromBuffer;
inSkipped = in.skip(requiredFromIn);
} else {
- inSkipped = in.skip(count);
+ inSkipped = in.skip(charCount);
}
return inSkipped + availableFromBuffer;
}
diff --git a/luni/src/main/java/java/io/RandomAccessFile.java b/luni/src/main/java/java/io/RandomAccessFile.java
index 615a755..b4a92a8 100644
--- a/luni/src/main/java/java/io/RandomAccessFile.java
+++ b/luni/src/main/java/java/io/RandomAccessFile.java
@@ -17,12 +17,18 @@
package java.io;
+import dalvik.system.CloseGuard;
+import java.nio.ByteOrder;
+import java.nio.NioUtils;
import java.nio.channels.FileChannel;
import java.nio.charset.ModifiedUtf8;
+import java.util.Arrays;
+import libcore.base.Streams;
import libcore.io.IoUtils;
+import libcore.io.SizeOf;
import org.apache.harmony.luni.platform.IFileSystem;
+import org.apache.harmony.luni.platform.OSMemory;
import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.nio.FileChannelFactory;
/**
* Allows reading from and writing to a file in a random-access manner. This is
@@ -44,13 +50,11 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
// initialized).
private FileChannel channel;
- private IFileSystem fileSystem = Platform.getFileSystem();
+ private int mode;
- private boolean isReadOnly;
+ private final CloseGuard guard = CloseGuard.get();
- // BEGIN android-added
- private int options;
- // END android-added
+ private final byte[] scratch = new byte[8];
/**
* Constructs a new {@code RandomAccessFile} based on {@code file} and opens
@@ -99,15 +103,13 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see java.lang.SecurityManager#checkWrite(FileDescriptor)
*/
public RandomAccessFile(File file, String mode) throws FileNotFoundException {
- options = 0;
+ int options;
fd = new FileDescriptor();
if (mode.equals("r")) {
- isReadOnly = true;
fd.readOnly = true;
options = IFileSystem.O_RDONLY;
} else if (mode.equals("rw") || mode.equals("rws") || mode.equals("rwd")) {
- isReadOnly = false;
options = IFileSystem.O_RDWR;
if (mode.equals("rws")) {
@@ -120,20 +122,17 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
} else {
throw new IllegalArgumentException("Invalid mode: " + mode);
}
+ this.mode = options;
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(file.getPath());
- if (!isReadOnly) {
+ if (!mode.equals("r")) {
security.checkWrite(file.getPath());
}
}
- fd.descriptor = fileSystem.open(file.getAbsolutePath(), options);
- // BEGIN android-removed
- // channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- // options);
- // END android-removed
+ fd.descriptor = Platform.FILE_SYSTEM.open(file.getAbsolutePath(), this.mode);
// if we are in "rws" mode, attempt to sync file+metadata
if (syncMetadata) {
@@ -143,6 +142,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
// Ignored
}
}
+ guard.open("close");
}
/**
@@ -168,8 +168,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see java.lang.SecurityManager#checkRead(FileDescriptor)
* @see java.lang.SecurityManager#checkWrite(FileDescriptor)
*/
- public RandomAccessFile(String fileName, String mode)
- throws FileNotFoundException {
+ public RandomAccessFile(String fileName, String mode) throws FileNotFoundException {
this(new File(fileName), mode);
}
@@ -180,6 +179,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* if an error occurs while closing this file.
*/
public void close() throws IOException {
+ guard.close();
synchronized (this) {
if (channel != null && channel.isOpen()) {
channel.close();
@@ -193,6 +193,9 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
@Override protected void finalize() throws Throwable {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
close();
} finally {
super.finalize();
@@ -210,12 +213,9 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @return this file's file channel instance.
*/
public final synchronized FileChannel getChannel() {
- // BEGIN android-added
if(channel == null) {
- channel = FileChannelFactory.getFileChannel(this, fd.descriptor,
- options);
+ channel = NioUtils.newFileChannel(this, fd.descriptor, mode);
}
- // END android-added
return channel;
}
@@ -244,7 +244,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
*/
public long getFilePointer() throws IOException {
openCheck();
- return fileSystem.seek(fd.descriptor, 0L, IFileSystem.SEEK_CUR);
+ return Platform.FILE_SYSTEM.seek(fd.descriptor, 0L, IFileSystem.SEEK_CUR);
}
/**
@@ -269,7 +269,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
*/
public long length() throws IOException {
openCheck();
- return fileSystem.length(fd.descriptor);
+ return Platform.FILE_SYSTEM.length(fd.descriptor);
}
/**
@@ -284,9 +284,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
*/
public int read() throws IOException {
openCheck();
- byte[] bytes = new byte[1];
- long byteCount = fileSystem.read(fd.descriptor, bytes, 0, 1);
- return byteCount == -1 ? -1 : bytes[0] & 0xff;
+ long byteCount = Platform.FILE_SYSTEM.read(fd.descriptor, scratch, 0, 1);
+ return byteCount == -1 ? -1 : scratch[0] & 0xff;
}
/**
@@ -328,24 +327,12 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* if this file is closed or another I/O error occurs.
*/
public int read(byte[] buffer, int offset, int count) throws IOException {
- // have to have four comparisons to not miss integer overflow cases
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to safe one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
- if (0 == count) {
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
+ if (count == 0) {
return 0;
}
openCheck();
- return (int) fileSystem.read(fd.descriptor, buffer, offset, count);
+ return (int) Platform.FILE_SYSTEM.read(fd.descriptor, buffer, offset, count);
}
/**
@@ -389,7 +376,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Reads a 16-bit character from the current position in this file. Blocks until
+ * Reads a big-endian 16-bit character from the current position in this file. Blocks until
* two bytes have been read, the end of the file is reached or an exception is
* thrown.
*
@@ -401,15 +388,11 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #writeChar(int)
*/
public final char readChar() throws IOException {
- byte[] buffer = new byte[2];
- if (read(buffer, 0, buffer.length) != buffer.length) {
- throw new EOFException();
- }
- return (char) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+ return (char) readShort();
}
/**
- * Reads a 64-bit double from the current position in this file. Blocks
+ * Reads a big-endian 64-bit double from the current position in this file. Blocks
* until eight bytes have been read, the end of the file is reached or an
* exception is thrown.
*
@@ -425,7 +408,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Reads a 32-bit float from the current position in this file. Blocks
+ * Reads a big-endian 32-bit float from the current position in this file. Blocks
* until four bytes have been read, the end of the file is reached or an
* exception is thrown.
*
@@ -441,71 +424,52 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Reads bytes from this file into {@code buffer}. Blocks until {@code
- * buffer.length} number of bytes have been read, the end of the file is
- * reached or an exception is thrown.
- *
- * @param buffer
- * the buffer to read bytes into.
- * @throws EOFException
- * if the end of this file is detected.
- * @throws IOException
- * if this file is closed or another I/O error occurs.
- * @throws NullPointerException
- * if {@code buffer} is {@code null}.
+ * Equivalent to {@code readFully(dst, 0, dst.length);}.
*/
- public final void readFully(byte[] buffer) throws IOException {
- readFully(buffer, 0, buffer.length);
+ public final void readFully(byte[] dst) throws IOException {
+ readFully(dst, 0, dst.length);
}
/**
- * Read bytes from this file into {@code buffer} starting at offset {@code
- * offset}. This method blocks until {@code count} number of bytes have been
- * read.
+ * Reads {@code byteCount} bytes from this stream and stores them in the byte
+ * array {@code dst} starting at {@code offset}. If {@code byteCount} is zero, then this
+ * method returns without reading any bytes. Otherwise, this method blocks until
+ * {@code byteCount} bytes have been read. If insufficient bytes are available,
+ * {@code EOFException} is thrown. If an I/O error occurs, {@code IOException} is
+ * thrown. When an exception is thrown, some bytes may have been consumed from the stream
+ * and written into the array.
*
- * @param buffer
- * the buffer to read bytes into.
+ * @param dst
+ * the byte array into which the data is read.
* @param offset
- * the initial position in {@code buffer} to store the bytes read
- * from this file.
- * @param count
- * the maximum number of bytes to store in {@code buffer}.
+ * the offset in {@code dst} at which to store the bytes.
+ * @param byteCount
+ * the number of bytes to read.
* @throws EOFException
- * if the end of this file is detected.
+ * if the end of the source stream is reached before enough
+ * bytes have been read.
* @throws IndexOutOfBoundsException
- * if {@code offset < 0} or {@code count < 0}, or if {@code
- * offset + count} is greater than the length of {@code buffer}.
+ * if {@code offset < 0} or {@code byteCount < 0}, or
+ * {@code offset + byteCount > dst.length}.
* @throws IOException
- * if this file is closed or another I/O error occurs.
+ * if a problem occurs while reading from this stream.
* @throws NullPointerException
- * if {@code buffer} is {@code null}.
+ * if {@code dst} is null.
*/
- public final void readFully(byte[] buffer, int offset, int count) throws IOException {
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to safe one operation
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
- while (count > 0) {
- int result = read(buffer, offset, count);
+ public final void readFully(byte[] dst, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(dst.length, offset, byteCount);
+ while (byteCount > 0) {
+ int result = read(dst, offset, byteCount);
if (result < 0) {
throw new EOFException();
}
offset += result;
- count -= result;
+ byteCount -= result;
}
}
/**
- * Reads a 32-bit integer from the current position in this file. Blocks
+ * Reads a big-endian 32-bit integer from the current position in this file. Blocks
* until four bytes have been read, the end of the file is reached or an
* exception is thrown.
*
@@ -517,12 +481,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #writeInt(int)
*/
public final int readInt() throws IOException {
- byte[] buffer = new byte[4];
- if (read(buffer, 0, buffer.length) != buffer.length) {
- throw new EOFException();
- }
- return ((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
- + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff);
+ readFully(scratch, 0, SizeOf.INT);
+ return OSMemory.peekInt(scratch, 0, ByteOrder.BIG_ENDIAN);
}
/**
@@ -570,7 +530,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Reads a 64-bit long from the current position in this file. Blocks until
+ * Reads a big-endian 64-bit long from the current position in this file. Blocks until
* eight bytes have been read, the end of the file is reached or an
* exception is thrown.
*
@@ -582,20 +542,12 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #writeLong(long)
*/
public final long readLong() throws IOException {
- byte[] buffer = new byte[8];
- if (read(buffer, 0, buffer.length) != buffer.length) {
- throw new EOFException();
- }
- return ((long) (((buffer[0] & 0xff) << 24) + ((buffer[1] & 0xff) << 16)
- + ((buffer[2] & 0xff) << 8) + (buffer[3] & 0xff)) << 32)
- + ((long) (buffer[4] & 0xff) << 24)
- + ((buffer[5] & 0xff) << 16)
- + ((buffer[6] & 0xff) << 8)
- + (buffer[7] & 0xff);
+ readFully(scratch, 0, SizeOf.LONG);
+ return OSMemory.peekLong(scratch, 0, ByteOrder.BIG_ENDIAN);
}
/**
- * Reads a 16-bit short from the current position in this file. Blocks until
+ * Reads a big-endian 16-bit short from the current position in this file. Blocks until
* two bytes have been read, the end of the file is reached or an exception
* is thrown.
*
@@ -607,11 +559,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #writeShort(int)
*/
public final short readShort() throws IOException {
- byte[] buffer = new byte[2];
- if (read(buffer, 0, buffer.length) != buffer.length) {
- throw new EOFException();
- }
- return (short) (((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff));
+ readFully(scratch, 0, SizeOf.SHORT);
+ return OSMemory.peekShort(scratch, 0, ByteOrder.BIG_ENDIAN);
}
/**
@@ -635,7 +584,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Reads an unsigned 16-bit short from the current position in this file and
+ * Reads an unsigned big-endian 16-bit short from the current position in this file and
* returns it as an integer. Blocks until two bytes have been read, the end of
* the file is reached or an exception is thrown.
*
@@ -647,11 +596,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #writeShort(int)
*/
public final int readUnsignedShort() throws IOException {
- byte[] buffer = new byte[2];
- if (read(buffer, 0, buffer.length) != buffer.length) {
- throw new EOFException();
- }
- return ((buffer[0] & 0xff) << 8) + (buffer[1] & 0xff);
+ return ((int) readShort()) & 0xffff;
}
/**
@@ -699,10 +644,10 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
public void seek(long offset) throws IOException {
if (offset < 0) {
// seek position is negative
- throw new IOException("offset < 0");
+ throw new IOException("offset < 0: " + offset);
}
openCheck();
- fileSystem.seek(fd.descriptor, offset, IFileSystem.SEEK_SET);
+ Platform.FILE_SYSTEM.seek(fd.descriptor, offset, IFileSystem.SEEK_SET);
}
/**
@@ -722,9 +667,14 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
public void setLength(long newLength) throws IOException {
openCheck();
if (newLength < 0) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("newLength < 0");
+ }
+ Platform.FILE_SYSTEM.truncate(fd.descriptor, newLength);
+
+ long filePointer = getFilePointer();
+ if (filePointer > newLength) {
+ seek(newLength);
}
- fileSystem.truncate(fd.descriptor, newLength);
// if we are in "rws" mode, attempt to sync file+metadata
if (syncMetadata) {
@@ -747,8 +697,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
public int skipBytes(int count) throws IOException {
if (count > 0) {
long currentPos = getFilePointer(), eof = length();
- int newCount = (int) ((currentPos + count > eof) ? eof - currentPos
- : count);
+ int newCount = (int) ((currentPos + count > eof) ? eof - currentPos : count);
seek(currentPos + newCount);
return newCount;
}
@@ -763,10 +712,6 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* the buffer to write.
* @throws IOException
* if an I/O error occurs while writing to this file.
- * @see #read(byte[])
- * @see #read(byte[],int,int)
- * @see #readFully(byte[])
- * @see #readFully(byte[],int,int)
*/
public void write(byte[] buffer) throws IOException {
write(buffer, 0, buffer.length);
@@ -788,28 +733,14 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* offset} is greater than the size of {@code buffer}.
* @throws IOException
* if an I/O error occurs while writing to this file.
- * @see #read(byte[], int, int)
- * @see #readFully(byte[], int, int)
*/
public void write(byte[] buffer, int offset, int count) throws IOException {
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // made implicit null check explicit,
- // removed redundant check, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to save one operation
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if ((offset | count) < 0 || count > buffer.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
if (count == 0) {
return;
}
openCheck();
- fileSystem.write(fd.descriptor, buffer, offset, count);
+ Platform.FILE_SYSTEM.write(fd.descriptor, buffer, offset, count);
// if we are in "rws" mode, attempt to sync file+metadata
if (syncMetadata) {
@@ -829,9 +760,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
*/
public void write(int oneByte) throws IOException {
openCheck();
- byte[] bytes = new byte[1];
- bytes[0] = (byte) (oneByte & 0xff);
- fileSystem.write(fd.descriptor, bytes, 0, 1);
+ scratch[0] = (byte) (oneByte & 0xff);
+ Platform.FILE_SYSTEM.write(fd.descriptor, scratch, 0, 1);
// if we are in "rws" mode, attempt to sync file+metadata
if (syncMetadata) {
@@ -840,7 +770,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Writes a boolean to this file, starting at the current file pointer.
+ * Writes a boolean to this file as a single byte (1 for true, 0 for false), starting at the
+ * current file pointer.
*
* @param val
* the boolean to write to this file.
@@ -875,10 +806,6 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* the string containing the bytes to write to this file
* @throws IOException
* if an I/O error occurs while writing to this file.
- * @see #read(byte[])
- * @see #read(byte[],int,int)
- * @see #readFully(byte[])
- * @see #readFully(byte[],int,int)
*/
public final void writeBytes(String str) throws IOException {
byte[] bytes = new byte[str.length()];
@@ -889,7 +816,7 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Writes a 16-bit character to this file, starting at the current file
+ * Writes a big-endian 16-bit character to this file, starting at the current file
* pointer. Only the two least significant bytes of the integer {@code val}
* are written, with the high byte first.
*
@@ -900,16 +827,12 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #readChar()
*/
public final void writeChar(int val) throws IOException {
- byte[] buffer = new byte[2];
- buffer[0] = (byte) (val >> 8);
- buffer[1] = (byte) val;
- write(buffer, 0, buffer.length);
+ writeShort(val);
}
/**
- * Writes the 16-bit characters from a string to this file, starting at the
- * current file pointer. Each character is written in the same way as with
- * {@link #writeChar(int)}, with its high byte first.
+ * Writes big-endian 16-bit characters from {@code str} to this file, starting at the
+ * current file pointer.
*
* @param str
* the string to write to this file.
@@ -918,19 +841,13 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #readChar()
*/
public final void writeChars(String str) throws IOException {
- byte[] newBytes = new byte[str.length() * 2];
- for (int index = 0; index < str.length(); index++) {
- int newIndex = index == 0 ? index : index * 2;
- newBytes[newIndex] = (byte) ((str.charAt(index) >> 8) & 0xFF);
- newBytes[newIndex + 1] = (byte) (str.charAt(index) & 0xFF);
- }
- write(newBytes);
+ write(str.getBytes("UTF-16BE"));
}
/**
- * Writes a 64-bit double to this file, starting at the current file
- * pointer. The eight bytes returned by
- * {@link Double#doubleToLongBits(double)} are written to this file.
+ * Writes a big-endian 64-bit double to this file, starting at the current file
+ * pointer. The bytes are those returned by
+ * {@link Double#doubleToLongBits(double)}, meaning a canonical NaN is used.
*
* @param val
* the double to write to this file.
@@ -943,9 +860,9 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Writes a 32-bit float to this file, starting at the current file pointer.
- * The four bytes returned by {@link Float#floatToIntBits(float)} are
- * written to this file.
+ * Writes a big-endian 32-bit float to this file, starting at the current file pointer.
+ * The bytes are those returned by {@link Float#floatToIntBits(float)}, meaning a canonical NaN
+ * is used.
*
* @param val
* the float to write to this file.
@@ -958,9 +875,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
}
/**
- * Writes a 32-bit integer to this file, starting at the current file
- * pointer. The four bytes of the integer are written with the highest byte
- * first.
+ * Writes a big-endian 32-bit integer to this file, starting at the current file
+ * pointer.
*
* @param val
* the int to write to this file.
@@ -969,18 +885,13 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #readInt()
*/
public final void writeInt(int val) throws IOException {
- byte[] buffer = new byte[4];
- buffer[0] = (byte) (val >> 24);
- buffer[1] = (byte) (val >> 16);
- buffer[2] = (byte) (val >> 8);
- buffer[3] = (byte) val;
- write(buffer, 0, buffer.length);
+ OSMemory.pokeInt(scratch, 0, val, ByteOrder.BIG_ENDIAN);
+ write(scratch, 0, SizeOf.INT);
}
/**
- * Writes a 64-bit long to this file, starting at the current file
- * pointer. The eight bytes of the long are written with the highest byte
- * first.
+ * Writes a big-endian 64-bit long to this file, starting at the current file
+ * pointer.
*
* @param val
* the long to write to this file.
@@ -989,23 +900,14 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #readLong()
*/
public final void writeLong(long val) throws IOException {
- byte[] buffer = new byte[8];
- int t = (int) (val >> 32);
- buffer[0] = (byte) (t >> 24);
- buffer[1] = (byte) (t >> 16);
- buffer[2] = (byte) (t >> 8);
- buffer[3] = (byte) t;
- buffer[4] = (byte) (val >> 24);
- buffer[5] = (byte) (val >> 16);
- buffer[6] = (byte) (val >> 8);
- buffer[7] = (byte) val;
- write(buffer, 0, buffer.length);
+ OSMemory.pokeLong(scratch, 0, val, ByteOrder.BIG_ENDIAN);
+ write(scratch, 0, SizeOf.LONG);
}
/**
- * Writes a 16-bit short to this file, starting at the current file
+ * Writes a big-endian 16-bit short to this file, starting at the current file
* pointer. Only the two least significant bytes of the integer {@code val}
- * are written, with the high byte first.
+ * are written.
*
* @param val
* the short to write to this file.
@@ -1015,7 +917,8 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see DataInput#readUnsignedShort()
*/
public final void writeShort(int val) throws IOException {
- writeChar(val);
+ OSMemory.pokeShort(scratch, 0, (short) val, ByteOrder.BIG_ENDIAN);
+ write(scratch, 0, SizeOf.SHORT);
}
/**
@@ -1032,37 +935,6 @@ public class RandomAccessFile implements DataInput, DataOutput, Closeable {
* @see #readUTF()
*/
public final void writeUTF(String str) throws IOException {
- int utfCount = 0, length = str.length();
- for (int i = 0; i < length; i++) {
- int charValue = str.charAt(i);
- if (charValue > 0 && charValue <= 127) {
- utfCount++;
- } else if (charValue <= 2047) {
- utfCount += 2;
- } else {
- utfCount += 3;
- }
- }
- if (utfCount > 65535) {
- throw new UTFDataFormatException("String more than 65535 UTF bytes long");
- }
- byte[] utfBytes = new byte[utfCount + 2];
- int utfIndex = 2;
- for (int i = 0; i < length; i++) {
- int charValue = str.charAt(i);
- if (charValue > 0 && charValue <= 127) {
- utfBytes[utfIndex++] = (byte) charValue;
- } else if (charValue <= 2047) {
- utfBytes[utfIndex++] = (byte) (0xc0 | (0x1f & (charValue >> 6)));
- utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
- } else {
- utfBytes[utfIndex++] = (byte) (0xe0 | (0x0f & (charValue >> 12)));
- utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & (charValue >> 6)));
- utfBytes[utfIndex++] = (byte) (0x80 | (0x3f & charValue));
- }
- }
- utfBytes[0] = (byte) (utfCount >> 8);
- utfBytes[1] = (byte) utfCount;
- write(utfBytes);
+ write(ModifiedUtf8.encode(str));
}
}
diff --git a/luni/src/main/java/java/io/Reader.java b/luni/src/main/java/java/io/Reader.java
index 4c4ce06..82f3ac5 100644
--- a/luni/src/main/java/java/io/Reader.java
+++ b/luni/src/main/java/java/io/Reader.java
@@ -207,31 +207,29 @@ public abstract class Reader implements Readable, Closeable {
}
/**
- * Skips {@code amount} characters in this reader. Subsequent calls of
+ * Skips {@code charCount} characters in this reader. Subsequent calls of
* {@code read} methods will not return these characters unless {@code
- * reset()} is used. This method may perform multiple reads to read {@code
- * count} characters.
+ * reset} is used. This method may perform multiple reads to read {@code
+ * charCount} characters.
*
- * @param count
- * the maximum number of characters to skip.
* @return the number of characters actually skipped.
* @throws IllegalArgumentException
- * if {@code amount < 0}.
+ * if {@code charCount < 0}.
* @throws IOException
* if this reader is closed or some other I/O error occurs.
* @see #mark(int)
* @see #markSupported()
* @see #reset()
*/
- public long skip(long count) throws IOException {
- if (count < 0) {
- throw new IllegalArgumentException();
+ public long skip(long charCount) throws IOException {
+ if (charCount < 0) {
+ throw new IllegalArgumentException("charCount < 0: " + charCount);
}
synchronized (lock) {
long skipped = 0;
- int toRead = count < 512 ? (int) count : 512;
+ int toRead = charCount < 512 ? (int) charCount : 512;
char[] charsSkipped = new char[toRead];
- while (skipped < count) {
+ while (skipped < charCount) {
int read = read(charsSkipped, 0, toRead);
if (read == -1) {
return skipped;
@@ -240,8 +238,8 @@ public abstract class Reader implements Readable, Closeable {
if (read < toRead) {
return skipped;
}
- if (count - skipped < toRead) {
- toRead = (int) (count - skipped);
+ if (charCount - skipped < toRead) {
+ toRead = (int) (charCount - skipped);
}
}
return skipped;
@@ -263,9 +261,6 @@ public abstract class Reader implements Readable, Closeable {
* if {@code target} is read-only.
*/
public int read(CharBuffer target) throws IOException {
- if (null == target) {
- throw new NullPointerException();
- }
int length = target.length();
char[] buf = new char[length];
length = Math.min(length, read(buf));
diff --git a/luni/src/main/java/java/io/SequenceInputStream.java b/luni/src/main/java/java/io/SequenceInputStream.java
index 1ce6cee..9ae1901 100644
--- a/luni/src/main/java/java/io/SequenceInputStream.java
+++ b/luni/src/main/java/java/io/SequenceInputStream.java
@@ -17,6 +17,7 @@
package java.io;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;
@@ -184,19 +185,7 @@ public class SequenceInputStream extends InputStream {
if (in == null) {
return -1;
}
- // BEGIN android-changed
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- // avoid int overflow
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // used (offset | count) < 0 instead of (offset < 0) || (count < 0)
- // to safe one operation
- if ((offset | count) < 0 || offset > buffer.length - count) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
while (in != null) {
int result = in.read(buffer, offset, count);
if (result >= 0) {
diff --git a/luni/src/main/java/java/io/SerializationHandleMap.java b/luni/src/main/java/java/io/SerializationHandleMap.java
new file mode 100644
index 0000000..8630b82
--- /dev/null
+++ b/luni/src/main/java/java/io/SerializationHandleMap.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.io;
+
+/**
+ * A specialization of IdentityHashMap<Object, int> for use when serializing objects.
+ * We need to assign each object we write an int 'handle' (densely packed but not starting
+ * at zero), and use the same handle any time we write the same object again.
+ */
+final class SerializationHandleMap {
+ /* Default load factor of 0.75; */
+ private static final int LOAD_FACTOR = 7500;
+
+ private Object[] keys;
+ private int[] values;
+
+ /* Actual number of key-value pairs. */
+ private int size;
+
+ /* Maximum number of elements that can be put in this map before having to rehash. */
+ private int threshold;
+
+ public SerializationHandleMap() {
+ this.size = 0;
+ this.threshold = 21; // Copied from IdentityHashMap.
+ int arraySize = (int) (((long) threshold * 10000) / LOAD_FACTOR);
+ resizeArrays(arraySize);
+ }
+
+ private void resizeArrays(int newSize) {
+ Object[] oldKeys = keys;
+ int[] oldValues = values;
+
+ this.keys = new Object[newSize];
+ this.values = new int[newSize];
+
+ if (oldKeys != null) {
+ for (int i = 0; i < oldKeys.length; ++i) {
+ Object key = oldKeys[i];
+ int value = oldValues[i];
+ int index = findIndex(key, keys);
+ keys[index] = key;
+ values[index] = value;
+ }
+ }
+ }
+
+ public int get(Object key) {
+ int index = findIndex(key, keys);
+ if (keys[index] == key) {
+ return values[index];
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the index where the key is found at, or the index of the next
+ * empty spot if the key is not found in this table.
+ */
+ private int findIndex(Object key, Object[] array) {
+ int length = array.length;
+ int index = getModuloHash(key, length);
+ int last = (index + length - 1) % length;
+ while (index != last) {
+ if (array[index] == key || array[index] == null) {
+ /*
+ * Found the key, or the next empty spot (which means key is not
+ * in the table)
+ */
+ break;
+ }
+ index = (index + 1) % length;
+ }
+ return index;
+ }
+
+ private int getModuloHash(Object key, int length) {
+ return (System.identityHashCode(key) & 0x7FFFFFFF) % length;
+ }
+
+ public int put(Object key, int value) {
+ Object _key = key;
+ int _value = value;
+
+ int index = findIndex(_key, keys);
+
+ // if the key doesn't exist in the table
+ if (keys[index] != _key) {
+ if (++size > threshold) {
+ rehash();
+ index = findIndex(_key, keys);
+ }
+ // insert the key and assign the value to -1 initially
+ keys[index] = _key;
+ values[index] = -1;
+ }
+
+ // insert value to where it needs to go, return the old value
+ int result = values[index];
+ values[index] = _value;
+ return result;
+ }
+
+ private void rehash() {
+ int newSize = keys.length * 2;
+ resizeArrays(newSize);
+ threshold = (int) ((long) (keys.length) * LOAD_FACTOR / 10000);
+ }
+
+ public int remove(Object key) {
+ boolean hashedOk;
+ int index, next, hash;
+ int result;
+ Object object;
+ index = next = findIndex(key, keys);
+
+ if (keys[index] != key) {
+ return -1;
+ }
+
+ // store the value for this key
+ result = values[index];
+
+ // shift the following elements up if needed
+ // until we reach an empty spot
+ int length = keys.length;
+ while (true) {
+ next = (next + 2) % length;
+ object = keys[next];
+ if (object == null) {
+ break;
+ }
+
+ hash = getModuloHash(object, length);
+ hashedOk = hash > index;
+ if (next < index) {
+ hashedOk = hashedOk || (hash <= next);
+ } else {
+ hashedOk = hashedOk && (hash <= next);
+ }
+ if (!hashedOk) {
+ keys[index] = object;
+ values[index] = values[next];
+ index = next;
+ }
+ }
+ size--;
+
+ // clear both the key and the value
+ keys[index] = null;
+ values[index] = -1;
+
+ return result;
+ }
+
+ public boolean isEmpty() {
+ return size == 0;
+ }
+}
diff --git a/luni/src/main/java/java/io/StreamTokenizer.java b/luni/src/main/java/java/io/StreamTokenizer.java
index c740a7c..36c42bf 100644
--- a/luni/src/main/java/java/io/StreamTokenizer.java
+++ b/luni/src/main/java/java/io/StreamTokenizer.java
@@ -205,7 +205,7 @@ public class StreamTokenizer {
* the character to be considered a comment character.
*/
public void commentChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length) {
+ if (ch >= 0 && ch < tokenTypes.length) {
tokenTypes[ch] = TOKEN_COMMENT;
}
}
@@ -486,7 +486,7 @@ public class StreamTokenizer {
* the character to be considered an ordinary character.
*/
public void ordinaryChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length) {
+ if (ch >= 0 && ch < tokenTypes.length) {
tokenTypes[ch] = 0;
}
}
@@ -541,7 +541,7 @@ public class StreamTokenizer {
* the character to be considered a quote character.
*/
public void quoteChar(int ch) {
- if (0 <= ch && ch < tokenTypes.length) {
+ if (ch >= 0 && ch < tokenTypes.length) {
tokenTypes[ch] = TOKEN_QUOTE;
}
}
diff --git a/luni/src/main/java/java/io/StringBufferInputStream.java b/luni/src/main/java/java/io/StringBufferInputStream.java
index 26482a2..1fada57 100644
--- a/luni/src/main/java/java/io/StringBufferInputStream.java
+++ b/luni/src/main/java/java/io/StringBufferInputStream.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link InputStream} that reads bytes from a {@code String} in
* a sequential manner.
@@ -98,25 +100,10 @@ public class StringBufferInputStream extends InputStream {
*/
@Override
public synchronized int read(byte[] buffer, int offset, int length) {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
- // According to 22.7.6 should return -1 before checking other
- // parameters.
- if (pos >= count) {
- return -1;
- }
if (buffer == null) {
throw new NullPointerException("buffer == null");
}
- // avoid int overflow
- if (offset < 0 || offset > buffer.length) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || length > buffer.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
-
+ Arrays.checkOffsetAndCount(buffer.length, offset, length);
if (length == 0) {
return 0;
}
@@ -138,28 +125,26 @@ public class StringBufferInputStream extends InputStream {
}
/**
- * Skips {@code n} characters in the source string. It does nothing and
- * returns 0 if {@code n} is negative. Less than {@code n} characters are
+ * Skips {@code charCount} characters in the source string. It does nothing and
+ * returns 0 if {@code charCount} is negative. Less than {@code charCount} characters are
* skipped if the end of the source string is reached before the operation
* completes.
*
- * @param n
- * the number of characters to skip.
* @return the number of characters actually skipped.
*/
@Override
- public synchronized long skip(long n) {
- if (n <= 0) {
+ public synchronized long skip(long charCount) {
+ if (charCount <= 0) {
return 0;
}
int numskipped;
- if (this.count - pos < n) {
+ if (this.count - pos < charCount) {
numskipped = this.count - pos;
pos = this.count;
} else {
- numskipped = (int) n;
- pos += n;
+ numskipped = (int) charCount;
+ pos += charCount;
}
return numskipped;
}
diff --git a/luni/src/main/java/java/io/StringReader.java b/luni/src/main/java/java/io/StringReader.java
index 4736156..635686e 100644
--- a/luni/src/main/java/java/io/StringReader.java
+++ b/luni/src/main/java/java/io/StringReader.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link Reader} that reads characters from a {@code String} in
* a sequential manner.
@@ -152,17 +154,9 @@ public class StringReader extends Reader {
*/
@Override
public int read(char[] buf, int offset, int len) throws IOException {
- // BEGIN android-note
- // changed array notation to be consistent with the rest of harmony
- // END android-note
synchronized (lock) {
checkNotClosed();
- if (offset < 0 || offset > buf.length) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (len < 0 || len > buf.length - offset) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + len);
- }
+ Arrays.checkOffsetAndCount(buf.length, offset, len);
if (len == 0) {
return 0;
}
@@ -215,13 +209,13 @@ public class StringReader extends Reader {
}
/**
- * Moves {@code ns} characters in the source string. Unlike the {@link
+ * Moves {@code charCount} characters in the source string. Unlike the {@link
* Reader#skip(long) overridden method}, this method may skip negative skip
* distances: this rewinds the input so that characters may be read again.
* When the end of the source string has been reached, the input cannot be
* rewound.
*
- * @param ns
+ * @param charCount
* the maximum number of characters to skip. Positive values skip
* forward; negative values skip backward.
* @return the number of characters actually skipped. This is bounded below
@@ -235,21 +229,21 @@ public class StringReader extends Reader {
* @see #reset()
*/
@Override
- public long skip(long ns) throws IOException {
+ public long skip(long charCount) throws IOException {
synchronized (lock) {
checkNotClosed();
int minSkip = -pos;
int maxSkip = count - pos;
- if (maxSkip == 0 || ns > maxSkip) {
- ns = maxSkip; // no rewinding if we're at the end
- } else if (ns < minSkip) {
- ns = minSkip;
+ if (maxSkip == 0 || charCount > maxSkip) {
+ charCount = maxSkip; // no rewinding if we're at the end
+ } else if (charCount < minSkip) {
+ charCount = minSkip;
}
- pos += ns;
- return ns;
+ pos += charCount;
+ return charCount;
}
}
}
diff --git a/luni/src/main/java/java/io/StringWriter.java b/luni/src/main/java/java/io/StringWriter.java
index 6fb0dda..7a74eea 100644
--- a/luni/src/main/java/java/io/StringWriter.java
+++ b/luni/src/main/java/java/io/StringWriter.java
@@ -17,6 +17,8 @@
package java.io;
+import java.util.Arrays;
+
/**
* A specialized {@link Writer} that writes characters to a {@code StringBuffer}
* in a sequential manner, appending them in the process. The result can later
@@ -115,19 +117,7 @@ public class StringWriter extends Writer {
*/
@Override
public void write(char[] chars, int offset, int count) {
- // avoid int overflow
- // BEGIN android-changed
- // Exception priorities (in case of multiple errors) differ from
- // RI, but are spec-compliant.
- // removed redundant check, added null check, used (offset | count) < 0
- // instead of (offset < 0) || (count < 0) to safe one operation
- if (chars == null) {
- throw new NullPointerException("chars == null");
- }
- if ((offset | count) < 0 || count > chars.length - offset) {
- throw new IndexOutOfBoundsException();
- }
- // END android-changed
+ Arrays.checkOffsetAndCount(chars.length, offset, count);
if (count == 0) {
return;
}
@@ -204,11 +194,10 @@ public class StringWriter extends Writer {
*/
@Override
public StringWriter append(CharSequence csq) {
- if (null == csq) {
- write(TOKEN_NULL);
- } else {
- write(csq.toString());
+ if (csq == null) {
+ csq = "null";
}
+ write(csq.toString());
return this;
}
@@ -235,8 +224,8 @@ public class StringWriter extends Writer {
*/
@Override
public StringWriter append(CharSequence csq, int start, int end) {
- if (null == csq) {
- csq = TOKEN_NULL;
+ if (csq == null) {
+ csq = "null";
}
String output = csq.subSequence(start, end).toString();
write(output, 0, output.length());
diff --git a/luni/src/main/java/java/io/Writer.java b/luni/src/main/java/java/io/Writer.java
index ca909f3..d1ff429 100644
--- a/luni/src/main/java/java/io/Writer.java
+++ b/luni/src/main/java/java/io/Writer.java
@@ -35,9 +35,6 @@ package java.io;
* @see Reader
*/
public abstract class Writer implements Appendable, Closeable, Flushable {
-
- static final String TOKEN_NULL = "null";
-
/**
* The object used to synchronize access to the writer.
*/
@@ -169,12 +166,11 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
* offset + count} is greater than the length of {@code str}.
*/
public void write(String str, int offset, int count) throws IOException {
- if (count < 0) { // other cases tested by getChars()
- throw new StringIndexOutOfBoundsException();
+ if ((offset | count) < 0 || offset > str.length() - count) {
+ throw new StringIndexOutOfBoundsException(str, offset, count);
}
char[] buf = new char[count];
str.getChars(offset, offset + count, buf, 0);
-
synchronized (lock) {
write(buf, 0, buf.length);
}
@@ -208,11 +204,10 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
* if this writer is closed or another I/O error occurs.
*/
public Writer append(CharSequence csq) throws IOException {
- if (null == csq) {
- write(TOKEN_NULL);
- } else {
- write(csq.toString());
+ if (csq == null) {
+ csq = "null";
}
+ write(csq.toString());
return this;
}
@@ -239,13 +234,11 @@ public abstract class Writer implements Appendable, Closeable, Flushable {
* either {@code start} or {@code end} are greater or equal than
* the length of {@code csq}.
*/
- public Writer append(CharSequence csq, int start, int end)
- throws IOException {
- if (null == csq) {
- write(TOKEN_NULL.substring(start, end));
- } else {
- write(csq.subSequence(start, end).toString());
+ public Writer append(CharSequence csq, int start, int end) throws IOException {
+ if (csq == null) {
+ csq = "null";
}
+ write(csq.subSequence(start, end).toString());
return this;
}
diff --git a/luni/src/main/java/java/lang/AbstractStringBuilder.java b/luni/src/main/java/java/lang/AbstractStringBuilder.java
index ebea88c..5fe059f 100644
--- a/luni/src/main/java/java/lang/AbstractStringBuilder.java
+++ b/luni/src/main/java/java/lang/AbstractStringBuilder.java
@@ -19,6 +19,7 @@ package java.lang;
import java.io.InvalidObjectException;
import java.util.Arrays;
+import libcore.base.EmptyArray;
/**
* A modifiable {@link CharSequence sequence of characters} for use in creating
@@ -59,7 +60,7 @@ abstract class AbstractStringBuilder {
*/
final void set(char[] val, int len) throws InvalidObjectException {
if (val == null) {
- val = new char[0];
+ val = EmptyArray.CHAR;
}
if (val.length < len) {
throw new InvalidObjectException("count out of range");
@@ -119,14 +120,7 @@ abstract class AbstractStringBuilder {
}
final void append0(char[] chars, int offset, int length) {
- // Force null check of chars first!
- if (offset > chars.length || offset < 0) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (length < 0 || chars.length - offset < length) {
- throw new ArrayIndexOutOfBoundsException("Length out of bounds: " + length);
- }
-
+ Arrays.checkOffsetAndCount(chars.length, offset, length);
int newCount = count + length;
if (newCount > value.length) {
enlargeBuffer(newCount);
@@ -160,7 +154,7 @@ abstract class AbstractStringBuilder {
if (s == null) {
s = "null";
}
- if (start < 0 || end < 0 || start > end || end > s.length()) {
+ if ((start | end) < 0 || start > end || end > s.length()) {
throw new IndexOutOfBoundsException();
}
@@ -211,11 +205,19 @@ abstract class AbstractStringBuilder {
*/
public char charAt(int index) {
if (index < 0 || index >= count) {
- throw new StringIndexOutOfBoundsException(index);
+ throw indexAndLength(index);
}
return value[index];
}
+ private StringIndexOutOfBoundsException indexAndLength(int index) {
+ throw new StringIndexOutOfBoundsException("index=" + index + " length=" + count);
+ }
+
+ private StringIndexOutOfBoundsException startEndAndLength(int start, int end) {
+ throw new StringIndexOutOfBoundsException("start=" + start + " end=" + end + " length=" + count);
+ }
+
final void delete0(int start, int end) {
if (start >= 0) {
if (end > count) {
@@ -241,23 +243,21 @@ abstract class AbstractStringBuilder {
return;
}
}
- throw new StringIndexOutOfBoundsException();
+ throw startEndAndLength(start, end);
}
- final void deleteCharAt0(int location) {
- if (0 > location || location >= count) {
- throw new StringIndexOutOfBoundsException(location);
+ final void deleteCharAt0(int index) {
+ if (index < 0 || index >= count) {
+ throw indexAndLength(index);
}
- int length = count - location - 1;
+ int length = count - index - 1;
if (length > 0) {
if (!shared) {
- System.arraycopy(value, location + 1, value, location, length);
+ System.arraycopy(value, index + 1, value, index, length);
} else {
char[] newData = new char[value.length];
- System.arraycopy(value, 0, newData, 0, location);
- System
- .arraycopy(value, location + 1, newData, location,
- length);
+ System.arraycopy(value, 0, newData, 0, index);
+ System.arraycopy(value, index + 1, newData, index, length);
value = newData;
shared = false;
}
@@ -279,8 +279,8 @@ abstract class AbstractStringBuilder {
*/
public void ensureCapacity(int min) {
if (min > value.length) {
- int twice = (value.length << 1) + 2;
- enlargeBuffer(twice > min ? twice : min);
+ int ourMin = value.length*2 + 2;
+ enlargeBuffer(Math.max(ourMin, min));
}
}
@@ -305,14 +305,14 @@ abstract class AbstractStringBuilder {
*/
public void getChars(int start, int end, char[] dst, int dstStart) {
if (start > count || end > count || start > end) {
- throw new StringIndexOutOfBoundsException();
+ throw startEndAndLength(start, end);
}
System.arraycopy(value, start, dst, dstStart, end - start);
}
final void insert0(int index, char[] chars) {
- if (0 > index || index > count) {
- throw new StringIndexOutOfBoundsException(index);
+ if (index < 0 || index > count) {
+ throw indexAndLength(index);
}
if (chars.length != 0) {
move(chars.length, index);
@@ -322,9 +322,9 @@ abstract class AbstractStringBuilder {
}
final void insert0(int index, char[] chars, int start, int length) {
- if (0 <= index && index <= count) {
+ if (index >= 0 && index <= count) {
// start + length could overflow, start/length maybe MaxInt
- if (start >= 0 && 0 <= length && length <= chars.length - start) {
+ if (start >= 0 && length >= 0 && length <= chars.length - start) {
if (length != 0) {
move(length, index);
System.arraycopy(chars, start, value, index, length);
@@ -332,17 +332,15 @@ abstract class AbstractStringBuilder {
}
return;
}
- throw new StringIndexOutOfBoundsException("offset " + start
- + ", length " + length
- + ", char[].length " + chars.length);
}
- throw new StringIndexOutOfBoundsException(index);
+ throw new StringIndexOutOfBoundsException("index=" + index + " chars.length=" + chars.length
+ + " start=" + start + " length=" + length + " this.length=" + count);
}
final void insert0(int index, char ch) {
- if (0 > index || index > count) {
+ if (index < 0 || index > count) {
// RI compatible exception type
- throw new ArrayIndexOutOfBoundsException(index);
+ throw new ArrayIndexOutOfBoundsException("index=" + index + ", length=" + count);
}
move(1, index);
value[index] = ch;
@@ -350,7 +348,7 @@ abstract class AbstractStringBuilder {
}
final void insert0(int index, String string) {
- if (0 <= index && index <= count) {
+ if (index >= 0 && index <= count) {
if (string == null) {
string = "null";
}
@@ -363,7 +361,7 @@ abstract class AbstractStringBuilder {
count += min;
}
} else {
- throw new StringIndexOutOfBoundsException(index);
+ throw indexAndLength(index);
}
}
@@ -371,7 +369,7 @@ abstract class AbstractStringBuilder {
if (s == null) {
s = "null";
}
- if (index < 0 || index > count || start < 0 || end < 0 || start > end || end > s.length()) {
+ if ((index | start | end) < 0 || index > count || start > end || end > s.length()) {
throw new IndexOutOfBoundsException();
}
insert0(index, s.subSequence(start, end).toString());
@@ -390,14 +388,13 @@ abstract class AbstractStringBuilder {
int newCount;
if (value.length - count >= size) {
if (!shared) {
- System.arraycopy(value, index, value, index + size, count
- - index); // index == count case is no-op
+ // index == count case is no-op
+ System.arraycopy(value, index, value, index + size, count - index);
return;
}
newCount = value.length;
} else {
- int a = count + size, b = (value.length << 1) + 2;
- newCount = a > b ? a : b;
+ newCount = Math.max(count + size, value.length*2 + 2);
}
char[] newData = new char[newCount];
@@ -451,7 +448,7 @@ abstract class AbstractStringBuilder {
return;
}
}
- throw new StringIndexOutOfBoundsException();
+ throw startEndAndLength(start, end);
}
final void reverse0() {
@@ -543,8 +540,8 @@ abstract class AbstractStringBuilder {
* current {@link #length()}.
*/
public void setCharAt(int index, char ch) {
- if (0 > index || index >= count) {
- throw new StringIndexOutOfBoundsException(index);
+ if (index < 0 || index >= count) {
+ throw indexAndLength(index);
}
if (shared) {
value = value.clone();
@@ -566,7 +563,7 @@ abstract class AbstractStringBuilder {
*/
public void setLength(int length) {
if (length < 0) {
- throw new StringIndexOutOfBoundsException(length);
+ throw new StringIndexOutOfBoundsException("length < 0: " + length);
}
if (length > value.length) {
enlargeBuffer(length);
@@ -597,7 +594,7 @@ abstract class AbstractStringBuilder {
* {@link #length()}.
*/
public String substring(int start) {
- if (0 <= start && start <= count) {
+ if (start >= 0 && start <= count) {
if (start == count) {
return "";
}
@@ -605,7 +602,7 @@ abstract class AbstractStringBuilder {
// Remove String sharing for more performance
return new String(value, start, count - start);
}
- throw new StringIndexOutOfBoundsException(start);
+ throw new StringIndexOutOfBoundsException("start=" + start + " length=" + count);
}
/**
@@ -622,7 +619,7 @@ abstract class AbstractStringBuilder {
* {@code end} is greater than the current {@link #length()}.
*/
public String substring(int start, int end) {
- if (0 <= start && start <= end && end <= count) {
+ if (start >= 0 && start <= end && end <= count) {
if (start == end) {
return "";
}
@@ -630,7 +627,7 @@ abstract class AbstractStringBuilder {
// Remove String sharing for more performance
return new String(value, start, end - start);
}
- throw new StringIndexOutOfBoundsException();
+ throw startEndAndLength(start, end);
}
/**
@@ -835,7 +832,7 @@ abstract class AbstractStringBuilder {
*/
public int codePointAt(int index) {
if (index < 0 || index >= count) {
- throw new StringIndexOutOfBoundsException(index);
+ throw indexAndLength(index);
}
return Character.codePointAt(value, index, count);
}
@@ -855,34 +852,33 @@ abstract class AbstractStringBuilder {
*/
public int codePointBefore(int index) {
if (index < 1 || index > count) {
- throw new StringIndexOutOfBoundsException(index);
+ throw indexAndLength(index);
}
return Character.codePointBefore(value, index);
}
/**
- * Calculates the number of Unicode code points between {@code beginIndex}
- * and {@code endIndex}.
+ * Calculates the number of Unicode code points between {@code start}
+ * and {@code end}.
*
- * @param beginIndex
+ * @param start
* the inclusive beginning index of the subsequence.
- * @param endIndex
+ * @param end
* the exclusive end index of the subsequence.
* @return the number of Unicode code points in the subsequence.
* @throws IndexOutOfBoundsException
- * if {@code beginIndex} is negative or greater than
- * {@code endIndex} or {@code endIndex} is greater than
+ * if {@code start} is negative or greater than
+ * {@code end} or {@code end} is greater than
* {@link #length()}.
* @see Character
* @see Character#codePointCount(char[], int, int)
* @since 1.5
*/
- public int codePointCount(int beginIndex, int endIndex) {
- if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
- throw new StringIndexOutOfBoundsException();
+ public int codePointCount(int start, int end) {
+ if (start < 0 || end > count || start > end) {
+ throw startEndAndLength(start, end);
}
- return Character.codePointCount(value, beginIndex, endIndex
- - beginIndex);
+ return Character.codePointCount(value, start, end - start);
}
/**
diff --git a/luni/src/main/java/java/lang/Byte.java b/luni/src/main/java/java/lang/Byte.java
index 043a9f3..ff36aac 100644
--- a/luni/src/main/java/java/lang/Byte.java
+++ b/luni/src/main/java/java/lang/Byte.java
@@ -74,7 +74,7 @@ public final class Byte extends Number implements Comparable<Byte> {
* @param string
* the string representation of a single byte value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into a byte value.
+ * if {@code string} cannot be parsed as a byte value.
* @see #parseByte(String)
*/
public Byte(String string) throws NumberFormatException {
@@ -118,15 +118,15 @@ public final class Byte extends Number implements Comparable<Byte> {
* a string representation of a single byte value.
* @return a {@code Byte} containing the value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} can not be parsed as a byte value.
+ * if {@code string} cannot be parsed as a byte value.
*/
public static Byte decode(String string) throws NumberFormatException {
- int intValue = Integer.decode(string).intValue();
+ int intValue = Integer.decode(string);
byte result = (byte) intValue;
if (result == intValue) {
return valueOf(result);
}
- throw new NumberFormatException();
+ throw new NumberFormatException("Value out of range for byte: \"" + string + "\"");
}
@Override
@@ -178,16 +178,10 @@ public final class Byte extends Number implements Comparable<Byte> {
* the string representation of a single byte value.
* @return the primitive byte value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a byte value.
+ * if {@code string} can not be parsed as a byte value.
*/
public static byte parseByte(String string) throws NumberFormatException {
- int intValue = Integer.parseInt(string);
- byte result = (byte) intValue;
- if (result == intValue) {
- return result;
- }
- throw new NumberFormatException();
+ return parseByte(string, 10);
}
/**
@@ -201,19 +195,17 @@ public final class Byte extends Number implements Comparable<Byte> {
* @return the primitive byte value represented by {@code string} using
* {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a byte value.
+ * if {@code string} can not be parsed as a byte value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
*/
- public static byte parseByte(String string, int radix)
- throws NumberFormatException {
+ public static byte parseByte(String string, int radix) throws NumberFormatException {
int intValue = Integer.parseInt(string, radix);
byte result = (byte) intValue;
if (result == intValue) {
return result;
}
- throw new NumberFormatException();
+ throw new NumberFormatException("Value out of range for byte: \"" + string + "\"");
}
@Override
@@ -246,8 +238,7 @@ public final class Byte extends Number implements Comparable<Byte> {
* @return a {@code Byte} instance containing the byte value represented by
* {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a byte value.
+ * if {@code string} can not be parsed as a byte value.
* @see #parseByte(String)
*/
public static Byte valueOf(String string) throws NumberFormatException {
@@ -265,14 +256,12 @@ public final class Byte extends Number implements Comparable<Byte> {
* @return a {@code Byte} instance containing the byte value represented by
* {@code string} using {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a byte value.
+ * if {@code string} can not be parsed as a byte value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
* @see #parseByte(String, int)
*/
- public static Byte valueOf(String string, int radix)
- throws NumberFormatException {
+ public static Byte valueOf(String string, int radix) throws NumberFormatException {
return valueOf(parseByte(string, radix));
}
diff --git a/luni/src/main/java/java/lang/CaseMapper.java b/luni/src/main/java/java/lang/CaseMapper.java
index 58a4412..5ec41f5 100644
--- a/luni/src/main/java/java/lang/CaseMapper.java
+++ b/luni/src/main/java/java/lang/CaseMapper.java
@@ -16,8 +16,8 @@
package java.lang;
-import com.ibm.icu4jni.util.ICU;
import java.util.Locale;
+import libcore.icu.ICU;
/**
* Performs case operations as described by http://unicode.org/reports/tr21/tr21-5.html.
@@ -54,7 +54,7 @@ class CaseMapper {
int newCount = 0;
for (int i = offset, end = offset + count; i < end; ++i) {
char ch = value[i];
- char newCh = ch;
+ char newCh;
if (ch == LATIN_CAPITAL_I_WITH_DOT || Character.isHighSurrogate(ch)) {
// Punt these hard cases.
return ICU.toLowerCase(s, locale.toString());
@@ -75,14 +75,6 @@ class CaseMapper {
return newValue != null ? new String(0, newCount, newValue) : s;
}
- private static boolean followedBy(char[] value, int offset, int count, int index, char ch) {
- return index + 1 < offset + count && value[index + 1] == ch;
- }
-
- private static boolean precededBy(char[] value, int offset, int count, int index, char ch) {
- return index > offset && value[index - 1] == ch;
- }
-
/**
* True if 'index' is preceded by a sequence consisting of a cased letter and a case-ignorable
* sequence, and 'index' is not followed by a sequence consisting of an ignorable sequence and
diff --git a/luni/src/main/java/java/lang/Character.java b/luni/src/main/java/java/lang/Character.java
index 5f0c936..0caabba 100644
--- a/luni/src/main/java/java/lang/Character.java
+++ b/luni/src/main/java/java/lang/Character.java
@@ -18,6 +18,7 @@
package java.lang;
import java.io.Serializable;
+import java.util.Arrays;
/**
* The wrapper for the primitive type {@code char}. This class also provides a
@@ -499,44 +500,6 @@ public final class Character implements Serializable, Comparable<Character> {
*/
public static final int SIZE = 16;
- // BEGIN android-removed
- // Unicode 3.0.1 (same as Unicode 3.0.0)
- // private static final String bidiKeys = ...
-
- // private static final char[] bidiValues = ...
-
- // private static final char[] mirrored = ...
-
- // Unicode 3.0.1 (same as Unicode 3.0.0)
- // private static final String typeKeys = ...
-
- // private static final char[] typeValues = ...
-
- // private static final int[] typeValuesCache = ...
-
- // Unicode 3.0.1 (same as Unicode 3.0.0)
- // private static final String uppercaseKeys = ...
-
- // private static final char[] uppercaseValues = ...
-
- // private static final int[] uppercaseValuesCache = ...
-
- // private static final String lowercaseKeys = ...
-
- // private static final char[] lowercaseValues = ...
-
- // private static final int[] lowercaseValuesCache = ...
-
- // private static final String digitKeys = ...
-
- // private static final char[] digitValues = ...
-
- // private static final char[] typeTags = ...
- // END android-removed
-
- // BEGIN android-note
- // put this in a helper class so that it's only initialized on demand?
- // END android-note
private static final byte[] DIRECTIONALITY = new byte[] {
DIRECTIONALITY_LEFT_TO_RIGHT, DIRECTIONALITY_RIGHT_TO_LEFT,
DIRECTIONALITY_EUROPEAN_NUMBER,
@@ -555,22 +518,6 @@ public final class Character implements Serializable, Comparable<Character> {
DIRECTIONALITY_POP_DIRECTIONAL_FORMAT,
DIRECTIONALITY_NONSPACING_MARK, DIRECTIONALITY_BOUNDARY_NEUTRAL };
- // BEGIN android-removed
- // private static final int ISJAVASTART = 1;
-
- // private static final int ISJAVAPART = 2;
-
- // Unicode 3.0.1 (same as Unicode 3.0.0)
- // private static final String titlecaseKeys = ...
-
- // private static final char[] titlecaseValues = ...
-
- // Unicode 3.0.0 (NOT the same as Unicode 3.0.1)
- // private static final String numericKeys = ...
-
- // private static final char[] numericValues = ...
- // END android-removed
-
/*
* Represents a subset of the Unicode character set.
*/
@@ -1553,13 +1500,13 @@ public final class Character implements Serializable, Comparable<Character> {
* if {@code blockName} is not a valid block name.
* @since 1.5
*/
- public static final UnicodeBlock forName(String blockName) {
+ public static UnicodeBlock forName(String blockName) {
if (blockName == null) {
throw new NullPointerException();
}
int block = forNameImpl(blockName);
if (block == -1) {
- if(blockName.equals("SURROGATES_AREA")) {
+ if (blockName.equals("SURROGATES_AREA")) {
return SURROGATES_AREA;
} else if(blockName.equalsIgnoreCase("greek")) {
return GREEK;
@@ -1607,7 +1554,7 @@ public final class Character implements Serializable, Comparable<Character> {
throw new IllegalArgumentException();
}
int block = ofImpl(codePoint);
- if(block == -1 || block >= BLOCKS.length) {
+ if (block == -1 || block >= BLOCKS.length) {
return null;
}
return BLOCKS[block];
@@ -2210,15 +2157,8 @@ public final class Character implements Serializable, Comparable<Character> {
* @since 1.5
*/
public static int codePointCount(char[] seq, int offset, int count) {
- if (seq == null) {
- throw new NullPointerException();
- }
- int len = seq.length;
+ Arrays.checkOffsetAndCount(seq.length, offset, count);
int endIndex = offset + count;
- if (offset < 0 || count < 0 || endIndex > len) {
- throw new IndexOutOfBoundsException();
- }
-
int result = 0;
for (int i = offset; i < endIndex; i++) {
char c = seq[i];
@@ -2258,8 +2198,7 @@ public final class Character implements Serializable, Comparable<Character> {
* negative) from {@code index}.
* @since 1.5
*/
- public static int offsetByCodePoints(CharSequence seq, int index,
- int codePointOffset) {
+ public static int offsetByCodePoints(CharSequence seq, int index, int codePointOffset) {
if (seq == null) {
throw new NullPointerException();
}
@@ -2291,7 +2230,6 @@ public final class Character implements Serializable, Comparable<Character> {
return i;
}
- assert codePointOffset < 0;
int codePoints = -codePointOffset;
int i = index;
while (codePoints > 0) {
@@ -2344,12 +2282,9 @@ public final class Character implements Serializable, Comparable<Character> {
*/
public static int offsetByCodePoints(char[] seq, int start, int count,
int index, int codePointOffset) {
- if (seq == null) {
- throw new NullPointerException();
- }
+ Arrays.checkOffsetAndCount(seq.length, start, count);
int end = start + count;
- if (start < 0 || count < 0 || end > seq.length || index < start
- || index > end) {
+ if (index < start || index > end) {
throw new IndexOutOfBoundsException();
}
@@ -2376,7 +2311,6 @@ public final class Character implements Serializable, Comparable<Character> {
return i;
}
- assert codePointOffset < 0;
int codePoints = -codePointOffset;
int i = index;
while (codePoints > 0) {
@@ -2476,7 +2410,7 @@ public final class Character implements Serializable, Comparable<Character> {
*/
public static char forDigit(int digit, int radix) {
if (MIN_RADIX <= radix && radix <= MAX_RADIX) {
- if (0 <= digit && digit < radix) {
+ if (digit >= 0 && digit < radix) {
return (char) (digit < 10 ? digit + '0' : digit + 'a' - 10);
}
}
@@ -2484,13 +2418,13 @@ public final class Character implements Serializable, Comparable<Character> {
}
/**
- * Gets the numeric value of the specified Unicode character.
+ * Returns the numeric value of the specified Unicode character.
+ * See {@link #getNumericValue(int)}.
*
- * @param c
- * the Unicode character to get the numeric value of.
+ * @param c the character
* @return a non-negative numeric integer value if a numeric value for
* {@code c} exists, -1 if there is no numeric value for {@code c},
- * -2 if the numeric value can not be represented with an integer.
+ * -2 if the numeric value can not be represented as an integer.
*/
public static int getNumericValue(char c) {
return getNumericValue((int) c);
@@ -2501,16 +2435,22 @@ public final class Character implements Serializable, Comparable<Character> {
* the code point '\u216B' stands for the Roman number XII, which has the
* numeric value 12.
*
- * @param codePoint
- * the Unicode code point to get the numeric value of.
+ * <p>There are two points of divergence between this method and the Unicode
+ * specification. This method treats the letters a-z (in both upper and lower
+ * cases, and their full-width variants) as numbers from 10 to 35. The
+ * Unicode specification also supports the idea of code points with non-integer
+ * numeric values; this method does not (except to the extent of returning -2
+ * for such code points).
+ *
+ * @param codePoint the code point
* @return a non-negative numeric integer value if a numeric value for
* {@code codePoint} exists, -1 if there is no numeric value for
* {@code codePoint}, -2 if the numeric value can not be
* represented with an integer.
*/
public static int getNumericValue(int codePoint) {
+ // This is both an optimization and papers over differences between Java and ICU.
if (codePoint < 128) {
- // Optimized for ASCII
if (codePoint >= '0' && codePoint <= '9') {
return codePoint - '0';
}
@@ -2522,6 +2462,14 @@ public final class Character implements Serializable, Comparable<Character> {
}
return -1;
}
+ // Full-width uppercase A-Z.
+ if (codePoint >= 0xff21 && codePoint <= 0xff3a) {
+ return codePoint - 0xff17;
+ }
+ // Full-width lowercase a-z.
+ if (codePoint >= 0xff41 && codePoint <= 0xff5a) {
+ return codePoint - 0xff37;
+ }
return getNumericValueImpl(codePoint);
}
@@ -2702,6 +2650,7 @@ public final class Character implements Serializable, Comparable<Character> {
* otherwise.
*/
public static boolean isIdentifierIgnorable(int codePoint) {
+ // This is both an optimization and papers over differences between Java and ICU.
if (codePoint < 0x600) {
return (codePoint >= 0 && codePoint <= 8) || (codePoint >= 0xe && codePoint <= 0x1b) ||
(codePoint >= 0x7f && codePoint <= 0x9f) || (codePoint == 0xad);
@@ -3136,7 +3085,7 @@ public final class Character implements Serializable, Comparable<Character> {
* in Java; {@code false} otherwise.
*/
public static boolean isWhitespace(int codePoint) {
- // Optimized case for ASCII
+ // This is both an optimization and papers over differences between Java and ICU.
if ((codePoint >= 0x1c && codePoint <= 0x20) || (codePoint >= 0x9 && codePoint <= 0xd)) {
return true;
}
diff --git a/luni/src/main/java/java/lang/Class.java b/luni/src/main/java/java/lang/Class.java
index 17bc86d..ff1a5d3 100644
--- a/luni/src/main/java/java/lang/Class.java
+++ b/luni/src/main/java/java/lang/Class.java
@@ -284,13 +284,11 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
*/
@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
- Annotation[] list = getAnnotations();
- for (int i = 0; i < list.length; i++) {
- if (annotationClass.isInstance(list[i])) {
- return (A)list[i];
+ for (Annotation annotation : getAnnotations()) {
+ if (annotationClass.isInstance(annotation)) {
+ return (A) annotation;
}
}
-
return null;
}
@@ -314,19 +312,17 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* HashMap might be overkill here.
*/
HashMap<Class, Annotation> map = new HashMap<Class, Annotation>();
- Annotation[] annos = getDeclaredAnnotations();
-
- for (int i = annos.length-1; i >= 0; --i)
- map.put(annos[i].annotationType(), annos[i]);
-
- for (Class sup = getSuperclass(); sup != null;
- sup = sup.getSuperclass()) {
- annos = sup.getDeclaredAnnotations();
- for (int i = annos.length-1; i >= 0; --i) {
- Class clazz = annos[i].annotationType();
- if (!map.containsKey(clazz) &&
- clazz.isAnnotationPresent(Inherited.class)) {
- map.put(clazz, annos[i]);
+ Annotation[] declaredAnnotations = getDeclaredAnnotations();
+
+ for (int i = declaredAnnotations.length-1; i >= 0; --i) {
+ map.put(declaredAnnotations[i].annotationType(), declaredAnnotations[i]);
+ }
+ for (Class<?> sup = getSuperclass(); sup != null; sup = sup.getSuperclass()) {
+ declaredAnnotations = sup.getDeclaredAnnotations();
+ for (int i = declaredAnnotations.length-1; i >= 0; --i) {
+ Class<?> clazz = declaredAnnotations[i].annotationType();
+ if (!map.containsKey(clazz) && clazz.isAnnotationPresent(Inherited.class)) {
+ map.put(clazz, declaredAnnotations[i]);
}
}
}
@@ -617,11 +613,11 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* @throws NoSuchMethodException if the constructor does not exist.
*/
private Constructor<T> getMatchingConstructor(
- Constructor<T>[] list, Class<?>[] parameterTypes)
+ Constructor<T>[] constructors, Class<?>[] parameterTypes)
throws NoSuchMethodException {
- for (int i = 0; i < list.length; i++) {
- if (compareClassLists(list[i].getParameterTypes(), parameterTypes)) {
- return list[i];
+ for (Constructor<T> constructor : constructors) {
+ if (compareClassLists(constructor.getParameterTypes(), parameterTypes)) {
+ return constructor;
}
}
@@ -658,8 +654,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* access.
* @see #getField(String)
*/
- public Field getDeclaredField(String name)
- throws NoSuchFieldException, SecurityException {
+ public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
checkDeclaredMemberAccess();
Field[] fields = getClassCache().getDeclaredFields();
@@ -835,7 +830,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
T[] values = getClassCache().getEnumValuesInOrder();
// Copy the private (to the package) array.
- return (T[]) values.clone();
+ return values.clone();
}
return null;
@@ -871,6 +866,26 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
}
/**
+ * Finds and returns a field with a given name and signature. Use
+ * this with one of the field lists returned by instances of ClassCache.
+ *
+ * @param list non-null; the list of fields to search through
+ * @return non-null; the matching field
+ * @throws NoSuchFieldException thrown if the field does not exist
+ */
+ private Field findFieldByName(Field[] list, String name) throws NoSuchFieldException {
+ if (name == null) {
+ throw new NullPointerException("name == null");
+ }
+ for (Field field : list) {
+ if (field.getName().equals(name)) {
+ return field;
+ }
+ }
+ throw new NoSuchFieldException("No field '" + name + "' in " + this);
+ }
+
+ /**
* Returns an array containing {@code Field} objects for all public fields
* for the class C represented by this {@code Class}. Fields may be declared
* in C, the interfaces it implements or in the superclasses of C. The
@@ -1077,7 +1092,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* defined in the source code. If there is no name (that is, the class is
* anonymous) then an empty string is returned. If the receiver is an array
* then the name of the underlying type with square braces appended (for
- * example {@code &quot;Integer[]&quot;}) is returned.
+ * example {@code "Integer[]"}) is returned.
*
* @return the simple name of the class represented by this {@code Class}.
*/
@@ -1467,7 +1482,9 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
if (clazz.isAssignableFrom(this)) {
return (Class<? extends U>)this;
}
- throw new ClassCastException();
+ String actualClassName = this.getName();
+ String desiredClassName = clazz.getName();
+ throw new ClassCastException(actualClassName + " cannot be cast to " + desiredClassName);
}
/**
@@ -1487,7 +1504,9 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
} else if (this.isInstance(obj)) {
return (T)obj;
}
- throw new ClassCastException();
+ String actualClassName = obj.getClass().getName();
+ String desiredClassName = this.getName();
+ throw new ClassCastException(actualClassName + " cannot be cast to " + desiredClassName);
}
/**
@@ -1553,7 +1572,7 @@ public final class Class<T> implements Serializable, AnnotatedElement, GenericDe
* stop at privileged classes
* @return the array of the most recent classes on the stack
*/
- static final Class<?>[] getStackClasses(int maxDepth, boolean stopAtPrivileged) {
+ static Class<?>[] getStackClasses(int maxDepth, boolean stopAtPrivileged) {
return VMStack.getClasses(maxDepth, stopAtPrivileged);
}
diff --git a/luni/src/main/java/java/lang/ClassCache.java b/luni/src/main/java/java/lang/ClassCache.java
index 5588f62..eb811ae 100644
--- a/luni/src/main/java/java/lang/ClassCache.java
+++ b/luni/src/main/java/java/lang/ClassCache.java
@@ -213,9 +213,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
*/
private static void getMethodsRecursive(Class<?> clazz, List<Method> result) {
for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
- for (Method method : c.getClassCache().getDeclaredPublicMethods()) {
- result.add(method);
- }
+ result.addAll(Arrays.asList(c.getClassCache().getDeclaredPublicMethods()));
}
for (Class<?> ifc : clazz.getInterfaces()) {
@@ -235,7 +233,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
public static Method findMethodByName(Method[] list, String name,
Class<?>[] parameterTypes) throws NoSuchMethodException {
if (name == null) {
- throw new NullPointerException("Method name must not be null.");
+ throw new NullPointerException("name == null");
}
for (Method method : list) {
if (method.getName().equals(name)
@@ -382,7 +380,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
ArrayList<Field> fields = new ArrayList<Field>();
HashSet<String> seen = new HashSet<String>();
- findAllfields(clazz, fields, seen, publicOnly);
+ findAllFields(clazz, fields, seen, publicOnly);
return fields.toArray(new Field[fields.size()]);
}
@@ -400,7 +398,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
* @param publicOnly reflects whether we want only public fields
* or all of them
*/
- private static void findAllfields(Class<?> clazz,
+ private static void findAllFields(Class<?> clazz,
ArrayList<Field> fields, HashSet<String> seen,
boolean publicOnly) {
@@ -415,9 +413,8 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
}
// Traverse all interfaces, and do the same recursively.
- Class<?>[] interfaces = clazz.getInterfaces();
- for (Class<?> intf : interfaces) {
- findAllfields(intf, fields, seen, publicOnly);
+ for (Class<?> interfaceClass : clazz.getInterfaces()) {
+ findAllFields(interfaceClass, fields, seen, publicOnly);
}
clazz = clazz.getSuperclass();
@@ -425,28 +422,6 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
}
/**
- * Finds and returns a field with a given name and signature. Use
- * this with one of the field lists returned by instances of this class.
- *
- * @param list non-null; the list of fields to search through
- * @return non-null; the matching field
- * @throws NoSuchFieldException thrown if the field does not exist
- */
- public static Field findFieldByName(Field[] list, String name)
- throws NoSuchFieldException {
- if (name == null) {
- throw new NullPointerException("Field name must not be null.");
- }
- for (Field field : list) {
- if (field.getName().equals(name)) {
- return field;
- }
- }
-
- throw new NoSuchFieldException(name);
- }
-
- /**
* Makes a deep copy of the given array of fields. This is useful
* when handing out arrays from the public API.
*
@@ -523,7 +498,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
T[] values = getEnumValuesInOrder();
if (values != null) {
- values = (T[]) values.clone();
+ values = values.clone();
Arrays.sort((Enum<?>[]) values, ENUM_COMPARATOR);
/*
@@ -566,7 +541,7 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
try {
Method[] methods = getDeclaredPublicMethods();
- method = findMethodByName(methods, "values", (Class[]) null);
+ method = findMethodByName(methods, "values", null);
method = REFLECT.accessibleClone(method);
} catch (NoSuchMethodException ex) {
// This shouldn't happen if the class is a well-formed enum.
@@ -603,12 +578,10 @@ import org.apache.harmony.kernel.vm.ReflectionAccess;
* initialization. So instead, we do a direct call into the
* native side.
*/
- Method[] methods =
- Class.getDeclaredMethods(AccessibleObject.class, false);
+ Method[] methods = Class.getDeclaredMethods(AccessibleObject.class, false);
try {
- Method method = findMethodByName(methods, "getReflectionAccess",
- (Class[]) null);
+ Method method = findMethodByName(methods, "getReflectionAccess", null);
Class.setAccessibleNoCheck(method, true);
return (ReflectionAccess) method.invoke((Object[]) null);
} catch (NoSuchMethodException ex) {
diff --git a/luni/src/main/java/java/lang/ClassCastException.java b/luni/src/main/java/java/lang/ClassCastException.java
index c63aff0..676f1b2 100644
--- a/luni/src/main/java/java/lang/ClassCastException.java
+++ b/luni/src/main/java/java/lang/ClassCastException.java
@@ -42,18 +42,4 @@ public class ClassCastException extends RuntimeException {
public ClassCastException(String detailMessage) {
super(detailMessage);
}
-
- /**
- * Constructs a new {@code ClassCastException} with the current stack trace
- * and a detail message based on the source and target class.
- *
- * @param instanceClass
- * the class being cast from.
- * @param castClass
- * the class being cast to.
- */
- ClassCastException(Class<?> instanceClass, Class<?> castClass) {
- super(String.format("%s incompatible with %s", instanceClass.getName(),
- castClass.getName()));
- }
}
diff --git a/luni/src/main/java/java/lang/ClassLoader.java b/luni/src/main/java/java/lang/ClassLoader.java
index d599508..43990cc 100644
--- a/luni/src/main/java/java/lang/ClassLoader.java
+++ b/luni/src/main/java/java/lang/ClassLoader.java
@@ -40,6 +40,7 @@ import java.net.URL;
import java.nio.ByteBuffer;
import java.security.ProtectionDomain;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@@ -434,14 +435,10 @@ public abstract class ClassLoader {
* @see Class#getResource
*/
public URL getResource(String resName) {
- URL resource = null;
-
- resource = parent.getResource(resName);
-
+ URL resource = parent.getResource(resName);
if (resource == null) {
resource = findResource(resName);
}
-
return resource;
}
@@ -647,7 +644,7 @@ public abstract class ClassLoader {
"unchecked", "unused"
})
protected Enumeration<URL> findResources(String resName) throws IOException {
- return EmptyEnumeration.getInstance();
+ return Collections.enumeration(Collections.<URL>emptyList());
}
/**
@@ -678,8 +675,7 @@ public abstract class ClassLoader {
*/
protected Package getPackage(String name) {
synchronized (packages) {
- Package p = packages.get(name);
- return p;
+ return packages.get(name);
}
}
@@ -1028,14 +1024,7 @@ class BootClassLoader extends ClassLoader {
@SuppressWarnings("unused")
@Override
protected Enumeration<URL> findResources(String resName) throws IOException {
- Enumeration<URL> result = VMClassLoader.getResources(resName);
-
- // VMClassLoader doesn't keep the contract for getResources()
- if (result == null) {
- result = EmptyEnumeration.getInstance();
- }
-
- return result;
+ return Collections.enumeration(VMClassLoader.getResources(resName));
}
/**
diff --git a/luni/src/main/java/java/lang/Compiler.java b/luni/src/main/java/java/lang/Compiler.java
index 3ce5376..be42394 100644
--- a/luni/src/main/java/java/lang/Compiler.java
+++ b/luni/src/main/java/java/lang/Compiler.java
@@ -79,14 +79,11 @@ public final class Compiler {
* Disables the JIT compiler. Does nothing on Android.
*/
public static void disable() {
- return;
}
/**
* Enables the JIT compiler. Does nothing on Android.
*/
public static void enable() {
- return;
}
-
}
diff --git a/luni/src/main/java/java/lang/Double.java b/luni/src/main/java/java/lang/Double.java
index 644592b..0edc4d7 100644
--- a/luni/src/main/java/java/lang/Double.java
+++ b/luni/src/main/java/java/lang/Double.java
@@ -130,7 +130,7 @@ public final class Double extends Number implements Comparable<Double> {
* @param string
* the string representation of a double value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into a double value.
+ * if {@code string} cannot be parsed as a double value.
* @see #parseDouble(String)
*/
public Double(String string) throws NumberFormatException {
@@ -311,8 +311,7 @@ public final class Double extends Number implements Comparable<Double> {
* the string representation of a double value.
* @return the primitive double value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a double value.
+ * if {@code string} cannot be parsed as a double value.
*/
public static double parseDouble(String string) throws NumberFormatException {
return org.apache.harmony.luni.util.FloatingPointParser.parseDouble(string);
@@ -348,8 +347,7 @@ public final class Double extends Number implements Comparable<Double> {
* @return a {@code Double} instance containing the double value represented
* by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a double value.
+ * if {@code string} cannot be parsed as a double value.
* @see #parseDouble(String)
*/
public static Double valueOf(String string) throws NumberFormatException {
diff --git a/luni/src/main/java/java/lang/EmptyEnumeration.java b/luni/src/main/java/java/lang/EmptyEnumeration.java
deleted file mode 100644
index 115cf9f..0000000
--- a/luni/src/main/java/java/lang/EmptyEnumeration.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.lang;
-
-import java.io.Serializable;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.NoSuchElementException;
-
-/**
- * Empty enumeration class. Call getInstance() to get the singleton.
- *
- * This is not part of the Java spec, so must be package-scope only.
- */
-/*package*/ final class EmptyEnumeration implements Enumeration<URL>, Serializable {
-
- private static final EmptyEnumeration mInst = new EmptyEnumeration();
-
- /**
- * One instance per VM.
- */
- private EmptyEnumeration() {}
-
- /**
- * Return instance.
- */
- public static EmptyEnumeration getInstance() {
- return mInst;
- }
-
- /**
- * Enumeration implementation.
- */
- public boolean hasMoreElements() {
- return false;
- }
-
- public URL nextElement() {
- throw new NoSuchElementException();
- }
-}
-
diff --git a/luni/src/main/java/java/lang/Enum.java b/luni/src/main/java/java/lang/Enum.java
index e70c198..88c4d73 100644
--- a/luni/src/main/java/java/lang/Enum.java
+++ b/luni/src/main/java/java/lang/Enum.java
@@ -188,26 +188,4 @@ public abstract class Enum<E extends Enum<E>> implements Serializable, Comparabl
@SuppressWarnings("FinalizeDoesntCallSuperFinalize")
protected final void finalize() {
}
-
- /*
- * Helper to invoke the values() static method on T and answer the result.
- * Returns null if there is a problem.
- */
- @SuppressWarnings("unchecked")
- static <T extends Enum<T>> T[] getValues(final Class<T> enumType) {
- try {
- Method values = AccessController
- .doPrivileged(new PrivilegedExceptionAction<Method>() {
- public Method run() throws Exception {
- Method valsMethod = enumType.getMethod("values",
- (Class[]) null);
- valsMethod.setAccessible(true);
- return valsMethod;
- }
- });
- return (T[]) values.invoke(enumType, (Object[])null);
- } catch (Exception e) {
- return null;
- }
- }
}
diff --git a/luni/src/main/java/java/lang/Float.java b/luni/src/main/java/java/lang/Float.java
index 446a346..e641eb6 100644
--- a/luni/src/main/java/java/lang/Float.java
+++ b/luni/src/main/java/java/lang/Float.java
@@ -136,7 +136,7 @@ public final class Float extends Number implements Comparable<Float> {
* @param string
* the string representation of a float value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into a float value.
+ * if {@code string} can not be parsed as a float value.
* @see #parseFloat(String)
*/
public Float(String string) throws NumberFormatException {
@@ -314,8 +314,7 @@ public final class Float extends Number implements Comparable<Float> {
* the string representation of a float value.
* @return the primitive float value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a float value.
+ * if {@code string} can not be parsed as a float value.
* @see #valueOf(String)
* @since 1.2
*/
@@ -354,8 +353,7 @@ public final class Float extends Number implements Comparable<Float> {
* @return a {@code Float} instance containing the float value represented
* by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a float value.
+ * if {@code string} can not be parsed as a float value.
* @see #parseFloat(String)
*/
public static Float valueOf(String string) throws NumberFormatException {
diff --git a/luni/src/main/java/java/lang/Integer.java b/luni/src/main/java/java/lang/Integer.java
index c8ac552..bec53c9 100644
--- a/luni/src/main/java/java/lang/Integer.java
+++ b/luni/src/main/java/java/lang/Integer.java
@@ -15,10 +15,6 @@
* limitations under the License.
*/
-// BEGIN android-note
-// Reimiplemented toString, bit-twiddling, etc. Faster and cleaner.
-// BEGIN android-note
-
package java.lang;
/**
@@ -98,7 +94,7 @@ public final class Integer extends Number implements Comparable<Integer> {
* @param string
* the string representation of an integer value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into an integer value.
+ * if {@code string} cannot be parsed as an integer value.
* @see #parseInt(String)
*/
public Integer(String string) throws NumberFormatException {
@@ -129,6 +125,10 @@ public final class Integer extends Number implements Comparable<Integer> {
return thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1);
}
+ private static NumberFormatException invalidInt(String s) {
+ throw new NumberFormatException("Invalid int: \"" + s + "\"");
+ }
+
/**
* Parses the specified string and returns a {@code Integer} instance if the
* string can be decoded into an integer value. The string may be an
@@ -140,22 +140,18 @@ public final class Integer extends Number implements Comparable<Integer> {
* @return an {@code Integer} containing the value represented by
* {@code string}.
* @throws NumberFormatException
- * if {@code string} can not be parsed as an integer value.
+ * if {@code string} cannot be parsed as an integer value.
*/
public static Integer decode(String string) throws NumberFormatException {
int length = string.length(), i = 0;
if (length == 0) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
char firstDigit = string.charAt(i);
boolean negative = firstDigit == '-';
if (negative) {
if (length == 1) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
firstDigit = string.charAt(++i);
}
@@ -167,9 +163,7 @@ public final class Integer extends Number implements Comparable<Integer> {
}
if ((firstDigit = string.charAt(i)) == 'x' || firstDigit == 'X') {
if (++i == length) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
base = 16;
} else {
@@ -177,9 +171,7 @@ public final class Integer extends Number implements Comparable<Integer> {
}
} else if (firstDigit == '#') {
if (++i == length) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
base = 16;
}
@@ -325,8 +317,7 @@ public final class Integer extends Number implements Comparable<Integer> {
* the string representation of an integer value.
* @return the primitive integer value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as an integer value.
+ * if {@code string} cannot be parsed as an integer value.
*/
public static int parseInt(String string) throws NumberFormatException {
return parseInt(string, 10);
@@ -343,65 +334,50 @@ public final class Integer extends Number implements Comparable<Integer> {
* @return the primitive integer value represented by {@code string} using
* {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as an integer value.
- */
- public static int parseInt(String string, int radix)
- throws NumberFormatException {
- if (string == null || radix < Character.MIN_RADIX
- || radix > Character.MAX_RADIX) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ * if {@code string} cannot be parsed as an integer value,
+ * or {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
+ */
+ public static int parseInt(String string, int radix) throws NumberFormatException {
+ if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
+ throw new NumberFormatException("Invalid radix: " + radix);
+ }
+ if (string == null) {
+ throw invalidInt(string);
}
int length = string.length(), i = 0;
if (length == 0) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
boolean negative = string.charAt(i) == '-';
if (negative && ++i == length) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
return parse(string, i, radix, negative);
}
- private static int parse(String string, int offset, int radix,
- boolean negative) throws NumberFormatException {
+ private static int parse(String string, int offset, int radix, boolean negative) throws NumberFormatException {
int max = Integer.MIN_VALUE / radix;
int result = 0, length = string.length();
while (offset < length) {
int digit = Character.digit(string.charAt(offset++), radix);
if (digit == -1) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
if (max > result) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
int next = result * radix - digit;
if (next > result) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
result = next;
}
if (!negative) {
result = -result;
if (result < 0) {
- // BEGIN android-changed
- throw new NumberFormatException("unable to parse '"+string+"' as integer");
- // END android-changed
+ throw invalidInt(string);
}
}
return result;
@@ -498,8 +474,7 @@ public final class Integer extends Number implements Comparable<Integer> {
* @return an {@code Integer} instance containing the integer value
* represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as an integer value.
+ * if {@code string} cannot be parsed as an integer value.
* @see #parseInt(String)
*/
public static Integer valueOf(String string) throws NumberFormatException {
@@ -517,14 +492,12 @@ public final class Integer extends Number implements Comparable<Integer> {
* @return an {@code Integer} instance containing the integer value
* represented by {@code string} using {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as an integer value.
+ * if {@code string} cannot be parsed as an integer value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
* @see #parseInt(String, int)
*/
- public static Integer valueOf(String string, int radix)
- throws NumberFormatException {
+ public static Integer valueOf(String string, int radix) throws NumberFormatException {
return valueOf(parseInt(string, radix));
}
diff --git a/luni/src/main/java/java/lang/IntegralToString.java b/luni/src/main/java/java/lang/IntegralToString.java
index ec8255a..8329a25 100644
--- a/luni/src/main/java/java/lang/IntegralToString.java
+++ b/luni/src/main/java/java/lang/IntegralToString.java
@@ -181,9 +181,9 @@ public final class IntegralToString {
// If -n is still negative, n is Integer.MIN_VALUE
quickResult = "-2147483648";
} else {
- String result = SMALL_NEGATIVE_VALUES[i];
- if (result == null) {
- SMALL_NEGATIVE_VALUES[i] = result =
+ quickResult = SMALL_NEGATIVE_VALUES[i];
+ if (quickResult == null) {
+ SMALL_NEGATIVE_VALUES[i] = quickResult =
i < 10 ? stringOf('-', ONES[i]) : stringOf('-', TENS[i], ONES[i]);
}
}
diff --git a/luni/src/main/java/java/lang/Long.java b/luni/src/main/java/java/lang/Long.java
index 7b7e5f3..fa1ae6c 100644
--- a/luni/src/main/java/java/lang/Long.java
+++ b/luni/src/main/java/java/lang/Long.java
@@ -15,10 +15,6 @@
* limitations under the License.
*/
-// BEGIN android-note
-// Reimiplemented toString, bit-twiddling, etc. Faster and cleaner.
-// BEGIN android-note
-
package java.lang;
/**
@@ -85,7 +81,7 @@ public final class Long extends Number implements Comparable<Long> {
* @param string
* the string representation of a long value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into a long value.
+ * if {@code string} cannot be parsed as a long value.
* @see #parseLong(String)
*/
public Long(String string) throws NumberFormatException {
@@ -116,6 +112,10 @@ public final class Long extends Number implements Comparable<Long> {
return thisValue < thatValue ? -1 : (thisValue == thatValue ? 0 : 1);
}
+ private static NumberFormatException invalidLong(String s) {
+ throw new NumberFormatException("Invalid long: \"" + s + "\"");
+ }
+
/**
* Parses the specified string and returns a {@code Long} instance if the
* string can be decoded into a long value. The string may be an optional
@@ -126,18 +126,18 @@ public final class Long extends Number implements Comparable<Long> {
* a string representation of a long value.
* @return a {@code Long} containing the value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} can not be parsed as a long value.
+ * if {@code string} cannot be parsed as a long value.
*/
public static Long decode(String string) throws NumberFormatException {
int length = string.length(), i = 0;
if (length == 0) {
- throw new NumberFormatException();
+ throw invalidLong(string);
}
char firstDigit = string.charAt(i);
boolean negative = firstDigit == '-';
if (negative) {
if (length == 1) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
firstDigit = string.charAt(++i);
}
@@ -149,7 +149,7 @@ public final class Long extends Number implements Comparable<Long> {
}
if ((firstDigit = string.charAt(i)) == 'x' || firstDigit == 'X') {
if (i == length) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
i++;
base = 16;
@@ -158,7 +158,7 @@ public final class Long extends Number implements Comparable<Long> {
}
} else if (firstDigit == '#') {
if (i == length) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
i++;
base = 16;
@@ -304,8 +304,7 @@ public final class Long extends Number implements Comparable<Long> {
* the string representation of a long value.
* @return the primitive long value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a long value.
+ * if {@code string} cannot be parsed as a long value.
*/
public static long parseLong(String string) throws NumberFormatException {
return parseLong(string, 10);
@@ -322,23 +321,24 @@ public final class Long extends Number implements Comparable<Long> {
* @return the primitive long value represented by {@code string} using
* {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a long value.
+ * if {@code string} cannot be parsed as a long value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
*/
public static long parseLong(String string, int radix) throws NumberFormatException {
- if (string == null || radix < Character.MIN_RADIX
- || radix > Character.MAX_RADIX) {
- throw new NumberFormatException();
+ if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
+ throw new NumberFormatException("Invalid radix: " + radix);
+ }
+ if (string == null) {
+ throw invalidLong(string);
}
int length = string.length(), i = 0;
if (length == 0) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
boolean negative = string.charAt(i) == '-';
if (negative && ++i == length) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
return parse(string, i, radix, negative);
@@ -350,21 +350,21 @@ public final class Long extends Number implements Comparable<Long> {
while (offset < length) {
int digit = Character.digit(string.charAt(offset++), radix);
if (digit == -1) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
if (max > result) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
long next = result * radix - digit;
if (next > result) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
result = next;
}
if (!negative) {
result = -result;
if (result < 0) {
- throw new NumberFormatException(string);
+ throw invalidLong(string);
}
}
return result;
@@ -461,8 +461,7 @@ public final class Long extends Number implements Comparable<Long> {
* @return a {@code Long} instance containing the long value represented by
* {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a long value.
+ * if {@code string} cannot be parsed as a long value.
* @see #parseLong(String)
*/
public static Long valueOf(String string) throws NumberFormatException {
@@ -480,10 +479,9 @@ public final class Long extends Number implements Comparable<Long> {
* @return a {@code Long} instance containing the long value represented by
* {@code string} using {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a long value.
+ * if {@code string} cannot be parsed as a long value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
* @see #parseLong(String, int)
*/
public static Long valueOf(String string, int radix) throws NumberFormatException {
diff --git a/luni/src/main/java/java/lang/Math.java b/luni/src/main/java/java/lang/Math.java
index 1da0b90..b1179a3 100644
--- a/luni/src/main/java/java/lang/Math.java
+++ b/luni/src/main/java/java/lang/Math.java
@@ -767,8 +767,8 @@ public final class Math {
* <li>{@code round(-0.0) = +0.0}</li>
* <li>{@code round((anything > Integer.MAX_VALUE) = Integer.MAX_VALUE}</li>
* <li>{@code round((anything < Integer.MIN_VALUE) = Integer.MIN_VALUE}</li>
- * <li>{@code round(+infintiy) = Integer.MAX_VALUE}</li>
- * <li>{@code round(-infintiy) = Integer.MIN_VALUE}</li>
+ * <li>{@code round(+infinity) = Integer.MAX_VALUE}</li>
+ * <li>{@code round(-infinity) = Integer.MIN_VALUE}</li>
* <li>{@code round(NaN) = +0.0}</li>
* </ul>
*
@@ -1017,8 +1017,8 @@ public final class Math {
* <ul>
* <li>{@code ulp(+0.0) = Double.MIN_VALUE}</li>
* <li>{@code ulp(-0.0) = Double.MIN_VALUE}</li>
- * <li>{@code ulp(+infintiy) = infinity}</li>
- * <li>{@code ulp(-infintiy) = infinity}</li>
+ * <li>{@code ulp(+infinity) = infinity}</li>
+ * <li>{@code ulp(-infinity) = infinity}</li>
* <li>{@code ulp(NaN) = NaN}</li>
* </ul>
*
@@ -1047,8 +1047,8 @@ public final class Math {
* <ul>
* <li>{@code ulp(+0.0) = Float.MIN_VALUE}</li>
* <li>{@code ulp(-0.0) = Float.MIN_VALUE}</li>
- * <li>{@code ulp(+infintiy) = infinity}</li>
- * <li>{@code ulp(-infintiy) = infinity}</li>
+ * <li>{@code ulp(+infinity) = infinity}</li>
+ * <li>{@code ulp(-infinity) = infinity}</li>
* <li>{@code ulp(NaN) = NaN}</li>
* </ul>
*
@@ -1281,7 +1281,7 @@ public final class Math {
int sign = bits & Float.SIGN_MASK;
int factor = ((bits & Float.EXPONENT_MASK) >> Float.MANTISSA_BITS)
- Float.EXPONENT_BIAS + scaleFactor;
- // calcutes the factor of sub-normal values
+ // calculates the factor of sub-normal values
int subNormalFactor = Integer.numberOfLeadingZeros(bits & ~Float.SIGN_MASK)
- Float.NON_MANTISSA_BITS;
if (subNormalFactor < 0) {
@@ -1327,17 +1327,17 @@ public final class Math {
return bits << digits;
}
// change it to positive
- int absdigits = -digits;
- if (!(Integer.numberOfLeadingZeros(bits & ~Float.SIGN_MASK) <= (32 - absdigits))) {
+ int absDigits = -digits;
+ if (!(Integer.numberOfLeadingZeros(bits & ~Float.SIGN_MASK) <= (32 - absDigits))) {
return 0;
}
- int ret = bits >> absdigits;
- boolean halfbit = ((bits >> (absdigits - 1)) & 0x1) == 1;
- if (halfbit) {
- if (Integer.numberOfTrailingZeros(bits) < (absdigits - 1)) {
+ int ret = bits >> absDigits;
+ boolean halfBit = ((bits >> (absDigits - 1)) & 0x1) == 1;
+ if (halfBit) {
+ if (Integer.numberOfTrailingZeros(bits) < (absDigits - 1)) {
ret = ret + 1;
}
- if (Integer.numberOfTrailingZeros(bits) == (absdigits - 1)) {
+ if (Integer.numberOfTrailingZeros(bits) == (absDigits - 1)) {
if ((ret & 0x1) == 1) {
ret = ret + 1;
}
@@ -1353,19 +1353,19 @@ public final class Math {
return bits << digits;
}
// change it to positive
- long absdigits = -digits;
- if (!(Long.numberOfLeadingZeros(bits & ~Double.SIGN_MASK) <= (64 - absdigits))) {
+ long absDigits = -digits;
+ if (!(Long.numberOfLeadingZeros(bits & ~Double.SIGN_MASK) <= (64 - absDigits))) {
return 0;
}
- long ret = bits >> absdigits;
- boolean halfbit = ((bits >> (absdigits - 1)) & 0x1) == 1;
- if (halfbit) {
+ long ret = bits >> absDigits;
+ boolean halfBit = ((bits >> (absDigits - 1)) & 0x1) == 1;
+ if (halfBit) {
// some bits will remain after shifting, calculates its carry
// subnormal
- if (Long.numberOfTrailingZeros(bits) < (absdigits - 1)) {
+ if (Long.numberOfTrailingZeros(bits) < (absDigits - 1)) {
ret = ret + 1;
}
- if (Long.numberOfTrailingZeros(bits) == (absdigits - 1)) {
+ if (Long.numberOfTrailingZeros(bits) == (absDigits - 1)) {
if ((ret & 0x1) == 1) {
ret = ret + 1;
}
diff --git a/luni/src/main/java/java/lang/Object.java b/luni/src/main/java/java/lang/Object.java
index 0d6b312..6a979bb 100644
--- a/luni/src/main/java/java/lang/Object.java
+++ b/luni/src/main/java/java/lang/Object.java
@@ -234,7 +234,7 @@ public class Object {
*
* @return this object's {@code Class} instance.
*/
- public final native Class<? extends Object> getClass();
+ public final native Class<?> getClass();
/**
* Returns an integer hash code for this object. By contract, any two
diff --git a/luni/src/main/java/java/lang/Package.java b/luni/src/main/java/java/lang/Package.java
index af96621..e3095ea 100644
--- a/luni/src/main/java/java/lang/Package.java
+++ b/luni/src/main/java/java/lang/Package.java
@@ -77,13 +77,11 @@ public class Package implements AnnotatedElement {
*/
@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
- Annotation[] list = getAnnotations();
- for (int i = 0; i < list.length; i++) {
- if (annotationType.isInstance(list[i])) {
- return (A) list[i];
+ for (Annotation annotation : getAnnotations()) {
+ if (annotationType.isInstance(annotation)) {
+ return (A) annotation;
}
}
-
return null;
}
@@ -117,8 +115,7 @@ public class Package implements AnnotatedElement {
* @return the list of annotations
*/
// TODO(Google) Provide proper (native) implementation.
- private static native Annotation[] getDeclaredAnnotations(Package pkg,
- boolean publicOnly);
+ private static native Annotation[] getDeclaredAnnotations(Package pkg, boolean publicOnly);
/**
* Indicates whether the specified annotation is present.
@@ -129,8 +126,7 @@ public class Package implements AnnotatedElement {
* otherwise.
* @see java.lang.reflect.AnnotatedElement#isAnnotationPresent(java.lang.Class)
*/
- public boolean isAnnotationPresent(
- Class<? extends Annotation> annotationType) {
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return getAnnotation(annotationType) != null;
}
@@ -250,8 +246,7 @@ public class Package implements AnnotatedElement {
* if this package's version string or the one provided are not
* in the correct format.
*/
- public boolean isCompatibleWith(String version)
- throws NumberFormatException {
+ public boolean isCompatibleWith(String version) throws NumberFormatException {
String[] requested = version.split("\\.");
String[] provided = specVersion.split("\\.");
diff --git a/luni/src/main/java/java/lang/Process.java b/luni/src/main/java/java/lang/Process.java
index 5081f0f..13c4ed9 100644
--- a/luni/src/main/java/java/lang/Process.java
+++ b/luni/src/main/java/java/lang/Process.java
@@ -22,17 +22,47 @@ import java.io.OutputStream;
/**
* Represents an external process. Enables writing to, reading from, destroying,
- * and waiting for the external process, as well as querying its exit value.
+ * and waiting for the external process, as well as querying its exit value. Use
+ * {@link ProcessBuilder} to create processes.
*
- * @see Runtime#exec
- * @see ProcessBuilder#start()
+ * <p>The child process writes its output to two streams, {@code out} and
+ * {@code err}. These streams should be read by the parent process using {@link
+ * #getInputStream()} and {@link #getErrorStream()} respectively. If these
+ * streams are not read, the target process may block while it awaits buffer
+ * space. It isn't sufficient to read the streams in sequence; to avoid blocking
+ * each of the two streams must have its own reader thread. If you are not
+ * interested in differentiating the out and err streams, use {@link
+ * ProcessBuilder#redirectErrorStream(boolean) redirectErrorStream(true)} to
+ * merge the two streams. This simplifies your reading code and makes it easier
+ * to avoid blocking the target process.
+ *
+ * <p>Running processes hold resources. When a process is no longer used, the
+ * process should be closed by calling {@link #destroy}. This will kill the
+ * process and release the resources that it holds.
+ *
+ * <p>For example, to run {@code /system/bin/ping} to ping {@code android.com}:
+ * <pre> {@code
+ * Process process = new ProcessBuilder()
+ * .command("/system/bin/ping", "android.com")
+ * .redirectErrorStream(true)
+ * .start();
+ * try {
+ * InputStream in = process.getInputStream();
+ * OutputStream out = process.getOutputStream();
+ *
+ * readStream(in);
+ *
+ * } finally {
+ * process.destroy();
+ * }
+ * }</pre>
*/
public abstract class Process {
/**
* Terminates this process and closes any associated streams.
*/
- abstract public void destroy();
+ public abstract void destroy();
/**
* Returns the exit value of the native process represented by this object.
@@ -42,7 +72,7 @@ public abstract class Process {
* @throws IllegalThreadStateException
* if this process has not terminated.
*/
- abstract public int exitValue();
+ public abstract int exitValue();
/**
* Returns an input stream that is connected to the error stream
@@ -51,7 +81,7 @@ public abstract class Process {
* @return the input stream to read from the error stream associated with
* the native process.
*/
- abstract public InputStream getErrorStream();
+ public abstract InputStream getErrorStream();
/**
* Returns an input stream that is connected to the standard output stream
@@ -60,7 +90,7 @@ public abstract class Process {
* @return the input stream to read from the output stream associated with
* the native process.
*/
- abstract public InputStream getInputStream();
+ public abstract InputStream getInputStream();
/**
* Returns an output stream that is connected to the standard input stream
@@ -69,7 +99,7 @@ public abstract class Process {
* @return the output stream to write to the input stream associated with
* the native process.
*/
- abstract public OutputStream getOutputStream();
+ public abstract OutputStream getOutputStream();
/**
* Causes the calling thread to wait for the native process associated with
@@ -79,5 +109,5 @@ public abstract class Process {
* @throws InterruptedException
* if the calling thread is interrupted.
*/
- abstract public int waitFor() throws InterruptedException;
+ public abstract int waitFor() throws InterruptedException;
}
diff --git a/luni/src/main/java/java/lang/ProcessBuilder.java b/luni/src/main/java/java/lang/ProcessBuilder.java
index 504b79c..d63af8b 100644
--- a/luni/src/main/java/java/lang/ProcessBuilder.java
+++ b/luni/src/main/java/java/lang/ProcessBuilder.java
@@ -19,23 +19,20 @@ package java.lang;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
/**
- * Creates operating system processes.
- *
- * @since 1.5
+ * Creates operating system processes. See {@link Process} for documentation and
+ * example usage.
*/
public final class ProcessBuilder {
private List<String> command;
-
private File directory;
-
private Map<String, String> environment;
-
private boolean redirectErrorStream;
/**
@@ -46,7 +43,7 @@ public final class ProcessBuilder {
* the requested operating system program and its arguments.
*/
public ProcessBuilder(String... command) {
- this(toList(command));
+ this(new ArrayList<String>(Arrays.asList(command)));
}
/**
@@ -90,7 +87,7 @@ public final class ProcessBuilder {
* @return this process builder instance.
*/
public ProcessBuilder command(String... command) {
- return command(toList(command));
+ return command(new ArrayList<String>(Arrays.asList(command)));
}
/**
@@ -203,11 +200,4 @@ public final class ProcessBuilder {
// END android-changed
}
- private static List<String> toList(String[] strings) {
- ArrayList<String> arrayList = new ArrayList<String>(strings.length);
- for (String string : strings) {
- arrayList.add(string);
- }
- return arrayList;
- }
}
diff --git a/luni/src/main/java/java/lang/ProcessManager.java b/luni/src/main/java/java/lang/ProcessManager.java
index f54640a..5d8c059 100644
--- a/luni/src/main/java/java/lang/ProcessManager.java
+++ b/luni/src/main/java/java/lang/ProcessManager.java
@@ -67,15 +67,14 @@ final class ProcessManager {
* Map from pid to Process. We keep weak references to the Process objects
* and clean up the entries when no more external references are left. The
* process objects themselves don't require much memory, but file
- * descriptors (associated with stdin/out/err in this case) can be
+ * descriptors (associated with stdin/stdout/stderr in this case) can be
* a scarce resource.
*/
private final Map<Integer, ProcessReference> processReferences
= new HashMap<Integer, ProcessReference>();
/** Keeps track of garbage-collected Processes. */
- private final ProcessReferenceQueue referenceQueue
- = new ProcessReferenceQueue();
+ private final ProcessReferenceQueue referenceQueue = new ProcessReferenceQueue();
private ProcessManager() {
// Spawn a thread to listen for signals from child processes.
@@ -273,9 +272,12 @@ final class ProcessManager {
try {
kill(this.id);
} catch (IOException e) {
- Logger.getLogger(Runtime.class.getName()).log(Level.FINE,
+ Logger.getLogger(Process.class.getName()).log(Level.FINE,
"Failed to destroy process " + id + ".", e);
}
+ IoUtils.closeQuietly(inputStream);
+ IoUtils.closeQuietly(errorStream);
+ IoUtils.closeQuietly(outputStream);
}
public int exitValue() {
diff --git a/luni/src/main/java/java/lang/Runtime.java b/luni/src/main/java/java/lang/Runtime.java
index 835c109..7a98c45 100644
--- a/luni/src/main/java/java/lang/Runtime.java
+++ b/luni/src/main/java/java/lang/Runtime.java
@@ -109,10 +109,6 @@ public class Runtime {
mLibPaths[i] += fileSep;
}
}
-
- if (false) {
- System.out.println("Runtime paths: " + Arrays.toString(mLibPaths));
- }
}
/**
@@ -309,8 +305,8 @@ public class Runtime {
}
// Start all shutdown hooks concurrently
- for (int i = 0; i < hooks.length; i++) {
- hooks[i].start();
+ for (Thread hook : hooks) {
+ hook.start();
}
// Wait for all shutdown hooks to finish
@@ -551,7 +547,10 @@ public class Runtime {
@Deprecated
public InputStream getLocalizedInputStream(InputStream stream) {
String encoding = System.getProperty("file.encoding", "UTF-8");
- return encoding.equals("UTF-8") ? stream : new ReaderInputStream(stream, encoding);
+ if (!encoding.equals("UTF-8")) {
+ throw new UnsupportedOperationException("Cannot localize " + encoding);
+ }
+ return stream;
}
/**
@@ -568,7 +567,10 @@ public class Runtime {
@Deprecated
public OutputStream getLocalizedOutputStream(OutputStream stream) {
String encoding = System.getProperty("file.encoding", "UTF-8");
- return encoding.equals("UTF-8") ? stream : new WriterOutputStream(stream, encoding);
+ if (!encoding.equals("UTF-8")) {
+ throw new UnsupportedOperationException("Cannot localize " + encoding);
+ }
+ return stream;
}
/**
@@ -712,124 +714,4 @@ public class Runtime {
*/
public native long maxMemory();
-}
-
-/*
- * Internal helper class for creating a localized InputStream. A reader
- * wrapped in an InputStream.
- */
-class ReaderInputStream extends InputStream {
-
- private Reader reader;
-
- private Writer writer;
-
- ByteArrayOutputStream out = new ByteArrayOutputStream(256);
-
- private byte[] bytes;
-
- private int nextByte;
-
- private int numBytes;
-
- public ReaderInputStream(InputStream stream, String encoding) {
- try {
- reader = new InputStreamReader(stream, Charsets.UTF_8);
- writer = new OutputStreamWriter(out, encoding);
- } catch (UnsupportedEncodingException e) {
- // Should never happen, since UTF-8 and platform encoding must be
- // supported.
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public int read() throws IOException {
- if (nextByte >= numBytes) {
- readBuffer();
- }
-
- return (numBytes < 0) ? -1 : bytes[nextByte++];
- }
-
- private void readBuffer() throws IOException {
- char[] chars = new char[128];
- int read = reader.read(chars);
- if (read < 0) {
- numBytes = read;
- return;
- }
-
- writer.write(chars, 0, read);
- writer.flush();
- bytes = out.toByteArray();
- numBytes = bytes.length;
- nextByte = 0;
- }
-
-}
-
-/*
- * Internal helper class for creating a localized OutputStream. A writer
- * wrapped in an OutputStream. Bytes are written to characters in big-endian
- * fashion.
- */
-class WriterOutputStream extends OutputStream {
-
- private Reader reader;
-
- private Writer writer;
-
- private PipedOutputStream out;
-
- private PipedInputStream pipe;
-
- private int numBytes;
-
- public WriterOutputStream(OutputStream stream, String encoding) {
- try {
- // sink
- this.writer = new OutputStreamWriter(stream, encoding);
-
- // transcriber
- out = new PipedOutputStream();
- pipe = new PipedInputStream(out);
- this.reader = new InputStreamReader(pipe, Charsets.UTF_8);
-
- } catch (UnsupportedEncodingException e) {
- // Should never happen, since platform encoding must be supported.
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void write(int b) throws IOException {
- out.write(b);
- if( ++numBytes > 256) {
- flush();
- numBytes = 0;
- }
- }
-
- @Override
- public void flush() throws IOException {
- out.flush();
- char[] chars = new char[128];
- if (pipe.available() > 0) {
- int read = reader.read(chars);
- if (read > 0) {
- writer.write(chars, 0, read);
- }
- }
- writer.flush();
- }
-
- @Override
- public void close() throws IOException {
- out.close();
- flush();
- writer.close();
- }
-}
+} \ No newline at end of file
diff --git a/luni/src/main/java/java/lang/Short.java b/luni/src/main/java/java/lang/Short.java
index fd7bca0..2900d6f 100644
--- a/luni/src/main/java/java/lang/Short.java
+++ b/luni/src/main/java/java/lang/Short.java
@@ -66,7 +66,7 @@ public final class Short extends Number implements Comparable<Short> {
* @param string
* the string representation of a short value.
* @throws NumberFormatException
- * if {@code string} can not be decoded into a short value.
+ * if {@code string} cannot be parsed as a short value.
* @see #parseShort(String)
*/
public Short(String string) throws NumberFormatException {
@@ -118,7 +118,7 @@ public final class Short extends Number implements Comparable<Short> {
* @return a {@code Short} containing the value represented by
* {@code string}.
* @throws NumberFormatException
- * if {@code string} can not be parsed as a short value.
+ * if {@code string} cannot be parsed as a short value.
*/
public static Short decode(String string) throws NumberFormatException {
int intValue = Integer.decode(string).intValue();
@@ -126,7 +126,7 @@ public final class Short extends Number implements Comparable<Short> {
if (result == intValue) {
return valueOf(result);
}
- throw new NumberFormatException();
+ throw new NumberFormatException("Value out of range for short: \"" + string + "\"");
}
@Override
@@ -178,8 +178,7 @@ public final class Short extends Number implements Comparable<Short> {
* the string representation of a short value.
* @return the primitive short value represented by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a short value.
+ * if {@code string} cannot be parsed as a short value.
*/
public static short parseShort(String string) throws NumberFormatException {
return parseShort(string, 10);
@@ -196,19 +195,17 @@ public final class Short extends Number implements Comparable<Short> {
* @return the primitive short value represented by {@code string} using
* {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a short value.
+ * if {@code string} cannot be parsed as a short value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
*/
- public static short parseShort(String string, int radix)
- throws NumberFormatException {
+ public static short parseShort(String string, int radix) throws NumberFormatException {
int intValue = Integer.parseInt(string, radix);
short result = (short) intValue;
if (result == intValue) {
return result;
}
- throw new NumberFormatException();
+ throw new NumberFormatException("Value out of range for short: \"" + string + "\"");
}
/**
@@ -246,8 +243,7 @@ public final class Short extends Number implements Comparable<Short> {
* @return a {@code Short} instance containing the short value represented
* by {@code string}.
* @throws NumberFormatException
- * if {@code string} is {@code null}, has a length of zero or
- * can not be parsed as a short value.
+ * if {@code string} cannot be parsed as a short value.
* @see #parseShort(String)
*/
public static Short valueOf(String string) throws NumberFormatException {
@@ -265,14 +261,12 @@ public final class Short extends Number implements Comparable<Short> {
* @return a {@code Short} instance containing the short value represented
* by {@code string} using {@code radix}.
* @throws NumberFormatException
- * if {@code string} is {@code null} or has a length of zero,
- * {@code radix < Character.MIN_RADIX},
- * {@code radix > Character.MAX_RADIX}, or if {@code string}
- * can not be parsed as a short value.
+ * if {@code string} cannot be parsed as a short value, or
+ * {@code radix < Character.MIN_RADIX ||
+ * radix > Character.MAX_RADIX}.
* @see #parseShort(String, int)
*/
- public static Short valueOf(String string, int radix)
- throws NumberFormatException {
+ public static Short valueOf(String string, int radix) throws NumberFormatException {
return valueOf(parseShort(string, radix));
}
diff --git a/luni/src/main/java/java/lang/StackOverflowError.java b/luni/src/main/java/java/lang/StackOverflowError.java
index 0ca5ff0..5ac4fdc 100644
--- a/luni/src/main/java/java/lang/StackOverflowError.java
+++ b/luni/src/main/java/java/lang/StackOverflowError.java
@@ -18,12 +18,12 @@
package java.lang;
/**
- * Thrown when the depth of the callstack of the running program excedes some
+ * Thrown when the depth of the stack of the running program exceeds some
* platform or virtual machine specific limit. Typically, this will occur only
* when a program becomes infinitely recursive, but it can also occur in
* correctly written (but deeply recursive) programs.
*/
-public class StackOverflowError extends java.lang.VirtualMachineError {
+public class StackOverflowError extends VirtualMachineError {
private static final long serialVersionUID = 8609175038441759607L;
diff --git a/luni/src/main/java/java/lang/StrictMath.java b/luni/src/main/java/java/lang/StrictMath.java
index ef937cf..426fc2d 100644
--- a/luni/src/main/java/java/lang/StrictMath.java
+++ b/luni/src/main/java/java/lang/StrictMath.java
@@ -46,8 +46,6 @@ public final class StrictMath {
*/
public final static double PI = Math.PI;
- private static java.util.Random random;
-
/**
* Prevents this class from being instantiated.
*/
@@ -1210,14 +1208,14 @@ public final class StrictMath {
return bits << digits;
}
// change it to positive
- int absdigits = -digits;
- if (Integer.numberOfLeadingZeros(bits & ~Float.SIGN_MASK) <= (32 - absdigits)) {
+ int absDigits = -digits;
+ if (Integer.numberOfLeadingZeros(bits & ~Float.SIGN_MASK) <= (32 - absDigits)) {
// some bits will remain after shifting, calculates its carry
- if ((((bits >> (absdigits - 1)) & 0x1) == 0)
- || Integer.numberOfTrailingZeros(bits) == (absdigits - 1)) {
- return bits >> absdigits;
+ if ((((bits >> (absDigits - 1)) & 0x1) == 0)
+ || Integer.numberOfTrailingZeros(bits) == (absDigits - 1)) {
+ return bits >> absDigits;
}
- return ((bits >> absdigits) + 1);
+ return ((bits >> absDigits) + 1);
}
return 0;
}
@@ -1229,14 +1227,14 @@ public final class StrictMath {
return bits << digits;
}
// change it to positive
- long absdigits = -digits;
- if (Long.numberOfLeadingZeros(bits & ~Double.SIGN_MASK) <= (64 - absdigits)) {
+ long absDigits = -digits;
+ if (Long.numberOfLeadingZeros(bits & ~Double.SIGN_MASK) <= (64 - absDigits)) {
// some bits will remain after shifting, calculates its carry
- if ((((bits >> (absdigits - 1)) & 0x1) == 0)
- || Long.numberOfTrailingZeros(bits) == (absdigits - 1)) {
- return bits >> absdigits;
+ if ((((bits >> (absDigits - 1)) & 0x1) == 0)
+ || Long.numberOfTrailingZeros(bits) == (absDigits - 1)) {
+ return bits >> absDigits;
}
- return ((bits >> absdigits) + 1);
+ return ((bits >> absDigits) + 1);
}
return 0;
}
diff --git a/luni/src/main/java/java/lang/String.java b/luni/src/main/java/java/lang/String.java
index 333909f..15c6886 100644
--- a/luni/src/main/java/java/lang/String.java
+++ b/luni/src/main/java/java/lang/String.java
@@ -28,6 +28,7 @@ import java.util.Comparator;
import java.util.Formatter;
import java.util.Locale;
import java.util.regex.Pattern;
+import libcore.base.EmptyArray;
/**
* An immutable sequence of characters/code units ({@code char}s). A
@@ -94,8 +95,6 @@ public final class String implements Serializable, Comparable<String>, CharSeque
*/
public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
- private static final char[] EMPTY_CHAR_ARRAY = new char[0];
-
private static final char[] ASCII;
static {
ASCII = new char[128];
@@ -116,7 +115,7 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* Creates an empty string.
*/
public String() {
- value = EMPTY_CHAR_ARRAY;
+ value = EmptyArray.CHAR;
offset = 0;
count = 0;
}
@@ -150,9 +149,8 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* @param high
* the high byte to use.
* @throws NullPointerException
- * when {@code data} is {@code null}.
- * @deprecated Use {@link #String(byte[])} or
- * {@link #String(byte[], String)} instead.
+ * if {@code data == null}.
+ * @deprecated Use {@link #String(byte[])} or {@link #String(byte[], String)} instead.
*/
@Deprecated
public String(byte[] data, int high) {
@@ -163,71 +161,47 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* Converts a subsequence of the byte array to a string using the system's
* {@link java.nio.charset.Charset#defaultCharset default charset}.
*
- * @param data
- * the byte array to convert to a string.
- * @param start
- * the starting offset in the byte array.
- * @param length
- * the number of bytes to convert.
* @throws NullPointerException
- * when {@code data} is {@code null}.
+ * if {@code data == null}.
* @throws IndexOutOfBoundsException
- * if {@code length < 0, start < 0} or {@code start + length >
- * data.length}.
+ * if {@code byteCount < 0 || offset < 0 || offset + byteCount > data.length}.
*/
- public String(byte[] data, int start, int length) {
- // start + length could overflow, start/length maybe MaxInt
- if (start >= 0 && 0 <= length && length <= data.length - start) {
- CharBuffer cb = Charset.defaultCharset().decode(ByteBuffer.wrap(data, start, length));
- count = cb.length();
- offset = 0;
- if (count > 0) {
- value = cb.array();
- } else {
- value = EMPTY_CHAR_ARRAY;
- }
+ public String(byte[] data, int offset, int byteCount) {
+ if ((offset | byteCount) < 0 || byteCount > data.length - offset) {
+ throw failedBoundsCheck(data.length, offset, byteCount);
+ }
+ CharBuffer cb = Charset.defaultCharset().decode(ByteBuffer.wrap(data, offset, byteCount));
+ this.count = cb.length();
+ this.offset = 0;
+ if (count > 0) {
+ value = cb.array();
} else {
- throw new StringIndexOutOfBoundsException();
+ value = EmptyArray.CHAR;
}
}
/**
* Converts the byte array to a string, setting the high byte of every
- * character to the specified value.
+ * character to {@code high}.
*
- * @param data
- * the byte array to convert to a string.
- * @param high
- * the high byte to use.
- * @param start
- * the starting offset in the byte array.
- * @param length
- * the number of bytes to convert.
* @throws NullPointerException
- * when {@code data} is {@code null}.
+ * if {@code data == null}.
* @throws IndexOutOfBoundsException
- * if {@code length < 0, start < 0} or
- * {@code start + length > data.length}
+ * if {@code byteCount < 0 || offset < 0 || offset + byteCount > data.length}
*
* @deprecated Use {@link #String(byte[], int, int)} instead.
*/
@Deprecated
- public String(byte[] data, int high, int start, int length) {
- if (data != null) {
- // start + length could overflow, start/length maybe MaxInt
- if (start >= 0 && 0 <= length && length <= data.length - start) {
- offset = 0;
- value = new char[length];
- count = length;
- high <<= 8;
- for (int i = 0; i < count; i++) {
- value[i] = (char) (high + (data[start++] & 0xff));
- }
- } else {
- throw new StringIndexOutOfBoundsException();
- }
- } else {
- throw new NullPointerException();
+ public String(byte[] data, int high, int offset, int byteCount) {
+ if ((offset | byteCount) < 0 || byteCount > data.length - offset) {
+ throw failedBoundsCheck(data.length, offset, byteCount);
+ }
+ this.offset = 0;
+ this.value = new char[byteCount];
+ this.count = byteCount;
+ high <<= 8;
+ for (int i = 0; i < count; i++) {
+ value[i] = (char) (high + (data[offset++] & 0xff));
}
}
@@ -237,24 +211,15 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* <p>The behavior when the bytes cannot be decoded by the named charset
* is unspecified. Use {@link java.nio.charset.CharsetDecoder} for more control.
*
- * @param data
- * the byte array to convert to a string.
- * @param start
- * the starting offset in the byte array.
- * @param length
- * the number of bytes to convert.
- * @param charsetName
- * the charset name.
* @throws NullPointerException
- * when {@code data} is {@code null}.
+ * if {@code data == null}.
* @throws IndexOutOfBoundsException
- * if {@code length < 0, start < 0} or {@code start + length >
- * data.length}.
+ * if {@code byteCount < 0 || offset < 0 || offset + byteCount > data.length}.
* @throws UnsupportedEncodingException
* if the named charset is not supported.
*/
- public String(byte[] data, int start, int length, String charsetName) throws UnsupportedEncodingException {
- this(data, start, length, Charset.forNameUEE(charsetName));
+ public String(byte[] data, int offset, int byteCount, String charsetName) throws UnsupportedEncodingException {
+ this(data, offset, byteCount, Charset.forNameUEE(charsetName));
}
/**
@@ -263,12 +228,8 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* <p>The behavior when the bytes cannot be decoded by the named charset
* is unspecified. Use {@link java.nio.charset.CharsetDecoder} for more control.
*
- * @param data
- * the byte array to convert to a string.
- * @param charsetName
- * the charset name.
* @throws NullPointerException
- * when {@code data} is {@code null}.
+ * if {@code data == null}.
* @throws UnsupportedEncodingException
* if {@code charsetName} is not supported.
*/
@@ -283,38 +244,16 @@ public final class String implements Serializable, Comparable<String>, CharSeque
* is to replace malformed input and unmappable characters with the charset's default
* replacement string. Use {@link java.nio.charset.CharsetDecoder} for more control.
*
- * @param data
- * the byte array to convert to a String
- * @param start
- * the starting offset in the byte array
- * @param length
- * the number of bytes to convert
- * @param charset
- * the charset
- *
* @throws IndexOutOfBoundsException
- * when <code>length &lt; 0, start &lt; 0</code> or
- * <code>start + length &gt; data.length</code>
+ * if {@code byteCount < 0 || offset < 0 || offset + byteCount > data.length}
* @throws NullPointerException
- * when data is null
- *
- * @see #getBytes()
- * @see #getBytes(int, int, byte[], int)
- * @see #getBytes(String)
- * @see #valueOf(boolean)
- * @see #valueOf(char)
- * @see #valueOf(char[])
- * @see #valueOf(char[], int, int)
- * @see #valueOf(double)
- * @see #valueOf(float)
- * @see #valueOf(int)
- * @see #valueOf(long)
- * @see #valueOf(Object)
+ * if {@code data == null}
+ *
* @since 1.6
*/
- public String(byte[] data, int start, int length, Charset charset) {
- if (start < 0 || length < 0 || length > data.length - start) {
- throw new StringIndexOutOfBoundsException();
+ public String(byte[] data, int offset, int byteCount, Charset charset) {
+ if ((offset | byteCount) < 0 || byteCount > data.length - offset) {
+ throw failedBoundsCheck(data.length, offset, byteCount);
}
// We inline UTF-8, ISO-8859-1, and US-ASCII decoders for speed and because 'count' and
@@ -322,9 +261,11 @@ public final class String implements Serializable, Comparable<String>, CharSeque
String canonicalCharsetName = charset.name();
if (canonicalCharsetName.equals("UTF-8")) {
byte[] d = data;
- char[] v = new char[length];
+ char[] v = new char[byteCount];
- int idx = start, last = start + length, s = 0;
+ int idx = offset;
+ int last = offset + byteCount;
+ int s = 0;
outer:
while (idx < last) {
byte b0 = d[idx++];
@@ -411,7 +352,7 @@ outer:
}
}
- if (s == length) {
+ if (s == byteCount) {
// We guessed right, so we can use our temporary array as-is.
this.offset = 0;
this.value = v;
@@ -425,16 +366,16 @@ outer:
}
} else if (canonicalCharsetName.equals("ISO-8859-1")) {
this.offset = 0;
- this.value = new char[length];
- this.count = length;
- Charsets.isoLatin1BytesToChars(data, start, length, value);
+ this.value = new char[byteCount];
+ this.count = byteCount;
+ Charsets.isoLatin1BytesToChars(data, offset, byteCount, value);
} else if (canonicalCharsetName.equals("US-ASCII")) {
this.offset = 0;
- this.value = new char[length];
- this.count = length;
- Charsets.asciiBytesToChars(data, start, length, value);
+ this.value = new char[byteCount];
+ this.count = byteCount;
+ Charsets.asciiBytesToChars(data, offset, byteCount, value);
} else {
- CharBuffer cb = charset.decode(ByteBuffer.wrap(data, start, length));
+ CharBuffer cb = charset.decode(ByteBuffer.wrap(data, offset, byteCount));
this.offset = 0;
this.count = cb.length();
if (count > 0) {
@@ -446,7 +387,7 @@ outer:
this.value = new char[count];
System.arraycopy(cb.array(), 0, value, 0, count);
} else {
- value = EMPTY_CHAR_ARRAY;
+ this.value = EmptyArray.CHAR;
}
}
}
@@ -455,19 +396,6 @@ outer:
* Converts the byte array to a String using the given charset.
*
* @throws NullPointerException if {@code data == null}
- *
- * @see #getBytes()
- * @see #getBytes(int, int, byte[], int)
- * @see #getBytes(String)
- * @see #valueOf(boolean)
- * @see #valueOf(char)
- * @see #valueOf(char[])
- * @see #valueOf(char[], int, int)
- * @see #valueOf(double)
- * @see #valueOf(float)
- * @see #valueOf(int)
- * @see #valueOf(long)
- * @see #valueOf(Object)
* @since 1.6
*/
public String(byte[] data, Charset charset) {
@@ -479,10 +407,7 @@ outer:
* character array. Modifying the character array after creating the string
* has no effect on the string.
*
- * @param data
- * the array of characters.
- * @throws NullPointerException
- * when {@code data} is {@code null}.
+ * @throws NullPointerException if {@code data == null}
*/
public String(char[] data) {
this(data, 0, data.length);
@@ -493,39 +418,29 @@ outer:
* character array. Modifying the character array after creating the string
* has no effect on the string.
*
- * @param data
- * the array of characters.
- * @param start
- * the starting offset in the character array.
- * @param length
- * the number of characters to use.
* @throws NullPointerException
- * when {@code data} is {@code null}.
+ * if {@code data == null}.
* @throws IndexOutOfBoundsException
- * if {@code length < 0, start < 0} or {@code start + length >
- * data.length}
- */
- public String(char[] data, int start, int length) {
- // range check everything so a new char[] is not created
- // start + length could overflow, start/length maybe MaxInt
- if (start >= 0 && 0 <= length && length <= data.length - start) {
- offset = 0;
- value = new char[length];
- count = length;
- System.arraycopy(data, start, value, 0, count);
- } else {
- throw new StringIndexOutOfBoundsException();
+ * if {@code charCount < 0 || offset < 0 || offset + charCount > data.length}
+ */
+ public String(char[] data, int offset, int charCount) {
+ if ((offset | charCount) < 0 || charCount > data.length - offset) {
+ throw failedBoundsCheck(data.length, offset, charCount);
}
+ this.offset = 0;
+ this.value = new char[charCount];
+ this.count = charCount;
+ System.arraycopy(data, offset, value, 0, count);
}
/*
- * Internal version of string constructor. Does not range check, null check,
- * or copy the character array.
+ * Internal version of the String(char[], int, int) constructor.
+ * Does not range check, null check, or copy the character array.
*/
- String(int start, int length, char[] data) {
- value = data;
- offset = start;
- count = length;
+ String(int offset, int charCount, char[] chars) {
+ this.value = chars;
+ this.offset = offset;
+ this.count = charCount;
}
/**
@@ -578,37 +493,26 @@ outer:
offset = 0;
System.arraycopy(s1.value, s1.offset, value, 0, s1.count);
System.arraycopy(s2.value, s2.offset, value, s1.count, s2.count);
- System.arraycopy(s3.value, s3.offset, value, s1.count + s2.count,
- s3.count);
+ System.arraycopy(s3.value, s3.offset, value, s1.count + s2.count, s3.count);
}
/**
* Creates a {@code String} from the contents of the specified
* {@code StringBuffer}.
- *
- * @param stringbuffer
- * the buffer to get the contents from.
*/
- public String(StringBuffer stringbuffer) {
+ public String(StringBuffer stringBuffer) {
offset = 0;
- synchronized (stringbuffer) {
- value = stringbuffer.shareValue();
- count = stringbuffer.length();
+ synchronized (stringBuffer) {
+ value = stringBuffer.shareValue();
+ count = stringBuffer.length();
}
}
/**
* Creates a {@code String} from the sub-array of Unicode code points.
*
- * @param codePoints
- * the array of Unicode code points to convert.
- * @param offset
- * the inclusive index into {@code codePoints} to begin
- * converting from.
- * @param count
- * the number of elements in {@code codePoints} to copy.
* @throws NullPointerException
- * if {@code codePoints} is {@code null}.
+ * if {@code codePoints == null}.
* @throws IllegalArgumentException
* if any of the elements of {@code codePoints} are not valid
* Unicode code points.
@@ -622,8 +526,8 @@ outer:
if (codePoints == null) {
throw new NullPointerException();
}
- if (offset < 0 || count < 0 || (long) offset + (long) count > codePoints.length) {
- throw new StringIndexOutOfBoundsException();
+ if ((offset | count) < 0 || count > codePoints.length - offset) {
+ throw failedBoundsCheck(codePoints.length, offset, count);
}
this.offset = 0;
this.value = new char[count * 2];
@@ -639,20 +543,18 @@ outer:
* Creates a {@code String} from the contents of the specified {@code
* StringBuilder}.
*
- * @param sb
- * the {@code StringBuilder} to copy the contents from.
* @throws NullPointerException
- * if {@code sb} is {@code null}.
+ * if {@code stringBuilder == null}.
* @since 1.5
*/
- public String(StringBuilder sb) {
- if (sb == null) {
- throw new NullPointerException();
+ public String(StringBuilder stringBuilder) {
+ if (stringBuilder == null) {
+ throw new NullPointerException("stringBuilder == null");
}
this.offset = 0;
- this.count = sb.length();
+ this.count = stringBuilder.length();
this.value = new char[this.count];
- sb.getChars(0, this.count, this.value, 0);
+ stringBuilder.getChars(0, this.count, this.value, 0);
}
/*
@@ -682,10 +584,22 @@ outer:
* if {@code index < 0} or {@code index >= length()}.
*/
public char charAt(int index) {
- if (0 <= index && index < count) {
+ if (index >= 0 && index < count) {
return value[offset + index];
}
- throw new StringIndexOutOfBoundsException();
+ throw indexAndLength(index);
+ }
+
+ private StringIndexOutOfBoundsException indexAndLength(int index) {
+ throw new StringIndexOutOfBoundsException("index=" + index + " length=" + count);
+ }
+
+ private StringIndexOutOfBoundsException startEndAndLength(int start, int end) {
+ throw new StringIndexOutOfBoundsException("start=" + start + " end=" + end + " length=" + count);
+ }
+
+ private StringIndexOutOfBoundsException failedBoundsCheck(int arrayLength, int offset, int count) {
+ throw new StringIndexOutOfBoundsException("array length=" + arrayLength + " offset=" + offset + " count=" + count);
}
// Optimized for ASCII
@@ -914,8 +828,8 @@ outer:
}
/**
- * Converts this string to a byte array, ignoring the high order bits of
- * each character.
+ * Mangles this string into a byte array by stripping the high order bits from
+ * each character. Use {@link #getBytes()} or {@link #getBytes(String)} instead.
*
* @param start
* the starting offset of characters to copy.
@@ -934,18 +848,17 @@ outer:
*/
@Deprecated
public void getBytes(int start, int end, byte[] data, int index) {
- if (0 <= start && start <= end && end <= count) {
+ if (start >= 0 && start <= end && end <= count) {
end += offset;
try {
for (int i = offset + start; i < end; i++) {
data[index++] = (byte) value[i];
}
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new StringIndexOutOfBoundsException();
+ } catch (ArrayIndexOutOfBoundsException ignored) {
}
- } else {
- throw new StringIndexOutOfBoundsException();
}
+ throw new StringIndexOutOfBoundsException("start=" + start + " end=" + end
+ + " data.length=" + data.length + " index=" + index + " length=" + count);
}
/**
@@ -991,6 +904,8 @@ outer:
return Charsets.toIsoLatin1Bytes(value, offset, count);
} else if (canonicalCharsetName.equals("US-ASCII")) {
return Charsets.toAsciiBytes(value, offset, count);
+ } else if (canonicalCharsetName.equals("UTF-16BE")) {
+ return Charsets.toBigEndianUtf16Bytes(value, offset, count);
} else {
CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count);
ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer());
@@ -1021,44 +936,39 @@ outer:
*/
public void getChars(int start, int end, char[] buffer, int index) {
// NOTE last character not copied!
- // Fast range check.
- if (0 <= start && start <= end && end <= count) {
+ if (start >= 0 && start <= end && end <= count) {
System.arraycopy(value, start + offset, buffer, index, end - start);
} else {
- throw new StringIndexOutOfBoundsException();
+ // We throw StringIndexOutOfBoundsException rather than System.arraycopy's AIOOBE.
+ throw new StringIndexOutOfBoundsException("start=" + start + " end=" + end +
+ " buffer.length=" + buffer.length + " index=" + index + " length=" + count);
}
}
- // BEGIN android-added
/**
* Version of getChars without bounds checks, for use by other classes
* within the java.lang package only. The caller is responsible for
- * ensuring that 0 <= start && start <= end && end <= count.
+ * ensuring that start >= 0 && start <= end && end <= count.
*/
void _getChars(int start, int end, char[] buffer, int index) {
// NOTE last character not copied!
System.arraycopy(value, start + offset, buffer, index, end - start);
}
- // END android-added
- @Override
- public int hashCode() {
- // BEGIN android-changed
+ @Override public int hashCode() {
int hash = hashCode;
if (hash == 0) {
- int multiplier = 1;
- int _offset = offset;
- int _count = count;
- char[] _value = value;
- for (int i = _offset + _count - 1; i >= _offset; i--) {
- hash += _value[i] * multiplier;
- int shifted = multiplier << 5;
- multiplier = shifted - multiplier;
+ if (count == 0) {
+ return 0;
+ }
+ final int end = count + offset;
+ final char[] chars = value;
+ for (int i = offset; i < end; ++i) {
+ hash = 31*hash + chars[i];
}
hashCode = hash;
}
return hash;
- // END android-changed
}
/**
@@ -1619,10 +1529,10 @@ outer:
if (start == 0) {
return this;
}
- if (0 <= start && start <= count) {
+ if (start >= 0 && start <= count) {
return new String(offset + start, count - start, value);
}
- throw new StringIndexOutOfBoundsException(start);
+ throw new StringIndexOutOfBoundsException("start=" + start + " length=" + count);
}
/**
@@ -1645,10 +1555,10 @@ outer:
}
// NOTE last character not copied!
// Fast range check.
- if (0 <= start && start <= end && end <= count) {
+ if (start >= 0 && start <= end && end <= count) {
return new String(offset + start, end - start, value);
}
- throw new StringIndexOutOfBoundsException();
+ throw startEndAndLength(start, end);
}
/**
@@ -1898,6 +1808,23 @@ outer:
}
/**
+ * Equivalent to {@code equals(new String(chars, offset, length))}.
+ *
+ * @hide
+ */
+ public boolean contentEquals(char[] chars, int offset, int length) {
+ if (count != length) {
+ return false;
+ }
+ for (int i = 0; i < length; i++) {
+ if (chars[offset + i] != value[this.offset + i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Compares a {@code CharSequence} to this {@code String} to determine if
* their contents are equal.
*
@@ -2049,7 +1976,7 @@ outer:
*/
public int codePointAt(int index) {
if (index < 0 || index >= count) {
- throw new StringIndexOutOfBoundsException();
+ throw indexAndLength(index);
}
return Character.codePointAt(value, offset + index, offset + count);
}
@@ -2063,30 +1990,30 @@ outer:
*/
public int codePointBefore(int index) {
if (index < 1 || index > count) {
- throw new StringIndexOutOfBoundsException();
+ throw indexAndLength(index);
}
return Character.codePointBefore(value, offset + index, offset);
}
/**
- * Calculates the number of Unicode code points between {@code beginIndex}
- * and {@code endIndex}.
+ * Calculates the number of Unicode code points between {@code start}
+ * and {@code end}.
*
- * @param beginIndex
+ * @param start
* the inclusive beginning index of the subsequence.
- * @param endIndex
+ * @param end
* the exclusive end index of the subsequence.
* @return the number of Unicode code points in the subsequence.
* @throws IndexOutOfBoundsException
- * if {@code beginIndex < 0 || endIndex > length() || beginIndex > endIndex}
+ * if {@code start < 0 || end > length() || start > end}
* @see Character#codePointCount(CharSequence, int, int)
* @since 1.5
*/
- public int codePointCount(int beginIndex, int endIndex) {
- if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
- throw new StringIndexOutOfBoundsException();
+ public int codePointCount(int start, int end) {
+ if (start < 0 || end > count || start > end) {
+ throw startEndAndLength(start, end);
}
- return Character.codePointCount(value, offset + beginIndex, endIndex - beginIndex);
+ return Character.codePointCount(value, offset + start, end - start);
}
/**
diff --git a/luni/src/main/java/java/lang/StringBuffer.java b/luni/src/main/java/java/lang/StringBuffer.java
index 4387f33..471c008 100644
--- a/luni/src/main/java/java/lang/StringBuffer.java
+++ b/luni/src/main/java/java/lang/StringBuffer.java
@@ -39,7 +39,7 @@ import java.io.Serializable;
* @see Appendable
* @see StringBuilder
* @see String
- * @see String.format
+ * @see String#format
* @since 1.0
*/
public final class StringBuffer extends AbstractStringBuilder implements
@@ -597,8 +597,7 @@ public final class StringBuffer extends AbstractStringBuilder implements
* length > chars.length}, {@code index < 0} or {@code index >
* length()}
*/
- public synchronized StringBuffer insert(int index, char[] chars, int start,
- int length) {
+ public synchronized StringBuffer insert(int index, char[] chars, int start, int length) {
insert0(index, chars, start, length);
return this;
}
diff --git a/luni/src/main/java/java/lang/StringBuilder.java b/luni/src/main/java/java/lang/StringBuilder.java
index 17f61b6..8aea930 100644
--- a/luni/src/main/java/java/lang/StringBuilder.java
+++ b/luni/src/main/java/java/lang/StringBuilder.java
@@ -38,7 +38,7 @@ import java.io.Serializable;
* @see Appendable
* @see StringBuffer
* @see String
- * @see String.format
+ * @see String#format
* @since 1.5
*/
public final class StringBuilder extends AbstractStringBuilder implements
diff --git a/luni/src/main/java/java/lang/StringIndexOutOfBoundsException.java b/luni/src/main/java/java/lang/StringIndexOutOfBoundsException.java
index 6275b09..6b7c929 100644
--- a/luni/src/main/java/java/lang/StringIndexOutOfBoundsException.java
+++ b/luni/src/main/java/java/lang/StringIndexOutOfBoundsException.java
@@ -55,4 +55,12 @@ public class StringIndexOutOfBoundsException extends IndexOutOfBoundsException {
public StringIndexOutOfBoundsException(String detailMessage) {
super(detailMessage);
}
+
+ /**
+ * Used internally for consistent high-quality error reporting.
+ * @hide
+ */
+ public StringIndexOutOfBoundsException(String s, int offset, int count) {
+ super("s.length()=" + s.length() + ", offset=" + offset + ", count=" + count);
+ }
}
diff --git a/luni/src/main/java/java/lang/System.java b/luni/src/main/java/java/lang/System.java
index 41e2c50..8ba0472 100644
--- a/luni/src/main/java/java/lang/System.java
+++ b/luni/src/main/java/java/lang/System.java
@@ -634,7 +634,7 @@ public final class System {
/**
- * The unmodifiable environment variables map. The System.getenv() specifies
+ * The unmodifiable environment variables map. System.getenv() specifies
* that this map must throw when queried with non-String keys values.
*/
static class SystemEnvironment extends AbstractMap<String, String> {
diff --git a/luni/src/main/java/java/lang/Thread.java b/luni/src/main/java/java/lang/Thread.java
index 980c841..e26ecf0 100644
--- a/luni/src/main/java/java/lang/Thread.java
+++ b/luni/src/main/java/java/lang/Thread.java
@@ -69,6 +69,7 @@ import org.apache.harmony.security.fortress.SecurityUtils;
*
*/
public class Thread implements Runnable {
+ private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
private static final int NANOS_PER_MILLI = 1000000;
@@ -735,7 +736,7 @@ public class Thread implements Runnable {
}
StackTraceElement ste[] = VMStack.getThreadStackTrace(this);
- return ste != null ? ste : new StackTraceElement[0];
+ return ste != null ? ste : EMPTY_STACK_TRACE;
}
/**
diff --git a/luni/src/main/java/java/lang/ThreadDeath.java b/luni/src/main/java/java/lang/ThreadDeath.java
index 3006865..3ffbb0a 100644
--- a/luni/src/main/java/java/lang/ThreadDeath.java
+++ b/luni/src/main/java/java/lang/ThreadDeath.java
@@ -27,7 +27,7 @@ public class ThreadDeath extends Error {
/**
* Constructs a new instance of this class. Note that in the case of
- * ThreadDeath, the stacktrace may <em>not</em> be filled in a way which
+ * ThreadDeath, the stack trace may <em>not</em> be filled in a way which
* allows a stack trace to be printed.
*/
public ThreadDeath() {
diff --git a/luni/src/main/java/java/lang/ThreadGroup.java b/luni/src/main/java/java/lang/ThreadGroup.java
index ca31d36..93e4a6d 100644
--- a/luni/src/main/java/java/lang/ThreadGroup.java
+++ b/luni/src/main/java/java/lang/ThreadGroup.java
@@ -17,6 +17,12 @@
package java.lang;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import libcore.base.CollectionUtils;
+
/**
* {@code ThreadGroup} is a means of organizing threads into a hierarchical structure.
* This class is obsolete. See <i>Effective Java</i> Item 73, "Avoid thread groups" for details.
@@ -26,38 +32,32 @@ package java.lang;
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
// Name of this ThreadGroup
- private String name;
- // BEGIN android-note
// VM needs this field name for debugging.
- // END android-note
+ private String name;
// Maximum priority for Threads inside this ThreadGroup
private int maxPriority = Thread.MAX_PRIORITY;
// The ThreadGroup to which this ThreadGroup belongs
- ThreadGroup parent;
- // BEGIN android-note
// VM needs this field name for debugging.
- // END android-note
-
- int numThreads;
+ final ThreadGroup parent;
- // The Threads this ThreadGroup contains
- private Thread[] childrenThreads = new Thread[5];
-
- // The number of children groups
- int numGroups;
-
- // The ThreadGroups this ThreadGroup contains
- private ThreadGroup[] childrenGroups = new ThreadGroup[3];
+ /**
+ * Weak references to the threads in this group.
+ * Access is guarded by synchronizing on this field.
+ */
+ private final List<WeakReference<Thread>> threadRefs = new ArrayList<WeakReference<Thread>>(5);
- // Locked when using the childrenGroups field
- private class ChildrenGroupsLock {}
- private Object childrenGroupsLock = new ChildrenGroupsLock();
+ /**
+ * View of the threads.
+ * Access is guarded by synchronizing on threadRefs.
+ */
+ private final Iterable<Thread> threads = CollectionUtils.dereferenceIterable(threadRefs, true);
- // Locked when using the childrenThreads field
- private class ChildrenThreadsLock {}
- private Object childrenThreadsLock = new ChildrenThreadsLock();
+ /**
+ * Thread groups. Access is guarded by synchronizing on this field.
+ */
+ private final List<ThreadGroup> groups = new ArrayList<ThreadGroup>(3);
// Whether this ThreadGroup is a daemon ThreadGroup or not
private boolean isDaemon;
@@ -65,21 +65,9 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
// Whether this ThreadGroup has already been destroyed or not
private boolean isDestroyed;
- // BEGIN android-added
/* the VM uses these directly; do not rename */
- static ThreadGroup mSystem = new ThreadGroup();
- static ThreadGroup mMain = new ThreadGroup(mSystem, "main");
- // END android-added
-
- // BEGIN android-removed
- // /**
- // * Used by the JVM to create the "system" ThreadGroup. Construct a
- // * ThreadGroup instance, and assign the name "system".
- // */
- // private ThreadGroup() {
- // name = "system";
- // }
- // END android-removed
+ static final ThreadGroup mSystem = new ThreadGroup();
+ static final ThreadGroup mMain = new ThreadGroup(mSystem, "main");
/**
* Constructs a new {@code ThreadGroup} with the given name. The new {@code ThreadGroup}
@@ -88,7 +76,7 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @param name the name
* @throws SecurityException if {@code checkAccess()} for the parent
* group fails with a SecurityException
- * @see java.lang.Thread#currentThread
+ * @see Thread#currentThread
*/
public ThreadGroup(String name) {
@@ -108,7 +96,6 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* destroyed already
*/
public ThreadGroup(ThreadGroup parent, String name) {
- super();
if (Thread.currentThread() != null) {
// If parent is null we must throw NullPointerException, but that
// will be done "for free" with the message send below
@@ -116,8 +103,9 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
}
this.name = name;
- this.setParent(parent);
+ this.parent = parent;
if (parent != null) {
+ parent.add(this);
this.setMaxPriority(parent.getMaxPriority());
if (parent.isDaemon()) {
this.setDaemon(true);
@@ -129,9 +117,9 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* Initialize the special "system" ThreadGroup. Was "main" in Harmony,
* but we have an additional group above that in Android.
*/
- ThreadGroup() {
+ private ThreadGroup() {
this.name = "system";
- this.setParent(null);
+ this.parent = null;
}
/**
@@ -141,21 +129,17 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @return the number of children
*/
public int activeCount() {
- // BEGIN android-changed
int count = 0;
- // Lock the children thread list
- synchronized (this.childrenThreadsLock) {
- for (int i = 0; i < numThreads; i++) {
- if(childrenThreads[i].isAlive()) {
+ synchronized (threadRefs) {
+ for (Thread thread : threads) {
+ if (thread.isAlive()) {
count++;
}
}
}
- // END android-changed
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- count += this.childrenGroups[i].activeCount();
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ count += group.activeCount();
}
}
return count;
@@ -169,39 +153,30 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
*/
public int activeGroupCount() {
int count = 0;
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
// One for this group & the subgroups
- count += 1 + this.childrenGroups[i].activeGroupCount();
+ count += 1 + group.activeGroupCount();
}
}
return count;
}
/**
- * Adds a {@code Thread} to this thread group. This should only be visible to class
- * java.lang.Thread, and should only be called when a new Thread is created
+ * Adds a {@code Thread} to this thread group. This should only be visible
+ * to class Thread, and should only be called when a new Thread is created
* and initialized by the constructor.
*
* @param thread Thread to add
* @throws IllegalThreadStateException if this group has been destroyed already
- * @see #remove(java.lang.Thread)
+ * @see #remove(Thread)
*/
final void add(Thread thread) throws IllegalThreadStateException {
- synchronized (this.childrenThreadsLock) {
- if (!isDestroyed) {
- if (childrenThreads.length == numThreads) {
- Thread[] newThreads = new Thread[childrenThreads.length * 2];
- System.arraycopy(childrenThreads, 0, newThreads, 0, numThreads);
- newThreads[numThreads++] = thread;
- childrenThreads = newThreads;
- } else {
- childrenThreads[numThreads++] = thread;
- }
- } else {
+ synchronized (threadRefs) {
+ if (isDestroyed) {
throw new IllegalThreadStateException();
}
+ threadRefs.add(new WeakReference<Thread>(thread));
}
}
@@ -212,19 +187,11 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @throws IllegalThreadStateException if this group has been destroyed already
*/
private void add(ThreadGroup g) throws IllegalThreadStateException {
- synchronized (this.childrenGroupsLock) {
- if (!isDestroyed) {
- if (childrenGroups.length == numGroups) {
- ThreadGroup[] newGroups = new ThreadGroup[childrenGroups.length * 2];
- System.arraycopy(childrenGroups, 0, newGroups, 0, numGroups);
- newGroups[numGroups++] = g;
- childrenGroups = newGroups;
- } else {
- childrenGroups[numGroups++] = g;
- }
- } else {
+ synchronized (groups) {
+ if (isDestroyed) {
throw new IllegalThreadStateException();
}
+ groups.add(g);
}
}
@@ -272,36 +239,31 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
public final void destroy() {
checkAccess();
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenThreadsLock) {
- synchronized (this.childrenGroupsLock) {
- // BEGIN android-added
- if (this.isDestroyed) {
+ synchronized (threadRefs) {
+ synchronized (groups) {
+ if (isDestroyed) {
throw new IllegalThreadStateException(
"Thread group was already destroyed: "
+ (this.name != null ? this.name : "n/a"));
}
- if (this.numThreads > 0) {
+ if (threads.iterator().hasNext()) {
throw new IllegalThreadStateException(
"Thread group still contains threads: "
+ (this.name != null ? this.name : "n/a"));
}
- // END android-added
- int toDestroy = numGroups;
// Call recursively for subgroups
- for (int i = 0; i < toDestroy; i++) {
+ while (!groups.isEmpty()) {
// We always get the first element - remember, when the
// child dies it removes itself from our collection. See
// below.
- this.childrenGroups[0].destroy();
+ groups.get(0).destroy();
}
if (parent != null) {
parent.remove(this);
}
- // Now that the ThreadGroup is really destroyed it can be tagged
- // as so
+ // Now that the ThreadGroup is really destroyed it can be tagged as so
this.isDestroyed = true;
}
}
@@ -317,10 +279,10 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
*/
private void destroyIfEmptyDaemon() {
// Has to be non-destroyed daemon to make sense
- synchronized (this.childrenThreadsLock) {
- if (isDaemon && !isDestroyed && numThreads == 0) {
- synchronized (this.childrenGroupsLock) {
- if (numGroups == 0) {
+ synchronized (threadRefs) {
+ if (isDaemon && !isDestroyed && !threads.iterator().hasNext()) {
+ synchronized (groups) {
+ if (groups.isEmpty()) {
destroy();
}
}
@@ -413,28 +375,37 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
boolean enumeratingThreads) {
checkAccess();
- Object[] immediateCollection = enumeratingThreads ? (Object[]) childrenThreads
- : (Object[]) childrenGroups;
- Object syncLock = enumeratingThreads ? childrenThreadsLock : childrenGroupsLock;
-
- synchronized (syncLock) { // Lock this subpart of the tree as we walk
- for (int i = enumeratingThreads ? numThreads : numGroups; --i >= 0;) {
- if (!enumeratingThreads || ((Thread) immediateCollection[i]).isAlive()) {
+ if (enumeratingThreads) {
+ synchronized (threadRefs) {
+ // walk the references directly so we can iterate in reverse order
+ for (int i = threadRefs.size() - 1; i >= 0; --i) {
+ Thread thread = threadRefs.get(i).get();
+ if (thread != null && thread.isAlive()) {
+ if (enumerationIndex >= enumeration.length) {
+ return enumerationIndex;
+ }
+ enumeration[enumerationIndex++] = thread;
+ }
+ }
+ }
+ } else {
+ synchronized (groups) {
+ for (int i = groups.size() - 1; i >= 0; --i) {
if (enumerationIndex >= enumeration.length) {
return enumerationIndex;
}
- enumeration[enumerationIndex++] = immediateCollection[i];
+ enumeration[enumerationIndex++] = groups.get(i);
}
}
}
- if (recurse) { // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
+ if (recurse) {
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
if (enumerationIndex >= enumeration.length) {
return enumerationIndex;
}
- enumerationIndex = childrenGroups[i].enumerateGeneric(enumeration, recurse,
+ enumerationIndex = group.enumerateGeneric(enumeration, recurse,
enumerationIndex, enumeratingThreads);
}
}
@@ -486,16 +457,14 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
*/
public final void interrupt() {
checkAccess();
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenThreadsLock) {
- for (int i = 0; i < numThreads; i++) {
- this.childrenThreads[i].interrupt();
+ synchronized (threadRefs) {
+ for (Thread thread : threads) {
+ thread.interrupt();
}
}
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- this.childrenGroups[i].interrupt();
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ group.interrupt();
}
}
}
@@ -543,30 +512,29 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* be output.
*/
private void list(int levels) {
- for (int i = 0; i < levels; i++) {
- System.out.print(" "); // 4 spaces for each level
- }
-
- // Print the receiver
+ indent(levels);
System.out.println(this.toString());
- // Print the children threads, with 1 extra indentation
- synchronized (this.childrenThreadsLock) {
- for (int i = 0; i < numThreads; i++) {
- // children get an extra indentation, 4 spaces for each level
- for (int j = 0; j <= levels; j++) {
- System.out.print(" ");
- }
- System.out.println(this.childrenThreads[i]);
+ ++levels;
+ synchronized (threadRefs) {
+ for (Thread thread : threads) {
+ indent(levels);
+ System.out.println(thread);
}
}
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- this.childrenGroups[i].list(levels + 1);
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ group.list(levels);
}
}
}
+ private void indent(int levels) {
+ for (int i = 0; i < levels; i++) {
+ System.out.print(" "); // 4 spaces for each level
+ }
+ }
+
/**
* Checks whether this thread group is a direct or indirect parent group of a
* given {@code ThreadGroup}.
@@ -586,21 +554,17 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
/**
* Removes a {@code Thread} from this group. This should only be visible to class
- * java.lang.Thread, and should only be called when a Thread dies.
+ * Thread, and should only be called when a Thread dies.
*
* @param thread Thread to remove
*
* @see #add(Thread)
*/
- final void remove(java.lang.Thread thread) {
- synchronized (this.childrenThreadsLock) {
- for (int i = 0; i < numThreads; i++) {
- if (childrenThreads[i].equals(thread)) {
- numThreads--;
- System
- .arraycopy(childrenThreads, i + 1, childrenThreads, i, numThreads
- - i);
- childrenThreads[numThreads] = null;
+ final void remove(Thread thread) {
+ synchronized (threadRefs) {
+ for (Iterator<Thread> i = threads.iterator(); i.hasNext(); ) {
+ if (i.next().equals(thread)) {
+ i.remove();
break;
}
}
@@ -617,12 +581,11 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @see #add(ThreadGroup)
*/
private void remove(ThreadGroup g) {
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- if (childrenGroups[i].equals(g)) {
- numGroups--;
- System.arraycopy(childrenGroups, i + 1, childrenGroups, i, numGroups - i);
- childrenGroups[numGroups] = null;
+ synchronized (groups) {
+ for (Iterator<ThreadGroup> i = groups.iterator(); i.hasNext(); ) {
+ ThreadGroup threadGroup = i.next();
+ if (threadGroup.equals(g)) {
+ i.remove();
break;
}
}
@@ -646,16 +609,14 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
@Deprecated
public final void resume() {
checkAccess();
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenThreadsLock) {
- for (int i = 0; i < numThreads; i++) {
- this.childrenThreads[i].resume();
+ synchronized (threadRefs) {
+ for (Thread thread : threads) {
+ thread.resume();
}
}
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- this.childrenGroups[i].resume();
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ group.resume();
}
}
}
@@ -703,35 +664,15 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
int parentPriority = parent == null ? newMax : parent.getMaxPriority();
this.maxPriority = parentPriority <= newMax ? parentPriority : newMax;
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- // ??? why not maxPriority
- for (int i = 0; i < numGroups; i++) {
- this.childrenGroups[i].setMaxPriority(newMax);
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ group.setMaxPriority(newMax);
}
}
}
}
/**
- * Sets the parent {@code ThreadGroup} of this thread group, and adds this
- * thread group to the parent's collection of immediate children (if {@code parent} is
- * not {@code null}).
- *
- * @param parent The parent ThreadGroup, or null to make this thread group
- * the root ThreadGroup
- *
- * @see #getParent
- * @see #parentOf
- */
- private void setParent(ThreadGroup parent) {
- if (parent != null) {
- parent.add(this);
- }
- this.parent = parent;
- }
-
- /**
* Stops every thread in this group and recursively in all its subgroups.
*
* @throws SecurityException if {@code this.checkAccess()} fails with
@@ -751,30 +692,24 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
}
}
- /**
- * @deprecated Requires deprecated method Thread.suspend().
- */
@SuppressWarnings("deprecation")
- @Deprecated
- private final boolean stopHelper() {
+ private boolean stopHelper() {
checkAccess();
boolean stopCurrent = false;
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenThreadsLock) {
+ synchronized (threadRefs) {
Thread current = Thread.currentThread();
- for (int i = 0; i < numThreads; i++) {
- if (this.childrenThreads[i] == current) {
+ for (Thread thread : threads) {
+ if (thread == current) {
stopCurrent = true;
} else {
- this.childrenThreads[i].stop();
+ thread.stop();
}
}
}
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- stopCurrent |= this.childrenGroups[i].stopHelper();
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ stopCurrent |= group.stopHelper();
}
}
return stopCurrent;
@@ -800,30 +735,24 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
}
}
- /**
- * @deprecated Requires deprecated method Thread.suspend().
- */
@SuppressWarnings("deprecation")
- @Deprecated
- private final boolean suspendHelper() {
+ private boolean suspendHelper() {
checkAccess();
boolean suspendCurrent = false;
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenThreadsLock) {
+ synchronized (threadRefs) {
Thread current = Thread.currentThread();
- for (int i = 0; i < numThreads; i++) {
- if (this.childrenThreads[i] == current) {
+ for (Thread thread : threads) {
+ if (thread == current) {
suspendCurrent = true;
} else {
- this.childrenThreads[i].suspend();
+ thread.suspend();
}
}
}
- // Lock this subpart of the tree as we walk
- synchronized (this.childrenGroupsLock) {
- for (int i = 0; i < numGroups; i++) {
- suspendCurrent |= this.childrenGroups[i].suspendHelper();
+ synchronized (groups) {
+ for (ThreadGroup group : groups) {
+ suspendCurrent |= group.suspendHelper();
}
}
return suspendCurrent;
@@ -831,8 +760,8 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
@Override
public String toString() {
- return getClass().getName() + "[name=" + this.getName() + ",maxPriority="
- + this.getMaxPriority() + "]";
+ return getClass().getName() + "[name=" + getName()
+ + ",maxPriority=" + getMaxPriority() + "]";
}
/**
@@ -846,7 +775,6 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @param e the uncaught exception itself
*/
public void uncaughtException(Thread t, Throwable e) {
- // BEGIN android-changed
if (parent != null) {
parent.uncaughtException(t, e);
} else if (Thread.getDefaultUncaughtExceptionHandler() != null) {
@@ -856,10 +784,8 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
// No parent group, has to be 'system' Thread Group
e.printStackTrace(System.err);
}
- // END android-changed
}
- // BEGIN android-added
/**
* Non-standard method for adding a thread to a group, required by Dalvik.
*
@@ -868,8 +794,8 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @throws IllegalThreadStateException if the thread has been destroyed
* already
*
- * @see #add(java.lang.Thread)
- * @see #removeThread(java.lang.Thread)
+ * @see #add(Thread)
+ * @see #removeThread(Thread)
*/
void addThread(Thread thread) throws IllegalThreadStateException {
add(thread);
@@ -883,11 +809,10 @@ public class ThreadGroup implements Thread.UncaughtExceptionHandler {
* @throws IllegalThreadStateException if the thread has been destroyed
* already
*
- * @see #remove(java.lang.Thread)
- * @see #addThread(java.lang.Thread)
+ * @see #remove(Thread)
+ * @see #addThread(Thread)
*/
void removeThread(Thread thread) throws IllegalThreadStateException {
remove(thread);
}
- // END android-added
}
diff --git a/luni/src/main/java/java/lang/ThreadLocal.java b/luni/src/main/java/java/lang/ThreadLocal.java
index 61e83b0..f2da519 100644
--- a/luni/src/main/java/java/lang/ThreadLocal.java
+++ b/luni/src/main/java/java/lang/ThreadLocal.java
@@ -16,12 +16,6 @@
package java.lang;
-/*
- * Android's thread local is not derived from Harmony's classlib. It is used in
- * Harmony's DRLVM, however, whose source is here:
- * http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/
- */
-
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.concurrent.atomic.AtomicInteger;
@@ -142,7 +136,7 @@ public class ThreadLocal<T> {
* We increment by Doug Lea's Magic Number(TM) (*2 since keys are in
* every other bucket) to help prevent clustering.
*/
- private final int hash = hashCounter.getAndAdd(0x61c88647 << 1);
+ private final int hash = hashCounter.getAndAdd(0x61c88647 * 2);
/**
* Per-thread map of ThreadLocal instances to values.
@@ -247,7 +241,7 @@ public class ThreadLocal<T> {
* Creates a new, empty table with the given capacity.
*/
private void initializeTable(int capacity) {
- this.table = new Object[capacity << 1];
+ this.table = new Object[capacity * 2];
this.mask = table.length - 1;
this.clean = 0;
this.maximumLoad = capacity * 2 / 3; // 2/3
@@ -322,7 +316,7 @@ public class ThreadLocal<T> {
if (size > (capacity >> 1)) {
// More than 1/2 filled w/ live entries.
// Double size.
- newCapacity = capacity << 1;
+ newCapacity = capacity * 2;
}
Object[] oldTable = this.table;
diff --git a/luni/src/main/java/java/lang/VMClassLoader.java b/luni/src/main/java/java/lang/VMClassLoader.java
index 7e890c5..afcec20 100644
--- a/luni/src/main/java/java/lang/VMClassLoader.java
+++ b/luni/src/main/java/java/lang/VMClassLoader.java
@@ -20,8 +20,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.NoSuchElementException;
+import java.util.List;
class VMClassLoader {
@@ -36,74 +35,51 @@ class VMClassLoader {
*/
static URL getResource(String name) {
int numEntries = getBootClassPathSize();
- int i;
-
- for (i = 0; i < numEntries; i++) {
+ for (int i = 0; i < numEntries; i++) {
String urlStr = getBootClassPathResource(name, i);
if (urlStr != null) {
try {
return new URL(urlStr);
- }
- catch (MalformedURLException mue) {
+ } catch (MalformedURLException mue) {
mue.printStackTrace();
// unexpected; keep going
}
}
}
-
return null;
}
/*
* Get an enumeration with all matching resources.
*/
- static Enumeration<URL> getResources(String name) {
- ArrayList<URL> list = null;
+ static List<URL> getResources(String name) {
+ ArrayList<URL> list = new ArrayList<URL>();
int numEntries = getBootClassPathSize();
- int i;
-
- for (i = 0; i < numEntries; i++) {
+ for (int i = 0; i < numEntries; i++) {
String urlStr = getBootClassPathResource(name, i);
if (urlStr != null) {
- if (list == null)
- list = new ArrayList<URL>();
-
try {
list.add(new URL(urlStr));
- }
- catch (MalformedURLException mue) {
+ } catch (MalformedURLException mue) {
mue.printStackTrace();
// unexpected; keep going
}
}
}
-
- if (list == null)
- return null;
- else
- return new EnumerateListArray<URL>(list);
+ return list;
}
/**
* Load class with bootstrap class loader.
*/
- native static Class loadClass(String name, boolean resolve)
- throws ClassNotFoundException;
+ native static Class loadClass(String name, boolean resolve) throws ClassNotFoundException;
native static Class getPrimitiveClass(char type);
- /*
- * TODO(Google) Ticket 156: Native implementation does nothing, just throws
- * OperationNotSupportedException.
- */
native static Class defineClass(ClassLoader cl, String name,
byte[] data, int offset, int len, ProtectionDomain pd)
throws ClassFormatError;
- /*
- * TODO(Google) Ticket 156: Native implementation does nothing, just throws
- * OperationNotSupportedException.
- */
native static Class defineClass(ClassLoader cl,
byte[] data, int offset, int len, ProtectionDomain pd)
throws ClassFormatError;
@@ -114,29 +90,6 @@ class VMClassLoader {
* Boot class path manipulation, for getResources().
*/
native private static int getBootClassPathSize();
- native private static String getBootClassPathResource(String name,
- int index);
-
- /*
- * Create an Enumeration for an ArrayList.
- */
- private static class EnumerateListArray<T> implements Enumeration<T> {
- private final ArrayList mList;
- private int i = 0;
-
- EnumerateListArray(ArrayList list) {
- mList = list;
- }
-
- public boolean hasMoreElements() {
- return i < mList.size();
- }
-
- public T nextElement() {
- if (i >= mList.size())
- throw new NoSuchElementException();
- return (T) mList.get(i++);
- }
- };
+ native private static String getBootClassPathResource(String name, int index);
}
diff --git a/luni/src/main/java/java/lang/VMThread.java b/luni/src/main/java/java/lang/VMThread.java
index 350f204..7beb301 100644
--- a/luni/src/main/java/java/lang/VMThread.java
+++ b/luni/src/main/java/java/lang/VMThread.java
@@ -19,8 +19,7 @@ package java.lang;
import java.util.logging.Level;
import java.util.logging.Logger;
-class VMThread
-{
+class VMThread {
Thread thread;
int vmData;
@@ -28,7 +27,7 @@ class VMThread
thread = t;
}
- native static void create(Thread t, long stacksize);
+ native static void create(Thread t, long stackSize);
static native Thread currentThread();
static native boolean interrupted();
@@ -41,13 +40,10 @@ class VMThread
/**
* Starts the VMThread (and thus the Java Thread) with the given
- * stacksize.
- *
- * @param stacksize
- * The desired stacksize.
+ * stack size.
*/
- void start(long stacksize) {
- VMThread.create(thread, stacksize);
+ void start(long stackSize) {
+ VMThread.create(thread, stackSize);
}
private static final String UNSUPPORTED_THREAD_METHOD
@@ -90,7 +86,7 @@ class VMThread
native int getStatus();
/**
- * Holds a mapping from native Thread statii to Java one. Required for
+ * Holds a mapping from native Thread statuses to Java one. Required for
* translating back the result of getStatus().
*/
static final Thread.State[] STATE_MAP = new Thread.State[] {
diff --git a/luni/src/main/java/java/lang/Void.java b/luni/src/main/java/java/lang/Void.java
index 56d7c74..2794bee 100644
--- a/luni/src/main/java/java/lang/Void.java
+++ b/luni/src/main/java/java/lang/Void.java
@@ -18,13 +18,14 @@
package java.lang;
import java.lang.reflect.Method;
+import libcore.base.EmptyArray;
/**
* Placeholder class for the Java keyword {@code void}.
*
* @since 1.1
*/
-public final class Void extends Object {
+public final class Void {
/**
* The {@link Class} object that represents the primitive type {@code void}.
@@ -36,14 +37,12 @@ public final class Void extends Object {
@SuppressWarnings("unchecked")
private static Class<Void> lookupType() {
- Class<?> voidType = null;
try {
- Method method = Runnable.class.getMethod("run", new Class[0]);
- voidType = method.getReturnType();
+ Method method = Runnable.class.getMethod("run", EmptyArray.CLASS);
+ return (Class<Void>) method.getReturnType();
} catch (Exception e) {
- throw new RuntimeException(e);
+ throw new AssertionError(e);
}
- return (Class<Void>) voidType;
}
private Void() {
diff --git a/luni/src/main/java/java/lang/reflect/AccessibleObject.java b/luni/src/main/java/java/lang/reflect/AccessibleObject.java
index 5d9e11c..33abc08 100644
--- a/luni/src/main/java/java/lang/reflect/AccessibleObject.java
+++ b/luni/src/main/java/java/lang/reflect/AccessibleObject.java
@@ -59,21 +59,6 @@ public class AccessibleObject implements AnnotatedElement {
// If true, object is accessible, bypassing normal security checks
boolean flag = false;
- /**
- * one dimensional array
- */
- private static final String DIMENSION_1 = "[]";
-
- /**
- * two dimensional array
- */
- private static final String DIMENSION_2 = "[][]";
-
- /**
- * three dimensional array
- */
- private static final String DIMENSION_3 = "[][][]";
-
// Holds a mapping from Java type names to native type codes.
static Hashtable<String, String> trans;
@@ -193,10 +178,12 @@ public class AccessibleObject implements AnnotatedElement {
if (annotationType == null) {
throw new NullPointerException();
}
- Annotation[] annos = getAnnotations();
- for (int i = annos.length-1; i >= 0; --i) {
- if (annos[i].annotationType() == annotationType) {
- return (T) annos[i];
+ Annotation[] annotations = getAnnotations();
+ for (int i = annotations.length-1; i >= 0; --i) {
+ if (annotations[i].annotationType() == annotationType) {
+ @SuppressWarnings("unchecked")
+ T result = (T) annotations[i];
+ return result;
}
}
return null;
@@ -243,10 +230,10 @@ public class AccessibleObject implements AnnotatedElement {
StringBuilder result = new StringBuilder();
if (types.length != 0) {
- result.append(types[0].getCanonicalName());
+ result.append(types[0].getName());
for (int i = 1; i < types.length; i++) {
result.append(',');
- result.append(types[i].getCanonicalName());
+ result.append(types[i].getName());
}
}
@@ -307,52 +294,14 @@ public class AccessibleObject implements AnnotatedElement {
* @throws NullPointerException if any of the arguments is null
*/
void appendArrayType(StringBuilder sb, Class<?> obj) {
- if (!obj.isArray()) {
- sb.append(obj.getName());
- return;
- }
- int dimensions = 1;
- Class simplified = obj.getComponentType();
- obj = simplified;
- while (simplified.isArray()) {
- obj = simplified;
+ int dimensions = 0;
+ while (obj.isArray()) {
+ obj = obj.getComponentType();
dimensions++;
}
sb.append(obj.getName());
- switch (dimensions) {
- case 1:
- sb.append(DIMENSION_1);
- break;
- case 2:
- sb.append(DIMENSION_2);
- break;
- case 3:
- sb.append(DIMENSION_3);
- break;
- default:
- for (; dimensions > 0; dimensions--) {
- sb.append(DIMENSION_1);
- }
- }
- }
-
- /**
- * Appends names of the specified array classes to the buffer. The array
- * elements may represent a simple type, a reference type or an array type.
- * Output format: java.lang.Object[], java.io.File, void
- *
- * @param sb buffer
- * @param objs array of classes to print the names
- *
- * @throws NullPointerException if any of the arguments is null
- */
- void appendArrayType(StringBuilder sb, Class[] objs) {
- if (objs.length > 0) {
- appendArrayType(sb, objs[0]);
- for (int i = 1; i < objs.length; i++) {
- sb.append(',');
- appendArrayType(sb, objs[i]);
- }
+ for (int d = 0; d < dimensions; d++) {
+ sb.append("[]");
}
}
diff --git a/luni/src/main/java/java/lang/reflect/Array.java b/luni/src/main/java/java/lang/reflect/Array.java
index 1e672d1..db0d426 100644
--- a/luni/src/main/java/java/lang/reflect/Array.java
+++ b/luni/src/main/java/java/lang/reflect/Array.java
@@ -47,14 +47,14 @@ public final class Array {
/**
* Returns the element of the array at the specified index. This reproduces
* the effect of {@code array[index]}. If the array component is a primitive
- * type, the result is automatically wrapped.
+ * type, the result is automatically boxed.
*
* @param array
* the array
* @param index
* the index
*
- * @return the requested element, possibly wrapped
+ * @return the requested element, possibly boxed
*
* @throws NullPointerException
* if the array is null
@@ -486,7 +486,7 @@ public final class Array {
/**
* Sets the element of the array at the specified index to the value. This
* reproduces the effect of {@code array[index] = value}. If the array
- * component is a primitive type, the value is automatically unwrapped.
+ * component is a primitive type, the value is automatically unboxed.
*
* @param array
* the array
diff --git a/luni/src/main/java/java/lang/reflect/Constructor.java b/luni/src/main/java/java/lang/reflect/Constructor.java
index fba433e..2a29822 100644
--- a/luni/src/main/java/java/lang/reflect/Constructor.java
+++ b/luni/src/main/java/java/lang/reflect/Constructor.java
@@ -34,6 +34,7 @@ package java.lang.reflect;
import dalvik.system.VMStack;
import java.lang.annotation.Annotation;
+import libcore.base.EmptyArray;
import org.apache.harmony.kernel.vm.StringUtils;
import org.apache.harmony.luni.lang.reflect.GenericSignatureParser;
import org.apache.harmony.luni.lang.reflect.ListOfTypes;
@@ -143,7 +144,7 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec
for (int i = 0; i < formalTypeParameters.length; i++) {
appendGenericType(sb, formalTypeParameters[i]);
if (i < formalTypeParameters.length - 1) {
- sb.append(", ");
+ sb.append(",");
}
}
sb.append("> ");
@@ -291,8 +292,9 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec
* @return the declared exception classes
*/
public Class<?>[] getExceptionTypes() {
- if (exceptionTypes == null)
- return new Class[0];
+ if (exceptionTypes == null) {
+ return EmptyArray.CLASS;
+ }
return exceptionTypes.clone();
}
@@ -381,7 +383,7 @@ public final class Constructor<T> extends AccessibleObject implements GenericDec
* <li>For each argument passed:
* <ul>
* <li>If the corresponding parameter type is a primitive type, the argument
- * is unwrapped. If the unwrapping fails, an IllegalArgumentException is
+ * is unboxed. If the unboxing fails, an IllegalArgumentException is
* thrown.</li>
* <li>If the resulting argument cannot be converted to the parameter type
* via a widening conversion, an IllegalArgumentException is thrown.</li>
diff --git a/luni/src/main/java/java/lang/reflect/Field.java b/luni/src/main/java/java/lang/reflect/Field.java
index ecdb93a..1d2726c 100644
--- a/luni/src/main/java/java/lang/reflect/Field.java
+++ b/luni/src/main/java/java/lang/reflect/Field.java
@@ -32,7 +32,6 @@
package java.lang.reflect;
-import dalvik.system.VMStack;
import java.lang.annotation.Annotation;
import org.apache.harmony.kernel.vm.StringUtils;
import org.apache.harmony.luni.lang.reflect.GenericSignatureParser;
@@ -209,23 +208,22 @@ public final class Field extends AccessibleObject implements Member {
/**
* Returns the value of the field in the specified object. This reproduces
* the effect of {@code object.fieldName}
- * <p>
- * If the type of this field is a primitive type, the field value is
- * automatically wrapped.
- * <p>
- * If this field is static, the object argument is ignored.
+ *
+ * <p>If the type of this field is a primitive type, the field value is
+ * automatically boxed.
+ *
+ * <p>If this field is static, the object argument is ignored.
* Otherwise, if the object is null, a NullPointerException is thrown. If
* the object is not an instance of the declaring class of the method, an
* IllegalArgumentException is thrown.
- * <p>
- * If this Field object is enforcing access control (see AccessibleObject)
+ *
+ * <p>If this Field object is enforcing access control (see AccessibleObject)
* and this field is not accessible from the current context, an
* IllegalAccessException is thrown.
- * <p>
*
* @param object
* the object to access
- * @return the field value, possibly wrapped
+ * @return the field value, possibly boxed
* @throws NullPointerException
* if the object is {@code null} and the field is non-static
* @throws IllegalArgumentException
@@ -527,18 +525,18 @@ public final class Field extends AccessibleObject implements Member {
/**
* Sets the value of the field in the specified object to the value. This
* reproduces the effect of {@code object.fieldName = value}
- * <p>
- * If this field is static, the object argument is ignored.
+ *
+ * <p>If this field is static, the object argument is ignored.
* Otherwise, if the object is {@code null}, a NullPointerException is
* thrown. If the object is not an instance of the declaring class of the
* method, an IllegalArgumentException is thrown.
- * <p>
- * If this Field object is enforcing access control (see AccessibleObject)
+ *
+ * <p>If this Field object is enforcing access control (see AccessibleObject)
* and this field is not accessible from the current context, an
* IllegalAccessException is thrown.
- * <p>
- * If the field type is a primitive type, the value is automatically
- * unwrapped. If the unwrap fails, an IllegalArgumentException is thrown. If
+ *
+ * <p>If the field type is a primitive type, the value is automatically
+ * unboxed. If the unboxing fails, an IllegalArgumentException is thrown. If
* the value cannot be converted to the field type via a widening
* conversion, an IllegalArgumentException is thrown.
*
@@ -839,7 +837,7 @@ public final class Field extends AccessibleObject implements Member {
if (result.length() != 0) {
result.append(' ');
}
- result.append(type.getName());
+ appendArrayType(result, type);
result.append(' ');
result.append(declaringClass.getName());
result.append('.');
diff --git a/luni/src/main/java/java/lang/reflect/InvocationHandler.java b/luni/src/main/java/java/lang/reflect/InvocationHandler.java
index c5bd7d2..330904e 100644
--- a/luni/src/main/java/java/lang/reflect/InvocationHandler.java
+++ b/luni/src/main/java/java/lang/reflect/InvocationHandler.java
@@ -46,10 +46,9 @@ public interface InvocationHandler {
* @param args
* an array of objects containing the parameters passed to the
* method, or {@code null} if no arguments are expected.
- * Primitive types are wrapped in the appropriate wrapper type
+ * Primitive types are boxed.
*
- * @return the result of executing the method. Primitive types need to be
- * wrapped in the appropriate wrapper type
+ * @return the result of executing the method. Primitive types are boxed.
*
* @throws Throwable
* the exception to throw from the invoked method on the proxy.
@@ -57,6 +56,5 @@ public interface InvocationHandler {
* of the invoked method or any unchecked exception type. If not
* then an {@code UndeclaredThrowableException} is thrown
*/
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable;
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable;
}
diff --git a/luni/src/main/java/java/lang/reflect/Method.java b/luni/src/main/java/java/lang/reflect/Method.java
index f46d76f..2e2c03f 100644
--- a/luni/src/main/java/java/lang/reflect/Method.java
+++ b/luni/src/main/java/java/lang/reflect/Method.java
@@ -34,6 +34,7 @@ package java.lang.reflect;
import java.lang.annotation.Annotation;
import java.util.Comparator;
+import libcore.base.EmptyArray;
import org.apache.harmony.kernel.vm.StringUtils;
import org.apache.harmony.luni.lang.reflect.GenericSignatureParser;
import org.apache.harmony.luni.lang.reflect.ListOfTypes;
@@ -174,7 +175,7 @@ public final class Method extends AccessibleObject implements GenericDeclaration
for (int i = 0; i < formalTypeParameters.length; i++) {
appendGenericType(sb, formalTypeParameters[i]);
if (i < formalTypeParameters.length - 1) {
- sb.append(", ");
+ sb.append(",");
}
}
sb.append("> ");
@@ -184,7 +185,7 @@ public final class Method extends AccessibleObject implements GenericDeclaration
sb.append(' ');
// append method name
appendArrayType(sb, getDeclaringClass());
- sb.append("."+getName());
+ sb.append(".").append(getName());
// append parameters
sb.append('(');
appendArrayGenericType(sb,
@@ -378,9 +379,8 @@ public final class Method extends AccessibleObject implements GenericDeclaration
*/
public Class<?>[] getExceptionTypes() {
if (exceptionTypes == null) {
- return new Class[0];
+ return EmptyArray.CLASS;
}
-
return exceptionTypes.clone();
}
@@ -444,73 +444,57 @@ public final class Method extends AccessibleObject implements GenericDeclaration
}
/**
- * Returns the result of dynamically invoking this method. This reproduces
- * the effect of {@code receiver.methodName(arg1, arg2, ... , argN)} This
- * method performs the following:
- * <ul>
- * <li>If this method is static, the receiver argument is ignored.</li>
- * <li>Otherwise, if the receiver is null, a NullPointerException is thrown.
- * </li>
- * <li>If the receiver is not an instance of the declaring class of the
- * method, an IllegalArgumentException is thrown.</li>
- * <li>If this Method object is enforcing access control (see
- * AccessibleObject) and this method is not accessible from the current
- * context, an IllegalAccessException is thrown.</li>
- * <li>If the number of arguments passed and the number of parameters do not
- * match, an IllegalArgumentException is thrown.</li>
- * <li>For each argument passed:
- * <ul>
- * <li>If the corresponding parameter type is a primitive type, the argument
- * is unwrapped. If the unwrapping fails, an IllegalArgumentException is
- * thrown.</li>
- * <li>If the resulting argument cannot be converted to the parameter type
- * via a widening conversion, an IllegalArgumentException is thrown.</li>
- * </ul>
- * <li>If this method is static, it is invoked directly. If it is
- * non-static, this method and the receiver are then used to perform a
- * standard dynamic method lookup. The resulting method is then invoked.</li>
- * <li>If an exception is thrown during the invocation it is caught and
- * wrapped in an InvocationTargetException. This exception is then thrown.</li>
- * <li>If the invocation completes normally, the return value itself is
+ * Returns the result of dynamically invoking this method. Equivalent to
+ * {@code receiver.methodName(arg1, arg2, ... , argN)}.
+ *
+ * <p>If the method is static, the receiver argument is ignored (and may be null).
+ *
+ * <p>If the method takes no arguments, you can pass {@code (Object[]) null} instead of
+ * allocating an empty array.
+ *
+ * <p>If you're calling a varargs method, you need to pass an {@code Object[]} for the
+ * varargs parameter: that conversion is usually done in {@code javac}, not the VM, and
+ * the reflection machinery does not do this for you. (It couldn't, because it would be
+ * ambiguous.)
+ *
+ * <p>Reflective method invocation follows the usual process for method lookup.
+ *
+ * <p>If an exception is thrown during the invocation it is caught and
+ * wrapped in an InvocationTargetException. This exception is then thrown.
+ *
+ * <p>If the invocation completes normally, the return value itself is
* returned. If the method is declared to return a primitive type, the
- * return value is first wrapped. If the return type is void, null is
- * returned.</li>
- * </ul>
+ * return value is boxed. If the return type is void, null is returned.
*
* @param receiver
- * the object on which to call this method
+ * the object on which to call this method (or null for static methods)
* @param args
* the arguments to the method
- *
- * @return the new, initialized, object
+ * @return the result
*
* @throws NullPointerException
- * if the receiver is null for a non-static method
+ * if {@code receiver == null} for a non-static method
* @throws IllegalAccessException
- * if this method is not accessible
+ * if this method is not accessible (see {@link AccessibleObject})
* @throws IllegalArgumentException
- * if an incorrect number of arguments are passed, the receiver
- * is incompatible with the declaring class, or an argument
- * could not be converted by a widening conversion
+ * if the number of arguments doesn't match the number of parameters, the receiver
+ * is incompatible with the declaring class, or an argument could not be unboxed
+ * or converted by a widening conversion to the corresponding parameter type
* @throws InvocationTargetException
* if an exception was thrown by the invoked method
- *
- * @see AccessibleObject
*/
public Object invoke(Object receiver, Object... args)
- throws IllegalAccessException, IllegalArgumentException,
- InvocationTargetException {
+ throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (args == null) {
- args = new Object[0];
+ args = EmptyArray.OBJECT;
}
-
- return invokeNative (receiver, args, declaringClass, parameterTypes, returnType, slot, flag);
+ return invokeNative(receiver, args, declaringClass, parameterTypes, returnType, slot, flag);
}
- private native Object invokeNative(Object obj, Object[] args, Class<?> declaringClass, Class<?>[] parameterTypes, Class<?> returnType, int slot, boolean noAccessCheck)
- throws IllegalAccessException,
- IllegalArgumentException,
- InvocationTargetException;
+ private native Object invokeNative(Object obj, Object[] args, Class<?> declaringClass,
+ Class<?>[] parameterTypes, Class<?> returnType, int slot, boolean noAccessCheck)
+ throws IllegalAccessException, IllegalArgumentException,
+ InvocationTargetException;
/**
* Returns a string containing a concise, human-readable description of this
diff --git a/luni/src/main/java/java/lang/reflect/ParameterizedType.java b/luni/src/main/java/java/lang/reflect/ParameterizedType.java
index e98827b..59b6e35 100644
--- a/luni/src/main/java/java/lang/reflect/ParameterizedType.java
+++ b/luni/src/main/java/java/lang/reflect/ParameterizedType.java
@@ -68,7 +68,7 @@ public interface ParameterizedType extends Type {
/**
* Returns the declaring type of this parameterized type.
* <p>
- * The raw type of {@code Set&lt;String&gt; field;} is {@code Set}.
+ * The raw type of {@code Set<String> field;} is {@code Set}.
*
* @return the raw type of this parameterized type
*/
diff --git a/luni/src/main/java/java/lang/reflect/TypeVariable.java b/luni/src/main/java/java/lang/reflect/TypeVariable.java
index 0ba57fb..6ab63db 100644
--- a/luni/src/main/java/java/lang/reflect/TypeVariable.java
+++ b/luni/src/main/java/java/lang/reflect/TypeVariable.java
@@ -18,9 +18,9 @@ package java.lang.reflect;
/**
* This interface represents a type variables such as {@code 'T'} in {@code
- * 'public interface Comparable&lt;T&gt;'}, the bounded {@code 'T'} in {@code
- * 'public interface A&lt;T extends Number&gt;'} or the multiple bounded {@code
- * 'T'} in {@code 'public interface B&lt;T extends Number & Cloneable&gt;'}.
+ * 'public interface Comparable<T>'}, the bounded {@code 'T'} in {@code
+ * 'public interface A<T extends Number>'} or the multiple bounded {@code
+ * 'T'} in {@code 'public interface B<T extends Number & Cloneable>'}.
*
* @param <D>
* the generic declaration that declares this type variable
diff --git a/luni/src/main/java/java/lang/reflect/WildcardType.java b/luni/src/main/java/java/lang/reflect/WildcardType.java
index affd526..31e1023 100644
--- a/luni/src/main/java/java/lang/reflect/WildcardType.java
+++ b/luni/src/main/java/java/lang/reflect/WildcardType.java
@@ -18,12 +18,21 @@
package java.lang.reflect;
/**
- * This interface represents a wildcard type, such as the simple wildcard
- * {@code '?'}, the upper bounded wildcard {@code '? extends Closeable'}, the
- * multiple upper bounded wildcard {@code '? extends Closeable & Flushable'} or
- * the lower bounded wildcard {@code '? super OutputStream'}.
+ * A pattern type, such as the upper bounded wildcard {@code
+ * ? extends Closeable} or the lower bounded wildcard {@code ? super String}.
*
- * @since 1.5
+ * <p>Although this interface permits an arbitrary number of upper and lower
+ * bounds, all wildcard types of Java language programs are in one of two forms:
+ * <ol>
+ * <li><strong>No lower bound and one upper bound.</strong> Such types are
+ * written like {@code ? extends java.lang.Number}. When the upper bound is
+ * {@code java.lang.Object}, the {@code extends java.lang.Object} suffix is
+ * optional: {@code Set<?>} is shorthand for {@code
+ * Set<? extends java.lang.Object>}.
+ * <li><strong>One lower bound and an upper bound of {@code
+ * java.lang.Object}.</strong> Such types are written like {@code
+ * ? super java.lang.String}.
+ * </ol>
*/
public interface WildcardType extends Type {
/**
diff --git a/luni/src/main/java/java/math/BigDecimal.java b/luni/src/main/java/java/math/BigDecimal.java
index f419897..dd3fb84 100644
--- a/luni/src/main/java/java/math/BigDecimal.java
+++ b/luni/src/main/java/java/math/BigDecimal.java
@@ -269,14 +269,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
* first index to be copied.
* @param len
* number of characters to be used.
- * @throws NullPointerException
- * if {@code in == null}.
- * @throws NumberFormatException
- * if {@code offset < 0} or {@code len <= 0} or {@code
- * offset+len-1 < 0} or {@code offset+len-1 >= in.length}.
* @throws NumberFormatException
- * if in does not contain a valid string representation of a big
- * decimal.
+ * if {@code offset < 0 || len <= 0 || offset+len-1 < 0 ||
+ * offset+len-1 >= in.length}, or if {@code in} does not
+ * contain a valid string representation of a big decimal.
*/
public BigDecimal(char[] in, int offset, int len) {
int begin = offset; // first index to be copied
@@ -289,7 +285,8 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
throw new NullPointerException();
}
if ((last >= in.length) || (offset < 0) || (len <= 0) || (last < 0)) {
- throw new NumberFormatException();
+ throw new NumberFormatException("Bad offset/length: offset=" + offset +
+ " len=" + len + " in.length=" + in.length);
}
unscaledBuffer = new StringBuilder(len);
int bufLength = 0;
@@ -301,8 +298,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
int counter = 0;
boolean wasNonZero = false;
// Accumulating all digits until a possible decimal point
- for (; (offset <= last) && (in[offset] != '.')
- && (in[offset] != 'e') && (in[offset] != 'E'); offset++) {
+ for (; (offset <= last) && (in[offset] != '.') && (in[offset] != 'e') && (in[offset] != 'E'); offset++) {
if (!wasNonZero) {
if (in[offset] == '0') {
counter++;
@@ -381,14 +377,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
* number of characters to be used.
* @param mc
* rounding mode and precision for the result of this operation.
- * @throws NullPointerException
- * if {@code in == null}.
- * @throws NumberFormatException
- * if {@code offset < 0} or {@code len <= 0} or {@code
- * offset+len-1 < 0} or {@code offset+len-1 >= in.length}.
* @throws NumberFormatException
- * if {@code in} does not contain a valid string representation
- * of a big decimal.
+ * if {@code offset < 0 || len <= 0 || offset+len-1 < 0 ||
+ * offset+len-1 >= in.length}, or if {@code in} does not
+ * contain a valid string representation of a big decimal.
* @throws ArithmeticException
* if {@code mc.precision > 0} and {@code mc.roundingMode ==
* UNNECESSARY} and the new big decimal cannot be represented
@@ -406,8 +398,6 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
* @param in
* array of characters containing the string representation of
* this {@code BigDecimal}.
- * @throws NullPointerException
- * if {@code in == null}.
* @throws NumberFormatException
* if {@code in} does not contain a valid string representation
* of a big decimal.
@@ -426,8 +416,6 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
* this {@code BigDecimal}.
* @param mc
* rounding mode and precision for the result of this operation.
- * @throws NullPointerException
- * if {@code in == null}.
* @throws NumberFormatException
* if {@code in} does not contain a valid string representation
* of a big decimal.
@@ -496,7 +484,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
*/
public BigDecimal(double val) {
if (Double.isInfinite(val) || Double.isNaN(val)) {
- throw new NumberFormatException("Infinity or NaN");
+ throw new NumberFormatException("Infinity or NaN: " + val);
}
long bits = Double.doubleToLongBits(val); // IEEE-754
long mantissa;
@@ -774,7 +762,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
*/
public static BigDecimal valueOf(double val) {
if (Double.isInfinite(val) || Double.isNaN(val)) {
- throw new NumberFormatException("Infinity or NaN");
+ throw new NumberFormatException("Infinity or NaN: " + val);
}
return new BigDecimal(Double.toString(val));
}
@@ -1001,10 +989,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
/* Let be: this = [u1,s1] and multiplicand = [u2,s2] so:
* this x multiplicand = [ s1 * s2 , s1 + s2 ] */
if(this.bitLength + multiplicand.bitLength < 64) {
- return valueOf(this.smallValue*multiplicand.smallValue,toIntScale(newScale));
+ return valueOf(this.smallValue*multiplicand.smallValue, safeLongToInt(newScale));
}
return new BigDecimal(this.getUnscaledValue().multiply(
- multiplicand.getUnscaledValue()), toIntScale(newScale));
+ multiplicand.getUnscaledValue()), safeLongToInt(newScale));
}
/**
@@ -1137,10 +1125,10 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
}
int sign = scaledDividend.signum() * scaledDivisor.signum();
int compRem; // 'compare to remainder'
- if(scaledDivisor.bitLength() < 63) { // 63 in order to avoid out of long after <<1
+ if(scaledDivisor.bitLength() < 63) { // 63 in order to avoid out of long after *2
long rem = remainder.longValue();
long divisor = scaledDivisor.longValue();
- compRem = longCompareTo(Math.abs(rem) << 1,Math.abs(divisor));
+ compRem = longCompareTo(Math.abs(rem) * 2,Math.abs(divisor));
// To look if there is a carry
compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0,
sign * (5 + compRem), roundingMode);
@@ -1169,7 +1157,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
if (remainder != 0) {
// Checking if: remainder * 2 >= scaledDivisor
int compRem; // 'compare to remainder'
- compRem = longCompareTo(Math.abs(remainder) << 1,Math.abs(scaledDivisor));
+ compRem = longCompareTo(Math.abs(remainder) * 2,Math.abs(scaledDivisor));
// To look if there is a carry
quotient += roundingBehavior(((int)quotient) & 1,
sign * (5 + compRem),
@@ -1296,7 +1284,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
p = p.negate();
}
// Checking if the new scale is out of range
- newScale = toIntScale(diffScale + Math.max(k, l));
+ newScale = safeLongToInt(diffScale + Math.max(k, l));
// k >= 0 and l >= 0 implies that k - l is in the 32-bit range
i = k - l;
@@ -1376,7 +1364,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
}
}
// To perform rounding
- return new BigDecimal(integerQuot, toIntScale(newScale), mc);
+ return new BigDecimal(integerQuot, safeLongToInt(newScale), mc);
}
/**
@@ -1439,7 +1427,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
}
return ((integralValue.signum() == 0)
? zeroScaledBy(newScale)
- : new BigDecimal(integralValue, toIntScale(newScale)));
+ : new BigDecimal(integralValue, safeLongToInt(newScale)));
}
/**
@@ -1546,7 +1534,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
if (resultPrecision > mcPrecision) {
throw new ArithmeticException("Division impossible");
}
- integralValue.scale = toIntScale(newScale);
+ integralValue.scale = safeLongToInt(newScale);
integralValue.setUnscaledValue(strippedBI);
return integralValue;
}
@@ -1675,7 +1663,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
long newScale = scale * (long)n;
// Let be: this = [u,s] so: this^n = [u^n, s*n]
return isZero() ? zeroScaledBy(newScale)
- : new BigDecimal(getUnscaledValue().pow(n), toIntScale(newScale));
+ : new BigDecimal(getUnscaledValue().pow(n), safeLongToInt(newScale));
}
/**
@@ -2041,15 +2029,16 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
*/
if(newScale >= 0) {
if(bitLength < 64) {
- return valueOf(smallValue,toIntScale(newScale));
+ return valueOf(smallValue, safeLongToInt(newScale));
}
- return new BigDecimal(getUnscaledValue(), toIntScale(newScale));
+ return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}
if(-newScale < MathUtils.LONG_POWERS_OF_TEN.length &&
bitLength + LONG_POWERS_OF_TEN_BIT_LENGTH[(int)-newScale] < 64 ) {
return valueOf(smallValue*MathUtils.LONG_POWERS_OF_TEN[(int)-newScale],0);
}
- return new BigDecimal(Multiplication.multiplyByTenPow(getUnscaledValue(),(int)-newScale), 0);
+ return new BigDecimal(Multiplication.multiplyByTenPow(
+ getUnscaledValue(), safeLongToInt(-newScale)), 0);
}
/**
@@ -2091,9 +2080,9 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
if( smallValue==0 ){
return zeroScaledBy( newScale );
}
- return valueOf(smallValue,toIntScale(newScale));
+ return valueOf(smallValue, safeLongToInt(newScale));
}
- return new BigDecimal(getUnscaledValue(), toIntScale(newScale));
+ return new BigDecimal(getUnscaledValue(), safeLongToInt(newScale));
}
/**
@@ -2141,7 +2130,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
i = 1;
}
}
- return new BigDecimal(strippedBI, toIntScale(newScale));
+ return new BigDecimal(strippedBI, safeLongToInt(newScale));
}
/**
@@ -2802,7 +2791,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
}
}
// To update all internal fields
- scale = toIntScale(newScale);
+ scale = safeLongToInt(newScale);
precision = mcPrecision;
setUnscaledValue(integerAndFraction[0]);
}
@@ -2831,7 +2820,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
// If the discarded fraction is non-zero perform rounding
if (fraction != 0) {
// To check if the discarded fraction >= 0.5
- compRem = longCompareTo(Math.abs(fraction) << 1,sizeOfFraction);
+ compRem = longCompareTo(Math.abs(fraction) * 2, sizeOfFraction);
// To look if there is a carry
integer += roundingBehavior( ((int)integer) & 1,
Long.signum(fraction) * (5 + compRem),
@@ -2843,7 +2832,7 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
}
}
// To update all internal fields
- scale = toIntScale(newScale);
+ scale = safeLongToInt(newScale);
precision = mc.getPrecision();
smallValue = integer;
bitLength = bitLength(integer);
@@ -2943,26 +2932,11 @@ public class BigDecimal extends Number implements Comparable<BigDecimal>, Serial
// END android-changed
}
- /**
- * It tests if a scale of type {@code long} fits in 32 bits. It
- * returns the same scale being casted to {@code int} type when is
- * possible, otherwise throws an exception.
- *
- * @param longScale
- * a 64 bit scale
- * @return a 32 bit scale when is possible
- * @throws ArithmeticException when {@code scale} doesn't
- * fit in {@code int} type
- * @see #scale
- */
- private static int toIntScale(long longScale) {
- if (longScale < Integer.MIN_VALUE) {
- throw new ArithmeticException("Overflow");
- } else if (longScale > Integer.MAX_VALUE) {
- throw new ArithmeticException("Underflow");
- } else {
- return (int)longScale;
+ private static int safeLongToInt(long longValue) {
+ if (longValue < Integer.MIN_VALUE || longValue > Integer.MAX_VALUE) {
+ throw new ArithmeticException("Out of int range: " + longValue);
}
+ return (int) longValue;
}
/**
diff --git a/luni/src/main/java/java/math/BigInt.java b/luni/src/main/java/java/math/BigInt.java
index 9955a1d..1768676 100644
--- a/luni/src/main/java/java/math/BigInt.java
+++ b/luni/src/main/java/java/math/BigInt.java
@@ -21,21 +21,17 @@ package java.math;
* Any Bit-Operations, including Shifting, solely regard the unsigned magnitude.
* Moreover BigInt objects are mutable and offer efficient in-place-operations.
*/
-class BigInt {
+final class BigInt {
/* Fields used for the internal representation. */
transient int bignum = 0;
- public void dispose() {
- if (this.bignum != 0) {
- NativeBN.BN_free(this.bignum);
- this.bignum = 0;
- }
- }
-
@Override protected void finalize() throws Throwable {
try {
- dispose();
+ if (this.bignum != 0) {
+ NativeBN.BN_free(this.bignum);
+ this.bignum = 0;
+ }
} finally {
super.finalize();
}
@@ -46,11 +42,11 @@ class BigInt {
return this.decString();
}
- public int getNativeBIGNUM() {
+ int getNativeBIGNUM() {
return this.bignum;
}
- public static int consumeErrors(StringBuilder sb) {
+ static int consumeErrors(StringBuilder sb) {
int cnt = 0;
int e, reason;
while ((e = NativeBN.ERR_get_error()) != 0) {
@@ -97,50 +93,54 @@ class BigInt {
}
- public static int cmp(BigInt a, BigInt b) {
+ static int cmp(BigInt a, BigInt b) {
return NativeBN.BN_cmp(a.bignum, b.bignum);
}
- public void putCopy(BigInt from) {
+ void putCopy(BigInt from) {
this.makeValid();
Check(NativeBN.BN_copy(this.bignum, from.bignum));
}
- public BigInt copy() {
+ BigInt copy() {
BigInt bi = new BigInt();
bi.putCopy(this);
return bi;
}
- public void putLongInt(long val) {
+ void putLongInt(long val) {
this.makeValid();
Check(NativeBN.putLongInt(this.bignum, val));
}
- public void putULongInt(long val, boolean neg) {
+ void putULongInt(long val, boolean neg) {
this.makeValid();
Check(NativeBN.putULongInt(this.bignum, val, neg));
}
- public void putDecString(String original) {
+ private NumberFormatException invalidBigInteger(String s) {
+ throw new NumberFormatException("Invalid BigInteger: " + s);
+ }
+
+ void putDecString(String original) {
String s = checkString(original, 10);
this.makeValid();
int usedLen = NativeBN.BN_dec2bn(this.bignum, s);
Check((usedLen > 0));
if (usedLen < s.length()) {
- throw new NumberFormatException(original);
+ throw invalidBigInteger(original);
}
}
- public void putHexString(String original) {
+ void putHexString(String original) {
String s = checkString(original, 16);
this.makeValid();
int usedLen = NativeBN.BN_hex2bn(this.bignum, s);
Check((usedLen > 0));
if (usedLen < s.length()) {
- throw new NumberFormatException(original);
+ throw invalidBigInteger(original);
}
}
@@ -151,7 +151,7 @@ class BigInt {
* ensure we comply with Java's rules.
* http://code.google.com/p/android/issues/detail?id=7036
*/
- public String checkString(String s, int base) {
+ String checkString(String s, int base) {
if (s == null) {
throw new NullPointerException();
}
@@ -171,13 +171,13 @@ class BigInt {
}
}
if (charCount - i == 0) {
- throw new NumberFormatException(s);
+ throw invalidBigInteger(s);
}
boolean nonAscii = false;
for (; i < charCount; ++i) {
char ch = s.charAt(i);
if (Character.digit(ch, base) == -1) {
- throw new NumberFormatException(s);
+ throw invalidBigInteger(s);
}
if (ch > 128) {
nonAscii = true;
@@ -203,159 +203,164 @@ class BigInt {
return result.toString();
}
- public void putBigEndian(byte[] a, boolean neg) {
+ void putBigEndian(byte[] a, boolean neg) {
this.makeValid();
Check(NativeBN.BN_bin2bn(a, a.length, neg, this.bignum));
}
- public void putLittleEndianInts(int[] a, boolean neg) {
+ void putLittleEndianInts(int[] a, boolean neg) {
this.makeValid();
Check(NativeBN.litEndInts2bn(a, a.length, neg, this.bignum));
}
- public void putBigEndianTwosComplement(byte[] a) {
+ void putBigEndianTwosComplement(byte[] a) {
this.makeValid();
Check(NativeBN.twosComp2bn(a, a.length, this.bignum));
}
- public long longInt() {
+ long longInt() {
return NativeBN.longInt(this.bignum);
}
- public String decString() {
+ String decString() {
return NativeBN.BN_bn2dec(this.bignum);
}
- public String hexString() {
+ String hexString() {
return NativeBN.BN_bn2hex(this.bignum);
}
- public byte[] bigEndianMagnitude() {
+ byte[] bigEndianMagnitude() {
return NativeBN.BN_bn2bin(this.bignum);
}
- public int[] littleEndianIntsMagnitude() {
+ int[] littleEndianIntsMagnitude() {
return NativeBN.bn2litEndInts(this.bignum);
}
- public int sign() {
+ int sign() {
return NativeBN.sign(this.bignum);
}
- public void setSign(int val) {
- if (val > 0) NativeBN.BN_set_negative(this.bignum, 0);
- else if (val < 0) NativeBN.BN_set_negative(this.bignum, 1);
+ void setSign(int val) {
+ if (val > 0) {
+ NativeBN.BN_set_negative(this.bignum, 0);
+ } else {
+ if (val < 0) NativeBN.BN_set_negative(this.bignum, 1);
+ }
}
- public boolean twosCompFitsIntoBytes(int desiredByteCount) {
+ boolean twosCompFitsIntoBytes(int desiredByteCount) {
int actualByteCount = (NativeBN.bitLength(this.bignum) + 7) / 8;
return actualByteCount <= desiredByteCount;
}
- public int bitLength() {
+ int bitLength() {
return NativeBN.bitLength(this.bignum);
}
- public boolean isBitSet(int n) {
+ boolean isBitSet(int n) {
return NativeBN.BN_is_bit_set(this.bignum, n);
}
// n > 0: shift left (multiply)
- public static BigInt shift(BigInt a, int n) {
+ static BigInt shift(BigInt a, int n) {
BigInt r = newBigInt();
Check(NativeBN.BN_shift(r.bignum, a.bignum, n));
return r;
}
- public void shift(int n) {
+ void shift(int n) {
Check(NativeBN.BN_shift(this.bignum, this.bignum, n));
}
- public void addPositiveInt(int w) {
+ void addPositiveInt(int w) {
Check(NativeBN.BN_add_word(this.bignum, w));
}
- public void multiplyByPositiveInt(int w) {
+ void multiplyByPositiveInt(int w) {
Check(NativeBN.BN_mul_word(this.bignum, w));
}
- public static int remainderByPositiveInt(BigInt a, int w) {
+ static int remainderByPositiveInt(BigInt a, int w) {
int rem = NativeBN.BN_mod_word(a.bignum, w);
Check(rem != -1);
return rem;
}
- public static BigInt addition(BigInt a, BigInt b) {
+ static BigInt addition(BigInt a, BigInt b) {
BigInt r = newBigInt();
Check(NativeBN.BN_add(r.bignum, a.bignum, b.bignum));
return r;
}
- public void add(BigInt a) {
+ void add(BigInt a) {
Check(NativeBN.BN_add(this.bignum, this.bignum, a.bignum));
}
- public static BigInt subtraction(BigInt a, BigInt b) {
+ static BigInt subtraction(BigInt a, BigInt b) {
BigInt r = newBigInt();
Check(NativeBN.BN_sub(r.bignum, a.bignum, b.bignum));
return r;
}
- public static BigInt gcd(BigInt a, BigInt b) {
+ static BigInt gcd(BigInt a, BigInt b) {
BigInt r = newBigInt();
Check(NativeBN.BN_gcd(r.bignum, a.bignum, b.bignum));
return r;
}
- public static BigInt product(BigInt a, BigInt b) {
+ static BigInt product(BigInt a, BigInt b) {
BigInt r = newBigInt();
Check(NativeBN.BN_mul(r.bignum, a.bignum, b.bignum));
return r;
}
- public static BigInt bigExp(BigInt a, BigInt p) {
+ static BigInt bigExp(BigInt a, BigInt p) {
// Sign of p is ignored!
BigInt r = newBigInt();
Check(NativeBN.BN_exp(r.bignum, a.bignum, p.bignum));
return r;
}
- public static BigInt exp(BigInt a, int p) {
+ static BigInt exp(BigInt a, int p) {
// Sign of p is ignored!
BigInt power = new BigInt();
power.putLongInt(p);
return bigExp(a, power);
// OPTIONAL:
-// public int BN_sqr(BigInteger r, BigInteger a, BN_CTX ctx);
- // int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
+ // int BN_sqr(BigInteger r, BigInteger a, BN_CTX ctx);
+ // int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
}
- public static void division(BigInt dividend, BigInt divisor,
+ static void division(BigInt dividend, BigInt divisor,
BigInt quotient, BigInt remainder) {
int quot, rem;
if (quotient != null) {
quotient.makeValid();
quot = quotient.bignum;
+ } else {
+ quot = 0;
}
- else quot = 0;
if (remainder != null) {
remainder.makeValid();
rem = remainder.bignum;
+ } else {
+ rem = 0;
}
- else rem = 0;
Check(NativeBN.BN_div(quot, rem, dividend.bignum, divisor.bignum));
}
- public static BigInt modulus(BigInt a, BigInt m) {
+ static BigInt modulus(BigInt a, BigInt m) {
// Sign of p is ignored! ?
BigInt r = newBigInt();
Check(NativeBN.BN_nnmod(r.bignum, a.bignum, m.bignum));
return r;
}
- public static BigInt modExp(BigInt a, BigInt p, BigInt m) {
+ static BigInt modExp(BigInt a, BigInt p, BigInt m) {
// Sign of p is ignored!
BigInt r = newBigInt();
Check(NativeBN.BN_mod_exp(r.bignum, a.bignum, p.bignum, m.bignum));
@@ -366,20 +371,20 @@ class BigInt {
}
- public static BigInt modInverse(BigInt a, BigInt m) {
+ static BigInt modInverse(BigInt a, BigInt m) {
BigInt r = newBigInt();
Check(NativeBN.BN_mod_inverse(r.bignum, a.bignum, m.bignum));
return r;
}
- public static BigInt generatePrimeDefault(int bitLength) {
+ static BigInt generatePrimeDefault(int bitLength) {
BigInt r = newBigInt();
Check(NativeBN.BN_generate_prime_ex(r.bignum, bitLength, false, 0, 0, 0));
return r;
}
- public boolean isPrime(int certainty) {
+ boolean isPrime(int certainty) {
return NativeBN.BN_is_prime_ex(bignum, certainty, 0);
}
}
diff --git a/luni/src/main/java/java/math/BigInteger.java b/luni/src/main/java/java/math/BigInteger.java
index 681a197..e75c8f2 100644
--- a/luni/src/main/java/java/math/BigInteger.java
+++ b/luni/src/main/java/java/math/BigInteger.java
@@ -217,7 +217,7 @@ public class BigInteger extends Number
setBigInt(bigInt);
} else {
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
- throw new NumberFormatException("bad radix: " + radix);
+ throw new NumberFormatException("Invalid radix: " + radix);
}
if (value.isEmpty()) {
throw new NumberFormatException("value.isEmpty()");
@@ -243,7 +243,7 @@ public class BigInteger extends Number
throw new NullPointerException("magnitude == null");
}
if (signum < -1 || signum > 1) {
- throw new NumberFormatException("bad signum: " + signum);
+ throw new NumberFormatException("Invalid signum: " + signum);
}
if (signum == 0) {
for (byte element : magnitude) {
diff --git a/luni/src/main/java/java/math/MathContext.java b/luni/src/main/java/java/math/MathContext.java
index 1e8e430..1231bc6 100644
--- a/luni/src/main/java/java/math/MathContext.java
+++ b/luni/src/main/java/java/math/MathContext.java
@@ -276,9 +276,9 @@ public final class MathContext implements Serializable {
* Returns the string representation for this {@code MathContext} instance.
* The string has the form
* {@code
- * "precision=&lt;precision&gt; roundingMode=&lt;roundingMode&gt;"
- * } where {@code &lt;precision&gt;} is an integer describing the number
- * of digits used for operations and {@code &lt;roundingMode&gt;} is the
+ * "precision=<precision> roundingMode=<roundingMode>"
+ * } where {@code <precision>} is an integer describing the number
+ * of digits used for operations and {@code <roundingMode>} is the
* string representation of the rounding mode.
*
* @return a string representation for this {@code MathContext} instance
diff --git a/luni/src/main/java/java/net/AddressCache.java b/luni/src/main/java/java/net/AddressCache.java
index 063c9e0..cbde9a4 100644
--- a/luni/src/main/java/java/net/AddressCache.java
+++ b/luni/src/main/java/java/net/AddressCache.java
@@ -40,15 +40,13 @@ class AddressCache {
// Default time-to-live for negative cache entries. 10 seconds.
private static final long DEFAULT_NEGATIVE_TTL_NANOS = 10 * 1000000000L;
- // Failed lookups are represented in the cache my mappings to this empty array.
- private static final InetAddress[] NO_ADDRESSES = new InetAddress[0];
-
// The actual cache.
private final Map<String, AddressCacheEntry> map;
static class AddressCacheEntry {
- // The addresses. May be the empty array for a negative cache entry.
- InetAddress[] addresses;
+ // Either an InetAddress[] for a positive entry,
+ // or a String detail message for a negative entry.
+ final Object value;
/**
* The absolute expiry time in nanoseconds. Nanoseconds from System.nanoTime is ideal
@@ -56,10 +54,10 @@ class AddressCache {
*
* Unless we need to cope with DNS TTLs of 292 years, we don't need to worry about overflow.
*/
- long expiryNanos;
+ final long expiryNanos;
- AddressCacheEntry(InetAddress[] addresses, long expiryNanos) {
- this.addresses = addresses;
+ AddressCacheEntry(Object value, long expiryNanos) {
+ this.value = value;
this.expiryNanos = expiryNanos;
}
}
@@ -77,17 +75,27 @@ class AddressCache {
}
/**
- * Returns the cached addresses associated with 'hostname'. Returns null if nothing is known
- * about 'hostname'. Returns an empty array if 'hostname' is known not to exist.
+ * Removes all entries from the cache.
*/
- public InetAddress[] get(String hostname) {
+ public void clear() {
+ synchronized (map) {
+ map.clear();
+ }
+ }
+
+ /**
+ * Returns the cached InetAddress[] associated with 'hostname'. Returns null if nothing is known
+ * about 'hostname'. Returns a String suitable for use as an UnknownHostException detail
+ * message if 'hostname' is known not to exist.
+ */
+ public Object get(String hostname) {
AddressCacheEntry entry;
synchronized (map) {
entry = map.get(hostname);
}
// Do we have a valid cache entry?
if (entry != null && entry.expiryNanos >= System.nanoTime()) {
- return entry.addresses;
+ return entry.value;
}
// Either we didn't find anything, or it had expired.
// No need to remove expired entries: the caller will provide a replacement shortly.
@@ -99,8 +107,23 @@ class AddressCache {
* certain length of time.
*/
public void put(String hostname, InetAddress[] addresses) {
+ put(hostname, addresses, true);
+ }
+
+ /**
+ * Associates the given 'detailMessage' with 'hostname'. The association will expire after a
+ * certain length of time.
+ */
+ public void put(String hostname, String detailMessage) {
+ put(hostname, detailMessage, false);
+ }
+
+ /**
+ * Associates the given 'addresses' with 'hostname'. The association will expire after a
+ * certain length of time.
+ */
+ public void put(String hostname, Object value, boolean isPositive) {
// Calculate the expiry time.
- boolean isPositive = (addresses.length > 0);
String propertyName = isPositive ? "networkaddress.cache.ttl" : "networkaddress.cache.negative.ttl";
long defaultTtlNanos = isPositive ? DEFAULT_POSITIVE_TTL_NANOS : DEFAULT_NEGATIVE_TTL_NANOS;
// Fast-path the default case...
@@ -114,7 +137,7 @@ class AddressCache {
}
// Update the cache.
synchronized (map) {
- map.put(hostname, new AddressCacheEntry(addresses, expiryNanos));
+ map.put(hostname, new AddressCacheEntry(value, expiryNanos));
}
}
@@ -122,8 +145,8 @@ class AddressCache {
* Records that 'hostname' is known not to have any associated addresses. (I.e. insert a
* negative cache entry.)
*/
- public void putUnknownHost(String hostname) {
- put(hostname, NO_ADDRESSES);
+ public void putUnknownHost(String hostname, String detailMessage) {
+ put(hostname, detailMessage);
}
private long customTtl(String propertyName, long defaultTtlNanos) {
diff --git a/luni/src/main/java/java/net/Authenticator.java b/luni/src/main/java/java/net/Authenticator.java
index 903f170..3b5fd8c 100644
--- a/luni/src/main/java/java/net/Authenticator.java
+++ b/luni/src/main/java/java/net/Authenticator.java
@@ -272,10 +272,10 @@ public abstract class Authenticator {
String rPrompt, String rScheme, URL rURL,
Authenticator.RequestorType reqType) {
SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
+ if (sm != null) {
sm.checkPermission(requestPasswordAuthenticationPermission);
}
- if (null == thisAuthenticator) {
+ if (thisAuthenticator == null) {
return null;
}
// sets the requester info so it knows what it is requesting
diff --git a/luni/src/main/java/java/net/CookieHandler.java b/luni/src/main/java/java/net/CookieHandler.java
index d3cbb5a..918c34a 100644
--- a/luni/src/main/java/java/net/CookieHandler.java
+++ b/luni/src/main/java/java/net/CookieHandler.java
@@ -40,7 +40,7 @@ public abstract class CookieHandler {
*/
public static CookieHandler getDefault() {
SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
+ if (sm != null) {
sm.checkPermission(getCookieHandlerPermission);
}
return systemWideCookieHandler;
@@ -54,7 +54,7 @@ public abstract class CookieHandler {
*/
public static void setDefault(CookieHandler cHandler) {
SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
+ if (sm != null) {
sm.checkPermission(setCookieHandlerPermission);
}
systemWideCookieHandler = cHandler;
diff --git a/luni/src/main/java/java/net/DatagramPacket.java b/luni/src/main/java/java/net/DatagramPacket.java
index 36ec922..8e7d6fa 100644
--- a/luni/src/main/java/java/net/DatagramPacket.java
+++ b/luni/src/main/java/java/net/DatagramPacket.java
@@ -178,24 +178,15 @@ public final class DatagramPacket {
/**
* Sets the data buffer for this datagram packet.
- *
- * @param buf
- * the buffer to store the data.
- * @param anOffset
- * the buffer offset where the data is stored.
- * @param aLength
- * the length of the data to be sent or the length of buffer to
- * store the received data.
*/
- public synchronized void setData(byte[] buf, int anOffset, int aLength) {
- if (0 > anOffset || anOffset > buf.length || 0 > aLength
- || aLength > buf.length - anOffset) {
+ public synchronized void setData(byte[] data, int offset, int byteCount) {
+ if ((offset | byteCount) < 0 || offset > data.length || byteCount > data.length - offset) {
throw new IllegalArgumentException();
}
- data = buf;
- offset = anOffset;
- length = aLength;
- capacity = aLength;
+ this.data = data;
+ this.offset = offset;
+ this.length = byteCount;
+ this.capacity = byteCount;
}
/**
@@ -225,15 +216,12 @@ public final class DatagramPacket {
* Sets the length of the datagram packet. This length plus the offset must
* be lesser than or equal to the buffer size.
*
- * @param len
+ * @param length
* the length of this datagram packet.
*/
- public synchronized void setLength(int len) {
- if (0 > len || offset + len > data.length) {
- throw new IndexOutOfBoundsException();
- }
- length = len;
- capacity = len;
+ public synchronized void setLength(int length) {
+ setLengthOnly(length);
+ this.capacity = length;
}
/**
@@ -242,11 +230,12 @@ public final class DatagramPacket {
*
* @param len the length of this datagram packet
*/
- synchronized void setLengthOnly(int len) {
- if (0 > len || offset + len > data.length) {
- throw new IndexOutOfBoundsException();
+ synchronized void setLengthOnly(int length) {
+ if (length < 0 || offset + length > data.length) {
+ throw new IndexOutOfBoundsException("length=" + length + ", offset=" + offset +
+ ", buffer size=" + data.length);
}
- length = len;
+ this.length = length;
}
/**
@@ -277,8 +266,7 @@ public final class DatagramPacket {
* @throws SocketException
* if an error in the underlying protocol occurs.
*/
- public DatagramPacket(byte[] data, int length, SocketAddress sockAddr)
- throws SocketException {
+ public DatagramPacket(byte[] data, int length, SocketAddress sockAddr) throws SocketException {
this(data, 0, length);
setSocketAddress(sockAddr);
}
@@ -328,6 +316,9 @@ public final class DatagramPacket {
(sockAddr == null ? null : sockAddr.getClass()));
}
InetSocketAddress inetAddr = (InetSocketAddress) sockAddr;
+ if (inetAddr.isUnresolved()) {
+ throw new IllegalArgumentException("Socket address unresolved: " + sockAddr);
+ }
port = inetAddr.getPort();
address = inetAddr.getAddress();
}
diff --git a/luni/src/main/java/java/net/DatagramSocket.java b/luni/src/main/java/java/net/DatagramSocket.java
index 532b53d..5237e49 100644
--- a/luni/src/main/java/java/net/DatagramSocket.java
+++ b/luni/src/main/java/java/net/DatagramSocket.java
@@ -45,10 +45,7 @@ public class DatagramSocket {
private boolean isClosed = false;
- private static class Lock {
- }
-
- private Object lock = new Lock();
+ private Object lock = new Object();
/**
* Constructs a UDP datagram socket which is bound to any available port on
@@ -92,7 +89,7 @@ public class DatagramSocket {
public DatagramSocket(int aPort, InetAddress addr) throws SocketException {
super();
checkListen(aPort);
- createSocket(aPort, null == addr ? Inet4Address.ANY : addr);
+ createSocket(aPort, (addr == null) ? Inet4Address.ANY : addr);
}
/**
@@ -271,11 +268,7 @@ public class DatagramSocket {
}
/**
- * Gets the socket receive buffer size. ( {@code SocketOptions.SO_RCVBUF} )
- *
- * @return the input buffer size.
- * @throws SocketException
- * if an error occurs while getting the option value.
+ * Returns this socket's {@link SocketOptions#SO_RCVBUF receive buffer size}.
*/
public synchronized int getReceiveBufferSize() throws SocketException {
checkClosedAndBind(false);
@@ -283,11 +276,7 @@ public class DatagramSocket {
}
/**
- * Gets the socket send buffer size. ( {@code SocketOptions.SO_SNDBUF} )
- *
- * @return the output buffer size.
- * @throws SocketException
- * if an error occurs while getting the option value.
+ * Returns this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized int getSendBufferSize() throws SocketException {
checkClosedAndBind(false);
@@ -432,18 +421,14 @@ public class DatagramSocket {
} else {
// not connected so the target address is not allowed to be null
if (packAddr == null) {
- if (pack.getPort() == -1) {
- throw new NullPointerException("Destination address is null");
- }
- return;
+ throw new NullPointerException("Destination address is null");
}
SecurityManager security = System.getSecurityManager();
if (security != null) {
if (packAddr.isMulticastAddress()) {
security.checkMulticast(packAddr);
} else {
- security.checkConnect(packAddr.getHostName(), pack
- .getPort());
+ security.checkConnect(packAddr.getHostName(), pack.getPort());
}
}
}
@@ -451,15 +436,25 @@ public class DatagramSocket {
}
/**
- * Sets the socket send buffer size. This buffer size determines which the
- * maximum packet size is that can be sent over this socket. It depends on
- * the network implementation what will happen if the packet is bigger than
- * the buffer size. ( {@code SocketOptions.SO_SNDBUF} )
+ * Sets the network interface used by this socket. Any packets sent
+ * via this socket are transmitted via the specified interface. Any
+ * packets received by this socket will come from the specified
+ * interface. Broadcast datagrams received on this interface will
+ * be processed by this socket. {@see SocketOptions#SO_BINDTODEVICE}
*
- * @param size
- * the buffer size in bytes. The size must be at least one byte.
- * @throws SocketException
- * if an error occurs while setting the option.
+ * @hide
+ */
+ public void setNetworkInterface(NetworkInterface netInterface) throws SocketException {
+ if (netInterface == null) {
+ throw new NullPointerException("networkInterface == null");
+ }
+
+ impl.setOption(SocketOptions.SO_BINDTODEVICE,
+ Integer.valueOf(netInterface.getIndex()));
+ }
+
+ /**
+ * Sets this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized void setSendBufferSize(int size) throws SocketException {
if (size < 1) {
@@ -470,15 +465,7 @@ public class DatagramSocket {
}
/**
- * Sets the socket receive buffer size. This buffer size determines which
- * the maximum packet size is that can be received over this socket. It
- * depends on the network implementation what will happen if the packet is
- * bigger than the buffer size. ( {@code SocketOptions.SO_RCVBUF} )
- *
- * @param size
- * the buffer size in bytes. The size must be at least one byte.
- * @throws SocketException
- * if an error occurs while setting the option.
+ * Sets this socket's {@link SocketOptions#SO_SNDBUF receive buffer size}.
*/
public synchronized void setReceiveBufferSize(int size) throws SocketException {
if (size < 1) {
@@ -821,11 +808,11 @@ public class DatagramSocket {
}
/**
- * Gets the related DatagramChannel of this socket. This implementation
- * returns always {@code null}.
- *
- * @return the related DatagramChannel or {@code null} if this socket was
- * not created by a {@code DatagramChannel} object.
+ * Returns this socket's {@code DatagramChannel}, if one exists. A channel is
+ * available only if this socket wraps a channel. (That is, you can go from a
+ * channel to a socket and back again, but you can't go from an arbitrary socket to a channel.)
+ * In practice, this means that the socket must have been created by
+ * {@link java.nio.channels.DatagramChannel#open}.
*/
public DatagramChannel getChannel() {
return null;
diff --git a/luni/src/main/java/java/net/DatagramSocketImpl.java b/luni/src/main/java/java/net/DatagramSocketImpl.java
index bc27c96..e92cb72 100644
--- a/luni/src/main/java/java/net/DatagramSocketImpl.java
+++ b/luni/src/main/java/java/net/DatagramSocketImpl.java
@@ -87,7 +87,7 @@ public abstract class DatagramSocketImpl implements SocketOptions {
* @return the local address to which the socket is bound.
*/
InetAddress getLocalAddress() {
- return Platform.getNetworkSystem().getSocketLocalAddress(fd);
+ return Platform.NETWORK.getSocketLocalAddress(fd);
}
/**
diff --git a/luni/src/main/java/java/net/HttpCookie.java b/luni/src/main/java/java/net/HttpCookie.java
index 1b333ef..cdbe3e2 100644
--- a/luni/src/main/java/java/net/HttpCookie.java
+++ b/luni/src/main/java/java/net/HttpCookie.java
@@ -127,14 +127,14 @@ public final class HttpCookie implements Cloneable {
return false;
}
- String a = host.toLowerCase();
- String b = domainPattern.toLowerCase();
+ String a = host.toLowerCase(Locale.US);
+ String b = domainPattern.toLowerCase(Locale.US);
/*
* From the spec: "both host names are IP addresses and their host name strings match
* exactly; or both host names are FQDN strings and their host name strings match exactly"
*/
- if (a.equals(b) && (isFullyQualifiedDomainName(a, 0) || !InetAddress.isHostName(a))) {
+ if (a.equals(b) && (isFullyQualifiedDomainName(a, 0) || InetAddress.isNumeric(a))) {
return true;
}
if (!isFullyQualifiedDomainName(a, 0)) {
@@ -505,7 +505,8 @@ public final class HttpCookie implements Cloneable {
private boolean isValidName(String n) {
// name cannot be empty or begin with '$' or equals the reserved
// attributes (case-insensitive)
- boolean isValid = !(n.length() == 0 || n.startsWith("$") || RESERVED_NAMES.contains(n.toLowerCase()));
+ boolean isValid = !(n.length() == 0 || n.startsWith("$")
+ || RESERVED_NAMES.contains(n.toLowerCase(Locale.US)));
if (isValid) {
for (int i = 0; i < n.length(); i++) {
char nameChar = n.charAt(i);
@@ -648,7 +649,7 @@ public final class HttpCookie implements Cloneable {
* cookies only to matching domains.
*/
public void setDomain(String pattern) {
- domain = pattern == null ? null : pattern.toLowerCase();
+ domain = pattern == null ? null : pattern.toLowerCase(Locale.US);
}
/**
@@ -733,14 +734,14 @@ public final class HttpCookie implements Cloneable {
/**
* Returns the hash code of this HTTP cookie: <pre> {@code
- * name.toLowerCase().hashCode()
- * + (domain == null ? 0 : domain.toLowerCase().hashCode())
+ * name.toLowerCase(Locale.US).hashCode()
+ * + (domain == null ? 0 : domain.toLowerCase(Locale.US).hashCode())
* + (path == null ? 0 : path.hashCode())
* }</pre>
*/
@Override public int hashCode() {
- return name.toLowerCase().hashCode()
- + (domain == null ? 0 : domain.toLowerCase().hashCode())
+ return name.toLowerCase(Locale.US).hashCode()
+ + (domain == null ? 0 : domain.toLowerCase(Locale.US).hashCode())
+ (path == null ? 0 : path.hashCode());
}
diff --git a/luni/src/main/java/java/net/Inet4Address.java b/luni/src/main/java/java/net/Inet4Address.java
index 86e12c1..efe232a 100644
--- a/luni/src/main/java/java/net/Inet4Address.java
+++ b/luni/src/main/java/java/net/Inet4Address.java
@@ -18,6 +18,8 @@
package java.net;
import java.io.ObjectStreamException;
+import java.nio.ByteOrder;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* An IPv4 address. See {@link InetAddress}.
@@ -28,14 +30,24 @@ public final class Inet4Address extends InetAddress {
private static final int AF_INET = 2;
- final static InetAddress ANY = new Inet4Address(new byte[] { 0, 0, 0, 0 });
- final static InetAddress LOOPBACK = new Inet4Address(
- new byte[] { 127, 0, 0, 1 }, "localhost");
+ /**
+ * @hide
+ */
+ public static final InetAddress ANY =
+ new Inet4Address(new byte[] { 0, 0, 0, 0 }, null);
- Inet4Address(byte[] address) {
- family = AF_INET;
- ipaddress = address;
- }
+ /**
+ * @hide
+ */
+ public static final InetAddress ALL =
+ new Inet4Address(new byte[] { (byte) 255, (byte) 255,
+ (byte) 255, (byte) 255 }, null);
+
+ /**
+ * @hide
+ */
+ public static final InetAddress LOOPBACK =
+ new Inet4Address(new byte[] { 127, 0, 0, 1 }, "localhost");
Inet4Address(byte[] address, String name) {
family = AF_INET;
@@ -136,7 +148,7 @@ public final class Inet4Address extends InetAddress {
return false;
}
- int address = InetAddress.bytesToInt(ipaddress, 0);
+ int address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
/*
* Now check the boundaries of the global space if we have an address
* that is prefixed by something less than 111000000000000000000001
@@ -181,7 +193,8 @@ public final class Inet4Address extends InetAddress {
*/
@Override
public boolean isMCLinkLocal() {
- return InetAddress.bytesToInt(ipaddress, 0) >>> 8 == 0xE00000;
+ int address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
+ return (address >>> 8) == 0xE00000;
}
/**
@@ -194,7 +207,8 @@ public final class Inet4Address extends InetAddress {
*/
@Override
public boolean isMCSiteLocal() {
- return (InetAddress.bytesToInt(ipaddress, 0) >>> 16) == 0xEFFF;
+ int address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
+ return (address >>> 16) == 0xEFFF;
}
/**
@@ -208,7 +222,8 @@ public final class Inet4Address extends InetAddress {
*/
@Override
public boolean isMCOrgLocal() {
- int prefix = InetAddress.bytesToInt(ipaddress, 0) >>> 16;
+ int address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
+ int prefix = address >>> 16;
return prefix >= 0xEFC0 && prefix <= 0xEFC3;
}
diff --git a/luni/src/main/java/java/net/Inet6Address.java b/luni/src/main/java/java/net/Inet6Address.java
index 79b39ee..b497041 100644
--- a/luni/src/main/java/java/net/Inet6Address.java
+++ b/luni/src/main/java/java/net/Inet6Address.java
@@ -21,7 +21,9 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
+import java.util.Arrays;
import java.util.Enumeration;
+import libcore.base.EmptyArray;
/**
* An IPv6 address. See {@link InetAddress}.
@@ -32,10 +34,11 @@ public final class Inet6Address extends InetAddress {
private static final int AF_INET6 = 10;
- static final InetAddress ANY = new Inet6Address(new byte[]
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 });
- static final InetAddress LOOPBACK = new Inet6Address(new byte[]
- {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, "localhost");
+ static final InetAddress ANY =
+ new Inet6Address(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, null, 0);
+ static final InetAddress LOOPBACK =
+ new Inet6Address(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
+ "localhost", 0);
int scope_id;
@@ -50,19 +53,6 @@ public final class Inet6Address extends InetAddress {
*/
transient NetworkInterface scopedIf;
- Inet6Address(byte[] address) {
- family = AF_INET6;
- ipaddress = address;
- scope_id = 0;
- }
-
- Inet6Address(byte[] address, String name) {
- family = AF_INET6;
- hostName = name;
- ipaddress = address;
- scope_id = 0;
- }
-
/**
* Constructs an {@code InetAddress} representing the {@code address} and
* {@code name} and {@code scope_id}.
@@ -75,13 +65,11 @@ public final class Inet6Address extends InetAddress {
* the scope id for link- or site-local addresses.
*/
Inet6Address(byte[] address, String name, int scope_id) {
- family = AF_INET6;
- hostName = name;
- ipaddress = address;
+ this.family = AF_INET6;
+ this.hostName = name;
+ this.ipaddress = address;
this.scope_id = scope_id;
- if (scope_id != 0) {
- scope_id_set = true;
- }
+ this.scope_id_set = (scope_id != 0);
}
/**
@@ -98,14 +86,15 @@ public final class Inet6Address extends InetAddress {
* @throws UnknownHostException
* if the address is null or has an invalid length.
*/
- public static Inet6Address getByAddress(String host, byte[] addr,
- int scope_id) throws UnknownHostException {
+ public static Inet6Address getByAddress(String host, byte[] addr, int scope_id)
+ throws UnknownHostException {
if (addr == null || addr.length != 16) {
- throw new UnknownHostException("Illegal IPv6 address");
+ throw new UnknownHostException("Not an IPv6 address: " + Arrays.toString(addr));
}
if (scope_id < 0) {
scope_id = 0;
}
+ // TODO: should we clone 'addr'?
return new Inet6Address(addr, host, scope_id);
}
@@ -133,7 +122,7 @@ public final class Inet6Address extends InetAddress {
Inet6Address address = Inet6Address.getByAddress(host, addr, 0);
// if nif is null, nothing needs to be set.
- if (null == nif) {
+ if (nif == null) {
return address;
}
@@ -158,7 +147,7 @@ public final class Inet6Address extends InetAddress {
// if no address matches the type of addr, throws an
// UnknownHostException.
if (!address.scope_id_set) {
- throw new UnknownHostException("Scope id not found for the given address");
+ throw new UnknownHostException("Scope id not found for address: " + Arrays.toString(addr));
}
return address;
}
@@ -186,23 +175,6 @@ public final class Inet6Address extends InetAddress {
}
/**
- * Constructs an {@code InetAddress} representing the {@code address} and
- * {@code scope_id}.
- *
- * @param address
- * the network address.
- * @param scope_id
- * the scope id for link- or site-local addresses.
- */
- Inet6Address(byte[] address, int scope_id) {
- ipaddress = address;
- this.scope_id = scope_id;
- if (scope_id != 0) {
- scope_id_set = true;
- }
- }
-
- /**
* Returns whether this address is an IP multicast address or not. Valid
* IPv6 multicast addresses are binary prefixed with 11111111 or FF (hex).
*
@@ -359,11 +331,6 @@ public final class Inet6Address extends InetAddress {
return (ipaddress[0] == -1) && (ipaddress[1] & 15) == 8;
}
- // BEGIN android-removed
- // public String getHostAddress() {
- // }
- // END android-removed
-
/**
* Gets the scope id as a number if this address is linked to an interface.
* Otherwise returns {@code 0}.
@@ -391,14 +358,6 @@ public final class Inet6Address extends InetAddress {
return null;
}
- // BEGIN android-removed
- // public int hashCode() {}
- // END android-removed
-
- // BEGIN android-removed
- // public boolean equals(Object obj) {}
- // END android-removed
-
/**
* Returns whether this address is IPv4 compatible or not. An IPv4
* compatible address is prefixed with 96 bits of 0's. The last 32-bits are
@@ -417,7 +376,7 @@ public final class Inet6Address extends InetAddress {
}
private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("ipaddress", new byte[0].getClass()),
+ new ObjectStreamField("ipaddress", EmptyArray.BYTE.getClass()),
new ObjectStreamField("scope_id", Integer.TYPE),
new ObjectStreamField("scope_id_set", Boolean.TYPE),
new ObjectStreamField("scope_ifname_set", Boolean.TYPE),
@@ -446,7 +405,7 @@ public final class Inet6Address extends InetAddress {
scope_id_set = fields.get("scope_id_set", false);
ifname = (String) fields.get("ifname", null);
scope_ifname_set = fields.get("scope_ifname_set", false);
- if (scope_ifname_set && null != ifname) {
+ if (scope_ifname_set && ifname != null) {
scopedIf = NetworkInterface.getByName(ifname);
}
}
diff --git a/luni/src/main/java/java/net/InetAddress.java b/luni/src/main/java/java/net/InetAddress.java
index 2f283bb..e4ca164 100644
--- a/luni/src/main/java/java/net/InetAddress.java
+++ b/luni/src/main/java/java/net/InetAddress.java
@@ -25,13 +25,14 @@ import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import java.io.ObjectStreamField;
import java.io.Serializable;
+import java.nio.ByteOrder;
import java.security.AccessController;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.List;
-import org.apache.harmony.luni.platform.INetworkSystem;
+import org.apache.harmony.luni.platform.OSMemory;
import org.apache.harmony.luni.platform.Platform;
import org.apache.harmony.luni.util.PriviAction;
@@ -118,6 +119,9 @@ import org.apache.harmony.luni.util.PriviAction;
* See <a href="https://www.ietf.org/rfc/rfc4007.txt">RFC 4007</a> for more on IPv6's scoped
* address architecture.
*
+ * <p>Additionally, for backwards compatibility, IPv6 addresses may be surrounded by square
+ * brackets.
+ *
* <h4>DNS caching</h4>
* <p>On Android, addresses are cached for 600 seconds (10 minutes) by default. Failed lookups are
* cached for 10 seconds. The underlying C library or OS may cache for longer, but you can control
@@ -136,8 +140,6 @@ public class InetAddress implements Serializable {
/** Our Java-side DNS cache. */
private static final AddressCache addressCache = new AddressCache();
- private final static INetworkSystem NETIMPL = Platform.getNetworkSystem();
-
private static final String ERRMSG_CONNECTION_REFUSED = "Connection refused";
private static final long serialVersionUID = 3286316764910316507L;
@@ -214,8 +216,9 @@ public class InetAddress implements Serializable {
* @param hostName the hostname corresponding to the IP address.
* @return the corresponding InetAddresses, appropriately sorted.
*/
- static InetAddress[] bytesToInetAddresses(byte[][] rawAddresses, String hostName) {
- // If we prefer IPv4, ignore the RFC3484 ordering we get from getaddrinfo
+ static InetAddress[] bytesToInetAddresses(byte[][] rawAddresses, String hostName)
+ throws UnknownHostException {
+ // If we prefer IPv4, ignore the RFC3484 ordering we get from getaddrinfo(3)
// and always put IPv4 addresses first. Arrays.sort() is stable, so the
// internal ordering will not be changed.
if (!preferIPv6Addresses()) {
@@ -225,17 +228,7 @@ public class InetAddress implements Serializable {
// Convert the byte arrays to InetAddresses.
InetAddress[] returnedAddresses = new InetAddress[rawAddresses.length];
for (int i = 0; i < rawAddresses.length; i++) {
- byte[] rawAddress = rawAddresses[i];
- if (rawAddress.length == 16) {
- returnedAddresses[i] = new Inet6Address(rawAddress, hostName);
- } else if (rawAddress.length == 4) {
- returnedAddresses[i] = new Inet4Address(rawAddress, hostName);
- } else {
- // Cannot happen, because the underlying code only returns
- // addresses that are 4 or 16 bytes long.
- throw new AssertionError("Impossible address length " +
- rawAddress.length);
- }
+ returnedAddresses[i] = makeInetAddress(rawAddresses[i], hostName);
}
return returnedAddresses;
}
@@ -274,16 +267,10 @@ public class InetAddress implements Serializable {
return new InetAddress[] { Inet4Address.ANY };
}
- try {
- byte[] hBytes = ipStringToByteArray(host);
- if (hBytes.length == 4) {
- return (new InetAddress[] { new Inet4Address(hBytes) });
- } else if (hBytes.length == 16) {
- return (new InetAddress[] { new Inet6Address(hBytes) });
- } else {
- throw new UnknownHostException(wrongAddressLength());
- }
- } catch (UnknownHostException e) {
+ // Is it a numeric address?
+ byte[] bytes = ipStringToByteArray(host);
+ if (bytes != null) {
+ return new InetAddress[] { makeInetAddress(bytes, null) };
}
SecurityManager security = System.getSecurityManager();
@@ -294,13 +281,19 @@ public class InetAddress implements Serializable {
return lookupHostByName(host);
}
- private static native String byteArrayToIpString(byte[] address);
+ private static InetAddress makeInetAddress(byte[] bytes, String hostname) throws UnknownHostException {
+ if (bytes.length == 4) {
+ return new Inet4Address(bytes, hostname);
+ } else if (bytes.length == 16) {
+ return new Inet6Address(bytes, hostname, 0);
+ } else {
+ throw badAddressLength(bytes);
+ }
+ }
- static native byte[] ipStringToByteArray(String address) throws UnknownHostException;
+ private static native String byteArrayToIpString(byte[] address);
- private static String wrongAddressLength() {
- return "Invalid IP Address is neither 4 or 16 bytes";
- }
+ static native byte[] ipStringToByteArray(String address);
static boolean preferIPv6Addresses() {
String propertyName = "java.net.preferIPv6Addresses";
@@ -346,7 +339,7 @@ public class InetAddress implements Serializable {
if (hostName == null) {
int address = 0;
if (ipaddress.length == 4) {
- address = bytesToInt(ipaddress, 0);
+ address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
if (address == 0) {
return hostName = byteArrayToIpString(ipaddress);
}
@@ -363,7 +356,7 @@ public class InetAddress implements Serializable {
SecurityManager security = System.getSecurityManager();
try {
// Only check host names, not addresses
- if (security != null && isHostName(hostName)) {
+ if (security != null && !isNumeric(hostName)) {
security.checkConnect(hostName, -1);
}
} catch (SecurityException e) {
@@ -385,7 +378,7 @@ public class InetAddress implements Serializable {
try {
int address = 0;
if (ipaddress.length == 4) {
- address = bytesToInt(ipaddress, 0);
+ address = OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN);
if (address == 0) {
return byteArrayToIpString(ipaddress);
}
@@ -397,7 +390,7 @@ public class InetAddress implements Serializable {
SecurityManager security = System.getSecurityManager();
try {
// Only check host names, not addresses
- if (security != null && isHostName(canonicalName)) {
+ if (security != null && !isNumeric(canonicalName)) {
security.checkConnect(canonicalName, -1);
}
} catch (SecurityException e) {
@@ -487,14 +480,14 @@ public class InetAddress implements Serializable {
private static InetAddress[] lookupHostByName(String host) throws UnknownHostException {
BlockGuard.getThreadPolicy().onNetwork();
// Do we have a result cached?
- InetAddress[] cachedResult = addressCache.get(host);
+ Object cachedResult = addressCache.get(host);
if (cachedResult != null) {
- if (cachedResult.length > 0) {
+ if (cachedResult instanceof InetAddress[]) {
// A cached positive result.
- return cachedResult;
+ return (InetAddress[]) cachedResult;
} else {
// A cached negative result.
- throw new UnknownHostException(host);
+ throw new UnknownHostException((String) cachedResult);
}
}
try {
@@ -502,13 +495,23 @@ public class InetAddress implements Serializable {
addressCache.put(host, addresses);
return addresses;
} catch (UnknownHostException e) {
- addressCache.putUnknownHost(host);
- throw new UnknownHostException(host);
+ String detailMessage = e.getMessage();
+ addressCache.putUnknownHost(host, detailMessage);
+ throw new UnknownHostException(detailMessage);
}
}
private static native byte[][] getaddrinfo(String name) throws UnknownHostException;
/**
+ * Removes all entries from the VM's DNS cache. This does not affect the C library's DNS
+ * cache, nor any caching DNS servers between you and the canonical server.
+ * @hide
+ */
+ public static void clearDnsCache() {
+ addressCache.clear();
+ }
+
+ /**
* Query the IP stack for the host address. The host is in address form.
*
* @param addr
@@ -516,16 +519,9 @@ public class InetAddress implements Serializable {
* @throws UnknownHostException
* if an error occurs during lookup.
*/
- static InetAddress getHostByAddrImpl(byte[] addr)
- throws UnknownHostException {
+ static InetAddress getHostByAddrImpl(byte[] addr) throws UnknownHostException {
BlockGuard.getThreadPolicy().onNetwork();
- if (addr.length == 4) {
- return new Inet4Address(addr, getnameinfo(addr));
- } else if (addr.length == 16) {
- return new Inet6Address(addr, getnameinfo(addr));
- } else {
- throw new UnknownHostException(wrongAddressLength());
- }
+ return makeInetAddress(addr, getnameinfo(addr));
}
/**
@@ -534,10 +530,10 @@ public class InetAddress implements Serializable {
private static native String getnameinfo(byte[] addr);
static String getHostNameInternal(String host, boolean isCheck) throws UnknownHostException {
- if (host == null || 0 == host.length()) {
+ if (host == null || host.isEmpty()) {
return Inet4Address.LOOPBACK.getHostAddress();
}
- if (isHostName(host)) {
+ if (!isNumeric(host)) {
if (isCheck) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
@@ -561,15 +557,14 @@ public class InetAddress implements Serializable {
}
/**
- * Returns true if the string is a host name, false if it is an IP Address.
+ * Returns true if the string is a valid numeric IPv4 or IPv6 address (such as "192.168.0.1").
+ * This copes with all forms of address that Java supports, detailed in the {@link InetAddress}
+ * class documentation.
+ *
+ * @hide - used by frameworks/base to ensure that a getAllByName won't cause a DNS lookup.
*/
- static boolean isHostName(String value) {
- try {
- ipStringToByteArray(value);
- return false;
- } catch (UnknownHostException e) {
- return true;
- }
+ public static boolean isNumeric(String address) {
+ return ipStringToByteArray(address) != null;
}
/**
@@ -831,7 +826,7 @@ public class InetAddress implements Serializable {
waitReachable.notifyAll();
} else {
addrCount--;
- if (0 == addrCount) {
+ if (addrCount == 0) {
// if count equals zero, all thread
// expired,notifies main thread
waitReachable.notifyAll();
@@ -863,12 +858,12 @@ public class InetAddress implements Serializable {
throws IOException {
FileDescriptor fd = new FileDescriptor();
boolean reached = false;
- NETIMPL.socket(fd, true);
+ Platform.NETWORK.socket(fd, true);
try {
- if (null != source) {
- NETIMPL.bind(fd, source, 0);
+ if (source != null) {
+ Platform.NETWORK.bind(fd, source, 0);
}
- NETIMPL.connect(fd, destination, 7, timeout);
+ Platform.NETWORK.connect(fd, destination, 7, timeout);
reached = true;
} catch (IOException e) {
if (ERRMSG_CONNECTION_REFUSED.equals(e.getMessage())) {
@@ -877,7 +872,7 @@ public class InetAddress implements Serializable {
}
}
- NETIMPL.close(fd);
+ Platform.NETWORK.close(fd);
return reached;
}
@@ -915,7 +910,7 @@ public class InetAddress implements Serializable {
* @param ipAddress
* either a 4 (IPv4) or 16 (IPv6) byte array.
* @param scope_id
- * the scope id for an IPV6 scoped address. If not a scoped
+ * the scope id for an IPv6 scoped address. If not a scoped
* address just pass in 0.
* @return the InetAddress
* @throws UnknownHostException
@@ -998,60 +993,29 @@ public class InetAddress implements Serializable {
* @return the InetAddress
* @throws UnknownHostException
*/
- static InetAddress getByAddressInternal(String hostName, byte[] ipAddress,
- int scope_id) throws UnknownHostException {
+ static InetAddress getByAddressInternal(String hostName, byte[] ipAddress, int scope_id)
+ throws UnknownHostException {
if (ipAddress == null) {
throw new UnknownHostException("ipAddress == null");
}
- switch (ipAddress.length) {
- case 4:
- return new Inet4Address(ipAddress.clone());
- case 16:
- // First check to see if the address is an IPv6-mapped
- // IPv4 address. If it is, then we can make it a IPv4
- // address, otherwise, we'll create an IPv6 address.
- if (isIPv4MappedAddress(ipAddress)) {
- return new Inet4Address(ipv4MappedToIPv4(ipAddress));
- } else {
- return new Inet6Address(ipAddress.clone(), scope_id);
- }
- default:
- throw new UnknownHostException(
- "Invalid IP Address is neither 4 or 16 bytes: " + hostName);
+ if (ipAddress.length == 4) {
+ return new Inet4Address(ipAddress.clone(), hostName);
+ } else if (ipAddress.length == 16) {
+ // First check to see if the address is an IPv6-mapped
+ // IPv4 address. If it is, then we can make it a IPv4
+ // address, otherwise, we'll create an IPv6 address.
+ if (isIPv4MappedAddress(ipAddress)) {
+ return new Inet4Address(ipv4MappedToIPv4(ipAddress), hostName);
+ } else {
+ return new Inet6Address(ipAddress.clone(), hostName, scope_id);
+ }
+ } else {
+ throw badAddressLength(ipAddress);
}
}
- /**
- * Takes the integer and chops it into 4 bytes, putting it into the byte
- * array starting with the high order byte at the index start. This method
- * makes no checks on the validity of the parameters.
- */
- static void intToBytes(int value, byte[] bytes, int start) {
- // Shift the int so the current byte is right-most
- // Use a byte mask of 255 to single out the last byte.
- bytes[start] = (byte) ((value >> 24) & 255);
- bytes[start + 1] = (byte) ((value >> 16) & 255);
- bytes[start + 2] = (byte) ((value >> 8) & 255);
- bytes[start + 3] = (byte) (value & 255);
- }
-
- /**
- * Takes the byte array and creates an integer out of four bytes starting at
- * start as the high-order byte. This method makes no checks on the validity
- * of the parameters.
- */
- static int bytesToInt(byte[] bytes, int start) {
- // First mask the byte with 255, as when a negative
- // signed byte converts to an integer, it has bits
- // on in the first 3 bytes, we are only concerned
- // about the right-most 8 bits.
- // Then shift the rightmost byte to align with its
- // position in the integer.
- int value = ((bytes[start + 3] & 255))
- | ((bytes[start + 2] & 255) << 8)
- | ((bytes[start + 1] & 255) << 16)
- | ((bytes[start] & 255) << 24);
- return value;
+ private static UnknownHostException badAddressLength(byte[] bytes) throws UnknownHostException {
+ throw new UnknownHostException("Address is neither 4 or 16 bytes: " + Arrays.toString(bytes));
}
private static final ObjectStreamField[] serialPersistentFields = {
@@ -1064,7 +1028,7 @@ public class InetAddress implements Serializable {
if (ipaddress == null) {
fields.put("address", 0);
} else {
- fields.put("address", bytesToInt(ipaddress, 0));
+ fields.put("address", OSMemory.peekInt(ipaddress, 0, ByteOrder.BIG_ENDIAN));
}
fields.put("family", family);
fields.put("hostName", hostName);
@@ -1072,12 +1036,11 @@ public class InetAddress implements Serializable {
stream.writeFields();
}
- private void readObject(ObjectInputStream stream) throws IOException,
- ClassNotFoundException {
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
ObjectInputStream.GetField fields = stream.readFields();
int addr = fields.get("address", 0);
ipaddress = new byte[4];
- intToBytes(addr, ipaddress, 0);
+ OSMemory.pokeInt(ipaddress, 0, addr, ByteOrder.BIG_ENDIAN);
hostName = (String) fields.get("hostName", null);
family = fields.get("family", 2);
}
diff --git a/luni/src/main/java/java/net/InetSocketAddress.java b/luni/src/main/java/java/net/InetSocketAddress.java
index cd1bae3..f9f973b 100644
--- a/luni/src/main/java/java/net/InetSocketAddress.java
+++ b/luni/src/main/java/java/net/InetSocketAddress.java
@@ -28,11 +28,10 @@ public class InetSocketAddress extends SocketAddress {
private static final long serialVersionUID = 5076001401234631237L;
- private String hostname;
-
- private InetAddress addr;
-
- private int port;
+ // Exactly one of hostname or addr should be set.
+ private final InetAddress addr;
+ private final String hostname;
+ private final int port;
/**
* Creates a socket endpoint with the given port number {@code port} and
@@ -59,14 +58,10 @@ public class InetSocketAddress extends SocketAddress {
*/
public InetSocketAddress(InetAddress address, int port) {
if (port < 0 || port > 65535) {
- throw new IllegalArgumentException();
- }
- if (address == null) {
- addr = Inet4Address.ANY;
- } else {
- addr = address;
+ throw new IllegalArgumentException("port=" + port);
}
- hostname = addr.getHostName();
+ this.addr = (address == null) ? Inet4Address.ANY : address;
+ this.hostname = null;
this.port = port;
}
@@ -97,20 +92,22 @@ public class InetSocketAddress extends SocketAddress {
if (hostname == null || port < 0 || port > 65535) {
throw new IllegalArgumentException("host=" + hostname + ", port=" + port);
}
- this.hostname = hostname;
- this.port = port;
+ InetAddress addr = null;
if (needResolved) {
SecurityManager smgr = System.getSecurityManager();
if (smgr != null) {
smgr.checkConnect(hostname, port);
}
try {
- this.addr = InetAddress.getByName(hostname);
- this.hostname = null;
+ addr = InetAddress.getByName(hostname);
+ hostname = null;
} catch (UnknownHostException ignored) {
}
}
+ this.addr = addr;
+ this.hostname = hostname;
+ this.port = port;
}
/**
@@ -155,7 +152,7 @@ public class InetSocketAddress extends SocketAddress {
* @return the socket endpoint hostname.
*/
public final String getHostName() {
- return (null != addr) ? addr.getHostName() : hostname;
+ return (addr != null) ? addr.getHostName() : hostname;
}
/**
@@ -176,13 +173,7 @@ public class InetSocketAddress extends SocketAddress {
*/
@Override
public String toString() {
- String host;
- if (addr != null) {
- host = addr.toString();
- } else {
- host = hostname;
- }
- return host + ":" + port;
+ return ((addr != null) ? addr.toString() : hostname) + ":" + port;
}
/**
@@ -225,11 +216,6 @@ public class InetSocketAddress extends SocketAddress {
return addr.equals(iSockAddr.addr);
}
- /**
- * Gets the hashcode of this socket.
- *
- * @return the appropriate hashcode.
- */
@Override
public final int hashCode() {
if (addr == null) {
@@ -238,8 +224,7 @@ public class InetSocketAddress extends SocketAddress {
return addr.hashCode() + port;
}
- private void readObject(ObjectInputStream stream) throws IOException,
- ClassNotFoundException {
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
}
}
diff --git a/luni/src/main/java/java/net/InterfaceAddress.java b/luni/src/main/java/java/net/InterfaceAddress.java
index 45fc236..2f8029e 100644
--- a/luni/src/main/java/java/net/InterfaceAddress.java
+++ b/luni/src/main/java/java/net/InterfaceAddress.java
@@ -69,7 +69,7 @@ public class InterfaceAddress {
broadcast[i] = (byte) (addrBytes[i] | ~maskBytes[i]);
}
}
- return new Inet4Address(broadcast);
+ return new Inet4Address(broadcast, null);
}
private static short countPrefixLength(InetAddress mask) {
diff --git a/luni/src/main/java/java/net/JarURLConnection.java b/luni/src/main/java/java/net/JarURLConnection.java
index 0ea065d..4b84893 100644
--- a/luni/src/main/java/java/net/JarURLConnection.java
+++ b/luni/src/main/java/java/net/JarURLConnection.java
@@ -75,7 +75,7 @@ public abstract class JarURLConnection extends URLConnection {
return;
}
entryName = file.substring(sepIdx, file.length());
- if (null != url.getRef()) {
+ if (url.getRef() != null) {
entryName += "#" + url.getRef();
}
}
diff --git a/luni/src/main/java/java/net/MulticastSocket.java b/luni/src/main/java/java/net/MulticastSocket.java
index df09de5..c853dc4 100644
--- a/luni/src/main/java/java/net/MulticastSocket.java
+++ b/luni/src/main/java/java/net/MulticastSocket.java
@@ -28,6 +28,9 @@ import org.apache.harmony.luni.net.PlainDatagramSocketImpl;
* @see DatagramSocket
*/
public class MulticastSocket extends DatagramSocket {
+ private static final int NO_INTERFACE_INDEX = 0;
+ private static final int UNSET_INTERFACE_INDEX = -1;
+
private InetAddress interfaceSet;
/**
@@ -71,7 +74,7 @@ public class MulticastSocket extends DatagramSocket {
InetAddress ipvXaddress = (InetAddress) impl
.getOption(SocketOptions.IP_MULTICAST_IF);
if (ipvXaddress.isAnyLocalAddress()) {
- // the address was not set at the IPV4 level so check the IPV6
+ // the address was not set at the IPv4 level so check the IPv6
// level
NetworkInterface theInterface = getNetworkInterface();
if (theInterface != null) {
@@ -105,13 +108,13 @@ public class MulticastSocket extends DatagramSocket {
public NetworkInterface getNetworkInterface() throws SocketException {
checkClosedAndBind(false);
- // check if it is set at the IPV6 level. If so then use that. Otherwise
- // do it at the IPV4 level
+ // check if it is set at the IPv6 level. If so then use that. Otherwise
+ // do it at the IPv4 level
Integer theIndex = Integer.valueOf(0);
try {
theIndex = (Integer) impl.getOption(SocketOptions.IP_MULTICAST_IF2);
} catch (SocketException e) {
- // we may get an exception if IPV6 is not enabled.
+ // we may get an exception if IPv6 is not enabled.
}
if (theIndex.intValue() != 0) {
@@ -124,7 +127,7 @@ public class MulticastSocket extends DatagramSocket {
}
}
- // ok it was not set at the IPV6 level so try at the IPV4 level
+ // ok it was not set at the IPv6 level so try at the IPv4 level
InetAddress theAddress = (InetAddress) impl.getOption(SocketOptions.IP_MULTICAST_IF);
if (theAddress != null) {
if (!theAddress.isAnyLocalAddress()) {
@@ -140,8 +143,7 @@ public class MulticastSocket extends DatagramSocket {
} else {
theAddresses[0] = Inet4Address.ANY;
}
- return new NetworkInterface(null, null, theAddresses,
- NetworkInterface.UNSET_INTERFACE_INDEX);
+ return new NetworkInterface(null, null, theAddresses, UNSET_INTERFACE_INDEX);
}
// ok not set at all so return null
@@ -355,9 +357,9 @@ public class MulticastSocket extends DatagramSocket {
}
/*
- * now we should also make sure this works for IPV6 get the network
+ * now we should also make sure this works for IPv6 get the network
* interface for the address and set the interface using its index
- * however if IPV6 is not enabled then we may get an exception. if IPV6
+ * however if IPv6 is not enabled then we may get an exception. if IPv6
* is not enabled
*/
NetworkInterface theInterface = NetworkInterface.getByInetAddress(addr);
@@ -404,26 +406,25 @@ public class MulticastSocket extends DatagramSocket {
throw new SocketException("No address associated with interface: " + netInterface);
}
- if (netInterface.getIndex() == NetworkInterface.UNSET_INTERFACE_INDEX) {
+ if (netInterface.getIndex() == UNSET_INTERFACE_INDEX) {
// set the address using IP_MULTICAST_IF to make sure this
- // works for both IPV4 and IPV6
+ // works for both IPv4 and IPv6
impl.setOption(SocketOptions.IP_MULTICAST_IF, Inet4Address.ANY);
try {
// we have the index so now we pass set the interface
// using IP_MULTICAST_IF2. This is what is used to set
- // the interface on systems which support IPV6
- impl.setOption(SocketOptions.IP_MULTICAST_IF2, Integer
- .valueOf(NetworkInterface.NO_INTERFACE_INDEX));
+ // the interface on systems which support IPv6
+ impl.setOption(SocketOptions.IP_MULTICAST_IF2, Integer.valueOf(NO_INTERFACE_INDEX));
} catch (SocketException e) {
// for now just do this, -- could be narrowed?
}
}
/*
- * Now try to set using IPV4 way. However, if interface passed in has no
+ * Now try to set using IPv4 way. However, if interface passed in has no
* IP addresses associated with it then we cannot do it. first we have
- * to make sure there is an IPV4 address that we can use to call set
+ * to make sure there is an IPv4 address that we can use to call set
* interface otherwise we will not set it
*/
Enumeration<InetAddress> theAddresses = netInterface.getInetAddresses();
@@ -436,8 +437,8 @@ public class MulticastSocket extends DatagramSocket {
found = true;
}
}
- if (netInterface.getIndex() == NetworkInterface.NO_INTERFACE_INDEX) {
- // the system does not support IPV6 and does not provide
+ if (netInterface.getIndex() == NO_INTERFACE_INDEX) {
+ // the system does not support IPv6 and does not provide
// indexes for the network interfaces. Just pass in the
// first address for the network interface
if (firstAddress != null) {
@@ -445,14 +446,14 @@ public class MulticastSocket extends DatagramSocket {
} else {
/*
* we should never get here as there should not be any network
- * interfaces which have no IPV4 address and which does not have
+ * interfaces which have no IPv4 address and which does not have
* the network interface index not set correctly
*/
throw new SocketException("No address associated with interface: " + netInterface);
}
} else {
// set the address using IP_MULTICAST_IF to make sure this
- // works for both IPV4 and IPV6
+ // works for both IPv4 and IPv6
if (firstAddress != null) {
impl.setOption(SocketOptions.IP_MULTICAST_IF, firstAddress);
}
@@ -460,7 +461,7 @@ public class MulticastSocket extends DatagramSocket {
try {
// we have the index so now we pass set the interface
// using IP_MULTICAST_IF2. This is what is used to set
- // the interface on systems which support IPV6
+ // the interface on systems which support IPv6
impl.setOption(SocketOptions.IP_MULTICAST_IF2, Integer
.valueOf(netInterface.getIndex()));
} catch (SocketException e) {
@@ -475,9 +476,6 @@ public class MulticastSocket extends DatagramSocket {
* Sets the time-to-live (TTL) for multicast packets sent on this socket.
* Valid TTL values are between 0 and 255 inclusive.
*
- * @param ttl
- * the default time-to-live field value for packets sent on this
- * socket. {@code 0 <= ttl <= 255}.
* @throws IOException
* if an error occurs while setting the TTL option value.
*/
@@ -493,9 +491,6 @@ public class MulticastSocket extends DatagramSocket {
* Sets the time-to-live (TTL) for multicast packets sent on this socket.
* Valid TTL values are between 0 and 255 inclusive.
*
- * @param ttl
- * the default time-to-live field value for packets sent on this
- * socket: {@code 0 <= ttl <= 255}.
* @throws IOException
* if an error occurs while setting the TTL option value.
* @deprecated Replaced by {@link #setTimeToLive}
diff --git a/luni/src/main/java/java/net/NetworkInterface.java b/luni/src/main/java/java/net/NetworkInterface.java
index 115e98a..d86cca2 100644
--- a/luni/src/main/java/java/net/NetworkInterface.java
+++ b/luni/src/main/java/java/net/NetworkInterface.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import libcore.base.EmptyArray;
/**
* This class is used to represent a network interface of the local device. An
@@ -35,27 +36,16 @@ public final class NetworkInterface extends Object {
private static final int CHECK_CONNECT_NO_PORT = -1;
- static final int NO_INTERFACE_INDEX = 0;
- static final int UNSET_INTERFACE_INDEX = -1;
-
private final String name;
private final String displayName;
private final List<InterfaceAddress> interfaceAddresses = new LinkedList<InterfaceAddress>();
+ private final int interfaceIndex;
private final List<InetAddress> addresses = new LinkedList<InetAddress>();
- // The interface index is a positive integer which is non-negative. Where
- // value is zero then we do not have an index for the interface (which
- // occurs in systems which only support IPV4)
- private int interfaceIndex;
-
- private NetworkInterface parent = null;
-
private final List<NetworkInterface> children = new LinkedList<NetworkInterface>();
- // BEGIN android-changed: we pay this extra complexity on the Java side
- // in return for vastly simpler native code.
- private static native InterfaceAddress[] getAllInterfaceAddressesImpl() throws SocketException;
+ private NetworkInterface parent = null;
private static NetworkInterface[] getNetworkInterfacesImpl() throws SocketException {
Map<String, NetworkInterface> networkInterfaces = new LinkedHashMap<String, NetworkInterface>();
@@ -75,7 +65,7 @@ public final class NetworkInterface extends Object {
}
return networkInterfaces.values().toArray(new NetworkInterface[networkInterfaces.size()]);
}
- // END android-changed
+ private static native InterfaceAddress[] getAllInterfaceAddressesImpl() throws SocketException;
/**
* This constructor is used by the native method in order to construct the
@@ -89,7 +79,7 @@ public final class NetworkInterface extends Object {
* the Internet addresses associated with the interface.
* @param interfaceIndex
* an index for the interface. Only set for platforms that
- * support IPV6.
+ * support IPv6.
*/
NetworkInterface(String name, String displayName, InetAddress[] addresses,
int interfaceIndex) {
@@ -105,7 +95,7 @@ public final class NetworkInterface extends Object {
/**
* Returns the index for the network interface. Unless the system supports
- * IPV6 this will be 0.
+ * IPv6 this will be 0.
*
* @return the index
*/
@@ -332,10 +322,8 @@ public final class NetworkInterface extends Object {
string.append(name);
string.append("][");
string.append(displayName);
- // BEGIN android-added: the RI shows this, and it's useful for IPv6 users.
string.append("][");
string.append(interfaceIndex);
- // END android-added
string.append("]");
/*
@@ -477,7 +465,7 @@ public final class NetworkInterface extends Object {
*/
public byte[] getHardwareAddress() throws SocketException {
if (addresses.isEmpty()) {
- return new byte[0];
+ return EmptyArray.BYTE;
}
return getHardwareAddressImpl(name);
}
diff --git a/luni/src/main/java/java/net/Proxy.java b/luni/src/main/java/java/net/Proxy.java
index 752ea2b..340ef39 100644
--- a/luni/src/main/java/java/net/Proxy.java
+++ b/luni/src/main/java/java/net/Proxy.java
@@ -102,11 +102,15 @@ public class Proxy {
*/
@Override
public String toString() {
- String proxyString = String.valueOf(type);
- if (null != address) {
- proxyString += "/" + address.toString();
+ StringBuilder builder = new StringBuilder();
+ if (type != null) {
+ builder.append(type.toString());
}
- return proxyString;
+ builder.append("@");
+ if (type != Proxy.Type.DIRECT && address != null) {
+ builder.append(address.toString());
+ }
+ return builder.toString();
}
/**
@@ -143,7 +147,7 @@ public class Proxy {
public final int hashCode() {
int ret = 0;
ret += type.hashCode();
- if (null != address) {
+ if (address != null) {
ret += address.hashCode();
}
return ret;
diff --git a/luni/src/main/java/java/net/ProxySelector.java b/luni/src/main/java/java/net/ProxySelector.java
index b9dee5e..8455274 100644
--- a/luni/src/main/java/java/net/ProxySelector.java
+++ b/luni/src/main/java/java/net/ProxySelector.java
@@ -13,116 +13,137 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package java.net;
import java.io.IOException;
import java.util.List;
/**
- * Selects an applicable proxy server when connecting to a resource specified by
- * a URL. Proxy selectors are concrete subclasses of {@code ProxySelector} and
- * can be set as default by calling the {@code setDefault()} method. If a
- * connection can't be established, the caller should notify the proxy selector
- * by invoking the {@code connectFailed()} method.
+ * Selects the proxy server to use, if any, when connecting to a given URL.
+ *
+ * <h3>System Properties</h3>
+ * <p>The default proxy selector is configured by system properties.
+ *
+ * <table border="1" cellpadding="3" cellspacing="0">
+ * <tr class="TableHeadingColor"><th colspan="4">Hostname patterns</th></tr>
+ * <tr><th>URL scheme</th><th>property name</th><th>description</th><th>default</th></tr>
+ * <tr><td>ftp</td><td>ftp.nonProxyHosts</td><td>Hostname pattern for FTP servers to connect to
+ * directly (without a proxy).</td><td>*</td></tr>
+ * <tr><td>http</td><td>http.nonProxyHosts</td><td>Hostname pattern for HTTP servers to connect to
+ * directly (without a proxy).</td><td>*</td></tr>
+ * <tr><td>https</td><td>https.nonProxyHosts</td><td>Hostname pattern for HTTPS servers to connect
+ * to directly (without a proxy).</td><td>*</td></tr>
+ * <tr><td colspan="4"><br></td></tr>
+ *
+ * <tr class="TableHeadingColor"><th colspan="4">{@linkplain Proxy.Type#HTTP HTTP Proxies}</th></tr>
+ * <tr><th>URL scheme</th><th>property name</th><th>description</th><th>default</th></tr>
+ * <tr><td rowspan="2">ftp</td><td>ftp.proxyHost</td><td>Hostname of the HTTP proxy server used for
+ * FTP requests.</td><td></td></tr>
+ * <tr><td>ftp.proxyPort</td><td>Port number of the HTTP proxy server used for FTP
+ * requests.</td><td>80</td></tr>
+ * <tr><td rowspan="2">http</td><td>http.proxyHost</td><td>Hostname of the HTTP proxy server used
+ * for HTTP requests.</td><td></td></tr>
+ * <tr><td>http.proxyPort</td><td>Port number of the HTTP proxy server used for HTTP
+ * requests.</td><td>80</td></tr>
+ * <tr><td rowspan="2">https</td><td>https.proxyHost</td><td>Hostname of the HTTP proxy server used
+ * for HTTPS requests.</td><td></td></tr>
+ * <tr><td>https.proxyPort</td><td>Port number of the HTTP proxy server used for HTTPS
+ * requests.</td><td>443</td></tr>
+ * <tr><td rowspan="2">ftp, http or https</td><td>proxyHost</td><td>Hostname of the HTTP proxy
+ * server used for FTP, HTTP and HTTPS requests.</td><td></td></tr>
+ * <tr><td>proxyPort</td><td>Port number of the HTTP proxy server.</td><td>80 for FTP and HTTP
+ * <br>443 for HTTPS</td></tr>
+ * <tr><td colspan="4"><br></td></tr>
+ *
+ * <tr class="TableHeadingColor"><th colspan="4">{@linkplain Proxy.Type#SOCKS SOCKS
+ * Proxies}</th></tr>
+ * <tr><th>URL scheme</th><th>property name</th><th>description</th><th>default</th></tr>
+ * <tr><td rowspan="2">ftp, http, https or socket</td><td>socksProxyHost</td><td>Hostname of the
+ * SOCKS proxy server used for FTP, HTTP, HTTPS and raw sockets.<br>Raw socket URLs are of the
+ * form <code>socket://<i>host</i>:<i>port</i></code></td><td></td></tr>
+ * <tr><td>socksProxyPort</td><td>Port number of the SOCKS proxy server.</td><td>1080</td></tr>
+ * </table>
+ *
+ * <p>Hostname patterns specify which hosts should be connected to directly,
+ * ignoring any other proxy system properties. If the URL's host matches the
+ * corresponding hostname pattern, {@link Proxy#NO_PROXY} is returned.
+ *
+ * <p>The format of a hostname pattern is a list of hostnames that are
+ * separated by {@code |} and that use {@code *} as a wildcard. For example,
+ * setting the {@code http.nonProxyHosts} property to {@code
+ * *.android.com|*.kernel.org} will cause requests to {@code
+ * http://developer.android.com} to be made without a proxy.
+ *
+ * <p>The default proxy selector always returns exactly one proxy. If no proxy
+ * is applicable, {@link Proxy#NO_PROXY} is returned. If multiple proxies are
+ * applicable, such as when both the {@code proxyHost} and {@code
+ * socksProxyHost} system properties are set, the result is the property listed
+ * earliest in the table above.
+ *
+ * <h3>Alternatives</h3>
+ * <p>To request a URL without involving the system proxy selector, explicitly
+ * specify a proxy or {@link Proxy#NO_PROXY} using {@link
+ * URL#openConnection(Proxy)}.
+ *
+ * <p>Use {@link ProxySelector#setDefault(ProxySelector)} to install a custom
+ * proxy selector.
*/
public abstract class ProxySelector {
private static ProxySelector defaultSelector = new ProxySelectorImpl();
- /*
- * "getProxySelector" permission. getDefault method requires this
- * permission.
- */
- private final static NetPermission getProxySelectorPermission = new NetPermission(
- "getProxySelector");
-
- /*
- * "setProxySelector" permission. setDefault method requires this
- * permission.
- */
- private final static NetPermission setProxySelectorPermission = new NetPermission(
- "setProxySelector");
-
- /**
- * Creates a new {@code ProxySelector} instance.
- */
- public ProxySelector() {
- super();
- }
+ private final static NetPermission getProxySelectorPermission
+ = new NetPermission("getProxySelector");
+ private final static NetPermission setProxySelectorPermission
+ = new NetPermission("setProxySelector");
/**
- * Gets the default {@code ProxySelector} of the system.
+ * Returns the default proxy selector, or null if none exists.
*
- * @return the currently set default {@code ProxySelector}.
- * @throws SecurityException
- * if a security manager is installed but it doesn't have the
- * NetPermission("getProxySelector").
+ * @throws SecurityException if a security manager is installed but it
+ * doesn't have the NetPermission("getProxySelector").
*/
public static ProxySelector getDefault() {
SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
+ if (sm != null) {
sm.checkPermission(getProxySelectorPermission);
}
return defaultSelector;
}
/**
- * Sets the default {@code ProxySelector} of the system. Removes the system
- * default {@code ProxySelector} if the parameter {@code selector} is set to
- * {@code null}.
+ * Sets the default proxy selector. If {@code selector} is null, the current
+ * proxy selector will be removed.
*
- * @param selector
- * the {@code ProxySelector} instance to set as default or
- * {@code null} to remove the current default {@code
- * ProxySelector}.
- * @throws SecurityException
- * if a security manager is installed but it doesn't have the
- * NetPermission("setProxySelector").
+ * @throws SecurityException if a security manager is installed but it
+ * doesn't have the NetPermission("setProxySelector").
*/
public static void setDefault(ProxySelector selector) {
SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
+ if (sm != null) {
sm.checkPermission(setProxySelectorPermission);
}
defaultSelector = selector;
}
/**
- * Gets all applicable proxies based on the accessing protocol of {@code
- * uri}. The format of URI is defined as below:
- * <p>
- * <li>http URI stands for http connection.</li>
- * <li>https URI stands for https connection.</li>
- * <li>ftp URI stands for ftp connection.</li>
- * <li>socket:://ip:port URI stands for tcp client sockets connection.</li>
+ * Returns the proxy servers to use on connections to {@code uri}. This list
+ * will contain {@link Proxy#NO_PROXY} if no proxy server should be used.
*
- * @param uri
- * the target URI object.
- * @return a list containing all applicable proxies. If no proxy is
- * available, the list contains only the {@code Proxy.NO_PROXY}
- * element.
- * @throws IllegalArgumentException
- * if {@code uri} is {@code null}.
+ * @throws IllegalArgumentException if {@code uri} is null.
*/
public abstract List<Proxy> select(URI uri);
/**
- * Notifies the {@code ProxySelector} that a connection to the proxy server
- * could not be established. A concrete implementation should upon this
- * notification maintain the list of available proxies, since an updated
- * version should be provided by {@code select()}.
+ * Notifies this {@code ProxySelector} that a connection to the proxy server
+ * could not be established.
*
- * @param uri
- * the URI to which the connection could not be established.
- * @param sa
- * the address of the proxy.
- * @param ioe
- * the exception which was thrown during connection
- * establishment.
- * @throws IllegalArgumentException
- * if any argument is {@code null}.
- * @see #select(URI)
+ * @param uri the URI to which the connection could not be established.
+ * @param address the address of the proxy.
+ * @param failure the exception which was thrown during connection
+ * establishment.
+ * @throws IllegalArgumentException if any argument is null.
*/
- public abstract void connectFailed(URI uri, SocketAddress sa,
- IOException ioe);
+ public abstract void connectFailed(URI uri, SocketAddress address, IOException failure);
}
diff --git a/luni/src/main/java/java/net/ProxySelectorImpl.java b/luni/src/main/java/java/net/ProxySelectorImpl.java
index 571f32b..772b9e5 100644
--- a/luni/src/main/java/java/net/ProxySelectorImpl.java
+++ b/luni/src/main/java/java/net/ProxySelectorImpl.java
@@ -13,311 +13,131 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package java.net;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessController;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
-import java.util.Properties;
-import org.apache.harmony.luni.util.PriviAction;
-
-/**
- * Default implementation for {@code ProxySelector}.
- */
-@SuppressWarnings("unchecked")
-class ProxySelectorImpl extends ProxySelector {
-
- private static final int HTTP_PROXY_PORT = 80;
-
- private static final int HTTPS_PROXY_PORT = 443;
-
- private static final int FTP_PROXY_PORT = 80;
-
- private static final int SOCKS_PROXY_PORT = 1080;
- // Net properties read from net.properties file.
- private static Properties netProps = null;
+final class ProxySelectorImpl extends ProxySelector {
- // read net.properties file
- static {
- AccessController.doPrivileged(new java.security.PrivilegedAction() {
- public Object run() {
- File f = new File(System.getProperty("java.home")
- + File.separator + "lib" + File.separator
- + "net.properties");
-
- if (f.exists()) {
- try {
- FileInputStream fis = new FileInputStream(f);
- InputStream is = new BufferedInputStream(fis);
- netProps = new Properties();
- netProps.load(is);
- is.close();
- } catch (IOException e) {
- }
- }
- return null;
- }
- });
- }
-
- public ProxySelectorImpl() {
- super();
- }
-
- @Override
- public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+ @Override public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
if (uri == null || sa == null || ioe == null) {
throw new IllegalArgumentException();
}
}
- @Override
- public List<Proxy> select(URI uri) {
- // argument check
+ @Override public List<Proxy> select(URI uri) {
+ return Collections.singletonList(selectOneProxy(uri));
+ }
+
+ private Proxy selectOneProxy(URI uri) {
if (uri == null) {
throw new IllegalArgumentException("uri == null");
}
- // check scheme
String scheme = uri.getScheme();
- if (null == scheme) {
- throw new IllegalArgumentException();
+ if (scheme == null) {
+ throw new IllegalArgumentException("scheme == null");
}
- String host = uri.getHost();
- Proxy proxy = Proxy.NO_PROXY;
-
- if ("http".equals(scheme)) {
- proxy = selectHttpProxy(host);
- } else if ("https".equals(scheme)) {
- proxy = selectHttpsProxy();
- } else if ("ftp".equals(scheme)) {
- proxy = selectFtpProxy(host);
- } else if ("socket".equals(scheme)) {
- proxy = selectSocksProxy();
+ int port = -1;
+ Proxy proxy = null;
+ String nonProxyHostsKey = null;
+ boolean httpProxyOkay = true;
+ if ("http".equalsIgnoreCase(scheme)) {
+ port = 80;
+ nonProxyHostsKey = "http.nonProxyHosts";
+ proxy = lookupProxy("http.proxyHost", "http.proxyPort", Proxy.Type.HTTP, port);
+ } else if ("https".equalsIgnoreCase(scheme)) {
+ port = 443;
+ nonProxyHostsKey = "https.nonProxyHosts"; // RI doesn't support this
+ proxy = lookupProxy("https.proxyHost", "https.proxyPort", Proxy.Type.HTTP, port);
+ } else if ("ftp".equalsIgnoreCase(scheme)) {
+ port = 80; // not 21 as you might guess
+ nonProxyHostsKey = "ftp.nonProxyHosts";
+ proxy = lookupProxy("ftp.proxyHost", "ftp.proxyPort", Proxy.Type.HTTP, port);
+ } else if ("socket".equalsIgnoreCase(scheme)) {
+ httpProxyOkay = false;
+ } else {
+ return Proxy.NO_PROXY;
}
- List<Proxy> proxyList = new ArrayList<Proxy>(1);
- proxyList.add(proxy);
- return proxyList;
- }
-
- /*
- * Gets proxy for http request. 1. gets from "http.proxyHost", then gets
- * port from "http.proxyPort", or from "proxyPort" if "http.proxyPort" is
- * unavailable. 2. gets from "proxyHost" if 1 is unavailable,then get port
- * from "proxyPort", or from "http.proxyPort" if "proxyPort" is unavailable.
- * 3. gets from "socksProxyHost" if 2 is unavailable.
- */
-
- private Proxy selectHttpProxy(String uriHost) {
- String host;
- String port = null;
- Proxy.Type type = Proxy.Type.DIRECT;
- String nonProxyHosts = getSystemProperty("http.nonProxyHosts");
- // if host is in non proxy host list, returns Proxy.NO_PROXY
- if (isNonProxyHost(uriHost, nonProxyHosts)) {
+ if (nonProxyHostsKey != null
+ && isNonProxyHost(uri.getHost(), System.getProperty(nonProxyHostsKey))) {
return Proxy.NO_PROXY;
}
- host = getSystemProperty("http.proxyHost");
- if (null != host) {
- // case 1: http.proxyHost is set, use exact http proxy
- type = Proxy.Type.HTTP;
- port = getSystemPropertyOrAlternative("http.proxyPort",
- "proxyPort", String.valueOf(HTTP_PROXY_PORT));
- } else if ((host = getSystemProperty("proxyHost", null)) != null) {
- // case 2: proxyHost is set, use exact http proxy
- type = Proxy.Type.HTTP;
- port = getSystemPropertyOrAlternative("proxyPort",
- "http.proxyPort", String.valueOf(HTTP_PROXY_PORT));
-
- } else if ((host = getSystemProperty("socksProxyHost")) != null) {
- // case 3: use socks proxy instead
- type = Proxy.Type.SOCKS;
- port = getSystemProperty(
- "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT));
+ if (proxy != null) {
+ return proxy;
}
- int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
- : HTTP_PROXY_PORT;
- return createProxy(type, host, port, defaultPort);
- }
- /*
- * Gets proxy for https request.
- */
- private Proxy selectHttpsProxy() {
- String host;
- String port = null;
- Proxy.Type type = Proxy.Type.DIRECT;
-
- host = getSystemProperty("https.proxyHost");
- if (null != host) {
- // case 1: use exact https proxy
- type = Proxy.Type.HTTP;
- port = getSystemProperty(
- "https.proxyPort", String.valueOf(HTTPS_PROXY_PORT));
- } else {
- host = getSystemProperty("socksProxyHost");
- if (null != host) {
- // case 2: use socks proxy instead
- type = Proxy.Type.SOCKS;
- port = getSystemProperty(
- "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT));
+ if (httpProxyOkay) {
+ proxy = lookupProxy("proxyHost", "proxyPort", Proxy.Type.HTTP, port);
+ if (proxy != null) {
+ return proxy;
}
}
- int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
- : HTTPS_PROXY_PORT;
- return createProxy(type, host, port, defaultPort);
- }
- /*
- * Gets proxy for ftp request.
- */
- private Proxy selectFtpProxy(String uriHost) {
- String host;
- String port = null;
- Proxy.Type type = Proxy.Type.DIRECT;
- String nonProxyHosts = getSystemProperty("ftp.nonProxyHosts");
- // if host is in non proxy host list, returns Proxy.NO_PROXY
- if (isNonProxyHost(uriHost, nonProxyHosts)) {
- return Proxy.NO_PROXY;
+ proxy = lookupProxy("socksProxyHost", "socksProxyPort", Proxy.Type.SOCKS, 1080);
+ if (proxy != null) {
+ return proxy;
}
- host = getSystemProperty("ftp.proxyHost");
- if (null != host) {
- // case 1: use exact ftp proxy
- type = Proxy.Type.HTTP;
- port = getSystemProperty(
- "ftp.proxyPort", String.valueOf(FTP_PROXY_PORT));
- } else {
- host = getSystemProperty("socksProxyHost");
- if (null != host) {
- // case 2: use socks proxy instead
- type = Proxy.Type.SOCKS;
- port = getSystemProperty(
- "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT));
- }
- }
- int defaultPort = (type == Proxy.Type.SOCKS) ? SOCKS_PROXY_PORT
- : FTP_PROXY_PORT;
- return createProxy(type, host, port, defaultPort);
+ return Proxy.NO_PROXY;
}
- /*
- * Gets proxy for socks request.
+ /**
+ * Returns the proxy identified by the {@code hostKey} system property, or
+ * null.
*/
- private Proxy selectSocksProxy() {
- String host;
- String port = null;
- Proxy.Type type = Proxy.Type.DIRECT;
-
- host = getSystemProperty("socksProxyHost");
- if (null != host) {
- type = Proxy.Type.SOCKS;
- port = getSystemProperty(
- "socksProxyPort", String.valueOf(SOCKS_PROXY_PORT));
+ private Proxy lookupProxy(String hostKey, String portKey, Proxy.Type type, int defaultPort) {
+ String host = System.getProperty(hostKey);
+ if (host == null || host.isEmpty()) {
+ return null;
}
- return createProxy(type, host, port, SOCKS_PROXY_PORT);
- }
- /*
- * checks whether the host needs proxy. return true if it doesn't need a
- * proxy.
- */
- private boolean isNonProxyHost(String host, String nonProxyHosts) {
- // nonProxyHosts is not set
- if (null == host || null == nonProxyHosts) {
- return false;
- }
- // Construct regex expression of nonProxyHosts
- int length = nonProxyHosts.length();
- char ch;
- StringBuilder buf = new StringBuilder(length);
- for (int i = 0; i < nonProxyHosts.length(); i++) {
- ch = nonProxyHosts.charAt(i);
- switch (ch) {
- case '.':
- buf.append("\\.");
- break;
- case '*':
- buf.append(".*");
- break;
- default:
- buf.append(ch);
- }
- }
- String nonProxyHostsReg = buf.toString();
- // check whether the host is the nonProxyHosts.
- return host.matches(nonProxyHostsReg);
+ int port = getSystemPropertyInt(portKey, defaultPort);
+ return new Proxy(type, InetSocketAddress.createUnresolved(host, port));
}
- /*
- * Create Proxy by "type","host" and "port".
- */
- private Proxy createProxy(Proxy.Type type, String host, String port,
- int defaultPort) {
- Proxy proxy;
- if (type == Proxy.Type.DIRECT) {
- proxy = Proxy.NO_PROXY;
- } else {
- int iPort;
+ private int getSystemPropertyInt(String key, int defaultValue) {
+ String string = System.getProperty(key);
+ if (string != null) {
try {
- // BEGIN android-changed
- iPort = Integer.parseInt(port);
- // END android-changed
- } catch (NumberFormatException e) {
- iPort = defaultPort;
+ return Integer.parseInt(string);
+ } catch (NumberFormatException ignored) {
}
- proxy = new Proxy(type, InetSocketAddress.createUnresolved(host,
- iPort));
}
- return proxy;
- }
-
- /*
- * gets system property, privileged operation. If the value of the property
- * is null or empty String, it returns defaultValue.
- */
- private String getSystemProperty(final String property) {
- return getSystemProperty(property, null);
+ return defaultValue;
}
- /*
- * gets system property, privileged operation. If the value of the property
- * is null or empty String, it returns defaultValue.
+ /**
+ * Returns true if the {@code nonProxyHosts} system property pattern exists
+ * and matches {@code host}.
*/
- private String getSystemProperty(final String property,
- final String defaultValue) {
- String value = AccessController.doPrivileged(new PriviAction<String>(
- property));
- if (value == null || value.isEmpty()) {
- value = (netProps != null)
- ? netProps.getProperty(property, defaultValue)
- : defaultValue;
+ private boolean isNonProxyHost(String host, String nonProxyHosts) {
+ if (host == null || nonProxyHosts == null) {
+ return false;
}
- return value;
- }
- /*
- * gets system property, privileged operation. If the value of "key"
- * property is null, then retrieve value from "alternative" property.
- * Finally, if the value is null or empty String, it returns defaultValue.
- */
- private String getSystemPropertyOrAlternative(final String key,
- final String alternativeKey, final String defaultValue) {
- String value = getSystemProperty(key);
- if (value == null) {
- value = getSystemProperty(alternativeKey);
- if (null == value) {
- value = defaultValue;
+ // construct pattern
+ StringBuilder patternBuilder = new StringBuilder();
+ for (int i = 0; i < nonProxyHosts.length(); i++) {
+ char c = nonProxyHosts.charAt(i);
+ switch (c) {
+ case '.':
+ patternBuilder.append("\\.");
+ break;
+ case '*':
+ patternBuilder.append(".*");
+ break;
+ default:
+ patternBuilder.append(c);
}
}
- return value;
+ // check whether the host is the nonProxyHosts.
+ String pattern = patternBuilder.toString();
+ return host.matches(pattern);
}
}
diff --git a/luni/src/main/java/java/net/ResponseCache.java b/luni/src/main/java/java/net/ResponseCache.java
index b92e6db..5eeb551 100644
--- a/luni/src/main/java/java/net/ResponseCache.java
+++ b/luni/src/main/java/java/net/ResponseCache.java
@@ -80,7 +80,7 @@ public abstract class ResponseCache {
*
* @param uri
* the reference to the requested resource.
- * @param conn
+ * @param connection
* the connection to fetch the response.
* @return a CacheRequest object with a WriteableByteChannel if the resource
* has to be cached, {@code null} otherwise.
@@ -89,5 +89,5 @@ public abstract class ResponseCache {
* @throws IllegalArgumentException
* if any one of the parameters is set to {@code null}.
*/
- public abstract CacheRequest put(URI uri, URLConnection conn) throws IOException;
+ public abstract CacheRequest put(URI uri, URLConnection connection) throws IOException;
}
diff --git a/luni/src/main/java/java/net/ServerSocket.java b/luni/src/main/java/java/net/ServerSocket.java
index e7e7f9f..edce448 100644
--- a/luni/src/main/java/java/net/ServerSocket.java
+++ b/luni/src/main/java/java/net/ServerSocket.java
@@ -487,14 +487,7 @@ public class ServerSocket {
}
/**
- * Sets the server socket receive buffer size {@code
- * SocketOptions.SO_RCVBUF}.
- *
- * @param size
- * the buffer size in bytes.
- * @throws SocketException
- * if an error occurs while setting the size or the size is
- * invalid.
+ * Sets this socket's {@link SocketOptions#SO_SNDBUF receive buffer size}.
*/
public void setReceiveBufferSize(int size) throws SocketException {
checkClosedAndCreate(true);
@@ -505,12 +498,7 @@ public class ServerSocket {
}
/**
- * Gets the value for the receive buffer size socket option {@code
- * SocketOptions.SO_RCVBUF}.
- *
- * @return the receive buffer size of this socket.
- * @throws SocketException
- * if an error occurs while reading the option value.
+ * Returns this socket's {@link SocketOptions#SO_RCVBUF receive buffer size}.
*/
public int getReceiveBufferSize() throws SocketException {
checkClosedAndCreate(true);
@@ -518,11 +506,11 @@ public class ServerSocket {
}
/**
- * Gets the related channel if this instance was created by a
- * {@code ServerSocketChannel}. The current implementation returns always {@code
- * null}.
- *
- * @return the related {@code ServerSocketChannel} if any.
+ * Returns this socket's {@code ServerSocketChannel}, if one exists. A channel is
+ * available only if this socket wraps a channel. (That is, you can go from a
+ * channel to a socket and back again, but you can't go from an arbitrary socket to a channel.)
+ * In practice, this means that the socket must have been created by
+ * {@link java.nio.channels.ServerSocketChannel#open}.
*/
public ServerSocketChannel getChannel() {
return null;
diff --git a/luni/src/main/java/java/net/Socket.java b/luni/src/main/java/java/net/Socket.java
index f578a25..39abdbe 100644
--- a/luni/src/main/java/java/net/Socket.java
+++ b/luni/src/main/java/java/net/Socket.java
@@ -42,10 +42,7 @@ public class Socket {
private InetAddress localAddress = Inet4Address.ANY;
- private static class ConnectLock {
- }
-
- private final Object connectLock = new ConnectLock();
+ private final Object connectLock = new Object();
/**
* Creates a new unconnected socket. When a SocketImplFactory is defined it
@@ -88,10 +85,10 @@ public class Socket {
throw new IllegalArgumentException("Proxy is null or invalid type");
}
InetSocketAddress address = (InetSocketAddress) proxy.address();
- if (null != address) {
+ if (address != null) {
InetAddress addr = address.getAddress();
String host;
- if (null != addr) {
+ if (addr != null) {
host = addr.getHostAddress();
} else {
host = address.getHostName();
@@ -102,7 +99,6 @@ public class Socket {
this.impl = factory != null ? factory.createSocketImpl() : new PlainSocketImpl(proxy);
}
- // BEGIN android-added
/**
* Tries to connect a socket to all IP addresses of the given hostname.
*
@@ -149,7 +145,6 @@ public class Socket {
checkDestination(dstAddress, dstPort);
startupSocket(dstAddress, dstPort, localAddress, localPort, streaming);
}
- // END android-added
/**
* Creates a new streaming socket connected to the target host specified by
@@ -377,10 +372,8 @@ public class Socket {
}
/**
- * Gets the IP address of the target host this socket is connected to.
- *
- * @return the IP address of the connected target host or {@code null} if
- * this socket is not yet connected.
+ * Returns the IP address of the target host this socket is connected to, or null if this
+ * socket is not yet connected.
*/
public InetAddress getInetAddress() {
if (!isConnected()) {
@@ -390,7 +383,7 @@ public class Socket {
}
/**
- * Gets an input stream to read data from this socket.
+ * Returns an input stream to read data from this socket.
*
* @return the byte-oriented input stream.
* @throws IOException
@@ -406,13 +399,7 @@ public class Socket {
}
/**
- * Gets the setting of the socket option {@code SocketOptions.SO_KEEPALIVE}.
- *
- * @return {@code true} if the {@code SocketOptions.SO_KEEPALIVE} is
- * enabled, {@code false} otherwise.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_KEEPALIVE
+ * Returns this socket's {@link SocketOptions#SO_KEEPALIVE} setting.
*/
public boolean getKeepAlive() throws SocketException {
checkOpenAndCreate(true);
@@ -438,7 +425,7 @@ public class Socket {
}
/**
- * Gets an output stream to write data into this socket.
+ * Returns an output stream to write data into this socket.
*
* @return the byte-oriented output stream.
* @throws IOException
@@ -454,10 +441,8 @@ public class Socket {
}
/**
- * Gets the port number of the target host this socket is connected to.
- *
- * @return the port number of the connected target host or {@code 0} if this
- * socket is not yet connected.
+ * Returns the port number of the target host this socket is connected to, or 0 if this socket
+ * is not yet connected.
*/
public int getPort() {
if (!isConnected()) {
@@ -467,13 +452,8 @@ public class Socket {
}
/**
- * Gets the value of the socket option {@link SocketOptions#SO_LINGER}.
- *
- * @return the current value of the option {@code SocketOptions.SO_LINGER}
- * or {@code -1} if this option is disabled.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_LINGER
+ * Returns this socket's {@link SocketOptions#SO_LINGER linger} timeout in seconds, or -1
+ * for no linger (i.e. {@code close} will return immediately).
*/
public int getSoLinger() throws SocketException {
checkOpenAndCreate(true);
@@ -487,12 +467,7 @@ public class Socket {
}
/**
- * Gets the receive buffer size of this socket.
- *
- * @return the current value of the option {@code SocketOptions.SO_RCVBUF}.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_RCVBUF
+ * Returns this socket's {@link SocketOptions#SO_RCVBUF receive buffer size}.
*/
public synchronized int getReceiveBufferSize() throws SocketException {
checkOpenAndCreate(true);
@@ -500,12 +475,7 @@ public class Socket {
}
/**
- * Gets the send buffer size of this socket.
- *
- * @return the current value of the option {@code SocketOptions.SO_SNDBUF}.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_SNDBUF
+ * Returns this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized int getSendBufferSize() throws SocketException {
checkOpenAndCreate(true);
@@ -513,10 +483,7 @@ public class Socket {
}
/**
- * Gets the socket {@link SocketOptions#SO_TIMEOUT receive timeout}.
- *
- * @throws SocketException
- * if an error occurs while reading the socket option.
+ * Returns this socket's {@link SocketOptions#SO_TIMEOUT receive timeout}.
*/
public synchronized int getSoTimeout() throws SocketException {
checkOpenAndCreate(true);
@@ -524,13 +491,7 @@ public class Socket {
}
/**
- * Gets the setting of the socket option {@code SocketOptions.TCP_NODELAY}.
- *
- * @return {@code true} if the {@code SocketOptions.TCP_NODELAY} is enabled,
- * {@code false} otherwise.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#TCP_NODELAY
+ * Returns this socket's {@code SocketOptions#TCP_NODELAY} setting.
*/
public boolean getTcpNoDelay() throws SocketException {
checkOpenAndCreate(true);
@@ -538,13 +499,7 @@ public class Socket {
}
/**
- * Sets the state of the {@code SocketOptions.SO_KEEPALIVE} for this socket.
- *
- * @param keepAlive
- * the state whether this option is enabled or not.
- * @throws SocketException
- * if an error occurs while setting the option.
- * @see SocketOptions#SO_KEEPALIVE
+ * Sets this socket's {@link SocketOptions#SO_KEEPALIVE} option.
*/
public void setKeepAlive(boolean keepAlive) throws SocketException {
if (impl != null) {
@@ -575,15 +530,7 @@ public class Socket {
}
/**
- * Sets the send buffer size of this socket.
- *
- * @param size
- * the buffer size in bytes. This value must be a positive number
- * greater than {@code 0}.
- * @throws SocketException
- * if an error occurs while setting the size or the given value
- * is an invalid size.
- * @see SocketOptions#SO_SNDBUF
+ * Sets this socket's {@link SocketOptions#SO_SNDBUF send buffer size}.
*/
public synchronized void setSendBufferSize(int size) throws SocketException {
checkOpenAndCreate(true);
@@ -594,15 +541,7 @@ public class Socket {
}
/**
- * Sets the receive buffer size of this socket.
- *
- * @param size
- * the buffer size in bytes. This value must be a positive number
- * greater than {@code 0}.
- * @throws SocketException
- * if an error occurs while setting the size or the given value
- * is an invalid size.
- * @see SocketOptions#SO_RCVBUF
+ * Sets this socket's {@link SocketOptions#SO_SNDBUF receive buffer size}.
*/
public synchronized void setReceiveBufferSize(int size) throws SocketException {
checkOpenAndCreate(true);
@@ -613,15 +552,8 @@ public class Socket {
}
/**
- * Sets the {@link SocketOptions#SO_LINGER} timeout in seconds.
- *
- * @param on
- * the state whether this option is enabled or not.
- * @param timeout
- * the linger timeout value in seconds.
- * @throws SocketException
- * if an error occurs while setting the option.
- * @see SocketOptions#SO_LINGER
+ * Sets this socket's {@link SocketOptions#SO_LINGER linger} timeout in seconds.
+ * If {@code on} is false, {@code timeout} is irrelevant.
*/
public void setSoLinger(boolean on, int timeout) throws SocketException {
checkOpenAndCreate(true);
@@ -637,15 +569,9 @@ public class Socket {
}
/**
- * Sets the {@link SocketOptions#SO_TIMEOUT read timeout} in milliseconds for this socket.
- * This receive timeout defines the period the socket will block waiting to
- * receive data before throwing an {@code InterruptedIOException}. The value
- * {@code 0} (default) is used to set an infinite timeout. To have effect
- * this option must be set before the blocking method was called.
- *
- * @param timeout the timeout in milliseconds or 0 for no timeout.
- * @throws SocketException
- * if an error occurs while setting the option.
+ * Sets this socket's {@link SocketOptions#SO_TIMEOUT read timeout} in milliseconds.
+ * Use 0 for no timeout.
+ * To take effect, this option must be set before the blocking method was called.
*/
public synchronized void setSoTimeout(int timeout) throws SocketException {
checkOpenAndCreate(true);
@@ -656,13 +582,7 @@ public class Socket {
}
/**
- * Sets the state of the {@code SocketOptions.TCP_NODELAY} for this socket.
- *
- * @param on
- * the state whether this option is enabled or not.
- * @throws SocketException
- * if an error occurs while setting the option.
- * @see SocketOptions#TCP_NODELAY
+ * Sets this socket's {@link SocketOptions#TCP_NODELAY} option.
*/
public void setTcpNoDelay(boolean on) throws SocketException {
checkOpenAndCreate(true);
@@ -810,11 +730,9 @@ public class Socket {
}
/**
- * Gets the local address and port of this socket as a SocketAddress or
- * {@code null} if the socket is unbound. This is useful on multihomed
+ * Returns the local address and port of this socket as a SocketAddress or
+ * null if the socket is unbound. This is useful on multihomed
* hosts.
- *
- * @return the bound local socket address and port.
*/
public SocketAddress getLocalSocketAddress() {
if (!isBound()) {
@@ -824,8 +742,8 @@ public class Socket {
}
/**
- * Gets the remote address and port of this socket as a {@code
- * SocketAddress} or {@code null} if the socket is not connected.
+ * Returns the remote address and port of this socket as a {@code
+ * SocketAddress} or null if the socket is not connected.
*
* @return the remote socket address and port.
*/
@@ -1013,13 +931,7 @@ public class Socket {
}
/**
- * Sets the state of the {@code SocketOptions.SO_REUSEADDR} for this socket.
- *
- * @param reuse
- * the state whether this option is enabled or not.
- * @throws SocketException
- * if an error occurs while setting the option.
- * @see SocketOptions#SO_REUSEADDR
+ * Sets this socket's {@link SocketOptions#SO_REUSEADDR} option.
*/
public void setReuseAddress(boolean reuse) throws SocketException {
checkOpenAndCreate(true);
@@ -1027,13 +939,7 @@ public class Socket {
}
/**
- * Gets the setting of the socket option {@code SocketOptions.SO_REUSEADDR}.
- *
- * @return {@code true} if the {@code SocketOptions.SO_REUSEADDR} is
- * enabled, {@code false} otherwise.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_REUSEADDR
+ * Returns this socket's {@link SocketOptions#SO_REUSEADDR} setting.
*/
public boolean getReuseAddress() throws SocketException {
checkOpenAndCreate(true);
@@ -1041,15 +947,7 @@ public class Socket {
}
/**
- * Sets the state of the {@code SocketOptions.SO_OOBINLINE} for this socket.
- * When this option is enabled urgent data can be received in-line with
- * normal data.
- *
- * @param oobinline
- * whether this option is enabled or not.
- * @throws SocketException
- * if an error occurs while setting the option.
- * @see SocketOptions#SO_OOBINLINE
+ * Sets this socket's {@link SocketOptions#SO_OOBINLINE} option.
*/
public void setOOBInline(boolean oobinline) throws SocketException {
checkOpenAndCreate(true);
@@ -1057,13 +955,7 @@ public class Socket {
}
/**
- * Gets the setting of the socket option {@code SocketOptions.SO_OOBINLINE}.
- *
- * @return {@code true} if the {@code SocketOptions.SO_OOBINLINE} is
- * enabled, {@code false} otherwise.
- * @throws SocketException
- * if an error occurs while reading the socket option.
- * @see SocketOptions#SO_OOBINLINE
+ * Returns this socket's {@link SocketOptions#SO_OOBINLINE} setting.
*/
public boolean getOOBInline() throws SocketException {
checkOpenAndCreate(true);
@@ -1071,10 +963,7 @@ public class Socket {
}
/**
- * Sets the {@see SocketOptions#IP_TOS} value for every packet sent by this socket.
- *
- * @throws SocketException
- * if the socket is closed or the option could not be set.
+ * Sets this socket's {@link SocketOptions#IP_TOS} value for every packet sent by this socket.
*/
public void setTrafficClass(int value) throws SocketException {
checkOpenAndCreate(true);
@@ -1086,9 +975,6 @@ public class Socket {
/**
* Returns this socket's {@see SocketOptions#IP_TOS} setting.
- *
- * @throws SocketException
- * if the socket is closed or the option is invalid.
*/
public int getTrafficClass() throws SocketException {
checkOpenAndCreate(true);
@@ -1120,14 +1006,16 @@ public class Socket {
}
private void cacheLocalAddress() {
- this.localAddress = Platform.getNetworkSystem().getSocketLocalAddress(impl.fd);
+ this.localAddress = Platform.NETWORK.getSocketLocalAddress(impl.fd);
}
/**
- * Gets the SocketChannel of this socket, if one is available. The current
- * implementation of this method returns always {@code null}.
- *
- * @return the related SocketChannel or {@code null} if no channel exists.
+ * Returns this socket's {@code SocketChannel}, if one exists. A channel is
+ * available only if this socket wraps a channel. (That is, you can go from a
+ * channel to a socket and back again, but you can't go from an arbitrary socket to a channel.)
+ * In practice, this means that the socket must have been created by
+ * {@link java.nio.channels.ServerSocketChannel#accept} or
+ * {@link java.nio.channels.SocketChannel#open}.
*/
public SocketChannel getChannel() {
return null;
@@ -1135,8 +1023,8 @@ public class Socket {
/**
* Sets performance preferences for connectionTime, latency and bandwidth.
- * <p>
- * This method does currently nothing.
+ *
+ * <p>This method does currently nothing.
*
* @param connectionTime
* the value representing the importance of a short connecting
diff --git a/luni/src/main/java/java/net/SocketImpl.java b/luni/src/main/java/java/net/SocketImpl.java
index 8eec68b..e3d9c04 100644
--- a/luni/src/main/java/java/net/SocketImpl.java
+++ b/luni/src/main/java/java/net/SocketImpl.java
@@ -21,7 +21,6 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import org.apache.harmony.luni.platform.INetworkSystem;
import org.apache.harmony.luni.platform.Platform;
/**
@@ -55,8 +54,6 @@ public abstract class SocketImpl implements SocketOptions {
*/
protected int localport;
- INetworkSystem netImpl = Platform.getNetworkSystem();
-
boolean streaming = true;
/**
@@ -239,9 +236,9 @@ public abstract class SocketImpl implements SocketOptions {
*/
int write(byte[] buffer, int offset, int count) throws IOException {
if (streaming) {
- return this.netImpl.write(fd, buffer, offset, count);
+ return Platform.NETWORK.write(fd, buffer, offset, count);
} else {
- return this.netImpl.send(fd, buffer, offset, count, port, address);
+ return Platform.NETWORK.send(fd, buffer, offset, count, port, address);
}
}
diff --git a/luni/src/main/java/java/net/SocketOptions.java b/luni/src/main/java/java/net/SocketOptions.java
index 71441d3..ea4a2d7 100644
--- a/luni/src/main/java/java/net/SocketOptions.java
+++ b/luni/src/main/java/java/net/SocketOptions.java
@@ -27,30 +27,35 @@ package java.net;
* @see DatagramSocketImpl
*/
public interface SocketOptions {
-
/**
- * This option specifies the behavior of the {@code close()} method if there
- * is still some buffered data to be sent while closing the socket. If the
- * value of this option is set to {@code 0} the method closes the TCP socket
- * forcefully and returns immediately. Is this value greater than {@code 0}
- * the method blocks this time in milliseconds. If all data could be sent
- * during this timeout the socket is closed normally otherwise forcefully.
- * Valid values for this option are in the range {@code 0 <= SO_LINGER <=
- * 65535}. (Larger timeouts will be treated as 65535s timeouts; roughly 18 hours.)
+ * Number of seconds to wait when closing a socket if there
+ * is still some buffered data to be sent.
+ *
+ * <p>If this option is set to 0, the TCP socket is closed forcefully and the
+ * call to {@code close} returns immediately.
+ *
+ * <p>If this option is set to a value greater than 0, the value is interpreted
+ * as the number of seconds to wait. If all data could be sent
+ * during this time, the socket is closed normally. Otherwise the connection will be
+ * closed forcefully.
+ *
+ * <p>Valid values for this option are in the range 0 to 65535 inclusive. (Larger
+ * timeouts will be treated as 65535s timeouts; roughly 18 hours.)
*/
public static final int SO_LINGER = 128;
/**
- * Timeout for blocking accept or read/receive operations (but not write/send operations).
- * The argument value is specified in milliseconds, with 0 meaning no timeout and negative
- * values not allowed.
- * An {@code InterruptedIOException} is thrown if this timeout expires.
+ * Timeout in milliseconds for blocking accept or read/receive operations (but not
+ * write/send operations). A timeout of 0 means no timeout. Negative
+ * timeouts are not allowed.
+ *
+ * <p>An {@code InterruptedIOException} is thrown if this timeout expires.
*/
public static final int SO_TIMEOUT = 4102;
/**
- * This option specifies whether data is sent immediately on this socket, as
- * a side-effect though, this could lead to a low packet efficiency. The
+ * Whether data is sent immediately on this socket.
+ * As a side-effect this could lead to low packet efficiency. The
* socket implementation uses the Nagle's algorithm to try to reach a higher
* packet efficiency if this option is disabled.
*/
@@ -61,8 +66,8 @@ public interface SocketOptions {
// For 7 see PlainDatagramSocketImpl
/**
- * This option specifies the interface which is used to send multicast
- * packets. It's only available on a {@code MulticastSocket}.
+ * The interface used to send multicast packets.
+ * This option is only available on a {@link MulticastSocket}.
*/
public static final int IP_MULTICAST_IF = 16;
@@ -83,15 +88,33 @@ public interface SocketOptions {
// 10 not currently used
/**
- * Buffer size of the outgoing channel.
+ * The size in bytes of a socket's send buffer. This must be an integer greater than 0.
+ * This is a hint to the kernel; the kernel may use a larger buffer.
+ *
+ * <p>For datagram sockets, it is implementation-defined whether packets larger than
+ * this size can be sent.
*/
public static final int SO_SNDBUF = 4097;
/**
- * Buffer size of the incoming channel.
+ * The size in bytes of a socket's receive buffer. This must be an integer greater than 0.
+ * This is a hint to the kernel; the kernel may use a larger buffer.
+ *
+ * <p>For datagram sockets, packets larger than this value will be discarded.
*/
public static final int SO_RCVBUF = 4098;
+ /**
+ * This option can be used to bind a datagram socket to a
+ * particular network interface. When this is done, only packets
+ * received on the specified interface will be processed by the
+ * socket. Packets sent via this socket will be transmitted by
+ * the specified interface. The argument to this operation is the
+ * network-interface index.
+ * @hide
+ */
+ public static final int SO_BINDTODEVICE = 8192;
+
// For 13, see DatagramSocket
/**
@@ -101,10 +124,13 @@ public interface SocketOptions {
public static final int SO_KEEPALIVE = 8;
/**
- * This option specifies the value for the Type-of-Service (TOS) field of
- * the IP header. This may be ignored by the underlying OS.
- * Values must be between 0 and 255 inclusive.
- * See <a href="http://www.ietf.org/rfc/rfc1349.txt">RFC 1349</a> for more information.
+ * This option specifies the value for the type-of-service field of the IPv4 header, or the
+ * traffic class field of the IPv6 header. These correspond to the IP_TOS and IPV6_TCLASS
+ * socket options. These may be ignored by the underlying OS. Values must be between 0 and 255
+ * inclusive.
+ *
+ * <p>See <a href="http://www.ietf.org/rfc/rfc1349.txt">RFC 1349</a> for more about IPv4
+ * and <a href="http://www.ietf.org/rfc/rfc2460.txt">RFC 2460</a> for more about IPv6.
*/
public static final int IP_TOS = 3;
@@ -121,7 +147,7 @@ public interface SocketOptions {
public static final int SO_BROADCAST = 32;
/**
- * This option specifies whether sending TCP urgent data is supported on
+ * This boolean option specifies whether sending TCP urgent data is supported on
* this socket or not.
*/
public static final int SO_OOBINLINE = 4099;
diff --git a/luni/src/main/java/java/net/SocketPermission.java b/luni/src/main/java/java/net/SocketPermission.java
index d09ae4c..a4dd942 100644
--- a/luni/src/main/java/java/net/SocketPermission.java
+++ b/luni/src/main/java/java/net/SocketPermission.java
@@ -53,7 +53,7 @@ import java.security.PermissionCollection;
* lowest or highest possible value respectively. For example:
*
* <pre>
- * {@code SocketPermission(&quot;www.company.com:7000-&quot;, &quot;connect,accept&quot;)}
+ * {@code SocketPermission("www.company.com:7000-", "connect,accept")}
* </pre>
*
* represents the permission to connect to and accept connections from {@code
@@ -427,7 +427,7 @@ public final class SocketPermission extends Permission implements Serializable {
}
return host.toLowerCase();
}
- // maybe ipv6
+ // maybe IPv6
boolean isFirstBracket = (host.charAt(0) == '[');
if (!isFirstBracket) {
// No bracket, should be in full form
diff --git a/luni/src/main/java/java/net/URI.java b/luni/src/main/java/java/net/URI.java
index 9626847..da68970 100644
--- a/luni/src/main/java/java/net/URI.java
+++ b/luni/src/main/java/java/net/URI.java
@@ -31,8 +31,6 @@ import org.apache.harmony.luni.platform.Platform;
*/
public final class URI implements Comparable<URI>, Serializable {
- private final static INetworkSystem NETWORK_SYSTEM = Platform.getNetworkSystem();
-
private static final long serialVersionUID = -6052424284110960213l;
static final String UNRESERVED = "_-!.~\'()*";
@@ -452,7 +450,7 @@ public final class URI implements Comparable<URI>, Serializable {
*
* @param forceServer true to always throw if the authority cannot be
* parsed. If false, this method may still throw for some kinds of
- * errors; this unpredictable behaviour is consistent with the RI.
+ * errors; this unpredictable behavior is consistent with the RI.
*/
private void parseAuthority(boolean forceServer) throws URISyntaxException {
if (authority == null) {
@@ -536,7 +534,7 @@ public final class URI implements Comparable<URI>, Serializable {
*
* @param forceServer true to always throw if the host cannot be parsed. If
* false, this method may still throw for some kinds of errors; this
- * unpredictable behaviour is consistent with the RI.
+ * unpredictable behavior is consistent with the RI.
*/
private boolean isValidHost(boolean forceServer, String host) throws URISyntaxException {
if (host.startsWith("[")) {
@@ -545,17 +543,14 @@ public final class URI implements Comparable<URI>, Serializable {
throw new URISyntaxException(host,
"Expected a closing square bracket for IPv6 address", 0);
}
- try {
- byte[] bytes = InetAddress.ipStringToByteArray(host);
- /*
- * The native IP parser may return 4 bytes for addresses like
- * "[::FFFF:127.0.0.1]". This is allowed, but we must not accept
- * IPv4-formatted addresses in square braces like "[127.0.0.1]".
- */
- if (bytes.length == 16 || bytes.length == 4 && host.contains(":")) {
- return true;
- }
- } catch (UnknownHostException e) {
+ byte[] bytes = InetAddress.ipStringToByteArray(host);
+ /*
+ * The native IP parser may return 4 bytes for addresses like
+ * "[::FFFF:127.0.0.1]". This is allowed, but we must not accept
+ * IPv4-formatted addresses in square braces like "[127.0.0.1]".
+ */
+ if (bytes != null && (bytes.length == 16 || bytes.length == 4 && host.contains(":"))) {
+ return true;
}
throw new URISyntaxException(host, "Malformed IPv6 address");
}
@@ -580,11 +575,9 @@ public final class URI implements Comparable<URI>, Serializable {
}
// IPv4 address
- try {
- if (InetAddress.ipStringToByteArray(host).length == 4) {
- return true;
- }
- } catch (UnknownHostException e) {
+ byte[] bytes = InetAddress.ipStringToByteArray(host);
+ if (bytes != null && bytes.length == 4) {
+ return true;
}
if (forceServer) {
diff --git a/luni/src/main/java/java/net/URL.java b/luni/src/main/java/java/net/URL.java
index 92d9446..947762b 100644
--- a/luni/src/main/java/java/net/URL.java
+++ b/luni/src/main/java/java/net/URL.java
@@ -669,13 +669,26 @@ public final class URL implements java.io.Serializable {
}
/**
+ * Encodes this URL to the equivalent URI after escaping characters that are
+ * not permitted by URI.
+ *
+ * @hide
+ */
+ public URI toURILenient() throws URISyntaxException {
+ if (strmHandler == null) {
+ throw new IllegalStateException(protocol);
+ }
+ return new URI(strmHandler.toExternalForm(this, true));
+ }
+
+ /**
* Opens a connection to the remote resource specified by this URL. The
* connection will be established through the given proxy and allows
* bidirectional data transfer.
*
* @param proxy
* the proxy through which the connection will be established.
- * @return the appropriate URLconnection instance representing the
+ * @return the appropriate URLConnection instance representing the
* connection to this URL.
* @throws IOException
* if an I/O error occurs while opening the connection.
diff --git a/luni/src/main/java/java/net/URLClassLoader.java b/luni/src/main/java/java/net/URLClassLoader.java
index aad2329..6929834 100644
--- a/luni/src/main/java/java/net/URLClassLoader.java
+++ b/luni/src/main/java/java/net/URLClassLoader.java
@@ -45,6 +45,7 @@ import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import libcore.io.IoUtils;
/**
* This class loader is responsible for loading classes and resources from a
@@ -161,20 +162,9 @@ public class URLClassLoader extends SecureClassLoader {
// Ignore this jar's index
} catch (IOException e) {
// Ignore this jar's index
- }
- finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- }
- }
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
+ } finally {
+ IoUtils.closeQuietly(in);
+ IoUtils.closeQuietly(is);
}
return null;
}
@@ -240,10 +230,7 @@ public class URLClassLoader extends SecureClassLoader {
} catch (IOException e) {
return null;
} finally {
- try {
- is.close();
- } catch (IOException e) {
- }
+ IoUtils.closeQuietly(is);
}
if (packageName != null) {
String packageDotName = packageName.replace('/', '.');
@@ -401,12 +388,7 @@ public class URLClassLoader extends SecureClassLoader {
} catch (IOException e) {
return null;
} finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- }
- }
+ IoUtils.closeQuietly(is);
}
if (packageName != null) {
String packageDotName = packageName.replace('/', '.');
diff --git a/luni/src/main/java/java/net/URLStreamHandler.java b/luni/src/main/java/java/net/URLStreamHandler.java
index dae193b..f132243 100644
--- a/luni/src/main/java/java/net/URLStreamHandler.java
+++ b/luni/src/main/java/java/net/URLStreamHandler.java
@@ -18,6 +18,8 @@
package java.net;
import java.io.IOException;
+import java.nio.charset.Charsets;
+import java.util.Locale;
import libcore.base.Objects;
import org.apache.harmony.luni.util.URLUtil;
@@ -113,12 +115,11 @@ public abstract class URLStreamHandler {
int refIdx = parseString.indexOf('#', 0);
if (parseString.startsWith("//")) {
- int hostIdx = 2, portIdx = -1;
+ int hostIdx = 2;
port = -1;
fileIdx = parseString.indexOf('/', hostIdx);
int questionMarkIndex = parseString.indexOf('?', hostIdx);
- if ((questionMarkIndex != -1)
- && ((fileIdx == -1) || (fileIdx > questionMarkIndex))) {
+ if (questionMarkIndex != -1 && (fileIdx == -1 || fileIdx > questionMarkIndex)) {
fileIdx = questionMarkIndex;
}
if (fileIdx == -1) {
@@ -129,36 +130,33 @@ public abstract class URLStreamHandler {
int hostEnd = fileIdx;
if (refIdx != -1 && refIdx < fileIdx) {
hostEnd = refIdx;
+ fileIdx = refIdx;
+ file = "";
}
int userIdx = parseString.lastIndexOf('@', hostEnd);
authority = parseString.substring(hostIdx, hostEnd);
- if (userIdx > -1) {
+ if (userIdx != -1) {
userInfo = parseString.substring(hostIdx, userIdx);
hostIdx = userIdx + 1;
}
- portIdx = parseString.indexOf(':', userIdx == -1 ? hostIdx
- : userIdx);
- int endOfIPv6Addr = parseString.indexOf(']');
- // if there are square braces, ie. IPv6 address, use last ':'
+ int endOfIPv6Addr = parseString.indexOf(']', hostIdx);
+ if (endOfIPv6Addr >= hostEnd) {
+ endOfIPv6Addr = -1;
+ }
+
+ // the port separator must be immediately after an IPv6 address "http://[::1]:80/"
+ int portIdx = -1;
if (endOfIPv6Addr != -1) {
- try {
- if (parseString.length() > endOfIPv6Addr + 1) {
- char c = parseString.charAt(endOfIPv6Addr + 1);
- if (c == ':') {
- portIdx = endOfIPv6Addr + 1;
- } else {
- portIdx = -1;
- }
- } else {
- portIdx = -1;
- }
- } catch (Exception e) {
- // Ignored
+ int maybeColon = endOfIPv6Addr + 1;
+ if (maybeColon < hostEnd && parseString.charAt(maybeColon) == ':') {
+ portIdx = maybeColon;
}
+ } else {
+ portIdx = parseString.indexOf(':', hostIdx);
}
- if (portIdx == -1 || portIdx > fileIdx) {
+ if (portIdx == -1 || portIdx > hostEnd) {
host = parseString.substring(hostIdx, hostEnd);
} else {
host = parseString.substring(hostIdx, portIdx);
@@ -303,25 +301,118 @@ public abstract class URLStreamHandler {
* @see URL#toExternalForm()
*/
protected String toExternalForm(URL url) {
- StringBuilder answer = new StringBuilder();
- answer.append(url.getProtocol());
- answer.append(':');
+ return toExternalForm(url, false);
+ }
+
+ String toExternalForm(URL url, boolean escapeIllegalCharacters) {
+ StringBuilder result = new StringBuilder();
+ result.append(url.getProtocol());
+ result.append(':');
+
String authority = url.getAuthority();
- if (authority != null && authority.length() > 0) {
- answer.append("//");
- answer.append(url.getAuthority());
+ if (authority != null && !authority.isEmpty()) {
+ result.append("//");
+ if (escapeIllegalCharacters) {
+ authority = fixEncoding(authority, "$,;@&=+:[]");
+ }
+ result.append(authority);
}
- String file = url.getFile();
- String ref = url.getRef();
- if (file != null) {
- answer.append(file);
+ String fileAndQuery = url.getFile();
+ if (fileAndQuery != null) {
+ if (escapeIllegalCharacters) {
+ fileAndQuery = fixEncoding(fileAndQuery, "$,;@&=+:/?");
+ }
+ result.append(fileAndQuery);
}
+
+ String ref = url.getRef();
if (ref != null) {
- answer.append('#');
- answer.append(ref);
+ result.append('#');
+ if (escapeIllegalCharacters) {
+ ref = fixEncoding(ref, "$,;@&=+:/?[]");
+ }
+ result.append(ref);
}
- return answer.toString();
+
+ return result.toString();
+ }
+
+ /**
+ * Escapes the unescaped characters of {@code s} that are not permitted.
+ * Permitted characters are:
+ * <ul>
+ * <li>Unreserved characters in RFC 2396.
+ * <li>{@code extraOkayChars},
+ * <li>non-ASCII, non-control, non-whitespace characters
+ * </ul>
+ *
+ * <p>Unlike the methods in {@code URI}, this method ignores input that has
+ * already been escaped. For example, input of "hello%20world" is unchanged
+ * by this method but would be double-escaped to "hello%2520world" by URI.
+ *
+ * <p>UTF-8 is used to encode escaped characters. A single input character
+ * like "\u0080" may be encoded to multiple octets like %C2%80.
+ */
+ private String fixEncoding(String s, String extraPermittedChars) {
+ StringBuilder result = null;
+ int copiedCount = 0;
+
+ for (int i = 0; i < s.length(); i++) {
+ char c = s.charAt(i);
+
+ if (c == '%') {
+ i += 2; // this is a 3-character sequence like "%20"
+ continue;
+ }
+
+ // unreserved characters: alphanum | mark
+ if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'
+ || c == '-' || c == '_' || c == '.' || c == '!' || c == '~'
+ || c == '*' || c == '\'' || c == '(' || c == ')') {
+ continue;
+ }
+
+ // characters permitted in this context
+ if (extraPermittedChars.indexOf(c) != -1) {
+ continue;
+ }
+
+ // other characters
+ if (c > 0x7f && !Character.isISOControl(c) && !Character.isSpaceChar(c)) {
+ continue;
+ }
+
+ /*
+ * We've encountered a character that must be escaped.
+ */
+ if (result == null) {
+ result = new StringBuilder();
+ }
+ result.append(s, copiedCount, i);
+
+ if (c < 0x7f) {
+ appendHex(result, c);
+ } else {
+ for (byte b : s.substring(i, i + 1).getBytes(Charsets.UTF_8)) {
+ appendHex(result, b & 0xff);
+ }
+ }
+
+ copiedCount = i + 1;
+ }
+
+ if (result == null) {
+ return s;
+ } else {
+ result.append(s, copiedCount, s.length());
+ return result.toString();
+ }
+ }
+
+ private void appendHex(StringBuilder stringBuilder, int b) {
+ String hex = Integer.toHexString(b).toUpperCase(Locale.US);
+ stringBuilder.append(hex.length() == 1 ? "%0" : "%").append(hex); // always 2 hex digits
}
/**
diff --git a/luni/src/main/java/java/net/UnknownHostException.java b/luni/src/main/java/java/net/UnknownHostException.java
index 325d36d..876593b 100644
--- a/luni/src/main/java/java/net/UnknownHostException.java
+++ b/luni/src/main/java/java/net/UnknownHostException.java
@@ -20,23 +20,24 @@ package java.net;
import java.io.IOException;
/**
- * Is thrown when a hostname can not be resolved.
+ * Thrown when a hostname can not be resolved.
*/
public class UnknownHostException extends IOException {
private static final long serialVersionUID = -4639126076052875403L;
/**
- * Constructs a new {@code UnknownHostException} instance with its walkback
- * filled in.
+ * Constructs a new {@code UnknownHostException} instance with no detail message.
+ * Callers should usually supply a detail message.
*/
public UnknownHostException() {
super();
}
/**
- * Constructs a new {@code UnknownHostException} instance with its walkback
- * and message filled in.
+ * Constructs a new {@code UnknownHostException} instance with the given detail message.
+ * The detail message should generally contain the hostname and a reason for the failure,
+ * if known.
*
* @param detailMessage
* the detail message for this exception.
diff --git a/luni/src/main/java/java/nio/BaseByteBuffer.java b/luni/src/main/java/java/nio/BaseByteBuffer.java
index ba086a8..d6cfb93 100644
--- a/luni/src/main/java/java/nio/BaseByteBuffer.java
+++ b/luni/src/main/java/java/nio/BaseByteBuffer.java
@@ -22,57 +22,57 @@ package java.nio;
*/
abstract class BaseByteBuffer extends ByteBuffer {
- protected BaseByteBuffer(int capacity) {
- super(capacity);
+ protected BaseByteBuffer(int capacity, MemoryBlock block) {
+ super(capacity, block);
}
@Override
public final CharBuffer asCharBuffer() {
- return CharToByteBufferAdapter.wrap(this);
+ return CharToByteBufferAdapter.asCharBuffer(this);
}
@Override
public final DoubleBuffer asDoubleBuffer() {
- return DoubleToByteBufferAdapter.wrap(this);
+ return DoubleToByteBufferAdapter.asDoubleBuffer(this);
}
@Override
public final FloatBuffer asFloatBuffer() {
- return FloatToByteBufferAdapter.wrap(this);
+ return FloatToByteBufferAdapter.asFloatBuffer(this);
}
@Override
public final IntBuffer asIntBuffer() {
- return IntToByteBufferAdapter.wrap(this);
+ return IntToByteBufferAdapter.asIntBuffer(this);
}
@Override
public final LongBuffer asLongBuffer() {
- return LongToByteBufferAdapter.wrap(this);
+ return LongToByteBufferAdapter.asLongBuffer(this);
}
@Override
public final ShortBuffer asShortBuffer() {
- return ShortToByteBufferAdapter.wrap(this);
+ return ShortToByteBufferAdapter.asShortBuffer(this);
}
@Override
- public final char getChar() {
+ public char getChar() {
return (char) getShort();
}
@Override
- public final char getChar(int index) {
+ public char getChar(int index) {
return (char) getShort(index);
}
@Override
- public final ByteBuffer putChar(char value) {
+ public ByteBuffer putChar(char value) {
return putShort((short) value);
}
@Override
- public final ByteBuffer putChar(int index, char value) {
+ public ByteBuffer putChar(int index, char value) {
return putShort(index, (short) value);
}
}
diff --git a/luni/src/main/java/java/nio/Buffer.java b/luni/src/main/java/java/nio/Buffer.java
index e141ea0..c0ba368 100644
--- a/luni/src/main/java/java/nio/Buffer.java
+++ b/luni/src/main/java/java/nio/Buffer.java
@@ -45,11 +45,10 @@ package java.nio;
* synchronization issues.
*/
public abstract class Buffer {
-
/**
* <code>UNSET_MARK</code> means the mark has not been set.
*/
- final static int UNSET_MARK = -1;
+ static final int UNSET_MARK = -1;
/**
* The capacity of this buffer, which never changes.
@@ -75,38 +74,33 @@ public abstract class Buffer {
*/
int position = 0;
- // BEGIN android-added
/**
* The log base 2 of the element size of this buffer. Each typed subclass
* (ByteBuffer, CharBuffer, etc.) is responsible for initializing this
* value. The value is used by JNI code in frameworks/base/ to avoid the
* need for costly 'instanceof' tests.
*/
- int _elementSizeShift;
+ final int _elementSizeShift;
/**
- * For direct buffers, the effective address of the data. This is set
- * on first use. If the field is zero, this is either not a direct
- * buffer or the field has not been initialized, and you need to issue
- * the getEffectiveAddress() call and use the result of that.
- *
- * This is an optimization used by the GetDirectBufferAddress JNI call.
+ * For direct buffers, the effective address of the data; zero otherwise.
+ * This is set in the constructor.
+ * TODO: make this final at the cost of loads of extra constructors? [how many?]
*/
- int effectiveDirectAddress = 0;
- // END android-added
+ int effectiveDirectAddress;
/**
- * Construct a buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of this buffer
+ * For direct buffers, the underlying MemoryBlock; null otherwise.
*/
- Buffer(int capacity) {
- super();
+ final MemoryBlock block;
+
+ Buffer(int elementSizeShift, int capacity, MemoryBlock block) {
+ this._elementSizeShift = elementSizeShift;
if (capacity < 0) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("capacity < 0: " + capacity);
}
this.capacity = this.limit = capacity;
+ this.block = block;
}
/**
@@ -155,6 +149,59 @@ public abstract class Buffer {
}
/**
+ * Used for the scalar get/put operations.
+ */
+ void checkIndex(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException("index=" + index + ", limit=" + limit);
+ }
+ }
+
+ /**
+ * Used for the ByteBuffer operations that get types larger than a byte.
+ */
+ void checkIndex(int index, int sizeOfType) {
+ if (index < 0 || index > limit - sizeOfType) {
+ throw new IndexOutOfBoundsException("index=" + index + ", limit=" + limit +
+ ", size of type=" + sizeOfType);
+ }
+ }
+
+ int checkGetBounds(int bytesPerElement, int length, int offset, int count) {
+ int byteCount = bytesPerElement * count;
+ if ((offset | count) < 0 || offset > length || length - offset < count) {
+ throw new IndexOutOfBoundsException("offset=" + offset +
+ ", count=" + count + ", length=" + length);
+ }
+ if (byteCount > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ return byteCount;
+ }
+
+ int checkPutBounds(int bytesPerElement, int length, int offset, int count) {
+ int byteCount = bytesPerElement * count;
+ if ((offset | count) < 0 || offset > length || length - offset < count) {
+ throw new IndexOutOfBoundsException("offset=" + offset +
+ ", count=" + count + ", length=" + length);
+ }
+ if (byteCount > remaining()) {
+ throw new BufferOverflowException();
+ }
+ if (isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ return byteCount;
+ }
+
+ void checkStartEndRemaining(int start, int end) {
+ if (end < start || start < 0 || end > remaining()) {
+ throw new IndexOutOfBoundsException("start=" + start + ", end=" + end +
+ ", remaining()=" + remaining());
+ }
+ }
+
+ /**
* Clears this buffer.
* <p>
* While the content of this buffer is not changed, the following internal
@@ -247,6 +294,14 @@ public abstract class Buffer {
* if <code>newLimit</code> is invalid.
*/
public final Buffer limit(int newLimit) {
+ limitImpl(newLimit);
+ return this;
+ }
+
+ /**
+ * Subverts the fact that limit(int) is final, for the benefit of MappedByteBufferAdapter.
+ */
+ void limitImpl(int newLimit) {
if (newLimit < 0 || newLimit > capacity) {
throw new IllegalArgumentException();
}
@@ -258,7 +313,6 @@ public abstract class Buffer {
if ((mark != UNSET_MARK) && (mark > newLimit)) {
mark = UNSET_MARK;
}
- return this;
}
/**
@@ -295,6 +349,11 @@ public abstract class Buffer {
* if <code>newPosition</code> is invalid.
*/
public final Buffer position(int newPosition) {
+ positionImpl(newPosition);
+ return this;
+ }
+
+ void positionImpl(int newPosition) {
if (newPosition < 0 || newPosition > limit) {
throw new IllegalArgumentException();
}
@@ -303,7 +362,6 @@ public abstract class Buffer {
if ((mark != UNSET_MARK) && (mark > position)) {
mark = UNSET_MARK;
}
- return this;
}
/**
@@ -344,4 +402,16 @@ public abstract class Buffer {
mark = UNSET_MARK;
return this;
}
+
+ @Override public String toString() {
+ StringBuilder buf = new StringBuilder();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity=");
+ buf.append(capacity);
+ buf.append(" position=");
+ buf.append(position);
+ buf.append(" limit=");
+ buf.append(limit);
+ return buf.toString();
+ }
}
diff --git a/luni/src/main/java/java/nio/BufferFactory.java b/luni/src/main/java/java/nio/BufferFactory.java
deleted file mode 100644
index 6783d63..0000000
--- a/luni/src/main/java/java/nio/BufferFactory.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.nio;
-
-/**
- * Provide factory service of buffer classes.
- * <p>
- * Since all buffer impl classes are package private (except DirectByteBuffer),
- * this factory is the only entrance to access buffer functions from outside of
- * the impl package.
- * </p>
- */
-final class BufferFactory {
-
- /**
- * Returns a new byte buffer based on the specified byte array.
- *
- * @param array
- * The byte array
- * @return A new byte buffer based on the specified byte array.
- */
- public static ByteBuffer newByteBuffer(byte[] array) {
- return new ReadWriteHeapByteBuffer(array);
- }
-
- /**
- * Returns a new array based byte buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based byte buffer with the specified capacity.
- */
- public static ByteBuffer newByteBuffer(int capacity) {
- return new ReadWriteHeapByteBuffer(capacity);
- }
-
- /**
- * Returns a new char buffer based on the specified char array.
- *
- * @param array
- * The char array
- * @return A new char buffer based on the specified char array.
- */
- public static CharBuffer newCharBuffer(char[] array) {
- return new ReadWriteCharArrayBuffer(array);
- }
-
- /**
- * Returns a new readonly char buffer based on the specified char sequence.
- *
- * @param chseq
- * The char sequence
- * @return A new readonly char buffer based on the specified char sequence.
- */
- public static CharBuffer newCharBuffer(CharSequence chseq) {
- return new CharSequenceAdapter(chseq);
- }
-
- /**
- * Returns a new array based char buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based char buffer with the specified capacity.
- */
- public static CharBuffer newCharBuffer(int capacity) {
- return new ReadWriteCharArrayBuffer(capacity);
- }
-
- /**
- * Returns a new direct byte buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new direct byte buffer with the specified capacity.
- */
- public static ByteBuffer newDirectByteBuffer(int capacity) {
- return new ReadWriteDirectByteBuffer(capacity);
- }
-
- /**
- * Returns a new double buffer based on the specified double array.
- *
- * @param array
- * The double array
- * @return A new double buffer based on the specified double array.
- */
- public static DoubleBuffer newDoubleBuffer(double[] array) {
- return new ReadWriteDoubleArrayBuffer(array);
- }
-
- /**
- * Returns a new array based double buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based double buffer with the specified capacity.
- */
- public static DoubleBuffer newDoubleBuffer(int capacity) {
- return new ReadWriteDoubleArrayBuffer(capacity);
- }
-
- /**
- * Returns a new float buffer based on the specified float array.
- *
- * @param array
- * The float array
- * @return A new float buffer based on the specified float array.
- */
- public static FloatBuffer newFloatBuffer(float[] array) {
- return new ReadWriteFloatArrayBuffer(array);
- }
-
- /**
- * Returns a new array based float buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based float buffer with the specified capacity.
- */
- public static FloatBuffer newFloatBuffer(int capacity) {
- return new ReadWriteFloatArrayBuffer(capacity);
- }
-
- /**
- * Returns a new array based int buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based int buffer with the specified capacity.
- */
- public static IntBuffer newIntBuffer(int capacity) {
- return new ReadWriteIntArrayBuffer(capacity);
- }
-
- /**
- * Returns a new int buffer based on the specified int array.
- *
- * @param array
- * The int array
- * @return A new int buffer based on the specified int array.
- */
- public static IntBuffer newIntBuffer(int[] array) {
- return new ReadWriteIntArrayBuffer(array);
- }
-
- /**
- * Returns a new array based long buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based long buffer with the specified capacity.
- */
- public static LongBuffer newLongBuffer(int capacity) {
- return new ReadWriteLongArrayBuffer(capacity);
- }
-
- /**
- * Returns a new long buffer based on the specified long array.
- *
- * @param array
- * The long array
- * @return A new long buffer based on the specified long array.
- */
- public static LongBuffer newLongBuffer(long[] array) {
- return new ReadWriteLongArrayBuffer(array);
- }
-
- /**
- * Returns a new array based short buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based short buffer with the specified capacity.
- */
- public static ShortBuffer newShortBuffer(int capacity) {
- return new ReadWriteShortArrayBuffer(capacity);
- }
-
- /**
- * Returns a new short buffer based on the specified short array.
- *
- * @param array
- * The short array
- * @return A new short buffer based on the specified short array.
- */
- public static ShortBuffer newShortBuffer(short[] array) {
- return new ReadWriteShortArrayBuffer(array);
- }
-
-}
diff --git a/luni/src/main/java/java/nio/ByteBuffer.java b/luni/src/main/java/java/nio/ByteBuffer.java
index e83a709..c539f76 100644
--- a/luni/src/main/java/java/nio/ByteBuffer.java
+++ b/luni/src/main/java/java/nio/ByteBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer for bytes.
* <p>
@@ -46,7 +48,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newByteBuffer(capacity);
+ return new ReadWriteHeapByteBuffer(capacity);
}
/**
@@ -62,7 +64,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newDirectByteBuffer(capacity);
+ return new ReadWriteDirectByteBuffer(capacity);
}
/**
@@ -76,37 +78,32 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* @return the created byte buffer.
*/
public static ByteBuffer wrap(byte[] array) {
- return BufferFactory.newByteBuffer(array);
+ return new ReadWriteHeapByteBuffer(array);
}
/**
* Creates a new byte buffer by wrapping the given byte array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + byteCount}, capacity will be the length of the array.
*
* @param array
* the byte array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param byteCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created byte buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code byteCount} is invalid.
*/
- public static ByteBuffer wrap(byte[] array, int start, int len) {
- int length = array.length;
- if ((start < 0) || (len < 0) || ((long) start + (long) len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- ByteBuffer buf = BufferFactory.newByteBuffer(array);
+ public static ByteBuffer wrap(byte[] array, int start, int byteCount) {
+ Arrays.checkOffsetAndCount(array.length, start, byteCount);
+ ByteBuffer buf = new ReadWriteHeapByteBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + byteCount;
return buf;
}
@@ -115,15 +112,8 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*/
ByteOrder order = ByteOrder.BIG_ENDIAN;
- /**
- * Constructs a {@code ByteBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
- ByteBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 0;
+ ByteBuffer(int capacity, MemoryBlock block) {
+ super(0, capacity, block);
}
/**
@@ -282,7 +272,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code remaining()}; the limit is set to capacity; the mark is
* cleared.
*
- * @return this buffer.
+ * @return {@code this}
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
@@ -385,7 +375,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param dst
* the destination byte array.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferUnderflowException
* if {@code dst.length} is greater than {@code remaining()}.
*/
@@ -400,28 +390,22 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param dst
* the target byte array.
- * @param off
+ * @param dstOffset
* the offset of the byte array, must not be negative and
* not greater than {@code dst.length}.
- * @param len
+ * @param byteCount
* the number of bytes to read, must not be negative and not
- * greater than {@code dst.length - off}
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- */
- public ByteBuffer get(byte[] dst, int off, int len) {
- int length = dst.length;
- if ((off < 0) || (len < 0) || ((long) off + (long) len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ * greater than {@code dst.length - dstOffset}
+ * @return {@code this}
+ * @exception IndexOutOfBoundsException if {@code dstOffset < 0 || byteCount < 0}
+ * @exception BufferUnderflowException if {@code byteCount > remaining()}
+ */
+ public ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, byteCount);
+ if (byteCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + byteCount; ++i) {
dst[i] = get();
}
return this;
@@ -655,19 +639,22 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* @param byteOrder
* the byte order to set. If {@code null} then the order
* will be {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}.
- * @return this buffer.
+ * @return {@code this}
* @see ByteOrder
*/
public final ByteBuffer order(ByteOrder byteOrder) {
- return orderImpl(byteOrder);
+ orderImpl(byteOrder);
+ return this;
}
- ByteBuffer orderImpl(ByteOrder byteOrder) {
+ /**
+ * Subverts the fact that order(ByteOrder) is final, for the benefit of MappedByteBufferAdapter.
+ */
+ void orderImpl(ByteOrder byteOrder) {
if (byteOrder == null) {
byteOrder = ByteOrder.LITTLE_ENDIAN;
}
order = byteOrder;
- return this;
}
/**
@@ -697,7 +684,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param b
* the byte to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is equal or greater than limit.
* @exception ReadOnlyBufferException
@@ -714,7 +701,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param src
* the source byte array.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if {@code remaining()} is less than {@code src.length}.
* @exception ReadOnlyBufferException
@@ -731,30 +718,26 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param src
* the source byte array.
- * @param off
+ * @param srcOffset
* the offset of byte array, must not be negative and not greater
* than {@code src.length}.
- * @param len
+ * @param byteCount
* the number of bytes to write, must not be negative and not
- * greater than {@code src.length - off}.
- * @return this buffer.
+ * greater than {@code src.length - srcOffset}.
+ * @return {@code this}
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code byteCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code byteCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public ByteBuffer put(byte[] src, int off, int len) {
- int length = src.length;
- if ((off < 0 ) || (len < 0) || ((long)off + (long)len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, byteCount);
+ if (byteCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + byteCount; ++i) {
put(src[i]);
}
return this;
@@ -767,7 +750,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param src
* the source byte buffer.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if {@code src.remaining()} is greater than this buffer's
* {@code remaining()}.
@@ -797,7 +780,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* the index, must not be negative and less than the limit.
* @param b
* the byte to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -813,7 +796,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the char to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 2}.
* @exception ReadOnlyBufferException
@@ -832,7 +815,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 2}.
* @param value
* the char to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -848,7 +831,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the double to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 8}.
* @exception ReadOnlyBufferException
@@ -867,7 +850,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 8}.
* @param value
* the double to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -883,7 +866,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the float to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 4}.
* @exception ReadOnlyBufferException
@@ -902,7 +885,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 4}.
* @param value
* the float to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -918,7 +901,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the int to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 4}.
* @exception ReadOnlyBufferException
@@ -937,7 +920,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 4}.
* @param value
* the int to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -953,7 +936,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the long to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 8}.
* @exception ReadOnlyBufferException
@@ -972,7 +955,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 8}.
* @param value
* the long to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -988,7 +971,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
*
* @param value
* the short to write.
- * @return this buffer.
+ * @return {@code this}
* @exception BufferOverflowException
* if position is greater than {@code limit - 2}.
* @exception ReadOnlyBufferException
@@ -1007,7 +990,7 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* {@code limit - 2}.
* @param value
* the short to write.
- * @return this buffer.
+ * @return {@code this}
* @exception IndexOutOfBoundsException
* if {@code index} is invalid.
* @exception ReadOnlyBufferException
@@ -1031,22 +1014,4 @@ public abstract class ByteBuffer extends Buffer implements Comparable<ByteBuffer
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract ByteBuffer slice();
-
- /**
- * Returns a string representing the state of this byte buffer.
- *
- * @return a string representing the state of this byte buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/ByteOrder.java b/luni/src/main/java/java/nio/ByteOrder.java
index 5e9a19a..286c970 100644
--- a/luni/src/main/java/java/nio/ByteOrder.java
+++ b/luni/src/main/java/java/nio/ByteOrder.java
@@ -20,24 +20,40 @@ package java.nio;
* Defines byte order constants.
*/
public final class ByteOrder {
+ private static final ByteOrder NATIVE_ORDER;
+
/**
* This constant represents big endian.
*/
- public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN");
+ public static final ByteOrder BIG_ENDIAN;
/**
* This constant represents little endian.
*/
- public static final ByteOrder LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN");
-
- private static final ByteOrder NATIVE_ORDER = isLittleEndian() ? LITTLE_ENDIAN : BIG_ENDIAN;
+ public static final ByteOrder LITTLE_ENDIAN;
private static native boolean isLittleEndian();
+ static {
+ boolean isLittleEndian = isLittleEndian();
+ BIG_ENDIAN = new ByteOrder("BIG_ENDIAN", isLittleEndian);
+ LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN", !isLittleEndian);
+ NATIVE_ORDER = isLittleEndian ? LITTLE_ENDIAN : BIG_ENDIAN;
+ }
+
private final String name;
- private ByteOrder(String name) {
+ /**
+ * This is the only thing that ByteOrder is really used for: to know whether we need to swap
+ * bytes to get this order, given bytes in native order. (That is, this is the opposite of
+ * the hypothetical "isNativeOrder".)
+ * @hide - needed in libcore.io too.
+ */
+ public final boolean needsSwap;
+
+ private ByteOrder(String name, boolean needsSwap) {
this.name = name;
+ this.needsSwap = needsSwap;
}
/**
diff --git a/luni/src/main/java/java/nio/CharArrayBuffer.java b/luni/src/main/java/java/nio/CharArrayBuffer.java
index d7b2267..53d7fb6 100644
--- a/luni/src/main/java/java/nio/CharArrayBuffer.java
+++ b/luni/src/main/java/java/nio/CharArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class CharArrayBuffer extends CharBuffer {
@Override
public final char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final CharBuffer get(char[] dst, int off, int len) {
- int length = dst.length;
- if ((off < 0) || (len < 0) || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final CharBuffer get(char[] dst, int srcOffset, int charCount) {
+ if (charCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, srcOffset, charCount);
+ position += charCount;
return this;
}
@@ -91,10 +85,7 @@ abstract class CharArrayBuffer extends CharBuffer {
@Override
public final CharSequence subSequence(int start, int end) {
- if (start < 0 || end < start || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
+ checkStartEndRemaining(start, end);
CharBuffer result = duplicate();
result.limit(position + end);
result.position(position + start);
diff --git a/luni/src/main/java/java/nio/CharBuffer.java b/luni/src/main/java/java/nio/CharBuffer.java
index 467e08f..cb041f5 100644
--- a/luni/src/main/java/java/nio/CharBuffer.java
+++ b/luni/src/main/java/java/nio/CharBuffer.java
@@ -18,6 +18,7 @@
package java.nio;
import java.io.IOException;
+import java.util.Arrays;
/**
* A buffer of chars.
@@ -50,7 +51,7 @@ public abstract class CharBuffer extends Buffer implements
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newCharBuffer(capacity);
+ return new ReadWriteCharArrayBuffer(capacity);
}
/**
@@ -71,30 +72,25 @@ public abstract class CharBuffer extends Buffer implements
* Creates a new char buffer by wrapping the given char array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + charCount}, capacity will be the length of the array.
*
* @param array
* the char array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param charCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created char buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code charCount} is invalid.
*/
- public static CharBuffer wrap(char[] array, int start, int len) {
- int length = array.length;
- if ((start < 0) || (len < 0) || (long) start + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer buf = BufferFactory.newCharBuffer(array);
+ public static CharBuffer wrap(char[] array, int start, int charCount) {
+ Arrays.checkOffsetAndCount(array.length, start, charCount);
+ CharBuffer buf = new ReadWriteCharArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + charCount;
return buf;
}
@@ -109,7 +105,7 @@ public abstract class CharBuffer extends Buffer implements
* @return the created char buffer.
*/
public static CharBuffer wrap(CharSequence chseq) {
- return BufferFactory.newCharBuffer(chseq);
+ return new CharSequenceAdapter(chseq);
}
/**
@@ -119,41 +115,30 @@ public abstract class CharBuffer extends Buffer implements
* {@code end}, capacity will be the length of the char sequence. The new
* buffer is read-only.
*
- * @param chseq
+ * @param cs
* the char sequence which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
- * {@code chseq.length()}.
+ * {@code cs.length()}.
* @param end
* the end index, must be no less than {@code start} and no
- * greater than {@code chseq.length()}.
+ * greater than {@code cs.length()}.
* @return the created char buffer.
* @exception IndexOutOfBoundsException
* if either {@code start} or {@code end} is invalid.
*/
- public static CharBuffer wrap(CharSequence chseq, int start, int end) {
- if (chseq == null) {
- throw new NullPointerException();
+ public static CharBuffer wrap(CharSequence cs, int start, int end) {
+ if (start < 0 || end < start || end > cs.length()) {
+ throw new IndexOutOfBoundsException("cs.length()=" + cs.length() + ", start=" + start + ", end=" + end);
}
- if (start < 0 || end < start || end > chseq.length()) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer result = BufferFactory.newCharBuffer(chseq);
+ CharBuffer result = new CharSequenceAdapter(cs);
result.position = start;
result.limit = end;
return result;
}
- /**
- * Constructs a {@code CharBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
CharBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 1;
+ super(1, capacity, null);
}
public final char[] array() {
@@ -194,7 +179,7 @@ public abstract class CharBuffer extends Buffer implements
*/
public final char charAt(int index) {
if (index < 0 || index >= remaining()) {
- throw new IndexOutOfBoundsException();
+ throw new IndexOutOfBoundsException("index=" + index + ", remaining()=" + remaining());
}
return get(position + index);
}
@@ -324,28 +309,24 @@ public abstract class CharBuffer extends Buffer implements
*
* @param dst
* the target char array.
- * @param off
+ * @param dstOffset
* the offset of the char array, must not be negative and not
* greater than {@code dst.length}.
- * @param len
+ * @param charCount
* The number of chars to read, must be no less than zero and no
- * greater than {@code dst.length - off}.
+ * greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code charCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code charCount} is greater than {@code remaining()}.
*/
- public CharBuffer get(char[] dst, int off, int len) {
- int length = dst.length;
- if ((off < 0) || (len < 0) || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public CharBuffer get(char[] dst, int dstOffset, int charCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, charCount);
+ if (charCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + charCount; ++i) {
dst[i] = get();
}
return this;
@@ -476,30 +457,26 @@ public abstract class CharBuffer extends Buffer implements
*
* @param src
* the source char array.
- * @param off
+ * @param srcOffset
* the offset of char array, must not be negative and not greater
* than {@code src.length}.
- * @param len
+ * @param charCount
* the number of chars to write, must be no less than zero and no
- * greater than {@code src.length - off}.
+ * greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code charCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code charCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public CharBuffer put(char[] src, int off, int len) {
- int length = src.length;
- if ((off < 0) || (len < 0) || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public CharBuffer put(char[] src, int srcOffset, int charCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, charCount);
+ if (charCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + charCount; ++i) {
put(src[i]);
}
return this;
@@ -591,11 +568,10 @@ public abstract class CharBuffer extends Buffer implements
* if no changes may be made to the contents of this buffer.
*/
public CharBuffer put(String str, int start, int end) {
- int length = str.length();
- if (start < 0 || end < start || end > length) {
- throw new IndexOutOfBoundsException();
+ if (start < 0 || end < start || end > str.length()) {
+ throw new IndexOutOfBoundsException("str.length()=" + str.length() +
+ ", start=" + start + ", end=" + end);
}
-
if (end - start > remaining()) {
throw new BufferOverflowException();
}
diff --git a/luni/src/main/java/java/nio/CharSequenceAdapter.java b/luni/src/main/java/java/nio/CharSequenceAdapter.java
index 5ea0657..3bed096 100644
--- a/luni/src/main/java/java/nio/CharSequenceAdapter.java
+++ b/luni/src/main/java/java/nio/CharSequenceAdapter.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* This class wraps a char sequence to be a char buffer.
* <p>
@@ -69,23 +71,18 @@ final class CharSequenceAdapter extends CharBuffer {
@Override
public char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return sequence.charAt(index);
}
@Override
- public final CharBuffer get(char[] dst, int off, int len) {
- int length = dst.length;
- if ((off < 0) || (len < 0) || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final CharBuffer get(char[] dst, int dstOffset, int charCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, charCount);
+ if (charCount > remaining()) {
throw new BufferUnderflowException();
}
- int newPosition = position + len;
- sequence.toString().getChars(position, newPosition, dst, off);
+ int newPosition = position + charCount;
+ sequence.toString().getChars(position, newPosition, dst, dstOffset);
position = newPosition;
return this;
}
@@ -131,24 +128,12 @@ final class CharSequenceAdapter extends CharBuffer {
}
@Override
- public final CharBuffer put(char[] src, int off, int len) {
- if ((off < 0) || (len < 0) || (long) off + (long) len > src.length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
-
+ public final CharBuffer put(char[] src, int srcOffset, int charCount) {
throw new ReadOnlyBufferException();
}
@Override
public CharBuffer put(String src, int start, int end) {
- if ((start < 0) || (end < 0)
- || (long) start + (long) end > src.length()) {
- throw new IndexOutOfBoundsException();
- }
throw new ReadOnlyBufferException();
}
@@ -159,10 +144,7 @@ final class CharSequenceAdapter extends CharBuffer {
@Override
public CharSequence subSequence(int start, int end) {
- if (end < start || start < 0 || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
+ checkStartEndRemaining(start, end);
CharSequenceAdapter result = copy(this);
result.position = position + start;
result.limit = position + end;
diff --git a/luni/src/main/java/java/nio/CharToByteBufferAdapter.java b/luni/src/main/java/java/nio/CharToByteBufferAdapter.java
index f38215a..0df1f5c 100644
--- a/luni/src/main/java/java/nio/CharToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/CharToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a char buffer.
@@ -32,76 +31,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </p>
*
*/
-final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
-
- static CharBuffer wrap(ByteBuffer byteBuffer) {
- return new CharToByteBufferAdapter(byteBuffer.slice());
- }
+final class CharToByteBufferAdapter extends CharBuffer {
private final ByteBuffer byteBuffer;
- CharToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
+ static CharBuffer asCharBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new CharToByteBufferAdapter(slice);
}
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ private CharToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super(byteBuffer.capacity() / SizeOf.CHAR);
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public CharBuffer asReadOnlyBuffer() {
- CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
+ CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -113,8 +62,8 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
+ byteBuffer.limit(limit * SizeOf.CHAR);
+ byteBuffer.position(position * SizeOf.CHAR);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -125,8 +74,7 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
@Override
public CharBuffer duplicate() {
- CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
- .duplicate());
+ CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -138,15 +86,26 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getChar(position++ << 1);
+ return byteBuffer.getChar(position++ * SizeOf.CHAR);
}
@Override
public char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getChar(index * SizeOf.CHAR);
+ }
+
+ @Override
+ public CharBuffer get(char[] dst, int dstOffset, int charCount) {
+ byteBuffer.limit(limit * SizeOf.CHAR);
+ byteBuffer.position(position * SizeOf.CHAR);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, charCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, charCount);
}
- return byteBuffer.getChar(index << 1);
+ this.position += charCount;
+ return this;
}
@Override
@@ -184,23 +143,34 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putChar(position++ << 1, c);
+ byteBuffer.putChar(position++ * SizeOf.CHAR, c);
return this;
}
@Override
public CharBuffer put(int index, char c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ byteBuffer.putChar(index * SizeOf.CHAR, c);
+ return this;
+ }
+
+ @Override
+ public CharBuffer put(char[] src, int srcOffset, int charCount) {
+ byteBuffer.limit(limit * SizeOf.CHAR);
+ byteBuffer.position(position * SizeOf.CHAR);
+ if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, charCount);
+ } else {
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, charCount);
}
- byteBuffer.putChar(index << 1, c);
+ this.position += charCount;
return this;
}
@Override
public CharBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
+ byteBuffer.limit(limit * SizeOf.CHAR);
+ byteBuffer.position(position * SizeOf.CHAR);
CharBuffer result = new CharToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
@@ -208,10 +178,7 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer {
@Override
public CharSequence subSequence(int start, int end) {
- if (start < 0 || end < start || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
+ checkStartEndRemaining(start, end);
CharBuffer result = duplicate();
result.limit(position + end);
result.position(position + start);
diff --git a/luni/src/main/java/java/nio/DatagramChannelImpl.java b/luni/src/main/java/java/nio/DatagramChannelImpl.java
new file mode 100644
index 0000000..e732e28
--- /dev/null
+++ b/luni/src/main/java/java/nio/DatagramChannelImpl.java
@@ -0,0 +1,729 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.ConnectException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.DatagramSocketImpl;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.nio.channels.AlreadyConnectedException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.NotYetConnectedException;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Arrays;
+import libcore.base.EmptyArray;
+import org.apache.harmony.luni.net.PlainDatagramSocketImpl;
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+import org.apache.harmony.luni.platform.INetworkSystem;
+import org.apache.harmony.luni.platform.Platform;
+
+/*
+ * The default implementation class of java.nio.channels.DatagramChannel.
+ */
+class DatagramChannelImpl extends DatagramChannel implements FileDescriptorHandler {
+ // The fd to interact with native code
+ private final FileDescriptor fd;
+
+ // Our internal DatagramSocket.
+ private DatagramSocket socket = null;
+
+ // The address to be connected.
+ InetSocketAddress connectAddress = null;
+
+ // local port
+ private int localPort;
+
+ // At first, uninitialized.
+ boolean connected = false;
+
+ // whether the socket is bound
+ boolean isBound = false;
+
+ private final Object readLock = new Object();
+ private final Object writeLock = new Object();
+
+ /*
+ * Constructor
+ */
+ protected DatagramChannelImpl(SelectorProvider selectorProvider) throws IOException {
+ super(selectorProvider);
+ fd = new FileDescriptor();
+ Platform.NETWORK.socket(fd, false);
+ }
+
+ /*
+ * for native call
+ */
+ @SuppressWarnings("unused")
+ private DatagramChannelImpl() {
+ super(SelectorProvider.provider());
+ fd = new FileDescriptor();
+ connectAddress = new InetSocketAddress(0);
+ }
+
+ /*
+ * Getting the internal DatagramSocket If we have not the socket, we create
+ * a new one.
+ */
+ @Override
+ synchronized public DatagramSocket socket() {
+ if (socket == null) {
+ socket = new DatagramSocketAdapter(new PlainDatagramSocketImpl(fd, localPort), this);
+ }
+ return socket;
+ }
+
+ /**
+ * Returns the local address from the IP stack. This method should not be
+ * called directly as it does not check the security policy.
+ *
+ * @return InetAddress the local address to which the socket is bound.
+ * @see DatagramSocket
+ */
+ InetAddress getLocalAddress() {
+ return Platform.NETWORK.getSocketLocalAddress(fd);
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#isConnected()
+ */
+ @Override
+ synchronized public boolean isConnected() {
+ return connected;
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress)
+ */
+ @Override
+ synchronized public DatagramChannel connect(SocketAddress address) throws IOException {
+ // must open
+ checkOpen();
+ // status must be un-connected.
+ if (connected) {
+ throw new IllegalStateException();
+ }
+
+ // check the address
+ InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address);
+
+ // security check
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ if (inetSocketAddress.getAddress().isMulticastAddress()) {
+ sm.checkMulticast(inetSocketAddress.getAddress());
+ } else {
+ sm.checkConnect(inetSocketAddress.getAddress().getHostName(),
+ inetSocketAddress.getPort());
+ }
+ }
+
+ try {
+ begin();
+ Platform.NETWORK.connect(fd,
+ inetSocketAddress.getAddress(), inetSocketAddress.getPort(), 0);
+ } catch (ConnectException e) {
+ // ConnectException means connect fail, not exception
+ } finally {
+ end(true);
+ }
+
+ // set the connected address.
+ connectAddress = inetSocketAddress;
+ connected = true;
+ isBound = true;
+ return this;
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#disconnect()
+ */
+ @Override
+ synchronized public DatagramChannel disconnect() throws IOException {
+ if (!isConnected() || !isOpen()) {
+ return this;
+ }
+ connected = false;
+ connectAddress = null;
+ Platform.NETWORK.disconnectDatagram(fd);
+ if (socket != null) {
+ socket.disconnect();
+ }
+ return this;
+ }
+
+ @Override
+ public SocketAddress receive(ByteBuffer target) throws IOException {
+ FileChannelImpl.checkWritable(target);
+ checkOpen();
+
+ if (!isBound) {
+ return null;
+ }
+
+ SocketAddress retAddr = null;
+ try {
+ begin();
+
+ // receive real data packet, (not peek)
+ synchronized (readLock) {
+ boolean loop = isBlocking();
+ if (!target.isDirect()) {
+ retAddr = receiveImpl(target, loop);
+ } else {
+ retAddr = receiveDirectImpl(target, loop);
+ }
+ }
+ } catch (InterruptedIOException e) {
+ // this line used in Linux
+ return null;
+ } finally {
+ end(retAddr != null);
+ }
+ return retAddr;
+ }
+
+ private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException {
+ SocketAddress retAddr = null;
+ DatagramPacket receivePacket;
+ int oldposition = target.position();
+ int received = 0;
+ if (target.hasArray()) {
+ receivePacket = new DatagramPacket(target.array(), target
+ .position()
+ + target.arrayOffset(), target.remaining());
+ } else {
+ receivePacket = new DatagramPacket(new byte[target.remaining()],
+ target.remaining());
+ }
+ do {
+ received = Platform.NETWORK.recv(fd, receivePacket,
+ receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(),
+ false, isConnected());
+
+ // security check
+ SecurityManager sm = System.getSecurityManager();
+ if (!isConnected() && sm != null) {
+ try {
+ sm.checkAccept(receivePacket.getAddress().getHostAddress(),
+ receivePacket.getPort());
+ } catch (SecurityException e) {
+ // do discard the datagram packet
+ receivePacket = null;
+ }
+ }
+ if (receivePacket != null && receivePacket.getAddress() != null) {
+
+ if (received > 0) {
+ if (target.hasArray()) {
+ target.position(oldposition + received);
+ } else {
+ // copy the data of received packet
+ target.put(receivePacket.getData(), 0, received);
+ }
+ }
+ retAddr = receivePacket.getSocketAddress();
+ break;
+ }
+ } while (loop);
+ return retAddr;
+ }
+
+ private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException {
+ SocketAddress retAddr = null;
+ DatagramPacket receivePacket = new DatagramPacket(EmptyArray.BYTE, 0);
+ int oldposition = target.position();
+ int received = 0;
+ do {
+ int address = NioUtils.getDirectBufferAddress(target);
+ received = Platform.NETWORK.recvDirect(fd, receivePacket, address,
+ target.position(), target.remaining(), false, isConnected());
+
+ // security check
+ SecurityManager sm = System.getSecurityManager();
+ if (!isConnected() && sm != null) {
+ try {
+ sm.checkAccept(receivePacket.getAddress().getHostAddress(),
+ receivePacket.getPort());
+ } catch (SecurityException e) {
+ // do discard the datagram packet
+ receivePacket = null;
+ }
+ }
+ if (receivePacket != null && receivePacket.getAddress() != null) {
+ // copy the data of received packet
+ if (received > 0) {
+ target.position(oldposition + received);
+ }
+ retAddr = receivePacket.getSocketAddress();
+ break;
+ }
+ } while (loop);
+ return retAddr;
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#send(java.nio.ByteBuffer,
+ * java.net.SocketAddress)
+ */
+ @Override
+ public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException {
+ // must not null
+ checkNotNull(source);
+ // must open
+ checkOpen();
+
+ // transfer socketAddress
+ InetSocketAddress isa = (InetSocketAddress) socketAddress;
+ if (isa.getAddress() == null) {
+ throw new IOException();
+ }
+
+ if (isConnected()) {
+ if (!connectAddress.equals(isa)) {
+ throw new IllegalArgumentException();
+ }
+ } else {
+ // not connected, check security
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ if (isa.getAddress().isMulticastAddress()) {
+ sm.checkMulticast(isa.getAddress());
+ } else {
+ sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort());
+ }
+ }
+ }
+
+ // the return value.
+ int sendCount = 0;
+ try {
+ begin();
+ byte[] array = null;
+ int length = source.remaining();
+ int oldposition = source.position();
+ int start = oldposition;
+ if (source.isDirect()) {
+ synchronized (writeLock) {
+ int data_address = NioUtils.getDirectBufferAddress(source);
+ sendCount = Platform.NETWORK.sendDirect(fd, data_address, start, length,
+ isa.getPort(), isa.getAddress());
+ }
+ } else {
+ if (source.hasArray()) {
+ array = source.array();
+ start += source.arrayOffset();
+ } else {
+ array = new byte[length];
+ source.get(array);
+ start = 0;
+ }
+ synchronized (writeLock) {
+ sendCount = Platform.NETWORK.send(fd, array, start, length,
+ isa.getPort(), isa.getAddress());
+ }
+ }
+ source.position(oldposition + sendCount);
+ return sendCount;
+ } finally {
+ end(sendCount >= 0);
+ }
+ }
+
+ @Override
+ public int read(ByteBuffer target) throws IOException {
+ FileChannelImpl.checkWritable(target);
+ checkOpenConnected();
+
+ if (!target.hasRemaining()) {
+ return 0;
+ }
+
+ int readCount = 0;
+ if (target.isDirect() || target.hasArray()) {
+ readCount = readImpl(target);
+ if (readCount > 0) {
+ target.position(target.position() + readCount);
+ }
+
+ } else {
+ byte[] readArray = new byte[target.remaining()];
+ ByteBuffer readBuffer = ByteBuffer.wrap(readArray);
+ readCount = readImpl(readBuffer);
+ if (readCount > 0) {
+ target.put(readArray, 0, readCount);
+ }
+ }
+ return readCount;
+ }
+
+ @Override
+ public long read(ByteBuffer[] targets, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(targets.length, offset, length);
+
+ // status must be open and connected
+ checkOpenConnected();
+ int totalCount = FileChannelImpl.calculateTotalRemaining(targets, offset, length, true);
+ if (totalCount == 0) {
+ return 0;
+ }
+
+ // read data to readBuffer, and then transfer data from readBuffer to
+ // targets.
+ ByteBuffer readBuffer = ByteBuffer.allocate(totalCount);
+ int readCount;
+ readCount = readImpl(readBuffer);
+ int left = readCount;
+ int index = offset;
+ // transfer data from readBuffer to targets
+ byte[] readArray = readBuffer.array();
+ while (left > 0) {
+ int putLength = Math.min(targets[index].remaining(), left);
+ targets[index].put(readArray, readCount - left, putLength);
+ index++;
+ left -= putLength;
+ }
+ return readCount;
+ }
+
+ /*
+ * read from channel, and store the result in the target.
+ */
+ private int readImpl(ByteBuffer readBuffer) throws IOException {
+ synchronized (readLock) {
+ int readCount = 0;
+ try {
+ begin();
+ int start = readBuffer.position();
+ int length = readBuffer.remaining();
+ if (readBuffer.isDirect()) {
+ int address = NioUtils.getDirectBufferAddress(readBuffer);
+ readCount = Platform.NETWORK.recvDirect(fd, null, address, start, length,
+ false, isConnected());
+ } else {
+ // the target is assured to have array.
+ byte[] target = readBuffer.array();
+ start += readBuffer.arrayOffset();
+ readCount = Platform.NETWORK.recv(fd, null, target, start, length, false,
+ isConnected());
+ }
+ return readCount;
+ } catch (InterruptedIOException e) {
+ // InterruptedIOException will be thrown when timeout.
+ return 0;
+ } finally {
+ end(readCount > 0);
+ }
+ }
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#write(java.nio.ByteBuffer)
+ */
+ @Override
+ public int write(ByteBuffer source) throws IOException {
+ // source buffer must be not null
+ checkNotNull(source);
+ // status must be open and connected
+ checkOpenConnected();
+ // return immediately if source is full
+ if (!source.hasRemaining()) {
+ return 0;
+ }
+
+ ByteBuffer writeBuffer = null;
+ byte[] writeArray = null;
+ int oldposition = source.position();
+ int result;
+ if (source.isDirect() || source.hasArray()) {
+ writeBuffer = source;
+ } else {
+ writeArray = new byte[source.remaining()];
+ source.get(writeArray);
+ writeBuffer = ByteBuffer.wrap(writeArray);
+ }
+ result = writeImpl(writeBuffer);
+ if (result > 0) {
+ source.position(oldposition + result);
+ }
+ return result;
+ }
+
+ /**
+ * @see java.nio.channels.DatagramChannel#write(java.nio.ByteBuffer[], int,
+ * int)
+ */
+ @Override
+ public long write(ByteBuffer[] sources, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(sources.length, offset, length);
+
+ // status must be open and connected
+ checkOpenConnected();
+ int count = FileChannelImpl.calculateTotalRemaining(sources, offset, length, false);
+ if (count == 0) {
+ return 0;
+ }
+ ByteBuffer writeBuf = ByteBuffer.allocate(count);
+ for (int val = offset; val < length + offset; val++) {
+ ByteBuffer source = sources[val];
+ int oldPosition = source.position();
+ writeBuf.put(source);
+ source.position(oldPosition);
+ }
+ writeBuf.flip();
+ int result = writeImpl(writeBuf);
+ int val = offset;
+ int written = result;
+ while (result > 0) {
+ ByteBuffer source = sources[val];
+ int gap = Math.min(result, source.remaining());
+ source.position(source.position() + gap);
+ val++;
+ result -= gap;
+ }
+ return written;
+ }
+
+ /*
+ * Write the source. Return the count of bytes written.
+ */
+ private int writeImpl(ByteBuffer buf) throws IOException {
+ synchronized (writeLock) {
+ int result = 0;
+ try {
+ begin();
+ int length = buf.remaining();
+ int start = buf.position();
+
+ if (buf.isDirect()) {
+ int address = NioUtils.getDirectBufferAddress(buf);
+ result = Platform.NETWORK.sendDirect(fd, address, start, length, 0, null);
+ } else {
+ // buf is assured to have array.
+ start += buf.arrayOffset();
+ result = Platform.NETWORK.send(fd, buf.array(), start, length, 0, null);
+ }
+ return result;
+ } finally {
+ end(result > 0);
+ }
+ }
+ }
+
+ /*
+ * Do really closing action here.
+ */
+ @Override
+ protected synchronized void implCloseSelectableChannel() throws IOException {
+ connected = false;
+ if (socket != null && !socket.isClosed()) {
+ socket.close();
+ } else {
+ Platform.NETWORK.close(fd);
+ }
+ }
+
+ @Override
+ protected void implConfigureBlocking(boolean blockingMode) throws IOException {
+ // Do nothing here. For real read/write operation in nonblocking mode,
+ // it uses select system call. Whether a channel is blocking can be
+ // decided by isBlocking() method.
+ }
+
+ /*
+ * Status check, must be open.
+ */
+ private void checkOpen() throws IOException {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ }
+
+ /*
+ * Status check, must be open and connected, for read and write.
+ */
+ private void checkOpenConnected() throws IOException {
+ checkOpen();
+ if (!isConnected()) {
+ throw new NotYetConnectedException();
+ }
+ }
+
+ /*
+ * Buffer check, must not null
+ */
+ private void checkNotNull(ByteBuffer source) {
+ if (source == null) {
+ throw new NullPointerException();
+ }
+ }
+
+ /*
+ * Get the fd for internal use.
+ */
+ public FileDescriptor getFD() {
+ return fd;
+ }
+
+ /*
+ * The adapter class of DatagramSocket
+ */
+ private static class DatagramSocketAdapter extends DatagramSocket {
+
+ /*
+ * The internal datagramChannelImpl.
+ */
+ private DatagramChannelImpl channelImpl;
+
+ /*
+ * Constructor initialize the datagramSocketImpl and datagramChannelImpl
+ */
+ DatagramSocketAdapter(DatagramSocketImpl socketimpl,
+ DatagramChannelImpl channelImpl) {
+ super(socketimpl);
+ this.channelImpl = channelImpl;
+ }
+
+ /*
+ * Get the internal datagramChannelImpl
+ */
+ @Override
+ public DatagramChannel getChannel() {
+ return channelImpl;
+ }
+
+ /**
+ * @see java.net.DatagramSocket#isBound()
+ */
+ @Override
+ public boolean isBound() {
+ return channelImpl.isBound;
+ }
+
+ /**
+ * @see java.net.DatagramSocket#isConnected()
+ */
+ @Override
+ public boolean isConnected() {
+ return channelImpl.isConnected();
+ }
+
+ /**
+ * @see java.net.DatagramSocket#getInetAddress()
+ */
+ @Override
+ public InetAddress getInetAddress() {
+ if (channelImpl.connectAddress == null) {
+ return null;
+ }
+ return channelImpl.connectAddress.getAddress();
+ }
+
+ /**
+ * @see java.net.DatagramSocket#getLocalAddress()
+ */
+ @Override
+ public InetAddress getLocalAddress() {
+ return channelImpl.getLocalAddress();
+ }
+
+ /**
+ * @see java.net.DatagramSocket#getPort()
+ */
+ @Override
+ public int getPort() {
+ if (channelImpl.connectAddress == null) {
+ return -1;
+ }
+ return channelImpl.connectAddress.getPort();
+ }
+
+ /**
+ * @see java.net.DatagramSocket#bind(java.net.SocketAddress)
+ */
+ @Override
+ public void bind(SocketAddress localAddr) throws SocketException {
+ if (channelImpl.isConnected()) {
+ throw new AlreadyConnectedException();
+ }
+ super.bind(localAddr);
+ channelImpl.isBound = true;
+ }
+
+ /**
+ * @see java.net.DatagramSocket#receive(java.net.DatagramPacket)
+ */
+ @Override
+ public void receive(DatagramPacket packet) throws IOException {
+ if (!channelImpl.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ super.receive(packet);
+ }
+
+ /**
+ * @see java.net.DatagramSocket#send(java.net.DatagramPacket)
+ */
+ @Override
+ public void send(DatagramPacket packet) throws IOException {
+ if (!channelImpl.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ super.send(packet);
+ }
+
+ /**
+ * @see java.net.DatagramSocket#close()
+ */
+ @Override
+ public void close() {
+ synchronized (channelImpl) {
+ if (channelImpl.isOpen()) {
+ try {
+ channelImpl.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ super.close();
+ }
+ }
+
+ /**
+ * @see java.net.DatagramSocket#disconnect()
+ */
+ @Override
+ public void disconnect() {
+ try {
+ channelImpl.disconnect();
+ } catch (IOException e) {
+ // Ignore
+ }
+ super.disconnect();
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/DirectByteBuffer.java b/luni/src/main/java/java/nio/DirectByteBuffer.java
index 95fe90f..d9e8afd 100644
--- a/luni/src/main/java/java/nio/DirectByteBuffer.java
+++ b/luni/src/main/java/java/nio/DirectByteBuffer.java
@@ -17,91 +17,67 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.luni.platform.PlatformAddressFactory;
-import org.apache.harmony.nio.internal.DirectBuffer;
-
-/**
- * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
- * compose the implementation of platform memory based byte buffers.
- * <p>
- * DirectByteBuffer implements all the shared readonly methods and is extended
- * by the other two classes.
- * </p>
- * <p>
- * All methods are marked final for runtime performance.
- * </p>
- *
- */
-abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer {
+import libcore.io.SizeOf;
- // This class will help us track whether the address is valid or not.
- static final class SafeAddress {
- protected volatile boolean isValid = true;
+abstract class DirectByteBuffer extends BaseByteBuffer {
+ // This is the offset into {@code Buffer.block} at which this buffer logically starts.
+ // TODO: rewrite this so we set 'block' to an OffsetMemoryBlock?
+ protected final int offset;
- protected final PlatformAddress address;
+ protected DirectByteBuffer(MemoryBlock block, int capacity, int offset) {
+ super(capacity, block);
- protected SafeAddress(PlatformAddress address) {
- super();
- this.address = address;
+ long baseSize = block.getSize();
+ if (baseSize >= 0 && (capacity + offset) > baseSize) {
+ throw new IllegalArgumentException("capacity + offset > baseSize");
}
- }
- // This is a wrapped reference to the base address of the buffer memory.
- protected final SafeAddress safeAddress;
+ this.offset = offset;
+ this.effectiveDirectAddress = block.toInt() + offset;
+ }
- // This is the offset from the base address at which this buffer logically
- // starts.
- protected final int offset;
+ @Override
+ public final ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
+ checkGetBounds(1, dst.length, dstOffset, byteCount);
+ this.block.peekByteArray(offset + position, dst, dstOffset, byteCount);
+ position += byteCount;
+ return this;
+ }
- /*
- * Constructs a new direct byte buffer of the given capacity on newly
- * allocated OS memory. The memory will have been zeroed. When the instance
- * is discarded the OS memory will be freed if it has not already been done
- * so by an explicit call to #free(). Callers are encouraged to explicitly
- * free the memory where possible.
- */
- DirectByteBuffer(int capacity) {
- this(new SafeAddress(PlatformAddressFactory.alloc(capacity, (byte) 0)),
- capacity, 0);
- safeAddress.address.autoFree();
+ final void get(char[] dst, int dstOffset, int charCount) {
+ int byteCount = checkGetBounds(SizeOf.CHAR, dst.length, dstOffset, charCount);
+ this.block.peekCharArray(offset + position, dst, dstOffset, charCount, order.needsSwap);
+ position += byteCount;
}
- DirectByteBuffer(SafeAddress address, int capacity, int offset) {
- super(capacity);
+ final void get(double[] dst, int dstOffset, int doubleCount) {
+ int byteCount = checkGetBounds(SizeOf.DOUBLE, dst.length, dstOffset, doubleCount);
+ this.block.peekDoubleArray(offset + position, dst, dstOffset, doubleCount, order.needsSwap);
+ position += byteCount;
+ }
- // BEGIN android-added
- PlatformAddress baseAddress = address.address;
- long baseSize = baseAddress.getSize();
+ final void get(float[] dst, int dstOffset, int floatCount) {
+ int byteCount = checkGetBounds(SizeOf.FLOAT, dst.length, dstOffset, floatCount);
+ this.block.peekFloatArray(offset + position, dst, dstOffset, floatCount, order.needsSwap);
+ position += byteCount;
+ }
- if ((baseSize >= 0) && ((offset + capacity) > baseSize)) {
- throw new IllegalArgumentException("slice out of range");
- }
- // END android-added
+ final void get(int[] dst, int dstOffset, int intCount) {
+ int byteCount = checkGetBounds(SizeOf.INT, dst.length, dstOffset, intCount);
+ this.block.peekIntArray(offset + position, dst, dstOffset, intCount, order.needsSwap);
+ position += byteCount;
+ }
- this.safeAddress = address;
- this.offset = offset;
+ final void get(long[] dst, int dstOffset, int longCount) {
+ int byteCount = checkGetBounds(SizeOf.LONG, dst.length, dstOffset, longCount);
+ this.block.peekLongArray(offset + position, dst, dstOffset, longCount, order.needsSwap);
+ position += byteCount;
}
- /*
- * Override ByteBuffer.get(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#get(byte[], int, int)
- */
- @Override
- public final ByteBuffer get(byte[] dst, int off, int len) {
- int length = dst.length;
- if ((off < 0) || (len < 0) || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- getBaseAddress().getByteArray(offset + position, dst, off, len);
- position += len;
- return this;
+ final void get(short[] dst, int dstOffset, int shortCount) {
+ int byteCount = checkGetBounds(SizeOf.SHORT, dst.length, dstOffset, shortCount);
+ this.block.peekShortArray(offset + position, dst, dstOffset, shortCount, order.needsSwap);
+ position += byteCount;
}
@Override
@@ -109,110 +85,115 @@ abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferUnderflowException();
}
- return getBaseAddress().getByte(offset + position++);
+ return this.block.peekByte(offset + position++);
}
@Override
public final byte get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return this.block.peekByte(offset + index);
+ }
+
+ @Override
+ public final char getChar() {
+ int newPosition = position + SizeOf.CHAR;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
}
- return getBaseAddress().getByte(offset + index);
+ char result = (char) this.block.peekShort(offset + position, order);
+ position = newPosition;
+ return result;
+ }
+
+ @Override
+ public final char getChar(int index) {
+ checkIndex(index, SizeOf.CHAR);
+ return (char) this.block.peekShort(offset + index, order);
}
@Override
public final double getDouble() {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.DOUBLE;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- double result = getBaseAddress().getDouble(offset + position, order);
+ double result = Double.longBitsToDouble(this.block.peekLong(offset + position, order));
position = newPosition;
return result;
}
@Override
public final double getDouble(int index) {
- if (index < 0 || (long) index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return getBaseAddress().getDouble(offset + index, order);
+ checkIndex(index, SizeOf.DOUBLE);
+ return Double.longBitsToDouble(this.block.peekLong(offset + index, order));
}
@Override
public final float getFloat() {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.FLOAT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- float result = getBaseAddress().getFloat(offset + position, order);
+ float result = Float.intBitsToFloat(this.block.peekInt(offset + position, order));
position = newPosition;
return result;
}
@Override
public final float getFloat(int index) {
- if (index < 0 || (long) index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return getBaseAddress().getFloat(offset + index, order);
+ checkIndex(index, SizeOf.FLOAT);
+ return Float.intBitsToFloat(this.block.peekInt(offset + index, order));
}
@Override
public final int getInt() {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.INT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- int result = getBaseAddress().getInt(offset + position, order);
+ int result = this.block.peekInt(offset + position, order);
position = newPosition;
return result;
}
@Override
public final int getInt(int index) {
- if (index < 0 || (long) index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return getBaseAddress().getInt(offset + index, order);
+ checkIndex(index, SizeOf.INT);
+ return this.block.peekInt(offset + index, order);
}
@Override
public final long getLong() {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.LONG;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- long result = getBaseAddress().getLong(offset + position, order);
+ long result = this.block.peekLong(offset + position, order);
position = newPosition;
return result;
}
@Override
public final long getLong(int index) {
- if (index < 0 || (long) index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return getBaseAddress().getLong(offset + index, order);
+ checkIndex(index, SizeOf.LONG);
+ return this.block.peekLong(offset + index, order);
}
@Override
public final short getShort() {
- int newPosition = position + 2;
+ int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- short result = getBaseAddress().getShort(offset + position, order);
+ short result = this.block.peekShort(offset + position, order);
position = newPosition;
return result;
}
@Override
public final short getShort(int index) {
- if (index < 0 || (long) index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return getBaseAddress().getShort(offset + index, order);
+ checkIndex(index, SizeOf.SHORT);
+ return this.block.peekShort(offset + index, order);
}
@Override
@@ -220,68 +201,8 @@ abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer {
return true;
}
- public final boolean isAddressValid() {
- return safeAddress.isValid;
- }
-
- public final void addressValidityCheck() {
- if (!isAddressValid()) {
- throw new IllegalStateException("Cannot use a direct byte buffer after it has been explicitly freed");
- }
- }
-
- private void markAddressInvalid() {
- safeAddress.isValid = false;
- }
-
- /*
- * Returns the base address of the buffer (i.e. before offset).
- */
- public final PlatformAddress getBaseAddress() {
- addressValidityCheck();
- return safeAddress.address;
- }
-
- /**
- * Returns the platform address of the start of this buffer instance.
- * <em>You must not attempt to free the returned address!!</em> It may not
- * be an address that was explicitly malloc'ed (i.e. if this buffer is the
- * result of a split); and it may be memory shared by multiple buffers.
- * <p>
- * If you can guarantee that you want to free the underlying memory call the
- * #free() method on this instance -- generally applications will rely on
- * the garbage collector to autofree this memory.
- * </p>
- *
- * @return the effective address of the start of the buffer.
- * @throws IllegalStateException
- * if this buffer address is known to have been freed
- * previously.
- */
- public final PlatformAddress getEffectiveAddress() {
- // BEGIN android-changed
- PlatformAddress addr = getBaseAddress().offsetBytes(offset);
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
-
- /**
- * Explicitly free the memory used by this direct byte buffer. If the memory
- * has already been freed then this is a no-op. Once the memory has been
- * freed then operations requiring access to the memory will throw an
- * <code>IllegalStateException</code>.
- * <p>
- * Note this is is possible that the memory is freed by code that reaches
- * into the address and explicitly frees it 'beneith' us -- this is bad
- * form.
- * </p>
- */
public final void free() {
- if (isAddressValid()) {
- markAddressInvalid();
- safeAddress.address.free();
- }
+ block.free();
}
@Override
@@ -298,8 +219,4 @@ abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer {
final protected boolean protectedHasArray() {
return false;
}
-
- public final int getByteCapacity() {
- return capacity;
- }
}
diff --git a/luni/src/main/java/java/nio/DirectByteBuffers.java b/luni/src/main/java/java/nio/DirectByteBuffers.java
deleted file mode 100644
index 84a51ac..0000000
--- a/luni/src/main/java/java/nio/DirectByteBuffers.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.nio;
-
-import org.apache.harmony.luni.platform.PlatformAddress;
-
-/**
- * Helper class for operations on direct ByteBuffer
- *
- * @see java.nio.ByteBuffer
- */
-class DirectByteBuffers {
-
- /**
- * Explicitly frees the memory used by the given direct byte buffer.
- * <p>
- * If the memory is known to already have been freed then this is a no-op.
- * Once the memory has been freed then operations requiring access to the
- * memory will throw an <code>IllegalStateException</code>.
- * <p>
- * Note this is is possible that the memory is freed by code that reaches
- * into the address and explicitly frees it 'beneith' us -- this is bad
- * form.
- *
- * @param directBuffer
- * the direct byte buffer memory to free
- * @throws IllegalArgumentException
- * if the buffer is <code>null</code> or is not a
- * <em>direct</em> byte buffer.
- */
- public static void free(ByteBuffer directBuffer) {
- if ((directBuffer == null) || (!directBuffer.isDirect())) {
- throw new IllegalArgumentException();
- }
- DirectByteBuffer buf = (DirectByteBuffer) directBuffer;
- buf.free();
- }
-
- /**
- * Returns the platform address of the start of this buffer instance.
- * <em>You must not attempt to free the returned address!!</em> It may not
- * be an address that was explicitly malloc'ed (i.e. if this buffer is the
- * result of a split); and it may be memory shared by multiple buffers.
- * <p>
- * If you can guarantee that you want to free the underlying memory call the
- * #free() method on this instance -- generally applications will rely on
- * the garbage collector to autofree this memory.
- *
- * @param directBuffer
- * the direct byte buffer
- * @return the effective address of the start of the buffer.
- * @throws IllegalStateException
- * if this buffer address is known to have been freed
- * previously.
- */
- public static PlatformAddress getEffectiveAddress(ByteBuffer directBuffer) {
- return toDirectBuffer(directBuffer).getEffectiveAddress();
- }
-
- private static DirectByteBuffer toDirectBuffer(ByteBuffer directBuffer) {
- if ((directBuffer == null) || (!directBuffer.isDirect())) {
- throw new IllegalArgumentException();
- }
- return (DirectByteBuffer) directBuffer;
- }
-
-}
diff --git a/luni/src/main/java/java/nio/DoubleArrayBuffer.java b/luni/src/main/java/java/nio/DoubleArrayBuffer.java
index 4c7b86e..ec32a80 100644
--- a/luni/src/main/java/java/nio/DoubleArrayBuffer.java
+++ b/luni/src/main/java/java/nio/DoubleArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class DoubleArrayBuffer extends DoubleBuffer {
@Override
public final double get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final DoubleBuffer get(double[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final DoubleBuffer get(double[] dst, int dstOffset, int doubleCount) {
+ if (doubleCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, doubleCount);
+ position += doubleCount;
return this;
}
diff --git a/luni/src/main/java/java/nio/DoubleBuffer.java b/luni/src/main/java/java/nio/DoubleBuffer.java
index 93f2b87..c495592 100644
--- a/luni/src/main/java/java/nio/DoubleBuffer.java
+++ b/luni/src/main/java/java/nio/DoubleBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer of doubles.
* <p>
@@ -47,7 +49,7 @@ public abstract class DoubleBuffer extends Buffer implements
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newDoubleBuffer(capacity);
+ return new ReadWriteDoubleArrayBuffer(capacity);
}
/**
@@ -68,42 +70,30 @@ public abstract class DoubleBuffer extends Buffer implements
* Creates a new double buffer by wrapping the given double array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + doubleCount}, capacity will be the length of the array.
*
* @param array
* the double array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param doubleCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created double buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code doubleCount} is invalid.
*/
- public static DoubleBuffer wrap(double[] array, int start, int len) {
- int length = array.length;
- if (start < 0 || len < 0 || (long) start + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- DoubleBuffer buf = BufferFactory.newDoubleBuffer(array);
+ public static DoubleBuffer wrap(double[] array, int start, int doubleCount) {
+ Arrays.checkOffsetAndCount(array.length, start, doubleCount);
+ DoubleBuffer buf = new ReadWriteDoubleArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + doubleCount;
return buf;
}
- /**
- * Constructs a {@code DoubleBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
DoubleBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 3;
+ super(3, capacity, null);
}
public final double[] array() {
@@ -264,28 +254,24 @@ public abstract class DoubleBuffer extends Buffer implements
*
* @param dst
* the target double array.
- * @param off
+ * @param dstOffset
* the offset of the double array, must not be negative and not
* greater than {@code dst.length}.
- * @param len
+ * @param doubleCount
* the number of doubles to read, must be no less than zero and
- * not greater than {@code dst.length - off}.
+ * not greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code doubleCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code doubleCount} is greater than {@code remaining()}.
*/
- public DoubleBuffer get(double[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public DoubleBuffer get(double[] dst, int dstOffset, int doubleCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, doubleCount);
+ if (doubleCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + doubleCount; ++i) {
dst[i] = get();
}
return this;
@@ -409,30 +395,26 @@ public abstract class DoubleBuffer extends Buffer implements
*
* @param src
* the source double array.
- * @param off
+ * @param srcOffset
* the offset of double array, must not be negative and not
* greater than {@code src.length}.
- * @param len
+ * @param doubleCount
* the number of doubles to write, must be no less than zero and
- * not greater than {@code src.length - off}.
+ * not greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code doubleCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code doubleCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public DoubleBuffer put(double[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public DoubleBuffer put(double[] src, int srcOffset, int doubleCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, doubleCount);
+ if (doubleCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + doubleCount; ++i) {
put(src[i]);
}
return this;
@@ -499,22 +481,4 @@ public abstract class DoubleBuffer extends Buffer implements
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract DoubleBuffer slice();
-
- /**
- * Returns a string representing the state of this double buffer.
- *
- * @return A string representing the state of this double buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/DoubleToByteBufferAdapter.java b/luni/src/main/java/java/nio/DoubleToByteBufferAdapter.java
index a368dac..c069e0e 100644
--- a/luni/src/main/java/java/nio/DoubleToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/DoubleToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a double buffer.
@@ -32,77 +31,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </p>
*
*/
-final class DoubleToByteBufferAdapter extends DoubleBuffer implements
- DirectBuffer {
-
- static DoubleBuffer wrap(ByteBuffer byteBuffer) {
- return new DoubleToByteBufferAdapter(byteBuffer.slice());
- }
+final class DoubleToByteBufferAdapter extends DoubleBuffer {
private final ByteBuffer byteBuffer;
- DoubleToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 3));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
+ static DoubleBuffer asDoubleBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new DoubleToByteBufferAdapter(slice);
}
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ private DoubleToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super(byteBuffer.capacity() / SizeOf.DOUBLE);
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public DoubleBuffer asReadOnlyBuffer() {
- DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
- byteBuffer.asReadOnlyBuffer());
+ DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -114,8 +62,8 @@ final class DoubleToByteBufferAdapter extends DoubleBuffer implements
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
+ byteBuffer.limit(limit * SizeOf.DOUBLE);
+ byteBuffer.position(position * SizeOf.DOUBLE);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -126,8 +74,7 @@ final class DoubleToByteBufferAdapter extends DoubleBuffer implements
@Override
public DoubleBuffer duplicate() {
- DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
- byteBuffer.duplicate());
+ DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -139,15 +86,26 @@ final class DoubleToByteBufferAdapter extends DoubleBuffer implements
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getDouble(position++ << 3);
+ return byteBuffer.getDouble(position++ * SizeOf.DOUBLE);
}
@Override
public double get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getDouble(index * SizeOf.DOUBLE);
+ }
+
+ @Override
+ public DoubleBuffer get(double[] dst, int dstOffset, int doubleCount) {
+ byteBuffer.limit(limit * SizeOf.DOUBLE);
+ byteBuffer.position(position * SizeOf.DOUBLE);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, doubleCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, doubleCount);
}
- return byteBuffer.getDouble(index << 3);
+ this.position += doubleCount;
+ return this;
}
@Override
@@ -185,23 +143,34 @@ final class DoubleToByteBufferAdapter extends DoubleBuffer implements
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putDouble(position++ << 3, c);
+ byteBuffer.putDouble(position++ * SizeOf.DOUBLE, c);
return this;
}
@Override
public DoubleBuffer put(int index, double c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ byteBuffer.putDouble(index * SizeOf.DOUBLE, c);
+ return this;
+ }
+
+ @Override
+ public DoubleBuffer put(double[] src, int srcOffset, int doubleCount) {
+ byteBuffer.limit(limit * SizeOf.DOUBLE);
+ byteBuffer.position(position * SizeOf.DOUBLE);
+ if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, doubleCount);
+ } else {
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, doubleCount);
}
- byteBuffer.putDouble(index << 3, c);
+ this.position += doubleCount;
return this;
}
@Override
public DoubleBuffer slice() {
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
+ byteBuffer.limit(limit * SizeOf.DOUBLE);
+ byteBuffer.position(position * SizeOf.DOUBLE);
DoubleBuffer result = new DoubleToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
diff --git a/luni/src/main/java/java/nio/FileChannelImpl.java b/luni/src/main/java/java/nio/FileChannelImpl.java
new file mode 100644
index 0000000..c8efc97
--- /dev/null
+++ b/luni/src/main/java/java/nio/FileChannelImpl.java
@@ -0,0 +1,623 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.Closeable;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.OverlappingFileLockException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.harmony.luni.platform.IFileSystem;
+import org.apache.harmony.luni.platform.Platform;
+
+/*
+ * The file channel impl class is the bridge between the logical channels
+ * described by the NIO channel framework, and the file system implementation
+ * provided by the port layer.
+ *
+ * This class is non-API, but implements the API of the FileChannel interface.
+ */
+abstract class FileChannelImpl extends FileChannel {
+ private static final int ALLOC_GRANULARITY = Platform.FILE_SYSTEM.getAllocGranularity();
+
+ private static final Comparator<FileLock> LOCK_COMPARATOR = new Comparator<FileLock>() {
+ public int compare(FileLock lock1, FileLock lock2) {
+ long position1 = lock1.position();
+ long position2 = lock2.position();
+ return position1 > position2 ? 1 : (position1 < position2 ? -1 : 0);
+ }
+ };
+
+ // Handle to the open file
+ private final int handle;
+
+ // The set of acquired and pending locks.
+ private final SortedSet<FileLock> locks = new TreeSet<FileLock>(LOCK_COMPARATOR);
+
+ private final Object repositioningLock = new Object();
+
+ private final Object stream;
+
+ /**
+ * Create a new file channel implementation class that wraps the given file
+ * handle and operates in the specified mode.
+ */
+ public FileChannelImpl(Object stream, int handle) {
+ this.handle = handle;
+ this.stream = stream;
+ }
+
+ /**
+ * Helper method to throw an exception if the channel is already closed.
+ * Note that we don't bother to synchronize on this test since the file may
+ * be closed by operations beyond our control anyways.
+ */
+ protected final void openCheck() throws ClosedChannelException {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ }
+
+ protected void implCloseChannel() throws IOException {
+ if (stream instanceof Closeable) {
+ ((Closeable) stream).close();
+ }
+ }
+
+ protected FileLock basicLock(long position, long size, boolean shared,
+ boolean wait) throws IOException {
+ if (position < 0 || size < 0) {
+ throw new IllegalArgumentException("Lock position and size must be non-negative");
+ }
+ int lockType = shared ? IFileSystem.SHARED_LOCK_TYPE : IFileSystem.EXCLUSIVE_LOCK_TYPE;
+ FileLock pendingLock = new FileLockImpl(this, position, size, shared);
+ addLock(pendingLock);
+
+ if (Platform.FILE_SYSTEM.lock(handle, position, size, lockType, wait)) {
+ return pendingLock;
+ }
+
+ // Lock acquisition failed
+ removeLock(pendingLock);
+ return null;
+ }
+
+ private static final class FileLockImpl extends FileLock {
+ private boolean isReleased = false;
+
+ public FileLockImpl(FileChannel channel, long position, long size, boolean shared) {
+ super(channel, position, size, shared);
+ }
+
+ @Override public boolean isValid() {
+ return !isReleased && channel().isOpen();
+ }
+
+ @Override public void release() throws IOException {
+ if (!channel().isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (!isReleased) {
+ ((FileChannelImpl) channel()).release(this);
+ isReleased = true;
+ }
+ }
+ }
+
+ public final FileLock lock(long position, long size, boolean shared) throws IOException {
+ openCheck();
+ FileLock resultLock = null;
+ {
+ boolean completed = false;
+ try {
+ begin();
+ resultLock = basicLock(position, size, shared, true);
+ completed = true;
+ } finally {
+ end(completed);
+ }
+ }
+ return resultLock;
+ }
+
+ public final FileLock tryLock(long position, long size, boolean shared) throws IOException {
+ openCheck();
+ return basicLock(position, size, shared, false);
+ }
+
+ /**
+ * Non-API method to release a given lock on a file channel. Assumes that
+ * the lock will mark itself invalid after successful unlocking.
+ */
+ void release(FileLock lock) throws IOException {
+ openCheck();
+ Platform.FILE_SYSTEM.unlock(handle, lock.position(), lock.size());
+ removeLock(lock);
+ }
+
+ @Override public void force(boolean metadata) throws IOException {
+ openCheck();
+ Platform.FILE_SYSTEM.fsync(handle, metadata);
+ }
+
+ public abstract MappedByteBuffer map(MapMode mode, long position, long size) throws IOException;
+
+ protected final MappedByteBuffer mapImpl(MapMode mapMode, long position, long size) throws IOException {
+ if (position + size > size()) {
+ Platform.FILE_SYSTEM.truncate(handle, position + size);
+ }
+ long alignment = position - position % ALLOC_GRANULARITY;
+ int offset = (int) (position - alignment);
+ MemoryBlock block = MemoryBlock.mmap(handle, alignment, size + offset, mapMode);
+ return new MappedByteBufferAdapter(block, (int) size, offset, mapMode);
+ }
+
+ /**
+ * Returns the current file position.
+ */
+ public long position() throws IOException {
+ openCheck();
+ return Platform.FILE_SYSTEM.seek(handle, 0L, IFileSystem.SEEK_CUR);
+ }
+
+ /**
+ * Sets the file pointer.
+ */
+ public FileChannel position(long newPosition) throws IOException {
+ openCheck();
+ if (newPosition < 0) {
+ throw new IllegalArgumentException("New position must be non-negative");
+ }
+
+ synchronized (repositioningLock) {
+ Platform.FILE_SYSTEM.seek(handle, newPosition, IFileSystem.SEEK_SET);
+ }
+ return this;
+ }
+
+ public int read(ByteBuffer buffer, long position) throws IOException {
+ FileChannelImpl.checkWritable(buffer);
+ if (position < 0) {
+ throw new IllegalArgumentException();
+ }
+ openCheck();
+ if (!buffer.hasRemaining()) {
+ return 0;
+ }
+ synchronized (repositioningLock) {
+ int bytesRead = 0;
+ long preReadPosition = position();
+ position(position);
+ try {
+ bytesRead = read(buffer);
+ } finally {
+ position(preReadPosition);
+ }
+ return bytesRead;
+ }
+ }
+
+ public int read(ByteBuffer buffer) throws IOException {
+ FileChannelImpl.checkWritable(buffer);
+ openCheck();
+ if (!buffer.hasRemaining()) {
+ return 0;
+ }
+ boolean completed = false;
+ int bytesRead = 0;
+ synchronized (repositioningLock) {
+ if (buffer.isDirect()) {
+ try {
+ begin();
+ /*
+ * if (bytesRead <= EOF) dealt by read completed = false;
+ */
+ int address = NioUtils.getDirectBufferAddress(buffer);
+ bytesRead = (int) Platform.FILE_SYSTEM.readDirect(handle, address,
+ buffer.position(), buffer.remaining());
+ completed = true;
+ } finally {
+ end(completed && bytesRead >= 0);
+ }
+ } else {
+ try {
+ begin();
+ /*
+ * if (bytesRead <= EOF) dealt by read completed = false;
+ */
+ bytesRead = (int) Platform.FILE_SYSTEM.read(handle, buffer.array(),
+ buffer.arrayOffset() + buffer.position(), buffer
+ .remaining());
+ completed = true;
+ } finally {
+ end(completed && bytesRead >= 0);
+ }
+ }
+ if (bytesRead > 0) {
+ buffer.position(buffer.position() + bytesRead);
+ }
+ }
+ return bytesRead;
+ }
+
+ public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(buffers.length, offset, length);
+ openCheck();
+ int count = FileChannelImpl.calculateTotalRemaining(buffers, offset, length, true);
+ if (count == 0) {
+ return 0;
+ }
+ ByteBuffer[] directBuffers = new ByteBuffer[length];
+ int[] handles = new int[length];
+ int[] offsets = new int[length];
+ int[] lengths = new int[length];
+ for (int i = 0; i < length; i++) {
+ ByteBuffer buffer = buffers[i + offset];
+ if (!buffer.isDirect()) {
+ buffer = ByteBuffer.allocateDirect(buffer.remaining());
+ directBuffers[i] = buffer;
+ offsets[i] = 0;
+ } else {
+ offsets[i] = buffer.position();
+ }
+ handles[i] = NioUtils.getDirectBufferAddress(buffer);
+ lengths[i] = buffer.remaining();
+ }
+ long bytesRead = 0;
+ {
+ boolean completed = false;
+ try {
+ begin();
+ synchronized (repositioningLock) {
+ bytesRead = Platform.FILE_SYSTEM.readv(handle, handles, offsets,
+ lengths, length);
+
+ }
+ completed = true;
+ /*
+ * if (bytesRead < EOF) //dealt by readv? completed = false;
+ */
+ } finally {
+ end(completed);
+ }
+ }
+ int end = offset + length;
+ long bytesRemaining = bytesRead;
+ for (int i = offset; i < end && bytesRemaining > 0; i++) {
+ if (buffers[i].isDirect()) {
+ if (lengths[i] < bytesRemaining) {
+ int pos = buffers[i].limit();
+ buffers[i].position(pos);
+ bytesRemaining -= lengths[i];
+ } else {
+ int pos = (int) bytesRemaining;
+ buffers[i].position(pos);
+ break;
+ }
+ } else {
+ ByteBuffer buf = directBuffers[i - offset];
+ if (bytesRemaining < buf.remaining()) {
+ // this is the last step.
+ int pos = buf.position();
+ buffers[i].put(buf);
+ buffers[i].position(pos + (int) bytesRemaining);
+ bytesRemaining = 0;
+ } else {
+ bytesRemaining -= buf.remaining();
+ buffers[i].put(buf);
+ }
+ }
+ }
+ return bytesRead;
+ }
+
+ /**
+ * Returns the current file size, as an integer number of bytes.
+ */
+ public long size() throws IOException {
+ openCheck();
+ return Platform.FILE_SYSTEM.length(handle);
+ }
+
+ public long transferFrom(ReadableByteChannel src, long position, long count)
+ throws IOException {
+ openCheck();
+ if (!src.isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (position < 0 || count < 0 || count > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException();
+ }
+ if (position > size()) {
+ return 0;
+ }
+
+ ByteBuffer buffer = null;
+
+ try {
+ if (src instanceof FileChannel) {
+ FileChannel fileSrc = (FileChannel) src;
+ long size = fileSrc.size();
+ long filePosition = fileSrc.position();
+ count = Math.min(count, size - filePosition);
+ buffer = fileSrc.map(MapMode.READ_ONLY, filePosition, count);
+ fileSrc.position(filePosition + count);
+ } else {
+ buffer = ByteBuffer.allocateDirect((int) count);
+ src.read(buffer);
+ buffer.flip();
+ }
+ return write(buffer, position);
+ } finally {
+ NioUtils.freeDirectBuffer(buffer);
+ }
+ }
+
+ public long transferTo(long position, long count, WritableByteChannel target)
+ throws IOException {
+ openCheck();
+ if (!target.isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (target instanceof ReadOnlyFileChannel) {
+ throw new NonWritableChannelException();
+ }
+ if (position < 0 || count < 0) {
+ throw new IllegalArgumentException();
+ }
+
+ if (count == 0 || position >= size()) {
+ return 0;
+ }
+ ByteBuffer buffer = null;
+ count = Math.min(count, size() - position);
+ if (target instanceof SocketChannelImpl) {
+ // only socket can be transfered by system call
+ return kernelTransfer(handle, ((SocketChannelImpl) target).getFD(),
+ position, count);
+ }
+
+ try {
+ buffer = map(MapMode.READ_ONLY, position, count);
+ return target.write(buffer);
+ } finally {
+ NioUtils.freeDirectBuffer(buffer);
+ }
+ }
+
+ private long kernelTransfer(int l, FileDescriptor fd, long position,
+ long count) throws IOException {
+ boolean completed = false;
+ try {
+ begin();
+ long ret = Platform.FILE_SYSTEM.transfer(l, fd, position, count);
+ completed = true;
+ return ret;
+ } finally {
+ end(completed);
+ }
+ }
+
+ public FileChannel truncate(long size) throws IOException {
+ openCheck();
+ if (size < 0) {
+ throw new IllegalArgumentException();
+ }
+ if (size < size()) {
+ synchronized (repositioningLock) {
+ long position = position();
+ Platform.FILE_SYSTEM.truncate(handle, size);
+ /*
+ * FIXME: currently the port library always modifies the
+ * position to given size. not sure it is a bug or intended
+ * behavior, so I always reset the position to proper value as
+ * Java Spec.
+ */
+ position(position > size ? size : position);
+ }
+ }
+ return this;
+ }
+
+ public int write(ByteBuffer buffer, long position) throws IOException {
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0) {
+ throw new IllegalArgumentException();
+ }
+ openCheck();
+ if (!buffer.hasRemaining()) {
+ return 0;
+ }
+ int bytesWritten = 0;
+ synchronized (repositioningLock) {
+ long preWritePosition = position();
+ position(position);
+ try {
+ bytesWritten = writeImpl(buffer);
+ } finally {
+ position(preWritePosition);
+ }
+ }
+ return bytesWritten;
+ }
+
+ public int write(ByteBuffer buffer) throws IOException {
+ openCheck();
+ return writeImpl(buffer);
+ }
+
+ private int writeImpl(ByteBuffer buffer) throws IOException {
+ int bytesWritten;
+ boolean completed = false;
+ synchronized (repositioningLock) {
+ if (buffer.isDirect()) {
+ try {
+ begin();
+ int address = NioUtils.getDirectBufferAddress(buffer);
+ bytesWritten = (int) Platform.FILE_SYSTEM.writeDirect(handle,
+ address, buffer.position(), buffer.remaining());
+ completed = true;
+ } finally {
+ end(completed);
+ }
+ } else {
+ try {
+ begin();
+ bytesWritten = (int) Platform.FILE_SYSTEM.write(handle, buffer
+ .array(), buffer.arrayOffset() + buffer.position(),
+ buffer.remaining());
+ completed = true;
+ } finally {
+ end(completed);
+ }
+ }
+ if (bytesWritten > 0) {
+ buffer.position(buffer.position() + bytesWritten);
+ }
+ }
+ return bytesWritten;
+ }
+
+ public long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(buffers.length, offset, length);
+ openCheck();
+ int count = FileChannelImpl.calculateTotalRemaining(buffers, offset, length, false);
+ if (count == 0) {
+ return 0;
+ }
+ int[] handles = new int[length];
+ int[] offsets = new int[length];
+ int[] lengths = new int[length];
+ // BEGIN android-changed
+ // list of allocated direct ByteBuffers to prevent them from being GC-ed
+ ByteBuffer[] allocatedBufs = new ByteBuffer[length];
+
+ for (int i = 0; i < length; i++) {
+ ByteBuffer buffer = buffers[i + offset];
+ if (!buffer.isDirect()) {
+ ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer.remaining());
+ directBuffer.put(buffer);
+ directBuffer.flip();
+ buffer = directBuffer;
+ allocatedBufs[i] = directBuffer;
+ offsets[i] = 0;
+ } else {
+ offsets[i] = buffer.position();
+ allocatedBufs[i] = null;
+ }
+ handles[i] = NioUtils.getDirectBufferAddress(buffer);
+ lengths[i] = buffer.remaining();
+ }
+ // END android-changed
+
+ long bytesWritten = 0;
+ boolean completed = false;
+ synchronized (repositioningLock) {
+ try {
+ begin();
+ bytesWritten = Platform.FILE_SYSTEM.writev(handle, handles, offsets,
+ lengths, length);
+ completed = true;
+ } finally {
+ end(completed);
+ for (ByteBuffer buffer : allocatedBufs) {
+ NioUtils.freeDirectBuffer(buffer);
+ }
+ }
+ }
+
+ long bytesRemaining = bytesWritten;
+ for (int i = offset; i < length + offset; i++) {
+ if (bytesRemaining > buffers[i].remaining()) {
+ int pos = buffers[i].limit();
+ buffers[i].position(pos);
+ bytesRemaining -= buffers[i].remaining();
+ } else {
+ int pos = buffers[i].position() + (int) bytesRemaining;
+ buffers[i].position(pos);
+ break;
+ }
+ }
+ return bytesWritten;
+ }
+
+ static void checkWritable(ByteBuffer buffer) {
+ if (buffer.isReadOnly()) {
+ throw new IllegalArgumentException("read-only buffer");
+ }
+ }
+
+ /**
+ * @param copyingIn true if we're copying data into the buffers (typically
+ * because the caller is a file/network read operation), false if we're
+ * copying data out of the buffers (for a file/network write operation).
+ */
+ static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) {
+ int count = 0;
+ for (int i = offset; i < offset + length; ++i) {
+ count += buffers[i].remaining();
+ if (copyingIn) {
+ checkWritable(buffers[i]);
+ }
+ }
+ return count;
+ }
+
+ public int getHandle() {
+ return handle;
+ }
+
+ /**
+ * Add a new pending lock to the manager. Throws an exception if the lock
+ * would overlap an existing lock. Once the lock is acquired it remains in
+ * this set as an acquired lock.
+ */
+ private synchronized void addLock(FileLock lock) throws OverlappingFileLockException {
+ long lockEnd = lock.position() + lock.size();
+ for (FileLock existingLock : locks) {
+ if (existingLock.position() > lockEnd) {
+ // This, and all remaining locks, start beyond our end (so
+ // cannot overlap).
+ break;
+ }
+ if (existingLock.overlaps(lock.position(), lock.size())) {
+ throw new OverlappingFileLockException();
+ }
+ }
+ locks.add(lock);
+ }
+
+ /**
+ * Removes an acquired lock from the lock manager. If the lock did not exist
+ * in the lock manager the operation is a no-op.
+ */
+ private synchronized void removeLock(FileLock lock) {
+ locks.remove(lock);
+ }
+}
diff --git a/luni/src/main/java/java/nio/FloatArrayBuffer.java b/luni/src/main/java/java/nio/FloatArrayBuffer.java
index f25ce24..c47ee21 100644
--- a/luni/src/main/java/java/nio/FloatArrayBuffer.java
+++ b/luni/src/main/java/java/nio/FloatArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class FloatArrayBuffer extends FloatBuffer {
@Override
public final float get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final FloatBuffer get(float[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final FloatBuffer get(float[] dst, int dstOffset, int floatCount) {
+ if (floatCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, floatCount);
+ position += floatCount;
return this;
}
diff --git a/luni/src/main/java/java/nio/FloatBuffer.java b/luni/src/main/java/java/nio/FloatBuffer.java
index 9044911..ec361d6 100644
--- a/luni/src/main/java/java/nio/FloatBuffer.java
+++ b/luni/src/main/java/java/nio/FloatBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer of floats.
* <p>
@@ -46,7 +48,7 @@ public abstract class FloatBuffer extends Buffer implements
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newFloatBuffer(capacity);
+ return new ReadWriteFloatArrayBuffer(capacity);
}
/**
@@ -67,45 +69,32 @@ public abstract class FloatBuffer extends Buffer implements
* Creates a new float buffer by wrapping the given float array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + floatCount}, capacity will be the length of the array.
*
* @param array
* the float array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param floatCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created float buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code floatCount} is invalid.
* @exception NullPointerException
* if {@code array} is null.
*/
- public static FloatBuffer wrap(float[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long) start + (long) len > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- FloatBuffer buf = BufferFactory.newFloatBuffer(array);
+ public static FloatBuffer wrap(float[] array, int start, int floatCount) {
+ Arrays.checkOffsetAndCount(array.length, start, floatCount);
+ FloatBuffer buf = new ReadWriteFloatArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + floatCount;
return buf;
}
- /**
- * Constructs a {@code FloatBuffer} with given capacity.
- *
- * @param capacity The capacity of the buffer
- */
FloatBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 2;
+ super(2, capacity, null);
}
public final float[] array() {
@@ -266,28 +255,24 @@ public abstract class FloatBuffer extends Buffer implements
*
* @param dst
* the target float array.
- * @param off
+ * @param dstOffset
* the offset of the float array, must not be negative and no
* greater than {@code dst.length}.
- * @param len
+ * @param floatCount
* the number of floats to read, must be no less than zero and no
- * greater than {@code dst.length - off}.
+ * greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code floatCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code floatCount} is greater than {@code remaining()}.
*/
- public FloatBuffer get(float[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public FloatBuffer get(float[] dst, int dstOffset, int floatCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, floatCount);
+ if (floatCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + floatCount; ++i) {
dst[i] = get();
}
return this;
@@ -409,30 +394,26 @@ public abstract class FloatBuffer extends Buffer implements
*
* @param src
* the source float array.
- * @param off
+ * @param srcOffset
* the offset of float array, must not be negative and not
* greater than {@code src.length}.
- * @param len
+ * @param floatCount
* the number of floats to write, must be no less than zero and
- * no greater than {@code src.length - off}.
+ * no greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code floatCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code floatCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public FloatBuffer put(float[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public FloatBuffer put(float[] src, int srcOffset, int floatCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, floatCount);
+ if (floatCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + floatCount; ++i) {
put(src[i]);
}
return this;
@@ -499,22 +480,4 @@ public abstract class FloatBuffer extends Buffer implements
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract FloatBuffer slice();
-
- /**
- * Returns a string representing the state of this float buffer.
- *
- * @return a string representing the state of this float buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/FloatToByteBufferAdapter.java b/luni/src/main/java/java/nio/FloatToByteBufferAdapter.java
index 079f7f8..9ad48d7 100644
--- a/luni/src/main/java/java/nio/FloatToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/FloatToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a float buffer.
@@ -31,77 +30,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </ul>
* </p>
*/
-final class FloatToByteBufferAdapter extends FloatBuffer implements
- DirectBuffer {
-
- static FloatBuffer wrap(ByteBuffer byteBuffer) {
- return new FloatToByteBufferAdapter(byteBuffer.slice());
- }
+final class FloatToByteBufferAdapter extends FloatBuffer {
private final ByteBuffer byteBuffer;
+ static FloatBuffer asFloatBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new FloatToByteBufferAdapter(slice);
+ }
+
FloatToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
+ super(byteBuffer.capacity() / SizeOf.FLOAT);
this.byteBuffer = byteBuffer;
this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
- }
-
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public FloatBuffer asReadOnlyBuffer() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -113,8 +61,8 @@ final class FloatToByteBufferAdapter extends FloatBuffer implements
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
+ byteBuffer.limit(limit * SizeOf.FLOAT);
+ byteBuffer.position(position * SizeOf.FLOAT);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -125,8 +73,7 @@ final class FloatToByteBufferAdapter extends FloatBuffer implements
@Override
public FloatBuffer duplicate() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .duplicate());
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -138,15 +85,26 @@ final class FloatToByteBufferAdapter extends FloatBuffer implements
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getFloat(position++ << 2);
+ return byteBuffer.getFloat(position++ * SizeOf.FLOAT);
}
@Override
public float get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getFloat(index * SizeOf.FLOAT);
+ }
+
+ @Override
+ public FloatBuffer get(float[] dst, int dstOffset, int floatCount) {
+ byteBuffer.limit(limit * SizeOf.FLOAT);
+ byteBuffer.position(position * SizeOf.FLOAT);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, floatCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, floatCount);
}
- return byteBuffer.getFloat(index << 2);
+ this.position += floatCount;
+ return this;
}
@Override
@@ -184,39 +142,34 @@ final class FloatToByteBufferAdapter extends FloatBuffer implements
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putFloat(position++ << 2, c);
+ byteBuffer.putFloat(position++ * SizeOf.FLOAT, c);
return this;
}
@Override
public FloatBuffer put(int index, float c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putFloat(index << 2, c);
+ checkIndex(index);
+ byteBuffer.putFloat(index * SizeOf.FLOAT, c);
return this;
}
- // BEGIN android-added
@Override
- public FloatBuffer put(float[] c, int off, int len) {
+ public FloatBuffer put(float[] src, int srcOffset, int floatCount) {
+ byteBuffer.limit(limit * SizeOf.FLOAT);
+ byteBuffer.position(position * SizeOf.FLOAT);
if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- ((ReadWriteDirectByteBuffer) byteBuffer).put(c, off, len);
- this.position += len;
- return this;
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, floatCount);
} else {
- return super.put(c, off, len);
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, floatCount);
}
+ this.position += floatCount;
+ return this;
}
- // END android-added
-
@Override
public FloatBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
+ byteBuffer.limit(limit * SizeOf.FLOAT);
+ byteBuffer.position(position * SizeOf.FLOAT);
FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
diff --git a/luni/src/main/java/java/nio/HeapByteBuffer.java b/luni/src/main/java/java/nio/HeapByteBuffer.java
index b246dc2..d0e63d9 100644
--- a/luni/src/main/java/java/nio/HeapByteBuffer.java
+++ b/luni/src/main/java/java/nio/HeapByteBuffer.java
@@ -17,6 +17,9 @@
package java.nio;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
+
/**
* HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
* the implementation of array based byte buffers.
@@ -44,36 +47,59 @@ abstract class HeapByteBuffer extends BaseByteBuffer {
}
HeapByteBuffer(byte[] backingArray, int capacity, int offset) {
- super(capacity);
+ super(capacity, null);
this.backingArray = backingArray;
this.offset = offset;
-
if (offset + capacity > backingArray.length) {
- throw new IndexOutOfBoundsException();
+ throw new IndexOutOfBoundsException("backingArray.length=" + backingArray.length +
+ ", capacity=" + capacity + ", offset=" + offset);
}
}
- /*
- * Override ByteBuffer.get(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#get(byte[], int, int)
- */
@Override
- public final ByteBuffer get(byte[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ public final ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
+ checkGetBounds(1, dst.length, dstOffset, byteCount);
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, byteCount);
+ position += byteCount;
return this;
}
+ final void get(char[] dst, int dstOffset, int charCount) {
+ int byteCount = checkGetBounds(SizeOf.CHAR, dst.length, dstOffset, charCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.CHAR, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void get(double[] dst, int dstOffset, int doubleCount) {
+ int byteCount = checkGetBounds(SizeOf.DOUBLE, dst.length, dstOffset, doubleCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.DOUBLE, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void get(float[] dst, int dstOffset, int floatCount) {
+ int byteCount = checkGetBounds(SizeOf.FLOAT, dst.length, dstOffset, floatCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.FLOAT, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void get(int[] dst, int dstOffset, int intCount) {
+ int byteCount = checkGetBounds(SizeOf.INT, dst.length, dstOffset, intCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.INT, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void get(long[] dst, int dstOffset, int longCount) {
+ int byteCount = checkGetBounds(SizeOf.LONG, dst.length, dstOffset, longCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.LONG, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void get(short[] dst, int dstOffset, int shortCount) {
+ int byteCount = checkGetBounds(SizeOf.SHORT, dst.length, dstOffset, shortCount);
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, backingArray, offset + position, SizeOf.SHORT, order.needsSwap);
+ position += byteCount;
+ }
+
@Override
public final byte get() {
if (position == limit) {
@@ -84,13 +110,28 @@ abstract class HeapByteBuffer extends BaseByteBuffer {
@Override
public final byte get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
+ public final char getChar() {
+ int newPosition = position + SizeOf.CHAR;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ char result = (char) OSMemory.peekShort(backingArray, offset + position, order);
+ position = newPosition;
+ return result;
+ }
+
+ @Override
+ public final char getChar(int index) {
+ checkIndex(index, SizeOf.CHAR);
+ return (char) OSMemory.peekShort(backingArray, offset + index, order);
+ }
+
+ @Override
public final double getDouble() {
return Double.longBitsToDouble(getLong());
}
@@ -112,151 +153,57 @@ abstract class HeapByteBuffer extends BaseByteBuffer {
@Override
public final int getInt() {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.INT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- int result = loadInt(position);
+ int result = OSMemory.peekInt(backingArray, offset + position, order);
position = newPosition;
return result;
}
@Override
public final int getInt(int index) {
- if (index < 0 || index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadInt(index);
+ checkIndex(index, SizeOf.INT);
+ return OSMemory.peekInt(backingArray, offset + index, order);
}
@Override
public final long getLong() {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.LONG;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- long result = loadLong(position);
+ long result = OSMemory.peekLong(backingArray, offset + position, order);
position = newPosition;
return result;
}
@Override
public final long getLong(int index) {
- if (index < 0 || index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadLong(index);
+ checkIndex(index, SizeOf.LONG);
+ return OSMemory.peekLong(backingArray, offset + index, order);
}
@Override
public final short getShort() {
- int newPosition = position + 2;
+ int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferUnderflowException();
}
- short result = loadShort(position);
+ short result = OSMemory.peekShort(backingArray, offset + position, order);
position = newPosition;
return result;
}
@Override
public final short getShort(int index) {
- if (index < 0 || index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadShort(index);
+ checkIndex(index, SizeOf.SHORT);
+ return OSMemory.peekShort(backingArray, offset + index, order);
}
@Override
public final boolean isDirect() {
return false;
}
-
- protected final int loadInt(int index) {
- int baseOffset = offset + index;
- int bytes = 0;
- if (order == ByteOrder.BIG_ENDIAN) {
- for (int i = 0; i < 4; i++) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- } else {
- for (int i = 3; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final long loadLong(int index) {
- int baseOffset = offset + index;
- long bytes = 0;
- if (order == ByteOrder.BIG_ENDIAN) {
- for (int i = 0; i < 8; i++) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- } else {
- for (int i = 7; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final short loadShort(int index) {
- int baseOffset = offset + index;
- short bytes = 0;
- if (order == ByteOrder.BIG_ENDIAN) {
- bytes = (short) (backingArray[baseOffset] << 8);
- bytes |= (backingArray[baseOffset + 1] & 0xFF);
- } else {
- bytes = (short) (backingArray[baseOffset + 1] << 8);
- bytes |= (backingArray[baseOffset] & 0xFF);
- }
- return bytes;
- }
-
- protected final void store(int index, int value) {
- int baseOffset = offset + index;
- if (order == ByteOrder.BIG_ENDIAN) {
- for (int i = 3; i >= 0; i--) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 3; i++) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int index, long value) {
- int baseOffset = offset + index;
- if (order == ByteOrder.BIG_ENDIAN) {
- for (int i = 7; i >= 0; i--) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 7; i++) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int index, short value) {
- int baseOffset = offset + index;
- if (order == ByteOrder.BIG_ENDIAN) {
- backingArray[baseOffset] = (byte) ((value >> 8) & 0xFF);
- backingArray[baseOffset + 1] = (byte) (value & 0xFF);
- } else {
- backingArray[baseOffset + 1] = (byte) ((value >> 8) & 0xFF);
- backingArray[baseOffset] = (byte) (value & 0xFF);
- }
- }
}
diff --git a/luni/src/main/java/java/nio/IntArrayBuffer.java b/luni/src/main/java/java/nio/IntArrayBuffer.java
index a1ee158..d031415 100644
--- a/luni/src/main/java/java/nio/IntArrayBuffer.java
+++ b/luni/src/main/java/java/nio/IntArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class IntArrayBuffer extends IntBuffer {
@Override
public final int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final IntBuffer get(int[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final IntBuffer get(int[] dst, int dstOffset, int intCount) {
+ if (intCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, intCount);
+ position += intCount;
return this;
}
diff --git a/luni/src/main/java/java/nio/IntBuffer.java b/luni/src/main/java/java/nio/IntBuffer.java
index 6f362ec..3e1d9a3 100644
--- a/luni/src/main/java/java/nio/IntBuffer.java
+++ b/luni/src/main/java/java/nio/IntBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer of ints.
* <p>
@@ -44,7 +46,7 @@ public abstract class IntBuffer extends Buffer implements Comparable<IntBuffer>
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newIntBuffer(capacity);
+ return new ReadWriteIntArrayBuffer(capacity);
}
/**
@@ -65,44 +67,30 @@ public abstract class IntBuffer extends Buffer implements Comparable<IntBuffer>
* Creates a new int buffer by wrapping the given int array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + intCount}, capacity will be the length of the array.
*
* @param array
* the int array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}
- * @param len
+ * @param intCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created int buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code intCount} is invalid.
*/
- public static IntBuffer wrap(int[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long) len + (long) start > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- IntBuffer buf = BufferFactory.newIntBuffer(array);
+ public static IntBuffer wrap(int[] array, int start, int intCount) {
+ Arrays.checkOffsetAndCount(array.length, start, intCount);
+ IntBuffer buf = new ReadWriteIntArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + intCount;
return buf;
}
- /**
- * Constructs a {@code IntBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
IntBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 2;
+ super(2, capacity, null);
}
public final int[] array() {
@@ -255,27 +243,24 @@ public abstract class IntBuffer extends Buffer implements Comparable<IntBuffer>
*
* @param dst
* the target int array.
- * @param off
+ * @param dstOffset
* the offset of the int array, must not be negative and not
* greater than {@code dst.length}.
- * @param len
+ * @param intCount
* the number of ints to read, must be no less than zero and not
- * greater than {@code dst.length - off}.
+ * greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code intCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code intCount} is greater than {@code remaining()}.
*/
- public IntBuffer get(int[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public IntBuffer get(int[] dst, int dstOffset, int intCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, intCount);
+ if (intCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + intCount; ++i) {
dst[i] = get();
}
return this;
@@ -397,30 +382,26 @@ public abstract class IntBuffer extends Buffer implements Comparable<IntBuffer>
*
* @param src
* the source int array.
- * @param off
+ * @param srcOffset
* the offset of int array, must not be negative and not greater
* than {@code src.length}.
- * @param len
+ * @param intCount
* the number of ints to write, must be no less than zero and not
- * greater than {@code src.length - off}.
+ * greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code intCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code intCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public IntBuffer put(int[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public IntBuffer put(int[] src, int srcOffset, int intCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, intCount);
+ if (intCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + intCount; ++i) {
put(src[i]);
}
return this;
@@ -487,22 +468,4 @@ public abstract class IntBuffer extends Buffer implements Comparable<IntBuffer>
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract IntBuffer slice();
-
- /**
- * Returns a string represents of the state of this int buffer.
- *
- * @return a string represents of the state of this int buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/IntToByteBufferAdapter.java b/luni/src/main/java/java/nio/IntToByteBufferAdapter.java
index 03ac9f9..10eb488 100644
--- a/luni/src/main/java/java/nio/IntToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/IntToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a int buffer.
@@ -32,76 +31,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </p>
*
*/
-final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
-
- static IntBuffer wrap(ByteBuffer byteBuffer) {
- return new IntToByteBufferAdapter(byteBuffer.slice());
- }
+final class IntToByteBufferAdapter extends IntBuffer {
private final ByteBuffer byteBuffer;
- IntToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
- }
-
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
+ static IntBuffer asIntBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new IntToByteBufferAdapter(slice);
}
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ private IntToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super(byteBuffer.capacity() / SizeOf.INT);
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public IntBuffer asReadOnlyBuffer() {
- IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -113,8 +62,8 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
+ byteBuffer.limit(limit * SizeOf.INT);
+ byteBuffer.position(position * SizeOf.INT);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -125,8 +74,7 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
@Override
public IntBuffer duplicate() {
- IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
- .duplicate());
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -138,15 +86,26 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getInt(position++ << 2);
+ return byteBuffer.getInt(position++ * SizeOf.INT);
}
@Override
public int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getInt(index * SizeOf.INT);
+ }
+
+ @Override
+ public IntBuffer get(int[] dst, int dstOffset, int intCount) {
+ byteBuffer.limit(limit * SizeOf.INT);
+ byteBuffer.position(position * SizeOf.INT);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, intCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, intCount);
}
- return byteBuffer.getInt(index << 2);
+ this.position += intCount;
+ return this;
}
@Override
@@ -184,38 +143,34 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putInt(position++ << 2, c);
+ byteBuffer.putInt(position++ * SizeOf.INT, c);
return this;
}
@Override
public IntBuffer put(int index, int c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putInt(index << 2, c);
+ checkIndex(index);
+ byteBuffer.putInt(index * SizeOf.INT, c);
return this;
}
- // BEGIN android-added
@Override
- public IntBuffer put(int[] i, int off, int len) {
+ public IntBuffer put(int[] src, int srcOffset, int intCount) {
+ byteBuffer.limit(limit * SizeOf.INT);
+ byteBuffer.position(position * SizeOf.INT);
if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- ((ReadWriteDirectByteBuffer) byteBuffer).put(i, off, len);
- this.position += len;
- return this;
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, intCount);
} else {
- return super.put(i, off, len);
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, intCount);
}
+ this.position += intCount;
+ return this;
}
- // END android-added
@Override
public IntBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
+ byteBuffer.limit(limit * SizeOf.INT);
+ byteBuffer.position(position * SizeOf.INT);
IntBuffer result = new IntToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
diff --git a/luni/src/main/java/java/nio/LongArrayBuffer.java b/luni/src/main/java/java/nio/LongArrayBuffer.java
index 39f66e7..8dd0cfb 100644
--- a/luni/src/main/java/java/nio/LongArrayBuffer.java
+++ b/luni/src/main/java/java/nio/LongArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class LongArrayBuffer extends LongBuffer {
@Override
public final long get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final LongBuffer get(long[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final LongBuffer get(long[] dst, int dstOffset, int longCount) {
+ if (longCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, longCount);
+ position += longCount;
return this;
}
diff --git a/luni/src/main/java/java/nio/LongBuffer.java b/luni/src/main/java/java/nio/LongBuffer.java
index b07185d..3b4be66 100644
--- a/luni/src/main/java/java/nio/LongBuffer.java
+++ b/luni/src/main/java/java/nio/LongBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer of longs.
* <p>
@@ -46,7 +48,7 @@ public abstract class LongBuffer extends Buffer implements
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newLongBuffer(capacity);
+ return new ReadWriteLongArrayBuffer(capacity);
}
/**
@@ -67,44 +69,30 @@ public abstract class LongBuffer extends Buffer implements
* Creates a new long buffer by wrapping the given long array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + longCount}, capacity will be the length of the array.
*
* @param array
* the long array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param longCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created long buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code longCount} is invalid.
*/
- public static LongBuffer wrap(long[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long) len + (long) start > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- LongBuffer buf = BufferFactory.newLongBuffer(array);
+ public static LongBuffer wrap(long[] array, int start, int longCount) {
+ Arrays.checkOffsetAndCount(array.length, start, longCount);
+ LongBuffer buf = new ReadWriteLongArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + longCount;
return buf;
}
- /**
- * Constructs a {@code LongBuffer} with given capacity.
- *
- * @param capacity
- * The capacity of the buffer
- */
LongBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 3;
+ super(3, capacity, null);
}
public final long[] array() {
@@ -257,28 +245,24 @@ public abstract class LongBuffer extends Buffer implements
*
* @param dst
* the target long array.
- * @param off
+ * @param dstOffset
* the offset of the long array, must not be negative and not
* greater than {@code dst.length}.
- * @param len
+ * @param longCount
* the number of longs to read, must be no less than zero and not
- * greater than {@code dst.length - off}.
+ * greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code longCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code longCount} is greater than {@code remaining()}.
*/
- public LongBuffer get(long[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public LongBuffer get(long[] dst, int dstOffset, int longCount) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, longCount);
+ if (longCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + longCount; ++i) {
dst[i] = get();
}
return this;
@@ -402,30 +386,26 @@ public abstract class LongBuffer extends Buffer implements
*
* @param src
* the source long array.
- * @param off
+ * @param srcOffset
* the offset of long array, must not be negative and not greater
* than {@code src.length}.
- * @param len
+ * @param longCount
* the number of longs to write, must be no less than zero and
- * not greater than {@code src.length - off}.
+ * not greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code longCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code longCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public LongBuffer put(long[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ public LongBuffer put(long[] src, int srcOffset, int longCount) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, longCount);
+ if (longCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + longCount; ++i) {
put(src[i]);
}
return this;
@@ -492,22 +472,4 @@ public abstract class LongBuffer extends Buffer implements
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract LongBuffer slice();
-
- /**
- * Returns a string representing the state of this long buffer.
- *
- * @return a string representing the state of this long buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/LongToByteBufferAdapter.java b/luni/src/main/java/java/nio/LongToByteBufferAdapter.java
index ca40c5f..022c543 100644
--- a/luni/src/main/java/java/nio/LongToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/LongToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a long buffer.
@@ -32,76 +31,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </p>
*
*/
-final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
-
- static LongBuffer wrap(ByteBuffer byteBuffer) {
- return new LongToByteBufferAdapter(byteBuffer.slice());
- }
+final class LongToByteBufferAdapter extends LongBuffer {
private final ByteBuffer byteBuffer;
- LongToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 3));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
+ static LongBuffer asLongBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new LongToByteBufferAdapter(slice);
}
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ private LongToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super(byteBuffer.capacity() / SizeOf.LONG);
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public LongBuffer asReadOnlyBuffer() {
- LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -113,8 +62,8 @@ final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
+ byteBuffer.limit(limit * SizeOf.LONG);
+ byteBuffer.position(position * SizeOf.LONG);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -125,8 +74,7 @@ final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
@Override
public LongBuffer duplicate() {
- LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
- .duplicate());
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -138,15 +86,26 @@ final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getLong(position++ << 3);
+ return byteBuffer.getLong(position++ * SizeOf.LONG);
}
@Override
public long get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getLong(index * SizeOf.LONG);
+ }
+
+ @Override
+ public LongBuffer get(long[] dst, int dstOffset, int longCount) {
+ byteBuffer.limit(limit * SizeOf.LONG);
+ byteBuffer.position(position * SizeOf.LONG);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, longCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, longCount);
}
- return byteBuffer.getLong(index << 3);
+ this.position += longCount;
+ return this;
}
@Override
@@ -184,23 +143,34 @@ final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer {
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putLong(position++ << 3, c);
+ byteBuffer.putLong(position++ * SizeOf.LONG, c);
return this;
}
@Override
public LongBuffer put(int index, long c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ byteBuffer.putLong(index * SizeOf.LONG, c);
+ return this;
+ }
+
+ @Override
+ public LongBuffer put(long[] src, int srcOffset, int longCount) {
+ byteBuffer.limit(limit * SizeOf.LONG);
+ byteBuffer.position(position * SizeOf.LONG);
+ if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, longCount);
+ } else {
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, longCount);
}
- byteBuffer.putLong(index << 3, c);
+ this.position += longCount;
return this;
}
@Override
public LongBuffer slice() {
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
+ byteBuffer.limit(limit * SizeOf.LONG);
+ byteBuffer.position(position * SizeOf.LONG);
LongBuffer result = new LongToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
diff --git a/luni/src/main/java/java/nio/MappedByteBuffer.java b/luni/src/main/java/java/nio/MappedByteBuffer.java
index 4c7902d..9a99781 100644
--- a/luni/src/main/java/java/nio/MappedByteBuffer.java
+++ b/luni/src/main/java/java/nio/MappedByteBuffer.java
@@ -17,9 +17,7 @@
package java.nio;
import java.nio.channels.FileChannel.MapMode;
-import org.apache.harmony.luni.platform.MappedPlatformAddress;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* {@code MappedByteBuffer} is a special kind of direct byte buffer which maps a
@@ -42,7 +40,7 @@ public abstract class MappedByteBuffer extends ByteBuffer {
private final MapMode mapMode;
MappedByteBuffer(ByteBuffer directBuffer) {
- super(directBuffer.capacity);
+ super(directBuffer.capacity, directBuffer.block);
if (!directBuffer.isDirect()) {
throw new IllegalArgumentException();
}
@@ -50,15 +48,14 @@ public abstract class MappedByteBuffer extends ByteBuffer {
this.mapMode = null;
}
- MappedByteBuffer(PlatformAddress addr, int capacity, int offset, MapMode mapMode) {
- super(capacity);
+ MappedByteBuffer(MemoryBlock block, int capacity, int offset, MapMode mapMode) {
+ super(capacity, block);
this.mapMode = mapMode;
if (mapMode == MapMode.READ_ONLY) {
- wrapped = new ReadOnlyDirectByteBuffer(addr, capacity, offset);
+ wrapped = new ReadOnlyDirectByteBuffer(block, capacity, offset);
} else {
- wrapped = new ReadWriteDirectByteBuffer(addr, capacity, offset);
+ wrapped = new ReadWriteDirectByteBuffer(block, capacity, offset);
}
- addr.autoFree();
}
/**
@@ -70,7 +67,7 @@ public abstract class MappedByteBuffer extends ByteBuffer {
* otherwise.
*/
public final boolean isLoaded() {
- return ((MappedPlatformAddress) ((DirectBuffer) wrapped).getBaseAddress()).mmapIsLoaded();
+ return OSMemory.isLoaded(block.toInt(), block.getSize());
}
/**
@@ -80,7 +77,7 @@ public abstract class MappedByteBuffer extends ByteBuffer {
* @return this buffer.
*/
public final MappedByteBuffer load() {
- ((MappedPlatformAddress) ((DirectBuffer) wrapped).getBaseAddress()).mmapLoad();
+ OSMemory.load(block.toInt(), block.getSize());
return this;
}
@@ -94,7 +91,7 @@ public abstract class MappedByteBuffer extends ByteBuffer {
*/
public final MappedByteBuffer force() {
if (mapMode == MapMode.READ_WRITE) {
- ((MappedPlatformAddress) ((DirectBuffer) wrapped).getBaseAddress()).mmapFlush();
+ OSMemory.msync(block.toInt(), block.getSize());
}
return this;
}
diff --git a/luni/src/main/java/java/nio/MappedByteBufferAdapter.java b/luni/src/main/java/java/nio/MappedByteBufferAdapter.java
index a66c4b7..73b2991 100644
--- a/luni/src/main/java/java/nio/MappedByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/MappedByteBufferAdapter.java
@@ -15,224 +15,213 @@
* limitations under the License.
*/
-// BEGIN android-note
-// added some missing updates on position and limit
-// END android-note
-
package java.nio;
import java.nio.channels.FileChannel.MapMode;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
- * @hide
+ * Rather than duplicate all the code from ReadOnlyDirectByteBuffer and
+ * ReadWriteDirectByteBuffer (and their superclasses), we delegate to one or the other.
+ * The tricky part is that we need to keep our fields in sync with our delegate's fields.
+ * There are lots of methods that access the fields directly.
+ *
+ * The main consequences of this implementation are:
+ *
+ * 1. we need to explicitly call wrapped.position(int) before any operation on our delegate
+ * that makes use of the implicit position.
+ *
+ * 2. we need to explicitly update position after any operation on our delegate that makes
+ * use of the implicit position.
+ *
+ * This means that, even more than usual, the implicit iteration
+ * operations are more expensive than the indexed operations.
+ *
+ * But we save a ton of code, for classes that no-one really uses because the API's broken
+ * by design (disallowing munmap(2) calls). Internally, we can use libcore.io.MemoryMappedFile
+ * as a high-performance and more usable replacement for MappedByteBuffer.
+ *
+ * FIXME: harmony changed their implementation after we diverged, switching to a scheme
+ * where DirectByteBuffer extends MappedByteBuffer and this class doesn't exist. That's
+ * much better than their original implementation, fossilized here.
*/
-public final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBuffer {
-
- private static final int CHAR_SIZE = 2;
-
- private static final int SHORT_SIZE = 2;
-
- private static final int INTEGER_SIZE = 4;
-
- private static final int LONG_SIZE = 8;
-
- private static final int FLOAT_SIZE = 4;
+final class MappedByteBufferAdapter extends MappedByteBuffer {
+ private MappedByteBufferAdapter(ByteBuffer buffer) {
+ super(buffer);
+ effectiveDirectAddress = wrapped.effectiveDirectAddress;
+ }
- private static final int DOUBLE_SIZE = 8;
+ public MappedByteBufferAdapter(MemoryBlock block, int capacity, int offset, MapMode mode) {
+ super(block, capacity, offset, mode);
+ effectiveDirectAddress = wrapped.effectiveDirectAddress;
+ }
- public MappedByteBufferAdapter(ByteBuffer buffer) {
- super(buffer);
+ @Override void limitImpl(int newLimit) {
+ super.limitImpl(newLimit);
+ wrapped.limit(newLimit);
}
- public MappedByteBufferAdapter(PlatformAddress addr, int capa, int offset, MapMode mode) {
- super(addr, capa, offset, mode);
+ @Override void positionImpl(int newPosition) {
+ super.positionImpl(newPosition);
+ wrapped.position(newPosition);
}
@Override
public CharBuffer asCharBuffer() {
- return this.wrapped.asCharBuffer();
+ return wrapped.asCharBuffer();
}
@Override
public DoubleBuffer asDoubleBuffer() {
- return this.wrapped.asDoubleBuffer();
+ return wrapped.asDoubleBuffer();
}
@Override
public FloatBuffer asFloatBuffer() {
- return this.wrapped.asFloatBuffer();
+ return wrapped.asFloatBuffer();
}
@Override
public IntBuffer asIntBuffer() {
- return this.wrapped.asIntBuffer();
+ return wrapped.asIntBuffer();
}
@Override
public LongBuffer asLongBuffer() {
- return this.wrapped.asLongBuffer();
+ return wrapped.asLongBuffer();
}
@Override
public ByteBuffer asReadOnlyBuffer() {
- MappedByteBufferAdapter buf = new MappedByteBufferAdapter(this.wrapped
- .asReadOnlyBuffer());
- buf.limit = this.limit;
- buf.position = this.position;
- buf.mark = this.mark;
- return buf;
+ MappedByteBufferAdapter result = new MappedByteBufferAdapter(wrapped.asReadOnlyBuffer());
+ result.limit(limit);
+ result.position(position);
+ result.mark = mark;
+ return result;
}
@Override
public ShortBuffer asShortBuffer() {
- return this.wrapped.asShortBuffer();
+ return wrapped.asShortBuffer();
}
@Override
public ByteBuffer compact() {
- if (this.wrapped.isReadOnly()) {
+ if (wrapped.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.compact();
- this.wrapped.clear();
- this.position = this.limit - this.position;
- this.limit = this.capacity;
+ wrapped.compact();
+ limit(capacity);
+ position(wrapped.position());
this.mark = UNSET_MARK;
return this;
}
@Override
public ByteBuffer duplicate() {
- MappedByteBufferAdapter buf = new MappedByteBufferAdapter(this.wrapped
- .duplicate());
- buf.limit = this.limit;
- buf.position = this.position;
- buf.mark = this.mark;
- return buf;
+ MappedByteBufferAdapter result = new MappedByteBufferAdapter(wrapped.duplicate());
+ result.limit(limit);
+ result.position(position);
+ result.mark = mark;
+ return result;
}
@Override
public byte get() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- byte result = this.wrapped.get();
- this.position++;
+ wrapped.position(position);
+ byte result = wrapped.get();
+ ++position;
return result;
}
@Override
public byte get(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.get(index);
+ return wrapped.get(index);
+ }
+
+ @Override
+ public ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
+ ByteBuffer result = wrapped.get(dst, dstOffset, byteCount);
+ position += byteCount;
+ return result;
}
@Override
public char getChar() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- char result = this.wrapped.getChar();
- this.position += CHAR_SIZE;
+ wrapped.position(position);
+ char result = wrapped.getChar();
+ position += SizeOf.CHAR;
return result;
}
@Override
public char getChar(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getChar(index);
+ return wrapped.getChar(index);
}
@Override
public double getDouble() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- double result = this.wrapped.getDouble();
- this.position += DOUBLE_SIZE;
+ wrapped.position(position);
+ double result = wrapped.getDouble();
+ position += SizeOf.DOUBLE;
return result;
}
@Override
public double getDouble(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getDouble(index);
- }
-
- public PlatformAddress getEffectiveAddress() {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer) this.wrapped).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
+ return wrapped.getDouble(index);
}
@Override
public float getFloat() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- float result = this.wrapped.getFloat();
- this.position += FLOAT_SIZE;
+ wrapped.position(position);
+ float result = wrapped.getFloat();
+ position += SizeOf.FLOAT;
return result;
}
@Override
public float getFloat(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getFloat(index);
+ return wrapped.getFloat(index);
}
@Override
public int getInt() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- int result = this.wrapped.getInt();
- this.position += INTEGER_SIZE;
+ wrapped.position(position);
+ int result = wrapped.getInt();
+ position += SizeOf.INT;
return result;
}
@Override
public int getInt(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getInt(index);
+ return wrapped.getInt(index);
}
@Override
public long getLong() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- long result = this.wrapped.getLong();
- this.position += LONG_SIZE;
+ wrapped.position(position);
+ long result = wrapped.getLong();
+ position += SizeOf.LONG;
return result;
}
@Override
public long getLong(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getLong(index);
+ return wrapped.getLong(index);
}
@Override
public short getShort() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- short result = this.wrapped.getShort();
- this.position += SHORT_SIZE;
+ wrapped.position(position);
+ short result = wrapped.getShort();
+ position += SizeOf.SHORT;
return result;
}
@Override
public short getShort(int index) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- return this.wrapped.getShort(index);
+ return wrapped.getShort(index);
}
@Override
@@ -242,185 +231,151 @@ public final class MappedByteBufferAdapter extends MappedByteBuffer implements D
@Override
public boolean isReadOnly() {
- return this.wrapped.isReadOnly();
+ return wrapped.isReadOnly();
}
- @Override
- ByteBuffer orderImpl(ByteOrder byteOrder) {
+ @Override void orderImpl(ByteOrder byteOrder) {
super.orderImpl(byteOrder);
- return this.wrapped.order(byteOrder);
+ wrapped.order(byteOrder);
}
@Override
public ByteBuffer put(byte b) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.put(b);
+ wrapped.position(this.position);
+ wrapped.put(b);
this.position++;
return this;
}
@Override
- public ByteBuffer put(byte[] src, int off, int len) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.put(src, off, len);
- this.position += len;
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
+ wrapped.position(this.position);
+ wrapped.put(src, srcOffset, byteCount);
+ this.position += byteCount;
return this;
}
@Override
public ByteBuffer put(int index, byte b) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.put(index, b);
+ wrapped.position(this.position);
+ wrapped.put(index, b);
return this;
}
@Override
public ByteBuffer putChar(char value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putChar(value);
- this.position += CHAR_SIZE;
+ wrapped.position(this.position);
+ wrapped.putChar(value);
+ this.position += SizeOf.CHAR;
return this;
}
@Override
public ByteBuffer putChar(int index, char value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putChar(index, value);
+ wrapped.position(this.position);
+ wrapped.putChar(index, value);
return this;
}
@Override
public ByteBuffer putDouble(double value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putDouble(value);
- this.position += DOUBLE_SIZE;
+ wrapped.position(this.position);
+ wrapped.putDouble(value);
+ this.position += SizeOf.DOUBLE;
return this;
}
@Override
public ByteBuffer putDouble(int index, double value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putDouble(index, value);
+ wrapped.position(this.position);
+ wrapped.putDouble(index, value);
return this;
}
@Override
public ByteBuffer putFloat(float value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putFloat(value);
- this.position += FLOAT_SIZE;
+ wrapped.position(this.position);
+ wrapped.putFloat(value);
+ this.position += SizeOf.FLOAT;
return this;
}
@Override
public ByteBuffer putFloat(int index, float value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putFloat(index, value);
+ wrapped.position(this.position);
+ wrapped.putFloat(index, value);
return this;
}
@Override
public ByteBuffer putInt(int index, int value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putInt(index, value);
+ wrapped.position(this.position);
+ wrapped.putInt(index, value);
return this;
}
@Override
public ByteBuffer putInt(int value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putInt(value);
- this.position += INTEGER_SIZE;
+ wrapped.position(this.position);
+ wrapped.putInt(value);
+ this.position += SizeOf.INT;
return this;
}
@Override
public ByteBuffer putLong(int index, long value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putLong(index, value);
+ wrapped.position(this.position);
+ wrapped.putLong(index, value);
return this;
}
@Override
public ByteBuffer putLong(long value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putLong(value);
- this.position += LONG_SIZE;
+ wrapped.position(this.position);
+ wrapped.putLong(value);
+ this.position += SizeOf.LONG;
return this;
}
@Override
public ByteBuffer putShort(int index, short value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putShort(index, value);
+ wrapped.position(this.position);
+ wrapped.putShort(index, value);
return this;
}
@Override
public ByteBuffer putShort(short value) {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- this.wrapped.putShort(value);
- this.position += SHORT_SIZE;
+ wrapped.position(this.position);
+ wrapped.putShort(value);
+ this.position += SizeOf.SHORT;
return this;
}
@Override
public ByteBuffer slice() {
- this.wrapped.limit(this.limit);
- this.wrapped.position(this.position);
- MappedByteBufferAdapter result = new MappedByteBufferAdapter(
- this.wrapped.slice());
- this.wrapped.clear();
+ wrapped.position(this.position);
+ MappedByteBufferAdapter result = new MappedByteBufferAdapter(wrapped.slice());
+ wrapped.clear();
return result;
}
@Override
byte[] protectedArray() {
- return this.wrapped.protectedArray();
+ return wrapped.protectedArray();
}
@Override
int protectedArrayOffset() {
- return this.wrapped.protectedArrayOffset();
+ return wrapped.protectedArrayOffset();
}
@Override
boolean protectedHasArray() {
- return this.wrapped.protectedHasArray();
- }
-
- public PlatformAddress getBaseAddress() {
- return this.wrapped.getBaseAddress();
- }
-
- public boolean isAddressValid() {
- return this.wrapped.isAddressValid();
- }
-
- public void addressValidityCheck() {
- this.wrapped.addressValidityCheck();
- }
-
- public void free() {
- this.wrapped.free();
+ return wrapped.protectedHasArray();
}
- public int getByteCapacity() {
- return wrapped.getByteCapacity();
+ public final void free() {
+ wrapped.free();
}
}
diff --git a/luni/src/main/java/java/nio/MemoryBlock.java b/luni/src/main/java/java/nio/MemoryBlock.java
new file mode 100644
index 0000000..76a7b36
--- /dev/null
+++ b/luni/src/main/java/java/nio/MemoryBlock.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import dalvik.system.VMRuntime;
+import java.io.IOException;
+import java.nio.channels.FileChannel.MapMode;
+import org.apache.harmony.luni.platform.OSMemory;
+
+class MemoryBlock {
+ /**
+ * Handles calling munmap(2) on a memory-mapped region.
+ */
+ private static class MemoryMappedBlock extends MemoryBlock {
+ private MemoryMappedBlock(int address, long byteCount) {
+ super(address, byteCount);
+ }
+
+ @Override public void free() {
+ if (address != 0) {
+ OSMemory.munmap(address, size);
+ address = 0;
+ }
+ }
+
+ @Override protected void finalize() throws Throwable {
+ free();
+ }
+ }
+
+ /**
+ * Non-movable heap blocks are byte arrays on the Java heap that the GC
+ * guarantees not to move. Used to implement DirectByteBuffer.
+ *
+ * Losing the strong reference to the array is sufficient
+ * to allow the GC to reclaim the storage. No finalizer needed.
+ */
+ private static class NonMovableHeapBlock extends MemoryBlock {
+ private byte[] array;
+
+ private NonMovableHeapBlock(byte[] array, int address, long byteCount) {
+ super(address, byteCount);
+ this.array = array;
+ }
+
+ @Override public void free() {
+ array = null;
+ address = 0;
+ }
+ }
+
+ /**
+ * Represents a block of memory we don't own. (We don't take ownership of memory corresponding
+ * to direct buffers created by the JNI NewDirectByteBuffer function.)
+ */
+ private static class UnmanagedBlock extends MemoryBlock {
+ private UnmanagedBlock(int address, long byteCount) {
+ super(address, byteCount);
+ }
+ }
+
+ // TODO: should be long on 64-bit devices; int for performance.
+ protected int address;
+ protected final long size;
+
+ public static MemoryBlock mmap(int fd, long start, long size, MapMode mode) throws IOException {
+ if (size == 0) {
+ // You can't mmap(2) a zero-length region.
+ return new MemoryBlock(0, 0);
+ }
+ int address = OSMemory.mmap(fd, start, size, mode);
+ return new MemoryMappedBlock(address, size);
+ }
+
+ public static MemoryBlock allocate(int byteCount) {
+ VMRuntime runtime = VMRuntime.getRuntime();
+ byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, byteCount);
+ int address = (int) runtime.addressOf(array);
+ return new NonMovableHeapBlock(array, address, byteCount);
+ }
+
+ public static MemoryBlock wrapFromJni(int address, long byteCount) {
+ return new UnmanagedBlock(address, byteCount);
+ }
+
+ private MemoryBlock(int address, long size) {
+ this.address = address;
+ this.size = size;
+ }
+
+ public void free() {
+ }
+
+ public final void pokeByte(int offset, byte value) {
+ OSMemory.pokeByte(address + offset, value);
+ }
+
+ public final void pokeByteArray(int offset, byte[] src, int srcOffset, int byteCount) {
+ OSMemory.pokeByteArray(address + offset, src, srcOffset, byteCount);
+ }
+
+ public final void pokeCharArray(int offset, char[] src, int srcOffset, int charCount, boolean swap) {
+ OSMemory.pokeCharArray(address + offset, src, srcOffset, charCount, swap);
+ }
+
+ public final void pokeDoubleArray(int offset, double[] src, int srcOffset, int doubleCount, boolean swap) {
+ OSMemory.pokeDoubleArray(address + offset, src, srcOffset, doubleCount, swap);
+ }
+
+ public final void pokeFloatArray(int offset, float[] src, int srcOffset, int floatCount, boolean swap) {
+ OSMemory.pokeFloatArray(address + offset, src, srcOffset, floatCount, swap);
+ }
+
+ public final void pokeIntArray(int offset, int[] src, int srcOffset, int intCount, boolean swap) {
+ OSMemory.pokeIntArray(address + offset, src, srcOffset, intCount, swap);
+ }
+
+ public final void pokeLongArray(int offset, long[] src, int srcOffset, int longCount, boolean swap) {
+ OSMemory.pokeLongArray(address + offset, src, srcOffset, longCount, swap);
+ }
+
+ public final void pokeShortArray(int offset, short[] src, int srcOffset, int shortCount, boolean swap) {
+ OSMemory.pokeShortArray(address + offset, src, srcOffset, shortCount, swap);
+ }
+
+ public final byte peekByte(int offset) {
+ return OSMemory.peekByte(address + offset);
+ }
+
+ public final void peekByteArray(int offset, byte[] dst, int dstOffset, int byteCount) {
+ OSMemory.peekByteArray(address + offset, dst, dstOffset, byteCount);
+ }
+
+ public final void peekCharArray(int offset, char[] dst, int dstOffset, int charCount, boolean swap) {
+ OSMemory.peekCharArray(address + offset, dst, dstOffset, charCount, swap);
+ }
+
+ public final void peekDoubleArray(int offset, double[] dst, int dstOffset, int doubleCount, boolean swap) {
+ OSMemory.peekDoubleArray(address + offset, dst, dstOffset, doubleCount, swap);
+ }
+
+ public final void peekFloatArray(int offset, float[] dst, int dstOffset, int floatCount, boolean swap) {
+ OSMemory.peekFloatArray(address + offset, dst, dstOffset, floatCount, swap);
+ }
+
+ public final void peekIntArray(int offset, int[] dst, int dstOffset, int intCount, boolean swap) {
+ OSMemory.peekIntArray(address + offset, dst, dstOffset, intCount, swap);
+ }
+
+ public final void peekLongArray(int offset, long[] dst, int dstOffset, int longCount, boolean swap) {
+ OSMemory.peekLongArray(address + offset, dst, dstOffset, longCount, swap);
+ }
+
+ public final void peekShortArray(int offset, short[] dst, int dstOffset, int shortCount, boolean swap) {
+ OSMemory.peekShortArray(address + offset, dst, dstOffset, shortCount, swap);
+ }
+
+ public final void pokeShort(int offset, short value, ByteOrder order) {
+ OSMemory.pokeShort(address + offset, value, order.needsSwap);
+ }
+
+ public final short peekShort(int offset, ByteOrder order) {
+ return OSMemory.peekShort(address + offset, order.needsSwap);
+ }
+
+ public final void pokeInt(int offset, int value, ByteOrder order) {
+ OSMemory.pokeInt(address + offset, value, order.needsSwap);
+ }
+
+ public final int peekInt(int offset, ByteOrder order) {
+ return OSMemory.peekInt(address + offset, order.needsSwap);
+ }
+
+ public final void pokeLong(int offset, long value, ByteOrder order) {
+ OSMemory.pokeLong(address + offset, value, order.needsSwap);
+ }
+
+ public final long peekLong(int offset, ByteOrder order) {
+ return OSMemory.peekLong(address + offset, order.needsSwap);
+ }
+
+ public final int toInt() {
+ return address;
+ }
+
+ public final String toString() {
+ return getClass().getName() + "[" + address + "]";
+ }
+
+ public final long getSize() {
+ return size;
+ }
+}
diff --git a/luni/src/main/java/java/nio/NIOAccess.java b/luni/src/main/java/java/nio/NIOAccess.java
index 431cb8b..361a37f 100644
--- a/luni/src/main/java/java/nio/NIOAccess.java
+++ b/luni/src/main/java/java/nio/NIOAccess.java
@@ -16,13 +16,10 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
-
/**
* This class is used via JNI by code in frameworks/base/.
*/
-class NIOAccess {
+final class NIOAccess {
/**
* Returns the underlying native pointer to the data of the given
@@ -36,26 +33,11 @@ class NIOAccess {
* position, or 0 if there is none
*/
static long getBasePointer(Buffer b) {
- if (b instanceof DirectBuffer) {
- PlatformAddress address = ((DirectBuffer) b).getEffectiveAddress();
- if (address == null) {
- return 0L;
- }
- return address.toInt() + (b.position() << b._elementSizeShift);
+ int address = b.effectiveDirectAddress;
+ if (address == 0) {
+ return 0L;
}
- return 0L;
- }
-
- /**
- * Returns the number of bytes remaining in the given Buffer. That is,
- * this scales <code>remaining()</code> by the byte-size of elements
- * of this Buffer.
- *
- * @param Buffer b the Buffer to be queried
- * @return the number of remaining bytes
- */
- static int getRemainingBytes(Buffer b) {
- return (b.limit - b.position) << b._elementSizeShift;
+ return address + (b.position << b._elementSizeShift);
}
/**
diff --git a/luni/src/main/java/java/nio/NioUtils.java b/luni/src/main/java/java/nio/NioUtils.java
new file mode 100644
index 0000000..5d7e7e2
--- /dev/null
+++ b/luni/src/main/java/java/nio/NioUtils.java
@@ -0,0 +1,87 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.nio.channels.FileChannel;
+import org.apache.harmony.luni.platform.IFileSystem;
+
+/**
+ * @hide internal use only
+ */
+public final class NioUtils {
+ private NioUtils() {
+ }
+
+ /**
+ * Gets the start address of a direct buffer.
+ * <p>
+ * This method corresponds to the JNI function:
+ *
+ * <pre>
+ * void* GetDirectBufferAddress(JNIEnv* env, jobject buf);
+ * </pre>
+ *
+ * @param buf
+ * the direct buffer whose address shall be returned must not be
+ * <code>null</code>.
+ * @return the address of the buffer given, or zero if the buffer is not a
+ * direct Buffer.
+ */
+ public static int getDirectBufferAddress(Buffer buffer) {
+ return buffer.effectiveDirectAddress;
+ }
+
+ public static void freeDirectBuffer(ByteBuffer buffer) {
+ if (buffer == null) {
+ return;
+ }
+ if (buffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) buffer).free();
+ } else if (buffer instanceof MappedByteBuffer) {
+ ((MappedByteBufferAdapter) buffer).free();
+ } else {
+ throw new AssertionError();
+ }
+ }
+
+ /**
+ * Returns the int file descriptor from within the given FileChannel 'fc'.
+ */
+ public static int getFd(FileChannel fc) {
+ return ((FileChannelImpl) fc).getHandle();
+ }
+
+ /**
+ * Helps bridge between io and nio.
+ */
+ public static FileChannel newFileChannel(Object stream, int fd, int mode) {
+ switch (mode) {
+ case IFileSystem.O_RDONLY:
+ return new ReadOnlyFileChannel(stream, fd);
+ case IFileSystem.O_WRONLY:
+ return new WriteOnlyFileChannel(stream, fd);
+ case IFileSystem.O_RDWR:
+ return new ReadWriteFileChannel(stream, fd);
+ case IFileSystem.O_RDWRSYNC:
+ return new ReadWriteFileChannel(stream, fd);
+ case IFileSystem.O_APPEND:
+ return new WriteOnlyFileChannel(stream, fd, true);
+ default:
+ throw new RuntimeException("Unknown mode: " + mode);
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/PipeImpl.java b/luni/src/main/java/java/nio/PipeImpl.java
new file mode 100644
index 0000000..2e6418e
--- /dev/null
+++ b/luni/src/main/java/java/nio/PipeImpl.java
@@ -0,0 +1,133 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.Closeable;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.nio.channels.Pipe;
+import java.nio.channels.spi.SelectorProvider;
+import libcore.io.IoUtils;
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+
+/*
+ * Implements {@link java.nio.channels.Pipe}.
+ */
+final class PipeImpl extends Pipe {
+ private final PipeSinkChannel sink;
+ private final PipeSourceChannel source;
+
+ public PipeImpl() throws IOException {
+ int[] fds = new int[2];
+ IoUtils.pipe(fds);
+ // Which fd is used for which channel is important. Unix pipes are only guaranteed to be
+ // unidirectional, and indeed are only unidirectional on Linux. See IoUtils.pipe.
+ this.sink = new PipeSinkChannel(fds[1]);
+ this.source = new PipeSourceChannel(fds[0]);
+ }
+
+ @Override public SinkChannel sink() {
+ return sink;
+ }
+
+ @Override public SourceChannel source() {
+ return source;
+ }
+
+ /**
+ * FileChannelImpl doesn't close its fd itself; it calls close on the object it's given.
+ */
+ private static class FdCloser implements Closeable {
+ private final FileDescriptor fd;
+ private FdCloser(FileDescriptor fd) {
+ this.fd = fd;
+ }
+ public void close() throws IOException {
+ IoUtils.close(fd);
+ }
+ }
+
+ private class PipeSourceChannel extends Pipe.SourceChannel implements FileDescriptorHandler {
+ private final FileDescriptor fd;
+ private final FileChannelImpl channel;
+
+ private PipeSourceChannel(int fd) throws IOException {
+ super(SelectorProvider.provider());
+ this.fd = IoUtils.newFileDescriptor(fd);
+ this.channel = new ReadOnlyFileChannel(new FdCloser(this.fd), fd);
+ }
+
+ @Override protected void implCloseSelectableChannel() throws IOException {
+ channel.close();
+ }
+
+ @Override protected void implConfigureBlocking(boolean blocking) throws IOException {
+ IoUtils.setBlocking(getFD(), blocking);
+ }
+
+ public int read(ByteBuffer buffer) throws IOException {
+ return channel.read(buffer);
+ }
+
+ public long read(ByteBuffer[] buffers) throws IOException {
+ return channel.read(buffers);
+ }
+
+ public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ return channel.read(buffers, offset, length);
+ }
+
+ public FileDescriptor getFD() {
+ return fd;
+ }
+ }
+
+ private class PipeSinkChannel extends Pipe.SinkChannel implements FileDescriptorHandler {
+ private final FileDescriptor fd;
+ private final FileChannelImpl channel;
+
+ private PipeSinkChannel(int fd) throws IOException {
+ super(SelectorProvider.provider());
+ this.fd = IoUtils.newFileDescriptor(fd);
+ this.channel = new WriteOnlyFileChannel(new FdCloser(this.fd), fd);
+ }
+
+ @Override protected void implCloseSelectableChannel() throws IOException {
+ channel.close();
+ }
+
+ @Override protected void implConfigureBlocking(boolean blocking) throws IOException {
+ IoUtils.setBlocking(getFD(), blocking);
+ }
+
+ public int write(ByteBuffer buffer) throws IOException {
+ return channel.write(buffer);
+ }
+
+ public long write(ByteBuffer[] buffers) throws IOException {
+ return channel.write(buffers);
+ }
+
+ public long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ return channel.write(buffers, offset, length);
+ }
+
+ public FileDescriptor getFD() {
+ return fd;
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
index 3388fcc..6f30dbc 100644
--- a/luni/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyCharArrayBuffer.java
@@ -32,9 +32,9 @@ package java.nio;
final class ReadOnlyCharArrayBuffer extends CharArrayBuffer {
static ReadOnlyCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) {
- ReadOnlyCharArrayBuffer buf = new ReadOnlyCharArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadOnlyCharArrayBuffer buf =
+ new ReadOnlyCharArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -90,7 +90,7 @@ final class ReadOnlyCharArrayBuffer extends CharArrayBuffer {
}
@Override
- public final CharBuffer put(char[] src, int off, int len) {
+ public final CharBuffer put(char[] src, int srcOffset, int charCount) {
throw new ReadOnlyBufferException();
}
@@ -101,16 +101,11 @@ final class ReadOnlyCharArrayBuffer extends CharArrayBuffer {
@Override
public CharBuffer put(String src, int start, int end) {
- if ((start < 0) || (end < 0)
- || (long) start + (long) end > src.length()) {
- throw new IndexOutOfBoundsException();
- }
throw new ReadOnlyBufferException();
}
@Override
public CharBuffer slice() {
- return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java b/luni/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
index 6da6725..d061e9c 100644
--- a/luni/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyDirectByteBuffer.java
@@ -17,8 +17,6 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-
/**
* DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
* compose the implementation of platform memory based byte buffers.
@@ -29,26 +27,18 @@ import org.apache.harmony.luni.platform.PlatformAddress;
* <p>
* This class is marked final for runtime performance.
* </p>
- *
*/
final class ReadOnlyDirectByteBuffer extends DirectByteBuffer {
-
static ReadOnlyDirectByteBuffer copy(DirectByteBuffer other, int markOfOther) {
- ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
- other.safeAddress, other.capacity(), other.offset);
- buf.limit = other.limit();
+ ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(other.block, other.capacity(), other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
- buf.order(other.order());
return buf;
}
- protected ReadOnlyDirectByteBuffer(SafeAddress address, int capacity, int offset) {
- super(address, capacity, offset);
- }
-
- protected ReadOnlyDirectByteBuffer(PlatformAddress address, int capacity, int offset) {
- super(new SafeAddress(address), capacity, offset);
+ protected ReadOnlyDirectByteBuffer(MemoryBlock block, int capacity, int offset) {
+ super(block, capacity, offset);
}
@Override
@@ -82,7 +72,7 @@ final class ReadOnlyDirectByteBuffer extends DirectByteBuffer {
}
@Override
- public ByteBuffer put(byte[] src, int off, int len) {
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
throw new ReadOnlyBufferException();
}
@@ -143,10 +133,6 @@ final class ReadOnlyDirectByteBuffer extends DirectByteBuffer {
@Override
public ByteBuffer slice() {
- ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
- safeAddress, remaining(), offset + position);
- buf.order = order;
- return buf;
+ return new ReadOnlyDirectByteBuffer(block, remaining(), offset + position);
}
-
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java
index d3cf353..460bbf4 100644
--- a/luni/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyDoubleArrayBuffer.java
@@ -31,18 +31,16 @@ package java.nio;
*/
final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
- static ReadOnlyDoubleArrayBuffer copy(DoubleArrayBuffer other,
- int markOfOther) {
- ReadOnlyDoubleArrayBuffer buf = new ReadOnlyDoubleArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ static ReadOnlyDoubleArrayBuffer copy(DoubleArrayBuffer other, int markOfOther) {
+ ReadOnlyDoubleArrayBuffer buf =
+ new ReadOnlyDoubleArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
}
- ReadOnlyDoubleArrayBuffer(int capacity, double[] backingArray,
- int arrayOffset) {
+ ReadOnlyDoubleArrayBuffer(int capacity, double[] backingArray, int arrayOffset) {
super(capacity, backingArray, arrayOffset);
}
@@ -92,7 +90,7 @@ final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
}
@Override
- public final DoubleBuffer put(double[] src, int off, int len) {
+ public final DoubleBuffer put(double[] src, int srcOffset, int byteCount) {
throw new ReadOnlyBufferException();
}
@@ -103,8 +101,7 @@ final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
@Override
public DoubleBuffer slice() {
- return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyFileChannel.java b/luni/src/main/java/java/nio/ReadOnlyFileChannel.java
new file mode 100644
index 0000000..8d3a907
--- /dev/null
+++ b/luni/src/main/java/java/nio/ReadOnlyFileChannel.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.ReadableByteChannel;
+import java.util.Arrays;
+
+final class ReadOnlyFileChannel extends FileChannelImpl {
+ public ReadOnlyFileChannel(Object stream, int handle) {
+ super(stream, handle);
+ }
+
+ public final int write(ByteBuffer buffer, long position) throws IOException {
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0) {
+ throw new IllegalArgumentException();
+ }
+ throw new NonWritableChannelException();
+ }
+
+ public final int write(ByteBuffer buffer) throws IOException {
+ openCheck();
+ throw new NonWritableChannelException();
+ }
+
+ public final long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(buffers.length, offset, length);
+ openCheck();
+ throw new NonWritableChannelException();
+ }
+
+ public final FileChannel truncate(long size) throws IOException {
+ openCheck();
+ if (size < 0) {
+ throw new IllegalArgumentException();
+ }
+ throw new NonWritableChannelException();
+ }
+
+ public final long transferFrom(ReadableByteChannel src, long position,
+ long count) throws IOException {
+ openCheck();
+ if (!src.isOpen()) {
+ throw new ClosedChannelException();
+ }
+ throw new NonWritableChannelException();
+ }
+
+ public final MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
+ openCheck();
+ if (mode == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException();
+ }
+ if (mode != MapMode.READ_ONLY) {
+ throw new NonWritableChannelException();
+ }
+ return super.mapImpl(mode, position, size);
+ }
+
+ @Override public final void force(boolean metadata) throws IOException {
+ openCheck();
+ }
+
+ protected final FileLock basicLock(long position, long size,
+ boolean shared, boolean wait) throws IOException {
+ if (!shared) {
+ throw new NonWritableChannelException();
+ }
+ return super.basicLock(position, size, shared, true);
+ }
+}
diff --git a/luni/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java
index f617a94..775e1d8 100644
--- a/luni/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyFloatArrayBuffer.java
@@ -32,9 +32,9 @@ package java.nio;
final class ReadOnlyFloatArrayBuffer extends FloatArrayBuffer {
static ReadOnlyFloatArrayBuffer copy(FloatArrayBuffer other, int markOfOther) {
- ReadOnlyFloatArrayBuffer buf = new ReadOnlyFloatArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadOnlyFloatArrayBuffer buf =
+ new ReadOnlyFloatArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -95,14 +95,13 @@ final class ReadOnlyFloatArrayBuffer extends FloatArrayBuffer {
}
@Override
- public final FloatBuffer put(float[] src, int off, int len) {
+ public final FloatBuffer put(float[] src, int srcOffset, int byteCount) {
throw new ReadOnlyBufferException();
}
@Override
public FloatBuffer slice() {
- return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java b/luni/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
index bee1e5d..ca486cb 100644
--- a/luni/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyHeapByteBuffer.java
@@ -32,12 +32,11 @@ package java.nio;
final class ReadOnlyHeapByteBuffer extends HeapByteBuffer {
static ReadOnlyHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
- ReadOnlyHeapByteBuffer buf = new ReadOnlyHeapByteBuffer(
- other.backingArray, other.capacity(), other.offset);
- buf.limit = other.limit();
+ ReadOnlyHeapByteBuffer buf =
+ new ReadOnlyHeapByteBuffer(other.backingArray, other.capacity(), other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
- buf.order(other.order());
return buf;
}
@@ -91,7 +90,7 @@ final class ReadOnlyHeapByteBuffer extends HeapByteBuffer {
}
@Override
- public ByteBuffer put(byte[] src, int off, int len) {
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
throw new ReadOnlyBufferException();
}
@@ -152,9 +151,6 @@ final class ReadOnlyHeapByteBuffer extends HeapByteBuffer {
@Override
public ByteBuffer slice() {
- ReadOnlyHeapByteBuffer slice = new ReadOnlyHeapByteBuffer(backingArray,
- remaining(), offset + position);
- slice.order = order;
- return slice;
+ return new ReadOnlyHeapByteBuffer(backingArray, remaining(), offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java
index 12dd275..a137b3b 100644
--- a/luni/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyIntArrayBuffer.java
@@ -32,9 +32,9 @@ package java.nio;
final class ReadOnlyIntArrayBuffer extends IntArrayBuffer {
static ReadOnlyIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
- ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadOnlyIntArrayBuffer buf =
+ new ReadOnlyIntArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -95,14 +95,13 @@ final class ReadOnlyIntArrayBuffer extends IntArrayBuffer {
}
@Override
- public final IntBuffer put(int[] src, int off, int len) {
+ public final IntBuffer put(int[] src, int srcOffset, int intCount) {
throw new ReadOnlyBufferException();
}
@Override
public IntBuffer slice() {
- return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java
index fbe3249..87b0c88 100644
--- a/luni/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyLongArrayBuffer.java
@@ -32,9 +32,9 @@ package java.nio;
final class ReadOnlyLongArrayBuffer extends LongArrayBuffer {
static ReadOnlyLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
- ReadOnlyLongArrayBuffer buf = new ReadOnlyLongArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadOnlyLongArrayBuffer buf =
+ new ReadOnlyLongArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -95,14 +95,13 @@ final class ReadOnlyLongArrayBuffer extends LongArrayBuffer {
}
@Override
- public final LongBuffer put(long[] src, int off, int len) {
+ public final LongBuffer put(long[] src, int srcOffset, int longCount) {
throw new ReadOnlyBufferException();
}
@Override
public LongBuffer slice() {
- return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java b/luni/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
index cf9d370..07b9c90 100644
--- a/luni/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadOnlyShortArrayBuffer.java
@@ -32,9 +32,9 @@ package java.nio;
final class ReadOnlyShortArrayBuffer extends ShortArrayBuffer {
static ReadOnlyShortArrayBuffer copy(ShortArrayBuffer other, int markOfOther) {
- ReadOnlyShortArrayBuffer buf = new ReadOnlyShortArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadOnlyShortArrayBuffer buf =
+ new ReadOnlyShortArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -95,14 +95,13 @@ final class ReadOnlyShortArrayBuffer extends ShortArrayBuffer {
}
@Override
- public final ShortBuffer put(short[] src, int off, int len) {
+ public final ShortBuffer put(short[] src, int srcOffset, int shortCount) {
throw new ReadOnlyBufferException();
}
@Override
public ShortBuffer slice() {
- return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteCharArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
index 570efa4..df125b3 100644
--- a/luni/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteCharArrayBuffer.java
@@ -31,9 +31,9 @@ package java.nio;
final class ReadWriteCharArrayBuffer extends CharArrayBuffer {
static ReadWriteCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) {
- ReadWriteCharArrayBuffer buf = new ReadWriteCharArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadWriteCharArrayBuffer buf =
+ new ReadWriteCharArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -58,8 +58,7 @@ final class ReadWriteCharArrayBuffer extends CharArrayBuffer {
@Override
public CharBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -102,31 +101,24 @@ final class ReadWriteCharArrayBuffer extends CharArrayBuffer {
@Override
public CharBuffer put(int index, char c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public CharBuffer put(char[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) len + (long) off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public CharBuffer put(char[] src, int srcOffset, int charCount) {
+ if (charCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, charCount);
+ position += charCount;
return this;
}
@Override
public CharBuffer slice() {
- return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteDirectByteBuffer.java b/luni/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
index e720c8a..091d06d 100644
--- a/luni/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteDirectByteBuffer.java
@@ -17,9 +17,8 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.luni.platform.PlatformAddressFactory;
-// END android-added
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
@@ -33,41 +32,28 @@ import org.apache.harmony.luni.platform.PlatformAddressFactory;
* </p>
*/
final class ReadWriteDirectByteBuffer extends DirectByteBuffer {
-
static ReadWriteDirectByteBuffer copy(DirectByteBuffer other, int markOfOther) {
- ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
- other.safeAddress, other.capacity(), other.offset);
- buf.limit = other.limit();
+ ReadWriteDirectByteBuffer buf =
+ new ReadWriteDirectByteBuffer(other.block, other.capacity(), other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
- buf.order(other.order());
return buf;
}
+ // Used by ByteBuffer.allocateDirect.
ReadWriteDirectByteBuffer(int capacity) {
- super(capacity);
- }
-
- // BEGIN android-added
- ReadWriteDirectByteBuffer(int pointer, int capacity) {
- this(PlatformAddressFactory.on(pointer, capacity),capacity,0);
- }
- // END android-added
-
- ReadWriteDirectByteBuffer(SafeAddress address, int capacity, int offset) {
- super(address, capacity, offset);
+ super(MemoryBlock.allocate(capacity), capacity, 0);
}
- ReadWriteDirectByteBuffer(PlatformAddress address, int aCapacity,
- int anOffset) {
- super(new SafeAddress(address), aCapacity, anOffset);
+ // Used by the JNI NewDirectByteBuffer function.
+ ReadWriteDirectByteBuffer(int address, int capacity) {
+ super(MemoryBlock.wrapFromJni(address, capacity), capacity, 0);
}
- // BEGIN android-added
- int getAddress() {
- return this.safeAddress.address.toInt();
+ ReadWriteDirectByteBuffer(MemoryBlock block, int capacity, int offset) {
+ super(block, capacity, offset);
}
- // END android-added
@Override
public ByteBuffer asReadOnlyBuffer() {
@@ -76,8 +62,8 @@ final class ReadWriteDirectByteBuffer extends DirectByteBuffer {
@Override
public ByteBuffer compact() {
- PlatformAddress effectiveAddress = getEffectiveAddress();
- effectiveAddress.offsetBytes(position).moveTo(effectiveAddress, remaining());
+ int addr = effectiveDirectAddress;
+ OSMemory.memmove(addr, addr + position, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -99,268 +85,172 @@ final class ReadWriteDirectByteBuffer extends DirectByteBuffer {
if (position == limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setByte(offset + position++, value);
+ this.block.pokeByte(offset + position++, value);
return this;
}
@Override
public ByteBuffer put(int index, byte value) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setByte(offset + index, value);
+ checkIndex(index);
+ this.block.pokeByte(offset + index, value);
return this;
}
- /*
- * Override ByteBuffer.put(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#put(byte[], int, int)
- */
@Override
- public ByteBuffer put(byte[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- getBaseAddress().setByteArray(offset + position, src, off, len);
- position += len;
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
+ checkPutBounds(1, src.length, srcOffset, byteCount);
+ this.block.pokeByteArray(offset + position, src, srcOffset, byteCount);
+ position += byteCount;
return this;
}
- // BEGIN android-added
- /**
- * Writes <code>short</code>s in the given short array, starting from the
- * specified offset, to the current position and increase the position by
- * the number of <code>short</code>s written.
- *
- * @param src
- * The source short array
- * @param off
- * The offset of short array, must be no less than zero and no
- * greater than <code>src.length</code>
- * @param len
- * The number of <code>short</code>s to write, must be no less
- * than zero and no greater than <code>src.length - off</code>
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>remaining()</code> is less than
- * <code>len</code>
- * @exception IndexOutOfBoundsException
- * If either <code>off</code> or <code>len</code> is
- * invalid
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- ByteBuffer put(short[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len << 1 > remaining()) {
- throw new BufferOverflowException();
- }
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- boolean swap = order() != ByteOrder.nativeOrder();
- getBaseAddress().setShortArray(offset + position, src, off, len, swap);
- position += len << 1;
- return this;
+ final void put(char[] src, int srcOffset, int charCount) {
+ int byteCount = checkPutBounds(SizeOf.CHAR, src.length, srcOffset, charCount);
+ this.block.pokeCharArray(offset + position, src, srcOffset, charCount, order.needsSwap);
+ position += byteCount;
}
- /**
- * Writes <code>int</code>s in the given int array, starting from the
- * specified offset, to the current position and increase the position by
- * the number of <code>int</code>s written.
- *
- * @param src
- * The source int array
- * @param off
- * The offset of int array, must be no less than zero and no
- * greater than <code>src.length</code>
- * @param len
- * The number of <code>int</code>s to write, must be no less
- * than zero and no greater than <code>src.length - off</code>
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>remaining()</code> is less than
- * <code>len</code>
- * @exception IndexOutOfBoundsException
- * If either <code>off</code> or <code>len</code> is
- * invalid
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- ByteBuffer put(int[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len << 2 > remaining()) {
+ final void put(double[] src, int srcOffset, int doubleCount) {
+ int byteCount = checkPutBounds(SizeOf.DOUBLE, src.length, srcOffset, doubleCount);
+ this.block.pokeDoubleArray(offset + position, src, srcOffset, doubleCount, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(float[] src, int srcOffset, int floatCount) {
+ int byteCount = checkPutBounds(SizeOf.FLOAT, src.length, srcOffset, floatCount);
+ this.block.pokeFloatArray(offset + position, src, srcOffset, floatCount, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(int[] src, int srcOffset, int intCount) {
+ int byteCount = checkPutBounds(SizeOf.INT, src.length, srcOffset, intCount);
+ this.block.pokeIntArray(offset + position, src, srcOffset, intCount, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(long[] src, int srcOffset, int longCount) {
+ int byteCount = checkPutBounds(SizeOf.LONG, src.length, srcOffset, longCount);
+ this.block.pokeLongArray(offset + position, src, srcOffset, longCount, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(short[] src, int srcOffset, int shortCount) {
+ int byteCount = checkPutBounds(SizeOf.SHORT, src.length, srcOffset, shortCount);
+ this.block.pokeShortArray(offset + position, src, srcOffset, shortCount, order.needsSwap);
+ position += byteCount;
+ }
+
+ @Override
+ public ByteBuffer putChar(char value) {
+ int newPosition = position + SizeOf.CHAR;
+ if (newPosition > limit) {
throw new BufferOverflowException();
}
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- boolean swap = order() != ByteOrder.nativeOrder();
- getBaseAddress().setIntArray(offset + position, src, off, len, swap);
- position += len << 2;
+ this.block.pokeShort(offset + position, (short) value, order);
+ position = newPosition;
return this;
}
- /**
- * Writes <code>float</code>s in the given float array, starting from the
- * specified offset, to the current position and increase the position by
- * the number of <code>float</code>s written.
- *
- * @param src
- * The source float array
- * @param off
- * The offset of float array, must be no less than zero and no
- * greater than <code>src.length</code>
- * @param len
- * The number of <code>float</code>s to write, must be no less
- * than zero and no greater than <code>src.length - off</code>
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>remaining()</code> is less than
- * <code>len</code>
- * @exception IndexOutOfBoundsException
- * If either <code>off</code> or <code>len</code> is
- * invalid
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- ByteBuffer put(float[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len << 2 > remaining()) {
- throw new BufferOverflowException();
- }
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- boolean swap = order() != ByteOrder.nativeOrder();
- getBaseAddress().setFloatArray(offset + position, src, off, len, swap);
- position += len << 2;
+ @Override
+ public ByteBuffer putChar(int index, char value) {
+ checkIndex(index, SizeOf.CHAR);
+ this.block.pokeShort(offset + index, (short) value, order);
return this;
}
- // END android-added
@Override
public ByteBuffer putDouble(double value) {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.DOUBLE;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setDouble(offset + position, value, order);
+ this.block.pokeLong(offset + position, Double.doubleToRawLongBits(value), order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putDouble(int index, double value) {
- if (index < 0 || (long) index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setDouble(offset + index, value, order);
+ checkIndex(index, SizeOf.DOUBLE);
+ this.block.pokeLong(offset + index, Double.doubleToRawLongBits(value), order);
return this;
}
@Override
public ByteBuffer putFloat(float value) {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.FLOAT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setFloat(offset + position, value, order);
+ this.block.pokeInt(offset + position, Float.floatToRawIntBits(value), order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putFloat(int index, float value) {
- if (index < 0 || (long) index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setFloat(offset + index, value, order);
+ checkIndex(index, SizeOf.FLOAT);
+ this.block.pokeInt(offset + index, Float.floatToRawIntBits(value), order);
return this;
}
@Override
public ByteBuffer putInt(int value) {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.INT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setInt(offset + position, value, order);
+ this.block.pokeInt(offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putInt(int index, int value) {
- if (index < 0 || (long) index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setInt(offset + index, value, order);
+ checkIndex(index, SizeOf.INT);
+ this.block.pokeInt(offset + index, value, order);
return this;
}
@Override
public ByteBuffer putLong(long value) {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.LONG;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setLong(offset + position, value, order);
+ this.block.pokeLong(offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putLong(int index, long value) {
- if (index < 0 || (long) index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setLong(offset + index, value, order);
+ checkIndex(index, SizeOf.LONG);
+ this.block.pokeLong(offset + index, value, order);
return this;
}
@Override
public ByteBuffer putShort(short value) {
- int newPosition = position + 2;
+ int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- getBaseAddress().setShort(offset + position, value, order);
+ this.block.pokeShort(offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putShort(int index, short value) {
- if (index < 0 || (long) index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- getBaseAddress().setShort(offset + index, value, order);
+ checkIndex(index, SizeOf.SHORT);
+ this.block.pokeShort(offset + index, value, order);
return this;
}
@Override
public ByteBuffer slice() {
- ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
- safeAddress, remaining(), offset + position);
- buf.order = order;
- return buf;
+ return new ReadWriteDirectByteBuffer(block, remaining(), offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
index c7d4d94..a2913ae 100644
--- a/luni/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteDoubleArrayBuffer.java
@@ -31,11 +31,10 @@ package java.nio;
*/
final class ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer {
- static ReadWriteDoubleArrayBuffer copy(DoubleArrayBuffer other,
- int markOfOther) {
- ReadWriteDoubleArrayBuffer buf = new ReadWriteDoubleArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ static ReadWriteDoubleArrayBuffer copy(DoubleArrayBuffer other, int markOfOther) {
+ ReadWriteDoubleArrayBuffer buf =
+ new ReadWriteDoubleArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -49,8 +48,7 @@ final class ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer {
super(capacity);
}
- ReadWriteDoubleArrayBuffer(int capacity, double[] backingArray,
- int arrayOffset) {
+ ReadWriteDoubleArrayBuffer(int capacity, double[] backingArray, int arrayOffset) {
super(capacity, backingArray, arrayOffset);
}
@@ -61,8 +59,7 @@ final class ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer {
@Override
public DoubleBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -105,31 +102,24 @@ final class ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer {
@Override
public DoubleBuffer put(int index, double c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public DoubleBuffer put(double[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public DoubleBuffer put(double[] src, int srcOffset, int doubleCount) {
+ if (doubleCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, doubleCount);
+ position += doubleCount;
return this;
}
@Override
public DoubleBuffer slice() {
- return new ReadWriteDoubleArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteDoubleArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteFileChannel.java b/luni/src/main/java/java/nio/ReadWriteFileChannel.java
new file mode 100644
index 0000000..a458a6c
--- /dev/null
+++ b/luni/src/main/java/java/nio/ReadWriteFileChannel.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.IOException;
+
+final class ReadWriteFileChannel extends FileChannelImpl {
+ public ReadWriteFileChannel(Object stream, int handle) {
+ super(stream, handle);
+ }
+
+ public final MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
+ openCheck();
+ if (mode == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException();
+ }
+ return mapImpl(mode, position, size);
+ }
+}
diff --git a/luni/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
index 838172f..da1e406 100644
--- a/luni/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteFloatArrayBuffer.java
@@ -31,11 +31,10 @@ package java.nio;
*/
final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
- static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other,
- int markOfOther) {
- ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other, int markOfOther) {
+ ReadWriteFloatArrayBuffer buf =
+ new ReadWriteFloatArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -49,8 +48,7 @@ final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
super(capacity);
}
- ReadWriteFloatArrayBuffer(int capacity, float[] backingArray,
- int arrayOffset) {
+ ReadWriteFloatArrayBuffer(int capacity, float[] backingArray, int arrayOffset) {
super(capacity, backingArray, arrayOffset);
}
@@ -61,8 +59,7 @@ final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
@Override
public FloatBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -105,31 +102,24 @@ final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
@Override
public FloatBuffer put(int index, float c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public FloatBuffer put(float[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public FloatBuffer put(float[] src, int srcOffset, int floatCount) {
+ if (floatCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, floatCount);
+ position += floatCount;
return this;
}
@Override
public FloatBuffer slice() {
- return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteHeapByteBuffer.java b/luni/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
index cbf41b8..81cac26 100644
--- a/luni/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteHeapByteBuffer.java
@@ -16,6 +16,9 @@
package java.nio;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
+
/**
* HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
* the implementation of array based byte buffers.
@@ -30,12 +33,11 @@ package java.nio;
final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
static ReadWriteHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
- ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer(
- other.backingArray, other.capacity(), other.offset);
- buf.limit = other.limit();
+ ReadWriteHeapByteBuffer buf =
+ new ReadWriteHeapByteBuffer(other.backingArray, other.capacity(), other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
- buf.order(other.order());
return buf;
}
@@ -58,8 +60,7 @@ final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
@Override
public ByteBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -102,33 +103,70 @@ final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
@Override
public ByteBuffer put(int index, byte b) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = b;
return this;
}
- /*
- * Override ByteBuffer.put(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#put(byte[], int, int)
- */
@Override
- public ByteBuffer put(byte[] src, int off, int len) {
- if (off < 0 || len < 0 || (long) off + (long) len > src.length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public ByteBuffer put(byte[] src, int srcOffset, int byteCount) {
+ checkPutBounds(1, src.length, srcOffset, byteCount);
+ System.arraycopy(src, srcOffset, backingArray, offset + position, byteCount);
+ position += byteCount;
+ return this;
+ }
+
+ final void put(char[] src, int srcOffset, int charCount) {
+ int byteCount = checkPutBounds(SizeOf.CHAR, src.length, srcOffset, charCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.CHAR, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(double[] src, int srcOffset, int doubleCount) {
+ int byteCount = checkPutBounds(SizeOf.DOUBLE, src.length, srcOffset, doubleCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.DOUBLE, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(float[] src, int srcOffset, int floatCount) {
+ int byteCount = checkPutBounds(SizeOf.FLOAT, src.length, srcOffset, floatCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.FLOAT, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(int[] src, int srcOffset, int intCount) {
+ int byteCount = checkPutBounds(SizeOf.INT, src.length, srcOffset, intCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.INT, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(long[] src, int srcOffset, int longCount) {
+ int byteCount = checkPutBounds(SizeOf.LONG, src.length, srcOffset, longCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.LONG, order.needsSwap);
+ position += byteCount;
+ }
+
+ final void put(short[] src, int srcOffset, int shortCount) {
+ int byteCount = checkPutBounds(SizeOf.SHORT, src.length, srcOffset, shortCount);
+ OSMemory.unsafeBulkPut(backingArray, offset + position, byteCount, src, srcOffset, SizeOf.SHORT, order.needsSwap);
+ position += byteCount;
+ }
+
+ @Override
+ public ByteBuffer putChar(int index, char value) {
+ checkIndex(index, SizeOf.CHAR);
+ OSMemory.pokeShort(backingArray, offset + index, (short) value, order);
+ return this;
+ }
+
+ @Override
+ public ByteBuffer putChar(char value) {
+ int newPosition = position + SizeOf.CHAR;
+ if (newPosition > limit) {
throw new BufferOverflowException();
}
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ OSMemory.pokeShort(backingArray, offset + position, (short) value, order);
+ position = newPosition;
return this;
}
@@ -144,79 +182,70 @@ final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
@Override
public ByteBuffer putFloat(float value) {
- return putInt(Float.floatToIntBits(value));
+ return putInt(Float.floatToRawIntBits(value));
}
@Override
public ByteBuffer putFloat(int index, float value) {
- return putInt(index, Float.floatToIntBits(value));
+ return putInt(index, Float.floatToRawIntBits(value));
}
@Override
public ByteBuffer putInt(int value) {
- int newPosition = position + 4;
+ int newPosition = position + SizeOf.INT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- store(position, value);
+ OSMemory.pokeInt(backingArray, offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putInt(int index, int value) {
- if (index < 0 || (long) index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
+ checkIndex(index, SizeOf.INT);
+ OSMemory.pokeInt(backingArray, offset + index, value, order);
return this;
}
@Override
public ByteBuffer putLong(int index, long value) {
- if (index < 0 || (long) index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
+ checkIndex(index, SizeOf.LONG);
+ OSMemory.pokeLong(backingArray, offset + index, value, order);
return this;
}
@Override
public ByteBuffer putLong(long value) {
- int newPosition = position + 8;
+ int newPosition = position + SizeOf.LONG;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- store(position, value);
+ OSMemory.pokeLong(backingArray, offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer putShort(int index, short value) {
- if (index < 0 || (long) index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
+ checkIndex(index, SizeOf.SHORT);
+ OSMemory.pokeShort(backingArray, offset + index, value, order);
return this;
}
@Override
public ByteBuffer putShort(short value) {
- int newPosition = position + 2;
+ int newPosition = position + SizeOf.SHORT;
if (newPosition > limit) {
throw new BufferOverflowException();
}
- store(position, value);
+ OSMemory.pokeShort(backingArray, offset + position, value, order);
position = newPosition;
return this;
}
@Override
public ByteBuffer slice() {
- ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer(
- backingArray, remaining(), offset + position);
- slice.order = order;
- return slice;
+ return new ReadWriteHeapByteBuffer(backingArray, remaining(), offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteIntArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
index 9aa74d7..8ec60c0 100644
--- a/luni/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteIntArrayBuffer.java
@@ -31,9 +31,9 @@ package java.nio;
final class ReadWriteIntArrayBuffer extends IntArrayBuffer {
static ReadWriteIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
- ReadWriteIntArrayBuffer buf = new ReadWriteIntArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadWriteIntArrayBuffer buf =
+ new ReadWriteIntArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -58,8 +58,7 @@ final class ReadWriteIntArrayBuffer extends IntArrayBuffer {
@Override
public IntBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -102,31 +101,24 @@ final class ReadWriteIntArrayBuffer extends IntArrayBuffer {
@Override
public IntBuffer put(int index, int c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public IntBuffer put(int[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public IntBuffer put(int[] src, int srcOffset, int intCount) {
+ if (intCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, intCount);
+ position += intCount;
return this;
}
@Override
public IntBuffer slice() {
- return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteLongArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
index 2a7e332..d02ec57 100644
--- a/luni/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteLongArrayBuffer.java
@@ -31,9 +31,9 @@ package java.nio;
final class ReadWriteLongArrayBuffer extends LongArrayBuffer {
static ReadWriteLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
- ReadWriteLongArrayBuffer buf = new ReadWriteLongArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ ReadWriteLongArrayBuffer buf =
+ new ReadWriteLongArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -58,8 +58,7 @@ final class ReadWriteLongArrayBuffer extends LongArrayBuffer {
@Override
public LongBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -102,31 +101,24 @@ final class ReadWriteLongArrayBuffer extends LongArrayBuffer {
@Override
public LongBuffer put(int index, long c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public LongBuffer put(long[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public LongBuffer put(long[] src, int srcOffset, int longCount) {
+ if (longCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, longCount);
+ position += longCount;
return this;
}
@Override
public LongBuffer slice() {
- return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/ReadWriteShortArrayBuffer.java b/luni/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
index f3b4220..6f16dae 100644
--- a/luni/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ReadWriteShortArrayBuffer.java
@@ -31,11 +31,10 @@ package java.nio;
*/
final class ReadWriteShortArrayBuffer extends ShortArrayBuffer {
- static ReadWriteShortArrayBuffer copy(ShortArrayBuffer other,
- int markOfOther) {
- ReadWriteShortArrayBuffer buf = new ReadWriteShortArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
+ static ReadWriteShortArrayBuffer copy(ShortArrayBuffer other, int markOfOther) {
+ ReadWriteShortArrayBuffer buf =
+ new ReadWriteShortArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit;
buf.position = other.position();
buf.mark = markOfOther;
return buf;
@@ -61,8 +60,7 @@ final class ReadWriteShortArrayBuffer extends ShortArrayBuffer {
@Override
public ShortBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
position = limit - position;
limit = capacity;
mark = UNSET_MARK;
@@ -105,31 +103,24 @@ final class ReadWriteShortArrayBuffer extends ShortArrayBuffer {
@Override
public ShortBuffer put(int index, short c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
backingArray[offset + index] = c;
return this;
}
@Override
- public ShortBuffer put(short[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public ShortBuffer put(short[] src, int srcOffset, int shortCount) {
+ if (shortCount > remaining()) {
throw new BufferOverflowException();
}
- System.arraycopy(src, off, backingArray, offset + position, len);
- position += len;
+ System.arraycopy(src, srcOffset, backingArray, offset + position, shortCount);
+ position += shortCount;
return this;
}
@Override
public ShortBuffer slice() {
- return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset
- + position);
+ return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset + position);
}
}
diff --git a/luni/src/main/java/java/nio/SelectionKeyImpl.java b/luni/src/main/java/java/nio/SelectionKeyImpl.java
new file mode 100644
index 0000000..694770e
--- /dev/null
+++ b/luni/src/main/java/java/nio/SelectionKeyImpl.java
@@ -0,0 +1,110 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.nio.channels.CancelledKeyException;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.AbstractSelectionKey;
+
+/**
+ * Default implementation of SelectionKey
+ */
+final class SelectionKeyImpl extends AbstractSelectionKey {
+
+ private AbstractSelectableChannel channel;
+
+ private int interestOps;
+
+ private int readyOps;
+
+ private SelectorImpl selector;
+
+ public SelectionKeyImpl(AbstractSelectableChannel channel, int operations,
+ Object attachment, SelectorImpl selector) {
+ this.channel = channel;
+ interestOps = operations;
+ this.selector = selector;
+ attach(attachment);
+ }
+
+ @Override
+ public SelectableChannel channel() {
+ return channel;
+ }
+
+ @Override
+ public int interestOps() {
+ checkValid();
+ synchronized (selector.keysLock) {
+ return interestOps;
+ }
+ }
+
+ int interestOpsNoCheck() {
+ synchronized (selector.keysLock) {
+ return interestOps;
+ }
+ }
+
+ @Override
+ public SelectionKey interestOps(int operations) {
+ checkValid();
+ if ((operations & ~(channel().validOps())) != 0) {
+ throw new IllegalArgumentException();
+ }
+ synchronized (selector.keysLock) {
+ interestOps = operations;
+ }
+ return this;
+ }
+
+ @Override
+ public int readyOps() {
+ checkValid();
+ return readyOps;
+ }
+
+ @Override
+ public Selector selector() {
+ return selector;
+ }
+
+ /*
+ * package private method for setting the ready operation by selector
+ */
+ void setReadyOps(int readyOps) {
+ this.readyOps = readyOps;
+ }
+
+ private void checkValid() {
+ if (!isValid()) {
+ throw new CancelledKeyException();
+ }
+ }
+
+ /**
+ * Returns true if the channel for this key is connected. If the channel
+ * does not need connecting, this always return true.
+ */
+ boolean isConnected() {
+ return !(channel instanceof SocketChannel) || ((SocketChannel) channel).isConnected();
+ }
+}
diff --git a/luni/src/main/java/java/nio/SelectorImpl.java b/luni/src/main/java/java/nio/SelectorImpl.java
new file mode 100644
index 0000000..733bb34
--- /dev/null
+++ b/luni/src/main/java/java/nio/SelectorImpl.java
@@ -0,0 +1,451 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package java.nio;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.nio.channels.ClosedSelectorException;
+import java.nio.channels.IllegalSelectorException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.SelectionKey;
+import static java.nio.channels.SelectionKey.*;
+import java.nio.channels.Selector;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.AbstractSelectionKey;
+import java.nio.channels.spi.AbstractSelector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import libcore.base.EmptyArray;
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+import org.apache.harmony.luni.platform.Platform;
+
+/*
+ * Default implementation of java.nio.channels.Selector
+ */
+final class SelectorImpl extends AbstractSelector {
+
+ static final FileDescriptor[] EMPTY_FILE_DESCRIPTORS_ARRAY = new FileDescriptor[0];
+
+ private static final SelectionKeyImpl[] EMPTY_SELECTION_KEY_IMPLS_ARRAY
+ = new SelectionKeyImpl[0];
+
+ private static final int CONNECT_OR_WRITE = OP_CONNECT | OP_WRITE;
+
+ private static final int ACCEPT_OR_READ = OP_ACCEPT | OP_READ;
+
+ private static final int WAKEUP_WRITE_SIZE = 1;
+
+ private static final int WAKEUP_READ_SIZE = 8;
+
+ private static final int NA = 0;
+
+ private static final int READABLE = 1;
+
+ private static final int WRITABLE = 2;
+
+ private static final int SELECT_BLOCK = -1;
+
+ private static final int SELECT_NOW = 0;
+
+ /**
+ * Used to synchronize when a key's interest ops change.
+ */
+ final Object keysLock = new Object();
+
+ private final Set<SelectionKeyImpl> mutableKeys = new HashSet<SelectionKeyImpl>();
+
+ /**
+ * The unmodifiable set of keys as exposed to the user. This object is used
+ * for synchronization.
+ */
+ private final Set<SelectionKey> unmodifiableKeys = Collections
+ .<SelectionKey>unmodifiableSet(mutableKeys);
+
+ private final Set<SelectionKey> mutableSelectedKeys = new HashSet<SelectionKey>();
+
+ /**
+ * The unmodifiable set of selectable keys as seen by the user. This object
+ * is used for synchronization.
+ */
+ private final Set<SelectionKey> selectedKeys
+ = new UnaddableSet<SelectionKey>(mutableSelectedKeys);
+
+ /**
+ * The pipe used to implement wakeup.
+ */
+ private final Pipe wakeupPipe;
+
+ /**
+ * File descriptors we're interested in reading from. When actively
+ * selecting, the first element is always the wakeup channel's file
+ * descriptor, and the other elements are user-specified file descriptors.
+ * Otherwise, all elements are null.
+ */
+ private FileDescriptor[] readableFDs = EMPTY_FILE_DESCRIPTORS_ARRAY;
+
+ /**
+ * File descriptors we're interested in writing from. May be empty. When not
+ * actively selecting, all elements are null.
+ */
+ private FileDescriptor[] writableFDs = EMPTY_FILE_DESCRIPTORS_ARRAY;
+
+ /**
+ * Selection keys that correspond to the concatenation of readableFDs and
+ * writableFDs. This is used to interpret the results returned by select().
+ * When not actively selecting, all elements are null.
+ */
+ private SelectionKeyImpl[] readyKeys = EMPTY_SELECTION_KEY_IMPLS_ARRAY;
+
+ /**
+ * Selection flags that define the ready ops on the ready keys. When not
+ * actively selecting, all elements are 0. Corresponds to the ready keys
+ * set.
+ */
+ private int[] flags = EmptyArray.INT;
+
+ public SelectorImpl(SelectorProvider selectorProvider) throws IOException {
+ super(selectorProvider);
+ wakeupPipe = selectorProvider.openPipe();
+ wakeupPipe.source().configureBlocking(false);
+ }
+
+ @Override protected void implCloseSelector() throws IOException {
+ wakeup();
+ synchronized (this) {
+ synchronized (unmodifiableKeys) {
+ synchronized (selectedKeys) {
+ wakeupPipe.sink().close();
+ wakeupPipe.source().close();
+ doCancel();
+ for (SelectionKey sk : mutableKeys) {
+ deregister((AbstractSelectionKey) sk);
+ }
+ }
+ }
+ }
+ }
+
+ @Override protected SelectionKey register(AbstractSelectableChannel channel,
+ int operations, Object attachment) {
+ if (!provider().equals(channel.provider())) {
+ throw new IllegalSelectorException();
+ }
+ synchronized (this) {
+ synchronized (unmodifiableKeys) {
+ SelectionKeyImpl selectionKey = new SelectionKeyImpl(
+ channel, operations, attachment, this);
+ mutableKeys.add(selectionKey);
+ return selectionKey;
+ }
+ }
+ }
+
+ @Override public synchronized Set<SelectionKey> keys() {
+ closeCheck();
+ return unmodifiableKeys;
+ }
+
+ /*
+ * Checks that the receiver is not closed. If it is throws an exception.
+ */
+ private void closeCheck() {
+ if (!isOpen()) {
+ throw new ClosedSelectorException();
+ }
+ }
+
+ @Override public int select() throws IOException {
+ return selectInternal(SELECT_BLOCK);
+ }
+
+ @Override public int select(long timeout) throws IOException {
+ if (timeout < 0) {
+ throw new IllegalArgumentException();
+ }
+ return selectInternal((timeout == 0) ? SELECT_BLOCK : timeout);
+ }
+
+ @Override public int selectNow() throws IOException {
+ return selectInternal(SELECT_NOW);
+ }
+
+ private int selectInternal(long timeout) throws IOException {
+ closeCheck();
+ synchronized (this) {
+ synchronized (unmodifiableKeys) {
+ synchronized (selectedKeys) {
+ doCancel();
+ boolean isBlock = (SELECT_NOW != timeout);
+ int readableKeysCount = 1; // first is always the wakeup channel
+ int writableKeysCount = 0;
+ synchronized (keysLock) {
+ for (SelectionKeyImpl key : mutableKeys) {
+ int ops = key.interestOpsNoCheck();
+ if ((ACCEPT_OR_READ & ops) != 0) {
+ readableKeysCount++;
+ }
+ if ((CONNECT_OR_WRITE & ops) != 0) {
+ writableKeysCount++;
+ }
+ }
+ prepareChannels(readableKeysCount, writableKeysCount);
+ }
+ boolean success;
+ try {
+ if (isBlock) {
+ begin();
+ }
+ success = Platform.NETWORK.select(readableFDs, writableFDs,
+ readableKeysCount, writableKeysCount, timeout, flags);
+ } finally {
+ if (isBlock) {
+ end();
+ }
+ }
+
+ int selected = success ? processSelectResult() : 0;
+
+ Arrays.fill(readableFDs, null);
+ Arrays.fill(writableFDs, null);
+ Arrays.fill(readyKeys, null);
+ Arrays.fill(flags, 0);
+
+ selected -= doCancel();
+
+ return selected;
+ }
+ }
+ }
+ }
+
+ private int getReadyOps(SelectionKeyImpl key) {
+ SelectableChannel channel = key.channel();
+ return ((channel instanceof SocketChannel) && !((SocketChannel) channel).isConnectionPending()) ?
+ OP_WRITE : CONNECT_OR_WRITE;
+ }
+
+ /**
+ * Prepare the readableFDs, writableFDs, readyKeys and flags arrays in
+ * preparation for a call to {@code INetworkSystem#select()}. After they're
+ * used, the array elements must be cleared.
+ */
+ private void prepareChannels(int numReadable, int numWritable) {
+ // grow each array to sufficient capacity. Always grow to at least 1.5x
+ // to avoid growing too frequently
+ if (readableFDs.length < numReadable) {
+ int newSize = Math.max((int) (readableFDs.length * 1.5f), numReadable);
+ readableFDs = new FileDescriptor[newSize];
+ }
+ if (writableFDs.length < numWritable) {
+ int newSize = Math.max((int) (writableFDs.length * 1.5f), numWritable);
+ writableFDs = new FileDescriptor[newSize];
+ }
+ int total = numReadable + numWritable;
+ if (readyKeys.length < total) {
+ int newSize = Math.max((int) (readyKeys.length * 1.5f), total);
+ readyKeys = new SelectionKeyImpl[newSize];
+ flags = new int[newSize];
+ }
+
+ // populate the FDs, including the wakeup channel
+ readableFDs[0] = ((FileDescriptorHandler) wakeupPipe.source()).getFD();
+ int r = 1;
+ int w = 0;
+ for (SelectionKeyImpl key : mutableKeys) {
+ int interestOps = key.interestOpsNoCheck();
+ if ((ACCEPT_OR_READ & interestOps) != 0) {
+ readableFDs[r] = ((FileDescriptorHandler) key.channel()).getFD();
+ readyKeys[r] = key;
+ r++;
+ }
+ if ((getReadyOps(key) & interestOps) != 0) {
+ writableFDs[w] = ((FileDescriptorHandler) key.channel()).getFD();
+ readyKeys[w + numReadable] = key;
+ w++;
+ }
+ }
+ }
+
+ /**
+ * Updates the key ready ops and selected key set with data from the flags
+ * array.
+ */
+ private int processSelectResult() throws IOException {
+ // If there's something in the wakeup pipe, read it all --- the definition of the various
+ // select methods says that one select swallows all outstanding wakeups. We made this
+ // channel non-blocking in our constructor so that we can just loop until read returns 0.
+ if (flags[0] == READABLE) {
+ ByteBuffer buf = ByteBuffer.allocate(WAKEUP_READ_SIZE);
+ while (wakeupPipe.source().read(buf) > 0) {
+ buf.flip();
+ }
+ }
+
+ int selected = 0;
+ for (int i = 1; i < flags.length; i++) {
+ if (flags[i] == NA) {
+ continue;
+ }
+
+ SelectionKeyImpl key = readyKeys[i];
+ int ops = key.interestOpsNoCheck();
+ int selectedOp = 0;
+
+ switch (flags[i]) {
+ case READABLE:
+ selectedOp = ACCEPT_OR_READ & ops;
+ break;
+ case WRITABLE:
+ if (key.isConnected()) {
+ selectedOp = OP_WRITE & ops;
+ } else {
+ selectedOp = OP_CONNECT & ops;
+ }
+ break;
+ }
+
+ if (selectedOp != 0) {
+ boolean wasSelected = mutableSelectedKeys.contains(key);
+ if (wasSelected && key.readyOps() != selectedOp) {
+ key.setReadyOps(key.readyOps() | selectedOp);
+ selected++;
+ } else if (!wasSelected) {
+ key.setReadyOps(selectedOp);
+ mutableSelectedKeys.add(key);
+ selected++;
+ }
+ }
+ }
+
+ return selected;
+ }
+
+ @Override public synchronized Set<SelectionKey> selectedKeys() {
+ closeCheck();
+ return selectedKeys;
+ }
+
+ /**
+ * Removes cancelled keys from the key set and selected key set, and
+ * deregisters the corresponding channels. Returns the number of keys
+ * removed from the selected key set.
+ */
+ private int doCancel() {
+ int deselected = 0;
+
+ Set<SelectionKey> cancelledKeys = cancelledKeys();
+ synchronized (cancelledKeys) {
+ if (cancelledKeys.size() > 0) {
+ for (SelectionKey currentKey : cancelledKeys) {
+ mutableKeys.remove(currentKey);
+ deregister((AbstractSelectionKey) currentKey);
+ if (mutableSelectedKeys.remove(currentKey)) {
+ deselected++;
+ }
+ }
+ cancelledKeys.clear();
+ }
+ }
+
+ return deselected;
+ }
+
+ @Override public Selector wakeup() {
+ try {
+ wakeupPipe.sink().write(ByteBuffer.allocate(WAKEUP_WRITE_SIZE));
+ } catch (IOException ignored) {
+ }
+ return this;
+ }
+
+ private static class UnaddableSet<E> implements Set<E> {
+
+ private final Set<E> set;
+
+ UnaddableSet(Set<E> set) {
+ this.set = set;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ return set.equals(object);
+ }
+
+ @Override
+ public int hashCode() {
+ return set.hashCode();
+ }
+
+ public boolean add(E object) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection<? extends E> c) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear() {
+ set.clear();
+ }
+
+ public boolean contains(Object object) {
+ return set.contains(object);
+ }
+
+ public boolean containsAll(Collection<?> c) {
+ return set.containsAll(c);
+ }
+
+ public boolean isEmpty() {
+ return set.isEmpty();
+ }
+
+ public Iterator<E> iterator() {
+ return set.iterator();
+ }
+
+ public boolean remove(Object object) {
+ return set.remove(object);
+ }
+
+ public boolean removeAll(Collection<?> c) {
+ return set.removeAll(c);
+ }
+
+ public boolean retainAll(Collection<?> c) {
+ return set.retainAll(c);
+ }
+
+ public int size() {
+ return set.size();
+ }
+
+ public Object[] toArray() {
+ return set.toArray();
+ }
+
+ public <T> T[] toArray(T[] a) {
+ return set.toArray(a);
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/SelectorProviderImpl.java b/luni/src/main/java/java/nio/SelectorProviderImpl.java
new file mode 100644
index 0000000..03003fe
--- /dev/null
+++ b/luni/src/main/java/java/nio/SelectorProviderImpl.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.IOException;
+import java.nio.channels.DatagramChannel;
+import java.nio.channels.Pipe;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelector;
+import java.nio.channels.spi.SelectorProvider;
+
+/**
+ * @hide for java.nio.channels.spi.SelectorProvider only.
+ */
+public final class SelectorProviderImpl extends SelectorProvider {
+ public DatagramChannel openDatagramChannel() throws IOException {
+ return new DatagramChannelImpl(this);
+ }
+
+ public Pipe openPipe() throws IOException {
+ return new PipeImpl();
+ }
+
+ public AbstractSelector openSelector() throws IOException {
+ return new SelectorImpl(this);
+ }
+
+ public ServerSocketChannel openServerSocketChannel() throws IOException {
+ return new ServerSocketChannelImpl(this);
+ }
+
+ public SocketChannel openSocketChannel() throws IOException {
+ return new SocketChannelImpl(this);
+ }
+}
diff --git a/luni/src/main/java/java/nio/ServerSocketChannelImpl.java b/luni/src/main/java/java/nio/ServerSocketChannelImpl.java
new file mode 100644
index 0000000..9cefe5f
--- /dev/null
+++ b/luni/src/main/java/java/nio/ServerSocketChannelImpl.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketImpl;
+import java.net.SocketTimeoutException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.NotYetBoundException;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.SelectorProvider;
+import org.apache.harmony.luni.net.PlainServerSocketImpl;
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+import org.apache.harmony.luni.platform.Platform;
+
+/**
+ * The default ServerSocketChannel.
+ */
+final class ServerSocketChannelImpl extends ServerSocketChannel implements FileDescriptorHandler {
+
+ private final FileDescriptor fd = new FileDescriptor();
+ private final SocketImpl impl = new PlainServerSocketImpl(fd);
+ private final ServerSocketAdapter socket = new ServerSocketAdapter(impl, this);
+
+ private boolean isBound = false;
+
+ private final Object acceptLock = new Object();
+
+ public ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
+ super(sp);
+ }
+
+ // for native call
+ @SuppressWarnings("unused")
+ private ServerSocketChannelImpl() throws IOException {
+ this(SelectorProvider.provider());
+ }
+
+ @Override public ServerSocket socket() {
+ return socket;
+ }
+
+ @Override public SocketChannel accept() throws IOException {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (!isBound) {
+ throw new NotYetBoundException();
+ }
+
+ // TODO: pass in the SelectorProvider used to create this ServerSocketChannelImpl?
+ // Create an empty socket channel. This will be populated by ServerSocketAdapter.accept.
+ SocketChannelImpl result = new SocketChannelImpl(SelectorProvider.provider(), false);
+ Socket resultSocket = result.socket();
+
+ try {
+ begin();
+ synchronized (acceptLock) {
+ synchronized (blockingLock()) {
+ boolean isBlocking = isBlocking();
+ if (!isBlocking) {
+ int[] tryResult = new int[1];
+ boolean success = Platform.NETWORK.select(new FileDescriptor[] { fd },
+ SelectorImpl.EMPTY_FILE_DESCRIPTORS_ARRAY, 1, 0, 0, tryResult);
+ if (!success || tryResult[0] == 0) {
+ // no pending connections, returns immediately.
+ return null;
+ }
+ }
+ // do accept.
+ do {
+ try {
+ socket.accept(resultSocket, result);
+ // select successfully, break out immediately.
+ break;
+ } catch (SocketTimeoutException e) {
+ // continue to accept if the channel is in blocking mode.
+ }
+ } while (isBlocking);
+ }
+ }
+ } finally {
+ end(resultSocket.isConnected());
+ }
+ return result;
+ }
+
+ protected void implConfigureBlocking(boolean blockingMode) throws IOException {
+ // Do nothing here. For real accept() operation in non-blocking mode,
+ // it uses INetworkSystem.select. Whether a channel is blocking can be
+ // decided by isBlocking() method.
+ }
+
+ synchronized protected void implCloseSelectableChannel() throws IOException {
+ if (!socket.isClosed()) {
+ socket.close();
+ }
+ }
+
+ public FileDescriptor getFD() {
+ return fd;
+ }
+
+ private static class ServerSocketAdapter extends ServerSocket {
+ private final ServerSocketChannelImpl channelImpl;
+
+ ServerSocketAdapter(SocketImpl impl, ServerSocketChannelImpl aChannelImpl) {
+ super(impl);
+ this.channelImpl = aChannelImpl;
+ }
+
+ @Override public void bind(SocketAddress localAddress, int backlog) throws IOException {
+ super.bind(localAddress, backlog);
+ channelImpl.isBound = true;
+ }
+
+ @Override public Socket accept() throws IOException {
+ if (!channelImpl.isBound) {
+ throw new IllegalBlockingModeException();
+ }
+ SocketChannel sc = channelImpl.accept();
+ if (sc == null) {
+ throw new IllegalBlockingModeException();
+ }
+ return sc.socket();
+ }
+
+ private Socket accept(Socket socket, SocketChannelImpl sockChannel) throws IOException {
+ boolean connectOK = false;
+ try {
+ synchronized (this) {
+ super.implAccept(socket);
+ sockChannel.setConnected();
+ sockChannel.setBound(true);
+ sockChannel.finishAccept();
+ }
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkAccept(socket.getInetAddress().getHostAddress(), socket.getPort());
+ }
+ connectOK = true;
+ } finally {
+ if (!connectOK) {
+ socket.close();
+ }
+ }
+ return socket;
+ }
+
+ @Override public ServerSocketChannel getChannel() {
+ return channelImpl;
+ }
+
+ @Override public boolean isBound() {
+ return channelImpl.isBound;
+ }
+
+ @Override public void bind(SocketAddress localAddress) throws IOException {
+ super.bind(localAddress);
+ channelImpl.isBound = true;
+ }
+
+ @Override public void close() throws IOException {
+ synchronized (channelImpl) {
+ if (channelImpl.isOpen()) {
+ channelImpl.close();
+ } else {
+ super.close();
+ }
+ }
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/ShortArrayBuffer.java b/luni/src/main/java/java/nio/ShortArrayBuffer.java
index e6d96ed..bf6f752 100644
--- a/luni/src/main/java/java/nio/ShortArrayBuffer.java
+++ b/luni/src/main/java/java/nio/ShortArrayBuffer.java
@@ -59,23 +59,17 @@ abstract class ShortArrayBuffer extends ShortBuffer {
@Override
public final short get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
+ checkIndex(index);
return backingArray[offset + index];
}
@Override
- public final ShortBuffer get(short[] dst, int off, int len) {
- int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ public final ShortBuffer get(short[] dst, int dstOffset, int shortCount) {
+ if (shortCount > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset + position, dst, off, len);
- position += len;
+ System.arraycopy(backingArray, offset + position, dst, dstOffset, shortCount);
+ position += shortCount;
return this;
}
diff --git a/luni/src/main/java/java/nio/ShortBuffer.java b/luni/src/main/java/java/nio/ShortBuffer.java
index c0fd0e7..1f70ff9 100644
--- a/luni/src/main/java/java/nio/ShortBuffer.java
+++ b/luni/src/main/java/java/nio/ShortBuffer.java
@@ -17,6 +17,8 @@
package java.nio;
+import java.util.Arrays;
+
/**
* A buffer of shorts.
* <p>
@@ -46,7 +48,7 @@ public abstract class ShortBuffer extends Buffer implements
if (capacity < 0) {
throw new IllegalArgumentException();
}
- return BufferFactory.newShortBuffer(capacity);
+ return new ReadWriteShortArrayBuffer(capacity);
}
/**
@@ -67,44 +69,30 @@ public abstract class ShortBuffer extends Buffer implements
* Creates a new short buffer by wrapping the given short array.
* <p>
* The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
+ * {@code start + shortCount}, capacity will be the length of the array.
*
* @param array
* the short array which the new buffer will be based on.
* @param start
* the start index, must not be negative and not greater than
* {@code array.length}.
- * @param len
+ * @param shortCount
* the length, must not be negative and not greater than
* {@code array.length - start}.
* @return the created short buffer.
* @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
+ * if either {@code start} or {@code shortCount} is invalid.
*/
- public static ShortBuffer wrap(short[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long) start + (long) len > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- ShortBuffer buf = BufferFactory.newShortBuffer(array);
+ public static ShortBuffer wrap(short[] array, int start, int shortCount) {
+ Arrays.checkOffsetAndCount(array.length, start, shortCount);
+ ShortBuffer buf = new ReadWriteShortArrayBuffer(array);
buf.position = start;
- buf.limit = start + len;
-
+ buf.limit = start + shortCount;
return buf;
}
- /**
- * Constructs a {@code ShortBuffer} with given capacity.
- *
- * @param capacity
- * The capacity of the buffer
- */
ShortBuffer(int capacity) {
- super(capacity);
- _elementSizeShift = 1;
+ super(1, capacity, null);
}
public final short[] array() {
@@ -256,27 +244,25 @@ public abstract class ShortBuffer extends Buffer implements
*
* @param dst
* the target short array.
- * @param off
+ * @param dstOffset
* the offset of the short array, must not be negative and not
* greater than {@code dst.length}.
- * @param len
+ * @param shortCount
* the number of shorts to read, must be no less than zero and
- * not greater than {@code dst.length - off}.
+ * not greater than {@code dst.length - dstOffset}.
* @return this buffer.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code dstOffset} or {@code shortCount} is invalid.
* @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
+ * if {@code shortCount} is greater than {@code remaining()}.
*/
- public ShortBuffer get(short[] dst, int off, int len) {
+ public ShortBuffer get(short[] dst, int dstOffset, int shortCount) {
int length = dst.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
+ Arrays.checkOffsetAndCount(dst.length, dstOffset, shortCount);
+ if (shortCount > remaining()) {
throw new BufferUnderflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = dstOffset; i < dstOffset + shortCount; ++i) {
dst[i] = get();
}
return this;
@@ -398,30 +384,27 @@ public abstract class ShortBuffer extends Buffer implements
*
* @param src
* the source short array.
- * @param off
+ * @param srcOffset
* the offset of short array, must not be negative and not
* greater than {@code src.length}.
- * @param len
+ * @param shortCount
* the number of shorts to write, must be no less than zero and
- * not greater than {@code src.length - off}.
+ * not greater than {@code src.length - srcOffset}.
* @return this buffer.
* @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
+ * if {@code remaining()} is less than {@code shortCount}.
* @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
+ * if either {@code srcOffset} or {@code shortCount} is invalid.
* @exception ReadOnlyBufferException
* if no changes may be made to the contents of this buffer.
*/
- public ShortBuffer put(short[] src, int off, int len) {
+ public ShortBuffer put(short[] src, int srcOffset, int shortCount) {
int length = src.length;
- if (off < 0 || len < 0 || (long) off + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
+ Arrays.checkOffsetAndCount(src.length, srcOffset, shortCount);
+ if (shortCount > remaining()) {
throw new BufferOverflowException();
}
- for (int i = off; i < off + len; i++) {
+ for (int i = srcOffset; i < srcOffset + shortCount; ++i) {
put(src[i]);
}
return this;
@@ -488,22 +471,4 @@ public abstract class ShortBuffer extends Buffer implements
* @return a sliced buffer that shares its content with this buffer.
*/
public abstract ShortBuffer slice();
-
- /**
- * Returns a string representing the state of this short buffer.
- *
- * @return a string representing the state of this short buffer.
- */
- @Override
- public String toString() {
- StringBuilder buf = new StringBuilder();
- buf.append(getClass().getName());
- buf.append(", status: capacity=");
- buf.append(capacity());
- buf.append(" position=");
- buf.append(position());
- buf.append(" limit=");
- buf.append(limit());
- return buf.toString();
- }
}
diff --git a/luni/src/main/java/java/nio/ShortToByteBufferAdapter.java b/luni/src/main/java/java/nio/ShortToByteBufferAdapter.java
index d534460..05f3757 100644
--- a/luni/src/main/java/java/nio/ShortToByteBufferAdapter.java
+++ b/luni/src/main/java/java/nio/ShortToByteBufferAdapter.java
@@ -16,8 +16,7 @@
package java.nio;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.nio.internal.DirectBuffer;
+import libcore.io.SizeOf;
/**
* This class wraps a byte buffer to be a short buffer.
@@ -31,77 +30,26 @@ import org.apache.harmony.nio.internal.DirectBuffer;
* </ul>
* </p>
*/
-final class ShortToByteBufferAdapter extends ShortBuffer implements
- DirectBuffer {
-
- static ShortBuffer wrap(ByteBuffer byteBuffer) {
- return new ShortToByteBufferAdapter(byteBuffer.slice());
- }
+final class ShortToByteBufferAdapter extends ShortBuffer {
private final ByteBuffer byteBuffer;
- ShortToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getByteCapacity();
- }
- assert false : byteBuffer;
- return -1;
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- // BEGIN android-changed
- PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress();
- effectiveDirectAddress = addr.toInt();
- return addr;
- // END android-changed
- }
- assert false : byteBuffer;
- return null;
- }
-
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).getBaseAddress();
- }
- assert false : byteBuffer;
- return null;
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer) byteBuffer).isAddressValid();
- }
- assert false : byteBuffer;
- return false;
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
+ static ShortBuffer asShortBuffer(ByteBuffer byteBuffer) {
+ ByteBuffer slice = byteBuffer.slice();
+ slice.order(byteBuffer.order());
+ return new ShortToByteBufferAdapter(slice);
}
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer) byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
+ private ShortToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super(byteBuffer.capacity() / SizeOf.SHORT);
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.effectiveDirectAddress = byteBuffer.effectiveDirectAddress;
}
@Override
public ShortBuffer asReadOnlyBuffer() {
- ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
+ ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -113,8 +61,8 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements
if (byteBuffer.isReadOnly()) {
throw new ReadOnlyBufferException();
}
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
+ byteBuffer.limit(limit * SizeOf.SHORT);
+ byteBuffer.position(position * SizeOf.SHORT);
byteBuffer.compact();
byteBuffer.clear();
position = limit - position;
@@ -125,8 +73,7 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements
@Override
public ShortBuffer duplicate() {
- ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
- .duplicate());
+ ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.duplicate());
buf.limit = limit;
buf.position = position;
buf.mark = mark;
@@ -138,15 +85,26 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements
if (position == limit) {
throw new BufferUnderflowException();
}
- return byteBuffer.getShort(position++ << 1);
+ return byteBuffer.getShort(position++ * SizeOf.SHORT);
}
@Override
public short get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
+ checkIndex(index);
+ return byteBuffer.getShort(index * SizeOf.SHORT);
+ }
+
+ @Override
+ public ShortBuffer get(short[] dst, int dstOffset, int shortCount) {
+ byteBuffer.limit(limit * SizeOf.SHORT);
+ byteBuffer.position(position * SizeOf.SHORT);
+ if (byteBuffer instanceof DirectByteBuffer) {
+ ((DirectByteBuffer) byteBuffer).get(dst, dstOffset, shortCount);
+ } else {
+ ((HeapByteBuffer) byteBuffer).get(dst, dstOffset, shortCount);
}
- return byteBuffer.getShort(index << 1);
+ this.position += shortCount;
+ return this;
}
@Override
@@ -184,38 +142,34 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements
if (position == limit) {
throw new BufferOverflowException();
}
- byteBuffer.putShort(position++ << 1, c);
+ byteBuffer.putShort(position++ * SizeOf.SHORT, c);
return this;
}
@Override
public ShortBuffer put(int index, short c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putShort(index << 1, c);
+ checkIndex(index);
+ byteBuffer.putShort(index * SizeOf.SHORT, c);
return this;
}
- // BEGIN android-added
@Override
- public ShortBuffer put(short[] s, int off, int len) {
+ public ShortBuffer put(short[] src, int srcOffset, int shortCount) {
+ byteBuffer.limit(limit * SizeOf.SHORT);
+ byteBuffer.position(position * SizeOf.SHORT);
if (byteBuffer instanceof ReadWriteDirectByteBuffer) {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- ((ReadWriteDirectByteBuffer) byteBuffer).put(s, off, len);
- this.position += len;
- return this;
+ ((ReadWriteDirectByteBuffer) byteBuffer).put(src, srcOffset, shortCount);
} else {
- return super.put(s, off, len);
+ ((ReadWriteHeapByteBuffer) byteBuffer).put(src, srcOffset, shortCount);
}
+ this.position += shortCount;
+ return this;
}
- // END android-added
@Override
public ShortBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
+ byteBuffer.limit(limit * SizeOf.SHORT);
+ byteBuffer.position(position * SizeOf.SHORT);
ShortBuffer result = new ShortToByteBufferAdapter(byteBuffer.slice());
byteBuffer.clear();
return result;
diff --git a/luni/src/main/java/java/nio/SocketChannelImpl.java b/luni/src/main/java/java/nio/SocketChannelImpl.java
new file mode 100644
index 0000000..dbef3c0
--- /dev/null
+++ b/luni/src/main/java/java/nio/SocketChannelImpl.java
@@ -0,0 +1,734 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ConnectException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.SocketException;
+import java.net.SocketUtils;
+import java.net.UnknownHostException;
+import java.nio.channels.AlreadyConnectedException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ConnectionPendingException;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.NoConnectionPendingException;
+import java.nio.channels.NotYetConnectedException;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.UnresolvedAddressException;
+import java.nio.channels.UnsupportedAddressTypeException;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Arrays;
+import libcore.io.IoUtils;
+import org.apache.harmony.luni.net.PlainSocketImpl;
+import org.apache.harmony.luni.platform.FileDescriptorHandler;
+import org.apache.harmony.luni.platform.Platform;
+
+/*
+ * The default implementation class of java.nio.channels.SocketChannel.
+ */
+class SocketChannelImpl extends SocketChannel implements FileDescriptorHandler {
+
+ private static final int EOF = -1;
+
+ // Status un-init, not initialized.
+ static final int SOCKET_STATUS_UNINIT = EOF;
+
+ // Status before connect.
+ static final int SOCKET_STATUS_UNCONNECTED = 0;
+
+ // Status connection pending.
+ static final int SOCKET_STATUS_PENDING = 1;
+
+ // Status after connection success.
+ static final int SOCKET_STATUS_CONNECTED = 2;
+
+ // Status closed.
+ static final int SOCKET_STATUS_CLOSED = 3;
+
+ // The descriptor to interact with native code.
+ final FileDescriptor fd;
+
+ // Our internal Socket.
+ private SocketAdapter socket = null;
+
+ // The address to be connected.
+ InetSocketAddress connectAddress = null;
+
+ // Local address of the this socket (package private for adapter).
+ InetAddress localAddress = null;
+
+ // Local port number.
+ int localPort;
+
+ // At first, uninitialized.
+ int status = SOCKET_STATUS_UNINIT;
+
+ // Whether the socket is bound.
+ volatile boolean isBound = false;
+
+ private final Object readLock = new Object();
+
+ private final Object writeLock = new Object();
+
+ /*
+ * Constructor for creating a connected socket channel.
+ */
+ public SocketChannelImpl(SelectorProvider selectorProvider) throws IOException {
+ this(selectorProvider, true);
+ }
+
+ /*
+ * Constructor for creating an optionally connected socket channel.
+ */
+ public SocketChannelImpl(SelectorProvider selectorProvider, boolean connect) throws IOException {
+ super(selectorProvider);
+ fd = new FileDescriptor();
+ status = SOCKET_STATUS_UNCONNECTED;
+ if (connect) {
+ Platform.NETWORK.socket(fd, true);
+ }
+ }
+
+ /*
+ * Getting the internal Socket If we have not the socket, we create a new
+ * one.
+ */
+ @Override
+ synchronized public Socket socket() {
+ if (socket == null) {
+ try {
+ InetAddress addr = null;
+ int port = 0;
+ if (connectAddress != null) {
+ addr = connectAddress.getAddress();
+ port = connectAddress.getPort();
+ }
+ socket = new SocketAdapter(new PlainSocketImpl(fd, localPort, addr, port), this);
+ } catch (SocketException e) {
+ return null;
+ }
+ }
+ return socket;
+ }
+
+ @Override
+ synchronized public boolean isConnected() {
+ return status == SOCKET_STATUS_CONNECTED;
+ }
+
+ /*
+ * Status setting used by other class.
+ */
+ synchronized void setConnected() {
+ status = SOCKET_STATUS_CONNECTED;
+ }
+
+ void setBound(boolean flag) {
+ isBound = flag;
+ }
+
+ @Override
+ synchronized public boolean isConnectionPending() {
+ return status == SOCKET_STATUS_PENDING;
+ }
+
+ @Override
+ public boolean connect(SocketAddress socketAddress) throws IOException {
+ // status must be open and unconnected
+ checkUnconnected();
+
+ // check the address
+ InetSocketAddress inetSocketAddress = validateAddress(socketAddress);
+ InetAddress normalAddr = inetSocketAddress.getAddress();
+
+ // When connecting, map ANY address to Localhost
+ if (normalAddr.isAnyLocalAddress()) {
+ normalAddr = InetAddress.getLocalHost();
+ }
+
+ int port = inetSocketAddress.getPort();
+ String hostName = normalAddr.getHostName();
+ // security check
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkConnect(hostName, port);
+ }
+
+ // connect result
+ int result = EOF;
+ boolean finished = false;
+
+ try {
+ if (isBlocking()) {
+ begin();
+ Platform.NETWORK.connect(fd, normalAddr, port, 0);
+ finished = true; // Or we'd have thrown an exception.
+ } else {
+ finished = Platform.NETWORK.connectNonBlocking(fd, normalAddr, port);
+ // set back to nonblocking to work around with a bug in portlib
+ if (!isBlocking()) {
+ IoUtils.setBlocking(fd, false);
+ }
+ }
+ isBound = finished;
+ } catch (IOException e) {
+ if (e instanceof ConnectException && !isBlocking()) {
+ status = SOCKET_STATUS_PENDING;
+ } else {
+ if (isOpen()) {
+ close();
+ finished = true;
+ }
+ throw e;
+ }
+ } finally {
+ if (isBlocking()) {
+ end(finished);
+ }
+ }
+
+ initLocalAddressAndPort();
+ connectAddress = inetSocketAddress;
+ if (socket != null) {
+ socket.socketImpl().initRemoteAddressAndPort(connectAddress.getAddress(),
+ connectAddress.getPort());
+ }
+
+ synchronized (this) {
+ if (isBlocking()) {
+ status = (finished ? SOCKET_STATUS_CONNECTED : SOCKET_STATUS_UNCONNECTED);
+ } else {
+ status = SOCKET_STATUS_PENDING;
+ }
+ }
+ return finished;
+ }
+
+ private void initLocalAddressAndPort() {
+ localAddress = Platform.NETWORK.getSocketLocalAddress(fd);
+ localPort = Platform.NETWORK.getSocketLocalPort(fd);
+ if (socket != null) {
+ socket.socketImpl().initLocalPort(localPort);
+ }
+ }
+
+ @Override
+ public boolean finishConnect() throws IOException {
+ // status check
+ synchronized (this) {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (status == SOCKET_STATUS_CONNECTED) {
+ return true;
+ }
+ if (status != SOCKET_STATUS_PENDING) {
+ throw new NoConnectionPendingException();
+ }
+ }
+
+ boolean finished = false;
+ try {
+ begin();
+ final int WAIT_FOREVER = -1;
+ final int POLL = 0;
+ finished = Platform.NETWORK.isConnected(fd, isBlocking() ? WAIT_FOREVER : POLL);
+ isBound = finished;
+ initLocalAddressAndPort();
+ } catch (ConnectException e) {
+ if (isOpen()) {
+ close();
+ finished = true;
+ }
+ throw e;
+ } finally {
+ end(finished);
+ }
+
+ synchronized (this) {
+ status = (finished ? SOCKET_STATUS_CONNECTED : status);
+ isBound = finished;
+ // TPE: Workaround for bug that turns socket back to blocking
+ if (!isBlocking()) implConfigureBlocking(false);
+ }
+ return finished;
+ }
+
+ void finishAccept() {
+ initLocalAddressAndPort();
+ }
+
+ @Override
+ public int read(ByteBuffer target) throws IOException {
+ FileChannelImpl.checkWritable(target);
+ checkOpenConnected();
+ if (!target.hasRemaining()) {
+ return 0;
+ }
+
+ int readCount;
+ if (target.isDirect() || target.hasArray()) {
+ readCount = readImpl(target);
+ if (readCount > 0) {
+ target.position(target.position() + readCount);
+ }
+ } else {
+ ByteBuffer readBuffer = null;
+ byte[] readArray = null;
+ readArray = new byte[target.remaining()];
+ readBuffer = ByteBuffer.wrap(readArray);
+ readCount = readImpl(readBuffer);
+ if (readCount > 0) {
+ target.put(readArray, 0, readCount);
+ }
+ }
+ return readCount;
+ }
+
+ @Override
+ public long read(ByteBuffer[] targets, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(targets.length, offset, length);
+ checkOpenConnected();
+ int totalCount = FileChannelImpl.calculateTotalRemaining(targets, offset, length, true);
+ if (totalCount == 0) {
+ return 0;
+ }
+ byte[] readArray = new byte[totalCount];
+ ByteBuffer readBuffer = ByteBuffer.wrap(readArray);
+ int readCount;
+ // read data to readBuffer, and then transfer data from readBuffer to
+ // targets.
+ readCount = readImpl(readBuffer);
+ if (readCount > 0) {
+ int left = readCount;
+ int index = offset;
+ // transfer data from readArray to targets
+ while (left > 0) {
+ int putLength = Math.min(targets[index].remaining(), left);
+ targets[index].put(readArray, readCount - left, putLength);
+ index++;
+ left -= putLength;
+ }
+ }
+ return readCount;
+ }
+
+ /**
+ * Read from channel, and store the result in the target.
+ *
+ * @param target
+ * output parameter
+ */
+ private int readImpl(ByteBuffer target) throws IOException {
+ synchronized (readLock) {
+ int readCount = 0;
+ try {
+ if (isBlocking()) {
+ begin();
+ }
+ int offset = target.position();
+ int length = target.remaining();
+ if (target.isDirect()) {
+ // BEGIN android-changed
+ // changed address from long to int
+ int address = NioUtils.getDirectBufferAddress(target);
+ readCount = Platform.NETWORK.readDirect(fd, address + offset, length);
+ // END android-changed
+ } else {
+ // target is assured to have array.
+ byte[] array = target.array();
+ offset += target.arrayOffset();
+ readCount = Platform.NETWORK.read(fd, array, offset, length);
+ }
+ return readCount;
+ } finally {
+ if (isBlocking()) {
+ end(readCount > 0);
+ }
+ }
+ }
+ }
+
+ @Override
+ public int write(ByteBuffer source) throws IOException {
+ if (source == null) {
+ throw new NullPointerException();
+ }
+ checkOpenConnected();
+ if (!source.hasRemaining()) {
+ return 0;
+ }
+ return writeImpl(source);
+ }
+
+ @Override
+ public long write(ByteBuffer[] sources, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(sources.length, offset, length);
+ checkOpenConnected();
+ int count = FileChannelImpl.calculateTotalRemaining(sources, offset, length, false);
+ if (count == 0) {
+ return 0;
+ }
+ ByteBuffer writeBuf = ByteBuffer.allocate(count);
+ for (int val = offset; val < length + offset; val++) {
+ ByteBuffer source = sources[val];
+ int oldPosition = source.position();
+ writeBuf.put(source);
+ source.position(oldPosition);
+ }
+ writeBuf.flip();
+ int result = writeImpl(writeBuf);
+ int val = offset;
+ int written = result;
+ while (result > 0) {
+ ByteBuffer source = sources[val];
+ int gap = Math.min(result, source.remaining());
+ source.position(source.position() + gap);
+ val++;
+ result -= gap;
+ }
+ return written;
+ }
+
+ /*
+ * Write the source. return the count of bytes written.
+ */
+ private int writeImpl(ByteBuffer source) throws IOException {
+ synchronized (writeLock) {
+ if (!source.hasRemaining()) {
+ return 0;
+ }
+ int writeCount = 0;
+ try {
+ int pos = source.position();
+ int length = source.remaining();
+ if (isBlocking()) {
+ begin();
+ }
+ if (source.isDirect()) {
+ int address = NioUtils.getDirectBufferAddress(source);
+ writeCount = Platform.NETWORK.writeDirect(fd, address, pos, length);
+ } else if (source.hasArray()) {
+ pos += source.arrayOffset();
+ writeCount = Platform.NETWORK.write(fd, source.array(), pos, length);
+ } else {
+ byte[] array = new byte[length];
+ source.get(array);
+ writeCount = Platform.NETWORK.write(fd, array, 0, length);
+ }
+ source.position(pos + writeCount);
+ } finally {
+ if (isBlocking()) {
+ end(writeCount >= 0);
+ }
+ }
+ return writeCount;
+ }
+ }
+
+ /*
+ * Status check, open and "connected", when read and write.
+ */
+ synchronized private void checkOpenConnected() throws ClosedChannelException {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (!isConnected()) {
+ throw new NotYetConnectedException();
+ }
+ }
+
+ /*
+ * Status check, open and "unconnected", before connection.
+ */
+ synchronized private void checkUnconnected() throws IOException {
+ if (!isOpen()) {
+ throw new ClosedChannelException();
+ }
+ if (status == SOCKET_STATUS_CONNECTED) {
+ throw new AlreadyConnectedException();
+ }
+ if (status == SOCKET_STATUS_PENDING) {
+ throw new ConnectionPendingException();
+ }
+ }
+
+ /*
+ * Shared by this class and DatagramChannelImpl, to do the address transfer
+ * and check.
+ */
+ static InetSocketAddress validateAddress(SocketAddress socketAddress) {
+ if (socketAddress == null) {
+ throw new IllegalArgumentException();
+ }
+ if (!(socketAddress instanceof InetSocketAddress)) {
+ throw new UnsupportedAddressTypeException();
+ }
+ InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
+ if (inetSocketAddress.isUnresolved()) {
+ throw new UnresolvedAddressException();
+ }
+ return inetSocketAddress;
+ }
+
+ /*
+ * Get local address.
+ */
+ public InetAddress getLocalAddress() throws UnknownHostException {
+ if (!isBound) {
+ byte[] any_bytes = { 0, 0, 0, 0 };
+ return InetAddress.getByAddress(any_bytes);
+ }
+ return localAddress;
+ }
+
+ /*
+ * Do really closing action here.
+ */
+ @Override
+ protected synchronized void implCloseSelectableChannel() throws IOException {
+ if (status != SOCKET_STATUS_CLOSED) {
+ status = SOCKET_STATUS_CLOSED;
+ if (socket != null && !socket.isClosed()) {
+ socket.close();
+ } else {
+ Platform.NETWORK.close(fd);
+ }
+ }
+ }
+
+ @Override
+ protected void implConfigureBlocking(boolean blockMode) throws IOException {
+ synchronized (blockingLock()) {
+ IoUtils.setBlocking(fd, blockMode);
+ }
+ }
+
+ /*
+ * Get the fd.
+ */
+ public FileDescriptor getFD() {
+ return fd;
+ }
+
+ /*
+ * Adapter classes for internal socket.
+ */
+ private static class SocketAdapter extends Socket {
+ private final SocketChannelImpl channel;
+ private final PlainSocketImpl socketImpl;
+
+ SocketAdapter(PlainSocketImpl socketImpl, SocketChannelImpl channel) throws SocketException {
+ super(socketImpl);
+ this.socketImpl = socketImpl;
+ this.channel = channel;
+ SocketUtils.setCreated(this);
+ }
+
+ PlainSocketImpl socketImpl() {
+ return socketImpl;
+ }
+
+ @Override
+ public SocketChannel getChannel() {
+ return channel;
+ }
+
+ @Override
+ public boolean isBound() {
+ return channel.isBound;
+ }
+
+ @Override
+ public boolean isConnected() {
+ return channel.isConnected();
+ }
+
+ @Override
+ public InetAddress getLocalAddress() {
+ try {
+ return channel.getLocalAddress();
+ } catch (UnknownHostException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
+ if (!channel.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ if (isConnected()) {
+ throw new AlreadyConnectedException();
+ }
+ super.connect(remoteAddr, timeout);
+ channel.initLocalAddressAndPort();
+ if (super.isConnected()) {
+ channel.setConnected();
+ channel.isBound = super.isBound();
+ }
+ }
+
+ @Override
+ public void bind(SocketAddress localAddr) throws IOException {
+ if (channel.isConnected()) {
+ throw new AlreadyConnectedException();
+ }
+ if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) {
+ throw new ConnectionPendingException();
+ }
+ super.bind(localAddr);
+ // keep here to see if need next version
+ // channel.Address = getLocalSocketAddress();
+ // channel.localport = getLocalPort();
+ channel.isBound = true;
+ }
+
+ @Override
+ public void close() throws IOException {
+ synchronized (channel) {
+ if (channel.isOpen()) {
+ channel.close();
+ } else {
+ super.close();
+ }
+ channel.status = SocketChannelImpl.SOCKET_STATUS_CLOSED;
+ }
+ }
+
+ @Override
+ public OutputStream getOutputStream() throws IOException {
+ checkOpenAndConnected();
+ if (isOutputShutdown()) {
+ throw new SocketException("Socket output is shutdown");
+ }
+ return new SocketChannelOutputStream(channel);
+ }
+
+ @Override
+ public InputStream getInputStream() throws IOException {
+ checkOpenAndConnected();
+ if (isInputShutdown()) {
+ throw new SocketException("Socket input is shutdown");
+ }
+ return new SocketChannelInputStream(channel);
+ }
+
+ private void checkOpenAndConnected() throws SocketException {
+ if (!channel.isOpen()) {
+ throw new SocketException("Socket is closed");
+ }
+ if (!channel.isConnected()) {
+ throw new SocketException("Socket is not connected");
+ }
+ }
+ }
+
+ /*
+ * This output stream delegates all operations to the associated channel.
+ * Throws an IllegalBlockingModeException if the channel is in non-blocking
+ * mode when performing write operations.
+ */
+ private static class SocketChannelOutputStream extends OutputStream {
+ private final SocketChannel channel;
+
+ public SocketChannelOutputStream(SocketChannel channel) {
+ this.channel = channel;
+ }
+
+ /*
+ * Closes this stream and channel.
+ *
+ * @exception IOException thrown if an error occurs during the close
+ */
+ @Override
+ public void close() throws IOException {
+ channel.close();
+ }
+
+ @Override
+ public void write(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount);
+ if (!channel.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ channel.write(buf);
+ }
+
+ @Override
+ public void write(int oneByte) throws IOException {
+ if (!channel.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ ByteBuffer buffer = ByteBuffer.allocate(1);
+ buffer.put(0, (byte) (oneByte & 0xFF));
+ channel.write(buffer);
+ }
+ }
+
+ /*
+ * This input stream delegates all operations to the associated channel.
+ * Throws an IllegalBlockingModeException if the channel is in non-blocking
+ * mode when performing read operations.
+ */
+ private static class SocketChannelInputStream extends InputStream {
+ private final SocketChannel channel;
+
+ public SocketChannelInputStream(SocketChannel channel) {
+ this.channel = channel;
+ }
+
+ /*
+ * Closes this stream and channel.
+ */
+ @Override
+ public void close() throws IOException {
+ channel.close();
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (!channel.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ ByteBuffer buf = ByteBuffer.allocate(1);
+ int result = channel.read(buf);
+ // BEGIN android-changed: input was already consumed
+ return (-1 == result) ? result : buf.get(0) & 0xFF;
+ // END android-changed
+ }
+
+ @Override
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (!channel.isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ ByteBuffer buf = ByteBuffer.wrap(buffer, offset, byteCount);
+ return channel.read(buf);
+ }
+ }
+}
diff --git a/luni/src/main/java/java/nio/WriteOnlyFileChannel.java b/luni/src/main/java/java/nio/WriteOnlyFileChannel.java
new file mode 100644
index 0000000..c0c19e9
--- /dev/null
+++ b/luni/src/main/java/java/nio/WriteOnlyFileChannel.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio;
+
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileLock;
+import java.nio.channels.NonReadableChannelException;
+import java.nio.channels.WritableByteChannel;
+import java.util.Arrays;
+
+final class WriteOnlyFileChannel extends FileChannelImpl {
+
+ private boolean append = false;
+
+ public WriteOnlyFileChannel(Object stream, int handle) {
+ super(stream, handle);
+ }
+
+ public WriteOnlyFileChannel(Object stream, int handle, boolean isAppend) {
+ super(stream, handle);
+ append = isAppend;
+ }
+
+ public long position() throws IOException {
+ return append ? size() : super.position();
+ }
+
+ public long transferTo(long position, long count, WritableByteChannel target)
+ throws IOException {
+ openCheck();
+ if (!target.isOpen()) {
+ throw new ClosedChannelException();
+ }
+ throw new NonReadableChannelException();
+ }
+
+ public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
+ Arrays.checkOffsetAndCount(buffers.length, offset, length);
+ openCheck();
+ throw new NonReadableChannelException();
+ }
+
+ public int read(ByteBuffer buffer) throws IOException {
+ openCheck();
+ throw new NonReadableChannelException();
+ }
+
+ public int read(ByteBuffer buffer, long position) throws IOException {
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0) {
+ throw new IllegalArgumentException();
+ }
+ throw new NonReadableChannelException();
+ }
+
+ public MappedByteBuffer map(MapMode mode, long position, long size)
+ throws IOException {
+ openCheck();
+ if (mode == null) {
+ throw new NullPointerException();
+ }
+ if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException();
+ }
+ throw new NonReadableChannelException();
+ }
+
+ public int write(ByteBuffer buffer) throws IOException {
+ if (append) {
+ position(size());
+ }
+ return super.write(buffer);
+ }
+
+ protected final FileLock basicLock(long position, long size,
+ boolean shared, boolean wait) throws IOException {
+ if (shared) {
+ throw new NonReadableChannelException();
+ }
+ return super.basicLock(position, size, shared, wait);
+ }
+}
diff --git a/luni/src/main/java/java/nio/channels/Channels.java b/luni/src/main/java/java/nio/channels/Channels.java
index 615e781..be498c4 100644
--- a/luni/src/main/java/java/nio/channels/Channels.java
+++ b/luni/src/main/java/java/nio/channels/Channels.java
@@ -19,28 +19,23 @@ package java.nio.channels;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
import java.nio.channels.spi.AbstractInterruptibleChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
-import org.apache.harmony.nio.internal.IOUtil;
/**
* This class provides several utilities to get I/O streams from channels.
*/
public final class Channels {
- /*
- * Not intended to be instantiated.
- */
- private Channels() {
- super();
- }
+ private Channels() {}
/**
* Returns an input stream on the given channel. The resulting stream has
@@ -60,7 +55,7 @@ public final class Channels {
* @return an InputStream that takes bytes from the given byte channel.
*/
public static InputStream newInputStream(ReadableByteChannel channel) {
- return new ReadableByteChannelInputStream(channel);
+ return new ChannelInputStream(channel);
}
/**
@@ -80,7 +75,7 @@ public final class Channels {
* @return an OutputStream that puts bytes onto the given byte channel.
*/
public static OutputStream newOutputStream(WritableByteChannel channel) {
- return new WritableByteChannelOutputStream(channel);
+ return new ChannelOutputStream(channel);
}
/**
@@ -97,7 +92,7 @@ public final class Channels {
* @return a byte channel that reads bytes from the input stream.
*/
public static ReadableByteChannel newChannel(InputStream inputStream) {
- return new ReadableByteChannelImpl(inputStream);
+ return new InputStreamChannel(inputStream);
}
/**
@@ -115,7 +110,7 @@ public final class Channels {
* @return a byte channel that writes bytes to the output stream.
*/
public static WritableByteChannel newChannel(OutputStream outputStream) {
- return new WritableByteChannelImpl(outputStream);
+ return new OutputStreamChannel(outputStream);
}
/**
@@ -132,8 +127,11 @@ public final class Channels {
*/
public static Reader newReader(ReadableByteChannel channel,
CharsetDecoder decoder, int minBufferCapacity) {
- return new ByteChannelReader(new ReaderInputStream(channel), decoder,
- minBufferCapacity);
+ /*
+ * This method doesn't honor minBufferCapacity. Ignoring that parameter
+ * saves us from having to add a hidden constructor to InputStreamReader.
+ */
+ return new InputStreamReader(new ChannelInputStream(channel), decoder);
}
/**
@@ -150,6 +148,9 @@ public final class Channels {
*/
public static Reader newReader(ReadableByteChannel channel,
String charsetName) {
+ if (charsetName == null) {
+ throw new NullPointerException();
+ }
return newReader(channel, Charset.forName(charsetName).newDecoder(), -1);
}
@@ -168,8 +169,11 @@ public final class Channels {
*/
public static Writer newWriter(WritableByteChannel channel,
CharsetEncoder encoder, int minBufferCapacity) {
- return new ByteChannelWriter(new WritableByteChannelOutputStream(
- channel), encoder, minBufferCapacity);
+ /*
+ * This method doesn't honor minBufferCapacity. Ignoring that parameter
+ * saves us from having to add a hidden constructor to OutputStreamWriter.
+ */
+ return new OutputStreamWriter(new ChannelOutputStream(channel), encoder);
}
/**
@@ -187,28 +191,24 @@ public final class Channels {
*/
public static Writer newWriter(WritableByteChannel channel,
String charsetName) {
+ if (charsetName == null) {
+ throw new NullPointerException();
+ }
return newWriter(channel, Charset.forName(charsetName).newEncoder(), -1);
}
- /*
- * wrap a byte array to a ByteBuffer
+ /**
+ * An input stream that delegates to a readable channel.
*/
- static ByteBuffer wrapByteBuffer(byte[] bytes, int offset, int length) {
- ByteBuffer buffer = ByteBuffer.wrap(bytes);
- int newLimit = offset + length <= buffer.capacity() ? offset + length
- : buffer.capacity();
- buffer.limit(newLimit);
- buffer.position(offset);
- return buffer;
- }
-
private static class ChannelInputStream extends InputStream {
- protected ReadableByteChannel channel;
+ private final ReadableByteChannel channel;
- public ChannelInputStream(ReadableByteChannel aChannel) {
- super();
- channel = aChannel;
+ ChannelInputStream(ReadableByteChannel channel) {
+ if (channel == null) {
+ throw new NullPointerException();
+ }
+ this.channel = channel;
}
@Override
@@ -223,101 +223,56 @@ public final class Channels {
}
@Override
- public synchronized void close() throws IOException {
- channel.close();
- }
- }
-
- /*
- * Wrapper class used for newInputStream(ReadableByteChannel channel)
- */
- private static class ReadableByteChannelInputStream extends ChannelInputStream {
-
- public ReadableByteChannelInputStream(ReadableByteChannel aChannel) {
- super(aChannel);
- }
-
- @Override
- public synchronized int read(byte[] target, int offset, int length)
- throws IOException {
- // avoid int overflow, check null target
- if (length + offset > target.length || length < 0 || offset < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
- if (0 == length) {
- return 0;
- }
- if (channel instanceof SelectableChannel) {
- if (!((SelectableChannel) channel).isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- }
+ public synchronized int read(byte[] target, int offset, int length) throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(target, offset, length);
+ checkBlocking(channel);
return channel.read(buffer);
}
- }
-
- /*
- * Wrapper class used for newReader(ReadableByteChannel channel,
- * CharsetDecoder decoder, int minBufferCapacity)
- */
- private static class ReaderInputStream extends ChannelInputStream {
- public ReaderInputStream(ReadableByteChannel aChannel) {
- super(aChannel);
+ @Override public int available() throws IOException {
+ if (channel instanceof FileChannel) {
+ FileChannel fileChannel = (FileChannel) channel;
+ long result = fileChannel.size() - fileChannel.position();
+ return result > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) result;
+ } else {
+ return super.available();
+ }
}
@Override
- public synchronized int read(byte[] target, int offset, int length)
- throws IOException {
- // avoid int overflow, check null target
- if (length + offset > target.length || length < 0 || offset < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
- if (0 == length) {
- return 0;
- }
- ByteBuffer buffer = ByteBuffer.wrap(target, offset, length);
- return channel.read(buffer);
+ public synchronized void close() throws IOException {
+ channel.close();
}
}
- /*
- * Wrapper class used for newOutputStream(WritableByteChannel channel)
+ /**
+ * An output stream that delegates to a writable channel.
*/
- private static class WritableByteChannelOutputStream extends OutputStream {
+ private static class ChannelOutputStream extends OutputStream {
- private WritableByteChannel channel;
+ private final WritableByteChannel channel;
- public WritableByteChannelOutputStream(WritableByteChannel aChannel) {
- super();
- channel = aChannel;
+ ChannelOutputStream(WritableByteChannel channel) {
+ if (channel == null) {
+ throw new NullPointerException();
+ }
+ this.channel = channel;
}
@Override
public synchronized void write(int oneByte) throws IOException {
- byte[] wrappedByte = new byte[1];
- wrappedByte[0] = (byte) oneByte;
+ byte[] wrappedByte = { (byte) oneByte };
write(wrappedByte);
}
@Override
- public synchronized void write(byte[] source, int offset, int length)
- throws IOException {
- // avoid int overflow, check null source
- if (length + offset > source.length || length < 0 || offset < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
- if (0 == length) {
- return;
- }
- if (channel instanceof SelectableChannel) {
- if (!((SelectableChannel) channel).isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- }
+ public synchronized void write(byte[] source, int offset, int length) throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(source, offset, length);
- channel.write(buffer);
+ checkBlocking(channel);
+ int total = 0;
+ while (total < length) {
+ total += channel.write(buffer);
+ }
}
@Override
@@ -326,16 +281,24 @@ public final class Channels {
}
}
- /*
- * Wrapper class used for newChannel(InputStream inputStream)
+ static void checkBlocking(Channel channel) {
+ if (channel instanceof SelectableChannel && !((SelectableChannel) channel).isBlocking()) {
+ throw new IllegalBlockingModeException();
+ }
+ }
+
+ /**
+ * A readable channel that delegates to an input stream.
*/
- private static class ReadableByteChannelImpl extends
- AbstractInterruptibleChannel implements ReadableByteChannel {
- private InputStream inputStream;
+ private static class InputStreamChannel extends AbstractInterruptibleChannel
+ implements ReadableByteChannel {
+ private final InputStream inputStream;
- ReadableByteChannelImpl(InputStream aInputStream) {
- super();
- inputStream = aInputStream;
+ InputStreamChannel(InputStream inputStream) {
+ if (inputStream == null) {
+ throw new NullPointerException();
+ }
+ this.inputStream = inputStream;
}
public synchronized int read(ByteBuffer target) throws IOException {
@@ -363,16 +326,18 @@ public final class Channels {
}
}
- /*
- * Wrapper class used for newChannel(OutputStream outputStream)
+ /**
+ * A writable channel that delegates to an output stream.
*/
- private static class WritableByteChannelImpl extends
- AbstractInterruptibleChannel implements WritableByteChannel {
- private OutputStream outputStream;
+ private static class OutputStreamChannel extends AbstractInterruptibleChannel
+ implements WritableByteChannel {
+ private final OutputStream outputStream;
- WritableByteChannelImpl(OutputStream aOutputStream) {
- super();
- outputStream = aOutputStream;
+ OutputStreamChannel(OutputStream outputStream) {
+ if (outputStream == null) {
+ throw new NullPointerException();
+ }
+ this.outputStream = outputStream;
}
public synchronized int write(ByteBuffer source) throws IOException {
@@ -399,133 +364,4 @@ public final class Channels {
outputStream.close();
}
}
-
- /*
- * Wrapper class used for newReader(ReadableByteChannel channel,
- * CharsetDecoder decoder, int minBufferCapacity)
- */
- private static class ByteChannelReader extends Reader {
-
- private InputStream inputStream;
-
- private static final int BUFFER_SIZE = 8192;
-
- CharsetDecoder decoder;
-
- ByteBuffer bytes;
-
- CharBuffer chars;
-
- public ByteChannelReader(InputStream aInputStream,
- CharsetDecoder aDecoder, int minBufferCapacity) {
- super(aInputStream);
- aDecoder.reset();
- inputStream = aInputStream;
- int bufferSize = Math.max(minBufferCapacity, BUFFER_SIZE);
- bytes = ByteBuffer.allocate(bufferSize);
- chars = CharBuffer.allocate(bufferSize);
- decoder = aDecoder;
- chars.limit(0);
- }
-
- @Override
- public void close() throws IOException {
- synchronized (lock) {
- decoder = null;
- if (inputStream != null) {
- inputStream.close();
- inputStream = null;
- }
- }
- }
-
- @Override
- public boolean ready() {
- synchronized (lock) {
- if (null == inputStream) {
- return false;
- }
- try {
- return chars.limit() > chars.position()
- || inputStream.available() > 0;
- } catch (IOException e) {
- return false;
- }
- }
- }
-
- @Override
- public int read() throws IOException {
- return IOUtil.readInputStreamReader(inputStream, bytes, chars,
- decoder, lock);
- }
-
- @Override
- public int read(char[] buf, int offset, int length) throws IOException {
- return IOUtil.readInputStreamReader(buf, offset, length,
- inputStream, bytes, chars, decoder, lock);
- }
- }
-
- /*
- * Wrapper class used for newWriter(WritableByteChannel channel,
- * CharsetEncoder encoder, int minBufferCapacity)
- */
- private static class ByteChannelWriter extends Writer {
-
- private static final int BUFFER_SIZE = 8192;
-
- private OutputStream outputStream;
-
- private CharsetEncoder encoder;
-
- private ByteBuffer byteBuf;
-
- public ByteChannelWriter(OutputStream aOutputStream,
- CharsetEncoder aEncoder, int minBufferCap) {
- super(aOutputStream);
- aEncoder.charset();
- outputStream = aOutputStream;
- byteBuf = ByteBuffer.allocate(Math.max(minBufferCap, BUFFER_SIZE));
- encoder = aEncoder;
- }
-
- @Override
- public void close() throws IOException {
- synchronized (lock) {
- if (encoder != null) {
- flush();
- outputStream.flush();
- outputStream.close();
- encoder = null;
- byteBuf = null;
- }
- }
- }
-
- @Override
- public void flush() throws IOException {
- IOUtil
- .flushOutputStreamWriter(outputStream, byteBuf, encoder,
- lock);
- }
-
- @Override
- public void write(char[] buf, int offset, int count) throws IOException {
- IOUtil.writeOutputStreamWriter(buf, offset, count, outputStream,
- byteBuf, encoder, lock);
- }
-
- @Override
- public void write(int oneChar) throws IOException {
- IOUtil.writeOutputStreamWriter(oneChar, outputStream, byteBuf,
- encoder, lock);
- }
-
- @Override
- public void write(String str, int offset, int count) throws IOException {
- IOUtil.writeOutputStreamWriter(str, offset, count, outputStream,
- byteBuf, encoder, lock);
- }
- }
}
diff --git a/luni/src/main/java/java/nio/channels/SocketChannel.java b/luni/src/main/java/java/nio/channels/SocketChannel.java
index 0951b46..9ca75ef 100644
--- a/luni/src/main/java/java/nio/channels/SocketChannel.java
+++ b/luni/src/main/java/java/nio/channels/SocketChannel.java
@@ -109,7 +109,7 @@ public abstract class SocketChannel extends AbstractSelectableChannel implements
*/
public static SocketChannel open(SocketAddress address) throws IOException {
SocketChannel socketChannel = open();
- if (null != socketChannel) {
+ if (socketChannel != null) {
socketChannel.connect(address);
}
return socketChannel;
diff --git a/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java b/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java
index 5be8919..ff44c11 100644
--- a/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java
+++ b/luni/src/main/java/java/nio/channels/spi/AbstractSelectableChannel.java
@@ -42,11 +42,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
*/
private List<SelectionKey> keyList = new ArrayList<SelectionKey>();
- // Marker class so lock type shows up in profilers
- static private class BlockingLock {
- }
-
- private final Object blockingLock = new BlockingLock();
+ private final Object blockingLock = new Object();
boolean isBlocking = true;
@@ -95,7 +91,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
synchronized public final SelectionKey keyFor(Selector selector) {
for (int i = 0; i < keyList.size(); i++) {
SelectionKey key = keyList.get(i);
- if (null != key && key.selector() == selector) {
+ if (key != null && key.selector() == selector) {
return key;
}
}
@@ -144,7 +140,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
throw new IllegalBlockingModeException();
}
if (!selector.isOpen()) {
- if (0 == interestSet) {
+ if (interestSet == 0) {
// throw ISE exactly to keep consistency
throw new IllegalSelectorException();
}
@@ -152,9 +148,8 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
throw new NullPointerException();
}
SelectionKey key = keyFor(selector);
- if (null == key) {
- key = ((AbstractSelector) selector).register(this, interestSet,
- attachment);
+ if (key == null) {
+ key = ((AbstractSelector) selector).register(this, interestSet, attachment);
keyList.add(key);
} else {
if (!key.isValid()) {
@@ -181,7 +176,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
implCloseSelectableChannel();
for (int i = 0; i < keyList.size(); i++) {
SelectionKey key = keyList.get(i);
- if (null != key) {
+ if (key != null) {
key.cancel();
}
}
@@ -273,7 +268,7 @@ public abstract class AbstractSelectableChannel extends SelectableChannel {
* package private for deregister method in AbstractSelector.
*/
synchronized void deregister(SelectionKey k) {
- if (null != keyList) {
+ if (keyList != null) {
keyList.remove(k);
}
}
diff --git a/luni/src/main/java/java/nio/channels/spi/SelectorProvider.java b/luni/src/main/java/java/nio/channels/spi/SelectorProvider.java
index dac2369..201ea9f 100644
--- a/luni/src/main/java/java/nio/channels/spi/SelectorProvider.java
+++ b/luni/src/main/java/java/nio/channels/spi/SelectorProvider.java
@@ -18,6 +18,7 @@
package java.nio.channels.spi;
import java.io.IOException;
+import java.nio.SelectorProviderImpl;
import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
@@ -26,7 +27,6 @@ import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ServiceLoader;
-import org.apache.harmony.nio.internal.SelectorProviderImpl;
/**
* {@code SelectorProvider} is an abstract base class that declares methods for
@@ -39,6 +39,7 @@ import org.apache.harmony.nio.internal.SelectorProviderImpl;
* the system default provider is returned.
*/
public abstract class SelectorProvider {
+
private static SelectorProvider provider = null;
/**
@@ -50,7 +51,7 @@ public abstract class SelectorProvider {
*/
protected SelectorProvider() {
super();
- if (null != System.getSecurityManager()) {
+ if (System.getSecurityManager() != null) {
System.getSecurityManager().checkPermission(
new RuntimePermission("selectorProvider"));
}
diff --git a/luni/src/main/java/java/nio/charset/Charset.java b/luni/src/main/java/java/nio/charset/Charset.java
index fe56655..800d810 100644
--- a/luni/src/main/java/java/nio/charset/Charset.java
+++ b/luni/src/main/java/java/nio/charset/Charset.java
@@ -17,7 +17,6 @@
package java.nio.charset;
-import com.ibm.icu4jni.charset.NativeConverter;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
@@ -33,6 +32,7 @@ import java.util.ServiceLoader;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
+import libcore.icu.NativeConverter;
/**
* A charset is a named mapping between Unicode characters and byte sequences. Every
@@ -308,7 +308,7 @@ public abstract class Charset implements Comparable<Charset> {
* Equivalent to {@code forName} but only throws {@code UnsupportedEncodingException},
* which is all pre-nio code claims to throw.
*
- * @hide
+ * @hide internal use only
*/
public static Charset forNameUEE(String charsetName) throws UnsupportedEncodingException {
try {
diff --git a/luni/src/main/java/java/nio/charset/CharsetDecoder.java b/luni/src/main/java/java/nio/charset/CharsetDecoder.java
index f4c4558..df2bb6a 100644
--- a/luni/src/main/java/java/nio/charset/CharsetDecoder.java
+++ b/luni/src/main/java/java/nio/charset/CharsetDecoder.java
@@ -620,7 +620,7 @@ public abstract class CharsetDecoder {
* if {@code newAction} is {@code null}.
*/
public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
- if (null == newAction) {
+ if (newAction == null) {
throw new IllegalArgumentException();
}
malformAction = newAction;
@@ -641,9 +641,8 @@ public abstract class CharsetDecoder {
* @throws IllegalArgumentException
* if {@code newAction} is {@code null}.
*/
- public final CharsetDecoder onUnmappableCharacter(
- CodingErrorAction newAction) {
- if (null == newAction) {
+ public final CharsetDecoder onUnmappableCharacter(CodingErrorAction newAction) {
+ if (newAction == null) {
throw new IllegalArgumentException();
}
unmapAction = newAction;
diff --git a/luni/src/main/java/java/nio/charset/CharsetEncoder.java b/luni/src/main/java/java/nio/charset/CharsetEncoder.java
index ca56ae5..739b152 100644
--- a/luni/src/main/java/java/nio/charset/CharsetEncoder.java
+++ b/luni/src/main/java/java/nio/charset/CharsetEncoder.java
@@ -16,12 +16,12 @@
package java.nio.charset;
-import com.ibm.icu4jni.charset.CharsetEncoderICU;
import java.nio.BufferOverflowException;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Arrays;
+import libcore.icu.CharsetEncoderICU;
/**
* Transforms a sequence of 16-bit Java characters to a byte sequence in some encoding.
diff --git a/luni/src/main/java/java/nio/charset/Charsets.java b/luni/src/main/java/java/nio/charset/Charsets.java
index 1e11bef..1c2425a 100644
--- a/luni/src/main/java/java/nio/charset/Charsets.java
+++ b/luni/src/main/java/java/nio/charset/Charsets.java
@@ -60,6 +60,22 @@ public class Charsets {
public static native byte[] toUtf8Bytes(char[] chars, int offset, int length);
/**
+ * Returns a new byte array containing the bytes corresponding to the given characters,
+ * encoded in UTF-16BE. All characters are representable in UTF-16BE.
+ */
+ public static byte[] toBigEndianUtf16Bytes(char[] chars, int offset, int length) {
+ byte[] result = new byte[length * 2];
+ int end = offset + length;
+ int resultIndex = 0;
+ for (int i = offset; i < end; ++i) {
+ char ch = chars[i];
+ result[resultIndex++] = (byte) (ch >> 8);
+ result[resultIndex++] = (byte) ch;
+ }
+ return result;
+ }
+
+ /**
* Decodes the given US-ASCII bytes into the given char[]. Equivalent to but faster than:
*
* for (int i = 0; i < count; ++i) {
diff --git a/luni/src/main/java/java/nio/charset/CoderResult.java b/luni/src/main/java/java/nio/charset/CoderResult.java
index 1d31250..b2595f0 100644
--- a/luni/src/main/java/java/nio/charset/CoderResult.java
+++ b/luni/src/main/java/java/nio/charset/CoderResult.java
@@ -115,7 +115,7 @@ public class CoderResult {
Integer key = Integer.valueOf(length);
synchronized (_malformedErrors) {
CoderResult r = _malformedErrors.get(key);
- if (null == r) {
+ if (r == null) {
r = new CoderResult(TYPE_MALFORMED_INPUT, length);
_malformedErrors.put(key, r);
}
@@ -143,7 +143,7 @@ public class CoderResult {
Integer key = Integer.valueOf(length);
synchronized (_unmappableErrors) {
CoderResult r = _unmappableErrors.get(key);
- if (null == r) {
+ if (r == null) {
r = new CoderResult(TYPE_UNMAPPABLE_CHAR, length);
_unmappableErrors.put(key, r);
}
diff --git a/luni/src/main/java/java/nio/charset/ModifiedUtf8.java b/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
index 7481ed7..f4233ef 100644
--- a/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
+++ b/luni/src/main/java/java/nio/charset/ModifiedUtf8.java
@@ -18,6 +18,9 @@
package java.nio.charset;
import java.io.UTFDataFormatException;
+import java.nio.ByteOrder;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* @hide internal use only
@@ -60,6 +63,66 @@ public class ModifiedUtf8 {
return new String(out, 0, s);
}
+ /**
+ * Returns the number of bytes the modified UTF8 representation of 's' would take. Note
+ * that this is just the space for the bytes representing the characters, not the length
+ * which precedes those bytes, because different callers represent the length differently,
+ * as two, four, or even eight bytes. If {@code shortLength} is true, we'll throw an
+ * exception if the string is too long for its length to be represented by a short.
+ */
+ public static long countBytes(String s, boolean shortLength) throws UTFDataFormatException {
+ long result = 0;
+ final int length = s.length();
+ for (int i = 0; i < length; ++i) {
+ char ch = s.charAt(i);
+ if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.
+ ++result;
+ } else if (ch <= 2047) {
+ result += 2;
+ } else {
+ result += 3;
+ }
+ if (shortLength && result > 65535) {
+ throw new UTFDataFormatException("String more than 65535 UTF bytes long");
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Encodes the <i>modified UTF-8</i> bytes corresponding to string {@code s} into the
+ * byte array {@code dst}, starting at the given {@code offset}.
+ */
+ public static void encode(byte[] dst, int offset, String s) {
+ final int length = s.length();
+ for (int i = 0; i < length; i++) {
+ char ch = s.charAt(i);
+ if (ch != 0 && ch <= 127) { // U+0000 uses two bytes.
+ dst[offset++] = (byte) ch;
+ } else if (ch <= 2047) {
+ dst[offset++] = (byte) (0xc0 | (0x1f & (ch >> 6)));
+ dst[offset++] = (byte) (0x80 | (0x3f & ch));
+ } else {
+ dst[offset++] = (byte) (0xe0 | (0x0f & (ch >> 12)));
+ dst[offset++] = (byte) (0x80 | (0x3f & (ch >> 6)));
+ dst[offset++] = (byte) (0x80 | (0x3f & ch));
+ }
+ }
+ }
+
+ /**
+ * Returns an array containing the <i>modified UTF-8</i> form of {@code s}, using a
+ * big-endian 16-bit length. Throws UTFDataFormatException if {@code s} is too long
+ * for a two-byte length.
+ */
+ public static byte[] encode(String s) throws UTFDataFormatException {
+ int utfCount = (int) ModifiedUtf8.countBytes(s, true);
+ byte[] result = new byte[SizeOf.SHORT + utfCount];
+ OSMemory.pokeShort(result, 0, (short) utfCount, ByteOrder.BIG_ENDIAN);
+ ModifiedUtf8.encode(result, SizeOf.SHORT, s);
+ return result;
+ }
+
private ModifiedUtf8() {
}
}
diff --git a/luni/src/main/java/java/security/AlgorithmParameterGenerator.java b/luni/src/main/java/java/security/AlgorithmParameterGenerator.java
index 43d577b..daefa3c 100644
--- a/luni/src/main/java/java/security/AlgorithmParameterGenerator.java
+++ b/luni/src/main/java/java/security/AlgorithmParameterGenerator.java
@@ -30,10 +30,10 @@ public class AlgorithmParameterGenerator {
private static final String SERVICE = "AlgorithmParameterGenerator";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store SecureRandom
- private static SecureRandom randm = new SecureRandom();
+ private static final SecureRandom RANDOM = new SecureRandom();
// Store used provider
private final Provider provider;
@@ -90,12 +90,9 @@ public class AlgorithmParameterGenerator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new AlgorithmParameterGenerator(
- (AlgorithmParameterGeneratorSpi) engine.spi, engine.provider,
- algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) sap.spi,
+ sap.provider, algorithm);
}
/**
@@ -154,12 +151,9 @@ public class AlgorithmParameterGenerator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new AlgorithmParameterGenerator(
- (AlgorithmParameterGeneratorSpi) engine.spi, provider,
- algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) spi, provider,
+ algorithm);
}
/**
@@ -182,7 +176,7 @@ public class AlgorithmParameterGenerator {
* the size (in number of bits).
*/
public final void init(int size) {
- spiImpl.engineInit(size, randm);
+ spiImpl.engineInit(size, RANDOM);
}
/**
@@ -211,7 +205,7 @@ public class AlgorithmParameterGenerator {
*/
public final void init(AlgorithmParameterSpec genParamSpec)
throws InvalidAlgorithmParameterException {
- spiImpl.engineInit(genParamSpec, randm);
+ spiImpl.engineInit(genParamSpec, RANDOM);
}
/**
diff --git a/luni/src/main/java/java/security/AlgorithmParameters.java b/luni/src/main/java/java/security/AlgorithmParameters.java
index 8f751d0..8bbbe1b 100644
--- a/luni/src/main/java/java/security/AlgorithmParameters.java
+++ b/luni/src/main/java/java/security/AlgorithmParameters.java
@@ -36,27 +36,27 @@ public class AlgorithmParameters {
/**
* Used to access common engine functionality.
*/
- private static Engine engine = new Engine(SEVICE);
+ private static final Engine ENGINE = new Engine(SEVICE);
/**
* The security provider.
*/
- private Provider provider;
+ private final Provider provider;
/**
* The SPI implementation.
*/
- private AlgorithmParametersSpi spiImpl;
+ private final AlgorithmParametersSpi spiImpl;
/**
* The security algorithm.
*/
- private String algorithm;
+ private final String algorithm;
/**
* The initialization state.
*/
- private boolean initialized; // = false;
+ private boolean initialized;
/**
* Constructs a new instance of {@code AlgorithmParameters} with the given
@@ -94,11 +94,8 @@ public class AlgorithmParameters {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new AlgorithmParameters((AlgorithmParametersSpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new AlgorithmParameters((AlgorithmParametersSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -156,11 +153,8 @@ public class AlgorithmParameters {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new AlgorithmParameters((AlgorithmParametersSpi) engine.spi,
- provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new AlgorithmParameters((AlgorithmParametersSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/KeyFactory.java b/luni/src/main/java/java/security/KeyFactory.java
index 8387740..916b697 100644
--- a/luni/src/main/java/java/security/KeyFactory.java
+++ b/luni/src/main/java/java/security/KeyFactory.java
@@ -31,18 +31,17 @@ public class KeyFactory {
// The service name.
private static final String SERVICE = "KeyFactory";
- // The provider
- private Provider provider;
-
-
// Used to access common engine functionality
- static private Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
+
+ // The provider
+ private final Provider provider;
// The SPI implementation.
- private KeyFactorySpi spiImpl;
+ private final KeyFactorySpi spiImpl;
// The algorithm.
- private String algorithm;
+ private final String algorithm;
/**
* Constructs a new instance of {@code KeyFactory} with the specified
@@ -59,7 +58,7 @@ public class KeyFactory {
Provider provider,
String algorithm) {
this.provider = provider;
- this. algorithm = algorithm;
+ this.algorithm = algorithm;
this.spiImpl = keyFacSpi;
}
@@ -75,14 +74,12 @@ public class KeyFactory {
* if no provider provides the requested algorithm.
*/
public static KeyFactory getInstance(String algorithm)
- throws NoSuchAlgorithmException {
+ throws NoSuchAlgorithmException {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyFactory((KeyFactorySpi)engine.spi, engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new KeyFactory((KeyFactorySpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -136,10 +133,8 @@ public class KeyFactory {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyFactory((KeyFactorySpi)engine.spi, provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new KeyFactory((KeyFactorySpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/KeyPairGenerator.java b/luni/src/main/java/java/security/KeyPairGenerator.java
index cc91b18..d5851fa 100644
--- a/luni/src/main/java/java/security/KeyPairGenerator.java
+++ b/luni/src/main/java/java/security/KeyPairGenerator.java
@@ -34,10 +34,10 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
private static final String SERVICE = "KeyPairGenerator";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store SecureRandom
- private static SecureRandom random = new SecureRandom();
+ private static final SecureRandom RANDOM = new SecureRandom();
// Store used provider
private Provider provider;
@@ -82,19 +82,16 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
if (algorithm == null) {
throw new NullPointerException();
}
- KeyPairGenerator result;
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- if (engine.spi instanceof KeyPairGenerator) {
- result = (KeyPairGenerator) engine.spi;
- result.algorithm = algorithm;
- result.provider = engine.provider;
- return result;
- }
- result = new KeyPairGeneratorImpl((KeyPairGeneratorSpi) engine.spi,
- engine.provider, algorithm);
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ Object spi = sap.spi;
+ Provider provider = sap.provider;
+ if (spi instanceof KeyPairGenerator) {
+ KeyPairGenerator result = (KeyPairGenerator) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
return result;
}
+ return new KeyPairGeneratorImpl((KeyPairGeneratorSpi) spi, provider, algorithm);
}
/**
@@ -148,19 +145,14 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
if (algorithm == null) {
throw new NullPointerException();
}
- KeyPairGenerator result;
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- if (engine.spi instanceof KeyPairGenerator) {
- result = (KeyPairGenerator) engine.spi;
- result.algorithm = algorithm;
- result.provider = provider;
- return result;
- }
- result = new KeyPairGeneratorImpl((KeyPairGeneratorSpi) engine.spi,
- provider, algorithm);
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ if (spi instanceof KeyPairGenerator) {
+ KeyPairGenerator result = (KeyPairGenerator) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
return result;
}
+ return new KeyPairGeneratorImpl((KeyPairGeneratorSpi) spi, provider, algorithm);
}
/**
@@ -181,7 +173,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
* the size of the key (number of bits)
*/
public void initialize(int keysize) {
- initialize(keysize, random);
+ initialize(keysize, RANDOM);
}
/**
@@ -196,7 +188,7 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
*/
public void initialize(AlgorithmParameterSpec param)
throws InvalidAlgorithmParameterException {
- initialize(param, random);
+ initialize(param, RANDOM);
}
/**
@@ -262,11 +254,6 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi {
// Save KeyPairGeneratorSpi
private KeyPairGeneratorSpi spiImpl;
- // Implementation of KeyPaiGenerator constructor
- //
- // @param KeyPairGeneratorSpi
- // @param provider
- // @param algorithm
private KeyPairGeneratorImpl(KeyPairGeneratorSpi keyPairGeneratorSpi,
Provider provider, String algorithm) {
super(algorithm);
diff --git a/luni/src/main/java/java/security/KeyStore.java b/luni/src/main/java/java/security/KeyStore.java
index fcd0469..ab4b924 100644
--- a/luni/src/main/java/java/security/KeyStore.java
+++ b/luni/src/main/java/java/security/KeyStore.java
@@ -32,6 +32,7 @@ import javax.crypto.SecretKey;
import javax.security.auth.DestroyFailedException;
import javax.security.auth.Destroyable;
import javax.security.auth.callback.CallbackHandler;
+import libcore.io.IoUtils;
import org.apache.harmony.security.fortress.Engine;
/**
@@ -51,7 +52,7 @@ public class KeyStore {
private static final String SERVICE = "KeyStore";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store KeyStore property name
private static final String PROPERTYNAME = "keystore.type";
@@ -111,13 +112,11 @@ public class KeyStore {
if (type == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- try {
- engine.getInstance(type, null);
- return new KeyStore((KeyStoreSpi) engine.spi, engine.provider, type);
- } catch (NoSuchAlgorithmException e) {
+ try {
+ Engine.SpiAndProvider sap = ENGINE.getInstance(type, null);
+ return new KeyStore((KeyStoreSpi) sap.spi, sap.provider, type);
+ } catch (NoSuchAlgorithmException e) {
throw new KeyStoreException(e.getMessage());
- }
}
}
@@ -187,14 +186,12 @@ public class KeyStore {
throw new NullPointerException();
}
// return KeyStore instance
- synchronized (engine) {
- try {
- engine.getInstance(type, provider, null);
- return new KeyStore((KeyStoreSpi) engine.spi, provider, type);
- } catch (Exception e) {
+ try {
+ Object spi = ENGINE.getInstance(type, provider, null);
+ return new KeyStore((KeyStoreSpi) spi, provider, type);
+ } catch (Exception e) {
// override exception
- throw new KeyStoreException(e.getMessage());
- }
+ throw new KeyStoreException(e.getMessage());
}
}
@@ -353,7 +350,7 @@ public class KeyStore {
}
// Certificate chain is required for PrivateKey
- if (null != key && key instanceof PrivateKey && (chain == null || chain.length == 0)) {
+ if (key != null && key instanceof PrivateKey && (chain == null || chain.length == 0)) {
throw new IllegalArgumentException("Certificate chain is not defined for Private key");
}
implSpi.engineSetKeyEntry(alias, key, password, chain);
@@ -879,7 +876,8 @@ public class KeyStore {
// CallbackHandlerProtection
if (!(protectionParameter instanceof PasswordProtection)
&& !(protectionParameter instanceof CallbackHandlerProtection)) {
- throw new IllegalArgumentException("protectionParameter is neither PasswordProtection nor CallbackHandlerProtection instance");
+ throw new IllegalArgumentException("protectionParameter is neither "
+ + "PasswordProtection nor CallbackHandlerProtection instance");
}
// check file parameter
if (!file.exists()) {
@@ -963,13 +961,13 @@ public class KeyStore {
// Store AccessControlContext which is used in getKeyStore() method
private final AccessControlContext accControlContext;
- //
- // Constructor BuilderImpl initializes private fields: keyStore,
- // protParameter, typeForKeyStore providerForKeyStore fileForLoad,
- // isGetKeyStore
- //
+ /**
+ * Constructor BuilderImpl initializes private fields: keyStore,
+ * protParameter, typeForKeyStore providerForKeyStore fileForLoad,
+ * isGetKeyStore
+ */
BuilderImpl(KeyStore ks, ProtectionParameter pp, File file,
- String type, Provider provider, AccessControlContext context) {
+ String type, Provider provider, AccessControlContext context) {
super();
keyStore = ks;
protParameter = pp;
@@ -981,20 +979,20 @@ public class KeyStore {
accControlContext = context;
}
- //
- // Implementation of abstract getKeyStore() method If
- // KeyStoreBuilder encapsulates KeyStore object then this object is
- // returned
- //
- // If KeyStoreBuilder encapsulates KeyStore type and provider then
- // KeyStore is created using these parameters. If KeyStoreBuilder
- // encapsulates file and ProtectionParameter then KeyStore data are
- // loaded from FileInputStream that is created on file. If file is
- // not defined then KeyStore object is initialized with null
- // InputStream and null password.
- //
- // Result KeyStore object is returned.
- //
+ /**
+ * Implementation of abstract getKeyStore() method If
+ * KeyStoreBuilder encapsulates KeyStore object then this object is
+ * returned
+ *
+ * If KeyStoreBuilder encapsulates KeyStore type and provider then
+ * KeyStore is created using these parameters. If KeyStoreBuilder
+ * encapsulates file and ProtectionParameter then KeyStore data are
+ * loaded from FileInputStream that is created on file. If file is
+ * not defined then KeyStore object is initialized with null
+ * InputStream and null password.
+ *
+ * Result KeyStore object is returned.
+ */
@Override
public synchronized KeyStore getKeyStore() throws KeyStoreException {
// If KeyStore was created but in final block some exception was
@@ -1027,7 +1025,8 @@ public class KeyStore {
passwd = KeyStoreSpi
.getPasswordFromCallBack(protParameter);
} else {
- throw new KeyStoreException("protectionParameter is neither PasswordProtection nor CallbackHandlerProtection instance");
+ throw new KeyStoreException("protectionParameter is neither "
+ + "PasswordProtection nor CallbackHandlerProtection instance");
}
// load KeyStore from file
@@ -1040,10 +1039,7 @@ public class KeyStore {
fis = new FileInputStream(fileForLoad);
ks.load(fis, passwd);
} finally {
- // close file input stream
- if( fis != null ) {
- fis.close();
- }
+ IoUtils.closeQuietly(fis);
}
} else {
ks.load(new TmpLSParameter(
@@ -1065,13 +1061,13 @@ public class KeyStore {
}
}
- //
- // This is implementation of abstract method
- // getProtectionParameter(String alias)
- //
- // Return: ProtectionParameter to get Entry which was saved in
- // KeyStore with defined alias
- //
+ /**
+ * This is implementation of abstract method
+ * getProtectionParameter(String alias)
+ *
+ * Return: ProtectionParameter to get Entry which was saved in
+ * KeyStore with defined alias
+ */
@Override
public synchronized ProtectionParameter getProtectionParameter(
String alias) throws KeyStoreException {
@@ -1286,13 +1282,15 @@ public class KeyStore {
// the end certificate
String s = chain[0].getType();
if (!(chain[0].getPublicKey().getAlgorithm()).equals(privateKey.getAlgorithm())) {
- throw new IllegalArgumentException("Algorithm of private key does not match " +
- "algorithm of public key in end certificate of entry (with index number: 0)");
+ throw new IllegalArgumentException("Algorithm of private key does not match "
+ + "algorithm of public key in end certificate of entry "
+ + "(with index number: 0)");
}
// Match certificate types
for (int i = 1; i < chain.length; i++) {
if (!s.equals(chain[i].getType())) {
- throw new IllegalArgumentException("Certificates from the given chain have different types");
+ throw new IllegalArgumentException("Certificates from the given chain have "
+ + "different types");
}
}
// clone chain - this.chain = (Certificate[])chain.clone();
diff --git a/luni/src/main/java/java/security/MessageDigest.java b/luni/src/main/java/java/security/MessageDigest.java
index aac5403..3154028 100644
--- a/luni/src/main/java/java/security/MessageDigest.java
+++ b/luni/src/main/java/java/security/MessageDigest.java
@@ -51,7 +51,7 @@ import org.apache.harmony.security.fortress.Engine;
public abstract class MessageDigest extends MessageDigestSpi {
// Used to access common engine functionality
- private static final Engine engine = new Engine("MessageDigest");
+ private static final Engine ENGINE = new Engine("MessageDigest");
// The provider
private Provider provider;
@@ -88,18 +88,16 @@ public abstract class MessageDigest extends MessageDigestSpi {
if (algorithm == null) {
throw new NullPointerException();
}
- MessageDigest result;
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- if (engine.spi instanceof MessageDigest) {
- result = (MessageDigest) engine.spi;
- result.algorithm = algorithm;
- result.provider = engine.provider;
- return result;
- }
- return new MessageDigestImpl((MessageDigestSpi) engine.spi,
- engine.provider, algorithm);
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ Object spi = sap.spi;
+ Provider provider = sap.provider;
+ if (spi instanceof MessageDigest) {
+ MessageDigest result = (MessageDigest) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
+ return result;
}
+ return new MessageDigestImpl((MessageDigestSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -156,19 +154,14 @@ public abstract class MessageDigest extends MessageDigestSpi {
if (algorithm == null) {
throw new NullPointerException();
}
- MessageDigest result;
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- if (engine.spi instanceof MessageDigest) {
- result = (MessageDigest) engine.spi;
- result.algorithm = algorithm;
- result.provider = provider;
- return result;
- }
- result = new MessageDigestImpl((MessageDigestSpi) engine.spi,
- provider, algorithm);
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ if (spi instanceof MessageDigest) {
+ MessageDigest result = (MessageDigest) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
return result;
}
+ return new MessageDigestImpl((MessageDigestSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/Policy.java b/luni/src/main/java/java/security/Policy.java
index baaedfc..8a5934d 100644
--- a/luni/src/main/java/java/security/Policy.java
+++ b/luni/src/main/java/java/security/Policy.java
@@ -44,30 +44,31 @@ public abstract class Policy {
"setPolicy");
// The SecurityPermission required to get current Policy.
- static final SecurityPermission GET_POLICY = new SecurityPermission("getPolicy");
+ private static final SecurityPermission GET_POLICY = new SecurityPermission("getPolicy");
// The policy currently in effect.
+ // protected by Policy.class monitor.
private static Policy activePolicy;
// Store spi implementation service name
private static final String POLICYSERVICE = "Policy";
// Used to access common engine functionality
- private static Engine engine = new Engine(POLICYSERVICE);
+ private static final Engine ENGINE = new Engine(POLICYSERVICE);
- private String type;
+ private final String type;
- private Policy.Parameters params;
+ private final Policy.Parameters params;
- private Provider provider;
+ private final Provider provider;
// Store used spi implementation
- private PolicySpi spiImpl;
+ private final PolicySpi spiImpl;
private static final String CREATE_POLICY = "createPolicy.";
public Policy() {
- // default constructor
+ this(null, null, null, null);
}
private Policy(PolicySpi spi, Provider p, String t, Policy.Parameters para) {
@@ -97,22 +98,22 @@ public abstract class Policy {
* Note that the list of registered providers may be retrieved via the
* Security.getProviders() method.
*
- * @param type -
+ * @param type
* the specified Policy type. See Appendix A in the Java
* Cryptography Architecture API Specification & Reference for a
* list of standard Policy types.
- * @param params -
+ * @param params
* parameters for the Policy, which may be null.
* @return the new Policy object.
- * @throws NoSuchAlgorithmException -
+ * @throws NoSuchAlgorithmException
* if no Provider supports a PolicySpi implementation for the
* specified type.
- * @throws SecurityException -
+ * @throws SecurityException
* if the caller does not have permission to get a Policy
* instance for the specified type.
- * @throws NullPointerException -
+ * @throws NullPointerException
* if the specified type is null.
- * @throws IllegalArgumentException -
+ * @throws IllegalArgumentException
* if the specified parameters' type are not allowed by the
* PolicySpi implementation from the selected Provider.
*/
@@ -125,12 +126,8 @@ public abstract class Policy {
}
try {
- synchronized (engine) {
- engine.getInstance(type, params);
- return new PolicyDelegate((PolicySpi) engine.spi,
- engine.provider, type, params);
- }
-
+ Engine.SpiAndProvider sap = ENGINE.getInstance(type, params);
+ return new PolicyDelegate((PolicySpi) sap.spi, sap.provider, type, params);
} catch (NoSuchAlgorithmException e) {
if (e.getCause() == null) {
throw e;
@@ -147,27 +144,27 @@ public abstract class Policy {
* in the provider list via the Security.getProviders() method, otherwise
* NoSuchProviderException will be thrown.
*
- * @param type -
+ * @param type
* the specified Policy type. So far in Java 6, only 'JavaPolicy'
* supported.
- * @param params -
+ * @param params
* the Policy.Parameter object, which may be null.
- * @param provider -
+ * @param provider
* the provider.
* @return the new Policy object.
*
- * @throws NoSuchProviderException -
+ * @throws NoSuchProviderException
* if the specified provider is not registered in the security
* provider list.
- * @throws NoSuchAlgorithmException -
+ * @throws NoSuchAlgorithmException
* if the specified provider does not support a PolicySpi
* implementation for the specified type.
- * @throws SecurityException -
+ * @throws SecurityException
* if the caller does not have permission to get a Policy
* instance for the specified type.
- * @throws NullPointerException -
+ * @throws NullPointerException
* if the specified type is null.
- * @throws IllegalArgumentException -
+ * @throws IllegalArgumentException
* if the specified Provider is null, or if the specified
* parameters' type are not allowed by the PolicySpi
* implementation from the specified Provider.
@@ -195,25 +192,25 @@ public abstract class Policy {
* specified Provider object is returned. Note that the specified Provider
* object does not have to be registered in the provider list.
*
- * @param type -
+ * @param type
* the specified Policy type. So far in Java 6, only 'JavaPolicy'
* supported.
- * @param params -
+ * @param params
* the Policy.Parameter object, which may be null.
- * @param provider -
+ * @param provider
* the Policy service Provider.
* @return the new Policy object.
*
- * @throws NoSuchAlgorithmException -
+ * @throws NoSuchAlgorithmException
* if the specified Provider does not support a PolicySpi
* implementation for the specified type.
- * @throws IllegalArgumentException -
+ * @throws IllegalArgumentException
* if the specified Provider is null, or if the specified
* parameters' type are not allowed by the PolicySpi
* implementation from the specified Provider.
- * @throws NullPointerException -
+ * @throws NullPointerException
* if the specified type is null.
- * @throws SecurityException -
+ * @throws SecurityException
* if the caller does not have permission to get a Policy
* instance for the specified type.
*/
@@ -234,17 +231,15 @@ public abstract class Policy {
}
}
- private static Policy getInstanceImpl(String type, Policy.Parameters params, Provider provider) throws NoSuchAlgorithmException {
+ private static Policy getInstanceImpl(String type, Policy.Parameters params, Provider provider)
+ throws NoSuchAlgorithmException {
if (type == null) {
throw new NullPointerException();
}
try {
- synchronized (engine) {
- engine.getInstance(type, provider, params);
- return new PolicyDelegate((PolicySpi) engine.spi, provider,
- type, params);
- }
+ Object spi = ENGINE.getInstance(type, provider, params);
+ return new PolicyDelegate((PolicySpi) spi, provider, type, params);
} catch (NoSuchAlgorithmException e) {
if (e.getCause() == null) {
throw e;
@@ -484,8 +479,7 @@ public abstract class Policy {
try {
return (Policy) Class.forName(defaultClass, true,
ClassLoader.getSystemClassLoader()).newInstance();
- }
- catch (Exception e) {
+ } catch (Exception e) {
//TODO log error
//System.err.println("Error loading policy provider <"
// + defaultClass + "> : " + e
@@ -502,7 +496,9 @@ public abstract class Policy {
* Returns {@code true} if system policy provider is instantiated.
*/
static boolean isSet() {
- return activePolicy != null;
+ synchronized (Policy.class) {
+ return activePolicy != null;
+ }
}
/**
@@ -511,11 +507,13 @@ public abstract class Policy {
* so this method never returns <code>null</code>. <br>
* This method is synchronized with setPolicy()
*/
- static synchronized Policy getAccessiblePolicy() {
- if (activePolicy == null) {
- activePolicy = getDefaultProvider();
+ static Policy getAccessiblePolicy() {
+ synchronized (Policy.class) {
+ if (activePolicy == null) {
+ activePolicy = getDefaultProvider();
+ }
+ return activePolicy;
}
- return activePolicy;
}
/**
diff --git a/luni/src/main/java/java/security/Provider.java b/luni/src/main/java/java/security/Provider.java
index 669fc7b..346d199 100644
--- a/luni/src/main/java/java/security/Provider.java
+++ b/luni/src/main/java/java/security/Provider.java
@@ -866,9 +866,9 @@ public abstract class Provider extends Properties {
*/
@SuppressWarnings("nls")
private void putProviderInfo() {
- super.put("Provider.id name", null != name ? name : "null");
+ super.put("Provider.id name", (name != null) ? name : "null");
super.put("Provider.id version", versionString);
- super.put("Provider.id info", null != info ? info : "null");
+ super.put("Provider.id info", (info != null) ? info : "null");
super.put("Provider.id className", this.getClass().getName());
}
diff --git a/luni/src/main/java/java/security/SecureRandom.java b/luni/src/main/java/java/security/SecureRandom.java
index 16f175c..e56f297 100644
--- a/luni/src/main/java/java/security/SecureRandom.java
+++ b/luni/src/main/java/java/security/SecureRandom.java
@@ -17,7 +17,10 @@
package java.security;
+import java.nio.ByteOrder;
import java.util.Random;
+import libcore.io.SizeOf;
+import org.apache.harmony.luni.platform.OSMemory;
import org.apache.harmony.security.fortress.Engine;
import org.apache.harmony.security.fortress.Services;
import org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl;
@@ -67,27 +70,19 @@ public class SecureRandom extends Random {
private static final long serialVersionUID = 4940670005562187L;
// The service name.
- private static final transient String SERVICE = "SecureRandom";
+ private static final String SERVICE = "SecureRandom";
// Used to access common engine functionality
- private static transient Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
- private Provider provider;
+ private final Provider provider;
- private SecureRandomSpi secureRandomSpi;
+ private final SecureRandomSpi secureRandomSpi;
- private String algorithm;
-
- private byte[] state;
-
- private byte[] randomBytes;
-
- private int randomBytesUsed;
-
- private long counter;
+ private final String algorithm;
// Internal SecureRandom used for getSeed(int)
- private static transient SecureRandom internalSecureRandom;
+ private static volatile SecureRandom internalSecureRandom;
/**
* Constructs a new {@code SecureRandom} that uses the default algorithm.
@@ -163,10 +158,9 @@ public class SecureRandom extends Random {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new SecureRandom((SecureRandomSpi)engine.spi, engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new SecureRandom((SecureRandomSpi) sap.spi, sap.provider,
+ algorithm);
}
/**
@@ -223,10 +217,8 @@ public class SecureRandom extends Random {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new SecureRandom((SecureRandomSpi)engine.spi, provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new SecureRandom((SecureRandomSpi) spi, provider, algorithm);
}
/**
@@ -266,16 +258,8 @@ public class SecureRandom extends Random {
if (seed == 0) { // skip call from Random
return;
}
- byte[] byteSeed = {
- (byte)((seed >> 56) & 0xFF),
- (byte)((seed >> 48) & 0xFF),
- (byte)((seed >> 40) & 0xFF),
- (byte)((seed >> 32) & 0xFF),
- (byte)((seed >> 24) & 0xFF),
- (byte)((seed >> 16) & 0xFF),
- (byte)((seed >> 8) & 0xFF),
- (byte)((seed) & 0xFF)
- };
+ byte[] byteSeed = new byte[SizeOf.LONG];
+ OSMemory.pokeLong(byteSeed, 0, seed, ByteOrder.BIG_ENDIAN);
setSeed(byteSeed);
}
@@ -330,10 +314,12 @@ public class SecureRandom extends Random {
* @return the seed bytes
*/
public static byte[] getSeed(int numBytes) {
- if (internalSecureRandom == null) {
- internalSecureRandom = new SecureRandom();
+ SecureRandom result = internalSecureRandom;
+ if (result == null) {
+ // single-check idiom
+ internalSecureRandom = result = new SecureRandom();
}
- return internalSecureRandom.generateSeed(numBytes);
+ return result.generateSeed(numBytes);
}
/**
diff --git a/luni/src/main/java/java/security/Security.java b/luni/src/main/java/java/security/Security.java
index c420769..65b5a3e 100644
--- a/luni/src/main/java/java/security/Security.java
+++ b/luni/src/main/java/java/security/Security.java
@@ -44,7 +44,7 @@ import org.apache.harmony.security.fortress.Services;
public final class Security {
// Security properties
- private static Properties secprops = new Properties();
+ private static final Properties secprops = new Properties();
// static initialization
// - load security properties files
diff --git a/luni/src/main/java/java/security/Signature.java b/luni/src/main/java/java/security/Signature.java
index f8fb2bb..d9e1e41 100644
--- a/luni/src/main/java/java/security/Signature.java
+++ b/luni/src/main/java/java/security/Signature.java
@@ -39,7 +39,7 @@ public abstract class Signature extends SignatureSpi {
private static final String SERVICE = "Signature";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static Engine ENGINE = new Engine(SERVICE);
// The provider
private Provider provider;
@@ -101,19 +101,16 @@ public abstract class Signature extends SignatureSpi {
if (algorithm == null) {
throw new NullPointerException();
}
- Signature result;
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- if (engine.spi instanceof Signature) {
- result = (Signature) engine.spi;
- result.algorithm = algorithm;
- result.provider = engine.provider;
- } else {
- result = new SignatureImpl((SignatureSpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ Object spi = sap.spi;
+ Provider provider = sap.provider;
+ if (spi instanceof Signature) {
+ Signature result = (Signature) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
+ return result;
}
- return result;
+ return new SignatureImpl((SignatureSpi) spi, provider, algorithm);
}
/**
@@ -178,19 +175,14 @@ public abstract class Signature extends SignatureSpi {
private static Signature getSignatureInstance(String algorithm,
Provider provider) throws NoSuchAlgorithmException {
- Signature result;
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- if (engine.spi instanceof Signature) {
- result = (Signature) engine.spi;
- result.algorithm = algorithm;
- result.provider = provider;
- } else {
- result = new SignatureImpl((SignatureSpi) engine.spi, provider,
- algorithm);
- }
- }
- return result;
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ if (spi instanceof Signature) {
+ Signature result = (Signature) spi;
+ result.algorithm = algorithm;
+ result.provider = provider;
+ return result;
+ }
+ return new SignatureImpl((SignatureSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/cert/CertPathBuilder.java b/luni/src/main/java/java/security/cert/CertPathBuilder.java
index 11a38cc..c2164db 100644
--- a/luni/src/main/java/java/security/cert/CertPathBuilder.java
+++ b/luni/src/main/java/java/security/cert/CertPathBuilder.java
@@ -35,7 +35,7 @@ public class CertPathBuilder {
private static final String SERVICE = "CertPathBuilder";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store default property name
private static final String PROPERTYNAME = "certpathbuilder.type";
@@ -48,7 +48,7 @@ public class CertPathBuilder {
private final Provider provider;
// Store spi implementation
- private CertPathBuilderSpi spiImpl;
+ private final CertPathBuilderSpi spiImpl;
// Store algorithm name
private final String algorithm;
@@ -105,11 +105,8 @@ public class CertPathBuilder {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new CertPathBuilder((CertPathBuilderSpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new CertPathBuilder((CertPathBuilderSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -165,11 +162,8 @@ public class CertPathBuilder {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new CertPathBuilder((CertPathBuilderSpi) engine.spi, provider,
- algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new CertPathBuilder((CertPathBuilderSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/cert/CertPathValidator.java b/luni/src/main/java/java/security/cert/CertPathValidator.java
index b73857f..49d2408 100644
--- a/luni/src/main/java/java/security/cert/CertPathValidator.java
+++ b/luni/src/main/java/java/security/cert/CertPathValidator.java
@@ -35,7 +35,7 @@ public class CertPathValidator {
private static final String SERVICE = "CertPathValidator";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store default property name
private static final String PROPERTYNAME = "certpathvalidator.type";
@@ -104,11 +104,8 @@ public class CertPathValidator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new CertPathValidator((CertPathValidatorSpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new CertPathValidator((CertPathValidatorSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -166,11 +163,8 @@ public class CertPathValidator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new CertPathValidator((CertPathValidatorSpi) engine.spi,
- provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new CertPathValidator((CertPathValidatorSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/java/security/cert/CertStore.java b/luni/src/main/java/java/security/cert/CertStore.java
index 775236c..a8cbfee 100644
--- a/luni/src/main/java/java/security/cert/CertStore.java
+++ b/luni/src/main/java/java/security/cert/CertStore.java
@@ -37,7 +37,7 @@ public class CertStore {
private static final String SERVICE = "CertStore";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store default property name
private static final String PROPERTYNAME = "certstore.type";
@@ -101,11 +101,8 @@ public class CertStore {
throw new NullPointerException();
}
try {
- synchronized (engine) {
- engine.getInstance(type, params);
- return new CertStore((CertStoreSpi) engine.spi, engine.provider,
- type, params);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(type, params);
+ return new CertStore((CertStoreSpi) sap.spi, sap.provider, type, params);
} catch (NoSuchAlgorithmException e) {
Throwable th = e.getCause();
if (th == null) {
@@ -182,11 +179,8 @@ public class CertStore {
throw new NullPointerException();
}
try {
- synchronized (engine) {
- engine.getInstance(type, provider, params);
- return new CertStore((CertStoreSpi) engine.spi, provider, type,
- params);
- }
+ Object spi = ENGINE.getInstance(type, provider, params);
+ return new CertStore((CertStoreSpi) spi, provider, type, params);
} catch (NoSuchAlgorithmException e) {
Throwable th = e.getCause();
if (th == null) {
diff --git a/luni/src/main/java/java/security/cert/CertificateFactory.java b/luni/src/main/java/java/security/cert/CertificateFactory.java
index 6bef771..d89ee26 100644
--- a/luni/src/main/java/java/security/cert/CertificateFactory.java
+++ b/luni/src/main/java/java/security/cert/CertificateFactory.java
@@ -41,7 +41,7 @@ public class CertificateFactory {
private static final String SERVICE = "CertificateFactory";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store used provider
private final Provider provider;
@@ -87,11 +87,8 @@ public class CertificateFactory {
throw new NullPointerException();
}
try {
- synchronized (engine) {
- engine.getInstance(type, null);
- return new CertificateFactory((CertificateFactorySpi) engine.spi,
- engine.provider, type);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(type, null);
+ return new CertificateFactory((CertificateFactorySpi) sap.spi, sap.provider, type);
} catch (NoSuchAlgorithmException e) {
throw new CertificateException(e);
}
@@ -156,11 +153,8 @@ public class CertificateFactory {
throw new NullPointerException();
}
try {
- synchronized (engine) {
- engine.getInstance(type, provider, null);
- return new CertificateFactory((CertificateFactorySpi) engine.spi,
- provider, type);
- }
+ Object spi = ENGINE.getInstance(type, provider, null);
+ return new CertificateFactory((CertificateFactorySpi) spi, provider, type);
} catch (NoSuchAlgorithmException e) {
throw new CertificateException(e.getMessage());
}
diff --git a/luni/src/main/java/java/security/cert/PKIXParameters.java b/luni/src/main/java/java/security/cert/PKIXParameters.java
index 639368e..2e9d4a2 100644
--- a/luni/src/main/java/java/security/cert/PKIXParameters.java
+++ b/luni/src/main/java/java/security/cert/PKIXParameters.java
@@ -114,9 +114,9 @@ public class PKIXParameters implements CertPathParameters {
String alias = (String) i.nextElement();
if (keyStore.isCertificateEntry(alias)) {
// this is trusted certificate entry
- // check if it is X509Cerificate
+ // check if it is X509Certificate
Certificate c = keyStore.getCertificate(alias);
- // add only X509Cerificate
+ // add only X509Certificate
// ignore all other types
if (c instanceof X509Certificate) {
trustAnchors.add(new TrustAnchor((X509Certificate)c, null));
@@ -195,11 +195,9 @@ public class PKIXParameters implements CertPathParameters {
return Collections.unmodifiableList(certPathCheckers);
}
// List is not empty - do deep copy
- ArrayList<PKIXCertPathChecker> modifiableList =
- new ArrayList<PKIXCertPathChecker>();
- for (Iterator<PKIXCertPathChecker> i
- = certPathCheckers.iterator(); i.hasNext();) {
- modifiableList.add((PKIXCertPathChecker)i.next().clone());
+ ArrayList<PKIXCertPathChecker> modifiableList = new ArrayList<PKIXCertPathChecker>();
+ for (PKIXCertPathChecker certPathChecker : certPathCheckers) {
+ modifiableList.add((PKIXCertPathChecker) certPathChecker.clone());
}
return Collections.unmodifiableList(modifiableList);
}
@@ -225,9 +223,8 @@ public class PKIXParameters implements CertPathParameters {
}
// non-empty list provided - do deep copy
this.certPathCheckers = new ArrayList<PKIXCertPathChecker>();
- for (Iterator<PKIXCertPathChecker> i
- = certPathCheckers.iterator(); i.hasNext();) {
- this.certPathCheckers.add((PKIXCertPathChecker)i.next().clone());
+ for (PKIXCertPathChecker certPathChecker : certPathCheckers) {
+ this.certPathCheckers.add((PKIXCertPathChecker) certPathChecker.clone());
}
}
@@ -291,13 +288,7 @@ public class PKIXParameters implements CertPathParameters {
return;
}
// non-empty list provided - do shallow copy
- this.certStores = new ArrayList(certStores);
- // check that all elements are CertStore
- for (Iterator i = this.certStores.iterator(); i.hasNext();) {
- if (!(i.next() instanceof CertStore)) {
- throw new ClassCastException("all list elements must be of type java.security.cert.CertStore");
- }
- }
+ this.certStores = new ArrayList<CertStore>(certStores);
}
/**
@@ -314,7 +305,7 @@ public class PKIXParameters implements CertPathParameters {
}
if (certStores == null) {
// set to empty List if has not been set yet
- certStores = new ArrayList();
+ certStores = new ArrayList<CertStore>();
}
// add store
certStores.add(store);
@@ -332,7 +323,7 @@ public class PKIXParameters implements CertPathParameters {
}
/**
- * Sets the time for which the validation of the certification path sould be
+ * Sets the time for which the validation of the certification path should be
* evaluated.
*
* @param date
@@ -376,7 +367,7 @@ public class PKIXParameters implements CertPathParameters {
public Set<String> getInitialPolicies() {
if (initialPolicies == null) {
// set to empty Set if has not been set yet
- initialPolicies = new HashSet();
+ initialPolicies = new HashSet<String>();
}
if (initialPolicies.isEmpty()) {
// no content - no need to copy,
@@ -385,7 +376,7 @@ public class PKIXParameters implements CertPathParameters {
return Collections.unmodifiableSet(initialPolicies);
}
// List is not empty - do shallow copy
- HashSet modifiableSet = new HashSet(initialPolicies);
+ HashSet<String> modifiableSet = new HashSet<String>(initialPolicies);
return Collections.unmodifiableSet(modifiableSet);
}
@@ -400,21 +391,14 @@ public class PKIXParameters implements CertPathParameters {
public void setInitialPolicies(Set<String> initialPolicies) {
if (initialPolicies == null || initialPolicies.isEmpty()) {
// empty list or null provided
- if (this.initialPolicies != null &&
- !this.initialPolicies.isEmpty()) {
+ if (this.initialPolicies != null && !this.initialPolicies.isEmpty()) {
// discard non-empty list
this.initialPolicies = null;
}
return;
}
// non-empty list provided - do shallow copy
- this.initialPolicies = new HashSet(initialPolicies);
- // check that all elements are String
- for (Iterator i = this.initialPolicies.iterator(); i.hasNext();) {
- if (!(i.next() instanceof String)) {
- throw new ClassCastException("all set elements must be of type java.lang.String");
- }
- }
+ this.initialPolicies = new HashSet<String>(initialPolicies);
}
/**
@@ -543,10 +527,10 @@ public class PKIXParameters implements CertPathParameters {
PKIXParameters ret = (PKIXParameters)super.clone();
// copy fields containing references to mutable objects
if (this.certStores != null) {
- ret.certStores = new ArrayList(this.certStores);
+ ret.certStores = new ArrayList<CertStore>(this.certStores);
}
if (this.certPathCheckers != null) {
- ret.certPathCheckers = new ArrayList(this.certPathCheckers);
+ ret.certPathCheckers = new ArrayList<PKIXCertPathChecker>(this.certPathCheckers);
}
return ret;
} catch (CloneNotSupportedException e) {
@@ -601,15 +585,9 @@ public class PKIXParameters implements CertPathParameters {
// only TrustAnchor instances.
// Throws InvalidAlgorithmParameterException if trustAnchors set is empty.
//
- private void checkTrustAnchors(Set trustAnchors)
- throws InvalidAlgorithmParameterException {
+ private void checkTrustAnchors(Set<TrustAnchor> trustAnchors) throws InvalidAlgorithmParameterException {
if (trustAnchors.isEmpty()) {
throw new InvalidAlgorithmParameterException("trustAnchors.isEmpty()");
}
- for (Iterator i = trustAnchors.iterator(); i.hasNext();) {
- if (!(i.next() instanceof TrustAnchor)) {
- throw new ClassCastException("all set elements must be of type java.security.cert.TrustAnchor");
- }
- }
}
}
diff --git a/luni/src/main/java/java/security/cert/X509CertSelector.java b/luni/src/main/java/java/security/cert/X509CertSelector.java
index 8745bf2..144e213 100644
--- a/luni/src/main/java/java/security/cert/X509CertSelector.java
+++ b/luni/src/main/java/java/security/cert/X509CertSelector.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import javax.security.auth.x500.X500Principal;
+import libcore.base.EmptyArray;
import org.apache.harmony.security.asn1.ASN1OctetString;
import org.apache.harmony.security.x509.AlgorithmIdentifier;
import org.apache.harmony.security.x509.CertificatePolicies;
@@ -65,7 +66,7 @@ public class X509CertSelector implements CertSelector {
private int pathLen = -1;
private List[] subjectAltNames;
private NameConstraints nameConstraints;
- private Set policies;
+ private Set<String> policies;
private ArrayList pathToNames;
// needed to avoid needless encoding/decoding work
@@ -875,10 +876,10 @@ public class X509CertSelector implements CertSelector {
this.policies = null;
return;
}
- HashSet pols = new HashSet(policies.size());
- Iterator it = policies.iterator();
+ HashSet<String> pols = new HashSet<String>(policies.size());
+ Iterator<String> it = policies.iterator();
while (it.hasNext()) {
- String certPolicyId = (String) it.next();
+ String certPolicyId = it.next();
checkOID(certPolicyId);
pols.add(certPolicyId);
}
@@ -917,8 +918,7 @@ public class X509CertSelector implements CertSelector {
* @throws IOException
* if decoding fails.
*/
- public void setPathToNames(Collection<List<?>> names)
- throws IOException {
+ public void setPathToNames(Collection<List<?>> names) throws IOException {
pathToNames = null;
if ((names == null) || (names.size() == 0)) {
return;
@@ -1281,8 +1281,7 @@ public class X509CertSelector implements CertSelector {
// initialize the check map
for (int i=0; i<9; i++) {
map[i] = (subjectAltNames[i] == null)
- ? new boolean[0]
- : new boolean[subjectAltNames[i].size()];
+ ? EmptyArray.BOOLEAN : new boolean[subjectAltNames[i].size()];
}
Iterator it = sans.iterator();
while (it.hasNext()) {
@@ -1417,9 +1416,7 @@ public class X509CertSelector implements CertSelector {
}
}
}
- result.policies = (this.policies == null)
- ? null
- : new HashSet(this.policies);
+ result.policies = (this.policies == null) ? null : new HashSet<String>(this.policies);
result.pathToNames = (this.pathToNames == null)
? null
: new ArrayList(this.pathToNames);
diff --git a/luni/src/main/java/java/security/security.properties b/luni/src/main/java/java/security/security.properties
index 4e69e99..d7a4890 100644
--- a/luni/src/main/java/java/security/security.properties
+++ b/luni/src/main/java/java/security/security.properties
@@ -26,7 +26,7 @@ security.provider.1=org.apache.harmony.xnet.provider.jsse.OpenSSLProvider
# Favor Harmony's CertificateFactory.X509 over BouncyCastle's
security.provider.2=org.apache.harmony.security.provider.cert.DRLCertFactory
# Android's stripped down BouncyCastle provider
-security.provider.3=org.bouncycastle.jce.provider.BouncyCastleProvider
+security.provider.3=com.android.org.bouncycastle.jce.provider.BouncyCastleProvider
# Remaining Harmony providers
security.provider.4=org.apache.harmony.security.provider.crypto.CryptoProvider
security.provider.5=org.apache.harmony.xnet.provider.jsse.JSSEProvider
diff --git a/luni/src/main/java/java/sql/DriverManager.java b/luni/src/main/java/java/sql/DriverManager.java
index d670562..77fe43f 100644
--- a/luni/src/main/java/java/sql/DriverManager.java
+++ b/luni/src/main/java/java/sql/DriverManager.java
@@ -202,13 +202,13 @@ public class DriverManager {
* if there is an error while attempting to connect to the
* database identified by the URL.
*/
- public static Connection getConnection(String url, String user,
- String password) throws SQLException {
+ public static Connection getConnection(String url, String user, String password)
+ throws SQLException {
Properties theProperties = new Properties();
- if (null != user) {
+ if (user != null) {
theProperties.setProperty("user", user);
}
- if (null != password) {
+ if (password != null) {
theProperties.setProperty("password", password);
}
return getConnection(url, theProperties);
diff --git a/luni/src/main/java/java/sql/Timestamp.java b/luni/src/main/java/java/sql/Timestamp.java
index 23cbea5..463ea8b 100644
--- a/luni/src/main/java/java/sql/Timestamp.java
+++ b/luni/src/main/java/java/sql/Timestamp.java
@@ -469,7 +469,7 @@ public class Timestamp extends Date {
// Require the next character to be a "."
if (s.charAt(position) != '.') {
throw new NumberFormatException("Bad input string format: expected '.' not '" +
- s.charAt(position) + "'");
+ s.charAt(position) + "' in \"" + s + "\"");
}
// Get the length of the number string - need to account for the '.'
int nanoLength = s.length() - position - 1;
diff --git a/luni/src/main/java/java/text/AttributedCharacterIterator.java b/luni/src/main/java/java/text/AttributedCharacterIterator.java
index b2533ec..2ab8e6a 100644
--- a/luni/src/main/java/java/text/AttributedCharacterIterator.java
+++ b/luni/src/main/java/java/text/AttributedCharacterIterator.java
@@ -19,6 +19,8 @@ package java.text;
import java.io.InvalidObjectException;
import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.Set;
@@ -119,20 +121,23 @@ public interface AttributedCharacterIterator extends CharacterIterator {
* or if it is not a known {@code Attribute}.
*/
protected Object readResolve() throws InvalidObjectException {
- if (this.getClass() != Attribute.class) {
- throw new InvalidObjectException("cannot resolve subclasses");
+ /*
+ * This class is used like Java enums, where all instances are
+ * defined as fields of their own class. To preserve identity
+ * equality, resolve to the canonical instance when deserialized.
+ */
+ try {
+ for (Field field : getClass().getFields()) {
+ if (field.getType() == getClass() && Modifier.isStatic(field.getModifiers())) {
+ Attribute candidate = (Attribute) field.get(null);
+ if (name.equals(candidate.name)) {
+ return candidate;
+ }
+ }
+ }
+ } catch (IllegalAccessException e) {
}
- String name = this.getName();
- if (name.equals(INPUT_METHOD_SEGMENT.getName())) {
- return INPUT_METHOD_SEGMENT;
- }
- if (name.equals(LANGUAGE.getName())) {
- return LANGUAGE;
- }
- if (name.equals(READING.getName())) {
- return READING;
- }
- throw new InvalidObjectException("Unknown attribute");
+ throw new InvalidObjectException("Failed to resolve " + this);
}
/**
diff --git a/luni/src/main/java/java/text/AttributedString.java b/luni/src/main/java/java/text/AttributedString.java
index 58839dd..1495dc5 100644
--- a/luni/src/main/java/java/text/AttributedString.java
+++ b/luni/src/main/java/java/text/AttributedString.java
@@ -579,9 +579,8 @@ public class AttributedString {
* @throws NullPointerException
* if {@code attribute} is {@code null}.
*/
- public void addAttribute(AttributedCharacterIterator.Attribute attribute,
- Object value) {
- if (null == attribute) {
+ public void addAttribute(AttributedCharacterIterator.Attribute attribute, Object value) {
+ if (attribute == null) {
throw new NullPointerException();
}
if (text.length() == 0) {
@@ -618,7 +617,7 @@ public class AttributedString {
*/
public void addAttribute(AttributedCharacterIterator.Attribute attribute,
Object value, int start, int end) {
- if (null == attribute) {
+ if (attribute == null) {
throw new NullPointerException();
}
if (start < 0 || end > text.length() || start >= end) {
diff --git a/luni/src/main/java/java/text/BreakIterator.java b/luni/src/main/java/java/text/BreakIterator.java
index 09fbc3b..ccc484c 100644
--- a/luni/src/main/java/java/text/BreakIterator.java
+++ b/luni/src/main/java/java/text/BreakIterator.java
@@ -17,9 +17,9 @@
package java.text;
-import com.ibm.icu4jni.text.NativeBreakIterator;
-import com.ibm.icu4jni.util.ICU;
import java.util.Locale;
+import libcore.icu.ICU;
+import libcore.icu.NativeBreakIterator;
/**
* Locates boundaries in text. This class defines a protocol for objects that
diff --git a/luni/src/main/java/java/text/ChoiceFormat.java b/luni/src/main/java/java/text/ChoiceFormat.java
index 4d689df..b594efc 100644
--- a/luni/src/main/java/java/text/ChoiceFormat.java
+++ b/luni/src/main/java/java/text/ChoiceFormat.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
+import libcore.base.EmptyArray;
/**
* Returns a fixed string based on a numeric value. The class can be used in
@@ -147,8 +148,8 @@ public class ChoiceFormat extends NumberFormat {
index = skipWhitespace(template, position.getIndex());
if (position.getErrorIndex() != -1 || index >= length) {
// Fix Harmony 540
- choiceLimits = new double[0];
- choiceFormats = new String[0];
+ choiceLimits = EmptyArray.DOUBLE;
+ choiceFormats = EmptyArray.STRING;
return;
}
char ch = template.charAt(index++);
diff --git a/luni/src/main/java/java/text/CollationElementIterator.java b/luni/src/main/java/java/text/CollationElementIterator.java
index 0bdef23..5da3b65 100644
--- a/luni/src/main/java/java/text/CollationElementIterator.java
+++ b/luni/src/main/java/java/text/CollationElementIterator.java
@@ -17,6 +17,8 @@
package java.text;
+import libcore.icu.CollationElementIteratorICU;
+
/**
* Created by a {@code RuleBasedCollator} to iterate through a string. The
* result of each iteration is a 32-bit collation element that defines the
@@ -52,9 +54,9 @@ public final class CollationElementIterator {
*/
public static final int NULLORDER = -1;
- private com.ibm.icu4jni.text.CollationElementIterator icuIterator;
+ private CollationElementIteratorICU icuIterator;
- CollationElementIterator(com.ibm.icu4jni.text.CollationElementIterator iterator) {
+ CollationElementIterator(CollationElementIteratorICU iterator) {
this.icuIterator = iterator;
}
@@ -130,7 +132,7 @@ public final class CollationElementIterator {
* @return the element's 16 bit primary order.
*/
public static final int primaryOrder(int order) {
- return com.ibm.icu4jni.text.CollationElementIterator.primaryOrder(order);
+ return CollationElementIteratorICU.primaryOrder(order);
}
/**
@@ -155,8 +157,7 @@ public final class CollationElementIterator {
* @return the 8 bit secondary order of the element.
*/
public static final short secondaryOrder(int order) {
- return (short) com.ibm.icu4jni.text.CollationElementIterator
- .secondaryOrder(order);
+ return (short) CollationElementIteratorICU.secondaryOrder(order);
}
/**
@@ -216,7 +217,6 @@ public final class CollationElementIterator {
* @return the 8 bit tertiary order of the element.
*/
public static final short tertiaryOrder(int order) {
- return (short) com.ibm.icu4jni.text.CollationElementIterator
- .tertiaryOrder(order);
+ return (short) CollationElementIteratorICU.tertiaryOrder(order);
}
}
diff --git a/luni/src/main/java/java/text/Collator.java b/luni/src/main/java/java/text/Collator.java
index 827031a..689fcb7 100644
--- a/luni/src/main/java/java/text/Collator.java
+++ b/luni/src/main/java/java/text/Collator.java
@@ -17,9 +17,10 @@
package java.text;
-import com.ibm.icu4jni.util.ICU;
import java.util.Comparator;
import java.util.Locale;
+import libcore.icu.ICU;
+import libcore.icu.RuleBasedCollatorICU;
/**
* Performs locale-sensitive string comparison. A concrete subclass,
@@ -144,21 +145,17 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
*/
public static final int IDENTICAL = 3;
- // Wrapper class of ICU4JNI Collator
- com.ibm.icu4jni.text.Collator icuColl;
+ RuleBasedCollatorICU icuColl;
- Collator(com.ibm.icu4jni.text.Collator wrapper) {
- this.icuColl = wrapper;
+ Collator(RuleBasedCollatorICU icuColl) {
+ this.icuColl = icuColl;
}
/**
* Constructs a new {@code Collator} instance.
*/
protected Collator() {
- super();
- // BEGIN android-added
- icuColl = com.ibm.icu4jni.text.Collator.getInstance(Locale.getDefault());
- // END android-added
+ icuColl = new RuleBasedCollatorICU(Locale.getDefault());
}
/**
@@ -172,7 +169,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
public Object clone() {
try {
Collator clone = (Collator) super.clone();
- clone.icuColl = (com.ibm.icu4jni.text.Collator) this.icuColl.clone();
+ clone.icuColl = (RuleBasedCollatorICU) icuColl.clone();
return clone;
} catch (CloneNotSupportedException e) {
throw new AssertionError(e); // android-changed
@@ -227,8 +224,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
return false;
}
Collator collator = (Collator) object;
- return this.icuColl == null ? collator.icuColl == null : this.icuColl
- .equals(collator.icuColl);
+ return icuColl == null ? collator.icuColl == null : icuColl.equals(collator.icuColl);
}
/**
@@ -273,7 +269,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
* not supported.
*/
public int getDecomposition() {
- return decompositionMode_ICU_Java(this.icuColl.getDecomposition());
+ return decompositionMode_ICU_Java(icuColl.getDecomposition());
}
/**
@@ -292,7 +288,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
if (locale == null) {
throw new NullPointerException();
}
- return new RuleBasedCollator(com.ibm.icu4jni.text.Collator.getInstance(locale));
+ return new RuleBasedCollator(new RuleBasedCollatorICU(locale));
}
/**
@@ -302,7 +298,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
* IDENTICAL.
*/
public int getStrength() {
- return strength_ICU_Java(this.icuColl.getStrength());
+ return strength_ICU_Java(icuColl.getStrength());
}
@Override
@@ -320,7 +316,7 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
* {@code FULL_DECOMPOSITION}.
*/
public void setDecomposition(int value) {
- this.icuColl.setDecomposition(decompositionMode_Java_ICU(value));
+ icuColl.setDecomposition(decompositionMode_Java_ICU(value));
}
/**
@@ -333,15 +329,15 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
* if the provided strength value is not valid.
*/
public void setStrength(int value) {
- this.icuColl.setStrength(strength_Java_ICU(value));
+ icuColl.setStrength(strength_Java_ICU(value));
}
private int decompositionMode_Java_ICU(int mode) {
switch (mode) {
case Collator.CANONICAL_DECOMPOSITION:
- return com.ibm.icu4jni.text.Collator.CANONICAL_DECOMPOSITION;
+ return RuleBasedCollatorICU.VALUE_ON;
case Collator.NO_DECOMPOSITION:
- return com.ibm.icu4jni.text.Collator.NO_DECOMPOSITION;
+ return RuleBasedCollatorICU.VALUE_OFF;
}
throw new IllegalArgumentException();
}
@@ -349,12 +345,12 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
private int decompositionMode_ICU_Java(int mode) {
int javaMode = mode;
switch (mode) {
- case com.ibm.icu4jni.text.Collator.NO_DECOMPOSITION:
- javaMode = Collator.NO_DECOMPOSITION;
- break;
- case com.ibm.icu4jni.text.Collator.CANONICAL_DECOMPOSITION:
- javaMode = Collator.CANONICAL_DECOMPOSITION;
- break;
+ case RuleBasedCollatorICU.VALUE_OFF:
+ javaMode = Collator.NO_DECOMPOSITION;
+ break;
+ case RuleBasedCollatorICU.VALUE_ON:
+ javaMode = Collator.CANONICAL_DECOMPOSITION;
+ break;
}
return javaMode;
}
@@ -362,13 +358,13 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
private int strength_Java_ICU(int value) {
switch (value) {
case Collator.PRIMARY:
- return com.ibm.icu4jni.text.Collator.PRIMARY;
+ return RuleBasedCollatorICU.VALUE_PRIMARY;
case Collator.SECONDARY:
- return com.ibm.icu4jni.text.Collator.SECONDARY;
+ return RuleBasedCollatorICU.VALUE_SECONDARY;
case Collator.TERTIARY:
- return com.ibm.icu4jni.text.Collator.TERTIARY;
+ return RuleBasedCollatorICU.VALUE_TERTIARY;
case Collator.IDENTICAL:
- return com.ibm.icu4jni.text.Collator.IDENTICAL;
+ return RuleBasedCollatorICU.VALUE_IDENTICAL;
}
throw new IllegalArgumentException();
}
@@ -376,18 +372,18 @@ public abstract class Collator implements Comparator<Object>, Cloneable {
private int strength_ICU_Java(int value) {
int javaValue = value;
switch (value) {
- case com.ibm.icu4jni.text.Collator.PRIMARY:
- javaValue = Collator.PRIMARY;
- break;
- case com.ibm.icu4jni.text.Collator.SECONDARY:
- javaValue = Collator.SECONDARY;
- break;
- case com.ibm.icu4jni.text.Collator.TERTIARY:
- javaValue = Collator.TERTIARY;
- break;
- case com.ibm.icu4jni.text.Collator.IDENTICAL:
- javaValue = Collator.IDENTICAL;
- break;
+ case RuleBasedCollatorICU.VALUE_PRIMARY:
+ javaValue = Collator.PRIMARY;
+ break;
+ case RuleBasedCollatorICU.VALUE_SECONDARY:
+ javaValue = Collator.SECONDARY;
+ break;
+ case RuleBasedCollatorICU.VALUE_TERTIARY:
+ javaValue = Collator.TERTIARY;
+ break;
+ case RuleBasedCollatorICU.VALUE_IDENTICAL:
+ javaValue = Collator.IDENTICAL;
+ break;
}
return javaValue;
}
diff --git a/luni/src/main/java/java/text/DateFormat.java b/luni/src/main/java/java/text/DateFormat.java
index 45ee0c7..53480e6 100644
--- a/luni/src/main/java/java/text/DateFormat.java
+++ b/luni/src/main/java/java/text/DateFormat.java
@@ -17,14 +17,14 @@
package java.text;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.InvalidObjectException;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Locale;
import java.util.TimeZone;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
/**
* An abstract class for date/time formatting subclasses which formats and
@@ -883,43 +883,6 @@ public abstract class DateFormat extends Format {
return table.get(Integer.valueOf(calendarField));
}
-
- /**
- * Resolves instances that are deserialized to the constant
- * {@code DateFormat.Field} values.
- *
- * @return the resolved field object.
- * @throws InvalidObjectException
- * if an error occurs while resolving the field object.
- */
- @Override
- protected Object readResolve() throws InvalidObjectException {
- if (this.getClass() != Field.class) {
- throw new InvalidObjectException("cannot resolve subclasses");
- }
- if (calendarField != -1) {
- try {
- Field result = ofCalendarField(calendarField);
-
- if (result != null && this.getName().equals(result.getName())) {
- return result;
- }
- } catch (IllegalArgumentException e) {
- throw new InvalidObjectException("Unknown attribute");
- }
- } else {
- if (this.equals(TIME_ZONE)) {
- return TIME_ZONE;
- }
- if (this.equals(HOUR1)) {
- return HOUR1;
- }
- if (this.equals(HOUR_OF_DAY1)) {
- return HOUR_OF_DAY1;
- }
- }
- throw new InvalidObjectException("Unknown attribute");
- }
}
private static void checkDateStyle(int style) {
diff --git a/luni/src/main/java/java/text/DateFormatSymbols.java b/luni/src/main/java/java/text/DateFormatSymbols.java
index 07544c7..73c818e 100644
--- a/luni/src/main/java/java/text/DateFormatSymbols.java
+++ b/luni/src/main/java/java/text/DateFormatSymbols.java
@@ -17,14 +17,14 @@
package java.text;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Locale;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
import libcore.icu.TimeZones;
/**
diff --git a/luni/src/main/java/java/text/DecimalFormat.java b/luni/src/main/java/java/text/DecimalFormat.java
index cdc064f..b2b5d6a 100644
--- a/luni/src/main/java/java/text/DecimalFormat.java
+++ b/luni/src/main/java/java/text/DecimalFormat.java
@@ -17,8 +17,6 @@
package java.text;
-import com.ibm.icu4jni.text.NativeDecimalFormat;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -28,6 +26,8 @@ import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Currency;
import java.util.Locale;
+import libcore.icu.LocaleData;
+import libcore.icu.NativeDecimalFormat;
/**
* A concrete subclass of {@link NumberFormat} that formats decimal numbers. It
@@ -163,13 +163,13 @@ import java.util.Locale;
* <td>Multiply by 100 and show as percentage.</td>
* </tr>
* <tr valign="top" bgcolor="#eeeeff">
- * <td>{@code \u2030} ({@code &#92;u2030})</td>
+ * <td>{@code \u2030} ({@code \u005Cu2030})</td>
* <td>Prefix or suffix</td>
* <td>Yes</td>
* <td>Multiply by 1000 and show as per mille.</td>
* </tr>
* <tr valign="top">
- * <td>{@code &#164;} ({@code &#92;u00A4})</td>
+ * <td>{@code \u00A4} ({@code \u005Cu00A4})</td>
* <td>Prefix or suffix</td>
* <td>No</td>
* <td>Currency sign, replaced by currency symbol. If doubled, replaced by
@@ -319,11 +319,11 @@ import java.util.Locale;
* <strong>Special Values</strong>
* <p>
* {@code NaN} is represented as a single character, typically
- * {@code &#92;uFFFD}. This character is determined by the
+ * {@code \u005cuFFFD}. This character is determined by the
* {@link DecimalFormatSymbols} object. This is the only value for which the
* prefixes and suffixes are not used.
* <p>
- * Infinity is represented as a single character, typically {@code &#92;u221E},
+ * Infinity is represented as a single character, typically {@code \u005cu221E},
* with the positive or negative prefixes and suffixes applied. The infinity
* character is determined by the {@link DecimalFormatSymbols} object. <a
* name="sci">
@@ -881,7 +881,7 @@ public class DecimalFormat extends NumberFormat {
@Override
public Number parse(String string, ParsePosition position) {
Number number = dform.parse(string, position);
- if (null == number) {
+ if (number == null) {
return null;
}
// BEGIN android-removed
@@ -1117,7 +1117,7 @@ public class DecimalFormat extends NumberFormat {
}
/**
- * Sets the behaviour of the parse method. If set to {@code true} then all
+ * Sets the behavior of the parse method. If set to {@code true} then all
* the returned objects will be of type {@code BigDecimal}.
*
* @param newValue
diff --git a/luni/src/main/java/java/text/DecimalFormatSymbols.java b/luni/src/main/java/java/text/DecimalFormatSymbols.java
index bc761e4..e8c1c0c 100644
--- a/luni/src/main/java/java/text/DecimalFormatSymbols.java
+++ b/luni/src/main/java/java/text/DecimalFormatSymbols.java
@@ -17,8 +17,6 @@
package java.text;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -26,6 +24,8 @@ import java.io.ObjectStreamField;
import java.io.Serializable;
import java.util.Currency;
import java.util.Locale;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
/**
* Encapsulates the set of symbols (such as the decimal separator, the grouping
diff --git a/luni/src/main/java/java/text/MessageFormat.java b/luni/src/main/java/java/text/MessageFormat.java
index 824ddb8..5abc9c8 100644
--- a/luni/src/main/java/java/text/MessageFormat.java
+++ b/luni/src/main/java/java/text/MessageFormat.java
@@ -27,6 +27,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
import java.util.Vector;
+import libcore.base.EmptyArray;
import libcore.base.Objects;
/**
@@ -866,7 +867,7 @@ public class MessageFormat extends Format {
*/
public Object[] parse(String string, ParsePosition position) {
if (string == null) {
- return new Object[0];
+ return EmptyArray.OBJECT;
}
ParsePosition internalPos = new ParsePosition(0);
int offset = position.getIndex();
@@ -1322,22 +1323,5 @@ public class MessageFormat extends Format {
protected Field(String fieldName) {
super(fieldName);
}
-
- /**
- * Resolves instances that are deserialized to the constant
- * {@code MessageFormat.Field} values.
- *
- * @return the resolved field object.
- * @throws InvalidObjectException
- * if an error occurs while resolving the field object.
- */
- @Override
- protected Object readResolve() throws InvalidObjectException {
- String name = this.getName();
- if (Objects.equal(name, ARGUMENT.getName())) {
- return ARGUMENT;
- }
- throw new InvalidObjectException("Not a valid MessageFormat.Field, subclass should override readResolve()");
- }
}
}
diff --git a/luni/src/main/java/java/text/NumberFormat.java b/luni/src/main/java/java/text/NumberFormat.java
index a808169..dd38a65 100644
--- a/luni/src/main/java/java/text/NumberFormat.java
+++ b/luni/src/main/java/java/text/NumberFormat.java
@@ -17,8 +17,6 @@
package java.text;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
@@ -28,6 +26,8 @@ import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Currency;
import java.util.Locale;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
/**
* The abstract base class for all number formats. This class provides the
@@ -821,52 +821,6 @@ public abstract class NumberFormat extends Format {
protected Field(String fieldName) {
super(fieldName);
}
-
- /**
- * Resolves instances that are deserialized to the constant
- * {@code NumberFormat.Field} values.
- *
- * @return the resolved field object.
- * @throws InvalidObjectException
- * if an error occurs while resolving the field object.
- */
- @Override
- protected Object readResolve() throws InvalidObjectException {
- if (this.equals(INTEGER)) {
- return INTEGER;
- }
- if (this.equals(FRACTION)) {
- return FRACTION;
- }
- if (this.equals(EXPONENT)) {
- return EXPONENT;
- }
- if (this.equals(EXPONENT_SIGN)) {
- return EXPONENT_SIGN;
- }
- if (this.equals(EXPONENT_SYMBOL)) {
- return EXPONENT_SYMBOL;
- }
- if (this.equals(CURRENCY)) {
- return CURRENCY;
- }
- if (this.equals(DECIMAL_SEPARATOR)) {
- return DECIMAL_SEPARATOR;
- }
- if (this.equals(GROUPING_SEPARATOR)) {
- return GROUPING_SEPARATOR;
- }
- if (this.equals(PERCENT)) {
- return PERCENT;
- }
- if (this.equals(PERMILLE)) {
- return PERMILLE;
- }
- if (this.equals(SIGN)) {
- return SIGN;
- }
- throw new InvalidObjectException("Unknown attribute");
- }
}
/**
diff --git a/luni/src/main/java/java/text/RuleBasedBreakIterator.java b/luni/src/main/java/java/text/RuleBasedBreakIterator.java
index 7202cb6..15b5b12 100644
--- a/luni/src/main/java/java/text/RuleBasedBreakIterator.java
+++ b/luni/src/main/java/java/text/RuleBasedBreakIterator.java
@@ -17,50 +17,29 @@
package java.text;
-import com.ibm.icu4jni.text.NativeBreakIterator;
+import libcore.icu.NativeBreakIterator;
/*
- * Default implementation of BreakIterator. Wraps com.ibm.icu4jni.text.NativeBreakIterator.
+ * Default implementation of BreakIterator. Wraps libcore.icu.NativeBreakIterator.
* We need this because BreakIterator.isBoundary and BreakIterator.preceding are non-abstract,
* and we don't have Java implementations of those methods (other than the current ones, which
* forward to the wrapped NativeBreakIterator).
*/
class RuleBasedBreakIterator extends BreakIterator {
- /*
- * Wrapping constructor.
- */
RuleBasedBreakIterator(NativeBreakIterator iterator) {
super(iterator);
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#current()
- */
- @Override
- public int current() {
+ @Override public int current() {
return wrapped.current();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#first()
- */
- @Override
- public int first() {
+ @Override public int first() {
return wrapped.first();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#following(int)
- */
- @Override
- public int following(int offset) {
+ @Override public int following(int offset) {
validateOffset(offset);
return wrapped.following(offset);
}
@@ -75,130 +54,58 @@ class RuleBasedBreakIterator extends BreakIterator {
}
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#getText()
- */
- @Override
- public CharacterIterator getText() {
+ @Override public CharacterIterator getText() {
return wrapped.getText();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#last()
- */
- @Override
- public int last() {
+ @Override public int last() {
return wrapped.last();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#next()
- */
- @Override
- public int next() {
+ @Override public int next() {
return wrapped.next();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#next(int)
- */
- @Override
- public int next(int n) {
+ @Override public int next(int n) {
return wrapped.next(n);
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#previous()
- */
- @Override
- public int previous() {
+ @Override public int previous() {
return wrapped.previous();
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#setText(java.text.CharacterIterator)
- */
- @Override
- public void setText(CharacterIterator newText) {
+ @Override public void setText(CharacterIterator newText) {
// call a method to check if null pointer
newText.current();
wrapped.setText(newText);
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#isBoundary(int)
- */
- @Override
- public boolean isBoundary(int offset) {
+ @Override public boolean isBoundary(int offset) {
validateOffset(offset);
return wrapped.isBoundary(offset);
}
- /*
- * (non-Javadoc)
- *
- * @see java.text.BreakIterator#preceding(int)
- */
- @Override
- public int preceding(int offset) {
+ @Override public int preceding(int offset) {
validateOffset(offset);
return wrapped.preceding(offset);
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object o) {
+ @Override public boolean equals(Object o) {
if (!(o instanceof RuleBasedBreakIterator)) {
return false;
}
return wrapped.equals(((RuleBasedBreakIterator) o).wrapped);
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
+ @Override public String toString() {
return wrapped.toString();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
+ @Override public int hashCode() {
return wrapped.hashCode();
}
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#clone()
- */
- @Override
- public Object clone() {
+ @Override public Object clone() {
RuleBasedBreakIterator cloned = (RuleBasedBreakIterator) super.clone();
cloned.wrapped = (NativeBreakIterator) wrapped.clone();
return cloned;
diff --git a/luni/src/main/java/java/text/RuleBasedCollator.java b/luni/src/main/java/java/text/RuleBasedCollator.java
index 9e638c9..4fd8650 100644
--- a/luni/src/main/java/java/text/RuleBasedCollator.java
+++ b/luni/src/main/java/java/text/RuleBasedCollator.java
@@ -17,6 +17,8 @@
package java.text;
+import libcore.icu.RuleBasedCollatorICU;
+
/**
* A concrete implementation class for {@code Collation}.
* <p>
@@ -257,8 +259,7 @@ package java.text;
* </blockquote>
*/
public class RuleBasedCollator extends Collator {
-
- RuleBasedCollator(com.ibm.icu4jni.text.Collator wrapper) {
+ RuleBasedCollator(RuleBasedCollatorICU wrapper) {
super(wrapper);
}
@@ -289,8 +290,7 @@ public class RuleBasedCollator extends Collator {
throw new ParseException("empty rules", 0);
}
try {
- this.icuColl = new com.ibm.icu4jni.text.RuleBasedCollator(rules);
- this.icuColl.setDecomposition(com.ibm.icu4jni.text.Collator.CANONICAL_DECOMPOSITION);
+ icuColl = new RuleBasedCollatorICU(rules);
} catch (Exception e) {
if (e instanceof ParseException) {
throw (ParseException) e;
@@ -316,9 +316,7 @@ public class RuleBasedCollator extends Collator {
if (source == null) {
throw new NullPointerException();
}
- return new CollationElementIterator(
- ((com.ibm.icu4jni.text.RuleBasedCollator) this.icuColl)
- .getCollationElementIterator(source));
+ return new CollationElementIterator(icuColl.getCollationElementIterator(source));
}
/**
@@ -332,9 +330,7 @@ public class RuleBasedCollator extends Collator {
if (source == null) {
throw new NullPointerException();
}
- return new CollationElementIterator(
- ((com.ibm.icu4jni.text.RuleBasedCollator) this.icuColl)
- .getCollationElementIterator(source));
+ return new CollationElementIterator(icuColl.getCollationElementIterator(source));
}
/**
@@ -350,7 +346,7 @@ public class RuleBasedCollator extends Collator {
* @return the collation rules.
*/
public String getRules() {
- return ((com.ibm.icu4jni.text.RuleBasedCollator) this.icuColl).getRules();
+ return icuColl.getRules();
}
/**
@@ -392,7 +388,7 @@ public class RuleBasedCollator extends Collator {
if (source == null || target == null) {
throw new NullPointerException();
}
- return this.icuColl.compare(source, target);
+ return icuColl.compare(source, target);
}
/**
@@ -409,7 +405,7 @@ public class RuleBasedCollator extends Collator {
@Override
public int hashCode() {
- return ((com.ibm.icu4jni.text.RuleBasedCollator) this.icuColl).getRules().hashCode();
+ return icuColl.getRules().hashCode();
}
/**
diff --git a/luni/src/main/java/java/text/SimpleDateFormat.java b/luni/src/main/java/java/text/SimpleDateFormat.java
index e1ff700..6b386f0 100644
--- a/luni/src/main/java/java/text/SimpleDateFormat.java
+++ b/luni/src/main/java/java/text/SimpleDateFormat.java
@@ -17,7 +17,6 @@
package java.text;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
@@ -29,6 +28,7 @@ import java.util.Locale;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.Vector;
+import libcore.icu.LocaleData;
import libcore.icu.TimeZones;
/**
diff --git a/luni/src/main/java/java/util/AbstractList.java b/luni/src/main/java/java/util/AbstractList.java
index 8f1e79f..fe83125 100644
--- a/luni/src/main/java/java/util/AbstractList.java
+++ b/luni/src/main/java/java/util/AbstractList.java
@@ -91,7 +91,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
ListIterator<E> {
FullListIterator(int start) {
super();
- if (0 <= start && start <= size()) {
+ if (start >= 0 && start <= size()) {
pos = start - 1;
} else {
throw new IndexOutOfBoundsException();
@@ -249,7 +249,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public void add(int location, E object) {
if (modCount == fullList.modCount) {
- if (0 <= location && location <= size) {
+ if (location >= 0 && location <= size) {
fullList.add(location + offset, object);
size++;
modCount = fullList.modCount;
@@ -264,7 +264,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public boolean addAll(int location, Collection<? extends E> collection) {
if (modCount == fullList.modCount) {
- if (0 <= location && location <= size) {
+ if (location >= 0 && location <= size) {
boolean result = fullList.addAll(location + offset,
collection);
if (result) {
@@ -294,7 +294,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public E get(int location) {
if (modCount == fullList.modCount) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
return fullList.get(location + offset);
}
throw new IndexOutOfBoundsException();
@@ -310,7 +310,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public ListIterator<E> listIterator(int location) {
if (modCount == fullList.modCount) {
- if (0 <= location && location <= size) {
+ if (location >= 0 && location <= size) {
return new SubAbstractListIterator<E>(fullList
.listIterator(location + offset), this, offset,
size);
@@ -323,7 +323,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public E remove(int location) {
if (modCount == fullList.modCount) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
E result = fullList.remove(location + offset);
size--;
modCount = fullList.modCount;
@@ -350,7 +350,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
@Override
public E set(int location, E object) {
if (modCount == fullList.modCount) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
return fullList.set(location + offset, object);
}
throw new IndexOutOfBoundsException();
@@ -733,7 +733,7 @@ public abstract class AbstractList<E> extends AbstractCollection<E> implements
* if (start > end)
*/
public List<E> subList(int start, int end) {
- if (0 <= start && end <= size()) {
+ if (start >= 0 && end <= size()) {
if (start <= end) {
if (this instanceof RandomAccess) {
return new SubAbstractListRandomAccess<E>(this, start, end);
diff --git a/luni/src/main/java/java/util/AbstractQueue.java b/luni/src/main/java/java/util/AbstractQueue.java
index 8ec69f9..d368ac9 100644
--- a/luni/src/main/java/java/util/AbstractQueue.java
+++ b/luni/src/main/java/java/util/AbstractQueue.java
@@ -1,127 +1,163 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
*/
package java.util;
+// BEGIN android-note
+// removed link to collections framework docs
+// END android-note
+
/**
- * AbstractQueue is an abstract class which implements some of the methods in
- * {@link Queue}. The provided implementations of {@code add, remove} and
- * {@code element} are based on {@code offer, poll}, and {@code peek} except
- * that they throw exceptions to indicate some error instead of returning true
- * or false.
+ * This class provides skeletal implementations of some {@link Queue}
+ * operations. The implementations in this class are appropriate when
+ * the base implementation does <em>not</em> allow <tt>null</tt>
+ * elements. Methods {@link #add add}, {@link #remove remove}, and
+ * {@link #element element} are based on {@link #offer offer}, {@link
+ * #poll poll}, and {@link #peek peek}, respectively, but throw
+ * exceptions instead of indicating failure via <tt>false</tt> or
+ * <tt>null</tt> returns.
+ *
+ * <p>A <tt>Queue</tt> implementation that extends this class must
+ * minimally define a method {@link Queue#offer} which does not permit
+ * insertion of <tt>null</tt> elements, along with methods {@link
+ * Queue#peek}, {@link Queue#poll}, {@link Collection#size}, and
+ * {@link Collection#iterator}. Typically, additional methods will be
+ * overridden as well. If these requirements cannot be met, consider
+ * instead subclassing {@link AbstractCollection}.
*
- * @param <E>
- * the type of the element in the collection.
+ * @since 1.5
+ * @author Doug Lea
+ * @param <E> the type of elements held in this collection
*/
-public abstract class AbstractQueue<E> extends AbstractCollection<E> implements
- Queue<E> {
+public abstract class AbstractQueue<E>
+ extends AbstractCollection<E>
+ implements Queue<E> {
/**
- * Constructor to be used by subclasses.
+ * Constructor for use by subclasses.
*/
protected AbstractQueue() {
- super();
}
/**
- * Adds an element to the queue.
+ * Inserts the specified element into this queue if it is possible to do so
+ * immediately without violating capacity restrictions, returning
+ * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
+ * if no space is currently available.
*
- * @param o
- * the element to be added to the queue.
- * @return {@code true} if the operation succeeds, otherwise {@code false}.
- * @throws IllegalStateException
- * if the element is not allowed to be added to the queue.
+ * <p>This implementation returns <tt>true</tt> if <tt>offer</tt> succeeds,
+ * else throws an <tt>IllegalStateException</tt>.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this queue
+ * @throws NullPointerException if the specified element is null and
+ * this queue does not permit null elements
+ * @throws IllegalArgumentException if some property of this element
+ * prevents it from being added to this queue
*/
- @Override
- public boolean add(E o) {
- if (null == o) {
- throw new NullPointerException();
- }
- if (offer(o)) {
+ public boolean add(E e) {
+ if (offer(e))
return true;
- }
- throw new IllegalStateException();
+ else
+ throw new IllegalStateException("Queue full");
}
/**
- * Adds all the elements of a collection to the queue. If the collection is
- * the queue itself, then an IllegalArgumentException will be thrown. If
- * during the process, some runtime exception is thrown, then those elements
- * in the collection which have already successfully been added will remain
- * in the queue. The result of the method is undefined if the collection is
- * modified during the process of the method.
+ * Retrieves and removes the head of this queue. This method differs
+ * from {@link #poll poll} only in that it throws an exception if this
+ * queue is empty.
*
- * @param c
- * the collection to be added to the queue.
- * @return {@code true} if the operation succeeds, otherwise {@code false}.
- * @throws NullPointerException
- * if the collection or any element of it is null.
- * @throws IllegalArgumentException
- * If the collection to be added to the queue is the queue
- * itself.
- */
- @Override
- public boolean addAll(Collection<? extends E> c) {
- if (null == c) {
- throw new NullPointerException();
- }
- if (this == c) {
- throw new IllegalArgumentException();
- }
- return super.addAll(c);
- }
-
- /**
- * Removes the element at the head of the queue and returns it.
+ * <p>This implementation returns the result of <tt>poll</tt>
+ * unless the queue is empty.
*
- * @return the element at the head of the queue.
- * @throws NoSuchElementException
- * if the queue is empty.
+ * @return the head of this queue
+ * @throws NoSuchElementException if this queue is empty
*/
public E remove() {
- E o = poll();
- if (null == o) {
+ E x = poll();
+ if (x != null)
+ return x;
+ else
throw new NoSuchElementException();
- }
- return o;
}
/**
- * Returns but does not remove the element at the head of the queue.
+ * Retrieves, but does not remove, the head of this queue. This method
+ * differs from {@link #peek peek} only in that it throws an exception if
+ * this queue is empty.
*
- * @return the element at the head of the queue.
- * @throws NoSuchElementException
- * if the queue is empty.
+ * <p>This implementation returns the result of <tt>peek</tt>
+ * unless the queue is empty.
+ *
+ * @return the head of this queue
+ * @throws NoSuchElementException if this queue is empty
*/
public E element() {
- E o = peek();
- if (null == o) {
+ E x = peek();
+ if (x != null)
+ return x;
+ else
throw new NoSuchElementException();
- }
- return o;
}
/**
- * Removes all elements of the queue, leaving it empty.
+ * Removes all of the elements from this queue.
+ * The queue will be empty after this call returns.
+ *
+ * <p>This implementation repeatedly invokes {@link #poll poll} until it
+ * returns <tt>null</tt>.
*/
- @Override
public void clear() {
- E o;
- do {
- o = poll();
- } while (null != o);
+ while (poll() != null)
+ ;
+ }
+
+ /**
+ * Adds all of the elements in the specified collection to this
+ * queue. Attempts to addAll of a queue to itself result in
+ * <tt>IllegalArgumentException</tt>. Further, the behavior of
+ * this operation is undefined if the specified collection is
+ * modified while the operation is in progress.
+ *
+ * <p>This implementation iterates over the specified collection,
+ * and adds each element returned by the iterator to this
+ * queue, in turn. A runtime exception encountered while
+ * trying to add an element (including, in particular, a
+ * <tt>null</tt> element) may result in only some of the elements
+ * having been successfully added when the associated exception is
+ * thrown.
+ *
+ * @param c collection containing elements to be added to this queue
+ * @return <tt>true</tt> if this queue changed as a result of the call
+ * @throws ClassCastException if the class of an element of the specified
+ * collection prevents it from being added to this queue
+ * @throws NullPointerException if the specified collection contains a
+ * null element and this queue does not permit null elements,
+ * or if the specified collection is null
+ * @throws IllegalArgumentException if some property of an element of the
+ * specified collection prevents it from being added to this
+ * queue, or if the specified collection is this queue
+ * @throws IllegalStateException if not all the elements can be added at
+ * this time due to insertion restrictions
+ * @see #add(Object)
+ */
+ public boolean addAll(Collection<? extends E> c) {
+ if (c == null)
+ throw new NullPointerException();
+ if (c == this)
+ throw new IllegalArgumentException();
+ boolean modified = false;
+ for (E e : c)
+ if (add(e))
+ modified = true;
+ return modified;
}
+
}
diff --git a/luni/src/main/java/java/util/ArrayDeque.java b/luni/src/main/java/java/util/ArrayDeque.java
index 95aadf0..fafcdb4 100644
--- a/luni/src/main/java/java/util/ArrayDeque.java
+++ b/luni/src/main/java/java/util/ArrayDeque.java
@@ -1,883 +1,838 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Written by Josh Bloch of Google Inc. and released to the public domain,
+ * as explained at http://creativecommons.org/licenses/publicdomain.
*/
package java.util;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.reflect.Array;
+// BEGIN android-note
+// removed link to collections framework docs
+// END android-note
+
+import java.io.*;
/**
- * An implementation of Deque, backed by an array.
+ * Resizable-array implementation of the {@link Deque} interface. Array
+ * deques have no capacity restrictions; they grow as necessary to support
+ * usage. They are not thread-safe; in the absence of external
+ * synchronization, they do not support concurrent access by multiple threads.
+ * Null elements are prohibited. This class is likely to be faster than
+ * {@link Stack} when used as a stack, and faster than {@link LinkedList}
+ * when used as a queue.
+ *
+ * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
+ * Exceptions include {@link #remove(Object) remove}, {@link
+ * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
+ * removeLastOccurrence}, {@link #contains contains}, {@link #iterator
+ * iterator.remove()}, and the bulk operations, all of which run in linear
+ * time.
*
- * ArrayDeques have no size limit, can not contain null element, and they are
- * not thread-safe.
+ * <p>The iterators returned by this class's <tt>iterator</tt> method are
+ * <i>fail-fast</i>: If the deque is modified at any time after the iterator
+ * is created, in any way except through the iterator's own <tt>remove</tt>
+ * method, the iterator will generally throw a {@link
+ * ConcurrentModificationException}. Thus, in the face of concurrent
+ * modification, the iterator fails quickly and cleanly, rather than risking
+ * arbitrary, non-deterministic behavior at an undetermined time in the
+ * future.
*
- * All optional operations are supported, and the elements can be any objects.
+ * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
+ * as it is, generally speaking, impossible to make any hard guarantees in the
+ * presence of unsynchronized concurrent modification. Fail-fast iterators
+ * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
+ * Therefore, it would be wrong to write a program that depended on this
+ * exception for its correctness: <i>the fail-fast behavior of iterators
+ * should be used only to detect bugs.</i>
*
- * @param <E>
- * the type of elements in this collection
+ * <p>This class and its iterator implement all of the
+ * <em>optional</em> methods of the {@link Collection} and {@link
+ * Iterator} interfaces.
*
- * @since 1.6
+ * @author Josh Bloch and Doug Lea
+ * @since 1.6
+ * @param <E> the type of elements held in this collection
*/
-public class ArrayDeque<E> extends AbstractCollection<E> implements Deque<E>,
- Cloneable, Serializable {
-
- private static final long serialVersionUID = 2340985798034038923L;
-
- private static final int DEFAULT_SIZE = 16;
-
- private enum DequeStatus {
- Empty, Normal, Full;
- }
-
- private transient DequeStatus status;
-
- private transient int modCount;
-
- // the pointer of the head element
- private transient int front;
-
- // the pointer of the "next" position of the tail element
- private transient int rear;
-
+public class ArrayDeque<E> extends AbstractCollection<E>
+ implements Deque<E>, Cloneable, Serializable
+{
+ /**
+ * The array in which the elements of the deque are stored.
+ * The capacity of the deque is the length of this array, which is
+ * always a power of two. The array is never allowed to become
+ * full, except transiently within an addX method where it is
+ * resized (see doubleCapacity) immediately upon becoming full,
+ * thus avoiding head and tail wrapping around to equal each
+ * other. We also guarantee that all array cells not holding
+ * deque elements are always null.
+ */
private transient E[] elements;
- @SuppressWarnings("hiding")
- private class ArrayDequeIterator<E> implements Iterator<E> {
- private int pos;
-
- private final int expectedModCount;
-
- private boolean canRemove;
+ /**
+ * The index of the element at the head of the deque (which is the
+ * element that would be removed by remove() or pop()); or an
+ * arbitrary number equal to tail if the deque is empty.
+ */
+ private transient int head;
- @SuppressWarnings("synthetic-access")
- ArrayDequeIterator() {
- super();
- pos = front;
- expectedModCount = modCount;
- canRemove = false;
- }
+ /**
+ * The index at which the next element would be added to the tail
+ * of the deque (via addLast(E), add(E), or push(E)).
+ */
+ private transient int tail;
- @SuppressWarnings("synthetic-access")
- public boolean hasNext() {
- if (expectedModCount != modCount) {
- return false;
- }
- return hasNextInternal();
- }
+ /**
+ * The minimum capacity that we'll use for a newly created deque.
+ * Must be a power of 2.
+ */
+ private static final int MIN_INITIAL_CAPACITY = 8;
- private boolean hasNextInternal() {
- // canRemove means "next" method is called, and the Full
- // status can ensure that this method is not called just
- // after "remove" method is call.(so, canRemove can keep
- // true after "next" method called)
- return (pos != rear)
- || ((status == DequeStatus.Full) && !canRemove);
- }
+ // ****** Array allocation and resizing utilities ******
- @SuppressWarnings( { "synthetic-access", "unchecked" })
- public E next() {
- if (hasNextInternal()) {
- E result = (E) elements[pos];
- if (expectedModCount == modCount && null != result) {
- canRemove = true;
- pos = circularBiggerPos(pos);
- return result;
- }
- throw new ConcurrentModificationException();
- }
- throw new NoSuchElementException();
- }
+ /**
+ * Allocate empty array to hold the given number of elements.
+ *
+ * @param numElements the number of elements to hold
+ */
+ private void allocateElements(int numElements) {
+ int initialCapacity = MIN_INITIAL_CAPACITY;
+ // Find the best power of two to hold elements.
+ // Tests "<=" because arrays aren't kept full.
+ if (numElements >= initialCapacity) {
+ initialCapacity = numElements;
+ initialCapacity |= (initialCapacity >>> 1);
+ initialCapacity |= (initialCapacity >>> 2);
+ initialCapacity |= (initialCapacity >>> 4);
+ initialCapacity |= (initialCapacity >>> 8);
+ initialCapacity |= (initialCapacity >>> 16);
+ initialCapacity++;
- @SuppressWarnings("synthetic-access")
- public void remove() {
- if (canRemove) {
- int removedPos = circularSmallerPos(pos);
- if (expectedModCount == modCount
- && null != elements[removedPos]) {
- removeInternal(removedPos, true);
- canRemove = false;
- return;
- }
- throw new ConcurrentModificationException();
- }
- throw new IllegalStateException();
+ if (initialCapacity < 0) // Too many elements, must back off
+ initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements
}
+ elements = (E[]) new Object[initialCapacity];
}
- /*
- * NOTES:descendingIterator is not fail-fast, according to the documentation
- * and test case.
+ /**
+ * Double the capacity of this deque. Call only when full, i.e.,
+ * when head and tail have wrapped around to become equal.
*/
- @SuppressWarnings("hiding")
- private class ReverseArrayDequeIterator<E> implements Iterator<E> {
- private int pos;
-
- private final int expectedModCount;
-
- private boolean canRemove;
-
- @SuppressWarnings("synthetic-access")
- ReverseArrayDequeIterator() {
- super();
- expectedModCount = modCount;
- pos = circularSmallerPos(rear);
- canRemove = false;
- }
-
- @SuppressWarnings("synthetic-access")
- public boolean hasNext() {
- if (expectedModCount != modCount) {
- return false;
- }
- return hasNextInternal();
- }
-
- private boolean hasNextInternal() {
- // canRemove means "next" method is called, and the Full
- // status can ensure that this method is not called just
- // after "remove" method is call.(so, canRemove can keep
- // true after "next" method called)
- return (circularBiggerPos(pos) != front)
- || ((status == DequeStatus.Full) && !canRemove);
- }
-
- @SuppressWarnings( { "synthetic-access", "unchecked" })
- public E next() {
- if (hasNextInternal()) {
- E result = (E) elements[pos];
- canRemove = true;
- pos = circularSmallerPos(pos);
- return result;
- }
- throw new NoSuchElementException();
- }
+ private void doubleCapacity() {
+ assert head == tail;
+ int p = head;
+ int n = elements.length;
+ int r = n - p; // number of elements to the right of p
+ int newCapacity = n << 1;
+ if (newCapacity < 0)
+ throw new IllegalStateException("Sorry, deque too big");
+ Object[] a = new Object[newCapacity];
+ System.arraycopy(elements, p, a, 0, r);
+ System.arraycopy(elements, 0, a, r, p);
+ elements = (E[])a;
+ head = 0;
+ tail = n;
+ }
- @SuppressWarnings("synthetic-access")
- public void remove() {
- if (canRemove) {
- removeInternal(circularBiggerPos(pos), false);
- canRemove = false;
- return;
- }
- throw new IllegalStateException();
+ /**
+ * Copies the elements from our element array into the specified array,
+ * in order (from first to last element in the deque). It is assumed
+ * that the array is large enough to hold all elements in the deque.
+ *
+ * @return its argument
+ */
+ private <T> T[] copyElements(T[] a) {
+ if (head < tail) {
+ System.arraycopy(elements, head, a, 0, size());
+ } else if (head > tail) {
+ int headPortionLen = elements.length - head;
+ System.arraycopy(elements, head, a, 0, headPortionLen);
+ System.arraycopy(elements, 0, a, headPortionLen, tail);
}
+ return a;
}
/**
- * Constructs a new empty instance of ArrayDeque big enough for 16 elements.
+ * Constructs an empty array deque with an initial capacity
+ * sufficient to hold 16 elements.
*/
public ArrayDeque() {
- this(DEFAULT_SIZE);
+ elements = (E[]) new Object[16];
}
/**
- * Constructs a new empty instance of ArrayDeque big enough for specified
- * number of elements.
+ * Constructs an empty array deque with an initial capacity
+ * sufficient to hold the specified number of elements.
*
- * @param minSize
- * the smallest size of the ArrayDeque
- */
- @SuppressWarnings("unchecked")
- public ArrayDeque(final int minSize) {
- int size = countInitSize(minSize);
- elements = (E[]) new Object[size];
- front = rear = 0;
- status = DequeStatus.Empty;
- modCount = 0;
- }
-
- /*
- * count out the size for a new deque, and ensure that size >= minSize
+ * @param numElements lower bound on initial capacity of the deque
*/
- private int countInitSize(final int minSize) {
- int size = Math.max(minSize, DEFAULT_SIZE);
- // get the smallest number that not smaller than size,
- // and is a power of 2.
- size = Integer.highestOneBit(size - 1) << 1;
- if (0 >= size) {
- size = minSize;
- }
- return size;
+ public ArrayDeque(int numElements) {
+ allocateElements(numElements);
}
/**
- * Constructs a new instance of ArrayDeque containing the elements of the
- * specified collection, with the order returned by the collection's
- * iterator.
+ * Constructs a deque containing the elements of the specified
+ * collection, in the order they are returned by the collection's
+ * iterator. (The first element returned by the collection's
+ * iterator becomes the first element, or <i>front</i> of the
+ * deque.)
*
- * @param c
- * the source of the elements
- * @throws NullPointerException
- * if the collection is null
+ * @param c the collection whose elements are to be placed into the deque
+ * @throws NullPointerException if the specified collection is null
*/
- @SuppressWarnings("unchecked")
public ArrayDeque(Collection<? extends E> c) {
- elements = (E[]) new Object[countInitSize(c.size())];
- front = rear = 0;
- status = DequeStatus.Empty;
- modCount = 0;
- Iterator<? extends E> it = c.iterator();
- while (it.hasNext()) {
- addLastImpl(it.next());
- }
+ allocateElements(c.size());
+ addAll(c);
}
+ // The main insertion and extraction methods are addFirst,
+ // addLast, pollFirst, pollLast. The other methods are defined in
+ // terms of these.
+
/**
- * {@inheritDoc}
+ * Inserts the specified element at the front of this deque.
*
- * @param e
- * the element
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Deque#addFirst(java.lang.Object)
+ * @param e the element to add
+ * @throws NullPointerException if the specified element is null
*/
public void addFirst(E e) {
- offerFirst(e);
+ if (e == null)
+ throw new NullPointerException();
+ elements[head = (head - 1) & (elements.length - 1)] = e;
+ if (head == tail)
+ doubleCapacity();
}
/**
- * {@inheritDoc}
+ * Inserts the specified element at the end of this deque.
+ *
+ * <p>This method is equivalent to {@link #add}.
*
- * @param e
- * the element
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Deque#addLast(java.lang.Object)
+ * @param e the element to add
+ * @throws NullPointerException if the specified element is null
*/
public void addLast(E e) {
- addLastImpl(e);
+ if (e == null)
+ throw new NullPointerException();
+ elements[tail] = e;
+ if ( (tail = (tail + 1) & (elements.length - 1)) == head)
+ doubleCapacity();
}
/**
- * {@inheritDoc}
+ * Inserts the specified element at the front of this deque.
*
- * @param e
- * the element
- * @return true
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Deque#offerFirst(java.lang.Object)
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Deque#offerFirst})
+ * @throws NullPointerException if the specified element is null
*/
- public boolean offerFirst(E e) {
- checkNull(e);
- checkAndExpand();
- front = circularSmallerPos(front);
- elements[front] = e;
- resetStatus(true);
- modCount++;
+ public boolean offerFirst(E e) {
+ addFirst(e);
return true;
}
/**
- * {@inheritDoc}
+ * Inserts the specified element at the end of this deque.
*
- * @param e
- * the element
- * @return true if the operation succeeds or false if it fails
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Deque#offerLast(java.lang.Object)
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Deque#offerLast})
+ * @throws NullPointerException if the specified element is null
*/
public boolean offerLast(E e) {
- return addLastImpl(e);
+ addLast(e);
+ return true;
}
/**
- * Inserts the element at the tail of the deque.
- *
- * @param e
- * the element
- * @return true if the operation succeeds or false if it fails.
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Queue#offer(java.lang.Object)
+ * @throws NoSuchElementException {@inheritDoc}
*/
- public boolean offer(E e) {
- return addLastImpl(e);
+ public E removeFirst() {
+ E x = pollFirst();
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
}
/**
- * Inserts the element to the tail of the deque.
- *
- * @param e
- * the element
- * @return true
- * @see java.util.AbstractCollection#add(java.lang.Object)
+ * @throws NoSuchElementException {@inheritDoc}
*/
- @Override
- public boolean add(E e) {
- return addLastImpl(e);
+ public E removeLast() {
+ E x = pollLast();
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
}
- /**
- * {@inheritDoc}
- *
- * @param e
- * the element to push
- * @throws NullPointerException
- * if the element is null
- * @see java.util.Deque#push(java.lang.Object)
- */
- public void push(E e) {
- offerFirst(e);
+ public E pollFirst() {
+ int h = head;
+ E result = elements[h]; // Element is null if deque empty
+ if (result == null)
+ return null;
+ elements[h] = null; // Must null out slot
+ head = (h + 1) & (elements.length - 1);
+ return result;
+ }
+
+ public E pollLast() {
+ int t = (tail - 1) & (elements.length - 1);
+ E result = elements[t];
+ if (result == null)
+ return null;
+ elements[t] = null;
+ tail = t;
+ return result;
}
/**
- * {@inheritDoc}
- *
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Deque#removeFirst()
+ * @throws NoSuchElementException {@inheritDoc}
*/
- public E removeFirst() {
- checkEmpty();
- return removePollFirstImpl();
+ public E getFirst() {
+ E x = elements[head];
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
}
/**
- * Gets and removes the head element of this deque. This method throws an
- * exception if the deque is empty.
- *
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Queue#remove()
+ * @throws NoSuchElementException {@inheritDoc}
*/
- public E remove() {
- return removeFirst();
+ public E getLast() {
+ E x = elements[(tail - 1) & (elements.length - 1)];
+ if (x == null)
+ throw new NoSuchElementException();
+ return x;
+ }
+
+ public E peekFirst() {
+ return elements[head]; // elements[head] is null if deque empty
+ }
+
+ public E peekLast() {
+ return elements[(tail - 1) & (elements.length - 1)];
}
/**
- * {@inheritDoc}
+ * Removes the first occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail).
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Deque#pop()
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if the deque contained the specified element
*/
- public E pop() {
- return removeFirst();
+ public boolean removeFirstOccurrence(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = head;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
+ i = (i + 1) & mask;
+ }
+ return false;
}
/**
- * {@inheritDoc}
- *
- * @return the tail element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Deque#removeLast()
- */
- public E removeLast() {
- checkEmpty();
- return removeLastImpl();
+ * Removes the last occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail).
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the last element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
+ *
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if the deque contained the specified element
+ */
+ public boolean removeLastOccurrence(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = (tail - 1) & mask;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x)) {
+ delete(i);
+ return true;
+ }
+ i = (i - 1) & mask;
+ }
+ return false;
}
+ // *** Queue methods ***
+
/**
- * {@inheritDoc}
+ * Inserts the specified element at the end of this deque.
*
- * @return the head element or null if the deque is empty
- * @see java.util.Deque#pollFirst()
+ * <p>This method is equivalent to {@link #addLast}.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @throws NullPointerException if the specified element is null
*/
- public E pollFirst() {
- return (status == DequeStatus.Empty) ? null : removePollFirstImpl();
+ public boolean add(E e) {
+ addLast(e);
+ return true;
}
/**
- * Gets and removes the head element of this deque. This method returns null
- * if the deque is empty.
+ * Inserts the specified element at the end of this deque.
+ *
+ * <p>This method is equivalent to {@link #offerLast}.
*
- * @return the head element or null if the deque is empty
- * @see java.util.Queue#poll()
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Queue#offer})
+ * @throws NullPointerException if the specified element is null
*/
- public E poll() {
- return pollFirst();
+ public boolean offer(E e) {
+ return offerLast(e);
}
/**
- * {@inheritDoc}
+ * Retrieves and removes the head of the queue represented by this deque.
+ *
+ * This method differs from {@link #poll poll} only in that it throws an
+ * exception if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #removeFirst}.
*
- * @return the tail element or null if the deque is empty
- * @see java.util.Deque#pollLast()
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException {@inheritDoc}
*/
- public E pollLast() {
- return (status == DequeStatus.Empty) ? null : removeLastImpl();
+ public E remove() {
+ return removeFirst();
}
/**
- * {@inheritDoc}
+ * Retrieves and removes the head of the queue represented by this deque
+ * (in other words, the first element of this deque), or returns
+ * <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #pollFirst}.
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Deque#getFirst()
+ * @return the head of the queue represented by this deque, or
+ * <tt>null</tt> if this deque is empty
*/
- public E getFirst() {
- checkEmpty();
- return elements[front];
+ public E poll() {
+ return pollFirst();
}
/**
- * Gets but does not remove the head element of this deque. It throws an
- * exception if the deque is empty.
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque. This method differs from {@link #peek peek} only in
+ * that it throws an exception if this deque is empty.
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Queue#element()
+ * <p>This method is equivalent to {@link #getFirst}.
+ *
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException {@inheritDoc}
*/
public E element() {
return getFirst();
}
/**
- * {@inheritDoc}
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque, or returns <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #peekFirst}.
*
- * @return the tail element
- * @throws NoSuchElementException
- * if the deque is empty
- * @see java.util.Deque#getLast()
+ * @return the head of the queue represented by this deque, or
+ * <tt>null</tt> if this deque is empty
*/
- public E getLast() {
- checkEmpty();
- return elements[circularSmallerPos(rear)];
+ public E peek() {
+ return peekFirst();
}
+ // *** Stack methods ***
+
/**
- * {@inheritDoc}
+ * Pushes an element onto the stack represented by this deque. In other
+ * words, inserts the element at the front of this deque.
+ *
+ * <p>This method is equivalent to {@link #addFirst}.
*
- * @return the head element or null if the deque is empty
- * @see java.util.Deque#peekFirst()
+ * @param e the element to push
+ * @throws NullPointerException if the specified element is null
*/
- public E peekFirst() {
- return (status == DequeStatus.Empty) ? null : elements[front];
+ public void push(E e) {
+ addFirst(e);
}
/**
- * Gets but not removes the head element of this deque. This method returns
- * null if the deque is empty.
+ * Pops an element from the stack represented by this deque. In other
+ * words, removes and returns the first element of this deque.
+ *
+ * <p>This method is equivalent to {@link #removeFirst()}.
*
- * @return the head element or null if the deque is empty
- * @see java.util.Queue#peek()
+ * @return the element at the front of this deque (which is the top
+ * of the stack represented by this deque)
+ * @throws NoSuchElementException {@inheritDoc}
*/
- public E peek() {
- return (status == DequeStatus.Empty) ? null : elements[front];
+ public E pop() {
+ return removeFirst();
+ }
+
+ private void checkInvariants() {
+ assert elements[tail] == null;
+ assert head == tail ? elements[head] == null :
+ (elements[head] != null &&
+ elements[(tail - 1) & (elements.length - 1)] != null);
+ assert elements[(head - 1) & (elements.length - 1)] == null;
}
/**
- * {@inheritDoc}
+ * Removes the element at the specified position in the elements array,
+ * adjusting head and tail as necessary. This can result in motion of
+ * elements backwards or forwards in the array.
*
- * @return the tail element or null if the deque is empty
- * @see java.util.Deque#peekLast()
+ * <p>This method is called delete rather than remove to emphasize
+ * that its semantics differ from those of {@link List#remove(int)}.
+ *
+ * @return true if elements moved backwards
*/
- public E peekLast() {
- return (status == DequeStatus.Empty) ? null
- : elements[circularSmallerPos(rear)];
- }
+ private boolean delete(int i) {
+ checkInvariants();
+ final E[] elements = this.elements;
+ final int mask = elements.length - 1;
+ final int h = head;
+ final int t = tail;
+ final int front = (i - h) & mask;
+ final int back = (t - i) & mask;
- private void checkNull(E e) {
- if (null == e) {
- throw new NullPointerException();
- }
- }
+ // Invariant: head <= i < tail mod circularity
+ if (front >= ((t - h) & mask))
+ throw new ConcurrentModificationException();
- private void checkEmpty() {
- if (status == DequeStatus.Empty) {
- throw new NoSuchElementException();
+ // Optimize for least element motion
+ if (front < back) {
+ if (h <= i) {
+ System.arraycopy(elements, h, elements, h + 1, front);
+ } else { // Wrap around
+ System.arraycopy(elements, 0, elements, 1, i);
+ elements[0] = elements[mask];
+ System.arraycopy(elements, h, elements, h + 1, mask - h);
+ }
+ elements[h] = null;
+ head = (h + 1) & mask;
+ return false;
+ } else {
+ if (i < t) { // Copy the null tail as well
+ System.arraycopy(elements, i + 1, elements, i, back);
+ tail = t - 1;
+ } else { // Wrap around
+ System.arraycopy(elements, i + 1, elements, i, mask - i);
+ elements[mask] = elements[0];
+ System.arraycopy(elements, 1, elements, 0, t);
+ tail = (t - 1) & mask;
+ }
+ return true;
}
}
- private int circularSmallerPos(int current) {
- return (current - 1 < 0) ? (elements.length - 1) : current - 1;
- }
+ // *** Collection Methods ***
- private int circularBiggerPos(int current) {
- return (current + 1 >= elements.length) ? 0 : current + 1;
+ /**
+ * Returns the number of elements in this deque.
+ *
+ * @return the number of elements in this deque
+ */
+ public int size() {
+ return (tail - head) & (elements.length - 1);
}
- @SuppressWarnings("unchecked")
- /*
- * If array of elements is full, there will be a new bigger array to store
- * the elements.
+ /**
+ * Returns <tt>true</tt> if this deque contains no elements.
+ *
+ * @return <tt>true</tt> if this deque contains no elements
*/
- private void checkAndExpand() {
- if (status != DequeStatus.Full) {
- return;
- }
- if (Integer.MAX_VALUE == elements.length) {
- throw new IllegalStateException();
- }
- int length = elements.length;
- int newLength = length << 1;
- // bigger than Integer.MAX_VALUE
- if (newLength < 0) {
- newLength = Integer.MAX_VALUE;
- }
- E[] newElements = (E[]) new Object[newLength];
- System.arraycopy(elements, front, newElements, 0, length - front);
- System.arraycopy(elements, 0, newElements, length - front, front);
- front = 0;
- rear = length;
- status = DequeStatus.Normal;
- elements = newElements;
+ public boolean isEmpty() {
+ return head == tail;
}
/**
- * Resets the status after adding or removing operation.
+ * Returns an iterator over the elements in this deque. The elements
+ * will be ordered from first (head) to last (tail). This is the same
+ * order that elements would be dequeued (via successive calls to
+ * {@link #remove} or popped (via successive calls to {@link #pop}).
*
- * @param adding
- * if the method is called after an "adding" operation
+ * @return an iterator over the elements in this deque
*/
- private void resetStatus(boolean adding) {
- if (front == rear) {
- status = adding ? DequeStatus.Full : DequeStatus.Empty;
- } else {
- status = DequeStatus.Normal;
- }
+ public Iterator<E> iterator() {
+ return new DeqIterator();
}
- private boolean addLastImpl(E e) {
- checkNull(e);
- checkAndExpand();
- elements[rear] = e;
- rear = circularBiggerPos(rear);
- resetStatus(true);
- modCount++;
- return true;
+ public Iterator<E> descendingIterator() {
+ return new DescendingIterator();
}
- private E removePollFirstImpl() {
- E element = elements[front];
- elements[front] = null;
- front = circularBiggerPos(front);
- resetStatus(false);
- modCount++;
- return element;
- }
+ private class DeqIterator implements Iterator<E> {
+ /**
+ * Index of element to be returned by subsequent call to next.
+ */
+ private int cursor = head;
- private E removeLastImpl() {
- int last = circularSmallerPos(rear);
- E element = elements[last];
- elements[last] = null;
- rear = last;
- resetStatus(false);
- modCount++;
- return element;
- }
+ /**
+ * Tail recorded at construction (also in remove), to stop
+ * iterator and also to check for comodification.
+ */
+ private int fence = tail;
- /**
- * {@inheritDoc}
- *
- * @param obj
- * the element to be removed
- * @return true if the operation succeeds or false if the deque does not
- * contain the element
- * @see java.util.Deque#removeFirstOccurrence(java.lang.Object)
- */
- public boolean removeFirstOccurrence(Object obj) {
- return removeFirstOccurrenceImpl(obj);
- }
+ /**
+ * Index of element returned by most recent call to next.
+ * Reset to -1 if element is deleted by a call to remove.
+ */
+ private int lastRet = -1;
- /**
- * Removes the first equivalent element of the specified object. If the
- * deque does not contain the element, it is unchanged and returns false.
- *
- * @param obj
- * the element to be removed
- * @return true if the operation succeeds or false if the deque does not
- * contain the element
- * @see java.util.AbstractCollection#remove(java.lang.Object)
- */
- @Override
- public boolean remove(Object obj) {
- return removeFirstOccurrenceImpl(obj);
- }
+ public boolean hasNext() {
+ return cursor != fence;
+ }
- /**
- * {@inheritDoc}
- *
- * @param obj
- * the element to be removed
- * @return true if the operation succeeds or false if the deque does not
- * contain the element.
- * @see java.util.Deque#removeLastOccurrence(java.lang.Object)
- */
- public boolean removeLastOccurrence(final Object obj) {
- if (null != obj) {
- Iterator<E> iter = descendingIterator();
- while (iter.hasNext()) {
- if (iter.next().equals(obj)) {
- iter.remove();
- return true;
- }
- }
+ public E next() {
+ if (cursor == fence)
+ throw new NoSuchElementException();
+ E result = elements[cursor];
+ // This check doesn't catch all possible comodifications,
+ // but does catch the ones that corrupt traversal
+ if (tail != fence || result == null)
+ throw new ConcurrentModificationException();
+ lastRet = cursor;
+ cursor = (cursor + 1) & (elements.length - 1);
+ return result;
}
- return false;
- }
- private boolean removeFirstOccurrenceImpl(final Object obj) {
- if (null != obj) {
- Iterator<E> iter = iterator();
- while (iter.hasNext()) {
- if (iter.next().equals(obj)) {
- iter.remove();
- return true;
- }
+ public void remove() {
+ if (lastRet < 0)
+ throw new IllegalStateException();
+ if (delete(lastRet)) { // if left-shifted, undo increment in next()
+ cursor = (cursor - 1) & (elements.length - 1);
+ fence = tail;
}
+ lastRet = -1;
}
- return false;
}
- /*
- * Removes the element in the cursor position and shifts front elements to
- * fill the gap if frontShift is true, shifts rear elements otherwise.
- *
- */
- private void removeInternal(final int current, final boolean frontShift) {
- int cursor = current;
- if (frontShift) {
- while (cursor != front) {
- int next = circularSmallerPos(cursor);
- elements[cursor] = elements[next];
- cursor = next;
- }
- front = circularBiggerPos(front);
- } else {
- while (cursor != rear) {
- int next = circularBiggerPos(cursor);
- elements[cursor] = elements[next];
- cursor = next;
- }
- rear = circularSmallerPos(rear);
+ private class DescendingIterator implements Iterator<E> {
+ /*
+ * This class is nearly a mirror-image of DeqIterator, using
+ * tail instead of head for initial cursor, and head instead of
+ * tail for fence.
+ */
+ private int cursor = tail;
+ private int fence = head;
+ private int lastRet = -1;
+
+ public boolean hasNext() {
+ return cursor != fence;
}
- elements[cursor] = null;
- resetStatus(false);
- }
- /**
- * Returns the size of the deque.
- *
- * @return the size of the deque
- * @see java.util.AbstractCollection#size()
- */
- @Override
- public int size() {
- if (status == DequeStatus.Full) {
- return elements.length;
+ public E next() {
+ if (cursor == fence)
+ throw new NoSuchElementException();
+ cursor = (cursor - 1) & (elements.length - 1);
+ E result = elements[cursor];
+ if (head != fence || result == null)
+ throw new ConcurrentModificationException();
+ lastRet = cursor;
+ return result;
}
- return (front <= rear) ? (rear - front)
- : (rear + elements.length - front);
- }
- /**
- * Returns true if the deque has no elements.
- *
- * @return true if the deque has no elements, false otherwise
- * @see java.util.AbstractCollection#isEmpty()
- */
- @Override
- public boolean isEmpty() {
- return 0 == size();
+ public void remove() {
+ if (lastRet < 0)
+ throw new IllegalStateException();
+ if (!delete(lastRet)) {
+ cursor = (cursor + 1) & (elements.length - 1);
+ fence = head;
+ }
+ lastRet = -1;
+ }
}
/**
- * Returns true if the specified element is in the deque.
+ * Returns <tt>true</tt> if this deque contains the specified element.
+ * More formally, returns <tt>true</tt> if and only if this deque contains
+ * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
*
- * @param obj
- * the element
- * @return true if the element is in the deque, false otherwise
- * @see java.util.AbstractCollection#contains(java.lang.Object)
+ * @param o object to be checked for containment in this deque
+ * @return <tt>true</tt> if this deque contains the specified element
*/
- @SuppressWarnings("cast")
- @Override
- public boolean contains(final Object obj) {
- if (null != obj) {
- Iterator<E> it = new ArrayDequeIterator<E>();
- while (it.hasNext()) {
- if (obj.equals((E) it.next())) {
- return true;
- }
- }
+ public boolean contains(Object o) {
+ if (o == null)
+ return false;
+ int mask = elements.length - 1;
+ int i = head;
+ E x;
+ while ( (x = elements[i]) != null) {
+ if (o.equals(x))
+ return true;
+ i = (i + 1) & mask;
}
return false;
}
/**
- * Empty the deque.
+ * Removes a single instance of the specified element from this deque.
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>o.equals(e)</tt> (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
*
- * @see java.util.AbstractCollection#clear()
+ * <p>This method is equivalent to {@link #removeFirstOccurrence}.
+ *
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if this deque contained the specified element
*/
- @SuppressWarnings("cast")
- @Override
- public void clear() {
- if (status != DequeStatus.Empty) {
- int cursor = front;
- do {
- elements[cursor] = null;
- cursor = circularBiggerPos(cursor);
- } while (cursor != rear);
- status = DequeStatus.Empty;
- }
- front = rear = 0;
- modCount = 0;
+ public boolean remove(Object o) {
+ return removeFirstOccurrence(o);
}
/**
- * Returns a clone of the deque.
- *
- * @return the clone of the deque
- * @see java.lang.Object#clone()
- * @see java.lang.Cloneable
+ * Removes all of the elements from this deque.
+ * The deque will be empty after this call returns.
*/
- @SuppressWarnings("unchecked")
- @Override
- public ArrayDeque<E> clone() {
- try {
- ArrayDeque<E> newDeque = (ArrayDeque<E>) super.clone();
- newDeque.elements = elements.clone();
- return newDeque;
- } catch (CloneNotSupportedException e) {
- return null;
+ public void clear() {
+ int h = head;
+ int t = tail;
+ if (h != t) { // clear all cells
+ head = tail = 0;
+ int i = h;
+ int mask = elements.length - 1;
+ do {
+ elements[i] = null;
+ i = (i + 1) & mask;
+ } while (i != t);
}
}
/**
- * Returns all the elements in an array from head to tail. The result is a
- * copy of all the elements.
+ * Returns an array containing all of the elements in this deque
+ * in proper sequence (from first to last element).
+ *
+ * <p>The returned array will be "safe" in that no references to it are
+ * maintained by this deque. (In other words, this method must allocate
+ * a new array). The caller is thus free to modify the returned array.
+ *
+ * <p>This method acts as bridge between array-based and collection-based
+ * APIs.
*
- * @return the Array of all the elements
- * @see java.util.AbstractCollection#toArray()
+ * @return an array containing all of the elements in this deque
*/
- @Override
public Object[] toArray() {
- return newArray(new Object[size()]);
+ return copyElements(new Object[size()]);
}
/**
- * Returns all the elements in an array from head to tail, and the type of
- * the result array is the type of the argument array. If the argument array
- * is big enough, the elements from the deque will be stored in it(elements
- * following the tail of the deque is set to null, if any); otherwise, it
- * will return a new array with the size of the argument array and size of
- * the deque.
+ * Returns an array containing all of the elements in this deque in
+ * proper sequence (from first to last element); the runtime type of the
+ * returned array is that of the specified array. If the deque fits in
+ * the specified array, it is returned therein. Otherwise, a new array
+ * is allocated with the runtime type of the specified array and the
+ * size of this deque.
*
- * @param array
- * the array stores all the elements from the deque, if it has
- * enough space; otherwise, a new array of the same type and the
- * size of the deque will be used
- * @return the Array of all the elements
- * @throws ArrayStoreException
- * if the type of the argument array is not compatible with
- * every element in the deque
- * @throws NullPointerException
- * if the argument array is null
- * @see java.util.AbstractCollection#toArray
+ * <p>If this deque fits in the specified array with room to spare
+ * (i.e., the array has more elements than this deque), the element in
+ * the array immediately following the end of the deque is set to
+ * <tt>null</tt>.
+ *
+ * <p>Like the {@link #toArray()} method, this method acts as bridge between
+ * array-based and collection-based APIs. Further, this method allows
+ * precise control over the runtime type of the output array, and may,
+ * under certain circumstances, be used to save allocation costs.
+ *
+ * <p>Suppose <tt>x</tt> is a deque known to contain only strings.
+ * The following code can be used to dump the deque into a newly
+ * allocated array of <tt>String</tt>:
+ *
+ * <pre>
+ * String[] y = x.toArray(new String[0]);</pre>
+ *
+ * Note that <tt>toArray(new Object[0])</tt> is identical in function to
+ * <tt>toArray()</tt>.
+ *
+ * @param a the array into which the elements of the deque are to
+ * be stored, if it is big enough; otherwise, a new array of the
+ * same runtime type is allocated for this purpose
+ * @return an array containing all of the elements in this deque
+ * @throws ArrayStoreException if the runtime type of the specified array
+ * is not a supertype of the runtime type of every element in
+ * this deque
+ * @throws NullPointerException if the specified array is null
*/
- @Override
- public <T> T[] toArray(T[] array) {
- return newArray(array);
- }
-
- @SuppressWarnings("unchecked")
- private <T> T[] newArray(T[] array) {
+ public <T> T[] toArray(T[] a) {
int size = size();
- if (size > array.length) {
- Class<?> clazz = array.getClass().getComponentType();
- array = (T[]) Array.newInstance(clazz, size);
- }
- if (front < rear) {
- System.arraycopy(elements, front, array, 0, size);
- } else if (size != 0) {
- int length = elements.length;
- System.arraycopy(elements, front, array, 0, length - front);
- System.arraycopy(elements, 0, array, length - front, rear);
- }
- if (size < array.length) {
- array[size] = null;
- }
- return array;
+ if (a.length < size)
+ a = (T[])java.lang.reflect.Array.newInstance(
+ a.getClass().getComponentType(), size);
+ copyElements(a);
+ if (a.length > size)
+ a[size] = null;
+ return a;
}
+ // *** Object methods ***
+
/**
- * Returns the iterator of the deque. The elements will be ordered from head
- * to tail.
+ * Returns a copy of this deque.
*
- * @return the iterator
- * @see java.util.AbstractCollection#iterator()
+ * @return a copy of this deque
*/
- @SuppressWarnings("synthetic-access")
- @Override
- public Iterator<E> iterator() {
- return new ArrayDequeIterator<E>();
+ public ArrayDeque<E> clone() {
+ try {
+ ArrayDeque<E> result = (ArrayDeque<E>) super.clone();
+ result.elements = Arrays.copyOf(elements, elements.length);
+ return result;
+
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError();
+ }
}
/**
- * {@inheritDoc}
- *
- * @return the reverse order Iterator
- * @see java.util.Deque#descendingIterator()
+ * Appease the serialization gods.
*/
- public Iterator<E> descendingIterator() {
- return new ReverseArrayDequeIterator<E>();
- }
+ private static final long serialVersionUID = 2340985798034038923L;
/**
- * Deserialization method.
+ * Serialize this deque.
*
- * @param stream
- * the ObjectInputStream
- * @throws IOException
- * @throws ClassNotFoundException
+ * @serialData The current size (<tt>int</tt>) of the deque,
+ * followed by all of its elements (each an object reference) in
+ * first-to-last order.
*/
- @SuppressWarnings("unchecked")
- private void readObject(ObjectInputStream stream) throws IOException,
- ClassNotFoundException {
- stream.defaultReadObject();
- int size = stream.readInt();
- elements = (E[]) new Object[countInitSize(size)];
- front = rear = 0;
- status = DequeStatus.Empty;
- modCount = 0;
- for (int i = 0; i < size; i++) {
- addLastImpl((E) stream.readObject());
- }
+ private void writeObject(ObjectOutputStream s) throws IOException {
+ s.defaultWriteObject();
+
+ // Write out size
+ s.writeInt(size());
+
+ // Write out elements in order.
+ int mask = elements.length - 1;
+ for (int i = head; i != tail; i = (i + 1) & mask)
+ s.writeObject(elements[i]);
}
/**
- * Serialization method.
- *
- * @param stream
- * the ObjectOutputStream
- * @serialData The current size of the deque, followed by all the elements
- * from head to tail.
- * @throws IOException
- *
+ * Deserialize this deque.
*/
- private void writeObject(ObjectOutputStream stream) throws IOException {
- stream.defaultWriteObject();
- stream.writeInt(size());
- Iterator<?> it = new ArrayDequeIterator<E>();
- while (it.hasNext()) {
- stream.writeObject(it.next());
- }
- }
+ private void readObject(ObjectInputStream s)
+ throws IOException, ClassNotFoundException {
+ s.defaultReadObject();
+
+ // Read in size and allocate array
+ int size = s.readInt();
+ allocateElements(size);
+ head = 0;
+ tail = size;
+ // Read in all elements in the proper order.
+ for (int i = 0; i < size; i++)
+ elements[i] = (E)s.readObject();
+ }
}
diff --git a/luni/src/main/java/java/util/ArrayList.java b/luni/src/main/java/java/util/ArrayList.java
index 19d2449..f632077 100644
--- a/luni/src/main/java/java/util/ArrayList.java
+++ b/luni/src/main/java/java/util/ArrayList.java
@@ -27,6 +27,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.lang.reflect.Array;
+import libcore.base.EmptyArray;
/**
* ArrayList is an implementation of {@link List}, backed by an array.
@@ -44,13 +45,7 @@ import java.lang.reflect.Array;
* @param <E> The element type of this list.
* @since 1.2
*/
-public class ArrayList<E> extends AbstractList<E>
- implements Cloneable, Serializable, RandomAccess {
- /**
- * An empty array of objects (to be shared among all empty lists).
- */
- private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0];
-
+public class ArrayList<E> extends AbstractList<E> implements Cloneable, Serializable, RandomAccess {
/**
* The minimum amount by which the capacity of an ArrayList will increase.
* This tuning parameter controls a time-space tradeoff. This value (12)
@@ -81,14 +76,14 @@ public class ArrayList<E> extends AbstractList<E>
if (capacity < 0) {
throw new IllegalArgumentException();
}
- array = (capacity == 0 ? EMPTY_OBJECT_ARRAY : new Object[capacity]);
+ array = (capacity == 0 ? EmptyArray.OBJECT : new Object[capacity]);
}
/**
* Constructs a new {@code ArrayList} instance with zero initial capacity.
*/
public ArrayList() {
- array = EMPTY_OBJECT_ARRAY;
+ array = EmptyArray.OBJECT;
}
/**
@@ -252,10 +247,12 @@ public class ArrayList<E> extends AbstractList<E>
return true;
}
- /** This method was extracted to encourage VM to inline callers. */
+ /**
+ * This method was extracted to encourage VM to inline callers.
+ * TODO: when we have a VM that can actually inline, move the test in here too!
+ */
private static void throwIndexOutOfBoundsException(int index, int size) {
- throw new IndexOutOfBoundsException("Invalid index " + index
- + ", size is " + size);
+ throw new IndexOutOfBoundsException("Invalid index " + index + ", size is " + size);
}
/**
@@ -542,7 +539,7 @@ public class ArrayList<E> extends AbstractList<E>
return;
}
if (s == 0) {
- array = EMPTY_OBJECT_ARRAY;
+ array = EmptyArray.OBJECT;
} else {
Object[] newArray = new Object[s];
System.arraycopy(array, 0, newArray, 0, s);
@@ -652,15 +649,14 @@ public class ArrayList<E> extends AbstractList<E>
}
}
- private void readObject(ObjectInputStream stream) throws IOException,
- ClassNotFoundException {
+ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
int cap = stream.readInt();
if (cap < size) {
throw new InvalidObjectException(
"Capacity: " + cap + " < size: " + size);
}
- array = (cap == 0 ? EMPTY_OBJECT_ARRAY : new Object[cap]);
+ array = (cap == 0 ? EmptyArray.OBJECT : new Object[cap]);
for (int i = 0; i < size; i++) {
array[i] = stream.readObject();
}
diff --git a/luni/src/main/java/java/util/Arrays.java b/luni/src/main/java/java/util/Arrays.java
index 791b86b..8d27f49 100644
--- a/luni/src/main/java/java/util/Arrays.java
+++ b/luni/src/main/java/java/util/Arrays.java
@@ -114,15 +114,9 @@ public class Arrays {
@Override
public E set(int location, E object) {
- try {
- E result = a[location];
- a[location] = object;
- return result;
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new IndexOutOfBoundsException();
- } catch (ArrayStoreException e) {
- throw new ClassCastException();
- }
+ E result = a[location];
+ a[location] = object;
+ return result;
}
@Override
@@ -703,7 +697,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(byte[] array, int start, int end, byte value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -740,7 +734,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(short[] array, int start, int end, short value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -777,7 +771,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(char[] array, int start, int end, char value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -814,7 +808,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(int[] array, int start, int end, int value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -851,7 +845,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(long[] array, int start, int end, long value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -888,7 +882,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(float[] array, int start, int end, float value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -925,7 +919,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(double[] array, int start, int end, double value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -962,7 +956,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(boolean[] array, int start, int end, boolean value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -999,7 +993,7 @@ public class Arrays {
* if {@code start < 0} or {@code end > array.length}.
*/
public static void fill(Object[] array, int start, int end, Object value) {
- checkFillBounds(array.length, start, end);
+ Arrays.checkStartAndEnd(array.length, start, end);
for (int i = start; i < end; i++) {
array[i] = value;
}
@@ -1012,8 +1006,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Boolean}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Boolean} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1040,8 +1034,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Integer}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Integer} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1068,8 +1062,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Short}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Short} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1096,8 +1090,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Character}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Character} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1124,8 +1118,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Byte}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Byte} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1152,8 +1146,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Long}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Long} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1184,8 +1178,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Float}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Float} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1215,8 +1209,8 @@ public class Arrays {
* that the return value of {@code Arrays.hashCode(a)} equals {@code Arrays.hashCode(b)}.
* <p>
* The value returned by this method is the same value as the
- * {@link List#hashCode()}} method which is invoked on a {@link List}}
- * containing a sequence of {@link Double}} instances representing the
+ * {@link List#hashCode()} method which is invoked on a {@link List}
+ * containing a sequence of {@link Double} instances representing the
* elements of array in the same order. If the array is {@code null}, the return
* value is 0.
*
@@ -1292,8 +1286,8 @@ public class Arrays {
* {@code Arrays.deepHashCode(b)}.
* <p>
* The computation of the value returned by this method is similar to that
- * of the value returned by {@link List#hashCode()}} invoked on a
- * {@link List}} containing a sequence of instances representing the
+ * of the value returned by {@link List#hashCode()} invoked on a
+ * {@link List} containing a sequence of instances representing the
* elements of array in the same order. The difference is: If an element e
* of array is itself an array, its hash code is computed by calling the
* appropriate overloading of {@code Arrays.hashCode(e)} if e is an array of a
@@ -1735,16 +1729,35 @@ public class Arrays {
DualPivotQuicksort.sort(array, start, end);
}
- private static void checkFillBounds(int arrLength, int start, int end) {
+ /**
+ * Checks that the range described by {@code offset} and {@code count} doesn't exceed
+ * {@code arrayLength}.
+ *
+ * @hide
+ */
+ public static void checkOffsetAndCount(int arrayLength, int offset, int count) {
+ if ((offset | count) < 0 || offset > arrayLength || arrayLength - offset < count) {
+ throw new ArrayIndexOutOfBoundsException("offset=" + offset + ", count=" + count +
+ ", array length=" + arrayLength);
+ }
+ }
+
+ /**
+ * Checks that the range described by {@code start} and {@code end} doesn't exceed
+ * {@code arrayLength}.
+ *
+ * @hide
+ */
+ public static void checkStartAndEnd(int arrayLength, int start, int end) {
if (start > end) {
- throw new IllegalArgumentException("start < end: " + start + " < " + end);
+ throw new IllegalArgumentException("start > end: " + start + " > " + end);
}
if (start < 0) {
throw new ArrayIndexOutOfBoundsException("start < 0: " + start);
}
- if (end > arrLength) {
+ if (end > arrayLength) {
throw new ArrayIndexOutOfBoundsException("end > array length: " +
- end + " > " + arrLength);
+ end + " > " + arrayLength);
}
}
@@ -2093,10 +2106,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code boolean[]} passed.
- * The result is surrounded by brackets ({@code &quot;[]&quot;}), each
+ * The result is surrounded by brackets ({@code "[]"}), each
* element is converted to a {@code String} via the
- * {@link String#valueOf(boolean)} and separated by {@code &quot;, &quot;}.
- * If the array is {@code null}, then {@code &quot;null&quot;} is returned.
+ * {@link String#valueOf(boolean)} and separated by {@code ", "}.
+ * If the array is {@code null}, then {@code "null"} is returned.
*
* @param array
* the {@code boolean} array to convert.
@@ -2123,10 +2136,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code byte[]} passed. The
- * result is surrounded by brackets ({@code &quot;[]&quot;}), each element
+ * result is surrounded by brackets ({@code "[]"}), each element
* is converted to a {@code String} via the {@link String#valueOf(int)} and
- * separated by {@code &quot;, &quot;}. If the array is {@code null}, then
- * {@code &quot;null&quot;} is returned.
+ * separated by {@code ", "}. If the array is {@code null}, then
+ * {@code "null"} is returned.
*
* @param array
* the {@code byte} array to convert.
@@ -2153,10 +2166,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code char[]} passed. The
- * result is surrounded by brackets ({@code &quot;[]&quot;}), each element
+ * result is surrounded by brackets ({@code "[]"}), each element
* is converted to a {@code String} via the {@link String#valueOf(char)} and
- * separated by {@code &quot;, &quot;}. If the array is {@code null}, then
- * {@code &quot;null&quot;} is returned.
+ * separated by {@code ", "}. If the array is {@code null}, then
+ * {@code "null"} is returned.
*
* @param array
* the {@code char} array to convert.
@@ -2183,10 +2196,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code double[]} passed.
- * The result is surrounded by brackets ({@code &quot;[]&quot;}), each
+ * The result is surrounded by brackets ({@code "[]"}), each
* element is converted to a {@code String} via the
- * {@link String#valueOf(double)} and separated by {@code &quot;, &quot;}.
- * If the array is {@code null}, then {@code &quot;null&quot;} is returned.
+ * {@link String#valueOf(double)} and separated by {@code ", "}.
+ * If the array is {@code null}, then {@code "null"} is returned.
*
* @param array
* the {@code double} array to convert.
@@ -2213,10 +2226,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code float[]} passed.
- * The result is surrounded by brackets ({@code &quot;[]&quot;}), each
+ * The result is surrounded by brackets ({@code "[]"}), each
* element is converted to a {@code String} via the
- * {@link String#valueOf(float)} and separated by {@code &quot;, &quot;}.
- * If the array is {@code null}, then {@code &quot;null&quot;} is returned.
+ * {@link String#valueOf(float)} and separated by {@code ", "}.
+ * If the array is {@code null}, then {@code "null"} is returned.
*
* @param array
* the {@code float} array to convert.
@@ -2243,10 +2256,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code int[]} passed. The
- * result is surrounded by brackets ({@code &quot;[]&quot;}), each element
+ * result is surrounded by brackets ({@code "[]"}), each element
* is converted to a {@code String} via the {@link String#valueOf(int)} and
- * separated by {@code &quot;, &quot;}. If the array is {@code null}, then
- * {@code &quot;null&quot;} is returned.
+ * separated by {@code ", "}. If the array is {@code null}, then
+ * {@code "null"} is returned.
*
* @param array
* the {@code int} array to convert.
@@ -2273,10 +2286,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code long[]} passed. The
- * result is surrounded by brackets ({@code &quot;[]&quot;}), each element
+ * result is surrounded by brackets ({@code "[]"}), each element
* is converted to a {@code String} via the {@link String#valueOf(long)} and
- * separated by {@code &quot;, &quot;}. If the array is {@code null}, then
- * {@code &quot;null&quot;} is returned.
+ * separated by {@code ", "}. If the array is {@code null}, then
+ * {@code "null"} is returned.
*
* @param array
* the {@code long} array to convert.
@@ -2303,10 +2316,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code short[]} passed.
- * The result is surrounded by brackets ({@code &quot;[]&quot;}), each
+ * The result is surrounded by brackets ({@code "[]"}), each
* element is converted to a {@code String} via the
- * {@link String#valueOf(int)} and separated by {@code &quot;, &quot;}. If
- * the array is {@code null}, then {@code &quot;null&quot;} is returned.
+ * {@link String#valueOf(int)} and separated by {@code ", "}. If
+ * the array is {@code null}, then {@code "null"} is returned.
*
* @param array
* the {@code short} array to convert.
@@ -2333,10 +2346,10 @@ public class Arrays {
/**
* Creates a {@code String} representation of the {@code Object[]} passed.
- * The result is surrounded by brackets ({@code &quot;[]&quot;}), each
+ * The result is surrounded by brackets ({@code "[]"}), each
* element is converted to a {@code String} via the
- * {@link String#valueOf(Object)} and separated by {@code &quot;, &quot;}.
- * If the array is {@code null}, then {@code &quot;null&quot;} is returned.
+ * {@link String#valueOf(Object)} and separated by {@code ", "}.
+ * If the array is {@code null}, then {@code "null"} is returned.
*
* @param array
* the {@code Object} array to convert.
diff --git a/luni/src/main/java/java/util/BitSet.java b/luni/src/main/java/java/util/BitSet.java
index e1b9341..bc76b80 100644
--- a/luni/src/main/java/java/util/BitSet.java
+++ b/luni/src/main/java/java/util/BitSet.java
@@ -245,19 +245,19 @@ public class BitSet implements Serializable, Cloneable {
private void checkIndex(int index) {
if (index < 0) {
- throw new IndexOutOfBoundsException("index < 0");
+ throw new IndexOutOfBoundsException("index < 0: " + index);
}
}
private void checkRange(int fromIndex, int toIndex) {
- if (fromIndex < 0 || toIndex < 0 || toIndex < fromIndex) {
+ if ((fromIndex | toIndex) < 0 || toIndex < fromIndex) {
throw new IndexOutOfBoundsException("fromIndex=" + fromIndex + " toIndex=" + toIndex);
}
}
/**
* Retrieves the bits starting from {@code fromIndex} to {@code toIndex} and returns
- * back a new bitset made of these bits. Grows the {@code BitSet} if {@code toIndex &gt; size}.
+ * back a new bitset made of these bits. Grows the {@code BitSet} if {@code toIndex > size}.
*
* @param fromIndex
* inclusive beginning position.
diff --git a/luni/src/main/java/java/util/Calendar.java b/luni/src/main/java/java/util/Calendar.java
index 780f647..3368b2d 100644
--- a/luni/src/main/java/java/util/Calendar.java
+++ b/luni/src/main/java/java/util/Calendar.java
@@ -17,14 +17,14 @@
package java.util;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.io.Serializable;
import java.text.DateFormatSymbols;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
/**
* {@code Calendar} is an abstract base class for converting between a
@@ -738,7 +738,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* if {@code field} is {@code DST_OFFSET} or {@code
* ZONE_OFFSET}.
*/
- abstract public void add(int field, int value);
+ public abstract void add(int field, int value);
/**
* Returns whether the {@code Date} specified by this {@code Calendar} instance is after the {@code Date}
@@ -979,7 +979,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* the field.
* @return the greatest minimum value of the specified field.
*/
- abstract public int getGreatestMinimum(int field);
+ public abstract int getGreatestMinimum(int field);
/**
* Constructs a new instance of the {@code Calendar} subclass appropriate for the
@@ -1042,7 +1042,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* the field number.
* @return the smallest maximum value of the specified field.
*/
- abstract public int getLeastMaximum(int field);
+ public abstract int getLeastMaximum(int field);
/**
* Gets the greatest maximum value of the specified field. This returns the
@@ -1052,7 +1052,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* the field.
* @return the greatest maximum value of the specified field.
*/
- abstract public int getMaximum(int field);
+ public abstract int getMaximum(int field);
/**
* Gets the minimal days in the first week of the year.
@@ -1071,7 +1071,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* the field number.
* @return the smallest minimum value of the specified field.
*/
- abstract public int getMinimum(int field);
+ public abstract int getMinimum(int field);
/**
* Gets the time of this {@code Calendar} as a {@code Date} object.
@@ -1197,7 +1197,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* @param increment
* {@code true} to increment the field, {@code false} to decrement.
*/
- abstract public void roll(int field, boolean increment);
+ public abstract void roll(int field, boolean increment);
/**
* Sets a field to the specified value.
@@ -1397,7 +1397,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
* value.
*/
public int compareTo(Calendar anotherCalendar) {
- if (null == anotherCalendar) {
+ if (anotherCalendar == null) {
throw new NullPointerException();
}
long timeInMillis = getTimeInMillis();
diff --git a/luni/src/main/java/java/util/Collections.java b/luni/src/main/java/java/util/Collections.java
index 0fafb53..38005ad 100644
--- a/luni/src/main/java/java/util/Collections.java
+++ b/luni/src/main/java/java/util/Collections.java
@@ -60,7 +60,7 @@ public class Collections {
@Override
public E get(int location) {
- if (0 <= location && location < n) {
+ if (location >= 0 && location < n) {
return element;
}
throw new IndexOutOfBoundsException();
@@ -593,15 +593,15 @@ public class Collections {
array = new Object[size];
list.toArray(array);
}
- if (null != object)
+ if (object != null) {
for (int i = 0; i < size; i++) {
if (object.equals(array[i])) {
return i;
}
}
- else {
+ } else {
for (int i = 0; i < size; i++) {
- if (null == array[i]) {
+ if (array[i] == null) {
return i;
}
}
@@ -617,15 +617,15 @@ public class Collections {
array = new Object[size];
list.toArray(array);
}
- if (null != object)
+ if (object != null) {
for (int i = size - 1; i >= 0; i--) {
if (object.equals(array[i])) {
return i;
}
}
- else {
+ } else {
for (int i = size - 1; i >= 0; i--) {
- if (null == array[i]) {
+ if (array[i] == null) {
return i;
}
}
@@ -1590,8 +1590,8 @@ public class Collections {
*/
public static <T> void copy(List<? super T> destination, List<? extends T> source) {
if (destination.size() < source.size()) {
- throw new ArrayIndexOutOfBoundsException("Source size " + source.size() +
- " does not fit into destination");
+ throw new IndexOutOfBoundsException("destination.size() < source.size(): " +
+ destination.size() + " < " + source.size());
}
Iterator<? extends T> srcIt = source.iterator();
ListIterator<? super T> destIt = destination.listIterator();
@@ -1600,7 +1600,7 @@ public class Collections {
destIt.next();
} catch (NoSuchElementException e) {
// TODO: AssertionError?
- throw new ArrayIndexOutOfBoundsException("Source size " + source.size() +
+ throw new IndexOutOfBoundsException("Source size " + source.size() +
" does not fit into destination");
}
destIt.set(srcIt.next());
diff --git a/luni/src/main/java/java/util/ComparableTimSort.java b/luni/src/main/java/java/util/ComparableTimSort.java
index cda4b12..aba7573 100644
--- a/luni/src/main/java/java/util/ComparableTimSort.java
+++ b/luni/src/main/java/java/util/ComparableTimSort.java
@@ -143,7 +143,7 @@ class ComparableTimSort {
}
static void sort(Object[] a, int lo, int hi) {
- rangeCheck(a.length, lo, hi);
+ Arrays.checkStartAndEnd(a.length, lo, hi);
int nRemaining = hi - lo;
if (nRemaining < 2)
return; // Arrays of size 0 and 1 are always sorted
@@ -867,25 +867,4 @@ class ComparableTimSort {
}
return tmp;
}
-
- /**
- * Checks that fromIndex and toIndex are in range, and throws an
- * appropriate exception if they aren't.
- *
- * @param arrayLen the length of the array
- * @param fromIndex the index of the first element of the range
- * @param toIndex the index after the last element of the range
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
- * or toIndex > arrayLen
- */
- private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
- if (fromIndex > toIndex)
- throw new IllegalArgumentException("fromIndex(" + fromIndex +
- ") > toIndex(" + toIndex+")");
- if (fromIndex < 0)
- throw new ArrayIndexOutOfBoundsException(fromIndex);
- if (toIndex > arrayLen)
- throw new ArrayIndexOutOfBoundsException(toIndex);
- }
}
diff --git a/luni/src/main/java/java/util/Currency.java b/luni/src/main/java/java/util/Currency.java
index 84bf833..8ea8a96 100644
--- a/luni/src/main/java/java/util/Currency.java
+++ b/luni/src/main/java/java/util/Currency.java
@@ -17,11 +17,11 @@
package java.util;
-import com.ibm.icu4jni.util.ICU;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
/**
* This class represents a currency as identified in the ISO 4217 currency
diff --git a/luni/src/main/java/java/util/Deque.java b/luni/src/main/java/java/util/Deque.java
index 7ccc6f4..cb6bd90 100644
--- a/luni/src/main/java/java/util/Deque.java
+++ b/luni/src/main/java/java/util/Deque.java
@@ -1,255 +1,548 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Written by Doug Lea and Josh Bloch with assistance from members of
+ * JCP JSR-166 Expert Group and released to the public domain, as explained
+ * at http://creativecommons.org/licenses/publicdomain
*/
package java.util;
+// BEGIN android-note
+// removed link to collections framework docs
+// changed {@link #offer(Object)} to {@link #offer} to satisfy DroidDoc
+// END android-note
+
/**
- * A kind of collection that can insert or remove element at both ends("double
- * ended queue"). Mostly a deque has no limit of its size.
+ * A linear collection that supports element insertion and removal at
+ * both ends. The name <i>deque</i> is short for "double ended queue"
+ * and is usually pronounced "deck". Most <tt>Deque</tt>
+ * implementations place no fixed limits on the number of elements
+ * they may contain, but this interface supports capacity-restricted
+ * deques as well as those with no fixed size limit.
+ *
+ * <p>This interface defines methods to access the elements at both
+ * ends of the deque. Methods are provided to insert, remove, and
+ * examine the element. Each of these methods exists in two forms:
+ * one throws an exception if the operation fails, the other returns a
+ * special value (either <tt>null</tt> or <tt>false</tt>, depending on
+ * the operation). The latter form of the insert operation is
+ * designed specifically for use with capacity-restricted
+ * <tt>Deque</tt> implementations; in most implementations, insert
+ * operations cannot fail.
+ *
+ * <p>The twelve methods described above are summarized in the
+ * following table:
+ *
+ * <p>
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ * <tr>
+ * <td></td>
+ * <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
+ * <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
+ * </tr>
+ * <tr>
+ * <td></td>
+ * <td ALIGN=CENTER><em>Throws exception</em></td>
+ * <td ALIGN=CENTER><em>Special value</em></td>
+ * <td ALIGN=CENTER><em>Throws exception</em></td>
+ * <td ALIGN=CENTER><em>Special value</em></td>
+ * </tr>
+ * <tr>
+ * <td><b>Insert</b></td>
+ * <td>{@link #addFirst addFirst(e)}</td>
+ * <td>{@link #offerFirst offerFirst(e)}</td>
+ * <td>{@link #addLast addLast(e)}</td>
+ * <td>{@link #offerLast offerLast(e)}</td>
+ * </tr>
+ * <tr>
+ * <td><b>Remove</b></td>
+ * <td>{@link #removeFirst removeFirst()}</td>
+ * <td>{@link #pollFirst pollFirst()}</td>
+ * <td>{@link #removeLast removeLast()}</td>
+ * <td>{@link #pollLast pollLast()}</td>
+ * </tr>
+ * <tr>
+ * <td><b>Examine</b></td>
+ * <td>{@link #getFirst getFirst()}</td>
+ * <td>{@link #peekFirst peekFirst()}</td>
+ * <td>{@link #getLast getLast()}</td>
+ * <td>{@link #peekLast peekLast()}</td>
+ * </tr>
+ * </table>
+ *
+ * <p>This interface extends the {@link Queue} interface. When a deque is
+ * used as a queue, FIFO (First-In-First-Out) behavior results. Elements are
+ * added at the end of the deque and removed from the beginning. The methods
+ * inherited from the <tt>Queue</tt> interface are precisely equivalent to
+ * <tt>Deque</tt> methods as indicated in the following table:
+ *
+ * <p>
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ * <tr>
+ * <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
+ * <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#add add(e)}</td>
+ * <td>{@link #addLast addLast(e)}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#offer offer(e)}</td>
+ * <td>{@link #offerLast offerLast(e)}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#remove remove()}</td>
+ * <td>{@link #removeFirst removeFirst()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#poll poll()}</td>
+ * <td>{@link #pollFirst pollFirst()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#element element()}</td>
+ * <td>{@link #getFirst getFirst()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link java.util.Queue#peek peek()}</td>
+ * <td>{@link #peek peekFirst()}</td>
+ * </tr>
+ * </table>
+ *
+ * <p>Deques can also be used as LIFO (Last-In-First-Out) stacks. This
+ * interface should be used in preference to the legacy {@link Stack} class.
+ * When a deque is used as a stack, elements are pushed and popped from the
+ * beginning of the deque. Stack methods are precisely equivalent to
+ * <tt>Deque</tt> methods as indicated in the table below:
*
- * <p>Extending from Queue, a deque can be used as a Queue which behavior is
- * first-in-first-out. Furthermore, a deque can also be used as a Stack(legacy
- * class) which behavior is last-in-first-out.
+ * <p>
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ * <tr>
+ * <td ALIGN=CENTER> <b>Stack Method</b></td>
+ * <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
+ * </tr>
+ * <tr>
+ * <td>{@link #push push(e)}</td>
+ * <td>{@link #addFirst addFirst(e)}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link #pop pop()}</td>
+ * <td>{@link #removeFirst removeFirst()}</td>
+ * </tr>
+ * <tr>
+ * <td>{@link #peek peek()}</td>
+ * <td>{@link #peekFirst peekFirst()}</td>
+ * </tr>
+ * </table>
*
- * <p>A typical deque does not allow null to be inserted as its element, while some
- * implementations allow it. But null should not be inserted even in these
- * implementations, since method poll return null to indicate that there is no
- * element left in the deque.
+ * <p>Note that the {@link #peek peek} method works equally well when
+ * a deque is used as a queue or a stack; in either case, elements are
+ * drawn from the beginning of the deque.
*
- * <p>A deque can also remove interior elements by removeFirstOccurrence and
- * removeLastOccurrence methods. A deque can not access elements by index.
+ * <p>This interface provides two methods to remove interior
+ * elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
+ * {@link #removeLastOccurrence removeLastOccurrence}.
*
- * @param <E>
- * the type of elements in this collection
- * @since 1.6
+ * <p>Unlike the {@link List} interface, this interface does not
+ * provide support for indexed access to elements.
+ *
+ * <p>While <tt>Deque</tt> implementations are not strictly required
+ * to prohibit the insertion of null elements, they are strongly
+ * encouraged to do so. Users of any <tt>Deque</tt> implementations
+ * that do allow null elements are strongly encouraged <i>not</i> to
+ * take advantage of the ability to insert nulls. This is so because
+ * <tt>null</tt> is used as a special return value by various methods
+ * to indicated that the deque is empty.
+ *
+ * <p><tt>Deque</tt> implementations generally do not define
+ * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
+ * methods, but instead inherit the identity-based versions from class
+ * <tt>Object</tt>.
+ *
+ * @author Doug Lea
+ * @author Josh Bloch
+ * @since 1.6
+ * @param <E> the type of elements held in this collection
*/
-public interface Deque<E> extends Queue<E> {
+public interface Deque<E> extends Queue<E> {
/**
- * Inserts an element at the head of this deque if it dose not violate size
- * limit immediately. It is better to use offerFirst(E) if a deque is
- * size-limited.
+ * Inserts the specified element at the front of this deque if it is
+ * possible to do so immediately without violating capacity restrictions.
+ * When using a capacity-restricted deque, it is generally preferable to
+ * use method {@link #offerFirst}.
*
- * @param e
- * the element
- * @throws IllegalStateException
- * if it can not add now due to size limit
- * @throws ClassCastException
- * if the class of element can not be added into this deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
- * @throws IllegalArgumentException
- * if the element can not be added due to some property.
+ * @param e the element to add
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
*/
void addFirst(E e);
/**
- * Inserts an element at the tail of this deque if it dose not violate size
- * limit immediately. It is better to use offerLast(E) if a deque is
- * size-limited.
+ * Inserts the specified element at the end of this deque if it is
+ * possible to do so immediately without violating capacity restrictions.
+ * When using a capacity-restricted deque, it is generally preferable to
+ * use method {@link #offerLast}.
*
- * @param e
- * the element
- * @throws IllegalStateException
- * if it can not add now due to size limit
- * @throws ClassCastException
- * if the class of element can not be added into this deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
- * @throws IllegalArgumentException
- * if the element can not be added due to some property.
+ * <p>This method is equivalent to {@link #add}.
+ *
+ * @param e the element to add
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
*/
void addLast(E e);
/**
- * Inserts an element at the head of this deque unless it would violate size
- * limit. It is better than the addFirst(E) method in a size-limited deque,
- * because the latter one may fail to add the element only by throwing an
- * exception.
+ * Inserts the specified element at the front of this deque unless it would
+ * violate capacity restrictions. When using a capacity-restricted deque,
+ * this method is generally preferable to the {@link #addFirst} method,
+ * which can fail to insert an element only by throwing an exception.
*
- * @param e
- * the element
- * @return true if the operation succeeds or false if it fails.
- * @throws ClassCastException
- * if the class of element can not be added into this deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
- * @throws IllegalArgumentException
- * if the element can not be added due to some property.
+ * @param e the element to add
+ * @return <tt>true</tt> if the element was added to this deque, else
+ * <tt>false</tt>
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
*/
boolean offerFirst(E e);
/**
- * Inserts an element at the tail of this deque unless it would violate size
- * limit. It is better than the addLast(E) method in a size-limited deque,
- * because the latter one may fail to add the element only by throwing an
- * exception.
+ * Inserts the specified element at the end of this deque unless it would
+ * violate capacity restrictions. When using a capacity-restricted deque,
+ * this method is generally preferable to the {@link #addLast} method,
+ * which can fail to insert an element only by throwing an exception.
*
- * @param e
- * the element
- * @return true if the operation succeeds or false if it fails
- * @throws ClassCastException
- * if the class of element can not be added into this deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
- * @throws IllegalArgumentException
- * if the element can not be added due to some property
+ * @param e the element to add
+ * @return <tt>true</tt> if the element was added to this deque, else
+ * <tt>false</tt>
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
*/
boolean offerLast(E e);
/**
- * Gets and removes the head element of this deque. This method throws an
- * exception if the deque is empty.
+ * Retrieves and removes the first element of this deque. This method
+ * differs from {@link #pollFirst pollFirst} only in that it throws an
+ * exception if this deque is empty.
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
+ * @return the head of this deque
+ * @throws NoSuchElementException if this deque is empty
*/
E removeFirst();
/**
- * Gets and removes the tail element of this deque. This method throws an
- * exception if the deque is empty.
+ * Retrieves and removes the last element of this deque. This method
+ * differs from {@link #pollLast pollLast} only in that it throws an
+ * exception if this deque is empty.
*
- * @return the tail element
- * @throws NoSuchElementException
- * if the deque is empty
+ * @return the tail of this deque
+ * @throws NoSuchElementException if this deque is empty
*/
E removeLast();
/**
- * Gets and removes the head element of this deque. This method returns null
- * if the deque is empty.
+ * Retrieves and removes the first element of this deque,
+ * or returns <tt>null</tt> if this deque is empty.
*
- * @return the head element or null if the deque is empty
+ * @return the head of this deque, or <tt>null</tt> if this deque is empty
*/
E pollFirst();
/**
- * Gets and removes the tail element of this deque. This method returns null
- * if the deque is empty.
+ * Retrieves and removes the last element of this deque,
+ * or returns <tt>null</tt> if this deque is empty.
*
- * @return the tail element or null if the deque is empty
+ * @return the tail of this deque, or <tt>null</tt> if this deque is empty
*/
E pollLast();
/**
- * Gets but not removes the head element of this deque. This method throws
- * an exception if the deque is empty.
+ * Retrieves, but does not remove, the first element of this deque.
+ *
+ * This method differs from {@link #peekFirst peekFirst} only in that it
+ * throws an exception if this deque is empty.
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
+ * @return the head of this deque
+ * @throws NoSuchElementException if this deque is empty
*/
E getFirst();
/**
- * Gets but not removes the tail element of this deque. This method throws
- * an exception if the deque is empty.
+ * Retrieves, but does not remove, the last element of this deque.
+ * This method differs from {@link #peekLast peekLast} only in that it
+ * throws an exception if this deque is empty.
*
- * @return the tail element
- * @throws NoSuchElementException
- * if the deque is empty
+ * @return the tail of this deque
+ * @throws NoSuchElementException if this deque is empty
*/
E getLast();
/**
- * Gets but not removes the head element of this deque. This method returns
- * null if the deque is empty.
+ * Retrieves, but does not remove, the first element of this deque,
+ * or returns <tt>null</tt> if this deque is empty.
*
- * @return the head element or null if the deque is empty
+ * @return the head of this deque, or <tt>null</tt> if this deque is empty
*/
E peekFirst();
/**
- * Gets but not removes the tail element of this deque. This method returns
- * null if the deque is empty.
+ * Retrieves, but does not remove, the last element of this deque,
+ * or returns <tt>null</tt> if this deque is empty.
*
- * @return the tail element or null if the deque is empty
+ * @return the tail of this deque, or <tt>null</tt> if this deque is empty
*/
E peekLast();
/**
- * Removes the first equivalent element of the specified object. If the
- * deque does not contain the element, it is unchanged and returns false.
+ * Removes the first occurrence of the specified element from this deque.
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
+ * (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
*
- * @param o
- * the element to be removed
- * @return true if the operation succeeds or false if the deque does not
- * contain the element.
- * @throws ClassCastException
- * if the class of the element is incompatible with the deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if an element was removed as a result of this call
+ * @throws ClassCastException if the class of the specified element
+ * is incompatible with this deque (optional)
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements (optional)
*/
boolean removeFirstOccurrence(Object o);
/**
- * Removes the last equivalent element of the specified object. If the deque
- * does not contain the element, it is unchanged and returns false.
+ * Removes the last occurrence of the specified element from this deque.
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the last element <tt>e</tt> such that
+ * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
+ * (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
*
- * @param o
- * the element to be removed
- * @return true if the operation succeeds or false if the deque does not
- * contain the element.
- * @throws ClassCastException
- * if the class of the element is incompatible with the deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if an element was removed as a result of this call
+ * @throws ClassCastException if the class of the specified element
+ * is incompatible with this deque (optional)
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements (optional)
*/
boolean removeLastOccurrence(Object o);
+ // *** Queue methods ***
+
+ /**
+ * Inserts the specified element into the queue represented by this deque
+ * (in other words, at the tail of this deque) if it is possible to do so
+ * immediately without violating capacity restrictions, returning
+ * <tt>true</tt> upon success and throwing an
+ * <tt>IllegalStateException</tt> if no space is currently available.
+ * When using a capacity-restricted deque, it is generally preferable to
+ * use {@link #offer offer}.
+ *
+ * <p>This method is equivalent to {@link #addLast}.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
+ */
+ boolean add(E e);
+
+ /**
+ * Inserts the specified element into the queue represented by this deque
+ * (in other words, at the tail of this deque) if it is possible to do so
+ * immediately without violating capacity restrictions, returning
+ * <tt>true</tt> upon success and <tt>false</tt> if no space is currently
+ * available. When using a capacity-restricted deque, this method is
+ * generally preferable to the {@link #add} method, which can fail to
+ * insert an element only by throwing an exception.
+ *
+ * <p>This method is equivalent to {@link #offerLast}.
+ *
+ * @param e the element to add
+ * @return <tt>true</tt> if the element was added to this deque, else
+ * <tt>false</tt>
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
+ */
+ boolean offer(E e);
+
/**
- * Pushes the element to the deque(at the head of the deque), just same as
- * addFirst(E).
+ * Retrieves and removes the head of the queue represented by this deque
+ * (in other words, the first element of this deque).
+ * This method differs from {@link #poll poll} only in that it throws an
+ * exception if this deque is empty.
*
- * @param e
- * the element
- * @throws IllegalStateException
- * if it can not add now due to size limit
- * @throws ClassCastException
- * if the class of element can not be added into this deque
- * @throws NullPointerException
- * if the element is null and the deque can not contain null
- * element
- * @throws IllegalArgumentException
- * if the element can not be added due to some property.
+ * <p>This method is equivalent to {@link #removeFirst()}.
+ *
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException if this deque is empty
+ */
+ E remove();
+
+ /**
+ * Retrieves and removes the head of the queue represented by this deque
+ * (in other words, the first element of this deque), or returns
+ * <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #pollFirst()}.
+ *
+ * @return the first element of this deque, or <tt>null</tt> if
+ * this deque is empty
+ */
+ E poll();
+
+ /**
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque (in other words, the first element of this deque).
+ * This method differs from {@link #peek peek} only in that it throws an
+ * exception if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #getFirst()}.
+ *
+ * @return the head of the queue represented by this deque
+ * @throws NoSuchElementException if this deque is empty
+ */
+ E element();
+
+ /**
+ * Retrieves, but does not remove, the head of the queue represented by
+ * this deque (in other words, the first element of this deque), or
+ * returns <tt>null</tt> if this deque is empty.
+ *
+ * <p>This method is equivalent to {@link #peekFirst()}.
+ *
+ * @return the head of the queue represented by this deque, or
+ * <tt>null</tt> if this deque is empty
+ */
+ E peek();
+
+
+ // *** Stack methods ***
+
+ /**
+ * Pushes an element onto the stack represented by this deque (in other
+ * words, at the head of this deque) if it is possible to do so
+ * immediately without violating capacity restrictions, returning
+ * <tt>true</tt> upon success and throwing an
+ * <tt>IllegalStateException</tt> if no space is currently available.
+ *
+ * <p>This method is equivalent to {@link #addFirst}.
+ *
+ * @param e the element to push
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this deque
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements
+ * @throws IllegalArgumentException if some property of the specified
+ * element prevents it from being added to this deque
*/
void push(E e);
/**
- * Pops the head element of the deque, just same as removeFirst().
+ * Pops an element from the stack represented by this deque. In other
+ * words, removes and returns the first element of this deque.
*
- * @return the head element
- * @throws NoSuchElementException
- * if the deque is empty
+ * <p>This method is equivalent to {@link #removeFirst()}.
+ *
+ * @return the element at the front of this deque (which is the top
+ * of the stack represented by this deque)
+ * @throws NoSuchElementException if this deque is empty
*/
E pop();
+
+ // *** Collection methods ***
+
/**
- * Returns the iterator in reverse order, from tail to head.
+ * Removes the first occurrence of the specified element from this deque.
+ * If the deque does not contain the element, it is unchanged.
+ * More formally, removes the first element <tt>e</tt> such that
+ * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
+ * (if such an element exists).
+ * Returns <tt>true</tt> if this deque contained the specified element
+ * (or equivalently, if this deque changed as a result of the call).
+ *
+ * <p>This method is equivalent to {@link #removeFirstOccurrence}.
*
- * @return the iterator in reverse order
+ * @param o element to be removed from this deque, if present
+ * @return <tt>true</tt> if an element was removed as a result of this call
+ * @throws ClassCastException if the class of the specified element
+ * is incompatible with this deque (optional)
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements (optional)
+ */
+ boolean remove(Object o);
+
+ /**
+ * Returns <tt>true</tt> if this deque contains the specified element.
+ * More formally, returns <tt>true</tt> if and only if this deque contains
+ * at least one element <tt>e</tt> such that
+ * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
+ *
+ * @param o element whose presence in this deque is to be tested
+ * @return <tt>true</tt> if this deque contains the specified element
+ * @throws ClassCastException if the type of the specified element
+ * is incompatible with this deque (optional)
+ * @throws NullPointerException if the specified element is null and this
+ * deque does not permit null elements (optional)
+ */
+ boolean contains(Object o);
+
+ /**
+ * Returns the number of elements in this deque.
+ *
+ * @return the number of elements in this deque
+ */
+ public int size();
+
+ /**
+ * Returns an iterator over the elements in this deque in proper sequence.
+ * The elements will be returned in order from first (head) to last (tail).
+ *
+ * @return an iterator over the elements in this deque in proper sequence
+ */
+ Iterator<E> iterator();
+
+ /**
+ * Returns an iterator over the elements in this deque in reverse
+ * sequential order. The elements will be returned in order from
+ * last (tail) to first (head).
+ *
+ * @return an iterator over the elements in this deque in reverse
+ * sequence
*/
Iterator<E> descendingIterator();
-} \ No newline at end of file
+
+}
diff --git a/luni/src/main/java/java/util/DualPivotQuicksort.java b/luni/src/main/java/java/util/DualPivotQuicksort.java
index 6f1b4aa..97797d1 100644
--- a/luni/src/main/java/java/util/DualPivotQuicksort.java
+++ b/luni/src/main/java/java/util/DualPivotQuicksort.java
@@ -86,7 +86,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(int[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
doSort(a, fromIndex, toIndex - 1);
}
@@ -364,7 +364,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(long[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
doSort(a, fromIndex, toIndex - 1);
}
@@ -642,7 +642,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(short[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
doSort(a, fromIndex, toIndex - 1);
}
@@ -937,7 +937,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(char[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
doSort(a, fromIndex, toIndex - 1);
}
@@ -1230,7 +1230,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(byte[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
doSort(a, fromIndex, toIndex - 1);
}
@@ -1541,7 +1541,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(float[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
sortNegZeroAndNaN(a, fromIndex, toIndex - 1);
}
@@ -1914,7 +1914,7 @@ final class DualPivotQuicksort {
* if {@code fromIndex < 0} or {@code toIndex > a.length}
*/
public static void sort(double[] a, int fromIndex, int toIndex) {
- rangeCheck(a.length, fromIndex, toIndex);
+ Arrays.checkStartAndEnd(a.length, fromIndex, toIndex);
sortNegZeroAndNaN(a, fromIndex, toIndex - 1);
}
@@ -2247,21 +2247,4 @@ final class DualPivotQuicksort {
// Sort center part recursively, excluding known pivot values
doSort(a, less, great);
}
-
- /**
- * Checks that {@code fromIndex} and {@code toIndex} are in
- * the range and throws an appropriate exception, if they aren't.
- */
- private static void rangeCheck(int length, int fromIndex, int toIndex) {
- if (fromIndex > toIndex) {
- throw new IllegalArgumentException(
- "fromIndex(" + fromIndex + ") > toIndex(" + toIndex + ")");
- }
- if (fromIndex < 0) {
- throw new ArrayIndexOutOfBoundsException(fromIndex);
- }
- if (toIndex > length) {
- throw new ArrayIndexOutOfBoundsException(toIndex);
- }
- }
}
diff --git a/luni/src/main/java/java/util/EnumMap.java b/luni/src/main/java/java/util/EnumMap.java
index 2ccaff1..5da3b86 100644
--- a/luni/src/main/java/java/util/EnumMap.java
+++ b/luni/src/main/java/java/util/EnumMap.java
@@ -72,8 +72,11 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
Object enumKey = entry.getKey();
if (key.equals(enumKey)) {
Object theValue = entry.getValue();
- isEqual = enumMap.values[ordinal] == null ? null == theValue
- : enumMap.values[ordinal].equals(theValue);
+ if (enumMap.values[ordinal] == null) {
+ isEqual = (theValue == null);
+ } else {
+ isEqual = enumMap.values[ordinal].equals(theValue);
+ }
}
}
return isEqual;
@@ -262,9 +265,9 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
@Override
public boolean remove(Object object) {
- if (null == object) {
+ if (object == null) {
for (int i = 0; i < enumMap.enumSize; i++) {
- if (enumMap.hasMapping[i] && null == enumMap.values[i]) {
+ if (enumMap.hasMapping[i] && enumMap.values[i] == null) {
enumMap.remove(enumMap.keys[i]);
return true;
}
@@ -326,8 +329,11 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
Object enumValue = ((Map.Entry) object).getValue();
if (enumMap.containsKey(enumKey)) {
VT value = enumMap.get(enumKey);
- isEqual = (value == null ? null == enumValue : value
- .equals(enumValue));
+ if (value == null) {
+ isEqual = enumValue == null;
+ } else {
+ isEqual = value.equals(enumValue);
+ }
}
}
return isEqual;
@@ -430,7 +436,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
if (map instanceof EnumMap) {
initialization((EnumMap<K, V>) map);
} else {
- if (0 == map.size()) {
+ if (map.size() == 0) {
throw new IllegalArgumentException();
}
Iterator<K> iter = map.keySet().iterator();
@@ -502,9 +508,9 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
*/
@Override
public boolean containsValue(Object value) {
- if (null == value) {
+ if (value == null) {
for (int i = 0; i < enumSize; i++) {
- if (hasMapping[i] && null == values[i]) {
+ if (hasMapping[i] && values[i] == null) {
return true;
}
}
@@ -530,7 +536,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
*/
@Override
public Set<Map.Entry<K, V>> entrySet() {
- if (null == entrySet) {
+ if (entrySet == null) {
entrySet = new EnumMapEntrySet<K, V>(this);
}
return entrySet;
@@ -594,7 +600,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
*/
@Override
public Set<K> keySet() {
- if (null == keySet) {
+ if (keySet == null) {
keySet = new EnumMapKeySet<K, V>(this);
}
return keySet;
@@ -698,7 +704,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
*/
@Override
public Collection<V> values() {
- if (null == valuesCollection) {
+ if (valuesCollection == null) {
valuesCollection = new EnumMapValueCollection<K, V>(this);
}
return valuesCollection;
@@ -731,7 +737,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
}
private boolean isValidKeyType(Object key) {
- if (null != key && keyType.isInstance(key)) {
+ if (key != null && keyType.isInstance(key)) {
return true;
}
return false;
@@ -766,12 +772,10 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V> implements
@SuppressWarnings("unchecked")
private V putImpl(K key, V value) {
- if (null == key) {
+ if (key == null) {
throw new NullPointerException();
}
- if (!isValidKeyType(key)) {
- throw new ClassCastException();
- }
+ keyType.cast(key); // Called to throw ClassCastException.
int keyOrdinal = key.ordinal();
if (!hasMapping[keyOrdinal]) {
hasMapping[keyOrdinal] = true;
diff --git a/luni/src/main/java/java/util/EnumSet.java b/luni/src/main/java/java/util/EnumSet.java
index 48bfd3a..1b4723e 100644
--- a/luni/src/main/java/java/util/EnumSet.java
+++ b/luni/src/main/java/java/util/EnumSet.java
@@ -55,7 +55,7 @@ public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E>
*/
public static <E extends Enum<E>> EnumSet<E> noneOf(Class<E> elementType) {
if (!elementType.isEnum()) {
- throw new ClassCastException();
+ throw new ClassCastException(elementType.getClass().getName() + " is not an Enum");
}
// BEGIN android-changed
E[] enums = SpecialAccess.LANG.getEnumValuesInOrder(elementType);
diff --git a/luni/src/main/java/java/util/FormatFlagsConversionMismatchException.java b/luni/src/main/java/java/util/FormatFlagsConversionMismatchException.java
index 73d8a64..5792877 100644
--- a/luni/src/main/java/java/util/FormatFlagsConversionMismatchException.java
+++ b/luni/src/main/java/java/util/FormatFlagsConversionMismatchException.java
@@ -43,7 +43,7 @@ public class FormatFlagsConversionMismatchException extends
* the conversion.
*/
public FormatFlagsConversionMismatchException(String f, char c) {
- if (null == f) {
+ if (f == null) {
throw new NullPointerException();
}
this.f = f;
diff --git a/luni/src/main/java/java/util/Formatter.java b/luni/src/main/java/java/util/Formatter.java
index 02111c0..490ae8e 100644
--- a/luni/src/main/java/java/util/Formatter.java
+++ b/luni/src/main/java/java/util/Formatter.java
@@ -15,8 +15,6 @@
*/
package java.util;
-import com.ibm.icu4jni.text.NativeDecimalFormat;
-import com.ibm.icu4jni.util.LocaleData;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.File;
@@ -34,6 +32,9 @@ import java.math.MathContext;
import java.nio.charset.Charset;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import libcore.icu.LocaleData;
+import libcore.icu.NativeDecimalFormat;
+import libcore.io.IoUtils;
/**
* Formats arguments according to a format string (like {@code printf} in C).
@@ -828,10 +829,10 @@ public final class Formatter implements Closeable, Flushable {
fout = new FileOutputStream(file);
out = new BufferedWriter(new OutputStreamWriter(fout, csn));
} catch (RuntimeException e) {
- closeOutputStream(fout);
+ IoUtils.closeQuietly(fout);
throw e;
} catch (UnsupportedEncodingException e) {
- closeOutputStream(fout);
+ IoUtils.closeQuietly(fout);
throw e;
}
@@ -1138,17 +1139,6 @@ public final class Formatter implements Closeable, Flushable {
return args[index];
}
- private static void closeOutputStream(OutputStream os) {
- if (os == null) {
- return;
- }
- try {
- os.close();
- } catch (IOException e) {
- // silently
- }
- }
-
/*
* Complete details of a single format specifier parsed from a format string.
*/
@@ -2169,7 +2159,9 @@ public final class Formatter implements Closeable, Flushable {
private void transform_g(StringBuilder result) {
int precision = formatToken.getPrecision();
- precision = (0 == precision ? 1 : precision);
+ if (precision == 0) {
+ precision = 1;
+ }
formatToken.setPrecision(precision);
double d = ((Number) arg).doubleValue();
@@ -2278,7 +2270,9 @@ public final class Formatter implements Closeable, Flushable {
}
int precision = formatToken.getPrecision();
- precision = (0 == precision ? 1 : precision);
+ if (precision == 0) {
+ precision = 1;
+ }
int indexOfFirstFractionalDigit = result.indexOf(".") + 1;
int indexOfP = result.indexOf("p");
int fractionalLength = indexOfP - indexOfFirstFractionalDigit;
diff --git a/luni/src/main/java/java/util/HashMap.java b/luni/src/main/java/java/util/HashMap.java
index 1e5bd0e..4a4e6f6 100644
--- a/luni/src/main/java/java/util/HashMap.java
+++ b/luni/src/main/java/java/util/HashMap.java
@@ -529,7 +529,7 @@ public class HashMap<K, V> extends AbstractMap<K, V> implements Cloneable, Seria
if (newCapacity <= oldCapacity) {
return;
}
- if (newCapacity == oldCapacity << 1) {
+ if (newCapacity == oldCapacity * 2) {
doubleCapacity();
return;
}
@@ -575,7 +575,7 @@ public class HashMap<K, V> extends AbstractMap<K, V> implements Cloneable, Seria
if (oldCapacity == MAXIMUM_CAPACITY) {
return oldTable;
}
- int newCapacity = oldCapacity << 1;
+ int newCapacity = oldCapacity * 2;
HashMapEntry<K, V>[] newTable = makeTable(newCapacity);
if (size == 0) {
return newTable;
diff --git a/luni/src/main/java/java/util/Hashtable.java b/luni/src/main/java/java/util/Hashtable.java
index d260df2..03e80a9 100644
--- a/luni/src/main/java/java/util/Hashtable.java
+++ b/luni/src/main/java/java/util/Hashtable.java
@@ -451,7 +451,7 @@ public class Hashtable<K, V> extends Dictionary<K, V>
rehash(); // Does nothing!!
- if (newCapacity == oldCapacity << 1) {
+ if (newCapacity == oldCapacity * 2) {
doubleCapacity();
return;
}
@@ -508,7 +508,7 @@ public class Hashtable<K, V> extends Dictionary<K, V>
if (oldCapacity == MAXIMUM_CAPACITY) {
return oldTable;
}
- int newCapacity = oldCapacity << 1;
+ int newCapacity = oldCapacity * 2;
HashtableEntry<K, V>[] newTable = makeTable(newCapacity);
if (size == 0) {
return newTable;
diff --git a/luni/src/main/java/java/util/HugeEnumSet.java b/luni/src/main/java/java/util/HugeEnumSet.java
index ef90d8e..2c6395f 100644
--- a/luni/src/main/java/java/util/HugeEnumSet.java
+++ b/luni/src/main/java/java/util/HugeEnumSet.java
@@ -121,10 +121,7 @@ final class HugeEnumSet<E extends Enum<E>> extends EnumSet<E> {
@Override
public boolean add(E element) {
- if (!isValidType(element.getDeclaringClass())) {
- throw new ClassCastException();
- }
-
+ elementClass.cast(element); // Called to throw ClassCastException.
int ordinal = element.ordinal();
int index = ordinal / BIT_IN_LONG;
int inBits = ordinal % BIT_IN_LONG;
@@ -146,9 +143,7 @@ final class HugeEnumSet<E extends Enum<E>> extends EnumSet<E> {
if (collection instanceof EnumSet) {
EnumSet<?> set = (EnumSet) collection; // raw type due to javac bug 6548436
- if (!isValidType(set.elementClass)) {
- throw new ClassCastException();
- }
+ set.elementClass.asSubclass(elementClass); // Called to throw ClassCastException.
HugeEnumSet<E> hugeSet = (HugeEnumSet<E>) set;
boolean changed = false;
diff --git a/luni/src/main/java/java/util/IdentityHashMap.java b/luni/src/main/java/java/util/IdentityHashMap.java
index 9678b9d..827ffcf 100644
--- a/luni/src/main/java/java/util/IdentityHashMap.java
+++ b/luni/src/main/java/java/util/IdentityHashMap.java
@@ -83,8 +83,11 @@ public class IdentityHashMap<K, V> extends AbstractMap<K, V> implements
private static final Object NULL_OBJECT = new Object(); //$NON-LOCK-1$
static class IdentityHashMapEntry<K, V> extends MapEntry<K, V> {
- IdentityHashMapEntry(K theKey, V theValue) {
+ private final IdentityHashMap<K,V> map;
+
+ IdentityHashMapEntry(IdentityHashMap<K,V> map, K theKey, V theValue) {
super(theKey, theValue);
+ this.map = map;
}
@Override
@@ -114,6 +117,13 @@ public class IdentityHashMap<K, V> extends AbstractMap<K, V> implements
public String toString() {
return key + "=" + value;
}
+
+ @Override
+ public V setValue(V object) {
+ V result = super.setValue(object);
+ map.put(key, object);
+ return result;
+ }
}
static class IdentityHashMapIterator<E, KT, VT> implements Iterator<E> {
@@ -407,7 +417,7 @@ public class IdentityHashMap<K, V> extends AbstractMap<K, V> implements
value = null;
}
- return new IdentityHashMapEntry<K, V>((K) key, (V) value);
+ return new IdentityHashMapEntry<K, V>(this, (K) key, (V) value);
}
/**
@@ -495,7 +505,7 @@ public class IdentityHashMap<K, V> extends AbstractMap<K, V> implements
}
private void rehash() {
- int newlength = elementData.length << 1;
+ int newlength = elementData.length * 2;
if (newlength == 0) {
newlength = 1;
}
diff --git a/luni/src/main/java/java/util/LinkedList.java b/luni/src/main/java/java/util/LinkedList.java
index e264ed0..2d264c2 100644
--- a/luni/src/main/java/java/util/LinkedList.java
+++ b/luni/src/main/java/java/util/LinkedList.java
@@ -67,7 +67,7 @@ public class LinkedList<E> extends AbstractSequentialList<E> implements
LinkIterator(LinkedList<ET> object, int location) {
list = object;
expectedModCount = list.modCount;
- if (0 <= location && location <= list.size) {
+ if (location >= 0 && location <= list.size) {
// pos ends up as -1 if list is empty, it ranges from -1 to
// list.size - 1
// if link == voidLink then pos must == -1
@@ -277,7 +277,7 @@ public class LinkedList<E> extends AbstractSequentialList<E> implements
*/
@Override
public void add(int location, E object) {
- if (0 <= location && location <= size) {
+ if (location >= 0 && location <= size) {
Link<E> link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) {
@@ -504,7 +504,7 @@ public class LinkedList<E> extends AbstractSequentialList<E> implements
@Override
public E get(int location) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
Link<E> link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) {
@@ -639,7 +639,7 @@ public class LinkedList<E> extends AbstractSequentialList<E> implements
*/
@Override
public E remove(int location) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
Link<E> link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) {
@@ -860,7 +860,7 @@ public class LinkedList<E> extends AbstractSequentialList<E> implements
*/
@Override
public E set(int location, E object) {
- if (0 <= location && location < size) {
+ if (location >= 0 && location < size) {
Link<E> link = voidLink;
if (location < (size / 2)) {
for (int i = 0; i <= location; i++) {
diff --git a/luni/src/main/java/java/util/Locale.java b/luni/src/main/java/java/util/Locale.java
index 79e148f..9e26f65 100644
--- a/luni/src/main/java/java/util/Locale.java
+++ b/luni/src/main/java/java/util/Locale.java
@@ -17,13 +17,13 @@
package java.util;
-import com.ibm.icu4jni.util.ICU;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamField;
import java.io.Serializable;
import java.security.AccessController;
+import libcore.icu.ICU;
import org.apache.harmony.luni.util.PriviAction;
import org.apache.harmony.luni.util.Util;
@@ -58,8 +58,8 @@ import org.apache.harmony.luni.util.Util;
* nor any locales for other languages (such as de_DE). The opposite may well be true for a device
* sold in Europe.
*
- * <p>You can use {@code getDefault} to get an appropriate locale for the <i>user</i> of
- * the device you're running on, or {@code getAvailableLocales} to get a list of all the locales
+ * <p>You can use {@link Locale#getDefault} to get an appropriate locale for the <i>user</i> of the
+ * device you're running on, or {@link Locale#getAvailableLocales} to get a list of all the locales
* available on the device you're running on.
*
* <a name="locale_data"><h3>Locale data</h3></a>
@@ -71,24 +71,37 @@ import org.apache.harmony.luni.util.Util;
* <table BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
* <tr><td>cupcake/donut/eclair</td> <td>ICU 3.8</td> <td><a href="http://www.unicode.org/press/pr-cldr1.5.html">CLDR 1.5</a></td> <td><a href="http://www.unicode.org/versions/Unicode5.0.0/">Unicode 5.0</a></td></tr>
* <tr><td>froyo</td> <td>ICU 4.2</td> <td><a href="http://www.unicode.org/press/pr-cldr1.7.html">CLDR 1.7</a></td> <td><a href="http://www.unicode.org/versions/Unicode5.1.0/">Unicode 5.1</a></td></tr>
- * <tr><td>gingerbread</td> <td>ICU 4.4</td> <td><a href="http://www.unicode.org/press/pr-cldr1.8.html">CLDR 1.8</a></td> <td><a href="http://www.unicode.org/versions/Unicode5.2.0/">Unicode 5.2</a></td></tr>
+ * <tr><td>gingerbread/honeycomb</td><td>ICU 4.4</td> <td><a href="http://www.unicode.org/press/pr-cldr1.8.html">CLDR 1.8</a></td> <td><a href="http://www.unicode.org/versions/Unicode5.2.0/">Unicode 5.2</a></td></tr>
* </table>
*
* <a name="default_locale"><h3>Be wary of the default locale</h3></a>
* <p>Note that there are many convenience methods that automatically use the default locale, but
- * these may not be as convenient as you imagine. The default locale is appropriate for anything
- * that involves presenting data to the user. You should use the user's date/time formats, number
- * formats, rules for conversion to lowercase, and so on. A common mistake is to implicitly use the
- * default locale when producing output meant to be machine-readable. This tends to work on the
- * developer's test devices but fail when run on a device whose user is in a less conventional
- * locale. For example, if you're formatting integers some locales will use non-ASCII decimal
+ * using them may lead to subtle bugs.
+ *
+ * <p>The default locale is appropriate for tasks that involve presenting data to the user. In
+ * this case, you want to use the user's date/time formats, number
+ * formats, rules for conversion to lowercase, and so on. In this case, it's safe to use the
+ * convenience methods.
+ *
+ * <p>The default locale is <i>not</i> appropriate for machine-readable output. The best choice
+ * there is usually {@code Locale.US}&nbsp;&ndash; this locale is guaranteed to be available on all
+ * devices, and the fact that it has no surprising special cases and is frequently used (especially
+ * for computer-computer communication) means that it tends to be the most efficient choice too.
+ *
+ * <p>A common mistake is to implicitly use the default locale when producing output meant to be
+ * machine-readable. This tends to work on the developer's test devices (especially because so many
+ * developers use en_US), but fails when run on a device whose user is in a more complex locale.
+ *
+ * <p>For example, if you're formatting integers some locales will use non-ASCII decimal
* digits. As another example, if you're formatting floating-point numbers some locales will use
- * {@code ','} as the decimal point. That's correct for human-readable output, but likely to cause
- * problems if presented to another computer ({@code Double.parseDouble} can't parse such a number,
- * for example). The best choice for computer-readable output is usually {@code Locale.US}: this
- * locale is guaranteed to be available on all devices, and the combination of no surprising
- * behavior and frequent use (especially for computer-computer communication) means that it tends
- * to be the most efficient choice too.
+ * {@code ','} as the decimal point and {@code '.'} for digit grouping. That's correct for
+ * human-readable output, but likely to cause problems if presented to another
+ * computer ({@link Double#parseDouble} can't parse such a number, for example).
+ * You should also be wary of the {@link String#toLowerCase} and
+ * {@link String#toUpperCase} overloads that don't take a {@code Locale}: in Turkey, for example,
+ * the characters {@code 'i'} and {@code 'I'} won't be converted to {@code 'I'} and {@code 'i'}.
+ * This is the correct behavior for Turkish text (such as user input), but inappropriate for, say,
+ * HTTP headers.
*/
public final class Locale implements Cloneable, Serializable {
@@ -406,10 +419,17 @@ public final class Locale implements Cloneable, Serializable {
/**
* Returns this locale's language name, country name, and variant, localized
* to {@code locale}. The exact output form depends on whether this locale
- * corresponds to a specific language, country and variant, such as:
- * {@code English}, {@code English (United States)}, {@code English (United
- * States,Computer)}, {@code anglais (&#x00c9;tats-Unis)}, {@code anglais
- * (&#x00c9;tats-Unis,informatique)}.
+ * corresponds to a specific language, country and variant.
+ *
+ * <p>For example:
+ * <ul>
+ * <li>{@code new Locale("en").getDisplayName(Locale.US)} -> {@code English}
+ * <li>{@code new Locale("en", "US").getDisplayName(Locale.US)} -> {@code English (United States)}
+ * <li>{@code new Locale("en", "US", "POSIX").getDisplayName(Locale.US)} -> {@code English (United States,Computer)}
+ * <li>{@code new Locale("en").getDisplayName(Locale.FRANCE)} -> {@code anglais}
+ * <li>{@code new Locale("en", "US").getDisplayName(Locale.FRANCE)} -> {@code anglais (États-Unis)}
+ * <li>{@code new Locale("en", "US", "POSIX").getDisplayName(Locale.FRANCE)} -> {@code anglais (États-Unis,informatique)}.
+ * </ul>
*/
public String getDisplayName(Locale locale) {
int count = 0;
@@ -444,24 +464,18 @@ public final class Locale implements Cloneable, Serializable {
}
/**
- * Gets the full variant name in the default {@code Locale} for the variant code of
+ * Returns the full variant name in the default {@code Locale} for the variant code of
* this {@code Locale}. If there is no matching variant name, the variant code is
* returned.
- *
- * @return a variant name.
*/
public final String getDisplayVariant() {
return getDisplayVariant(getDefault());
}
/**
- * Gets the full variant name in the specified {@code Locale} for the variant code
+ * Returns the full variant name in the specified {@code Locale} for the variant code
* of this {@code Locale}. If there is no matching variant name, the variant code is
* returned.
- *
- * @param locale
- * the {@code Locale} for which the display name is retrieved.
- * @return a variant name.
*/
public String getDisplayVariant(Locale locale) {
if (variantCode.length() == 0) {
@@ -475,14 +489,10 @@ public final class Locale implements Cloneable, Serializable {
}
/**
- * Gets the three letter ISO country code which corresponds to the country
+ * Returns the three letter ISO country code which corresponds to the country
* code for this {@code Locale}.
- *
- * @return a three letter ISO language code.
- * @throws MissingResourceException
- * if there is no matching three letter ISO country code.
*/
- public String getISO3Country() throws MissingResourceException {
+ public String getISO3Country() {
if (countryCode.length() == 0) {
return countryCode;
}
@@ -490,14 +500,10 @@ public final class Locale implements Cloneable, Serializable {
}
/**
- * Gets the three letter ISO language code which corresponds to the language
+ * Returns the three letter ISO language code which corresponds to the language
* code for this {@code Locale}.
- *
- * @return a three letter ISO language code.
- * @throws MissingResourceException
- * if there is no matching three letter ISO language code.
*/
- public String getISO3Language() throws MissingResourceException {
+ public String getISO3Language() {
if (languageCode.length() == 0) {
return languageCode;
}
@@ -505,52 +511,37 @@ public final class Locale implements Cloneable, Serializable {
}
/**
- * Gets the list of two letter ISO country codes which can be used as the
- * country code for a {@code Locale}.
- *
- * @return an array of strings.
+ * Returns an array of strings containing all the two-letter ISO country codes that can be
+ * used as the country code when constructing a {@code Locale}.
*/
public static String[] getISOCountries() {
return ICU.getISOCountries();
}
/**
- * Gets the list of two letter ISO language codes which can be used as the
- * language code for a {@code Locale}.
- *
- * @return an array of strings.
+ * Returns an array of strings containing all the two-letter ISO language codes that can be
+ * used as the language code when constructing a {@code Locale}.
*/
public static String[] getISOLanguages() {
return ICU.getISOLanguages();
}
/**
- * Gets the language code for this {@code Locale} or the empty string of no language
+ * Returns the language code for this {@code Locale} or the empty string if no language
* was set.
- *
- * @return a language code.
*/
public String getLanguage() {
return languageCode;
}
/**
- * Gets the variant code for this {@code Locale} or an empty {@code String} if no variant
+ * Returns the variant code for this {@code Locale} or an empty {@code String} if no variant
* was set.
- *
- * @return a variant code.
*/
public String getVariant() {
return variantCode;
}
- /**
- * Returns an integer hash code for the receiver. Objects which are equal
- * return the same value for this method.
- *
- * @return the receiver's hash.
- * @see #equals
- */
@Override
public synchronized int hashCode() {
return countryCode.hashCode() + languageCode.hashCode()
@@ -588,8 +579,6 @@ public final class Locale implements Cloneable, Serializable {
* return the empty string.
*
* <p>Examples: "en", "en_US", "_US", "en__POSIX", "en_US_POSIX"
- *
- * @return the string representation of this {@code Locale}.
*/
@Override
public final String toString() {
diff --git a/luni/src/main/java/java/util/MiniEnumSet.java b/luni/src/main/java/java/util/MiniEnumSet.java
index e19612a..c4c7364 100644
--- a/luni/src/main/java/java/util/MiniEnumSet.java
+++ b/luni/src/main/java/java/util/MiniEnumSet.java
@@ -108,10 +108,7 @@ final class MiniEnumSet<E extends Enum<E>> extends EnumSet<E> {
@Override
public boolean add(E element) {
- if (!isValidType(element.getDeclaringClass())) {
- throw new ClassCastException();
- }
-
+ elementClass.cast(element); // Called to throw ClassCastException.
long oldBits = bits;
long newBits = oldBits | (1L << element.ordinal());
if (oldBits != newBits) {
@@ -129,9 +126,7 @@ final class MiniEnumSet<E extends Enum<E>> extends EnumSet<E> {
}
if (collection instanceof EnumSet) {
EnumSet<?> set = (EnumSet) collection; // raw type due to javac bug 6548436
- if (!isValidType(set.elementClass)) {
- throw new ClassCastException();
- }
+ set.elementClass.asSubclass(elementClass); // Called to throw ClassCastException.
MiniEnumSet<?> miniSet = (MiniEnumSet<?>) set;
long oldBits = bits;
diff --git a/luni/src/main/java/java/util/MissingFormatArgumentException.java b/luni/src/main/java/java/util/MissingFormatArgumentException.java
index cd56f87..ce72efa 100644
--- a/luni/src/main/java/java/util/MissingFormatArgumentException.java
+++ b/luni/src/main/java/java/util/MissingFormatArgumentException.java
@@ -36,7 +36,7 @@ public class MissingFormatArgumentException extends IllegalFormatException {
* the specified conversion that lacks the argument.
*/
public MissingFormatArgumentException(String s) {
- if (null == s) {
+ if (s == null) {
throw new NullPointerException();
}
this.s = s;
diff --git a/luni/src/main/java/java/util/MissingFormatWidthException.java b/luni/src/main/java/java/util/MissingFormatWidthException.java
index 842b0c4..b6d0ca6 100644
--- a/luni/src/main/java/java/util/MissingFormatWidthException.java
+++ b/luni/src/main/java/java/util/MissingFormatWidthException.java
@@ -35,7 +35,7 @@ public class MissingFormatWidthException extends IllegalFormatException {
* the specified format specifier.
*/
public MissingFormatWidthException(String s) {
- if (null == s) {
+ if (s == null) {
throw new NullPointerException();
}
this.s = s;
diff --git a/luni/src/main/java/java/util/NavigableMap.java b/luni/src/main/java/java/util/NavigableMap.java
index a87a8c0..29961c8 100644
--- a/luni/src/main/java/java/util/NavigableMap.java
+++ b/luni/src/main/java/java/util/NavigableMap.java
@@ -1,262 +1,396 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ * Written by Doug Lea and Josh Bloch with assistance from members of JCP
+ * JSR-166 Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
*/
package java.util;
+// BEGIN android-note
+// removed link to collections framework docs
+// changed {@link #subMap(Object)} to {@link #subMap} to satisfy DroidDoc
+// END android-note
+
/**
- * NavigableMap is a SortedMap with navigation methods answering the closest
- * matches for specified item.
+ * A {@link SortedMap} extended with navigation methods returning the
+ * closest matches for given search targets. Methods
+ * {@code lowerEntry}, {@code floorEntry}, {@code ceilingEntry},
+ * and {@code higherEntry} return {@code Map.Entry} objects
+ * associated with keys respectively less than, less than or equal,
+ * greater than or equal, and greater than a given key, returning
+ * {@code null} if there is no such key. Similarly, methods
+ * {@code lowerKey}, {@code floorKey}, {@code ceilingKey}, and
+ * {@code higherKey} return only the associated keys. All of these
+ * methods are designed for locating, not traversing entries.
+ *
+ * <p>A {@code NavigableMap} may be accessed and traversed in either
+ * ascending or descending key order. The {@code descendingMap}
+ * method returns a view of the map with the senses of all relational
+ * and directional methods inverted. The performance of ascending
+ * operations and views is likely to be faster than that of descending
+ * ones. Methods {@code subMap}, {@code headMap},
+ * and {@code tailMap} differ from the like-named {@code
+ * SortedMap} methods in accepting additional arguments describing
+ * whether lower and upper bounds are inclusive versus exclusive.
+ * Submaps of any {@code NavigableMap} must implement the {@code
+ * NavigableMap} interface.
*
- * @param <K>
- * the type of key
- * @param <V>
- * the type of value
+ * <p>This interface additionally defines methods {@code firstEntry},
+ * {@code pollFirstEntry}, {@code lastEntry}, and
+ * {@code pollLastEntry} that return and/or remove the least and
+ * greatest mappings, if any exist, else returning {@code null}.
+ *
+ * <p>Implementations of entry-returning methods are expected to
+ * return {@code Map.Entry} pairs representing snapshots of mappings
+ * at the time they were produced, and thus generally do <em>not</em>
+ * support the optional {@code Entry.setValue} method. Note however
+ * that it is possible to change mappings in the associated map using
+ * method {@code put}.
+ *
+ * <p>Methods
+ * {@link #subMap subMap(K, K)},
+ * {@link #headMap headMap(K)}, and
+ * {@link #tailMap tailMap(K)}
+ * are specified to return {@code SortedMap} to allow existing
+ * implementations of {@code SortedMap} to be compatibly retrofitted to
+ * implement {@code NavigableMap}, but extensions and implementations
+ * of this interface are encouraged to override these methods to return
+ * {@code NavigableMap}. Similarly,
+ * {@link #keySet()} can be overriden to return {@code NavigableSet}.
+ *
+ * @author Doug Lea
+ * @author Josh Bloch
+ * @param <K> the type of keys maintained by this map
+ * @param <V> the type of mapped values
* @since 1.6
*/
-public interface NavigableMap<K, V> extends SortedMap<K, V> {
+public interface NavigableMap<K,V> extends SortedMap<K,V> {
/**
- * Returns the entry with the smallest key, or null if the map is empty.
+ * Returns a key-value mapping associated with the greatest key
+ * strictly less than the given key, or {@code null} if there is
+ * no such key.
*
- * @return the entry with the smallest key, or null if the map is empty
+ * @param key the key
+ * @return an entry with the greatest key less than {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> firstEntry();
+ Map.Entry<K,V> lowerEntry(K key);
/**
- * Returns the entry with the biggest key, or null if the map is empty.
+ * Returns the greatest key strictly less than the given key, or
+ * {@code null} if there is no such key.
*
- * @return the entry with the biggest key, or null if the map is empty
+ * @param key the key
+ * @return the greatest key less than {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> lastEntry();
+ K lowerKey(K key);
/**
- * Deletes and returns the entry with the smallest key, or null if the map
- * is empty.
+ * Returns a key-value mapping associated with the greatest key
+ * less than or equal to the given key, or {@code null} if there
+ * is no such key.
*
- * @return the entry with the smallest key, or null if the map is empty
+ * @param key the key
+ * @return an entry with the greatest key less than or equal to
+ * {@code key}, or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> pollFirstEntry();
+ Map.Entry<K,V> floorEntry(K key);
/**
- * Deletes and returns the entry with the biggest key, or null if the map is
- * empty.
+ * Returns the greatest key less than or equal to the given key,
+ * or {@code null} if there is no such key.
*
- * @return the entry with the biggest key, or null if the map is empty
+ * @param key the key
+ * @return the greatest key less than or equal to {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> pollLastEntry();
+ K floorKey(K key);
/**
- * Returns an entry related with the smallest key greater than or equal to
- * the specified key, or null if no such key.
+ * Returns a key-value mapping associated with the least key
+ * greater than or equal to the given key, or {@code null} if
+ * there is no such key.
*
- * @param key
- * the key
- * @return the entry, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @param key the key
+ * @return an entry with the least key greater than or equal to
+ * {@code key}, or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> ceilingEntry(K key);
+ Map.Entry<K,V> ceilingEntry(K key);
/**
- * Returns the smallest key greater than or equal to the specified key, or
- * null if no such key.
+ * Returns the least key greater than or equal to the given key,
+ * or {@code null} if there is no such key.
*
- * @param key
- * the key
- * @return the smallest key greater than or equal to key, or null if no such
- * key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @param key the key
+ * @return the least key greater than or equal to {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
K ceilingKey(K key);
/**
- * Returns an entry related with the smallest key greater than the specified
- * key, or null if no such key.
+ * Returns a key-value mapping associated with the least key
+ * strictly greater than the given key, or {@code null} if there
+ * is no such key.
*
- * @param key
- * the key
- * @return the entry, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @param key the key
+ * @return an entry with the least key greater than {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
- Map.Entry<K, V> higherEntry(K key);
+ Map.Entry<K,V> higherEntry(K key);
/**
- * Returns the smallest key greater than the specified key, or null if no
- * such key.
+ * Returns the least key strictly greater than the given key, or
+ * {@code null} if there is no such key.
*
- * @param key
- * the key
- * @return the smallest key greater than key, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @param key the key
+ * @return the least key greater than {@code key},
+ * or {@code null} if there is no such key
+ * @throws ClassCastException if the specified key cannot be compared
+ * with the keys currently in the map
+ * @throws NullPointerException if the specified key is null
+ * and this map does not permit null keys
*/
K higherKey(K key);
/**
- * Returns an entry related with the biggest key less than or equal to the
- * specified key, or null if no such key.
+ * Returns a key-value mapping associated with the least
+ * key in this map, or {@code null} if the map is empty.
*
- * @param key
- * the key
- * @return the entry, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @return an entry with the least key,
+ * or {@code null} if this map is empty
*/
- Map.Entry<K, V> floorEntry(K key);
+ Map.Entry<K,V> firstEntry();
/**
- * Returns the biggest key less than or equal to the specified key, or null
- * if no such key.
+ * Returns a key-value mapping associated with the greatest
+ * key in this map, or {@code null} if the map is empty.
*
- * @param key
- * the key
- * @return the biggest key less than or equal to key, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @return an entry with the greatest key,
+ * or {@code null} if this map is empty
*/
- K floorKey(K key);
+ Map.Entry<K,V> lastEntry();
/**
- * Returns an entry related with the biggest key less than the specified
- * key, or null if no such key.
+ * Removes and returns a key-value mapping associated with
+ * the least key in this map, or {@code null} if the map is empty.
*
- * @param key
- * the key
- * @return the entry, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @return the removed first entry of this map,
+ * or {@code null} if this map is empty
*/
- Map.Entry<K, V> lowerEntry(K key);
+ Map.Entry<K,V> pollFirstEntry();
/**
- * Returns the biggest key less than the specified key, or null if no such
- * key.
+ * Removes and returns a key-value mapping associated with
+ * the greatest key in this map, or {@code null} if the map is empty.
*
- * @param key
- * the key
- * @return the biggest key less than key, or null if no such key
- * @throws ClassCastException
- * if the key cannot be compared with the keys in the map
- * @throws NullPointerException
- * if the key is null and the map can not contain null key
+ * @return the removed last entry of this map,
+ * or {@code null} if this map is empty
*/
- K lowerKey(K key);
+ Map.Entry<K,V> pollLastEntry();
/**
- * Returns a NavigableSet view of the keys in ascending order.
+ * Returns a reverse order view of the mappings contained in this map.
+ * The descending map is backed by this map, so changes to the map are
+ * reflected in the descending map, and vice-versa. If either map is
+ * modified while an iteration over a collection view of either map
+ * is in progress (except through the iterator's own {@code remove}
+ * operation), the results of the iteration are undefined.
+ *
+ * <p>The returned map has an ordering equivalent to
+ * <tt>{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator())</tt>.
+ * The expression {@code m.descendingMap().descendingMap()} returns a
+ * view of {@code m} essentially equivalent to {@code m}.
*
- * @return the navigable set view
+ * @return a reverse order view of this map
*/
- NavigableSet<K> navigableKeySet();
+ NavigableMap<K,V> descendingMap();
/**
- * Returns a reverse order view of the map.
+ * Returns a {@link NavigableSet} view of the keys contained in this map.
+ * The set's iterator returns the keys in ascending order.
+ * The set is backed by the map, so changes to the map are reflected in
+ * the set, and vice-versa. If the map is modified while an iteration
+ * over the set is in progress (except through the iterator's own {@code
+ * remove} operation), the results of the iteration are undefined. The
+ * set supports element removal, which removes the corresponding mapping
+ * from the map, via the {@code Iterator.remove}, {@code Set.remove},
+ * {@code removeAll}, {@code retainAll}, and {@code clear} operations.
+ * It does not support the {@code add} or {@code addAll} operations.
*
- * @return the reverse order view of the map
+ * @return a navigable set view of the keys in this map
*/
- NavigableMap<K, V> descendingMap();
+ NavigableSet<K> navigableKeySet();
/**
- * Returns a NavigableSet view of the keys in descending order.
+ * Returns a reverse order {@link NavigableSet} view of the keys contained in this map.
+ * The set's iterator returns the keys in descending order.
+ * The set is backed by the map, so changes to the map are reflected in
+ * the set, and vice-versa. If the map is modified while an iteration
+ * over the set is in progress (except through the iterator's own {@code
+ * remove} operation), the results of the iteration are undefined. The
+ * set supports element removal, which removes the corresponding mapping
+ * from the map, via the {@code Iterator.remove}, {@code Set.remove},
+ * {@code removeAll}, {@code retainAll}, and {@code clear} operations.
+ * It does not support the {@code add} or {@code addAll} operations.
*
- * @return the navigable set view
+ * @return a reverse order navigable set view of the keys in this map
*/
NavigableSet<K> descendingKeySet();
/**
- * Returns a view of part of the map whose keys is from startKey to endKey.
+ * Returns a view of the portion of this map whose keys range from
+ * {@code fromKey} to {@code toKey}. If {@code fromKey} and
+ * {@code toKey} are equal, the returned map is empty unless
+ * {@code fromExclusive} and {@code toExclusive} are both true. The
+ * returned map is backed by this map, so changes in the returned map are
+ * reflected in this map, and vice-versa. The returned map supports all
+ * optional map operations that this map supports.
+ *
+ * <p>The returned map will throw an {@code IllegalArgumentException}
+ * on an attempt to insert a key outside of its range, or to construct a
+ * submap either of whose endpoints lie outside its range.
+ *
+ * @param fromKey low endpoint of the keys in the returned map
+ * @param fromInclusive {@code true} if the low endpoint
+ * is to be included in the returned view
+ * @param toKey high endpoint of the keys in the returned map
+ * @param toInclusive {@code true} if the high endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this map whose keys range from
+ * {@code fromKey} to {@code toKey}
+ * @throws ClassCastException if {@code fromKey} and {@code toKey}
+ * cannot be compared to one another using this map's comparator
+ * (or, if the map has no comparator, using natural ordering).
+ * Implementations may, but are not required to, throw this
+ * exception if {@code fromKey} or {@code toKey}
+ * cannot be compared to keys currently in the map.
+ * @throws NullPointerException if {@code fromKey} or {@code toKey}
+ * is null and this map does not permit null keys
+ * @throws IllegalArgumentException if {@code fromKey} is greater than
+ * {@code toKey}; or if this map itself has a restricted
+ * range, and {@code fromKey} or {@code toKey} lies
+ * outside the bounds of the range
+ */
+ NavigableMap<K,V> subMap(K fromKey, boolean fromInclusive,
+ K toKey, boolean toInclusive);
+
+ /**
+ * Returns a view of the portion of this map whose keys are less than (or
+ * equal to, if {@code inclusive} is true) {@code toKey}. The returned
+ * map is backed by this map, so changes in the returned map are reflected
+ * in this map, and vice-versa. The returned map supports all optional
+ * map operations that this map supports.
+ *
+ * <p>The returned map will throw an {@code IllegalArgumentException}
+ * on an attempt to insert a key outside its range.
+ *
+ * @param toKey high endpoint of the keys in the returned map
+ * @param inclusive {@code true} if the high endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this map whose keys are less than
+ * (or equal to, if {@code inclusive} is true) {@code toKey}
+ * @throws ClassCastException if {@code toKey} is not compatible
+ * with this map's comparator (or, if the map has no comparator,
+ * if {@code toKey} does not implement {@link Comparable}).
+ * Implementations may, but are not required to, throw this
+ * exception if {@code toKey} cannot be compared to keys
+ * currently in the map.
+ * @throws NullPointerException if {@code toKey} is null
+ * and this map does not permit null keys
+ * @throws IllegalArgumentException if this map itself has a
+ * restricted range, and {@code toKey} lies outside the
+ * bounds of the range
+ */
+ NavigableMap<K,V> headMap(K toKey, boolean inclusive);
+
+ /**
+ * Returns a view of the portion of this map whose keys are greater than (or
+ * equal to, if {@code inclusive} is true) {@code fromKey}. The returned
+ * map is backed by this map, so changes in the returned map are reflected
+ * in this map, and vice-versa. The returned map supports all optional
+ * map operations that this map supports.
+ *
+ * <p>The returned map will throw an {@code IllegalArgumentException}
+ * on an attempt to insert a key outside its range.
+ *
+ * @param fromKey low endpoint of the keys in the returned map
+ * @param inclusive {@code true} if the low endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this map whose keys are greater than
+ * (or equal to, if {@code inclusive} is true) {@code fromKey}
+ * @throws ClassCastException if {@code fromKey} is not compatible
+ * with this map's comparator (or, if the map has no comparator,
+ * if {@code fromKey} does not implement {@link Comparable}).
+ * Implementations may, but are not required to, throw this
+ * exception if {@code fromKey} cannot be compared to keys
+ * currently in the map.
+ * @throws NullPointerException if {@code fromKey} is null
+ * and this map does not permit null keys
+ * @throws IllegalArgumentException if this map itself has a
+ * restricted range, and {@code fromKey} lies outside the
+ * bounds of the range
+ */
+ NavigableMap<K,V> tailMap(K fromKey, boolean inclusive);
+
+ /**
+ * {@inheritDoc}
*
- * @param startKey
- * the start key
- * @param startInclusive
- * true if the start key is in the returned map
- * @param endKey
- * the end key
- * @param endInclusive
- * true if the end key is in the returned map
- * @return the sub-map view
+ * <p>Equivalent to {@code subMap(fromKey, true, toKey, false)}.
*
- * @exception ClassCastException
- * when the class of the start or end key is inappropriate
- * for this SubMap
- * @exception NullPointerException
- * when the start or end key is null and this SortedMap does
- * not support null keys
- * @exception IllegalArgumentException
- * when the start key is greater than the end key
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
*/
- NavigableMap<K, V> subMap(K startKey, boolean startInclusive, K endKey,
- boolean endInclusive);
+ SortedMap<K,V> subMap(K fromKey, K toKey);
/**
- * Returns a view of the head of the map whose keys are smaller than (or
- * equal to, depends on inclusive argument) endKey.
+ * {@inheritDoc}
*
- * @param endKey
- * the end key
- * @param inclusive
- * true if the end key is in the returned map
- * @return the head-map view
+ * <p>Equivalent to {@code headMap(toKey, false)}.
*
- * @exception ClassCastException
- * when the class of the end key is inappropriate for this
- * SubMap
- * @exception NullPointerException
- * when the end key is null and this SortedMap does not
- * support null keys
- * @exception IllegalArgumentException
- * when the map is range-limited and end key is out of the
- * range of the map
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
*/
- NavigableMap<K, V> headMap(K endKey, boolean inclusive);
+ SortedMap<K,V> headMap(K toKey);
/**
- * Returns a view of the tail of the map whose keys are bigger than (or
- * equal to, depends on inclusive argument) startKey.
+ * {@inheritDoc}
*
- * @param startKey
- * the start key
- * @param inclusive
- * true if the start key is in the returned map
- * @return the tail-map view
+ * <p>Equivalent to {@code tailMap(fromKey, true)}.
*
- * @exception ClassCastException
- * when the class of the start key is inappropriate for this
- * SubMap
- * @exception NullPointerException
- * when the start key is null and this SortedMap does not
- * support null keys
- * @exception IllegalArgumentException
- * when the map is range-limited and start key is out of the
- * range of the map
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
*/
- NavigableMap<K, V> tailMap(K startKey, boolean inclusive);
-} \ No newline at end of file
+ SortedMap<K,V> tailMap(K fromKey);
+}
diff --git a/luni/src/main/java/java/util/NavigableSet.java b/luni/src/main/java/java/util/NavigableSet.java
index ae94b77..cff0800 100644
--- a/luni/src/main/java/java/util/NavigableSet.java
+++ b/luni/src/main/java/java/util/NavigableSet.java
@@ -1,192 +1,291 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Written by Doug Lea and Josh Bloch with assistance from members of JCP
+ * JSR-166 Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
*/
package java.util;
+// BEGIN android-note
+// removed link to collections framework docs
+// changed {@link #subSet(Object)} to {@link #subSet} to satisfy DroidDoc
+// END android-note
+
/**
- * NavigableSet is a SortedSet with navigation methods answering the closest
- * matches for specified item.
+ * A {@link SortedSet} extended with navigation methods reporting
+ * closest matches for given search targets. Methods {@code lower},
+ * {@code floor}, {@code ceiling}, and {@code higher} return elements
+ * respectively less than, less than or equal, greater than or equal,
+ * and greater than a given element, returning {@code null} if there
+ * is no such element. A {@code NavigableSet} may be accessed and
+ * traversed in either ascending or descending order. The {@code
+ * descendingSet} method returns a view of the set with the senses of
+ * all relational and directional methods inverted. The performance of
+ * ascending operations and views is likely to be faster than that of
+ * descending ones. This interface additionally defines methods
+ * {@code pollFirst} and {@code pollLast} that return and remove the
+ * lowest and highest element, if one exists, else returning {@code
+ * null}. Methods {@code subSet}, {@code headSet},
+ * and {@code tailSet} differ from the like-named {@code
+ * SortedSet} methods in accepting additional arguments describing
+ * whether lower and upper bounds are inclusive versus exclusive.
+ * Subsets of any {@code NavigableSet} must implement the {@code
+ * NavigableSet} interface.
*
- * @param <E>
- * the type of element
+ * <p> The return values of navigation methods may be ambiguous in
+ * implementations that permit {@code null} elements. However, even
+ * in this case the result can be disambiguated by checking
+ * {@code contains(null)}. To avoid such issues, implementations of
+ * this interface are encouraged to <em>not</em> permit insertion of
+ * {@code null} elements. (Note that sorted sets of {@link
+ * Comparable} elements intrinsically do not permit {@code null}.)
+ *
+ * <p>Methods
+ * {@link #subSet subSet(E, E)},
+ * {@link #headSet headSet(E)}, and
+ * {@link #tailSet tailSet(E)}
+ * are specified to return {@code SortedSet} to allow existing
+ * implementations of {@code SortedSet} to be compatibly retrofitted to
+ * implement {@code NavigableSet}, but extensions and implementations
+ * of this interface are encouraged to override these methods to return
+ * {@code NavigableSet}.
+ *
+ * @author Doug Lea
+ * @author Josh Bloch
+ * @param <E> the type of elements maintained by this set
* @since 1.6
*/
public interface NavigableSet<E> extends SortedSet<E> {
+ /**
+ * Returns the greatest element in this set strictly less than the
+ * given element, or {@code null} if there is no such element.
+ *
+ * @param e the value to match
+ * @return the greatest element less than {@code e},
+ * or {@code null} if there is no such element
+ * @throws ClassCastException if the specified element cannot be
+ * compared with the elements currently in the set
+ * @throws NullPointerException if the specified element is null
+ * and this set does not permit null elements
+ */
+ E lower(E e);
/**
- * Deletes and returns the smallest element, or null if the set is empty.
+ * Returns the greatest element in this set less than or equal to
+ * the given element, or {@code null} if there is no such element.
*
- * @return the smallest element, or null if the set is empty
+ * @param e the value to match
+ * @return the greatest element less than or equal to {@code e},
+ * or {@code null} if there is no such element
+ * @throws ClassCastException if the specified element cannot be
+ * compared with the elements currently in the set
+ * @throws NullPointerException if the specified element is null
+ * and this set does not permit null elements
*/
- E pollFirst();
+ E floor(E e);
/**
- * Deletes and returns the biggest element, or null if the set is empty.
+ * Returns the least element in this set greater than or equal to
+ * the given element, or {@code null} if there is no such element.
*
- * @return the biggest element, or null if the set is empty
+ * @param e the value to match
+ * @return the least element greater than or equal to {@code e},
+ * or {@code null} if there is no such element
+ * @throws ClassCastException if the specified element cannot be
+ * compared with the elements currently in the set
+ * @throws NullPointerException if the specified element is null
+ * and this set does not permit null elements
*/
- E pollLast();
+ E ceiling(E e);
/**
- * Returns the smallest element bigger than the specified one, or null if no
- * such element.
- *
- * @param e
- * the specified element
- * @return the smallest element bigger than the specified one, or null if no
- * such element
- * @throws ClassCastException
- * if the element cannot be compared with the ones in the set
- * @throws NullPointerException
- * if the element is null and the set can not contain null
+ * Returns the least element in this set strictly greater than the
+ * given element, or {@code null} if there is no such element.
+ *
+ * @param e the value to match
+ * @return the least element greater than {@code e},
+ * or {@code null} if there is no such element
+ * @throws ClassCastException if the specified element cannot be
+ * compared with the elements currently in the set
+ * @throws NullPointerException if the specified element is null
+ * and this set does not permit null elements
*/
E higher(E e);
/**
- * Returns the smallest element bigger than or equal to the specified one,
- * or null if no such element.
- *
- * @param e
- * the specified element
- * @return the smallest element bigger than or equal to the specified one,
- * or null if no such element
- * @throws ClassCastException
- * if the element cannot be compared with the ones in the set
- * @throws NullPointerException
- * if the element is null and the set can not contain null
+ * Retrieves and removes the first (lowest) element,
+ * or returns {@code null} if this set is empty.
+ *
+ * @return the first element, or {@code null} if this set is empty
*/
- E ceiling(E e);
+ E pollFirst();
/**
- * Returns the biggest element less than the specified one, or null if no
- * such element.
- *
- * @param e
- * the specified element
- * @return the biggest element less than the specified one, or null if no
- * such element
- * @throws ClassCastException
- * if the element cannot be compared with the ones in the set
- * @throws NullPointerException
- * if the element is null and the set can not contain null
+ * Retrieves and removes the last (highest) element,
+ * or returns {@code null} if this set is empty.
+ *
+ * @return the last element, or {@code null} if this set is empty
*/
- E lower(E e);
+ E pollLast();
/**
- * Returns the biggest element less than or equal to the specified one, or
- * null if no such element.
- *
- * @param e
- * the specified element
- * @return the biggest element less than or equal to the specified one, or
- * null if no such element
- * @throws ClassCastException
- * if the element cannot be compared with the ones in the set
- * @throws NullPointerException
- * if the element is null and the set can not contain null
+ * Returns an iterator over the elements in this set, in ascending order.
+ *
+ * @return an iterator over the elements in this set, in ascending order
*/
- E floor(E e);
+ Iterator<E> iterator();
/**
- * Returns a descending iterator of this set.
+ * Returns a reverse order view of the elements contained in this set.
+ * The descending set is backed by this set, so changes to the set are
+ * reflected in the descending set, and vice-versa. If either set is
+ * modified while an iteration over either set is in progress (except
+ * through the iterator's own {@code remove} operation), the results of
+ * the iteration are undefined.
+ *
+ * <p>The returned set has an ordering equivalent to
+ * <tt>{@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator())</tt>.
+ * The expression {@code s.descendingSet().descendingSet()} returns a
+ * view of {@code s} essentially equivalent to {@code s}.
*
- * @return the descending iterator
+ * @return a reverse order view of this set
+ */
+ NavigableSet<E> descendingSet();
+
+ /**
+ * Returns an iterator over the elements in this set, in descending order.
+ * Equivalent in effect to {@code descendingSet().iterator()}.
+ *
+ * @return an iterator over the elements in this set, in descending order
*/
Iterator<E> descendingIterator();
/**
- * Returns a reverse order view of this set.
+ * Returns a view of the portion of this set whose elements range from
+ * {@code fromElement} to {@code toElement}. If {@code fromElement} and
+ * {@code toElement} are equal, the returned set is empty unless {@code
+ * fromExclusive} and {@code toExclusive} are both true. The returned set
+ * is backed by this set, so changes in the returned set are reflected in
+ * this set, and vice-versa. The returned set supports all optional set
+ * operations that this set supports.
+ *
+ * <p>The returned set will throw an {@code IllegalArgumentException}
+ * on an attempt to insert an element outside its range.
*
- * @return the reverse order view
+ * @param fromElement low endpoint of the returned set
+ * @param fromInclusive {@code true} if the low endpoint
+ * is to be included in the returned view
+ * @param toElement high endpoint of the returned set
+ * @param toInclusive {@code true} if the high endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this set whose elements range from
+ * {@code fromElement}, inclusive, to {@code toElement}, exclusive
+ * @throws ClassCastException if {@code fromElement} and
+ * {@code toElement} cannot be compared to one another using this
+ * set's comparator (or, if the set has no comparator, using
+ * natural ordering). Implementations may, but are not required
+ * to, throw this exception if {@code fromElement} or
+ * {@code toElement} cannot be compared to elements currently in
+ * the set.
+ * @throws NullPointerException if {@code fromElement} or
+ * {@code toElement} is null and this set does
+ * not permit null elements
+ * @throws IllegalArgumentException if {@code fromElement} is
+ * greater than {@code toElement}; or if this set itself
+ * has a restricted range, and {@code fromElement} or
+ * {@code toElement} lies outside the bounds of the range.
*/
- NavigableSet<E> descendingSet();
+ NavigableSet<E> subSet(E fromElement, boolean fromInclusive,
+ E toElement, boolean toInclusive);
+
+ /**
+ * Returns a view of the portion of this set whose elements are less than
+ * (or equal to, if {@code inclusive} is true) {@code toElement}. The
+ * returned set is backed by this set, so changes in the returned set are
+ * reflected in this set, and vice-versa. The returned set supports all
+ * optional set operations that this set supports.
+ *
+ * <p>The returned set will throw an {@code IllegalArgumentException}
+ * on an attempt to insert an element outside its range.
+ *
+ * @param toElement high endpoint of the returned set
+ * @param inclusive {@code true} if the high endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this set whose elements are less than
+ * (or equal to, if {@code inclusive} is true) {@code toElement}
+ * @throws ClassCastException if {@code toElement} is not compatible
+ * with this set's comparator (or, if the set has no comparator,
+ * if {@code toElement} does not implement {@link Comparable}).
+ * Implementations may, but are not required to, throw this
+ * exception if {@code toElement} cannot be compared to elements
+ * currently in the set.
+ * @throws NullPointerException if {@code toElement} is null and
+ * this set does not permit null elements
+ * @throws IllegalArgumentException if this set itself has a
+ * restricted range, and {@code toElement} lies outside the
+ * bounds of the range
+ */
+ NavigableSet<E> headSet(E toElement, boolean inclusive);
/**
- * Returns a NavigableSet of the specified portion of this set which
- * contains elements greater (or equal to, depends on startInclusive) the
- * start element but less than (or equal to, depends on endInclusive) the
- * end element. The returned NavigableSet is backed by this set so changes
- * to one are reflected by the other.
- *
- * @param start
- * the start element
- * @param startInclusive
- * true if the start element is in the returned set
- * @param end
- * the end element
- * @param endInclusive
- * true if the end element is in the returned set
- * @return the subset
- *
- * @throws ClassCastException
- * when the start or end object cannot be compared with the
- * elements in this set
- * @throws NullPointerException
- * when the start or end object is null and the set cannot
- * contain null
- * @throws IllegalArgumentException
- * when the start is bigger than end; or start or end is out of
- * range and the set has a range
+ * Returns a view of the portion of this set whose elements are greater
+ * than (or equal to, if {@code inclusive} is true) {@code fromElement}.
+ * The returned set is backed by this set, so changes in the returned set
+ * are reflected in this set, and vice-versa. The returned set supports
+ * all optional set operations that this set supports.
+ *
+ * <p>The returned set will throw an {@code IllegalArgumentException}
+ * on an attempt to insert an element outside its range.
+ *
+ * @param fromElement low endpoint of the returned set
+ * @param inclusive {@code true} if the low endpoint
+ * is to be included in the returned view
+ * @return a view of the portion of this set whose elements are greater
+ * than or equal to {@code fromElement}
+ * @throws ClassCastException if {@code fromElement} is not compatible
+ * with this set's comparator (or, if the set has no comparator,
+ * if {@code fromElement} does not implement {@link Comparable}).
+ * Implementations may, but are not required to, throw this
+ * exception if {@code fromElement} cannot be compared to elements
+ * currently in the set.
+ * @throws NullPointerException if {@code fromElement} is null
+ * and this set does not permit null elements
+ * @throws IllegalArgumentException if this set itself has a
+ * restricted range, and {@code fromElement} lies outside the
+ * bounds of the range
*/
- NavigableSet<E> subSet(E start, boolean startInclusive, E end,
- boolean endInclusive);
+ NavigableSet<E> tailSet(E fromElement, boolean inclusive);
/**
- * Returns a NavigableSet of the specified portion of this set which
- * contains elements less than (or equal to, depends on endInclusive) the
- * end element. The returned NavigableSet is backed by this set so changes
- * to one are reflected by the other.
- *
- * @param end
- * the end element
- * @param endInclusive
- * true if the end element is in the returned set
- * @return the subset
- *
- * @throws ClassCastException
- * when the end object cannot be compared with the elements in
- * this set
- * @throws NullPointerException
- * when the end object is null and the set cannot contain handle
- * null
- * @throws IllegalArgumentException
- * when end is out of range and the set has a range
+ * {@inheritDoc}
+ *
+ * <p>Equivalent to {@code subSet(fromElement, true, toElement, false)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
*/
- NavigableSet<E> headSet(E end, boolean endInclusive);
+ SortedSet<E> subSet(E fromElement, E toElement);
/**
- * Returns a NavigableSet of the specified portion of this set which
- * contains elements greater (or equal to, depends on startInclusive) the
- * start element. The returned NavigableSet is backed by this set so changes
- * to one are reflected by the other.
- *
- * @param start
- * the start element
- * @param startInclusive
- * true if the start element is in the returned set
- * @return the subset
- *
- * @throws ClassCastException
- * when the start object cannot be compared with the elements in
- * this set
- * @throws NullPointerException
- * when the start object is null and the set cannot contain null
- * @throws IllegalArgumentException
- * when start is out of range and the set has a range
+ * {@inheritDoc}
+ *
+ * <p>Equivalent to {@code headSet(toElement, false)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
+na */
+ SortedSet<E> headSet(E toElement);
+
+ /**
+ * {@inheritDoc}
+ *
+ * <p>Equivalent to {@code tailSet(fromElement, true)}.
+ *
+ * @throws ClassCastException {@inheritDoc}
+ * @throws NullPointerException {@inheritDoc}
+ * @throws IllegalArgumentException {@inheritDoc}
*/
- NavigableSet<E> tailSet(E start, boolean startInclusive);
-} \ No newline at end of file
+ SortedSet<E> tailSet(E fromElement);
+}
diff --git a/luni/src/main/java/java/util/PriorityQueue.java b/luni/src/main/java/java/util/PriorityQueue.java
index 30fce2e..10c5968 100644
--- a/luni/src/main/java/java/util/PriorityQueue.java
+++ b/luni/src/main/java/java/util/PriorityQueue.java
@@ -185,7 +185,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable {
* if {@code o} is {@code null}.
*/
public boolean offer(E o) {
- if (null == o) {
+ if (o == null) {
throw new NullPointerException();
}
growToSize(size + 1);
@@ -347,7 +347,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable {
}
private int compare(E o1, E o2) {
- if (null != comparator) {
+ if (comparator != null) {
return comparator.compare(o1, o2);
}
return ((Comparable<? super E>) o1).compareTo(o2);
@@ -386,7 +386,7 @@ public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable {
}
private void initSize(Collection<? extends E> c) {
- if (null == c) {
+ if (c == null) {
throw new NullPointerException();
}
if (c.isEmpty()) {
diff --git a/luni/src/main/java/java/util/Properties.java b/luni/src/main/java/java/util/Properties.java
index 34a8faa..bff7ebc 100644
--- a/luni/src/main/java/java/util/Properties.java
+++ b/luni/src/main/java/java/util/Properties.java
@@ -471,31 +471,25 @@ public class Properties extends Hashtable<Object, Object> {
* @since 1.6
*/
public Set<String> stringPropertyNames() {
- Hashtable<String, String> stringProperties = new Hashtable<String, String>();
+ Hashtable<String, Object> stringProperties = new Hashtable<String, Object>();
selectProperties(stringProperties, true);
return Collections.unmodifiableSet(stringProperties.keySet());
}
- private void selectProperties(Hashtable selectProperties, final boolean isStringOnly) {
+ private <K> void selectProperties(Hashtable<K, Object> selectProperties, final boolean isStringOnly) {
if (defaults != null) {
defaults.selectProperties(selectProperties, isStringOnly);
}
- Enumeration<?> keys = keys();
- Object key, value;
+ Enumeration<Object> keys = keys();
while (keys.hasMoreElements()) {
- key = keys.nextElement();
- if (isStringOnly) {
+ @SuppressWarnings("unchecked")
+ K key = (K) keys.nextElement();
+ if (isStringOnly && !(key instanceof String)) {
// Only select property with string key and value
- if (key instanceof String) {
- value = get(key);
- if (value instanceof String) {
- selectProperties.put(key, value);
- }
- }
- } else {
- value = get(key);
- selectProperties.put(key, value);
+ continue;
}
+ Object value = get(key);
+ selectProperties.put(key, value);
}
}
diff --git a/luni/src/main/java/java/util/Queue.java b/luni/src/main/java/java/util/Queue.java
index 51899e3..5aef944 100644
--- a/luni/src/main/java/java/util/Queue.java
+++ b/luni/src/main/java/java/util/Queue.java
@@ -1,91 +1,188 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Written by Doug Lea with assistance from members of JCP JSR-166
+ * Expert Group and released to the public domain, as explained at
+ * http://creativecommons.org/licenses/publicdomain
*/
+
package java.util;
+// BEGIN android-note
+// removed link to collections framework docs
+// END android-note
+
/**
- * This kind of collection provides advanced operations compared to basic
- * collections, such as insertion, extraction, and inspection.
- * <p>
- * Generally, a queue orders its elements by means of first-in-first-out.
- * However, a priority queue orders its elements according to a comparator
- * specified or the elements' natural order. Furthermore, a stack orders its
- * elements last-in-first out.
- * <p>
- * A typical queue does not allow {@code null} to be inserted as its element,
- * while some implementations such as {@code LinkedList} allow it. But {@code
- * null} should not be inserted even in these implementations, since the method
- * {@code poll} returns {@code null} to indicate that there is no element left
- * in the queue.
+ * A collection designed for holding elements prior to processing.
+ * Besides basic {@link java.util.Collection Collection} operations,
+ * queues provide additional insertion, extraction, and inspection
+ * operations. Each of these methods exists in two forms: one throws
+ * an exception if the operation fails, the other returns a special
+ * value (either <tt>null</tt> or <tt>false</tt>, depending on the
+ * operation). The latter form of the insert operation is designed
+ * specifically for use with capacity-restricted <tt>Queue</tt>
+ * implementations; in most implementations, insert operations cannot
+ * fail.
+ *
* <p>
- * {@code Queue} does not provide blocking queue methods, which would block
- * until the operation of the method is allowed. See the
- * {@link java.util.concurrent.BlockingQueue} interface for information about
- * blocking queue methods.
+ * <table BORDER CELLPADDING=3 CELLSPACING=1>
+ * <tr>
+ * <td></td>
+ * <td ALIGN=CENTER><em>Throws exception</em></td>
+ * <td ALIGN=CENTER><em>Returns special value</em></td>
+ * </tr>
+ * <tr>
+ * <td><b>Insert</b></td>
+ * <td>{@link #add add(e)}</td>
+ * <td>{@link #offer offer(e)}</td>
+ * </tr>
+ * <tr>
+ * <td><b>Remove</b></td>
+ * <td>{@link #remove remove()}</td>
+ * <td>{@link #poll poll()}</td>
+ * </tr>
+ * <tr>
+ * <td><b>Examine</b></td>
+ * <td>{@link #element element()}</td>
+ * <td>{@link #peek peek()}</td>
+ * </tr>
+ * </table>
+ *
+ * <p>Queues typically, but do not necessarily, order elements in a
+ * FIFO (first-in-first-out) manner. Among the exceptions are
+ * priority queues, which order elements according to a supplied
+ * comparator, or the elements' natural ordering, and LIFO queues (or
+ * stacks) which order the elements LIFO (last-in-first-out).
+ * Whatever the ordering used, the <em>head</em> of the queue is that
+ * element which would be removed by a call to {@link #remove() } or
+ * {@link #poll()}. In a FIFO queue, all new elements are inserted at
+ * the <em> tail</em> of the queue. Other kinds of queues may use
+ * different placement rules. Every <tt>Queue</tt> implementation
+ * must specify its ordering properties.
+ *
+ * <p>The {@link #offer offer} method inserts an element if possible,
+ * otherwise returning <tt>false</tt>. This differs from the {@link
+ * java.util.Collection#add Collection.add} method, which can fail to
+ * add an element only by throwing an unchecked exception. The
+ * <tt>offer</tt> method is designed for use when failure is a normal,
+ * rather than exceptional occurrence, for example, in fixed-capacity
+ * (or &quot;bounded&quot;) queues.
+ *
+ * <p>The {@link #remove()} and {@link #poll()} methods remove and
+ * return the head of the queue.
+ * Exactly which element is removed from the queue is a
+ * function of the queue's ordering policy, which differs from
+ * implementation to implementation. The <tt>remove()</tt> and
+ * <tt>poll()</tt> methods differ only in their behavior when the
+ * queue is empty: the <tt>remove()</tt> method throws an exception,
+ * while the <tt>poll()</tt> method returns <tt>null</tt>.
+ *
+ * <p>The {@link #element()} and {@link #peek()} methods return, but do
+ * not remove, the head of the queue.
+ *
+ * <p>The <tt>Queue</tt> interface does not define the <i>blocking queue
+ * methods</i>, which are common in concurrent programming. These methods,
+ * which wait for elements to appear or for space to become available, are
+ * defined in the {@link java.util.concurrent.BlockingQueue} interface, which
+ * extends this interface.
+ *
+ * <p><tt>Queue</tt> implementations generally do not allow insertion
+ * of <tt>null</tt> elements, although some implementations, such as
+ * {@link LinkedList}, do not prohibit insertion of <tt>null</tt>.
+ * Even in the implementations that permit it, <tt>null</tt> should
+ * not be inserted into a <tt>Queue</tt>, as <tt>null</tt> is also
+ * used as a special return value by the <tt>poll</tt> method to
+ * indicate that the queue contains no elements.
+ *
+ * <p><tt>Queue</tt> implementations generally do not define
+ * element-based versions of methods <tt>equals</tt> and
+ * <tt>hashCode</tt> but instead inherit the identity based versions
+ * from class <tt>Object</tt>, because element-based equality is not
+ * always well-defined for queues with the same elements but different
+ * ordering properties.
+ *
+ * @see java.util.Collection
+ * @see LinkedList
+ * @see PriorityQueue
+ * @see java.util.concurrent.LinkedBlockingQueue
+ * @see java.util.concurrent.BlockingQueue
+ * @see java.util.concurrent.ArrayBlockingQueue
+ * @see java.util.concurrent.LinkedBlockingQueue
+ * @see java.util.concurrent.PriorityBlockingQueue
+ * @since 1.5
+ * @author Doug Lea
+ * @param <E> the type of elements held in this collection
*/
public interface Queue<E> extends Collection<E> {
-
/**
- * Inserts the specified element into the queue provided that the condition
- * allows such an operation. The method is generally preferable to
- * {@link Collection#add}, since the latter might throw an exception if the
- * operation fails.
+ * Inserts the specified element into this queue if it is possible to do so
+ * immediately without violating capacity restrictions, returning
+ * <tt>true</tt> upon success and throwing an <tt>IllegalStateException</tt>
+ * if no space is currently available.
*
- * @param o
- * the specified element to insert into the queue.
- * @return {@code true} if the operation succeeds and {@code false} if it
- * fails.
+ * @param e the element to add
+ * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @throws IllegalStateException if the element cannot be added at this
+ * time due to capacity restrictions
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this queue
+ * @throws NullPointerException if the specified element is null and
+ * this queue does not permit null elements
+ * @throws IllegalArgumentException if some property of this element
+ * prevents it from being added to this queue
*/
- public boolean offer(E o);
+ boolean add(E e);
/**
- * Gets and removes the element at the head of the queue, or returns {@code
- * null} if there is no element in the queue.
+ * Inserts the specified element into this queue if it is possible to do
+ * so immediately without violating capacity restrictions.
+ * When using a capacity-restricted queue, this method is generally
+ * preferable to {@link #add}, which can fail to insert an element only
+ * by throwing an exception.
*
- * @return the element at the head of the queue or {@code null} if there is
- * no element in the queue.
+ * @param e the element to add
+ * @return <tt>true</tt> if the element was added to this queue, else
+ * <tt>false</tt>
+ * @throws ClassCastException if the class of the specified element
+ * prevents it from being added to this queue
+ * @throws NullPointerException if the specified element is null and
+ * this queue does not permit null elements
+ * @throws IllegalArgumentException if some property of this element
+ * prevents it from being added to this queue
*/
- public E poll();
+ boolean offer(E e);
/**
- * Gets and removes the element at the head of the queue. Throws a
- * NoSuchElementException if there is no element in the queue.
+ * Retrieves and removes the head of this queue. This method differs
+ * from {@link #poll poll} only in that it throws an exception if this
+ * queue is empty.
*
- * @return the element at the head of the queue.
- * @throws NoSuchElementException
- * if there is no element in the queue.
+ * @return the head of this queue
+ * @throws NoSuchElementException if this queue is empty
*/
- public E remove();
+ E remove();
/**
- * Gets but does not remove the element at the head of the queue.
+ * Retrieves and removes the head of this queue,
+ * or returns <tt>null</tt> if this queue is empty.
*
- * @return the element at the head of the queue or {@code null} if there is
- * no element in the queue.
+ * @return the head of this queue, or <tt>null</tt> if this queue is empty
*/
- public E peek();
+ E poll();
/**
- * Gets but does not remove the element at the head of the queue. Throws a
- * {@code NoSuchElementException} if there is no element in the queue.
+ * Retrieves, but does not remove, the head of this queue. This method
+ * differs from {@link #peek peek} only in that it throws an exception
+ * if this queue is empty.
*
- * @return the element at the head of the queue.
- * @throws NoSuchElementException
- * if there is no element in the queue.
+ * @return the head of this queue
+ * @throws NoSuchElementException if this queue is empty
*/
- public E element();
+ E element();
+ /**
+ * Retrieves, but does not remove, the head of this queue,
+ * or returns <tt>null</tt> if this queue is empty.
+ *
+ * @return the head of this queue, or <tt>null</tt> if this queue is empty
+ */
+ E peek();
}
diff --git a/luni/src/main/java/java/util/Random.java b/luni/src/main/java/java/util/Random.java
index 0ff7d77..dac8eec 100644
--- a/luni/src/main/java/java/util/Random.java
+++ b/luni/src/main/java/java/util/Random.java
@@ -194,7 +194,7 @@ public class Random implements Serializable {
}
/**
- * Modifies the seed a using linear congruential formula presented in <i>The
+ * Modifies the seed using a linear congruential formula presented in <i>The
* Art of Computer Programming, Volume 2</i>, Section 3.2.1.
*/
public synchronized void setSeed(long seed) {
diff --git a/luni/src/main/java/java/util/ResourceBundle.java b/luni/src/main/java/java/util/ResourceBundle.java
index be7c06d..3c4442c 100644
--- a/luni/src/main/java/java/util/ResourceBundle.java
+++ b/luni/src/main/java/java/util/ResourceBundle.java
@@ -17,7 +17,6 @@
package java.util;
-import com.ibm.icu4jni.util.ICU;
import dalvik.system.VMStack;
import java.io.File;
import java.io.IOException;
@@ -27,6 +26,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import libcore.io.IoUtils;
/**
* {@code ResourceBundle} is an abstract class which is the superclass of classes which
@@ -110,7 +110,10 @@ public abstract class ResourceBundle {
private static final ResourceBundle MISSINGBASE = new MissingBundle();
- private static final WeakHashMap<Object, Hashtable<String, ResourceBundle>> cache = new WeakHashMap<Object, Hashtable<String, ResourceBundle>>();
+ private static final WeakHashMap<Object, Hashtable<String, ResourceBundle>> cache
+ = new WeakHashMap<Object, Hashtable<String, ResourceBundle>>();
+
+ private static Locale cacheLocale = Locale.getDefault();
/**
* Constructs a new instance of this class.
@@ -129,8 +132,12 @@ public abstract class ResourceBundle {
* @throws MissingResourceException
* if the {@code ResourceBundle} cannot be found.
*/
- public static final ResourceBundle getBundle(String bundleName) throws MissingResourceException {
- return getBundleImpl(bundleName, Locale.getDefault(), VMStack.getCallingClassLoader());
+ public static ResourceBundle getBundle(String bundleName) throws MissingResourceException {
+ ClassLoader classLoader = VMStack.getCallingClassLoader();
+ if (classLoader == null) {
+ classLoader = getLoader();
+ }
+ return getBundle(bundleName, Locale.getDefault(), classLoader);
}
/**
@@ -145,8 +152,12 @@ public abstract class ResourceBundle {
* @throws MissingResourceException
* if the resource bundle cannot be found.
*/
- public static final ResourceBundle getBundle(String bundleName, Locale locale) {
- return getBundleImpl(bundleName, locale, VMStack.getCallingClassLoader());
+ public static ResourceBundle getBundle(String bundleName, Locale locale) {
+ ClassLoader classLoader = VMStack.getCallingClassLoader();
+ if (classLoader == null) {
+ classLoader = getLoader();
+ }
+ return getBundle(bundleName, locale, classLoader);
}
/**
@@ -200,24 +211,25 @@ public abstract class ResourceBundle {
*/
public static ResourceBundle getBundle(String bundleName, Locale locale,
ClassLoader loader) throws MissingResourceException {
- if (loader == null) {
+ if (loader == null || bundleName == null) {
throw new NullPointerException();
}
- if (bundleName != null) {
- ResourceBundle bundle;
- if (!locale.equals(Locale.getDefault())) {
- if ((bundle = handleGetBundle(bundleName, UNDER_SCORE + locale,
- false, loader)) != null) {
- return bundle;
- }
- }
- if ((bundle = handleGetBundle(bundleName, UNDER_SCORE
- + Locale.getDefault(), true, loader)) != null) {
- return bundle;
+ Locale defaultLocale = Locale.getDefault();
+ if (!cacheLocale.equals(defaultLocale)) {
+ cache.clear();
+ cacheLocale = defaultLocale;
+ }
+ ResourceBundle bundle = null;
+ if (!locale.equals(defaultLocale)) {
+ bundle = handleGetBundle(false, bundleName, locale, loader);
+ }
+ if (bundle == null) {
+ bundle = handleGetBundle(true, bundleName, defaultLocale, loader);
+ if (bundle == null) {
+ throw missingResourceException(bundleName + '_' + locale, "");
}
- throw missingResourceException(bundleName + '_' + locale, "");
}
- throw new NullPointerException();
+ return bundle;
}
private static MissingResourceException missingResourceException(String className, String key) {
@@ -236,7 +248,7 @@ public abstract class ResourceBundle {
*
* @since 1.6
*/
- public static final ResourceBundle getBundle(String baseName, ResourceBundle.Control control) {
+ public static ResourceBundle getBundle(String baseName, ResourceBundle.Control control) {
return getBundle(baseName, Locale.getDefault(), getLoader(), control);
}
@@ -253,7 +265,7 @@ public abstract class ResourceBundle {
*
* @since 1.6
*/
- public static final ResourceBundle getBundle(String baseName,
+ public static ResourceBundle getBundle(String baseName,
Locale targetLocale, ResourceBundle.Control control) {
return getBundle(baseName, targetLocale, getLoader(), control);
}
@@ -263,7 +275,7 @@ public abstract class ResourceBundle {
.doPrivileged(new PrivilegedAction<ClassLoader>() {
public ClassLoader run() {
ClassLoader cl = this.getClass().getClassLoader();
- if (null == cl) {
+ if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
return cl;
@@ -291,16 +303,8 @@ public abstract class ResourceBundle {
ResourceBundle.Control control) {
boolean expired = false;
String bundleName = control.toBundleName(baseName, targetLocale);
- Object cacheKey = loader != null ? (Object) loader : (Object) "null";
- Hashtable<String, ResourceBundle> loaderCache;
- // try to find in cache
- synchronized (cache) {
- loaderCache = cache.get(cacheKey);
- if (loaderCache == null) {
- loaderCache = new Hashtable<String, ResourceBundle>();
- cache.put(cacheKey, loaderCache);
- }
- }
+ Object cacheKey = loader != null ? loader : "null";
+ Hashtable<String, ResourceBundle> loaderCache = getLoaderCache(cacheKey);
ResourceBundle result = loaderCache.get(bundleName);
if (result != null) {
long time = control.getTimeToLive(baseName, targetLocale);
@@ -318,23 +322,21 @@ public abstract class ResourceBundle {
ResourceBundle ret = processGetBundle(baseName, targetLocale, loader,
control, expired, result);
- if (null != ret) {
+ if (ret != null) {
loaderCache.put(bundleName, ret);
ret.lastLoadTime = System.currentTimeMillis();
return ret;
}
loaderCache.put(bundleName, MISSING);
- throw new MissingResourceException(null, bundleName + '_'
- + targetLocale, EMPTY_STRING);
+ throw new MissingResourceException(null, bundleName + '_' + targetLocale, EMPTY_STRING);
}
private static ResourceBundle processGetBundle(String baseName,
Locale targetLocale, ClassLoader loader,
ResourceBundle.Control control, boolean expired,
ResourceBundle result) {
- List<Locale> locales = control.getCandidateLocales(baseName,
- targetLocale);
- if (null == locales) {
+ List<Locale> locales = control.getCandidateLocales(baseName, targetLocale);
+ if (locales == null) {
throw new IllegalArgumentException();
}
List<String> formats = control.getFormats(baseName);
@@ -370,29 +372,28 @@ public abstract class ResourceBundle {
} catch (IOException e) {
// do nothing
}
- if (null != bundle) {
- if (null != currentBundle) {
+ if (bundle != null) {
+ if (currentBundle != null) {
currentBundle.setParent(bundle);
currentBundle = bundle;
} else {
- if (null == ret) {
+ if (ret == null) {
ret = bundle;
currentBundle = ret;
}
}
}
- if (null != bundle) {
+ if (bundle != null) {
break;
}
}
}
- if ((null == ret)
+ if ((ret == null)
|| (Locale.ROOT.equals(ret.getLocale()) && (!(locales.size() == 1 && locales
.contains(Locale.ROOT))))) {
- Locale nextLocale = control.getFallbackLocale(baseName,
- targetLocale);
- if (null != nextLocale) {
+ Locale nextLocale = control.getFallbackLocale(baseName, targetLocale);
+ if (nextLocale != null) {
ret = processGetBundle(baseName, nextLocale, loader, control,
expired, result);
}
@@ -401,32 +402,6 @@ public abstract class ResourceBundle {
return ret;
}
- private static ResourceBundle getBundleImpl(String bundleName,
- Locale locale, ClassLoader loader) throws MissingResourceException {
- if (bundleName != null) {
- ResourceBundle bundle;
- if (!locale.equals(Locale.getDefault())) {
- String localeName = locale.toString();
- if (localeName.length() > 0) {
- localeName = UNDER_SCORE + localeName;
- }
- if ((bundle = handleGetBundle(bundleName, localeName, false,
- loader)) != null) {
- return bundle;
- }
- }
- String localeName = Locale.getDefault().toString();
- if (localeName.length() > 0) {
- localeName = UNDER_SCORE + localeName;
- }
- if ((bundle = handleGetBundle(bundleName, localeName, true, loader)) != null) {
- return bundle;
- }
- throw missingResourceException(bundleName + '_' + locale, "");
- }
- throw new NullPointerException();
- }
-
/**
* Returns the names of the resources contained in this {@code ResourceBundle}.
*
@@ -502,80 +477,63 @@ public abstract class ResourceBundle {
return (String[]) getObject(key);
}
- private static ResourceBundle handleGetBundle(String base, String locale,
- boolean loadBase, final ClassLoader loader) {
- ResourceBundle bundle = null;
- String bundleName = base + locale;
- Object cacheKey = loader != null ? (Object) loader : (Object) "null";
- Hashtable<String, ResourceBundle> loaderCache;
- synchronized (cache) {
- loaderCache = cache.get(cacheKey);
- if (loaderCache == null) {
- loaderCache = new Hashtable<String, ResourceBundle>();
- cache.put(cacheKey, loaderCache);
- }
- }
- ResourceBundle result = loaderCache.get(bundleName);
- if (result != null) {
- if (result == MISSINGBASE) {
+ private static ResourceBundle handleGetBundle(boolean loadBase, String base, Locale locale,
+ ClassLoader loader) {
+ String localeName = locale.toString();
+ String bundleName = localeName.isEmpty()
+ ? base
+ : (base + "_" + localeName);
+ Object cacheKey = loader != null ? loader : "null";
+ Hashtable<String, ResourceBundle> loaderCache = getLoaderCache(cacheKey);
+ ResourceBundle cached = loaderCache.get(bundleName);
+ if (cached != null) {
+ if (cached == MISSINGBASE) {
return null;
- }
- if (result == MISSING) {
+ } else if (cached == MISSING) {
if (!loadBase) {
return null;
}
- String extension = strip(locale);
- if (extension == null) {
+ Locale newLocale = strip(locale);
+ if (newLocale == null) {
return null;
}
- return handleGetBundle(base, extension, loadBase, loader);
+ return handleGetBundle(loadBase, base, newLocale, loader);
}
- return result;
+ return cached;
}
+ ResourceBundle bundle = null;
try {
Class<?> bundleClass = Class.forName(bundleName, true, loader);
-
if (ResourceBundle.class.isAssignableFrom(bundleClass)) {
bundle = (ResourceBundle) bundleClass.newInstance();
}
- } catch (LinkageError e) {
- } catch (Exception e) {
+ } catch (LinkageError ignored) {
+ } catch (Exception ignored) {
}
if (bundle != null) {
bundle.setLocale(locale);
} else {
- final String fileName = bundleName.replace('.', '/');
- InputStream stream = AccessController
- .doPrivileged(new PrivilegedAction<InputStream>() {
- public InputStream run() {
- return loader == null ? ClassLoader
- .getSystemResourceAsStream(fileName
- + ".properties") : loader
- .getResourceAsStream(fileName
- + ".properties");
- }
- });
+ String fileName = bundleName.replace('.', '/') + ".properties";
+ InputStream stream = loader != null
+ ? loader.getResourceAsStream(fileName)
+ : ClassLoader.getSystemResourceAsStream(fileName);
if (stream != null) {
try {
- try {
- bundle = new PropertyResourceBundle(new InputStreamReader(stream));
- } finally {
- stream.close();
- }
+ bundle = new PropertyResourceBundle(new InputStreamReader(stream));
bundle.setLocale(locale);
- } catch (IOException e) {
- // do nothing
+ } catch (IOException ignored) {
+ } finally {
+ IoUtils.closeQuietly(stream);
}
}
}
- String extension = strip(locale);
+ Locale strippedLocale = strip(locale);
if (bundle != null) {
- if (extension != null) {
- ResourceBundle parent = handleGetBundle(base, extension, true,
- loader);
+ if (strippedLocale != null) {
+ ResourceBundle parent = handleGetBundle(loadBase, base, strippedLocale, loader);
if (parent != null) {
bundle.setParent(parent);
}
@@ -584,8 +542,8 @@ public abstract class ResourceBundle {
return bundle;
}
- if (extension != null && (loadBase || extension.length() > 0)) {
- bundle = handleGetBundle(base, extension, loadBase, loader);
+ if (strippedLocale != null && (loadBase || !strippedLocale.toString().isEmpty())) {
+ bundle = handleGetBundle(loadBase, base, strippedLocale, loader);
if (bundle != null) {
loaderCache.put(bundleName, bundle);
return bundle;
@@ -595,6 +553,17 @@ public abstract class ResourceBundle {
return null;
}
+ private static Hashtable<String, ResourceBundle> getLoaderCache(Object cacheKey) {
+ synchronized (cache) {
+ Hashtable<String, ResourceBundle> loaderCache = cache.get(cacheKey);
+ if (loaderCache == null) {
+ loaderCache = new Hashtable<String, ResourceBundle>();
+ cache.put(cacheKey, loaderCache);
+ }
+ return loaderCache;
+ }
+ }
+
/**
* Returns the named resource from this {@code ResourceBundle}, or null if the
* resource is not found.
@@ -616,35 +585,43 @@ public abstract class ResourceBundle {
parent = bundle;
}
- private static String strip(String name) {
- int index = name.lastIndexOf('_');
- if (index != -1) {
- return name.substring(0, index);
+ /**
+ * Returns a locale with the most-specific field removed, or null if this
+ * locale had an empty language, country and variant.
+ */
+ private static Locale strip(Locale locale) {
+ String language = locale.getLanguage();
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
+ if (!variant.isEmpty()) {
+ variant = "";
+ } else if (!country.isEmpty()) {
+ country = "";
+ } else if (!language.isEmpty()) {
+ language = "";
+ } else {
+ return null;
}
- return null;
+ return new Locale(language, country, variant);
}
private void setLocale(Locale locale) {
this.locale = locale;
}
- private void setLocale(String name) {
- setLocale(ICU.localeFromString(name));
- }
-
- public static final void clearCache() {
+ public static void clearCache() {
cache.remove(ClassLoader.getSystemClassLoader());
}
- public static final void clearCache(ClassLoader loader) {
- if (null == loader) {
+ public static void clearCache(ClassLoader loader) {
+ if (loader == null) {
throw new NullPointerException();
}
cache.remove(loader);
}
public boolean containsKey(String key) {
- if (null == key) {
+ if (key == null) {
throw new NullPointerException();
}
return keySet().contains(key);
@@ -663,7 +640,7 @@ public abstract class ResourceBundle {
Set<String> set = keySet();
Set<String> ret = new HashSet<String>();
for (String key : set) {
- if (null != handleGetObject(key)) {
+ if (handleGetObject(key) != null) {
ret.add(key);
}
}
@@ -695,7 +672,7 @@ public abstract class ResourceBundle {
@Override
public Locale getFallbackLocale(String baseName, Locale locale) {
- if (null == baseName || null == locale) {
+ if (baseName == null || locale == null) {
throw new NullPointerException();
}
return null;
@@ -790,7 +767,7 @@ public abstract class ResourceBundle {
/**
* Returns a control according to {@code formats}.
*/
- public static final Control getControl(List<String> formats) {
+ public static Control getControl(List<String> formats) {
switch (formats.size()) {
case 1:
if (formats.contains(JAVACLASS)) {
@@ -813,7 +790,7 @@ public abstract class ResourceBundle {
* Returns a control according to {@code formats} whose fallback
* locale is null.
*/
- public static final Control getNoFallbackControl(List<String> formats) {
+ public static Control getNoFallbackControl(List<String> formats) {
switch (formats.size()) {
case 1:
if (formats.contains(JAVACLASS)) {
@@ -837,7 +814,7 @@ public abstract class ResourceBundle {
* {@code locale}.
*/
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
- if (null == baseName || null == locale) {
+ if (baseName == null || locale == null) {
throw new NullPointerException();
}
List<Locale> retList = new ArrayList<Locale>();
@@ -861,7 +838,7 @@ public abstract class ResourceBundle {
* Returns a list of strings of formats according to {@code baseName}.
*/
public List<String> getFormats(String baseName) {
- if (null == baseName) {
+ if (baseName == null) {
throw new NullPointerException();
}
return format;
@@ -871,7 +848,7 @@ public abstract class ResourceBundle {
* Returns the fallback locale for {@code baseName} in {@code locale}.
*/
public Locale getFallbackLocale(String baseName, Locale locale) {
- if (null == baseName || null == locale) {
+ if (baseName == null || locale == null) {
throw new NullPointerException();
}
if (Locale.getDefault() != locale) {
@@ -905,7 +882,7 @@ public abstract class ResourceBundle {
String format, ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException,
IOException {
- if (null == format || null == loader) {
+ if (format == null || loader == null) {
throw new NullPointerException();
}
InputStream streams = null;
@@ -926,7 +903,7 @@ public abstract class ResourceBundle {
}
}
});
- if (null == cls) {
+ if (cls == null) {
return null;
}
try {
@@ -947,7 +924,7 @@ public abstract class ResourceBundle {
} catch (NullPointerException e) {
// do nothing
}
- if (null != url) {
+ if (url != null) {
URLConnection con = url.openConnection();
con.setUseCaches(false);
streams = con.getInputStream();
@@ -985,7 +962,7 @@ public abstract class ResourceBundle {
* default is TTL_NO_EXPIRATION_CONTROL.
*/
public long getTimeToLive(String baseName, Locale locale) {
- if (null == baseName || null == locale) {
+ if (baseName == null || locale == null) {
throw new NullPointerException();
}
return TTL_NO_EXPIRATION_CONTROL;
@@ -1011,7 +988,7 @@ public abstract class ResourceBundle {
public boolean needsReload(String baseName, Locale locale,
String format, ClassLoader loader, ResourceBundle bundle,
long loadTime) {
- if (null == bundle) {
+ if (bundle == null) {
// FIXME what's the use of bundle?
throw new NullPointerException();
}
@@ -1025,7 +1002,7 @@ public abstract class ResourceBundle {
}
String urlname = toResourceName(bundleName, suffix);
URL url = loader.getResource(urlname);
- if (null != url) {
+ if (url != null) {
String fileName = url.getFile();
long lastModified = new File(fileName).lastModified();
if (lastModified > loadTime) {
@@ -1050,7 +1027,7 @@ public abstract class ResourceBundle {
final String emptyString = EMPTY_STRING;
final String preString = UNDER_SCORE;
final String underline = UNDER_SCORE;
- if (null == baseName) {
+ if (baseName == null) {
throw new NullPointerException();
}
StringBuilder ret = new StringBuilder();
@@ -1090,7 +1067,7 @@ public abstract class ResourceBundle {
* suffix
*/
public final String toResourceName(String bundleName, String suffix) {
- if (null == suffix) {
+ if (suffix == null) {
throw new NullPointerException();
}
StringBuilder ret = new StringBuilder(bundleName.replace('.', '/'));
diff --git a/luni/src/main/java/java/util/Scanner.java b/luni/src/main/java/java/util/Scanner.java
index 0245329..85de1e7 100644
--- a/luni/src/main/java/java/util/Scanner.java
+++ b/luni/src/main/java/java/util/Scanner.java
@@ -35,6 +35,7 @@ import java.text.NumberFormat;
import java.util.regex.MatchResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import libcore.io.IoUtils;
/**
* A parser that parses a text string of primitive types and strings with the
@@ -191,11 +192,7 @@ public final class Scanner implements Iterator<String> {
try {
input = new InputStreamReader(fis, charsetName);
} catch (UnsupportedEncodingException e) {
- try {
- fis.close();
- } catch (IOException ioException) {
- // ignore
- }
+ IoUtils.closeQuietly(fis);
throw new IllegalArgumentException(e.getMessage());
}
initialization();
@@ -253,7 +250,7 @@ public final class Scanner implements Iterator<String> {
* the {@code Readable} to be scanned.
*/
public Scanner(Readable src) {
- if (null == src) {
+ if (src == null) {
throw new NullPointerException();
}
input = src;
@@ -445,9 +442,9 @@ public final class Scanner implements Iterator<String> {
* The {@code Scanner}'s search will never go more than {@code horizon} code points from current
* position. The position of {@code horizon} does have an effect on the result of the
* match. For example, when the input is "123" and current position is at zero,
- * {@code findWithinHorizon(Pattern.compile("\\p&#123;Digit&#125;&#123;3&#125;"), 2)}
- * will return {@code null}. While
- * {@code findWithinHorizon(Pattern.compile("\\p&#123;Digit&#125;&#123;3&#125;"), 3)}
+ * <code>findWithinHorizon(Pattern.compile("\\p{Digit}{3}"), 2)</code>
+ * will return {@code null}, while
+ * <code>findWithinHorizon(Pattern.compile("\\p{Digit}{3}"), 3)</code>
* will return {@code "123"}. {@code horizon} is treated as a transparent,
* non-anchoring bound. (refer to
* {@link Matcher#useTransparentBounds(boolean)} and
@@ -516,7 +513,7 @@ public final class Scanner implements Iterator<String> {
resetMatcher();
}
}
- if (null != result) {
+ if (result != null) {
findStartIndex = matcher.end();
matchSuccessful = true;
} else {
@@ -1423,7 +1420,7 @@ public final class Scanner implements Iterator<String> {
}
}
// Find text without line terminator here.
- if (null != result) {
+ if (result != null) {
Matcher terminatorMatcher = LINE_TERMINATOR.matcher(result);
if (terminatorMatcher.find()) {
result = result.substring(0, terminatorMatcher.start());
@@ -1676,7 +1673,7 @@ public final class Scanner implements Iterator<String> {
* @return this {@code Scanner}.
*/
public Scanner useLocale(Locale l) {
- if (null == l) {
+ if (l == null) {
throw new NullPointerException();
}
this.locale = l;
@@ -1736,7 +1733,7 @@ public final class Scanner implements Iterator<String> {
* will be thrown out.
*/
private void checkNull(Pattern pattern) {
- if (null == pattern) {
+ if (pattern == null) {
throw new NullPointerException();
}
}
@@ -1745,7 +1742,7 @@ public final class Scanner implements Iterator<String> {
* Change the matcher's string after reading input
*/
private void resetMatcher() {
- if (null == matcher) {
+ if (matcher == null) {
matcher = delimiter.matcher(buffer);
} else {
matcher.reset(buffer);
@@ -1955,7 +1952,7 @@ public final class Scanner implements Iterator<String> {
}
}
// Token is NaN or Infinity
- if (0 == result.length()) {
+ if (result.length() == 0) {
result = tokenBuilder;
}
if (-1 != separatorIndex) {
@@ -1978,10 +1975,10 @@ public final class Scanner implements Iterator<String> {
String negativePrefix = decimalFormat.getNegativePrefix();
String negativeSuffix = decimalFormat.getNegativeSuffix();
- if (0 == tokenBuilder.indexOf("+")) {
+ if (tokenBuilder.indexOf("+") == 0) {
tokenBuilder.delete(0, 1);
}
- if (!positivePrefix.isEmpty() && 0 == tokenBuilder.indexOf(positivePrefix)) {
+ if (!positivePrefix.isEmpty() && tokenBuilder.indexOf(positivePrefix) == 0) {
tokenBuilder.delete(0, positivePrefix.length());
}
if (!positiveSuffix.isEmpty()
@@ -1991,12 +1988,11 @@ public final class Scanner implements Iterator<String> {
tokenBuilder.length());
}
boolean negative = false;
- if (0 == tokenBuilder.indexOf("-")) {
+ if (tokenBuilder.indexOf("-") == 0) {
tokenBuilder.delete(0, 1);
negative = true;
}
- if (!negativePrefix.isEmpty()
- && 0 == tokenBuilder.indexOf(negativePrefix)) {
+ if (!negativePrefix.isEmpty() && tokenBuilder.indexOf(negativePrefix) == 0) {
tokenBuilder.delete(0, negativePrefix.length());
negative = true;
}
diff --git a/luni/src/main/java/java/util/ServiceLoader.java b/luni/src/main/java/java/util/ServiceLoader.java
index 1608c1d..8fc232f 100644
--- a/luni/src/main/java/java/util/ServiceLoader.java
+++ b/luni/src/main/java/java/util/ServiceLoader.java
@@ -22,6 +22,7 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import libcore.io.IoUtils;
/**
* A service-provider loader.
@@ -249,12 +250,7 @@ public final class ServiceLoader<S> implements Iterable<S> {
} catch (Exception e) {
throw new ServiceConfigurationError("Couldn't read " + url, e);
} finally {
- try {
- if (reader != null) {
- reader.close();
- }
- } catch (IOException ex) {
- }
+ IoUtils.closeQuietly(reader);
}
}
}
diff --git a/luni/src/main/java/java/util/SimpleTimeZone.java b/luni/src/main/java/java/util/SimpleTimeZone.java
index fa2e9e1..a57ab9a 100644
--- a/luni/src/main/java/java/util/SimpleTimeZone.java
+++ b/luni/src/main/java/java/util/SimpleTimeZone.java
@@ -15,12 +15,6 @@
* limitations under the License.
*/
-// BEGIN android-note
-// This implementation is based on an old version of Apache Harmony. The current
-// Harmony uses ICU4J, which makes it much simpler. We should consider updating
-// this implementation to leverage ICU4JNI.
-// END android-note
-
package java.util;
import java.io.IOException;
@@ -46,16 +40,6 @@ public class SimpleTimeZone extends TimeZone {
private static final long serialVersionUID = -403250971215465050L;
- // BEGIN android-removed
- // private static com.ibm.icu.util.TimeZone getICUTimeZone(final String name){
- // return AccessController.doPrivileged(new PrivilegedAction<com.ibm.icu.util.TimeZone>(){
- // public com.ibm.icu.util.TimeZone run() {
- // return com.ibm.icu.util.TimeZone.getTimeZone(name);
- // }
- // });
- // }
- // END android-removed
-
private int rawOffset;
private int startYear, startMonth, startDay, startDayOfWeek, startTime;
diff --git a/luni/src/main/java/java/util/TimSort.java b/luni/src/main/java/java/util/TimSort.java
index 79dc377..009cdc4 100644
--- a/luni/src/main/java/java/util/TimSort.java
+++ b/luni/src/main/java/java/util/TimSort.java
@@ -175,7 +175,7 @@ class TimSort<T> {
return;
}
- rangeCheck(a.length, lo, hi);
+ Arrays.checkStartAndEnd(a.length, lo, hi);
int nRemaining = hi - lo;
if (nRemaining < 2)
return; // Arrays of size 0 and 1 are always sorted
@@ -509,7 +509,7 @@ class TimSort<T> {
int maxOfs = len - hint;
while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) > 0) {
lastOfs = ofs;
- ofs = (ofs << 1) + 1;
+ ofs = (ofs * 2) + 1;
if (ofs <= 0) // int overflow
ofs = maxOfs;
}
@@ -524,7 +524,7 @@ class TimSort<T> {
final int maxOfs = hint + 1;
while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) <= 0) {
lastOfs = ofs;
- ofs = (ofs << 1) + 1;
+ ofs = (ofs * 2) + 1;
if (ofs <= 0) // int overflow
ofs = maxOfs;
}
@@ -580,7 +580,7 @@ class TimSort<T> {
int maxOfs = hint + 1;
while (ofs < maxOfs && c.compare(key, a[base + hint - ofs]) < 0) {
lastOfs = ofs;
- ofs = (ofs << 1) + 1;
+ ofs = (ofs * 2) + 1;
if (ofs <= 0) // int overflow
ofs = maxOfs;
}
@@ -596,7 +596,7 @@ class TimSort<T> {
int maxOfs = len - hint;
while (ofs < maxOfs && c.compare(key, a[base + hint + ofs]) >= 0) {
lastOfs = ofs;
- ofs = (ofs << 1) + 1;
+ ofs = (ofs * 2) + 1;
if (ofs <= 0) // int overflow
ofs = maxOfs;
}
@@ -900,25 +900,4 @@ class TimSort<T> {
}
return tmp;
}
-
- /**
- * Checks that fromIndex and toIndex are in range, and throws an
- * appropriate exception if they aren't.
- *
- * @param arrayLen the length of the array
- * @param fromIndex the index of the first element of the range
- * @param toIndex the index after the last element of the range
- * @throws IllegalArgumentException if fromIndex > toIndex
- * @throws ArrayIndexOutOfBoundsException if fromIndex < 0
- * or toIndex > arrayLen
- */
- private static void rangeCheck(int arrayLen, int fromIndex, int toIndex) {
- if (fromIndex > toIndex)
- throw new IllegalArgumentException("fromIndex(" + fromIndex +
- ") > toIndex(" + toIndex+")");
- if (fromIndex < 0)
- throw new ArrayIndexOutOfBoundsException(fromIndex);
- if (toIndex > arrayLen)
- throw new ArrayIndexOutOfBoundsException(toIndex);
- }
}
diff --git a/luni/src/main/java/java/util/TreeMap.java b/luni/src/main/java/java/util/TreeMap.java
index ad0f182..59f240c 100644
--- a/luni/src/main/java/java/util/TreeMap.java
+++ b/luni/src/main/java/java/util/TreeMap.java
@@ -251,7 +251,7 @@ public class TreeMap<K, V> extends AbstractMap<K, V>
Node<K, V> find(K key, Relation relation) {
if (root == null) {
if (comparator == NATURAL_ORDER && !(key instanceof Comparable)) {
- throw new ClassCastException(key.getClass().getName()); // NullPointerException ok
+ throw new ClassCastException(key.getClass().getName() + " is not Comparable"); // NullPointerException ok
}
if (relation == Relation.CREATE) {
root = new Node<K, V>(null, key);
diff --git a/luni/src/main/java/java/util/TreeSet.java b/luni/src/main/java/java/util/TreeSet.java
index 0d330da..e4f2136 100644
--- a/luni/src/main/java/java/util/TreeSet.java
+++ b/luni/src/main/java/java/util/TreeSet.java
@@ -280,7 +280,7 @@ public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>,
*/
public E pollFirst() {
Map.Entry<E, Object> entry = backingMap.pollFirstEntry();
- return (null == entry) ? null : entry.getKey();
+ return (entry == null) ? null : entry.getKey();
}
/**
@@ -291,7 +291,7 @@ public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>,
*/
public E pollLast() {
Map.Entry<E, Object> entry = backingMap.pollLastEntry();
- return (null == entry) ? null : entry.getKey();
+ return (entry == null) ? null : entry.getKey();
}
/**
@@ -341,7 +341,7 @@ public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>,
* @since 1.6
*/
public NavigableSet<E> descendingSet() {
- return (null != descendingSet) ? descendingSet
+ return (descendingSet != null) ? descendingSet
: (descendingSet = new TreeSet<E>(backingMap.descendingMap()));
}
diff --git a/luni/src/main/java/java/util/UUID.java b/luni/src/main/java/java/util/UUID.java
index e2d7da1..8a39ead 100644
--- a/luni/src/main/java/java/util/UUID.java
+++ b/luni/src/main/java/java/util/UUID.java
@@ -20,9 +20,11 @@ package java.util;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
+import java.nio.ByteOrder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* UUID is an immutable representation of a 128-bit universally unique
@@ -119,34 +121,15 @@ public final class UUID implements Serializable, Comparable<UUID> {
* @return an UUID instance.
*/
public static UUID randomUUID() {
- byte[] data;
+ byte[] data = new byte[16];
// lock on the class to protect lazy init
synchronized (UUID.class) {
if (rng == null) {
rng = new SecureRandom();
}
}
- rng.nextBytes(data = new byte[16]);
- long msb = (data[0] & 0xFFL) << 56;
- msb |= (data[1] & 0xFFL) << 48;
- msb |= (data[2] & 0xFFL) << 40;
- msb |= (data[3] & 0xFFL) << 32;
- msb |= (data[4] & 0xFFL) << 24;
- msb |= (data[5] & 0xFFL) << 16;
- msb |= (data[6] & 0x0FL) << 8;
- msb |= (0x4L << 12); // set the version to 4
- msb |= (data[7] & 0xFFL);
-
- long lsb = (data[8] & 0x3FL) << 56;
- lsb |= (0x2L << 62); // set the variant to bits 01
- lsb |= (data[9] & 0xFFL) << 48;
- lsb |= (data[10] & 0xFFL) << 40;
- lsb |= (data[11] & 0xFFL) << 32;
- lsb |= (data[12] & 0xFFL) << 24;
- lsb |= (data[13] & 0xFFL) << 16;
- lsb |= (data[14] & 0xFFL) << 8;
- lsb |= (data[15] & 0xFFL);
- return new UUID(msb, lsb);
+ rng.nextBytes(data);
+ return makeUuid(data, 4);
}
/**
@@ -162,34 +145,24 @@ public final class UUID implements Serializable, Comparable<UUID> {
if (name == null) {
throw new NullPointerException();
}
-
- byte[] hash;
try {
MessageDigest md = MessageDigest.getInstance("MD5");
- hash = md.digest(name);
+ return makeUuid(md.digest(name), 3);
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
+ }
- long msb = (hash[0] & 0xFFL) << 56;
- msb |= (hash[1] & 0xFFL) << 48;
- msb |= (hash[2] & 0xFFL) << 40;
- msb |= (hash[3] & 0xFFL) << 32;
- msb |= (hash[4] & 0xFFL) << 24;
- msb |= (hash[5] & 0xFFL) << 16;
- msb |= (hash[6] & 0x0FL) << 8;
- msb |= (0x3L << 12); // set the version to 3
- msb |= (hash[7] & 0xFFL);
-
- long lsb = (hash[8] & 0x3FL) << 56;
- lsb |= (0x2L << 62); // set the variant to bits 01
- lsb |= (hash[9] & 0xFFL) << 48;
- lsb |= (hash[10] & 0xFFL) << 40;
- lsb |= (hash[11] & 0xFFL) << 32;
- lsb |= (hash[12] & 0xFFL) << 24;
- lsb |= (hash[13] & 0xFFL) << 16;
- lsb |= (hash[14] & 0xFFL) << 8;
- lsb |= (hash[15] & 0xFFL);
+ private static UUID makeUuid(byte[] hash, int version) {
+ long msb = OSMemory.peekLong(hash, 0, ByteOrder.BIG_ENDIAN);
+ long lsb = OSMemory.peekLong(hash, 8, ByteOrder.BIG_ENDIAN);
+ // Set the version field.
+ msb &= ~(0xfL << 12);
+ msb |= ((long) version) << 12;
+ // Set the variant field to 2. Note that the variant field is variable-width,
+ // so supporting other variants is not just a matter of changing the constant 2 below!
+ lsb &= ~(0x3L << 62);
+ lsb |= 2L << 62;
return new UUID(msb, lsb);
}
@@ -227,13 +200,10 @@ public final class UUID implements Serializable, Comparable<UUID> {
}
long m1 = Long.parseLong(uuid.substring(0, position[0]), 16);
- long m2 = Long.parseLong(uuid.substring(position[0] + 1, position[1]),
- 16);
- long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]),
- 16);
+ long m2 = Long.parseLong(uuid.substring(position[0] + 1, position[1]), 16);
+ long m3 = Long.parseLong(uuid.substring(position[1] + 1, position[2]), 16);
- long lsb1 = Long.parseLong(
- uuid.substring(position[2] + 1, position[3]), 16);
+ long lsb1 = Long.parseLong(uuid.substring(position[2] + 1, position[3]), 16);
long lsb2 = Long.parseLong(uuid.substring(position[3] + 1), 16);
long msb = (m1 << 32) | (m2 << 16) | m3;
diff --git a/luni/src/main/java/java/util/Vector.java b/luni/src/main/java/java/util/Vector.java
index 868aff7..dcd19f2 100644
--- a/luni/src/main/java/java/util/Vector.java
+++ b/luni/src/main/java/java/util/Vector.java
@@ -173,9 +173,8 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
* if {@code location < 0} or {@code location > size()}.
*/
@Override
- public synchronized boolean addAll(int location,
- Collection<? extends E> collection) {
- if (0 <= location && location <= elementCount) {
+ public synchronized boolean addAll(int location, Collection<? extends E> collection) {
+ if (location >= 0 && location <= elementCount) {
int size = collection.size();
if (size == 0) {
return false;
@@ -197,7 +196,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
modCount++;
return true;
}
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
/**
@@ -326,7 +325,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
if (location < elementCount) {
return (E) elementData[location];
}
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
/**
@@ -575,7 +574,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
* @see #size
*/
public synchronized void insertElementAt(E object, int location) {
- if (0 <= location && location <= elementCount) {
+ if (location >= 0 && location <= elementCount) {
if (elementCount == elementData.length) {
growByOne();
}
@@ -588,7 +587,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
elementCount++;
modCount++;
} else {
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
}
@@ -675,7 +674,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
}
return -1;
}
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
/**
@@ -704,7 +703,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
modCount++;
return result;
}
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
/**
@@ -793,7 +792,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
* @see #size
*/
public synchronized void removeElementAt(int location) {
- if (0 <= location && location < elementCount) {
+ if (location >= 0 && location < elementCount) {
elementCount--;
int size = elementCount - location;
if (size > 0) {
@@ -803,7 +802,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
elementData[elementCount] = null;
modCount++;
} else {
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
}
@@ -877,7 +876,7 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
elementData[location] = object;
return result;
}
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
/**
@@ -896,11 +895,19 @@ public class Vector<E> extends AbstractList<E> implements List<E>,
if (location < elementCount) {
elementData[location] = object;
} else {
- throw new ArrayIndexOutOfBoundsException(location);
+ throw arrayIndexOutOfBoundsException(location, elementCount);
}
}
/**
+ * This method was extracted to encourage VM to inline callers.
+ * TODO: when we have a VM that can actually inline, move the test in here too!
+ */
+ private static ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException(int index, int size) {
+ throw new ArrayIndexOutOfBoundsException("index=" + index + ", size=" + size);
+ }
+
+ /**
* Sets the size of this vector to the specified size. If there are more
* than length elements in this vector, the elements at end are lost. If
* there are less than length elements in the vector, the additional
diff --git a/luni/src/main/java/java/util/WeakHashMap.java b/luni/src/main/java/java/util/WeakHashMap.java
index 48da8cb..6417679 100644
--- a/luni/src/main/java/java/util/WeakHashMap.java
+++ b/luni/src/main/java/java/util/WeakHashMap.java
@@ -638,7 +638,7 @@ public class WeakHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
}
private void rehash() {
- int length = elementData.length << 1;
+ int length = elementData.length * 2;
if (length == 0) {
length = 1;
}
diff --git a/luni/src/main/java/java/util/concurrent/AbstractExecutorService.java b/luni/src/main/java/java/util/concurrent/AbstractExecutorService.java
index eee6c1c..36fcecc 100644
--- a/luni/src/main/java/java/util/concurrent/AbstractExecutorService.java
+++ b/luni/src/main/java/java/util/concurrent/AbstractExecutorService.java
@@ -5,11 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
/**
* Provides default implementations of {@link ExecutorService}
@@ -26,20 +22,20 @@ import java.util.List;
* <p> <b>Extension example</b>. Here is a sketch of a class
* that customizes {@link ThreadPoolExecutor} to use
* a <tt>CustomTask</tt> class instead of the default <tt>FutureTask</tt>:
- * <pre>
+ * <pre> {@code
* public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
*
- * static class CustomTask&lt;V&gt; implements RunnableFuture&lt;V&gt; {...}
+ * static class CustomTask<V> implements RunnableFuture<V> {...}
*
- * protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Callable&lt;V&gt; c) {
- * return new CustomTask&lt;V&gt;(c);
+ * protected <V> RunnableFuture<V> newTaskFor(Callable<V> c) {
+ * return new CustomTask<V>(c);
* }
- * protected &lt;V&gt; RunnableFuture&lt;V&gt; newTaskFor(Runnable r, V v) {
- * return new CustomTask&lt;V&gt;(r, v);
+ * protected <V> RunnableFuture<V> newTaskFor(Runnable r, V v) {
+ * return new CustomTask<V>(r, v);
* }
* // ... add constructors, etc.
- * }
- * </pre>
+ * }}</pre>
+ *
* @since 1.5
* @author Doug Lea
*/
@@ -81,7 +77,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
*/
public Future<?> submit(Runnable task) {
if (task == null) throw new NullPointerException();
- RunnableFuture<Object> ftask = newTaskFor(task, null);
+ RunnableFuture<Void> ftask = newTaskFor(task, null);
execute(ftask);
return ftask;
}
@@ -133,7 +129,7 @@ public abstract class AbstractExecutorService implements ExecutorService {
// Record exceptions so that if we fail to obtain any
// result, we can throw the last exception we got.
ExecutionException ee = null;
- long lastTime = (timed)? System.nanoTime() : 0;
+ long lastTime = timed ? System.nanoTime() : 0;
Iterator<? extends Callable<T>> it = tasks.iterator();
// Start one task for sure; the rest incrementally
@@ -166,8 +162,6 @@ public abstract class AbstractExecutorService implements ExecutorService {
--active;
try {
return f.get();
- } catch (InterruptedException ie) {
- throw ie;
} catch (ExecutionException eex) {
ee = eex;
} catch (RuntimeException rex) {
diff --git a/luni/src/main/java/java/util/concurrent/ArrayBlockingQueue.java b/luni/src/main/java/java/util/concurrent/ArrayBlockingQueue.java
index 24d04e3..a622832 100644
--- a/luni/src/main/java/java/util/concurrent/ArrayBlockingQueue.java
+++ b/luni/src/main/java/java/util/concurrent/ArrayBlockingQueue.java
@@ -5,14 +5,8 @@
*/
package java.util.concurrent;
-
-import java.util.AbstractQueue;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
+import java.util.*;
// BEGIN android-note
// removed link to collections framework docs
@@ -30,14 +24,14 @@ import java.util.concurrent.locks.ReentrantLock;
* <p>This is a classic &quot;bounded buffer&quot;, in which a
* fixed-sized array holds elements inserted by producers and
* extracted by consumers. Once created, the capacity cannot be
- * increased. Attempts to <tt>put</tt> an element into a full queue
- * will result in the operation blocking; attempts to <tt>take</tt> an
+ * changed. Attempts to {@code put} an element into a full queue
+ * will result in the operation blocking; attempts to {@code take} an
* element from an empty queue will similarly block.
*
- * <p> This class supports an optional fairness policy for ordering
+ * <p>This class supports an optional fairness policy for ordering
* waiting producer and consumer threads. By default, this ordering
* is not guaranteed. However, a queue constructed with fairness set
- * to <tt>true</tt> grants threads access in FIFO order. Fairness
+ * to {@code true} grants threads access in FIFO order. Fairness
* generally decreases throughput but reduces variability and avoids
* starvation.
*
@@ -60,14 +54,17 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
*/
private static final long serialVersionUID = -817911632652898426L;
- /** The queued items */
- private final E[] items;
- /** items index for next take, poll or remove */
- private int takeIndex;
- /** items index for next put, offer, or add. */
- private int putIndex;
- /** Number of items in the queue */
- private int count;
+ /** The queued items */
+ final Object[] items;
+
+ /** items index for next take, poll, peek or remove */
+ int takeIndex;
+
+ /** items index for next put, offer, or add */
+ int putIndex;
+
+ /** Number of elements in the queue */
+ int count;
/*
* Concurrency control uses the classic two-condition algorithm
@@ -75,7 +72,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
*/
/** Main lock guarding all access */
- private final ReentrantLock lock;
+ final ReentrantLock lock;
/** Condition for waiting takes */
private final Condition notEmpty;
/** Condition for waiting puts */
@@ -87,7 +84,36 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* Circularly increment i.
*/
final int inc(int i) {
- return (++i == items.length)? 0 : i;
+ return (++i == items.length) ? 0 : i;
+ }
+
+ /**
+ * Circularly decrement i.
+ */
+ final int dec(int i) {
+ return ((i == 0) ? items.length : i) - 1;
+ }
+
+ @SuppressWarnings("unchecked")
+ static <E> E cast(Object item) {
+ return (E) item;
+ }
+
+ /**
+ * Returns item at index i.
+ */
+ final E itemAt(int i) {
+ return this.<E>cast(items[i]);
+ }
+
+ /**
+ * Throws NullPointerException if argument is null.
+ *
+ * @param v the element
+ */
+ private static void checkNotNull(Object v) {
+ if (v == null)
+ throw new NullPointerException();
}
/**
@@ -106,8 +132,8 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* Call only when holding lock.
*/
private E extract() {
- final E[] items = this.items;
- E x = items[takeIndex];
+ final Object[] items = this.items;
+ E x = this.<E>cast(items[takeIndex]);
items[takeIndex] = null;
takeIndex = inc(takeIndex);
--count;
@@ -116,11 +142,12 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
}
/**
- * Utility for remove and iterator.remove: Delete item at position i.
+ * Deletes item at position i.
+ * Utility for remove and iterator.remove.
* Call only when holding lock.
*/
void removeAt(int i) {
- final E[] items = this.items;
+ final Object[] items = this.items;
// if removing front item, just advance
if (i == takeIndex) {
items[takeIndex] = null;
@@ -144,69 +171,82 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
}
/**
- * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed)
+ * Creates an {@code ArrayBlockingQueue} with the given (fixed)
* capacity and default access policy.
*
* @param capacity the capacity of this queue
- * @throws IllegalArgumentException if <tt>capacity</tt> is less than 1
+ * @throws IllegalArgumentException if {@code capacity < 1}
*/
public ArrayBlockingQueue(int capacity) {
this(capacity, false);
}
/**
- * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed)
+ * Creates an {@code ArrayBlockingQueue} with the given (fixed)
* capacity and the specified access policy.
*
* @param capacity the capacity of this queue
- * @param fair if <tt>true</tt> then queue accesses for threads blocked
+ * @param fair if {@code true} then queue accesses for threads blocked
* on insertion or removal, are processed in FIFO order;
- * if <tt>false</tt> the access order is unspecified.
- * @throws IllegalArgumentException if <tt>capacity</tt> is less than 1
+ * if {@code false} the access order is unspecified.
+ * @throws IllegalArgumentException if {@code capacity < 1}
*/
public ArrayBlockingQueue(int capacity, boolean fair) {
if (capacity <= 0)
throw new IllegalArgumentException();
- this.items = (E[]) new Object[capacity];
+ this.items = new Object[capacity];
lock = new ReentrantLock(fair);
notEmpty = lock.newCondition();
notFull = lock.newCondition();
}
/**
- * Creates an <tt>ArrayBlockingQueue</tt> with the given (fixed)
+ * Creates an {@code ArrayBlockingQueue} with the given (fixed)
* capacity, the specified access policy and initially containing the
* elements of the given collection,
* added in traversal order of the collection's iterator.
*
* @param capacity the capacity of this queue
- * @param fair if <tt>true</tt> then queue accesses for threads blocked
+ * @param fair if {@code true} then queue accesses for threads blocked
* on insertion or removal, are processed in FIFO order;
- * if <tt>false</tt> the access order is unspecified.
+ * if {@code false} the access order is unspecified.
* @param c the collection of elements to initially contain
- * @throws IllegalArgumentException if <tt>capacity</tt> is less than
- * <tt>c.size()</tt>, or less than 1.
+ * @throws IllegalArgumentException if {@code capacity} is less than
+ * {@code c.size()}, or less than 1.
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
public ArrayBlockingQueue(int capacity, boolean fair,
Collection<? extends E> c) {
this(capacity, fair);
- if (capacity < c.size())
- throw new IllegalArgumentException();
- for (E e : c)
- add(e);
+ final ReentrantLock lock = this.lock;
+ lock.lock(); // Lock only for visibility, not mutual exclusion
+ try {
+ int i = 0;
+ try {
+ for (E e : c) {
+ checkNotNull(e);
+ items[i++] = e;
+ }
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ throw new IllegalArgumentException();
+ }
+ count = i;
+ putIndex = (i == capacity) ? 0 : i;
+ } finally {
+ lock.unlock();
+ }
}
/**
* Inserts the specified element at the tail of this queue if it is
* possible to do so immediately without exceeding the queue's capacity,
- * returning <tt>true</tt> upon success and throwing an
- * <tt>IllegalStateException</tt> if this queue is full.
+ * returning {@code true} upon success and throwing an
+ * {@code IllegalStateException} if this queue is full.
*
* @param e the element to add
- * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @return {@code true} (as specified by {@link Collection#add})
* @throws IllegalStateException if this queue is full
* @throws NullPointerException if the specified element is null
*/
@@ -217,14 +257,14 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
/**
* Inserts the specified element at the tail of this queue if it is
* possible to do so immediately without exceeding the queue's capacity,
- * returning <tt>true</tt> upon success and <tt>false</tt> if this queue
+ * returning {@code true} upon success and {@code false} if this queue
* is full. This method is generally preferable to method {@link #add},
* which can fail to insert an element only by throwing an exception.
*
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
- if (e == null) throw new NullPointerException();
+ checkNotNull(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
@@ -247,18 +287,12 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* @throws NullPointerException {@inheritDoc}
*/
public void put(E e) throws InterruptedException {
- if (e == null) throw new NullPointerException();
- final E[] items = this.items;
+ checkNotNull(e);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- try {
- while (count == items.length)
- notFull.await();
- } catch (InterruptedException ie) {
- notFull.signal(); // propagate to non-interrupted thread
- throw ie;
- }
+ while (count == items.length)
+ notFull.await();
insert(e);
} finally {
lock.unlock();
@@ -276,25 +310,18 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
public boolean offer(E e, long timeout, TimeUnit unit)
throws InterruptedException {
- if (e == null) throw new NullPointerException();
+ checkNotNull(e);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- for (;;) {
- if (count != items.length) {
- insert(e);
- return true;
- }
+ while (count == items.length) {
if (nanos <= 0)
return false;
- try {
- nanos = notFull.awaitNanos(nanos);
- } catch (InterruptedException ie) {
- notFull.signal(); // propagate to non-interrupted thread
- throw ie;
- }
+ nanos = notFull.awaitNanos(nanos);
}
+ insert(e);
+ return true;
} finally {
lock.unlock();
}
@@ -304,10 +331,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- if (count == 0)
- return null;
- E x = extract();
- return x;
+ return (count == 0) ? null : extract();
} finally {
lock.unlock();
}
@@ -317,15 +341,9 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- try {
- while (count == 0)
- notEmpty.await();
- } catch (InterruptedException ie) {
- notEmpty.signal(); // propagate to non-interrupted thread
- throw ie;
- }
- E x = extract();
- return x;
+ while (count == 0)
+ notEmpty.await();
+ return extract();
} finally {
lock.unlock();
}
@@ -336,21 +354,12 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- for (;;) {
- if (count != 0) {
- E x = extract();
- return x;
- }
+ while (count == 0) {
if (nanos <= 0)
return null;
- try {
- nanos = notEmpty.awaitNanos(nanos);
- } catch (InterruptedException ie) {
- notEmpty.signal(); // propagate to non-interrupted thread
- throw ie;
- }
-
+ nanos = notEmpty.awaitNanos(nanos);
}
+ return extract();
} finally {
lock.unlock();
}
@@ -360,7 +369,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return (count == 0) ? null : items[takeIndex];
+ return (count == 0) ? null : itemAt(takeIndex);
} finally {
lock.unlock();
}
@@ -389,10 +398,10 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* Returns the number of additional elements that this queue can ideally
* (in the absence of memory or resource constraints) accept without
* blocking. This is always equal to the initial capacity of this queue
- * less the current <tt>size</tt> of this queue.
+ * less the current {@code size} of this queue.
*
* <p>Note that you <em>cannot</em> always tell if an attempt to insert
- * an element will succeed by inspecting <tt>remainingCapacity</tt>
+ * an element will succeed by inspecting {@code remainingCapacity}
* because it may be the case that another thread is about to
* insert or remove an element.
*/
@@ -408,59 +417,56 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
/**
* Removes a single instance of the specified element from this queue,
- * if it is present. More formally, removes an element <tt>e</tt> such
- * that <tt>o.equals(e)</tt>, if this queue contains one or more such
+ * if it is present. More formally, removes an element {@code e} such
+ * that {@code o.equals(e)}, if this queue contains one or more such
* elements.
- * Returns <tt>true</tt> if this queue contained the specified element
+ * Returns {@code true} if this queue contained the specified element
* (or equivalently, if this queue changed as a result of the call).
*
+ * <p>Removal of interior elements in circular array based queues
+ * is an intrinsically slow and disruptive operation, so should
+ * be undertaken only in exceptional circumstances, ideally
+ * only when the queue is known not to be accessible by other
+ * threads.
+ *
* @param o element to be removed from this queue, if present
- * @return <tt>true</tt> if this queue changed as a result of the call
+ * @return {@code true} if this queue changed as a result of the call
*/
public boolean remove(Object o) {
if (o == null) return false;
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- int i = takeIndex;
- int k = 0;
- for (;;) {
- if (k++ >= count)
- return false;
+ for (int i = takeIndex, k = count; k > 0; i = inc(i), k--) {
if (o.equals(items[i])) {
removeAt(i);
return true;
}
- i = inc(i);
}
-
+ return false;
} finally {
lock.unlock();
}
}
/**
- * Returns <tt>true</tt> if this queue contains the specified element.
- * More formally, returns <tt>true</tt> if and only if this queue contains
- * at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
+ * Returns {@code true} if this queue contains the specified element.
+ * More formally, returns {@code true} if and only if this queue contains
+ * at least one element {@code e} such that {@code o.equals(e)}.
*
* @param o object to be checked for containment in this queue
- * @return <tt>true</tt> if this queue contains the specified element
+ * @return {@code true} if this queue contains the specified element
*/
public boolean contains(Object o) {
if (o == null) return false;
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- int i = takeIndex;
- int k = 0;
- while (k++ < count) {
+ for (int i = takeIndex, k = count; k > 0; i = inc(i), k--)
if (o.equals(items[i]))
return true;
- i = inc(i);
- }
return false;
} finally {
lock.unlock();
@@ -481,17 +487,14 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* @return an array containing all of the elements in this queue
*/
public Object[] toArray() {
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
+ final int count = this.count;
Object[] a = new Object[count];
- int k = 0;
- int i = takeIndex;
- while (k < count) {
- a[k++] = items[i];
- i = inc(i);
- }
+ for (int i = takeIndex, k = 0; k < count; i = inc(i), k++)
+ a[k] = items[i];
return a;
} finally {
lock.unlock();
@@ -508,22 +511,22 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* <p>If this queue fits in the specified array with room to spare
* (i.e., the array has more elements than this queue), the element in
* the array immediately following the end of the queue is set to
- * <tt>null</tt>.
+ * {@code null}.
*
* <p>Like the {@link #toArray()} method, this method acts as bridge between
* array-based and collection-based APIs. Further, this method allows
* precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs.
*
- * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
+ * <p>Suppose {@code x} is a queue known to contain only strings.
* The following code can be used to dump the queue into a newly
- * allocated array of <tt>String</tt>:
+ * allocated array of {@code String}:
*
* <pre>
* String[] y = x.toArray(new String[0]);</pre>
*
- * Note that <tt>toArray(new Object[0])</tt> is identical in function to
- * <tt>toArray()</tt>.
+ * Note that {@code toArray(new Object[0])} is identical in function to
+ * {@code toArray()}.
*
* @param a the array into which the elements of the queue are to
* be stored, if it is big enough; otherwise, a new array of the
@@ -534,24 +537,20 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* this queue
* @throws NullPointerException if the specified array is null
*/
+ @SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- if (a.length < count)
+ final int count = this.count;
+ final int len = a.length;
+ if (len < count)
a = (T[])java.lang.reflect.Array.newInstance(
- a.getClass().getComponentType(),
- count
- );
-
- int k = 0;
- int i = takeIndex;
- while (k < count) {
- a[k++] = (T)items[i];
- i = inc(i);
- }
- if (a.length > count)
+ a.getClass().getComponentType(), count);
+ for (int i = takeIndex, k = 0; k < count; i = inc(i), k++)
+ a[k] = (T) items[i];
+ if (len > count)
a[count] = null;
return a;
} finally {
@@ -563,7 +562,19 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return super.toString();
+ int k = count;
+ if (k == 0)
+ return "[]";
+
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (int i = takeIndex; ; i = inc(i)) {
+ Object e = items[i];
+ sb.append(e == this ? "(this Collection)" : e);
+ if (--k == 0)
+ return sb.append(']').toString();
+ sb.append(',').append(' ');
+ }
} finally {
lock.unlock();
}
@@ -574,16 +585,12 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* The queue will be empty after this call returns.
*/
public void clear() {
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- int i = takeIndex;
- int k = count;
- while (k-- > 0) {
+ for (int i = takeIndex, k = count; k > 0; i = inc(i), k--)
items[i] = null;
- i = inc(i);
- }
count = 0;
putIndex = 0;
takeIndex = 0;
@@ -600,11 +607,10 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c) {
- if (c == null)
- throw new NullPointerException();
+ checkNotNull(c);
if (c == this)
throw new IllegalArgumentException();
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
@@ -612,7 +618,7 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
int n = 0;
int max = count;
while (n < max) {
- c.add(items[i]);
+ c.add(this.<E>cast(items[i]));
items[i] = null;
i = inc(i);
++n;
@@ -636,22 +642,20 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* @throws IllegalArgumentException {@inheritDoc}
*/
public int drainTo(Collection<? super E> c, int maxElements) {
- if (c == null)
- throw new NullPointerException();
+ checkNotNull(c);
if (c == this)
throw new IllegalArgumentException();
if (maxElements <= 0)
return 0;
- final E[] items = this.items;
+ final Object[] items = this.items;
final ReentrantLock lock = this.lock;
lock.lock();
try {
int i = takeIndex;
int n = 0;
- int sz = count;
- int max = (maxElements < count)? maxElements : count;
+ int max = (maxElements < count) ? maxElements : count;
while (n < max) {
- c.add(items[i]);
+ c.add(this.<E>cast(items[i]));
items[i] = null;
i = inc(i);
++n;
@@ -667,11 +671,13 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
}
}
-
/**
* Returns an iterator over the elements in this queue in proper sequence.
- * The returned <tt>Iterator</tt> is a "weakly consistent" iterator that
- * will never throw {@link ConcurrentModificationException},
+ * The elements will be returned in order from first (head) to last (tail).
+ *
+ * <p>The returned {@code Iterator} is a "weakly consistent" iterator that
+ * will never throw {@link java.util.ConcurrentModificationException
+ * ConcurrentModificationException},
* and guarantees to traverse elements as they existed upon
* construction of the iterator, and may (but is not guaranteed to)
* reflect any modifications subsequent to construction.
@@ -679,83 +685,65 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
* @return an iterator over the elements in this queue in proper sequence
*/
public Iterator<E> iterator() {
- final ReentrantLock lock = this.lock;
- lock.lock();
- try {
- return new Itr();
- } finally {
- lock.unlock();
- }
+ return new Itr();
}
/**
- * Iterator for ArrayBlockingQueue
+ * Iterator for ArrayBlockingQueue. To maintain weak consistency
+ * with respect to puts and takes, we (1) read ahead one slot, so
+ * as to not report hasNext true but then not have an element to
+ * return -- however we later recheck this slot to use the most
+ * current value; (2) ensure that each array slot is traversed at
+ * most once (by tracking "remaining" elements); (3) skip over
+ * null slots, which can occur if takes race ahead of iterators.
+ * However, for circular array-based queues, we cannot rely on any
+ * well established definition of what it means to be weakly
+ * consistent with respect to interior removes since these may
+ * require slot overwrites in the process of sliding elements to
+ * cover gaps. So we settle for resiliency, operating on
+ * established apparent nexts, which may miss some elements that
+ * have moved between calls to next.
*/
private class Itr implements Iterator<E> {
- /**
- * Index of element to be returned by next,
- * or a negative number if no such.
- */
- private int nextIndex;
-
- /**
- * nextItem holds on to item fields because once we claim
- * that an element exists in hasNext(), we must return it in
- * the following next() call even if it was in the process of
- * being removed when hasNext() was called.
- */
- private E nextItem;
-
- /**
- * Index of element returned by most recent call to next.
- * Reset to -1 if this element is deleted by a call to remove.
- */
- private int lastRet;
+ private int remaining; // Number of elements yet to be returned
+ private int nextIndex; // Index of element to be returned by next
+ private E nextItem; // Element to be returned by next call to next
+ private E lastItem; // Element returned by last call to next
+ private int lastRet; // Index of last element returned, or -1 if none
Itr() {
- lastRet = -1;
- if (count == 0)
- nextIndex = -1;
- else {
- nextIndex = takeIndex;
- nextItem = items[takeIndex];
+ final ReentrantLock lock = ArrayBlockingQueue.this.lock;
+ lock.lock();
+ try {
+ lastRet = -1;
+ if ((remaining = count) > 0)
+ nextItem = itemAt(nextIndex = takeIndex);
+ } finally {
+ lock.unlock();
}
}
public boolean hasNext() {
- /*
- * No sync. We can return true by mistake here
- * only if this iterator passed across threads,
- * which we don't support anyway.
- */
- return nextIndex >= 0;
- }
-
- /**
- * Checks whether nextIndex is valid; if so setting nextItem.
- * Stops iterator when either hits putIndex or sees null item.
- */
- private void checkNext() {
- if (nextIndex == putIndex) {
- nextIndex = -1;
- nextItem = null;
- } else {
- nextItem = items[nextIndex];
- if (nextItem == null)
- nextIndex = -1;
- }
+ return remaining > 0;
}
public E next() {
final ReentrantLock lock = ArrayBlockingQueue.this.lock;
lock.lock();
try {
- if (nextIndex < 0)
+ if (remaining <= 0)
throw new NoSuchElementException();
lastRet = nextIndex;
- E x = nextItem;
- nextIndex = inc(nextIndex);
- checkNext();
+ E x = itemAt(nextIndex); // check for fresher value
+ if (x == null) {
+ x = nextItem; // we are forced to report old value
+ lastItem = null; // but ensure remove fails
+ }
+ else
+ lastItem = x;
+ while (--remaining > 0 && // skip over nulls
+ (nextItem = itemAt(nextIndex = inc(nextIndex))) == null)
+ ;
return x;
} finally {
lock.unlock();
@@ -770,15 +758,19 @@ public class ArrayBlockingQueue<E> extends AbstractQueue<E>
if (i == -1)
throw new IllegalStateException();
lastRet = -1;
-
- int ti = takeIndex;
- removeAt(i);
- // back up cursor (reset to front if was first element)
- nextIndex = (i == ti) ? takeIndex : i;
- checkNext();
+ E x = lastItem;
+ lastItem = null;
+ // only remove if item still at index
+ if (x != null && x == items[i]) {
+ boolean removingHead = (i == takeIndex);
+ removeAt(i);
+ if (!removingHead)
+ nextIndex = dec(nextIndex);
+ }
} finally {
lock.unlock();
}
}
}
+
}
diff --git a/luni/src/main/java/java/util/concurrent/BlockingDeque.java b/luni/src/main/java/java/util/concurrent/BlockingDeque.java
index 2074061..136df9c 100644
--- a/luni/src/main/java/java/util/concurrent/BlockingDeque.java
+++ b/luni/src/main/java/java/util/concurrent/BlockingDeque.java
@@ -5,10 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
+import java.util.*;
/**
* A {@link Deque} that additionally supports blocking operations that wait
@@ -39,9 +36,9 @@ import java.util.NoSuchElementException;
* <tr>
* <td><b>Insert</b></td>
* <td>{@link #addFirst addFirst(e)}</td>
- * <td>{@link #offerFirst(E) offerFirst(e)}</td>
+ * <td>{@link #offerFirst offerFirst(e)}</td>
* <td>{@link #putFirst putFirst(e)}</td>
- * <td>{@link #offerFirst(E, long, TimeUnit) offerFirst(e, time, unit)}</td>
+ * <td>{@link #offerFirst offerFirst(e, time, unit)}</td>
* </tr>
* <tr>
* <td><b>Remove</b></td>
@@ -70,9 +67,9 @@ import java.util.NoSuchElementException;
* <tr>
* <td><b>Insert</b></td>
* <td>{@link #addLast addLast(e)}</td>
- * <td>{@link #offerLast(E) offerLast(e)}</td>
+ * <td>{@link #offerLast offerLast(e)}</td>
* <td>{@link #putLast putLast(e)}</td>
- * <td>{@link #offerLast(E, long, TimeUnit) offerLast(e, time, unit)}</td>
+ * <td>{@link #offerLast offerLast(e, time, unit)}</td>
* </tr>
* <tr>
* <td><b>Remove</b></td>
@@ -109,20 +106,20 @@ import java.util.NoSuchElementException;
* <td ALIGN=CENTER COLSPAN = 2> <b>Insert</b></td>
* </tr>
* <tr>
- * <td>{@link #add(E) add(e)}</td>
- * <td>{@link #addLast(E) addLast(e)}</td>
+ * <td>{@link #add add(e)}</td>
+ * <td>{@link #addLast addLast(e)}</td>
* </tr>
* <tr>
- * <td>{@link #offer(E) offer(e)}</td>
- * <td>{@link #offerLast(E) offerLast(e)}</td>
+ * <td>{@link #offer offer(e)}</td>
+ * <td>{@link #offerLast offerLast(e)}</td>
* </tr>
* <tr>
- * <td>{@link #put(E) put(e)}</td>
- * <td>{@link #putLast(E) putLast(e)}</td>
+ * <td>{@link #put put(e)}</td>
+ * <td>{@link #putLast putLast(e)}</td>
* </tr>
* <tr>
- * <td>{@link #offer(E, long, TimeUnit) offer(e, time, unit)}</td>
- * <td>{@link #offerLast(E, long, TimeUnit) offerLast(e, time, unit)}</td>
+ * <td>{@link #offer offer(e, time, unit)}</td>
+ * <td>{@link #offerLast offerLast(e, time, unit)}</td>
* </tr>
* <tr>
* <td ALIGN=CENTER COLSPAN = 2> <b>Remove</b></td>
@@ -184,7 +181,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* possible to do so immediately without violating capacity restrictions,
* throwing an <tt>IllegalStateException</tt> if no space is currently
* available. When using a capacity-restricted deque, it is generally
- * preferable to use {@link #offerFirst(E) offerFirst}.
+ * preferable to use {@link #offerFirst offerFirst}.
*
* @param e the element to add
* @throws IllegalStateException {@inheritDoc}
@@ -199,7 +196,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* possible to do so immediately without violating capacity restrictions,
* throwing an <tt>IllegalStateException</tt> if no space is currently
* available. When using a capacity-restricted deque, it is generally
- * preferable to use {@link #offerLast(E) offerLast}.
+ * preferable to use {@link #offerLast offerLast}.
*
* @param e the element to add
* @throws IllegalStateException {@inheritDoc}
@@ -215,7 +212,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* returning <tt>true</tt> upon success and <tt>false</tt> if no space is
* currently available.
* When using a capacity-restricted deque, this method is generally
- * preferable to the {@link #addFirst(E) addFirst} method, which can
+ * preferable to the {@link #addFirst addFirst} method, which can
* fail to insert an element only by throwing an exception.
*
* @param e the element to add
@@ -231,7 +228,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* returning <tt>true</tt> upon success and <tt>false</tt> if no space is
* currently available.
* When using a capacity-restricted deque, this method is generally
- * preferable to the {@link #addLast(E) addLast} method, which can
+ * preferable to the {@link #addLast addLast} method, which can
* fail to insert an element only by throwing an exception.
*
* @param e the element to add
@@ -404,9 +401,9 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* <tt>true</tt> upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available.
* When using a capacity-restricted deque, it is generally preferable to
- * use {@link #offer(E) offer}.
+ * use {@link #offer offer}.
*
- * <p>This method is equivalent to {@link #addLast(E) addLast}.
+ * <p>This method is equivalent to {@link #addLast addLast}.
*
* @param e the element to add
* @throws IllegalStateException {@inheritDoc}
@@ -427,7 +424,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* generally preferable to the {@link #add} method, which can fail to
* insert an element only by throwing an exception.
*
- * <p>This method is equivalent to {@link #offerLast(E) offerLast}.
+ * <p>This method is equivalent to {@link #offerLast offerLast}.
*
* @param e the element to add
* @throws ClassCastException if the class of the specified element
@@ -443,7 +440,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* (in other words, at the tail of this deque), waiting if necessary for
* space to become available.
*
- * <p>This method is equivalent to {@link #putLast(E) putLast}.
+ * <p>This method is equivalent to {@link #putLast putLast}.
*
* @param e the element to add
* @throws InterruptedException {@inheritDoc}
@@ -461,7 +458,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* specified wait time if necessary for space to become available.
*
* <p>This method is equivalent to
- * {@link #offerLast(E,long,TimeUnit) offerLast}.
+ * {@link #offerLast offerLast}.
*
* @param e the element to add
* @return <tt>true</tt> if the element was added to this deque, else
@@ -560,7 +557,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* (or equivalently, if this deque changed as a result of the call).
*
* <p>This method is equivalent to
- * {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
+ * {@link #removeFirstOccurrence removeFirstOccurrence}.
*
* @param o element to be removed from this deque, if present
* @return <tt>true</tt> if this deque changed as a result of the call
@@ -605,7 +602,7 @@ public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
* words, inserts the element at the front of this deque unless it would
* violate capacity restrictions.
*
- * <p>This method is equivalent to {@link #addFirst(E) addFirst}.
+ * <p>This method is equivalent to {@link #addFirst addFirst}.
*
* @throws IllegalStateException {@inheritDoc}
* @throws ClassCastException {@inheritDoc}
diff --git a/luni/src/main/java/java/util/concurrent/BlockingQueue.java b/luni/src/main/java/java/util/concurrent/BlockingQueue.java
index 0690dd7..d01c097 100644
--- a/luni/src/main/java/java/util/concurrent/BlockingQueue.java
+++ b/luni/src/main/java/java/util/concurrent/BlockingQueue.java
@@ -42,7 +42,7 @@ import java.util.Queue;
* <td>{@link #add add(e)}</td>
* <td>{@link #offer offer(e)}</td>
* <td>{@link #put put(e)}</td>
- * <td>{@link #offer(E, long, TimeUnit) offer(e, time, unit)}</td>
+ * <td>{@link #offer offer(e, time, unit)}</td>
* </tr>
* <tr>
* <td><b>Remove</b></td>
@@ -156,7 +156,7 @@ public interface BlockingQueue<E> extends Queue<E> {
* <tt>true</tt> upon success and throwing an
* <tt>IllegalStateException</tt> if no space is currently available.
* When using a capacity-restricted queue, it is generally preferable to
- * use {@link #offer(E) offer}.
+ * use {@link #offer offer}.
*
* @param e the element to add
* @return <tt>true</tt> (as specified by {@link Collection#add})
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java b/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
index 1685325..c142e2a 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentHashMap.java
@@ -5,22 +5,12 @@
*/
package java.util.concurrent;
-
-import java.io.IOException;
+import java.util.concurrent.locks.*;
+import java.util.*;
import java.io.Serializable;
-import java.util.AbstractCollection;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.concurrent.locks.ReentrantLock;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
// BEGIN android-note
// removed link to collections framework docs
@@ -1251,7 +1241,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
* for each key-value mapping, followed by a null pair.
* The key-value mappings are emitted in no particular order.
*/
- private void writeObject(java.io.ObjectOutputStream s) throws IOException {
+ private void writeObject(java.io.ObjectOutputStream s) throws IOException {
s.defaultWriteObject();
for (int k = 0; k < segments.length; ++k) {
@@ -1279,7 +1269,7 @@ public class ConcurrentHashMap<K, V> extends AbstractMap<K, V>
* @param s the stream
*/
private void readObject(java.io.ObjectInputStream s)
- throws IOException, ClassNotFoundException {
+ throws IOException, ClassNotFoundException {
s.defaultReadObject();
// Initialize each segment to be minimally sized, and let grow.
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentLinkedDeque.java b/luni/src/main/java/java/util/concurrent/ConcurrentLinkedDeque.java
index 3845ade..72c2e08 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentLinkedDeque.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentLinkedDeque.java
@@ -9,48 +9,54 @@ package java.util.concurrent;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.ConcurrentModificationException;
import java.util.Deque;
import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.util.Queue;
+
+// BEGIN android-note
+// removed link to collections framework docs
+// END android-note
/**
- * A concurrent linked-list implementation of a {@link Deque}
- * (double-ended queue). Concurrent insertion, removal, and access
- * operations execute safely across multiple threads. Iterators are
- * <i>weakly consistent</i>, returning elements reflecting the state
- * of the deque at some point at or since the creation of the
- * iterator. They do <em>not</em> throw {@link
+ * An unbounded concurrent {@linkplain Deque deque} based on linked nodes.
+ * Concurrent insertion, removal, and access operations execute safely
+ * across multiple threads.
+ * A {@code ConcurrentLinkedDeque} is an appropriate choice when
+ * many threads will share access to a common collection.
+ * Like most other concurrent collection implementations, this class
+ * does not permit the use of {@code null} elements.
+ *
+ * <p>Iterators are <i>weakly consistent</i>, returning elements
+ * reflecting the state of the deque at some point at or since the
+ * creation of the iterator. They do <em>not</em> throw {@link
+ * java.util.ConcurrentModificationException
* ConcurrentModificationException}, and may proceed concurrently with
* other operations.
*
- * <p>This class and its iterators implement all of the
- * <em>optional</em> methods of the {@link Collection} and {@link
- * Iterator} interfaces. Like most other concurrent collection
- * implementations, this class does not permit the use of
- * {@code null} elements. because some null arguments and return
- * values cannot be reliably distinguished from the absence of
- * elements. Arbitrarily, the {@link Collection#remove} method is
- * mapped to {@code removeFirstOccurrence}, and {@link
- * Collection#add} is mapped to {@code addLast}.
- *
* <p>Beware that, unlike in most collections, the {@code size}
* method is <em>NOT</em> a constant-time operation. Because of the
* asynchronous nature of these deques, determining the current number
* of elements requires a traversal of the elements.
*
- * <p>This class is {@code Serializable}, but relies on default
- * serialization mechanisms. Usually, it is a better idea for any
- * serializable class using a {@code ConcurrentLinkedDeque} to instead
- * serialize a snapshot of the elements obtained by method
- * {@code toArray}.
+ * <p>This class and its iterator implement all of the <em>optional</em>
+ * methods of the {@link Deque} and {@link Iterator} interfaces.
+ *
+ * <p>Memory consistency effects: As with other concurrent collections,
+ * actions in a thread prior to placing an object into a
+ * {@code ConcurrentLinkedDeque}
+ * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
+ * actions subsequent to the access or removal of that element from
+ * the {@code ConcurrentLinkedDeque} in another thread.
*
* @hide
*
- * @author Doug Lea
- * @author Martin Buchholz
+ * @since 1.7
+ * @author Doug Lea
+ * @author Martin Buchholz
* @param <E> the type of elements held in this collection
*/
+
public class ConcurrentLinkedDeque<E>
extends AbstractCollection<E>
implements Deque<E>, java.io.Serializable {
@@ -58,70 +64,113 @@ public class ConcurrentLinkedDeque<E>
/*
* This is an implementation of a concurrent lock-free deque
* supporting interior removes but not interior insertions, as
- * required to fully support the Deque interface.
+ * required to support the entire Deque interface.
+ *
+ * We extend the techniques developed for ConcurrentLinkedQueue and
+ * LinkedTransferQueue (see the internal docs for those classes).
+ * Understanding the ConcurrentLinkedQueue implementation is a
+ * prerequisite for understanding the implementation of this class.
+ *
+ * The data structure is a symmetrical doubly-linked "GC-robust"
+ * linked list of nodes. We minimize the number of volatile writes
+ * using two techniques: advancing multiple hops with a single CAS
+ * and mixing volatile and non-volatile writes of the same memory
+ * locations.
+ *
+ * A node contains the expected E ("item") and links to predecessor
+ * ("prev") and successor ("next") nodes:
+ *
+ * class Node<E> { volatile Node<E> prev, next; volatile E item; }
*
- * We extend the techniques developed for
- * ConcurrentLinkedQueue and LinkedTransferQueue
- * (see the internal docs for those classes).
+ * A node p is considered "live" if it contains a non-null item
+ * (p.item != null). When an item is CASed to null, the item is
+ * atomically logically deleted from the collection.
*
- * At any time, there is precisely one "first" active node with a
- * null prev pointer. Similarly there is one "last" active node
- * with a null next pointer. New nodes are simply enqueued by
- * null-CASing.
+ * At any time, there is precisely one "first" node with a null
+ * prev reference that terminates any chain of prev references
+ * starting at a live node. Similarly there is precisely one
+ * "last" node terminating any chain of next references starting at
+ * a live node. The "first" and "last" nodes may or may not be live.
+ * The "first" and "last" nodes are always mutually reachable.
*
- * A node p is considered "active" if it either contains an
- * element, or is an end node and neither next nor prev pointers
- * are self-links:
+ * A new element is added atomically by CASing the null prev or
+ * next reference in the first or last node to a fresh node
+ * containing the element. The element's node atomically becomes
+ * "live" at that point.
+ *
+ * A node is considered "active" if it is a live node, or the
+ * first or last node. Active nodes cannot be unlinked.
+ *
+ * A "self-link" is a next or prev reference that is the same node:
+ * p.prev == p or p.next == p
+ * Self-links are used in the node unlinking process. Active nodes
+ * never have self-links.
+ *
+ * A node p is active if and only if:
*
* p.item != null ||
* (p.prev == null && p.next != p) ||
* (p.next == null && p.prev != p)
*
- * The head and tail pointers are only approximations to the start
- * and end of the deque. The first node can always be found by
+ * The deque object has two node references, "head" and "tail".
+ * The head and tail are only approximations to the first and last
+ * nodes of the deque. The first node can always be found by
* following prev pointers from head; likewise for tail. However,
- * head and tail may be pointing at deleted nodes that have been
- * unlinked and so may not be reachable from any live node.
+ * it is permissible for head and tail to be referring to deleted
+ * nodes that have been unlinked and so may not be reachable from
+ * any live node.
+ *
+ * There are 3 stages of node deletion;
+ * "logical deletion", "unlinking", and "gc-unlinking".
+ *
+ * 1. "logical deletion" by CASing item to null atomically removes
+ * the element from the collection, and makes the containing node
+ * eligible for unlinking.
*
- * There are 3 levels of node deletion:
- * - logical deletion atomically removes the element
- * - "unlinking" makes a deleted node unreachable from active
- * nodes, and thus eventually reclaimable by GC
- * - "gc-unlinking" further does the reverse of making active
- * nodes unreachable from deleted nodes, making it easier for
- * the GC to reclaim future deleted nodes
+ * 2. "unlinking" makes a deleted node unreachable from active
+ * nodes, and thus eventually reclaimable by GC. Unlinked nodes
+ * may remain reachable indefinitely from an iterator.
*
- * TODO: find a better name for "gc-unlinked"
+ * Physical node unlinking is merely an optimization (albeit a
+ * critical one), and so can be performed at our convenience. At
+ * any time, the set of live nodes maintained by prev and next
+ * links are identical, that is, the live nodes found via next
+ * links from the first node is equal to the elements found via
+ * prev links from the last node. However, this is not true for
+ * nodes that have already been logically deleted - such nodes may
+ * be reachable in one direction only.
*
- * Logical deletion of a node simply involves CASing its element
- * to null. Physical deletion is merely an optimization (albeit a
- * critical one), and can be performed at our convenience. At any
- * time, the set of non-logically-deleted nodes maintained by prev
- * and next links are identical, that is the live elements found
- * via next links from the first node is equal to the elements
- * found via prev links from the last node. However, this is not
- * true for nodes that have already been logically deleted - such
- * nodes may only be reachable in one direction.
+ * 3. "gc-unlinking" takes unlinking further by making active
+ * nodes unreachable from deleted nodes, making it easier for the
+ * GC to reclaim future deleted nodes. This step makes the data
+ * structure "gc-robust", as first described in detail by Boehm
+ * (http://portal.acm.org/citation.cfm?doid=503272.503282).
*
- * When a node is dequeued at either end, e.g. via poll(), we
- * would like to break any references from the node to live nodes,
- * to stop old garbage from causing retention of new garbage with
- * a generational or conservative GC. We develop further the
- * self-linking trick that was very effective in other concurrent
- * collection classes. The idea is to replace prev and next
- * pointers to active nodes with special values that are
- * interpreted to mean off-the-list-at-one-end. These are
- * approximations, but good enough to preserve the properties we
- * want in our traversals, e.g. we guarantee that a traversal will
- * never hit the same element twice, but we don't guarantee
- * whether a traversal that runs out of elements will be able to
- * see more elements later after more elements are added at that
- * end. Doing gc-unlinking safely is particularly tricky, since
- * any node can be in use indefinitely (for example by an
- * iterator). We must make sure that the nodes pointed at by
- * head/tail do not get gc-unlinked, since head/tail are needed to
- * get "back on track" by other nodes that are gc-unlinked.
- * gc-unlinking accounts for much of the implementation complexity.
+ * GC-unlinked nodes may remain reachable indefinitely from an
+ * iterator, but unlike unlinked nodes, are never reachable from
+ * head or tail.
+ *
+ * Making the data structure GC-robust will eliminate the risk of
+ * unbounded memory retention with conservative GCs and is likely
+ * to improve performance with generational GCs.
+ *
+ * When a node is dequeued at either end, e.g. via poll(), we would
+ * like to break any references from the node to active nodes. We
+ * develop further the use of self-links that was very effective in
+ * other concurrent collection classes. The idea is to replace
+ * prev and next pointers with special values that are interpreted
+ * to mean off-the-list-at-one-end. These are approximations, but
+ * good enough to preserve the properties we want in our
+ * traversals, e.g. we guarantee that a traversal will never visit
+ * the same element twice, but we don't guarantee whether a
+ * traversal that runs out of elements will be able to see more
+ * elements later after enqueues at that end. Doing gc-unlinking
+ * safely is particularly tricky, since any node can be in use
+ * indefinitely (for example by an iterator). We must ensure that
+ * the nodes pointed at by head/tail never get gc-unlinked, since
+ * head/tail are needed to get "back on track" by other nodes that
+ * are gc-unlinked. gc-unlinking accounts for much of the
+ * implementation complexity.
*
* Since neither unlinking nor gc-unlinking are necessary for
* correctness, there are many implementation choices regarding
@@ -133,45 +182,68 @@ public class ConcurrentLinkedDeque<E>
* are occasionally broken.
*
* The actual representation we use is that p.next == p means to
- * goto the first node, and p.next == null && p.prev == p means
- * that the iteration is at an end and that p is a (final static)
+ * goto the first node (which in turn is reached by following prev
+ * pointers from head), and p.next == null && p.prev == p means
+ * that the iteration is at an end and that p is a (static final)
* dummy node, NEXT_TERMINATOR, and not the last active node.
* Finishing the iteration when encountering such a TERMINATOR is
- * good enough for read-only traversals. When the last active
- * node is desired, for example when enqueueing, goto tail and
- * continue traversal.
+ * good enough for read-only traversals, so such traversals can use
+ * p.next == null as the termination condition. When we need to
+ * find the last (active) node, for enqueueing a new node, we need
+ * to check whether we have reached a TERMINATOR node; if so,
+ * restart traversal from tail.
*
* The implementation is completely directionally symmetrical,
* except that most public methods that iterate through the list
* follow next pointers ("forward" direction).
*
- * There is one desirable property we would like to have, but
- * don't: it is possible, when an addFirst(A) is racing with
- * pollFirst() removing B, for an iterating observer to see A B C
- * and subsequently see A C, even though no interior removes are
- * ever performed. I believe this wart can only be removed at
- * significant runtime cost.
+ * We believe (without full proof) that all single-element deque
+ * operations (e.g., addFirst, peekLast, pollLast) are linearizable
+ * (see Herlihy and Shavit's book). However, some combinations of
+ * operations are known not to be linearizable. In particular,
+ * when an addFirst(A) is racing with pollFirst() removing B, it is
+ * possible for an observer iterating over the elements to observe
+ * A B C and subsequently observe A C, even though no interior
+ * removes are ever performed. Nevertheless, iterators behave
+ * reasonably, providing the "weakly consistent" guarantees.
*
* Empirically, microbenchmarks suggest that this class adds about
* 40% overhead relative to ConcurrentLinkedQueue, which feels as
* good as we can hope for.
*/
+ private static final long serialVersionUID = 876323262645176354L;
+
/**
- * A node from which the first node on list (that is, the unique
- * node with node.prev == null) can be reached in O(1) time.
+ * A node from which the first node on list (that is, the unique node p
+ * with p.prev == null && p.next != p) can be reached in O(1) time.
* Invariants:
* - the first node is always O(1) reachable from head via prev links
* - all live nodes are reachable from the first node via succ()
* - head != null
* - (tmp = head).next != tmp || tmp != head
+ * - head is never gc-unlinked (but may be unlinked)
* Non-invariants:
* - head.item may or may not be null
* - head may not be reachable from the first or last node, or from tail
*/
- private transient volatile Node<E> head = new Node<E>(null);
+ private transient volatile Node<E> head;
- private final static Node<Object> PREV_TERMINATOR, NEXT_TERMINATOR;
+ /**
+ * A node from which the last node on list (that is, the unique node p
+ * with p.next == null && p.prev != p) can be reached in O(1) time.
+ * Invariants:
+ * - the last node is always O(1) reachable from tail via next links
+ * - all live nodes are reachable from the last node via pred()
+ * - tail != null
+ * - tail is never gc-unlinked (but may be unlinked)
+ * Non-invariants:
+ * - tail.item may or may not be null
+ * - tail may not be reachable from the first or last node, or from head
+ */
+ private transient volatile Node<E> tail;
+
+ private static final Node<Object> PREV_TERMINATOR, NEXT_TERMINATOR;
static {
PREV_TERMINATOR = new Node<Object>(null);
@@ -190,37 +262,23 @@ public class ConcurrentLinkedDeque<E>
return (Node<E>) NEXT_TERMINATOR;
}
- /**
- * A node from which the last node on list (that is, the unique
- * node with node.next == null) can be reached in O(1) time.
- * Invariants:
- * - the last node is always O(1) reachable from tail via next links
- * - all live nodes are reachable from the last node via pred()
- * - tail != null
- * Non-invariants:
- * - tail.item may or may not be null
- * - tail may not be reachable from the first or last node, or from head
- */
- private transient volatile Node<E> tail = head;
-
static final class Node<E> {
volatile Node<E> prev;
volatile E item;
volatile Node<E> next;
+ /**
+ * Constructs a new node. Uses relaxed write because item can
+ * only be seen after publication via casNext or casPrev.
+ */
Node(E item) {
- // Piggyback on imminent casNext() or casPrev()
- lazySetItem(item);
+ UNSAFE.putObject(this, itemOffset, item);
}
boolean casItem(E cmp, E val) {
return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val);
}
- void lazySetItem(E val) {
- UNSAFE.putOrderedObject(this, itemOffset, val);
- }
-
void lazySetNext(Node<E> val) {
UNSAFE.putOrderedObject(this, nextOffset, val);
}
@@ -256,28 +314,30 @@ public class ConcurrentLinkedDeque<E>
checkNotNull(e);
final Node<E> newNode = new Node<E>(e);
- retry:
- for (;;) {
- for (Node<E> h = head, p = h;;) {
- Node<E> q = p.prev;
- if (q == null) {
- if (p.next == p)
- continue retry;
+ restartFromHead:
+ for (;;)
+ for (Node<E> h = head, p = h, q;;) {
+ if ((q = p.prev) != null &&
+ (q = (p = q).prev) != null)
+ // Check for head updates every other hop.
+ // If p == q, we are sure to follow head instead.
+ p = (h != (h = head)) ? h : q;
+ else if (p.next == p) // PREV_TERMINATOR
+ continue restartFromHead;
+ else {
+ // p is first node
newNode.lazySetNext(p); // CAS piggyback
if (p.casPrev(null, newNode)) {
+ // Successful CAS is the linearization point
+ // for e to become an element of this deque,
+ // and for newNode to become "live".
if (p != h) // hop two nodes at a time
- casHead(h, newNode);
+ casHead(h, newNode); // Failure is OK.
return;
- } else {
- p = p.prev; // lost CAS race to another thread
}
+ // Lost CAS race to another thread; re-read prev
}
- else if (p == q)
- continue retry;
- else
- p = q;
}
- }
}
/**
@@ -287,53 +347,42 @@ public class ConcurrentLinkedDeque<E>
checkNotNull(e);
final Node<E> newNode = new Node<E>(e);
- retry:
- for (;;) {
- for (Node<E> t = tail, p = t;;) {
- Node<E> q = p.next;
- if (q == null) {
- if (p.prev == p)
- continue retry;
+ restartFromTail:
+ for (;;)
+ for (Node<E> t = tail, p = t, q;;) {
+ if ((q = p.next) != null &&
+ (q = (p = q).next) != null)
+ // Check for tail updates every other hop.
+ // If p == q, we are sure to follow tail instead.
+ p = (t != (t = tail)) ? t : q;
+ else if (p.prev == p) // NEXT_TERMINATOR
+ continue restartFromTail;
+ else {
+ // p is last node
newNode.lazySetPrev(p); // CAS piggyback
if (p.casNext(null, newNode)) {
+ // Successful CAS is the linearization point
+ // for e to become an element of this deque,
+ // and for newNode to become "live".
if (p != t) // hop two nodes at a time
- casTail(t, newNode);
+ casTail(t, newNode); // Failure is OK.
return;
- } else {
- p = p.next; // lost CAS race to another thread
}
+ // Lost CAS race to another thread; re-read next
}
- else if (p == q)
- continue retry;
- else
- p = q;
}
- }
}
- // TODO: Is there a better cheap way of performing some cleanup
- // operation "occasionally"?
- static class Count {
- int count = 0;
- }
- private final static ThreadLocal<Count> tlc =
- new ThreadLocal<Count>() {
- protected Count initialValue() { return new Count(); }
- };
- private static boolean shouldGCUnlinkOccasionally() {
- return (tlc.get().count++ & 0x3) == 0;
- }
-
- private final static int HOPS = 2;
+ private static final int HOPS = 2;
/**
* Unlinks non-null node x.
*/
void unlink(Node<E> x) {
- assert x != null;
- assert x.item == null;
- assert x != PREV_TERMINATOR;
- assert x != NEXT_TERMINATOR;
+ // assert x != null;
+ // assert x.item == null;
+ // assert x != PREV_TERMINATOR;
+ // assert x != NEXT_TERMINATOR;
final Node<E> prev = x.prev;
final Node<E> next = x.next;
@@ -346,7 +395,7 @@ public class ConcurrentLinkedDeque<E>
//
// This is the common case, since a series of polls at the
// same end will be "interior" removes, except perhaps for
- // the first one, since end nodes cannot be physically removed.
+ // the first one, since end nodes cannot be unlinked.
//
// At any time, all active nodes are mutually reachable by
// following a sequence of either next or prev pointers.
@@ -355,18 +404,18 @@ public class ConcurrentLinkedDeque<E>
// and successor of x. Try to fix up their links so that
// they point to each other, leaving x unreachable from
// active nodes. If successful, and if x has no live
- // predecessor/successor, we additionally try to leave
- // active nodes unreachable from x, by rechecking that
- // the status of predecessor and successor are unchanged
- // and ensuring that x is not reachable from tail/head,
- // before setting x's prev/next links to their logical
- // approximate replacements, self/TERMINATOR.
+ // predecessor/successor, we additionally try to gc-unlink,
+ // leaving active nodes unreachable from x, by rechecking
+ // that the status of predecessor and successor are
+ // unchanged and ensuring that x is not reachable from
+ // tail/head, before setting x's prev/next links to their
+ // logical approximate replacements, self/TERMINATOR.
Node<E> activePred, activeSucc;
boolean isFirst, isLast;
int hops = 1;
// Find active predecessor
- for (Node<E> p = prev;; ++hops) {
+ for (Node<E> p = prev; ; ++hops) {
if (p.item != null) {
activePred = p;
isFirst = false;
@@ -374,7 +423,7 @@ public class ConcurrentLinkedDeque<E>
}
Node<E> q = p.prev;
if (q == null) {
- if (p == p.next)
+ if (p.next == p)
return;
activePred = p;
isFirst = true;
@@ -387,7 +436,7 @@ public class ConcurrentLinkedDeque<E>
}
// Find active successor
- for (Node<E> p = next;; ++hops) {
+ for (Node<E> p = next; ; ++hops) {
if (p.item != null) {
activeSucc = p;
isLast = false;
@@ -395,7 +444,7 @@ public class ConcurrentLinkedDeque<E>
}
Node<E> q = p.next;
if (q == null) {
- if (p == p.prev)
+ if (p.prev == p)
return;
activeSucc = p;
isLast = true;
@@ -420,7 +469,6 @@ public class ConcurrentLinkedDeque<E>
// Try to gc-unlink, if possible
if ((isFirst | isLast) &&
- //shouldGCUnlinkOccasionally() &&
// Recheck expected state of predecessor and successor
(activePred.next == activeSucc) &&
@@ -428,9 +476,10 @@ public class ConcurrentLinkedDeque<E>
(isFirst ? activePred.prev == null : activePred.item != null) &&
(isLast ? activeSucc.next == null : activeSucc.item != null)) {
- // Ensure x is not reachable from head or tail
- updateHead();
- updateTail();
+ updateHead(); // Ensure x is not reachable from head
+ updateTail(); // Ensure x is not reachable from tail
+
+ // Finally, actually gc-unlink
x.lazySetPrev(isFirst ? prevTerminator() : x);
x.lazySetNext(isLast ? nextTerminator() : x);
}
@@ -441,26 +490,23 @@ public class ConcurrentLinkedDeque<E>
* Unlinks non-null first node.
*/
private void unlinkFirst(Node<E> first, Node<E> next) {
- assert first != null && next != null && first.item == null;
- Node<E> o = null, p = next;
- for (int hops = 0;; ++hops) {
- Node<E> q;
+ // assert first != null;
+ // assert next != null;
+ // assert first.item == null;
+ for (Node<E> o = null, p = next, q;;) {
if (p.item != null || (q = p.next) == null) {
- if (hops >= HOPS) {
- if (p == p.prev)
- return;
- if (first.casNext(next, p)) {
- skipDeletedPredecessors(p);
- if (//shouldGCUnlinkOccasionally() &&
- first.prev == null &&
- (p.next == null || p.item != null) &&
- p.prev == first) {
-
- updateHead();
- updateTail();
- o.lazySetNext(o);
- o.lazySetPrev(prevTerminator());
- }
+ if (o != null && p.prev != p && first.casNext(next, p)) {
+ skipDeletedPredecessors(p);
+ if (first.prev == null &&
+ (p.next == null || p.item != null) &&
+ p.prev == first) {
+
+ updateHead(); // Ensure o is not reachable from head
+ updateTail(); // Ensure o is not reachable from tail
+
+ // Finally, actually gc-unlink
+ o.lazySetNext(o);
+ o.lazySetPrev(prevTerminator());
}
}
return;
@@ -478,26 +524,23 @@ public class ConcurrentLinkedDeque<E>
* Unlinks non-null last node.
*/
private void unlinkLast(Node<E> last, Node<E> prev) {
- assert last != null && prev != null && last.item == null;
- Node<E> o = null, p = prev;
- for (int hops = 0;; ++hops) {
- Node<E> q;
+ // assert last != null;
+ // assert prev != null;
+ // assert last.item == null;
+ for (Node<E> o = null, p = prev, q;;) {
if (p.item != null || (q = p.prev) == null) {
- if (hops >= HOPS) {
- if (p == p.next)
- return;
- if (last.casPrev(prev, p)) {
- skipDeletedSuccessors(p);
- if (//shouldGCUnlinkOccasionally() &&
- last.next == null &&
- (p.prev == null || p.item != null) &&
- p.next == last) {
-
- updateHead();
- updateTail();
- o.lazySetPrev(o);
- o.lazySetNext(nextTerminator());
- }
+ if (o != null && p.next != p && last.casPrev(prev, p)) {
+ skipDeletedSuccessors(p);
+ if (last.next == null &&
+ (p.prev == null || p.item != null) &&
+ p.next == last) {
+
+ updateHead(); // Ensure o is not reachable from head
+ updateTail(); // Ensure o is not reachable from tail
+
+ // Finally, actually gc-unlink
+ o.lazySetPrev(o);
+ o.lazySetNext(nextTerminator());
}
}
return;
@@ -511,21 +554,73 @@ public class ConcurrentLinkedDeque<E>
}
}
+ /**
+ * Guarantees that any node which was unlinked before a call to
+ * this method will be unreachable from head after it returns.
+ * Does not guarantee to eliminate slack, only that head will
+ * point to a node that was active while this method was running.
+ */
private final void updateHead() {
- first();
+ // Either head already points to an active node, or we keep
+ // trying to cas it to the first node until it does.
+ Node<E> h, p, q;
+ restartFromHead:
+ while ((h = head).item == null && (p = h.prev) != null) {
+ for (;;) {
+ if ((q = p.prev) == null ||
+ (q = (p = q).prev) == null) {
+ // It is possible that p is PREV_TERMINATOR,
+ // but if so, the CAS is guaranteed to fail.
+ if (casHead(h, p))
+ return;
+ else
+ continue restartFromHead;
+ }
+ else if (h != head)
+ continue restartFromHead;
+ else
+ p = q;
+ }
+ }
}
+ /**
+ * Guarantees that any node which was unlinked before a call to
+ * this method will be unreachable from tail after it returns.
+ * Does not guarantee to eliminate slack, only that tail will
+ * point to a node that was active while this method was running.
+ */
private final void updateTail() {
- last();
+ // Either tail already points to an active node, or we keep
+ // trying to cas it to the last node until it does.
+ Node<E> t, p, q;
+ restartFromTail:
+ while ((t = tail).item == null && (p = t.next) != null) {
+ for (;;) {
+ if ((q = p.next) == null ||
+ (q = (p = q).next) == null) {
+ // It is possible that p is NEXT_TERMINATOR,
+ // but if so, the CAS is guaranteed to fail.
+ if (casTail(t, p))
+ return;
+ else
+ continue restartFromTail;
+ }
+ else if (t != tail)
+ continue restartFromTail;
+ else
+ p = q;
+ }
+ }
}
private void skipDeletedPredecessors(Node<E> x) {
whileActive:
do {
Node<E> prev = x.prev;
- assert prev != null;
- assert x != NEXT_TERMINATOR;
- assert x != PREV_TERMINATOR;
+ // assert prev != null;
+ // assert x != NEXT_TERMINATOR;
+ // assert x != PREV_TERMINATOR;
Node<E> p = prev;
findActive:
for (;;) {
@@ -554,9 +649,9 @@ public class ConcurrentLinkedDeque<E>
whileActive:
do {
Node<E> next = x.next;
- assert next != null;
- assert x != NEXT_TERMINATOR;
- assert x != PREV_TERMINATOR;
+ // assert next != null;
+ // assert x != NEXT_TERMINATOR;
+ // assert x != PREV_TERMINATOR;
Node<E> p = next;
findActive:
for (;;) {
@@ -603,57 +698,53 @@ public class ConcurrentLinkedDeque<E>
}
/**
- * Returns the first node, the unique node which has a null prev link.
+ * Returns the first node, the unique node p for which:
+ * p.prev == null && p.next != p
* The returned node may or may not be logically deleted.
* Guarantees that head is set to the returned node.
*/
Node<E> first() {
- retry:
- for (;;) {
- for (Node<E> h = head, p = h;;) {
- Node<E> q = p.prev;
- if (q == null) {
- if (p == h
- // It is possible that p is PREV_TERMINATOR,
- // but if so, the CAS will fail.
- || casHead(h, p))
- return p;
- else
- continue retry;
- } else if (p == q) {
- continue retry;
- } else {
- p = q;
- }
+ restartFromHead:
+ for (;;)
+ for (Node<E> h = head, p = h, q;;) {
+ if ((q = p.prev) != null &&
+ (q = (p = q).prev) != null)
+ // Check for head updates every other hop.
+ // If p == q, we are sure to follow head instead.
+ p = (h != (h = head)) ? h : q;
+ else if (p == h
+ // It is possible that p is PREV_TERMINATOR,
+ // but if so, the CAS is guaranteed to fail.
+ || casHead(h, p))
+ return p;
+ else
+ continue restartFromHead;
}
- }
}
/**
- * Returns the last node, the unique node which has a null next link.
+ * Returns the last node, the unique node p for which:
+ * p.next == null && p.prev != p
* The returned node may or may not be logically deleted.
* Guarantees that tail is set to the returned node.
*/
Node<E> last() {
- retry:
- for (;;) {
- for (Node<E> t = tail, p = t;;) {
- Node<E> q = p.next;
- if (q == null) {
- if (p == t
- // It is possible that p is NEXT_TERMINATOR,
- // but if so, the CAS will fail.
- || casTail(t, p))
- return p;
- else
- continue retry;
- } else if (p == q) {
- continue retry;
- } else {
- p = q;
- }
+ restartFromTail:
+ for (;;)
+ for (Node<E> t = tail, p = t, q;;) {
+ if ((q = p.next) != null &&
+ (q = (p = q).next) != null)
+ // Check for tail updates every other hop.
+ // If p == q, we are sure to follow tail instead.
+ p = (t != (t = tail)) ? t : q;
+ else if (p == t
+ // It is possible that p is NEXT_TERMINATOR,
+ // but if so, the CAS is guaranteed to fail.
+ || casTail(t, p))
+ return p;
+ else
+ continue restartFromTail;
}
- }
}
// Minor convenience utilities
@@ -688,23 +779,21 @@ public class ConcurrentLinkedDeque<E>
* @return the arrayList
*/
private ArrayList<E> toArrayList() {
- ArrayList<E> c = new ArrayList<E>();
+ ArrayList<E> list = new ArrayList<E>();
for (Node<E> p = first(); p != null; p = succ(p)) {
E item = p.item;
if (item != null)
- c.add(item);
+ list.add(item);
}
- return c;
+ return list;
}
- // Fields and constructors
-
- private static final long serialVersionUID = 876323262645176354L;
-
/**
* Constructs an empty deque.
*/
- public ConcurrentLinkedDeque() {}
+ public ConcurrentLinkedDeque() {
+ head = tail = new Node<E>(null);
+ }
/**
* Constructs a deque initially containing the elements of
@@ -715,15 +804,48 @@ public class ConcurrentLinkedDeque<E>
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
- public ConcurrentLinkedDeque(Collection<? extends E> c) {
- this();
- addAll(c);
- }
+ public ConcurrentLinkedDeque(Collection<? extends E> c) {
+ // Copy c into a private chain of Nodes
+ Node<E> h = null, t = null;
+ for (E e : c) {
+ checkNotNull(e);
+ Node<E> newNode = new Node<E>(e);
+ if (h == null)
+ h = t = newNode;
+ else {
+ t.lazySetNext(newNode);
+ newNode.lazySetPrev(t);
+ t = newNode;
+ }
+ }
+ initHeadTail(h, t);
+ }
+
+ /**
+ * Initializes head and tail, ensuring invariants hold.
+ */
+ private void initHeadTail(Node<E> h, Node<E> t) {
+ if (h == t) {
+ if (h == null)
+ h = t = new Node<E>(null);
+ else {
+ // Avoid edge case of a single Node with non-null item.
+ Node<E> newNode = new Node<E>(null);
+ t.lazySetNext(newNode);
+ newNode.lazySetPrev(t);
+ t = newNode;
+ }
+ }
+ head = h;
+ tail = t;
+ }
/**
* Inserts the specified element at the front of this deque.
+ * As the deque is unbounded, this method will never throw
+ * {@link IllegalStateException}.
*
- * @throws NullPointerException {@inheritDoc}
+ * @throws NullPointerException if the specified element is null
*/
public void addFirst(E e) {
linkFirst(e);
@@ -731,9 +853,12 @@ public class ConcurrentLinkedDeque<E>
/**
* Inserts the specified element at the end of this deque.
- * This is identical in function to the {@code add} method.
+ * As the deque is unbounded, this method will never throw
+ * {@link IllegalStateException}.
*
- * @throws NullPointerException {@inheritDoc}
+ * <p>This method is equivalent to {@link #add}.
+ *
+ * @throws NullPointerException if the specified element is null
*/
public void addLast(E e) {
linkLast(e);
@@ -741,9 +866,10 @@ public class ConcurrentLinkedDeque<E>
/**
* Inserts the specified element at the front of this deque.
+ * As the deque is unbounded, this method will never return {@code false}.
*
- * @return {@code true} always
- * @throws NullPointerException {@inheritDoc}
+ * @return {@code true} (as specified by {@link Deque#offerFirst})
+ * @throws NullPointerException if the specified element is null
*/
public boolean offerFirst(E e) {
linkFirst(e);
@@ -752,11 +878,12 @@ public class ConcurrentLinkedDeque<E>
/**
* Inserts the specified element at the end of this deque.
+ * As the deque is unbounded, this method will never return {@code false}.
*
* <p>This method is equivalent to {@link #add}.
*
- * @return {@code true} always
- * @throws NullPointerException {@inheritDoc}
+ * @return {@code true} (as specified by {@link Deque#offerLast})
+ * @throws NullPointerException if the specified element is null
*/
public boolean offerLast(E e) {
linkLast(e);
@@ -791,7 +918,7 @@ public class ConcurrentLinkedDeque<E>
/**
* @throws NoSuchElementException {@inheritDoc}
*/
- public E getLast() {
+ public E getLast() {
return screenNullResult(peekLast());
}
@@ -835,8 +962,9 @@ public class ConcurrentLinkedDeque<E>
/**
* Inserts the specified element at the tail of this deque.
+ * As the deque is unbounded, this method will never return {@code false}.
*
- * @return {@code true} (as specified by {@link java.util.Queue#offer})
+ * @return {@code true} (as specified by {@link Queue#offer})
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
@@ -845,6 +973,8 @@ public class ConcurrentLinkedDeque<E>
/**
* Inserts the specified element at the tail of this deque.
+ * As the deque is unbounded, this method will never throw
+ * {@link IllegalStateException} or return {@code false}.
*
* @return {@code true} (as specified by {@link Collection#add})
* @throws NullPointerException if the specified element is null
@@ -867,7 +997,7 @@ public class ConcurrentLinkedDeque<E>
*
* @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element
- * @throws NullPointerException if the specified element is {@code null}
+ * @throws NullPointerException if the specified element is null
*/
public boolean removeFirstOccurrence(Object o) {
checkNotNull(o);
@@ -888,7 +1018,7 @@ public class ConcurrentLinkedDeque<E>
*
* @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element
- * @throws NullPointerException if the specified element is {@code null}
+ * @throws NullPointerException if the specified element is null
*/
public boolean removeLastOccurrence(Object o) {
checkNotNull(o);
@@ -945,11 +1075,13 @@ public class ConcurrentLinkedDeque<E>
* @return the number of elements in this deque
*/
public int size() {
- long count = 0;
+ int count = 0;
for (Node<E> p = first(); p != null; p = succ(p))
if (p.item != null)
- ++count;
- return (count >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) count;
+ // Collection.size() spec says to max out
+ if (++count == Integer.MAX_VALUE)
+ break;
+ return count;
}
/**
@@ -959,7 +1091,7 @@ public class ConcurrentLinkedDeque<E>
*
* @param o element to be removed from this deque, if present
* @return {@code true} if the deque contained the specified element
- * @throws NullPointerException if the specified element is {@code null}
+ * @throws NullPointerException if the specified element is null
*/
public boolean remove(Object o) {
return removeFirstOccurrence(o);
@@ -968,24 +1100,65 @@ public class ConcurrentLinkedDeque<E>
/**
* Appends all of the elements in the specified collection to the end of
* this deque, in the order that they are returned by the specified
- * collection's iterator. The behavior of this operation is undefined if
- * the specified collection is modified while the operation is in
- * progress. (This implies that the behavior of this call is undefined if
- * the specified Collection is this deque, and this deque is nonempty.)
+ * collection's iterator. Attempts to {@code addAll} of a deque to
+ * itself result in {@code IllegalArgumentException}.
*
* @param c the elements to be inserted into this deque
* @return {@code true} if this deque changed as a result of the call
- * @throws NullPointerException if {@code c} or any element within it
- * is {@code null}
+ * @throws NullPointerException if the specified collection or any
+ * of its elements are null
+ * @throws IllegalArgumentException if the collection is this deque
*/
public boolean addAll(Collection<? extends E> c) {
- Iterator<? extends E> it = c.iterator();
- if (!it.hasNext())
+ if (c == this)
+ // As historically specified in AbstractQueue#addAll
+ throw new IllegalArgumentException();
+
+ // Copy c into a private chain of Nodes
+ Node<E> beginningOfTheEnd = null, last = null;
+ for (E e : c) {
+ checkNotNull(e);
+ Node<E> newNode = new Node<E>(e);
+ if (beginningOfTheEnd == null)
+ beginningOfTheEnd = last = newNode;
+ else {
+ last.lazySetNext(newNode);
+ newNode.lazySetPrev(last);
+ last = newNode;
+ }
+ }
+ if (beginningOfTheEnd == null)
return false;
- do {
- addLast(it.next());
- } while (it.hasNext());
- return true;
+
+ // Atomically append the chain at the tail of this collection
+ restartFromTail:
+ for (;;)
+ for (Node<E> t = tail, p = t, q;;) {
+ if ((q = p.next) != null &&
+ (q = (p = q).next) != null)
+ // Check for tail updates every other hop.
+ // If p == q, we are sure to follow tail instead.
+ p = (t != (t = tail)) ? t : q;
+ else if (p.prev == p) // NEXT_TERMINATOR
+ continue restartFromTail;
+ else {
+ // p is last node
+ beginningOfTheEnd.lazySetPrev(p); // CAS piggyback
+ if (p.casNext(null, beginningOfTheEnd)) {
+ // Successful CAS is the linearization point
+ // for all elements to be added to this deque.
+ if (!casTail(t, last)) {
+ // Try a little harder to update tail,
+ // since we may be adding many elements.
+ t = tail;
+ if (last.next == null)
+ casTail(t, last);
+ }
+ return true;
+ }
+ // Lost CAS race to another thread; re-read next
+ }
+ }
}
/**
@@ -1026,10 +1199,11 @@ public class ConcurrentLinkedDeque<E>
* the array immediately following the end of the deque is set to
* {@code null}.
*
- * <p>Like the {@link #toArray()} method, this method acts as bridge between
- * array-based and collection-based APIs. Further, this method allows
- * precise control over the runtime type of the output array, and may,
- * under certain circumstances, be used to save allocation costs.
+ * <p>Like the {@link #toArray()} method, this method acts as
+ * bridge between array-based and collection-based APIs. Further,
+ * this method allows precise control over the runtime type of the
+ * output array, and may, under certain circumstances, be used to
+ * save allocation costs.
*
* <p>Suppose {@code x} is a deque known to contain only strings.
* The following code can be used to dump the deque into a newly
@@ -1058,12 +1232,12 @@ public class ConcurrentLinkedDeque<E>
* Returns an iterator over the elements in this deque in proper sequence.
* The elements will be returned in order from first (head) to last (tail).
*
- * <p>The returned {@code Iterator} is a "weakly consistent" iterator that
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
*
* @return an iterator over the elements in this deque in proper sequence
*/
@@ -1076,12 +1250,14 @@ public class ConcurrentLinkedDeque<E>
* sequential order. The elements will be returned in order from
* last (tail) to first (head).
*
- * <p>The returned {@code Iterator} is a "weakly consistent" iterator that
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
+ *
+ * @return an iterator over the elements in this deque in reverse order
*/
public Iterator<E> descendingIterator() {
return new DescendingItr();
@@ -1171,7 +1347,7 @@ public class ConcurrentLinkedDeque<E>
}
/**
- * Save the state to a stream (that is, serialize it).
+ * Saves the state to a stream (that is, serializes it).
*
* @serialData All of the elements (each an {@code E}) in
* the proper order, followed by a null
@@ -1185,7 +1361,7 @@ public class ConcurrentLinkedDeque<E>
// Write out all elements in the proper order.
for (Node<E> p = first(); p != null; p = succ(p)) {
- Object item = p.item;
+ E item = p.item;
if (item != null)
s.writeObject(item);
}
@@ -1195,24 +1371,28 @@ public class ConcurrentLinkedDeque<E>
}
/**
- * Reconstitute the Queue instance from a stream (that is,
- * deserialize it).
+ * Reconstitutes the instance from a stream (that is, deserializes it).
* @param s the stream
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
- // Read in capacity, and any hidden stuff
s.defaultReadObject();
- tail = head = new Node<E>(null);
- // Read in all elements and place in queue
- for (;;) {
+
+ // Read in elements until trailing null sentinel found
+ Node<E> h = null, t = null;
+ Object item;
+ while ((item = s.readObject()) != null) {
@SuppressWarnings("unchecked")
- E item = (E)s.readObject();
- if (item == null)
- break;
- else
- offer(item);
+ Node<E> newNode = new Node<E>((E) item);
+ if (h == null)
+ h = t = newNode;
+ else {
+ t.lazySetNext(newNode);
+ newNode.lazySetPrev(t);
+ t = newNode;
+ }
}
+ initHeadTail(h, t);
}
// Unsafe mechanics
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentLinkedQueue.java b/luni/src/main/java/java/util/concurrent/ConcurrentLinkedQueue.java
index 2d222c1..3ed0a7c 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentLinkedQueue.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentLinkedQueue.java
@@ -1,7 +1,7 @@
/*
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group and released to the public domain, as explained at
- * http://creativecommons.org/licenses/publicdomain
+ * Written by Doug Lea and Martin Buchholz with assistance from members of
+ * JCP JSR-166 Expert Group and released to the public domain, as explained
+ * at http://creativecommons.org/licenses/publicdomain
*/
package java.util.concurrent;
@@ -28,7 +28,8 @@ import java.util.Queue;
* operations obtain elements at the head of the queue.
* A {@code ConcurrentLinkedQueue} is an appropriate choice when
* many threads will share access to a common collection.
- * This queue does not permit {@code null} elements.
+ * Like most other concurrent collection implementations, this class
+ * does not permit the use of {@code null} elements.
*
* <p>This implementation employs an efficient &quot;wait-free&quot;
* algorithm based on one described in <a
@@ -36,14 +37,20 @@ import java.util.Queue;
* Fast, and Practical Non-Blocking and Blocking Concurrent Queue
* Algorithms</a> by Maged M. Michael and Michael L. Scott.
*
+ * <p>Iterators are <i>weakly consistent</i>, returning elements
+ * reflecting the state of the queue at some point at or since the
+ * creation of the iterator. They do <em>not</em> throw {@link
+ * java.util.ConcurrentModificationException}, and may proceed concurrently
+ * with other operations. Elements contained in the queue since the creation
+ * of the iterator will be returned exactly once.
+ *
* <p>Beware that, unlike in most collections, the {@code size} method
* is <em>NOT</em> a constant-time operation. Because of the
* asynchronous nature of these queues, determining the current number
* of elements requires a traversal of the elements.
*
- * <p>This class and its iterator implement all of the
- * <em>optional</em> methods of the {@link Collection} and {@link
- * Iterator} interfaces.
+ * <p>This class and its iterator implement all of the <em>optional</em>
+ * methods of the {@link Queue} and {@link Iterator} interfaces.
*
* <p>Memory consistency effects: As with other concurrent
* collections, actions in a thread prior to placing an object into a
@@ -103,9 +110,10 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
*
* Both head and tail are permitted to lag. In fact, failing to
* update them every time one could is a significant optimization
- * (fewer CASes). This is controlled by local "hops" variables
- * that only trigger helping-CASes after experiencing multiple
- * lags.
+ * (fewer CASes). As with LinkedTransferQueue (see the internal
+ * documentation for that class), we use a slack threshold of two;
+ * that is, we update head/tail when the current pointer appears
+ * to be two or more steps away from the first/last node.
*
* Since head and tail are updated concurrently and independently,
* it is possible for tail to lag behind head (why not)?
@@ -119,8 +127,8 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* this is merely an optimization.
*
* When constructing a Node (before enqueuing it) we avoid paying
- * for a volatile write to item by using lazySet instead of a
- * normal write. This allows the cost of enqueue to be
+ * for a volatile write to item by using Unsafe.putObject instead
+ * of a normal write. This allows the cost of enqueue to be
* "one-and-a-half" CASes.
*
* Both head and tail may or may not point to a Node with a
@@ -132,38 +140,25 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
*/
private static class Node<E> {
- private volatile E item;
- private volatile Node<E> next;
+ volatile E item;
+ volatile Node<E> next;
+ /**
+ * Constructs a new node. Uses relaxed write because item can
+ * only be seen after publication via casNext.
+ */
Node(E item) {
- // Piggyback on imminent casNext()
- lazySetItem(item);
- }
-
- E getItem() {
- return item;
+ UNSAFE.putObject(this, itemOffset, item);
}
boolean casItem(E cmp, E val) {
return UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val);
}
- void setItem(E val) {
- item = val;
- }
-
- void lazySetItem(E val) {
- UNSAFE.putOrderedObject(this, itemOffset, val);
- }
-
void lazySetNext(Node<E> val) {
UNSAFE.putOrderedObject(this, nextOffset, val);
}
- Node<E> getNext() {
- return next;
- }
-
boolean casNext(Node<E> cmp, Node<E> val) {
return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
}
@@ -190,7 +185,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* - it is permitted for tail to lag behind head, that is, for tail
* to not be reachable from head!
*/
- private transient volatile Node<E> head = new Node<E>(null);
+ private transient volatile Node<E> head;
/**
* A node from which the last node on list (that is, the unique
@@ -204,31 +199,49 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* to not be reachable from head!
* - tail.next may or may not be self-pointing to tail.
*/
- private transient volatile Node<E> tail = head;
+ private transient volatile Node<E> tail;
/**
* Creates a {@code ConcurrentLinkedQueue} that is initially empty.
*/
- public ConcurrentLinkedQueue() {}
+ public ConcurrentLinkedQueue() {
+ head = tail = new Node<E>(null);
+ }
/**
* Creates a {@code ConcurrentLinkedQueue}
* initially containing the elements of the given collection,
* added in traversal order of the collection's iterator.
+ *
* @param c the collection of elements to initially contain
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
public ConcurrentLinkedQueue(Collection<? extends E> c) {
- for (E e : c)
- add(e);
+ Node<E> h = null, t = null;
+ for (E e : c) {
+ checkNotNull(e);
+ Node<E> newNode = new Node<E>(e);
+ if (h == null)
+ h = t = newNode;
+ else {
+ t.lazySetNext(newNode);
+ t = newNode;
+ }
+ }
+ if (h == null)
+ h = t = new Node<E>(null);
+ head = h;
+ tail = t;
}
// Have to override just to update the javadoc
/**
* Inserts the specified element at the tail of this queue.
+ * As the queue is unbounded, this method will never throw
+ * {@link IllegalStateException} or return {@code false}.
*
* @return {@code true} (as specified by {@link Collection#add})
* @throws NullPointerException if the specified element is null
@@ -238,13 +251,6 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
}
/**
- * We don't bother to update head or tail pointers if fewer than
- * HOPS links from "true" location. We assume that volatile
- * writes are significantly more expensive than volatile reads.
- */
- private static final int HOPS = 1;
-
- /**
* Try to CAS head to p. If successful, repoint old head to itself
* as sentinel for succ(), below.
*/
@@ -259,79 +265,87 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* stale pointer that is now off the list.
*/
final Node<E> succ(Node<E> p) {
- Node<E> next = p.getNext();
+ Node<E> next = p.next;
return (p == next) ? head : next;
}
/**
* Inserts the specified element at the tail of this queue.
+ * As the queue is unbounded, this method will never return {@code false}.
*
* @return {@code true} (as specified by {@link Queue#offer})
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
- if (e == null) throw new NullPointerException();
- Node<E> n = new Node<E>(e);
- retry:
- for (;;) {
- Node<E> t = tail;
- Node<E> p = t;
- for (int hops = 0; ; hops++) {
- Node<E> next = succ(p);
- if (next != null) {
- if (hops > HOPS && t != tail)
- continue retry;
- p = next;
- } else if (p.casNext(null, n)) {
- if (hops >= HOPS)
- casTail(t, n); // Failure is OK.
+ checkNotNull(e);
+ final Node<E> newNode = new Node<E>(e);
+
+ for (Node<E> t = tail, p = t;;) {
+ Node<E> q = p.next;
+ if (q == null) {
+ // p is last node
+ if (p.casNext(null, newNode)) {
+ // Successful CAS is the linearization point
+ // for e to become an element of this queue,
+ // and for newNode to become "live".
+ if (p != t) // hop two nodes at a time
+ casTail(t, newNode); // Failure is OK.
return true;
- } else {
- p = succ(p);
}
+ // Lost CAS race to another thread; re-read next
}
+ else if (p == q)
+ // We have fallen off list. If tail is unchanged, it
+ // will also be off-list, in which case we need to
+ // jump to head, from which all live nodes are always
+ // reachable. Else the new tail is a better bet.
+ p = (t != (t = tail)) ? t : head;
+ else
+ // Check for tail updates after two hops.
+ p = (p != t && t != (t = tail)) ? t : q;
}
}
public E poll() {
- Node<E> h = head;
- Node<E> p = h;
- for (int hops = 0; ; hops++) {
- E item = p.getItem();
-
- if (item != null && p.casItem(item, null)) {
- if (hops >= HOPS) {
- Node<E> q = p.getNext();
- updateHead(h, (q != null) ? q : p);
+ restartFromHead:
+ for (;;) {
+ for (Node<E> h = head, p = h, q;;) {
+ E item = p.item;
+
+ if (item != null && p.casItem(item, null)) {
+ // Successful CAS is the linearization point
+ // for item to be removed from this queue.
+ if (p != h) // hop two nodes at a time
+ updateHead(h, ((q = p.next) != null) ? q : p);
+ return item;
}
- return item;
- }
- Node<E> next = succ(p);
- if (next == null) {
- updateHead(h, p);
- break;
+ else if ((q = p.next) == null) {
+ updateHead(h, p);
+ return null;
+ }
+ else if (p == q)
+ continue restartFromHead;
+ else
+ p = q;
}
- p = next;
}
- return null;
}
public E peek() {
- Node<E> h = head;
- Node<E> p = h;
- E item;
+ restartFromHead:
for (;;) {
- item = p.getItem();
- if (item != null)
- break;
- Node<E> next = succ(p);
- if (next == null) {
- break;
+ for (Node<E> h = head, p = h, q;;) {
+ E item = p.item;
+ if (item != null || (q = p.next) == null) {
+ updateHead(h, p);
+ return item;
+ }
+ else if (p == q)
+ continue restartFromHead;
+ else
+ p = q;
}
- p = next;
}
- updateHead(h, p);
- return item;
}
/**
@@ -343,24 +357,20 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* of losing a race to a concurrent poll().
*/
Node<E> first() {
- Node<E> h = head;
- Node<E> p = h;
- Node<E> result;
+ restartFromHead:
for (;;) {
- E item = p.getItem();
- if (item != null) {
- result = p;
- break;
- }
- Node<E> next = succ(p);
- if (next == null) {
- result = null;
- break;
+ for (Node<E> h = head, p = h, q;;) {
+ boolean hasItem = (p.item != null);
+ if (hasItem || (q = p.next) == null) {
+ updateHead(h, p);
+ return hasItem ? p : null;
+ }
+ else if (p == q)
+ continue restartFromHead;
+ else
+ p = q;
}
- p = next;
}
- updateHead(h, p);
- return result;
}
/**
@@ -381,18 +391,20 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
* <em>NOT</em> a constant-time operation. Because of the
* asynchronous nature of these queues, determining the current
* number of elements requires an O(n) traversal.
+ * Additionally, if elements are added or removed during execution
+ * of this method, the returned result may be inaccurate. Thus,
+ * this method is typically not very useful in concurrent
+ * applications.
*
* @return the number of elements in this queue
*/
public int size() {
int count = 0;
- for (Node<E> p = first(); p != null; p = succ(p)) {
- if (p.getItem() != null) {
- // Collections.size() spec says to max out
+ for (Node<E> p = first(); p != null; p = succ(p))
+ if (p.item != null)
+ // Collection.size() spec says to max out
if (++count == Integer.MAX_VALUE)
break;
- }
- }
return count;
}
@@ -407,9 +419,8 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
public boolean contains(Object o) {
if (o == null) return false;
for (Node<E> p = first(); p != null; p = succ(p)) {
- E item = p.getItem();
- if (item != null &&
- o.equals(item))
+ E item = p.item;
+ if (item != null && o.equals(item))
return true;
}
return false;
@@ -430,7 +441,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
if (o == null) return false;
Node<E> pred = null;
for (Node<E> p = first(); p != null; p = succ(p)) {
- E item = p.getItem();
+ E item = p.item;
if (item != null &&
o.equals(item) &&
p.casItem(item, null)) {
@@ -445,6 +456,69 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
}
/**
+ * Appends all of the elements in the specified collection to the end of
+ * this queue, in the order that they are returned by the specified
+ * collection's iterator. Attempts to {@code addAll} of a queue to
+ * itself result in {@code IllegalArgumentException}.
+ *
+ * @param c the elements to be inserted into this queue
+ * @return {@code true} if this queue changed as a result of the call
+ * @throws NullPointerException if the specified collection or any
+ * of its elements are null
+ * @throws IllegalArgumentException if the collection is this queue
+ */
+ public boolean addAll(Collection<? extends E> c) {
+ if (c == this)
+ // As historically specified in AbstractQueue#addAll
+ throw new IllegalArgumentException();
+
+ // Copy c into a private chain of Nodes
+ Node<E> beginningOfTheEnd = null, last = null;
+ for (E e : c) {
+ checkNotNull(e);
+ Node<E> newNode = new Node<E>(e);
+ if (beginningOfTheEnd == null)
+ beginningOfTheEnd = last = newNode;
+ else {
+ last.lazySetNext(newNode);
+ last = newNode;
+ }
+ }
+ if (beginningOfTheEnd == null)
+ return false;
+
+ // Atomically append the chain at the tail of this collection
+ for (Node<E> t = tail, p = t;;) {
+ Node<E> q = p.next;
+ if (q == null) {
+ // p is last node
+ if (p.casNext(null, beginningOfTheEnd)) {
+ // Successful CAS is the linearization point
+ // for all elements to be added to this queue.
+ if (!casTail(t, last)) {
+ // Try a little harder to update tail,
+ // since we may be adding many elements.
+ t = tail;
+ if (last.next == null)
+ casTail(t, last);
+ }
+ return true;
+ }
+ // Lost CAS race to another thread; re-read next
+ }
+ else if (p == q)
+ // We have fallen off list. If tail is unchanged, it
+ // will also be off-list, in which case we need to
+ // jump to head, from which all live nodes are always
+ // reachable. Else the new tail is a better bet.
+ p = (t != (t = tail)) ? t : head;
+ else
+ // Check for tail updates after two hops.
+ p = (p != t && t != (t = tail)) ? t : q;
+ }
+ }
+
+ /**
* Returns an array containing all of the elements in this queue, in
* proper sequence.
*
@@ -461,7 +535,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
// Use ArrayList to deal with resizing.
ArrayList<E> al = new ArrayList<E>();
for (Node<E> p = first(); p != null; p = succ(p)) {
- E item = p.getItem();
+ E item = p.item;
if (item != null)
al.add(item);
}
@@ -510,7 +584,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
int k = 0;
Node<E> p;
for (p = first(); p != null && k < a.length; p = succ(p)) {
- E item = p.getItem();
+ E item = p.item;
if (item != null)
a[k++] = (T)item;
}
@@ -523,7 +597,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
// If won't fit, use ArrayList version
ArrayList<E> al = new ArrayList<E>();
for (Node<E> q = first(); q != null; q = succ(q)) {
- E item = q.getItem();
+ E item = q.item;
if (item != null)
al.add(item);
}
@@ -532,12 +606,14 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
/**
* Returns an iterator over the elements in this queue in proper sequence.
- * The returned iterator is a "weakly consistent" iterator that
+ * The elements will be returned in order from first (head) to last (tail).
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
*
* @return an iterator over the elements in this queue in proper sequence
*/
@@ -591,7 +667,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
nextItem = null;
return x;
}
- E item = p.getItem();
+ E item = p.item;
if (item != null) {
nextNode = p;
nextItem = item;
@@ -619,13 +695,13 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
Node<E> l = lastRet;
if (l == null) throw new IllegalStateException();
// rely on a future traversal to relink.
- l.setItem(null);
+ l.item = null;
lastRet = null;
}
}
/**
- * Save the state to a stream (that is, serialize it).
+ * Saves the state to a stream (that is, serializes it).
*
* @serialData All of the elements (each an {@code E}) in
* the proper order, followed by a null
@@ -639,7 +715,7 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
// Write out all elements in the proper order.
for (Node<E> p = first(); p != null; p = succ(p)) {
- Object item = p.getItem();
+ Object item = p.item;
if (item != null)
s.writeObject(item);
}
@@ -649,25 +725,40 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
}
/**
- * Reconstitute the Queue instance from a stream (that is,
- * deserialize it).
+ * Reconstitutes the instance from a stream (that is, deserializes it).
* @param s the stream
*/
private void readObject(java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
- // Read in capacity, and any hidden stuff
s.defaultReadObject();
- head = new Node<E>(null);
- tail = head;
- // Read in all elements and place in queue
- for (;;) {
+
+ // Read in elements until trailing null sentinel found
+ Node<E> h = null, t = null;
+ Object item;
+ while ((item = s.readObject()) != null) {
@SuppressWarnings("unchecked")
- E item = (E)s.readObject();
- if (item == null)
- break;
- else
- offer(item);
+ Node<E> newNode = new Node<E>((E) item);
+ if (h == null)
+ h = t = newNode;
+ else {
+ t.lazySetNext(newNode);
+ t = newNode;
+ }
}
+ if (h == null)
+ h = t = new Node<E>(null);
+ head = h;
+ tail = t;
+ }
+
+ /**
+ * Throws NullPointerException if argument is null.
+ *
+ * @param v the element
+ */
+ private static void checkNotNull(Object v) {
+ if (v == null)
+ throw new NullPointerException();
}
// Unsafe mechanics
@@ -686,10 +777,6 @@ public class ConcurrentLinkedQueue<E> extends AbstractQueue<E>
return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
}
- private void lazySetHead(Node<E> val) {
- UNSAFE.putOrderedObject(this, headOffset, val);
- }
-
static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
String field, Class<?> klazz) {
try {
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentNavigableMap.java b/luni/src/main/java/java/util/concurrent/ConcurrentNavigableMap.java
index 727f2a6..7d86afb 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentNavigableMap.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentNavigableMap.java
@@ -5,12 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import java.util.NavigableMap;
-import java.util.NavigableSet;
+import java.util.*;
/**
* A {@link ConcurrentMap} supporting {@link NavigableMap} operations,
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentSkipListMap.java b/luni/src/main/java/java/util/concurrent/ConcurrentSkipListMap.java
index 19ca588..fbd1083 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentSkipListMap.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentSkipListMap.java
@@ -5,24 +5,8 @@
*/
package java.util.concurrent;
-
-import java.util.AbstractCollection;
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.NoSuchElementException;
-import java.util.Random;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import java.util.*;
+import java.util.concurrent.atomic.*;
/**
* A scalable concurrent {@link ConcurrentNavigableMap} implementation.
@@ -361,17 +345,11 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
null, null, 1);
}
- /** Updater for casHead */
- private static final
- AtomicReferenceFieldUpdater<ConcurrentSkipListMap, HeadIndex>
- headUpdater = AtomicReferenceFieldUpdater.newUpdater
- (ConcurrentSkipListMap.class, HeadIndex.class, "head");
-
/**
* compareAndSet head node
*/
private boolean casHead(HeadIndex<K,V> cmp, HeadIndex<K,V> val) {
- return headUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapObject(this, headOffset, cmp, val);
}
/* ---------------- Nodes -------------- */
@@ -410,28 +388,18 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
this.next = next;
}
- /** Updater for casNext */
- static final AtomicReferenceFieldUpdater<Node, Node>
- nextUpdater = AtomicReferenceFieldUpdater.newUpdater
- (Node.class, Node.class, "next");
-
- /** Updater for casValue */
- static final AtomicReferenceFieldUpdater<Node, Object>
- valueUpdater = AtomicReferenceFieldUpdater.newUpdater
- (Node.class, Object.class, "value");
-
/**
* compareAndSet value field
*/
boolean casValue(Object cmp, Object val) {
- return valueUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapObject(this, valueOffset, cmp, val);
}
/**
* compareAndSet next field
*/
boolean casNext(Node<K,V> cmp, Node<K,V> val) {
- return nextUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
}
/**
@@ -509,6 +477,14 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
return null;
return new AbstractMap.SimpleImmutableEntry<K,V>(key, v);
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long valueOffset =
+ objectFieldOffset(UNSAFE, "value", Node.class);
+ private static final long nextOffset =
+ objectFieldOffset(UNSAFE, "next", Node.class);
+
}
/* ---------------- Indexing -------------- */
@@ -534,16 +510,11 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
this.right = right;
}
- /** Updater for casRight */
- static final AtomicReferenceFieldUpdater<Index, Index>
- rightUpdater = AtomicReferenceFieldUpdater.newUpdater
- (Index.class, Index.class, "right");
-
/**
* compareAndSet right field
*/
final boolean casRight(Index<K,V> cmp, Index<K,V> val) {
- return rightUpdater.compareAndSet(this, cmp, val);
+ return UNSAFE.compareAndSwapObject(this, rightOffset, cmp, val);
}
/**
@@ -578,6 +549,12 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
final boolean unlink(Index<K,V> succ) {
return !indexesDeletedNode() && casRight(succ, succ.right);
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long rightOffset =
+ objectFieldOffset(UNSAFE, "right", Index.class);
+
}
/* ---------------- Head nodes -------------- */
@@ -627,7 +604,8 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
* cast key as Comparable, which may cause ClassCastException,
* which is propagated back to caller.
*/
- private Comparable<? super K> comparable(Object key) throws ClassCastException {
+ private Comparable<? super K> comparable(Object key)
+ throws ClassCastException {
if (key == null)
throw new NullPointerException();
if (comparator != null)
@@ -786,68 +764,12 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
}
/**
- * Specialized variant of findNode to perform Map.get. Does a weak
- * traversal, not bothering to fix any deleted index nodes,
- * returning early if it happens to see key in index, and passing
- * over any deleted base nodes, falling back to getUsingFindNode
- * only if it would otherwise return value from an ongoing
- * deletion. Also uses "bound" to eliminate need for some
- * comparisons (see Pugh Cookbook). Also folds uses of null checks
- * and node-skipping because markers have null keys.
+ * Gets value for key using findNode.
* @param okey the key
* @return the value, or null if absent
*/
private V doGet(Object okey) {
Comparable<? super K> key = comparable(okey);
- Node<K,V> bound = null;
- Index<K,V> q = head;
- Index<K,V> r = q.right;
- Node<K,V> n;
- K k;
- int c;
- for (;;) {
- Index<K,V> d;
- // Traverse rights
- if (r != null && (n = r.node) != bound && (k = n.key) != null) {
- if ((c = key.compareTo(k)) > 0) {
- q = r;
- r = r.right;
- continue;
- } else if (c == 0) {
- Object v = n.value;
- return (v != null)? (V)v : getUsingFindNode(key);
- } else
- bound = n;
- }
-
- // Traverse down
- if ((d = q.down) != null) {
- q = d;
- r = d.right;
- } else
- break;
- }
-
- // Traverse nexts
- for (n = q.node.next; n != null; n = n.next) {
- if ((k = n.key) != null) {
- if ((c = key.compareTo(k)) == 0) {
- Object v = n.value;
- return (v != null)? (V)v : getUsingFindNode(key);
- } else if (c < 0)
- break;
- }
- }
- return null;
- }
-
- /**
- * Performs map.get via findNode. Used as a backup if doGet
- * encounters an in-progress deletion.
- * @param key the key
- * @return the value, or null if absent
- */
- private V getUsingFindNode(Comparable<? super K> key) {
/*
* Loop needed here and elsewhere in case value field goes
* null just as it is about to be returned, in which case we
@@ -930,7 +852,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
x ^= x << 13;
x ^= x >>> 17;
randomSeed = x ^= x << 5;
- if ((x & 0x8001) != 0) // test highest and lowest bits
+ if ((x & 0x80000001) != 0) // test highest and lowest bits
return 0;
int level = 1;
while (((x >>>= 1) & 1) != 0) ++level;
@@ -1243,7 +1165,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
Node<K,V> n = b.next;
for (;;) {
if (n == null)
- return (b.isBaseHeader())? null : b;
+ return b.isBaseHeader() ? null : b;
Node<K,V> f = n.next; // inconsistent read
if (n != b.next)
break;
@@ -1361,7 +1283,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
Node<K,V> n = b.next;
for (;;) {
if (n == null)
- return ((rel & LT) == 0 || b.isBaseHeader())? null : b;
+ return ((rel & LT) == 0 || b.isBaseHeader()) ? null : b;
Node<K,V> f = n.next;
if (n != b.next) // inconsistent read
break;
@@ -1377,7 +1299,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
(c < 0 && (rel & LT) == 0))
return n;
if ( c <= 0 && (rel & LT) != 0)
- return (b.isBaseHeader())? null : b;
+ return b.isBaseHeader() ? null : b;
b = n;
n = f;
}
@@ -1731,7 +1653,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
if (n.getValidValue() != null)
++count;
}
- return (count >= Integer.MAX_VALUE)? Integer.MAX_VALUE : (int)count;
+ return (count >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) count;
}
/**
@@ -2086,7 +2008,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
*/
public K lowerKey(K key) {
Node<K,V> n = findNear(key, LT);
- return (n == null)? null : n.key;
+ return (n == null) ? null : n.key;
}
/**
@@ -2110,7 +2032,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
*/
public K floorKey(K key) {
Node<K,V> n = findNear(key, LT|EQ);
- return (n == null)? null : n.key;
+ return (n == null) ? null : n.key;
}
/**
@@ -2132,7 +2054,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
*/
public K ceilingKey(K key) {
Node<K,V> n = findNear(key, GT|EQ);
- return (n == null)? null : n.key;
+ return (n == null) ? null : n.key;
}
/**
@@ -2156,7 +2078,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
*/
public K higherKey(K key) {
Node<K,V> n = findNear(key, GT);
- return (n == null)? null : n.key;
+ return (n == null) ? null : n.key;
}
/**
@@ -2329,7 +2251,8 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
return list;
}
- static final class KeySet<E> extends AbstractSet<E> implements NavigableSet<E> {
+ static final class KeySet<E>
+ extends AbstractSet<E> implements NavigableSet<E> {
private final ConcurrentNavigableMap<E,Object> m;
KeySet(ConcurrentNavigableMap<E,Object> map) { m = map; }
public int size() { return m.size(); }
@@ -2346,11 +2269,11 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
public E last() { return m.lastKey(); }
public E pollFirst() {
Map.Entry<E,Object> e = m.pollFirstEntry();
- return e == null? null : e.getKey();
+ return (e == null) ? null : e.getKey();
}
public E pollLast() {
Map.Entry<E,Object> e = m.pollLastEntry();
- return e == null? null : e.getKey();
+ return (e == null) ? null : e.getKey();
}
public Iterator<E> iterator() {
if (m instanceof ConcurrentSkipListMap)
@@ -2697,9 +2620,9 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
rel &= ~m.LT;
}
if (tooLow(key))
- return ((rel & m.LT) != 0)? null : lowestEntry();
+ return ((rel & m.LT) != 0) ? null : lowestEntry();
if (tooHigh(key))
- return ((rel & m.LT) != 0)? highestEntry() : null;
+ return ((rel & m.LT) != 0) ? highestEntry() : null;
for (;;) {
Node<K,V> n = m.findNear(key, rel);
if (n == null || !inBounds(n.key))
@@ -2770,7 +2693,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
public V remove(Object key) {
K k = (K)key;
- return (!inBounds(k))? null : m.remove(k);
+ return (!inBounds(k)) ? null : m.remove(k);
}
public int size() {
@@ -2781,7 +2704,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
if (n.getValidValue() != null)
++count;
}
- return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count;
+ return count >= Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)count;
}
public boolean isEmpty() {
@@ -2959,27 +2882,27 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
}
public K firstKey() {
- return isDescending? highestKey() : lowestKey();
+ return isDescending ? highestKey() : lowestKey();
}
public K lastKey() {
- return isDescending? lowestKey() : highestKey();
+ return isDescending ? lowestKey() : highestKey();
}
public Map.Entry<K,V> firstEntry() {
- return isDescending? highestEntry() : lowestEntry();
+ return isDescending ? highestEntry() : lowestEntry();
}
public Map.Entry<K,V> lastEntry() {
- return isDescending? lowestEntry() : highestEntry();
+ return isDescending ? lowestEntry() : highestEntry();
}
public Map.Entry<K,V> pollFirstEntry() {
- return isDescending? removeHighest() : removeLowest();
+ return isDescending ? removeHighest() : removeLowest();
}
public Map.Entry<K,V> pollLastEntry() {
- return isDescending? removeLowest() : removeHighest();
+ return isDescending ? removeLowest() : removeHighest();
}
/* ---------------- Submap Views -------------- */
@@ -3128,4 +3051,22 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
}
}
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long headOffset =
+ objectFieldOffset(UNSAFE, "head", ConcurrentSkipListMap.class);
+
+ static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
+ String field, Class<?> klazz) {
+ try {
+ return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
+ } catch (NoSuchFieldException e) {
+ // Convert Exception to corresponding Error
+ NoSuchFieldError error = new NoSuchFieldError(field);
+ error.initCause(e);
+ throw error;
+ }
+ }
+
}
diff --git a/luni/src/main/java/java/util/concurrent/ConcurrentSkipListSet.java b/luni/src/main/java/java/util/concurrent/ConcurrentSkipListSet.java
index f91e6e8..d24876f 100644
--- a/luni/src/main/java/java/util/concurrent/ConcurrentSkipListSet.java
+++ b/luni/src/main/java/java/util/concurrent/ConcurrentSkipListSet.java
@@ -5,18 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.NoSuchElementException;
-import java.util.Set;
-import java.util.SortedSet;
+import java.util.*;
import sun.misc.Unsafe;
/**
@@ -344,12 +333,12 @@ public class ConcurrentSkipListSet<E>
public E pollFirst() {
Map.Entry<E,Object> e = m.pollFirstEntry();
- return e == null? null : e.getKey();
+ return (e == null) ? null : e.getKey();
}
public E pollLast() {
Map.Entry<E,Object> e = m.pollLastEntry();
- return e == null? null : e.getKey();
+ return (e == null) ? null : e.getKey();
}
diff --git a/luni/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java b/luni/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
index 2f29a59..2aa375a 100644
--- a/luni/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
+++ b/luni/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
@@ -1,18 +1,17 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package java.util.concurrent;
@@ -21,8 +20,8 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.lang.reflect.Array;
import java.util.AbstractList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
@@ -30,640 +29,408 @@ import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
-import java.util.concurrent.locks.ReentrantLock;
+import libcore.base.EmptyArray;
+import libcore.base.Objects;
/**
- * Implements a {@link java.util.ArrayList} variant that is thread-safe. All
- * write operation result in a new copy of the underlying data being created.
- * Iterators reflect the state of the CopyOnWriteArrayList at the time they were
- * created. They are not updated to reflect subsequent changes to the list. In
- * addition, these iterators cannot be used for modifying the underlying
- * CopyOnWriteArrayList.
+ * A thread-safe random-access list.
+ *
+ * <p>Read operations (including {@link #get}) do not block and may overlap with
+ * update operations. Reads reflect the results of the most recently completed
+ * operations. Aggregate operations like {@link #addAll} and {@link #clear} are
+ * atomic; they never expose an intermediate state.
+ *
+ * <p>Iterators of this list never throw {@link
+ * ConcurrentModificationException}. When an iterator is created, it keeps a
+ * copy of the list's contents. It is always safe to iterate this list, but
+ * iterations may not reflect the latest state of the list.
*
- * @param <E> the element type
+ * <p>Iterators returned by this list and its sub lists cannot modify the
+ * underlying list. In particular, {@link Iterator#remove}, {@link
+ * ListIterator#add} and {@link ListIterator#set} all throw {@link
+ * UnsupportedOperationException}.
+ *
+ * <p>This class offers extended API beyond the {@link List} interface. It
+ * includes additional overloads for indexed search ({@link #indexOf} and {@link
+ * #lastIndexOf}) and methods for conditional adds ({@link #addIfAbsent} and
+ * {@link #addAllAbsent}).
*/
public class CopyOnWriteArrayList<E> implements List<E>, RandomAccess, Cloneable, Serializable {
private static final long serialVersionUID = 8673264195747942595L;
- private transient volatile E[] arr;
-
/**
- * Lock for the queue write methods
+ * Holds the latest snapshot of the list's data. This field is volatile so
+ * that data can be read without synchronization. As a consequence, all
+ * writes to this field must be atomic; it is an error to modify the
+ * contents of an array after it has been assigned to this field.
+ *
+ * Synchronization is required by all update operations. This defends
+ * against one update clobbering the result of another operation. For
+ * example, 100 threads simultaneously calling add() will grow the list's
+ * size by 100 when they have completed. No update operations are lost!
+ *
+ * Maintainers should be careful to read this field only once in
+ * non-blocking read methods. Write methods must be synchronized to avoid
+ * clobbering concurrent writes.
*/
- private final transient ReentrantLock lock = new ReentrantLock();
+ private transient volatile Object[] elements;
/**
- * Creates a new, empty instance of CopyOnWriteArrayList.
+ * Creates a new empty instance.
*/
public CopyOnWriteArrayList() {
- arr = newElementArray(0);
+ elements = EmptyArray.OBJECT;
}
/**
- * Creates a new instance of CopyOnWriteArrayList and fills it with the
- * contents of a given Collection.
- *
- * @param c the collection the elements of which are to be copied into
- * the new instance.
+ * Creates a new instance containing the elements of {@code collection}.
*/
- public CopyOnWriteArrayList(Collection<? extends E> c) {
- this((E[]) c.toArray());
+ @SuppressWarnings("unchecked")
+ public CopyOnWriteArrayList(Collection<? extends E> collection) {
+ this((E[]) collection.toArray());
}
/**
- * Creates a new instance of CopyOnWriteArrayList and fills it with the
- * contents of a given array.
- *
- * @param array the array the elements of which are to be copied into the
- * new instance.
+ * Creates a new instance containing the elements of {@code array}.
*/
public CopyOnWriteArrayList(E[] array) {
- int size = array.length;
- E[] data = newElementArray(size);
- for (int i = 0; i < size; i++) {
- data[i] = array[i];
- }
- arr = data;
- }
-
- public boolean add(E e) {
- lock.lock();
- try {
- E[] data;
- E[] old = getData();
- int size = old.length;
- data = newElementArray(size + 1);
- System.arraycopy(old, 0, data, 0, size);
- data[size] = e;
- setData(data);
- return true;
- } finally {
- lock.unlock();
- }
- }
-
- public void add(int index, E e) {
- lock.lock();
- try {
- E[] data;
- E[] old = getData();
- int size = old.length;
- checkIndexInclusive(index, size);
- data = newElementArray(size+1);
- System.arraycopy(old, 0, data, 0, index);
- data[index] = e;
- if (size > index) {
- System.arraycopy(old, index, data, index + 1, size - index);
- }
- setData(data);
- } finally {
- lock.unlock();
- }
- }
-
- public boolean addAll(Collection<? extends E> c) {
- Iterator it = c.iterator();
- int ssize = c.size();
- lock.lock();
- try {
- int size = size();
- E[] data;
- E[] old = getData();
- int nSize = size + ssize;
- data = newElementArray(nSize);
- System.arraycopy(old, 0, data, 0, size);
- while (it.hasNext()) {
- data[size++] = (E) it.next();
- }
- setData(data);
- } finally {
- lock.unlock();
- }
- return ssize > 0;
- }
-
- public boolean addAll(int index, Collection<? extends E> c) {
- Iterator it = c.iterator();
- int ssize = c.size();
- lock.lock();
- try {
- int size = size();
- checkIndexInclusive(index, size);
- E[] data;
- E[] old = getData();
- int nSize = size + ssize;
- data = newElementArray(nSize);
- System.arraycopy(old, 0, data, 0, index);
- int i = index;
- while (it.hasNext()) {
- data[i++] = (E) it.next();
- }
- if (size > index) {
- System.arraycopy(old, index, data, index + ssize, size - index);
- }
- setData(data);
- } finally {
- lock.unlock();
- }
- return ssize > 0;
+ this.elements = Arrays.copyOf(array, array.length, Object[].class);
}
- /**
- * Adds to this CopyOnWriteArrayList all those elements from a given
- * collection that are not yet part of the list.
- *
- * @param c the collection from which the potential new elements are
- * taken.
- *
- * @return the number of elements actually added to this list.
- */
- public int addAllAbsent(Collection<? extends E> c) {
- if (c.size() == 0) {
- return 0;
- }
- lock.lock();
+ @Override public Object clone() {
try {
- E[] old = getData();
- int size = old.length;
- E[] toAdd = newElementArray(c.size());
- int i = 0;
- for (Iterator it = c.iterator(); it.hasNext();) {
- E o = (E) it.next();
- if (indexOf(o) < 0 && indexOf(o, toAdd, 0, i) == -1) {
- toAdd[i++] = o;
- }
- }
- E[] data = newElementArray(size + i);
- System.arraycopy(old, 0, data, 0, size);
- System.arraycopy(toAdd, 0, data, size, i);
- setData(data);
- return i;
- } finally {
- lock.unlock();
- }
- }
-
- /**
- * Adds to this CopyOnWriteArrayList another element, given that this
- * element is not yet part of the list.
- *
- * @param e the potential new element.
- *
- * @return true if the element was added, or false otherwise.
- */
- public boolean addIfAbsent(E e) {
- lock.lock();
- try {
- E[] data;
- E[] old = getData();
- int size = old.length;
- if (size != 0) {
- if (indexOf(e) >= 0) {
- return false;
- }
- }
- data = newElementArray(size + 1);
- System.arraycopy(old, 0, data, 0, size);
- data[size] = e;
- setData(data);
- return true;
- } finally {
- lock.unlock();
+ CopyOnWriteArrayList result = (CopyOnWriteArrayList) super.clone();
+ result.elements = result.elements.clone();
+ return result;
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError(e);
}
}
- public void clear() {
- lock.lock();
- try {
- setData(newElementArray(0));
- } finally {
- lock.unlock();
- }
+ public int size() {
+ return elements.length;
}
- @Override
- public Object clone() {
- try {
- CopyOnWriteArrayList thisClone = (CopyOnWriteArrayList) super.clone();
- thisClone.setData(this.getData());
- return thisClone;
- } catch (CloneNotSupportedException e) {
- throw new RuntimeException("CloneNotSupportedException is not expected here");
- }
+ @SuppressWarnings("unchecked")
+ public E get(int index) {
+ return (E) elements[index];
}
public boolean contains(Object o) {
- return indexOf(o) >= 0;
+ return indexOf(o) != -1;
}
- public boolean containsAll(Collection<?> c) {
- E[] data = getData();
- return containsAll(c, data, 0, data.length);
+ public boolean containsAll(Collection<?> collection) {
+ Object[] snapshot = elements;
+ return containsAll(collection, snapshot, 0, snapshot.length);
}
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (!(o instanceof List)) {
- return false;
- }
- List l = (List) o;
- Iterator it = l.listIterator();
- Iterator ourIt = listIterator();
- while (it.hasNext()) {
- if (!ourIt.hasNext()) {
- return false;
- }
- Object thisListElem = it.next();
- Object anotherListElem = ourIt.next();
- if (!(thisListElem == null ? anotherListElem == null : thisListElem
- .equals(anotherListElem))) {
+ static boolean containsAll(Collection<?> collection, Object[] snapshot, int from, int to) {
+ for (Object o : collection) {
+ if (indexOf(o, snapshot, from, to) == -1) {
return false;
}
}
- if (ourIt.hasNext()) {
- return false;
- }
return true;
}
- public E get(int index) {
- E[] data = getData();
- return data[index];
+ /**
+ * Searches this list for {@code object} and returns the index of the first
+ * occurrence that is at or after {@code from}.
+ *
+ * @return the index or -1 if the object was not found.
+ */
+ public int indexOf(E object, int from) {
+ Object[] snapshot = elements;
+ return indexOf(object, snapshot, from, snapshot.length);
}
- public int hashCode() {
- int hashCode = 1;
- Iterator it = listIterator();
- while (it.hasNext()) {
- Object obj = it.next();
- hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
- }
- return hashCode;
+ public int indexOf(Object object) {
+ Object[] snapshot = elements;
+ return indexOf(object, snapshot, 0, snapshot.length);
}
/**
- * Returns the index of a given element, starting the search from a given
- * position in the list.
- *
- * @param e the element to search.
- * @param index the index at which to start the search.
+ * Searches this list for {@code object} and returns the index of the last
+ * occurrence that is before {@code to}.
*
- * @return the index of the element or null, if the element has not been
- * found at or beyond the given start index.
+ * @return the index or -1 if the object was not found.
*/
- public int indexOf(E e, int index) {
- E[] data = getData();
- return indexOf(e, data, index, data.length - index);
+ public int lastIndexOf(E object, int to) {
+ Object[] snapshot = elements;
+ return lastIndexOf(object, snapshot, 0, to);
}
- public int indexOf(Object o) {
- E[] data = getData();
- return indexOf(o, data, 0, data.length);
+ public int lastIndexOf(Object object) {
+ Object[] snapshot = elements;
+ return lastIndexOf(object, snapshot, 0, snapshot.length);
}
public boolean isEmpty() {
- return size() == 0;
+ return elements.length == 0;
}
+ /**
+ * Returns an {@link Iterator} that iterates over the elements of this list
+ * as they were at the time of this method call. Changes to the list made
+ * after this method call will not be reflected by the iterator, nor will
+ * they trigger a {@link ConcurrentModificationException}.
+ *
+ * <p>The returned iterator does not support {@link Iterator#remove()}.
+ */
public Iterator<E> iterator() {
- return new ListIteratorImpl(getData(), 0);
+ Object[] snapshot = elements;
+ return new CowIterator<E>(snapshot, 0, snapshot.length);
}
/**
- * Returns the last index of a given element, starting the search from
- * a given position in the list and going backwards.
- *
- * @param e the element to search.
- * @param index the index at which to start the search.
+ * Returns a {@link ListIterator} that iterates over the elements of this
+ * list as they were at the time of this method call. Changes to the list
+ * made after this method call will not be reflected by the iterator, nor
+ * will they trigger a {@link ConcurrentModificationException}.
*
- * @return the index of the element or null, if the element has not been
- * found at or before the given start index.
+ * <p>The returned iterator does not support {@link ListIterator#add},
+ * {@link ListIterator#set} or {@link Iterator#remove()},
*/
- public int lastIndexOf(E e, int index) {
- E[] data = getData();
- return lastIndexOf(e, data, 0, index);
- }
-
- public int lastIndexOf(Object o) {
- E[] data = getData();
- return lastIndexOf(o, data, 0, data.length);
- }
-
- public ListIterator<E> listIterator() {
- return new ListIteratorImpl(getData(), 0);
- }
-
public ListIterator<E> listIterator(int index) {
- E[] data = getData();
- checkIndexInclusive(index, data.length);
- return new ListIteratorImpl(data, index);
+ Object[] snapshot = elements;
+ if (index < 0 || index > snapshot.length) {
+ throw new IndexOutOfBoundsException("index=" + index + ", length=" + snapshot.length);
+ }
+ CowIterator<E> result = new CowIterator<E>(snapshot, 0, snapshot.length);
+ result.index = index;
+ return result;
}
- public E remove(int index) {
- return removeRange(index, 1);
+ /**
+ * Equivalent to {@code listIterator(0)}.
+ */
+ public ListIterator<E> listIterator() {
+ Object[] snapshot = elements;
+ return new CowIterator<E>(snapshot, 0, snapshot.length);
}
- public boolean remove(Object o) {
- lock.lock();
- try {
- int index = indexOf(o);
- if (index == -1) {
- return false;
- }
- remove(index);
- return true;
- } finally {
- lock.unlock();
+ public List<E> subList(int from, int to) {
+ Object[] snapshot = elements;
+ if (from < 0 || from > to || to > snapshot.length) {
+ throw new IndexOutOfBoundsException("from=" + from + ", to=" + to +
+ ", list size=" + snapshot.length);
}
+ return new CowSubList(snapshot, from, to);
}
- public boolean removeAll(Collection<?> c) {
- lock.lock();
- try {
- return removeAll(c, 0, getData().length) != 0;
- } finally {
- lock.unlock();
- }
+ public Object[] toArray() {
+ return elements.clone();
}
- public boolean retainAll(Collection<?> c) {
- if (c == null) {
- throw new NullPointerException();
+ @SuppressWarnings({"unchecked","SuspiciousSystemArraycopy"})
+ public <T> T[] toArray(T[] contents) {
+ Object[] snapshot = elements;
+ if (snapshot.length > contents.length) {
+ return (T[]) Arrays.copyOf(snapshot, snapshot.length, contents.getClass());
}
- lock.lock();
- try {
- return retainAll(c, 0, getData().length) != 0;
- } finally {
- lock.unlock();
+ System.arraycopy(snapshot, 0, contents, 0, snapshot.length);
+ if (snapshot.length < contents.length) {
+ contents[snapshot.length] = null;
}
+ return contents;
}
- public E set(int index, E e) {
- lock.lock();
- try {
- int size = size();
- checkIndexExlusive(index, size);
- E[] data;
- data = newElementArray(size);
- E[] oldArr = getData();
- System.arraycopy(oldArr, 0, data, 0, size);
- E old = data[index];
- data[index] = e;
- setData(data);
- return old;
- } finally {
- lock.unlock();
+ @Override public boolean equals(Object other) {
+ if (other instanceof CopyOnWriteArrayList) {
+ return this == other
+ || Arrays.equals(elements, ((CopyOnWriteArrayList<?>) other).elements);
+ } else if (other instanceof List) {
+ Object[] snapshot = elements;
+ Iterator<?> i = ((List<?>) other).iterator();
+ for (Object o : snapshot) {
+ if (!i.hasNext() || !Objects.equal(o, i.next())) {
+ return false;
+ }
+ }
+ return !i.hasNext();
+ } else {
+ return false;
}
}
- public int size() {
- return getData().length;
+ @Override public int hashCode() {
+ return Arrays.hashCode(elements);
}
- public List<E> subList(int fromIndex, int toIndex) {
- return new SubList(this, fromIndex, toIndex);
+ @Override public String toString() {
+ return Arrays.toString(elements);
}
- public Object[] toArray() {
- E[] data = getData();
- return toArray(data, 0, data.length);
+ public synchronized boolean add(E e) {
+ Object[] newElements = new Object[elements.length + 1];
+ System.arraycopy(elements, 0, newElements, 0, elements.length);
+ newElements[elements.length] = e;
+ elements = newElements;
+ return true;
}
- public <T> T[] toArray(T[] a) {
- E[] data = getData();
- return (T[]) toArray(a, data, 0, data.length);
+ public synchronized void add(int index, E e) {
+ Object[] newElements = new Object[elements.length + 1];
+ System.arraycopy(elements, 0, newElements, 0, index);
+ newElements[index] = e;
+ System.arraycopy(elements, index, newElements, index + 1, elements.length - index);
+ elements = newElements;
}
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("[");
-
- Iterator it = listIterator();
- while (it.hasNext()) {
- sb.append(String.valueOf(it.next()));
- sb.append(", ");
- }
- if (sb.length() > 1) {
- sb.setLength(sb.length() - 2);
- }
- sb.append("]");
- return sb.toString();
+ public synchronized boolean addAll(Collection<? extends E> collection) {
+ return addAll(elements.length, collection);
}
- // private and package private methods
-
- @SuppressWarnings("unchecked")
- private final E[] newElementArray(int size) {
- return (E[])new Object[size];
+ public synchronized boolean addAll(int index, Collection<? extends E> collection) {
+ Object[] toAdd = collection.toArray();
+ Object[] newElements = new Object[elements.length + toAdd.length];
+ System.arraycopy(elements, 0, newElements, 0, index);
+ System.arraycopy(toAdd, 0, newElements, index, toAdd.length);
+ System.arraycopy(elements, index,
+ newElements, index + toAdd.length, elements.length - index);
+ elements = newElements;
+ return toAdd.length > 0;
}
/**
- * sets the internal data array
+ * Adds the elements of {@code collection} that are not already present in
+ * this list. If {@code collection} includes a repeated value, at most one
+ * occurrence of that value will be added to this list. Elements are added
+ * at the end of this list.
*
- * @param data array to set
+ * <p>Callers of this method may prefer {@link CopyOnWriteArraySet}, whose
+ * API is more appropriate for set operations.
*/
- private final void setData(E[] data) {
- arr = data;
+ public synchronized int addAllAbsent(Collection<? extends E> collection) {
+ Object[] toAdd = collection.toArray();
+ Object[] newElements = new Object[elements.length + toAdd.length];
+ System.arraycopy(elements, 0, newElements, 0, elements.length);
+ int addedCount = 0;
+ for (Object o : toAdd) {
+ if (indexOf(o, newElements, 0, elements.length + addedCount) == -1) {
+ newElements[elements.length + addedCount++] = o;
+ }
+ }
+ if (addedCount < toAdd.length) {
+ newElements = Arrays.copyOfRange(
+ newElements, 0, elements.length + addedCount); // trim to size
+ }
+ elements = newElements;
+ return addedCount;
}
/**
- * gets the internal data array (or a new array if it is null)
+ * Adds {@code object} to the end of this list if it is not already present.
*
- * @return the data array
+ * <p>Callers of this method may prefer {@link CopyOnWriteArraySet}, whose
+ * API is more appropriate for set operations.
*/
- final E[] getData() {
- if (arr == null) {
- return newElementArray(0);
+ public synchronized boolean addIfAbsent(E object) {
+ if (contains(object)) {
+ return false;
}
- return arr;
+ add(object);
+ return true;
}
- /**
- * Removes from the specified range of this list
- * all the elements that are contained in the specified collection
- * <p/>
- * !should be called under lock
- *
- * @return Returns the number of removed elements
- */
- final int removeAll(Collection c, int start, int size) {
- int ssize = c.size();
- if (ssize == 0) {
- return 0;
- }
- Object[] old = getData();
- int arrsize = old.length;
- if (arrsize == 0) {
- return 0;
- }
- Object[] data = new Object[size];
- int j = 0;
- for (int i = start; i < (start + size); i++) {
- if (!c.contains(old[i])) {
- data[j++] = old[i];
- }
- }
- if (j != size) {
- E[] result = newElementArray(arrsize - (size - j));
- System.arraycopy(old, 0, result, 0, start);
- System.arraycopy(data, 0, result, start, j);
- System.arraycopy(old, start + size, result, start + j, arrsize
- - (start + size));
- setData(result);
- return (size - j);
- }
- return 0;
+ @Override public synchronized void clear() {
+ elements = EmptyArray.OBJECT;
}
- /**
- * Retains only the elements in the specified range of this list
- * that are contained in the specified collection
- *
- * @return Returns the number of removed elements
- */
- // should be called under lock
- int retainAll(Collection c, int start, int size) {
- Object[] old = getData();
- if (size == 0) {
- return 0;
- }
- if (c.size() == 0) {
- E[] data;
- if (size == old.length) {
- data = newElementArray(0);
- } else {
- data = newElementArray(old.length - size);
- System.arraycopy(old, 0, data, 0, start);
- System.arraycopy(old, start + size, data, start, old.length
- - start - size);
- }
- setData(data);
- return size;
- }
- Object[] temp = new Object[size];
- int pos = 0;
- for (int i = start; i < (start + size); i++) {
- if (c.contains(old[i])) {
- temp[pos++] = old[i];
- }
- }
- if (pos == size) {
- return 0;
- }
- E[] data = newElementArray(pos + old.length - size);
- System.arraycopy(old, 0, data, 0, start);
- System.arraycopy(temp, 0, data, start, pos);
- System.arraycopy(old, start + size, data, start + pos, old.length
- - start - size);
- setData(data);
- return (size - pos);
+ public synchronized E remove(int index) {
+ @SuppressWarnings("unchecked")
+ E removed = (E) elements[index];
+ removeRange(index, index + 1);
+ return removed;
}
- /**
- * Removes specified range from this list
- */
- E removeRange(int start, int size) {
- lock.lock();
- try {
- int sizeArr = size();
- checkRange(start, start + size, sizeArr);
- E[] data;
- data = newElementArray(sizeArr - size);
- E[] oldArr = getData();
- System.arraycopy(oldArr, 0, data, 0, start);
- E old = oldArr[start];
- if (sizeArr > (start + size)) {
- System.arraycopy(oldArr, start + size, data, start, sizeArr
- - (start + size));
- }
- setData(data);
- return old;
- } finally {
- lock.unlock();
+ public synchronized boolean remove(Object o) {
+ int index = indexOf(o);
+ if (index == -1) {
+ return false;
}
+ remove(index);
+ return true;
}
- // some util static functions to use by iterators and methods
- /**
- * Returns an array containing all of the elements
- * in the specified range of the array in proper sequence
- */
- static Object[] toArray(Object[] data, int start, int size) {
- Object[] result = new Object[size];
- System.arraycopy(data, start, result, 0, size);
- return result;
+ public synchronized boolean removeAll(Collection<?> collection) {
+ return removeOrRetain(collection, false, 0, elements.length) != 0;
}
- /**
- * Returns an array containing all of the elements
- * in the specified range of the array in proper sequence,
- * stores the result in the array, specified by first parameter
- * (as for public instance method toArray(Object[] to)
- */
- static Object[] toArray(Object[] to, Object[] data, int start, int size) {
- int l = data.length;
- if (to.length < l) {
- to = (Object[]) Array.newInstance(to.getClass().getComponentType(),
- l);
- } else {
- if (to.length > l) {
- to[l] = null;
- }
- }
- System.arraycopy(data, start, to, 0, size);
- return to;
+ public synchronized boolean retainAll(Collection<?> collection) {
+ return removeOrRetain(collection, true, 0, elements.length) != 0;
}
/**
- * Checks if the specified range of the
- * array contains all of the elements in the collection
- *
- * @param c collection with elements
- * @param data array where to search the elements
- * @param start start index
- * @param size size of the range
+ * Removes or retains the elements in {@code collection}. Returns the number
+ * of elements removed.
*/
- static final boolean containsAll(Collection c, Object[] data, int start,
- int size) {
- if (size == 0) {
- return c.isEmpty();
- }
- Iterator it = c.iterator();
- while (it.hasNext()) {
- Object next = it.next();
- if (indexOf(next, data, start, size) < 0) {
- return false;
+ private int removeOrRetain(Collection<?> collection, boolean retain, int from, int to) {
+ for (int i = from; i < to; i++) {
+ if (collection.contains(elements[i]) == retain) {
+ continue;
}
+
+ /*
+ * We've encountered an element that must be removed! Create a new
+ * array and copy in the surviving elements one by one.
+ */
+ Object[] newElements = new Object[elements.length - 1];
+ System.arraycopy(elements, 0, newElements, 0, i);
+ int newSize = i;
+ for (int j = i + 1; j < to; j++) {
+ if (collection.contains(elements[j]) == retain) {
+ newElements[newSize++] = elements[j];
+ }
+ }
+
+ /*
+ * Copy the elements after 'to'. This is only useful for sub lists,
+ * where 'to' will be less than elements.length.
+ */
+ System.arraycopy(elements, to, newElements, newSize, elements.length - to);
+ newSize += (elements.length - to);
+
+ if (newSize < newElements.length) {
+ newElements = Arrays.copyOfRange(newElements, 0, newSize); // trim to size
+ }
+ int removed = elements.length - newElements.length;
+ elements = newElements;
+ return removed;
}
- return true;
+
+ // we made it all the way through the loop without making any changes
+ return 0;
}
- /**
- * Returns the index in the specified range of the data array
- * of the last occurrence of the specified element
- *
- * @param o element to search
- * @param data array where to search
- * @param start start index
- * @param size size of the range
- * @return
- */
- static final int lastIndexOf(Object o, Object[] data, int start, int size) {
- if (size == 0) {
- return -1;
- }
- if (o != null) {
- for (int i = start + size - 1; i > start - 1; i--) {
- if (o.equals(data[i])) {
+ public synchronized E set(int index, E e) {
+ Object[] newElements = elements.clone();
+ @SuppressWarnings("unchecked")
+ E result = (E) newElements[index];
+ newElements[index] = e;
+ elements = newElements;
+ return result;
+ }
+
+ private void removeRange(int from, int to) {
+ Object[] newElements = new Object[elements.length - (to - from)];
+ System.arraycopy(elements, 0, newElements, 0, from);
+ System.arraycopy(elements, to, newElements, from, elements.length - to);
+ elements = newElements;
+ }
+
+ static int lastIndexOf(Object o, Object[] data, int from, int to) {
+ if (o == null) {
+ for (int i = to - 1; i >= from; i--) {
+ if (data[i] == null) {
return i;
}
}
} else {
- for (int i = start + size - 1; i > start - 1; i--) {
- if (data[i] == null) {
+ for (int i = to - 1; i >= from; i--) {
+ if (o.equals(data[i])) {
return i;
}
}
@@ -671,28 +438,15 @@ public class CopyOnWriteArrayList<E> implements List<E>, RandomAccess, Cloneable
return -1;
}
- /**
- * Returns the index in the specified range of the data array
- * of the first occurrence of the specified element
- *
- * @param o element to search
- * @param data array where to search
- * @param start start index
- * @param size end index
- * @return
- */
- static final int indexOf(Object o, Object[] data, int start, int size) {
- if (size == 0) {
- return -1;
- }
+ static int indexOf(Object o, Object[] data, int from, int to) {
if (o == null) {
- for (int i = start; i < start + size; i++) {
+ for (int i = from; i < to; i++) {
if (data[i] == null) {
return i;
}
}
} else {
- for (int i = start; i < start + size; i++) {
+ for (int i = from; i < to; i++) {
if (o.equals(data[i])) {
return i;
}
@@ -701,491 +455,316 @@ public class CopyOnWriteArrayList<E> implements List<E>, RandomAccess, Cloneable
return -1;
}
- /**
- * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
- * is out of the list bounds.
- *
- * @param index element index to check.
- */
- static final void checkIndexInclusive(int index, int size) {
- if (index < 0 || index > size) {
- throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
- }
+ final Object[] getArray() {
+ // CopyOnWriteArraySet needs this.
+ return elements;
}
/**
- * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
- * is out of the list bounds. Excluding the last element.
+ * The sub list is thread safe and supports non-blocking reads. Doing so is
+ * more difficult than in the full list, because each read needs to examine
+ * four fields worth of state:
+ * - the elements array of the full list
+ * - two integers for the bounds of this sub list
+ * - the expected elements array (to detect concurrent modification)
*
- * @param index element index to check.
- */
- static final void checkIndexExlusive(int index, int size) {
- if (index < 0 || index >= size) {
- throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
- }
- }
-
- static void checkRange(int start, int end, int listSize) {
- if (start < 0 || start > end || end > listSize) {
- throw new IndexOutOfBoundsException("start=" + start + ", end=" + end +
- ", list size=" + listSize);
- }
- }
-
- /**
- * gets the internal data array
- *
- * @return the data array
- */
- final E[] getArray() {
- return arr;
- }
-
- /**
- * list iterator implementation,
- * when created gets snapshot of the list,
- * so never throws ConcurrentModificationException
+ * This is accomplished by aggregating the sub list's three fields into a
+ * single snapshot object representing the current slice. This permits reads
+ * to be internally consistent without synchronization. This takes advantage
+ * of Java's concurrency semantics for final fields.
*/
- private static class ListIteratorImpl implements ListIterator {
- private final Object[] arr;
-
- private int current;
+ class CowSubList extends AbstractList<E> {
- private final int size;
+ /*
+ * An immutable snapshot of a sub list's state. By gathering all three
+ * of the sub list's fields in an immutable object,
+ */
+ private volatile Slice slice;
- final int size() {
- return size;
+ public CowSubList(Object[] expectedElements, int from, int to) {
+ this.slice = new Slice(expectedElements, from, to);
}
- public ListIteratorImpl(Object[] data, int current) {
- this.current = current;
- arr = data;
- size = data.length;
+ @Override public int size() {
+ Slice slice = this.slice;
+ return slice.to - slice.from;
}
- public void add(Object o) {
- throw new UnsupportedOperationException("Unsupported operation add");
+ @Override public boolean isEmpty() {
+ Slice slice = this.slice;
+ return slice.from == slice.to;
}
- public boolean hasNext() {
- if (current < size) {
- return true;
- }
- return false;
+ @SuppressWarnings("unchecked")
+ @Override public E get(int index) {
+ Slice slice = this.slice;
+ Object[] snapshot = elements;
+ slice.checkElementIndex(index);
+ slice.checkConcurrentModification(snapshot);
+ return (E) snapshot[index + slice.from];
}
- public boolean hasPrevious() {
- return current > 0;
+ @Override public Iterator<E> iterator() {
+ return listIterator(0);
}
- public Object next() {
- if (hasNext()) {
- return arr[current++];
- }
- throw new NoSuchElementException("pos is " + current + ", size is " + size);
+ @Override public ListIterator<E> listIterator() {
+ return listIterator(0);
}
- public int nextIndex() {
- return current;
+ @Override public ListIterator<E> listIterator(int index) {
+ Slice slice = this.slice;
+ Object[] snapshot = elements;
+ slice.checkPositionIndex(index);
+ slice.checkConcurrentModification(snapshot);
+ CowIterator<E> result = new CowIterator<E>(snapshot, slice.from, slice.to);
+ result.index = slice.from + index;
+ return result;
}
- public Object previous() {
- if (hasPrevious()) {
- return arr[--current];
- }
- throw new NoSuchElementException("pos is " + (current-1) + ", size is " + size);
+ @Override public int indexOf(Object object) {
+ Slice slice = this.slice;
+ Object[] snapshot = elements;
+ slice.checkConcurrentModification(snapshot);
+ int result = CopyOnWriteArrayList.indexOf(object, snapshot, slice.from, slice.to);
+ return (result != -1) ? (result - slice.from) : -1;
}
- public int previousIndex() {
- return current - 1;
+ @Override public int lastIndexOf(Object object) {
+ Slice slice = this.slice;
+ Object[] snapshot = elements;
+ slice.checkConcurrentModification(snapshot);
+ int result = CopyOnWriteArrayList.lastIndexOf(object, snapshot, slice.from, slice.to);
+ return (result != -1) ? (result - slice.from) : -1;
}
- public void remove() {
- throw new UnsupportedOperationException("Unsupported operation remove");
+ @Override public boolean contains(Object object) {
+ return indexOf(object) != -1;
}
- public void set(Object o) {
- throw new UnsupportedOperationException("Unsupported operation set");
+ @Override public boolean containsAll(Collection<?> collection) {
+ Slice slice = this.slice;
+ Object[] snapshot = elements;
+ slice.checkConcurrentModification(snapshot);
+ return CopyOnWriteArrayList.containsAll(collection, snapshot, slice.from, slice.to);
}
- }
-
- /**
- * Keeps a state of sublist implementation,
- * size and array declared as final,
- * so we'll never get the unconsistent state
- */
- static final class SubListReadData {
- final int size;
-
- final Object[] data;
-
- SubListReadData(int size, Object[] data) {
- this.size = size;
- this.data = data;
- }
- }
-
- /**
- * Represents a list returned by <code>sublist()</code>.
- */
- static class SubList extends AbstractList {
- private final CopyOnWriteArrayList list;
-
- private volatile SubListReadData read;
-
- private final int start;
-
- /**
- * Sublist constructor.
- *
- * @param list backing list.
- * @param fromIdx startingIndex, inclusive
- * @param toIdx endIndex, exclusive
- */
- public SubList(CopyOnWriteArrayList list, int fromIdx, int toIdx) {
- this.list = list;
- Object[] data = list.getData();
- int size = toIdx - fromIdx;
- checkRange(fromIdx, toIdx, data.length);
- read = new SubListReadData(size, list.getData());
- start = fromIdx;
+ @Override public List<E> subList(int from, int to) {
+ Slice slice = this.slice;
+ if (from < 0 || from > to || to > size()) {
+ throw new IndexOutOfBoundsException("from=" + from + ", to=" + to +
+ ", list size=" + size());
+ }
+ return new CowSubList(slice.expectedElements, slice.from + from, slice.from + to);
}
- /**
- * throws ConcurrentModificationException when the list
- * is structurally modified in the other way other than via this subList
- * <p/>
- * Should be called under lock!
- */
- private void checkModifications() {
- if (read.data != list.getData()) {
- throw new ConcurrentModificationException();
+ @Override public E remove(int index) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkElementIndex(index);
+ slice.checkConcurrentModification(elements);
+ E removed = CopyOnWriteArrayList.this.remove(slice.from + index);
+ slice = new Slice(elements, slice.from, slice.to - 1);
+ return removed;
}
}
- /**
- * @see java.util.List#listIterator(int)
- */
- public ListIterator listIterator(int startIdx) {
- return new SubListIterator(startIdx, read);
+ @Override public void clear() {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkConcurrentModification(elements);
+ CopyOnWriteArrayList.this.removeRange(slice.from, slice.to);
+ slice = new Slice(elements, slice.from, slice.from);
+ }
}
- /**
- * @see java.util.List#set(int, java.lang.Object)
- */
- public Object set(int index, Object obj) {
- list.lock.lock();
- try {
- checkIndexExlusive(index, read.size);
- checkModifications();
- Object result = list.set(index + start, obj);
- read = new SubListReadData(read.size, list.getData());
- return result;
- } finally {
- list.lock.unlock();
+ @Override public void add(int index, E object) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkPositionIndex(index);
+ slice.checkConcurrentModification(elements);
+ CopyOnWriteArrayList.this.add(index + slice.from, object);
+ slice = new Slice(elements, slice.from, slice.to + 1);
}
}
- /**
- * @see java.util.List#get(int)
- */
- public Object get(int index) {
- SubListReadData data = read;
- if (data.data != list.getData()) {
- list.lock.lock();
- try {
- data = read;
- if (data.data != list.getData()) {
- throw new ConcurrentModificationException();
- }
- } finally {
- list.lock.unlock();
- }
+ @Override public boolean add(E object) {
+ synchronized (CopyOnWriteArrayList.this) {
+ add(slice.to - slice.from, object);
+ return true;
}
- checkIndexExlusive(index, data.size);
- return data.data[index + start];
}
- /**
- * @see java.util.Collection#size()
- */
- public int size() {
- return read.size;
+ @Override public boolean addAll(int index, Collection<? extends E> collection) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkPositionIndex(index);
+ slice.checkConcurrentModification(elements);
+ int oldSize = elements.length;
+ boolean result = CopyOnWriteArrayList.this.addAll(index + slice.from, collection);
+ slice = new Slice(elements, slice.from, slice.to + (elements.length - oldSize));
+ return result;
+ }
}
- /**
- * @see java.util.List#remove(int)
- */
- public Object remove(int index) {
- list.lock.lock();
- try {
- checkIndexExlusive(index, read.size);
- checkModifications();
- Object obj = list.remove(index + start);
- read = new SubListReadData(read.size - 1, list.getData());
- return obj;
- } finally {
- list.lock.unlock();
+ @Override public boolean addAll(Collection<? extends E> collection) {
+ synchronized (CopyOnWriteArrayList.this) {
+ return addAll(size(), collection);
}
}
- /**
- * @see java.util.List#add(int, java.lang.Object)
- */
- public void add(int index, Object object) {
- list.lock.lock();
- try {
- checkIndexInclusive(index, read.size);
- checkModifications();
- list.add(index + start, object);
- read = new SubListReadData(read.size + 1, list.getData());
- } finally {
- list.lock.unlock();
+ @Override public E set(int index, E object) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkElementIndex(index);
+ slice.checkConcurrentModification(elements);
+ E result = CopyOnWriteArrayList.this.set(index + slice.from, object);
+ slice = new Slice(elements, slice.from, slice.to);
+ return result;
}
}
- public boolean add(Object o) {
- list.lock.lock();
- try {
- checkModifications();
- list.add(start + read.size, o);
- read = new SubListReadData(read.size + 1, list.getData());
+ @Override public boolean remove(Object object) {
+ synchronized (CopyOnWriteArrayList.this) {
+ int index = indexOf(object);
+ if (index == -1) {
+ return false;
+ }
+ remove(index);
return true;
- } finally {
- list.lock.unlock();
}
}
- public boolean addAll(Collection c) {
- list.lock.lock();
- try {
- checkModifications();
- int d = list.size();
- list.addAll(start + read.size, c);
- read = new SubListReadData(read.size + (list.size() - d), list
- .getData());
- return true;
- } finally {
- list.lock.unlock();
+ @Override public boolean removeAll(Collection<?> collection) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkConcurrentModification(elements);
+ int removed = removeOrRetain(collection, false, slice.from, slice.to);
+ slice = new Slice(elements, slice.from, slice.to - removed);
+ return removed != 0;
}
}
- public void clear() {
- list.lock.lock();
- try {
- checkModifications();
- list.removeRange(start, read.size);
- read = new SubListReadData(0, list.getData());
- } finally {
- list.lock.unlock();
+ @Override public boolean retainAll(Collection<?> collection) {
+ synchronized (CopyOnWriteArrayList.this) {
+ slice.checkConcurrentModification(elements);
+ int removed = removeOrRetain(collection, true, slice.from, slice.to);
+ slice = new Slice(elements, slice.from, slice.to - removed);
+ return removed != 0;
}
}
+ }
- public boolean contains(Object o) {
- return indexOf(o) != -1;
- }
+ static class Slice {
+ private final Object[] expectedElements;
+ private final int from;
+ private final int to;
- public boolean containsAll(Collection c) {
- SubListReadData b = read;
- return CopyOnWriteArrayList.containsAll(c, b.data, start, b.size);
+ Slice(Object[] expectedElements, int from, int to) {
+ this.expectedElements = expectedElements;
+ this.from = from;
+ this.to = to;
}
- public int indexOf(Object o) {
- SubListReadData b = read;
- int ind = CopyOnWriteArrayList.indexOf(o, b.data, start, b.size)
- - start;
- return ind < 0 ? -1 : ind;
+ /**
+ * Throws if {@code index} doesn't identify an element in the array.
+ */
+ void checkElementIndex(int index) {
+ if (index < 0 || index >= to - from) {
+ throw new IndexOutOfBoundsException("index=" + index + ", size=" + (to - from));
+ }
}
- public boolean isEmpty() {
- return read.size == 0;
+ /**
+ * Throws if {@code index} doesn't identify an insertion point in the
+ * array. Unlike element index, it's okay to add or iterate at size().
+ */
+ void checkPositionIndex(int index) {
+ if (index < 0 || index > to - from) {
+ throw new IndexOutOfBoundsException("index=" + index + ", size=" + (to - from));
+ }
}
- public Iterator iterator() {
- return new SubListIterator(0, read);
+ void checkConcurrentModification(Object[] snapshot) {
+ if (expectedElements != snapshot) {
+ throw new ConcurrentModificationException();
+ }
}
+ }
+
+ /**
+ * Iterates an immutable snapshot of the list.
+ */
+ static class CowIterator<E> implements ListIterator<E> {
+ private final Object[] snapshot;
+ private final int from;
+ private final int to;
+ private int index = 0;
- public int lastIndexOf(Object o) {
- SubListReadData b = read;
- int ind = CopyOnWriteArrayList
- .lastIndexOf(o, b.data, start, b.size)
- - start;
- return ind < 0 ? -1 : ind;
+ CowIterator(Object[] snapshot, int from, int to) {
+ this.snapshot = snapshot;
+ this.from = from;
+ this.to = to;
+ this.index = from;
}
- public ListIterator listIterator() {
- return new SubListIterator(0, read);
+ public void add(E object) {
+ throw new UnsupportedOperationException();
}
- public boolean remove(Object o) {
- list.lock.lock();
- try {
- checkModifications();
- int i = indexOf(o);
- if (i == -1) {
- return false;
- }
- boolean result = list.remove(i + start) != null;
- if (result) {
- read = new SubListReadData(read.size - 1, list.getData());
- }
- return result;
- } finally {
- list.lock.unlock();
- }
+ public boolean hasNext() {
+ return index < to;
}
- public boolean removeAll(Collection c) {
- list.lock.lock();
- try {
- checkModifications();
- int removed = list.removeAll(c, start, read.size);
- if (removed > 0) {
- read = new SubListReadData(read.size - removed, list
- .getData());
- return true;
- }
- } finally {
- list.lock.unlock();
- }
- return false;
+ public boolean hasPrevious() {
+ return index > from;
}
- public boolean retainAll(Collection c) {
- list.lock.lock();
- try {
- checkModifications();
- int removed = list.retainAll(c, start, read.size);
- if (removed > 0) {
- read = new SubListReadData(read.size - removed, list
- .getData());
- return true;
- }
- return false;
- } finally {
- list.lock.unlock();
+ @SuppressWarnings("unchecked")
+ public E next() {
+ if (index < to) {
+ return (E) snapshot[index++];
+ } else {
+ throw new NoSuchElementException();
}
}
- public List subList(int fromIndex, int toIndex) {
- return new SubList(list, start + fromIndex, start + toIndex);
+ public int nextIndex() {
+ return index;
}
- public Object[] toArray() {
- SubListReadData r = read;
- return CopyOnWriteArrayList.toArray(r.data, start, r.size);
+ @SuppressWarnings("unchecked")
+ public E previous() {
+ if (index > from) {
+ return (E) snapshot[--index];
+ } else {
+ throw new NoSuchElementException();
+ }
}
- public Object[] toArray(Object[] a) {
- SubListReadData r = read;
- return CopyOnWriteArrayList.toArray(a, r.data, start, r.size);
+ public int previousIndex() {
+ return index - 1;
}
- /**
- * @see java.util.List#addAll(int, java.util.Collection)
- */
- public boolean addAll(int index, Collection collection) {
- list.lock.lock();
- try {
- checkIndexInclusive(index, read.size);
- checkModifications();
- int d = list.size();
- boolean rt = list.addAll(index + start, collection);
- read = new SubListReadData(read.size + list.size() - d, list
- .getData());
- return rt;
- } finally {
- list.lock.unlock();
- }
+ public void remove() {
+ throw new UnsupportedOperationException();
}
- /**
- * Implementation of <code>ListIterator</code> for the
- * <code>SubList</code>
- * gets a snapshot of the sublist,
- * never throws ConcurrentModificationException
- */
- private class SubListIterator extends ListIteratorImpl {
- private final SubListReadData dataR;
-
- /**
- * Constructs an iterator starting with the given index
- *
- * @param index index of the first element to iterate.
- */
- private SubListIterator(int index, SubListReadData d) {
- super(d.data, index + start);
- this.dataR = d;
- }
-
- /**
- * @see java.util.ListIterator#nextIndex()
- */
- public int nextIndex() {
- return super.nextIndex() - start;
- }
-
- /**
- * @see java.util.ListIterator#previousIndex()
- */
- public int previousIndex() {
- return super.previousIndex() - start;
- }
-
- /**
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return nextIndex() < dataR.size;
- }
-
- /**
- * @see java.util.ListIterator#hasPrevious()
- */
- public boolean hasPrevious() {
- return previousIndex() > -1;
- }
+ public void set(E object) {
+ throw new UnsupportedOperationException();
}
-
}
- //serialization support
- /**
- * Writes the object state to the ObjectOutputStream.
- *
- * @param oos ObjectOutputStream to write object to.
- * @throws IOException if an I/O error occur.
- */
- private void writeObject(ObjectOutputStream oos) throws IOException {
- E[] back = getData();
- int size = back.length;
- oos.defaultWriteObject();
- oos.writeInt(size);
- for (int i = 0; i < size; i++) {
- oos.writeObject(back[i]);
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ Object[] snapshot = elements;
+ out.defaultWriteObject();
+ out.writeInt(snapshot.length);
+ for (Object o : snapshot) {
+ out.writeObject(o);
}
}
- /**
- * Reads the object state from the ObjectOutputStream.
- *
- * @param ois ObjectInputStream to read object from.
- * @throws IOException if an I/O error occur.
- */
- private void readObject(ObjectInputStream ois) throws IOException,
- ClassNotFoundException {
- ois.defaultReadObject();
- int length = ois.readInt();
- if (length == 0) {
- setData(newElementArray(0));
- } else {
- E[] back = newElementArray(length);
- for (int i = 0; i < back.length; i++) {
- back[i] = (E) ois.readObject();
- }
- setData(back);
+ private synchronized void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ Object[] snapshot = new Object[in.readInt()];
+ for (int i = 0; i < snapshot.length; i++) {
+ snapshot[i] = in.readObject();
}
+ elements = snapshot;
}
-
}
diff --git a/luni/src/main/java/java/util/concurrent/CopyOnWriteArraySet.java b/luni/src/main/java/java/util/concurrent/CopyOnWriteArraySet.java
index b07014b..87419fc 100644
--- a/luni/src/main/java/java/util/concurrent/CopyOnWriteArraySet.java
+++ b/luni/src/main/java/java/util/concurrent/CopyOnWriteArraySet.java
@@ -5,12 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
// BEGIN android-note
// removed link to collections framework docs
@@ -39,24 +34,23 @@ import java.util.Set;
* copy-on-write set to maintain a set of Handler objects that
* perform some action upon state updates.
*
- * <pre>
+ * <pre> {@code
* class Handler { void handle(); ... }
*
* class X {
- * private final CopyOnWriteArraySet&lt;Handler&gt; handlers
- * = new CopyOnWriteArraySet&lt;Handler&gt;();
- * public void addHandler(Handler h) { handlers.add(h); }
+ * private final CopyOnWriteArraySet<Handler> handlers
+ * = new CopyOnWriteArraySet<Handler>();
+ * public void addHandler(Handler h) { handlers.add(h); }
*
- * private long internalState;
- * private synchronized void changeState() { internalState = ...; }
+ * private long internalState;
+ * private synchronized void changeState() { internalState = ...; }
*
- * public void update() {
- * changeState();
- * for (Handler handler : handlers)
- * handler.handle();
- * }
- * }
- * </pre>
+ * public void update() {
+ * changeState();
+ * for (Handler handler : handlers)
+ * handler.handle();
+ * }
+ * }}</pre>
*
* @see CopyOnWriteArrayList
* @since 1.5
diff --git a/luni/src/main/java/java/util/concurrent/CountDownLatch.java b/luni/src/main/java/java/util/concurrent/CountDownLatch.java
index 849ae9d..1888279 100644
--- a/luni/src/main/java/java/util/concurrent/CountDownLatch.java
+++ b/luni/src/main/java/java/util/concurrent/CountDownLatch.java
@@ -5,8 +5,8 @@
*/
package java.util.concurrent;
-
-import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+import java.util.concurrent.locks.*;
+import java.util.concurrent.atomic.*;
/**
* A synchronization aid that allows one or more threads to wait until
@@ -146,7 +146,7 @@ public class CountDownLatch {
}
protected int tryAcquireShared(int acquires) {
- return getState() == 0? 1 : -1;
+ return (getState() == 0) ? 1 : -1;
}
protected boolean tryReleaseShared(int releases) {
diff --git a/luni/src/main/java/java/util/concurrent/CyclicBarrier.java b/luni/src/main/java/java/util/concurrent/CyclicBarrier.java
index afb267b..d5738c5 100644
--- a/luni/src/main/java/java/util/concurrent/CyclicBarrier.java
+++ b/luni/src/main/java/java/util/concurrent/CyclicBarrier.java
@@ -5,9 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
/**
* A synchronization aid that allows a set of threads to all wait for
diff --git a/luni/src/main/java/java/util/concurrent/DelayQueue.java b/luni/src/main/java/java/util/concurrent/DelayQueue.java
index ff35dbc..8c44e82 100644
--- a/luni/src/main/java/java/util/concurrent/DelayQueue.java
+++ b/luni/src/main/java/java/util/concurrent/DelayQueue.java
@@ -6,15 +6,8 @@
package java.util.concurrent;
-
-import java.util.AbstractQueue;
-import java.util.Collection;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.PriorityQueue;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
+import java.util.*;
// BEGIN android-note
// removed link to collections framework docs
@@ -460,12 +453,14 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
/**
* Returns an iterator over all the elements (both expired and
* unexpired) in this queue. The iterator does not return the
- * elements in any particular order. The returned
- * <tt>Iterator</tt> is a "weakly consistent" iterator that will
- * never throw {@link ConcurrentModificationException}, and
- * guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed
- * to) reflect any modifications subsequent to construction.
+ * elements in any particular order.
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
+ * will never throw {@link java.util.ConcurrentModificationException
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
*
* @return an iterator over the elements in this queue
*/
diff --git a/luni/src/main/java/java/util/concurrent/Delayed.java b/luni/src/main/java/java/util/concurrent/Delayed.java
index 7d05064..b1ff4ee 100644
--- a/luni/src/main/java/java/util/concurrent/Delayed.java
+++ b/luni/src/main/java/java/util/concurrent/Delayed.java
@@ -6,6 +6,8 @@
package java.util.concurrent;
+import java.util.*;
+
/**
* A mix-in style interface for marking objects that should be
* acted upon after a given delay.
diff --git a/luni/src/main/java/java/util/concurrent/Exchanger.java b/luni/src/main/java/java/util/concurrent/Exchanger.java
index e8224ed..3c230be 100644
--- a/luni/src/main/java/java/util/concurrent/Exchanger.java
+++ b/luni/src/main/java/java/util/concurrent/Exchanger.java
@@ -6,9 +6,7 @@
*/
package java.util.concurrent;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReference;
+import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.LockSupport;
/**
@@ -328,7 +326,9 @@ public class Exchanger<V> {
else if (y == null && // Try to occupy
slot.compareAndSet(null, me)) {
if (index == 0) // Blocking wait for slot 0
- return timed? awaitNanos(me, slot, nanos): await(me, slot);
+ return timed ?
+ awaitNanos(me, slot, nanos) :
+ await(me, slot);
Object v = spinWait(me, slot); // Spin wait for non-0
if (v != CANCEL)
return v;
@@ -570,8 +570,8 @@ public class Exchanger<V> {
* dormant until one of two things happens:
* <ul>
* <li>Some other thread enters the exchange; or
- * <li>Some other thread {@linkplain Thread#interrupt interrupts} the current
- * thread.
+ * <li>Some other thread {@linkplain Thread#interrupt interrupts}
+ * the current thread.
* </ul>
* <p>If the current thread:
* <ul>
@@ -589,7 +589,7 @@ public class Exchanger<V> {
*/
public V exchange(V x) throws InterruptedException {
if (!Thread.interrupted()) {
- Object v = doExchange(x == null? NULL_ITEM : x, false, 0);
+ Object v = doExchange((x == null) ? NULL_ITEM : x, false, 0);
if (v == NULL_ITEM)
return null;
if (v != CANCEL)
@@ -644,7 +644,7 @@ public class Exchanger<V> {
public V exchange(V x, long timeout, TimeUnit unit)
throws InterruptedException, TimeoutException {
if (!Thread.interrupted()) {
- Object v = doExchange(x == null? NULL_ITEM : x,
+ Object v = doExchange((x == null) ? NULL_ITEM : x,
true, unit.toNanos(timeout));
if (v == NULL_ITEM)
return null;
diff --git a/luni/src/main/java/java/util/concurrent/Executor.java b/luni/src/main/java/java/util/concurrent/Executor.java
index a61e921..fbc4e6f 100644
--- a/luni/src/main/java/java/util/concurrent/Executor.java
+++ b/luni/src/main/java/java/util/concurrent/Executor.java
@@ -50,37 +50,37 @@ package java.util.concurrent;
* serializes the submission of tasks to a second executor,
* illustrating a composite executor.
*
- * <pre>
+ * <pre> {@code
* class SerialExecutor implements Executor {
- * final Queue&lt;Runnable&gt; tasks = new ArrayDeque&lt;Runnable&gt;();
- * final Executor executor;
- * Runnable active;
+ * final Queue<Runnable> tasks = new ArrayDeque<Runnable>();
+ * final Executor executor;
+ * Runnable active;
*
- * SerialExecutor(Executor executor) {
- * this.executor = executor;
- * }
+ * SerialExecutor(Executor executor) {
+ * this.executor = executor;
+ * }
*
- * public synchronized void execute(final Runnable r) {
- * tasks.offer(new Runnable() {
- * public void run() {
- * try {
- * r.run();
- * } finally {
- * scheduleNext();
- * }
- * }
- * });
- * if (active == null) {
- * scheduleNext();
+ * public synchronized void execute(final Runnable r) {
+ * tasks.offer(new Runnable() {
+ * public void run() {
+ * try {
+ * r.run();
+ * } finally {
+ * scheduleNext();
* }
+ * }
+ * });
+ * if (active == null) {
+ * scheduleNext();
* }
+ * }
*
- * protected synchronized void scheduleNext() {
- * if ((active = tasks.poll()) != null) {
- * executor.execute(active);
- * }
+ * protected synchronized void scheduleNext() {
+ * if ((active = tasks.poll()) != null) {
+ * executor.execute(active);
* }
- * }</pre>
+ * }
+ * }}</pre>
*
* The <tt>Executor</tt> implementations provided in this package
* implement {@link ExecutorService}, which is a more extensive
diff --git a/luni/src/main/java/java/util/concurrent/ExecutorCompletionService.java b/luni/src/main/java/java/util/concurrent/ExecutorCompletionService.java
index bf4a584..b41955d 100644
--- a/luni/src/main/java/java/util/concurrent/ExecutorCompletionService.java
+++ b/luni/src/main/java/java/util/concurrent/ExecutorCompletionService.java
@@ -168,7 +168,8 @@ public class ExecutorCompletionService<V> implements CompletionService<V> {
return completionQueue.poll();
}
- public Future<V> poll(long timeout, TimeUnit unit) throws InterruptedException {
+ public Future<V> poll(long timeout, TimeUnit unit)
+ throws InterruptedException {
return completionQueue.poll(timeout, unit);
}
diff --git a/luni/src/main/java/java/util/concurrent/ExecutorService.java b/luni/src/main/java/java/util/concurrent/ExecutorService.java
index b4bc5cb..ddd77bf 100644
--- a/luni/src/main/java/java/util/concurrent/ExecutorService.java
+++ b/luni/src/main/java/java/util/concurrent/ExecutorService.java
@@ -5,9 +5,10 @@
*/
package java.util.concurrent;
-
-import java.util.Collection;
import java.util.List;
+import java.util.Collection;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
/**
* An {@link Executor} that provides methods to manage termination and
diff --git a/luni/src/main/java/java/util/concurrent/Executors.java b/luni/src/main/java/java/util/concurrent/Executors.java
index 5c407b0..e42b0cc 100644
--- a/luni/src/main/java/java/util/concurrent/Executors.java
+++ b/luni/src/main/java/java/util/concurrent/Executors.java
@@ -5,16 +5,14 @@
*/
package java.util.concurrent;
-
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
import java.security.AccessControlContext;
-import java.security.AccessControlException;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
+import java.security.PrivilegedActionException;
+import java.security.AccessControlException;
// import sun.security.util.SecurityConstants; // android-removed
/**
@@ -56,7 +54,7 @@ public class Executors {
*
* @param nThreads the number of threads in the pool
* @return the newly created thread pool
- * @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt>
+ * @throws IllegalArgumentException if {@code nThreads <= 0}
*/
public static ExecutorService newFixedThreadPool(int nThreads) {
return new ThreadPoolExecutor(nThreads, nThreads,
@@ -81,7 +79,7 @@ public class Executors {
* @param threadFactory the factory to use when creating new threads
* @return the newly created thread pool
* @throws NullPointerException if threadFactory is null
- * @throws IllegalArgumentException if <tt>nThreads &lt;= 0</tt>
+ * @throws IllegalArgumentException if {@code nThreads <= 0}
*/
public static ExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory) {
return new ThreadPoolExecutor(nThreads, nThreads,
@@ -215,7 +213,7 @@ public class Executors {
* @param corePoolSize the number of threads to keep in the pool,
* even if they are idle.
* @return a newly created scheduled thread pool
- * @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt>
+ * @throws IllegalArgumentException if {@code corePoolSize < 0}
*/
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) {
return new ScheduledThreadPoolExecutor(corePoolSize);
@@ -229,7 +227,7 @@ public class Executors {
* @param threadFactory the factory to use when the executor
* creates a new thread.
* @return a newly created scheduled thread pool
- * @throws IllegalArgumentException if <tt>corePoolSize &lt; 0</tt>
+ * @throws IllegalArgumentException if {@code corePoolSize < 0}
* @throws NullPointerException if threadFactory is null
*/
public static ScheduledExecutorService newScheduledThreadPool(
@@ -535,8 +533,8 @@ public class Executors {
DefaultThreadFactory() {
SecurityManager s = System.getSecurityManager();
- group = (s != null)? s.getThreadGroup() :
- Thread.currentThread().getThreadGroup();
+ group = (s != null) ? s.getThreadGroup() :
+ Thread.currentThread().getThreadGroup();
namePrefix = "pool-" +
poolNumber.getAndIncrement() +
"-thread-";
@@ -642,12 +640,8 @@ public class Executors {
FinalizableDelegatedExecutorService(ExecutorService executor) {
super(executor);
}
- @Override protected void finalize() throws Throwable {
- try {
- super.shutdown();
- } finally {
- super.finalize();
- }
+ protected void finalize() {
+ super.shutdown();
}
}
diff --git a/luni/src/main/java/java/util/concurrent/Future.java b/luni/src/main/java/java/util/concurrent/Future.java
index 0459ee4..eb84796 100644
--- a/luni/src/main/java/java/util/concurrent/Future.java
+++ b/luni/src/main/java/java/util/concurrent/Future.java
@@ -18,21 +18,21 @@ package java.util.concurrent;
* computation has completed, the computation cannot be cancelled.
* If you would like to use a <tt>Future</tt> for the sake
* of cancellability but not provide a usable result, you can
- * declare types of the form <tt>Future&lt;?&gt;</tt> and
+ * declare types of the form {@code Future<?>} and
* return <tt>null</tt> as a result of the underlying task.
*
* <p>
* <b>Sample Usage</b> (Note that the following classes are all
* made-up.) <p>
- * <pre>
+ * <pre> {@code
* interface ArchiveSearcher { String search(String target); }
* class App {
* ExecutorService executor = ...
* ArchiveSearcher searcher = ...
* void showSearch(final String target)
* throws InterruptedException {
- * Future&lt;String&gt; future
- * = executor.submit(new Callable&lt;String&gt;() {
+ * Future<String> future
+ * = executor.submit(new Callable<String>() {
* public String call() {
* return searcher.search(target);
* }});
@@ -41,20 +41,18 @@ package java.util.concurrent;
* displayText(future.get()); // use future
* } catch (ExecutionException ex) { cleanup(); return; }
* }
- * }
- * </pre>
+ * }}</pre>
*
* The {@link FutureTask} class is an implementation of <tt>Future</tt> that
* implements <tt>Runnable</tt>, and so may be executed by an <tt>Executor</tt>.
* For example, the above construction with <tt>submit</tt> could be replaced by:
- * <pre>
- * FutureTask&lt;String&gt; future =
- * new FutureTask&lt;String&gt;(new Callable&lt;String&gt;() {
+ * <pre> {@code
+ * FutureTask<String> future =
+ * new FutureTask<String>(new Callable<String>() {
* public String call() {
* return searcher.search(target);
* }});
- * executor.execute(future);
- * </pre>
+ * executor.execute(future);}</pre>
*
* <p>Memory consistency effects: Actions taken by the asynchronous computation
* <a href="package-summary.html#MemoryVisibility"> <i>happen-before</i></a>
diff --git a/luni/src/main/java/java/util/concurrent/FutureTask.java b/luni/src/main/java/java/util/concurrent/FutureTask.java
index 9142275..2f2335e 100644
--- a/luni/src/main/java/java/util/concurrent/FutureTask.java
+++ b/luni/src/main/java/java/util/concurrent/FutureTask.java
@@ -5,8 +5,7 @@
*/
package java.util.concurrent;
-
-import java.util.concurrent.locks.AbstractQueuedSynchronizer;
+import java.util.concurrent.locks.*;
/**
* A cancellable asynchronous computation. This class provides a base
@@ -57,7 +56,7 @@ public class FutureTask<V> implements RunnableFuture<V> {
* @param result the result to return on successful completion. If
* you don't need a particular result, consider using
* constructions of the form:
- * <tt>Future&lt;?&gt; f = new FutureTask&lt;Object&gt;(runnable, null)</tt>
+ * {@code Future<?> f = new FutureTask<Void>(runnable, null)}
* @throws NullPointerException if runnable is null
*/
public FutureTask(Runnable runnable, V result) {
diff --git a/luni/src/main/java/java/util/concurrent/LinkedBlockingDeque.java b/luni/src/main/java/java/util/concurrent/LinkedBlockingDeque.java
index 463e8d0..8c01e71 100644
--- a/luni/src/main/java/java/util/concurrent/LinkedBlockingDeque.java
+++ b/luni/src/main/java/java/util/concurrent/LinkedBlockingDeque.java
@@ -97,10 +97,8 @@ public class LinkedBlockingDeque<E>
*/
Node<E> next;
- Node(E x, Node<E> p, Node<E> n) {
+ Node(E x) {
item = x;
- prev = p;
- next = n;
}
}
@@ -170,7 +168,7 @@ public class LinkedBlockingDeque<E>
for (E e : c) {
if (e == null)
throw new NullPointerException();
- if (!linkLast(e))
+ if (!linkLast(new Node<E>(e)))
throw new IllegalStateException("Deque full");
}
} finally {
@@ -182,38 +180,38 @@ public class LinkedBlockingDeque<E>
// Basic linking and unlinking operations, called only while holding lock
/**
- * Links e as first element, or returns false if full.
+ * Links node as first element, or returns false if full.
*/
- private boolean linkFirst(E e) {
+ private boolean linkFirst(Node<E> node) {
// assert lock.isHeldByCurrentThread();
if (count >= capacity)
return false;
Node<E> f = first;
- Node<E> x = new Node<E>(e, null, f);
- first = x;
+ node.next = f;
+ first = node;
if (last == null)
- last = x;
+ last = node;
else
- f.prev = x;
+ f.prev = node;
++count;
notEmpty.signal();
return true;
}
/**
- * Links e as last element, or returns false if full.
+ * Links node as last element, or returns false if full.
*/
- private boolean linkLast(E e) {
+ private boolean linkLast(Node<E> node) {
// assert lock.isHeldByCurrentThread();
if (count >= capacity)
return false;
Node<E> l = last;
- Node<E> x = new Node<E>(e, l, null);
- last = x;
+ node.prev = l;
+ last = node;
if (first == null)
- first = x;
+ first = node;
else
- l.next = x;
+ l.next = node;
++count;
notEmpty.signal();
return true;
@@ -310,10 +308,11 @@ public class LinkedBlockingDeque<E>
*/
public boolean offerFirst(E e) {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return linkFirst(e);
+ return linkFirst(node);
} finally {
lock.unlock();
}
@@ -324,10 +323,11 @@ public class LinkedBlockingDeque<E>
*/
public boolean offerLast(E e) {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return linkLast(e);
+ return linkLast(node);
} finally {
lock.unlock();
}
@@ -339,10 +339,11 @@ public class LinkedBlockingDeque<E>
*/
public void putFirst(E e) throws InterruptedException {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
- while (!linkFirst(e))
+ while (!linkFirst(node))
notFull.await();
} finally {
lock.unlock();
@@ -355,10 +356,11 @@ public class LinkedBlockingDeque<E>
*/
public void putLast(E e) throws InterruptedException {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
final ReentrantLock lock = this.lock;
lock.lock();
try {
- while (!linkLast(e))
+ while (!linkLast(node))
notFull.await();
} finally {
lock.unlock();
@@ -372,11 +374,12 @@ public class LinkedBlockingDeque<E>
public boolean offerFirst(E e, long timeout, TimeUnit unit)
throws InterruptedException {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- while (!linkFirst(e)) {
+ while (!linkFirst(node)) {
if (nanos <= 0)
return false;
nanos = notFull.awaitNanos(nanos);
@@ -394,11 +397,12 @@ public class LinkedBlockingDeque<E>
public boolean offerLast(E e, long timeout, TimeUnit unit)
throws InterruptedException {
if (e == null) throw new NullPointerException();
+ Node<E> node = new Node<E>(e);
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
try {
- while (!linkLast(e)) {
+ while (!linkLast(node)) {
if (nanos <= 0)
return false;
nanos = notFull.awaitNanos(nanos);
@@ -586,7 +590,7 @@ public class LinkedBlockingDeque<E>
/**
* Inserts the specified element at the end of this deque unless it would
* violate capacity restrictions. When using a capacity-restricted deque,
- * it is generally preferable to use method {@link #offer(E) offer}.
+ * it is generally preferable to use method {@link #offer offer}.
*
* <p>This method is equivalent to {@link #addLast}.
*
@@ -926,7 +930,20 @@ public class LinkedBlockingDeque<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return super.toString();
+ Node<E> p = first;
+ if (p == null)
+ return "[]";
+
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (;;) {
+ E e = p.item;
+ sb.append(e == this ? "(this Collection)" : e);
+ p = p.next;
+ if (p == null)
+ return sb.append(']').toString();
+ sb.append(',').append(' ');
+ }
} finally {
lock.unlock();
}
@@ -958,12 +975,13 @@ public class LinkedBlockingDeque<E>
/**
* Returns an iterator over the elements in this deque in proper sequence.
* The elements will be returned in order from first (head) to last (tail).
- * The returned {@code Iterator} is a "weakly consistent" iterator that
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
*
* @return an iterator over the elements in this deque in proper sequence
*/
@@ -975,12 +993,15 @@ public class LinkedBlockingDeque<E>
* Returns an iterator over the elements in this deque in reverse
* sequential order. The elements will be returned in order from
* last (tail) to first (head).
- * The returned {@code Iterator} is a "weakly consistent" iterator that
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
+ *
+ * @return an iterator over the elements in this deque in reverse order
*/
public Iterator<E> descendingIterator() {
return new DescendingItr();
@@ -1025,6 +1046,26 @@ public class LinkedBlockingDeque<E>
}
/**
+ * Returns the successor node of the given non-null, but
+ * possibly previously deleted, node.
+ */
+ private Node<E> succ(Node<E> n) {
+ // Chains of deleted nodes ending in null or self-links
+ // are possible if multiple interior nodes are removed.
+ for (;;) {
+ Node<E> s = nextNode(n);
+ if (s == null)
+ return null;
+ else if (s.item != null)
+ return s;
+ else if (s == n)
+ return firstNode();
+ else
+ n = s;
+ }
+ }
+
+ /**
* Advances next.
*/
void advance() {
@@ -1032,16 +1073,7 @@ public class LinkedBlockingDeque<E>
lock.lock();
try {
// assert next != null;
- Node<E> s = nextNode(next);
- if (s == next) {
- next = firstNode();
- } else {
- // Skip over removed nodes.
- // May be necessary if multiple interior Nodes are removed.
- while (s != null && s.item == null)
- s = nextNode(s);
- next = s;
- }
+ next = succ(next);
nextItem = (next == null) ? null : next.item;
} finally {
lock.unlock();
diff --git a/luni/src/main/java/java/util/concurrent/LinkedBlockingQueue.java b/luni/src/main/java/java/util/concurrent/LinkedBlockingQueue.java
index b385320..d06c737 100644
--- a/luni/src/main/java/java/util/concurrent/LinkedBlockingQueue.java
+++ b/luni/src/main/java/java/util/concurrent/LinkedBlockingQueue.java
@@ -6,17 +6,17 @@
package java.util.concurrent;
-// BEGIN android-note
-// removed link to collections framework docs
-// END android-note
-
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.AbstractQueue;
import java.util.Collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+
+// BEGIN android-note
+// removed link to collections framework docs
+// END android-note
/**
* An optionally-bounded {@linkplain BlockingQueue blocking queue} based on
@@ -160,14 +160,14 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
}
/**
- * Creates a node and links it at end of queue.
+ * Links node at end of queue.
*
- * @param x the item
+ * @param node the node
*/
- private void enqueue(E x) {
+ private void enqueue(Node<E> node) {
// assert putLock.isHeldByCurrentThread();
// assert last.next == null;
- last = last.next = new Node<E>(x);
+ last = last.next = node;
}
/**
@@ -253,7 +253,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
throw new NullPointerException();
if (n == capacity)
throw new IllegalStateException("Queue full");
- enqueue(e);
+ enqueue(new Node<E>(e));
++n;
}
count.set(n);
@@ -303,6 +303,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
// Note: convention in all put/take/etc is to preset local var
// holding count negative to indicate failure unless set.
int c = -1;
+ Node<E> node = new Node(e);
final ReentrantLock putLock = this.putLock;
final AtomicInteger count = this.count;
putLock.lockInterruptibly();
@@ -318,7 +319,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
while (count.get() == capacity) {
notFull.await();
}
- enqueue(e);
+ enqueue(node);
c = count.getAndIncrement();
if (c + 1 < capacity)
notFull.signal();
@@ -353,7 +354,7 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
return false;
nanos = notFull.awaitNanos(nanos);
}
- enqueue(e);
+ enqueue(new Node<E>(e));
c = count.getAndIncrement();
if (c + 1 < capacity)
notFull.signal();
@@ -382,11 +383,12 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
if (count.get() == capacity)
return false;
int c = -1;
+ Node<E> node = new Node(e);
final ReentrantLock putLock = this.putLock;
putLock.lock();
try {
if (count.get() < capacity) {
- enqueue(e);
+ enqueue(node);
c = count.getAndIncrement();
if (c + 1 < capacity)
notFull.signal();
@@ -531,6 +533,27 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
}
/**
+ * Returns {@code true} if this queue contains the specified element.
+ * More formally, returns {@code true} if and only if this queue contains
+ * at least one element {@code e} such that {@code o.equals(e)}.
+ *
+ * @param o object to be checked for containment in this queue
+ * @return {@code true} if this queue contains the specified element
+ */
+ public boolean contains(Object o) {
+ if (o == null) return false;
+ fullyLock();
+ try {
+ for (Node<E> p = head.next; p != null; p = p.next)
+ if (o.equals(p.item))
+ return true;
+ return false;
+ } finally {
+ fullyUnlock();
+ }
+ }
+
+ /**
* Returns an array containing all of the elements in this queue, in
* proper sequence.
*
@@ -616,7 +639,20 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
public String toString() {
fullyLock();
try {
- return super.toString();
+ Node<E> p = head.next;
+ if (p == null)
+ return "[]";
+
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (;;) {
+ E e = p.item;
+ sb.append(e == this ? "(this Collection)" : e);
+ p = p.next;
+ if (p == null)
+ return sb.append(']').toString();
+ sb.append(',').append(' ');
+ }
} finally {
fullyUnlock();
}
@@ -698,12 +734,14 @@ public class LinkedBlockingQueue<E> extends AbstractQueue<E>
/**
* Returns an iterator over the elements in this queue in proper sequence.
- * The returned {@code Iterator} is a "weakly consistent" iterator that
+ * The elements will be returned in order from first (head) to last (tail).
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
* will never throw {@link java.util.ConcurrentModificationException
- * ConcurrentModificationException},
- * and guarantees to traverse elements as they existed upon
- * construction of the iterator, and may (but is not guaranteed to)
- * reflect any modifications subsequent to construction.
+ * ConcurrentModificationException}, and guarantees to traverse
+ * elements as they existed upon construction of the iterator, and
+ * may (but is not guaranteed to) reflect any modifications
+ * subsequent to construction.
*
* @return an iterator over the elements in this queue in proper sequence
*/
diff --git a/luni/src/main/java/java/util/concurrent/PriorityBlockingQueue.java b/luni/src/main/java/java/util/concurrent/PriorityBlockingQueue.java
index 95dfc75..cffbe64 100644
--- a/luni/src/main/java/java/util/concurrent/PriorityBlockingQueue.java
+++ b/luni/src/main/java/java/util/concurrent/PriorityBlockingQueue.java
@@ -6,17 +6,8 @@
package java.util.concurrent;
-import java.util.AbstractQueue;
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.ConcurrentModificationException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.PriorityQueue;
-import java.util.Queue;
-import java.util.SortedSet;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
+import java.util.*;
// BEGIN android-note
// removed link to collections framework docs
@@ -27,11 +18,11 @@ import java.util.concurrent.locks.ReentrantLock;
* the same ordering rules as class {@link PriorityQueue} and supplies
* blocking retrieval operations. While this queue is logically
* unbounded, attempted additions may fail due to resource exhaustion
- * (causing <tt>OutOfMemoryError</tt>). This class does not permit
- * <tt>null</tt> elements. A priority queue relying on {@linkplain
+ * (causing {@code OutOfMemoryError}). This class does not permit
+ * {@code null} elements. A priority queue relying on {@linkplain
* Comparable natural ordering} also does not permit insertion of
* non-comparable objects (doing so results in
- * <tt>ClassCastException</tt>).
+ * {@code ClassCastException}).
*
* <p>This class and its iterator implement all of the
* <em>optional</em> methods of the {@link Collection} and {@link
@@ -39,7 +30,7 @@ import java.util.concurrent.locks.ReentrantLock;
* #iterator()} is <em>not</em> guaranteed to traverse the elements of
* the PriorityBlockingQueue in any particular order. If you need
* ordered traversal, consider using
- * <tt>Arrays.sort(pq.toArray())</tt>. Also, method <tt>drainTo</tt>
+ * {@code Arrays.sort(pq.toArray())}. Also, method {@code drainTo}
* can be used to <em>remove</em> some or all elements in priority
* order and place them in another collection.
*
@@ -49,12 +40,12 @@ import java.util.concurrent.locks.ReentrantLock;
* secondary key to break ties in primary priority values. For
* example, here is a class that applies first-in-first-out
* tie-breaking to comparable elements. To use it, you would insert a
- * <tt>new FIFOEntry(anEntry)</tt> instead of a plain entry object.
+ * {@code new FIFOEntry(anEntry)} instead of a plain entry object.
*
- * <pre>
- * class FIFOEntry&lt;E extends Comparable&lt;? super E&gt;&gt;
- * implements Comparable&lt;FIFOEntry&lt;E&gt;&gt; {
- * final static AtomicLong seq = new AtomicLong();
+ * <pre> {@code
+ * class FIFOEntry<E extends Comparable<? super E>>
+ * implements Comparable<FIFOEntry<E>> {
+ * static final AtomicLong seq = new AtomicLong(0);
* final long seqNum;
* final E entry;
* public FIFOEntry(E entry) {
@@ -62,13 +53,13 @@ import java.util.concurrent.locks.ReentrantLock;
* this.entry = entry;
* }
* public E getEntry() { return entry; }
- * public int compareTo(FIFOEntry&lt;E&gt; other) {
+ * public int compareTo(FIFOEntry<E> other) {
* int res = entry.compareTo(other.entry);
- * if (res == 0 &amp;&amp; other.entry != this.entry)
- * res = (seqNum &lt; other.seqNum ? -1 : 1);
+ * if (res == 0 && other.entry != this.entry)
+ * res = (seqNum < other.seqNum ? -1 : 1);
* return res;
* }
- * }</pre>
+ * }}</pre>
*
* @since 1.5
* @author Doug Lea
@@ -78,34 +69,102 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
implements BlockingQueue<E>, java.io.Serializable {
private static final long serialVersionUID = 5595510919245408276L;
- private final PriorityQueue<E> q;
- private final ReentrantLock lock = new ReentrantLock(true);
- private final Condition notEmpty = lock.newCondition();
+ /*
+ * The implementation uses an array-based binary heap, with public
+ * operations protected with a single lock. However, allocation
+ * during resizing uses a simple spinlock (used only while not
+ * holding main lock) in order to allow takes to operate
+ * concurrently with allocation. This avoids repeated
+ * postponement of waiting consumers and consequent element
+ * build-up. The need to back away from lock during allocation
+ * makes it impossible to simply wrap delegated
+ * java.util.PriorityQueue operations within a lock, as was done
+ * in a previous version of this class. To maintain
+ * interoperability, a plain PriorityQueue is still used during
+ * serialization, which maintains compatibility at the espense of
+ * transiently doubling overhead.
+ */
+
+ /**
+ * Default array capacity.
+ */
+ private static final int DEFAULT_INITIAL_CAPACITY = 11;
+
+ /**
+ * The maximum size of array to allocate.
+ * Some VMs reserve some header words in an array.
+ * Attempts to allocate larger arrays may result in
+ * OutOfMemoryError: Requested array size exceeds VM limit
+ */
+ private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
+
+ /**
+ * Priority queue represented as a balanced binary heap: the two
+ * children of queue[n] are queue[2*n+1] and queue[2*(n+1)]. The
+ * priority queue is ordered by comparator, or by the elements'
+ * natural ordering, if comparator is null: For each node n in the
+ * heap and each descendant d of n, n <= d. The element with the
+ * lowest value is in queue[0], assuming the queue is nonempty.
+ */
+ private transient Object[] queue;
+
+ /**
+ * The number of elements in the priority queue.
+ */
+ private transient int size;
+
+ /**
+ * The comparator, or null if priority queue uses elements'
+ * natural ordering.
+ */
+ private transient Comparator<? super E> comparator;
/**
- * Creates a <tt>PriorityBlockingQueue</tt> with the default
+ * Lock used for all public operations
+ */
+ private final ReentrantLock lock;
+
+ /**
+ * Condition for blocking when empty
+ */
+ private final Condition notEmpty;
+
+ /**
+ * Spinlock for allocation, acquired via CAS.
+ */
+ private transient volatile int allocationSpinLock;
+
+ /**
+ * A plain PriorityQueue used only for serialization,
+ * to maintain compatibility with previous versions
+ * of this class. Non-null only during serialization/deserialization.
+ */
+ private PriorityQueue q;
+
+ /**
+ * Creates a {@code PriorityBlockingQueue} with the default
* initial capacity (11) that orders its elements according to
* their {@linkplain Comparable natural ordering}.
*/
public PriorityBlockingQueue() {
- q = new PriorityQueue<E>();
+ this(DEFAULT_INITIAL_CAPACITY, null);
}
/**
- * Creates a <tt>PriorityBlockingQueue</tt> with the specified
+ * Creates a {@code PriorityBlockingQueue} with the specified
* initial capacity that orders its elements according to their
* {@linkplain Comparable natural ordering}.
*
* @param initialCapacity the initial capacity for this priority queue
- * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
+ * @throws IllegalArgumentException if {@code initialCapacity} is less
* than 1
*/
public PriorityBlockingQueue(int initialCapacity) {
- q = new PriorityQueue<E>(initialCapacity, null);
+ this(initialCapacity, null);
}
/**
- * Creates a <tt>PriorityBlockingQueue</tt> with the specified initial
+ * Creates a {@code PriorityBlockingQueue} with the specified initial
* capacity that orders its elements according to the specified
* comparator.
*
@@ -113,16 +172,21 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* @param comparator the comparator that will be used to order this
* priority queue. If {@code null}, the {@linkplain Comparable
* natural ordering} of the elements will be used.
- * @throws IllegalArgumentException if <tt>initialCapacity</tt> is less
+ * @throws IllegalArgumentException if {@code initialCapacity} is less
* than 1
*/
public PriorityBlockingQueue(int initialCapacity,
Comparator<? super E> comparator) {
- q = new PriorityQueue<E>(initialCapacity, comparator);
+ if (initialCapacity < 1)
+ throw new IllegalArgumentException();
+ this.lock = new ReentrantLock();
+ this.notEmpty = lock.newCondition();
+ this.comparator = comparator;
+ this.queue = new Object[initialCapacity];
}
/**
- * Creates a <tt>PriorityBlockingQueue</tt> containing the elements
+ * Creates a {@code PriorityBlockingQueue} containing the elements
* in the specified collection. If the specified collection is a
* {@link SortedSet} or a {@link PriorityQueue}, this
* priority queue will be ordered according to the same ordering.
@@ -138,14 +202,214 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* of its elements are null
*/
public PriorityBlockingQueue(Collection<? extends E> c) {
- q = new PriorityQueue<E>(c);
+ this.lock = new ReentrantLock();
+ this.notEmpty = lock.newCondition();
+ boolean heapify = true; // true if not known to be in heap order
+ boolean screen = true; // true if must screen for nulls
+ if (c instanceof SortedSet<?>) {
+ SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
+ this.comparator = (Comparator<? super E>) ss.comparator();
+ heapify = false;
+ }
+ else if (c instanceof PriorityBlockingQueue<?>) {
+ PriorityBlockingQueue<? extends E> pq =
+ (PriorityBlockingQueue<? extends E>) c;
+ this.comparator = (Comparator<? super E>) pq.comparator();
+ screen = false;
+ if (pq.getClass() == PriorityBlockingQueue.class) // exact match
+ heapify = false;
+ }
+ Object[] a = c.toArray();
+ int n = a.length;
+ // If c.toArray incorrectly doesn't return Object[], copy it.
+ if (a.getClass() != Object[].class)
+ a = Arrays.copyOf(a, n, Object[].class);
+ if (screen && (n == 1 || this.comparator != null)) {
+ for (int i = 0; i < n; ++i)
+ if (a[i] == null)
+ throw new NullPointerException();
+ }
+ this.queue = a;
+ this.size = n;
+ if (heapify)
+ heapify();
+ }
+
+ /**
+ * Tries to grow array to accommodate at least one more element
+ * (but normally expand by about 50%), giving up (allowing retry)
+ * on contention (which we expect to be rare). Call only while
+ * holding lock.
+ *
+ * @param array the heap array
+ * @param oldCap the length of the array
+ */
+ private void tryGrow(Object[] array, int oldCap) {
+ lock.unlock(); // must release and then re-acquire main lock
+ Object[] newArray = null;
+ if (allocationSpinLock == 0 &&
+ UNSAFE.compareAndSwapInt(this, allocationSpinLockOffset,
+ 0, 1)) {
+ try {
+ int newCap = oldCap + ((oldCap < 64) ?
+ (oldCap + 2) : // grow faster if small
+ (oldCap >> 1));
+ if (newCap - MAX_ARRAY_SIZE > 0) { // possible overflow
+ int minCap = oldCap + 1;
+ if (minCap < 0 || minCap > MAX_ARRAY_SIZE)
+ throw new OutOfMemoryError();
+ newCap = MAX_ARRAY_SIZE;
+ }
+ if (newCap > oldCap && queue == array)
+ newArray = new Object[newCap];
+ } finally {
+ allocationSpinLock = 0;
+ }
+ }
+ if (newArray == null) // back off if another thread is allocating
+ Thread.yield();
+ lock.lock();
+ if (newArray != null && queue == array) {
+ queue = newArray;
+ System.arraycopy(array, 0, newArray, 0, oldCap);
+ }
+ }
+
+ /**
+ * Mechanics for poll(). Call only while holding lock.
+ */
+ private E extract() {
+ E result;
+ int n = size - 1;
+ if (n < 0)
+ result = null;
+ else {
+ Object[] array = queue;
+ result = (E) array[0];
+ E x = (E) array[n];
+ array[n] = null;
+ Comparator<? super E> cmp = comparator;
+ if (cmp == null)
+ siftDownComparable(0, x, array, n);
+ else
+ siftDownUsingComparator(0, x, array, n, cmp);
+ size = n;
+ }
+ return result;
+ }
+
+ /**
+ * Inserts item x at position k, maintaining heap invariant by
+ * promoting x up the tree until it is greater than or equal to
+ * its parent, or is the root.
+ *
+ * To simplify and speed up coercions and comparisons. the
+ * Comparable and Comparator versions are separated into different
+ * methods that are otherwise identical. (Similarly for siftDown.)
+ * These methods are static, with heap state as arguments, to
+ * simplify use in light of possible comparator exceptions.
+ *
+ * @param k the position to fill
+ * @param x the item to insert
+ * @param array the heap array
+ */
+ private static <T> void siftUpComparable(int k, T x, Object[] array) {
+ Comparable<? super T> key = (Comparable<? super T>) x;
+ while (k > 0) {
+ int parent = (k - 1) >>> 1;
+ Object e = array[parent];
+ if (key.compareTo((T) e) >= 0)
+ break;
+ array[k] = e;
+ k = parent;
+ }
+ array[k] = key;
+ }
+
+ private static <T> void siftUpUsingComparator(int k, T x, Object[] array,
+ Comparator<? super T> cmp) {
+ while (k > 0) {
+ int parent = (k - 1) >>> 1;
+ Object e = array[parent];
+ if (cmp.compare(x, (T) e) >= 0)
+ break;
+ array[k] = e;
+ k = parent;
+ }
+ array[k] = x;
+ }
+
+ /**
+ * Inserts item x at position k, maintaining heap invariant by
+ * demoting x down the tree repeatedly until it is less than or
+ * equal to its children or is a leaf.
+ *
+ * @param k the position to fill
+ * @param x the item to insert
+ * @param array the heap array
+ * @param n heap size
+ */
+ private static <T> void siftDownComparable(int k, T x, Object[] array,
+ int n) {
+ Comparable<? super T> key = (Comparable<? super T>)x;
+ int half = n >>> 1; // loop while a non-leaf
+ while (k < half) {
+ int child = (k << 1) + 1; // assume left child is least
+ Object c = array[child];
+ int right = child + 1;
+ if (right < n &&
+ ((Comparable<? super T>) c).compareTo((T) array[right]) > 0)
+ c = array[child = right];
+ if (key.compareTo((T) c) <= 0)
+ break;
+ array[k] = c;
+ k = child;
+ }
+ array[k] = key;
+ }
+
+ private static <T> void siftDownUsingComparator(int k, T x, Object[] array,
+ int n,
+ Comparator<? super T> cmp) {
+ int half = n >>> 1;
+ while (k < half) {
+ int child = (k << 1) + 1;
+ Object c = array[child];
+ int right = child + 1;
+ if (right < n && cmp.compare((T) c, (T) array[right]) > 0)
+ c = array[child = right];
+ if (cmp.compare(x, (T) c) <= 0)
+ break;
+ array[k] = c;
+ k = child;
+ }
+ array[k] = x;
+ }
+
+ /**
+ * Establishes the heap invariant (described above) in the entire tree,
+ * assuming nothing about the order of the elements prior to the call.
+ */
+ private void heapify() {
+ Object[] array = queue;
+ int n = size;
+ int half = (n >>> 1) - 1;
+ Comparator<? super E> cmp = comparator;
+ if (cmp == null) {
+ for (int i = half; i >= 0; i--)
+ siftDownComparable(i, (E) array[i], array, n);
+ }
+ else {
+ for (int i = half; i >= 0; i--)
+ siftDownUsingComparator(i, (E) array[i], array, n, cmp);
+ }
}
/**
* Inserts the specified element into this priority queue.
*
* @param e the element to add
- * @return <tt>true</tt> (as specified by {@link Collection#add})
+ * @return {@code true} (as specified by {@link Collection#add})
* @throws ClassCastException if the specified element cannot be compared
* with elements currently in the priority queue according to the
* priority queue's ordering
@@ -157,30 +421,41 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
/**
* Inserts the specified element into this priority queue.
+ * As the queue is unbounded, this method will never return {@code false}.
*
* @param e the element to add
- * @return <tt>true</tt> (as specified by {@link Queue#offer})
+ * @return {@code true} (as specified by {@link Queue#offer})
* @throws ClassCastException if the specified element cannot be compared
* with elements currently in the priority queue according to the
* priority queue's ordering
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
+ if (e == null)
+ throw new NullPointerException();
final ReentrantLock lock = this.lock;
lock.lock();
+ int n, cap;
+ Object[] array;
+ while ((n = size) >= (cap = (array = queue).length))
+ tryGrow(array, cap);
try {
- boolean ok = q.offer(e);
- assert ok;
+ Comparator<? super E> cmp = comparator;
+ if (cmp == null)
+ siftUpComparable(n, e, array);
+ else
+ siftUpUsingComparator(n, e, array, cmp);
+ size = n + 1;
notEmpty.signal();
- return true;
} finally {
lock.unlock();
}
+ return true;
}
/**
- * Inserts the specified element into this priority queue. As the queue is
- * unbounded this method will never block.
+ * Inserts the specified element into this priority queue.
+ * As the queue is unbounded, this method will never block.
*
* @param e the element to add
* @throws ClassCastException if the specified element cannot be compared
@@ -193,13 +468,15 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
}
/**
- * Inserts the specified element into this priority queue. As the queue is
- * unbounded this method will never block.
+ * Inserts the specified element into this priority queue.
+ * As the queue is unbounded, this method will never block or
+ * return {@code false}.
*
* @param e the element to add
* @param timeout This parameter is ignored as the method never blocks
* @param unit This parameter is ignored as the method never blocks
- * @return <tt>true</tt>
+ * @return {@code true} (as specified by
+ * {@link BlockingQueue#offer BlockingQueue.offer})
* @throws ClassCastException if the specified element cannot be compared
* with elements currently in the priority queue according to the
* priority queue's ordering
@@ -212,97 +489,123 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
public E poll() {
final ReentrantLock lock = this.lock;
lock.lock();
+ E result;
try {
- return q.poll();
+ result = extract();
} finally {
lock.unlock();
}
+ return result;
}
public E take() throws InterruptedException {
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
+ E result;
try {
- try {
- while (q.size() == 0)
- notEmpty.await();
- } catch (InterruptedException ie) {
- notEmpty.signal(); // propagate to non-interrupted thread
- throw ie;
- }
- E x = q.poll();
- assert x != null;
- return x;
+ while ( (result = extract()) == null)
+ notEmpty.await();
} finally {
lock.unlock();
}
+ return result;
}
public E poll(long timeout, TimeUnit unit) throws InterruptedException {
long nanos = unit.toNanos(timeout);
final ReentrantLock lock = this.lock;
lock.lockInterruptibly();
+ E result;
try {
- for (;;) {
- E x = q.poll();
- if (x != null)
- return x;
- if (nanos <= 0)
- return null;
- try {
- nanos = notEmpty.awaitNanos(nanos);
- } catch (InterruptedException ie) {
- notEmpty.signal(); // propagate to non-interrupted thread
- throw ie;
- }
- }
+ while ( (result = extract()) == null && nanos > 0)
+ nanos = notEmpty.awaitNanos(nanos);
} finally {
lock.unlock();
}
+ return result;
}
public E peek() {
final ReentrantLock lock = this.lock;
lock.lock();
+ E result;
try {
- return q.peek();
+ result = size > 0 ? (E) queue[0] : null;
} finally {
lock.unlock();
}
+ return result;
}
/**
* Returns the comparator used to order the elements in this queue,
- * or <tt>null</tt> if this queue uses the {@linkplain Comparable
+ * or {@code null} if this queue uses the {@linkplain Comparable
* natural ordering} of its elements.
*
* @return the comparator used to order the elements in this queue,
- * or <tt>null</tt> if this queue uses the natural
+ * or {@code null} if this queue uses the natural
* ordering of its elements
*/
public Comparator<? super E> comparator() {
- return q.comparator();
+ return comparator;
}
public int size() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.size();
+ return size;
} finally {
lock.unlock();
}
}
/**
- * Always returns <tt>Integer.MAX_VALUE</tt> because
- * a <tt>PriorityBlockingQueue</tt> is not capacity constrained.
- * @return <tt>Integer.MAX_VALUE</tt>
+ * Always returns {@code Integer.MAX_VALUE} because
+ * a {@code PriorityBlockingQueue} is not capacity constrained.
+ * @return {@code Integer.MAX_VALUE} always
*/
public int remainingCapacity() {
return Integer.MAX_VALUE;
}
+ private int indexOf(Object o) {
+ if (o != null) {
+ Object[] array = queue;
+ int n = size;
+ for (int i = 0; i < n; i++)
+ if (o.equals(array[i]))
+ return i;
+ }
+ return -1;
+ }
+
+ /**
+ * Removes the ith element from queue.
+ */
+ private void removeAt(int i) {
+ Object[] array = queue;
+ int n = size - 1;
+ if (n == i) // removed last element
+ array[i] = null;
+ else {
+ E moved = (E) array[n];
+ array[n] = null;
+ Comparator<? super E> cmp = comparator;
+ if (cmp == null)
+ siftDownComparable(i, moved, array, n);
+ else
+ siftDownUsingComparator(i, moved, array, n, cmp);
+ if (array[i] == moved) {
+ if (cmp == null)
+ siftUpComparable(i, moved, array);
+ else
+ siftUpUsingComparator(i, moved, array, cmp);
+ }
+ }
+ size = n;
+ }
+
/**
* Removes a single instance of the specified element from this queue,
* if it is present. More formally, removes an element {@code e} such
@@ -312,13 +615,40 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* result of the call).
*
* @param o element to be removed from this queue, if present
- * @return <tt>true</tt> if this queue changed as a result of the call
+ * @return {@code true} if this queue changed as a result of the call
*/
public boolean remove(Object o) {
+ boolean removed = false;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.remove(o);
+ int i = indexOf(o);
+ if (i != -1) {
+ removeAt(i);
+ removed = true;
+ }
+ } finally {
+ lock.unlock();
+ }
+ return removed;
+ }
+
+
+ /**
+ * Identity-based version for use in Itr.remove
+ */
+ private void removeEQ(Object o) {
+ final ReentrantLock lock = this.lock;
+ lock.lock();
+ try {
+ Object[] array = queue;
+ int n = size;
+ for (int i = 0; i < n; i++) {
+ if (o == array[i]) {
+ removeAt(i);
+ break;
+ }
+ }
} finally {
lock.unlock();
}
@@ -330,16 +660,18 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* at least one element {@code e} such that {@code o.equals(e)}.
*
* @param o object to be checked for containment in this queue
- * @return <tt>true</tt> if this queue contains the specified element
+ * @return {@code true} if this queue contains the specified element
*/
public boolean contains(Object o) {
+ int index;
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.contains(o);
+ index = indexOf(o);
} finally {
lock.unlock();
}
+ return index != -1;
}
/**
@@ -359,7 +691,7 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.toArray();
+ return Arrays.copyOf(queue, size);
} finally {
lock.unlock();
}
@@ -370,7 +702,18 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.toString();
+ int n = size;
+ if (n == 0)
+ return "[]";
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ for (int i = 0; i < n; ++i) {
+ E e = (E)queue[i];
+ sb.append(e == this ? "(this Collection)" : e);
+ if (i != n - 1)
+ sb.append(',').append(' ');
+ }
+ return sb.append(']').toString();
} finally {
lock.unlock();
}
@@ -392,7 +735,7 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
try {
int n = 0;
E e;
- while ( (e = q.poll()) != null) {
+ while ( (e = extract()) != null) {
c.add(e);
++n;
}
@@ -420,7 +763,7 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
try {
int n = 0;
E e;
- while (n < maxElements && (e = q.poll()) != null) {
+ while (n < maxElements && (e = extract()) != null) {
c.add(e);
++n;
}
@@ -438,7 +781,11 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- q.clear();
+ Object[] array = queue;
+ int n = size;
+ size = 0;
+ for (int i = 0; i < n; i++)
+ array[i] = null;
} finally {
lock.unlock();
}
@@ -455,22 +802,22 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
* <p>If this queue fits in the specified array with room to spare
* (i.e., the array has more elements than this queue), the element in
* the array immediately following the end of the queue is set to
- * <tt>null</tt>.
+ * {@code null}.
*
* <p>Like the {@link #toArray()} method, this method acts as bridge between
* array-based and collection-based APIs. Further, this method allows
* precise control over the runtime type of the output array, and may,
* under certain circumstances, be used to save allocation costs.
*
- * <p>Suppose <tt>x</tt> is a queue known to contain only strings.
+ * <p>Suppose {@code x} is a queue known to contain only strings.
* The following code can be used to dump the queue into a newly
- * allocated array of <tt>String</tt>:
+ * allocated array of {@code String}:
*
* <pre>
* String[] y = x.toArray(new String[0]);</pre>
*
- * Note that <tt>toArray(new Object[0])</tt> is identical in function to
- * <tt>toArray()</tt>.
+ * Note that {@code toArray(new Object[0])} is identical in function to
+ * {@code toArray()}.
*
* @param a the array into which the elements of the queue are to
* be stored, if it is big enough; otherwise, a new array of the
@@ -485,7 +832,14 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
final ReentrantLock lock = this.lock;
lock.lock();
try {
- return q.toArray(a);
+ int n = size;
+ if (a.length < n)
+ // Make a new array of a's runtime type, but my contents:
+ return (T[]) Arrays.copyOf(queue, size, a.getClass());
+ System.arraycopy(queue, 0, a, 0, n);
+ if (a.length > n)
+ a[n] = null;
+ return a;
} finally {
lock.unlock();
}
@@ -494,8 +848,9 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
/**
* Returns an iterator over the elements in this queue. The
* iterator does not return the elements in any particular order.
- * The returned <tt>Iterator</tt> is a "weakly consistent"
- * iterator that will never throw {@link
+ *
+ * <p>The returned iterator is a "weakly consistent" iterator that
+ * will never throw {@link java.util.ConcurrentModificationException
* ConcurrentModificationException}, and guarantees to traverse
* elements as they existed upon construction of the iterator, and
* may (but is not guaranteed to) reflect any modifications
@@ -510,7 +865,7 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
/**
* Snapshot iterator that works off copy of underlying q array.
*/
- private class Itr implements Iterator<E> {
+ final class Itr implements Iterator<E> {
final Object[] array; // Array of all elements
int cursor; // index of next element to return;
int lastRet; // index of last element, or -1 if no such
@@ -534,39 +889,65 @@ public class PriorityBlockingQueue<E> extends AbstractQueue<E>
public void remove() {
if (lastRet < 0)
throw new IllegalStateException();
- Object x = array[lastRet];
+ removeEQ(array[lastRet]);
lastRet = -1;
- // Traverse underlying queue to find == element,
- // not just a .equals element.
- lock.lock();
- try {
- for (Iterator it = q.iterator(); it.hasNext(); ) {
- if (it.next() == x) {
- it.remove();
- return;
- }
- }
- } finally {
- lock.unlock();
- }
}
}
/**
- * Saves the state to a stream (that is, serializes it). This
- * merely wraps default serialization within lock. The
- * serialization strategy for items is left to underlying
- * Queue. Note that locking is not needed on deserialization, so
- * readObject is not defined, just relying on default.
+ * Saves the state to a stream (that is, serializes it). For
+ * compatibility with previous version of this class,
+ * elements are first copied to a java.util.PriorityQueue,
+ * which is then serialized.
*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
lock.lock();
try {
+ int n = size; // avoid zero capacity argument
+ q = new PriorityQueue<E>(n == 0 ? 1 : n, comparator);
+ q.addAll(this);
s.defaultWriteObject();
} finally {
+ q = null;
lock.unlock();
}
}
+ /**
+ * Reconstitutes the {@code PriorityBlockingQueue} instance from a stream
+ * (that is, deserializes it).
+ *
+ * @param s the stream
+ */
+ private void readObject(java.io.ObjectInputStream s)
+ throws java.io.IOException, ClassNotFoundException {
+ try {
+ s.defaultReadObject();
+ this.queue = new Object[q.size()];
+ comparator = q.comparator();
+ addAll(q);
+ } finally {
+ q = null;
+ }
+ }
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long allocationSpinLockOffset =
+ objectFieldOffset(UNSAFE, "allocationSpinLock",
+ PriorityBlockingQueue.class);
+
+ static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
+ String field, Class<?> klazz) {
+ try {
+ return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
+ } catch (NoSuchFieldException e) {
+ // Convert Exception to corresponding Error
+ NoSuchFieldError error = new NoSuchFieldError(field);
+ error.initCause(e);
+ throw error;
+ }
+ }
+
}
diff --git a/luni/src/main/java/java/util/concurrent/ScheduledExecutorService.java b/luni/src/main/java/java/util/concurrent/ScheduledExecutorService.java
index 2eae4b8..6cb4e27 100644
--- a/luni/src/main/java/java/util/concurrent/ScheduledExecutorService.java
+++ b/luni/src/main/java/java/util/concurrent/ScheduledExecutorService.java
@@ -5,6 +5,8 @@
*/
package java.util.concurrent;
+import java.util.concurrent.atomic.*;
+import java.util.*;
/**
* An {@link ExecutorService} that can schedule commands to run after a given
@@ -41,24 +43,23 @@ package java.util.concurrent;
* Here is a class with a method that sets up a ScheduledExecutorService
* to beep every ten seconds for an hour:
*
- * <pre>
+ * <pre> {@code
* import static java.util.concurrent.TimeUnit.*;
* class BeeperControl {
- * private final ScheduledExecutorService scheduler =
- * Executors.newScheduledThreadPool(1);
+ * private final ScheduledExecutorService scheduler =
+ * Executors.newScheduledThreadPool(1);
*
- * public void beepForAnHour() {
- * final Runnable beeper = new Runnable() {
- * public void run() { System.out.println("beep"); }
- * };
- * final ScheduledFuture&lt;?&gt; beeperHandle =
- * scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
- * scheduler.schedule(new Runnable() {
- * public void run() { beeperHandle.cancel(true); }
- * }, 60 * 60, SECONDS);
- * }
- * }
- * </pre>
+ * public void beepForAnHour() {
+ * final Runnable beeper = new Runnable() {
+ * public void run() { System.out.println("beep"); }
+ * };
+ * final ScheduledFuture<?> beeperHandle =
+ * scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
+ * scheduler.schedule(new Runnable() {
+ * public void run() { beeperHandle.cancel(true); }
+ * }, 60 * 60, SECONDS);
+ * }
+ * }}</pre>
*
* @since 1.5
* @author Doug Lea
diff --git a/luni/src/main/java/java/util/concurrent/ScheduledThreadPoolExecutor.java b/luni/src/main/java/java/util/concurrent/ScheduledThreadPoolExecutor.java
index 6b3a90c..c2eaedf 100644
--- a/luni/src/main/java/java/util/concurrent/ScheduledThreadPoolExecutor.java
+++ b/luni/src/main/java/java/util/concurrent/ScheduledThreadPoolExecutor.java
@@ -5,16 +5,13 @@
*/
package java.util.concurrent;
+import java.util.concurrent.atomic.*;
+import java.util.concurrent.locks.*;
+import java.util.*;
-import java.util.AbstractQueue;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+// BEGIN android-note
+// Omit class-level docs on setRemoveOnCancelPolicy()
+// END android-note
/**
* A {@link ThreadPoolExecutor} that can additionally schedule
@@ -37,8 +34,8 @@ import java.util.concurrent.locks.ReentrantLock;
* may also cause unbounded retention of cancelled tasks.
*
* <p>Successive executions of a task scheduled via
- * <code>scheduleAtFixedRate</code> or
- * <code>scheduleWithFixedDelay</code> do not overlap. While different
+ * {@code scheduleAtFixedRate} or
+ * {@code scheduleWithFixedDelay} do not overlap. While different
* executions may be performed by different threads, the effects of
* prior executions <a
* href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
@@ -335,8 +332,12 @@ public class ScheduledThreadPoolExecutor
getExecuteExistingDelayedTasksAfterShutdownPolicy();
boolean keepPeriodic =
getContinueExistingPeriodicTasksAfterShutdownPolicy();
- if (!keepDelayed && !keepPeriodic)
+ if (!keepDelayed && !keepPeriodic) {
+ for (Object e : q.toArray())
+ if (e instanceof RunnableScheduledFuture<?>)
+ ((RunnableScheduledFuture<?>) e).cancel(false);
q.clear();
+ }
else {
// Traverse snapshot to avoid iterator exceptions
for (Object e : q.toArray()) {
@@ -411,7 +412,7 @@ public class ScheduledThreadPoolExecutor
* @throws NullPointerException if {@code threadFactory} is null
*/
public ScheduledThreadPoolExecutor(int corePoolSize,
- ThreadFactory threadFactory) {
+ ThreadFactory threadFactory) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), threadFactory);
}
@@ -428,7 +429,7 @@ public class ScheduledThreadPoolExecutor
* @throws NullPointerException if {@code handler} is null
*/
public ScheduledThreadPoolExecutor(int corePoolSize,
- RejectedExecutionHandler handler) {
+ RejectedExecutionHandler handler) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), handler);
}
@@ -448,8 +449,8 @@ public class ScheduledThreadPoolExecutor
* {@code handler} is null
*/
public ScheduledThreadPoolExecutor(int corePoolSize,
- ThreadFactory threadFactory,
- RejectedExecutionHandler handler) {
+ ThreadFactory threadFactory,
+ RejectedExecutionHandler handler) {
super(corePoolSize, Integer.MAX_VALUE, 0, TimeUnit.NANOSECONDS,
new DelayedWorkQueue(), threadFactory, handler);
}
@@ -701,7 +702,7 @@ public class ScheduledThreadPoolExecutor
*
* @return {@code true} if cancelled tasks are immediately removed
* from the queue
- * @see #setRemoveOnCancelPolicy(boolean)
+ * @see #setRemoveOnCancelPolicy
* @since 1.7
*/
/*public*/ boolean getRemoveOnCancelPolicy() { // android-changed
diff --git a/luni/src/main/java/java/util/concurrent/Semaphore.java b/luni/src/main/java/java/util/concurrent/Semaphore.java
index 9cf94f5..62dea1a 100644
--- a/luni/src/main/java/java/util/concurrent/Semaphore.java
+++ b/luni/src/main/java/java/util/concurrent/Semaphore.java
@@ -5,10 +5,9 @@
*/
package java.util.concurrent;
-
-import java.util.Collection;
-import java.util.concurrent.locks.AbstractQueuedSynchronizer;
-import java.util.concurrent.locks.Lock;
+import java.util.*;
+import java.util.concurrent.locks.*;
+import java.util.concurrent.atomic.*;
/**
* A counting semaphore. Conceptually, a semaphore maintains a set of
@@ -163,8 +162,11 @@ public class Semaphore implements java.io.Serializable {
protected final boolean tryReleaseShared(int releases) {
for (;;) {
- int p = getState();
- if (compareAndSetState(p, p + releases))
+ int current = getState();
+ int next = current + releases;
+ if (next < current) // overflow
+ throw new Error("Maximum permit count exceeded");
+ if (compareAndSetState(current, next))
return true;
}
}
@@ -173,6 +175,8 @@ public class Semaphore implements java.io.Serializable {
for (;;) {
int current = getState();
int next = current - reductions;
+ if (next > current) // underflow
+ throw new Error("Permit count underflow");
if (compareAndSetState(current, next))
return;
}
@@ -190,7 +194,7 @@ public class Semaphore implements java.io.Serializable {
/**
* NonFair version
*/
- final static class NonfairSync extends Sync {
+ static final class NonfairSync extends Sync {
private static final long serialVersionUID = -2694183684443567898L;
NonfairSync(int permits) {
@@ -205,7 +209,7 @@ public class Semaphore implements java.io.Serializable {
/**
* Fair version
*/
- final static class FairSync extends Sync {
+ static final class FairSync extends Sync {
private static final long serialVersionUID = 2014338818796000944L;
FairSync(int permits) {
@@ -249,7 +253,7 @@ public class Semaphore implements java.io.Serializable {
* else {@code false}
*/
public Semaphore(int permits, boolean fair) {
- sync = (fair)? new FairSync(permits) : new NonfairSync(permits);
+ sync = fair ? new FairSync(permits) : new NonfairSync(permits);
}
/**
diff --git a/luni/src/main/java/java/util/concurrent/SynchronousQueue.java b/luni/src/main/java/java/util/concurrent/SynchronousQueue.java
index 153d449..4bd2360 100644
--- a/luni/src/main/java/java/util/concurrent/SynchronousQueue.java
+++ b/luni/src/main/java/java/util/concurrent/SynchronousQueue.java
@@ -6,14 +6,10 @@
*/
package java.util.concurrent;
-
-import java.util.AbstractQueue;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
-import java.util.concurrent.locks.LockSupport;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
+import java.util.concurrent.atomic.*;
+import java.util.*;
+import libcore.base.EmptyArray;
// BEGIN android-note
// removed link to collections framework docs
@@ -139,7 +135,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
/**
* Shared internal API for dual stacks and queues.
*/
- static abstract class Transferer {
+ abstract static class Transferer {
/**
* Performs a put or take.
*
@@ -166,7 +162,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* seems not to vary with number of CPUs (beyond 2) so is just
* a constant.
*/
- static final int maxTimedSpins = (NCPUS < 2)? 0 : 32;
+ static final int maxTimedSpins = (NCPUS < 2) ? 0 : 32;
/**
* The number of times to spin before blocking in untimed waits.
@@ -217,19 +213,11 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
this.item = item;
}
- static final AtomicReferenceFieldUpdater<SNode, SNode>
- nextUpdater = AtomicReferenceFieldUpdater.newUpdater
- (SNode.class, SNode.class, "next");
-
boolean casNext(SNode cmp, SNode val) {
- return (cmp == next &&
- nextUpdater.compareAndSet(this, cmp, val));
+ return cmp == next &&
+ UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
}
- static final AtomicReferenceFieldUpdater<SNode, SNode>
- matchUpdater = AtomicReferenceFieldUpdater.newUpdater
- (SNode.class, SNode.class, "match");
-
/**
* Tries to match node s to this node, if so, waking up thread.
* Fulfillers call tryMatch to identify their waiters.
@@ -240,7 +228,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
*/
boolean tryMatch(SNode s) {
if (match == null &&
- matchUpdater.compareAndSet(this, null, s)) {
+ UNSAFE.compareAndSwapObject(this, matchOffset, null, s)) {
Thread w = waiter;
if (w != null) { // waiters need at most one unpark
waiter = null;
@@ -255,23 +243,28 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* Tries to cancel a wait by matching node to itself.
*/
void tryCancel() {
- matchUpdater.compareAndSet(this, null, this);
+ UNSAFE.compareAndSwapObject(this, matchOffset, null, this);
}
boolean isCancelled() {
return match == this;
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long nextOffset =
+ objectFieldOffset(UNSAFE, "next", SNode.class);
+ private static final long matchOffset =
+ objectFieldOffset(UNSAFE, "match", SNode.class);
+
}
/** The head (top) of the stack */
volatile SNode head;
- static final AtomicReferenceFieldUpdater<TransferStack, SNode>
- headUpdater = AtomicReferenceFieldUpdater.newUpdater
- (TransferStack.class, SNode.class, "head");
-
boolean casHead(SNode h, SNode nh) {
- return h == head && headUpdater.compareAndSet(this, h, nh);
+ return h == head &&
+ UNSAFE.compareAndSwapObject(this, headOffset, h, nh);
}
/**
@@ -314,7 +307,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
*/
SNode s = null; // constructed/reused as needed
- int mode = (e == null)? REQUEST : DATA;
+ int mode = (e == null) ? REQUEST : DATA;
for (;;) {
SNode h = head;
@@ -332,7 +325,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
}
if ((h = head) != null && h.next == s)
casHead(h, s.next); // help s's fulfiller
- return mode == REQUEST? m.item : s.item;
+ return (mode == REQUEST) ? m.item : s.item;
}
} else if (!isFulfilling(h.mode)) { // try to fulfill
if (h.isCancelled()) // already cancelled
@@ -348,7 +341,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
SNode mn = m.next;
if (m.tryMatch(s)) {
casHead(s, mn); // pop both s and m
- return (mode == REQUEST)? m.item : s.item;
+ return (mode == REQUEST) ? m.item : s.item;
} else // lost match
s.casNext(m, mn); // help unlink
}
@@ -399,11 +392,11 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* and don't wait at all, so are trapped in transfer
* method rather than calling awaitFulfill.
*/
- long lastTime = (timed)? System.nanoTime() : 0;
+ long lastTime = timed ? System.nanoTime() : 0;
Thread w = Thread.currentThread();
SNode h = head;
- int spins = (shouldSpin(s)?
- (timed? maxTimedSpins : maxUntimedSpins) : 0);
+ int spins = (shouldSpin(s) ?
+ (timed ? maxTimedSpins : maxUntimedSpins) : 0);
for (;;) {
if (w.isInterrupted())
s.tryCancel();
@@ -420,7 +413,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
}
}
if (spins > 0)
- spins = shouldSpin(s)? (spins-1) : 0;
+ spins = shouldSpin(s) ? (spins-1) : 0;
else if (s.waiter == null)
s.waiter = w; // establish waiter so can park next iter
else if (!timed)
@@ -475,6 +468,12 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
p = n;
}
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long headOffset =
+ objectFieldOffset(UNSAFE, "head", TransferStack.class);
+
}
/** Dual Queue */
@@ -500,29 +499,21 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
this.isData = isData;
}
- static final AtomicReferenceFieldUpdater<QNode, QNode>
- nextUpdater = AtomicReferenceFieldUpdater.newUpdater
- (QNode.class, QNode.class, "next");
-
boolean casNext(QNode cmp, QNode val) {
- return (next == cmp &&
- nextUpdater.compareAndSet(this, cmp, val));
+ return next == cmp &&
+ UNSAFE.compareAndSwapObject(this, nextOffset, cmp, val);
}
- static final AtomicReferenceFieldUpdater<QNode, Object>
- itemUpdater = AtomicReferenceFieldUpdater.newUpdater
- (QNode.class, Object.class, "item");
-
boolean casItem(Object cmp, Object val) {
- return (item == cmp &&
- itemUpdater.compareAndSet(this, cmp, val));
+ return item == cmp &&
+ UNSAFE.compareAndSwapObject(this, itemOffset, cmp, val);
}
/**
* Tries to cancel by CAS'ing ref to this as item.
*/
void tryCancel(Object cmp) {
- itemUpdater.compareAndSet(this, cmp, this);
+ UNSAFE.compareAndSwapObject(this, itemOffset, cmp, this);
}
boolean isCancelled() {
@@ -537,6 +528,13 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
boolean isOffList() {
return next == this;
}
+
+ // Unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long nextOffset =
+ objectFieldOffset(UNSAFE, "next", QNode.class);
+ private static final long itemOffset =
+ objectFieldOffset(UNSAFE, "item", QNode.class);
}
/** Head of queue */
@@ -556,41 +554,30 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
tail = h;
}
- static final AtomicReferenceFieldUpdater<TransferQueue, QNode>
- headUpdater = AtomicReferenceFieldUpdater.newUpdater
- (TransferQueue.class, QNode.class, "head");
-
/**
* Tries to cas nh as new head; if successful, unlink
* old head's next node to avoid garbage retention.
*/
void advanceHead(QNode h, QNode nh) {
- if (h == head && headUpdater.compareAndSet(this, h, nh))
+ if (h == head &&
+ UNSAFE.compareAndSwapObject(this, headOffset, h, nh))
h.next = h; // forget old next
}
- static final AtomicReferenceFieldUpdater<TransferQueue, QNode>
- tailUpdater = AtomicReferenceFieldUpdater.newUpdater
- (TransferQueue.class, QNode.class, "tail");
-
/**
* Tries to cas nt as new tail.
*/
void advanceTail(QNode t, QNode nt) {
if (tail == t)
- tailUpdater.compareAndSet(this, t, nt);
+ UNSAFE.compareAndSwapObject(this, tailOffset, t, nt);
}
- static final AtomicReferenceFieldUpdater<TransferQueue, QNode>
- cleanMeUpdater = AtomicReferenceFieldUpdater.newUpdater
- (TransferQueue.class, QNode.class, "cleanMe");
-
/**
* Tries to CAS cleanMe slot.
*/
boolean casCleanMe(QNode cmp, QNode val) {
- return (cleanMe == cmp &&
- cleanMeUpdater.compareAndSet(this, cmp, val));
+ return cleanMe == cmp &&
+ UNSAFE.compareAndSwapObject(this, cleanMeOffset, cmp, val);
}
/**
@@ -659,7 +646,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
s.item = s;
s.waiter = null;
}
- return (x != null)? x : e;
+ return (x != null) ? x : e;
} else { // complementary-mode
QNode m = h.next; // node to fulfill
@@ -676,7 +663,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
advanceHead(h, m); // successfully fulfilled
LockSupport.unpark(m.waiter);
- return (x != null)? x : e;
+ return (x != null) ? x : e;
}
}
}
@@ -692,10 +679,10 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
*/
Object awaitFulfill(QNode s, Object e, boolean timed, long nanos) {
/* Same idea as TransferStack.awaitFulfill */
- long lastTime = (timed)? System.nanoTime() : 0;
+ long lastTime = timed ? System.nanoTime() : 0;
Thread w = Thread.currentThread();
int spins = ((head.next == s) ?
- (timed? maxTimedSpins : maxUntimedSpins) : 0);
+ (timed ? maxTimedSpins : maxUntimedSpins) : 0);
for (;;) {
if (w.isInterrupted())
s.tryCancel(e);
@@ -775,6 +762,16 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
return; // Postpone cleaning s
}
}
+
+ // unsafe mechanics
+ private static final sun.misc.Unsafe UNSAFE = sun.misc.Unsafe.getUnsafe();
+ private static final long headOffset =
+ objectFieldOffset(UNSAFE, "head", TransferQueue.class);
+ private static final long tailOffset =
+ objectFieldOffset(UNSAFE, "tail", TransferQueue.class);
+ private static final long cleanMeOffset =
+ objectFieldOffset(UNSAFE, "cleanMe", TransferQueue.class);
+
}
/**
@@ -800,7 +797,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* access; otherwise the order is unspecified.
*/
public SynchronousQueue(boolean fair) {
- transferer = (fair)? new TransferQueue() : new TransferStack();
+ transferer = fair ? new TransferQueue() : new TransferStack();
}
/**
@@ -1011,7 +1008,7 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
* @return a zero-length array
*/
public Object[] toArray() {
- return new Object[0];
+ return EmptyArray.OBJECT; // android-changed
}
/**
@@ -1117,4 +1114,17 @@ public class SynchronousQueue<E> extends AbstractQueue<E>
transferer = new TransferStack();
}
+ // Unsafe mechanics
+ static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
+ String field, Class<?> klazz) {
+ try {
+ return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
+ } catch (NoSuchFieldException e) {
+ // Convert Exception to corresponding Error
+ NoSuchFieldError error = new NoSuchFieldError(field);
+ error.initCause(e);
+ throw error;
+ }
+ }
+
}
diff --git a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
index 7efa78b..da2c4c5 100644
--- a/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
+++ b/luni/src/main/java/java/util/concurrent/ThreadPoolExecutor.java
@@ -5,16 +5,9 @@
*/
package java.util.concurrent;
-
-import java.util.ArrayList;
-import java.util.ConcurrentModificationException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.locks.AbstractQueuedSynchronizer;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.ReentrantLock;
+import java.util.concurrent.locks.*;
+import java.util.concurrent.atomic.*;
+import java.util.*;
/**
* An {@link ExecutorService} that executes each submitted task using
@@ -1419,16 +1412,8 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
* Invokes {@code shutdown} when this executor is no longer
* referenced and it has no threads.
*/
- @Override protected void finalize() {
- try {
- shutdown();
- } finally {
- try {
- super.finalize();
- } catch (Throwable t) {
- throw new AssertionError(t);
- }
- }
+ protected void finalize() {
+ shutdown();
}
/**
@@ -1827,6 +1812,43 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
}
}
+ /**
+ * Returns a string identifying this pool, as well as its state,
+ * including indications of run state and estimated worker and
+ * task counts.
+ *
+ * @return a string identifying this pool, as well as its state
+ */
+ public String toString() {
+ long ncompleted;
+ int nworkers, nactive;
+ final ReentrantLock mainLock = this.mainLock;
+ mainLock.lock();
+ try {
+ ncompleted = completedTaskCount;
+ nactive = 0;
+ nworkers = workers.size();
+ for (Worker w : workers) {
+ ncompleted += w.completedTasks;
+ if (w.isLocked())
+ ++nactive;
+ }
+ } finally {
+ mainLock.unlock();
+ }
+ int c = ctl.get();
+ String rs = (runStateLessThan(c, SHUTDOWN) ? "Running" :
+ (runStateAtLeast(c, TERMINATED) ? "Terminated" :
+ "Shutting down"));
+ return super.toString() +
+ "[" + rs +
+ ", pool size = " + nworkers +
+ ", active threads = " + nactive +
+ ", queued tasks = " + workQueue.size() +
+ ", completed tasks = " + ncompleted +
+ "]";
+ }
+
/* Extension hooks */
/**
@@ -1947,20 +1969,9 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
* @throws RejectedExecutionException always.
*/
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
- // BEGIN android-changed
- // provide diagnostic messaging for a common exception
-
- // a message is helpful even if it isn't created atomically
- int queueSize = e.getQueue().size();
- int remainingCapacity = e.getQueue().remainingCapacity();
- String message = "pool=" + e.getPoolSize() + "/" + e.maximumPoolSize
- + ", queue=" + queueSize;
- if (remainingCapacity != Integer.MAX_VALUE) {
- message += "/" + (queueSize + remainingCapacity);
- }
- throw new RejectedExecutionException(message);
-
- // END android-changed
+ throw new RejectedExecutionException("Task " + r.toString() +
+ " rejected from " +
+ e.toString());
}
}
diff --git a/luni/src/main/java/java/util/concurrent/TimeUnit.java b/luni/src/main/java/java/util/concurrent/TimeUnit.java
index ae78fda..b2e3060 100644
--- a/luni/src/main/java/java/util/concurrent/TimeUnit.java
+++ b/luni/src/main/java/java/util/concurrent/TimeUnit.java
@@ -24,12 +24,12 @@ package java.util.concurrent;
* java.util.concurrent.locks.Lock lock} is not available:
*
* <pre> Lock lock = ...;
- * if ( lock.tryLock(50L, TimeUnit.MILLISECONDS) ) ...
+ * if (lock.tryLock(50L, TimeUnit.MILLISECONDS)) ...
* </pre>
* while this code will timeout in 50 seconds:
* <pre>
* Lock lock = ...;
- * if ( lock.tryLock(50L, TimeUnit.SECONDS) ) ...
+ * if (lock.tryLock(50L, TimeUnit.SECONDS)) ...
* </pre>
*
* Note however, that there is no guarantee that a particular timeout
@@ -262,7 +262,8 @@ public enum TimeUnit {
abstract int excessNanos(long d, long m);
/**
- * Performs a timed <tt>Object.wait</tt> using this time unit.
+ * Performs a timed {@link Object#wait(long, int) Object.wait}
+ * using this time unit.
* This is a convenience method that converts timeout arguments
* into the form required by the <tt>Object.wait</tt> method.
*
@@ -270,21 +271,22 @@ public enum TimeUnit {
* method (see {@link BlockingQueue#poll BlockingQueue.poll})
* using:
*
- * <pre> public synchronized Object poll(long timeout, TimeUnit unit) throws InterruptedException {
- * while (empty) {
- * unit.timedWait(this, timeout);
- * ...
- * }
- * }</pre>
+ * <pre> {@code
+ * public synchronized Object poll(long timeout, TimeUnit unit)
+ * throws InterruptedException {
+ * while (empty) {
+ * unit.timedWait(this, timeout);
+ * ...
+ * }
+ * }}</pre>
*
* @param obj the object to wait on
* @param timeout the maximum time to wait. If less than
* or equal to zero, do not wait at all.
- * @throws InterruptedException if interrupted while waiting.
- * @see Object#wait(long, int)
+ * @throws InterruptedException if interrupted while waiting
*/
public void timedWait(Object obj, long timeout)
- throws InterruptedException {
+ throws InterruptedException {
if (timeout > 0) {
long ms = toMillis(timeout);
int ns = excessNanos(timeout, ms);
@@ -293,17 +295,18 @@ public enum TimeUnit {
}
/**
- * Performs a timed <tt>Thread.join</tt> using this time unit.
+ * Performs a timed {@link Thread#join(long, int) Thread.join}
+ * using this time unit.
* This is a convenience method that converts time arguments into the
* form required by the <tt>Thread.join</tt> method.
+ *
* @param thread the thread to wait for
* @param timeout the maximum time to wait. If less than
* or equal to zero, do not wait at all.
- * @throws InterruptedException if interrupted while waiting.
- * @see Thread#join(long, int)
+ * @throws InterruptedException if interrupted while waiting
*/
public void timedJoin(Thread thread, long timeout)
- throws InterruptedException {
+ throws InterruptedException {
if (timeout > 0) {
long ms = toMillis(timeout);
int ns = excessNanos(timeout, ms);
@@ -312,13 +315,14 @@ public enum TimeUnit {
}
/**
- * Performs a <tt>Thread.sleep</tt> using this unit.
+ * Performs a {@link Thread#sleep(long, int) Thread.sleep} using
+ * this time unit.
* This is a convenience method that converts time arguments into the
* form required by the <tt>Thread.sleep</tt> method.
+ *
* @param timeout the minimum time to sleep. If less than
* or equal to zero, do not sleep at all.
- * @throws InterruptedException if interrupted while sleeping.
- * @see Thread#sleep
+ * @throws InterruptedException if interrupted while sleeping
*/
public void sleep(long timeout) throws InterruptedException {
if (timeout > 0) {
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java
index 30fa483..6dcdfd0 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerArray.java
@@ -5,8 +5,8 @@
*/
package java.util.concurrent.atomic;
-
import sun.misc.Unsafe;
+import java.util.*;
/**
* An {@code int} array in which elements may be updated atomically.
@@ -21,9 +21,16 @@ public class AtomicIntegerArray implements java.io.Serializable {
private static final Unsafe unsafe = UnsafeAccess.THE_ONE; // android-changed
private static final int base = unsafe.arrayBaseOffset(int[].class);
- private static final int scale = unsafe.arrayIndexScale(int[].class);
+ private static final int shift;
private final int[] array;
+ static {
+ int scale = unsafe.arrayIndexScale(int[].class);
+ if ((scale & (scale - 1)) != 0)
+ throw new Error("data type scale not a power of two");
+ shift = 31 - Integer.numberOfLeadingZeros(scale);
+ }
+
private long checkedByteOffset(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
@@ -32,7 +39,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
}
private static long byteOffset(int i) {
- return base + (long) i * scale;
+ return ((long) i << shift) + base;
}
/**
@@ -241,7 +248,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
b.append(getRaw(byteOffset(i)));
if (i == iMax)
return b.append(']').toString();
- b.append(", ");
+ b.append(',').append(' ');
}
}
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
index 11b1124..a13c920 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.java
@@ -6,11 +6,9 @@
package java.util.concurrent.atomic;
-import dalvik.system.VMStack;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
+import dalvik.system.VMStack; // android-added
import sun.misc.Unsafe;
+import java.lang.reflect.*;
/**
* A reflection-based utility that enables atomic updates to
@@ -30,7 +28,7 @@ import sun.misc.Unsafe;
* @author Doug Lea
* @param <T> The type of the object holding the updatable field
*/
-public abstract class AtomicIntegerFieldUpdater<T> {
+public abstract class AtomicIntegerFieldUpdater<T> {
/**
* Creates and returns an updater for objects with the given field.
* The Class argument is needed to check that reflective types and
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicLong.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicLong.java
index e1f5dc7..12d6cd1 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicLong.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicLong.java
@@ -32,10 +32,8 @@ public class AtomicLong extends Number implements java.io.Serializable {
* compareAndSwap for longs. While the Unsafe.compareAndSwapLong
* method works in either case, some constructions should be
* handled at Java level to avoid locking user-visible locks.
- *
- * Initialised in the static block.
*/
- static final boolean VM_SUPPORTS_LONG_CAS;
+ static final boolean VM_SUPPORTS_LONG_CAS = VMSupportsCS8();
/**
* Returns whether underlying JVM supports lockless CompareAndSet
@@ -48,15 +46,6 @@ public class AtomicLong extends Number implements java.io.Serializable {
valueOffset = unsafe.objectFieldOffset
(AtomicLong.class.getDeclaredField("value"));
} catch (Exception ex) { throw new Error(ex); }
-
- boolean longCASSupport;
- try {
- longCASSupport = VMSupportsCS8();
- } catch (UnsatisfiedLinkError e) {
- // assume there's support if the native isn't provided by the VM
- longCASSupport = true;
- }
- VM_SUPPORTS_LONG_CAS = longCASSupport;
}
private volatile long value;
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java
index 7e91ae7..9e2d25f 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicLongArray.java
@@ -5,8 +5,8 @@
*/
package java.util.concurrent.atomic;
-
import sun.misc.Unsafe;
+import java.util.*;
/**
* A {@code long} array in which elements may be updated atomically.
@@ -20,9 +20,16 @@ public class AtomicLongArray implements java.io.Serializable {
private static final Unsafe unsafe = UnsafeAccess.THE_ONE; // android-changed
private static final int base = unsafe.arrayBaseOffset(long[].class);
- private static final int scale = unsafe.arrayIndexScale(long[].class);
+ private static final int shift;
private final long[] array;
+ static {
+ int scale = unsafe.arrayIndexScale(long[].class);
+ if ((scale & (scale - 1)) != 0)
+ throw new Error("data type scale not a power of two");
+ shift = 31 - Integer.numberOfLeadingZeros(scale);
+ }
+
private long checkedByteOffset(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
@@ -31,7 +38,7 @@ public class AtomicLongArray implements java.io.Serializable {
}
private static long byteOffset(int i) {
- return base + (long) i * scale;
+ return ((long) i << shift) + base;
}
/**
@@ -241,7 +248,7 @@ public class AtomicLongArray implements java.io.Serializable {
b.append(getRaw(byteOffset(i)));
if (i == iMax)
return b.append(']').toString();
- b.append(", ");
+ b.append(',').append(' ');
}
}
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
index 81802af..3d6e5d6 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicLongFieldUpdater.java
@@ -6,11 +6,9 @@
package java.util.concurrent.atomic;
-import dalvik.system.VMStack;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
+import dalvik.system.VMStack; // android-added
import sun.misc.Unsafe;
+import java.lang.reflect.*;
/**
* A reflection-based utility that enables atomic updates to
@@ -30,7 +28,7 @@ import sun.misc.Unsafe;
* @author Doug Lea
* @param <T> The type of the object holding the updatable field
*/
-public abstract class AtomicLongFieldUpdater<T> {
+public abstract class AtomicLongFieldUpdater<T> {
/**
* Creates and returns an updater for objects with the given field.
* The Class argument is needed to check that reflective types and
@@ -317,7 +315,7 @@ public abstract class AtomicLongFieldUpdater<T> {
if (cclass.isInstance(obj)) {
return;
}
- throw new RuntimeException (
+ throw new RuntimeException(
new IllegalAccessException("Class " +
cclass.getName() +
" can not access a protected member of class " +
@@ -384,7 +382,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public boolean compareAndSet(T obj, long expect, long update) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
- synchronized(this) {
+ synchronized (this) {
long v = unsafe.getLong(obj, offset);
if (v != expect)
return false;
@@ -399,7 +397,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public void set(T obj, long newValue) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
- synchronized(this) {
+ synchronized (this) {
unsafe.putLong(obj, offset, newValue);
}
}
@@ -410,7 +408,7 @@ public abstract class AtomicLongFieldUpdater<T> {
public long get(T obj) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
- synchronized(this) {
+ synchronized (this) {
return unsafe.getLong(obj, offset);
}
}
@@ -419,7 +417,7 @@ public abstract class AtomicLongFieldUpdater<T> {
if (cclass.isInstance(obj)) {
return;
}
- throw new RuntimeException (
+ throw new RuntimeException(
new IllegalAccessException("Class " +
cclass.getName() +
" can not access a protected member of class " +
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicMarkableReference.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicMarkableReference.java
index 4877dc4..63f46d6 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicMarkableReference.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicMarkableReference.java
@@ -6,11 +6,13 @@
package java.util.concurrent.atomic;
+import sun.misc.Unsafe;
+
/**
* An {@code AtomicMarkableReference} maintains an object reference
* along with a mark bit, that can be updated atomically.
- * <p>
- * <p> Implementation note. This implementation maintains markable
+ *
+ * <p>Implementation note: This implementation maintains markable
* references by creating internal objects representing "boxed"
* [reference, boolean] pairs.
*
@@ -18,17 +20,21 @@ package java.util.concurrent.atomic;
* @author Doug Lea
* @param <V> The type of object referred to by this reference
*/
-public class AtomicMarkableReference<V> {
+public class AtomicMarkableReference<V> {
- private static class ReferenceBooleanPair<T> {
- private final T reference;
- private final boolean bit;
- ReferenceBooleanPair(T r, boolean i) {
- reference = r; bit = i;
+ private static class Pair<T> {
+ final T reference;
+ final boolean mark;
+ private Pair(T reference, boolean mark) {
+ this.reference = reference;
+ this.mark = mark;
+ }
+ static <T> Pair<T> of(T reference, boolean mark) {
+ return new Pair<T>(reference, mark);
}
}
- private final AtomicReference<ReferenceBooleanPair<V>> atomicRef;
+ private volatile Pair<V> pair;
/**
* Creates a new {@code AtomicMarkableReference} with the given
@@ -38,7 +44,7 @@ public class AtomicMarkableReference<V> {
* @param initialMark the initial mark
*/
public AtomicMarkableReference(V initialRef, boolean initialMark) {
- atomicRef = new AtomicReference<ReferenceBooleanPair<V>> (new ReferenceBooleanPair<V>(initialRef, initialMark));
+ pair = Pair.of(initialRef, initialMark);
}
/**
@@ -47,7 +53,7 @@ public class AtomicMarkableReference<V> {
* @return the current value of the reference
*/
public V getReference() {
- return atomicRef.get().reference;
+ return pair.reference;
}
/**
@@ -56,7 +62,7 @@ public class AtomicMarkableReference<V> {
* @return the current value of the mark
*/
public boolean isMarked() {
- return atomicRef.get().bit;
+ return pair.mark;
}
/**
@@ -68,9 +74,9 @@ public class AtomicMarkableReference<V> {
* @return the current value of the reference
*/
public V get(boolean[] markHolder) {
- ReferenceBooleanPair<V> p = atomicRef.get();
- markHolder[0] = p.bit;
- return p.reference;
+ Pair<V> pair = this.pair;
+ markHolder[0] = pair.mark;
+ return pair.reference;
}
/**
@@ -93,13 +99,8 @@ public class AtomicMarkableReference<V> {
V newReference,
boolean expectedMark,
boolean newMark) {
- ReferenceBooleanPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- expectedMark == current.bit &&
- ((newReference == current.reference && newMark == current.bit) ||
- atomicRef.weakCompareAndSet(current,
- new ReferenceBooleanPair<V>(newReference,
- newMark)));
+ return compareAndSet(expectedReference, newReference,
+ expectedMark, newMark);
}
/**
@@ -118,13 +119,13 @@ public class AtomicMarkableReference<V> {
V newReference,
boolean expectedMark,
boolean newMark) {
- ReferenceBooleanPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- expectedMark == current.bit &&
- ((newReference == current.reference && newMark == current.bit) ||
- atomicRef.compareAndSet(current,
- new ReferenceBooleanPair<V>(newReference,
- newMark)));
+ Pair<V> current = pair;
+ return
+ expectedReference == current.reference &&
+ expectedMark == current.mark &&
+ ((newReference == current.reference &&
+ newMark == current.mark) ||
+ casPair(current, Pair.of(newReference, newMark)));
}
/**
@@ -134,9 +135,9 @@ public class AtomicMarkableReference<V> {
* @param newMark the new value for the mark
*/
public void set(V newReference, boolean newMark) {
- ReferenceBooleanPair<V> current = atomicRef.get();
- if (newReference != current.reference || newMark != current.bit)
- atomicRef.set(new ReferenceBooleanPair<V>(newReference, newMark));
+ Pair<V> current = pair;
+ if (newReference != current.reference || newMark != current.mark)
+ this.pair = Pair.of(newReference, newMark);
}
/**
@@ -153,11 +154,32 @@ public class AtomicMarkableReference<V> {
* @return true if successful
*/
public boolean attemptMark(V expectedReference, boolean newMark) {
- ReferenceBooleanPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- (newMark == current.bit ||
- atomicRef.compareAndSet
- (current, new ReferenceBooleanPair<V>(expectedReference,
- newMark)));
+ Pair<V> current = pair;
+ return
+ expectedReference == current.reference &&
+ (newMark == current.mark ||
+ casPair(current, Pair.of(expectedReference, newMark)));
+ }
+
+ // Unsafe mechanics
+
+ private static final sun.misc.Unsafe UNSAFE = UnsafeAccess.THE_ONE; // android-changed
+ private static final long pairOffset =
+ objectFieldOffset(UNSAFE, "pair", AtomicMarkableReference.class);
+
+ private boolean casPair(Pair<V> cmp, Pair<V> val) {
+ return UNSAFE.compareAndSwapObject(this, pairOffset, cmp, val);
+ }
+
+ static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
+ String field, Class<?> klazz) {
+ try {
+ return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
+ } catch (NoSuchFieldException e) {
+ // Convert Exception to corresponding Error
+ NoSuchFieldError error = new NoSuchFieldError(field);
+ error.initCause(e);
+ throw error;
+ }
}
}
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java
index b421e1b..dbc5886 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceArray.java
@@ -5,8 +5,8 @@
*/
package java.util.concurrent.atomic;
-
import sun.misc.Unsafe;
+import java.util.*;
/**
* An array of object references in which elements may be updated
@@ -22,9 +22,16 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
private static final Unsafe unsafe = UnsafeAccess.THE_ONE; // android-changed
private static final int base = unsafe.arrayBaseOffset(Object[].class);
- private static final int scale = unsafe.arrayIndexScale(Object[].class);
+ private static final int shift;
private final Object[] array;
+ static {
+ int scale = unsafe.arrayIndexScale(Object[].class);
+ if ((scale & (scale - 1)) != 0)
+ throw new Error("data type scale not a power of two");
+ shift = 31 - Integer.numberOfLeadingZeros(scale);
+ }
+
private long checkedByteOffset(int i) {
if (i < 0 || i >= array.length)
throw new IndexOutOfBoundsException("index " + i);
@@ -33,7 +40,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
}
private static long byteOffset(int i) {
- return base + (long) i * scale;
+ return ((long) i << shift) + base;
}
/**
@@ -170,7 +177,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
b.append(getRaw(byteOffset(i)));
if (i == iMax)
return b.append(']').toString();
- b.append(", ");
+ b.append(',').append(' ');
}
}
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
index b854803..e4ae0cf 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.java
@@ -5,12 +5,9 @@
*/
package java.util.concurrent.atomic;
-
import dalvik.system.VMStack;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Modifier;
import sun.misc.Unsafe;
+import java.lang.reflect.*;
/**
* A reflection-based utility that enables atomic updates to
@@ -20,13 +17,13 @@ import sun.misc.Unsafe;
* independently subject to atomic updates. For example, a tree node
* might be declared as
*
- * <pre>
+ * <pre> {@code
* class Node {
* private volatile Node left, right;
*
- * private static final AtomicReferenceFieldUpdater&lt;Node, Node&gt; leftUpdater =
+ * private static final AtomicReferenceFieldUpdater<Node, Node> leftUpdater =
* AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "left");
- * private static AtomicReferenceFieldUpdater&lt;Node, Node&gt; rightUpdater =
+ * private static AtomicReferenceFieldUpdater<Node, Node> rightUpdater =
* AtomicReferenceFieldUpdater.newUpdater(Node.class, Node.class, "right");
*
* Node getLeft() { return left; }
@@ -34,8 +31,7 @@ import sun.misc.Unsafe;
* return leftUpdater.compareAndSet(this, expect, update);
* }
* // ... and so on
- * }
- * </pre>
+ * }}</pre>
*
* <p>Note that the guarantees of the {@code compareAndSet}
* method in this class are weaker than in other atomic classes.
@@ -49,7 +45,7 @@ import sun.misc.Unsafe;
* @param <T> The type of the object holding the updatable field
* @param <V> The type of the field
*/
-public abstract class AtomicReferenceFieldUpdater<T, V> {
+public abstract class AtomicReferenceFieldUpdater<T, V> {
/**
* Creates and returns an updater for objects with the given field.
@@ -277,7 +273,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
if (cclass.isInstance(obj)) {
return;
}
- throw new RuntimeException (
+ throw new RuntimeException(
new IllegalAccessException("Class " +
cclass.getName() +
" can not access a protected member of class " +
diff --git a/luni/src/main/java/java/util/concurrent/atomic/AtomicStampedReference.java b/luni/src/main/java/java/util/concurrent/atomic/AtomicStampedReference.java
index a1d535f..2e826f2 100644
--- a/luni/src/main/java/java/util/concurrent/atomic/AtomicStampedReference.java
+++ b/luni/src/main/java/java/util/concurrent/atomic/AtomicStampedReference.java
@@ -10,7 +10,7 @@ package java.util.concurrent.atomic;
* An {@code AtomicStampedReference} maintains an object reference
* along with an integer "stamp", that can be updated atomically.
*
- * <p> Implementation note. This implementation maintains stamped
+ * <p>Implementation note: This implementation maintains stamped
* references by creating internal objects representing "boxed"
* [reference, integer] pairs.
*
@@ -18,17 +18,21 @@ package java.util.concurrent.atomic;
* @author Doug Lea
* @param <V> The type of object referred to by this reference
*/
-public class AtomicStampedReference<V> {
+public class AtomicStampedReference<V> {
- private static class ReferenceIntegerPair<T> {
- private final T reference;
- private final int integer;
- ReferenceIntegerPair(T r, int i) {
- reference = r; integer = i;
+ private static class Pair<T> {
+ final T reference;
+ final int stamp;
+ private Pair(T reference, int stamp) {
+ this.reference = reference;
+ this.stamp = stamp;
+ }
+ static <T> Pair<T> of(T reference, int stamp) {
+ return new Pair<T>(reference, stamp);
}
}
- private final AtomicReference<ReferenceIntegerPair<V>> atomicRef;
+ private volatile Pair<V> pair;
/**
* Creates a new {@code AtomicStampedReference} with the given
@@ -38,8 +42,7 @@ public class AtomicStampedReference<V> {
* @param initialStamp the initial stamp
*/
public AtomicStampedReference(V initialRef, int initialStamp) {
- atomicRef = new AtomicReference<ReferenceIntegerPair<V>>
- (new ReferenceIntegerPair<V>(initialRef, initialStamp));
+ pair = Pair.of(initialRef, initialStamp);
}
/**
@@ -48,7 +51,7 @@ public class AtomicStampedReference<V> {
* @return the current value of the reference
*/
public V getReference() {
- return atomicRef.get().reference;
+ return pair.reference;
}
/**
@@ -57,7 +60,7 @@ public class AtomicStampedReference<V> {
* @return the current value of the stamp
*/
public int getStamp() {
- return atomicRef.get().integer;
+ return pair.stamp;
}
/**
@@ -69,9 +72,9 @@ public class AtomicStampedReference<V> {
* @return the current value of the reference
*/
public V get(int[] stampHolder) {
- ReferenceIntegerPair<V> p = atomicRef.get();
- stampHolder[0] = p.integer;
- return p.reference;
+ Pair<V> pair = this.pair;
+ stampHolder[0] = pair.stamp;
+ return pair.reference;
}
/**
@@ -90,18 +93,12 @@ public class AtomicStampedReference<V> {
* @param newStamp the new value for the stamp
* @return true if successful
*/
- public boolean weakCompareAndSet(V expectedReference,
- V newReference,
- int expectedStamp,
- int newStamp) {
- ReferenceIntegerPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- expectedStamp == current.integer &&
- ((newReference == current.reference &&
- newStamp == current.integer) ||
- atomicRef.weakCompareAndSet(current,
- new ReferenceIntegerPair<V>(newReference,
- newStamp)));
+ public boolean weakCompareAndSet(V expectedReference,
+ V newReference,
+ int expectedStamp,
+ int newStamp) {
+ return compareAndSet(expectedReference, newReference,
+ expectedStamp, newStamp);
}
/**
@@ -116,18 +113,17 @@ public class AtomicStampedReference<V> {
* @param newStamp the new value for the stamp
* @return true if successful
*/
- public boolean compareAndSet(V expectedReference,
- V newReference,
- int expectedStamp,
- int newStamp) {
- ReferenceIntegerPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- expectedStamp == current.integer &&
+ public boolean compareAndSet(V expectedReference,
+ V newReference,
+ int expectedStamp,
+ int newStamp) {
+ Pair<V> current = pair;
+ return
+ expectedReference == current.reference &&
+ expectedStamp == current.stamp &&
((newReference == current.reference &&
- newStamp == current.integer) ||
- atomicRef.compareAndSet(current,
- new ReferenceIntegerPair<V>(newReference,
- newStamp)));
+ newStamp == current.stamp) ||
+ casPair(current, Pair.of(newReference, newStamp)));
}
@@ -138,9 +134,9 @@ public class AtomicStampedReference<V> {
* @param newStamp the new value for the stamp
*/
public void set(V newReference, int newStamp) {
- ReferenceIntegerPair<V> current = atomicRef.get();
- if (newReference != current.reference || newStamp != current.integer)
- atomicRef.set(new ReferenceIntegerPair<V>(newReference, newStamp));
+ Pair<V> current = pair;
+ if (newReference != current.reference || newStamp != current.stamp)
+ this.pair = Pair.of(newReference, newStamp);
}
/**
@@ -157,11 +153,32 @@ public class AtomicStampedReference<V> {
* @return true if successful
*/
public boolean attemptStamp(V expectedReference, int newStamp) {
- ReferenceIntegerPair<V> current = atomicRef.get();
- return expectedReference == current.reference &&
- (newStamp == current.integer ||
- atomicRef.compareAndSet(current,
- new ReferenceIntegerPair<V>(expectedReference,
- newStamp)));
+ Pair<V> current = pair;
+ return
+ expectedReference == current.reference &&
+ (newStamp == current.stamp ||
+ casPair(current, Pair.of(expectedReference, newStamp)));
+ }
+
+ // Unsafe mechanics
+
+ private static final sun.misc.Unsafe UNSAFE = UnsafeAccess.THE_ONE; // android-changed
+ private static final long pairOffset =
+ objectFieldOffset(UNSAFE, "pair", AtomicStampedReference.class);
+
+ private boolean casPair(Pair<V> cmp, Pair<V> val) {
+ return UNSAFE.compareAndSwapObject(this, pairOffset, cmp, val);
+ }
+
+ static long objectFieldOffset(sun.misc.Unsafe UNSAFE,
+ String field, Class<?> klazz) {
+ try {
+ return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
+ } catch (NoSuchFieldException e) {
+ // Convert Exception to corresponding Error
+ NoSuchFieldError error = new NoSuchFieldError(field);
+ error.initCause(e);
+ throw error;
+ }
}
}
diff --git a/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java b/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
index 90adce6..5c8111c 100644
--- a/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
+++ b/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.java
@@ -5,11 +5,9 @@
*/
package java.util.concurrent.locks;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.concurrent.TimeUnit;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
import sun.misc.Unsafe;
/**
@@ -963,7 +961,8 @@ public abstract class AbstractQueuedLongSynchronizer
* can represent anything you like.
* @throws InterruptedException if the current thread is interrupted
*/
- public final void acquireInterruptibly(long arg) throws InterruptedException {
+ public final void acquireInterruptibly(long arg)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
if (!tryAcquire(arg))
@@ -987,7 +986,8 @@ public abstract class AbstractQueuedLongSynchronizer
* @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted
*/
- public final boolean tryAcquireNanos(long arg, long nanosTimeout) throws InterruptedException {
+ public final boolean tryAcquireNanos(long arg, long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
return tryAcquire(arg) ||
@@ -1043,7 +1043,8 @@ public abstract class AbstractQueuedLongSynchronizer
* you like.
* @throws InterruptedException if the current thread is interrupted
*/
- public final void acquireSharedInterruptibly(long arg) throws InterruptedException {
+ public final void acquireSharedInterruptibly(long arg)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
if (tryAcquireShared(arg) < 0)
@@ -1066,7 +1067,8 @@ public abstract class AbstractQueuedLongSynchronizer
* @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted
*/
- public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout) throws InterruptedException {
+ public final boolean tryAcquireSharedNanos(long arg, long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
return tryAcquireShared(arg) >= 0 ||
@@ -1436,7 +1438,6 @@ public abstract class AbstractQueuedLongSynchronizer
* Transfers node, if necessary, to sync queue after a cancelled
* wait. Returns true if thread was cancelled before being
* signalled.
- * @param current the waiting thread
* @param node its node
* @return true if cancelled before the node was signalled
*/
@@ -1814,7 +1815,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If interrupted while blocked in step 4, throw InterruptedException.
* </ol>
*/
- public final long awaitNanos(long nanosTimeout) throws InterruptedException {
+ public final long awaitNanos(long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
Node node = addConditionWaiter();
@@ -1858,7 +1860,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If timed out while blocked in step 4, return false, else true.
* </ol>
*/
- public final boolean awaitUntil(Date deadline) throws InterruptedException {
+ public final boolean awaitUntil(Date deadline)
+ throws InterruptedException {
if (deadline == null)
throw new NullPointerException();
long abstime = deadline.getTime();
@@ -1901,7 +1904,8 @@ public abstract class AbstractQueuedLongSynchronizer
* <li> If timed out while blocked in step 4, return false, else true.
* </ol>
*/
- public final boolean await(long time, TimeUnit unit) throws InterruptedException {
+ public final boolean await(long time, TimeUnit unit)
+ throws InterruptedException {
if (unit == null)
throw new NullPointerException();
long nanosTimeout = unit.toNanos(time);
@@ -2057,7 +2061,7 @@ public abstract class AbstractQueuedLongSynchronizer
/**
* CAS waitStatus field of a node.
*/
- private final static boolean compareAndSetWaitStatus(Node node,
+ private static final boolean compareAndSetWaitStatus(Node node,
int expect,
int update) {
return unsafe.compareAndSwapInt(node, waitStatusOffset,
@@ -2067,7 +2071,7 @@ public abstract class AbstractQueuedLongSynchronizer
/**
* CAS next field of a node.
*/
- private final static boolean compareAndSetNext(Node node,
+ private static final boolean compareAndSetNext(Node node,
Node expect,
Node update) {
return unsafe.compareAndSwapObject(node, nextOffset, expect, update);
diff --git a/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java b/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
index 9715bc5..065f130 100644
--- a/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
+++ b/luni/src/main/java/java/util/concurrent/locks/AbstractQueuedSynchronizer.java
@@ -5,14 +5,15 @@
*/
package java.util.concurrent.locks;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
import sun.misc.Unsafe;
+// BEGIN android-note
+// Use older class level documentation to not @link to hasQueuedPredecessors
+// END android-changed
+
/**
* Provides a framework for implementing blocking locks and related
* synchronizers (semaphores, events, etc) that rely on
@@ -123,14 +124,18 @@ import sun.misc.Unsafe;
*
* <p><a name="barging">Because checks in acquire are invoked before
* enqueuing, a newly acquiring thread may <em>barge</em> ahead of
- * others that are blocked and queued. However, you can, if desired,
+ * others that are blocked and queued. However, you can, if desired,
* define <tt>tryAcquire</tt> and/or <tt>tryAcquireShared</tt> to
* disable barging by internally invoking one or more of the inspection
- * methods, thereby providing a <em>fair</em> FIFO acquisition order.
- * In particular, most fair synchronizers can define <tt>tryAcquire</tt>
- * to return <tt>false</tt> if {@code hasQueuedPredecessors} (a method
- * specifically designed to be used by fair synchronizers) returns
- * <tt>true</tt>. Other variations are possible.
+ * methods. In particular, a strict FIFO lock can define
+ * <tt>tryAcquire</tt> to immediately return <tt>false</tt> if {@link
+ * #getFirstQueuedThread} does not return the current thread. A
+ * normally preferable non-strict fair version can immediately return
+ * <tt>false</tt> only if {@link #hasQueuedThreads} returns
+ * <tt>true</tt> and <tt>getFirstQueuedThread</tt> is not the current
+ * thread; or equivalently, that <tt>getFirstQueuedThread</tt> is both
+ * non-null and not the current thread. Further variations are
+ * possible.
*
* <p>Throughput and scalability are generally highest for the
* default barging (also known as <em>greedy</em>,
@@ -239,7 +244,7 @@ import sun.misc.Unsafe;
* boolean isSignalled() { return getState() != 0; }
*
* protected int tryAcquireShared(int ignore) {
- * return isSignalled()? 1 : -1;
+ * return isSignalled() ? 1 : -1;
* }
*
* protected boolean tryReleaseShared(int ignore) {
@@ -1187,7 +1192,8 @@ public abstract class AbstractQueuedSynchronizer
* can represent anything you like.
* @throws InterruptedException if the current thread is interrupted
*/
- public final void acquireInterruptibly(int arg) throws InterruptedException {
+ public final void acquireInterruptibly(int arg)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
if (!tryAcquire(arg))
@@ -1211,7 +1217,8 @@ public abstract class AbstractQueuedSynchronizer
* @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted
*/
- public final boolean tryAcquireNanos(int arg, long nanosTimeout) throws InterruptedException {
+ public final boolean tryAcquireNanos(int arg, long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
return tryAcquire(arg) ||
@@ -1267,7 +1274,8 @@ public abstract class AbstractQueuedSynchronizer
* you like.
* @throws InterruptedException if the current thread is interrupted
*/
- public final void acquireSharedInterruptibly(int arg) throws InterruptedException {
+ public final void acquireSharedInterruptibly(int arg)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
if (tryAcquireShared(arg) < 0)
@@ -1290,7 +1298,8 @@ public abstract class AbstractQueuedSynchronizer
* @return {@code true} if acquired; {@code false} if timed out
* @throws InterruptedException if the current thread is interrupted
*/
- public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout) throws InterruptedException {
+ public final boolean tryAcquireSharedNanos(int arg, long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
return tryAcquireShared(arg) >= 0 ||
@@ -2002,9 +2011,6 @@ public abstract class AbstractQueuedSynchronizer
* {@link #acquire} with saved state as argument.
* <li> If interrupted while blocked in step 4, throw InterruptedException.
* </ol>
- *
- * @throws InterruptedException if the current thread is interrupted (and
- * interruption of thread suspension is supported).
*/
public final void await() throws InterruptedException {
if (Thread.interrupted())
@@ -2038,17 +2044,9 @@ public abstract class AbstractQueuedSynchronizer
* {@link #acquire} with saved state as argument.
* <li> If interrupted while blocked in step 4, throw InterruptedException.
* </ol>
- *
- * @param nanosTimeout the maximum time to wait, in nanoseconds
- * @return A value less than or equal to zero if the wait has
- * timed out; otherwise an estimate, that
- * is strictly less than the <tt>nanosTimeout</tt> argument,
- * of the time still remaining when this method returned.
- *
- * @throws InterruptedException if the current thread is interrupted (and
- * interruption of thread suspension is supported).
*/
- public final long awaitNanos(long nanosTimeout) throws InterruptedException {
+ public final long awaitNanos(long nanosTimeout)
+ throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
Node node = addConditionWaiter();
@@ -2091,15 +2089,9 @@ public abstract class AbstractQueuedSynchronizer
* <li> If interrupted while blocked in step 4, throw InterruptedException.
* <li> If timed out while blocked in step 4, return false, else true.
* </ol>
- *
- * @param deadline the absolute time to wait until
- * @return <tt>false</tt> if the deadline has
- * elapsed upon return, else <tt>true</tt>.
- *
- * @throws InterruptedException if the current thread is interrupted (and
- * interruption of thread suspension is supported).
*/
- public final boolean awaitUntil(Date deadline) throws InterruptedException {
+ public final boolean awaitUntil(Date deadline)
+ throws InterruptedException {
if (deadline == null)
throw new NullPointerException();
long abstime = deadline.getTime();
@@ -2141,15 +2133,9 @@ public abstract class AbstractQueuedSynchronizer
* <li> If interrupted while blocked in step 4, throw InterruptedException.
* <li> If timed out while blocked in step 4, return false, else true.
* </ol>
- *
- * @param time the maximum time to wait
- * @param unit the time unit of the <tt>time</tt> argument.
- * @return <tt>false</tt> if the waiting time detectably elapsed
- * before return from the method, else <tt>true</tt>.
- * @throws InterruptedException if the current thread is interrupted (and
- * interruption of thread suspension is supported).
*/
- public final boolean await(long time, TimeUnit unit) throws InterruptedException {
+ public final boolean await(long time, TimeUnit unit)
+ throws InterruptedException {
if (unit == null)
throw new NullPointerException();
long nanosTimeout = unit.toNanos(time);
@@ -2307,7 +2293,7 @@ public abstract class AbstractQueuedSynchronizer
/**
* CAS waitStatus field of a node.
*/
- private final static boolean compareAndSetWaitStatus(Node node,
+ private static final boolean compareAndSetWaitStatus(Node node,
int expect,
int update) {
return unsafe.compareAndSwapInt(node, waitStatusOffset,
@@ -2317,7 +2303,7 @@ public abstract class AbstractQueuedSynchronizer
/**
* CAS next field of a node.
*/
- private final static boolean compareAndSetNext(Node node,
+ private static final boolean compareAndSetNext(Node node,
Node expect,
Node update) {
return unsafe.compareAndSwapObject(node, nextOffset, expect, update);
diff --git a/luni/src/main/java/java/util/concurrent/locks/Condition.java b/luni/src/main/java/java/util/concurrent/locks/Condition.java
index f3c6a3f..8504e1f 100644
--- a/luni/src/main/java/java/util/concurrent/locks/Condition.java
+++ b/luni/src/main/java/java/util/concurrent/locks/Condition.java
@@ -5,9 +5,8 @@
*/
package java.util.concurrent.locks;
-
+import java.util.concurrent.*;
import java.util.Date;
-import java.util.concurrent.TimeUnit;
/**
* {@code Condition} factors out the {@code Object} monitor
@@ -280,18 +279,21 @@ public interface Condition {
* condition still does not hold. Typical uses of this method take
* the following form:
*
- * <pre>
- * synchronized boolean aMethod(long timeout, TimeUnit unit) {
- * long nanosTimeout = unit.toNanos(timeout);
- * while (!conditionBeingWaitedFor) {
- * if (nanosTimeout &gt; 0)
- * nanosTimeout = theCondition.awaitNanos(nanosTimeout);
- * else
- * return false;
+ * <pre> {@code
+ * boolean aMethod(long timeout, TimeUnit unit) {
+ * long nanos = unit.toNanos(timeout);
+ * lock.lock();
+ * try {
+ * while (!conditionBeingWaitedFor()) {
+ * if (nanos <= 0L)
+ * return false;
+ * nanos = theCondition.awaitNanos(nanos);
+ * }
+ * // ...
+ * } finally {
+ * lock.unlock();
* }
- * // ...
- * }
- * </pre>
+ * }}</pre>
*
* <p> Design note: This method requires a nanosecond argument so
* as to avoid truncation errors in reporting remaining times.
@@ -380,18 +382,21 @@ public interface Condition {
*
* <p>The return value indicates whether the deadline has elapsed,
* which can be used as follows:
- * <pre>
- * synchronized boolean aMethod(Date deadline) {
+ * <pre> {@code
+ * boolean aMethod(Date deadline) {
* boolean stillWaiting = true;
- * while (!conditionBeingWaitedFor) {
- * if (stillWaiting)
- * stillWaiting = theCondition.awaitUntil(deadline);
- * else
- * return false;
+ * lock.lock();
+ * try {
+ * while (!conditionBeingWaitedFor()) {
+ * if (!stillWaiting)
+ * return false;
+ * stillWaiting = theCondition.awaitUntil(deadline);
+ * }
+ * // ...
+ * } finally {
+ * lock.unlock();
* }
- * // ...
- * }
- * </pre>
+ * }}</pre>
*
* <p><b>Implementation Considerations</b>
*
@@ -425,12 +430,12 @@ public interface Condition {
*
* <p><b>Implementation Considerations</b>
*
- * <p>The current thread is assumed to hold the lock associated
- * with this {@code Condition} when this method is called. It is
- * up to the implementation to determine if this is the case and
- * if not, how to respond. Typically, an exception will be thrown
- * (such as {@link IllegalMonitorStateException}) and the
- * implementation must document that fact.
+ * <p>An implementation may (and typically does) require that the
+ * current thread hold the lock associated with this {@code
+ * Condition} when this method is called. Implementations must
+ * document this precondition and any actions taken if the lock is
+ * not held. Typically, an exception such as {@link
+ * IllegalMonitorStateException} will be thrown.
*/
void signal();
@@ -443,12 +448,12 @@ public interface Condition {
*
* <p><b>Implementation Considerations</b>
*
- * <p>The current thread is assumed to hold the lock associated
- * with this {@code Condition} when this method is called. It is
- * up to the implementation to determine if this is the case and
- * if not, how to respond. Typically, an exception will be thrown
- * (such as {@link IllegalMonitorStateException}) and the
- * implementation must document that fact.
+ * <p>An implementation may (and typically does) require that the
+ * current thread hold the lock associated with this {@code
+ * Condition} when this method is called. Implementations must
+ * document this precondition and any actions taken if the lock is
+ * not held. Typically, an exception such as {@link
+ * IllegalMonitorStateException} will be thrown.
*/
void signalAll();
}
diff --git a/luni/src/main/java/java/util/concurrent/locks/LockSupport.java b/luni/src/main/java/java/util/concurrent/locks/LockSupport.java
index 4b8ccf7..0c0f07d 100644
--- a/luni/src/main/java/java/util/concurrent/locks/LockSupport.java
+++ b/luni/src/main/java/java/util/concurrent/locks/LockSupport.java
@@ -5,7 +5,7 @@
*/
package java.util.concurrent.locks;
-
+import java.util.concurrent.*;
import sun.misc.Unsafe;
@@ -171,8 +171,8 @@ public class LockSupport {
* <li>Some other thread invokes {@link #unpark unpark} with the
* current thread as the target; or
*
- * <li>Some other thread {@linkplain Thread#interrupt interrupts} the current
- * thread; or
+ * <li>Some other thread {@linkplain Thread#interrupt interrupts}
+ * the current thread; or
*
* <li>The specified waiting time elapses; or
*
diff --git a/luni/src/main/java/java/util/concurrent/locks/ReentrantLock.java b/luni/src/main/java/java/util/concurrent/locks/ReentrantLock.java
index 500a3b7..cf787ca 100644
--- a/luni/src/main/java/java/util/concurrent/locks/ReentrantLock.java
+++ b/luni/src/main/java/java/util/concurrent/locks/ReentrantLock.java
@@ -5,9 +5,9 @@
*/
package java.util.concurrent.locks;
-
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
/**
* A reentrant mutual exclusion {@link Lock} with the same basic
@@ -87,7 +87,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* into fair and nonfair versions below. Uses AQS state to
* represent the number of holds on the lock.
*/
- static abstract class Sync extends AbstractQueuedSynchronizer {
+ abstract static class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = -5179523762034025860L;
/**
@@ -171,7 +171,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
/**
* Sync object for non-fair locks
*/
- final static class NonfairSync extends Sync {
+ static final class NonfairSync extends Sync {
private static final long serialVersionUID = 7316153563782823691L;
/**
@@ -193,7 +193,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
/**
* Sync object for fair locks
*/
- final static class FairSync extends Sync {
+ static final class FairSync extends Sync {
private static final long serialVersionUID = -3000897897090466540L;
final void lock() {
@@ -240,7 +240,7 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* @param fair {@code true} if this lock should use a fair ordering policy
*/
public ReentrantLock(boolean fair) {
- sync = (fair)? new FairSync() : new NonfairSync();
+ sync = fair ? new FairSync() : new NonfairSync();
}
/**
@@ -411,7 +411,8 @@ public class ReentrantLock implements Lock, java.io.Serializable {
* @throws NullPointerException if the time unit is null
*
*/
- public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
+ public boolean tryLock(long timeout, TimeUnit unit)
+ throws InterruptedException {
return sync.tryAcquireNanos(1, unit.toNanos(timeout));
}
diff --git a/luni/src/main/java/java/util/concurrent/locks/ReentrantReadWriteLock.java b/luni/src/main/java/java/util/concurrent/locks/ReentrantReadWriteLock.java
index a8f81b2..b1a1a60 100644
--- a/luni/src/main/java/java/util/concurrent/locks/ReentrantReadWriteLock.java
+++ b/luni/src/main/java/java/util/concurrent/locks/ReentrantReadWriteLock.java
@@ -5,9 +5,9 @@
*/
package java.util.concurrent.locks;
-
-import java.util.Collection;
-import java.util.concurrent.TimeUnit;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.*;
+import java.util.*;
/**
* An implementation of {@link ReadWriteLock} supporting similar
@@ -126,7 +126,7 @@ import java.util.concurrent.TimeUnit;
* }
* // Downgrade by acquiring read lock before releasing write lock
* rwl.readLock().lock();
- * } finally {
+ * } finally {
* rwl.writeLock().unlock(); // Unlock write, still hold read
* }
* }
@@ -186,7 +186,8 @@ import java.util.concurrent.TimeUnit;
* @author Doug Lea
*
*/
-public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializable {
+public class ReentrantReadWriteLock
+ implements ReadWriteLock, java.io.Serializable {
private static final long serialVersionUID = -6992448646407690164L;
/** Inner class providing readlock */
private final ReentrantReadWriteLock.ReadLock readerLock;
@@ -222,7 +223,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* Synchronization implementation for ReentrantReadWriteLock.
* Subclassed into fair and nonfair versions.
*/
- static abstract class Sync extends AbstractQueuedSynchronizer {
+ abstract static class Sync extends AbstractQueuedSynchronizer {
private static final long serialVersionUID = 6317671515068378041L;
/*
@@ -589,7 +590,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
final Thread getOwner() {
// Must read state before owner to ensure memory consistency
- return ((exclusiveCount(getState()) == 0)?
+ return ((exclusiveCount(getState()) == 0) ?
null :
getExclusiveOwnerThread());
}
@@ -640,7 +641,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/**
* Nonfair version of Sync
*/
- final static class NonfairSync extends Sync {
+ static final class NonfairSync extends Sync {
private static final long serialVersionUID = -8159625535654395037L;
final boolean writerShouldBlock() {
return false; // writers can always barge
@@ -660,7 +661,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/**
* Fair version of Sync
*/
- final static class FairSync extends Sync {
+ static final class FairSync extends Sync {
private static final long serialVersionUID = -2274990926593161451L;
final boolean writerShouldBlock() {
return hasQueuedPredecessors();
@@ -673,7 +674,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/**
* The lock returned by method {@link ReentrantReadWriteLock#readLock}.
*/
- public static class ReadLock implements Lock, java.io.Serializable {
+ public static class ReadLock implements Lock, java.io.Serializable {
private static final long serialVersionUID = -5992448646407690164L;
private final Sync sync;
@@ -838,7 +839,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* @throws NullPointerException if the time unit is null
*
*/
- public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
+ public boolean tryLock(long timeout, TimeUnit unit)
+ throws InterruptedException {
return sync.tryAcquireSharedNanos(1, unit.toNanos(timeout));
}
@@ -879,7 +881,7 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
/**
* The lock returned by method {@link ReentrantReadWriteLock#writeLock}.
*/
- public static class WriteLock implements Lock, java.io.Serializable {
+ public static class WriteLock implements Lock, java.io.Serializable {
private static final long serialVersionUID = -4992448646407690164L;
private final Sync sync;
@@ -1079,7 +1081,8 @@ public class ReentrantReadWriteLock implements ReadWriteLock, java.io.Serializab
* @throws NullPointerException if the time unit is null
*
*/
- public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
+ public boolean tryLock(long timeout, TimeUnit unit)
+ throws InterruptedException {
return sync.tryAcquireNanos(1, unit.toNanos(timeout));
}
diff --git a/luni/src/main/java/java/util/concurrent/package-info.java b/luni/src/main/java/java/util/concurrent/package-info.java
index 6252069..8509a41 100644
--- a/luni/src/main/java/java/util/concurrent/package-info.java
+++ b/luni/src/main/java/java/util/concurrent/package-info.java
@@ -4,6 +4,10 @@
* http://creativecommons.org/licenses/publicdomain
*/
+// BEGIN android-note
+// Dropped references to unreleased APIs (ForkJoinPool, Phaser, etc.)
+// END android-note
+
/**
* Utility classes commonly useful in concurrent programming. This
* package includes a few small standardized extensible frameworks, as
diff --git a/luni/src/main/java/java/util/jar/Attributes.java b/luni/src/main/java/java/util/jar/Attributes.java
index a0f6bf4..9041c26 100644
--- a/luni/src/main/java/java/util/jar/Attributes.java
+++ b/luni/src/main/java/java/util/jar/Attributes.java
@@ -387,7 +387,7 @@ public class Attributes implements Cloneable, Map<Object, Object> {
*/
public void putAll(Map<?, ?> attrib) {
if (attrib == null || !(attrib instanceof Attributes)) {
- throw new ClassCastException();
+ throw new ClassCastException(attrib.getClass().getName() + " not an Attributes");
}
this.map.putAll(attrib);
}
diff --git a/luni/src/main/java/java/util/jar/JarEntry.java b/luni/src/main/java/java/util/jar/JarEntry.java
index f53f78f..381dd52 100644
--- a/luni/src/main/java/java/util/jar/JarEntry.java
+++ b/luni/src/main/java/java/util/jar/JarEntry.java
@@ -98,11 +98,11 @@ public class JarEntry extends ZipEntry {
* @see java.security.cert.Certificate
*/
public Certificate[] getCertificates() {
- if (null == parentJar) {
+ if (parentJar == null) {
return null;
}
JarVerifier jarVerifier = parentJar.verifier;
- if (null == jarVerifier) {
+ if (jarVerifier == null) {
return null;
}
return jarVerifier.getCertificates(getName());
@@ -136,10 +136,10 @@ public class JarEntry extends ZipEntry {
* @see CodeSigner
*/
public CodeSigner[] getCodeSigners() {
- if (null == signers) {
+ if (signers == null) {
signers = getCodeSigners(getCertificates());
}
- if (null == signers) {
+ if (signers == null) {
return null;
}
@@ -149,7 +149,7 @@ public class JarEntry extends ZipEntry {
}
private CodeSigner[] getCodeSigners(Certificate[] certs) {
- if (null == certs) {
+ if (certs == null) {
return null;
}
@@ -163,7 +163,7 @@ public class JarEntry extends ZipEntry {
continue;
}
X509Certificate x509 = (X509Certificate) element;
- if (null != prevIssuer) {
+ if (prevIssuer != null) {
X500Principal subj = x509.getSubjectX500Principal();
if (!prevIssuer.equals(subj)) {
// Ok, this ends the previous chain,
@@ -203,7 +203,7 @@ public class JarEntry extends ZipEntry {
isFactoryChecked = true;
}
}
- if (null == factory) {
+ if (factory == null) {
return;
}
try {
@@ -211,7 +211,7 @@ public class JarEntry extends ZipEntry {
} catch (CertificateException ex) {
// do nothing
}
- if (null != certPath) {
+ if (certPath != null) {
asigners.add(new CodeSigner(certPath, null));
}
}
diff --git a/luni/src/main/java/java/util/jar/JarFile.java b/luni/src/main/java/java/util/jar/JarFile.java
index 9f3eda2..ed39f67 100644
--- a/luni/src/main/java/java/util/jar/JarFile.java
+++ b/luni/src/main/java/java/util/jar/JarFile.java
@@ -26,8 +26,8 @@ import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import libcore.base.Streams;
import org.apache.harmony.archive.util.Util;
-import org.apache.harmony.luni.util.InputStreamHelper;
/**
* {@code JarFile} is used to read jar entries and their associated data from
@@ -136,19 +136,8 @@ public class JarFile extends ZipFile {
}
@Override
- public long skip(long nbytes) throws IOException {
- long cnt = 0, rem = 0;
- byte[] buf = new byte[(int)Math.min(nbytes, 2048L)];
- while (cnt < nbytes) {
- int x = read(buf, 0,
- (rem = nbytes - cnt) > buf.length ? buf.length
- : (int) rem);
- if (x == -1) {
- return cnt;
- }
- cnt += x;
- }
- return cnt;
+ public long skip(long byteCount) throws IOException {
+ return Streams.skipByReading(this, byteCount);
}
}
@@ -301,8 +290,11 @@ public class JarFile extends ZipFile {
try {
InputStream is = super.getInputStream(manifestEntry);
if (verifier != null) {
- verifier.addMetaEntry(manifestEntry.getName(),
- InputStreamHelper.readFullyAndClose(is));
+ try {
+ verifier.addMetaEntry(manifestEntry.getName(), Streams.readFully(is));
+ } finally {
+ is.close();
+ }
is = super.getInputStream(manifestEntry);
}
try {
@@ -339,8 +331,7 @@ public class JarFile extends ZipFile {
for (ZipEntry entry : metaEntries) {
String entryName = entry.getName();
// Is this the entry for META-INF/MANIFEST.MF ?
- if (manifestEntry == null
- && Util.asciiEqualsIgnoreCase(MANIFEST_NAME, entryName)) {
+ if (manifestEntry == null && Util.asciiEqualsIgnoreCase(MANIFEST_NAME, entryName)) {
manifestEntry = entry;
// If there is no verifier then we don't need to look any further.
if (verifier == null) {
@@ -354,8 +345,11 @@ public class JarFile extends ZipFile {
|| Util.asciiEndsWithIgnoreCase(entryName, ".RSA"))) {
signed = true;
InputStream is = super.getInputStream(entry);
- byte[] buf = InputStreamHelper.readFullyAndClose(is);
- verifier.addMetaEntry(entryName, buf);
+ try {
+ verifier.addMetaEntry(entryName, Streams.readFully(is));
+ } finally {
+ is.close();
+ }
}
}
}
diff --git a/luni/src/main/java/java/util/jar/JarVerifier.java b/luni/src/main/java/java/util/jar/JarVerifier.java
index f59ac13..cacafa0 100644
--- a/luni/src/main/java/java/util/jar/JarVerifier.java
+++ b/luni/src/main/java/java/util/jar/JarVerifier.java
@@ -300,7 +300,7 @@ class JarVerifier {
* Recursive call in loading security provider related class which
* is in a signed JAR.
*/
- if (null == metaEntries) {
+ if (metaEntries == null) {
return;
}
if (signerCertChain != null) {
diff --git a/luni/src/main/java/java/util/jar/Manifest.java b/luni/src/main/java/java/util/jar/Manifest.java
index 618234f..289032f 100644
--- a/luni/src/main/java/java/util/jar/Manifest.java
+++ b/luni/src/main/java/java/util/jar/Manifest.java
@@ -17,20 +17,22 @@
package java.util.jar;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharsetEncoder;
+import java.nio.charset.Charsets;
import java.nio.charset.CoderResult;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import org.apache.harmony.luni.util.InputStreamHelper;
-import org.apache.harmony.luni.util.ThreadLocalCache;
+import libcore.base.Streams;
/**
* The {@code Manifest} class is used to obtain attribute information for a
@@ -45,6 +47,19 @@ public class Manifest implements Cloneable {
private static final Attributes.Name NAME_ATTRIBUTE = new Attributes.Name("Name");
+ private static final Field BAIS_BUF = getByteArrayInputStreamField("buf");
+ private static final Field BAIS_POS = getByteArrayInputStreamField("pos");
+
+ private static Field getByteArrayInputStreamField(String name) {
+ try {
+ Field f = ByteArrayInputStream.class.getDeclaredField(name);
+ f.setAccessible(true);
+ return f;
+ } catch (Exception ex) {
+ throw new AssertionError(ex);
+ }
+ }
+
private Attributes mainAttributes = new Attributes();
private HashMap<String, Attributes> entries = new HashMap<String, Attributes>();
@@ -185,11 +200,10 @@ public class Manifest implements Cloneable {
*/
public void read(InputStream is) throws IOException {
byte[] buf;
- // Try to read get a reference to the bytes directly
- try {
- buf = InputStreamHelper.expose(is);
- } catch (UnsupportedOperationException uoe) {
- buf = readFully(is);
+ if (is instanceof ByteArrayInputStream) {
+ buf = exposeByteArrayInputStreamBytes((ByteArrayInputStream) is);
+ } else {
+ buf = Streams.readFully(is);
}
if (buf.length == 0) {
@@ -200,7 +214,7 @@ public class Manifest implements Cloneable {
// replace EOF and NUL with another new line
// which does not trigger an error
byte b = buf[buf.length - 1];
- if (0 == b || 26 == b) {
+ if (b == 0 || b == 26) {
buf[buf.length - 1] = '\n';
}
@@ -211,53 +225,31 @@ public class Manifest implements Cloneable {
im.initEntries(entries, chunks);
}
- /*
- * Helper to read the entire contents of the manifest from the
- * given input stream. Usually we can do this in a single read
- * but we need to account for 'infinite' streams, by ensuring we
- * have a line feed within a reasonable number of characters.
+ /**
+ * Returns a byte[] containing all the bytes from a ByteArrayInputStream.
+ * Where possible, this returns the actual array rather than a copy.
*/
- private byte[] readFully(InputStream is) throws IOException {
- // Initial read
- byte[] buffer = new byte[4096];
- int count = is.read(buffer);
- int nextByte = is.read();
-
- // Did we get it all in one read?
- if (nextByte == -1) {
- return Arrays.copyOf(buffer, count);
- }
-
- // Does it look like a manifest?
- if (!containsLine(buffer, count)) {
- throw new IOException("Manifest is too long");
- }
-
- // Requires additional reads
- ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
- baos.write(buffer, 0, count);
- baos.write(nextByte);
- while (true) {
- count = is.read(buffer);
- if (count == -1) {
- return baos.toByteArray();
+ private static byte[] exposeByteArrayInputStreamBytes(ByteArrayInputStream bais) {
+ byte[] buffer;
+ synchronized (bais) {
+ byte[] buf;
+ int pos;
+ try {
+ buf = (byte[]) BAIS_BUF.get(bais);
+ pos = BAIS_POS.getInt(bais);
+ } catch (IllegalAccessException iae) {
+ throw new AssertionError(iae);
}
- baos.write(buffer, 0, count);
- }
- }
-
- /*
- * Check to see if the buffer contains a newline or carriage
- * return character within the first 'length' bytes. Used to
- * check the validity of the manifest input stream.
- */
- private boolean containsLine(byte[] buffer, int length) {
- for (int i = 0; i < length; i++) {
- if (buffer[i] == 0x0A || buffer[i] == 0x0D) {
- return true;
+ int available = bais.available();
+ if (pos == 0 && buf.length == available) {
+ buffer = buf;
+ } else {
+ buffer = new byte[available];
+ System.arraycopy(buf, pos, buffer, 0, available);
}
+ bais.skip(available);
}
- return false;
+ return buffer;
}
/**
@@ -317,20 +309,17 @@ public class Manifest implements Cloneable {
* If an error occurs writing the {@code Manifest}.
*/
static void write(Manifest manifest, OutputStream out) throws IOException {
- CharsetEncoder encoder = ThreadLocalCache.utf8Encoder.get();
- ByteBuffer buffer = ThreadLocalCache.byteBuffer.get();
+ CharsetEncoder encoder = Charsets.UTF_8.newEncoder();
+ ByteBuffer buffer = ByteBuffer.allocate(LINE_LENGTH_LIMIT);
- String version = manifest.mainAttributes
- .getValue(Attributes.Name.MANIFEST_VERSION);
+ String version = manifest.mainAttributes.getValue(Attributes.Name.MANIFEST_VERSION);
if (version != null) {
- writeEntry(out, Attributes.Name.MANIFEST_VERSION, version, encoder,
- buffer);
+ writeEntry(out, Attributes.Name.MANIFEST_VERSION, version, encoder, buffer);
Iterator<?> entries = manifest.mainAttributes.keySet().iterator();
while (entries.hasNext()) {
Attributes.Name name = (Attributes.Name) entries.next();
if (!name.equals(Attributes.Name.MANIFEST_VERSION)) {
- writeEntry(out, name, manifest.mainAttributes
- .getValue(name), encoder, buffer);
+ writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer);
}
}
}
diff --git a/luni/src/main/java/java/util/logging/FileHandler.java b/luni/src/main/java/java/util/logging/FileHandler.java
index bc12b8d..0735911 100644
--- a/luni/src/main/java/java/util/logging/FileHandler.java
+++ b/luni/src/main/java/java/util/logging/FileHandler.java
@@ -28,6 +28,7 @@ import java.nio.channels.FileLock;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Hashtable;
+import libcore.io.IoUtils;
/**
* A {@code FileHandler} writes logging records into a specified file or a
@@ -181,7 +182,7 @@ public class FileHandler extends StreamHandler {
* if current process has held lock for this fileName continue
* to find next file
*/
- if (null != allLocks.get(fileName)) {
+ if (allLocks.get(fileName) != null) {
continue;
}
if (files[0].exists()
@@ -202,12 +203,8 @@ public class FileHandler extends StreamHandler {
* undead cycle
*/
lock = channel.tryLock();
- if (null == lock) {
- try {
- fileStream.close();
- } catch (Exception e) {
- // ignore
- }
+ if (lock == null) {
+ IoUtils.closeQuietly(fileStream);
continue;
}
allLocks.put(fileName, lock);
@@ -224,16 +221,16 @@ public class FileHandler extends StreamHandler {
super.initProperties("ALL", null, "java.util.logging.XMLFormatter",
null);
String className = this.getClass().getName();
- pattern = (null == p) ? getStringProperty(className + ".pattern",
+ pattern = (p == null) ? getStringProperty(className + ".pattern",
DEFAULT_PATTERN) : p;
if (pattern == null || pattern.isEmpty()) {
throw new NullPointerException("Pattern cannot be empty or null");
}
- append = (null == a) ? getBooleanProperty(className + ".append",
+ append = (a == null) ? getBooleanProperty(className + ".append",
DEFAULT_APPEND) : a.booleanValue();
- count = (null == c) ? getIntProperty(className + ".count",
+ count = (c == null) ? getIntProperty(className + ".count",
DEFAULT_COUNT) : c.intValue();
- limit = (null == l) ? getIntProperty(className + ".limit",
+ limit = (l == null) ? getIntProperty(className + ".limit",
DEFAULT_LIMIT) : l.intValue();
count = count < 1 ? DEFAULT_COUNT : count;
limit = limit < 0 ? DEFAULT_LIMIT : limit;
@@ -341,7 +338,7 @@ public class FileHandler extends StreamHandler {
// value
private boolean getBooleanProperty(String key, boolean defaultValue) {
String property = manager.getProperty(key);
- if (null == property) {
+ if (property == null) {
return defaultValue;
}
boolean result = defaultValue;
@@ -363,7 +360,7 @@ public class FileHandler extends StreamHandler {
private int getIntProperty(String key, int defaultValue) {
String property = manager.getProperty(key);
int result = defaultValue;
- if (null != property) {
+ if (property != null) {
try {
result = Integer.parseInt(property);
} catch (Exception e) {
diff --git a/luni/src/main/java/java/util/logging/Formatter.java b/luni/src/main/java/java/util/logging/Formatter.java
index 2ad4b4f..5e8d98e 100644
--- a/luni/src/main/java/java/util/logging/Formatter.java
+++ b/luni/src/main/java/java/util/logging/Formatter.java
@@ -65,21 +65,20 @@ public abstract class Formatter {
String pattern = r.getMessage();
ResourceBundle rb = null;
// try to localize the message string first
- if (null != (rb = r.getResourceBundle())) {
+ if ((rb = r.getResourceBundle()) != null) {
try {
pattern = rb.getString(pattern);
} catch (Exception e) {
pattern = r.getMessage();
}
}
- if (null != pattern) {
+ if (pattern != null) {
Object[] params = r.getParameters();
/*
* if the message contains "{0", use java.text.MessageFormat to
* format the string
*/
- if (pattern.indexOf("{0") >= 0 && null != params
- && params.length > 0) {
+ if (pattern.indexOf("{0") >= 0 && params != null && params.length > 0) {
try {
pattern = MessageFormat.format(pattern, params);
} catch (IllegalArgumentException e) {
diff --git a/luni/src/main/java/java/util/logging/Handler.java b/luni/src/main/java/java/util/logging/Handler.java
index 5a3937d..21e77d7 100644
--- a/luni/src/main/java/java/util/logging/Handler.java
+++ b/luni/src/main/java/java/util/logging/Handler.java
@@ -66,7 +66,7 @@ public abstract class Handler {
// get a instance from given class name, using Class.forName()
private Object getDefaultInstance(String className) {
Object result = null;
- if (null == className) {
+ if (className == null) {
return result;
}
try {
@@ -83,9 +83,8 @@ public abstract class Handler {
Class<?> c = AccessController
.doPrivileged(new PrivilegedExceptionAction<Class<?>>() {
public Class<?> run() throws Exception {
- ClassLoader loader = Thread.currentThread()
- .getContextClassLoader();
- if (null == loader) {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
return loader.loadClass(className);
@@ -110,7 +109,7 @@ public abstract class Handler {
// set filter
final String filterName = manager.getProperty(prefix + ".filter");
- if (null != filterName) {
+ if (filterName != null) {
try {
filter = (Filter) getCustomizeInstance(filterName);
} catch (Exception e1) {
@@ -123,7 +122,7 @@ public abstract class Handler {
// set level
String levelName = manager.getProperty(prefix + ".level");
- if (null != levelName) {
+ if (levelName != null) {
try {
level = Level.parse(levelName);
} catch (Exception e) {
@@ -136,7 +135,7 @@ public abstract class Handler {
// set formatter
final String formatterName = manager.getProperty(prefix + ".formatter");
- if (null != formatterName) {
+ if (formatterName != null) {
try {
formatter = (Formatter) getCustomizeInstance(formatterName);
} catch (Exception e) {
@@ -242,13 +241,13 @@ public abstract class Handler {
* otherwise {@code false}.
*/
public boolean isLoggable(LogRecord record) {
- if (null == record) {
+ if (record == null) {
throw new NullPointerException();
}
if (this.level.intValue() == Level.OFF.intValue()) {
return false;
} else if (record.getLevel().intValue() >= this.level.intValue()) {
- return null == this.filter || this.filter.isLoggable(record);
+ return this.filter == null || this.filter.isLoggable(record);
}
return false;
}
@@ -324,7 +323,7 @@ public abstract class Handler {
*/
public void setErrorManager(ErrorManager em) {
LogManager.getLogManager().checkAccess();
- if (null == em) {
+ if (em == null) {
throw new NullPointerException();
}
this.errorMan = em;
@@ -352,7 +351,7 @@ public abstract class Handler {
* the formatter to set.
*/
void internalSetFormatter(Formatter newFormatter) {
- if (null == newFormatter) {
+ if (newFormatter == null) {
throw new NullPointerException();
}
this.formatter = newFormatter;
@@ -387,7 +386,7 @@ public abstract class Handler {
* have the required permission.
*/
public void setLevel(Level newLevel) {
- if (null == newLevel) {
+ if (newLevel == null) {
throw new NullPointerException();
}
LogManager.getLogManager().checkAccess();
diff --git a/luni/src/main/java/java/util/logging/LogManager.java b/luni/src/main/java/java/util/logging/LogManager.java
index d4c96fb..fac3602 100644
--- a/luni/src/main/java/java/util/logging/LogManager.java
+++ b/luni/src/main/java/java/util/logging/LogManager.java
@@ -37,6 +37,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
+import libcore.io.IoUtils;
/**
* {@code LogManager} is used to maintain configuration properties of the
@@ -162,10 +163,10 @@ public class LogManager {
public Object run() {
String className = System.getProperty("java.util.logging.manager");
- if (null != className) {
+ if (className != null) {
manager = (LogManager) getInstanceByClass(className);
}
- if (null == manager) {
+ if (manager == null) {
manager = new LogManager();
}
@@ -233,7 +234,7 @@ public class LogManager {
* {@code LoggingPermission("control")}
*/
public void checkAccess() {
- if (null != System.getSecurityManager()) {
+ if (System.getSecurityManager() != null) {
System.getSecurityManager().checkPermission(perm);
}
}
@@ -257,7 +258,7 @@ public class LogManager {
*/
public synchronized boolean addLogger(Logger logger) {
String name = logger.getName();
- if (null != loggers.get(name)) {
+ if (loggers.get(name) != null) {
return false;
}
addToFamilyTree(logger, name);
@@ -284,7 +285,7 @@ public class LogManager {
break;
}
}
- if (parent == null && null != (parent = loggers.get(""))) {
+ if (parent == null && (parent = loggers.get("")) != null) {
setParent(logger, parent);
}
@@ -304,7 +305,7 @@ public class LogManager {
return null;
}
});
- if (null != oldParent) {
+ if (oldParent != null) {
// -- remove from old parent as the parent has been changed
oldParent.children.remove(child);
}
@@ -368,12 +369,11 @@ public class LogManager {
public void readConfiguration() throws IOException {
// check config class
String configClassName = System.getProperty("java.util.logging.config.class");
- if (null == configClassName
- || null == getInstanceByClass(configClassName)) {
+ if (configClassName == null || getInstanceByClass(configClassName) == null) {
// if config class failed, check config file
String configFile = System.getProperty("java.util.logging.config.file");
- if (null == configFile) {
+ if (configFile == null) {
// if cannot find configFile, use default logging.properties
configFile = System.getProperty("java.home") + File.separator + "lib" +
File.separator + "logging.properties";
@@ -381,27 +381,18 @@ public class LogManager {
InputStream input = null;
try {
- // BEGIN android-removed
- // input = new BufferedInputStream(new FileInputStream(configFile));
- // END android-removed
-
- // BEGIN android-added
try {
- input = new BufferedInputStream(new FileInputStream(configFile));
- } catch (Exception ex) {
- // consult fixed resource as a last resort
- input = new BufferedInputStream(
- getClass().getResourceAsStream("logging.properties"));
- }
- // END android-added
- readConfiguration(input);
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (Exception e) {// ignore
+ input = new FileInputStream(configFile);
+ } catch (IOException exception) {
+ // fall back to using the built-in logging.properties file
+ input = LogManager.class.getResourceAsStream("logging.properties");
+ if (input == null) {
+ throw exception;
}
}
+ readConfiguration(new BufferedInputStream(input));
+ } finally {
+ IoUtils.closeQuietly(input);
}
}
}
@@ -448,7 +439,7 @@ public class LogManager {
// parse property "config" and apply setting
String configs = props.getProperty("config");
- if (null != configs) {
+ if (configs != null) {
StringTokenizer st = new StringTokenizer(configs, " ");
while (st.hasMoreTokens()) {
String configerName = st.nextToken();
@@ -460,7 +451,7 @@ public class LogManager {
Collection<Logger> allLoggers = loggers.values();
for (Logger logger : allLoggers) {
String property = props.getProperty(logger.getName() + ".level");
- if (null != property) {
+ if (property != null) {
logger.setLevel(Level.parse(property));
}
}
@@ -511,7 +502,7 @@ public class LogManager {
}
}
Logger root = loggers.get("");
- if (null != root) {
+ if (root != null) {
root.setLevel(Level.INFO);
}
}
diff --git a/luni/src/main/java/java/util/logging/LogRecord.java b/luni/src/main/java/java/util/logging/LogRecord.java
index 0a9e2fb..fd34eb4 100644
--- a/luni/src/main/java/java/util/logging/LogRecord.java
+++ b/luni/src/main/java/java/util/logging/LogRecord.java
@@ -162,7 +162,7 @@ public class LogRecord implements Serializable {
synchronized (LogRecord.class) {
this.sequenceNumber = currentSequenceNumber++;
Integer id = currentThreadId.get();
- if (null == id) {
+ if (id == null) {
this.threadID = initThreadId;
currentThreadId.set(Integer.valueOf(initThreadId++));
} else {
@@ -465,12 +465,12 @@ public class LogRecord implements Serializable {
out.defaultWriteObject();
out.writeByte(MAJOR);
out.writeByte(MINOR);
- if (null == parameters) {
+ if (parameters == null) {
out.writeInt(-1);
} else {
out.writeInt(parameters.length);
for (Object element : parameters) {
- out.writeObject(null == element ? null : element.toString());
+ out.writeObject((element == null) ? null : element.toString());
}
}
}
@@ -495,7 +495,7 @@ public class LogRecord implements Serializable {
parameters[i] = in.readObject();
}
}
- if (null != resourceBundleName) {
+ if (resourceBundleName != null) {
try {
resourceBundle = Logger.loadResourceBundle(resourceBundleName);
} catch (MissingResourceException e) {
diff --git a/luni/src/main/java/java/util/logging/MemoryHandler.java b/luni/src/main/java/java/util/logging/MemoryHandler.java
index 08c36c9..4e7be49 100644
--- a/luni/src/main/java/java/util/logging/MemoryHandler.java
+++ b/luni/src/main/java/java/util/logging/MemoryHandler.java
@@ -109,7 +109,7 @@ public class MemoryHandler extends Handler {
}
// init size
String sizeString = manager.getProperty(className + ".size");
- if (null != sizeString) {
+ if (sizeString != null) {
try {
size = Integer.parseInt(sizeString);
if (size <= 0) {
@@ -121,7 +121,7 @@ public class MemoryHandler extends Handler {
}
// init push level
String pushName = manager.getProperty(className + ".push");
- if (null != pushName) {
+ if (pushName != null) {
try {
push = Level.parse(pushName);
} catch (Exception e) {
@@ -246,13 +246,13 @@ public class MemoryHandler extends Handler {
*/
public void push() {
for (int i = cursor; i < size; i++) {
- if (null != buffer[i]) {
+ if (buffer[i] != null) {
target.publish(buffer[i]);
}
buffer[i] = null;
}
for (int i = 0; i < cursor; i++) {
- if (null != buffer[i]) {
+ if (buffer[i] != null) {
target.publish(buffer[i]);
}
buffer[i] = null;
diff --git a/luni/src/main/java/java/util/logging/SimpleFormatter.java b/luni/src/main/java/java/util/logging/SimpleFormatter.java
index d93742c..38672e7 100644
--- a/luni/src/main/java/java/util/logging/SimpleFormatter.java
+++ b/luni/src/main/java/java/util/logging/SimpleFormatter.java
@@ -21,6 +21,7 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.MessageFormat;
import java.util.Date;
+import libcore.io.IoUtils;
/**
* {@code SimpleFormatter} can be used to print a summary of the information
@@ -52,7 +53,7 @@ public class SimpleFormatter extends Formatter {
LogManager.getSystemLineSeparator());
sb.append(r.getLevel().getName()).append(": ");
sb.append(formatMessage(r)).append(LogManager.getSystemLineSeparator());
- if (null != r.getThrown()) {
+ if (r.getThrown() != null) {
sb.append("Throwable occurred: ");
Throwable t = r.getThrown();
PrintWriter pw = null;
@@ -62,13 +63,7 @@ public class SimpleFormatter extends Formatter {
t.printStackTrace(pw);
sb.append(sw.toString());
} finally {
- if (pw != null) {
- try {
- pw.close();
- } catch (Exception e) {
- // ignore
- }
- }
+ IoUtils.closeQuietly(pw);
}
}
return sb.toString();
diff --git a/luni/src/main/java/java/util/logging/SocketHandler.java b/luni/src/main/java/java/util/logging/SocketHandler.java
index f227bc2..bcaee09 100644
--- a/luni/src/main/java/java/util/logging/SocketHandler.java
+++ b/luni/src/main/java/java/util/logging/SocketHandler.java
@@ -143,7 +143,7 @@ public class SocketHandler extends StreamHandler {
public void close() {
try {
super.close();
- if (null != this.socket) {
+ if (this.socket != null) {
this.socket.close();
this.socket = null;
}
diff --git a/luni/src/main/java/java/util/logging/StreamHandler.java b/luni/src/main/java/java/util/logging/StreamHandler.java
index eec3e38..42a02a3 100644
--- a/luni/src/main/java/java/util/logging/StreamHandler.java
+++ b/luni/src/main/java/java/util/logging/StreamHandler.java
@@ -119,7 +119,7 @@ public class StreamHandler extends Handler {
// initialize the writer
private void initializeWriter() {
this.writerNotInitialized = false;
- if (null == getEncoding()) {
+ if (getEncoding() == null) {
this.writer = new OutputStreamWriter(this.os);
} else {
try {
@@ -169,7 +169,7 @@ public class StreamHandler extends Handler {
* if {@code os} is {@code null}.
*/
protected void setOutputStream(OutputStream os) {
- if (null == os) {
+ if (os == null) {
throw new NullPointerException();
}
LogManager.getLogManager().checkAccess();
@@ -198,8 +198,8 @@ public class StreamHandler extends Handler {
this.flush();
super.setEncoding(encoding);
// renew writer only if the writer exists
- if (null != this.writer) {
- if (null == getEncoding()) {
+ if (this.writer != null) {
+ if (getEncoding() == null) {
this.writer = new OutputStreamWriter(this.os);
} else {
try {
@@ -223,7 +223,7 @@ public class StreamHandler extends Handler {
* whether to close the underlying output stream.
*/
void close(boolean closeStream) {
- if (null != this.os) {
+ if (this.os != null) {
if (this.writerNotInitialized) {
initializeWriter();
}
@@ -263,9 +263,9 @@ public class StreamHandler extends Handler {
*/
@Override
public void flush() {
- if (null != this.os) {
+ if (this.os != null) {
try {
- if (null != this.writer) {
+ if (this.writer != null) {
this.writer.flush();
} else {
this.os.flush();
@@ -329,10 +329,10 @@ public class StreamHandler extends Handler {
*/
@Override
public boolean isLoggable(LogRecord record) {
- if (null == record) {
+ if (record == null) {
return false;
}
- if (null != this.os && super.isLoggable(record)) {
+ if (this.os != null && super.isLoggable(record)) {
return true;
}
return false;
diff --git a/luni/src/main/java/java/util/logging/XMLFormatter.java b/luni/src/main/java/java/util/logging/XMLFormatter.java
index b83eeba..5e461c4 100644
--- a/luni/src/main/java/java/util/logging/XMLFormatter.java
+++ b/luni/src/main/java/java/util/logging/XMLFormatter.java
@@ -68,18 +68,18 @@ public class XMLFormatter extends Formatter {
("</millis>")).append(lineSeperator);
sb.append(indent).append(("<sequence>")).append(r.getSequenceNumber())
.append(("</sequence>")).append(lineSeperator);
- if (null != r.getLoggerName()) {
+ if (r.getLoggerName() != null) {
sb.append(indent).append(("<logger>")).append(r.getLoggerName())
.append(("</logger>")).append(lineSeperator);
}
sb.append(indent).append(("<level>")).append(r.getLevel().getName())
.append(("</level>")).append(lineSeperator);
- if (null != r.getSourceClassName()) {
+ if (r.getSourceClassName() != null) {
sb.append(indent).append(("<class>"))
.append(r.getSourceClassName()).append(("</class>"))
.append(lineSeperator);
}
- if (null != r.getSourceMethodName()) {
+ if (r.getSourceMethodName() != null) {
sb.append(indent).append(("<method>")).append(
r.getSourceMethodName()).append(("</method>")).append(
lineSeperator);
@@ -105,7 +105,7 @@ public class XMLFormatter extends Formatter {
// to parse pattern string
ResourceBundle rb = r.getResourceBundle();
String pattern = r.getMessage();
- if (null != rb && null != pattern) {
+ if (rb != null && pattern != null) {
String message;
try {
message = rb.getString(pattern);
@@ -126,7 +126,7 @@ public class XMLFormatter extends Formatter {
r.getResourceBundleName()).append(("</catalog>"))
.append(lineSeperator);
}
- } else if (null != pattern) {
+ } else if (pattern != null) {
sb.append(indent).append(("<message>")).append(pattern).append(
("</message>")).append(lineSeperator);
} else {
@@ -175,10 +175,10 @@ public class XMLFormatter extends Formatter {
@Override
public String getHead(Handler h) {
String encoding = null;
- if (null != h) {
+ if (h != null) {
encoding = h.getEncoding();
}
- if (null == encoding) {
+ if (encoding == null) {
encoding = getSystemProperty("file.encoding");
}
StringBuilder sb = new StringBuilder();
diff --git a/luni/src/main/java/java/util/prefs/AbstractPreferences.java b/luni/src/main/java/java/util/prefs/AbstractPreferences.java
index 57d8fb0..1ae2565 100644
--- a/luni/src/main/java/java/util/prefs/AbstractPreferences.java
+++ b/luni/src/main/java/java/util/prefs/AbstractPreferences.java
@@ -30,6 +30,7 @@ import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import org.apache.harmony.luni.util.Base64;
+import libcore.base.EmptyArray;
/**
* This abstract class is a partial implementation of the abstract class
@@ -91,9 +92,6 @@ public abstract class AbstractPreferences extends Preferences {
* Instance fields (private)
* -----------------------------------------------------------
*/
- /** Marker class for 'lock' field. */
- private static class Lock {}
-
/**
* The object used to lock this node.
*/
@@ -146,17 +144,17 @@ public abstract class AbstractPreferences extends Preferences {
* parent} is not {@code null}.
*/
protected AbstractPreferences(AbstractPreferences parent, String name) {
- if ((null == parent ^ name.length() == 0) || name.indexOf("/") >= 0) {
+ if ((parent == null ^ name.length() == 0) || name.indexOf("/") >= 0) {
throw new IllegalArgumentException();
}
- root = null == parent ? this : parent.root;
+ root = (parent == null) ? this : parent.root;
nodeChangeListeners = new LinkedList<EventListener>();
preferenceChangeListeners = new LinkedList<EventListener>();
isRemoved = false;
cachedNode = new HashMap<String, AbstractPreferences>();
nodeName = name;
parentPref = parent;
- lock = new Lock();
+ lock = new Object();
userNode = root.userNode;
}
@@ -442,7 +440,7 @@ public abstract class AbstractPreferences extends Preferences {
return deflt;
}
if (svalue.length() == 0) {
- return new byte[0];
+ return EmptyArray.BYTE;
}
try {
byte[] bavalue = svalue.getBytes(Charsets.US_ASCII);
@@ -565,7 +563,7 @@ public abstract class AbstractPreferences extends Preferences {
String[] names = path.split("/");
AbstractPreferences currentNode = this;
AbstractPreferences temp = null;
- if (null != currentNode) {
+ if (currentNode != null) {
for (int i = 0; i < names.length; i++) {
String name = names[i];
synchronized (currentNode.lock) {
@@ -575,7 +573,7 @@ public abstract class AbstractPreferences extends Preferences {
}
}
currentNode = temp;
- if (null == currentNode) {
+ if (currentNode == null) {
break;
}
}
@@ -603,7 +601,7 @@ public abstract class AbstractPreferences extends Preferences {
@Override
public boolean nodeExists(String name) throws BackingStoreException {
- if (null == name) {
+ if (name == null) {
throw new NullPointerException();
}
AbstractPreferences startNode = null;
@@ -627,7 +625,7 @@ public abstract class AbstractPreferences extends Preferences {
}
try {
Preferences result = startNode.nodeImpl(name, false);
- return null == result ? false : true;
+ return (result != null);
} catch(IllegalArgumentException e) {
return false;
}
@@ -647,7 +645,7 @@ public abstract class AbstractPreferences extends Preferences {
@Override
public void put(String key, String value) {
- if (null == key || null == value) {
+ if (key == null || value == null) {
throw new NullPointerException();
}
if (key.length() > MAX_KEY_LENGTH || value.length() > MAX_VALUE_LENGTH) {
@@ -719,7 +717,7 @@ public abstract class AbstractPreferences extends Preferences {
checkState();
String[] childrenNames = childrenNamesSpi();
for (int i = 0; i < childrenNames.length; i++) {
- if (null == cachedNode.get(childrenNames[i])) {
+ if (cachedNode.get(childrenNames[i]) == null) {
AbstractPreferences child = childSpi(childrenNames[i]);
cachedNode.put(childrenNames[i], child);
}
@@ -741,7 +739,7 @@ public abstract class AbstractPreferences extends Preferences {
@Override
public void addNodeChangeListener(NodeChangeListener ncl) {
- if (null == ncl) {
+ if (ncl == null) {
throw new NullPointerException();
}
checkState();
@@ -752,7 +750,7 @@ public abstract class AbstractPreferences extends Preferences {
@Override
public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
- if (null == pcl) {
+ if (pcl == null) {
throw new NullPointerException();
}
checkState();
diff --git a/luni/src/main/java/java/util/prefs/FilePreferencesImpl.java b/luni/src/main/java/java/util/prefs/FilePreferencesImpl.java
index 5c10dca..0fd8466 100644
--- a/luni/src/main/java/java/util/prefs/FilePreferencesImpl.java
+++ b/luni/src/main/java/java/util/prefs/FilePreferencesImpl.java
@@ -139,7 +139,7 @@ class FilePreferencesImpl extends AbstractPreferences {
}
});
- if (null == names) {// file is not a directory, exception case
+ if (names == null) {// file is not a directory, exception case
throw new BackingStoreException("Cannot get child names for " + toString()
+ " (path is " + path + ")");
}
@@ -184,7 +184,7 @@ class FilePreferencesImpl extends AbstractPreferences {
@Override
protected String getSpi(String key) {
try {
- if (null == prefs) {
+ if (prefs == null) {
prefs = XMLParser.loadFilePrefs(prefsFile);
}
return prefs.getProperty(key);
diff --git a/luni/src/main/java/java/util/prefs/Preferences.java b/luni/src/main/java/java/util/prefs/Preferences.java
index 707b3ba..94eb2ab 100644
--- a/luni/src/main/java/java/util/prefs/Preferences.java
+++ b/luni/src/main/java/java/util/prefs/Preferences.java
@@ -828,10 +828,9 @@ public abstract class Preferences {
//check the RuntimePermission("preferences")
private static void checkSecurity() {
SecurityManager manager = System.getSecurityManager();
- if(null != manager){
+ if (manager != null){
manager.checkPermission(PREFS_PERM);
}
-
}
/**
@@ -862,7 +861,7 @@ public abstract class Preferences {
//parse node's absolute path from class instance
private static String getNodeName(Class<?> c){
Package p = c.getPackage();
- if(null == p){
+ if (p == null){
return "/<unnamed>";
}
return "/"+p.getName().replace('.', '/');
diff --git a/luni/src/main/java/java/util/prefs/XMLParser.java b/luni/src/main/java/java/util/prefs/XMLParser.java
index 1a108fc..4934212 100644
--- a/luni/src/main/java/java/util/prefs/XMLParser.java
+++ b/luni/src/main/java/java/util/prefs/XMLParser.java
@@ -21,12 +21,14 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.io.Reader;
import java.io.StringReader;
-import java.io.Writer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.security.AccessController;
@@ -40,6 +42,8 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
+import libcore.base.EmptyArray;
+import libcore.io.IoUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -85,11 +89,6 @@ class XMLParser {
static final String DOCTYPE = "<!DOCTYPE preferences SYSTEM";
/*
- * empty string array constant
- */
- private static final String[] EMPTY_SARRAY = new String[0];
-
- /*
* Constant - used by FilePreferencesImpl, which is default implementation of Linux platform
*/
private static final String FILE_PREFS = "<!DOCTYPE map SYSTEM 'http://java.sun.com/dtd/preferences.dtd'>";
@@ -488,14 +487,14 @@ class XMLParser {
if (!file.exists()) {
file.getParentFile().mkdirs();
} else if (file.canRead()) {
- InputStream in = null;
+ Reader reader = null;
FileLock lock = null;
try {
- FileInputStream istream = new FileInputStream(file);
- in = new BufferedInputStream(istream);
- FileChannel channel = istream.getChannel();
+ FileInputStream fileInputStream = new FileInputStream(file);
+ reader = new InputStreamReader(fileInputStream, "UTF-8");
+ FileChannel channel = fileInputStream.getChannel();
lock = channel.lock(0L, Long.MAX_VALUE, true);
- Document doc = builder.parse(in);
+ Document doc = builder.parse(new InputSource(reader));
NodeList entries = selectNodeList(doc.getDocumentElement(), "entry");
int length = entries.getLength();
for (int i = 0; i < length; i++) {
@@ -509,7 +508,7 @@ class XMLParser {
} catch (SAXException e) {
} finally {
releaseQuietly(lock);
- closeQuietly(in);
+ IoUtils.closeQuietly(reader);
}
} else {
file.delete();
@@ -545,7 +544,7 @@ class XMLParser {
out.write(FILE_PREFS);
out.newLine();
if (prefs.size() == 0) {
- exportEntries(EMPTY_SARRAY, EMPTY_SARRAY, out);
+ exportEntries(EmptyArray.STRING, EmptyArray.STRING, out);
} else {
String[] keys = prefs.keySet().toArray(new String[prefs.size()]);
int length = keys.length;
@@ -558,7 +557,7 @@ class XMLParser {
out.flush();
} finally {
releaseQuietly(lock);
- closeQuietly(out);
+ IoUtils.closeQuietly(out);
}
}
@@ -570,22 +569,4 @@ class XMLParser {
lock.release();
} catch (IOException e) {}
}
-
- private static void closeQuietly(Writer out) {
- if (out == null) {
- return;
- }
- try {
- out.close();
- } catch (IOException e) {}
- }
-
- private static void closeQuietly(InputStream in) {
- if (in == null) {
- return;
- }
- try {
- in.close();
- } catch (IOException e) {}
- }
}
diff --git a/luni/src/main/java/java/util/zip/Adler32.java b/luni/src/main/java/java/util/zip/Adler32.java
index 7682ef9..1dd14da 100644
--- a/luni/src/main/java/java/util/zip/Adler32.java
+++ b/luni/src/main/java/java/util/zip/Adler32.java
@@ -17,12 +17,14 @@
package java.util.zip;
+import java.util.Arrays;
+
/**
* The Adler-32 class is used to compute the {@code Adler32} checksum from a set
* of data. Compared to {@link CRC32} it trades reliability for speed.
* Refer to RFC 1950 for the specification.
*/
-public class Adler32 implements java.util.zip.Checksum {
+public class Adler32 implements Checksum {
private long adler = 1;
@@ -65,29 +67,14 @@ public class Adler32 implements java.util.zip.Checksum {
/**
* Update this {@code Adler32} checksum with the contents of {@code buf},
- * starting from the offset provided and reading n bytes of data.
- *
- * @param buf
- * buffer to obtain data from.
- * @param off
- * offset in {@code buf} to start reading from.
- * @param nbytes
- * number of bytes from {@code buf} to use.
- * @throws ArrayIndexOutOfBoundsException
- * if {@code offset > buf.length} or {@code nbytes} is negative
- * or {@code offset + nbytes > buf.length}.
+ * starting from {@code offset} and reading {@code byteCount} bytes of data.
*/
- public void update(byte[] buf, int off, int nbytes) {
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- adler = updateImpl(buf, off, nbytes, adler);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public void update(byte[] buf, int offset, int byteCount) {
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ adler = updateImpl(buf, offset, byteCount, adler);
}
- private native long updateImpl(byte[] buf, int off, int nbytes, long adler1);
+ private native long updateImpl(byte[] buf, int offset, int byteCount, long adler1);
private native long updateByteImpl(int val, long adler1);
}
diff --git a/luni/src/main/java/java/util/zip/CRC32.java b/luni/src/main/java/java/util/zip/CRC32.java
index 8fc6bb7..5d0dbd4 100644
--- a/luni/src/main/java/java/util/zip/CRC32.java
+++ b/luni/src/main/java/java/util/zip/CRC32.java
@@ -17,11 +17,13 @@
package java.util.zip;
+import java.util.Arrays;
+
/**
* The CRC32 class is used to compute a CRC32 checksum from data provided as
- * input value.
+ * input value. See also {@link Adler32} which is almost as good, but cheaper.
*/
-public class CRC32 implements java.util.zip.Checksum {
+public class CRC32 implements Checksum {
private long crc = 0L;
@@ -65,28 +67,16 @@ public class CRC32 implements java.util.zip.Checksum {
}
/**
- * Updates this checksum with n bytes of data obtained from buffer {@code
- * buf}, starting at offset {@code off}.
- *
- * @param buf
- * the buffer to update the checksum.
- * @param off
- * the offset in {@code buf} to obtain data from.
- * @param nbytes
- * the number of bytes to read from {@code buf}.
+ * Update this {@code CRC32} checksum with the contents of {@code buf},
+ * starting from {@code offset} and reading {@code byteCount} bytes of data.
*/
- public void update(byte[] buf, int off, int nbytes) {
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- tbytes += nbytes;
- crc = updateImpl(buf, off, nbytes, crc);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public void update(byte[] buf, int offset, int byteCount) {
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ tbytes += byteCount;
+ crc = updateImpl(buf, offset, byteCount, crc);
}
- private native long updateImpl(byte[] buf, int off, int nbytes, long crc1);
+ private native long updateImpl(byte[] buf, int offset, int byteCount, long crc1);
private native long updateByteImpl(byte val, long crc1);
}
diff --git a/luni/src/main/java/java/util/zip/CheckedInputStream.java b/luni/src/main/java/java/util/zip/CheckedInputStream.java
index 296ddd7..f2f3407 100644
--- a/luni/src/main/java/java/util/zip/CheckedInputStream.java
+++ b/luni/src/main/java/java/util/zip/CheckedInputStream.java
@@ -19,6 +19,7 @@ package java.util.zip;
import java.io.IOException;
import java.io.InputStream;
+import libcore.base.Streams;
/**
* The {@code CheckedInputStream} class is used to maintain a checksum at the
@@ -102,32 +103,15 @@ public class CheckedInputStream extends java.io.FilterInputStream {
}
/**
- * Skip up to n bytes of data on the underlying input stream. Any skipped
- * bytes are added to the running checksum value.
+ * Skip up to {@code byteCount} bytes of data on the underlying input
+ * stream. Any skipped bytes are added to the running checksum value.
*
- * @param nbytes
- * the number of bytes to skip.
- * @throws IOException
- * if this stream is closed or another I/O error occurs.
+ * @param byteCount the number of bytes to skip.
+ * @throws IOException if this stream is closed or another I/O error occurs.
* @return the number of bytes skipped.
*/
@Override
- public long skip(long nbytes) throws IOException {
- if (nbytes < 1) {
- return 0;
- }
- long skipped = 0;
- byte[] b = new byte[(int)Math.min(nbytes, 2048L)];
- int x, v;
- while (skipped != nbytes) {
- x = in.read(b, 0,
- (v = (int) (nbytes - skipped)) > b.length ? b.length : v);
- if (x == -1) {
- return skipped;
- }
- check.update(b, 0, x);
- skipped += x;
- }
- return skipped;
+ public long skip(long byteCount) throws IOException {
+ return Streams.skipByReading(this, byteCount);
}
}
diff --git a/luni/src/main/java/java/util/zip/Checksum.java b/luni/src/main/java/java/util/zip/Checksum.java
index fac7e4e..824b85a 100644
--- a/luni/src/main/java/java/util/zip/Checksum.java
+++ b/luni/src/main/java/java/util/zip/Checksum.java
@@ -18,8 +18,7 @@
package java.util.zip;
/**
- * Holds information about a checksum which was computed with the methods
- * implementing a checksum algorithm.
+ * The interface common to checksum classes such as {@link Adler32} and {@link CRC32}.
*/
public interface Checksum {
diff --git a/luni/src/main/java/java/util/zip/Deflater.java b/luni/src/main/java/java/util/zip/Deflater.java
index 4ac5c47..bb0d228 100644
--- a/luni/src/main/java/java/util/zip/Deflater.java
+++ b/luni/src/main/java/java/util/zip/Deflater.java
@@ -17,21 +17,39 @@
package java.util.zip;
+import dalvik.system.CloseGuard;
+import java.util.Arrays;
+import libcore.base.EmptyArray;
/**
* This class compresses data using the <i>DEFLATE</i> algorithm (see <a
* href="http://www.gzip.org/algorithm.txt">specification</a>).
- * <p>
- * Basically this class is part of the API to the stream based ZLIB compression
- * library and is used as such by {@code DeflaterOutputStream} and its
- * descendants.
- * <p>
- * The typical usage of a {@code Deflater} instance outside this package
- * consists of a specific call to one of its constructors before being passed to
- * an instance of {@code DeflaterOutputStream}.
*
- * @see DeflaterOutputStream
- * @see Inflater
+ * <p>It is usually more convenient to use {@link DeflaterOutputStream}.
+ *
+ * <p>To compress an in-memory {@code byte[]} to another in-memory {@code byte[]} manually:
+ * <pre>
+ * byte[] originalBytes = ...
+ *
+ * Deflater deflater = new Deflater();
+ * deflater.setInput(originalBytes);
+ * deflater.finish();
+ *
+ * ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ * byte[] buf = new byte[8192];
+ * while (!deflater.finished()) {
+ * int byteCount = deflater.deflate(buf);
+ * baos.write(buf, 0, byteCount);
+ * }
+ * deflater.end();
+ *
+ * byte[] compressedBytes = baos.toByteArray();
+ * </pre>
+ * <p>In situations where you don't have all the input in one array (or have so much
+ * input that you want to feed it to the deflater in chunks), it's possible to call
+ * {@link #setInput} repeatedly, but you're much better off using {@link DeflaterOutputStream}
+ * to handle all this for you. {@link DeflaterOutputStream} also helps minimize memory
+ * requirements&nbsp;&mdash; the sample code above is very expensive.
*/
public class Deflater {
@@ -46,32 +64,32 @@ public class Deflater {
public static final int BEST_SPEED = 1;
/**
- * Usage of the default compression level.
+ * The default compression level.
*/
public static final int DEFAULT_COMPRESSION = -1;
/**
- * Default value for compression strategy.
+ * The default compression strategy.
*/
public static final int DEFAULT_STRATEGY = 0;
/**
- * Default value for compression method.
+ * The default compression method.
*/
public static final int DEFLATED = 8;
/**
- * Possible value for compression strategy.
+ * A compression strategy.
*/
public static final int FILTERED = 1;
/**
- * Possible value for compression strategy.
+ * A compression strategy.
*/
public static final int HUFFMAN_ONLY = 2;
/**
- * Possible value for compression level.
+ * A compression level.
*/
public static final int NO_COMPRESSION = 0;
@@ -104,14 +122,15 @@ public class Deflater {
public static final int FULL_FLUSH = 3;
/**
- * Flush buffers and mark the end of the datastream.
+ * Flush buffers and mark the end of the data stream.
*/
private static final int FINISH = 4;
- // A stub buffer used when deflate() called while inputBuffer has not been
- // set.
- private static final byte[] STUB_INPUT_BUFFER = new byte[0];
-
+ /**
+ * The ugly name flushParm is for RI compatibility, should code need to access this
+ * field via reflection if it's not able to use public API to choose what
+ * kind of flushing it gets.
+ */
private int flushParm = NO_FLUSH;
private boolean finished;
@@ -128,21 +147,23 @@ public class Deflater {
private int inLength;
+ private final CloseGuard guard = CloseGuard.get();
+
/**
- * Constructs a new {@code Deflater} instance with default compression
- * level. The strategy can be specified with {@link #setStrategy}, only. A
- * header is added to the output by default; use constructor {@code
- * Deflater(level, boolean)} if you need to omit the header.
+ * Constructs a new {@code Deflater} instance using the default compression
+ * level. The strategy can be specified with {@link #setStrategy}. A
+ * header is added to the output by default; use {@link
+ * #Deflater(int, boolean)} if you need to omit the header.
*/
public Deflater() {
this(DEFAULT_COMPRESSION, false);
}
/**
- * Constructs a new {@code Deflater} instance with a specific compression
- * level. The strategy can be specified with {@code setStrategy}, only. A
- * header is added to the output by default; use
- * {@code Deflater(level, boolean)} if you need to omit the header.
+ * Constructs a new {@code Deflater} instance using compression
+ * level {@code level}. The strategy can be specified with {@link #setStrategy}.
+ * A header is added to the output by default; use
+ * {@link #Deflater(int, boolean)} if you need to omit the header.
*
* @param level
* the compression level in the range between 0 and 9.
@@ -153,9 +174,9 @@ public class Deflater {
/**
* Constructs a new {@code Deflater} instance with a specific compression
- * level. If noHeader is passed as true no ZLib header is added to the
+ * level. If {@code noHeader} is true, no ZLIB header is added to the
* output. In a ZIP archive every entry (compressed file) comes with such a
- * header. The strategy can be specified with the setStrategy method, only.
+ * header. The strategy can be specified using {@link #setStrategy}.
*
* @param level
* the compression level in the range between 0 and 9.
@@ -169,88 +190,68 @@ public class Deflater {
}
compressLevel = level;
streamHandle = createStream(compressLevel, strategy, noHeader);
+ guard.open("end");
}
/**
- * Deflates the data (previously passed to {@code setInput}) into the
+ * Deflates the data (previously passed to {@link #setInput}) into the
* supplied buffer.
*
- * @param buf
- * buffer to write compressed data to.
* @return number of bytes of compressed data written to {@code buf}.
- * @see #deflate(byte[], int, int)
*/
public int deflate(byte[] buf) {
return deflate(buf, 0, buf.length);
}
/**
- * Deflates data (previously passed to {@code setInput}) into a specific
+ * Deflates data (previously passed to {@link #setInput}) into a specific
* region within the supplied buffer.
*
- * @param buf
- * the buffer to write compressed data to.
- * @param off
- * the offset within {@code buf} at which to start writing to.
- * @param nbytes
- * maximum number of bytes of compressed data to be written.
* @return the number of bytes of compressed data written to {@code buf}.
*/
- public synchronized int deflate(byte[] buf, int off, int nbytes) {
- return deflateImpl(buf, off, nbytes, flushParm);
+ public synchronized int deflate(byte[] buf, int offset, int byteCount) {
+ return deflateImpl(buf, offset, byteCount, flushParm);
}
/**
- * Deflates data (previously passed to {@code setInput}) into a specific
+ * Deflates data (previously passed to {@link #setInput}) into a specific
* region within the supplied buffer, optionally flushing the input buffer.
*
- * @param buf the buffer to write compressed data to.
- * @param off the offset within {@code buf} at which to start writing to.
- * @param nbytes maximum number of bytes of compressed data to be written.
- * @param flush one of {@link #NO_FLUSH}, {@link #SYNC_FLUSH} or
- * {@link #FULL_FLUSH}.
+ * @param flush one of {@link #NO_FLUSH}, {@link #SYNC_FLUSH} or {@link #FULL_FLUSH}.
* @return the number of compressed bytes written to {@code buf}. If this
- * equals {@code nbytes}, the number of bytes of input to be flushed
+ * equals {@code byteCount}, the number of bytes of input to be flushed
* may have exceeded the output buffer's capacity. In this case,
* finishing a flush will require the output buffer to be drained
* and additional calls to {@link #deflate} to be made.
* @hide
* @since 1.7
*/
- public synchronized int deflate(byte[] buf, int off, int nbytes, int flush) {
+ public synchronized int deflate(byte[] buf, int offset, int byteCount, int flush) {
if (flush != NO_FLUSH && flush != SYNC_FLUSH && flush != FULL_FLUSH) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad flush value: " + flush);
}
- return deflateImpl(buf, off, nbytes, flush);
+ return deflateImpl(buf, offset, byteCount, flush);
}
- private synchronized int deflateImpl(
- byte[] buf, int off, int nbytes, int flush) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- if (off > buf.length || nbytes < 0 || off < 0 || buf.length - off < nbytes) {
- throw new ArrayIndexOutOfBoundsException();
- }
+ private synchronized int deflateImpl(byte[] buf, int offset, int byteCount, int flush) {
+ checkOpen();
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
if (inputBuffer == null) {
- setInput(STUB_INPUT_BUFFER);
+ setInput(EmptyArray.BYTE);
}
- return deflateImpl(buf, off, nbytes, streamHandle, flush);
+ return deflateImpl(buf, offset, byteCount, streamHandle, flush);
}
- private synchronized native int deflateImpl(byte[] buf, int off,
- int nbytes, long handle, int flushParm1);
-
- private synchronized native void endImpl(long handle);
+ private native int deflateImpl(byte[] buf, int offset, int byteCount, long handle, int flushParm);
/**
* Frees all resources held onto by this deflating algorithm. Any unused
- * input or output is discarded. While this method is used by {@code
- * finalize()}, it can be called explicitly in order to free native
- * resources before the next GC cycle. After {@code end()} was called other
- * methods will typically throw an {@code IllegalStateException}.
+ * input or output is discarded. This method should be called explicitly in
+ * order to free native resources as soon as possible. After {@code end()} is
+ * called, other methods will typically throw {@code IllegalStateException}.
*/
public synchronized void end() {
+ guard.close();
endImpl();
}
@@ -262,8 +263,13 @@ public class Deflater {
}
}
+ private native void endImpl(long handle);
+
@Override protected void finalize() {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
synchronized (this) {
end(); // to allow overriding classes to clean up
endImpl(); // in case those classes don't call super.end()
@@ -288,77 +294,48 @@ public class Deflater {
}
/**
- * Returns whether or not all provided data has been successfully
- * compressed.
- *
- * @return true if all data has been compressed, false otherwise.
+ * Returns true if all provided data has been successfully compressed.
*/
public synchronized boolean finished() {
return finished;
}
/**
- * Returns the Adler32 checksum of uncompressed data currently read. If a
- * preset dictionary is used getAdler() will return the Adler32 checksum of
- * the dictionary used.
- *
- * @return the Adler32 checksum of uncompressed data or preset dictionary if
- * used.
- * @see #setDictionary(byte[])
- * @see #setDictionary(byte[], int, int)
+ * Returns the {@link Adler32} checksum of the uncompressed data read so far.
*/
public synchronized int getAdler() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
-
+ checkOpen();
return getAdlerImpl(streamHandle);
}
- private synchronized native int getAdlerImpl(long handle);
+ private native int getAdlerImpl(long handle);
/**
- * Returns the total number of bytes of input consumed by the {@code Deflater}.
- *
- * @return number of bytes of input read.
+ * Returns the total number of bytes of input read by this {@code Deflater}. This
+ * method is limited to 32 bits; use {@link #getBytesRead} instead.
*/
public synchronized int getTotalIn() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
-
+ checkOpen();
return (int) getTotalInImpl(streamHandle);
}
- private synchronized native long getTotalInImpl(long handle);
+ private native long getTotalInImpl(long handle);
/**
- * Returns the total number of compressed bytes output by this {@code Deflater}.
- *
- * @return number of compressed bytes output.
+ * Returns the total number of bytes written to the output buffer by this {@code
+ * Deflater}. The method is limited to 32 bits; use {@link #getBytesWritten} instead.
*/
public synchronized int getTotalOut() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
-
+ checkOpen();
return (int) getTotalOutImpl(streamHandle);
}
- private synchronized native long getTotalOutImpl(long handle);
+ private native long getTotalOutImpl(long handle);
/**
- * Counterpart to setInput(). Indicates whether or not all bytes of
- * uncompressed input have been consumed by the {@code Deflater}. If needsInput()
- * returns true setInput() must be called before deflation can continue. If
- * all bytes of uncompressed data have been provided to the {@code Deflater}
- * finish() must be called to ensure the compressed data is output.
- *
- * @return {@code true} if input is required for deflation to continue,
- * {@code false} otherwise.
- * @see #finished()
- * @see #setInput(byte[])
- * @see #setInput(byte[], int, int)
+ * Returns true if {@link #setInput} must be called before deflation can continue.
+ * If all uncompressed data has been provided to the {@code Deflater},
+ * {@link #finish} must be called to ensure the compressed data is output.
*/
public synchronized boolean needsInput() {
if (inputBuffer == null) {
@@ -370,74 +347,46 @@ public class Deflater {
/**
* Resets the {@code Deflater} to accept new input without affecting any
* previously made settings for the compression strategy or level. This
- * operation <i>must</i> be called after {@code finished()} returns
- * {@code true} if the {@code Deflater} is to be reused.
- *
- * @see #finished
+ * operation <i>must</i> be called after {@link #finished} returns
+ * true if the {@code Deflater} is to be reused.
*/
public synchronized void reset() {
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
-
+ checkOpen();
flushParm = NO_FLUSH;
finished = false;
resetImpl(streamHandle);
inputBuffer = null;
}
- private synchronized native void resetImpl(long handle);
+ private native void resetImpl(long handle);
/**
* Sets the dictionary to be used for compression by this {@code Deflater}.
- * setDictionary() can only be called if this {@code Deflater} supports the writing
- * of ZLIB headers. This is the default behaviour but can be overridden
- * using {@code Deflater(int, boolean)}.
- *
- * @param buf
- * the buffer containing the dictionary data bytes.
- * @see Deflater#Deflater(int, boolean)
+ * This method can only be called if this {@code Deflater} supports the writing
+ * of ZLIB headers. This is the default, but can be overridden
+ * using {@link #Deflater(int, boolean)}.
*/
- public void setDictionary(byte[] buf) {
- setDictionary(buf, 0, buf.length);
+ public void setDictionary(byte[] dictionary) {
+ setDictionary(dictionary, 0, dictionary.length);
}
/**
* Sets the dictionary to be used for compression by this {@code Deflater}.
- * setDictionary() can only be called if this {@code Deflater} supports the writing
- * of ZLIB headers. This is the default behaviour but can be overridden
- * using {@code Deflater(int, boolean)}.
- *
- * @param buf
- * the buffer containing the dictionary data bytes.
- * @param off
- * the offset of the data.
- * @param nbytes
- * the length of the data.
- * @see Deflater#Deflater(int, boolean)
- */
- public synchronized void setDictionary(byte[] buf, int off, int nbytes) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- setDictionaryImpl(buf, off, nbytes, streamHandle);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ * This method can only be called if this {@code Deflater} supports the writing
+ * of ZLIB headers. This is the default, but can be overridden
+ * using {@link #Deflater(int, boolean)}.
+ */
+ public synchronized void setDictionary(byte[] buf, int offset, int byteCount) {
+ checkOpen();
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ setDictionaryImpl(buf, offset, byteCount, streamHandle);
}
- private synchronized native void setDictionaryImpl(byte[] buf, int off,
- int nbytes, long handle);
+ private native void setDictionaryImpl(byte[] buf, int offset, int byteCount, long handle);
/**
* Sets the input buffer the {@code Deflater} will use to extract uncompressed bytes
* for later compression.
- *
- * @param buf
- * the buffer.
*/
public void setInput(byte[] buf) {
setInput(buf, 0, buf.length);
@@ -445,113 +394,85 @@ public class Deflater {
/**
* Sets the input buffer the {@code Deflater} will use to extract uncompressed bytes
- * for later compression. Input will be taken from the buffer region
- * starting at off and ending at nbytes - 1.
- *
- * @param buf
- * the buffer containing the input data bytes.
- * @param off
- * the offset of the data.
- * @param nbytes
- * the length of the data.
- */
- public synchronized void setInput(byte[] buf, int off, int nbytes) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- inLength = nbytes;
- inRead = 0;
- if (inputBuffer == null) {
- setLevelsImpl(compressLevel, strategy, streamHandle);
- }
- inputBuffer = buf;
- setInputImpl(buf, off, nbytes, streamHandle);
- } else {
- throw new ArrayIndexOutOfBoundsException();
+ * for later compression.
+ */
+ public synchronized void setInput(byte[] buf, int offset, int byteCount) {
+ checkOpen();
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ inLength = byteCount;
+ inRead = 0;
+ if (inputBuffer == null) {
+ setLevelsImpl(compressLevel, strategy, streamHandle);
}
+ inputBuffer = buf;
+ setInputImpl(buf, offset, byteCount, streamHandle);
}
- private synchronized native void setLevelsImpl(int level, int strategy,
- long handle);
+ private native void setLevelsImpl(int level, int strategy, long handle);
- private synchronized native void setInputImpl(byte[] buf, int off,
- int nbytes, long handle);
+ private native void setInputImpl(byte[] buf, int offset, int byteCount, long handle);
/**
* Sets the compression level to be used when compressing data. The
* compression level must be a value between 0 and 9. This value must be set
- * prior to calling setInput().
- *
- * @param level
- * compression level to use
+ * prior to calling {@link #setInput}.
* @exception IllegalArgumentException
* If the compression level is invalid.
*/
public synchronized void setLevel(int level) {
if (level < DEFAULT_COMPRESSION || level > BEST_COMPRESSION) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad level: " + level);
}
if (inputBuffer != null) {
- throw new IllegalStateException();
+ throw new IllegalStateException("setLevel cannot be called after setInput");
}
compressLevel = level;
}
/**
* Sets the compression strategy to be used. The strategy must be one of
- * FILTERED, HUFFMAN_ONLY or DEFAULT_STRATEGY.This value must be set prior
- * to calling setInput().
+ * FILTERED, HUFFMAN_ONLY or DEFAULT_STRATEGY. This value must be set prior
+ * to calling {@link #setInput}.
*
- * @param strategy
- * compression strategy to use
* @exception IllegalArgumentException
* If the strategy specified is not one of FILTERED,
* HUFFMAN_ONLY or DEFAULT_STRATEGY.
*/
public synchronized void setStrategy(int strategy) {
if (strategy < DEFAULT_STRATEGY || strategy > HUFFMAN_ONLY) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad strategy: " + strategy);
}
if (inputBuffer != null) {
- throw new IllegalStateException();
+ throw new IllegalStateException("setStrategy cannot be called after setInput");
}
this.strategy = strategy;
}
/**
- * Returns a long int of total number of bytes read by the {@code Deflater}. This
- * method performs the same as {@code getTotalIn} except it returns a long value
- * instead of an integer
- *
- * @see #getTotalIn()
- * @return total number of bytes read by {@code Deflater}.
+ * Returns the total number of bytes read by the {@code Deflater}. This
+ * method is the same as {@link #getTotalIn} except that it returns a
+ * {@code long} value instead of an integer.
*/
public synchronized long getBytesRead() {
- // Throw NPE here
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
+ checkOpen();
return getTotalInImpl(streamHandle);
}
/**
- * Returns a long int of total number of bytes of read by the {@code Deflater}. This
- * method performs the same as {@code getTotalOut} except it returns a long
- * value instead of an integer
- *
- * @see #getTotalOut()
- * @return bytes exactly write by {@code Deflater}
+ * Returns a the total number of bytes written by this {@code Deflater}. This
+ * method is the same as {@code getTotalOut} except it returns a
+ * {@code long} value instead of an integer.
*/
public synchronized long getBytesWritten() {
- // Throw NPE here
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
+ checkOpen();
return getTotalOutImpl(streamHandle);
}
private native long createStream(int level, int strategy1, boolean noHeader1);
+
+ private void checkOpen() {
+ if (streamHandle == -1) {
+ throw new IllegalStateException("attempt to use Deflater after calling end");
+ }
+ }
}
diff --git a/luni/src/main/java/java/util/zip/DeflaterInputStream.java b/luni/src/main/java/java/util/zip/DeflaterInputStream.java
index c0c0f4c..71c5483 100644
--- a/luni/src/main/java/java/util/zip/DeflaterInputStream.java
+++ b/luni/src/main/java/java/util/zip/DeflaterInputStream.java
@@ -20,6 +20,8 @@ package java.util.zip;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
+import libcore.base.Streams;
/**
* An {@code InputStream} filter to compress data. Callers read
@@ -109,27 +111,14 @@ public class DeflaterInputStream extends FilterInputStream {
/**
* Reads compressed data into a byte buffer. The result will be bytes of compressed
* data corresponding to an uncompressed byte or bytes read from the underlying stream.
- *
- * @param b
- * the byte buffer that compressed data will be read into.
- * @param off
- * the offset in the byte buffer where compressed data will start
- * to be read into.
- * @param len
- * the length of the compressed data that is expected to read.
* @return the number of bytes read or -1 if the end of the compressed input
* stream has been reached.
*/
@Override
- public int read(byte[] b, int off, int len) throws IOException {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
checkClosed();
- if (b == null) {
- throw new NullPointerException();
- }
- if (off < 0 || len < 0 || len > b.length - off) {
- throw new IndexOutOfBoundsException();
- }
- if (len == 0) {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (byteCount == 0) {
return 0;
}
@@ -138,22 +127,22 @@ public class DeflaterInputStream extends FilterInputStream {
}
int count = 0;
- while (count < len && !def.finished()) {
+ while (count < byteCount && !def.finished()) {
if (def.needsInput()) {
// read data from input stream
- int byteCount = in.read(buf);
- if (byteCount == -1) {
+ int bytesRead = in.read(buf);
+ if (bytesRead == -1) {
def.finish();
} else {
- def.setInput(buf, 0, byteCount);
+ def.setInput(buf, 0, bytesRead);
}
}
- int byteCount = def.deflate(buf, 0, Math.min(buf.length, len - count));
- if (byteCount == -1) {
+ int bytesDeflated = def.deflate(buf, 0, Math.min(buf.length, byteCount - count));
+ if (bytesDeflated == -1) {
break;
}
- System.arraycopy(buf, 0, b, off + count, byteCount);
- count += byteCount;
+ System.arraycopy(buf, 0, buffer, offset + count, bytesDeflated);
+ count += bytesDeflated;
}
if (count == 0) {
count = -1;
@@ -168,25 +157,9 @@ public class DeflaterInputStream extends FilterInputStream {
* skip {@code Integer.MAX_VALUE} bytes.
*/
@Override
- public long skip(long n) throws IOException {
- if (n < 0) {
- throw new IllegalArgumentException();
- }
- if (n > Integer.MAX_VALUE) {
- n = Integer.MAX_VALUE;
- }
- checkClosed();
-
- int remaining = (int) n;
- byte[] tmp = new byte[Math.min(remaining, DEFAULT_BUFFER_SIZE)];
- while (remaining > 0) {
- int count = read(tmp, 0, Math.min(remaining, tmp.length));
- if (count == -1) {
- break;
- }
- remaining -= count;
- }
- return n - remaining;
+ public long skip(long byteCount) throws IOException {
+ byteCount = Math.min(Integer.MAX_VALUE, byteCount);
+ return Streams.skipByReading(this, byteCount);
}
/**
diff --git a/luni/src/main/java/java/util/zip/DeflaterOutputStream.java b/luni/src/main/java/java/util/zip/DeflaterOutputStream.java
index 7cb47db..a1584bf 100644
--- a/luni/src/main/java/java/util/zip/DeflaterOutputStream.java
+++ b/luni/src/main/java/java/util/zip/DeflaterOutputStream.java
@@ -20,6 +20,7 @@ package java.util.zip;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
/**
* This class provides an implementation of {@code FilterOutputStream} that
@@ -132,10 +133,9 @@ public class DeflaterOutputStream extends FilterOutputStream {
* If an error occurs during deflation.
*/
protected void deflate() throws IOException {
- int x = 0;
do {
- x = def.deflate(buf);
- out.write(buf, 0, x);
+ int byteCount = def.deflate(buf);
+ out.write(buf, 0, byteCount);
} while (!def.needsInput());
}
@@ -150,6 +150,7 @@ public class DeflaterOutputStream extends FilterOutputStream {
*/
@Override
public void close() throws IOException {
+ // everything closed here should also be closed in ZipOutputStream.close()
if (!def.finished()) {
finish();
}
@@ -188,34 +189,22 @@ public class DeflaterOutputStream extends FilterOutputStream {
}
/**
- * Compresses {@code nbytes} of data from {@code buf} starting at
- * {@code off} and writes it to the underlying stream.
- *
- * @param buffer
- * the buffer of data to compress.
- * @param off
- * offset in buffer to extract data from.
- * @param nbytes
- * the number of bytes of data to read from the buffer.
+ * Compresses {@code byteCount} bytes of data from {@code buf} starting at
+ * {@code offset} and writes it to the underlying stream.
* @throws IOException
* If an error occurs during writing.
*/
@Override
- public void write(byte[] buffer, int off, int nbytes) throws IOException {
+ public void write(byte[] buffer, int offset, int byteCount) throws IOException {
if (done) {
throw new IOException("attempt to write after finish");
}
- // avoid int overflow, check null buf
- if (off <= buffer.length && nbytes >= 0 && off >= 0
- && buffer.length - off >= nbytes) {
- if (!def.needsInput()) {
- throw new IOException();
- }
- def.setInput(buffer, off, nbytes);
- deflate();
- } else {
- throw new ArrayIndexOutOfBoundsException();
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ if (!def.needsInput()) {
+ throw new IOException();
}
+ def.setInput(buffer, offset, byteCount);
+ deflate();
}
/**
diff --git a/luni/src/main/java/java/util/zip/GZIPInputStream.java b/luni/src/main/java/java/util/zip/GZIPInputStream.java
index cd51b25..6a8f456 100644
--- a/luni/src/main/java/java/util/zip/GZIPInputStream.java
+++ b/luni/src/main/java/java/util/zip/GZIPInputStream.java
@@ -20,14 +20,31 @@ package java.util.zip;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* The {@code GZIPInputStream} class is used to read data stored in the GZIP
* format, reading and decompressing GZIP data from the underlying stream into
* its buffer.
+ *
+ * <h3>Example</h3>
+ * <p>Using {@code GZIPInputStream} is easier than {@link ZipInputStream}
+ * because GZIP is only for compression, and is not a container for multiple files.
+ * This code decompresses the data from a GZIP stream, similar to the {@code gunzip(1)} utility.
+ * <pre>
+ * InputStream is = ...
+ * GZIPInputStream zis = new GZIPInputStream(new BufferedInputStream(is));
+ * try {
+ * // Reading from 'zis' gets you the uncompressed bytes...
+ * processStream(zis);
+ * } finally {
+ * zis.close();
+ * }
+ * </pre>
*/
public class GZIPInputStream extends InflaterInputStream {
-
private static final int FCOMMENT = 16;
private static final int FEXTRA = 4;
@@ -79,8 +96,8 @@ public class GZIPInputStream extends InflaterInputStream {
super(is, new Inflater(true), size);
byte[] header = new byte[10];
readFully(header, 0, header.length);
- int magic = getShort(header, 0);
- if (magic != GZIP_MAGIC) {
+ short magic = OSMemory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN);
+ if (magic != (short) GZIP_MAGIC) {
throw new IOException(String.format("unknown format (magic number %x)", magic));
}
int flags = header[3];
@@ -93,7 +110,7 @@ public class GZIPInputStream extends InflaterInputStream {
if (hcrc) {
crc.update(header, 0, 2);
}
- int length = getShort(header, 0);
+ int length = OSMemory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN) & 0xffff;
while (length > 0) {
int max = length > buf.length ? buf.length : length;
int result = in.read(buf, 0, max);
@@ -114,8 +131,8 @@ public class GZIPInputStream extends InflaterInputStream {
}
if (hcrc) {
readFully(header, 0, 2);
- int crc16 = getShort(header, 0);
- if ((crc.getValue() & 0xffff) != crc16) {
+ short crc16 = OSMemory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN);
+ if ((short) crc.getValue() != crc16) {
throw new IOException("CRC mismatch");
}
crc.reset();
@@ -131,53 +148,29 @@ public class GZIPInputStream extends InflaterInputStream {
super.close();
}
- private long getLong(byte[] buffer, int off) {
- long l = 0;
- l |= (buffer[off] & 0xFF);
- l |= (buffer[off + 1] & 0xFF) << 8;
- l |= (buffer[off + 2] & 0xFF) << 16;
- l |= ((long) (buffer[off + 3] & 0xFF)) << 24;
- return l;
- }
-
- private int getShort(byte[] buffer, int off) {
- return (buffer[off] & 0xFF) | ((buffer[off + 1] & 0xFF) << 8);
- }
-
/**
* Reads and decompresses GZIP data from the underlying stream into the
* given buffer.
- *
- * @param buffer
- * Buffer to receive data
- * @param off
- * Offset in buffer to store data
- * @param nbytes
- * Number of bytes to read
*/
@Override
- public int read(byte[] buffer, int off, int nbytes) throws IOException {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
if (closed) {
throw new IOException("Stream is closed");
}
if (eos) {
return -1;
}
- // avoid int overflow, check null buffer
- if (off > buffer.length || nbytes < 0 || off < 0
- || buffer.length - off < nbytes) {
- throw new ArrayIndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
int bytesRead;
try {
- bytesRead = super.read(buffer, off, nbytes);
+ bytesRead = super.read(buffer, offset, byteCount);
} finally {
eos = eof; // update eos after every read(), even when it throws
}
if (bytesRead != -1) {
- crc.update(buffer, off, bytesRead);
+ crc.update(buffer, offset, bytesRead);
}
if (eos) {
@@ -197,16 +190,15 @@ public class GZIPInputStream extends InflaterInputStream {
System.arraycopy(buf, len - size, b, 0, copySize);
readFully(b, copySize, trailerSize - copySize);
- if (getLong(b, 0) != crc.getValue()) {
+ if (OSMemory.peekInt(b, 0, ByteOrder.LITTLE_ENDIAN) != (int) crc.getValue()) {
throw new IOException("CRC mismatch");
}
- if ((int) getLong(b, 4) != inf.getTotalOut()) {
+ if (OSMemory.peekInt(b, 4, ByteOrder.LITTLE_ENDIAN) != inf.getTotalOut()) {
throw new IOException("Size mismatch");
}
}
- private void readFully(byte[] buffer, int offset, int length)
- throws IOException {
+ private void readFully(byte[] buffer, int offset, int length) throws IOException {
int result;
while (length > 0) {
result = in.read(buffer, offset, length);
diff --git a/luni/src/main/java/java/util/zip/GZIPOutputStream.java b/luni/src/main/java/java/util/zip/GZIPOutputStream.java
index 02510db..7d30ae8 100644
--- a/luni/src/main/java/java/util/zip/GZIPOutputStream.java
+++ b/luni/src/main/java/java/util/zip/GZIPOutputStream.java
@@ -23,6 +23,21 @@ import java.io.OutputStream;
/**
* The {@code GZIPOutputStream} class is used to write data to a stream in the
* GZIP storage format.
+ *
+ * <h3>Example</h3>
+ * <p>Using {@code GZIPOutputStream} is a little easier than {@link ZipOutputStream}
+ * because GZIP is only for compression, and is not a container for multiple files.
+ * This code creates a GZIP stream, similar to the {@code gzip(1)} utility.
+ * <pre>
+ * OutputStream os = ...
+ * byte[] bytes = ...
+ * GZIPOutputStream zos = new GZIPOutputStream(new BufferedOutputStream(os));
+ * try {
+ * zos.write(bytes);
+ * } finally {
+ * zos.close();
+ * }
+ * </pre>
*/
public class GZIPOutputStream extends DeflaterOutputStream {
diff --git a/luni/src/main/java/java/util/zip/Inflater.java b/luni/src/main/java/java/util/zip/Inflater.java
index 9dd56f3..65c7851 100644
--- a/luni/src/main/java/java/util/zip/Inflater.java
+++ b/luni/src/main/java/java/util/zip/Inflater.java
@@ -17,37 +17,52 @@
package java.util.zip;
+import dalvik.system.CloseGuard;
import java.io.FileDescriptor;
+import java.util.Arrays;
/**
- * This class uncompresses data that was compressed using the <i>DEFLATE</i>
+ * This class decompresses data that was compressed using the <i>DEFLATE</i>
* algorithm (see <a href="http://www.gzip.org/algorithm.txt">specification</a>).
- * <p>
- * Basically this class is part of the API to the stream based ZLIB compression
- * library and is used as such by {@code InflaterInputStream} and its
- * descendants.
- * <p>
- * The typical usage of a {@code Inflater} outside this package consists of a
- * specific call to one of its constructors before being passed to an instance
- * of {@code InflaterInputStream}.
*
- * @see InflaterInputStream
- * @see Deflater
+ * <p>It is usually more convenient to use {@link InflaterInputStream}.
+ *
+ * <p>To decompress an in-memory {@code byte[]} to another in-memory {@code byte[]} manually:
+ * <pre>
+ * byte[] compressedBytes = ...
+ * int decompressedByteCount = ... // From your format's metadata.
+ * Inflater inflater = new Inflater();
+ * inflater.setInput(compressedBytes, 0, compressedBytes.length);
+ * byte[] decompressedBytes = new byte[decompressedByteCount];
+ * if (inflater.inflate(decompressedBytes) != decompressedByteCount) {
+ * throw new AssertionError();
+ * }
+ * inflater.end();
+ * </pre>
+ * <p>In situations where you don't have all the input in one array (or have so much
+ * input that you want to feed it to the inflater in chunks), it's possible to call
+ * {@link #setInput} repeatedly, but you're much better off using {@link InflaterInputStream}
+ * to handle all this for you.
+ *
+ * <p>If you don't know how big the decompressed data will be, you can call {@link #inflate}
+ * repeatedly on a temporary buffer, copying the bytes to a {@link java.io.ByteArrayOutputStream},
+ * but this is probably another sign you'd be better off using {@link InflaterInputStream}.
*/
public class Inflater {
- private boolean finished; // Set by the inflateImpl native
- int inLength;
+ private int inLength;
- int inRead;
-
- private boolean needsDictionary; // Set by the inflateImpl native
+ private int inRead; // Set by inflateImpl.
+ private boolean finished; // Set by inflateImpl.
+ private boolean needsDictionary; // Set by inflateImpl.
private long streamHandle = -1;
+ private final CloseGuard guard = CloseGuard.get();
+
/**
* This constructor creates an inflater that expects a header from the input
- * stream. Use {@code Inflater(boolean)} if the input comes without a ZLIB
+ * stream. Use {@link #Inflater(boolean)} if the input comes without a ZLIB
* header.
*/
public Inflater() {
@@ -64,15 +79,19 @@ public class Inflater {
*/
public Inflater(boolean noHeader) {
streamHandle = createStream(noHeader);
+ guard.open("end");
}
private native long createStream(boolean noHeader1);
/**
- * Release any resources associated with this {@code Inflater}. Any unused
- * input/output is discarded. This is also called by the finalize method.
+ * Releases resources associated with this {@code Inflater}. Any unused
+ * input or output is discarded. This method should be called explicitly in
+ * order to free native resources as soon as possible. After {@code end()} is
+ * called, other methods will typically throw {@code IllegalStateException}.
*/
public synchronized void end() {
+ guard.close();
if (streamHandle != -1) {
endImpl(streamHandle);
inRead = 0;
@@ -81,10 +100,13 @@ public class Inflater {
}
}
- private native synchronized void endImpl(long handle);
+ private native void endImpl(long handle);
@Override protected void finalize() {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
end();
} finally {
try {
@@ -97,7 +119,7 @@ public class Inflater {
/**
* Indicates if the {@code Inflater} has inflated the entire deflated
- * stream. If deflated bytes remain and {@code needsInput()} returns {@code
+ * stream. If deflated bytes remain and {@link #needsInput} returns {@code
* true} this method will return {@code false}. This method should be
* called after all deflated input is supplied to the {@code Inflater}.
*
@@ -109,97 +131,68 @@ public class Inflater {
}
/**
- * Returns the <i>Adler32</i> checksum of either all bytes inflated, or the
- * checksum of the preset dictionary if one has been supplied.
- *
- * @return The <i>Adler32</i> checksum associated with this
- * {@code Inflater}.
+ * Returns the {@link Adler32} checksum of the bytes inflated so far, or the
+ * checksum of the preset dictionary if {@link #needsDictionary} returns true.
*/
public synchronized int getAdler() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
+ checkOpen();
return getAdlerImpl(streamHandle);
}
- private native synchronized int getAdlerImpl(long handle);
+ private native int getAdlerImpl(long handle);
/**
* Returns the total number of bytes read by the {@code Inflater}. This
- * method performs the same as {@code getTotalIn()} except that it returns a
+ * method is the same as {@link #getTotalIn} except that it returns a
* {@code long} value instead of an integer.
- *
- * @return the total number of bytes read.
*/
public synchronized long getBytesRead() {
- // Throw NPE here
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
+ checkOpen();
return getTotalInImpl(streamHandle);
}
/**
- * Returns a the total number of bytes read by the {@code Inflater}. This
- * method performs the same as {@code getTotalOut} except it returns a
+ * Returns a the total number of bytes written by this {@code Inflater}. This
+ * method is the same as {@code getTotalOut} except it returns a
* {@code long} value instead of an integer.
- *
- * @return the total bytes written to the output buffer.
*/
public synchronized long getBytesWritten() {
- // Throw NPE here
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
+ checkOpen();
return getTotalOutImpl(streamHandle);
}
/**
- * Returns the number of bytes of current input remaining to be read by the
+ * Returns the number of bytes of current input remaining to be read by this
* inflater.
- *
- * @return the number of bytes of unread input.
*/
public synchronized int getRemaining() {
return inLength - inRead;
}
/**
- * Returns total number of bytes of input read by the {@code Inflater}. The
- * result value is limited by {@code Integer.MAX_VALUE}.
- *
- * @return the total number of bytes read.
+ * Returns the total number of bytes of input read by this {@code Inflater}. This
+ * method is limited to 32 bits; use {@link #getBytesRead} instead.
*/
public synchronized int getTotalIn() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- long totalIn = getTotalInImpl(streamHandle);
- return (totalIn <= Integer.MAX_VALUE ? (int) totalIn
- : Integer.MAX_VALUE);
+ checkOpen();
+ return (int) Math.min(getTotalInImpl(streamHandle), (long) Integer.MAX_VALUE);
}
- private synchronized native long getTotalInImpl(long handle);
+ private native long getTotalInImpl(long handle);
/**
- * Returns total number of bytes written to the output buffer by the {@code
- * Inflater}. The result value is limited by {@code Integer.MAX_VALUE}.
- *
- * @return the total bytes of output data written.
+ * Returns the total number of bytes written to the output buffer by this {@code
+ * Inflater}. The method is limited to 32 bits; use {@link #getBytesWritten} instead.
*/
public synchronized int getTotalOut() {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- long totalOut = getTotalOutImpl(streamHandle);
- return (totalOut <= Integer.MAX_VALUE ? (int) totalOut
- : Integer.MAX_VALUE);
+ checkOpen();
+ return (int) Math.min(getTotalOutImpl(streamHandle), (long) Integer.MAX_VALUE);
}
- private native synchronized long getTotalOutImpl(long handle);
+ private native long getTotalOutImpl(long handle);
/**
- * Inflates bytes from current input and stores them in {@code buf}.
+ * Inflates bytes from the current input and stores them in {@code buf}.
*
* @param buf
* the buffer where decompressed data bytes are written.
@@ -213,35 +206,22 @@ public class Inflater {
}
/**
- * Inflates up to n bytes from the current input and stores them in {@code
- * buf} starting at {@code off}.
+ * Inflates up to {@code byteCount} bytes from the current input and stores them in
+ * {@code buf} starting at {@code offset}.
*
- * @param buf
- * the buffer to write inflated bytes to.
- * @param off
- * the offset in buffer where to start writing decompressed data.
- * @param nbytes
- * the number of inflated bytes to write to {@code buf}.
* @throws DataFormatException
* if the underlying stream is corrupted or was not compressed
* using a {@code Deflater}.
* @return the number of bytes inflated.
*/
- public synchronized int inflate(byte[] buf, int off, int nbytes)
- throws DataFormatException {
- // avoid int overflow, check null buf
- if (off > buf.length || nbytes < 0 || off < 0
- || buf.length - off < nbytes) {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public synchronized int inflate(byte[] buf, int offset, int byteCount) throws DataFormatException {
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
- if (nbytes == 0) {
+ if (byteCount == 0) {
return 0;
}
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
+ checkOpen();
if (needsInput()) {
return 0;
@@ -249,174 +229,104 @@ public class Inflater {
boolean neededDict = needsDictionary;
needsDictionary = false;
- int result = inflateImpl(buf, off, nbytes, streamHandle);
+ int result = inflateImpl(buf, offset, byteCount, streamHandle);
if (needsDictionary && neededDict) {
throw new DataFormatException("Needs dictionary");
}
-
return result;
}
- private native synchronized int inflateImpl(byte[] buf, int off,
- int nbytes, long handle);
+ private native int inflateImpl(byte[] buf, int offset, int byteCount, long handle);
/**
- * Indicates whether the input bytes were compressed with a preset
- * dictionary. This method should be called prior to {@code inflate()} to
- * determine whether a dictionary is required. If so {@code setDictionary()}
- * should be called with the appropriate dictionary prior to calling {@code
- * inflate()}.
- *
- * @return {@code true} if a preset dictionary is required for inflation.
- * @see #setDictionary(byte[])
- * @see #setDictionary(byte[], int, int)
+ * Returns true if the input bytes were compressed with a preset
+ * dictionary. This method should be called if the first call to {@link #inflate} returns 0,
+ * to determine whether a dictionary is required. If so, {@link #setDictionary}
+ * should be called with the appropriate dictionary before calling {@code
+ * inflate} again. Use {@link #getAdler} to determine which dictionary is required.
*/
public synchronized boolean needsDictionary() {
return needsDictionary;
}
/**
- * Indicates that input has to be passed to the inflater.
- *
- * @return {@code true} if {@code setInput} has to be called before
- * inflation can proceed.
- * @see #setInput(byte[])
+ * Returns true if {@link #setInput} must be called before inflation can continue.
*/
public synchronized boolean needsInput() {
return inRead == inLength;
}
/**
- * Resets the {@code Inflater}. Should be called prior to inflating a new
+ * Resets this {@code Inflater}. Should be called prior to inflating a new
* set of data.
*/
public synchronized void reset() {
- if (streamHandle == -1) {
- throw new NullPointerException();
- }
+ checkOpen();
finished = false;
needsDictionary = false;
inLength = inRead = 0;
resetImpl(streamHandle);
}
- private native synchronized void resetImpl(long handle);
+ private native void resetImpl(long handle);
/**
- * Sets the preset dictionary to be used for inflation to {@code buf}.
- * {@code needsDictionary()} can be called to determine whether the current
- * input was deflated using a preset dictionary.
- *
- * @param buf
- * The buffer containing the dictionary bytes.
- * @see #needsDictionary
+ * Sets the preset dictionary to be used for inflation to {@code dictionary}.
+ * See {@link #needsDictionary} for details.
*/
- public synchronized void setDictionary(byte[] buf) {
- setDictionary(buf, 0, buf.length);
+ public synchronized void setDictionary(byte[] dictionary) {
+ setDictionary(dictionary, 0, dictionary.length);
}
/**
- * Like {@code setDictionary(byte[])}, allowing to define a specific region
- * inside {@code buf} to be used as a dictionary.
- * <p>
- * The dictionary should be set if the {@link #inflate(byte[])} returned
- * zero bytes inflated and {@link #needsDictionary()} returns
- * <code>true</code>.
- *
- * @param buf
- * the buffer containing the dictionary data bytes.
- * @param off
- * the offset of the data.
- * @param nbytes
- * the length of the data.
- * @see #needsDictionary
+ * Sets the preset dictionary to be used for inflation to a subsequence of {@code dictionary}
+ * starting at {@code offset} and continuing for {@code byteCount} bytes. See {@link
+ * #needsDictionary} for details.
*/
- public synchronized void setDictionary(byte[] buf, int off, int nbytes) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- setDictionaryImpl(buf, off, nbytes, streamHandle);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public synchronized void setDictionary(byte[] dictionary, int offset, int byteCount) {
+ checkOpen();
+ Arrays.checkOffsetAndCount(dictionary.length, offset, byteCount);
+ setDictionaryImpl(dictionary, offset, byteCount, streamHandle);
}
- private native synchronized void setDictionaryImpl(byte[] buf, int off,
- int nbytes, long handle);
+ private native void setDictionaryImpl(byte[] dictionary, int offset, int byteCount, long handle);
/**
- * Sets the current input to to be decrompressed. This method should only be
- * called if {@code needsInput()} returns {@code true}.
- *
- * @param buf
- * the input buffer.
- * @see #needsInput
+ * Sets the current input to to be decompressed. This method should only be
+ * called if {@link #needsInput} returns {@code true}.
*/
public synchronized void setInput(byte[] buf) {
setInput(buf, 0, buf.length);
}
/**
- * Sets the current input to the region of the input buffer starting at
- * {@code off} and ending at {@code nbytes - 1} where data is written after
- * decompression. This method should only be called if {@code needsInput()}
- * returns {@code true}.
- *
- * @param buf
- * the input buffer.
- * @param off
- * the offset to read from the input buffer.
- * @param nbytes
- * the number of bytes to read.
- * @see #needsInput
+ * Sets the current input to to be decompressed. This method should only be
+ * called if {@link #needsInput} returns {@code true}.
*/
- public synchronized void setInput(byte[] buf, int off, int nbytes) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
- // avoid int overflow, check null buf
- if (off <= buf.length && nbytes >= 0 && off >= 0
- && buf.length - off >= nbytes) {
- inRead = 0;
- inLength = nbytes;
- setInputImpl(buf, off, nbytes, streamHandle);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public synchronized void setInput(byte[] buf, int offset, int byteCount) {
+ checkOpen();
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ inRead = 0;
+ inLength = byteCount;
+ setInputImpl(buf, offset, byteCount, streamHandle);
}
+ private native void setInputImpl(byte[] buf, int offset, int byteCount, long handle);
+
// BEGIN android-only
- /**
- * Sets the current input to the region within a file starting at {@code
- * off} and ending at {@code nbytes - 1}. This method should only be called
- * if {@code needsInput()} returns {@code true}.
- *
- * @param fd
- * the input file.
- * @param off
- * the offset to read from in buffer.
- * @param nbytes
- * the number of bytes to read.
- * @see #needsInput
- */
- synchronized int setFileInput(FileDescriptor fd, long off, int nbytes) {
- if (streamHandle == -1) {
- throw new IllegalStateException();
- }
+ synchronized int setFileInput(FileDescriptor fd, long offset, int byteCount) {
+ checkOpen();
inRead = 0;
- inLength = setFileInputImpl(fd, off, nbytes, streamHandle);
+ inLength = setFileInputImpl(fd, offset, byteCount, streamHandle);
return inLength;
}
- // END android-only
-
- private native synchronized void setInputImpl(byte[] buf, int off,
- int nbytes, long handle);
- // BEGIN android-only
- private native synchronized int setFileInputImpl(FileDescriptor fd, long off,
- int nbytes, long handle);
+ private native int setFileInputImpl(FileDescriptor fd, long offset, int byteCount, long handle);
// END android-only
+
+ private void checkOpen() {
+ if (streamHandle == -1) {
+ throw new IllegalStateException("attempt to use Inflater after calling end");
+ }
+ }
}
diff --git a/luni/src/main/java/java/util/zip/InflaterInputStream.java b/luni/src/main/java/java/util/zip/InflaterInputStream.java
index 5136e2c..d40ab6a 100644
--- a/luni/src/main/java/java/util/zip/InflaterInputStream.java
+++ b/luni/src/main/java/java/util/zip/InflaterInputStream.java
@@ -21,11 +21,12 @@ import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Arrays;
import libcore.base.Streams;
/**
* This class provides an implementation of {@code FilterInputStream} that
- * uncompresses data that was compressed using the <i>DEFLATE</i> algorithm
+ * decompresses data that was compressed using the <i>DEFLATE</i> algorithm
* (see <a href="http://www.gzip.org/algorithm.txt">specification</a>).
* Basically it wraps the {@code Inflater} class and takes care of the
* buffering.
@@ -83,7 +84,7 @@ public class InflaterInputStream extends FilterInputStream {
* @param is
* the {@code InputStream} to read data from.
* @param inflater
- * the specific {@code Inflater} for uncompressing data.
+ * the specific {@code Inflater} for decompressing data.
*/
public InflaterInputStream(InputStream is, Inflater inflater) {
this(is, inflater, BUF_SIZE);
@@ -96,7 +97,7 @@ public class InflaterInputStream extends FilterInputStream {
* @param is
* the {@code InputStream} to read data from.
* @param inflater
- * the specific {@code Inflater} for uncompressing data.
+ * the specific {@code Inflater} for decompressing data.
* @param bsize
* the size to be used for the internal buffer.
*/
@@ -135,31 +136,17 @@ public class InflaterInputStream extends FilterInputStream {
}
/**
- * Reads up to {@code nbytes} of decompressed data and stores it in
- * {@code buffer} starting at {@code off}.
+ * Reads up to {@code byteCount} bytes of decompressed data and stores it in
+ * {@code buffer} starting at {@code offset}.
*
- * @param buffer
- * the buffer to write data to.
- * @param off
- * offset in buffer to start writing.
- * @param nbytes
- * number of bytes to read.
* @return Number of uncompressed bytes read
- * @throws IOException
- * if an IOException occurs.
*/
@Override
- public int read(byte[] buffer, int off, int nbytes) throws IOException {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
checkClosed();
- if (buffer == null) {
- throw new NullPointerException();
- }
-
- if (off < 0 || nbytes < 0 || off + nbytes > buffer.length) {
- throw new IndexOutOfBoundsException();
- }
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
- if (nbytes == 0) {
+ if (byteCount == 0) {
return 0;
}
@@ -167,12 +154,6 @@ public class InflaterInputStream extends FilterInputStream {
return -1;
}
- // avoid int overflow, check null buffer
- if (off > buffer.length || nbytes < 0 || off < 0
- || buffer.length - off < nbytes) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
do {
if (inf.needsInput()) {
fill();
@@ -180,7 +161,7 @@ public class InflaterInputStream extends FilterInputStream {
// Invariant: if reading returns -1 or throws, eof must be true.
// It may also be true if the next read() should return -1.
try {
- int result = inf.inflate(buffer, off, nbytes);
+ int result = inf.inflate(buffer, offset, byteCount);
eof = inf.finished();
if (result > 0) {
return result;
@@ -218,7 +199,7 @@ public class InflaterInputStream extends FilterInputStream {
synchronized (is.mSharedRaf) {
long len = is.mLength - is.mOffset;
if (len > nativeEndBufSize) len = nativeEndBufSize;
- int cnt = inf.setFileInput(is.mSharedRaf.getFD(), is.mOffset, (int)nativeEndBufSize);
+ int cnt = inf.setFileInput(is.mSharedRaf.getFD(), is.mOffset, nativeEndBufSize);
is.skip(cnt);
}
} else {
@@ -234,10 +215,14 @@ public class InflaterInputStream extends FilterInputStream {
*
* @param byteCount the number of bytes to skip.
* @return the number of uncompressed bytes skipped.
+ * @throws IllegalArgumentException if {@code byteCount < 0}.
* @throws IOException if an error occurs skipping.
*/
@Override
public long skip(long byteCount) throws IOException {
+ if (byteCount < 0) {
+ throw new IllegalArgumentException("byteCount < 0");
+ }
return Streams.skipByReading(this, byteCount);
}
diff --git a/luni/src/main/java/java/util/zip/InflaterOutputStream.java b/luni/src/main/java/java/util/zip/InflaterOutputStream.java
index 8c07603..c9687b6 100644
--- a/luni/src/main/java/java/util/zip/InflaterOutputStream.java
+++ b/luni/src/main/java/java/util/zip/InflaterOutputStream.java
@@ -20,6 +20,7 @@ package java.util.zip;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
/**
* An {@code OutputStream} filter to decompress data. Callers write
@@ -125,29 +126,20 @@ public class InflaterOutputStream extends FilterOutputStream {
}
/**
- * Writes bytes to the decompressing output stream. {@code b} should be an array of
+ * Writes to the decompressing output stream. The {@code bytes} array should contain
* compressed input. The corresponding uncompressed data will be written to the underlying
* stream.
*
- * @param b the byte array
- * @param off the start offset in the byte array
- * @param len the number of the bytes to take from the byte array
* @throws IOException if an I/O error occurs, or the stream has been closed
* @throws ZipException if a zip exception occurs.
* @throws NullPointerException if {@code b == null}.
* @throws IndexOutOfBoundsException if {@code off < 0 || len < 0 || off + len > b.length}
*/
@Override
- public void write(byte[] b, int off, int len) throws IOException, ZipException {
+ public void write(byte[] bytes, int offset, int byteCount) throws IOException, ZipException {
checkClosed();
- if (b == null) {
- throw new NullPointerException();
- }
- if (off < 0 || len < 0 || len > b.length - off) {
- throw new IndexOutOfBoundsException();
- }
-
- inf.setInput(b, off, len);
+ Arrays.checkOffsetAndCount(bytes.length, offset, byteCount);
+ inf.setInput(bytes, offset, byteCount);
write();
}
diff --git a/luni/src/main/java/java/util/zip/ZipEntry.java b/luni/src/main/java/java/util/zip/ZipEntry.java
index d99b414..b7bde59 100644
--- a/luni/src/main/java/java/util/zip/ZipEntry.java
+++ b/luni/src/main/java/java/util/zip/ZipEntry.java
@@ -21,10 +21,14 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
+import java.nio.ByteOrder;
import java.nio.charset.Charsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
+import libcore.base.Streams;
+import libcore.io.BufferIterator;
+import libcore.io.HeapBufferIterator;
/**
* An instance of {@code ZipEntry} represents an entry within a <i>ZIP-archive</i>.
@@ -46,7 +50,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
byte[] extra;
- int nameLen = -1;
+ int nameLength = -1;
long mLocalHeaderRelOffset = -1;
/**
@@ -72,7 +76,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
throw new NullPointerException();
}
if (name.length() > 0xFFFF) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Name too long: " + name.length());
}
this.name = name;
}
@@ -177,12 +181,12 @@ public class ZipEntry implements ZipConstants, Cloneable {
/**
* Sets the comment for this {@code ZipEntry}.
*
- * @param string
+ * @param comment
* the comment for this entry.
*/
- public void setComment(String string) {
- if (string == null || string.length() <= 0xFFFF) {
- comment = string;
+ public void setComment(String comment) {
+ if (comment == null || comment.length() <= 0xFFFF) {
+ this.comment = comment;
} else {
throw new IllegalArgumentException();
}
@@ -210,7 +214,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
if (value >= 0 && value <= 0xFFFFFFFFL) {
crc = value;
} else {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad CRC32: " + value);
}
}
@@ -241,7 +245,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
*/
public void setMethod(int value) {
if (value != STORED && value != DEFLATED) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad method: " + value);
}
compressionMethod = value;
}
@@ -258,7 +262,7 @@ public class ZipEntry implements ZipConstants, Cloneable {
if (value >= 0 && value <= 0xFFFFFFFFL) {
size = value;
} else {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Bad size: " + value);
}
}
@@ -313,18 +317,21 @@ public class ZipEntry implements ZipConstants, Cloneable {
compressionMethod = ze.compressionMethod;
modDate = ze.modDate;
extra = ze.extra;
- nameLen = ze.nameLen;
+ nameLength = ze.nameLength;
mLocalHeaderRelOffset = ze.mLocalHeaderRelOffset;
}
/**
- * Returns a shallow copy of this entry.
- *
- * @return a copy of this entry.
+ * Returns a deep copy of this zip entry.
*/
- @Override
- public Object clone() {
- return new ZipEntry(this);
+ @Override public Object clone() {
+ try {
+ ZipEntry result = (ZipEntry) super.clone();
+ result.extra = extra != null ? extra.clone() : null;
+ return result;
+ } catch (CloneNotSupportedException e) {
+ throw new AssertionError(e);
+ }
}
/**
@@ -344,128 +351,49 @@ public class ZipEntry implements ZipConstants, Cloneable {
*
* On exit, "in" will be positioned at the start of the next entry.
*/
- ZipEntry(LittleEndianReader ler, InputStream in) throws IOException {
-
- /*
- * We're seeing performance issues when we call readShortLE and
- * readIntLE, so we're going to read the entire header at once
- * and then parse the results out without using any function calls.
- * Uglier, but should be much faster.
- *
- * Note that some lines look a bit different, because the corresponding
- * fields or locals are long and so we need to do & 0xffffffffl to avoid
- * problems induced by sign extension.
- */
-
- byte[] hdrBuf = ler.hdrBuf;
- myReadFully(in, hdrBuf);
-
- long sig = (hdrBuf[0] & 0xff) | ((hdrBuf[1] & 0xff) << 8) |
- ((hdrBuf[2] & 0xff) << 16) | ((hdrBuf[3] << 24) & 0xffffffffL);
+ ZipEntry(byte[] hdrBuf, InputStream in) throws IOException {
+ Streams.readFully(in, hdrBuf, 0, hdrBuf.length);
+
+ BufferIterator it = HeapBufferIterator.iterator(hdrBuf, 0, hdrBuf.length, ByteOrder.LITTLE_ENDIAN);
+
+ int sig = it.readInt();
if (sig != CENSIG) {
throw new ZipException("Central Directory Entry not found");
}
- compressionMethod = (hdrBuf[10] & 0xff) | ((hdrBuf[11] & 0xff) << 8);
- time = (hdrBuf[12] & 0xff) | ((hdrBuf[13] & 0xff) << 8);
- modDate = (hdrBuf[14] & 0xff) | ((hdrBuf[15] & 0xff) << 8);
- crc = (hdrBuf[16] & 0xff) | ((hdrBuf[17] & 0xff) << 8)
- | ((hdrBuf[18] & 0xff) << 16)
- | ((hdrBuf[19] << 24) & 0xffffffffL);
- compressedSize = (hdrBuf[20] & 0xff) | ((hdrBuf[21] & 0xff) << 8)
- | ((hdrBuf[22] & 0xff) << 16)
- | ((hdrBuf[23] << 24) & 0xffffffffL);
- size = (hdrBuf[24] & 0xff) | ((hdrBuf[25] & 0xff) << 8)
- | ((hdrBuf[26] & 0xff) << 16)
- | ((hdrBuf[27] << 24) & 0xffffffffL);
- nameLen = (hdrBuf[28] & 0xff) | ((hdrBuf[29] & 0xff) << 8);
- int extraLen = (hdrBuf[30] & 0xff) | ((hdrBuf[31] & 0xff) << 8);
- int commentLen = (hdrBuf[32] & 0xff) | ((hdrBuf[33] & 0xff) << 8);
- mLocalHeaderRelOffset = (hdrBuf[42] & 0xff) | ((hdrBuf[43] & 0xff) << 8)
- | ((hdrBuf[44] & 0xff) << 16)
- | ((hdrBuf[45] << 24) & 0xffffffffL);
-
- byte[] nameBytes = new byte[nameLen];
- myReadFully(in, nameBytes);
-
- byte[] commentBytes = null;
- if (commentLen > 0) {
- commentBytes = new byte[commentLen];
- myReadFully(in, commentBytes);
- }
+ it.seek(10);
+ compressionMethod = it.readShort();
+ time = it.readShort();
+ modDate = it.readShort();
- if (extraLen > 0) {
- extra = new byte[extraLen];
- myReadFully(in, extra);
- }
+ // These are 32-bit values in the file, but 64-bit fields in this object.
+ crc = ((long) it.readInt()) & 0xffffffffL;
+ compressedSize = ((long) it.readInt()) & 0xffffffffL;
+ size = ((long) it.readInt()) & 0xffffffffL;
- // The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
- // actually IBM-437.)
- name = new String(nameBytes, 0, nameBytes.length, Charsets.UTF_8);
- if (commentBytes != null) {
- comment = new String(commentBytes, 0, commentBytes.length, Charsets.UTF_8);
- } else {
- comment = null;
- }
- }
+ nameLength = it.readShort();
+ int extraLength = it.readShort();
+ int commentLength = it.readShort();
- private void myReadFully(InputStream in, byte[] b) throws IOException {
- int len = b.length;
- int off = 0;
-
- while (len > 0) {
- int count = in.read(b, off, len);
- if (count <= 0) {
- throw new EOFException();
- }
- off += count;
- len -= count;
- }
- }
+ // This is a 32-bit value in the file, but a 64-bit field in this object.
+ it.seek(42);
+ mLocalHeaderRelOffset = ((long) it.readInt()) & 0xffffffffL;
- /*
- * Read a four-byte int in little-endian order.
- */
- static long readIntLE(RandomAccessFile raf) throws IOException {
- int b0 = raf.read();
- int b1 = raf.read();
- int b2 = raf.read();
- int b3 = raf.read();
-
- if (b3 < 0) {
- throw new EOFException("in ZipEntry.readIntLE(RandomAccessFile)");
- }
- return b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); // ATTENTION: DOES SIGN EXTENSION: IS THIS WANTED?
- }
+ byte[] nameBytes = new byte[nameLength];
+ Streams.readFully(in, nameBytes, 0, nameBytes.length);
+ name = new String(nameBytes, 0, nameBytes.length, Charsets.UTF_8);
- static class LittleEndianReader {
- private byte[] b = new byte[4];
- byte[] hdrBuf = new byte[CENHDR];
-
- /*
- * Read a two-byte short in little-endian order.
- */
- int readShortLE(InputStream in) throws IOException {
- if (in.read(b, 0, 2) == 2) {
- return (b[0] & 0XFF) | ((b[1] & 0XFF) << 8);
- } else {
- throw new EOFException("in ZipEntry.readShortLE(InputStream)");
- }
+ // The RI has always assumed UTF-8. (If GPBF_UTF8_FLAG isn't set, the encoding is
+ // actually IBM-437.)
+ if (commentLength > 0) {
+ byte[] commentBytes = new byte[commentLength];
+ Streams.readFully(in, commentBytes, 0, commentLength);
+ comment = new String(commentBytes, 0, commentBytes.length, Charsets.UTF_8);
}
- /*
- * Read a four-byte int in little-endian order.
- */
- long readIntLE(InputStream in) throws IOException {
- if (in.read(b, 0, 4) == 4) {
- return ( ((b[0] & 0XFF))
- | ((b[1] & 0XFF) << 8)
- | ((b[2] & 0XFF) << 16)
- | ((b[3] & 0XFF) << 24))
- & 0XFFFFFFFFL; // Here for sure NO sign extension is wanted.
- } else {
- throw new EOFException("in ZipEntry.readIntLE(InputStream)");
- }
+ if (extraLength > 0) {
+ extra = new byte[extraLength];
+ Streams.readFully(in, extra, 0, extraLength);
}
}
}
diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java
index 8f70aeb..06be579 100644
--- a/luni/src/main/java/java/util/zip/ZipFile.java
+++ b/luni/src/main/java/java/util/zip/ZipFile.java
@@ -17,16 +17,22 @@
package java.util.zip;
+import dalvik.system.CloseGuard;
import java.io.BufferedInputStream;
+import java.io.EOFException;
+import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
+import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
+import libcore.io.BufferIterator;
+import libcore.io.HeapBufferIterator;
/**
* This class provides random read access to a <i>ZIP-archive</i> file.
@@ -80,10 +86,9 @@ public class ZipFile implements ZipConstants {
private RandomAccessFile mRaf;
- private final ZipEntry.LittleEndianReader ler = new ZipEntry.LittleEndianReader();
+ private final LinkedHashMap<String, ZipEntry> mEntries = new LinkedHashMap<String, ZipEntry>();
- private final LinkedHashMap<String, ZipEntry> mEntries
- = new LinkedHashMap<String, ZipEntry>();
+ private final CloseGuard guard = CloseGuard.get();
/**
* Constructs a new {@code ZipFile} with the specified file.
@@ -133,6 +138,7 @@ public class ZipFile implements ZipConstants {
mRaf = new RandomAccessFile(fileName, "r");
readCentralDir();
+ guard.open("close");
}
/**
@@ -149,7 +155,9 @@ public class ZipFile implements ZipConstants {
@Override protected void finalize() throws IOException {
try {
- close();
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
} finally {
try {
super.finalize();
@@ -166,6 +174,7 @@ public class ZipFile implements ZipConstants {
* if an IOException occurs.
*/
public void close() throws IOException {
+ guard.close();
RandomAccessFile raf = mRaf;
if (raf != null) { // Only close initialized instances
@@ -249,29 +258,26 @@ public class ZipFile implements ZipConstants {
* @throws IllegalStateException if this ZIP file has been closed.
*/
public InputStream getInputStream(ZipEntry entry) throws IOException {
- /*
- * Make sure this ZipEntry is in this Zip file. We run it through
- * the name lookup.
- */
+ // Make sure this ZipEntry is in this Zip file. We run it through the name lookup.
entry = getEntry(entry.getName());
if (entry == null) {
return null;
}
- /*
- * Create a ZipInputStream at the right part of the file.
- */
+ // Create an InputStream at the right part of the file.
RandomAccessFile raf = mRaf;
synchronized (raf) {
// We don't know the entry data's start position. All we have is the
// position of the entry's local header. At position 28 we find the
// length of the extra data. In some cases this length differs from
// the one coming in the central header.
- RAFStream rafstrm = new RAFStream(raf,
- entry.mLocalHeaderRelOffset + 28);
- int localExtraLenOrWhatever = ler.readShortLE(rafstrm);
+ RAFStream rafstrm = new RAFStream(raf, entry.mLocalHeaderRelOffset + 28);
+ DataInputStream is = new DataInputStream(rafstrm);
+ int localExtraLenOrWhatever = Short.reverseBytes(is.readShort());
+ is.close();
+
// Skip the name and this "extra" data or whatever it is:
- rafstrm.skip(entry.nameLen + localExtraLenOrWhatever);
+ rafstrm.skip(entry.nameLength + localExtraLenOrWhatever);
rafstrm.mLength = rafstrm.mOffset + entry.compressedSize;
if (entry.compressionMethod == ZipEntry.DEFLATED) {
int bufSize = Math.max(1024, (int)Math.min(entry.getSize(), 65535L));
@@ -334,9 +340,10 @@ public class ZipFile implements ZipConstants {
stopOffset = 0;
}
+ final int ENDHEADERMAGIC = 0x06054b50;
while (true) {
mRaf.seek(scanOffset);
- if (ZipEntry.readIntLE(mRaf) == 101010256L) {
+ if (Integer.reverseBytes(mRaf.readInt()) == ENDHEADERMAGIC) {
break;
}
@@ -346,38 +353,30 @@ public class ZipFile implements ZipConstants {
}
}
- /*
- * Found it, read the EOCD.
- *
- * For performance we want to use buffered I/O when reading the
- * file. We wrap a buffered stream around the random-access file
- * object. If we just read from the RandomAccessFile we'll be
- * doing a read() system call every time.
- */
- RAFStream rafs = new RAFStream(mRaf, mRaf.getFilePointer());
- BufferedInputStream bin = new BufferedInputStream(rafs, ENDHDR);
-
- int diskNumber = ler.readShortLE(bin);
- int diskWithCentralDir = ler.readShortLE(bin);
- int numEntries = ler.readShortLE(bin);
- int totalNumEntries = ler.readShortLE(bin);
- /*centralDirSize =*/ ler.readIntLE(bin);
- long centralDirOffset = ler.readIntLE(bin);
- /*commentLen =*/ ler.readShortLE(bin);
-
- if (numEntries != totalNumEntries ||
- diskNumber != 0 ||
- diskWithCentralDir != 0) {
+ // Read the End Of Central Directory. We could use ENDHDR instead of the magic number 18,
+ // but we don't actually need all the header.
+ byte[] eocd = new byte[18];
+ mRaf.readFully(eocd);
+
+ // Pull out the information we need.
+ BufferIterator it = HeapBufferIterator.iterator(eocd, 0, eocd.length, ByteOrder.LITTLE_ENDIAN);
+ short diskNumber = it.readShort();
+ short diskWithCentralDir = it.readShort();
+ short numEntries = it.readShort();
+ short totalNumEntries = it.readShort();
+ it.skip(4); // Ignore centralDirSize.
+ int centralDirOffset = it.readInt();
+
+ if (numEntries != totalNumEntries || diskNumber != 0 || diskWithCentralDir != 0) {
throw new ZipException("spanned archives not supported");
}
- /*
- * Seek to the first CDE and read all entries.
- */
- rafs = new RAFStream(mRaf, centralDirOffset);
- bin = new BufferedInputStream(rafs, 4096);
- for (int i = 0; i < numEntries; i++) {
- ZipEntry newEntry = new ZipEntry(ler, bin);
+ // Seek to the first CDE and read all entries.
+ RAFStream rafs = new RAFStream(mRaf, centralDirOffset);
+ BufferedInputStream bin = new BufferedInputStream(rafs, 4096);
+ byte[] hdrBuf = new byte[CENHDR]; // Reuse the same buffer for each entry.
+ for (int i = 0; i < numEntries; ++i) {
+ ZipEntry newEntry = new ZipEntry(hdrBuf, bin);
mEntries.put(newEntry.getName(), newEntry);
}
}
@@ -435,12 +434,12 @@ public class ZipFile implements ZipConstants {
}
@Override
- public long skip(long n) throws IOException {
- if (n > mLength - mOffset) {
- n = mLength - mOffset;
+ public long skip(long byteCount) throws IOException {
+ if (byteCount > mLength - mOffset) {
+ byteCount = mLength - mOffset;
}
- mOffset += n;
- return n;
+ mOffset += byteCount;
+ return byteCount;
}
}
diff --git a/luni/src/main/java/java/util/zip/ZipInputStream.java b/luni/src/main/java/java/util/zip/ZipInputStream.java
index 87b566f..1ca8982 100644
--- a/luni/src/main/java/java/util/zip/ZipInputStream.java
+++ b/luni/src/main/java/java/util/zip/ZipInputStream.java
@@ -21,33 +21,59 @@ import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
+import java.nio.ByteOrder;
import java.nio.charset.ModifiedUtf8;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
+import java.util.Arrays;
+import libcore.base.Streams;
+import org.apache.harmony.luni.platform.OSMemory;
/**
* This class provides an implementation of {@code FilterInputStream} that
- * uncompresses data from a <i>ZIP-archive</i> input stream.
- * <p>
- * A <i>ZIP-archive</i> is a collection of compressed (or uncompressed) files -
- * the so called ZIP entries. Therefore when reading from a {@code
- * ZipInputStream} first the entry's attributes will be retrieved with {@code
- * getNextEntry} before its data is read.
- * <p>
- * While {@code InflaterInputStream} can read a compressed <i>ZIP-archive</i>
- * entry, this extension can read uncompressed entries as well.
- * <p>
- * Use {@code ZipFile} if you can access the archive as a file directly.
+ * decompresses data from an {@code InputStream} containing a ZIP archive.
+ *
+ * <p>A ZIP archive is a collection of (possibly) compressed files.
+ * When reading from a {@code ZipInputStream}, you retrieve the
+ * entry's metadata with {@code getNextEntry} before you can read the userdata.
+ *
+ * <p>Although {@code InflaterInputStream} can only read compressed ZIP archive
+ * entries, this class can read non-compressed entries as well.
+ *
+ * <p>Use {@code ZipFile} if you can access the archive as a file directly,
+ * especially if you want random access to entries, rather than needing to
+ * iterate over all entries.
+ *
+ * <h3>Example</h3>
+ * <p>Using {@code ZipInputStream} is a little more complicated than {@link GZIPInputStream}
+ * because ZIP archives are containers that can contain multiple files. This code pulls all the
+ * files out of a ZIP archive, similar to the {@code unzip(1)} utility.
+ * <pre>
+ * InputStream is = ...
+ * ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
+ * try {
+ * ZipEntry ze;
+ * while ((ze = zis.getNextEntry()) != null) {
+ * ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ * byte[] buffer = new byte[1024];
+ * int count;
+ * while ((count = zis.read(buffer)) != -1) {
+ * baos.write(buffer, 0, count);
+ * }
+ * String filename = ze.getName();
+ * byte[] bytes = baos.toByteArray();
+ * // do something with 'filename' and 'bytes'...
+ * }
+ * } finally {
+ * zis.close();
+ * }
+ * </pre>
*
* @see ZipEntry
* @see ZipFile
*/
public class ZipInputStream extends InflaterInputStream implements ZipConstants {
- static final int DEFLATED = 8;
-
- static final int STORED = 0;
-
- static final int ZIPLocalHeaderVersionNeeded = 20;
+ private static final int ZIPLocalHeaderVersionNeeded = 20;
private boolean entriesEnd = false;
@@ -57,7 +83,7 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
private int inRead, lastRead = 0;
- ZipEntry currentEntry;
+ private ZipEntry currentEntry;
private final byte[] hdrBuf = new byte[LOCHDR - LOCVER];
@@ -124,13 +150,13 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
// Ensure all entry bytes are read
Exception failure = null;
try {
- skip(Long.MAX_VALUE);
+ Streams.skipAll(this);
} catch (Exception e) {
failure = e;
}
int inB, out;
- if (currentEntry.compressionMethod == DEFLATED) {
+ if (currentEntry.compressionMethod == ZipEntry.DEFLATED) {
inB = inf.getTotalIn();
out = inf.getTotalOut();
} else {
@@ -171,13 +197,13 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
private void readAndVerifyDataDescriptor(int inB, int out) throws IOException {
if (hasDD) {
in.read(hdrBuf, 0, EXTHDR);
- long sig = getLong(hdrBuf, 0);
- if (sig != EXTSIG) {
+ int sig = OSMemory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN);
+ if (sig != (int) EXTSIG) {
throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig));
}
- currentEntry.crc = getLong(hdrBuf, EXTCRC);
- currentEntry.compressedSize = getLong(hdrBuf, EXTSIZ);
- currentEntry.size = getLong(hdrBuf, EXTLEN);
+ currentEntry.crc = ((long) OSMemory.peekInt(hdrBuf, EXTCRC, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
+ currentEntry.compressedSize = ((long) OSMemory.peekInt(hdrBuf, EXTSIZ, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
+ currentEntry.size = ((long) OSMemory.peekInt(hdrBuf, EXTLEN, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
}
if (currentEntry.crc != crc.getValue()) {
throw new ZipException("CRC mismatch");
@@ -202,14 +228,8 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
return null;
}
- int x = 0, count = 0;
- while (count != 4) {
- count += x = in.read(hdrBuf, count, 4 - count);
- if (x == -1) {
- return null;
- }
- }
- long hdr = getLong(hdrBuf, 0);
+ Streams.readFully(in, hdrBuf, 0, 4);
+ int hdr = OSMemory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN);
if (hdr == CENSIG) {
entriesEnd = true;
return null;
@@ -219,95 +239,68 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
}
// Read the local header
- count = 0;
- while (count != (LOCHDR - LOCVER)) {
- count += x = in.read(hdrBuf, count, (LOCHDR - LOCVER) - count);
- if (x == -1) {
- throw new EOFException();
- }
- }
- int version = getShort(hdrBuf, 0) & 0xff;
+ Streams.readFully(in, hdrBuf, 0, (LOCHDR - LOCVER));
+ int version = OSMemory.peekShort(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN) & 0xff;
if (version > ZIPLocalHeaderVersionNeeded) {
throw new ZipException("Cannot read local header version " + version);
}
- int flags = getShort(hdrBuf, LOCFLG - LOCVER);
+ short flags = OSMemory.peekShort(hdrBuf, LOCFLG - LOCVER, ByteOrder.LITTLE_ENDIAN);
hasDD = ((flags & ZipFile.GPBF_DATA_DESCRIPTOR_FLAG) != 0);
- int cetime = getShort(hdrBuf, LOCTIM - LOCVER);
- int cemodDate = getShort(hdrBuf, LOCTIM - LOCVER + 2);
- int cecompressionMethod = getShort(hdrBuf, LOCHOW - LOCVER);
- long cecrc = 0, cecompressedSize = 0, cesize = -1;
+ int ceTime = OSMemory.peekShort(hdrBuf, LOCTIM - LOCVER, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+ int ceModDate = OSMemory.peekShort(hdrBuf, LOCTIM - LOCVER + 2, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+ int ceCompressionMethod = OSMemory.peekShort(hdrBuf, LOCHOW - LOCVER, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+ long ceCrc = 0, ceCompressedSize = 0, ceSize = -1;
if (!hasDD) {
- cecrc = getLong(hdrBuf, LOCCRC - LOCVER);
- cecompressedSize = getLong(hdrBuf, LOCSIZ - LOCVER);
- cesize = getLong(hdrBuf, LOCLEN - LOCVER);
+ ceCrc = ((long) OSMemory.peekInt(hdrBuf, LOCCRC - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
+ ceCompressedSize = ((long) OSMemory.peekInt(hdrBuf, LOCSIZ - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
+ ceSize = ((long) OSMemory.peekInt(hdrBuf, LOCLEN - LOCVER, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL;
}
- int flen = getShort(hdrBuf, LOCNAM - LOCVER);
- if (flen == 0) {
+ int nameLength = OSMemory.peekShort(hdrBuf, LOCNAM - LOCVER, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+ if (nameLength == 0) {
throw new ZipException("Entry is not named");
}
- int elen = getShort(hdrBuf, LOCEXT - LOCVER);
-
- count = 0;
- if (flen > nameBuf.length) {
- nameBuf = new byte[flen];
- charBuf = new char[flen];
- }
- while (count != flen) {
- count += x = in.read(nameBuf, count, flen - count);
- if (x == -1) {
- throw new EOFException();
- }
- }
- currentEntry = createZipEntry(ModifiedUtf8.decode(nameBuf, charBuf, 0, flen));
- currentEntry.time = cetime;
- currentEntry.modDate = cemodDate;
- currentEntry.setMethod(cecompressionMethod);
- if (cesize != -1) {
- currentEntry.setCrc(cecrc);
- currentEntry.setSize(cesize);
- currentEntry.setCompressedSize(cecompressedSize);
- }
- if (elen > 0) {
- count = 0;
- byte[] e = new byte[elen];
- while (count != elen) {
- count += x = in.read(e, count, elen - count);
- if (x == -1) {
- throw new EOFException();
- }
- }
- currentEntry.setExtra(e);
+ int extraLength = OSMemory.peekShort(hdrBuf, LOCEXT - LOCVER, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+
+ if (nameLength > nameBuf.length) {
+ nameBuf = new byte[nameLength];
+ // The bytes are modified UTF-8, so the number of chars will always be less than or
+ // equal to the number of bytes. It's fine if this buffer is too long.
+ charBuf = new char[nameLength];
+ }
+ Streams.readFully(in, nameBuf, 0, nameLength);
+ currentEntry = createZipEntry(ModifiedUtf8.decode(nameBuf, charBuf, 0, nameLength));
+ currentEntry.time = ceTime;
+ currentEntry.modDate = ceModDate;
+ currentEntry.setMethod(ceCompressionMethod);
+ if (ceSize != -1) {
+ currentEntry.setCrc(ceCrc);
+ currentEntry.setSize(ceSize);
+ currentEntry.setCompressedSize(ceCompressedSize);
+ }
+ if (extraLength > 0) {
+ byte[] extraData = new byte[extraLength];
+ Streams.readFully(in, extraData, 0, extraLength);
+ currentEntry.setExtra(extraData);
}
return currentEntry;
}
- /* Read 4 bytes from the buffer and store it as an int */
-
/**
* Reads up to the specified number of uncompressed bytes into the buffer
* starting at the offset.
*
- * @param buffer
- * a byte array
- * @param start
- * the starting offset into the buffer
- * @param length
- * the number of bytes to read
* @return the number of bytes read
*/
@Override
- public int read(byte[] buffer, int start, int length) throws IOException {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
checkClosed();
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+
if (inf.finished() || currentEntry == null) {
return -1;
}
- // avoid int overflow, check null buffer
- if (start > buffer.length || length < 0 || start < 0
- || buffer.length - start < length) {
- throw new ArrayIndexOutOfBoundsException();
- }
- if (currentEntry.compressionMethod == STORED) {
+ if (currentEntry.compressionMethod == ZipEntry.STORED) {
int csize = (int) currentEntry.size;
if (inRead >= csize) {
return -1;
@@ -320,14 +313,14 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
}
entryIn += len;
}
- int toRead = length > (len - lastRead) ? len - lastRead : length;
+ int toRead = byteCount > (len - lastRead) ? len - lastRead : byteCount;
if ((csize - inRead) < toRead) {
toRead = csize - inRead;
}
- System.arraycopy(buf, lastRead, buffer, start, toRead);
+ System.arraycopy(buf, lastRead, buffer, offset, toRead);
lastRead += toRead;
inRead += toRead;
- crc.update(buffer, start, toRead);
+ crc.update(buffer, offset, toRead);
return toRead;
}
if (inf.needsInput()) {
@@ -338,45 +331,17 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
}
int read;
try {
- read = inf.inflate(buffer, start, length);
+ read = inf.inflate(buffer, offset, byteCount);
} catch (DataFormatException e) {
throw new ZipException(e.getMessage());
}
if (read == 0 && inf.finished()) {
return -1;
}
- crc.update(buffer, start, read);
+ crc.update(buffer, offset, read);
return read;
}
- /**
- * Skips up to the specified number of bytes in the current ZIP entry.
- *
- * @param value
- * the number of bytes to skip.
- * @return the number of bytes skipped.
- * @throws IOException
- * if an {@code IOException} occurs.
- */
- @Override
- public long skip(long value) throws IOException {
- if (value < 0) {
- throw new IllegalArgumentException();
- }
-
- long skipped = 0;
- byte[] b = new byte[(int)Math.min(value, 2048L)];
- while (skipped != value) {
- long rem = value - skipped;
- int x = read(b, 0, (int) (b.length > rem ? rem : b.length));
- if (x == -1) {
- return skipped;
- }
- skipped += x;
- }
- return skipped;
- }
-
@Override
public int available() throws IOException {
checkClosed();
@@ -395,19 +360,6 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
return new ZipEntry(name);
}
- private int getShort(byte[] buffer, int off) {
- return (buffer[off] & 0xFF) | ((buffer[off + 1] & 0xFF) << 8);
- }
-
- private long getLong(byte[] buffer, int off) {
- long l = 0;
- l |= (buffer[off] & 0xFF);
- l |= (buffer[off + 1] & 0xFF) << 8;
- l |= (buffer[off + 2] & 0xFF) << 16;
- l |= ((long) (buffer[off + 3] & 0xFF)) << 24;
- return l;
- }
-
private void checkClosed() throws IOException {
if (closed) {
throw new IOException("Stream is closed");
diff --git a/luni/src/main/java/java/util/zip/ZipOutputStream.java b/luni/src/main/java/java/util/zip/ZipOutputStream.java
index 7586c84..55a52bf 100644
--- a/luni/src/main/java/java/util/zip/ZipOutputStream.java
+++ b/luni/src/main/java/java/util/zip/ZipOutputStream.java
@@ -20,6 +20,8 @@ package java.util.zip;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.charset.Charsets;
+import java.util.Arrays;
import java.util.Vector;
/**
@@ -36,11 +38,31 @@ import java.util.Vector;
* href="http://www.pkware.com/documents/casestudies/APPNOTE.TXT">file format
* specification</a>.
*
+ * <h3>Example</h3>
+ * <p>Using {@code ZipOutputStream} is a little more complicated than {@link GZIPOutputStream}
+ * because ZIP archives are containers that can contain multiple files. This code creates a ZIP
+ * archive containing several files, similar to the {@code zip(1)} utility.
+ * <pre>
+ * OutputStream os = ...
+ * ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os));
+ * try {
+ * for (int i = 0; i < fileCount; ++i) {
+ * String filename = ...
+ * byte[] bytes = ...
+ * ZipEntry entry = new ZipEntry(filename);
+ * zos.putNextEntry(entry);
+ * zos.write(bytes);
+ * zos.closeEntry();
+ * }
+ * } finally {
+ * zos.close();
+ * }
+ * </pre>
+ *
* @see ZipEntry
* @see ZipFile
*/
-public class ZipOutputStream extends DeflaterOutputStream implements
- ZipConstants {
+public class ZipOutputStream extends DeflaterOutputStream implements ZipConstants {
/**
* Indicates deflated entries.
@@ -52,7 +74,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements
*/
public static final int STORED = 0;
- static final int ZIPLocalHeaderVersionNeeded = 20;
+ private static final int ZIPLocalHeaderVersionNeeded = 20;
private String comment;
@@ -92,8 +114,10 @@ public class ZipOutputStream extends DeflaterOutputStream implements
*/
@Override
public void close() throws IOException {
+ // don't call super.close() because that calls finish() conditionally
if (out != null) {
finish();
+ def.end();
out.close();
out = null;
}
@@ -223,7 +247,6 @@ public class ZipOutputStream extends DeflaterOutputStream implements
// Write the central dir
out.write(cDir.toByteArray());
cDir = null;
-
}
/**
@@ -238,7 +261,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements
* If an error occurs storing the entry.
* @see #write
*/
- public void putNextEntry(ZipEntry ze) throws java.io.IOException {
+ public void putNextEntry(ZipEntry ze) throws IOException {
if (currentEntry != null) {
closeEntry();
}
@@ -257,7 +280,8 @@ public class ZipOutputStream extends DeflaterOutputStream implements
if (entries.contains(ze.name)) {
throw new ZipException("Entry already exists: " + ze.name);
}
- nameLength = utf8Count(ze.name);
+ nameBytes = ze.name.getBytes(Charsets.UTF_8);
+ nameLength = nameBytes.length;
if (nameLength > 0xffff) {
throw new IllegalArgumentException("Name too long: " + nameLength + " UTF-8 bytes");
}
@@ -306,7 +330,6 @@ public class ZipOutputStream extends DeflaterOutputStream implements
} else {
writeShort(out, 0);
}
- nameBytes = toUTF8Bytes(currentEntry.name, nameLength);
out.write(nameBytes);
if (currentEntry.extra != null) {
out.write(currentEntry.extra);
@@ -336,8 +359,7 @@ public class ZipOutputStream extends DeflaterOutputStream implements
* @see Deflater
*/
public void setLevel(int level) {
- if (level < Deflater.DEFAULT_COMPRESSION
- || level > Deflater.BEST_COMPRESSION) {
+ if (level < Deflater.DEFAULT_COMPRESSION || level > Deflater.BEST_COMPRESSION) {
throw new IllegalArgumentException();
}
compressLevel = level;
@@ -356,10 +378,9 @@ public class ZipOutputStream extends DeflaterOutputStream implements
throw new IllegalArgumentException();
}
compressMethod = method;
-
}
- private long writeLong(OutputStream os, long i) throws java.io.IOException {
+ private long writeLong(OutputStream os, long i) throws IOException {
// Write out the long value as an unsigned int
os.write((int) (i & 0xFF));
os.write((int) (i >> 8) & 0xFF);
@@ -368,11 +389,10 @@ public class ZipOutputStream extends DeflaterOutputStream implements
return i;
}
- private int writeShort(OutputStream os, int i) throws java.io.IOException {
+ private int writeShort(OutputStream os, int i) throws IOException {
os.write(i & 0xFF);
os.write((i >> 8) & 0xFF);
return i;
-
}
/**
@@ -382,58 +402,18 @@ public class ZipOutputStream extends DeflaterOutputStream implements
* If an error occurs writing to the stream
*/
@Override
- public void write(byte[] buffer, int off, int nbytes)
- throws java.io.IOException {
- // avoid int overflow, check null buf
- if ((off < 0 || (nbytes < 0) || off > buffer.length)
- || (buffer.length - off < nbytes)) {
- throw new IndexOutOfBoundsException();
- }
-
+ public void write(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
if (currentEntry == null) {
throw new ZipException("No active entry");
}
if (currentEntry.getMethod() == STORED) {
- out.write(buffer, off, nbytes);
+ out.write(buffer, offset, byteCount);
} else {
- super.write(buffer, off, nbytes);
- }
- crc.update(buffer, off, nbytes);
- }
-
- static int utf8Count(String value) {
- int total = 0;
- for (int i = value.length(); --i >= 0;) {
- char ch = value.charAt(i);
- if (ch < 0x80) {
- total++;
- } else if (ch < 0x800) {
- total += 2;
- } else {
- total += 3;
- }
- }
- return total;
- }
-
- static byte[] toUTF8Bytes(String value, int length) {
- byte[] result = new byte[length];
- int pos = result.length;
- for (int i = value.length(); --i >= 0;) {
- char ch = value.charAt(i);
- if (ch < 0x80) {
- result[--pos] = (byte) ch;
- } else if (ch < 0x800) {
- result[--pos] = (byte) (0x80 | (ch & 0x3f));
- result[--pos] = (byte) (0xc0 | (ch >> 6));
- } else {
- result[--pos] = (byte) (0x80 | (ch & 0x3f));
- result[--pos] = (byte) (0x80 | ((ch >> 6) & 0x3f));
- result[--pos] = (byte) (0xe0 | (ch >> 12));
- }
+ super.write(buffer, offset, byteCount);
}
- return result;
+ crc.update(buffer, offset, byteCount);
}
private void checkClosed() throws IOException {
diff --git a/luni/src/main/java/javax/crypto/Cipher.java b/luni/src/main/java/javax/crypto/Cipher.java
index 20dca98..aaf6b35 100644
--- a/luni/src/main/java/javax/crypto/Cipher.java
+++ b/luni/src/main/java/javax/crypto/Cipher.java
@@ -107,7 +107,7 @@ public class Cipher {
/**
* Used to access common engine functionality.
*/
- private static final Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
/**
* The provider.
@@ -264,53 +264,60 @@ public class Cipher {
boolean needSetPadding = false;
boolean needSetMode = false;
+ Object engineSpi = null;
+ Provider engineProvider = provider;
if (transf[1] == null && transf[2] == null) { // "algorithm"
if (provider == null) {
- engine.getInstance(transf[0], null);
+ Engine.SpiAndProvider sap = ENGINE.getInstance(transf[0], null);
+ engineSpi = sap.spi;
+ engineProvider = sap.provider;
} else {
- engine.getInstance(transf[0], provider, null);
+ engineSpi = ENGINE.getInstance(transf[0], provider, null);
}
} else {
- String[] searhOrder = {
- transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode/padding"
- transf[0] + "/" + transf[1], // "algorithm/mode"
- transf[0] + "//" + transf[2], // "algorithm//padding"
- transf[0] // "algorithm"
+ String[] searchOrder = {
+ transf[0] + "/" + transf[1] + "/" + transf[2], // "algorithm/mode/padding"
+ transf[0] + "/" + transf[1], // "algorithm/mode"
+ transf[0] + "//" + transf[2], // "algorithm//padding"
+ transf[0] // "algorithm"
};
int i;
- for (i = 0; i < searhOrder.length; i++) {
+ for (i = 0; i < searchOrder.length; i++) {
try {
if (provider == null) {
- engine.getInstance(searhOrder[i], null);
+ Engine.SpiAndProvider sap = ENGINE.getInstance(searchOrder[i], null);
+ engineSpi = sap.spi;
+ engineProvider = sap.provider;
} else {
- engine.getInstance(searhOrder[i], provider, null);
+ engineSpi = ENGINE.getInstance(searchOrder[i], provider, null);
}
break;
} catch (NoSuchAlgorithmException e) {
- if ( i == searhOrder.length-1) {
+ if (i == searchOrder.length-1) {
throw new NoSuchAlgorithmException(transformation);
}
}
}
switch (i) {
- case 1: // "algorithm/mode"
- needSetPadding = true;
- break;
- case 2: // "algorithm//padding"
- needSetMode = true;
- break;
- case 3: // "algorithm"
- needSetPadding = true;
- needSetMode = true;
+ case 1: // "algorithm/mode"
+ needSetPadding = true;
+ break;
+ case 2: // "algorithm//padding"
+ needSetMode = true;
+ break;
+ case 3: // "algorithm"
+ needSetPadding = true;
+ needSetMode = true;
}
}
- CipherSpi cspi;
- try {
- cspi = (CipherSpi) engine.spi;
- } catch (ClassCastException e) {
- throw new NoSuchAlgorithmException(e);
+ if (engineSpi == null || engineProvider == null) {
+ throw new NoSuchAlgorithmException(transformation);
+ }
+ if (!(engineSpi instanceof CipherSpi)) {
+ throw new NoSuchAlgorithmException(engineSpi.getClass().getName());
}
- Cipher c = new Cipher(cspi, engine.provider, transformation);
+ CipherSpi cspi = (CipherSpi) engineSpi;
+ Cipher c = new Cipher(cspi, engineProvider, transformation);
if (needSetMode) {
c.spiImpl.engineSetMode(transf[1]);
}
@@ -513,7 +520,8 @@ public class Cipher {
}
private void checkMode(int mode) {
- if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE && mode != UNWRAP_MODE && mode != WRAP_MODE) {
+ if (mode != ENCRYPT_MODE && mode != DECRYPT_MODE
+ && mode != UNWRAP_MODE && mode != WRAP_MODE) {
throw new InvalidParameterException("Invalid mode: " + mode);
}
}
@@ -782,28 +790,35 @@ public class Cipher {
boolean critical = false;
if (ce != null && !ce.isEmpty()) {
for (String oid : ce) {
- if (oid.equals("2.5.29.15")) { //KeyUsage OID = 2.5.29.15
+ if (oid.equals("2.5.29.15")) { // KeyUsage OID = 2.5.29.15
critical = true;
break;
}
}
if (critical) {
- boolean[] keyUsage = ((X509Certificate) certificate)
- .getKeyUsage();
- // As specified in RFC 3280 -
- // Internet X.509 Public Key Infrastructure
- // Certificate and Certificate Revocation List (CRL) Profile.
- // (http://www.ietf.org/rfc/rfc3280.txt)
+ boolean[] keyUsage = ((X509Certificate) certificate).getKeyUsage();
+ // As specified in RFC 3280:
+ // Internet X.509 Public Key Infrastructure
+ // Certificate and Certificate Revocation List (CRL) Profile.
+ // Section 4.2.1.3 Key Usage
+ // http://www.ietf.org/rfc/rfc3280.txt
//
// KeyUsage ::= BIT STRING {digitalSignature (0),
- // ...
- // encipherOnly (7),
- // decipherOnly (8) }
+ // nonRepudiation (1),
+ // keyEncipherment (2),
+ // dataEncipherment (3),
+ // keyAgreement (4),
+ // keyCertSign (5),
+ // cRLSign (6),
+ // encipherOnly (7),
+ // decipherOnly (8) }
if (keyUsage != null) {
- if (opmode == ENCRYPT_MODE && (!keyUsage[7])) {
- throw new InvalidKeyException("The public key in the certificate cannot be used for ENCRYPT_MODE");
- } else if (opmode == DECRYPT_MODE && (!keyUsage[8])) {
- throw new InvalidKeyException("The public key in the certificate cannot be used for DECRYPT_MODE");
+ if (opmode == ENCRYPT_MODE && !keyUsage[3]) {
+ throw new InvalidKeyException("The public key in the certificate "
+ + "cannot be used for ENCRYPT_MODE");
+ } else if (opmode == WRAP_MODE && !keyUsage[2]) {
+ throw new InvalidKeyException("The public key in the certificate "
+ + "cannot be used for WRAP_MODE");
}
}
}
diff --git a/luni/src/main/java/javax/crypto/CipherInputStream.java b/luni/src/main/java/javax/crypto/CipherInputStream.java
index 85f38b7..fa6040f 100644
--- a/luni/src/main/java/javax/crypto/CipherInputStream.java
+++ b/luni/src/main/java/javax/crypto/CipherInputStream.java
@@ -21,6 +21,7 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
+import libcore.base.Streams;
/**
* This class wraps an {@code InputStream} and a cipher so that {@code read()}
@@ -162,30 +163,9 @@ public class CipherInputStream extends FilterInputStream {
return i;
}
- /**
- * Skips up to n bytes from this input stream.
- * <p>
- * The number of bytes skipped depends on the result of a call to
- * {@link CipherInputStream#available() available}. The smaller of n and the
- * result are the number of bytes being skipped.
- *
- * @param n
- * the number of bytes that should be skipped.
- * @return the number of bytes actually skipped.
- * @throws IOException
- * if an error occurs
- */
@Override
- public long skip(long n) throws IOException {
- long i = 0;
- int available = available();
- if (available < n) {
- n = available;
- }
- while ((i < n) && (read() != -1)) {
- i++;
- }
- return i;
+ public long skip(long byteCount) throws IOException {
+ return Streams.skipByReading(this, byteCount);
}
@Override
diff --git a/luni/src/main/java/javax/crypto/ExemptionMechanism.java b/luni/src/main/java/javax/crypto/ExemptionMechanism.java
index fe7e553..2ac4994 100644
--- a/luni/src/main/java/javax/crypto/ExemptionMechanism.java
+++ b/luni/src/main/java/javax/crypto/ExemptionMechanism.java
@@ -36,7 +36,7 @@ import org.apache.harmony.security.fortress.Engine;
public class ExemptionMechanism {
// Used to access common engine functionality
- private static final Engine engine = new Engine("ExemptionMechanism");
+ private static final Engine ENGINE = new Engine("ExemptionMechanism");
// Store used provider
private final Provider provider;
@@ -100,11 +100,8 @@ public class ExemptionMechanism {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new ExemptionMechanism((ExemptionMechanismSpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new ExemptionMechanism((ExemptionMechanismSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -167,11 +164,8 @@ public class ExemptionMechanism {
if (provider == null) {
throw new IllegalArgumentException("provider == null");
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new ExemptionMechanism((ExemptionMechanismSpi) engine.spi,
- provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new ExemptionMechanism((ExemptionMechanismSpi) spi, provider, algorithm);
}
/**
@@ -373,6 +367,8 @@ public class ExemptionMechanism {
try {
super.finalize();
} catch (Throwable t) {
+ // for consistency with the RI, we must override Object.finalize() to
+ // remove the throws clause.
throw new AssertionError(t);
}
}
diff --git a/luni/src/main/java/javax/crypto/KeyAgreement.java b/luni/src/main/java/javax/crypto/KeyAgreement.java
index 8df7447..9c5d86c 100644
--- a/luni/src/main/java/javax/crypto/KeyAgreement.java
+++ b/luni/src/main/java/javax/crypto/KeyAgreement.java
@@ -36,10 +36,10 @@ import org.apache.harmony.security.fortress.Engine;
public class KeyAgreement {
// Used to access common engine functionality
- private static final Engine engine = new Engine("KeyAgreement");
+ private static final Engine ENGINE = new Engine("KeyAgreement");
// Store SecureRandom
- private static final SecureRandom rndm = new SecureRandom();
+ private static final SecureRandom RANDOM = new SecureRandom();
// Store used provider
private final Provider provider;
@@ -101,11 +101,8 @@ public class KeyAgreement {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyAgreement((KeyAgreementSpi) engine.spi, engine.provider,
- algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new KeyAgreement((KeyAgreementSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -166,11 +163,8 @@ public class KeyAgreement {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyAgreement((KeyAgreementSpi) engine.spi, provider,
- algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new KeyAgreement((KeyAgreementSpi) spi, provider, algorithm);
}
/**
@@ -183,7 +177,7 @@ public class KeyAgreement {
* agreement.
*/
public final void init(Key key) throws InvalidKeyException {
- spiImpl.engineInit(key, rndm);//new SecureRandom());
+ spiImpl.engineInit(key, RANDOM);//new SecureRandom());
}
/**
@@ -220,7 +214,7 @@ public class KeyAgreement {
*/
public final void init(Key key, AlgorithmParameterSpec params)
throws InvalidKeyException, InvalidAlgorithmParameterException {
- spiImpl.engineInit(key, params, rndm);//new SecureRandom());
+ spiImpl.engineInit(key, params, RANDOM);//new SecureRandom());
}
/**
diff --git a/luni/src/main/java/javax/crypto/KeyGenerator.java b/luni/src/main/java/javax/crypto/KeyGenerator.java
index 915662c..77b1a82 100644
--- a/luni/src/main/java/javax/crypto/KeyGenerator.java
+++ b/luni/src/main/java/javax/crypto/KeyGenerator.java
@@ -34,10 +34,10 @@ import org.apache.harmony.security.fortress.Engine;
public class KeyGenerator {
// Used to access common engine functionality
- private static final Engine engine = new Engine("KeyGenerator");
+ private static final Engine ENGINE = new Engine("KeyGenerator");
// Store SecureRandom
- private static final SecureRandom rndm = new SecureRandom();
+ private static final SecureRandom RANDOM = new SecureRandom();
// Store used provider
private final Provider provider;
@@ -100,11 +100,8 @@ public class KeyGenerator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyGenerator((KeyGeneratorSpi) engine.spi, engine.provider,
- algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new KeyGenerator((KeyGeneratorSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -163,11 +160,8 @@ public class KeyGenerator {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyGenerator((KeyGeneratorSpi) engine.spi, provider,
- algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new KeyGenerator((KeyGeneratorSpi) spi, provider, algorithm);
}
/**
@@ -191,7 +185,7 @@ public class KeyGenerator {
*/
public final void init(AlgorithmParameterSpec params)
throws InvalidAlgorithmParameterException {
- spiImpl.engineInit(params, rndm);//new SecureRandom());
+ spiImpl.engineInit(params, RANDOM);//new SecureRandom());
}
/**
@@ -219,7 +213,7 @@ public class KeyGenerator {
* the size of the key (in bits).
*/
public final void init(int keysize) {
- spiImpl.engineInit(keysize, rndm);//new SecureRandom());
+ spiImpl.engineInit(keysize, RANDOM);//new SecureRandom());
}
/**
diff --git a/luni/src/main/java/javax/crypto/Mac.java b/luni/src/main/java/javax/crypto/Mac.java
index 1e98db8..1a05b59 100644
--- a/luni/src/main/java/javax/crypto/Mac.java
+++ b/luni/src/main/java/javax/crypto/Mac.java
@@ -36,7 +36,7 @@ import org.apache.harmony.security.fortress.Engine;
public class Mac implements Cloneable {
//Used to access common engine functionality
- private static final Engine engine = new Engine("Mac");
+ private static final Engine ENGINE = new Engine("Mac");
// Store used provider
private final Provider provider;
@@ -103,10 +103,8 @@ public class Mac implements Cloneable {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new Mac((MacSpi) engine.spi, engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new Mac((MacSpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -167,10 +165,8 @@ public class Mac implements Cloneable {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new Mac((MacSpi) engine.spi, provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new Mac((MacSpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/javax/crypto/SecretKeyFactory.java b/luni/src/main/java/javax/crypto/SecretKeyFactory.java
index 05dc1ba..5e47abe 100644
--- a/luni/src/main/java/javax/crypto/SecretKeyFactory.java
+++ b/luni/src/main/java/javax/crypto/SecretKeyFactory.java
@@ -42,7 +42,7 @@ import org.apache.harmony.security.fortress.Engine;
public class SecretKeyFactory {
// Used to access common engine functionality
- private static final Engine engine = new Engine("SecretKeyFactory");
+ private static final Engine ENGINE = new Engine("SecretKeyFactory");
// Store used provider
private final Provider provider;
@@ -105,11 +105,8 @@ public class SecretKeyFactory {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi,
- engine.provider, algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new SecretKeyFactory((SecretKeyFactorySpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -170,11 +167,8 @@ public class SecretKeyFactory {
if (algorithm == null) {
throw new NullPointerException();
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new SecretKeyFactory((SecretKeyFactorySpi) engine.spi, provider,
- algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new SecretKeyFactory((SecretKeyFactorySpi) spi, provider, algorithm);
}
/**
diff --git a/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java b/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
index eac721d..581ff0d 100644
--- a/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
+++ b/luni/src/main/java/javax/crypto/spec/IvParameterSpec.java
@@ -22,6 +22,7 @@
package javax.crypto.spec;
import java.security.spec.AlgorithmParameterSpec;
+import java.util.Arrays;
/**
* The algorithm parameter specification for an <i>initialization vector</i>.
@@ -48,32 +49,24 @@ public class IvParameterSpec implements AlgorithmParameterSpec {
}
/**
- * Creates a new <code>IvParameterSpec</code> instance with <code>len</code>
+ * Creates a new <code>IvParameterSpec</code> instance with <code>byteCount</code>
* bytes from the specified buffer <code>iv</code> starting at
* <code>offset</code>.
*
- * @param iv
- * the buffer used as initialization vector.
- * @param offset
- * the offset to start in the buffer.
- * @param len
- * the length of the data.
* @throws IllegalArgumentException
* if the specified buffer is null or <code>offset</code> and
- * <code>len</code> do not specify a valid chunk in the
+ * <code>byteCount</code> do not specify a valid chunk in the
* specified buffer.
* @throws ArrayIndexOutOfBoundsException
- * if <code>offset</code> or <code>len</code> are negative.
+ * if <code>offset</code> or <code>byteCount</code> are negative.
*/
- public IvParameterSpec(byte[] iv, int offset, int len) {
- if ((iv == null) || (iv.length - offset < len)) {
+ public IvParameterSpec(byte[] iv, int offset, int byteCount) {
+ if ((iv == null) || (iv.length - offset < byteCount)) {
throw new IllegalArgumentException();
}
- if (offset < 0 || len < 0) {
- throw new ArrayIndexOutOfBoundsException();
- }
- this.iv = new byte[len];
- System.arraycopy(iv, offset, this.iv, 0, len);
+ Arrays.checkOffsetAndCount(iv.length, offset, byteCount);
+ this.iv = new byte[byteCount];
+ System.arraycopy(iv, offset, this.iv, 0, byteCount);
}
/**
diff --git a/luni/src/main/java/javax/crypto/spec/PBEKeySpec.java b/luni/src/main/java/javax/crypto/spec/PBEKeySpec.java
index 1d67f68..c84cdcb 100644
--- a/luni/src/main/java/javax/crypto/spec/PBEKeySpec.java
+++ b/luni/src/main/java/javax/crypto/spec/PBEKeySpec.java
@@ -19,6 +19,7 @@ package javax.crypto.spec;
import java.security.spec.KeySpec;
import java.util.Arrays;
+import libcore.base.EmptyArray;
/**
* The key specification for a <i>password based encryption</i> key.
@@ -41,7 +42,7 @@ public class PBEKeySpec implements KeySpec {
*/
public PBEKeySpec(char[] password) {
if (password == null) {
- this.password = new char[0];
+ this.password = EmptyArray.CHAR;
} else {
this.password = new char[password.length];
System.arraycopy(password, 0, this.password, 0, password.length);
@@ -85,7 +86,7 @@ public class PBEKeySpec implements KeySpec {
}
if (password == null) {
- this.password = new char[0];
+ this.password = EmptyArray.CHAR;
} else {
this.password = new char[password.length];
System.arraycopy(password, 0, this.password, 0, password.length);
@@ -123,7 +124,7 @@ public class PBEKeySpec implements KeySpec {
}
if (password == null) {
- this.password = new char[0];
+ this.password = EmptyArray.CHAR;
} else {
this.password = new char[password.length];
System.arraycopy(password, 0, this.password, 0, password.length);
diff --git a/luni/src/main/java/javax/crypto/spec/PSource.java b/luni/src/main/java/javax/crypto/spec/PSource.java
index a7f592c..5f520f3 100644
--- a/luni/src/main/java/javax/crypto/spec/PSource.java
+++ b/luni/src/main/java/javax/crypto/spec/PSource.java
@@ -17,6 +17,8 @@
package javax.crypto.spec;
+import libcore.base.EmptyArray;
+
/**
* The source of the label <code>L</code> as specified in <a
* href="http://www.ietf.org/rfc/rfc3447.txt"> PKCS #1</a>.
@@ -68,7 +70,7 @@ public class PSource {
private PSpecified() {
super("PSpecified");
- p = new byte[0];
+ p = EmptyArray.BYTE;
}
/**
diff --git a/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java b/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
index 4726321..08a890f 100644
--- a/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
+++ b/luni/src/main/java/javax/crypto/spec/RC5ParameterSpec.java
@@ -114,7 +114,7 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
throw new IllegalArgumentException("iv == null");
}
if (offset < 0) {
- throw new ArrayIndexOutOfBoundsException("offset < 0");
+ throw new ArrayIndexOutOfBoundsException("offset < 0: " + offset);
}
if (iv.length - offset < 2 * (wordSize / 8)) {
throw new IllegalArgumentException("iv.length - offset < 2 * (wordSize / 8)");
diff --git a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
index ff53632..dc17202 100644
--- a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
+++ b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
@@ -15,42 +15,27 @@
* limitations under the License.
*/
-// BEGIN android-added
-// Copied and condensed code taken from the Apache HttpClient. Also slightly
-// modified, so it matches the package/class structure of the core libraries.
-// This HostnameVerifier does checking similar to what the RI and popular
-// browsers do.
-// END android-added
-
package javax.net.ssl;
-import java.io.IOException;
+import java.net.InetAddress;
import java.security.cert.Certificate;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
+import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLSocket;
/**
* A HostnameVerifier that works the same way as Curl and Firefox.
- * <p/>
- * The hostname must match either the first CN, or any of the subject-alts.
+ *
+ * <p>The hostname must match either the first CN, or any of the subject-alts.
* A wildcard can occur in the CN, and in any of the subject-alts.
- * <p/>
- * The only difference between BROWSER_COMPATIBLE and STRICT is that a wildcard
- * (such as "*.foo.com") with BROWSER_COMPATIBLE matches all subdomains,
- * including "a.b.foo.com".
*
* @author Julius Davies
*/
@@ -60,8 +45,8 @@ class DefaultHostnameVerifier implements HostnameVerifier {
* This contains a list of 2nd-level domains that aren't allowed to
* have wildcards when combined with country-codes.
* For example: [*.co.uk].
- * <p/>
- * The [*.co.uk] problem is an interesting one. Should we just hope
+ *
+ * <p>The [*.co.uk] problem is an interesting one. Should we just hope
* that CA's would never foolishly allow such a certificate to happen?
* Looks like we're the only implementation guarding against this.
* Firefox, Curl, Sun Java 1.4, 5, 6 don't bother with this check.
@@ -75,152 +60,67 @@ class DefaultHostnameVerifier implements HostnameVerifier {
Arrays.sort(BAD_COUNTRY_2LDS);
}
- public final void verify(String host, SSLSocket ssl)
- throws IOException {
- if (host == null) {
- throw new NullPointerException("host to verify is null");
- }
-
- SSLSession session = ssl.getSession();
- Certificate[] certs = session.getPeerCertificates();
- X509Certificate x509 = (X509Certificate) certs[0];
- verify(host, x509);
- }
-
public final boolean verify(String host, SSLSession session) {
+ Certificate[] certs;
try {
- Certificate[] certs = session.getPeerCertificates();
- X509Certificate x509 = (X509Certificate) certs[0];
- verify(host, x509);
- return true;
+ certs = session.getPeerCertificates();
} catch (SSLException e) {
return false;
}
- }
-
- public final void verify(String host, X509Certificate cert)
- throws SSLException {
- String[] cns = getCNs(cert);
- String[] subjectAlts = getDNSSubjectAlts(cert);
- verify(host, cns, subjectAlts);
- }
-
- public final void verify(final String host, final String[] cns,
- final String[] subjectAlts,
- final boolean strictWithSubDomains)
- throws SSLException {
- // Build the list of names we're going to check. Our DEFAULT and
- // STRICT implementations of the HostnameVerifier only use the
- // first CN provided. All other CNs are ignored.
- // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
- LinkedList<String> names = new LinkedList<String>();
- if (cns != null && cns.length > 0 && cns[0] != null) {
- names.add(cns[0]);
- }
- if (subjectAlts != null) {
- for (String subjectAlt : subjectAlts) {
- if (subjectAlt != null) {
- names.add(subjectAlt);
- }
- }
- }
-
- if (names.isEmpty()) {
- String msg = "Certificate for <" + host + "> doesn't contain CN or DNS subjectAlt";
- throw new SSLException(msg);
- }
- // StringBuilder for building the error message.
- StringBuilder buf = new StringBuilder();
+ X509Certificate x509 = (X509Certificate) certs[0];
// We can be case-insensitive when comparing the host we used to
// establish the socket to the hostname in the certificate.
String hostName = host.trim().toLowerCase(Locale.ENGLISH);
- boolean match = false;
- for (Iterator<String> it = names.iterator(); it.hasNext();) {
- // Don't trim the CN, though!
- String cn = it.next();
- cn = cn.toLowerCase(Locale.ENGLISH);
- // Store CN in StringBuilder in case we need to report an error.
- buf.append(" <");
- buf.append(cn);
- buf.append('>');
- if (it.hasNext()) {
- buf.append(" OR");
- }
- // The CN better have at least two dots if it wants wildcard
- // action. It also can't be [*.co.uk] or [*.co.jp] or
- // [*.org.uk], etc...
- boolean doWildcard = cn.startsWith("*.") &&
- cn.lastIndexOf('.') >= 0 &&
- acceptableCountryWildcard(cn) &&
- !isValidIPV4Address(host);
+ // Verify the first CN provided. Other CNs are ignored. Firefox, wget,
+ // curl, and Sun Java work this way.
+ String firstCn = getFirstCn(x509);
+ if (matches(hostName, firstCn)) {
+ return true;
+ }
- if (doWildcard) {
- match = hostName.endsWith(cn.substring(1));
- if (match && strictWithSubDomains) {
- // If we're in strict mode, then [*.foo.com] is not
- // allowed to match [a.b.foo.com]
- match = countDots(hostName) == countDots(cn);
- }
- } else {
- match = hostName.equals(cn);
- }
- if (match) {
- break;
+ for (String cn : getDNSSubjectAlts(x509)) {
+ if (matches(hostName, cn)) {
+ return true;
}
}
- if (!match) {
- throw new SSLException("hostname in certificate didn't match: <" + host + "> !=" + buf);
- }
+
+ return false;
}
/**
- * Takes a string and parses it to see if it is a valid IPV4 address.
+ * Returns true if {@code hostname} matches {@code cn}.
*
- * @return true, if the string represents an IPV4 address in dotted
- * notation, false otherwise
+ * @param hostName a trimmed, lowercase hostname to verify
+ * @param cn a certificate CN or DNS subject alt. Either a literal name or
+ * a wildcard of the form "*.google.com".
*/
- private static boolean isValidIPV4Address(String value) {
- // BEGIN android-changed
- // general test
- if (!value.matches("\\p{Digit}+(\\.\\p{Digit}+)*")) {
+ private boolean matches(String hostName, String cn) {
+ if (cn == null) {
return false;
}
- String[] parts = value.split("\\.");
- int length = parts.length;
- if (length < 1 || length > 4) {
- return false;
- }
+ // Don't trim the CN, though!
+ cn = cn.toLowerCase(Locale.ENGLISH);
- if (length == 1) {
- // One part decimal numeric address
- long longValue = Long.parseLong(parts[0]);
- return longValue <= 0xFFFFFFFFL;
+ if (cn.startsWith("*.")) {
+ // When a wildcard matches, also check that the wildcard is legit
+ // - Wildcards must contain at least two dots: "*.google.com"
+ // - Wildcards must be for private domains. No "*.co.uk" etc.
+ // - Wildcards must not match IP addresses: "*.8.8"
+ int matchLength = cn.length() - 1;
+ return hostName.regionMatches(hostName.length() - matchLength, cn, 1, matchLength)
+ && cn.indexOf('.', 2) != -1
+ && acceptableCountryWildcard(cn)
+ && !InetAddress.isNumeric(hostName);
} else {
- // Test each part for inclusion in the correct range
- for (int i = 0; i < length; i++) {
- // For two part addresses, the second part expresses
- // a 24-bit quantity; for three part addresses, the third
- // part expresses a 16-bit quantity.
- int max = 0xff;
- if ((length == 2) && (i == 1)) {
- max = 0xffffff;
- } else if ((length == 3) && (i == 2)) {
- max = 0xffff;
- }
- if (Integer.parseInt(parts[i]) > max) {
- return false;
- }
- }
- return true;
+ return hostName.equals(cn);
}
- // END android-changed
}
- public static boolean acceptableCountryWildcard(String cn) {
+ private boolean acceptableCountryWildcard(String cn) {
int cnLen = cn.length();
if (cnLen >= 7 && cnLen <= 9) {
// Look for the '.' in the 3rd-last position:
@@ -235,8 +135,7 @@ class DefaultHostnameVerifier implements HostnameVerifier {
return true;
}
- public static String[] getCNs(X509Certificate cert) {
- LinkedList<String> cnList = new LinkedList<String>();
+ private String getFirstCn(X509Certificate cert) {
/*
* Sebastian Hauer's original StrictSSLProtocolSocketFactory used
* getName() and had the following comment:
@@ -258,103 +157,51 @@ class DefaultHostnameVerifier implements HostnameVerifier {
*
* Looks like toString() even works with non-ascii domain names!
* I tested it with "&#x82b1;&#x5b50;.co.jp" and it worked fine.
- */
+ */
String subjectPrincipal = cert.getSubjectX500Principal().toString();
StringTokenizer st = new StringTokenizer(subjectPrincipal, ",");
- while(st.hasMoreTokens()) {
+ while (st.hasMoreTokens()) {
String tok = st.nextToken();
int x = tok.indexOf("CN=");
if (x >= 0) {
- cnList.add(tok.substring(x + 3));
+ return tok.substring(x + 3);
}
}
- if (!cnList.isEmpty()) {
- String[] cns = new String[cnList.size()];
- cnList.toArray(cns);
- return cns;
- } else {
- return null;
- }
+ return null;
}
-
/**
- * Extracts the array of SubjectAlt DNS names from an X509Certificate.
- * Returns null if there aren't any.
- * <p/>
- * Note: Java doesn't appear able to extract international characters
+ * Returns all SubjectAlt DNS names from an X509Certificate.
+ *
+ * <p>Note: Java doesn't appear able to extract international characters
* from the SubjectAlts. It can only extract international characters
* from the CN field.
- * <p/>
- * (Or maybe the version of OpenSSL I'm using to test isn't storing the
- * international characters correctly in the SubjectAlts?).
*
- * @param cert X509Certificate
- * @return Array of SubjectALT DNS names stored in the certificate.
+ * <p>(Or maybe the version of OpenSSL I'm using to test isn't storing the
+ * international characters correctly in the SubjectAlts?).
*/
- public static String[] getDNSSubjectAlts(X509Certificate cert) {
- LinkedList<String> subjectAltList = new LinkedList<String>();
- Collection<List<?>> c = null;
+ private List<String> getDNSSubjectAlts(X509Certificate cert) {
+ Collection<List<?>> subjectAlternativeNames;
try {
- c = cert.getSubjectAlternativeNames();
+ subjectAlternativeNames = cert.getSubjectAlternativeNames();
} catch (CertificateParsingException cpe) {
Logger.getLogger(DefaultHostnameVerifier.class.getName())
.log(Level.FINE, "Error parsing certificate.", cpe);
+ return Collections.emptyList();
}
- if (c != null) {
- for (List<?> aC : c) {
- List<?> list = aC;
- int type = ((Integer) list.get(0)).intValue();
- // If type is 2, then we've got a dNSName
- if (type == 2) {
- String s = (String) list.get(1);
- subjectAltList.add(s);
- }
- }
+
+ if (subjectAlternativeNames == null) {
+ return Collections.emptyList();
}
- if (!subjectAltList.isEmpty()) {
- String[] subjectAlts = new String[subjectAltList.size()];
- subjectAltList.toArray(subjectAlts);
- return subjectAlts;
- } else {
- return null;
- }
- }
- /**
- * Counts the number of dots "." in a string.
- * @param s string to count dots from
- * @return number of dots
- */
- public static int countDots(final String s) {
- int count = 0;
- for (int i = 0; i < s.length(); i++) {
- if (s.charAt(i) == '.') {
- count++;
+ List<String> subjectAltList = new ArrayList<String>();
+ for (List<?> pair : subjectAlternativeNames) {
+ int type = (Integer) pair.get(0);
+ // If type is 2, then we've got a dNSName
+ if (type == 2) {
+ subjectAltList.add((String) pair.get(1));
}
}
- return count;
+ return subjectAltList;
}
-
- /**
- * Checks to see if the supplied hostname matches any of the supplied CNs
- * or "DNS" Subject-Alts. Most implementations only look at the first CN,
- * and ignore any additional CNs. Most implementations do look at all of
- * the "DNS" Subject-Alts. The CNs or Subject-Alts may contain wildcards
- * according to RFC 2818.
- *
- * @param cns CN fields, in order, as extracted from the X.509
- * certificate.
- * @param subjectAlts Subject-Alt fields of type 2 ("DNS"), as extracted
- * from the X.509 certificate.
- * @param host The hostname to verify.
- * @throws SSLException If verification failed.
- */
- public final void verify(
- final String host,
- final String[] cns,
- final String[] subjectAlts) throws SSLException {
- verify(host, cns, subjectAlts, false);
- }
-
}
diff --git a/luni/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java b/luni/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java
index 3e58897..267648c 100644
--- a/luni/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java
+++ b/luni/src/main/java/javax/net/ssl/DefaultSSLServerSocketFactory.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.SocketException;
+import libcore.base.EmptyArray;
/**
* Default inoperative implementation of javax.net.ssl.SSLServerSocketFactory
@@ -35,12 +36,12 @@ class DefaultSSLServerSocketFactory extends SSLServerSocketFactory {
@Override
public String[] getDefaultCipherSuites() {
- return new String[0];
+ return EmptyArray.STRING;
}
@Override
public String[] getSupportedCipherSuites() {
- return new String[0];
+ return EmptyArray.STRING;
}
@Override
diff --git a/luni/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java b/luni/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java
index a44404f..5b5025d 100644
--- a/luni/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java
+++ b/luni/src/main/java/javax/net/ssl/DefaultSSLSocketFactory.java
@@ -22,6 +22,7 @@ import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
+import libcore.base.EmptyArray;
/**
* Default inoperative implementation of javax.net.ssl.SSLSocketFactory
@@ -37,12 +38,12 @@ class DefaultSSLSocketFactory extends SSLSocketFactory {
@Override
public String[] getDefaultCipherSuites() {
- return new String[0];
+ return EmptyArray.STRING;
}
@Override
public String[] getSupportedCipherSuites() {
- return new String[0];
+ return EmptyArray.STRING;
}
@Override
diff --git a/luni/src/main/java/javax/net/ssl/KeyManagerFactory.java b/luni/src/main/java/javax/net/ssl/KeyManagerFactory.java
index 21b9b59..c5c9196 100644
--- a/luni/src/main/java/javax/net/ssl/KeyManagerFactory.java
+++ b/luni/src/main/java/javax/net/ssl/KeyManagerFactory.java
@@ -37,7 +37,7 @@ public class KeyManagerFactory {
private static final String SERVICE = "KeyManagerFactory";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store default property name
private static final String PROPERTY_NAME = "ssl.KeyManagerFactory.algorithm";
@@ -76,11 +76,8 @@ public class KeyManagerFactory {
if (algorithm == null) {
throw new NullPointerException("algorithm is null");
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, engine.provider,
- algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new KeyManagerFactory((KeyManagerFactorySpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -138,10 +135,8 @@ public class KeyManagerFactory {
if (algorithm == null) {
throw new NullPointerException("algorithm is null");
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new KeyManagerFactory((KeyManagerFactorySpi) engine.spi, provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new KeyManagerFactory((KeyManagerFactorySpi) spi, provider, algorithm);
}
// Store used provider
@@ -163,8 +158,8 @@ public class KeyManagerFactory {
* @param algorithm
* the key management algorithm name.
*/
- protected KeyManagerFactory(KeyManagerFactorySpi factorySpi, Provider provider, String algorithm) {
- super();
+ protected KeyManagerFactory(KeyManagerFactorySpi factorySpi, Provider provider,
+ String algorithm) {
this.provider = provider;
this.algorithm = algorithm;
this.spiImpl = factorySpi;
@@ -216,7 +211,8 @@ public class KeyManagerFactory {
* @throws InvalidAlgorithmParameterException
* if an error occurs.
*/
- public final void init(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException {
+ public final void init(ManagerFactoryParameters spec)
+ throws InvalidAlgorithmParameterException {
spiImpl.engineInit(spec);
}
diff --git a/luni/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java b/luni/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
index 195eb43..f7fe7e8 100644
--- a/luni/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
+++ b/luni/src/main/java/javax/net/ssl/KeyStoreBuilderParameters.java
@@ -41,7 +41,6 @@ public class KeyStoreBuilderParameters implements ManagerFactoryParameters {
* the key store builder.
*/
public KeyStoreBuilderParameters(KeyStore.Builder builder) {
- super();
ksbuilders = Collections.singletonList(builder);
}
@@ -55,7 +54,6 @@ public class KeyStoreBuilderParameters implements ManagerFactoryParameters {
* if the specified list is empty.
*/
public KeyStoreBuilderParameters(List<KeyStore.Builder> parameters) {
- super();
if (parameters == null) {
throw new NullPointerException("Builders list is null");
}
diff --git a/luni/src/main/java/javax/net/ssl/SSLContext.java b/luni/src/main/java/javax/net/ssl/SSLContext.java
index 5299771..9097bb9 100644
--- a/luni/src/main/java/javax/net/ssl/SSLContext.java
+++ b/luni/src/main/java/javax/net/ssl/SSLContext.java
@@ -95,10 +95,8 @@ public class SSLContext {
if (protocol == null) {
throw new NullPointerException("protocol is null");
}
- synchronized (ENGINE) {
- ENGINE.getInstance(protocol, null);
- return new SSLContext((SSLContextSpi) ENGINE.spi, ENGINE.provider, protocol);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(protocol, null);
+ return new SSLContext((SSLContextSpi) sap.spi, sap.provider, protocol);
}
/**
@@ -158,10 +156,8 @@ public class SSLContext {
if (protocol == null) {
throw new NullPointerException("protocol is null");
}
- synchronized (ENGINE) {
- ENGINE.getInstance(protocol, provider, null);
- return new SSLContext((SSLContextSpi) ENGINE.spi, provider, protocol);
- }
+ Object spi = ENGINE.getInstance(protocol, provider, null);
+ return new SSLContext((SSLContextSpi) spi, provider, protocol);
}
private final Provider provider;
diff --git a/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java b/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java
index 896a486..04633a4 100644
--- a/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java
+++ b/luni/src/main/java/javax/net/ssl/TrustManagerFactory.java
@@ -37,7 +37,7 @@ public class TrustManagerFactory {
private static final String SERVICE = "TrustManagerFactory";
// Used to access common engine functionality
- private static Engine engine = new Engine(SERVICE);
+ private static final Engine ENGINE = new Engine(SERVICE);
// Store default property name
private static final String PROPERTYNAME = "ssl.TrustManagerFactory.algorithm";
@@ -75,11 +75,8 @@ public class TrustManagerFactory {
if (algorithm == null) {
throw new NullPointerException("algorithm is null");
}
- synchronized (engine) {
- engine.getInstance(algorithm, null);
- return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, engine.provider,
- algorithm);
- }
+ Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ return new TrustManagerFactory((TrustManagerFactorySpi) sap.spi, sap.provider, algorithm);
}
/**
@@ -137,10 +134,8 @@ public class TrustManagerFactory {
if (algorithm == null) {
throw new NullPointerException("algorithm is null");
}
- synchronized (engine) {
- engine.getInstance(algorithm, provider, null);
- return new TrustManagerFactory((TrustManagerFactorySpi) engine.spi, provider, algorithm);
- }
+ Object spi = ENGINE.getInstance(algorithm, provider, null);
+ return new TrustManagerFactory((TrustManagerFactorySpi) spi, provider, algorithm);
}
// Store used provider
@@ -211,7 +206,8 @@ public class TrustManagerFactory {
* @throws InvalidAlgorithmParameterException
* if the initialization fails.
*/
- public final void init(ManagerFactoryParameters spec) throws InvalidAlgorithmParameterException {
+ public final void init(ManagerFactoryParameters spec)
+ throws InvalidAlgorithmParameterException {
spiImpl.engineInit(spec);
}
diff --git a/luni/src/main/java/javax/xml/datatype/FactoryFinder.java b/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
index a940705..9a6b29b 100644
--- a/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
+++ b/luni/src/main/java/javax/xml/datatype/FactoryFinder.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;
+import libcore.io.IoUtils;
/**
* <p>Implement pluggabile Datatypes.</p>
@@ -290,18 +291,11 @@ final class FactoryFinder {
// XXX Does not handle all possible input as specified by the
// Jar Service Provider specification
factoryClassName = rd.readLine();
- }
- catch (IOException x) {
+ } catch (IOException x) {
// No provider found
return null;
- }
- finally {
- try {
- // try to close the reader.
- rd.close();
- }
- // Ignore the exception.
- catch (IOException exc) {}
+ } finally {
+ IoUtils.closeQuietly(rd);
}
if (factoryClassName != null &&
diff --git a/luni/src/main/java/javax/xml/transform/ErrorListener.java b/luni/src/main/java/javax/xml/transform/ErrorListener.java
index 0849132..321c5fe 100644
--- a/luni/src/main/java/javax/xml/transform/ErrorListener.java
+++ b/luni/src/main/java/javax/xml/transform/ErrorListener.java
@@ -50,7 +50,7 @@ public interface ErrorListener {
* Receive notification of a warning.
*
* <p>{@link javax.xml.transform.Transformer} can use this method to report
- * conditions that are not errors or fatal errors. The default behaviour
+ * conditions that are not errors or fatal errors. The default behavior
* is to take no action.</p>
*
* <p>After invoking this method, the Transformer must continue with
diff --git a/luni/src/main/java/javax/xml/transform/Transformer.java b/luni/src/main/java/javax/xml/transform/Transformer.java
index 09503cc..c94a9ef 100644
--- a/luni/src/main/java/javax/xml/transform/Transformer.java
+++ b/luni/src/main/java/javax/xml/transform/Transformer.java
@@ -240,7 +240,7 @@ public abstract class Transformer {
*
* <p>If any of the argument keys are not recognized and are not
* namespace qualified, the property will be ignored and not returned.
- * In other words the behaviour is not orthogonal with
+ * In other words the behavior is not orthogonal with
* {@link #setOutputProperties setOutputProperties}.</p>
*
* @return A copy of the set of output properties in effect for
diff --git a/luni/src/main/java/javax/xml/validation/SchemaFactory.java b/luni/src/main/java/javax/xml/validation/SchemaFactory.java
index 43db936..7d3a1f6 100644
--- a/luni/src/main/java/javax/xml/validation/SchemaFactory.java
+++ b/luni/src/main/java/javax/xml/validation/SchemaFactory.java
@@ -586,7 +586,7 @@ public abstract class SchemaFactory {
* in the same order as the sources. Section 4.2.3 of the XML Schema
* recommendation describes the options processors have in this
* regard. While a processor should be consistent in its treatment of
- * JAXP schema sources and XML Schema imports, the behaviour between
+ * JAXP schema sources and XML Schema imports, the behavior between
* JAXP-compliant parsers may vary; in particular, parsers may choose
* to ignore all but the first &lt;import> for a given namespace,
* regardless of information provided in schemaLocation.
diff --git a/luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java b/luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java
index b475d1d..9cf521a 100644
--- a/luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java
+++ b/luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Properties;
import javax.xml.XMLConstants;
+import libcore.io.IoUtils;
/**
* Implementation of {@link SchemaFactory#newInstance(String)}.
@@ -454,12 +455,7 @@ final class SchemaFactoryFinder {
}
}
- try {
- // try to close the reader.
- rd.close();
- }
- // Ignore the exception.
- catch (IOException exc) {}
+ IoUtils.closeQuietly(rd);
return resultFactory;
}
diff --git a/luni/src/main/java/javax/xml/xpath/XPathFactoryFinder.java b/luni/src/main/java/javax/xml/xpath/XPathFactoryFinder.java
index c85bfd1..d6ed893 100644
--- a/luni/src/main/java/javax/xml/xpath/XPathFactoryFinder.java
+++ b/luni/src/main/java/javax/xml/xpath/XPathFactoryFinder.java
@@ -30,6 +30,7 @@ import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Properties;
import javax.xml.validation.SchemaFactory;
+import libcore.io.IoUtils;
/**
* Implementation of {@link XPathFactory#newInstance(String)}.
@@ -365,12 +366,7 @@ final class XPathFactoryFinder {
}
}
- try {
- // try to close the reader.
- rd.close();
- }
- // Ignore the exception.
- catch (IOException exc) {}
+ IoUtils.closeQuietly(rd);
return resultFactory;
}
diff --git a/luni/src/main/java/libcore/base/CollectionUtils.java b/luni/src/main/java/libcore/base/CollectionUtils.java
new file mode 100644
index 0000000..322cc9e
--- /dev/null
+++ b/luni/src/main/java/libcore/base/CollectionUtils.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.base;
+
+import java.lang.ref.Reference;
+import java.util.Iterator;
+
+public final class CollectionUtils {
+ private CollectionUtils() {}
+
+ /**
+ * Returns an iterator over the values referenced by the elements of {@code
+ * iterable}.
+ *
+ * @param trim true to remove reference objects from the iterable after
+ * their referenced values have been cleared.
+ */
+ public static <T> Iterable<T> dereferenceIterable(
+ final Iterable<? extends Reference<T>> iterable, final boolean trim) {
+ return new Iterable<T>() {
+ public Iterator<T> iterator() {
+ return new Iterator<T>() {
+ private final Iterator<? extends Reference<T>> delegate = iterable.iterator();
+ private boolean removeIsOkay;
+ private T next;
+
+ private void computeNext() {
+ removeIsOkay = false;
+ while (next == null && delegate.hasNext()) {
+ next = delegate.next().get();
+ if (trim && next == null) {
+ delegate.remove();
+ }
+ }
+ }
+
+ @Override public boolean hasNext() {
+ computeNext();
+ return next != null;
+ }
+
+ @Override public T next() {
+ if (!hasNext()) {
+ throw new IllegalStateException();
+ }
+ T result = next;
+ removeIsOkay = true;
+ next = null;
+ return result;
+ }
+
+ public void remove() {
+ if (!removeIsOkay) {
+ throw new IllegalStateException();
+ }
+ delegate.remove();
+ }
+ };
+ }
+ };
+ }
+}
diff --git a/luni/src/main/java/libcore/base/EmptyArray.java b/luni/src/main/java/libcore/base/EmptyArray.java
new file mode 100644
index 0000000..6e97876
--- /dev/null
+++ b/luni/src/main/java/libcore/base/EmptyArray.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.base;
+
+public final class EmptyArray {
+ private EmptyArray() {}
+
+ public static final boolean[] BOOLEAN = new boolean[0];
+ public static final byte[] BYTE = new byte[0];
+ public static final char[] CHAR = new char[0];
+ public static final double[] DOUBLE = new double[0];
+ public static final int[] INT = new int[0];
+
+ public static final Class<?>[] CLASS = new Class[0];
+ public static final Object[] OBJECT = new Object[0];
+ public static final String[] STRING = new String[0];
+}
diff --git a/luni/src/main/java/libcore/base/Objects.java b/luni/src/main/java/libcore/base/Objects.java
index 4c420b8..22bad9c 100644
--- a/luni/src/main/java/libcore/base/Objects.java
+++ b/luni/src/main/java/libcore/base/Objects.java
@@ -25,4 +25,8 @@ public final class Objects {
public static boolean equal(Object a, Object b) {
return a == b || (a != null && a.equals(b));
}
+
+ public static int hashCode(Object o) {
+ return (o == null) ? 0 : o.hashCode();
+ }
}
diff --git a/luni/src/main/java/libcore/base/Streams.java b/luni/src/main/java/libcore/base/Streams.java
index 6d38e4f..6471941 100644
--- a/luni/src/main/java/libcore/base/Streams.java
+++ b/luni/src/main/java/libcore/base/Streams.java
@@ -16,8 +16,12 @@
package libcore.base;
+import java.io.ByteArrayOutputStream;
+import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
import java.util.concurrent.atomic.AtomicReference;
public final class Streams {
@@ -25,6 +29,46 @@ public final class Streams {
private Streams() {}
+ /**
+ * Implements {@link java.io.DataInputStream#readFully(byte[], int, int)}.
+ */
+ public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
+ if (byteCount == 0) {
+ return;
+ }
+ if (in == null) {
+ throw new NullPointerException("in == null");
+ }
+ if (dst == null) {
+ throw new NullPointerException("dst == null");
+ }
+ Arrays.checkOffsetAndCount(dst.length, offset, byteCount);
+ while (byteCount > 0) {
+ int bytesRead = in.read(dst, offset, byteCount);
+ if (bytesRead < 0) {
+ throw new EOFException();
+ }
+ offset += bytesRead;
+ byteCount -= bytesRead;
+ }
+ }
+
+ /**
+ * Returns a new byte[] containing the entire contents of the given InputStream.
+ * Useful when you don't know in advance how much data there is to be read.
+ */
+ public static byte[] readFully(InputStream in) throws IOException {
+ byte[] buffer = new byte[1024];
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ while (true) {
+ int byteCount = in.read(buffer);
+ if (byteCount == -1) {
+ return bytes.toByteArray();
+ }
+ bytes.write(buffer, 0, byteCount);
+ }
+ }
+
public static void skipAll(InputStream in) throws IOException {
do {
in.skip(Long.MAX_VALUE);
@@ -67,4 +111,19 @@ public final class Streams {
return skipped;
}
+
+ /**
+ * Copies all of the bytes from {@code in} to {@code out}. Neither stream is closed.
+ * Returns the total number of bytes transferred.
+ */
+ public static int copy(InputStream in, OutputStream out) throws IOException {
+ int total = 0;
+ byte[] buffer = new byte[8192];
+ int c;
+ while ((c = in.read(buffer)) != -1) {
+ total += c;
+ out.write(buffer, 0, c);
+ }
+ return total;
+ }
}
diff --git a/luni/src/main/java/libcore/icu/CharsetDecoderICU.java b/luni/src/main/java/libcore/icu/CharsetDecoderICU.java
new file mode 100644
index 0000000..86ba13b
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/CharsetDecoderICU.java
@@ -0,0 +1,313 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2006, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*******************************************************************************
+*/
+ /**
+ * A JNI interface for ICU converters.
+ *
+ *
+ * @author Ram Viswanadha, IBM
+ */
+package libcore.icu;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+public final class CharsetDecoderICU extends CharsetDecoder {
+ private static final int MAX_CHARS_PER_BYTE = 2;
+
+ private static final int INPUT_OFFSET = 0;
+ private static final int OUTPUT_OFFSET = 1;
+ private static final int INVALID_BYTES = 2;
+ private static final int INPUT_HELD = 3;
+ /*
+ * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input bytes consumed
+ * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output chars written
+ * data[INVALID_BYTES] = number of invalid bytes
+ * data[INPUT_HELD] = number of input bytes held in the converter's state
+ */
+ private int[] data = new int[4];
+
+ /* handle to the ICU converter that is opened */
+ private long converterHandle = 0;
+
+ private byte[] input = null;
+ private char[] output= null;
+
+ // BEGIN android-added
+ private byte[] allocatedInput = null;
+ private char[] allocatedOutput = null;
+ // END android-added
+
+ // These instance variables are always assigned in the methods before being used. This class
+ // is inherently thread-unsafe so we don't have to worry about synchronization.
+ private int inEnd;
+ private int outEnd;
+ private int ec;
+ private int savedInputHeldLen;
+
+ public static CharsetDecoderICU newInstance(Charset cs, String icuCanonicalName) {
+ // This complexity is necessary to ensure that even if the constructor, superclass
+ // constructor, or call to updateCallback throw, we still free the native peer.
+ long address = 0;
+ try {
+ address = NativeConverter.openConverter(icuCanonicalName);
+ float averageCharsPerByte = NativeConverter.getAveCharsPerByte(address);
+ CharsetDecoderICU result = new CharsetDecoderICU(cs, averageCharsPerByte, address);
+ address = 0; // CharsetDecoderICU has taken ownership; its finalizer will do the free.
+ result.updateCallback();
+ return result;
+ } finally {
+ if (address != 0) {
+ NativeConverter.closeConverter(address);
+ }
+ }
+ }
+
+ private CharsetDecoderICU(Charset cs, float averageCharsPerByte, long address) {
+ super(cs, averageCharsPerByte, MAX_CHARS_PER_BYTE);
+ this.converterHandle = address;
+ }
+
+ /**
+ * Sets this decoders replacement string. Substitutes the string in input if an
+ * unmappable or illegal sequence is encountered
+ * @param newReplacement to replace the error bytes with
+ * @stable ICU 2.4
+ */
+ protected void implReplaceWith(String newReplacement) {
+ if (converterHandle > 0) {
+ if (newReplacement.length() > NativeConverter.getMaxBytesPerChar(converterHandle)) {
+ throw new IllegalArgumentException();
+ }
+ updateCallback();
+ }
+ }
+
+ /**
+ * Sets the action to be taken if an illegal sequence is encountered
+ * @param newAction action to be taken
+ * @exception IllegalArgumentException
+ * @stable ICU 2.4
+ */
+ protected final void implOnMalformedInput(CodingErrorAction newAction) {
+ updateCallback();
+ }
+
+ /**
+ * Sets the action to be taken if an illegal sequence is encountered
+ * @param newAction action to be taken
+ * @exception IllegalArgumentException
+ * @stable ICU 2.4
+ */
+ protected final void implOnUnmappableCharacter(CodingErrorAction newAction) {
+ updateCallback();
+ }
+
+ private void updateCallback() {
+ ec = NativeConverter.setCallbackDecode(converterHandle, this);
+ if (ErrorCode.isFailure(ec)) {
+ throw ErrorCode.throwException(ec);
+ }
+ }
+
+ /**
+ * Flushes any characters saved in the converter's internal buffer and
+ * resets the converter.
+ * @param out action to be taken
+ * @return result of flushing action and completes the decoding all input.
+ * Returns CoderResult.UNDERFLOW if the action succeeds.
+ * @stable ICU 2.4
+ */
+ protected final CoderResult implFlush(CharBuffer out) {
+ try {
+ data[OUTPUT_OFFSET] = getArray(out);
+ ec = NativeConverter.flushByteToChar(
+ converterHandle, /* Handle to ICU Converter */
+ output, /* input array of chars */
+ outEnd, /* input index+1 to be written */
+ data /* contains data, inOff,outOff */
+ );
+
+ /* If we don't have room for the output, throw an exception*/
+ if (ErrorCode.isFailure(ec)) {
+ if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
+ return CoderResult.OVERFLOW;
+ } else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND) {//CSDL: add this truncated character error handling
+ if (data[INPUT_OFFSET] > 0) {
+ return CoderResult.malformedForLength(data[INPUT_OFFSET]);
+ }
+ } else {
+ throw ErrorCode.throwException(ec);
+ }
+ }
+ return CoderResult.UNDERFLOW;
+ } finally {
+ /* save the flushed data */
+ setPosition(out);
+ implReset();
+ }
+ }
+
+ protected void implReset() {
+ NativeConverter.resetByteToChar(converterHandle);
+ data[INPUT_OFFSET] = 0;
+ data[OUTPUT_OFFSET] = 0;
+ data[INVALID_BYTES] = 0;
+ data[INPUT_HELD] = 0;
+ savedInputHeldLen = 0;
+ output = null;
+ input = null;
+ allocatedInput = null;
+ allocatedOutput = null;
+ ec = 0;
+ inEnd = 0;
+ outEnd = 0;
+ }
+
+ /**
+ * Decodes one or more bytes. The default behavior of the converter
+ * is stop and report if an error in input stream is encountered.
+ * To set different behavior use @see CharsetDecoder.onMalformedInput()
+ * This method allows a buffer by buffer conversion of a data stream.
+ * The state of the conversion is saved between calls to convert.
+ * Among other things, this means multibyte input sequences can be
+ * split between calls. If a call to convert results in an Error, the
+ * conversion may be continued by calling convert again with suitably
+ * modified parameters.All conversions should be finished with a call to
+ * the flush method.
+ * @param in buffer to decode
+ * @param out buffer to populate with decoded result
+ * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
+ * action succeeds or more input is needed for completing the decoding action.
+ * @stable ICU 2.4
+ */
+ protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out){
+ if (!in.hasRemaining()){
+ return CoderResult.UNDERFLOW;
+ }
+
+ data[INPUT_OFFSET] = getArray(in);
+ data[OUTPUT_OFFSET]= getArray(out);
+ data[INPUT_HELD] = 0;
+
+ try{
+ ec = NativeConverter.decode(
+ converterHandle, /* Handle to ICU Converter */
+ input, /* input array of bytes */
+ inEnd, /* last index+1 to be converted */
+ output, /* input array of chars */
+ outEnd, /* input index+1 to be written */
+ data, /* contains data, inOff,outOff */
+ false /* don't flush the data */
+ );
+
+ // Return an error.
+ if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
+ return CoderResult.OVERFLOW;
+ } else if (ec == ErrorCode.U_INVALID_CHAR_FOUND) {
+ return CoderResult.unmappableForLength(data[INVALID_BYTES]);
+ } else if (ec == ErrorCode.U_ILLEGAL_CHAR_FOUND) {
+ return CoderResult.malformedForLength(data[INVALID_BYTES]);
+ }
+ // Decoding succeeded: give us more data.
+ return CoderResult.UNDERFLOW;
+ } finally {
+ setPosition(in);
+ setPosition(out);
+ }
+ }
+
+ /**
+ * Releases the system resources by cleanly closing ICU converter opened
+ * @stable ICU 2.4
+ */
+ @Override protected void finalize() throws Throwable {
+ try {
+ NativeConverter.closeConverter(converterHandle);
+ converterHandle = 0;
+ } finally {
+ super.finalize();
+ }
+ }
+
+ //------------------------------------------
+ // private utility methods
+ //------------------------------------------
+
+ private int getArray(CharBuffer out) {
+ if (out.hasArray()) {
+ // BEGIN android-changed: take arrayOffset into account
+ output = out.array();
+ outEnd = out.arrayOffset() + out.limit();
+ return out.arrayOffset() + out.position();
+ // END android-changed
+ } else {
+ outEnd = out.remaining();
+ // BEGIN android-added
+ if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
+ allocatedOutput = new char[outEnd];
+ }
+ output = allocatedOutput;
+ // END android-added
+ //since the new
+ // buffer start position
+ // is 0
+ return 0;
+ }
+ }
+
+ private int getArray(ByteBuffer in) {
+ if (in.hasArray()) {
+ // BEGIN android-changed: take arrayOffset into account
+ input = in.array();
+ inEnd = in.arrayOffset() + in.limit();
+ return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
+ // END android-changed
+ } else {
+ inEnd = in.remaining();
+ // BEGIN android-added
+ if (allocatedInput == null || (inEnd > allocatedInput.length)) {
+ allocatedInput = new byte[inEnd];
+ }
+ input = allocatedInput;
+ // END android-added
+ // save the current position
+ int pos = in.position();
+ in.get(input,0,inEnd);
+ // reset the position
+ in.position(pos);
+ // the start position
+ // of the new buffer
+ // is whatever is savedInputLen
+ return savedInputHeldLen;
+ }
+ }
+
+ private void setPosition(CharBuffer out) {
+ if (out.hasArray()) {
+ out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
+ } else {
+ out.put(output, 0, data[OUTPUT_OFFSET]);
+ }
+ // release reference to output array, which may not be ours
+ output = null;
+ }
+
+ private void setPosition(ByteBuffer in) {
+ // ok was there input held in the previous invocation of decodeLoop
+ // that resulted in output in this invocation?
+ in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen - data[INPUT_HELD]);
+ savedInputHeldLen = data[INPUT_HELD];
+ // release reference to input array, which may not be ours
+ input = null;
+ }
+}
diff --git a/luni/src/main/java/libcore/icu/CharsetEncoderICU.java b/luni/src/main/java/libcore/icu/CharsetEncoderICU.java
new file mode 100644
index 0000000..2855a4c
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/CharsetEncoderICU.java
@@ -0,0 +1,378 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2006, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*******************************************************************************
+*/
+/**
+ * A JNI interface for ICU converters.
+ *
+ *
+ * @author Ram Viswanadha, IBM
+ */
+package libcore.icu;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class CharsetEncoderICU extends CharsetEncoder {
+ private static final Map<String, byte[]> DEFAULT_REPLACEMENTS = new HashMap<String, byte[]>();
+ static {
+ // ICU has different default replacements to the RI in some cases. There are many
+ // additional cases, but this covers all the charsets that Java guarantees will be
+ // available, which is where compatibility seems most important. (The RI even uses
+ // the byte corresponding to '?' in ASCII as the replacement byte for charsets where that
+ // byte corresponds to an entirely different character.)
+ // It's odd that UTF-8 doesn't use U+FFFD, given that (unlike ISO-8859-1 and US-ASCII) it
+ // can represent it, but this is what the RI does...
+ byte[] questionMark = new byte[] { (byte) '?' };
+ DEFAULT_REPLACEMENTS.put("UTF-8", questionMark);
+ DEFAULT_REPLACEMENTS.put("ISO-8859-1", questionMark);
+ DEFAULT_REPLACEMENTS.put("US-ASCII", questionMark);
+ }
+
+ private static final int INPUT_OFFSET = 0;
+ private static final int OUTPUT_OFFSET = 1;
+ private static final int INVALID_CHARS = 2;
+ private static final int INPUT_HELD = 3;
+ /*
+ * data[INPUT_OFFSET] = on input contains the start of input and on output the number of input chars consumed
+ * data[OUTPUT_OFFSET] = on input contains the start of output and on output the number of output bytes written
+ * data[INVALID_CHARS] = number of invalid chars
+ * data[INPUT_HELD] = number of input chars held in the converter's state
+ */
+ private int[] data = new int[4];
+ /* handle to the ICU converter that is opened */
+ private long converterHandle=0;
+
+ private char[] input = null;
+ private byte[] output = null;
+
+ // BEGIN android-added
+ private char[] allocatedInput = null;
+ private byte[] allocatedOutput = null;
+ // END android-added
+
+ // These instance variables are always assigned in the methods before being used. This class
+ // is inherently thread-unsafe so we don't have to worry about synchronization.
+ private int inEnd;
+ private int outEnd;
+ private int ec;
+ private int savedInputHeldLen;
+
+ public static CharsetEncoderICU newInstance(Charset cs, String icuCanonicalName) {
+ // This complexity is necessary to ensure that even if the constructor, superclass
+ // constructor, or call to updateCallback throw, we still free the native peer.
+ long address = 0;
+ try {
+ address = NativeConverter.openConverter(icuCanonicalName);
+ float averageBytesPerChar = NativeConverter.getAveBytesPerChar(address);
+ float maxBytesPerChar = NativeConverter.getMaxBytesPerChar(address);
+ byte[] replacement = makeReplacement(icuCanonicalName, address);
+ CharsetEncoderICU result = new CharsetEncoderICU(cs, averageBytesPerChar, maxBytesPerChar, replacement, address);
+ address = 0; // CharsetEncoderICU has taken ownership; its finalizer will do the free.
+ result.updateCallback();
+ return result;
+ } finally {
+ if (address != 0) {
+ NativeConverter.closeConverter(address);
+ }
+ }
+ }
+
+ private static byte[] makeReplacement(String icuCanonicalName, long address) {
+ // We have our own map of RI-compatible default replacements (where ICU disagrees)...
+ byte[] replacement = DEFAULT_REPLACEMENTS.get(icuCanonicalName);
+ if (replacement != null) {
+ return replacement.clone();
+ }
+ // ...but fall back to asking ICU.
+ return NativeConverter.getSubstitutionBytes(address);
+ }
+
+ private CharsetEncoderICU(Charset cs, float averageBytesPerChar, float maxBytesPerChar, byte[] replacement, long address) {
+ super(cs, averageBytesPerChar, maxBytesPerChar, replacement);
+ this.converterHandle = address;
+ }
+
+ /**
+ * Sets this encoders replacement string. Substitutes the string in output if an
+ * unmappable or illegal sequence is encountered
+ * @param newReplacement to replace the error chars with
+ * @stable ICU 2.4
+ */
+ protected void implReplaceWith(byte[] newReplacement) {
+ if (converterHandle != 0) {
+ if (newReplacement.length > NativeConverter.getMaxBytesPerChar(converterHandle)) {
+ throw new IllegalArgumentException("Number of replacement Bytes are greater than max bytes per char");
+ }
+ updateCallback();
+ }
+ }
+
+ /**
+ * Sets the action to be taken if an illegal sequence is encountered
+ * @param newAction action to be taken
+ * @exception IllegalArgumentException
+ * @stable ICU 2.4
+ */
+ protected void implOnMalformedInput(CodingErrorAction newAction) {
+ updateCallback();
+ }
+
+ /**
+ * Sets the action to be taken if an illegal sequence is encountered
+ * @param newAction action to be taken
+ * @exception IllegalArgumentException
+ * @stable ICU 2.4
+ */
+ protected void implOnUnmappableCharacter(CodingErrorAction newAction) {
+ updateCallback();
+ }
+
+ private void updateCallback() {
+ ec = NativeConverter.setCallbackEncode(converterHandle, this);
+ if (ErrorCode.isFailure(ec)) {
+ throw ErrorCode.throwException(ec);
+ }
+ }
+
+ /**
+ * Flushes any characters saved in the converter's internal buffer and
+ * resets the converter.
+ * @param out action to be taken
+ * @return result of flushing action and completes the decoding all input.
+ * Returns CoderResult.UNDERFLOW if the action succeeds.
+ * @stable ICU 2.4
+ */
+ protected CoderResult implFlush(ByteBuffer out) {
+ try {
+ data[OUTPUT_OFFSET] = getArray(out);
+ ec = NativeConverter.flushCharToByte(converterHandle,/* Handle to ICU Converter */
+ output, /* output array of chars */
+ outEnd, /* output index+1 to be written */
+ data /* contains data, inOff,outOff */
+ );
+
+ /* If we don't have room for the output, throw an exception*/
+ if (ErrorCode.isFailure(ec)) {
+ if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
+ return CoderResult.OVERFLOW;
+ } else if (ec == ErrorCode.U_TRUNCATED_CHAR_FOUND) {//CSDL: add this truncated character error handling
+ if (data[INPUT_OFFSET] > 0) {
+ return CoderResult.malformedForLength(data[INPUT_OFFSET]);
+ }
+ } else {
+ throw ErrorCode.throwException(ec);
+ }
+ }
+ return CoderResult.UNDERFLOW;
+ } finally {
+ setPosition(out);
+ implReset();
+ }
+ }
+
+ /**
+ * Resets the from Unicode mode of converter
+ * @stable ICU 2.4
+ */
+ protected void implReset() {
+ NativeConverter.resetCharToByte(converterHandle);
+ data[INPUT_OFFSET] = 0;
+ data[OUTPUT_OFFSET] = 0;
+ data[INVALID_CHARS] = 0;
+ data[INPUT_HELD] = 0;
+ savedInputHeldLen = 0;
+ }
+
+ /**
+ * Encodes one or more chars. The default behavior of the
+ * converter is stop and report if an error in input stream is encountered.
+ * To set different behavior use @see CharsetEncoder.onMalformedInput()
+ * @param in buffer to decode
+ * @param out buffer to populate with decoded result
+ * @return result of decoding action. Returns CoderResult.UNDERFLOW if the decoding
+ * action succeeds or more input is needed for completing the decoding action.
+ * @stable ICU 2.4
+ */
+ protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+ if (!in.hasRemaining()) {
+ return CoderResult.UNDERFLOW;
+ }
+
+ data[INPUT_OFFSET] = getArray(in);
+ data[OUTPUT_OFFSET]= getArray(out);
+ data[INPUT_HELD] = 0;
+ // BEGIN android-added
+ data[INVALID_CHARS] = 0; // Make sure we don't see earlier errors.
+ // END android added
+
+ try {
+ /* do the conversion */
+ ec = NativeConverter.encode(converterHandle,/* Handle to ICU Converter */
+ input, /* input array of bytes */
+ inEnd, /* last index+1 to be converted */
+ output, /* output array of chars */
+ outEnd, /* output index+1 to be written */
+ data, /* contains data, inOff,outOff */
+ false /* don't flush the data */
+ );
+ if (ErrorCode.isFailure(ec)) {
+ /* If we don't have room for the output return error */
+ if (ec == ErrorCode.U_BUFFER_OVERFLOW_ERROR) {
+ return CoderResult.OVERFLOW;
+ } else if (ec == ErrorCode.U_INVALID_CHAR_FOUND) {
+ return CoderResult.unmappableForLength(data[INVALID_CHARS]);
+ } else if (ec == ErrorCode.U_ILLEGAL_CHAR_FOUND) {
+ // in.position(in.position() - 1);
+ return CoderResult.malformedForLength(data[INVALID_CHARS]);
+ }
+ }
+ return CoderResult.UNDERFLOW;
+ } finally {
+ /* save state */
+ setPosition(in);
+ setPosition(out);
+ }
+ }
+
+ public boolean canEncode(char c) {
+ return canEncode((int) c);
+ }
+
+ public boolean canEncode(int codePoint) {
+ return NativeConverter.canEncode(converterHandle, codePoint);
+ }
+
+ /**
+ * Releases the system resources by cleanly closing ICU converter opened
+ * @exception Throwable exception thrown by super class' finalize method
+ * @stable ICU 2.4
+ */
+ @Override protected void finalize() throws Throwable {
+ try {
+ NativeConverter.closeConverter(converterHandle);
+ converterHandle=0;
+ } finally {
+ super.finalize();
+ }
+ }
+
+ //------------------------------------------
+ // private utility methods
+ //------------------------------------------
+ private int getArray(ByteBuffer out) {
+ if (out.hasArray()) {
+ // BEGIN android-changed: take arrayOffset into account
+ output = out.array();
+ outEnd = out.arrayOffset() + out.limit();
+ return out.arrayOffset() + out.position();
+ // END android-changed
+ } else {
+ outEnd = out.remaining();
+ // BEGIN android-added
+ if (allocatedOutput == null || (outEnd > allocatedOutput.length)) {
+ allocatedOutput = new byte[outEnd];
+ }
+ output = allocatedOutput;
+ // END android-added
+ //since the new
+ // buffer start position
+ // is 0
+ return 0;
+ }
+ }
+
+ private int getArray(CharBuffer in) {
+ if (in.hasArray()) {
+ // BEGIN android-changed: take arrayOffset into account
+ input = in.array();
+ inEnd = in.arrayOffset() + in.limit();
+ return in.arrayOffset() + in.position() + savedInputHeldLen;/*exclude the number fo bytes held in previous conversion*/
+ // END android-changed
+ } else {
+ inEnd = in.remaining();
+ // BEGIN android-added
+ if (allocatedInput == null || (inEnd > allocatedInput.length)) {
+ allocatedInput = new char[inEnd];
+ }
+ input = allocatedInput;
+ // END android-added
+ // save the current position
+ int pos = in.position();
+ in.get(input,0,inEnd);
+ // reset the position
+ in.position(pos);
+ // the start position
+ // of the new buffer
+ // is whatever is savedInputLen
+ return savedInputHeldLen;
+ }
+
+ }
+ private void setPosition(ByteBuffer out) {
+
+ if (out.hasArray()) {
+ // in getArray method we accessed the
+ // array backing the buffer directly and wrote to
+ // it, so just just set the position and return.
+ // This is done to avoid the creation of temp array.
+ // BEGIN android-changed: take arrayOffset into account
+ out.position(out.position() + data[OUTPUT_OFFSET] - out.arrayOffset());
+ // END android-changed
+ } else {
+ out.put(output, 0, data[OUTPUT_OFFSET]);
+ }
+ // BEGIN android-added
+ // release reference to output array, which may not be ours
+ output = null;
+ // END android-added
+ }
+ private void setPosition(CharBuffer in){
+
+// BEGIN android-removed
+// // was there input held in the previous invocation of encodeLoop
+// // that resulted in output in this invocation?
+// if(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0){
+// int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
+// in.position(len);
+// savedInputHeldLen = data[INPUT_HELD];
+// }else{
+// in.position(in.position() + data[INPUT_OFFSET] + savedInputHeldLen);
+// savedInputHeldLen = data[INPUT_HELD];
+// in.position(in.position() - savedInputHeldLen);
+// }
+// END android-removed
+
+// BEGIN android-added
+ // Slightly rewired original code to make it cleaner. Also
+ // added a fix for the problem where input characters got
+ // lost when invalid characters were encountered. Not sure
+ // what happens when data[INVALID_CHARS] is > 1, though,
+ // since we never saw that happening.
+ int len = in.position() + data[INPUT_OFFSET] + savedInputHeldLen;
+ len -= data[INVALID_CHARS]; // Otherwise position becomes wrong.
+ in.position(len);
+ savedInputHeldLen = data[INPUT_HELD];
+ // was there input held in the previous invocation of encodeLoop
+ // that resulted in output in this invocation?
+ if(!(data[OUTPUT_OFFSET]>0 && savedInputHeldLen>0)){
+ in.position(in.position() - savedInputHeldLen);
+ }
+// END android-added
+
+ // BEGIN android-added
+ // release reference to input array, which may not be ours
+ input = null;
+ // END android-added
+ }
+}
diff --git a/luni/src/main/java/libcore/icu/CharsetICU.java b/luni/src/main/java/libcore/icu/CharsetICU.java
new file mode 100644
index 0000000..ac84e6c
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/CharsetICU.java
@@ -0,0 +1,40 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+public final class CharsetICU extends Charset {
+ private final String icuCanonicalName;
+
+ protected CharsetICU(String canonicalName, String icuCanonName, String[] aliases) {
+ super(canonicalName, aliases);
+ icuCanonicalName = icuCanonName;
+ }
+
+ public CharsetDecoder newDecoder() {
+ return CharsetDecoderICU.newInstance(this, icuCanonicalName);
+ }
+
+ public CharsetEncoder newEncoder() {
+ return CharsetEncoderICU.newInstance(this, icuCanonicalName);
+ }
+
+ public boolean contains(Charset cs) {
+ if (cs == null) {
+ return false;
+ } else if (this.equals(cs)) {
+ return true;
+ }
+ return NativeConverter.contains(this.name(), cs.name());
+ }
+}
diff --git a/luni/src/main/java/libcore/icu/CollationElementIteratorICU.java b/luni/src/main/java/libcore/icu/CollationElementIteratorICU.java
new file mode 100644
index 0000000..6d85718
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/CollationElementIteratorICU.java
@@ -0,0 +1,215 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+import java.text.CharacterIterator;
+
+/**
+* Collation element iterator JNI wrapper.
+* Iterates over the collation elements of a data string.
+* The iterator supports both forward and backwards full iteration, ie if
+* backwards iteration is performed in the midst of a forward iteration, the
+* result is undefined.
+* To perform a backwards iteration in the midst of a forward iteration,
+* reset() has to be called.
+* This will shift the position to either the start or the last character in the
+* data string depending on whether next() is called or previous().
+* <pre>
+* RuleBasedCollator coll = Collator.getInstance();
+* CollationElementIterator iterator = coll.getCollationElementIterator("abc");
+* int ce = 0;
+* while (ce != CollationElementIterator.NULLORDER) {
+* ce = iterator.next();
+* }
+* iterator.reset();
+* while (ce != CollationElementIterator.NULLORDER) {
+* ce = iterator.previous();
+* }
+* </pre>
+* @author syn wee quek
+* @stable ICU 2.4
+*/
+public final class CollationElementIteratorICU {
+ // public data member -------------------------------------------
+
+ /**
+ * @stable ICU 2.4
+ */
+ public static final int NULLORDER = 0xFFFFFFFF;
+
+ // public methods -----------------------------------------------
+
+ /**
+ * Reset the collation elements to their initial state.
+ * This will move the 'cursor' to the beginning of the text.
+ * @stable ICU 2.4
+ */
+ public void reset() {
+ NativeCollation.reset(address);
+ }
+
+ /**
+ * Get the ordering priority of the next collation element in the text.
+ * A single character may contain more than one collation element.
+ * @return next collation elements ordering, or NULLORDER if the end of the
+ * text is reached.
+ * @stable ICU 2.4
+ */
+ public int next() {
+ return NativeCollation.next(address);
+ }
+
+ /**
+ * Get the ordering priority of the previous collation element in the text.
+ * A single character may contain more than one collation element.
+ * @return previous collation element ordering, or NULLORDER if the end of
+ * the text is reached.
+ * @stable ICU 2.4
+ */
+ public int previous() {
+ return NativeCollation.previous(address);
+ }
+
+ /**
+ * Get the maximum length of any expansion sequences that end with the
+ * specified comparison order.
+ * @param order collation order returned by previous or next.
+ * @return maximum size of the expansion sequences ending with the collation
+ * element or 1 if collation element does not occur at the end of
+ * any expansion sequence
+ * @stable ICU 2.4
+ */
+ public int getMaxExpansion(int order) {
+ return NativeCollation.getMaxExpansion(address, order);
+ }
+
+ /**
+ * Set the text containing the collation elements.
+ * @param source text containing the collation elements.
+ * @stable ICU 2.4
+ */
+ public void setText(String source) {
+ NativeCollation.setText(address, source);
+ }
+
+ // BEGIN android-added
+ public void setText(CharacterIterator source) {
+ NativeCollation.setText(address, source.toString());
+ }
+ // END android-added
+
+ /**
+ * Get the offset of the current source character.
+ * This is an offset into the text of the character containing the current
+ * collation elements.
+ * @return offset of the current source character.
+ * @stable ICU 2.4
+ */
+ public int getOffset() {
+ return NativeCollation.getOffset(address);
+ }
+
+ /**
+ * Set the offset of the current source character.
+ * This is an offset into the text of the character to be processed.
+ * @param offset The desired character offset.
+ * @stable ICU 2.4
+ */
+ public void setOffset(int offset) {
+ NativeCollation.setOffset(address, offset);
+ }
+
+ /**
+ * Gets the primary order of a collation order.
+ * @param order the collation order
+ * @return the primary order of a collation order.
+ * @stable ICU 2.4
+ */
+ public static int primaryOrder(int order) {
+ return ((order & PRIMARY_ORDER_MASK_) >> PRIMARY_ORDER_SHIFT_) &
+ UNSIGNED_16_BIT_MASK_;
+ }
+
+ /**
+ * Gets the secondary order of a collation order.
+ * @param order the collation order
+ * @return the secondary order of a collation order.
+ * @stable ICU 2.4
+ */
+ public static int secondaryOrder(int order) {
+ return (order & SECONDARY_ORDER_MASK_) >> SECONDARY_ORDER_SHIFT_;
+ }
+
+ /**
+ * Gets the tertiary order of a collation order.
+ * @param order the collation order
+ * @return the tertiary order of a collation order.
+ * @stable ICU 2.4
+ */
+ public static int tertiaryOrder(int order) {
+ return order & TERTIARY_ORDER_MASK_;
+ }
+
+ public static CollationElementIteratorICU getInstance(int collatorAddress, String source) {
+ int iteratorAddress = NativeCollation.getCollationElementIterator(collatorAddress, source);
+ return new CollationElementIteratorICU(iteratorAddress);
+ }
+
+ private CollationElementIteratorICU(int address) {
+ this.address = address;
+ }
+
+ // protected methods --------------------------------------------
+
+ /**
+ * Garbage collection.
+ * Close C collator and reclaim memory.
+ * @stable ICU 2.4
+ */
+ @Override protected void finalize() throws Throwable {
+ try {
+ NativeCollation.closeElements(address);
+ } finally {
+ super.finalize();
+ }
+ }
+
+ // private data members -----------------------------------------
+
+ /**
+ * C collator
+ */
+ private int address;
+
+ /**
+ * ICU constant primary order mask for collation elements
+ */
+ private static final int PRIMARY_ORDER_MASK_ = 0xffff0000;
+ /**
+ * ICU constant secondary order mask for collation elements
+ */
+ private static final int SECONDARY_ORDER_MASK_ = 0x0000ff00;
+ /**
+ * ICU constant tertiary order mask for collation elements
+ */
+ private static final int TERTIARY_ORDER_MASK_ = 0x000000ff;
+ /**
+ * ICU constant primary order shift for collation elements
+ */
+ private static final int PRIMARY_ORDER_SHIFT_ = 16;
+ /**
+ * ICU constant secondary order shift for collation elements
+ */
+ private static final int SECONDARY_ORDER_SHIFT_ = 8;
+ /**
+ * Unsigned 16 bit mask
+ */
+ private static final int UNSIGNED_16_BIT_MASK_ = 0x0000FFFF;
+}
diff --git a/luni/src/main/java/libcore/icu/CollationKeyICU.java b/luni/src/main/java/libcore/icu/CollationKeyICU.java
new file mode 100644
index 0000000..614d841
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/CollationKeyICU.java
@@ -0,0 +1,117 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+import java.text.CollationKey;
+
+/**
+ * A concrete implementation of the abstract java.text.CollationKey.
+ */
+public final class CollationKeyICU extends CollationKey {
+ /**
+ * The key.
+ */
+ private final byte[] bytes;
+
+ /**
+ * Cached hash value.
+ */
+ private int hashCode;
+
+ CollationKeyICU(String source, byte[] bytes) {
+ super(source);
+ this.bytes = bytes;
+ }
+
+ @Override public int compareTo(CollationKey other) {
+ // Get the bytes from the other collation key.
+ final byte[] rhsBytes;
+ if (other instanceof CollationKeyICU) {
+ rhsBytes = ((CollationKeyICU) other).bytes;
+ } else {
+ rhsBytes = other.toByteArray();
+ }
+
+ if (bytes == null || bytes.length == 0) {
+ if (rhsBytes == null || rhsBytes.length == 0) {
+ return 0;
+ }
+ return -1;
+ } else {
+ if (rhsBytes == null || rhsBytes.length == 0) {
+ return 1;
+ }
+ }
+
+ int count = Math.min(bytes.length, rhsBytes.length);
+ for (int i = 0; i < count; ++i) {
+ int s = bytes[i] & 0xff;
+ int t = rhsBytes[i] & 0xff;
+ if (s < t) {
+ return -1;
+ }
+ if (s > t) {
+ return 1;
+ }
+ }
+ if (bytes.length < rhsBytes.length) {
+ return -1;
+ }
+ if (bytes.length > rhsBytes.length) {
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof CollationKey)) {
+ return false;
+ }
+ return compareTo((CollationKey) object) == 0;
+ }
+
+ /**
+ * Creates a hash code for this CollationKey.
+ * Compute the hash by iterating sparsely over about 32 (up to 63) bytes
+ * spaced evenly through the string. For each byte, multiply the previous
+ * hash value by a prime number and add the new byte in, like a linear
+ * congruential random number generator, producing a pseudo-random
+ * deterministic value well distributed over the output range.
+ * @return hash value of collation key. Hash value is never 0.
+ * @stable ICU 2.4
+ */
+ @Override public int hashCode() {
+ if (hashCode == 0) {
+ if (bytes != null && bytes.length != 0) {
+ int len = bytes.length;
+ int inc = ((len - 32) / 32) + 1;
+ for (int i = 0; i < len;) {
+ hashCode = (hashCode * 37) + bytes[i];
+ i += inc;
+ }
+ }
+ if (hashCode == 0) {
+ hashCode = 1;
+ }
+ }
+ return hashCode;
+ }
+
+ @Override public byte[] toByteArray() {
+ if (bytes == null || bytes.length == 0) {
+ return null;
+ }
+ return bytes.clone();
+ }
+}
diff --git a/luni/src/main/java/libcore/icu/ErrorCode.java b/luni/src/main/java/libcore/icu/ErrorCode.java
new file mode 100644
index 0000000..c093af2
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/ErrorCode.java
@@ -0,0 +1,71 @@
+/**
+******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+******************************************************************************
+*
+******************************************************************************
+*/
+
+package libcore.icu;
+
+/**
+ * Error exception class mapping ICU error codes of the enum UErrorCode
+ * @author syn wee quek
+*/
+public final class ErrorCode extends Exception {
+ public static boolean isFailure(int error) {
+ return error > U_ZERO_ERROR && error < U_ERROR_LIMIT;
+ }
+
+ public static RuntimeException throwException(int error) {
+ if (error <= U_ZERO_ERROR && error >= U_ERROR_LIMIT) {
+ return null;
+ }
+ switch (error) {
+ case U_ILLEGAL_ARGUMENT_ERROR:
+ return new IllegalArgumentException(ERROR_NAMES[error]);
+ case U_INDEX_OUTOFBOUNDS_ERROR:
+ case U_BUFFER_OVERFLOW_ERROR:
+ return new ArrayIndexOutOfBoundsException(ERROR_NAMES[error]);
+ case U_UNSUPPORTED_ERROR:
+ return new UnsupportedOperationException(ERROR_NAMES[error]);
+ }
+ throw new RuntimeException(ERROR_NAMES[error]);
+ }
+
+ // The errors needed by our CharsetDecoderICU/CharsetEncoderICU.
+ public static final int U_ZERO_ERROR = 0;
+ private static final int U_ILLEGAL_ARGUMENT_ERROR = 1;
+ private static final int U_INDEX_OUTOFBOUNDS_ERROR = 8;
+ public static final int U_INVALID_CHAR_FOUND = 10;
+ public static final int U_TRUNCATED_CHAR_FOUND = 11;
+ public static final int U_ILLEGAL_CHAR_FOUND = 12;
+ public static final int U_BUFFER_OVERFLOW_ERROR = 15;
+ private static final int U_UNSUPPORTED_ERROR = 16;
+ private static final int U_ERROR_LIMIT = 21;
+
+ // TODO: this list is incomplete; get these from native code!
+ private static final String ERROR_NAMES[] = {
+ "U_ZERO_ERROR",
+ "U_ILLEGAL_ARGUMENT_ERROR",
+ "U_MISSING_RESOURCE_ERROR",
+ "U_INVALID_FORMAT_ERROR",
+ "U_FILE_ACCESS_ERROR",
+ "U_INTERNAL_PROGRAM_ERROR",
+ "U_MESSAGE_PARSE_ERROR",
+ "U_MEMORY_ALLOCATION_ERROR",
+ "U_INDEX_OUTOFBOUNDS_ERROR",
+ "U_PARSE_ERROR",
+ "U_INVALID_CHAR_FOUND",
+ "U_TRUNCATED_CHAR_FOUND",
+ "U_ILLEGAL_CHAR_FOUND",
+ "U_INVALID_TABLE_FORMAT",
+ "U_INVALID_TABLE_FILE",
+ "U_BUFFER_OVERFLOW_ERROR",
+ "U_UNSUPPORTED_ERROR",
+ "U_RESOURCE_TYPE_MISMATCH",
+ "U_ILLEGAL_ESCAPE_SEQUENCE",
+ "U_UNSUPPORTED_ESCAPE_SEQUENCE"
+ };
+}
diff --git a/luni/src/main/java/libcore/icu/ICU.java b/luni/src/main/java/libcore/icu/ICU.java
new file mode 100644
index 0000000..3359305
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/ICU.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.icu;
+
+import java.util.Locale;
+
+/**
+ * Makes ICU data accessible to Java.
+ */
+public final class ICU {
+ /**
+ * Cache for ISO language names.
+ */
+ private static String[] isoLanguages;
+
+ /**
+ * Cache for ISO country names.
+ */
+ private static String[] isoCountries;
+
+ /**
+ * Returns an array of ISO language names (two-letter codes), fetched either
+ * from ICU's database or from our memory cache.
+ *
+ * @return The array.
+ */
+ public static String[] getISOLanguages() {
+ if (isoLanguages == null) {
+ isoLanguages = getISOLanguagesNative();
+ }
+ return isoLanguages.clone();
+ }
+
+ /**
+ * Returns an array of ISO country names (two-letter codes), fetched either
+ * from ICU's database or from our memory cache.
+ *
+ * @return The array.
+ */
+ public static String[] getISOCountries() {
+ if (isoCountries == null) {
+ isoCountries = getISOCountriesNative();
+ }
+ return isoCountries.clone();
+ }
+
+ /**
+ * Returns the appropriate {@code Locale} given a {@code String} of the form returned
+ * by {@code toString}. This is very lenient, and doesn't care what's between the underscores:
+ * this method can parse strings that {@code Locale.toString} won't produce.
+ * Used to remove duplication.
+ */
+ public static Locale localeFromString(String localeName) {
+ int first = localeName.indexOf('_');
+ int second = localeName.indexOf('_', first + 1);
+ if (first == -1) {
+ // Language only ("ja").
+ return new Locale(localeName);
+ } else if (second == -1) {
+ // Language and country ("ja_JP").
+ return new Locale(localeName.substring(0, first), localeName.substring(first + 1));
+ } else {
+ // Language and country and variant ("ja_JP_TRADITIONAL").
+ return new Locale(localeName.substring(0, first), localeName.substring(first + 1, second), localeName.substring(second + 1));
+ }
+ }
+
+ public static Locale[] localesFromStrings(String[] localeNames) {
+ Locale[] result = new Locale[localeNames.length];
+ for (int i = 0; i < result.length; ++i) {
+ result[i] = localeFromString(localeNames[i]);
+ }
+ return result;
+ }
+
+ private static Locale[] availableLocalesCache;
+ public static Locale[] getAvailableLocales() {
+ if (availableLocalesCache == null) {
+ availableLocalesCache = localesFromStrings(getAvailableLocalesNative());
+ }
+ return availableLocalesCache.clone();
+ }
+
+ public static Locale[] getAvailableBreakIteratorLocales() {
+ return localesFromStrings(getAvailableBreakIteratorLocalesNative());
+ }
+
+ public static Locale[] getAvailableCalendarLocales() {
+ return localesFromStrings(getAvailableCalendarLocalesNative());
+ }
+
+ public static Locale[] getAvailableCollatorLocales() {
+ return localesFromStrings(getAvailableCollatorLocalesNative());
+ }
+
+ public static Locale[] getAvailableDateFormatLocales() {
+ return localesFromStrings(getAvailableDateFormatLocalesNative());
+ }
+
+ public static Locale[] getAvailableDateFormatSymbolsLocales() {
+ return getAvailableDateFormatLocales();
+ }
+
+ public static Locale[] getAvailableDecimalFormatSymbolsLocales() {
+ return getAvailableNumberFormatLocales();
+ }
+
+ public static Locale[] getAvailableNumberFormatLocales() {
+ return localesFromStrings(getAvailableNumberFormatLocalesNative());
+ }
+
+ // --- Case mapping.
+
+ public static native String toLowerCase(String s, String localeName);
+ public static native String toUpperCase(String s, String localeName);
+
+ // --- Native methods accessing ICU's database.
+
+ private static native String[] getAvailableBreakIteratorLocalesNative();
+ private static native String[] getAvailableCalendarLocalesNative();
+ private static native String[] getAvailableCollatorLocalesNative();
+ private static native String[] getAvailableDateFormatLocalesNative();
+ private static native String[] getAvailableLocalesNative();
+ private static native String[] getAvailableNumberFormatLocalesNative();
+
+ public static native String getCurrencyCodeNative(String locale);
+ public static native int getCurrencyFractionDigitsNative(String currencyCode);
+ public static native String getCurrencySymbolNative(String locale, String currencyCode);
+
+ public static native String getDisplayCountryNative(String countryCode, String locale);
+ public static native String getDisplayLanguageNative(String languageCode, String locale);
+ public static native String getDisplayVariantNative(String variantCode, String locale);
+
+ public static native String getISO3CountryNative(String locale);
+ public static native String getISO3LanguageNative(String locale);
+
+ private static native String[] getISOLanguagesNative();
+ private static native String[] getISOCountriesNative();
+
+ static native boolean initLocaleDataImpl(String locale, LocaleData result);
+}
diff --git a/luni/src/main/java/libcore/icu/LocaleData.java b/luni/src/main/java/libcore/icu/LocaleData.java
new file mode 100644
index 0000000..dba7d7c
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/LocaleData.java
@@ -0,0 +1,343 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.icu;
+
+import java.text.DateFormat;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Locale;
+
+/**
+ * Passes locale-specific from ICU native code to Java.
+ * <p>
+ * Note that you share these; you must not alter any of the fields, nor their array elements
+ * in the case of arrays. If you ever expose any of these things to user code, you must give
+ * them a clone rather than the original.
+ */
+public final class LocaleData {
+ // A cache for the locale-specific data.
+ private static final HashMap<String, LocaleData> localeDataCache = new HashMap<String, LocaleData>();
+
+ // Used by Calendar.
+ public Integer firstDayOfWeek;
+ public Integer minimalDaysInFirstWeek;
+
+ // Used by DateFormatSymbols.
+ public String[] amPm;
+ public String[] eras;
+
+ public String[] longMonthNames;
+ public String[] shortMonthNames;
+ public String[] longStandAloneMonthNames;
+ public String[] shortStandAloneMonthNames;
+
+ public String[] longWeekdayNames;
+ public String[] shortWeekdayNames;
+ public String[] longStandAloneWeekdayNames;
+ public String[] shortStandAloneWeekdayNames;
+
+ public String fullTimeFormat;
+ public String longTimeFormat;
+ public String mediumTimeFormat;
+ public String shortTimeFormat;
+
+ public String fullDateFormat;
+ public String longDateFormat;
+ public String mediumDateFormat;
+ public String shortDateFormat;
+
+ // Used by DecimalFormatSymbols.
+ public char zeroDigit;
+ public char digit;
+ public char decimalSeparator;
+ public char groupingSeparator;
+ public char patternSeparator;
+ public char percent;
+ public char perMill;
+ public char monetarySeparator;
+ public char minusSign;
+ public String exponentSeparator;
+ public String infinity;
+ public String NaN;
+ // Also used by Currency.
+ public String currencySymbol;
+ public String internationalCurrencySymbol;
+
+ // Used by DecimalFormat and NumberFormat.
+ public String numberPattern;
+ public String integerPattern;
+ public String currencyPattern;
+ public String percentPattern;
+
+ private LocaleData() {
+ }
+
+ /**
+ * Returns a shared LocaleData for the given locale.
+ */
+ public static LocaleData get(Locale locale) {
+ if (locale == null) {
+ locale = Locale.getDefault();
+ }
+ String localeName = locale.toString();
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ }
+ LocaleData newLocaleData = makeLocaleData(locale);
+ synchronized (localeDataCache) {
+ LocaleData localeData = localeDataCache.get(localeName);
+ if (localeData != null) {
+ return localeData;
+ }
+ localeDataCache.put(localeName, newLocaleData);
+ return newLocaleData;
+ }
+ }
+
+ private static LocaleData makeLocaleData(Locale locale) {
+ String language = locale.getLanguage();
+ String country = locale.getCountry();
+ String variant = locale.getVariant();
+ // Start with data from the parent (next-most-specific) locale...
+ LocaleData result = new LocaleData();
+ if (!variant.isEmpty()) {
+ result.overrideWithDataFrom(get(new Locale(language, country, "")));
+ } else if (!country.isEmpty()) {
+ result.overrideWithDataFrom(get(new Locale(language, "", "")));
+ } else if (!language.isEmpty()) {
+ result.overrideWithDataFrom(get(Locale.ROOT));
+ }
+ // Override with data from this locale.
+ result.overrideWithDataFrom(initLocaleData(locale));
+ return result;
+ }
+
+ @Override public String toString() {
+ return "LocaleData[" +
+ "firstDayOfWeek=" + firstDayOfWeek + "," +
+ "minimalDaysInFirstWeek=" + minimalDaysInFirstWeek + "," +
+ "amPm=" + Arrays.toString(amPm) + "," +
+ "eras=" + Arrays.toString(eras) + "," +
+ "longMonthNames=" + Arrays.toString(longMonthNames) + "," +
+ "shortMonthNames=" + Arrays.toString(shortMonthNames) + "," +
+ "longStandAloneMonthNames=" + Arrays.toString(longStandAloneMonthNames) + "," +
+ "shortStandAloneMonthNames=" + Arrays.toString(shortStandAloneMonthNames) + "," +
+ "longWeekdayNames=" + Arrays.toString(longWeekdayNames) + "," +
+ "shortWeekdayNames=" + Arrays.toString(shortWeekdayNames) + "," +
+ "longStandAloneWeekdayNames=" + Arrays.toString(longStandAloneWeekdayNames) + "," +
+ "shortStandAloneWeekdayNames=" + Arrays.toString(shortStandAloneWeekdayNames) + "," +
+ "fullTimeFormat=" + fullTimeFormat + "," +
+ "longTimeFormat=" + longTimeFormat + "," +
+ "mediumTimeFormat=" + mediumTimeFormat + "," +
+ "shortTimeFormat=" + shortTimeFormat + "," +
+ "fullDateFormat=" + fullDateFormat + "," +
+ "longDateFormat=" + longDateFormat + "," +
+ "mediumDateFormat=" + mediumDateFormat + "," +
+ "shortDateFormat=" + shortDateFormat + "," +
+ "zeroDigit=" + zeroDigit + "," +
+ "digit=" + digit + "," +
+ "decimalSeparator=" + decimalSeparator + "," +
+ "groupingSeparator=" + groupingSeparator + "," +
+ "patternSeparator=" + patternSeparator + "," +
+ "percent=" + percent + "," +
+ "perMill=" + perMill + "," +
+ "monetarySeparator=" + monetarySeparator + "," +
+ "minusSign=" + minusSign + "," +
+ "exponentSeparator=" + exponentSeparator + "," +
+ "infinity=" + infinity + "," +
+ "NaN=" + NaN + "," +
+ "currencySymbol=" + currencySymbol + "," +
+ "internationalCurrencySymbol=" + internationalCurrencySymbol + "," +
+ "numberPattern=" + numberPattern + "," +
+ "integerPattern=" + integerPattern + "," +
+ "currencyPattern=" + currencyPattern + "," +
+ "percentPattern=" + percentPattern + "]";
+ }
+
+ private void overrideWithDataFrom(LocaleData overrides) {
+ if (overrides.firstDayOfWeek != null) {
+ firstDayOfWeek = overrides.firstDayOfWeek;
+ }
+ if (overrides.minimalDaysInFirstWeek != null) {
+ minimalDaysInFirstWeek = overrides.minimalDaysInFirstWeek;
+ }
+ if (overrides.amPm != null) {
+ amPm = overrides.amPm;
+ }
+ if (overrides.eras != null) {
+ eras = overrides.eras;
+ }
+ if (overrides.longMonthNames != null) {
+ longMonthNames = overrides.longMonthNames;
+ }
+ if (overrides.shortMonthNames != null) {
+ shortMonthNames = overrides.shortMonthNames;
+ }
+ if (overrides.longStandAloneMonthNames != null) {
+ longStandAloneMonthNames = overrides.longStandAloneMonthNames;
+ }
+ if (overrides.shortStandAloneMonthNames != null) {
+ shortStandAloneMonthNames = overrides.shortStandAloneMonthNames;
+ }
+ if (overrides.longWeekdayNames != null) {
+ longWeekdayNames = overrides.longWeekdayNames;
+ }
+ if (overrides.shortWeekdayNames != null) {
+ shortWeekdayNames = overrides.shortWeekdayNames;
+ }
+ if (overrides.longStandAloneWeekdayNames != null) {
+ longStandAloneWeekdayNames = overrides.longStandAloneWeekdayNames;
+ }
+ if (overrides.shortStandAloneWeekdayNames != null) {
+ shortStandAloneWeekdayNames = overrides.shortStandAloneWeekdayNames;
+ }
+ if (overrides.fullTimeFormat != null) {
+ fullTimeFormat = overrides.fullTimeFormat;
+ }
+ if (overrides.longTimeFormat != null) {
+ longTimeFormat = overrides.longTimeFormat;
+ }
+ if (overrides.mediumTimeFormat != null) {
+ mediumTimeFormat = overrides.mediumTimeFormat;
+ }
+ if (overrides.shortTimeFormat != null) {
+ shortTimeFormat = overrides.shortTimeFormat;
+ }
+ if (overrides.fullDateFormat != null) {
+ fullDateFormat = overrides.fullDateFormat;
+ }
+ if (overrides.longDateFormat != null) {
+ longDateFormat = overrides.longDateFormat;
+ }
+ if (overrides.mediumDateFormat != null) {
+ mediumDateFormat = overrides.mediumDateFormat;
+ }
+ if (overrides.shortDateFormat != null) {
+ shortDateFormat = overrides.shortDateFormat;
+ }
+ if (overrides.zeroDigit != '\0') {
+ zeroDigit = overrides.zeroDigit;
+ }
+ if (overrides.digit != '\0') {
+ digit = overrides.digit;
+ }
+ if (overrides.decimalSeparator != '\0') {
+ decimalSeparator = overrides.decimalSeparator;
+ }
+ if (overrides.groupingSeparator != '\0') {
+ groupingSeparator = overrides.groupingSeparator;
+ }
+ if (overrides.patternSeparator != '\0') {
+ patternSeparator = overrides.patternSeparator;
+ }
+ if (overrides.percent != '\0') {
+ percent = overrides.percent;
+ }
+ if (overrides.perMill != '\0') {
+ perMill = overrides.perMill;
+ }
+ if (overrides.monetarySeparator != '\0') {
+ monetarySeparator = overrides.monetarySeparator;
+ }
+ if (overrides.minusSign != '\0') {
+ minusSign = overrides.minusSign;
+ }
+ if (overrides.exponentSeparator != null) {
+ exponentSeparator = overrides.exponentSeparator;
+ }
+ if (overrides.NaN != null) {
+ NaN = overrides.NaN;
+ }
+ if (overrides.infinity != null) {
+ infinity = overrides.infinity;
+ }
+ if (overrides.currencySymbol != null) {
+ currencySymbol = overrides.currencySymbol;
+ }
+ if (overrides.internationalCurrencySymbol != null) {
+ internationalCurrencySymbol = overrides.internationalCurrencySymbol;
+ }
+ if (overrides.numberPattern != null) {
+ numberPattern = overrides.numberPattern;
+ }
+ if (overrides.integerPattern != null) {
+ integerPattern = overrides.integerPattern;
+ }
+ if (overrides.currencyPattern != null) {
+ currencyPattern = overrides.currencyPattern;
+ }
+ if (overrides.percentPattern != null) {
+ percentPattern = overrides.percentPattern;
+ }
+ }
+
+ public String getDateFormat(int style) {
+ switch (style) {
+ case DateFormat.SHORT:
+ return shortDateFormat;
+ case DateFormat.MEDIUM:
+ return mediumDateFormat;
+ case DateFormat.LONG:
+ return longDateFormat;
+ case DateFormat.FULL:
+ return fullDateFormat;
+ }
+ throw new AssertionError();
+ }
+
+ public String getTimeFormat(int style) {
+ switch (style) {
+ case DateFormat.SHORT:
+ return shortTimeFormat;
+ case DateFormat.MEDIUM:
+ return mediumTimeFormat;
+ case DateFormat.LONG:
+ return longTimeFormat;
+ case DateFormat.FULL:
+ return fullTimeFormat;
+ }
+ throw new AssertionError();
+ }
+
+ private static LocaleData initLocaleData(Locale locale) {
+ LocaleData localeData = new LocaleData();
+ if (!ICU.initLocaleDataImpl(locale.toString(), localeData)) {
+ throw new AssertionError("couldn't initialize LocaleData for locale " + locale);
+ }
+ if (localeData.fullTimeFormat != null) {
+ // There are some full time format patterns in ICU that use the pattern character 'v'.
+ // Java doesn't accept this, so we replace it with 'z' which has about the same result
+ // as 'v', the timezone name.
+ // 'v' -> "PT", 'z' -> "PST", v is the generic timezone and z the standard tz
+ // "vvvv" -> "Pacific Time", "zzzz" -> "Pacific Standard Time"
+ localeData.fullTimeFormat = localeData.fullTimeFormat.replace('v', 'z');
+ }
+ if (localeData.numberPattern != null) {
+ // The number pattern might contain positive and negative subpatterns. Arabic, for
+ // example, might look like "#,##0.###;#,##0.###-" because the minus sign should be
+ // written last. Macedonian supposedly looks something like "#,##0.###;(#,##0.###)".
+ // (The negative subpattern is optional, though, and not present in most locales.)
+ // By only swallowing '#'es and ','s after the '.', we ensure that we don't
+ // accidentally eat too much.
+ localeData.integerPattern = localeData.numberPattern.replaceAll("\\.[#,]*", "");
+ }
+ return localeData;
+ }
+}
diff --git a/luni/src/main/java/libcore/icu/NativeBreakIterator.java b/luni/src/main/java/libcore/icu/NativeBreakIterator.java
new file mode 100644
index 0000000..9c10461
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/NativeBreakIterator.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.icu;
+
+import java.text.CharacterIterator;
+import java.text.StringCharacterIterator;
+import java.util.Locale;
+
+public final class NativeBreakIterator implements Cloneable {
+ // Acceptable values for the 'type' field.
+ private static final int BI_CHAR_INSTANCE = 1;
+ private static final int BI_WORD_INSTANCE = 2;
+ private static final int BI_LINE_INSTANCE = 3;
+ private static final int BI_SENT_INSTANCE = 4;
+
+ private final int address;
+ private final int type;
+ private CharacterIterator charIter;
+
+ private NativeBreakIterator(int address, int type) {
+ this.address = address;
+ this.type = type;
+ this.charIter = new StringCharacterIterator("");
+ }
+
+ @Override
+ public Object clone() {
+ int cloneAddr = cloneImpl(this.address);
+ NativeBreakIterator clone = new NativeBreakIterator(cloneAddr, this.type);
+ // The RI doesn't clone the CharacterIterator.
+ clone.charIter = this.charIter;
+ return clone;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof NativeBreakIterator)) {
+ return false;
+ }
+ // TODO: is this sufficient? shouldn't we be checking the underlying rules?
+ NativeBreakIterator rhs = (NativeBreakIterator) object;
+ return type == rhs.type && charIter.equals(rhs.charIter);
+ }
+
+ @Override
+ public int hashCode() {
+ return 42; // No-one uses BreakIterator as a hash key.
+ }
+
+ @Override protected void finalize() throws Throwable {
+ try {
+ closeBreakIteratorImpl(this.address);
+ } finally {
+ super.finalize();
+ }
+ }
+
+ public int current() {
+ return currentImpl(this.address);
+ }
+
+ public int first() {
+ return firstImpl(this.address);
+ }
+
+ public int following(int offset) {
+ return followingImpl(this.address, offset);
+ }
+
+ public CharacterIterator getText() {
+ int newLoc = currentImpl(this.address);
+ this.charIter.setIndex(newLoc);
+ return this.charIter;
+ }
+
+ public int last() {
+ return lastImpl(this.address);
+ }
+
+ public int next(int n) {
+ return nextImpl(this.address, n);
+ }
+
+ public int next() {
+ return nextImpl(this.address, 1);
+ }
+
+ public int previous() {
+ return previousImpl(this.address);
+ }
+
+ public void setText(CharacterIterator newText) {
+ this.charIter = newText;
+ StringBuilder sb = new StringBuilder();
+ for (char c = newText.first(); c != CharacterIterator.DONE; c = newText.next()) {
+ sb.append(c);
+ }
+ setTextImpl(this.address, sb.toString());
+ }
+
+ public void setText(String newText) {
+ setText(new StringCharacterIterator(newText));
+ }
+
+ public boolean isBoundary(int offset) {
+ return isBoundaryImpl(this.address, offset);
+ }
+
+ public int preceding(int offset) {
+ return precedingImpl(this.address, offset);
+ }
+
+ public static NativeBreakIterator getCharacterInstance(Locale where) {
+ return new NativeBreakIterator(getCharacterInstanceImpl(where.toString()), BI_CHAR_INSTANCE);
+ }
+
+ public static NativeBreakIterator getLineInstance(Locale where) {
+ return new NativeBreakIterator(getLineInstanceImpl(where.toString()), BI_LINE_INSTANCE);
+ }
+
+ public static NativeBreakIterator getSentenceInstance(Locale where) {
+ return new NativeBreakIterator(getSentenceInstanceImpl(where.toString()), BI_SENT_INSTANCE);
+ }
+
+ public static NativeBreakIterator getWordInstance(Locale where) {
+ return new NativeBreakIterator(getWordInstanceImpl(where.toString()), BI_WORD_INSTANCE);
+ }
+
+ private static native int getCharacterInstanceImpl(String locale);
+ private static native int getWordInstanceImpl(String locale);
+ private static native int getLineInstanceImpl(String locale);
+ private static native int getSentenceInstanceImpl(String locale);
+ private static native void closeBreakIteratorImpl(int address);
+ private static native void setTextImpl(int address, String text);
+ private static native int cloneImpl(int address);
+ private static native int precedingImpl(int address, int offset);
+ private static native boolean isBoundaryImpl(int address, int offset);
+ private static native int nextImpl(int address, int n);
+ private static native int previousImpl(int address);
+ private static native int currentImpl(int address);
+ private static native int firstImpl(int address);
+ private static native int followingImpl(int address, int offset);
+ private static native int lastImpl(int address);
+}
diff --git a/luni/src/main/java/libcore/icu/NativeCollation.java b/luni/src/main/java/libcore/icu/NativeCollation.java
new file mode 100644
index 0000000..2f61c49
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/NativeCollation.java
@@ -0,0 +1,43 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+/**
+* Package static class for declaring all native methods for collation use.
+* @author syn wee quek
+* @internal ICU 2.4
+*/
+public final class NativeCollation {
+ private NativeCollation() {
+ }
+
+ // Collator.
+ public static native void closeCollator(int address);
+ public static native int compare(int address, String source, String target);
+ public static native int getAttribute(int address, int type);
+ public static native int getCollationElementIterator(int address, String source);
+ public static native String getRules(int address);
+ public static native byte[] getSortKey(int address, String source);
+ public static native int openCollator(String locale);
+ public static native int openCollatorFromRules(String rules, int normalizationMode, int collationStrength);
+ public static native int safeClone(int address);
+ public static native void setAttribute(int address, int type, int value);
+
+ // CollationElementIterator.
+ public static native void closeElements(int address);
+ public static native int getMaxExpansion(int address, int order);
+ public static native int getOffset(int address);
+ public static native int next(int address);
+ public static native int previous(int address);
+ public static native void reset(int address);
+ public static native void setOffset(int address, int offset);
+ public static native void setText(int address, String source);
+}
diff --git a/luni/src/main/java/libcore/icu/NativeConverter.java b/luni/src/main/java/libcore/icu/NativeConverter.java
new file mode 100644
index 0000000..6165c61
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/NativeConverter.java
@@ -0,0 +1,143 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2006, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+
+public final class NativeConverter {
+ /**
+ * Converts an array of bytes containing characters in an external
+ * encoding into an array of Unicode characters. This method allows
+ * buffer-by-buffer conversion of a data stream. The state of the
+ * conversion is saved between calls. Among other things,
+ * this means multibyte input sequences can be split between calls.
+ * If a call to results in an error, the conversion may be
+ * continued by calling this method again with suitably modified parameters.
+ * All conversions should be finished with a call to the flush method.
+ *
+ * @param converterHandle Address of converter object created by C code
+ * @param input byte array containing text to be converted.
+ * @param inEnd stop conversion at this offset in input array (exclusive).
+ * @param output character array to receive conversion result.
+ * @param outEnd stop writing to output array at this offset (exclusive).
+ * @param data integer array containing the following data
+ * data[0] = inputOffset
+ * data[1] = outputOffset
+ * @return int error code returned by ICU
+ * @internal ICU 2.4
+ */
+ public static native int decode(long converterHandle, byte[] input, int inEnd,
+ char[] output, int outEnd, int[] data, boolean flush);
+
+ /**
+ * Converts an array of Unicode chars to an array of bytes in an external encoding.
+ * This method allows a buffer by buffer conversion of a data stream. The state of the
+ * conversion is saved between calls to convert. Among other things,
+ * this means multibyte input sequences can be split between calls.
+ * If a call results in an error, the conversion may be
+ * continued by calling this method again with suitably modified parameters.
+ * All conversions should be finished with a call to the flush method.
+ *
+ * @param converterHandle Address of converter object created by C code
+ * @param input char array containing text to be converted.
+ * @param inEnd stop conversion at this offset in input array (exclusive).
+ * @param output byte array to receive conversion result.
+ * @param outEnd stop writing to output array at this offset (exclusive).
+ * @param data integer array containing the following data
+ * data[0] = inputOffset
+ * data[1] = outputOffset
+ * @return int error code returned by ICU
+ * @internal ICU 2.4
+ */
+ public static native int encode(long converterHandle, char[] input, int inEnd,
+ byte[] output, int outEnd, int[] data, boolean flush);
+
+ /**
+ * Writes any remaining output to the output buffer and resets the
+ * converter to its initial state.
+ *
+ * @param converterHandle Address of converter object created by C code
+ * @param output byte array to receive flushed output.
+ * @param outEnd stop writing to output array at this offset (exclusive).
+ * @return int error code returned by ICU
+ * @param data integer array containing the following data
+ * data[0] = inputOffset
+ * data[1] = outputOffset
+ * @internal ICU 2.4
+ */
+ public static native int flushCharToByte(long converterHandle, byte[] output, int outEnd, int[] data);
+
+ /**
+ * Writes any remaining output to the output buffer and resets the
+ * converter to its initial state.
+ *
+ * @param converterHandle Address of converter object created by the native code
+ * @param output char array to receive flushed output.
+ * @param outEnd stop writing to output array at this offset (exclusive).
+ * @return int error code returned by ICU
+ * @param data integer array containing the following data
+ * data[0] = inputOffset
+ * data[1] = outputOffset
+ * @internal ICU 2.4
+ */
+ public static native int flushByteToChar(long converterHandle, char[] output, int outEnd, int[] data);
+
+ public static native long openConverter(String encoding);
+ public static native void closeConverter(long converterHandle);
+
+ public static native void resetByteToChar(long converterHandle);
+ public static native void resetCharToByte(long converterHandle);
+
+ public static native byte[] getSubstitutionBytes(long converterHandle);
+
+ public static native int getMaxBytesPerChar(long converterHandle);
+ public static native int getMinBytesPerChar(long converterHandle);
+ public static native float getAveBytesPerChar(long converterHandle);
+ public static native float getAveCharsPerByte(long converterHandle);
+
+ public static native boolean contains(String converterName1, String converterName2);
+
+ public static native boolean canEncode(long converterHandle, int codeUnit);
+
+ public static native String[] getAvailableCharsetNames();
+ public static native Charset charsetForName(String charsetName);
+
+ // Translates from Java's enum to the magic numbers #defined in "NativeConverter.cpp".
+ private static int translateCodingErrorAction(CodingErrorAction action) {
+ if (action == CodingErrorAction.REPORT) {
+ return 0;
+ } else if (action == CodingErrorAction.IGNORE) {
+ return 1;
+ } else if (action == CodingErrorAction.REPLACE) {
+ return 2;
+ } else {
+ throw new AssertionError(); // Someone changed the enum.
+ }
+ }
+
+ public static int setCallbackDecode(long converterHandle, CharsetDecoder decoder) {
+ return setCallbackDecode(converterHandle,
+ translateCodingErrorAction(decoder.malformedInputAction()),
+ translateCodingErrorAction(decoder.unmappableCharacterAction()),
+ decoder.replacement().toCharArray());
+ }
+ private static native int setCallbackDecode(long converterHandle, int onMalformedInput, int onUnmappableInput, char[] subChars);
+
+ public static int setCallbackEncode(long converterHandle, CharsetEncoder encoder) {
+ return setCallbackEncode(converterHandle,
+ translateCodingErrorAction(encoder.malformedInputAction()),
+ translateCodingErrorAction(encoder.unmappableCharacterAction()),
+ encoder.replacement());
+ }
+ private static native int setCallbackEncode(long converterHandle, int onMalformedInput, int onUnmappableInput, byte[] subBytes);
+}
diff --git a/luni/src/main/java/libcore/icu/NativeDecimalFormat.java b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
new file mode 100644
index 0000000..14f291f
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/NativeDecimalFormat.java
@@ -0,0 +1,642 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.icu;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.RoundingMode;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.text.DecimalFormatSymbols;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.NumberFormat;
+import java.text.ParsePosition;
+import java.util.Currency;
+import java.util.NoSuchElementException;
+
+public final class NativeDecimalFormat {
+ /**
+ * Constants corresponding to the native type UNumberFormatSymbol, for setSymbol.
+ */
+ private static final int UNUM_DECIMAL_SEPARATOR_SYMBOL = 0;
+ private static final int UNUM_GROUPING_SEPARATOR_SYMBOL = 1;
+ private static final int UNUM_PATTERN_SEPARATOR_SYMBOL = 2;
+ private static final int UNUM_PERCENT_SYMBOL = 3;
+ private static final int UNUM_ZERO_DIGIT_SYMBOL = 4;
+ private static final int UNUM_DIGIT_SYMBOL = 5;
+ private static final int UNUM_MINUS_SIGN_SYMBOL = 6;
+ private static final int UNUM_PLUS_SIGN_SYMBOL = 7;
+ private static final int UNUM_CURRENCY_SYMBOL = 8;
+ private static final int UNUM_INTL_CURRENCY_SYMBOL = 9;
+ private static final int UNUM_MONETARY_SEPARATOR_SYMBOL = 10;
+ private static final int UNUM_EXPONENTIAL_SYMBOL = 11;
+ private static final int UNUM_PERMILL_SYMBOL = 12;
+ private static final int UNUM_PAD_ESCAPE_SYMBOL = 13;
+ private static final int UNUM_INFINITY_SYMBOL = 14;
+ private static final int UNUM_NAN_SYMBOL = 15;
+ private static final int UNUM_SIGNIFICANT_DIGIT_SYMBOL = 16;
+ private static final int UNUM_MONETARY_GROUPING_SEPARATOR_SYMBOL = 17;
+ private static final int UNUM_FORMAT_SYMBOL_COUNT = 18;
+
+ /**
+ * Constants corresponding to the native type UNumberFormatAttribute, for
+ * getAttribute/setAttribute.
+ */
+ private static final int UNUM_PARSE_INT_ONLY = 0;
+ private static final int UNUM_GROUPING_USED = 1;
+ private static final int UNUM_DECIMAL_ALWAYS_SHOWN = 2;
+ private static final int UNUM_MAX_INTEGER_DIGITS = 3;
+ private static final int UNUM_MIN_INTEGER_DIGITS = 4;
+ private static final int UNUM_INTEGER_DIGITS = 5;
+ private static final int UNUM_MAX_FRACTION_DIGITS = 6;
+ private static final int UNUM_MIN_FRACTION_DIGITS = 7;
+ private static final int UNUM_FRACTION_DIGITS = 8;
+ private static final int UNUM_MULTIPLIER = 9;
+ private static final int UNUM_GROUPING_SIZE = 10;
+ private static final int UNUM_ROUNDING_MODE = 11;
+ private static final int UNUM_ROUNDING_INCREMENT = 12;
+ private static final int UNUM_FORMAT_WIDTH = 13;
+ private static final int UNUM_PADDING_POSITION = 14;
+ private static final int UNUM_SECONDARY_GROUPING_SIZE = 15;
+ private static final int UNUM_SIGNIFICANT_DIGITS_USED = 16;
+ private static final int UNUM_MIN_SIGNIFICANT_DIGITS = 17;
+ private static final int UNUM_MAX_SIGNIFICANT_DIGITS = 18;
+ private static final int UNUM_LENIENT_PARSE = 19;
+
+ /**
+ * Constants corresponding to the native type UNumberFormatTextAttribute, for
+ * getTextAttribute/setTextAttribute.
+ */
+ private static final int UNUM_POSITIVE_PREFIX = 0;
+ private static final int UNUM_POSITIVE_SUFFIX = 1;
+ private static final int UNUM_NEGATIVE_PREFIX = 2;
+ private static final int UNUM_NEGATIVE_SUFFIX = 3;
+ private static final int UNUM_PADDING_CHARACTER = 4;
+ private static final int UNUM_CURRENCY_CODE = 5;
+ private static final int UNUM_DEFAULT_RULESET = 6;
+ private static final int UNUM_PUBLIC_RULESETS = 7;
+
+ /**
+ * The address of the ICU DecimalFormat* on the native heap.
+ */
+ private int address;
+
+ /**
+ * The last pattern we gave to ICU, so we can make repeated applications cheap.
+ * This helps in cases like String.format("%.2f,%.2f\n", x, y) where the DecimalFormat is
+ * reused.
+ */
+ private String lastPattern;
+
+ // TODO: store all these in DecimalFormat instead!
+ private boolean negPrefNull;
+ private boolean negSuffNull;
+ private boolean posPrefNull;
+ private boolean posSuffNull;
+
+ private transient boolean parseBigDecimal;
+
+ /**
+ * Cache the BigDecimal form of the multiplier. This is null until we've
+ * formatted a BigDecimal (with a multiplier that is not 1), or the user has
+ * explicitly called {@link #setMultiplier(int)} with any multiplier.
+ */
+ private BigDecimal multiplierBigDecimal = null;
+
+ public NativeDecimalFormat(String pattern, DecimalFormatSymbols dfs) {
+ try {
+ this.address = open(pattern, dfs.getCurrencySymbol(),
+ dfs.getDecimalSeparator(), dfs.getDigit(), dfs.getExponentSeparator(),
+ dfs.getGroupingSeparator(), dfs.getInfinity(),
+ dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
+ dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
+ dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
+ this.lastPattern = pattern;
+ } catch (NullPointerException npe) {
+ throw npe;
+ } catch (RuntimeException re) {
+ throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
+ }
+ }
+
+ // Used so java.util.Formatter doesn't need to allocate DecimalFormatSymbols instances.
+ public NativeDecimalFormat(String pattern, LocaleData data) {
+ this.address = open(pattern, data.currencySymbol,
+ data.decimalSeparator, data.digit, data.exponentSeparator, data.groupingSeparator,
+ data.infinity, data.internationalCurrencySymbol, data.minusSign,
+ data.monetarySeparator, data.NaN, data.patternSeparator,
+ data.percent, data.perMill, data.zeroDigit);
+ this.lastPattern = pattern;
+ }
+
+ // Used to implement clone.
+ private NativeDecimalFormat(NativeDecimalFormat other) {
+ this.address = cloneImpl(other.address);
+ this.lastPattern = other.lastPattern;
+ this.negPrefNull = other.negPrefNull;
+ this.negSuffNull = other.negSuffNull;
+ this.posPrefNull = other.posPrefNull;
+ this.posSuffNull = other.posSuffNull;
+ }
+
+ // TODO: remove this and just have DecimalFormat.hashCode do the right thing itself.
+ @Override
+ public int hashCode() {
+ return this.getPositivePrefix().hashCode();
+ }
+
+ public synchronized void close() {
+ if (address != 0) {
+ close(address);
+ address = 0;
+ }
+ }
+
+ @Override
+ public Object clone() {
+ return new NativeDecimalFormat(this);
+ }
+
+ /**
+ * Note: this doesn't check that the underlying native DecimalFormat objects' configured
+ * native DecimalFormatSymbols objects are equal. It is assumed that the
+ * caller (DecimalFormat) will check the DecimalFormatSymbols objects
+ * instead, for performance.
+ *
+ * This is also unreasonably expensive, calling down to JNI multiple times.
+ *
+ * TODO: remove this and just have DecimalFormat.equals do the right thing itself.
+ */
+ @Override
+ public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof NativeDecimalFormat)) {
+ return false;
+ }
+ NativeDecimalFormat obj = (NativeDecimalFormat) object;
+ if (obj.address == this.address) {
+ return true;
+ }
+ return obj.toPattern().equals(this.toPattern()) &&
+ obj.isDecimalSeparatorAlwaysShown() == this.isDecimalSeparatorAlwaysShown() &&
+ obj.getGroupingSize() == this.getGroupingSize() &&
+ obj.getMultiplier() == this.getMultiplier() &&
+ obj.getNegativePrefix().equals(this.getNegativePrefix()) &&
+ obj.getNegativeSuffix().equals(this.getNegativeSuffix()) &&
+ obj.getPositivePrefix().equals(this.getPositivePrefix()) &&
+ obj.getPositiveSuffix().equals(this.getPositiveSuffix()) &&
+ obj.getMaximumIntegerDigits() == this.getMaximumIntegerDigits() &&
+ obj.getMaximumFractionDigits() == this.getMaximumFractionDigits() &&
+ obj.getMinimumIntegerDigits() == this.getMinimumIntegerDigits() &&
+ obj.getMinimumFractionDigits() == this.getMinimumFractionDigits() &&
+ obj.isGroupingUsed() == this.isGroupingUsed();
+ }
+
+ /**
+ * Copies the DecimalFormatSymbols settings into our native peer in bulk.
+ */
+ public void setDecimalFormatSymbols(final DecimalFormatSymbols dfs) {
+ setDecimalFormatSymbols(this.address, dfs.getCurrencySymbol(), dfs.getDecimalSeparator(),
+ dfs.getDigit(), dfs.getExponentSeparator(), dfs.getGroupingSeparator(),
+ dfs.getInfinity(), dfs.getInternationalCurrencySymbol(), dfs.getMinusSign(),
+ dfs.getMonetaryDecimalSeparator(), dfs.getNaN(), dfs.getPatternSeparator(),
+ dfs.getPercent(), dfs.getPerMill(), dfs.getZeroDigit());
+ }
+
+ public void setDecimalFormatSymbols(final LocaleData localeData) {
+ setDecimalFormatSymbols(this.address, localeData.currencySymbol, localeData.decimalSeparator,
+ localeData.digit, localeData.exponentSeparator, localeData.groupingSeparator,
+ localeData.infinity, localeData.internationalCurrencySymbol, localeData.minusSign,
+ localeData.monetarySeparator, localeData.NaN, localeData.patternSeparator,
+ localeData.percent, localeData.perMill, localeData.zeroDigit);
+ }
+
+ public char[] formatBigDecimal(BigDecimal value, FieldPosition field) {
+ FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
+ char[] result = formatDigitList(this.address, value.toString(), fpi);
+ if (fpi != null) {
+ FieldPositionIterator.setFieldPosition(fpi, field);
+ }
+ return result;
+ }
+
+ public char[] formatBigInteger(BigInteger value, FieldPosition field) {
+ FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
+ char[] result = formatDigitList(this.address, value.toString(10), fpi);
+ if (fpi != null) {
+ FieldPositionIterator.setFieldPosition(fpi, field);
+ }
+ return result;
+ }
+
+ public char[] formatLong(long value, FieldPosition field) {
+ FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
+ char[] result = formatLong(this.address, value, fpi);
+ if (fpi != null) {
+ FieldPositionIterator.setFieldPosition(fpi, field);
+ }
+ return result;
+ }
+
+ public char[] formatDouble(double value, FieldPosition field) {
+ FieldPositionIterator fpi = FieldPositionIterator.forFieldPosition(field);
+ char[] result = formatDouble(this.address, value, fpi);
+ if (fpi != null) {
+ FieldPositionIterator.setFieldPosition(fpi, field);
+ }
+ return result;
+ }
+
+ public void applyLocalizedPattern(String pattern) {
+ applyPattern(this.address, true, pattern);
+ lastPattern = null;
+ }
+
+ public void applyPattern(String pattern) {
+ if (lastPattern != null && pattern.equals(lastPattern)) {
+ return;
+ }
+ applyPattern(this.address, false, pattern);
+ lastPattern = pattern;
+ }
+
+ public AttributedCharacterIterator formatToCharacterIterator(Object object) {
+ if (!(object instanceof Number)) {
+ throw new IllegalArgumentException();
+ }
+ Number number = (Number) object;
+ FieldPositionIterator fpIter = new FieldPositionIterator();
+ String text;
+ if (number instanceof BigInteger || number instanceof BigDecimal) {
+ text = new String(formatDigitList(this.address, number.toString(), fpIter));
+ } else if (number instanceof Double || number instanceof Float) {
+ double dv = number.doubleValue();
+ text = new String(formatDouble(this.address, dv, fpIter));
+ } else {
+ long lv = number.longValue();
+ text = new String(formatLong(this.address, lv, fpIter));
+ }
+
+ AttributedString as = new AttributedString(text);
+
+ while (fpIter.next()) {
+ Format.Field field = fpIter.field();
+ as.addAttribute(field, field, fpIter.start(), fpIter.limit());
+ }
+
+ // return the CharacterIterator from AttributedString
+ return as.getIterator();
+ }
+
+ private int makeScalePositive(int scale, StringBuilder val) {
+ if (scale < 0) {
+ scale = -scale;
+ for (int i = scale; i > 0; i--) {
+ val.append('0');
+ }
+ scale = 0;
+ }
+ return scale;
+ }
+
+ public String toLocalizedPattern() {
+ return toPatternImpl(this.address, true);
+ }
+
+ public String toPattern() {
+ return toPatternImpl(this.address, false);
+ }
+
+ public Number parse(String string, ParsePosition position) {
+ return parse(address, string, position, parseBigDecimal);
+ }
+
+ // start getter and setter
+
+ public int getMaximumFractionDigits() {
+ return getAttribute(this.address, UNUM_MAX_FRACTION_DIGITS);
+ }
+
+ public int getMaximumIntegerDigits() {
+ return getAttribute(this.address, UNUM_MAX_INTEGER_DIGITS);
+ }
+
+ public int getMinimumFractionDigits() {
+ return getAttribute(this.address, UNUM_MIN_FRACTION_DIGITS);
+ }
+
+ public int getMinimumIntegerDigits() {
+ return getAttribute(this.address, UNUM_MIN_INTEGER_DIGITS);
+ }
+
+ public int getGroupingSize() {
+ return getAttribute(this.address, UNUM_GROUPING_SIZE);
+ }
+
+ public int getMultiplier() {
+ return getAttribute(this.address, UNUM_MULTIPLIER);
+ }
+
+ public String getNegativePrefix() {
+ if (negPrefNull) {
+ return null;
+ }
+ return getTextAttribute(this.address, UNUM_NEGATIVE_PREFIX);
+ }
+
+ public String getNegativeSuffix() {
+ if (negSuffNull) {
+ return null;
+ }
+ return getTextAttribute(this.address, UNUM_NEGATIVE_SUFFIX);
+ }
+
+ public String getPositivePrefix() {
+ if (posPrefNull) {
+ return null;
+ }
+ return getTextAttribute(this.address, UNUM_POSITIVE_PREFIX);
+ }
+
+ public String getPositiveSuffix() {
+ if (posSuffNull) {
+ return null;
+ }
+ return getTextAttribute(this.address, UNUM_POSITIVE_SUFFIX);
+ }
+
+ public boolean isDecimalSeparatorAlwaysShown() {
+ return getAttribute(this.address, UNUM_DECIMAL_ALWAYS_SHOWN) != 0;
+ }
+
+ public boolean isParseBigDecimal() {
+ return parseBigDecimal;
+ }
+
+ public boolean isParseIntegerOnly() {
+ return getAttribute(this.address, UNUM_PARSE_INT_ONLY) != 0;
+ }
+
+ public boolean isGroupingUsed() {
+ return getAttribute(this.address, UNUM_GROUPING_USED) != 0;
+ }
+
+ public void setDecimalSeparatorAlwaysShown(boolean value) {
+ int i = value ? -1 : 0;
+ setAttribute(this.address, UNUM_DECIMAL_ALWAYS_SHOWN, i);
+ }
+
+ public void setCurrency(Currency currency) {
+ setSymbol(this.address, UNUM_CURRENCY_SYMBOL, currency.getSymbol());
+ setSymbol(this.address, UNUM_INTL_CURRENCY_SYMBOL, currency.getCurrencyCode());
+ }
+
+ public void setGroupingSize(int value) {
+ setAttribute(this.address, UNUM_GROUPING_SIZE, value);
+ }
+
+ public void setGroupingUsed(boolean value) {
+ int i = value ? -1 : 0;
+ setAttribute(this.address, UNUM_GROUPING_USED, i);
+ }
+
+ public void setMaximumFractionDigits(int value) {
+ setAttribute(this.address, UNUM_MAX_FRACTION_DIGITS, value);
+ }
+
+ public void setMaximumIntegerDigits(int value) {
+ setAttribute(this.address, UNUM_MAX_INTEGER_DIGITS, value);
+ }
+
+ public void setMinimumFractionDigits(int value) {
+ setAttribute(this.address, UNUM_MIN_FRACTION_DIGITS, value);
+ }
+
+ public void setMinimumIntegerDigits(int value) {
+ setAttribute(this.address, UNUM_MIN_INTEGER_DIGITS, value);
+ }
+
+ public void setMultiplier(int value) {
+ setAttribute(this.address, UNUM_MULTIPLIER, value);
+ // Update the cached BigDecimal for multiplier.
+ multiplierBigDecimal = BigDecimal.valueOf(value);
+ }
+
+ public void setNegativePrefix(String value) {
+ negPrefNull = value == null;
+ if (!negPrefNull) {
+ setTextAttribute(this.address, UNUM_NEGATIVE_PREFIX, value);
+ }
+ }
+
+ public void setNegativeSuffix(String value) {
+ negSuffNull = value == null;
+ if (!negSuffNull) {
+ setTextAttribute(this.address, UNUM_NEGATIVE_SUFFIX, value);
+ }
+ }
+
+ public void setPositivePrefix(String value) {
+ posPrefNull = value == null;
+ if (!posPrefNull) {
+ setTextAttribute(this.address, UNUM_POSITIVE_PREFIX, value);
+ }
+ }
+
+ public void setPositiveSuffix(String value) {
+ posSuffNull = value == null;
+ if (!posSuffNull) {
+ setTextAttribute(this.address, UNUM_POSITIVE_SUFFIX, value);
+ }
+ }
+
+ public void setParseBigDecimal(boolean value) {
+ parseBigDecimal = value;
+ }
+
+ public void setParseIntegerOnly(boolean value) {
+ int i = value ? -1 : 0;
+ setAttribute(this.address, UNUM_PARSE_INT_ONLY, i);
+ }
+
+ private static void applyPattern(int addr, boolean localized, String pattern) {
+ try {
+ applyPatternImpl(addr, localized, pattern);
+ } catch (NullPointerException npe) {
+ throw npe;
+ } catch (RuntimeException re) {
+ throw new IllegalArgumentException("syntax error: " + re.getMessage() + ": " + pattern);
+ }
+ }
+
+ public void setRoundingMode(RoundingMode roundingMode, double roundingIncrement) {
+ final int nativeRoundingMode;
+ switch (roundingMode) {
+ case CEILING: nativeRoundingMode = 0; break;
+ case FLOOR: nativeRoundingMode = 1; break;
+ case DOWN: nativeRoundingMode = 2; break;
+ case UP: nativeRoundingMode = 3; break;
+ case HALF_EVEN: nativeRoundingMode = 4; break;
+ case HALF_DOWN: nativeRoundingMode = 5; break;
+ case HALF_UP: nativeRoundingMode = 6; break;
+ default: throw new AssertionError();
+ }
+ setRoundingMode(address, nativeRoundingMode, roundingIncrement);
+ }
+
+ // Utility to get information about field positions from native (ICU) code.
+ private static class FieldPositionIterator {
+ private int[] data;
+ private int pos = -3; // so first call to next() leaves pos at 0
+
+ private FieldPositionIterator() {
+ }
+
+ public static FieldPositionIterator forFieldPosition(FieldPosition fp) {
+ if (fp != null && fp.getField() != -1) {
+ return new FieldPositionIterator();
+ }
+ return null;
+ }
+
+ private static int getNativeFieldPositionId(FieldPosition fp) {
+ // NOTE: -1, 0, and 1 were the only valid original java field values
+ // for NumberFormat. They take precedence. This assumes any other
+ // value is a mistake and the actual value is in the attribute.
+ // Clients can construct FieldPosition combining any attribute with any field
+ // value, which is just wrong, but there you go.
+
+ int id = fp.getField();
+ if (id < -1 || id > 1) {
+ id = -1;
+ }
+ if (id == -1) {
+ Format.Field attr = fp.getFieldAttribute();
+ if (attr != null) {
+ for (int i = 0; i < fields.length; ++i) {
+ if (fields[i].equals(attr)) {
+ id = i;
+ break;
+ }
+ }
+ }
+ }
+ return id;
+ }
+
+ private static void setFieldPosition(FieldPositionIterator fpi, FieldPosition fp) {
+ if (fpi != null && fp != null) {
+ int field = getNativeFieldPositionId(fp);
+ if (field != -1) {
+ while (fpi.next()) {
+ if (fpi.fieldId() == field) {
+ fp.setBeginIndex(fpi.start());
+ fp.setEndIndex(fpi.limit());
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ public boolean next() {
+ // if pos == data.length, we've already returned false once
+ if (data == null || pos == data.length) {
+ throw new NoSuchElementException();
+ }
+ pos += 3;
+ return pos < data.length;
+ }
+
+ private void checkValid() {
+ if (data == null || pos < 0 || pos == data.length) {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public int fieldId() {
+ return data[pos];
+ }
+
+ public Format.Field field() {
+ checkValid();
+ return fields[data[pos]];
+ }
+
+ public int start() {
+ checkValid();
+ return data[pos + 1];
+ }
+
+ public int limit() {
+ checkValid();
+ return data[pos + 2];
+ }
+
+ private static Format.Field fields[] = {
+ // The old java field values were 0 for integer and 1 for fraction.
+ // The new java field attributes are all objects. ICU assigns the values
+ // starting from 0 in the following order; note that integer and
+ // fraction positions match the old field values.
+ NumberFormat.Field.INTEGER,
+ NumberFormat.Field.FRACTION,
+ NumberFormat.Field.DECIMAL_SEPARATOR,
+ NumberFormat.Field.EXPONENT_SYMBOL,
+ NumberFormat.Field.EXPONENT_SIGN,
+ NumberFormat.Field.EXPONENT,
+ NumberFormat.Field.GROUPING_SEPARATOR,
+ NumberFormat.Field.CURRENCY,
+ NumberFormat.Field.PERCENT,
+ NumberFormat.Field.PERMILLE,
+ NumberFormat.Field.SIGN,
+ };
+
+ // called by native
+ private void setData(int[] data) {
+ this.data = data;
+ this.pos = -3;
+ }
+ }
+
+ private static native void applyPatternImpl(int addr, boolean localized, String pattern);
+ private static native int cloneImpl(int addr);
+ private static native void close(int addr);
+ private static native char[] formatLong(int addr, long value, FieldPositionIterator iter);
+ private static native char[] formatDouble(int addr, double value, FieldPositionIterator iter);
+ private static native char[] formatDigitList(int addr, String value, FieldPositionIterator iter);
+ private static native int getAttribute(int addr, int symbol);
+ private static native String getTextAttribute(int addr, int symbol);
+ private static native int open(String pattern, String currencySymbol,
+ char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
+ String infinity, String internationalCurrencySymbol, char minusSign,
+ char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
+ char perMill, char zeroDigit);
+ private static native Number parse(int addr, String string, ParsePosition position, boolean parseBigDecimal);
+ private static native void setDecimalFormatSymbols(int addr, String currencySymbol,
+ char decimalSeparator, char digit, String exponentSeparator, char groupingSeparator,
+ String infinity, String internationalCurrencySymbol, char minusSign,
+ char monetaryDecimalSeparator, String nan, char patternSeparator, char percent,
+ char perMill, char zeroDigit);
+ private static native void setSymbol(int addr, int symbol, String str);
+ private static native void setAttribute(int addr, int symbol, int i);
+ private static native void setRoundingMode(int addr, int roundingMode, double roundingIncrement);
+ private static native void setTextAttribute(int addr, int symbol, String str);
+ private static native String toPatternImpl(int addr, boolean localized);
+}
diff --git a/luni/src/main/java/libcore/icu/RuleBasedCollatorICU.java b/luni/src/main/java/libcore/icu/RuleBasedCollatorICU.java
new file mode 100644
index 0000000..d036c98
--- /dev/null
+++ b/luni/src/main/java/libcore/icu/RuleBasedCollatorICU.java
@@ -0,0 +1,154 @@
+/**
+*******************************************************************************
+* Copyright (C) 1996-2005, International Business Machines Corporation and *
+* others. All Rights Reserved. *
+*******************************************************************************
+*
+*
+*******************************************************************************
+*/
+
+package libcore.icu;
+
+import java.text.CharacterIterator;
+import java.text.CollationKey;
+import java.text.ParseException;
+import java.util.Locale;
+
+public final class RuleBasedCollatorICU implements Cloneable {
+ // Values from the native UColAttributeValue enum.
+ public static final int VALUE_DEFAULT = -1;
+ public static final int VALUE_PRIMARY = 0;
+ public static final int VALUE_SECONDARY = 1;
+ public static final int VALUE_TERTIARY = 2;
+ public static final int VALUE_DEFAULT_STRENGTH = VALUE_TERTIARY;
+ public static final int VALUE_QUATERNARY = 3;
+ public static final int VALUE_IDENTICAL = 15;
+ public static final int VALUE_OFF = 16;
+ public static final int VALUE_ON = 17;
+ public static final int VALUE_SHIFTED = 20;
+ public static final int VALUE_NON_IGNORABLE = 21;
+ public static final int VALUE_LOWER_FIRST = 24;
+ public static final int VALUE_UPPER_FIRST = 25;
+ public static final int VALUE_ON_WITHOUT_HANGUL = 28;
+ public static final int VALUE_ATTRIBUTE_VALUE_COUNT = 29;
+
+ // Values from the UColAttribute enum.
+ public static final int FRENCH_COLLATION = 0;
+ public static final int ALTERNATE_HANDLING = 1;
+ public static final int CASE_FIRST = 2;
+ public static final int CASE_LEVEL = 3;
+ public static final int DECOMPOSITION_MODE = 4;
+ public static final int STRENGTH = 5;
+
+ // The address of the ICU4C native peer.
+ private int address;
+
+ public RuleBasedCollatorICU(String rules) throws ParseException {
+ if (rules == null) {
+ throw new NullPointerException();
+ }
+ address = NativeCollation.openCollatorFromRules(rules, VALUE_OFF, VALUE_DEFAULT_STRENGTH);
+ }
+
+ public RuleBasedCollatorICU(Locale locale) {
+ address = NativeCollation.openCollator(locale.toString());
+ }
+
+ private RuleBasedCollatorICU(int address) {
+ this.address = address;
+ }
+
+ public Object clone() {
+ return new RuleBasedCollatorICU(NativeCollation.safeClone(address));
+ }
+
+ public int compare(String source, String target) {
+ return NativeCollation.compare(address, source, target);
+ }
+
+ public int getDecomposition() {
+ return NativeCollation.getAttribute(address, DECOMPOSITION_MODE);
+ }
+
+ public void setDecomposition(int mode) {
+ NativeCollation.setAttribute(address, DECOMPOSITION_MODE, mode);
+ }
+
+ public int getStrength() {
+ return NativeCollation.getAttribute(address, STRENGTH);
+ }
+
+ public void setStrength(int strength) {
+ NativeCollation.setAttribute(address, STRENGTH, strength);
+ }
+
+ public void setAttribute(int type, int value) {
+ NativeCollation.setAttribute(address, type, value);
+ }
+
+ public int getAttribute(int type) {
+ return NativeCollation.getAttribute(address, type);
+ }
+
+ public CollationKey getCollationKey(String source) {
+ if (source == null) {
+ return null;
+ }
+ byte[] key = NativeCollation.getSortKey(address, source);
+ if (key == null) {
+ return null;
+ }
+ return new CollationKeyICU(source, key);
+ }
+
+ public String getRules() {
+ return NativeCollation.getRules(address);
+ }
+
+ public CollationElementIteratorICU getCollationElementIterator(String source) {
+ return CollationElementIteratorICU.getInstance(address, source);
+ }
+
+ public CollationElementIteratorICU getCollationElementIterator(CharacterIterator it) {
+ // We only implement the String-based API, so build a string from the iterator.
+ return getCollationElementIterator(characterIteratorToString(it));
+ }
+
+ private String characterIteratorToString(CharacterIterator it) {
+ StringBuilder result = new StringBuilder();
+ for (char ch = it.current(); ch != CharacterIterator.DONE; ch = it.next()) {
+ result.append(ch);
+ }
+ return result.toString();
+ }
+
+ @Override public int hashCode() {
+ return 42; // No-one uses RuleBasedCollatorICU as a hash key.
+ }
+
+ public boolean equals(String source, String target) {
+ return (compare(source, target) == 0);
+ }
+
+ @Override public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof RuleBasedCollatorICU)) {
+ return false;
+ }
+ RuleBasedCollatorICU rhs = (RuleBasedCollatorICU) object;
+ return getRules().equals(rhs.getRules()) &&
+ getStrength() == rhs.getStrength() &&
+ getDecomposition() == rhs.getDecomposition();
+ }
+
+ @Override protected void finalize() throws Throwable {
+ try {
+ NativeCollation.closeCollator(address);
+ } finally {
+ super.finalize();
+ }
+ }
+}
diff --git a/luni/src/main/java/libcore/internal/StringPool.java b/luni/src/main/java/libcore/internal/StringPool.java
new file mode 100644
index 0000000..779a59a
--- /dev/null
+++ b/luni/src/main/java/libcore/internal/StringPool.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.internal;
+
+/**
+ * A pool of string instances. Unlike the {@link String#intern() VM's
+ * interned strings}, this pool provides no guarantee of reference equality.
+ * It is intended only to save allocations. This class is not thread safe.
+ */
+public final class StringPool {
+
+ private final String[] pool = new String[512];
+
+ /**
+ * Returns a string equal to {@code new String(array, start, length)}.
+ */
+ public String get(char[] array, int start, int length) {
+ // Compute an arbitrary hash of the content
+ int hashCode = 0;
+ for (int i = start; i < start + length; i++) {
+ hashCode = (hashCode * 31) + array[i];
+ }
+
+ // Pick a bucket using Doug Lea's supplemental secondaryHash function (from HashMap)
+ hashCode ^= (hashCode >>> 20) ^ (hashCode >>> 12);
+ hashCode ^= (hashCode >>> 7) ^ (hashCode >>> 4);
+ int index = hashCode & (pool.length - 1);
+
+ String pooled = pool[index];
+ if (pooled != null && pooled.contentEquals(array, start, length)) {
+ return pooled;
+ }
+
+ String result = new String(array, start, length);
+ pool[index] = result;
+ return result;
+ }
+}
diff --git a/luni/src/main/java/libcore/io/BufferIterator.java b/luni/src/main/java/libcore/io/BufferIterator.java
new file mode 100644
index 0000000..7f3ad47
--- /dev/null
+++ b/luni/src/main/java/libcore/io/BufferIterator.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.io;
+
+/**
+ * Iterates over big- or little-endian bytes. See {@link MemoryMappedFile#bigEndianIterator} and
+ * {@link MemoryMappedFile#littleEndianIterator}.
+ *
+ * @hide don't make this public without adding bounds checking.
+ */
+public abstract class BufferIterator {
+ /**
+ * Seeks to the absolute position {@code offset}, measured in bytes from the start.
+ */
+ public abstract void seek(int offset);
+
+ /**
+ * Skips forwards or backwards {@code byteCount} bytes from the current position.
+ */
+ public abstract void skip(int byteCount);
+
+ /**
+ * Copies {@code byteCount} bytes from the current position into {@code dst}, starting at
+ * {@code dstOffset}, and advances the current position {@code byteCount} bytes.
+ */
+ public abstract void readByteArray(byte[] dst, int dstOffset, int byteCount);
+
+ /**
+ * Returns the byte at the current position, and advances the current position one byte.
+ */
+ public abstract byte readByte();
+
+ /**
+ * Returns the 32-bit int at the current position, and advances the current position four bytes.
+ */
+ public abstract int readInt();
+
+ /**
+ * Copies {@code intCount} 32-bit ints from the current position into {@code dst}, starting at
+ * {@code dstOffset}, and advances the current position {@code 4 * intCount} bytes.
+ */
+ public abstract void readIntArray(int[] dst, int dstOffset, int intCount);
+
+ /**
+ * Returns the 16-bit short at the current position, and advances the current position two bytes.
+ */
+ public abstract short readShort();
+}
diff --git a/luni/src/main/java/libcore/io/HeapBufferIterator.java b/luni/src/main/java/libcore/io/HeapBufferIterator.java
new file mode 100644
index 0000000..ab44b99
--- /dev/null
+++ b/luni/src/main/java/libcore/io/HeapBufferIterator.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.io;
+
+import java.nio.ByteOrder;
+import org.apache.harmony.luni.platform.OSMemory;
+
+/**
+ * Iterates over big- or little-endian bytes in a Java byte[].
+ *
+ * @hide don't make this public without adding bounds checking.
+ */
+public final class HeapBufferIterator extends BufferIterator {
+ private final byte[] buffer;
+ private final int offset;
+ private final int byteCount;
+ private final ByteOrder order;
+
+ private int position;
+
+ HeapBufferIterator(byte[] buffer, int offset, int byteCount, ByteOrder order) {
+ this.buffer = buffer;
+ this.offset = offset;
+ this.byteCount = byteCount;
+ this.order = order;
+ }
+
+ public void seek(int offset) {
+ position = offset;
+ }
+
+ public void skip(int byteCount) {
+ position += byteCount;
+ }
+
+ public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
+ System.arraycopy(buffer, offset + position, dst, dstOffset, byteCount);
+ position += byteCount;
+ }
+
+ public byte readByte() {
+ byte result = buffer[offset + position];
+ ++position;
+ return result;
+ }
+
+ public int readInt() {
+ int result = OSMemory.peekInt(buffer, offset + position, order);
+ position += SizeOf.INT;
+ return result;
+ }
+
+ public void readIntArray(int[] dst, int dstOffset, int intCount) {
+ final int byteCount = intCount * SizeOf.INT;
+ OSMemory.unsafeBulkGet(dst, dstOffset, byteCount, buffer, offset + position, SizeOf.INT, order.needsSwap);
+ position += byteCount;
+ }
+
+ public short readShort() {
+ short result = OSMemory.peekShort(buffer, offset + position, order);
+ position += SizeOf.SHORT;
+ return result;
+ }
+
+ /**
+ * Returns a new iterator over {@code buffer}, starting at {@code offset} and continuing for
+ * {@code byteCount} bytes. Items larger than a byte are interpreted using the given byte order.
+ */
+ public static BufferIterator iterator(byte[] buffer, int offset, int byteCount, ByteOrder order) {
+ return new HeapBufferIterator(buffer, offset, byteCount, order);
+ }
+}
diff --git a/luni/src/main/java/libcore/io/IoUtils.java b/luni/src/main/java/libcore/io/IoUtils.java
index 30c48c9..29a64ba 100644
--- a/luni/src/main/java/libcore/io/IoUtils.java
+++ b/luni/src/main/java/libcore/io/IoUtils.java
@@ -19,6 +19,8 @@ package libcore.io;
import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.net.Socket;
public final class IoUtils {
private IoUtils() {
@@ -42,6 +44,18 @@ public final class IoUtils {
}
/**
+ * Closes 'socket', ignoring any exceptions. Does nothing if 'socket' is null.
+ */
+ public static void closeQuietly(Socket socket) {
+ if (socket != null) {
+ try {
+ socket.close();
+ } catch (Exception ignored) {
+ }
+ }
+ }
+
+ /**
* Returns the int file descriptor from within the given FileDescriptor 'fd'.
*/
public static native int getFd(FileDescriptor fd);
@@ -71,4 +85,19 @@ public final class IoUtils {
* Sets 'fd' to be blocking or non-blocking, according to the state of 'blocking'.
*/
public static native void setBlocking(FileDescriptor fd, boolean blocking) throws IOException;
+
+ /**
+ * Returns the contents of 'path' as a byte array.
+ */
+ public static byte[] readFileAsByteArray(String path) throws IOException {
+ RandomAccessFile f = null;
+ try {
+ f = new RandomAccessFile(path, "r");
+ byte[] buf = new byte[(int) f.length()];
+ f.readFully(buf);
+ return buf;
+ } finally {
+ IoUtils.closeQuietly(f);
+ }
+ }
}
diff --git a/luni/src/main/java/libcore/io/MemoryMappedFile.java b/luni/src/main/java/libcore/io/MemoryMappedFile.java
new file mode 100644
index 0000000..10ef8f0
--- /dev/null
+++ b/luni/src/main/java/libcore/io/MemoryMappedFile.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.io;
+
+import java.io.Closeable;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.nio.ByteOrder;
+import java.nio.NioUtils;
+import java.nio.channels.FileChannel;
+import org.apache.harmony.luni.platform.OSMemory;
+
+/**
+ * A memory-mapped file. Use {@link #mmap} to map a file, {@link #close} to unmap a file,
+ * and either {@link #bigEndianIterator} or {@link #littleEndianIterator} to get a seekable
+ * {@link BufferIterator} over the mapped data.
+ */
+public final class MemoryMappedFile implements Closeable {
+ private int address;
+
+ // Until we have 64-bit address spaces, we only need an int for 'size'.
+ private final int size;
+
+ private MemoryMappedFile(int address, int size) {
+ this.address = address;
+ this.size = size;
+ }
+
+ public static MemoryMappedFile mmap(FileChannel fc, FileChannel.MapMode mapMode, long start, long size) throws IOException {
+ return mmap(NioUtils.getFd(fc), mapMode, start, size);
+ }
+
+ public static MemoryMappedFile mmap(FileDescriptor fd, FileChannel.MapMode mapMode, long start, long size) throws IOException {
+ return mmap(IoUtils.getFd(fd), mapMode, start, size);
+ }
+
+ private static MemoryMappedFile mmap(int fd, FileChannel.MapMode mapMode, long start, long size) throws IOException {
+ if (start < 0) {
+ throw new IllegalArgumentException("start < 0: " + start);
+ }
+ if (size <= 0) {
+ throw new IllegalArgumentException("size <= 0: " + size);
+ }
+ if ((start + size) > Integer.MAX_VALUE) {
+ throw new IllegalArgumentException("(start + size) > Integer.MAX_VALUE");
+ }
+ int address = OSMemory.mmap(fd, start, size, mapMode);
+ return new MemoryMappedFile(address, (int) size);
+ }
+
+ /**
+ * Unmaps this memory-mapped file using munmap(2). This is a no-op if close has already been
+ * called. Note that this class does <i>not</i> use finalization; you must call {@code close}
+ * yourself.
+ *
+ * Calling this method invalidates any iterators over this {@code MemoryMappedFile}. It is an
+ * error to use such an iterator after calling {@code close}.
+ */
+ public synchronized void close() throws IOException {
+ if (address != 0) {
+ OSMemory.munmap(address, size);
+ address = 0;
+ }
+ }
+
+ /**
+ * Returns a new iterator that treats the mapped data as big-endian.
+ */
+ public BufferIterator bigEndianIterator() {
+ return new NioBufferIterator(address, size, ByteOrder.nativeOrder() != ByteOrder.BIG_ENDIAN);
+ }
+
+ /**
+ * Returns a new iterator that treats the mapped data as little-endian.
+ */
+ public BufferIterator littleEndianIterator() {
+ return new NioBufferIterator(address, size, ByteOrder.nativeOrder() != ByteOrder.LITTLE_ENDIAN);
+ }
+
+ /**
+ * Returns the size in bytes of the memory-mapped region.
+ */
+ public int size() {
+ return size;
+ }
+}
diff --git a/luni/src/main/java/libcore/io/NioBufferIterator.java b/luni/src/main/java/libcore/io/NioBufferIterator.java
new file mode 100644
index 0000000..4a44c97
--- /dev/null
+++ b/luni/src/main/java/libcore/io/NioBufferIterator.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.io;
+
+import org.apache.harmony.luni.platform.OSMemory;
+
+/**
+ * Iterates over big- or little-endian bytes on the native heap.
+ * See {@link MemoryMappedFile#bigEndianIterator} and {@link MemoryMappedFile#littleEndianIterator}.
+ *
+ * @hide don't make this public without adding bounds checking.
+ */
+public final class NioBufferIterator extends BufferIterator {
+ private final int address;
+ private final int size;
+ private final boolean swap;
+
+ private int position;
+
+ NioBufferIterator(int address, int size, boolean swap) {
+ this.address = address;
+ this.size = size;
+ this.swap = swap;
+ }
+
+ public void seek(int offset) {
+ position = offset;
+ }
+
+ public void skip(int byteCount) {
+ position += byteCount;
+ }
+
+ public void readByteArray(byte[] dst, int dstOffset, int byteCount) {
+ OSMemory.peekByteArray(address + position, dst, dstOffset, byteCount);
+ position += byteCount;
+ }
+
+ public byte readByte() {
+ byte result = OSMemory.peekByte(address + position);
+ ++position;
+ return result;
+ }
+
+ public int readInt() {
+ int result = OSMemory.peekInt(address + position, swap);
+ position += SizeOf.INT;
+ return result;
+ }
+
+ public void readIntArray(int[] dst, int dstOffset, int intCount) {
+ OSMemory.peekIntArray(address + position, dst, dstOffset, intCount, swap);
+ position += SizeOf.INT * intCount;
+ }
+
+ public short readShort() {
+ short result = OSMemory.peekShort(address + position, swap);
+ position += SizeOf.SHORT;
+ return result;
+ }
+}
diff --git a/luni/src/main/java/libcore/io/SizeOf.java b/luni/src/main/java/libcore/io/SizeOf.java
new file mode 100644
index 0000000..728fbfc
--- /dev/null
+++ b/luni/src/main/java/libcore/io/SizeOf.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.io;
+
+public final class SizeOf {
+ public static final int CHAR = 2;
+ public static final int DOUBLE = 8;
+ public static final int FLOAT = 4;
+ public static final int INT = 4;
+ public static final int LONG = 8;
+ public static final int SHORT = 2;
+
+ private SizeOf() {
+ }
+}
diff --git a/luni/src/main/java/libcore/net/RawSocket.java b/luni/src/main/java/libcore/net/RawSocket.java
new file mode 100644
index 0000000..255b0b9
--- /dev/null
+++ b/luni/src/main/java/libcore/net/RawSocket.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.net;
+
+import dalvik.system.CloseGuard;
+import java.io.Closeable;
+import java.io.FileDescriptor;
+import java.io.IOException;
+import java.net.SocketException;
+import java.util.Arrays;
+import org.apache.harmony.luni.platform.Platform;
+
+/**
+ * This class allows raw L2 packets to be sent and received via the
+ * specified network interface. The receive-side implementation is
+ * restricted to UDP packets for efficiency.
+ *
+ * @hide
+ */
+public class RawSocket implements Closeable {
+ private static native void create(FileDescriptor fd, String interfaceName)
+ throws SocketException;
+ private static native int sendPacket(FileDescriptor fd,
+ String interfaceName, byte[] destMac, byte[] packet, int offset,
+ int byteCount);
+ private static native int recvPacket(FileDescriptor fd, byte[] packet,
+ int offset, int byteCount, int destPort, int timeoutMillis);
+
+ private final FileDescriptor fd;
+ private final String mInterfaceName;
+ private final CloseGuard guard = CloseGuard.get();
+
+ /**
+ * Creates a socket on the specified interface.
+ */
+ public RawSocket(String interfaceName) throws SocketException {
+ mInterfaceName = interfaceName;
+ fd = new FileDescriptor();
+ create(fd, mInterfaceName);
+ guard.open("close");
+ }
+
+ /**
+ * Reads a raw packet into the specified buffer, with the
+ * specified timeout. Packets not destined for the desired UDP
+ * port are discarded. Returns the length actually read. No
+ * indication of overflow is signaled. The packet data will start
+ * at the IP header (EthernetII dest/source/type headers are
+ * removed).
+ */
+ public int read(byte[] packet, int offset, int byteCount, int destPort,
+ int timeoutMillis) {
+ if (packet == null) {
+ throw new NullPointerException("packet == null");
+ }
+
+ Arrays.checkOffsetAndCount(packet.length, offset, byteCount);
+
+ if (destPort < 0 || destPort > 65535) {
+ throw new IllegalArgumentException("Port out of range: "
+ + destPort);
+ }
+
+ return recvPacket(fd, packet, offset, byteCount, destPort,
+ timeoutMillis);
+ }
+
+ /**
+ * Writes a raw packet to the desired interface. A L2 header will
+ * be added which includes the specified destination address, our
+ * source MAC, and the IP type. The caller is responsible for
+ * computing correct IP-header and payload checksums.
+ */
+ public int write(byte[] destMac, byte[] packet, int offset, int byteCount) {
+ if (destMac == null) {
+ throw new NullPointerException("destMac == null");
+ }
+
+ if (packet == null) {
+ throw new NullPointerException("packet == null");
+ }
+
+ Arrays.checkOffsetAndCount(packet.length, offset, byteCount);
+
+ if (destMac.length != 6) {
+ throw new IllegalArgumentException("MAC length must be 6: "
+ + destMac.length);
+ }
+
+ return sendPacket(fd, mInterfaceName, destMac, packet, offset,
+ byteCount);
+ }
+
+ /**
+ * Closes the socket. After this method is invoked, subsequent
+ * read/write operations will fail.
+ */
+ public void close() throws IOException {
+ guard.close();
+ Platform.NETWORK.close(fd);
+ }
+
+ @Override protected void finalize() throws Throwable {
+ try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
+ close();
+ } finally {
+ super.finalize();
+ }
+ }
+}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
index 10386d2..3fb49fd 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/FileURLConnection.java
@@ -80,7 +80,8 @@ public class FileURLConnection extends URLConnection {
// use -1 for the contentLength
} else {
is = new BufferedInputStream(new FileInputStream(f));
- length = is.available();
+ long lengthAsLong = f.length();
+ length = lengthAsLong <= Integer.MAX_VALUE ? (int) lengthAsLong : Integer.MAX_VALUE;
}
connected = true;
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
index a983155..8b15ec8 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/file/Handler.java
@@ -44,7 +44,7 @@ public class Handler extends URLStreamHandler {
}
/**
- * The behaviour of this method is the same as openConnection(URL).
+ * The behavior of this method is the same as openConnection(URL).
* <code>proxy</code> is not used in FileURLConnection.
*
* @param url
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
index bdd06db..2414154 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLConnection.java
@@ -168,7 +168,7 @@ public class FtpURLConnection extends URLConnection {
// Use system-wide ProxySelect to select proxy list,
// then try to connect via elements in the proxy list.
List<Proxy> proxyList = null;
- if (null != proxy) {
+ if (proxy != null) {
proxyList = new ArrayList<Proxy>(1);
proxyList.add(proxy);
} else {
@@ -177,7 +177,7 @@ public class FtpURLConnection extends URLConnection {
proxyList = selector.select(uri);
}
}
- if (null == proxyList) {
+ if (proxyList == null) {
currentProxy = null;
connectInternal();
} else {
@@ -194,7 +194,7 @@ public class FtpURLConnection extends URLConnection {
failureReason = ioe.getLocalizedMessage();
// If connect failed, callback "connectFailed"
// should be invoked.
- if (null != selector && Proxy.NO_PROXY != currentProxy) {
+ if (selector != null && Proxy.NO_PROXY != currentProxy) {
selector.connectFailed(uri, currentProxy.address(), ioe);
}
}
@@ -211,7 +211,7 @@ public class FtpURLConnection extends URLConnection {
if (port <= 0) {
port = FTP_PORT;
}
- if (null == currentProxy || Proxy.Type.HTTP == currentProxy.type()) {
+ if (currentProxy == null || Proxy.Type.HTTP == currentProxy.type()) {
controlSocket = new Socket();
} else {
controlSocket = new Socket(currentProxy);
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLInputStream.java
index 65fb258..9392081 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/ftp/FtpURLInputStream.java
@@ -20,6 +20,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.ftp;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
+import libcore.io.IoUtils;
/**
* This class associates a given inputStream with a control socket. This ensures
@@ -63,16 +64,8 @@ class FtpURLInputStream extends InputStream {
@Override
public void close() {
- try {
- is.close();
- } catch (Exception e) {
- // ignored
- }
- try {
- controlSocket.close();
- } catch (Exception e) {
- // ignored
- }
+ IoUtils.closeQuietly(is);
+ IoUtils.closeQuietly(controlSocket);
}
@Override
@@ -81,8 +74,8 @@ class FtpURLInputStream extends InputStream {
}
@Override
- public long skip(long sbytes) throws IOException {
- return is.skip(sbytes);
+ public long skip(long byteCount) throws IOException {
+ return is.skip(byteCount);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpInputStream.java
index 7219bbe..4c9505c 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpInputStream.java
@@ -34,17 +34,24 @@ import java.net.CacheRequest;
abstract class AbstractHttpInputStream extends InputStream {
protected final InputStream in;
protected final HttpURLConnectionImpl httpURLConnection;
- protected final CacheRequest cacheRequest;
- protected final OutputStream cacheOut;
+ private final CacheRequest cacheRequest;
+ private final OutputStream cacheBody;
protected boolean closed;
- private byte[] skipBuffer;
AbstractHttpInputStream(InputStream in, HttpURLConnectionImpl httpURLConnection,
CacheRequest cacheRequest) throws IOException {
this.in = in;
this.httpURLConnection = httpURLConnection;
+
+ OutputStream cacheBody = cacheRequest != null ? cacheRequest.getBody() : null;
+
+ // some apps return a null body; for compatibility we treat that like a null cache request
+ if (cacheBody == null) {
+ cacheRequest = null;
+ }
+
+ this.cacheBody = cacheBody;
this.cacheRequest = cacheRequest;
- this.cacheOut = cacheRequest != null ? cacheRequest.getBody() : null;
}
/**
@@ -57,33 +64,6 @@ abstract class AbstractHttpInputStream extends InputStream {
return count == -1 ? -1 : buffer[0] & 0xff;
}
- /**
- * skip(long) is implemented using read(byte[], int, int) so subclasses
- * only need to override the latter.
- */
- @Override public final long skip(long n) throws IOException {
- if (skipBuffer == null) {
- skipBuffer = new byte[4096];
- }
- long total = 0;
- while (total < n) {
- // Calling read() ensures the skipped bytes make it into the response cache.
- int count = read(skipBuffer, 0, (int) Math.min(n - total, skipBuffer.length));
- if (count == -1) {
- break;
- }
- total += count;
- }
- return total;
- }
-
- protected final void checkBounds(byte[] buffer, int offset, int count) {
- if (offset < 0 || offset > buffer.length || count < 0 || buffer.length - offset < count) {
- throw new ArrayIndexOutOfBoundsException(
- "offset=" + offset + ", buffer.length=" + buffer.length + ", count=" + count);
- }
- }
-
protected final void checkNotClosed() throws IOException {
if (closed) {
throw new IOException("stream closed");
@@ -91,8 +71,8 @@ abstract class AbstractHttpInputStream extends InputStream {
}
protected final void cacheWrite(byte[] buffer, int offset, int count) throws IOException {
- if (cacheOut != null) {
- cacheOut.write(buffer, offset, count);
+ if (cacheBody != null) {
+ cacheBody.write(buffer, offset, count);
}
}
@@ -102,7 +82,7 @@ abstract class AbstractHttpInputStream extends InputStream {
*/
protected final void endOfInput(boolean reuseSocket) throws IOException {
if (cacheRequest != null) {
- cacheOut.close();
+ cacheBody.close();
}
httpURLConnection.releaseSocket(reuseSocket);
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpOutputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpOutputStream.java
index 4d2eacc..7cbb81e 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpOutputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/AbstractHttpOutputStream.java
@@ -32,13 +32,6 @@ abstract class AbstractHttpOutputStream extends OutputStream {
write(new byte[] { (byte) data });
}
- protected final void checkBounds(byte[] buffer, int offset, int count) {
- if (offset < 0|| offset > buffer.length || count < 0 || buffer.length - offset < count) {
- throw new ArrayIndexOutOfBoundsException(
- "offset=" + offset + ", buffer.length=" + buffer.length + ", count=" + count);
- }
- }
-
protected final void checkNotClosed() throws IOException {
if (closed) {
throw new IOException("stream closed");
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java
index 678e792..73fd388 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedInputStream.java
@@ -19,6 +19,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.IOException;
import java.io.InputStream;
import java.net.CacheRequest;
+import java.util.Arrays;
/**
* An HTTP body with alternating chunk sizes and chunk bodies.
@@ -35,7 +36,7 @@ final class ChunkedInputStream extends AbstractHttpInputStream {
}
@Override public int read(byte[] buffer, int offset, int count) throws IOException {
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
checkNotClosed();
if (!hasMoreChunks) {
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedOutputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedOutputStream.java
index cf6fc4c..543e495 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedOutputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/ChunkedOutputStream.java
@@ -19,6 +19,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
/**
* An HTTP body with alternating chunk sizes and chunk bodies. Chunks are
@@ -62,7 +63,7 @@ final class ChunkedOutputStream extends AbstractHttpOutputStream {
@Override public synchronized void write(byte[] buffer, int offset, int count)
throws IOException {
checkNotClosed();
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
while (count > 0) {
int numBytesWritten;
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthInputStream.java
index aa4e214..3a19f58 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthInputStream.java
@@ -19,6 +19,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.IOException;
import java.io.InputStream;
import java.net.CacheRequest;
+import java.util.Arrays;
/**
* An HTTP body with a fixed length specified in advance.
@@ -36,7 +37,7 @@ final class FixedLengthInputStream extends AbstractHttpInputStream {
}
@Override public int read(byte[] buffer, int offset, int count) throws IOException {
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
checkNotClosed();
if (bytesRemaining == 0) {
return -1;
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthOutputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthOutputStream.java
index 6bdab60..d3c3f02 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthOutputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/FixedLengthOutputStream.java
@@ -18,6 +18,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
/**
* An HTTP body with a fixed length known in advance.
@@ -33,7 +34,7 @@ final class FixedLengthOutputStream extends AbstractHttpOutputStream {
@Override public void write(byte[] buffer, int offset, int count) throws IOException {
checkNotClosed();
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
if (count > bytesRemaining) {
throw new IOException("expected " + bytesRemaining + " bytes but received " + count);
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java
deleted file mode 100644
index 50ca102..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/Header.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.internal.net.www.protocol.http;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.SortedMap;
-import java.util.TreeMap;
-import java.util.logging.Logger;
-
-/**
- * The general structure for request / response header. It is essentially
- * constructed by hashtable with key indexed in a vector for position lookup.
- */
-public class Header implements Cloneable {
- private ArrayList<String> props;
-
- private SortedMap<String, LinkedList<String>> keyTable;
-
- private String statusLine;
-
- /**
- * A generic header structure. Used mostly for request / response header.
- * The key/value pair of the header may be inserted for later use. The key
- * is stored in an array for indexed slot access.
- */
- public Header() {
- super();
- this.props = new ArrayList<String>(20);
- this.keyTable = new TreeMap<String, LinkedList<String>>(
- String.CASE_INSENSITIVE_ORDER);
- }
-
- /**
- * The alternative constructor which sets the input map as its initial
- * keyTable.
- *
- * @param map
- * the initial keyTable as a map
- */
- public Header(Map<String, List<String>> map) {
- this(); // initialize fields
- for (Entry<String, List<String>> next : map.entrySet()) {
- String key = next.getKey();
- List<String> value = next.getValue();
- LinkedList<String> linkedList = new LinkedList<String>();
- for (String element : value) {
- linkedList.add(element);
- props.add(key);
- props.add(element);
- }
- keyTable.put(key, linkedList);
- }
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public Object clone() {
- try {
- Header clone = (Header) super.clone();
- clone.props = (ArrayList<String>) props.clone();
- clone.keyTable = new TreeMap<String, LinkedList<String>>(
- String.CASE_INSENSITIVE_ORDER);
- for (Map.Entry<String, LinkedList<String>> next : this.keyTable
- .entrySet()) {
- LinkedList<String> v = (LinkedList<String>) next.getValue()
- .clone();
- clone.keyTable.put(next.getKey(), v);
- }
- return clone;
- } catch (CloneNotSupportedException e) {
- throw new AssertionError(e); // android-changed
- }
- }
-
- /**
- * Add a field with the specified value.
- *
- * @param key
- * @param value
- */
- public void add(String key, String value) {
- if (key == null) {
- throw new NullPointerException();
- }
- if (value == null) {
- /*
- * Given null values, the RI sends a malformed header line like
- * "Accept\r\n". For platform compatibility and HTTP compliance, we
- * print a warning and ignore null values.
- */
- Logger.getAnonymousLogger().warning(
- "Ignoring HTTP header field " + key + " because its value is null.");
- return;
- }
- LinkedList<String> list = keyTable.get(key);
- if (list == null) {
- list = new LinkedList<String>();
- keyTable.put(key, list);
- }
- list.add(value);
- props.add(key);
- props.add(value);
- }
-
- public void removeAll(String key) {
- keyTable.remove(key);
-
- for (int i = 0; i < props.size(); i += 2) {
- if (key.equals(props.get(i))) {
- props.remove(i); // key
- props.remove(i); // value
- }
- }
- }
-
- public void addAll(String key, List<String> headers) {
- for (String header : headers) {
- add(key, header);
- }
- }
-
- public void addIfAbsent(String key, String value) {
- if (get(key) == null) {
- add(key, value);
- }
- }
-
- /**
- * Set a field with the specified value. If the field is not found, it is
- * added. If the field is found, the existing value(s) are overwritten.
- *
- * @param key
- * @param value
- */
- public void set(String key, String value) {
- removeAll(key);
- add(key, value);
- }
-
- /**
- * Provides an unmodifiable map with all String header names mapped to their
- * String values. The map keys are Strings and the values are unmodifiable
- * Lists of Strings.
- *
- * @return an unmodifiable map of the headers
- *
- * @since 1.4
- */
- public Map<String, List<String>> getFieldMap() {
- Map<String, List<String>> result = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); // android-changed
- for (Map.Entry<String, LinkedList<String>> next : keyTable.entrySet()) {
- List<String> v = next.getValue();
- result.put(next.getKey(), Collections.unmodifiableList(v));
- }
- return Collections.unmodifiableMap(result);
- }
-
- /**
- * Returns the element at <code>pos</code>, null if no such element
- * exist.
- *
- * @return java.lang.String the value of the key
- * @param pos
- * int the position to look for
- */
- public String get(int pos) {
- if (pos >= 0 && pos < props.size() / 2) {
- return props.get(pos * 2 + 1);
- }
- return null;
- }
-
- /**
- * Returns the key of this header at <code>pos</code>, null if there are
- * fewer keys in the header
- *
- *
- * @return the key the desired position
- * @param pos
- * the position to look for
- */
- public String getKey(int pos) {
- if (pos >= 0 && pos < props.size() / 2) {
- return props.get(pos * 2);
- }
- return null;
- }
-
- /**
- * Returns the value corresponding to the specified key, or null.
- */
- public String get(String key) {
- LinkedList<String> result = keyTable.get(key);
- if (result == null) {
- return null;
- }
- return result.getLast();
- }
-
- /**
- * Returns the number of keys stored in this header
- *
- * @return the number of keys.
- */
- public int length() {
- return props.size() / 2;
- }
-
- /**
- * Sets the status line in the header request example: GET / HTTP/1.1
- * response example: HTTP/1.1 200 OK
- *
- * @param statusLine
- */
- public void setStatusLine(String statusLine) {
- this.statusLine = statusLine;
- /*
- * we add the status line to the list of headers so that it is
- * accessible from java.net.HttpURLConnection.getResponseCode() which
- * calls
- * org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHeaderField(0)
- * to get it
- */
- props.add(0, null);
- props.add(1, statusLine);
- }
-
- /**
- * Gets the status line in the header request example: GET / HTTP/1.1
- * response example: HTTP/1.1 200 OK
- *
- * @return the status line
- */
- public String getStatusLine() {
- return statusLine;
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
index 32c801f..54e074f 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java
@@ -18,7 +18,6 @@
package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.BufferedInputStream;
-import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -34,6 +33,7 @@ import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import libcore.base.Objects;
+import libcore.io.IoUtils;
import org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl;
/**
@@ -61,7 +61,7 @@ public final class HttpConnection {
this.address = config;
/*
- * Try each of the host's addresses for best behaviour in mixed IPv4/IPv6
+ * Try each of the host's addresses for best behavior in mixed IPv4/IPv6
* environments. See http://b/2876927
* TODO: add a hidden method so that Socket.tryAllAddresses can does this for us
*/
@@ -86,30 +86,12 @@ public final class HttpConnection {
}
public void closeSocketAndStreams() {
- closeQuietly(sslOutputStream);
- closeQuietly(sslInputStream);
- closeQuietly(sslSocket);
- closeQuietly(outputStream);
- closeQuietly(inputStream);
- closeQuietly(socket);
- }
-
- private void closeQuietly(Socket socket) {
- if (socket != null) {
- try {
- socket.close();
- } catch (Exception ignored) {
- }
- }
- }
-
- private void closeQuietly(Closeable closeable) {
- if (closeable != null) {
- try {
- closeable.close();
- } catch (Exception ignored) {
- }
- }
+ IoUtils.closeQuietly(sslOutputStream);
+ IoUtils.closeQuietly(sslInputStream);
+ IoUtils.closeQuietly(sslSocket);
+ IoUtils.closeQuietly(outputStream);
+ IoUtils.closeQuietly(inputStream);
+ IoUtils.closeQuietly(socket);
}
public void setSoTimeout(int readTimeout) throws SocketException {
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeaders.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeaders.java
new file mode 100644
index 0000000..1d02097
--- /dev/null
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeaders.java
@@ -0,0 +1,211 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.internal.net.www.protocol.http;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import java.util.logging.Logger;
+
+/**
+ * The HTTP status and header lines of a single HTTP message. This class
+ * maintains the order of the header lines within the HTTP message.
+ */
+public final class HttpHeaders implements Cloneable {
+
+ private static final Comparator<String> HEADER_COMPARATOR = new Comparator<String>() {
+ @Override public int compare(String a, String b) {
+ if (a == b) {
+ return 0;
+ } else if (a == null) {
+ return -1;
+ } else if (b == null) {
+ return 1;
+ } else {
+ return String.CASE_INSENSITIVE_ORDER.compare(a, b);
+ }
+ }
+ };
+
+ private final List<String> alternatingKeysAndValues = new ArrayList<String>(20);
+ private String statusLine;
+
+ public HttpHeaders() {}
+
+ public HttpHeaders(HttpHeaders copyFrom) {
+ statusLine = copyFrom.statusLine;
+ alternatingKeysAndValues.addAll(copyFrom.alternatingKeysAndValues);
+ }
+
+ public void setStatusLine(String statusLine) {
+ this.statusLine = statusLine;
+ }
+
+ public String getStatusLine() {
+ return statusLine;
+ }
+
+ /**
+ * Add a field with the specified value.
+ */
+ public void add(String key, String value) {
+ if (key == null) {
+ throw new IllegalArgumentException("key == null");
+ }
+ if (value == null) {
+ /*
+ * Given null values, the RI sends a malformed header line like
+ * "Accept\r\n". For platform compatibility and HTTP compliance, we
+ * print a warning and ignore null values.
+ */
+ Logger.getAnonymousLogger().warning(
+ "Ignoring HTTP header field " + key + " because its value is null.");
+ return;
+ }
+ alternatingKeysAndValues.add(key);
+ alternatingKeysAndValues.add(value);
+ }
+
+ public void removeAll(String key) {
+ for (int i = 0; i < alternatingKeysAndValues.size(); i += 2) {
+ if (key.equalsIgnoreCase(alternatingKeysAndValues.get(i))) {
+ alternatingKeysAndValues.remove(i); // key
+ alternatingKeysAndValues.remove(i); // value
+ }
+ }
+ }
+
+ public void addAll(String key, List<String> headers) {
+ for (String header : headers) {
+ add(key, header);
+ }
+ }
+
+ public void addIfAbsent(String key, String value) {
+ if (get(key) == null) {
+ add(key, value);
+ }
+ }
+
+ /**
+ * Set a field with the specified value. If the field is not found, it is
+ * added. If the field is found, the existing values are replaced.
+ */
+ public void set(String key, String value) {
+ removeAll(key);
+ add(key, value);
+ }
+
+ /**
+ * Returns the number of header lines.
+ */
+ public int length() {
+ return alternatingKeysAndValues.size() / 2;
+ }
+
+ /**
+ * Returns the key at {@code position} or null if that is out of range.
+ */
+ public String getKey(int index) {
+ int keyIndex = index * 2;
+ if (keyIndex < 0 || keyIndex >= alternatingKeysAndValues.size()) {
+ return null;
+ }
+ return alternatingKeysAndValues.get(keyIndex);
+ }
+
+ /**
+ * Returns the value at {@code index} or null if that is out of range.
+ */
+ public String getValue(int index) {
+ int valueIndex = index * 2 + 1;
+ if (valueIndex < 0 || valueIndex >= alternatingKeysAndValues.size()) {
+ return null;
+ }
+ return alternatingKeysAndValues.get(valueIndex);
+ }
+
+ /**
+ * Returns the last value corresponding to the specified key, or null.
+ */
+ public String get(String key) {
+ for (int i = alternatingKeysAndValues.size() - 2; i >= 0; i -= 2) {
+ if (key.equalsIgnoreCase(alternatingKeysAndValues.get(i))) {
+ return alternatingKeysAndValues.get(i + 1);
+ }
+ }
+ return null;
+ }
+
+ public String toHeaderString() {
+ StringBuilder result = new StringBuilder(256);
+ result.append(statusLine).append("\r\n");
+ for (int i = 0; i < alternatingKeysAndValues.size(); i += 2) {
+ result.append(alternatingKeysAndValues.get(i)).append(": ")
+ .append(alternatingKeysAndValues.get(i + 1)).append("\r\n");
+ }
+ result.append("\r\n");
+ return result.toString();
+ }
+
+ /**
+ * Returns an immutable map containing each field to its list of values. The
+ * status line is mapped to null.
+ */
+ public Map<String, List<String>> toMultimap() {
+ Map<String, List<String>> result = new TreeMap<String, List<String>>(HEADER_COMPARATOR);
+ for (int i = 0; i < alternatingKeysAndValues.size(); i += 2) {
+ String key = alternatingKeysAndValues.get(i);
+ String value = alternatingKeysAndValues.get(i + 1);
+
+ List<String> allValues = new ArrayList<String>();
+ List<String> otherValues = result.get(key);
+ if (otherValues != null) {
+ allValues.addAll(otherValues);
+ }
+ allValues.add(value);
+ result.put(key, Collections.unmodifiableList(allValues));
+ }
+ if (statusLine != null) {
+ result.put(null, Collections.unmodifiableList(Collections.singletonList(statusLine)));
+ }
+ return Collections.unmodifiableMap(result);
+ }
+
+ /**
+ * Creates a header from the given map of fields to values. If present, the
+ * null key's last element will be used to set the status line.
+ */
+ public static HttpHeaders fromMultimap(Map<String, List<String>> map) {
+ HttpHeaders result = new HttpHeaders();
+ for (Entry<String, List<String>> entry : map.entrySet()) {
+ String key = entry.getKey();
+ List<String> values = entry.getValue();
+ if (key != null) {
+ result.addAll(key, values);
+ } else if (!values.isEmpty()) {
+ result.setStatusLine(values.get(values.size() - 1));
+ }
+ }
+ return result;
+ }
+}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
index 6983181..1a8ccdb 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java
@@ -17,6 +17,7 @@
package org.apache.harmony.luni.internal.net.www.protocol.http;
+import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -102,6 +103,14 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
public static final int DEFAULT_CHUNK_LENGTH = 1024;
+ /**
+ * The maximum number of bytes to buffer when sending a header and a request
+ * body. When the header and body can be sent in a single write, the request
+ * completes sooner. In one WiFi benchmark, using a large enough buffer sped
+ * up some uploads by half.
+ */
+ private static final int MAX_REQUEST_BUFFER_LENGTH = 32768;
+
private final int defaultPort;
/**
@@ -115,12 +124,21 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
private InputStream socketIn;
private OutputStream socketOut;
- private InputStream responseBodyIn;
+ /**
+ * This stream buffers the request header and the request body when their
+ * combined size is less than MAX_REQUEST_BUFFER_LENGTH. By combining them
+ * we can save socket writes, which in turn saves a packet transmission.
+ * This is socketOut if the request size is large or unknown.
+ */
+ private OutputStream requestOut;
+
private AbstractHttpOutputStream requestBodyOut;
+ protected InputStream responseBodyIn;
+
private ResponseCache responseCache;
- private CacheResponse cacheResponse;
+ protected CacheResponse cacheResponse;
private CacheRequest cacheRequest;
@@ -142,12 +160,12 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
// the destination URI
private URI uri;
- private static Header defaultRequestHeader = new Header();
+ private static HttpHeaders defaultRequestHeader = new HttpHeaders();
- private final Header requestHeader;
+ private final HttpHeaders requestHeader;
/** Null until a response is received from the network or the cache */
- private Header responseHeader;
+ private HttpHeaders responseHeader;
private int redirectionCount;
@@ -168,19 +186,13 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
protected HttpURLConnectionImpl(URL url, int port) {
super(url);
defaultPort = port;
- requestHeader = (Header) defaultRequestHeader.clone();
+ requestHeader = new HttpHeaders(defaultRequestHeader);
- try {
- uri = url.toURI();
- } catch (URISyntaxException e) {
- // do nothing.
- }
- responseCache = AccessController
- .doPrivileged(new PrivilegedAction<ResponseCache>() {
- public ResponseCache run() {
- return ResponseCache.getDefault();
- }
- });
+ responseCache = AccessController.doPrivileged(new PrivilegedAction<ResponseCache>() {
+ public ResponseCache run() {
+ return ResponseCache.getDefault();
+ }
+ });
}
/**
@@ -216,23 +228,18 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
public void makeConnection() throws IOException {
connected = true;
- if (connection != null) {
+ if (connection != null || responseBodyIn != null) {
return;
}
- if (getFromCache()) {
- return;
+ try {
+ uri = url.toURILenient();
+ } catch (URISyntaxException e) {
+ throw new IOException(e);
}
- /*
- * URL.toURI() throws if it has illegal characters. Since we don't mind
- * illegal characters for proxy selection, just create the minimal URI.
- */
- try {
- uri = new URI(url.getProtocol(), null, url.getHost(), url.getPort(), url.getPath(),
- null, null);
- } catch (URISyntaxException e1) {
- throw new IOException(e1.getMessage());
+ if (getFromCache()) {
+ return;
}
// try to determine: to use the proxy or not
@@ -290,29 +297,46 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
*/
protected void setUpTransportIO(HttpConnection connection) throws IOException {
socketOut = connection.getOutputStream();
+ requestOut = socketOut;
socketIn = connection.getInputStream();
}
/**
- * Returns true if the input streams are prepared to return data from the
- * cache.
+ * Attempts to load the response headers and body from the response cache.
+ * Returns true if the request was satisfied by the cache.
*/
private boolean getFromCache() throws IOException {
if (!useCaches || responseCache == null || hasTriedCache) {
- return (hasTriedCache && socketIn != null);
+ return false;
}
hasTriedCache = true;
- cacheResponse = responseCache.get(uri, method, requestHeader.getFieldMap());
- if (cacheResponse == null) {
- return socketIn != null; // TODO: if this is non-null, why are we calling getFromCache?
+ CacheResponse candidate = responseCache.get(uri, method, requestHeader.toMultimap());
+ if (!acceptCacheResponse(candidate)) {
+ return false;
+ }
+ Map<String, List<String>> headersMap = candidate.getHeaders();
+ if (headersMap == null) {
+ return false;
}
- Map<String, List<String>> headersMap = cacheResponse.getHeaders();
- if (headersMap != null) {
- responseHeader = new Header(headersMap);
+ InputStream cacheBodyIn = candidate.getBody();
+ if (cacheBodyIn == null) {
+ return false;
}
- socketIn = responseBodyIn = cacheResponse.getBody();
- return socketIn != null;
+
+ cacheResponse = candidate;
+ responseHeader = HttpHeaders.fromMultimap(headersMap);
+ parseStatusLine();
+ responseBodyIn = cacheBodyIn;
+ return true;
+ }
+
+ /**
+ * Returns true if {@code cacheResponse} is sufficient to forgo a network
+ * request. HTTPS connections require secure cache responses.
+ */
+ protected boolean acceptCacheResponse(CacheResponse cacheResponse) {
+ return cacheResponse != null;
}
private void maybeCache() throws IOException {
@@ -328,7 +352,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
return;
}
// Offer this request to the cache.
- cacheRequest = responseCache.put(uri, this);
+ cacheRequest = responseCache.put(uri, getConnectionForCaching());
}
/**
@@ -370,12 +394,12 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
}
/*
- * Clear "socketIn" and "socketOut" to ensure that no further I/O
- * attempts from this instance make their way to the underlying
- * connection (which may get recycled).
+ * Ensure that no further I/O attempts from this instance make their way
+ * to the underlying connection (which may get recycled).
*/
- socketIn = null;
socketOut = null;
+ socketIn = null;
+ requestOut = null;
}
/**
@@ -399,6 +423,9 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
responseCode = -1;
responseMessage = null;
cacheRequest = null;
+ uri = null;
+ cacheResponse = null;
+ hasTriedCache = false;
} finally {
intermediateResponse = oldIntermediateResponse;
}
@@ -422,27 +449,16 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
}
/**
- * Returns the value of the field at position <code>pos<code>.
- * Returns <code>null</code> if there is fewer than <code>pos</code> fields
- * in the response header.
- *
- * @return java.lang.String The value of the field
- * @param pos int the position of the field from the top
- *
- * @see #getHeaderField(String)
- * @see #getHeaderFieldKey
+ * Returns the value of the field at {@code position}. Returns null if there
+ * are fewer than {@code position} headers.
*/
@Override
- public String getHeaderField(int pos) {
+ public String getHeaderField(int position) {
try {
getInputStream();
- } catch (IOException e) {
- // ignore
- }
- if (null == responseHeader) {
- return null;
+ } catch (IOException ignored) {
}
- return responseHeader.get(pos);
+ return responseHeader != null ? responseHeader.getValue(position) : null;
}
/**
@@ -463,26 +479,21 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
public String getHeaderField(String key) {
try {
getInputStream();
- } catch (IOException e) {
- // ignore
+ } catch (IOException ignored) {
}
- if (null == responseHeader) {
+ if (responseHeader == null) {
return null;
}
- return responseHeader.get(key);
+ return key == null ? responseHeader.getStatusLine() : responseHeader.get(key);
}
@Override
- public String getHeaderFieldKey(int pos) {
+ public String getHeaderFieldKey(int position) {
try {
getInputStream();
- } catch (IOException e) {
- // ignore
- }
- if (null == responseHeader) {
- return null;
+ } catch (IOException ignored) {
}
- return responseHeader.getKey(pos);
+ return responseHeader != null ? responseHeader.getKey(position) : null;
}
@Override
@@ -491,7 +502,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
retrieveResponse();
} catch (IOException ignored) {
}
- return responseHeader != null ? responseHeader.getFieldMap() : null;
+ return responseHeader != null ? responseHeader.toMultimap() : null;
}
@Override
@@ -500,7 +511,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
throw new IllegalStateException(
"Cannot access request header fields after connection is set");
}
- return requestHeader.getFieldMap();
+ return requestHeader.toMultimap();
}
@Override
@@ -528,7 +539,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
return responseBodyIn;
}
- private InputStream initContentStream() throws IOException {
+ private void initContentStream() throws IOException {
InputStream transferStream = getTransferStream();
if (transparentGzip && "gzip".equalsIgnoreCase(responseHeader.get("Content-Encoding"))) {
/*
@@ -540,7 +551,6 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
} else {
responseBodyIn = transferStream;
}
- return responseBodyIn;
}
private InputStream getTransferStream() throws IOException {
@@ -623,12 +633,13 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
}
if (fixedContentLength != -1) {
- writeRequestHeaders(socketOut);
- requestBodyOut = new FixedLengthOutputStream(socketOut, fixedContentLength);
+ writeRequestHeaders(fixedContentLength);
+ requestBodyOut = new FixedLengthOutputStream(requestOut, fixedContentLength);
} else if (sendChunked) {
- writeRequestHeaders(socketOut);
- requestBodyOut = new ChunkedOutputStream(socketOut, chunkLength);
+ writeRequestHeaders(-1);
+ requestBodyOut = new ChunkedOutputStream(requestOut, chunkLength);
} else if (contentLength != -1) {
+ writeRequestHeaders(contentLength);
requestBodyOut = new RetryableOutputStream(contentLength);
} else {
requestBodyOut = new RetryableOutputStream();
@@ -644,7 +655,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
@Override
public String getRequestProperty(String field) {
- if (null == field) {
+ if (field == null) {
return null;
}
return requestHeader.get(field);
@@ -684,12 +695,11 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
private void readResponseHeaders() throws IOException {
do {
- responseCode = -1;
- responseMessage = null;
- responseHeader = new Header();
+ responseHeader = new HttpHeaders();
responseHeader.setStatusLine(readLine(socketIn).trim());
readHeaders();
- } while (parseResponseCode() == HTTP_CONTINUE);
+ parseStatusLine();
+ } while (responseCode == HTTP_CONTINUE);
}
/**
@@ -727,16 +737,20 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
return responseCode;
}
- private int parseResponseCode() {
- // Response Code Sample : "HTTP/1.0 200 OK"
+ private void parseStatusLine() {
+ httpVersion = 1;
+ responseCode = -1;
+ responseMessage = null;
+
+ // Status line sample: "HTTP/1.0 200 OK"
String response = responseHeader.getStatusLine();
if (response == null || !response.startsWith("HTTP/")) {
- return -1;
+ return;
}
response = response.trim();
int mark = response.indexOf(" ") + 1;
if (mark == 0) {
- return -1;
+ return;
}
if (response.charAt(mark - 2) != '1') {
httpVersion = 0;
@@ -749,7 +763,6 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
if (last + 1 <= response.length()) {
responseMessage = response.substring(last + 1);
}
- return responseCode;
}
void readHeaders() throws IOException {
@@ -767,7 +780,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null) {
- cookieHandler.put(uri, responseHeader.getFieldMap());
+ cookieHandler.put(uri, responseHeader.toMultimap());
}
}
@@ -782,21 +795,19 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
* <strong>after</strong> the output stream has been written to and closed.
* This ensures that the {@code Content-Length} header receives the proper
* value.
+ *
+ * @param contentLength the number of bytes in the request body, or -1 if
+ * the request body length is unknown.
*/
- private void writeRequestHeaders(OutputStream out) throws IOException {
- Header header = prepareRequestHeaders();
-
- StringBuilder result = new StringBuilder(256);
- result.append(header.getStatusLine()).append("\r\n");
- for (int i = 0; i < header.length(); i++) {
- String key = header.getKey(i);
- String value = header.get(i);
- if (key != null) {
- result.append(key).append(": ").append(value).append("\r\n");
- }
+ private void writeRequestHeaders(int contentLength) throws IOException {
+ byte[] headerBytes = prepareRequestHeaders().toHeaderString().getBytes(Charsets.ISO_8859_1);
+
+ if (contentLength != -1
+ && headerBytes.length + contentLength <= MAX_REQUEST_BUFFER_LENGTH) {
+ requestOut = new BufferedOutputStream(socketOut, headerBytes.length + contentLength);
}
- result.append("\r\n");
- out.write(result.toString().getBytes(Charsets.ISO_8859_1));
+
+ requestOut.write(headerBytes);
sentRequestHeaders = true;
}
@@ -807,14 +818,14 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
* <p>This client doesn't specify a default {@code Accept} header because it
* doesn't know what content types the application is interested in.
*/
- private Header prepareRequestHeaders() throws IOException {
+ private HttpHeaders prepareRequestHeaders() throws IOException {
/*
* If we're establishing an HTTPS tunnel with CONNECT (RFC 2817 5.2),
* send only the minimum set of headers. This avoids sending potentially
* sensitive data like HTTP cookies to the proxy unencrypted.
*/
if (method == CONNECT) {
- Header proxyHeader = new Header();
+ HttpHeaders proxyHeader = new HttpHeaders();
proxyHeader.setStatusLine(getStatusLine());
// always set Host and User-Agent
@@ -877,7 +888,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler != null) {
Map<String, List<String>> allCookieHeaders
- = cookieHandler.get(uri, requestHeader.getFieldMap());
+ = cookieHandler.get(uri, requestHeader.toMultimap());
for (Map.Entry<String, List<String>> entry : allCookieHeaders.entrySet()) {
String key = entry.getKey();
if ("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key)) {
@@ -1004,6 +1015,15 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
}
/**
+ * Returns this connection in a form suitable for use by the response cache.
+ * If this returns an HTTPS connection, only secure cache responses will be
+ * honored.
+ */
+ protected HttpURLConnection getConnectionForCaching() {
+ return this;
+ }
+
+ /**
* Aggressively tries to get the final HTTP response, potentially making
* many HTTP requests in the process in order to cope with redirects and
* authentication.
@@ -1017,34 +1037,10 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
while (true) {
makeConnection();
- // if we can get a response from the cache, we're done
- if (cacheResponse != null) {
- // TODO: how does this interact with redirects? Consider processing the headers so
- // that a redirect is never returned.
- return;
+ if (cacheResponse == null) {
+ getFromNetwork();
}
- if (!sentRequestHeaders) {
- writeRequestHeaders(socketOut);
- }
-
- if (requestBodyOut != null) {
- requestBodyOut.close();
- if (requestBodyOut instanceof RetryableOutputStream) {
- ((RetryableOutputStream) requestBodyOut).writeToSocket(socketOut);
- }
- }
-
- socketOut.flush();
-
- readResponseHeaders();
-
- if (hasResponseBody()) {
- maybeCache(); // reentrant. this calls into user code which may call back into this!
- }
-
- initContentStream();
-
Retry retry = processResponseHeaders();
if (retry == Retry.NONE) {
@@ -1071,6 +1067,33 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
}
}
+ private void getFromNetwork() throws IOException {
+ if (!sentRequestHeaders) {
+ int contentLength = requestBodyOut instanceof RetryableOutputStream
+ ? ((RetryableOutputStream) requestBodyOut).contentLength()
+ : -1;
+ writeRequestHeaders(contentLength);
+ }
+
+ if (requestBodyOut != null) {
+ requestBodyOut.close();
+ if (requestBodyOut instanceof RetryableOutputStream) {
+ ((RetryableOutputStream) requestBodyOut).writeToSocket(requestOut);
+ }
+ }
+
+ requestOut.flush();
+ requestOut = socketOut;
+
+ readResponseHeaders();
+
+ if (hasResponseBody()) {
+ maybeCache(); // reentrant. this calls into user code which may call back into this!
+ }
+
+ initContentStream();
+ }
+
enum Retry {
NONE,
SAME_CONNECTION,
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/RetryableOutputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/RetryableOutputStream.java
index d02f5a4..de97ccc 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/RetryableOutputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/RetryableOutputStream.java
@@ -19,6 +19,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
/**
* An HTTP request body that's completely buffered in memory. This allows
@@ -53,7 +54,7 @@ final class RetryableOutputStream extends AbstractHttpOutputStream {
@Override public synchronized void write(byte[] buffer, int offset, int count)
throws IOException {
checkNotClosed();
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
if (limit != -1 && content.size() > limit - count) {
throw new IOException("exceeded content-length limit of " + limit + " bytes");
}
@@ -66,8 +67,6 @@ final class RetryableOutputStream extends AbstractHttpOutputStream {
}
public void writeToSocket(OutputStream socketOut) throws IOException {
- close();
content.writeTo(socketOut);
- socketOut.flush();
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java
index 7bb4abb..c5eec13 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/UnknownLengthHttpInputStream.java
@@ -19,6 +19,7 @@ package org.apache.harmony.luni.internal.net.www.protocol.http;
import java.io.IOException;
import java.io.InputStream;
import java.net.CacheRequest;
+import java.util.Arrays;
/**
* An HTTP payload terminated by the end of the socket stream.
@@ -32,7 +33,7 @@ final class UnknownLengthHttpInputStream extends AbstractHttpInputStream {
}
@Override public int read(byte[] buffer, int offset, int count) throws IOException {
- checkBounds(buffer, offset, count);
+ Arrays.checkOffsetAndCount(buffer.length, offset, count);
checkNotClosed();
if (in == null) {
return -1;
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
index 5897685..46fb786 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java
@@ -19,8 +19,11 @@ package org.apache.harmony.luni.internal.net.www.protocol.https;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.CacheResponse;
+import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.Proxy;
+import java.net.SecureCacheResponse;
import java.net.URL;
import java.security.Permission;
import java.security.Principal;
@@ -73,30 +76,52 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
@Override
public String getCipherSuite() {
+ SecureCacheResponse cacheResponse = httpsEngine.getCacheResponse();
+ if (cacheResponse != null) {
+ return cacheResponse.getCipherSuite();
+ }
checkConnected();
return sslSocket.getSession().getCipherSuite();
}
@Override
public Certificate[] getLocalCertificates() {
+ SecureCacheResponse cacheResponse = httpsEngine.getCacheResponse();
+ if (cacheResponse != null) {
+ List<Certificate> result = cacheResponse.getLocalCertificateChain();
+ return result != null ? result.toArray(new Certificate[result.size()]) : null;
+ }
checkConnected();
return sslSocket.getSession().getLocalCertificates();
}
@Override
public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
+ SecureCacheResponse cacheResponse = httpsEngine.getCacheResponse();
+ if (cacheResponse != null) {
+ List<Certificate> result = cacheResponse.getServerCertificateChain();
+ return result != null ? result.toArray(new Certificate[result.size()]) : null;
+ }
checkConnected();
return sslSocket.getSession().getPeerCertificates();
}
@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
+ SecureCacheResponse cacheResponse = httpsEngine.getCacheResponse();
+ if (cacheResponse != null) {
+ return cacheResponse.getPeerPrincipal();
+ }
checkConnected();
return sslSocket.getSession().getPeerPrincipal();
}
@Override
public Principal getLocalPrincipal() {
+ SecureCacheResponse cacheResponse = httpsEngine.getCacheResponse();
+ if (cacheResponse != null) {
+ return cacheResponse.getLocalPrincipal();
+ }
checkConnected();
return sslSocket.getSession().getLocalPrincipal();
}
@@ -348,6 +373,16 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
return httpsEngine.toString();
}
+ @Override
+ public void setFixedLengthStreamingMode(int contentLength) {
+ httpsEngine.setFixedLengthStreamingMode(contentLength);
+ }
+
+ @Override
+ public void setChunkedStreamingMode(int chunkLength) {
+ httpsEngine.setChunkedStreamingMode(chunkLength);
+ }
+
private final class HttpsEngine extends HttpURLConnectionImpl {
protected HttpsEngine(URL url, int port) {
@@ -359,6 +394,12 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
}
@Override public void makeConnection() throws IOException {
+ connected = true;
+
+ if (connection != null || responseBodyIn != null) {
+ return;
+ }
+
/*
* Short-circuit a reentrant call. The first step in doing SSL with
* an HTTP proxy requires calling retrieveResponse() which calls
@@ -405,6 +446,11 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
super.makeConnection();
+ // if we got a response from the cache, we're done
+ if (cacheResponse != null) {
+ return true;
+ }
+
// if super.makeConnection returned a connection from the
// pool, sslSocket needs to be initialized here. If it is
// a new connection, it will be initialized by
@@ -434,6 +480,10 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
return false;
}
+ public SecureCacheResponse getCacheResponse() {
+ return (SecureCacheResponse) cacheResponse;
+ }
+
@Override protected void setUpTransportIO(HttpConnection connection) throws IOException {
if (!requiresTunnel() && sslSocket == null) {
return; // don't initialize streams that won't be used
@@ -445,6 +495,14 @@ public class HttpsURLConnectionImpl extends HttpsURLConnection {
return usingProxy();
}
+ @Override protected HttpURLConnection getConnectionForCaching() {
+ return HttpsURLConnectionImpl.this;
+ }
+
+ @Override protected boolean acceptCacheResponse(CacheResponse cacheResponse) {
+ return cacheResponse instanceof SecureCacheResponse;
+ }
+
@Override protected String requestString() {
if (!usingProxy()) {
return super.requestString();
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
index bc8959b..9864350 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/jar/JarURLConnectionImpl.java
@@ -380,13 +380,10 @@ public class JarURLConnectionImpl extends JarURLConnection {
}
private class JarURLConnectionInputStream extends FilterInputStream {
- InputStream inputStream;
-
- JarFile jarFile;
+ final JarFile jarFile;
protected JarURLConnectionInputStream(InputStream in, JarFile file) {
super(in);
- inputStream = in;
jarFile = file;
}
@@ -398,20 +395,5 @@ public class JarURLConnectionImpl extends JarURLConnection {
jarFile.close();
}
}
-
- @Override
- public int read() throws IOException {
- return inputStream.read();
- }
-
- @Override
- public int read(byte[] buf, int off, int nbytes) throws IOException {
- return inputStream.read(buf, off, nbytes);
- }
-
- @Override
- public long skip(long nbytes) throws IOException {
- return inputStream.skip(nbytes);
- }
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java
index c4ba36a..78e5440 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java
@@ -17,8 +17,10 @@
package org.apache.harmony.luni.internal.util;
import java.nio.charset.Charsets;
+import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
+import java.util.Formatter;
import java.util.TimeZone;
import libcore.base.Objects;
@@ -38,78 +40,41 @@ final class ZoneInfo extends TimeZone {
0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
};
- private static String nullName(byte[] bytes, int begin) {
- if (begin < 0) {
- return null;
- }
- int end = begin;
- while (end < bytes.length && bytes[end] != 0) {
- ++end;
- }
- return new String(bytes, begin, end - begin, Charsets.US_ASCII);
- }
-
private int mRawOffset;
private final int[] mTransitions;
- private final int[] mGmtOffs;
+ private final int[] mOffsets;
private final byte[] mTypes;
private final byte[] mIsDsts;
private final boolean mUseDst;
- private final String mDaylightName;
- private final String mStandardName;
- ZoneInfo(String name, int[] transitions, byte[] type, int[] gmtoff, byte[] isdst,
- byte[] abbreviationIndexes, byte[] abbreviationList) {
+ ZoneInfo(String name, int[] transitions, byte[] type, int[] gmtOffsets, byte[] isDsts) {
mTransitions = transitions;
mTypes = type;
- mGmtOffs = gmtoff;
- mIsDsts = isdst;
+ mIsDsts = isDsts;
setID(name);
- // Find the latest GMT and non-GMT offsets for their abbreviations
-
- int lastdst;
- for (lastdst = mTransitions.length - 1; lastdst >= 0; lastdst--) {
- if (mIsDsts[mTypes[lastdst] & 0xFF] != 0) {
+ // Use the latest non-daylight offset (if any) as the raw offset.
+ int lastStd;
+ for (lastStd = mTransitions.length - 1; lastStd >= 0; lastStd--) {
+ if (mIsDsts[mTypes[lastStd] & 0xFF] == 0) {
break;
}
}
-
- int laststd;
- for (laststd = mTransitions.length - 1; laststd >= 0; laststd--) {
- if (mIsDsts[mTypes[laststd] & 0xFF] == 0) {
- break;
- }
- }
-
- if (lastdst >= 0) {
- mDaylightName = nullName(abbreviationList, abbreviationIndexes[mTypes[lastdst] & 0xFF]);
- } else {
- mDaylightName = null;
- }
- if (laststd >= 0) {
- mStandardName = nullName(abbreviationList, abbreviationIndexes[mTypes[laststd] & 0xFF]);
- } else {
- mStandardName = null;
- }
-
- // Use the latest non-DST offset if any as the raw offset
-
- if (laststd < 0) {
- laststd = 0;
+ if (lastStd < 0) {
+ lastStd = 0;
}
-
- if (laststd >= mTypes.length) {
- mRawOffset = mGmtOffs[0];
+ if (lastStd >= mTypes.length) {
+ mRawOffset = gmtOffsets[0];
} else {
- mRawOffset = mGmtOffs[mTypes[laststd] & 0xFF];
+ mRawOffset = gmtOffsets[mTypes[lastStd] & 0xFF];
}
- // Subtract the raw offset from all offsets so it can be changed
- // and affect them too.
- for (int i = 0; i < mGmtOffs.length; i++) {
- mGmtOffs[i] -= mRawOffset;
+ // Rather than keep offsets from UTC, we use offsets from local time, so the raw offset
+ // can be changed and automatically affect all the offsets.
+ mOffsets = gmtOffsets;
+ for (int i = 0; i < mOffsets.length; i++) {
+ mOffsets[i] -= mRawOffset;
}
// Is this zone still observing DST?
@@ -146,8 +111,9 @@ final class ZoneInfo extends TimeZone {
calc += year * (365 * MILLISECONDS_PER_DAY);
calc += ((year + 3) / 4) * MILLISECONDS_PER_DAY;
- if (year > 0)
+ if (year > 0) {
calc -= ((year - 1) / 100) * MILLISECONDS_PER_DAY;
+ }
boolean isLeap = (year == 0 || (year % 4 == 0 && year % 100 != 0));
int[] mlen = isLeap ? LEAP : NORMAL;
@@ -168,13 +134,13 @@ final class ZoneInfo extends TimeZone {
int trans = Arrays.binarySearch(mTransitions, unix);
if (trans == ~0) {
- return mGmtOffs[0] * 1000 + mRawOffset;
+ return mRawOffset + mOffsets[0] * 1000;
}
if (trans < 0) {
trans = ~trans - 1;
}
- return mGmtOffs[mTypes[trans] & 0xFF] * 1000 + mRawOffset;
+ return mRawOffset + mOffsets[mTypes[trans] & 0xFF] * 1000;
}
@Override
@@ -220,7 +186,7 @@ final class ZoneInfo extends TimeZone {
}
return mRawOffset == other.mRawOffset
// Arrays.equals returns true if both arrays are null
- && Arrays.equals(mGmtOffs, other.mGmtOffs)
+ && Arrays.equals(mOffsets, other.mOffsets)
&& Arrays.equals(mIsDsts, other.mIsDsts)
&& Arrays.equals(mTypes, other.mTypes)
&& Arrays.equals(mTransitions, other.mTransitions);
@@ -231,20 +197,17 @@ final class ZoneInfo extends TimeZone {
return false;
}
ZoneInfo other = (ZoneInfo) obj;
- return Objects.equal(mDaylightName, other.mDaylightName)
- && Objects.equal(mStandardName, other.mStandardName)
- && hasSameRules(other);
+ return getID().equals(other.getID()) && hasSameRules(other);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((mDaylightName == null) ? 0 : mDaylightName.hashCode());
- result = prime * result + Arrays.hashCode(mGmtOffs);
+ result = prime * result + getID().hashCode();
+ result = prime * result + Arrays.hashCode(mOffsets);
result = prime * result + Arrays.hashCode(mIsDsts);
result = prime * result + mRawOffset;
- result = prime * result + ((mStandardName == null) ? 0 : mStandardName.hashCode());
result = prime * result + Arrays.hashCode(mTransitions);
result = prime * result + Arrays.hashCode(mTypes);
result = prime * result + (mUseDst ? 1231 : 1237);
@@ -253,7 +216,29 @@ final class ZoneInfo extends TimeZone {
@Override
public String toString() {
- return getClass().getName() +
- "[\"" + mStandardName + "\",mRawOffset=" + mRawOffset + ",mUseDst=" + mUseDst + "]";
+ StringBuilder sb = new StringBuilder();
+ // First the basics...
+ sb.append(getClass().getName() + "[" + getID() + ",mRawOffset=" + mRawOffset +
+ ",mUseDst=" + mUseDst + "]");
+ // ...followed by a zdump(1)-like description of all our transition data.
+ sb.append("\n");
+ Formatter f = new Formatter(sb);
+ for (int i = 0; i < mTransitions.length; ++i) {
+ int type = mTypes[i] & 0xff;
+ String utcTime = formatTime(mTransitions[i], TimeZone.getTimeZone("UTC"));
+ String localTime = formatTime(mTransitions[i], this);
+ int offset = mOffsets[type];
+ int gmtOffset = mRawOffset/1000 + offset;
+ f.format("%4d : time=%10d %s = %s isDst=%d offset=%5d gmtOffset=%d\n",
+ i, mTransitions[i], utcTime, localTime, mIsDsts[type], offset, gmtOffset);
+ }
+ return sb.toString();
+ }
+
+ private static String formatTime(int s, TimeZone tz) {
+ SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy zzz");
+ sdf.setTimeZone(tz);
+ long ms = ((long) s) * 1000L;
+ return sdf.format(new Date(ms));
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfoDB.java b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfoDB.java
index c44044c..c91f597 100644
--- a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfoDB.java
+++ b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfoDB.java
@@ -20,13 +20,15 @@ import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TimeZone;
+import libcore.io.BufferIterator;
import libcore.io.IoUtils;
+import libcore.io.MemoryMappedFile;
/**
* A class used to initialize the time zone database. This implementation uses the
@@ -72,7 +74,7 @@ public final class ZoneInfoDB {
readIndex();
}
- private static ByteBuffer mappedData = mapData();
+ private static final MemoryMappedFile allZoneData = mapData();
private ZoneInfoDB() {}
@@ -81,16 +83,11 @@ public final class ZoneInfoDB {
* present or is unreadable, we assume a version of "2007h".
*/
private static String readVersion() {
- RandomAccessFile versionFile = null;
try {
- versionFile = new RandomAccessFile(ZONE_DIRECTORY_NAME + "zoneinfo.version", "r");
- byte[] buf = new byte[(int) versionFile.length()];
- versionFile.readFully(buf);
- return new String(buf, 0, buf.length, Charsets.ISO_8859_1).trim();
+ byte[] bytes = IoUtils.readFileAsByteArray(ZONE_DIRECTORY_NAME + "zoneinfo.version");
+ return new String(bytes, 0, bytes.length, Charsets.ISO_8859_1).trim();
} catch (IOException ex) {
throw new RuntimeException(ex);
- } finally {
- IoUtils.closeQuietly(versionFile);
}
}
@@ -105,76 +102,80 @@ public final class ZoneInfoDB {
* All this code assumes strings are US-ASCII.
*/
private static void readIndex() {
- RandomAccessFile indexFile = null;
+ RandomAccessFile file = null;
+ MemoryMappedFile mappedFile = null;
try {
- indexFile = new RandomAccessFile(INDEX_FILE_NAME, "r");
-
- // The database reserves 40 bytes for each id.
- final int SIZEOF_TZNAME = 40;
- // The database uses 32-bit (4 byte) integers.
- final int SIZEOF_TZINT = 4;
+ file = new RandomAccessFile(INDEX_FILE_NAME, "r");
+ mappedFile = MemoryMappedFile.mmap(file.getFD(), MapMode.READ_ONLY, 0, file.length());
+ readIndex(mappedFile);
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ } finally {
+ IoUtils.closeQuietly(mappedFile);
+ IoUtils.closeQuietly(file);
+ }
+ }
- byte[] idBytes = new byte[SIZEOF_TZNAME];
+ private static void readIndex(MemoryMappedFile mappedFile) throws IOException {
+ BufferIterator it = mappedFile.bigEndianIterator();
- int numEntries = (int) (indexFile.length() / (SIZEOF_TZNAME + 3*SIZEOF_TZINT));
+ // The database reserves 40 bytes for each id.
+ final int SIZEOF_TZNAME = 40;
+ // The database uses 32-bit (4 byte) integers.
+ final int SIZEOF_TZINT = 4;
- char[] idChars = new char[numEntries * SIZEOF_TZNAME];
- int[] idEnd = new int[numEntries];
- int idOffset = 0;
+ byte[] idBytes = new byte[SIZEOF_TZNAME];
+ int numEntries = mappedFile.size() / (SIZEOF_TZNAME + 3*SIZEOF_TZINT);
- byteOffsets = new int[numEntries];
- rawUtcOffsets = new int[numEntries];
+ char[] idChars = new char[numEntries * SIZEOF_TZNAME];
+ int[] idEnd = new int[numEntries];
+ int idOffset = 0;
- for (int i = 0; i < numEntries; i++) {
- indexFile.readFully(idBytes);
- byteOffsets[i] = indexFile.readInt();
- int length = indexFile.readInt();
- if (length < 44) {
- throw new AssertionError("length in index file < sizeof(tzhead)");
- }
- rawUtcOffsets[i] = indexFile.readInt();
-
- // Don't include null chars in the String
- int len = idBytes.length;
- for (int j = 0; j < len; j++) {
- if (idBytes[j] == 0) {
- break;
- }
- idChars[idOffset++] = (char) (idBytes[j] & 0xFF);
- }
+ byteOffsets = new int[numEntries];
+ rawUtcOffsets = new int[numEntries];
- idEnd[i] = idOffset;
+ for (int i = 0; i < numEntries; i++) {
+ it.readByteArray(idBytes, 0, idBytes.length);
+ byteOffsets[i] = it.readInt();
+ int length = it.readInt();
+ if (length < 44) {
+ throw new AssertionError("length in index file < sizeof(tzhead)");
}
+ rawUtcOffsets[i] = it.readInt();
- // We create one string containing all the ids, and then break that into substrings.
- // This way, all ids share a single char[] on the heap.
- String allIds = new String(idChars, 0, idOffset);
- ids = new String[numEntries];
- for (int i = 0; i < numEntries; i++) {
- ids[i] = allIds.substring(i == 0 ? 0 : idEnd[i - 1], idEnd[i]);
+ // Don't include null chars in the String
+ int len = idBytes.length;
+ for (int j = 0; j < len; j++) {
+ if (idBytes[j] == 0) {
+ break;
+ }
+ idChars[idOffset++] = (char) (idBytes[j] & 0xFF);
}
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- } finally {
- IoUtils.closeQuietly(indexFile);
+
+ idEnd[i] = idOffset;
+ }
+
+ // We create one string containing all the ids, and then break that into substrings.
+ // This way, all ids share a single char[] on the heap.
+ String allIds = new String(idChars, 0, idOffset);
+ ids = new String[numEntries];
+ for (int i = 0; i < numEntries; i++) {
+ ids[i] = allIds.substring(i == 0 ? 0 : idEnd[i - 1], idEnd[i]);
}
}
/**
* Rather than open, read, and close the big data file each time we look up a time zone,
- * we map the big data file during startup, and then just use the ByteBuffer.
+ * we map the big data file during startup, and then just use the MemoryMappedFile.
*
* At the moment, this "big" data file is about 160 KiB. At some point, that will be small
* enough that we'll just keep the byte[] in memory.
*/
- private static ByteBuffer mapData() {
+ private static MemoryMappedFile mapData() {
RandomAccessFile file = null;
try {
file = new RandomAccessFile(ZONE_FILE_NAME, "r");
- FileChannel channel = file.getChannel();
- ByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
- buffer.order(ByteOrder.BIG_ENDIAN);
- return buffer;
+ return MemoryMappedFile.mmap(file.getFD(), MapMode.READ_ONLY, 0, file.length());
} catch (IOException ex) {
throw new RuntimeException(ex);
} finally {
@@ -188,53 +189,51 @@ public final class ZoneInfoDB {
if (index < 0) {
return null;
}
- int start = byteOffsets[index];
- // We duplicate the ByteBuffer to allow unsynchronized access to this shared data,
- // despite Buffer's implicit position.
- ByteBuffer data = mappedData.duplicate();
- data.position(start);
+ BufferIterator data = allZoneData.bigEndianIterator();
+ data.skip(byteOffsets[index]);
// Variable names beginning tzh_ correspond to those in "tzfile.h".
// Check tzh_magic.
- if (data.getInt() != 0x545a6966) { // "TZif"
+ if (data.readInt() != 0x545a6966) { // "TZif"
return null;
}
// Skip the uninteresting part of the header.
- data.position(start + 32);
+ data.skip(28);
// Read the sizes of the arrays we're about to read.
- int tzh_timecnt = data.getInt();
- int tzh_typecnt = data.getInt();
- int tzh_charcnt = data.getInt();
+ int tzh_timecnt = data.readInt();
+ int tzh_typecnt = data.readInt();
+
+ data.skip(4); // Skip tzh_charcnt.
int[] transitions = new int[tzh_timecnt];
- for (int i = 0; i < tzh_timecnt; ++i) {
- transitions[i] = data.getInt();
- }
+ data.readIntArray(transitions, 0, transitions.length);
byte[] type = new byte[tzh_timecnt];
- data.get(type);
+ data.readByteArray(type, 0, type.length);
int[] gmtOffsets = new int[tzh_typecnt];
byte[] isDsts = new byte[tzh_typecnt];
- byte[] abbreviationIndexes = new byte[tzh_typecnt];
for (int i = 0; i < tzh_typecnt; ++i) {
- gmtOffsets[i] = data.getInt();
- isDsts[i] = data.get();
- abbreviationIndexes[i] = data.get();
+ gmtOffsets[i] = data.readInt();
+ isDsts[i] = data.readByte();
+ // We skip the abbreviation index. This would let us provide historically-accurate
+ // time zone abbreviations (such as "AHST", "YST", and "AKST" for standard time in
+ // America/Anchorage in 1982, 1983, and 1984 respectively). ICU only knows the current
+ // names, though, so even if we did use this data to provide the correct abbreviations
+ // for en_US, we wouldn't be able to provide correct abbreviations for other locales,
+ // nor would we be able to provide correct long forms (such as "Yukon Standard Time")
+ // for any locale. (The RI doesn't do any better than us here either.)
+ data.skip(1);
}
- byte[] abbreviationList = new byte[tzh_charcnt];
- data.get(abbreviationList);
-
- return new ZoneInfo(id, transitions, type, gmtOffsets, isDsts,
- abbreviationIndexes, abbreviationList);
+ return new ZoneInfo(id, transitions, type, gmtOffsets, isDsts);
}
public static String[] getAvailableIDs() {
- return (String[]) ids.clone();
+ return ids.clone();
}
public static String[] getAvailableIDs(int rawOffset) {
diff --git a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java
index 3d60a0e..b0605f2 100644
--- a/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java
+++ b/luni/src/main/java/org/apache/harmony/luni/lang/reflect/ImplForWildcard.java
@@ -59,7 +59,8 @@ public final class ImplForWildcard implements WildcardType {
@Override
public String toString() {
StringBuilder sb = new StringBuilder("?");
- if (extendsBound.length() > 0) {
+ if ((extendsBound.length() == 1 && extendsBound.getResolvedTypes()[0] != Object.class)
+ || extendsBound.length() > 1) {
sb.append(" extends ").append(extendsBound);
} else if (superBound.length() > 0) {
sb.append(" super ").append(superBound);
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
index a210a0b..8fa73e0 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainDatagramSocketImpl.java
@@ -17,6 +17,7 @@
package org.apache.harmony.luni.net;
+import dalvik.system.CloseGuard;
import java.io.FileDescriptor;
import java.io.IOException;
import java.net.DatagramPacket;
@@ -28,7 +29,7 @@ import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
-import org.apache.harmony.luni.platform.INetworkSystem;
+import libcore.base.EmptyArray;
import org.apache.harmony.luni.platform.Platform;
/**
@@ -43,19 +44,11 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
private static final int SO_BROADCAST = 32;
- static final int TCP_NODELAY = 4;
-
final static int IP_MULTICAST_TTL = 17;
- private byte[] ipaddress = { 0, 0, 0, 0 };
-
- private INetworkSystem netImpl = Platform.getNetworkSystem();
-
private volatile boolean isNativeConnected;
- private boolean streaming = true;
-
- private boolean shutdownInput;
+ private final CloseGuard guard = CloseGuard.get();
/**
* used to keep address to which the socket was connected to at the native
@@ -69,6 +62,9 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
super();
this.fd = fd;
this.localPort = localPort;
+ if (fd.valid()) {
+ guard.open("close");
+ }
}
public PlainDatagramSocketImpl() {
@@ -78,40 +74,38 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
@Override
public void bind(int port, InetAddress addr) throws SocketException {
- netImpl.bind(fd, addr, port);
- if (0 != port) {
+ Platform.NETWORK.bind(fd, addr, port);
+ if (port != 0) {
localPort = port;
} else {
- localPort = netImpl.getSocketLocalPort(fd);
+ localPort = Platform.NETWORK.getSocketLocalPort(fd);
}
try {
- // Ignore failures
setOption(SO_BROADCAST, Boolean.TRUE);
- } catch (IOException e) {
+ } catch (IOException ignored) {
}
}
@Override
- public void close() {
- synchronized (fd) {
- if (fd.valid()) {
- try {
- netImpl.close(fd);
- } catch (IOException e) {
- }
- fd = new FileDescriptor();
- }
+ public synchronized void close() {
+ guard.close();
+ try {
+ Platform.NETWORK.close(fd);
+ } catch (IOException ignored) {
}
}
@Override
public void create() throws SocketException {
- netImpl.socket(fd, false);
+ Platform.NETWORK.socket(fd, false);
}
@Override protected void finalize() throws Throwable {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
close();
} finally {
super.finalize();
@@ -119,12 +113,12 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
}
public Object getOption(int optID) throws SocketException {
- return netImpl.getSocketOption(fd, optID);
+ return Platform.NETWORK.getSocketOption(fd, optID);
}
@Override
public int getTimeToLive() throws IOException {
- return ((Integer) getOption(IP_MULTICAST_TTL)).intValue();
+ return (Integer) getOption(IP_MULTICAST_TTL);
}
@Override
@@ -161,15 +155,14 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
@Override
protected int peek(InetAddress sender) throws IOException {
// We don't actually want the data: we just want the DatagramPacket's filled-in address.
- byte[] bytes = new byte[0];
- DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
+ DatagramPacket packet = new DatagramPacket(EmptyArray.BYTE, 0);
int result = peekData(packet);
- netImpl.setInetAddress(sender, packet.getAddress().getAddress());
+ Platform.NETWORK.setInetAddress(sender, packet.getAddress().getAddress());
return result;
}
private void doRecv(DatagramPacket pack, boolean peek) throws IOException {
- netImpl.recv(fd, pack, pack.getData(), pack.getOffset(), pack.getLength(), peek,
+ Platform.NETWORK.recv(fd, pack, pack.getData(), pack.getOffset(), pack.getLength(), peek,
isNativeConnected);
if (isNativeConnected) {
updatePacketRecvAddress(pack);
@@ -191,11 +184,12 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
public void send(DatagramPacket packet) throws IOException {
int port = isNativeConnected ? 0 : packet.getPort();
InetAddress address = isNativeConnected ? null : packet.getAddress();
- netImpl.send(fd, packet.getData(), packet.getOffset(), packet.getLength(), port, address);
+ Platform.NETWORK.send(fd, packet.getData(), packet.getOffset(), packet.getLength(),
+ port, address);
}
public void setOption(int optID, Object val) throws SocketException {
- netImpl.setSocketOption(fd, optID, val);
+ Platform.NETWORK.setSocketOption(fd, optID, val);
}
@Override
@@ -210,7 +204,7 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
@Override
public void connect(InetAddress inetAddr, int port) throws SocketException {
- netImpl.connect(fd, inetAddr, port, 0);
+ Platform.NETWORK.connect(fd, inetAddr, port, 0);
// if we get here then we are connected at the native level
try {
@@ -227,10 +221,8 @@ public class PlainDatagramSocketImpl extends DatagramSocketImpl {
@Override
public void disconnect() {
try {
- netImpl.disconnectDatagram(fd);
- } catch (Exception e) {
- // there is currently no way to return an error so just eat any
- // exception
+ Platform.NETWORK.disconnectDatagram(fd);
+ } catch (Exception ignored) {
}
connectedPort = -1;
connectedAddress = null;
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
index 2a36fee..4952cf6 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/PlainSocketImpl.java
@@ -17,6 +17,7 @@
package org.apache.harmony.luni.net;
+import dalvik.system.CloseGuard;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
@@ -31,9 +32,10 @@ import java.net.SocketException;
import java.net.SocketImpl;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
+import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import org.apache.harmony.luni.platform.INetworkSystem;
+import org.apache.harmony.luni.platform.OSMemory;
import org.apache.harmony.luni.platform.Platform;
/**
@@ -49,16 +51,19 @@ public class PlainSocketImpl extends SocketImpl {
private static Field fdField;
- protected INetworkSystem netImpl = Platform.getNetworkSystem();
-
private boolean streaming = true;
private boolean shutdownInput;
private Proxy proxy;
+ private final CloseGuard guard = CloseGuard.get();
+
public PlainSocketImpl(FileDescriptor fd) {
this.fd = fd;
+ if (fd.valid()) {
+ guard.open("close");
+ }
}
public PlainSocketImpl(Proxy proxy) {
@@ -76,6 +81,9 @@ public class PlainSocketImpl extends SocketImpl {
this.localport = localport;
this.address = addr;
this.port = port;
+ if (fd.valid()) {
+ guard.open("close");
+ }
}
@Override
@@ -89,7 +97,7 @@ public class PlainSocketImpl extends SocketImpl {
try {
if (newImpl instanceof PlainSocketImpl) {
PlainSocketImpl newPlainSocketImpl = (PlainSocketImpl) newImpl;
- netImpl.accept(fd, newImpl, newPlainSocketImpl.getFileDescriptor());
+ Platform.NETWORK.accept(fd, newImpl, newPlainSocketImpl.getFileDescriptor());
} else {
// if newImpl is not an instance of PlainSocketImpl, use
// reflection to get/set protected fields.
@@ -97,7 +105,7 @@ public class PlainSocketImpl extends SocketImpl {
fdField = getSocketImplField("fd");
}
FileDescriptor newFd = (FileDescriptor) fdField.get(newImpl);
- netImpl.accept(fd, newImpl, newFd);
+ Platform.NETWORK.accept(fd, newImpl, newFd);
}
} catch (IllegalAccessException e) {
// empty
@@ -149,28 +157,24 @@ public class PlainSocketImpl extends SocketImpl {
if (shutdownInput) {
return 0;
}
- return Platform.getFileSystem().ioctlAvailable(fd);
+ return Platform.FILE_SYSTEM.ioctlAvailable(fd);
}
@Override
protected void bind(InetAddress address, int port) throws IOException {
- netImpl.bind(fd, address, port);
+ Platform.NETWORK.bind(fd, address, port);
this.address = address;
if (port != 0) {
this.localport = port;
} else {
- this.localport = netImpl.getSocketLocalPort(fd);
+ this.localport = Platform.NETWORK.getSocketLocalPort(fd);
}
}
@Override
- protected void close() throws IOException {
- synchronized (fd) {
- if (fd.valid()) {
- netImpl.close(fd);
- fd = new FileDescriptor();
- }
- }
+ protected synchronized void close() throws IOException {
+ guard.close();
+ Platform.NETWORK.close(fd);
}
@Override
@@ -201,7 +205,7 @@ public class PlainSocketImpl extends SocketImpl {
if (streaming && usingSocks()) {
socksConnect(anAddr, aPort, 0);
} else {
- netImpl.connect(fd, normalAddr, aPort, timeout);
+ Platform.NETWORK.connect(fd, normalAddr, aPort, timeout);
}
} catch (ConnectException e) {
throw new ConnectException(anAddr + ":" + aPort + " - " + e.getMessage());
@@ -213,11 +217,14 @@ public class PlainSocketImpl extends SocketImpl {
@Override
protected void create(boolean streaming) throws IOException {
this.streaming = streaming;
- netImpl.socket(fd, streaming);
+ Platform.NETWORK.socket(fd, streaming);
}
@Override protected void finalize() throws Throwable {
try {
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
close();
} finally {
super.finalize();
@@ -232,7 +239,7 @@ public class PlainSocketImpl extends SocketImpl {
@Override
public Object getOption(int optID) throws SocketException {
- return netImpl.getSocketOption(fd, optID);
+ return Platform.NETWORK.getSocketOption(fd, optID);
}
@Override
@@ -248,12 +255,12 @@ public class PlainSocketImpl extends SocketImpl {
// server during the bind.
return;
}
- netImpl.listen(fd, backlog);
+ Platform.NETWORK.listen(fd, backlog);
}
@Override
public void setOption(int optID, Object val) throws SocketException {
- netImpl.setSocketOption(fd, optID, val);
+ Platform.NETWORK.setSocketOption(fd, optID, val);
}
/**
@@ -278,7 +285,7 @@ public class PlainSocketImpl extends SocketImpl {
// determined by ProxySelector.
InetSocketAddress addr = (InetSocketAddress) proxy.address();
proxyName = addr.getHostName();
- if (null == proxyName) {
+ if (proxyName == null) {
proxyName = addr.getAddress().getHostAddress();
}
return InetAddress.getByName(proxyName);
@@ -290,7 +297,7 @@ public class PlainSocketImpl extends SocketImpl {
private void socksConnect(InetAddress applicationServerAddress,
int applicationServerPort, int timeout) throws IOException {
try {
- netImpl.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout);
+ Platform.NETWORK.connect(fd, socksGetServerAddress(), socksGetServerPort(), timeout);
} catch (Exception e) {
throw new SocketException("SOCKS connection failed: " + e);
}
@@ -333,7 +340,7 @@ public class PlainSocketImpl extends SocketImpl {
@Override
protected void shutdownInput() throws IOException {
shutdownInput = true;
- netImpl.shutdownInput(fd);
+ Platform.NETWORK.shutdownInput(fd);
}
/**
@@ -341,7 +348,7 @@ public class PlainSocketImpl extends SocketImpl {
*/
@Override
protected void shutdownOutput() throws IOException {
- netImpl.shutdownOutput(fd);
+ Platform.NETWORK.shutdownOutput(fd);
}
/**
@@ -349,7 +356,7 @@ public class PlainSocketImpl extends SocketImpl {
*/
private void socksBind() throws IOException {
try {
- netImpl.connect(fd, socksGetServerAddress(), socksGetServerPort(), 0);
+ Platform.NETWORK.connect(fd, socksGetServerAddress(), socksGetServerPort(), 0);
} catch (Exception e) {
throw new IOException("Unable to connect to SOCKS server: " + e);
}
@@ -366,8 +373,7 @@ public class PlainSocketImpl extends SocketImpl {
Socks4Message reply = socksReadReply();
if (reply.getCommandOrResult() != Socks4Message.RETURN_SUCCESS) {
- throw new IOException(reply.getErrorString(reply
- .getCommandOrResult()));
+ throw new IOException(reply.getErrorString(reply.getCommandOrResult()));
}
// A peculiarity of socks 4 - if the address returned is 0, use the
@@ -379,28 +385,16 @@ public class PlainSocketImpl extends SocketImpl {
// currently the Socks4Message.getIP() only returns int,
// so only works with IPv4 4byte addresses
byte[] replyBytes = new byte[4];
- intToBytes(reply.getIP(), replyBytes, 0);
+ OSMemory.pokeInt(replyBytes, 0, reply.getIP(), ByteOrder.BIG_ENDIAN);
address = InetAddress.getByAddress(replyBytes);
}
localport = reply.getPort();
}
- private static void intToBytes(int value, byte[] bytes, int start) {
- /*
- * Shift the int so the current byte is right-most Use a byte mask of
- * 255 to single out the last byte.
- */
- bytes[start] = (byte) ((value >> 24) & 255);
- bytes[start + 1] = (byte) ((value >> 16) & 255);
- bytes[start + 2] = (byte) ((value >> 8) & 255);
- bytes[start + 3] = (byte) (value & 255);
- }
-
/**
* Send a SOCKS V4 request.
*/
- private void socksSendRequest(int command, InetAddress address, int port)
- throws IOException {
+ private void socksSendRequest(int command, InetAddress address, int port) throws IOException {
Socks4Message request = new Socks4Message();
request.setCommandOrResult(command);
request.setPort(port);
@@ -444,18 +438,14 @@ public class PlainSocketImpl extends SocketImpl {
@Override
protected void sendUrgentData(int value) throws IOException {
- netImpl.sendUrgentData(fd, (byte) value);
- }
-
- FileDescriptor getFD() {
- return fd;
+ Platform.NETWORK.sendUrgentData(fd, (byte) value);
}
int read(byte[] buffer, int offset, int count) throws IOException {
if (shutdownInput) {
return -1;
}
- int read = netImpl.read(fd, buffer, offset, count);
+ int read = Platform.NETWORK.read(fd, buffer, offset, count);
// Return of zero bytes for a blocking socket means a timeout occurred
if (read == 0) {
throw new SocketTimeoutException();
@@ -469,9 +459,9 @@ public class PlainSocketImpl extends SocketImpl {
int write(byte[] buffer, int offset, int count) throws IOException {
if (streaming) {
- return netImpl.write(fd, buffer, offset, count);
+ return Platform.NETWORK.write(fd, buffer, offset, count);
} else {
- return netImpl.send(fd, buffer, offset, count, port, address);
+ return Platform.NETWORK.send(fd, buffer, offset, count, port, address);
}
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java b/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
index a78fb0e..2dee305 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/SocketInputStream.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import java.net.SocketImpl;
+import java.util.Arrays;
/**
* The SocketInputStream supports the streamed reading of bytes from a socket.
@@ -66,27 +67,11 @@ class SocketInputStream extends InputStream {
}
@Override
- public int read(byte[] buffer, int offset, int count) throws IOException {
- if (buffer == null) {
- throw new IOException("buffer == null");
- }
-
- if (count == 0) {
+ public int read(byte[] buffer, int offset, int byteCount) throws IOException {
+ if (byteCount == 0) {
return 0;
}
-
- if (0 > offset || offset >= buffer.length) {
- throw new ArrayIndexOutOfBoundsException("Offset out of bounds: " + offset);
- }
- if (0 > count || offset + count > buffer.length) {
- throw new ArrayIndexOutOfBoundsException();
- }
-
- return socket.read(buffer, offset, count);
- }
-
- @Override
- public long skip(long n) throws IOException {
- return (0 == n) ? 0 : super.skip(n);
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ return socket.read(buffer, offset, byteCount);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java b/luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java
index 7c7bd18..2e64d01 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/SocketOutputStream.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketImpl;
+import java.util.Arrays;
class SocketOutputStream extends OutputStream {
@@ -49,22 +50,15 @@ class SocketOutputStream extends OutputStream {
}
@Override
- public void write(byte[] buffer, int offset, int count) throws IOException {
- if (buffer == null) {
- throw new NullPointerException("buffer == null");
- }
- if (0 <= offset && offset <= buffer.length && 0 <= count && count <= buffer.length - offset) {
- socket.write(buffer, offset, count);
- } else {
- throw new ArrayIndexOutOfBoundsException();
- }
+ public void write(byte[] buffer, int offset, int byteCount) throws IOException {
+ Arrays.checkOffsetAndCount(buffer.length, offset, byteCount);
+ socket.write(buffer, offset, byteCount);
}
@Override
public void write(int oneByte) throws IOException {
byte[] buffer = new byte[1];
buffer[0] = (byte) (oneByte & 0xFF);
-
socket.write(buffer, 0, 1);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java b/luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java
index efd0fce..065e205 100644
--- a/luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java
+++ b/luni/src/main/java/org/apache/harmony/luni/net/Socks4Message.java
@@ -17,7 +17,9 @@
package org.apache.harmony.luni.net;
+import java.nio.ByteOrder;
import java.nio.charset.Charsets;
+import org.apache.harmony.luni.platform.OSMemory;
class Socks4Message {
static final int COMMAND_CONNECT = 1;
@@ -76,21 +78,21 @@ class Socks4Message {
* Returns the request's port number.
*/
public int getPort() {
- return getInt16(INDEX_PORT);
+ return OSMemory.peekShort(buffer, INDEX_PORT, ByteOrder.BIG_ENDIAN);
}
/**
* Set the request's port number.
*/
public void setPort(int port) {
- setInt16(INDEX_PORT, port);
+ OSMemory.pokeShort(buffer, INDEX_PORT, (short) port, ByteOrder.BIG_ENDIAN);
}
/**
* Returns the IP address of the request as an integer.
*/
public int getIP() {
- return getInt32(INDEX_IP);
+ return OSMemory.peekInt(buffer, INDEX_IP, ByteOrder.BIG_ENDIAN);
}
/**
@@ -178,22 +180,6 @@ class Socks4Message {
}
/**
- * Get a 16 bit integer from the buffer at the offset given.
- */
- private int getInt16(int offset) {
- return (((buffer[offset] & 0xFF) << 8) + (buffer[offset + 1] & 0xFF));
- }
-
- /**
- * Get a 32 bit integer from the buffer at the offset given.
- */
- private int getInt32(int offset) {
- return ((buffer[offset + 3] & 0xFF)
- + ((buffer[offset + 2] & 0xFF) << 8)
- + ((buffer[offset + 1] & 0xFF) << 16) + ((buffer[offset + 0] & 0xFF) << 24));
- }
-
- /**
* Get a String from the buffer at the offset given. The method reads until
* it encounters a null value or reaches the maxLength given.
*/
@@ -214,14 +200,6 @@ class Socks4Message {
}
/**
- * Put a 16 bit integer into the buffer at the offset given.
- */
- private void setInt16(int offset, int value) {
- buffer[offset] = (byte) (value >>> 8 & 0xFF);
- buffer[offset + 1] = (byte) (value & 0xFF);
- }
-
- /**
* Put a string into the buffer at the offset given.
*/
private void setString(int offset, int maxLength, String theString) {
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
index 08f1453..46a8b0e 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/IFileSystem.java
@@ -98,7 +98,7 @@ public interface IFileSystem {
/**
* Returns the granularity for virtual memory allocation.
*/
- public int getAllocGranularity() throws IOException;
+ public int getAllocGranularity();
public int open(String path, int mode) throws FileNotFoundException;
@@ -112,6 +112,12 @@ public interface IFileSystem {
// BEGIN android-added
public int ioctlAvailable(FileDescriptor fileDescriptor) throws IOException;
+
+ public static class SeekPipeException extends IOException {
+ public SeekPipeException(String message) {
+ super(message);
+ }
+ }
// END android-added
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
index 24a42db..682ec3a 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/INetworkSystem.java
@@ -140,6 +140,10 @@ public interface INetworkSystem {
public void setSocketOption(FileDescriptor fd, int opt, Object optVal)
throws SocketException;
+ /**
+ * It is an error to close the same file descriptor from multiple threads
+ * concurrently.
+ */
public void close(FileDescriptor fd) throws IOException;
// TODO: change the single caller so that recv/recvDirect
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java b/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
deleted file mode 100644
index 52894b7..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// BEGIN android-note
-// address length was changed from long to int for performance reasons.
-// END android-note
-
-package org.apache.harmony.luni.platform;
-
-public class MappedPlatformAddress extends PlatformAddress {
- MappedPlatformAddress(int address, long size) {
- super(address, size);
- }
-
- public final void mmapLoad() {
- memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
- OSMemory.load(osaddr, size);
- }
-
- public final boolean mmapIsLoaded() {
- memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
- return OSMemory.isLoaded(osaddr, size);
- }
-
- public final void mmapFlush() {
- memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
- OSMemory.flush(osaddr, size);
- }
-
- public final void free() {
- if (memorySpy.free(this)){
- OSMemory.unmap(osaddr, size);
- }
- }
-
- public PlatformAddress duplicate() {
- return PlatformAddressFactory.mapOn(osaddr, size);
- }
-
- public final PlatformAddress offsetBytes(int offset) {
- return PlatformAddressFactory.mapOn(osaddr + offset, size - offset);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java b/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
index 6d4aa40..c567432 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
@@ -15,10 +15,6 @@
* limitations under the License.
*/
-// BEGIN android-note
-// address length was changed from long to int for performance reasons.
-// END android-note
-
package org.apache.harmony.luni.platform;
import java.io.IOException;
@@ -26,478 +22,150 @@ import java.nio.ByteOrder;
import java.nio.channels.FileChannel.MapMode;
/**
- * This class enables direct access to OS memory.
+ * This class enables direct access to memory.
+ *
+ * @hide - we should move this in with the NIO stuff it supports, and make it package-private again
*/
-final class OSMemory {
- /**
- * Defines the natural byte order for this machine.
- */
- public static final ByteOrder NATIVE_ORDER = ByteOrder.nativeOrder();
-
- private OSMemory() {
- }
-
- /**
- * Allocates and returns a pointer to space for a memory block of
- * <code>length</code> bytes. The space is uninitialized and may be larger
- * than the number of bytes requested; however, the guaranteed usable memory
- * block is exactly <code>length</code> bytes int.
- *
- * @param length
- * number of bytes requested.
- * @return the address of the start of the memory block.
- * @throws OutOfMemoryError
- * if the request cannot be satisfied.
- */
- public static native int malloc(int length) throws OutOfMemoryError;
-
- /**
- * Deallocates space for a memory block that was previously allocated by a
- * call to {@link #malloc(int) malloc(int)}. The number of bytes freed is
- * identical to the number of bytes acquired when the memory block was
- * allocated. If <code>address</code> is zero the method does nothing.
- * <p>
- * Freeing a pointer to a memory block that was not allocated by
- * <code>malloc()</code> has unspecified effect.
- * </p>
- *
- * @param address
- * the address of the memory block to deallocate.
- */
- public static native void free(int address);
-
- /**
- * Places <code>value</code> into first <code>length</code> bytes of the
- * memory block starting at <code>address</code>.
- * <p>
- * The behavior is unspecified if
- * <code>(address ... address + length)</code> is not wholly within the
- * range that was previously allocated using <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the address of the first memory location.
- * @param value
- * the byte value to set at each location.
- * @param length
- * the number of byte-length locations to set.
- */
- public static native void memset(int address, byte value, long length);
-
- /**
- * Copies <code>length</code> bytes from <code>srcAddress</code> to
- * <code>destAddress</code>. Where any part of the source memory block
- * and the destination memory block overlap <code>memmove()</code> ensures
- * that the original source bytes in the overlapping region are copied
- * before being overwritten.
- * <p>
- * The behavior is unspecified if
- * <code>(srcAddress ... srcAddress + length)</code> and
- * <code>(destAddress ... destAddress + length)</code> are not both wholly
- * within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param destAddress
- * the address of the destination memory block.
- * @param srcAddress
- * the address of the source memory block.
- * @param length
- * the number of bytes to move.
- */
- public static native void memmove(int destAddress, int srcAddress, long length);
-
- /**
- * Copies <code>length</code> bytes from the memory block at
- * <code>address</code> into the byte array <code>bytes</code> starting
- * at element <code>offset</code> within the byte array.
- * <p>
- * The behavior of this method is undefined if the range
- * <code>(address ... address + length)</code> is not within a memory
- * block that was allocated using {@link #malloc(int) malloc(int)}.
- * </p>
- *
- * @param address
- * the address of the OS memory block from which to copy bytes.
- * @param bytes
- * the byte array into which to copy the bytes.
- * @param offset
- * the index of the first element in <code>bytes</code> that
- * will be overwritten.
- * @param length
- * the total number of bytes to copy into the byte array.
- * @throws NullPointerException
- * if <code>bytes</code> is <code>null</code>.
- * @throws IndexOutOfBoundsException
- * if <code>offset + length > bytes.length</code>.
- */
- public static native void getByteArray(int address, byte[] bytes, int offset,
- int length) throws NullPointerException, IndexOutOfBoundsException;
-
- /**
- * Copies <code>length</code> bytes from the byte array <code>bytes</code>
- * into the memory block at <code>address</code>, starting at element
- * <code>offset</code> within the byte array.
- * <p>
- * The behavior of this method is undefined if the range
- * <code>(address ... address + length)</code> is not within a memory
- * block that was allocated using {@link #malloc(int) malloc(int)}.
- * </p>
- *
- * @param address
- * the address of the OS memory block into which to copy the
- * bytes.
- * @param bytes
- * the byte array from which to copy the bytes.
- * @param offset
- * the index of the first element in <code>bytes</code> that
- * will be read.
- * @param length
- * the total number of bytes to copy from <code>bytes</code>
- * into the memory block.
- * @throws NullPointerException
- * if <code>bytes</code> is <code>null</code>.
- * @throws IndexOutOfBoundsException
- * if <code>offset + length > bytes.length</code>.
- */
- public static native void setByteArray(int address, byte[] bytes, int offset,
- int length) throws NullPointerException, IndexOutOfBoundsException;
+public final class OSMemory {
+ private OSMemory() { }
/**
- * Copies <code>length</code> shorts from the short array <code>shorts</code>
- * into the memory block at <code>address</code>, starting at element
- * <code>offset</code> within the short array.
- * <p>
- * The behavior of this method is undefined if the range
- * <code>(address ... address + 2*length)</code> is not within a memory
- * block that was allocated using {@link #malloc(int) malloc(int)}.
- * </p>
- *
- * @param address
- * the address of the OS memory block into which to copy the
- * shorts.
- * @param shorts
- * the short array from which to copy the shorts.
- * @param offset
- * the index of the first element in <code>shorts</code> that
- * will be read.
- * @param length
- * the total number of shorts to copy from <code>shorts</code>
- * into the memory block.
- * @param swap
- * true if the shorts should be written in reverse byte order.
- * @throws NullPointerException
- * if <code>bytes</code> is <code>null</code>.
- * @throws IndexOutOfBoundsException
- * if <code>offset + length > bytes.length</code>.
+ * Used to optimize nio heap buffer bulk get operations. 'dst' must be a primitive array.
+ * 'dstOffset' is measured in units of 'sizeofElements' bytes.
*/
- public static native void setShortArray(int address, short[] shorts, int offset,
- int length, boolean swap) throws NullPointerException,
- IndexOutOfBoundsException;
+ public static native void unsafeBulkGet(Object dst, int dstOffset, int byteCount,
+ byte[] src, int srcOffset, int sizeofElements, boolean swap);
/**
- * Copies <code>length</code> ints from the int array <code>ints</code>
- * into the memory block at <code>address</code>, starting at element
- * <code>offset</code> within the int array.
- * <p>
- * The behavior of this method is undefined if the range
- * <code>(address ... address + 2*length)</code> is not within a memory
- * block that was allocated using {@link #malloc(int) malloc(int)}.
- * </p>
- *
- * @param address
- * the address of the OS memory block into which to copy the
- * ints.
- * @param ints
- * the int array from which to copy the ints.
- * @param offset
- * the index of the first element in <code>ints</code> that
- * will be read.
- * @param length
- * the total number of ints to copy from <code>ints</code>
- * into the memory block.
- * @param swap
- * true if the ints should be written in reverse byte order.
- * @throws NullPointerException
- * if <code>bytes</code> is <code>null</code>.
- * @throws IndexOutOfBoundsException
- * if <code>offset + length > bytes.length</code>.
+ * Used to optimize nio heap buffer bulk put operations. 'src' must be a primitive array.
+ * 'srcOffset' is measured in units of 'sizeofElements' bytes.
*/
- public static native void setIntArray(int address, int[] ints, int offset,
- int length, boolean swap) throws NullPointerException,
- IndexOutOfBoundsException;
+ public static native void unsafeBulkPut(byte[] dst, int dstOffset, int byteCount,
+ Object src, int srcOffset, int sizeofElements, boolean swap);
- public static native void setFloatArray(int address, float[] floats, int offset,
- int length, boolean swap) throws NullPointerException,
- IndexOutOfBoundsException;
-
- /**
- * Gets the value of the single byte at the given address.
- * <p>
- * The behavior is unspecified if <code>address</code> is not in the range
- * that was previously allocated using <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the byte.
- * @return the byte value.
- */
- public static native byte getByte(int address);
-
- /**
- * Sets the given single byte value at the given address.
- * <p>
- * The behavior is unspecified if <code>address</code> is not in the range
- * that was previously allocated using <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the address at which to set the byte value.
- * @param value
- * the value to set.
- */
- public static native void setByte(int address, byte value);
-
- /**
- * Gets the value of the signed two-byte integer stored in platform byte
- * order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 2)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the two-byte value.
- * @return the value of the two-byte integer as a Java <code>short</code>.
- */
- public static native short getShort(int address);
-
- public static short getShort(int address, ByteOrder byteOrder) {
- return (byteOrder == NATIVE_ORDER)
- ? getShort(address)
- : Short.reverseBytes(getShort(address));
- }
-
- /**
- * Sets the value of the signed two-byte integer at the given address in
- * platform byte order.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 2)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the two-byte value.
- * @param value
- * the value of the two-byte integer as a Java <code>short</code>.
- */
- public static native void setShort(int address, short value);
-
- public static void setShort(int address, short value, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- setShort(address, value);
+ public static int peekInt(byte[] src, int offset, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ return (((src[offset++] & 0xff) << 24) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset ] & 0xff) << 0));
} else {
- setShort(address, Short.reverseBytes(value));
+ return (((src[offset++] & 0xff) << 0) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset ] & 0xff) << 24));
}
}
- /**
- * Gets the value of the signed four-byte integer stored in platform
- * byte-order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 4)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the four-byte value.
- * @return the value of the four-byte integer as a Java <code>int</code>.
- */
- public static native int getInt(int address);
-
- public static int getInt(int address, ByteOrder byteOrder) {
- return (byteOrder == NATIVE_ORDER)
- ? getInt(address)
- : Integer.reverseBytes(getInt(address));
- }
-
- /**
- * Sets the value of the signed four-byte integer at the given address in
- * platform byte order.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 4)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the four-byte value.
- * @param value
- * the value of the four-byte integer as a Java <code>int</code>.
- */
- public static native void setInt(int address, int value);
-
- public static void setInt(int address, int value, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- setInt(address, value);
+ public static long peekLong(byte[] src, int offset, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ int h = ((src[offset++] & 0xff) << 24) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset++] & 0xff) << 0);
+ int l = ((src[offset++] & 0xff) << 24) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset ] & 0xff) << 0);
+ return (((long) h) << 32L) | ((long) l) & 0xffffffffL;
} else {
- setInt(address, Integer.reverseBytes(value));
+ int l = ((src[offset++] & 0xff) << 0) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset++] & 0xff) << 24);
+ int h = ((src[offset++] & 0xff) << 0) |
+ ((src[offset++] & 0xff) << 8) |
+ ((src[offset++] & 0xff) << 16) |
+ ((src[offset ] & 0xff) << 24);
+ return (((long) h) << 32L) | ((long) l) & 0xffffffffL;
}
}
- /**
- * Gets the value of the signed eight-byte integer stored in platform byte
- * order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 8)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @return the value of the eight-byte integer as a Java <code>long</code>.
- */
- public static native long getLong(int address);
-
- public static long getLong(int address, ByteOrder byteOrder) {
- return (byteOrder == NATIVE_ORDER)
- ? getLong(address)
- : Long.reverseBytes(getLong(address));
- }
-
- /**
- * Sets the value of the signed eight-byte integer at the given address in
- * the platform byte order.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 8)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @param value
- * the value of the eight-byte integer as a Java
- * <code>long</code>.
- */
- public static native void setLong(int address, long value);
-
- public static void setLong(int address, long value, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- setLong(address, value);
+ public static short peekShort(byte[] src, int offset, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ return (short) ((src[offset] << 8) | (src[offset + 1] & 0xff));
} else {
- setLong(address, Long.reverseBytes(value));
+ return (short) ((src[offset + 1] << 8) | (src[offset] & 0xff));
}
}
- /**
- * Gets the value of the IEEE754-format four-byte float stored in platform
- * byte order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 4)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @return the value of the four-byte float as a Java <code>float</code>.
- */
- public static native float getFloat(int address);
-
- public static float getFloat(int address, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- return getFloat(address);
- }
- int floatBits = Integer.reverseBytes(getInt(address));
- return Float.intBitsToFloat(floatBits);
- }
-
- /**
- * Sets the value of the IEEE754-format four-byte float stored in platform
- * byte order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 4)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @param value
- * the value of the four-byte float as a Java <code>float</code>.
- */
- public static native void setFloat(int address, float value);
-
- public static void setFloat(int address, float value, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- setFloat(address, value);
+ public static void pokeInt(byte[] dst, int offset, int value, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ dst[offset++] = (byte) ((value >> 24) & 0xff);
+ dst[offset++] = (byte) ((value >> 16) & 0xff);
+ dst[offset++] = (byte) ((value >> 8) & 0xff);
+ dst[offset ] = (byte) ((value >> 0) & 0xff);
} else {
- int floatBits = Float.floatToIntBits(value);
- setInt(address, Integer.reverseBytes(floatBits));
+ dst[offset++] = (byte) ((value >> 0) & 0xff);
+ dst[offset++] = (byte) ((value >> 8) & 0xff);
+ dst[offset++] = (byte) ((value >> 16) & 0xff);
+ dst[offset ] = (byte) ((value >> 24) & 0xff);
}
}
- /**
- * Gets the value of the IEEE754-format eight-byte float stored in platform
- * byte order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 8)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @return the value of the eight-byte float as a Java <code>double</code>.
- */
- public static native double getDouble(int address);
-
- public static double getDouble(int address, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- return getDouble(address);
+ public static void pokeLong(byte[] dst, int offset, long value, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ int i = (int) (value >> 32);
+ dst[offset++] = (byte) ((i >> 24) & 0xff);
+ dst[offset++] = (byte) ((i >> 16) & 0xff);
+ dst[offset++] = (byte) ((i >> 8) & 0xff);
+ dst[offset++] = (byte) ((i >> 0) & 0xff);
+ i = (int) value;
+ dst[offset++] = (byte) ((i >> 24) & 0xff);
+ dst[offset++] = (byte) ((i >> 16) & 0xff);
+ dst[offset++] = (byte) ((i >> 8) & 0xff);
+ dst[offset ] = (byte) ((i >> 0) & 0xff);
+ } else {
+ int i = (int) value;
+ dst[offset++] = (byte) ((i >> 0) & 0xff);
+ dst[offset++] = (byte) ((i >> 8) & 0xff);
+ dst[offset++] = (byte) ((i >> 16) & 0xff);
+ dst[offset++] = (byte) ((i >> 24) & 0xff);
+ i = (int) (value >> 32);
+ dst[offset++] = (byte) ((i >> 0) & 0xff);
+ dst[offset++] = (byte) ((i >> 8) & 0xff);
+ dst[offset++] = (byte) ((i >> 16) & 0xff);
+ dst[offset ] = (byte) ((i >> 24) & 0xff);
}
- long doubleBits = Long.reverseBytes(getLong(address));
- return Double.longBitsToDouble(doubleBits);
}
- /**
- * Sets the value of the IEEE754-format eight-byte float store in platform
- * byte order at the given address.
- * <p>
- * The behavior is unspecified if <code>(address ... address + 8)</code>
- * is not wholly within the range that was previously allocated using
- * <code>malloc()</code>.
- * </p>
- *
- * @param address
- * the platform address of the start of the eight-byte value.
- * @param value
- * the value of the eight-byte float as a Java
- * <code>double</code>.
- */
- public static native void setDouble(int address, double value);
-
- public static void setDouble(int address, double value, ByteOrder byteOrder) {
- if (byteOrder == NATIVE_ORDER) {
- setDouble(address, value);
+ public static void pokeShort(byte[] dst, int offset, short value, ByteOrder order) {
+ if (order == ByteOrder.BIG_ENDIAN) {
+ dst[offset++] = (byte) ((value >> 8) & 0xff);
+ dst[offset ] = (byte) ((value >> 0) & 0xff);
} else {
- long doubleBits = Double.doubleToLongBits(value);
- setLong(address, Long.reverseBytes(doubleBits));
+ dst[offset++] = (byte) ((value >> 0) & 0xff);
+ dst[offset ] = (byte) ((value >> 8) & 0xff);
}
}
- // "get uintptr_t"
- public static native int getAddress(int address);
-
- // "put uintptr_t"
- public static native void setAddress(int address, int value);
-
- private static native int mmapImpl(int fd, long offset, long size, int mapMode);
+ public static native void memmove(int destAddress, int srcAddress, long byteCount);
+
+ public static native byte peekByte(int address);
+ public static native int peekInt(int address, boolean swap);
+ public static native long peekLong(int address, boolean swap);
+ public static native short peekShort(int address, boolean swap);
+
+ public static native void peekByteArray(int address, byte[] dst, int dstOffset, int byteCount);
+ public static native void peekCharArray(int address, char[] dst, int dstOffset, int charCount, boolean swap);
+ public static native void peekDoubleArray(int address, double[] dst, int dstOffset, int doubleCount, boolean swap);
+ public static native void peekFloatArray(int address, float[] dst, int dstOffset, int floatCount, boolean swap);
+ public static native void peekIntArray(int address, int[] dst, int dstOffset, int intCount, boolean swap);
+ public static native void peekLongArray(int address, long[] dst, int dstOffset, int longCount, boolean swap);
+ public static native void peekShortArray(int address, short[] dst, int dstOffset, int shortCount, boolean swap);
+
+ public static native void pokeByte(int address, byte value);
+ public static native void pokeInt(int address, int value, boolean swap);
+ public static native void pokeLong(int address, long value, boolean swap);
+ public static native void pokeShort(int address, short value, boolean swap);
+
+ public static native void pokeByteArray(int address, byte[] src, int offset, int count);
+ public static native void pokeCharArray(int address, char[] src, int offset, int count, boolean swap);
+ public static native void pokeDoubleArray(int address, double[] src, int offset, int count, boolean swap);
+ public static native void pokeFloatArray(int address, float[] src, int offset, int count, boolean swap);
+ public static native void pokeIntArray(int address, int[] src, int offset, int count, boolean swap);
+ public static native void pokeLongArray(int address, long[] src, int offset, int count, boolean swap);
+ public static native void pokeShortArray(int address, short[] src, int offset, int count, boolean swap);
public static int mmap(int fd, long offset, long size, MapMode mapMode) throws IOException {
// Check just those errors mmap(2) won't detect.
@@ -512,13 +180,13 @@ final class OSMemory {
}
return mmapImpl(fd, offset, size, intMode);
}
- // END android-changed
+ private static native int mmapImpl(int fd, long offset, long size, int mapMode);
- public static native void unmap(int addr, long size);
+ public static native void munmap(int addr, long size);
public static native void load(int addr, long size);
public static native boolean isLoaded(int addr, long size);
- public static native void flush(int addr, long size);
+ public static native void msync(int addr, long size);
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java b/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java
index 62725f5..fb9caf9 100644
--- a/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java
+++ b/luni/src/main/java/org/apache/harmony/luni/platform/Platform.java
@@ -35,41 +35,13 @@ import dalvik.system.VMStack;
* @see INetworkSystem
*/
public class Platform {
- // Note: for now, we're always wrapping the filesystem with
- // BlockGuard. In the future we intend to measure this and, with
- // the arriving of upcoming method call Dalvik improvements,
- // remove a lot of the static caching in RandomAccessFile, etc.,
- // at which point we can make getFileSystem() return an unwrapped
- // filesystem in some cases so RandomAccessFiles created on
- // BlockGuard-policy-free threads have no extra overhead. But for
- // now they do: ThreadLocal lookups will be done on most VFS
- // operations, which should be relatively less than the speed of
- // the flash.
+ // BlockGuard-policy-free threads should have no extra overhead, but for
+ // now they do because ThreadLocal lookups will be done on most operations, which
+ // should be relatively less than the speed of the operation.
// TODO: measure & fix if needed.
- private static final IFileSystem FILE_SYSTEM =
+ public static final IFileSystem FILE_SYSTEM =
new BlockGuard.WrappedFileSystem(OSFileSystem.getOSFileSystem());
- private static final INetworkSystem NETWORK_SYSTEM =
+ public static final INetworkSystem NETWORK =
new BlockGuard.WrappedNetworkSystem(OSNetworkSystem.getOSNetworkSystem());
-
- /**
- * Checks to ensure that whoever is asking for the OS component is running
- * on the system classpath.
- */
- private static final void accessCheck() {
- if (VMStack.getCallingClassLoader() != null) {
- throw new SecurityException();
- }
- }
-
- public static IFileSystem getFileSystem() {
- accessCheck();
- return FILE_SYSTEM;
- }
-
- public static INetworkSystem getNetworkSystem() {
- accessCheck();
- // TODO: use BlockGuard here too, like in getFileSystem() above.
- return NETWORK_SYSTEM;
- }
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
deleted file mode 100644
index 5dd0337..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// BEGIN android-note
-// address length was changed from long to int for performance reasons.
-// END android-note
-
-package org.apache.harmony.luni.platform;
-
-import java.nio.ByteOrder;
-
-/**
- * The platform address class is an unsafe virtualization of an OS memory block.
- */
-public class PlatformAddress implements Comparable {
- public static final int SIZEOF_JBYTE = 1;
- public static final int SIZEOF_JSHORT = 2;
- public static final int SIZEOF_JINT = 4;
- public static final int SIZEOF_JSIZE = 4;
- public static final int SIZEOF_JFLOAT = 4;
- public static final int SIZEOF_JLONG = 8;
- public static final int SIZEOF_JDOUBLE = 8;
-
- /**
- * This final field defines the sentinel for an unknown address value.
- */
- static final int UNKNOWN = -1;
-
- /**
- * NULL is the canonical address with address value zero.
- */
- public static final PlatformAddress NULL = new PlatformAddress(0, 0);
-
- /**
- * INVALID is the canonical address with an invalid value
- * (i.e. a non-address).
- */
- public static final PlatformAddress INVALID = new PlatformAddress(UNKNOWN, UNKNOWN);
-
- public static final RuntimeMemorySpy memorySpy = new RuntimeMemorySpy();
-
- final int osaddr;
-
- final long size;
-
- PlatformAddress(int address, long size) {
- super();
- osaddr = address;
- this.size = size;
- }
-
- /**
- * Sending auto free to an address means that, when this subsystem has
- * allocated the memory, it will automatically be freed when this object is
- * collected by the garbage collector if the memory has not already been
- * freed explicitly.
- *
- */
- public final void autoFree() {
- memorySpy.autoFree(this);
- }
-
- public PlatformAddress duplicate() {
- return PlatformAddressFactory.on(osaddr, size);
- }
-
- public PlatformAddress offsetBytes(int offset) {
- return PlatformAddressFactory.on(osaddr + offset, size - offset);
- }
-
- public final void moveTo(PlatformAddress dst, long numBytes) {
- OSMemory.memmove(dst.osaddr, osaddr, numBytes);
- }
-
- public final boolean equals(Object other) {
- return (other instanceof PlatformAddress)
- && (((PlatformAddress) other).osaddr == osaddr);
- }
-
- public final int hashCode() {
- return (int) osaddr;
- }
-
- public final boolean isNULL() {
- return this == NULL;
- }
-
- public void free() {
- // Memory spys can veto the basic free if they determine the memory was
- // not allocated.
- if (memorySpy.free(this)) {
- OSMemory.free(osaddr);
- }
- }
-
- public final void setAddress(int offset, PlatformAddress address) {
- OSMemory.setAddress(osaddr + offset, address.osaddr);
- }
-
- public final PlatformAddress getAddress(int offset) {
- int addr = getInt(offset);
- return PlatformAddressFactory.on(addr);
- }
-
- public final void setByte(int offset, byte value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JBYTE);
- OSMemory.setByte(osaddr + offset, value);
- }
-
- public final void setByteArray(int offset, byte[] bytes, int bytesOffset,
- int length) {
- memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
- OSMemory.setByteArray(osaddr + offset, bytes, bytesOffset, length);
- }
-
- // BEGIN android-added
- public final void setShortArray(int offset, short[] shorts,
- int shortsOffset, int length, boolean swap) {
- memorySpy.rangeCheck(this, offset, length * SIZEOF_JSHORT);
- OSMemory.setShortArray(osaddr + offset, shorts, shortsOffset, length,
- swap);
- }
-
- public final void setIntArray(int offset, int[] ints,
- int intsOffset, int length, boolean swap) {
- memorySpy.rangeCheck(this, offset, length * SIZEOF_JINT);
- OSMemory.setIntArray(osaddr + offset, ints, intsOffset, length, swap);
- }
-
- public final void setFloatArray(int offset, float[] floats,
- int floatsOffset, int length, boolean swap) {
- memorySpy.rangeCheck(this, offset, length * SIZEOF_JFLOAT);
- OSMemory.setFloatArray(
- osaddr + offset, floats, floatsOffset, length, swap);
- }
- // END android-added
-
- public final byte getByte(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JBYTE);
- return OSMemory.getByte(osaddr + offset);
- }
-
- public final void getByteArray(int offset, byte[] bytes, int bytesOffset,
- int length) {
- memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
- OSMemory.getByteArray(osaddr + offset, bytes, bytesOffset, length);
- }
-
- public final void setShort(int offset, short value, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
- OSMemory.setShort(osaddr + offset, value, order);
- }
-
- public final void setShort(int offset, short value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
- OSMemory.setShort(osaddr + offset, value);
- }
-
- public final short getShort(int offset, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
- return OSMemory.getShort(osaddr + offset, order);
- }
-
- public final short getShort(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
- return OSMemory.getShort(osaddr + offset);
- }
-
- public final void setInt(int offset, int value, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
- OSMemory.setInt(osaddr + offset, value, order);
- }
-
- public final void setInt(int offset, int value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
- OSMemory.setInt(osaddr + offset, value);
- }
-
- public final int getInt(int offset, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
- return OSMemory.getInt(osaddr + offset, order);
- }
-
- public final int getInt(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
- return OSMemory.getInt(osaddr + offset);
- }
-
- public final void setLong(int offset, long value, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
- OSMemory.setLong(osaddr + offset, value, order);
- }
-
- public final void setLong(int offset, long value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
- OSMemory.setLong(osaddr + offset, value);
- }
-
- public final long getLong(int offset, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
- return OSMemory.getLong(osaddr + offset, order);
- }
-
- public final long getLong(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
- return OSMemory.getLong(osaddr + offset);
- }
-
- public final void setFloat(int offset, float value, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
- OSMemory.setFloat(osaddr + offset, value, order);
- }
-
- public final void setFloat(int offset, float value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
- OSMemory.setFloat(osaddr + offset, value);
- }
-
- public final float getFloat(int offset, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
- return OSMemory.getFloat(osaddr + offset, order);
- }
-
- public final float getFloat(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
- return OSMemory.getFloat(osaddr + offset);
- }
-
- public final void setDouble(int offset, double value, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
- OSMemory.setDouble(osaddr + offset, value, order);
- }
-
- public final void setDouble(int offset, double value) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
- OSMemory.setDouble(osaddr + offset, value);
- }
-
- public final double getDouble(int offset, ByteOrder order) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
- return OSMemory.getDouble(osaddr + offset, order);
- }
-
- public final double getDouble(int offset) {
- memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
- return OSMemory.getDouble(osaddr + offset);
- }
-
- // BEGIN android-added
- public final int toInt() {
- return osaddr;
- }
- // END android-added
-
- public final long toLong() {
- return osaddr;
- }
-
- public final String toString() {
- return "PlatformAddress[" + osaddr + "]";
- }
-
- public final long getSize() {
- return size;
- }
-
- public final int compareTo(Object other) {
- if (other == null) {
- throw new NullPointerException(); // per spec.
- }
- if (other instanceof PlatformAddress) {
- int otherPA = ((PlatformAddress) other).osaddr;
- if (osaddr == otherPA) {
- return 0;
- }
- return osaddr < otherPA ? -1 : 1;
- }
-
- throw new ClassCastException(); // per spec.
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java b/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
deleted file mode 100644
index 86df02d..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// BEGIN android-note
-// address length was changed from long to int for performance reasons.
-// END android-note
-
-package org.apache.harmony.luni.platform;
-
-import java.io.IOException;
-import java.nio.channels.FileChannel.MapMode;
-
-public class PlatformAddressFactory {
-
- // BEGIN android-added
- /**
- * Defines the number of PlatformAddress objects to be cached. Must be a
- * power of two. Caching PlatformAddress objects minimizes the creation
- * of garbage and reduces the number of GC-hiccups in OpenGL animations.
- */
- private final static int CACHE_SIZE = 1<<8;
-
- /**
- * A mask with all bits set, matching the size of the cache.
- */
- private final static int CACHE_MASK = CACHE_SIZE - 1;
-
- /**
- * Defines the maximum number of probes taken per hash, used for looking
- * up an empty cache slot or a previously stored PlatformAddress.
- */
- private final static int MAX_PROBES = 5;
-
- /**
- * A cycling index (0 to MAX_PROBES-1) used to replace elements in
- * the cache.
- */
- private static int replacementIndex = 0;
-
- /**
- * Array of PlatformAddress references kept from garbage collection.
- */
- private static PlatformAddress[] cache = new PlatformAddress[CACHE_SIZE];
-
- /**
- * Constructs a {@code PlatformAddress} or returns
- * {@link PlatformAddress#NULL} if given a {@code null} address.
- *
- * @param address the start address for the memory; {@code 0} means
- * {@code null}
- * @param size the size of the memory in bytes
- * @return an appropriately-constructed {@code PlatformAddress}
- */
- private static PlatformAddress make(int value, long size) {
- if (value == 0) {
- return PlatformAddress.NULL;
- }
-
- return new PlatformAddress(value, size);
- }
- // END android-added
-
- // BEGIN android-changed
- public synchronized static PlatformAddress on(int value, long size) {
- if (value == 0) {
- return PlatformAddress.NULL;
- }
- int idx = value >> 5;
- for (int probe = 0; probe < MAX_PROBES; probe++) {
- PlatformAddress cachedObj = cache[(idx + probe) & CACHE_MASK];
- if (cachedObj == null) {
- return cache[(idx + probe) & CACHE_MASK] =
- new PlatformAddress(value, size);
- }
- if (cachedObj.osaddr == value && cachedObj.size == size) {
- return cachedObj;
- }
- }
- replacementIndex = (replacementIndex + 1) % MAX_PROBES;
- return cache[(idx + replacementIndex) & CACHE_MASK] =
- new PlatformAddress(value, size);
- }
- // END android-changed
-
- public static PlatformAddress on(int value) {
- return PlatformAddressFactory.on(value, PlatformAddress.UNKNOWN);
- }
-
- public static MappedPlatformAddress mapOn(int value, long size) {
- MappedPlatformAddress addr = new MappedPlatformAddress(value, size);
- return addr;
- }
-
- public static PlatformAddress allocMap(int fd, long start, long size, MapMode mode)
- throws IOException {
- if (size == 0) {
- // if size is 0, call to mmap has incorrect behaviour on
- // unix and windows, so return empty address
- return mapOn(0, 0);
- }
- int osAddress = OSMemory.mmap(fd, start, size, mode);
- PlatformAddress newMemory = mapOn(osAddress, size);
- PlatformAddress.memorySpy.alloc(newMemory);
- return newMemory;
- }
-
- /**
- * Allocates a contiguous block of OS heap memory and initializes it to
- * a given value.
- *
- * @param size The number of bytes to allocate from the system heap.
- * @param init The value to initialize the memory.
- * @return PlatformAddress representing the memory block.
- */
- public static PlatformAddress alloc(int size, byte init) {
- int osAddress = OSMemory.malloc(size);
- OSMemory.memset(osAddress, init, size);
- /*
- * We use make() and not on() here, for a couple reasons:
- * First and foremost, doing so means that if the client uses
- * address.autoFree() (to enable auto-free on gc) the cache
- * won't prevent the freeing behavior. Second, this avoids
- * polluting the cache with addresses that aren't likely to be
- * reused anyway.
- */
- PlatformAddress newMemory = make(osAddress, size);
- PlatformAddress.memorySpy.alloc(newMemory);
- return newMemory;
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java b/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
deleted file mode 100644
index 8be70c6..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.platform;
-
-import java.lang.ref.PhantomReference;
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.util.HashMap;
-import java.util.Map;
-
-final class RuntimeMemorySpy {
-
- final class AddressWrapper {
- final PlatformAddress shadow;
-
- final PhantomReference<PlatformAddress> wrAddress;
-
- volatile boolean autoFree = false;
-
- AddressWrapper(PlatformAddress address) {
- this.shadow = address.duplicate();
- this.wrAddress = new PhantomReference<PlatformAddress>(address, notifyQueue);
- }
- }
-
- // TODO: figure out how to prevent this being a synchronization bottleneck
- private final Map<PlatformAddress, AddressWrapper> memoryInUse = new HashMap<PlatformAddress, AddressWrapper>(); // Shadow to Wrapper
-
- private final Map<Reference, PlatformAddress> refToShadow = new HashMap<Reference, PlatformAddress>(); // Reference to Shadow
-
- private final ReferenceQueue<Object> notifyQueue = new ReferenceQueue<Object>();
-
- public RuntimeMemorySpy() {
- }
-
- public void alloc(PlatformAddress address) {
- // Pay a tax on the allocation to see if there are any frees pending.
- Reference ref = notifyQueue.poll(); // non-blocking check
- while (ref != null) {
- orphanedMemory(ref);
- ref = notifyQueue.poll();
- }
-
- AddressWrapper wrapper = new AddressWrapper(address);
- synchronized (this) {
- memoryInUse.put(wrapper.shadow, wrapper);
- refToShadow.put(wrapper.wrAddress, wrapper.shadow);
- }
- }
-
- // Has a veto: true == do free,false = don't
- public boolean free(PlatformAddress address) {
- AddressWrapper wrapper;
- synchronized (this) {
- wrapper = memoryInUse.remove(address);
- if (wrapper != null) {
- refToShadow.remove(wrapper.wrAddress);
- }
- }
- if (wrapper == null) {
- // Attempt to free memory we didn't alloc
- System.err.println("Memory Spy! Fixed attempt to free memory that was not allocated " + address);
- }
- return wrapper != null;
- }
-
- public void rangeCheck(PlatformAddress address, int offset, int length) throws IndexOutOfBoundsException {
- // Do nothing
- }
-
- /**
- * Requests that the given address is freed automatically when it becomes
- * garbage. If the address is already freed, or has not been notified as
- * allocated via this memory spy, then this call has no effect and completes
- * quietly.
- *
- * @param address
- * the address to be freed.
- */
- public void autoFree(PlatformAddress address) {
- AddressWrapper wrapper;
- synchronized (this) {
- wrapper = memoryInUse.get(address);
- }
- if (wrapper != null) {
- wrapper.autoFree = true;
- }
- }
-
- private void orphanedMemory(Reference ref) {
- synchronized (this) {
- PlatformAddress shadow = refToShadow.remove(ref);
- AddressWrapper wrapper = memoryInUse.get(shadow);
- if (wrapper != null) {
- // There is a leak if we were not auto-freeing this memory.
- if (!wrapper.autoFree) {
- System.err.println("Memory Spy! Fixed memory leak by freeing " + wrapper.shadow);
- }
- wrapper.shadow.free();
- }
- }
- ref.clear();
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/Base64.java b/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
index 2657867..3521b2d 100644
--- a/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
+++ b/luni/src/main/java/org/apache/harmony/luni/util/Base64.java
@@ -22,6 +22,7 @@
package org.apache.harmony.luni.util;
import java.nio.charset.Charset;
+import libcore.base.EmptyArray;
/**
* This class implements Base64 encoding/decoding functionality
@@ -40,7 +41,7 @@ public class Base64 {
int length = len / 4 * 3;
// return an empty array on empty or short input without padding
if (length == 0) {
- return new byte[0];
+ return EmptyArray.BYTE;
}
// temporary array
byte[] out = new byte[length];
@@ -103,9 +104,9 @@ public class Base64 {
quantum = (quantum << 6) | (byte) bits;
if (in_index%4 == 3) {
// 4 characters were read, so make the output:
- out[out_index++] = (byte) ((quantum & 0x00FF0000) >> 16);
- out[out_index++] = (byte) ((quantum & 0x0000FF00) >> 8);
- out[out_index++] = (byte) (quantum & 0x000000FF);
+ out[out_index++] = (byte) (quantum >> 16);
+ out[out_index++] = (byte) (quantum >> 8);
+ out[out_index++] = (byte) quantum;
}
in_index++;
}
@@ -113,9 +114,9 @@ public class Base64 {
// adjust the quantum value according to the padding
quantum = quantum << (6*pad);
// make output
- out[out_index++] = (byte) ((quantum & 0x00FF0000) >> 16);
+ out[out_index++] = (byte) (quantum >> 16);
if (pad == 1) {
- out[out_index++] = (byte) ((quantum & 0x0000FF00) >> 8);
+ out[out_index++] = (byte) (quantum >> 8);
}
}
// create the resulting array
@@ -138,10 +139,8 @@ public class Base64 {
int index = 0, i, crlr = 0, end = in.length - in.length%3;
for (i=0; i<end; i+=3) {
out[index++] = map[(in[i] & 0xff) >> 2];
- out[index++] = map[((in[i] & 0x03) << 4)
- | ((in[i+1] & 0xff) >> 4)];
- out[index++] = map[((in[i+1] & 0x0f) << 2)
- | ((in[i+2] & 0xff) >> 6)];
+ out[index++] = map[((in[i] & 0x03) << 4) | ((in[i+1] & 0xff) >> 4)];
+ out[index++] = map[((in[i+1] & 0x0f) << 2) | ((in[i+2] & 0xff) >> 6)];
out[index++] = map[(in[i+2] & 0x3f)];
if (((index - crlr)%76 == 0) && (index != 0)) {
out[index++] = '\n';
@@ -159,8 +158,7 @@ public class Base64 {
break;
case 2:
out[index++] = map[(in[end] & 0xff) >> 2];
- out[index++] = map[((in[end] & 0x03) << 4)
- | ((in[end+1] & 0xff) >> 4)];
+ out[index++] = map[((in[end] & 0x03) << 4) | ((in[end+1] & 0xff) >> 4)];
out[index++] = map[((in[end+1] & 0x0f) << 2)];
out[index++] = '=';
break;
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java b/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
index d383f9d..1feb323 100644
--- a/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
+++ b/luni/src/main/java/org/apache/harmony/luni/util/FloatingPointParser.java
@@ -24,153 +24,163 @@ package org.apache.harmony.luni.util;
*/
public final class FloatingPointParser {
- private static final class StringExponentPair {
- String s;
-
- int e;
-
- boolean negative;
-
- StringExponentPair(String s, int e, boolean negative) {
- this.s = s;
- this.e = e;
- this.negative = negative;
- }
- }
-
- /**
- * Takes a String and an integer exponent. The String should hold a positive
- * integer value (or zero). The exponent will be used to calculate the
- * floating point number by taking the positive integer the String
- * represents and multiplying by 10 raised to the power of the of the
- * exponent. Returns the closest double value to the real number
- *
- * @param s
- * the String that will be parsed to a floating point
- * @param e
- * an int represent the 10 to part
- * @return the double closest to the real number
- *
- * @exception NumberFormatException
- * if the String doesn't represent a positive integer value
- */
- private static native double parseDblImpl(String s, int e);
-
- /**
- * Takes a String and an integer exponent. The String should hold a positive
- * integer value (or zero). The exponent will be used to calculate the
- * floating point number by taking the positive integer the String
- * represents and multiplying by 10 raised to the power of the of the
- * exponent. Returns the closest float value to the real number
- *
- * @param s
- * the String that will be parsed to a floating point
- * @param e
- * an int represent the 10 to part
- * @return the float closest to the real number
- *
- * @exception NumberFormatException
- * if the String doesn't represent a positive integer value
- */
- private static native float parseFltImpl(String s, int e);
-
- /**
- * Takes a String and does some initial parsing. Should return a
- * StringExponentPair containing a String with no leading or trailing white
- * space and trailing zeroes eliminated. The exponent of the
- * StringExponentPair will be used to calculate the floating point number by
- * taking the positive integer the String represents and multiplying by 10
- * raised to the power of the of the exponent.
- *
- * @param s
- * the String that will be parsed to a floating point
- * @param length
- * the length of s
- * @return a StringExponentPair with necessary values
- *
- * @exception NumberFormatException
- * if the String doesn't pass basic tests
- */
- private static StringExponentPair initialParse(String s, int length) {
- boolean negative = false;
- char c;
- int start, end, decimal;
- int e = 0;
-
- start = 0;
- if (length == 0)
- throw new NumberFormatException(s);
-
- c = s.charAt(length - 1);
- if (c == 'D' || c == 'd' || c == 'F' || c == 'f') {
- length--;
- if (length == 0)
- throw new NumberFormatException(s);
- }
-
- end = Math.max(s.indexOf('E'), s.indexOf('e'));
- if (end > -1) {
- if (end + 1 == length)
- throw new NumberFormatException(s);
-
- int exponent_offset = end + 1;
- if (s.charAt(exponent_offset) == '+') {
- if (s.charAt(exponent_offset + 1) == '-') {
- throw new NumberFormatException(s);
- }
- exponent_offset++; // skip the plus sign
- }
- try {
- e = Integer.parseInt(s.substring(exponent_offset,
- length));
- } catch (NumberFormatException ex) {
- // ex contains the exponent substring
- // only so throw a new exception with
- // the correct string
- throw new NumberFormatException(s);
- }
-
- } else {
- end = length;
- }
- if (length == 0)
- throw new NumberFormatException(s);
-
- c = s.charAt(start);
- if (c == '-') {
- ++start;
- --length;
- negative = true;
- } else if (c == '+') {
- ++start;
- --length;
- }
- if (length == 0)
- throw new NumberFormatException(s);
-
- decimal = s.indexOf('.');
- if (decimal > -1) {
- e -= end - decimal - 1;
- s = s.substring(start, decimal) + s.substring(decimal + 1, end);
- } else {
- s = s.substring(start, end);
- }
-
- if ((length = s.length()) == 0)
- throw new NumberFormatException();
-
- end = length;
- while (end > 1 && s.charAt(end - 1) == '0')
- --end;
-
- start = 0;
- while (start < end - 1 && s.charAt(start) == '0')
- start++;
-
- if (end != length || start != 0) {
- e += length - end;
- s = s.substring(start, end);
- }
+ private static final class StringExponentPair {
+ String s;
+
+ int e;
+
+ boolean negative;
+
+ StringExponentPair(String s, int e, boolean negative) {
+ this.s = s;
+ this.e = e;
+ this.negative = negative;
+ }
+ }
+
+ /**
+ * Takes a String and an integer exponent. The String should hold a positive
+ * integer value (or zero). The exponent will be used to calculate the
+ * floating point number by taking the positive integer the String
+ * represents and multiplying by 10 raised to the power of the of the
+ * exponent. Returns the closest double value to the real number
+ *
+ * @param s
+ * the String that will be parsed to a floating point
+ * @param e
+ * an int represent the 10 to part
+ * @return the double closest to the real number
+ *
+ * @exception NumberFormatException
+ * if the String doesn't represent a positive integer value
+ */
+ private static native double parseDblImpl(String s, int e);
+
+ /**
+ * Takes a String and an integer exponent. The String should hold a positive
+ * integer value (or zero). The exponent will be used to calculate the
+ * floating point number by taking the positive integer the String
+ * represents and multiplying by 10 raised to the power of the of the
+ * exponent. Returns the closest float value to the real number
+ *
+ * @param s
+ * the String that will be parsed to a floating point
+ * @param e
+ * an int represent the 10 to part
+ * @return the float closest to the real number
+ *
+ * @exception NumberFormatException
+ * if the String doesn't represent a positive integer value
+ */
+ private static native float parseFltImpl(String s, int e);
+
+ private static NumberFormatException invalidReal(String s, boolean isDouble) {
+ throw new NumberFormatException("Invalid " + (isDouble ? "double" : "float") + ": \"" + s + "\"");
+ }
+
+ /**
+ * Takes a String and does some initial parsing. Should return a
+ * StringExponentPair containing a String with no leading or trailing white
+ * space and trailing zeroes eliminated. The exponent of the
+ * StringExponentPair will be used to calculate the floating point number by
+ * taking the positive integer the String represents and multiplying by 10
+ * raised to the power of the of the exponent.
+ *
+ * @param s
+ * the String that will be parsed to a floating point
+ * @param length
+ * the length of s
+ * @return a StringExponentPair with necessary values
+ *
+ * @exception NumberFormatException
+ * if the String doesn't pass basic tests
+ */
+ private static StringExponentPair initialParse(String s, int length, boolean isDouble) {
+ boolean negative = false;
+ char c;
+ int start, end, decimal;
+ int e = 0;
+
+ start = 0;
+ if (length == 0) {
+ throw invalidReal(s, isDouble);
+ }
+ c = s.charAt(length - 1);
+ if (c == 'D' || c == 'd' || c == 'F' || c == 'f') {
+ length--;
+ if (length == 0) {
+ throw invalidReal(s, isDouble);
+ }
+ }
+
+ end = Math.max(s.indexOf('E'), s.indexOf('e'));
+ if (end > -1) {
+ if (end + 1 == length) {
+ throw invalidReal(s, isDouble);
+ }
+
+ int exponent_offset = end + 1;
+ if (s.charAt(exponent_offset) == '+') {
+ if (s.charAt(exponent_offset + 1) == '-') {
+ throw invalidReal(s, isDouble);
+ }
+ exponent_offset++; // skip the plus sign
+ }
+ try {
+ e = Integer.parseInt(s.substring(exponent_offset, length));
+ } catch (NumberFormatException ex) {
+ // ex contains the exponent substring
+ // only so throw a new exception with
+ // the correct string
+ throw invalidReal(s, isDouble);
+ }
+
+ } else {
+ end = length;
+ }
+ if (length == 0) {
+ throw invalidReal(s, isDouble);
+ }
+
+ c = s.charAt(start);
+ if (c == '-') {
+ ++start;
+ --length;
+ negative = true;
+ } else if (c == '+') {
+ ++start;
+ --length;
+ }
+ if (length == 0) {
+ throw invalidReal(s, isDouble);
+ }
+
+ decimal = s.indexOf('.');
+ if (decimal > -1) {
+ e -= end - decimal - 1;
+ s = s.substring(start, decimal) + s.substring(decimal + 1, end);
+ } else {
+ s = s.substring(start, end);
+ }
+
+ if ((length = s.length()) == 0) {
+ throw invalidReal(s, isDouble);
+ }
+
+ end = length;
+ while (end > 1 && s.charAt(end - 1) == '0') {
+ --end;
+ }
+
+ start = 0;
+ while (start < end - 1 && s.charAt(start) == '0') {
+ start++;
+ }
+
+ if (end != length || start != 0) {
+ e += length - end;
+ s = s.substring(start, end);
+ }
// Trim the length of very small numbers, natives can only handle down
// to E-309
@@ -183,145 +193,149 @@ public final class FloatingPointParser {
e += d;
}
- return new StringExponentPair(s, e, negative);
- }
-
- /*
- * Assumes the string is trimmed.
- */
- private static double parseDblName(String namedDouble, int length) {
- // Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
- // -Infinity.
- if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
- throw new NumberFormatException();
- }
-
- boolean negative = false;
- int cmpstart = 0;
- switch (namedDouble.charAt(0)) {
- case '-':
- negative = true; // fall through
- case '+':
- cmpstart = 1;
- default:
- }
-
- if (namedDouble.regionMatches(false, cmpstart, "Infinity", 0, 8)) {
- return negative ? Double.NEGATIVE_INFINITY
- : Float.POSITIVE_INFINITY;
- }
-
- if (namedDouble.regionMatches(false, cmpstart, "NaN", 0, 3)) {
- return Double.NaN;
- }
-
- throw new NumberFormatException();
- }
-
- /*
- * Assumes the string is trimmed.
- */
- private static float parseFltName(String namedFloat, int length) {
- // Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
- // -Infinity.
- if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
- throw new NumberFormatException();
- }
-
- boolean negative = false;
- int cmpstart = 0;
- switch (namedFloat.charAt(0)) {
- case '-':
- negative = true; // fall through
- case '+':
- cmpstart = 1;
- default:
- }
-
- if (namedFloat.regionMatches(false, cmpstart, "Infinity", 0, 8)) {
- return negative ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
- }
-
- if (namedFloat.regionMatches(false, cmpstart, "NaN", 0, 3)) {
- return Float.NaN;
- }
-
- throw new NumberFormatException();
- }
-
- /**
- * Returns the closest double value to the real number in the string.
- *
- * @param s
- * the String that will be parsed to a floating point
- * @return the double closest to the real number
- *
- * @exception NumberFormatException
- * if the String doesn't represent a double
- */
- public static double parseDouble(String s) {
- s = s.trim();
- int length = s.length();
-
- if (length == 0) {
- throw new NumberFormatException(s);
- }
-
- // See if this could be a named double
- char last = s.charAt(length - 1);
- if ((last == 'y') || (last == 'N')) {
- return parseDblName(s, length);
- }
+ return new StringExponentPair(s, e, negative);
+ }
+
+ /*
+ * Assumes the string is trimmed.
+ */
+ private static double parseDblName(String namedDouble, int length) {
+ // Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
+ // -Infinity.
+ if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
+ throw invalidReal(namedDouble, true);
+ }
+
+ boolean negative = false;
+ int i = 0;
+ char firstChar = namedDouble.charAt(i);
+ if (firstChar == '-') {
+ negative = true;
+ ++i;
+ } else if (firstChar == '+') {
+ ++i;
+ }
+
+ if (namedDouble.regionMatches(false, i, "Infinity", 0, 8)) {
+ return negative ? Double.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
+ }
+
+ if (namedDouble.regionMatches(false, i, "NaN", 0, 3)) {
+ return Double.NaN;
+ }
+
+ throw invalidReal(namedDouble, true);
+ }
+
+ /*
+ * Assumes the string is trimmed.
+ */
+ private static float parseFltName(String namedFloat, int length) {
+ // Valid strings are only +Nan, NaN, -Nan, +Infinity, Infinity,
+ // -Infinity.
+ if ((length != 3) && (length != 4) && (length != 8) && (length != 9)) {
+ throw invalidReal(namedFloat, false);
+ }
+
+ boolean negative = false;
+ int i = 0;
+ char firstChar = namedFloat.charAt(i);
+ if (firstChar == '-') {
+ negative = true;
+ ++i;
+ } else if (firstChar == '+') {
+ ++i;
+ }
+
+ if (namedFloat.regionMatches(false, i, "Infinity", 0, 8)) {
+ return negative ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;
+ }
+
+ if (namedFloat.regionMatches(false, i, "NaN", 0, 3)) {
+ return Float.NaN;
+ }
+
+ throw invalidReal(namedFloat, false);
+ }
+
+ /**
+ * Returns the closest double value to the real number in the string.
+ *
+ * @param s
+ * the String that will be parsed to a floating point
+ * @return the double closest to the real number
+ *
+ * @exception NumberFormatException
+ * if the String doesn't represent a double
+ */
+ public static double parseDouble(String s) {
+ s = s.trim();
+ int length = s.length();
+
+ if (length == 0) {
+ throw invalidReal(s, true);
+ }
+
+ // See if this could be a named double
+ char last = s.charAt(length - 1);
+ if ((last == 'y') || (last == 'N')) {
+ return parseDblName(s, length);
+ }
// See if it could be a hexadecimal representation
if (s.toLowerCase().indexOf("0x") != -1) {
return HexStringParser.parseDouble(s);
}
- StringExponentPair info = initialParse(s, length);
-
- double result = parseDblImpl(info.s, info.e);
- if (info.negative)
- result = -result;
-
- return result;
- }
-
- /**
- * Returns the closest float value to the real number in the string.
- *
- * @param s
- * the String that will be parsed to a floating point
- * @return the float closest to the real number
- *
- * @exception NumberFormatException
- * if the String doesn't represent a float
- */
- public static float parseFloat(String s) {
- s = s.trim();
- int length = s.length();
-
- if (length == 0) {
- throw new NumberFormatException(s);
- }
-
- // See if this could be a named float
- char last = s.charAt(length - 1);
- if ((last == 'y') || (last == 'N')) {
- return parseFltName(s, length);
- }
+ StringExponentPair info = initialParse(s, length, true);
+
+ double result = parseDblImpl(info.s, info.e);
+ if (Double.doubleToRawLongBits(result) == 0xffffffffffffffffL) {
+ throw invalidReal(s, true);
+ }
+ if (info.negative) {
+ result = -result;
+ }
+ return result;
+ }
+
+ /**
+ * Returns the closest float value to the real number in the string.
+ *
+ * @param s
+ * the String that will be parsed to a floating point
+ * @return the float closest to the real number
+ *
+ * @exception NumberFormatException
+ * if the String doesn't represent a float
+ */
+ public static float parseFloat(String s) {
+ s = s.trim();
+ int length = s.length();
+
+ if (length == 0) {
+ throw invalidReal(s, false);
+ }
+
+ // See if this could be a named float
+ char last = s.charAt(length - 1);
+ if ((last == 'y') || (last == 'N')) {
+ return parseFltName(s, length);
+ }
// See if it could be a hexadecimal representation
if (s.toLowerCase().indexOf("0x") != -1) {
return HexStringParser.parseFloat(s);
}
- StringExponentPair info = initialParse(s, length);
-
- float result = parseFltImpl(info.s, info.e);
- if (info.negative)
- result = -result;
-
- return result;
- }
+ StringExponentPair info = initialParse(s, length, false);
+ float result = parseFltImpl(info.s, info.e);
+ if (Float.floatToRawIntBits(result) == 0xffffffff) {
+ throw invalidReal(s, false);
+ }
+ if (info.negative) {
+ result = -result;
+ }
+ return result;
+ }
}
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java b/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java
index b37a498..8a9d148 100644
--- a/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java
+++ b/luni/src/main/java/org/apache/harmony/luni/util/HexStringParser.java
@@ -82,9 +82,8 @@ final class HexStringParser {
* Parses the hex string to a double number.
*/
public static double parseDouble(String hexString) {
- HexStringParser parser = new HexStringParser(DOUBLE_EXPONENT_WIDTH,
- DOUBLE_MANTISSA_WIDTH);
- long result = parser.parse(hexString);
+ HexStringParser parser = new HexStringParser(DOUBLE_EXPONENT_WIDTH, DOUBLE_MANTISSA_WIDTH);
+ long result = parser.parse(hexString, true);
return Double.longBitsToDouble(result);
}
@@ -92,17 +91,21 @@ final class HexStringParser {
* Parses the hex string to a float number.
*/
public static float parseFloat(String hexString) {
- HexStringParser parser = new HexStringParser(FLOAT_EXPONENT_WIDTH,
- FLOAT_MANTISSA_WIDTH);
- int result = (int) parser.parse(hexString);
+ HexStringParser parser = new HexStringParser(FLOAT_EXPONENT_WIDTH, FLOAT_MANTISSA_WIDTH);
+ int result = (int) parser.parse(hexString, false);
return Float.intBitsToFloat(result);
}
- private long parse(String hexString) {
- String[] hexSegments = getSegmentsFromHexString(hexString);
- String signStr = hexSegments[0];
- String significantStr = hexSegments[1];
- String exponentStr = hexSegments[2];
+ private long parse(String hexString, boolean isDouble) {
+ Matcher matcher = PATTERN.matcher(hexString);
+ if (!matcher.matches()) {
+ throw new NumberFormatException("Invalid hex " + (isDouble ? "double" : "float")+ ":" +
+ hexString);
+ }
+
+ String signStr = matcher.group(1);
+ String significantStr = matcher.group(2);
+ String exponentStr = matcher.group(3);
parseHexSign(signStr);
parseExponent(exponentStr);
@@ -114,23 +117,6 @@ final class HexStringParser {
}
/*
- * Analyzes the hex string and extracts the sign and digit segments.
- */
- private static String[] getSegmentsFromHexString(String hexString) {
- Matcher matcher = PATTERN.matcher(hexString);
- if (!matcher.matches()) {
- throw new NumberFormatException();
- }
-
- String[] hexSegments = new String[3];
- hexSegments[0] = matcher.group(1);
- hexSegments[1] = matcher.group(2);
- hexSegments[2] = matcher.group(3);
-
- return hexSegments;
- }
-
- /*
* Parses the sign field.
*/
private void parseHexSign(String signStr) {
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java b/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
deleted file mode 100644
index d1ceba5..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/util/InputStreamHelper.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Arrays;
-
-/**
- * The class contains static {@link java.io.InputStream} utilities.
- */
-public class InputStreamHelper {
-
- /**
- * Provides access to a protected underlying buffer of
- * <code>ByteArrayInputStream</code>.
- */
- private static final Field BAIS_BUF;
-
- /**
- * Provides access to a protected position in the underlying buffer of
- * <code>ByteArrayInputStream</code>.
- */
- private static final Field BAIS_POS;
-
- static {
- final Field[] f = new Field[2];
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- public Object run() {
- try {
- f[0] = ByteArrayInputStream.class.getDeclaredField("buf");
- f[0].setAccessible(true);
- f[1] = ByteArrayInputStream.class.getDeclaredField("pos");
- f[1].setAccessible(true);
- } catch (NoSuchFieldException nsfe) {
- throw new InternalError(nsfe.getLocalizedMessage());
- }
- return null;
- }
- });
- BAIS_BUF = f[0];
- BAIS_POS = f[1];
- }
-
- /**
- * The extension of <code>ByteArrayInputStream</code> which exposes an
- * underlying buffer.
- */
- static class ExposedByteArrayInputStream extends ByteArrayInputStream {
- public ExposedByteArrayInputStream(byte[] buf) {
- super(buf);
- }
-
- public ExposedByteArrayInputStream(byte[] buf, int offset, int length) {
- super(buf, offset, length);
- }
-
- /**
- * Reads the whole stream and returns the stream snapshot.
- */
- public synchronized byte[] expose() {
- if (pos == 0 && count == buf.length) {
- skip(count);
- return buf;
- }
-
- final int available = available();
- final byte[] buffer = new byte[available];
- System.arraycopy(buf, pos, buffer, 0, available);
- skip(available);
- return buffer;
- }
- }
-
- /**
- * Reads all bytes from {@link java.io.ByteArrayInputStream} using its
- * underlying buffer directly.
- *
- * @return an underlying buffer, if a current position is at the buffer
- * beginning, and an end position is at the buffer end, or a copy of
- * the underlying buffer part.
- */
- private static byte[] expose(ByteArrayInputStream bais) {
- byte[] buffer, buf;
- int pos;
- synchronized (bais) {
- int available = bais.available();
- try {
- buf = (byte[]) BAIS_BUF.get(bais);
- pos = BAIS_POS.getInt(bais);
- } catch (IllegalAccessException iae) {
- throw new InternalError(iae.getLocalizedMessage());
- }
- if (pos == 0 && available == buf.length) {
- buffer = buf;
- } else {
- buffer = new byte[available];
- System.arraycopy(buf, pos, buffer, 0, available);
- }
- bais.skip(available);
- }
- return buffer;
- }
-
- /**
- * The utility method for reading the whole input stream into a snapshot
- * buffer. To speed up the access it works with an underlying buffer for a
- * given {@link java.io.ByteArrayInputStream}.
- *
- * @param is
- * the stream to be read.
- * @return the snapshot wrapping the buffer where the bytes are read to.
- * @throws UnsupportedOperationException
- * if the input stream data cannot be exposed
- */
- public static byte[] expose(InputStream is) throws IOException,
- UnsupportedOperationException {
- if (is instanceof ExposedByteArrayInputStream) {
- return ((ExposedByteArrayInputStream) is).expose();
- }
-
- if (is.getClass().equals(ByteArrayInputStream.class)) {
- return expose((ByteArrayInputStream) is);
- }
-
- // We don't know how to do this
- throw new UnsupportedOperationException();
- }
-
- /**
- * Reads all the bytes from the given input stream.
- *
- * Calls read multiple times on the given input stream until it receives an
- * end of file marker. Returns the combined results as a byte array. Note
- * that this method may block if the underlying stream read blocks.
- *
- * @param is
- * the input stream to be read.
- * @return the content of the stream as a byte array.
- * @throws IOException
- * if a read error occurs.
- */
- public static byte[] readFullyAndClose(InputStream is) throws IOException {
-
- try {
- // Initial read
- byte[] buffer = new byte[1024];
- int count = is.read(buffer);
- int nextByte = is.read();
-
- // Did we get it all in one read?
- if (nextByte == -1) {
- return Arrays.copyOf(buffer, count);
- }
-
- // Requires additional reads
- ByteArrayOutputStream baos = new ByteArrayOutputStream(count * 2);
- baos.write(buffer, 0, count);
- baos.write(nextByte);
- while (true) {
- count = is.read(buffer);
- if (count == -1) {
- return baos.toByteArray();
- }
- baos.write(buffer, 0, count);
- }
- } finally {
- is.close();
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java b/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
deleted file mode 100644
index e1bc217..0000000
--- a/luni/src/main/java/org/apache/harmony/luni/util/ThreadLocalCache.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.util;
-
-import java.lang.ref.SoftReference;
-import java.nio.CharBuffer;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.Charsets;
-
-/**
- * The class extends the functionality of {@link java.lang.ThreadLocal} with
- * possibility of discarding the thread local storage content when a heap is
- * exhausted.
- */
-public class ThreadLocalCache<T> {
-
- private SoftReference<ThreadLocal<T>> storage = new SoftReference<ThreadLocal<T>>(
- null);
-
- private ThreadLocal<T> getThreadLocal() {
- ThreadLocal<T> tls = storage.get();
- if (tls == null) {
- tls = new ThreadLocal<T>() {
- public T initialValue() {
- return ThreadLocalCache.this.initialValue();
- }
- };
- storage = new SoftReference<ThreadLocal<T>>(tls);
- }
- return tls;
- }
-
- /**
- * Returns the initial value for the cache for the current thread.
- */
- protected T initialValue() {
- return null;
- }
-
- /**
- * Returns the thread local value of this object.
- */
- public T get() {
- return getThreadLocal().get();
- }
-
- /**
- * Sets the value of this variable for the current thread. Might be useful
- * for expanding the thread local cache.
- */
- public void set(T value) {
- getThreadLocal().set(value);
- }
-
- /**
- * Discards the cache for all threads.
- */
- public void remove() {
- storage.clear();
- }
-
- public static ThreadLocalCache<CharsetDecoder> utf8Decoder = new ThreadLocalCache<CharsetDecoder>() {
- protected CharsetDecoder initialValue() {
- return Charsets.UTF_8.newDecoder();
- }
- };
-
- public static ThreadLocalCache<CharsetEncoder> utf8Encoder = new ThreadLocalCache<CharsetEncoder>() {
- protected CharsetEncoder initialValue() {
- return Charsets.UTF_8.newEncoder();
- }
- };
-
- public static ThreadLocalCache<java.nio.ByteBuffer> byteBuffer = new ThreadLocalCache<java.nio.ByteBuffer>() {
- protected java.nio.ByteBuffer initialValue() {
- return java.nio.ByteBuffer.allocate(72); // >=
- // Manifest.LINE_LENGTH_LIMIT
- }
- };
-
- public static ThreadLocalCache<CharBuffer> charBuffer = new ThreadLocalCache<CharBuffer>() {
- protected CharBuffer initialValue() {
- return CharBuffer.allocate(72); // no specific requirement
- }
- };
-
-}
diff --git a/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java b/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java
index b7d3097..086d561 100644
--- a/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java
+++ b/luni/src/main/java/org/apache/harmony/luni/util/TwoKeyHashMap.java
@@ -127,7 +127,7 @@ public class TwoKeyHashMap<E, K, V> extends AbstractMap<String, V> {
*/
public V remove(Object key1, Object key2) {
Entry<E, K, V> e = removeEntry(key1, key2);
- return null != e ? e.value : null;
+ return (e != null) ? e.value : null;
}
/**
diff --git a/luni/src/main/java/org/apache/harmony/nio/AddressUtil.java b/luni/src/main/java/org/apache/harmony/nio/AddressUtil.java
deleted file mode 100644
index eaff193..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/AddressUtil.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- */
-
-package org.apache.harmony.nio;
-
-import java.nio.Buffer;
-import org.apache.harmony.nio.internal.DirectBuffer;
-
-public class AddressUtil {
-
- /**
- * Gets the start address of a direct buffer.
- * <p>
- * This method corresponds to the JNI function:
- *
- * <pre>
- * void* GetDirectBufferAddress(JNIEnv* env, jobject buf);
- * </pre>
- *
- * @param buf
- * the direct buffer whose address shall be returned must not be
- * <code>null</code>.
- * @return the address of the buffer given, or zero if the buffer is not a
- * direct Buffer.
- */
- public static int getDirectBufferAddress(Buffer buf) {
- if (!(buf instanceof DirectBuffer)) {
- return 0;
- }
- return ((DirectBuffer) buf).getEffectiveAddress().toInt();
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/FileChannelFactory.java b/luni/src/main/java/org/apache/harmony/nio/FileChannelFactory.java
deleted file mode 100644
index d51e8f2..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/FileChannelFactory.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- */
-
-package org.apache.harmony.nio;
-
-import java.nio.channels.FileChannel;
-import org.apache.harmony.luni.platform.IFileSystem;
-import org.apache.harmony.nio.internal.ReadOnlyFileChannel;
-import org.apache.harmony.nio.internal.ReadWriteFileChannel;
-import org.apache.harmony.nio.internal.WriteOnlyFileChannel;
-
-/**
- * A simple factory to provide a generic way to create FileChannel
- * implementation from within the java.io package.
- */
-public class FileChannelFactory {
- public static FileChannel getFileChannel(Object stream, int fd, int mode) {
- switch (mode) {
- case IFileSystem.O_RDONLY:
- return new ReadOnlyFileChannel(stream, fd);
- case IFileSystem.O_WRONLY:
- return new WriteOnlyFileChannel(stream, fd);
- case IFileSystem.O_RDWR:
- return new ReadWriteFileChannel(stream, fd);
- case IFileSystem.O_RDWRSYNC:
- return new ReadWriteFileChannel(stream, fd);
- case IFileSystem.O_APPEND:
- return new WriteOnlyFileChannel(stream, fd, true);
- default:
- throw new RuntimeException("Unknown file channel type " + mode);
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
deleted file mode 100644
index 093551a..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/DatagramChannelImpl.java
+++ /dev/null
@@ -1,747 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-// BEGIN android-note
-// In this class the address length was changed from long to int.
-// END android-note
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.ConnectException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.DatagramSocketImpl;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.channels.AlreadyConnectedException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.NotYetConnectedException;
-import java.nio.channels.spi.SelectorProvider;
-import org.apache.harmony.luni.net.PlainDatagramSocketImpl;
-import org.apache.harmony.luni.platform.FileDescriptorHandler;
-import org.apache.harmony.luni.platform.INetworkSystem;
-import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.nio.AddressUtil;
-
-/*
- * The default implementation class of java.nio.channels.DatagramChannel.
- */
-class DatagramChannelImpl extends DatagramChannel implements FileDescriptorHandler {
-
- // The singleton to do the native network operation.
- private static final INetworkSystem networkSystem = Platform.getNetworkSystem();
-
- private static final byte[] stubArray = new byte[0];
-
- // The fd to interact with native code
- private FileDescriptor fd;
-
- // Our internal DatagramSocket.
- private DatagramSocket socket = null;
-
- // The address to be connected.
- InetSocketAddress connectAddress = null;
-
- // local port
- private int localPort;
-
- // At first, uninitialized.
- boolean connected = false;
-
- // whether the socket is bound
- boolean isBound = false;
-
- private static class ReadLock {}
- private final Object readLock = new ReadLock();
-
- private static class WriteLock {}
- private final Object writeLock = new WriteLock();
-
- /*
- * Constructor
- */
- protected DatagramChannelImpl(SelectorProvider selectorProvider) throws IOException {
- super(selectorProvider);
- fd = new FileDescriptor();
- networkSystem.socket(fd, false);
- }
-
- /*
- * for native call
- */
- @SuppressWarnings("unused")
- private DatagramChannelImpl() {
- super(SelectorProvider.provider());
- fd = new FileDescriptor();
- connectAddress = new InetSocketAddress(0);
- }
-
- /*
- * Getting the internal DatagramSocket If we have not the socket, we create
- * a new one.
- */
- @Override
- synchronized public DatagramSocket socket() {
- if (null == socket) {
- socket = new DatagramSocketAdapter(new PlainDatagramSocketImpl(fd, localPort), this);
- }
- return socket;
- }
-
- /**
- * Returns the local address from the IP stack. This method should not be
- * called directly as it does not check the security policy.
- *
- * @return InetAddress the local address to which the socket is bound.
- * @see DatagramSocket
- */
- InetAddress getLocalAddress() {
- return networkSystem.getSocketLocalAddress(fd);
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#isConnected()
- */
- @Override
- synchronized public boolean isConnected() {
- return connected;
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#connect(java.net.SocketAddress)
- */
- @Override
- synchronized public DatagramChannel connect(SocketAddress address) throws IOException {
- // must open
- checkOpen();
- // status must be un-connected.
- if (connected) {
- throw new IllegalStateException();
- }
-
- // check the address
- InetSocketAddress inetSocketAddress = SocketChannelImpl.validateAddress(address);
-
- // security check
- SecurityManager sm = System.getSecurityManager();
- if (null != sm) {
- if (inetSocketAddress.getAddress().isMulticastAddress()) {
- sm.checkMulticast(inetSocketAddress.getAddress());
- } else {
- sm.checkConnect(inetSocketAddress.getAddress().getHostName(),
- inetSocketAddress.getPort());
- }
- }
-
- try {
- begin();
- networkSystem.connect(fd,
- inetSocketAddress.getAddress(), inetSocketAddress.getPort(), 0);
- } catch (ConnectException e) {
- // ConnectException means connect fail, not exception
- } finally {
- end(true);
- }
-
- // set the connected address.
- connectAddress = inetSocketAddress;
- connected = true;
- isBound = true;
- return this;
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#disconnect()
- */
- @Override
- synchronized public DatagramChannel disconnect() throws IOException {
- if (!isConnected() || !isOpen()) {
- return this;
- }
- connected = false;
- connectAddress = null;
- networkSystem.disconnectDatagram(fd);
- if (null != socket) {
- socket.disconnect();
- }
- return this;
- }
-
- @Override
- public SocketAddress receive(ByteBuffer target) throws IOException {
- FileChannelImpl.checkWritable(target);
- checkOpen();
-
- if (!isBound) {
- return null;
- }
-
- SocketAddress retAddr = null;
- try {
- begin();
-
- // receive real data packet, (not peek)
- synchronized (readLock) {
- boolean loop = isBlocking();
- if (!target.isDirect()) {
- retAddr = receiveImpl(target, loop);
- } else {
- retAddr = receiveDirectImpl(target, loop);
- }
- }
- } catch (InterruptedIOException e) {
- // this line used in Linux
- return null;
- } finally {
- end(null != retAddr);
- }
- return retAddr;
- }
-
- private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException {
- SocketAddress retAddr = null;
- DatagramPacket receivePacket;
- int oldposition = target.position();
- int received = 0;
- if (target.hasArray()) {
- receivePacket = new DatagramPacket(target.array(), target
- .position()
- + target.arrayOffset(), target.remaining());
- } else {
- receivePacket = new DatagramPacket(new byte[target.remaining()],
- target.remaining());
- }
- do {
- received = networkSystem.recv(fd, receivePacket,
- receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(),
- false, isConnected());
-
- // security check
- SecurityManager sm = System.getSecurityManager();
- if (!isConnected() && null != sm) {
- try {
- sm.checkAccept(receivePacket.getAddress().getHostAddress(),
- receivePacket.getPort());
- } catch (SecurityException e) {
- // do discard the datagram packet
- receivePacket = null;
- }
- }
- if (null != receivePacket && null != receivePacket.getAddress()) {
-
- if (received > 0) {
- if (target.hasArray()) {
- target.position(oldposition + received);
- } else {
- // copy the data of received packet
- target.put(receivePacket.getData(), 0, received);
- }
- }
- retAddr = receivePacket.getSocketAddress();
- break;
- }
- } while (loop);
- return retAddr;
- }
-
- private SocketAddress receiveDirectImpl(ByteBuffer target, boolean loop) throws IOException {
- SocketAddress retAddr = null;
- DatagramPacket receivePacket = new DatagramPacket(stubArray, 0);
- int oldposition = target.position();
- int received = 0;
- do {
- int address = AddressUtil.getDirectBufferAddress(target);
- received = networkSystem.recvDirect(fd, receivePacket, address,
- target.position(), target.remaining(), false, isConnected());
-
- // security check
- SecurityManager sm = System.getSecurityManager();
- if (!isConnected() && null != sm) {
- try {
- sm.checkAccept(receivePacket.getAddress().getHostAddress(),
- receivePacket.getPort());
- } catch (SecurityException e) {
- // do discard the datagram packet
- receivePacket = null;
- }
- }
- if (null != receivePacket && null != receivePacket.getAddress()) {
- // copy the data of received packet
- if (received > 0) {
- target.position(oldposition + received);
- }
- retAddr = receivePacket.getSocketAddress();
- break;
- }
- } while (loop);
- return retAddr;
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#send(java.nio.ByteBuffer,
- * java.net.SocketAddress)
- */
- @Override
- public int send(ByteBuffer source, SocketAddress socketAddress) throws IOException {
- // must not null
- checkNotNull(source);
- // must open
- checkOpen();
-
- // transfer socketAddress
- InetSocketAddress isa = (InetSocketAddress) socketAddress;
- if (null == isa.getAddress()) {
- throw new IOException();
- }
-
- if (isConnected()) {
- if (!connectAddress.equals(isa)) {
- throw new IllegalArgumentException();
- }
- } else {
- // not connected, check security
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- if (isa.getAddress().isMulticastAddress()) {
- sm.checkMulticast(isa.getAddress());
- } else {
- sm.checkConnect(isa.getAddress().getHostAddress(), isa.getPort());
- }
- }
- }
-
- // the return value.
- int sendCount = 0;
- try {
- begin();
- byte[] array = null;
- int length = source.remaining();
- int oldposition = source.position();
- int start = oldposition;
- if (source.isDirect()) {
- synchronized (writeLock) {
- int data_address = AddressUtil.getDirectBufferAddress(source);
- sendCount = networkSystem.sendDirect(fd, data_address, start, length,
- isa.getPort(), isa.getAddress());
- }
- } else {
- if (source.hasArray()) {
- array = source.array();
- start += source.arrayOffset();
- } else {
- array = new byte[length];
- source.get(array);
- start = 0;
- }
- synchronized (writeLock) {
- sendCount = networkSystem.send(fd, array, start, length,
- isa.getPort(), isa.getAddress());
- }
- }
- source.position(oldposition + sendCount);
- return sendCount;
- } finally {
- end(sendCount >= 0);
- }
- }
-
- @Override
- public int read(ByteBuffer target) throws IOException {
- FileChannelImpl.checkWritable(target);
- checkOpenConnected();
-
- if (!target.hasRemaining()) {
- return 0;
- }
-
- int readCount = 0;
- if (target.isDirect() || target.hasArray()) {
- readCount = readImpl(target);
- if (readCount > 0) {
- target.position(target.position() + readCount);
- }
-
- } else {
- byte[] readArray = new byte[target.remaining()];
- ByteBuffer readBuffer = ByteBuffer.wrap(readArray);
- readCount = readImpl(readBuffer);
- if (readCount > 0) {
- target.put(readArray, 0, readCount);
- }
- }
- return readCount;
- }
-
- @Override
- public long read(ByteBuffer[] targets, int offset, int length) throws IOException {
- if (length < 0 || offset < 0 || (long) length + (long) offset > targets.length) {
- throw new IndexOutOfBoundsException();
- }
-
- // status must be open and connected
- checkOpenConnected();
- int totalCount = FileChannelImpl.calculateTotalRemaining(targets, offset, length, true);
- if (totalCount == 0) {
- return 0;
- }
-
- // read data to readBuffer, and then transfer data from readBuffer to
- // targets.
- ByteBuffer readBuffer = ByteBuffer.allocate(totalCount);
- int readCount;
- readCount = readImpl(readBuffer);
- int left = readCount;
- int index = offset;
- // transfer data from readBuffer to targets
- byte[] readArray = readBuffer.array();
- while (left > 0) {
- int putLength = Math.min(targets[index].remaining(), left);
- targets[index].put(readArray, readCount - left, putLength);
- index++;
- left -= putLength;
- }
- return readCount;
- }
-
- /*
- * read from channel, and store the result in the target.
- */
- private int readImpl(ByteBuffer readBuffer) throws IOException {
- synchronized (readLock) {
- int readCount = 0;
- try {
- begin();
- int start = readBuffer.position();
- int length = readBuffer.remaining();
- if (readBuffer.isDirect()) {
- int address = AddressUtil.getDirectBufferAddress(readBuffer);
- readCount = networkSystem.recvDirect(fd, null, address, start, length,
- false, isConnected());
- } else {
- // the target is assured to have array.
- byte[] target = readBuffer.array();
- start += readBuffer.arrayOffset();
- readCount = networkSystem.recv(fd, null, target, start, length, false,
- isConnected());
- }
- return readCount;
- } catch (InterruptedIOException e) {
- // InterruptedIOException will be thrown when timeout.
- return 0;
- } finally {
- end(readCount > 0);
- }
- }
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#write(java.nio.ByteBuffer)
- */
- @Override
- public int write(ByteBuffer source) throws IOException {
- // source buffer must be not null
- checkNotNull(source);
- // status must be open and connected
- checkOpenConnected();
- // return immediately if source is full
- if (!source.hasRemaining()) {
- return 0;
- }
-
- ByteBuffer writeBuffer = null;
- byte[] writeArray = null;
- int oldposition = source.position();
- int result;
- if (source.isDirect() || source.hasArray()) {
- writeBuffer = source;
- } else {
- writeArray = new byte[source.remaining()];
- source.get(writeArray);
- writeBuffer = ByteBuffer.wrap(writeArray);
- }
- result = writeImpl(writeBuffer);
- if (result > 0) {
- source.position(oldposition + result);
- }
- return result;
- }
-
- /**
- * @see java.nio.channels.DatagramChannel#write(java.nio.ByteBuffer[], int,
- * int)
- */
- @Override
- public long write(ByteBuffer[] sources, int offset, int length) throws IOException {
- if (length < 0 || offset < 0
- || (long) length + (long) offset > sources.length) {
- throw new IndexOutOfBoundsException();
- }
-
- // status must be open and connected
- checkOpenConnected();
- int count = FileChannelImpl.calculateTotalRemaining(sources, offset, length, false);
- if (count == 0) {
- return 0;
- }
- ByteBuffer writeBuf = ByteBuffer.allocate(count);
- for (int val = offset; val < length + offset; val++) {
- ByteBuffer source = sources[val];
- int oldPosition = source.position();
- writeBuf.put(source);
- source.position(oldPosition);
- }
- writeBuf.flip();
- int result = writeImpl(writeBuf);
- int val = offset;
- int written = result;
- while (result > 0) {
- ByteBuffer source = sources[val];
- int gap = Math.min(result, source.remaining());
- source.position(source.position() + gap);
- val++;
- result -= gap;
- }
- return written;
- }
-
- /*
- * Write the source. Return the count of bytes written.
- */
- private int writeImpl(ByteBuffer buf) throws IOException {
- synchronized (writeLock) {
- int result = 0;
- try {
- begin();
- int length = buf.remaining();
- int start = buf.position();
-
- if (buf.isDirect()) {
- int address = AddressUtil.getDirectBufferAddress(buf);
- result = networkSystem.sendDirect(fd, address, start, length, 0, null);
- } else {
- // buf is assured to have array.
- start += buf.arrayOffset();
- result = networkSystem.send(fd, buf.array(), start, length, 0, null);
- }
- return result;
- } finally {
- end(result > 0);
- }
- }
- }
-
- /*
- * Do really closing action here.
- */
- @Override
- synchronized protected void implCloseSelectableChannel() throws IOException {
- connected = false;
- if (null != socket && !socket.isClosed()) {
- socket.close();
- } else {
- networkSystem.close(fd);
- }
- }
-
- @Override
- protected void implConfigureBlocking(boolean blockingMode) throws IOException {
- // Do nothing here. For real read/write operation in nonblocking mode,
- // it uses select system call. Whether a channel is blocking can be
- // decided by isBlocking() method.
- }
-
- /*
- * Status check, must be open.
- */
- private void checkOpen() throws IOException {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- }
-
- /*
- * Status check, must be open and connected, for read and write.
- */
- private void checkOpenConnected() throws IOException {
- checkOpen();
- if (!isConnected()) {
- throw new NotYetConnectedException();
- }
- }
-
- /*
- * Buffer check, must not null
- */
- private void checkNotNull(ByteBuffer source) {
- if (null == source) {
- throw new NullPointerException();
- }
- }
-
- /*
- * Get the fd for internal use.
- */
- public FileDescriptor getFD() {
- return fd;
- }
-
- /*
- * The adapter class of DatagramSocket
- */
- private static class DatagramSocketAdapter extends DatagramSocket {
-
- /*
- * The internal datagramChannelImpl.
- */
- private DatagramChannelImpl channelImpl;
-
- /*
- * Constructor initialize the datagramSocketImpl and datagramChannelImpl
- */
- DatagramSocketAdapter(DatagramSocketImpl socketimpl,
- DatagramChannelImpl channelImpl) {
- super(socketimpl);
- this.channelImpl = channelImpl;
- }
-
- /*
- * Get the internal datagramChannelImpl
- */
- @Override
- public DatagramChannel getChannel() {
- return channelImpl;
- }
-
- /**
- * @see java.net.DatagramSocket#isBound()
- */
- @Override
- public boolean isBound() {
- return channelImpl.isBound;
- }
-
- /**
- * @see java.net.DatagramSocket#isConnected()
- */
- @Override
- public boolean isConnected() {
- return channelImpl.isConnected();
- }
-
- /**
- * @see java.net.DatagramSocket#getInetAddress()
- */
- @Override
- public InetAddress getInetAddress() {
- if (null == channelImpl.connectAddress) {
- return null;
- }
- return channelImpl.connectAddress.getAddress();
- }
-
- /**
- * @see java.net.DatagramSocket#getLocalAddress()
- */
- @Override
- public InetAddress getLocalAddress() {
- return channelImpl.getLocalAddress();
- }
-
- /**
- * @see java.net.DatagramSocket#getPort()
- */
- @Override
- public int getPort() {
- if (null == channelImpl.connectAddress) {
- return -1;
- }
- return channelImpl.connectAddress.getPort();
- }
-
- /**
- * @see java.net.DatagramSocket#bind(java.net.SocketAddress)
- */
- @Override
- public void bind(SocketAddress localAddr) throws SocketException {
- if (channelImpl.isConnected()) {
- throw new AlreadyConnectedException();
- }
- super.bind(localAddr);
- channelImpl.isBound = true;
- }
-
- /**
- * @see java.net.DatagramSocket#receive(java.net.DatagramPacket)
- */
- @Override
- public void receive(DatagramPacket packet) throws IOException {
- if (!channelImpl.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- super.receive(packet);
- }
-
- /**
- * @see java.net.DatagramSocket#send(java.net.DatagramPacket)
- */
- @Override
- public void send(DatagramPacket packet) throws IOException {
- if (!channelImpl.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- super.send(packet);
- }
-
- /**
- * @see java.net.DatagramSocket#close()
- */
- @Override
- public void close() {
- synchronized (channelImpl) {
- if (channelImpl.isOpen()) {
- try {
- channelImpl.close();
- } catch (IOException e) {
- // Ignore
- }
- }
- super.close();
- }
- }
-
- /**
- * @see java.net.DatagramSocket#disconnect()
- */
- @Override
- public void disconnect() {
- try {
- channelImpl.disconnect();
- } catch (IOException e) {
- // Ignore
- }
- super.disconnect();
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java b/luni/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
deleted file mode 100644
index 58c096b..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/DirectBuffer.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.internal;
-
-import org.apache.harmony.luni.platform.PlatformAddress;
-
-public interface DirectBuffer {
-
- PlatformAddress getEffectiveAddress();
-
- PlatformAddress getBaseAddress();
-
- boolean isAddressValid();
-
- void addressValidityCheck();
-
- void free();
-
- int getByteCapacity();
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
deleted file mode 100644
index 880c4f1..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/FileChannelImpl.java
+++ /dev/null
@@ -1,636 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- *
- * Also this class was copied from a newer version of harmony.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.Closeable;
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.MappedByteBufferAdapter;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.channels.NonWritableChannelException;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.WritableByteChannel;
-import org.apache.harmony.luni.platform.IFileSystem;
-import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.luni.platform.PlatformAddress;
-import org.apache.harmony.luni.platform.PlatformAddressFactory;
-
-/*
- * The file channel impl class is the bridge between the logical channels
- * described by the NIO channel framework, and the file system implementation
- * provided by the port layer.
- *
- * This class is non-API, but implements the API of the FileChannel interface.
- */
-public abstract class FileChannelImpl extends FileChannel {
-
- // Reference to the portable file system code.
- private static final IFileSystem fileSystem = Platform.getFileSystem();
-
- private static final int ALLOC_GRANULARITY;
-
- static {
- try {
- ALLOC_GRANULARITY = fileSystem.getAllocGranularity();
- } catch (IOException e) {
- throw new Error(e);
- }
- }
-
- // Handle to the open file
- private final int handle;
-
- // The object that will track all outstanding locks on this channel.
- private final LockManager lockManager = new LockManager();
-
- private static class RepositioningLock {}
- private final Object repositioningLock = new RepositioningLock();
-
- private final Object stream;
-
- /*
- * Create a new file channel implementation class that wraps the given file
- * handle and operates in the specified mode.
- *
- */
- public FileChannelImpl(Object stream, int handle) {
- super();
- this.handle = handle;
- this.stream = stream;
- }
-
- /*
- * Helper method to throw an exception if the channel is already closed.
- * Note that we don't bother to synchronize on this test since the file may
- * be closed by operations beyond our control anyways.
- */
- protected final void openCheck() throws ClosedChannelException {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.nio.channels.spi.AbstractInterruptibleChannel#implCloseChannel()
- */
- protected void implCloseChannel() throws IOException {
- if (stream instanceof Closeable) {
- ((Closeable) stream).close();
- }
- }
-
- protected FileLock basicLock(long position, long size, boolean shared,
- boolean wait) throws IOException {
- if (position < 0 || size < 0) {
- throw new IllegalArgumentException("Lock position and size must be non-negative");
- }
- int lockType = shared ? IFileSystem.SHARED_LOCK_TYPE : IFileSystem.EXCLUSIVE_LOCK_TYPE;
- FileLock pendingLock = new FileLockImpl(this, position, size, shared);
- lockManager.addLock(pendingLock);
-
- if (fileSystem.lock(handle, position, size, lockType, wait)) {
- return pendingLock;
- }
-
- // Lock acquisition failed
- lockManager.removeLock(pendingLock);
- return null;
- }
-
- /*
- * Acquire a lock on the receiver, blocks if the lock cannot be obtained
- * immediately.
- *
- * @see java.nio.channels.FileChannel#lock(long, long, boolean)
- */
- public final FileLock lock(long position, long size, boolean shared)
- throws IOException {
- openCheck();
- FileLock resultLock = null;
- {
- boolean completed = false;
- try {
- begin();
- resultLock = basicLock(position, size, shared, true);
- completed = true;
- } finally {
- end(completed);
- }
- }
- return resultLock;
- }
-
- /*
- * Attempts to acquire the given lock, but does not block. If the lock
- * cannot be acquired the method returns null.
- *
- * @see java.nio.channels.FileChannel#tryLock(long, long, boolean)
- */
- public final FileLock tryLock(long position, long size, boolean shared)
- throws IOException {
- openCheck();
- return basicLock(position, size, shared, false);
- }
-
- /*
- * Non-API method to release a given lock on a file channel. Assumes that
- * the lock will mark itself invalid after successful unlocking.
- */
- void release(FileLock lock) throws IOException {
- openCheck();
- fileSystem.unlock(handle, lock.position(), lock.size());
- lockManager.removeLock(lock);
- }
-
- @Override public void force(boolean metadata) throws IOException {
- openCheck();
- fileSystem.fsync(handle, metadata);
- }
-
- public abstract MappedByteBuffer map(MapMode mode, long position, long size) throws IOException;
-
- protected final MappedByteBuffer mapImpl(MapMode mapMode, long position, long size)
- throws IOException {
- if (position + size > size()) {
- fileSystem.truncate(handle, position + size);
- }
- long alignment = position - position % ALLOC_GRANULARITY;
- int offset = (int) (position - alignment);
- PlatformAddress address = PlatformAddressFactory.allocMap(handle,
- alignment, size + offset, mapMode);
- return new MappedByteBufferAdapter(address, (int) size, offset, mapMode);
- }
-
- /*
- * Returns the current file position.
- */
- public long position() throws IOException {
- openCheck();
- return fileSystem.seek(handle, 0L, IFileSystem.SEEK_CUR);
- }
-
- /*
- * Sets the file pointer.
- */
- public FileChannel position(long newPosition) throws IOException {
- openCheck();
- if (newPosition < 0) {
- throw new IllegalArgumentException("New position must be non-negative");
- }
-
- synchronized (repositioningLock) {
- fileSystem.seek(handle, newPosition, IFileSystem.SEEK_SET);
- }
- return this;
- }
-
- public int read(ByteBuffer buffer, long position) throws IOException {
- FileChannelImpl.checkWritable(buffer);
- if (position < 0) {
- throw new IllegalArgumentException();
- }
- openCheck();
- if (!buffer.hasRemaining()) {
- return 0;
- }
- synchronized (repositioningLock) {
- int bytesRead = 0;
- long preReadPosition = position();
- position(position);
- try {
- bytesRead = read(buffer);
- } finally {
- position(preReadPosition);
- }
- return bytesRead;
- }
- }
-
- public int read(ByteBuffer buffer) throws IOException {
- FileChannelImpl.checkWritable(buffer);
- openCheck();
- if (!buffer.hasRemaining()) {
- return 0;
- }
- boolean completed = false;
- int bytesRead = 0;
- synchronized (repositioningLock) {
- if (buffer.isDirect()) {
- DirectBuffer directBuffer = (DirectBuffer) buffer;
- int address = directBuffer.getEffectiveAddress().toInt();
- try {
- begin();
- /*
- * if (bytesRead <= EOF) dealt by read completed = false;
- */
- bytesRead = (int) fileSystem.readDirect(handle, address,
- buffer.position(), buffer.remaining());
- completed = true;
- } finally {
- end(completed && bytesRead >= 0);
- }
- } else {
- try {
- begin();
- /*
- * if (bytesRead <= EOF) dealt by read completed = false;
- */
- bytesRead = (int) fileSystem.read(handle, buffer.array(),
- buffer.arrayOffset() + buffer.position(), buffer
- .remaining());
- completed = true;
- } finally {
- end(completed && bytesRead >= 0);
- }
- }
- if (bytesRead > 0) {
- buffer.position(buffer.position() + bytesRead);
- }
- }
- return bytesRead;
- }
-
- public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
- if (offset < 0 || length < 0 || offset + length > buffers.length) {
- throw new IndexOutOfBoundsException();
- }
- openCheck();
- int count = FileChannelImpl.calculateTotalRemaining(buffers, offset, length, true);
- if (count == 0) {
- return 0;
- }
- ByteBuffer[] directBuffers = new ByteBuffer[length];
- int[] handles = new int[length];
- int[] offsets = new int[length];
- int[] lengths = new int[length];
- for (int i = 0; i < length; i++) {
- ByteBuffer buffer = buffers[i + offset];
- if (!buffer.isDirect()) {
- buffer = ByteBuffer.allocateDirect(buffer.remaining());
- directBuffers[i] = buffer;
- offsets[i] = 0;
- } else {
- offsets[i] = buffer.position();
- }
- handles[i] = ((DirectBuffer) buffer).getEffectiveAddress().toInt();
- lengths[i] = buffer.remaining();
- }
- long bytesRead = 0;
- {
- boolean completed = false;
- try {
- begin();
- synchronized (repositioningLock) {
- bytesRead = fileSystem.readv(handle, handles, offsets,
- lengths, length);
-
- }
- completed = true;
- /*
- * if (bytesRead < EOF) //dealt by readv? completed = false;
- */
- } finally {
- end(completed);
- }
- }
- int end = offset + length;
- long bytesRemaining = bytesRead;
- for (int i = offset; i < end && bytesRemaining > 0; i++) {
- if (buffers[i].isDirect()) {
- if (lengths[i] < bytesRemaining) {
- int pos = buffers[i].limit();
- buffers[i].position(pos);
- bytesRemaining -= lengths[i];
- } else {
- int pos = (int) bytesRemaining;
- buffers[i].position(pos);
- break;
- }
- } else {
- ByteBuffer buf = directBuffers[i - offset];
- if (bytesRemaining < buf.remaining()) {
- // this is the last step.
- int pos = buf.position();
- buffers[i].put(buf);
- buffers[i].position(pos + (int) bytesRemaining);
- bytesRemaining = 0;
- } else {
- bytesRemaining -= buf.remaining();
- buffers[i].put(buf);
- }
- }
- }
- return bytesRead;
- }
-
- /*
- * Returns the current file size, as an integer number of bytes.
- */
- public long size() throws IOException {
- openCheck();
- return fileSystem.length(handle);
- }
-
- public long transferFrom(ReadableByteChannel src, long position, long count)
- throws IOException {
- openCheck();
- if (!src.isOpen()) {
- throw new ClosedChannelException();
- }
- if (position < 0 || count < 0 || count > Integer.MAX_VALUE) {
- throw new IllegalArgumentException();
- }
- if (position > size()) {
- return 0;
- }
-
- ByteBuffer buffer = null;
-
- try {
- if (src instanceof FileChannel) {
- FileChannel fileSrc = (FileChannel) src;
- long size = fileSrc.size();
- long filePosition = fileSrc.position();
- count = Math.min(count, size - filePosition);
- buffer = fileSrc.map(MapMode.READ_ONLY, filePosition, count);
- fileSrc.position(filePosition + count);
- } else {
- buffer = ByteBuffer.allocateDirect((int) count);
- src.read(buffer);
- buffer.flip();
- }
- return write(buffer, position);
- } finally {
- // unmap the buffer
- if (buffer != null) {
- // all children of FileChannelImpl currently returns
- // an instance of DirectBuffer from map() method
- ((DirectBuffer) buffer).free();
- }
- }
- }
-
- public long transferTo(long position, long count, WritableByteChannel target)
- throws IOException {
- openCheck();
- if (!target.isOpen()) {
- throw new ClosedChannelException();
- }
- if (target instanceof ReadOnlyFileChannel) {
- throw new NonWritableChannelException();
- }
- if (position < 0 || count < 0) {
- throw new IllegalArgumentException();
- }
-
- if (count == 0 || position >= size()) {
- return 0;
- }
- ByteBuffer buffer = null;
- count = Math.min(count, size() - position);
- if (target instanceof SocketChannelImpl) {
- // only socket can be transfered by system call
- return kernelTransfer(handle, ((SocketChannelImpl) target).getFD(),
- position, count);
- }
-
- try {
- buffer = map(MapMode.READ_ONLY, position, count);
- return target.write(buffer);
- } finally {
- // unmap the buffer
- if (buffer != null) {
- // all children of FileChannelImpl currently returns
- // an instance of DirectBuffer from map() method
- ((DirectBuffer) buffer).free();
- }
- }
- }
-
- private long kernelTransfer(int l, FileDescriptor fd, long position,
- long count) throws IOException {
- boolean completed = false;
- try {
- begin();
- long ret = fileSystem.transfer(l, fd, position, count);
- completed = true;
- return ret;
- } finally {
- end(completed);
- }
- }
-
- public FileChannel truncate(long size) throws IOException {
- openCheck();
- if (size < 0) {
- throw new IllegalArgumentException();
- }
- if (size < size()) {
- synchronized (repositioningLock) {
- long position = position();
- fileSystem.truncate(handle, size);
- /*
- * FIXME: currently the port library always modifies the
- * position to given size. not sure it is a bug or intended
- * behaviour, so I always reset the position to proper value as
- * Java Spec.
- */
- position(position > size ? size : position);
- }
- }
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
- */
-
- public int write(ByteBuffer buffer, long position) throws IOException {
- if (null == buffer) {
- throw new NullPointerException();
- }
- if (position < 0) {
- throw new IllegalArgumentException();
- }
- openCheck();
- if (!buffer.hasRemaining()) {
- return 0;
- }
- int bytesWritten = 0;
- synchronized (repositioningLock) {
- long preWritePosition = position();
- position(position);
- try {
- bytesWritten = writeImpl(buffer);
- } finally {
- position(preWritePosition);
- }
- }
- return bytesWritten;
- }
-
- public int write(ByteBuffer buffer) throws IOException {
- openCheck();
- return writeImpl(buffer);
- }
-
- private int writeImpl(ByteBuffer buffer) throws IOException {
- int bytesWritten;
- boolean completed = false;
- synchronized (repositioningLock) {
- if (buffer.isDirect()) {
- DirectBuffer directBuffer = (DirectBuffer) buffer;
- int address = directBuffer.getEffectiveAddress().toInt();
- try {
- begin();
- bytesWritten = (int) fileSystem.writeDirect(handle,
- address, buffer.position(), buffer.remaining());
- completed = true;
- } finally {
- end(completed);
- }
- } else {
- try {
- begin();
- bytesWritten = (int) fileSystem.write(handle, buffer
- .array(), buffer.arrayOffset() + buffer.position(),
- buffer.remaining());
- completed = true;
- } finally {
- end(completed);
- }
- }
- if (bytesWritten > 0) {
- buffer.position(buffer.position() + bytesWritten);
- }
- }
- return bytesWritten;
- }
-
- public long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
- if (offset < 0 || length < 0 || (offset + length) > buffers.length) {
- throw new IndexOutOfBoundsException();
- }
- openCheck();
- int count = FileChannelImpl.calculateTotalRemaining(buffers, offset, length, false);
- if (count == 0) {
- return 0;
- }
- int[] handles = new int[length];
- int[] offsets = new int[length];
- int[] lengths = new int[length];
- // BEGIN android-changed
- // list of allocated direct ByteBuffers to prevent them from being GC-ed
- DirectBuffer[] allocatedBufs = new DirectBuffer[length];
-
- for (int i = 0; i < length; i++) {
- ByteBuffer buffer = buffers[i + offset];
- if (!buffer.isDirect()) {
- ByteBuffer directBuffer = ByteBuffer.allocateDirect(buffer.remaining());
- directBuffer.put(buffer);
- directBuffer.flip();
- buffer = directBuffer;
- allocatedBufs[i] = (DirectBuffer) directBuffer;
- offsets[i] = 0;
- } else {
- offsets[i] = buffer.position();
- allocatedBufs[i] = null;
- }
- handles[i] = ((DirectBuffer) buffer).getEffectiveAddress().toInt();
- lengths[i] = buffer.remaining();
- }
- // END android-changed
-
- long bytesWritten = 0;
- boolean completed = false;
- synchronized (repositioningLock) {
- try {
- begin();
- bytesWritten = fileSystem.writev(handle, handles, offsets,
- lengths, length);
- completed = true;
- } finally {
- end(completed);
- // BEGIN android-added
- // free temporary direct buffers
- for (int i = 0; i < length; ++i) {
- if (allocatedBufs[i] != null) {
- allocatedBufs[i].free();
- }
- }
- // END android-added
- }
- }
-
- long bytesRemaining = bytesWritten;
- for (int i = offset; i < length + offset; i++) {
- if (bytesRemaining > buffers[i].remaining()) {
- int pos = buffers[i].limit();
- buffers[i].position(pos);
- bytesRemaining -= buffers[i].remaining();
- } else {
- int pos = buffers[i].position() + (int) bytesRemaining;
- buffers[i].position(pos);
- break;
- }
- }
- return bytesWritten;
- }
-
- static void checkWritable(ByteBuffer buffer) {
- if (buffer.isReadOnly()) {
- throw new IllegalArgumentException("read-only buffer");
- }
- }
-
- /**
- * @param copyingIn true if we're copying data into the buffers (typically
- * because the caller is a file/network read operation), false if we're
- * copying data out of the buffers (for a file/network write operation).
- */
- static int calculateTotalRemaining(ByteBuffer[] buffers, int offset, int length, boolean copyingIn) {
- int count = 0;
- for (int i = offset; i < offset + length; ++i) {
- count += buffers[i].remaining();
- if (copyingIn) {
- checkWritable(buffers[i]);
- }
- }
- return count;
- }
-
- public int getHandle() {
- return handle;
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/FileLockImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/FileLockImpl.java
deleted file mode 100644
index d3d2635..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/FileLockImpl.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-
-/**
- * The concrete implementation of an NIO file lock object.
- */
-final class FileLockImpl extends FileLock {
-
- // Remembers if this lock has been released via the API.
- private boolean isReleased = false;
-
- /**
- * Constructs a new file lock object with the given parameters.
- *
- * @param channel
- * the file channel hosting the lock.
- * @param position
- * the start position of the lock, in bytes
- * @param size
- * the length of the lock, in bytes
- * @param shared
- * whether this lock is shared (true) or exclusive (false)
- */
- public FileLockImpl(FileChannel channel, long position, long size, boolean shared) {
- super(channel, position, size, shared);
- }
-
- /**
- * Tests to see if the lock is valid. A lock can be invalidated if the
- * channel it is acquired on is closed or if it is released. (non-Javadoc)
- *
- * @see java.nio.channels.FileLock#isValid()
- */
- @Override
- public boolean isValid() {
- return !isReleased && channel().isOpen();
- }
-
- /**
- * Releases the file lock on the channel that acquired it. Releasing an
- * invalid lock has no effect.
- *
- * @see java.nio.channels.FileLock#release()
- */
- @Override
- public void release() throws IOException {
- if (!channel().isOpen()) {
- throw new ClosedChannelException();
- }
-
- if (!isReleased) {
- ((FileChannelImpl) channel()).release(this);
- isReleased = true;
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/IOUtil.java b/luni/src/main/java/org/apache/harmony/nio/internal/IOUtil.java
deleted file mode 100644
index 8a98928..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/IOUtil.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-
-/**
- * Static methods for I/O util. Used by io package and nio package.
- */
-public final class IOUtil {
-
- private static final int DEFAULT_BUFFER_SIZE = 8192;
-
- /*
- * Not designed to be instantiated.
- */
- private IOUtil() {
- super();
- }
-
- /*
- * Read method for InputStreamReader and Channels.
- */
- public static int readInputStreamReader(InputStream in, ByteBuffer bytes,
- CharBuffer chars, CharsetDecoder decoder, Object lock)
- throws IOException {
- synchronized (lock) {
- if (in != null) {
- if (chars.limit() == chars.position()) {
- fillBuf(in, bytes, chars, decoder);
- }
- if (chars.limit() == 0) {
- return -1;
- }
- return chars.get();
- }
- throw new IOException("InputStreamReader is closed");
- }
- }
-
- private static void assertArrayIndex(int arrayLength, int offset, int length) {
- if (offset < 0 || length < 0) {
- throw new IndexOutOfBoundsException("Negative index specified");
- }
- if ((long) offset + (long) length > arrayLength) {
- throw new IndexOutOfBoundsException("Size mismatch");
- }
- }
-
- /*
- * Read method for InputStreamReader and Channels.
- */
- public static int readInputStreamReader(char[] buf, int offset, int length,
- InputStream in, ByteBuffer bytes, CharBuffer chars,
- CharsetDecoder decoder, Object lock) throws IOException {
- synchronized (lock) {
- if (in != null) {
- if (length == 0) {
- return 0;
- }
- assertArrayIndex(buf.length, offset, length);
- // read at least once
- if (chars.limit() == chars.position()) {
- fillBuf(in, bytes, chars, decoder);
- }
- int position = chars.position();
- int availableChars = chars.limit() - position;
- // read at least once for one byte
- int needChars = length;
- while (availableChars < needChars) {
- System.arraycopy(chars.array(), position, buf, offset,
- availableChars);
- chars.position(position + availableChars);
- needChars -= availableChars;
- offset += availableChars;
- if (in.available() <= 0) {
- return needChars == length ? -1 : length - needChars;
- }
- fillBuf(in, bytes, chars, decoder);
- position = chars.position();
- availableChars = chars.limit();
- if (availableChars == 0) {
- return needChars == length ? -1 : length - needChars;
- }
- }
- System.arraycopy(chars.array(), position, buf, offset,
- needChars);
- chars.position(chars.position() + needChars);
- return length;
- }
- throw new IOException("InputStreamReader is closed");
- }
- }
-
- /*
- * Refill the buffer from wrapped InputStream.
- */
- private static void fillBuf(InputStream in, ByteBuffer bytes,
- CharBuffer chars, CharsetDecoder decoder) throws IOException {
- chars.clear();
- int read = 0;
- try {
- read = in.read(bytes.array());
- } catch (IOException e) {
- chars.limit(0);
- throw e;
- }
- if (read == -1) {
- chars.limit(0);
- return;
- }
- bytes.limit(read);
- boolean endOfInput = read < DEFAULT_BUFFER_SIZE;
- CoderResult result = decoder.decode(bytes, chars, endOfInput);
- if (result.isError()) {
- throw new IOException(result.toString());
- }
- bytes.clear();
- chars.flip();
- }
-
- /*
- * Write method for OutputStreamWriter and Channels.
- */
- public static void writeOutputStreamWriter(String str, int offset,
- int count, OutputStream out, ByteBuffer bytes,
- CharsetEncoder encoder, Object lock) throws IOException {
- assertArrayIndex(str.length(), offset, count);
- CharBuffer chars = CharBuffer.wrap(str, offset, count + offset);
- convert(lock, encoder, bytes, chars, out);
- }
-
- private static void checkEncoder(CharsetEncoder encoder) throws IOException {
- if (encoder == null) {
- throw new IOException("Writer is closed");
- }
- }
-
- /*
- * Write method for OutputStreamWriter and Channels.
- */
- public static void writeOutputStreamWriter(int oneChar, OutputStream out,
- ByteBuffer bytes, CharsetEncoder encoder, Object lock)
- throws IOException {
- synchronized (lock) {
- checkEncoder(encoder);
- CharBuffer chars = CharBuffer.wrap(new char[] { (char) oneChar });
- convert(lock, encoder, bytes, chars, out);
- }
- }
-
- /*
- * Write method for OutputStreamWriter and Channels.
- */
- public static void writeOutputStreamWriter(char[] buf, int offset,
- int count, OutputStream out, ByteBuffer bytes,
- CharsetEncoder encoder, Object lock) throws IOException {
- assertArrayIndex(buf.length, offset, count);
- CharBuffer chars = CharBuffer.wrap(buf, offset, count);
- convert(lock, encoder, bytes, chars, out);
- }
-
- /*
- * Flush method for OutputStreamWriter and Channels.
- */
- public static void flushOutputStreamWriter(OutputStream out,
- ByteBuffer bytes, CharsetEncoder encoder, Object lock)
- throws IOException {
- synchronized (lock) {
- checkEncoder(encoder);
- int position;
- if ((position = bytes.position()) > 0) {
- bytes.flip();
- out.write(bytes.array(), 0, position);
- bytes.clear();
- }
- out.flush();
- }
- }
-
- /*
- * Convert function used in write.
- */
- private static void convert(Object lock, CharsetEncoder encoder,
- ByteBuffer bytes, CharBuffer chars, OutputStream out)
- throws IOException {
- synchronized (lock) {
- checkEncoder(encoder);
- CoderResult result = encoder.encode(chars, bytes, true);
- while (true) {
- if (result.isError()) {
- throw new IOException(result.toString());
- } else if (result.isOverflow()) {
- // flush the output buffer
- flushOutputStreamWriter(out, bytes, encoder, lock);
- result = encoder.encode(chars, bytes, true);
- continue;
- }
- break;
- }
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/LockManager.java b/luni/src/main/java/org/apache/harmony/nio/internal/LockManager.java
deleted file mode 100644
index e1ba13d..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/LockManager.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.nio.channels.FileLock;
-import java.nio.channels.OverlappingFileLockException;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-/**
- * The lock manager is responsible for tracking acquired and pending locks on
- * the underlying file channel.
- *
- */
-final class LockManager {
- // The set of acquired and pending locks.
- private final Comparator<FileLock> lockComparator = new Comparator<FileLock>() {
- public int compare(FileLock lock1, FileLock lock2) {
- long position1 = lock1.position();
- long position2 = lock2.position();
- return position1 > position2 ? 1 : (position1 < position2 ? -1 : 0);
- }
- };
-
- private final SortedSet<FileLock> locks = new TreeSet<FileLock>(
- lockComparator);
-
- /*
- * Default Constructor.
- */
- protected LockManager() {
- super();
- }
-
- /*
- * Add a new pending lock to the manager. Throws an exception if the lock
- * would overlap an existing lock. Once the lock is acquired it remains in
- * this set as an acquired lock.
- */
- synchronized void addLock(FileLock lock)
- throws OverlappingFileLockException {
- long lockEnd = lock.position() + lock.size();
- for (Iterator<FileLock> keyItr = locks.iterator(); keyItr.hasNext();) {
- FileLock existingLock = keyItr.next();
- if (existingLock.position() > lockEnd) {
- // This, and all remaining locks, start beyond our end (so
- // cannot overlap).
- break;
- }
- if (existingLock.overlaps(lock.position(), lock.size())) {
- throw new OverlappingFileLockException();
- }
- }
- locks.add(lock);
- }
-
- /*
- * Removes an acquired lock from the lock manager. If the lock did not exist
- * in the lock manager the operation is a no-op.
- */
- synchronized void removeLock(FileLock lock) {
- locks.remove(lock);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
deleted file mode 100644
index 37c342c..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/PipeImpl.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.Closeable;
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.Pipe;
-import java.nio.channels.spi.SelectorProvider;
-import libcore.io.IoUtils;
-import org.apache.harmony.luni.platform.FileDescriptorHandler;
-
-/*
- * Implements {@link java.nio.channels.Pipe}.
- */
-final class PipeImpl extends Pipe {
- private final PipeSinkChannel sink;
- private final PipeSourceChannel source;
-
- public PipeImpl() throws IOException {
- int[] fds = new int[2];
- IoUtils.pipe(fds);
- // Which fd is used for which channel is important. Unix pipes are only guaranteed to be
- // unidirectional, and indeed are only unidirectional on Linux. See IoUtils.pipe.
- this.sink = new PipeSinkChannel(fds[1]);
- this.source = new PipeSourceChannel(fds[0]);
- }
-
- @Override public SinkChannel sink() {
- return sink;
- }
-
- @Override public SourceChannel source() {
- return source;
- }
-
- /**
- * FileChannelImpl doesn't close its fd itself; it calls close on the object it's given.
- */
- private static class FdCloser implements Closeable {
- private final FileDescriptor fd;
- private FdCloser(FileDescriptor fd) {
- this.fd = fd;
- }
- public void close() throws IOException {
- IoUtils.close(fd);
- }
- }
-
- private class PipeSourceChannel extends Pipe.SourceChannel implements FileDescriptorHandler {
- private final FileDescriptor fd;
- private final FileChannelImpl channel;
-
- private PipeSourceChannel(int fd) throws IOException {
- super(SelectorProvider.provider());
- this.fd = IoUtils.newFileDescriptor(fd);
- this.channel = new ReadOnlyFileChannel(new FdCloser(this.fd), fd);
- }
-
- @Override protected void implCloseSelectableChannel() throws IOException {
- channel.close();
- }
-
- @Override protected void implConfigureBlocking(boolean blocking) throws IOException {
- IoUtils.setBlocking(getFD(), blocking);
- }
-
- public int read(ByteBuffer buffer) throws IOException {
- return channel.read(buffer);
- }
-
- public long read(ByteBuffer[] buffers) throws IOException {
- return channel.read(buffers);
- }
-
- public long read(ByteBuffer[] buffers, int offset, int length) throws IOException {
- return channel.read(buffers, offset, length);
- }
-
- public FileDescriptor getFD() {
- return fd;
- }
- }
-
- private class PipeSinkChannel extends Pipe.SinkChannel implements FileDescriptorHandler {
- private final FileDescriptor fd;
- private final FileChannelImpl channel;
-
- private PipeSinkChannel(int fd) throws IOException {
- super(SelectorProvider.provider());
- this.fd = IoUtils.newFileDescriptor(fd);
- this.channel = new WriteOnlyFileChannel(new FdCloser(this.fd), fd);
- }
-
- @Override protected void implCloseSelectableChannel() throws IOException {
- channel.close();
- }
-
- @Override protected void implConfigureBlocking(boolean blocking) throws IOException {
- IoUtils.setBlocking(getFD(), blocking);
- }
-
- public int write(ByteBuffer buffer) throws IOException {
- return channel.write(buffer);
- }
-
- public long write(ByteBuffer[] buffers) throws IOException {
- return channel.write(buffers);
- }
-
- public long write(ByteBuffer[] buffers, int offset, int length) throws IOException {
- return channel.write(buffers, offset, length);
- }
-
- public FileDescriptor getFD() {
- return fd;
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java b/luni/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
deleted file mode 100644
index 7cd64e3..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/ReadOnlyFileChannel.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.channels.NonWritableChannelException;
-import java.nio.channels.ReadableByteChannel;
-
-public final class ReadOnlyFileChannel extends FileChannelImpl {
- public ReadOnlyFileChannel(Object stream, int handle) {
- super(stream, handle);
- }
-
- public final int write(ByteBuffer buffer, long position) throws IOException {
- if (null == buffer) {
- throw new NullPointerException();
- }
- if (position < 0) {
- throw new IllegalArgumentException();
- }
- throw new NonWritableChannelException();
- }
-
- public final int write(ByteBuffer buffer) throws IOException {
- openCheck();
- throw new NonWritableChannelException();
- }
-
- public final long write(ByteBuffer[] buffers, int offset, int length)
- throws IOException {
- if (offset < 0 || length < 0 || (offset + length) > buffers.length) {
- throw new IndexOutOfBoundsException();
- }
- openCheck();
- throw new NonWritableChannelException();
- }
-
- public final FileChannel truncate(long size) throws IOException {
- openCheck();
- if (size < 0) {
- throw new IllegalArgumentException();
- }
- throw new NonWritableChannelException();
- }
-
- public final long transferFrom(ReadableByteChannel src, long position,
- long count) throws IOException {
- openCheck();
- if (!src.isOpen()) {
- throw new ClosedChannelException();
- }
- throw new NonWritableChannelException();
- }
-
- public final MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
- openCheck();
- if (mode == null) {
- throw new NullPointerException();
- }
- if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
- throw new IllegalArgumentException();
- }
- if (mode != MapMode.READ_ONLY) {
- throw new NonWritableChannelException();
- }
- return super.mapImpl(mode, position, size);
- }
-
- @Override public final void force(boolean metadata) throws IOException {
- openCheck();
- }
-
- protected final FileLock basicLock(long position, long size,
- boolean shared, boolean wait) throws IOException {
- if (!shared) {
- throw new NonWritableChannelException();
- }
- return super.basicLock(position, size, shared, true);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/ReadWriteFileChannel.java b/luni/src/main/java/org/apache/harmony/nio/internal/ReadWriteFileChannel.java
deleted file mode 100644
index ef888b1..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/ReadWriteFileChannel.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.nio.MappedByteBuffer;
-
-public final class ReadWriteFileChannel extends FileChannelImpl {
- public ReadWriteFileChannel(Object stream, int handle) {
- super(stream, handle);
- }
-
- public final MappedByteBuffer map(MapMode mode, long position, long size) throws IOException {
- openCheck();
- if (mode == null) {
- throw new NullPointerException();
- }
- if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
- throw new IllegalArgumentException();
- }
- return mapImpl(mode, position, size);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java
deleted file mode 100644
index c6e9930..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/SelectionKeyImpl.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.nio.channels.CancelledKeyException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.AbstractSelectionKey;
-
-/**
- * Default implementation of SelectionKey
- */
-final class SelectionKeyImpl extends AbstractSelectionKey {
-
- private AbstractSelectableChannel channel;
-
- private int interestOps;
-
- private int readyOps;
-
- private SelectorImpl selector;
-
- // BEGIN android-removed
- // private int index;
- // END android-removed
-
- public SelectionKeyImpl(AbstractSelectableChannel channel, int operations,
- Object attachment, SelectorImpl selector) {
- this.channel = channel;
- interestOps = operations;
- this.selector = selector;
- attach(attachment);
- }
-
- @Override
- public SelectableChannel channel() {
- return channel;
- }
-
- @Override
- public int interestOps() {
- checkValid();
- synchronized (selector.keysLock) {
- return interestOps;
- }
- }
-
- int interestOpsNoCheck() {
- synchronized (selector.keysLock) {
- return interestOps;
- }
- }
-
- @Override
- public SelectionKey interestOps(int operations) {
- checkValid();
- if ((operations & ~(channel().validOps())) != 0) {
- throw new IllegalArgumentException();
- }
- synchronized (selector.keysLock) {
- interestOps = operations;
- // BEGIN android-removed
- // selector.modKey(this);
- // END android-removed
- }
- return this;
- }
-
- @Override
- public int readyOps() {
- checkValid();
- return readyOps;
- }
-
- @Override
- public Selector selector() {
- return selector;
- }
-
- /*
- * package private method for setting the ready operation by selector
- */
- void setReadyOps(int readyOps) {
- this.readyOps = readyOps;
- }
-
- // BEGIN android-removed
- // int getIndex() {
- // return index;
- // }
-
- // void setIndex(int index) {
- // this.index = index;
- // }
- // END android-removed
-
- private void checkValid() {
- if (!isValid()) {
- throw new CancelledKeyException();
- }
- }
-
- /**
- * Returns true if the channel for this key is connected. If the channel
- * does not need connecting, this always return true.
- */
- boolean isConnected() {
- return !(channel instanceof SocketChannel)
- || ((SocketChannel) channel).isConnected();
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
deleted file mode 100644
index 35e383f..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/SelectorImpl.java
+++ /dev/null
@@ -1,453 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.internal;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedSelectorException;
-import java.nio.channels.IllegalSelectorException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import static java.nio.channels.SelectionKey.*;
-import java.nio.channels.Selector;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.AbstractSelectionKey;
-import java.nio.channels.spi.AbstractSelector;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-import org.apache.harmony.luni.platform.FileDescriptorHandler;
-import org.apache.harmony.luni.platform.Platform;
-
-/*
- * Default implementation of java.nio.channels.Selector
- */
-final class SelectorImpl extends AbstractSelector {
-
- private static final int[] EMPTY_INT_ARRAY = new int[0];
-
- private static final FileDescriptor[] EMPTY_FILE_DESCRIPTORS_ARRAY = new FileDescriptor[0];
- private static final SelectionKeyImpl[] EMPTY_SELECTION_KEY_IMPLS_ARRAY
- = new SelectionKeyImpl[0];
-
- private static final int CONNECT_OR_WRITE = OP_CONNECT | OP_WRITE;
-
- private static final int ACCEPT_OR_READ = OP_ACCEPT | OP_READ;
-
- private static final int WAKEUP_WRITE_SIZE = 1;
-
- private static final int WAKEUP_READ_SIZE = 8;
-
- private static final int NA = 0;
-
- private static final int READABLE = 1;
-
- private static final int WRITABLE = 2;
-
- private static final int SELECT_BLOCK = -1;
-
- private static final int SELECT_NOW = 0;
-
- /**
- * Used to synchronize when a key's interest ops change.
- */
- private static class KeysLock {}
- final Object keysLock = new KeysLock();
-
- private final Set<SelectionKeyImpl> mutableKeys = new HashSet<SelectionKeyImpl>();
-
- /**
- * The unmodifiable set of keys as exposed to the user. This object is used
- * for synchronization.
- */
- private final Set<SelectionKey> unmodifiableKeys = Collections
- .<SelectionKey>unmodifiableSet(mutableKeys);
-
- private final Set<SelectionKey> mutableSelectedKeys = new HashSet<SelectionKey>();
-
- /**
- * The unmodifiable set of selectable keys as seen by the user. This object
- * is used for synchronization.
- */
- private final Set<SelectionKey> selectedKeys
- = new UnaddableSet<SelectionKey>(mutableSelectedKeys);
-
- /**
- * The pipe used to implement wakeup.
- */
- private final Pipe wakeupPipe;
-
- /**
- * File descriptors we're interested in reading from. When actively
- * selecting, the first element is always the wakeup channel's file
- * descriptor, and the other elements are user-specified file descriptors.
- * Otherwise, all elements are null.
- */
- private FileDescriptor[] readableFDs = EMPTY_FILE_DESCRIPTORS_ARRAY;
-
- /**
- * File descriptors we're interested in writing from. May be empty. When not
- * actively selecting, all elements are null.
- */
- private FileDescriptor[] writableFDs = EMPTY_FILE_DESCRIPTORS_ARRAY;
-
- /**
- * Selection keys that correspond to the concatenation of readableFDs and
- * writableFDs. This is used to interpret the results returned by select().
- * When not actively selecting, all elements are null.
- */
- private SelectionKeyImpl[] readyKeys = EMPTY_SELECTION_KEY_IMPLS_ARRAY;
-
- /**
- * Selection flags that define the ready ops on the ready keys. When not
- * actively selecting, all elements are 0. Corresponds to the ready keys
- * set.
- */
- private int[] flags = EMPTY_INT_ARRAY;
-
- public SelectorImpl(SelectorProvider selectorProvider) throws IOException {
- super(selectorProvider);
- wakeupPipe = selectorProvider.openPipe();
- wakeupPipe.source().configureBlocking(false);
- }
-
- @Override protected void implCloseSelector() throws IOException {
- wakeup();
- synchronized (this) {
- synchronized (unmodifiableKeys) {
- synchronized (selectedKeys) {
- wakeupPipe.sink().close();
- wakeupPipe.source().close();
- doCancel();
- for (SelectionKey sk : mutableKeys) {
- deregister((AbstractSelectionKey) sk);
- }
- }
- }
- }
- }
-
- @Override protected SelectionKey register(AbstractSelectableChannel channel,
- int operations, Object attachment) {
- if (!provider().equals(channel.provider())) {
- throw new IllegalSelectorException();
- }
- synchronized (this) {
- synchronized (unmodifiableKeys) {
- SelectionKeyImpl selectionKey = new SelectionKeyImpl(
- channel, operations, attachment, this);
- mutableKeys.add(selectionKey);
- return selectionKey;
- }
- }
- }
-
- @Override public synchronized Set<SelectionKey> keys() {
- closeCheck();
- return unmodifiableKeys;
- }
-
- /*
- * Checks that the receiver is not closed. If it is throws an exception.
- */
- private void closeCheck() {
- if (!isOpen()) {
- throw new ClosedSelectorException();
- }
- }
-
- @Override public int select() throws IOException {
- return selectInternal(SELECT_BLOCK);
- }
-
- @Override public int select(long timeout) throws IOException {
- if (timeout < 0) {
- throw new IllegalArgumentException();
- }
- return selectInternal((0 == timeout) ? SELECT_BLOCK : timeout);
- }
-
- @Override public int selectNow() throws IOException {
- return selectInternal(SELECT_NOW);
- }
-
- private int selectInternal(long timeout) throws IOException {
- closeCheck();
- synchronized (this) {
- synchronized (unmodifiableKeys) {
- synchronized (selectedKeys) {
- doCancel();
- boolean isBlock = (SELECT_NOW != timeout);
- int readableKeysCount = 1; // first is always the wakeup channel
- int writableKeysCount = 0;
- synchronized (keysLock) {
- for (SelectionKeyImpl key : mutableKeys) {
- int ops = key.interestOpsNoCheck();
- if ((ACCEPT_OR_READ & ops) != 0) {
- readableKeysCount++;
- }
- if ((CONNECT_OR_WRITE & ops) != 0) {
- writableKeysCount++;
- }
- }
- prepareChannels(readableKeysCount, writableKeysCount);
- }
- boolean success;
- try {
- if (isBlock) {
- begin();
- }
- success = Platform.getNetworkSystem().select(
- readableFDs, writableFDs, readableKeysCount, writableKeysCount, timeout, flags);
- } finally {
- if (isBlock) {
- end();
- }
- }
-
- int selected = success ? processSelectResult() : 0;
-
- Arrays.fill(readableFDs, null);
- Arrays.fill(writableFDs, null);
- Arrays.fill(readyKeys, null);
- Arrays.fill(flags, 0);
-
- selected -= doCancel();
-
- return selected;
- }
- }
- }
- }
-
- private int getReadyOps(SelectionKeyImpl key) {
- SelectableChannel channel = key.channel();
- return ((channel instanceof SocketChannel) && !((SocketChannel) channel).isConnectionPending()) ?
- OP_WRITE : CONNECT_OR_WRITE;
- }
-
- /**
- * Prepare the readableFDs, writableFDs, readyKeys and flags arrays in
- * preparation for a call to {@code INetworkSystem#select()}. After they're
- * used, the array elements must be cleared.
- */
- private void prepareChannels(int numReadable, int numWritable) {
- // grow each array to sufficient capacity. Always grow to at least 1.5x
- // to avoid growing too frequently
- if (readableFDs.length < numReadable) {
- int newSize = Math.max((int) (readableFDs.length * 1.5f), numReadable);
- readableFDs = new FileDescriptor[newSize];
- }
- if (writableFDs.length < numWritable) {
- int newSize = Math.max((int) (writableFDs.length * 1.5f), numWritable);
- writableFDs = new FileDescriptor[newSize];
- }
- int total = numReadable + numWritable;
- if (readyKeys.length < total) {
- int newSize = Math.max((int) (readyKeys.length * 1.5f), total);
- readyKeys = new SelectionKeyImpl[newSize];
- flags = new int[newSize];
- }
-
- // populate the FDs, including the wakeup channel
- readableFDs[0] = ((FileDescriptorHandler) wakeupPipe.source()).getFD();
- int r = 1;
- int w = 0;
- for (SelectionKeyImpl key : mutableKeys) {
- int interestOps = key.interestOpsNoCheck();
- if ((ACCEPT_OR_READ & interestOps) != 0) {
- readableFDs[r] = ((FileDescriptorHandler) key.channel()).getFD();
- readyKeys[r] = key;
- r++;
- }
- if ((getReadyOps(key) & interestOps) != 0) {
- writableFDs[w] = ((FileDescriptorHandler) key.channel()).getFD();
- readyKeys[w + numReadable] = key;
- w++;
- }
- }
- }
-
- /**
- * Updates the key ready ops and selected key set with data from the flags
- * array.
- */
- private int processSelectResult() throws IOException {
- // If there's something in the wakeup pipe, read it all --- the definition of the various
- // select methods says that one select swallows all outstanding wakeups. We made this
- // channel non-blocking in our constructor so that we can just loop until read returns 0.
- if (flags[0] == READABLE) {
- ByteBuffer buf = ByteBuffer.allocate(WAKEUP_READ_SIZE);
- while (wakeupPipe.source().read(buf) > 0) {
- buf.flip();
- }
- }
-
- int selected = 0;
- for (int i = 1; i < flags.length; i++) {
- if (flags[i] == NA) {
- continue;
- }
-
- SelectionKeyImpl key = readyKeys[i];
- int ops = key.interestOpsNoCheck();
- int selectedOp = 0;
-
- switch (flags[i]) {
- case READABLE:
- selectedOp = ACCEPT_OR_READ & ops;
- break;
- case WRITABLE:
- if (key.isConnected()) {
- selectedOp = OP_WRITE & ops;
- } else {
- selectedOp = OP_CONNECT & ops;
- }
- break;
- }
-
- if (selectedOp != 0) {
- boolean wasSelected = mutableSelectedKeys.contains(key);
- if (wasSelected && key.readyOps() != selectedOp) {
- key.setReadyOps(key.readyOps() | selectedOp);
- selected++;
- } else if (!wasSelected) {
- key.setReadyOps(selectedOp);
- mutableSelectedKeys.add(key);
- selected++;
- }
- }
- }
-
- return selected;
- }
-
- @Override public synchronized Set<SelectionKey> selectedKeys() {
- closeCheck();
- return selectedKeys;
- }
-
- /**
- * Removes cancelled keys from the key set and selected key set, and
- * deregisters the corresponding channels. Returns the number of keys
- * removed from the selected key set.
- */
- private int doCancel() {
- int deselected = 0;
-
- Set<SelectionKey> cancelledKeys = cancelledKeys();
- synchronized (cancelledKeys) {
- if (cancelledKeys.size() > 0) {
- for (SelectionKey currentKey : cancelledKeys) {
- mutableKeys.remove(currentKey);
- deregister((AbstractSelectionKey) currentKey);
- if (mutableSelectedKeys.remove(currentKey)) {
- deselected++;
- }
- }
- cancelledKeys.clear();
- }
- }
-
- return deselected;
- }
-
- @Override public Selector wakeup() {
- try {
- wakeupPipe.sink().write(ByteBuffer.allocate(WAKEUP_WRITE_SIZE));
- } catch (IOException ignored) {
- }
- return this;
- }
-
- private static class UnaddableSet<E> implements Set<E> {
-
- private final Set<E> set;
-
- UnaddableSet(Set<E> set) {
- this.set = set;
- }
-
- @Override
- public boolean equals(Object object) {
- return set.equals(object);
- }
-
- @Override
- public int hashCode() {
- return set.hashCode();
- }
-
- public boolean add(E object) {
- throw new UnsupportedOperationException();
- }
-
- public boolean addAll(Collection<? extends E> c) {
- throw new UnsupportedOperationException();
- }
-
- public void clear() {
- set.clear();
- }
-
- public boolean contains(Object object) {
- return set.contains(object);
- }
-
- public boolean containsAll(Collection<?> c) {
- return set.containsAll(c);
- }
-
- public boolean isEmpty() {
- return set.isEmpty();
- }
-
- public Iterator<E> iterator() {
- return set.iterator();
- }
-
- public boolean remove(Object object) {
- return set.remove(object);
- }
-
- public boolean removeAll(Collection<?> c) {
- return set.removeAll(c);
- }
-
- public boolean retainAll(Collection<?> c) {
- return set.retainAll(c);
- }
-
- public int size() {
- return set.size();
- }
-
- public Object[] toArray() {
- return set.toArray();
- }
-
- public <T> T[] toArray(T[] a) {
- return set.toArray(a);
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
deleted file mode 100644
index 0c75808..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/SelectorProviderImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.Pipe;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.AbstractSelector;
-import java.nio.channels.spi.SelectorProvider;
-
-/*
- * Internal implementation of SelectorProvider.
- */
-public class SelectorProviderImpl extends SelectorProvider {
-
- /*
- * Constructor for this class.
- */
- public SelectorProviderImpl() {
- super();
- }
-
- /**
- * @see java.nio.channels.spi.SelectorProvider#openDatagramChannel()
- */
- public DatagramChannel openDatagramChannel() throws IOException {
- return new DatagramChannelImpl(this);
- }
-
- /**
- * @see java.nio.channels.spi.SelectorProvider#openPipe()
- */
- public Pipe openPipe() throws IOException {
- return new PipeImpl();
- }
-
- /**
- * @see java.nio.channels.spi.SelectorProvider#openSelector()
- */
- public AbstractSelector openSelector() throws IOException {
- return new SelectorImpl(this);
- }
-
- /**
- * @see java.nio.channels.spi.SelectorProvider#openServerSocketChannel()
- */
- public ServerSocketChannel openServerSocketChannel() throws IOException {
- return new ServerSocketChannelImpl(this);
- }
-
- /**
- * @see java.nio.channels.spi.SelectorProvider#openSocketChannel()
- */
- public SocketChannel openSocketChannel() throws IOException {
- return new SocketChannelImpl(this);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
deleted file mode 100644
index 75e9910..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/ServerSocketChannelImpl.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.SocketImpl;
-import java.net.SocketTimeoutException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.NotYetBoundException;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-import org.apache.harmony.luni.net.PlainServerSocketImpl;
-import org.apache.harmony.luni.platform.FileDescriptorHandler;
-import org.apache.harmony.luni.platform.Platform;
-
-/**
- * The default ServerSocketChannel.
- */
-public final class ServerSocketChannelImpl
- extends ServerSocketChannel implements FileDescriptorHandler {
-
- private final FileDescriptor fd = new FileDescriptor();
- private final SocketImpl impl = new PlainServerSocketImpl(fd);
- private final ServerSocketAdapter socket = new ServerSocketAdapter(impl, this);
-
- private boolean isBound = false;
-
- private static class AcceptLock {}
- private final Object acceptLock = new AcceptLock();
-
- public ServerSocketChannelImpl(SelectorProvider sp) throws IOException {
- super(sp);
- }
-
- // for native call
- @SuppressWarnings("unused")
- private ServerSocketChannelImpl() throws IOException {
- this(SelectorProvider.provider());
- }
-
- @Override public ServerSocket socket() {
- return socket;
- }
-
- @Override public SocketChannel accept() throws IOException {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- if (!isBound) {
- throw new NotYetBoundException();
- }
-
- // TODO: pass in the SelectorProvider used to create this ServerSocketChannelImpl?
- // Create an empty socket channel. This will be populated by ServerSocketAdapter.accept.
- SocketChannelImpl result = new SocketChannelImpl(SelectorProvider.provider(), false);
- Socket resultSocket = result.socket();
-
- try {
- begin();
- synchronized (acceptLock) {
- synchronized (blockingLock()) {
- boolean isBlocking = isBlocking();
- if (!isBlocking) {
- int[] tryResult = new int[1];
- boolean success = Platform.getNetworkSystem().select(
- new FileDescriptor[] { fd },
- new FileDescriptor[0], 1, 0, 0, tryResult);
- if (!success || 0 == tryResult[0]) {
- // no pending connections, returns immediately.
- return null;
- }
- }
- // do accept.
- do {
- try {
- socket.accept(resultSocket, result);
- // select successfully, break out immediately.
- break;
- } catch (SocketTimeoutException e) {
- // continue to accept if the channel is in blocking mode.
- }
- } while (isBlocking);
- }
- }
- } finally {
- end(resultSocket.isConnected());
- }
- return result;
- }
-
- protected void implConfigureBlocking(boolean blockingMode) throws IOException {
- // Do nothing here. For real accept() operation in non-blocking mode,
- // it uses INetworkSystem.select. Whether a channel is blocking can be
- // decided by isBlocking() method.
- }
-
- synchronized protected void implCloseSelectableChannel() throws IOException {
- if (!socket.isClosed()) {
- socket.close();
- }
- }
-
- public FileDescriptor getFD() {
- return fd;
- }
-
- private static class ServerSocketAdapter extends ServerSocket {
- private final ServerSocketChannelImpl channelImpl;
-
- ServerSocketAdapter(SocketImpl impl, ServerSocketChannelImpl aChannelImpl) {
- super(impl);
- this.channelImpl = aChannelImpl;
- }
-
- @Override public void bind(SocketAddress localAddress, int backlog) throws IOException {
- super.bind(localAddress, backlog);
- channelImpl.isBound = true;
- }
-
- @Override public Socket accept() throws IOException {
- if (!channelImpl.isBound) {
- throw new IllegalBlockingModeException();
- }
- SocketChannel sc = channelImpl.accept();
- if (null == sc) {
- throw new IllegalBlockingModeException();
- }
- return sc.socket();
- }
-
- private Socket accept(Socket socket, SocketChannelImpl sockChannel) throws IOException {
- boolean connectOK = false;
- try {
- synchronized (this) {
- super.implAccept(socket);
- sockChannel.setConnected();
- sockChannel.setBound(true);
- sockChannel.finishAccept();
- }
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkAccept(socket.getInetAddress().getHostAddress(), socket.getPort());
- }
- connectOK = true;
- } finally {
- if (!connectOK) {
- socket.close();
- }
- }
- return socket;
- }
-
- @Override public ServerSocketChannel getChannel() {
- return channelImpl;
- }
-
- @Override public boolean isBound() {
- return channelImpl.isBound;
- }
-
- @Override public void bind(SocketAddress localAddress) throws IOException {
- super.bind(localAddress);
- channelImpl.isBound = true;
- }
-
- @Override public void close() throws IOException {
- synchronized (channelImpl) {
- if (channelImpl.isOpen()) {
- channelImpl.close();
- } else {
- super.close();
- }
- }
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java b/luni/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
deleted file mode 100644
index 529e00a..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/SocketChannelImpl.java
+++ /dev/null
@@ -1,760 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.internal;
-
-// BEGIN android-note
-// In this class the address length was changed from long to int.
-// END android-note
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.ConnectException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.net.SocketUtils;
-import java.net.UnknownHostException;
-import java.nio.ByteBuffer;
-import java.nio.channels.AlreadyConnectedException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.ConnectionPendingException;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.NoConnectionPendingException;
-import java.nio.channels.NotYetConnectedException;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.UnresolvedAddressException;
-import java.nio.channels.UnsupportedAddressTypeException;
-import java.nio.channels.spi.SelectorProvider;
-import libcore.io.IoUtils;
-import org.apache.harmony.luni.net.PlainSocketImpl;
-import org.apache.harmony.luni.platform.FileDescriptorHandler;
-import org.apache.harmony.luni.platform.INetworkSystem;
-import org.apache.harmony.luni.platform.Platform;
-import org.apache.harmony.nio.AddressUtil;
-
-/*
- * The default implementation class of java.nio.channels.SocketChannel.
- */
-class SocketChannelImpl extends SocketChannel implements FileDescriptorHandler {
-
- private static final int EOF = -1;
-
- // The singleton to do the native network operation.
- static final INetworkSystem networkSystem = Platform.getNetworkSystem();
-
- // Status un-init, not initialized.
- static final int SOCKET_STATUS_UNINIT = EOF;
-
- // Status before connect.
- static final int SOCKET_STATUS_UNCONNECTED = 0;
-
- // Status connection pending.
- static final int SOCKET_STATUS_PENDING = 1;
-
- // Status after connection success.
- static final int SOCKET_STATUS_CONNECTED = 2;
-
- // Status closed.
- static final int SOCKET_STATUS_CLOSED = 3;
-
- // The descriptor to interact with native code.
- FileDescriptor fd;
-
- // Our internal Socket.
- private SocketAdapter socket = null;
-
- // The address to be connected.
- InetSocketAddress connectAddress = null;
-
- // Local address of the this socket (package private for adapter).
- InetAddress localAddress = null;
-
- // Local port number.
- int localPort;
-
- // At first, uninitialized.
- int status = SOCKET_STATUS_UNINIT;
-
- // Whether the socket is bound.
- volatile boolean isBound = false;
-
- private static class ReadLock {}
- private final Object readLock = new ReadLock();
-
- private static class WriteLock {}
- private final Object writeLock = new WriteLock();
-
- /*
- * Constructor for creating a connected socket channel.
- */
- public SocketChannelImpl(SelectorProvider selectorProvider) throws IOException {
- this(selectorProvider, true);
- }
-
- /*
- * Constructor for creating an optionally connected socket channel.
- */
- public SocketChannelImpl(SelectorProvider selectorProvider, boolean connect) throws IOException {
- super(selectorProvider);
- fd = new FileDescriptor();
- status = SOCKET_STATUS_UNCONNECTED;
- if (connect) {
- networkSystem.socket(fd, true);
- }
- }
-
- /*
- * Getting the internal Socket If we have not the socket, we create a new
- * one.
- */
- @Override
- synchronized public Socket socket() {
- if (socket == null) {
- try {
- InetAddress addr = null;
- int port = 0;
- if (connectAddress != null) {
- addr = connectAddress.getAddress();
- port = connectAddress.getPort();
- }
- socket = new SocketAdapter(new PlainSocketImpl(fd, localPort, addr, port), this);
- } catch (SocketException e) {
- return null;
- }
- }
- return socket;
- }
-
- @Override
- synchronized public boolean isConnected() {
- return status == SOCKET_STATUS_CONNECTED;
- }
-
- /*
- * Status setting used by other class.
- */
- synchronized void setConnected() {
- status = SOCKET_STATUS_CONNECTED;
- }
-
- void setBound(boolean flag) {
- isBound = flag;
- }
-
- @Override
- synchronized public boolean isConnectionPending() {
- return status == SOCKET_STATUS_PENDING;
- }
-
- @Override
- public boolean connect(SocketAddress socketAddress) throws IOException {
- // status must be open and unconnected
- checkUnconnected();
-
- // check the address
- InetSocketAddress inetSocketAddress = validateAddress(socketAddress);
- InetAddress normalAddr = inetSocketAddress.getAddress();
-
- // When connecting, map ANY address to Localhost
- if (normalAddr.isAnyLocalAddress()) {
- normalAddr = InetAddress.getLocalHost();
- }
-
- int port = inetSocketAddress.getPort();
- String hostName = normalAddr.getHostName();
- // security check
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkConnect(hostName, port);
- }
-
- // connect result
- int result = EOF;
- boolean finished = false;
-
- try {
- if (isBlocking()) {
- begin();
- networkSystem.connect(fd, normalAddr, port, 0);
- finished = true; // Or we'd have thrown an exception.
- } else {
- finished = networkSystem.connectNonBlocking(fd, normalAddr, port);
- // set back to nonblocking to work around with a bug in portlib
- if (!isBlocking()) {
- IoUtils.setBlocking(fd, false);
- }
- }
- isBound = finished;
- } catch (IOException e) {
- if (e instanceof ConnectException && !isBlocking()) {
- status = SOCKET_STATUS_PENDING;
- } else {
- if (isOpen()) {
- close();
- finished = true;
- }
- throw e;
- }
- } finally {
- if (isBlocking()) {
- end(finished);
- }
- }
-
- initLocalAddressAndPort();
- connectAddress = inetSocketAddress;
- if (socket != null) {
- socket.socketImpl().initRemoteAddressAndPort(connectAddress.getAddress(),
- connectAddress.getPort());
- }
-
- synchronized (this) {
- if (isBlocking()) {
- status = (finished ? SOCKET_STATUS_CONNECTED : SOCKET_STATUS_UNCONNECTED);
- } else {
- status = SOCKET_STATUS_PENDING;
- }
- }
- return finished;
- }
-
- private void initLocalAddressAndPort() {
- localAddress = networkSystem.getSocketLocalAddress(fd);
- localPort = networkSystem.getSocketLocalPort(fd);
- if (socket != null) {
- socket.socketImpl().initLocalPort(localPort);
- }
- }
-
- @Override
- public boolean finishConnect() throws IOException {
- // status check
- synchronized (this) {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- if (status == SOCKET_STATUS_CONNECTED) {
- return true;
- }
- if (status != SOCKET_STATUS_PENDING) {
- throw new NoConnectionPendingException();
- }
- }
-
- boolean finished = false;
- try {
- begin();
- final int WAIT_FOREVER = -1;
- final int POLL = 0;
- finished = networkSystem.isConnected(fd, isBlocking() ? WAIT_FOREVER : POLL);
- isBound = finished;
- initLocalAddressAndPort();
- } catch (ConnectException e) {
- if (isOpen()) {
- close();
- finished = true;
- }
- throw e;
- } finally {
- end(finished);
- }
-
- synchronized (this) {
- status = (finished ? SOCKET_STATUS_CONNECTED : status);
- isBound = finished;
- // TPE: Workaround for bug that turns socket back to blocking
- if (!isBlocking()) implConfigureBlocking(false);
- }
- return finished;
- }
-
- void finishAccept() {
- initLocalAddressAndPort();
- }
-
- @Override
- public int read(ByteBuffer target) throws IOException {
- FileChannelImpl.checkWritable(target);
- checkOpenConnected();
- if (!target.hasRemaining()) {
- return 0;
- }
-
- int readCount;
- if (target.isDirect() || target.hasArray()) {
- readCount = readImpl(target);
- if (readCount > 0) {
- target.position(target.position() + readCount);
- }
- } else {
- ByteBuffer readBuffer = null;
- byte[] readArray = null;
- readArray = new byte[target.remaining()];
- readBuffer = ByteBuffer.wrap(readArray);
- readCount = readImpl(readBuffer);
- if (readCount > 0) {
- target.put(readArray, 0, readCount);
- }
- }
- return readCount;
- }
-
- @Override
- public long read(ByteBuffer[] targets, int offset, int length) throws IOException {
- if (!isIndexValid(targets, offset, length)) {
- throw new IndexOutOfBoundsException();
- }
-
- checkOpenConnected();
- int totalCount = FileChannelImpl.calculateTotalRemaining(targets, offset, length, true);
- if (totalCount == 0) {
- return 0;
- }
- byte[] readArray = new byte[totalCount];
- ByteBuffer readBuffer = ByteBuffer.wrap(readArray);
- int readCount;
- // read data to readBuffer, and then transfer data from readBuffer to
- // targets.
- readCount = readImpl(readBuffer);
- if (readCount > 0) {
- int left = readCount;
- int index = offset;
- // transfer data from readArray to targets
- while (left > 0) {
- int putLength = Math.min(targets[index].remaining(), left);
- targets[index].put(readArray, readCount - left, putLength);
- index++;
- left -= putLength;
- }
- }
- return readCount;
- }
-
- private boolean isIndexValid(ByteBuffer[] targets, int offset, int length) {
- return (length >= 0) && (offset >= 0)
- && ((long) length + (long) offset <= targets.length);
- }
-
- /**
- * Read from channel, and store the result in the target.
- *
- * @param target
- * output parameter
- */
- private int readImpl(ByteBuffer target) throws IOException {
- synchronized (readLock) {
- int readCount = 0;
- try {
- if (isBlocking()) {
- begin();
- }
- int offset = target.position();
- int length = target.remaining();
- if (target.isDirect()) {
- // BEGIN android-changed
- // changed address from long to int
- int address = AddressUtil.getDirectBufferAddress(target);
- readCount = networkSystem.readDirect(fd, address + offset, length);
- // END android-changed
- } else {
- // target is assured to have array.
- byte[] array = target.array();
- offset += target.arrayOffset();
- readCount = networkSystem.read(fd, array, offset, length);
- }
- return readCount;
- } finally {
- if (isBlocking()) {
- end(readCount > 0);
- }
- }
- }
- }
-
- @Override
- public int write(ByteBuffer source) throws IOException {
- if (null == source) {
- throw new NullPointerException();
- }
- checkOpenConnected();
- if (!source.hasRemaining()) {
- return 0;
- }
- return writeImpl(source);
- }
-
- @Override
- public long write(ByteBuffer[] sources, int offset, int length) throws IOException {
- if (!isIndexValid(sources, offset, length)) {
- throw new IndexOutOfBoundsException();
- }
-
- checkOpenConnected();
- int count = FileChannelImpl.calculateTotalRemaining(sources, offset, length, false);
- if (count == 0) {
- return 0;
- }
- ByteBuffer writeBuf = ByteBuffer.allocate(count);
- for (int val = offset; val < length + offset; val++) {
- ByteBuffer source = sources[val];
- int oldPosition = source.position();
- writeBuf.put(source);
- source.position(oldPosition);
- }
- writeBuf.flip();
- int result = writeImpl(writeBuf);
- int val = offset;
- int written = result;
- while (result > 0) {
- ByteBuffer source = sources[val];
- int gap = Math.min(result, source.remaining());
- source.position(source.position() + gap);
- val++;
- result -= gap;
- }
- return written;
- }
-
- /*
- * Write the source. return the count of bytes written.
- */
- private int writeImpl(ByteBuffer source) throws IOException {
- synchronized (writeLock) {
- if (!source.hasRemaining()) {
- return 0;
- }
- int writeCount = 0;
- try {
- int pos = source.position();
- int length = source.remaining();
- if (isBlocking()) {
- begin();
- }
- if (source.isDirect()) {
- int address = AddressUtil.getDirectBufferAddress(source);
- writeCount = networkSystem.writeDirect(fd, address, pos, length);
- } else if (source.hasArray()) {
- pos += source.arrayOffset();
- writeCount = networkSystem.write(fd, source.array(), pos, length);
- } else {
- byte[] array = new byte[length];
- source.get(array);
- writeCount = networkSystem.write(fd, array, 0, length);
- }
- source.position(pos + writeCount);
- } finally {
- if (isBlocking()) {
- end(writeCount >= 0);
- }
- }
- return writeCount;
- }
- }
-
- /*
- * Status check, open and "connected", when read and write.
- */
- synchronized private void checkOpenConnected() throws ClosedChannelException {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- if (!isConnected()) {
- throw new NotYetConnectedException();
- }
- }
-
- /*
- * Status check, open and "unconnected", before connection.
- */
- synchronized private void checkUnconnected() throws IOException {
- if (!isOpen()) {
- throw new ClosedChannelException();
- }
- if (status == SOCKET_STATUS_CONNECTED) {
- throw new AlreadyConnectedException();
- }
- if (status == SOCKET_STATUS_PENDING) {
- throw new ConnectionPendingException();
- }
- }
-
- /*
- * Shared by this class and DatagramChannelImpl, to do the address transfer
- * and check.
- */
- static InetSocketAddress validateAddress(SocketAddress socketAddress) {
- if (null == socketAddress) {
- throw new IllegalArgumentException();
- }
- if (!(socketAddress instanceof InetSocketAddress)) {
- throw new UnsupportedAddressTypeException();
- }
- InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
- if (inetSocketAddress.isUnresolved()) {
- throw new UnresolvedAddressException();
- }
- return inetSocketAddress;
- }
-
- /*
- * Get local address.
- */
- public InetAddress getLocalAddress() throws UnknownHostException {
- if (!isBound) {
- byte[] any_bytes = { 0, 0, 0, 0 };
- return InetAddress.getByAddress(any_bytes);
- }
- return localAddress;
- }
-
- /*
- * Do really closing action here.
- */
- @Override
- synchronized protected void implCloseSelectableChannel() throws IOException {
- if (SOCKET_STATUS_CLOSED != status) {
- status = SOCKET_STATUS_CLOSED;
- if (null != socket && !socket.isClosed()) {
- socket.close();
- } else {
- networkSystem.close(fd);
- }
- }
- }
-
- @Override
- protected void implConfigureBlocking(boolean blockMode) throws IOException {
- synchronized (blockingLock()) {
- IoUtils.setBlocking(fd, blockMode);
- }
- }
-
- /*
- * Get the fd.
- */
- public FileDescriptor getFD() {
- return fd;
- }
-
- /*
- * Adapter classes for internal socket.
- */
- private static class SocketAdapter extends Socket {
- private final SocketChannelImpl channel;
- private final PlainSocketImpl socketImpl;
-
- SocketAdapter(PlainSocketImpl socketImpl, SocketChannelImpl channel) throws SocketException {
- super(socketImpl);
- this.socketImpl = socketImpl;
- this.channel = channel;
- SocketUtils.setCreated(this);
- }
-
- PlainSocketImpl socketImpl() {
- return socketImpl;
- }
-
- @Override
- public SocketChannel getChannel() {
- return channel;
- }
-
- @Override
- public boolean isBound() {
- return channel.isBound;
- }
-
- @Override
- public boolean isConnected() {
- return channel.isConnected();
- }
-
- @Override
- public InetAddress getLocalAddress() {
- try {
- return channel.getLocalAddress();
- } catch (UnknownHostException e) {
- return null;
- }
- }
-
- @Override
- public void connect(SocketAddress remoteAddr, int timeout) throws IOException {
- if (!channel.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- if (isConnected()) {
- throw new AlreadyConnectedException();
- }
- super.connect(remoteAddr, timeout);
- channel.initLocalAddressAndPort();
- if (super.isConnected()) {
- channel.setConnected();
- channel.isBound = super.isBound();
- }
- }
-
- @Override
- public void bind(SocketAddress localAddr) throws IOException {
- if (channel.isConnected()) {
- throw new AlreadyConnectedException();
- }
- if (SocketChannelImpl.SOCKET_STATUS_PENDING == channel.status) {
- throw new ConnectionPendingException();
- }
- super.bind(localAddr);
- // keep here to see if need next version
- // channel.Address = getLocalSocketAddress();
- // channel.localport = getLocalPort();
- channel.isBound = true;
- }
-
- @Override
- public void close() throws IOException {
- synchronized (channel) {
- if (channel.isOpen()) {
- channel.close();
- } else {
- super.close();
- }
- channel.status = SocketChannelImpl.SOCKET_STATUS_CLOSED;
- }
- }
-
- @Override
- public OutputStream getOutputStream() throws IOException {
- checkOpenAndConnected();
- if (isOutputShutdown()) {
- throw new SocketException("Socket output is shutdown");
- }
- return new SocketChannelOutputStream(channel);
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- checkOpenAndConnected();
- if (isInputShutdown()) {
- throw new SocketException("Socket input is shutdown");
- }
- return new SocketChannelInputStream(channel);
- }
-
- private void checkOpenAndConnected() throws SocketException {
- if (!channel.isOpen()) {
- throw new SocketException("Socket is closed");
- }
- if (!channel.isConnected()) {
- throw new SocketException("Socket is not connected");
- }
- }
- }
-
- /*
- * This output stream delegates all operations to the associated channel.
- * Throws an IllegalBlockingModeException if the channel is in non-blocking
- * mode when performing write operations.
- */
- private static class SocketChannelOutputStream extends OutputStream {
- private final SocketChannel channel;
-
- public SocketChannelOutputStream(SocketChannel channel) {
- this.channel = channel;
- }
-
- /*
- * Closes this stream and channel.
- *
- * @exception IOException thrown if an error occurs during the close
- */
- @Override
- public void close() throws IOException {
- channel.close();
- }
-
- @Override
- public void write(byte[] buffer, int offset, int count) throws IOException {
- if (0 > offset || 0 > count || count + offset > buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- ByteBuffer buf = ByteBuffer.wrap(buffer, offset, count);
- if (!channel.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- channel.write(buf);
- }
-
- @Override
- public void write(int oneByte) throws IOException {
- if (!channel.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- ByteBuffer buffer = ByteBuffer.allocate(1);
- buffer.put(0, (byte) (oneByte & 0xFF));
- channel.write(buffer);
- }
- }
-
- /*
- * This input stream delegates all operations to the associated channel.
- * Throws an IllegalBlockingModeException if the channel is in non-blocking
- * mode when performing read operations.
- */
- private static class SocketChannelInputStream extends InputStream {
- private final SocketChannel channel;
-
- public SocketChannelInputStream(SocketChannel channel) {
- this.channel = channel;
- }
-
- /*
- * Closes this stream and channel.
- */
- @Override
- public void close() throws IOException {
- channel.close();
- }
-
- @Override
- public int read() throws IOException {
- if (!channel.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- ByteBuffer buf = ByteBuffer.allocate(1);
- int result = channel.read(buf);
- // BEGIN android-changed: input was already consumed
- return (-1 == result) ? result : buf.get(0) & 0xFF;
- // END android-changed
- }
-
- @Override
- public int read(byte[] buffer, int offset, int count) throws IOException {
- if (0 > offset || 0 > count || count + offset > buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- if (!channel.isBlocking()) {
- throw new IllegalBlockingModeException();
- }
- ByteBuffer buf = ByteBuffer.wrap(buffer, offset, count);
- return channel.read(buf);
- }
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java b/luni/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java
deleted file mode 100644
index 21fa9d3..0000000
--- a/luni/src/main/java/org/apache/harmony/nio/internal/WriteOnlyFileChannel.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Android Notice
- * In this class the address length was changed from long to int.
- * This is due to performance optimizations for the device.
- */
-
-package org.apache.harmony.nio.internal;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.FileLock;
-import java.nio.channels.NonReadableChannelException;
-import java.nio.channels.WritableByteChannel;
-
-public final class WriteOnlyFileChannel extends FileChannelImpl {
-
- private boolean append = false;
-
- public WriteOnlyFileChannel(Object stream, int handle) {
- super(stream, handle);
- }
-
- public WriteOnlyFileChannel(Object stream, int handle, boolean isAppend) {
- super(stream, handle);
- append = isAppend;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.harmony.nio.internal.FileChannelImpl#position()
- */
- public long position() throws IOException {
- return append ? size() : super.position();
- }
-
- public long transferTo(long position, long count, WritableByteChannel target)
- throws IOException {
- openCheck();
- if (!target.isOpen()) {
- throw new ClosedChannelException();
- }
- throw new NonReadableChannelException();
- }
-
- public long read(ByteBuffer[] buffers, int offset, int length)
- throws IOException {
- if (offset < 0 || length < 0 || offset + length > buffers.length) {
- throw new IndexOutOfBoundsException();
- }
- openCheck();
- throw new NonReadableChannelException();
- }
-
- public int read(ByteBuffer buffer) throws IOException {
- openCheck();
- throw new NonReadableChannelException();
- }
-
- public int read(ByteBuffer buffer, long position) throws IOException {
- if (null == buffer) {
- throw new NullPointerException();
- }
- if (position < 0) {
- throw new IllegalArgumentException();
- }
- throw new NonReadableChannelException();
- }
-
- public MappedByteBuffer map(MapMode mode, long position, long size)
- throws IOException {
- openCheck();
- if (mode == null) {
- throw new NullPointerException();
- }
- if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
- throw new IllegalArgumentException();
- }
- throw new NonReadableChannelException();
- }
-
- public int write(ByteBuffer buffer) throws IOException {
- if (append) {
- position(size());
- }
- return super.write(buffer);
- }
-
- protected final FileLock basicLock(long position, long size,
- boolean shared, boolean wait) throws IOException {
- if (shared) {
- throw new NonReadableChannelException();
- }
- return super.basicLock(position, size, shared, wait);
- }
-}
diff --git a/luni/src/main/java/org/apache/harmony/security/PolicyEntry.java b/luni/src/main/java/org/apache/harmony/security/PolicyEntry.java
index 8470f58..32f15a3 100644
--- a/luni/src/main/java/org/apache/harmony/security/PolicyEntry.java
+++ b/luni/src/main/java/org/apache/harmony/security/PolicyEntry.java
@@ -57,7 +57,7 @@ public class PolicyEntry {
Collection<? extends Permission> permissions) {
this.cs = (cs != null) ? normalizeCodeSource(cs) : null;
this.principals = (prs == null || prs.isEmpty()) ? null
- : (Principal[]) prs.toArray(new Principal[prs.size()]);
+ : prs.toArray(new Principal[prs.size()]);
this.permissions = (permissions == null || permissions.isEmpty()) ? null
: Collections.unmodifiableCollection(permissions);
}
diff --git a/luni/src/main/java/org/apache/harmony/security/asn1/ASN1Choice.java b/luni/src/main/java/org/apache/harmony/security/asn1/ASN1Choice.java
index b17a4b0..ae719a5 100644
--- a/luni/src/main/java/org/apache/harmony/security/asn1/ASN1Choice.java
+++ b/luni/src/main/java/org/apache/harmony/security/asn1/ASN1Choice.java
@@ -269,7 +269,7 @@ public abstract class ASN1Choice extends ASN1Type {
Iterator it = map.entrySet().iterator();
for (int i = 0; i < size; i++) {
- Map.Entry entry = (Map.Entry) it.next();
+ Map.Entry entry = (Map.Entry) it.next();
BigInteger identifier = (BigInteger) entry.getKey();
identifiers[0][i] = identifier.intValue();
diff --git a/luni/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java b/luni/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java
index 7214e3f..ebdce53 100644
--- a/luni/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java
+++ b/luni/src/main/java/org/apache/harmony/security/fortress/DefaultPolicy.java
@@ -209,7 +209,7 @@ public class DefaultPolicy extends Policy {
pc = new HashSet<Permission>();
Iterator<PolicyEntry> it = grants.iterator();
while (it.hasNext()) {
- PolicyEntry ge = (PolicyEntry)it.next();
+ PolicyEntry ge = it.next();
if (ge.impliesPrincipals(pd == null ? null : pd.getPrincipals())
&& ge.impliesCodeSource(pd == null ? null : pd.getCodeSource())) {
pc.addAll(ge.getPermissions());
@@ -248,9 +248,8 @@ public class DefaultPolicy extends Policy {
pc = new HashSet<Permission>();
Iterator<PolicyEntry> it = grants.iterator();
while (it.hasNext()) {
- PolicyEntry ge = (PolicyEntry)it.next();
- if (ge.impliesPrincipals(null)
- && ge.impliesCodeSource(cs)) {
+ PolicyEntry ge = it.next();
+ if (ge.impliesPrincipals(null) && ge.impliesCodeSource(cs)) {
pc.addAll(ge.getPermissions());
}
}
diff --git a/luni/src/main/java/org/apache/harmony/security/fortress/Engine.java b/luni/src/main/java/org/apache/harmony/security/fortress/Engine.java
index c5bb376..7dbc476 100644
--- a/luni/src/main/java/org/apache/harmony/security/fortress/Engine.java
+++ b/luni/src/main/java/org/apache/harmony/security/fortress/Engine.java
@@ -28,38 +28,92 @@ import org.apache.harmony.security.Util;
/**
+ * This class implements common functionality for Provider supplied
+ * classes. The usage pattern is to allocate static Engine instance
+ * per service type and synchronize on that instance during calls to
+ * {@code getInstance} and retreival of the selected {@code Provider}
+ * and Service Provider Interface (SPI) results. Retreiving the
+ * results with {@code getProvider} and {@code getSpi} sets the
+ * internal {@code Engine} values to null to prevent memory leaks.
*
- * This class implements common functionality for all engine classes
+ * <p>
*
+ * For example: <pre> {@code
+ * public class Foo {
+ *
+ * private static final Engine ENGINE = new Engine("Foo");
+ *
+ * private final FooSpi spi;
+ * private final Provider provider;
+ * private final String algorithm;
+ *
+ * protected Foo(FooSpi spi,
+ * Provider provider,
+ * String algorithm) {
+ * this.spi = spi;
+ * this.provider = provider;
+ * this.algorithm = algorithm;
+ * }
+ *
+ * public static Foo getInstance(String algorithm) {
+ * Engine.SpiAndProvider sap = ENGINE.getInstance(algorithm, null);
+ * return new Foo((FooSpi) sap.spi, sap.provider, algorithm);
+ * }
+ *
+ * public static Foo getInstance(String algorithm, Provider provider) {
+ * Object spi = ENGINE.getInstance(algorithm, provider, null);
+ * return new Foo((FooSpi) spi, provider, algorithm);
+ * }
+ *
+ * ...
+ *
+ * }</pre>
*/
public class Engine {
- // Service name
- private final String serviceName;
-
- // for getInstance(String algorithm, Object param) optimization:
- // previous result
- private Provider.Service returnedService;
-
- // previous parameter
- private String lastAlgorithm;
-
- private int refreshNumber;
-
/**
- * Provider
+ * Access to package visible api in java.security
*/
- public Provider provider;
+ public static SecurityAccess door;
/**
- * SPI instance
+ * Service name such as Cipher or SSLContext
*/
- public Object spi;
+ private final String serviceName;
/**
- * Access to package visible api in java.security
+ * Previous result for getInstance(String, Object) optimization.
+ * Only this non-Provider version of getInstance is optimized
+ * since the the Provider version does not require an expensive
+ * Services.getService call.
*/
- public static SecurityAccess door;
+ private volatile ServiceCacheEntry serviceCache;
+
+ private static final class ServiceCacheEntry {
+ /** used to test for cache hit */
+ private final String algorithm;
+ /** used to test for cache validity */
+ private final int refreshNumber;
+ /** cached result */
+ private final Provider.Service service;
+
+ private ServiceCacheEntry(String algorithm,
+ int refreshNumber,
+ Provider.Service service) {
+ this.algorithm = algorithm;
+ this.refreshNumber = refreshNumber;
+ this.service = service;
+ }
+ }
+
+ public static final class SpiAndProvider {
+ public final Object spi;
+ public final Provider provider;
+ private SpiAndProvider(Object spi, Provider provider) {
+ this.spi = spi;
+ this.provider = provider;
+ }
+ }
/**
* Creates a Engine object
@@ -71,71 +125,60 @@ public class Engine {
}
/**
- *
- * Finds the appropriate service implementation and creates instance of the
- * class that implements corresponding Service Provider Interface.
- *
- * @param algorithm
- * @param service
- * @throws NoSuchAlgorithmException
+ * Finds the appropriate service implementation and returns an
+ * {@code SpiAndProvider} instance containing a reference to SPI
+ * and its {@code Provider}
*/
- public synchronized void getInstance(String algorithm, Object param)
+ public SpiAndProvider getInstance(String algorithm, Object param)
throws NoSuchAlgorithmException {
- Provider.Service serv;
-
if (algorithm == null) {
throw new NoSuchAlgorithmException("Null algorithm name");
}
Services.refresh();
- if (returnedService != null
- && Util.equalsIgnoreCase(algorithm, lastAlgorithm)
- && refreshNumber == Services.refreshNumber) {
- serv = returnedService;
+ Provider.Service service;
+ ServiceCacheEntry cacheEntry = this.serviceCache;
+ if (cacheEntry != null
+ && Util.equalsIgnoreCase(algorithm, cacheEntry.algorithm)
+ && Services.refreshNumber != cacheEntry.refreshNumber) {
+ service = cacheEntry.service;
} else {
if (Services.isEmpty()) {
throw notFound(serviceName, algorithm);
}
- serv = Services.getService(new StringBuilder(128)
- .append(serviceName).append(".").append(
- Util.toUpperCase(algorithm)).toString());
- if (serv == null) {
+ String name = new StringBuilder(128)
+ .append(this.serviceName)
+ .append(".")
+ .append(Util.toUpperCase(algorithm))
+ .toString();
+ service = Services.getService(name);
+ if (service == null) {
throw notFound(serviceName, algorithm);
}
- returnedService = serv;
- lastAlgorithm = algorithm;
- refreshNumber = Services.refreshNumber;
+ this.serviceCache = new ServiceCacheEntry(algorithm, Services.refreshNumber, service);
}
- spi = serv.newInstance(param);
- this.provider = serv.getProvider();
- }
-
- private NoSuchAlgorithmException notFound(String serviceName, String algorithm) throws NoSuchAlgorithmException {
- throw new NoSuchAlgorithmException(serviceName + " " + algorithm + " implementation not found");
+ return new SpiAndProvider(service.newInstance(param), service.getProvider());
}
/**
- *
- * Finds the appropriate service implementation and creates instance of the
- * class that implements corresponding Service Provider Interface.
- *
- * @param algorithm
- * @param service
- * @param provider
- * @throws NoSuchAlgorithmException
+ * Finds the appropriate service implementation and returns and
+ * instance of the class that implements corresponding Service
+ * Provider Interface.
*/
- public synchronized void getInstance(String algorithm, Provider provider,
- Object param) throws NoSuchAlgorithmException {
-
- Provider.Service serv = null;
+ public Object getInstance(String algorithm, Provider provider, Object param)
+ throws NoSuchAlgorithmException {
if (algorithm == null) {
throw new NoSuchAlgorithmException("algorithm == null");
}
- serv = provider.getService(serviceName, algorithm);
- if (serv == null) {
+ Provider.Service service = provider.getService(serviceName, algorithm);
+ if (service == null) {
throw notFound(serviceName, algorithm);
}
- spi = serv.newInstance(param);
- this.provider = provider;
+ return service.newInstance(param);
}
+ private NoSuchAlgorithmException notFound(String serviceName, String algorithm)
+ throws NoSuchAlgorithmException {
+ throw new NoSuchAlgorithmException(serviceName + " " + algorithm
+ + " implementation not found");
+ }
}
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java
index 20e5646..0b1f797 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertFactoryImpl.java
@@ -860,22 +860,5 @@ public class X509CertFactoryImpl extends CertificateFactorySpi {
"position became invalid or stream has not been marked");
}
}
-
- @Override
- public long skip(long n) throws IOException {
- if (pos >= 0) {
- long i = 0;
- int av = available();
- if (av < n) {
- n = av;
- }
- while ((i < n) && (read() != -1)) {
- i++;
- }
- return i;
- } else {
- return inStream.skip(n);
- }
- }
}
}
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java
index 5870f60..d8f79bc 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertImpl.java
@@ -71,27 +71,26 @@ public class X509CertImpl extends X509Certificate {
private final Certificate certificate;
// to speed up access to the info, the following fields
- // cache values retrieved from the certificate object
+ // cache values retrieved from the certificate object,
+ // initialized using the "single-check idiom".
private final TBSCertificate tbsCert;
private final Extensions extensions;
- private long notBefore = -1;
- private long notAfter;
- private BigInteger serialNumber;
- private X500Principal issuer;
- private X500Principal subject;
- private byte[] tbsCertificate;
- private byte[] signature;
- private String sigAlgName;
- private String sigAlgOID;
- private byte[] sigAlgParams;
+ private volatile long notBefore = -1;
+ private volatile long notAfter = -1;
+ private volatile BigInteger serialNumber;
+ private volatile X500Principal issuer;
+ private volatile X500Principal subject;
+ private volatile byte[] tbsCertificate;
+ private volatile byte[] signature;
+ private volatile String sigAlgName;
+ private volatile String sigAlgOID;
+ private volatile byte[] sigAlgParams;
// indicates whether the signature algorithm parameters are null
- private boolean nullSigAlgParams;
- private PublicKey publicKey;
+ private volatile boolean nullSigAlgParams;
+ private volatile PublicKey publicKey;
// encoding of the certificate
-// BEGIN android-changed
private volatile byte[] encoding;
-// END android-changed
//
// ---------------------- Constructors -------------------------------
@@ -144,20 +143,9 @@ public class X509CertImpl extends X509Certificate {
* @see java.security.cert.X509Certificate#checkValidity()
* method documentation for more information.
*/
- public void checkValidity() throws CertificateExpiredException,
- CertificateNotYetValidException {
- if (notBefore == -1) {
- // retrieve and cache the value of validity period
- notBefore = tbsCert.getValidity().getNotBefore().getTime();
- notAfter = tbsCert.getValidity().getNotAfter().getTime();
- }
- long time = System.currentTimeMillis();
- if (time < notBefore) {
- throw new CertificateNotYetValidException();
- }
- if (time > notAfter) {
- throw new CertificateExpiredException();
- }
+ public void checkValidity()
+ throws CertificateExpiredException, CertificateNotYetValidException {
+ checkValidity(System.currentTimeMillis());
}
/**
@@ -165,25 +153,19 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public void checkValidity(Date date)
- throws CertificateExpiredException,
- CertificateNotYetValidException {
- if (notBefore == -1) {
- // retrieve and cache the value of validity period
- notBefore = tbsCert.getValidity().getNotBefore().getTime();
- notAfter = tbsCert.getValidity().getNotAfter().getTime();
- }
- long time = date.getTime();
- if (time < notBefore) {
- // BEGIN android-changed
- throw new CertificateNotYetValidException("current time: " + date
- + ", validation time: " + new Date(notBefore));
- // END android-changed
+ throws CertificateExpiredException, CertificateNotYetValidException {
+ checkValidity(date.getTime());
+ }
+
+ private void checkValidity(long time)
+ throws CertificateExpiredException, CertificateNotYetValidException {
+ if (time < getNotBeforeInternal()) {
+ throw new CertificateNotYetValidException("current time: " + new Date(time)
+ + ", validation time: " + new Date(getNotBeforeInternal()));
}
- if (time > notAfter) {
- // BEGIN android-changed
- throw new CertificateExpiredException("current time: " + date
- + ", expiration time: " + new Date(notAfter));
- // END android-changed
+ if (time > getNotAfterInternal()) {
+ throw new CertificateExpiredException("current time: " + new Date(time)
+ + ", expiration time: " + new Date(getNotAfterInternal()));
}
}
@@ -200,10 +182,11 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public BigInteger getSerialNumber() {
- if (serialNumber == null) {
- serialNumber = tbsCert.getSerialNumber();
+ BigInteger result = serialNumber;
+ if (result == null) {
+ serialNumber = result = tbsCert.getSerialNumber();
}
- return serialNumber;
+ return result;
}
/**
@@ -211,11 +194,7 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public Principal getIssuerDN() {
- if (issuer == null) {
- // retrieve the issuer's principal
- issuer = tbsCert.getIssuer().getX500Principal();
- }
- return issuer;
+ return getIssuerX500Principal();
}
/**
@@ -223,11 +202,12 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public X500Principal getIssuerX500Principal() {
- if (issuer == null) {
+ X500Principal result = issuer;
+ if (result == null) {
// retrieve the issuer's principal
- issuer = tbsCert.getIssuer().getX500Principal();
+ issuer = result = tbsCert.getIssuer().getX500Principal();
}
- return issuer;
+ return result;
}
/**
@@ -235,11 +215,7 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public Principal getSubjectDN() {
- if (subject == null) {
- // retrieve the subject's principal
- subject = tbsCert.getSubject().getX500Principal();
- }
- return subject;
+ return getSubjectX500Principal();
}
/**
@@ -247,11 +223,12 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public X500Principal getSubjectX500Principal() {
- if (subject == null) {
+ X500Principal result = subject;
+ if (result == null) {
// retrieve the subject's principal
- subject = tbsCert.getSubject().getX500Principal();
+ subject = result = tbsCert.getSubject().getX500Principal();
}
- return subject;
+ return result;
}
/**
@@ -259,12 +236,14 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public Date getNotBefore() {
- if (notBefore == -1) {
- // the value was not retrieved from the certificate, do it:
- notBefore = tbsCert.getValidity().getNotBefore().getTime();
- notAfter = tbsCert.getValidity().getNotAfter().getTime();
+ return new Date(getNotBeforeInternal());
+ }
+ private long getNotBeforeInternal() {
+ long result = notBefore;
+ if (result == -1) {
+ notBefore = result = tbsCert.getValidity().getNotBefore().getTime();
}
- return new Date(notBefore);
+ return result;
}
/**
@@ -272,26 +251,28 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public Date getNotAfter() {
- if (notBefore == -1) {
- // the value was not retrieved from the certificate, do it:
- notBefore = tbsCert.getValidity().getNotBefore().getTime();
- notAfter = tbsCert.getValidity().getNotAfter().getTime();
+ return new Date(getNotAfterInternal());
+ }
+ private long getNotAfterInternal() {
+ long result = notAfter;
+ if (result == -1) {
+ notAfter = result = tbsCert.getValidity().getNotAfter().getTime();
}
- return new Date(notAfter);
+ return result;
}
/**
* @see java.security.cert.X509Certificate#getTBSCertificate()
* method documentation for more information.
*/
- public byte[] getTBSCertificate()
- throws CertificateEncodingException {
- if (tbsCertificate == null) {
- // retrieve the encoded form of the TBSCertificate structure
- tbsCertificate = tbsCert.getEncoded();
+ public byte[] getTBSCertificate() throws CertificateEncodingException {
+ return getTbsCertificateInternal().clone();
+ }
+ private byte[] getTbsCertificateInternal() {
+ byte[] result = tbsCertificate;
+ if (result == null) {
+ tbsCertificate = result = tbsCert.getEncoded();
}
- byte[] result = new byte[tbsCertificate.length];
- System.arraycopy(tbsCertificate, 0, result, 0, tbsCertificate.length);
return result;
}
@@ -300,12 +281,13 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public byte[] getSignature() {
- if (signature == null) {
- // retrieve the value of the signature
- signature = certificate.getSignatureValue();
+ return getSignatureInternal().clone();
+ }
+ private byte[] getSignatureInternal() {
+ byte[] result = signature;
+ if (result == null) {
+ signature = result = certificate.getSignatureValue();
}
- byte[] result = new byte[signature.length];
- System.arraycopy(signature, 0, result, 0, signature.length);
return result;
}
@@ -314,17 +296,18 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public String getSigAlgName() {
- if (sigAlgOID == null) {
- // if info was not retrieved (and cached), do it:
- sigAlgOID = tbsCert.getSignature().getAlgorithm();
+ String result = sigAlgName;
+ if (result == null) {
+ String sigAlgOIDLocal = getSigAlgOID();
// retrieve the name of the signing algorithm
- sigAlgName = AlgNameMapper.map2AlgName(sigAlgOID);
- if (sigAlgName == null) {
+ result = AlgNameMapper.map2AlgName(sigAlgOIDLocal);
+ if (result == null) {
// if could not be found, use OID as a name
- sigAlgName = sigAlgOID;
+ result = sigAlgOIDLocal;
}
+ sigAlgName = result;
}
- return sigAlgName;
+ return result;
}
/**
@@ -332,17 +315,12 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public String getSigAlgOID() {
- if (sigAlgOID == null) {
+ String result = sigAlgOID;
+ if (result == null) {
// if info was not retrieved (and cached), do it:
- sigAlgOID = tbsCert.getSignature().getAlgorithm();
- // retrieve the name of the signing algorithm
- sigAlgName = AlgNameMapper.map2AlgName(sigAlgOID);
- if (sigAlgName == null) {
- // if could not be found, use OID as a name
- sigAlgName = sigAlgOID;
- }
+ sigAlgOID = result = tbsCert.getSignature().getAlgorithm();
}
- return sigAlgOID;
+ return result;
}
/**
@@ -353,14 +331,16 @@ public class X509CertImpl extends X509Certificate {
if (nullSigAlgParams) {
return null;
}
- if (sigAlgParams == null) {
- sigAlgParams = tbsCert.getSignature().getParameters();
- if (sigAlgParams == null) {
+ byte[] result = sigAlgParams;
+ if (result == null) {
+ result = tbsCert.getSignature().getParameters();
+ if (result == null) {
nullSigAlgParams = true;
return null;
}
+ sigAlgParams = result;
}
- return sigAlgParams;
+ return result;
}
/**
@@ -464,11 +444,13 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public byte[] getEncoded() throws CertificateEncodingException {
+ return getEncodedInternal().clone();
+ }
+ private byte[] getEncodedInternal() throws CertificateEncodingException {
+ byte[] result = encoding;
if (encoding == null) {
- encoding = certificate.getEncoded();
+ encoding = result = certificate.getEncoded();
}
- byte[] result = new byte[encoding.length];
- System.arraycopy(encoding, 0, result, 0, encoding.length);
return result;
}
@@ -477,12 +459,11 @@ public class X509CertImpl extends X509Certificate {
* method documentation for more information.
*/
public PublicKey getPublicKey() {
- if (publicKey == null) {
- // retrieve the public key from SubjectPublicKeyInfo
- // substructure of X.509 certificate
- publicKey = tbsCert.getSubjectPublicKeyInfo().getPublicKey();
+ PublicKey result = publicKey;
+ if (result == null) {
+ publicKey = result = tbsCert.getSubjectPublicKeyInfo().getPublicKey();
}
- return publicKey;
+ return result;
}
/**
@@ -502,22 +483,17 @@ public class X509CertImpl extends X509Certificate {
throws CertificateException, NoSuchAlgorithmException,
InvalidKeyException, NoSuchProviderException,
SignatureException {
-
- // BEGIN android-added
if (getSigAlgName().endsWith("withRSA")) {
fastVerify(key);
return;
}
- // END android-added
Signature signature = Signature.getInstance(getSigAlgName());
signature.initVerify(key);
// retrieve the encoding of the TBSCertificate structure
- if (tbsCertificate == null) {
- tbsCertificate = tbsCert.getEncoded();
- }
+ byte[] tbsCertificateLocal = getTbsCertificateInternal();
// compute and verify the signature
- signature.update(tbsCertificate, 0, tbsCertificate.length);
+ signature.update(tbsCertificateLocal, 0, tbsCertificateLocal.length);
if (!signature.verify(certificate.getSignatureValue())) {
throw new SignatureException("Signature was not verified");
}
@@ -532,29 +508,23 @@ public class X509CertImpl extends X509Certificate {
throws CertificateException, NoSuchAlgorithmException,
InvalidKeyException, NoSuchProviderException,
SignatureException {
-
- // BEGIN android-added
if (getSigAlgName().endsWith("withRSA")) {
fastVerify(key);
return;
}
- // END android-added
Signature signature =
Signature.getInstance(getSigAlgName(), sigProvider);
signature.initVerify(key);
// retrieve the encoding of the TBSCertificate structure
- if (tbsCertificate == null) {
- tbsCertificate = tbsCert.getEncoded();
- }
+ byte[] tbsCertificateLocal = getTbsCertificateInternal();
// compute and verify the signature
- signature.update(tbsCertificate, 0, tbsCertificate.length);
+ signature.update(tbsCertificateLocal, 0, tbsCertificateLocal.length);
if (!signature.verify(certificate.getSignatureValue())) {
throw new SignatureException("Signature was not verified");
}
}
- // BEGIN android-added
/**
* Implements a faster RSA verification method that delegates to OpenSSL
* native code. In all other aspects it behaves just like the ordinary
@@ -586,16 +556,12 @@ public class X509CertImpl extends X509Certificate {
int i = algorithm.indexOf("with");
algorithm = algorithm.substring(i + 4) + "-" + algorithm.substring(0, i);
- if (tbsCertificate == null) {
- tbsCertificate = tbsCert.getEncoded();
- }
-
+ byte[] tbsCertificateLocal = getTbsCertificateInternal();
byte[] sig = certificate.getSignatureValue();
- if (!NativeCrypto.verifySignature(tbsCertificate, sig, algorithm, rsaKey)) {
+ if (!NativeCrypto.verifySignature(tbsCertificateLocal, sig, algorithm, rsaKey)) {
throw new SignatureException("Signature was not verified");
}
}
- // END android-added
//
// ----- java.security.cert.X509Extension methods implementations ----
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertPathImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertPathImpl.java
index 8d5f247..e961d1f 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertPathImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/cert/X509CertPathImpl.java
@@ -83,10 +83,8 @@ public class X509CertPathImpl extends CertPath {
public static final int PKCS7 = 1;
// supported encoding names
- private static final String[] encodingsArr =
- new String[] {"PkiPath", "PKCS7"};
- static final List encodings = Collections.unmodifiableList(
- Arrays.asList(encodingsArr));
+ private static final String[] encodingsArr = new String[] {"PkiPath", "PKCS7"};
+ static final List encodings = Collections.unmodifiableList(Arrays.asList(encodingsArr));
// the list of certificates representing this certification path
private final List certificates;
// PkiPath encoding of the certification path
@@ -107,7 +105,8 @@ public class X509CertPathImpl extends CertPath {
for (int i=0; i<size; i++) {
Object cert = certs.get(i);
if (!(cert instanceof X509Certificate) ) {
- throw new CertificateException("One of the provided certificates is not an X509 certificate");
+ throw new CertificateException(
+ "One of the provided certificates is not an X509 certificate");
}
certificates.add(cert);
}
@@ -140,8 +139,7 @@ public class X509CertPathImpl extends CertPath {
* @throws CertificateException if some problems occurred during
* the decoding.
*/
- public static X509CertPathImpl getInstance(InputStream in)
- throws CertificateException {
+ public static X509CertPathImpl getInstance(InputStream in) throws CertificateException {
try {
return (X509CertPathImpl) ASN1.decode(in);
} catch (IOException e) {
@@ -157,7 +155,7 @@ public class X509CertPathImpl extends CertPath {
* or some problems occurred during the decoding.
*/
public static X509CertPathImpl getInstance(InputStream in, String encoding)
- throws CertificateException {
+ throws CertificateException {
if (!encodings.contains(encoding)) {
throw new CertificateException("Unsupported encoding");
}
@@ -170,7 +168,8 @@ public class X509CertPathImpl extends CertPath {
ContentInfo ci = (ContentInfo) ContentInfo.ASN1.decode(in);
SignedData sd = ci.getSignedData();
if (sd == null) {
- throw new CertificateException("Incorrect PKCS7 encoded form: missing signed data");
+ throw new CertificateException(
+ "Incorrect PKCS7 encoded form: missing signed data");
}
List certs = sd.getCertificates();
if (certs == null) {
@@ -194,8 +193,7 @@ public class X509CertPathImpl extends CertPath {
* @throws CertificateException if some problems occurred during
* the decoding.
*/
- public static X509CertPathImpl getInstance(byte[] in)
- throws CertificateException {
+ public static X509CertPathImpl getInstance(byte[] in) throws CertificateException {
try {
return (X509CertPathImpl) ASN1.decode(in);
} catch (IOException e) {
@@ -211,7 +209,7 @@ public class X509CertPathImpl extends CertPath {
* or some problems occurred during the decoding.
*/
public static X509CertPathImpl getInstance(byte[] in, String encoding)
- throws CertificateException {
+ throws CertificateException {
if (!encodings.contains(encoding)) {
throw new CertificateException("Unsupported encoding");
}
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPrivateKeyImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPrivateKeyImpl.java
index ea26cf8..c0fc766 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPrivateKeyImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPrivateKeyImpl.java
@@ -152,8 +152,8 @@ public class DSAPrivateKeyImpl extends PrivateKeyImpl implements DSAPrivateKey {
}
private void readObject(java.io.ObjectInputStream in) throws NotActiveException, IOException, ClassNotFoundException {
- in.defaultReadObject();
- params = new DSAParameterSpec(p, q, g);
+ in.defaultReadObject();
+ params = new DSAParameterSpec(p, q, g);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPublicKeyImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPublicKeyImpl.java
index e4420bd..6b35970 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPublicKeyImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/crypto/DSAPublicKeyImpl.java
@@ -164,8 +164,8 @@ public class DSAPublicKeyImpl extends PublicKeyImpl implements DSAPublicKey {
}
private void readObject(java.io.ObjectInputStream in) throws NotActiveException, IOException, ClassNotFoundException {
- in.defaultReadObject();
- params = new DSAParameterSpec(p, q, g);
+ in.defaultReadObject();
+ params = new DSAParameterSpec(p, q, g);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1PRNG_SecureRandomImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1PRNG_SecureRandomImpl.java
index c07e2b1..b99bd0f 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1PRNG_SecureRandomImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1PRNG_SecureRandomImpl.java
@@ -24,6 +24,7 @@ import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.security.InvalidParameterException;
import java.security.SecureRandomSpi;
+import libcore.base.EmptyArray;
/**
* This class extends the SecureRandomSpi class implementing all its abstract methods. <BR>
@@ -197,7 +198,7 @@ public class SHA1PRNG_SecureRandomImpl extends SecureRandomSpi implements Serial
* @throws
* NullPointerException - if null is passed to the "seed" argument
*/
- protected void engineSetSeed(byte[] seed) {
+ protected synchronized void engineSetSeed(byte[] seed) {
if (seed == null) {
throw new NullPointerException("seed == null");
@@ -226,7 +227,7 @@ public class SHA1PRNG_SecureRandomImpl extends SecureRandomSpi implements Serial
* @throws
* InvalidParameterException - if numBytes < 0
*/
- protected byte[] engineGenerateSeed(int numBytes) {
+ protected synchronized byte[] engineGenerateSeed(int numBytes) {
byte[] myBytes; // byte[] for bytes returned by "nextBytes()"
@@ -234,13 +235,12 @@ public class SHA1PRNG_SecureRandomImpl extends SecureRandomSpi implements Serial
throw new NegativeArraySizeException(Integer.toString(numBytes));
}
if (numBytes == 0) {
- return new byte[0];
+ return EmptyArray.BYTE;
}
if (myRandom == null) {
myRandom = new SHA1PRNG_SecureRandomImpl();
- myRandom.engineSetSeed(RandomBitsSupplier
- .getRandomBits(DIGEST_LENGTH));
+ myRandom.engineSetSeed(RandomBitsSupplier.getRandomBits(DIGEST_LENGTH));
}
myBytes = new byte[numBytes];
@@ -265,7 +265,7 @@ public class SHA1PRNG_SecureRandomImpl extends SecureRandomSpi implements Serial
* @throws
* NullPointerException - if null is passed to the "bytes" argument
*/
- protected void engineNextBytes(byte[] bytes) {
+ protected synchronized void engineNextBytes(byte[] bytes) {
int i, n;
diff --git a/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1_MessageDigestImpl.java b/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1_MessageDigestImpl.java
index 82e9e7a..fe8a69e 100644
--- a/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1_MessageDigestImpl.java
+++ b/luni/src/main/java/org/apache/harmony/security/provider/crypto/SHA1_MessageDigestImpl.java
@@ -142,12 +142,9 @@ public class SHA1_MessageDigestImpl extends MessageDigestSpi implements Cloneabl
* a clone of this object
*/
public Object clone() throws CloneNotSupportedException {
-
SHA1_MessageDigestImpl cloneObj = (SHA1_MessageDigestImpl) super.clone();
-
- cloneObj.buffer = ( int[])buffer.clone();
- cloneObj.oneByte = (byte[])oneByte.clone();
-
+ cloneObj.buffer = buffer.clone();
+ cloneObj.oneByte = oneByte.clone();
return cloneObj;
}
@@ -163,9 +160,7 @@ public class SHA1_MessageDigestImpl extends MessageDigestSpi implements Cloneabl
* byte array containing message digest value
*/
protected byte[] engineDigest() {
-
byte[] hash = new byte[DIGEST_LENGTH];
-
processDigest(hash, 0);
return hash;
}
@@ -213,7 +208,7 @@ public class SHA1_MessageDigestImpl extends MessageDigestSpi implements Cloneabl
throw new DigestException("len < DIGEST_LENGTH");
}
if (offset < 0) {
- throw new ArrayIndexOutOfBoundsException(Integer.toString(offset));
+ throw new ArrayIndexOutOfBoundsException(offset);
}
processDigest(buf, offset);
@@ -300,7 +295,7 @@ public class SHA1_MessageDigestImpl extends MessageDigestSpi implements Cloneabl
return;
}
if (offset < 0) {
- throw new ArrayIndexOutOfBoundsException(Integer.toString(offset));
+ throw new ArrayIndexOutOfBoundsException(offset);
}
if (offset > input.length || len > input.length || (len + offset) > input.length) {
throw new IllegalArgumentException();
diff --git a/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValue.java b/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValue.java
index d386c84..6dbf416 100644
--- a/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValue.java
+++ b/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValue.java
@@ -244,7 +244,7 @@ public class AttributeTypeAndValue {
private final ObjectIdentifier oid;
//Attribute value
- private AttributeValue value;
+ private final AttributeValue value;
// for decoder only
private AttributeTypeAndValue(int[] oid, AttributeValue value)
diff --git a/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java b/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java
index f6a011c..160c62d 100644
--- a/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java
+++ b/luni/src/main/java/org/apache/harmony/security/x501/AttributeTypeAndValueComparator.java
@@ -32,9 +32,9 @@ import org.apache.harmony.security.utils.ObjectIdentifier;
*/
public class AttributeTypeAndValueComparator implements Comparator, Serializable {
- private static final long serialVersionUID = -1286471842007103132L;
+ private static final long serialVersionUID = -1286471842007103132L;
- /**
+ /**
* compares two AttributeTypeAndValues
*
* @param obj1
diff --git a/luni/src/main/java/org/apache/harmony/security/x501/AttributeValue.java b/luni/src/main/java/org/apache/harmony/security/x501/AttributeValue.java
index 94ffa45..ecce1e0 100644
--- a/luni/src/main/java/org/apache/harmony/security/x501/AttributeValue.java
+++ b/luni/src/main/java/org/apache/harmony/security/x501/AttributeValue.java
@@ -182,11 +182,8 @@ public class AttributeValue {
StringBuilder buf = new StringBuilder(length * 2);
for (int index = 0; index < length; index++) {
-
char ch = name.charAt(index);
-
switch (ch) {
-
case ' ':
if (index == 0 || index == (length - 1)) {
// escape first or last space
@@ -198,6 +195,9 @@ public class AttributeValue {
case '"':
case '\\':
hasQE = true;
+ buf.append('\\');
+ buf.append(ch);
+ break;
case ',':
case '+':
@@ -207,9 +207,12 @@ public class AttributeValue {
case '#': // required by RFC 1779
case '=': // required by RFC 1779
buf.append('\\');
+ buf.append(ch);
+ break;
default:
buf.append(ch);
+ break;
}
}
diff --git a/luni/src/main/java/org/apache/harmony/security/x501/Name.java b/luni/src/main/java/org/apache/harmony/security/x501/Name.java
index a29c3df..c3c4ffd 100644
--- a/luni/src/main/java/org/apache/harmony/security/x501/Name.java
+++ b/luni/src/main/java/org/apache/harmony/security/x501/Name.java
@@ -185,8 +185,7 @@ public class Name {
if (X500Principal.CANONICAL == format) {
List sortedList = new LinkedList(atavList);
- Collections.sort(sortedList,
- new AttributeTypeAndValueComparator());
+ Collections.sort(sortedList, new AttributeTypeAndValueComparator());
atavList = sortedList;
}
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/AlgorithmIdentifier.java b/luni/src/main/java/org/apache/harmony/security/x509/AlgorithmIdentifier.java
index eeda86b..9298ba5 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/AlgorithmIdentifier.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/AlgorithmIdentifier.java
@@ -143,8 +143,7 @@ public class AlgorithmIdentifier {
}
public int hashCode() {
- return algorithm.hashCode() * 37 +
- (parameters != null ? parameters.hashCode() : 0);
+ return algorithm.hashCode() * 37 + (parameters != null ? parameters.hashCode() : 0);
}
/**
@@ -186,4 +185,3 @@ public class AlgorithmIdentifier {
};
}
-
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/DNParser.java b/luni/src/main/java/org/apache/harmony/security/x509/DNParser.java
index 71cf52c..4f2ccd8 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/DNParser.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/DNParser.java
@@ -273,10 +273,12 @@ public class DNParser {
throw new IOException("Invalid distinguished name string");
}
- switch (chars[pos]) {
+ char ch = chars[pos];
+ switch (ch) {
case '"':
case '\\':
hasQE = true;
+ return ch;
case ',':
case '=':
case '+':
@@ -289,7 +291,7 @@ public class DNParser {
case '%':
case '_':
//FIXME: escaping is allowed only for leading or trailing space char
- return chars[pos];
+ return ch;
default:
// RFC doesn't explicitly say that escaped hex pair is
// interpreted as UTF-8 char. It only contains an example of such DN.
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/Extension.java b/luni/src/main/java/org/apache/harmony/security/x509/Extension.java
index b854c60..f30c73f 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/Extension.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/Extension.java
@@ -239,7 +239,7 @@ public class Extension {
}
public int hashCode() {
- return (extnID.hashCode() * 37 + (critical ? 1 : 0)) * 37 + extnValue.hashCode();
+ return (extnID.hashCode() * 37 + (critical ? 1 : 0)) * 37 + extnValue.hashCode();
}
public ExtensionValue getDecodedExtensionValue() throws IOException {
@@ -456,4 +456,3 @@ public class Extension {
}
};
}
-
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java b/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java
index 2bda81c..9bff5f2 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/Extensions.java
@@ -53,8 +53,8 @@ public class Extensions {
// Supported critical extensions oids:
private static List SUPPORTED_CRITICAL = Arrays.asList(
- new String[] {"2.5.29.15", "2.5.29.19", "2.5.29.32", "2.5.29.17",
- "2.5.29.30", "2.5.29.36", "2.5.29.37", "2.5.29.54"});
+ "2.5.29.15", "2.5.29.19", "2.5.29.32", "2.5.29.17",
+ "2.5.29.30", "2.5.29.36", "2.5.29.37", "2.5.29.54");
// the values of extensions of the structure
private List<Extension> extensions;
@@ -82,18 +82,8 @@ public class Extensions {
this.extensions = extensions;
}
- /**
- * Returns the values of extensions.
- * @return extensions
- */
- public List getExtensions() {
- return extensions;
- }
-
public int size() {
- return (extensions == null)
- ? 0
- : extensions.size();
+ return (extensions == null) ? 0 : extensions.size();
}
/**
@@ -137,7 +127,7 @@ public class Extensions {
critical = new HashSet(size);
noncritical = new HashSet(size);
for (int i=0; i<size; i++) {
- Extension extn = (Extension) extensions.get(i);
+ Extension extn = extensions.get(i);
String oid = extn.getExtnID();
if (extn.getCritical()) {
if (!SUPPORTED_CRITICAL.contains(oid)) {
@@ -385,11 +375,11 @@ public class Extensions {
}
public int hashCode() {
- int hashcode = 0;
- if (extensions != null) {
- hashcode = extensions.hashCode();
- }
- return hashcode;
+ int hashcode = 0;
+ if (extensions != null) {
+ hashcode = extensions.hashCode();
+ }
+ return hashcode;
}
/**
@@ -422,4 +412,3 @@ public class Extensions {
}
};
}
-
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/GeneralName.java b/luni/src/main/java/org/apache/harmony/security/x509/GeneralName.java
index 2a6253b..d52fe89 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/GeneralName.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/GeneralName.java
@@ -324,23 +324,23 @@ public class GeneralName {
return false;
}
- public int hashCode() {
- switch(tag) {
- case RFC822_NAME:
- case DNS_NAME:
- case UR_ID:
- case REG_ID:
- case IP_ADDR:
- return name.hashCode();
- case DIR_NAME:
- case X400_ADDR:
- case OTHER_NAME:
- case EDIP_NAME:
- return getEncoded().hashCode();
- default:
- return super.hashCode();
- }
- }
+ public int hashCode() {
+ switch (tag) {
+ case RFC822_NAME:
+ case DNS_NAME:
+ case UR_ID:
+ case REG_ID:
+ case IP_ADDR:
+ return name.hashCode();
+ case DIR_NAME:
+ case X400_ADDR:
+ case OTHER_NAME:
+ case EDIP_NAME:
+ return getEncoded().hashCode();
+ default:
+ return super.hashCode();
+ }
+ }
/**
* Checks if the other general name is acceptable by this object.
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/ReasonCode.java b/luni/src/main/java/org/apache/harmony/security/x509/ReasonCode.java
index 2c8bae9..d94e8b3 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/ReasonCode.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/ReasonCode.java
@@ -78,7 +78,7 @@ public class ReasonCode extends ExtensionValue {
*/
public byte[] getEncoded() {
if (encoding == null) {
- encoding = ASN1.encode(new byte[] {(byte) code});
+ encoding = ASN1.encode(new byte[] { code });
}
return encoding;
}
@@ -129,4 +129,3 @@ public class ReasonCode extends ExtensionValue {
*/
public static final ASN1Type ASN1 = ASN1Enumerated.getInstance();
}
-
diff --git a/luni/src/main/java/org/apache/harmony/security/x509/TBSCertList.java b/luni/src/main/java/org/apache/harmony/security/x509/TBSCertList.java
index 4944cba..78b294d 100644
--- a/luni/src/main/java/org/apache/harmony/security/x509/TBSCertList.java
+++ b/luni/src/main/java/org/apache/harmony/security/x509/TBSCertList.java
@@ -153,8 +153,8 @@ public class TBSCertList {
}
public int hashCode() {
- return userCertificate.hashCode() * 37 + (int)revocationDate.getTime() / 1000
- + (crlEntryExtensions == null ? 0 : crlEntryExtensions.hashCode());
+ return userCertificate.hashCode() * 37 + (int)revocationDate.getTime() / 1000
+ + (crlEntryExtensions == null ? 0 : crlEntryExtensions.hashCode());
}
/**
@@ -363,9 +363,9 @@ public class TBSCertList {
}
public int hashCode() {
- return ((version * 37 + signature.hashCode()) * 37
- + issuer.getEncoded().hashCode()) * 37
- + (int)thisUpdate.getTime() / 1000;
+ return ((version * 37 + signature.hashCode()) * 37
+ + issuer.getEncoded().hashCode()) * 37
+ + (int)thisUpdate.getTime() / 1000;
}
/**
@@ -448,4 +448,3 @@ public class TBSCertList {
}
};
}
-
diff --git a/luni/src/main/java/org/apache/harmony/text/BidiRun.java b/luni/src/main/java/org/apache/harmony/text/BidiRun.java
index 8cbe8d1..b1490ef 100644
--- a/luni/src/main/java/org/apache/harmony/text/BidiRun.java
+++ b/luni/src/main/java/org/apache/harmony/text/BidiRun.java
@@ -44,12 +44,4 @@ public class BidiRun {
public int getStart() {
return start;
}
-
- @Override
- public boolean equals(Object o) {
- return o == null || o.getClass() != BidiRun.class ? false
- : this.start == ((BidiRun) o).start
- && this.limit == ((BidiRun) o).limit
- && this.level == ((BidiRun) o).level;
- }
}
diff --git a/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java b/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java
index 9eb89e9..01b08f2 100644
--- a/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java
+++ b/luni/src/main/java/org/apache/harmony/xml/ExpatParser.java
@@ -24,6 +24,7 @@ import java.net.URL;
import java.net.URLConnection;
import java.util.logging.Level;
import java.util.logging.Logger;
+import libcore.io.IoUtils;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
@@ -348,8 +349,7 @@ class ExpatParser {
entityParser.parseFragment(reader);
entityParser.append("</externalEntity>");
} finally {
- // TODO: Don't eat original exception when close() throws.
- reader.close();
+ IoUtils.closeQuietly(reader);
}
return;
}
@@ -364,8 +364,7 @@ class ExpatParser {
entityParser.append("</externalEntity>"
.getBytes(entityParser.encoding));
} finally {
- // TODO: Don't eat original exception when close() throws.
- in.close();
+ IoUtils.closeQuietly(in);
}
return;
}
@@ -386,7 +385,7 @@ class ExpatParser {
entityParser.append("</externalEntity>"
.getBytes(entityParser.encoding));
} finally {
- in.close();
+ IoUtils.closeQuietly(in);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xml/ExpatPullParser.java b/luni/src/main/java/org/apache/harmony/xml/ExpatPullParser.java
index c48962a..2ddf464 100644
--- a/luni/src/main/java/org/apache/harmony/xml/ExpatPullParser.java
+++ b/luni/src/main/java/org/apache/harmony/xml/ExpatPullParser.java
@@ -763,7 +763,7 @@ public class ExpatPullParser implements XmlPullParser {
}
if (length == 0) {
- return;
+ return; // TODO: can't happen?
}
flush(parser, length);
diff --git a/luni/src/main/java/org/apache/harmony/xml/ExpatReader.java b/luni/src/main/java/org/apache/harmony/xml/ExpatReader.java
index db2b428..972f3ed 100644
--- a/luni/src/main/java/org/apache/harmony/xml/ExpatReader.java
+++ b/luni/src/main/java/org/apache/harmony/xml/ExpatReader.java
@@ -19,6 +19,7 @@ package org.apache.harmony.xml;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
+import libcore.io.IoUtils;
import org.xml.sax.ContentHandler;
import org.xml.sax.DTDHandler;
import org.xml.sax.EntityResolver;
@@ -261,8 +262,7 @@ public class ExpatReader implements XMLReader {
try {
parse(reader, input.getPublicId(), input.getSystemId());
} finally {
- // TODO: Don't eat original exception when close() throws.
- reader.close();
+ IoUtils.closeQuietly(reader);
}
return;
}
@@ -274,8 +274,7 @@ public class ExpatReader implements XMLReader {
try {
parse(in, encoding, input.getPublicId(), input.getSystemId());
} finally {
- // TODO: Don't eat original exception when close() throws.
- in.close();
+ IoUtils.closeQuietly(in);
}
return;
}
@@ -290,7 +289,7 @@ public class ExpatReader implements XMLReader {
try {
parse(in, encoding, input.getPublicId(), systemId);
} finally {
- in.close();
+ IoUtils.closeQuietly(in);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/AttrImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/AttrImpl.java
index fb98212..4c68249 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/AttrImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/AttrImpl.java
@@ -43,35 +43,16 @@ public final class AttrImpl extends NodeImpl implements Attr {
String prefix;
String localName;
- private String value;
+ private String value = "";
AttrImpl(DocumentImpl document, String namespaceURI, String qualifiedName) {
super(document);
-
setNameNS(this, namespaceURI, qualifiedName);
- value = "";
}
AttrImpl(DocumentImpl document, String name) {
super(document);
-
- this.namespaceAware = false;
-
- int prefixSeparator = name.lastIndexOf(":");
- if (prefixSeparator != -1) {
- String prefix = name.substring(0, prefixSeparator);
- String localName = name.substring(prefixSeparator + 1);
-
- if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
- }
- } else {
- if (!DocumentImpl.isXMLIdentifier(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
- }
- }
-
- this.localName = name;
+ setName(this, name);
}
@Override
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/DOMConfigurationImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/DOMConfigurationImpl.java
index 89c2321..46845b6 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/DOMConfigurationImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/DOMConfigurationImpl.java
@@ -29,7 +29,7 @@ import org.w3c.dom.Node;
/**
* A minimal implementation of DOMConfiguration. This implementation uses inner
- * parameter instances to centralize each parameter's behaviour.
+ * parameter instances to centralize each parameter's behavior.
*/
public final class DOMConfigurationImpl implements DOMConfiguration {
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java
index d1cf342..e1b62fa 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/DocumentImpl.java
@@ -20,7 +20,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.WeakHashMap;
-import org.w3c.dom.Attr;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Comment;
import org.w3c.dom.DOMConfiguration;
@@ -77,10 +76,9 @@ public final class DocumentImpl extends InnerNodeImpl implements Document {
public DocumentImpl(DOMImplementationImpl impl, String namespaceURI,
String qualifiedName, DocumentType doctype, String inputEncoding) {
super(null);
-
+ this.document = this;
this.domImplementation = impl;
this.inputEncoding = inputEncoding;
- this.document = this;
if (doctype != null) {
appendChild(doctype);
@@ -130,67 +128,81 @@ public final class DocumentImpl extends InnerNodeImpl implements Document {
*/
private NodeImpl shallowCopy(short operation, Node node) {
switch (node.getNodeType()) {
- case Node.ATTRIBUTE_NODE:
- Attr attr = (Attr) node;
- AttrImpl attrCopy = createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
+ case Node.ATTRIBUTE_NODE:
+ AttrImpl attr = (AttrImpl) node;
+ AttrImpl attrCopy;
+ if (attr.namespaceAware) {
+ attrCopy = createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
attrCopy.setPrefix(attr.getPrefix());
- attrCopy.setNodeValue(attr.getNodeValue());
- return attrCopy;
+ } else {
+ attrCopy = createAttribute(attr.getName());
+ }
+ attrCopy.setNodeValue(attr.getValue());
+ return attrCopy;
- case Node.CDATA_SECTION_NODE:
- return createCDATASection(((CharacterData) node).getData());
+ case Node.CDATA_SECTION_NODE:
+ return createCDATASection(((CharacterData) node).getData());
- case Node.COMMENT_NODE:
- return createComment(((Comment) node).getData());
+ case Node.COMMENT_NODE:
+ return createComment(((Comment) node).getData());
- case Node.DOCUMENT_FRAGMENT_NODE:
- return createDocumentFragment();
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ return createDocumentFragment();
- case Node.DOCUMENT_NODE:
- case Node.DOCUMENT_TYPE_NODE:
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
- "Cannot copy node of type " + node.getNodeType());
+ case Node.DOCUMENT_NODE:
+ case Node.DOCUMENT_TYPE_NODE:
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
+ "Cannot copy node of type " + node.getNodeType());
- case Node.ELEMENT_NODE:
- Element element = (Element) node;
- ElementImpl elementCopy = createElementNS(
- element.getNamespaceURI(), element.getLocalName());
+ case Node.ELEMENT_NODE:
+ ElementImpl element = (ElementImpl) node;
+ ElementImpl elementCopy;
+ if (element.namespaceAware) {
+ elementCopy = createElementNS(element.getNamespaceURI(), element.getLocalName());
elementCopy.setPrefix(element.getPrefix());
- NamedNodeMap attributes = element.getAttributes();
- for (int i = 0; i < attributes.getLength(); i++) {
- Node elementAttr = attributes.item(i);
- AttrImpl elementAttrCopy = (AttrImpl) shallowCopy(operation, elementAttr);
- notifyUserDataHandlers(operation, elementAttr, elementAttrCopy);
+ } else {
+ elementCopy = createElement(element.getTagName());
+ }
+
+ NamedNodeMap attributes = element.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ AttrImpl elementAttr = (AttrImpl) attributes.item(i);
+ AttrImpl elementAttrCopy = (AttrImpl) shallowCopy(operation, elementAttr);
+ notifyUserDataHandlers(operation, elementAttr, elementAttrCopy);
+ if (elementAttr.namespaceAware) {
elementCopy.setAttributeNodeNS(elementAttrCopy);
+ } else {
+ elementCopy.setAttributeNode(elementAttrCopy);
}
- return elementCopy;
-
- case Node.ENTITY_NODE:
- case Node.NOTATION_NODE:
- // TODO: implement this when we support these node types
- throw new UnsupportedOperationException();
-
- case Node.ENTITY_REFERENCE_NODE:
- /*
- * When we support entities in the doctype, this will need to
- * behave differently for clones vs. imports. Clones copy
- * entities by value, copying the referenced subtree from the
- * original document. Imports copy entities by reference,
- * possibly referring to a different subtree in the new
- * document.
- */
- return createEntityReference(node.getNodeName());
-
- case Node.PROCESSING_INSTRUCTION_NODE:
- ProcessingInstruction pi = (ProcessingInstruction) node;
- return createProcessingInstruction(pi.getTarget(), pi.getData());
-
- case Node.TEXT_NODE:
- return createTextNode(((Text) node).getData());
-
- default:
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
- "Unsupported node type " + node.getNodeType());
+ }
+ return elementCopy;
+
+ case Node.ENTITY_NODE:
+ case Node.NOTATION_NODE:
+ // TODO: implement this when we support these node types
+ throw new UnsupportedOperationException();
+
+ case Node.ENTITY_REFERENCE_NODE:
+ /*
+ * When we support entities in the doctype, this will need to
+ * behave differently for clones vs. imports. Clones copy
+ * entities by value, copying the referenced subtree from the
+ * original document. Imports copy entities by reference,
+ * possibly referring to a different subtree in the new
+ * document.
+ */
+ return createEntityReference(node.getNodeName());
+
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ ProcessingInstruction pi = (ProcessingInstruction) node;
+ return createProcessingInstruction(pi.getTarget(), pi.getData());
+
+ case Node.TEXT_NODE:
+ return createTextNode(((Text) node).getData());
+
+ default:
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
+ "Unsupported node type " + node.getNodeType());
}
}
@@ -374,18 +386,16 @@ public final class DocumentImpl extends InnerNodeImpl implements Document {
return (root == null ? null : root.getElementById(elementId));
}
- public NodeList getElementsByTagName(String tagname) {
- ElementImpl root = (ElementImpl) getDocumentElement();
-
- return (root == null ? new NodeListImpl()
- : root.getElementsByTagName(tagname));
+ public NodeList getElementsByTagName(String name) {
+ NodeListImpl result = new NodeListImpl();
+ getElementsByTagName(result, name);
+ return result;
}
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
- ElementImpl root = (ElementImpl) getDocumentElement();
-
- return (root == null ? new NodeListImpl() : root.getElementsByTagNameNS(
- namespaceURI, localName));
+ NodeListImpl result = new NodeListImpl();
+ getElementsByTagNameNS(result, namespaceURI, localName);
+ return result;
}
public DOMImplementation getImplementation() {
@@ -402,18 +412,20 @@ public final class DocumentImpl extends InnerNodeImpl implements Document {
return Node.DOCUMENT_NODE;
}
- @Override
- public Node insertChildAt(Node newChild, int index) {
- // Make sure we have at most one root element and one DTD element.
- if (newChild instanceof Element && getDocumentElement() != null) {
+ /**
+ * Document elements may have at most one root element and at most one DTD
+ * element.
+ */
+ @Override public Node insertChildAt(Node toInsert, int index) {
+ if (toInsert instanceof Element && getDocumentElement() != null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
"Only one root element allowed");
- } else if (newChild instanceof DocumentType && getDoctype() != null) {
+ }
+ if (toInsert instanceof DocumentType && getDoctype() != null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
"Only one DOCTYPE element allowed");
}
-
- return super.insertChildAt(newChild, index);
+ return super.insertChildAt(toInsert, index);
}
@Override public String getTextContent() {
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/ElementImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/ElementImpl.java
index c019b24..5a043cc 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/ElementImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/ElementImpl.java
@@ -18,6 +18,7 @@ package org.apache.harmony.xml.dom;
import java.util.ArrayList;
import java.util.List;
+import libcore.base.Objects;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
@@ -52,30 +53,13 @@ public class ElementImpl extends InnerNodeImpl implements Element {
ElementImpl(DocumentImpl document, String name) {
super(document);
-
- this.namespaceAware = false;
-
- int p = name.lastIndexOf(":");
- if (p != -1) {
- String prefix = name.substring(0, p);
- String localName = name.substring(p + 1);
-
- if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
- }
- } else {
- if (!DocumentImpl.isXMLIdentifier(name)) {
- throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
- }
- }
-
- this.localName = name;
+ setName(this, name);
}
private int indexOfAttribute(String name) {
for (int i = 0; i < attributes.size(); i++) {
AttrImpl attr = attributes.get(i);
- if (attr.matchesName(name, false)) {
+ if (Objects.equal(name, attr.getNodeName())) {
return i;
}
}
@@ -86,7 +70,8 @@ public class ElementImpl extends InnerNodeImpl implements Element {
private int indexOfAttributeNS(String namespaceURI, String localName) {
for (int i = 0; i < attributes.size(); i++) {
AttrImpl attr = attributes.get(i);
- if (attr.matchesNameNS(namespaceURI, localName, false)) {
+ if (Objects.equal(namespaceURI, attr.getNamespaceURI())
+ && Objects.equal(localName, attr.getLocalName())) {
return i;
}
}
@@ -174,41 +159,15 @@ public class ElementImpl extends InnerNodeImpl implements Element {
}
public NodeList getElementsByTagName(String name) {
- NodeListImpl list = new NodeListImpl();
- getElementsByTagName(list, name);
- return list;
- }
-
- void getElementsByTagName(NodeListImpl list, String name) {
- if (matchesName(name, true)) {
- list.add(this);
- }
-
- for (NodeImpl node : children) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ((ElementImpl) node).getElementsByTagName(list, name);
- }
- }
+ NodeListImpl result = new NodeListImpl();
+ getElementsByTagName(result, name);
+ return result;
}
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) {
- NodeListImpl list = new NodeListImpl();
- getElementsByTagNameNS(list, namespaceURI, localName);
- return list;
- }
-
- void getElementsByTagNameNS(NodeListImpl list, String namespaceURI,
- String localName) {
- if (matchesNameNS(namespaceURI, localName, true)) {
- list.add(this);
- }
-
- for (NodeImpl node : children) {
- if (node.getNodeType() == Node.ELEMENT_NODE) {
- ((ElementImpl) node).getElementsByTagNameNS(list, namespaceURI,
- localName);
- }
- }
+ NodeListImpl result = new NodeListImpl();
+ getElementsByTagNameNS(result, namespaceURI, localName);
+ return result;
}
@Override
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java
index 6fcbfe0..ba4b6e3 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/InnerNodeImpl.java
@@ -18,7 +18,9 @@ package org.apache.harmony.xml.dom;
import java.util.ArrayList;
import java.util.List;
+import libcore.base.Objects;
import org.w3c.dom.DOMException;
+import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -95,38 +97,34 @@ public abstract class InnerNodeImpl extends LeafNodeImpl {
}
/**
- * Inserts a new child node into this node at a given position. If the new
- * node is already child of another node, it is first removed from there.
- * This method is the generalization of the appendChild() and insertBefore()
- * methods.
- *
- * @param newChild The new child node to add.
- * @param index The index at which to insert the new child node.
- *
- * @return The node added.
- *
- * @throws DOMException If the attempted operation violates the XML/DOM
- * well-formedness rules.
+ * Inserts {@code newChild} at {@code index}. If it is already child of
+ * another node, it is removed from there.
*/
- public Node insertChildAt(Node newChild, int index) throws DOMException {
- LeafNodeImpl newChildImpl = (LeafNodeImpl) newChild;
+ Node insertChildAt(Node newChild, int index) throws DOMException {
+ if (newChild instanceof DocumentFragment) {
+ NodeList toAdd = newChild.getChildNodes();
+ for (int i = 0; i < toAdd.getLength(); i++) {
+ insertChildAt(toAdd.item(i), index + i);
+ }
+ return newChild;
+ }
- if (document != null && newChildImpl.document != null && newChildImpl.document != document) {
+ LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
+ if (toInsert.document != null && document != null && toInsert.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
-
- if (newChildImpl.isParentOf(this)) {
+ if (toInsert.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
- if (newChildImpl.parent != null) {
- int oldIndex = newChildImpl.index;
- newChildImpl.parent.children.remove(oldIndex);
- newChildImpl.parent.refreshIndices(oldIndex);
+ if (toInsert.parent != null) {
+ int oldIndex = toInsert.index;
+ toInsert.parent.children.remove(oldIndex);
+ toInsert.parent.refreshIndices(oldIndex);
}
- children.add(index, newChildImpl);
- newChildImpl.parent = this;
+ children.add(index, toInsert);
+ toInsert.parent = this;
refreshIndices(index);
return newChild;
@@ -175,7 +173,6 @@ public abstract class InnerNodeImpl extends LeafNodeImpl {
if (oldChildImpl.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
-
if (oldChildImpl.parent != this) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
@@ -188,26 +185,15 @@ public abstract class InnerNodeImpl extends LeafNodeImpl {
return oldChild;
}
+ /**
+ * Removes {@code oldChild} and adds {@code newChild} in its place. This
+ * is not atomic.
+ */
public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
- LeafNodeImpl oldChildImpl = (LeafNodeImpl) oldChild;
- LeafNodeImpl newChildImpl = (LeafNodeImpl) newChild;
-
- if (oldChildImpl.document != document
- || newChildImpl.document != document) {
- throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
- }
-
- if (oldChildImpl.parent != this || newChildImpl.isParentOf(this)) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
- }
-
- int index = oldChildImpl.index;
- children.set(index, newChildImpl);
- oldChildImpl.parent = null;
- newChildImpl.parent = this;
- refreshIndices(index);
-
- return oldChildImpl;
+ int index = ((LeafNodeImpl) oldChild).index;
+ removeChild(oldChild);
+ insertChildAt(newChild, index);
+ return oldChild;
}
public String getTextContent() throws DOMException {
@@ -241,4 +227,37 @@ public abstract class InnerNodeImpl extends LeafNodeImpl {
return child.getNodeType() != Node.COMMENT_NODE
&& child.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE;
}
+
+ void getElementsByTagName(NodeListImpl out, String name) {
+ for (NodeImpl node : children) {
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ ElementImpl element = (ElementImpl) node;
+ if (matchesNameOrWildcard(name, element.getNodeName())) {
+ out.add(element);
+ }
+ element.getElementsByTagName(out, name);
+ }
+ }
+ }
+
+ void getElementsByTagNameNS(NodeListImpl out, String namespaceURI, String localName) {
+ for (NodeImpl node : children) {
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ ElementImpl element = (ElementImpl) node;
+ if (matchesNameOrWildcard(namespaceURI, element.getNamespaceURI())
+ && matchesNameOrWildcard(localName, element.getLocalName())) {
+ out.add(element);
+ }
+ element.getElementsByTagNameNS(out, namespaceURI, localName);
+ }
+ }
+ }
+
+ /**
+ * Returns true if {@code pattern} equals either "*" or {@code s}. Pattern
+ * may be {@code null}.
+ */
+ private static boolean matchesNameOrWildcard(String pattern, String s) {
+ return "*".equals(pattern) || Objects.equal(pattern, s);
+ }
}
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/NamedNodeMapImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/NamedNodeMapImpl.java
deleted file mode 100644
index d567b47..0000000
--- a/luni/src/main/java/org/apache/harmony/xml/dom/NamedNodeMapImpl.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml.dom;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.w3c.dom.DOMException;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-
-/**
- * Provides a straightforward implementation of the corresponding W3C DOM
- * interface. The class is used internally only, thus only notable members that
- * are not in the original interface are documented (the W3C docs are quite
- * extensive). Hope that's ok.
- * <p>
- * Some of the fields may have package visibility, so other classes belonging to
- * the DOM implementation can easily access them while maintaining the DOM tree
- * structure.
- */
-public class NamedNodeMapImpl implements NamedNodeMap {
-
- private Class<?> type;
-
- private List<NodeImpl> list;
-
- NamedNodeMapImpl(Class<?> type) {
- list = new ArrayList<NodeImpl>();
- this.type = type;
- }
-
- NamedNodeMapImpl(List<NodeImpl> list, Class<?> type) {
- this.list = list;
- this.type = type;
- }
-
- public int getLength() {
- return list.size();
- }
-
- private int indexOfItem(String name) {
- for (int i = 0; i < list.size(); i++) {
- NodeImpl node = list.get(i);
- if (node.matchesName(name, false)) {
- return i;
- }
- }
-
- return -1;
- }
-
- private int indexOfItemNS(String namespaceURI, String localName) {
- for (int i = 0; i < list.size(); i++) {
- NodeImpl node = list.get(i);
- if (node.matchesNameNS(namespaceURI, localName, false)) {
- return i;
- }
- }
-
- return -1;
- }
-
- public Node getNamedItem(String name) {
- int i = indexOfItem(name);
-
- return (i == -1 ? null : item(i));
- }
-
- public Node getNamedItemNS(String namespaceURI, String localName) {
- int i = indexOfItemNS(namespaceURI, localName);
-
- return (i == -1 ? null : item(i));
- }
-
- public Node item(int index) {
- return list.get(index);
- }
-
- public Node removeNamedItem(String name) throws DOMException {
- int i = indexOfItem(name);
-
- if (i == -1) {
- throw new DOMException(DOMException.NOT_FOUND_ERR, null);
- }
-
- return list.remove(i);
- }
-
- public Node removeNamedItemNS(String namespaceURI, String localName)
- throws DOMException {
- int i = indexOfItemNS(namespaceURI, localName);
-
- if (i == -1) {
- throw new DOMException(DOMException.NOT_FOUND_ERR, null);
- }
-
- return list.remove(i);
- }
-
- public Node setNamedItem(Node arg) throws DOMException {
- // Ensure we only accept nodes of the correct type.
- if (!type.isAssignableFrom(arg.getClass())) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
- }
-
- // All nodes in the map must belong to the same document.
- if (list.size() != 0) {
- Document document = list.get(0).document;
-
- if (document != null && arg.getOwnerDocument() != document) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
- }
- }
-
-// TODO Theoretically we should ensure that the nodes don't have a parent.
-// if (newAttrImpl.getOwnerElement() != null) {
-// throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null);
-// }
-
- int i = indexOfItem(arg.getNodeName());
-
- if (i != -1) {
- list.remove(i);
- }
-
- list.add((NodeImpl)arg);
- return arg;
- }
-
- public Node setNamedItemNS(Node arg) throws DOMException {
- // Ensure we only accept nodes of the correct type.
- if (!type.isAssignableFrom(arg.getClass())) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
- }
-
- // All nodes in the map must belong to the same document.
- if (list.size() != 0) {
- Document document = list.get(0).document;
-
- if (document != null && arg.getOwnerDocument() != document) {
- throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
- }
- }
-
-// TODO Theoretically we should ensure that the nodes don't have a parent.
-// if (newAttrImpl.getOwnerElement() != null) {
-// throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, null);
-// }
-
- int i = indexOfItemNS(arg.getNamespaceURI(), arg.getLocalName());
-
- if (i != -1) {
- list.remove(i);
- }
-
- list.add((NodeImpl)arg);
- return arg;
- }
-
-}
diff --git a/luni/src/main/java/org/apache/harmony/xml/dom/NodeImpl.java b/luni/src/main/java/org/apache/harmony/xml/dom/NodeImpl.java
index 31ead86..1b61c59 100644
--- a/luni/src/main/java/org/apache/harmony/xml/dom/NodeImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/dom/NodeImpl.java
@@ -62,6 +62,10 @@ public abstract class NodeImpl implements Node {
}
};
+ /**
+ * The containing document. This is non-null except for DocumentTypeImpl
+ * nodes created by the DOMImplementation.
+ */
DocumentImpl document;
NodeImpl(DocumentImpl document) {
@@ -215,10 +219,10 @@ public abstract class NodeImpl implements Node {
}
/**
- * Sets the element or attribute node to be namespace-aware and assign it
- * the specified name and namespace URI.
+ * Sets {@code node} to be namespace-aware and assigns its namespace URI
+ * and qualified name.
*
- * @param node an AttrImpl or ElementImpl node.
+ * @param node an element or attribute node.
* @param namespaceURI this node's namespace URI. May be null.
* @param qualifiedName a possibly-prefixed name like "img" or "html:img".
*/
@@ -239,77 +243,67 @@ public abstract class NodeImpl implements Node {
}
switch (node.getNodeType()) {
- case ATTRIBUTE_NODE:
- if ("xmlns".equals(qualifiedName)
- && !"http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
- throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
- }
+ case ATTRIBUTE_NODE:
+ if ("xmlns".equals(qualifiedName)
+ && !"http://www.w3.org/2000/xmlns/".equals(namespaceURI)) {
+ throw new DOMException(DOMException.NAMESPACE_ERR, qualifiedName);
+ }
- AttrImpl attr = (AttrImpl) node;
- attr.namespaceAware = true;
- attr.namespaceURI = namespaceURI;
- attr.prefix = prefix;
- attr.localName = qualifiedName;
- break;
+ AttrImpl attr = (AttrImpl) node;
+ attr.namespaceAware = true;
+ attr.namespaceURI = namespaceURI;
+ attr.prefix = prefix;
+ attr.localName = qualifiedName;
+ break;
- case ELEMENT_NODE:
- ElementImpl element = (ElementImpl) node;
- element.namespaceAware = true;
- element.namespaceURI = namespaceURI;
- element.prefix = prefix;
- element.localName = qualifiedName;
- break;
+ case ELEMENT_NODE:
+ ElementImpl element = (ElementImpl) node;
+ element.namespaceAware = true;
+ element.namespaceURI = namespaceURI;
+ element.prefix = prefix;
+ element.localName = qualifiedName;
+ break;
- default:
- throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
- "Cannot rename nodes of type " + node.getNodeType());
+ default:
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
+ "Cannot rename nodes of type " + node.getNodeType());
}
}
/**
- * Checks whether a required string matches an actual string. This utility
- * method is used for comparing namespaces and such. It takes into account
- * null arguments and the "*" special case.
+ * Sets {@code node} to be not namespace-aware and assigns its name.
*
- * @param required The required string.
- * @param actual The actual string.
- * @return True if and only if the actual string matches the required one.
+ * @param node an element or attribute node.
*/
- private static boolean matchesName(String required, String actual, boolean wildcard) {
- if (wildcard && "*".equals(required)) {
- return true;
+ static void setName(NodeImpl node, String name) {
+ int prefixSeparator = name.lastIndexOf(":");
+ if (prefixSeparator != -1) {
+ String prefix = name.substring(0, prefixSeparator);
+ String localName = name.substring(prefixSeparator + 1);
+ if (!DocumentImpl.isXMLIdentifier(prefix) || !DocumentImpl.isXMLIdentifier(localName)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
+ }
+ } else if (!DocumentImpl.isXMLIdentifier(name)) {
+ throw new DOMException(DOMException.INVALID_CHARACTER_ERR, name);
}
- if (required == null) {
- return (actual == null);
+ switch (node.getNodeType()) {
+ case ATTRIBUTE_NODE:
+ AttrImpl attr = (AttrImpl) node;
+ attr.namespaceAware = false;
+ attr.localName = name;
+ break;
+
+ case ELEMENT_NODE:
+ ElementImpl element = (ElementImpl) node;
+ element.namespaceAware = false;
+ element.localName = name;
+ break;
+
+ default:
+ throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
+ "Cannot rename nodes of type " + node.getNodeType());
}
-
- return required.equals(actual);
- }
-
- /**
- * Checks whether this node's name matches a required name. It takes into
- * account null arguments and the "*" special case.
- *
- * @param name The required name.
- * @return True if and only if the actual name matches the required one.
- */
- public boolean matchesName(String name, boolean wildcard) {
- return matchesName(name, getNodeName(), wildcard);
- }
-
- /**
- * Checks whether this node's namespace and local name match a required
- * pair of namespace and local name. It takes into account null arguments
- * and the "*" special case.
- *
- * @param namespaceURI The required namespace.
- * @param localName The required local name.
- * @return True if and only if the actual namespace and local name match
- * the required pair of namespace and local name.
- */
- public boolean matchesNameNS(String namespaceURI, String localName, boolean wildcard) {
- return matchesName(namespaceURI, getNamespaceURI(), wildcard) && matchesName(localName, getLocalName(), wildcard);
}
public final String getBaseURI() {
diff --git a/luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java b/luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
index 224e59e..e2ff801 100644
--- a/luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xml/parsers/DocumentBuilderImpl.java
@@ -19,8 +19,8 @@ package org.apache.harmony.xml.parsers;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
-import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
+import libcore.io.IoUtils;
import org.apache.harmony.xml.dom.CDATASectionImpl;
import org.apache.harmony.xml.dom.DOMImplementationImpl;
import org.apache.harmony.xml.dom.DocumentImpl;
@@ -93,7 +93,7 @@ class DocumentBuilderImpl extends DocumentBuilder {
@Override
public Document parse(InputSource source) throws SAXException, IOException {
if (source == null) {
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("source == null");
}
String namespaceURI = null;
@@ -105,8 +105,8 @@ class DocumentBuilderImpl extends DocumentBuilder {
dom, namespaceURI, qualifiedName, doctype, inputEncoding);
document.setDocumentURI(systemId);
+ KXmlParser parser = new KXmlParser();
try {
- KXmlParser parser = new KXmlParser();
parser.keepNamespaceAttributes();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, namespaceAware);
@@ -121,24 +121,22 @@ class DocumentBuilderImpl extends DocumentBuilder {
// TODO: if null, extract the inputEncoding from the Content-Type header?
parser.setInput(urlConnection.getInputStream(), inputEncoding);
} else {
- throw new SAXParseException(
- "InputSource needs a stream, reader or URI", null);
+ throw new SAXParseException("InputSource needs a stream, reader or URI", null);
}
- if(parser.nextToken() == XmlPullParser.END_DOCUMENT) {
- throw new SAXParseException(
- "Unexpected end of document", null);
+ if (parser.nextToken() == XmlPullParser.END_DOCUMENT) {
+ throw new SAXParseException("Unexpected end of document", null);
}
parse(parser, document, document, XmlPullParser.END_DOCUMENT);
parser.require(XmlPullParser.END_DOCUMENT, null, null);
} catch (XmlPullParserException ex) {
- if(ex.getDetail() instanceof IOException) {
- throw (IOException)ex.getDetail();
+ if (ex.getDetail() instanceof IOException) {
+ throw (IOException) ex.getDetail();
}
- if(ex.getDetail() instanceof RuntimeException) {
- throw (RuntimeException)ex.getDetail();
+ if (ex.getDetail() instanceof RuntimeException) {
+ throw (RuntimeException) ex.getDetail();
}
LocatorImpl locator = new LocatorImpl();
@@ -148,14 +146,15 @@ class DocumentBuilderImpl extends DocumentBuilder {
locator.setLineNumber(ex.getLineNumber());
locator.setColumnNumber(ex.getColumnNumber());
- SAXParseException newEx = new SAXParseException(ex.getMessage(),
- locator);
+ SAXParseException newEx = new SAXParseException(ex.getMessage(), locator);
if (errorHandler != null) {
errorHandler.error(newEx);
}
throw newEx;
+ } finally {
+ IoUtils.closeQuietly(parser);
}
return document;
@@ -178,7 +177,7 @@ class DocumentBuilderImpl extends DocumentBuilder {
* @throws XmlPullParserException If a parsing error occurs.
* @throws IOException If a general IO error occurs.
*/
- private void parse(XmlPullParser parser, DocumentImpl document, Node node,
+ private void parse(KXmlParser parser, DocumentImpl document, Node node,
int endToken) throws XmlPullParserException, IOException {
int token = parser.getEventType();
@@ -205,45 +204,10 @@ class DocumentBuilderImpl extends DocumentBuilder {
node.appendChild(document.createProcessingInstruction(target,
data));
} else if (token == XmlPullParser.DOCDECL) {
- /*
- * Found a document type declaration. Unfortunately KXML doesn't
- * have the necessary details. Do we parse it ourselves, or do
- * we silently ignore it, since it isn't mandatory in DOM 2
- * anyway?
- */
- StringTokenizer tokenizer = new StringTokenizer(parser.getText());
- if (tokenizer.hasMoreTokens()) {
- String name = tokenizer.nextToken();
- String pubid = null;
- String sysid = null;
-
- if (tokenizer.hasMoreTokens()) {
- String text = tokenizer.nextToken();
-
- if ("SYSTEM".equals(text)) {
- if (tokenizer.hasMoreTokens()) {
- sysid = tokenizer.nextToken();
- }
- } else if ("PUBLIC".equals(text)) {
- if (tokenizer.hasMoreTokens()) {
- pubid = tokenizer.nextToken();
- }
- if (tokenizer.hasMoreTokens()) {
- sysid = tokenizer.nextToken();
- }
- }
- }
-
- if (pubid != null && pubid.length() >= 2 && pubid.startsWith("\"") && pubid.endsWith("\"")) {
- pubid = pubid.substring(1, pubid.length() - 1);
- }
-
- if (sysid != null && sysid.length() >= 2 && sysid.startsWith("\"") && sysid.endsWith("\"")) {
- sysid = sysid.substring(1, sysid.length() - 1);
- }
-
- document.appendChild(new DocumentTypeImpl(document, name, pubid, sysid));
- }
+ String name = parser.getRootElementName();
+ String publicId = parser.getPublicId();
+ String systemId = parser.getSystemId();
+ document.appendChild(new DocumentTypeImpl(document, name, publicId, systemId));
} else if (token == XmlPullParser.COMMENT) {
/*
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
index 90035d4..8ee8a33 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/AbstractSessionContext.java
@@ -158,7 +158,7 @@ abstract class AbstractSessionContext implements SSLSessionContext {
* Called when a session is removed. Used by ClientSessionContext
* to update its host-and-port based cache.
*/
- abstract protected void sessionRemoved(SSLSession session);
+ protected abstract void sessionRemoved(SSLSession session);
public final void setSessionCacheSize(int size)
throws IllegalArgumentException {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java
index 748e7df..49f63bf 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CertificateRequest.java
@@ -31,15 +31,6 @@ import javax.security.auth.x500.X500Principal;
public class CertificateRequest extends Message {
/**
- * Client certificate types as defined in
- * TLS 1.0 spec., 7.4.4. Certificate request
- */
- public static final byte RSA_SIGN = 1;
- public static final byte DSS_SIGN = 2;
- public static final byte RSA_FIXED_DH = 3;
- public static final byte DSS_FIXED_DH = 4;
-
- /**
* Requested certificate types
*/
final byte[] certificate_types;
@@ -161,23 +152,12 @@ public class CertificateRequest extends Message {
if (types == null) {
types = new String[certificate_types.length];
for (int i = 0; i < types.length; i++) {
- switch (certificate_types[i]) {
- case 1:
- types[i] = "RSA";
- break;
- case 2:
- types[i] = "DSA";
- break;
- case 3:
- types[i] = "DH_RSA";
- break;
- case 4:
- types[i] = "DH_DSA";
- break;
- default:
+ String type = CipherSuite.getClientKeyType(certificate_types[i]);
+ if (type == null) {
fatalAlert(AlertProtocol.DECODE_ERROR,
"DECODE ERROR: incorrect CertificateRequest");
}
+ types[i] = type;
}
}
return types;
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java
index f712d11..c20a0b9 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/CipherSuite.java
@@ -86,12 +86,21 @@ public class CipherSuite {
static final int KEY_EXCHANGE_DHE_DSS_EXPORT = 4;
static final int KEY_EXCHANGE_DHE_RSA = 5;
static final int KEY_EXCHANGE_DHE_RSA_EXPORT = 6;
- static final int KEY_EXCHANGE_DH_DSS = 7;
- static final int KEY_EXCHANGE_DH_RSA = 8;
+ // BEGIN android-removed
+ // static final int KEY_EXCHANGE_DH_DSS = 7;
+ // static final int KEY_EXCHANGE_DH_RSA = 8;
+ // END android-removed
static final int KEY_EXCHANGE_DH_anon = 9;
static final int KEY_EXCHANGE_DH_anon_EXPORT = 10;
- static final int KEY_EXCHANGE_DH_DSS_EXPORT = 11;
- static final int KEY_EXCHANGE_DH_RSA_EXPORT = 12;
+ // BEGIN android-removed
+ // static final int KEY_EXCHANGE_DH_DSS_EXPORT = 11;
+ // static final int KEY_EXCHANGE_DH_RSA_EXPORT = 12;
+ // END android-removed
+ static final int KEY_EXCHANGE_ECDH_ECDSA = 13;
+ static final int KEY_EXCHANGE_ECDHE_ECDSA = 14;
+ static final int KEY_EXCHANGE_ECDH_RSA = 15;
+ static final int KEY_EXCHANGE_ECDHE_RSA = 16;
+ static final int KEY_EXCHANGE_ECDH_anon = 17;
/**
* TLS cipher suite codes
@@ -143,6 +152,33 @@ public class CipherSuite {
static final byte[] CODE_TLS_DHE_RSA_WITH_AES_256_CBC_SHA = { 0x00, 0x39 };
static final byte[] CODE_TLS_DH_anon_WITH_AES_256_CBC_SHA = { 0x00, 0x3A };
+ // EC Cipher Suites from RFC 4492 - http://www.ietf.org/rfc/rfc4492.txt
+ static final byte[] CODE_TLS_ECDH_ECDSA_WITH_NULL_SHA = { (byte) 0xc0, 0x01};
+ static final byte[] CODE_TLS_ECDH_ECDSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x02};
+ static final byte[] CODE_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x03};
+ static final byte[] CODE_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x04};
+ static final byte[] CODE_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x05};
+ static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_NULL_SHA = { (byte) 0xc0, 0x06};
+ static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x07};
+ static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x08};
+ static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x09};
+ static final byte[] CODE_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x0A};
+ static final byte[] CODE_TLS_ECDH_RSA_WITH_NULL_SHA = { (byte) 0xc0, 0x0B};
+ static final byte[] CODE_TLS_ECDH_RSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x0C};
+ static final byte[] CODE_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x0D};
+ static final byte[] CODE_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x0E};
+ static final byte[] CODE_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x0F};
+ static final byte[] CODE_TLS_ECDHE_RSA_WITH_NULL_SHA = { (byte) 0xc0, 0x10};
+ static final byte[] CODE_TLS_ECDHE_RSA_WITH_RC4_128_SHA = { (byte) 0xc0, 0x11};
+ static final byte[] CODE_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x12};
+ static final byte[] CODE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x13};
+ static final byte[] CODE_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x14};
+ static final byte[] CODE_TLS_ECDH_anon_WITH_NULL_SHA = { (byte) 0xc0, 0x15};
+ static final byte[] CODE_TLS_ECDH_anon_WITH_RC4_128_SHA = { (byte) 0xc0, 0x16};
+ static final byte[] CODE_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA = { (byte) 0xc0, 0x17};
+ static final byte[] CODE_TLS_ECDH_anon_WITH_AES_128_CBC_SHA = { (byte) 0xc0, 0x18};
+ static final byte[] CODE_TLS_ECDH_anon_WITH_AES_256_CBC_SHA = { (byte) 0xc0, 0x19};
+
static final CipherSuite SSL_NULL_WITH_NULL_NULL = new CipherSuite(
"SSL_NULL_WITH_NULL_NULL", true, 0, null, null, null,
CODE_SSL_NULL_WITH_NULL_NULL);
@@ -270,7 +306,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_RSA,
"RSA",
- "AES_128",
+ "AES_128_CBC",
"SHA",
CODE_TLS_RSA_WITH_AES_128_CBC_SHA);
static final CipherSuite TLS_DHE_DSS_WITH_AES_128_CBC_SHA
@@ -278,7 +314,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DHE_DSS,
"DSA",
- "AES_128",
+ "AES_128_CBC",
"SHA",
CODE_TLS_DHE_DSS_WITH_AES_128_CBC_SHA);
static final CipherSuite TLS_DHE_RSA_WITH_AES_128_CBC_SHA
@@ -286,7 +322,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DHE_RSA,
"RSA",
- "AES_128",
+ "AES_128_CBC",
"SHA",
CODE_TLS_DHE_RSA_WITH_AES_128_CBC_SHA);
static final CipherSuite TLS_DH_anon_WITH_AES_128_CBC_SHA
@@ -294,7 +330,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DH_anon,
"DH",
- "AES_128",
+ "AES_128_CBC",
"SHA",
CODE_TLS_DH_anon_WITH_AES_128_CBC_SHA);
static final CipherSuite TLS_RSA_WITH_AES_256_CBC_SHA
@@ -302,7 +338,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_RSA,
"RSA",
- "AES_256",
+ "AES_256_CBC",
"SHA",
CODE_TLS_RSA_WITH_AES_256_CBC_SHA);
static final CipherSuite TLS_DHE_DSS_WITH_AES_256_CBC_SHA
@@ -310,7 +346,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DHE_DSS,
"DSA",
- "AES_256",
+ "AES_256_CBC",
"SHA",
CODE_TLS_DHE_DSS_WITH_AES_256_CBC_SHA);
static final CipherSuite TLS_DHE_RSA_WITH_AES_256_CBC_SHA
@@ -318,7 +354,7 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DHE_RSA,
"RSA",
- "AES_256",
+ "AES_256_CBC",
"SHA",
CODE_TLS_DHE_RSA_WITH_AES_256_CBC_SHA);
static final CipherSuite TLS_DH_anon_WITH_AES_256_CBC_SHA
@@ -326,79 +362,342 @@ public class CipherSuite {
false,
KEY_EXCHANGE_DH_anon,
"DH",
- "AES_256",
+ "AES_256_CBC",
"SHA",
CODE_TLS_DH_anon_WITH_AES_256_CBC_SHA);
- // array for quick access to cipher suite by code
- private static final CipherSuite[] SUITES_BY_CODE = {
+ static final CipherSuite TLS_ECDH_ECDSA_WITH_NULL_SHA
+ = new CipherSuite("TLS_ECDH_ECDSA_WITH_NULL_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_ECDSA,
+ "EC",
+ null,
+ "SHA",
+ CODE_TLS_ECDH_ECDSA_WITH_NULL_SHA);
+ static final CipherSuite TLS_ECDH_ECDSA_WITH_RC4_128_SHA
+ = new CipherSuite("TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_ECDSA,
+ "EC",
+ "RC4_128",
+ "SHA",
+ CODE_TLS_ECDH_ECDSA_WITH_RC4_128_SHA);
+ static final CipherSuite TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
+ = new CipherSuite("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_ECDSA,
+ "EC",
+ "3DES_EDE_CBC",
+ "SHA",
+ CODE_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA);
+ static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
+ = new CipherSuite("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_ECDSA,
+ "EC",
+ "AES_128_CBC",
+ "SHA",
+ CODE_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA);
+ static final CipherSuite TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
+ = new CipherSuite("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_ECDSA,
+ "EC",
+ "AES_256_CBC",
+ "SHA",
+ CODE_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_ECDSA_WITH_NULL_SHA
+ = new CipherSuite("TLS_ECDHE_ECDSA_WITH_NULL_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_ECDSA,
+ "EC",
+ null,
+ "SHA",
+ CODE_TLS_ECDHE_ECDSA_WITH_NULL_SHA);
+ static final CipherSuite TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
+ = new CipherSuite("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_ECDSA,
+ "EC",
+ "RC4_128",
+ "SHA",
+ CODE_TLS_ECDHE_ECDSA_WITH_RC4_128_SHA);
+ static final CipherSuite TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_ECDSA,
+ "EC",
+ "3DES_EDE_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_ECDSA,
+ "EC",
+ "AES_128_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_ECDSA,
+ "EC",
+ "AES_256_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);
+ static final CipherSuite TLS_ECDH_RSA_WITH_NULL_SHA
+ = new CipherSuite("TLS_ECDH_RSA_WITH_NULL_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_RSA,
+ "EC",
+ null,
+ "SHA",
+ CODE_TLS_ECDH_RSA_WITH_NULL_SHA);
+ static final CipherSuite TLS_ECDH_RSA_WITH_RC4_128_SHA
+ = new CipherSuite("TLS_ECDH_RSA_WITH_RC4_128_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_RSA,
+ "EC",
+ "RC4_128",
+ "SHA",
+ CODE_TLS_ECDH_RSA_WITH_RC4_128_SHA);
+ static final CipherSuite TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
+ = new CipherSuite("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_RSA,
+ "EC",
+ "3DES_EDE_CBC",
+ "SHA",
+ CODE_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA);
+ static final CipherSuite TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
+ = new CipherSuite("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_RSA,
+ "EC",
+ "AES_128_CBC",
+ "SHA",
+ CODE_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA);
+ static final CipherSuite TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
+ = new CipherSuite("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_RSA,
+ "EC",
+ "AES_256_CBC",
+ "SHA",
+ CODE_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_RSA_WITH_NULL_SHA
+ = new CipherSuite("TLS_ECDHE_RSA_WITH_NULL_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_RSA,
+ "EC",
+ null,
+ "SHA",
+ CODE_TLS_ECDHE_RSA_WITH_NULL_SHA);
+ static final CipherSuite TLS_ECDHE_RSA_WITH_RC4_128_SHA
+ = new CipherSuite("TLS_ECDHE_RSA_WITH_RC4_128_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_RSA,
+ "EC",
+ "RC4_128",
+ "SHA",
+ CODE_TLS_ECDHE_RSA_WITH_RC4_128_SHA);
+ static final CipherSuite TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_RSA,
+ "EC",
+ "3DES_EDE_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_RSA,
+ "EC",
+ "AES_128_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA);
+ static final CipherSuite TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
+ = new CipherSuite("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDHE_RSA,
+ "EC",
+ "AES_256_CBC",
+ "SHA",
+ CODE_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA);
+ static final CipherSuite TLS_ECDH_anon_WITH_NULL_SHA
+ = new CipherSuite("TLS_ECDH_anon_WITH_NULL_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_anon,
+ "EC",
+ null,
+ "SHA",
+ CODE_TLS_ECDH_anon_WITH_NULL_SHA);
+ static final CipherSuite TLS_ECDH_anon_WITH_RC4_128_SHA
+ = new CipherSuite("TLS_ECDH_anon_WITH_RC4_128_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_anon,
+ "EC",
+ "RC4_128",
+ "SHA",
+ CODE_TLS_ECDH_anon_WITH_RC4_128_SHA);
+ static final CipherSuite TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA
+ = new CipherSuite("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_anon,
+ "EC",
+ "3DES_EDE_CBC",
+ "SHA",
+ CODE_TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA);
+ static final CipherSuite TLS_ECDH_anon_WITH_AES_128_CBC_SHA
+ = new CipherSuite("TLS_ECDH_anon_WITH_AES_128_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_anon,
+ "EC",
+ "AES_128_CBC",
+ "SHA",
+ CODE_TLS_ECDH_anon_WITH_AES_128_CBC_SHA);
+ static final CipherSuite TLS_ECDH_anon_WITH_AES_256_CBC_SHA
+ = new CipherSuite("TLS_ECDH_anon_WITH_AES_256_CBC_SHA",
+ false,
+ KEY_EXCHANGE_ECDH_anon,
+ "EC",
+ "AES_256_CBC",
+ "SHA",
+ CODE_TLS_ECDH_anon_WITH_AES_256_CBC_SHA);
+
+ // arrays for quick access to cipher suite by code
+ private static final CipherSuite[] SUITES_BY_CODE_0x00 = {
// http://www.iana.org/assignments/tls-parameters/tls-parameters.xml
- SSL_NULL_WITH_NULL_NULL, // { 0x00, 0x00 };
- SSL_RSA_WITH_NULL_MD5, // { 0x00, 0x01 };
- SSL_RSA_WITH_NULL_SHA, // { 0x00, 0x02 };
- SSL_RSA_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x03 };
- SSL_RSA_WITH_RC4_128_MD5, // { 0x00, 0x04 };
- SSL_RSA_WITH_RC4_128_SHA, // { 0x00, 0x05 };
+ SSL_NULL_WITH_NULL_NULL, // { 0x00, 0x00 };
+ SSL_RSA_WITH_NULL_MD5, // { 0x00, 0x01 };
+ SSL_RSA_WITH_NULL_SHA, // { 0x00, 0x02 };
+ SSL_RSA_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x03 };
+ SSL_RSA_WITH_RC4_128_MD5, // { 0x00, 0x04 };
+ SSL_RSA_WITH_RC4_128_SHA, // { 0x00, 0x05 };
// BEGIN android-changed
- null, // SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5, // { 0x00, 0x06 };
- null, // TLS_RSA_WITH_IDEA_CBC_SHA, // { 0x00, 0x07 };
+ null, // SSL_RSA_EXPORT_WITH_RC2_CBC_40_MD5, // { 0x00, 0x06 };
+ null, // TLS_RSA_WITH_IDEA_CBC_SHA, // { 0x00, 0x07 };
// END android-changed
- SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x08 };
- SSL_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x09 };
- SSL_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0a };
+ SSL_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x08 };
+ SSL_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x09 };
+ SSL_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0a };
// BEGIN android-changed
- null, // SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA // { 0x00, 0x0b };
- null, // SSL_DH_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x0c };
- null, // SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0d };
- null, // SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x0e };
- null, // SSL_DH_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x0f };
- null, // SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x10 };
+ null, // SSL_DH_DSS_EXPORT_WITH_DES40_CBC_SHA // { 0x00, 0x0b };
+ null, // SSL_DH_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x0c };
+ null, // SSL_DH_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x0d };
+ null, // SSL_DH_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x0e };
+ null, // SSL_DH_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x0f };
+ null, // SSL_DH_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x10 };
// END android-changed
- SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x11 };
- SSL_DHE_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x12 };
- SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x13 };
- SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x14 };
- SSL_DHE_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x15 };
- SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x16 };
- SSL_DH_anon_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x17 };
- SSL_DH_anon_WITH_RC4_128_MD5, // { 0x00, 0x18 };
- SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x19 };
- SSL_DH_anon_WITH_DES_CBC_SHA, // { 0x00, 0x1A };
- SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x1B };
+ SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x11 };
+ SSL_DHE_DSS_WITH_DES_CBC_SHA, // { 0x00, 0x12 };
+ SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x13 };
+ SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x14 };
+ SSL_DHE_RSA_WITH_DES_CBC_SHA, // { 0x00, 0x15 };
+ SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x16 };
+ SSL_DH_anon_EXPORT_WITH_RC4_40_MD5, // { 0x00, 0x17 };
+ SSL_DH_anon_WITH_RC4_128_MD5, // { 0x00, 0x18 };
+ SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA, // { 0x00, 0x19 };
+ SSL_DH_anon_WITH_DES_CBC_SHA, // { 0x00, 0x1A };
+ SSL_DH_anon_WITH_3DES_EDE_CBC_SHA, // { 0x00, 0x1B };
// BEGIN android-added
- null, // SSL_FORTEZZA_KEA_WITH_NULL_SHA // { 0x00, 0x1C };
- null, // SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA // { 0x00, 0x1D };
- null, // TLS_KRB5_WITH_DES_CBC_SHA // { 0x00, 0x1E };
- null, // TLS_KRB5_WITH_3DES_EDE_CBC_SHA // { 0x00, 0x1F };
- null, // TLS_KRB5_WITH_RC4_128_SHA // { 0x00, 0x20 };
- null, // TLS_KRB5_WITH_IDEA_CBC_SHA // { 0x00, 0x21 };
- null, // TLS_KRB5_WITH_DES_CBC_MD5 // { 0x00, 0x22 };
- null, // TLS_KRB5_WITH_3DES_EDE_CBC_MD5 // { 0x00, 0x23 };
- null, // TLS_KRB5_WITH_RC4_128_MD5 // { 0x00, 0x24 };
- null, // TLS_KRB5_WITH_IDEA_CBC_MD5 // { 0x00, 0x25 };
- null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA // { 0x00, 0x26 };
- null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA // { 0x00, 0x27 };
- null, // TLS_KRB5_EXPORT_WITH_RC4_40_SHA // { 0x00, 0x28 };
- null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 // { 0x00, 0x29 };
- null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 // { 0x00, 0x2A };
- null, // TLS_KRB5_EXPORT_WITH_RC4_40_MD5 // { 0x00, 0x2B };
- null, // TLS_PSK_WITH_NULL_SHA // { 0x00, 0x2C };
- null, // TLS_DHE_PSK_WITH_NULL_SHA // { 0x00, 0x2D };
- null, // TLS_RSA_PSK_WITH_NULL_SHA // { 0x00, 0x2E };
- TLS_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x2F };
- null, // TLS_DH_DSS_WITH_AES_128_CBC_SHA // { 0x00, 0x30 };
- null, // TLS_DH_RSA_WITH_AES_128_CBC_SHA // { 0x00, 0x31 };
- TLS_DHE_DSS_WITH_AES_128_CBC_SHA, // { 0x00, 0x32 };
- TLS_DHE_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x33 };
- TLS_DH_anon_WITH_AES_128_CBC_SHA, // { 0x00, 0x34 };
- TLS_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x35 };
- null, // TLS_DH_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x36 };
- null, // TLS_DH_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x37 };
- TLS_DHE_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x38 };
- TLS_DHE_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x39 };
- TLS_DH_anon_WITH_AES_256_CBC_SHA, // { 0x00, 0x3A };
+ null, // SSL_FORTEZZA_KEA_WITH_NULL_SHA // { 0x00, 0x1C };
+ null, // SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA // { 0x00, 0x1D };
+ null, // TLS_KRB5_WITH_DES_CBC_SHA // { 0x00, 0x1E };
+ null, // TLS_KRB5_WITH_3DES_EDE_CBC_SHA // { 0x00, 0x1F };
+ null, // TLS_KRB5_WITH_RC4_128_SHA // { 0x00, 0x20 };
+ null, // TLS_KRB5_WITH_IDEA_CBC_SHA // { 0x00, 0x21 };
+ null, // TLS_KRB5_WITH_DES_CBC_MD5 // { 0x00, 0x22 };
+ null, // TLS_KRB5_WITH_3DES_EDE_CBC_MD5 // { 0x00, 0x23 };
+ null, // TLS_KRB5_WITH_RC4_128_MD5 // { 0x00, 0x24 };
+ null, // TLS_KRB5_WITH_IDEA_CBC_MD5 // { 0x00, 0x25 };
+ null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA // { 0x00, 0x26 };
+ null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA // { 0x00, 0x27 };
+ null, // TLS_KRB5_EXPORT_WITH_RC4_40_SHA // { 0x00, 0x28 };
+ null, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5 // { 0x00, 0x29 };
+ null, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5 // { 0x00, 0x2A };
+ null, // TLS_KRB5_EXPORT_WITH_RC4_40_MD5 // { 0x00, 0x2B };
+ null, // TLS_PSK_WITH_NULL_SHA // { 0x00, 0x2C };
+ null, // TLS_DHE_PSK_WITH_NULL_SHA // { 0x00, 0x2D };
+ null, // TLS_RSA_PSK_WITH_NULL_SHA // { 0x00, 0x2E };
+ TLS_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x2F };
+ null, // TLS_DH_DSS_WITH_AES_128_CBC_SHA // { 0x00, 0x30 };
+ null, // TLS_DH_RSA_WITH_AES_128_CBC_SHA // { 0x00, 0x31 };
+ TLS_DHE_DSS_WITH_AES_128_CBC_SHA, // { 0x00, 0x32 };
+ TLS_DHE_RSA_WITH_AES_128_CBC_SHA, // { 0x00, 0x33 };
+ TLS_DH_anon_WITH_AES_128_CBC_SHA, // { 0x00, 0x34 };
+ TLS_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x35 };
+ null, // TLS_DH_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x36 };
+ null, // TLS_DH_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x37 };
+ TLS_DHE_DSS_WITH_AES_256_CBC_SHA, // { 0x00, 0x38 };
+ TLS_DHE_RSA_WITH_AES_256_CBC_SHA, // { 0x00, 0x39 };
+ TLS_DH_anon_WITH_AES_256_CBC_SHA, // { 0x00, 0x3A };
// END android-added
};
+ private static final CipherSuite[] SUITES_BY_CODE_0xc0 = {
+ null, // { 0xc0, 0x00};
+ TLS_ECDH_ECDSA_WITH_NULL_SHA, // { 0xc0, 0x01};
+ TLS_ECDH_ECDSA_WITH_RC4_128_SHA, // { 0xc0, 0x02};
+ TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x03};
+ TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x04};
+ TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x05};
+ TLS_ECDHE_ECDSA_WITH_NULL_SHA, // { 0xc0, 0x06};
+ TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, // { 0xc0, 0x07};
+ TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x08};
+ TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x09};
+ TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x0A};
+ TLS_ECDH_RSA_WITH_NULL_SHA, // { 0xc0, 0x0B};
+ TLS_ECDH_RSA_WITH_RC4_128_SHA, // { 0xc0, 0x0C};
+ TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x0D};
+ TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x0E};
+ TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x0F};
+ TLS_ECDHE_RSA_WITH_NULL_SHA, // { 0xc0, 0x10};
+ TLS_ECDHE_RSA_WITH_RC4_128_SHA, // { 0xc0, 0x11};
+ TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x12};
+ TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x13};
+ TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x14};
+ TLS_ECDH_anon_WITH_NULL_SHA, // { 0xc0, 0x15};
+ TLS_ECDH_anon_WITH_RC4_128_SHA, // { 0xc0, 0x16};
+ TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x17};
+ TLS_ECDH_anon_WITH_AES_128_CBC_SHA, // { 0xc0, 0x18};
+ TLS_ECDH_anon_WITH_AES_256_CBC_SHA, // { 0xc0, 0x19};
+ // TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1A};
+ // TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1B};
+ // TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x1C};
+ // TLS_SRP_SHA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1D};
+ // TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1E};
+ // TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA, // { 0xc0, 0x1F};
+ // TLS_SRP_SHA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x20};
+ // TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA, // { 0xc0, 0x21};
+ // TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA, // { 0xc0, 0x22};
+ // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x23};
+ // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x24};
+ // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x25};
+ // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x26};
+ // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x27};
+ // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x28};
+ // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x29};
+ // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x2A};
+ // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2B};
+ // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x2C};
+ // TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2D};
+ // TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x2E};
+ // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x2F};
+ // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x30};
+ // TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, // { 0xc0, 0x31};
+ // TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, // { 0xc0, 0x32};
+ // TLS_ECDHE_PSK_WITH_RC4_128_SHA, // { 0xc0, 0x33};
+ // TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA, // { 0xc0, 0x34};
+ // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA, // { 0xc0, 0x35};
+ // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA, // { 0xc0, 0x36};
+ // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256, // { 0xc0, 0x37};
+ // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384, // { 0xc0, 0x38};
+ // TLS_ECDHE_PSK_WITH_NULL_SHA, // { 0xc0, 0x39};
+ // TLS_ECDHE_PSK_WITH_NULL_SHA256, // { 0xc0, 0x3A};
+ // TLS_ECDHE_PSK_WITH_NULL_SHA384, // { 0xc0, 0x3B};
+ };
// hash for quick access to cipher suite by name
private static final Hashtable<String, CipherSuite> SUITES_BY_NAME;
@@ -422,36 +721,14 @@ public class CipherSuite {
static final CipherSuite[] DEFAULT_CIPHER_SUITES;
static {
- int count = 0;
SUITES_BY_NAME = new Hashtable<String, CipherSuite>();
- for (int i = 0; i < SUITES_BY_CODE.length; i++) {
- if (SUITES_BY_CODE[i] == SSL_NULL_WITH_NULL_NULL) {
- continue;
- }
- if (SUITES_BY_CODE[i] == null) {
- continue;
- }
- SUITES_BY_NAME.put(SUITES_BY_CODE[i].getName(), SUITES_BY_CODE[i]);
- if (SUITES_BY_CODE[i].supported) {
- count++;
- }
- }
+ int count_0x00 = registerCipherSuitesByCode(SUITES_BY_CODE_0x00);
+ int count_0xc0 = registerCipherSuitesByCode(SUITES_BY_CODE_0xc0);
+ int count = count_0x00 + count_0xc0;
SUPPORTED_CIPHER_SUITES = new CipherSuite[count];
SUPPORTED_CIPHER_SUITE_NAMES = new String[count];
- count = 0;
- for (int i = 0; i < SUITES_BY_CODE.length; i++) {
- if (SUITES_BY_CODE[i] == SSL_NULL_WITH_NULL_NULL) {
- continue;
- }
- if (SUITES_BY_CODE[i] == null) {
- continue;
- }
- if (SUITES_BY_CODE[i].supported) {
- SUPPORTED_CIPHER_SUITES[count] = SUITES_BY_CODE[i];
- SUPPORTED_CIPHER_SUITE_NAMES[count] = SUPPORTED_CIPHER_SUITES[count].getName();
- count++;
- }
- }
+ registerSupportedCipherSuites(0, SUITES_BY_CODE_0x00);
+ registerSupportedCipherSuites(count_0x00, SUITES_BY_CODE_0xc0);
CipherSuite[] defaultCipherSuites = {
SSL_RSA_WITH_RC4_128_MD5,
@@ -484,6 +761,38 @@ public class CipherSuite {
}
}
}
+ private static int registerCipherSuitesByCode(CipherSuite[] cipherSuites) {
+ int count = 0;
+ for (int i = 0; i < cipherSuites.length; i++) {
+ if (cipherSuites[i] == SSL_NULL_WITH_NULL_NULL) {
+ continue;
+ }
+ if (cipherSuites[i] == null) {
+ continue;
+ }
+ SUITES_BY_NAME.put(cipherSuites[i].getName(), cipherSuites[i]);
+ if (cipherSuites[i].supported) {
+ count++;
+ }
+ }
+ return count;
+ }
+ private static void registerSupportedCipherSuites(int offset, CipherSuite[] cipherSuites) {
+ int count = offset;
+ for (int i = 0; i < cipherSuites.length; i++) {
+ if (cipherSuites[i] == SSL_NULL_WITH_NULL_NULL) {
+ continue;
+ }
+ if (cipherSuites[i] == null) {
+ continue;
+ }
+ if (cipherSuites[i].supported) {
+ SUPPORTED_CIPHER_SUITES[count] = cipherSuites[i];
+ SUPPORTED_CIPHER_SUITE_NAMES[count] = SUPPORTED_CIPHER_SUITES[count].getName();
+ count++;
+ }
+ }
+ }
/**
* Returns CipherSuite by name
@@ -497,12 +806,14 @@ public class CipherSuite {
* @see <a href="http://www.ietf.org/rfc/rfc2246.txt">TLS 1.0 spec., A.5. The CipherSuite</a>
*/
public static CipherSuite getByCode(byte b1, byte b2) {
- if (b1 != 0 || (b2 & 0xFF) > SUITES_BY_CODE.length) {
- // Unknown
- return new CipherSuite("UNKNOWN_" + b1 + "_" + b2, false, 0, null,
- null, null, new byte[] { b1, b2 });
+ int i1 = b1 & 0xff;
+ int i2 = b2 & 0xff;
+ CipherSuite cs = getCipherSuiteByCode(0, i1, i2);
+ if (cs != null) {
+ return cs;
}
- return SUITES_BY_CODE[b2];
+ return new CipherSuite("UNKNOWN_" + i1 + "_" + i2, false, 0, null,
+ null, null, new byte[] { b1, b2 });
}
/**
@@ -510,21 +821,36 @@ public class CipherSuite {
* as described in TLS 1.0 spec., E. Backward Compatibility With SSL
*/
public static CipherSuite getByCode(byte b1, byte b2, byte b3) {
- if (b1 == 0 && b2 == 0) {
- if ((b3 & 0xFF) <= SUITES_BY_CODE.length) {
- return SUITES_BY_CODE[b3];
- }
+ int i1 = b1 & 0xff;
+ int i2 = b2 & 0xff;
+ int i3 = b3 & 0xff;
+ CipherSuite cs = getCipherSuiteByCode(i1, i2, i3);
+ if (cs != null) {
+ return cs;
}
- // as TLSv1 equivalent of V2CipherSpec should be included in
- // V2ClientHello, ignore V2CipherSpec
- return new CipherSuite("UNKNOWN_" + b1 + "_" + b2 + "_" + b3, false, 0,
- null, null, null, new byte[] { b1, b2, b3 });
+ return new CipherSuite("UNKNOWN_" + i1 + "_" + i2 + "_" + i3, false, 0,
+ null, null, null, new byte[] { b1, b2, b3 });
+ }
+
+ private static CipherSuite getCipherSuiteByCode(int i1, int i2, int i3) {
+ CipherSuite[] cipherSuites;
+ if (i1 == 0x00 && i2 == 0x00) {
+ cipherSuites = SUITES_BY_CODE_0x00;
+ } else if (i1 == 0x00 && i2 == 0xc0) {
+ cipherSuites = SUITES_BY_CODE_0xc0;
+ } else {
+ return null;
+ }
+ if (i3 >= cipherSuites.length) {
+ return null;
+ }
+ return cipherSuites[i3];
}
/**
* Creates CipherSuite
*/
- public CipherSuite(String name, boolean isExportable, int keyExchange,
+ private CipherSuite(String name, boolean isExportable, int keyExchange,
String authType, String cipherName, String hash, byte[] code) {
this.name = name;
this.keyExchange = keyExchange;
@@ -588,14 +914,14 @@ public class CipherSuite {
effectiveKeyBytes = 24;
ivSize = 8;
blockSize = 8;
- } else if ("AES_128".equals(cipherName)) {
+ } else if ("AES_128_CBC".equals(cipherName)) {
this.cipherName = "AES/CBC/NoPadding";
keyMaterial = 16;
expandedKeyMaterial = 16;
effectiveKeyBytes = 16;
ivSize = 16;
blockSize = 16;
- } else if ("AES_256".equals(cipherName)) {
+ } else if ("AES_256_CBC".equals(cipherName)) {
this.cipherName = "AES/CBC/NoPadding";
keyMaterial = 32;
expandedKeyMaterial = 32;
@@ -635,6 +961,12 @@ public class CipherSuite {
}
}
+ // We define the Elliptic Curve cipher suites for use with
+ // code shared by OpenSSL, but they are not supported by
+ // SSLEngine or SSLSocket's built with SSLEngine.
+ if (this.name.startsWith("TLS_EC")) {
+ supported = false;
+ }
}
/**
@@ -643,7 +975,8 @@ public class CipherSuite {
*/
public boolean isAnonymous() {
if (keyExchange == KEY_EXCHANGE_DH_anon
- || keyExchange == KEY_EXCHANGE_DH_anon_EXPORT) {
+ || keyExchange == KEY_EXCHANGE_DH_anon_EXPORT
+ || keyExchange == KEY_EXCHANGE_ECDH_anon) {
return true;
}
return false;
@@ -690,19 +1023,6 @@ public class CipherSuite {
}
/**
- * Compares this cipher suite to the specified object.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof CipherSuite
- && this.cipherSuiteCode[0] == ((CipherSuite) obj).cipherSuiteCode[0]
- && this.cipherSuiteCode[1] == ((CipherSuite) obj).cipherSuiteCode[1]) {
- return true;
- }
- return false;
- }
-
- /**
* Returns cipher algorithm name
* @return
*/
@@ -750,5 +1070,126 @@ public class CipherSuite {
return isExportable;
}
-}
+ static final String KEY_TYPE_RSA = "RSA";
+ static final String KEY_TYPE_DSA = "DSA";
+ static final String KEY_TYPE_DH_RSA = "DH_RSA";
+ static final String KEY_TYPE_DH_DSA = "DH_DSA";
+ static final String KEY_TYPE_EC = "EC";
+ static final String KEY_TYPE_EC_EC = "EC_EC";
+ static final String KEY_TYPE_EC_RSA = "EC_RSA";
+ /**
+ * Returns key type constant suitable for calling
+ * X509KeyManager.chooseServerAlias or
+ * X509ExtendedKeyManager.chooseEngineServerAlias.
+ */
+ public String getServerKeyType() {
+ switch (keyExchange) {
+ case KEY_EXCHANGE_DHE_RSA:
+ case KEY_EXCHANGE_DHE_RSA_EXPORT:
+ case KEY_EXCHANGE_ECDHE_RSA:
+ case KEY_EXCHANGE_RSA:
+ case KEY_EXCHANGE_RSA_EXPORT:
+ return KEY_TYPE_RSA;
+ case KEY_EXCHANGE_DHE_DSS:
+ case KEY_EXCHANGE_DHE_DSS_EXPORT:
+ return KEY_TYPE_DSA;
+ case KEY_EXCHANGE_ECDH_ECDSA:
+ case KEY_EXCHANGE_ECDHE_ECDSA:
+ return KEY_TYPE_EC_EC;
+ case KEY_EXCHANGE_ECDH_RSA:
+ return KEY_TYPE_EC_RSA;
+ case KEY_EXCHANGE_DH_anon:
+ case KEY_EXCHANGE_DH_anon_EXPORT:
+ case KEY_EXCHANGE_ECDH_anon:
+ return null;
+ default:
+ throw new IllegalStateException("Unknown key type for key exchange " + keyExchange);
+ }
+ }
+
+ /**
+ * Client certificate types as defined in
+ * TLS 1.0 spec., 7.4.4. Certificate request.
+ * EC constants from RFC 4492.
+ * Names match openssl constants.
+ */
+ static final byte TLS_CT_RSA_SIGN = 1;
+ static final byte TLS_CT_DSS_SIGN = 2;
+ static final byte TLS_CT_RSA_FIXED_DH = 3;
+ static final byte TLS_CT_DSS_FIXED_DH = 4;
+ static final byte TLS_CT_ECDSA_SIGN = 64;
+ static final byte TLS_CT_RSA_FIXED_ECDH = 65;
+ static final byte TLS_CT_ECDSA_FIXED_ECDH = 66;
+
+ /**
+ * Similar to getServerKeyType, but returns value given TLS
+ * ClientCertificateType byte values from a CertificateRequest
+ * message for use with X509KeyManager.chooseClientAlias or
+ * X509ExtendedKeyManager.chooseEngineClientAlias.
+ */
+ public static String getClientKeyType(byte keyType) {
+ // See also http://www.ietf.org/assignments/tls-parameters/tls-parameters.xml
+ switch (keyType) {
+ case TLS_CT_RSA_SIGN:
+ return KEY_TYPE_RSA; // RFC rsa_sign
+ case TLS_CT_DSS_SIGN:
+ return KEY_TYPE_DSA; // RFC dss_sign
+ case TLS_CT_RSA_FIXED_DH:
+ return KEY_TYPE_DH_RSA; // RFC rsa_fixed_dh
+ case TLS_CT_DSS_FIXED_DH:
+ return KEY_TYPE_DH_DSA; // RFC dss_fixed_dh
+ case TLS_CT_ECDSA_SIGN:
+ return KEY_TYPE_EC; // RFC ecdsa_sign
+ case TLS_CT_RSA_FIXED_ECDH:
+ return KEY_TYPE_EC_RSA; // RFC rsa_fixed_ecdh
+ case TLS_CT_ECDSA_FIXED_ECDH:
+ return KEY_TYPE_EC_EC; // RFC ecdsa_fixed_ecdh
+ default:
+ return null;
+ }
+ }
+
+ private static final String AUTH_TYPE_RSA = "RSA";
+ private static final String AUTH_TYPE_RSA_EXPORT = "RSA_EXPORT";
+ private static final String AUTH_TYPE_DHE_DSS = "DHE_DSS";
+ private static final String AUTH_TYPE_DHE_RSA = "DHE_RSA";
+ private static final String AUTH_TYPE_DH_DSS = "DH_DSS";
+ private static final String AUTH_TYPE_DH_RSA = "DH_RSA";
+ private static final String AUTH_TYPE_ECDH_ECDSA = "ECDH_ECDSA";
+ private static final String AUTH_TYPE_ECDH_RSA = "ECDH_RSA";
+ private static final String AUTH_TYPE_ECDHE_ECDSA = "ECDHE_ECDSA";
+ private static final String AUTH_TYPE_ECDHE_RSA = "ECDHE_RSA";
+
+ /**
+ * Returns auth type constant suitable for calling X509TrustManager.checkServerTrusted.
+ */
+ public String getAuthType(boolean emphemeral) {
+ switch (keyExchange) {
+ case KEY_EXCHANGE_RSA:
+ return AUTH_TYPE_RSA;
+ case KEY_EXCHANGE_RSA_EXPORT:
+ return emphemeral ? AUTH_TYPE_RSA_EXPORT : AUTH_TYPE_RSA;
+ case KEY_EXCHANGE_DHE_DSS:
+ case KEY_EXCHANGE_DHE_DSS_EXPORT:
+ return AUTH_TYPE_DHE_DSS;
+ case KEY_EXCHANGE_DHE_RSA:
+ case KEY_EXCHANGE_DHE_RSA_EXPORT:
+ return AUTH_TYPE_DHE_RSA;
+ case KEY_EXCHANGE_ECDH_ECDSA:
+ return AUTH_TYPE_ECDH_ECDSA;
+ case KEY_EXCHANGE_ECDHE_ECDSA:
+ return AUTH_TYPE_ECDHE_ECDSA;
+ case KEY_EXCHANGE_ECDH_RSA:
+ return AUTH_TYPE_ECDH_RSA;
+ case KEY_EXCHANGE_ECDHE_RSA:
+ return AUTH_TYPE_ECDHE_RSA;
+ case KEY_EXCHANGE_DH_anon:
+ case KEY_EXCHANGE_DH_anon_EXPORT:
+ case KEY_EXCHANGE_ECDH_anon:
+ return null;
+ default:
+ throw new IllegalStateException("Unknown auth type for key exchange " + keyExchange);
+ }
+ }
+}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
index 11300f7..a09914e 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHandshakeImpl.java
@@ -93,8 +93,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
session.setPeer(socketOwner.getInetAddress().getHostName(), socketOwner.getPort());
}
// END android-added
- session.protocol = ProtocolVersion.getLatestVersion(parameters
- .getEnabledProtocols());
+ session.protocol = ProtocolVersion.getLatestVersion(parameters.getEnabledProtocols());
recordProtocol.setVersion(session.protocol.version);
} else {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "SSL Session may not be created ");
@@ -117,8 +116,7 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
session.setPeer(socketOwner.getInetAddress().getHostName(), socketOwner.getPort());
}
// END android-added
- session.protocol = ProtocolVersion.getLatestVersion(parameters
- .getEnabledProtocols());
+ session.protocol = ProtocolVersion.getLatestVersion(parameters.getEnabledProtocols());
recordProtocol.setVersion(session.protocol.version);
startSession();
} else {
@@ -198,24 +196,22 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
serverHello = new ServerHello(io_stream, length);
//check protocol version
- ProtocolVersion servProt = ProtocolVersion
- .getByVersion(serverHello.server_version);
+ ProtocolVersion servProt = ProtocolVersion.getByVersion(serverHello.server_version);
String[] enabled = parameters.getEnabledProtocols();
find: {
for (int i = 0; i < enabled.length; i++) {
- if (servProt.equals(ProtocolVersion
- .getByName(enabled[i]))) {
+ if (servProt.equals(ProtocolVersion.getByName(enabled[i]))) {
break find;
}
}
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "Bad server hello protocol version");
+ "Bad server hello protocol version");
}
// check compression method
if (serverHello.compression_method != 0) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "Bad server hello compression method");
+ "Bad server hello compression method");
}
//check cipher_suite
@@ -224,13 +220,12 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
// END android-changed
find: {
for (int i = 0; i < enabledSuites.length; i++) {
- if (serverHello.cipher_suite
- .equals(enabledSuites[i])) {
+ if (serverHello.cipher_suite.equals(enabledSuites[i])) {
break find;
}
}
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "Bad server hello cipher suite");
+ "Bad server hello cipher suite");
}
if (isResuming) {
@@ -242,11 +237,10 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
isResuming = false;
} else if (!session.protocol.equals(servProt)) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "Bad server hello protocol version");
- } else if (!session.cipherSuite
- .equals(serverHello.cipher_suite)) {
+ "Bad server hello protocol version");
+ } else if (!session.cipherSuite.equals(serverHello.cipher_suite)) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "Bad server hello cipher suite");
+ "Bad server hello cipher suite");
}
if (serverHello.server_version[1] == 1) {
computerReferenceVerifyDataTLS("server finished");
@@ -283,12 +277,10 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
unexpectedMessage();
return;
}
- certificateRequest = new CertificateRequest(io_stream,
- length);
+ certificateRequest = new CertificateRequest(io_stream, length);
break;
case 14: // SERVER_HELLO_DONE
- if (serverHello == null || serverHelloDone != null
- || isResuming) {
+ if (serverHello == null || serverHelloDone != null || isResuming) {
unexpectedMessage();
return;
}
@@ -458,29 +450,12 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
return;
}
} else {
- PublicKey serverPublic;
- KeyAgreement agreement = null;
- DHParameterSpec spec;
try {
- KeyFactory kf = null;
- try {
- kf = KeyFactory.getInstance("DH");
- } catch (NoSuchAlgorithmException e) {
- kf = KeyFactory.getInstance("DiffieHellman");
- }
-
- try {
- agreement = KeyAgreement.getInstance("DH");
- } catch (NoSuchAlgorithmException ee) {
- agreement = KeyAgreement.getInstance("DiffieHellman");
- }
-
- KeyPairGenerator kpg = null;
- try {
- kpg = KeyPairGenerator.getInstance("DH");
- } catch (NoSuchAlgorithmException e) {
- kpg = KeyPairGenerator.getInstance("DiffieHellman");
- }
+ KeyFactory kf = KeyFactory.getInstance("DH");
+ KeyAgreement agreement = KeyAgreement.getInstance("DH");
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("DH");
+ PublicKey serverPublic;
+ DHParameterSpec spec;
if (serverKeyExchange != null) {
serverPublic = kf.generatePublic(new DHPublicKeySpec(
serverKeyExchange.par3, serverKeyExchange.par1,
@@ -560,42 +535,12 @@ public class ClientHandshakeImpl extends HandshakeProtocol {
* Verifies certificate path
*/
private void verifyServerCert() {
- String authType = null;
- switch (session.cipherSuite.keyExchange) {
- case 1: // KeyExchange_RSA
- authType = "RSA";
- break;
- case 2: // KeyExchange_RSA_EXPORT
- if (serverKeyExchange != null ) {
- // ephemeral RSA key is used
- authType = "RSA_EXPORT";
- } else {
- authType = "RSA";
- }
- break;
- case 3: // KeyExchange_DHE_DSS
- case 4: // KeyExchange_DHE_DSS_EXPORT
- authType = "DHE_DSS";
- break;
- case 5: // KeyExchange_DHE_RSA
- case 6: // KeyExchange_DHE_RSA_EXPORT
- authType = "DHE_RSA";
- break;
- case 7: // KeyExchange_DH_DSS
- case 11: // KeyExchange_DH_DSS_EXPORT
- authType = "DH_DSS";
- break;
- case 8: // KeyExchange_DH_RSA
- case 12: // KeyExchange_DH_RSA_EXPORT
- authType = "DH_RSA";
- break;
- case 9: // KeyExchange_DH_anon
- case 10: // KeyExchange_DH_anon_EXPORT
+ String authType = session.cipherSuite.getAuthType(serverKeyExchange != null);
+ if (authType == null) {
return;
}
try {
- parameters.getTrustManager().checkServerTrusted(serverCert.certs,
- authType);
+ parameters.getTrustManager().checkServerTrusted(serverCert.certs, authType);
} catch (CertificateException e) {
fatalAlert(AlertProtocol.BAD_CERTIFICATE, "Not trusted server certificate", e);
return;
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java
index 6942894..b39b9e4 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientHello.java
@@ -20,6 +20,7 @@ package org.apache.harmony.xnet.provider.jsse;
import java.io.IOException;
import java.security.SecureRandom;
import java.util.Arrays;
+import libcore.base.EmptyArray;
/**
* Represents Client Hello message
@@ -141,7 +142,7 @@ public class ClientHello extends Message {
if (challenge_length < 16) {
fatalAlert(AlertProtocol.DECODE_ERROR, "DECODE ERROR: incorrect V2ClientHello, short challenge data");
}
- session_id = new byte[0];
+ session_id = EmptyArray.BYTE;
cipher_suites = new CipherSuite[cipher_spec_length/3];
for (int i = 0; i < cipher_suites.length; i++) {
byte b0 = (byte) in.read();
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java
index 4103cf4..3f2daeb 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ClientKeyExchange.java
@@ -19,6 +19,7 @@ package org.apache.harmony.xnet.provider.jsse;
import java.io.IOException;
import java.math.BigInteger;
+import libcore.base.EmptyArray;
/**
* Represents client key exchange message
@@ -79,7 +80,7 @@ public class ClientKeyExchange extends Message {
*
*/
public ClientKeyExchange() {
- exchange_keys = new byte[0];
+ exchange_keys = EmptyArray.BYTE;
length = 0;
isRSA = false;
}
@@ -97,7 +98,7 @@ public class ClientKeyExchange extends Message {
this.isRSA = isRSA;
if (length == 0) {
this.length = 0;
- exchange_keys = new byte[0];
+ exchange_keys = EmptyArray.BYTE;
} else {
int size;
if (isRSA && !isTLS) {// SSL3.0 RSA
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java
index e0ca33c..a100513 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/DigitalSignature.java
@@ -30,6 +30,7 @@ import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.net.ssl.SSLException;
+import libcore.base.EmptyArray;
/**
* This class represents Signature type, as described in TLS v 1.0 Protocol
@@ -190,15 +191,15 @@ public class DigitalSignature {
} else if (cipher != null) {
return cipher.doFinal();
}
- return new byte[0];
+ return EmptyArray.BYTE;
} catch (DigestException e){
- return new byte[0];
+ return EmptyArray.BYTE;
} catch (SignatureException e){
- return new byte[0];
+ return EmptyArray.BYTE;
} catch (BadPaddingException e){
- return new byte[0];
+ return EmptyArray.BYTE;
} catch (IllegalBlockSizeException e){
- return new byte[0];
+ return EmptyArray.BYTE;
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCache.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCache.java
index 31ec396..9558ceb 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCache.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/FileClientSessionCache.java
@@ -31,6 +31,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import javax.net.ssl.SSLSession;
+import libcore.io.IoUtils;
/**
* File-based cache implementation. Only one process should access the
@@ -83,8 +84,7 @@ public class FileClientSessionCache {
Impl(File directory) throws IOException {
boolean exists = directory.exists();
if (exists && !directory.isDirectory()) {
- throw new IOException(directory
- + " exists but is not a directory.");
+ throw new IOException(directory + " exists but is not a directory.");
}
if (exists) {
@@ -95,13 +95,17 @@ public class FileClientSessionCache {
// Note: Sorting an array here was faster than creating a
// HashSet on Dalvik.
initialFiles = directory.list();
+ if (initialFiles == null) {
+ // File.list() will return null in error cases without throwing IOException
+ // http://b/3363561
+ throw new IOException(directory + " exists but cannot list contents.");
+ }
Arrays.sort(initialFiles);
size = initialFiles.length;
} else {
// Create directory.
if (!directory.mkdirs()) {
- throw new IOException("Creation of " + directory
- + " directory failed.");
+ throw new IOException("Creation of " + directory + " directory failed.");
}
size = 0;
}
@@ -172,9 +176,7 @@ public class FileClientSessionCache {
logReadError(host, e);
return null;
} finally {
- try {
- in.close();
- } catch (IOException e) { /* ignore */ }
+ IoUtils.closeQuietly(in);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java
index 9cc988c..fc89d48 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Finished.java
@@ -50,7 +50,7 @@ public class Finished extends Message {
throws IOException {
if (length == 12 || length == 36) {
data = in.read(length);
- length = data.length;
+ this.length = data.length;
} else {
fatalAlert(AlertProtocol.DECODE_ERROR, "DECODE ERROR: incorrect Finished");
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java
index 8fabe29..bd83989 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/HandshakeProtocol.java
@@ -96,7 +96,7 @@ public abstract class HandshakeProtocol {
protected SSLSessionImpl session;
/**
- * Sended and received handshake messages
+ * Sent and received handshake messages
*/
protected ClientHello clientHello;
protected ServerHello serverHello;
@@ -479,8 +479,7 @@ public abstract class HandshakeProtocol {
}
/**
- *
- * Clears previously sended and received handshake messages
+ * Clears previously sent and received handshake messages
*/
protected void clearMessages() {
io_stream.clearBuffer();
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
index 30556fe..802ec52 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/IndexedPKIXParameters.java
@@ -17,101 +17,86 @@
package org.apache.harmony.xnet.provider.jsse;
import java.security.InvalidAlgorithmParameterException;
-import java.security.KeyStoreException;
+import java.security.PublicKey;
import java.security.cert.CertPathValidatorException;
-import java.security.cert.CertificateEncodingException;
import java.security.cert.PKIXParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.security.auth.x500.X500Principal;
/**
* Indexes trust anchors so they can be found in O(1) time instead of O(N).
*/
-public class IndexedPKIXParameters extends PKIXParameters {
+public final class IndexedPKIXParameters extends PKIXParameters {
- final Map<Bytes, TrustAnchor> encodings
- = new HashMap<Bytes, TrustAnchor>();
- final Map<X500Principal, TrustAnchor> bySubject
- = new HashMap<X500Principal, TrustAnchor>();
- final Map<X500Principal, List<TrustAnchor>> byCA
+ private final Map<X500Principal, List<TrustAnchor>> subjectToTrustAnchors
= new HashMap<X500Principal, List<TrustAnchor>>();
public IndexedPKIXParameters(Set<TrustAnchor> anchors)
- throws KeyStoreException, InvalidAlgorithmParameterException,
- CertificateEncodingException {
+ throws InvalidAlgorithmParameterException {
super(anchors);
+ index();
+ }
- for (TrustAnchor anchor : anchors) {
- X509Certificate cert = anchor.getTrustedCert();
-
- Bytes encoded = new Bytes(cert.getEncoded());
- encodings.put(encoded, anchor);
+ private void index() {
+ for (TrustAnchor anchor : getTrustAnchors()) {
+ index(anchor);
+ }
+ }
- X500Principal subject = cert.getSubjectX500Principal();
- if (bySubject.put(subject, anchor) != null) {
- // TODO: Should we allow this?
- throw new KeyStoreException("Two certs have the same subject: "
- + subject);
- }
+ public void index(TrustAnchor anchor) {
+ X500Principal subject;
+ X509Certificate cert = anchor.getTrustedCert();
+ if (cert != null) {
+ subject = cert.getSubjectX500Principal();
+ } else {
+ subject = anchor.getCA();
+ }
- X500Principal ca = anchor.getCA();
- List<TrustAnchor> caAnchors = byCA.get(ca);
- if (caAnchors == null) {
- caAnchors = new ArrayList<TrustAnchor>();
- byCA.put(ca, caAnchors);
+ synchronized (subjectToTrustAnchors) {
+ List<TrustAnchor> anchors = subjectToTrustAnchors.get(subject);
+ if (anchors == null) {
+ anchors = new ArrayList<TrustAnchor>();
+ subjectToTrustAnchors.put(subject, anchors);
}
- caAnchors.add(anchor);
+ anchors.add(anchor);
}
}
public TrustAnchor findTrustAnchor(X509Certificate cert)
throws CertPathValidatorException {
- // Mimic the alg in CertPathValidatorUtilities.findTrustAnchor().
- Exception verificationException = null;
X500Principal issuer = cert.getIssuerX500Principal();
+ Exception verificationException = null;
+ synchronized (subjectToTrustAnchors) {
+ List<TrustAnchor> anchors = subjectToTrustAnchors.get(issuer);
+ if (anchors == null) {
+ return null;
+ }
- List<TrustAnchor> anchors = byCA.get(issuer);
- if (anchors != null) {
- for (TrustAnchor caAnchor : anchors) {
+ for (TrustAnchor anchor : anchors) {
+ PublicKey publicKey;
try {
- cert.verify(caAnchor.getCAPublicKey());
- return caAnchor;
+ X509Certificate caCert = anchor.getTrustedCert();
+ if (caCert != null) {
+ publicKey = caCert.getPublicKey();
+ } else {
+ publicKey = anchor.getCAPublicKey();
+ }
+ cert.verify(publicKey);
+ return anchor;
} catch (Exception e) {
verificationException = e;
}
}
}
- TrustAnchor anchor = bySubject.get(issuer);
- if (anchor != null) {
- try {
- cert.verify(anchor.getTrustedCert().getPublicKey());
- return anchor;
- } catch (Exception e) {
- verificationException = e;
- }
- }
-
- try {
- Bytes encoded = new Bytes(cert.getEncoded());
- anchor = encodings.get(encoded);
- if (anchor != null) {
- return anchor;
- }
- } catch (Exception e) {
- Logger.getLogger(IndexedPKIXParameters.class.getName()).log(
- Level.WARNING, "Error encoding cert.", e);
- }
-
// Throw last verification exception.
if (verificationException != null) {
throw new CertPathValidatorException("TrustAnchor found but"
@@ -122,19 +107,36 @@ public class IndexedPKIXParameters extends PKIXParameters {
return null;
}
- /**
- * Returns true if the given certificate is found in the trusted key
- * store.
- */
- public boolean isDirectlyTrusted(X509Certificate cert) {
- try {
- Bytes encoded = new Bytes(cert.getEncoded());
- return encodings.containsKey(encoded);
- } catch (Exception e) {
- Logger.getLogger(IndexedPKIXParameters.class.getName()).log(
- Level.WARNING, "Error encoding cert.", e);
- return false;
+ public boolean isTrustAnchor(X509Certificate cert) {
+ X500Principal subject = cert.getSubjectX500Principal();
+ synchronized (subjectToTrustAnchors) {
+ List<TrustAnchor> anchors = subjectToTrustAnchors.get(subject);
+ if (anchors == null) {
+ return false;
+ }
+ return isTrustAnchor(cert, anchors);
+ }
+ }
+
+ private static boolean isTrustAnchor(X509Certificate cert, Collection<TrustAnchor> anchors) {
+ PublicKey certPublicKey = cert.getPublicKey();
+ for (TrustAnchor anchor : anchors) {
+ PublicKey caPublicKey;
+ try {
+ X509Certificate caCert = anchor.getTrustedCert();
+ if (caCert != null) {
+ caPublicKey = caCert.getPublicKey();
+ } else {
+ caPublicKey = anchor.getCAPublicKey();
+ }
+ if (caPublicKey.equals(certPublicKey)) {
+ return true;
+ }
+ } catch (Exception e) {
+ // can happen with unsupported public key types
+ }
}
+ return false;
}
/**
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java
index 7df12c0..b5ffa06 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerFactoryImpl.java
@@ -30,6 +30,7 @@ import java.security.cert.CertificateException;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactorySpi;
import javax.net.ssl.ManagerFactoryParameters;
+import libcore.base.EmptyArray;
/**
* KeyManagerFactory implementation.
@@ -56,7 +57,7 @@ public class KeyManagerFactoryImpl extends KeyManagerFactorySpi {
if (password != null) {
pwd = password.clone();
} else {
- pwd = new char[0];
+ pwd = EmptyArray.CHAR;
}
} else {
keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -85,7 +86,7 @@ public class KeyManagerFactoryImpl extends KeyManagerFactorySpi {
}
});
if (keyStorePwd == null) {
- pwd = new char[0];
+ pwd = EmptyArray.CHAR;
} else {
pwd = keyStorePwd.toCharArray();
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java
index ceff289..6955ab1 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/KeyManagerImpl.java
@@ -26,8 +26,10 @@ import java.security.PrivateKey;
import java.security.UnrecoverableEntryException;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import java.util.Vector;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.X509ExtendedKeyManager;
@@ -82,8 +84,8 @@ public class KeyManagerImpl extends X509ExtendedKeyManager {
}
}
- public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
- final String[] al = chooseAlias(keyType, issuers);
+ public String chooseClientAlias(String[] keyTypes, Principal[] issuers, Socket socket) {
+ final String[] al = chooseAlias(keyTypes, issuers);
return (al == null ? null : al[0]);
}
@@ -133,8 +135,8 @@ public class KeyManagerImpl extends X509ExtendedKeyManager {
}
@Override
- public String chooseEngineClientAlias(String[] keyType, Principal[] issuers, SSLEngine engine) {
- final String[] al = chooseAlias(keyType, issuers);
+ public String chooseEngineClientAlias(String[] keyTypes, Principal[] issuers, SSLEngine engine) {
+ final String[] al = chooseAlias(keyTypes, issuers);
return (al == null ? null : al[0]);
}
@@ -144,34 +146,70 @@ public class KeyManagerImpl extends X509ExtendedKeyManager {
return (al == null ? null : al[0]);
}
- private String[] chooseAlias(String[] keyType, Principal[] issuers) {
- if (keyType == null || keyType.length == 0) {
+ private String[] chooseAlias(String[] keyTypes, Principal[] issuers) {
+ if (keyTypes == null || keyTypes.length == 0) {
return null;
}
+ List<Principal> issuersList = (issuers == null) ? null : Arrays.asList(issuers);
Vector<String> found = new Vector<String>();
for (Enumeration<String> aliases = hash.keys(); aliases.hasMoreElements();) {
final String alias = aliases.nextElement();
final KeyStore.PrivateKeyEntry entry = hash.get(alias);
- final Certificate[] certs = entry.getCertificateChain();
- final String alg = certs[0].getPublicKey().getAlgorithm();
- for (int i = 0; i < keyType.length; i++) {
- if (alg.equals(keyType[i])) {
- if (issuers != null && issuers.length != 0) {
- // check that certificate was issued by specified issuer
- loop: for (int ii = 0; ii < certs.length; ii++) {
- if (certs[ii] instanceof X509Certificate) {
- X500Principal issuer = ((X509Certificate) certs[ii])
- .getIssuerX500Principal();
- for (int iii = 0; iii < issuers.length; iii++) {
- if (issuer.equals(issuers[iii])) {
- found.add(alias);
- break loop;
- }
- }
- }
-
- }
- } else {
+ final Certificate[] chain = entry.getCertificateChain();
+ final Certificate cert = chain[0];
+ final String certKeyAlg = cert.getPublicKey().getAlgorithm();
+ final String certSigAlg = (cert instanceof X509Certificate
+ ? ((X509Certificate) cert).getSigAlgName().toUpperCase()
+ : null);
+ for (String keyAlgorithm : keyTypes) {
+ if (keyAlgorithm == null) {
+ continue;
+ }
+ String sigAlgorithm;
+ // handle cases like EC_EC and EC_RSA
+ int index = keyAlgorithm.indexOf('_');
+ if (index == -1) {
+ sigAlgorithm = keyAlgorithm;
+ } else {
+ sigAlgorithm = keyAlgorithm.substring(index + 1);
+ keyAlgorithm = keyAlgorithm.substring(0, index);
+ }
+ // key algorithm does not match
+ if (!certKeyAlg.equals(keyAlgorithm)) {
+ continue;
+ }
+ /*
+ * TODO find a more reliable test for signature
+ * algorithm. Unfortunately value varies with
+ * provider. For example for "EC" it could be
+ * "SHA1WithECDSA" or simply "ECDSA".
+ */
+ // sig algorithm does not match
+ if (certSigAlg != null && !certSigAlg.contains(sigAlgorithm)) {
+ continue;
+ }
+ // no issuers to match, just add to return list and continue
+ if (issuers == null || issuers.length == 0) {
+ found.add(alias);
+ continue;
+ }
+ // check that a certificate in the chain was issued by one of the specified issuers
+ loop: for (Certificate certFromChain : chain) {
+ if (!(certFromChain instanceof X509Certificate)) {
+ // skip non-X509Certificates
+ continue;
+ }
+ X509Certificate xcertFromChain = (X509Certificate) certFromChain;
+ /*
+ * Note use of X500Principal from
+ * getIssuerX500Principal as opposed to Principal
+ * from getIssuerDN. Principal.equals test does
+ * not work in the case where
+ * xcertFromChain.getIssuerDN is a bouncycastle
+ * org.bouncycastle.jce.X509Principal.
+ */
+ X500Principal issuerFromChain = xcertFromChain.getIssuerX500Principal();
+ if (issuersList.contains(issuerFromChain)) {
found.add(alias);
}
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java
index 08c0822..da974f9 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/Logger.java
@@ -20,6 +20,7 @@ package org.apache.harmony.xnet.provider.jsse;
import java.io.PrintStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import libcore.base.EmptyArray;
/**
* This class provides debug logging for JSSE provider implementation
@@ -106,7 +107,7 @@ public class Logger {
}
});
} catch (Exception e) {
- names = new String[0];
+ names = EmptyArray.STRING;
}
}
@@ -119,4 +120,3 @@ public class Logger {
return null;
}
}
-
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java
index ee2b33a..ade8841 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java
@@ -32,6 +32,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.net.ssl.SSLException;
/**
@@ -158,34 +159,55 @@ public final class NativeCrypto {
STANDARD_TO_OPENSSL_CIPHER_SUITES.put(standard, openssl);
}
+ /**
+ * TLS_EMPTY_RENEGOTIATION_INFO_SCSV is RFC 5746's renegotiation
+ * indication signaling cipher suite value. It is not a real
+ * cipher suite. It is just an indication in the default and
+ * supported cipher suite lists indicates that the implementation
+ * supports secure renegotiation.
+ *
+ * In the RI, its presence means that the SCSV is sent in the
+ * cipher suite list to indicate secure renegotiation support and
+ * its absense means to send an empty TLS renegotiation info
+ * extension instead.
+ *
+ * However, OpenSSL doesn't provide an API to give this level of
+ * control, instead always sending the SCSV and always including
+ * the empty renegotiation info if TLS is used (as opposed to
+ * SSL). So we simply allow TLS_EMPTY_RENEGOTIATION_INFO_SCSV to
+ * be passed for compatibility as to provide the hint that we
+ * support secure renegotiation.
+ */
+ public static String TLS_EMPTY_RENEGOTIATION_INFO_SCSV
+ = "TLS_EMPTY_RENEGOTIATION_INFO_SCSV";
+
static {
// Note these are added in priority order
- // Android doesn't currently support Elliptic Curve
add("SSL_RSA_WITH_RC4_128_MD5", "RC4-MD5");
add("SSL_RSA_WITH_RC4_128_SHA", "RC4-SHA");
add("TLS_RSA_WITH_AES_128_CBC_SHA", "AES128-SHA");
add("TLS_RSA_WITH_AES_256_CBC_SHA", "AES256-SHA");
- // add("TLS_ECDH_ECDSA_WITH_RC4_128_SHA", "ECDH-ECDSA-RC4-SHA");
- // add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", "ECDH-ECDSA-AES128-SHA");
- // add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", "ECDH-ECDSA-AES256-SHA");
- // add("TLS_ECDH_RSA_WITH_RC4_128_SHA", "ECDH-RSA-RC4-SHA");
- // add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", "ECDH-RSA-AES128-SHA");
- // add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", "ECDH-RSA-AES256-SHA");
- // add("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", "ECDHE-ECDSA-RC4-SHA");
- // add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "ECDHE-ECDSA-AES128-SHA");
- // add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "ECDHE-ECDSA-AES256-SHA");
- // add("TLS_ECDHE_RSA_WITH_RC4_128_SHA", "ECDHE-RSA-RC4-SHA");
- // add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "ECDHE-RSA-AES128-SHA");
- // add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "ECDHE-RSA-AES256-SHA");
+ add("TLS_ECDH_ECDSA_WITH_RC4_128_SHA", "ECDH-ECDSA-RC4-SHA");
+ add("TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", "ECDH-ECDSA-AES128-SHA");
+ add("TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA", "ECDH-ECDSA-AES256-SHA");
+ add("TLS_ECDH_RSA_WITH_RC4_128_SHA", "ECDH-RSA-RC4-SHA");
+ add("TLS_ECDH_RSA_WITH_AES_128_CBC_SHA", "ECDH-RSA-AES128-SHA");
+ add("TLS_ECDH_RSA_WITH_AES_256_CBC_SHA", "ECDH-RSA-AES256-SHA");
+ add("TLS_ECDHE_ECDSA_WITH_RC4_128_SHA", "ECDHE-ECDSA-RC4-SHA");
+ add("TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "ECDHE-ECDSA-AES128-SHA");
+ add("TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "ECDHE-ECDSA-AES256-SHA");
+ add("TLS_ECDHE_RSA_WITH_RC4_128_SHA", "ECDHE-RSA-RC4-SHA");
+ add("TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "ECDHE-RSA-AES128-SHA");
+ add("TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "ECDHE-RSA-AES256-SHA");
add("TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "DHE-RSA-AES128-SHA");
add("TLS_DHE_RSA_WITH_AES_256_CBC_SHA", "DHE-RSA-AES256-SHA");
add("TLS_DHE_DSS_WITH_AES_128_CBC_SHA", "DHE-DSS-AES128-SHA");
add("TLS_DHE_DSS_WITH_AES_256_CBC_SHA", "DHE-DSS-AES256-SHA");
add("SSL_RSA_WITH_3DES_EDE_CBC_SHA", "DES-CBC3-SHA");
- // add("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", "ECDH-ECDSA-DES-CBC3-SHA");
- // add("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", "ECDH-RSA-DES-CBC3-SHA");
- // add("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", "ECDHE-ECDSA-DES-CBC3-SHA");
- // add("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "ECDHE-RSA-DES-CBC3-SHA");
+ add("TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA", "ECDH-ECDSA-DES-CBC3-SHA");
+ add("TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA", "ECDH-RSA-DES-CBC3-SHA");
+ add("TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA", "ECDHE-ECDSA-DES-CBC3-SHA");
+ add("TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA", "ECDHE-RSA-DES-CBC3-SHA");
add("SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA", "EDH-RSA-DES-CBC3-SHA");
add("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA", "EDH-DSS-DES-CBC3-SHA");
add("SSL_RSA_WITH_DES_CBC_SHA", "DES-CBC-SHA");
@@ -197,22 +219,22 @@ public final class NativeCrypto {
add("SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA", "EXP-EDH-DSS-DES-CBC-SHA");
add("SSL_RSA_WITH_NULL_MD5", "NULL-MD5");
add("SSL_RSA_WITH_NULL_SHA", "NULL-SHA");
- // add("TLS_ECDH_ECDSA_WITH_NULL_SHA", "ECDH-ECDSA-NULL-SHA");
- // add("TLS_ECDH_RSA_WITH_NULL_SHA", "ECDH-RSA-NULL-SHA");
- // add("TLS_ECDHE_ECDSA_WITH_NULL_SHA", "ECDHE-ECDSA-NULL-SHA");
- // add("TLS_ECDHE_RSA_WITH_NULL_SHA", "ECDHE-RSA-NULL-SHA");
+ add("TLS_ECDH_ECDSA_WITH_NULL_SHA", "ECDH-ECDSA-NULL-SHA");
+ add("TLS_ECDH_RSA_WITH_NULL_SHA", "ECDH-RSA-NULL-SHA");
+ add("TLS_ECDHE_ECDSA_WITH_NULL_SHA", "ECDHE-ECDSA-NULL-SHA");
+ add("TLS_ECDHE_RSA_WITH_NULL_SHA", "ECDHE-RSA-NULL-SHA");
add("SSL_DH_anon_WITH_RC4_128_MD5", "ADH-RC4-MD5");
add("TLS_DH_anon_WITH_AES_128_CBC_SHA", "ADH-AES128-SHA");
add("TLS_DH_anon_WITH_AES_256_CBC_SHA", "ADH-AES256-SHA");
add("SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", "ADH-DES-CBC3-SHA");
add("SSL_DH_anon_WITH_DES_CBC_SHA", "ADH-DES-CBC-SHA");
- // add("TLS_ECDH_anon_WITH_RC4_128_SHA", "AECDH-RC4-SHA");
- // add("TLS_ECDH_anon_WITH_AES_128_CBC_SHA", "AECDH-AES128-SHA");
- // add("TLS_ECDH_anon_WITH_AES_256_CBC_SHA", "AECDH-AES256-SHA");
- // add("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", "AECDH-DES-CBC3-SHA");
+ add("TLS_ECDH_anon_WITH_RC4_128_SHA", "AECDH-RC4-SHA");
+ add("TLS_ECDH_anon_WITH_AES_128_CBC_SHA", "AECDH-AES128-SHA");
+ add("TLS_ECDH_anon_WITH_AES_256_CBC_SHA", "AECDH-AES256-SHA");
+ add("TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA", "AECDH-DES-CBC3-SHA");
add("SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", "EXP-ADH-RC4-MD5");
add("SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", "EXP-ADH-DES-CBC-SHA");
- // add("TLS_ECDH_anon_WITH_NULL_SHA", "AECDH-NULL-SHA");
+ add("TLS_ECDH_anon_WITH_NULL_SHA", "AECDH-NULL-SHA");
// No Kerberos in Android
// add("TLS_KRB5_WITH_RC4_128_SHA", "KRB5-RC4-SHA");
@@ -245,10 +267,18 @@ public final class NativeCrypto {
// add(null, "PSK-AES128-CBC-SHA");
// add(null, "PSK-AES256-CBC-SHA");
// add(null, "PSK-RC4-SHA");
+
+ // Signaling Cipher Suite Value for secure renegotiation handled as special case.
+ // add("TLS_EMPTY_RENEGOTIATION_INFO_SCSV", null);
}
- private static final String[] SUPPORTED_CIPHER_SUITES
- = STANDARD_TO_OPENSSL_CIPHER_SUITES.keySet().toArray(new String[0]);
+ private static final String[] SUPPORTED_CIPHER_SUITES;
+ static {
+ int size = STANDARD_TO_OPENSSL_CIPHER_SUITES.size();
+ SUPPORTED_CIPHER_SUITES = new String[size + 1];
+ STANDARD_TO_OPENSSL_CIPHER_SUITES.keySet().toArray(SUPPORTED_CIPHER_SUITES);
+ SUPPORTED_CIPHER_SUITES[size] = TLS_EMPTY_RENEGOTIATION_INFO_SCSV;
+ }
// SSL mode from ssl.h
public static long SSL_MODE_HANDSHAKE_CUTTHROUGH = 0x00000040L;
@@ -266,9 +296,28 @@ public final class NativeCrypto {
"SSL_RSA_WITH_RC4_128_MD5",
"SSL_RSA_WITH_RC4_128_SHA",
"TLS_RSA_WITH_AES_128_CBC_SHA",
+ "TLS_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDH_ECDSA_WITH_RC4_128_SHA",
+ "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
+ "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDH_RSA_WITH_RC4_128_SHA",
+ "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
+ "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
+ "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
+ "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
+ "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
"TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
+ "TLS_DHE_DSS_WITH_AES_256_CBC_SHA",
"SSL_RSA_WITH_3DES_EDE_CBC_SHA",
+ "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA",
+ "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
+ "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA",
"SSL_RSA_WITH_DES_CBC_SHA",
@@ -277,7 +326,8 @@ public final class NativeCrypto {
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
- "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"
+ "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA",
+ TLS_EMPTY_RENEGOTIATION_INFO_SCSV
};
}
@@ -289,31 +339,6 @@ public final class NativeCrypto {
public static native int SSL_new(int ssl_ctx) throws SSLException;
- public static final String[] KEY_TYPES = new String[] {
- "RSA",
- "DSA",
- "DH_RSA",
- "DH_DSA",
- "EC"
- };
-
- public static String keyType(int keyType) {
- switch (keyType) {
- case 1: // TLS_CT_RSA_SIGN
- return "RSA";
- case 2: // TLS_CT_DSS_SIGN
- return "DSA";
- case 3: // TLS_CT_RSA_FIXED_DH
- return "DH_RSA";
- case 4: // TLS_CT_DSS_FIXED_DH
- return "DH_DSA";
- case 64: // TLS_CT_ECDSA_SIGN
- return "EC";
- default:
- return null;
- }
- }
-
public static byte[][] encodeCertificates(Certificate[] certificates)
throws CertificateEncodingException {
byte[][] certificateBytes = new byte[certificates.length][];
@@ -406,6 +431,9 @@ public final class NativeCrypto {
List<String> opensslSuites = new ArrayList<String>();
for (int i = 0; i < cipherSuites.length; i++) {
String cipherSuite = cipherSuites[i];
+ if (cipherSuite.equals(TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) {
+ continue;
+ }
String openssl = STANDARD_TO_OPENSSL_CIPHER_SUITES.get(cipherSuite);
String cs = (openssl == null) ? cipherSuite : openssl;
opensslSuites.add(cs);
@@ -423,6 +451,9 @@ public final class NativeCrypto {
if (cipherSuite == null) {
throw new IllegalArgumentException("cipherSuites[" + i + "] == null");
}
+ if (cipherSuite.equals(TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) {
+ continue;
+ }
if (STANDARD_TO_OPENSSL_CIPHER_SUITES.containsKey(cipherSuite)) {
continue;
}
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java
index 3d7e4a4..1900d04 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.security.PrivateKey;
+import java.security.interfaces.ECPrivateKey;
import java.security.interfaces.DSAPrivateKey;
import java.security.interfaces.RSAPrivateKey;
import javax.net.ssl.SSLException;
@@ -207,54 +208,37 @@ public class OpenSSLServerSocketImpl extends javax.net.ssl.SSLServerSocket {
* an anonymous cipher is picked.
*/
for (String enabledCipherSuite : enabledCipherSuites) {
- CipherSuite cipherSuite = CipherSuite.getByName(enabledCipherSuite);
-
- int keyExchange;
- if (cipherSuite == null) {
- // An NativeCrypto cipher suite unknown to the Java
- // implementation, use some safe heuristics
- if (enabledCipherSuite.contains("_RSA_")) {
- keyExchange = CipherSuite.KEY_EXCHANGE_RSA;
- } else if (enabledCipherSuite.contains("_DSS_")) {
- keyExchange = CipherSuite.KEY_EXCHANGE_DH_DSS;
- } else if (enabledCipherSuite.contains("_anon_")) {
- keyExchange = CipherSuite.KEY_EXCHANGE_DH_anon;
- } else {
- keyExchange = -1;
+ if (enabledCipherSuite.equals(NativeCrypto.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) {
+ continue;
+ }
+ String keyType = CipherSuite.getByName(enabledCipherSuite).getServerKeyType();
+ if (keyType == null) {
+ // anonymous always work
+ return;
+ }
+ if (keyType.equals(CipherSuite.KEY_TYPE_RSA)
+ || keyType.equals(CipherSuite.KEY_TYPE_DH_RSA)) {
+ if (checkForPrivateKey(keyType, RSAPrivateKey.class)) {
+ return;
}
- } else {
- keyExchange = cipherSuite.keyExchange;
+ continue;
}
-
- switch (keyExchange) {
- case CipherSuite.KEY_EXCHANGE_DHE_RSA:
- case CipherSuite.KEY_EXCHANGE_DHE_RSA_EXPORT:
- case CipherSuite.KEY_EXCHANGE_DH_RSA:
- case CipherSuite.KEY_EXCHANGE_DH_RSA_EXPORT:
- case CipherSuite.KEY_EXCHANGE_RSA:
- case CipherSuite.KEY_EXCHANGE_RSA_EXPORT:
- if (checkForPrivateKey("RSA", RSAPrivateKey.class)) {
- return;
- }
- continue;
-
- case CipherSuite.KEY_EXCHANGE_DHE_DSS:
- case CipherSuite.KEY_EXCHANGE_DHE_DSS_EXPORT:
- case CipherSuite.KEY_EXCHANGE_DH_DSS:
- case CipherSuite.KEY_EXCHANGE_DH_DSS_EXPORT:
- if (checkForPrivateKey("DSA", DSAPrivateKey.class)) {
- return;
- }
- continue;
-
- case CipherSuite.KEY_EXCHANGE_DH_anon:
- case CipherSuite.KEY_EXCHANGE_DH_anon_EXPORT:
- // anonymous always works
+ if (keyType.equals(CipherSuite.KEY_TYPE_DSA)
+ || keyType.equals(CipherSuite.KEY_TYPE_DH_DSA)) {
+ if (checkForPrivateKey(keyType, DSAPrivateKey.class)) {
return;
- default:
- // unknown, just assume it will work
+ }
+ continue;
+ }
+ if (keyType.equals(CipherSuite.KEY_TYPE_EC)
+ || keyType.equals(CipherSuite.KEY_TYPE_EC_RSA)
+ || keyType.equals(CipherSuite.KEY_TYPE_EC_EC)) {
+ if (checkForPrivateKey(keyType, ECPrivateKey.class)) {
return;
+ }
+ continue;
}
+ throw new IllegalStateException("Unknown key type " + keyType);
}
throw new SSLException("Could not find any key store entries "
+ "to support the enabled cipher suites.");
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketFactoryImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketFactoryImpl.java
index 756030b..41c58b6 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketFactoryImpl.java
@@ -24,23 +24,25 @@ import java.security.KeyManagementException;
public class OpenSSLSocketFactoryImpl extends javax.net.ssl.SSLSocketFactory {
- private SSLParametersImpl sslParameters;
- private IOException instantiationException;
+ private final SSLParametersImpl sslParameters;
+ private final IOException instantiationException;
public OpenSSLSocketFactoryImpl() {
- super();
+ SSLParametersImpl sslParametersLocal = null;
+ IOException instantiationExceptionLocal = null;
try {
- sslParameters = SSLParametersImpl.getDefault();
+ sslParametersLocal = SSLParametersImpl.getDefault();
} catch (KeyManagementException e) {
- instantiationException =
- new IOException("Delayed instantiation exception:");
- instantiationException.initCause(e);
+ instantiationExceptionLocal = new IOException("Delayed instantiation exception:");
+ instantiationExceptionLocal.initCause(e);
}
+ this.sslParameters = sslParametersLocal;
+ this.instantiationException = instantiationExceptionLocal;
}
public OpenSSLSocketFactoryImpl(SSLParametersImpl sslParameters) {
- super();
this.sslParameters = sslParameters;
+ this.instantiationException = null;
}
public String[] getDefaultCipherSuites() {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
index 36e7d09..d84e28a 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
@@ -17,6 +17,7 @@
package org.apache.harmony.xnet.provider.jsse;
import dalvik.system.BlockGuard;
+import dalvik.system.CloseGuard;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
@@ -30,6 +31,9 @@ import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import javax.net.ssl.HandshakeCompletedEvent;
@@ -37,6 +41,7 @@ import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
+import javax.net.ssl.X509TrustManager;
import javax.security.auth.x500.X500Principal;
import org.apache.harmony.security.provider.cert.X509CertImpl;
@@ -75,6 +80,7 @@ public class OpenSSLSocketImpl
private final FileDescriptor fd;
private boolean autoClose;
private boolean handshakeStarted = false;
+ private final CloseGuard guard = CloseGuard.get();
/**
* Not set to true until the update from native that tells us the
@@ -100,16 +106,6 @@ public class OpenSSLSocketImpl
private String wrappedHost;
private int wrappedPort;
- private static final AtomicInteger instanceCount = new AtomicInteger(0);
-
- public static int getInstanceCount() {
- return instanceCount.get();
- }
-
- private static void updateInstanceCount(int amount) {
- instanceCount.addAndGet(amount);
- }
-
/**
* Class constructor with 1 parameter
*
@@ -246,7 +242,6 @@ public class OpenSSLSocketImpl
this.enabledProtocols = enabledProtocols;
this.enabledCipherSuites = enabledCipherSuites;
this.enabledCompressionMethods = enabledCompressionMethods;
- updateInstanceCount(1);
}
/**
@@ -369,160 +364,184 @@ public class OpenSSLSocketImpl
sslParameters.getClientSessionContext().sslCtxNativePointer :
sslParameters.getServerSessionContext().sslCtxNativePointer;
- this.sslNativePointer = NativeCrypto.SSL_new(sslCtxNativePointer);
-
- // setup server certificates and private keys.
- // clients will receive a call back to request certificates.
- if (!client) {
- for (String keyType : NativeCrypto.KEY_TYPES) {
- try {
- setCertificate(sslParameters.getKeyManager().chooseServerAlias(keyType,
- null,
- this));
- } catch (CertificateEncodingException e) {
- throw new IOException(e);
+ this.sslNativePointer = 0;
+ boolean exception = true;
+ try {
+ sslNativePointer = NativeCrypto.SSL_new(sslCtxNativePointer);
+ guard.open("close");
+
+ // setup server certificates and private keys.
+ // clients will receive a call back to request certificates.
+ if (!client) {
+ Set<String> keyTypes = new HashSet<String>();
+ for (String enabledCipherSuite : enabledCipherSuites) {
+ if (enabledCipherSuite.equals(NativeCrypto.TLS_EMPTY_RENEGOTIATION_INFO_SCSV)) {
+ continue;
+ }
+ String keyType = CipherSuite.getByName(enabledCipherSuite).getServerKeyType();
+ if (keyType != null) {
+ keyTypes.add(keyType);
+ }
+ }
+ for (String keyType : keyTypes) {
+ try {
+ setCertificate(sslParameters.getKeyManager().chooseServerAlias(keyType,
+ null,
+ this));
+ } catch (CertificateEncodingException e) {
+ throw new IOException(e);
+ }
}
}
- }
-
- NativeCrypto.setEnabledProtocols(sslNativePointer, enabledProtocols);
- NativeCrypto.setEnabledCipherSuites(sslNativePointer, enabledCipherSuites);
- if (enabledCompressionMethods.length != 0) {
- NativeCrypto.setEnabledCompressionMethods(sslNativePointer, enabledCompressionMethods);
- }
- if (useSessionTickets) {
- NativeCrypto.SSL_clear_options(sslNativePointer, NativeCrypto.SSL_OP_NO_TICKET);
- }
- if (hostname != null) {
- NativeCrypto.SSL_set_tlsext_host_name(sslNativePointer, hostname);
- }
- boolean enableSessionCreation = sslParameters.getEnableSessionCreation();
- if (!enableSessionCreation) {
- NativeCrypto.SSL_set_session_creation_enabled(sslNativePointer,
- enableSessionCreation);
- }
+ NativeCrypto.setEnabledProtocols(sslNativePointer, enabledProtocols);
+ NativeCrypto.setEnabledCipherSuites(sslNativePointer, enabledCipherSuites);
+ if (enabledCompressionMethods.length != 0) {
+ NativeCrypto.setEnabledCompressionMethods(sslNativePointer,
+ enabledCompressionMethods);
+ }
+ if (useSessionTickets) {
+ NativeCrypto.SSL_clear_options(sslNativePointer, NativeCrypto.SSL_OP_NO_TICKET);
+ }
+ if (hostname != null) {
+ NativeCrypto.SSL_set_tlsext_host_name(sslNativePointer, hostname);
+ }
- AbstractSessionContext sessionContext;
- OpenSSLSessionImpl session;
- if (client) {
- // look for client session to reuse
- ClientSessionContext clientSessionContext = sslParameters.getClientSessionContext();
- sessionContext = clientSessionContext;
- session = getCachedClientSession(clientSessionContext);
- if (session != null) {
- NativeCrypto.SSL_set_session(sslNativePointer, session.sslSessionNativePointer);
+ boolean enableSessionCreation = sslParameters.getEnableSessionCreation();
+ if (!enableSessionCreation) {
+ NativeCrypto.SSL_set_session_creation_enabled(sslNativePointer,
+ enableSessionCreation);
}
- } else {
- sessionContext = sslParameters.getServerSessionContext();
- session = null;
- }
- // setup peer certificate verification
- if (client) {
- // TODO support for anonymous cipher would require us to
- // conditionally use SSL_VERIFY_NONE
- } else {
- // needing client auth takes priority...
- boolean certRequested = false;
- if (sslParameters.getNeedClientAuth()) {
- NativeCrypto.SSL_set_verify(sslNativePointer,
- NativeCrypto.SSL_VERIFY_PEER
- | NativeCrypto.SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
- certRequested = true;
- // ... over just wanting it...
- } else if (sslParameters.getWantClientAuth()) {
- NativeCrypto.SSL_set_verify(sslNativePointer,
- NativeCrypto.SSL_VERIFY_PEER);
- certRequested = true;
- // ... and it defaults properly so we don't need call SSL_set_verify in the common case.
+ AbstractSessionContext sessionContext;
+ OpenSSLSessionImpl session;
+ if (client) {
+ // look for client session to reuse
+ ClientSessionContext clientSessionContext = sslParameters.getClientSessionContext();
+ sessionContext = clientSessionContext;
+ session = getCachedClientSession(clientSessionContext);
+ if (session != null) {
+ NativeCrypto.SSL_set_session(sslNativePointer,
+ session.sslSessionNativePointer);
+ }
} else {
- certRequested = false;
+ sessionContext = sslParameters.getServerSessionContext();
+ session = null;
}
- if (certRequested) {
- X509Certificate[] issuers = sslParameters.getTrustManager().getAcceptedIssuers();
- if (issuers != null && issuers.length != 0) {
- byte[][] issuersBytes;
- try {
- issuersBytes = NativeCrypto.encodeIssuerX509Principals(issuers);
- } catch (CertificateEncodingException e) {
- throw new IOException("Problem encoding principals", e);
+ // setup peer certificate verification
+ if (client) {
+ // TODO support for anonymous cipher would require us to
+ // conditionally use SSL_VERIFY_NONE
+ } else {
+ // needing client auth takes priority...
+ boolean certRequested = false;
+ if (sslParameters.getNeedClientAuth()) {
+ NativeCrypto.SSL_set_verify(sslNativePointer,
+ NativeCrypto.SSL_VERIFY_PEER
+ | NativeCrypto.SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
+ certRequested = true;
+ // ... over just wanting it...
+ } else if (sslParameters.getWantClientAuth()) {
+ NativeCrypto.SSL_set_verify(sslNativePointer,
+ NativeCrypto.SSL_VERIFY_PEER);
+ certRequested = true;
+ // ... and it defaults properly so don't call SSL_set_verify in the common case.
+ } else {
+ certRequested = false;
+ }
+
+ if (certRequested) {
+ X509TrustManager trustManager = sslParameters.getTrustManager();
+ X509Certificate[] issuers = trustManager.getAcceptedIssuers();
+ if (issuers != null && issuers.length != 0) {
+ byte[][] issuersBytes;
+ try {
+ issuersBytes = NativeCrypto.encodeIssuerX509Principals(issuers);
+ } catch (CertificateEncodingException e) {
+ throw new IOException("Problem encoding principals", e);
+ }
+ NativeCrypto.SSL_set_client_CA_list(sslNativePointer, issuersBytes);
}
- NativeCrypto.SSL_set_client_CA_list(sslNativePointer, issuersBytes);
}
}
- }
-
- if (client && full) {
- // we want to do a full synchronous handshake, so turn off cutthrough
- NativeCrypto.SSL_clear_mode(sslNativePointer,
- NativeCrypto.SSL_MODE_HANDSHAKE_CUTTHROUGH);
- }
- // BEGIN android-added
- // Temporarily use a different timeout for the handshake process
- int savedTimeoutMilliseconds = getSoTimeout();
- if (handshakeTimeoutMilliseconds >= 0) {
- setSoTimeout(handshakeTimeoutMilliseconds);
- }
- // END android-added
+ if (client && full) {
+ // we want to do a full synchronous handshake, so turn off cutthrough
+ NativeCrypto.SSL_clear_mode(sslNativePointer,
+ NativeCrypto.SSL_MODE_HANDSHAKE_CUTTHROUGH);
+ }
+ // BEGIN android-added
+ // Temporarily use a different timeout for the handshake process
+ int savedTimeoutMilliseconds = getSoTimeout();
+ if (handshakeTimeoutMilliseconds >= 0) {
+ setSoTimeout(handshakeTimeoutMilliseconds);
+ }
+ // END android-added
- int sslSessionNativePointer;
- try {
- sslSessionNativePointer = NativeCrypto.SSL_do_handshake(sslNativePointer, fd, this,
- getSoTimeout(), client);
- } catch (CertificateException e) {
- SSLHandshakeException exception = new SSLHandshakeException(e.getMessage());
- exception.initCause(e);
- throw exception;
- }
- byte[] sessionId = NativeCrypto.SSL_SESSION_session_id(sslSessionNativePointer);
- sslSession = (OpenSSLSessionImpl) sessionContext.getSession(sessionId);
- if (sslSession != null) {
- sslSession.lastAccessedTime = System.currentTimeMillis();
- LoggerHolder.logger.fine("Reused cached session for "
- + getInetAddress() + ".");
- NativeCrypto.SSL_SESSION_free(sslSessionNativePointer);
- } else {
- if (!enableSessionCreation) {
- // Should have been prevented by NativeCrypto.SSL_set_session_creation_enabled
- throw new IllegalStateException("SSL Session may not be created");
+ int sslSessionNativePointer;
+ try {
+ sslSessionNativePointer = NativeCrypto.SSL_do_handshake(sslNativePointer, fd, this,
+ getSoTimeout(), client);
+ } catch (CertificateException e) {
+ SSLHandshakeException wrapper = new SSLHandshakeException(e.getMessage());
+ wrapper.initCause(e);
+ throw wrapper;
}
- X509Certificate[] localCertificates
- = createCertChain(NativeCrypto.SSL_get_certificate(sslNativePointer));
- X509Certificate[] peerCertificates
- = createCertChain(NativeCrypto.SSL_get_peer_cert_chain(sslNativePointer));
- if (wrappedHost == null) {
- sslSession = new OpenSSLSessionImpl(sslSessionNativePointer,
- localCertificates, peerCertificates,
- super.getInetAddress().getHostName(),
- super.getPort(), sessionContext);
- } else {
- sslSession = new OpenSSLSessionImpl(sslSessionNativePointer,
- localCertificates, peerCertificates,
- wrappedHost, wrappedPort,
- sessionContext);
+ byte[] sessionId = NativeCrypto.SSL_SESSION_session_id(sslSessionNativePointer);
+ sslSession = (OpenSSLSessionImpl) sessionContext.getSession(sessionId);
+ if (sslSession != null) {
+ sslSession.lastAccessedTime = System.currentTimeMillis();
+ LoggerHolder.logger.fine("Reused cached session for "
+ + getInetAddress() + ".");
+ NativeCrypto.SSL_SESSION_free(sslSessionNativePointer);
+ } else {
+ if (!enableSessionCreation) {
+ // Should have been prevented by NativeCrypto.SSL_set_session_creation_enabled
+ throw new IllegalStateException("SSL Session may not be created");
+ }
+ X509Certificate[] localCertificates
+ = createCertChain(NativeCrypto.SSL_get_certificate(sslNativePointer));
+ X509Certificate[] peerCertificates
+ = createCertChain(NativeCrypto.SSL_get_peer_cert_chain(sslNativePointer));
+ if (wrappedHost == null) {
+ sslSession = new OpenSSLSessionImpl(sslSessionNativePointer,
+ localCertificates, peerCertificates,
+ super.getInetAddress().getHostName(),
+ super.getPort(), sessionContext);
+ } else {
+ sslSession = new OpenSSLSessionImpl(sslSessionNativePointer,
+ localCertificates, peerCertificates,
+ wrappedHost, wrappedPort,
+ sessionContext);
+ }
+ // if not, putSession later in handshakeCompleted() callback
+ if (handshakeCompleted) {
+ sessionContext.putSession(sslSession);
+ }
+ LoggerHolder.logger.fine("Created new session for "
+ + getInetAddress().getHostName() + ".");
}
- // if not, putSession later in handshakeCompleted() callback
- if (handshakeCompleted) {
- sessionContext.putSession(sslSession);
+
+ // BEGIN android-added
+ // Restore the original timeout now that the handshake is complete
+ if (handshakeTimeoutMilliseconds >= 0) {
+ setSoTimeout(savedTimeoutMilliseconds);
}
- LoggerHolder.logger.fine("Created new session for "
- + getInetAddress().getHostName() + ".");
- }
+ // END android-added
- // BEGIN android-added
- // Restore the original timeout now that the handshake is complete
- if (handshakeTimeoutMilliseconds >= 0) {
- setSoTimeout(savedTimeoutMilliseconds);
- }
- // END android-added
+ // if not, notifyHandshakeCompletedListeners later in handshakeCompleted() callback
+ if (handshakeCompleted) {
+ notifyHandshakeCompletedListeners();
+ }
- // if not, notifyHandshakeCompletedListeners later in handshakeCompleted() callback
- if (handshakeCompleted) {
- notifyHandshakeCompletedListeners();
+ exception = false;
+ } finally {
+ // on exceptional exit, treat the socket as closed
+ if (exception) {
+ close();
+ }
}
}
@@ -572,7 +591,7 @@ public class OpenSSLSocketImpl
String[] keyTypes = new String[keyTypeBytes.length];
for (int i = 0; i < keyTypeBytes.length; i++) {
- keyTypes[i] = NativeCrypto.keyType(keyTypeBytes[i]);
+ keyTypes[i] = CipherSuite.getClientKeyType(keyTypeBytes[i]);
}
X500Principal[] issuers;
@@ -655,17 +674,16 @@ public class OpenSSLSocketImpl
}
X509Certificate[] peerCertificateChain = new X509Certificate[bytes.length];
for (int i = 0; i < bytes.length; i++) {
- peerCertificateChain[i] =
- new X509CertImpl(
- javax.security.cert.X509Certificate.getInstance(bytes[i]).getEncoded());
+ peerCertificateChain[i] = new X509CertImpl(bytes[i]);
}
boolean client = sslParameters.getUseClientMode();
if (client) {
sslParameters.getTrustManager().checkServerTrusted(peerCertificateChain,
authMethod);
} else {
+ String authType = peerCertificateChain[0].getPublicKey().getAlgorithm();
sslParameters.getTrustManager().checkClientTrusted(peerCertificateChain,
- authMethod);
+ authType);
}
} catch (CertificateException e) {
@@ -772,21 +790,16 @@ public class OpenSSLSocketImpl
* @see java.io.InputStream#read(byte[],int,int)
*/
@Override
- public int read(byte[] b, int off, int len) throws IOException {
+ public int read(byte[] buf, int offset, int byteCount) throws IOException {
BlockGuard.getThreadPolicy().onNetwork();
synchronized (readLock) {
checkOpen();
- if (b == null) {
- throw new NullPointerException("b == null");
- }
- if ((len | off) < 0 || len > b.length - off) {
- throw new IndexOutOfBoundsException();
- }
- if (0 == len) {
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ if (byteCount == 0) {
return 0;
}
return NativeCrypto.SSL_read(sslNativePointer, fd, OpenSSLSocketImpl.this,
- b, off, len, getSoTimeout());
+ buf, offset, byteCount, getSoTimeout());
}
}
}
@@ -823,20 +836,16 @@ public class OpenSSLSocketImpl
* @see java.io.OutputStream#write(byte[],int,int)
*/
@Override
- public void write(byte[] b, int start, int len) throws IOException {
+ public void write(byte[] buf, int offset, int byteCount) throws IOException {
BlockGuard.getThreadPolicy().onNetwork();
synchronized (writeLock) {
checkOpen();
- if (b == null) {
- throw new NullPointerException("b == null");
- }
- if ((len | start) < 0 || len > b.length - start) {
- throw new IndexOutOfBoundsException();
- }
- if (len == 0) {
+ Arrays.checkOffsetAndCount(buf.length, offset, byteCount);
+ if (byteCount == 0) {
return;
}
- NativeCrypto.SSL_write(sslNativePointer, fd, OpenSSLSocketImpl.this, b, start, len);
+ NativeCrypto.SSL_write(sslNativePointer, fd, OpenSSLSocketImpl.this,
+ buf, offset, byteCount);
}
}
}
@@ -856,7 +865,6 @@ public class OpenSSLSocketImpl
try {
startHandshake(true);
} catch (IOException e) {
-
// return an invalid session with
// invalid cipher suite of "SSL_NULL_WITH_NULL_NULL"
return SSLSessionImpl.NULL_SESSION;
@@ -1265,6 +1273,7 @@ public class OpenSSLSocketImpl
}
NativeCrypto.SSL_free(sslNativePointer);
sslNativePointer = 0;
+ guard.close();
}
@Override protected void finalize() throws Throwable {
@@ -1285,7 +1294,9 @@ public class OpenSSLSocketImpl
* and will write the close notify to some unsuspecting
* reader.
*/
- updateInstanceCount(-1);
+ if (guard != null) {
+ guard.warnIfOpen();
+ }
free();
} finally {
super.finalize();
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java
index 99eb9b4..230f9fe 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ProtocolVersion.java
@@ -112,13 +112,13 @@ public class ProtocolVersion {
/**
* SSL 3.0 protocol version
*/
- public static ProtocolVersion SSLv3 = new ProtocolVersion("SSLv3",
+ public static final ProtocolVersion SSLv3 = new ProtocolVersion("SSLv3",
new byte[] { 3, 0 });
/**
* TLS 1.0 protocol version
*/
- public static ProtocolVersion TLSv1 = new ProtocolVersion("TLSv1",
+ public static final ProtocolVersion TLSv1 = new ProtocolVersion("TLSv1",
new byte[] { 3, 1 });
static {
@@ -142,17 +142,4 @@ public class ProtocolVersion {
this.name = name;
this.version = version;
}
-
- /**
- * Compares this ProtocolVersion to the specified object.
- */
- @Override
- public boolean equals(Object o) {
- if (o instanceof ProtocolVersion
- && this.version[0] == ((ProtocolVersion) o).version[0]
- && this.version[1] == ((ProtocolVersion) o).version[1]) {
- return true;
- }
- return false;
- }
} \ No newline at end of file
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java
index b2501a7..2e62e44 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLInputStream.java
@@ -45,16 +45,6 @@ public abstract class SSLInputStream extends InputStream {
@Override
public abstract int read() throws IOException;
- @Override
- public long skip(long n) throws IOException {
- long skept = n;
- while (n > 0) {
- read();
- n--;
- }
- return skept;
- }
-
/**
* Reads and returns uint8 value.
*/
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParametersImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParametersImpl.java
index f6db4b2..405e5dd 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParametersImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLParametersImpl.java
@@ -425,20 +425,11 @@ public class SSLParametersImpl implements Cloneable {
tmf.init((KeyStore) null);
TrustManager[] tms = tmf.getTrustManagers();
X509TrustManager trustManager = findX509TrustManager(tms);
- // BEGIN android-added
- if (trustManager instanceof TrustManagerImpl) {
- ((TrustManagerImpl) trustManager).indexTrustAnchors();
- }
- // END android-added
return trustManager;
} catch (NoSuchAlgorithmException e) {
return null;
} catch (KeyStoreException e) {
return null;
- } catch (CertificateEncodingException e) {
- return null;
- } catch (InvalidAlgorithmParameterException e) {
- return null;
}
}
private static X509TrustManager findX509TrustManager(TrustManager[] tms) {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java
index 7a1683a..abec7d1 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLRecordProtocol.java
@@ -36,11 +36,11 @@ import javax.net.ssl.SSLProtocolException;
* getChangeCipherSpecMesage method).
* For server side mode record protocol retrieves the parameters from
* handshake protocol after receiving of client's change_cipher_spec message.
- * After the pending session has been setted up as a curent session,
- * new connectin state object is created and used for encryption/decryption
+ * After the pending session has been set up as a current session,
+ * new connection state object is created and used for encryption/decryption
* of the messages.
* Among with base functionality this class provides the information about
- * constrains on the data length, and information about correspondance
+ * constrains on the data length, and information about correspondence
* of plain and encrypted data lengths.
* For more information on TLS v1 see http://www.ietf.org/rfc/rfc2246.txt,
* on SSL v3 see http://wp.netscape.com/eng/ssl3,
@@ -52,24 +52,24 @@ public class SSLRecordProtocol {
* Maximum length of allowed plain data fragment
* as specified by TLS specification.
*/
- protected static int MAX_DATA_LENGTH = 16384; // 2^14
+ protected static final int MAX_DATA_LENGTH = 16384; // 2^14
/**
* Maximum length of allowed compressed data fragment
* as specified by TLS specification.
*/
- protected static int MAX_COMPRESSED_DATA_LENGTH
+ protected static final int MAX_COMPRESSED_DATA_LENGTH
= MAX_DATA_LENGTH + 1024;
/**
* Maximum length of allowed ciphered data fragment
* as specified by TLS specification.
*/
- protected static int MAX_CIPHERED_DATA_LENGTH
+ protected static final int MAX_CIPHERED_DATA_LENGTH
= MAX_COMPRESSED_DATA_LENGTH + 1024;
/**
* Maximum length of ssl record. It is counted as:
* type(1) + version(2) + length(2) + MAX_CIPHERED_DATA_LENGTH
*/
- protected static int MAX_SSL_PACKET_SIZE
+ protected static final int MAX_SSL_PACKET_SIZE
= MAX_CIPHERED_DATA_LENGTH + 5;
// the SSL session used for connection
private SSLSessionImpl session;
@@ -79,7 +79,7 @@ public class SSLRecordProtocol {
private SSLInputStream in;
// handshake protocol object to which handshaking data will be transmitted
private HandshakeProtocol handshakeProtocol;
- // alert protocol to indicate alerts occured/received
+ // alert protocol to indicate alerts occurred/received
private AlertProtocol alertProtocol;
// application data object to which application data will be transmitted
private org.apache.harmony.xnet.provider.jsse.Appendable appData;
@@ -119,7 +119,7 @@ public class SSLRecordProtocol {
/**
* Returns the session obtained during the handshake negotiation.
- * If the handshake process was not compleated, method returns null.
+ * If the handshake process was not completed, method returns null.
* @return the session in effect.
*/
protected SSLSessionImpl getSession() {
@@ -148,7 +148,7 @@ public class SSLRecordProtocol {
int res = 5 + activeWriteState.getFragmentSize(data_size);
return (res > MAX_CIPHERED_DATA_LENGTH)
? MAX_CIPHERED_DATA_LENGTH // so the source data should be
- // splitted into several packets
+ // split into several packets
: res;
}
}
@@ -178,7 +178,6 @@ public class SSLRecordProtocol {
* Depending on the Connection State (Session) encrypts and compress
* the provided data, and packs it into TLSCiphertext structure.
* @param content_type: int
- * @param fragment: byte[]
* @return ssl packet created over the current connection state
*/
protected byte[] wrap(byte content_type, DataStream dataStream) {
@@ -318,10 +317,10 @@ public class SSLRecordProtocol {
* In addition this method can recognize SSLv2 hello message which
* are often used to establish the SSL/TLS session.
*
- * @throws IOException if some io errors have been occured
+ * @throws IOException if some io errors have been occurred
* @throws EndOfSourceException if underlying input stream
* has ran out of data.
- * @throws EndOfBufferException if there was not enought data
+ * @throws EndOfBufferException if there was not enough data
* to build complete ssl packet.
* @return the type of unwrapped message.
*/
@@ -452,7 +451,7 @@ public class SSLRecordProtocol {
}
/**
- * Shutdownes the protocol. It will be impossiblke to use the instance
+ * Shuts down the protocol. It will be impossible to use the instance
* after the calling of this method.
*/
protected void shutdown() {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLServerSocketFactoryImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLServerSocketFactoryImpl.java
index 222ebec..1899342 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLServerSocketFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLServerSocketFactoryImpl.java
@@ -22,6 +22,7 @@ import java.net.InetAddress;
import java.net.ServerSocket;
import java.security.KeyManagementException;
import javax.net.ssl.SSLServerSocketFactory;
+import libcore.base.EmptyArray;
/**
* Implementation of SSLServerSocketFactory.
@@ -61,7 +62,7 @@ public class SSLServerSocketFactoryImpl extends SSLServerSocketFactory {
@Override
public String[] getDefaultCipherSuites() {
if (instantiationException != null) {
- return new String[0];
+ return EmptyArray.STRING;
}
return sslParameters.getEnabledCipherSuites();
}
@@ -72,7 +73,7 @@ public class SSLServerSocketFactoryImpl extends SSLServerSocketFactory {
@Override
public String[] getSupportedCipherSuites() {
if (instantiationException != null) {
- return new String[0];
+ return EmptyArray.STRING;
}
return CipherSuite.getSupportedCipherSuiteNames();
}
@@ -127,4 +128,3 @@ public class SSLServerSocketFactoryImpl extends SSLServerSocketFactory {
(SSLParametersImpl) sslParameters.clone());
}
}
-
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
index 582d316..0bf4007 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java
@@ -33,6 +33,7 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSessionBindingEvent;
import javax.net.ssl.SSLSessionBindingListener;
import javax.net.ssl.SSLSessionContext;
+import libcore.base.EmptyArray;
import libcore.base.Objects;
/**
@@ -175,7 +176,7 @@ public class SSLSessionImpl implements SSLSession, Cloneable {
lastAccessedTime = creationTime;
if (cipher_suite == null) {
this.cipherSuite = CipherSuite.SSL_NULL_WITH_NULL_NULL;
- id = new byte[0];
+ id = EmptyArray.BYTE;
isServer = false;
isValid = false;
} else {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketFactoryImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketFactoryImpl.java
index 2701f5d..9cd9eeb 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketFactoryImpl.java
@@ -23,35 +23,38 @@ import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import javax.net.ssl.SSLSocketFactory;
+import libcore.base.EmptyArray;
/**
* Implementation of SSLSocketFactory.
*/
public class SSLSocketFactoryImpl extends SSLSocketFactory {
- private SSLParametersImpl sslParameters;
- private IOException instantiationException;
+ private final SSLParametersImpl sslParameters;
+ private final IOException instantiationException;
/**
* Constructor.
*/
public SSLSocketFactoryImpl() {
- super();
+ SSLParametersImpl sslParametersLocal = null;
+ IOException instantiationExceptionLocal = null;
try {
- sslParameters = SSLParametersImpl.getDefault();
+ sslParametersLocal = SSLParametersImpl.getDefault();
} catch (KeyManagementException e) {
- instantiationException =
- new IOException("Delayed instantiation exception:");
- instantiationException.initCause(e);
+ instantiationExceptionLocal = new IOException("Delayed instantiation exception:");
+ instantiationExceptionLocal.initCause(e);
}
+ this.sslParameters = sslParametersLocal;
+ this.instantiationException = instantiationExceptionLocal;
}
/**
* Constructor.
*/
protected SSLSocketFactoryImpl(SSLParametersImpl sslParameters) {
- super();
this.sslParameters = sslParameters;
+ this.instantiationException = null;
}
/**
@@ -60,7 +63,7 @@ public class SSLSocketFactoryImpl extends SSLSocketFactory {
@Override
public String[] getDefaultCipherSuites() {
if (instantiationException != null) {
- return new String[0];
+ return EmptyArray.STRING;
}
return sslParameters.getEnabledCipherSuites();
}
@@ -71,7 +74,7 @@ public class SSLSocketFactoryImpl extends SSLSocketFactory {
@Override
public String[] getSupportedCipherSuites() {
if (instantiationException != null) {
- return new String[0];
+ return EmptyArray.STRING;
}
return CipherSuite.getSupportedCipherSuiteNames();
}
@@ -157,4 +160,3 @@ public class SSLSocketFactoryImpl extends SSLSocketFactory {
// ------------------------------------------------------------------
}
-
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
index 68b9a19..950518b 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSocketInputStream.java
@@ -142,23 +142,6 @@ public final class SSLSocketInputStream
return i;
}
- /**
- * Method acts as described in spec for superclass.
- * @see java.io.InputStream#skip(long)
- */
- @Override
- public long skip(long n) throws IOException {
- long i = 0;
- int av = available();
- if (av < n) {
- n = av;
- }
- while ((i < n) && (read() != -1)) {
- i++;
- }
- return i;
- }
-
// The helper class devivering the application data from the record layer
// to this input stream.
// It 'adapts' the InputStream interface to Appendable, which is used for
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
index bbb08a5..f9df058 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/ServerHandshakeImpl.java
@@ -140,7 +140,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
if (clientCert.certs.length == 0) {
if (parameters.getNeedClientAuth()) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "HANDSHAKE FAILURE: no client certificate received");
+ "HANDSHAKE FAILURE: no client certificate received");
}
} else {
String authType = clientCert.getAuthType();
@@ -149,7 +149,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
clientCert.certs, authType);
} catch (CertificateException e) {
fatalAlert(AlertProtocol.BAD_CERTIFICATE,
- "Untrusted Client Certificate ", e);
+ "Untrusted Client Certificate ", e);
}
session.peerCertificates = clientCert.certs;
}
@@ -187,15 +187,14 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
ds.setSHA(sha_hash);
if (!ds.verifySignature(certificateVerify.signedHash)) {
fatalAlert(AlertProtocol.DECRYPT_ERROR,
- "DECRYPT ERROR: CERTIFICATE_VERIFY incorrect signature");
+ "DECRYPT ERROR: CERTIFICATE_VERIFY incorrect signature");
}
break;
case 16: // CLIENT_KEY_EXCHANGE
if (isResuming
|| serverHelloDone == null
|| clientKeyExchange != null
- || (clientCert == null && parameters
- .getNeedClientAuth())) {
+ || (clientCert == null && parameters.getNeedClientAuth())) {
unexpectedMessage();
return;
}
@@ -208,8 +207,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
try {
c = Cipher.getInstance("RSA/ECB/PKCS1Padding");
c.init(Cipher.DECRYPT_MODE, privKey);
- preMasterSecret = c
- .doFinal(clientKeyExchange.exchange_keys);
+ preMasterSecret = c.doFinal(clientKeyExchange.exchange_keys);
// check preMasterSecret:
if (preMasterSecret.length != 48
|| preMasterSecret[0] != clientHello.client_version[0]
@@ -222,7 +220,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
}
} catch (Exception e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR,
- "INTERNAL ERROR", e);
+ "INTERNAL ERROR", e);
}
} else { // diffie hellman key exchange
clientKeyExchange = new ClientKeyExchange(io_stream,
@@ -233,27 +231,12 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
// matched server cert. DH params
// client cert. contains fixed DH parameters
- preMasterSecret = ((DHPublicKey) clientCert.certs[0]
- .getPublicKey()).getY().toByteArray();
+ preMasterSecret = ((DHPublicKey) clientCert.certs[0].getPublicKey()).getY().toByteArray();
} else {
- PublicKey clientPublic;
- KeyAgreement agreement;
try {
- KeyFactory kf = null;
- try {
- kf = KeyFactory.getInstance("DH");
- } catch (NoSuchAlgorithmException ee) {
- kf = KeyFactory
- .getInstance("DiffieHellman");
- }
- try {
- agreement = KeyAgreement.getInstance("DH");
- } catch (NoSuchAlgorithmException ee) {
- agreement = KeyAgreement
- .getInstance("DiffieHellman");
- }
- clientPublic = kf
- .generatePublic(new DHPublicKeySpec(
+ KeyFactory kf = KeyFactory.getInstance("DH");
+ KeyAgreement agreement = KeyAgreement.getInstance("DH");
+ PublicKey clientPublic = kf.generatePublic(new DHPublicKeySpec(
new BigInteger(
1,
clientKeyExchange.exchange_keys),
@@ -264,7 +247,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
preMasterSecret = agreement.generateSecret();
} catch (Exception e) {
fatalAlert(AlertProtocol.INTERNAL_ERROR,
- "INTERNAL ERROR", e);
+ "INTERNAL ERROR", e);
return;
}
}
@@ -349,14 +332,14 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
}
}
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "HANDSHAKE FAILURE. Incorrect client hello message");
+ "HANDSHAKE FAILURE. Incorrect client hello message");
}
if (!ProtocolVersion.isSupported(clientHello.client_version)) {
fatalAlert(AlertProtocol.PROTOCOL_VERSION,
- "PROTOCOL VERSION. Unsupported client version "
- + clientHello.client_version[0]
- + clientHello.client_version[1]);
+ "PROTOCOL VERSION. Unsupported client version "
+ + clientHello.client_version[0]
+ + clientHello.client_version[1]);
}
isResuming = false;
@@ -407,7 +390,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
}
}
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "HANDSHAKE FAILURE. Incorrect client hello message");
+ "HANDSHAKE FAILURE. Incorrect client hello message");
}
} else {
cipher_suite = selectSuite(clientHello.cipher_suites);
@@ -416,7 +399,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
}
if (!parameters.getEnableSessionCreation()) {
fatalAlert(AlertProtocol.HANDSHAKE_FAILURE,
- "SSL Session may not be created");
+ "SSL Session may not be created");
}
session = new SSLSessionImpl(cipher_suite, parameters.getSecureRandom());
// BEGIN android-added
@@ -446,27 +429,9 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
// create and send server certificate message if needed
if (!cipher_suite.isAnonymous()) { // need to send server certificate
X509Certificate[] certs = null;
- String certType = null;
- switch (cipher_suite.keyExchange) {
- case CipherSuite.KEY_EXCHANGE_RSA:
- case CipherSuite.KEY_EXCHANGE_RSA_EXPORT:
- case CipherSuite.KEY_EXCHANGE_DHE_RSA:
- case CipherSuite.KEY_EXCHANGE_DHE_RSA_EXPORT:
- certType = "RSA";
- break;
- case CipherSuite.KEY_EXCHANGE_DHE_DSS:
- case CipherSuite.KEY_EXCHANGE_DHE_DSS_EXPORT:
- case CipherSuite.KEY_EXCHANGE_DH_DSS_EXPORT:
- certType = "DSA";
- break;
- case CipherSuite.KEY_EXCHANGE_DH_DSS:
- certType = "DH_DSA";
- break;
- case CipherSuite.KEY_EXCHANGE_DH_RSA:
- certType = "DH_RSA";
- break;
- default:
- fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "NO CERT TYPE FOR " + cipher_suite.getName());
+ String certType = cipher_suite.getServerKeyType();
+ if (certType == null) {
+ fatalAlert(AlertProtocol.HANDSHAKE_FAILURE, "NO CERT TYPE FOR " + cipher_suite.getName());
}
// obtain certificates from key manager
String alias = null;
@@ -523,11 +488,7 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
|| cipher_suite.keyExchange == CipherSuite.KEY_EXCHANGE_DHE_RSA_EXPORT
|| cipher_suite.keyExchange == CipherSuite.KEY_EXCHANGE_DH_anon
|| cipher_suite.keyExchange == CipherSuite.KEY_EXCHANGE_DH_anon_EXPORT) {
- try {
- kpg = KeyPairGenerator.getInstance("DH");
- } catch (NoSuchAlgorithmException ee) {
- kpg = KeyPairGenerator.getInstance("DiffieHellman");
- }
+ kpg = KeyPairGenerator.getInstance("DH");
p = new BigInteger(1, DHParameters.getPrime());
g = new BigInteger("2");
DHParameterSpec spec = new DHParameterSpec(p, g);
@@ -547,14 +508,8 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
rsakey = (RSAPublicKey) kp.getPublic();
} else {
DHPublicKey dhkey = (DHPublicKey) kp.getPublic();
- KeyFactory kf = null;
- try {
- kf = KeyFactory.getInstance("DH");
- } catch (NoSuchAlgorithmException e) {
- kf = KeyFactory.getInstance("DiffieHellman");
- }
- dhkeySpec = kf.getKeySpec(dhkey,
- DHPublicKeySpec.class);
+ KeyFactory kf = KeyFactory.getInstance("DH");
+ dhkeySpec = kf.getKeySpec(dhkey, DHPublicKeySpec.class);
}
if (!cipher_suite.isAnonymous()) { // calculate signed_params
@@ -627,7 +582,8 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
// don't send certificateRequest
break certRequest;
}
- byte[] requestedClientCertTypes = {1, 2}; // rsa sign, dsa sign
+ byte[] requestedClientCertTypes = { CipherSuite.TLS_CT_RSA_SIGN,
+ CipherSuite.TLS_CT_DSS_SIGN };
certificateRequest = new CertificateRequest(
requestedClientCertTypes, accepted);
send(certificateRequest);
@@ -674,15 +630,15 @@ public class ServerHandshakeImpl extends HandshakeProtocol {
}
// find appropriate cipher_suite in the client suites
- private CipherSuite selectSuite(CipherSuite[] client_suites) {
- for (int i = 0; i < client_suites.length; i++) {
- if (!client_suites[i].supported) {
+ private CipherSuite selectSuite(CipherSuite[] clientSuites) {
+ for (CipherSuite clientSuite : clientSuites) {
+ if (!clientSuite.supported) {
continue;
}
// BEGIN android-changed
- for (int j = 0; j < parameters.getEnabledCipherSuitesMember().length; j++) {
- if (client_suites[i].equals(parameters.getEnabledCipherSuitesMember()[j])) {
- return client_suites[i];
+ for (CipherSuite enabledCipherSuite : parameters.getEnabledCipherSuitesMember()) {
+ if (clientSuite.equals(enabledCipherSuite)) {
+ return clientSuite;
}
}
// END android-changed
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java
index 7a555ea..f894331 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerFactoryImpl.java
@@ -21,6 +21,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.io.IOException;
import java.security.AccessController;
import java.security.InvalidAlgorithmParameterException;
@@ -31,6 +32,7 @@ import java.security.cert.CertificateException;
import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactorySpi;
+import libcore.base.EmptyArray;
/**
*
@@ -90,12 +92,20 @@ public class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
});
char[] pwd;
if (keyStorePwd == null) {
- pwd = new char[0];
+ pwd = EmptyArray.CHAR;
} else {
pwd = keyStorePwd.toCharArray();
}
try {
- keyStore.load(new BufferedInputStream(new FileInputStream(keyStoreName)), pwd);
+ InputStream in = null;
+ try {
+ in = new BufferedInputStream(new FileInputStream(keyStoreName));
+ keyStore.load(in, pwd);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
} catch (FileNotFoundException e) {
throw new KeyStoreException(e);
} catch (IOException e) {
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java
index 8ccf085..01af5b3 100644
--- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java
+++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/TrustManagerImpl.java
@@ -23,16 +23,16 @@ import java.security.KeyStoreException;
import java.security.cert.CertPath;
import java.security.cert.CertPathValidator;
import java.security.cert.CertPathValidatorException;
-import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.PKIXParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Arrays;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
-import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import javax.net.ssl.X509TrustManager;
@@ -46,13 +46,15 @@ import javax.net.ssl.X509TrustManager;
*/
public class TrustManagerImpl implements X509TrustManager {
- private CertPathValidator validator;
+ private final CertPathValidator validator;
- private PKIXParameters params;
+ private final IndexedPKIXParameters params;
- private Exception err = null;
+ private final X509Certificate[] acceptedIssuers;
- private CertificateFactory factory;
+ private final Exception err;
+
+ private final CertificateFactory factory;
/**
* Creates trust manager implementation
@@ -60,35 +62,57 @@ public class TrustManagerImpl implements X509TrustManager {
* @param ks
*/
public TrustManagerImpl(KeyStore ks) {
+ CertPathValidator validatorLocal = null;
+ CertificateFactory factoryLocal = null;
+ IndexedPKIXParameters paramsLocal = null;
+ X509Certificate[] acceptedIssuersLocal = null;
+ Exception errLocal = null;
try {
- validator = CertPathValidator.getInstance("PKIX");
- factory = CertificateFactory.getInstance("X509");
- byte[] nameConstrains = null;
- Set<TrustAnchor> trusted = new HashSet<TrustAnchor>();
- for (Enumeration<String> en = ks.aliases(); en.hasMoreElements();) {
- final String alias = en.nextElement();
- final X509Certificate cert = (X509Certificate) ks.getCertificate(alias);
- if (cert != null) {
- trusted.add(new TrustAnchor(cert, nameConstrains));
- }
- }
- params = new PKIXParameters(trusted);
- params.setRevocationEnabled(false);
+ validatorLocal = CertPathValidator.getInstance("PKIX");
+ factoryLocal = CertificateFactory.getInstance("X509");
+ acceptedIssuersLocal = acceptedIssuers(ks);
+ paramsLocal = new IndexedPKIXParameters(trustAnchors(acceptedIssuersLocal));
+ paramsLocal.setRevocationEnabled(false);
} catch (Exception e) {
- err = e;
+ errLocal = e;
}
+ this.validator = validatorLocal;
+ this.factory = factoryLocal;
+ this.params = paramsLocal;
+ this.acceptedIssuers = (acceptedIssuersLocal != null
+ ? acceptedIssuersLocal
+ : new X509Certificate[0]);
+ this.err = errLocal;
}
-// BEGIN android-added
- /**
- * Indexes trust anchors so they can be found in O(1) instead of O(N) time.
- */
- public void indexTrustAnchors() throws CertificateEncodingException,
- InvalidAlgorithmParameterException, KeyStoreException {
- params = new IndexedPKIXParameters(params.getTrustAnchors());
- params.setRevocationEnabled(false);
+ private static X509Certificate[] acceptedIssuers(KeyStore ks) throws KeyStoreException {
+ // Note that unlike the PKIXParameters code to create a Set of
+ // TrustAnchors from a KeyStore, this version takes from both
+ // TrustedCertificateEntry and PrivateKeyEntry, not just
+ // TrustedCertificateEntry, which is why TrustManagerImpl
+ // cannot just use an PKIXParameters(KeyStore)
+ // constructor.
+
+ // TODO remove duplicates if same cert is found in both a
+ // PrivateKeyEntry and TrustedCertificateEntry
+ List<X509Certificate> trusted = new ArrayList<X509Certificate>();
+ for (Enumeration<String> en = ks.aliases(); en.hasMoreElements();) {
+ final String alias = en.nextElement();
+ final X509Certificate cert = (X509Certificate) ks.getCertificate(alias);
+ if (cert != null) {
+ trusted.add(cert);
+ }
+ }
+ return trusted.toArray(new X509Certificate[trusted.size()]);
+ }
+
+ private static Set<TrustAnchor> trustAnchors(X509Certificate[] certs) {
+ Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>(certs.length);
+ for (X509Certificate cert : certs) {
+ trustAnchors.add(new TrustAnchor(cert, null));
+ }
+ return trustAnchors;
}
-// END android-added
/**
* @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],
@@ -96,38 +120,7 @@ public class TrustManagerImpl implements X509TrustManager {
*/
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
- if (chain == null || chain.length == 0 || authType == null
- || authType.length() == 0) {
- throw new IllegalArgumentException("null or zero-length parameter");
- }
- if (err != null) {
- throw new CertificateException(err);
- }
- // BEGIN android-added
- // Caters to degenerate special case where we can't
- // establish an actual certificate chain the usual way,
- // but have the peer certificate in our trust store.
- if (isDirectlyTrustedCert(chain)) {
- return;
- }
- // END android-added
- try {
- // BEGIN android-changed
- CertPath certPath = factory.generateCertPath(Arrays.asList(chain));
- if (!Arrays.equals(chain[0].getEncoded(),
- ((X509Certificate)certPath.getCertificates().get(0))
- .getEncoded())) {
- // Sanity check failed (shouldn't ever happen, but we
- // are using pretty remote code)
- throw new CertificateException("Certificate chain error");
- }
- validator.validate(certPath, params);
- // END android-changed
- } catch (InvalidAlgorithmParameterException e) {
- throw new CertificateException(e);
- } catch (CertPathValidatorException e) {
- throw new CertificateException(e);
- }
+ checkTrusted(chain, authType);
}
/**
@@ -136,94 +129,115 @@ public class TrustManagerImpl implements X509TrustManager {
*/
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
- if (chain == null || chain.length == 0 || authType == null
- || authType.length() == 0) {
+ checkTrusted(chain, authType);
+ }
+
+ private void checkTrusted(X509Certificate[] chain, String authType)
+ throws CertificateException {
+ if (chain == null || chain.length == 0 || authType == null || authType.length() == 0) {
throw new IllegalArgumentException("null or zero-length parameter");
}
if (err != null) {
throw new CertificateException(err);
}
- // BEGIN android-changed
- CertificateException ce = null;
+
+ X509Certificate[] newChain = cleanupCertChain(chain);
+ if (newChain.length == 0) {
+ // chain was entirely trusted, skip the validator
+ return;
+ }
+ CertPath certPath = factory.generateCertPath(Arrays.asList(newChain));
+ if (!Arrays.equals(chain[0].getEncoded(),
+ certPath.getCertificates().get(0).getEncoded())) {
+ // Sanity check failed (shouldn't ever happen, but we
+ // are using pretty remote code)
+ throw new CertificateException("Certificate chain error");
+ }
try {
- CertPath certPath = factory.generateCertPath(Arrays.asList(chain));
- if (!Arrays.equals(chain[0].getEncoded(),
- certPath.getCertificates().get(0).getEncoded())) {
- // Sanity check failed (shouldn't ever happen, but we
- // are using pretty remote code)
- throw new CertificateException("Certificate chain error");
- }
validator.validate(certPath, params);
- // END android-changed
+ // Add intermediate CAs to the index to tolerate sites
+ // that assume that the browser will have cached these.
+ // The server certificate is skipped by skipping the
+ // zeroth element of new chain and note that the root CA
+ // will have been removed in cleanupCertChain.
+ // http://b/3404902
+ for (int i = 1; i < newChain.length; i++) {
+ params.index(new TrustAnchor(newChain[i], null));
+ }
} catch (InvalidAlgorithmParameterException e) {
- ce = new CertificateException(e);
+ throw new CertificateException(e);
} catch (CertPathValidatorException e) {
- ce = new CertificateException(e);
- }
- // BEGIN android-added
- if (ce != null) {
- // Caters to degenerate special case where we can't
- // establish an actual certificate chain the usual way
- // but have the peer certificate in our trust store.
- if (!isDirectlyTrustedCert(chain)) {
- throw ce;
- }
+ throw new CertificateException(e);
}
- // END android-added
}
/**
- * Checks whether the given chain is just a certificate
- * that we have in our trust store.
- *
- * @param chain The certificate chain.
- *
- * @return True if the certificate is in our trust store, false otherwise.
+ * Clean up the certificate chain, returning a cleaned up chain,
+ * which may be a new array instance if elements were removed.
+ * Theoretically, we shouldn't have to do this, but various web
+ * servers in practice are mis-configured to have out-of-order
+ * certificates, expired self-issued root certificate, or CAs with
+ * unsupported signature algorithms such as
+ * md2WithRSAEncryption. This also handles removing old certs
+ * after bridge CA certs.
*/
- private boolean isDirectlyTrustedCert(X509Certificate[] chain) {
- byte[] questionable;
-
- if (chain.length == 1) {
- if (params instanceof IndexedPKIXParameters) {
- IndexedPKIXParameters index = (IndexedPKIXParameters) params;
- return index.isDirectlyTrusted(chain[0]);
- } else {
- try {
- questionable = chain[0].getEncoded();
- Set<TrustAnchor> anchors = params.getTrustAnchors();
-
- for (TrustAnchor trustAnchor : anchors) {
- byte[] trusted = trustAnchor.getTrustedCert()
- .getEncoded();
- if (Arrays.equals(questionable, trusted)) {
- return true;
+ private X509Certificate[] cleanupCertChain(X509Certificate[] chain) {
+ X509Certificate[] original = chain;
+
+ // 1. Clean the received certificates chain.
+ int currIndex;
+ // Start with the first certificate in the chain, assuming it
+ // is the leaf certificate (server or client cert).
+ for (currIndex = 0; currIndex < chain.length; currIndex++) {
+ // If the current cert is a TrustAnchor, we can ignore the rest of the chain.
+ // This avoids including "bridge" CA certs that added for legacy compatability.
+ if (params.isTrustAnchor(chain[currIndex])) {
+ currIndex--;
+ break;
+ }
+ // Walk the rest of the chain to find a "subject" matching
+ // the "issuer" of the current certificate. In a properly
+ // order chain this should be the next cert and be fast.
+ // If not, we reorder things to be as the validator will
+ // expect.
+ boolean foundNext = false;
+ for (int nextIndex = currIndex + 1; nextIndex < chain.length; nextIndex++) {
+ if (chain[currIndex].getIssuerDN().equals(chain[nextIndex].getSubjectDN())) {
+ foundNext = true;
+ // Exchange certificates so that 0 through currIndex + 1 are in proper order
+ if (nextIndex != currIndex + 1) {
+ // don't mutuate original chain, which may be directly from an SSLSession
+ if (chain == original) {
+ chain = original.clone();
}
+ X509Certificate tempCertificate = chain[nextIndex];
+ chain[nextIndex] = chain[currIndex + 1];
+ chain[currIndex + 1] = tempCertificate;
}
- } catch (CertificateEncodingException e) {
- // Ignore.
+ break;
}
}
-
+ // If we can't find the next in the chain, just give up
+ // and use what we found so far. This drops unrelated
+ // certificates that have nothing to do with the cert
+ // chain.
+ if (!foundNext) {
+ break;
+ }
}
- return false;
+ // 2. If the chain is now shorter, copy to an appropriately sized array.
+ int chainLength = currIndex + 1;
+ if (chainLength == chain.length) {
+ return chain;
+ }
+ return Arrays.copyOf(chain, chainLength);
}
-// END android-changed
/**
* @see javax.net.ssl.X509TrustManager#getAcceptedIssuers()
*/
public X509Certificate[] getAcceptedIssuers() {
- if (params == null) {
- return new X509Certificate[0];
- }
- Set<TrustAnchor> anchors = params.getTrustAnchors();
- X509Certificate[] certs = new X509Certificate[anchors.size()];
- int i = 0;
- for (Iterator<TrustAnchor> it = anchors.iterator(); it.hasNext();) {
- certs[i++] = it.next().getTrustedCert();
- }
- return certs;
+ return acceptedIssuers.clone();
}
-
}
diff --git a/luni/src/main/java/org/apache/xml/serializer/ToHTMLStream.java b/luni/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
index 4f2927a..9414875 100644
--- a/luni/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
+++ b/luni/src/main/java/org/apache/xml/serializer/ToHTMLStream.java
@@ -25,6 +25,8 @@ import java.util.Properties;
import javax.xml.transform.Result;
+import libcore.base.EmptyArray;
+
import org.apache.xml.serializer.utils.MsgKey;
import org.apache.xml.serializer.utils.Utils;
import org.xml.sax.Attributes;
@@ -2054,7 +2056,7 @@ public class ToHTMLStream extends ToStream
final Node m_Root;
/** helper buffer to convert Strings to char arrays */
- private char[] m_charBuffer = new char[0];
+ private char[] m_charBuffer = EmptyArray.CHAR;
/** true if the search for an object is lower case only with the key */
private final boolean m_lowerCaseOnly;
diff --git a/luni/src/main/java/org/xml/sax/ext/Attributes2Impl.java b/luni/src/main/java/org/xml/sax/ext/Attributes2Impl.java
index 83cee5b..b3ec94a 100644
--- a/luni/src/main/java/org/xml/sax/ext/Attributes2Impl.java
+++ b/luni/src/main/java/org/xml/sax/ext/Attributes2Impl.java
@@ -7,7 +7,7 @@ package org.xml.sax.ext;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.AttributesImpl;
-
+import libcore.base.EmptyArray;
/**
* SAX2 extension helper for additional Attributes information,
@@ -46,8 +46,8 @@ public class Attributes2Impl extends AttributesImpl implements Attributes2
*/
public Attributes2Impl () {
// BEGIN android-added
- declared = new boolean[0];
- specified = new boolean[0];
+ declared = EmptyArray.BOOLEAN;
+ specified = EmptyArray.BOOLEAN;
// END android-added
}
diff --git a/luni/src/main/java/sun/misc/Unsafe.java b/luni/src/main/java/sun/misc/Unsafe.java
index 6cd0519..1080414 100644
--- a/luni/src/main/java/sun/misc/Unsafe.java
+++ b/luni/src/main/java/sun/misc/Unsafe.java
@@ -258,10 +258,7 @@ public final class Unsafe {
/**
* Lazy set an int field.
*/
- public void putOrderedInt(Object obj, long offset, int newValue) {
- // TODO: this should be an intrinsic that executes a store fence followed by a write
- putIntVolatile(obj, offset, newValue);
- }
+ public native void putOrderedInt(Object obj, long offset, int newValue);
/**
* Gets a <code>long</code> field from the given object.
@@ -284,10 +281,7 @@ public final class Unsafe {
/**
* Lazy set a long field.
*/
- public void putOrderedLong(Object obj, long offset, long newValue) {
- // TODO: this should be an intrinsic that executes a store fence followed by a write
- putLongVolatile(obj, offset, newValue);
- }
+ public native void putOrderedLong(Object obj, long offset, long newValue);
/**
* Gets an <code>Object</code> field from the given object.
@@ -310,10 +304,8 @@ public final class Unsafe {
/**
* Lazy set an object field.
*/
- public void putOrderedObject(Object obj, long offset, Object newValue) {
- // TODO: this should be an intrinsic that executes a store fence followed by a write
- putObjectVolatile(obj, offset, newValue);
- }
+ public native void putOrderedObject(Object obj, long offset,
+ Object newValue);
/**
* Parks the calling thread for the specified amount of time,
diff --git a/luni/src/main/native/ICU.cpp b/luni/src/main/native/ICU.cpp
index 04f6631..7e05978 100644
--- a/luni/src/main/native/ICU.cpp
+++ b/luni/src/main/native/ICU.cpp
@@ -353,21 +353,6 @@ static jobjectArray getNames(JNIEnv* env, UResourceBundle* namesBundle, bool mon
return result;
}
-static jstring getIntCurrencyCode(JNIEnv* env, jstring locale) {
- ScopedUtfChars localeChars(env, locale);
-
- // Extract the 2-character country name.
- if (strlen(localeChars.c_str()) < 5) {
- return NULL;
- }
- if (localeChars[3] < 'A' || localeChars[3] > 'Z' || localeChars[4] < 'A' || localeChars[4] > 'Z') {
- return NULL;
- }
-
- char country[3] = { localeChars[3], localeChars[4], 0 };
- return ICU_getCurrencyCodeNative(env, NULL, env->NewStringUTF(country));
-}
-
static void setIntegerField(JNIEnv* env, jobject obj, const char* fieldName, int value) {
ScopedLocalRef<jobject> integerValue(env, integerValueOf(env, value));
jfieldID fid = env->GetFieldID(JniConstants::localeDataClass, fieldName, "Ljava/lang/Integer;");
@@ -506,7 +491,8 @@ static jboolean ICU_initLocaleDataImpl(JNIEnv* env, jclass, jstring locale, jobj
}
status = U_ZERO_ERROR;
- jstring internationalCurrencySymbol = getIntCurrencyCode(env, locale);
+ jstring countryCode = env->NewStringUTF(Locale::createFromName(localeName.c_str()).getCountry());
+ jstring internationalCurrencySymbol = ICU_getCurrencyCodeNative(env, NULL, countryCode);
jstring currencySymbol = NULL;
if (internationalCurrencySymbol != NULL) {
currencySymbol = ICU_getCurrencySymbolNative(env, NULL, locale, internationalCurrencySymbol);
@@ -563,10 +549,19 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(ICU, getISO3LanguageNative, "(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ICU, getISOCountriesNative, "()[Ljava/lang/String;"),
NATIVE_METHOD(ICU, getISOLanguagesNative, "()[Ljava/lang/String;"),
- NATIVE_METHOD(ICU, initLocaleDataImpl, "(Ljava/lang/String;Lcom/ibm/icu4jni/util/LocaleData;)Z"),
+ NATIVE_METHOD(ICU, initLocaleDataImpl, "(Ljava/lang/String;Llibcore/icu/LocaleData;)Z"),
NATIVE_METHOD(ICU, toLowerCase, "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ICU, toUpperCase, "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;"),
};
-int register_com_ibm_icu4jni_util_ICU(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/util/ICU", gMethods, NELEM(gMethods));
+int register_libcore_icu_ICU(JNIEnv* env) {
+ // Failures to find the ICU data tend to be somewhat obscure because ICU loads its data on first
+ // use, which can be anywhere. Force initialization up front so we can report a nice clear error
+ // and bail.
+ UErrorCode status = U_ZERO_ERROR;
+ u_init(&status);
+ if (status != U_ZERO_ERROR) {
+ LOGE("Couldn't initialize ICU: %s", u_errorName(status));
+ return -1;
+ }
+ return jniRegisterNativeMethods(env, "libcore/icu/ICU", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/JniConstants.cpp b/luni/src/main/native/JniConstants.cpp
index 5ae3ded..e147e0c 100644
--- a/luni/src/main/native/JniConstants.cpp
+++ b/luni/src/main/native/JniConstants.cpp
@@ -44,7 +44,6 @@ jclass JniConstants::realToStringClass;
jclass JniConstants::socketClass;
jclass JniConstants::socketImplClass;
jclass JniConstants::stringClass;
-jclass JniConstants::vmRuntimeClass;
static jclass findClass(JNIEnv* env, const char* name) {
jclass result = reinterpret_cast<jclass>(env->NewGlobalRef(env->FindClass(name)));
@@ -61,18 +60,18 @@ void JniConstants::init(JNIEnv* env) {
booleanClass = findClass(env, "java/lang/Boolean");
byteClass = findClass(env, "java/lang/Byte");
byteArrayClass = findClass(env, "[B");
- charsetICUClass = findClass(env, "com/ibm/icu4jni/charset/CharsetICU");
+ charsetICUClass = findClass(env, "libcore/icu/CharsetICU");
constructorClass = findClass(env, "java/lang/reflect/Constructor");
datagramPacketClass = findClass(env, "java/net/DatagramPacket");
deflaterClass = findClass(env, "java/util/zip/Deflater");
doubleClass = findClass(env, "java/lang/Double");
fieldClass = findClass(env, "java/lang/reflect/Field");
- fieldPositionIteratorClass = findClass(env, "com/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator");
+ fieldPositionIteratorClass = findClass(env, "libcore/icu/NativeDecimalFormat$FieldPositionIterator");
inetAddressClass = findClass(env, "java/net/InetAddress");
inflaterClass = findClass(env, "java/util/zip/Inflater");
integerClass = findClass(env, "java/lang/Integer");
interfaceAddressClass = findClass(env, "java/net/InterfaceAddress");
- localeDataClass = findClass(env, "com/ibm/icu4jni/util/LocaleData");
+ localeDataClass = findClass(env, "libcore/icu/LocaleData");
longClass = findClass(env, "java/lang/Long");
methodClass = findClass(env, "java/lang/reflect/Method");
multicastGroupRequestClass = findClass(env, "java/net/MulticastGroupRequest");
@@ -82,5 +81,4 @@ void JniConstants::init(JNIEnv* env) {
socketClass = findClass(env, "java/net/Socket");
socketImplClass = findClass(env, "java/net/SocketImpl");
stringClass = findClass(env, "java/lang/String");
- vmRuntimeClass = findClass(env, "dalvik/system/VMRuntime");
}
diff --git a/luni/src/main/native/JniConstants.h b/luni/src/main/native/JniConstants.h
index 191b18b..576b1a6 100644
--- a/luni/src/main/native/JniConstants.h
+++ b/luni/src/main/native/JniConstants.h
@@ -66,7 +66,6 @@ struct JniConstants {
static jclass socketClass;
static jclass socketImplClass;
static jclass stringClass;
- static jclass vmRuntimeClass;
};
#define NATIVE_METHOD(className, functionName, signature) \
diff --git a/luni/src/main/native/NativeBN.cpp b/luni/src/main/native/NativeBN.cpp
index 4ef8c28..6359e3e 100644
--- a/luni/src/main/native/NativeBN.cpp
+++ b/luni/src/main/native/NativeBN.cpp
@@ -24,9 +24,9 @@
#include "JniConstants.h"
#include "ScopedPrimitiveArray.h"
#include "ScopedUtfChars.h"
+#include "StaticAssert.h"
#include "UniquePtr.h"
#include "jni.h"
-#include <assert.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <openssl/err.h>
@@ -169,7 +169,7 @@ static jboolean NativeBN_litEndInts2bn(JNIEnv* env, jclass, jintArray arr, int l
return JNI_FALSE;
}
- assert(sizeof(BN_ULONG) == sizeof(jint));
+ STATIC_ASSERT(sizeof(BN_ULONG) == sizeof(jint), BN_ULONG_not_32_bit);
const BN_ULONG* tmpInts = reinterpret_cast<const BN_ULONG*>(scopedArray.get());
if ((tmpInts != NULL) && (bn_wexpand(ret, len) != NULL)) {
int i = len; do { i--; ret->d[i] = tmpInts[i]; } while (i > 0);
@@ -197,10 +197,9 @@ static jboolean NativeBN_litEndInts2bn(JNIEnv* env, jclass, jintArray arr, int l
| (bytes[k + 0] & 0xFF) << 24 )
static jboolean negBigEndianBytes2bn(JNIEnv*, jclass, const unsigned char* bytes, int bytesLen, BIGNUM* ret) {
-// We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
-//
+ // We rely on: (BN_BITS2 == 32), i.e. BN_ULONG is unsigned int and has 4 bytes:
bn_check_top(ret);
-// FIXME: ASSERT (bytesLen > 0);
+ // FIXME: assert bytesLen > 0
int intLen = (bytesLen + 3) / 4;
int firstNonzeroDigit = -2;
if (bn_wexpand(ret, intLen) != NULL) {
diff --git a/luni/src/main/native/NativeBreakIterator.cpp b/luni/src/main/native/NativeBreakIterator.cpp
index 742a41a..b3eab45 100644
--- a/luni/src/main/native/NativeBreakIterator.cpp
+++ b/luni/src/main/native/NativeBreakIterator.cpp
@@ -139,7 +139,6 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeBreakIterator, previousImpl, "(I)I"),
NATIVE_METHOD(NativeBreakIterator, setTextImpl, "(ILjava/lang/String;)V"),
};
-int register_com_ibm_icu4jni_text_NativeBreakIterator(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeBreakIterator",
- gMethods, NELEM(gMethods));
+int register_libcore_icu_NativeBreakIterator(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "libcore/icu/NativeBreakIterator", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/NativeCollation.cpp b/luni/src/main/native/NativeCollation.cpp
index d01b46f..60c6488 100644
--- a/luni/src/main/native/NativeCollation.cpp
+++ b/luni/src/main/native/NativeCollation.cpp
@@ -63,19 +63,6 @@ static jint NativeCollation_getMaxExpansion(JNIEnv*, jclass, jint address, jint
return ucol_getMaxExpansion(toCollationElements(address), order);
}
-static jint NativeCollation_getNormalization(JNIEnv* env, jclass, jint address) {
- UErrorCode status = U_ZERO_ERROR;
- jint result = ucol_getAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, &status);
- icu4jni_error(env, status);
- return result;
-}
-
-static void NativeCollation_setNormalization(JNIEnv* env, jclass, jint address, jint mode) {
- UErrorCode status = U_ZERO_ERROR;
- ucol_setAttribute(toCollator(address), UCOL_NORMALIZATION_MODE, UColAttributeValue(mode), &status);
- icu4jni_error(env, status);
-}
-
static jint NativeCollation_getOffset(JNIEnv*, jclass, jint address) {
return ucol_getOffset(toCollationElements(address));
}
@@ -182,7 +169,6 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeCollation, getAttribute, "(II)I"),
NATIVE_METHOD(NativeCollation, getCollationElementIterator, "(ILjava/lang/String;)I"),
NATIVE_METHOD(NativeCollation, getMaxExpansion, "(II)I"),
- NATIVE_METHOD(NativeCollation, getNormalization, "(I)I"),
NATIVE_METHOD(NativeCollation, getOffset, "(I)I"),
NATIVE_METHOD(NativeCollation, getRules, "(I)Ljava/lang/String;"),
NATIVE_METHOD(NativeCollation, getSortKey, "(ILjava/lang/String;)[B"),
@@ -193,11 +179,9 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeCollation, reset, "(I)V"),
NATIVE_METHOD(NativeCollation, safeClone, "(I)I"),
NATIVE_METHOD(NativeCollation, setAttribute, "(III)V"),
- NATIVE_METHOD(NativeCollation, setNormalization, "(II)V"),
NATIVE_METHOD(NativeCollation, setOffset, "(II)V"),
NATIVE_METHOD(NativeCollation, setText, "(ILjava/lang/String;)V"),
};
-int register_com_ibm_icu4jni_text_NativeCollator(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeCollation",
- gMethods, NELEM(gMethods));
+int register_libcore_icu_NativeCollation(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "libcore/icu/NativeCollation", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/NativeConverter.cpp b/luni/src/main/native/NativeConverter.cpp
index e2894d6..7587fc6 100644
--- a/luni/src/main/native/NativeConverter.cpp
+++ b/luni/src/main/native/NativeConverter.cpp
@@ -8,8 +8,6 @@
*******************************************************************************
*/
/*
- * @(#) icujniinterface.c 1.2 00/10/11
- *
* (C) Copyright IBM Corp. 2000 - All Rights Reserved
* A JNI wrapper to ICU native converter Interface
* @author: Ram Viswanadha
@@ -686,7 +684,6 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeConverter, setCallbackDecode, "(JII[C)I"),
NATIVE_METHOD(NativeConverter, setCallbackEncode, "(JII[B)I"),
};
-int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/charset/NativeConverter",
- gMethods, NELEM(gMethods));
+int register_libcore_icu_NativeConverter(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "libcore/icu/NativeConverter", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/NativeCrypto.cpp b/luni/src/main/native/NativeCrypto.cpp
index f94b7e7..0f9ae1d 100644
--- a/luni/src/main/native/NativeCrypto.cpp
+++ b/luni/src/main/native/NativeCrypto.cpp
@@ -20,6 +20,7 @@
#define LOG_TAG "NativeCrypto"
+#include <algorithm>
#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
@@ -37,7 +38,6 @@
#include "JNIHelp.h"
#include "JniConstants.h"
#include "JniException.h"
-#include "LocalArray.h"
#include "NetFd.h"
#include "NetworkUtilities.h"
#include "ScopedLocalRef.h"
@@ -46,6 +46,8 @@
#include "UniquePtr.h"
#undef WITH_JNI_TRACE
+#undef WITH_JNI_TRACE_DATA
+
#ifdef WITH_JNI_TRACE
#define JNI_TRACE(...) \
((void)LOG(LOG_INFO, LOG_TAG "-jni", __VA_ARGS__)); \
@@ -57,6 +59,8 @@
#else
#define JNI_TRACE(...) ((void)0)
#endif
+// don't overwhelm logcat
+#define WITH_JNI_TRACE_DATA_CHUNK_SIZE 512
struct BIO_Delete {
void operator()(BIO* p) const {
@@ -86,6 +90,13 @@ struct DSA_Delete {
};
typedef UniquePtr<DSA, DSA_Delete> Unique_DSA;
+struct EC_KEY_Delete {
+ void operator()(EC_KEY* p) const {
+ EC_KEY_free(p);
+ }
+};
+typedef UniquePtr<EC_KEY, EC_KEY_Delete> Unique_EC_KEY;
+
struct EVP_PKEY_Delete {
void operator()(EVP_PKEY* p) const {
EVP_PKEY_free(p);
@@ -619,19 +630,19 @@ static jint NativeCrypto_EVP_MD_CTX_copy(JNIEnv* env, jclass, EVP_MD_CTX* ctx) {
if (ctx == NULL) {
jniThrowNullPointerException(env, NULL);
- return NULL;
+ return 0;
}
EVP_MD_CTX* copy = EVP_MD_CTX_create();
if (copy == NULL) {
jniThrowOutOfMemoryError(env, "Unable to allocate copy of EVP_MD_CTX");
- return NULL;
+ return 0;
}
EVP_MD_CTX_init(copy);
int result = EVP_MD_CTX_copy_ex(copy, ctx);
if (result == 0) {
EVP_MD_CTX_destroy(copy);
jniThrowRuntimeException(env, "Unable to copy EVP_MD_CTX");
- return NULL;
+ return 0;
}
JNI_TRACE("NativeCrypto_EVP_MD_CTX_copy(%p) => %p", ctx, copy);
return (jint) copy;
@@ -987,72 +998,6 @@ static int NativeCrypto_RAND_load_file(JNIEnv* env, jclass, jstring filename, jl
return result;
}
-/**
- * Convert ssl version constant to string. Based on SSL_get_version
- */
-// TODO move to jsse.patch
-static const char* get_ssl_version(int ssl_version) {
- switch (ssl_version) {
- // newest to oldest
- case TLS1_VERSION: {
- return SSL_TXT_TLSV1;
- }
- case SSL3_VERSION: {
- return SSL_TXT_SSLV3;
- }
- case SSL2_VERSION: {
- return SSL_TXT_SSLV2;
- }
- default: {
- return "unknown";
- }
- }
-}
-
-#ifdef WITH_JNI_TRACE
-/**
- * Convert content type constant to string.
- */
-// TODO move to jsse.patch
-static const char* get_content_type(int content_type) {
- switch (content_type) {
- case SSL3_RT_CHANGE_CIPHER_SPEC: {
- return "SSL3_RT_CHANGE_CIPHER_SPEC";
- }
- case SSL3_RT_ALERT: {
- return "SSL3_RT_ALERT";
- }
- case SSL3_RT_HANDSHAKE: {
- return "SSL3_RT_HANDSHAKE";
- }
- case SSL3_RT_APPLICATION_DATA: {
- return "SSL3_RT_APPLICATION_DATA";
- }
- default: {
- LOGD("Unknown TLS/SSL content type %d", content_type);
- return "<unknown>";
- }
- }
-}
-#endif
-
-#ifdef WITH_JNI_TRACE
-/**
- * Simple logging call back to show hand shake messages
- */
-static void ssl_msg_callback_LOG(int write_p, int ssl_version, int content_type,
- const void* buf, size_t len, SSL* ssl, void* arg) {
- JNI_TRACE("ssl=%p SSL msg %s %s %s %p %d %p",
- ssl,
- (write_p) ? "send" : "recv",
- get_ssl_version(ssl_version),
- get_content_type(content_type),
- buf,
- len,
- arg);
-}
-#endif
-
#ifdef WITH_JNI_TRACE
/**
* Based on example logging call back from SSL_CTX_set_info_callback man page
@@ -1259,11 +1204,14 @@ static jobjectArray getPrincipalBytes(JNIEnv* env, const STACK_OF(X509_NAME)* na
* the JNIEnv on calls that can read and write to the SSL such as
* SSL_do_handshake, SSL_read, SSL_write, and SSL_shutdown.
*
- * Finally, we have one other piece of state setup by OpenSSL callbacks:
+ * Finally, we have two emphemeral keys setup by OpenSSL callbacks:
*
* (8) a set of ephemeral RSA keys that is lazily generated if a peer
* wants to use an exportable RSA cipher suite.
*
+ * (9) a set of ephemeral EC keys that is lazily generated if a peer
+ * wants to use an TLS_ECDHE_* cipher suite.
+ *
*/
class AppData {
public:
@@ -1275,6 +1223,7 @@ class AppData {
jobject sslHandshakeCallbacks;
jobject fileDescriptor;
Unique_RSA ephemeralRsa;
+ Unique_EC_KEY ephemeralEc;
/**
* Creates the application data context for the SSL*.
@@ -1285,6 +1234,9 @@ class AppData {
if (pipe(appData.get()->fdsEmergency) == -1) {
return NULL;
}
+ if (!setBlocking(appData.get()->fdsEmergency[0], false)) {
+ return NULL;
+ }
if (MUTEX_SETUP(appData.get()->mutex) == -1) {
return NULL;
}
@@ -1308,7 +1260,8 @@ class AppData {
waitingThreads(0),
env(NULL),
sslHandshakeCallbacks(NULL),
- ephemeralRsa(NULL) {
+ ephemeralRsa(NULL),
+ ephemeralEc(NULL) {
fdsEmergency[0] = -1;
fdsEmergency[1] = -1;
}
@@ -1345,7 +1298,7 @@ class AppData {
/**
* Dark magic helper function that checks, for a given SSL session, whether it
* can SSL_read() or SSL_write() without blocking. Takes into account any
- * concurrent attempts to close the SSL session from the Java side. This is
+ * concurrent attempts to close the SSLSocket from the Java side. This is
* needed to get rid of the hangs that occur when thread #1 closes the SSLSocket
* while thread #2 is sitting in a blocking read or write. The type argument
* specifies whether we are waiting for readability or writability. It expects
@@ -1393,7 +1346,7 @@ static int sslSelect(JNIEnv* env, int type, jobject fdObject, AppData* appData,
FD_SET(appData->fdsEmergency[0], &rfds);
- int max = intFd > appData->fdsEmergency[0] ? intFd : appData->fdsEmergency[0];
+ int maxFd = (intFd > appData->fdsEmergency[0]) ? intFd : appData->fdsEmergency[0];
// Build a struct for the timeout data if we actually want a timeout.
timeval tv;
@@ -1406,32 +1359,34 @@ static int sslSelect(JNIEnv* env, int type, jobject fdObject, AppData* appData,
ptv = NULL;
}
- {
- AsynchronousSocketCloseMonitor monitor(intFd);
- result = select(max + 1, &rfds, &wfds, NULL, ptv);
- JNI_TRACE("sslSelect %s fd=%d appData=%p timeout=%d => %d",
- (type == SSL_ERROR_WANT_READ) ? "READ" : "WRITE",
- fd.get(), appData, timeout, result);
- if (result == -1) {
- if (fd.isClosed()) {
- result = THROWN_SOCKETEXCEPTION;
- break;
- }
- if (errno != EINTR) {
- break;
- }
+ AsynchronousSocketCloseMonitor monitor(intFd);
+ result = select(maxFd + 1, &rfds, &wfds, NULL, ptv);
+ JNI_TRACE("sslSelect %s fd=%d appData=%p timeout=%d => %d",
+ (type == SSL_ERROR_WANT_READ) ? "READ" : "WRITE",
+ fd.get(), appData, timeout, result);
+ if (result == -1) {
+ if (fd.isClosed()) {
+ result = THROWN_SOCKETEXCEPTION;
+ break;
+ }
+ if (errno != EINTR) {
+ break;
}
}
} while (result == -1);
- // Lock
if (MUTEX_LOCK(appData->mutex) == -1) {
return -1;
}
if (result > 0) {
- // If we have been woken up by the emergency pipe, there must be a token in
- // it. Thus we can safely read it (even in a blocking way).
+ // We have been woken up by a token in the emergency pipe. We
+ // can't be sure the token is still in the pipe at this point
+ // because it could have already been read by the thread that
+ // originally wrote it if it entered sslSelect and acquired
+ // the mutex before we did. Thus we cannot safely read from
+ // the pipe in a blocking way (so we make the pipe
+ // non-blocking at creation).
if (FD_ISSET(appData->fdsEmergency[0], &rfds)) {
char token;
do {
@@ -1444,7 +1399,6 @@ static int sslSelect(JNIEnv* env, int type, jobject fdObject, AppData* appData,
// underlying network.
appData->waitingThreads--;
- // Unlock
MUTEX_UNLOCK(appData->mutex);
return result;
@@ -1470,76 +1424,6 @@ static void sslNotify(AppData* appData) {
errno = errnoBackup;
}
-// From private header file external/openssl/ssl_locl.h
-// TODO move dependent code to jsse.patch to avoid dependency
-#define SSL_aRSA 0x00000001L
-#define SSL_aDSS 0x00000002L
-#define SSL_aNULL 0x00000004L
-#define SSL_aDH 0x00000008L
-#define SSL_aECDH 0x00000010L
-#define SSL_aKRB5 0x00000020L
-#define SSL_aECDSA 0x00000040L
-#define SSL_aPSK 0x00000080L
-
-/**
- * Converts an SSL_CIPHER's algorithms field to a TrustManager auth argument
- */
-// TODO move to jsse.patch
-static const char* SSL_CIPHER_authentication_method(const SSL_CIPHER* cipher)
-{
- unsigned long alg_auth = cipher->algorithm_auth;
-
- const char* au;
- switch (alg_auth) {
- case SSL_aRSA:
- au="RSA";
- break;
- case SSL_aDSS:
- au="DSS";
- break;
- case SSL_aDH:
- au="DH";
- break;
- case SSL_aKRB5:
- au="KRB5";
- break;
- case SSL_aECDH:
- au = "ECDH";
- break;
- case SSL_aNULL:
- au="None";
- break;
- case SSL_aECDSA:
- au="ECDSA";
- break;
- case SSL_aPSK:
- au="PSK";
- break;
- default:
- au="unknown";
- break;
- }
- return au;
-}
-
-/**
- * Converts an SSL_CIPHER's algorithms field to a TrustManager auth argument
- */
-// TODO move to jsse.patch
-static const char* SSL_authentication_method(SSL* ssl)
-{
- switch (ssl->version) {
- case SSL2_VERSION:
- return "RSA";
- case SSL3_VERSION:
- case TLS1_VERSION:
- case DTLS1_VERSION:
- return SSL_CIPHER_authentication_method(ssl->s3->tmp.new_cipher);
- default:
- return "unknown";
- }
-}
-
static AppData* toAppData(const SSL* ssl) {
return reinterpret_cast<AppData*>(SSL_get_app_data(ssl));
}
@@ -1782,6 +1666,31 @@ static DH* tmp_dh_callback(SSL* ssl __attribute__ ((unused)),
return tmp_dh;
}
+static EC_KEY* ecGenerateKey(int keylength __attribute__ ((unused))) {
+ // TODO selected curve based on keylength
+ Unique_EC_KEY ec(EC_KEY_new_by_curve_name(NID_X9_62_prime256v1));
+ if (ec.get() == NULL) {
+ return NULL;
+ }
+ return ec.release();
+}
+
+/**
+ * Call back to ask for an ephemeral EC key for TLS_ECDHE_* cipher suites
+ */
+static EC_KEY* tmp_ecdh_callback(SSL* ssl __attribute__ ((unused)),
+ int is_export __attribute__ ((unused)),
+ int keylength) {
+ JNI_TRACE("ssl=%p tmp_ecdh_callback is_export=%d keylength=%d", ssl, is_export, keylength);
+ AppData* appData = toAppData(ssl);
+ if (appData->ephemeralEc.get() == NULL) {
+ JNI_TRACE("ssl=%p tmp_ecdh_callback generating ephemeral EC key", ssl);
+ appData->ephemeralEc.reset(ecGenerateKey(keylength));
+ }
+ JNI_TRACE("ssl=%p tmp_ecdh_callback => %p", ssl, appData->ephemeralEc.get());
+ return appData->ephemeralEc.get();
+}
+
/*
* public static native int SSL_CTX_new();
*/
@@ -1789,7 +1698,7 @@ static int NativeCrypto_SSL_CTX_new(JNIEnv* env, jclass) {
Unique_SSL_CTX sslCtx(SSL_CTX_new(SSLv23_method()));
if (sslCtx.get() == NULL) {
jniThrowRuntimeException(env, "SSL_CTX_new");
- return NULL;
+ return 0;
}
SSL_CTX_set_options(sslCtx.get(),
SSL_OP_ALL
@@ -1800,7 +1709,9 @@ static int NativeCrypto_SSL_CTX_new(JNIEnv* env, jclass) {
// We also disable compression for better compatibility b/2710492 b/2710497
| SSL_OP_NO_COMPRESSION
// Because dhGenerateParameters uses DSA_generate_parameters_ex
- | SSL_OP_SINGLE_DH_USE);
+ | SSL_OP_SINGLE_DH_USE
+ // Because ecGenerateParameters uses a fixed named curve
+ | SSL_OP_SINGLE_ECDH_USE);
int mode = SSL_CTX_get_mode(sslCtx.get());
/*
@@ -1828,10 +1739,8 @@ static int NativeCrypto_SSL_CTX_new(JNIEnv* env, jclass) {
SSL_CTX_set_client_cert_cb(sslCtx.get(), client_cert_cb);
SSL_CTX_set_tmp_rsa_callback(sslCtx.get(), tmp_rsa_callback);
SSL_CTX_set_tmp_dh_callback(sslCtx.get(), tmp_dh_callback);
+ SSL_CTX_set_tmp_ecdh_callback(sslCtx.get(), tmp_ecdh_callback);
-#ifdef WITH_JNI_TRACE
- SSL_CTX_set_msg_callback(sslCtx.get(), ssl_msg_callback_LOG); /* enable for message debug */
-#endif
JNI_TRACE("NativeCrypto_SSL_CTX_new => %p", sslCtx.get());
return (jint) sslCtx.release();
}
@@ -1858,14 +1767,14 @@ static jint NativeCrypto_SSL_new(JNIEnv* env, jclass, jint ssl_ctx_address)
SSL_CTX* ssl_ctx = to_SSL_CTX(env, ssl_ctx_address, true);
JNI_TRACE("ssl_ctx=%p NativeCrypto_SSL_new", ssl_ctx);
if (ssl_ctx == NULL) {
- return NULL;
+ return 0;
}
Unique_SSL ssl(SSL_new(ssl_ctx));
if (ssl.get() == NULL) {
throwSSLExceptionWithSslErrors(env, NULL, SSL_ERROR_NONE,
"Unable to create SSL structure");
JNI_TRACE("ssl_ctx=%p NativeCrypto_SSL_new => NULL", ssl_ctx);
- return NULL;
+ return 0;
}
/* Java code in class OpenSSLSocketImpl does the verification. Meaning of
@@ -1917,6 +1826,8 @@ static void NativeCrypto_SSL_use_PrivateKey(JNIEnv* env, jclass,
return;
}
+ JNI_TRACE("ssl=%p NativeCrypto_SSL_use_PrivateKey EVP_PKEY_type=%d",
+ ssl, EVP_PKEY_type(privatekeyevp.get()->type));
int ret = SSL_use_PrivateKey(ssl, privatekeyevp.get());
if (ret == 1) {
privatekeyevp.release();
@@ -2323,7 +2234,8 @@ static void NativeCrypto_SSL_set_tlsext_host_name(JNIEnv* env, jclass,
if (hostnameChars.c_str() == NULL) {
return;
}
- JNI_TRACE("NativeCrypto_SSL_set_tlsext_host_name hostnameChars=%s", hostnameChars.c_str());
+ JNI_TRACE("ssl=%p NativeCrypto_SSL_set_tlsext_host_name hostnameChars=%s",
+ ssl, hostnameChars.c_str());
int ret = SSL_set_tlsext_host_name(ssl, hostnameChars.c_str());
if (ret != 1) {
@@ -2421,6 +2333,7 @@ static jint NativeCrypto_SSL_do_handshake(JNIEnv* env, jclass,
ret = 0;
while (appData->aliveAndKicking) {
errno = 0;
+
if (!appData->setCallbackState(env, shc, fdObject)) {
// SocketException thrown by NetFd.isClosed
SSL_clear(ssl);
@@ -2635,8 +2548,7 @@ static jobjectArray NativeCrypto_SSL_get_peer_cert_chain(JNIEnv* env, jclass, ji
*/
static int sslRead(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, char* buf, jint len,
int* sslReturnCode, int* sslErrorCode, int timeout) {
-
- // LOGD("Entering sslRead, caller requests to read %d bytes...", len);
+ JNI_TRACE("ssl=%p sslRead buf=%p len=%d", ssl, buf, len);
if (len == 0) {
// Don't bother doing anything in this case.
@@ -2653,14 +2565,12 @@ static int sslRead(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, char* b
while (appData->aliveAndKicking) {
errno = 0;
- // Lock
if (MUTEX_LOCK(appData->mutex) == -1) {
return -1;
}
unsigned int bytesMoved = BIO_number_read(bio) + BIO_number_written(bio);
- // LOGD("Doing SSL_Read()");
if (!appData->setCallbackState(env, shc, fdObject)) {
MUTEX_UNLOCK(appData->mutex);
return THROWN_SOCKETEXCEPTION;
@@ -2672,7 +2582,13 @@ static int sslRead(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, char* b
sslError = SSL_get_error(ssl, result);
freeSslErrorState();
}
- // LOGD("Returned from SSL_Read() with result %d, error code %d", result, sslError);
+ JNI_TRACE("ssl=%p sslRead SSL_read result=%d sslError=%d", ssl, result, sslError);
+#ifdef WITH_JNI_TRACE_DATA
+ for (int i = 0; i < result; i+= WITH_JNI_TRACE_DATA_CHUNK_SIZE) {
+ int n = std::min(result - i, WITH_JNI_TRACE_DATA_CHUNK_SIZE);
+ JNI_TRACE("ssl=%p sslRead data: %d:\n%*s", ssl, n, n, buf+i);
+ }
+#endif
// If we have been successful in moving data around, check whether it
// might make sense to wake up other blocked threads, so they can give
@@ -2688,7 +2604,6 @@ static int sslRead(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, char* b
appData->waitingThreads++;
}
- // Unlock
MUTEX_UNLOCK(appData->mutex);
switch (sslError) {
@@ -2882,8 +2797,7 @@ static jint NativeCrypto_SSL_read(JNIEnv* env, jclass, jint ssl_address, jobject
*/
static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const char* buf, jint len,
int* sslReturnCode, int* sslErrorCode) {
-
- // LOGD("Entering sslWrite(), caller requests to write %d bytes...", len);
+ JNI_TRACE("ssl=%p sslWrite buf=%p len=%d", ssl, buf, len);
if (len == 0) {
// Don't bother doing anything in this case.
@@ -2901,6 +2815,7 @@ static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const
while (appData->aliveAndKicking && len > 0) {
errno = 0;
+
if (MUTEX_LOCK(appData->mutex) == -1) {
return -1;
}
@@ -2919,7 +2834,13 @@ static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const
sslError = SSL_get_error(ssl, result);
freeSslErrorState();
}
- // LOGD("Returned from SSL_write() with result %d, error code %d", result, error);
+ JNI_TRACE("ssl=%p sslWrite SSL_write result=%d sslError=%d", ssl, result, sslError);
+#ifdef WITH_JNI_TRACE_DATA
+ for (int i = 0; i < result; i+= WITH_JNI_TRACE_DATA_CHUNK_SIZE) {
+ int n = std::min(result - i, WITH_JNI_TRACE_DATA_CHUNK_SIZE);
+ JNI_TRACE("ssl=%p sslWrite data: %d:\n%*s", ssl, n, n, buf+i);
+ }
+#endif
// If we have been successful in moving data around, check whether it
// might make sense to wake up other blocked threads, so they can give
@@ -2938,7 +2859,7 @@ static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const
MUTEX_UNLOCK(appData->mutex);
switch (sslError) {
- // Successfully write at least one byte.
+ // Successfully wrote at least one byte.
case SSL_ERROR_NONE: {
buf += result;
len -= result;
@@ -2971,7 +2892,7 @@ static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const
break;
}
- // An problem occurred during a system call, but this is not
+ // A problem occurred during a system call, but this is not
// necessarily an error.
case SSL_ERROR_SYSCALL: {
// Connection closed without proper shutdown. Tell caller we
@@ -2997,7 +2918,7 @@ static int sslWrite(JNIEnv* env, SSL* ssl, jobject fdObject, jobject shc, const
}
}
}
- // LOGD("Successfully wrote %d bytes", count);
+ JNI_TRACE("ssl=%p sslWrite => count=%d", ssl, count);
return count;
}
@@ -3248,16 +3169,6 @@ static jlong NativeCrypto_SSL_SESSION_get_time(JNIEnv* env, jclass, jint ssl_ses
}
/**
- * Our implementation of what might be considered
- * SSL_SESSION_get_version, based on SSL_get_version.
- * See get_ssl_version above.
- */
-// TODO move to jsse.patch
-static const char* SSL_SESSION_get_version(SSL_SESSION* ssl_session) {
- return get_ssl_version(ssl_session->ssl_version);
-}
-
-/**
* Gets and returns in a string the version of the SSL protocol. If it
* returns the string "unknown" it means that no connection is established.
*/
diff --git a/luni/src/main/native/NativeDecimalFormat.cpp b/luni/src/main/native/NativeDecimalFormat.cpp
index 4fc7448..51113fa 100644
--- a/luni/src/main/native/NativeDecimalFormat.cpp
+++ b/luni/src/main/native/NativeDecimalFormat.cpp
@@ -336,9 +336,9 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeDecimalFormat, applyPatternImpl, "(IZLjava/lang/String;)V"),
NATIVE_METHOD(NativeDecimalFormat, cloneImpl, "(I)I"),
NATIVE_METHOD(NativeDecimalFormat, close, "(I)V"),
- NATIVE_METHOD(NativeDecimalFormat, formatDouble, "(IDLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)[C"),
- NATIVE_METHOD(NativeDecimalFormat, formatLong, "(IJLcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)[C"),
- NATIVE_METHOD(NativeDecimalFormat, formatDigitList, "(ILjava/lang/String;Lcom/ibm/icu4jni/text/NativeDecimalFormat$FieldPositionIterator;)[C"),
+ NATIVE_METHOD(NativeDecimalFormat, formatDouble, "(IDLlibcore/icu/NativeDecimalFormat$FieldPositionIterator;)[C"),
+ NATIVE_METHOD(NativeDecimalFormat, formatLong, "(IJLlibcore/icu/NativeDecimalFormat$FieldPositionIterator;)[C"),
+ NATIVE_METHOD(NativeDecimalFormat, formatDigitList, "(ILjava/lang/String;Llibcore/icu/NativeDecimalFormat$FieldPositionIterator;)[C"),
NATIVE_METHOD(NativeDecimalFormat, getAttribute, "(II)I"),
NATIVE_METHOD(NativeDecimalFormat, getTextAttribute, "(II)Ljava/lang/String;"),
NATIVE_METHOD(NativeDecimalFormat, open, "(Ljava/lang/String;Ljava/lang/String;CCLjava/lang/String;CLjava/lang/String;Ljava/lang/String;CCLjava/lang/String;CCCC)I"),
@@ -350,7 +350,6 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(NativeDecimalFormat, setTextAttribute, "(IILjava/lang/String;)V"),
NATIVE_METHOD(NativeDecimalFormat, toPatternImpl, "(IZ)Ljava/lang/String;"),
};
-int register_com_ibm_icu4jni_text_NativeDecimalFormat(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "com/ibm/icu4jni/text/NativeDecimalFormat", gMethods,
- NELEM(gMethods));
+int register_libcore_icu_NativeDecimalFormat(JNIEnv* env) {
+ return jniRegisterNativeMethods(env, "libcore/icu/NativeDecimalFormat", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/Register.cpp b/luni/src/main/native/Register.cpp
index 0c953cb..a6e49dc 100644
--- a/luni/src/main/native/Register.cpp
+++ b/luni/src/main/native/Register.cpp
@@ -14,23 +14,20 @@
* limitations under the License.
*/
+#define LOG_TAG "libcore" // We'll be next to "dalvikvm" in the log; make the distinction clear.
+
#include "JniConstants.h"
#include "ScopedLocalFrame.h"
+#include <stdlib.h>
+
namespace android {
extern int register_dalvik_system_TouchDex(JNIEnv* env);
}
-extern int register_com_ibm_icu4jni_converters_NativeConverter(JNIEnv* env);
-extern int register_com_ibm_icu4jni_text_NativeBreakIterator(JNIEnv* env);
-extern int register_com_ibm_icu4jni_text_NativeCollator(JNIEnv* env);
-extern int register_com_ibm_icu4jni_text_NativeDecimalFormat(JNIEnv* env);
-extern int register_com_ibm_icu4jni_util_ICU(JNIEnv* env);
extern int register_java_io_Console(JNIEnv* env);
extern int register_java_io_File(JNIEnv* env);
extern int register_java_io_FileDescriptor(JNIEnv* env);
-extern int register_java_io_ObjectInputStream(JNIEnv* env);
-extern int register_java_io_ObjectOutputStream(JNIEnv* env);
extern int register_java_io_ObjectStreamClass(JNIEnv* env);
extern int register_java_lang_Character(JNIEnv* env);
extern int register_java_lang_Double(JNIEnv* env);
@@ -51,11 +48,17 @@ extern int register_java_util_zip_Adler32(JNIEnv* env);
extern int register_java_util_zip_CRC32(JNIEnv* env);
extern int register_java_util_zip_Deflater(JNIEnv* env);
extern int register_java_util_zip_Inflater(JNIEnv* env);
+extern int register_libcore_icu_ICU(JNIEnv* env);
+extern int register_libcore_icu_NativeBreakIterator(JNIEnv* env);
+extern int register_libcore_icu_NativeCollation(JNIEnv* env);
+extern int register_libcore_icu_NativeConverter(JNIEnv* env);
+extern int register_libcore_icu_NativeDecimalFormat(JNIEnv* env);
extern int register_libcore_icu_NativeIDN(JNIEnv* env);
extern int register_libcore_icu_NativeNormalizer(JNIEnv* env);
extern int register_libcore_icu_NativePluralRules(JNIEnv* env);
extern int register_libcore_icu_TimeZones(JNIEnv* env);
extern int register_libcore_io_IoUtils(JNIEnv* env);
+extern int register_libcore_net_RawSocket(JNIEnv* env);
extern int register_org_apache_harmony_dalvik_NativeTestTarget(JNIEnv* env);
extern int register_org_apache_harmony_luni_platform_OSFileSystem(JNIEnv* env);
extern int register_org_apache_harmony_luni_platform_OSMemory(JNIEnv* env);
@@ -72,16 +75,9 @@ extern "C" int registerCoreLibrariesJni(JNIEnv* env) {
JniConstants::init(env);
bool result =
- register_com_ibm_icu4jni_converters_NativeConverter(env) != -1 &&
- register_com_ibm_icu4jni_text_NativeBreakIterator(env) != -1 &&
- register_com_ibm_icu4jni_text_NativeCollator(env) != -1 &&
- register_com_ibm_icu4jni_text_NativeDecimalFormat(env) != -1 &&
- register_com_ibm_icu4jni_util_ICU(env) != -1 &&
register_java_io_Console(env) != -1 &&
register_java_io_File(env) != -1 &&
register_java_io_FileDescriptor(env) != -1 &&
- register_java_io_ObjectInputStream(env) != -1 &&
- register_java_io_ObjectOutputStream(env) != -1 &&
register_java_io_ObjectStreamClass(env) != -1 &&
register_java_lang_Character(env) != -1 &&
register_java_lang_Double(env) != -1 &&
@@ -102,11 +98,17 @@ extern "C" int registerCoreLibrariesJni(JNIEnv* env) {
register_java_util_zip_CRC32(env) != -1 &&
register_java_util_zip_Deflater(env) != -1 &&
register_java_util_zip_Inflater(env) != -1 &&
+ register_libcore_icu_ICU(env) != -1 &&
+ register_libcore_icu_NativeBreakIterator(env) != -1 &&
+ register_libcore_icu_NativeCollation(env) != -1 &&
+ register_libcore_icu_NativeConverter(env) != -1 &&
+ register_libcore_icu_NativeDecimalFormat(env) != -1 &&
register_libcore_icu_NativeIDN(env) != -1 &&
register_libcore_icu_NativeNormalizer(env) != -1 &&
register_libcore_icu_NativePluralRules(env) != -1 &&
register_libcore_icu_TimeZones(env) != -1 &&
register_libcore_io_IoUtils(env) != -1 &&
+ register_libcore_net_RawSocket(env) != -1 &&
register_org_apache_harmony_luni_platform_OSFileSystem(env) != -1 &&
register_org_apache_harmony_luni_platform_OSMemory(env) != -1 &&
register_org_apache_harmony_luni_platform_OSNetworkSystem(env) != -1 &&
@@ -118,5 +120,9 @@ extern "C" int registerCoreLibrariesJni(JNIEnv* env) {
register_org_apache_harmony_dalvik_NativeTestTarget(env) != -1 &&
register_org_apache_harmony_xml_ExpatParser(env) != -1;
- return result ? 0 : -1;
+ if (!result) {
+ LOGE("Failed to initialize the core libraries; aborting...");
+ abort();
+ }
+ return 0;
}
diff --git a/luni/src/main/native/cbigint.cpp b/luni/src/main/native/cbigint.cpp
index 0b7cc42..da15fcb 100644
--- a/luni/src/main/native/cbigint.cpp
+++ b/luni/src/main/native/cbigint.cpp
@@ -251,29 +251,26 @@ simpleMultiplyAddHighPrecision (uint64_t * arg1, int32_t length, uint64_t arg2,
#if __BYTE_ORDER != __LITTLE_ENDIAN
void simpleMultiplyAddHighPrecisionBigEndianFix(uint64_t* arg1, int32_t length, uint64_t arg2, uint32_t* result) {
- /* Assumes result can hold the product and arg2 only holds 32 bits
- of information */
- uint64_t product;
- int32_t index, resultIndex;
-
- index = resultIndex = 0;
- product = 0;
-
- do {
- product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * LOW_U32_FROM_PTR(arg1 + index);
- result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
- ++resultIndex;
- product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * HIGH_U32_FROM_PTR(arg1 + index);
- result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
- ++resultIndex;
- } while (++index < length);
-
- result[halfAt(resultIndex)] += HIGH_U32_FROM_VAR(product);
- if (result[halfAt(resultIndex)] < HIGH_U32_FROM_VAR(product)) {
- /* must be careful with ++ operator and macro expansion */
- ++resultIndex;
- while (++result[halfAt(resultIndex)] == 0) ++resultIndex;
- }
+ /* Assumes result can hold the product and arg2 only holds 32 bits of information */
+ int32_t index = 0;
+ int32_t resultIndex = 0;
+ uint64_t product = 0;
+
+ do {
+ product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * LOW_U32_FROM_PTR(arg1 + index);
+ result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
+ ++resultIndex;
+ product = HIGH_IN_U64(product) + result[halfAt(resultIndex)] + arg2 * HIGH_U32_FROM_PTR(arg1 + index);
+ result[halfAt(resultIndex)] = LOW_U32_FROM_VAR(product);
+ ++resultIndex;
+ } while (++index < length);
+
+ result[halfAt(resultIndex)] += HIGH_U32_FROM_VAR(product);
+ if (result[halfAt(resultIndex)] < HIGH_U32_FROM_VAR(product)) {
+ /* must be careful with ++ operator and macro expansion */
+ ++resultIndex;
+ while (++result[halfAt(resultIndex)] == 0) ++resultIndex;
+ }
}
#endif
diff --git a/luni/src/main/native/ifaddrs-android.cpp b/luni/src/main/native/ifaddrs-android.cpp
new file mode 100644
index 0000000..4193bdf
--- /dev/null
+++ b/luni/src/main/native/ifaddrs-android.cpp
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_ANDROID_OS
+
+#include "ifaddrs-android.h"
+
+#include <arpa/inet.h>
+#include <cstring>
+#include <errno.h>
+#include <net/if.h>
+#include <netinet/in.h>
+#include <new>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include "ScopedFd.h"
+#include "UniquePtr.h"
+
+ifaddrs::ifaddrs(ifaddrs* next, sockaddr* ifa_addr, sockaddr* ifa_netmask)
+: ifa_next(next), ifa_name(NULL), ifa_flags(0), ifa_addr(ifa_addr), ifa_netmask(ifa_netmask)
+{
+}
+
+ifaddrs::~ifaddrs() {
+ delete ifa_next;
+ delete[] ifa_name;
+ delete ifa_addr;
+ delete ifa_netmask;
+}
+
+static bool sendNetlinkMessage(int fd, const void* data, size_t byteCount) {
+ ssize_t sentByteCount = TEMP_FAILURE_RETRY(send(fd, data, byteCount, 0));
+ return (sentByteCount == static_cast<ssize_t>(byteCount));
+}
+
+static ssize_t recvNetlinkMessage(int fd, char* buf, size_t byteCount) {
+ return TEMP_FAILURE_RETRY(recv(fd, buf, byteCount, 0));
+}
+
+// Returns a pointer to the first byte in the address data (which is
+// stored in network byte order).
+static uint8_t* sockaddrBytes(int family, sockaddr_storage* ss) {
+ if (family == AF_INET) {
+ sockaddr_in* ss4 = reinterpret_cast<sockaddr_in*>(ss);
+ return reinterpret_cast<uint8_t*>(&ss4->sin_addr);
+ } else if (family == AF_INET6) {
+ sockaddr_in6* ss6 = reinterpret_cast<sockaddr_in6*>(ss);
+ return reinterpret_cast<uint8_t*>(&ss6->sin6_addr);
+ }
+ return NULL;
+}
+
+// Netlink gives us the address family in the header, and the
+// sockaddr_in or sockaddr_in6 bytes as the payload. We need to
+// stitch the two bits together into the sockaddr that's part of
+// our portable interface.
+static sockaddr* toSocketAddress(int family, void* data, size_t byteCount) {
+ // Set the address proper...
+ sockaddr_storage* ss = new sockaddr_storage;
+ memset(ss, 0, sizeof(*ss));
+ ss->ss_family = family;
+ uint8_t* dst = sockaddrBytes(family, ss);
+ memcpy(dst, data, byteCount);
+ return reinterpret_cast<sockaddr*>(ss);
+}
+
+// Netlink gives us the prefix length as a bit count. We need to turn
+// that into a BSD-compatible netmask represented by a sockaddr*.
+static sockaddr* toNetmask(int family, size_t prefixLength) {
+ // ...and work out the netmask from the prefix length.
+ sockaddr_storage* ss = new sockaddr_storage;
+ memset(ss, 0, sizeof(*ss));
+ ss->ss_family = family;
+ uint8_t* dst = sockaddrBytes(family, ss);
+ memset(dst, 0xff, prefixLength / 8);
+ if ((prefixLength % 8) != 0) {
+ dst[prefixLength/8] = (0xff << (8 - (prefixLength % 8)));
+ }
+ return reinterpret_cast<sockaddr*>(ss);
+}
+
+// Sadly, we can't keep the interface index for portability with BSD.
+// We'll have to keep the name instead, and re-query the index when
+// we need it later.
+static bool setNameAndFlagsByIndex(ifaddrs* ifa, int interfaceIndex) {
+ // Get the name.
+ char buf[IFNAMSIZ];
+ char* name = if_indextoname(interfaceIndex, buf);
+ if (name == NULL) {
+ return false;
+ }
+ ifa->ifa_name = new char[strlen(name) + 1];
+ strcpy(ifa->ifa_name, name);
+
+ // Get the flags.
+ ScopedFd fd(socket(AF_INET, SOCK_DGRAM, 0));
+ if (fd.get() == -1) {
+ return false;
+ }
+ ifreq ifr;
+ memset(&ifr, 0, sizeof(ifr));
+ strcpy(ifr.ifr_name, name);
+ int rc = ioctl(fd.get(), SIOCGIFFLAGS, &ifr);
+ if (rc == -1) {
+ return false;
+ }
+ ifa->ifa_flags = ifr.ifr_flags;
+ return true;
+}
+
+// Source-compatible with the BSD function.
+int getifaddrs(ifaddrs** result) {
+ // Simplify cleanup for callers.
+ *result = NULL;
+
+ // Create a netlink socket.
+ ScopedFd fd(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE));
+ if (fd.get() < 0) {
+ return -1;
+ }
+
+ // Ask for the address information.
+ struct {
+ nlmsghdr netlinkHeader;
+ ifaddrmsg msg;
+ } request;
+ memset(&request, 0, sizeof(request));
+ request.netlinkHeader.nlmsg_flags = NLM_F_ROOT | NLM_F_REQUEST | NLM_F_MATCH;
+ request.netlinkHeader.nlmsg_type = RTM_GETADDR;
+ request.netlinkHeader.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(request)));
+ request.msg.ifa_family = AF_UNSPEC; // All families.
+ request.msg.ifa_index = 0; // All interfaces.
+ if (!sendNetlinkMessage(fd.get(), &request, request.netlinkHeader.nlmsg_len)) {
+ return -1;
+ }
+
+ // Read the responses.
+ const size_t bufferSize = 65536;
+ UniquePtr<char[]> buf(new char[bufferSize]);
+ ssize_t bytesRead;
+ while ((bytesRead = recvNetlinkMessage(fd.get(), &buf[0], bufferSize)) > 0) {
+ nlmsghdr* hdr = reinterpret_cast<nlmsghdr*>(&buf[0]);
+ for (; NLMSG_OK(hdr, (size_t)bytesRead); hdr = NLMSG_NEXT(hdr, bytesRead)) {
+ switch (hdr->nlmsg_type) {
+ case NLMSG_DONE:
+ return 0;
+ case NLMSG_ERROR:
+ return -1;
+ case RTM_NEWADDR:
+ {
+ // A given RTM_NEWADDR payload may contain multiple addresses. The while loop
+ // below iterates through them. These locals contain the best address we've
+ // seen so far.
+ int ifa_index = -1;
+ UniquePtr<sockaddr> ifa_addr;
+ UniquePtr<sockaddr> ifa_netmask;
+
+ ifaddrmsg* address = reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(hdr));
+ rtattr* rta = IFA_RTA(address);
+ size_t ifaPayloadLength = IFA_PAYLOAD(hdr);
+ while (RTA_OK(rta, ifaPayloadLength)) {
+ // We can't just use IFA_ADDRESS because it's the destination address for
+ // a point-to-point interface; we can't just use IFA_LOCAL because we don't
+ // always have it. That is: we want IFA_LOCAL if we get it, but IFA_ADDRESS
+ // otherwise. We take advantage of the fact that the kernel returns
+ // IFA_LOCAL (if available) second.
+ if (rta->rta_type == IFA_LOCAL || rta->rta_type == IFA_ADDRESS) {
+ int family = address->ifa_family;
+ if (family == AF_INET || family == AF_INET6) {
+ ifa_index = address->ifa_index;
+ ifa_addr.reset(toSocketAddress(family, RTA_DATA(rta), RTA_PAYLOAD(rta)));
+ ifa_netmask.reset(toNetmask(family, address->ifa_prefixlen));
+ }
+ }
+ rta = RTA_NEXT(rta, ifaPayloadLength);
+ }
+
+ // Did we get a usable address? If so, thread it on our list.
+ if (ifa_index != -1) {
+ *result = new ifaddrs(*result, ifa_addr.release(), ifa_netmask.release());
+ if (!setNameAndFlagsByIndex(*result, ifa_index)) {
+ return -1;
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ // We only get here if recv fails before we see a NLMSG_DONE.
+ return -1;
+}
+
+// Source-compatible with the BSD function.
+void freeifaddrs(ifaddrs* addresses) {
+ delete addresses;
+}
+
+#endif
diff --git a/luni/src/main/native/ifaddrs-android.h b/luni/src/main/native/ifaddrs-android.h
index 446d8d2..c89d08a 100644
--- a/luni/src/main/native/ifaddrs-android.h
+++ b/luni/src/main/native/ifaddrs-android.h
@@ -17,25 +17,11 @@
#ifndef IFADDRS_ANDROID_H_included
#define IFADDRS_ANDROID_H_included
-#include <arpa/inet.h>
-#include <cstring>
-#include <errno.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <new>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <stdio.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-
-#include "LocalArray.h"
-#include "ScopedFd.h"
+struct sockaddr;
// Android (bionic) doesn't have getifaddrs(3)/freeifaddrs(3).
-// We fake it here, so java_net_NetworkInterface.cpp can use that API
-// with all the non-portable code being in this file.
+// We fake it here, so java_net_NetworkInterface.cpp can use that API.
+// This code should move into bionic, though.
// Source-compatible subset of the BSD struct.
struct ifaddrs {
@@ -54,88 +40,9 @@ struct ifaddrs {
// Interface netmask.
sockaddr* ifa_netmask;
- ifaddrs(ifaddrs* next)
- : ifa_next(next), ifa_name(NULL), ifa_flags(0), ifa_addr(NULL), ifa_netmask(NULL)
- {
- }
-
- ~ifaddrs() {
- delete ifa_next;
- delete[] ifa_name;
- delete ifa_addr;
- delete ifa_netmask;
- }
-
- // Sadly, we can't keep the interface index for portability with BSD.
- // We'll have to keep the name instead, and re-query the index when
- // we need it later.
- bool setNameAndFlagsByIndex(int interfaceIndex) {
- // Get the name.
- char buf[IFNAMSIZ];
- char* name = if_indextoname(interfaceIndex, buf);
- if (name == NULL) {
- return false;
- }
- ifa_name = new char[strlen(name) + 1];
- strcpy(ifa_name, name);
-
- // Get the flags.
- ScopedFd fd(socket(AF_INET, SOCK_DGRAM, 0));
- if (fd.get() == -1) {
- return false;
- }
- ifreq ifr;
- memset(&ifr, 0, sizeof(ifr));
- strcpy(ifr.ifr_name, name);
- int rc = ioctl(fd.get(), SIOCGIFFLAGS, &ifr);
- if (rc == -1) {
- return false;
- }
- ifa_flags = ifr.ifr_flags;
- return true;
- }
+ ifaddrs(ifaddrs* next, sockaddr* ifa_addr, sockaddr* ifa_netmask);
- // Netlink gives us the address family in the header, and the
- // sockaddr_in or sockaddr_in6 bytes as the payload. We need to
- // stitch the two bits together into the sockaddr that's part of
- // our portable interface.
- void setAddress(int family, void* data, size_t byteCount) {
- // Set the address proper...
- sockaddr_storage* ss = new sockaddr_storage;
- memset(ss, 0, sizeof(*ss));
- ifa_addr = reinterpret_cast<sockaddr*>(ss);
- ss->ss_family = family;
- uint8_t* dst = sockaddrBytes(family, ss);
- memcpy(dst, data, byteCount);
- }
-
- // Netlink gives us the prefix length as a bit count. We need to turn
- // that into a BSD-compatible netmask represented by a sockaddr*.
- void setNetmask(int family, size_t prefixLength) {
- // ...and work out the netmask from the prefix length.
- sockaddr_storage* ss = new sockaddr_storage;
- memset(ss, 0, sizeof(*ss));
- ifa_netmask = reinterpret_cast<sockaddr*>(ss);
- ss->ss_family = family;
- uint8_t* dst = sockaddrBytes(family, ss);
- memset(dst, 0xff, prefixLength / 8);
- if ((prefixLength % 8) != 0) {
- dst[prefixLength/8] = (0xff << (8 - (prefixLength % 8)));
- }
- }
-
- // Returns a pointer to the first byte in the address data (which is
- // stored in network byte order).
- uint8_t* sockaddrBytes(int family, sockaddr_storage* ss) {
- if (family == AF_INET) {
- sockaddr_in* ss4 = reinterpret_cast<sockaddr_in*>(ss);
- return reinterpret_cast<uint8_t*>(&ss4->sin_addr);
- } else if (family == AF_INET6) {
- sockaddr_in6* ss6 = reinterpret_cast<sockaddr_in6*>(ss);
- return reinterpret_cast<uint8_t*>(&ss6->sin6_addr);
- }
- return NULL;
- }
+ ~ifaddrs();
private:
// Disallow copy and assignment.
@@ -143,86 +50,7 @@ private:
void operator=(const ifaddrs&);
};
-// FIXME: use iovec instead.
-struct addrReq_struct {
- nlmsghdr netlinkHeader;
- ifaddrmsg msg;
-};
-
-inline bool sendNetlinkMessage(int fd, const void* data, size_t byteCount) {
- ssize_t sentByteCount = TEMP_FAILURE_RETRY(send(fd, data, byteCount, 0));
- return (sentByteCount == static_cast<ssize_t>(byteCount));
-}
-
-inline ssize_t recvNetlinkMessage(int fd, char* buf, size_t byteCount) {
- return TEMP_FAILURE_RETRY(recv(fd, buf, byteCount, 0));
-}
-
-// Source-compatible with the BSD function.
-inline int getifaddrs(ifaddrs** result) {
- // Simplify cleanup for callers.
- *result = NULL;
-
- // Create a netlink socket.
- ScopedFd fd(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE));
- if (fd.get() < 0) {
- return -1;
- }
-
- // Ask for the address information.
- addrReq_struct addrRequest;
- memset(&addrRequest, 0, sizeof(addrRequest));
- addrRequest.netlinkHeader.nlmsg_flags = NLM_F_REQUEST | NLM_F_MATCH;
- addrRequest.netlinkHeader.nlmsg_type = RTM_GETADDR;
- addrRequest.netlinkHeader.nlmsg_len = NLMSG_ALIGN(NLMSG_LENGTH(sizeof(addrRequest)));
- addrRequest.msg.ifa_family = AF_UNSPEC; // All families.
- addrRequest.msg.ifa_index = 0; // All interfaces.
- if (!sendNetlinkMessage(fd.get(), &addrRequest, addrRequest.netlinkHeader.nlmsg_len)) {
- return -1;
- }
-
- // Read the responses.
- LocalArray<0> buf(65536); // We don't necessarily have std::vector.
- ssize_t bytesRead;
- while ((bytesRead = recvNetlinkMessage(fd.get(), &buf[0], buf.size())) > 0) {
- nlmsghdr* hdr = reinterpret_cast<nlmsghdr*>(&buf[0]);
- for (; NLMSG_OK(hdr, (size_t)bytesRead); hdr = NLMSG_NEXT(hdr, bytesRead)) {
- switch (hdr->nlmsg_type) {
- case NLMSG_DONE:
- return 0;
- case NLMSG_ERROR:
- return -1;
- case RTM_NEWADDR:
- {
- ifaddrmsg* address = reinterpret_cast<ifaddrmsg*>(NLMSG_DATA(hdr));
- rtattr* rta = IFA_RTA(address);
- size_t ifaPayloadLength = IFA_PAYLOAD(hdr);
- while (RTA_OK(rta, ifaPayloadLength)) {
- if (rta->rta_type == IFA_LOCAL) {
- int family = address->ifa_family;
- if (family == AF_INET || family == AF_INET6) {
- *result = new ifaddrs(*result);
- if (!(*result)->setNameAndFlagsByIndex(address->ifa_index)) {
- return -1;
- }
- (*result)->setAddress(family, RTA_DATA(rta), RTA_PAYLOAD(rta));
- (*result)->setNetmask(family, address->ifa_prefixlen);
- }
- }
- rta = RTA_NEXT(rta, ifaPayloadLength);
- }
- }
- break;
- }
- }
- }
- // We only get here if recv fails before we see a NLMSG_DONE.
- return -1;
-}
-
-// Source-compatible with the BSD function.
-inline void freeifaddrs(ifaddrs* addresses) {
- delete addresses;
-}
+int getifaddrs(ifaddrs** result);
+void freeifaddrs(ifaddrs* addresses);
#endif // IFADDRS_ANDROID_H_included
diff --git a/luni/src/main/native/java_io_File.cpp b/luni/src/main/native/java_io_File.cpp
index e14cf73..3004fc4 100644
--- a/luni/src/main/native/java_io_File.cpp
+++ b/luni/src/main/native/java_io_File.cpp
@@ -24,6 +24,10 @@
#include "ScopedLocalRef.h"
#include "ScopedPrimitiveArray.h"
#include "ScopedUtfChars.h"
+#include "StaticAssert.h"
+#include "readlink.h"
+
+#include <string>
#include <dirent.h>
#include <errno.h>
@@ -31,8 +35,8 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/vfs.h>
#include <sys/types.h>
+#include <sys/vfs.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
@@ -56,22 +60,7 @@ static bool doStat(JNIEnv* env, jstring javaPath, struct stat& sb) {
static jlong File_lengthImpl(JNIEnv* env, jclass, jstring javaPath) {
struct stat sb;
if (!doStat(env, javaPath, sb)) {
- // We must return 0 for files that don't exist.
- // TODO: shouldn't we throw an IOException for ELOOP or EACCES?
- return 0;
- }
-
- /*
- * This android-changed code explicitly treats non-regular files (e.g.,
- * sockets and block-special devices) as having size zero. Some synthetic
- * "regular" files may report an arbitrary non-zero size, but
- * in these cases they generally report a block count of zero.
- * So, use a zero block count to trump any other concept of
- * size.
- *
- * TODO: why do we do this?
- */
- if (!S_ISREG(sb.st_mode) || sb.st_blocks == 0) {
+ // The RI returns 0 on error. (Even for errors like EACCES or ELOOP.)
return 0;
}
return sb.st_size;
@@ -125,24 +114,27 @@ static jstring File_readlink(JNIEnv* env, jclass, jstring javaPath) {
return NULL;
}
- // We can't know how big a buffer readlink(2) will need, so we need to
- // loop until it says "that fit".
- size_t bufSize = 512;
- while (true) {
- LocalArray<512> buf(bufSize);
- ssize_t len = readlink(path.c_str(), &buf[0], buf.size() - 1);
- if (len == -1) {
- // An error occurred.
- return javaPath;
- }
- if (static_cast<size_t>(len) < buf.size() - 1) {
- // The buffer was big enough.
- buf[len] = '\0'; // readlink(2) doesn't NUL-terminate.
- return env->NewStringUTF(&buf[0]);
- }
- // Try again with a bigger buffer.
- bufSize *= 2;
+ std::string result;
+ if (!readlink(path.c_str(), result)) {
+ jniThrowIOException(env, errno);
+ return NULL;
}
+ return env->NewStringUTF(result.c_str());
+}
+
+static jstring File_realpath(JNIEnv* env, jclass, jstring javaPath) {
+ ScopedUtfChars path(env, javaPath);
+ if (path.c_str() == NULL) {
+ return NULL;
+ }
+
+ extern bool realpath(const char* path, std::string& resolved);
+ std::string result;
+ if (!realpath(path.c_str(), result)) {
+ jniThrowIOException(env, errno);
+ return NULL;
+ }
+ return env->NewStringUTF(result.c_str());
}
static jboolean File_setLastModifiedImpl(JNIEnv* env, jclass, jstring javaPath, jlong ms) {
@@ -208,6 +200,7 @@ static jlong File_getFreeSpaceImpl(JNIEnv* env, jclass, jstring javaPath) {
if (!doStatFs(env, javaPath, sb)) {
return 0;
}
+ STATIC_ASSERT(sizeof(sb.f_bfree) == sizeof(jlong), statfs_not_64_bit);
return sb.f_bfree * sb.f_bsize; // free block count * block size in bytes.
}
@@ -216,6 +209,7 @@ static jlong File_getTotalSpaceImpl(JNIEnv* env, jclass, jstring javaPath) {
if (!doStatFs(env, javaPath, sb)) {
return 0;
}
+ STATIC_ASSERT(sizeof(sb.f_blocks) == sizeof(jlong), statfs_not_64_bit);
return sb.f_blocks * sb.f_bsize; // total block count * block size in bytes.
}
@@ -224,6 +218,7 @@ static jlong File_getUsableSpaceImpl(JNIEnv* env, jclass, jstring javaPath) {
if (!doStatFs(env, javaPath, sb)) {
return 0;
}
+ STATIC_ASSERT(sizeof(sb.f_bavail) == sizeof(jlong), statfs_not_64_bit);
return sb.f_bavail * sb.f_bsize; // non-root free block count * block size in bytes.
}
@@ -417,6 +412,22 @@ static jboolean File_renameToImpl(JNIEnv* env, jclass, jstring javaOldPath, jstr
return (rename(oldPath.c_str(), newPath.c_str()) == 0);
}
+static void File_symlink(JNIEnv* env, jclass, jstring javaOldPath, jstring javaNewPath) {
+ ScopedUtfChars oldPath(env, javaOldPath);
+ if (oldPath.c_str() == NULL) {
+ return;
+ }
+
+ ScopedUtfChars newPath(env, javaNewPath);
+ if (newPath.c_str() == NULL) {
+ return;
+ }
+
+ if (symlink(oldPath.c_str(), newPath.c_str()) == -1) {
+ jniThrowIOException(env, errno);
+ }
+}
+
static JNINativeMethod gMethods[] = {
NATIVE_METHOD(File, canExecuteImpl, "(Ljava/lang/String;)Z"),
NATIVE_METHOD(File, canReadImpl, "(Ljava/lang/String;)Z"),
@@ -434,11 +445,13 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(File, listImpl, "(Ljava/lang/String;)[Ljava/lang/String;"),
NATIVE_METHOD(File, mkdirImpl, "(Ljava/lang/String;)Z"),
NATIVE_METHOD(File, readlink, "(Ljava/lang/String;)Ljava/lang/String;"),
+ NATIVE_METHOD(File, realpath, "(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(File, renameToImpl, "(Ljava/lang/String;Ljava/lang/String;)Z"),
NATIVE_METHOD(File, setExecutableImpl, "(Ljava/lang/String;ZZ)Z"),
NATIVE_METHOD(File, setLastModifiedImpl, "(Ljava/lang/String;J)Z"),
NATIVE_METHOD(File, setReadableImpl, "(Ljava/lang/String;ZZ)Z"),
NATIVE_METHOD(File, setWritableImpl, "(Ljava/lang/String;ZZ)Z"),
+ NATIVE_METHOD(File, symlink, "(Ljava/lang/String;Ljava/lang/String;)V"),
};
int register_java_io_File(JNIEnv* env) {
return jniRegisterNativeMethods(env, "java/io/File", gMethods, NELEM(gMethods));
diff --git a/luni/src/main/native/java_io_ObjectInputStream.cpp b/luni/src/main/native/java_io_ObjectInputStream.cpp
deleted file mode 100644
index 1dd2f89..0000000
--- a/luni/src/main/native/java_io_ObjectInputStream.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "ObjectInputStream"
-
-#include "JNIHelp.h"
-#include "JniConstants.h"
-#include "ScopedUtfChars.h"
-
-#define SETTER(FUNCTION_NAME, JNI_C_TYPE, JNI_TYPE_STRING, JNI_SETTER_FUNCTION) \
- static void FUNCTION_NAME(JNIEnv* env, jclass, jobject instance, \
- jclass declaringClass, jstring javaFieldName, JNI_C_TYPE newValue) { \
- if (instance == NULL) { \
- return; \
- } \
- ScopedUtfChars fieldName(env, javaFieldName); \
- if (fieldName.c_str() == NULL) { \
- return; \
- } \
- jfieldID fid = env->GetFieldID(declaringClass, fieldName.c_str(), JNI_TYPE_STRING); \
- if (fid != 0) { \
- env->JNI_SETTER_FUNCTION(instance, fid, newValue); \
- } \
- }
-
-SETTER(ObjectInputStream_setFieldBool, jboolean, "Z", SetBooleanField)
-SETTER(ObjectInputStream_setFieldByte, jbyte, "B", SetByteField)
-SETTER(ObjectInputStream_setFieldChar, jchar, "C", SetCharField)
-SETTER(ObjectInputStream_setFieldDouble, jdouble, "D", SetDoubleField)
-SETTER(ObjectInputStream_setFieldFloat, jfloat, "F", SetFloatField)
-SETTER(ObjectInputStream_setFieldInt, jint, "I", SetIntField)
-SETTER(ObjectInputStream_setFieldLong, jlong, "J", SetLongField)
-SETTER(ObjectInputStream_setFieldShort, jshort, "S", SetShortField)
-
-static void ObjectInputStream_setFieldObject(JNIEnv* env, jclass, jobject instance,
- jclass declaringClass, jstring javaFieldName, jstring javaFieldTypeName, jobject newValue) {
- if (instance == NULL) {
- return;
- }
- ScopedUtfChars fieldName(env, javaFieldName);
- if (fieldName.c_str() == NULL) {
- return;
- }
- ScopedUtfChars fieldTypeName(env, javaFieldTypeName);
- if (fieldTypeName.c_str() == NULL) {
- return;
- }
- jfieldID fid = env->GetFieldID(declaringClass, fieldName.c_str(), fieldTypeName.c_str());
- if (fid != 0) {
- env->SetObjectField(instance, fid, newValue);
- }
-}
-
-static jobject ObjectInputStream_newInstance(JNIEnv* env, jclass,
- jclass instantiationClass, jclass constructorClass) {
- jmethodID mid = env->GetMethodID(constructorClass, "<init>", "()V");
- if (mid == 0) {
- return NULL;
- }
- return env->NewObject(instantiationClass, mid);
-}
-
-static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(ObjectInputStream, newInstance, "(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;"),
- NATIVE_METHOD(ObjectInputStream, setFieldObject, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Object;)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldByte, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;B)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldChar, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;C)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldDouble, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;D)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldFloat, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;F)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldInt, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;I)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldLong, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;J)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldShort, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;S)V"),
- NATIVE_METHOD(ObjectInputStream, setFieldBool, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Z)V"),
-};
-int register_java_io_ObjectInputStream(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "java/io/ObjectInputStream", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_io_ObjectOutputStream.cpp b/luni/src/main/native/java_io_ObjectOutputStream.cpp
deleted file mode 100644
index e99f9b2..0000000
--- a/luni/src/main/native/java_io_ObjectOutputStream.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "ObjectOutputStream"
-
-#include "JNIHelp.h"
-#include "JniConstants.h"
-#include "ScopedUtfChars.h"
-
-#define GETTER(FUNCTION_NAME, JNI_C_TYPE, JNI_TYPE_STRING, JNI_GETTER_FUNCTION) \
- static JNI_C_TYPE FUNCTION_NAME(JNIEnv* env, jclass, jobject instance, jclass declaringClass, \
- jstring javaFieldName) { \
- if (instance == NULL) { \
- return JNI_C_TYPE(); \
- } \
- ScopedUtfChars fieldName(env, javaFieldName); \
- if (fieldName.c_str() == NULL) { \
- return JNI_C_TYPE(); \
- } \
- jfieldID fid = env->GetFieldID(declaringClass, fieldName.c_str(), JNI_TYPE_STRING); \
- if (fid == 0) { \
- return JNI_C_TYPE(); \
- } \
- return env->JNI_GETTER_FUNCTION(instance, fid); \
- }
-
-GETTER(ObjectOutputStream_getFieldBool, jboolean, "Z", GetBooleanField)
-GETTER(ObjectOutputStream_getFieldByte, jbyte, "B", GetByteField)
-GETTER(ObjectOutputStream_getFieldChar, jchar, "C", GetCharField)
-GETTER(ObjectOutputStream_getFieldDouble, jdouble, "D", GetDoubleField)
-GETTER(ObjectOutputStream_getFieldFloat, jfloat, "F", GetFloatField)
-GETTER(ObjectOutputStream_getFieldInt, jint, "I", GetIntField)
-GETTER(ObjectOutputStream_getFieldLong, jlong, "J", GetLongField)
-GETTER(ObjectOutputStream_getFieldShort, jshort, "S", GetShortField)
-
-static jobject ObjectOutputStream_getFieldObj(JNIEnv* env, jclass, jobject instance,
- jclass declaringClass, jstring javaFieldName, jstring javaFieldTypeName) {
- ScopedUtfChars fieldName(env, javaFieldName);
- if (fieldName.c_str() == NULL) {
- return NULL;
- }
- ScopedUtfChars fieldTypeName(env, javaFieldTypeName);
- if (fieldTypeName.c_str() == NULL) {
- return NULL;
- }
- jfieldID fid = env->GetFieldID(declaringClass, fieldName.c_str(), fieldTypeName.c_str());
- if (fid == 0) {
- return NULL;
- }
- return env->GetObjectField(instance, fid);
-}
-
-static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(ObjectOutputStream, getFieldBool, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)Z"),
- NATIVE_METHOD(ObjectOutputStream, getFieldByte, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)B"),
- NATIVE_METHOD(ObjectOutputStream, getFieldChar, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)C"),
- NATIVE_METHOD(ObjectOutputStream, getFieldDouble, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)D"),
- NATIVE_METHOD(ObjectOutputStream, getFieldFloat, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)F"),
- NATIVE_METHOD(ObjectOutputStream, getFieldInt, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)I"),
- NATIVE_METHOD(ObjectOutputStream, getFieldLong, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)J"),
- NATIVE_METHOD(ObjectOutputStream, getFieldObj, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"),
- NATIVE_METHOD(ObjectOutputStream, getFieldShort, "(Ljava/lang/Object;Ljava/lang/Class;Ljava/lang/String;)S"),
-};
-int register_java_io_ObjectOutputStream(JNIEnv* env) {
- return jniRegisterNativeMethods(env, "java/io/ObjectOutputStream", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/java_io_ObjectStreamClass.cpp b/luni/src/main/native/java_io_ObjectStreamClass.cpp
index c131d4f..721136e 100644
--- a/luni/src/main/native/java_io_ObjectStreamClass.cpp
+++ b/luni/src/main/native/java_io_ObjectStreamClass.cpp
@@ -47,11 +47,21 @@ static jboolean ObjectStreamClass_hasClinit(JNIEnv * env, jclass, jclass targetC
return (mid != 0);
}
+static jint ObjectStreamClass_getConstructorId(JNIEnv* env, jclass, jclass constructorClass) {
+ return reinterpret_cast<jint>(env->GetMethodID(constructorClass, "<init>", "()V"));
+}
+
+static jobject ObjectStreamClass_newInstance(JNIEnv* env, jclass, jclass instantiationClass, jint methodId) {
+ return env->NewObject(instantiationClass, reinterpret_cast<jmethodID>(methodId));
+}
+
static JNINativeMethod gMethods[] = {
+ NATIVE_METHOD(ObjectStreamClass, getConstructorId, "(Ljava/lang/Class;)I"),
NATIVE_METHOD(ObjectStreamClass, getConstructorSignature, "(Ljava/lang/reflect/Constructor;)Ljava/lang/String;"),
NATIVE_METHOD(ObjectStreamClass, getFieldSignature, "(Ljava/lang/reflect/Field;)Ljava/lang/String;"),
NATIVE_METHOD(ObjectStreamClass, getMethodSignature, "(Ljava/lang/reflect/Method;)Ljava/lang/String;"),
NATIVE_METHOD(ObjectStreamClass, hasClinit, "(Ljava/lang/Class;)Z"),
+ NATIVE_METHOD(ObjectStreamClass, newInstance, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
};
int register_java_io_ObjectStreamClass(JNIEnv* env) {
return jniRegisterNativeMethods(env, "java/io/ObjectStreamClass", gMethods, NELEM(gMethods));
diff --git a/luni/src/main/native/java_lang_Character.cpp b/luni/src/main/native/java_lang_Character.cpp
index d433269..66860e8 100644
--- a/luni/src/main/native/java_lang_Character.cpp
+++ b/luni/src/main/native/java_lang_Character.cpp
@@ -39,36 +39,14 @@ static jboolean Character_isMirroredImpl(JNIEnv*, jclass, jint codePoint) {
return u_isMirrored(codePoint);
}
-static jint Character_getNumericValueImpl(JNIEnv*, jclass, jint codePoint){
- // The letters A-Z in their uppercase ('\u0041' through '\u005A'),
- // lowercase ('\u0061' through '\u007A'),
- // and full width variant ('\uFF21' through '\uFF3A'
- // and '\uFF41' through '\uFF5A') forms
- // have numeric values from 10 through 35. This is independent of the
- // Unicode specification, which does not assign numeric values to these
- // char values.
- if (codePoint >= 0x41 && codePoint <= 0x5A) {
- return codePoint - 0x37;
- }
- if (codePoint >= 0x61 && codePoint <= 0x7A) {
- return codePoint - 0x57;
- }
- if (codePoint >= 0xFF21 && codePoint <= 0xFF3A) {
- return codePoint - 0xFF17;
- }
- if (codePoint >= 0xFF41 && codePoint <= 0xFF5A) {
- return codePoint - 0xFF37;
- }
-
+static jint Character_getNumericValueImpl(JNIEnv*, jclass, jint codePoint) {
double result = u_getNumericValue(codePoint);
-
if (result == U_NO_NUMERIC_VALUE) {
return -1;
} else if (result < 0 || floor(result + 0.5) != result) {
return -2;
}
-
- return result;
+ return static_cast<jint>(result);
}
static jboolean Character_isDefinedImpl(JNIEnv*, jclass, jint codePoint) {
@@ -80,10 +58,6 @@ static jboolean Character_isDigitImpl(JNIEnv*, jclass, jint codePoint) {
}
static jboolean Character_isIdentifierIgnorableImpl(JNIEnv*, jclass, jint codePoint) {
- // Java also returns true for U+0085 Next Line (it omits U+0085 from whitespace ISO controls).
- if(codePoint == 0x0085) {
- return JNI_TRUE;
- }
return u_isIDIgnorable(codePoint);
}
@@ -112,10 +86,6 @@ static jboolean Character_isUnicodeIdentifierStartImpl(JNIEnv*, jclass, jint cod
}
static jboolean Character_isWhitespaceImpl(JNIEnv*, jclass, jint codePoint) {
- // Java omits U+0085
- if(codePoint == 0x0085) {
- return JNI_FALSE;
- }
return u_isWhitespace(codePoint);
}
diff --git a/luni/src/main/native/java_lang_Double.cpp b/luni/src/main/native/java_lang_Double.cpp
index 259be30..f8b6be8 100644
--- a/luni/src/main/native/java_lang_Double.cpp
+++ b/luni/src/main/native/java_lang_Double.cpp
@@ -18,36 +18,25 @@
#include "JNIHelp.h"
#include "JniConstants.h"
+#include "java_lang_Double.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
-#include <stdint.h>
-
-union Double {
- uint64_t bits;
- double d;
-};
static const jlong NaN = 0x7ff8000000000000ULL;
-static jlong Double_doubleToLongBits(JNIEnv*, jclass, jdouble val) {
- Double d;
- d.d = val;
+static jlong Double_doubleToLongBits(JNIEnv*, jclass, jdouble doubleValue) {
// For this method all values in the NaN range are normalized to the canonical NaN value.
- return isnan(d.d) ? NaN : d.bits;
+ return isnan(doubleValue) ? NaN : Double::doubleToRawLongBits(doubleValue);
}
-static jlong Double_doubleToRawLongBits(JNIEnv*, jclass, jdouble val) {
- Double d;
- d.d = val;
- return d.bits;
+static jlong Double_doubleToRawLongBits(JNIEnv*, jclass, jdouble doubleValue) {
+ return Double::doubleToRawLongBits(doubleValue);
}
-static jdouble Double_longBitsToDouble(JNIEnv*, jclass, jlong val) {
- Double d;
- d.bits = val;
- return d.d;
+static jdouble Double_longBitsToDouble(JNIEnv*, jclass, jlong bits) {
+ return Double::longBitsToDouble(bits);
}
static JNINativeMethod gMethods[] = {
diff --git a/luni/src/main/native/java_lang_Double.h b/luni/src/main/native/java_lang_Double.h
new file mode 100644
index 0000000..2f63c0d
--- /dev/null
+++ b/luni/src/main/native/java_lang_Double.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef JAVA_LANG_DOUBLE_H_included
+#define JAVA_LANG_DOUBLE_H_included
+
+#include <stdint.h>
+
+union Double {
+public:
+ static inline double longBitsToDouble(uint64_t bits) {
+ Double result;
+ result.bits = bits;
+ return result.doubleValue;
+ }
+
+ static inline uint64_t doubleToRawLongBits(double doubleValue) {
+ Double result;
+ result.doubleValue = doubleValue;
+ return result.bits;
+ }
+
+private:
+ uint64_t bits;
+ double doubleValue;
+};
+
+#endif // JAVA_LANG_DOUBLE_H_included
diff --git a/luni/src/main/native/java_lang_Float.cpp b/luni/src/main/native/java_lang_Float.cpp
index 59544db..93384df 100644
--- a/luni/src/main/native/java_lang_Float.cpp
+++ b/luni/src/main/native/java_lang_Float.cpp
@@ -18,35 +18,25 @@
#include "JNIHelp.h"
#include "JniConstants.h"
+#include "java_lang_Float.h"
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
-union Float {
- unsigned int bits;
- float f;
-};
-
static const jint NaN = 0x7fc00000;
-static jint Float_floatToIntBits(JNIEnv*, jclass, jfloat val) {
- Float f;
- f.f = val;
+static jint Float_floatToIntBits(JNIEnv*, jclass, jfloat floatValue) {
// For this method all values in the NaN range are normalized to the canonical NaN value.
- return isnanf(f.f) ? NaN : f.bits;
+ return isnanf(floatValue) ? NaN : Float::floatToRawIntBits(floatValue);
}
-jint Float_floatToRawIntBits(JNIEnv*, jclass, jfloat val) {
- Float f;
- f.f = val;
- return f.bits;
+static jint Float_floatToRawIntBits(JNIEnv*, jclass, jfloat floatValue) {
+ return Float::floatToRawIntBits(floatValue);
}
-jfloat Float_intBitsToFloat(JNIEnv*, jclass, jint val) {
- Float f;
- f.bits = val;
- return f.f;
+static jfloat Float_intBitsToFloat(JNIEnv*, jclass, jint bits) {
+ return Float::intBitsToFloat(bits);
}
static JNINativeMethod gMethods[] = {
diff --git a/luni/src/main/native/java_lang_Float.h b/luni/src/main/native/java_lang_Float.h
new file mode 100644
index 0000000..e60d953
--- /dev/null
+++ b/luni/src/main/native/java_lang_Float.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef JAVA_LANG_FLOAT_H_included
+#define JAVA_LANG_FLOAT_H_included
+
+#include <stdint.h>
+
+union Float {
+public:
+ static inline float intBitsToFloat(uint32_t bits) {
+ Float result;
+ result.bits = bits;
+ return result.floatValue;
+ }
+
+ static inline uint32_t floatToRawIntBits(float floatValue) {
+ Float result;
+ result.floatValue = floatValue;
+ return result.bits;
+ }
+
+private:
+ uint32_t bits;
+ float floatValue;
+};
+
+#endif // JAVA_LANG_FLOAT_H_included
diff --git a/luni/src/main/native/java_lang_StrictMath.cpp b/luni/src/main/native/java_lang_StrictMath.cpp
index bce7a48..24c15b0 100644
--- a/luni/src/main/native/java_lang_StrictMath.cpp
+++ b/luni/src/main/native/java_lang_StrictMath.cpp
@@ -21,6 +21,7 @@
#include "jni.h"
#include "JNIHelp.h"
#include "JniConstants.h"
+#include "java_lang_Float.h"
static jdouble StrictMath_sin(JNIEnv*, jclass, jdouble a) {
return ieee_sin(a);
@@ -118,17 +119,14 @@ static jdouble StrictMath_nextafter(JNIEnv*, jclass, jdouble a, jdouble b) {
return ieee_nextafter(a, b);
}
-extern jint Float_floatToRawIntBits(JNIEnv*, jclass, jfloat);
-extern jfloat Float_intBitsToFloat(JNIEnv*, jclass, jint val);
-
// TODO: we should make Float.floatToRawBits and Float.intBitsToFloat intrinsics, and move
// this kind of code into Java.
static jfloat StrictMath_nextafterf(JNIEnv*, jclass, jfloat arg1, jfloat arg2) {
- jint hx = Float_floatToRawIntBits(NULL, NULL, arg1);
- jint hy = Float_floatToRawIntBits(NULL, NULL, arg2);
+ jint hx = Float::floatToRawIntBits(arg1);
+ jint hy = Float::floatToRawIntBits(arg2);
if (!(hx & 0x7fffffff)) { /* arg1 == 0 */
- return Float_intBitsToFloat(NULL, NULL, (hy & 0x80000000) | 0x1);
+ return Float::intBitsToFloat((hy & 0x80000000) | 0x1);
}
if ((hx > 0) ^ (hx > hy)) { /* |arg1| < |arg2| */
@@ -136,7 +134,7 @@ static jfloat StrictMath_nextafterf(JNIEnv*, jclass, jfloat arg1, jfloat arg2) {
} else {
hx -= 1;
}
- return Float_intBitsToFloat(NULL, NULL, hx);
+ return Float::intBitsToFloat(hx);
}
static JNINativeMethod gMethods[] = {
diff --git a/luni/src/main/native/java_net_InetAddress.cpp b/luni/src/main/native/java_net_InetAddress.cpp
index 8c81075..7681463 100644
--- a/luni/src/main/native/java_net_InetAddress.cpp
+++ b/luni/src/main/native/java_net_InetAddress.cpp
@@ -145,9 +145,12 @@ static jobjectArray InetAddress_getaddrinfo(JNIEnv* env, jclass, jstring javaNam
} else if (result == EAI_SYSTEM && errno == EACCES) {
/* No permission to use network */
jniThrowException(env, "java/lang/SecurityException",
- "Permission denied (maybe missing INTERNET permission)");
+ "Permission denied (maybe missing INTERNET permission)");
} else {
- jniThrowException(env, "java/net/UnknownHostException", gai_strerror(result));
+ char buf[256];
+ snprintf(buf, sizeof(buf), "Unable to resolve host \"%s\": %s",
+ name.c_str(), gai_strerror(result));
+ jniThrowException(env, "java/net/UnknownHostException", buf);
}
if (addressList) {
@@ -209,25 +212,6 @@ static jstring InetAddress_getnameinfo(JNIEnv* env, jclass,
return env->NewStringUTF(name);
}
-/**
- * Convert a Java string representing an IP address to a Java byte array.
- * The formats accepted are:
- * - IPv4:
- * - 1.2.3.4
- * - 1.2.4
- * - 1.4
- * - 4
- * - IPv6
- * - Compressed form (2001:db8::1)
- * - Uncompressed form (2001:db8:0:0:0:0:0:1)
- * - IPv4-compatible (::192.0.2.0)
- * - With an embedded IPv4 address (2001:db8::192.0.2.0).
- * IPv6 addresses may appear in square brackets.
- *
- * @param addressByteArray the byte array to convert.
- * @return a string with the textual representation of the address.
- * @throws UnknownHostException the IP address was invalid.
- */
static jbyteArray InetAddress_ipStringToByteArray(JNIEnv* env, jobject, jstring javaString) {
// Convert the String to UTF-8 bytes.
ScopedUtfChars chars(env, javaString);
@@ -287,7 +271,6 @@ static jbyteArray InetAddress_ipStringToByteArray(JNIEnv* env, jobject, jstring
if (!result) {
env->ExceptionClear();
- jniThrowException(env, "java/net/UnknownHostException", gai_strerror(ret));
}
return result;
diff --git a/luni/src/main/native/java_util_zip_Deflater.cpp b/luni/src/main/native/java_util_zip_Deflater.cpp
index c0b2fef..2f27f5c 100644
--- a/luni/src/main/native/java_util_zip_Deflater.cpp
+++ b/luni/src/main/native/java_util_zip_Deflater.cpp
@@ -21,11 +21,6 @@
#include "ScopedPrimitiveArray.h"
#include "zip.h"
-static struct {
- jfieldID inRead;
- jfieldID finished;
-} gCachedFields;
-
static void Deflater_setDictionaryImpl(JNIEnv* env, jobject, jbyteArray dict, int off, int len, jlong handle) {
toNativeZipStream(handle)->setDictionary(env, dict, off, len, false);
}
@@ -42,7 +37,6 @@ static jint Deflater_getAdlerImpl(JNIEnv*, jobject, jlong handle) {
return toNativeZipStream(handle)->stream.adler;
}
-/* Create a new stream . This stream cannot be used until it has been properly initialized. */
static jlong Deflater_createStream(JNIEnv * env, jobject, jint level, jint strategy, jboolean noHeader) {
UniquePtr<NativeZipStream> jstream(new NativeZipStream);
if (jstream.get() == NULL) {
@@ -50,17 +44,19 @@ static jlong Deflater_createStream(JNIEnv * env, jobject, jint level, jint strat
return -1;
}
- int wbits = 12; // Was 15, made it 12 to reduce memory consumption. Use MAX for fastest.
- int mlevel = 5; // Was 9, made it 5 to reduce memory consumption. Might result
- // in out-of-memory problems according to some web pages. The
- // ZLIB docs are a bit vague, unfortunately. The default
- // results in 2 x 128K being allocated per Deflater, which is
- // not acceptable.
- /*Unable to find official doc that this is the way to avoid zlib header use. However doc in zipsup.c claims it is so */
- if (noHeader) {
- wbits = wbits / -1;
- }
- int err = deflateInit2(&jstream->stream, level, Z_DEFLATED, wbits, mlevel, strategy);
+ /*
+ * See zlib.h for documentation of the deflateInit2 windowBits and memLevel parameters.
+ *
+ * zconf.h says the "requirements for deflate are (in bytes):
+ * (1 << (windowBits+2)) + (1 << (memLevel+9))
+ * that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ * plus a few kilobytes for small objects."
+ */
+ // TODO: should we just use DEF_WBITS (15) and DEF_MEM_LEVEL (8) now?
+ int windowBits = noHeader ? -12 : 12; // Was 15, made it 12 to reduce memory consumption. Use MAX_WBITS for fastest.
+ int memLevel = 5; // Was 9 (MAX_MEM_LEVEL), made it 5 to reduce memory consumption. Might result
+ // in out-of-memory problems according to some web pages.
+ int err = deflateInit2(&jstream->stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
if (err != Z_OK) {
throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
return -1;
@@ -72,35 +68,44 @@ static void Deflater_setInputImpl(JNIEnv* env, jobject, jbyteArray buf, jint off
toNativeZipStream(handle)->setInput(env, buf, off, len);
}
-static jint Deflater_deflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int off, int len, jlong handle, int flushParm) {
- /* We need to get the number of bytes already read */
- jint inBytes = env->GetIntField(recv, gCachedFields.inRead);
-
+static jint Deflater_deflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int off, int len, jlong handle, int flushStyle) {
NativeZipStream* stream = toNativeZipStream(handle);
- stream->stream.avail_out = len;
- jint sin = stream->stream.total_in;
- jint sout = stream->stream.total_out;
ScopedByteArrayRW out(env, buf);
if (out.get() == NULL) {
return -1;
}
stream->stream.next_out = reinterpret_cast<Bytef*>(out.get() + off);
- int err = deflate(&stream->stream, flushParm);
- if (err != Z_OK) {
- if (err == Z_MEM_ERROR) {
- jniThrowOutOfMemoryError(env, NULL);
- return 0;
- }
- if (err == Z_STREAM_END) {
- env->SetBooleanField(recv, gCachedFields.finished, JNI_TRUE);
- return stream->stream.total_out - sout;
- }
- }
- if (flushParm != Z_FINISH) {
- /* Need to update the number of input bytes read. */
- env->SetIntField(recv, gCachedFields.inRead, (jint) stream->stream.total_in - sin + inBytes);
+ stream->stream.avail_out = len;
+
+ Bytef* initialNextIn = stream->stream.next_in;
+ Bytef* initialNextOut = stream->stream.next_out;
+
+ int err = deflate(&stream->stream, flushStyle);
+ switch (err) {
+ case Z_OK:
+ break;
+ case Z_STREAM_END:
+ static jfieldID finished = env->GetFieldID(JniConstants::deflaterClass, "finished", "Z");
+ env->SetBooleanField(recv, finished, JNI_TRUE);
+ break;
+ case Z_BUF_ERROR:
+ // zlib reports this "if no progress is possible (for example avail_in or avail_out was
+ // zero) ... Z_BUF_ERROR is not fatal, and deflate() can be called again with more
+ // input and more output space to continue compressing".
+ break;
+ default:
+ throwExceptionForZlibError(env, "java/util/zip/DataFormatException", err);
+ return -1;
}
- return stream->stream.total_out - sout;
+
+ jint bytesRead = stream->stream.next_in - initialNextIn;
+ jint bytesWritten = stream->stream.next_out - initialNextOut;
+
+ static jfieldID inReadField = env->GetFieldID(JniConstants::deflaterClass, "inRead", "I");
+ jint inReadValue = env->GetIntField(recv, inReadField);
+ inReadValue += bytesRead;
+ env->SetIntField(recv, inReadField, inReadValue);
+ return bytesWritten;
}
static void Deflater_endImpl(JNIEnv*, jobject, jlong handle) {
@@ -118,13 +123,13 @@ static void Deflater_resetImpl(JNIEnv* env, jobject, jlong handle) {
}
static void Deflater_setLevelsImpl(JNIEnv* env, jobject, int level, int strategy, jlong handle) {
- if (handle == -1) {
- jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return;
- }
NativeZipStream* stream = toNativeZipStream(handle);
- jbyte b = 0;
- stream->stream.next_out = reinterpret_cast<Bytef*>(&b);
+ // The deflateParams documentation says that avail_out must never be 0 because it may be
+ // necessary to flush, but the Java API ensures that we only get here if there's nothing
+ // to flush. To be on the safe side, make sure that we're not pointing to a no longer valid
+ // buffer.
+ stream->stream.next_out = reinterpret_cast<Bytef*>(NULL);
+ stream->stream.avail_out = 0;
int err = deflateParams(&stream->stream, level, strategy);
if (err != Z_OK) {
throwExceptionForZlibError(env, "java/lang/IllegalStateException", err);
@@ -144,7 +149,5 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Deflater, setLevelsImpl, "(IIJ)V"),
};
int register_java_util_zip_Deflater(JNIEnv* env) {
- gCachedFields.finished = env->GetFieldID(JniConstants::deflaterClass, "finished", "Z");
- gCachedFields.inRead = env->GetFieldID(JniConstants::deflaterClass, "inRead", "I");
return jniRegisterNativeMethods(env, "java/util/zip/Deflater", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/java_util_zip_Inflater.cpp b/luni/src/main/native/java_util_zip_Inflater.cpp
index aa53240..192d1b5 100644
--- a/luni/src/main/native/java_util_zip_Inflater.cpp
+++ b/luni/src/main/native/java_util_zip_Inflater.cpp
@@ -22,13 +22,6 @@
#include "zip.h"
#include <errno.h>
-static struct {
- jfieldID inRead;
- jfieldID finished;
- jfieldID needsDictionary;
-} gCachedFields;
-
-/* Create a new stream . This stream cannot be used until it has been properly initialized. */
static jlong Inflater_createStream(JNIEnv* env, jobject, jboolean noHeader) {
UniquePtr<NativeZipStream> jstream(new NativeZipStream);
if (jstream.get() == NULL) {
@@ -38,15 +31,14 @@ static jlong Inflater_createStream(JNIEnv* env, jobject, jboolean noHeader) {
jstream->stream.adler = 1;
/*
- * In the range 8..15 for checked, or -8..-15 for unchecked inflate. Unchecked
- * is appropriate for formats like zip that do their own validity checking.
+ * See zlib.h for documentation of the inflateInit2 windowBits parameter.
+ *
+ * zconf.h says the "requirements for inflate are (in bytes) 1 << windowBits
+ * that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ * for small objects." This means that we can happily use the default
+ * here without worrying about memory consumption.
*/
- /* Window bits to use. 15 is fastest but consumes the most memory */
- int wbits = 15; /*Use MAX for fastest */
- if (noHeader) {
- wbits = wbits / -1;
- }
- int err = inflateInit2(&jstream->stream, wbits);
+ int err = inflateInit2(&jstream->stream, noHeader ? -DEF_WBITS : DEF_WBITS);
if (err != Z_OK) {
throwExceptionForZlibError(env, "java/lang/IllegalArgumentException", err);
return -1;
@@ -107,26 +99,31 @@ static jint Inflater_inflateImpl(JNIEnv* env, jobject recv, jbyteArray buf, int
Bytef* initialNextOut = stream->stream.next_out;
int err = inflate(&stream->stream, Z_SYNC_FLUSH);
- if (err != Z_OK) {
- if (err == Z_STREAM_ERROR) {
- return 0;
- }
- if (err == Z_STREAM_END) {
- env->SetBooleanField(recv, gCachedFields.finished, JNI_TRUE);
- } else if (err == Z_NEED_DICT) {
- env->SetBooleanField(recv, gCachedFields.needsDictionary, JNI_TRUE);
- } else {
- throwExceptionForZlibError(env, "java/util/zip/DataFormatException", err);
- return -1;
- }
+ switch (err) {
+ case Z_OK:
+ break;
+ case Z_NEED_DICT:
+ static jfieldID needsDictionary = env->GetFieldID(JniConstants::inflaterClass, "needsDictionary", "Z");
+ env->SetBooleanField(recv, needsDictionary, JNI_TRUE);
+ break;
+ case Z_STREAM_END:
+ static jfieldID finished = env->GetFieldID(JniConstants::inflaterClass, "finished", "Z");
+ env->SetBooleanField(recv, finished, JNI_TRUE);
+ break;
+ case Z_STREAM_ERROR:
+ return 0;
+ default:
+ throwExceptionForZlibError(env, "java/util/zip/DataFormatException", err);
+ return -1;
}
jint bytesRead = stream->stream.next_in - initialNextIn;
jint bytesWritten = stream->stream.next_out - initialNextOut;
- jint inReadValue = env->GetIntField(recv, gCachedFields.inRead);
+ static jfieldID inReadField = env->GetFieldID(JniConstants::inflaterClass, "inRead", "I");
+ jint inReadValue = env->GetIntField(recv, inReadField);
inReadValue += bytesRead;
- env->SetIntField(recv, gCachedFields.inRead, inReadValue);
+ env->SetIntField(recv, inReadField, inReadValue);
return bytesWritten;
}
@@ -172,8 +169,5 @@ static JNINativeMethod gMethods[] = {
NATIVE_METHOD(Inflater, setInputImpl, "([BIIJ)V"),
};
int register_java_util_zip_Inflater(JNIEnv* env) {
- gCachedFields.finished = env->GetFieldID(JniConstants::inflaterClass, "finished", "Z");
- gCachedFields.inRead = env->GetFieldID(JniConstants::inflaterClass, "inRead", "I");
- gCachedFields.needsDictionary = env->GetFieldID(JniConstants::inflaterClass, "needsDictionary", "Z");
return jniRegisterNativeMethods(env, "java/util/zip/Inflater", gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/libcore_io_IoUtils.cpp b/luni/src/main/native/libcore_io_IoUtils.cpp
index 289b28c..b7d312b 100644
--- a/luni/src/main/native/libcore_io_IoUtils.cpp
+++ b/luni/src/main/native/libcore_io_IoUtils.cpp
@@ -25,12 +25,15 @@
#include <unistd.h>
static void IoUtils_close(JNIEnv* env, jclass, jobject fileDescriptor) {
+ // Get the FileDescriptor's 'fd' field and clear it.
+ // We need to do this before we can throw an IOException (http://b/3222087).
int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
+ jniSetFileDescriptorOfFD(env, fileDescriptor, -1);
+
jint rc = TEMP_FAILURE_RETRY(close(fd));
if (rc == -1) {
jniThrowIOException(env, errno);
}
- jniSetFileDescriptorOfFD(env, fileDescriptor, -1);
}
static jint IoUtils_getFd(JNIEnv* env, jclass, jobject fileDescriptor) {
diff --git a/luni/src/main/native/libcore_net_RawSocket.cpp b/luni/src/main/native/libcore_net_RawSocket.cpp
new file mode 100644
index 0000000..7878986
--- /dev/null
+++ b/luni/src/main/native/libcore_net_RawSocket.cpp
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "AsynchronousSocketCloseMonitor.h"
+#include "JNIHelp.h"
+#include "JniException.h"
+#include "JniConstants.h"
+#include "NetFd.h"
+#include "NetworkUtilities.h"
+#include "ScopedUtfChars.h"
+#include "ScopedPrimitiveArray.h"
+
+#include "jni.h"
+#include <utils/misc.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/rtnetlink.h>
+#include <net/if.h>
+#include <linux/if_ether.h>
+#include <linux/if_packet.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <netinet/ip.h>
+#include <linux/udp.h>
+
+/*
+ * Creates a socket suitable for raw socket operations. The socket is
+ * bound to the interface specified by the supplied name. The socket
+ * value is placed into the supplied FileDescriptor instance.
+ *
+ * TODO(chesnutt): consider breaking this into pieces: create a
+ * variety of constructors for different socket types, then a generic
+ * setBlocking() method followed by polymorphic bind().
+ */
+static void RawSocket_create(JNIEnv* env, jclass, jobject fileDescriptor,
+ jstring interfaceName) {
+
+ union sockunion {
+ struct sockaddr sa;
+ struct sockaddr_ll sll;
+ } su;
+
+ short protocol = ETH_P_IP;
+ ScopedUtfChars ifname(env, interfaceName);
+
+ if (ifname.c_str() == NULL) {
+ return;
+ }
+
+ memset(&su, 0, sizeof(su));
+ su.sll.sll_family = PF_PACKET;
+ su.sll.sll_protocol = htons(protocol);
+ su.sll.sll_ifindex = if_nametoindex(ifname.c_str());
+ int sock = socket(PF_PACKET, SOCK_DGRAM, htons(protocol));
+
+ if (sock == -1) {
+ LOGE("Can't create socket %s", strerror(errno));
+ jniThrowSocketException(env, errno);
+ return;
+ }
+
+ jniSetFileDescriptorOfFD(env, fileDescriptor, sock);
+
+ if (!setBlocking(sock, false)) {
+ LOGE("Can't set non-blocking mode on socket %s", strerror(errno));
+ jniThrowSocketException(env, errno);
+ return;
+ }
+
+ int err = bind(sock, &su.sa, sizeof(su));
+
+ if (err != 0) {
+ LOGE("Socket bind error %s", strerror(errno));
+ jniThrowSocketException(env, errno);
+ return;
+ }
+}
+
+/*
+ * Writes the L3 (IP) packet to the raw socket supplied in the
+ * FileDescriptor instance.
+ *
+ * Assumes that the caller has validated the offset & byteCount values.
+ */
+static int RawSocket_sendPacket(JNIEnv* env, jclass, jobject fileDescriptor,
+ jstring interfaceName, jbyteArray destMac, jbyteArray packet, jint offset,
+ jint byteCount)
+{
+ NetFd fd(env, fileDescriptor);
+
+ if (fd.isClosed()) {
+ return 0;
+ }
+
+ union sockunion {
+ struct sockaddr sa;
+ struct sockaddr_ll sll;
+ } su;
+ short protocol = ETH_P_IP;
+ ScopedUtfChars ifname(env, interfaceName);
+
+ if (ifname.c_str() == NULL) {
+ return 0;
+ }
+
+ ScopedByteArrayRO byteArray(env, packet);
+
+ if (byteArray.get() == NULL) {
+ return 0;
+ }
+
+ ScopedByteArrayRO mac(env, destMac);
+
+ if (mac.get() == NULL) {
+ return 0;
+ }
+
+ memset(&su, 0, sizeof(su));
+ su.sll.sll_hatype = htons(1); // ARPHRD_ETHER
+ su.sll.sll_halen = mac.size();
+ memcpy(&su.sll.sll_addr, mac.get(), mac.size());
+ su.sll.sll_family = AF_PACKET;
+ su.sll.sll_protocol = htons(protocol);
+ su.sll.sll_ifindex = if_nametoindex(ifname.c_str());
+
+ int err;
+
+ {
+ int intFd = fd.get();
+ AsynchronousSocketCloseMonitor monitor(intFd);
+ err = NET_FAILURE_RETRY(fd, sendto(intFd, byteArray.get() + offset,
+ byteCount, 0, &su.sa, sizeof(su)));
+ }
+
+ return err;
+}
+
+/*
+ * Reads a network packet into the user-supplied buffer. Return the
+ * length of the packet, or a 0 if there was a timeout or an
+ * unacceptable packet was acquired.
+ *
+ * Assumes that the caller has validated the offset & byteCount values.
+ */
+static jint RawSocket_recvPacket(JNIEnv* env, jclass, jobject fileDescriptor,
+ jbyteArray packet, jint offset, jint byteCount, jint port,
+ jint timeout_millis)
+{
+ NetFd fd(env, fileDescriptor);
+
+ if (fd.isClosed()) {
+ return 0;
+ }
+
+ ScopedByteArrayRW body(env, packet);
+ jbyte* packetData = body.get();
+
+ if (packetData == NULL) {
+ return 0;
+ }
+
+ packetData += offset;
+
+ int packetSize = byteCount;
+ unsigned int size = 0;
+ struct pollfd fds[1];
+
+ fds[0].fd = fd.get();
+ fds[0].events = POLLIN;
+ int retval = poll(fds, 1, timeout_millis);
+
+ if (retval <= 0) {
+ return 0;
+ }
+
+ {
+ int intFd = fd.get();
+ AsynchronousSocketCloseMonitor monitor(intFd);
+ size = NET_FAILURE_RETRY(fd, read(intFd, packetData, packetSize));
+ }
+
+ if (env->ExceptionOccurred()) {
+ return 0;
+ }
+
+ // quick check for UDP type & UDP port
+ // the packet is an IP header, UDP header, and UDP payload
+ if ((size < (sizeof(struct iphdr) + sizeof(struct udphdr)))) {
+ return 0; // runt packet
+ }
+
+ u_int8_t ip_proto = ((struct iphdr *) packetData)->protocol;
+
+ if (ip_proto != IPPROTO_UDP) {
+ return 0; // something other than UDP
+ }
+
+ __be16 destPort =
+ htons((reinterpret_cast<struct udphdr*>
+ (packetData + sizeof(struct iphdr)))->dest);
+
+ if (destPort != port) {
+ return 0; // something other than requested port
+ }
+
+ return size;
+}
+
+/*
+ * JNI registration
+ */
+static JNINativeMethod gRawMethods[] = {
+ NATIVE_METHOD(RawSocket, create,
+ "(Ljava/io/FileDescriptor;Ljava/lang/String;)V"),
+ NATIVE_METHOD(RawSocket, sendPacket,
+ "(Ljava/io/FileDescriptor;Ljava/lang/String;[B[BII)I"),
+ NATIVE_METHOD(RawSocket, recvPacket,
+ "(Ljava/io/FileDescriptor;[BIIII)I"),
+};
+
+int register_libcore_net_RawSocket(JNIEnv* env) {
+ return jniRegisterNativeMethods(env,
+ "libcore/net/RawSocket", gRawMethods, NELEM(gRawMethods));
+}
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
index 6576155..4a9a6f0 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSFileSystem.cpp
@@ -32,12 +32,12 @@
#include "JNIHelp.h"
#include "JniConstants.h"
+#include "JniException.h"
#include "LocalArray.h"
#include "ScopedPrimitiveArray.h"
#include "ScopedUtfChars.h"
#include "UniquePtr.h"
-#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -104,30 +104,6 @@ static int EsTranslateOpenFlags(int flags) {
return -1;
}
-// Checks whether we can safely treat the given jlong as an off_t without
-// accidental loss of precision.
-// TODO: this is bogus; we should use _FILE_OFFSET_BITS=64.
-static bool offsetTooLarge(JNIEnv* env, jlong longOffset) {
- if (sizeof(off_t) >= sizeof(jlong)) {
- // We're only concerned about the possibility that off_t is
- // smaller than jlong. off_t is signed, so we don't need to
- // worry about signed/unsigned.
- return false;
- }
-
- // TODO: use std::numeric_limits<off_t>::max() and min() when we have them.
- assert(sizeof(off_t) == sizeof(int));
- static const off_t off_t_max = INT_MAX;
- static const off_t off_t_min = INT_MIN;
-
- if (longOffset > off_t_max || longOffset < off_t_min) {
- // "Value too large for defined data type".
- jniThrowIOException(env, EOVERFLOW);
- return true;
- }
- return false;
-}
-
static jlong translateLockLength(jlong length) {
// FileChannel.tryLock uses Long.MAX_VALUE to mean "lock the whole
// file", where POSIX would use 0. We can support that special case,
@@ -136,8 +112,8 @@ static jlong translateLockLength(jlong length) {
return (length == 0x7fffffffffffffffLL) ? 0 : length;
}
-static struct flock flockFromStartAndLength(jlong start, jlong length) {
- struct flock lock;
+static struct flock64 flockFromStartAndLength(jlong start, jlong length) {
+ struct flock64 lock;
memset(&lock, 0, sizeof(lock));
lock.l_whence = SEEK_SET;
@@ -147,15 +123,11 @@ static struct flock flockFromStartAndLength(jlong start, jlong length) {
return lock;
}
-static jint OSFileSystem_lockImpl(JNIEnv* env, jobject, jint fd,
+static jint OSFileSystem_lockImpl(JNIEnv*, jobject, jint fd,
jlong start, jlong length, jint typeFlag, jboolean waitFlag) {
length = translateLockLength(length);
- if (offsetTooLarge(env, start) || offsetTooLarge(env, length)) {
- return -1;
- }
-
- struct flock lock(flockFromStartAndLength(start, length));
+ struct flock64 lock(flockFromStartAndLength(start, length));
if ((typeFlag & SHARED_LOCK_TYPE) == SHARED_LOCK_TYPE) {
lock.l_type = F_RDLCK;
@@ -163,20 +135,16 @@ static jint OSFileSystem_lockImpl(JNIEnv* env, jobject, jint fd,
lock.l_type = F_WRLCK;
}
- int waitMode = (waitFlag) ? F_SETLKW : F_SETLK;
+ int waitMode = (waitFlag) ? F_SETLKW64 : F_SETLK64;
return TEMP_FAILURE_RETRY(fcntl(fd, waitMode, &lock));
}
static void OSFileSystem_unlockImpl(JNIEnv* env, jobject, jint fd, jlong start, jlong length) {
length = translateLockLength(length);
- if (offsetTooLarge(env, start) || offsetTooLarge(env, length)) {
- return;
- }
-
- struct flock lock(flockFromStartAndLength(start, length));
+ struct flock64 lock(flockFromStartAndLength(start, length));
lock.l_type = F_UNLCK;
- int rc = TEMP_FAILURE_RETRY(fcntl(fd, F_SETLKW, &lock));
+ int rc = TEMP_FAILURE_RETRY(fcntl(fd, F_SETLKW64, &lock));
if (rc == -1) {
jniThrowIOException(env, errno);
}
@@ -337,37 +305,28 @@ static jlong OSFileSystem_seek(JNIEnv* env, jobject, jint fd, jlong offset, jint
return -1;
}
- // If the offset is relative, lseek(2) will tell us whether it's too large.
- // We're just worried about too large an absolute offset, which would cause
- // us to lie to lseek(2).
- if (offsetTooLarge(env, offset)) {
- return -1;
- }
-
- jlong result = lseek(fd, offset, nativeWhence);
+ jlong result = lseek64(fd, offset, nativeWhence);
if (result == -1) {
- jniThrowIOException(env, errno);
+ if (errno == ESPIPE) {
+ jniThrowExceptionWithErrno(env,
+ "org/apache/harmony/luni/platform/IFileSystem$SeekPipeException",
+ errno);
+ } else {
+ jniThrowIOException(env, errno);
+ }
}
return result;
}
static void OSFileSystem_fsync(JNIEnv* env, jobject, jint fd, jboolean metadataToo) {
- if (!metadataToo) {
- LOGW("fdatasync(2) unimplemented on Android - doing fsync(2)"); // http://b/2667481
- }
- int rc = fsync(fd);
- // int rc = metadataToo ? fsync(fd) : fdatasync(fd);
+ int rc = metadataToo ? fsync(fd) : fdatasync(fd);
if (rc == -1) {
jniThrowIOException(env, errno);
}
}
static jint OSFileSystem_truncate(JNIEnv* env, jobject, jint fd, jlong length) {
- if (offsetTooLarge(env, length)) {
- return -1;
- }
-
- int rc = ftruncate(fd, length);
+ int rc = ftruncate64(fd, length);
if (rc == -1) {
jniThrowIOException(env, errno);
}
@@ -408,8 +367,24 @@ static jint OSFileSystem_open(JNIEnv* env, jobject, jstring javaPath, jint jflag
if (path.c_str() == NULL) {
return -1;
}
- jint rc = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
- if (rc == -1) {
+ jint fd = TEMP_FAILURE_RETRY(open(path.c_str(), flags, mode));
+
+ // Posix open(2) fails with EISDIR only if you ask for write permission.
+ // Java disallows reading directories too.
+ if (fd != -1) {
+ struct stat sb;
+ int rc = fstat(fd, &sb);
+ if (rc == -1 || S_ISDIR(sb.st_mode)) {
+ // Use EISDIR if that was the case; fail with the fstat(2) error otherwise.
+ close(fd);
+ fd = -1;
+ if (S_ISDIR(sb.st_mode)) {
+ errno = EISDIR;
+ }
+ }
+ }
+
+ if (fd == -1) {
// Get the human-readable form of errno.
char buffer[80];
const char* reason = jniStrError(errno, &buffer[0], sizeof(buffer));
@@ -422,7 +397,7 @@ static jint OSFileSystem_open(JNIEnv* env, jobject, jstring javaPath, jint jflag
// failure. (This appears to be true of the RI too.)
jniThrowException(env, "java/io/FileNotFoundException", &message[0]);
}
- return rc;
+ return fd;
}
static jint OSFileSystem_ioctlAvailable(JNIEnv*env, jobject, jobject fileDescriptor) {
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
index 43cfa32..5b19626 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSMemory.cpp
@@ -18,184 +18,234 @@
#include "JNIHelp.h"
#include "JniConstants.h"
+#include "ScopedPrimitiveArray.h"
#include "UniquePtr.h"
+#include "java_lang_Float.h"
+#include "java_lang_Double.h"
+#include <byteswap.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
-/*
- * Cached dalvik.system.VMRuntime pieces.
- */
-static struct {
- jmethodID method_trackExternalAllocation;
- jmethodID method_trackExternalFree;
-
- jobject runtimeInstance;
-} gIDCache;
+#if defined(__arm__)
+// 32-bit ARM has load/store alignment restrictions for longs.
+#define LONG_ALIGNMENT_MASK 0x3
+#elif defined(__i386__)
+// x86 can load anything at any alignment.
+#define LONG_ALIGNMENT_MASK 0x0
+#else
+#error unknown load/store alignment restrictions for this architecture
+#endif
template <typename T> static T cast(jint address) {
return reinterpret_cast<T>(static_cast<uintptr_t>(address));
}
-static jint OSMemory_malloc(JNIEnv* env, jclass, jint size) {
- jboolean allowed = env->CallBooleanMethod(gIDCache.runtimeInstance,
- gIDCache.method_trackExternalAllocation, static_cast<jlong>(size));
- if (!allowed) {
- LOGW("External allocation of %d bytes was rejected\n", size);
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
- return 0;
+static inline void swapShorts(jshort* dstShorts, const jshort* srcShorts, size_t count) {
+ // Do 32-bit swaps as long as possible...
+ jint* dst = reinterpret_cast<jint*>(dstShorts);
+ const jint* src = reinterpret_cast<const jint*>(srcShorts);
+ for (size_t i = 0; i < count / 2; ++i) {
+ jint v = *src++; // v=ABCD
+ v = bswap_32(v); // v=DCBA
+ jint v2 = (v << 16) | ((v >> 16) & 0xffff); // v=BADC
+ *dst++ = v2;
}
-
- LOGV("OSMemory alloc %d\n", size);
- void* block = malloc(size + sizeof(jlong));
- if (block == NULL) {
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
- return 0;
+ // ...with one last 16-bit swap if necessary.
+ if ((count % 2) != 0) {
+ jshort v = *reinterpret_cast<const jshort*>(src);
+ *reinterpret_cast<jshort*>(dst) = bswap_16(v);
}
-
- /*
- * Tuck a copy of the size at the head of the buffer. We need this
- * so OSMemory_free() knows how much memory is being freed.
- */
- jlong* result = reinterpret_cast<jlong*>(block);
- *result++ = size;
- return static_cast<jint>(reinterpret_cast<uintptr_t>(result));
}
-static void OSMemory_free(JNIEnv* env, jclass, jint address) {
- jlong* p = reinterpret_cast<jlong*>(static_cast<uintptr_t>(address));
- jlong size = *--p;
- LOGV("OSMemory free %ld\n", size);
- env->CallVoidMethod(gIDCache.runtimeInstance, gIDCache.method_trackExternalFree, size);
- free(reinterpret_cast<void*>(p));
+static inline void swapInts(jint* dstInts, const jint* srcInts, size_t count) {
+ for (size_t i = 0; i < count; ++i) {
+ jint v = *srcInts++;
+ *dstInts++ = bswap_32(v);
+ }
}
-static void OSMemory_memset(JNIEnv*, jclass, jint dstAddress, jbyte value, jlong length) {
- memset(cast<void*>(dstAddress), value, length);
+static inline void swapLongs(jlong* dstLongs, const jlong* srcLongs, size_t count) {
+ jint* dst = reinterpret_cast<jint*>(dstLongs);
+ const jint* src = reinterpret_cast<const jint*>(srcLongs);
+ for (size_t i = 0; i < count; ++i) {
+ jint v1 = *src++;
+ jint v2 = *src++;
+ *dst++ = bswap_32(v2);
+ *dst++ = bswap_32(v1);
+ }
}
static void OSMemory_memmove(JNIEnv*, jclass, jint dstAddress, jint srcAddress, jlong length) {
memmove(cast<void*>(dstAddress), cast<const void*>(srcAddress), length);
}
-static jbyte OSMemory_getByte(JNIEnv*, jclass, jint srcAddress) {
+static jbyte OSMemory_peekByte(JNIEnv*, jclass, jint srcAddress) {
return *cast<const jbyte*>(srcAddress);
}
-static void OSMemory_getByteArray(JNIEnv* env, jclass, jint srcAddress,
- jbyteArray dst, jint offset, jint length) {
- env->SetByteArrayRegion(dst, offset, length, cast<const jbyte*>(srcAddress));
+static void OSMemory_peekByteArray(JNIEnv* env, jclass, jint srcAddress, jbyteArray dst, jint dstOffset, jint byteCount) {
+ env->SetByteArrayRegion(dst, dstOffset, byteCount, cast<const jbyte*>(srcAddress));
+}
+
+// Implements the peekXArray methods:
+// - For unswapped access, we just use the JNI SetXArrayRegion functions.
+// - For swapped access, we use GetXArrayElements and our own copy-and-swap routines.
+// GetXArrayElements is disproportionately cheap on Dalvik because it doesn't copy (as opposed
+// to Hotspot, which always copies). The SWAP_FN copies and swaps in one pass, which is cheaper
+// than copying and then swapping in a second pass. Depending on future VM/GC changes, the
+// swapped case might need to be revisited.
+#define PEEKER(SCALAR_TYPE, JNI_NAME, SWAP_TYPE, SWAP_FN) { \
+ if (swap) { \
+ Scoped ## JNI_NAME ## ArrayRW elements(env, dst); \
+ if (elements.get() == NULL) { \
+ return; \
+ } \
+ const SWAP_TYPE* src = cast<const SWAP_TYPE*>(srcAddress); \
+ SWAP_FN(reinterpret_cast<SWAP_TYPE*>(elements.get()) + dstOffset, src, count); \
+ } else { \
+ const SCALAR_TYPE* src = cast<const SCALAR_TYPE*>(srcAddress); \
+ env->Set ## JNI_NAME ## ArrayRegion(dst, dstOffset, count, src); \
+ } \
+}
+
+static void OSMemory_peekCharArray(JNIEnv* env, jclass, jint srcAddress, jcharArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jchar, Char, jshort, swapShorts);
+}
+
+static void OSMemory_peekDoubleArray(JNIEnv* env, jclass, jint srcAddress, jdoubleArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jdouble, Double, jlong, swapLongs);
+}
+
+static void OSMemory_peekFloatArray(JNIEnv* env, jclass, jint srcAddress, jfloatArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jfloat, Float, jint, swapInts);
+}
+
+static void OSMemory_peekIntArray(JNIEnv* env, jclass, jint srcAddress, jintArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jint, Int, jint, swapInts);
+}
+
+static void OSMemory_peekLongArray(JNIEnv* env, jclass, jint srcAddress, jlongArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jlong, Long, jlong, swapLongs);
+}
+
+static void OSMemory_peekShortArray(JNIEnv* env, jclass, jint srcAddress, jshortArray dst, jint dstOffset, jint count, jboolean swap) {
+ PEEKER(jshort, Short, jshort, swapShorts);
}
-static void OSMemory_setByte(JNIEnv*, jclass, jint dstAddress, jbyte value) {
+static void OSMemory_pokeByte(JNIEnv*, jclass, jint dstAddress, jbyte value) {
*cast<jbyte*>(dstAddress) = value;
}
-static void OSMemory_setByteArray(JNIEnv* env, jclass,
- jint dstAddress, jbyteArray src, jint offset, jint length) {
+static void OSMemory_pokeByteArray(JNIEnv* env, jclass, jint dstAddress, jbyteArray src, jint offset, jint length) {
env->GetByteArrayRegion(src, offset, length, cast<jbyte*>(dstAddress));
}
-static void swapShorts(jshort* shorts, int count) {
- jbyte* src = reinterpret_cast<jbyte*>(shorts);
- jbyte* dst = src;
- for (int i = 0; i < count; ++i) {
- jbyte b0 = *src++;
- jbyte b1 = *src++;
- *dst++ = b1;
- *dst++ = b0;
- }
+// Implements the pokeXArray methods:
+// - For unswapped access, we just use the JNI GetXArrayRegion functions.
+// - For swapped access, we use GetXArrayElements and our own copy-and-swap routines.
+// GetXArrayElements is disproportionately cheap on Dalvik because it doesn't copy (as opposed
+// to Hotspot, which always copies). The SWAP_FN copies and swaps in one pass, which is cheaper
+// than copying and then swapping in a second pass. Depending on future VM/GC changes, the
+// swapped case might need to be revisited.
+#define POKER(SCALAR_TYPE, JNI_NAME, SWAP_TYPE, SWAP_FN) { \
+ if (swap) { \
+ Scoped ## JNI_NAME ## ArrayRO elements(env, src); \
+ if (elements.get() == NULL) { \
+ return; \
+ } \
+ const SWAP_TYPE* src = reinterpret_cast<const SWAP_TYPE*>(elements.get()) + srcOffset; \
+ SWAP_FN(cast<SWAP_TYPE*>(dstAddress), src, count); \
+ } else { \
+ env->Get ## JNI_NAME ## ArrayRegion(src, srcOffset, count, cast<SCALAR_TYPE*>(dstAddress)); \
+ } \
}
-static void swapInts(jint* ints, int count) {
- jbyte* src = reinterpret_cast<jbyte*>(ints);
- jbyte* dst = src;
- for (int i = 0; i < count; ++i) {
- jbyte b0 = *src++;
- jbyte b1 = *src++;
- jbyte b2 = *src++;
- jbyte b3 = *src++;
- *dst++ = b3;
- *dst++ = b2;
- *dst++ = b1;
- *dst++ = b0;
- }
+static void OSMemory_pokeCharArray(JNIEnv* env, jclass, jint dstAddress, jcharArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jchar, Char, jshort, swapShorts);
}
-static void OSMemory_setFloatArray(JNIEnv* env, jclass, jint dstAddress,
- jfloatArray src, jint offset, jint length, jboolean swap) {
- jfloat* dst = cast<jfloat*>(dstAddress);
- env->GetFloatArrayRegion(src, offset, length, dst);
- if (swap) {
- swapInts(reinterpret_cast<jint*>(dst), length);
- }
+static void OSMemory_pokeDoubleArray(JNIEnv* env, jclass, jint dstAddress, jdoubleArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jdouble, Double, jlong, swapLongs);
+}
+
+static void OSMemory_pokeFloatArray(JNIEnv* env, jclass, jint dstAddress, jfloatArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jfloat, Float, jint, swapInts);
+}
+
+static void OSMemory_pokeIntArray(JNIEnv* env, jclass, jint dstAddress, jintArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jint, Int, jint, swapInts);
+}
+
+static void OSMemory_pokeLongArray(JNIEnv* env, jclass, jint dstAddress, jlongArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jlong, Long, jlong, swapLongs);
+}
+
+static void OSMemory_pokeShortArray(JNIEnv* env, jclass, jint dstAddress, jshortArray src, jint srcOffset, jint count, jboolean swap) {
+ POKER(jshort, Short, jshort, swapShorts);
}
-static void OSMemory_setIntArray(JNIEnv* env, jclass,
- jint dstAddress, jintArray src, jint offset, jint length, jboolean swap) {
- jint* dst = cast<jint*>(dstAddress);
- env->GetIntArrayRegion(src, offset, length, dst);
+static jshort OSMemory_peekShort(JNIEnv*, jclass, jint srcAddress, jboolean swap) {
+ jshort result = *cast<const jshort*>(srcAddress);
if (swap) {
- swapInts(dst, length);
+ result = bswap_16(result);
}
+ return result;
}
-static void OSMemory_setShortArray(JNIEnv* env, jclass,
- jint dstAddress, jshortArray src, jint offset, jint length, jboolean swap) {
- jshort* dst = cast<jshort*>(dstAddress);
- env->GetShortArrayRegion(src, offset, length, dst);
+static void OSMemory_pokeShort(JNIEnv*, jclass, jint dstAddress, jshort value, jboolean swap) {
if (swap) {
- swapShorts(dst, length);
+ value = bswap_16(value);
}
+ *cast<jshort*>(dstAddress) = value;
}
-static jshort OSMemory_getShort(JNIEnv*, jclass, jint srcAddress) {
- if ((srcAddress & 0x1) == 0) {
- return *cast<const jshort*>(srcAddress);
- } else {
- // Handle unaligned memory access one byte at a time
- jshort result;
- const jbyte* src = cast<const jbyte*>(srcAddress);
- jbyte* dst = reinterpret_cast<jbyte*>(&result);
- dst[0] = src[0];
- dst[1] = src[1];
- return result;
+static jint OSMemory_peekInt(JNIEnv*, jclass, jint srcAddress, jboolean swap) {
+ jint result = *cast<const jint*>(srcAddress);
+ if (swap) {
+ result = bswap_32(result);
}
+ return result;
}
-static void OSMemory_setShort(JNIEnv*, jclass, jint dstAddress, jshort value) {
- if ((dstAddress & 0x1) == 0) {
- *cast<jshort*>(dstAddress) = value;
- } else {
- // Handle unaligned memory access one byte at a time
- const jbyte* src = reinterpret_cast<const jbyte*>(&value);
- jbyte* dst = cast<jbyte*>(dstAddress);
- dst[0] = src[0];
- dst[1] = src[1];
+static void OSMemory_pokeInt(JNIEnv*, jclass, jint dstAddress, jint value, jboolean swap) {
+ if (swap) {
+ value = bswap_32(value);
}
+ *cast<jint*>(dstAddress) = value;
}
-static jint OSMemory_getInt(JNIEnv*, jclass, jint srcAddress) {
- if ((srcAddress & 0x3) == 0) {
- return *cast<const jint*>(srcAddress);
+static jlong OSMemory_peekLong(JNIEnv*, jclass, jint srcAddress, jboolean swap) {
+ jlong result;
+ if ((srcAddress & LONG_ALIGNMENT_MASK) == 0) {
+ result = *cast<const jlong*>(srcAddress);
} else {
// Handle unaligned memory access one byte at a time
- jint result;
const jbyte* src = cast<const jbyte*>(srcAddress);
jbyte* dst = reinterpret_cast<jbyte*>(&result);
dst[0] = src[0];
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
- return result;
+ dst[4] = src[4];
+ dst[5] = src[5];
+ dst[6] = src[6];
+ dst[7] = src[7];
}
+ if (swap) {
+ result = bswap_64(result);
+ }
+ return result;
}
-static void OSMemory_setInt(JNIEnv*, jclass, jint dstAddress, jint value) {
- if ((dstAddress & 0x3) == 0) {
- *cast<jint*>(dstAddress) = value;
+static void OSMemory_pokeLong(JNIEnv*, jclass, jint dstAddress, jlong value, jboolean swap) {
+ if (swap) {
+ value = bswap_64(value);
+ }
+ if ((dstAddress & LONG_ALIGNMENT_MASK) == 0) {
+ *cast<jlong*>(dstAddress) = value;
} else {
// Handle unaligned memory access one byte at a time
const jbyte* src = reinterpret_cast<const jbyte*>(&value);
@@ -204,63 +254,13 @@ static void OSMemory_setInt(JNIEnv*, jclass, jint dstAddress, jint value) {
dst[1] = src[1];
dst[2] = src[2];
dst[3] = src[3];
+ dst[4] = src[4];
+ dst[5] = src[5];
+ dst[6] = src[6];
+ dst[7] = src[7];
}
}
-template <typename T> static T get(jint srcAddress) {
- if ((srcAddress & (sizeof(T) - 1)) == 0) {
- return *cast<const T*>(srcAddress);
- } else {
- // Cast to void* so GCC can't assume correct alignment and optimize this out.
- const void* src = cast<const void*>(srcAddress);
- T result;
- memcpy(&result, src, sizeof(T));
- return result;
- }
-}
-
-template <typename T> static void set(jint dstAddress, T value) {
- if ((dstAddress & (sizeof(T) - 1)) == 0) {
- *cast<T*>(dstAddress) = value;
- } else {
- // Cast to void* so GCC can't assume correct alignment and optimize this out.
- void* dst = cast<void*>(dstAddress);
- memcpy(dst, &value, sizeof(T));
- }
-}
-
-static jlong OSMemory_getLong(JNIEnv*, jclass, jint srcAddress) {
- return get<jlong>(srcAddress);
-}
-
-static void OSMemory_setLong(JNIEnv*, jclass, jint dstAddress, jlong value) {
- set<jlong>(dstAddress, value);
-}
-
-static jfloat OSMemory_getFloat(JNIEnv*, jclass, jint srcAddress) {
- return get<jfloat>(srcAddress);
-}
-
-static void OSMemory_setFloat(JNIEnv*, jclass, jint dstAddress, jfloat value) {
- set<jfloat>(dstAddress, value);
-}
-
-static jdouble OSMemory_getDouble(JNIEnv*, jclass, jint srcAddress) {
- return get<jdouble>(srcAddress);
-}
-
-static void OSMemory_setDouble(JNIEnv*, jclass, jint dstAddress, jdouble value) {
- set<jdouble>(dstAddress, value);
-}
-
-static jint OSMemory_getAddress(JNIEnv*, jclass, jint srcAddress) {
- return *cast<const jint*>(srcAddress);
-}
-
-static void OSMemory_setAddress(JNIEnv*, jclass, jint dstAddress, jint value) {
- *cast<jint*>(dstAddress) = value;
-}
-
static jint OSMemory_mmapImpl(JNIEnv* env, jclass, jint fd, jlong offset, jlong size, jint mapMode) {
int prot, flags;
switch (mapMode) {
@@ -289,7 +289,7 @@ static jint OSMemory_mmapImpl(JNIEnv* env, jclass, jint fd, jlong offset, jlong
return reinterpret_cast<uintptr_t>(mapAddress);
}
-static void OSMemory_unmap(JNIEnv*, jclass, jint address, jlong size) {
+static void OSMemory_munmap(JNIEnv*, jclass, jint address, jlong size) {
munmap(cast<void*>(address), size);
}
@@ -325,68 +325,99 @@ static jboolean OSMemory_isLoaded(JNIEnv*, jclass, jint address, jlong size) {
return JNI_TRUE;
}
-static void OSMemory_flush(JNIEnv*, jclass, jint address, jlong size) {
+static void OSMemory_msync(JNIEnv*, jclass, jint address, jlong size) {
msync(cast<void*>(address), size, MS_SYNC);
}
+static void unsafeBulkCopy(jbyte* dst, const jbyte* src, jint byteCount,
+ jint sizeofElement, jboolean swap) {
+ if (!swap) {
+ memcpy(dst, src, byteCount);
+ return;
+ }
+
+ if (sizeofElement == 2) {
+ jshort* dstShorts = reinterpret_cast<jshort*>(dst);
+ const jshort* srcShorts = reinterpret_cast<const jshort*>(src);
+ swapShorts(dstShorts, srcShorts, byteCount / 2);
+ } else if (sizeofElement == 4) {
+ jint* dstInts = reinterpret_cast<jint*>(dst);
+ const jint* srcInts = reinterpret_cast<const jint*>(src);
+ swapInts(dstInts, srcInts, byteCount / 4);
+ } else if (sizeofElement == 8) {
+ jlong* dstLongs = reinterpret_cast<jlong*>(dst);
+ const jlong* srcLongs = reinterpret_cast<const jlong*>(src);
+ swapLongs(dstLongs, srcLongs, byteCount / 8);
+ }
+}
+
+static void OSMemory_unsafeBulkGet(JNIEnv* env, jclass, jobject dstObject, jint dstOffset,
+ jint byteCount, jbyteArray srcArray, jint srcOffset, jint sizeofElement, jboolean swap) {
+ ScopedByteArrayRO srcBytes(env, srcArray);
+ if (srcBytes.get() == NULL) {
+ return;
+ }
+ jarray dstArray = reinterpret_cast<jarray>(dstObject);
+ jbyte* dstBytes = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(dstArray, NULL));
+ if (dstBytes == NULL) {
+ return;
+ }
+ jbyte* dst = dstBytes + dstOffset*sizeofElement;
+ const jbyte* src = srcBytes.get() + srcOffset;
+ unsafeBulkCopy(dst, src, byteCount, sizeofElement, swap);
+ env->ReleasePrimitiveArrayCritical(dstArray, dstBytes, 0);
+}
+
+static void OSMemory_unsafeBulkPut(JNIEnv* env, jclass, jbyteArray dstArray, jint dstOffset,
+ jint byteCount, jobject srcObject, jint srcOffset, jint sizeofElement, jboolean swap) {
+ ScopedByteArrayRW dstBytes(env, dstArray);
+ if (dstBytes.get() == NULL) {
+ return;
+ }
+ jarray srcArray = reinterpret_cast<jarray>(srcObject);
+ jbyte* srcBytes = reinterpret_cast<jbyte*>(env->GetPrimitiveArrayCritical(srcArray, NULL));
+ if (srcBytes == NULL) {
+ return;
+ }
+ jbyte* dst = dstBytes.get() + dstOffset;
+ const jbyte* src = srcBytes + srcOffset*sizeofElement;
+ unsafeBulkCopy(dst, src, byteCount, sizeofElement, swap);
+ env->ReleasePrimitiveArrayCritical(srcArray, srcBytes, 0);
+}
+
static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(OSMemory, flush, "(IJ)V"),
- NATIVE_METHOD(OSMemory, free, "(I)V"),
- NATIVE_METHOD(OSMemory, getAddress, "(I)I"),
- NATIVE_METHOD(OSMemory, getByte, "(I)B"),
- NATIVE_METHOD(OSMemory, getByteArray, "(I[BII)V"),
- NATIVE_METHOD(OSMemory, getDouble, "(I)D"),
- NATIVE_METHOD(OSMemory, getFloat, "(I)F"),
- NATIVE_METHOD(OSMemory, getInt, "(I)I"),
- NATIVE_METHOD(OSMemory, getLong, "(I)J"),
- NATIVE_METHOD(OSMemory, getShort, "(I)S"),
NATIVE_METHOD(OSMemory, isLoaded, "(IJ)Z"),
NATIVE_METHOD(OSMemory, load, "(IJ)V"),
- NATIVE_METHOD(OSMemory, malloc, "(I)I"),
NATIVE_METHOD(OSMemory, memmove, "(IIJ)V"),
- NATIVE_METHOD(OSMemory, memset, "(IBJ)V"),
NATIVE_METHOD(OSMemory, mmapImpl, "(IJJI)I"),
- NATIVE_METHOD(OSMemory, setAddress, "(II)V"),
- NATIVE_METHOD(OSMemory, setByte, "(IB)V"),
- NATIVE_METHOD(OSMemory, setByteArray, "(I[BII)V"),
- NATIVE_METHOD(OSMemory, setDouble, "(ID)V"),
- NATIVE_METHOD(OSMemory, setFloat, "(IF)V"),
- NATIVE_METHOD(OSMemory, setFloatArray, "(I[FIIZ)V"),
- NATIVE_METHOD(OSMemory, setInt, "(II)V"),
- NATIVE_METHOD(OSMemory, setIntArray, "(I[IIIZ)V"),
- NATIVE_METHOD(OSMemory, setLong, "(IJ)V"),
- NATIVE_METHOD(OSMemory, setShort, "(IS)V"),
- NATIVE_METHOD(OSMemory, setShortArray, "(I[SIIZ)V"),
- NATIVE_METHOD(OSMemory, unmap, "(IJ)V"),
+ NATIVE_METHOD(OSMemory, msync, "(IJ)V"),
+ NATIVE_METHOD(OSMemory, munmap, "(IJ)V"),
+ NATIVE_METHOD(OSMemory, peekByte, "(I)B"),
+ NATIVE_METHOD(OSMemory, peekByteArray, "(I[BII)V"),
+ NATIVE_METHOD(OSMemory, peekCharArray, "(I[CIIZ)V"),
+ NATIVE_METHOD(OSMemory, peekDoubleArray, "(I[DIIZ)V"),
+ NATIVE_METHOD(OSMemory, peekFloatArray, "(I[FIIZ)V"),
+ NATIVE_METHOD(OSMemory, peekInt, "(IZ)I"),
+ NATIVE_METHOD(OSMemory, peekIntArray, "(I[IIIZ)V"),
+ NATIVE_METHOD(OSMemory, peekLong, "(IZ)J"),
+ NATIVE_METHOD(OSMemory, peekLongArray, "(I[JIIZ)V"),
+ NATIVE_METHOD(OSMemory, peekShort, "(IZ)S"),
+ NATIVE_METHOD(OSMemory, peekShortArray, "(I[SIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeByte, "(IB)V"),
+ NATIVE_METHOD(OSMemory, pokeByteArray, "(I[BII)V"),
+ NATIVE_METHOD(OSMemory, pokeCharArray, "(I[CIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeDoubleArray, "(I[DIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeFloatArray, "(I[FIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeInt, "(IIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeIntArray, "(I[IIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeLong, "(IJZ)V"),
+ NATIVE_METHOD(OSMemory, pokeLongArray, "(I[JIIZ)V"),
+ NATIVE_METHOD(OSMemory, pokeShort, "(ISZ)V"),
+ NATIVE_METHOD(OSMemory, pokeShortArray, "(I[SIIZ)V"),
+ NATIVE_METHOD(OSMemory, unsafeBulkGet, "(Ljava/lang/Object;II[BIIZ)V"),
+ NATIVE_METHOD(OSMemory, unsafeBulkPut, "([BIILjava/lang/Object;IIZ)V"),
};
int register_org_apache_harmony_luni_platform_OSMemory(JNIEnv* env) {
- /*
- * We need to call VMRuntime.trackExternal{Allocation,Free}. Cache
- * method IDs and a reference to the singleton.
- */
- gIDCache.method_trackExternalAllocation = env->GetMethodID(JniConstants::vmRuntimeClass,
- "trackExternalAllocation", "(J)Z");
- gIDCache.method_trackExternalFree = env->GetMethodID(JniConstants::vmRuntimeClass,
- "trackExternalFree", "(J)V");
-
- jmethodID method_getRuntime = env->GetStaticMethodID(JniConstants::vmRuntimeClass,
- "getRuntime", "()Ldalvik/system/VMRuntime;");
-
- if (gIDCache.method_trackExternalAllocation == NULL ||
- gIDCache.method_trackExternalFree == NULL ||
- method_getRuntime == NULL)
- {
- LOGE("Unable to find VMRuntime methods\n");
- return -1;
- }
-
- jobject instance = env->CallStaticObjectMethod(JniConstants::vmRuntimeClass, method_getRuntime);
- if (instance == NULL) {
- LOGE("Unable to obtain VMRuntime instance\n");
- return -1;
- }
- gIDCache.runtimeInstance = env->NewGlobalRef(instance);
-
return jniRegisterNativeMethods(env, "org/apache/harmony/luni/platform/OSMemory",
gMethods, NELEM(gMethods));
}
diff --git a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
index 64cf516..03d1e69 100644
--- a/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_platform_OSNetworkSystem.cpp
@@ -20,7 +20,6 @@
#include "JNIHelp.h"
#include "JniConstants.h"
#include "JniException.h"
-#include "LocalArray.h"
#include "NetFd.h"
#include "NetworkUtilities.h"
#include "ScopedPrimitiveArray.h"
@@ -28,8 +27,8 @@
#include "valueOf.h"
#include <arpa/inet.h>
-#include <assert.h>
#include <errno.h>
+#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -74,6 +73,7 @@
#define JAVASOCKOPT_SO_TIMEOUT 4102
#define JAVASOCKOPT_SO_REUSEADDR 4
#define JAVASOCKOPT_SO_SNDBUF 4097
+#define JAVASOCKOPT_SO_BINDTODEVICE 8192
#define JAVASOCKOPT_TCP_NODELAY 1
/* constants for OSNetworkSystem_selectImpl */
@@ -359,20 +359,36 @@ static void mcastJoinLeaveGroup(JNIEnv* env, int fd, jobject javaGroupRequest, b
group_req groupRequest;
// Get the IPv4 or IPv6 multicast address to join or leave.
- jfieldID fid = env->GetFieldID(JniConstants::multicastGroupRequestClass,
+ static jfieldID grGroupFid = env->GetFieldID(JniConstants::multicastGroupRequestClass,
"gr_group", "Ljava/net/InetAddress;");
- jobject group = env->GetObjectField(javaGroupRequest, fid);
+ jobject group = env->GetObjectField(javaGroupRequest, grGroupFid);
if (!inetAddressToSocketAddress(env, group, 0, &groupRequest.gr_group)) {
return;
}
// Get the interface index to use (or 0 for "whatever").
- fid = env->GetFieldID(JniConstants::multicastGroupRequestClass, "gr_interface", "I");
- groupRequest.gr_interface = env->GetIntField(javaGroupRequest, fid);
+ static jfieldID grInterfaceFid =
+ env->GetFieldID(JniConstants::multicastGroupRequestClass, "gr_interface", "I");
+ groupRequest.gr_interface = env->GetIntField(javaGroupRequest, grInterfaceFid);
+ // Decide exactly what we're trying to do...
int level = groupRequest.gr_group.ss_family == AF_INET ? IPPROTO_IP : IPPROTO_IPV6;
int option = join ? MCAST_JOIN_GROUP : MCAST_LEAVE_GROUP;
+
int rc = setsockopt(fd, level, option, &groupRequest, sizeof(groupRequest));
+ if (rc == -1 && errno == EINVAL) {
+ // Maybe we're a 32-bit binary talking to a 64-bit kernel?
+ // glibc doesn't automatically handle this.
+ struct group_req64 {
+ uint32_t gr_interface;
+ uint32_t my_padding;
+ sockaddr_storage gr_group;
+ };
+ group_req64 groupRequest64;
+ groupRequest64.gr_interface = groupRequest.gr_interface;
+ memcpy(&groupRequest64.gr_group, &groupRequest.gr_group, sizeof(groupRequest.gr_group));
+ rc = setsockopt(fd, level, option, &groupRequest64, sizeof(groupRequest64));
+ }
if (rc == -1) {
jniThrowSocketException(env, errno);
return;
@@ -1221,6 +1237,22 @@ static void OSNetworkSystem_setSocketOption(JNIEnv* env, jobject, jobject fileDe
case JAVASOCKOPT_SO_SNDBUF:
setSocketOption(env, fd, SOL_SOCKET, SO_SNDBUF, &intVal);
return;
+ case JAVASOCKOPT_SO_BINDTODEVICE: {
+ // intVal contains the interface index
+ char ifname[IF_NAMESIZE];
+
+ if (if_indextoname(intVal, ifname) == NULL) {
+ jniThrowSocketException(env, ENODEV);
+ } else {
+ ifreq ifr;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ setSocketOption(env, fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr);
+ }
+ return;
+ }
case JAVASOCKOPT_SO_TIMEOUT:
{
timeval timeout(toTimeval(intVal));
@@ -1328,6 +1360,8 @@ static void OSNetworkSystem_shutdownOutput(JNIEnv* env, jobject, jobject fd) {
static void OSNetworkSystem_close(JNIEnv* env, jobject, jobject fileDescriptor) {
NetFd fd(env, fileDescriptor);
if (fd.isClosed()) {
+ // Socket.close doesn't throw if you try to close an already-closed socket.
+ env->ExceptionClear();
return;
}
diff --git a/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp b/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp
index fdae21a..1428a80 100644
--- a/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp
+++ b/luni/src/main/native/org_apache_harmony_luni_util_FloatingPointParser.cpp
@@ -332,7 +332,7 @@ static jdouble createDouble1(JNIEnv* env, uint64_t* f, int32_t length, jint e) {
* is currently set such that if the oscillation occurs more than twice
* then return the original approximation.
*/
-static jdouble doubleAlgorithm(JNIEnv*, uint64_t* f, int32_t length, jint e, jdouble z) {
+static jdouble doubleAlgorithm(JNIEnv* env, uint64_t* f, int32_t length, jint e, jdouble z) {
uint64_t m;
int32_t k, comparison, comparison2;
uint64_t* x;
@@ -510,9 +510,7 @@ OutOfMemory:
free(y);
free(D);
free(D2);
-
- DOUBLE_TO_LONGBITS (z) = -2;
-
+ jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
return z;
}
@@ -584,7 +582,6 @@ static const uint32_t float_tens[] = {
break; \
} \
}
-#define ERROR_OCCURRED(x) (HIGH_I32_FROM_VAR(x) < 0)
static jfloat createFloat(JNIEnv* env, const char* s, jint e) {
/* assumes s is a null terminated string with at least one
@@ -809,7 +806,7 @@ static jfloat createFloat1 (JNIEnv* env, uint64_t* f, int32_t length, jint e) {
* is currently set such that if the oscillation occurs more than twice
* then return the original approximation.
*/
-static jfloat floatAlgorithm(JNIEnv*, uint64_t* f, int32_t length, jint e, jfloat z) {
+static jfloat floatAlgorithm(JNIEnv* env, uint64_t* f, int32_t length, jint e, jfloat z) {
uint64_t m;
int32_t k, comparison, comparison2;
uint64_t* x;
@@ -987,9 +984,7 @@ OutOfMemory:
free(y);
free(D);
free(D2);
-
- FLOAT_TO_INTBITS (z) = -2;
-
+ jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
return z;
}
@@ -998,16 +993,7 @@ static jfloat FloatingPointParser_parseFltImpl(JNIEnv* env, jclass, jstring s, j
if (str.c_str() == NULL) {
return 0.0;
}
- jfloat flt = createFloat(env, str.c_str(), e);
-
- if (((int32_t) FLOAT_TO_INTBITS (flt)) >= 0) {
- return flt;
- } else if (((int32_t) FLOAT_TO_INTBITS (flt)) == (int32_t) - 1) {
- jniThrowException(env, "java/lang/NumberFormatException", NULL);
- } else {
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
- }
- return 0.0;
+ return createFloat(env, str.c_str(), e);
}
static jdouble FloatingPointParser_parseDblImpl(JNIEnv* env, jclass, jstring s, jint e) {
@@ -1015,16 +1001,7 @@ static jdouble FloatingPointParser_parseDblImpl(JNIEnv* env, jclass, jstring s,
if (str.c_str() == NULL) {
return 0.0;
}
- jdouble dbl = createDouble(env, str.c_str(), e);
-
- if (!ERROR_OCCURRED (dbl)) {
- return dbl;
- } else if (LOW_I32_FROM_VAR (dbl) == (int32_t) - 1) {
- jniThrowException(env, "java/lang/NumberFormatException", NULL);
- } else {
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
- }
- return 0.0;
+ return createDouble(env, str.c_str(), e);
}
static JNINativeMethod gMethods[] = {
diff --git a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
index c4623e6..a5ee710 100644
--- a/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
+++ b/luni/src/main/native/org_apache_harmony_xml_ExpatParser.cpp
@@ -608,7 +608,7 @@ static void startElement(void* data, const char* elementName, const char** attri
// Count the number of attributes.
int count = 0;
- while (attributes[count << 1]) count++;
+ while (attributes[count * 2]) count++;
// Make the attributes available for the duration of this call.
parsingContext->attributes = attributes;
@@ -1000,9 +1000,11 @@ static jint ExpatParser_initialize(JNIEnv* env, jobject object, jstring javaEnco
}
/**
- * Expat decides for itself what character encoding it's looking at. The interface is in terms of
- * bytes, which may point to UTF-8, UTF-16, ISO-8859-1, or US-ASCII. appendBytes, appendCharacters,
- * and appendString thus all call through to this method, strange though that appears.
+ * Decodes the bytes as characters and parse the characters as XML. This
+ * performs character decoding using the charset specified at XML_Parser
+ * creation. For Java chars, that charset must be UTF-16 so that a Java char[]
+ * can be reinterpreted as a UTF-16 encoded byte[]. appendBytes, appendChars
+ * and appendString all call through this method.
*/
static void append(JNIEnv* env, jobject object, jint pointer,
const char* bytes, size_t byteOffset, size_t byteCount, jboolean isFinal) {
@@ -1159,7 +1161,7 @@ static jstring ExpatAttributes_getQName(JNIEnv* env, jobject, jint pointer,
static jstring ExpatAttributes_getValueByIndex(JNIEnv* env, jobject,
jint attributePointer, jint index) {
const char** attributes = toAttributes(attributePointer);
- const char* value = attributes[(index << 1) + 1];
+ const char* value = attributes[(index * 2) + 1];
return env->NewStringUTF(value);
}
@@ -1262,7 +1264,7 @@ static jstring ExpatAttributes_getValue(JNIEnv* env, jobject clazz,
*/
static jint ExpatParser_cloneAttributes(JNIEnv* env, jobject, jint address, jint count) {
const char** source = reinterpret_cast<const char**>(static_cast<uintptr_t>(address));
- count <<= 1;
+ count *= 2;
// Figure out how big the buffer needs to be.
int arraySize = (count + 1) * sizeof(char*);
@@ -1277,7 +1279,7 @@ static jint ExpatParser_cloneAttributes(JNIEnv* env, jobject, jint address, jint
char* buffer = new char[totalSize];
if (buffer == NULL) {
throw_OutOfMemoryError(env);
- return NULL;
+ return 0;
}
// Array is at the beginning of the buffer.
diff --git a/luni/src/main/native/readlink.cpp b/luni/src/main/native/readlink.cpp
new file mode 100644
index 0000000..555d515
--- /dev/null
+++ b/luni/src/main/native/readlink.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "LocalArray.h"
+#include "readlink.h"
+
+#include <string>
+#include <unistd.h>
+
+bool readlink(const char* path, std::string& result) {
+ // We can't know how big a buffer readlink(2) will need, so we need to
+ // loop until it says "that fit".
+ size_t bufSize = 512;
+ while (true) {
+ LocalArray<512> buf(bufSize);
+ ssize_t len = readlink(path, &buf[0], buf.size());
+ if (len == -1) {
+ // An error occurred.
+ return false;
+ }
+ if (static_cast<size_t>(len) < buf.size()) {
+ // The buffer was big enough.
+ result.assign(&buf[0], len);
+ return true;
+ }
+ // Try again with a bigger buffer.
+ bufSize *= 2;
+ }
+}
diff --git a/luni/src/main/native/readlink.h b/luni/src/main/native/readlink.h
new file mode 100644
index 0000000..14031dc
--- /dev/null
+++ b/luni/src/main/native/readlink.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <string>
+
+/**
+ * Fills 'result' with the contents of the symbolic link 'path'. Sets errno and returns false on
+ * failure, returns true on success. The contents of 'result' on failure are undefined. Possible
+ * errors are those defined for readlink(2), except that this function takes care of sizing the
+ * buffer appropriately.
+ */
+bool readlink(const char* path, std::string& result);
diff --git a/luni/src/main/native/realpath.cpp b/luni/src/main/native/realpath.cpp
new file mode 100644
index 0000000..d1960a4
--- /dev/null
+++ b/luni/src/main/native/realpath.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2003 Constantin S. Svintsoff <kostik@iclub.nsu.ru>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The names of the authors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "readlink.h"
+
+#include <string>
+
+#include <errno.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/**
+ * This differs from realpath(3) mainly in its behavior when a path element does not exist or can
+ * not be searched. realpath(3) treats that as an error and gives up, but we have Java-compatible
+ * behavior where we just assume the path element was not a symbolic link. This leads to a textual
+ * treatment of ".." from that point in the path, which may actually lead us back to a path we
+ * can resolve (as in "/tmp/does-not-exist/../blah.txt" which would be an error for realpath(3)
+ * but "/tmp/blah.txt" under the traditional Java interpretation).
+ *
+ * This implementation also removes all the fixed-length buffers of the C original.
+ */
+bool realpath(const char* path, std::string& resolved) {
+ // 'path' must be an absolute path.
+ if (path[0] != '/') {
+ errno = EINVAL;
+ return false;
+ }
+
+ resolved = "/";
+ if (path[1] == '\0') {
+ return true;
+ }
+
+ // Iterate over path components in 'left'.
+ int symlinkCount = 0;
+ std::string left(path + 1);
+ while (!left.empty()) {
+ // Extract the next path component.
+ size_t nextSlash = left.find('/');
+ std::string nextPathComponent = left.substr(0, nextSlash);
+ if (nextSlash != std::string::npos) {
+ left.erase(0, nextSlash + 1);
+ } else {
+ left.clear();
+ }
+ if (nextPathComponent.empty()) {
+ continue;
+ } else if (nextPathComponent == ".") {
+ continue;
+ } else if (nextPathComponent == "..") {
+ // Strip the last path component except when we have single "/".
+ if (resolved.size() > 1) {
+ resolved.erase(resolved.rfind('/'));
+ }
+ continue;
+ }
+
+ // Append the next path component.
+ if (resolved[resolved.size() - 1] != '/') {
+ resolved += '/';
+ }
+ resolved += nextPathComponent;
+
+ // See if we've got a symbolic link, and resolve it if so.
+ struct stat sb;
+ if (lstat(resolved.c_str(), &sb) == 0 && S_ISLNK(sb.st_mode)) {
+ if (symlinkCount++ > MAXSYMLINKS) {
+ errno = ELOOP;
+ return false;
+ }
+
+ std::string symlink;
+ if (!readlink(resolved.c_str(), symlink)) {
+ return false;
+ }
+ if (symlink[0] == '/') {
+ // The symbolic link is absolute, so we need to start from scratch.
+ resolved = "/";
+ } else if (resolved.size() > 1) {
+ // The symbolic link is relative, so we just lose the last path component (which
+ // was the link).
+ resolved.erase(resolved.rfind('/'));
+ }
+
+ if (!left.empty()) {
+ const char* maybeSlash = (symlink[symlink.size() - 1] != '/') ? "/" : "";
+ left = symlink + maybeSlash + left;
+ } else {
+ left = symlink;
+ }
+ }
+ }
+
+ // Remove trailing slash except when the resolved pathname is a single "/".
+ if (resolved.size() > 1 && resolved[resolved.size() - 1] == '/') {
+ resolved.erase(resolved.size() - 1, 1);
+ }
+ return true;
+}
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index 774e8cb..16059fe 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -22,11 +22,10 @@ LOCAL_SRC_FILES := \
Register.cpp \
TimeZones.cpp \
cbigint.cpp \
+ ifaddrs-android.cpp \
java_io_Console.cpp \
java_io_File.cpp \
java_io_FileDescriptor.cpp \
- java_io_ObjectInputStream.cpp \
- java_io_ObjectOutputStream.cpp \
java_io_ObjectStreamClass.cpp \
java_lang_Character.cpp \
java_lang_Double.cpp \
@@ -47,11 +46,14 @@ LOCAL_SRC_FILES := \
java_util_zip_Deflater.cpp \
java_util_zip_Inflater.cpp \
libcore_io_IoUtils.cpp \
+ libcore_net_RawSocket.cpp \
org_apache_harmony_luni_platform_OSFileSystem.cpp \
org_apache_harmony_luni_platform_OSMemory.cpp \
org_apache_harmony_luni_platform_OSNetworkSystem.cpp \
org_apache_harmony_luni_util_FloatingPointParser.cpp \
org_apache_harmony_xml_ExpatParser.cpp \
+ readlink.cpp \
+ realpath.cpp \
valueOf.cpp
LOCAL_C_INCLUDES += \
diff --git a/luni/src/main/native/zip.h b/luni/src/main/native/zip.h
index 9909d44..0f3c0c1 100644
--- a/luni/src/main/native/zip.h
+++ b/luni/src/main/native/zip.h
@@ -23,6 +23,7 @@
#include "UniquePtr.h"
#include "jni.h"
#include "zlib.h"
+#include "zutil.h"
static void throwExceptionForZlibError(JNIEnv* env, const char* exceptionClassName, int error) {
if (error == Z_MEM_ERROR) {
diff --git a/luni/src/test/etc/loading-test-jar/README.txt b/luni/src/test/etc/loading-test-jar/README.txt
new file mode 100644
index 0000000..c2fb191
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/README.txt
@@ -0,0 +1,8 @@
+This directory contains the source code for the loading-test jar and
+dex files, which are included as resources in the luni tests. These
+files are used for testing the various class loaders.
+
+The Android build system doesn't support dynamically producing
+resources in any sane way. To update the resource, use the script
+build.sh in this directory, which copies resulting files into the luni
+test resources directory.
diff --git a/luni/src/test/etc/loading-test-jar/Target.java b/luni/src/test/etc/loading-test-jar/Target.java
new file mode 100644
index 0000000..f87144d
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/Target.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package test;
+
+/**
+ * Class which is probed at by the class loading tests.
+ */
+public class Target {
+ public static int staticVariable = 0;
+ public int instanceVariable = 0;
+
+ public Target() {
+ // This space intentionally left blank.
+ }
+
+ public static String blort() {
+ return "blort";
+ }
+
+ public static void setStaticVariable(int n) {
+ staticVariable = n;
+ }
+
+ public String zorch() {
+ return "zorch";
+ }
+
+ public void setInstanceVariable(int n) {
+ instanceVariable = n;
+ }
+}
diff --git a/luni/src/test/etc/loading-test-jar/Test1.java b/luni/src/test/etc/loading-test-jar/Test1.java
new file mode 100644
index 0000000..8296145
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/Test1.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package test;
+
+/**
+ * Class used as part of the class loading tests.
+ */
+public class Test1 {
+ public static String test() {
+ return "blort";
+ }
+}
diff --git a/luni/src/test/etc/loading-test-jar/TestMethods.java b/luni/src/test/etc/loading-test-jar/TestMethods.java
new file mode 100644
index 0000000..fd40163
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/TestMethods.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package test;
+
+import test2.Target2;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Class used as part of the class loading tests. This class uses
+ * other classes, some of which should have come from the same jar/dex
+ * file and others of which should have come from a different jar/dex
+ * file. Each test method in this class is called from the same-named
+ * method in {@code DexClassLoaderTest}.
+ */
+public class TestMethods {
+ /*
+ * The following are all simple utility methods which, under
+ * normal circumstances, would be part of other libraries
+ * (specifically, JUnit and the Android libcore support library).
+ *
+ * However, this file gets compiled as an independent unit without
+ * any dependencies. We could theoretically add dependencies on other
+ * libraries, but that would make things much more complicated and
+ * fragile, and for very little benefit.
+ */
+
+ /**
+ * Simple sameness assertion checker.
+ */
+ public static void assertSame(Object expected, Object actual) {
+ if (expected != actual) {
+ throw new RuntimeException(
+ "EXPECTED: " + expected + "; ACTUAL: " + actual);
+ }
+ }
+
+ /**
+ * Simple sameness assertion checker.
+ */
+ public static void assertSame(int expected, int actual) {
+ if (expected != actual) {
+ throw new RuntimeException(
+ "EXPECTED: " + expected + "; ACTUAL: " + actual);
+ }
+ }
+
+ /**
+ * Fully read the contents of the given stream.
+ */
+ public static byte[] readFully(InputStream in) throws IOException {
+ // This is a copy of the same-named method in libcore.base.Streams.
+ byte[] buffer = new byte[1024];
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ while (true) {
+ int byteCount = in.read(buffer);
+ if (byteCount == -1) {
+ return bytes.toByteArray();
+ }
+ bytes.write(buffer, 0, byteCount);
+ }
+ }
+
+ /*
+ * Test methods that use another class from the same dex/jar file
+ */
+
+ /**
+ * Test that an instance of a sibling class can be constructed.
+ */
+ public static void test_constructor() {
+ new Target();
+ }
+
+ /**
+ * Test calling a static method on a sibling class.
+ */
+ public static void test_callStaticMethod() {
+ assertSame("blort", Target.blort());
+ }
+
+ /**
+ * Test getting a static variable of a sibling class.
+ */
+ public static void test_getStaticVariable() {
+ Target.setStaticVariable(22);
+ assertSame(22, Target.staticVariable);
+ }
+
+ /**
+ * Test calling an instance method on a sibling class.
+ */
+ public static void test_callInstanceMethod() {
+ Target target = new Target();
+ assertSame("zorch", target.zorch());
+ }
+
+ /**
+ * Test getting an instance variable of a sibling class.
+ */
+ public static void test_getInstanceVariable() {
+ Target target = new Target();
+ target.setInstanceVariable(10098);
+ assertSame(10098, target.instanceVariable);
+ }
+
+ /**
+ * Test getting a resource which should be in the same jar
+ * file as this class.
+ */
+ public static void test_getResourceAsStream() throws IOException {
+ ClassLoader cl = TestMethods.class.getClassLoader();
+ InputStream in = cl.getResourceAsStream("test/Resource1.txt");
+ byte[] contents = readFully(in);
+ String s = new String(contents, "UTF-8");
+
+ assertSame("Muffins are tasty!\n", s.intern());
+ }
+
+ /*
+ * Test methods that use a class from a different dex/jar file
+ */
+
+ /**
+ * Test that an instance of a cousin class can be constructed.
+ */
+ public static void test_diff_constructor() {
+ new Target2();
+ }
+
+ /**
+ * Test calling a static method on a cousin class.
+ */
+ public static void test_diff_callStaticMethod() {
+ assertSame("frotz", Target2.frotz());
+ }
+
+ /**
+ * Test getting a static variable of a cousin class.
+ */
+ public static void test_diff_getStaticVariable() {
+ Target2.setStaticIgram(220);
+ assertSame(220, Target2.staticIgram);
+ }
+
+ /**
+ * Test calling an instance method on a cousin class.
+ */
+ public static void test_diff_callInstanceMethod() {
+ Target2 target = new Target2();
+ assertSame("fizmo", target.fizmo());
+ }
+
+ /**
+ * Test getting an instance variable of a cousin class.
+ */
+ public static void test_diff_getInstanceVariable() {
+ Target2 target = new Target2();
+ target.setInstanceMagri(10098);
+ assertSame(10098, target.instanceMagri);
+ }
+
+ /**
+ * Test getting a resource which should be in a different jar
+ * file as this class.
+ */
+ public static void test_diff_getResourceAsStream() throws IOException {
+ ClassLoader cl = TestMethods.class.getClassLoader();
+ InputStream in = cl.getResourceAsStream("test2/Resource2.txt");
+ byte[] contents = readFully(in);
+ String s = new String(contents, "UTF-8");
+
+ assertSame("Who doesn't like a good biscuit?\n", s.intern());
+ }
+}
diff --git a/luni/src/test/etc/loading-test-jar/build.sh b/luni/src/test/etc/loading-test-jar/build.sh
new file mode 100755
index 0000000..4737f14
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/build.sh
@@ -0,0 +1,56 @@
+#!/bin/bash -e
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set up prog to be the path of this script, including following
+# symlinks, and set up progdir to be the fully-qualified pathname of
+# its directory. Switch the current directory to progdir for the
+# remainder of the script.
+prog="$0"
+while [ -h "${prog}" ]; do
+ newProg=`/bin/ls -ld "${prog}"`
+ newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+ if expr "x${newProg}" : 'x/' >/dev/null; then
+ prog="${newProg}"
+ else
+ progdir=`dirname "${prog}"`
+ prog="${progdir}/${newProg}"
+ fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+
+resourceDir=../../resources/dalvik/system
+
+rm -rf classes
+rm -rf classes2
+rm -rf classes.dex
+rm -rf loading-test.jar
+
+# This library depends on loading-test2, so compile those classes first,
+# but keep them separate.
+mkdir classes2
+javac -d classes2 ../loading-test2-jar/*.java
+
+mkdir classes
+javac -classpath classes2 -d classes *.java
+dx --dex --output=classes.dex classes
+jar cf loading-test.jar classes.dex -C resources .
+
+rm -rf classes
+rm -rf classes2
+mv classes.dex ${resourceDir}/loading-test.dex
+mv loading-test.jar ${resourceDir}
diff --git a/luni/src/test/etc/loading-test-jar/resources/test/Resource1.txt b/luni/src/test/etc/loading-test-jar/resources/test/Resource1.txt
new file mode 100644
index 0000000..fef87fc
--- /dev/null
+++ b/luni/src/test/etc/loading-test-jar/resources/test/Resource1.txt
@@ -0,0 +1 @@
+Muffins are tasty!
diff --git a/luni/src/test/etc/loading-test2-jar/README.txt b/luni/src/test/etc/loading-test2-jar/README.txt
new file mode 100644
index 0000000..e1d8bbb
--- /dev/null
+++ b/luni/src/test/etc/loading-test2-jar/README.txt
@@ -0,0 +1,8 @@
+This directory contains the source code for the loading-test2 jar and
+dex files, which are included as resources in the luni tests. These
+files are used for testing the various class loaders.
+
+The Android build system doesn't support dynamically producing
+resources in any sane way. To update the resource, use the script
+build.sh in this directory, which copies resulting files into the luni
+test resources directory.
diff --git a/luni/src/test/etc/loading-test2-jar/Target2.java b/luni/src/test/etc/loading-test2-jar/Target2.java
new file mode 100644
index 0000000..072a27e
--- /dev/null
+++ b/luni/src/test/etc/loading-test2-jar/Target2.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package test2;
+
+/**
+ * Class which is probed at by the class loading tests.
+ */
+public class Target2 {
+ public static int staticIgram = 0;
+ public int instanceMagri = 0;
+
+ public Target2() {
+ // This space intentionally left blank.
+ }
+
+ public static String frotz() {
+ return "frotz";
+ }
+
+ public static void setStaticIgram(int n) {
+ staticIgram = n;
+ }
+
+ public String fizmo() {
+ return "fizmo";
+ }
+
+ public void setInstanceMagri(int n) {
+ instanceMagri = n;
+ }
+}
diff --git a/luni/src/test/etc/loading-test2-jar/build.sh b/luni/src/test/etc/loading-test2-jar/build.sh
new file mode 100755
index 0000000..0d98a2a
--- /dev/null
+++ b/luni/src/test/etc/loading-test2-jar/build.sh
@@ -0,0 +1,49 @@
+#!/bin/bash -e
+#
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Set up prog to be the path of this script, including following
+# symlinks, and set up progdir to be the fully-qualified pathname of
+# its directory. Switch the current directory to progdir for the
+# remainder of the script.
+prog="$0"
+while [ -h "${prog}" ]; do
+ newProg=`/bin/ls -ld "${prog}"`
+ newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
+ if expr "x${newProg}" : 'x/' >/dev/null; then
+ prog="${newProg}"
+ else
+ progdir=`dirname "${prog}"`
+ prog="${progdir}/${newProg}"
+ fi
+done
+oldwd=`pwd`
+progdir=`dirname "${prog}"`
+cd "${progdir}"
+
+resourceDir=../../resources/dalvik/system
+
+rm -rf classes
+rm -rf classes.dex
+rm -rf loading-test2.jar
+
+mkdir classes
+javac -d classes *.java
+dx --dex --output=classes.dex classes
+jar cf loading-test2.jar classes.dex -C resources .
+
+rm -rf classes
+mv classes.dex ${resourceDir}/loading-test2.dex
+mv loading-test2.jar ${resourceDir}
diff --git a/luni/src/test/etc/loading-test2-jar/resources/test2/Resource2.txt b/luni/src/test/etc/loading-test2-jar/resources/test2/Resource2.txt
new file mode 100644
index 0000000..82f5c2d
--- /dev/null
+++ b/luni/src/test/etc/loading-test2-jar/resources/test2/Resource2.txt
@@ -0,0 +1 @@
+Who doesn't like a good biscuit?
diff --git a/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java b/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java
new file mode 100644
index 0000000..d2247cf
--- /dev/null
+++ b/luni/src/test/java/com/android/org/bouncycastle/crypto/digests/DigestTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.org.bouncycastle.crypto.digests;
+
+import junit.framework.TestCase;
+import com.android.org.bouncycastle.crypto.Digest;
+import com.android.org.bouncycastle.crypto.ExtendedDigest;
+
+/**
+ * Implements unit tests for our JNI wrapper around OpenSSL. We use the
+ * existing Bouncy Castle implementation as our test oracle.
+ */
+public class DigestTest extends TestCase {
+
+ /**
+ * Processes the two given message digests for the same data and checks
+ * the results. Requirement is that the results must be equal, the digest
+ * implementations must have the same properties, and the new implementation
+ * must be faster than the old one.
+ *
+ * @param oldDigest The old digest implementation, provided by Bouncy Castle
+ * @param newDigest The new digest implementation, provided by OpenSSL
+ */
+ public void doTestMessageDigest(Digest oldDigest, Digest newDigest) {
+ final int ITERATIONS = 10;
+
+ byte[] data = new byte[1024];
+
+ byte[] oldHash = new byte[oldDigest.getDigestSize()];
+ byte[] newHash = new byte[newDigest.getDigestSize()];
+
+ assertEquals("Hash names must be equal",
+ oldDigest.getAlgorithmName(), newDigest.getAlgorithmName());
+ assertEquals("Hash sizes must be equal",
+ oldHash.length, newHash.length);
+ assertEquals("Hash block sizes must be equal",
+ ((ExtendedDigest)oldDigest).getByteLength(),
+ ((ExtendedDigest)newDigest).getByteLength());
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte)i;
+ }
+
+ long oldTime = 0;
+ long newTime = 0;
+
+ for (int j = 0; j < ITERATIONS; j++) {
+ long t0 = System.currentTimeMillis();
+ for (int i = 0; i < 4; i++) {
+ oldDigest.update(data, 0, data.length);
+ }
+ int oldLength = oldDigest.doFinal(oldHash, 0);
+ long t1 = System.currentTimeMillis();
+
+ oldTime = oldTime + (t1 - t0);
+
+ long t2 = System.currentTimeMillis();
+ for (int i = 0; i < 4; i++) {
+ newDigest.update(data, 0, data.length);
+ }
+ int newLength = newDigest.doFinal(newHash, 0);
+ long t3 = System.currentTimeMillis();
+
+ newTime = newTime + (t3 - t2);
+
+ assertEquals("Hash sizes must be equal", oldLength, newLength);
+
+ for (int i = 0; i < oldLength; i++) {
+ assertEquals("Hashes[" + i + "] must be equal", oldHash[i], newHash[i]);
+ }
+ }
+
+ System.out.println("Time for " + ITERATIONS + " x old hash processing: " + oldTime + " ms");
+ System.out.println("Time for " + ITERATIONS + " x new hash processing: " + newTime + " ms");
+
+ assertTrue("New hash should be faster", newTime < oldTime);
+ }
+
+ /**
+ * Tests the MD5 implementation.
+ */
+ public void testMD5() {
+ Digest oldDigest = new MD5Digest();
+ Digest newDigest = new OpenSSLDigest.MD5();
+ doTestMessageDigest(oldDigest, newDigest);
+ }
+
+ /**
+ * Tests the SHA-1 implementation.
+ */
+ public void testSHA1() {
+ Digest oldDigest = new SHA1Digest();
+ Digest newDigest = new OpenSSLDigest.SHA1();
+ doTestMessageDigest(oldDigest, newDigest);
+ }
+
+ /**
+ * Tests the SHA-256 implementation.
+ */
+ public void testSHA256() {
+ Digest oldDigest = new SHA256Digest();
+ Digest newDigest = new OpenSSLDigest.SHA256();
+ doTestMessageDigest(oldDigest, newDigest);
+ }
+
+ /**
+ * Tests the SHA-384 implementation.
+ */
+ public void testSHA384() {
+ Digest oldDigest = new SHA384Digest();
+ Digest newDigest = new OpenSSLDigest.SHA384();
+ doTestMessageDigest(oldDigest, newDigest);
+ }
+
+ /**
+ * Tests the SHA-512 implementation.
+ */
+ public void testSHA512() {
+ Digest oldDigest = new SHA512Digest();
+ Digest newDigest = new OpenSSLDigest.SHA512();
+ doTestMessageDigest(oldDigest, newDigest);
+ }
+}
diff --git a/luni/src/test/java/com/android/org/bouncycastle/jce/provider/AllTests.java b/luni/src/test/java/com/android/org/bouncycastle/jce/provider/AllTests.java
new file mode 100644
index 0000000..3ec53a4
--- /dev/null
+++ b/luni/src/test/java/com/android/org/bouncycastle/jce/provider/AllTests.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.org.bouncycastle.jce.provider;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class AllTests {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("All tests for " + AllTests.class.getPackage());
+ suite.addTestSuite(PKIXCertPathValidatorSpiTest.class);
+ return suite;
+ }
+}
diff --git a/luni/src/test/java/com/android/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java b/luni/src/test/java/com/android/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
new file mode 100644
index 0000000..e89aede
--- /dev/null
+++ b/luni/src/test/java/com/android/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.org.bouncycastle.jce.provider;
+
+import com.android.org.bouncycastle.asn1.ASN1InputStream;
+import com.android.org.bouncycastle.asn1.ASN1Sequence;
+import com.android.org.bouncycastle.asn1.x509.X509CertificateStructure;
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStoreException;
+import java.security.cert.CertPathValidatorException;
+import java.security.cert.CertificateException;
+import java.security.cert.TrustAnchor;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import junit.framework.TestCase;
+import org.apache.harmony.security.provider.cert.X509CertImpl;
+import org.apache.harmony.security.provider.cert.X509CertPathImpl;
+import org.apache.harmony.xnet.provider.jsse.IndexedPKIXParameters;
+
+/**
+ * Verify the behavior of PKIXCertPathValidatorSpi.
+ */
+public class PKIXCertPathValidatorSpiTest extends TestCase {
+
+ /**
+ * A chain of 3 ASN1-encoded certificates for https://service.sprint.com.
+ * The certificate subjects are "service.sprint.com", "Entrust Certification
+ * Authority - L1B", and "Entrust.net Certification Authority (2048)". The
+ * last certificate uses UTF8 encoding for its X509 name.
+ */
+ private final byte[][] serviceSprintComCertChain = new byte[][] {
+ new byte[] { 48, -126, 6, 89, 48, -126, 5, 65, -96, 3, 2, 1, 2, 2, 4, 72, 13, 115, -81, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, 30, 23, 13, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, 23, 13, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 120, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 15, 48, 13, 6, 3, 85, 4, 8, 19, 6, 75, 65, 78, 83, 65, 83, 49, 22, 48, 20, 6, 3, 85, 4, 7, 19, 13, 79, 118, 101, 114, 108, 97, 110, 100, 32, 80, 97, 114, 107, 49, 15, 48, 13, 6, 3, 85, 4, 10, 19, 6, 83, 112, 114, 105, 110, 116, 49, 18, 48, 16, 6, 3, 85, 4, 11, 19, 9, 100, 97, 115, 110, 109, 112, 48, 52, 98, 49, 27, 48, 25, 6, 3, 85, 4, 3, 19, 18, 115, 101, 114, 118, 105, 99, 101, 46, 115, 112, 114, 105, 110, 116, 46, 99, 111, 109, 48, -127, -97, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -127, -115, 0, 48, -127, -119, 2, -127, -127, 0, -80, 99, 109, 108, 94, -41, -78, 88, 56, -97, 33, -23, 65, -74, -118, 0, 1, 119, 126, 122, -59, -83, -25, -16, -75, -87, 100, 46, 37, -98, 65, -104, 54, -87, 56, -81, 96, -38, -4, -78, 11, 101, -29, 70, -13, -110, -76, -125, -106, -35, 41, 83, 71, 56, 6, 67, -8, 82, -58, -81, -113, 90, 91, 79, 74, -38, 34, 28, 39, -37, -12, 54, 87, 61, 48, 33, -16, 10, 112, -40, -37, -15, 59, -72, 112, 96, 85, 109, 123, -122, 58, 18, 95, 56, -81, 49, 43, -39, 99, 69, -28, -81, -106, -64, 8, -62, 40, -92, 95, -109, -122, 94, 53, -13, -33, 88, -104, 3, -77, -30, -27, 23, 92, -69, 12, -23, -9, 125, 2, 3, 1, 0, 1, -93, -126, 2, -81, 48, -126, 2, -85, 48, 11, 6, 3, 85, 29, 15, 4, 4, 3, 2, 5, -96, 48, 43, 6, 3, 85, 29, 16, 4, 36, 48, 34, -128, 15, 50, 48, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, -127, 15, 50, 48, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 19, 6, 3, 85, 29, 37, 4, 12, 48, 10, 6, 8, 43, 6, 1, 5, 5, 7, 3, 1, 48, 51, 6, 3, 85, 29, 31, 4, 44, 48, 42, 48, 40, -96, 38, -96, 36, -122, 34, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 108, 101, 118, 101, 108, 49, 98, 46, 99, 114, 108, 48, 100, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 88, 48, 86, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 47, 6, 8, 43, 6, 1, 5, 5, 7, 48, 2, -122, 35, 104, 116, 116, 112, 58, 47, 47, 97, 105, 97, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 45, 108, 49, 98, 46, 99, 101, 114, 48, -126, 1, 87, 6, 3, 85, 29, 32, 4, -126, 1, 78, 48, -126, 1, 74, 48, -126, 1, 70, 6, 9, 42, -122, 72, -122, -10, 125, 7, 75, 2, 48, -126, 1, 55, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 48, -126, 1, 11, 6, 8, 43, 6, 1, 5, 5, 7, 2, 2, 48, -127, -2, 26, -127, -5, 84, 104, 101, 32, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 80, 114, 97, 99, 116, 105, 99, 101, 32, 83, 116, 97, 116, 101, 109, 101, 110, 116, 32, 40, 67, 80, 83, 41, 32, 97, 118, 97, 105, 108, 97, 98, 108, 101, 32, 97, 116, 32, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 32, 32, 105, 115, 32, 104, 101, 114, 101, 98, 121, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 105, 110, 116, 111, 32, 121, 111, 117, 114, 32, 117, 115, 101, 32, 111, 114, 32, 114, 101, 108, 105, 97, 110, 99, 101, 32, 111, 110, 32, 116, 104, 105, 115, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 46, 32, 32, 84, 104, 105, 115, 32, 67, 80, 83, 32, 99, 111, 110, 116, 97, 105, 110, 115, 32, 108, 105, 109, 105, 116, 97, 116, 105, 111, 110, 115, 32, 111, 110, 32, 119, 97, 114, 114, 97, 110, 116, 105, 101, 115, 32, 97, 110, 100, 32, 108, 105, 97, 98, 105, 108, 105, 116, 105, 101, 115, 46, 32, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 32, 76, 105, 109, 105, 116, 101, 100, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 68, 101, 26, -23, -69, -107, 32, 89, 18, 28, -123, 32, 74, -116, -33, -48, 70, -52, 68, 77, 48, 9, 6, 3, 85, 29, 19, 4, 2, 48, 0, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 3, 40, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 18, 56, 92, -74, -100, -56, 95, 121, 27, -84, -88, -104, -27, -98, -12, 58, 48, -26, 40, -7, 25, -68, -124, -104, -54, -121, 84, 52, 3, 22, -106, 88, 44, -39, 126, 17, 96, 4, -41, -84, -101, 74, -92, -113, -12, -99, 77, 108, -30, 38, 19, 78, 48, 32, -126, 95, -10, -114, 58, 98, -49, -108, -109, -87, 5, -80, -43, 121, 21, -99, 43, -73, 26, 51, 31, 87, -38, -119, 78, -113, -59, -100, -118, -84, -46, -48, 93, 99, 2, 40, -39, 76, -48, -122, -60, -25, -73, 103, 126, 83, -86, -26, 66, 122, -65, -89, -102, 115, 105, -124, -85, -18, -66, 85, 30, -29, -96, 104, 65, -66, 40, 69, -91, 101, -19, 39, -86, -21, -18, 39, 51, -1, 36, -52, 53, -65, 53, 12, -62, -97, -45, -26, 113, -20, 102, 56, 102, 104, 37, 17, 57, -96, -83, -71, 106, 63, -64, -122, 61, 59, 8, -123, 108, 22, 62, -58, -105, 88, 38, 96, -6, -29, -114, 105, 110, -102, -72, 109, -33, 56, 61, 52, 70, -75, -92, 97, -9, -6, -64, 53, -76, 81, -100, 90, -50, 19, -87, 30, -24, -53, 109, -75, 45, -38, 14, 119, -31, 44, -30, -93, -76, 14, 97, -53, -107, 60, 30, -102, 68, 12, 26, 76, -114, 73, -13, -127, 21, 94, -42, 94, 30, -50, -3, 116, 41, -3, -89, 23, -27, -49, -3, -95, 119, -104, -45, 112, 35, 66, 59, 84, 116, 19, -102, -68, -104, 1 },
+ new byte[] { 48, -126, 5, -111, 48, -126, 4, 121, -96, 3, 2, 1, 2, 2, 4, 56, 99, -59, -82, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 48, 56, 48, 56, 50, 53, 49, 56, 49, 52, 50, 54, 90, 23, 13, 49, 56, 48, 56, 50, 53, 49, 56, 52, 52, 50, 54, 90, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -36, 33, -11, 104, -7, 122, -50, -121, -14, 120, -33, -40, 59, 77, 6, 125, -58, 36, -28, -87, -51, -99, 1, 86, -28, -10, 113, 23, -86, 127, 117, 34, 24, -28, 116, 109, 27, 62, 86, -43, -79, -90, 30, -35, 89, 38, 83, -54, 6, -26, -70, 11, 111, 55, -69, -88, -58, -100, 21, 59, 6, 27, -121, 12, -62, 26, 77, -45, -127, -82, -37, 80, 101, -91, 58, 100, 79, 48, 52, -102, 43, -87, 31, -3, 43, -47, 56, 113, 25, 104, -14, -114, -21, 123, -55, 64, 60, 72, -60, 25, -79, -73, 16, 37, -17, 68, -89, -26, 119, -101, 125, 34, -102, -34, -40, 94, -39, -61, -50, -55, 113, 34, -69, -82, -17, 5, -42, -14, 23, -25, 86, 120, -31, 83, 5, 74, 38, 115, -72, -57, 73, 103, -109, 35, 15, 86, -78, -113, -35, -55, 89, 5, -27, 99, 21, -76, -121, 126, 64, 70, -23, -75, 0, 123, 3, -76, 13, -28, -106, 103, 44, -34, 27, 89, 11, 26, 31, -72, 99, 68, -82, -63, -41, 68, -121, -60, -111, 89, -100, 0, 67, 109, -58, -33, 10, -80, -79, 4, -51, -2, -66, 48, 94, 58, 37, 114, -35, -94, 62, -19, 70, 58, -57, -92, 92, 92, -28, 37, -14, 19, 7, -24, -82, -38, -101, 25, -101, -94, -39, 96, -99, -50, -112, 71, 106, 97, 123, 64, -24, 20, -62, -2, 47, -124, 90, 102, 23, -64, -105, -45, 73, 56, -34, 99, 2, -97, 2, 3, 1, 0, 1, -93, -126, 1, 38, 48, -126, 1, 34, 48, 14, 6, 3, 85, 29, 15, 1, 1, -1, 4, 4, 3, 2, 1, 6, 48, 15, 6, 3, 85, 29, 19, 1, 1, -1, 4, 5, 48, 3, 1, 1, -1, 48, 51, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 39, 48, 37, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 50, 6, 3, 85, 29, 31, 4, 43, 48, 41, 48, 39, -96, 37, -96, 35, -122, 33, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 99, 97, 46, 99, 114, 108, 48, 59, 6, 3, 85, 29, 32, 4, 52, 48, 50, 48, 48, 6, 4, 85, 29, 32, 0, 48, 40, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 0, -127, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 11, 37, 60, 88, -6, -114, -36, -94, 66, 59, 118, 113, 110, 108, -44, 79, 43, -71, 83, 92, -78, 88, -71, -79, -36, 111, 26, -28, -29, -60, 80, -14, 65, -126, -70, -12, 125, -57, -63, -7, -6, -116, 83, -65, -71, 98, -73, 73, -29, 29, 10, -4, 31, -42, -60, 118, 106, -109, -53, 119, 30, 44, 127, -48, 63, 22, 99, 76, 114, 76, 103, 96, 15, -8, -128, -42, -89, -102, -54, -94, 51, -111, 15, 68, -78, 102, 61, -114, 104, 12, 64, -123, 18, 55, -111, -71, -126, 119, 52, 89, 45, 92, -33, -126, 110, 44, -74, 122, -46, 4, -112, 103, 104, 75, 112, -4, 45, -72, -1, -112, 100, 111, 126, -111, -9, -47, 71, 51, -13, 91, -72, 88, 46, 33, -40, 117, 96, 27, 19, -52, -8, -78, -88, -6, 106, -87, 42, 90, 79, 69, -123, 64, -76, -35, 52, 5, -73, 112, -54, 1, -17, -31, -127, -25, 17, 80, -37, 62, -30, -41, 16, 46, 106, 21, 127, -73, -44, -93, 98, -78, -119, 105, 97, 87, -58, 127, -114, -98, -44, 36, 122, -13, -95, 67, 95, -96, 122, -119, -36, 89, -51, 125, -41, 117, -89, -68, 83, -43, 71, 53, -58, 49, 48, 32, -97, -101, -70, -75, -125, -26, -119, 85, 1, 77, -111, 59, -42, -119, 53, -121, 60, -125, 107, 122, 41, -126, -44, 75, -44, -26, 22, 116, -80, 1, 16, -85, 105, 6, 20, 55, 123, -9, 102, 48, 58, -59 },
+ new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 },
+ };
+
+ /**
+ * ASN1-encoded trusted certificate #946059622 for Entrust.net. This
+ * certificate uses the TELETEX encoding for its X509 name.
+ */
+ private final byte[] trustedCert = new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 };
+
+ public void testTrustAndRemoteCertificatesWithDifferentEncodings()
+ throws IOException, CertificateException, KeyStoreException,
+ InvalidAlgorithmParameterException, CertPathValidatorException {
+
+ X509CertPathImpl certPath = new X509CertPathImpl(Arrays.asList(
+ new X509CertImpl(serviceSprintComCertChain[0]),
+ new X509CertImpl(serviceSprintComCertChain[1]),
+ new X509CertImpl(serviceSprintComCertChain[2])));
+
+ Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
+ trustAnchors.add(new TrustAnchor(new X509CertificateObject(
+ new X509CertificateStructure(
+ (ASN1Sequence) new ASN1InputStream(trustedCert).readObject())), null));
+
+ IndexedPKIXParameters indexedPKIXParameters = new IndexedPKIXParameters(trustAnchors);
+ indexedPKIXParameters.setRevocationEnabled(false);
+
+ new PKIXCertPathValidatorSpi().engineValidate(certPath, indexedPKIXParameters);
+ // completing normally indicates that the certificate was valid
+ }
+}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestDummy.java b/luni/src/test/java/com/google/coretests/CoreTestDummy.java
deleted file mode 100644
index 4e1400d..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestDummy.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import junit.framework.TestCase;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.SideEffect;
-
-/**
- * A dummy test for testing our CoreTestRunner.
- */
-public class CoreTestDummy extends TestCase {
-
- @AndroidOnly("")
- public void testAndroidOnlyPass() {
- }
-
- @AndroidOnly("")
- public void testAndroidOnlyFail() {
- fail("Oops!");
- }
-
- @BrokenTest("")
- public void testBrokenTestPass() {
- }
-
- @BrokenTest("")
- public void testBrokenTestFail() {
- fail("Oops!");
- }
-
- @KnownFailure("")
- public void testKnownFailurePass() {
- }
-
- @KnownFailure("")
- public void testKnownFailureFail() {
- fail("Oops!");
- }
-
- @SideEffect("")
- public void testSideEffectPass() {
- }
-
- @SideEffect("")
- public void testSideEffectFail() {
- fail("Oops!");
- }
-
- public void testNormalPass() {
- }
-
- public void testNormalFail() {
- fail("Oops!");
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestIsolator.java b/luni/src/test/java/com/google/coretests/CoreTestIsolator.java
deleted file mode 100644
index 53b2fdf..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestIsolator.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import junit.framework.Test;
-import junit.framework.TestFailure;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * A minimalistic TestRunner implementation that silently executes a single test
- * method and writes a possible stack trace to a temporary file. Used for
- * isolating tests.
- */
-public class CoreTestIsolator extends TestRunner {
-
- /**
- * Creates a new CoreTestIsolator. The superclass needs to be able to build
- * a proper ResultPrinter, so we pass it a null device for printing stuff.
- */
- public CoreTestIsolator() {
- super(new PrintStream(new OutputStream() {
- @Override
- public void write(int oneByte) throws IOException {
- // Null device
- }
- }));
- }
-
- @Override
- protected TestResult createTestResult() {
- return new TestResult();
- }
-
- /**
- * Provides the main entry point. First and second argument are class and
- * method name, respectively. Third argument is the temporary file name for
- * the result. Exits with one of the usual JUnit exit values.
- */
- public static void main(String args[]) {
- Logger.global.setLevel(Level.OFF);
-
- CoreTestIsolator testRunner = new CoreTestIsolator();
- try {
- TestResult r = testRunner.start(args);
-
- if (!r.wasSuccessful()) {
- // Store failure or error - we know there must be one
- Throwable failure = r.failureCount() != 0 ?
- ((TestFailure)r.failures().nextElement()).
- thrownException() :
- ((TestFailure)r.errors().nextElement()).
- thrownException();
-
- saveStackTrace(failure, args[2]);
-
- System.exit(FAILURE_EXIT);
- } else {
- // Nothing to see here, please get along
- System.exit(SUCCESS_EXIT);
- }
- } catch(Exception e) {
- // Let main TestRunner know about execution problem
- saveStackTrace(e, args[2]);
- System.exit(EXCEPTION_EXIT);
- }
-
- }
-
- /**
- * Saves a given stack trace to a given file.
- */
- private static void saveStackTrace(Throwable throwable, String fileName) {
- try {
- FileOutputStream fos = new FileOutputStream(fileName);
- ObjectOutputStream oos = new ObjectOutputStream(fos);
-
- oos.writeObject(throwable);
-
- oos.flush();
- oos.close();
- } catch (IOException ex) {
- // Ignore
- }
- }
-
- @Override
- protected TestResult start(String args[]) {
- try {
- Test suite = TestSuite.createTest(Class.forName(args[0]), args[1]);
- return doRun(suite);
- }
- catch(Exception e) {
- throw new RuntimeException("Unable to launch test", e);
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestPrinter.java b/luni/src/test/java/com/google/coretests/CoreTestPrinter.java
deleted file mode 100644
index acfabcc..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestPrinter.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.io.PrintStream;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.textui.ResultPrinter;
-
-/**
- * A special ResultPrinter implementation that displays additional statistics
- * about the test that have been executed.
- */
-public class CoreTestPrinter extends ResultPrinter {
-
- /**
- * The last test class we executed.
- */
- private Class<?> fLastClass;
-
- /**
- * The current output column for dots.
- */
- private int fColumn;
-
- /**
- * The time it took to execute the tests.
- */
- private int fRunTime;
-
- /**
- * The flags the user specified.
- */
- private int fFlags;
-
- /**
- * Creates a new CoreTestPrinter for the given parameters.
- */
- public CoreTestPrinter(PrintStream writer, int flags) {
- super(writer);
- fFlags = flags;
- }
-
- @Override
- protected void printHeader(long runTime) {
- fRunTime = (int)(runTime / 1000);
-
- if (fColumn != 0) {
- getWriter().println();
- }
-
- getWriter().println();
- }
-
- @Override
- protected void printFooter(TestResult result) {
- CoreTestResult coreResult = (CoreTestResult)result;
-
- PrintStream printer = getWriter();
-
- if (fColumn != 0) {
- printer.println();
- }
-
- printer.println();
- printer.println("Total tests : " + coreResult.fTotalTestCount);
- printer.println("Tests run : " + coreResult.runCount());
- printer.println("Tests ignored : " + coreResult.fIgnoredCount);
-
- printer.println();
- printer.println("Normal tests : " + coreResult.fNormalTestCount);
- printer.println("Android-only : " + coreResult.fAndroidOnlyCount);
- printer.println("Broken tests : " + coreResult.fBrokenTestCount);
- printer.println("Known failures: " + coreResult.fKnownFailureCount);
- printer.println("Side-effects : " + coreResult.fSideEffectCount);
-
- printMemory();
-
- int seconds = fRunTime;
-
- int hours = seconds / 3600;
- seconds = seconds % 3600;
-
- int minutes = seconds / 60;
- seconds = seconds % 60;
-
- String text = String.format("%02d:%02d:%02d", hours, minutes, seconds);
-
- printer.println();
- printer.println("Time taken : " + text);
-
- super.printFooter(result);
- }
-
- /**
- * Dumps some memory info.
- */
- private void printMemory() {
- PrintStream printer = getWriter();
- Runtime runtime = Runtime.getRuntime();
-
- long total = runtime.totalMemory();
- long free = runtime.freeMemory();
- long used = total - free;
-
- printer.println();
- printer.println("Total memory : " + total);
- printer.println("Used memory : " + used);
- printer.println("Free memory : " + free);
- }
-
- @Override
- public void startTest(Test test) {
- TestCase caze = (TestCase)test;
-
- if (fLastClass == null ||
- caze.getClass().getPackage() != fLastClass.getPackage()) {
-
- if (fColumn != 0) {
- getWriter().println();
- fColumn = 0;
- }
-
- getWriter().println();
- Package pack = caze.getClass().getPackage();
- getWriter().println(pack == null ? "Default package" :
- pack.getName());
- getWriter().println();
-
- }
-
- if ((fFlags & CoreTestSuite.VERBOSE) != 0) {
- if (caze.getClass() != fLastClass) {
- if (fColumn != 0) {
- getWriter().println();
- fColumn = 0;
- }
-
- String name = caze.getClass().getSimpleName().toString();
-
- printMemory();
- getWriter().println("Now executing : " + name);
- getWriter().println();
- }
- }
-
- getWriter().print(".");
- if (fColumn++ >= 40) {
- getWriter().println();
- fColumn= 0;
- }
-
- fLastClass = caze.getClass();
- }
-
- @Override
- public void addError(Test test, Throwable t) {
- if (t instanceof CoreTestTimeout) {
- getWriter().print("T");
- } else {
- super.addError(test, t);
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestResult.java b/luni/src/test/java/com/google/coretests/CoreTestResult.java
deleted file mode 100644
index 02267fa..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestResult.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.lang.reflect.Method;
-
-import junit.framework.Protectable;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.SideEffect;
-
-/**
- * A special TestResult implementation that is able to filter out annotated
- * tests and handles our known failures properly (expects them to fail).
- * Handy when running the Core Libraries tests on Android, the bare-metal
- * Dalvik VM, or the RI.
- */
-public class CoreTestResult extends TestResult {
-
- /**
- * The flags the user specified for this test run.
- */
- protected int fFlags;
-
- /**
- * The timeout the user specified for this test run.
- */
- protected int fTimeout;
-
- /**
- * The total number of tests in the original suite.
- */
- protected int fTotalTestCount;
-
- /**
- * The number of Android-only tests in the original suite.
- */
- protected int fAndroidOnlyCount;
-
- /**
- * The number of broken tests in the original suite.
- */
- protected int fBrokenTestCount;
-
- /**
- * The number of known failures in the original suite.
- */
- protected int fKnownFailureCount;
-
- /**
- * The number of side-effective tests in the original suite.
- */
- protected int fSideEffectCount;
-
- /**
- * The number of normal (non-annotated) tests in the original suite.
- */
- protected int fNormalTestCount;
-
- /**
- * The number of ignored tests, that is, the number of tests that were
- * excluded from this suite due to their annotations.
- */
- protected int fIgnoredCount;
-
- /**
- * Creates a new CoreTestResult with the given flags and timeout.
- */
- public CoreTestResult(int flags, int timeout) {
- super();
-
- fFlags = flags;
- fTimeout = timeout;
- }
-
- /**
- * Checks whether the given TestCase method has the given annotation.
- */
- @SuppressWarnings("unchecked")
- boolean hasAnnotation(TestCase test, Class clazz) {
- try {
- Method method = test.getClass().getMethod(test.getName());
- return method.getAnnotation(clazz) != null;
- } catch (Exception e) {
- // Ignore
- }
-
- return false;
- }
-
- @Override
- @SuppressWarnings("deprecation")
- public void runProtected(final Test test, Protectable p) {
- if ((fFlags & CoreTestSuite.DRY_RUN) == 0) {
- if (test instanceof TestCase) {
- TestCase testCase = (TestCase)test;
-
- // Check whether we need to invert the test result (known failures)
- boolean invert = hasAnnotation(testCase, KnownFailure.class) &&
- (fFlags & CoreTestSuite.INVERT_KNOWN_FAILURES) != 0;
-
- // Check whether we need to isolate the test (side effects)
- boolean isolate = hasAnnotation(testCase, SideEffect.class) &&
- (fFlags & CoreTestSuite.ISOLATE_NONE) == 0 ||
- (fFlags & CoreTestSuite.ISOLATE_ALL) != 0;
-
- CoreTestRunnable runnable = new CoreTestRunnable(
- testCase, this, p, invert, isolate);
-
- if (fTimeout > 0) {
- Thread thread = new Thread(runnable);
- thread.start();
- try {
- thread.join(fTimeout * 1000);
- } catch (InterruptedException ex) {
- // Ignored
- }
- if (thread.isAlive()) {
- StackTraceElement[] trace = thread.getStackTrace();
- runnable.stop();
- thread.stop();
- try {
- thread.join(fTimeout * 1000);
- } catch (InterruptedException ex) {
- // Ignored
- }
-
- CoreTestTimeout timeout = new CoreTestTimeout("Test timed out");
- timeout.setStackTrace(trace);
- addError(test, timeout);
- }
- } else {
- runnable.run();
- }
- }
- }
- }
-
- /**
- * Updates the statistics in this TestResult. Called from the TestSuite,
- * since, once the original suite has been filtered, we don't actually see
- * these tests here anymore.
- */
- void updateStats(int total, int androidOnly, int broken, int knownFailure,
- int normal, int ignored, int sideEffect) {
-
- this.fTotalTestCount += total;
- this.fAndroidOnlyCount += androidOnly;
- this.fBrokenTestCount += broken;
- this.fKnownFailureCount += knownFailure;
- this.fNormalTestCount += normal;
- this.fIgnoredCount += ignored;
- this.fSideEffectCount += sideEffect;
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestRunnable.java b/luni/src/test/java/com/google/coretests/CoreTestRunnable.java
deleted file mode 100644
index 177a291..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestRunnable.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Protectable;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-import junit.textui.TestRunner;
-
-/**
- * A wrapper around a single test that allows to execute the test either in the
- * same thread, in a separate thread, or even in a different process.
- */
-public class CoreTestRunnable implements Runnable {
-
- private static boolean IS_DALVIK = "Dalvik".equals(
- System.getProperty("java.vm.name"));
-
- /**
- * The test case we are supposed to run.
- */
- private TestCase fTest;
-
- /**
- * The TestResult we need to update after the run.
- */
- private TestResult fResult;
-
- /**
- * The Protectable that JUnit has created for us.
- */
- private Protectable fProtectable;
-
- /**
- * Reflects whether we need to invert the test result, which is used for
- * treating known failures.
- */
- private boolean fInvert;
-
- /**
- * Reflects whether we need to isolate the test, which means we run it in
- * a separate process.
- */
- private boolean fIsolate;
-
- /**
- * If we are isolating the test case, this holds the process that is running
- * it.
- */
- private Process fProcess;
-
- /**
- * Creates a new CoreTestRunnable for the given parameters.
- */
- public CoreTestRunnable(TestCase test, TestResult result,
- Protectable protectable, boolean invert, boolean isolate) {
-
- this.fTest = test;
- this.fProtectable = protectable;
- this.fResult = result;
- this.fInvert = invert;
- this.fIsolate = isolate;
- }
-
- /**
- * Executes the test and stores the results. May be run from a secondary
- * Thread.
- */
- public void run() {
- try {
- if (fIsolate) {
- runExternally();
- } else {
- runInternally();
- }
-
- if (fInvert) {
- fInvert = false;
- throw new AssertionFailedError(
- "@KnownFailure expected to fail, but succeeded");
- }
- } catch (AssertionFailedError e) {
- if (!fInvert) {
- fResult.addFailure(fTest, e);
- }
- } catch (ThreadDeath e) { // don't catch ThreadDeath by accident
- throw e;
- } catch (Throwable e) {
- if (!fInvert) {
- fResult.addError(fTest, e);
- }
- }
- }
-
- /**
- * Tells the test case to stop. Only used with isolation. We need to kill
- * the external process in this case.
- */
- public void stop() {
- if (fProcess != null) {
- fProcess.destroy();
- }
- }
-
- /**
- * Runs the test case in the same process. This is basically what a
- * run-of-the-mill JUnit does, except we might also do it in a secondary
- * thread.
- */
- private void runInternally() throws Throwable {
- fProtectable.protect();
- }
-
- /**
- * Runs the test case in a different process. This is what we do for
- * isolating test cases that have side effects or do suffer from them.
- */
- private void runExternally() throws Throwable {
- Throwable throwable = null;
-
- File file = File.createTempFile("isolation", ".tmp");
-
- String program = (IS_DALVIK ? "dalvikvm" : "java") +
- " -classpath " + System.getProperty("java.class.path") +
- " -Djava.home=" + System.getProperty("java.home") +
- " -Duser.home=" + System.getProperty("user.home") +
- " -Djava.io.tmpdir=" + System.getProperty("java.io.tmpdir") +
- " com.google.coretests.CoreTestIsolator" +
- " " + fTest.getClass().getName() +
- " " + fTest.getName() +
- " " + file.getAbsolutePath();
- fProcess = Runtime.getRuntime().exec(program);
-
- int result = fProcess.waitFor();
-
- if (result != TestRunner.SUCCESS_EXIT) {
- try {
- FileInputStream fis = new FileInputStream(file);
- ObjectInputStream ois = new ObjectInputStream(fis);
- throwable = (Throwable)ois.readObject();
- ois.close();
- } catch (Exception ex) {
- throwable = new RuntimeException("Error isolating test: " + program, ex);
- }
- }
-
- file.delete();
-
- if (throwable != null) {
- throw throwable;
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestRunner.java b/luni/src/test/java/com/google/coretests/CoreTestRunner.java
deleted file mode 100644
index aa62ca4..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestRunner.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import junit.textui.ResultPrinter;
-import junit.textui.TestRunner;
-
-/**
- * A special TestRunner implementation that is able to filter out annotated
- * tests and handles our known failures properly (expects them to fail).
- * Handy when running the Core Libraries tests on Android, the bare-metal
- * Dalvik VM, or the RI.
- */
-public class CoreTestRunner extends TestRunner {
-
- /**
- * Reflects our environment.
- */
- private static boolean IS_DALVIK = "Dalvik".equals(
- System.getProperty("java.vm.name"));
-
- /**
- * Defines the default flags for running on Dalvik.
- */
- private static final int DEFAULT_FLAGS_DALVIK =
- CoreTestSuite.RUN_ANDROID_ONLY |
- CoreTestSuite.RUN_NORMAL_TESTS |
- CoreTestSuite.RUN_KNOWN_FAILURES |
- CoreTestSuite.RUN_SIDE_EFFECTS |
- CoreTestSuite.INVERT_KNOWN_FAILURES;
-
- /**
- * Defines the default flags for running on an RI.
- */
- private static final int DEFAULT_FLAGS_NON_DALVIK =
- CoreTestSuite.RUN_NORMAL_TESTS |
- CoreTestSuite.RUN_KNOWN_FAILURES |
- CoreTestSuite.RUN_SIDE_EFFECTS;
-
- /**
- * Holds the flags specified by the user on the command line.
- */
- private int fFlags;
-
- /**
- * Holds the timeout value specified by the user on the command line.
- */
- private int fTimeout;
-
- private int fStep = 1;
-
- /**
- * The path to write XML reports to, or {@code null} for no reports.
- */
- private String xmlReportsDirectory;
-
- /**
- * Creates a new instance of our CoreTestRunner.
- */
- public CoreTestRunner() {
- super();
- }
-
- @Override
- protected TestResult createTestResult() {
- return new CoreTestResult(fFlags, fTimeout);
- }
-
- protected ResultPrinter createPrinter() {
- return new CoreTestPrinter(System.out, fFlags);
- }
-
- /**
- * Provides our main entry point.
- */
- public static void main(String args[]) {
- Logger.global.setLevel(Level.OFF);
-
- System.out.println(
- "--------------------------------------------------");
- System.out.println("Android Core Libraries Test Suite");
- System.out.println("Version 1.0");
- System.out.println(
- "Copyright (c) 2009 The Android Open Source Project");
- System.out.println("");
-
- CoreTestRunner testRunner = new CoreTestRunner();
- try {
- TestResult r = testRunner.start(args);
-
- System.out.println(
- "--------------------------------------------------");
-
- if (!r.wasSuccessful()) {
- System.exit(FAILURE_EXIT);
- } else {
- System.exit(SUCCESS_EXIT);
- }
- } catch(Exception e) {
- System.err.println(e.getMessage());
- System.exit(EXCEPTION_EXIT);
- }
-
- }
-
- @Override
- public TestResult doRun(Test suite, boolean wait) {
- setPrinter(createPrinter());
-
- /*
- * Make sure the original suite is unreachable after we have
- * created the new one, so GC can dispose terminated tests.
- */
- CoreTestSuite coreTestSuite = new CoreTestSuite(suite, fFlags, fStep, null);
-
- XmlReportPrinter xmlReportPrinter = xmlReportsDirectory != null
- ? new XmlReportPrinter(coreTestSuite)
- : null;
-
- TestResult result = super.doRun(coreTestSuite, wait);
-
- if (xmlReportPrinter != null) {
- System.out.print("Printing XML Reports... ");
- xmlReportPrinter.setResults(result);
- int numFiles = xmlReportPrinter.generateReports(xmlReportsDirectory);
- System.out.println(numFiles + " files written.");
- }
-
- return result;
- }
-
- /**
- * Prints a help screen on the console.
- */
- private void showHelp() {
- System.out.println("Usage: run-core-tests [OPTION]... [TEST]...");
- System.out.println();
- System.out.println("Where each TEST is a class name, optionally followed");
- System.out.println("by \"#\" and a method name, and each OPTION is one of");
- System.out.println("the following:");
- System.out.println();
- System.out.println(" --include-all");
- System.out.println(" --exclude-all");
- System.out.println(" --include-android-only");
- System.out.println(" --exclude-android-only");
- System.out.println(" --include-broken-tests");
- System.out.println(" --exclude-broken-tests");
- System.out.println(" --include-known-failures");
- System.out.println(" --exclude-known-failures");
- System.out.println(" --include-normal-tests");
- System.out.println(" --exclude-normal-tests");
- System.out.println(" --include-side-effects");
- System.out.println(" --exclude-side-effects");
- System.out.println();
- System.out.println(" --known-failures-must-fail");
- System.out.println(" --known-failures-must-pass");
- System.out.println(" --timeout <seconds>");
- // System.out.println(" --find-side-effect <test>");
- System.out.println(" --isolate-all");
- System.out.println(" --isolate-none");
- System.out.println(" --verbose");
- System.out.println(" --xml-reports-directory <path>");
- System.out.println(" --help");
- System.out.println();
- System.out.println("Default parameters are:");
- System.out.println();
-
- if (IS_DALVIK) {
- System.out.println(" --include-android-only");
- System.out.println(" --exclude-broken-tests");
- System.out.println(" --include-known-failures");
- System.out.println(" --include-normal-tests");
- System.out.println(" --include-side-effects");
- System.out.println(" --known-failures-must-fail");
- } else {
- System.out.println(" --exclude-android-only");
- System.out.println(" --exclude-broken-tests");
- System.out.println(" --include-known-failures");
- System.out.println(" --include-normal-tests");
- System.out.println(" --include-side-effects");
- System.out.println(" --known-failures-must-pass");
- }
-
- System.out.println();
- }
-
- /**
- * Tries to create a Test instance from the given strings. The strings might
- * either specify a class only or a class plus a method name, separated by
- * a "#".
- */
- private Test createTest(List<String> testCases) throws Exception {
- TestSuite result = new TestSuite();
- for (String testCase : testCases) {
- int p = testCase.indexOf("#");
- if (p != -1) {
- String testName = testCase.substring(p + 1);
- testCase = testCase.substring(0, p);
-
- result.addTest(TestSuite.createTest(Class.forName(testCase), testName));
- } else {
- result.addTest(getTest(testCase));
- }
- }
- return result;
- }
-
- @Override
- protected TestResult start(String args[]) throws Exception {
- List<String> testNames = new ArrayList<String>();
- // String victimName = null;
-
- boolean wait = false;
-
- if (IS_DALVIK) {
- fFlags = DEFAULT_FLAGS_DALVIK;
- } else {
- fFlags = DEFAULT_FLAGS_NON_DALVIK;
- }
-
- for (int i= 0; i < args.length; i++) {
- if (args[i].startsWith("--")) {
- if (args[i].equals("--wait")) {
- wait = true;
- } else if (args[i].equals("--include-all")) {
- fFlags = fFlags | CoreTestSuite.RUN_ALL_TESTS;
- } else if (args[i].equals("--exclude-all")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_ALL_TESTS;
- } else if (args[i].equals("--include-android-only")) {
- fFlags = fFlags | CoreTestSuite.RUN_ANDROID_ONLY;
- } else if (args[i].equals("--exclude-android-only")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_ANDROID_ONLY;
- } else if (args[i].equals("--include-broken-tests")) {
- fFlags = fFlags | CoreTestSuite.RUN_BROKEN_TESTS;
- } else if (args[i].equals("--exclude-broken-tests")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_BROKEN_TESTS;
- } else if (args[i].equals("--include-known-failures")) {
- fFlags = fFlags | CoreTestSuite.RUN_KNOWN_FAILURES;
- } else if (args[i].equals("--exclude-known-failures")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_KNOWN_FAILURES;
- } else if (args[i].equals("--include-normal-tests")) {
- fFlags = fFlags | CoreTestSuite.RUN_NORMAL_TESTS;
- } else if (args[i].equals("--exclude-normal-tests")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_NORMAL_TESTS;
- } else if (args[i].equals("--include-side-effects")) {
- fFlags = fFlags | CoreTestSuite.RUN_SIDE_EFFECTS;
- } else if (args[i].equals("--exclude-side-effects")) {
- fFlags = fFlags & ~CoreTestSuite.RUN_SIDE_EFFECTS;
- } else if (args[i].equals("--known-failures-must-fail")) {
- fFlags = fFlags | CoreTestSuite.INVERT_KNOWN_FAILURES;
- } else if (args[i].equals("--known-failures-must-pass")) {
- fFlags = fFlags & ~CoreTestSuite.INVERT_KNOWN_FAILURES;
- } else if (args[i].equals("--timeout")) {
- fTimeout = Integer.parseInt(args[++i]);
- } else if (args[i].equals("--reverse")) {
- fFlags = fFlags | CoreTestSuite.REVERSE;
- } else if (args[i].equals("--step")) {
- fStep = Integer.parseInt(args[++i]);
- } else if (args[i].equals("--isolate-all")) {
- fFlags = (fFlags | CoreTestSuite.ISOLATE_ALL) &
- ~CoreTestSuite.ISOLATE_NONE;
- } else if (args[i].equals("--isolate-none")) {
- fFlags = (fFlags | CoreTestSuite.ISOLATE_NONE) &
- ~CoreTestSuite.ISOLATE_ALL;
- } else if (args[i].equals("--verbose")) {
- fFlags = fFlags | CoreTestSuite.VERBOSE;
- // } else if (args[i].equals("--find-side-effect")) {
- // victimName = args[++i];
- } else if (args[i].equals("--dry-run")) {
- fFlags = fFlags | CoreTestSuite.DRY_RUN;
- } else if (args[i].equals("--xml-reports-directory")) {
- xmlReportsDirectory = args[++i];
- } else if (args[i].equals("--help")) {
- showHelp();
- System.exit(1);
- } else {
- unknownArgument(args[i]);
- }
- } else if (args[i].startsWith("-")) {
- unknownArgument(args[i]);
- } else {
- testNames.add(args[i]);
- }
- }
-
- if (IS_DALVIK) {
- System.out.println("Using Dalvik VM version " +
- System.getProperty("java.vm.version"));
- } else {
- System.out.println("Using Java VM version " +
- System.getProperty("java.version"));
- }
- System.out.println();
-
- try {
- return doRun(createTest(testNames), wait);
- }
- catch(Exception e) {
- e.printStackTrace();
- throw new Exception("Could not create and run test suite: " + e);
- }
- }
-
- private static void unknownArgument(String arg) {
- System.err.println("Unknown argument " + arg + ", try --help");
- System.exit(1);
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestSuite.java b/luni/src/test/java/com/google/coretests/CoreTestSuite.java
deleted file mode 100644
index 8e94b83..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestSuite.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestFailure;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.SideEffect;
-
-/**
- * A special TestSuite implementation that flattens the hierarchy of a given
- * JUnit TestSuite and removes tests after executing them. This is so the core
- * tests actually have a chance to succeed, since they do consume quite some
- * memory and many tests do not (have a chance to) cleanup properly after
- * themselves. The class also implements our filtering mechanism for tests, so
- * it becomes easy to only include or exclude tests based on their annotations
- * (like, say, execute all Android-only tests that are not known to be broken).
- */
-public class CoreTestSuite implements Test {
-
- /**
- * Include all normal tests in the suite.
- */
- public static final int RUN_NORMAL_TESTS = 1;
-
- /**
- * Include all broken tests in the suite.
- */
- public static final int RUN_BROKEN_TESTS = 2;
-
- /**
- * Include all known failures in the suite.
- */
- public static final int RUN_KNOWN_FAILURES = 4;
-
- /**
- * Include all Android-only tests in the suite.
- */
- public static final int RUN_ANDROID_ONLY = 8;
-
- /**
- * Include side-effective tests in the suite.
- */
- public static final int RUN_SIDE_EFFECTS = 16;
-
- /**
- * Include all tests in the suite.
- */
- public static final int RUN_ALL_TESTS =
- RUN_NORMAL_TESTS | RUN_BROKEN_TESTS |
- RUN_KNOWN_FAILURES | RUN_SIDE_EFFECTS | RUN_ANDROID_ONLY;
-
- /**
- * Special treatment for known failures: they are expected to fail, so we
- * throw an Exception if they succeed and accept them failing.
- */
- public static final int INVERT_KNOWN_FAILURES = 32;
-
- /**
- * Run each test in its own VM.
- */
- public static final int ISOLATE_ALL = 64;
-
- /**
- * Run no test in its own VM.
- */
- public static final int ISOLATE_NONE = 128;
-
- /**
- * Be verbose.
- */
- public static final int VERBOSE = 256;
-
- public static final int REVERSE = 512;
-
- public static final int DRY_RUN = 1024;
-
- private final String name;
-
- /**
- * The total number of tests in the original suite.
- */
- protected int fTotalCount;
-
- /**
- * The number of Android-only tests in the original suite.
- */
- protected int fAndroidOnlyCount;
-
- /**
- * The number of broken tests in the original suite.
- */
- protected int fBrokenCount;
-
- /**
- * The number of known failures in the original suite.
- */
- protected int fKnownFailureCount;
-
- /**
- * The number of side-effective tests in the original suite.
- */
- protected int fSideEffectCount;
-
- /**
- * The number of normal (non-annotated) tests in the original suite.
- */
- protected int fNormalCount;
-
- /**
- * The number of ignored tests, that is, the number of tests that were
- * excluded from this suite due to their annotations.
- */
- protected int fIgnoredCount;
-
- /**
- * Contains the actual test cases in a reverse-ordered, flat list.
- */
- private Vector<Test> fTests = new Vector<Test>();
-
- private TestCase fVictim;
-
- private int fStep;
-
- private int fFlags;
-
- /**
- * Creates a new CoreTestSuite for the given ordinary JUnit Test (which may
- * be a TestCase or TestSuite). The CoreTestSuite will be a flattened and
- * potentially filtered subset of the original JUnit Test. The flags
- * determine the way we filter.
- */
- public CoreTestSuite(Test suite, int flags, int step, TestCase victim) {
- super();
-
- name = suite.toString();
- fStep = step;
- addAndFlatten(suite, flags);
- fVictim = victim;
- fFlags = flags;
- }
-
- /**
- * Adds the given ordinary JUnit Test (which may be a TestCase or TestSuite)
- * to this CoreTestSuite. Note we are storing the tests in reverse order,
- * so it's easier to remove a finished test from the end of the list.
- */
- private void addAndFlatten(Test test, int flags) {
- if (test instanceof TestSuite) {
- TestSuite suite = (TestSuite)test;
-
- if ((flags & REVERSE) != 0) {
- for (int i = suite.testCount() - 1; i >= 0; i--) {
- addAndFlatten(suite.testAt(i), flags);
- }
- } else {
- for (int i = 0; i < suite.testCount(); i++) {
- addAndFlatten(suite.testAt(i), flags);
- }
- }
- } else if (test instanceof TestCase) {
- TestCase testCase = (TestCase)test;
- boolean ignoreMe = false;
-
- boolean isAndroidOnly = hasAnnotation(testCase, AndroidOnly.class);
- boolean isBrokenTest = hasAnnotation(testCase, BrokenTest.class);
- boolean isKnownFailure = hasAnnotation(testCase, KnownFailure.class);
- boolean isSideEffect = hasAnnotation(testCase, SideEffect.class);
- boolean isNormalTest =
- !(isAndroidOnly || isBrokenTest || isKnownFailure ||
- isSideEffect);
-
- if (isAndroidOnly) {
- fAndroidOnlyCount++;
- }
-
- if (isBrokenTest) {
- fBrokenCount++;
- }
-
- if (isKnownFailure) {
- fKnownFailureCount++;
- }
-
- if (isNormalTest) {
- fNormalCount++;
- }
-
- if (isSideEffect) {
- fSideEffectCount++;
- }
-
- if ((flags & RUN_ANDROID_ONLY) == 0 && isAndroidOnly) {
- ignoreMe = true;
- }
-
- if ((flags & RUN_BROKEN_TESTS) == 0 && isBrokenTest) {
- ignoreMe = true;
- }
-
- if ((flags & RUN_KNOWN_FAILURES) == 0 && isKnownFailure) {
- ignoreMe = true;
- }
-
- if (((flags & RUN_NORMAL_TESTS) == 0) && isNormalTest) {
- ignoreMe = true;
- }
-
- if (((flags & RUN_SIDE_EFFECTS) == 0) && isSideEffect) {
- ignoreMe = true;
- }
-
- this.fTotalCount++;
-
- if (!ignoreMe) {
- fTests.add(test);
- } else {
- this.fIgnoredCount++;
- }
- } else {
- System.out.println("Warning: Don't know how to handle " +
- test.getClass().getName() + " " + test.toString());
- }
- }
-
- /**
- * Checks whether the given TestCase class has the given annotation.
- */
- @SuppressWarnings("unchecked")
- private boolean hasAnnotation(TestCase test, Class clazz) {
- try {
- Method method = test.getClass().getMethod(test.getName());
- return method.getAnnotation(clazz) != null;
- } catch (Exception e) {
- // Ignore
- }
-
- return false;
- }
-
- /**
- * Runs the tests and collects their result in a TestResult.
- */
- public void run(TestResult result) {
- // Run tests
- int i = 0;
-
- while (fTests.size() != 0 && !result.shouldStop()) {
- TestCase test = (TestCase)fTests.elementAt(i);
-
- Thread.currentThread().setContextClassLoader(
- test.getClass().getClassLoader());
-
- test.run(result);
-
- /*
- if (fVictim != null) {
- TestResult dummy = fVictim.run();
-
- if (dummy.failureCount() != 0) {
- result.addError(fTests.elementAt(i), new RuntimeException(
- "Probable side effect",
- ((TestFailure)dummy.failures().nextElement()).
- thrownException()));
- } else if (dummy.errorCount() != 0) {
- result.addError(fTests.elementAt(i), new RuntimeException(
- "Probable side effect",
- ((TestFailure)dummy.errors().nextElement()).
- thrownException()));
- }
- }
- */
-
- fTests.remove(i);
-
- if (fTests.size() != 0) {
- i = (i + fStep - 1) % fTests.size();
- }
-
- }
-
- // Forward overall stats to TestResult, so ResultPrinter can see it.
- if (result instanceof CoreTestResult) {
- ((CoreTestResult)result).updateStats(
- fTotalCount, fAndroidOnlyCount, fBrokenCount,
- fKnownFailureCount, fNormalCount, fIgnoredCount,
- fSideEffectCount);
- }
- }
-
- /**
- * Nulls all reference fields in the given test object. This method helps
- * us with those test classes that don't have an explicit tearDown()
- * method. Normally the garbage collector should take care of everything,
- * but it can't hurt to support it a bit.
- */
- private void cleanup(TestCase test) {
- Field[] fields = test.getClass().getDeclaredFields();
- for (int i = 0; i < fields.length; i++) {
- Field f = fields[i];
- if (!f.getType().isPrimitive() &&
- (f.getModifiers() & Modifier.STATIC) == 0) {
- try {
- f.setAccessible(true);
- f.set(test, null);
- } catch (Exception ex) {
- // Nothing we can do about it.
- }
- }
- }
- }
-
- /**
- * Returns the tests as an enumeration. Note this is empty once the tests
- * have been executed.
- */
- @SuppressWarnings("unchecked")
- public Enumeration tests() {
- return fTests.elements();
- }
-
- /**
- * Returns the number of tests in the suite. Note this is zero once the
- * tests have been executed.
- */
- public int countTestCases() {
- return fTests.size();
- }
-
- @Override public String toString() {
- return name;
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/CoreTestTimeout.java b/luni/src/test/java/com/google/coretests/CoreTestTimeout.java
deleted file mode 100644
index 864e4e4..0000000
--- a/luni/src/test/java/com/google/coretests/CoreTestTimeout.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.google.coretests;
-
-/**
- * A special exception for timeouts during tests. The CoreResultPrinter knows
- * how to handle this.
- */
-@SuppressWarnings("serial")
-public class CoreTestTimeout extends RuntimeException {
-
- /**
- * Creates a new instance with the given message.
- */
- public CoreTestTimeout(String message) {
- super(message);
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/Main.java b/luni/src/test/java/com/google/coretests/Main.java
deleted file mode 100644
index 73c8ce5..0000000
--- a/luni/src/test/java/com/google/coretests/Main.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import junit.textui.TestRunner;
-import tests.AllTests;
-
-/**
- * Main class to run the core tests.
- */
-public class Main
-{
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println("Running all tests...");
- CoreTestRunner.main(new String[] { "tests.AllTests" });
- } else if ("--stats".equals(args[0])) {
- // Delegate to new stats test runner
- String[] args2 = new String[args.length - 1];
- System.arraycopy(args, 1, args2, 0, args2.length);
-
- if (args2.length == 0) {
- System.out.println("Running all tests with stats...");
- StatTestRunner.run(AllTests.suite());
- } else {
- System.out.println("Running selected tests with stats...");
- StatTestRunner.main(args2);
- }
- } else {
- System.out.println("Running selected tests...");
- CoreTestRunner.main(args);
- }
-
- Runtime.getRuntime().halt(0);
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/PerfStatCollector.java b/luni/src/test/java/com/google/coretests/PerfStatCollector.java
deleted file mode 100644
index 4ef7c03..0000000
--- a/luni/src/test/java/com/google/coretests/PerfStatCollector.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import dalvik.system.VMDebug;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestListener;
-
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-public class PerfStatCollector implements TestListener {
-
- public boolean listAll = false;
- public boolean listBad = false;
- public long thresholdDuration = 3600 * 1000; // in milliseconds
- public boolean twoLines = true;
- public boolean bigMarking = true;
-
- private static boolean havePreciseTime =
- VMDebug.threadCpuTimeNanos() != -1;
-
- public class Item {
- Test test;
- long startTime, duration;
- int res;
- public boolean existsInStore;
- public int id;
- public int bestRes;
- public long lastBestAt;
- public int lastRes;
- public long lastDuration;
- public int statCount;
- public double statAvgDuration;
- public long statMinDuration;
- public long statMaxDuration;
- int adhocRelevance;
- public int histRelevance;
- public boolean isTransition;
- boolean printed = false;
-
- void update(boolean rBad, long rthDurat) {
- // AdHoc Evaluation:
- if (rBad && (res != 0)) {
- // no success:
- adhocRelevance = 2;
- }
- else if (duration >= rthDurat) {
- // long duration:
- adhocRelevance = 1;
- }
- else {
- adhocRelevance = 0;
- }
-
- StatsStore.use1(this);
- }
-
- void print1(PrintStream out, boolean bigMarking) {
- switch (histRelevance) {
- case -4:
- if (bigMarking) {
- out.println();
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("Test ran SUCCESSFULLY once, but NOT this time!!!!");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- out.println("*** *** *** *** *** ATTENTION *** *** *** *** ***");
- }
- out.print("-4 VBAD"); break;
- case 4: out.print(" 4 Good"); break;
- case 3: out.print(" 3 good"); break;
- case -2: out.print("-2 SLOW"); break;
- case 2: out.print(" 2 Fast"); break;
- case 1: out.print(" 1 fast"); break;
- case -3:
- if (res == -2) out.print("-3 FAIL");
- else out.print("-3 ERR ");
- break;
- default:
- if (res == 0) out.print(" ");
- else if (res == -2) out.print(" fail");
- else out.print(" err ");
- }
- if (isTransition) out.print("! ");
- else out.print(" ");
- out.print(test.toString());
- out.format(": %d# %d(%d) [%d..%d] %.1f ms",
- statCount, duration, lastDuration,
- statMinDuration, statMaxDuration, statAvgDuration);
- out.println();
- printed = true;
- }
-
- void print2(PrintStream out, boolean bigMarking) {
- out.format("%5d. ", id);
-
- out.println(test.toString());
- out.print(" ");
-
- switch (histRelevance) {
- case -4: out.print("FAIL"); break;
- case 4: out.print("PASS"); break;
- case 3: out.print("PASS"); break;
- case -2: out.print("SLOW"); break;
- case 2: out.print("FAST"); break;
- case 1: out.print("PASS"); break;
- case -3:
- if (res == -2) out.print("FAIL");
- else out.print("ERR ");
- break;
- default:
- if (res == 0) out.print("PASS");
- else if (res == -2) out.print("FAIL");
- else out.print("XCPT");
- }
-
- out.format(" %d ms (min %d ms, max %d ms, avg %#.1f ms, %d runs)",
- duration,
- statMinDuration, statMaxDuration, statAvgDuration,
- statCount);
- out.println();
-
- printed = true;
- }
-
- void print(PrintStream out, boolean bigMarking) {
- if (twoLines) print2(out, bigMarking);
- else print1(out, bigMarking);
- }
-
- boolean checkPrint(PrintStream out) {
- if (printed) return false;
- print(out, false);
- return true;
- }
- }
-
- ArrayList<Item> items;
- Item current;
-
- PrintStream fWriter;
- int fColumn= 0;
-
- public PerfStatCollector(PrintStream writer) {
- fWriter= writer;
- items = new ArrayList();
- }
-
- synchronized void digest() {
- int totalCnt = 0;
- int adhocRelevantCnt = 0;
- int histRelevantCnt = 0;
- long evalStartTime = System.currentTimeMillis();
- PrintStream out = fWriter;
- out.println("Failure and Performance Statistics:");
- Iterator<Item> r = items.iterator();
- while (r.hasNext()) {
- Item item = r.next();
- item.update(listBad, thresholdDuration);
- if (item.histRelevance != 0) {
- item.print(out, bigMarking);
- histRelevantCnt++;
- }
- if (item.adhocRelevance != 0) {
- if (item.checkPrint(out))
- adhocRelevantCnt++;
- }
- if (listAll) item.checkPrint(out);
- totalCnt++;
- }
- long evalDuration = System.currentTimeMillis() - evalStartTime;
- out.println();
- out.print(totalCnt); out.println(" tests run totally.");
- out.print(histRelevantCnt);
- out.println(" tests listed due to historical relevance.");
-// out.print(adhocRelevantCnt);
-// out.println(" tests listed due to ad-hoc-relevance.");
-// out.print(totalCnt - histRelevantCnt - adhocRelevantCnt);
-// out.println(" tests NOT listed due to relevance.");
- out.println();
- out.print("Time used in Statistics Acquisition: ");
- out.print(evalDuration);
- out.print("ms");
- out.println();
- }
-
-
- public PrintStream getWriter() {
- return fWriter;
- }
-
- /**
- * @see junit.framework.TestListener#addError(Test, Throwable)
- */
- public void addError(Test test, Throwable t) {
- current.res = -1;
- }
-
- /**
- * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
- */
- public void addFailure(Test test, AssertionFailedError t) {
- current.res = -2;
- }
-
- /**
- * @see junit.framework.TestListener#startTest(Test)
- */
- public void startTest(Test test) {
- System.gc();
- current = new Item();
- current.test = test;
- current.startTime = currentTimeMillis();
- items.add(current);
- }
-
- /**
- * @see junit.framework.TestListener#endTest(Test)
- */
- public void endTest(Test test) {
- current.duration = currentTimeMillis() - current.startTime;
- }
-
- /*
- * Returns a "current time" in ms. Depending on the environment, this is
- * either the actual CPU time out current thread has used so far, or the
- * wall clock time of the system.
- */
- private long currentTimeMillis() {
- if (havePreciseTime) {
- return VMDebug.threadCpuTimeNanos() / 1000;
- } else {
- return System.currentTimeMillis();
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/ResultPrinter.java b/luni/src/test/java/com/google/coretests/ResultPrinter.java
deleted file mode 100644
index 93f3f2b..0000000
--- a/luni/src/test/java/com/google/coretests/ResultPrinter.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import java.io.PrintStream;
-// The following line was removed for compatibility with Android libraries.
-//import java.text.NumberFormat;
-import java.util.Enumeration;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestFailure;
-import junit.framework.TestListener;
-import junit.framework.TestResult;
-import junit.runner.BaseTestRunner;
-
-public class ResultPrinter implements TestListener {
- PrintStream fWriter;
- int fColumn= 0;
-
- public ResultPrinter(PrintStream writer) {
- fWriter= writer;
- }
-
- /* API for use by textui.TestRunner
- */
-
- synchronized void print(TestResult result, long runTime) {
- printHeader(runTime);
- printErrors(result);
- printFailures(result);
- printFooter(result);
- }
-
- void printWaitPrompt() {
- getWriter().println();
- getWriter().println("<RETURN> to continue");
- }
-
- /* Internal methods
- */
-
- protected void printHeader(long runTime) {
- getWriter().println();
- getWriter().println("Time: "+elapsedTimeAsString(runTime));
- }
-
- protected void printErrors(TestResult result) {
- printDefects(result.errors(), result.errorCount(), "error");
- }
-
- protected void printFailures(TestResult result) {
- printDefects(result.failures(), result.failureCount(), "failure");
- }
-
- protected void printDefects(Enumeration booBoos, int count, String type) {
- if (count == 0) return;
- if (count == 1)
- getWriter().println("There was " + count + " " + type + ":");
- else
- getWriter().println("There were " + count + " " + type + "s:");
- for (int i= 1; booBoos.hasMoreElements(); i++) {
- printDefect((TestFailure) booBoos.nextElement(), i);
- }
- }
-
- public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
- printDefectHeader(booBoo, count);
- printDefectTrace(booBoo);
- }
-
- protected void printDefectHeader(TestFailure booBoo, int count) {
- // I feel like making this a println, then adding a line giving the throwable a chance to print something
- // before we get to the stack trace.
- getWriter().print(count + ") " + booBoo.failedTest());
- }
-
- protected void printDefectTrace(TestFailure booBoo) {
- getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
- }
-
- protected void printFooter(TestResult result) {
- if (result.wasSuccessful()) {
- getWriter().println();
- getWriter().print("OK");
- getWriter().println (" (" + result.runCount() + " test" + (result.runCount() == 1 ? "": "s") + ")");
-
- } else {
- getWriter().println();
- getWriter().println("FAILURES!!!");
- getWriter().println("Tests run: "+result.runCount()+
- ", Failures: "+result.failureCount()+
- ", Errors: "+result.errorCount());
- }
- getWriter().println();
- }
-
-
- /**
- * Returns the formatted string of the elapsed time.
- * Duplicated from BaseTestRunner. Fix it.
- */
- protected String elapsedTimeAsString(long runTime) {
- // The following line was altered for compatibility with
- // Android libraries.
- return Double.toString((double)runTime/1000);
- }
-
- public PrintStream getWriter() {
- return fWriter;
- }
- /**
- * @see junit.framework.TestListener#addError(Test, Throwable)
- */
- public void addError(Test test, Throwable t) {
- getWriter().print("E");
- }
-
- /**
- * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
- */
- public void addFailure(Test test, AssertionFailedError t) {
- getWriter().print("F");
- }
-
- /**
- * @see junit.framework.TestListener#endTest(Test)
- */
- public void endTest(Test test) {
- }
-
- /**
- * @see junit.framework.TestListener#startTest(Test)
- */
- public void startTest(Test test) {
- getWriter().print(".");
- if (fColumn++ >= 40) {
- getWriter().println();
- fColumn= 0;
- }
- }
-
-}
diff --git a/luni/src/test/java/com/google/coretests/StatTestRunner.java b/luni/src/test/java/com/google/coretests/StatTestRunner.java
deleted file mode 100644
index 602a241..0000000
--- a/luni/src/test/java/com/google/coretests/StatTestRunner.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-import junit.framework.Test;
-import junit.framework.TestResult;
-import junit.framework.TestSuite;
-import junit.runner.BaseTestRunner;
-import junit.runner.StandardTestSuiteLoader;
-import junit.runner.TestSuiteLoader;
-
-import java.io.PrintStream;
-
-/**
- * A command line based tool to run tests.
- * <pre>
- * java junit.textui.TestRunner [-wait] TestCaseClass
- * </pre>
- * TestRunner expects the name of a TestCase class as argument.
- * If this class defines a static <code>suite</code> method it
- * will be invoked and the returned test is run. Otherwise all
- * the methods starting with "test" having no arguments are run.
- * <p>
- * When the wait command line argument is given TestRunner
- * waits until the users types RETURN.
- * <p>
- * TestRunner prints a trace as the tests are executed followed by a
- * summary at the end.
- */
-public class StatTestRunner extends BaseTestRunner {
- private ResultPrinter fPrinter;
- private PerfStatCollector fPerfStatCollector;
-
- public static final int SUCCESS_EXIT= 0;
- public static final int FAILURE_EXIT= 1;
- public static final int EXCEPTION_EXIT= 2;
-
- public static final String DEFAULT_DATABASE = "sqlite:/coretests.db";
- public static final String DEFAULT_DRIVER = "SQLite.JDBCDriver";
-
- public static String connectionURL;
- public static String jdbcDriver;
-
- /**
- * Constructs a TestRunner.
- */
- public StatTestRunner() {
- this(System.out);
- }
-
- /**
- * Constructs a TestRunner using the given stream for all the output
- */
- public StatTestRunner(PrintStream writer) {
- this(new ResultPrinter(writer));
- }
-
- /**
- * Constructs a TestRunner using the given ResultPrinter all the output
- */
- public StatTestRunner(ResultPrinter printer) {
- fPrinter= printer;
- fPerfStatCollector = new PerfStatCollector(printer.getWriter());
- }
-
- /**
- * Runs a suite extracted from a TestCase subclass.
- */
- static public void run(Class testClass) {
- run(new TestSuite(testClass));
- }
-
- /**
- * Runs a single test and collects its results.
- * This method can be used to start a test run
- * from your program.
- * <pre>
- * public static void main (String[] args) {
- * test.textui.TestRunner.run(suite());
- * }
- * </pre>
- */
- static public TestResult run(Test test) {
- StatTestRunner runner= new StatTestRunner();
- try {
- return runner.doRun(test, false);
- }
- catch (Exception e) {
- return null;
- }
- }
-
- /**
- * Runs a single test and waits until the user
- * types RETURN.
- */
- static public void runAndWait(Test suite) {
- StatTestRunner aTestRunner= new StatTestRunner();
- try {
- aTestRunner.doRun(suite, true);
- }
- catch (Exception e) {}
- }
-
- /**
- * Always use the StandardTestSuiteLoader. Overridden from
- * BaseTestRunner.
- */
- public TestSuiteLoader getLoader() {
- return new StandardTestSuiteLoader();
- }
-
- public void testFailed(int status, Test test, Throwable t) {
- }
-
- public void testStarted(String testName) {
- }
-
- public void testEnded(String testName) {
- }
-
- public TestResult doRun(Test suite, boolean wait) throws Exception {
- StatsStore.open(jdbcDriver, connectionURL);
- TestResult result = new TestResult();
- result.addListener(fPrinter);
- result.addListener(fPerfStatCollector);
- long startTime= System.currentTimeMillis();
- StatsStore.now = startTime;
- suite.run(result);
- long endTime= System.currentTimeMillis();
- long runTime= endTime-startTime;
- fPrinter.print(result, runTime);
- fPerfStatCollector.digest();
- StatsStore.close();
-
- pause(wait);
- return result;
- }
-
- protected void pause(boolean wait) {
- if (!wait) return;
- fPrinter.printWaitPrompt();
- try {
- System.in.read();
- }
- catch(Exception e) {
- }
- }
-
- public static void main(String args[]) {
- StatTestRunner aTestRunner= new StatTestRunner();
- try {
- TestResult r= aTestRunner.start(args);
- if (!r.wasSuccessful())
- System.exit(FAILURE_EXIT);
- System.exit(SUCCESS_EXIT);
- } catch(Exception e) {
- System.err.println(e.getMessage());
- System.exit(EXCEPTION_EXIT);
- }
- }
-
- /**
- * Starts a test run. Analyzes the command line arguments
- * and runs the given test suite.
- */
- protected TestResult start(String args[]) throws Exception {
- String testCase= "";
- boolean wait= false;
-
- jdbcDriver = System.getProperty("android.coretests.driver", DEFAULT_DRIVER);
- connectionURL = System.getProperty("android.coretests.database", "jdbc:" + DEFAULT_DATABASE);
-
- for (int i= 0; i < args.length; i++) {
- if (args[i].equals("--all"))
- fPerfStatCollector.listAll = true;
- else if (args[i].equals("--bad"))
- fPerfStatCollector.listBad = true;
- else if (args[i].equals("--nobig"))
- fPerfStatCollector.bigMarking = false;
- else if (args[i].equals("--s")) {
- fPerfStatCollector.thresholdDuration =
- Integer.valueOf(args[++i]);
- } else if (args[i].equals("-wait"))
- wait= true;
- else if (args[i].equals("-c"))
- testCase= extractClassName(args[++i]);
- else if (args[i].equals("-v"))
- System.err.println("JUnit "+Version.id()+" (plus Android performance stats)");
- else
- testCase= args[i];
- }
-
- if (testCase.equals(""))
- throw new Exception("Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class");
-
- try {
- Test suite= getTest(testCase);
- return doRun(suite, wait);
- }
- catch (Exception e) {
- throw new Exception("Exception: " + e);
- }
- }
-
- protected void runFailed(String message) {
- System.err.println(message);
- System.exit(FAILURE_EXIT);
- }
-
- public void setPrinter(ResultPrinter printer) {
- fPrinter= printer;
- }
-
-
-}
diff --git a/luni/src/test/java/com/google/coretests/StatsStore.java b/luni/src/test/java/com/google/coretests/StatsStore.java
deleted file mode 100644
index 2c18ab3..0000000
--- a/luni/src/test/java/com/google/coretests/StatsStore.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-
-import junit.framework.Test;
-
-import java.io.File;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-
-public class StatsStore {
-
- static final String sysVersion = "1.0";
-
- static Connection conn;
- static Statement stmt;
- static PreparedStatement insertStmt, selectByNameStmt, updateStmt;
- static PreparedStatement insertDetStmt, insertEventStmt;
- static PreparedStatement selectAllStmt;
-
- public static long now;
-
- static int compareDuration(long dur, long refDur) {
- long diff = dur - refDur;
- if (diff <= 0) {
- if ((double)-diff / refDur > 0.5) return 1; // remarkably faster
- else return 0; // equivalent duration (maybe a bit faster)
- }
- else if (diff < 20) return 0; // not measurably slower: equivalent duration
- else if ((double)diff / refDur < 0.2) return 0; // just little slower: equivalent duration
- else return -1; // relevantly SLOWer
- }
-
- static void initStats(PerfStatCollector.Item a) {
- a.statMinDuration = a.duration;
- a.statMaxDuration = a.duration;
- a.statAvgDuration = a.duration;
- a.statCount = 1;
- }
-
- static void adjustStats(PerfStatCollector.Item a) {
- if (a.duration < a.statMinDuration) a.statMinDuration = a.duration;
- else
- if (a.duration > a.statMaxDuration) a.statMaxDuration = a.duration;
- a.statAvgDuration = ((a.statAvgDuration * a.statCount + a.duration) / (a.statCount + 1));
- a.statCount++;
- }
-
- static void adjustStatsOptimistic(PerfStatCollector.Item a) {
- adjustStats(a);
- // Could consider reducing a.statMaxDuration.
- }
-
- static void use1(PerfStatCollector.Item a) {
- Test test;
- int pos;
- PreparedStatement selectStmt = selectByNameStmt;
- try {
- try {
- insertStmt.setString(1, a.test.toString());
- insertStmt.execute();
- } catch (SQLException e) {}
- selectStmt.setString(1, a.test.toString());
- ResultSet row = selectStmt.executeQuery();
- row.first();
- pos = 1;
- a.id = row.getInt(pos); pos++;
- a.bestRes = row.getInt(pos); pos++;
- a.lastBestAt = row.getLong(pos); pos++;
- a.lastRes = row.getInt(pos); pos++;
- a.lastDuration = row.getLong(pos); pos++;
- a.statCount = row.getInt(pos); pos++;
- a.statAvgDuration = row.getDouble(pos); pos++;
- a.statMinDuration = row.getLong(pos); pos++;
- a.statMaxDuration = row.getLong(pos); pos++;
- if (a.res == 0) {
- if (a.bestRes == 100) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 0; // Good from scratch.
- a.isTransition = false;
- initStats(a);
- } else if (a.bestRes != 0) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 4; // "Good" for the first time:
- a.isTransition = true; // was bad before.
- initStats(a);
- } else if (a.lastRes != 0) {
- a.bestRes = 0; a.lastBestAt = now;
- a.histRelevance = 3; // "good" again:
- a.isTransition = true; // was bad in between.
- adjustStats(a);
- } else {
- // res == lastRes == bestRes == 0:
- int cmp = compareDuration(a.duration, a.statMinDuration);
- if (cmp >= 0) {
- a.bestRes = 0; a.lastBestAt = now;
- if (cmp > 0) {
- a.histRelevance = 2; // "Fast"er than ever before.
- a.isTransition = true;
- adjustStatsOptimistic(a);
- } else if (compareDuration(a.duration, a.lastDuration) > 0) {
- // As fast as best but faster than last run:
- a.histRelevance = 1; // "fast" again.
- a.isTransition = true;
- adjustStatsOptimistic(a);
- } else {
- a.histRelevance = 0; // Equivalent Duration:
- a.isTransition = false; // usual good case.
- adjustStats(a);
- }
- } else {
- if (compareDuration(a.duration, a.lastDuration) < 0) {
- a.histRelevance = -2; // "SLOW"!!!
- a.isTransition = true;
- adjustStats(a);
- } else {
- a.histRelevance = -2; // Still "SLOW"!!!
- a.isTransition = false; // (But NO transition!)
- adjustStats(a);
- }
- }
- }
- } else if (a.bestRes == 0) {
- if (a.lastRes == 0) {
- a.histRelevance = -4; // "VBAD"!!!
- a.isTransition = true;
- } else {
- a.histRelevance = -4; // Still "VBAD"!!!
- a.isTransition = false; // (But NO transition!)
- }
- // DON'T adjust statistics: they should reflect good runs, only.
- } else if (a.bestRes == 100) {
- a.bestRes = -3; // Just mark as NOT good.
- a.histRelevance = -3; // Bad (initial run).
- a.isTransition = true;
- initStats(a);
- } else {
- a.histRelevance = 0; // Still Failure or Error:
- a.isTransition = false; // usual bad case.
- adjustStats(a);
- }
- pos = 1;
- updateStmt.setInt(pos, a.bestRes); pos++;
- updateStmt.setLong(pos, a.lastBestAt); pos++;
- updateStmt.setInt(pos, a.res); pos++;
- updateStmt.setLong(pos, a.duration); pos++;
- updateStmt.setInt(pos, a.statCount); pos++;
- updateStmt.setDouble(pos, a.statAvgDuration); pos++;
- updateStmt.setLong(pos, a.statMinDuration); pos++;
- updateStmt.setLong(pos, a.statMaxDuration); pos++;
- updateStmt.setInt(pos, a.id); pos++;
- updateStmt.execute();
- pos = 1;
- insertDetStmt.setInt(pos, a.id); pos++;
- insertDetStmt.setLong(pos, now); pos++;
- insertDetStmt.setInt(pos, a.statCount); pos++;
- insertDetStmt.setInt(pos, a.res); pos++;
- insertDetStmt.setLong(pos, a.duration); pos++;
- insertDetStmt.execute();
- if (a.isTransition) {
- pos = 1;
- insertEventStmt.setInt(pos, a.id); pos++;
- insertEventStmt.setLong(pos, now); pos++;
- insertEventStmt.setInt(pos, a.histRelevance); pos++;
- insertEventStmt.setInt(pos, a.res); pos++;
- insertEventStmt.setLong(pos, a.duration); pos++;
- insertEventStmt.execute();
- }
- }
- catch (SQLException e) {
- int x = 0;
- }
- }
-
-// static void use2(PerfStatCollector.Item a) {
-// }
-
- static void execOrIgnore(String sql) {
- try { stmt.execute(sql); }
- catch (SQLException e) {}
- }
-
- static void open(String jdbcDriver, String connectionURL)
- throws Exception {
-// try {
- Class.forName(jdbcDriver).newInstance();
- conn = DriverManager.getConnection(connectionURL);
- stmt = conn.createStatement();
- String dbVersion;
- try {
- ResultSet res = stmt.executeQuery("SELECT id FROM Version");
- res.first();
- dbVersion = res.getString(1);
- }
- catch (SQLException e) {
- dbVersion = "";
- }
- if (!dbVersion.equals(sysVersion)) {
- execOrIgnore("DROP TABLE Test_Cases;");
- stmt.execute("CREATE TABLE Test_Cases (" +
- " id INTEGER PRIMARY KEY AUTOINCREMENT, " +
- " name VARCHAR(255) UNIQUE, " +
- // (best_Res != 0) ==> (last_Best_At == 0) never ran good!
- " best_Res INTEGER, last_Best_At INTEGER, " +
- " last_Res INTEGER, last_Duration INTEGER, " +
- " stat_Cnt INTEGER, stat_Avg NUMBER(20, 2), " +
- " stat_Min INTEGER, stat_Max INTEGER);");
- execOrIgnore("DROP TABLE Test_Case_Runs;");
- stmt.execute("CREATE TABLE Test_Case_Runs (" +
- " test_Id INTEGER, run_At INTEGER, " +
- " iteration INTEGER, res INTEGER, duration INTEGER, " +
- " PRIMARY KEY (test_Id, run_At));");
- execOrIgnore("DROP TABLE Test_Case_Events;");
- stmt.execute("CREATE TABLE Test_Case_Events (" +
- " test_Id INTEGER, run_At INTEGER, " +
- " relevance INTEGER, " +
- " res INTEGER, duration INTEGER, " +
- " PRIMARY KEY (test_Id, run_At));");
-// stmt.execute("CREATE PROCEDURE useSample (IN pName TEXT, " +
-// "pRes INTEGER, pDuration INTEGER, pTime INTEGER) " +
-// "BEGIN " +
-// " INSERT OR IGNORE INTO TestCases (name)" +
-// " VALUES (pName);" +
-// "END;");
- execOrIgnore("DROP TABLE Version;");
- stmt.execute("CREATE TABLE Version(id VARCHAR(31));");
- stmt.execute("INSERT INTO Version (id) VALUES ('" + sysVersion + "');");
- }
-// updateStmt = conn.prepareStatement("useSample(:name, :res, :duration, :time)");
- // firstConnection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
- // firstStmt = firstConnection.createStatement();
- // firstStmt.execute("create table tbl1(one varchar(10), two smallint)");
- insertStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Cases (name, stat_Cnt) VALUES (?, 0);");
- selectByNameStmt = conn.prepareStatement("SELECT id, " +
- " IFNULL(best_Res, 100), IFNULL(last_Best_At, 0), " +
- " IFNULL(last_Res, 100), IFNULL(last_Duration, 0), " +
- " IFNULL(stat_Cnt, 0), IFNULL(stat_Avg, 0), " +
- " IFNULL(stat_Min, 0), IFNULL(stat_Max, 0) " +
- "FROM Test_Cases WHERE name = ?;");
- updateStmt = conn.prepareStatement("UPDATE Test_Cases SET " +
- " best_Res = ?, last_Best_At = ?, " +
- " last_Res = ?, last_Duration = ?, " +
- " stat_Cnt = ?, stat_Avg = ?, " +
- " stat_Min = ?, stat_Max = ? " +
- "WHERE id = ?;");
- insertDetStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Case_Runs (test_Id, run_At, iteration, res, duration) " +
- "VALUES (?, ?, ?, ?, ?);");
- insertEventStmt = conn.prepareStatement("INSERT " +
- "INTO Test_Case_Events (test_Id, run_At, relevance, res, duration) " +
- "VALUES (?, ?, ?, ?, ?);");
- selectAllStmt = conn.prepareStatement("SELECT id, name, " +
- "last_Res, stat_Cnt, " +
- "last_Duration, stat_Avg, stat_Min, stat_Max " +
- "FROM Test_Cases;");
-
- try {
-// ResultSet res = stmt.executeQuery("PRAGMA CACHE_SIZE;");
-// res.first();
-// System.out.print("CACHE_SIZE = ");
-// System.out.println(res.getString(1));
-// stmt.execute("PRAGMA CACHE_SIZE = 5000;");
- stmt.execute("PRAGMA SYNCHRONOUS = OFF;");
- stmt.execute("PRAGMA temp_store = MEMORY;");
- }
- catch (SQLException e) {
- dbVersion = "";
- }
- stmt.close();
- conn.commit();
-// }
-// catch (Exception e) {
-// conn = null;
-// }
-// return conn != null;
- }
-
- static void close() {
- try {
- conn.commit();
- conn.close();
- conn = null;
- }
- catch (Exception e) {
- conn = null;
- }
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/Version.java b/luni/src/test/java/com/google/coretests/Version.java
deleted file mode 100644
index e76a6bb..0000000
--- a/luni/src/test/java/com/google/coretests/Version.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.coretests;
-
-/**
- * This class defines the current version of JUnit
- */
-public class Version {
- private Version() {
- // don't instantiate
- }
-
- public static String id() {
- return "0.1";
- }
-}
diff --git a/luni/src/test/java/com/google/coretests/XmlReportPrinter.java b/luni/src/test/java/com/google/coretests/XmlReportPrinter.java
deleted file mode 100644
index f098b3a..0000000
--- a/luni/src/test/java/com/google/coretests/XmlReportPrinter.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package com.google.coretests;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestFailure;
-import junit.framework.TestResult;
-import junit.runner.BaseTestRunner;
-import org.kxml2.io.KXmlSerializer;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-
-
-/**
- * Writes JUnit results to a series of XML files in a format consistent with
- * Ant's XMLJUnitResultFormatter.
- *
- * <p>Unlike Ant's formatter, this class does not report the execution time of
- * tests.
- */
-public class XmlReportPrinter {
-
- private static final String TESTSUITE = "testsuite";
- private static final String TESTCASE = "testcase";
- private static final String ERROR = "error";
- private static final String FAILURE = "failure";
- private static final String ATTR_NAME = "name";
- private static final String ATTR_TIME = "time";
- private static final String ATTR_ERRORS = "errors";
- private static final String ATTR_FAILURES = "failures";
- private static final String ATTR_TESTS = "tests";
- private static final String ATTR_TYPE = "type";
- private static final String ATTR_MESSAGE = "message";
- private static final String PROPERTIES = "properties";
- private static final String ATTR_CLASSNAME = "classname";
- private static final String TIMESTAMP = "timestamp";
- private static final String HOSTNAME = "hostname";
-
- /** the XML namespace */
- private static final String ns = null;
-
- /** the test suites, which each contain tests */
- private final Map<String, Suite> suites = new LinkedHashMap<String, Suite>();
-
- /**
- * Create a report printer that prints the specified test suite. Since the
- * CoreTestSuite nulls-out tests after they're run (to limit memory
- * consumption), it is necessary to create the report printer prior to test
- * execution.
- */
- public XmlReportPrinter(CoreTestSuite allTests) {
- // partition the tests by suite to be consistent with Ant's printer
- for (Enumeration<Test> e = allTests.tests(); e.hasMoreElements(); ) {
- TestId test = new TestId(e.nextElement());
-
- // create the suite's entry in the map if necessary
- Suite suite = suites.get(test.className);
- if (suite == null) {
- suite = new Suite(test.className);
- suites.put(test.className, suite);
- }
-
- suite.tests.add(test);
- }
- }
-
- public void setResults(TestResult result) {
- populateFailures(true, result.errors());
- populateFailures(false, result.failures());
- }
-
- /**
- * Populate the list of failures in each of the suites.
- */
- private void populateFailures(boolean errors, Enumeration<TestFailure> failures) {
- while (failures.hasMoreElements()) {
- TestFailure failure = failures.nextElement();
- TestId test = new TestId(failure.failedTest());
- Suite suite = suites.get(test.className);
-
- if (suite == null) {
- throw new IllegalStateException( "received a failure for a "
- + "test that wasn't in the original test suite!");
- }
-
- if (errors) {
- suite.errors.put(test, failure);
- } else {
- suite.failures.put(test, failure);
- }
- }
- }
-
- public int generateReports(String directory) {
- File parent = new File(directory);
- parent.mkdirs();
-
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
- TimeZone gmt = TimeZone.getTimeZone("GMT");
- dateFormat.setTimeZone(gmt);
- dateFormat.setLenient(true);
- String timestamp = dateFormat.format(new Date());
-
- for (Suite suite : suites.values()) {
- FileOutputStream stream = null;
- try {
- stream = new FileOutputStream(new File(parent, "TEST-" + suite.name + ".xml"));
-
- KXmlSerializer serializer = new KXmlSerializer();
- serializer.setOutput(stream, "UTF-8");
- serializer.startDocument("UTF-8", null);
- serializer.setFeature(
- "http://xmlpull.org/v1/doc/features.html#indent-output", true);
- suite.print(serializer, timestamp);
- serializer.endDocument();
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException ignored) {
- ignored.printStackTrace();
- }
- }
- }
- }
-
- return suites.size();
- }
-
- static class Suite {
- private final String name;
- private final List<TestId> tests = new ArrayList<TestId>();
- private final Map<TestId, TestFailure> failures = new HashMap<TestId, TestFailure>();
- private final Map<TestId, TestFailure> errors = new HashMap<TestId, TestFailure>();
-
- Suite(String name) {
- this.name = name;
- }
-
- void print(KXmlSerializer serializer, String timestamp) throws IOException {
- serializer.startTag(ns, TESTSUITE);
- serializer.attribute(ns, ATTR_NAME, name);
- serializer.attribute(ns, ATTR_TESTS, Integer.toString(tests.size()));
- serializer.attribute(ns, ATTR_FAILURES, Integer.toString(failures.size()));
- serializer.attribute(ns, ATTR_ERRORS, Integer.toString(errors.size()));
- serializer.attribute(ns, ATTR_TIME, "0");
-
- serializer.attribute(ns, TIMESTAMP, timestamp);
- serializer.attribute(ns, HOSTNAME, "localhost");
- serializer.startTag(ns, PROPERTIES);
- serializer.endTag(ns, PROPERTIES);
-
- for (TestId testId : tests) {
- TestFailure error = errors.get(testId);
- TestFailure failure = failures.get(testId);
-
- if (error != null) {
- testId.printFailure(serializer, ERROR, error.thrownException());
- } else if (failure != null) {
- testId.printFailure(serializer, FAILURE, failure.thrownException());
- } else {
- testId.printSuccess(serializer);
- }
- }
-
- serializer.endTag(ns, TESTSUITE);
- }
- }
-
- private static class TestId {
- private final String name;
- private final String className;
-
- TestId(Test test) {
- this.name = test instanceof TestCase
- ? ((TestCase) test).getName()
- : test.toString();
- this.className = test.getClass().getName();
- }
-
- void printSuccess(KXmlSerializer serializer) throws IOException {
- serializer.startTag(ns, TESTCASE);
- printAttributes(serializer);
- serializer.endTag(ns, TESTCASE);
- }
-
- void printFailure(KXmlSerializer serializer, String type, Throwable t)
- throws IOException {
- serializer.startTag(ns, TESTCASE);
- printAttributes(serializer);
-
- serializer.startTag(ns, type);
- String message = t.getMessage();
- if (message != null && message.length() > 0) {
- serializer.attribute(ns, ATTR_MESSAGE, t.getMessage());
- }
- serializer.attribute(ns, ATTR_TYPE, t.getClass().getName());
- serializer.text(sanitize(BaseTestRunner.getFilteredTrace(t)));
- serializer.endTag(ns, type);
-
- serializer.endTag(ns, TESTCASE);
- }
-
- void printAttributes(KXmlSerializer serializer) throws IOException {
- serializer.attribute(ns, ATTR_NAME, name);
- serializer.attribute(ns, ATTR_CLASSNAME, className);
- serializer.attribute(ns, ATTR_TIME, "0");
- }
-
- @Override public boolean equals(Object o) {
- return o instanceof TestId
- && ((TestId) o).name.equals(name)
- && ((TestId) o).className.equals(className);
- }
-
- @Override public int hashCode() {
- return name.hashCode() ^ className.hashCode();
- }
-
- /**
- * Returns the text in a format that is safe for use in an XML document.
- */
- private static String sanitize(String text) {
- return text.replace("\0", "<\\0>");
- }
- }
-}
diff --git a/luni/src/test/java/com/ibm/icu4jni/util/ICUTest.java b/luni/src/test/java/com/ibm/icu4jni/util/ICUTest.java
deleted file mode 100644
index c950e0a..0000000
--- a/luni/src/test/java/com/ibm/icu4jni/util/ICUTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.ibm.icu4jni.util;
-
-import java.util.Locale;
-
-public class ICUTest extends junit.framework.TestCase {
- public void test_getISOLanguages() throws Exception {
- // Check that corrupting our array doesn't affect other callers.
- assertNotNull(ICU.getISOLanguages()[0]);
- ICU.getISOLanguages()[0] = null;
- assertNotNull(ICU.getISOLanguages()[0]);
- }
-
- public void test_getISOCountries() throws Exception {
- // Check that corrupting our array doesn't affect other callers.
- assertNotNull(ICU.getISOCountries()[0]);
- ICU.getISOCountries()[0] = null;
- assertNotNull(ICU.getISOCountries()[0]);
- }
-
- public void test_getAvailableLocales() throws Exception {
- // Check that corrupting our array doesn't affect other callers.
- assertNotNull(ICU.getAvailableLocales()[0]);
- ICU.getAvailableLocales()[0] = null;
- assertNotNull(ICU.getAvailableLocales()[0]);
- }
-
- public void test_localeFromString() throws Exception {
- // localeFromString is pretty lenient. Some of these can't be round-tripped
- // through Locale.toString.
- assertEquals(Locale.ENGLISH, ICU.localeFromString("en"));
- assertEquals(Locale.ENGLISH, ICU.localeFromString("en_"));
- assertEquals(Locale.ENGLISH, ICU.localeFromString("en__"));
- assertEquals(Locale.US, ICU.localeFromString("en_US"));
- assertEquals(Locale.US, ICU.localeFromString("en_US_"));
- assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US"));
- assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US_"));
- assertEquals(new Locale("", "", "POSIX"), ICU.localeFromString("__POSIX"));
- assertEquals(new Locale("aa", "BB", "CC"), ICU.localeFromString("aa_BB_CC"));
- }
-}
diff --git a/luni/src/test/java/dalvik/system/DexClassLoaderTest.java b/luni/src/test/java/dalvik/system/DexClassLoaderTest.java
new file mode 100644
index 0000000..f667789
--- /dev/null
+++ b/luni/src/test/java/dalvik/system/DexClassLoaderTest.java
@@ -0,0 +1,465 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dalvik.system;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import libcore.base.Streams;
+import junit.framework.TestCase;
+
+/**
+ * Tests for the class {@link DexClassLoader}.
+ */
+public class DexClassLoaderTest extends TestCase {
+ private static final File TMP_DIR =
+ new File(System.getProperty("java.io.tmpdir"), "loading-test");
+ private static final String PACKAGE_PATH = "dalvik/system/";
+ private static final String JAR_NAME = "loading-test.jar";
+ private static final String DEX_NAME = "loading-test.dex";
+ private static final String JAR2_NAME = "loading-test2.jar";
+ private static final String DEX2_NAME = "loading-test2.dex";
+ private static final File JAR_FILE = new File(TMP_DIR, JAR_NAME);
+ private static final File DEX_FILE = new File(TMP_DIR, DEX_NAME);
+ private static final File JAR2_FILE = new File(TMP_DIR, JAR2_NAME);
+ private static final File DEX2_FILE = new File(TMP_DIR, DEX2_NAME);
+
+ private static enum Configuration {
+ /** just one classpath element, a raw dex file */
+ ONE_DEX,
+
+ /** just one classpath element, a jar file */
+ ONE_JAR,
+
+ /** two classpath elements, both raw dex files */
+ TWO_DEX,
+
+ /** two classpath elements, both jar files */
+ TWO_JAR;
+ }
+
+ protected void setUp() throws IOException {
+ TMP_DIR.mkdirs();
+
+ ClassLoader cl = DexClassLoaderTest.class.getClassLoader();
+ copyResource(cl, JAR_NAME, JAR_FILE);
+ copyResource(cl, DEX_NAME, DEX_FILE);
+ copyResource(cl, JAR2_NAME, JAR2_FILE);
+ copyResource(cl, DEX2_NAME, DEX2_FILE);
+ }
+
+ /**
+ * Copy a resource in the package directory to the indicated file.
+ */
+ private static void copyResource(ClassLoader loader, String resourceName,
+ File destination) throws IOException {
+ InputStream in =
+ loader.getResourceAsStream(PACKAGE_PATH + resourceName);
+ FileOutputStream out = new FileOutputStream(destination);
+ Streams.copy(in, out);
+ in.close();
+ out.close();
+ }
+
+ /**
+ * Helper to construct an instance to test.
+ *
+ * @param config how to configure the classpath
+ */
+ private static DexClassLoader createInstance(Configuration config) {
+ File file1;
+ File file2;
+
+ switch (config) {
+ case ONE_DEX: file1 = DEX_FILE; file2 = null; break;
+ case ONE_JAR: file1 = JAR_FILE; file2 = null; break;
+ case TWO_DEX: file1 = DEX_FILE; file2 = DEX2_FILE; break;
+ case TWO_JAR: file1 = JAR_FILE; file2 = JAR2_FILE; break;
+ default: throw new AssertionError("shouldn't happen");
+ }
+
+ String path = file1.getAbsolutePath();
+ if (file2 != null) {
+ path += File.pathSeparator + file2.getAbsolutePath();
+ }
+
+ return new DexClassLoader(
+ path, TMP_DIR.getAbsolutePath(), null,
+ ClassLoader.getSystemClassLoader());
+ }
+
+ /**
+ * Helper to construct an instance to test, using the jar file as
+ * the source, and call a named no-argument static method on a
+ * named class.
+ *
+ * @param config how to configure the classpath
+ */
+ public static Object createInstanceAndCallStaticMethod(
+ Configuration config, String className, String methodName)
+ throws ClassNotFoundException, NoSuchMethodException,
+ IllegalAccessException, InvocationTargetException {
+ DexClassLoader dcl = createInstance(config);
+ Class c = dcl.loadClass(className);
+ Method m = c.getMethod(methodName, (Class[]) null);
+ return m.invoke(null, (Object[]) null);
+ }
+
+ /*
+ * Tests that are parametric with respect to whether to use a jar
+ * file or a dex file as the source of the code
+ */
+
+ /**
+ * Just a trivial test of construction. This one merely makes
+ * sure that a valid construction doesn't fail; it doesn't try
+ * to verify anything about the constructed instance. (Other
+ * tests will do that.)
+ */
+ public static void test_init(Configuration config) {
+ createInstance(config);
+ }
+
+ /**
+ * Check that a class in the jar/dex file may be used successfully. In this
+ * case, a trivial static method is called.
+ */
+ public static void test_simpleUse(Configuration config) throws Exception {
+ String result = (String)
+ createInstanceAndCallStaticMethod(config, "test.Test1", "test");
+
+ assertSame("blort", result);
+ }
+
+ /*
+ * All the following tests are just pass-throughs to test code
+ * that lives inside the loading-test dex/jar file.
+ */
+
+ public static void test_constructor(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_constructor");
+ }
+
+ public static void test_callStaticMethod(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_callStaticMethod");
+ }
+
+ public static void test_getStaticVariable(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_getStaticVariable");
+ }
+
+ public static void test_callInstanceMethod(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_callInstanceMethod");
+ }
+
+ public static void test_getInstanceVariable(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_getInstanceVariable");
+ }
+
+ public static void test_diff_constructor(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_diff_constructor");
+ }
+
+ public static void test_diff_callStaticMethod(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_diff_callStaticMethod");
+ }
+
+ public static void test_diff_getStaticVariable(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_diff_getStaticVariable");
+ }
+
+ public static void test_diff_callInstanceMethod(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_diff_callInstanceMethod");
+ }
+
+ public static void test_diff_getInstanceVariable(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_diff_getInstanceVariable");
+ }
+
+ /*
+ * These methods are all essentially just calls to the
+ * parametrically-defined tests above.
+ */
+
+ // ONE_JAR
+
+ public void test_oneJar_init() throws Exception {
+ test_init(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_simpleUse() throws Exception {
+ test_simpleUse(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_constructor() throws Exception {
+ test_constructor(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_callStaticMethod() throws Exception {
+ test_callStaticMethod(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_getStaticVariable() throws Exception {
+ test_getStaticVariable(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_callInstanceMethod() throws Exception {
+ test_callInstanceMethod(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_getInstanceVariable() throws Exception {
+ test_getInstanceVariable(Configuration.ONE_JAR);
+ }
+
+ // ONE_DEX
+
+ public void test_oneDex_init() throws Exception {
+ test_init(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_simpleUse() throws Exception {
+ test_simpleUse(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_constructor() throws Exception {
+ test_constructor(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_callStaticMethod() throws Exception {
+ test_callStaticMethod(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_getStaticVariable() throws Exception {
+ test_getStaticVariable(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_callInstanceMethod() throws Exception {
+ test_callInstanceMethod(Configuration.ONE_DEX);
+ }
+
+ public void test_oneDex_getInstanceVariable() throws Exception {
+ test_getInstanceVariable(Configuration.ONE_DEX);
+ }
+
+ // TWO_JAR
+
+ public void test_twoJar_init() throws Exception {
+ test_init(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_simpleUse() throws Exception {
+ test_simpleUse(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_constructor() throws Exception {
+ test_constructor(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_callStaticMethod() throws Exception {
+ test_callStaticMethod(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_getStaticVariable() throws Exception {
+ test_getStaticVariable(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_callInstanceMethod() throws Exception {
+ test_callInstanceMethod(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_getInstanceVariable() throws Exception {
+ test_getInstanceVariable(Configuration.TWO_JAR);
+ }
+
+ public static void test_twoJar_diff_constructor() throws Exception {
+ test_diff_constructor(Configuration.TWO_JAR);
+ }
+
+ public static void test_twoJar_diff_callStaticMethod() throws Exception {
+ test_diff_callStaticMethod(Configuration.TWO_JAR);
+ }
+
+ public static void test_twoJar_diff_getStaticVariable() throws Exception {
+ test_diff_getStaticVariable(Configuration.TWO_JAR);
+ }
+
+ public static void test_twoJar_diff_callInstanceMethod()
+ throws Exception {
+ test_diff_callInstanceMethod(Configuration.TWO_JAR);
+ }
+
+ public static void test_twoJar_diff_getInstanceVariable()
+ throws Exception {
+ test_diff_getInstanceVariable(Configuration.TWO_JAR);
+ }
+
+ // TWO_DEX
+
+ public void test_twoDex_init() throws Exception {
+ test_init(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_simpleUse() throws Exception {
+ test_simpleUse(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_constructor() throws Exception {
+ test_constructor(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_callStaticMethod() throws Exception {
+ test_callStaticMethod(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_getStaticVariable() throws Exception {
+ test_getStaticVariable(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_callInstanceMethod() throws Exception {
+ test_callInstanceMethod(Configuration.TWO_DEX);
+ }
+
+ public void test_twoDex_getInstanceVariable() throws Exception {
+ test_getInstanceVariable(Configuration.TWO_DEX);
+ }
+
+ public static void test_twoDex_diff_constructor() throws Exception {
+ test_diff_constructor(Configuration.TWO_DEX);
+ }
+
+ public static void test_twoDex_diff_callStaticMethod() throws Exception {
+ test_diff_callStaticMethod(Configuration.TWO_DEX);
+ }
+
+ public static void test_twoDex_diff_getStaticVariable() throws Exception {
+ test_diff_getStaticVariable(Configuration.TWO_DEX);
+ }
+
+ public static void test_twoDex_diff_callInstanceMethod()
+ throws Exception {
+ test_diff_callInstanceMethod(Configuration.TWO_DEX);
+ }
+
+ public static void test_twoDex_diff_getInstanceVariable()
+ throws Exception {
+ test_diff_getInstanceVariable(Configuration.TWO_DEX);
+ }
+
+ /*
+ * Tests specifically for resource-related functionality. Since
+ * raw dex files don't contain resources, these test only work
+ * with jar files. The first couple methods here are helpers,
+ * and they are followed by the tests per se.
+ */
+
+ /**
+ * Check that a given resource (by name) is retrievable and contains
+ * the given expected contents.
+ */
+ public static void test_directGetResourceAsStream(Configuration config,
+ String resourceName, String expectedContents)
+ throws Exception {
+ DexClassLoader dcl = createInstance(config);
+ InputStream in = dcl.getResourceAsStream(resourceName);
+ byte[] contents = Streams.readFully(in);
+ String s = new String(contents, "UTF-8");
+
+ assertEquals(expectedContents, s);
+ }
+
+ /**
+ * Check that a resource in the jar file is retrievable and contains
+ * the expected contents.
+ */
+ public static void test_directGetResourceAsStream(Configuration config)
+ throws Exception {
+ test_directGetResourceAsStream(
+ config, "test/Resource1.txt", "Muffins are tasty!\n");
+ }
+
+ /**
+ * Check that a resource in the jar file can be retrieved from
+ * a class within that jar file.
+ */
+ public static void test_getResourceAsStream(Configuration config)
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ config, "test.TestMethods", "test_getResourceAsStream");
+ }
+
+ public void test_oneJar_directGetResourceAsStream() throws Exception {
+ test_directGetResourceAsStream(Configuration.ONE_JAR);
+ }
+
+ public void test_oneJar_getResourceAsStream() throws Exception {
+ test_getResourceAsStream(Configuration.ONE_JAR);
+ }
+
+ public void test_twoJar_directGetResourceAsStream() throws Exception {
+ test_directGetResourceAsStream(Configuration.TWO_JAR);
+ }
+
+ public void test_twoJar_getResourceAsStream() throws Exception {
+ test_getResourceAsStream(Configuration.TWO_JAR);
+ }
+
+ /**
+ * Check that a resource in the second jar file is retrievable and
+ * contains the expected contents.
+ */
+ public static void test_twoJar_diff_directGetResourceAsStream()
+ throws Exception {
+ test_directGetResourceAsStream(
+ Configuration.TWO_JAR, "test2/Resource2.txt",
+ "Who doesn't like a good biscuit?\n");
+ }
+
+ /**
+ * Check that a resource in a jar file can be retrieved from
+ * a class within the other jar file.
+ */
+ public static void test_twoJar_diff_getResourceAsStream()
+ throws Exception {
+ createInstanceAndCallStaticMethod(
+ Configuration.TWO_JAR, "test.TestMethods",
+ "test_diff_getResourceAsStream");
+ }
+}
diff --git a/luni/src/test/java/libcore/base/CollectionUtilsTest.java b/luni/src/test/java/libcore/base/CollectionUtilsTest.java
new file mode 100644
index 0000000..1c92a46
--- /dev/null
+++ b/luni/src/test/java/libcore/base/CollectionUtilsTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.base;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import junit.framework.TestCase;
+
+public final class CollectionUtilsTest extends TestCase {
+
+ public void testDereferenceIterable() {
+ List<Reference<String>> refs = new ArrayList<Reference<String>>();
+ refs.add(newLiteralReference("a"));
+ refs.add(newLiteralReference("b"));
+ refs.add(newLiteralReference("c"));
+ refs.add(newLiteralReference("d"));
+ refs.add(newLiteralReference("e"));
+
+ Iterable<String> strings = CollectionUtils.dereferenceIterable(refs, true);
+ assertEquals(Arrays.<String>asList("a", "b", "c", "d", "e"), toList(strings));
+
+ refs.get(1).clear(); // b
+ assertEquals(Arrays.<String>asList("a", "c", "d", "e"), toList(strings));
+ assertEquals(4, refs.size());
+
+ Iterator<String> i = strings.iterator();
+ assertEquals("a", i.next());
+ i.remove();
+ assertEquals(3, refs.size());
+ assertEquals("c", i.next());
+ assertEquals("d", i.next());
+ assertTrue(i.hasNext());
+ try {
+ i.remove();
+ fail("Expected hasNext() to make remove() impossible.");
+ } catch (IllegalStateException expected) {
+ }
+ assertEquals("e", i.next());
+ i.remove();
+ assertEquals(2, refs.size());
+ assertFalse(i.hasNext());
+
+ refs.get(0).clear(); // c
+ refs.get(1).clear(); // d
+ assertEquals(Arrays.<String>asList(), toList(strings));
+ }
+
+ private <T> List<T> toList(Iterable<T> iterable) {
+ List<T> result = new ArrayList<T>();
+ for (T t : iterable) {
+ result.add(t);
+ }
+ return result;
+ }
+
+ /**
+ * A reference that must be manually cleared.
+ */
+ public Reference<String> newLiteralReference(String s) {
+ return new WeakReference<String>(s);
+ }
+}
diff --git a/luni/src/test/java/libcore/icu/ICUTest.java b/luni/src/test/java/libcore/icu/ICUTest.java
new file mode 100644
index 0000000..9282167
--- /dev/null
+++ b/luni/src/test/java/libcore/icu/ICUTest.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.icu;
+
+import java.util.Locale;
+
+public class ICUTest extends junit.framework.TestCase {
+ public void test_getISOLanguages() throws Exception {
+ // Check that corrupting our array doesn't affect other callers.
+ assertNotNull(ICU.getISOLanguages()[0]);
+ ICU.getISOLanguages()[0] = null;
+ assertNotNull(ICU.getISOLanguages()[0]);
+ }
+
+ public void test_getISOCountries() throws Exception {
+ // Check that corrupting our array doesn't affect other callers.
+ assertNotNull(ICU.getISOCountries()[0]);
+ ICU.getISOCountries()[0] = null;
+ assertNotNull(ICU.getISOCountries()[0]);
+ }
+
+ public void test_getAvailableLocales() throws Exception {
+ // Check that corrupting our array doesn't affect other callers.
+ assertNotNull(ICU.getAvailableLocales()[0]);
+ ICU.getAvailableLocales()[0] = null;
+ assertNotNull(ICU.getAvailableLocales()[0]);
+ }
+
+ public void test_localeFromString() throws Exception {
+ // localeFromString is pretty lenient. Some of these can't be round-tripped
+ // through Locale.toString.
+ assertEquals(Locale.ENGLISH, ICU.localeFromString("en"));
+ assertEquals(Locale.ENGLISH, ICU.localeFromString("en_"));
+ assertEquals(Locale.ENGLISH, ICU.localeFromString("en__"));
+ assertEquals(Locale.US, ICU.localeFromString("en_US"));
+ assertEquals(Locale.US, ICU.localeFromString("en_US_"));
+ assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US"));
+ assertEquals(new Locale("", "US", ""), ICU.localeFromString("_US_"));
+ assertEquals(new Locale("", "", "POSIX"), ICU.localeFromString("__POSIX"));
+ assertEquals(new Locale("aa", "BB", "CC"), ICU.localeFromString("aa_BB_CC"));
+ }
+}
diff --git a/luni/src/test/java/libcore/internal/StringPoolTest.java b/luni/src/test/java/libcore/internal/StringPoolTest.java
new file mode 100644
index 0000000..82c7c4e
--- /dev/null
+++ b/luni/src/test/java/libcore/internal/StringPoolTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.internal;
+
+import junit.framework.TestCase;
+import libcore.internal.StringPool;
+
+public final class StringPoolTest extends TestCase {
+
+ public void testStringPool() {
+ StringPool stringPool = new StringPool();
+ String bcd = stringPool.get(new char[] { 'a', 'b', 'c', 'd', 'e' }, 1, 3);
+ assertEquals("bcd", bcd);
+ assertSame(bcd, stringPool.get(new char[] { 'a', 'b', 'c', 'd', 'e' }, 1, 3));
+ }
+
+ public void testHashCollision() {
+ StringPool stringPool = new StringPool();
+ char[] a = { (char) 1, (char) 0 };
+ char[] b = { (char) 0, (char) 31 };
+ assertEquals(new String(a).hashCode(), new String(b).hashCode());
+
+ String aString = stringPool.get(a, 0, 2);
+ assertEquals(new String(a), aString);
+ String bString = stringPool.get(b, 0, 2);
+ assertEquals(new String(b), bString);
+ assertSame(bString, stringPool.get(b, 0, 2));
+ assertNotSame(aString, stringPool.get(a, 0, 2));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/DataOutputStreamTest.java b/luni/src/test/java/libcore/java/io/DataOutputStreamTest.java
new file mode 100644
index 0000000..666a44e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/DataOutputStreamTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.UTFDataFormatException;
+import java.util.Arrays;
+import junit.framework.TestCase;
+
+public final class DataOutputStreamTest extends TestCase {
+ private ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ private DataOutputStream os = new DataOutputStream(bytes);
+
+ public void test_writeBoolean() throws Exception {
+ os.writeBoolean(true);
+ os.writeBoolean(false);
+ assertEquals("[01, 00]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeByte() throws Exception {
+ os.writeByte(-1);
+ os.writeByte(0);
+ os.writeByte(1);
+ os.writeByte(129);
+ // writeByte takes only the bottom byte from its int parameter.
+ os.writeByte(0x1234);
+ assertEquals("[ff, 00, 01, 81, 34]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeBytes() throws Exception {
+ // writeBytes takes only the bottom byte from each character.
+ os.writeBytes("0\u12341");
+ assertEquals("[30, 34, 31]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeChar() throws Exception {
+ // writeChar writes two-byte big-endian characters.
+ os.writeChar('0');
+ os.writeChar(0x1234);
+ assertEquals("[00, 30, 12, 34]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeChars() throws Exception {
+ // writeChars writes two-byte big-endian characters.
+ os.writeChars("0\u12341");
+ assertEquals("[00, 30, 12, 34, 00, 31]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeDouble() throws Exception {
+ os.writeDouble(Double.longBitsToDouble(0x0123456789abcdefL));
+ assertEquals("[01, 23, 45, 67, 89, ab, cd, ef]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeFloat() throws Exception {
+ os.writeFloat(Float.intBitsToFloat(0x01234567));
+ assertEquals("[01, 23, 45, 67]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeInt() throws Exception {
+ os.writeInt(0x01234567);
+ assertEquals("[01, 23, 45, 67]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeLong() throws Exception {
+ os.writeLong(0x0123456789abcdefL);
+ assertEquals("[01, 23, 45, 67, 89, ab, cd, ef]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeShort() throws Exception {
+ // writeShort only writes the bottommost 16 bits of its int parameter.
+ os.writeShort(0x01234567);
+ assertEquals("[45, 67]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeUTF() throws Exception {
+ // The limit is 65535 *bytes* but we want to test 2- and 3-byte characters too.
+ char[] chars = new char[65535 - 1 - 2];
+ Arrays.fill(chars, 0, chars.length, 'a');
+ chars[0] = '\u0666'; // a two-byte character
+ chars[1] = '\u2603'; // a three-byte character
+ String maxLength = new String(chars);
+ os.writeUTF(maxLength);
+ byte[] expected = new byte[2 + 65535];
+ expected[0] = (byte) 0xff;
+ expected[1] = (byte) 0xff;
+ // U+0666 = 0xD9 0xA6
+ expected[2] = (byte) 0xd9;
+ expected[3] = (byte) 0xa6;
+ // U+2603 = 0xE2 0x98 0x83
+ expected[4] = (byte) 0xe2;
+ expected[5] = (byte) 0x98;
+ expected[6] = (byte) 0x83;
+ Arrays.fill(expected, 7, expected.length, (byte) 'a');
+ assertEquals(Arrays.toString(expected), Arrays.toString(bytes.toByteArray()));
+ }
+
+ public void test_writeUTF_NUL() throws Exception {
+ // This is a special case, represented with two non-zero bytes.
+ os.writeUTF("\u0000");
+ assertEquals("[00, 02, c0, 80]", toHexString(bytes.toByteArray()));
+ }
+
+ public void test_writeUTF_too_long() throws Exception {
+ String tooLong = new String(new char[65536]);
+ try {
+ os.writeUTF(tooLong);
+ fail("should throw UTFDataFormatException");
+ } catch (UTFDataFormatException expected) {
+ }
+ assertEquals("[]", toHexString(bytes.toByteArray()));
+ }
+
+ /**
+ * Returns a string representation of a byte array that's more useful for debugging.
+ * TODO: move this somewhere where it's available to all tests.
+ */
+ public static String toHexString(byte[] array) {
+ if (array == null) {
+ return null;
+ }
+ if (array.length == 0) {
+ return "[]";
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append('[');
+ // TODO: don't use String.format if we put this in the library. Too expensive!
+ sb.append(String.format("%02x", array[0] & 0xff));
+ for (int i = 1; i < array.length; i++) {
+ sb.append(", ");
+ sb.append(String.format("%02x", array[i] & 0xff));
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/FileInputStreamTest.java b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java
new file mode 100644
index 0000000..d622afc
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/FileInputStreamTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+import libcore.io.IoUtils;
+
+public final class FileInputStreamTest extends TestCase {
+ private static final int TOTAL_SIZE = 1024;
+ private static final int SKIP_SIZE = 100;
+
+ private static void createPipes(FileDescriptor pipe[]) throws IOException {
+ int fds[] = new int[2];
+ IoUtils.pipe(fds);
+ pipe[0] = IoUtils.newFileDescriptor(fds[0]);
+ pipe[1] = IoUtils.newFileDescriptor(fds[1]);
+ }
+
+ private static class DataFeeder extends Thread {
+ private FileDescriptor mOutFd;
+
+ public DataFeeder(FileDescriptor fd) {
+ mOutFd = fd;
+ }
+
+ @Override
+ public void run() {
+ try {
+ FileOutputStream fos = new FileOutputStream(mOutFd);
+ try {
+ byte[] buffer = new byte[TOTAL_SIZE];
+ for (int i = 0; i < buffer.length; ++i) {
+ buffer[i] = (byte) i;
+ }
+ fos.write(buffer);
+ } finally {
+ IoUtils.closeQuietly(fos);
+ IoUtils.close(mOutFd);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private void verifyData(FileInputStream is, int start, int count)
+ throws IOException {
+ byte buffer[] = new byte[count];
+ assertEquals(count, is.read(buffer));
+ for (int i = 0; i < count; ++i) {
+ assertEquals((byte) (i + start), buffer[i]);
+ }
+ }
+
+ private static void closeQuietly(FileDescriptor fd) {
+ try {
+ if (fd != null) IoUtils.close(fd);
+ } catch (Throwable t) {}
+ }
+
+ public void testSkipInPipes() throws Exception {
+ FileDescriptor pipe[] = new FileDescriptor[2];
+ createPipes(pipe);
+ DataFeeder feeder = new DataFeeder(pipe[1]);
+ try {
+ feeder.start();
+ FileInputStream fis = new FileInputStream(pipe[0]);
+ fis.skip(SKIP_SIZE);
+ verifyData(fis, SKIP_SIZE, TOTAL_SIZE - SKIP_SIZE);
+ assertEquals(-1, fis.read());
+ feeder.join(1000);
+ assertFalse(feeder.isAlive());
+ } finally {
+ closeQuietly(pipe[0]);
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/FileTest.java b/luni/src/test/java/libcore/java/io/FileTest.java
index cd9b877..535975d 100644
--- a/luni/src/test/java/libcore/java/io/FileTest.java
+++ b/luni/src/test/java/libcore/java/io/FileTest.java
@@ -186,18 +186,6 @@ public class FileTest extends junit.framework.TestCase {
}
private static void ln_s(String target, String linkName) throws Exception {
- String[] args = new String[] { "ln", "-s", target, linkName };
- // System.err.println("ln -s " + target + " " + linkName);
- Process p = Runtime.getRuntime().exec(args);
- int result = p.waitFor();
- if (result != 0) {
- BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
- String line;
- while ((line = r.readLine()) != null) {
- System.err.println(line);
- }
- fail("ln -s " + target + " " + linkName + " failed. " +
- "Does that file system support symlinks?");
- }
+ File.symlink(target, linkName);
}
}
diff --git a/luni/src/test/java/libcore/java/io/ObjectOutputStreamTest.java b/luni/src/test/java/libcore/java/io/ObjectOutputStreamTest.java
new file mode 100644
index 0000000..9228162
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/ObjectOutputStreamTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import junit.framework.TestCase;
+
+public final class ObjectOutputStreamTest extends TestCase {
+ public void testLongString() throws Exception {
+ // Most modified UTF-8 is limited to 64KiB, but serialized strings can have an 8-byte
+ // length, so this should never throw java.io.UTFDataFormatException...
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 64*1024 * 2; ++i) {
+ sb.append('a');
+ }
+ String s = sb.toString();
+ ObjectOutputStream os = new ObjectOutputStream(new ByteArrayOutputStream());
+ os.writeObject(s);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidBufferedInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidBufferedInputStreamTest.java
new file mode 100644
index 0000000..95ef22e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidBufferedInputStreamTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that simple functionality works for BufferedInputStreams.
+ */
+public class OldAndroidBufferedInputStreamTest extends TestCase {
+
+ public void testBufferedInputStream() throws Exception {
+ String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
+ ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream da = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ea = new ByteArrayInputStream(str.getBytes());
+
+ BufferedInputStream a = new BufferedInputStream(aa, 6);
+ try {
+ Assert.assertEquals(str, read(a));
+ } finally {
+ a.close();
+ }
+
+ BufferedInputStream b = new BufferedInputStream(ba, 7);
+ try {
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ BufferedInputStream c = new BufferedInputStream(ca, 9);
+ try {
+ assertEquals("bdfhjl\nprtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+
+ BufferedInputStream d = new BufferedInputStream(da, 9);
+ try {
+ assertEquals('A', d.read());
+ d.mark(15);
+ assertEquals('b', d.read());
+ assertEquals('C', d.read());
+ d.reset();
+ assertEquals('b', d.read());
+ } finally {
+ d.close();
+ }
+
+ BufferedInputStream e = new BufferedInputStream(ea, 11);
+ try {
+ // test that we can ask for more than is present, and that we'll get
+ // back only what is there.
+ assertEquals(str, read(e, 10000));
+ } finally {
+ e.close();
+ }
+ }
+
+ public static String read(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String skipRead(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(InputStream a, int x) throws IOException {
+ byte[] b = new byte[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidBufferedOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidBufferedOutputStreamTest.java
new file mode 100644
index 0000000..6d5a251
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidBufferedOutputStreamTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that simple functionality works for BufferedOutputStreams.
+ */
+public class OldAndroidBufferedOutputStreamTest extends TestCase {
+
+ public void testBufferedOutputStream() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ ByteArrayOutputStream aa = new ByteArrayOutputStream();
+ BufferedOutputStream a = new BufferedOutputStream(aa, 15);
+ try {
+ a.write(str.getBytes(), 0, 26);
+ a.write('A');
+
+ assertEquals(26, aa.size());
+ assertEquals(aa.toString(), str);
+
+ a.flush();
+
+ assertEquals(27, aa.size());
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzA", aa.toString());
+ } finally {
+ a.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidBufferedReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidBufferedReaderTest.java
new file mode 100644
index 0000000..0c8dc13
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidBufferedReaderTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that simple functionality works for BufferedReaders.
+ */
+public class OldAndroidBufferedReaderTest extends TestCase {
+
+ public void testBufferedReader() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(str);
+ StringReader ca = new StringReader(str);
+ StringReader da = new StringReader(str);
+
+ BufferedReader a = new BufferedReader(aa, 5);
+ try {
+ assertEquals(str, read(a));
+ } finally {
+ a.close();
+ }
+
+ BufferedReader b = new BufferedReader(ba, 15);
+ try {
+ assertEquals("AbCdEfGhIj", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ BufferedReader c = new BufferedReader(ca);
+ try {
+ assertEquals("bdfhjlnprtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+
+ BufferedReader d = new BufferedReader(da);
+ try {
+ assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", markRead(d, 3, 4));
+ } finally {
+ d.close();
+ }
+ }
+
+ public static String read(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(Reader a, int x) throws IOException {
+ char[] b = new char[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(Reader a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidBufferedWriterTest.java b/luni/src/test/java/libcore/java/io/OldAndroidBufferedWriterTest.java
new file mode 100644
index 0000000..27f1214
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidBufferedWriterTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedWriter;
+import java.io.StringWriter;
+import junit.framework.TestCase;
+
+/**
+ * Some basic tests for BufferedWriter.
+ */
+public class OldAndroidBufferedWriterTest extends TestCase {
+
+ public void testBufferedWriter() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ StringWriter aa = new StringWriter();
+
+ BufferedWriter a = new BufferedWriter(aa, 20);
+ try {
+ a.write(str.toCharArray(), 0, 26);
+ a.write('X');
+ a.flush();
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", aa.toString());
+
+ a.write("alphabravodelta", 5, 5);
+ a.flush();
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravo", aa.toString());
+ a.newLine();
+ a.write("I'm on a new line.");
+ a.flush();
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravo\nI\'m on a new line.", aa.toString());
+ } finally {
+ a.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidByteArrayInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidByteArrayInputStreamTest.java
new file mode 100644
index 0000000..164c1f3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidByteArrayInputStreamTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Tests to verify that simple functionality works for ByteArrayInputStreams.
+ */
+public class OldAndroidByteArrayInputStreamTest extends TestCase {
+
+ public void testByteArrayInputStream() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+
+ ByteArrayInputStream a = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream b = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream c = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream d = new ByteArrayInputStream(str.getBytes());
+
+ Assert.assertEquals(str, read(a));
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
+ Assert.assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", markRead(d, 3, 4));
+ }
+
+ public static String read(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(InputStream a, int x) throws IOException {
+ byte[] b = new byte[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(InputStream a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidByteArrayOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidByteArrayOutputStreamTest.java
new file mode 100644
index 0000000..dd3b791
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidByteArrayOutputStreamTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import junit.framework.TestCase;
+
+/**
+ * A basic test for ByteArrayOutputStream.
+ */
+public class OldAndroidByteArrayOutputStreamTest extends TestCase {
+
+ public void testByteArrayOutputStream() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ ByteArrayOutputStream a = new ByteArrayOutputStream();
+ ByteArrayOutputStream b = new ByteArrayOutputStream(10);
+
+ a.write(str.getBytes(), 0, 26);
+ a.write('X');
+ a.writeTo(b);
+
+ assertEquals(27, a.size());
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", a.toString());
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", b.toString());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidCharArrayReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidCharArrayReaderTest.java
new file mode 100644
index 0000000..8e6f8ce
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidCharArrayReaderTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.Reader;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Basic tests for CharArrayReader.
+ */
+public class OldAndroidCharArrayReaderTest extends TestCase {
+
+ public void testCharArrayReader() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ CharArrayReader a = new CharArrayReader(str.toCharArray());
+ CharArrayReader b = new CharArrayReader(str.toCharArray());
+ CharArrayReader c = new CharArrayReader(str.toCharArray());
+ CharArrayReader d = new CharArrayReader(str.toCharArray());
+
+ Assert.assertEquals(str, read(a));
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
+ Assert.assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", markRead(d, 3, 4));
+ }
+
+ public static String read(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(Reader a, int x) throws IOException {
+ char[] b = new char[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(Reader a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidDataInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidDataInputStreamTest.java
new file mode 100644
index 0000000..c97cb3a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidDataInputStreamTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class OldAndroidDataInputStreamTest extends TestCase {
+
+ public void testDataInputStream() throws Exception {
+ String str = "AbCdEfGhIjKlM\nOpQ\rStUvWxYz";
+ ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream da = new ByteArrayInputStream(str.getBytes());
+
+ DataInputStream a = new DataInputStream(aa);
+ try {
+ Assert.assertEquals(str, read(a));
+ } finally {
+ a.close();
+ }
+
+ DataInputStream b = new DataInputStream(ba);
+ try {
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ DataInputStream c = new DataInputStream(ca);
+ try {
+ Assert.assertEquals("bdfhjl\np\rtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+
+ DataInputStream d = new DataInputStream(da);
+ try {
+ assertEquals("AbCdEfGhIjKlM", d.readLine());
+ assertEquals("OpQ", d.readLine());
+ assertEquals("StUvWxYz", d.readLine());
+ } finally {
+ d.close();
+ }
+
+ ByteArrayOutputStream e = new ByteArrayOutputStream();
+ DataOutputStream f = new DataOutputStream(e);
+ try {
+ f.writeBoolean(true);
+ f.writeByte('a');
+ f.writeBytes("BCD");
+ f.writeChar('e');
+ f.writeChars("FGH");
+ f.writeUTF("ijklm");
+ f.writeDouble(1);
+ f.writeFloat(2);
+ f.writeInt(3);
+ f.writeLong(4);
+ f.writeShort(5);
+ } finally {
+ f.close();
+ }
+
+ ByteArrayInputStream ga = new ByteArrayInputStream(e.toByteArray());
+ DataInputStream g = new DataInputStream(ga);
+
+ try {
+ assertTrue(g.readBoolean());
+ assertEquals('a', g.readByte());
+ assertEquals(2, g.skipBytes(2));
+ assertEquals('D', g.readByte());
+ assertEquals('e', g.readChar());
+ assertEquals('F', g.readChar());
+ assertEquals('G', g.readChar());
+ assertEquals('H', g.readChar());
+ assertEquals("ijklm", g.readUTF());
+ assertEquals(1, g.readDouble(), 0);
+ assertEquals(2f, g.readFloat(), 0f);
+ assertEquals(3, g.readInt());
+ assertEquals(4, g.readLong());
+ assertEquals(5, g.readShort());
+ } finally {
+ g.close();
+ }
+ }
+
+ public static String read(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(InputStream a, int x) throws IOException {
+ byte[] b = new byte[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(InputStream a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidDataOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidDataOutputStreamTest.java
new file mode 100644
index 0000000..2d9fcda
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidDataOutputStreamTest.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import junit.framework.TestCase;
+
+/**
+ * Basic tests for DataOutputStreams.
+ */
+public class OldAndroidDataOutputStreamTest extends TestCase {
+
+ public void testDataOutputStream() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ ByteArrayOutputStream aa = new ByteArrayOutputStream();
+ DataOutputStream a = new DataOutputStream(aa);
+
+ try {
+ a.write(str.getBytes(), 0, 26);
+ a.write('A');
+
+ assertEquals(27, aa.size());
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzA", aa.toString());
+
+ a.writeByte('B');
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzAB", aa.toString());
+ a.writeBytes("BYTES");
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzABBYTES", aa.toString());
+ } finally {
+ a.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidFileTest.java b/luni/src/test/java/libcore/java/io/OldAndroidFileTest.java
new file mode 100644
index 0000000..7ceac0d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidFileTest.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import junit.framework.TestCase;
+
+/**
+ * Checks creation and deletion of a file.
+ */
+public class OldAndroidFileTest extends TestCase {
+
+ public void testFile() throws Exception {
+ File file = File.createTempFile(String.valueOf(System.currentTimeMillis()), null, null);
+
+ assertTrue(file.exists());
+ assertTrue(file.delete());
+ assertFalse(file.exists());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidInputStreamReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidInputStreamReaderTest.java
new file mode 100644
index 0000000..7a0d5fc
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidInputStreamReaderTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import junit.framework.TestCase;
+
+/**
+ * Checks basic InputStreamReader functionality.
+ */
+public class OldAndroidInputStreamReaderTest extends TestCase {
+
+ /**
+ * Checks if ASCII encoding works with InputStreamReader
+ */
+ public void testAscii() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYzX";
+ ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes("ISO8859_1"));
+ InputStreamReader a = new InputStreamReader(aa, "ISO8859_1");
+
+ try {
+ int x = a.read();
+ assertEquals('A', x);
+ char[] c = new char[26];
+ x = a.read(c, 0, 26);
+ assertTrue(a.getEncoding().equalsIgnoreCase("ISO8859_1"));
+ assertEquals(26, x);
+ assertEquals("bCdEfGhIjKlMnOpQrStUvWxYzX", String.valueOf(c));
+ } finally {
+ a.close();
+ }
+ }
+
+ /**
+ * Checks if Utf8 encoding works with InputStreamReader
+ */
+ public void testUtf8() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYzX" +
+ "\u00a3\u00c5\u00c9"; // total of 30 characters
+ ByteArrayInputStream aa =
+ new ByteArrayInputStream(str.getBytes());
+
+ InputStreamReader a = new InputStreamReader(aa);
+
+ try {
+ assertEquals("UTF8", a.getEncoding());
+
+ int x = a.read();
+ assertEquals('A', x);
+
+ char[] c = new char[29];
+ x = a.read(c, 0, 3);
+ assertEquals(3, x);
+ assertEquals("bCd", new String(c, 0, 3));
+
+ x = a.read(c, 3, 26);
+ assertEquals(26, x);
+ assertEquals("EfGhIjKlMnOpQrStUvWxYzX\u00a3\u00c5\u00c9", new String(c, 3, 26));
+ } finally {
+ a.close();
+ }
+ }
+
+ /**
+ * Checks if several encodings works with InputStreamReader
+ */
+ public void testStringy() throws Exception {
+ String src = "The quick brown fox\u00A0\u00FF" +
+ "\uFFFC\uD7C5\uDC03bloof";
+
+ String[] enc = new String[]{
+ "utf-8", "us-ascii", "iso-8859-1", "utf-16be", "utf-16le",
+ "utf-16",
+ };
+
+ for (int i = 0; i < enc.length; i++) {
+ byte[] ba = src.getBytes(enc[i]);
+
+ String s1 = new String(ba, enc[i]);
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(ba);
+ InputStreamReader r = new InputStreamReader(bais, enc[i]);
+ try {
+ char[] ca = new char[600];
+ int n = r.read(ca, 0, 600);
+
+ String s2 = new String(ca, 0, n);
+ assertEquals(s1, s2);
+ } finally {
+ r.close();
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidLineNumberReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidLineNumberReaderTest.java
new file mode 100644
index 0000000..6acb955
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidLineNumberReaderTest.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.io.StringReader;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Checks basic functionality for LineNumberReader.
+ */
+public class OldAndroidLineNumberReaderTest extends TestCase {
+
+ public void testLineNumberReader() throws Exception {
+ String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
+
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(str);
+ StringReader ca = new StringReader(str);
+ StringReader da = new StringReader(str);
+ StringReader ea = new StringReader(str);
+
+ LineNumberReader a = new LineNumberReader(aa);
+ try {
+ assertEquals(0, a.getLineNumber());
+ Assert.assertEquals(str, read(a));
+ assertEquals(1, a.getLineNumber());
+ a.setLineNumber(5);
+ assertEquals(5, a.getLineNumber());
+ } finally {
+ a.close();
+ }
+
+ LineNumberReader b = new LineNumberReader(ba);
+ try {
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ LineNumberReader c = new LineNumberReader(ca);
+ try {
+ Assert.assertEquals("bdfhjl\nprtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+
+ LineNumberReader d = new LineNumberReader(da);
+ try {
+ Assert.assertEquals("AbCdEfGdEfGhIjKlM\nOpQrStUvWxYz", markRead(d, 3, 4));
+ } finally {
+ d.close();
+ }
+
+ LineNumberReader e = new LineNumberReader(ea);
+ try {
+ assertEquals("AbCdEfGhIjKlM", e.readLine());
+ } finally {
+ e.close();
+ }
+ }
+
+ public static String read(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(Reader a, int x) throws IOException {
+ char[] b = new char[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(Reader a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidOutputStreamWriterTest.java b/luni/src/test/java/libcore/java/io/OldAndroidOutputStreamWriterTest.java
new file mode 100644
index 0000000..de559ff
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidOutputStreamWriterTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import junit.framework.TestCase;
+
+/**
+ * Tests basic functionality of an OutputStreamWriter.
+ */
+public class OldAndroidOutputStreamWriterTest extends TestCase {
+
+ public void testOutputStreamWriter() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ ByteArrayOutputStream aa = new ByteArrayOutputStream();
+ OutputStreamWriter a = new OutputStreamWriter(aa, "ISO8859_1");
+ try {
+ a.write(str, 0, 4);
+ a.write('A');
+ // We have to flush the OutputStreamWriter to guarantee
+ // that the results will appear in the underlying OutputStream
+ a.flush();
+ assertEquals("ISO8859_1", a.getEncoding());
+ assertEquals(5, aa.size());
+ assertEquals("AbCdA", aa.toString());
+ } finally {
+ a.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidPipedStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidPipedStreamTest.java
new file mode 100644
index 0000000..ec55612
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidPipedStreamTest.java
@@ -0,0 +1,291 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import junit.framework.TestCase;
+
+public class OldAndroidPipedStreamTest extends TestCase {
+
+ private abstract static class TestThread extends Thread {
+ public abstract void runTest() throws Exception;
+
+ public final void run() {
+ try {
+ runTest();
+ } catch (Throwable e) {
+ exception = e;
+ }
+ }
+
+ Throwable exception;
+ int countRead = 0;
+ }
+
+ public void testA() throws Exception {
+
+ final PipedInputStream in = new PipedInputStream();
+ final PipedOutputStream out = new PipedOutputStream(in);
+
+ assertEquals(0, in.available());
+
+ TestThread reader, writer;
+
+ reader = new TestThread() {
+ Fibonacci fib = new Fibonacci();
+
+ @Override
+ public void runTest() throws Exception {
+ int readInt;
+ byte readByte;
+
+ for (; ;) {
+ readInt = in.read();
+
+ if (readInt == -1) {
+ return;
+ }
+
+ readByte = (byte) readInt;
+ assertEquals(readByte, (byte) fib.next());
+ countRead++;
+ }
+ }
+ };
+
+ reader.start();
+
+ writer = new TestThread() {
+ Fibonacci fib = new Fibonacci();
+
+ @Override
+ public void runTest() throws Exception {
+ for (int i = 0; i < 2000; i++) {
+ int toWrite = fib.next();
+ out.write(toWrite);
+ }
+ out.close();
+ }
+ };
+
+ writer.start();
+
+
+ for (; ;) {
+ try {
+ reader.join(60 * 1000);
+ writer.join(1000);
+ break;
+ } catch (InterruptedException ex) {
+ }
+ }
+
+ assertEquals(2000, reader.countRead);
+
+ if (writer.exception != null) {
+ throw new Exception(writer.exception);
+ }
+ if (reader.exception != null) {
+ throw new Exception(reader.exception);
+ }
+ }
+
+ public void testB() throws Exception {
+ final PipedInputStream in = new PipedInputStream();
+ final PipedOutputStream out = new PipedOutputStream(in);
+
+ assertEquals(0, in.available());
+
+ TestThread reader, writer;
+
+ reader = new TestThread() {
+ Fibonacci fib = new Fibonacci();
+
+ @Override
+ public void runTest() throws Exception {
+ byte readBytes[] = new byte[5];
+ int ret;
+
+ for (; ;) {
+ int nread = 0;
+ while (nread < 5) {
+ ret = in.read(readBytes, nread, readBytes.length - nread);
+
+ if (ret == -1) {
+ return;
+ }
+ nread += ret;
+ }
+
+ assertEquals(5, nread);
+
+ int readInt = (((int) readBytes[0] & 0xff) << 24)
+ | (((int) readBytes[1] & 0xff) << 16)
+ | (((int) readBytes[2] & 0xff) << 8)
+ | (((int) readBytes[3] & 0xff));
+
+
+ assertEquals("Error at " + countRead, fib.next(), readInt);
+ assertEquals("Error at " + countRead, 0, readBytes[4]);
+ countRead++;
+ }
+ }
+ };
+
+ reader.start();
+
+ writer = new TestThread() {
+ Fibonacci fib = new Fibonacci();
+
+ @Override
+ public void runTest() throws Exception {
+ byte writeBytes[] = new byte[5];
+ for (int i = 0; i < 2000; i++) {
+ int toWrite = fib.next();
+ writeBytes[0] = (byte) (toWrite >> 24);
+ writeBytes[1] = (byte) (toWrite >> 16);
+ writeBytes[2] = (byte) (toWrite >> 8);
+ writeBytes[3] = (byte) (toWrite);
+ writeBytes[4] = 0;
+ out.write(writeBytes, 0, writeBytes.length);
+ }
+ out.close();
+ }
+ };
+
+ writer.start();
+
+
+ for (; ;) {
+ try {
+ reader.join(60 * 1000);
+ writer.join(1000);
+ break;
+ } catch (InterruptedException ex) {
+ }
+ }
+
+ if (reader.exception != null) {
+ throw new Exception(reader.exception);
+ }
+ if (writer.exception != null) {
+ throw new Exception(writer.exception);
+ }
+
+ assertEquals(2000, reader.countRead);
+ }
+
+ public void testC() throws Exception {
+ final PipedInputStream in = new PipedInputStream();
+ final PipedOutputStream out = new PipedOutputStream(in);
+ final byte readBytes[] = new byte[1024 * 2];
+
+ assertEquals(0, in.available());
+
+ TestThread reader, writer;
+
+ reader = new TestThread() {
+ @Override
+ public void runTest() throws Exception {
+ int ret;
+
+ for (; ;) {
+ int nread = 0;
+ while (nread < readBytes.length) {
+ ret = in.read(readBytes, nread, readBytes.length - nread);
+
+ if (ret == -1) {
+ return;
+ }
+ nread += ret;
+ }
+ }
+ }
+ };
+
+ reader.start();
+
+ writer = new TestThread() {
+ Fibonacci fib = new Fibonacci();
+
+ @Override
+ public void runTest() throws Exception {
+ byte writeBytes[] = new byte[1024 * 2];
+ for (int i = 0; i < (writeBytes.length - 4); i += 4) {
+ int toWrite = fib.next();
+ writeBytes[i ] = (byte) (toWrite >> 24);
+ writeBytes[i + 1] = (byte) (toWrite >> 16);
+ writeBytes[i + 2] = (byte) (toWrite >> 8);
+ writeBytes[i + 3] = (byte) (toWrite);
+ }
+ out.write(writeBytes, 0, writeBytes.length);
+ out.close();
+ }
+ };
+
+ writer.start();
+
+
+ for (; ;) {
+ try {
+ reader.join(60 * 1000);
+ writer.join(1000);
+ break;
+ } catch (InterruptedException ex) {
+ }
+ }
+
+ if (reader.exception != null) {
+ throw new Exception(reader.exception);
+ }
+ if (writer.exception != null) {
+ throw new Exception(writer.exception);
+ }
+
+ Fibonacci fib = new Fibonacci();
+ for (int i = 0; i < (readBytes.length - 4); i += 4) {
+ int readInt = (((int) readBytes[i] & 0xff) << 24)
+ | (((int) readBytes[i + 1] & 0xff) << 16)
+ | (((int) readBytes[i + 2] & 0xff) << 8)
+ | (((int) readBytes[i + 3] & 0xff));
+
+ assertEquals("Error at " + i, readInt, fib.next());
+ }
+ }
+
+ static class Fibonacci {
+ int n1 = -1;
+ int n2;
+
+ public int next() {
+ if (n1 < 0) {
+ n1 = 0;
+ return 0;
+ } else if (n1 == 0) {
+ n2 = 0;
+ n1 = 1;
+ return 1;
+ } else {
+ int ret = n1 + n2;
+ n2 = n1;
+ n1 = ret;
+ return ret;
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidPrintWriterTest.java b/luni/src/test/java/libcore/java/io/OldAndroidPrintWriterTest.java
new file mode 100644
index 0000000..7f99036
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidPrintWriterTest.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import junit.framework.TestCase;
+
+public class OldAndroidPrintWriterTest extends TestCase {
+
+ public void testPrintWriter() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ StringWriter aa = new StringWriter();
+ PrintWriter a = new PrintWriter(aa);
+
+ try {
+ a.write(str, 0, 26);
+ a.write('X');
+
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", aa.toString());
+
+ a.write("alphabravodelta", 5, 5);
+ a.append('X');
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", aa.toString());
+ a.append("omega");
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", aa.toString());
+ a.print("ZZZ");
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomegaZZZ", aa.toString());
+ } finally {
+ a.close();
+ }
+
+ StringWriter ba = new StringWriter();
+ PrintWriter b = new PrintWriter(ba);
+ try {
+ b.print(true);
+ b.print((char) 'A');
+ b.print("BCD".toCharArray());
+ b.print((double) 1.2);
+ b.print((float) 3);
+ b.print((int) 4);
+ b.print((long) 5);
+ assertEquals("trueABCD1.23.045", ba.toString());
+ b.println();
+ b.println(true);
+ b.println((char) 'A');
+ b.println("BCD".toCharArray());
+ b.println((double) 1.2);
+ b.println((float) 3);
+ b.println((int) 4);
+ b.println((long) 5);
+ b.print("THE END");
+ assertEquals("trueABCD1.23.045\ntrue\nA\nBCD\n1.2\n3.0\n4\n5\nTHE END", ba.toString());
+ } finally {
+ b.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidPushbackInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldAndroidPushbackInputStreamTest.java
new file mode 100644
index 0000000..7eddeca
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidPushbackInputStreamTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class OldAndroidPushbackInputStreamTest extends TestCase {
+
+ public void testPushbackInputStream() throws Exception {
+ String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
+ ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
+ ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
+
+ PushbackInputStream a = new PushbackInputStream(aa, 7);
+ try {
+ a.unread("push".getBytes());
+ Assert.assertEquals("pushAbCdEfGhIjKlM\nOpQrStUvWxYz", read(a));
+ } finally {
+ a.close();
+ }
+
+ PushbackInputStream b = new PushbackInputStream(ba, 9);
+ try {
+ b.unread('X');
+ Assert.assertEquals("XAbCdEfGhI", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ PushbackInputStream c = new PushbackInputStream(ca);
+ try {
+ Assert.assertEquals("bdfhjl\nprtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+ }
+
+ public static String read(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(InputStream a, int x) throws IOException {
+ byte[] b = new byte[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(InputStream a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(InputStream a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidPushbackReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidPushbackReaderTest.java
new file mode 100644
index 0000000..fa3f8fa
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidPushbackReaderTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.PushbackReader;
+import java.io.Reader;
+import java.io.StringReader;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class OldAndroidPushbackReaderTest extends TestCase {
+
+ public void testPushbackReader() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(str);
+ StringReader ca = new StringReader(str);
+
+ PushbackReader a = new PushbackReader(aa, 5);
+ try {
+ a.unread("PUSH".toCharArray());
+ Assert.assertEquals("PUSHAbCdEfGhIjKlMnOpQrStUvWxYz", read(a));
+ } finally {
+ a.close();
+ }
+
+ PushbackReader b = new PushbackReader(ba, 15);
+ try {
+ b.unread('X');
+ Assert.assertEquals("XAbCdEfGhI", read(b, 10));
+ } finally {
+ b.close();
+ }
+
+ PushbackReader c = new PushbackReader(ca);
+ try {
+ Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
+ } finally {
+ c.close();
+ }
+ }
+
+ public static String read(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(Reader a, int x) throws IOException {
+ char[] b = new char[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidSerializationTest.java b/luni/src/test/java/libcore/java/io/OldAndroidSerializationTest.java
new file mode 100644
index 0000000..2064581
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidSerializationTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import junit.framework.TestCase;
+
+/**
+ * Tests serialization of user-level classes.
+ */
+public class OldAndroidSerializationTest extends TestCase {
+
+ static class MySerializable implements Serializable {}
+
+ public void testSerialization() throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ ObjectOutputStream oout = new ObjectOutputStream(bout);
+ oout.writeObject(new MySerializable());
+ oout.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
+ Object o = new ObjectInputStream(bin).readObject();
+ assertTrue(o instanceof MySerializable);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidStreamTokenizerTest.java b/luni/src/test/java/libcore/java/io/OldAndroidStreamTokenizerTest.java
new file mode 100644
index 0000000..e13ba99
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidStreamTokenizerTest.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import junit.framework.TestCase;
+
+/**
+ * Tests for the StreamTokenizer
+ */
+public class OldAndroidStreamTokenizerTest extends TestCase {
+
+ public void testStreamTokenizer() throws Exception {
+ String str = "Testing 12345 \n alpha \r\n omega";
+ String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(strb);
+ StreamTokenizer a = new StreamTokenizer(aa);
+ StreamTokenizer b = new StreamTokenizer(ba);
+
+ assertEquals(1, a.lineno());
+ assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
+ assertEquals("Token[Testing], line 1", a.toString());
+ assertEquals(StreamTokenizer.TT_NUMBER, a.nextToken());
+ assertEquals("Token[n=12345.0], line 1", a.toString());
+ assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
+ assertEquals("Token[alpha], line 2", a.toString());
+ assertEquals(StreamTokenizer.TT_WORD, a.nextToken());
+ assertEquals("Token[omega], line 3", a.toString());
+ assertEquals(StreamTokenizer.TT_EOF, a.nextToken());
+ assertEquals("Token[EOF], line 3", a.toString());
+
+ b.commentChar('u');
+ b.eolIsSignificant(true);
+ b.lowerCaseMode(true);
+ b.ordinaryChar('y');
+ b.slashStarComments(true);
+
+ assertEquals(StreamTokenizer.TT_NUMBER, b.nextToken());
+ assertEquals(-3.8, b.nval);
+ assertEquals("Token[n=-3.8], line 1", b.toString());
+ assertEquals(39, b.nextToken()); // '
+ assertEquals("Token[BLIND mice], line 1", b.toString());
+ assertEquals(10, b.nextToken()); // \n
+ assertEquals("Token[EOL], line 2", b.toString());
+ assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
+ assertEquals("Token[see], line 2", b.toString());
+ assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
+ assertEquals("Token[the], line 2", b.toString());
+ assertEquals(121, b.nextToken()); // y
+ assertEquals("Token['y'], line 2", b.toString());
+ assertEquals(StreamTokenizer.TT_WORD, b.nextToken());
+ assertEquals("Token[r], line 2", b.toString());
+ assertEquals(StreamTokenizer.TT_EOF, b.nextToken());
+ assertEquals("Token[EOF], line 2", b.toString());
+
+ // A harmony regression test
+ byte[] data = new byte[]{(byte) '-'};
+ StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
+ tokenizer.nextToken();
+ String result = tokenizer.toString();
+ assertEquals("Token['-'], line 1", result);
+
+ // another harmony regression test
+ byte[] data2 = new byte[]{(byte) '"',
+ (byte) 'H',
+ (byte) 'e',
+ (byte) 'l',
+ (byte) 'l',
+ (byte) 'o',
+ (byte) '"'};
+ StreamTokenizer tokenizer2 = new StreamTokenizer(new ByteArrayInputStream(data2));
+ tokenizer2.nextToken();
+ result = tokenizer2.toString();
+ assertEquals("Token[Hello], line 1", result);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidStringReaderTest.java b/luni/src/test/java/libcore/java/io/OldAndroidStringReaderTest.java
new file mode 100644
index 0000000..a65d98d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidStringReaderTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class OldAndroidStringReaderTest extends TestCase {
+
+ public void testStringReader() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+
+ StringReader a = new StringReader(str);
+ StringReader b = new StringReader(str);
+ StringReader c = new StringReader(str);
+ StringReader d = new StringReader(str);
+
+ Assert.assertEquals(str, read(a));
+ Assert.assertEquals("AbCdEfGhIj", read(b, 10));
+ Assert.assertEquals("bdfhjlnprtvxz", skipRead(c));
+ Assert.assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", markRead(d, 3, 4));
+ }
+
+ public static String read(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String read(Reader a, int x) throws IOException {
+ char[] b = new char[x];
+ int len = a.read(b, 0, x);
+ if (len < 0) {
+ return "";
+ }
+ return new String(b, 0, len);
+ }
+
+ public static String skipRead(Reader a) throws IOException {
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ a.skip(1);
+ r = a.read();
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+
+ public static String markRead(Reader a, int x, int y) throws IOException {
+ int m = 0;
+ int r;
+ StringBuilder builder = new StringBuilder();
+ do {
+ m++;
+ r = a.read();
+ if (m == x)
+ a.mark((x + y));
+ if (m == (x + y))
+ a.reset();
+
+ if (r != -1)
+ builder.append((char) r);
+ } while (r != -1);
+ return builder.toString();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldAndroidStringWriterTest.java b/luni/src/test/java/libcore/java/io/OldAndroidStringWriterTest.java
new file mode 100644
index 0000000..91673f3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldAndroidStringWriterTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.StringWriter;
+import junit.framework.TestCase;
+
+public class OldAndroidStringWriterTest extends TestCase {
+
+ public void testStringWriter() throws Exception {
+ String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
+ StringWriter a = new StringWriter(10);
+
+ a.write(str, 0, 26);
+ a.write('X');
+
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", a.toString());
+
+ a.write("alphabravodelta", 5, 5);
+ a.append('X');
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", a.toString());
+ a.append("omega");
+ assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", a.toString());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java
new file mode 100644
index 0000000..a3ef4e4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldBufferedInputStreamTest.java
@@ -0,0 +1,228 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleInputStream;
+import tests.support.Support_PlatformFile;
+
+public class OldBufferedInputStreamTest extends TestCase {
+
+ public String fileName;
+ private BufferedInputStream is;
+ private FileInputStream isFile;
+ public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_InputStream() {
+ is = new BufferedInputStream(isFile);
+
+ try {
+ is.read();
+ } catch (Exception e) {
+ fail("Test 1: Read failed on a freshly constructed buffer.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_InputStreamI() throws IOException {
+ // regression test for harmony-2407
+ new testBufferedInputStream(null);
+ assertNotNull(testBufferedInputStream.buf);
+ testBufferedInputStream.buf = null;
+ new testBufferedInputStream(null, 100);
+ assertNotNull(testBufferedInputStream.buf);
+ }
+
+ static class testBufferedInputStream extends BufferedInputStream {
+ static byte[] buf;
+ testBufferedInputStream(InputStream is) throws IOException {
+ super(is);
+ buf = super.buf;
+ }
+
+ testBufferedInputStream(InputStream is, int size) throws IOException {
+ super(is, size);
+ buf = super.buf;
+ }
+ }
+
+ public void test_available() {
+ // Test for method int java.io.BufferedInputStream.available()
+ try {
+ assertTrue("Returned incorrect number of available bytes", is
+ .available() == fileString.length());
+ } catch (IOException e) {
+ fail("Exception during available test");
+ }
+
+ // Test that a closed stream throws an IOE for available()
+ BufferedInputStream bis = new BufferedInputStream(
+ new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
+ ' ', 't', 'i', 'm' }));
+ int available = 0;
+ try {
+ available = bis.available();
+ bis.close();
+ } catch (IOException ex) {
+ fail();
+ }
+ assertTrue(available != 0);
+
+ try {
+ bis.available();
+ fail("Expected test to throw IOE.");
+ } catch (IOException ex) {
+ // expected
+ } catch (Throwable ex) {
+ fail("Expected test to throw IOE not "
+ + ex.getClass().getName());
+ }
+ }
+
+ public void test_close() throws IOException {
+ is.close();
+
+ try {
+ is.read();
+ fail("Test 1: IOException expected when reading after closing " +
+ "the stream.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
+ is = new BufferedInputStream(sis);
+ try {
+ is.close();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sis.throwExceptionOnNextUse = false;
+ }
+
+ public void test_markI_reset() throws IOException {
+ byte[] buf1 = new byte[100];
+ byte[] buf2 = new byte[100];
+
+ // Test 1: Check that reset fails if no mark has been set.
+ try {
+ is.reset();
+ fail("Test 1: IOException expected if no mark has been set.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // Test 2: Check that mark / reset works when the mark is not invalidated.
+ is.skip(10);
+ is.mark(100);
+ is.read(buf1, 0, buf1.length);
+ is.reset();
+ is.read(buf2, 0, buf2.length);
+ is.reset();
+ assertTrue("Test 2: Failed to mark correct position or reset failed.",
+ new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+ // Tests 3 and 4: Check that skipping less than readlimit bytes does
+ // not invalidate the mark.
+ is.skip(10);
+ try {
+ is.reset();
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException " + e.getMessage());
+ }
+ is.read(buf2, 0, buf2.length);
+ is.reset();
+ assertTrue("Test 4: Failed to mark correct position, or reset failed.",
+ new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+ // Test 8: Check that reset fails for a closed input stream.
+ is.close();
+ try {
+ is.reset();
+ fail("Test 8: IOException expected because the input stream is closed.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read() throws IOException {
+ int c = is.read();
+ assertTrue("Test 1: Incorrect character read.",
+ c == fileString.charAt(0));
+
+ byte[] bytes = new byte[256];
+ for (int i = 0; i < 256; i++) {
+ bytes[i] = (byte) i;
+ }
+
+ BufferedInputStream in = new BufferedInputStream(
+ new ByteArrayInputStream(bytes), 5);
+
+ // Read more bytes than are buffered.
+ for (int i = 0; i < 10; i++) {
+ assertEquals("Test 2: Incorrect byte read;", bytes[i], in.read());
+ }
+
+ in.close();
+ try {
+ in.read();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ @Override
+ protected void setUp() throws IOException {
+ fileName = System.getProperty("user.dir");
+ String separator = System.getProperty("file.separator");
+ if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName,
+ "input.tst");
+ } else {
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName
+ + separator, "input.tst");
+ }
+ OutputStream fos = new FileOutputStream(fileName);
+ fos.write(fileString.getBytes());
+ fos.close();
+ isFile = new FileInputStream(fileName);
+ is = new BufferedInputStream(isFile);
+ }
+
+ @Override
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ try {
+ File f = new File(fileName);
+ f.delete();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java
new file mode 100644
index 0000000..cfb317b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldBufferedOutputStreamTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import tests.support.Support_OutputStream;
+
+public class OldBufferedOutputStreamTest extends junit.framework.TestCase {
+
+ private java.io.OutputStream os;
+
+ java.io.ByteArrayOutputStream baos;
+
+ java.io.ByteArrayInputStream bais;
+
+ Support_OutputStream sos;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_OutputStream() {
+ try {
+ baos = new java.io.ByteArrayOutputStream();
+ os = new java.io.BufferedOutputStream(baos);
+ os.write(fileString.getBytes(), 0, 500);
+ } catch (java.io.IOException e) {
+ fail("Constructor test failed");
+ }
+
+ }
+
+ public void test_ConstructorLjava_io_OutputStreamI() {
+ baos = new java.io.ByteArrayOutputStream();
+
+ try {
+ os = new java.io.BufferedOutputStream(baos, -1);
+ fail("Test 1: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ try {
+ os = new java.io.BufferedOutputStream(baos, 1024);
+ os.write(fileString.getBytes(), 0, 500);
+ } catch (java.io.IOException e) {
+ fail("Test 2: Unexpected IOException.");
+ }
+ }
+
+ public void test_flush() throws IOException {
+ baos = new ByteArrayOutputStream();
+ os = new java.io.BufferedOutputStream(baos, 600);
+ os.write(fileString.getBytes(), 0, 500);
+ os.flush();
+ assertEquals("Test 1: Bytes not written after flush;",
+ 500, ((ByteArrayOutputStream) baos).size());
+ os.close();
+
+ sos = new Support_OutputStream(true);
+ os = new BufferedOutputStream(sos, 10);
+ try {
+ os.flush();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // To avoid exception during tearDown().
+ sos.setThrowsException(false);
+ }
+
+ public void test_write$BII() throws IOException {
+ os = new java.io.BufferedOutputStream(
+ baos = new java.io.ByteArrayOutputStream(),512);
+ os.write(fileString.getBytes(), 0, 500);
+ bais = new java.io.ByteArrayInputStream(baos.toByteArray());
+ assertEquals("Test 1: Bytes written, not buffered;",
+ 0, bais.available());
+ os.flush();
+ bais = new java.io.ByteArrayInputStream(baos.toByteArray());
+ assertEquals("Test 2: Bytes not written after flush;",
+ 500, bais.available());
+ os.write(fileString.getBytes(), 500, 513);
+ bais = new java.io.ByteArrayInputStream(baos.toByteArray());
+ assertTrue("Test 3: Bytes not written when buffer full.",
+ bais.available() >= 1000);
+ byte[] wbytes = new byte[1013];
+ bais.read(wbytes, 0, 1013);
+ assertTrue("Test 4: Incorrect bytes written or read.",
+ fileString.substring(0, 1013).equals(
+ new String(wbytes, 0, wbytes.length)));
+ os.close();
+
+ sos = new Support_OutputStream(true);
+ os = new BufferedOutputStream(sos, 10);
+ try {
+ os.write(fileString.getBytes(), 0, 500);
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // To avoid exception during tearDown().
+ sos.setThrowsException(false);
+ }
+
+ public void test_write$BII_Exception() throws IOException {
+ OutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream());
+ byte[] nullByteArray = null;
+ byte[] byteArray = new byte[10];
+
+ try {
+ bos.write(nullByteArray, 0, 1);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ bos.write(byteArray, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bos.write(byteArray, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bos.write(byteArray, 1, 10);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ baos = new java.io.ByteArrayOutputStream();
+ os = new java.io.BufferedOutputStream(baos);
+ os.write('t');
+ bais = new java.io.ByteArrayInputStream(baos.toByteArray());
+ assertEquals("Test 1: Byte written, not buffered;",
+ 0, bais.available());
+ os.flush();
+ bais = new java.io.ByteArrayInputStream(baos.toByteArray());
+ assertEquals("Test 2: Byte not written after flush;",
+ 1, bais.available());
+ byte[] wbytes = new byte[1];
+ bais.read(wbytes, 0, 1);
+ assertEquals("Test 3: Incorrect byte written or read;",
+ 't', wbytes[0]);
+ os.close();
+
+ sos = new Support_OutputStream(true);
+ os = new BufferedOutputStream(sos, 1);
+ os.write('t');
+ try {
+ // Exception is only thrown when the buffer is flushed.
+ os.write('e');
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // To avoid exception during tearDown().
+ sos.setThrowsException(false);
+ }
+
+ protected void tearDown() {
+ try {
+ if (bais != null)
+ bais.close();
+ if (os != null)
+ os.close();
+ if (baos != null)
+ baos.close();
+ } catch (Exception e) {
+ System.out.println("Exception during tearDown" + e.toString());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java b/luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java
new file mode 100644
index 0000000..214c1b2
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldBufferedReaderTest.java
@@ -0,0 +1,321 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedReader;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.io.PipedReader;
+import java.io.Reader;
+import java.io.StringReader;
+import tests.support.Support_ASimpleReader;
+import tests.support.Support_StringReader;
+import tests.support.ThrowingReader;
+
+public class OldBufferedReaderTest extends junit.framework.TestCase {
+
+ BufferedReader br;
+
+ String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_Reader() {
+ // Test for method java.io.BufferedReader(java.io.Reader)
+ br = new BufferedReader(new Support_StringReader(testString));
+ assertNotNull(br);
+ }
+
+ public void test_ConstructorLjava_io_ReaderI() {
+ // Illegal negative size argument test.
+ try {
+ br = new BufferedReader(new Support_StringReader(testString), 0);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException expected) {
+ }
+ br = new BufferedReader(new Support_StringReader(testString), 1024);
+ assertNotNull(br);
+ }
+
+ public void test_close() {
+ Support_ASimpleReader ssr = new Support_ASimpleReader(true);
+ try {
+ br = new BufferedReader(new Support_StringReader(testString));
+ br.close();
+ br.read();
+ fail("Test 1: Read on closed stream.");
+ } catch (IOException x) {
+ // Expected.
+ } catch (Exception e) {
+ fail("Exception during close test " + e.toString());
+ }
+
+ br = new BufferedReader(ssr);
+ try {
+ br.close();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // Avoid IOException in tearDown().
+ ssr.throwExceptionOnNextUse = false;
+ }
+
+ public void test_markI() throws IOException {
+ // Test for method void java.io.BufferedReader.mark(int)
+ char[] buf = null;
+ try {
+ br = new BufferedReader(new Support_StringReader(testString));
+ br.skip(500);
+ br.mark(1000);
+ br.skip(250);
+ br.reset();
+ buf = new char[testString.length()];
+ br.read(buf, 0, 500);
+ assertTrue("Failed to set mark properly", testString.substring(500,
+ 1000).equals(new String(buf, 0, 500)));
+ } catch (java.io.IOException e) {
+ fail("Exception during mark test");
+ }
+ try {
+ br = new BufferedReader(new Support_StringReader(testString), 800);
+ br.skip(500);
+ br.mark(250);
+ br.read(buf, 0, 1000);
+ br.reset();
+ fail("Failed to invalidate mark properly");
+ } catch (IOException x) {
+ }
+
+ char[] chars = new char[256];
+ for (int i = 0; i < 256; i++)
+ chars[i] = (char) i;
+ Reader in = new BufferedReader(new Support_StringReader(new String(
+ chars)), 12);
+ try {
+ in.skip(6);
+ in.mark(14);
+ in.read(new char[14], 0, 14);
+ in.reset();
+ assertTrue("Wrong chars", in.read() == (char) 6
+ && in.read() == (char) 7);
+ } catch (IOException e) {
+ fail("Exception during mark test 2:" + e);
+ }
+
+ in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
+ try {
+ in.skip(6);
+ in.mark(8);
+ in.skip(7);
+ in.reset();
+ assertTrue("Wrong chars 2", in.read() == (char) 6
+ && in.read() == (char) 7);
+ } catch (IOException e) {
+ fail("Exception during mark test 3:" + e);
+ }
+ }
+
+ public void test_markSupported() {
+ // Test for method boolean java.io.BufferedReader.markSupported()
+ br = new BufferedReader(new Support_StringReader(testString));
+ assertTrue("markSupported returned false.", br.markSupported());
+ }
+
+ public void test_read() throws IOException {
+ Support_ASimpleReader ssr = new Support_ASimpleReader(true);
+ try {
+ br = new BufferedReader(new Support_StringReader(testString));
+ int r = br.read();
+ assertTrue("Char read improperly", testString.charAt(0) == r);
+ br = new BufferedReader(new Support_StringReader(new String(
+ new char[] { '\u8765' })));
+ assertTrue("Wrong double byte character", br.read() == '\u8765');
+ } catch (java.io.IOException e) {
+ fail("Exception during read test");
+ }
+
+ char[] chars = new char[256];
+ for (int i = 0; i < 256; i++)
+ chars[i] = (char) i;
+ Reader in = new BufferedReader(new Support_StringReader(new String(
+ chars)), 12);
+ try {
+ assertEquals("Wrong initial char", 0, in.read()); // Fill the
+ // buffer
+ char[] buf = new char[14];
+ in.read(buf, 0, 14); // Read greater than the buffer
+ assertTrue("Wrong block read data", new String(buf)
+ .equals(new String(chars, 1, 14)));
+ assertEquals("Wrong chars", 15, in.read()); // Check next byte
+ } catch (IOException e) {
+ fail("Exception during read test 2:" + e);
+ }
+
+ // regression test for HARMONY-841
+ assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
+
+ br.close();
+ br = new BufferedReader(ssr);
+ try {
+ br.read();
+ fail("IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // Avoid IOException in tearDown().
+ ssr.throwExceptionOnNextUse = false;
+ }
+
+ public void test_read$CII_Exception() throws Exception {
+ br = new BufferedReader(new Support_StringReader(testString));
+ try{
+ br.read(new char[10], -1, 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try{
+ br.read(new char[10], 0, -1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try{
+ br.read(new char[10], 10, 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ //regression for HARMONY-831
+ try{
+ new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
+ fail("should throw IndexOutOfBoundsException");
+ }catch(IndexOutOfBoundsException e){
+ }
+ }
+
+ public void test_readLine() throws IOException {
+ String line;
+ br = new BufferedReader(new Support_StringReader("Lorem\nipsum\rdolor sit amet..."));
+
+ line = br.readLine();
+ assertTrue("Test 1: Incorrect line written or read: " + line,
+ line.equals("Lorem"));
+ line = br.readLine();
+ assertTrue("Test 2: Incorrect line written or read: " + line,
+ line.equals("ipsum"));
+ line = br.readLine();
+ assertTrue("Test 3: Incorrect line written or read: " + line,
+ line.equals("dolor sit amet..."));
+
+ br.close();
+ try {
+ br.readLine();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ready() throws IOException {
+ Support_ASimpleReader ssr = new Support_ASimpleReader(true);
+ try {
+ br = new BufferedReader(new Support_StringReader(testString));
+ assertTrue("Test 1: ready() returned false", br.ready());
+ } catch (java.io.IOException e) {
+ fail("Exception during ready test" + e.toString());
+ }
+
+ br.close();
+ br = new BufferedReader(ssr);
+ try {
+ br.close();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // Avoid IOException in tearDown().
+ ssr.throwExceptionOnNextUse = false;
+ }
+
+ public void test_skipJ() throws IOException {
+ Support_ASimpleReader ssr = new Support_ASimpleReader(true);
+ br = new BufferedReader(new Support_StringReader(testString));
+
+ try {
+ br.skip(-1);
+ fail("Test 1: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ br.skip(500);
+ char[] buf = new char[testString.length()];
+ br.read(buf, 0, 500);
+ assertTrue("Test 2: Failed to set skip properly.",
+ testString.substring(500, 1000).equals(
+ new String(buf, 0, 500)));
+
+ br.close();
+ br = new BufferedReader(ssr);
+ try {
+ br.skip(1);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ // Avoid IOException in tearDown().
+ ssr.throwExceptionOnNextUse = false;
+ }
+
+ public void testReadZeroLengthArray() throws IOException {
+ br = new BufferedReader(new Support_StringReader("ABCDEF"));
+ br.read();
+ br.read();
+ assertEquals(0, br.read(new char[6], 3, 0));
+ }
+
+ public void testSourceThrowsWithMark() throws IOException {
+ br = new BufferedReader(new ThrowingReader(
+ new StringReader("ABCDEFGHI"), 4));
+
+ br.read();
+ br.read();
+ br.mark(10);
+ br.read();
+ br.read();
+
+ try {
+ br.read();
+ fail();
+ } catch (IOException fromThrowingReader) {
+ }
+
+ assertEquals('E', br.read());
+ assertEquals('F', br.read());
+ }
+
+ protected void tearDown() {
+ try {
+ br.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java b/luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java
new file mode 100644
index 0000000..ed5b862
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldBufferedWriterTest.java
@@ -0,0 +1,316 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import tests.support.Support_ASimpleWriter;
+import tests.support.Support_StringWriter;
+
+public class OldBufferedWriterTest extends junit.framework.TestCase {
+
+ BufferedWriter bw;
+
+ Support_StringWriter sw;
+
+ Support_ASimpleWriter ssw;
+
+ public String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_Writer() {
+ bw = new BufferedWriter(sw);
+ try {
+ bw.write("Hi", 0, 2);
+ assertTrue("Test 1: Buffering failed.", sw.toString().equals(""));
+ bw.flush();
+ assertEquals("Test 2: Incorrect value;", "Hi", sw.toString());
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_WriterI() {
+ try {
+ bw = new BufferedWriter(sw, 0);
+ fail("Test 1: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException expected) {
+ // Expected.
+ }
+
+ bw = new BufferedWriter(sw, 10);
+ try {
+ bw.write("Hi", 0, 2);
+ assertTrue("Test 2: Buffering failed.", sw.toString().equals(""));
+ bw.flush();
+ assertEquals("Test 3: Incorrect value;", "Hi", sw.toString());
+ } catch (IOException e) {
+ fail("Test 4: Unexpected IOException.");
+ }
+ }
+
+ public void test_close() {
+ // Test for method void java.io.BufferedWriter.close()
+ try {
+ bw.close();
+ bw.write(testString);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ assertFalse("Test 2: Write after close.", sw.toString().equals(testString));
+
+ bw = new BufferedWriter(ssw);
+ try {
+ bw.close();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_flush() throws IOException {
+ bw.write("This should not cause a flush");
+ assertTrue("Test 1: Bytes written without flush.",
+ sw.toString().equals(""));
+ bw.flush();
+ assertEquals("Test 2: Bytes not flushed.",
+ "This should not cause a flush", sw.toString());
+
+ bw.close();
+ bw = new BufferedWriter(ssw);
+ try {
+ bw.flush();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_newLine() throws IOException {
+ String separator = System.getProperty("line.separator");
+ bw.write("Hello");
+ bw.newLine();
+ bw.write("World");
+ bw.flush();
+ assertTrue("Test 1: Incorrect string written: " + sw.toString(),
+ sw.toString().equals("Hello" + separator + "World"));
+
+ bw.close();
+ bw = new BufferedWriter(ssw, 1);
+ try {
+ bw.newLine();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$CII() {
+ // Test for method void java.io.BufferedWriter.write(char [], int, int)
+ try {
+ char[] testCharArray = testString.toCharArray();
+ bw.write(testCharArray, 500, 1000);
+ bw.flush();
+ assertTrue("Incorrect string written", sw.toString().equals(
+ testString.substring(500, 1500)));
+
+ int idx = sw.toString().length();
+ bw.write(testCharArray, 0, testCharArray.length);
+ assertEquals(idx + testCharArray.length, sw.toString().length());
+ bw.write(testCharArray, 0, 0);
+ assertEquals(idx + testCharArray.length, sw.toString().length());
+ bw.write(testCharArray, testCharArray.length, 0);
+ assertEquals(idx + testCharArray.length, sw.toString().length());
+ } catch (Exception e) {
+ fail("Exception during write test");
+ }
+
+ }
+
+ public void test_write$CII_Exception() throws IOException {
+ char[] nullCharArray = null;
+ char[] charArray = testString.toCharArray();
+
+ try {
+ bw.write(nullCharArray, 0, 1);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ bw.write(charArray, -1, 0);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bw.write(charArray, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bw.write(charArray, charArray.length + 1, 0);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bw.write(charArray, charArray.length, 1);
+ fail("Test 5: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bw.write(charArray, 0, charArray.length + 1);
+ fail("Test 6: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ bw.write(charArray, 1, charArray.length);
+ fail("Test 7: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ bw.close();
+
+ try {
+ bw.write(charArray, 0, 1);
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ bw = new BufferedWriter(ssw, charArray.length / 2);
+ try {
+ bw.write(charArray, 0, charArray.length);
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ bw.write('T');
+ assertTrue("Test 1: Char written without flush.",
+ sw.toString().equals(""));
+ bw.flush();
+ assertEquals("Test 2: Incorrect char written;",
+ "T", sw.toString());
+
+ bw.close();
+ try {
+ bw.write('E');
+ fail("Test 3: IOException expected since the target writer is closed.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // IOException should be thrown when the buffer is full and data is
+ // written out to the target writer.
+ bw = new BufferedWriter(ssw, 1);
+ bw.write('S');
+ try {
+ bw.write('T');
+ fail("Test 4: IOException expected since the target writer throws it.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeLjava_lang_StringII() {
+ // Test for method void java.io.BufferedWriter.write(java.lang.String,
+ // int, int)
+ try {
+ bw.write(testString);
+ bw.flush();
+ assertTrue("Incorrect string written", sw.toString().equals(
+ testString));
+ } catch (Exception e) {
+ fail("Exception during write test");
+ }
+ }
+
+ public void test_writeLjava_lang_StringII_Exception() throws IOException {
+
+ bw.write((String) null , -1, -1);
+ bw.write((String) null , -1, 0);
+ bw.write((String) null , 0 , -1);
+ bw.write((String) null , 0 , 0);
+
+ try {
+ bw.write((String) null, 0, 1);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ bw.write(testString, -1, 1);
+ fail("Test 2: StringIndexOutOfBoundsException expected.");
+ } catch (StringIndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ bw.write(testString, 1, testString.length());
+ fail("Test 3: StringIndexOutOfBoundsException expected.");
+ } catch (StringIndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ bw.close();
+
+ try {
+ bw.write(testString, 0, 1);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ bw = new BufferedWriter(ssw, testString.length() / 2);
+ try {
+ bw.write(testString, 0, testString.length());
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void setUp() {
+ sw = new Support_StringWriter();
+ ssw = new Support_ASimpleWriter(true);
+ bw = new BufferedWriter(sw, 500);
+ }
+
+ protected void tearDown() {
+ ssw.throwExceptionOnNextUse = false;
+ try {
+ bw.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java
new file mode 100644
index 0000000..b5f3f4e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldByteArrayInputStreamTest.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+public class OldByteArrayInputStreamTest extends junit.framework.TestCase {
+
+ private ByteArrayInputStream is;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+ public void test_Constructor$B() {
+ // Test for method java.io.ByteArrayInputStream(byte [])
+
+ java.io.InputStream bis = new java.io.ByteArrayInputStream(fileString
+ .getBytes());
+
+ try {
+ assertTrue("Unable to create ByteArrayInputStream",
+ bis.available() == fileString.length());
+ } catch (Exception e) {
+ System.out.println("Exception during Constructor test");
+ }
+ }
+
+ public void test_Constructor$BII() throws IOException {
+ // Test for method java.io.ByteArrayInputStream(byte [], int, int)
+
+ byte[] zz = fileString.getBytes();
+ java.io.InputStream bis = new java.io.ByteArrayInputStream(zz, 0, 100);
+
+ try {
+ assertEquals("Unable to create ByteArrayInputStream",
+ 100, bis.available());
+ } catch (Exception e) {
+ fail("Exception during Constructor test");
+ }
+
+ // Regression test for Harmony-2405
+ new SubByteArrayInputStream(new byte[] { 1, 2 }, 444, 13);
+ assertEquals(444, SubByteArrayInputStream.pos);
+ assertEquals(444, SubByteArrayInputStream.mark);
+ assertEquals(2, SubByteArrayInputStream.count);
+ }
+
+ static class SubByteArrayInputStream extends ByteArrayInputStream {
+ public static byte[] buf;
+
+ public static int mark, pos, count;
+
+ SubByteArrayInputStream(byte[] buf, int offset, int length)
+ throws IOException {
+ super(buf, offset, length);
+ buf = super.buf;
+ mark = super.mark;
+ pos = super.pos;
+ count = super.count;
+ }
+ }
+
+ public void test_available() {
+ // Test for method int java.io.ByteArrayInputStream.available()
+ try {
+ assertTrue("Returned incorrect number of available bytes", is
+ .available() == fileString.length());
+ } catch (Exception e) {
+ fail("Exception during available test");
+ }
+ }
+
+ public void test_close() {
+ is.read();
+ try {
+ is.close();
+ } catch (java.io.IOException e) {
+ fail("Test 1: Failed to close the input stream.");
+ }
+ try {
+ is.read();
+ } catch (Exception e) {
+ fail("Test 2: Should be able to read from closed stream.");
+ }
+ }
+
+ public void test_markI() {
+ // Test for method void java.io.ByteArrayInputStream.mark(int)
+ byte[] buf1 = new byte[100];
+ byte[] buf2 = new byte[100];
+ try {
+ is.skip(3000);
+ is.mark(1000);
+ is.read(buf1, 0, buf1.length);
+ is.reset();
+ is.read(buf2, 0, buf2.length);
+ is.reset();
+ assertTrue("Failed to mark correct position", new String(buf1, 0,
+ buf1.length).equals(new String(buf2, 0, buf2.length)));
+
+ } catch (Exception e) {
+ fail("Exception during mark test");
+ }
+
+ }
+
+ public void test_markSupported() {
+ // Test for method boolean java.io.ByteArrayInputStream.markSupported()
+ assertTrue("markSupported returned incorrect value", is.markSupported());
+ }
+
+ public void test_read() {
+ // Test for method int java.io.ByteArrayInputStream.read()
+ try {
+
+ int c = is.read();
+ is.reset();
+ assertTrue("read returned incorrect char", c == fileString
+ .charAt(0));
+ } catch (Exception e) {
+ fail("Exception during read test");
+ }
+ }
+
+ public void test_read$BII() throws IOException {
+ byte[] buf1 = new byte[20];
+ is.skip(50);
+ is.mark(100);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Test 1: Failed to read correct data.",
+ new String(buf1, 0, buf1.length).equals(
+ fileString.substring(50, 70)));
+
+ // Illegal argument checks.
+ try {
+ is.read(null, 1, 0);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf1 , -1, 1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ is.read(buf1 , 1, -1);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ is.read(buf1, 1, buf1.length);
+ fail("Test 5: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ public void test_reset() {
+ // Test for method void java.io.ByteArrayInputStream.reset()
+ byte[] buf1 = new byte[10];
+ byte[] buf2 = new byte[10];
+ try {
+ is.mark(200);
+ is.read(buf1, 0, 10);
+ is.reset();
+ is.read(buf2, 0, 10);
+ is.reset();
+ assertTrue("Reset failed", new String(buf1, 0, buf1.length)
+ .equals(new String(buf2, 0, buf2.length)));
+ } catch (Exception e) {
+ fail("Exception during reset test : " + e.getMessage());
+ }
+ }
+
+ public void test_skipJ() {
+ // Test for method long java.io.ByteArrayInputStream.skip(long)
+ byte[] buf1 = new byte[10];
+ try {
+ is.skip(100);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Failed to skip to correct position", new String(buf1,
+ 0, buf1.length).equals(fileString.substring(100, 110)));
+ } catch (Exception e) {
+ fail("Exception during skip test : " + e.getMessage());
+ }
+ }
+
+ protected void setUp() {
+ is = new ByteArrayInputStream(fileString.getBytes());
+
+ }
+
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java
new file mode 100644
index 0000000..0ef7f75
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldByteArrayOutputStreamTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.TestCase;
+import tests.support.Support_OutputStream;
+
+/**
+ * Automated Test Suite for class java.io.ByteArrayOutputStream
+ *
+ * @see java.io.ByteArrayOutputStream
+ */
+public class OldByteArrayOutputStreamTest extends TestCase {
+
+ ByteArrayOutputStream bos = null;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+ public void test_ConstructorI() {
+ bos = new java.io.ByteArrayOutputStream(100);
+ assertEquals("Test 1: Failed to create stream;", 0, bos.size());
+
+ try {
+ bos = new ByteArrayOutputStream(-1);
+ fail("Test 2: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void test_toStringLjava_lang_String() throws Exception {
+ bos = new ByteArrayOutputStream();
+
+ bos.write(fileString.getBytes(), 0, fileString.length());
+ assertTrue("Test 1: Returned incorrect 8859-1 String",
+ bos.toString("8859_1").equals(fileString));
+ assertTrue("Test 2: Returned incorrect 8859-2 String",
+ bos.toString("8859_2").equals(fileString));
+
+ try {
+ bos.toString("NotAnEcoding");
+ fail("Test 3: UnsupportedEncodingException expected.");
+ } catch (UnsupportedEncodingException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$BII_Exception() {
+ byte[] target = new byte[10];
+ bos = new ByteArrayOutputStream();
+ try {
+ bos.write(target, -1, 1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(target, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(target, 1, target.length);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ bos.write(null, 1, 1);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeToLjava_io_OutputStream() throws Exception {
+ Support_OutputStream sos = new Support_OutputStream();
+ bos = new java.io.ByteArrayOutputStream();
+ bos.write(fileString.getBytes(), 0, 10);
+ bos.writeTo(sos);
+ assertTrue("Test 1: Incorrect string written.",
+ sos.toString().equals(
+ fileString.substring(0, 10)));
+
+ sos.setThrowsException(true);
+ try {
+ bos.writeTo(sos);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java b/luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java
new file mode 100644
index 0000000..31277e0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldCharArrayReaderTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.CharArrayReader;
+import java.io.IOException;
+
+public class OldCharArrayReaderTest extends junit.framework.TestCase {
+
+ char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
+
+ CharArrayReader cr;
+
+ /**
+ * @tests java.io.CharArrayReader#CharArrayReader(char[])
+ */
+ public void test_Constructor$C() {
+ // Test for method java.io.CharArrayReader(char [])
+
+ try {
+ cr = new CharArrayReader(hw);
+ assertTrue("Failed to create reader", cr.ready());
+ } catch (IOException e) {
+ fail("Exception determining ready state : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#CharArrayReader(char[], int, int)
+ */
+ public void test_Constructor$CII() throws IOException {
+ try {
+ cr = new CharArrayReader(null, 0, 0);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ try {
+ cr = new CharArrayReader(hw, -1, 0);
+ fail("Test 2: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ try {
+ cr = new CharArrayReader(hw, 0, -1);
+ fail("Test 3: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ try {
+ cr = new CharArrayReader(hw, hw.length + 1, 1);
+ fail("Test 4: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ cr = new CharArrayReader(hw, 5, 5);
+ assertTrue("Test 5: Failed to create reader", cr.ready());
+ assertEquals("Test 6: Incorrect character read;",
+ 'W', cr.read());
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#close()
+ */
+ public void test_close() {
+ cr = new CharArrayReader(hw);
+ cr.close();
+ try {
+ cr.read();
+ fail("Failed to throw exception on read from closed stream");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#mark(int)
+ */
+ public void test_markI() throws IOException {
+ cr = new CharArrayReader(hw);
+ cr.skip(5L);
+ cr.mark(100);
+ cr.read();
+ cr.reset();
+ assertEquals("Test 1: Failed to mark correct position;",
+ 'W', cr.read());
+
+ cr.close();
+ try {
+ cr.mark(100);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#markSupported()
+ */
+ public void test_markSupported() {
+ cr = new CharArrayReader(hw);
+ assertTrue("markSupported returned false", cr.markSupported());
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#read()
+ */
+ public void test_read() throws IOException {
+ cr = new CharArrayReader(hw);
+ assertEquals("Test 1: Read returned incorrect char;",
+ 'H', cr.read());
+ cr = new CharArrayReader(new char[] { '\u8765' });
+ assertTrue("Test 2: Incorrect double byte char;",
+ cr.read() == '\u8765');
+
+ cr.close();
+ try {
+ cr.read();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#read(char[], int, int)
+ */
+ public void test_read$CII() throws IOException {
+ // Test for method int java.io.CharArrayReader.read(char [], int, int)
+ char[] c = new char[11];
+ cr = new CharArrayReader(hw);
+ cr.read(c, 1, 10);
+ assertTrue("Test 1: Read returned incorrect chars.",
+ new String(c, 1, 10).equals(new String(hw, 0, 10)));
+
+ // Illegal argument checks.
+ try {
+ cr.read(null, 1, 0);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ cr.read(c , -1, 1);
+ fail("Test 3: ArrayIndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ cr.read(c , 1, -1);
+ fail("Test 4: ArrayIndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ cr.read(c, 1, c.length);
+ fail("Test 5: ArrayIndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ cr.close();
+ try {
+ cr.read(c, 1, 1);
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ready() {
+ // Test for method boolean java.io.CharArrayReader.ready()
+ cr = new CharArrayReader(hw);
+ boolean expectException = false;
+ try {
+ assertTrue("ready returned false", cr.ready());
+ cr.skip(1000);
+ assertTrue("ready returned true", !cr.ready());
+ cr.close();
+ expectException = true;
+ cr.ready();
+ fail("No exception 1");
+ } catch (IOException e) {
+ if (!expectException)
+ fail("Unexpected: " + e);
+ }
+ try {
+ cr = new CharArrayReader(hw);
+ cr.close();
+ cr.ready();
+ fail("No exception 2");
+ } catch (IOException e) {
+ }
+ }
+
+ /**
+ * @tests java.io.CharArrayReader#reset()
+ */
+ public void test_reset() throws IOException {
+ cr = new CharArrayReader(hw);
+ cr.skip(5L);
+ cr.mark(100);
+ cr.read();
+ cr.reset();
+ assertEquals("Test 1: Reset failed to return to marker position.",
+ 'W', cr.read());
+
+ cr.close();
+ try {
+ cr.reset();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ long skipped = 0;
+ cr = new CharArrayReader(hw);
+ skipped = cr.skip(5L);
+ assertEquals("Test 1: Failed to skip correct number of chars;",
+ 5L, skipped);
+ assertEquals("Test 2: Skip skipped wrong chars;",
+ 'W', cr.read());
+
+ cr.close();
+ try {
+ cr.skip(1);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void tearDown() {
+ if (cr != null)
+ cr.close();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java b/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java
new file mode 100644
index 0000000..662ad24
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldCharArrayWriterTest.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.CharArrayReader;
+import java.io.CharArrayWriter;
+import java.io.IOException;
+import java.io.StringWriter;
+import tests.support.Support_ASimpleWriter;
+
+public class OldCharArrayWriterTest extends junit.framework.TestCase {
+
+ CharArrayWriter cw;
+ CharArrayReader cr;
+
+ public void test_ConstructorI() {
+ // Test for method java.io.CharArrayWriter(int)
+ cw = new CharArrayWriter(90);
+ assertEquals("Test 1: Incorrect writer created.", 0, cw.size());
+
+ try {
+ cw = new CharArrayWriter(-1);
+ fail("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$CII_Exception() {
+ char[] target = new char[10];
+ cw = new CharArrayWriter();
+ try {
+ cw.write(target, -1, 1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write(target, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write(target, 1, target.length);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ cw.write((char[]) null, 1, 1);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeToLjava_io_Writer() {
+ Support_ASimpleWriter ssw = new Support_ASimpleWriter(true);
+ cw.write("HelloWorld", 0, 10);
+ StringWriter sw = new StringWriter();
+ try {
+ cw.writeTo(sw);
+ assertEquals("Test 1: Writer failed to write correct chars;",
+ "HelloWorld", sw.toString());
+ } catch (IOException e) {
+ fail("Exception during writeTo test : " + e.getMessage());
+ }
+
+ try {
+ cw.writeTo(ssw);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_appendLjava_langCharSequenceII() {
+ String testString = "My Test String";
+ CharArrayWriter writer = new CharArrayWriter(10);
+
+ // Illegal argument checks.
+ try {
+ writer.append(testString, -1, 0);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 1, 0);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ writer.append(testString, 1, testString.length() + 1);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ writer.append(testString, 1, 3);
+ writer.flush();
+ assertEquals("Test 5: Appending failed;",
+ testString.substring(1, 3), writer.toString());
+ writer.close();
+ }
+
+ protected void setUp() {
+ cw = new CharArrayWriter();
+ }
+
+ protected void tearDown() {
+ if (cr != null) {
+ cr.close();
+ }
+ cw.close();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java
new file mode 100644
index 0000000..ca2e325
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldDataInputOutputStreamTest.java
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import tests.support.Support_OutputStream;
+
+public class OldDataInputOutputStreamTest extends junit.framework.TestCase {
+
+ private DataOutputStream os;
+
+ private DataInputStream dis;
+
+ private Support_OutputStream sos;
+
+ String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
+
+ public void test_read_writeBoolean() throws IOException {
+ os.writeBoolean(true);
+ sos.setThrowsException(true);
+ try {
+ os.writeBoolean(false);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertTrue("Test 2: Incorrect boolean written or read.",
+ dis.readBoolean());
+
+ try {
+ dis.readBoolean();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readBoolean();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeByte() throws IOException {
+ os.writeByte((byte) 127);
+ sos.setThrowsException(true);
+ try {
+ os.writeByte((byte) 127);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 2: Incorrect byte written or read;",
+ (byte) 127, dis.readByte());
+
+ try {
+ dis.readByte();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readByte();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeChar() throws IOException {
+ os.writeChar('b');
+ sos.setThrowsException(true);
+ try {
+ os.writeChar('k');
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 2: Incorrect char written or read;",
+ 'b', dis.readChar());
+
+ try {
+ dis.readChar();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readChar();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeDouble() throws IOException {
+ os.writeDouble(2345.76834720202);
+ sos.setThrowsException(true);
+ try {
+ os.writeDouble(2345.76834720202);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect double written or read;",
+ 2345.76834720202, dis.readDouble());
+
+ try {
+ dis.readDouble();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readDouble();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeFloat() throws IOException {
+ os.writeFloat(29.08764f);
+ sos.setThrowsException(true);
+ try {
+ os.writeFloat(29.08764f);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 2: Incorrect float written or read;",
+ 29.08764f, dis.readFloat());
+
+ try {
+ dis.readFloat();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readFloat();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeInt() throws IOException {
+ os.writeInt(768347202);
+ sos.setThrowsException(true);
+ try {
+ os.writeInt(768347202);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect int written or read;",
+ 768347202, dis.readInt());
+
+ try {
+ dis.readInt();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readInt();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeLong() throws IOException {
+ os.writeLong(9875645283333L);
+ sos.setThrowsException(true);
+ try {
+ os.writeLong(9875645283333L);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 2: Incorrect long written or read;",
+ 9875645283333L, dis.readLong());
+
+ try {
+ dis.readLong();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readLong();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeShort() throws IOException {
+ os.writeShort(9875);
+ sos.setThrowsException(true);
+ try {
+ os.writeShort(9875);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect short written or read;",
+ 9875, dis.readShort());
+
+ try {
+ dis.readShort();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readShort();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeUTF() throws IOException {
+ os.writeUTF(unihw);
+ sos.setThrowsException(true);
+ try {
+ os.writeUTF(unihw);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ os.close();
+ openDataInputStream();
+ assertTrue("Test 1: Incorrect UTF-8 string written or read.",
+ dis.readUTF().equals(unihw));
+
+ try {
+ dis.readUTF();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readUTF();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void openDataInputStream() throws IOException {
+ dis = new DataInputStream(new ByteArrayInputStream(sos.toByteArray()));
+ }
+
+ protected void setUp() {
+ sos = new Support_OutputStream(256);
+ os = new DataOutputStream(sos);
+ }
+
+ protected void tearDown() {
+ try {
+ os.close();
+ } catch (Exception e) {
+ }
+ try {
+ dis.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java
new file mode 100644
index 0000000..27240e6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldDataInputStreamTest.java
@@ -0,0 +1,380 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import tests.support.Support_ASimpleInputStream;
+
+public class OldDataInputStreamTest extends junit.framework.TestCase {
+
+ private DataOutputStream os;
+
+ private DataInputStream dis;
+
+ private ByteArrayOutputStream bos;
+
+ String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_DataInputStream\n";
+
+ private final int testLength = fileString.length();
+
+ public void test_ConstructorLjava_io_InputStream() {
+ try {
+ os.writeChar('t');
+ os.close();
+ openDataInputStream();
+ } catch (IOException e) {
+ fail("IOException during constructor test : " + e.getMessage());
+ } finally {
+ try {
+ dis.close();
+ } catch (IOException e) {
+ fail("IOException during constructor test : " + e.getMessage());
+ }
+ }
+ }
+
+ public void test_read$B() throws IOException {
+ byte rbytes[] = new byte[testLength - 5];
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
+ int r;
+
+ os.write(fileString.getBytes());
+ os.close();
+ openDataInputStream();
+
+ r = dis.read(rbytes);
+ assertEquals("Test 1: Incorrect number of bytes read;",
+ testLength - 5, r);
+ assertTrue("Test 2: Incorrect data written or read.",
+ new String(rbytes).equals(fileString.substring(0, testLength - 5)));
+
+ r = dis.read(rbytes);
+ assertEquals("Test 3: Incorrect number of bytes read;", 5, r);
+ assertTrue("Test 4: Incorrect data written or read.",
+ new String(rbytes, 0, 5).equals(fileString.substring(testLength - 5)));
+
+ dis.close();
+ sis.throwExceptionOnNextUse = true;
+ dis = new DataInputStream(sis);
+ try {
+ dis.read(rbytes);
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$BII() throws IOException {
+ byte rbytes[] = new byte[testLength - 5];
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
+ int r;
+
+ os.write(fileString.getBytes());
+ os.close();
+ openDataInputStream();
+
+ r = dis.read(rbytes, 1, testLength - 10);
+ assertEquals("Test 1: Incorrect number of bytes read;",
+ testLength - 10, r);
+ assertEquals("Test 2: Incorrect data read.", 0, rbytes[0]);
+ assertTrue("Test 3: Incorrect data written or read.",
+ new String(rbytes, 1, r).equals(fileString.substring(0, r)));
+
+ r = dis.read(rbytes, 0, 15);
+ assertEquals("Test 3: Incorrect number of bytes read;", 10, r);
+ assertTrue("Test 4: Incorrect data written or read.",
+ new String(rbytes, 0, r).equals(fileString.substring(testLength - 10)));
+
+ dis.close();
+ sis.throwExceptionOnNextUse = true;
+ dis = new DataInputStream(sis);
+ try {
+ dis.read(rbytes, 1, 5);
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$BII_Exception() throws IOException {
+ byte rbytes[] = new byte[testLength - 5];
+
+ os.write(fileString.getBytes());
+ os.close();
+ openDataInputStream();
+
+ try {
+ dis.read(rbytes, -1, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ dis.read(rbytes, 0, -1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ dis.read(rbytes, rbytes.length, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ public void test_readFully$B() throws IOException {
+ byte rbytes[] = new byte[testLength];
+
+ os.write(fileString.getBytes());
+ os.close();
+ openDataInputStream();
+
+ dis.readFully(rbytes);
+ assertTrue("Test 1: Incorrect data written or read.",
+ new String(rbytes, 0, testLength).equals(fileString));
+
+ dis.close();
+ try {
+ dis.readFully(rbytes);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ openDataInputStream();
+ dis.readByte();
+ try {
+ dis.readFully(rbytes);
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readFully$BII() throws IOException {
+ byte rbytes[] = new byte[testLength];
+
+ os.write(fileString.getBytes());
+ os.close();
+ openDataInputStream();
+
+ dis.readFully(rbytes, 2, testLength - 4);
+ assertTrue("Test 1: Incorrect data written or read.",
+ new String(rbytes, 2, testLength - 4).equals(
+ fileString.substring(0, testLength - 4)));
+
+ dis.close();
+ try {
+ dis.readFully(rbytes, 0, testLength);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ openDataInputStream();
+ dis.readByte();
+ try {
+ dis.readFully(rbytes, 0, testLength);
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readFully$BII_Exception() throws IOException {
+ DataInputStream is = new DataInputStream(new ByteArrayInputStream(new byte[testLength]));
+
+ byte[] byteArray = new byte[testLength];
+
+ try {
+ is.readFully(byteArray, 0, -1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.readFully(byteArray, 0, byteArray.length + 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.readFully(byteArray, 1, byteArray.length);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.readFully(byteArray, -1, byteArray.length);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.readFully(null, 0, 1);
+ fail("Test 5: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ is = new DataInputStream(null);
+
+ try {
+ is.readFully(byteArray, 0, 1);
+ fail("Test 6: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void test_readLine() throws IOException {
+ String line;
+ os.writeBytes("Lorem\nipsum\rdolor sit amet...");
+ os.close();
+ openDataInputStream();
+ line = dis.readLine();
+ assertTrue("Test 1: Incorrect line written or read: " + line,
+ line.equals("Lorem"));
+ line = dis.readLine();
+ assertTrue("Test 2: Incorrect line written or read: " + line,
+ line.equals("ipsum"));
+ line = dis.readLine();
+ assertTrue("Test 3: Incorrect line written or read: " + line,
+ line.equals("dolor sit amet..."));
+
+ dis.close();
+ try {
+ dis.readLine();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readUnsignedByte() throws IOException {
+ os.writeByte((byte) -127);
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect byte written or read;",
+ 129, dis.readUnsignedByte());
+
+ try {
+ dis.readUnsignedByte();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readUnsignedByte();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readUnsignedShort() throws IOException {
+ os.writeShort(Short.MIN_VALUE);
+ os.close();
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect short written or read;",
+ (Short.MAX_VALUE + 1), dis.readUnsignedShort());
+
+ try {
+ dis.readUnsignedShort();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ dis.readUnsignedShort();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readUTFLjava_io_DataInput() throws IOException {
+ os.writeUTF(unihw);
+ os.close();
+ openDataInputStream();
+ assertTrue("Test 1: Incorrect UTF-8 string written or read.",
+ DataInputStream.readUTF(dis).equals(unihw));
+
+ try {
+ DataInputStream.readUTF(dis);
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ dis.close();
+ try {
+ DataInputStream.readUTF(dis);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void openDataInputStream() throws IOException {
+ dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ bos = new ByteArrayOutputStream();
+ os = new DataOutputStream(bos);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ try {
+ os.close();
+ } catch (Exception e) {
+ }
+ try {
+ dis.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java
new file mode 100644
index 0000000..a4bfc8e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldDataOutputStreamTest.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import tests.support.Support_OutputStream;
+
+public class OldDataOutputStreamTest extends junit.framework.TestCase {
+
+ private DataOutputStream os;
+
+ private DataInputStream dis;
+
+ private ByteArrayOutputStream bos;
+
+ private Support_OutputStream sos;
+
+ String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
+
+ private static final String testString = "Lorem ipsum dolor sit amet,\n" +
+ "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
+ "labore et dolore magna aliqua.\n";
+
+ private static final int testLength = testString.length();
+
+ public void test_flush() throws IOException {
+ BufferedOutputStream buf = new BufferedOutputStream(bos);
+
+ os = new DataOutputStream(buf);
+ os.writeInt(9087589);
+ assertTrue("Test 1: Written data should not be available.",
+ bos.toByteArray().length == 0);
+ os.flush();
+ assertTrue("Test 2: Written data should be available.",
+ bos.toByteArray().length > 0);
+ os.close();
+
+ openDataInputStream();
+ int c = dis.readInt();
+ assertEquals("Test 3: Failed to flush correctly;", 9087589, c);
+ dis.close();
+
+ os = new DataOutputStream(sos);
+ try {
+ os.flush();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$BII() throws IOException {
+ int r;
+ os.write(testString.getBytes(), 5, testLength - 7);
+ os.close();
+ openDataInputStream();
+ byte[] rbuf = new byte[testLength];
+ r = dis.read(rbuf, 0, testLength);
+ assertEquals("Test 1: Incorrect number of bytes read;",
+ testLength - 7, r);
+ dis.close();
+ assertTrue("Test 2: Incorrect bytes written or read.",
+ new String(rbuf, 0, r).equals(
+ testString.substring(5, testLength - 2)));
+ }
+
+ public void test_write$BII_Exception() throws IOException {
+ byte[] nullByteArray = null;
+ byte[] byteArray = new byte[10];
+
+ try {
+ os.write(nullByteArray, 0, 1);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ os.write(byteArray, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ os.write(byteArray, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ os.write(byteArray, 1, 10);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ os.write(42);
+ os.close();
+
+ openDataInputStream();
+ assertEquals("Test 1: Incorrect int written or read;",
+ 42, dis.read());
+ dis.close();
+
+ os = new DataOutputStream(sos);
+ try {
+ os.write(42);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeBytesLjava_lang_String() throws IOException {
+ os.writeBytes(testString);
+ os.close();
+
+ openDataInputStream();
+ byte[] rbuf = new byte[testLength];
+ dis.read(rbuf, 0, testLength);
+ dis.close();
+ assertTrue("Test 1: Incorrect bytes written or read.",
+ new String(rbuf, 0, testLength).equals(testString));
+
+ os = new DataOutputStream(sos);
+ try {
+ os.writeBytes(testString);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeCharsLjava_lang_String() throws IOException {
+ os.writeChars(unihw);
+ os.close();
+ openDataInputStream();
+ char[] chars = new char[unihw.length()];
+ int i, a = dis.available() / 2;
+ for (i = 0; i < a; i++) chars[i] = dis.readChar();
+ assertEquals("Test 1: Incorrect chars written or read;",
+ unihw, new String(chars, 0, i)
+ );
+ dis.close();
+
+ os = new DataOutputStream(sos);
+ try {
+ os.writeChars(unihw);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void openDataInputStream() throws IOException {
+ dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
+ }
+
+ protected void setUp() {
+ sos = new Support_OutputStream(true);
+ bos = new ByteArrayOutputStream();
+ os = new DataOutputStream(bos);
+ }
+
+ protected void tearDown() {
+ sos.setThrowsException(false);
+ try {
+ if (os != null)
+ os.close();
+ if (dis != null)
+ dis.close();
+ } catch (IOException e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java
new file mode 100644
index 0000000..894849a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileInputStreamTest.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import junit.framework.TestCase;
+import tests.support.Support_PlatformFile;
+
+public class OldFileInputStreamTest extends TestCase {
+
+ public String fileName;
+ private FileInputStream is;
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_File() {
+ // Test for method FileInputStream(File)
+ try {
+ File f = new File(fileName);
+ is = new FileInputStream(f);
+ is.close();
+ } catch (Exception e) {
+ fail("Failed to create FileInputStream : " + e.getMessage());
+ }
+ File f2 = new File("ImprobableFile.42");
+ try {
+ is = new FileInputStream(f2);
+ is.close();
+ f2.delete();
+ fail("FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_ConstructorLjava_io_FileDescriptor() {
+ try {
+ FileInputStream fis = new FileInputStream((FileDescriptor) null);
+ fis.close();
+ fail("NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ // Test for method FileInputStream(java.lang.String)
+ try {
+ is = new FileInputStream(fileName);
+ is.close();
+ } catch (Exception e) {
+ fail("Failed to create FileInputStream : " + e.getMessage());
+ }
+ try {
+ is = new FileInputStream("ImprobableFile.42");
+ is.close();
+ new File("ImprobableFile.42").delete();
+ fail("FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_available() throws IOException {
+ is = new FileInputStream(fileName);
+ assertEquals("Test 1: Returned incorrect number of available bytes;",
+ fileString.length(), is.available());
+ is.close();
+ try {
+ is.available();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_getChannel() {
+ // Test for method FileChannel FileInputStream.getChannel()
+ FileChannel channel;
+ byte[] buffer = new byte[100];
+ byte[] stringBytes;
+ final int offset = 5;
+ boolean equal = true;
+
+ try {
+ FileInputStream fis = new FileInputStream(fileName);
+ channel = fis.getChannel();
+ assertNotNull(channel);
+ assertTrue("Channel is closed.", channel.isOpen());
+
+ // Check that the channel is associated with the input stream.
+ channel.position(offset);
+ fis.read(buffer, 0, 10);
+ stringBytes = fileString.getBytes();
+ for (int i = 0; i < 10; i++) {
+ equal &= (buffer[i] == stringBytes[i + offset]);
+ }
+ assertTrue("Channel is not associated with this stream.", equal);
+
+ fis.close();
+ assertFalse("Channel has not been closed.", channel.isOpen());
+ } catch (FileNotFoundException e) {
+ fail("Could not find : " + fileName);
+ }
+
+ catch (IOException e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ public void test_read() throws IOException {
+ is = new FileInputStream(fileName);
+ int c = is.read();
+ assertEquals("Test 1: Read returned incorrect char;",
+ fileString.charAt(0), c);
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$B() throws IOException {
+ byte[] buf1 = new byte[100];
+ is = new FileInputStream(fileName);
+ is.skip(3000);
+ is.read(buf1);
+ is.close();
+ assertTrue("Test 1: Failed to read correct data.",
+ new String(buf1, 0, buf1.length).equals(
+ fileString.substring(3000, 3100)));
+
+ is.close();
+ try {
+ is.read(buf1);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ byte[] buf1 = new byte[10];
+ is = new FileInputStream(fileName);
+ is.skip(1000);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Test 1: Failed to skip to correct position.",
+ new String(buf1, 0, buf1.length).equals(
+ fileString.substring(1000, 1010)));
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void setUp() throws Exception {
+ fileName = System.getProperty("java.io.tmpdir");
+ String separator = System.getProperty("file.separator");
+ if (fileName.charAt(fileName.length() - 1) == separator.charAt(0))
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName,
+ "input.tst");
+ else
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName
+ + separator, "input.tst");
+ java.io.OutputStream fos = new FileOutputStream(fileName);
+ fos.write(fileString.getBytes());
+ fos.close();
+ }
+
+ protected void tearDown() throws Exception {
+ if (is != null) {
+ is.close();
+ }
+ new File(fileName).delete();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java
new file mode 100644
index 0000000..3661b3e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileOutputStreamTest.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class OldFileOutputStreamTest extends junit.framework.TestCase {
+
+ public String fileName;
+
+ FileOutputStream fos;
+
+ FileInputStream fis;
+
+ File f;
+
+ String tmpDirName = System.getProperty("java.io.tmpdir");
+
+ File tmpDir = new File(tmpDirName);
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_File() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDir);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(fileName = System.getProperty("java.io.tmpdir"), "fos.tst");
+ fos = new FileOutputStream(f);
+ }
+
+ public void test_ConstructorLjava_io_FileZ() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDir, false);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(tmpDirName, "fos.tst");
+ fos = new FileOutputStream(f, false);
+ fos.write("FZ1".getBytes(), 0, 3);
+ fos.close();
+ // Append data to existing file
+ fos = new FileOutputStream(f, true);
+ fos.write(fileString.getBytes());
+ fos.close();
+ byte[] buf = new byte[fileString.length() + 3];
+ fis = new FileInputStream(f);
+ fis.read(buf, 0, buf.length);
+ assertTrue("Test 2: Failed to create appending stream.", new String(buf, 0,
+ buf.length).equals("FZ1" + fileString));
+ fis.close();
+
+ // Check that the existing file is overwritten
+ fos = new FileOutputStream(f, false);
+ fos.write("FZ2".getBytes(), 0, 3);
+ fos.close();
+ fis = new FileInputStream(f);
+ int bytesRead = fis.read(buf, 0, buf.length);
+ assertTrue("Test 3: Failed to overwrite stream.", new String(buf, 0,
+ bytesRead).equals("FZ2"));
+ }
+
+ public void test_ConstructorLjava_lang_String() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDirName);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringZ() throws Exception {
+ try {
+ fos = new FileOutputStream(tmpDirName, true);
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+
+ f = new File(tmpDirName, "fos.tst");
+ fos = new FileOutputStream(f.getPath(), false);
+ fos.write("HI".getBytes(), 0, 2);
+ fos.close();
+ // Append data to existing file
+ fos = new FileOutputStream(f.getPath(), true);
+ fos.write(fileString.getBytes());
+ fos.close();
+ byte[] buf = new byte[fileString.length() + 2];
+ fis = new FileInputStream(f.getPath());
+ fis.read(buf, 0, buf.length);
+ assertTrue("Failed to create appending stream", new String(buf, 0,
+ buf.length).equals("HI" + fileString));
+ fis.close();
+
+ // Check that the existing file is overwritten
+ fos = new FileOutputStream(f.getPath(), false);
+ fos.write("HI".getBytes(), 0, 2);
+ fos.close();
+ fis = new FileInputStream(f.getPath());
+ int bytesRead = fis.read(buf, 0, buf.length);
+ assertTrue("Failed to overwrite stream", new String(buf, 0,
+ bytesRead).equals("HI"));
+ }
+
+ public void test_write$B() throws Exception {
+ // Test for method void java.io.FileOutputStream.write(byte [])
+ f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
+ fos = new FileOutputStream(f.getPath());
+ fos.write(fileString.getBytes());
+ fos.close();
+ try {
+ fos.write(fileString.getBytes());
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ fis = new FileInputStream(f.getPath());
+ byte rbytes[] = new byte[4000];
+ fis.read(rbytes, 0, fileString.length());
+ assertTrue("Test 2: Incorrect string written or read.",
+ new String(rbytes, 0, fileString.length()).equals(fileString));
+ }
+
+ public void test_writeI() throws IOException {
+ // Test for method void java.io.FileOutputStream.write(int)
+ f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
+ fos = new FileOutputStream(f.getPath());
+ fos.write('t');
+ fos.close();
+ try {
+ fos.write(42);
+ fail("Test: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ fis = new FileInputStream(f.getPath());
+ assertEquals("Test 1: Incorrect char written or read.",
+ 't', fis.read());
+ }
+
+ public void test_write$BII3() {
+ try {
+ new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e);
+ }
+ }
+
+ public void test_getChannel() throws Exception {
+ // Make sure that system properties are set correctly
+ if (tmpDir == null) {
+ throw new Exception("System property java.io.tmpdir not defined.");
+ }
+ File tmpfile = File.createTempFile("FileOutputStream", "tmp");
+ tmpfile.deleteOnExit();
+ FileOutputStream fos = new FileOutputStream(tmpfile);
+ byte[] b = new byte[10];
+ for (int i = 10; i < b.length; i++) {
+ b[i] = (byte) i;
+ }
+ fos.write(b);
+ fos.flush();
+ fos.close();
+ FileOutputStream f = new FileOutputStream(tmpfile, true);
+ assertEquals(10, f.getChannel().position());
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (f != null)
+ f.delete();
+ if (fis != null)
+ fis.close();
+ if (fos != null)
+ fos.close();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java b/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java
new file mode 100644
index 0000000..66fbbf6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFilePermissionTest.java
@@ -0,0 +1,191 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import java.io.FilePermission;
+import java.security.PermissionCollection;
+
+public class OldFilePermissionTest extends junit.framework.TestCase {
+
+ FilePermission readAllFiles;
+ FilePermission alsoReadAllFiles;
+ FilePermission allInCurrent;
+ FilePermission readInCurrent;
+ FilePermission readInFile;
+
+ @Override protected void setUp() throws Exception {
+ super.setUp();
+
+ readAllFiles = new FilePermission("<<ALL FILES>>", "read");
+ alsoReadAllFiles = new FilePermission("<<ALL FILES>>", "read");
+ allInCurrent = new FilePermission("*", "read, write, execute,delete");
+ readInCurrent = new FilePermission("*", "read");
+ readInFile = new FilePermission("aFile.file", "read");
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() {
+ // Test for method java.io.FilePermission(java.lang.String,
+ // java.lang.String)
+ assertTrue("Used to test", true);
+ FilePermission constructFile = new FilePermission("test constructor",
+ "write");
+ assertEquals("action given to the constructor did not correspond - constructor failed",
+ "write", constructFile.getActions());
+ assertEquals(
+ "name given to the constructor did not correspond - constructor failed",
+ "test constructor", constructFile.getName());
+
+ // Regression test for HARMONY-1050
+ try {
+ new FilePermission(null, "drink");
+ fail("Expected IAE");
+ } catch (IllegalArgumentException e) {
+ // Expected
+ }
+
+ try {
+ new FilePermission(null, "read");
+ fail("Expected NPE");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ new FilePermission(null, null);
+ fail("Expected IAE");
+ } catch (IllegalArgumentException e) {
+ // Expected
+ }
+ }
+
+ public void test_getActions() {
+ // Test for method java.lang.String java.io.FilePermission.getActions()
+ assertEquals("getActions should have returned only read", "read", readAllFiles
+ .getActions());
+ assertEquals("getActions should have returned all actions", "read,write,execute,delete", allInCurrent
+ .getActions());
+ }
+
+ public void test_equalsLjava_lang_Object() {
+ // test for method java.io.FilePermission.equals()
+ assertTrue(
+ "returned false when two instance of FilePermission is equal",
+ readAllFiles.equals(alsoReadAllFiles));
+ assertTrue(
+ "returned true when two instance of FilePermission is not equal",
+ !(readInCurrent.equals(readInFile)));
+ }
+
+ public void test_impliesLjava_security_Permission() {
+ // Test for method boolean
+ // java.io.FilePermission.implies(java.security.Permission)
+ assertTrue("Returned true for non-subset of actions", !readAllFiles
+ .implies(allInCurrent));
+ assertTrue("Returned true for non-subset of files", !allInCurrent
+ .implies(readAllFiles));
+ assertTrue("Returned false for subset of actions", allInCurrent
+ .implies(readInCurrent));
+ assertTrue("Returned false for subset of files", readAllFiles
+ .implies(readInCurrent));
+ assertTrue("Returned false for subset of files and actions",
+ allInCurrent.implies(readInFile));
+ assertTrue("Returned false for equal FilePermissions", readAllFiles
+ .implies(alsoReadAllFiles));
+
+ FilePermission fp3 = new FilePermission("/bob/*".replace('/',
+ File.separatorChar), "read,write");
+ FilePermission fp4 = new FilePermission("/bob/".replace('/',
+ File.separatorChar), "write");
+ assertTrue("returned true for same dir using * and not *", !fp3
+ .implies(fp4));
+ FilePermission fp5 = new FilePermission("/bob/file".replace('/',
+ File.separatorChar), "write");
+ assertTrue("returned false for same dir using * and file", fp3
+ .implies(fp5));
+
+ FilePermission fp6 = new FilePermission("/bob/".replace('/',
+ File.separatorChar), "read,write");
+ FilePermission fp7 = new FilePermission("/bob/*".replace('/',
+ File.separatorChar), "write");
+ assertTrue("returned false for same dir using not * and *", !fp6
+ .implies(fp7));
+ assertTrue("returned false for same subdir", fp6.implies(fp4));
+
+ FilePermission fp8 = new FilePermission("/".replace('/',
+ File.separatorChar), "read,write");
+ FilePermission fp9 = new FilePermission("/".replace('/',
+ File.separatorChar), "write");
+ assertTrue("returned false for same dir", fp8.implies(fp9));
+
+ FilePermission fp10 = new FilePermission("/".replace('/',
+ File.separatorChar), "read,write");
+ FilePermission fp11 = new FilePermission("/".replace('/',
+ File.separatorChar), "write");
+ assertTrue("returned false for same dir", fp10.implies(fp11));
+
+ FilePermission fp12 = new FilePermission("/*".replace('/',
+ File.separatorChar), "read,write");
+ assertTrue("returned false for same dir using * and dir", !fp12
+ .implies(fp10));
+ }
+
+ public void test_newPermissionCollection() {
+ // test for method java.io.FilePermission.newPermissionCollection
+ char s = File.separatorChar;
+ FilePermission perm[] = new FilePermission[4];
+ perm[0] = readAllFiles;
+ perm[1] = allInCurrent;
+ perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
+ "read,write");
+ perm[3] = new FilePermission(s + "tmp" + s + "test" + s
+ + "collection.file", "read");
+
+ PermissionCollection collect = perm[0].newPermissionCollection();
+ for (int i = 0; i < perm.length; i++) {
+ collect.add(perm[i]);
+ }
+ assertTrue("returned false for subset of files", collect
+ .implies(new FilePermission("*", "write")));
+ assertTrue("returned false for subset of name and action", collect
+ .implies(new FilePermission(s + "tmp", "read")));
+ assertTrue("returned true for non subset of file and action", collect
+ .implies(readInFile));
+
+ FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
+ File.separatorChar), "read");
+ PermissionCollection fpc = fp1.newPermissionCollection();
+ fpc.add(fp1);
+ fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
+ File.separatorChar), "write"));
+ FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
+ .replace('/', File.separatorChar), "read,write");
+ assertTrue("collection does not collate", fpc.implies(fp2));
+ }
+
+ public void test_hashCode() {
+ // test method java.io.FilePermission.hasCode()
+ assertTrue(
+ "two equal filePermission instances returned different hashCode",
+ readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
+ assertTrue(
+ "two filePermission instances with same permission name returned same hashCode",
+ readInCurrent.hashCode() != allInCurrent.hashCode());
+
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileReaderTest.java b/luni/src/test/java/libcore/java/io/OldFileReaderTest.java
new file mode 100644
index 0000000..fb541f3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileReaderTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+
+public class OldFileReaderTest extends junit.framework.TestCase {
+
+ FileReader br;
+
+ public void test_ConstructorLjava_io_File() {
+ File noFile = new File(System.getProperty("java.io.tmpdir"), "noreader.tst");
+ try {
+ br = new FileReader(noFile);
+ fail("Test 2: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ br = new FileReader(System.getProperty("java.io.tmpdir") + "/noreader.tst");
+ fail("Test 2: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileTest.java b/luni/src/test/java/libcore/java/io/OldFileTest.java
new file mode 100644
index 0000000..8265d20
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileTest.java
@@ -0,0 +1,241 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import junit.framework.TestCase;
+import static tests.support.Support_Exec.execAndGetOutput;
+import static tests.support.Support_Exec.javaProcessBuilder;
+
+public class OldFileTest extends TestCase {
+
+ /** Location to store tests in */
+ private File tempDirectory;
+
+ /** Temp file that does exist */
+ private File tempFile;
+
+ /** File separator */
+ private String slash = File.separator;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_File\nTest_FileDescriptor\nTest_FileInputStream\nTest_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ private static String platformId = "Android"
+ + System.getProperty("java.vm.version").replace('.', '-');
+
+ {
+ // Delete all old temporary files
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ String[] files = tempDir.list();
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(tempDir, files[i]);
+ if (f.isDirectory()) {
+ if (files[i].startsWith("hyts_resources"))
+ deleteTempFolder(f);
+ }
+ if (files[i].startsWith("hyts_") || files[i].startsWith("hyjar_"))
+ new File(tempDir, files[i]).delete();
+ }
+ }
+
+ private void deleteTempFolder(File dir) {
+ String files[] = dir.list();
+ for (int i = 0; i < files.length; i++) {
+ File f = new File(dir, files[i]);
+ if (f.isDirectory())
+ deleteTempFolder(f);
+ else {
+ f.delete();
+ }
+ }
+ dir.delete();
+
+ }
+
+ public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
+ String error;
+ String dirName = System.getProperty("java.io.tmpdir");
+ System.setProperty("user.dir", dirName);
+
+ File d = new File(dirName);
+ File f = new File(d, "input.tst");
+ if (!dirName.regionMatches((dirName.length() - 1), slash, 0, 1))
+ dirName += slash;
+ dirName += "input.tst";
+ error = String.format("Test 1: Incorrect file created: %s; %s expected.", f.getPath(), dirName);
+ assertTrue(error, f.getPath().equals(dirName));
+
+ String fileName = null;
+ try {
+ f = new File(d, fileName);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ }
+
+ d = null;
+ f = new File(d, "input.tst");
+ error = String.format("Test 3: Incorrect file created: %s; %s expected.",
+ f.getAbsolutePath(), dirName);
+ assertTrue(error, f.getAbsolutePath().equals(dirName));
+
+ // Regression test for Harmony-382
+ File s = null;
+ f = new File("/abc");
+ d = new File(s, "/abc");
+ assertEquals("Test 4: Incorrect file created;",
+ f.getAbsolutePath(), d.getAbsolutePath());
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_String() throws IOException {
+ String dirName = null;
+ String fileName = "input.tst";
+
+ String userDir = System.getProperty("java.io.tmpdir");
+ System.setProperty("user.dir", userDir);
+
+ File f = new File(dirName, fileName);
+ if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
+ userDir += slash;
+ userDir += "input.tst";
+ String error = String.format("Test 1: Incorrect file created: %s; %s expected.",
+ f.getAbsolutePath(), userDir);
+ assertTrue(error, f.getAbsolutePath().equals(userDir));
+
+ dirName = System.getProperty("java.io.tmpdir");
+ fileName = null;
+ try {
+ f = new File(dirName, fileName);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ fileName = "input.tst";
+ f = new File(dirName, fileName);
+ assertTrue("Test 3: Incorrect file created.", f.getPath()
+ .equals(userDir));
+
+ // Regression test for Harmony-382
+ String s = null;
+ f = new File("/abc");
+ File d = new File(s, "/abc");
+ assertEquals("Test 4: Incorrect file created;", d.getAbsolutePath(), f
+ .getAbsolutePath());
+ assertEquals("Test3: Created Incorrect File", "/abc", f
+ .getAbsolutePath());
+ }
+
+ public void test_createTempFileLjava_lang_StringLjava_lang_String() {
+ try {
+ // Providing an illegal file prefix.
+ File f3 = File.createTempFile("/../../../../../", null);
+ f3.delete();
+ fail("IOException not thrown");
+ } catch (IOException e) {
+ }
+ }
+
+ public void test_renameToLjava_io_File() {
+ String base = System.getProperty("java.io.tmpdir");
+ File dir = new File(base, platformId);
+ dir.mkdir();
+ File f = new File(dir, "xxx.xxx");
+ try {
+ f.renameTo(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_toURL3() throws MalformedURLException {
+ File dir = new File(""); // current directory
+ String newDirURL = dir.toURL().toString();
+ assertTrue("Test 1: URL does not end with slash.",
+ newDirURL.endsWith("/"));
+ }
+
+ public void test_deleteOnExit() throws IOException, InterruptedException {
+ String cts = System.getProperty("java.io.tmpdir");
+ File dir = new File(cts + "/hello");
+ dir.mkdir();
+ assertTrue(dir.exists());
+ File subDir = new File(cts + "/hello/world");
+ subDir.mkdir();
+ assertTrue(subDir.exists());
+
+ URL url = getClass().getResource("/HelloWorld.txt");
+ String classPath = url.toString();
+ int idx = classPath.indexOf("!");
+ assertTrue("could not find the path of the test jar/apk", idx > 0);
+ classPath = classPath.substring(9, idx); // cutting off jar:file:
+
+ ProcessBuilder builder = javaProcessBuilder();
+ builder.command().add("-cp");
+ builder.command().add(System.getProperty("java.class.path"));
+ builder.command().add("tests.support.Support_DeleteOnExitTest");
+ builder.command().add(dir.getAbsolutePath());
+ builder.command().add(subDir.getAbsolutePath());
+ execAndGetOutput(builder);
+
+ assertFalse(dir.exists());
+ assertFalse(subDir.exists());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // Make sure that system properties are set correctly
+ String userDir = System.getProperty("java.io.tmpdir");
+ if (userDir == null)
+ throw new Exception("System property java.io.tmpdir not defined.");
+ System.setProperty("java.io.tmpdir", userDir);
+
+ /** Setup the temporary directory */
+ if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
+ userDir += slash;
+ tempDirectory = new File(userDir + "tempDir"
+ + String.valueOf(System.currentTimeMillis()));
+ if (!tempDirectory.mkdir())
+ System.out.println("Setup for OldFileTest failed (1).");
+
+ /** Setup the temporary file */
+ tempFile = new File(tempDirectory, "tempfile");
+ FileOutputStream tempStream;
+ try {
+ tempStream = new FileOutputStream(tempFile.getPath(), false);
+ tempStream.close();
+ } catch (IOException e) {
+ System.out.println("Setup for OldFileTest failed (2).");
+ return;
+ }
+ }
+
+ protected void tearDown() {
+ if (tempFile.exists() && !tempFile.delete())
+ System.out
+ .println("OldFileTest.tearDown() failed, could not delete file!");
+ if (!tempDirectory.delete())
+ System.out
+ .println("OldFileTest.tearDown() failed, could not delete directory!");
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFileWriterTest.java b/luni/src/test/java/libcore/java/io/OldFileWriterTest.java
new file mode 100644
index 0000000..1db9a3e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFileWriterTest.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import junit.framework.TestCase;
+
+public class OldFileWriterTest extends TestCase {
+
+ FileWriter fw;
+
+ FileInputStream fis;
+
+ BufferedWriter bw;
+
+ File f;
+
+ public void test_ConstructorLjava_io_File_IOException() {
+ File dir = new File(System.getProperty("java.io.tmpdir"));
+
+ try {
+ fw = new FileWriter(dir);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_io_FileZ_IOException() {
+ File dir = new File(System.getProperty("java.io.tmpdir"));
+
+ try {
+ fw = new FileWriter(dir, true);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String_IOException() {
+ try {
+ fw = new FileWriter(System.getProperty("java.io.tmpdir"));
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+
+ public void test_ConstructorLjava_lang_StringZ_IOException() {
+ try {
+ fw = new FileWriter(System.getProperty("java.io.tmpdir"), false);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_handleEarlyEOFChar_1() {
+ String str = "All work and no play makes Jack a dull boy\n";
+ int NUMBER = 2048;
+ int j = 0;
+ int len = str.length() * NUMBER;
+ /* == 88064 *//* NUMBER compulsively written copies of the same string */
+ char[] strChars = new char[len];
+ for (int i = 0; i < NUMBER; ++i) {
+ for (int k = 0; k < str.length(); ++k) {
+ strChars[j++] = str.charAt(k);
+ }
+ }
+ File f = null;
+ FileWriter fw = null;
+ try {
+ f = File.createTempFile("ony", "by_one");
+ fw = new FileWriter(f);
+ fw.write(strChars);
+ fw.close();
+ InputStreamReader in = null;
+ FileInputStream fis = new FileInputStream(f);
+ in = new InputStreamReader(fis);
+ int b;
+ int errors = 0;
+ for (int offset = 0; offset < strChars.length; ++offset) {
+ b = in.read();
+ if (b == -1) {
+ fail("Early EOF at offset " + offset + "\n");
+ return;
+ }
+ }
+ assertEquals(0, errors);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void test_handleEarlyEOFChar_2() throws IOException {
+ int capacity = 65536;
+ byte[] bytes = new byte[capacity];
+ byte[] bs = {
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
+ };
+ for (int i = 0; i < bytes.length; i++) {
+ bytes[i] = bs[i / 8192];
+ }
+ String inputStr = new String(bytes);
+ int len = inputStr.length();
+ File f = File.createTempFile("FileWriterBugTest ", null);
+ FileWriter writer = new FileWriter(f);
+ writer.write(inputStr);
+ writer.close();
+ long flen = f.length();
+
+ FileReader reader = new FileReader(f);
+ char[] outChars = new char[capacity];
+ int outCount = reader.read(outChars);
+ String outStr = new String(outChars, 0, outCount);
+
+ f.deleteOnExit();
+ assertEquals(len, flen);
+ assertEquals(inputStr, outStr);
+ }
+
+ protected void setUp() throws Exception {
+ f = File.createTempFile("writer", ".tst");
+
+ if (f.exists())
+ if (!f.delete()) {
+ fail("Unable to delete test file");
+ }
+ }
+
+ protected void tearDown() {
+ try {
+ bw.close();
+ } catch (Exception e) {
+ }
+ try {
+ fis.close();
+ } catch (Exception e) {
+ }
+ f.delete();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java
new file mode 100644
index 0000000..848b1bf
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFilterInputStreamTest.java
@@ -0,0 +1,323 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import tests.support.Support_ASimpleInputStream;
+import tests.support.Support_PlatformFile;
+
+public class OldFilterInputStreamTest extends junit.framework.TestCase {
+
+ static class MyFilterInputStream extends java.io.FilterInputStream {
+ public MyFilterInputStream(java.io.InputStream is) {
+ super(is);
+ }
+ }
+
+ private String fileName;
+
+ private FilterInputStream is;
+
+ byte[] ibuf = new byte[4096];
+
+ private static final String testString = "Lorem ipsum dolor sit amet,\n" +
+ "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
+ "labore et dolore magna aliqua.\n";
+
+ private static final int testLength = testString.length();
+
+ public void test_Constructor() {
+ // The FilterInputStream object has already been created in setUp().
+ // If anything has gone wrong, closing it should throw a
+ // NullPointerException.
+ try {
+ is.close();
+ } catch (IOException e) {
+ fail("Unexpected IOException: " + e.getMessage());
+ } catch (NullPointerException npe) {
+ fail("Unexpected NullPointerException.");
+ }
+ }
+
+ public void test_available() throws IOException {
+ assertEquals("Test 1: Returned incorrect number of available bytes;",
+ testLength, is.available());
+
+ is.close();
+ try {
+ is.available();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws IOException {
+ is.close();
+
+ try {
+ is.read();
+ fail("Test 1: Read from closed stream succeeded.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
+ is = new MyFilterInputStream(sis);
+ try {
+ is.close();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sis.throwExceptionOnNextUse = false;
+ }
+
+ public void test_markI() throws Exception {
+ // Test for method void java.io.FilterInputStream.mark(int)
+ final int bufSize = 10;
+ byte[] buf1 = new byte[bufSize];
+ byte[] buf2 = new byte[bufSize];
+
+ // Purpose 1: Check that mark() does nothing if the filtered stream
+ // is a FileInputStream.
+ is.read(buf1, 0, bufSize);
+ is.mark(2 * bufSize);
+ is.read(buf1, 0, bufSize);
+ try {
+ is.reset();
+ } catch (IOException e) {
+ // Expected
+ }
+ is.read(buf2, 0, bufSize);
+ assertFalse("Test 1: mark() should have no effect.",
+ Arrays.equals(buf1, buf2));
+ is.close();
+
+ // Purpose 2: Check that mark() in combination with reset() works if
+ // the filtered stream is a BufferedInputStream.
+ is = new MyFilterInputStream(new BufferedInputStream(
+ new java.io.FileInputStream(fileName), 100));
+ is.read(buf1, 0, bufSize);
+ is.mark(2 * bufSize);
+ is.read(buf1, 0, bufSize);
+ is.reset();
+ is.read(buf2, 0, bufSize);
+ assertTrue("Test 2: mark() or reset() has failed.",
+ Arrays.equals(buf1, buf2));
+ }
+
+ public void test_markSupported() throws Exception {
+ // Test for method boolean java.io.FilterInputStream.markSupported()
+
+ // Test 1: Check that markSupported() returns false for a filtered
+ // input stream that is known to not support mark().
+ assertFalse("Test 1: markSupported() incorrectly returned true " +
+ "for a FileInputStream.", is.markSupported());
+ is.close();
+ // Test 2: Check that markSupported() returns true for a filtered
+ // input stream that is known to support mark().
+ is = new MyFilterInputStream(new BufferedInputStream(
+ new java.io.FileInputStream(fileName), 100));
+ assertTrue("Test 2: markSupported() incorrectly returned false " +
+ "for a BufferedInputStream.", is.markSupported());
+ }
+
+ public void test_read() throws IOException {
+ int c = is.read();
+ assertEquals("Test 1: Read returned incorrect char;",
+ testString.charAt(0), c);
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$B() throws IOException {
+ // Test for method int java.io.FilterInputStream.read(byte [])
+ byte[] buf1 = new byte[100];
+ is.read(buf1);
+ assertTrue("Test 1: Failed to read correct data.",
+ new String(buf1, 0, buf1.length).equals(
+ testString.substring(0, 100)));
+
+ is.close();
+ try {
+ is.read(buf1);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$BII_Exception() throws IOException {
+ byte[] buf = null;
+ try {
+ is.read(buf, -1, 0);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ buf = new byte[1000];
+ try {
+ is.read(buf, -1, 0);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf, -1, -1);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf, 0, 1001);
+ fail("Test 5: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf, 1001, 0);
+ fail("Test 6: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ is.read(buf, 500, 501);
+ fail("Test 7: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.read(buf, 0, 100);
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_reset() throws Exception {
+ // Test for method void java.io.FilterInputStream.reset()
+
+ // Test 1: Check that reset() throws an IOException if the
+ // filtered stream is a FileInputStream.
+ try {
+ is.reset();
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test 2: Check that reset() throws an IOException if the
+ // filtered stream is a BufferedInputStream but mark() has not
+ // yet been called.
+ is = new MyFilterInputStream(new BufferedInputStream(
+ new java.io.FileInputStream(fileName), 100));
+ try {
+ is.reset();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test 3: Check that reset() in combination with mark()
+ // works correctly.
+ final int bufSize = 10;
+ byte[] buf1 = new byte[bufSize];
+ byte[] buf2 = new byte[bufSize];
+ is.read(buf1, 0, bufSize);
+ is.mark(2 * bufSize);
+ is.read(buf1, 0, bufSize);
+ try {
+ is.reset();
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException.");
+ }
+ is.read(buf2, 0, bufSize);
+ assertTrue("Test 4: mark() or reset() has failed.",
+ Arrays.equals(buf1, buf2));
+ }
+
+ public void test_skipJ() throws IOException {
+ byte[] buf1 = new byte[10];
+ is.skip(10);
+ is.read(buf1, 0, buf1.length);
+ assertTrue("Test 1: Failed to skip to the correct position.",
+ new String(buf1, 0, buf1.length).equals(
+ testString.substring(10, 20)));
+
+ is.close();
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void setUp() {
+ try {
+ fileName = System.getProperty("java.io.tmpdir");
+ String separator = System.getProperty("file.separator");
+ if (fileName.charAt(fileName.length() - 1) == separator.charAt(0))
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName,
+ "input.tst");
+ else
+ fileName = Support_PlatformFile.getNewPlatformFile(fileName
+ + separator, "input.tst");
+ java.io.OutputStream fos = new java.io.FileOutputStream(fileName);
+ fos.write(testString.getBytes());
+ fos.close();
+ is = new MyFilterInputStream(new java.io.FileInputStream(fileName));
+ } catch (java.io.IOException e) {
+ System.out.println("Exception during setup");
+ e.printStackTrace();
+ }
+ }
+
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ System.out.println("Unexpected exception in tearDown().");
+ }
+ new java.io.File(fileName).delete();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java
new file mode 100644
index 0000000..da8b85d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFilterOutputStreamTest.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import tests.support.Support_OutputStream;
+
+public class OldFilterOutputStreamTest extends junit.framework.TestCase {
+
+ private java.io.FilterOutputStream os;
+
+ java.io.ByteArrayOutputStream bos;
+
+ java.io.ByteArrayInputStream bis;
+
+ byte[] ibuf = new byte[4096];
+
+ private final String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ private final int testLength = fileString.length();
+
+
+ public void test_ConstructorLjava_io_OutputStream() {
+ // Test for method java.io.FilterOutputStream(java.io.OutputStream)
+ try {
+ bos = new ByteArrayOutputStream();
+ os = new FilterOutputStream(bos);
+ os.write('t');
+ } catch (java.io.IOException e) {
+ fail("Constructor test failed : " + e.getMessage());
+ }
+ }
+
+ public void test_close() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream();
+ os = new FilterOutputStream(sos);
+ os.close();
+
+ try {
+ os.write(42);
+ } catch (java.io.IOException e) {
+ fail("Test 1: Unexpected IOException.");
+ }
+
+ sos.setThrowsException(true);
+ try {
+ os.write(42);
+ fail("Test 2: IOException expected.");
+ } catch (java.io.IOException e) {
+ // Expected.
+ }
+
+ os = new FilterOutputStream(sos);
+ try {
+ os.close();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_flush() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream(550);
+ os = new FilterOutputStream(sos);
+ os.write(fileString.getBytes(), 0, 500);
+ os.flush();
+ assertEquals("Test 1: Bytes not written after flush;",
+ 500, sos.size());
+
+ sos.setThrowsException(true);
+ try {
+ os.flush();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+ }
+
+ public void test_write$B() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream(testLength);
+ os = new FilterOutputStream(sos);
+ os.write(fileString.getBytes());
+
+ bis = new ByteArrayInputStream(sos.toByteArray());
+ assertTrue("Test 1: Bytes have not been written.",
+ bis.available() == testLength);
+ byte[] wbytes = new byte[testLength];
+ bis.read(wbytes, 0, testLength);
+ assertTrue("Test 2: Incorrect bytes written or read.",
+ fileString.equals(new String(wbytes)));
+
+ try {
+ // Support_OutputStream throws an IOException if the internal
+ // buffer is full, which it should be now.
+ os.write(42);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$BII() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream(testLength);
+ os = new FilterOutputStream(sos);
+ os.write(fileString.getBytes(), 10, testLength - 10);
+
+ bis = new ByteArrayInputStream(sos.toByteArray());
+ assertTrue("Test 1: Bytes have not been written.",
+ bis.available() == testLength - 10);
+ byte[] wbytes = new byte[testLength - 10];
+ bis.read(wbytes);
+ assertTrue("Test 2: Incorrect bytes written or read.",
+ fileString.substring(10).equals(new String(wbytes)));
+
+ try {
+ // Support_OutputStream throws an IOException if the internal
+ // buffer is full, which it should be eventually.
+ os.write(fileString.getBytes());
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_write$BII_Exception() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream(testLength);
+ os = new FilterOutputStream(sos);
+ byte[] buf = new byte[10];
+
+ try {
+ os.write(buf, -1, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ os.write(buf, 0, -1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ os.write(buf, 10, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ Support_OutputStream sos = new Support_OutputStream(1);
+ os = new FilterOutputStream(sos);
+ os.write(42);
+
+ bis = new ByteArrayInputStream(sos.toByteArray());
+ assertTrue("Test 1: Byte has not been written.",
+ bis.available() == 1);
+ assertEquals("Test 2: Incorrect byte written or read;",
+ 42, bis.read());
+
+ try {
+ // Support_OutputStream throws an IOException if the internal
+ // buffer is full, which it should be now.
+ os.write(42);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void tearDown() {
+ try {
+ if (bos != null)
+ bos.close();
+ if (bis != null)
+ bis.close();
+ if (os != null)
+ os.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFilterReaderTest.java b/luni/src/test/java/libcore/java/io/OldFilterReaderTest.java
new file mode 100644
index 0000000..7d1d3de
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFilterReaderTest.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.FilterReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class OldFilterReaderTest extends junit.framework.TestCase {
+
+ private boolean called;
+ private FilterReader fr;
+
+ static class MyFilterReader extends java.io.FilterReader {
+ public MyFilterReader(java.io.Reader reader) {
+ super(reader);
+ }
+ }
+
+ class MockReader extends java.io.Reader {
+ public MockReader() {
+ }
+
+ public void close() throws IOException {
+ called = true;
+ }
+
+ public void mark(int readLimit) throws IOException {
+ called = true;
+ }
+
+ public boolean markSupported() {
+ called = true;
+ return false;
+ }
+
+ public int read() throws IOException {
+ called = true;
+ return 0;
+ }
+
+ public int read(char[] buffer, int offset, int count) throws IOException {
+ called = true;
+ return 0;
+ }
+
+ public boolean ready() throws IOException {
+ called = true;
+ return true;
+ }
+
+ public void reset() throws IOException {
+ called = true;
+ }
+
+ public long skip(long count) throws IOException {
+ called = true;
+ return 0;
+ }
+ }
+
+ public void test_ConstructorLjava_io_Reader() {
+
+ FilterReader myReader = null;
+
+ called = true;
+
+ try {
+ myReader = new MyFilterReader(null);
+ fail("NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_close() throws IOException {
+ fr.close();
+ assertTrue("close() has not been called.", called);
+ }
+
+ public void test_markI() throws IOException {
+ fr.mark(0);
+ assertTrue("mark(int) has not been called.", called);
+ }
+
+ public void test_markSupported() {
+ fr.markSupported();
+ assertTrue("markSupported() has not been called.", called);
+ }
+
+ public void test_read() throws IOException {
+ fr.read();
+ assertTrue("read() has not been called.", called);
+ }
+
+ public void test_read$CII() throws IOException {
+ char[] buffer = new char[5];
+ fr.read(buffer, 0, 5);
+ assertTrue("read(char[], int, int) has not been called.", called);
+ }
+
+ public void test_read$CII_Exception() throws IOException {
+ byte[] bbuffer = new byte[20];
+ char[] buffer = new char[10];
+
+ fr = new MyFilterReader(new InputStreamReader(
+ new ByteArrayInputStream(bbuffer)));
+
+ try {
+ fr.read(buffer, 0, -1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ fr.read(buffer, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ fr.read(buffer, 10, 1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ready() throws IOException {
+ fr.ready();
+ assertTrue("ready() has not been called.", called);
+ }
+
+ public void test_reset() throws IOException {
+ fr.reset();
+ assertTrue("reset() has not been called.", called);
+ }
+
+ public void test_skip() throws IOException {
+ fr.skip(10);
+ assertTrue("skip(long) has not been called.", called);
+ }
+
+ protected void setUp() {
+
+ fr = new MyFilterReader(new MockReader());
+ called = false;
+ }
+
+ protected void tearDown() {
+
+ try {
+ fr.close();
+ } catch (Exception e) {
+ System.out.println("Exception during FilterReaderTest tear down.");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldFilterWriterTest.java b/luni/src/test/java/libcore/java/io/OldFilterWriterTest.java
new file mode 100644
index 0000000..f4c9797
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldFilterWriterTest.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+public class OldFilterWriterTest extends junit.framework.TestCase {
+
+ private boolean called;
+ private FilterWriter fw;
+
+ static class MyFilterWriter extends java.io.FilterWriter {
+ public MyFilterWriter(java.io.Writer writer) {
+ super(writer);
+ }
+ }
+
+ class MockWriter extends java.io.Writer {
+ public MockWriter() {
+ }
+
+ public void close() throws IOException {
+ called = true;
+ }
+
+ public void flush() throws IOException {
+ called = true;
+ }
+
+ public void write(char[] buffer, int offset, int count) throws IOException {
+ called = true;
+ }
+
+ public void write(int oneChar) throws IOException {
+ called = true;
+ }
+
+ public void write(String str, int offset, int count) throws IOException {
+ called = true;
+ }
+
+ public long skip(long count) throws IOException {
+ called = true;
+ return 0;
+ }
+ }
+
+ public void test_ConstructorLjava_io_Writer() {
+
+ FilterWriter myWriter = null;
+
+ called = true;
+
+ try {
+ myWriter = new MyFilterWriter(null);
+ fail("NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ }
+
+ public void test_close() throws IOException {
+ fw.close();
+ assertTrue("close() has not been called.", called);
+ }
+
+ public void test_flush() throws IOException {
+ fw.flush();
+ assertTrue("flush() has not been called.", called);
+ }
+
+ public void test_writeI() throws IOException {
+ fw.write(0);
+ assertTrue("write(int) has not been called.", called);
+ }
+
+ public void test_write$CII() throws IOException {
+ char[] buffer = new char[5];
+ fw.write(buffer, 0, 5);
+ assertTrue("write(char[], int, int) has not been called.", called);
+ }
+
+ public void test_write$CII_Exception() throws IOException {
+ char[] buffer = new char[10];
+
+ fw = new MyFilterWriter(new OutputStreamWriter(
+ new ByteArrayOutputStream()));
+
+ try {
+ fw.write(buffer, 0, -1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ fw.write(buffer, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ fw.write(buffer, 10, 1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeLjava_lang_StringII() throws IOException {
+ fw.write("Hello world", 0, 5);
+ assertTrue("write(String, int, int) has not been called.", called);
+ }
+
+ protected void setUp() {
+
+ fw = new MyFilterWriter(new MockWriter());
+ called = false;
+ }
+
+ protected void tearDown() {
+
+ try {
+ fw.close();
+ } catch (Exception e) {
+ System.out.println("Exception during OldFilterWriterTest tear down.");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java b/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java
new file mode 100644
index 0000000..db5a374
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldInputStreamReaderTest.java
@@ -0,0 +1,295 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleInputStream;
+
+public class OldInputStreamReaderTest extends TestCase {
+
+ private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
+
+ private InputStream in;
+
+ private InputStreamReader reader;
+
+ private InputStreamReader is;
+
+ private InputStream fis;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ in = new ByteArrayInputStream(source.getBytes("UTF-8"));
+ reader = new InputStreamReader(in, "UTF-8");
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ OutputStreamWriter osw = new OutputStreamWriter(bos);
+ char[] buf = new char[fileString.length()];
+ fileString.getChars(0, fileString.length(), buf, 0);
+ osw.write(buf);
+ osw.close();
+ fis = new ByteArrayInputStream(bos.toByteArray());
+ is = new InputStreamReader(fis);
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ in.close();
+ is.close();
+ fis.close();
+ } catch (IOException e) {
+ }
+
+ super.tearDown();
+ }
+
+ public void testReadcharArrayintint() throws IOException {
+ try {
+ reader.read(new char[3], -1, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 0, -1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 4, 0);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 3, 1);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 1, 3);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ try {
+ reader.read(new char[3], 0, 4);
+ fail("Should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ reader.read(null, 0, 0);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ assertEquals(0, reader.read(new char[3], 3, 0));
+ char[] chars = new char[source.length()];
+ assertEquals(0, reader.read(chars, 0, 0));
+ assertEquals(0, chars[0]);
+ assertEquals(3, reader.read(chars, 0, 3));
+ assertEquals(5, reader.read(chars, 3, 5));
+ assertEquals(source.length() - 8, reader.read(chars, 8,
+ chars.length - 8));
+ assertTrue(Arrays.equals(chars, source.toCharArray()));
+ assertEquals(-1, reader.read(chars, 0, chars.length));
+ assertTrue(Arrays.equals(chars, source.toCharArray()));
+ }
+
+ public void testReadcharArrayintint2() throws IOException {
+ char[] chars = new char[source.length()];
+ assertEquals(source.length() - 3, reader.read(chars, 0,
+ chars.length - 3));
+ assertEquals(3, reader.read(chars, 0, 10));
+ }
+
+ public void testReady() throws IOException {
+ assertTrue(reader.ready());
+ reader.read(new char[source.length()]);
+ assertFalse(reader.ready());
+ }
+
+ public void testInputStreamReaderSuccessiveReads() throws IOException {
+ byte[] data = new byte[8192 * 2];
+ Arrays.fill(data, (byte) 116); // 116 = ISO-8859-1 value for 't'
+ ByteArrayInputStream bis = new ByteArrayInputStream(data);
+ InputStreamReader isr = new InputStreamReader(bis, "ISO-8859-1");
+
+ // One less than the InputStreamReader.BUFFER_SIZE
+ char[] buf = new char[8191];
+ int bytesRead = isr.read(buf, 0, buf.length);
+ if (bytesRead == -1) {
+ throw new RuntimeException();
+ }
+ bytesRead = isr.read(buf, 0, buf.length);
+ if (bytesRead == -1) {
+ throw new RuntimeException();
+ }
+ }
+
+ public void test_ConstructorLjava_io_InputStream() {
+ // Test for method java.io.InputStreamReader(java.io.InputStream)
+ assertTrue("Used to test other methods", true);
+ }
+
+ public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
+ // Test for method java.io.InputStreamReader(java.io.InputStream,
+ // java.lang.String)
+ try {
+ is = new InputStreamReader(fis, "8859_1");
+ } catch (UnsupportedEncodingException e) {
+ fail("Unable to create input stream : " + e.getMessage());
+ }
+
+ try {
+ is = new InputStreamReader(fis, "Bogus");
+ } catch (UnsupportedEncodingException e) {
+ return;
+ }
+ fail("Failed to throw Unsupported Encoding exception");
+ }
+
+ public void test_close() {
+ // Test for method void java.io.InputStreamReader.close()
+ try {
+ is.close();
+ } catch (IOException e) {
+ fail("Failed to close reader : " + e.getMessage());
+ }
+ try {
+ is.read();
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Exception means read failed due to close
+ }
+
+ is = new InputStreamReader(new Support_ASimpleInputStream(true));
+ try {
+ is.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ }
+
+ public void testClose() throws IOException {
+ reader.close();
+ try {
+ reader.ready();
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ }
+ reader.close();
+ }
+
+ public void test_read$CII() {
+ // Test for method int java.io.InputStreamReader.read(char [], int, int)
+ try {
+ char[] rbuf = new char[100];
+ char[] sbuf = new char[100];
+ fileString.getChars(0, 100, sbuf, 0);
+ is.read(rbuf, 0, 100);
+ for (int i = 0; i < rbuf.length; i++)
+ assertTrue("returned incorrect chars", rbuf[i] == sbuf[i]);
+ } catch (IOException e) {
+ fail("Exception during read test : " + e.getMessage());
+ }
+ }
+
+ public void test_ready() {
+ // Test for method boolean java.io.InputStreamReader.ready()
+ try {
+ assertTrue("Ready test failed", is.ready());
+ is.read();
+ assertTrue("More chars, but not ready", is.ready());
+ } catch (IOException e) {
+ fail("Exception during ready test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Test for regression of a bug that dropped characters when
+ * multibyte encodings spanned buffer boundaries.
+ */
+ public void test_readWhenCharacterSpansBuffer() {
+ final byte[] suffix = {
+ (byte) 0x93, (byte) 0xa1, (byte) 0x8c, (byte) 0xb4,
+ (byte) 0x97, (byte) 0x43, (byte) 0x88, (byte) 0xea,
+ (byte) 0x98, (byte) 0x59
+ };
+ final char[] decodedSuffix = {
+ (char) 0x85e4, (char) 0x539f, (char) 0x4f51, (char) 0x4e00,
+ (char) 0x90ce
+ };
+ final int prefixLength = 8189;
+
+ byte[] bytes = new byte[prefixLength + 10];
+ Arrays.fill(bytes, (byte) ' ');
+ System.arraycopy(suffix, 0, bytes, prefixLength, suffix.length);
+ ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+
+ try {
+ InputStreamReader isr = new InputStreamReader(is, "SHIFT_JIS");
+ char[] chars = new char[8192];
+ int at = 0;
+
+ for (;;) {
+ int amt = isr.read(chars);
+ if (amt <= 0) {
+ break;
+ }
+
+ for (int i = 0; i < amt; i++) {
+ char c = chars[i];
+ if (at < prefixLength) {
+ if (c != ' ') {
+ fail("Found bad prefix character " +
+ (int) c + " at " + at);
+ }
+ } else {
+ char decoded = decodedSuffix[at - prefixLength];
+ if (c != decoded) {
+ fail("Found mismatched character " +
+ (int) c + " at " + at);
+ }
+ }
+ at++;
+ }
+ }
+ } catch (IOException ex) {
+ throw new RuntimeException("unexpected exception", ex);
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldInputStreamTest.java
new file mode 100644
index 0000000..04ec124
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldInputStreamTest.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class OldInputStreamTest extends junit.framework.TestCase {
+
+ public static final String testString = "Lorem ipsum dolor sit amet,\n" +
+ "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
+ "labore et dolore magna aliqua.\n";
+
+ private InputStream is;
+
+ class MockInputStream extends java.io.InputStream {
+
+ private byte[] input;
+ private int position;
+
+ public MockInputStream() {
+ super();
+ input = testString.getBytes();
+ position = 0;
+ }
+
+ public int read() throws IOException {
+ int result = -1;
+ if (position < input.length) {
+ result = input[position];
+ position++;
+ }
+ return result;
+ }
+ }
+
+ public void test_Constructor() {
+ try {
+ InputStream myIS = new MockInputStream();
+ myIS.close();
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e.getMessage());
+ }
+ }
+
+ public void test_available() throws IOException {
+ assertEquals(is.available(), 0);
+ }
+
+ public void test_close() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e.getMessage());
+ }
+ }
+
+ public void test_markI() {
+ try {
+ is.mark(10);
+ } catch (Exception e) {
+ fail("Unexpected exception: " + e.getMessage());
+ }
+ }
+
+ public void test_markSupported() throws IOException {
+ assertFalse("markSupported() has returned the wrong default value.",
+ is.markSupported());
+ }
+
+ public void test_read$B() throws IOException {
+ byte[] b = new byte[10];
+ byte[] ref = testString.getBytes();
+ boolean equal = true;
+ int bytesRead = 0;
+ int i;
+
+ // Test 1: This read operation should complete without an error.
+ assertEquals("Test 1: Incorrect count of bytes read.",
+ is.read(b), 10);
+
+ for (i = 0; i < 10; i++) {
+ equal &= (b[i] == ref[i]);
+ }
+ assertTrue("Test 1: Wrong bytes read.", equal);
+
+ // Test 2: Test that the correct number of bytes read is returned
+ // if the source has less bytes available than fit in the buffer.
+ b = new byte[ref.length];
+ bytesRead = is.read(b);
+ assertEquals("Test 2: Incorrect count of bytes read.",
+ bytesRead, ref.length - 10);
+
+ for (i = 0; i < bytesRead; i++) {
+ equal &= (b[i] == ref[i + 10]);
+ }
+ assertTrue("Test 2: Wrong bytes read.", equal);
+
+ // Test 3: Since we have now reached the end of the source,
+ // the next call of read(byte[]) should return -1.
+ bytesRead = is.read(b);
+ assertEquals("Test 3:", bytesRead, -1);
+ }
+
+ public void test_read$BII_Exception() throws IOException {
+ byte[] b = new byte[10];
+ int bytesRead = 0;
+
+ // Test 1: Invalid offset.
+ try {
+ bytesRead = is.read(b, -1, 5);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // Test 2: Invalid length.
+ try {
+ bytesRead = is.read(b, 5, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // Test 3: Invalid offset and length combination (sum is larger
+ // than the length of b).
+ try {
+ bytesRead = is.read(b, 6, 5);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // Test 4: Border case.
+ try {
+ bytesRead = is.read(b, 6, 4);
+ } catch (IndexOutOfBoundsException e) {
+ fail("Test 4: Unexpected IndexOutOfBoundsException.");
+ }
+ assertEquals("Test 4:", bytesRead, 4);
+
+ // Test 5: Border case.
+ try {
+ bytesRead = is.read(b, 6, 0);
+ } catch (Exception e) {
+ fail("Test 5: Unexpected Exception " + e.getMessage());
+ }
+ assertEquals("Test 5:", bytesRead, 0);
+ }
+
+ public void test_read$BII() throws IOException {
+ byte[] b = new byte[10];
+ byte[] ref = testString.getBytes();
+ boolean equal = true;
+ int bytesRead = 0;
+ int i;
+
+ // Test 1: This read operation should complete without an error.
+ assertEquals("Test 1: Incorrect count of bytes read.",
+ is.read(b, 0, 5), 5);
+
+ for (i = 0; i < 5; i++) {
+ equal &= (b[i] == ref[i]);
+ }
+ assertTrue("Test 1: Wrong bytes read.", equal);
+
+ // Test 2: Read operation with offset.
+ assertEquals("Test 2: Incorrect count of bytes read.",
+ is.read(b, 5, 3), 3);
+
+ for (i = 5; i < 8; i++) {
+ equal &= (b[i] == ref[i]);
+ }
+ assertTrue("Test 2: Wrong bytes read.", equal);
+
+ // Test 3: Test that the correct number of bytes read is returned
+ // if the source has less bytes available than fit in the buffer.
+ b = new byte[ref.length];
+ bytesRead = is.read(b, 2, b.length - 2);
+
+ // 8 bytes have been read during tests 1 and 2.
+ assertEquals("Test 3: Incorrect count of bytes read.",
+ bytesRead, ref.length - 8);
+
+ // The first two bytes of b should be 0 because of the offset.
+ assertEquals("Test 3:", b[0], 0);
+ assertEquals("Test 3:", b[1], 0);
+ for (i = 0; i < bytesRead; i++) {
+ equal &= (b[i + 2] == ref[i + 8]);
+ }
+ assertTrue("Test 2: Wrong bytes read.", equal);
+
+ // Test 4: Since we have now reached the end of the source,
+ // the next call of read(byte[], int, int) should return -1.
+ assertEquals("Test 4:", is.read(b, 0, 2), -1);
+ }
+
+ public void test_reset() {
+ try {
+ is.reset();
+ fail("IOException expected.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_skipL() throws IOException {
+ byte[] b = new byte[12];
+ byte[] ref = testString.getBytes();
+ int i;
+ boolean equal = true;
+
+ // Test 1: Check that skip(long) just returns 0 if called with a
+ // negative number.
+ assertEquals("Test 1:", is.skip(-42), 0);
+ assertEquals("Test 1: Incorrect count of bytes read.",
+ is.read(b), 12);
+ for (i = 0; i < 12; i++) {
+ equal &= (b[i] == ref[i]);
+ }
+ assertTrue("Test 1: Wrong bytes read.", equal);
+
+ // Test 2: Check if the number of bytes skipped matches the requested
+ // number of bytes to skip.
+ assertEquals("Test 2: Incorrect count of bytes skipped.",
+ is.skip(17), 17);
+
+ // Test 3: Check that bytes have actually been skipped
+ is.read(b, 0, 10);
+ for (i = 0; i < 10; i++) {
+ equal &= (b[i] == ref[i + 29]);
+ }
+ assertTrue("Test 3: Wrong bytes read.", equal);
+
+ // Test 4: Test that the correct number of bytes skipped is returned
+ // if the source has less bytes available than fit in the buffer.
+ assertEquals("Test 4: Incorrect count of bytes skipped.",
+ is.skip(ref.length), ref.length - 39);
+
+ // Test 5: Since we have now reached the end of the source,
+ // the next call of read(byte[]) should return -1 and calling
+ // skip(long) should return 0.
+ assertEquals("Test 5:", is.read(b), -1);
+ assertEquals("Test 5:", is.skip(10), 0);
+ }
+
+ protected void setUp() {
+ is = new MockInputStream();
+ }
+
+ protected void tearDown() {
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java
new file mode 100644
index 0000000..1f5544b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldLineNumberInputStreamTest.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.io;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.LineNumberInputStream;
+import junit.framework.TestCase;
+
+public class OldLineNumberInputStreamTest extends TestCase {
+
+ final String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501";
+
+ String dosText = "0\r\n1\r\n2";
+
+ LineNumberInputStream lnis;
+
+ LineNumberInputStream lnis2;
+
+ public void test_available() throws IOException {
+ assertEquals("Test 1: Returned incorrect number of available bytes;",
+ text.length() / 2, lnis.available());
+
+ lnis.close();
+ try {
+ lnis.available();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read() throws IOException {
+ assertEquals("Test 1: Failed to read correct byte;",
+ '0', lnis.read());
+ assertEquals("Test 2: Failed to read correct byte on dos text;",
+ '0', lnis2.read());
+ assertEquals("Test 3: Failed to read correct byte on dos text;",
+ '\n', lnis2.read());
+ assertEquals("Test 4: Failed to read correct byte on dos text;",
+ '1', lnis2.read());
+ assertEquals("Test 5: Failed to read correct byte on dos text;",
+ '\n', lnis2.read());
+ assertEquals("Test 6: Failed to read correct byte on dos text;",
+ '2', lnis2.read());
+
+ lnis.close();
+ try {
+ lnis.read();
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$BII() throws IOException {
+ byte[] buf = new byte[100];
+ lnis.read(buf, 0, 100);
+ assertTrue("Test 1: Incorrect bytes read.",
+ new String(buf, 0, 100).equals(text.substring(0, 100)));
+
+ lnis.close();
+ try {
+ lnis.read(buf, 0, 100);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$BII_Exception() throws IOException {
+ byte[] buf = new byte[10];
+
+ try {
+ lnis.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnis.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnis.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_reset() throws IOException {
+ lnis.mark(40);
+ lnis.skip(4);
+ lnis.reset();
+ assertEquals("Test 1: Failed to reset", 0, lnis.getLineNumber());
+ assertEquals("Test 2: Failed to reset", '0', lnis.read());
+ lnis.reset();
+
+ try {
+ lnis.mark(5);
+ lnis.skip(100);
+ lnis.reset();
+ fail("Test 3: Failed to invalidate mark.");
+ } catch (IOException e) {
+ // Correct; mark has been invalidated.
+ }
+
+ lnis.mark(5);
+ lnis.close();
+ try {
+ lnis.reset();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_setLineNumberI() {
+ lnis.setLineNumber(42);
+ assertEquals("Test 1: Failed to set line number;",
+ 42, lnis.getLineNumber());
+ // Repeat the test with a different number to make sure that the
+ // line number is really set.
+ lnis.setLineNumber(89);
+ assertEquals("Test 2: Failed to set line number;",
+ 89, lnis.getLineNumber());
+ }
+
+ public void test_skipJ() throws IOException {
+ long skipped = lnis.skip(4);
+ assertEquals("Test 1: Incorrect number of characters skipped;",
+ 4, skipped);
+ assertEquals("Test 2: Skip failed to increment line number;",
+ 2, lnis.getLineNumber());
+
+ lnis.close();
+ try {
+ lnis.skip(4);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ protected void setUp() {
+ /*
+ * In order for IOException to be thrown in reset(),the inputStream to
+ * the constructor cannot be a byteArrayInputstream because the reset()
+ * in byteArrayInputStream does not throw IOException. When
+ * BufferedInputStream is used, the size of the buffer must be smaller
+ * than the readlimit in mark inorder for IOException to be thrown
+ */
+ BufferedInputStream buftemp = new BufferedInputStream(
+ new ByteArrayInputStream(text.getBytes()), 4);
+ lnis = new LineNumberInputStream(buftemp);
+ lnis2 = new LineNumberInputStream(new ByteArrayInputStream(dosText
+ .getBytes()));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java b/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java
new file mode 100644
index 0000000..7e27698
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldLineNumberReaderTest.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.StringReader;
+import junit.framework.TestCase;
+
+public class OldLineNumberReaderTest extends TestCase {
+
+ String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n";
+
+ LineNumberReader lnr;
+
+ public void test_markI() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ String line;
+ lnr.skip(80);
+ lnr.mark(100);
+ line = lnr.readLine();
+ lnr.reset();
+ assertTrue("Test 1: Failed to return to marked position.",
+ line.equals(lnr.readLine()));
+
+ lnr.close();
+ try {
+ lnr.mark(42);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // The spec does not say the mark has to be invalidated
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read()
+ */
+ public void test_read() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+
+ int c = lnr.read();
+ assertEquals("Test 1: Read returned incorrect character;",
+ '0', c);
+ lnr.read();
+ assertEquals("Test 2: Read failed to increase the line number;",
+ 1, lnr.getLineNumber());
+
+ lnr.close();
+ try {
+ lnr.read();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.LineNumberReader#read(char[], int, int)
+ */
+ public void test_read$CII() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ lnr.read(c, 0, 4);
+ assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n"
+ .equals(new String(c, 0, 4)));
+ assertEquals("Test 2: Read failed to inc lineNumber",
+ 2, lnr.getLineNumber());
+
+ lnr.close();
+ try {
+ lnr.read(c, 0, 4);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read$CII_Exception() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[10];
+
+ try {
+ lnr.read(c, -1, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnr.read(c, 0, -1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ lnr.read(c, 10, 1);
+ fail("IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void test_readLine() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
+ String line = null;
+ lnr.readLine();
+ line = lnr.readLine();
+ assertEquals("Test 1: Returned incorrect string;", "1", line);
+ assertTrue("Test 2: Returned incorrect line number:" + lnr.getLineNumber(),
+ lnr.getLineNumber() == 2);
+
+ lnr.close();
+ try {
+ lnr.readLine();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_reset() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ assertEquals("Test 1: Returned incorrect line number;",
+ 0, lnr.getLineNumber());
+ String line = null;
+ lnr.mark(100);
+ lnr.readLine();
+ lnr.reset();
+ line = lnr.readLine();
+ assertEquals("Test 2: Failed to reset reader", "0", line);
+
+ lnr.mark(100);
+ lnr.close();
+ try {
+ lnr.reset();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ lnr = new LineNumberReader(new StringReader(text));
+ char[] c = new char[100];
+ long skipped = lnr.skip(80);
+ assertEquals("Test 1: Incorrect number of characters skipped;",
+ 80, skipped);
+ lnr.read(c, 0, 100);
+ assertTrue("Test 2: Failed to skip to correct position.",
+ text.substring(80, 180).equals(new String(c, 0, c.length)));
+
+ try {
+ lnr.skip(-1);
+ fail("Test 3: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ lnr.close();
+ try {
+ lnr.skip(1);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java
new file mode 100644
index 0000000..cb3e92f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectInputOutputStreamTest.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import tests.support.Support_OutputStream;
+
+public class OldObjectInputOutputStreamTest extends junit.framework.TestCase {
+
+ private ObjectOutputStream os;
+
+ private ObjectInputStream is;
+
+ private Support_OutputStream sos;
+
+ String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
+
+ public void test_read_writeBoolean() throws IOException {
+ os.writeBoolean(true);
+
+ os.close();
+ openObjectInputStream();
+ assertTrue("Test 1: Incorrect boolean written or read.",
+ is.readBoolean());
+
+ try {
+ is.readBoolean();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readBoolean();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeByte() throws IOException {
+ os.writeByte((byte) 127);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect byte written or read;",
+ (byte) 127, is.readByte());
+
+ try {
+ is.readByte();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readByte();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeChar() throws IOException {
+ os.writeChar('b');
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect char written or read;",
+ 'b', is.readChar());
+
+ try {
+ is.readChar();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readChar();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeDouble() throws IOException {
+ os.writeDouble(2345.76834720202);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect double written or read;",
+ 2345.76834720202, is.readDouble());
+
+ try {
+ is.readDouble();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readDouble();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeFloat() throws IOException {
+ os.writeFloat(29.08764f);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect float written or read;",
+ 29.08764f, is.readFloat());
+
+ try {
+ is.readFloat();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readFloat();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeInt() throws IOException {
+ os.writeInt(768347202);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect int written or read;",
+ 768347202, is.readInt());
+
+ try {
+ is.readInt();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readInt();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeLong() throws IOException {
+ os.writeLong(9875645283333L);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect long written or read;",
+ 9875645283333L, is.readLong());
+
+ try {
+ is.readLong();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readLong();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeShort() throws IOException {
+ os.writeShort(9875);
+
+ os.close();
+ openObjectInputStream();
+ assertEquals("Test 1: Incorrect short written or read;",
+ 9875, is.readShort());
+
+ try {
+ is.readShort();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readShort();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_read_writeUTF() throws IOException {
+ os.writeUTF(unihw);
+
+ os.close();
+ openObjectInputStream();
+ assertTrue("Test 1: Incorrect UTF-8 string written or read.",
+ is.readUTF().equals(unihw));
+
+ try {
+ is.readUTF();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ is.close();
+ try {
+ is.readUTF();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ private void openObjectInputStream() throws IOException {
+ is = new ObjectInputStream(
+ new ByteArrayInputStream(sos.toByteArray()));
+ }
+
+ protected void setUp() throws IOException {
+ sos = new Support_OutputStream(256);
+ os = new ObjectOutputStream(sos);
+ }
+
+ protected void tearDown() {
+ try {
+ os.close();
+ } catch (Exception e) {
+ }
+ try {
+ is.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java
new file mode 100644
index 0000000..696d130
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectInputStreamGetFieldTest.java
@@ -0,0 +1,259 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ObjectInputStream;
+import tests.support.Support_GetPutFields;
+import tests.support.Support_GetPutFieldsDefaulted;
+
+
+/**
+ * Tests the methods of {@code ObjectInputStream.GetField}. Three things make
+ * this class somewhat difficult to test:
+ * <ol>
+ * <li>It is a completely abstract class; none of the methods is implemented in
+ * {@code ObjectInputStream.GetField}.</li>
+ * <li>There is no public class that implements
+ * {@code ObjectInputStream.GetField}. The only way to get an implementation is
+ * by calling {@code ObjectInputStream.getFields()}.</li>
+ * <li>Invoking {@code ObjectOutputStream.getFields()} only works from within
+ * the private {@code readObject(ObjectInputStream)} method of a class that
+ * implements {@code Serializable}; an exception is thrown otherwise.</li>
+ * </ol>
+ * <p>
+ * Given these restrictions, an indirect approach is used to test
+ * {@code ObjectInputStream.GetField}: Three serializable helper classes in
+ * package {@code tests.support} ({@code Support_GetPutFields},
+ * {@code Support_GetPutFieldsDeprecated} and
+ * {@code Support_GetPutFieldsDefaulted}) implement
+ * {@code readObject(ObjectInputStream)} to read data from an input stream.
+ * This input stream in turn reads from one of the corresponding files
+ * ({@code testFields.ser}, {@code testFieldsDeprecated.ser} and
+ * {@code testFieldsDefaulted.ser}) that have been created with
+ * {@code tests.util.FieldTestFileGenerator} on a reference platform.
+ * </p>
+ * <p>
+ * The test method in this class expects to find the reference files as a
+ * resource stored at {@code tests/api/java/io}.
+ * </p>
+ */
+public class OldObjectInputStreamGetFieldTest extends junit.framework.TestCase {
+
+ private ObjectInputStream ois = null;
+
+ private final String FILENAME =
+ "/tests/api/java/io/testFields.ser";
+ private final String DEFAULTED_FILENAME =
+ "/tests/api/java/io/testFieldsDefaulted.ser";
+
+ public boolean booleanValue;
+ public byte byteValue;
+ public char charValue;
+ public int intValue;
+
+ public void test_get() throws Exception {
+ initOis(FILENAME);
+ Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
+ Support_GetPutFields newObject = new Support_GetPutFields();
+ newObject.initTestValues();
+
+ assertTrue("Test 1: The object read from the reference file does " +
+ "not match a locally created instance of the same class.",
+ object.equals(newObject));
+
+ initOis(DEFAULTED_FILENAME);
+ Support_GetPutFieldsDefaulted defaulted =
+ (Support_GetPutFieldsDefaulted) ois.readObject();
+ Support_GetPutFieldsDefaulted newDefaulted =
+ new Support_GetPutFieldsDefaulted();
+ newDefaulted.initTestValues();
+
+ assertTrue("Test 2: The object read from the reference file does " +
+ "not match a locally created instance of the same class.",
+ defaulted.equals(newDefaulted));
+
+ // Executing the same procedure against the file created with the
+ // deprecated ObjectOutputStream.PutFields.write(ObjectOutput) method
+ // is not possible since there is no corresponding read(ObjectInput)
+ // method. When trying to do it as in tests 1 and 2, a
+ // NullPointerException is thrown.
+ }
+
+ public void test_defaultedLjava_lang_String() throws Exception {
+ initOis(FILENAME);
+ Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
+ ObjectInputStream.GetField fields = object.getField;
+
+ try {
+ fields.defaulted("noField");
+ fail("IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {}
+
+ assertFalse("The field longValue should not be defaulted.",
+ fields.defaulted("longValue"));
+
+ // Now the same with defaulted fields.
+ initOis(DEFAULTED_FILENAME);
+ Support_GetPutFieldsDefaulted defaultedObject =
+ (Support_GetPutFieldsDefaulted) ois.readObject();
+ fields = defaultedObject.getField;
+
+ assertTrue("The field longValue should be defaulted.",
+ fields.defaulted("longValue"));
+
+ }
+
+ public void test_getException() throws Exception {
+ initOis(FILENAME);
+ Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
+ ObjectInputStream.GetField fields = object.getField;
+
+ // Methods called with invalid field name.
+ try {
+ fields.get("noValue", false);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, boolean).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", (byte) 0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, byte).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", (char) 0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, char).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", 0.0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, double).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", 0.0f);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, float).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", (long) 0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, long).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", 0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, int).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", new Object());
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, Object).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("noValue", (short) 0);
+ fail("IllegalArgumentException expected for not existing name " +
+ "argument in get(String, short).");
+ } catch (IllegalArgumentException e) {}
+
+ // Methods called with correct field name but non-matching type.
+ try {
+ fields.get("byteValue", false);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, boolean).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("booleanValue", (byte) 0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, byte).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("intValue", (char) 0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, char).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("floatValue", 0.0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, double).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("doubleValue", 0.0f);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, float).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("intValue", (long) 0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, long).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("shortValue", 0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, int).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("booleanValue", new Object());
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, Object).");
+ } catch (IllegalArgumentException e) {}
+
+ try {
+ fields.get("longValue", (short) 0);
+ fail("IllegalArgumentException expected for non-matching name " +
+ "and type arguments in get(String, short).");
+ } catch (IllegalArgumentException e) {}
+ }
+
+ public void test_getObjectStreamClass() throws Exception {
+ initOis(FILENAME);
+ Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
+ assertNotNull("Return value of getObjectStreamClass() should not be null.",
+ object.getField.getObjectStreamClass());
+ }
+
+ private void initOis(String fileName) throws Exception {
+ if (ois != null) {
+ ois.close();
+ }
+ ois = new ObjectInputStream(
+ getClass().getResourceAsStream(fileName));
+ }
+
+ protected void tearDown() throws Exception {
+ if (ois != null) {
+ ois.close();
+ }
+ super.tearDown();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java
new file mode 100644
index 0000000..59008ab
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamPutFieldTest.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import tests.support.Support_GetPutFields;
+import tests.support.Support_GetPutFieldsDeprecated;
+
+/**
+ * Tests the methods of {@code ObjectOutputStream.PutField}. Three things make
+ * this class somewhat difficult to test:
+ * <ol>
+ * <li>It is a completely abstract class; none of the methods is implemented in
+ * {@code ObjectOutputStream.PutField}.</li>
+ * <li>There is no public class that implements
+ * {@code ObjectOutputStream.PutField}. The only way to get an implementation
+ * is by calling {@code ObjectOutputStream.putFields()}.</li>
+ * <li>Invoking the methods of {@code ObjectOutputStream.PutField} only works
+ * from within the private {@code writeObject(ObjectOutputStream)} method of a
+ * class that implements {@code Serializable}; an exception is thrown
+ * otherwise.</li>
+ * </ol>
+ * <p>
+ * Given these restrictions, an indirect approach is used to test
+ * {@code ObjectOutputStream.PutField}: The serializable helper class
+ * {@code tests.support.Support_GetPutFields} implements
+ * {@code writeObject(ObjectOutputStream)} and uses all {@code putX} methods in
+ * {@code PutField} to write data to the output stream. A second helper class,
+ * {@code tests.support.Support_GetPutFieldsDeprecated}, also uses the
+ * deprecated {@code ObjectOutputStream.PutField.write(ObjectOutput)}.
+ * {@code tests.util.FieldTestFileGenerator} can then be used on a reference
+ * platform to write these two classes to the file {@code testFields.ser} and
+ * {@code testFieldsDeprecated.ser} respectively.
+ * </p>
+ * <p>
+ * The test methods in this class expect to find {@code testFields.ser} and
+ * {@code testFieldsDeprecated.ser} as a resource stored at
+ * {@code tests/api/java/io}. The contents of these files is compared to what
+ * is written when {@code Support_GetPutFields.writeObject(ObjectOutputStream)}
+ * and {@code Support_GetPutFieldsDeprecated.writeObject(ObjectOutputStream)} is
+ * called by the test methods.
+ * </p>
+ */
+public class OldObjectOutputStreamPutFieldTest extends TestCase {
+
+ private final String FILENAME =
+ "/tests/api/java/io/testFields.ser";
+ private final String DEPRECATED_FILENAME =
+ "/tests/api/java/io/testFieldsDeprecated.ser";
+
+ public void test_put() throws Exception {
+ Support_GetPutFields toSerialize = new Support_GetPutFields();
+ byte[] content;
+ byte[] refContent;
+ ObjectOutputStream oos = null;
+ ByteArrayOutputStream baos;
+
+ toSerialize.initTestValues();
+
+ try {
+ refContent = getRefContent(FILENAME);
+
+ baos = new ByteArrayOutputStream(refContent.length);
+ oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(toSerialize);
+ content = baos.toByteArray();
+ assertTrue("Serialization is not equal to reference platform.",
+ Arrays.equals(content, refContent));
+ }
+ finally {
+ if (oos != null) oos.close();
+ }
+ }
+
+ public void test_writeLjava_io_ObjectOutputStream() throws Exception {
+ Support_GetPutFieldsDeprecated toSerialize = new Support_GetPutFieldsDeprecated();
+ byte[] content;
+ byte[] refContent;
+ ObjectOutputStream oos = null;
+ ByteArrayOutputStream baos;
+
+ toSerialize.initTestValues();
+
+ try {
+ refContent = getRefContent(DEPRECATED_FILENAME);
+
+ baos = new ByteArrayOutputStream(refContent.length);
+ oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(toSerialize);
+ content = baos.toByteArray();
+ assertTrue("Serialization is not equal to reference platform.",
+ Arrays.equals(content, refContent));
+ }
+ finally {
+ if (oos != null) oos.close();
+ }
+ }
+
+ private byte[] getRefContent(String path) throws Exception {
+ int bytesRead;
+ byte[] refContent;
+ byte[] streamContent = new byte[2000];
+ InputStream refStream = null;
+
+ try {
+ refStream = getClass().getResourceAsStream(path);
+ bytesRead = refStream.read(streamContent);
+ assertTrue("Test case implementation error: The byte array to " +
+ "store the reference file is too small.",
+ (refStream.read() == -1));
+ refContent = new byte[bytesRead];
+ System.arraycopy(streamContent, 0, refContent, 0, bytesRead);
+ }
+ finally {
+ if (refStream != null) refStream.close();
+ }
+ return refContent;
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java
new file mode 100644
index 0000000..cf01d9d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectOutputStreamTest.java
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.NotActiveException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.OutputStream;
+import java.io.Serializable;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleOutputStream;
+import tests.support.Support_OutputStream;
+
+public class OldObjectOutputStreamTest extends TestCase implements Serializable {
+
+ static final long serialVersionUID = 1L;
+
+ java.io.File f;
+
+ public class SerializableTestHelper implements Serializable {
+ public String aField1;
+
+ public String aField2;
+
+ SerializableTestHelper(String s, String t) {
+ aField1 = s;
+ aField2 = t;
+ }
+
+ private void readObject(ObjectInputStream ois) throws IOException {
+ // note aField2 is not read
+ try {
+ ObjectInputStream.GetField fields = ois.readFields();
+ aField1 = (String) fields.get("aField1", "Zap");
+ } catch (Exception e) {
+ }
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ // note aField2 is not written
+ ObjectOutputStream.PutField fields = oos.putFields();
+ fields.put("aField1", aField1);
+ oos.writeFields();
+ }
+
+ public String getText1() {
+ return aField1;
+ }
+
+ public String getText2() {
+ return aField2;
+ }
+ }
+
+ private static class BasicObjectOutputStream extends ObjectOutputStream {
+ public boolean writeStreamHeaderCalled;
+
+ public BasicObjectOutputStream() throws IOException, SecurityException {
+ super();
+ writeStreamHeaderCalled = false;
+ }
+
+ public BasicObjectOutputStream(OutputStream output) throws IOException {
+ super(output);
+ }
+
+ public void drain() throws IOException {
+ super.drain();
+ }
+
+ public boolean enableReplaceObject(boolean enable)
+ throws SecurityException {
+ return super.enableReplaceObject(enable);
+ }
+
+ public void writeObjectOverride(Object object) throws IOException {
+ super.writeObjectOverride(object);
+ }
+
+ public void writeStreamHeader() throws IOException {
+ super.writeStreamHeader();
+ writeStreamHeaderCalled = true;
+ }
+}
+
+ private static class NoFlushTestOutputStream extends ByteArrayOutputStream {
+ public boolean flushCalled;
+
+ public NoFlushTestOutputStream() {
+ super();
+ flushCalled = false;
+ }
+
+ public void flush() throws IOException {
+ super.flush();
+ flushCalled = true;
+ }
+ }
+
+ protected static final String MODE_XLOAD = "xload";
+
+ protected static final String MODE_XDUMP = "xdump";
+
+ static final String FOO = "foo";
+
+ static final String MSG_WITE_FAILED = "Failed to write: ";
+
+ private static final boolean DEBUG = false;
+
+ protected static boolean xload = false;
+
+ protected static boolean xdump = false;
+
+ protected static String xFileName = null;
+
+ protected ObjectInputStream ois;
+
+ protected ObjectOutputStream oos;
+
+ protected ObjectOutputStream oos_ioe;
+
+ protected Support_OutputStream sos;
+
+ protected ByteArrayOutputStream bao;
+
+ static final int INIT_INT_VALUE = 7;
+
+ static final String INIT_STR_VALUE = "a string that is blortz";
+
+ /**
+ * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
+ */
+ public void test_ConstructorLjava_io_OutputStream() throws IOException {
+ oos.close();
+ oos = new ObjectOutputStream(new ByteArrayOutputStream());
+ oos.close();
+
+ try {
+ oos = new ObjectOutputStream(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ Support_ASimpleOutputStream sos = new Support_ASimpleOutputStream(true);
+ try {
+ oos = new ObjectOutputStream(sos);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws IOException {
+ int outputSize = bao.size();
+ // Writing of a primitive type should be buffered.
+ oos.writeInt(42);
+ assertTrue("Test 1: Primitive data unexpectedly written to the target stream.",
+ bao.size() == outputSize);
+ // Closing should write the buffered data to the target stream.
+ oos.close();
+ assertTrue("Test 2: Primitive data has not been written to the the target stream.",
+ bao.size() > outputSize);
+
+ try {
+ oos_ioe.close();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_drain() throws IOException {
+ NoFlushTestOutputStream target = new NoFlushTestOutputStream();
+ BasicObjectOutputStream boos = new BasicObjectOutputStream(target);
+ int initialSize = target.size();
+ boolean written = false;
+
+ boos.writeBytes("Lorem ipsum");
+ // If there is no buffer then the bytes have already been written.
+ written = (target.size() > initialSize);
+
+ boos.drain();
+ assertTrue("Content has not been written to the target.",
+ written || (target.size() > initialSize));
+ assertFalse("flush() has been called on the target.",
+ target.flushCalled);
+ }
+
+ public void test_enableReplaceObjectB() throws IOException {
+ // Start testing without a SecurityManager.
+ BasicObjectOutputStream boos = new BasicObjectOutputStream();
+ assertFalse("Test 1: Object resolving must be disabled by default.",
+ boos.enableReplaceObject(true));
+
+ assertTrue("Test 2: enableReplaceObject did not return the previous value.",
+ boos.enableReplaceObject(false));
+ }
+
+ public void test_flush() throws Exception {
+ // Test for method void java.io.ObjectOutputStream.flush()
+ int size = bao.size();
+ oos.writeByte(127);
+ assertTrue("Test 1: Data already flushed.", bao.size() == size);
+ oos.flush();
+ assertTrue("Test 2: Failed to flush data.", bao.size() > size);
+
+ try {
+ oos_ioe.flush();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_putFields() throws Exception {
+ /*
+ * "SerializableTestHelper" is an object created for these tests with
+ * two fields (Strings) and simple implementations of readObject and
+ * writeObject which simply read and write the first field but not the
+ * second one.
+ */
+ SerializableTestHelper sth;
+
+ try {
+ oos.putFields();
+ fail("Test 1: NotActiveException expected.");
+ } catch (NotActiveException e) {
+ // Expected.
+ }
+
+ oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
+ oos.flush();
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+ sth = (SerializableTestHelper) (ois.readObject());
+ assertEquals("Test 2: readFields or writeFields failed; first field not set.",
+ "Gabba", sth.getText1());
+ assertNull("Test 3: readFields or writeFields failed; second field should not have been set.",
+ sth.getText2());
+ }
+
+ public void test_reset() throws Exception {
+ String o = "HelloWorld";
+ sos = new Support_OutputStream(200);
+ oos.close();
+ oos = new ObjectOutputStream(sos);
+ oos.writeObject(o);
+ oos.writeObject(o);
+ oos.reset();
+ oos.writeObject(o);
+
+ sos.setThrowsException(true);
+ try {
+ oos.reset();
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ sos.setThrowsException(false);
+
+ ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
+ assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
+ assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
+ assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
+ ois.close();
+ }
+
+ public void test_write$BII() throws Exception {
+ byte[] buf = new byte[10];
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
+ try {
+ ois.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ ois.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ ois.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ ois.close();
+
+ }
+
+ public void test_writeObjectOverrideLjava_lang_Object() throws IOException {
+ BasicObjectOutputStream boos =
+ new BasicObjectOutputStream(new ByteArrayOutputStream());
+
+ try {
+ boos.writeObjectOverride(new Object());
+ fail("IOException expected.");
+ }
+ catch (IOException e) {
+ }
+ finally {
+ boos.close();
+ }
+ }
+
+ public void test_writeStreamHeader() throws IOException {
+ BasicObjectOutputStream boos;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ short s;
+ byte[] buffer;
+
+ // Test 1: Make sure that writeStreamHeader() has been called.
+ boos = new BasicObjectOutputStream(baos);
+ try {
+ assertTrue("Test 1: writeStreamHeader() has not been called.",
+ boos.writeStreamHeaderCalled);
+
+ // Test 2: Check that at least four bytes have been written.
+ buffer = baos.toByteArray();
+ assertTrue("Test 2: At least four bytes should have been written",
+ buffer.length >= 4);
+
+ // Test 3: Check the magic number.
+ s = buffer[0];
+ s <<= 8;
+ s += ((short) buffer[1] & 0x00ff);
+ assertEquals("Test 3: Invalid magic number written.",
+ java.io.ObjectStreamConstants.STREAM_MAGIC, s);
+
+ // Test 4: Check the stream version number.
+ s = buffer[2];
+ s <<= 8;
+ s += ((short) buffer[3] & 0x00ff);
+ assertEquals("Invalid stream version number written.",
+ java.io.ObjectStreamConstants.STREAM_VERSION, s);
+ }
+ finally {
+ boos.close();
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
+ sos.setThrowsException(true);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (oos != null) {
+ try {
+ oos.close();
+ } catch (Exception e) {}
+ }
+ if (oos_ioe != null) {
+ try {
+ oos_ioe.close();
+ } catch (Exception e) {}
+ }
+ if (f != null && f.exists()) {
+ if (!f.delete()) {
+ fail("Error cleaning up files during teardown");
+ }
+ }
+ }
+
+ protected Object reload() throws IOException, ClassNotFoundException {
+
+ // Choose the load stream
+ if (xload || xdump) {
+ // Load from pre-existing file
+ ois = new ObjectInputStream(new FileInputStream(xFileName + "-"
+ + getName() + ".ser"));
+ } else {
+ // Just load from memory, we dumped to memory
+ ois = new ObjectInputStream(new ByteArrayInputStream(bao
+ .toByteArray()));
+ }
+
+ try {
+ return ois.readObject();
+ } finally {
+ ois.close();
+ }
+ }
+
+ protected void dump(Object o) throws IOException, ClassNotFoundException {
+
+ // Choose the dump stream
+ if (xdump) {
+ oos = new ObjectOutputStream(new FileOutputStream(
+ f = new java.io.File(xFileName + "-" + getName() + ".ser")));
+ } else {
+ oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
+ }
+
+ // Dump the object
+ try {
+ oos.writeObject(o);
+ } finally {
+ oos.close();
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java b/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java
new file mode 100644
index 0000000..ee09221
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldObjectStreamFieldTest.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ObjectStreamClass;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+
+public class OldObjectStreamFieldTest extends junit.framework.TestCase {
+
+ static class DummyClass implements Serializable {
+ private static final long serialVersionUID = 999999999999998L;
+
+ boolean bField = true;
+ char cField = 'c';
+ double dField = 424242.4242;
+ float fField = 24.12F;
+ int iField = 1965;
+ long lField = 9999999L;
+ short sField = 42;
+
+ long bam = 999L;
+
+ int ham = 9999;
+
+ int sam = 8888;
+
+ Object hola = new Object();
+
+ public static long getUID() {
+ return serialVersionUID;
+ }
+ }
+
+ class MyObjectStreamField extends ObjectStreamField {
+ public MyObjectStreamField(String name, Class<?> cl) {
+ super(name, cl);
+ }
+
+ public void setOffset(int newValue) {
+ super.setOffset(newValue);
+ }
+ }
+
+ ObjectStreamClass osc;
+
+ ObjectStreamField hamField;
+
+ ObjectStreamField samField;
+
+ ObjectStreamField bamField;
+
+ ObjectStreamField holaField;
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
+ ObjectStreamField osf = new ObjectStreamField("aField", int.class);
+ assertTrue("Test 1: Name member not set correctly.",
+ osf.getName().equals("aField"));
+ assertTrue("Test 2: Type member not set correctly.",
+ osf.getType().equals(int.class));
+
+ // Repeat the tests with a different object to make sure
+ // that we have not tested against default values.
+ osf = new ObjectStreamField("anotherField", String.class);
+ assertTrue("Test 3: Name member not set correctly.",
+ osf.getName().equals("anotherField"));
+ assertTrue("Test 4: Type member not set correctly.",
+ osf.getType().equals(String.class));
+
+ // Invalid argument tests.
+ try {
+ osf = new ObjectStreamField(null, boolean.class);
+ fail("Test 5: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ try {
+ osf = new ObjectStreamField("thisField", null);
+ fail("Test 6: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_ClassB() {
+ ObjectStreamField osf = new ObjectStreamField("aField", int.class, false);
+ assertTrue("Test 1: Name member not set correctly.",
+ osf.getName().equals("aField"));
+ assertTrue("Test 2: Type member not set correctly.",
+ osf.getType().equals(int.class));
+ assertFalse("Test 3: Unshared member not set correctly.",
+ osf.isUnshared());
+
+ // Repeat the tests with a different object to make sure
+ // that we have not tested against default values.
+ osf = new ObjectStreamField("anotherField", String.class, true);
+ assertTrue("Test 4: Name member not set correctly.",
+ osf.getName().equals("anotherField"));
+ assertTrue("Test 5: Type member not set correctly.",
+ osf.getType().equals(String.class));
+ assertTrue("Test 6: Unshared member not set correctly.",
+ osf.isUnshared());
+
+ // Invalid argument tests.
+ try {
+ osf = new ObjectStreamField(null, boolean.class);
+ fail("Test 7: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ try {
+ osf = new ObjectStreamField("thisField", null);
+ fail("Test 8: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+
+ public void test_getOffset() {
+ ObjectStreamField[] osfArray;
+ osfArray = osc.getFields();
+ int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};
+
+ assertTrue("getOffset() did not return reasonable values.", osfArray[0]
+ .getOffset() != osfArray[1].getOffset());
+
+ for (int i = 0; i < expectedOffsets.length; i++) {
+ assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
+ expectedOffsets[i], osfArray[i].getOffset());
+
+ }
+ }
+
+ public void test_setOffsetI() {
+ MyObjectStreamField f = new MyObjectStreamField("aField", int.class);
+ f.setOffset(42);
+ assertEquals("Test 1: Unexpected offset value.", 42, f.getOffset());
+ f.setOffset(2008);
+ assertEquals("Test 2: Unexpected offset value.", 2008, f.getOffset());
+ }
+
+ public void test_isPrimitive() {
+ // Test for method int java.io.ObjectStreamField.getOffset()
+ ObjectStreamField[] osfArray;
+ osfArray = osc.getFields();
+
+ for (int i = 0; i < (osfArray.length - 1); i++) {
+ assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
+ osfArray[i].isPrimitive());
+ }
+ assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
+ osfArray.length - 1),
+ osfArray[(osfArray.length - 1)].isPrimitive());
+ }
+
+ protected void setUp() {
+ osc = ObjectStreamClass.lookup(DummyClass.class);
+ bamField = osc.getField("bam");
+ samField = osc.getField("sam");
+ hamField = osc.getField("ham");
+ holaField = osc.getField("hola");
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldOutputStreamTest.java
new file mode 100644
index 0000000..585612b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldOutputStreamTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+public class OldOutputStreamTest extends junit.framework.TestCase {
+
+ class BasicOutputStream extends OutputStream {
+
+ private static final int BUFFER_SIZE = 20;
+ private byte[] buffer;
+ private int position;
+
+ public BasicOutputStream() {
+ buffer = new byte[BUFFER_SIZE];
+ position = 0;
+ }
+
+ public void write(int oneByte) throws IOException {
+ if (position < BUFFER_SIZE) {
+ buffer[position] = (byte) (oneByte & 255);
+ position++;
+ } else {
+ throw new IOException("Internal buffer overflow.");
+ }
+ }
+
+ public byte[] getBuffer() {
+ return buffer;
+ }
+ }
+
+ private final byte[] shortByteArray = "Lorem ipsum...".getBytes();
+ private final byte[] longByteArray = "Lorem ipsum dolor sit amet...".getBytes();
+
+ public void test_write$B() {
+ BasicOutputStream bos = new BasicOutputStream();
+ boolean expected;
+ byte[] buffer;
+
+ try {
+ bos.write(shortByteArray);
+ } catch (IOException e) {
+ fail("Test 1: Unexpected IOException encountered.");
+ }
+
+ expected = true;
+ buffer = bos.getBuffer();
+ for (int i = 0; i < (shortByteArray.length) && expected; i++) {
+ expected = (shortByteArray[i] == buffer[i]);
+ }
+ assertTrue("Test 1: Test byte array has not been written correctly.",
+ expected);
+
+ try {
+ bos.write(longByteArray);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {}
+ }
+
+ public void test_write$BII() {
+ BasicOutputStream bos = new BasicOutputStream();
+ boolean expected;
+ byte[] buffer;
+
+ try {
+ bos.write(shortByteArray, 6, 5);
+ } catch (IOException e) {
+ fail("Test 1: Unexpected IOException encountered.");
+ }
+
+ expected = true;
+ buffer = bos.getBuffer();
+ for (int i = 6, j = 0; j < 5 && expected; i++, j++) {
+ expected = (shortByteArray[i] == buffer[j]);
+ }
+ assertTrue("Test 1: Test byte array has not been written correctly.",
+ expected);
+
+ try {
+ bos.write(longByteArray, 5, 20);
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {}
+
+ try {
+ bos.write(longByteArray, -1, 10);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException encountered.");
+ }
+
+ try {
+ bos.write(longByteArray, 10, -1);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ } catch (IOException e) {
+ fail("Test 4: Unexpected IOException encountered.");
+ }
+
+ try {
+ bos.write(longByteArray, 20, 10);
+ fail("Test 5: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ } catch (IOException e) {
+ fail("Test 5: Unexpected IOException encountered.");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java b/luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java
new file mode 100644
index 0000000..dc51553
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldOutputStreamWriterTest.java
@@ -0,0 +1,589 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetEncoder;
+import junit.framework.TestCase;
+import tests.support.Support_OutputStream;
+
+public class OldOutputStreamWriterTest extends TestCase {
+
+ OutputStreamWriter osw;
+ InputStreamReader isr;
+
+ private Support_OutputStream fos;
+
+ public String testString = "This is a test message with Unicode characters. \u4e2d\u56fd is China's name in Chinese";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ fos = new Support_OutputStream(500);
+ osw = new OutputStreamWriter(fos, "UTF-8");
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ if (isr != null) isr.close();
+ osw.close();
+ } catch (Exception e) {
+ }
+
+ super.tearDown();
+ }
+
+ public void test_ConstructorLjava_io_OutputStream() throws IOException {
+ OutputStreamWriter writer = null;
+
+ try {
+ writer = new OutputStreamWriter(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ writer = new OutputStreamWriter(new Support_OutputStream());
+ } catch (Exception e) {
+ fail("Test 2: Unexpected exception: " + e.getMessage());
+ }
+
+ // Test that the default encoding has been used.
+ assertEquals("Test 3: Incorrect default encoding used.",
+ Charset.defaultCharset(),
+ Charset.forName(writer.getEncoding()));
+
+ if (writer != null) writer.close();
+ }
+
+ public void test_ConstructorLjava_io_OutputStreamLjava_lang_String()
+ throws UnsupportedEncodingException {
+
+ try {
+ osw = new OutputStreamWriter(null, "utf-8");
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ osw = new OutputStreamWriter(fos, (String) null);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ osw = new OutputStreamWriter(fos, "");
+ fail("Test 3: UnsupportedEncodingException expected.");
+ } catch (UnsupportedEncodingException e) {
+ // Expected
+ }
+
+ try {
+ osw = new OutputStreamWriter(fos, "Bogus");
+ fail("Test 4: UnsupportedEncodingException expected.");
+ } catch (UnsupportedEncodingException e) {
+ // Expected
+ }
+
+ try {
+ osw = new OutputStreamWriter(fos, "8859_1");
+ } catch (UnsupportedEncodingException e) {
+ fail("Test 5: Unexpected UnsupportedEncodingException.");
+ }
+
+ assertEquals("Test 6: Encoding not set correctly. ",
+ Charset.forName("8859_1"),
+ Charset.forName(osw.getEncoding()));
+ }
+
+ public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_Charset()
+ throws IOException {
+ OutputStreamWriter writer;
+ Support_OutputStream out = new Support_OutputStream();
+ Charset cs = Charset.forName("ascii");
+
+ try {
+ writer = new OutputStreamWriter(null, cs);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ writer = new OutputStreamWriter(out, (Charset) null);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ writer = new OutputStreamWriter(out, cs);
+ assertEquals("Test 3: Encoding not set correctly. ",
+ cs, Charset.forName(writer.getEncoding()));
+ writer.close();
+ }
+
+ public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_CharsetEncoder()
+ throws IOException {
+ OutputStreamWriter writer;
+ Support_OutputStream out = new Support_OutputStream();
+ Charset cs = Charset.forName("ascii");
+ CharsetEncoder enc = cs.newEncoder();
+
+ try {
+ writer = new OutputStreamWriter(null, enc);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ writer = new OutputStreamWriter(out, (CharsetEncoder) null);
+ fail("Test 2: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ writer = new OutputStreamWriter(out, cs);
+ assertEquals("Test 3: CharacterEncoder not set correctly. ",
+ cs, Charset.forName(writer.getEncoding()));
+ writer.close();
+ }
+
+ public void test_close() {
+
+ fos.setThrowsException(true);
+ try {
+ osw.close();
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+/* Test 2 does not work and has therefore been disabled (see Ticket #87).
+ // Test 2: Write should not fail since the closing
+ // in test 1 has not been successful.
+ try {
+ osw.write("Lorem ipsum...");
+ } catch (IOException e) {
+ fail("Test 2: Unexpected IOException.");
+ }
+
+ // Test 3: Close should succeed.
+ fos.setThrowsException(false);
+ try {
+ osw.close();
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException.");
+ }
+*/
+
+ ByteArrayOutputStream bout = new ByteArrayOutputStream();
+ try {
+ OutputStreamWriter writer = new OutputStreamWriter(bout,
+ "ISO2022JP");
+ writer.write(new char[] { 'a' });
+ writer.close();
+ // The default is ASCII, there should not be any mode changes.
+ String converted = new String(bout.toByteArray(), "ISO8859_1");
+ assertTrue("Test 4: Invalid conversion: " + converted,
+ converted.equals("a"));
+
+ bout.reset();
+ writer = new OutputStreamWriter(bout, "ISO2022JP");
+ writer.write(new char[] { '\u3048' });
+ writer.flush();
+ // The byte sequence should not switch to ASCII mode until the
+ // stream is closed.
+ converted = new String(bout.toByteArray(), "ISO8859_1");
+ assertTrue("Test 5: Invalid conversion: " + converted,
+ converted.equals("\u001b$B$("));
+ writer.close();
+ converted = new String(bout.toByteArray(), "ISO8859_1");
+ assertTrue("Test 6: Invalid conversion: " + converted,
+ converted.equals("\u001b$B$(\u001b(B"));
+
+ bout.reset();
+ writer = new OutputStreamWriter(bout, "ISO2022JP");
+ writer.write(new char[] { '\u3048' });
+ writer.write(new char[] { '\u3048' });
+ writer.close();
+ // There should not be a mode switch between writes.
+ assertEquals("Test 7: Invalid conversion. ",
+ "\u001b$B$($(\u001b(B",
+ new String(bout.toByteArray(), "ISO8859_1"));
+ } catch (UnsupportedEncodingException e) {
+ // Can't test missing converter.
+ System.out.println(e);
+ } catch (IOException e) {
+ fail("Unexpected: " + e);
+ }
+ }
+
+ public void test_flush() {
+ // Test for method void java.io.OutputStreamWriter.flush()
+ try {
+ char[] buf = new char[testString.length()];
+ osw.write(testString, 0, testString.length());
+ osw.flush();
+ openInputStream();
+ isr.read(buf, 0, buf.length);
+ assertTrue("Test 1: Characters have not been flushed.",
+ new String(buf, 0, buf.length).equals(testString));
+ } catch (Exception e) {
+ fail("Test 1: Unexpected exception: " + e.getMessage());
+ }
+
+ fos.setThrowsException(true);
+ try {
+ osw.flush();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ fos.setThrowsException(false);
+ }
+
+ public void test_write_US_ASCII() throws Exception {
+ testEncodeCharset("US-ASCII", 128);
+ }
+
+ public void test_write_ISO_8859_1() throws Exception {
+ testEncodeCharset("ISO-8859-1", 256);
+ }
+
+ public void test_write_UTF_16BE() throws Exception {
+ testEncodeCharset("UTF-16BE", 0xd800);
+ }
+
+ public void test_write_UTF_16LE() throws Exception {
+ testEncodeCharset("UTF-16LE", 0xd800);
+ }
+
+ public void test_write_UTF_16() throws Exception {
+ testEncodeCharset("UTF-16", 0xd800);
+ }
+
+ public void test_write_UTF_8() throws Exception {
+ testEncodeCharset("UTF-8", 0xd800);
+ }
+
+ private void testEncodeCharset(String charset, int maxChar) throws Exception {
+ char[] chars = new char[maxChar];
+ for (int i = 0; i < maxChar; i++) {
+ chars[i] = (char) i;
+ }
+
+ // to byte array
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ OutputStreamWriter charsOut = new OutputStreamWriter(bytesOut, charset);
+ charsOut.write(chars);
+ charsOut.flush();
+
+ // decode from byte array, one character at a time
+ ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesOut.toByteArray());
+ InputStreamReader charsIn = new InputStreamReader(bytesIn, charset);
+ for (int i = 0; i < maxChar; i++) {
+ assertEquals(i, charsIn.read());
+ }
+ assertEquals(-1, charsIn.read());
+
+ // decode from byte array, using byte buffers
+ bytesIn = new ByteArrayInputStream(bytesOut.toByteArray());
+ charsIn = new InputStreamReader(bytesIn, charset);
+ char[] decoded = new char[maxChar];
+ for (int r = 0; r < maxChar; ) {
+ r += charsIn.read(decoded, r, maxChar - r);
+ }
+ assertEquals(-1, charsIn.read());
+ for (int i = 0; i < maxChar; i++) {
+ assertEquals(i, decoded[i]);
+ }
+ }
+
+ public void test_getEncoding() throws IOException {
+ OutputStreamWriter writer;
+ writer = new OutputStreamWriter(new Support_OutputStream(), "utf-8");
+ assertEquals("Test 1: Incorrect encoding returned.",
+ Charset.forName("utf-8"),
+ Charset.forName(writer.getEncoding()));
+
+ writer.close();
+ assertNull("Test 2: getEncoding() did not return null for a closed writer.",
+ writer.getEncoding());
+ }
+
+ public void test_write$CII() throws IOException {
+ char[] chars = testString.toCharArray();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Support_OutputStream out = new Support_OutputStream(500);
+ OutputStreamWriter writer;
+
+ writer = new OutputStreamWriter(out, "utf-8");
+
+ try {
+ writer.write(chars, -1, 1);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(chars, 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(new char[0], 0, 1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write((char[]) null, 0, 1);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(chars, 1, chars.length);
+ fail("Test 5a: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ writer.write(chars, 0, chars.length + 1);
+ fail("Test 5b: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ writer.write(chars, chars.length, 1);
+ fail("Test 5c: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ writer.write(chars, chars.length + 1, 0);
+ fail("Test 5d: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ out.setThrowsException(true);
+ try {
+ for (int i = 0; i < 200; i++) {
+ writer.write(chars, 0, chars.length);
+ }
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ out.setThrowsException(false);
+
+ writer.close();
+ writer = new OutputStreamWriter(baos, "utf-8");
+ writer.write(chars, 1, 2);
+ writer.flush();
+ assertEquals("Test 7: write(char[], int, int) has not produced the " +
+ "expected content in the output stream.",
+ "hi", baos.toString("utf-8"));
+
+ writer.write(chars, 0, chars.length);
+ writer.flush();
+ assertEquals("Test 8: write(char[], int, int) has not produced the " +
+ "expected content in the output stream.",
+ "hi" + testString, baos.toString("utf-8"));
+
+ writer.close();
+ try {
+ writer.write((char[]) null, -1, -1);
+ fail("Test 9: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ Support_OutputStream out = new Support_OutputStream(500);
+ OutputStreamWriter writer;
+
+ out.setThrowsException(true);
+ writer = new OutputStreamWriter(out, "utf-8");
+ try {
+ // Since there is an internal buffer in the encoder, more than
+ // one character needs to be written.
+ for (int i = 0; i < 200; i++) {
+ for (int j = 0; j < testString.length(); j++) {
+ writer.write(testString.charAt(j));
+ }
+ }
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ out.setThrowsException(false);
+ writer.close();
+
+ writer = new OutputStreamWriter(out, "utf-8");
+ writer.write(1);
+ writer.flush();
+ String str = new String(out.toByteArray(), "utf-8");
+ assertEquals("Test 2: ", "\u0001", str);
+
+ writer.write(2);
+ writer.flush();
+ str = new String(out.toByteArray(), "utf-8");
+ assertEquals("Test 3: ", "\u0001\u0002", str);
+
+ writer.write(-1);
+ writer.flush();
+ str = new String(out.toByteArray(), "utf-8");
+ assertEquals("Test 4: ", "\u0001\u0002\uffff", str);
+
+ writer.write(0xfedcb);
+ writer.flush();
+ str = new String(out.toByteArray(), "utf-8");
+ assertEquals("Test 5: ", "\u0001\u0002\uffff\uedcb", str);
+
+ writer.close();
+ try {
+ writer.write(1);
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ }
+
+ public void test_writeLjava_lang_StringII() throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Support_OutputStream out = new Support_OutputStream(500);
+ OutputStreamWriter writer;
+
+ writer = new OutputStreamWriter(out, "utf-8");
+
+ try {
+ writer.write("Lorem", -1, 0);
+ fail("Test 1: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write("Lorem", 0, -1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write("", 0, 1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(testString, 1, testString.length());
+ fail("Test 4a: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(testString, 0, testString.length() + 1);
+ fail("Test 4b: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(testString, testString.length(), 1);
+ fail("Test 4c: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write(testString, testString.length() + 1, 0);
+ fail("Test 4d: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ writer.write((String) null, 0, 1);
+ fail("Test 5: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ out.setThrowsException(true);
+ try {
+ for (int i = 0; i < 200; i++) {
+ writer.write(testString, 0, testString.length());
+ }
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ out.setThrowsException(false);
+
+ writer.close();
+ writer = new OutputStreamWriter(baos, "utf-8");
+
+ writer.write("abc", 1, 2);
+ writer.flush();
+ assertEquals("Test 7: write(String, int, int) has not produced the " +
+ "expected content in the output stream.",
+ "bc", baos.toString("utf-8"));
+
+ writer.write(testString, 0, testString.length());
+ writer.flush();
+ assertEquals("Test 7: write(String, int, int) has not produced the " +
+ "expected content in the output stream.",
+ "bc" + testString, baos.toString("utf-8"));
+
+ writer.close();
+ try {
+ writer.write("abc", 0, 1);
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected
+ }
+ }
+
+ private void openInputStream() {
+ try {
+ isr = new InputStreamReader(new ByteArrayInputStream(fos.toByteArray()), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ fail("UTF-8 not supported");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java b/luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java
new file mode 100644
index 0000000..a82a89a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPipedOutputStreamTest.java
@@ -0,0 +1,270 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+public class OldPipedOutputStreamTest extends junit.framework.TestCase {
+
+ static class PReader implements Runnable {
+ PipedInputStream reader;
+
+ public PipedInputStream getReader() {
+ return reader;
+ }
+
+ public PReader(PipedOutputStream out) {
+ try {
+ reader = new PipedInputStream(out);
+ } catch (Exception e) {
+ System.out.println("Exception setting up reader: "
+ + e.toString());
+ }
+ }
+
+ public int available() {
+ try {
+ return reader.available();
+ } catch (Exception e) {
+ return -1;
+ }
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ Thread.sleep(1000);
+ Thread.yield();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public String read(int nbytes) {
+ byte[] buf = new byte[nbytes];
+ try {
+ reader.read(buf, 0, nbytes);
+ return new String(buf);
+ } catch (IOException e) {
+ System.out.println("Exception reading ("
+ + Thread.currentThread().getName() + "): "
+ + e.toString());
+ return "ERROR";
+ }
+ }
+ }
+
+ static final String testString = "Lorem ipsum dolor sit amet,\n" +
+ "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
+ "labore et dolore magna aliqua.\n";
+ static final int testLength = testString.length();
+
+ Thread rt;
+
+ PReader reader;
+
+ PipedOutputStream out;
+
+ public void test_Constructor() {
+ out = new PipedOutputStream();
+ assertNotNull(out);
+ try {
+ out.close();
+ } catch (IOException e) {
+ fail("Unexpeceted IOException.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_PipedInputStream() throws IOException {
+ // Test for method java.io.PipedOutputStream(java.io.PipedInputStream)
+
+ try {
+ out = new PipedOutputStream(new PipedInputStream());
+ out.write('b');
+ } catch (Exception e) {
+ fail("Test 1: Constructor failed: " + e.getMessage());
+ }
+ out.close();
+
+ PipedInputStream pis = new PipedInputStream(new PipedOutputStream());
+ try {
+ out = new PipedOutputStream(pis);
+ fail("Test 2: IOException expected because the input stream is already connected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() {
+ out = new PipedOutputStream();
+ rt = new Thread(reader = new PReader(out));
+ rt.start();
+ try {
+ out.close();
+ } catch (IOException e) {
+ fail("Test 1: Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_connectLjava_io_PipedInputStream() throws IOException {
+ out = new PipedOutputStream();
+
+ try {
+ out.connect(new PipedInputStream());
+ } catch (Exception e) {
+ fail("Test 1: Unexpected exception when connecting: " +
+ e.getLocalizedMessage());
+ }
+
+ try {
+ out.write('B');
+ } catch (IOException e) {
+ fail("Test 2: Unexpected IOException when writing after connecting.");
+ }
+
+ try {
+ out.connect(new PipedInputStream());
+ fail("Test 3: IOException expected when reconnecting the stream.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ try {
+ out.connect(null);
+ fail("Test 4: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+ }
+
+ public void test_flush() throws Exception {
+ out = new PipedOutputStream();
+ rt = new Thread(reader = new PReader(out));
+ rt.start();
+ out.write(testString.getBytes(), 0, 10);
+ assertTrue("Test 1: Bytes have been written before flush.", reader.available() != 0);
+ out.flush();
+ assertEquals("Test 2: Flush failed. ",
+ testString.substring(0, 10), reader.read(10));
+ }
+
+ public void test_write$BII() throws IOException {
+ out = new PipedOutputStream();
+
+ try {
+ out.write(testString.getBytes(), 0, 5);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ out = new PipedOutputStream(new PipedInputStream());
+
+ try {
+ out.write(testString.getBytes(), -1, 10);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ out.write(testString.getBytes(), 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ out.write(testString.getBytes(), 5, testString.length());
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ out.close();
+ out = new PipedOutputStream();
+ try {
+ rt = new Thread(reader = new PReader(out));
+ rt.start();
+ out.write(testString.getBytes(), 0, testString.length());
+ out.flush();
+ assertEquals("Test 5: Bytes read do not match the bytes written. ",
+ testString, reader.read(testString.length()));
+ } catch (IOException e) {
+ fail("Test 5: Unexpected IOException: " + e.getMessage());
+ }
+
+ reader.getReader().close();
+ try {
+ out.write(testString.getBytes(), 0, 5);
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+
+ public void test_writeI() throws IOException {
+ out = new PipedOutputStream();
+
+ try {
+ out.write(42);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ rt = new Thread(reader = new PReader(out));
+ rt.start();
+ out.write('c');
+ out.flush();
+ assertEquals("Test 2: The byte read does not match the byte written. ",
+ "c", reader.read(1));
+
+/* Test disabled due to incomplete implementation, see ticket #92.
+ rt.interrupt();
+
+ try {
+ out.write(42);
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+*/
+ reader.getReader().close();
+ try {
+ out.write(42);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() throws Exception {
+ if (rt != null)
+ rt.interrupt();
+ super.tearDown();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java b/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java
new file mode 100644
index 0000000..b6f686e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPipedWriterTest.java
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.PipedReader;
+import java.io.PipedWriter;
+import java.util.Arrays;
+
+public class OldPipedWriterTest extends junit.framework.TestCase {
+
+ static final String testString = "Lorem ipsum...";
+ static final int testLength = testString.length();
+
+ static class PReader implements Runnable {
+ public PipedReader pr;
+
+ public char[] buf;
+
+ public PReader(PipedWriter pw) {
+ try {
+ pr = new PipedReader(pw);
+ } catch (IOException e) {
+ System.out.println("Exception setting up reader: "
+ + e.toString());
+ }
+ }
+
+ public PReader(PipedReader pr) {
+ this.pr = pr;
+ }
+
+ public void run() {
+ try {
+ while (true) {
+ Thread.sleep(1000);
+ Thread.yield();
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+
+ public String read(int nbytes) {
+ buf = new char[nbytes];
+ try {
+ pr.read(buf, 0, nbytes);
+ return new String(buf);
+ } catch (IOException e) {
+ System.out.println("Exception reading ("
+ + Thread.currentThread().getName() + "): "
+ + e.toString());
+ return "ERROR";
+ }
+ }
+ }
+
+ Thread readerThread;
+ PReader reader;
+ PipedWriter pw;
+ char[] testBuf;
+
+ public void test_Constructor() {
+ pw = new PipedWriter();
+ assertNotNull(pw);
+ try {
+ pw.close();
+ } catch (IOException e) {
+ fail("Unexpeceted IOException.");
+ }
+ }
+
+ public void test_ConstructorLjava_io_PipedReader() throws Exception {
+ PipedReader rd = new PipedReader();
+
+ try {
+ pw = new PipedWriter(rd);
+ } catch (Exception e) {
+ fail("Test 1: Construtor failed:" + e.getMessage());
+ }
+
+ readerThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
+ readerThread.start();
+ try {
+ pw.write(testBuf);
+ } catch (Exception e) {
+ fail("Test 2: Could not write to the constructed writer: "
+ + e.getMessage());
+ }
+ pw.close();
+ assertEquals("Test 3: Incorrect character string received.", testString,
+ reader.read(testLength));
+
+ rd = new PipedReader(new PipedWriter());
+ try {
+ pw = new PipedWriter(rd);
+ fail("Test 4: IOException expected because the reader is already connected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws Exception {
+ PipedReader rd = new PipedReader();
+ pw = new PipedWriter(rd);
+ reader = new PReader(rd);
+ try {
+ pw.close();
+ } catch (IOException e) {
+ fail("Test 1: Unexpected IOException: " + e.getMessage());
+ }
+ }
+
+ public void test_connectLjava_io_PipedReader() throws Exception {
+ PipedReader rd = new PipedReader();
+ pw = new PipedWriter();
+
+ try {
+ pw.connect(rd);
+ } catch (Exception e) {
+ fail("Test 1: Unexpected exception when connecting: " +
+ e.getLocalizedMessage());
+ }
+
+ readerThread = new Thread(reader = new PReader(rd), "connect");
+ readerThread.start();
+
+ try {
+ pw.write(testBuf);
+ } catch (IOException e) {
+ fail("Test 2: Unexpected IOException when writing after connecting.");
+ }
+ assertEquals("Test 3: Incorrect character string received.", testString,
+ reader.read(testLength));
+
+ try {
+ pw.connect(new PipedReader());
+ fail("Test 4: IOException expected when reconnecting the writer.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_flush() throws Exception {
+ // Test for method void java.io.PipedWriter.flush()
+ pw = new PipedWriter();
+ readerThread = new Thread(reader = new PReader(pw), "flush");
+ readerThread.start();
+ pw.write(testBuf);
+ pw.flush();
+ assertEquals("Test 1: Flush failed. ", testString,
+ reader.read(testLength));
+ }
+
+ public void test_write$CII() throws Exception {
+ pw = new PipedWriter();
+
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ pw = new PipedWriter(new PipedReader());
+
+ try {
+ pw.write(testBuf, -1, 1);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ pw.write(testBuf, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ try {
+ pw.write(testBuf, 5, testString.length());
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ pw.close();
+ pw = new PipedWriter();
+ try {
+ readerThread = new Thread(reader = new PReader(pw), "writeCII");
+ readerThread.start();
+ pw.write(testBuf, 0, testLength);
+ pw.close();
+ reader.read(testLength);
+ assertTrue("Test 5: Characters read do not match the characters written.",
+ Arrays.equals( testBuf, reader.buf));
+ } catch (IOException e) {
+ fail("Test 5: Unexpected IOException: " + e.getMessage());
+ }
+
+ readerThread.interrupt();
+
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 6: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ reader.pr.close();
+ try {
+ pw.write(testBuf, 0, 5);
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_writeI() throws Exception {
+ // Test for method void java.io.PipedWriter.write(int)
+
+ pw = new PipedWriter();
+
+ try {
+ pw.write(42);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ readerThread = new Thread(reader = new PReader(pw), "writeI");
+ readerThread.start();
+ pw.write(1);
+ pw.write(2);
+ pw.write(3);
+ pw.close();
+ reader.read(3);
+ assertTrue("Test 2: The charaacters read do not match the characters written: " +
+ (int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
+ reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ testBuf = new char[testLength];
+ testString.getChars(0, testLength, testBuf, 0);
+ }
+
+ protected void tearDown() throws Exception {
+ try {
+ if (readerThread != null) {
+ readerThread.interrupt();
+ }
+ } catch (Exception ignore) {}
+ try {
+ if (pw != null) {
+ pw.close();
+ }
+ } catch (Exception ignore) {}
+ super.tearDown();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java
new file mode 100644
index 0000000..270650e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPushbackInputStreamTest.java
@@ -0,0 +1,356 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.PushbackInputStream;
+
+import tests.support.Support_ASimpleInputStream;
+
+public class OldPushbackInputStreamTest extends junit.framework.TestCase {
+
+ Support_ASimpleInputStream underlying = new Support_ASimpleInputStream();
+ PushbackInputStream pis;
+
+ public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
+
+ public void test_ConstructorLjava_io_InputStream() {
+ // Test for method java.io.PushbackInputStream(java.io.InputStream)
+ try {
+ pis = new PushbackInputStream(new ByteArrayInputStream("Hello"
+ .getBytes()));
+ pis.unread("He".getBytes());
+ } catch (IOException e) {
+ // Correct
+ // Pushback buffer should be full
+ return;
+
+ }
+ fail("Failed to throw exception on unread when buffer full");
+ }
+
+ public void test_ConstructorLjava_io_InputStreamI() {
+ ByteArrayInputStream bas = new ByteArrayInputStream("Hello".getBytes());
+ try {
+ pis = new PushbackInputStream(bas, 0);
+ fail("Test 1: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ try {
+ pis = new PushbackInputStream(bas, -1);
+ fail("Test 2: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ pis = new PushbackInputStream(bas , 5);
+ try {
+ pis.unread("Hello world".getBytes());
+ fail("Test 3: IOException expected when the unread buffer is full.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_close() throws IOException {
+ PushbackInputStream tobj;
+
+ tobj = new PushbackInputStream(underlying);
+ tobj.close();
+ tobj.close();
+ tobj = new PushbackInputStream(underlying);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_available() throws IOException {
+ PushbackInputStream tobj;
+
+ tobj = new PushbackInputStream(underlying);
+ assertEquals("Wrong number!", 30, tobj.available());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.available();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_markSupported() {
+ // Test for method boolean java.io.PushbackInputStream.markSupported()
+ assertTrue("markSupported returned true", !pis.markSupported());
+ }
+
+ public void test_read() throws IOException {
+ PushbackInputStream tobj;
+
+ tobj = new PushbackInputStream(underlying);
+ assertEquals("Test 1: Incorrect byte read;", 66, tobj.read());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ assertEquals("Test 3: Incorrect byte read;",
+ fileString.getBytes()[0], pis.read());
+ }
+
+ public void test_read$BII() throws IOException {
+ PushbackInputStream tobj;
+ byte[] buf = ("01234567890123456789").getBytes();
+
+ tobj = new PushbackInputStream(underlying);
+ tobj.read(buf, 6, 5);
+ assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
+ assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf, 6, 5);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_read$BII_Exception() throws IOException {
+ PushbackInputStream tobj;
+ byte[] buf = new byte[10];
+
+ tobj = new PushbackInputStream(underlying);
+ try {
+ tobj.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ tobj.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ tobj.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ public void test_skipJ() throws IOException {
+ PushbackInputStream tobj;
+ byte[] buf = ("01234567890123456789").getBytes();
+
+ tobj = new PushbackInputStream(underlying);
+ tobj.skip(6);
+ assertEquals("Wrong number!", 30 - 6, tobj.available());
+ tobj.skip(1000000);
+ tobj.skip(1000000);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.skip(1);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method long java.io.PushbackInputStream.skip(long)
+ try {
+ buf = new byte[50];
+ pis.skip(50);
+ pis.read(buf, 0, buf.length);
+ assertTrue("a) Incorrect bytes read", new String(buf)
+ .equals(fileString.substring(50, 100)));
+ pis.unread(buf);
+ pis.skip(25);
+ byte[] buf2 = new byte[25];
+ pis.read(buf2, 0, buf2.length);
+ assertTrue("b) Incorrect bytes read", new String(buf2)
+ .equals(fileString.substring(75, 100)));
+ } catch (Exception e) {
+ fail("Exception during test : " + e.getMessage());
+ }
+ }
+
+ public void test_unread$B() throws IOException {
+ PushbackInputStream tobj;
+ String str2 = "0123456789";
+ byte[] buf2 = str2.getBytes();
+ byte[] readBuf = new byte[10];
+
+ tobj = new PushbackInputStream(underlying, 10);
+ tobj.unread(buf2);
+ assertEquals("Wrong number!", 30 + 10, tobj.available());
+ try {
+ tobj.unread(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", str2, new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method void java.io.PushbackInputStream.unread(byte [])
+ try {
+ byte[] buf = new byte[100];
+ pis.read(buf, 0, buf.length);
+ assertTrue("Incorrect bytes read", new String(buf)
+ .equals(fileString.substring(0, 100)));
+ pis.unread(buf);
+ pis.read(buf, 0, 50);
+ assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+ .equals(fileString.substring(0, 50)));
+ } catch (IOException e) {
+ fail("IOException during unread test : " + e.getMessage());
+ }
+ }
+
+ public void test_unread$BII() throws IOException {
+ PushbackInputStream tobj;
+ String str2 = "0123456789";
+ byte[] buf2 = (str2 + str2 + str2).getBytes();
+ byte[] readBuf = new byte[10];
+
+ tobj = new PushbackInputStream(underlying, 10);
+ tobj.unread(buf2, 15, 10);
+ assertEquals("Wrong number!", 30 + 10, tobj.available());
+ try {
+ tobj.unread(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method void java.io.PushbackInputStream.unread(byte [], int,
+ // int)
+ try {
+ byte[] buf = new byte[100];
+ pis.read(buf, 0, buf.length);
+ assertTrue("Incorrect bytes read", new String(buf)
+ .equals(fileString.substring(0, 100)));
+ pis.unread(buf, 50, 50);
+ pis.read(buf, 0, 50);
+ assertTrue("Failed to unread bytes", new String(buf, 0, 50)
+ .equals(fileString.substring(50, 100)));
+ } catch (IOException e) {
+ fail("IOException during unread test : " + e.getMessage());
+ }
+
+ try {
+ byte[] buf = new byte[10];
+ pis.unread(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ byte[] buf = new byte[10];
+ pis.unread(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+
+ try {
+ byte[] buf = new byte[10];
+ pis.unread(buf, 10, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ public void test_unreadI() throws IOException {
+ PushbackInputStream tobj;
+
+ tobj = new PushbackInputStream(underlying);
+ tobj.unread(23); // Why does this work?!?
+ tobj.skip(2);
+ tobj.unread(23);
+ assertEquals("Wrong number!", 30, tobj.available());
+ assertEquals("Wrong value read!", 23, tobj.read());
+ tobj.unread(13);
+ try {
+ tobj.unread(13);
+ fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method void java.io.PushbackInputStream.unread(int)
+ try {
+ int x;
+ assertTrue("Incorrect byte read", (x = pis.read()) == fileString
+ .getBytes()[0]);
+ pis.unread(x);
+ assertTrue("Failed to unread", pis.read() == x);
+ } catch (IOException e) {
+ fail("IOException during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+
+ pis = new PushbackInputStream(new ByteArrayInputStream(fileString
+ .getBytes()), 65535);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ try {
+ pis.close();
+ } catch (IOException e) {
+ fail("IOException during tearDown : " + e.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java b/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java
new file mode 100644
index 0000000..31d921b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldPushbackReaderTest.java
@@ -0,0 +1,385 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.PushbackReader;
+import java.io.StringReader;
+import tests.support.Support_ASimpleReader;
+
+public class OldPushbackReaderTest extends junit.framework.TestCase {
+
+ Support_ASimpleReader underlying = new Support_ASimpleReader();
+ PushbackReader pbr;
+
+ String pbString = "Hello World";
+
+ /**
+ * @tests java.io.PushbackReader#PushbackReader(java.io.Reader)
+ */
+ public void test_ConstructorLjava_io_Reader() {
+ // Test for method java.io.PushbackReader(java.io.Reader)
+ try {
+ pbr.close();
+ pbr = new PushbackReader(new StringReader(pbString));
+ char buf[] = new char[5];
+ pbr.read(buf, 0, 5);
+ pbr.unread(buf);
+ fail("Created reader with buffer larger than 1");;
+ } catch (IOException e) {
+ // Expected
+ }
+
+ try {
+ pbr = new PushbackReader(null);
+ } catch (NullPointerException e) {
+ // EXpected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#PushbackReader(java.io.Reader, int)
+ */
+ public void test_ConstructorLjava_io_ReaderI() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying, 10000);
+ tobj = new PushbackReader(underlying, 1);
+
+ try {
+ tobj = new PushbackReader(underlying, -1);
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ tobj = new PushbackReader(underlying, 0);
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#close()
+ */
+ public void test_close() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.close();
+ tobj.close();
+ tobj = new PushbackReader(underlying);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.close();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#markSupported()
+ */
+ public void test_markSupported() {
+ assertFalse("Test 1: markSupported() must return false.",
+ pbr.markSupported());
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read()
+ */
+ public void test_read() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ assertEquals("Wrong value read!", 66, tobj.read());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read(char[], int, int)
+ */
+ public void test_read$CII() throws IOException {
+ PushbackReader tobj;
+ char[] buf = ("01234567890123456789").toCharArray();
+
+ tobj = new PushbackReader(underlying);
+ tobj.read(buf, 6, 5);
+ assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
+ assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf, 6, 5);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method int java.io.PushbackReader.read(char [], int, int)
+ try {
+ char[] c = new char[5];
+ pbr.read(c, 0, 5);
+ assertTrue("Failed to read chars", new String(c).equals(pbString
+ .substring(0, 5)));
+
+ assertEquals(0, pbr.read(c, 0, 0));
+ assertEquals(c.length, pbr.read(c, 0, c.length));
+ assertEquals(0, pbr.read(c, c.length, 0));
+ } catch (IOException e) {
+ fail("IOException during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#read(char[], int, int)
+ */
+ public void test_read_$CII_Exception() throws IOException {
+ pbr = new PushbackReader(new StringReader(pbString), 10);
+
+ char[] nullCharArray = null;
+ char[] charArray = new char[10];
+
+ try {
+ pbr.read(nullCharArray, 0, 1);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 0, -1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, -1, 0);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, charArray.length + 1, 0);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, charArray.length, 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 1, charArray.length);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ pbr.read(charArray, 0, charArray.length + 1);
+ fail("should throw IndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ pbr.close();
+
+ try {
+ pbr.read(charArray, 0, 1);
+ fail("should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#ready()
+ */
+ public void test_ready() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ assertTrue("Should be ready!", tobj.ready());
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.ready();
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+ /**
+ * @tests java.io.PushbackReader#unread(char[])
+ */
+ public void test_unread$C() throws IOException {
+ PushbackReader tobj;
+ String str2 = "0123456789";
+ char[] buf2 = str2.toCharArray();
+ char[] readBuf = new char[10];
+
+ tobj = new PushbackReader(underlying, 10);
+ tobj.unread(buf2);
+ try {
+ tobj.unread(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", str2, new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+
+ // Test for method void java.io.PushbackReader.unread(char [])
+ try {
+ char[] c = new char[5];
+ pbr.read(c, 0, 5);
+ pbr.unread(c);
+ pbr.read(c, 0, 5);
+ assertTrue("Failed to unread chars", new String(c).equals(pbString
+ .substring(0, 5)));
+ } catch (IOException e) {
+ fail("IOException during read test : " + e.getMessage());
+ }
+ }
+
+ /**
+ * @throws IOException
+ * @tests java.io.PushbackReader#skip(long)
+ */
+ public void test_skip$J() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.skip(6);
+ tobj.skip(1000000);
+ tobj.skip(1000000);
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.skip(1);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#unread(char[], int, int)
+ */
+ public void test_unread$CII() throws IOException {
+ PushbackReader tobj;
+ String str2 = "0123456789";
+ char[] buf2 = (str2 + str2 + str2).toCharArray();
+ char[] readBuf = new char[10];
+
+ tobj = new PushbackReader(underlying, 10);
+ tobj.unread(buf2, 15, 10);
+ try {
+ tobj.unread(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ tobj.read(readBuf);
+ assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
+ underlying.throwExceptionOnNextUse = true;
+ try {
+ tobj.read(buf2, 15, 10);
+ fail("IOException not thrown.");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
+ //a pushback reader with one character buffer
+ pbr = new PushbackReader(new StringReader(pbString));
+ try {
+ pbr.unread(new char[pbString.length()], 0 , -1);
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ pbr.unread(new char[10], 10 , 1);
+ fail("should throw ArrayIndexOutOfBoundsException");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ /**
+ * @tests java.io.PushbackReader#unread(int)
+ */
+ public void test_unreadI() throws IOException {
+ PushbackReader tobj;
+
+ tobj = new PushbackReader(underlying);
+ tobj.unread(23); // Why does this work?!?
+ tobj.skip(2);
+ tobj.unread(23);
+ assertEquals("Wrong value read!", 23, tobj.read());
+ tobj.unread(13);
+ try {
+ tobj.unread(13);
+ fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ pbr = new PushbackReader(new StringReader(pbString), 10);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ try {
+ pbr.close();
+ } catch (IOException e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldRandomAccessFileTest.java b/luni/src/test/java/libcore/java/io/OldRandomAccessFileTest.java
new file mode 100644
index 0000000..c63cd7e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldRandomAccessFileTest.java
@@ -0,0 +1,1210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+import java.nio.channels.FileChannel;
+import java.nio.channels.NonWritableChannelException;
+
+public class OldRandomAccessFileTest extends junit.framework.TestCase {
+
+ public String fileName;
+
+ public boolean ufile = true;
+
+ java.io.RandomAccessFile raf;
+
+ java.io.File f;
+
+ String unihw = "\u0048\u0065\u006C\u0801\u006C\u006F\u0020\u0057\u0081\u006F\u0072\u006C\u0064";
+
+ static final String testString = "Lorem ipsum dolor sit amet,\n" +
+ "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
+ "labore et dolore magna aliqua.\n";
+ static final int testLength = testString.length();
+
+ /**
+ * @tests java.io.RandomAccessFile#RandomAccessFile(java.io.File,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
+ RandomAccessFile raf = null;
+ File tmpFile = new File(fileName);
+
+ try {
+ raf = new java.io.RandomAccessFile(tmpFile, "r");
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IllegalArgumentException e) {
+ fail("Test 2: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+
+ tmpFile.createNewFile();
+
+ try {
+ // Checking the remaining valid mode parameters.
+ try {
+ raf = new java.io.RandomAccessFile(tmpFile, "rwd");
+ } catch (IllegalArgumentException e) {
+ fail("Test 3: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+ try {
+ raf = new java.io.RandomAccessFile(tmpFile, "rws");
+ } catch (IllegalArgumentException e) {
+ fail("Test 4: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+ try {
+ raf = new java.io.RandomAccessFile(tmpFile, "rw");
+ } catch (IllegalArgumentException e) {
+ fail("Test 5: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+
+ // Checking an invalid mode parameter.
+ try {
+ raf = new java.io.RandomAccessFile(tmpFile, "i");
+ fail("Test 6: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+ } finally {
+ if (raf != null ) raf.close();
+ tmpFile.delete();
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#RandomAccessFile(java.lang.String,
+ * java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_StringLjava_lang_String()
+ throws IOException {
+ RandomAccessFile raf = null;
+ File tmpFile = new File(fileName);
+
+ try {
+ raf = new java.io.RandomAccessFile(fileName, "r");
+ fail("Test 1: FileNotFoundException expected.");
+ } catch (FileNotFoundException e) {
+ // Expected.
+ } catch (IllegalArgumentException e) {
+ fail("Test 2: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+
+ try {
+ // Checking the remaining valid mode parameters.
+ try {
+ raf = new java.io.RandomAccessFile(fileName, "rwd");
+ } catch (IllegalArgumentException e) {
+ fail("Test 3: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+ try {
+ raf = new java.io.RandomAccessFile(fileName, "rws");
+ } catch (IllegalArgumentException e) {
+ fail("Test 4: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+ try {
+ raf = new java.io.RandomAccessFile(fileName, "rw");
+ } catch (IllegalArgumentException e) {
+ fail("Test 5: Unexpected IllegalArgumentException: " + e.getMessage());
+ }
+ raf.close();
+
+ // Checking an invalid mode parameter.
+ try {
+ raf = new java.io.RandomAccessFile(fileName, "i");
+ fail("Test 6: IllegalArgumentException expected.");
+ } catch (IllegalArgumentException e) {
+ // Expected.
+ }
+
+ // Checking for NoWritableChannelException.
+ raf = new java.io.RandomAccessFile(fileName, "r");
+ FileChannel fcr = raf.getChannel();
+
+ try {
+ fcr.lock(0L, Long.MAX_VALUE, false);
+ fail("Test 7: NonWritableChannelException expected.");
+ } catch (NonWritableChannelException e) {
+ // Expected.
+ }
+
+ } finally {
+ if (raf != null ) raf.close();
+ if (tmpFile.exists()) tmpFile.delete();
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#close()
+ */
+ public void test_close() {
+ // Test for method void java.io.RandomAccessFile.close()
+ try {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.close();
+ raf.write("Test".getBytes(), 0, 4);
+ fail("Failed to close file properly.");
+ } catch (IOException e) {}
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#getChannel()
+ */
+ public void test_getChannel() throws IOException {
+
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ FileChannel fc = raf.getChannel();
+
+ // Indirect test: If the file's file pointer moves then the position
+ // in the channel has to move accordingly.
+ assertTrue("Test 1: Channel position expected to be 0.", fc.position() == 0);
+
+ raf.write(testString.getBytes());
+ assertEquals("Test 2: Unexpected channel position.",
+ testLength, fc.position());
+ assertTrue("Test 3: Channel position is not equal to file pointer.",
+ fc.position() == raf.getFilePointer());
+ raf.close();
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#getFD()
+ */
+ public void test_getFD() throws IOException {
+ // Test for method java.io.FileDescriptor
+ // java.io.RandomAccessFile.getFD()
+
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ assertTrue("Test 1: Returned invalid fd.", raf.getFD().valid());
+
+ raf.close();
+ assertFalse("Test 2: Returned valid fd after close", raf.getFD().valid());
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#getFilePointer()
+ */
+ public void test_getFilePointer() throws IOException {
+ // Test for method long java.io.RandomAccessFile.getFilePointer()
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.write(testString.getBytes(), 0, testLength);
+ assertEquals("Test 1: Incorrect filePointer returned. ", testLength, raf
+ .getFilePointer());
+ raf.close();
+ try {
+ raf.getFilePointer();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#length()
+ */
+ public void test_length() throws IOException {
+ // Test for method long java.io.RandomAccessFile.length()
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.write(testString.getBytes());
+ assertEquals("Test 1: Incorrect length returned. ", testLength,
+ raf.length());
+ raf.close();
+ try {
+ raf.length();
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#read()
+ */
+ public void test_read_write() throws IOException {
+ int i;
+ byte[] testBuf = testString.getBytes();
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ for (i = 0; i < testString.length(); i++) {
+ try {
+ raf.write(testBuf[i]);
+ } catch (Exception e) {
+ fail("Test 1: Unexpected exception while writing: "
+ + e.getMessage());
+ }
+ }
+
+ raf.seek(0);
+
+ for (i = 0; i < testString.length(); i++) {
+ assertEquals(String.format("Test 2: Incorrect value written or read at index %d; ", i),
+ testBuf[i], raf.read());
+ }
+
+ assertTrue("Test 3: End of file indicator (-1) expected.", raf.read() == -1);
+
+ raf.close();
+ try {
+ raf.write(42);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.read();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#read(byte[])
+ */
+ public void test_read$B() throws IOException {
+ FileOutputStream fos = new java.io.FileOutputStream(fileName);
+ fos.write(testString.getBytes(), 0, testLength);
+ fos.close();
+
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
+ byte[] rbuf = new byte[testLength + 10];
+
+ int bytesRead = raf.read(rbuf);
+ assertEquals("Test 1: Incorrect number of bytes read. ",
+ testLength, bytesRead);
+ assertEquals("Test 2: Incorrect bytes read. ", testString,
+ new String(rbuf, 0, testLength));
+
+ bytesRead = raf.read(rbuf);
+ assertTrue("Test 3: EOF (-1) expected. ", bytesRead == -1);
+
+ raf.close();
+ try {
+ bytesRead = raf.read(rbuf);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#read(byte[], int, int)
+ */
+ public void test_read$BII() throws IOException {
+ int bytesRead;
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ byte[] rbuf = new byte[4000];
+
+ FileOutputStream fos = new java.io.FileOutputStream(fileName);
+ fos.write(testString.getBytes(), 0, testLength);
+ fos.close();
+
+ // Read half of the file contents.
+ bytesRead = raf.read(rbuf, 10, testLength / 2);
+ assertEquals("Test 1: Incorrect number of bytes read. ",
+ testLength / 2, bytesRead);
+ assertEquals("Test 2: Incorrect bytes read. ",
+ testString.substring(0, testLength / 2),
+ new String(rbuf, 10, testLength / 2));
+
+ // Read the rest of the file contents.
+ bytesRead = raf.read(rbuf, 0, testLength);
+ assertEquals("Test 3: Incorrect number of bytes read. ",
+ testLength - (testLength / 2), bytesRead);
+ assertEquals("Test 4: Incorrect bytes read. ",
+ testString.substring(testLength / 2, (testLength / 2) + bytesRead),
+ new String(rbuf, 0, bytesRead));
+
+ // Try to read even more.
+ bytesRead = raf.read(rbuf, 0, 1);
+ assertTrue("Test 5: EOF (-1) expected. ", bytesRead == -1);
+
+ // Illegal parameter value tests.
+ try {
+ raf.read(rbuf, -1, 1);
+ fail("Test 6: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ raf.read(rbuf, 0, -1);
+ fail("Test 7: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ raf.read(rbuf, 2000, 2001);
+ fail("Test 8: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ // IOException test.
+ raf.close();
+ try {
+ bytesRead = raf.read(rbuf, 0, 1);
+ fail("Test 9: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readBoolean()
+ * @tests java.io.RandomAccessFile#writeBoolean(boolean)
+ */
+ public void test_read_writeBoolean() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeBoolean(true);
+ raf.writeBoolean(false);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ true, raf.readBoolean());
+ assertEquals("Test 2: Incorrect value written or read;",
+ false, raf.readBoolean());
+
+ try {
+ raf.readBoolean();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeBoolean(false);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readBoolean();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readByte()
+ * @tests java.io.RandomAccessFile#writeByte(byte)
+ */
+ public void test_read_writeByte() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeByte(Byte.MIN_VALUE);
+ raf.writeByte(11);
+ raf.writeByte(Byte.MAX_VALUE);
+ raf.writeByte(Byte.MIN_VALUE - 1);
+ raf.writeByte(Byte.MAX_VALUE + 1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Byte.MIN_VALUE, raf.readByte());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 11, raf.readByte());
+ assertEquals("Test 3: Incorrect value written or read;",
+ Byte.MAX_VALUE, raf.readByte());
+ assertEquals("Test 4: Incorrect value written or read;",
+ 127, raf.readByte());
+ assertEquals("Test 5: Incorrect value written or read;",
+ -128, raf.readByte());
+
+ try {
+ raf.readByte();
+ fail("Test 6: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeByte(13);
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readByte();
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readChar()
+ * @tests java.io.RandomAccessFile#writeChar(char)
+ */
+ public void test_read_writeChar() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeChar(Character.MIN_VALUE);
+ raf.writeChar('T');
+ raf.writeChar(Character.MAX_VALUE);
+ raf.writeChar(Character.MIN_VALUE - 1);
+ raf.writeChar(Character.MAX_VALUE + 1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Character.MIN_VALUE, raf.readChar());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 'T', raf.readChar());
+ assertEquals("Test 3: Incorrect value written or read;",
+ Character.MAX_VALUE, raf.readChar());
+ assertEquals("Test 4: Incorrect value written or read;",
+ 0xffff, raf.readChar());
+ assertEquals("Test 5: Incorrect value written or read;",
+ 0, raf.readChar());
+
+ try {
+ raf.readChar();
+ fail("Test 6: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeChar('E');
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readChar();
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readDouble()
+ * @tests java.io.RandomAccessFile#writeDouble(double)
+ */
+ public void test_read_writeDouble() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeDouble(Double.MAX_VALUE);
+ raf.writeDouble(424242.4242);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Double.MAX_VALUE, raf.readDouble());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 424242.4242, raf.readDouble());
+
+ try {
+ raf.readDouble();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeDouble(Double.MIN_VALUE);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readDouble();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readFloat()
+ * @tests java.io.RandomAccessFile#writeFloat(double)
+ */
+ public void test_read_writeFloat() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeFloat(Float.MAX_VALUE);
+ raf.writeFloat(555.55f);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read. ",
+ Float.MAX_VALUE, raf.readFloat());
+ assertEquals("Test 2: Incorrect value written or read. ",
+ 555.55f, raf.readFloat());
+
+ try {
+ raf.readFloat();
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeFloat(Float.MIN_VALUE);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readFloat();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readInt()
+ * @tests java.io.RandomAccessFile#writeInt(char)
+ */
+ public void test_read_writeInt() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeInt(Integer.MIN_VALUE);
+ raf.writeInt('T');
+ raf.writeInt(Integer.MAX_VALUE);
+ raf.writeInt(Integer.MIN_VALUE - 1);
+ raf.writeInt(Integer.MAX_VALUE + 1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Integer.MIN_VALUE, raf.readInt());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 'T', raf.readInt());
+ assertEquals("Test 3: Incorrect value written or read;",
+ Integer.MAX_VALUE, raf.readInt());
+ assertEquals("Test 4: Incorrect value written or read;",
+ 0x7fffffff, raf.readInt());
+ assertEquals("Test 5: Incorrect value written or read;",
+ 0x80000000, raf.readInt());
+
+ try {
+ raf.readInt();
+ fail("Test 6: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeInt('E');
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readInt();
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readLong()
+ * @tests java.io.RandomAccessFile#writeLong(char)
+ */
+ public void test_read_writeLong() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeLong(Long.MIN_VALUE);
+ raf.writeLong('T');
+ raf.writeLong(Long.MAX_VALUE);
+ raf.writeLong(Long.MIN_VALUE - 1);
+ raf.writeLong(Long.MAX_VALUE + 1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Long.MIN_VALUE, raf.readLong());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 'T', raf.readLong());
+ assertEquals("Test 3: Incorrect value written or read;",
+ Long.MAX_VALUE, raf.readLong());
+ assertEquals("Test 4: Incorrect value written or read;",
+ 0x7fffffffffffffffl, raf.readLong());
+ assertEquals("Test 5: Incorrect value written or read;",
+ 0x8000000000000000l, raf.readLong());
+
+ try {
+ raf.readLong();
+ fail("Test 6: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeLong('E');
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readLong();
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readShort()
+ * @tests java.io.RandomAccessFile#writeShort(short)
+ */
+ public void test_read_writeShort() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeShort(Short.MIN_VALUE);
+ raf.writeShort('T');
+ raf.writeShort(Short.MAX_VALUE);
+ raf.writeShort(Short.MIN_VALUE - 1);
+ raf.writeShort(Short.MAX_VALUE + 1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ Short.MIN_VALUE, raf.readShort());
+ assertEquals("Test 2: Incorrect value written or read;",
+ 'T', raf.readShort());
+ assertEquals("Test 3: Incorrect value written or read;",
+ Short.MAX_VALUE, raf.readShort());
+ assertEquals("Test 4: Incorrect value written or read;",
+ 0x7fff, raf.readShort());
+ assertEquals("Test 5: Incorrect value written or read;",
+ (short) 0x8000, raf.readShort());
+
+ try {
+ raf.readShort();
+ fail("Test 6: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeShort('E');
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readShort();
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readUTF()
+ * @tests java.io.RandomAccessFile#writeShort(char)
+ */
+ public void test_read_writeUTF() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeUTF(unihw);
+ raf.seek(0);
+ assertEquals("Test 1: Incorrect UTF string written or read;",
+ unihw, raf.readUTF());
+
+ try {
+ raf.readUTF();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeUTF("Already closed.");
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readUTF();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#writeBytes(java.lang.String)
+ * @tests java.io.RandomAccessFile#readFully(byte[])
+ */
+ public void test_readFully$B_writeBytesLjava_lang_String() throws IOException {
+ byte[] buf = new byte[testLength];
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeBytes(testString);
+ raf.seek(0);
+
+ try {
+ raf.readFully(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ raf.readFully(buf);
+ assertEquals("Test 2: Incorrect bytes written or read;",
+ testString, new String(buf));
+
+ try {
+ raf.readFully(buf);
+ fail("Test 3: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.writeBytes("Already closed.");
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ try {
+ raf.readFully(buf);
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#writeBytes(java.lang.String)
+ * @tests java.io.RandomAccessFile#readFully(byte[], int, int)
+ */
+ public void test_readFully$BII() throws IOException {
+ byte[] buf = new byte[testLength];
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeBytes(testString);
+ raf.seek(0);
+
+ try {
+ raf.readFully(null);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ raf.readFully(buf, 5, testLength - 10);
+ for (int i = 0; i < 5; i++) {
+ assertEquals("Test 2: Incorrect bytes read;", 0, buf[i]);
+ }
+ assertEquals("Test 3: Incorrect bytes written or read;",
+ testString.substring(0, testLength - 10),
+ new String(buf, 5, testLength - 10));
+
+ // Reading past the end of the file.
+ try {
+ raf.readFully(buf, 3, testLength - 6);
+ fail("Test 4: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ // Passing invalid arguments.
+ try {
+ raf.readFully(buf, -1, 1);
+ fail("Test 5: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ raf.readFully(buf, 0, -1);
+ fail("Test 6: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ try {
+ raf.readFully(buf, 2, testLength);
+ fail("Test 7: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected.
+ }
+
+ // Reading from a closed file.
+ raf.close();
+ try {
+ raf.readFully(buf);
+ fail("Test 8: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readUnsignedByte()
+ */
+ public void test_readUnsignedByte() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeByte(-1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ 255, raf.readUnsignedByte());
+
+ try {
+ raf.readUnsignedByte();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.readUnsignedByte();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readUnsignedShort()
+ */
+ public void test_readUnsignedShort() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeShort(-1);
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect value written or read;",
+ 65535, raf.readUnsignedShort());
+
+ try {
+ raf.readUnsignedShort();
+ fail("Test 2: EOFException expected.");
+ } catch (EOFException e) {
+ // Expected.
+ }
+
+ raf.close();
+ try {
+ raf.readUnsignedShort();
+ fail("Test 3: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#readLine()
+ */
+ public void test_readLine() throws IOException {
+ // Test for method java.lang.String java.io.RandomAccessFile.readLine()
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ String s = "Goodbye\nCruel\nWorld\n";
+ raf.write(s.getBytes(), 0, s.length());
+ raf.seek(0);
+
+ assertEquals("Test 1: Incorrect line read;", "Goodbye", raf.readLine());
+ assertEquals("Test 2: Incorrect line read;", "Cruel", raf.readLine());
+ assertEquals("Test 3: Incorrect line read;", "World", raf.readLine());
+ assertNull("Test 4: Incorrect line read; null expected.", raf.readLine());
+
+ raf.close();
+ try {
+ raf.readLine();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#seek(long)
+ */
+ public void test_seekJ() throws IOException {
+ // Test for method void java.io.RandomAccessFile.seek(long)
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+
+ try {
+ raf.seek(-1);
+ fail("Test 1: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ raf.write(testString.getBytes(), 0, testLength);
+ raf.seek(12);
+ assertEquals("Test 3: Seek failed to set file pointer.", 12,
+ raf.getFilePointer());
+
+ raf.close();
+ try {
+ raf.seek(1);
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#skipBytes(int)
+ */
+ public void test_skipBytesI() throws IOException {
+ byte[] buf = new byte[5];
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeBytes("HelloWorld");
+ raf.seek(0);
+
+ assertTrue("Test 1: Nothing should be skipped if parameter is less than zero",
+ raf.skipBytes(-1) == 0);
+
+ assertEquals("Test 4: Incorrect number of bytes skipped; ",
+ 5, raf.skipBytes(5));
+
+ raf.readFully(buf);
+ assertEquals("Test 3: Failed to skip bytes.",
+ "World", new String(buf, 0, 5));
+
+ raf.seek(0);
+ assertEquals("Test 4: Incorrect number of bytes skipped; ",
+ 10, raf.skipBytes(20));
+
+ raf.close();
+ try {
+ raf.skipBytes(1);
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#skipBytes(int)
+ */
+ public void test_setLengthJ() throws IOException {
+ int bytesRead;
+ long truncLength = (long) (testLength * 0.75);
+ byte[] rbuf = new byte[testLength + 10];
+
+ // Setup the test file.
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.write(testString.getBytes());
+ assertEquals("Test 1: Incorrect file length;",
+ testLength, raf.length());
+
+ // Truncate the file.
+ raf.setLength(truncLength);
+ assertTrue("Test 2: File pointer not moved to the end of the truncated file.",
+ raf.getFilePointer() == truncLength);
+
+ raf.close();
+ raf = new java.io.RandomAccessFile(fileName, "rw");
+ assertEquals("Test 3: Incorrect file length;",
+ truncLength, raf.length());
+ bytesRead = raf.read(rbuf);
+ assertEquals("Test 4: Incorrect number of bytes read;",
+ truncLength, bytesRead);
+ assertEquals("Test 5: Incorrect bytes read. ",
+ testString.substring(0, bytesRead),
+ new String(rbuf, 0, bytesRead));
+
+ // Expand the file.
+ raf.setLength(testLength + 2);
+ assertTrue("Test 6: File pointer incorrectly moved.",
+ raf.getFilePointer() == truncLength);
+ assertEquals("Test 7: Incorrect file length;",
+ testLength + 2, raf.length());
+
+ // Exception testing.
+ try {
+ raf.setLength(-1);
+ fail("Test 9: IllegalArgumentException expected.");
+ } catch (IOException expected) {
+ } catch (IllegalArgumentException expected) {
+ }
+
+ raf.close();
+ try {
+ raf.setLength(truncLength);
+ fail("Test 10: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#write(byte[])
+ */
+ public void test_write$B() throws IOException {
+ byte[] rbuf = new byte[4000];
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+
+ byte[] nullByteArray = null;
+ try {
+ raf.write(nullByteArray);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ try {
+ raf.write(testString.getBytes());
+ } catch (Exception e) {
+ fail("Test 2: Unexpected exception: " + e.getMessage());
+ }
+
+ raf.close();
+
+ try {
+ raf.write(new byte[0]);
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException: " + e.getMessage());
+ }
+
+ try {
+ raf.write(testString.getBytes());
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ FileInputStream fis = new java.io.FileInputStream(fileName);
+ fis.read(rbuf, 0, testLength);
+ assertEquals("Incorrect bytes written", testString, new String(rbuf, 0,
+ testLength));
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#write(byte[], int, int)
+ */
+ public void test_write$BII() throws Exception {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ byte[] rbuf = new byte[4000];
+ byte[] testBuf = null;
+ int bytesRead;
+
+ try {
+ raf.write(testBuf, 1, 1);
+ fail("Test 1: NullPointerException expected.");
+ } catch (NullPointerException e) {
+ // Expected.
+ }
+
+ testBuf = testString.getBytes();
+
+ try {
+ raf.write(testBuf, -1, 10);
+ fail("Test 2: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException expected) {
+ }
+
+ try {
+ raf.write(testBuf, 0, -1);
+ fail("Test 3: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException expected) {
+ }
+
+ try {
+ raf.write(testBuf, 5, testLength);
+ fail("Test 4: IndexOutOfBoundsException expected.");
+ } catch (IndexOutOfBoundsException expected) {
+ }
+
+ // Positive test: The following write should not fail.
+ try {
+ raf.write(testBuf, 3, testLength - 5);
+ } catch (Exception e) {
+ fail("Test 5: Unexpected exception: " + e.getMessage());
+ }
+
+ raf.close();
+
+ // Writing nothing to a closed file should not fail either.
+ try {
+ raf.write(new byte[0]);
+ } catch (IOException e) {
+ fail("Test 6: Unexpected IOException: " + e.getMessage());
+ }
+
+ // Writing something to a closed file should fail.
+ try {
+ raf.write(testString.getBytes());
+ fail("Test 7: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ FileInputStream fis = new java.io.FileInputStream(fileName);
+ bytesRead = fis.read(rbuf, 0, testLength);
+ assertEquals("Test 8: Incorrect number of bytes written or read;",
+ testLength - 5, bytesRead);
+ assertEquals("Test 9: Incorrect bytes written or read; ",
+ testString.substring(3, testLength - 2),
+ new String(rbuf, 0, bytesRead));
+ }
+
+ /**
+ * @tests java.io.RandomAccessFile#writeChars(java.lang.String)
+ */
+ public void test_writeCharsLjava_lang_String() throws IOException {
+ RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
+ raf.writeChars(unihw);
+ char[] hchars = new char[unihw.length()];
+ unihw.getChars(0, unihw.length(), hchars, 0);
+ raf.seek(0);
+ for (int i = 0; i < hchars.length; i++)
+ assertEquals("Test 1: Incorrect character written or read at index " + i + ";",
+ hchars[i], raf.readChar());
+ raf.close();
+ try {
+ raf.writeChars("Already closed.");
+ fail("Test 2: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ f = File.createTempFile("raf", "tst");
+ if (!f.delete()) {
+ fail("Unable to delete test file : " + f);
+ }
+ fileName = f.getAbsolutePath();
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ * @throws Exception
+ */
+ protected void tearDown() throws Exception {
+ if (f.exists()) {
+ f.delete();
+ }
+ super.tearDown();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/io/OldReaderTest.java b/luni/src/test/java/libcore/java/io/OldReaderTest.java
new file mode 100644
index 0000000..eb7767e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldReaderTest.java
@@ -0,0 +1,124 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.CharBuffer;
+
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleReader;
+
+public class OldReaderTest extends TestCase {
+
+ public void test_Reader() {
+ MockReader r = new MockReader();
+ assertTrue("Test 1: Lock has not been set correctly.", r.lockSet(r));
+ }
+
+ public void test_Reader_CharBufferChar() throws IOException {
+ Support_ASimpleReader simple;
+ simple = new Support_ASimpleReader("Bla bla, what else?");
+ CharBuffer buf = CharBuffer.allocate(4);
+ assertEquals("Wrong return value!", 4, simple.read(buf));
+ buf.rewind();
+ assertEquals("Wrong stuff read!", "Bla ", String.valueOf(buf));
+ simple.read(buf);
+ buf.rewind();
+ assertEquals("Wrong stuff read!", "bla,", String.valueOf(buf));
+ simple.throwExceptionOnNextUse = true;
+ try {
+ simple.read(buf);
+ fail("IOException not thrown!");
+ } catch (IOException expected) {
+ }
+ }
+
+ public void test_Read_$C() throws IOException {
+ Support_ASimpleReader simple;
+ simple = new Support_ASimpleReader("Bla bla, what else?");
+ char[] buf = new char[4];
+ assertEquals("Wrong return value!", 4, simple.read(buf));
+ assertEquals("Wrong stuff read!", "Bla ", new String(buf));
+ simple.read(buf);
+ assertEquals("Wrong stuff read!", "bla,", new String(buf));
+ simple.throwExceptionOnNextUse = true;
+ try {
+ simple.read(buf);
+ fail("IOException not thrown!");
+ } catch (IOException expected) {
+ }
+ }
+
+
+ public void test_markSupported() {
+ assertFalse("markSupported must return false", new MockReader().markSupported());
+ }
+
+ public void test_read() throws IOException {
+ Support_ASimpleReader simple = new Support_ASimpleReader("Bla bla, what else?");
+ int res = simple.read();
+ assertEquals("Wrong stuff read!", 'B', res);
+ res = simple.read();
+ assertEquals("Wrong stuff read!", 'l', res);
+ simple.throwExceptionOnNextUse = true;
+ try {
+ simple.read();
+ fail("IOException not thrown!");
+ } catch (IOException expected) {
+ }
+ }
+
+ public void test_ready() throws IOException {
+ Support_ASimpleReader simple = new Support_ASimpleReader("Bla bla, what else?");
+ simple.throwExceptionOnNextUse = true;
+ try {
+ simple.ready();
+ fail("IOException not thrown!");
+ } catch (IOException expected) {
+ }
+ }
+
+ public void test_skip() throws IOException {
+ Support_ASimpleReader simple = new Support_ASimpleReader("Bla bla, what else?");
+ char[] buf = new char[4];
+ simple.read(buf);
+ assertEquals("Wrong stuff read!", "Bla ", new String(buf));
+ simple.skip(5);
+ simple.read(buf);
+ assertEquals("Wrong stuff read!", "what", new String(buf));
+ simple.throwExceptionOnNextUse = true;
+ try {
+ simple.skip(1);
+ fail("IOException not thrown!");
+ } catch (IOException expected) {
+ }
+ }
+
+ class MockReader extends Reader {
+
+ @Override public void close() {}
+
+ @Override public int read(char[] buf, int offset, int count) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean lockSet(Object o) {
+ return (lock == o);
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java
new file mode 100644
index 0000000..f7d9a49
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldSequenceInputStreamTest.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.SequenceInputStream;
+import tests.support.Support_ASimpleInputStream;
+
+public class OldSequenceInputStreamTest extends junit.framework.TestCase {
+
+ Support_ASimpleInputStream simple1, simple2;
+ SequenceInputStream si;
+ String s1 = "Hello";
+ String s2 = "World";
+
+ public void test_available() throws IOException {
+ assertEquals("Returned incorrect number of bytes!", s1.length(), si.available());
+ simple2.throwExceptionOnNextUse = true;
+ assertTrue("IOException on second stream should not affect at this time!",
+ si.available() == s1.length());
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.available();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_close2() throws IOException {
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.close();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_read() throws IOException {
+ si.read();
+ assertEquals("Test 1: Incorrect char read;",
+ s1.charAt(1), (char) si.read());
+
+ // We are still reading from the first input stream, should be ok.
+ simple2.throwExceptionOnNextUse = true;
+ try {
+ assertEquals("Test 2: Incorrect char read;",
+ s1.charAt(2), (char) si.read());
+ } catch (IOException e) {
+ fail("Test 3: Unexpected IOException.");
+ }
+
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read();
+ fail("Test 4: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ simple1.throwExceptionOnNextUse = false;
+
+ // Reading bytes 4 and 5 of the first input stream should be ok again.
+ si.read();
+ si.read();
+
+ // Reading the first byte of the second input stream should fail.
+ try {
+ si.read();
+ fail("Test 5: IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+
+ // Reading from the second input stream should be ok now.
+ simple2.throwExceptionOnNextUse = false;
+ try {
+ assertEquals("Test 6: Incorrect char read;",
+ s2.charAt(0), (char) si.read());
+ } catch (IOException e) {
+ fail("Test 7: Unexpected IOException.");
+ }
+
+ si.close();
+ assertTrue("Test 8: -1 expected when reading from a closed " +
+ "sequence input stream.", si.read() == -1);
+ }
+
+ public void test_read_exc() throws IOException {
+ simple2.throwExceptionOnNextUse = true;
+ assertEquals("IOException on second stream should not affect at this time!", 72, si.read());
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read();
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_read$BII_Excpetion() throws IOException {
+ byte[] buf = new byte[4];
+ si.read(buf, 0, 2);
+ si.read(buf, 2, 1);
+ simple2.throwExceptionOnNextUse = true;
+ si.read(buf, 3, 1);
+ assertEquals("Wrong stuff read!", "Hell", new String(buf));
+ simple1.throwExceptionOnNextUse = true;
+ try {
+ si.read(buf, 3, 1);
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+
+ buf = new byte[10];
+ simple1 = new Support_ASimpleInputStream(s1);
+ simple2 = new Support_ASimpleInputStream(s2);
+ si = new SequenceInputStream(simple1, simple2);
+ try {
+ si.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ si.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ si.read(buf, 1, 10);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void setUp() {
+ simple1 = new Support_ASimpleInputStream(s1);
+ simple2 = new Support_ASimpleInputStream(s2);
+ si = new SequenceInputStream(simple1, simple2);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java b/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java
new file mode 100644
index 0000000..22b276b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStreamTokenizerTest.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import junit.framework.Assert;
+import tests.support.Support_ASimpleInputStream;
+import tests.support.Support_StringReader;
+
+public class OldStreamTokenizerTest extends junit.framework.TestCase {
+ StreamTokenizer st;
+
+ public void test_nextToken() throws IOException {
+ st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
+ st.ordinaryChar('\n'); // make \n ordinary
+ st.eolIsSignificant(true);
+ assertTrue("Wrong token 2,1", st.nextToken() == '\n');
+ assertTrue("Wrong token 2,2", st.nextToken() == '\n');
+ assertEquals("Wrong token 2,3", '#', st.nextToken());
+
+ Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
+ sis.throwExceptionOnNextUse = true;
+ st = new StreamTokenizer(sis);
+ try {
+ st.nextToken();
+ fail("IOException expected.");
+ } catch (IOException e) {
+ // Expected.
+ }
+ }
+
+ public void test_basicStringTokenizerMethods() throws IOException {
+ String str = "Testing 12345 \n alpha \r\n omega";
+ String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
+ StringReader aa = new StringReader(str);
+ StringReader ba = new StringReader(strb);
+ StreamTokenizer a = new StreamTokenizer(aa);
+ StreamTokenizer b = new StreamTokenizer(ba);
+
+ Assert.assertTrue(a.lineno() == 1);
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[Testing], line 1"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_NUMBER);
+ Assert.assertTrue(a.toString().equals("Token[n=12345.0], line 1"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[alpha], line 2"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(a.toString().equals("Token[omega], line 3"));
+ Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_EOF);
+ Assert.assertTrue(a.toString().equals("Token[EOF], line 3"));
+
+ b.commentChar('u');
+ b.eolIsSignificant(true);
+ b.lowerCaseMode(true);
+ b.ordinaryChar('y');
+ b.slashStarComments(true);
+
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_NUMBER);
+ Assert.assertTrue(b.nval == -3.8);
+ Assert.assertTrue(b.toString().equals("Token[n=-3.8], line 1"));
+ Assert.assertTrue(b.nextToken() == 39); // '
+ Assert.assertTrue(b.toString().equals("Token[BLIND mice], line 1"));
+ Assert.assertTrue(b.nextToken() == 10); // \n
+ Assert.assertTrue(b.toString().equals("Token[EOL], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[see], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[the], line 2"));
+ Assert.assertTrue(b.nextToken() == 121); // y
+ Assert.assertTrue(b.toString().equals("Token['y'], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
+ Assert.assertTrue(b.toString().equals("Token[r], line 2"));
+ Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_EOF);
+ Assert.assertTrue(b.toString().equals("Token[EOF], line 2"));
+ }
+
+ public void test_harmonyRegressionTest() {
+ byte[] data = new byte[] {(byte) '-'};
+ StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
+ try {
+ tokenizer.nextToken();
+ } catch(Exception e) {
+ Assert.fail(e.getMessage());
+ }
+ String result = tokenizer.toString();
+ Assert.assertEquals("Token['-'], line 1", result);
+ }
+
+ public void test_harmonyRegressionTest2() {
+ byte[] data = new byte[] {(byte) '"',
+ (byte) 'H',
+ (byte) 'e',
+ (byte) 'l',
+ (byte) 'l',
+ (byte) 'o',
+ (byte) '"'};
+ StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
+ try {
+ tokenizer.nextToken();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ String result = tokenizer.toString();
+ Assert.assertEquals("Token[Hello], line 1", result);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java b/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java
new file mode 100644
index 0000000..f7aaae9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringBufferInputStreamTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.StringBufferInputStream;
+import junit.framework.TestCase;
+
+public class OldStringBufferInputStreamTest extends TestCase {
+
+ StringBufferInputStream sbis;
+
+ public void test_read$BII_Exception() {
+ // Test for method int java.io.StringBufferInputStream.read()
+ byte[] buf = new byte[10];
+ try {
+ sbis.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sbis.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sbis.read(buf, 10, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void setUp() {
+ sbis = new StringBufferInputStream("Hello World");
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringReaderTest.java b/luni/src/test/java/libcore/java/io/OldStringReaderTest.java
new file mode 100644
index 0000000..a3c6bf0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringReaderTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.StringReader;
+
+public class OldStringReaderTest extends junit.framework.TestCase {
+
+ String testString = "This is a test string";
+
+ StringReader sr;
+
+ public void test_markI() throws IOException {
+ sr = new StringReader(testString);
+ try {
+ sr.mark(-1);
+ fail("IllegalArgumentException not thrown!");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void test_read$CII() throws Exception {
+ char[] buf = new char[testString.length()];
+ sr = new StringReader(testString);
+ try {
+ sr.read(buf, 0, -1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sr.read(buf, -1, 1);
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ try {
+ sr.read(buf, 1, testString.length());
+ fail("IndexOutOfBoundsException was not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected
+ }
+ }
+
+ protected void tearDown() {
+
+ try {
+ sr.close();
+ } catch (Exception e) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldStringWriterTest.java b/luni/src/test/java/libcore/java/io/OldStringWriterTest.java
new file mode 100644
index 0000000..6ff2b74
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldStringWriterTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+public class OldStringWriterTest extends junit.framework.TestCase {
+
+ StringWriter sw;
+
+ public void test_appendCharSequenceIntInt() throws IOException {
+ try {
+ StringWriter tobj = new StringWriter(9);
+ tobj.append("01234567890123456789", 19, 2);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ StringWriter tobj = new StringWriter(9);
+ tobj.append("01234567890123456789", 29, 2);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ protected void setUp() {
+ sw = new StringWriter();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/OldWriterTest.java b/luni/src/test/java/libcore/java/io/OldWriterTest.java
new file mode 100644
index 0000000..b88e3bb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/io/OldWriterTest.java
@@ -0,0 +1,194 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.io;
+
+import java.io.IOException;
+import java.io.Writer;
+import junit.framework.TestCase;
+import tests.support.Support_ASimpleWriter;
+
+public class OldWriterTest extends TestCase {
+
+ public void test_appendChar() throws IOException {
+ Writer tobj = new Support_ASimpleWriter(2);
+ tobj.append('a');
+ tobj.append('b');
+ assertEquals("Wrong stuff written!", "ab", tobj.toString());
+ try {
+ tobj.append('c');
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_appendCharSequence() throws IOException {
+ String testString = "My Test String";
+ Writer tobj = new Support_ASimpleWriter(20);
+ tobj.append(testString);
+ assertEquals("Wrong stuff written!", testString, tobj.toString());
+ try {
+ tobj.append(testString);
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_appendCharSequenceIntInt() throws IOException {
+ String testString = "My Test String";
+ Writer tobj = new Support_ASimpleWriter(21);
+ testString = "0123456789abcdefghijABCDEFGHIJ";
+ tobj.append(testString, 0, 5);
+ assertEquals("Wrong stuff written!", "01234", tobj.toString());
+ tobj.append(testString, 10, 15);
+ assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
+ tobj.append(testString, 20, 30);
+ assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
+ try {
+ tobj.append(testString, 30, 31);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ tobj.append(testString, 20, 21); // Just fill the writer to its limit!
+ try {
+ tobj.append(testString, 29, 30);
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_appendCharSequenceIntInt_Exception() throws IOException {
+ String testString = "My Test String";
+ Writer tobj = new Support_ASimpleWriter(21);
+ try {
+ tobj.append(testString, 30, 31);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ tobj.append(testString, -1, 1);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ tobj.append(testString, 0, -1);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+
+ public void test_write$C() throws IOException {
+ Writer tobj = new Support_ASimpleWriter(21);
+ tobj.write("01234".toCharArray());
+ assertEquals("Wrong stuff written!", "01234", tobj.toString());
+ tobj.write("abcde".toCharArray());
+ assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
+ tobj.write("ABCDEFGHIJ".toCharArray());
+ assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
+ tobj.write("z".toCharArray()); // Just fill the writer to its limit!
+ try {
+ tobj.write("LES JEUX SONT FAITS".toCharArray());
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_writeI() throws IOException {
+ Writer tobj = new Support_ASimpleWriter(2);
+ tobj.write('a');
+ tobj.write('b');
+ assertEquals("Wrong stuff written!", "ab", tobj.toString());
+ try {
+ tobj.write('c');
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_writeLjava_lang_String() throws IOException {
+ Writer tobj = new Support_ASimpleWriter(21);
+ tobj.write("01234");
+ assertEquals("Wrong stuff written!", "01234", tobj.toString());
+ tobj.write("abcde");
+ assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
+ tobj.write("ABCDEFGHIJ");
+ assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
+ tobj.write("z"); // Just fill the writer to its limit!
+ try {
+ tobj.write("LES JEUX SONT FAITS");
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_writeLjava_lang_StringII() throws IOException {
+ String testString;
+ Writer tobj = new Support_ASimpleWriter(21);
+ testString = "0123456789abcdefghijABCDEFGHIJ";
+ tobj.write(testString, 0, 5);
+ assertEquals("Wrong stuff written!", "01234", tobj.toString());
+ tobj.write(testString, 10, 5);
+ assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
+ tobj.write(testString, 20, 10);
+ assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
+ try {
+ tobj.write(testString, 30, 1);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ tobj.write(testString, 20, 1); // Just fill the writer to its limit!
+ try {
+ tobj.write(testString, 29, 1);
+ fail("IOException not thrown!");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+
+ public void test_writeLjava_lang_StringII_Exception() throws IOException {
+ String testString = "My Test String";
+ Writer tobj = new Support_ASimpleWriter(21);
+ try {
+ tobj.write(testString, 30, 31);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ tobj.write(testString, -1, 1);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ tobj.write(testString, 0, -1);
+ fail("IndexOutOfBoundsException not thrown!");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java b/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
index f2709cb..8524502 100644
--- a/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
+++ b/luni/src/test/java/libcore/java/io/RandomAccessFileTest.java
@@ -17,14 +17,52 @@
package libcore.java.io;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import junit.framework.TestCase;
public final class RandomAccessFileTest extends TestCase {
+ private File file;
+
+ @Override protected void setUp() throws Exception {
+ file = File.createTempFile("RandomAccessFileTest", "tmp");
+ }
+
+ @Override protected void tearDown() throws Exception {
+ file.delete();
+ }
+
+ public void testSeekTooLarge() throws Exception {
+ RandomAccessFile raf = new RandomAccessFile(file, "rw");
+ try {
+ raf.seek(Long.MAX_VALUE);
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+
+ public void testSetLengthTooLarge() throws Exception {
+ RandomAccessFile raf = new RandomAccessFile(file, "rw");
+ try {
+ raf.setLength(Long.MAX_VALUE);
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+
+ public void testSetLength64() throws Exception {
+ RandomAccessFile raf = new RandomAccessFile(file, "rw");
+ raf.setLength(0);
+ assertEquals(0, file.length());
+ long moreThanFourGig = ((long) Integer.MAX_VALUE) + 1L;
+ raf.setLength(moreThanFourGig);
+ assertEquals(moreThanFourGig, file.length());
+ }
+
// http://b/3015023
- public void testRandomAccessFileHasCleanupFinalizer() throws IOException {
+ public void testRandomAccessFileHasCleanupFinalizer() throws Exception {
int tooManyOpenFiles = 2000;
File file = File.createTempFile("RandomAccessFileTest", "tmp");
for (int i = 0; i < tooManyOpenFiles; i++) {
diff --git a/luni/src/test/java/libcore/java/lang/ArrayIndexOutOfBoundsExceptionTest.java b/luni/src/test/java/libcore/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
new file mode 100644
index 0000000..041b931
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public final class ArrayIndexOutOfBoundsExceptionTest extends TestCase {
+ public void testAput() throws Exception {
+ byte[] bs = new byte[1];
+ try {
+ bs[2] = 0;
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+
+ public void testAget() throws Exception {
+ byte[] bs = new byte[1];
+ try {
+ byte b = bs[2];
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+
+ public void testAputWide() throws Exception {
+ double[] ds = new double[1];
+ try {
+ ds[2] = 0.0;
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+
+ public void testAgetWide() throws Exception {
+ double[] ds = new double[1];
+ try {
+ double d = ds[2];
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+
+ public void testAputObject() throws Exception {
+ Object[] os = new Object[1];
+ try {
+ os[2] = null;
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+
+ public void testAgetObject() throws Exception {
+ Object[] os = new Object[1];
+ try {
+ Object o = os[2];
+ fail();
+ } catch (ArrayIndexOutOfBoundsException ex) {
+ assertEquals("index=2 length=1", ex.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/ArrayStoreExceptionTest.java b/luni/src/test/java/libcore/java/lang/ArrayStoreExceptionTest.java
new file mode 100644
index 0000000..1b4288e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/ArrayStoreExceptionTest.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public final class ArrayStoreExceptionTest extends TestCase {
+ public void testArrayStoreException() throws Exception {
+ Object[] array = new String[10];
+ Object o = new Exception();
+ try {
+ array[0] = o;
+ fail();
+ } catch (ArrayStoreException ex) {
+ ex.printStackTrace();
+ assertEquals("java.lang.Exception cannot be stored in an array of type java.lang.String[]", ex.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/ClassCastExceptionTest.java b/luni/src/test/java/libcore/java/lang/ClassCastExceptionTest.java
new file mode 100644
index 0000000..780f620
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/ClassCastExceptionTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.util.EnumMap;
+import java.util.EnumSet;
+import junit.framework.TestCase;
+
+public final class ClassCastExceptionTest extends TestCase {
+ public void testCast() throws Exception {
+ Object o = new Exception();
+ try {
+ String s = (String) o;
+ fail();
+ } catch (ClassCastException ex) {
+ assertEquals("java.lang.Exception cannot be cast to java.lang.String", ex.getMessage());
+ }
+ }
+
+ public void testClassCast() throws Exception {
+ Object o = new Exception();
+ try {
+ String.class.cast(o);
+ fail();
+ } catch (ClassCastException ex) {
+ assertEquals("java.lang.Exception cannot be cast to java.lang.String", ex.getMessage());
+ }
+ }
+
+ public void testClassAsSubclass() throws Exception {
+ try {
+ Exception.class.asSubclass(String.class);
+ fail();
+ } catch (ClassCastException ex) {
+ assertEquals("java.lang.Exception cannot be cast to java.lang.String", ex.getMessage());
+ }
+ }
+
+ enum E { A, B, C };
+ enum F { A, B, C };
+
+ public void testEnumMapPut() throws Exception {
+ EnumMap m = new EnumMap(E.class);
+ try {
+ m.put(F.A, "world");
+ fail();
+ } catch (ClassCastException ex) {
+ ex.printStackTrace();
+ assertNotNull(ex.getMessage());
+ }
+ }
+
+ public void testMiniEnumSetAdd() throws Exception {
+ EnumSet m = EnumSet.noneOf(E.class);
+ try {
+ m.add(F.A);
+ fail();
+ } catch (ClassCastException ex) {
+ ex.printStackTrace();
+ assertNotNull(ex.getMessage());
+ }
+ }
+
+ public void testMiniEnumSetAddAll() throws Exception {
+ EnumSet m = EnumSet.noneOf(E.class);
+ EnumSet n = EnumSet.allOf(F.class);
+ try {
+ m.addAll(n);
+ fail();
+ } catch (ClassCastException ex) {
+ ex.printStackTrace();
+ assertNotNull(ex.getMessage());
+ }
+ }
+
+ enum HugeE {
+ A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0, S0, T0, U0, V0, W0, X0, Y0, Z0,
+ A1, B1, C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1, S1, T1, U1, V1, W1, X1, Y1, Z1,
+ A2, B2, C2, D2, E2, F2, G2, H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, V2, W2, X2, Y2, Z2,
+ };
+ enum HugeF {
+ A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0, S0, T0, U0, V0, W0, X0, Y0, Z0,
+ A1, B1, C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1, S1, T1, U1, V1, W1, X1, Y1, Z1,
+ A2, B2, C2, D2, E2, F2, G2, H2, I2, J2, K2, L2, M2, N2, O2, P2, Q2, R2, S2, T2, U2, V2, W2, X2, Y2, Z2,
+ };
+
+ public void testHugeEnumSetAdd() throws Exception {
+ EnumSet m = EnumSet.noneOf(HugeE.class);
+ try {
+ m.add(HugeF.A0);
+ fail();
+ } catch (ClassCastException ex) {
+ ex.printStackTrace();
+ assertNotNull(ex.getMessage());
+ }
+ }
+
+ public void testHugeEnumSetAddAll() throws Exception {
+ EnumSet m = EnumSet.noneOf(HugeE.class);
+ EnumSet n = EnumSet.allOf(HugeF.class);
+ try {
+ m.addAll(n);
+ fail();
+ } catch (ClassCastException ex) {
+ ex.printStackTrace();
+ assertNotNull(ex.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidBooleanTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidBooleanTest.java
new file mode 100644
index 0000000..3f39dbb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidBooleanTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests some basic functionality of Booleans.
+ */
+public class OldAndroidBooleanTest extends TestCase {
+
+ public void testBoolean() throws Exception {
+ Boolean a = new Boolean(true);
+ Boolean b = new Boolean("True");
+ Boolean c = new Boolean(false);
+ Boolean d = new Boolean("Yes");
+
+ assertEquals(a, b);
+ assertEquals(c, d);
+ assertTrue(a.booleanValue());
+ assertFalse(c.booleanValue());
+ assertEquals("true", a.toString());
+ assertEquals("false", c.toString());
+ assertEquals(Boolean.TRUE, a);
+ assertEquals(Boolean.FALSE, c);
+ assertSame(Boolean.valueOf(true), Boolean.TRUE);
+ assertSame(Boolean.valueOf(false), Boolean.FALSE);
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidEnumTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidEnumTest.java
new file mode 100644
index 0000000..b72adcb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidEnumTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests basic behavior of enums.
+ */
+public class OldAndroidEnumTest extends TestCase {
+ enum MyEnum {
+ ZERO, ONE, TWO, THREE, FOUR {boolean isFour() {
+ return true;
+ }};
+
+ boolean isFour() {
+ return false;
+ }
+ }
+
+ enum MyEnumTwo {
+ FIVE, SIX
+ }
+
+ public void testEnum() throws Exception {
+ assertTrue(MyEnum.ZERO.compareTo(MyEnum.ONE) < 0);
+ assertEquals(MyEnum.ZERO, MyEnum.ZERO);
+ assertTrue(MyEnum.TWO.compareTo(MyEnum.ONE) > 0);
+ assertTrue(MyEnum.FOUR.compareTo(MyEnum.ONE) > 0);
+
+ assertEquals("ONE", MyEnum.ONE.name());
+ assertSame(MyEnum.ONE.getDeclaringClass(), MyEnum.class);
+ assertSame(MyEnum.FOUR.getDeclaringClass(), MyEnum.class);
+
+ assertTrue(MyEnum.FOUR.isFour());
+
+ MyEnum e;
+
+ e = MyEnum.ZERO;
+
+ switch (e) {
+ case ZERO:
+ break;
+ default:
+ fail("wrong switch");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidFloatDoubleTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidFloatDoubleTest.java
new file mode 100644
index 0000000..ced7df9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidFloatDoubleTest.java
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for basic functionality of floats and doubles.
+ */
+public class OldAndroidFloatDoubleTest extends TestCase {
+
+ public void testFloatDouble() throws Exception {
+ Double d = Double.valueOf(1.0);
+ Float f = Float.valueOf(1.0f);
+ Object o = new Object();
+
+ assertFalse(f.equals(d));
+ assertFalse(d.equals(f));
+ assertFalse(f.equals(o));
+ assertFalse(d.equals(o));
+ assertFalse(f.equals(null));
+ assertFalse(d.equals(null));
+ }
+
+ public void testFloat() throws Exception {
+ float pz = 0.0f;
+ float nz = -0.0f;
+
+ float pzero = 1.0f / Float.POSITIVE_INFINITY;
+ float nzero = 1.0f / Float.NEGATIVE_INFINITY;
+
+ // Everything compares as '=='
+ assertTrue(pz == pz);
+ assertTrue(pz == nz);
+ assertTrue(pz == pzero);
+ assertTrue(pz == nzero);
+
+ assertTrue(nz == pz);
+ assertTrue(nz == nz);
+ assertTrue(nz == pzero);
+ assertTrue(nz == nzero);
+
+ assertTrue(pzero == pz);
+ assertTrue(pzero == nz);
+ assertTrue(pzero == pzero);
+ assertTrue(pzero == nzero);
+
+ assertTrue(nzero == pz);
+ assertTrue(nzero == nz);
+ assertTrue(nzero == pzero);
+ assertTrue(nzero == nzero);
+
+ // +-0 are distinct as Floats
+ assertEquals(Float.valueOf(pz), Float.valueOf(pz));
+ assertTrue(!Float.valueOf(pz).equals(Float.valueOf(nz)));
+ assertEquals(Float.valueOf(pz), Float.valueOf(pzero));
+ assertTrue(!Float.valueOf(pz).equals(Float.valueOf(nzero)));
+
+ assertTrue(!Float.valueOf(nz).equals(Float.valueOf(pz)));
+ assertEquals(Float.valueOf(nz), Float.valueOf(nz));
+ assertTrue(!Float.valueOf(nz).equals(Float.valueOf(pzero)));
+ assertEquals(Float.valueOf(nz), Float.valueOf(nzero));
+
+ assertEquals(Float.valueOf(pzero), Float.valueOf(pz));
+ assertTrue(!Float.valueOf(pzero).equals(Float.valueOf(nz)));
+ assertEquals(Float.valueOf(pzero), Float.valueOf(pzero));
+ assertTrue(!Float.valueOf(pzero).equals(Float.valueOf(nzero)));
+
+ assertTrue(!Float.valueOf(nzero).equals(Float.valueOf(pz)));
+ assertEquals(Float.valueOf(nzero), Float.valueOf(nz));
+ assertTrue(!Float.valueOf(nzero).equals(Float.valueOf(pzero)));
+ assertEquals(Float.valueOf(nzero), Float.valueOf(nzero));
+
+ // Nan's compare as equal
+ Float sqrtm2 = Float.valueOf((float) Math.sqrt(-2.0f));
+ Float sqrtm3 = Float.valueOf((float) Math.sqrt(-3.0f));
+ assertEquals(sqrtm2, sqrtm3);
+ }
+
+ public void testDouble() throws Exception {
+ double pz = 0.0;
+ double nz = -0.0;
+
+ double pzero = 1.0 / Double.POSITIVE_INFINITY;
+ double nzero = 1.0 / Double.NEGATIVE_INFINITY;
+
+ // Everything compares as '=='
+ assertTrue(pz == pz);
+ assertTrue(pz == nz);
+ assertTrue(pz == pzero);
+ assertTrue(pz == nzero);
+
+ assertTrue(nz == pz);
+ assertTrue(nz == nz);
+ assertTrue(nz == pzero);
+ assertTrue(nz == nzero);
+
+ assertTrue(pzero == pz);
+ assertTrue(pzero == nz);
+ assertTrue(pzero == pzero);
+ assertTrue(pzero == nzero);
+
+ assertTrue(nzero == pz);
+ assertTrue(nzero == nz);
+ assertTrue(nzero == pzero);
+ assertTrue(nzero == nzero);
+
+ // +-0 are distinct as Doubles
+ assertEquals(Double.valueOf(pz), Double.valueOf(pz));
+ assertTrue(!Double.valueOf(pz).equals(Double.valueOf(nz)));
+ assertEquals(Double.valueOf(pz), Double.valueOf(pzero));
+ assertTrue(!Double.valueOf(pz).equals(Double.valueOf(nzero)));
+
+ assertTrue(!Double.valueOf(nz).equals(Double.valueOf(pz)));
+ assertEquals(Double.valueOf(nz), Double.valueOf(nz));
+ assertTrue(!Double.valueOf(nz).equals(Double.valueOf(pzero)));
+ assertEquals(Double.valueOf(nz), Double.valueOf(nzero));
+
+ assertEquals(Double.valueOf(pzero), Double.valueOf(pz));
+ assertTrue(!Double.valueOf(pzero).equals(Double.valueOf(nz)));
+ assertEquals(Double.valueOf(pzero), Double.valueOf(pzero));
+ assertTrue(!Double.valueOf(pzero).equals(Double.valueOf(nzero)));
+
+ assertTrue(!Double.valueOf(nzero).equals(Double.valueOf(pz)));
+ assertEquals(Double.valueOf(nzero), Double.valueOf(nz));
+ assertTrue(!Double.valueOf(nzero).equals(Double.valueOf(pzero)));
+ assertEquals(Double.valueOf(nzero), Double.valueOf(nzero));
+
+ // Nan's compare as equal
+ Double sqrtm2 = Double.valueOf(Math.sqrt(-2.0));
+ Double sqrtm3 = Double.valueOf(Math.sqrt(-3.0));
+ assertEquals(sqrtm2, sqrtm3);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidInstanceofTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidInstanceofTest.java
new file mode 100644
index 0000000..ee97c23
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidInstanceofTest.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2006 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldAndroidInstanceofTest extends TestCase {
+
+ protected A mA;
+ protected ChildOfAOne mOne;
+ protected ChildOfAOne mTwo;
+ protected ChildOfAOne mThree;
+ protected ChildOfAOne mFour;
+ protected ChildOfAFive mFive;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mA = new A();
+ mOne = new ChildOfAOne();
+ mTwo = new ChildOfATwo();
+ mThree = new ChildOfAThree();
+ mFour = new ChildOfAFour();
+ mFive = new ChildOfAFive();
+ }
+
+
+ public void testNoInterface() throws Exception {
+ A a = mA;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_a should not be a ChildOfAFive", a instanceof ChildOfAFive);
+ }
+ }
+
+ public void testDerivedOne() throws Exception {
+ InterfaceOne one = mOne;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_one should not be a ChildOfAFive", one instanceof ChildOfAFive);
+ }
+ }
+
+ public void testDerivedTwo() throws Exception {
+ InterfaceTwo two = mTwo;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_two should not be a ChildOfAFive", two instanceof ChildOfAFive);
+ }
+ }
+
+ public void testDerivedThree() throws Exception {
+ InterfaceThree three = mThree;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_three should not be a ChildOfAFive", three instanceof ChildOfAFive);
+ }
+ }
+
+ public void testDerivedFour() throws Exception {
+ InterfaceFour four = mFour;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_four should not be a ChildOfAFive", four instanceof ChildOfAFive);
+ }
+ }
+
+ public void testSuccessClass() throws Exception {
+ ChildOfAOne five = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertTrue("m_five is suppose to be a ChildOfAFive", five instanceof ChildOfAFive);
+ }
+ }
+
+ public void testSuccessInterface() throws Exception {
+ ChildOfAFive five = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertTrue("m_five is suppose to be a InterfaceFour", five instanceof InterfaceFour);
+ }
+ }
+
+ public void testFailInterface() throws Exception {
+ InterfaceOne one = mFive;
+ for (int i = 0; i < 100000; i++) {
+ assertFalse("m_five does not implement InterfaceFive", one instanceof InterfaceFive);
+ }
+ }
+
+ private interface InterfaceOne {
+ }
+
+ private interface InterfaceTwo {
+ }
+
+ private interface InterfaceThree {
+ }
+
+ private interface InterfaceFour {
+ }
+
+ private interface InterfaceFive {
+ }
+
+ private static class A {
+ }
+
+ private static class ChildOfAOne extends A implements InterfaceOne, InterfaceTwo, InterfaceThree, InterfaceFour {
+ }
+
+ private static class ChildOfATwo extends ChildOfAOne {
+ }
+
+ private static class ChildOfAThree extends ChildOfATwo {
+ }
+
+ private static class ChildOfAFour extends ChildOfAThree {
+ }
+
+ private static class ChildOfAFive extends ChildOfAFour {
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidMathTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidMathTest.java
new file mode 100644
index 0000000..c18f2bd
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidMathTest.java
@@ -0,0 +1,653 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+public class OldAndroidMathTest extends TestCase {
+
+ private static final double HYP = Math.sqrt(2.0);
+
+ private static final double OPP = 1.0;
+
+ private static final double ADJ = 1.0;
+
+ /* Required to make previous preprocessor flags work - do not remove */
+ int unused = 0;
+
+ public static void assertEquals(String message, double expected, double actual, double delta) {
+ if (delta == 0D) {
+ Assert.assertEquals(message, expected, actual, Math.ulp(expected));
+ } else {
+ Assert.assertEquals(message, expected, actual, delta);
+ }
+ }
+
+ public static void assertEquals(String message, float expected, float actual, float delta) {
+ if (delta == 0F) {
+ Assert.assertEquals(message, expected, actual, Math.ulp(expected));
+ } else {
+ Assert.assertEquals(message, expected, actual, delta);
+ }
+ }
+
+ public void testAbsD() {
+ // Test for method double java.lang.Math.abs(double)
+
+ assertTrue("Incorrect double abs value",
+ (Math.abs(-1908.8976) == 1908.8976));
+ assertTrue("Incorrect double abs value",
+ (Math.abs(1908.8976) == 1908.8976));
+ }
+
+ public void testAbsF() {
+ // Test for method float java.lang.Math.abs(float)
+ assertTrue("Incorrect float abs value",
+ (Math.abs(-1908.8976f) == 1908.8976f));
+ assertTrue("Incorrect float abs value",
+ (Math.abs(1908.8976f) == 1908.8976f));
+ }
+
+ public void testAbsI() {
+ // Test for method int java.lang.Math.abs(int)
+ assertTrue("Incorrect int abs value", (Math.abs(-1908897) == 1908897));
+ assertTrue("Incorrect int abs value", (Math.abs(1908897) == 1908897));
+ }
+
+ public void testAbsJ() {
+ // Test for method long java.lang.Math.abs(long)
+ assertTrue("Incorrect long abs value",
+ (Math.abs(-19088976000089L) == 19088976000089L));
+ assertTrue("Incorrect long abs value",
+ (Math.abs(19088976000089L) == 19088976000089L));
+ }
+
+ public void testAcosD() {
+ // Test for method double java.lang.Math.acos(double)
+ double r = Math.cos(Math.acos(ADJ / HYP));
+ long lr = Double.doubleToLongBits(r);
+ long t = Double.doubleToLongBits(ADJ / HYP);
+ assertTrue("Returned incorrect arc cosine", lr == t || (lr + 1) == t
+ || (lr - 1) == t);
+ }
+
+ public void testAsinD() {
+ // Test for method double java.lang.Math.asin(double)
+ double r = Math.sin(Math.asin(OPP / HYP));
+ long lr = Double.doubleToLongBits(r);
+ long t = Double.doubleToLongBits(OPP / HYP);
+ assertTrue("Returned incorrect arc sine", lr == t || (lr + 1) == t
+ || (lr - 1) == t);
+ }
+
+ public void testAtanD() {
+ // Test for method double java.lang.Math.atan(double)
+ double answer = Math.tan(Math.atan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ public void testAtan2DD() {
+ // Test for method double java.lang.Math.atan2(double, double)
+ double answer = Math.atan(Math.tan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ public void testCbrtD() {
+ //Test for special situations
+ assertTrue("Should return Double.NaN", Double.isNaN(Math
+ .cbrt(Double.NaN)));
+ assertEquals("Should return Double.POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math
+ .cbrt(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return Double.NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, Math
+ .cbrt(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .cbrt(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double.doubleToLongBits(Math
+ .cbrt(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(Math
+ .cbrt(-0.0)));
+
+ assertEquals("Should return 3.0", 3.0, Math.cbrt(27.0), 0D);
+ assertEquals("Should return 23.111993172558684", 23.111993172558684,
+ Math.cbrt(12345.6), 0D);
+ assertEquals("Should return 5.643803094122362E102",
+ 5.643803094122362E102, Math.cbrt(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 0.01", 0.01, Math.cbrt(0.000001), 0D);
+
+ assertEquals("Should return -3.0", -3.0, Math.cbrt(-27.0), 0D);
+ assertEquals("Should return -23.111993172558684", -23.111993172558684,
+ Math.cbrt(-12345.6), 0D);
+ assertEquals("Should return 1.7031839360032603E-108",
+ 1.7031839360032603E-108, Math.cbrt(Double.MIN_VALUE), 0D);
+ assertEquals("Should return -0.01", -0.01, Math.cbrt(-0.000001), 0D);
+ }
+
+ public void testCeilD() {
+ // Test for method double java.lang.Math.ceil(double)
+ assertEquals("Incorrect ceiling for double",
+ 79, Math.ceil(78.89), 0);
+ assertEquals("Incorrect ceiling for double",
+ -78, Math.ceil(-78.89), 0);
+ }
+
+ public void testCosD() {
+ // Test for method double java.lang.Math.cos(double)
+ assertEquals("Incorrect answer", 1.0, Math.cos(0), 0D);
+ assertEquals("Incorrect answer", 0.5403023058681398, Math.cos(1), 0D);
+ }
+
+ public void testCoshD() {
+ // Test for special situations
+ assertTrue(Double.isNaN(Math.cosh(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.cosh(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.cosh(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Should return 1.0", 1.0, Math.cosh(+0.0), 0D);
+ assertEquals("Should return 1.0", 1.0, Math.cosh(-0.0), 0D);
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.cosh(1234.56), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.cosh(-1234.56), 0D);
+ assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
+ .cosh(0.000001), 0D);
+ assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
+ .cosh(-0.000001), 0D);
+ assertEquals("Should return 5.212214351945598", 5.212214351945598, Math
+ .cosh(2.33482), 0D);
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.cosh(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 1.0", 1.0, Math.cosh(Double.MIN_VALUE), 0D);
+ }
+
+ public void testExpD() {
+ // Test for method double java.lang.Math.exp(double)
+ assertTrue("Incorrect answer returned for simple power", Math.abs(Math
+ .exp(4D)
+ - Math.E * Math.E * Math.E * Math.E) < 0.1D);
+ assertTrue("Incorrect answer returned for larger power", Math.log(Math
+ .abs(Math.exp(5.5D)) - 5.5D) < 10.0D);
+ }
+
+ public void testExpm1D() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(Math.expm1(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return -1.0", -1.0, Math
+ .expm1(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .expm1(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(Math.expm1(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(Math.expm1(-0.0)));
+
+ assertEquals("Should return -9.999950000166666E-6",
+ -9.999950000166666E-6, Math.expm1(-0.00001), 0D);
+ assertEquals("Should return 1.0145103074469635E60",
+ 1.0145103074469635E60, Math.expm1(138.16951162), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math
+ .expm1(123456789123456789123456789.4521584223), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.expm1(Double.MAX_VALUE), 0D);
+ assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, Math
+ .expm1(Double.MIN_VALUE), 0D);
+ }
+
+ public void testFloorD() {
+ // Test for method double java.lang.Math.floor(double)
+ assertEquals("Incorrect floor for double",
+ 78, Math.floor(78.89), 0);
+ assertEquals("Incorrect floor for double",
+ -79, Math.floor(-78.89), 0);
+ }
+
+ public void testHypotDD() {
+ // Test for special cases
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
+ 1.0), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
+ 123.324), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(-758.2587,
+ Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(5687.21,
+ Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
+ Double.POSITIVE_INFINITY), 0D);
+ assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN,
+ 2342301.89843)));
+ assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680,
+ Double.NaN)));
+
+ assertEquals("Should return 2396424.905416697", 2396424.905416697, Math
+ .hypot(12322.12, -2396393.2258), 0D);
+ assertEquals("Should return 138.16958070558556", 138.16958070558556,
+ Math.hypot(-138.16951162, 0.13817035864), 0D);
+ assertEquals("Should return 1.7976931348623157E308",
+ 1.7976931348623157E308, Math.hypot(Double.MAX_VALUE, 211370.35), 0D);
+ assertEquals("Should return 5413.7185", 5413.7185, Math.hypot(
+ -5413.7185, Double.MIN_VALUE), 0D);
+ }
+
+ public void testIEEEremainderDD() {
+ // Test for method double java.lang.Math.IEEEremainder(double, double)
+ assertEquals("Incorrect remainder returned",
+ 0.0, Math.IEEEremainder(1.0, 1.0), 0D);
+ assertTrue("Incorrect remainder returned", Math.IEEEremainder(1.32,
+ 89.765) >= 1.4705063220631647E-2
+ || Math.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
+ }
+
+ public void testLogD() {
+ // Test for method double java.lang.Math.log(double)
+ for (double d = 10; d >= -10; d -= 0.5) {
+ double answer = Math.log(Math.exp(d));
+ assertTrue("Answer does not equal expected answer for d = " + d
+ + " answer = " + answer, Math.abs(answer - d) <= Math
+ .abs(d * 0.00000001));
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ public void testLog10D() {
+ // Test for special cases
+ assertTrue(Double.isNaN(Math.log10(Double.NaN)));
+ assertTrue(Double.isNaN(Math.log10(-2541.05745687234187532)));
+ assertTrue(Double.isNaN(Math.log10(-0.1)));
+ assertEquals(Double.POSITIVE_INFINITY, Math.log10(Double.POSITIVE_INFINITY));
+ assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0));
+ assertEquals(Double.NEGATIVE_INFINITY, Math.log10(+0.0));
+ assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0));
+
+ assertEquals(3.0, Math.log10(1000.0));
+ assertEquals(14.0, Math.log10(Math.pow(10, 14)));
+ assertEquals(3.7389561269540406, Math.log10(5482.2158));
+ assertEquals(14.661551142893833, Math.log10(458723662312872.125782332587));
+ assertEquals(-0.9083828622192334, Math.log10(0.12348583358871));
+ assertEquals(308.25471555991675, Math.log10(Double.MAX_VALUE));
+ assertEquals(-323.3062153431158, Math.log10(Double.MIN_VALUE));
+ }
+
+ public void testLog1pD() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN)));
+ assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .log1p(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(Math.log1p(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(Math.log1p(-0.0)));
+
+ assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
+ Math.log1p(-0.254856327), 0D);
+ assertEquals("Should return 7.368050685564151", 7.368050685564151, Math
+ .log1p(1583.542), 0D);
+ assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
+ Math.log1p(0.5894227), 0D);
+ assertEquals("Should return 709.782712893384", 709.782712893384, Math
+ .log1p(Double.MAX_VALUE), 0D);
+ assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, Math
+ .log1p(Double.MIN_VALUE), 0D);
+ }
+
+ public void testMaxDD() {
+ // Test for method double java.lang.Math.max(double, double)
+ assertEquals("Incorrect double max value", 1908897.6000089, Math.max(-1908897.6000089,
+ 1908897.6000089), 0D);
+ assertEquals("Incorrect double max value",
+ 1908897.6000089, Math.max(2.0, 1908897.6000089), 0D);
+ assertEquals("Incorrect double max value", -2.0, Math.max(-2.0,
+ -1908897.6000089), 0D);
+
+ }
+
+ public void testMaxFF() {
+ // Test for method float java.lang.Math.max(float, float)
+ assertTrue("Incorrect float max value", Math.max(-1908897.600f,
+ 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value",
+ Math.max(2.0f, 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value",
+ Math.max(-2.0f, -1908897.600f) == -2.0f);
+ }
+
+ public void testMaxII() {
+ // Test for method int java.lang.Math.max(int, int)
+ assertEquals("Incorrect int max value",
+ 19088976, Math.max(-19088976, 19088976));
+ assertEquals("Incorrect int max value",
+ 19088976, Math.max(20, 19088976));
+ assertEquals("Incorrect int max value", -20, Math.max(-20, -19088976));
+ }
+
+ public void testMaxJJ() {
+ // Test for method long java.lang.Math.max(long, long)
+ assertEquals("Incorrect long max value", 19088976000089L, Math.max(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long max value",
+ 19088976000089L, Math.max(20, 19088976000089L));
+ assertEquals("Incorrect long max value",
+ -20, Math.max(-20, -19088976000089L));
+ }
+
+ public void testMinDD() {
+ // Test for method double java.lang.Math.min(double, double)
+ assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-1908897.6000089,
+ 1908897.6000089), 0D);
+ assertEquals("Incorrect double min value",
+ 2.0, Math.min(2.0, 1908897.6000089), 0D);
+ assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-2.0,
+ -1908897.6000089), 0D);
+ }
+
+ public void testMinFF() {
+ // Test for method float java.lang.Math.min(float, float)
+ assertTrue("Incorrect float min value", Math.min(-1908897.600f,
+ 1908897.600f) == -1908897.600f);
+ assertTrue("Incorrect float min value",
+ Math.min(2.0f, 1908897.600f) == 2.0f);
+ assertTrue("Incorrect float min value",
+ Math.min(-2.0f, -1908897.600f) == -1908897.600f);
+ }
+
+ public void testMinII() {
+ // Test for method int java.lang.Math.min(int, int)
+ assertEquals("Incorrect int min value",
+ -19088976, Math.min(-19088976, 19088976));
+ assertEquals("Incorrect int min value", 20, Math.min(20, 19088976));
+ assertEquals("Incorrect int min value",
+ -19088976, Math.min(-20, -19088976));
+
+ }
+
+ public void testMinJJ() {
+ // Test for method long java.lang.Math.min(long, long)
+ assertEquals("Incorrect long min value", -19088976000089L, Math.min(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long min value",
+ 20, Math.min(20, 19088976000089L));
+ assertEquals("Incorrect long min value",
+ -19088976000089L, Math.min(-20, -19088976000089L));
+ }
+
+ public void testPowDD() {
+ // Test for method double java.lang.Math.pow(double, double)
+ assertTrue("pow returned incorrect value",
+ (long) Math.pow(2, 8) == 256l);
+ assertTrue("pow returned incorrect value",
+ Math.pow(2, -8) == 0.00390625d);
+ assertEquals("Incorrect root returned1",
+ 2, Math.sqrt(Math.pow(Math.sqrt(2), 4)), 0);
+ }
+
+ public void testRintD() {
+ // Test for method double java.lang.Math.rint(double)
+ assertEquals("Failed to round properly - up to odd",
+ 3.0, Math.rint(2.9), 0D);
+ assertTrue("Failed to round properly - NaN", Double.isNaN(Math
+ .rint(Double.NaN)));
+ assertEquals("Failed to round properly down to even",
+ 2.0, Math.rint(2.1), 0D);
+ assertTrue("Failed to round properly " + 2.5 + " to even", Math
+ .rint(2.5) == 2.0);
+ }
+
+ public void testRoundD() {
+ // Test for method long java.lang.Math.round(double)
+ assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89d));
+ }
+
+ public void testRoundF() {
+ // Test for method int java.lang.Math.round(float)
+ assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f));
+ }
+
+ public void testSignumD() {
+ assertTrue(Double.isNaN(Math.signum(Double.NaN)));
+ assertTrue(Double.isNaN(Math.signum(Double.NaN)));
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .signum(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(Math.signum(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(Math.signum(-0.0)));
+
+ assertEquals(1.0, Math.signum(253681.2187962), 0D);
+ assertEquals(-1.0, Math.signum(-125874693.56), 0D);
+ assertEquals(1.0, Math.signum(1.2587E-308), 0D);
+ assertEquals(-1.0, Math.signum(-1.2587E-308), 0D);
+
+ assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D);
+ assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D);
+ assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D);
+ assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D);
+ assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D);
+ assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D);
+ }
+
+ public void testSignumF() {
+ assertTrue(Float.isNaN(Math.signum(Float.NaN)));
+ assertEquals(Float.floatToIntBits(0.0f), Float
+ .floatToIntBits(Math.signum(0.0f)));
+ assertEquals(Float.floatToIntBits(+0.0f), Float
+ .floatToIntBits(Math.signum(+0.0f)));
+ assertEquals(Float.floatToIntBits(-0.0f), Float
+ .floatToIntBits(Math.signum(-0.0f)));
+
+ assertEquals(1.0f, Math.signum(253681.2187962f), 0f);
+ assertEquals(-1.0f, Math.signum(-125874693.56f), 0f);
+ assertEquals(1.0f, Math.signum(1.2587E-11f), 0f);
+ assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f);
+
+ assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f);
+ assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f);
+ assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f);
+ assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f);
+ assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f);
+ assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f);
+ }
+
+ public void testSinD() {
+ // Test for method double java.lang.Math.sin(double)
+ assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D);
+ assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D);
+ }
+
+ public void testSinhD() {
+ // Test for special situations
+ assertTrue("Should return NaN", Double.isNaN(Math.sinh(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.sinh(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, Math.sinh(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .sinh(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(Math.sinh(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(Math.sinh(-0.0)));
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.sinh(1234.56), 0D);
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, Math.sinh(-1234.56), 0D);
+ assertEquals("Should return 1.0000000000001666E-6",
+ 1.0000000000001666E-6, Math.sinh(0.000001), 0D);
+ assertEquals("Should return -1.0000000000001666E-6",
+ -1.0000000000001666E-6, Math.sinh(-0.000001), 0D);
+ assertEquals("Should return 5.115386441963859", 5.115386441963859, Math
+ .sinh(2.33482), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, Math.sinh(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 4.9E-324", 4.9E-324, Math
+ .sinh(Double.MIN_VALUE), 0D);
+ }
+
+ public void testSqrtD() {
+ // Test for method double java.lang.Math.sqrt(double)
+ assertEquals("Incorrect root returned2", 7, Math.sqrt(49), 0);
+ }
+
+ public void testTanD() {
+ // Test for method double java.lang.Math.tan(double)
+ assertEquals("Incorrect answer", 0.0, Math.tan(0), 0D);
+ assertEquals("Incorrect answer", 1.5574077246549023, Math.tan(1), 0D);
+
+ }
+
+ public void testTanhD() {
+ // Test for special situations
+ assertTrue("Should return NaN", Double.isNaN(Math.tanh(Double.NaN)));
+ assertEquals("Should return +1.0", +1.0, Math
+ .tanh(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return -1.0", -1.0, Math
+ .tanh(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
+ .tanh(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(Math.tanh(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(Math.tanh(-0.0)));
+
+ assertEquals("Should return 1.0", 1.0, Math.tanh(1234.56), 0D);
+ assertEquals("Should return -1.0", -1.0, Math.tanh(-1234.56), 0D);
+ assertEquals("Should return 9.999999999996666E-7",
+ 9.999999999996666E-7, Math.tanh(0.000001), 0D);
+ assertEquals("Should return 0.981422884124941", 0.981422884124941, Math
+ .tanh(2.33482), 0D);
+ assertEquals("Should return 1.0", 1.0, Math.tanh(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 4.9E-324", 4.9E-324, Math
+ .tanh(Double.MIN_VALUE), 0D);
+ }
+
+ public void testRandom() {
+ // There isn't a place for these tests so just stick them here
+ assertEquals("Wrong value E",
+ 4613303445314885481L, Double.doubleToLongBits(Math.E));
+ assertEquals("Wrong value PI",
+ 4614256656552045848L, Double.doubleToLongBits(Math.PI));
+
+ for (int i = 500; i >= 0; i--) {
+ double d = Math.random();
+ assertTrue("Generated number is out of range: " + d, d >= 0.0
+ && d < 1.0);
+ }
+ }
+
+ public void testToRadiansD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = Math.toDegrees(Math.toRadians(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ public void testToDegreesD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = Math.toRadians(Math.toDegrees(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ public void testUlpD() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN)));
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
+ .ulp(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
+ .ulp(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(+0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(-0.0), 0D);
+ assertEquals("Returned incorrect value", Math.pow(2, 971), Math
+ .ulp(Double.MAX_VALUE), 0D);
+ assertEquals("Returned incorrect value", Math.pow(2, 971), Math
+ .ulp(-Double.MAX_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(Double.MIN_VALUE), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
+ .ulp(-Double.MIN_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
+ .ulp(1.0), 0D);
+ assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
+ .ulp(-1.0), 0D);
+ assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math
+ .ulp(1153.0), 0D);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testUlpf() {
+ // Test for special cases
+ assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN)));
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
+ .ulp(Float.POSITIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
+ .ulp(Float.NEGATIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(+0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
+ .ulp(-0.0f), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, Math
+ .ulp(Float.MAX_VALUE), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, Math
+ .ulp(-Float.MAX_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.4E-45f, Math
+ .ulp(Float.MIN_VALUE), 0f);
+ assertEquals("Returned incorrect value", 1.4E-45f, Math
+ .ulp(-Float.MIN_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f),
+ 0f);
+ assertEquals("Returned incorrect value", 1.1920929E-7f,
+ Math.ulp(-1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.2207031E-4f, Math
+ .ulp(1153.0f), 0f);
+ assertEquals("Returned incorrect value", 5.6E-45f, Math
+ .ulp(9.403954E-38f), 0f);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidMonitorTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidMonitorTest.java
new file mode 100644
index 0000000..d1704fb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidMonitorTest.java
@@ -0,0 +1,464 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldAndroidMonitorTest extends TestCase {
+
+ public void testWaitArgumentsTest() throws Exception {
+ /* Try some valid arguments. These should all
+ * return very quickly.
+ */
+ try {
+ synchronized (this) {
+ /* millisecond version */
+ wait(1);
+ wait(10);
+
+ /* millisecond + nanosecond version */
+ wait(0, 1);
+ wait(0, 999999);
+ wait(1, 1);
+ wait(1, 999999);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("good Object.wait() interrupted",
+ ex);
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with good arguments", ex);
+ }
+
+ /* Try some invalid arguments.
+ */
+ boolean sawException = false;
+ try {
+ synchronized (this) {
+ wait(-1);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+
+ sawException = false;
+ try {
+ synchronized (this) {
+ wait(0, -1);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+
+ sawException = false;
+ try {
+ synchronized (this) {
+ /* The legal range of nanos is 0-999999. */
+ wait(0, 1000000);
+ }
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("bad Object.wait() interrupted", ex);
+ } catch (IllegalArgumentException ex) {
+ sawException = true;
+ } catch (Exception ex) {
+ throw new RuntimeException("Unexpected exception when calling" +
+ "Object.wait() with bad arguments", ex);
+ }
+ if (!sawException) {
+ throw new RuntimeException("bad call to Object.wait() should " +
+ "have thrown IllegalArgumentException");
+ }
+ }
+
+ private class Interrupter extends Thread {
+ Waiter waiter;
+
+ Interrupter(String name, Waiter waiter) {
+ super(name);
+ this.waiter = waiter;
+ }
+
+ public void run() {
+ try {
+ run_inner();
+ } catch (Throwable t) {
+ OldAndroidMonitorTest.errorException = t;
+ OldAndroidMonitorTest.testThread.interrupt();
+ }
+ }
+
+ void run_inner() {
+ waiter.spin = true;
+ // System.out.println("InterruptTest: starting waiter");
+ waiter.start();
+
+ try {
+ Thread.currentThread().sleep(500);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test sleep interrupted.", ex);
+ }
+
+ /* Waiter is spinning, and its monitor should still be thin.
+ */
+ // System.out.println("Test interrupting waiter");
+ waiter.interrupt();
+ waiter.spin = false;
+
+ for (int i = 0; i < 3; i++) {
+ /* Wait for the waiter to start waiting.
+ */
+ synchronized (waiter.interrupterLock) {
+ try {
+ waiter.interrupterLock.wait();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test wait interrupted.", ex);
+ }
+ }
+
+ /* Before interrupting, grab the waiter lock, which
+ * guarantees that the waiter is already sitting in wait().
+ */
+ synchronized (waiter) {
+ //System.out.println("Test interrupting waiter (" + i + ")");
+ waiter.interrupt();
+ }
+ }
+
+ // System.out.println("Test waiting for waiter to die.");
+ try {
+ waiter.join();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test join interrupted.", ex);
+ }
+ // System.out.println("InterruptTest done.");
+ }
+ }
+
+ private class Waiter extends Thread {
+ Object interrupterLock = new Object();
+ Boolean spin = false;
+
+ Waiter(String name) {
+ super(name);
+ }
+
+ public void run() {
+ try {
+ run_inner();
+ } catch (Throwable t) {
+ OldAndroidMonitorTest.errorException = t;
+ OldAndroidMonitorTest.testThread.interrupt();
+ }
+ }
+
+ void run_inner() {
+ // System.out.println("Waiter spinning");
+ while (spin) {
+ // We're going to get interrupted while we spin.
+ }
+ if (interrupted()) {
+ // System.out.println("Waiter done spinning; interrupted.");
+ } else {
+ throw new RuntimeException("Thread not interrupted " +
+ "during spin");
+ }
+
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait()");
+ this.wait();
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(): Waiter caught " + ex);
+ }
+ // System.out.println("wait() finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait()");
+ }
+ }
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait(1000)");
+ this.wait(1000);
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(1000): Waiter caught " + ex);
+ }
+ // System.out.println("wait(1000) finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait(1000)");
+ }
+ }
+ synchronized (this) {
+ Boolean sawEx = false;
+
+ try {
+ synchronized (interrupterLock) {
+ interrupterLock.notify();
+ }
+ // System.out.println("Waiter calling wait(1000, 5000)");
+ this.wait(1000, 5000);
+ } catch (InterruptedException ex) {
+ sawEx = true;
+ // System.out.println("wait(1000, 5000): Waiter caught " + ex);
+ }
+ // System.out.println("wait(1000, 5000) finished");
+
+ if (!sawEx) {
+ throw new RuntimeException("Thread not interrupted " +
+ "during wait(1000, 5000)");
+ }
+ }
+
+ // System.out.println("Waiter returning");
+ }
+ }
+
+ private static Throwable errorException;
+ private static Thread testThread;
+
+ // TODO: Flaky test. Add back MediumTest annotation once fixed
+ public void testInterruptTest() throws Exception {
+
+
+ testThread = Thread.currentThread();
+ errorException = null;
+
+ Waiter waiter = new Waiter("InterruptTest Waiter");
+ Interrupter interrupter =
+ new Interrupter("InterruptTest Interrupter", waiter);
+ interrupter.start();
+
+ try {
+ interrupter.join();
+ waiter.join();
+ } catch (InterruptedException ex) {
+ throw new RuntimeException("Test join interrupted.", ex);
+ }
+
+ if (errorException != null) {
+ throw new RuntimeException("InterruptTest failed",
+ errorException);
+ }
+
+
+
+
+ }
+
+ private static void deepWait(int depth, Object lock) {
+ synchronized (lock) {
+ if (depth > 0) {
+ deepWait(depth - 1, lock);
+ } else {
+ String threadName = Thread.currentThread().getName();
+ try {
+ // System.out.println(threadName + " waiting");
+ lock.wait();
+ // System.out.println(threadName + " done waiting");
+ } catch (InterruptedException ex) {
+ // System.out.println(threadName + " interrupted.");
+ }
+ }
+ }
+ }
+
+ private class Worker extends Thread {
+ Object lock;
+ int id;
+
+ Worker(int id, Object lock) {
+ super("Worker(" + id + ")");
+ this.id = id;
+ this.lock = lock;
+ }
+
+ public void run() {
+ int iterations = 0;
+
+ while (OldAndroidMonitorTest.running) {
+ OldAndroidMonitorTest.deepWait(id, lock);
+ iterations++;
+ }
+ // System.out.println(getName() + " done after " + iterations + " iterations.");
+ }
+ }
+
+ private static Object commonLock = new Object();
+ private static Boolean running = false;
+
+
+ public void testNestedMonitors() throws Exception {
+ final int NUM_WORKERS = 5;
+
+ Worker w[] = new Worker[NUM_WORKERS];
+ int i;
+
+ for (i = 0; i < NUM_WORKERS; i++) {
+ w[i] = new Worker(i * 2 - 1, new Object());
+ }
+
+ running = true;
+
+ // System.out.println("NestedMonitors: starting workers");
+ for (i = 0; i < NUM_WORKERS; i++) {
+ w[i].start();
+ }
+
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException ex) {
+ // System.out.println("Test sleep interrupted.");
+ }
+
+ for (i = 0; i < 100; i++) {
+ for (int j = 0; j < NUM_WORKERS; j++) {
+ synchronized (w[j].lock) {
+ w[j].lock.notify();
+ }
+ }
+ }
+
+ // System.out.println("NesterMonitors: stopping workers");
+ running = false;
+ for (i = 0; i < NUM_WORKERS; i++) {
+ synchronized (w[i].lock) {
+ w[i].lock.notifyAll();
+ }
+ }
+ }
+
+ private static class CompareAndExchange extends Thread {
+ static Object toggleLock = null;
+ static int toggle = -1;
+ static Boolean running = false;
+
+ public void run() {
+ toggleLock = new Object();
+ toggle = -1;
+
+ Worker w1 = new Worker(0, 1);
+ Worker w2 = new Worker(2, 3);
+ Worker w3 = new Worker(4, 5);
+ Worker w4 = new Worker(6, 7);
+
+ running = true;
+
+ // System.out.println("CompareAndExchange: starting workers");
+
+ w1.start();
+ w2.start();
+ w3.start();
+ w4.start();
+
+ try {
+ this.sleep(10000);
+ } catch (InterruptedException ex) {
+ // System.out.println(getName() + " interrupted.");
+ }
+
+ // System.out.println("MonitorTest: stopping workers");
+ running = false;
+
+ toggleLock = null;
+ }
+
+ class Worker extends Thread {
+ int i1;
+ int i2;
+
+ Worker(int i1, int i2) {
+ super("Worker(" + i1 + ", " + i2 + ")");
+ this.i1 = i1;
+ this.i2 = i2;
+ }
+
+ public void run() {
+ int iterations = 0;
+
+ /* Latch this because run() may set the static field to
+ * null at some point.
+ */
+ Object toggleLock = CompareAndExchange.toggleLock;
+
+ // System.out.println(getName() + " running");
+ try {
+ while (CompareAndExchange.running) {
+ synchronized (toggleLock) {
+ int test;
+ int check;
+
+ if (CompareAndExchange.toggle == i1) {
+ this.sleep(5 + i2);
+ CompareAndExchange.toggle = test = i2;
+ } else {
+ this.sleep(5 + i1);
+ CompareAndExchange.toggle = test = i1;
+ }
+ if ((check = CompareAndExchange.toggle) != test) {
+// System.out.println("Worker(" + i1 + ", " +
+// i2 + ") " + "test " + test +
+// " != toggle " + check);
+ throw new RuntimeException(
+ "locked value changed");
+ }
+ }
+
+ iterations++;
+ }
+ } catch (InterruptedException ex) {
+ // System.out.println(getName() + " interrupted.");
+ }
+
+// System.out.println(getName() + " done after " +
+// iterations + " iterations.");
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidParseIntTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidParseIntTest.java
new file mode 100644
index 0000000..08351d6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidParseIntTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for functionality of class Integer to parse integers.
+ */
+public class OldAndroidParseIntTest extends TestCase {
+
+ public void testParseInt() throws Exception {
+ assertEquals(0, Integer.parseInt("0", 10));
+ assertEquals(473, Integer.parseInt("473", 10));
+ assertEquals(0, Integer.parseInt("-0", 10));
+ assertEquals(-255, Integer.parseInt("-FF", 16));
+ assertEquals(102, Integer.parseInt("1100110", 2));
+ assertEquals(2147483647, Integer.parseInt("2147483647", 10));
+ assertEquals(-2147483648, Integer.parseInt("-2147483648", 10));
+
+ try {
+ Integer.parseInt("2147483648", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("-2147483649", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ // One digit too many
+ try {
+ Integer.parseInt("21474836470", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("-21474836480", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("21474836471", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("-21474836481", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("214748364710", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("-214748364811", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("99", 8);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ try {
+ Integer.parseInt("Kona", 10);
+ fail();
+ } catch (NumberFormatException e) {
+ // ok
+ }
+
+ assertEquals(411787, Integer.parseInt("Kona", 27));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldAndroidStrictMathTest.java b/luni/src/test/java/libcore/java/lang/OldAndroidStrictMathTest.java
new file mode 100644
index 0000000..aa603ba
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldAndroidStrictMathTest.java
@@ -0,0 +1,677 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldAndroidStrictMathTest extends TestCase {
+
+ private final double HYP = StrictMath.sqrt(2.0);
+
+ private final double OPP = 1.0;
+
+ private final double ADJ = 1.0;
+
+ /* Required to make previous preprocessor flags work - do not remove */
+ int unused = 0;
+
+ public void testAbsD() {
+ // Test for method double java.lang.StrictMath.abs(double)
+
+ assertTrue("Incorrect double abs value",
+ (StrictMath.abs(-1908.8976) == 1908.8976));
+ assertTrue("Incorrect double abs value",
+ (StrictMath.abs(1908.8976) == 1908.8976));
+ }
+
+ public void testAbsF() {
+ // Test for method float java.lang.StrictMath.abs(float)
+ assertTrue("Incorrect float abs value",
+ (StrictMath.abs(-1908.8976f) == 1908.8976f));
+ assertTrue("Incorrect float abs value",
+ (StrictMath.abs(1908.8976f) == 1908.8976f));
+ }
+
+ public void testAbsI() {
+ // Test for method int java.lang.StrictMath.abs(int)
+ assertTrue("Incorrect int abs value",
+ (StrictMath.abs(-1908897) == 1908897));
+ assertTrue("Incorrect int abs value",
+ (StrictMath.abs(1908897) == 1908897));
+ }
+
+ public void testAbsJ() {
+ // Test for method long java.lang.StrictMath.abs(long)
+ assertTrue("Incorrect long abs value", (StrictMath
+ .abs(-19088976000089L) == 19088976000089L));
+ assertTrue("Incorrect long abs value",
+ (StrictMath.abs(19088976000089L) == 19088976000089L));
+ }
+
+ public void testAcosD() {
+ // Test for method double java.lang.StrictMath.acos(double)
+ assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
+ .acos(ADJ / HYP)) == ADJ / HYP);
+ }
+
+ public void testAsinD() {
+ // Test for method double java.lang.StrictMath.asin(double)
+ assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
+ .asin(OPP / HYP)) == OPP / HYP);
+ }
+
+ public void testAtanD() {
+ // Test for method double java.lang.StrictMath.atan(double)
+ double answer = StrictMath.tan(StrictMath.atan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ public void testAtan2DD() {
+ // Test for method double java.lang.StrictMath.atan2(double, double)
+ double answer = StrictMath.atan(StrictMath.tan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testCbrtD() {
+ // Test for special situations
+ assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
+ .cbrt(Double.NaN)));
+ assertEquals("Should return Double.POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .cbrt(Double.POSITIVE_INFINITY));
+ assertEquals("Should return Double.NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath
+ .cbrt(Double.NEGATIVE_INFINITY));
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.cbrt(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.cbrt(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.cbrt(-0.0)));
+
+ assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0));
+ assertEquals("Should return 23.111993172558684", 23.111993172558684,
+ StrictMath.cbrt(12345.6));
+ assertEquals("Should return 5.643803094122362E102",
+ 5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE));
+ assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001));
+
+ assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0));
+ assertEquals("Should return -23.111993172558684", -23.111993172558684,
+ StrictMath.cbrt(-12345.6));
+ assertEquals("Should return 1.7031839360032603E-108",
+ 1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE));
+ assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001));
+
+ try {
+ StrictMath.cbrt((Double) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ //expected
+ }
+ }
+
+ public void testCeilD() {
+ // Test for method double java.lang.StrictMath.ceil(double)
+ assertEquals("Incorrect ceiling for double",
+ 79, StrictMath.ceil(78.89), 0.0);
+ assertEquals("Incorrect ceiling for double",
+ -78, StrictMath.ceil(-78.89), 0.0);
+ }
+
+ public void testCosD() {
+ // Test for method double java.lang.StrictMath.cos(double)
+
+ assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
+ .acos(ADJ / HYP)) == ADJ / HYP);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testCosh_D() {
+ // Test for special situations
+ assertTrue("Should return NaN", Double.isNaN(StrictMath
+ .cosh(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .cosh(Double.POSITIVE_INFINITY));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .cosh(Double.NEGATIVE_INFINITY));
+ assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0));
+ assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0));
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56));
+ assertEquals("Should return 1.0000000000005", 1.0000000000005,
+ StrictMath.cosh(0.000001));
+ assertEquals("Should return 1.0000000000005", 1.0000000000005,
+ StrictMath.cosh(-0.000001));
+ assertEquals("Should return 5.212214351945598", 5.212214351945598,
+ StrictMath.cosh(2.33482));
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE));
+ assertEquals("Should return 1.0", 1.0, StrictMath
+ .cosh(Double.MIN_VALUE));
+ }
+
+ public void testExpD() {
+ // Test for method double java.lang.StrictMath.exp(double)
+ assertTrue("Incorrect answer returned for simple power", StrictMath
+ .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
+ * StrictMath.E * StrictMath.E) < 0.1D);
+ assertTrue("Incorrect answer returned for larger power", StrictMath
+ .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testExpm1D() {
+ //Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY));
+ assertEquals("Should return -1.0", -1.0, StrictMath
+ .expm1(Double.NEGATIVE_INFINITY));
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.expm1(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.expm1(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.expm1(-0.0)));
+
+ assertEquals("Should return -9.999950000166666E-6",
+ -9.999950000166666E-6, StrictMath.expm1(-0.00001));
+ assertEquals("Should return 1.0145103074469635E60",
+ 1.0145103074469635E60, StrictMath.expm1(138.16951162));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .expm1(123456789123456789123456789.4521584223));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE));
+ assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath
+ .expm1(Double.MIN_VALUE));
+
+ }
+
+ public void testFloorD() {
+ // Test for method double java.lang.StrictMath.floor(double)
+ assertEquals("Incorrect floor for double",
+ 78, StrictMath.floor(78.89), 0.0);
+ assertEquals("Incorrect floor for double",
+ -79, StrictMath.floor(-78.89), 0.0);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testHypotDD() {
+ // Test for special cases
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
+ 1.0));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
+ 123.324));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587,
+ Double.POSITIVE_INFINITY));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21,
+ Double.NEGATIVE_INFINITY));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
+ Double.NEGATIVE_INFINITY));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
+ Double.POSITIVE_INFINITY));
+ assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(Double.NaN,
+ 2342301.89843)));
+ assertTrue("Should return NaN", Double.isNaN(StrictMath.hypot(-345.2680,
+ Double.NaN)));
+
+ assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath
+ .hypot(12322.12, -2396393.2258));
+ assertEquals("Should return 138.16958070558556", 138.16958070558556,
+ StrictMath.hypot(-138.16951162, 0.13817035864));
+ assertEquals("Should return 1.7976931348623157E308",
+ 1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35));
+ assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot(
+ -5413.7185, Double.MIN_VALUE));
+
+ }
+
+ public void testIEEEremainderDD() {
+ // Test for method double java.lang.StrictMath.IEEEremainder(double,
+ // double)
+ assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
+ 1.0, 1.0), 0.0);
+ assertTrue(
+ "Incorrect remainder returned",
+ StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
+ || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
+ }
+
+ public void testLogD() {
+ // Test for method double java.lang.StrictMath.log(double)
+ for (double d = 10; d >= -10; d -= 0.5) {
+ double answer = StrictMath.log(StrictMath.exp(d));
+ assertTrue("Answer does not equal expected answer for d = " + d
+ + " answer = " + answer,
+ StrictMath.abs(answer - d) <= StrictMath
+ .abs(d * 0.00000001));
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ public void testLog10D() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(StrictMath
+ .log10(Double.NaN)));
+ assertTrue("Should return NaN", Double.isNaN(StrictMath
+ .log10(-2541.05745687234187532)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .log10(Double.POSITIVE_INFINITY));
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0));
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0));
+ assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath
+ .pow(10, 14)));
+
+ assertEquals("Should return 3.7389561269540406", 3.7389561269540406,
+ StrictMath.log10(5482.2158));
+ assertEquals("Should return 14.661551142893833", 14.661551142893833,
+ StrictMath.log10(458723662312872.125782332587));
+ assertEquals("Should return -0.9083828622192334", -0.9083828622192334,
+ StrictMath.log10(0.12348583358871));
+ assertEquals("Should return 308.25471555991675", 308.25471555991675,
+ StrictMath.log10(Double.MAX_VALUE));
+ assertEquals("Should return -323.3062153431158", -323.3062153431158,
+ StrictMath.log10(Double.MIN_VALUE));
+ }
+
+ @SuppressWarnings("boxing")
+ public void testLog1pD() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double.isNaN(StrictMath
+ .log1p(Double.NaN)));
+ assertTrue("Should return NaN", Double.isNaN(StrictMath
+ .log1p(-32.0482175)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .log1p(Double.POSITIVE_INFINITY));
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.log1p(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.log1p(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.log1p(-0.0)));
+
+ assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
+ StrictMath.log1p(-0.254856327));
+ assertEquals("Should return 7.368050685564151", 7.368050685564151,
+ StrictMath.log1p(1583.542));
+ assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
+ StrictMath.log1p(0.5894227));
+ assertEquals("Should return 709.782712893384", 709.782712893384,
+ StrictMath.log1p(Double.MAX_VALUE));
+ assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE,
+ StrictMath.log1p(Double.MIN_VALUE));
+ }
+
+ public void testMaxDD() {
+ // Test for method double java.lang.StrictMath.max(double, double)
+ assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
+ -1908897.6000089, 1908897.6000089), 0D);
+ assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
+ 1908897.6000089), 0D);
+ assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
+ -1908897.6000089), 0D);
+
+ }
+
+ public void testMaxFF() {
+ // Test for method float java.lang.StrictMath.max(float, float)
+ assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
+ 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value", StrictMath.max(2.0f,
+ 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
+ -1908897.600f) == -2.0f);
+ }
+
+ public void testMaxII() {
+ // Test for method int java.lang.StrictMath.max(int, int)
+ assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
+ 19088976));
+ assertEquals("Incorrect int max value",
+ 19088976, StrictMath.max(20, 19088976));
+ assertEquals("Incorrect int max value",
+ -20, StrictMath.max(-20, -19088976));
+ }
+
+ public void testMaxJJ() {
+ // Test for method long java.lang.StrictMath.max(long, long)
+ assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
+ 19088976000089L));
+ assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
+ -19088976000089L));
+ }
+
+ public void testMinDD() {
+ // Test for method double java.lang.StrictMath.min(double, double)
+ assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
+ -1908897.6000089, 1908897.6000089), 0D);
+ assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
+ 1908897.6000089), 0D);
+ assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
+ -1908897.6000089), 0D);
+ }
+
+ public void testMinFF() {
+ // Test for method float java.lang.StrictMath.min(float, float)
+ assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
+ 1908897.600f) == -1908897.600f);
+ assertTrue("Incorrect float min value", StrictMath.min(2.0f,
+ 1908897.600f) == 2.0f);
+ assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
+ -1908897.600f) == -1908897.600f);
+ }
+
+ public void testMinII() {
+ // Test for method int java.lang.StrictMath.min(int, int)
+ assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
+ 19088976));
+ assertEquals("Incorrect int min value",
+ 20, StrictMath.min(20, 19088976));
+ assertEquals("Incorrect int min value",
+ -19088976, StrictMath.min(-20, -19088976));
+
+ }
+
+ public void testMinJJ() {
+ // Test for method long java.lang.StrictMath.min(long, long)
+ assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long min value", 20, StrictMath.min(20,
+ 19088976000089L));
+ assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
+ -19088976000089L));
+ }
+
+ public void testPowDD() {
+ // Test for method double java.lang.StrictMath.pow(double, double)
+ assertTrue("pow returned incorrect value",
+ (long) StrictMath.pow(2, 8) == 256l);
+ assertTrue("pow returned incorrect value",
+ StrictMath.pow(2, -8) == 0.00390625d);
+ }
+
+ public void testRintD() {
+ // Test for method double java.lang.StrictMath.rint(double)
+ assertEquals("Failed to round properly - up to odd",
+ 3.0, StrictMath.rint(2.9), 0D);
+ assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
+ .rint(Double.NaN)));
+ assertEquals("Failed to round properly down to even", 2.0, StrictMath
+ .rint(2.1), 0D);
+ assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
+ .rint(2.5) == 2.0);
+ }
+
+ public void testRoundD() {
+ // Test for method long java.lang.StrictMath.round(double)
+ assertEquals("Incorrect rounding of a float",
+ -91, StrictMath.round(-90.89d));
+ }
+
+ public void testRoundF() {
+ // Test for method int java.lang.StrictMath.round(float)
+ assertEquals("Incorrect rounding of a float",
+ -91, StrictMath.round(-90.89f));
+ }
+
+ public void testSignumD() {
+ assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.signum(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.signum(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.signum(-0.0)));
+
+ assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
+ assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
+ assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
+ assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
+
+ assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
+ assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
+ assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
+ assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
+ assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D);
+ assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D);
+
+ }
+
+ public void testSignumF() {
+ assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
+ assertEquals(Float.floatToIntBits(0.0f), Float
+ .floatToIntBits(StrictMath.signum(0.0f)));
+ assertEquals(Float.floatToIntBits(+0.0f), Float
+ .floatToIntBits(StrictMath.signum(+0.0f)));
+ assertEquals(Float.floatToIntBits(-0.0f), Float
+ .floatToIntBits(StrictMath.signum(-0.0f)));
+
+ assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
+ assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
+ assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
+ assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
+
+ assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
+ assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
+ assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
+ assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
+ assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f);
+ assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f);
+ }
+
+ public void testSinD() {
+ // Test for method double java.lang.StrictMath.sin(double)
+ assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
+ .asin(OPP / HYP)) == OPP / HYP);
+ }
+
+ public void testSinhD() {
+ // Test for special situations
+ assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN)));
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath
+ .sinh(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath
+ .sinh(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.sinh(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.sinh(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.sinh(-0.0)));
+
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D);
+ assertEquals("Should return NEGATIVE_INFINITY",
+ Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D);
+ assertEquals("Should return 1.0000000000001666E-6",
+ 1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D);
+ assertEquals("Should return -1.0000000000001666E-6",
+ -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D);
+ assertEquals("Should return 5.115386441963859", 5.115386441963859,
+ StrictMath.sinh(2.33482), 0D);
+ assertEquals("Should return POSITIVE_INFINITY",
+ Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
+ .sinh(Double.MIN_VALUE), 0D);
+ }
+
+ public void testSqrtD() {
+ // Test for method double java.lang.StrictMath.sqrt(double)
+ assertEquals("Incorrect root returned1",
+ 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
+ assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
+ }
+
+ public void testTanD() {
+ // Test for method double java.lang.StrictMath.tan(double)
+ assertTrue(
+ "Returned incorrect tangent: ",
+ StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
+ || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
+ }
+
+ public void testTanhD() {
+ // Test for special situations
+ assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN)));
+ assertEquals("Should return +1.0", +1.0, StrictMath
+ .tanh(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Should return -1.0", -1.0, StrictMath
+ .tanh(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals(Double.doubleToLongBits(0.0), Double
+ .doubleToLongBits(StrictMath.tanh(0.0)));
+ assertEquals(Double.doubleToLongBits(+0.0), Double
+ .doubleToLongBits(StrictMath.tanh(+0.0)));
+ assertEquals(Double.doubleToLongBits(-0.0), Double
+ .doubleToLongBits(StrictMath.tanh(-0.0)));
+
+ assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D);
+ assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D);
+ assertEquals("Should return 9.999999999996666E-7",
+ 9.999999999996666E-7, StrictMath.tanh(0.000001), 0D);
+ assertEquals("Should return 0.981422884124941", 0.981422884124941,
+ StrictMath.tanh(2.33482), 0D);
+ assertEquals("Should return 1.0", 1.0, StrictMath
+ .tanh(Double.MAX_VALUE), 0D);
+ assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
+ .tanh(Double.MIN_VALUE), 0D);
+ }
+
+ public void testRandom() {
+ // There isn't a place for these tests so just stick them here
+ assertEquals("Wrong value E",
+ 4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
+ assertEquals("Wrong value PI",
+ 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
+
+ for (int i = 500; i >= 0; i--) {
+ double d = StrictMath.random();
+ assertTrue("Generated number is out of range: " + d, d >= 0.0
+ && d < 1.0);
+ }
+ }
+
+ public void testToRadiansD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ public void testToDegreesD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ @SuppressWarnings("boxing")
+ public void testUlp_D() {
+ // Test for special cases
+ assertTrue("Should return NaN", Double
+ .isNaN(StrictMath.ulp(Double.NaN)));
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
+ StrictMath.ulp(Double.POSITIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
+ StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(+0.0), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(-0.0), 0D);
+ assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
+ StrictMath.ulp(Double.MAX_VALUE), 0D);
+ assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
+ StrictMath.ulp(-Double.MAX_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(Double.MIN_VALUE), 0D);
+ assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
+ .ulp(-Double.MIN_VALUE), 0D);
+
+ assertEquals("Returned incorrect value", 2.220446049250313E-16,
+ StrictMath.ulp(1.0), 0D);
+ assertEquals("Returned incorrect value", 2.220446049250313E-16,
+ StrictMath.ulp(-1.0), 0D);
+ assertEquals("Returned incorrect value", 2.2737367544323206E-13,
+ StrictMath.ulp(1153.0), 0D);
+ }
+
+ @SuppressWarnings("boxing")
+ public void testUlpF() {
+ // Test for special cases
+ assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN)));
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
+ StrictMath.ulp(Float.POSITIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
+ StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(+0.0f), 0f);
+ assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
+ .ulp(-0.0f), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
+ .ulp(Float.MAX_VALUE), 0f);
+ assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
+ .ulp(-Float.MAX_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
+ .ulp(Float.MIN_VALUE), 0f);
+ assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
+ .ulp(-Float.MIN_VALUE), 0f);
+
+ assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
+ .ulp(1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
+ .ulp(-1.0f), 0f);
+ assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath
+ .ulp(1153.0f), 0f);
+ assertEquals("Returned incorrect value", 5.6E-45f, Math
+ .ulp(9.403954E-38f), 0f);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldCharacterSubsetTest.java b/luni/src/test/java/libcore/java/lang/OldCharacterSubsetTest.java
new file mode 100644
index 0000000..215747b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldCharacterSubsetTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldCharacterSubsetTest extends TestCase {
+
+ public void test_equals() {
+ Character.Subset subset1 = new Character.Subset("name") { };
+ assertTrue(subset1.equals(subset1));
+ assertFalse(subset1.equals(new Character.Subset("name") {}));
+ assertFalse(subset1.equals(new Character.Subset("name1") {}));
+ assertFalse(subset1.equals(new Integer(0)));
+ }
+
+ public void test_hashCode() {
+ Character.Subset subset1 = new Character.Subset("name") {};
+ Character.Subset subset2 = new Character.Subset("name") {};
+ Character.Subset subset3 = new Character.Subset("name1") {};
+ assertFalse(subset1.hashCode() == subset2.hashCode());
+ assertFalse(subset1.hashCode() == subset3.hashCode());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldCharacterTest.java b/luni/src/test/java/libcore/java/lang/OldCharacterTest.java
new file mode 100644
index 0000000..8e6f9ab
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldCharacterTest.java
@@ -0,0 +1,152 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldCharacterTest extends TestCase {
+
+ public void test_codePointCountLjava_lang_CharArrayII() {
+
+ assertEquals(1, Character.codePointCount("\uD800\uDC00".toCharArray(),
+ 0, 2));
+ assertEquals(3, Character.codePointCount("a\uD800\uDC00b".toCharArray(),
+ 0, 4));
+ assertEquals(4, Character.codePointCount("a\uD800\uDC00b\uD800".toCharArray(),
+ 0, 5));
+ assertEquals(4, Character.codePointCount("ab\uD800\uDC00b\uD800".toCharArray(),
+ 1, 5));
+
+ try {
+ Character.codePointCount((char[]) null, 0, 1);
+ fail("No NPE, null char sequence.");
+ } catch (NullPointerException e) {
+ }
+
+ try {
+ Character.codePointCount("abc".toCharArray(), -1, 1);
+ fail("No IOOBE, negative start.");
+ } catch (IndexOutOfBoundsException e) {
+ }
+
+ try {
+ Character.codePointCount("abc".toCharArray(), 0, 4);
+ fail("No IOOBE, end greater than length.");
+ } catch (IndexOutOfBoundsException e) {
+ }
+
+ try {
+ Character.codePointCount("abc".toCharArray(), 1, 3);
+ fail("No IOOBE, end greater than start.");
+ } catch (IndexOutOfBoundsException e) {
+ }
+ }
+
+ public void test_getDirectionality() throws Exception {
+
+ byte[] directionalities = {
+ // BEGIN android-changed
+ // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
+ Character.DIRECTIONALITY_LEFT_TO_RIGHT,
+ // END android-changed.
+
+ Character.DIRECTIONALITY_LEFT_TO_RIGHT,
+ Character.DIRECTIONALITY_RIGHT_TO_LEFT,
+
+ // BEGIN android-changed
+ // Unicode standard 5.1 changed category of unicode point 0x0600 from AL to AN
+ Character.DIRECTIONALITY_ARABIC_NUMBER,
+ // END android-changed.
+
+ Character.DIRECTIONALITY_EUROPEAN_NUMBER,
+ // Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR,
+ Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR,
+ Character.DIRECTIONALITY_ARABIC_NUMBER,
+ Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR,
+ Character.DIRECTIONALITY_NONSPACING_MARK,
+ Character.DIRECTIONALITY_BOUNDARY_NEUTRAL,
+ Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR,
+ Character.DIRECTIONALITY_SEGMENT_SEPARATOR,
+ Character.DIRECTIONALITY_WHITESPACE,
+ Character.DIRECTIONALITY_OTHER_NEUTRALS,
+ Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING,
+ Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE,
+ Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING,
+ Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE,
+ Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
+ };
+
+ char[] characters = {
+ // BEGIN android-changed
+ // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
+ '\u0370', // 1
+ // END android-changed
+ '\u00B5', // 0
+ '\u05BE', // 1
+ // BEGIN android-changed
+ '\u0600', // 6
+ // END android-changed
+ '\u00B2', // 3
+ // '', // No common char in this group on android and java.
+ '\u00B1', // 5
+ '\u0660', // 6
+ '\u00A0', // 7
+ '\u0300', // 8
+ '\u009F', // 9
+ '\u0085', // 10
+ '\u001F', // 11
+ '\u0020', // 12
+ '\u00AB', // 13
+ '\u202A', // 14
+ '\u202D', // 15
+ '\u202B', // 16
+ '\u202E', // 17
+ '\u202C' // 18
+ };
+
+ for(int i = 0; i < directionalities.length; i++) {
+ assertEquals(directionalities[i],
+ Character.getDirectionality(characters[i]));
+ }
+
+
+ }
+
+ public void test_digitCI() {
+ assertEquals(-1, Character.digit('\uFFFF', 1));
+ }
+
+ public void test_isUpperCaseC() {
+ assertFalse("Incorrect case value", Character.isUpperCase('1'));
+ assertFalse("Incorrect case value", Character.isUpperCase('?'));
+ }
+
+ public void test_toLowerCaseC() {
+ assertEquals("Failed to change case", 't', Character.toLowerCase('t'));
+ assertEquals("Failed to change case", '1', Character.toLowerCase('1'));
+ }
+
+ public void test_toString() {
+ assertEquals("Incorrect String returned", "T", new Character('T').toString());
+ assertEquals("Incorrect String returned", "1", new Character('1').toString());
+ assertEquals("Incorrect String returned", "$", new Character('$').toString());
+ }
+
+ public void test_toString_char() {
+ assertEquals("Incorrect String returned", "T", Character.toString('T'));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldClassTest.java b/luni/src/test/java/libcore/java/lang/OldClassTest.java
new file mode 100644
index 0000000..c516467
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldClassTest.java
@@ -0,0 +1,1024 @@
+/*
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Vector;
+import tests.support.Support_ClassLoader;
+import tests.support.resource.Support_Resources;
+
+@SuppressWarnings("deprecation")
+public class OldClassTest extends junit.framework.TestCase {
+
+ public static final String FILENAME =
+ OldClassTest.class.getPackage().getName().replace('.', '/') +
+ "/test#.properties";
+
+ final String packageName = getClass().getPackage().getName();
+ final String classNameInitError1 = packageName + ".TestClass1";
+ final String classNameInitError2 = packageName + ".TestClass1B";
+ final String classNameLinkageError = packageName + ".TestClass";
+ final String sourceJARfile = "illegalClasses.jar";
+ final String illegalClassName = "illegalClass";
+
+ @Retention(RetentionPolicy.RUNTIME)
+ public @interface TestAnnotation {
+ String value();
+ }
+
+ public static class TestClass1C {
+ static TestClass2 tc = new TestClass2(0);
+
+ TestClass1C() {
+ }
+
+ }
+
+ public static class TestClass2 {
+
+ public TestClass2(int i) throws IllegalArgumentException {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public static class TestClass3 {
+ private TestClass3() {}
+ }
+
+ interface TestInterface {
+ public static int TEST_INTERFACE_FIELD = 0;
+
+ int getCount();
+ void setCount(int value);
+ }
+
+ static class StaticMember$Class {
+ class Member2$A {
+ }
+ }
+
+ class Member$Class {
+ class Member3$B {
+ }
+ }
+
+ @Deprecated
+ @TestAnnotation("libcore.java.lang.OldClassTest$ExtendTestClass")
+ public static class ExtendTestClass extends PublicTestClass {
+
+ private static final long serialVersionUID = 1L;
+
+ public enum enumExm {ONE, TWO, THREE};
+ @Override
+ public void setCount(int value) {
+
+ }
+ }
+
+ public class ExtendTestClass1 extends ExtendTestClass {
+
+ }
+
+ @TestAnnotation("libcore.java.lang.OldClassTest$PublicTestClass")
+ public static class PublicTestClass implements TestInterface, Serializable, Cloneable {
+
+ private static final long serialVersionUID = 1L;
+
+ public static String TEST_FIELD = "test field";
+
+ Object clazz;
+
+ public PublicTestClass() {
+ class LocalClass { }
+
+ clazz = new LocalClass();
+ }
+
+ public Object getLocalClass() {
+ class LocalClass {}
+ Object returnedObject = new LocalClass();
+ return returnedObject;
+ }
+
+ int count = 0;
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int value) {
+ count = value;
+ }
+
+ private class PrivateClass1 {
+
+ public String toString() {
+ return "PrivateClass0";
+ }
+ }
+
+ public class PrivateClass2 {
+
+ public String toString() {
+ return "PrivateClass1";
+ }
+ }
+ }
+
+ public static class TestClass {
+ @SuppressWarnings("unused")
+ private int privField = 1;
+
+ public int pubField = 2;
+
+ private Object cValue = null;
+
+ public Object ack = new Object();
+
+ @SuppressWarnings("unused")
+ private int privMethod() {
+ return 1;
+ }
+
+ public int pubMethod() {
+ return 2;
+ }
+
+ public Object cValue() {
+ return cValue;
+ }
+
+ public TestClass() {
+ }
+
+ @SuppressWarnings("unused")
+ private TestClass(Object o) {
+ }
+ }
+
+ public static class SubTestClass extends TestClass {
+ }
+
+ interface Intf1 {
+ public int field1 = 1;
+ public int field2 = 1;
+ void test();
+ }
+
+ interface Intf2 {
+ public int field1 = 1;
+ void test();
+ }
+
+ interface Intf3 extends Intf1 {
+ public int field1 = 1;
+ }
+
+ interface Intf4 extends Intf1, Intf2 {
+ public int field1 = 1;
+ void test2(int a, Object b);
+ }
+
+ interface Intf5 extends Intf1 {
+ }
+
+ class Cls1 implements Intf2 {
+ public int field1 = 2;
+ public int field2 = 2;
+ public void test() {
+ }
+ }
+
+ class Cls2 extends Cls1 implements Intf1 {
+ public int field1 = 2;
+ @Override
+ public void test() {
+ }
+ }
+
+ class Cls3 implements Intf3, Intf4 {
+ public void test() {
+ }
+ public void test2(int a, Object b) {
+ }
+ }
+
+ static class Cls4 {
+
+ }
+
+ public void test_getAnnotations() {
+ Annotation [] annotations = PublicTestClass.class.getAnnotations();
+ assertEquals(1, annotations.length);
+ assertEquals(TestAnnotation.class, annotations[0].annotationType());
+
+ annotations = ExtendTestClass.class.getAnnotations();
+ assertEquals(2, annotations.length);
+
+ for(int i = 0; i < annotations.length; i++) {
+ Class<? extends Annotation> type = annotations[i].annotationType();
+ assertTrue("Annotation's type " + i + ": " + type,
+ type.equals(Deprecated.class) ||
+ type.equals(TestAnnotation.class));
+ }
+ }
+
+ public void test_forNameLjava_lang_StringLbooleanLClassLoader() throws Exception {
+
+ ClassLoader pcl = getClass().getClassLoader();
+
+ Class<?> [] classes = {PublicTestClass.class, ExtendTestClass.class,
+ ExtendTestClass1.class, TestInterface.class, String.class};
+
+ for(int i = 0; i < classes.length; i++) {
+ Class<?> clazz = Class.forName(classes[i].getName(), true, pcl);
+ assertEquals(classes[i], clazz);
+
+ clazz = Class.forName(classes[i].getName(), false, pcl);
+ assertEquals(classes[i], clazz);
+ }
+
+ Class<?> [] systemClasses = {String.class, Integer.class, Object.class,
+ Object[].class};
+
+ for(int i = 0; i < systemClasses.length; i++) {
+ Class<?> clazz = Class.forName(systemClasses[i].getName(), true,
+ ClassLoader.getSystemClassLoader());
+ assertEquals(systemClasses[i], clazz);
+
+ clazz = Class.forName(systemClasses[i].getName(), false,
+ ClassLoader.getSystemClassLoader());
+ assertEquals(systemClasses[i], clazz);
+ }
+
+ try {
+ Class.forName(null, true, pcl);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ Class.forName("NotExistClass", true, pcl);
+ fail("ClassNotFoundException is not thrown for non existent class.");
+ } catch(ClassNotFoundException cnfe) {
+ //expected
+ }
+
+ try {
+ Class.forName("String", false, pcl);
+ fail("ClassNotFoundException is not thrown for non existent class.");
+ } catch(ClassNotFoundException cnfe) {
+ //expected
+ }
+
+ try {
+ Class.forName("libcore.java.lang.NonexistentClass", false, pcl);
+ fail("ClassNotFoundException is not thrown for non existent class.");
+ } catch(ClassNotFoundException cnfe) {
+ //expected
+ }
+ }
+
+ // AndroidOnly: Class.forName method throws ClassNotFoundException on Android.
+ public void test_forNameLjava_lang_StringLbooleanLClassLoader_AndroidOnly() throws Exception {
+
+ // Android doesn't support loading class files from a jar.
+ try {
+
+ URL url = getClass().getClassLoader().getResource(
+ packageName.replace(".", "/") + "/" + sourceJARfile);
+
+ ClassLoader loader = new URLClassLoader(new URL[] { url },
+ getClass().getClassLoader());
+ try {
+ Class.forName(classNameLinkageError, true, loader);
+ fail("LinkageError or ClassNotFoundException expected.");
+ } catch (java.lang.LinkageError le) {
+ // Expected for the RI.
+ } catch (java.lang.ClassNotFoundException ce) {
+ // Expected for Android.
+ }
+ } catch(Exception e) {
+ fail("Unexpected exception was thrown: " + e.toString());
+ }
+
+ try {
+ Class.forName(classNameInitError2,
+ true, getClass().getClassLoader());
+ fail("ExceptionInInitializerError or ClassNotFoundException " +
+ "should be thrown.");
+ } catch (java.lang.ExceptionInInitializerError ie) {
+ // Expected for the RI.
+ // Remove this comment to let the test pass on Android.
+ } catch (java.lang.ClassNotFoundException ce) {
+ // Expected for Android.
+ }
+ }
+
+ public void test_getAnnotation() {
+ TestAnnotation target = PublicTestClass.class.getAnnotation(TestAnnotation.class);
+ assertEquals(target.value(), PublicTestClass.class.getName());
+
+ assertNull(PublicTestClass.class.getAnnotation(Deprecated.class));
+
+ Deprecated target2 = ExtendTestClass.class.getAnnotation(Deprecated.class);
+ assertNotNull(target2);
+ }
+
+ public void test_getDeclaredAnnotations() {
+ Annotation [] annotations = PublicTestClass.class.getDeclaredAnnotations();
+ assertEquals(1, annotations.length);
+
+ annotations = ExtendTestClass.class.getDeclaredAnnotations();
+ assertEquals(2, annotations.length);
+
+ annotations = TestInterface.class.getDeclaredAnnotations();
+ assertEquals(0, annotations.length);
+
+ annotations = String.class.getDeclaredAnnotations();
+ assertEquals(0, annotations.length);
+ }
+
+ public void test_getEnclosingClass() {
+ Class clazz = OldClassTest.class.getEnclosingClass();
+ assertNull(clazz);
+
+ assertEquals(getClass(), Cls1.class.getEnclosingClass());
+ assertEquals(getClass(), Intf1.class.getEnclosingClass());
+ assertEquals(getClass(), Cls4.class.getEnclosingClass());
+ }
+
+ public void test_getEnclosingMethod() {
+ Method clazz = ExtendTestClass.class.getEnclosingMethod();
+ assertNull(clazz);
+
+ PublicTestClass ptc = new PublicTestClass();
+ try {
+ assertEquals("getEnclosingMethod returns incorrect method.",
+ PublicTestClass.class.getMethod("getLocalClass",
+ (Class []) null),
+ ptc.getLocalClass().getClass().getEnclosingMethod());
+ } catch(NoSuchMethodException nsme) {
+ fail("NoSuchMethodException was thrown.");
+ }
+ }
+
+ public void test_getEnclosingConstructor() {
+
+ PublicTestClass ptc = new PublicTestClass();
+
+ assertEquals("getEnclosingConstructor method returns incorrect class.",
+ PublicTestClass.class.getConstructors()[0],
+ ptc.clazz.getClass().getEnclosingConstructor());
+
+ assertNull("getEnclosingConstructor should return null for local " +
+ "class declared in method.",
+ ptc.getLocalClass().getClass().getEnclosingConstructor());
+
+ assertNull("getEnclosingConstructor should return null for local " +
+ "class declared in method.",
+ ExtendTestClass.class.getEnclosingConstructor());
+ }
+
+
+ public void test_getEnumConstants() {
+ Object [] clazz = ExtendTestClass.class.getEnumConstants();
+ assertNull(clazz);
+ Object [] constants = TestEnum.class.getEnumConstants();
+ assertEquals(TestEnum.values().length, constants.length);
+ for(int i = 0; i < constants.length; i++) {
+ assertEquals(TestEnum.values()[i], constants[i]);
+ }
+ assertEquals(0, TestEmptyEnum.class.getEnumConstants().length);
+ }
+ public enum TestEnum {
+ ONE, TWO, THREE
+ }
+ public enum TestEmptyEnum {
+ }
+
+ public void test_getGenericInterfaces() {
+ Type [] types = ExtendTestClass1.class.getGenericInterfaces();
+ assertEquals(0, types.length);
+
+ Class [] interfaces = {TestInterface.class, Serializable.class,
+ Cloneable.class};
+ types = PublicTestClass.class.getGenericInterfaces();
+ assertEquals(interfaces.length, types.length);
+ for(int i = 0; i < types.length; i++) {
+ assertEquals(interfaces[i], types[i]);
+ }
+
+ types = TestInterface.class.getGenericInterfaces();
+ assertEquals(0, types.length);
+
+ types = List.class.getGenericInterfaces();
+ assertEquals(1, types.length);
+ assertEquals(Collection.class, ((ParameterizedType)types[0]).getRawType());
+
+ assertEquals(0, int.class.getGenericInterfaces().length);
+ assertEquals(0, void.class.getGenericInterfaces().length);
+ }
+
+ public void test_getGenericSuperclass () {
+ assertEquals(PublicTestClass.class,
+ ExtendTestClass.class.getGenericSuperclass());
+ assertEquals(ExtendTestClass.class,
+ ExtendTestClass1.class.getGenericSuperclass());
+ assertEquals(Object.class, PublicTestClass.class.getGenericSuperclass());
+ assertEquals(Object.class, String.class.getGenericSuperclass());
+ assertEquals(null, TestInterface.class.getGenericSuperclass());
+
+ ParameterizedType type = (ParameterizedType) Vector.class.getGenericSuperclass();
+ assertEquals(AbstractList.class, type.getRawType());
+ }
+
+ // AndroidOnly: Uses dalvik.system.PathClassLoader.
+ // Different behavior between cts host and run-core-test")
+ public void test_getPackage() {
+
+ Package thisPackage = getClass().getPackage();
+ assertEquals("libcore.java.lang",
+ thisPackage.getName());
+
+ Package stringPackage = String.class.getPackage();
+ assertNotNull("java.lang", stringPackage.getName());
+
+ String hyts_package_name = "hyts_package_dex.jar";
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, "Package", hyts_package_name);
+
+ String resPath = resources.toString();
+ if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
+ resPath = resPath.substring(1);
+
+ try {
+
+ URL resourceURL = new URL("file:/" + resPath + "/Package/"
+ + hyts_package_name);
+
+ ClassLoader cl = Support_ClassLoader.getInstance(resourceURL,
+ getClass().getClassLoader());
+
+ Class clazz = cl.loadClass("C");
+ assertNull("getPackage for C.class should return null",
+ clazz.getPackage());
+
+ clazz = cl.loadClass("a.b.C");
+ Package cPackage = clazz.getPackage();
+ assertNotNull("getPackage for a.b.C.class should not return null",
+ cPackage);
+
+ /*
+ * URLClassLoader doesn't work on Android for jar files
+ *
+ * URL url = getClass().getClassLoader().getResource(
+ * packageName.replace(".", "/") + "/" + sourceJARfile);
+ *
+ * ClassLoader loader = new URLClassLoader(new URL[] { url }, null);
+ *
+ * try {
+ * Class<?> clazz = loader.loadClass(illegalClassName);
+ * Package pack = clazz.getPackage();
+ * assertNull(pack);
+ * } catch(ClassNotFoundException cne) {
+ * fail("ClassNotFoundException was thrown for " + illegalClassName);
+ * }
+ */
+ } catch(Exception e) {
+ fail("Unexpected exception was thrown: " + e.toString());
+ }
+ }
+
+ public void test_getSigners() {
+ assertNull(void.class.getSigners());
+ assertNull(PublicTestClass.class.getSigners());
+ }
+
+ public void test_getSimpleName() {
+ assertEquals("PublicTestClass", PublicTestClass.class.getSimpleName());
+ assertEquals("void", void.class.getSimpleName());
+ assertEquals("int[]", int[].class.getSimpleName());
+ }
+
+ public void test_getTypeParameters() {
+ assertEquals(0, PublicTestClass.class.getTypeParameters().length);
+ TypeVariable [] tv = TempTestClass1.class.getTypeParameters();
+ assertEquals(1, tv.length);
+ assertEquals(Object.class, tv[0].getBounds()[0]);
+
+ TempTestClass2<String> tc = new TempTestClass2<String>();
+ tv = tc.getClass().getTypeParameters();
+ assertEquals(1, tv.length);
+ assertEquals(String.class, tv[0].getBounds()[0]);
+ }
+
+ class TempTestClass1<T> {
+ }
+
+ class TempTestClass2<S extends String> extends TempTestClass1<S> {
+ }
+
+ public void test_isAnnotation() {
+ assertTrue(Deprecated.class.isAnnotation());
+ assertTrue(TestAnnotation.class.isAnnotation());
+ assertFalse(PublicTestClass.class.isAnnotation());
+ assertFalse(String.class.isAnnotation());
+ }
+
+ public void test_isAnnotationPresent() {
+ assertTrue(PublicTestClass.class.isAnnotationPresent(TestAnnotation.class));
+ assertFalse(ExtendTestClass1.class.isAnnotationPresent(TestAnnotation.class));
+ assertFalse(String.class.isAnnotationPresent(Deprecated.class));
+ assertTrue(ExtendTestClass.class.isAnnotationPresent(TestAnnotation.class));
+ assertTrue(ExtendTestClass.class.isAnnotationPresent(Deprecated.class));
+ }
+
+ public void test_isAnonymousClass() {
+ assertFalse(PublicTestClass.class.isAnonymousClass());
+ assertTrue((new Thread() {}).getClass().isAnonymousClass());
+ }
+
+ public void test_isEnum() {
+ assertFalse(PublicTestClass.class.isEnum());
+ assertFalse(ExtendTestClass.class.isEnum());
+ assertTrue(TestEnum.ONE.getClass().isEnum());
+ assertTrue(TestEnum.class.isEnum());
+ }
+
+ public void test_isLocalClass() {
+ assertFalse(ExtendTestClass.class.isLocalClass());
+ assertFalse(TestInterface.class.isLocalClass());
+ assertFalse(TestEnum.class.isLocalClass());
+ class InternalClass {}
+ assertTrue(InternalClass.class.isLocalClass());
+ }
+
+ public void test_isMemberClass() {
+ assertFalse(OldClassTest.class.isMemberClass());
+ assertFalse(String.class.isMemberClass());
+ assertTrue(TestEnum.class.isMemberClass());
+ assertTrue(StaticMember$Class.class.isMemberClass());
+ }
+
+ public void test_isSynthetic() {
+ assertFalse("Returned true for non synthetic class.",
+ ExtendTestClass.class.isSynthetic());
+ assertFalse("Returned true for non synthetic class.",
+ TestInterface.class.isSynthetic());
+ assertFalse("Returned true for non synthetic class.",
+ String.class.isSynthetic());
+ }
+
+ public void test_getCanonicalName() {
+ Class [] classArray = { int.class, int[].class, String.class,
+ PublicTestClass.class, TestInterface.class,
+ ExtendTestClass.class };
+ String [] classNames = {"int", "int[]", "java.lang.String",
+ "libcore.java.lang.OldClassTest.PublicTestClass",
+ "libcore.java.lang.OldClassTest.TestInterface",
+ "libcore.java.lang.OldClassTest.ExtendTestClass"};
+
+ for(int i = 0; i < classArray.length; i++) {
+ assertEquals(classNames[i], classArray[i].getCanonicalName());
+ }
+ }
+
+ public void test_getClassLoader() {
+ assertEquals(ExtendTestClass.class.getClassLoader(),
+ PublicTestClass.class.getClassLoader());
+
+ assertNull(int.class.getClassLoader());
+ assertNull(void.class.getClassLoader());
+ }
+
+ public void test_getClasses() {
+ assertEquals("Incorrect class array returned",
+ 11, OldClassTest.class.getClasses().length);
+ }
+
+ public void test_getDeclaredClasses() {
+ Class [] declClasses = Object.class.getDeclaredClasses();
+ assertEquals("Incorrect length of declared classes array is returned " +
+ "for Object.", 0, declClasses.length);
+
+ declClasses = PublicTestClass.class.getDeclaredClasses();
+ assertEquals(2, declClasses.length);
+
+ assertEquals(0, int.class.getDeclaredClasses().length);
+ assertEquals(0, void.class.getDeclaredClasses().length);
+
+ for(int i = 0; i < declClasses.length; i++) {
+ Constructor<?> constr = declClasses[i].getDeclaredConstructors()[0];
+ constr.setAccessible(true);
+ PublicTestClass publicClazz = new PublicTestClass();
+ try {
+ Object o = constr.newInstance(publicClazz);
+ assertTrue("Returned incorrect class: " + o.toString(),
+ o.toString().startsWith("PrivateClass"));
+ } catch(Exception e) {
+ fail("Unexpected exception was thrown: " + e.toString());
+ }
+ }
+
+ declClasses = TestInterface.class.getDeclaredClasses();
+ assertEquals(0, declClasses.length);
+ }
+
+ public void test_getDeclaredConstructor$Ljava_lang_Class() throws Exception {
+ try {
+ TestClass.class.getDeclaredConstructor(String.class);
+ fail("NoSuchMethodException should be thrown.");
+ } catch(NoSuchMethodException nsme) {
+ //expected
+ }
+ }
+
+ public void test_getDeclaredFieldLjava_lang_String() throws Exception {
+ try {
+ TestClass.class.getDeclaredField(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ TestClass.class.getDeclaredField("NonExistentField");
+ fail("NoSuchFieldException is not thrown.");
+ } catch(NoSuchFieldException nsfe) {
+ //expected
+ }
+ }
+
+ public void test_getDeclaredMethodLjava_lang_String$Ljava_lang_Class() throws Exception {
+ try {
+ TestClass.class.getDeclaredMethod(null, new Class[0]);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ TestClass.class.getDeclaredMethod("NonExistentMethod", new Class[0]);
+ fail("NoSuchMethodException is not thrown.");
+ } catch(NoSuchMethodException nsme) {
+ //expected
+ }
+ }
+
+ public void test_getMethodLjava_lang_String$Ljava_lang_Class() throws Exception {
+ Method m = ExtendTestClass1.class.getMethod("getCount", new Class[0]);
+ assertEquals("Returned incorrect method", 0, ((Integer) (m.invoke(new ExtendTestClass1())))
+ .intValue());
+
+ try {
+ m = TestClass.class.getMethod("init", new Class[0]);
+ fail("Failed to throw exception accessing to init method");
+ } catch (NoSuchMethodException e) {
+ // Correct
+ return;
+ }
+
+ try {
+ TestClass.class.getMethod("pubMethod", new Class[0]);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_getDeclaringClass() {
+ assertNull(OldClassTest.class.getDeclaringClass());
+ assertNotNull(PublicTestClass.class.getDeclaringClass());
+ }
+
+ public void test_getFieldLjava_lang_String() throws Exception {
+ Field f = TestClass.class.getField("pubField");
+ assertEquals("Returned incorrect field", 2, f.getInt(new TestClass()));
+
+ f = PublicTestClass.class.getField("TEST_FIELD");
+ assertEquals("Returned incorrect field", "test field",
+ f.get(new PublicTestClass()));
+
+ f = PublicTestClass.class.getField("TEST_INTERFACE_FIELD");
+ assertEquals("Returned incorrect field", 0,
+ f.getInt(new PublicTestClass()));
+
+ try {
+ TestClass.class.getField(null);
+ fail("NullPointerException is thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_getFields2() throws Exception {
+ Field[] f;
+ Field expected = null;
+
+ f = PublicTestClass.class.getFields();
+ assertEquals("Test 1: Incorrect number of fields;", 2, f.length);
+
+ f = Cls2.class.getFields();
+ assertEquals("Test 2: Incorrect number of fields;", 6, f.length);
+
+ f = Cls3.class.getFields();
+ assertEquals("Test 2: Incorrect number of fields;", 5, f.length);
+
+ for (Field field : f) {
+ if (field.toString().equals("public static final int "
+ + "libcore.java.lang.OldClassTest$Intf3.field1")) {
+ expected = field;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("Test 3: getFields() did not return all fields.");
+ }
+ assertEquals("Test 4: Incorrect field;", expected,
+ Cls3.class.getField("field1"));
+
+ expected = null;
+ for (Field field : f) {
+ if(field.toString().equals("public static final int " +
+ "libcore.java.lang.OldClassTest$Intf1.field2")) {
+ expected = field;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("Test 5: getFields() did not return all fields.");
+ }
+ assertEquals("Test 6: Incorrect field;", expected,
+ Cls3.class.getField("field2"));
+ }
+
+ public void test_getFields() throws Exception {
+ Field expected = null;
+ Field[] fields = Cls2.class.getFields();
+ for (Field field : fields) {
+ if(field.toString().equals("public int libcore.java.lang.OldClassTest$Cls2.field1")) {
+ expected = field;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("getFields() did not return all fields");
+ }
+ assertEquals(expected, Cls2.class.getField("field1"));
+ }
+
+ public void test_getInterfaces() {
+ Class [] interfaces1 = Cls1.class.getInterfaces();
+ assertEquals(1, interfaces1.length);
+ assertEquals(Intf2.class, interfaces1[0]);
+
+ Class [] interfaces2 = Cls2.class.getInterfaces();
+ assertEquals(1, interfaces2.length);
+ assertEquals(Intf1.class, interfaces2[0]);
+
+ Class [] interfaces3 = Cls3.class.getInterfaces();
+ assertEquals(2, interfaces3.length);
+ assertEquals(Intf3.class, interfaces3[0]);
+ assertEquals(Intf4.class, interfaces3[1]);
+
+ Class [] interfaces4 = Cls4.class.getInterfaces();
+ assertEquals(0, interfaces4.length);
+ }
+
+ public void test_getMethods() throws Exception {
+ assertEquals("Incorrect number of methods", 10,
+ Cls2.class.getMethods().length);
+ assertEquals("Incorrect number of methods", 11,
+ Cls3.class.getMethods().length);
+
+ Method expected = null;
+ Method[] methods = Cls2.class.getMethods();
+ for (Method method : methods) {
+ if(method.toString().equals("public void libcore.java.lang.OldClassTest$Cls2.test()")) {
+ expected = method;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("getMethods() did not return all methods");
+ }
+ assertEquals(expected, Cls2.class.getMethod("test"));
+
+ expected = null;
+ methods = Cls3.class.getMethods();
+ for (Method method : methods) {
+ if(method.toString().equals("public void libcore.java.lang.OldClassTest$Cls3.test()")) {
+ expected = method;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("getMethods() did not return all methods");
+ }
+ assertEquals(expected, Cls3.class.getMethod("test"));
+
+ expected = null;
+ methods = Cls3.class.getMethods();
+ for (Method method : methods) {
+ if(method.toString().equals("public void libcore.java.lang.OldClassTest$Cls3.test2(int,"
+ + "java.lang.Object)")) {
+ expected = method;
+ break;
+ }
+ }
+ if (expected == null) {
+ fail("getMethods() did not return all methods");
+ }
+
+ assertEquals(expected, Cls3.class.getMethod("test2", int.class,
+ Object.class));
+
+ assertEquals("Incorrect number of methods", 1,
+ Intf5.class.getMethods().length);
+ }
+
+ public void test_getResourceLjava_lang_String() {
+ assertNull(getClass().getResource(
+ "libcore/java/lang/NonExistentResource"));
+ assertNull(getClass().getResource(getClass().getName() + "NonExistentResource"));
+ }
+
+ public void test_getResourceAsStreamLjava_lang_String() throws Exception {
+ String name = "/HelloWorld.txt";
+ assertNotNull("the file " + name + " can not be found in this " +
+ "directory", getClass().getResourceAsStream(name));
+
+ final String nameBadURI = "org/apache/harmony/luni/tests/test_resource.txt";
+ assertNull("the file " + nameBadURI + " should not be found in this directory",
+ getClass().getResourceAsStream(nameBadURI));
+
+ ClassLoader pcl = getClass().getClassLoader();
+ Class<?> clazz = pcl.loadClass("libcore.java.lang.OldClassTest");
+ assertNotNull(clazz.getResourceAsStream("HelloWorld1.txt"));
+
+ try {
+ getClass().getResourceAsStream(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_isAssignableFromLjava_lang_Class() {
+ assertFalse("returned true not assignable classes",
+ Integer.class.isAssignableFrom(String.class));
+
+ try {
+ Runnable.class.isAssignableFrom(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_newInstance() throws Exception {
+ try {
+ TestClass3.class.newInstance();
+ fail("IllegalAccessException is not thrown.");
+ } catch(IllegalAccessException iae) {
+ //expected
+ }
+
+ try {
+ TestClass1C.class.newInstance();
+ fail("ExceptionInInitializerError should be thrown.");
+ } catch (java.lang.ExceptionInInitializerError ie) {
+ //expected
+ }
+ }
+
+ public void test_asSubclass1() {
+ assertEquals(ExtendTestClass.class,
+ ExtendTestClass.class.asSubclass(PublicTestClass.class));
+
+ assertEquals(PublicTestClass.class,
+ PublicTestClass.class.asSubclass(TestInterface.class));
+
+ assertEquals(ExtendTestClass1.class,
+ ExtendTestClass1.class.asSubclass(PublicTestClass.class));
+
+ assertEquals(PublicTestClass.class,
+ PublicTestClass.class.asSubclass(PublicTestClass.class));
+ }
+
+ public void test_asSubclass2() {
+ try {
+ PublicTestClass.class.asSubclass(ExtendTestClass.class);
+ fail("Test 1: ClassCastException expected.");
+ } catch(ClassCastException cce) {
+ // Expected.
+ }
+
+ try {
+ PublicTestClass.class.asSubclass(String.class);
+ fail("Test 2: ClassCastException expected.");
+ } catch(ClassCastException cce) {
+ // Expected.
+ }
+ }
+
+ public void test_cast() {
+ Object o = PublicTestClass.class.cast(new ExtendTestClass());
+ assertTrue(o instanceof ExtendTestClass);
+
+ try {
+ ExtendTestClass.class.cast(new PublicTestClass());
+ fail("Test 1: ClassCastException expected.");
+ } catch(ClassCastException cce) {
+ //expected
+ }
+
+ try {
+ ExtendTestClass.class.cast(new String());
+ fail("ClassCastException is not thrown.");
+ } catch(ClassCastException cce) {
+ //expected
+ }
+ }
+
+ public void test_desiredAssertionStatus() {
+ Class [] classArray = { Object.class, Integer.class,
+ String.class, PublicTestClass.class,
+ ExtendTestClass.class, ExtendTestClass1.class};
+
+ for(int i = 0; i < classArray.length; i++) {
+ assertFalse("assertion status for " + classArray[i],
+ classArray[i].desiredAssertionStatus());
+ }
+ }
+
+ public void testGetResourceAsStream1() throws IOException {
+ Class clazz = getClass();
+
+ InputStream stream = clazz.getResourceAsStream("HelloWorld.txt");
+ assert(stream != null);
+
+ byte[] buffer = new byte[20];
+ int length = stream.read(buffer);
+ String s = new String(buffer, 0, length);
+ assert("Hello, World.".equals(s));
+
+ stream.close();
+ }
+
+ public void testGetResourceAsStream2() throws IOException {
+ Class clazz = getClass();
+
+ InputStream stream = clazz.getResourceAsStream("/libcore/java/lang/HelloWorld.txt");
+ assert(stream != null);
+
+ byte[] buffer = new byte[20];
+ int length = stream.read(buffer);
+ String s = new String(buffer, 0, length);
+ assert("Hello, World.".equals(s));
+
+ stream.close();
+
+ try {
+ clazz.getResourceAsStream(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ assertNull(clazz.getResourceAsStream("/NonExistentResource"));
+ assertNull(clazz.getResourceAsStream("libcore/java/lang/HelloWorld.txt"));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldDoubleTest.java b/luni/src/test/java/libcore/java/lang/OldDoubleTest.java
new file mode 100644
index 0000000..dacb521
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldDoubleTest.java
@@ -0,0 +1,79 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldDoubleTest extends TestCase {
+
+ public void test_byteValue() {
+ Double d = new Double(Byte.MAX_VALUE);
+ assertEquals("Returned incorrect byte value", Byte.MAX_VALUE, d.byteValue());
+ d= new Double(Byte.MIN_VALUE);
+ assertEquals("Returned incorrect byte value", Byte.MIN_VALUE, d.byteValue());
+ d= new Double(Double.MAX_VALUE);
+ assertEquals("Returned incorrect byte value", -1, d.byteValue());
+ }
+
+ public void test_doubleToLongBitsD() {
+ assertEquals(0x7ff8000000000000L, Double.doubleToLongBits(Double.NaN));
+ assertEquals(0x7ff0000000000000L, Double.doubleToLongBits(Double.POSITIVE_INFINITY));
+ assertEquals(0xfff0000000000000L, Double.doubleToLongBits(Double.NEGATIVE_INFINITY));
+ }
+
+ public void test_doubleToRawLongBitsD() {
+ assertEquals(0x7ff8000000000000L, Double.doubleToLongBits(Double.NaN));
+ assertEquals(0x7ff0000000000000L, Double.doubleToLongBits(Double.POSITIVE_INFINITY));
+ assertEquals(0xfff0000000000000L, Double.doubleToLongBits(Double.NEGATIVE_INFINITY));
+ }
+
+ public void test_doubleValue() {
+ assertEquals(Double.POSITIVE_INFINITY, new Double("1.7976931348623159E308").doubleValue());
+ assertEquals(Double.NEGATIVE_INFINITY, new Double("-1.7976931348623159E308").doubleValue());
+ assertEquals(Double.MAX_VALUE, new Double("1.7976931348623157E308").doubleValue());
+ assertEquals(Double.MIN_VALUE, new Double("4.9E-324").doubleValue());
+ }
+
+ public void test_floatValue() {
+ assertEquals(Float.POSITIVE_INFINITY, new Double("3.4028236E38").floatValue());
+ assertEquals(Float.NEGATIVE_INFINITY, new Double("-3.4028236E38").floatValue());
+ assertEquals(Float.MAX_VALUE, new Double("3.4028235E38").floatValue());
+ assertEquals(Float.MIN_VALUE, new Double("1.4E-45").floatValue());
+ }
+
+ public void test_intValue() {
+ assertEquals("Returned incorrect int value", Integer.MAX_VALUE,
+ new Double(2147483648d).intValue());
+ assertEquals("Returned incorrect int value", Integer.MIN_VALUE,
+ new Double(-2147483649d).intValue());
+ }
+
+ public void test_isNaND() {
+ assertFalse("Doesn't return false value", Double.isNaN(new Double(Double.MAX_VALUE)));
+ }
+
+ // Regression test for hotfix in native code of double parser.
+ public void test_parseDouble_LString_AndroidRegression() {
+ // Android regression test
+ long startTime = System.currentTimeMillis();
+ double actual = Double.parseDouble("9e551027");
+ assertTrue("parsing double 9e551027 took too long.",
+ (System.currentTimeMillis() - startTime) < 1000);
+ assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
+ actual, 0.0D);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldFloatTest.java b/luni/src/test/java/libcore/java/lang/OldFloatTest.java
new file mode 100644
index 0000000..1bbac12
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldFloatTest.java
@@ -0,0 +1,92 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldFloatTest extends TestCase {
+
+ public void test_ConstructorLjava_lang_String() {
+ try {
+ new Float("900.89ff");
+ fail("NumberFormatException is not thrown.");
+ } catch(NumberFormatException nfe) {
+ //expected
+ }
+ }
+
+ public void test_ConstructorD() {
+ Float f = new Float(Double.MAX_VALUE);
+ assertTrue("Created incorrect float", f.floatValue() == Float.POSITIVE_INFINITY);
+ }
+
+ public void test_parseFloatLExceptions() {
+ String [] incorrectStrings = {"", ";", "99999999EE999999", "99999l",
+ "0x1.f.ffffep127"};
+ for(int i = 0; i < incorrectStrings.length; i++) {
+ try {
+ Float.parseFloat(incorrectStrings[i]);
+ fail("NumberFormatException is not thrown for string: "
+ + incorrectStrings[i]);
+ } catch(NumberFormatException nfe) {
+ //expected
+ }
+ }
+ }
+
+ public void test_floatToIntBitsF() {
+ assertEquals(0x7f800000, Float.floatToIntBits(Float.POSITIVE_INFINITY));
+ assertEquals(0xff800000, Float.floatToIntBits(Float.NEGATIVE_INFINITY));
+ assertEquals(0x7fc00000, Float.floatToIntBits(Float.NaN));
+ }
+
+ public void test_floatToRawIntBitsF() {
+ assertEquals(0x7f800000, Float.floatToRawIntBits(Float.POSITIVE_INFINITY));
+ assertEquals(0xff800000, Float.floatToRawIntBits(Float.NEGATIVE_INFINITY));
+ assertEquals(0x7fc00000, Float.floatToRawIntBits(Float.NaN));
+ }
+
+ public void test_hashCode() {
+ assertTrue(new Float(Float.MAX_VALUE).hashCode() != new Float(Float.MIN_VALUE).hashCode());
+ }
+
+ public void test_intBitsToFloatI() {
+ assertEquals(Float.POSITIVE_INFINITY, Float.intBitsToFloat(0x7f800000));
+ assertEquals(Float.NEGATIVE_INFINITY, Float.intBitsToFloat(0xff800000));
+
+ assertEquals(Float.NaN, Float.intBitsToFloat(0x7f800001));
+ assertEquals(Float.NaN, Float.intBitsToFloat(0x7fffffff));
+ assertEquals(Float.NaN, Float.intBitsToFloat(0xff800001));
+ assertEquals(Float.NaN, Float.intBitsToFloat(0xffffffff));
+ }
+
+ public void test_intValue() {
+ assertEquals(Integer.MAX_VALUE, new Float(Float.MAX_VALUE).intValue());
+ assertEquals(0, new Float(Float.MIN_VALUE).intValue());
+ }
+
+ public void test_isNaNF() {
+ assertFalse(Float.isNaN(12.09f));
+ assertFalse(Float.isNaN(Float.MAX_VALUE));
+ assertFalse(Float.isNaN(Float.MIN_VALUE));
+ }
+
+ public void test_longValue() {
+ assertEquals(Long.MAX_VALUE, new Float(Float.MAX_VALUE).longValue());
+ assertEquals(0, new Float(Float.MIN_VALUE).longValue());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldInheritableThreadLocalTest.java b/luni/src/test/java/libcore/java/lang/OldInheritableThreadLocalTest.java
new file mode 100644
index 0000000..dd9b9f4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldInheritableThreadLocalTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldInheritableThreadLocalTest extends TestCase {
+
+ public void test_Ljava_lang_InheritableThreadLocal()
+ throws InterruptedException {
+ final Object value = new Object();
+ final Object inheritedValue = new Object();
+ final ThreadLocal<Object> threadLocal
+ = new InheritableThreadLocal<Object>() {
+ @Override
+ protected Object childValue(Object parentValue) {
+ assertSame(value, parentValue);
+ return inheritedValue;
+ }
+ };
+ threadLocal.set(value);
+ final Object[] holder = new Object[1];
+ Thread thread = new Thread() {
+ public void run() {
+ holder[0] = threadLocal.get();
+ }
+ };
+ thread.start();
+ thread.join();
+ assertSame(value, threadLocal.get());
+ assertSame(inheritedValue, holder[0]);
+
+ // Cleanup properly, so other tests are not affected.
+ threadLocal.remove();
+ }
+
+ public void test_childValue() {
+ InheritableThreadLocal<String> itl = new InheritableThreadLocal<String>() {
+ @Override
+ protected String initialValue() {
+ return "initial";
+ }
+ @Override
+ protected String childValue(String parentValue) {
+ return "childValue";
+ }
+ };
+ assertEquals("initial", itl.get());
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldIntegerTest.java b/luni/src/test/java/libcore/java/lang/OldIntegerTest.java
new file mode 100644
index 0000000..462ee19
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldIntegerTest.java
@@ -0,0 +1,69 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.util.Properties;
+import junit.framework.TestCase;
+
+public class OldIntegerTest extends TestCase {
+ private Properties orgProps;
+
+ @Override
+ protected void setUp() {
+ orgProps = System.getProperties();
+ }
+
+ @Override
+ protected void tearDown() {
+ System.setProperties(orgProps);
+ }
+
+ public void test_getIntegerLjava_lang_StringI() {
+ // Test for method java.lang.Integer
+ // java.lang.Integer.getInteger(java.lang.String, int)
+ Properties tProps = new Properties();
+ tProps.put("testIncInt", "notInt");
+ System.setProperties(tProps);
+ assertTrue("returned incorrect default Integer", Integer.getInteger(
+ "testIncInt", 4).equals(new Integer(4)));
+ }
+
+ public void test_getIntegerLjava_lang_StringLjava_lang_Integer() {
+ // Test for method java.lang.Integer
+ // java.lang.Integer.getInteger(java.lang.String, java.lang.Integer)
+ Properties tProps = new Properties();
+ tProps.put("testIncInt", "notInt");
+ System.setProperties(tProps);
+ assertTrue("returned incorrect default Integer", Integer.getInteger(
+ "testIncInt", new Integer(4)).equals(new Integer(4)));
+ }
+
+ public void test_intValue() {
+ assertEquals(Integer.MAX_VALUE, new Integer(Integer.MAX_VALUE).intValue());
+ assertEquals(Integer.MIN_VALUE, new Integer(Integer.MIN_VALUE).intValue());
+ }
+
+ public void test_longValue() {
+ assertEquals(Integer.MAX_VALUE, new Integer(Integer.MAX_VALUE).longValue());
+ assertEquals(Integer.MIN_VALUE, new Integer(Integer.MIN_VALUE).longValue());
+ }
+
+ public void test_shortValue() {
+ assertEquals(-1, new Integer(Integer.MAX_VALUE).shortValue());
+ assertEquals(0, new Integer(Integer.MIN_VALUE).shortValue());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldLongTest.java b/luni/src/test/java/libcore/java/lang/OldLongTest.java
new file mode 100644
index 0000000..6fb7d49
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldLongTest.java
@@ -0,0 +1,83 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.util.Properties;
+import junit.framework.TestCase;
+
+public class OldLongTest extends TestCase {
+ private Properties orgProps;
+
+ @Override
+ protected void setUp() {
+ orgProps = System.getProperties();
+ }
+
+ @Override
+ protected void tearDown() {
+ System.setProperties(orgProps);
+ }
+
+ public void test_getLongLjava_lang_String() {
+ Properties tProps = new Properties();
+ tProps.put("testLong", "99");
+ tProps.put("testIncLong", "string");
+ System.setProperties(tProps);
+ assertNull("returned incorrect default Long",
+ Long.getLong("testIncLong"));
+ }
+
+ public void test_getLongLjava_lang_StringJ() {
+ // Test for method java.lang.Long
+ // java.lang.Long.getLong(java.lang.String, long)
+ Properties tProps = new Properties();
+ tProps.put("testIncLong", "string");
+ System.setProperties(tProps);
+ assertTrue("returned incorrect default Long", Long.getLong("testIncLong", 4L)
+ .equals(new Long(4)));
+ }
+
+ public void test_getLongLjava_lang_StringLjava_lang_Long() {
+ // Test for method java.lang.Long
+ // java.lang.Long.getLong(java.lang.String, java.lang.Long)
+ Properties tProps = new Properties();
+ tProps.put("testIncLong", "string");
+ System.setProperties(tProps);
+ assertTrue("returned incorrect default Long", Long.getLong("testIncLong",
+ new Long(4)).equals(new Long(4)));
+ }
+
+ public void test_floatValue() {
+ assertEquals(Long.MAX_VALUE, new Long(Long.MAX_VALUE).floatValue(), 0F);
+ assertEquals(Long.MIN_VALUE, new Long(Long.MIN_VALUE).floatValue(), 0F);
+ }
+
+ public void test_intValue() {
+ assertEquals(-1, new Long(Long.MAX_VALUE).intValue());
+ assertEquals(0, new Long(Long.MIN_VALUE).intValue());
+ }
+
+ public void test_longValue() {
+ assertEquals(Long.MAX_VALUE, new Long(Long.MAX_VALUE).longValue());
+ assertEquals(Long.MIN_VALUE, new Long(Long.MIN_VALUE).longValue());
+ }
+
+ public void test_shortValue() {
+ assertEquals(-1, new Long(Long.MAX_VALUE).shortValue());
+ assertEquals(0, new Long(Long.MIN_VALUE).shortValue());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldObjectTest.java b/luni/src/test/java/libcore/java/lang/OldObjectTest.java
new file mode 100644
index 0000000..dd0e217
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldObjectTest.java
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.lang;
+
+import dalvik.annotation.SideEffect;
+import java.util.Vector;
+import junit.framework.TestCase;
+
+public class OldObjectTest extends TestCase {
+
+ public boolean isCalled = false;
+
+ /**
+ * Test objects.
+ */
+ Object obj1 = new Object();
+
+ /**
+ * Generic state indicator.
+ */
+ int status = 0;
+
+ int ready = 0;
+ TestThread1 thr1;
+ TestThread2 thr2;
+
+
+ @SideEffect("Causes OutOfMemoryError to test finalization")
+ public void test_finalize() {
+ isCalled = false;
+ class TestObject extends Object {
+
+ Vector<StringBuffer> v = new Vector<StringBuffer>();
+ public void add() {
+ v.add(new StringBuffer(10000));
+ }
+
+ protected void finalize() throws Throwable {
+ isCalled = true;
+ super.finalize();
+ }
+ }
+
+ TestObject to = new TestObject();
+
+ try {
+ while(true) {
+ to.add();
+ }
+ } catch(OutOfMemoryError oome) {
+ //expected
+ to = null;
+ }
+ System.gc();
+ System.runFinalization();
+ assertTrue(isCalled);
+ }
+
+ public void test_clone() {
+ MockCloneableObject mco = new MockCloneableObject();
+ try {
+ assertFalse(mco.equals(mco.clone()));
+ assertEquals(mco.getClass(), mco.clone().getClass());
+ } catch(CloneNotSupportedException cnse) {
+ fail("CloneNotSupportedException was thrown.");
+ }
+
+ MockObject mo = new MockObject();
+ try {
+ mo.clone();
+ fail("CloneNotSupportedException was not thrown.");
+ } catch(CloneNotSupportedException cnse) {
+ //expected
+ }
+ }
+
+ class MockCloneableObject extends Object implements Cloneable {
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+ class MockObject extends Object {
+
+ boolean isCalled = false;
+
+ public void finalize() throws Throwable {
+ super.finalize();
+ isCalled = true;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+ public void test_notify() {
+ try {
+ Object obj = new Object();
+ obj.notify();
+ fail("IllegalMonitorStateException was not thrown.");
+ } catch(IllegalMonitorStateException imse) {
+ //expected
+ }
+ }
+
+ public void test_notifyAll() {
+ try {
+ Object obj = new Object();
+ obj.notifyAll();
+ fail("IllegalMonitorStateException was not thrown.");
+ } catch(IllegalMonitorStateException imse) {
+ //expected
+ }
+ }
+
+ public void test_wait() {
+
+ try {
+ Object obj = new Object();
+ obj.wait();
+ fail("IllegalMonitorStateException was not thrown.");
+ } catch(IllegalMonitorStateException imse) {
+ //expected
+ } catch(InterruptedException ex) {
+ fail("InterruptedException was thrown.");
+ }
+
+ try {
+ thr1 = new TestThread1(TestThread1.CASE_WAIT);
+ thr2 = new TestThread2();
+ thr1.start();
+ thr2.start();
+ thr2.join();
+ thr1.join();
+ thr1 = null;
+ thr2 = null;
+ } catch(InterruptedException e) {
+ fail("InterruptedException was thrown.");
+ }
+ assertEquals(3, status);
+ }
+
+ class TestThread1 extends Thread {
+
+ static final int CASE_WAIT = 0;
+ static final int CASE_WAIT_LONG = 1;
+ static final int CASE_WAIT_LONG_INT = 2;
+
+ int testCase = CASE_WAIT;
+
+ public TestThread1(int option) {
+ testCase = option;
+ }
+
+ public void run() {
+ synchronized (obj1) {
+ try {
+ switch(testCase) {
+ case CASE_WAIT:
+ obj1.wait();// Wait for ever.
+ break;
+ case CASE_WAIT_LONG:
+ obj1.wait(5000L);
+ break;
+ case CASE_WAIT_LONG_INT:
+ obj1.wait(10000L, 999999);
+ break;
+ }
+
+ } catch (InterruptedException ex) {
+ status = 3;
+ }
+ }
+ }
+ }
+
+ class TestThread2 extends Thread {
+ public void run() {
+ thr1.interrupt();
+ }
+ }
+
+ public void test_waitJI() {
+ try {
+ Object obj = new Object();
+ obj.wait(5000L, 1);
+ fail("IllegalMonitorStateException was not thrown.");
+ } catch(IllegalMonitorStateException imse) {
+ //expected
+ } catch(InterruptedException ex) {
+ fail("InterruptedException was thrown.");
+ }
+
+ try {
+ thr1 = new TestThread1(TestThread1.CASE_WAIT_LONG_INT);
+ thr2 = new TestThread2();
+ thr1.start();
+ thr2.start();
+ thr2.join();
+ thr1.join();
+ thr1 = null;
+ thr2 = null;
+ } catch(InterruptedException e) {
+ fail("InterruptedException was thrown.");
+ }
+ assertEquals(3, status);
+
+ }
+
+ public void test_waitJ() {
+ try {
+ Object obj = new Object();
+ obj.wait(5000L);
+ fail("IllegalMonitorStateException was not thrown.");
+ } catch(IllegalMonitorStateException imse) {
+ //expected
+ } catch(InterruptedException ex) {
+ fail("InterruptedException was thrown.");
+ }
+
+ try {
+ thr1 = new TestThread1(TestThread1.CASE_WAIT_LONG);
+ thr2 = new TestThread2();
+ thr1.start();
+ thr2.start();
+ thr2.join();
+ thr1.join();
+ thr1 = null;
+ thr2 = null;
+ } catch(InterruptedException e) {
+ fail("InterruptedException was thrown.");
+ }
+ assertEquals(3, status);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldRuntimeExceptionTest.java b/luni/src/test/java/libcore/java/lang/OldRuntimeExceptionTest.java
new file mode 100644
index 0000000..8004124
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldRuntimeExceptionTest.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldRuntimeExceptionTest extends TestCase {
+
+ public void test_ConstructorLStringLThrowable() {
+ String message = "Test message";
+ NullPointerException npe = new NullPointerException();
+ RuntimeException re = new RuntimeException(message, npe);
+ assertEquals(message, re.getMessage());
+ assertEquals(npe, re.getCause());
+
+ re = new RuntimeException(null, npe);
+ assertNull(re.getMessage());
+
+ re = new RuntimeException(message, null);
+ assertNull(re.getCause());
+ }
+
+ public void test_ConstructorLThrowable() {
+ NullPointerException npe = new NullPointerException();
+ RuntimeException re = new RuntimeException(npe);
+ assertEquals(npe, re.getCause());
+
+ re = new RuntimeException((Throwable) null);
+ assertNull(re.getCause());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java b/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java
new file mode 100644
index 0000000..4b692d7
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldRuntimeTest.java
@@ -0,0 +1,550 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import dalvik.annotation.KnownFailure;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Permission;
+import java.util.Arrays;
+import java.util.Vector;
+import tests.support.resource.Support_Resources;
+
+public class OldRuntimeTest extends junit.framework.TestCase {
+
+ Runtime r = Runtime.getRuntime();
+
+ InputStream is;
+
+ public void test_freeMemory() {
+ // Heap might grow or do GC at any time,
+ // so we can't really test a lot. Hence
+ // we are just doing some basic sanity
+ // checks here.
+ assertTrue("must have some free memory",
+ r.freeMemory() > 0);
+
+ assertTrue("must not exceed total memory",
+ r.freeMemory() < r.totalMemory());
+
+ long before = r.totalMemory() - r.freeMemory();
+ Vector<byte[]> v = new Vector<byte[]>();
+ for (int i = 1; i < 10; i++) {
+ v.addElement(new byte[10000]);
+ }
+ long after = r.totalMemory() - r.freeMemory();
+
+ assertTrue("free memory must change with allocations",
+ after != before);
+ }
+
+ public void test_getRuntime() {
+ // Test for method java.lang.Runtime java.lang.Runtime.getRuntime()
+ assertNotNull(Runtime.getRuntime());
+ }
+
+ public void test_addShutdownHook() {
+ Thread thrException = new Thread () {
+ public void run() {
+ try {
+ Runtime.getRuntime().addShutdownHook(this);
+ fail("IllegalStateException was not thrown.");
+ } catch(IllegalStateException ise) {
+ //expected
+ }
+ }
+ };
+
+ try {
+ Runtime.getRuntime().addShutdownHook(thrException);
+ } catch (Throwable t) {
+ fail(t.getMessage());
+ }
+
+ try {
+ Runtime.getRuntime().addShutdownHook(thrException);
+ fail("IllegalArgumentException was not thrown.");
+ } catch(IllegalArgumentException iae) {
+ // expected
+ }
+
+ SecurityManager sm = new SecurityManager() {
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals("shutdownHooks")) {
+ throw new SecurityException();
+ }
+ }
+ };
+
+ // remove previously added hook so we're not depending on the priority
+ // of the Exceptions to be thrown.
+ Runtime.getRuntime().removeShutdownHook(thrException);
+
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ public void test_availableProcessors() {
+ assertTrue(Runtime.getRuntime().availableProcessors() > 0);
+ }
+
+
+ public void test_execLjava_lang_StringLjava_lang_StringArray() {
+ String [] envp = getEnv();
+
+ checkExec(0, envp, null);
+ checkExec(0, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String)null, null);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ SecurityManager sm = new SecurityManager() {
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals("checkExec")) {
+ throw new SecurityException();
+ }
+ }
+
+ public void checkExec(String cmd) {
+ throw new SecurityException();
+ }
+ };
+
+ try {
+ Runtime.getRuntime().exec("", envp);
+ fail("IllegalArgumentException should be thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+ }
+
+ public void test_execLjava_lang_StringArrayLjava_lang_StringArray() {
+ String [] envp = getEnv();
+
+ checkExec(4, envp, null);
+ checkExec(4, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String[])null, null);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{"ls", null}, null);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ SecurityManager sm = new SecurityManager() {
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals("checkExec")) {
+ throw new SecurityException();
+ }
+ }
+
+ public void checkExec(String cmd) {
+ throw new SecurityException();
+ }
+ };
+
+ try {
+ Runtime.getRuntime().exec(new String[]{}, envp);
+ fail("IndexOutOfBoundsException should be thrown.");
+ } catch(IndexOutOfBoundsException ioob) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{""}, envp);
+ fail("IOException should be thrown.");
+ } catch (IOException e) { /* expected */ }
+ }
+
+ public void test_execLjava_lang_StringLjava_lang_StringArrayLjava_io_File() {
+
+ String [] envp = getEnv();
+
+ File workFolder = Support_Resources.createTempFolder();
+
+ checkExec(2, envp, workFolder);
+ checkExec(2, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String)null, null, workFolder);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ SecurityManager sm = new SecurityManager() {
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals("checkExec")) {
+ throw new SecurityException();
+ }
+ }
+
+ public void checkExec(String cmd) {
+ throw new SecurityException();
+ }
+ };
+
+ try {
+ Runtime.getRuntime().exec("", envp, workFolder);
+ fail("SecurityException should be thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+ }
+
+ public void test_execLjava_lang_StringArrayLjava_lang_StringArrayLjava_io_File() {
+ String [] envp = getEnv();
+
+ File workFolder = Support_Resources.createTempFolder();
+
+ checkExec(5, envp, workFolder);
+ checkExec(5, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String[])null, null, workFolder);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{"ls", null}, null, workFolder);
+ fail("NullPointerException should be thrown.");
+ } catch(IOException ioe) {
+ fail("IOException was thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ SecurityManager sm = new SecurityManager() {
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals("checkExec")) {
+ throw new SecurityException();
+ }
+ }
+
+ public void checkExec(String cmd) {
+ throw new SecurityException();
+ }
+ };
+
+ try {
+ Runtime.getRuntime().exec(new String[]{""}, envp, workFolder);
+ fail("IOException should be thrown.");
+ } catch (IOException e) {
+ //expected
+ }
+ }
+
+ String [] getEnv() {
+ Object [] valueSet = System.getenv().values().toArray();
+ Object [] keySet = System.getenv().keySet().toArray();
+ String [] envp = new String[valueSet.length];
+ for(int i = 0; i < envp.length; i++) {
+ envp[i] = keySet[i] + "=" + valueSet[i];
+ }
+ return envp;
+ }
+
+ void checkExec(int testCase, String [] envp, File file) {
+ String dirName = "Test_Directory";
+ String dirParentName = "Parent_Directory";
+ File resources = Support_Resources.createTempFolder();
+ String folder = resources.getAbsolutePath() + "/" + dirName;
+ String folderWithParent = resources.getAbsolutePath() + "/" +
+ dirParentName + "/" + dirName;
+ String command = "mkdir " + folder;
+ String [] commandArguments = {"mkdir", folder};
+ try {
+ Process proc = null;
+ switch(testCase) {
+ case 0:
+ proc = Runtime.getRuntime().exec(command, envp);
+ break;
+ case 1:
+ proc = Runtime.getRuntime().exec(command);
+ break;
+ case 2:
+ proc = Runtime.getRuntime().exec(command, envp, file);
+ break;
+ case 3:
+ proc = Runtime.getRuntime().exec(commandArguments);
+ break;
+ case 4:
+ proc = Runtime.getRuntime().exec(commandArguments, envp);
+ break;
+ case 5:
+ proc = Runtime.getRuntime().exec(commandArguments, envp, file);
+ break;
+ }
+ assertNotNull(proc);
+ try {
+ Thread.sleep(3000);
+ } catch(InterruptedException ie) {
+ fail("InterruptedException was thrown.");
+ }
+ File f = new File(folder);
+ assertTrue(f.exists());
+ if(f.exists()) {
+ f.delete();
+ }
+ } catch(IOException io) {
+ fail("IOException was thrown.");
+ }
+ }
+
+ public void test_execLjava_lang_String() {
+ checkExec(1, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String) null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+
+ try {
+ Runtime.getRuntime().exec("");
+ fail("IllegalArgumentException was not thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+ }
+
+ public void test_execLjava_lang_StringArray() {
+
+ checkExec(3, null, null);
+
+ try {
+ Runtime.getRuntime().exec((String[]) null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{"ls", null});
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{});
+ fail("IndexOutOfBoundsException was not thrown.");
+ } catch(IndexOutOfBoundsException iobe) {
+ //expected
+ } catch (IOException e) {
+ fail("IOException was thrown.");
+ }
+
+ try {
+ Runtime.getRuntime().exec(new String[]{""});
+ fail("IOException should be thrown.");
+ } catch (IOException e) {
+ //expected
+ }
+ }
+
+ public void test_runFinalizersOnExit() {
+ Runtime.getRuntime().runFinalizersOnExit(true);
+ }
+
+ public void test_removeShutdownHookLjava_lang_Thread() {
+ Thread thr1 = new Thread () {
+ public void run() {
+ try {
+ Runtime.getRuntime().addShutdownHook(this);
+ } catch(IllegalStateException ise) {
+ fail("IllegalStateException shouldn't be thrown.");
+ }
+ }
+ };
+
+ try {
+ Runtime.getRuntime().addShutdownHook(thr1);
+ Runtime.getRuntime().removeShutdownHook(thr1);
+ } catch (Throwable t) {
+ fail(t.getMessage());
+ }
+
+ Thread thr2 = new Thread () {
+ public void run() {
+ try {
+ Runtime.getRuntime().removeShutdownHook(this);
+ fail("IllegalStateException wasn't thrown.");
+ } catch(IllegalStateException ise) {
+ //expected
+ }
+ }
+ };
+
+ try {
+ Runtime.getRuntime().addShutdownHook(thr2);
+ } catch (Throwable t) {
+ fail(t.getMessage());
+ }
+
+ try {
+ Thread.currentThread().sleep(1000);
+ } catch (InterruptedException ie) {
+ }
+ }
+
+ public void test_maxMemory() {
+ assertTrue(Runtime.getRuntime().maxMemory() < Long.MAX_VALUE);
+ }
+
+ public void test_traceInstructions() {
+ Runtime.getRuntime().traceInstructions(false);
+ Runtime.getRuntime().traceInstructions(true);
+ Runtime.getRuntime().traceInstructions(false);
+ }
+
+ @KnownFailure("Fails in CTS but passes under run-core-tests")
+ public void test_traceMethodCalls() {
+ try {
+ Runtime.getRuntime().traceMethodCalls(false);
+ Runtime.getRuntime().traceMethodCalls(true);
+ Runtime.getRuntime().traceMethodCalls(false);
+ } catch (RuntimeException ex) {
+ // Slightly ugly: we default to the SD card, which may or may not
+ // be there. So we also accept the error case as a success, since
+ // it means we actually did enable tracing (or tried to).
+ if (!"file open failed".equals(ex.getMessage())) {
+ throw ex;
+ }
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void test_getLocalizedInputStream() throws Exception {
+ String simpleString = "Heart \u2f3c";
+ byte[] expected = simpleString.getBytes("UTF-8");
+ byte[] returned = new byte[expected.length];
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(
+ simpleString.getBytes("UTF-8"));
+
+ InputStream lcIn =
+ Runtime.getRuntime().getLocalizedInputStream(bais);
+ lcIn.read(returned);
+
+ assertTrue("wrong result for String: " + simpleString,
+ Arrays.equals(expected, returned));
+ }
+
+ @SuppressWarnings("deprecation")
+ public void test_getLocalizedOutputStream() throws IOException {
+ String simpleString = "Heart \u2f3c";
+ byte[] expected = simpleString.getBytes("UTF-8");
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ OutputStream lcOut =
+ Runtime.getRuntime().getLocalizedOutputStream(out);
+ lcOut.write(simpleString.getBytes("UTF-8"));
+ lcOut.flush();
+ lcOut.close();
+
+ byte[] returned = out.toByteArray();
+
+ assertTrue("wrong result for String: " + returned.toString() +
+ " expected string: " + expected.toString(),
+ Arrays.equals(expected, returned));
+ }
+
+
+ public void test_load() {
+ try {
+ Runtime.getRuntime().load("nonExistentLibrary");
+ fail("UnsatisfiedLinkError was not thrown.");
+ } catch(UnsatisfiedLinkError ule) {
+ //expected
+ }
+
+ try {
+ Runtime.getRuntime().load(null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_loadLibrary() {
+ try {
+ Runtime.getRuntime().loadLibrary("nonExistentLibrary");
+ fail("UnsatisfiedLinkError was not thrown.");
+ } catch(UnsatisfiedLinkError ule) {
+ //expected
+ }
+
+ try {
+ Runtime.getRuntime().loadLibrary(null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java b/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java
new file mode 100644
index 0000000..9a09c45
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldStackTraceElementTest.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldStackTraceElementTest extends TestCase {
+
+ public class Original extends TestCase {
+
+ public void pureJavaMethod(Object test) throws Exception {
+ throw new Exception("pure java method");
+ }
+
+ native public void pureNativeMethod(Object test);
+ }
+
+ private Original original;
+
+ @Override
+ protected void setUp() throws Exception {
+ original = new Original();
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_StringI() {
+ StackTraceElement ste2 = null;
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ StackTraceElement ste1 = e.getStackTrace()[0];
+ ste2 = new StackTraceElement(ste1.getClassName(),
+ ste1.getMethodName(),
+ ste1.getFileName(),
+ ste1.getLineNumber());
+ assertEquals("Incorrect value of class name",
+ ste1.getClassName(), ste2.getClassName());
+ assertEquals("Incorrect value of method name",
+ ste1.getMethodName(), ste2.getMethodName());
+ assertEquals("Incorrect value of file name",
+ ste1.getFileName(), ste2.getFileName());
+ assertEquals("Incorrect value of line number",
+ ste1.getLineNumber(), ste2.getLineNumber());
+ }
+ assertNotNull("Incorrect stack trace object", ste2);
+ try {
+ new StackTraceElement(null,
+ ste2.getMethodName(),
+ ste2.getFileName(),
+ ste2.getLineNumber());
+ fail("Expected NullPointerException was not thrown");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ new StackTraceElement(ste2.getClassName(),
+ null,
+ ste2.getFileName(),
+ ste2.getLineNumber());
+ fail("Expected NullPointerException was not thrown");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ new StackTraceElement(ste2.getClassName(),
+ ste2.getMethodName(),
+ null,
+ ste2.getLineNumber());
+ } catch (NullPointerException e) {
+ fail("Unexpected exception " + e.toString());
+ }
+ }
+
+ public void test_equalsLjava_lang_Object() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ StackTraceElement ste1 = e.getStackTrace()[0];
+ StackTraceElement ste2 =
+ new StackTraceElement(ste1.getClassName(),
+ ste1.getMethodName(),
+ ste1.getFileName(),
+ ste1.getLineNumber());
+ assertEquals("Objects are equaled", ste1, ste2);
+ }
+ }
+
+ public void test_getClassName() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ assertEquals("Incorrect class name",
+ "libcore.java.lang.OldStackTraceElementTest$Original",
+ e.getStackTrace()[0].getClassName());
+ assertEquals("Incorrect class name",
+ "libcore.java.lang.OldStackTraceElementTest",
+ e.getStackTrace()[1].getClassName());
+ }
+ }
+
+ public void test_getFileName() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ assertEquals("Incorrect file name",
+ "OldStackTraceElementTest.java",
+ e.getStackTrace()[0].getFileName());
+ assertEquals("Incorrect file name",
+ "OldStackTraceElementTest.java",
+ e.getStackTrace()[1].getFileName());
+ }
+ }
+
+ public void test_getLineNumber() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ assertEquals("Incorrect line number",
+ 26, e.getStackTrace()[0].getLineNumber());
+ }
+ }
+
+ public void test_getMethodName() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ assertEquals("Incorrect method name",
+ "pureJavaMethod",
+ e.getStackTrace()[0].getMethodName());
+ assertEquals("Incorrect method name",
+ "test_getMethodName",
+ e.getStackTrace()[1].getMethodName());
+ }
+ }
+
+ public void test_hashCode() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ StackTraceElement ste1 = e.getStackTrace()[0];
+ StackTraceElement ste2 =
+ new StackTraceElement(ste1.getClassName(),
+ ste1.getMethodName(),
+ ste1.getFileName(),
+ ste1.getLineNumber());
+ assertEquals("Incorrect value of hash code",
+ ste1.hashCode(), ste2.hashCode());
+ assertFalse("Incorrect value of hash code",
+ ste1.hashCode() == e.getStackTrace()[1].hashCode());
+ }
+ }
+
+ public void test_isNativeMethod() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ assertFalse("Incorrect method type",
+ e.getStackTrace()[0].isNativeMethod());
+ }
+ try {
+ original.pureNativeMethod(new Object());
+ fail();
+ } catch (Error e) {
+ assertTrue("Incorrect method type",
+ e.getStackTrace()[0].isNativeMethod());
+ }
+ }
+
+ public void test_toString() {
+ try {
+ original.pureJavaMethod(new Object());
+ fail();
+ } catch (Exception e) {
+ StackTraceElement ste = e.getStackTrace()[0];
+ assertTrue("String representation doesn't contain a package name",
+ ste.toString().contains(getClass().getPackage().getName()));
+ assertTrue("String representation doesn't contain a class name",
+ ste.toString().contains("Original"));
+ assertTrue("String representation doesn't contain a file name",
+ ste.toString().contains("OldStackTraceElementTest.java"));
+ assertTrue("String representation doesn't contain a line number",
+ ste.toString().contains("26"));
+ assertTrue("String representation doesn't contain a method name",
+ ste.toString().contains("pureJavaMethod"));
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldStringBufferTest.java b/luni/src/test/java/libcore/java/lang/OldStringBufferTest.java
new file mode 100644
index 0000000..84828c4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldStringBufferTest.java
@@ -0,0 +1,329 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+public class OldStringBufferTest extends junit.framework.TestCase {
+
+ StringBuffer testBuffer = new StringBuffer("This is a test buffer");
+
+ public void test_deleteCharAtI() {
+ try {
+ testBuffer.deleteCharAt(testBuffer.length() + 1);
+ fail("StringIndexOutOfBoundsException was not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.deleteCharAt(-1);
+ fail("StringIndexOutOfBoundsException was not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_ensureCapacityI() {
+ // Test for method void java.lang.StringBuffer.ensureCapacity(int)
+ StringBuffer sb = new StringBuffer(10);
+
+ sb.ensureCapacity(-2);
+ assertEquals("Failed to increase capacity.", 10, sb.capacity());
+
+
+ try {
+ sb.ensureCapacity(Integer.MAX_VALUE);
+ fail("OutOfMemoryError should be thrown.");
+ } catch(java.lang.OutOfMemoryError oome) {
+ //expected
+ }
+ }
+
+ public void test_getCharsII$CI() {
+ StringBuffer buf2 = new StringBuffer("");
+ try {
+ buf2.getChars(-1, 0, new char[5], 2);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ buf2.getChars(0, -1, new char[5], 2);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ buf2.getChars(0, -1, new char[5], 2);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ buf2.getChars(2, 1, new char[5], 2);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ buf2.getChars(0, 6, new char[5], 2);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+
+ try {
+ buf2.getChars(0, 6, new char[10], 5);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch (IndexOutOfBoundsException e) {
+ //expected
+ }
+ }
+
+ public void test_insertID() {
+ try {
+ testBuffer.insert(-1, Double.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, Double.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertIF() {
+ try {
+ testBuffer.insert(-1, Float.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, Float.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertII() {
+ try {
+ testBuffer.insert(-1, Integer.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, Integer.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertIJ() {
+ try {
+ testBuffer.insert(-1, Long.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, Long.MAX_VALUE);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertILjava_lang_Object() {
+ Object obj1 = new Object();
+ try {
+ testBuffer.insert(-1, obj1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, obj1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertILjava_lang_String() {
+ try {
+ testBuffer.insert(-1, "");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(testBuffer.length() + 1, "");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_insertIZ() {
+ try {
+ testBuffer.insert(testBuffer.length() + 1, true);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.insert(-1, true);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_replaceIILjava_lang_String() {
+ try {
+ testBuffer.replace(-1, 0, "text");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.replace(0, -1, "text");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.replace(2, 1, "text");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.replace(testBuffer.length() + 1, testBuffer.length() + 1,
+ "text");
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException sioobe) {
+ //expected
+ }
+ }
+
+ public void test_setCharAtIC() {
+ StringBuffer s = new StringBuffer("HelloWorld");
+ try {
+ s.setCharAt(-1, 'Z');
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+ try {
+ s.setCharAt(s.length() + 1, 'Z');
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+ }
+
+ public void test_substringI() {
+ try {
+ testBuffer.substring(testBuffer.length() + 1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException oobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.substring(-1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException oobe) {
+ //expected
+ }
+ }
+
+ public void test_substringII() {
+ try {
+ testBuffer.substring(-1, testBuffer.length());
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException oobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.substring(0, -1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException oobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.substring(2, 1);
+ fail("StringIndexOutOfBoundsException is not thrown.");
+ } catch(StringIndexOutOfBoundsException oobe) {
+ //expected
+ }
+ }
+
+ public void test_subSequence() {
+ assertEquals("Incorrect substring returned", " is",
+ testBuffer.subSequence(4, 7));
+ assertEquals("Incorrect substring returned", "test buffer",
+ testBuffer.subSequence(10, 21));
+ assertEquals("not identical", "This is a test buffer",
+ testBuffer.subSequence(0, testBuffer.length()));
+
+ try {
+ testBuffer.subSequence(0, Integer.MAX_VALUE);
+ fail("IndexOutOfBoundsException was not thrown.");
+ } catch (IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.subSequence(Integer.MAX_VALUE, testBuffer.length());
+ fail("IndexOutOfBoundsException was not thrown.");
+ } catch (IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ testBuffer.subSequence(-1, testBuffer.length());
+ fail("IndexOutOfBoundsException was not thrown.");
+ } catch (IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldStringTest.java b/luni/src/test/java/libcore/java/lang/OldStringTest.java
index 42eb048..33c3215 100644
--- a/luni/src/test/java/libcore/java/lang/OldStringTest.java
+++ b/luni/src/test/java/libcore/java/lang/OldStringTest.java
@@ -93,24 +93,21 @@ public class OldStringTest extends junit.framework.TestCase {
try {
"Hello World".getBytes(-1, 1, null, 0);
fail("Expected IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- } catch (NullPointerException e) {
- fail("Threw wrong exception");
+ } catch (IndexOutOfBoundsException expected) {
+ } catch (NullPointerException expected) {
}
try {
"Hello World".getBytes(6, 2, null, 0);
fail("IndexOutOfBoundsException was not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
+ } catch (IndexOutOfBoundsException expected) {
+ } catch (NullPointerException expected) {
}
try {
"Hello World".getBytes(2, 10, new byte[10], 4);
fail("IndexOutOfBoundsException was not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
+ } catch (IndexOutOfBoundsException expected) {
}
}
@@ -118,24 +115,21 @@ public class OldStringTest extends junit.framework.TestCase {
try {
"Hello World".getChars(-1, 1, null, 0);
fail("Expected IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- } catch (NullPointerException e) {
- fail("Threw wrong exception");
+ } catch (IndexOutOfBoundsException expected) {
+ } catch (NullPointerException expected) {
}
try {
"Hello World".getChars(6, 2, null, 0);
fail("IndexOutOfBoundsException was not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
+ } catch (IndexOutOfBoundsException expected) {
+ } catch (NullPointerException expected) {
}
try {
"Hello World".getChars(2, 10, new char[10], 4);
fail("IndexOutOfBoundsException was not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
+ } catch (IndexOutOfBoundsException expected) {
}
}
diff --git a/luni/src/test/java/libcore/java/lang/OldSystemTest.java b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
new file mode 100644
index 0000000..dee5bdd
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldSystemTest.java
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.io.IOException;
+import java.nio.channels.Channel;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+public class OldSystemTest extends junit.framework.TestCase {
+
+ public void test_arraycopyLjava_lang_ObjectILjava_lang_ObjectII() {
+ // Test for method void java.lang.System.arraycopy(java.lang.Object,
+ // int, java.lang.Object, int, int)
+ Integer a[] = new Integer[20];
+ Integer b[] = new Integer[20];
+
+ try {
+ // copy from non array object into Object array
+ System.arraycopy(new Object(), 0, b, 0, 0);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from Object array into non array object
+ System.arraycopy(a, 0, new Object(), 0, 0);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from primitive array into object array
+ System.arraycopy(new char[] {'a'}, 0, new String[1], 0, 1);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from object array into primitive array
+ System.arraycopy(new String[] {"a"}, 0, new char[1], 0, 1);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from primitive array into an array of another primitive type
+ System.arraycopy(new char[] {'a'}, 0, new int[1], 0, 1);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from object array into an array of another Object type
+ System.arraycopy(new Character[] {'a'}, 0, new Integer[1], 0, 1);
+ fail("ArrayStoreException is not thrown.");
+ } catch(ArrayStoreException ase) {
+ //expected
+ }
+
+ try {
+ // copy from null into an array of a primitive type
+ System.arraycopy(null, 0, new int[1], 0, 1);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ // copy from a primitive array into null
+ System.arraycopy(new int[]{'1'}, 0, null, 0, 1);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, a.length + 1, b, 0, 1);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, -1, b, 0, 1);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, 0, b, -1, 1);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, 0, b, 0, -1);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, 11, b, 0, 10);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, Integer.MAX_VALUE, b, 0, 10);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, 0, b, Integer.MAX_VALUE, 10);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+
+ try {
+ System.arraycopy(a, 0, b, 10, Integer.MAX_VALUE);
+ fail("IndexOutOfBoundsException is not thrown.");
+ } catch(IndexOutOfBoundsException ioobe) {
+ //expected
+ }
+ }
+
+ public void test_currentTimeMillis() {
+ // Test for method long java.lang.System.currentTimeMillis()
+ try {
+ long firstRead = System.currentTimeMillis();
+ try {
+ Thread.sleep(150);
+ } catch (InterruptedException e) {
+ }
+ long secondRead = System.currentTimeMillis();
+ assertTrue("Incorrect times returned: " + firstRead + ", "
+ + secondRead, firstRead < secondRead);
+ } catch (Exception e) {
+ fail("Exception during test: " + e.toString());
+ }
+ }
+
+ public void test_getProperties() {
+ String [] props = {"java.vendor.url",
+ "java.class.path", "user.home",
+ "java.class.version", "os.version",
+ "java.vendor", "user.dir",
+ /*"user.timezone",*/ "path.separator",
+ "os.name", "os.arch",
+ "line.separator", "file.separator",
+ "user.name", "java.version", "java.home" };
+
+ Properties p = System.getProperties();
+ assertTrue(p.size() > 0);
+
+ // Ensure spec'ed properties are non-null. See System.getProperties()
+ // spec.
+
+ for (String prop : props) {
+ assertNotNull("There is no property among returned properties: "
+ + prop, p.getProperty(prop));
+ assertNotNull("System property is null: " + prop,
+ System.getProperty(prop));
+ }
+ }
+
+ public void test_getPropertyLjava_lang_String() {
+ try {
+ System.getProperty(null);
+ fail("NullPointerException should be thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ System.getProperty("");
+ fail("IllegalArgumentException should be thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ public void test_getPropertyLjava_lang_StringLjava_lang_String() {
+ try {
+ System.getProperty(null, "0.0");
+ fail("NullPointerException should be thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ System.getProperty("", "0");
+ fail("IllegalArgumentException should be thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ public void test_inheritedChannel() throws IOException {
+ Channel iChannel = System.inheritedChannel();
+ assertNull("Incorrect value of channel", iChannel);
+ SelectorProvider sp = SelectorProvider.provider();
+ assertEquals("Incorrect value of channel",
+ sp.inheritedChannel(), iChannel);
+ }
+
+ public void test_clearProperty() {
+ System.setProperty("test", "value");
+ System.clearProperty("test");
+ assertNull("Property was not deleted.", System.getProperty("test"));
+
+ try {
+ System.clearProperty(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+
+ try {
+ System.clearProperty("");
+ fail("IllegalArgumentException is not thrown.");
+ } catch(IllegalArgumentException iae) {
+ //expected
+ }
+ }
+
+ public void test_gc() {
+ Runtime rt = Runtime.getRuntime();
+ Vector<StringBuffer> vec = new Vector<StringBuffer>();
+ long beforeTest = rt.freeMemory();
+ while(rt.freeMemory() < beforeTest * 2/3) {
+ vec.add(new StringBuffer(1000));
+ }
+ long beforeGC = rt.freeMemory();
+ System.gc();
+ long afterGC = rt.freeMemory();
+ assertTrue("memory was not released after calling System.gc()." +
+ "before gc: " + beforeGC + "; after gc: " + afterGC,
+ beforeGC < afterGC);
+ }
+
+ public void test_getenv() {
+ // String[] props = { "PATH", "HOME", "USER"};
+ // only PATH of these three exists on android
+ String[] props = { "PATH" };
+
+ Map<String,String> envMap = System.getenv();
+ assertFalse("environment map is empty.", envMap.isEmpty());
+ assertTrue("env map contains less than 3 keys.",
+ props.length < envMap.keySet().size());
+ for (String prop : props) {
+ assertNotNull("There is no property: " + prop,
+ envMap.get(prop));
+ }
+ }
+
+ public void test_getenvLString() {
+ assertNotNull("PATH environment variable is not found",
+ System.getenv("PATH"));
+
+ assertNull("Doesn't return NULL for non existent property",
+ System.getenv("nonexistent.property"));
+
+ try {
+ System.getenv(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_load() {
+ try {
+ Runtime.getRuntime().load("nonExistentLibrary");
+ fail("UnsatisfiedLinkError was not thrown.");
+ } catch(UnsatisfiedLinkError e) {
+ //expected
+ }
+
+ try {
+ System.load("nonExistentLibrary");
+ fail("UnsatisfiedLinkError was not thrown.");
+ } catch(UnsatisfiedLinkError ule) {
+ //expected
+ }
+
+ try {
+ System.load(null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_loadLibrary() {
+ try {
+ System.loadLibrary("nonExistentLibrary");
+ fail("UnsatisfiedLinkError was not thrown.");
+ } catch(UnsatisfiedLinkError ule) {
+ //expected
+ }
+
+ try {
+ System.loadLibrary(null);
+ fail("NullPointerException was not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_mapLibraryName() {
+ assertEquals("libname.so", System.mapLibraryName("name"));
+
+ try {
+ System.mapLibraryName(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException npe) {
+ //expected
+ }
+ }
+
+ public void test_nanoTime() {
+ long sleepTime = 5000;
+ long beginTime = System.nanoTime();
+ try {
+ Thread.sleep(sleepTime);
+ } catch(Exception e) {
+ fail("Unknown exception was thrown.");
+ }
+ long endTime = System.nanoTime();
+ assertTrue((endTime - beginTime) > sleepTime * 1000000);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldThreadStateTest.java b/luni/src/test/java/libcore/java/lang/OldThreadStateTest.java
new file mode 100644
index 0000000..855655e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldThreadStateTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldThreadStateTest extends TestCase {
+
+ Thread.State [] exStates = { Thread.State.NEW, Thread.State.RUNNABLE,
+ Thread.State.BLOCKED, Thread.State.WAITING,
+ Thread.State.TIMED_WAITING, Thread.State.TERMINATED };
+
+ public void test_valueOfLString(){
+ String [] spNames = {"NEW", "RUNNABLE", "BLOCKED", "WAITING",
+ "TIMED_WAITING", "TERMINATED"};
+
+ for(int i = 0; i < exStates.length; i++) {
+ assertEquals(exStates[i], Thread.State.valueOf(spNames[i]));
+ }
+
+ String [] illegalNames = {"New", "new", "", "NAME", "TIME"};
+ for(String s:illegalNames) {
+ try {
+ Thread.State.valueOf(s);
+ fail("IllegalArgumentException was not thrown for string: "+s);
+ } catch(IllegalArgumentException iae) {
+ //expected
+ }
+ }
+ }
+
+ public void test_values() {
+ Thread.State [] thStates = Thread.State.values();
+ assertEquals(exStates.length, thStates.length);
+ for(Thread.State ts:thStates) {
+ assertTrue(isContain(ts));
+ }
+ }
+
+ boolean isContain(Thread.State state) {
+ for(Thread.State ts:exStates) {
+ if(ts.equals(state)) return true;
+ }
+ return false;
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/OldThreadTest.java b/luni/src/test/java/libcore/java/lang/OldThreadTest.java
index 4028eaa..1094d33 100644
--- a/luni/src/test/java/libcore/java/lang/OldThreadTest.java
+++ b/luni/src/test/java/libcore/java/lang/OldThreadTest.java
@@ -301,7 +301,7 @@ public class OldThreadTest extends junit.framework.TestCase {
}
- public void test_getState() {
+ public void test_getState() throws InterruptedException {
Thread.State state = Thread.currentThread().getState();
assertNotNull(state);
assertEquals(Thread.State.RUNNABLE, state);
@@ -344,15 +344,11 @@ public class OldThreadTest extends junit.framework.TestCase {
};
assertEquals(Thread.State.NEW, th.getState());
th.start();
- try {
- sem.acquire();
- } catch (InterruptedException e) {
- fail("InterruptedException was thrown.");
- }
+ sem.acquire();
assertEquals(Thread.State.RUNNABLE, th.getState());
run = false;
- while (!sem.hasQueuedThreads()){}
+ Thread.sleep(200);
assertEquals(Thread.State.WAITING, th.getState());
synchronized (lock) {
@@ -362,22 +358,14 @@ public class OldThreadTest extends junit.framework.TestCase {
assertEquals(Thread.State.BLOCKED, th.getState());
}
- try {
- sem.acquire();
- } catch (InterruptedException e) {
- fail("InterruptedException was thrown.");
- }
+ sem.acquire();
synchronized (lock) {
assertEquals(Thread.State.TIMED_WAITING, th.getState());
th.interrupt();
}
- try {
- th.join(1000);
- } catch(InterruptedException ie) {
- fail("InterruptedException was thrown.");
- }
+ th.join(1000);
assertEquals(Thread.State.TERMINATED, th.getState());
}
volatile boolean run = true;
diff --git a/luni/src/test/java/libcore/java/lang/OldThrowableTest.java b/luni/src/test/java/libcore/java/lang/OldThrowableTest.java
new file mode 100644
index 0000000..a616855
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/OldThrowableTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public class OldThrowableTest extends TestCase {
+
+ public void test_ConstructorLStringLThrowable() {
+ String message = "Test message";
+ NullPointerException npe = new NullPointerException();
+ Throwable thr = new Throwable(message, npe);
+ assertEquals("message is incorrect.", message, thr.getMessage());
+ assertEquals("cause is incorrect.", npe, thr.getCause());
+
+ thr = new Throwable(null, npe);
+ assertNull("message is not null.", thr.getMessage());
+ assertEquals("cause is incorrect.", npe, thr.getCause());
+
+ thr = new Throwable(message, null);
+ assertEquals("message is incorrect.", message, thr.getMessage());
+ assertNull("cause is not null.", thr.getCause());
+ }
+
+ public void test_ConstructorLThrowable() {
+
+ NullPointerException npe = new NullPointerException();
+ Throwable thr = new Throwable(npe);
+
+ assertEquals("Returned cause is incorrect.", npe, thr.getCause());
+
+ thr = new Throwable((Throwable) null);
+ assertNull("The cause is not null.", thr.getCause());
+ }
+
+ public void test_getLocalizedMessage() {
+ String testMessage = "Test message";
+ Throwable e = new Throwable(testMessage);
+ assertEquals("Returned incorrect localized message.",
+ testMessage, e.getLocalizedMessage());
+
+ TestThrowable tt = new TestThrowable(testMessage);
+ assertEquals("localized message", tt.getLocalizedMessage());
+ }
+
+ class TestThrowable extends Throwable {
+
+ public TestThrowable(String message) {
+ super(message);
+ }
+
+ public String getLocalizedMessage() {
+ return "localized message";
+ }
+ }
+
+ public void test_getStackTrace() {
+ String message = "Test message";
+ NullPointerException npe = new NullPointerException();
+ Throwable thr = new Throwable(message, npe);
+ StackTraceElement[] ste = thr.getStackTrace();
+ assertNotNull("Returned stack trace is empty", ste.length != 0);
+ }
+
+ public void test_initCause() {
+ String message = "Test message";
+ NullPointerException npe = new NullPointerException();
+ IllegalArgumentException iae = new IllegalArgumentException();
+ Throwable thr = new Throwable();
+ thr.initCause(iae);
+ assertEquals("getCause returns incorrect cause.", iae, thr.getCause());
+
+ thr = new Throwable("message");
+ thr.initCause(npe);
+ assertEquals("getCause returns incorrect cause.", npe, thr.getCause());
+
+ thr = new Throwable(message, npe);
+ try {
+ thr.initCause(iae);
+ fail("IllegalStateException was not thrown.");
+ } catch(IllegalStateException ise) {
+ //expected
+ }
+
+ thr = new Throwable(npe);
+ try {
+ thr.initCause(iae);
+ fail("IllegalStateException was not thrown.");
+ } catch(IllegalStateException ise) {
+ //expected
+ }
+
+ thr = new Throwable();
+ try {
+ thr.initCause(thr);
+ fail("IllegalArgumentException was not thrown.");
+ } catch(IllegalArgumentException ise) {
+ //expected
+ }
+ }
+
+ public void test_setStackTrace() {
+ NullPointerException npe = new NullPointerException();
+ Throwable thr = new Throwable(npe);
+ StackTraceElement[] ste = thr.getStackTrace();
+ Throwable thr1 = new Throwable(npe);
+ thr1.setStackTrace(ste);
+ assertEquals(ste.length, thr1.getStackTrace().length);
+
+ try {
+ thr.setStackTrace(null);
+ fail("NullPointerException is not thrown.");
+ } catch(NullPointerException np) {
+ //expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java b/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java
index 6b8edcb..405de6e 100644
--- a/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java
+++ b/luni/src/test/java/libcore/java/lang/ProcessBuilderTest.java
@@ -16,13 +16,21 @@
package libcore.java.lang;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
+import libcore.dalvik.system.CloseGuardTester;
import static tests.support.Support_Exec.execAndCheckOutput;
public class ProcessBuilderTest extends junit.framework.TestCase {
+
private static String shell() {
- return "Dalvik".equals(System.getProperty("java.vm.name")) ? "/system/bin/sh" : "/bin/sh";
+ String deviceSh = "/system/bin/sh";
+ String desktopSh = "/bin/sh";
+ return new File(deviceSh).exists() ? deviceSh : desktopSh;
}
public void testRedirectErrorStream(boolean doRedirect,
@@ -46,6 +54,46 @@ public class ProcessBuilderTest extends junit.framework.TestCase {
execAndCheckOutput(pb, "android\n", "");
}
+ public void testDestroyClosesEverything() throws IOException {
+ Process process = new ProcessBuilder(shell(), "-c", "echo out; echo err 1>&2").start();
+ InputStream in = process.getInputStream();
+ InputStream err = process.getErrorStream();
+ OutputStream out = process.getOutputStream();
+ process.destroy();
+
+ try {
+ in.read();
+ fail();
+ } catch (IOException expected) {
+ }
+ try {
+ err.read();
+ fail();
+ } catch (IOException expected) {
+ }
+ try {
+ /*
+ * We test write+flush because the RI returns a wrapped stream, but
+ * only bothers to close the underlying stream.
+ */
+ out.write(1);
+ out.flush();
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+
+ public void testDestroyDoesNotLeak() throws IOException {
+ CloseGuardTester closeGuardTester = new CloseGuardTester();
+ try {
+ Process process = new ProcessBuilder(shell(), "-c", "echo out; echo err 1>&2").start();
+ process.destroy();
+ closeGuardTester.assertEverythingWasClosed();
+ } finally {
+ closeGuardTester.close();
+ }
+ }
+
public void testEnvironmentMapForbidsNulls() throws Exception {
ProcessBuilder pb = new ProcessBuilder(shell(), "-c", "echo $A");
Map<String, String> environment = pb.environment();
diff --git a/luni/src/test/java/libcore/java/lang/StringIndexOutOfBoundsExceptionTest.java b/luni/src/test/java/libcore/java/lang/StringIndexOutOfBoundsExceptionTest.java
new file mode 100644
index 0000000..bba8a96
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/StringIndexOutOfBoundsExceptionTest.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import junit.framework.TestCase;
+
+public final class StringIndexOutOfBoundsExceptionTest extends TestCase {
+ public void testCharAt() throws Exception {
+ try {
+ "hello".charAt(-1);
+ fail();
+ } catch (StringIndexOutOfBoundsException ex) {
+ assertEquals("index=-1 length=5", ex.getMessage());
+ }
+ try {
+ "hello".charAt(7);
+ fail();
+ } catch (StringIndexOutOfBoundsException ex) {
+ assertEquals("index=7 length=5", ex.getMessage());
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/ThreadTest.java b/luni/src/test/java/libcore/java/lang/ThreadTest.java
new file mode 100644
index 0000000..3695e3e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/ThreadTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import junit.framework.TestCase;
+
+public final class ThreadTest extends TestCase {
+
+ public void testLeakingStartedThreads() {
+ final AtomicInteger finalizedThreadsCount = new AtomicInteger();
+ for (int i = 0; true; i++) {
+ try {
+ newThread(finalizedThreadsCount, 1024 << i).start();
+ } catch (OutOfMemoryError expected) {
+ break;
+ }
+ }
+ System.runFinalization();
+ assertTrue("Started threads were never finalized!", finalizedThreadsCount.get() > 0);
+ }
+
+ public void testLeakingUnstartedThreads() {
+ final AtomicInteger finalizedThreadsCount = new AtomicInteger();
+ for (int i = 0; true; i++) {
+ try {
+ newThread(finalizedThreadsCount, 1024 << i);
+ } catch (OutOfMemoryError expected) {
+ break;
+ }
+ }
+ System.runFinalization();
+ assertTrue("Unstarted threads were never finalized!", finalizedThreadsCount.get() > 0);
+ }
+
+ private Thread newThread(final AtomicInteger finalizedThreadsCount, final int size) {
+ return new Thread() {
+ byte[] memoryPressure = new byte[size];
+ @Override protected void finalize() throws Throwable {
+ super.finalize();
+ finalizedThreadsCount.incrementAndGet();
+ }
+ };
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/reflect/ClassLoaderReflectionTest.java b/luni/src/test/java/libcore/java/lang/reflect/ClassLoaderReflectionTest.java
index a5a72e0..2e15de2 100644
--- a/luni/src/test/java/libcore/java/lang/reflect/ClassLoaderReflectionTest.java
+++ b/luni/src/test/java/libcore/java/lang/reflect/ClassLoaderReflectionTest.java
@@ -16,22 +16,18 @@
package libcore.java.lang.reflect;
-import java.io.File;
-import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import junit.framework.TestCase;
+import tests.util.ClassLoaderBuilder;
/**
* This class creates another class loader to load multiple copies of various
@@ -55,7 +51,7 @@ public final class ClassLoaderReflectionTest extends TestCase {
@Override protected void setUp() throws Exception {
String prefix = ClassLoaderReflectionTest.class.getName();
- ClassLoader loader = twoCopiesClassLoader(prefix, getClass().getClassLoader());
+ ClassLoader loader = new ClassLoaderBuilder().withPrivateCopy(prefix).build();
aClass = loader.loadClass(prefix + "$A");
bClass = loader.loadClass(prefix + "$B");
cClass = loader.loadClass(prefix + "$C");
@@ -152,68 +148,6 @@ public final class ClassLoaderReflectionTest extends TestCase {
}
static class BString extends B<String> {}
- /**
- * Returns a class loader that permits multiple copies of the same class to
- * be loaded into the same VM at the same time. This loads classes using the
- * same classpath as the application class loader.
- *
- * @param prefix the prefix of classes that can be loaded by both the
- * returned class loader and the application class loader.
- */
- private ClassLoader twoCopiesClassLoader(final String prefix, ClassLoader parent)
- throws IOException, InterruptedException {
-
- /*
- * To load two copies of a given class in the VM, we end up creating two
- * new class loaders: a bridge class loader and a leaf class loader.
- *
- * The bridge class loader is a child of the application class loader.
- * It never loads any classes. All it does is decide when to delegate to
- * the application class loader (which has a copy of everything) and
- * when to fail.
- *
- * The leaf class loader is a child of the bridge class loader. It
- * uses the same classpath as the application class loader. It loads
- * anything that its parent failed on.
- */
-
- ClassLoader bridge = new ClassLoader(parent) {
- @Override protected Class<?> loadClass(String className, boolean resolve)
- throws ClassNotFoundException {
- if (className.startsWith(prefix)) {
- /* throwing will cause the child class loader to load the class. */
- throw new ClassNotFoundException();
- } else {
- return super.loadClass(className, resolve);
- }
- }
- };
-
- try {
- // first try to create a PathClassLoader for a dalvik VM...
- String classPath = System.getProperty("java.class.path");
- return (ClassLoader) Class.forName("dalvik.system.PathClassLoader")
- .getConstructor(String.class, ClassLoader.class)
- .newInstance(classPath, bridge);
- } catch (Exception ignored) {
- }
-
- // fall back to a URLClassLoader on a JVM
- List<URL> classpath = new ArrayList<URL>();
- classpath.addAll(classpathToUrls("java.class.path"));
- classpath.addAll(classpathToUrls("sun.boot.class.path"));
- return new URLClassLoader(classpath.toArray(new URL[classpath.size()]), bridge);
- }
-
- private List<URL> classpathToUrls(String propertyName) throws MalformedURLException {
- String classpath = System.getProperty(propertyName);
- List<URL> result = new ArrayList<URL>();
- for (String pathElement : classpath.split(File.pathSeparator)) {
- result.add(new File(pathElement).toURI().toURL());
- }
- return result;
- }
-
private void assertParameterizedType(Type actual, Type raw, Type... args) {
assertTrue(actual.toString(), actual instanceof ParameterizedType);
ParameterizedType parameterizedType = (ParameterizedType) actual;
diff --git a/luni/src/test/java/libcore/java/lang/reflect/MethodTest.java b/luni/src/test/java/libcore/java/lang/reflect/MethodTest.java
index 9d99350..192c79c 100644
--- a/luni/src/test/java/libcore/java/lang/reflect/MethodTest.java
+++ b/luni/src/test/java/libcore/java/lang/reflect/MethodTest.java
@@ -19,6 +19,41 @@ package libcore.java.lang.reflect;
import java.lang.reflect.Method;
public class MethodTest extends junit.framework.TestCase {
+ // Check that the VM gives useful detail messages.
+ public void test_invokeExceptions() throws Exception {
+ Method m = String.class.getMethod("charAt", int.class);
+ try {
+ m.invoke("hello"); // Wrong number of arguments.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("wrong number of arguments; expected 1, got 0", iae.getMessage());
+ }
+ try {
+ m.invoke("hello", "world"); // Wrong type.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("argument 1 should have type int, got java.lang.String", iae.getMessage());
+ }
+ try {
+ m.invoke("hello", (Object) null); // Null for a primitive argument.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("argument 1 should have type int, got null", iae.getMessage());
+ }
+ try {
+ m.invoke(new Integer(5)); // Wrong type for 'this'.
+ fail();
+ } catch (IllegalArgumentException iae) {
+ assertEquals("expected receiver of type java.lang.String, not java.lang.Integer", iae.getMessage());
+ }
+ try {
+ m.invoke(null); // Null for 'this'.
+ fail();
+ } catch (NullPointerException npe) {
+ assertEquals("expected receiver of type java.lang.String, not null", npe.getMessage());
+ }
+ }
+
public void test_getExceptionTypes() throws Exception {
Method method = MethodTestHelper.class.getMethod("m1", new Class[0]);
Class[] exceptions = method.getExceptionTypes();
diff --git a/luni/src/test/java/libcore/java/lang/reflect/MissingClassesTest.java b/luni/src/test/java/libcore/java/lang/reflect/MissingClassesTest.java
new file mode 100644
index 0000000..8b4c835
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/reflect/MissingClassesTest.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang.reflect;
+
+import junit.framework.TestCase;
+import tests.util.ClassLoaderBuilder;
+
+public final class MissingClassesTest extends TestCase {
+
+ private Class<?> loadableClass;
+
+ @Override protected void setUp() throws Exception {
+ String prefix = MissingClassesTest.class.getName();
+ ClassLoader cl = new ClassLoaderBuilder()
+ .withPrivateCopy(prefix + "$Loadable")
+ .without(prefix + "$Unloadable")
+ .build();
+ loadableClass = cl.loadClass(prefix + "$Loadable");
+ }
+
+ /**
+ * http://b/issue?id=2634005
+ */
+ public void testGetDeclaredFieldsFails() {
+ try {
+ loadableClass.getDeclaredFields();
+ fail();
+ } catch (NoClassDefFoundError expected) {
+ }
+ }
+
+ public void testGetDeclaredMethodsFails() {
+ try {
+ loadableClass.getDeclaredMethods();
+ fail();
+ } catch (NoClassDefFoundError expected) {
+ }
+ }
+
+ public void testGetMethodFails() throws NoSuchMethodException {
+ try {
+ loadableClass.getDeclaredMethod("method", Unloadable.class);
+ fail();
+ } catch (NoClassDefFoundError expected) {
+ }
+ }
+
+ public void testGetFieldFails() throws NoSuchFieldException {
+ try {
+ loadableClass.getDeclaredField("field");
+ fail();
+ } catch (NoClassDefFoundError expected) {
+ }
+ }
+
+ class Loadable {
+ Unloadable field;
+ void method(Unloadable unloadable) {}
+ }
+
+ class Unloadable {}
+}
diff --git a/luni/src/test/java/libcore/java/lang/reflect/OldAndroidArrayTest.java b/luni/src/test/java/libcore/java/lang/reflect/OldAndroidArrayTest.java
new file mode 100644
index 0000000..f0534a4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/reflect/OldAndroidArrayTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang.reflect;
+
+import java.lang.reflect.Array;
+import junit.framework.TestCase;
+
+/**
+ * Test java.lang.reflect.Array methods.
+ */
+public class OldAndroidArrayTest extends TestCase {
+
+ public void testSingleInt() throws Exception {
+ Object intArray = Array.newInstance(Integer.TYPE, 2);
+
+ int[] array = (int[]) intArray;
+ array[0] = 5;
+ Array.setInt(intArray, 1, 6);
+
+ assertEquals(5, Array.getInt(intArray, 0));
+ assertEquals(6, array[1]);
+
+ try {
+ array[2] = 27;
+ fail("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) {
+ // expected
+ }
+
+ assertEquals(2, array.length);
+ assertEquals(Array.getLength(intArray), array.length);
+
+ try {
+ int[][] wrongArray = (int[][]) intArray;
+ fail("cast should have failed");
+ } catch (ClassCastException cce) {
+ // expected
+ }
+
+ intArray = Array.newInstance(Integer.TYPE, 0);
+ assertEquals(0, Array.getLength(intArray));
+ }
+
+ public void testSingle() throws Exception {
+ Object strArray = Array.newInstance(String.class, 2);
+
+ String[] array = (String[]) strArray;
+ array[0] = "entry zero";
+ Array.set(strArray, 1, "entry one");
+
+ //System.out.println("array: " + array);
+
+ assertEquals("entry zero", Array.get(strArray, 0));
+ assertEquals("entry one", array[1]);
+
+ assertEquals(2, array.length);
+ assertEquals(Array.getLength(strArray), array.length);
+ }
+
+ public void testMultiInt() throws Exception {
+ int[] dimensions = {3, 2, 1};
+ Object intIntIntArray = Array.newInstance(Integer.TYPE, dimensions);
+ int[][][] array3 = (int[][][]) intIntIntArray;
+
+ array3[0][0][0] = 123;
+ array3[2][1][0] = 456;
+
+ try {
+ array3[2][1][1] = 768;
+ fail("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) {
+ // expected
+ }
+
+ //System.out.println("array3: " + array3);
+ }
+
+ public void testMulti() throws Exception {
+ int[] dimensions = {1, 2, 3};
+ Object strStrStrArray = Array.newInstance(String.class, dimensions);
+ String[][][] array3 = (String[][][]) strStrStrArray;
+
+ array3[0][0][0] = "zero zero zero";
+ array3[0][1][2] = "zero one two";
+
+ try {
+ array3[1][0][0] = "bad store";
+ fail("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) {
+ // expected
+ }
+
+ try {
+ String[][] array2 = (String[][]) strStrStrArray;
+ fail("expecting bad cast");
+ } catch (ClassCastException cce) {
+ // expected
+ }
+ //System.out.println("array3: " + array3);
+
+
+ int[] dimensions2 = {1, 2};
+ strStrStrArray = Array.newInstance(String[].class, dimensions2);
+ array3 = (String[][][]) strStrStrArray;
+ array3[0][1] = new String[3];
+ array3[0][1][2] = "zero one two";
+ try {
+ array3[1][0][0] = "bad store";
+ fail("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) {
+ // expected
+ }
+ //System.out.println("array3: " + array3);
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/lang/reflect/ProxyTest.java b/luni/src/test/java/libcore/java/lang/reflect/ProxyTest.java
new file mode 100644
index 0000000..b6ae8b3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/lang/reflect/ProxyTest.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.lang.reflect;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import junit.framework.TestCase;
+import tests.util.ClassLoaderBuilder;
+
+public final class ProxyTest extends TestCase {
+
+ /**
+ * Make sure the proxy's class loader fails if it cannot see the class
+ * loaders of its implemented interfaces. http://b/1608481
+ */
+ public void testClassLoaderMustSeeImplementedInterfaces() throws Exception {
+ String prefix = ProxyTest.class.getName();
+ ClassLoader loaderA = new ClassLoaderBuilder().withPrivateCopy(prefix).build();
+ ClassLoader loaderB = new ClassLoaderBuilder().withPrivateCopy(prefix).build();
+
+ Class[] interfacesA = { loaderA.loadClass(prefix + "$Echo") };
+ try {
+ Proxy.newProxyInstance(loaderB, interfacesA, new TestInvocationHandler());
+ fail();
+ } catch (IllegalArgumentException expected) {
+ }
+ }
+
+ public void testClassLoaderDoesNotNeedToSeeInvocationHandlerLoader() throws Exception {
+ String prefix = ProxyTest.class.getName();
+ ClassLoader loaderA = new ClassLoaderBuilder().withPrivateCopy(prefix).build();
+ ClassLoader loaderB = new ClassLoaderBuilder().withPrivateCopy(prefix).build();
+ InvocationHandler invocationHandlerB = (InvocationHandler) loaderB.loadClass(
+ prefix + "$TestInvocationHandler").newInstance();
+
+ Class[] interfacesA = { loaderA.loadClass(prefix + "$Echo") };
+ Object proxy = Proxy.newProxyInstance(loaderA, interfacesA, invocationHandlerB);
+ assertEquals(loaderA, proxy.getClass().getClassLoader());
+ assertEquals("foo", proxy.getClass().getMethod("echo", String.class).invoke(proxy, "foo"));
+ }
+
+ public interface Echo {
+ String echo(String s);
+ }
+
+ public static class TestInvocationHandler implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return args[0];
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/lang/reflect/ReflectionTest.java b/luni/src/test/java/libcore/java/lang/reflect/ReflectionTest.java
index 19092c5..42ef01d 100644
--- a/luni/src/test/java/libcore/java/lang/reflect/ReflectionTest.java
+++ b/luni/src/test/java/libcore/java/lang/reflect/ReflectionTest.java
@@ -16,19 +16,147 @@
package libcore.java.lang.reflect;
+import java.io.Serializable;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.RandomAccess;
+import java.util.Set;
import junit.framework.TestCase;
public final class ReflectionTest extends TestCase {
+ String classA = "libcore.java.lang.reflect.ReflectionTest$A";
+ String classB = "libcore.java.lang.reflect.ReflectionTest$B";
+ String classC = "libcore.java.lang.reflect.ReflectionTest$C";
+
/**
* http://code.google.com/p/android/issues/detail?id=6636
*/
public void testGenericSuperclassToString() throws Exception {
- assertEquals("java.util.ArrayList<libcore.java.lang.reflect.ReflectionTest$A>",
+ assertEquals("java.util.ArrayList<" + classA + ">",
AList.class.getGenericSuperclass().toString());
}
+ public void testFieldToString() throws Exception {
+ Field fieldOne = C.class.getDeclaredField("fieldOne");
+ String fieldOneRaw = "public static " + classA + " " + classC + ".fieldOne";
+ assertEquals(fieldOneRaw, fieldOne.toString());
+ assertEquals(fieldOneRaw, fieldOne.toGenericString());
+
+ Field fieldTwo = C.class.getDeclaredField("fieldTwo");
+ assertEquals("transient volatile java.util.Map " + classC + ".fieldTwo",
+ fieldTwo.toString());
+ assertEquals("transient volatile java.util.Map<" + classA + ", java.lang.String> "
+ + classC + ".fieldTwo", fieldTwo.toGenericString());
+
+ Field fieldThree = C.class.getDeclaredField("fieldThree");
+ String fieldThreeRaw = "java.lang.Object[] " + classC + ".fieldThree";
+ assertEquals(fieldThreeRaw, fieldThree.toString());
+ String fieldThreeGeneric = "K[] " + classC + ".fieldThree";
+ assertEquals(fieldThreeGeneric, fieldThree.toGenericString());
+
+ Field fieldFour = C.class.getDeclaredField("fieldFour");
+ String fieldFourRaw = "java.util.Map " + classC + ".fieldFour";
+ assertEquals(fieldFourRaw, fieldFour.toString());
+ String fieldFourGeneric = "java.util.Map<? super java.lang.Integer, java.lang.Integer[]> "
+ + classC + ".fieldFour";
+ assertEquals(fieldFourGeneric, fieldFour.toGenericString());
+
+ Field fieldFive = C.class.getDeclaredField("fieldFive");
+ String fieldFiveRaw = "java.lang.String[][][][][] " + classC + ".fieldFive";
+ assertEquals(fieldFiveRaw, fieldFive.toString());
+ assertEquals(fieldFiveRaw, fieldFive.toGenericString());
+ }
+
+ public void testConstructorToString() throws Exception {
+ Constructor constructorOne = C.class.getDeclaredConstructor(A.class);
+ String constructorOneRaw = classC + "(" + classA + ") throws " + classB;
+ assertEquals(constructorOneRaw, constructorOne.toString());
+ assertEquals(constructorOneRaw, constructorOne.toGenericString());
+
+ Constructor constructorTwo = C.class.getDeclaredConstructor(Map.class, Object.class);
+ String constructorTwoRaw = "protected " + classC + "(java.util.Map,java.lang.Object)";
+ assertEquals(constructorTwoRaw, constructorTwo.toString());
+ String constructorTwoGeneric = "protected <T1> " + classC
+ + "(java.util.Map<? super " + classA + ", T1>,K)";
+ assertEquals(constructorTwoGeneric, constructorTwo.toGenericString());
+ }
+
+ public void testMethodToString() throws Exception {
+ Method methodOne = C.class.getDeclaredMethod("methodOne", A.class, C.class);
+ String methodOneRaw = "protected final synchronized " + classA + " "
+ + classC + ".methodOne(" + classA + "," + classC + ") throws " + classB;
+ assertEquals(methodOneRaw, methodOne.toString());
+ assertEquals(methodOneRaw, methodOne.toGenericString());
+
+ Method methodTwo = C.class.getDeclaredMethod("methodTwo", List.class);
+ String methodTwoRaw = "public abstract java.util.Map "
+ + classC + ".methodTwo(java.util.List)";
+ assertEquals(methodTwoRaw, methodTwo.toString());
+ String methodTwoGeneric = "public abstract java.util.Map<" + classA + ", java.lang.String> "
+ + classC + ".methodTwo(java.util.List<" + classA + ">)";
+ assertEquals(methodTwoGeneric, methodTwo.toGenericString());
+
+ Method methodThree = C.class.getDeclaredMethod("methodThree", A.class, Set.class);
+ String methodThreeRaw = "private static java.util.Map "
+ + classC + ".methodThree(" + classA + ",java.util.Set)";
+ assertEquals(methodThreeRaw, methodThree.toString());
+ String methodThreeGeneric = "private static <T1,T2> java.util.Map<T1, ?> "
+ + classC + ".methodThree(T1,java.util.Set<? super T2>)";
+ assertEquals(methodThreeGeneric, methodThree.toGenericString());
+
+ Method methodFour = C.class.getDeclaredMethod("methodFour", Set.class);
+ String methodFourRaw = "public java.lang.Comparable " + classC + ".methodFour(java.util.Set)";
+ assertEquals(methodFourRaw, methodFour.toString());
+ String methodFourGeneric = "public <T> T " + classC + ".methodFour(java.util.Set<T>)";
+ assertEquals(methodFourGeneric, methodFour.toGenericString());
+ }
+
+ public void testTypeVariableWithMultipleBounds() throws Exception {
+ TypeVariable t = C.class.getDeclaredMethod("methodFour", Set.class).getTypeParameters()[0];
+ assertEquals("T", t.toString());
+
+ Type[] bounds = t.getBounds();
+ ParameterizedType comparableT = (ParameterizedType) bounds[0];
+ assertEquals(Comparable.class, comparableT.getRawType());
+ assertEquals("T", ((TypeVariable) comparableT.getActualTypeArguments()[0]).getName());
+ assertEquals(3, bounds.length);
+ assertEquals(Serializable.class, bounds[1]);
+ assertEquals(RandomAccess.class, bounds[2]);
+ }
+
static class A {}
static class AList extends ArrayList<A> {}
+
+ static class B extends Exception {}
+
+ public static abstract class C<K> {
+ public static A fieldOne;
+ transient volatile Map<A, String> fieldTwo;
+ K[] fieldThree;
+ Map<? super Integer, Integer[]> fieldFour;
+ String[][][][][] fieldFive;
+
+ C(A a) throws B {}
+ protected <T1 extends A> C(Map<? super A, T1> a, K s) {}
+
+ protected final synchronized A methodOne(A parameterOne, C parameterTwo) throws B {
+ return null;
+ }
+ public abstract Map<A, String> methodTwo(List<A> onlyParameter);
+ @Deprecated /** this annotation is used because it has runtime retention */
+ private static <T1 extends A, T2> Map<T1, ?> methodThree(T1 t, Set<? super T2> t2s) {
+ return null;
+ }
+ public <T extends Comparable<T> & Serializable & RandomAccess> T methodFour(Set<T> t) {
+ return null;
+ }
+ }
}
diff --git a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
index 5968fdf..726b05a 100644
--- a/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
+++ b/luni/src/test/java/libcore/java/net/ConcurrentCloseTest.java
@@ -28,6 +28,7 @@ import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
+import tests.net.StuckServer;
/**
* Test that Socket.close called on another thread interrupts a thread that's blocked doing
@@ -47,24 +48,28 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
}
public void test_connect() throws Exception {
+ StuckServer ss = new StuckServer();
Socket s = new Socket();
new Killer(s).start();
try {
System.err.println("connect...");
- s.connect(new InetSocketAddress("10.0.0.1", 7));
+ s.connect(ss.getLocalSocketAddress());
fail("connect returned!");
} catch (SocketException expected) {
assertEquals("Socket closed", expected.getMessage());
+ } finally {
+ ss.close();
}
}
public void test_connect_nonBlocking() throws Exception {
+ StuckServer ss = new StuckServer();
SocketChannel s = SocketChannel.open();
new Killer(s.socket()).start();
try {
System.err.println("connect (non-blocking)...");
s.configureBlocking(false);
- s.connect(new InetSocketAddress("10.0.0.2", 7));
+ s.connect(ss.getLocalSocketAddress());
while (!s.finishConnect()) {
// Spin like a mad thing!
}
@@ -76,6 +81,8 @@ public class ConcurrentCloseTest extends junit.framework.TestCase {
} catch (ClosedChannelException alsoOkay) {
// For now, I'm assuming that we're happy as long as we get any reasonable exception.
// It may be that we're supposed to guarantee only one or the other.
+ } finally {
+ ss.close();
}
}
diff --git a/luni/src/test/java/libcore/java/net/CookiesTest.java b/luni/src/test/java/libcore/java/net/CookiesTest.java
index f29d3ea..69dea61 100644
--- a/luni/src/test/java/libcore/java/net/CookiesTest.java
+++ b/luni/src/test/java/libcore/java/net/CookiesTest.java
@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import junit.framework.TestCase;
import tests.http.MockResponse;
@@ -287,9 +288,9 @@ public class CookiesTest extends TestCase {
}
});
MockWebServer server = new MockWebServer();
+ server.enqueue(new MockResponse());
server.play();
- server.enqueue(new MockResponse());
HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
assertEquals(Collections.<String, List<String>>emptyMap(),
connection.getRequestProperties());
@@ -336,9 +337,9 @@ public class CookiesTest extends TestCase {
}
});
MockWebServer server = new MockWebServer();
+ server.enqueue(new MockResponse());
server.play();
- server.enqueue(new MockResponse());
get(server, "/");
RecordedRequest request = server.takeRequest();
@@ -363,6 +364,25 @@ public class CookiesTest extends TestCase {
assertFalse(HttpCookie.domainMatches("127.0.0.1", "localhost"));
}
+ public void testDomainMatchesCaseMapping() {
+ testDomainMatchesCaseMapping(Locale.US);
+ }
+
+ public void testDomainMatchesCaseMappingExoticLocale() {
+ testDomainMatchesCaseMapping(new Locale("tr", "TR"));
+ }
+
+ private void testDomainMatchesCaseMapping(Locale locale) {
+ Locale defaultLocale = Locale.getDefault();
+ Locale.setDefault(locale);
+ try {
+ assertTrue(HttpCookie.domainMatches(".android.com", "WWW.ANDROID.COM"));
+ assertFalse(HttpCookie.domainMatches("android.com", "WWW.ANDROID.COM"));
+ } finally {
+ Locale.setDefault(defaultLocale);
+ }
+ }
+
/**
* From the spec, "If an explicitly specified value does not start with a dot, the user agent
* supplies a leading dot.". This prepending doesn't happen in setDomain.
@@ -482,7 +502,7 @@ public class CookiesTest extends TestCase {
private void assertContains(Collection<String> collection, String element) {
for (String c : collection) {
- if (c.equalsIgnoreCase(element)) {
+ if (c != null && c.equalsIgnoreCase(element)) {
return;
}
}
diff --git a/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java b/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java
new file mode 100644
index 0000000..fe89adb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/net/NetworkInterfaceTest.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.net;
+
+import java.net.*;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import junit.framework.TestCase;
+
+public class NetworkInterfaceTest extends TestCase {
+ // http://code.google.com/p/android/issues/detail?id=13784
+ public void testIPv6() throws Exception {
+ NetworkInterface lo = NetworkInterface.getByName("lo");
+ Set<InetAddress> actual = new HashSet<InetAddress>(Collections.list(lo.getInetAddresses()));
+
+ Set<InetAddress> expected = new HashSet<InetAddress>();
+ expected.add(Inet4Address.LOOPBACK);
+ expected.add(Inet6Address.getByAddress("localhost", new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }, null));
+
+ assertEquals(expected, actual);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/net/OldAndroidDatagramTest.java b/luni/src/test/java/libcore/java/net/OldAndroidDatagramTest.java
new file mode 100644
index 0000000..8d79027
--- /dev/null
+++ b/luni/src/test/java/libcore/java/net/OldAndroidDatagramTest.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.net;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketTimeoutException;
+import junit.framework.TestCase;
+
+/**
+ * Implements some simple tests for datagrams. Not as excessive as the core
+ * tests, but good enough for the harness.
+ */
+public class OldAndroidDatagramTest extends TestCase {
+
+ /**
+ * Helper class that listens to incoming datagrams and reflects them to the
+ * sender. Incoming datagram is interpreted as a String. It is uppercased
+ * before being sent back.
+ */
+
+ class Reflector extends Thread {
+ // Helper class for reflecting incoming datagrams.
+ DatagramSocket socket;
+
+ boolean alive = true;
+
+ byte[] buffer = new byte[256];
+
+ DatagramPacket packet;
+
+ /**
+ * Main loop. Receives datagrams and reflects them.
+ */
+ @Override
+ public void run() {
+ try {
+ while (alive) {
+ try {
+ packet.setLength(buffer.length);
+ socket.receive(packet);
+ String s = stringFromPacket(packet);
+ // System.out.println(s + " (from " + packet.getAddress() + ":" + packet.getPort() + ")");
+
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ex) {
+ // Ignore.
+ }
+
+ stringToPacket(s.toUpperCase(), packet);
+
+ packet.setAddress(InetAddress.getLocalHost());
+ packet.setPort(2345);
+
+ socket.send(packet);
+ } catch (java.io.InterruptedIOException e) {
+ }
+ }
+ } catch (java.io.IOException ex) {
+ ex.printStackTrace();
+ } finally {
+ socket.close();
+ }
+ }
+
+ /**
+ * Creates a new Relfector object for the given local address and port.
+ */
+ public Reflector(int port, InetAddress address) {
+ try {
+ packet = new DatagramPacket(buffer, buffer.length);
+ socket = new DatagramSocket(port, address);
+ } catch (IOException ex) {
+ throw new RuntimeException(
+ "Creating datagram reflector failed", ex);
+ }
+ }
+ }
+
+ /**
+ * Converts a given datagram packet's contents to a String.
+ */
+ static String stringFromPacket(DatagramPacket packet) {
+ return new String(packet.getData(), 0, packet.getLength());
+ }
+
+ /**
+ * Converts a given String into a datagram packet.
+ */
+ static void stringToPacket(String s, DatagramPacket packet) {
+ byte[] bytes = s.getBytes();
+ System.arraycopy(bytes, 0, packet.getData(), 0, bytes.length);
+ packet.setLength(bytes.length);
+ }
+
+ /**
+ * Implements the main part of the Datagram test.
+ */
+ public void testDatagram() throws Exception {
+
+ Reflector reflector = null;
+ DatagramSocket socket = null;
+
+ try {
+ // Setup the reflector, so we have a partner to send to
+ reflector = new Reflector(1234, InetAddress.getLocalHost());
+ reflector.start();
+
+ byte[] buffer = new byte[256];
+
+ DatagramPacket packet = new DatagramPacket(buffer, buffer.length);
+ socket = new DatagramSocket(2345, InetAddress.getLocalHost());
+
+ // Send ten simple packets and check for the expected responses.
+ for (int i = 1; i <= 10; i++) {
+ String s = "Hello, Android world #" + i + "!";
+ stringToPacket(s, packet);
+
+ packet.setAddress(InetAddress.getLocalHost());
+ packet.setPort(1234);
+
+ socket.send(packet);
+
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException ex) {
+ // Ignore.
+ }
+
+ packet.setLength(buffer.length);
+ socket.receive(packet);
+ String t = stringFromPacket(packet);
+ // System.out.println(t + " (from " + packet.getAddress() + ":" + packet.getPort() + ")");
+
+ assertEquals(s.toUpperCase(), t);
+ }
+ } finally {
+ if (reflector != null) {
+ reflector.alive = false;
+ }
+
+ if (socket != null) {
+ socket.close();
+ }
+ }
+ }
+
+ // Regression test for issue 1018003: DatagramSocket ignored a set timeout.
+ public void testDatagramSocketSetSOTimeout() throws Exception {
+ DatagramSocket sock = null;
+ int timeout = 5000;
+ long start = System.currentTimeMillis();
+ try {
+ sock = new DatagramSocket();
+ DatagramPacket pack = new DatagramPacket(new byte[100], 100);
+ sock.setSoTimeout(timeout);
+ sock.receive(pack);
+ } catch (SocketTimeoutException e) {
+ // expected
+ long delay = System.currentTimeMillis() - start;
+ if (Math.abs(delay - timeout) > 1000) {
+ fail("timeout was not accurate. expected: " + timeout
+ + " actual: " + delay + " miliseconds.");
+ }
+ } finally {
+ if (sock != null) {
+ sock.close();
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/net/OldAndroidURITest.java b/luni/src/test/java/libcore/java/net/OldAndroidURITest.java
new file mode 100644
index 0000000..ddb399b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/net/OldAndroidURITest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.net;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import junit.framework.TestCase;
+
+public class OldAndroidURITest extends TestCase {
+
+ public void testConstruct() throws Exception {
+ construct("http://www.google.com/this/is-the/path?query#fragment",
+ "www.google.com", "/this/is-the/path", true);
+ }
+
+ private static void construct(String str, String host, String path, boolean absolute)
+ throws URISyntaxException {
+ URI uri = new URI(str);
+ assertEquals(host, uri.getHost());
+ assertEquals(path, uri.getPath());
+ assertEquals(absolute, uri.isAbsolute());
+ }
+
+ public void testResolve() throws Exception {
+ resolve("http://www.google.com/your",
+ "mom",
+ "http://www.google.com/mom");
+ }
+
+ private static void resolve(String base, String uri, String expected) {
+ URI b = URI.create(base);
+ URI resolved = b.resolve(uri);
+ assertEquals(expected, resolved.toString());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java b/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java
index b6606b5..07e0897 100644
--- a/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java
+++ b/luni/src/test/java/libcore/java/net/OldDatagramSocketTest.java
@@ -1148,7 +1148,7 @@ public class OldDatagramSocketTest extends junit.framework./*Socket*/TestCase {
return null;
}
}
- InetSocketAddress sa = InetSocketAddress.createUnresolved("localhost", 0);
+ InetSocketAddress sa = new InetSocketAddress(InetAddress.getLocalHost(), 0);
//no exception expected for next line
new testDatagramSocket(new testDatagramSocketImpl()).send(new DatagramPacket(new byte[272], 3, sa));
diff --git a/luni/src/test/java/libcore/java/net/OldResponseCacheTest.java b/luni/src/test/java/libcore/java/net/OldResponseCacheTest.java
index c4a662e..71e2176 100644
--- a/luni/src/test/java/libcore/java/net/OldResponseCacheTest.java
+++ b/luni/src/test/java/libcore/java/net/OldResponseCacheTest.java
@@ -20,6 +20,7 @@ import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargets;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -34,6 +35,8 @@ import java.net.URL;
import java.net.URLConnection;
import java.security.Permission;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
import tests.support.Support_PortManager;
@@ -208,9 +211,8 @@ public class OldResponseCacheTest extends TestCase {
class TestCacheResponse extends CacheResponse {
InputStream is = null;
- public TestCacheResponse(String filename) {
- String path = getClass().getPackage().getName().replace(".", "/");
- is = getClass().getResourceAsStream("/" + path + "/" + filename);
+ public TestCacheResponse(String body) {
+ is = new ByteArrayInputStream(body.getBytes());
}
@Override
@@ -219,9 +221,9 @@ public class OldResponseCacheTest extends TestCase {
}
@Override
- public Map getHeaders() {
- return null;
- }
+ public Map<String, List<String>> getHeaders() throws IOException {
+ return new HashMap<String, List<String>>();
+ }
}
class TestCacheRequest extends CacheRequest {
@@ -256,7 +258,7 @@ public class OldResponseCacheTest extends TestCase {
public CacheResponse get(URI uri, String rqstMethod, Map rqstHeaders) {
getWasCalled = uri;
if (testGet && uri.equals(uri1)) {
- return new TestCacheResponse("file1.cache");
+ return new TestCacheResponse("Cache test");
}
return null;
}
diff --git a/luni/src/test/java/libcore/java/net/OldURLStreamHandlerTest.java b/luni/src/test/java/libcore/java/net/OldURLStreamHandlerTest.java
index a6804be..51d6001 100644
--- a/luni/src/test/java/libcore/java/net/OldURLStreamHandlerTest.java
+++ b/luni/src/test/java/libcore/java/net/OldURLStreamHandlerTest.java
@@ -1,6 +1,23 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
package libcore.java.net;
import java.io.IOException;
+import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.Proxy;
@@ -38,11 +55,11 @@ public class OldURLStreamHandlerTest extends TestCase {
URL url1 = new URL("ftp://test_url/test?a=b&c=%D0+%D1");
assertNull(handler.getHostAddress(url1));
- URL url2 = new URL("http://test:pwd@host/test?a=b&c=%D0+%D1");
- assertNull("testHost", handler.getHostAddress(url2));handler.getHostAddress(url2);
+ URL url2 = new URL("http://test:pwd@fakehostname.fakedomain/test?a=b&c=%D0+%D1");
+ assertNull(handler.getHostAddress(url2));
URL url3 = new URL("http://localhost/test");
- assertEquals(InetAddress.getLocalHost(), handler.getHostAddress(url3));
+ assertEquals(InetAddress.getByName("localhost"), handler.getHostAddress(url3));
}
public void test_hashCodeLjava_net_URL() throws MalformedURLException {
@@ -60,9 +77,11 @@ public class OldURLStreamHandlerTest extends TestCase {
}
}
- public void test_hostsEqualLjava_net_URLLjava_net_URL() throws MalformedURLException {
+ public void test_hostsEqualLjava_net_URLLjava_net_URL() throws Exception {
+ String loopback = getLoopbackAddressAsHost();
+
URL url1 = new URL("ftp://localhost:21/*test");
- URL url2 = new URL("http://127.0.0.1/_test");
+ URL url2 = new URL("http://" + loopback + "/_test");
assertTrue(handler.hostsEqual(url1, url2));
URL url3 = new URL("http://foo/_test_goo");
@@ -98,12 +117,14 @@ public class OldURLStreamHandlerTest extends TestCase {
}
}
- public void test_sameFile() throws MalformedURLException {
+ public void test_sameFile() throws Exception {
+ String loopback = getLoopbackAddressAsHost();
+
URL url1 = new URL("http://test:pwd@localhost:80/foo/foo1.c");
- URL url2 = new URL("http://test:pwd@127.0.01:80/foo/foo1.c");
- URL url3 = new URL("http://test:pwd@127.0.01:80/foo/foo2.c");
- URL url4 = new URL("ftp://test:pwd@127.0.01:21/foo/foo2.c");
- URL url5 = new URL("ftp://test:pwd@127.0.01:21/foo/foo1/foo2.c");
+ URL url2 = new URL("http://test:pwd@" + loopback + ":80/foo/foo1.c");
+ URL url3 = new URL("http://test:pwd@" + loopback + ":80/foo/foo2.c");
+ URL url4 = new URL("ftp://test:pwd@" + loopback + ":21/foo/foo2.c");
+ URL url5 = new URL("ftp://test:pwd@" + loopback + ":21/foo/foo1/foo2.c");
URL url6 = new URL("http://test/foo/foo1.c");
assertTrue("Test case 1", handler.sameFile(url1, url2));
@@ -154,6 +175,13 @@ public class OldURLStreamHandlerTest extends TestCase {
handler = new MockURLStreamHandler();
}
+ private String getLoopbackAddressAsHost() throws UnknownHostException {
+ InetAddress localhost = InetAddress.getByName("localhost");
+ return localhost instanceof Inet6Address
+ ? "[" + localhost.getHostAddress() + "]"
+ : localhost.getHostAddress();
+ }
+
class MockURLStreamHandler extends URLStreamHandler {
@Override
diff --git a/luni/src/test/java/libcore/java/net/ProxySelectorTest.java b/luni/src/test/java/libcore/java/net/ProxySelectorTest.java
new file mode 100644
index 0000000..491cb8d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/net/ProxySelectorTest.java
@@ -0,0 +1,207 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.net;
+
+import static java.net.InetSocketAddress.createUnresolved;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import junit.framework.TestCase;
+
+public final class ProxySelectorTest extends TestCase {
+
+ private ProxySelector proxySelector;
+
+ private URI httpUri;
+ private URI ftpUri;
+ private URI httpsUri;
+ private URI socketUri;
+ private URI otherUri;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ proxySelector = ProxySelector.getDefault();
+ httpUri = new URI("http://android.com");
+ ftpUri = new URI("ftp://android.com");
+ httpsUri = new URI("https://android.com");
+ socketUri = new URI("socket://android.com");
+ otherUri = new URI("other://android.com");
+ }
+
+ @Override protected void tearDown() throws Exception {
+ System.clearProperty("ftp.proxyHost");
+ System.clearProperty("ftp.proxyPort");
+ System.clearProperty("ftp.nonProxyHosts");
+ System.clearProperty("http.proxyHost");
+ System.clearProperty("http.proxyPort");
+ System.clearProperty("http.nonProxyHosts");
+ System.clearProperty("https.proxyHost");
+ System.clearProperty("https.proxyPort");
+ System.clearProperty("https.nonProxyHosts");
+ System.clearProperty("other.proxyHost");
+ System.clearProperty("other.proxyPort");
+ System.clearProperty("socket.proxyHost");
+ System.clearProperty("socket.proxyPort");
+ System.clearProperty("proxyHost");
+ System.clearProperty("proxyPort");
+ }
+
+ public void testNoProxySystemProperty() throws URISyntaxException {
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testProxyHostOnly() throws URISyntaxException {
+ System.setProperty("ftp.proxyHost", "a");
+ System.setProperty("http.proxyHost", "b");
+ System.setProperty("https.proxyHost", "c");
+ System.setProperty("other.proxyHost", "d");
+ System.setProperty("socket.proxyHost", "d");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("b", 80))),
+ proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("c", 443))),
+ proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
+ }
+
+ public void testProxyHostPort() throws URISyntaxException {
+ System.setProperty("ftp.proxyHost", "a");
+ System.setProperty("ftp.proxyPort", "1001");
+ System.setProperty("http.proxyHost", "b");
+ System.setProperty("http.proxyPort", "1002");
+ System.setProperty("https.proxyHost", "c");
+ System.setProperty("https.proxyPort", "1003");
+ System.setProperty("other.proxyHost", "d");
+ System.setProperty("other.proxyPort", "1004");
+ System.setProperty("socket.proxyHost", "e");
+ System.setProperty("socket.proxyPort", "1005");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 1001))),
+ proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("b", 1002))),
+ proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("c", 1003))),
+ proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testProxyPortOnly() throws URISyntaxException {
+ System.setProperty("ftp.proxyPort", "1001");
+ System.setProperty("http.proxyPort", "1002");
+ System.setProperty("https.proxyPort", "1003");
+ System.setProperty("other.proxyPort", "1004");
+ System.setProperty("socket.proxyPort", "1005");
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testHttpsDoesNotUseHttpProperties() throws URISyntaxException {
+ System.setProperty("http.proxyHost", "a");
+ System.setProperty("http.proxyPort", "1001");
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(httpsUri));
+ }
+
+ public void testProxyHost() throws URISyntaxException {
+ System.setProperty("proxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 443))),
+ proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testHttpProxyHostPreferredOverProxyHost() throws URISyntaxException {
+ System.setProperty("http.proxyHost", "a");
+ System.setProperty("proxyHost", "b");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(httpUri));
+ }
+
+ public void testSocksProxyHost() throws URISyntaxException {
+ System.setProperty("socksProxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1080))),
+ proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1080))),
+ proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1080))),
+ proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1080))),
+ proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testSocksProxyHostAndPort() throws URISyntaxException {
+ System.setProperty("socksProxyHost", "a");
+ System.setProperty("socksProxyPort", "1001");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1001))),
+ proxySelector.select(ftpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1001))),
+ proxySelector.select(httpUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1001))),
+ proxySelector.select(httpsUri));
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.SOCKS, createUnresolved("a", 1001))),
+ proxySelector.select(socketUri));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY), proxySelector.select(otherUri));
+ }
+
+ public void testNonProxyHostsFtp() throws URISyntaxException {
+ System.setProperty("ftp.nonProxyHosts", "*.com");
+ System.setProperty("ftp.proxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(new URI("ftp://foo.net")));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY),
+ proxySelector.select(new URI("ftp://foo.com")));
+ }
+
+ public void testNonProxyHostsHttp() throws URISyntaxException {
+ System.setProperty("http.nonProxyHosts", "*.com");
+ System.setProperty("http.proxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(new URI("http://foo.net")));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY),
+ proxySelector.select(new URI("http://foo.com")));
+ }
+
+ public void testNonProxyHostsHttps() throws URISyntaxException {
+ System.setProperty("https.nonProxyHosts", "*.com");
+ System.setProperty("https.proxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 443))),
+ proxySelector.select(new URI("https://foo.net")));
+ assertEquals(Arrays.asList(Proxy.NO_PROXY),
+ proxySelector.select(new URI("https://foo.com")));
+ }
+
+ public void testSchemeCaseSensitive() throws URISyntaxException {
+ System.setProperty("http.proxyHost", "a");
+ assertEquals(Arrays.asList(new Proxy(Proxy.Type.HTTP, createUnresolved("a", 80))),
+ proxySelector.select(new URI("HTTP://foo.net")));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/net/SocketTest.java b/luni/src/test/java/libcore/java/net/SocketTest.java
index f769a45..9fa09b7 100644
--- a/luni/src/test/java/libcore/java/net/SocketTest.java
+++ b/luni/src/test/java/libcore/java/net/SocketTest.java
@@ -29,6 +29,10 @@ import java.net.SocketException;
import java.net.SocketImpl;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
public class SocketTest extends junit.framework.TestCase {
// See http://b/2980559.
@@ -202,4 +206,83 @@ public class SocketTest extends junit.framework.TestCase {
s.setTrafficClass(123);
assertEquals(123, s.getTrafficClass());
}
+
+ public void testReadAfterClose() throws Exception {
+ MockServer server = new MockServer();
+ server.enqueue(new byte[]{5, 3}, 0);
+ Socket socket = new Socket("localhost", server.port);
+ InputStream in = socket.getInputStream();
+ assertEquals(5, in.read());
+ assertEquals(3, in.read());
+ assertEquals(-1, in.read());
+ assertEquals(-1, in.read());
+ socket.close();
+ in.close();
+
+ /*
+ * Rather astonishingly, read() doesn't throw even though the stream is
+ * closed. This is consistent with the RI's behavior.
+ */
+ assertEquals(-1, in.read());
+ assertEquals(-1, in.read());
+
+ server.shutdown();
+ }
+
+ public void testWriteAfterClose() throws Exception {
+ MockServer server = new MockServer();
+ server.enqueue(new byte[0], 3);
+ Socket socket = new Socket("localhost", server.port);
+ OutputStream out = socket.getOutputStream();
+ out.write(5);
+ out.write(3);
+ socket.close();
+ out.close();
+
+ try {
+ out.write(9);
+ fail();
+ } catch (IOException expected) {
+ }
+
+ server.shutdown();
+ }
+
+ static class MockServer {
+ private ExecutorService executor;
+ private ServerSocket serverSocket;
+ private int port = -1;
+
+ MockServer() throws IOException {
+ executor = Executors.newCachedThreadPool();
+ serverSocket = new ServerSocket(0);
+ serverSocket.setReuseAddress(true);
+ port = serverSocket.getLocalPort();
+ }
+
+ public Future<byte[]> enqueue(final byte[] sendBytes, final int receiveByteCount)
+ throws IOException {
+ return executor.submit(new Callable<byte[]>() {
+ @Override public byte[] call() throws Exception {
+ Socket socket = serverSocket.accept();
+ OutputStream out = socket.getOutputStream();
+ out.write(sendBytes);
+
+ InputStream in = socket.getInputStream();
+ byte[] result = new byte[receiveByteCount];
+ int total = 0;
+ while (total < receiveByteCount) {
+ total += in.read(result, total, result.length - total);
+ }
+ socket.close();
+ return result;
+ }
+ });
+ }
+
+ public void shutdown() throws IOException {
+ serverSocket.close();
+ executor.shutdown();
+ }
+ }
}
diff --git a/luni/src/test/java/libcore/java/net/URLConnectionTest.java b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
index e3394a5..65f2dae 100644
--- a/luni/src/test/java/libcore/java/net/URLConnectionTest.java
+++ b/luni/src/test/java/libcore/java/net/URLConnectionTest.java
@@ -25,19 +25,21 @@ import java.io.OutputStream;
import java.net.Authenticator;
import java.net.CacheRequest;
import java.net.CacheResponse;
+import java.net.ConnectException;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.ResponseCache;
-import java.net.ServerSocket;
-import java.net.Socket;
+import java.net.SecureCacheResponse;
import java.net.SocketTimeoutException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
+import java.security.Principal;
+import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
@@ -48,6 +50,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@@ -66,6 +69,12 @@ import tests.http.DefaultResponseCache;
import tests.http.MockResponse;
import tests.http.MockWebServer;
import tests.http.RecordedRequest;
+import tests.http.SocketPolicy;
+import static tests.http.SocketPolicy.DISCONNECT_AT_END;
+import static tests.http.SocketPolicy.DISCONNECT_AT_START;
+import static tests.http.SocketPolicy.SHUTDOWN_INPUT_AT_END;
+import static tests.http.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
+import tests.net.StuckServer;
public class URLConnectionTest extends junit.framework.TestCase {
@@ -160,7 +169,9 @@ public class URLConnectionTest extends junit.framework.TestCase {
HttpURLConnection urlConnection = (HttpURLConnection) server.getUrl("/").openConnection();
assertEquals(200, urlConnection.getResponseCode());
assertEquals("Fantastic", urlConnection.getResponseMessage());
+ assertEquals("HTTP/1.0 200 Fantastic", urlConnection.getHeaderField(null));
Map<String, List<String>> responseHeaders = urlConnection.getHeaderFields();
+ assertEquals(Arrays.asList("HTTP/1.0 200 Fantastic"), responseHeaders.get(null));
assertEquals(newSet("b", "c"), new HashSet<String>(responseHeaders.get("A")));
try {
responseHeaders.put("N", Arrays.asList("o"));
@@ -227,6 +238,33 @@ public class URLConnectionTest extends junit.framework.TestCase {
assertEquals(2, server.takeRequest().getSequenceNumber());
}
+ public void testServerClosesSocket() throws Exception {
+ testServerClosesOutput(DISCONNECT_AT_END);
+ }
+
+ public void testServerShutdownInput() throws Exception {
+ testServerClosesOutput(SHUTDOWN_INPUT_AT_END);
+ }
+
+ public void testServerShutdownOutput() throws Exception {
+ testServerClosesOutput(SHUTDOWN_OUTPUT_AT_END);
+ }
+
+ private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
+ server.enqueue(new MockResponse()
+ .setBody("This connection won't pool properly")
+ .setSocketPolicy(socketPolicy));
+ server.enqueue(new MockResponse()
+ .setBody("This comes after a busted connection"));
+ server.play();
+
+ assertContent("This connection won't pool properly", server.getUrl("/a").openConnection());
+ assertEquals(0, server.takeRequest().getSequenceNumber());
+ assertContent("This comes after a busted connection", server.getUrl("/b").openConnection());
+ // sequence number 0 means the HTTP socket connection was not reused
+ assertEquals(0, server.takeRequest().getSequenceNumber());
+ }
+
enum WriteKind { BYTE_BY_BYTE, SMALL_BUFFERS, LARGE_BUFFERS }
public void test_chunkedUpload_byteByByte() throws Exception {
@@ -450,7 +488,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
TestSSLContext testSSLContext = TestSSLContext.create();
server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
- server.enqueue(new MockResponse().setDisconnectAtStart(true));
+ server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AT_START));
server.enqueue(new MockResponse().setBody("this response comes via SSL"));
server.play();
@@ -570,6 +608,14 @@ public class URLConnectionTest extends junit.framework.TestCase {
testConnectViaHttpProxyToHttps(ProxyConfig.CREATE_ARG);
}
+ /**
+ * We weren't honoring all of the appropriate proxy system properties when
+ * connecting via HTTPS. http://b/3097518
+ */
+ public void testConnectViaHttpProxyToHttpsUsingProxySystemProperty() throws Exception {
+ testConnectViaHttpProxyToHttps(ProxyConfig.PROXY_SYSTEM_PROPERTY);
+ }
+
public void testConnectViaHttpProxyToHttpsUsingHttpsProxySystemProperty() throws Exception {
testConnectViaHttpProxyToHttps(ProxyConfig.HTTPS_PROXY_SYSTEM_PROPERTY);
}
@@ -672,7 +718,8 @@ public class URLConnectionTest extends junit.framework.TestCase {
* http://code.google.com/p/android/issues/detail?id=8175
*/
private void testResponseCaching(TransferKind transferKind) throws IOException {
- MockResponse response = new MockResponse();
+ MockResponse response = new MockResponse()
+ .setStatus("HTTP/1.1 200 Fantastic");
transferKind.setBody(response, "I love puppies but hate spiders", 1);
server.enqueue(response);
server.play();
@@ -681,7 +728,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
ResponseCache.setDefault(cache);
// Make sure that calling skip() doesn't omit bytes from the cache.
- URLConnection urlConnection = server.getUrl("/").openConnection();
+ HttpURLConnection urlConnection = (HttpURLConnection) server.getUrl("/").openConnection();
InputStream in = urlConnection.getInputStream();
assertEquals("I love ", readAscii(in, "I love ".length()));
reliableSkip(in, "puppies but hate ".length());
@@ -691,10 +738,13 @@ public class URLConnectionTest extends junit.framework.TestCase {
assertEquals(1, cache.getSuccessCount());
assertEquals(0, cache.getAbortCount());
- urlConnection = server.getUrl("/").openConnection(); // this response is cached!
+ urlConnection = (HttpURLConnection) server.getUrl("/").openConnection(); // cached!
in = urlConnection.getInputStream();
assertEquals("I love puppies but hate spiders",
readAscii(in, "I love puppies but hate spiders".length()));
+ assertEquals(200, urlConnection.getResponseCode());
+ assertEquals("Fantastic", urlConnection.getResponseMessage());
+
assertEquals(-1, in.read());
assertEquals(1, cache.getMissCount());
assertEquals(1, cache.getHitCount());
@@ -702,6 +752,105 @@ public class URLConnectionTest extends junit.framework.TestCase {
assertEquals(0, cache.getAbortCount());
}
+ public void testSecureResponseCaching() throws IOException {
+ TestSSLContext testSSLContext = TestSSLContext.create();
+ server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
+ server.enqueue(new MockResponse().setBody("ABC"));
+ server.play();
+
+ DefaultResponseCache cache = new DefaultResponseCache();
+ ResponseCache.setDefault(cache);
+
+ HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ // OpenJDK 6 fails on this line, complaining that the connection isn't open yet
+ String suite = connection.getCipherSuite();
+ List<Certificate> localCerts = toListOrNull(connection.getLocalCertificates());
+ List<Certificate> serverCerts = toListOrNull(connection.getServerCertificates());
+ Principal peerPrincipal = connection.getPeerPrincipal();
+ Principal localPrincipal = connection.getLocalPrincipal();
+
+ connection = (HttpsURLConnection) server.getUrl("/").openConnection(); // cached!
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ assertEquals(1, cache.getMissCount());
+ assertEquals(1, cache.getHitCount());
+
+ assertEquals(suite, connection.getCipherSuite());
+ assertEquals(localCerts, toListOrNull(connection.getLocalCertificates()));
+ assertEquals(serverCerts, toListOrNull(connection.getServerCertificates()));
+ assertEquals(peerPrincipal, connection.getPeerPrincipal());
+ assertEquals(localPrincipal, connection.getLocalPrincipal());
+ }
+
+ public void testCacheReturnsInsecureResponseForSecureRequest() throws IOException {
+ TestSSLContext testSSLContext = TestSSLContext.create();
+ server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
+ server.enqueue(new MockResponse().setBody("ABC"));
+ server.enqueue(new MockResponse().setBody("DEF"));
+ server.play();
+
+ ResponseCache insecureResponseCache = new InsecureResponseCache();
+ ResponseCache.setDefault(insecureResponseCache);
+
+ HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ connection = (HttpsURLConnection) server.getUrl("/").openConnection(); // not cached!
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("DEF", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+ }
+
+ public void testResponseCachingAndRedirects() throws IOException {
+ server.enqueue(new MockResponse()
+ .setResponseCode(HttpURLConnection.HTTP_MOVED_PERM)
+ .addHeader("Location: /foo"));
+ server.enqueue(new MockResponse().setBody("ABC"));
+ server.enqueue(new MockResponse().setBody("DEF"));
+ server.play();
+
+ DefaultResponseCache cache = new DefaultResponseCache();
+ ResponseCache.setDefault(cache);
+
+ HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ connection = (HttpURLConnection) server.getUrl("/").openConnection(); // cached!
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ assertEquals(2, cache.getMissCount()); // 1 redirect + 1 final response = 2
+ assertEquals(2, cache.getHitCount());
+ }
+
+ public void testSecureResponseCachingAndRedirects() throws IOException {
+ TestSSLContext testSSLContext = TestSSLContext.create();
+ server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
+ server.enqueue(new MockResponse()
+ .setResponseCode(HttpURLConnection.HTTP_MOVED_PERM)
+ .addHeader("Location: /foo"));
+ server.enqueue(new MockResponse().setBody("ABC"));
+ server.enqueue(new MockResponse().setBody("DEF"));
+ server.play();
+
+ DefaultResponseCache cache = new DefaultResponseCache();
+ ResponseCache.setDefault(cache);
+
+ HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ connection = (HttpsURLConnection) server.getUrl("/").openConnection(); // cached!
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ assertEquals("ABC", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ assertEquals(2, cache.getMissCount()); // 1 redirect + 1 final response = 2
+ assertEquals(2, cache.getHitCount());
+ }
+
public void testResponseCacheRequestHeaders() throws IOException, URISyntaxException {
server.enqueue(new MockResponse().setBody("ABC"));
server.play();
@@ -836,7 +985,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
* the HTTP body.
*/
private MockResponse truncateViolently(MockResponse response, int numBytesToKeep) {
- response.setDisconnectAtEnd(true);
+ response.setSocketPolicy(DISCONNECT_AT_END);
List<String> headers = new ArrayList<String>(response.getHeaders());
response.setBody(Arrays.copyOfRange(response.getBody(), 0, numBytesToKeep));
response.getHeaders().clear();
@@ -925,7 +1074,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
.setBody("5")
.clearHeaders()
.addHeader("Transfer-encoding: chunked")
- .setDisconnectAtEnd(true));
+ .setSocketPolicy(DISCONNECT_AT_END));
server.play();
URLConnection connection = server.getUrl("/").openConnection();
@@ -1081,6 +1230,48 @@ public class URLConnectionTest extends junit.framework.TestCase {
assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
}
+ public void testSecureFixedLengthStreaming() throws Exception {
+ testSecureStreamingPost(StreamingMode.FIXED_LENGTH);
+ }
+
+ public void testSecureChunkedStreaming() throws Exception {
+ testSecureStreamingPost(StreamingMode.CHUNKED);
+ }
+
+ /**
+ * Users have reported problems using HTTPS with streaming request bodies.
+ * http://code.google.com/p/android/issues/detail?id=12860
+ */
+ private void testSecureStreamingPost(StreamingMode streamingMode) throws Exception {
+ TestSSLContext testSSLContext = TestSSLContext.create();
+ server.useHttps(testSSLContext.serverContext.getSocketFactory(), false);
+ server.enqueue(new MockResponse().setBody("Success!"));
+ server.play();
+
+ HttpsURLConnection connection = (HttpsURLConnection) server.getUrl("/").openConnection();
+ connection.setSSLSocketFactory(testSSLContext.clientContext.getSocketFactory());
+ connection.setDoOutput(true);
+ byte[] requestBody = { 'A', 'B', 'C', 'D' };
+ if (streamingMode == StreamingMode.FIXED_LENGTH) {
+ connection.setFixedLengthStreamingMode(requestBody.length);
+ } else if (streamingMode == StreamingMode.CHUNKED) {
+ connection.setChunkedStreamingMode(0);
+ }
+ OutputStream outputStream = connection.getOutputStream();
+ outputStream.write(requestBody);
+ outputStream.close();
+ assertEquals("Success!", readAscii(connection.getInputStream(), Integer.MAX_VALUE));
+
+ RecordedRequest request = server.takeRequest();
+ assertEquals("POST / HTTP/1.1", request.getRequestLine());
+ if (streamingMode == StreamingMode.FIXED_LENGTH) {
+ assertEquals(Collections.<Integer>emptyList(), request.getChunkSizes());
+ } else if (streamingMode == StreamingMode.CHUNKED) {
+ assertEquals(Arrays.asList(4), request.getChunkSizes());
+ }
+ assertEquals(Arrays.toString(requestBody), Arrays.toString(request.getBody()));
+ }
+
enum StreamingMode {
FIXED_LENGTH, CHUNKED
}
@@ -1290,10 +1481,10 @@ public class URLConnectionTest extends junit.framework.TestCase {
assertEquals(Arrays.asList("verify " + hostname), hostnameVerifier.calls);
assertEquals(Arrays.asList("checkServerTrusted ["
- + "CN=" + hostname + " 1, "
- + "CN=Test Intermediate Certificate Authority 1, "
- + "CN=Test Root Certificate Authority 1"
- + "] RSA"),
+ + "CN=" + hostname + " 1, "
+ + "CN=Test Intermediate Certificate Authority 1, "
+ + "CN=Test Root Certificate Authority 1"
+ + "] RSA"),
trustManager.calls);
} finally {
HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
@@ -1302,27 +1493,20 @@ public class URLConnectionTest extends junit.framework.TestCase {
}
public void testConnectTimeouts() throws IOException {
- // Set a backlog and use it up so that we can expect the
- // URLConnection to properly timeout. According to Steven's
- // 4.5 "listen function", linux adds 3 to the specified
- // backlog, so we need to connect 4 times before it will hang.
- ServerSocket serverSocket = new ServerSocket(0, 1);
- int serverPort = serverSocket.getLocalPort();
- Socket[] sockets = new Socket[4];
- for (int i = 0; i < sockets.length; i++) {
- sockets[i] = new Socket("localhost", serverPort);
- }
-
+ StuckServer ss = new StuckServer();
+ int serverPort = ss.getLocalPort();
URLConnection urlConnection = new URL("http://localhost:" + serverPort).openConnection();
- urlConnection.setConnectTimeout(1000);
+ int timeout = 1000;
+ urlConnection.setConnectTimeout(timeout);
+ long start = System.currentTimeMillis();
try {
urlConnection.getInputStream();
fail();
} catch (SocketTimeoutException expected) {
- }
-
- for (Socket s : sockets) {
- s.close();
+ long actual = System.currentTimeMillis() - start;
+ assertTrue(Math.abs(timeout - actual) < 500);
+ } finally {
+ ss.close();
}
}
@@ -1337,6 +1521,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
.clearHeaders()
.addHeader("Content-Length: 4");
server.enqueue(timeout);
+ server.enqueue(new MockResponse().setBody("unused")); // to keep the server alive
server.play();
URLConnection urlConnection = server.getUrl("/").openConnection();
@@ -1483,7 +1668,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
}
public void testGetHeadersThrows() throws IOException {
- server.enqueue(new MockResponse().setDisconnectAtStart(true));
+ server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AT_START));
server.play();
HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
@@ -1500,6 +1685,161 @@ public class URLConnectionTest extends junit.framework.TestCase {
}
}
+ public void testGetKeepAlive() throws Exception {
+ MockWebServer server = new MockWebServer();
+ server.enqueue(new MockResponse().setBody("ABC"));
+ server.play();
+
+ // The request should work once and then fail
+ URLConnection connection = server.getUrl("").openConnection();
+ InputStream input = connection.getInputStream();
+ assertEquals("ABC", readAscii(input, Integer.MAX_VALUE));
+ input.close();
+ try {
+ server.getUrl("").openConnection().getInputStream();
+ fail();
+ } catch (ConnectException expected) {
+ }
+ }
+
+ /**
+ * This test goes through the exhaustive set of interesting ASCII characters
+ * because most of those characters are interesting in some way according to
+ * RFC 2396 and RFC 2732. http://b/1158780
+ */
+ public void testLenientUrlToUri() throws Exception {
+ // alphanum
+ testUrlToUriMapping("abzABZ09", "abzABZ09", "abzABZ09", "abzABZ09", "abzABZ09");
+
+ // control characters
+ testUrlToUriMapping("\u0001", "%01", "%01", "%01", "%01");
+ testUrlToUriMapping("\u001f", "%1F", "%1F", "%1F", "%1F");
+
+ // ascii characters
+ testUrlToUriMapping("%20", "%20", "%20", "%20", "%20");
+ testUrlToUriMapping("%20", "%20", "%20", "%20", "%20");
+ testUrlToUriMapping(" ", "%20", "%20", "%20", "%20");
+ testUrlToUriMapping("!", "!", "!", "!", "!");
+ testUrlToUriMapping("\"", "%22", "%22", "%22", "%22");
+ testUrlToUriMapping("#", null, null, null, "%23");
+ testUrlToUriMapping("$", "$", "$", "$", "$");
+ testUrlToUriMapping("&", "&", "&", "&", "&");
+ testUrlToUriMapping("'", "'", "'", "'", "'");
+ testUrlToUriMapping("(", "(", "(", "(", "(");
+ testUrlToUriMapping(")", ")", ")", ")", ")");
+ testUrlToUriMapping("*", "*", "*", "*", "*");
+ testUrlToUriMapping("+", "+", "+", "+", "+");
+ testUrlToUriMapping(",", ",", ",", ",", ",");
+ testUrlToUriMapping("-", "-", "-", "-", "-");
+ testUrlToUriMapping(".", ".", ".", ".", ".");
+ testUrlToUriMapping("/", null, "/", "/", "/");
+ testUrlToUriMapping(":", null, ":", ":", ":");
+ testUrlToUriMapping(";", ";", ";", ";", ";");
+ testUrlToUriMapping("<", "%3C", "%3C", "%3C", "%3C");
+ testUrlToUriMapping("=", "=", "=", "=", "=");
+ testUrlToUriMapping(">", "%3E", "%3E", "%3E", "%3E");
+ testUrlToUriMapping("?", null, null, "?", "?");
+ testUrlToUriMapping("@", "@", "@", "@", "@");
+ testUrlToUriMapping("[", null, "%5B", null, "%5B");
+ testUrlToUriMapping("\\", "%5C", "%5C", "%5C", "%5C");
+ testUrlToUriMapping("]", null, "%5D", null, "%5D");
+ testUrlToUriMapping("^", "%5E", "%5E", "%5E", "%5E");
+ testUrlToUriMapping("_", "_", "_", "_", "_");
+ testUrlToUriMapping("`", "%60", "%60", "%60", "%60");
+ testUrlToUriMapping("{", "%7B", "%7B", "%7B", "%7B");
+ testUrlToUriMapping("|", "%7C", "%7C", "%7C", "%7C");
+ testUrlToUriMapping("}", "%7D", "%7D", "%7D", "%7D");
+ testUrlToUriMapping("~", "~", "~", "~", "~");
+ testUrlToUriMapping("~", "~", "~", "~", "~");
+ testUrlToUriMapping("\u007f", "%7F", "%7F", "%7F", "%7F");
+
+ // beyond ascii
+ testUrlToUriMapping("\u0080", "%C2%80", "%C2%80", "%C2%80", "%C2%80");
+ testUrlToUriMapping("\u20ac", "\u20ac", "\u20ac", "\u20ac", "\u20ac");
+ }
+
+ public void testLenientUrlToUriNul() throws Exception {
+ testUrlToUriMapping("\u0000", "%00", "%00", "%00", "%00"); // RI fails this
+ }
+
+ private void testUrlToUriMapping(String string, String asAuthority, String asFile,
+ String asQuery, String asFragment) throws Exception {
+ if (asAuthority != null) {
+ assertEquals("http://host" + asAuthority + ".tld/",
+ backdoorUrlToUri(new URL("http://host" + string + ".tld/")).toString());
+ }
+ if (asFile != null) {
+ assertEquals("http://host.tld/file" + asFile + "/",
+ backdoorUrlToUri(new URL("http://host.tld/file" + string + "/")).toString());
+ }
+ if (asQuery != null) {
+ assertEquals("http://host.tld/file?q" + asQuery + "=x",
+ backdoorUrlToUri(new URL("http://host.tld/file?q" + string + "=x")).toString());
+ }
+ assertEquals("http://host.tld/file#" + asFragment + "-x",
+ backdoorUrlToUri(new URL("http://host.tld/file#" + asFragment + "-x")).toString());
+ }
+
+ /**
+ * Exercises HttpURLConnection to convert URL to a URI. Unlike URL#toURI,
+ * HttpURLConnection recovers from URLs with unescaped but unsupported URI
+ * characters like '{' and '|' by escaping these characters.
+ */
+ private URI backdoorUrlToUri(URL url) throws Exception {
+ final AtomicReference<URI> uriReference = new AtomicReference<URI>();
+
+ ResponseCache.setDefault(new ResponseCache() {
+ @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
+ return null;
+ }
+ @Override public CacheResponse get(URI uri, String requestMethod,
+ Map<String, List<String>> requestHeaders) throws IOException {
+ uriReference.set(uri);
+ throw new UnsupportedOperationException();
+ }
+ });
+
+ try {
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.getResponseCode();
+ } catch (Exception expected) {
+ }
+
+ return uriReference.get();
+ }
+
+ /**
+ * Don't explode if the cache returns a null body. http://b/3373699
+ */
+ public void testResponseCacheReturnsNullOutputStream() throws Exception {
+ final AtomicBoolean aborted = new AtomicBoolean();
+ ResponseCache.setDefault(new ResponseCache() {
+ @Override public CacheResponse get(URI uri, String requestMethod,
+ Map<String, List<String>> requestHeaders) throws IOException {
+ return null;
+ }
+ @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
+ return new CacheRequest() {
+ @Override public void abort() {
+ aborted.set(true);
+ }
+ @Override public OutputStream getBody() throws IOException {
+ return null;
+ }
+ };
+ }
+ });
+
+ server.enqueue(new MockResponse().setBody("abcdef"));
+ server.play();
+
+ HttpURLConnection connection = (HttpURLConnection) server.getUrl("/").openConnection();
+ InputStream in = connection.getInputStream();
+ assertEquals("abc", readAscii(in, 3));
+ in.close();
+ assertFalse(aborted.get()); // The best behavior is ambiguous, but RI 6 doesn't abort here
+ }
+
/**
* Encodes the response body using GZIP and adds the corresponding header.
*/
@@ -1511,6 +1851,10 @@ public class URLConnectionTest extends junit.framework.TestCase {
return bytesOut.toByteArray();
}
+ private <T> List<T> toListOrNull(T[] arrayOrNull) {
+ return arrayOrNull != null ? Arrays.asList(arrayOrNull) : null;
+ }
+
/**
* Reads at most {@code limit} characters from {@code in} and asserts that
* content equals {@code expected}.
@@ -1557,7 +1901,7 @@ public class URLConnectionTest extends junit.framework.TestCase {
END_OF_STREAM() {
@Override void setBody(MockResponse response, byte[] content, int chunkSize) {
response.setBody(content);
- response.setDisconnectAtEnd(true);
+ response.setSocketPolicy(DISCONNECT_AT_END);
for (Iterator<String> h = response.getHeaders().iterator(); h.hasNext(); ) {
if (h.next().startsWith("Content-Length:")) {
h.remove();
@@ -1655,4 +1999,28 @@ public class URLConnectionTest extends junit.framework.TestCase {
return true;
}
}
+
+ private static class InsecureResponseCache extends ResponseCache {
+ private final DefaultResponseCache delegate = new DefaultResponseCache();
+
+ @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
+ return delegate.put(uri, connection);
+ }
+
+ @Override public CacheResponse get(URI uri, String requestMethod,
+ Map<String, List<String>> requestHeaders) throws IOException {
+ final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
+ if (response instanceof SecureCacheResponse) {
+ return new CacheResponse() {
+ @Override public InputStream getBody() throws IOException {
+ return response.getBody();
+ }
+ @Override public Map<String, List<String>> getHeaders() throws IOException {
+ return response.getHeaders();
+ }
+ };
+ }
+ return response;
+ }
+ }
}
diff --git a/luni/src/test/java/libcore/java/net/URLTest.java b/luni/src/test/java/libcore/java/net/URLTest.java
new file mode 100644
index 0000000..f5091bb
--- /dev/null
+++ b/luni/src/test/java/libcore/java/net/URLTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.net;
+
+import java.net.URL;
+import junit.framework.TestCase;
+
+public class URLTest extends TestCase {
+ // http://code.google.com/p/android/issues/detail?id=12724
+ public void testExplicitPort() throws Exception {
+ URL url = new URL("http://www.google.com:80/example?language[id]=2");
+ assertEquals("www.google.com", url.getHost());
+ assertEquals(80, url.getPort());
+ }
+
+ public void testHostWithSlashInFragment() throws Exception {
+ URL url = new URL("http://www.google.com#foo/bar");
+ assertEquals("www.google.com", url.getHost());
+ assertEquals("foo/bar", url.getRef());
+ assertEquals(-1, url.getPort());
+ }
+
+ public void testHostWithColonAndSlashInFragment() throws Exception {
+ URL url = new URL("http://www.google.com#foo:bar/baz");
+ assertEquals("www.google.com", url.getHost());
+ assertEquals("foo:bar/baz", url.getRef());
+ assertEquals(-1, url.getPort());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/BufferTest.java b/luni/src/test/java/libcore/java/nio/BufferTest.java
new file mode 100644
index 0000000..ec85235
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/BufferTest.java
@@ -0,0 +1,419 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio;
+
+import java.io.*;
+import java.nio.*;
+import java.nio.channels.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+
+public class BufferTest extends TestCase {
+ private static ByteBuffer allocateMapped(int size) throws Exception {
+ File f = File.createTempFile("mapped", "tmp");
+ f.deleteOnExit();
+ RandomAccessFile raf = new RandomAccessFile(f, "rw");
+ raf.setLength(size);
+ FileChannel ch = raf.getChannel();
+ MappedByteBuffer result = ch.map(FileChannel.MapMode.READ_WRITE, 0, size);
+ ch.close();
+ return result;
+ }
+
+ public void testByteSwappedBulkGetDirect() throws Exception {
+ testByteSwappedBulkGet(ByteBuffer.allocateDirect(10));
+ }
+
+ public void testByteSwappedBulkGetHeap() throws Exception {
+ testByteSwappedBulkGet(ByteBuffer.allocate(10));
+ }
+
+ public void testByteSwappedBulkGetMapped() throws Exception {
+ testByteSwappedBulkGet(allocateMapped(10));
+ }
+
+ private void testByteSwappedBulkGet(ByteBuffer b) throws Exception {
+ for (int i = 0; i < b.limit(); ++i) {
+ b.put(i, (byte) i);
+ }
+ b.position(1);
+
+ char[] chars = new char[6];
+ b.order(ByteOrder.BIG_ENDIAN).asCharBuffer().get(chars, 1, 4);
+ assertEquals("[\u0000, \u0102, \u0304, \u0506, \u0708, \u0000]", Arrays.toString(chars));
+ b.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer().get(chars, 1, 4);
+ assertEquals("[\u0000, \u0201, \u0403, \u0605, \u0807, \u0000]", Arrays.toString(chars));
+
+ double[] doubles = new double[3];
+ b.order(ByteOrder.BIG_ENDIAN).asDoubleBuffer().get(doubles, 1, 1);
+ assertEquals(0, Double.doubleToRawLongBits(doubles[0]));
+ assertEquals(0x0102030405060708L, Double.doubleToRawLongBits(doubles[1]));
+ assertEquals(0, Double.doubleToRawLongBits(doubles[2]));
+ b.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer().get(doubles, 1, 1);
+ assertEquals(0, Double.doubleToRawLongBits(doubles[0]));
+ assertEquals(0x0807060504030201L, Double.doubleToRawLongBits(doubles[1]));
+ assertEquals(0, Double.doubleToRawLongBits(doubles[2]));
+
+ float[] floats = new float[4];
+ b.order(ByteOrder.BIG_ENDIAN).asFloatBuffer().get(floats, 1, 2);
+ assertEquals(0, Float.floatToRawIntBits(floats[0]));
+ assertEquals(0x01020304, Float.floatToRawIntBits(floats[1]));
+ assertEquals(0x05060708, Float.floatToRawIntBits(floats[2]));
+ assertEquals(0, Float.floatToRawIntBits(floats[3]));
+ b.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer().get(floats, 1, 2);
+ assertEquals(0, Float.floatToRawIntBits(floats[0]));
+ assertEquals(0x04030201, Float.floatToRawIntBits(floats[1]));
+ assertEquals(0x08070605, Float.floatToRawIntBits(floats[2]));
+ assertEquals(0, Float.floatToRawIntBits(floats[3]));
+
+ int[] ints = new int[4];
+ b.order(ByteOrder.BIG_ENDIAN).asIntBuffer().get(ints, 1, 2);
+ assertEquals(0, ints[0]);
+ assertEquals(0x01020304, ints[1]);
+ assertEquals(0x05060708, ints[2]);
+ assertEquals(0, ints[3]);
+ b.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().get(ints, 1, 2);
+ assertEquals(0, ints[0]);
+ assertEquals(0x04030201, ints[1]);
+ assertEquals(0x08070605, ints[2]);
+ assertEquals(0, ints[3]);
+
+ long[] longs = new long[3];
+ b.order(ByteOrder.BIG_ENDIAN).asLongBuffer().get(longs, 1, 1);
+ assertEquals(0, longs[0]);
+ assertEquals(0x0102030405060708L, longs[1]);
+ assertEquals(0, longs[2]);
+ b.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer().get(longs, 1, 1);
+ assertEquals(0, longs[0]);
+ assertEquals(0x0807060504030201L, longs[1]);
+ assertEquals(0, longs[2]);
+
+ short[] shorts = new short[6];
+ b.order(ByteOrder.BIG_ENDIAN).asShortBuffer().get(shorts, 1, 4);
+ assertEquals(0, shorts[0]);
+ assertEquals(0x0102, shorts[1]);
+ assertEquals(0x0304, shorts[2]);
+ assertEquals(0x0506, shorts[3]);
+ assertEquals(0x0708, shorts[4]);
+ assertEquals(0, shorts[5]);
+ b.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shorts, 1, 4);
+ assertEquals(0, shorts[0]);
+ assertEquals(0x0201, shorts[1]);
+ assertEquals(0x0403, shorts[2]);
+ assertEquals(0x0605, shorts[3]);
+ assertEquals(0x0807, shorts[4]);
+ assertEquals(0, shorts[5]);
+ }
+
+ private static String toString(ByteBuffer b) {
+ StringBuilder result = new StringBuilder();
+ for (int i = 0; i < b.limit(); ++i) {
+ result.append(String.format("%02x", (int) b.get(i)));
+ }
+ return result.toString();
+ }
+
+ public void testByteSwappedBulkPutDirect() throws Exception {
+ testByteSwappedBulkPut(ByteBuffer.allocateDirect(10));
+ }
+
+ public void testByteSwappedBulkPutHeap() throws Exception {
+ testByteSwappedBulkPut(ByteBuffer.allocate(10));
+ }
+
+ public void testByteSwappedBulkPutMapped() throws Exception {
+ testByteSwappedBulkPut(allocateMapped(10));
+ }
+
+ private void testByteSwappedBulkPut(ByteBuffer b) throws Exception {
+ b.position(1);
+
+ char[] chars = new char[] { '\u2222', '\u0102', '\u0304', '\u0506', '\u0708', '\u2222' };
+ b.order(ByteOrder.BIG_ENDIAN).asCharBuffer().put(chars, 1, 4);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asCharBuffer().put(chars, 1, 4);
+ assertEquals("00020104030605080700", toString(b));
+
+ double[] doubles = new double[] { 0, Double.longBitsToDouble(0x0102030405060708L), 0 };
+ b.order(ByteOrder.BIG_ENDIAN).asDoubleBuffer().put(doubles, 1, 1);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asDoubleBuffer().put(doubles, 1, 1);
+ assertEquals("00080706050403020100", toString(b));
+
+ float[] floats = new float[] { 0, Float.intBitsToFloat(0x01020304),
+ Float.intBitsToFloat(0x05060708), 0 };
+ b.order(ByteOrder.BIG_ENDIAN).asFloatBuffer().put(floats, 1, 2);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asFloatBuffer().put(floats, 1, 2);
+ assertEquals("00040302010807060500", toString(b));
+
+ int[] ints = new int[] { 0, 0x01020304, 0x05060708, 0 };
+ b.order(ByteOrder.BIG_ENDIAN).asIntBuffer().put(ints, 1, 2);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asIntBuffer().put(ints, 1, 2);
+ assertEquals("00040302010807060500", toString(b));
+
+ long[] longs = new long[] { 0, 0x0102030405060708L, 0 };
+ b.order(ByteOrder.BIG_ENDIAN).asLongBuffer().put(longs, 1, 1);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asLongBuffer().put(longs, 1, 1);
+ assertEquals("00080706050403020100", toString(b));
+
+ short[] shorts = new short[] { 0, 0x0102, 0x0304, 0x0506, 0x0708, 0 };
+ b.order(ByteOrder.BIG_ENDIAN).asShortBuffer().put(shorts, 1, 4);
+ assertEquals("00010203040506070800", toString(b));
+ b.order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(shorts, 1, 4);
+ assertEquals("00020104030605080700", toString(b));
+ }
+
+ public void testByteBufferByteOrderDirectRW() throws Exception {
+ testByteBufferByteOrder(ByteBuffer.allocateDirect(10), false);
+ }
+
+ public void testByteBufferByteOrderHeapRW() throws Exception {
+ testByteBufferByteOrder(ByteBuffer.allocate(10), false);
+ }
+
+ public void testByteBufferByteOrderMappedRW() throws Exception {
+ testByteBufferByteOrder(allocateMapped(10), false);
+ }
+
+ public void testByteBufferByteOrderDirectRO() throws Exception {
+ testByteBufferByteOrder(ByteBuffer.allocateDirect(10), true);
+ }
+
+ public void testByteBufferByteOrderHeapRO() throws Exception {
+ testByteBufferByteOrder(ByteBuffer.allocate(10), true);
+ }
+
+ public void testByteBufferByteOrderMappedRO() throws Exception {
+ testByteBufferByteOrder(allocateMapped(10), true);
+ }
+
+ private void testByteBufferByteOrder(ByteBuffer b, boolean readOnly) throws Exception {
+ if (readOnly) {
+ b = b.asReadOnlyBuffer();
+ }
+ // allocate/allocateDirect/map always returns a big-endian buffer.
+ assertEquals(ByteOrder.BIG_ENDIAN, b.order());
+
+ // wrap always returns a big-endian buffer.
+ assertEquals(ByteOrder.BIG_ENDIAN, b.wrap(new byte[10]).order());
+
+ // duplicate always returns a big-endian buffer.
+ b.order(ByteOrder.BIG_ENDIAN);
+ assertEquals(ByteOrder.BIG_ENDIAN, b.duplicate().order());
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals(ByteOrder.BIG_ENDIAN, b.duplicate().order());
+
+ // slice always returns a big-endian buffer.
+ b.order(ByteOrder.BIG_ENDIAN);
+ assertEquals(ByteOrder.BIG_ENDIAN, b.slice().order());
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals(ByteOrder.BIG_ENDIAN, b.slice().order());
+
+ // asXBuffer always returns a current-endian buffer.
+ b.order(ByteOrder.BIG_ENDIAN);
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asCharBuffer().order());
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asDoubleBuffer().order());
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asFloatBuffer().order());
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asIntBuffer().order());
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asLongBuffer().order());
+ assertEquals(ByteOrder.BIG_ENDIAN, b.asShortBuffer().order());
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asCharBuffer().order());
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asDoubleBuffer().order());
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asFloatBuffer().order());
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asIntBuffer().order());
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asLongBuffer().order());
+ assertEquals(ByteOrder.LITTLE_ENDIAN, b.asShortBuffer().order());
+ }
+
+ public void testCharBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ CharBuffer b = CharBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new char[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new char[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testDoubleBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ DoubleBuffer b = DoubleBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new double[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new double[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testFloatBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ FloatBuffer b = FloatBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new float[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new float[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testIntBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ IntBuffer b = IntBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new int[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new int[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testLongBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ LongBuffer b = LongBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new long[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new long[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testShortBufferByteOrder() throws Exception {
+ // Everything always returns a native-endian buffer.
+ ShortBuffer b = ShortBuffer.allocate(10);
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new short[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ b = b.asReadOnlyBuffer();
+ assertEquals(ByteOrder.nativeOrder(), b.order());
+ assertEquals(ByteOrder.nativeOrder(), b.wrap(new short[10]).order());
+ assertEquals(ByteOrder.nativeOrder(), b.duplicate().order());
+ assertEquals(ByteOrder.nativeOrder(), b.slice().order());
+ }
+
+ public void testRelativePositionsHeap() throws Exception {
+ testRelativePositions(ByteBuffer.allocate(10));
+ }
+
+ public void testRelativePositionsDirect() throws Exception {
+ testRelativePositions(ByteBuffer.allocateDirect(10));
+ }
+
+ public void testRelativePositionsMapped() throws Exception {
+ testRelativePositions(allocateMapped(10));
+ }
+
+ // http://b/3291927 - ensure that the relative get and put methods advance 'position'.
+ private void testRelativePositions(ByteBuffer b) throws Exception {
+ // gets
+ b.position(0);
+ b.get();
+ assertEquals(1, b.position());
+
+ byte[] buf = new byte[5];
+ b.position(0);
+ b.get(buf);
+ assertEquals(5, b.position());
+
+ b.position(0);
+ b.get(buf, 1, 3);
+ assertEquals(3, b.position());
+
+ b.position(0);
+ b.getChar();
+ assertEquals(2, b.position());
+
+ b.position(0);
+ b.getDouble();
+ assertEquals(8, b.position());
+
+ b.position(0);
+ b.getFloat();
+ assertEquals(4, b.position());
+
+ b.position(0);
+ b.getInt();
+ assertEquals(4, b.position());
+
+ b.position(0);
+ b.getLong();
+ assertEquals(8, b.position());
+
+ b.position(0);
+ b.getShort();
+ assertEquals(2, b.position());
+
+ // puts
+ b.position(0);
+ b.put((byte) 0);
+ assertEquals(1, b.position());
+
+ b.position(0);
+ b.put(buf);
+ assertEquals(5, b.position());
+
+ b.position(0);
+ b.put(buf, 1, 3);
+ assertEquals(3, b.position());
+
+ b.position(0);
+ b.putChar('x');
+ assertEquals(2, b.position());
+
+ b.position(0);
+ b.putDouble(0);
+ assertEquals(8, b.position());
+
+ b.position(0);
+ b.putFloat(0);
+ assertEquals(4, b.position());
+
+ b.position(0);
+ b.putInt(0);
+ assertEquals(4, b.position());
+
+ b.position(0);
+ b.putLong(0);
+ assertEquals(8, b.position());
+
+ b.position(0);
+ b.putShort((short) 0);
+ assertEquals(2, b.position());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/NoArrayTest.java b/luni/src/test/java/libcore/java/nio/NoArrayTest.java
new file mode 100644
index 0000000..04d9af1
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/NoArrayTest.java
@@ -0,0 +1,51 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio;
+
+import java.nio.ByteBuffer;
+import java.nio.ReadOnlyBufferException;
+import junit.framework.TestCase;
+
+public final class NoArrayTest extends TestCase {
+
+ public void testWrappedReadOnly() {
+ assertNoArray(ByteBuffer.wrap(new byte[32]).asReadOnlyBuffer());
+ }
+
+ public void testAllocatedReadOnly() {
+ assertNoArray(ByteBuffer.allocate(32).asReadOnlyBuffer());
+ }
+
+ public void testAllocatedDirect() {
+ assertNoArray(ByteBuffer.allocateDirect(32));
+ }
+
+ private void assertNoArray(ByteBuffer buf) {
+ try {
+ buf.asReadOnlyBuffer().array();
+ fail();
+ } catch (ReadOnlyBufferException expected) {
+ } catch (UnsupportedOperationException expected) {
+ }
+ try {
+ buf.arrayOffset();
+ fail();
+ } catch (ReadOnlyBufferException expected) {
+ } catch (UnsupportedOperationException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/OldAndroidNIOTest.java b/luni/src/test/java/libcore/java/nio/OldAndroidNIOTest.java
new file mode 100644
index 0000000..deea63f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/OldAndroidNIOTest.java
@@ -0,0 +1,704 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio;
+
+import java.nio.Buffer;
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.ShortBuffer;
+import junit.framework.TestCase;
+
+/**
+ * Tests for some buffers from the java.nio package.
+ */
+public class OldAndroidNIOTest extends TestCase {
+
+ void checkBuffer(Buffer b) {
+ assertTrue(0 <= b.position());
+ assertTrue(b.position() <= b.limit());
+ assertTrue(b.limit() <= b.capacity());
+ }
+
+ public void testNIO_byte_array() throws Exception {
+ // Test byte array-based buffer
+ byteBufferTest(ByteBuffer.allocate(12));
+ }
+
+ public void testNIO_direct() throws Exception {
+ // Test native heap-allocated buffer
+ byteBufferTest(ByteBuffer.allocateDirect(12));
+ }
+
+ public void testNIO_short_array() throws Exception {
+ // Test short array-based buffer
+ short[] shortArray = new short[8];
+ ShortBuffer sb = ShortBuffer.wrap(shortArray);
+ shortBufferTest(sb);
+ }
+
+ public void testNIO_int_array() throws Exception {
+ // Test int array-based buffer
+ int[] intArray = new int[8];
+ IntBuffer ib = IntBuffer.wrap(intArray);
+ intBufferTest(ib);
+ }
+
+ public void testNIO_float_array() throws Exception {
+ // Test float array-based buffer
+ float[] floatArray = new float[8];
+ FloatBuffer fb = FloatBuffer.wrap(floatArray);
+ floatBufferTest(fb);
+ }
+
+ private void byteBufferTest(ByteBuffer b) {
+ checkBuffer(b);
+
+ // Duplicate buffers revert to big-endian.
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ ByteBuffer dupe = b.duplicate();
+ assertEquals(ByteOrder.BIG_ENDIAN, dupe.order());
+ b.order(ByteOrder.BIG_ENDIAN);
+
+ // Bounds checks
+ try {
+ b.put(-1, (byte) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ b.put(b.limit(), (byte) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: offset < 0
+ try {
+ byte[] data = new byte[8];
+ b.position(0);
+ b.put(data, -1, 2);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: length > array.length - offset
+ try {
+ byte[] data = new byte[8];
+ b.position(0);
+ b.put(data, 1, 8);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // BufferOverflowException: length > remaining()
+ try {
+ byte[] data = new byte[8];
+ b.position(b.limit() - 2);
+ b.put(data, 0, 3);
+ fail("expected exception not thrown");
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+
+ // Fill buffer with bytes A0 A1 A2 A3 ...
+ b.position(0);
+ for (int i = 0; i < b.capacity(); i++) {
+ b.put((byte) (0xA0 + i));
+ }
+ try {
+ b.put((byte) 0xFF);
+ fail("expected exception not thrown");
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+
+ b.position(0);
+ assertEquals((byte) 0xA7, b.get(7));
+ try {
+ b.get(12);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ b.get(-10);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ b.position(0);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals((byte) 0xA0, b.get());
+ assertEquals((byte) 0xA1, b.get());
+ assertEquals((byte) 0xA2, b.get());
+ assertEquals((byte) 0xA3, b.get());
+ assertEquals((byte) 0xA4, b.get());
+ assertEquals((byte) 0xA5, b.get());
+ assertEquals((byte) 0xA6, b.get());
+ assertEquals((byte) 0xA7, b.get());
+ assertEquals((byte) 0xA8, b.get());
+ assertEquals((byte) 0xA9, b.get());
+ assertEquals((byte) 0xAA, b.get());
+ assertEquals((byte) 0xAB, b.get());
+ try {
+ b.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ b.position(0);
+ b.order(ByteOrder.BIG_ENDIAN);
+ assertEquals((byte) 0xA0, b.get());
+ assertEquals((byte) 0xA1, b.get());
+ assertEquals((byte) 0xA2, b.get());
+ assertEquals((byte) 0xA3, b.get());
+ assertEquals((byte) 0xA4, b.get());
+ assertEquals((byte) 0xA5, b.get());
+ assertEquals((byte) 0xA6, b.get());
+ assertEquals((byte) 0xA7, b.get());
+ assertEquals((byte) 0xA8, b.get());
+ assertEquals((byte) 0xA9, b.get());
+ assertEquals((byte) 0xAA, b.get());
+ assertEquals((byte) 0xAB, b.get());
+ try {
+ b.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ b.position(6);
+ b.limit(10);
+ assertEquals((byte) 0xA6, b.get());
+
+ // Check sliced buffer
+ b.position(6);
+
+ ByteBuffer bb = b.slice();
+ checkBuffer(bb);
+
+ assertEquals(0, bb.position());
+ assertEquals(4, bb.limit());
+ assertEquals(4, bb.capacity());
+
+ assertEquals((byte) 0xA6, bb.get());
+ assertEquals((byte) 0xA7, bb.get());
+ assertEquals((byte) 0xA8, bb.get());
+ assertEquals((byte) 0xA9, bb.get());
+ try {
+ bb.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ // Reset position and limit
+ b.position(0);
+ b.limit(b.capacity());
+
+ // Check 'getShort'
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(0);
+ assertEquals((short) 0xA1A0, b.getShort());
+ assertEquals((short) 0xA3A2, b.getShort());
+ assertEquals((short) 0xA5A4, b.getShort());
+ assertEquals((short) 0xA7A6, b.getShort());
+ assertEquals((short) 0xA9A8, b.getShort());
+ assertEquals((short) 0xABAA, b.getShort());
+ try {
+ bb.getShort();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ b.position(0);
+ assertEquals((short) 0xA0A1, b.getShort());
+ assertEquals((short) 0xA2A3, b.getShort());
+ assertEquals((short) 0xA4A5, b.getShort());
+ assertEquals((short) 0xA6A7, b.getShort());
+ assertEquals((short) 0xA8A9, b.getShort());
+ assertEquals((short) 0xAAAB, b.getShort());
+ try {
+ bb.getShort();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ // Check 'getInt'
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(0);
+ assertEquals(0xA3A2A1A0, b.getInt());
+ assertEquals(0xA7A6A5A4, b.getInt());
+ assertEquals(0xABAAA9A8, b.getInt());
+ try {
+ bb.getInt();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ b.position(0);
+ assertEquals(0xA0A1A2A3, b.getInt());
+ assertEquals(0xA4A5A6A7, b.getInt());
+ assertEquals(0xA8A9AAAB, b.getInt());
+ try {
+ bb.getInt();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ // Check 'getFloat'
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ b.position(0);
+ assertEquals(0xA3A2A1A0, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA7A6A5A4, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xABAAA9A8, Float.floatToRawIntBits(b.getFloat()));
+ try {
+ b.getFloat();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ b.position(0);
+ assertEquals(0xA0A1A2A3, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA4A5A6A7, Float.floatToRawIntBits(b.getFloat()));
+ assertEquals(0xA8A9AAAB, Float.floatToRawIntBits(b.getFloat()));
+ try {
+ b.getFloat();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ // Check 'getDouble(int position)'
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals(0xA7A6A5A4A3A2A1A0L, Double.doubleToRawLongBits(b.getDouble(0)));
+ assertEquals(0xA8A7A6A5A4A3A2A1L, Double.doubleToRawLongBits(b.getDouble(1)));
+ try {
+ b.getDouble(-1);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ b.getDouble(5);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ b.order(ByteOrder.BIG_ENDIAN);
+ assertEquals(0xA0A1A2A3A4A5A6A7L, Double.doubleToRawLongBits(b.getDouble(0)));
+ assertEquals(0xA1A2A3A4A5A6A7A8L, Double.doubleToRawLongBits(b.getDouble(1)));
+ try {
+ b.getDouble(-1);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+ try {
+ b.getDouble(5);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // Slice and check 'getInt'
+ b.position(1);
+ b.limit(5);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ bb = b.slice();
+ assertEquals(4, bb.capacity());
+ assertEquals(ByteOrder.BIG_ENDIAN, bb.order());
+ assertEquals(0xA1A2A3A4, bb.getInt(0));
+ bb.order(ByteOrder.LITTLE_ENDIAN);
+ assertEquals(0xA4A3A2A1, bb.getInt(0));
+
+ bb.order(ByteOrder.LITTLE_ENDIAN);
+ ShortBuffer sb = bb.asShortBuffer();
+
+ checkBuffer(sb);
+ assertEquals(2, sb.capacity());
+ assertEquals((short) 0xA2A1, sb.get());
+ assertEquals((short) 0xA4A3, sb.get());
+
+ bb.order(ByteOrder.BIG_ENDIAN);
+ sb = bb.asShortBuffer();
+
+ checkBuffer(sb);
+ assertEquals(2, sb.capacity());
+ assertEquals((short) 0xA1A2, sb.get());
+ assertEquals((short) 0xA3A4, sb.get());
+
+ bb.order(ByteOrder.LITTLE_ENDIAN);
+ IntBuffer ib = bb.asIntBuffer();
+
+ checkBuffer(ib);
+ assertEquals(1, ib.capacity());
+ assertEquals(0xA4A3A2A1, ib.get());
+
+ bb.order(ByteOrder.BIG_ENDIAN);
+ ib = bb.asIntBuffer();
+
+ checkBuffer(ib);
+ assertEquals(1, ib.capacity());
+ assertEquals(0xA1A2A3A4, ib.get());
+
+ bb.order(ByteOrder.LITTLE_ENDIAN);
+ FloatBuffer fb = bb.asFloatBuffer();
+
+ checkBuffer(fb);
+ assertEquals(1, fb.capacity());
+ assertEquals(0xA4A3A2A1, Float.floatToRawIntBits(fb.get()));
+
+ bb.order(ByteOrder.BIG_ENDIAN);
+ fb = bb.asFloatBuffer();
+
+ checkBuffer(fb);
+ assertEquals(1, fb.capacity());
+ assertEquals(0xA1A2A3A4, Float.floatToRawIntBits(fb.get()));
+ }
+
+ private void shortBufferTest(ShortBuffer sb) {
+ checkBuffer(sb);
+
+ try {
+ sb.put(-1, (short) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ sb.put(sb.limit(), (short) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: offset < 0
+ try {
+ short[] data = new short[8];
+ sb.position(0);
+ sb.put(data, -1, 2);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: length > array.length - offset
+ try {
+ short[] data = new short[8];
+ sb.position(0);
+ sb.put(data, 1, 8);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // BufferOverflowException: length > remaining()
+ try {
+ short[] data = new short[8];
+ sb.position(sb.limit() - 2);
+ sb.put(data, 0, 3);
+ fail("expected exception not thrown");
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+
+ short[] data = {0, 10, 20, 30, 40, 50, 60, 70};
+ sb.position(0);
+ sb.put(data);
+
+ try {
+ sb.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ sb.position(0);
+ assertEquals((short) 0, sb.get());
+ assertEquals((short) 10, sb.get());
+ assertEquals((short) 20, sb.get());
+ assertEquals((short) 30, sb.get());
+ assertEquals((short) 40, sb.get());
+ assertEquals((short) 50, sb.get());
+ assertEquals((short) 60, sb.get());
+ assertEquals((short) 70, sb.get());
+ try {
+ sb.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+ sb.position(1);
+ sb.put((short) 11);
+ assertEquals((short) 11, sb.get(1));
+
+ short[] ss1 = {33, 44, 55, 66};
+ sb.position(3);
+ sb.put(ss1);
+ sb.position(0);
+ assertEquals((short) 0, sb.get());
+ assertEquals((short) 11, sb.get());
+ assertEquals((short) 20, sb.get());
+ assertEquals((short) 33, sb.get());
+ assertEquals((short) 44, sb.get());
+ assertEquals((short) 55, sb.get());
+ assertEquals((short) 66, sb.get());
+ assertEquals((short) 70, sb.get());
+
+ short[] ss2 = {10, 22, 30};
+ sb.position(2);
+ sb.put(ss2, 1, 1);
+ sb.position(0);
+ assertEquals((short) 0, sb.get());
+ assertEquals((short) 11, sb.get());
+ assertEquals((short) 22, sb.get());
+ assertEquals((short) 33, sb.get());
+ assertEquals((short) 44, sb.get());
+ assertEquals((short) 55, sb.get());
+ assertEquals((short) 66, sb.get());
+ assertEquals((short) 70, sb.get());
+ }
+
+ private void intBufferTest(IntBuffer ib) {
+ checkBuffer(ib);
+
+ try {
+ ib.put(-1, (int) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ ib.put(ib.limit(), (int) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: offset < 0
+ try {
+ int[] data = new int[8];
+ ib.position(0);
+ ib.put(data, -1, 2);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: length > array.length - offset
+ try {
+ int[] data = new int[8];
+ ib.position(0);
+ ib.put(data, 1, 8);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // BufferOverflowException: length > remaining()
+ try {
+ int[] data = new int[8];
+ ib.position(ib.limit() - 2);
+ ib.put(data, 0, 3);
+ fail("expected exception not thrown");
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+
+ int[] data = {0, 10, 20, 30, 40, 50, 60, 70};
+ ib.position(0);
+ ib.put(data);
+
+ try {
+ ib.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ ib.position(0);
+ assertEquals((int) 0, ib.get());
+ assertEquals((int) 10, ib.get());
+ assertEquals((int) 20, ib.get());
+ assertEquals((int) 30, ib.get());
+ assertEquals((int) 40, ib.get());
+ assertEquals((int) 50, ib.get());
+ assertEquals((int) 60, ib.get());
+ assertEquals((int) 70, ib.get());
+ try {
+ ib.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+ ib.position(1);
+ ib.put((int) 11);
+ assertEquals((int) 11, ib.get(1));
+
+ int[] ss1 = {33, 44, 55, 66};
+ ib.position(3);
+ ib.put(ss1);
+ ib.position(0);
+ assertEquals((int) 0, ib.get());
+ assertEquals((int) 11, ib.get());
+ assertEquals((int) 20, ib.get());
+ assertEquals((int) 33, ib.get());
+ assertEquals((int) 44, ib.get());
+ assertEquals((int) 55, ib.get());
+ assertEquals((int) 66, ib.get());
+ assertEquals((int) 70, ib.get());
+
+ int[] ss2 = {10, 22, 30};
+ ib.position(2);
+ ib.put(ss2, 1, 1);
+ ib.position(0);
+ assertEquals((int) 0, ib.get());
+ assertEquals((int) 11, ib.get());
+ assertEquals((int) 22, ib.get());
+ assertEquals((int) 33, ib.get());
+ assertEquals((int) 44, ib.get());
+ assertEquals((int) 55, ib.get());
+ assertEquals((int) 66, ib.get());
+ assertEquals((int) 70, ib.get());
+ }
+
+ void floatBufferTest(FloatBuffer fb) {
+ checkBuffer(fb);
+
+ try {
+ fb.put(-1, (float) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ try {
+ fb.put(fb.limit(), (float) 0);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: offset < 0
+ try {
+ float[] data = new float[8];
+ fb.position(0);
+ fb.put(data, -1, 2);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // IndexOutOfBoundsException: length > array.length - offset
+ try {
+ float[] data = new float[8];
+ fb.position(0);
+ fb.put(data, 1, 8);
+ fail("expected exception not thrown");
+ } catch (IndexOutOfBoundsException e) {
+ // expected
+ }
+
+ // BufferOverflowException: length > remaining()
+ try {
+ float[] data = new float[8];
+ fb.position(fb.limit() - 2);
+ fb.put(data, 0, 3);
+ fail("expected exception not thrown");
+ } catch (BufferOverflowException e) {
+ // expected
+ }
+
+ float[] data = {0, 10, 20, 30, 40, 50, 60, 70};
+ fb.position(0);
+ fb.put(data);
+
+ try {
+ fb.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+
+ fb.position(0);
+ assertEquals((float) 0, fb.get());
+ assertEquals((float) 10, fb.get());
+ assertEquals((float) 20, fb.get());
+ assertEquals((float) 30, fb.get());
+ assertEquals((float) 40, fb.get());
+ assertEquals((float) 50, fb.get());
+ assertEquals((float) 60, fb.get());
+ assertEquals((float) 70, fb.get());
+ try {
+ fb.get();
+ fail("expected exception not thrown");
+ } catch (BufferUnderflowException e) {
+ // expected
+ }
+ fb.position(1);
+ fb.put((float) 11);
+ assertEquals((float) 11, fb.get(1));
+
+ float[] ss1 = {33, 44, 55, 66};
+ fb.position(3);
+ fb.put(ss1);
+ fb.position(0);
+ assertEquals((float) 0, fb.get());
+ assertEquals((float) 11, fb.get());
+ assertEquals((float) 20, fb.get());
+ assertEquals((float) 33, fb.get());
+ assertEquals((float) 44, fb.get());
+ assertEquals((float) 55, fb.get());
+ assertEquals((float) 66, fb.get());
+ assertEquals((float) 70, fb.get());
+
+ float[] ss2 = {10, 22, 30};
+ fb.position(2);
+ fb.put(ss2, 1, 1);
+ fb.position(0);
+ assertEquals((float) 0, fb.get());
+ assertEquals((float) 11, fb.get());
+ assertEquals((float) 22, fb.get());
+ assertEquals((float) 33, fb.get());
+ assertEquals((float) 44, fb.get());
+ assertEquals((float) 55, fb.get());
+ assertEquals((float) 66, fb.get());
+ assertEquals((float) 70, fb.get());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/OldDirectIntBufferTest.java b/luni/src/test/java/libcore/java/nio/OldDirectIntBufferTest.java
new file mode 100644
index 0000000..4274f42
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/OldDirectIntBufferTest.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import junit.framework.TestCase;
+
+public final class OldDirectIntBufferTest extends TestCase {
+
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ IntBuffer intBuffer = byteBuffer.asIntBuffer();
+
+ int[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ intBuffer.put(source, 2, 2);
+ intBuffer.put(source, 4, 2);
+ assertEquals(4, intBuffer.get(0));
+ assertEquals(5, intBuffer.get(1));
+ assertEquals(6, intBuffer.get(2));
+ assertEquals(7, intBuffer.get(3));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/OldDirectShortBufferTest.java b/luni/src/test/java/libcore/java/nio/OldDirectShortBufferTest.java
new file mode 100644
index 0000000..7a93857
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/OldDirectShortBufferTest.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.ShortBuffer;
+import junit.framework.TestCase;
+
+public final class OldDirectShortBufferTest extends TestCase {
+
+ /**
+ * Regression for http://code.google.com/p/android/issues/detail?id=3279
+ */
+ public void testPutWhenOffsetIsNonZero() {
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
+ byteBuffer.order(ByteOrder.nativeOrder());
+ ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
+
+ short[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
+
+ shortBuffer.put(source, 2, 2);
+ shortBuffer.put(source, 4, 2);
+ assertEquals(4, shortBuffer.get(0));
+ assertEquals(5, shortBuffer.get(1));
+ assertEquals(6, shortBuffer.get(2));
+ assertEquals(7, shortBuffer.get(3));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/channels/ChannelsTest.java b/luni/src/test/java/libcore/java/nio/channels/ChannelsTest.java
new file mode 100644
index 0000000..4bbf3a9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/channels/ChannelsTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio.channels;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.Pipe;
+import java.nio.channels.WritableByteChannel;
+import junit.framework.TestCase;
+
+public final class ChannelsTest extends TestCase {
+
+ public void testStreamNonBlocking() throws IOException {
+ Pipe.SourceChannel sourceChannel = createNonBlockingChannel("abc".getBytes("UTF-8"));
+ try {
+ Channels.newInputStream(sourceChannel).read();
+ fail();
+ } catch (IllegalBlockingModeException expected) {
+ }
+ }
+
+ /**
+ * This fails on the RI which violates its own promise to throw when
+ * read in non-blocking mode.
+ */
+ public void testReaderNonBlocking() throws IOException {
+ Pipe.SourceChannel sourceChannel = createNonBlockingChannel("abc".getBytes("UTF-8"));
+ try {
+ Channels.newReader(sourceChannel, "UTF-8").read();
+ fail();
+ } catch (IllegalBlockingModeException expected) {
+ }
+ }
+
+ private Pipe.SourceChannel createNonBlockingChannel(byte[] content) throws IOException {
+ Pipe pipe = Pipe.open();
+ WritableByteChannel sinkChannel = pipe.sink();
+ sinkChannel.write(ByteBuffer.wrap(content));
+ Pipe.SourceChannel sourceChannel = pipe.source();
+ sourceChannel.configureBlocking(false);
+ return sourceChannel;
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/nio/channels/OldFileChannelTest.java b/luni/src/test/java/libcore/java/nio/channels/OldFileChannelTest.java
index 3072cf0..363dbd6 100644
--- a/luni/src/test/java/libcore/java/nio/channels/OldFileChannelTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/OldFileChannelTest.java
@@ -34,6 +34,7 @@ import java.nio.channels.DatagramChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.OverlappingFileLockException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
@@ -262,25 +263,28 @@ public final class OldFileChannelTest extends TestCase {
} catch (IllegalArgumentException e) {
// expected
}
+ }
- // BEGIN android-added
- // Android uses 32-bit off_t, so anything larger than a signed 32-bit int won't work...
- // ...except for the special case of length == Long.MAX_VALUE, which is used to mean "the
- // whole file". The special case is tested elsewhere.
- long tooBig = ((long) Integer.MAX_VALUE) + 1;
- try {
- readWriteFileChannel.tryLock(tooBig, 1, false);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- readWriteFileChannel.tryLock(0, tooBig, false);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- // END android-added
+ public void testTryLockVeryLarge() throws IOException {
+ long tooBig = Integer.MAX_VALUE + 1L;
+ FileLock lock = readWriteFileChannel.tryLock(tooBig, 1, false);
+ assertLockFails(tooBig, 1);
+ lock.release();
+
+ lock = readWriteFileChannel.tryLock(0, tooBig, false);
+ assertLockFails(0, 1);
+ lock.release();
+ }
+
+ public void testTryLockOverlapping() throws IOException {
+ FileLock lockOne = readWriteFileChannel.tryLock(0, 10, false);
+ FileLock lockTwo = readWriteFileChannel.tryLock(10, 20, false);
+ assertLockFails(0, 10);
+ lockOne.release();
+ assertLockFails(5, 10);
+ lockOne = readWriteFileChannel.tryLock(0, 10, false);
+ lockTwo.release();
+ lockOne.release();
}
/**
@@ -732,40 +736,40 @@ public final class OldFileChannelTest extends TestCase {
try {
readOnlyFileChannel.read(null, -1, 0);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
readOnlyFileChannel.read(null, 0, -1);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
readWriteFileChannel.read(null, -1, 0);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
readWriteFileChannel.read(null, 0, -1);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
writeOnlyFileChannel.read(null, -1, 0);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
try {
writeOnlyFileChannel.read(null, 0, -1);
fail("should throw IndexOutOfBoundException");
- } catch (IndexOutOfBoundsException e) {
- // expected
+ } catch (NullPointerException expected) {
+ } catch (IndexOutOfBoundsException expected) {
}
readOnlyFileChannel.close();
@@ -1491,6 +1495,13 @@ public final class OldFileChannelTest extends TestCase {
}
}
+ private void assertLockFails(long position, long size) throws IOException {
+ try {
+ readWriteFileChannel.tryLock(position, size, false);
+ fail();
+ } catch (OverlappingFileLockException expected) {
+ }
+ }
private class MockFileChannel extends FileChannel {
diff --git a/luni/src/test/java/libcore/java/nio/charset/CharsetDecoderTest.java b/luni/src/test/java/libcore/java/nio/charset/CharsetDecoderTest.java
deleted file mode 100644
index fa8eab5..0000000
--- a/luni/src/test/java/libcore/java/nio/charset/CharsetDecoderTest.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.java.nio.charset;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-
-public class CharsetDecoderTest extends junit.framework.TestCase {
- private static final String CHARSET = "UTF-16";
-
- private static final String SAMPLE_STRING = "Android";
-
- // None of the harmony or jtreg tests actually check that replaceWith does the right thing!
- public void test_replaceWith() throws Exception {
- CharsetDecoder d = Charset.forName("UTF-16").newDecoder();
- d.replaceWith("x");
- d.onMalformedInput(CodingErrorAction.REPLACE);
- d.onUnmappableCharacter(CodingErrorAction.REPLACE);
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
- assertEquals("\u6d61x", d.decode(in).toString());
- }
-
- // http://code.google.com/p/android/issues/detail?id=4237
- public void test_ByteArray_decode_no_offset() throws Exception {
- CharsetDecoder decoder = getCharsetDecoderUnderTest();
- byte[] arr = getEncodedByteArrayFixture();
- ByteBuffer inBuffer = ByteBuffer.wrap(arr, 0, arr.length).slice();
- CharBuffer outBuffer = CharBuffer.allocate(arr.length);
- decoder.reset();
- CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
- assertFalse(coderResult.toString(), coderResult.isError());
- decoder.flush(outBuffer);
- outBuffer.flip();
- assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
- }
-
- // http://code.google.com/p/android/issues/detail?id=4237
- public void test_ByteArray_decode_with_offset() throws Exception {
- CharsetDecoder decoder = getCharsetDecoderUnderTest();
- byte[] arr = getEncodedByteArrayFixture();
- arr = prependByteToByteArray(arr, new Integer(1).byteValue());
- int offset = 1;
- ByteBuffer inBuffer = ByteBuffer.wrap(arr, offset, arr.length - offset).slice();
- CharBuffer outBuffer = CharBuffer.allocate(arr.length - offset);
- decoder.reset();
- CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
- assertFalse(coderResult.toString(), coderResult.isError());
- decoder.flush(outBuffer);
- outBuffer.flip();
- assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
- }
-
- // http://code.google.com/p/android/issues/detail?id=4237
- public void test_ByteArray_decode_with_offset_using_facade_method() throws Exception {
- CharsetDecoder decoder = getCharsetDecoderUnderTest();
- byte[] arr = getEncodedByteArrayFixture();
- arr = prependByteToByteArray(arr, new Integer(1).byteValue());
- int offset = 1;
- CharBuffer outBuffer = decoder.decode(ByteBuffer.wrap(arr, offset, arr.length - offset));
- assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
- }
-
- private static byte[] prependByteToByteArray(byte[] arr, byte b) {
- byte[] result = new byte[arr.length + 1];
- result[0] = b;
- System.arraycopy(arr, 0, result, 1, arr.length);
- return result;
- }
-
- private static CharsetDecoder getCharsetDecoderUnderTest() {
- return Charset.forName(CHARSET).newDecoder();
- }
-
- private byte[] getEncodedByteArrayFixture() throws CharacterCodingException {
- CharsetEncoder encoder = Charset.forName(CHARSET).newEncoder();
- return encoder.encode(CharBuffer.wrap(SAMPLE_STRING)).array();
- }
-}
diff --git a/luni/src/test/java/libcore/java/nio/charset/CharsetEncoderTest.java b/luni/src/test/java/libcore/java/nio/charset/CharsetEncoderTest.java
index 9632ffe..87e7306 100644
--- a/luni/src/test/java/libcore/java/nio/charset/CharsetEncoderTest.java
+++ b/luni/src/test/java/libcore/java/nio/charset/CharsetEncoderTest.java
@@ -41,12 +41,22 @@ public class CharsetEncoderTest extends junit.framework.TestCase {
}
// For all the guaranteed built-in charsets, check that we have the right default replacements.
- public void test_defaultReplacementBytes() throws Exception {
+ public void test_defaultReplacementBytesIso_8859_1() throws Exception {
assertReplacementBytesForEncoder("ISO-8859-1", new byte[] { (byte) '?' });
+ }
+ public void test_defaultReplacementBytesUs_Ascii() throws Exception {
assertReplacementBytesForEncoder("US-ASCII", new byte[] { (byte) '?' });
+ }
+ public void test_defaultReplacementBytesUtf_16() throws Exception {
assertReplacementBytesForEncoder("UTF-16", new byte[] { (byte) 0xff, (byte) 0xfd });
+ }
+ public void test_defaultReplacementBytesUtf_16be() throws Exception {
assertReplacementBytesForEncoder("UTF-16BE", new byte[] { (byte) 0xff, (byte) 0xfd });
+ }
+ public void test_defaultReplacementBytesUtf_16le() throws Exception {
assertReplacementBytesForEncoder("UTF-16LE", new byte[] { (byte) 0xfd, (byte) 0xff });
+ }
+ public void test_defaultReplacementBytesUtf_8() throws Exception {
assertReplacementBytesForEncoder("UTF-8", new byte[] { (byte) '?' });
}
}
diff --git a/luni/src/test/java/libcore/java/nio/charset/Charset_TestGenerator.java b/luni/src/test/java/libcore/java/nio/charset/Charset_TestGenerator.java
new file mode 100644
index 0000000..b189382
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/Charset_TestGenerator.java
@@ -0,0 +1,261 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * Super class for concrete charset test suites.
+ */
+public class Charset_TestGenerator {
+
+ Charset charset;
+ CharsetDecoder decoder;
+ CharsetEncoder encoder;
+
+
+ static final int[] codes = {
+ 9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
+ 89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 170, 181, 186, 192, 195, 198,
+ 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246,
+ 249, 252, 255, 258, 261, 264, 267, 270, 273, 276, 279, 282, 285, 288, 291, 294,
+ 297, 300, 303, 306, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342,
+ 345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, 384, 387, 390,
+ 393, 396, 399, 402, 405, 408, 411, 414, 417, 420, 423, 426, 429, 432, 435, 438,
+ 441, 444, 447, 450, 453, 456, 459, 462, 465, 468, 471, 474, 477, 480, 483, 486,
+ 489, 492, 495, 498, 501, 504, 507, 510, 513, 516, 519, 522, 525, 528, 531, 534,
+ 537, 540, 543, 546, 549, 552, 555, 558, 561, 564, 592, 595, 598, 601, 604, 607,
+ 610, 613, 616, 619, 622, 625, 628, 631, 634, 637, 640, 643, 646, 649, 652, 655,
+ 658, 661, 664, 667, 670, 673, 676, 679, 682, 685, 688, 691, 694, 697, 700, 703,
+ 710, 713, 716, 719, 736, 739, 750, 890, 902, 905, 908, 911, 914, 917, 920, 923,
+ 926, 929, 932, 935, 938, 941, 944, 947, 950, 953, 956, 959, 962, 965, 968, 971,
+ 974, 977, 980, 983, 986, 989, 992, 995, 998, 1001, 1004, 1007, 1010, 1013, 1016, 1019,
+ 1024, 1027, 1060, 1093, 1126, 1162, 1195, 1228, 1261, 1294, 1329, 1362, 1395, 1488, 1521, 1569,
+ 1602, 1635, 1668, 1701, 1734, 1774, 1808, 1869, 1920, 1953, 2308, 2341, 2384, 2437, 2470, 2524,
+ 2565, 2598, 2649, 2693, 2726, 2768, 2821, 2854, 2908, 2947, 2980, 3047, 3080, 3114, 3168, 3205,
+ 3238, 3294, 3333, 3366, 3424, 3461, 3494, 3585, 3618, 3651, 3713, 3746, 3779, 3840, 3873, 3906,
+ 3939, 3976, 4096, 4129, 4162, 4256, 4289, 4322, 4355, 4388, 4421, 4454, 4487, 4520, 4553, 4586,
+ 4619, 4652, 4685, 4718, 4752, 4786, 4819, 4852, 4885, 4918, 4951, 5024, 5057, 5090, 5123, 5156,
+ 5189, 5222, 5255, 5288, 5321, 5354, 5387, 5420, 5453, 5486, 5519, 5552, 5585, 5618, 5651, 5684,
+ 5717, 5750, 5783, 5816, 5849, 5888, 5921, 5954, 5987, 6020, 6053, 6103, 6158, 6191, 6224, 6257,
+ 6290, 6400, 6470, 6503, 7424, 7457, 7490, 7523, 7680, 7713, 7746, 7779, 7812, 7845, 7878, 7911,
+ 7944, 7977, 8010, 8043, 8076, 8109, 8144, 8178, 8232, 8287, 8450, 8484, 8517, 12288, 12337, 12370,
+ 12403, 12436, 12469, 12502, 12535, 12568, 12601, 12634, 12667, 12704, 12784, 13312, 13345, 13378, 13411, 13444,
+ 13477, 13510, 13543, 13576, 13609, 13642, 13675, 13708, 13741, 13774, 13807, 13840, 13873, 13906, 13939, 13972,
+ 14005, 14038, 14071, 14104, 14137, 14170, 14203, 14236, 14269, 14302, 14335, 14368, 14401, 14434, 14467, 14500,
+ 14533, 14566, 14599, 14632, 14665, 14698, 14731, 14764, 14797, 14830, 14863, 14896, 14929, 14962, 14995, 15028,
+ 15061, 15094, 15127, 15160, 15193, 15226, 15259, 15292, 15325, 15358, 15391, 15424, 15457, 15490, 15523, 15556,
+ 15589, 15622, 15655, 15688, 15721, 15754, 15787, 15820, 15853, 15886, 15919, 15952, 15985, 16018, 16051, 16084,
+ 16117, 16150, 16183, 16216, 16249, 16282, 16315, 16348, 16381, 16414, 16447, 16480, 16513, 16546, 16579, 16612,
+ 16645, 16678, 16711, 16744, 16777, 16810, 16843, 16876, 16909, 16942, 16975, 17008, 17041, 17074, 17107, 17140,
+ 17173, 17206, 17239, 17272, 17305, 17338, 17371, 17404, 17437, 17470, 17503, 17536, 17569, 17602, 17635, 17668,
+ 17701, 17734, 17767, 17800, 17833, 17866, 17899, 17932, 17965, 17998, 18031, 18064, 18097, 18130, 18163, 18196,
+ 18229, 18262, 18295, 18328, 18361, 18394, 18427, 18460, 18493, 18526, 18559, 18592, 18625, 18658, 18691, 18724,
+ 18757, 18790, 18823, 18856, 18889, 18922, 18955, 18988, 19021, 19054, 19087, 19120, 19153, 19186, 19219, 19252,
+ 19285, 19318, 19351, 19384, 19417, 19450, 19483, 19516, 19549, 19582, 19615, 19648, 19681, 19714, 19747, 19780,
+ 19813, 19846, 19879, 19968, 20001, 20034, 20067, 20100, 20133, 20166, 20199, 20232, 20265, 20298, 20331, 20364,
+ 20397, 20430, 20463, 20496, 20529, 20562, 20595, 20628, 20661, 20694, 20727, 20760, 20793, 20826, 20859, 20892,
+ 20925, 20958, 20991, 21024, 21057, 21090, 21123, 21156, 21189, 21222, 21255, 21288, 21321, 21354, 21387, 21420,
+ 21453, 21486, 21519, 21552, 21585, 21618, 21651, 21684, 21717, 21750, 21783, 21816, 21849, 21882, 21915, 21948,
+ 21981, 22014, 22047, 22080, 22113, 22146, 22179, 22212, 22245, 22278, 22311, 22344, 22377, 22410, 22443, 22476,
+ 22509, 22542, 22575, 22608, 22641, 22674, 22707, 22740, 22773, 22806, 22839, 22872, 22905, 22938, 22971, 23004,
+ 23037, 23070, 23103, 23136, 23169, 23202, 23235, 23268, 23301, 23334, 23367, 23400, 23433, 23466, 23499, 23532,
+ 23565, 23598, 23631, 23664, 23697, 23730, 23763, 23796, 23829, 23862, 23895, 23928, 23961, 23994, 24027, 24060,
+ 24093, 24126, 24159, 24192, 24225, 24258, 24291, 24324, 24357, 24390, 24423, 24456, 24489, 24522, 24555, 24588,
+ 24621, 24654, 24687, 24720, 24753, 24786, 24819, 24852, 24885, 24918, 24951, 24984, 25017, 25050, 25083, 25116,
+ 25149, 25182, 25215, 25248, 25281, 25314, 25347, 25380, 25413, 25446, 25479, 25512, 25545, 25578, 25611, 25644,
+ 25677, 25710, 25743, 25776, 25809, 25842, 25875, 25908, 25941, 25974, 26007, 26040, 26073, 26106, 26139, 26172,
+ 26205, 26238, 26271, 26304, 26337, 26370, 26403, 26436, 26469, 26502, 26535, 26568, 26601, 26634, 26667, 26700,
+ 26733, 26766, 26799, 26832, 26865, 26898, 26931, 26964, 26997, 27030, 27063, 27096, 27129, 27162, 27195, 27228,
+ 27261, 27294, 27327, 27360, 27393, 27426, 27459, 27492, 27525, 27558, 27591, 27624, 27657, 27690, 27723, 27756,
+ 27789, 27822, 27855, 27888, 27921, 27954, 27987, 28020, 28053, 28086, 28119, 28152, 28185, 28218, 28251, 28284,
+ 28317, 28350, 28383, 28416, 28449, 28482, 28515, 28548, 28581, 28614, 28647, 28680, 28713, 28746, 28779, 28812,
+ 28845, 28878, 28911, 28944, 28977, 29010, 29043, 29076, 29109, 29142, 29175, 29208, 29241, 29274, 29307, 29340,
+ 29373, 29406, 29439, 29472, 29505, 29538, 29571, 29604, 29637, 29670, 29703, 29736, 29769, 29802, 29835, 29868,
+ 29901, 29934, 29967, 30000, 30033, 30066, 30099, 30132, 30165, 30198, 30231, 30264, 30297, 30330, 30363, 30396,
+ 30429, 30462, 30495, 30528, 30561, 30594, 30627, 30660, 30693, 30726, 30759, 30792, 30825, 30858, 30891, 30924,
+ 30957, 30990, 31023, 31056, 31089, 31122, 31155, 31188, 31221, 31254, 31287, 31320, 31353, 31386, 31419, 31452,
+ 31485, 31518, 31551, 31584, 31617, 31650, 31683, 31716, 31749, 31782, 31815, 31848, 31881, 31914, 31947, 31980,
+ 32013, 32046, 32079, 32112, 32145, 32178, 32211, 32244, 32277, 32310, 32343, 32376, 32409, 32442, 32475, 32508,
+ 32541, 32574, 32607, 32640, 32673, 32706, 32739
+ };
+ static final char[] chars = OldCharset_AbstractTest.theseChars(codes);
+
+ static abstract class CodesGenerator {
+ int row = 0, col = 0;
+ abstract void consume (int code);
+
+ boolean isAccepted (int code)
+ {
+ return Character.isLetterOrDigit(code);
+ }
+ }
+
+ static class CodesGenerator1 extends CodesGenerator {
+ @Override
+ void consume (int code) {
+ System.out.print(code);
+ System.out.print(", ");
+ col++;
+ if (col == 16) {
+ System.out.println();
+ row++;
+ col = 0;
+ }
+ }
+
+ @Override
+ boolean isAccepted (int code)
+ {
+ return Character.isLetterOrDigit(code) || Character.isWhitespace(code);
+ }
+ }
+
+ static class CodesGenerator2 extends CodesGenerator {
+ @Override
+ void consume (int code) {
+// System.out.print(code);
+// System.out.print(", ");
+ System.out.print((char) code);
+ col++;
+ if (col == 80) {
+ System.out.println();
+ row++;
+ col = 0;
+ }
+ }
+ }
+
+ static class CodesGenerator3 extends CodesGenerator {
+ char[] buf = new char[8];
+
+ @Override
+ void consume (int code) {
+ buf[col] = (char) code;
+ System.out.print(code);
+ System.out.print(", ");
+ col++;
+ if (col == 8) {
+ System.out.print(" // ");
+ System.out.println(buf);
+ row++;
+ col = 0;
+ }
+ }
+
+ @Override
+ boolean isAccepted (int code)
+ {
+ return Character.isLetterOrDigit(code);
+// || Character.isWhitespace(code);
+ }
+ }
+
+ static void genCodes () {
+ CodesGenerator gen = new CodesGenerator1();
+ int code = 0;
+ while (code < (1 << 10)) {
+ while (!gen.isAccepted(code)) code ++;
+ gen.consume(code);
+ code += 3;
+ }
+ while (code < (1 << 15)) {
+ while (!gen.isAccepted(code)) code ++;
+ gen.consume(code);
+ code += 33;
+ }
+ }
+
+
+ static abstract class Dumper {
+ int row = 0, col = 0;
+ abstract void consume (int code);
+ }
+
+ static class Dumper1 extends Dumper {
+ int colMax;
+
+ Dumper1 () {
+ colMax = 16;
+ }
+
+ Dumper1 (int colums) {
+ colMax = colums;
+ }
+
+ @Override
+ void consume (int code) {
+ System.out.print(code);
+ System.out.print(", ");
+ col++;
+ if (col == colMax) {
+ System.out.println();
+ row++;
+ col = 0;
+ }
+ }
+ }
+
+ static void genEncoded (Charset charset, CharBuffer cb) {
+ System.out.println(charset.name());
+ Dumper out = new Dumper1();
+ CharsetEncoder encoder = charset.newEncoder();
+ encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ try {
+ ByteBuffer bb = encoder.encode(cb);
+// bb.rewind();
+ while (bb.hasRemaining()) {
+ out.consume(bb.get());
+ }
+ } catch (CharacterCodingException e) {
+ System.out.println(e);
+// e.printStackTrace();
+ }
+ }
+
+ static void genDecoded (Charset charset, ByteBuffer bb) {
+ CharsetDecoder decoder = charset.newDecoder();
+// System.out.println(code);
+// bytes[0] = (byte) code;
+// System.out.println(bytes[0]);
+// ByteBuffer inputBB = ByteBuffer.wrap(bytes);
+// CharBuffer outputCB;
+// try {
+// outputCB = decoder.decode(inputBB);
+// outputCB.rewind();
+// System.out.println(outputCB);
+// } catch (CharacterCodingException e) {
+// System.out.println(e);
+//// e.printStackTrace();
+// }
+ }
+
+
+ public static void main(String[] args) {
+// charset = Charset.defaultCharset();
+// decoder = charset.newDecoder();
+// System.out.println(charset.name());
+ genEncoded(Charset.forName("MacRoman"), CharBuffer.wrap(chars));
+// genEncoded(Charset.forName(charsetNames[37]), CharBuffer.wrap(chars));
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharsetDecoderTest.java b/luni/src/test/java/libcore/java/nio/charset/OldCharsetDecoderTest.java
new file mode 100644
index 0000000..8f37f63
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharsetDecoderTest.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CoderResult;
+import java.nio.charset.CodingErrorAction;
+
+public class OldCharsetDecoderTest extends junit.framework.TestCase {
+ private static final String CHARSET = "UTF-16";
+
+ private static final String SAMPLE_STRING = "Android";
+
+ // None of the harmony or jtreg tests actually check that replaceWith does the right thing!
+ public void test_replaceWith() throws Exception {
+ CharsetDecoder d = Charset.forName("UTF-16").newDecoder();
+ d.replaceWith("x");
+ d.onMalformedInput(CodingErrorAction.REPLACE);
+ d.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
+ assertEquals("\u6d61x", d.decode(in).toString());
+ }
+
+ // http://code.google.com/p/android/issues/detail?id=4237
+ public void test_ByteArray_decode_no_offset() throws Exception {
+ CharsetDecoder decoder = getCharsetDecoderUnderTest();
+ byte[] arr = getEncodedByteArrayFixture();
+ ByteBuffer inBuffer = ByteBuffer.wrap(arr, 0, arr.length).slice();
+ CharBuffer outBuffer = CharBuffer.allocate(arr.length);
+ decoder.reset();
+ CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
+ assertFalse(coderResult.toString(), coderResult.isError());
+ decoder.flush(outBuffer);
+ outBuffer.flip();
+ assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
+ }
+
+ // http://code.google.com/p/android/issues/detail?id=4237
+ public void test_ByteArray_decode_with_offset() throws Exception {
+ CharsetDecoder decoder = getCharsetDecoderUnderTest();
+ byte[] arr = getEncodedByteArrayFixture();
+ arr = prependByteToByteArray(arr, new Integer(1).byteValue());
+ int offset = 1;
+ ByteBuffer inBuffer = ByteBuffer.wrap(arr, offset, arr.length - offset).slice();
+ CharBuffer outBuffer = CharBuffer.allocate(arr.length - offset);
+ decoder.reset();
+ CoderResult coderResult = decoder.decode(inBuffer, outBuffer, true);
+ assertFalse(coderResult.toString(), coderResult.isError());
+ decoder.flush(outBuffer);
+ outBuffer.flip();
+ assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
+ }
+
+ // http://code.google.com/p/android/issues/detail?id=4237
+ public void test_ByteArray_decode_with_offset_using_facade_method() throws Exception {
+ CharsetDecoder decoder = getCharsetDecoderUnderTest();
+ byte[] arr = getEncodedByteArrayFixture();
+ arr = prependByteToByteArray(arr, new Integer(1).byteValue());
+ int offset = 1;
+ CharBuffer outBuffer = decoder.decode(ByteBuffer.wrap(arr, offset, arr.length - offset));
+ assertEquals(SAMPLE_STRING, outBuffer.toString().trim());
+ }
+
+ private static byte[] prependByteToByteArray(byte[] arr, byte b) {
+ byte[] result = new byte[arr.length + 1];
+ result[0] = b;
+ System.arraycopy(arr, 0, result, 1, arr.length);
+ return result;
+ }
+
+ private static CharsetDecoder getCharsetDecoderUnderTest() {
+ return Charset.forName(CHARSET).newDecoder();
+ }
+
+ private byte[] getEncodedByteArrayFixture() throws CharacterCodingException {
+ CharsetEncoder encoder = Charset.forName(CHARSET).newEncoder();
+ return encoder.encode(CharBuffer.wrap(SAMPLE_STRING)).array();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharsetEncoderDecoderBufferTest.java b/luni/src/test/java/libcore/java/nio/charset/OldCharsetEncoderDecoderBufferTest.java
new file mode 100644
index 0000000..583cb47
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharsetEncoderDecoderBufferTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import junit.framework.TestCase;
+
+
+/* See bug 1844104.
+ * Checks for ICU encoder/decoder buffer corruption.
+ */
+public class OldCharsetEncoderDecoderBufferTest extends TestCase {
+
+ /* Checks for a buffer corruption that happens in ICU
+ * (CharsetDecoderICU) when a decode operation
+ * is done first with an out-buffer with hasArray()==true, and next with an out-buffer with
+ * hasArray()==false. In that situation ICU may overwrite the first out-buffer.
+ */
+ public void testDecoderOutputBuffer() {
+ CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
+
+ char[] cBuf = new char[10];
+ CharBuffer out = CharBuffer.wrap(cBuf);
+ assertTrue(out.hasArray());
+ decoder.decode(ByteBuffer.wrap(new byte[]{(byte)'a', (byte)'b', (byte)'c', (byte)'d'}),
+ out, false);
+
+ assertEquals("abcd", new String(cBuf, 0, 4));
+ assertEquals(0, cBuf[4]);
+ assertEquals(0, cBuf[5]);
+
+ byte[] bBuf = new byte[10];
+ out = ByteBuffer.wrap(bBuf).asCharBuffer();
+ assertFalse(out.hasArray());
+ decoder.decode(ByteBuffer.wrap(new byte[]{(byte)'x'}), out, true);
+
+ assertEquals('x', bBuf[1]);
+ assertEquals(0, bBuf[3]);
+
+ // check if the first buffer was corrupted by the second decode
+ assertEquals("abcd", new String(cBuf, 0, 4));
+ assertEquals(0, cBuf[4]);
+ assertEquals(0, cBuf[5]);
+ }
+
+ /* Checks for a buffer corruption that happens in ICU
+ * (CharsetDecoderICU) when a decode operation
+ * is done first with an in-buffer with hasArray()==true, and next with an in-buffer with
+ * hasArray()==false. In that situation ICU may overwrite the array of the first in-buffer.
+ */
+ public void testDecoderInputBuffer() {
+ CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
+ CharBuffer out = CharBuffer.wrap(new char[10]);
+
+ byte[] inArray = {(byte)'a', (byte)'b'};
+ ByteBuffer inWithArray = ByteBuffer.wrap(inArray);
+ assertTrue(inWithArray.hasArray());
+ decoder.decode(inWithArray, out, false);
+ assertEquals('a', inArray[0]);
+ assertEquals('b', inArray[1]);
+
+ ByteBuffer inWithoutArray = ByteBuffer.allocateDirect(1);
+ inWithoutArray.put(0, (byte)'x');
+ assertFalse(inWithoutArray.hasArray());
+ decoder.decode(inWithoutArray, out, true);
+
+ // check whether the first buffer was corrupted by the second decode
+ assertEquals('a', inArray[0]);
+ assertEquals('b', inArray[1]);
+ }
+
+ /* Checks for a buffer corruption that happens in ICU
+ * (CharsetEncoderICU) when an encode operation
+ * is done first with an out-buffer with hasArray()==true, and next with an out-buffer with
+ * hasArray()==false. In that situation ICU may overwrite the first out-buffer.
+ */
+ public void testEncoderOutputBuffer() {
+ CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
+
+ byte[] buffer = new byte[10];
+ ByteBuffer out = ByteBuffer.wrap(buffer);
+
+ assertTrue(out.hasArray());
+ encoder.encode(CharBuffer.wrap("ab"), out, false);
+
+ assertEquals('a', buffer[0]);
+ assertEquals('b', buffer[1]);
+ assertEquals(0, buffer[2]);
+
+ out = ByteBuffer.allocateDirect(10);
+ assertFalse(out.hasArray());
+ encoder.encode(CharBuffer.wrap("x"), out, true);
+
+ // check whether the second decode corrupted the first buffer
+ assertEquals('a', buffer[0]);
+ assertEquals('b', buffer[1]);
+ assertEquals(0, buffer[2]);
+ }
+
+ /* Checks for a buffer corruption that happens in ICU
+ * (CharsetEncoderICU) when an encode operation
+ * is done first with an in-buffer with hasArray()==true, and next with an in-buffer with
+ * hasArray()==false. In that situation ICU may overwrite the array of the first in-buffer.
+ */
+ public void testEncoderInputBuffer() {
+ CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
+ ByteBuffer out = ByteBuffer.wrap(new byte[10]);
+
+ char[] inArray = {'a', 'b'};
+ CharBuffer inWithArray = CharBuffer.wrap(inArray);
+ assertTrue(inWithArray.hasArray());
+ encoder.encode(inWithArray, out, false);
+
+ assertEquals('a', inArray[0]);
+ assertEquals('b', inArray[1]);
+
+ CharBuffer inWithoutArray = CharBuffer.wrap("x");
+ assertFalse(inWithoutArray.hasArray());
+ encoder.encode(inWithoutArray, out, true);
+
+ // check whether the second decode corrupted the first buffer
+ assertEquals('a', inArray[0]);
+ assertEquals('b', inArray[1]);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_AbstractTest.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_AbstractTest.java
new file mode 100644
index 0000000..d6a635e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_AbstractTest.java
@@ -0,0 +1,306 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+import java.nio.charset.CodingErrorAction;
+import junit.framework.TestCase;
+
+/**
+ * Super class for concrete charset test suites.
+ */
+public abstract class OldCharset_AbstractTest extends TestCase {
+
+ static String charsetName;
+ static private Charset charset;
+ static CharsetDecoder decoder;
+ static CharsetEncoder encoder;
+
+ static final int[] codes = Charset_TestGenerator.codes;
+
+ static final char[] chars = new char[codes.length]; // Is filled with
+ // contents of codes.
+
+ static char[] testChars;
+ static byte[] testBytes;
+
+ static char[] theseChars (int[] codes) {
+ char[] chars = new char[codes.length];
+ for (int i = 0; i < codes.length; i++) chars[i] = (char) codes[i];
+ return chars;
+ }
+
+ static byte[] theseBytes (int[] codes) {
+ byte[] bytes = new byte[codes.length];
+ for (int i = 0; i < codes.length; i++) bytes[i] = (byte) codes[i];
+ return bytes;
+ }
+
+
+ @Override
+ protected void setUp() throws Exception {
+ charset = charset.forName(charsetName);
+ decoder = charset.newDecoder();
+ encoder = charset.newEncoder();
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void test_nameMatch () {
+ assertEquals("Name of charset must match!", charsetName, charset.name());
+ }
+
+ public void test_dumpEncodableChars () {
+ if (testChars == null) return;
+ if (testChars.length > 0) return;
+ System.out.format("\ntest_dumpEncodableChars() for name %s => %s (class = %s)\n",
+ charsetName, charset.name(), getClass().getName());
+ Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1(16);
+ int code = 0;
+ while (code < 256) {
+ while (!encoder.canEncode((char) code)) code ++;
+ if (code < 65536) {
+ out.consume(code);
+ code += 1;
+ }
+ }
+ while (code < 65536) {
+ while (!encoder.canEncode((char) code)) code ++;
+ if (code < 65536) {
+ out.consume(code);
+ code += 20;
+ }
+ }
+ System.out.println();
+ System.out.println("Encodable Chars dumped for Test Class " + getClass().getName());
+ fail("Encodable Chars dumped for Test Class " + getClass().getName());
+ }
+
+ public void test_dumpEncoded () throws CharacterCodingException {
+ if (testChars == null) return;
+ if (testChars.length == 0) return;
+ if (testBytes.length > 0) return;
+ System.out.format("\ntest_dumpEncoded() for name %s => %s (class = %s)\n",
+ charsetName, charset.name(), getClass().getName());
+ Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1();
+ CharBuffer inputCB = CharBuffer.wrap(testChars);
+ ByteBuffer outputBB;
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ outputBB = encoder.encode(inputCB);
+ outputBB.rewind();
+ while (outputBB.hasRemaining()) {
+ out.consume(outputBB.get() & 0xff);
+ }
+ System.out.println();
+ System.out.println("Encoded Bytes dumped for Test Class " + getClass().getName());
+ fail("Encoded Bytes dumped for Test Class " + getClass().getName());
+ }
+
+
+ static void decode (byte[] input, char[] expectedOutput) throws CharacterCodingException {
+ ByteBuffer inputBB = ByteBuffer.wrap(input);
+ CharBuffer outputCB;
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ outputCB = decoder.decode(inputBB);
+ outputCB.rewind();
+
+// assertTrue("Decoded charactes must match!",
+// Arrays.equals(expectedOutput, outputCB.array()));
+ assertEqualChars("Decoded charactes must match!",
+ expectedOutput, outputCB);
+
+// assertEqualChars2("Decoded charactes must match!",
+// expectedOutput,
+// outputCB.array(),
+// input);
+// assertTrue("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
+// Arrays.equals(expectedOutput, outputCB.array()));
+
+// assertEqualChars("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
+// expectedOutput,
+// outputCB.array());
+
+// assertEquals("Decoded charactes must match!",
+// String.valueOf(allChars),
+// outputCB.toString());
+ }
+
+ public void test_Decode () throws CharacterCodingException {
+ decode(testBytes, testChars);
+ }
+
+ public void test_Encode () throws CharacterCodingException {
+ CharBuffer inputCB = CharBuffer.wrap(testChars);
+ ByteBuffer outputBB;
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ outputBB = encoder.encode(inputCB);
+ outputBB.rewind();
+// assertTrue("Encoded bytes must match!",
+// Arrays.equals(testBytes, outputBB.array()));
+ assertEqualBytes("Encoded bytes must match!", testBytes, outputBB);
+ }
+
+
+ public void NNtest_CodecDynamicIndividuals () throws CharacterCodingException {
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+
+ for (int code = 32; code <= 65533; code ++) {
+ if (encoder.canEncode((char) code)) {
+// inputCB.rewind();
+ CharBuffer inputCB = CharBuffer.allocate(1);
+ inputCB.put((char) code);
+ inputCB.rewind();
+ ByteBuffer intermediateBB = encoder.encode(inputCB);
+ inputCB.rewind();
+ intermediateBB.rewind();
+ try {
+ CharBuffer outputCB = decoder.decode(intermediateBB);
+ outputCB.rewind();
+ assertEqualCBs("decode(encode(A)) must be identical with A = " + code,
+ inputCB, outputCB);
+ if (code == 165) {
+ outputCB.rewind();
+ System.out.println("WOW:" + outputCB.get());
+ }
+ } catch (CharacterCodingException e) {
+ fail("failed to decode(encode(" + code + "))");
+ }
+ }
+ }
+ }
+
+ public void test_CodecDynamic () throws CharacterCodingException {
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ CharBuffer inputCB = CharBuffer.allocate(65536);
+ for (int code = 32; code <= 65533; code ++) {
+ if (encoder.canEncode((char) code)) {
+ inputCB.put((char) code);
+ }
+ }
+ inputCB.rewind();
+ ByteBuffer intermediateBB = encoder.encode(inputCB);
+ inputCB.rewind();
+ intermediateBB.rewind();
+ CharBuffer outputCB = decoder.decode(intermediateBB);
+ outputCB.rewind();
+ assertEqualCBs("decode(encode(A)) must be identical with A!",
+ inputCB, outputCB);
+ }
+
+ static void assertEqualCBs (String msg, CharBuffer expectedCB, CharBuffer actualCB) {
+ boolean match = true;
+ boolean lenMatch = true;
+ char expected, actual;
+ int len = actualCB.length();
+ if (expectedCB.length() != len) {
+ lenMatch = false;
+ if (expectedCB.length() < len) len = expectedCB.length();
+ }
+ for (int i = 0; i < len; i++) {
+ expected = expectedCB.get();
+ actual = actualCB.get();
+ if (actual != expected) {
+ String detail = String.format(
+ "Mismatch at index %d: %d instead of expected %d.\n",
+ i, (int) actual, (int) expected);
+ match = false;
+ fail(msg + ": " + detail);
+ }
+// else {
+// System.out.format("Match index %d: %d = %d\n",
+// i, (int) actual[i], (int) expected[i]);
+// }
+ }
+ assertTrue(msg, match);
+ assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
+// assertTrue(msg, Arrays.equals(actual, expected));
+ }
+
+ static void assertEqualChars (String msg, char[] expected, CharBuffer actualCB) {
+ boolean match = true;
+ boolean lenMatch = true;
+ char actual;
+ int len = actualCB.length();
+ if (expected.length != len) {
+ lenMatch = false;
+ if (expected.length < len) len = expected.length;
+ }
+ for (int i = 0; i < len; i++) {
+ actual = actualCB.get();
+ if (actual != expected[i]) {
+ String detail = String.format(
+ "Mismatch at index %d: %d instead of expected %d.\n",
+ i, (int) actual, (int) expected[i]);
+ match = false;
+ fail(msg + ": " + detail);
+ }
+// else {
+// System.out.format("Match index %d: %d = %d\n",
+// i, (int) actual[i], (int) expected[i]);
+// }
+ }
+ assertTrue(msg, match);
+ assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
+// assertTrue(msg, Arrays.equals(actual, expected));
+ }
+
+ static void assertEqualBytes (String msg, byte[] expected, ByteBuffer actualBB) {
+ boolean match = true;
+ boolean lenMatch = true;
+ byte actual;
+ int len = actualBB.remaining();
+ if (expected.length != len) {
+ lenMatch = false;
+ if (expected.length < len) len = expected.length;
+ }
+ for (int i = 0; i < len; i++) {
+ actual = actualBB.get();
+ if (actual != expected[i]) {
+ String detail = String.format(
+ "Mismatch at index %d: %d instead of expected %d.\n",
+ i, actual & 0xff, expected[i] & 0xff);
+ match = false;
+ fail(msg + ": " + detail);
+ }
+ }
+ assertTrue(msg, match);
+ assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
+ }
+
+
+ static abstract class CodesGenerator {
+ int row = 0, col = 0;
+
+ abstract void consume(int code);
+
+ boolean isAccepted(int code) {
+ return Character.isLetterOrDigit(code);
+ }
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_GSM0338.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_GSM0338.java
new file mode 100644
index 0000000..a8d2669
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_GSM0338.java
@@ -0,0 +1,57 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+/** Note: this test is GSM specific */
+public class OldCharset_GSM0338 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+// charsetName = "GSM0338";
+ charsetName = "x-gsm-03.38-2000";
+
+ testChars = theseChars(new int[]{
+10, 13, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
+46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
+78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98,
+99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
+115, 116, 117, 118, 119, 120, 121, 122, 161, 163, 164, 165, 167, 191, 196, 197,
+198, 201, 209, 214, 216, 220, 223, 224, 228, 229, 230, 231, 232, 233, 236, 241,
+242, 246, 248, 249, 252, 915, 916
+ });
+
+ testBytes = theseBytes(new int[]{
+10, 13, 32, 33, 34, 35, 2, 37, 38, 39, 40, 41, 42, 43, 44, 45,
+46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+62, 63, 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
+78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 17, 97, 98,
+99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
+115, 116, 117, 118, 119, 120, 121, 122, 64, 1, 36, 3, 95, 96, 91, 14,
+28, 31, 93, 92, 11, 94, 30, 127, 123, 15, 29, 9, 4, 5, 7, 125,
+8, 124, 12, 6, 126, 19, 16
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic () throws CharacterCodingException {
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_10.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_10.java
new file mode 100644
index 0000000..c7bbc94
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_10.java
@@ -0,0 +1,62 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU only */
+public class OldCharset_ISO_8859_10 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-10";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 167, 173, 176, 183, 193, 194, 195, 196, 197, 198, 201, 203, 205, 206, 207,
+208, 211, 212, 213, 214, 216, 218, 219, 220, 221, 222, 223, 225, 226, 227, 228,
+229, 230, 233, 235, 237, 238, 239, 240, 243, 244, 245, 246, 248, 250, 251, 252,
+253, 254, 256, 257, 290, 325, 358, 8213
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 167, 173, 176, 183, 193, 194, 195, 196, 197, 198, 201, 203, 205, 206, 207,
+208, 211, 212, 213, 214, 216, 218, 219, 220, 221, 222, 223, 225, 226, 227, 228,
+229, 230, 233, 235, 237, 238, 239, 240, 243, 244, 245, 246, 248, 250, 251, 252,
+253, 254, 192, 224, 163, 209, 171, 189
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_14.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_14.java
new file mode 100644
index 0000000..1daedf5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_14.java
@@ -0,0 +1,64 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU only */
+public class OldCharset_ISO_8859_14 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-14";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 163, 167, 169, 173, 174, 182, 192, 193, 194, 195, 196, 197, 198, 199, 200,
+201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
+219, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
+236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253,
+255, 266, 372, 7682, 7744, 7776, 7808, 7922
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 163, 167, 169, 173, 174, 182, 192, 193, 194, 195, 196, 197, 198, 199, 200,
+201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
+219, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
+236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253,
+255, 164, 208, 161, 180, 187, 168, 172
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_16.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_16.java
new file mode 100644
index 0000000..edb219a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_ISO_8859_16.java
@@ -0,0 +1,62 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU only */
+public class OldCharset_ISO_8859_16 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-16";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 167, 169, 171, 173, 176, 177, 182, 183, 187, 192, 193, 194, 196, 198, 199,
+200, 201, 202, 203, 204, 205, 206, 207, 210, 211, 212, 214, 217, 218, 219, 220,
+223, 224, 225, 226, 228, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 242,
+243, 244, 246, 249, 250, 251, 252, 255, 258, 321, 352, 382, 536, 8221, 8364
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 167, 169, 171, 173, 176, 177, 182, 183, 187, 192, 193, 194, 196, 198, 199,
+200, 201, 202, 203, 204, 205, 206, 207, 210, 211, 212, 214, 217, 218, 219, 220,
+223, 224, 225, 226, 228, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 242,
+243, 244, 246, 249, 250, 251, 252, 255, 195, 163, 166, 184, 170, 181, 164
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5.java
new file mode 100644
index 0000000..0330cd5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5.java
@@ -0,0 +1,421 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** @hide
+ * SEE correspondig_Android test class:
+ */
+
+public class OldCharset_MultiByte_Big5 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "Big5";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+162, 163, 165, 167, 176, 177, 183, 215, 247, 711, 713, 729, 913, 923, 933, 945,
+955, 965, 1025, 1044, 1059, 1069, 1079, 1089, 1099, 8211, 8221, 8242, 8254, 8451, 8544, 8592,
+8730, 8741, 8756, 8786, 8800, 8869, 8895, 9312, 9332, 9472, 9484, 9496, 9508, 9524, 9552, 9566,
+9578, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733, 9792, 12288, 12298, 12308, 12318, 12328,
+12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12445, 12455, 12465, 12475, 12485, 12495, 12505,
+12515, 12525, 12542, 12552, 12562, 12572, 12582, 12963, 13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998,
+20011, 20024, 20034, 20045, 20056, 20073, 20083, 20094, 20104, 20114, 20126, 20136, 20147, 20160, 20170, 20180,
+20190, 20200, 20210, 20221, 20232, 20242, 20253, 20268, 20278, 20289, 20300, 20310, 20320, 20330, 20340, 20350,
+20360, 20370, 20380, 20398, 20409, 20419, 20429, 20439, 20449, 20460, 20470, 20480, 20491, 20501, 20511, 20521,
+20531, 20544, 20554, 20565, 20575, 20585, 20595, 20605, 20615, 20625, 20635, 20652, 20662, 20673, 20683, 20693,
+20704, 20714, 20725, 20735, 20745, 20755, 20767, 20777, 20787, 20797, 20807, 20818, 20828, 20839, 20849, 20860,
+20871, 20881, 20894, 20906, 20918, 20932, 20942, 20952, 20976, 20986, 20998, 21008, 21020, 21032, 21042, 21057,
+21067, 21077, 21087, 21097, 21108, 21119, 21129, 21139, 21151, 21161, 21179, 21191, 21202, 21213, 21225, 21235,
+21246, 21256, 21266, 21276, 21290, 21300, 21310, 21320, 21330, 21340, 21350, 21360, 21371, 21386, 21396, 21406,
+21420, 21433, 21443, 21453, 21463, 21473, 21483, 21493, 21505, 21515, 21528, 21540, 21550, 21560, 21570, 21582,
+21600, 21611, 21621, 21631, 21643, 21653, 21664, 21674, 21686, 21696, 21710, 21726, 21736, 21746, 21756, 21766,
+21776, 21786, 21798, 21808, 21819, 21829, 21839, 21852, 21862, 21877, 21887, 21897, 21907, 21917, 21927, 21937,
+21947, 21957, 21967, 21977, 21987, 21999, 22009, 22020, 22030, 22043, 22055, 22066, 22077, 22088, 22099, 22110,
+22120, 22130, 22142, 22156, 22167, 22181, 22194, 22204, 22214, 22225, 22235, 22245, 22256, 22266, 22276, 22290,
+22300, 22312, 22323, 22334, 22345, 22369, 22379, 22389, 22400, 22411, 22421, 22431, 22446, 22456, 22466, 22476,
+22492, 22503, 22513, 22523, 22533, 22544, 22555, 22565, 22575, 22585, 22600, 22610, 22621, 22632, 22644, 22654,
+22664, 22675, 22685, 22696, 22707, 22717, 22727, 22737, 22747, 22759, 22772, 22782, 22796, 22806, 22816, 22826,
+22839, 22852, 22862, 22872, 22882, 22893, 22903, 22913, 22925, 22935, 22945, 22958, 22969, 22979, 22989, 23000,
+23011, 23021, 23031, 23041, 23052, 23062, 23072, 23085, 23095, 23105, 23116, 23126, 23136, 23146, 23159, 23171,
+23182, 23194, 23205, 23215, 23225, 23236, 23253, 23263, 23273, 23283, 23293, 23303, 23315, 23325, 23335, 23346,
+23356, 23367, 23377, 23387, 23397, 23408, 23418, 23428, 23438, 23448, 23458, 23468, 23478, 23488, 23498, 23508,
+23518, 23528, 23538, 23553, 23563, 23573, 23583, 23594, 23607, 23617, 23627, 23637, 23648, 23658, 23668, 23678,
+23688, 23698, 23709, 23719, 23729, 23750, 23760, 23770, 23784, 23796, 23807, 23819, 23830, 23840, 23854, 23864,
+23874, 23884, 23897, 23907, 23919, 23929, 23940, 23954, 23964, 23975, 23985, 23996, 24006, 24017, 24029, 24039,
+24049, 24061, 24074, 24084, 24095, 24105, 24115, 24125, 24138, 24148, 24159, 24169, 24179, 24189, 24199, 24213,
+24224, 24234, 24244, 24254, 24264, 24274, 24284, 24294, 24305, 24318, 24328, 24338, 24349, 24359, 24369, 24380,
+24390, 24404, 24418, 24428, 24438, 24448, 24458, 24470, 24480, 24490, 24501, 24511, 24521, 24532, 24542, 24552,
+24563, 24573, 24585, 24595, 24605, 24615, 24626, 24640, 24652, 24664, 24674, 24684, 24703, 24713, 24724, 24735,
+24752, 24762, 24772, 24782, 24792, 24802, 24816, 24826, 24836, 24846, 24856, 24867, 24878, 24891, 24901, 24911,
+24922, 24933, 24944, 24954, 24969, 24979, 24989, 24999, 25009, 25020, 25030, 25046, 25056, 25066, 25077, 25087,
+25097, 25108, 25119, 25129, 25139, 25149, 25159, 25169, 25179, 25189, 25199, 25209, 25219, 25230, 25240, 25256,
+25267, 25277, 25287, 25297, 25307, 25323, 25333, 25343, 25353, 25363, 25384, 25394, 25404, 25414, 25424, 25434,
+25445, 25455, 25466, 25476, 25486, 25496, 25506, 25516, 25533, 25543, 25554, 25564, 25575, 25585, 25606, 25616,
+25626, 25636, 25646, 25657, 25667, 25677, 25688, 25701, 25711, 25721, 25733, 25743, 25753, 25763, 25773, 25787,
+25797, 25807, 25817, 25827, 25837, 25847, 25857, 25868, 25878, 25888, 25898, 25910, 25921, 25935, 25945, 25955,
+25967, 25977, 25987, 26000, 26011, 26021, 26031, 26041, 26051, 26061, 26071, 26081, 26092, 26106, 26116, 26126,
+26140, 26150, 26161, 26177, 26188, 26201, 26212, 26222, 26232, 26244, 26256, 26269, 26280, 26290, 26301, 26311,
+26322, 26332, 26342, 26352, 26364, 26376, 26386, 26397, 26407, 26417, 26427, 26437, 26447, 26457, 26474, 26484,
+26494, 26505, 26515, 26525, 26542, 26552, 26562, 26572, 26584, 26594, 26604, 26614, 26642, 26652, 26662, 26673,
+26683, 26693, 26703, 26731, 26741, 26751, 26761, 26771, 26781, 26791, 26801, 26820, 26830, 26840, 26851, 26862,
+26872, 26884, 26894, 26917, 26927, 26937, 26948, 26958, 26968, 26978, 26988, 26998, 27010, 27021, 27031, 27041,
+27051, 27061, 27071, 27081, 27091, 27106, 27116, 27126, 27136, 27146, 27156, 27166, 27176, 27186, 27196, 27206,
+27216, 27226, 27236, 27247, 27262, 27273, 27283, 27294, 27304, 27315, 27325, 27335, 27345, 27355, 27365, 27375,
+27385, 27395, 27407, 27417, 27427, 27437, 27447, 27457, 27467, 27477, 27487, 27498, 27510, 27520, 27530, 27540,
+27550, 27562, 27573, 27583, 27593, 27603, 27614, 27624, 27634, 27644, 27654, 27664, 27674, 27684, 27694, 27704,
+27714, 27724, 27735, 27745, 27755, 27766, 27776, 27786, 27796, 27819, 27830, 27840, 27850, 27860, 27870, 27880,
+27890, 27904, 27914, 27926, 27936, 27946, 27956, 27966, 27992, 28002, 28012, 28022, 28032, 28042, 28052, 28074,
+28084, 28094, 28104, 28114, 28124, 28134, 28144, 28154, 28165, 28185, 28195, 28205, 28216, 28227, 28237, 28248,
+28258, 28270, 28280, 28296, 28306, 28316, 28326, 28336, 28346, 28356, 28366, 28376, 28395, 28405, 28415, 28425,
+28435, 28446, 28457, 28467, 28478, 28494, 28504, 28514, 28524, 28534, 28544, 28555, 28565, 28576, 28586, 28596,
+28607, 28617, 28628, 28638, 28648, 28658, 28668, 28678, 28689, 28699, 28710, 28720, 28730, 28740, 28753, 28763,
+28773, 28784, 28794, 28804, 28814, 28824, 28836, 28846, 28856, 28869, 28879, 28889, 28900, 28911, 28921, 28932,
+28942, 28953, 28963, 28974, 28986, 28996, 29006, 29016, 29026, 29036, 29048, 29058, 29071, 29081, 29092, 29103,
+29113, 29123, 29134, 29144, 29154, 29164, 29176, 29186, 29196, 29209, 29219, 29229, 29240, 29250, 29260, 29270,
+29280, 29290, 29300, 29310, 29320, 29330, 29341, 29351, 29364, 29375, 29385, 29396, 29407, 29417, 29427, 29437,
+29447, 29457, 29467, 29477, 29488, 29498, 29508, 29518, 29528, 29538, 29548, 29558, 29568, 29578, 29588, 29599,
+29609, 29619, 29630, 29640, 29650, 29660, 29671, 29684, 29694, 29704, 29718, 29728, 29738, 29748, 29759, 29770,
+29780, 29790, 29801, 29811, 29821, 29831, 29842, 29852, 29862, 29872, 29882, 29893, 29903, 29913, 29923, 29934,
+29947, 29959, 29969, 29980, 29990, 30000, 30010, 30023, 30036, 30047, 30058, 30070, 30080, 30090, 30100, 30114,
+30128, 30138, 30148, 30158, 30168, 30178, 30189, 30199, 30209, 30219, 30229, 30239, 30249, 30259, 30269, 30279,
+30290, 30300, 30313, 30325, 30335, 30345, 30355, 30365, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448,
+30458, 30468, 30480, 30490, 30501, 30511, 30521, 30532, 30542, 30553, 30563, 30573, 30585, 30595, 30605, 30615,
+30625, 30635, 30645, 30655, 30665, 30675, 30686, 30696, 30706, 30716, 30726, 30736, 30749, 30759, 30769, 30787,
+30797, 30812, 30824, 30841, 30851, 30862, 30872, 30882, 30892, 30906, 30916, 30926, 30938, 30949, 30959, 30969,
+30980, 30990, 31001, 31011, 31021, 31032, 31042, 31052, 31062, 31072, 31082, 31092, 31103, 31114, 31124, 31136,
+31146, 31156, 31166, 31176, 31186, 31196, 31206, 31222, 31232, 31242, 31252, 31262, 31272, 31287, 31300, 31310,
+31320, 31330, 31340, 31350, 31360, 31370, 31380, 31390, 31400, 31410, 31422, 31434, 31448, 31459, 31469, 31479,
+31489, 31502, 31512, 31522, 31532, 31544, 31556, 31566, 31576, 31587, 31597, 31607, 31618, 31628, 31638, 31648,
+31660, 31671, 31681, 31691, 31701, 31711, 31721, 31731, 31741, 31751, 31761, 31772, 31782, 31792, 31803, 31813,
+31824, 31834, 31844, 31854, 31864, 31876, 31889, 31902, 31912, 31922, 31932, 31944, 31954, 31964, 31975, 31985,
+31995, 32005, 32015, 32025, 32040, 32050, 32060, 32070, 32080, 32091, 32102, 32112, 32122, 32132, 32142, 32156,
+32166, 32176, 32186, 32196, 32206, 32216, 32227, 32238, 32249, 32259, 32269, 32279, 32289, 32299, 32309, 32319,
+32329, 32339, 32350, 32360, 32370, 32380, 32390, 32401, 32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631,
+32643, 32653, 32666, 32676, 32687, 32697, 32707, 32717, 32727, 32737, 32747, 32757, 32767, 32779, 32789, 32799,
+32809, 32819, 32829, 32839, 32849, 32860, 32871, 32881, 32893, 32903, 32914, 32924, 32937, 32948, 32962, 32972,
+32982, 32992, 33005, 33016, 33026, 33045, 33055, 33065, 33081, 33091, 33101, 33115, 33125, 33135, 33145, 33155,
+33165, 33175, 33186, 33196, 33207, 33218, 33228, 33239, 33249, 33260, 33271, 33281, 33291, 33301, 33311, 33322,
+33332, 33343, 33353, 33363, 33374, 33384, 33394, 33404, 33418, 33428, 33438, 33448, 33459, 33469, 33489, 33499,
+33509, 33519, 33529, 33539, 33549, 33559, 33570, 33580, 33590, 33600, 33610, 33620, 33651, 33661, 33671, 33682,
+33693, 33703, 33725, 33735, 33745, 33755, 33765, 33775, 33785, 33795, 33805, 33819, 33833, 33843, 33853, 33863,
+33873, 33883, 33893, 33903, 33913, 33926, 33936, 33946, 33956, 33966, 33976, 33986, 33996, 34006, 34023, 34033,
+34043, 34054, 34065, 34076, 34086, 34096, 34107, 34117, 34129, 34139, 34149, 34161, 34171, 34181, 34191, 34201,
+34211, 34223, 34233, 34243, 34253, 34263, 34273, 34283, 34294, 34304, 34314, 34327, 34337, 34348, 34358, 34368,
+34379, 34389, 34399, 34409, 34419, 34437, 34448, 34458, 34468, 34479, 34489, 34499, 34512, 34522, 34532, 34549,
+34560, 34570, 34584, 34594, 34604, 34615, 34625, 34636, 34646, 34656, 34666, 34676, 34689, 34701, 34711, 34722,
+34732, 34742, 34752, 34762, 34772, 34782, 34792, 34802, 34812, 34822, 34832, 34843, 34853, 34863, 34873, 34883,
+34893, 34903, 34913, 34923, 34933, 34943, 34953, 34963, 34974, 34984, 34994, 35004, 35017, 35028, 35038, 35048,
+35058, 35068, 35078, 35088, 35098, 35109, 35119, 35131, 35142, 35152, 35162, 35172, 35182, 35193, 35203, 35215,
+35227, 35238, 35250, 35261, 35282, 35292, 35302, 35312, 35322, 35332, 35342, 35352, 35362, 35372, 35382, 35392,
+35402, 35412, 35422, 35432, 35442, 35452, 35462, 35473, 35486, 35496, 35506, 35516, 35526, 35537, 35547, 35558,
+35568, 35578, 35588, 35598, 35608, 35618, 35628, 35638, 35648, 35658, 35668, 35679, 35690, 35700, 35710, 35720,
+35730, 35740, 35895, 35905, 35915, 35925, 35935, 35945, 35955, 35965, 35977, 35987, 35997, 36007, 36018, 36028,
+36039, 36049, 36060, 36070, 36080, 36090, 36100, 36111, 36121, 36196, 36206, 36216, 36228, 36238, 36249, 36259,
+36269, 36279, 36289, 36299, 36309, 36319, 36329, 36339, 36349, 36359, 36369, 36379, 36389, 36400, 36412, 36423,
+36435, 36445, 36455, 36466, 36476, 36486, 36496, 36506, 36516, 36530, 36541, 36553, 36563, 36573, 36583, 36593,
+36603, 36613, 36624, 36634, 36644, 36654, 36664, 36674, 36685, 36695, 36705, 36763, 36774, 36784, 36799, 36809,
+36819, 36832, 36842, 36852, 36862, 36875, 36885, 36895, 36909, 36920, 36930, 36941, 36952, 36962, 36973, 36983,
+36993, 37003, 37013, 37023, 37034, 37044, 37054, 37064, 37076, 37087, 37097, 37107, 37117, 37127, 37137, 37147,
+37158, 37168, 37178, 37188, 37198, 37208, 37218, 37228, 37239, 37249, 37259, 37273, 37283, 37293, 37303, 37313,
+37323, 37333, 37346, 37356, 37367, 37377, 37388, 37398, 37411, 37421, 37431, 37445, 37455, 37466, 37476, 37487,
+37497, 37507, 37517, 37527, 37537, 37547, 37557, 37568, 37578, 37589, 37599, 37609, 37623, 37633, 37643, 37653,
+37663, 37673, 37683, 37702, 37712, 37722, 37732, 37744, 37754, 37768, 37778, 37789, 37799, 37809, 37824, 37834,
+37844, 37854, 37864, 37877, 37887, 37897, 37907, 37920, 37930, 37941, 37951, 37961, 37973, 37984, 37994, 38004,
+38014, 38263, 38274, 38284, 38296, 38307, 38317, 38327, 38339, 38349, 38362, 38372, 38428, 38440, 38450, 38460,
+38474, 38484, 38494, 38506, 38516, 38526, 38536, 38546, 38556, 38567, 38577, 38587, 38597, 38610, 38620, 38632,
+38642, 38653, 38663, 38673, 38684, 38694, 38704, 38714, 38724, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
+38808, 38818, 38828, 38838, 38849, 38859, 38869, 38879, 38893, 38904, 38914, 38924, 38934, 38944, 38955, 38965,
+38977, 38988, 38999, 39010, 39023, 39080, 39090, 39100, 39110, 39131, 39141, 39151, 39161, 39171, 39184, 39194,
+39204, 39214, 39226, 39237, 39248, 39259, 39318, 39329, 39339, 39349, 39361, 39371, 39381, 39391, 39401, 39412,
+39422, 39433, 39444, 39454, 39465, 39476, 39486, 39496, 39506, 39518, 39528, 39592, 39603, 39614, 39626, 39636,
+39647, 39659, 39670, 39681, 39691, 39701, 39711, 39721, 39731, 39742, 39752, 39762, 39775, 39788, 39798, 39808,
+39824, 39834, 39844, 39854, 39864, 39875, 39891, 39902, 39912, 39927, 39941, 39954, 39964, 39976, 39986, 39996,
+40006, 40016, 40030, 40040, 40051, 40165, 40177, 40187, 40197, 40208, 40219, 40229, 40239, 40251, 40261, 40271,
+40281, 40295, 40305, 40315, 40325, 40336, 40346, 40356, 40367, 40377, 40387, 40397, 40407, 40417, 40427, 40437,
+40447, 40457, 40467, 40477, 40565, 40575, 40585, 40595, 40605, 40615, 40628, 40638, 40648, 40659, 40669, 40679,
+40690, 40700, 40710, 40720, 40730, 40740, 40750, 40760, 40770, 40780, 40790, 40800, 40810, 40820, 40830, 40845,
+40856, 40866, 64012, 65072, 65082, 65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65343,
+65353, 65363, 65373, 65536
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+162, 70, 162, 71, 162, 68, 161, 177, 162, 88, 161, 211, 161, 80, 161, 209,
+161, 210, 163, 190, 163, 188, 163, 187, 163, 68, 163, 78, 163, 87, 163, 92,
+163, 102, 163, 111, 199, 179, 199, 177, 199, 187, 199, 197, 199, 208, 199, 218,
+199, 228, 161, 86, 161, 168, 161, 172, 161, 194, 162, 74, 162, 185, 161, 246,
+161, 212, 161, 252, 161, 239, 161, 220, 161, 218, 161, 230, 161, 233, 199, 233,
+199, 243, 162, 119, 162, 122, 162, 125, 162, 116, 162, 114, 162, 164, 162, 165,
+162, 166, 162, 98, 162, 110, 162, 121, 161, 189, 161, 182, 161, 191, 161, 187,
+162, 168, 161, 185, 161, 240, 161, 64, 161, 109, 161, 101, 161, 170, 162, 202,
+198, 165, 198, 175, 198, 185, 198, 195, 198, 205, 198, 215, 198, 225, 198, 235,
+198, 245, 198, 162, 198, 254, 199, 73, 199, 83, 199, 93, 199, 103, 199, 113,
+199, 123, 199, 167, 198, 161, 163, 119, 163, 163, 163, 173, 163, 183, 161, 192,
+162, 85, 162, 80, 162, 87, 162, 83, 164, 64, 164, 87, 165, 66, 165, 224,
+164, 88, 164, 89, 201, 64, 165, 69, 173, 188, 165, 228, 168, 197, 176, 174,
+164, 169, 164, 172, 168, 200, 166, 235, 173, 189, 164, 176, 164, 181, 165, 74,
+165, 81, 201, 101, 165, 242, 165, 247, 201, 179, 201, 187, 201, 180, 201, 173,
+167, 68, 202, 100, 203, 189, 202, 90, 167, 65, 203, 191, 203, 185, 168, 219,
+168, 215, 203, 200, 203, 197, 171, 86, 205, 238, 171, 80, 205, 221, 171, 85,
+171, 72, 205, 239, 208, 212, 173, 206, 173, 211, 212, 91, 173, 201, 173, 197,
+208, 209, 212, 99, 212, 89, 176, 186, 212, 93, 212, 94, 212, 101, 176, 176,
+216, 95, 179, 199, 216, 81, 182, 202, 220, 195, 220, 190, 220, 193, 185, 178,
+224, 254, 224, 246, 187, 248, 228, 230, 187, 252, 232, 245, 192, 118, 236, 190,
+195, 95, 247, 208, 165, 251, 168, 224, 176, 194, 164, 186, 166, 64, 173, 221,
+201, 78, 171, 96, 203, 205, 190, 173, 167, 77, 208, 226, 208, 229, 225, 64,
+176, 196, 165, 88, 164, 192, 201, 191, 202, 108, 167, 83, 203, 209, 168, 239,
+171, 103, 208, 235, 208, 234, 179, 209, 179, 207, 182, 207, 188, 66, 190, 176,
+165, 92, 167, 85, 168, 241, 171, 105, 176, 199, 179, 211, 225, 67, 190, 177,
+164, 196, 166, 73, 216, 98, 201, 108, 173, 234, 232, 250, 176, 208, 164, 200,
+168, 242, 164, 82, 168, 246, 166, 76, 171, 111, 201, 196, 203, 218, 208, 239,
+225, 70, 201, 88, 176, 209, 164, 207, 168, 252, 232, 251, 165, 115, 165, 114,
+166, 83, 166, 84, 202, 126, 202, 165, 167, 109, 167, 108, 167, 102, 167, 96,
+203, 235, 203, 225, 168, 254, 203, 220, 169, 81, 169, 66, 206, 72, 171, 125,
+206, 69, 171, 115, 171, 117, 206, 78, 173, 239, 173, 245, 173, 243, 173, 246,
+173, 240, 208, 247, 208, 240, 212, 124, 212, 168, 212, 126, 176, 221, 176, 227,
+176, 213, 212, 113, 216, 120, 179, 239, 216, 109, 179, 220, 179, 217, 179, 237,
+179, 235, 182, 229, 220, 216, 220, 223, 182, 224, 182, 226, 225, 85, 225, 83,
+185, 199, 185, 192, 225, 71, 188, 74, 229, 67, 228, 246, 188, 78, 233, 69,
+190, 185, 233, 68, 236, 198, 236, 193, 239, 188, 195, 96, 243, 254, 196, 90,
+246, 215, 197, 241, 165, 124, 202, 169, 167, 120, 169, 84, 174, 70, 182, 233,
+233, 71, 166, 98, 166, 96, 167, 163, 202, 173, 169, 89, 203, 245, 203, 250,
+203, 249, 171, 172, 206, 94, 206, 82, 171, 177, 209, 82, 174, 71, 209, 74,
+212, 177, 212, 197, 212, 200, 212, 173, 176, 237, 212, 196, 216, 170, 216, 168,
+179, 243, 216, 175, 216, 167, 182, 246, 220, 235, 220, 227, 225, 93, 185, 209,
+225, 101, 185, 211, 229, 75, 190, 165, 188, 88, 233, 74, 190, 194, 192, 164,
+241, 248, 247, 211, 206, 95, 225, 105, 204, 66, 165, 126, 176, 247, 164, 211,
+166, 105, 169, 97, 171, 182, 174, 78, 176, 248, 188, 93, 201, 209, 166, 113,
+167, 176, 202, 181, 202, 187, 169, 103, 169, 102, 204, 77, 169, 107, 171, 185,
+171, 187, 206, 118, 206, 110, 171, 194, 174, 91, 209, 92, 174, 87, 209, 93,
+216, 194, 176, 250, 212, 231, 212, 236, 212, 206, 176, 253, 180, 64, 216, 198,
+212, 227, 180, 65, 216, 190, 216, 181, 221, 70, 220, 244, 225, 110, 225, 124,
+185, 224, 225, 115, 229, 86, 229, 94, 233, 86, 190, 197, 236, 211, 236, 208,
+239, 193, 245, 200, 164, 109, 167, 184, 204, 86, 177, 69, 192, 169, 201, 115,
+202, 188, 169, 120, 171, 200, 209, 104, 174, 97, 212, 242, 216, 213, 216, 211,
+185, 230, 185, 235, 236, 217, 171, 202, 180, 77, 201, 212, 221, 75, 202, 191,
+192, 170, 167, 190, 171, 206, 174, 105, 177, 79, 239, 195, 201, 118, 201, 217,
+202, 194, 202, 197, 204, 104, 204, 103, 169, 167, 206, 171, 206, 121, 206, 162,
+174, 111, 174, 115, 209, 109, 212, 245, 177, 86, 212, 248, 213, 68, 216, 236,
+216, 233, 180, 79, 216, 232, 221, 78, 183, 68, 225, 176, 185, 241, 229, 101,
+229, 106, 233, 97, 233, 95, 192, 172, 244, 68, 246, 222, 164, 116, 165, 169,
+164, 118, 180, 83, 202, 203, 204, 110, 171, 212, 209, 115, 177, 98, 180, 85,
+221, 90, 185, 247, 188, 109, 229, 110, 165, 173, 171, 213, 167, 200, 169, 179,
+171, 214, 209, 119, 213, 72, 177, 104, 183, 72, 225, 188, 225, 185, 233, 113,
+245, 203, 164, 123, 171, 217, 183, 73, 202, 211, 169, 183, 174, 122, 180, 93,
+185, 251, 204, 116, 167, 206, 177, 108, 202, 213, 169, 185, 171, 222, 213, 79,
+177, 116, 180, 96, 188, 120, 242, 64, 201, 123, 201, 225, 204, 120, 202, 218,
+202, 220, 169, 191, 204, 175, 204, 172, 171, 228, 169, 202, 204, 125, 206, 202,
+206, 201, 206, 207, 171, 236, 171, 239, 177, 118, 177, 120, 174, 172, 174, 169,
+213, 85, 213, 86, 216, 253, 216, 252, 177, 166, 216, 251, 180, 107, 180, 105,
+217, 79, 180, 112, 217, 75, 180, 104, 221, 108, 225, 210, 221, 105, 221, 111,
+186, 70, 225, 209, 188, 162, 225, 207, 229, 126, 229, 162, 233, 118, 188, 165,
+229, 123, 236, 225, 233, 123, 239, 207, 236, 227, 239, 204, 195, 106, 197, 116,
+201, 124, 204, 177, 180, 117, 225, 214, 194, 87, 204, 178, 174, 176, 165, 183,
+166, 170, 201, 236, 167, 232, 167, 229, 202, 231, 202, 233, 167, 233, 169, 225,
+204, 187, 169, 226, 169, 230, 204, 181, 169, 219, 206, 218, 206, 215, 174, 179,
+171, 246, 206, 225, 174, 193, 213, 102, 209, 189, 174, 185, 174, 189, 209, 199,
+213, 103, 213, 114, 177, 204, 177, 193, 213, 113, 177, 184, 177, 180, 177, 197,
+213, 107, 217, 107, 180, 161, 217, 102, 221, 183, 221, 120, 183, 112, 221, 122,
+221, 178, 221, 126, 221, 185, 221, 166, 221, 162, 225, 218, 186, 75, 225, 242,
+188, 176, 188, 177, 229, 177, 229, 180, 188, 193, 229, 184, 188, 189, 190, 216,
+190, 213, 233, 167, 233, 174, 236, 234, 192, 195, 194, 94, 239, 213, 242, 70,
+244, 76, 246, 225, 197, 205, 166, 172, 206, 231, 177, 211, 177, 208, 180, 178,
+221, 188, 229, 191, 192, 197, 180, 180, 177, 216, 165, 184, 180, 181, 164, 232,
+209, 208, 213, 168, 186, 88, 201, 94, 166, 175, 169, 244, 204, 198, 169, 250,
+206, 239, 206, 240, 172, 82, 174, 208, 174, 206, 213, 172, 177, 224, 180, 182,
+221, 199, 183, 121, 221, 194, 186, 92, 186, 91, 229, 198, 233, 185, 190, 232,
+236, 242, 194, 96, 196, 102, 164, 234, 176, 210, 164, 235, 209, 215, 180, 194,
+196, 103, 166, 182, 201, 242, 202, 253, 167, 246, 203, 64, 170, 87, 204, 220,
+170, 81, 170, 80, 170, 85, 170, 75, 207, 91, 172, 101, 207, 81, 207, 90,
+207, 67, 172, 107, 172, 90, 207, 78, 209, 236, 209, 227, 209, 238, 209, 226,
+209, 222, 174, 233, 209, 224, 213, 196, 213, 189, 177, 236, 213, 206, 177, 234,
+177, 248, 177, 239, 177, 238, 177, 243, 217, 205, 180, 198, 180, 208, 180, 203,
+217, 197, 217, 172, 180, 213, 217, 216, 221, 242, 221, 210, 221, 228, 221, 204,
+221, 230, 221, 205, 221, 218, 221, 229, 183, 167, 226, 74, 226, 93, 226, 90,
+186, 103, 226, 96, 226, 78, 225, 254, 186, 98, 229, 213, 229, 212, 229, 235,
+229, 202, 188, 212, 229, 220, 188, 207, 233, 202, 233, 194, 233, 215, 233, 221,
+233, 209, 233, 203, 233, 208, 233, 212, 192, 207, 236, 247, 236, 253, 236, 251,
+237, 66, 194, 98, 239, 223, 239, 229, 242, 79, 192, 205, 195, 111, 244, 90,
+244, 87, 245, 208, 247, 226, 248, 242, 170, 89, 209, 247, 213, 216, 221, 250,
+226, 101, 233, 222, 194, 106, 172, 110, 230, 209, 204, 234, 174, 237, 217, 222,
+226, 102, 233, 226, 172, 113, 183, 181, 239, 233, 183, 182, 204, 236, 210, 64,
+217, 228, 221, 254, 233, 232, 165, 194, 203, 74, 174, 244, 180, 225, 165, 195,
+168, 68, 202, 64, 166, 189, 166, 195, 203, 77, 168, 90, 205, 69, 205, 67,
+168, 92, 170, 106, 204, 243, 205, 71, 170, 121, 204, 244, 205, 70, 170, 96,
+204, 254, 207, 124, 207, 116, 210, 100, 207, 168, 172, 120, 207, 110, 172, 163,
+210, 76, 210, 77, 175, 64, 210, 72, 210, 98, 175, 71, 175, 75, 178, 101,
+213, 226, 213, 240, 213, 236, 178, 89, 213, 242, 178, 104, 213, 249, 178, 76,
+178, 77, 181, 65, 180, 237, 180, 244, 180, 229, 180, 251, 180, 248, 180, 240,
+217, 240, 180, 243, 218, 78, 217, 236, 222, 95, 183, 200, 222, 87, 222, 85,
+183, 196, 183, 201, 226, 108, 222, 93, 226, 170, 226, 109, 186, 161, 226, 117,
+186, 118, 226, 183, 186, 120, 186, 115, 186, 121, 226, 118, 188, 239, 230, 67,
+230, 73, 230, 72, 192, 223, 230, 90, 230, 93, 191, 73, 233, 251, 191, 74,
+233, 253, 234, 65, 237, 81, 237, 87, 237, 91, 237, 88, 239, 246, 194, 112,
+194, 114, 195, 115, 239, 245, 196, 106, 244, 100, 245, 212, 197, 120, 247, 228,
+249, 163, 166, 199, 203, 95, 205, 85, 170, 162, 205, 81, 172, 183, 172, 182,
+172, 181, 210, 119, 175, 81, 175, 79, 175, 78, 178, 109, 178, 105, 214, 79,
+214, 91, 181, 72, 218, 94, 218, 92, 218, 100, 222, 161, 183, 206, 222, 120,
+222, 114, 183, 213, 222, 116, 226, 191, 226, 192, 186, 179, 230, 109, 230, 99,
+191, 81, 191, 85, 191, 82, 234, 84, 237, 98, 192, 236, 194, 119, 242, 108,
+242, 105, 245, 220, 248, 177, 170, 167, 170, 168, 210, 125, 181, 80, 188, 248,
+168, 101, 205, 91, 172, 187, 214, 92, 218, 104, 186, 185, 234, 89, 196, 235,
+202, 67, 203, 97, 205, 95, 205, 98, 207, 194, 172, 188, 210, 168, 175, 86,
+214, 98, 214, 99, 178, 114, 181, 84, 218, 111, 222, 173, 186, 187, 188, 250,
+230, 117, 230, 161, 234, 94, 239, 254, 197, 122, 201, 167, 203, 107, 170, 179,
+170, 177, 172, 197, 207, 210, 207, 201, 210, 180, 210, 179, 210, 176, 214, 120,
+178, 123, 214, 121, 218, 126, 218, 169, 181, 88, 181, 94, 183, 233, 222, 178,
+222, 190, 183, 231, 188, 252, 226, 207, 230, 167, 230, 162, 234, 102, 191, 88,
+192, 245, 192, 244, 244, 111, 242, 116, 196, 110, 246, 242, 195, 164, 207, 216,
+218, 171, 230, 173, 237, 112, 178, 162, 181, 100, 165, 208, 203, 109, 207, 218,
+175, 96, 210, 194, 181, 102, 183, 237, 234, 106, 197, 124, 203, 111, 172, 207,
+210, 195, 210, 202, 210, 198, 214, 124, 181, 107, 181, 103, 222, 210, 222, 202,
+183, 241, 186, 198, 226, 221, 189, 69, 189, 68, 234, 111, 234, 110, 237, 119,
+194, 161, 240, 74, 196, 238, 249, 204, 202, 71, 214, 166, 181, 113, 230, 185,
+244, 113, 181, 114, 244, 114, 172, 213, 178, 176, 181, 115, 234, 117, 205, 120,
+207, 231, 207, 226, 210, 207, 210, 214, 214, 176, 214, 169, 214, 168, 218, 188,
+218, 192, 222, 225, 183, 254, 222, 226, 184, 64, 226, 234, 230, 188, 234, 161,
+234, 120, 237, 123, 237, 122, 194, 163, 242, 121, 196, 239, 218, 195, 207, 233,
+244, 120, 205, 123, 207, 234, 207, 238, 175, 124, 175, 122, 210, 229, 178, 185,
+214, 182, 218, 200, 218, 207, 222, 238, 222, 237, 184, 72, 184, 75, 226, 246,
+226, 245, 189, 84, 230, 201, 230, 197, 191, 106, 234, 164, 193, 70, 237, 172,
+237, 174, 194, 166, 195, 170, 244, 122, 245, 225, 248, 181, 205, 162, 207, 245,
+175, 170, 175, 168, 214, 191, 218, 210, 184, 83, 226, 249, 226, 253, 230, 205,
+193, 73, 246, 247, 165, 221, 170, 196, 172, 237, 210, 243, 175, 179, 214, 198,
+181, 125, 218, 215, 184, 90, 184, 92, 227, 72, 189, 94, 234, 175, 191, 111,
+237, 180, 194, 169, 244, 163, 168, 115, 207, 254, 210, 251, 214, 201, 223, 68,
+227, 74, 230, 211, 237, 183, 197, 209, 210, 253, 181, 164, 186, 220, 244, 165,
+208, 67, 211, 70, 214, 211, 214, 208, 178, 196, 214, 219, 218, 224, 218, 227,
+218, 229, 223, 83, 223, 72, 184, 95, 227, 93, 227, 85, 227, 83, 189, 105,
+230, 217, 230, 214, 189, 104, 230, 215, 234, 187, 234, 198, 191, 122, 237, 195,
+237, 201, 193, 76, 191, 117, 240, 97, 240, 104, 240, 108, 242, 172, 244, 170,
+196, 240, 246, 254, 197, 210, 198, 89, 208, 69, 211, 73, 211, 74, 218, 232,
+218, 233, 223, 84, 227, 96, 230, 224, 234, 199, 193, 83, 194, 179, 247, 65,
+168, 116, 172, 245, 211, 89, 175, 200, 214, 240, 178, 216, 178, 209, 178, 204,
+181, 178, 184, 108, 181, 185, 181, 187, 223, 93, 223, 100, 223, 94, 186, 238,
+227, 117, 186, 237, 186, 246, 227, 108, 227, 107, 189, 112, 189, 116, 230, 239,
+189, 123, 230, 233, 234, 219, 234, 206, 234, 205, 193, 95, 193, 103, 193, 104,
+237, 215, 240, 119, 194, 182, 242, 184, 242, 182, 196, 126, 245, 235, 247, 66,
+249, 65, 166, 206, 234, 223, 245, 237, 208, 77, 214, 241, 223, 103, 189, 125,
+242, 187, 208, 79, 178, 220, 184, 115, 189, 126, 195, 188, 211, 99, 214, 248,
+219, 68, 187, 66, 230, 246, 239, 168, 244, 177, 181, 192, 175, 209, 214, 254,
+234, 230, 166, 213, 175, 212, 215, 66, 219, 69, 227, 163, 230, 252, 193, 109,
+197, 165, 187, 70, 203, 119, 203, 120, 170, 211, 170, 212, 208, 91, 173, 73,
+173, 68, 208, 88, 175, 218, 175, 221, 175, 215, 215, 78, 215, 74, 178, 231,
+181, 200, 219, 74, 219, 80, 223, 119, 184, 123, 223, 126, 184, 161, 227, 166,
+227, 168, 231, 68, 231, 66, 234, 239, 234, 242, 193, 117, 237, 234, 242, 193,
+249, 68, 175, 229, 219, 84, 211, 112, 244, 181, 227, 171, 166, 224, 175, 232,
+215, 86, 219, 90, 223, 164, 231, 71, 240, 163, 244, 182, 166, 226, 202, 75,
+203, 161, 208, 106, 205, 188, 205, 191, 170, 218, 170, 222, 173, 98, 173, 86,
+173, 89, 173, 102, 208, 109, 173, 83, 206, 65, 175, 250, 211, 126, 211, 179,
+175, 249, 175, 251, 175, 240, 175, 239, 215, 94, 215, 104, 215, 119, 178, 247,
+215, 107, 179, 65, 178, 245, 219, 163, 219, 164, 219, 175, 219, 111, 181, 216,
+219, 94, 181, 209, 181, 211, 219, 174, 223, 199, 223, 217, 184, 168, 223, 215,
+223, 177, 184, 175, 223, 176, 223, 211, 223, 173, 223, 179, 187, 96, 227, 187,
+227, 173, 227, 180, 187, 93, 227, 178, 227, 196, 227, 201, 231, 115, 223, 169,
+231, 88, 189, 183, 189, 176, 231, 87, 231, 114, 231, 122, 231, 77, 234, 249,
+235, 70, 235, 74, 235, 86, 235, 75, 237, 251, 238, 81, 237, 245, 238, 75,
+237, 250, 193, 166, 194, 202, 240, 167, 194, 197, 242, 205, 242, 202, 242, 198,
+244, 190, 244, 189, 196, 173, 196, 244, 245, 250, 247, 74, 247, 76, 247, 241,
+249, 199, 179, 66, 184, 185, 240, 186, 208, 169, 211, 196, 211, 205, 211, 195,
+176, 68, 179, 76, 215, 167, 215, 174, 181, 241, 219, 182, 181, 240, 223, 232,
+184, 190, 184, 196, 187, 106, 187, 103, 227, 224, 187, 108, 227, 225, 189, 193,
+231, 161, 189, 187, 231, 176, 189, 185, 235, 97, 191, 196, 235, 93, 191, 195,
+238, 93, 238, 107, 193, 172, 238, 105, 240, 197, 238, 111, 240, 208, 194, 206,
+242, 228, 242, 227, 244, 197, 246, 66, 247, 81, 247, 215, 197, 251, 211, 207,
+173, 108, 181, 243, 191, 197, 173, 109, 211, 210, 211, 215, 215, 178, 215, 195,
+179, 79, 215, 180, 219, 205, 219, 202, 219, 207, 184, 199, 223, 245, 187, 116,
+227, 248, 227, 252, 231, 201, 189, 197, 187, 117, 191, 200, 235, 122, 193, 182,
+240, 214, 240, 215, 242, 234, 196, 176, 246, 74, 249, 72, 181, 247, 179, 87,
+223, 251, 191, 204, 194, 209, 196, 253, 168, 164, 224, 67, 224, 68, 231, 210,
+246, 76, 208, 176, 176, 81, 176, 79, 179, 96, 215, 203, 182, 70, 219, 218,
+219, 226, 182, 64, 181, 252, 184, 229, 184, 211, 184, 217, 224, 70, 187, 165,
+187, 121, 187, 163, 189, 210, 189, 203, 231, 213, 231, 216, 189, 219, 191, 205,
+235, 169, 191, 206, 193, 195, 193, 188, 238, 161, 238, 166, 194, 213, 240, 232,
+242, 249, 242, 248, 242, 252, 196, 183, 244, 207, 196, 254, 247, 86, 248, 67,
+197, 254, 198, 109, 168, 166, 193, 197, 224, 83, 168, 168, 219, 229, 228, 82,
+193, 199, 215, 209, 184, 232, 191, 223, 168, 169, 179, 104, 184, 237, 182, 75,
+184, 234, 187, 172, 189, 231, 189, 225, 235, 183, 193, 200, 240, 244, 196, 185,
+248, 69, 168, 170, 235, 186, 211, 228, 219, 237, 224, 96, 187, 175, 189, 236,
+243, 77, 211, 230, 215, 218, 182, 91, 219, 247, 184, 242, 224, 109, 184, 245,
+228, 91, 228, 94, 231, 251, 231, 249, 231, 245, 235, 198, 235, 195, 238, 191,
+238, 188, 241, 67, 240, 254, 195, 219, 195, 218, 244, 215, 247, 97, 247, 95,
+249, 80, 184, 250, 235, 200, 249, 172, 211, 233, 215, 221, 220, 69, 220, 73,
+182, 97, 224, 120, 228, 100, 232, 74, 232, 72, 235, 202, 191, 233, 193, 212,
+194, 225, 244, 220, 197, 175, 168, 175, 191, 236, 168, 176, 203, 166, 203, 165,
+205, 206, 208, 182, 173, 125, 176, 106, 211, 234, 215, 227, 179, 119, 179, 116,
+220, 77, 182, 104, 185, 69, 185, 77, 187, 184, 187, 189, 190, 68, 190, 69,
+193, 218, 195, 229, 176, 111, 203, 167, 168, 184, 205, 212, 208, 188, 208, 191,
+215, 238, 211, 247, 215, 241, 215, 237, 179, 163, 220, 90, 224, 167, 228, 113,
+232, 89, 190, 70, 241, 75, 246, 91, 212, 64, 215, 243, 220, 96, 185, 83,
+187, 197, 232, 94, 190, 76, 238, 200, 193, 222, 243, 95, 244, 227, 198, 93,
+196, 192, 212, 66, 212, 67, 215, 247, 216, 65, 220, 98, 220, 105, 220, 119,
+182, 116, 228, 186, 185, 87, 185, 100, 224, 188, 185, 103, 185, 95, 224, 191,
+228, 164, 224, 182, 228, 126, 228, 165, 228, 175, 228, 163, 232, 161, 232, 101,
+232, 115, 232, 120, 232, 106, 232, 108, 235, 244, 235, 233, 236, 64, 192, 67,
+235, 224, 235, 249, 191, 248, 235, 234, 238, 216, 193, 237, 238, 208, 193, 236,
+235, 227, 241, 96, 241, 85, 241, 88, 241, 90, 241, 100, 243, 115, 243, 108,
+243, 109, 243, 96, 195, 245, 244, 243, 244, 254, 244, 251, 244, 232, 244, 234,
+246, 102, 197, 75, 246, 94, 247, 111, 248, 75, 197, 224, 198, 68, 249, 114,
+198, 113, 170, 248, 173, 172, 220, 122, 185, 104, 187, 213, 190, 91, 238, 243,
+238, 241, 236, 71, 243, 119, 246, 108, 170, 250, 203, 174, 168, 190, 205, 218,
+208, 198, 208, 194, 176, 165, 179, 173, 179, 178, 220, 125, 220, 126, 224, 209,
+187, 217, 192, 71, 193, 244, 176, 166, 182, 174, 187, 220, 194, 248, 171, 66,
+182, 179, 224, 215, 190, 95, 192, 76, 193, 247, 243, 126, 196, 197, 246, 111,
+198, 71, 171, 67, 192, 82, 192, 83, 220, 170, 228, 192, 228, 198, 232, 178,
+192, 84, 241, 161, 241, 121, 243, 163, 197, 183, 173, 179, 239, 66, 243, 166,
+173, 180, 236, 88, 179, 187, 185, 124, 228, 203, 232, 187, 190, 102, 236, 89,
+239, 69, 195, 68, 243, 170, 245, 79, 197, 227, 173, 183, 232, 190, 196, 66,
+246, 116, 173, 184, 216, 79, 182, 186, 224, 227, 187, 229, 192, 92, 192, 97,
+236, 92, 195, 75, 241, 174, 196, 67, 245, 84, 247, 119, 173, 186, 239, 87,
+249, 178, 224, 231, 187, 233, 232, 207, 190, 114, 190, 111, 236, 104, 239, 90,
+239, 97, 241, 177, 243, 192, 243, 190, 245, 96, 245, 91, 197, 91, 247, 125,
+247, 162, 248, 211, 249, 195, 176, 169, 232, 210, 239, 100, 245, 101, 197, 233,
+212, 73, 232, 212, 236, 110, 239, 103, 243, 194, 246, 163, 248, 85, 241, 190,
+236, 114, 228, 221, 239, 105, 246, 168, 228, 225, 232, 227, 232, 222, 236, 115,
+236, 124, 239, 106, 239, 113, 194, 65, 241, 201, 241, 197, 241, 202, 243, 202,
+196, 72, 245, 108, 245, 109, 245, 110, 246, 171, 246, 174, 247, 180, 247, 177,
+247, 170, 248, 89, 248, 218, 249, 90, 249, 120, 179, 190, 228, 226, 232, 236,
+232, 238, 236, 172, 192, 112, 236, 163, 239, 123, 194, 69, 239, 161, 241, 209,
+241, 213, 239, 120, 243, 221, 243, 235, 243, 233, 245, 125, 245, 167, 245, 121,
+197, 97, 246, 191, 246, 187, 246, 199, 197, 195, 248, 105, 248, 101, 247, 196,
+248, 229, 248, 228, 249, 124, 249, 207, 179, 191, 179, 192, 239, 171, 196, 83,
+197, 101, 228, 229, 196, 84, 190, 163, 239, 174, 232, 241, 194, 75, 245, 182,
+248, 118, 243, 245, 248, 120, 232, 243, 246, 208, 239, 178, 245, 185, 248, 122,
+247, 204, 241, 233, 243, 250, 245, 187, 197, 198, 248, 235, 249, 211, 192, 115,
+249, 213, 247, 207, 201, 74, 161, 74, 161, 104, 161, 124, 161, 201, 161, 125,
+161, 223, 161, 73, 161, 207, 162, 180, 161, 72, 162, 215, 162, 225, 161, 196,
+162, 241, 162, 251, 161, 98, 0
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5_Android.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5_Android.java
new file mode 100644
index 0000000..b1a71f0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_Big5_Android.java
@@ -0,0 +1,301 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_MultiByte_Big5_Android extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "Big5";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 167, 175, 176, 177, 183, 215, 247, 711, 713, 913, 933, 953, 8211, 8231, 8251,
+8364, 8451, 8544, 8592, 8725, 8745, 8786, 8806, 8853, 8895, 9472, 9492, 9516, 9552, 9572, 9601,
+9621, 9650, 9670, 9698, 9733, 9792, 12288, 12308, 12328, 12549, 12569, 12963, 13198, 13252, 19968, 19988,
+20011, 20034, 20054, 20083, 20104, 20126, 20147, 20167, 20188, 20208, 20228, 20248, 20268, 20289, 20309, 20329,
+20349, 20369, 20398, 20418, 20438, 20460, 20480, 20500, 20520, 20540, 20561, 20581, 20602, 20622, 20642, 20662,
+20682, 20704, 20725, 20745, 20767, 20787, 20807, 20827, 20849, 20871, 20894, 20918, 20938, 20958, 20979, 20999,
+21020, 21040, 21060, 21082, 21102, 21122, 21142, 21162, 21182, 21202, 21222, 21242, 21262, 21282, 21303, 21324,
+21344, 21365, 21386, 21406, 21426, 21448, 21471, 21491, 21511, 21531, 21552, 21573, 21600, 21620, 21640, 21664,
+21686, 21710, 21730, 21751, 21771, 21798, 21819, 21839, 21859, 21879, 21899, 21919, 21939, 21959, 21979, 21999,
+22020, 22043, 22063, 22085, 22105, 22125, 22145, 22165, 22186, 22206, 22227, 22247, 22271, 22291, 22312, 22334,
+22354, 22374, 22395, 22415, 22435, 22456, 22476, 22496, 22516, 22536, 22556, 22576, 22600, 22621, 22641, 22661,
+22684, 22705, 22725, 22745, 22767, 22787, 22807, 22827, 22848, 22868, 22889, 22909, 22930, 22950, 22970, 22990,
+23011, 23031, 23052, 23072, 23093, 23113, 23133, 23159, 23179, 23199, 23219, 23239, 23259, 23283, 23303, 23323,
+23343, 23363, 23383, 23403, 23423, 23443, 23463, 23487, 23507, 23527, 23553, 23573, 23594, 23614, 23636, 23656,
+23676, 23696, 23716, 23736, 23756, 23784, 23805, 23825, 23845, 23865, 23886, 23906, 23927, 23949, 23969, 23989,
+24009, 24029, 24049, 24070, 24090, 24115, 24138, 24159, 24179, 24199, 24219, 24240, 24260, 24280, 24300, 24321,
+24341, 24361, 24384, 24404, 24425, 24445, 24465, 24485, 24505, 24525, 24545, 24565, 24585, 24605, 24626, 24646,
+24666, 24686, 24707, 24727, 24752, 24772, 24792, 24816, 24836, 24856, 24876, 24896, 24916, 24936, 24956, 24976,
+24996, 25016, 25036, 25056, 25077, 25097, 25119, 25139, 25159, 25179, 25199, 25219, 25239, 25259, 25279, 25299,
+25323, 25343, 25363, 25384, 25404, 25424, 25445, 25466, 25486, 25506, 25533, 25554, 25575, 25606, 25626, 25646,
+25667, 25688, 25708, 25730, 25750, 25771, 25791, 25812, 25832, 25852, 25872, 25892, 25912, 25935, 25955, 25975,
+25996, 26016, 26038, 26059, 26079, 26099, 26119, 26140, 26161, 26181, 26201, 26222, 26244, 26264, 26286, 26308,
+26328, 26348, 26368, 26388, 26408, 26428, 26448, 26474, 26494, 26514, 26542, 26562, 26584, 26604, 26642, 26662,
+26682, 26702, 26731, 26751, 26771, 26791, 26820, 26840, 26860, 26884, 26917, 26937, 26958, 26978, 26998, 27021,
+27041, 27061, 27081, 27106, 27126, 27146, 27166, 27186, 27206, 27226, 27247, 27267, 27287, 27308, 27330, 27353,
+27374, 27394, 27414, 27436, 27457, 27477, 27498, 27518, 27540, 27562, 27583, 27603, 27623, 27643, 27663, 27683,
+27704, 27724, 27744, 27764, 27784, 27804, 27824, 27844, 27865, 27885, 27905, 27926, 27946, 27966, 27992, 28012,
+28032, 28052, 28074, 28094, 28114, 28134, 28154, 28185, 28205, 28225, 28245, 28265, 28296, 28316, 28336, 28356,
+28376, 28396, 28416, 28436, 28457, 28478, 28498, 28518, 28538, 28558, 28578, 28598, 28618, 28638, 28658, 28678,
+28698, 28719, 28739, 28759, 28779, 28802, 28822, 28843, 28869, 28889, 28911, 28932, 28953, 28974, 28994, 29014,
+29034, 29056, 29076, 29096, 29116, 29136, 29156, 29176, 29196, 29218, 29238, 29258, 29278, 29298, 29318, 29338,
+29358, 29378, 29398, 29418, 29438, 29458, 29478, 29498, 29518, 29538, 29558, 29578, 29599, 29619, 29639, 29659,
+29684, 29704, 29725, 29745, 29766, 29786, 29806, 29827, 29847, 29867, 29887, 29908, 29928, 29949, 29969, 29989,
+30009, 30030, 30050, 30070, 30090, 30114, 30134, 30154, 30174, 30194, 30216, 30236, 30256, 30278, 30298, 30318,
+30338, 30358, 30378, 30398, 30418, 30438, 30458, 30480, 30501, 30521, 30541, 30561, 30585, 30605, 30625, 30645,
+30665, 30686, 30706, 30726, 30749, 30769, 30789, 30812, 30832, 30852, 30872, 30892, 30913, 30933, 30953, 30973,
+30993, 31013, 31033, 31055, 31075, 31097, 31117, 31137, 31158, 31179, 31199, 31222, 31242, 31262, 31287, 31307,
+31327, 31348, 31368, 31390, 31410, 31431, 31455, 31478, 31498, 31518, 31538, 31558, 31584, 31604, 31624, 31644,
+31665, 31686, 31706, 31728, 31749, 31769, 31789, 31811, 31831, 31851, 31871, 31892, 31912, 31932, 31952, 31975,
+31995, 32015, 32040, 32060, 32080, 32102, 32122, 32142, 32162, 32183, 32203, 32223, 32243, 32264, 32284, 32304,
+32324, 32344, 32365, 32385, 32405, 32566, 32586, 32606, 32626, 32646, 32666, 32687, 32707, 32727, 32747, 32767,
+32788, 32808, 32829, 32849, 32871, 32893, 32914, 32937, 32962, 32982, 33005, 33025, 33045, 33065, 33085, 33105,
+33125, 33145, 33165, 33186, 33207, 33228, 33248, 33268, 33288, 33308, 33330, 33351, 33371, 33391, 33411, 33432,
+33452, 33472, 33492, 33512, 33534, 33558, 33578, 33599, 33619, 33651, 33671, 33691, 33711, 33731, 33751, 33771,
+33791, 33811, 33833, 33853, 33873, 33893, 33913, 33933, 33953, 33974, 33994, 34023, 34043, 34063, 34083, 34107,
+34129, 34149, 34169, 34189, 34209, 34229, 34249, 34269, 34289, 34309, 34329, 34349, 34371, 34393, 34413, 34437,
+34457, 34479, 34499, 34519, 34539, 34560, 34584, 34604, 34624, 34644, 34664, 34689, 34710, 34730, 34750, 34770,
+34790, 34810, 34832, 34852, 34872, 34892, 34913, 34933, 34953, 34974, 34994, 35017, 35037, 35057, 35077, 35097,
+35117, 35137, 35158, 35178, 35198, 35219, 35242, 35262, 35282, 35302, 35322, 35342, 35362, 35382, 35402, 35422,
+35442, 35462, 35482, 35504, 35524, 35544, 35565, 35585, 35605, 35626, 35646, 35666, 35686, 35706, 35726, 35895,
+35915, 35935, 35955, 35977, 35997, 36018, 36039, 36060, 36080, 36100, 36121, 36196, 36216, 36236, 36256, 36276,
+36296, 36316, 36336, 36356, 36376, 36398, 36418, 36438, 36458, 36481, 36501, 36521, 36541, 36561, 36581, 36601,
+36621, 36643, 36663, 36683, 36703, 36763, 36783, 36804, 36832, 36852, 36875, 36895, 36916, 36937, 36957, 36978,
+36998, 37019, 37039, 37059, 37079, 37099, 37119, 37140, 37160, 37182, 37202, 37224, 37248, 37273, 37293, 37313,
+37333, 37353, 37373, 37393, 37413, 37433, 37453, 37473, 37494, 37514, 37536, 37556, 37576, 37597, 37617, 37638,
+37658, 37678, 37702, 37722, 37744, 37768, 37789, 37809, 37831, 37852, 37877, 37897, 37920, 37941, 37961, 37981,
+38001, 38263, 38283, 38303, 38325, 38345, 38366, 38428, 38448, 38468, 38488, 38508, 38528, 38548, 38568, 38588,
+38610, 38632, 38653, 38673, 38693, 38713, 38738, 38758, 38778, 38798, 38818, 38838, 38859, 38879, 38899, 38919,
+38939, 38959, 38979, 38999, 39019, 39080, 39100, 39131, 39151, 39171, 39191, 39211, 39231, 39251, 39318, 39339,
+39361, 39381, 39401, 39421, 39441, 39461, 39481, 39501, 39522, 39592, 39612, 39632, 39654, 39674, 39694, 39714,
+39735, 39755, 39775, 39796, 39816, 39838, 39861, 39881, 39902, 39927, 39947, 39969, 39990, 40010, 40030, 40051,
+40165, 40185, 40208, 40229, 40251, 40271, 40295, 40315, 40336, 40356, 40376, 40396, 40417, 40437, 40457, 40477,
+40565, 40585, 40605, 40628, 40648, 40668, 40688, 40710, 40730, 40750, 40770, 40790, 40810, 40830, 40850, 57344,
+57364, 57384, 57404, 57424, 57444, 57464, 57484, 57504, 57524, 57544, 57564, 57584, 57604, 57624, 57644, 57664,
+57684, 57704, 57724, 57744, 57764, 57784, 57804, 57824, 57844, 57864, 57884, 57904, 57924, 57944, 57964, 57984,
+58004, 58024, 58044, 58064, 58084, 58104, 58124, 58144, 58164, 58184, 58204, 58224, 58244, 58264, 58284, 58304,
+58324, 58344, 58364, 58384, 58404, 58424, 58444, 58464, 58484, 58504, 58524, 58544, 58564, 58584, 58604, 58624,
+58644, 58664, 58684, 58704, 58724, 58744, 58764, 58784, 58804, 58824, 58844, 58864, 58884, 58904, 58924, 58944,
+58964, 58984, 59004, 59024, 59044, 59064, 59084, 59104, 59124, 59144, 59164, 59184, 59204, 59224, 59244, 59264,
+59284, 59304, 59324, 59344, 59364, 59384, 59404, 59424, 59444, 59464, 59484, 59504, 59524, 59544, 59564, 59584,
+59604, 59624, 59644, 59664, 59684, 59704, 59724, 59744, 59764, 59784, 59804, 59824, 59844, 59864, 59884, 59904,
+59924, 59944, 59964, 59984, 60004, 60024, 60044, 60064, 60084, 60104, 60124, 60144, 60164, 60184, 60204, 60224,
+60244, 60264, 60284, 60304, 60324, 60344, 60364, 60384, 60404, 60424, 60444, 60464, 60484, 60504, 60524, 60544,
+60564, 60584, 60604, 60624, 60644, 60664, 60684, 60704, 60724, 60744, 60764, 60784, 60804, 60824, 60844, 60864,
+60884, 60904, 60924, 60944, 60964, 60984, 61004, 61024, 61044, 61064, 61084, 61104, 61124, 61144, 61164, 61184,
+61204, 61224, 61244, 61264, 61284, 61304, 61324, 61344, 61364, 61384, 61404, 61424, 61444, 61464, 61484, 61504,
+61524, 61544, 61564, 61584, 61604, 61624, 61644, 61664, 61684, 61704, 61724, 61744, 61764, 61784, 61804, 61824,
+61844, 61864, 61884, 61904, 61924, 61944, 61964, 61984, 62004, 62024, 62044, 62064, 62084, 62104, 62124, 62144,
+62164, 62184, 62204, 62224, 62244, 62264, 62284, 62304, 62324, 62344, 62364, 62384, 62404, 62424, 62444, 62464,
+62484, 62504, 62524, 62544, 62564, 62584, 62604, 62624, 62644, 62664, 62684, 62704, 62724, 62744, 62764, 62784,
+62804, 62824, 62844, 62864, 62884, 62904, 62924, 62944, 62964, 62984, 63004, 63024, 63044, 63064, 63084, 63104,
+63124, 63144, 63164, 63184, 63204, 63224, 63244, 63264, 63284, 63304, 63324, 63344, 63364, 63384, 63404, 63424,
+63444, 63464, 63484, 63504, 63524, 63544, 63736, 64012, 65072, 65092, 65113, 65281, 65301, 65321, 65343, 65363,
+65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 161, 177, 161, 194, 162, 88, 161, 211, 161, 80, 161, 209, 161, 210, 163,
+190, 163, 188, 163, 68, 163, 87, 163, 100, 161, 86, 161, 69, 161, 176, 163,
+225, 162, 74, 162, 185, 161, 246, 162, 65, 161, 228, 161, 220, 161, 216, 161,
+242, 161, 233, 162, 119, 162, 124, 162, 115, 249, 249, 249, 231, 162, 98, 162,
+121, 161, 182, 161, 187, 162, 168, 161, 185, 161, 240, 161, 64, 161, 101, 162,
+202, 163, 116, 163, 170, 161, 192, 162, 85, 162, 87, 164, 64, 165, 66, 164,
+88, 201, 64, 168, 196, 168, 197, 164, 169, 168, 200, 173, 189, 164, 179, 201,
+102, 165, 245, 201, 185, 201, 172, 201, 173, 202, 100, 166, 243, 168, 216, 203,
+181, 168, 221, 171, 86, 171, 89, 205, 235, 205, 239, 173, 206, 173, 207, 173,
+208, 173, 200, 212, 103, 176, 183, 176, 175, 216, 89, 179, 195, 220, 195, 220,
+185, 224, 254, 187, 248, 187, 252, 192, 118, 195, 95, 165, 251, 162, 90, 166,
+64, 201, 78, 203, 205, 167, 77, 208, 225, 232, 249, 185, 185, 164, 193, 202,
+108, 168, 236, 205, 240, 208, 231, 212, 108, 185, 187, 241, 237, 167, 86, 168,
+240, 176, 199, 182, 211, 164, 99, 208, 238, 201, 193, 243, 253, 201, 109, 165,
+101, 167, 90, 201, 196, 208, 239, 188, 70, 164, 83, 173, 238, 165, 107, 201,
+197, 167, 103, 202, 118, 202, 122, 203, 235, 203, 230, 203, 224, 206, 72, 206,
+69, 171, 117, 208, 241, 209, 66, 209, 71, 208, 240, 212, 168, 176, 221, 176,
+229, 216, 106, 179, 227, 179, 231, 179, 229, 182, 222, 220, 203, 182, 226, 225,
+83, 185, 192, 188, 83, 216, 107, 190, 178, 233, 67, 236, 201, 194, 80, 241,
+244, 245, 198, 248, 165, 202, 168, 171, 170, 182, 234, 166, 98, 167, 163, 202,
+175, 169, 90, 203, 251, 206, 90, 171, 174, 209, 82, 209, 74, 176, 240, 212,
+178, 212, 182, 216, 169, 179, 247, 216, 167, 220, 235, 220, 241, 185, 214, 188,
+89, 229, 76, 190, 195, 194, 82, 167, 167, 201, 90, 201, 112, 164, 210, 202,
+177, 169, 98, 185, 221, 166, 110, 167, 170, 202, 178, 204, 69, 204, 71, 171,
+187, 206, 110, 174, 91, 174, 87, 212, 212, 176, 251, 212, 222, 180, 64, 216,
+199, 216, 183, 183, 64, 220, 243, 225, 118, 225, 115, 229, 94, 233, 83, 236,
+213, 196, 93, 166, 114, 174, 93, 197, 112, 204, 87, 209, 102, 177, 74, 180,
+74, 185, 231, 171, 202, 201, 212, 202, 191, 167, 192, 209, 107, 192, 171, 201,
+214, 167, 193, 204, 92, 169, 164, 206, 123, 174, 111, 174, 108, 177, 88, 212,
+253, 216, 234, 216, 225, 221, 86, 225, 169, 225, 175, 229, 107, 233, 98, 196,
+96, 164, 116, 164, 118, 166, 124, 169, 170, 177, 98, 221, 90, 188, 109, 165,
+173, 167, 200, 206, 184, 206, 181, 180, 92, 225, 181, 195, 102, 165, 175, 164,
+222, 169, 184, 221, 98, 204, 116, 177, 109, 204, 119, 174, 124, 216, 246, 185,
+253, 167, 212, 202, 221, 169, 192, 204, 175, 171, 228, 204, 125, 171, 237, 209,
+125, 206, 209, 209, 168, 209, 171, 213, 85, 216, 253, 177, 166, 180, 107, 217,
+79, 217, 75, 225, 194, 221, 113, 225, 206, 180, 110, 188, 161, 188, 166, 188,
+171, 233, 162, 233, 125, 236, 227, 195, 106, 201, 124, 180, 117, 194, 87, 174,
+176, 166, 170, 167, 232, 202, 231, 167, 220, 169, 220, 169, 215, 169, 221, 206,
+218, 174, 179, 206, 225, 174, 193, 209, 189, 174, 189, 213, 103, 177, 204, 213,
+113, 177, 180, 213, 107, 180, 161, 221, 183, 183, 112, 221, 178, 221, 185, 221,
+162, 186, 75, 225, 239, 225, 230, 229, 175, 188, 190, 190, 223, 190, 225, 236,
+237, 239, 215, 242, 67, 197, 117, 167, 241, 177, 211, 180, 178, 188, 197, 217,
+121, 225, 245, 236, 240, 177, 219, 244, 79, 202, 250, 170, 64, 206, 239, 172,
+82, 174, 207, 213, 172, 180, 182, 183, 121, 183, 122, 188, 199, 190, 231, 239,
+220, 197, 206, 179, 204, 174, 210, 164, 236, 201, 245, 167, 247, 170, 87, 170,
+81, 204, 214, 207, 91, 207, 81, 207, 67, 172, 90, 209, 236, 209, 238, 209,
+242, 209, 232, 213, 196, 177, 236, 177, 234, 177, 239, 177, 243, 180, 198, 217,
+175, 217, 172, 217, 216, 221, 210, 221, 204, 221, 205, 221, 229, 226, 74, 226,
+90, 226, 96, 225, 254, 229, 213, 229, 235, 188, 212, 188, 207, 233, 194, 233,
+221, 233, 203, 233, 212, 237, 65, 192, 208, 194, 99, 194, 103, 242, 80, 244,
+89, 245, 206, 198, 86, 209, 245, 221, 250, 233, 222, 172, 110, 204, 235, 217,
+222, 233, 226, 183, 181, 183, 182, 210, 67, 221, 253, 164, 243, 174, 240, 165,
+195, 202, 64, 166, 192, 168, 88, 168, 72, 203, 88, 205, 75, 170, 110, 204,
+242, 204, 253, 207, 161, 210, 100, 172, 120, 172, 163, 210, 76, 175, 64, 210,
+98, 175, 75, 178, 101, 213, 240, 178, 89, 178, 104, 178, 76, 181, 65, 180,
+244, 217, 243, 218, 81, 181, 70, 217, 236, 183, 200, 222, 85, 183, 201, 222,
+93, 186, 173, 230, 83, 186, 116, 186, 120, 186, 121, 230, 77, 188, 227, 188,
+235, 188, 234, 234, 64, 191, 71, 233, 244, 237, 87, 237, 88, 194, 112, 195,
+118, 244, 93, 245, 211, 246, 234, 164, 245, 205, 88, 205, 87, 172, 175, 210,
+119, 175, 79, 178, 109, 214, 79, 181, 72, 218, 92, 222, 119, 183, 220, 222,
+117, 226, 189, 186, 178, 188, 247, 234, 85, 191, 77, 237, 96, 194, 119, 242,
+105, 247, 230, 164, 247, 207, 185, 202, 66, 172, 185, 218, 106, 230, 116, 201,
+165, 168, 103, 205, 92, 207, 195, 210, 166, 218, 109, 218, 118, 222, 173, 188,
+250, 230, 161, 239, 254, 201, 167, 170, 179, 172, 197, 207, 209, 210, 181, 214,
+120, 214, 121, 218, 167, 218, 164, 222, 188, 183, 228, 226, 212, 188, 254, 237,
+102, 237, 104, 194, 123, 196, 237, 205, 111, 222, 194, 237, 112, 181, 99, 203,
+110, 172, 202, 178, 166, 183, 237, 197, 124, 172, 207, 210, 201, 178, 172, 181,
+108, 183, 242, 226, 219, 230, 179, 234, 115, 192, 247, 240, 80, 197, 125, 168,
+109, 181, 112, 244, 113, 244, 114, 178, 176, 234, 117, 207, 231, 210, 207, 214,
+176, 214, 168, 218, 189, 186, 206, 184, 64, 230, 188, 234, 120, 237, 122, 242,
+121, 218, 195, 244, 120, 207, 234, 175, 124, 210, 229, 214, 186, 218, 200, 218,
+205, 222, 232, 184, 75, 226, 245, 186, 207, 189, 87, 234, 163, 237, 166, 240,
+93, 244, 121, 248, 250, 210, 232, 214, 192, 222, 246, 186, 215, 230, 204, 248,
+183, 172, 238, 175, 178, 214, 198, 218, 215, 184, 92, 189, 94, 191, 114, 240,
+96, 165, 222, 175, 183, 223, 68, 230, 211, 196, 117, 179, 186, 196, 118, 211,
+69, 178, 199, 214, 218, 181, 167, 184, 97, 223, 73, 227, 78, 227, 79, 189,
+99, 189, 102, 234, 189, 237, 203, 237, 186, 240, 99, 240, 102, 196, 120, 246,
+250, 248, 252, 208, 71, 214, 222, 218, 233, 227, 96, 234, 202, 194, 179, 168,
+116, 211, 89, 214, 240, 178, 209, 181, 178, 181, 185, 223, 93, 223, 94, 186,
+247, 227, 99, 227, 110, 230, 240, 229, 114, 191, 162, 234, 212, 237, 220, 237,
+223, 240, 113, 195, 181, 244, 174, 247, 238, 166, 206, 242, 186, 211, 93, 184,
+112, 242, 188, 178, 220, 189, 126, 211, 99, 219, 68, 230, 246, 244, 177, 208,
+84, 191, 174, 175, 212, 219, 69, 230, 252, 197, 165, 203, 119, 170, 211, 208,
+91, 173, 68, 175, 218, 211, 109, 215, 78, 178, 231, 219, 79, 181, 198, 184,
+123, 184, 161, 227, 168, 231, 66, 234, 242, 237, 234, 249, 67, 173, 80, 191,
+179, 181, 207, 215, 87, 184, 165, 237, 240, 168, 125, 203, 162, 205, 182, 170,
+226, 205, 179, 173, 97, 208, 111, 208, 108, 211, 168, 211, 164, 211, 122, 211,
+177, 215, 94, 215, 119, 215, 108, 215, 113, 219, 167, 219, 172, 219, 106, 219,
+113, 219, 166, 223, 199, 184, 168, 223, 177, 223, 176, 223, 173, 223, 175, 227,
+174, 227, 203, 187, 99, 231, 115, 231, 88, 231, 78, 189, 177, 231, 77, 235,
+70, 235, 86, 238, 82, 238, 74, 238, 67, 240, 170, 194, 199, 195, 192, 242,
+199, 244, 193, 245, 247, 196, 245, 248, 188, 215, 123, 205, 201, 211, 196, 211,
+198, 179, 76, 215, 174, 219, 189, 219, 185, 184, 190, 187, 106, 227, 224, 227,
+217, 231, 168, 189, 190, 235, 97, 235, 98, 238, 89, 238, 88, 193, 175, 240,
+188, 242, 220, 244, 197, 246, 68, 248, 189, 166, 230, 191, 197, 211, 210, 215,
+178, 179, 79, 219, 205, 219, 207, 184, 203, 227, 247, 231, 194, 231, 200, 235,
+115, 238, 117, 195, 205, 196, 251, 202, 80, 179, 86, 191, 203, 247, 84, 168,
+164, 224, 68, 246, 76, 176, 81, 179, 96, 182, 70, 219, 226, 181, 252, 184,
+211, 224, 70, 187, 166, 189, 214, 189, 206, 231, 224, 191, 217, 191, 214, 238,
+169, 240, 218, 240, 227, 243, 66, 196, 181, 246, 80, 248, 65, 168, 166, 224,
+83, 219, 229, 193, 199, 184, 232, 168, 169, 184, 237, 184, 234, 189, 231, 235,
+183, 240, 244, 248, 69, 168, 170, 211, 228, 224, 95, 231, 239, 173, 119, 219,
+249, 219, 245, 224, 103, 228, 99, 232, 66, 231, 247, 191, 228, 240, 251, 243,
+82, 196, 188, 247, 93, 249, 171, 235, 200, 211, 232, 220, 67, 220, 64, 228,
+103, 232, 76, 235, 206, 241, 73, 197, 70, 168, 175, 197, 71, 168, 180, 208,
+182, 176, 106, 215, 227, 179, 116, 220, 78, 224, 162, 187, 190, 191, 240, 235,
+211, 202, 84, 205, 213, 173, 168, 211, 251, 215, 239, 220, 83, 224, 169, 241,
+74, 241, 77, 176, 115, 221, 115, 232, 97, 238, 200, 243, 95, 198, 93, 212,
+66, 179, 171, 220, 109, 182, 122, 220, 100, 185, 101, 185, 99, 224, 193, 228,
+120, 228, 176, 228, 123, 232, 164, 232, 116, 232, 110, 232, 105, 235, 225, 191,
+254, 192, 68, 235, 234, 193, 237, 193, 236, 241, 96, 241, 88, 241, 100, 243,
+97, 195, 237, 244, 243, 244, 251, 244, 234, 197, 75, 247, 111, 248, 76, 249,
+85, 170, 248, 182, 125, 224, 205, 236, 77, 238, 240, 245, 69, 170, 250, 203,
+173, 170, 254, 176, 164, 179, 181, 220, 163, 185, 106, 192, 72, 212, 71, 187,
+220, 171, 66, 224, 215, 192, 76, 241, 120, 197, 82, 171, 67, 192, 83, 228,
+192, 232, 178, 241, 161, 243, 163, 173, 179, 243, 166, 173, 181, 220, 172, 232,
+188, 236, 90, 239, 74, 243, 170, 197, 184, 173, 183, 196, 66, 173, 184, 182,
+186, 187, 229, 232, 196, 239, 76, 195, 73, 245, 89, 173, 186, 249, 178, 187,
+233, 190, 114, 236, 104, 239, 96, 241, 180, 243, 182, 246, 120, 197, 187, 198,
+106, 176, 169, 192, 102, 247, 164, 187, 236, 236, 111, 243, 196, 198, 75, 243,
+198, 241, 194, 228, 225, 232, 219, 236, 162, 239, 108, 241, 200, 195, 85, 243,
+202, 245, 108, 245, 106, 246, 177, 247, 182, 248, 90, 248, 218, 249, 120, 179,
+190, 232, 235, 236, 172, 236, 163, 194, 69, 241, 209, 239, 120, 243, 235, 245,
+125, 245, 121, 197, 100, 246, 197, 248, 105, 247, 196, 248, 228, 249, 207, 179,
+191, 239, 171, 197, 101, 196, 84, 239, 174, 194, 74, 247, 200, 248, 120, 246,
+208, 245, 185, 247, 204, 243, 250, 197, 198, 249, 211, 246, 213, 250, 64, 250,
+84, 250, 104, 250, 124, 250, 178, 250, 198, 250, 218, 250, 238, 251, 67, 251,
+87, 251, 107, 251, 161, 251, 181, 251, 201, 251, 221, 251, 241, 252, 70, 252,
+90, 252, 110, 252, 164, 252, 184, 252, 204, 252, 224, 252, 244, 253, 73, 253,
+93, 253, 113, 253, 167, 253, 187, 253, 207, 253, 227, 253, 247, 254, 76, 254,
+96, 254, 116, 254, 170, 254, 190, 254, 210, 254, 230, 254, 250, 142, 79, 142,
+99, 142, 119, 142, 173, 142, 193, 142, 213, 142, 233, 142, 253, 143, 82, 143,
+102, 143, 122, 143, 176, 143, 196, 143, 216, 143, 236, 144, 65, 144, 85, 144,
+105, 144, 125, 144, 179, 144, 199, 144, 219, 144, 239, 145, 68, 145, 88, 145,
+108, 145, 162, 145, 182, 145, 202, 145, 222, 145, 242, 146, 71, 146, 91, 146,
+111, 146, 165, 146, 185, 146, 205, 146, 225, 146, 245, 147, 74, 147, 94, 147,
+114, 147, 168, 147, 188, 147, 208, 147, 228, 147, 248, 148, 77, 148, 97, 148,
+117, 148, 171, 148, 191, 148, 211, 148, 231, 148, 251, 149, 80, 149, 100, 149,
+120, 149, 174, 149, 194, 149, 214, 149, 234, 149, 254, 150, 83, 150, 103, 150,
+123, 150, 177, 150, 197, 150, 217, 150, 237, 151, 66, 151, 86, 151, 106, 151,
+126, 151, 180, 151, 200, 151, 220, 151, 240, 152, 69, 152, 89, 152, 109, 152,
+163, 152, 183, 152, 203, 152, 223, 152, 243, 153, 72, 153, 92, 153, 112, 153,
+166, 153, 186, 153, 206, 153, 226, 153, 246, 154, 75, 154, 95, 154, 115, 154,
+169, 154, 189, 154, 209, 154, 229, 154, 249, 155, 78, 155, 98, 155, 118, 155,
+172, 155, 192, 155, 212, 155, 232, 155, 252, 156, 81, 156, 101, 156, 121, 156,
+175, 156, 195, 156, 215, 156, 235, 157, 64, 157, 84, 157, 104, 157, 124, 157,
+178, 157, 198, 157, 218, 157, 238, 158, 67, 158, 87, 158, 107, 158, 161, 158,
+181, 158, 201, 158, 221, 158, 241, 159, 70, 159, 90, 159, 110, 159, 164, 159,
+184, 159, 204, 159, 224, 159, 244, 160, 73, 160, 93, 160, 113, 160, 167, 160,
+187, 160, 207, 160, 227, 160, 247, 129, 76, 129, 96, 129, 116, 129, 170, 129,
+190, 129, 210, 129, 230, 129, 250, 130, 79, 130, 99, 130, 119, 130, 173, 130,
+193, 130, 213, 130, 233, 130, 253, 131, 82, 131, 102, 131, 122, 131, 176, 131,
+196, 131, 216, 131, 236, 132, 65, 132, 85, 132, 105, 132, 125, 132, 179, 132,
+199, 132, 219, 132, 239, 133, 68, 133, 88, 133, 108, 133, 162, 133, 182, 133,
+202, 133, 222, 133, 242, 134, 71, 134, 91, 134, 111, 134, 165, 134, 185, 134,
+205, 134, 225, 134, 245, 135, 74, 135, 94, 135, 114, 135, 168, 135, 188, 135,
+208, 135, 228, 135, 248, 136, 77, 136, 97, 136, 117, 136, 171, 136, 191, 136,
+211, 136, 231, 136, 251, 137, 80, 137, 100, 137, 120, 137, 174, 137, 194, 137,
+214, 137, 234, 137, 254, 138, 83, 138, 103, 138, 123, 138, 177, 138, 197, 138,
+217, 138, 237, 139, 66, 139, 86, 139, 106, 139, 126, 139, 180, 139, 200, 139,
+220, 139, 240, 140, 69, 140, 89, 140, 109, 140, 163, 140, 183, 140, 203, 140,
+223, 140, 243, 141, 72, 141, 92, 141, 112, 141, 166, 141, 186, 141, 206, 141,
+226, 141, 246, 198, 172, 198, 192, 198, 212, 198, 232, 198, 252, 199, 81, 199,
+101, 199, 121, 199, 175, 199, 195, 199, 215, 199, 235, 200, 64, 200, 84, 200,
+104, 200, 124, 200, 178, 200, 198, 200, 218, 200, 238, 255, 201, 74, 161, 74,
+161, 124, 161, 125, 161, 73, 162, 180, 162, 215, 161, 196, 162, 251, 162, 70
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP.java
new file mode 100644
index 0000000..2e7fcc2
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP.java
@@ -0,0 +1,525 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CodingErrorAction;
+
+/** @hide
+ * SEE correspondig_Android test class:
+ */
+
+public class OldCharset_MultiByte_EUC_JP extends OldCharset_AbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "EUC-JP";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 162, 163, 164, /*165,*/ 166, 167, 168, 169, 170, 172, 174, 175, 176, 177, 180,
+182, 184, 186, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
+204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
+221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
+237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
+253, 254, 255, 256, 266, 278, 288, 298, 308, 318, 328, 338, 348, 358, 368, 378,
+461, 471, 501, 711, 728, 900, 910, 920, 931, 941, 951, 961, 971, 1025, 1035, 1045,
+1055, 1065, 1075, 1085, 1095, 1105, 1115, 8208, 8220, 8230, 8240, 8251, 8451, 8470, 8482, 8592,
+8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472, 9484, 9495, 9507,
+9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298, 12308, 12353, 12363,
+12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523,
+12533, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20039, 20049, 20060, 20072, 20083, 20094, 20104, 20114,
+20124, 20134, 20144, 20154, 20164, 20174, 20184, 20194, 20205, 20215, 20225, 20235, 20245, 20270, 20280, 20290,
+20300, 20310, 20320, 20330, 20341, 20351, 20361, 20371, 20381, 20395, 20405, 20415, 20425, 20436, 20447, 20462,
+20472, 20484, 20494, 20504, 20514, 20524, 20534, 20544, 20554, 20565, 20575, 20586, 20596, 20608, 20618, 20628,
+20638, 20650, 20660, 20670, 20681, 20691, 20701, 20711, 20721, 20731, 20742, 20752, 20762, 20775, 20785, 20795,
+20805, 20815, 20826, 20836, 20846, 20856, 20866, 20876, 20886, 20896, 20906, 20916, 20926, 20936, 20946, 20956,
+20966, 20976, 20986, 20996, 21006, 21016, 21026, 21038, 21048, 21059, 21069, 21079, 21089, 21102, 21112, 21122,
+21132, 21142, 21152, 21162, 21172, 21182, 21192, 21202, 21212, 21222, 21232, 21242, 21253, 21263, 21273, 21283,
+21293, 21304, 21314, 21324, 21335, 21345, 21356, 21367, 21378, 21390, 21400, 21412, 21422, 21432, 21442, 21452,
+21462, 21472, 21482, 21493, 21505, 21515, 21530, 21542, 21553, 21563, 21574, 21585, 21598, 21608, 21619, 21629,
+21640, 21650, 21660, 21670, 21681, 21691, 21702, 21720, 21730, 21740, 21750, 21760, 21772, 21782, 21802, 21813,
+21824, 21834, 21846, 21856, 21883, 21894, 21905, 21916, 21927, 21938, 21951, 21961, 21971, 21982, 21993, 22006,
+22021, 22031, 22041, 22057, 22067, 22077, 22089, 22100, 22110, 22120, 22130, 22144, 22154, 22164, 22174, 22184,
+22195, 22206, 22216, 22227, 22237, 22247, 22257, 22269, 22279, 22289, 22299, 22309, 22319, 22331, 22341, 22351,
+22369, 22379, 22389, 22399, 22409, 22419, 22429, 22439, 22451, 22461, 22471, 22482, 22492, 22502, 22512, 22522,
+22532, 22549, 22559, 22570, 22580, 22591, 22601, 22612, 22622, 22632, 22642, 22652, 22663, 22675, 22685, 22696,
+22706, 22716, 22727, 22737, 22748, 22761, 22771, 22781, 22793, 22803, 22813, 22823, 22833, 22846, 22856, 22866,
+22877, 22887, 22898, 22908, 22922, 22933, 22943, 22956, 22967, 22977, 22987, 23001, 23011, 23022, 23035, 23049,
+23059, 23070, 23080, 23093, 23104, 23116, 23130, 23141, 23159, 23179, 23190, 23200, 23212, 23224, 23234, 23244,
+23254, 23264, 23274, 23285, 23296, 23307, 23318, 23329, 23340, 23350, 23360, 23371, 23381, 23391, 23401, 23411,
+23421, 23431, 23441, 23451, 23461, 23471, 23481, 23491, 23501, 23511, 23521, 23531, 23541, 23551, 23561, 23571,
+23582, 23592, 23602, 23612, 23622, 23632, 23642, 23652, 23662, 23673, 23687, 23697, 23709, 23720, 23730, 23740,
+23751, 23762, 23773, 23784, 23794, 23805, 23815, 23825, 23835, 23846, 23857, 23869, 23880, 23890, 23900, 23913,
+23923, 23934, 23944, 23954, 23965, 23975, 23986, 23996, 24007, 24018, 24029, 24039, 24049, 24059, 24070, 24081,
+24091, 24101, 24111, 24125, 24135, 24145, 24155, 24168, 24178, 24188, 24199, 24213, 24224, 24234, 24245, 24255,
+24265, 24275, 24285, 24296, 24307, 24318, 24328, 24339, 24349, 24359, 24369, 24379, 24389, 24400, 24411, 24422,
+24432, 24442, 24452, 24463, 24473, 24484, 24494, 24504, 24515, 24525, 24535, 24545, 24555, 24565, 24575, 24586,
+24596, 24607, 24617, 24627, 24640, 24650, 24660, 24671, 24681, 24693, 24703, 24713, 24723, 24733, 24743, 24753,
+24763, 24773, 24783, 24793, 24803, 24816, 24826, 24838, 24848, 24858, 24871, 24881, 24892, 24902, 24915, 24925,
+24935, 24945, 24955, 24967, 24977, 24988, 24999, 25010, 25020, 25030, 25040, 25052, 25062, 25074, 25084, 25095,
+25105, 25115, 25126, 25136, 25147, 25158, 25168, 25178, 25188, 25198, 25209, 25219, 25229, 25239, 25254, 25265,
+25275, 25285, 25295, 25305, 25322, 25332, 25342, 25352, 25363, 25375, 25385, 25397, 25407, 25417, 25427, 25445,
+25457, 25467, 25479, 25490, 25502, 25512, 25522, 25533, 25544, 25554, 25564, 25577, 25587, 25606, 25616, 25628,
+25638, 25648, 25658, 25675, 25688, 25699, 25709, 25720, 25731, 25743, 25753, 25763, 25773, 25785, 25796, 25806,
+25816, 25826, 25836, 25846, 25856, 25866, 25876, 25886, 25897, 25908, 25918, 25928, 25938, 25949, 25959, 25970,
+25981, 25991, 26001, 26011, 26021, 26031, 26041, 26051, 26062, 26072, 26082, 26092, 26105, 26115, 26125, 26140,
+26150, 26160, 26172, 26182, 26193, 26203, 26214, 26224, 26234, 26244, 26254, 26264, 26274, 26285, 26296, 26306,
+26316, 26326, 26336, 26347, 26357, 26367, 26377, 26387, 26397, 26407, 26417, 26429, 26439, 26449, 26460, 26470,
+26480, 26491, 26501, 26511, 26521, 26534, 26544, 26555, 26565, 26575, 26585, 26596, 26606, 26617, 26627, 26643,
+26653, 26663, 26673, 26683, 26693, 26704, 26715, 26727, 26737, 26747, 26757, 26767, 26778, 26789, 26799, 26809,
+26820, 26831, 26841, 26851, 26861, 26873, 26884, 26894, 26905, 26915, 26928, 26939, 26949, 26963, 26973, 26984,
+26994, 27004, 27018, 27028, 27040, 27051, 27063, 27073, 27083, 27094, 27106, 27117, 27129, 27139, 27151, 27161,
+27171, 27182, 27192, 27204, 27214, 27224, 27234, 27249, 27262, 27273, 27287, 27298, 27308, 27320, 27330, 27340,
+27350, 27364, 27376, 27386, 27396, 27407, 27419, 27431, 27442, 27453, 27463, 27474, 27485, 27495, 27507, 27517,
+27529, 27541, 27551, 27561, 27571, 27581, 27593, 27603, 27615, 27627, 27639, 27650, 27661, 27671, 27683, 27694,
+27704, 27714, 27725, 27735, 27746, 27757, 27768, 27778, 27788, 27798, 27809, 27819, 27832, 27842, 27852, 27862,
+27872, 27882, 27892, 27908, 27918, 27929, 27941, 27951, 27961, 27972, 27991, 28001, 28012, 28023, 28034, 28044,
+28054, 28074, 28084, 28095, 28106, 28117, 28127, 28137, 28147, 28160, 28170, 28181, 28191, 28201, 28214, 28227,
+28237, 28247, 28258, 28270, 28283, 28300, 28310, 28320, 28330, 28342, 28352, 28362, 28372, 28382, 28395, 28407,
+28417, 28428, 28438, 28448, 28458, 28470, 28481, 28495, 28505, 28516, 28526, 28536, 28546, 28556, 28566, 28576,
+28586, 28597, 28608, 28618, 28628, 28638, 28648, 28659, 28669, 28679, 28689, 28699, 28710, 28720, 28732, 28744,
+28756, 28766, 28779, 28789, 28801, 28814, 28824, 28836, 28846, 28856, 28872, 28883, 28893, 28913, 28925, 28935,
+28948, 28958, 28971, 28982, 28993, 29003, 29013, 29024, 29036, 29049, 29060, 29071, 29081, 29096, 29106, 29118,
+29128, 29138, 29148, 29158, 29173, 29183, 29193, 29203, 29213, 29224, 29234, 29244, 29254, 29264, 29274, 29287,
+29297, 29307, 29319, 29330, 29344, 29356, 29366, 29377, 29388, 29398, 29408, 29420, 29431, 29442, 29453, 29463,
+29474, 29484, 29494, 29507, 29517, 29527, 29539, 29550, 29560, 29571, 29582, 29592, 29602, 29613, 29623, 29634,
+29644, 29654, 29664, 29674, 29684, 29694, 29705, 29722, 29732, 29742, 29753, 29763, 29773, 29783, 29794, 29805,
+29822, 29833, 29848, 29858, 29870, 29881, 29896, 29907, 29918, 29928, 29938, 29948, 29958, 29969, 29980, 29990,
+30000, 30010, 30020, 30030, 30041, 30052, 30063, 30073, 30085, 30095, 30105, 30115, 30129, 30140, 30150, 30162,
+30172, 30183, 30193, 30204, 30215, 30226, 30236, 30246, 30256, 30266, 30276, 30290, 30300, 30311, 30321, 30331,
+30341, 30352, 30362, 30372, 30382, 30392, 30402, 30412, 30422, 30432, 30442, 30452, 30462, 30472, 30482, 30492,
+30502, 30516, 30526, 30538, 30550, 30560, 30570, 30580, 30590, 30603, 30613, 30623, 30634, 30645, 30655, 30665,
+30677, 30687, 30697, 30707, 30722, 30732, 30749, 30759, 30770, 30783, 30796, 30812, 30824, 30834, 30844, 30854,
+30865, 30877, 30887, 30897, 30907, 30917, 30928, 30938, 30948, 30959, 30970, 30982, 30992, 31002, 31013, 31025,
+31035, 31045, 31055, 31066, 31077, 31090, 31100, 31114, 31124, 31137, 31147, 31160, 31170, 31183, 31194, 31204,
+31216, 31227, 31239, 31249, 31259, 31271, 31281, 31291, 31301, 31311, 31321, 31331, 31341, 31352, 31362, 31376,
+31390, 31401, 31411, 31423, 31433, 31443, 31453, 31464, 31476, 31486, 31496, 31508, 31518, 31528, 31539, 31549,
+31559, 31569, 31581, 31591, 31601, 31620, 31630, 31640, 31653, 31663, 31674, 31684, 31695, 31705, 31716, 31730,
+31740, 31750, 31761, 31771, 31781, 31793, 31805, 31818, 31828, 31838, 31849, 31859, 31869, 31879, 31890, 31902,
+31912, 31922, 31932, 31943, 31954, 31964, 31974, 31986, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068,
+32078, 32089, 32099, 32110, 32120, 32130, 32140, 32150, 32162, 32172, 32182, 32194, 32204, 32215, 32225, 32235,
+32245, 32256, 32266, 32277, 32287, 32299, 32309, 32319, 32330, 32340, 32350, 32361, 32371, 32381, 32391, 32401,
+32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631, 32642, 32652, 32662, 32673, 32685, 32696, 32707, 32718,
+32731, 32741, 32751, 32761, 32771, 32781, 32791, 32801, 32812, 32822, 32832, 32842, 32854, 32864, 32877, 32887,
+32897, 32907, 32918, 32929, 32939, 32952, 32963, 32973, 32983, 32993, 33005, 33016, 33026, 33046, 33056, 33068,
+33081, 33093, 33104, 33119, 33129, 33140, 33151, 33162, 33173, 33184, 33198, 33208, 33218, 33229, 33239, 33249,
+33259, 33269, 33279, 33289, 33299, 33309, 33320, 33330, 33344, 33355, 33366, 33376, 33386, 33396, 33406, 33417,
+33428, 33439, 33449, 33459, 33469, 33488, 33498, 33508, 33519, 33529, 33539, 33550, 33560, 33570, 33580, 33590,
+33600, 33610, 33620, 33648, 33659, 33669, 33682, 33692, 33702, 33713, 33725, 33735, 33745, 33756, 33768, 33778,
+33788, 33798, 33809, 33824, 33834, 33845, 33861, 33871, 33881, 33891, 33901, 33911, 33921, 33931, 33941, 33951,
+33961, 33972, 33982, 33992, 34003, 34023, 34033, 34043, 34054, 34064, 34074, 34084, 34095, 34109, 34120, 34130,
+34140, 34152, 34167, 34177, 34187, 34199, 34210, 34220, 34230, 34241, 34251, 34261, 34271, 34281, 34291, 34302,
+34314, 34326, 34337, 34349, 34360, 34370, 34381, 34391, 34401, 34411, 34421, 34440, 34451, 34465, 34475, 34485,
+34495, 34505, 34516, 34526, 34537, 34552, 34562, 34573, 34584, 34595, 34606, 34617, 34627, 34637, 34647, 34657,
+34670, 34680, 34690, 34700, 34711, 34722, 34732, 34746, 34756, 34766, 34777, 34787, 34797, 34807, 34817, 34827,
+34837, 34847, 34861, 34873, 34883, 34893, 34903, 34913, 34923, 34933, 34943, 34955, 34966, 34976, 34986, 34996,
+35006, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35109, 35120, 35130, 35140, 35151, 35162,
+35172, 35182, 35194, 35206, 35216, 35226, 35237, 35247, 35258, 35282, 35292, 35302, 35313, 35325, 35335, 35345,
+35355, 35365, 35375, 35386, 35397, 35408, 35419, 35429, 35440, 35450, 35460, 35471, 35481, 35491, 35501, 35511,
+35522, 35532, 35542, 35552, 35563, 35573, 35583, 35594, 35604, 35614, 35624, 35635, 35646, 35656, 35666, 35676,
+35686, 35696, 35708, 35722, 35732, 35742, 35895, 35905, 35915, 35925, 35937, 35947, 35957, 35970, 35980, 35992,
+36002, 36012, 36022, 36032, 36042, 36053, 36064, 36074, 36085, 36095, 36105, 36115, 36196, 36206, 36223, 36234,
+36245, 36255, 36267, 36277, 36288, 36298, 36308, 36319, 36330, 36340, 36351, 36361, 36372, 36382, 36394, 36404,
+36416, 36426, 36436, 36446, 36457, 36468, 36481, 36491, 36501, 36513, 36523, 36533, 36544, 36554, 36564, 36575,
+36587, 36599, 36610, 36620, 36630, 36640, 36650, 36660, 36670, 36681, 36691, 36701, 36763, 36773, 36783, 36794,
+36804, 36814, 36826, 36836, 36846, 36856, 36866, 36876, 36886, 36896, 36906, 36916, 36926, 36937, 36947, 36957,
+36967, 36978, 36988, 36999, 37009, 37019, 37029, 37039, 37053, 37063, 37074, 37084, 37096, 37108, 37118, 37128,
+37138, 37148, 37159, 37169, 37180, 37191, 37202, 37217, 37228, 37239, 37249, 37259, 37269, 37281, 37291, 37301,
+37311, 37321, 37331, 37341, 37351, 37361, 37371, 37381, 37392, 37404, 37414, 37424, 37434, 37444, 37454, 37464,
+37474, 37486, 37496, 37507, 37517, 37527, 37540, 37551, 37561, 37571, 37581, 37591, 37601, 37612, 37624, 37634,
+37645, 37656, 37666, 37676, 37686, 37700, 37712, 37722, 37732, 37742, 37754, 37768, 37778, 37790, 37800, 37812,
+37825, 37835, 37846, 37857, 37879, 37889, 37901, 37911, 37921, 37931, 37941, 37951, 37962, 37973, 37983, 37994,
+38005, 38015, 38263, 38274, 38284, 38294, 38304, 38315, 38326, 38339, 38349, 38360, 38370, 38428, 38438, 38449,
+38459, 38475, 38486, 38497, 38508, 38518, 38529, 38539, 38549, 38559, 38569, 38579, 38592, 38602, 38613, 38623,
+38633, 38646, 38656, 38666, 38678, 38689, 38704, 38717, 38728, 38738, 38748, 38758, 38769, 38779, 38789, 38799,
+38809, 38819, 38829, 38840, 38851, 38861, 38871, 38881, 38893, 38903, 38913, 38924, 38934, 38944, 38955, 38965,
+38980, 38990, 39000, 39010, 39020, 39080, 39092, 39103, 39116, 39131, 39141, 39151, 39164, 39175, 39185, 39195,
+39206, 39217, 39227, 39237, 39248, 39259, 39318, 39333, 39344, 39354, 39364, 39376, 39386, 39399, 39409, 39419,
+39429, 39439, 39449, 39459, 39469, 39479, 39489, 39499, 39509, 39519, 39529, 39592, 39602, 39612, 39622, 39632,
+39643, 39653, 39663, 39673, 39683, 39693, 39704, 39714, 39725, 39735, 39745, 39755, 39765, 39777, 39787, 39797,
+39807, 39817, 39827, 39837, 39847, 39857, 39867, 39878, 39888, 39899, 39909, 39919, 39929, 39940, 39951, 39961,
+39971, 39981, 39991, 40001, 40014, 40024, 40035, 40046, 40056, 40165, 40176, 40194, 40206, 40216, 40227, 40239,
+40250, 40260, 40272, 40284, 40297, 40310, 40323, 40333, 40343, 40353, 40363, 40373, 40383, 40393, 40403, 40414,
+40425, 40435, 40445, 40455, 40465, 40475, 40565, 40575, 40587, 40597, 40607, 40617, 40627, 40638, 40648, 40658,
+40668, 40679, 40689, 40699, 40711, 40721, 40731, 40742, 40753, 40763, 40773, 40783, 40794, 40806, 40816, 40826,
+40845, 40855, 40865, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401,
+65411, 65421, 65431, 65507
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+143, 162, 194, 161, 241, 161, 242, 143, 162, 240, /*92,*/ 143, 162, 195, 161, 248,
+161, 175, 143, 162, 237, 143, 162, 236, 162, 204, 143, 162, 238, 143, 162, 180,
+161, 235, 161, 222, 161, 173, 162, 249, 143, 162, 177, 143, 162, 235, 143, 162,
+196, 143, 170, 162, 143, 170, 161, 143, 170, 164, 143, 170, 170, 143, 170, 163,
+143, 170, 169, 143, 169, 161, 143, 170, 174, 143, 170, 178, 143, 170, 177, 143,
+170, 180, 143, 170, 179, 143, 170, 192, 143, 170, 191, 143, 170, 194, 143, 170,
+193, 143, 170, 208, 143, 170, 210, 143, 170, 209, 143, 170, 212, 143, 170, 216,
+143, 170, 211, 161, 223, 143, 169, 172, 143, 170, 227, 143, 170, 226, 143, 170,
+229, 143, 170, 228, 143, 170, 242, 143, 169, 176, 143, 169, 206, 143, 171, 162,
+143, 171, 161, 143, 171, 164, 143, 171, 170, 143, 171, 163, 143, 171, 169, 143,
+169, 193, 143, 171, 174, 143, 171, 178, 143, 171, 177, 143, 171, 180, 143, 171,
+179, 143, 171, 192, 143, 171, 191, 143, 171, 194, 143, 171, 193, 143, 169, 195,
+143, 171, 208, 143, 171, 210, 143, 171, 209, 143, 171, 212, 143, 171, 216, 143,
+171, 211, 161, 224, 143, 169, 204, 143, 171, 227, 143, 171, 226, 143, 171, 229,
+143, 171, 228, 143, 171, 242, 143, 169, 208, 143, 171, 243, 143, 170, 167, 143,
+170, 175, 143, 170, 182, 143, 170, 189, 143, 170, 197, 143, 170, 200, 143, 171,
+203, 143, 171, 206, 143, 169, 173, 143, 170, 221, 143, 169, 175, 143, 170, 232,
+143, 171, 245, 143, 170, 166, 143, 170, 237, 143, 171, 185, 143, 162, 176, 143,
+162, 175, 143, 162, 184, 143, 166, 233, 166, 168, 166, 178, 143, 166, 242, 166,
+199, 166, 209, 143, 166, 250, 167, 167, 143, 167, 203, 167, 166, 167, 177, 167,
+187, 167, 212, 167, 223, 167, 233, 167, 215, 143, 167, 251, 161, 190, 161, 200,
+161, 196, 162, 243, 162, 168, 161, 238, 143, 162, 241, 143, 162, 239, 162, 171,
+162, 205, 162, 207, 162, 187, 162, 229, 162, 202, 161, 232, 162, 226, 161, 226,
+162, 227, 162, 190, 162, 221, 162, 222, 168, 161, 168, 163, 168, 177, 168, 178,
+168, 184, 168, 181, 168, 182, 162, 163, 162, 165, 162, 167, 162, 161, 162, 254,
+161, 250, 161, 234, 162, 246, 161, 161, 161, 212, 161, 204, 164, 161, 164, 171,
+164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 161, 171,
+165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
+165, 245, 176, 236, 190, 229, 179, 238, 190, 231, 143, 176, 169, 182, 250, 208,
+167, 143, 176, 178, 143, 176, 179, 143, 176, 181, 143, 176, 183, 198, 253, 180,
+165, 205, 189, 184, 223, 176, 161, 203, 242, 208, 183, 191, 205, 208, 188, 208,
+186, 201, 213, 143, 176, 201, 208, 193, 208, 195, 180, 235, 143, 176, 214, 143,
+176, 217, 143, 176, 221, 191, 173, 143, 176, 231, 143, 176, 235, 143, 176, 238,
+143, 176, 223, 143, 176, 242, 202, 187, 187, 200, 143, 177, 162, 143, 177, 168,
+176, 205, 213, 165, 191, 175, 202, 216, 143, 177, 187, 208, 215, 208, 216, 189,
+164, 202, 240, 143, 177, 203, 143, 177, 207, 143, 177, 211, 143, 177, 216, 208,
+235, 182, 230, 143, 177, 223, 143, 177, 228, 208, 243, 143, 177, 236, 143, 177,
+242, 194, 166, 208, 250, 143, 177, 251, 143, 178, 163, 143, 178, 167, 143, 178,
+172, 208, 253, 183, 185, 209, 161, 143, 178, 185, 143, 178, 189, 193, 206, 143,
+178, 197, 202, 200, 143, 178, 202, 143, 178, 210, 209, 179, 143, 178, 218, 143,
+178, 223, 209, 184, 189, 188, 143, 178, 231, 197, 222, 143, 178, 237, 209, 194,
+197, 181, 209, 196, 209, 198, 209, 204, 180, 167, 209, 209, 186, 227, 143, 178,
+252, 143, 179, 161, 143, 179, 164, 244, 165, 189, 232, 209, 224, 189, 208, 209,
+227, 209, 230, 143, 179, 183, 143, 179, 184, 209, 233, 183, 244, 196, 230, 193,
+176, 143, 179, 193, 143, 179, 199, 143, 179, 201, 143, 179, 203, 143, 179, 206,
+143, 179, 209, 143, 179, 212, 178, 195, 197, 216, 207, 171, 179, 175, 143, 179,
+232, 240, 213, 143, 179, 239, 210, 171, 143, 179, 246, 188, 219, 202, 241, 210,
+183, 186, 252, 210, 186, 143, 180, 175, 210, 190, 143, 180, 182, 143, 180, 183,
+198, 238, 143, 180, 187, 143, 180, 190, 210, 203, 210, 204, 143, 180, 198, 206,
+210, 143, 180, 204, 210, 209, 143, 180, 212, 187, 178, 193, 208, 188, 232, 143,
+180, 224, 194, 254, 143, 180, 227, 210, 222, 177, 165, 143, 180, 230, 200, 221,
+143, 180, 236, 202, 173, 202, 242, 198, 221, 143, 180, 244, 188, 254, 204, 163,
+204, 191, 143, 181, 164, 210, 240, 143, 181, 170, 143, 181, 173, 143, 181, 179,
+143, 181, 183, 143, 181, 185, 211, 166, 211, 175, 143, 181, 191, 143, 181, 193,
+143, 181, 197, 143, 181, 202, 176, 162, 143, 181, 206, 143, 181, 209, 211, 177,
+143, 181, 217, 211, 183, 143, 181, 225, 211, 193, 143, 181, 232, 143, 181, 236,
+180, 238, 183, 246, 143, 181, 244, 143, 181, 245, 143, 181, 249, 143, 182, 161,
+143, 182, 165, 143, 182, 167, 143, 182, 168, 143, 182, 170, 143, 182, 175, 143,
+182, 179, 178, 222, 143, 182, 182, 143, 182, 188, 143, 182, 195, 143, 182, 199,
+143, 182, 200, 180, 239, 143, 182, 210, 211, 230, 211, 231, 211, 233, 143, 182,
+221, 143, 182, 225, 143, 182, 231, 143, 182, 233, 211, 244, 211, 247, 143, 182,
+244, 143, 182, 250, 143, 182, 252, 185, 241, 143, 183, 165, 143, 183, 168, 143,
+183, 171, 143, 183, 177, 143, 183, 182, 212, 173, 143, 183, 188, 212, 175, 212,
+179, 143, 183, 197, 143, 183, 205, 212, 180, 212, 181, 212, 182, 143, 183, 220,
+143, 183, 225, 212, 184, 143, 183, 230, 143, 183, 231, 212, 191, 199, 184, 143,
+183, 239, 143, 183, 243, 180, 240, 143, 183, 251, 194, 196, 143, 184, 165, 180,
+174, 190, 236, 143, 184, 172, 143, 184, 173, 197, 227, 186, 201, 143, 184, 183,
+212, 199, 143, 184, 185, 143, 184, 189, 202, 232, 143, 184, 199, 203, 207, 143,
+184, 206, 143, 184, 208, 195, 197, 212, 219, 212, 224, 143, 184, 221, 143, 184,
+222, 212, 232, 202, 209, 143, 184, 228, 143, 184, 231, 194, 231, 188, 186, 212,
+243, 198, 224, 143, 184, 244, 143, 184, 248, 212, 252, 143, 185, 162, 143, 185,
+167, 199, 165, 143, 185, 172, 143, 185, 174, 197, 202, 143, 185, 182, 143, 185,
+185, 187, 207, 213, 172, 143, 185, 195, 143, 185, 198, 176, 249, 213, 178, 143,
+185, 210, 143, 185, 211, 143, 185, 215, 213, 183, 213, 180, 143, 185, 223, 186,
+167, 143, 185, 228, 143, 185, 231, 143, 185, 235, 143, 185, 238, 143, 185, 243,
+143, 185, 246, 143, 185, 251, 213, 191, 183, 249, 213, 197, 143, 186, 167, 143,
+186, 169, 143, 186, 171, 143, 186, 174, 213, 201, 213, 202, 143, 186, 182, 196,
+220, 213, 206, 213, 210, 143, 186, 187, 213, 212, 204, 210, 213, 216, 213, 218,
+143, 186, 196, 177, 167, 143, 186, 205, 176, 184, 205, 168, 143, 186, 213, 205,
+198, 213, 227, 143, 186, 221, 143, 186, 224, 178, 201, 213, 237, 195, 254, 188,
+247, 176, 211, 213, 245, 143, 186, 235, 213, 248, 143, 186, 244, 198, 244, 213,
+252, 214, 161, 143, 186, 248, 193, 216, 214, 165, 214, 168, 143, 187, 169, 214,
+170, 143, 187, 174, 193, 187, 143, 187, 181, 214, 176, 214, 180, 143, 187, 187,
+143, 187, 188, 178, 229, 143, 187, 192, 214, 183, 191, 242, 214, 194, 214, 193,
+143, 187, 201, 143, 187, 203, 143, 187, 206, 143, 187, 211, 214, 201, 214, 191,
+191, 243, 214, 205, 143, 187, 226, 143, 187, 230, 143, 187, 232, 214, 211, 143,
+187, 240, 143, 230, 244, 214, 217, 143, 187, 247, 214, 221, 192, 238, 185, 170,
+184, 202, 180, 172, 200, 193, 214, 230, 214, 231, 191, 227, 194, 211, 203, 185,
+214, 243, 143, 188, 181, 143, 188, 184, 143, 188, 187, 180, 179, 205, 196, 200,
+223, 196, 236, 214, 249, 143, 188, 201, 176, 195, 143, 188, 207, 206, 247, 179,
+199, 215, 163, 215, 168, 215, 172, 215, 176, 143, 188, 223, 181, 221, 143, 188,
+227, 184, 204, 188, 229, 143, 188, 239, 143, 188, 244, 143, 188, 247, 143, 188,
+250, 201, 167, 190, 180, 143, 189, 166, 183, 194, 143, 189, 171, 215, 208, 143,
+189, 178, 200, 249, 143, 189, 183, 191, 180, 199, 166, 187, 214, 143, 189, 195,
+178, 247, 199, 176, 215, 221, 143, 189, 210, 143, 189, 213, 143, 189, 217, 215,
+226, 143, 189, 220, 143, 189, 222, 215, 240, 143, 189, 228, 215, 239, 178, 184,
+183, 195, 143, 189, 236, 188, 189, 143, 189, 243, 143, 189, 246, 216, 166, 143,
+189, 253, 143, 190, 161, 190, 240, 143, 190, 170, 143, 190, 173, 193, 218, 194,
+198, 216, 185, 216, 180, 143, 190, 188, 182, 242, 216, 195, 143, 190, 202, 216,
+198, 143, 190, 209, 216, 216, 216, 215, 183, 197, 216, 213, 143, 190, 216, 216,
+220, 216, 225, 143, 190, 229, 198, 180, 183, 251, 143, 190, 239, 216, 234, 178,
+251, 143, 190, 246, 216, 239, 196, 168, 216, 246, 143, 191, 167, 178, 230, 216,
+254, 192, 239, 217, 165, 204, 225, 143, 191, 182, 143, 191, 184, 143, 191, 189,
+143, 191, 191, 202, 177, 200, 227, 217, 183, 143, 191, 197, 185, 179, 143, 191,
+201, 202, 250, 217, 187, 195, 180, 217, 188, 192, 219, 143, 191, 214, 143, 191,
+216, 189, 166, 217, 205, 143, 191, 225, 182, 180, 143, 191, 228, 143, 191, 231,
+193, 222, 194, 170, 143, 191, 244, 143, 191, 248, 143, 191, 252, 199, 177, 143,
+192, 167, 199, 211, 143, 192, 174, 191, 228, 183, 199, 143, 192, 180, 143, 192,
+183, 217, 231, 143, 192, 189, 217, 226, 143, 192, 195, 217, 236, 143, 192, 201,
+217, 211, 217, 238, 143, 192, 213, 183, 200, 143, 192, 217, 197, 166, 143, 192,
+230, 143, 192, 231, 204, 206, 183, 226, 143, 192, 238, 143, 192, 242, 143, 192,
+247, 199, 197, 179, 201, 143, 193, 161, 143, 193, 166, 218, 166, 197, 167, 181,
+188, 218, 177, 218, 181, 143, 193, 185, 143, 193, 188, 143, 193, 192, 143, 193,
+196, 218, 189, 202, 252, 218, 195, 143, 193, 206, 218, 201, 143, 193, 210, 218,
+202, 143, 193, 213, 202, 184, 200, 195, 218, 207, 192, 205, 187, 219, 202, 253,
+218, 211, 143, 193, 232, 143, 193, 236, 180, 251, 189, 220, 143, 193, 242, 218,
+224, 143, 193, 249, 218, 230, 143, 194, 166, 143, 194, 172, 195, 235, 143, 194,
+179, 143, 194, 182, 143, 194, 187, 179, 162, 218, 242, 195, 210, 218, 247, 218,
+245, 218, 248, 196, 170, 143, 194, 217, 219, 162, 143, 194, 224, 143, 194, 227,
+219, 163, 219, 165, 143, 194, 234, 219, 170, 194, 216, 205, 173, 143, 194, 241,
+196, 171, 219, 176, 188, 235, 181, 224, 143, 194, 249, 194, 188, 197, 206, 143,
+195, 161, 219, 191, 143, 195, 166, 219, 199, 143, 195, 170, 143, 195, 175, 219,
+197, 143, 195, 177, 143, 195, 181, 143, 195, 188, 199, 240, 143, 195, 193, 219,
+207, 219, 211, 143, 195, 184, 198, 202, 192, 242, 143, 195, 204, 143, 195, 207,
+143, 195, 212, 143, 195, 214, 143, 195, 217, 182, 205, 143, 195, 223, 201, 176,
+143, 195, 228, 143, 195, 233, 199, 223, 219, 231, 143, 195, 241, 143, 195, 245,
+196, 244, 219, 238, 180, 254, 143, 195, 254, 143, 196, 165, 220, 168, 143, 196,
+173, 220, 170, 220, 166, 196, 199, 191, 250, 220, 176, 220, 191, 143, 196, 193,
+143, 196, 195, 201, 246, 220, 194, 143, 196, 204, 143, 196, 209, 207, 176, 186,
+231, 207, 177, 220, 213, 143, 196, 222, 143, 196, 225, 220, 201, 185, 189, 143,
+196, 232, 143, 196, 234, 220, 229, 220, 223, 143, 196, 244, 143, 196, 245, 201,
+184, 220, 235, 220, 211, 220, 247, 220, 237, 143, 197, 170, 181, 204, 220, 243,
+143, 197, 180, 143, 197, 182, 143, 197, 187, 221, 161, 220, 253, 221, 168, 221,
+166, 221, 165, 143, 197, 206, 143, 197, 210, 143, 197, 213, 143, 197, 216, 221,
+178, 205, 243, 143, 197, 226, 143, 197, 230, 178, 164, 205, 223, 182, 214, 221,
+188, 143, 197, 244, 143, 197, 247, 143, 197, 249, 186, 208, 143, 197, 254, 189,
+222, 221, 205, 143, 198, 166, 143, 198, 171, 221, 213, 143, 198, 178, 143, 198,
+182, 221, 218, 221, 219, 221, 221, 143, 198, 192, 143, 198, 195, 143, 198, 199,
+181, 164, 221, 230, 143, 198, 209, 177, 202, 181, 225, 143, 198, 218, 180, 192,
+221, 233, 143, 198, 226, 143, 198, 230, 221, 235, 198, 217, 178, 173, 203, 215,
+203, 247, 202, 168, 143, 198, 246, 200, 231, 143, 198, 254, 143, 199, 163, 222,
+165, 143, 199, 170, 143, 199, 171, 143, 199, 174, 222, 172, 196, 197, 143, 199,
+184, 143, 199, 186, 190, 244, 143, 199, 189, 143, 199, 192, 179, 189, 179, 164,
+143, 199, 198, 205, 176, 143, 199, 203, 143, 199, 206, 143, 199, 208, 143, 199,
+212, 143, 199, 215, 222, 204, 143, 199, 221, 143, 199, 225, 189, 223, 143, 199,
+231, 222, 189, 222, 188, 222, 219, 178, 185, 143, 199, 237, 222, 220, 222, 218,
+143, 199, 251, 143, 200, 161, 222, 208, 143, 200, 165, 200, 174, 189, 224, 143,
+200, 170, 222, 228, 205, 207, 143, 200, 178, 143, 200, 183, 222, 237, 194, 218,
+143, 200, 187, 223, 163, 181, 249, 143, 200, 196, 143, 200, 198, 199, 249, 143,
+200, 204, 143, 200, 208, 222, 243, 143, 200, 212, 143, 200, 217, 189, 225, 196,
+172, 223, 166, 223, 173, 143, 200, 231, 143, 200, 237, 143, 200, 240, 223, 186,
+143, 200, 248, 183, 227, 143, 200, 254, 223, 190, 143, 201, 162, 143, 201, 163,
+223, 171, 143, 201, 169, 143, 201, 173, 223, 198, 223, 202, 195, 245, 223, 208,
+143, 201, 182, 143, 201, 185, 143, 201, 189, 143, 201, 192, 178, 208, 143, 201,
+198, 143, 201, 201, 177, 234, 143, 201, 208, 143, 201, 210, 223, 220, 223, 218,
+206, 245, 143, 201, 218, 223, 223, 223, 216, 223, 226, 143, 201, 230, 177, 235,
+143, 201, 234, 143, 201, 236, 193, 179, 143, 201, 242, 143, 201, 247, 223, 230,
+143, 201, 254, 223, 236, 143, 202, 162, 223, 239, 223, 237, 244, 166, 223, 241,
+143, 202, 174, 223, 245, 197, 245, 223, 246, 143, 202, 187, 187, 184, 223, 253,
+224, 162, 143, 202, 193, 143, 202, 194, 143, 202, 197, 224, 166, 224, 170, 224,
+172, 224, 175, 143, 202, 211, 143, 202, 215, 203, 210, 143, 202, 224, 143, 202,
+227, 224, 182, 224, 183, 181, 190, 184, 164, 190, 245, 143, 202, 242, 143, 202,
+245, 143, 202, 247, 224, 195, 198, 200, 224, 198, 143, 203, 162, 143, 203, 167,
+224, 200, 143, 203, 173, 143, 203, 177, 205, 177, 143, 203, 184, 143, 203, 185,
+224, 213, 189, 195, 143, 203, 199, 224, 217, 143, 203, 207, 143, 203, 210, 143,
+203, 215, 143, 203, 220, 143, 203, 225, 143, 203, 227, 178, 209, 143, 203, 236,
+143, 203, 240, 188, 238, 183, 190, 143, 203, 248, 184, 189, 206, 176, 143, 204,
+168, 143, 204, 170, 143, 204, 178, 143, 204, 182, 143, 204, 184, 143, 204, 189,
+143, 204, 192, 143, 204, 194, 143, 204, 199, 224, 247, 143, 204, 208, 143, 204,
+213, 224, 229, 143, 204, 226, 143, 204, 231, 143, 204, 234, 143, 204, 238, 143,
+204, 242, 143, 204, 245, 225, 166, 143, 204, 252, 143, 204, 254, 185, 249, 197,
+188, 225, 180, 197, 196, 196, 174, 225, 183, 143, 205, 180, 206, 177, 225, 191,
+143, 205, 187, 143, 205, 189, 143, 205, 196, 193, 193, 143, 205, 201, 225, 207,
+225, 215, 225, 214, 143, 205, 211, 225, 218, 143, 205, 216, 143, 205, 221, 143,
+205, 225, 225, 224, 143, 205, 231, 143, 205, 236, 143, 205, 242, 143, 205, 247,
+225, 240, 143, 206, 161, 143, 206, 167, 204, 254, 225, 245, 225, 252, 143, 206,
+179, 197, 208, 143, 206, 182, 187, 169, 226, 173, 143, 206, 193, 200, 233, 226,
+176, 226, 179, 143, 206, 205, 226, 181, 143, 206, 209, 226, 187, 196, 190, 189,
+226, 226, 190, 143, 206, 222, 143, 206, 228, 226, 197, 143, 206, 234, 143, 206,
+239, 143, 206, 243, 143, 206, 248, 143, 206, 253, 143, 207, 163, 143, 207, 168,
+226, 208, 226, 211, 143, 207, 176, 143, 207, 179, 143, 207, 182, 143, 207, 186,
+226, 218, 143, 207, 189, 143, 207, 192, 143, 207, 195, 182, 235, 192, 208, 186,
+189, 226, 230, 143, 207, 212, 181, 206, 203, 164, 185, 220, 143, 207, 225, 143,
+207, 228, 143, 207, 234, 200, 163, 226, 239, 226, 238, 200, 234, 143, 207, 244,
+202, 203, 143, 207, 252, 143, 208, 161, 226, 252, 200, 216, 227, 162, 143, 208,
+173, 176, 235, 143, 208, 185, 143, 208, 188, 143, 208, 190, 143, 208, 191, 143,
+208, 196, 143, 208, 200, 143, 208, 203, 143, 208, 207, 143, 208, 211, 227, 175,
+190, 205, 143, 208, 220, 143, 208, 223, 227, 180, 143, 208, 229, 143, 208, 235,
+143, 208, 238, 143, 208, 242, 143, 208, 244, 143, 208, 249, 143, 208, 252, 199,
+233, 190, 206, 176, 220, 143, 209, 172, 143, 209, 176, 143, 209, 178, 143, 209,
+181, 227, 202, 227, 203, 143, 209, 192, 178, 186, 143, 209, 198, 190, 247, 143,
+209, 206, 143, 209, 208, 143, 209, 211, 143, 209, 216, 143, 209, 219, 227, 221,
+143, 209, 223, 227, 227, 143, 209, 229, 227, 234, 227, 237, 143, 209, 234, 143,
+209, 239, 143, 209, 242, 181, 232, 143, 209, 244, 227, 250, 227, 252, 227, 247,
+143, 210, 163, 143, 210, 167, 195, 222, 228, 184, 228, 170, 228, 172, 143, 210,
+180, 143, 210, 182, 228, 176, 143, 210, 189, 143, 210, 191, 143, 210, 196, 200,
+207, 228, 189, 143, 210, 207, 198, 198, 143, 210, 212, 143, 210, 218, 143, 210,
+224, 228, 194, 143, 210, 231, 143, 210, 233, 143, 210, 237, 228, 213, 143, 210,
+244, 228, 216, 143, 210, 254, 143, 211, 164, 202, 198, 143, 211, 171, 143, 211,
+173, 206, 179, 143, 211, 176, 228, 234, 228, 236, 143, 211, 184, 143, 211, 187,
+228, 245, 228, 246, 143, 211, 199, 228, 250, 181, 234, 143, 211, 205, 143, 211,
+209, 229, 162, 143, 211, 215, 186, 217, 186, 176, 193, 200, 229, 174, 143, 211,
+230, 229, 179, 229, 177, 143, 211, 238, 143, 211, 243, 143, 211, 249, 143, 211,
+252, 229, 194, 188, 250, 143, 212, 166, 143, 212, 169, 143, 212, 174, 143, 212,
+177, 229, 206, 143, 212, 184, 143, 212, 187, 143, 212, 179, 229, 208, 143, 212,
+194, 229, 213, 203, 165, 229, 220, 143, 212, 206, 193, 161, 191, 165, 229, 229,
+229, 234, 143, 212, 221, 229, 239, 143, 212, 226, 143, 212, 229, 229, 251, 180,
+204, 143, 212, 240, 230, 163, 230, 169, 143, 212, 250, 143, 212, 254, 200, 237,
+230, 176, 230, 181, 143, 213, 171, 143, 213, 174, 143, 213, 178, 230, 192, 143,
+213, 183, 143, 213, 185, 143, 213, 187, 143, 213, 190, 143, 213, 194, 230, 203,
+185, 205, 143, 213, 203, 204, 215, 230, 212, 143, 213, 216, 204, 237, 143, 213,
+226, 230, 216, 192, 187, 143, 213, 228, 143, 213, 231, 191, 166, 143, 213, 234,
+207, 190, 190, 211, 184, 212, 143, 213, 241, 143, 213, 242, 176, 223, 143, 213,
+245, 143, 213, 250, 184, 213, 143, 213, 253, 182, 187, 187, 233, 143, 214, 170,
+143, 214, 175, 143, 214, 178, 196, 177, 143, 214, 183, 201, 229, 231, 181, 143,
+214, 193, 231, 171, 194, 220, 231, 174, 231, 178, 231, 177, 143, 214, 209, 231,
+187, 231, 190, 231, 193, 143, 214, 220, 143, 214, 224, 143, 214, 226, 143, 214,
+231, 143, 214, 236, 218, 170, 143, 214, 240, 143, 214, 244, 143, 214, 247, 143,
+214, 248, 231, 217, 143, 215, 161, 143, 215, 165, 143, 215, 167, 231, 226, 143,
+215, 171, 231, 232, 143, 215, 180, 143, 215, 184, 231, 236, 143, 215, 195, 203,
+167, 178, 234, 143, 215, 207, 143, 215, 209, 143, 215, 212, 143, 215, 216, 231,
+249, 231, 247, 183, 212, 232, 173, 143, 215, 233, 143, 215, 234, 195, 227, 232,
+166, 183, 213, 143, 215, 227, 143, 215, 253, 178, 174, 232, 174, 143, 216, 168,
+143, 216, 174, 143, 216, 176, 205, 233, 232, 207, 143, 216, 183, 143, 216, 187,
+186, 218, 143, 216, 191, 232, 203, 143, 216, 196, 143, 216, 198, 143, 216, 201,
+232, 206, 232, 212, 232, 226, 143, 216, 207, 143, 216, 212, 143, 216, 217, 198,
+161, 232, 211, 232, 216, 143, 216, 232, 190, 213, 143, 216, 236, 232, 231, 143,
+216, 240, 143, 216, 244, 143, 216, 247, 143, 216, 251, 143, 216, 254, 143, 217,
+162, 143, 217, 166, 143, 217, 171, 232, 209, 143, 217, 178, 177, 182, 143, 217,
+183, 143, 217, 188, 202, 195, 232, 254, 143, 217, 197, 143, 217, 201, 207, 207,
+233, 177, 143, 217, 216, 143, 217, 220, 177, 242, 143, 217, 228, 204, 244, 143,
+217, 232, 207, 206, 143, 217, 242, 233, 185, 143, 217, 247, 200, 205, 143, 217,
+252, 233, 193, 233, 190, 221, 177, 143, 218, 174, 205, 246, 143, 218, 178, 143,
+218, 183, 233, 200, 143, 218, 188, 143, 218, 193, 195, 238, 143, 218, 200, 143,
+218, 237, 233, 206, 143, 218, 210, 233, 219, 143, 218, 218, 143, 218, 222, 233,
+217, 233, 220, 233, 221, 233, 222, 194, 253, 203, 170, 233, 235, 195, 216, 143,
+218, 254, 143, 219, 162, 143, 219, 166, 143, 219, 172, 143, 219, 174, 233, 251,
+143, 219, 177, 233, 253, 233, 247, 234, 167, 143, 219, 192, 143, 219, 196, 234,
+165, 143, 219, 203, 205, 230, 234, 175, 143, 219, 214, 143, 219, 217, 143, 219,
+222, 143, 219, 226, 234, 187, 143, 219, 232, 143, 219, 237, 234, 192, 143, 219,
+248, 143, 219, 250, 234, 197, 143, 220, 164, 222, 167, 179, 185, 185, 213, 234,
+206, 234, 210, 182, 222, 194, 222, 194, 181, 143, 220, 190, 143, 220, 192, 184,
+211, 143, 220, 195, 143, 220, 197, 234, 227, 143, 220, 206, 234, 235, 234, 236,
+234, 233, 143, 220, 214, 179, 236, 143, 220, 222, 234, 243, 143, 220, 228, 143,
+220, 233, 234, 247, 143, 220, 240, 143, 220, 243, 235, 162, 143, 220, 250, 143,
+220, 254, 202, 164, 143, 221, 166, 179, 208, 143, 221, 173, 235, 178, 235, 180,
+179, 209, 235, 185, 191, 168, 143, 221, 189, 143, 221, 193, 143, 221, 197, 143,
+221, 199, 235, 194, 235, 196, 143, 221, 210, 191, 199, 143, 221, 217, 186, 190,
+235, 199, 143, 221, 229, 181, 205, 143, 221, 235, 235, 209, 143, 221, 243, 143,
+221, 248, 235, 216, 198, 201, 143, 222, 162, 235, 219, 180, 210, 207, 192, 235,
+227, 235, 221, 143, 222, 180, 143, 222, 183, 143, 222, 191, 235, 226, 143, 222,
+189, 235, 245, 235, 240, 235, 244, 143, 222, 201, 143, 222, 202, 201, 232, 183,
+217, 181, 196, 143, 222, 213, 218, 206, 143, 222, 221, 143, 222, 224, 195, 171,
+236, 175, 143, 222, 233, 236, 181, 190, 221, 208, 174, 143, 222, 250, 236, 186,
+203, 198, 236, 194, 185, 215, 192, 213, 236, 202, 178, 236, 194, 177, 143, 223,
+178, 199, 229, 188, 193, 143, 223, 187, 143, 223, 191, 143, 223, 194, 236, 219,
+192, 214, 143, 223, 201, 143, 223, 202, 177, 219, 143, 223, 209, 143, 223, 211,
+143, 223, 214, 143, 223, 218, 143, 223, 222, 143, 223, 227, 143, 223, 230, 236,
+240, 236, 238, 143, 223, 242, 236, 245, 236, 244, 143, 223, 250, 236, 247, 237,
+169, 236, 253, 143, 224, 171, 236, 254, 143, 224, 177, 143, 224, 181, 143, 224,
+184, 189, 179, 237, 175, 237, 179, 143, 224, 198, 237, 186, 191, 200, 143, 224,
+209, 143, 224, 212, 188, 214, 143, 224, 219, 198, 240, 237, 199, 143, 224, 225,
+143, 224, 230, 237, 210, 143, 224, 235, 143, 224, 239, 206, 216, 143, 224, 248,
+237, 217, 237, 219, 143, 225, 166, 143, 225, 170, 191, 201, 143, 225, 177, 237,
+231, 202, 213, 203, 248, 183, 222, 237, 233, 143, 225, 195, 143, 225, 197, 237,
+254, 143, 225, 203, 143, 225, 206, 237, 248, 194, 164, 143, 225, 212, 143, 225,
+216, 238, 167, 238, 166, 198, 187, 143, 225, 223, 143, 225, 226, 238, 175, 206,
+203, 237, 238, 205, 184, 143, 225, 241, 143, 225, 245, 238, 184, 143, 225, 251,
+143, 226, 163, 143, 226, 173, 143, 226, 169, 201, 244, 143, 226, 178, 143, 226,
+179, 143, 226, 185, 238, 192, 143, 226, 193, 143, 226, 199, 143, 226, 203, 143,
+226, 209, 143, 226, 212, 188, 242, 143, 226, 220, 189, 183, 185, 243, 143, 226,
+228, 238, 204, 143, 226, 237, 143, 226, 240, 238, 208, 238, 211, 143, 226, 254,
+238, 216, 143, 227, 164, 191, 203, 182, 252, 143, 227, 179, 143, 227, 182, 143,
+227, 187, 143, 227, 193, 143, 227, 198, 143, 227, 203, 143, 227, 207, 143, 227,
+213, 197, 180, 143, 227, 223, 143, 227, 226, 200, 173, 143, 227, 236, 143, 227,
+242, 189, 198, 143, 227, 251, 143, 227, 254, 143, 228, 164, 143, 228, 169, 238,
+248, 143, 228, 181, 143, 228, 188, 143, 228, 193, 143, 228, 200, 143, 228, 205,
+181, 248, 143, 228, 212, 143, 228, 214, 191, 238, 239, 162, 207, 163, 143, 228,
+230, 238, 253, 143, 228, 235, 143, 228, 241, 143, 228, 243, 239, 171, 143, 229,
+161, 143, 229, 167, 143, 229, 172, 143, 229, 176, 143, 229, 181, 143, 229, 183,
+143, 229, 188, 143, 229, 195, 239, 178, 182, 192, 143, 229, 207, 143, 229, 212,
+143, 229, 217, 143, 229, 222, 239, 197, 239, 195, 239, 196, 143, 229, 231, 143,
+229, 236, 143, 229, 238, 143, 229, 241, 239, 206, 239, 209, 239, 216, 196, 185,
+239, 217, 143, 230, 164, 239, 221, 239, 224, 143, 230, 173, 143, 230, 176, 239,
+234, 239, 235, 198, 174, 239, 243, 201, 236, 143, 230, 201, 143, 230, 203, 193,
+203, 239, 251, 143, 230, 214, 143, 230, 217, 240, 165, 198, 171, 143, 230, 224,
+231, 161, 240, 168, 143, 230, 233, 143, 230, 237, 143, 230, 240, 191, 253, 143,
+230, 242, 240, 186, 143, 230, 249, 143, 230, 250, 206, 237, 188, 251, 206, 238,
+240, 195, 143, 231, 167, 240, 199, 240, 201, 240, 205, 192, 196, 240, 208, 240,
+211, 240, 215, 143, 231, 191, 240, 217, 240, 223, 143, 231, 199, 240, 228, 202,
+220, 143, 231, 210, 240, 231, 143, 231, 223, 143, 231, 228, 143, 231, 235, 240,
+236, 143, 231, 240, 202, 199, 240, 243, 143, 231, 249, 143, 231, 252, 143, 232,
+161, 143, 232, 167, 143, 232, 170, 179, 220, 180, 234, 143, 232, 180, 143, 232,
+185, 201, 247, 143, 232, 190, 143, 232, 195, 143, 232, 199, 200, 244, 143, 232,
+202, 200, 211, 187, 244, 143, 232, 209, 143, 232, 211, 143, 232, 216, 143, 232,
+220, 143, 232, 223, 143, 232, 230, 241, 189, 241, 190, 143, 232, 242, 188, 243,
+241, 198, 143, 232, 251, 143, 233, 162, 194, 204, 195, 243, 143, 233, 170, 143,
+233, 173, 241, 209, 241, 211, 241, 215, 241, 214, 241, 217, 143, 233, 194, 143,
+233, 197, 241, 219, 143, 233, 204, 143, 233, 207, 241, 225, 241, 229, 241, 233,
+185, 252, 143, 233, 218, 241, 238, 143, 233, 228, 143, 233, 231, 143, 233, 236,
+143, 233, 240, 241, 249, 143, 233, 247, 143, 233, 254, 143, 234, 167, 242, 163,
+242, 166, 143, 234, 178, 143, 234, 182, 179, 161, 143, 234, 187, 143, 234, 189,
+143, 234, 194, 143, 234, 200, 143, 234, 205, 143, 234, 209, 143, 234, 215, 242,
+184, 143, 234, 223, 143, 234, 226, 143, 234, 230, 143, 234, 234, 242, 196, 143,
+234, 242, 194, 228, 143, 234, 247, 143, 234, 251, 143, 235, 161, 242, 218, 143,
+235, 168, 143, 235, 172, 143, 235, 177, 201, 201, 143, 235, 186, 143, 235, 188,
+143, 235, 194, 143, 235, 200, 143, 235, 205, 143, 235, 211, 242, 233, 196, 187,
+242, 236, 143, 235, 222, 178, 170, 143, 235, 225, 242, 245, 143, 235, 229, 143,
+235, 234, 242, 247, 243, 165, 177, 173, 143, 235, 248, 143, 235, 252, 143, 236,
+163, 143, 236, 167, 143, 236, 173, 143, 236, 175, 243, 170, 143, 236, 180, 143,
+236, 183, 143, 236, 186, 243, 186, 143, 236, 193, 143, 236, 198, 143, 236, 202,
+243, 191, 143, 236, 207, 143, 236, 210, 243, 193, 243, 195, 188, 175, 243, 200,
+243, 203, 206, 219, 243, 207, 143, 236, 238, 221, 224, 143, 236, 242, 185, 245,
+243, 217, 143, 236, 247, 143, 236, 252, 243, 228, 243, 231, 143, 237, 168, 143,
+237, 175, 143, 237, 178, 143, 237, 182, 201, 161, 143, 237, 194, 240, 237, 143,
+237, 202, 243, 245, 143, 237, 210, 143, 237, 214, 206, 182, 143, 237, 222, 143,
+237, 224, 161, 170, 161, 220, 163, 181, 161, 169, 163, 201, 163, 211, 161, 207,
+163, 231, 163, 241, 161, 208, 142, 165, 142, 175, 142, 185, 142, 195, 142, 205,
+142, 215, 161, 177
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic () throws CharacterCodingException {
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ CharBuffer inputCB = CharBuffer.allocate(65536);
+ for (int code = 32; code <= 65533; code ++) {
+ if ((encoder.canEncode((char) code))
+ && (code != 165) && (code != 8254)) {
+ inputCB.put((char) code);
+ }
+ }
+ inputCB.rewind();
+ ByteBuffer intermediateBB = encoder.encode(inputCB);
+ inputCB.rewind();
+ intermediateBB.rewind();
+ CharBuffer outputCB = decoder.decode(intermediateBB);
+ outputCB.rewind();
+ assertEqualCBs("decode(encode(A)) must be identical with A!",
+ inputCB, outputCB);
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP_Android.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP_Android.java
new file mode 100644
index 0000000..373c97f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_JP_Android.java
@@ -0,0 +1,523 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CodingErrorAction;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_MultiByte_EUC_JP_Android extends OldCharset_AbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "EUC-JP";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 162, 163, 164, /*165,*/ 166, 167, 168, 169, 170, 172, 174, 175, 176, 177, 180,
+182, 184, 186, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
+204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
+221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
+237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
+253, 254, 255, 256, 266, 278, 288, 298, 308, 318, 328, 338, 348, 358, 368, 378,
+461, 471, 501, 711, 728, 900, 910, 920, 931, 941, 951, 961, 971, 1025, 1035, 1045,
+1055, 1065, 1075, 1085, 1095, 1105, 1115, 8208, 8220, 8230, 8240, 8251, 8451, 8470, 8482, 8592,
+8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472, 9484, 9495, 9507,
+9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298, 12308, 12353, 12363,
+12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523,
+12533, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20039, 20049, 20060, 20072, 20083, 20094, 20104, 20114,
+20124, 20134, 20144, 20154, 20164, 20174, 20184, 20194, 20205, 20215, 20225, 20235, 20245, 20270, 20280, 20290,
+20300, 20310, 20320, 20330, 20341, 20351, 20361, 20371, 20381, 20395, 20405, 20415, 20425, 20436, 20447, 20462,
+20472, 20484, 20494, 20504, 20514, 20524, 20534, 20544, 20554, 20565, 20575, 20586, 20596, 20608, 20618, 20628,
+20638, 20650, 20660, 20670, 20681, 20691, 20701, 20711, 20721, 20731, 20742, 20752, 20762, 20775, 20785, 20795,
+20805, 20815, 20826, 20836, 20846, 20856, 20866, 20876, 20886, 20896, 20906, 20916, 20926, 20936, 20946, 20956,
+20966, 20976, 20986, 20996, 21006, 21016, 21026, 21038, 21048, 21059, 21069, 21079, 21089, 21102, 21112, 21122,
+21132, 21142, 21152, 21162, 21172, 21182, 21192, 21202, 21212, 21222, 21232, 21242, 21253, 21263, 21273, 21283,
+21293, 21304, 21314, 21324, 21335, 21345, 21356, 21367, 21378, 21390, 21400, 21412, 21422, 21432, 21442, 21452,
+21462, 21472, 21482, 21493, 21505, 21515, 21530, 21542, 21553, 21563, 21574, 21585, 21598, 21608, 21619, 21629,
+21640, 21650, 21660, 21670, 21681, 21691, 21702, 21720, 21730, 21740, 21750, 21760, 21772, 21782, 21802, 21813,
+21824, 21834, 21846, 21856, 21883, 21894, 21905, 21916, 21927, 21938, 21951, 21961, 21971, 21982, 21993, 22006,
+22021, 22031, 22041, 22057, 22067, 22077, 22089, 22100, 22110, 22120, 22130, 22144, 22154, 22164, 22174, 22184,
+22195, 22206, 22216, 22227, 22237, 22247, 22257, 22269, 22279, 22289, 22299, 22309, 22319, 22331, 22341, 22351,
+22369, 22379, 22389, 22399, 22409, 22419, 22429, 22439, 22451, 22461, 22471, 22482, 22492, 22502, 22512, 22522,
+22532, 22549, 22559, 22570, 22580, 22591, 22601, 22612, 22622, 22632, 22642, 22652, 22663, 22675, 22685, 22696,
+22706, 22716, 22727, 22737, 22748, 22761, 22771, 22781, 22793, 22803, 22813, 22823, 22833, 22846, 22856, 22866,
+22877, 22887, 22898, 22908, 22922, 22933, 22943, 22956, 22967, 22977, 22987, 23001, 23011, 23022, 23035, 23049,
+23059, 23070, 23080, 23093, 23104, 23116, 23130, 23141, 23159, 23179, 23190, 23200, 23212, 23224, 23234, 23244,
+23254, 23264, 23274, 23285, 23296, 23307, 23318, 23329, 23340, 23350, 23360, 23371, 23381, 23391, 23401, 23411,
+23421, 23431, 23441, 23451, 23461, 23471, 23481, 23491, 23501, 23511, 23521, 23531, 23541, 23551, 23561, 23571,
+23582, 23592, 23602, 23612, 23622, 23632, 23642, 23652, 23662, 23673, 23687, 23697, 23709, 23720, 23730, 23740,
+23751, 23762, 23773, 23784, 23794, 23805, 23815, 23825, 23835, 23846, 23857, 23869, 23880, 23890, 23900, 23913,
+23923, 23934, 23944, 23954, 23965, 23975, 23986, 23996, 24007, 24018, 24029, 24039, 24049, 24059, 24070, 24081,
+24091, 24101, 24111, 24125, 24135, 24145, 24155, 24168, 24178, 24188, 24199, 24213, 24224, 24234, 24245, 24255,
+24265, 24275, 24285, 24296, 24307, 24318, 24328, 24339, 24349, 24359, 24369, 24379, 24389, 24400, 24411, 24422,
+24432, 24442, 24452, 24463, 24473, 24484, 24494, 24504, 24515, 24525, 24535, 24545, 24555, 24565, 24575, 24586,
+24596, 24607, 24617, 24627, 24640, 24650, 24660, 24671, 24681, 24693, 24703, 24713, 24723, 24733, 24743, 24753,
+24763, 24773, 24783, 24793, 24803, 24816, 24826, 24838, 24848, 24858, 24871, 24881, 24892, 24902, 24915, 24925,
+24935, 24945, 24955, 24967, 24977, 24988, 24999, 25010, 25020, 25030, 25040, 25052, 25062, 25074, 25084, 25095,
+25105, 25115, 25126, 25136, 25147, 25158, 25168, 25178, 25188, 25198, 25209, 25219, 25229, 25239, 25254, 25265,
+25275, 25285, 25295, 25305, 25322, 25332, 25342, 25352, 25363, 25375, 25385, 25397, 25407, 25417, 25427, 25445,
+25457, 25467, 25479, 25490, 25502, 25512, 25522, 25533, 25544, 25554, 25564, 25577, 25587, 25606, 25616, 25628,
+25638, 25648, 25658, 25675, 25688, 25699, 25709, 25720, 25731, 25743, 25753, 25763, 25773, 25785, 25796, 25806,
+25816, 25826, 25836, 25846, 25856, 25866, 25876, 25886, 25897, 25908, 25918, 25928, 25938, 25949, 25959, 25970,
+25981, 25991, 26001, 26011, 26021, 26031, 26041, 26051, 26062, 26072, 26082, 26092, 26105, 26115, 26125, 26140,
+26150, 26160, 26172, 26182, 26193, 26203, 26214, 26224, 26234, 26244, 26254, 26264, 26274, 26285, 26296, 26306,
+26316, 26326, 26336, 26347, 26357, 26367, 26377, 26387, 26397, 26407, 26417, 26429, 26439, 26449, 26460, 26470,
+26480, 26491, 26501, 26511, 26521, 26534, 26544, 26555, 26565, 26575, 26585, 26596, 26606, 26617, 26627, 26643,
+26653, 26663, 26673, 26683, 26693, 26704, 26715, 26727, 26737, 26747, 26757, 26767, 26778, 26789, 26799, 26809,
+26820, 26831, 26841, 26851, 26861, 26873, 26884, 26894, 26905, 26915, 26928, 26939, 26949, 26963, 26973, 26984,
+26994, 27004, 27018, 27028, 27040, 27051, 27063, 27073, 27083, 27094, 27106, 27117, 27129, 27139, 27151, 27161,
+27171, 27182, 27192, 27204, 27214, 27224, 27234, 27249, 27262, 27273, 27287, 27298, 27308, 27320, 27330, 27340,
+27350, 27364, 27376, 27386, 27396, 27407, 27419, 27431, 27442, 27453, 27463, 27474, 27485, 27495, 27507, 27517,
+27529, 27541, 27551, 27561, 27571, 27581, 27593, 27603, 27615, 27627, 27639, 27650, 27661, 27671, 27683, 27694,
+27704, 27714, 27725, 27735, 27746, 27757, 27768, 27778, 27788, 27798, 27809, 27819, 27832, 27842, 27852, 27862,
+27872, 27882, 27892, 27908, 27918, 27929, 27941, 27951, 27961, 27972, 27991, 28001, 28012, 28023, 28034, 28044,
+28054, 28074, 28084, 28095, 28106, 28117, 28127, 28137, 28147, 28160, 28170, 28181, 28191, 28201, 28214, 28227,
+28237, 28247, 28258, 28270, 28283, 28300, 28310, 28320, 28330, 28342, 28352, 28362, 28372, 28382, 28395, 28407,
+28417, 28428, 28438, 28448, 28458, 28470, 28481, 28495, 28505, 28516, 28526, 28536, 28546, 28556, 28566, 28576,
+28586, 28597, 28608, 28618, 28628, 28638, 28648, 28659, 28669, 28679, 28689, 28699, 28710, 28720, 28732, 28744,
+28756, 28766, 28779, 28789, 28801, 28814, 28824, 28836, 28846, 28856, 28872, 28883, 28893, 28913, 28925, 28935,
+28948, 28958, 28971, 28982, 28993, 29003, 29013, 29024, 29036, 29049, 29060, 29071, 29081, 29096, 29106, 29118,
+29128, 29138, 29148, 29158, 29173, 29183, 29193, 29203, 29213, 29224, 29234, 29244, 29254, 29264, 29274, 29287,
+29297, 29307, 29319, 29330, 29344, 29356, 29366, 29377, 29388, 29398, 29408, 29420, 29431, 29442, 29453, 29463,
+29474, 29484, 29494, 29507, 29517, 29527, 29539, 29550, 29560, 29571, 29582, 29592, 29602, 29613, 29623, 29634,
+29644, 29654, 29664, 29674, 29684, 29694, 29705, 29722, 29732, 29742, 29753, 29763, 29773, 29783, 29794, 29805,
+29822, 29833, 29848, 29858, 29870, 29881, 29896, 29907, 29918, 29928, 29938, 29948, 29958, 29969, 29980, 29990,
+30000, 30010, 30020, 30030, 30041, 30052, 30063, 30073, 30085, 30095, 30105, 30115, 30129, 30140, 30150, 30162,
+30172, 30183, 30193, 30204, 30215, 30226, 30236, 30246, 30256, 30266, 30276, 30290, 30300, 30311, 30321, 30331,
+30341, 30352, 30362, 30372, 30382, 30392, 30402, 30412, 30422, 30432, 30442, 30452, 30462, 30472, 30482, 30492,
+30502, 30516, 30526, 30538, 30550, 30560, 30570, 30580, 30590, 30603, 30613, 30623, 30634, 30645, 30655, 30665,
+30677, 30687, 30697, 30707, 30722, 30732, 30749, 30759, 30770, 30783, 30796, 30812, 30824, 30834, 30844, 30854,
+30865, 30877, 30887, 30897, 30907, 30917, 30928, 30938, 30948, 30959, 30970, 30982, 30992, 31002, 31013, 31025,
+31035, 31045, 31055, 31066, 31077, 31090, 31100, 31114, 31124, 31137, 31147, 31160, 31170, 31183, 31194, 31204,
+31216, 31227, 31239, 31249, 31259, 31271, 31281, 31291, 31301, 31311, 31321, 31331, 31341, 31352, 31362, 31376,
+31390, 31401, 31411, 31423, 31433, 31443, 31453, 31464, 31476, 31486, 31496, 31508, 31518, 31528, 31539, 31549,
+31559, 31569, 31581, 31591, 31601, 31620, 31630, 31640, 31653, 31663, 31674, 31684, 31695, 31705, 31716, 31730,
+31740, 31750, 31761, 31771, 31781, 31793, 31805, 31818, 31828, 31838, 31849, 31859, 31869, 31879, 31890, 31902,
+31912, 31922, 31932, 31943, 31954, 31964, 31974, 31986, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068,
+32078, 32089, 32099, 32110, 32120, 32130, 32140, 32150, 32162, 32172, 32182, 32194, 32204, 32215, 32225, 32235,
+32245, 32256, 32266, 32277, 32287, 32299, 32309, 32319, 32330, 32340, 32350, 32361, 32371, 32381, 32391, 32401,
+32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631, 32642, 32652, 32662, 32673, 32685, 32696, 32707, 32718,
+32731, 32741, 32751, 32761, 32771, 32781, 32791, 32801, 32812, 32822, 32832, 32842, 32854, 32864, 32877, 32887,
+32897, 32907, 32918, 32929, 32939, 32952, 32963, 32973, 32983, 32993, 33005, 33016, 33026, 33046, 33056, 33068,
+33081, 33093, 33104, 33119, 33129, 33140, 33151, 33162, 33173, 33184, 33198, 33208, 33218, 33229, 33239, 33249,
+33259, 33269, 33279, 33289, 33299, 33309, 33320, 33330, 33344, 33355, 33366, 33376, 33386, 33396, 33406, 33417,
+33428, 33439, 33449, 33459, 33469, 33488, 33498, 33508, 33519, 33529, 33539, 33550, 33560, 33570, 33580, 33590,
+33600, 33610, 33620, 33648, 33659, 33669, 33682, 33692, 33702, 33713, 33725, 33735, 33745, 33756, 33768, 33778,
+33788, 33798, 33809, 33824, 33834, 33845, 33861, 33871, 33881, 33891, 33901, 33911, 33921, 33931, 33941, 33951,
+33961, 33972, 33982, 33992, 34003, 34023, 34033, 34043, 34054, 34064, 34074, 34084, 34095, 34109, 34120, 34130,
+34140, 34152, 34167, 34177, 34187, 34199, 34210, 34220, 34230, 34241, 34251, 34261, 34271, 34281, 34291, 34302,
+34314, 34326, 34337, 34349, 34360, 34370, 34381, 34391, 34401, 34411, 34421, 34440, 34451, 34465, 34475, 34485,
+34495, 34505, 34516, 34526, 34537, 34552, 34562, 34573, 34584, 34595, 34606, 34617, 34627, 34637, 34647, 34657,
+34670, 34680, 34690, 34700, 34711, 34722, 34732, 34746, 34756, 34766, 34777, 34787, 34797, 34807, 34817, 34827,
+34837, 34847, 34861, 34873, 34883, 34893, 34903, 34913, 34923, 34933, 34943, 34955, 34966, 34976, 34986, 34996,
+35006, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35109, 35120, 35130, 35140, 35151, 35162,
+35172, 35182, 35194, 35206, 35216, 35226, 35237, 35247, 35258, 35282, 35292, 35302, 35313, 35325, 35335, 35345,
+35355, 35365, 35375, 35386, 35397, 35408, 35419, 35429, 35440, 35450, 35460, 35471, 35481, 35491, 35501, 35511,
+35522, 35532, 35542, 35552, 35563, 35573, 35583, 35594, 35604, 35614, 35624, 35635, 35646, 35656, 35666, 35676,
+35686, 35696, 35708, 35722, 35732, 35742, 35895, 35905, 35915, 35925, 35937, 35947, 35957, 35970, 35980, 35992,
+36002, 36012, 36022, 36032, 36042, 36053, 36064, 36074, 36085, 36095, 36105, 36115, 36196, 36206, 36223, 36234,
+36245, 36255, 36267, 36277, 36288, 36298, 36308, 36319, 36330, 36340, 36351, 36361, 36372, 36382, 36394, 36404,
+36416, 36426, 36436, 36446, 36457, 36468, 36481, 36491, 36501, 36513, 36523, 36533, 36544, 36554, 36564, 36575,
+36587, 36599, 36610, 36620, 36630, 36640, 36650, 36660, 36670, 36681, 36691, 36701, 36763, 36773, 36783, 36794,
+36804, 36814, 36826, 36836, 36846, 36856, 36866, 36876, 36886, 36896, 36906, 36916, 36926, 36937, 36947, 36957,
+36967, 36978, 36988, 36999, 37009, 37019, 37029, 37039, 37053, 37063, 37074, 37084, 37096, 37108, 37118, 37128,
+37138, 37148, 37159, 37169, 37180, 37191, 37202, 37217, 37228, 37239, 37249, 37259, 37269, 37281, 37291, 37301,
+37311, 37321, 37331, 37341, 37351, 37361, 37371, 37381, 37392, 37404, 37414, 37424, 37434, 37444, 37454, 37464,
+37474, 37486, 37496, 37507, 37517, 37527, 37540, 37551, 37561, 37571, 37581, 37591, 37601, 37612, 37624, 37634,
+37645, 37656, 37666, 37676, 37686, 37700, 37712, 37722, 37732, 37742, 37754, 37768, 37778, 37790, 37800, 37812,
+37825, 37835, 37846, 37857, 37879, 37889, 37901, 37911, 37921, 37931, 37941, 37951, 37962, 37973, 37983, 37994,
+38005, 38015, 38263, 38274, 38284, 38294, 38304, 38315, 38326, 38339, 38349, 38360, 38370, 38428, 38438, 38449,
+38459, 38475, 38486, 38497, 38508, 38518, 38529, 38539, 38549, 38559, 38569, 38579, 38592, 38602, 38613, 38623,
+38633, 38646, 38656, 38666, 38678, 38689, 38704, 38717, 38728, 38738, 38748, 38758, 38769, 38779, 38789, 38799,
+38809, 38819, 38829, 38840, 38851, 38861, 38871, 38881, 38893, 38903, 38913, 38924, 38934, 38944, 38955, 38965,
+38980, 38990, 39000, 39010, 39020, 39080, 39092, 39103, 39116, 39131, 39141, 39151, 39164, 39175, 39185, 39195,
+39206, 39217, 39227, 39237, 39248, 39259, 39318, 39333, 39344, 39354, 39364, 39376, 39386, 39399, 39409, 39419,
+39429, 39439, 39449, 39459, 39469, 39479, 39489, 39499, 39509, 39519, 39529, 39592, 39602, 39612, 39622, 39632,
+39643, 39653, 39663, 39673, 39683, 39693, 39704, 39714, 39725, 39735, 39745, 39755, 39765, 39777, 39787, 39797,
+39807, 39817, 39827, 39837, 39847, 39857, 39867, 39878, 39888, 39899, 39909, 39919, 39929, 39940, 39951, 39961,
+39971, 39981, 39991, 40001, 40014, 40024, 40035, 40046, 40056, 40165, 40176, 40194, 40206, 40216, 40227, 40239,
+40250, 40260, 40272, 40284, 40297, 40310, 40323, 40333, 40343, 40353, 40363, 40373, 40383, 40393, 40403, 40414,
+40425, 40435, 40445, 40455, 40465, 40475, 40565, 40575, 40587, 40597, 40607, 40617, 40627, 40638, 40648, 40658,
+40668, 40679, 40689, 40699, 40711, 40721, 40731, 40742, 40753, 40763, 40773, 40783, 40794, 40806, 40816, 40826,
+40845, 40855, 40865, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401,
+65411, 65421, 65431, 65507
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+143, 162, 194, 142, 224, 142, 225, 143, 162, 240, 143, 162, 195, 161, 248, 161,
+175, 143, 162, 237, 143, 162, 236, 142, 226, 143, 162, 238, 143, 162, 180, 161,
+235, 161, 222, 161, 173, 162, 249, 143, 162, 177, 143, 162, 235, 143, 162, 196,
+143, 170, 162, 143, 170, 161, 143, 170, 164, 143, 170, 170, 143, 170, 163, 143,
+170, 169, 143, 169, 161, 143, 170, 174, 143, 170, 178, 143, 170, 177, 143, 170,
+180, 143, 170, 179, 143, 170, 192, 143, 170, 191, 143, 170, 194, 143, 170, 193,
+143, 170, 208, 143, 170, 210, 143, 170, 209, 143, 170, 212, 143, 170, 216, 143,
+170, 211, 161, 223, 143, 169, 172, 143, 170, 227, 143, 170, 226, 143, 170, 229,
+143, 170, 228, 143, 170, 242, 143, 169, 176, 143, 169, 206, 143, 171, 162, 143,
+171, 161, 143, 171, 164, 143, 171, 170, 143, 171, 163, 143, 171, 169, 143, 169,
+193, 143, 171, 174, 143, 171, 178, 143, 171, 177, 143, 171, 180, 143, 171, 179,
+143, 171, 192, 143, 171, 191, 143, 171, 194, 143, 171, 193, 143, 169, 195, 143,
+171, 208, 143, 171, 210, 143, 171, 209, 143, 171, 212, 143, 171, 216, 143, 171,
+211, 161, 224, 143, 169, 204, 143, 171, 227, 143, 171, 226, 143, 171, 229, 143,
+171, 228, 143, 171, 242, 143, 169, 208, 143, 171, 243, 143, 170, 167, 143, 170,
+175, 143, 170, 182, 143, 170, 189, 143, 170, 197, 143, 170, 200, 143, 171, 203,
+143, 171, 206, 143, 169, 173, 143, 170, 221, 143, 169, 175, 143, 170, 232, 143,
+171, 245, 143, 170, 166, 143, 170, 237, 143, 171, 185, 143, 162, 176, 143, 162,
+175, 143, 162, 184, 143, 166, 233, 166, 168, 166, 178, 143, 166, 242, 166, 199,
+166, 209, 143, 166, 250, 167, 167, 143, 167, 203, 167, 166, 167, 177, 167, 187,
+167, 212, 167, 223, 167, 233, 167, 215, 143, 167, 251, 161, 190, 161, 200, 161,
+196, 162, 243, 162, 168, 161, 238, 143, 162, 241, 143, 162, 239, 162, 171, 162,
+205, 162, 207, 162, 187, 162, 229, 162, 202, 161, 232, 162, 226, 161, 226, 162,
+227, 162, 190, 162, 221, 162, 222, 168, 161, 168, 163, 168, 177, 168, 178, 168,
+184, 168, 181, 168, 182, 162, 163, 162, 165, 162, 167, 162, 161, 162, 254, 161,
+250, 161, 234, 162, 246, 161, 161, 161, 212, 161, 204, 164, 161, 164, 171, 164,
+181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 161, 171, 165,
+165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235, 165,
+245, 176, 236, 190, 229, 179, 238, 190, 231, 143, 176, 169, 182, 250, 208, 167,
+143, 176, 178, 143, 176, 179, 143, 176, 181, 143, 176, 183, 198, 253, 180, 165,
+205, 189, 184, 223, 176, 161, 203, 242, 208, 183, 191, 205, 208, 188, 208, 186,
+201, 213, 143, 176, 201, 208, 193, 208, 195, 180, 235, 143, 176, 214, 143, 176,
+217, 143, 176, 221, 191, 173, 143, 176, 231, 143, 176, 235, 143, 176, 238, 143,
+176, 223, 143, 176, 242, 202, 187, 187, 200, 143, 177, 162, 143, 177, 168, 176,
+205, 213, 165, 191, 175, 202, 216, 143, 177, 187, 208, 215, 208, 216, 189, 164,
+202, 240, 143, 177, 203, 143, 177, 207, 143, 177, 211, 143, 177, 216, 208, 235,
+182, 230, 143, 177, 223, 143, 177, 228, 208, 243, 143, 177, 236, 143, 177, 242,
+194, 166, 208, 250, 143, 177, 251, 143, 178, 163, 143, 178, 167, 143, 178, 172,
+208, 253, 183, 185, 209, 161, 143, 178, 185, 143, 178, 189, 193, 206, 143, 178,
+197, 202, 200, 143, 178, 202, 143, 178, 210, 209, 179, 143, 178, 218, 143, 178,
+223, 209, 184, 189, 188, 143, 178, 231, 197, 222, 143, 178, 237, 209, 194, 197,
+181, 209, 196, 209, 198, 209, 204, 180, 167, 209, 209, 186, 227, 143, 178, 252,
+143, 179, 161, 143, 179, 164, 244, 165, 189, 232, 209, 224, 189, 208, 209, 227,
+209, 230, 143, 179, 183, 143, 179, 184, 209, 233, 183, 244, 196, 230, 193, 176,
+143, 179, 193, 143, 179, 199, 143, 179, 201, 143, 179, 203, 143, 179, 206, 143,
+179, 209, 143, 179, 212, 178, 195, 197, 216, 207, 171, 179, 175, 143, 179, 232,
+240, 213, 143, 179, 239, 210, 171, 143, 179, 246, 188, 219, 202, 241, 210, 183,
+186, 252, 210, 186, 143, 180, 175, 210, 190, 143, 180, 182, 143, 180, 183, 198,
+238, 143, 180, 187, 143, 180, 190, 210, 203, 210, 204, 143, 180, 198, 206, 210,
+143, 180, 204, 210, 209, 143, 180, 212, 187, 178, 193, 208, 188, 232, 143, 180,
+224, 194, 254, 143, 180, 227, 210, 222, 177, 165, 143, 180, 230, 200, 221, 143,
+180, 236, 202, 173, 202, 242, 198, 221, 143, 180, 244, 188, 254, 204, 163, 204,
+191, 143, 181, 164, 210, 240, 143, 181, 170, 143, 181, 173, 143, 181, 179, 143,
+181, 183, 143, 181, 185, 211, 166, 211, 175, 143, 181, 191, 143, 181, 193, 143,
+181, 197, 143, 181, 202, 176, 162, 143, 181, 206, 143, 181, 209, 211, 177, 143,
+181, 217, 211, 183, 143, 181, 225, 211, 193, 143, 181, 232, 143, 181, 236, 180,
+238, 183, 246, 143, 181, 244, 143, 181, 245, 143, 181, 249, 143, 182, 161, 143,
+182, 165, 143, 182, 167, 143, 182, 168, 143, 182, 170, 143, 182, 175, 143, 182,
+179, 178, 222, 143, 182, 182, 143, 182, 188, 143, 182, 195, 143, 182, 199, 143,
+182, 200, 180, 239, 143, 182, 210, 211, 230, 211, 231, 211, 233, 143, 182, 221,
+143, 182, 225, 143, 182, 231, 143, 182, 233, 211, 244, 211, 247, 143, 182, 244,
+143, 182, 250, 143, 182, 252, 185, 241, 143, 183, 165, 143, 183, 168, 143, 183,
+171, 143, 183, 177, 143, 183, 182, 212, 173, 143, 183, 188, 212, 175, 212, 179,
+143, 183, 197, 143, 183, 205, 212, 180, 212, 181, 212, 182, 143, 183, 220, 143,
+183, 225, 212, 184, 143, 183, 230, 143, 183, 231, 212, 191, 199, 184, 143, 183,
+239, 143, 183, 243, 180, 240, 143, 183, 251, 194, 196, 143, 184, 165, 180, 174,
+190, 236, 143, 184, 172, 143, 184, 173, 197, 227, 186, 201, 143, 184, 183, 212,
+199, 143, 184, 185, 143, 184, 189, 202, 232, 143, 184, 199, 203, 207, 143, 184,
+206, 143, 184, 208, 195, 197, 212, 219, 212, 224, 143, 184, 221, 143, 184, 222,
+212, 232, 202, 209, 143, 184, 228, 143, 184, 231, 194, 231, 188, 186, 212, 243,
+198, 224, 143, 184, 244, 143, 184, 248, 212, 252, 143, 185, 162, 143, 185, 167,
+199, 165, 143, 185, 172, 143, 185, 174, 197, 202, 143, 185, 182, 143, 185, 185,
+187, 207, 213, 172, 143, 185, 195, 143, 185, 198, 176, 249, 213, 178, 143, 185,
+210, 143, 185, 211, 143, 185, 215, 213, 183, 213, 180, 143, 185, 223, 186, 167,
+143, 185, 228, 143, 185, 231, 143, 185, 235, 143, 185, 238, 143, 185, 243, 143,
+185, 246, 143, 185, 251, 213, 191, 183, 249, 213, 197, 143, 186, 167, 143, 186,
+169, 143, 186, 171, 143, 186, 174, 213, 201, 213, 202, 143, 186, 182, 196, 220,
+213, 206, 213, 210, 143, 186, 187, 213, 212, 204, 210, 213, 216, 213, 218, 143,
+186, 196, 177, 167, 143, 186, 205, 176, 184, 205, 168, 143, 186, 213, 205, 198,
+213, 227, 143, 186, 221, 143, 186, 224, 178, 201, 213, 237, 195, 254, 188, 247,
+176, 211, 213, 245, 143, 186, 235, 213, 248, 143, 186, 244, 198, 244, 213, 252,
+214, 161, 143, 186, 248, 193, 216, 214, 165, 214, 168, 143, 187, 169, 214, 170,
+143, 187, 174, 193, 187, 143, 187, 181, 214, 176, 214, 180, 143, 187, 187, 143,
+187, 188, 178, 229, 143, 187, 192, 214, 183, 191, 242, 214, 194, 214, 193, 143,
+187, 201, 143, 187, 203, 143, 187, 206, 143, 187, 211, 214, 201, 214, 191, 191,
+243, 214, 205, 143, 187, 226, 143, 187, 230, 143, 187, 232, 214, 211, 143, 187,
+240, 143, 230, 244, 214, 217, 143, 187, 247, 214, 221, 192, 238, 185, 170, 184,
+202, 180, 172, 200, 193, 214, 230, 214, 231, 191, 227, 194, 211, 203, 185, 214,
+243, 143, 188, 181, 143, 188, 184, 143, 188, 187, 180, 179, 205, 196, 200, 223,
+196, 236, 214, 249, 143, 188, 201, 176, 195, 143, 188, 207, 206, 247, 179, 199,
+215, 163, 215, 168, 215, 172, 215, 176, 143, 188, 223, 181, 221, 143, 188, 227,
+184, 204, 188, 229, 143, 188, 239, 143, 188, 244, 143, 188, 247, 143, 188, 250,
+201, 167, 190, 180, 143, 189, 166, 183, 194, 143, 189, 171, 215, 208, 143, 189,
+178, 200, 249, 143, 189, 183, 191, 180, 199, 166, 187, 214, 143, 189, 195, 178,
+247, 199, 176, 215, 221, 143, 189, 210, 143, 189, 213, 143, 189, 217, 215, 226,
+143, 189, 220, 143, 189, 222, 215, 240, 143, 189, 228, 215, 239, 178, 184, 183,
+195, 143, 189, 236, 188, 189, 143, 189, 243, 143, 189, 246, 216, 166, 143, 189,
+253, 143, 190, 161, 190, 240, 143, 190, 170, 143, 190, 173, 193, 218, 194, 198,
+216, 185, 216, 180, 143, 190, 188, 182, 242, 216, 195, 143, 190, 202, 216, 198,
+143, 190, 209, 216, 216, 216, 215, 183, 197, 216, 213, 143, 190, 216, 216, 220,
+216, 225, 143, 190, 229, 198, 180, 183, 251, 143, 190, 239, 216, 234, 178, 251,
+143, 190, 246, 216, 239, 196, 168, 216, 246, 143, 191, 167, 178, 230, 216, 254,
+192, 239, 217, 165, 204, 225, 143, 191, 182, 143, 191, 184, 143, 191, 189, 143,
+191, 191, 202, 177, 200, 227, 217, 183, 143, 191, 197, 185, 179, 143, 191, 201,
+202, 250, 217, 187, 195, 180, 217, 188, 192, 219, 143, 191, 214, 143, 191, 216,
+189, 166, 217, 205, 143, 191, 225, 182, 180, 143, 191, 228, 143, 191, 231, 193,
+222, 194, 170, 143, 191, 244, 143, 191, 248, 143, 191, 252, 199, 177, 143, 192,
+167, 199, 211, 143, 192, 174, 191, 228, 183, 199, 143, 192, 180, 143, 192, 183,
+217, 231, 143, 192, 189, 217, 226, 143, 192, 195, 217, 236, 143, 192, 201, 217,
+211, 217, 238, 143, 192, 213, 183, 200, 143, 192, 217, 197, 166, 143, 192, 230,
+143, 192, 231, 204, 206, 183, 226, 143, 192, 238, 143, 192, 242, 143, 192, 247,
+199, 197, 179, 201, 143, 193, 161, 143, 193, 166, 218, 166, 197, 167, 181, 188,
+218, 177, 218, 181, 143, 193, 185, 143, 193, 188, 143, 193, 192, 143, 193, 196,
+218, 189, 202, 252, 218, 195, 143, 193, 206, 218, 201, 143, 193, 210, 218, 202,
+143, 193, 213, 202, 184, 200, 195, 218, 207, 192, 205, 187, 219, 202, 253, 218,
+211, 143, 193, 232, 143, 193, 236, 180, 251, 189, 220, 143, 193, 242, 218, 224,
+143, 193, 249, 218, 230, 143, 194, 166, 143, 194, 172, 195, 235, 143, 194, 179,
+143, 194, 182, 143, 194, 187, 179, 162, 218, 242, 195, 210, 218, 247, 218, 245,
+218, 248, 196, 170, 143, 194, 217, 219, 162, 143, 194, 224, 143, 194, 227, 219,
+163, 219, 165, 143, 194, 234, 219, 170, 194, 216, 205, 173, 143, 194, 241, 196,
+171, 219, 176, 188, 235, 181, 224, 143, 194, 249, 194, 188, 197, 206, 143, 195,
+161, 219, 191, 143, 195, 166, 219, 199, 143, 195, 170, 143, 195, 175, 219, 197,
+143, 195, 177, 143, 195, 181, 143, 195, 188, 199, 240, 143, 195, 193, 219, 207,
+219, 211, 143, 195, 184, 198, 202, 192, 242, 143, 195, 204, 143, 195, 207, 143,
+195, 212, 143, 195, 214, 143, 195, 217, 182, 205, 143, 195, 223, 201, 176, 143,
+195, 228, 143, 195, 233, 199, 223, 219, 231, 143, 195, 241, 143, 195, 245, 196,
+244, 219, 238, 180, 254, 143, 195, 254, 143, 196, 165, 220, 168, 143, 196, 173,
+220, 170, 220, 166, 196, 199, 191, 250, 220, 176, 220, 191, 143, 196, 193, 143,
+196, 195, 201, 246, 220, 194, 143, 196, 204, 143, 196, 209, 207, 176, 186, 231,
+207, 177, 220, 213, 143, 196, 222, 143, 196, 225, 220, 201, 185, 189, 143, 196,
+232, 143, 196, 234, 220, 229, 220, 223, 143, 196, 244, 143, 196, 245, 201, 184,
+220, 235, 220, 211, 220, 247, 220, 237, 143, 197, 170, 181, 204, 220, 243, 143,
+197, 180, 143, 197, 182, 143, 197, 187, 221, 161, 220, 253, 221, 168, 221, 166,
+221, 165, 143, 197, 206, 143, 197, 210, 143, 197, 213, 143, 197, 216, 221, 178,
+205, 243, 143, 197, 226, 143, 197, 230, 178, 164, 205, 223, 182, 214, 221, 188,
+143, 197, 244, 143, 197, 247, 143, 197, 249, 186, 208, 143, 197, 254, 189, 222,
+221, 205, 143, 198, 166, 143, 198, 171, 221, 213, 143, 198, 178, 143, 198, 182,
+221, 218, 221, 219, 221, 221, 143, 198, 192, 143, 198, 195, 143, 198, 199, 181,
+164, 221, 230, 143, 198, 209, 177, 202, 181, 225, 143, 198, 218, 180, 192, 221,
+233, 143, 198, 226, 143, 198, 230, 221, 235, 198, 217, 178, 173, 203, 215, 203,
+247, 202, 168, 143, 198, 246, 200, 231, 143, 198, 254, 143, 199, 163, 222, 165,
+143, 199, 170, 143, 199, 171, 143, 199, 174, 222, 172, 196, 197, 143, 199, 184,
+143, 199, 186, 190, 244, 143, 199, 189, 143, 199, 192, 179, 189, 179, 164, 143,
+199, 198, 205, 176, 143, 199, 203, 143, 199, 206, 143, 199, 208, 143, 199, 212,
+143, 199, 215, 222, 204, 143, 199, 221, 143, 199, 225, 189, 223, 143, 199, 231,
+222, 189, 222, 188, 222, 219, 178, 185, 143, 199, 237, 222, 220, 222, 218, 143,
+199, 251, 143, 200, 161, 222, 208, 143, 200, 165, 200, 174, 189, 224, 143, 200,
+170, 222, 228, 205, 207, 143, 200, 178, 143, 200, 183, 222, 237, 194, 218, 143,
+200, 187, 223, 163, 181, 249, 143, 200, 196, 143, 200, 198, 199, 249, 143, 200,
+204, 143, 200, 208, 222, 243, 143, 200, 212, 143, 200, 217, 189, 225, 196, 172,
+223, 166, 223, 173, 143, 200, 231, 143, 200, 237, 143, 200, 240, 223, 186, 143,
+200, 248, 183, 227, 143, 200, 254, 223, 190, 143, 201, 162, 143, 201, 163, 223,
+171, 143, 201, 169, 143, 201, 173, 223, 198, 223, 202, 195, 245, 223, 208, 143,
+201, 182, 143, 201, 185, 143, 201, 189, 143, 201, 192, 178, 208, 143, 201, 198,
+143, 201, 201, 177, 234, 143, 201, 208, 143, 201, 210, 223, 220, 223, 218, 206,
+245, 143, 201, 218, 223, 223, 223, 216, 223, 226, 143, 201, 230, 177, 235, 143,
+201, 234, 143, 201, 236, 193, 179, 143, 201, 242, 143, 201, 247, 223, 230, 143,
+201, 254, 223, 236, 143, 202, 162, 223, 239, 223, 237, 244, 166, 223, 241, 143,
+202, 174, 223, 245, 197, 245, 223, 246, 143, 202, 187, 187, 184, 223, 253, 224,
+162, 143, 202, 193, 143, 202, 194, 143, 202, 197, 224, 166, 224, 170, 224, 172,
+224, 175, 143, 202, 211, 143, 202, 215, 203, 210, 143, 202, 224, 143, 202, 227,
+224, 182, 224, 183, 181, 190, 184, 164, 190, 245, 143, 202, 242, 143, 202, 245,
+143, 202, 247, 224, 195, 198, 200, 224, 198, 143, 203, 162, 143, 203, 167, 224,
+200, 143, 203, 173, 143, 203, 177, 205, 177, 143, 203, 184, 143, 203, 185, 224,
+213, 189, 195, 143, 203, 199, 224, 217, 143, 203, 207, 143, 203, 210, 143, 203,
+215, 143, 203, 220, 143, 203, 225, 143, 203, 227, 178, 209, 143, 203, 236, 143,
+203, 240, 188, 238, 183, 190, 143, 203, 248, 184, 189, 206, 176, 143, 204, 168,
+143, 204, 170, 143, 204, 178, 143, 204, 182, 143, 204, 184, 143, 204, 189, 143,
+204, 192, 143, 204, 194, 143, 204, 199, 224, 247, 143, 204, 208, 143, 204, 213,
+224, 229, 143, 204, 226, 143, 204, 231, 143, 204, 234, 143, 204, 238, 143, 204,
+242, 143, 204, 245, 225, 166, 143, 204, 252, 143, 204, 254, 185, 249, 197, 188,
+225, 180, 197, 196, 196, 174, 225, 183, 143, 205, 180, 206, 177, 225, 191, 143,
+205, 187, 143, 205, 189, 143, 205, 196, 193, 193, 143, 205, 201, 225, 207, 225,
+215, 225, 214, 143, 205, 211, 225, 218, 143, 205, 216, 143, 205, 221, 143, 205,
+225, 225, 224, 143, 205, 231, 143, 205, 236, 143, 205, 242, 143, 205, 247, 225,
+240, 143, 206, 161, 143, 206, 167, 204, 254, 225, 245, 225, 252, 143, 206, 179,
+197, 208, 143, 206, 182, 187, 169, 226, 173, 143, 206, 193, 200, 233, 226, 176,
+226, 179, 143, 206, 205, 226, 181, 143, 206, 209, 226, 187, 196, 190, 189, 226,
+226, 190, 143, 206, 222, 143, 206, 228, 226, 197, 143, 206, 234, 143, 206, 239,
+143, 206, 243, 143, 206, 248, 143, 206, 253, 143, 207, 163, 143, 207, 168, 226,
+208, 226, 211, 143, 207, 176, 143, 207, 179, 143, 207, 182, 143, 207, 186, 226,
+218, 143, 207, 189, 143, 207, 192, 143, 207, 195, 182, 235, 192, 208, 186, 189,
+226, 230, 143, 207, 212, 181, 206, 203, 164, 185, 220, 143, 207, 225, 143, 207,
+228, 143, 207, 234, 200, 163, 226, 239, 226, 238, 200, 234, 143, 207, 244, 202,
+203, 143, 207, 252, 143, 208, 161, 226, 252, 200, 216, 227, 162, 143, 208, 173,
+176, 235, 143, 208, 185, 143, 208, 188, 143, 208, 190, 143, 208, 191, 143, 208,
+196, 143, 208, 200, 143, 208, 203, 143, 208, 207, 143, 208, 211, 227, 175, 190,
+205, 143, 208, 220, 143, 208, 223, 227, 180, 143, 208, 229, 143, 208, 235, 143,
+208, 238, 143, 208, 242, 143, 208, 244, 143, 208, 249, 143, 208, 252, 199, 233,
+190, 206, 176, 220, 143, 209, 172, 143, 209, 176, 143, 209, 178, 143, 209, 181,
+227, 202, 227, 203, 143, 209, 192, 178, 186, 143, 209, 198, 190, 247, 143, 209,
+206, 143, 209, 208, 143, 209, 211, 143, 209, 216, 143, 209, 219, 227, 221, 143,
+209, 223, 227, 227, 143, 209, 229, 227, 234, 227, 237, 143, 209, 234, 143, 209,
+239, 143, 209, 242, 181, 232, 143, 209, 244, 227, 250, 227, 252, 227, 247, 143,
+210, 163, 143, 210, 167, 195, 222, 228, 184, 228, 170, 228, 172, 143, 210, 180,
+143, 210, 182, 228, 176, 143, 210, 189, 143, 210, 191, 143, 210, 196, 200, 207,
+228, 189, 143, 210, 207, 198, 198, 143, 210, 212, 143, 210, 218, 143, 210, 224,
+228, 194, 143, 210, 231, 143, 210, 233, 143, 210, 237, 228, 213, 143, 210, 244,
+228, 216, 143, 210, 254, 143, 211, 164, 202, 198, 143, 211, 171, 143, 211, 173,
+206, 179, 143, 211, 176, 228, 234, 228, 236, 143, 211, 184, 143, 211, 187, 228,
+245, 228, 246, 143, 211, 199, 228, 250, 181, 234, 143, 211, 205, 143, 211, 209,
+229, 162, 143, 211, 215, 186, 217, 186, 176, 193, 200, 229, 174, 143, 211, 230,
+229, 179, 229, 177, 143, 211, 238, 143, 211, 243, 143, 211, 249, 143, 211, 252,
+229, 194, 188, 250, 143, 212, 166, 143, 212, 169, 143, 212, 174, 143, 212, 177,
+229, 206, 143, 212, 184, 143, 212, 187, 143, 212, 179, 229, 208, 143, 212, 194,
+229, 213, 203, 165, 229, 220, 143, 212, 206, 193, 161, 191, 165, 229, 229, 229,
+234, 143, 212, 221, 229, 239, 143, 212, 226, 143, 212, 229, 229, 251, 180, 204,
+143, 212, 240, 230, 163, 230, 169, 143, 212, 250, 143, 212, 254, 200, 237, 230,
+176, 230, 181, 143, 213, 171, 143, 213, 174, 143, 213, 178, 230, 192, 143, 213,
+183, 143, 213, 185, 143, 213, 187, 143, 213, 190, 143, 213, 194, 230, 203, 185,
+205, 143, 213, 203, 204, 215, 230, 212, 143, 213, 216, 204, 237, 143, 213, 226,
+230, 216, 192, 187, 143, 213, 228, 143, 213, 231, 191, 166, 143, 213, 234, 207,
+190, 190, 211, 184, 212, 143, 213, 241, 143, 213, 242, 176, 223, 143, 213, 245,
+143, 213, 250, 184, 213, 143, 213, 253, 182, 187, 187, 233, 143, 214, 170, 143,
+214, 175, 143, 214, 178, 196, 177, 143, 214, 183, 201, 229, 231, 181, 143, 214,
+193, 231, 171, 194, 220, 231, 174, 231, 178, 231, 177, 143, 214, 209, 231, 187,
+231, 190, 231, 193, 143, 214, 220, 143, 214, 224, 143, 214, 226, 143, 214, 231,
+143, 214, 236, 218, 170, 143, 214, 240, 143, 214, 244, 143, 214, 247, 143, 214,
+248, 231, 217, 143, 215, 161, 143, 215, 165, 143, 215, 167, 231, 226, 143, 215,
+171, 231, 232, 143, 215, 180, 143, 215, 184, 231, 236, 143, 215, 195, 203, 167,
+178, 234, 143, 215, 207, 143, 215, 209, 143, 215, 212, 143, 215, 216, 231, 249,
+231, 247, 183, 212, 232, 173, 143, 215, 233, 143, 215, 234, 195, 227, 232, 166,
+183, 213, 143, 215, 227, 143, 215, 253, 178, 174, 232, 174, 143, 216, 168, 143,
+216, 174, 143, 216, 176, 205, 233, 232, 207, 143, 216, 183, 143, 216, 187, 186,
+218, 143, 216, 191, 232, 203, 143, 216, 196, 143, 216, 198, 143, 216, 201, 232,
+206, 232, 212, 232, 226, 143, 216, 207, 143, 216, 212, 143, 216, 217, 198, 161,
+232, 211, 232, 216, 143, 216, 232, 190, 213, 143, 216, 236, 232, 231, 143, 216,
+240, 143, 216, 244, 143, 216, 247, 143, 216, 251, 143, 216, 254, 143, 217, 162,
+143, 217, 166, 143, 217, 171, 232, 209, 143, 217, 178, 177, 182, 143, 217, 183,
+143, 217, 188, 202, 195, 232, 254, 143, 217, 197, 143, 217, 201, 207, 207, 233,
+177, 143, 217, 216, 143, 217, 220, 177, 242, 143, 217, 228, 204, 244, 143, 217,
+232, 207, 206, 143, 217, 242, 233, 185, 143, 217, 247, 200, 205, 143, 217, 252,
+233, 193, 233, 190, 221, 177, 143, 218, 174, 205, 246, 143, 218, 178, 143, 218,
+183, 233, 200, 143, 218, 188, 143, 218, 193, 195, 238, 143, 218, 200, 143, 218,
+237, 233, 206, 143, 218, 210, 233, 219, 143, 218, 218, 143, 218, 222, 233, 217,
+233, 220, 233, 221, 233, 222, 194, 253, 203, 170, 233, 235, 195, 216, 143, 218,
+254, 143, 219, 162, 143, 219, 166, 143, 219, 172, 143, 219, 174, 233, 251, 143,
+219, 177, 233, 253, 233, 247, 234, 167, 143, 219, 192, 143, 219, 196, 234, 165,
+143, 219, 203, 205, 230, 234, 175, 143, 219, 214, 143, 219, 217, 143, 219, 222,
+143, 219, 226, 234, 187, 143, 219, 232, 143, 219, 237, 234, 192, 143, 219, 248,
+143, 219, 250, 234, 197, 143, 220, 164, 222, 167, 179, 185, 185, 213, 234, 206,
+234, 210, 182, 222, 194, 222, 194, 181, 143, 220, 190, 143, 220, 192, 184, 211,
+143, 220, 195, 143, 220, 197, 234, 227, 143, 220, 206, 234, 235, 234, 236, 234,
+233, 143, 220, 214, 179, 236, 143, 220, 222, 234, 243, 143, 220, 228, 143, 220,
+233, 234, 247, 143, 220, 240, 143, 220, 243, 235, 162, 143, 220, 250, 143, 220,
+254, 202, 164, 143, 221, 166, 179, 208, 143, 221, 173, 235, 178, 235, 180, 179,
+209, 235, 185, 191, 168, 143, 221, 189, 143, 221, 193, 143, 221, 197, 143, 221,
+199, 235, 194, 235, 196, 143, 221, 210, 191, 199, 143, 221, 217, 186, 190, 235,
+199, 143, 221, 229, 181, 205, 143, 221, 235, 235, 209, 143, 221, 243, 143, 221,
+248, 235, 216, 198, 201, 143, 222, 162, 235, 219, 180, 210, 207, 192, 235, 227,
+235, 221, 143, 222, 180, 143, 222, 183, 143, 222, 191, 235, 226, 143, 222, 189,
+235, 245, 235, 240, 235, 244, 143, 222, 201, 143, 222, 202, 201, 232, 183, 217,
+181, 196, 143, 222, 213, 218, 206, 143, 222, 221, 143, 222, 224, 195, 171, 236,
+175, 143, 222, 233, 236, 181, 190, 221, 208, 174, 143, 222, 250, 236, 186, 203,
+198, 236, 194, 185, 215, 192, 213, 236, 202, 178, 236, 194, 177, 143, 223, 178,
+199, 229, 188, 193, 143, 223, 187, 143, 223, 191, 143, 223, 194, 236, 219, 192,
+214, 143, 223, 201, 143, 223, 202, 177, 219, 143, 223, 209, 143, 223, 211, 143,
+223, 214, 143, 223, 218, 143, 223, 222, 143, 223, 227, 143, 223, 230, 236, 240,
+236, 238, 143, 223, 242, 236, 245, 236, 244, 143, 223, 250, 236, 247, 237, 169,
+236, 253, 143, 224, 171, 236, 254, 143, 224, 177, 143, 224, 181, 143, 224, 184,
+189, 179, 237, 175, 237, 179, 143, 224, 198, 237, 186, 191, 200, 143, 224, 209,
+143, 224, 212, 188, 214, 143, 224, 219, 198, 240, 237, 199, 143, 224, 225, 143,
+224, 230, 237, 210, 143, 224, 235, 143, 224, 239, 206, 216, 143, 224, 248, 237,
+217, 237, 219, 143, 225, 166, 143, 225, 170, 191, 201, 143, 225, 177, 237, 231,
+202, 213, 203, 248, 183, 222, 237, 233, 143, 225, 195, 143, 225, 197, 237, 254,
+143, 225, 203, 143, 225, 206, 237, 248, 194, 164, 143, 225, 212, 143, 225, 216,
+238, 167, 238, 166, 198, 187, 143, 225, 223, 143, 225, 226, 238, 175, 206, 203,
+237, 238, 205, 184, 143, 225, 241, 143, 225, 245, 238, 184, 143, 225, 251, 143,
+226, 163, 143, 226, 173, 143, 226, 169, 201, 244, 143, 226, 178, 143, 226, 179,
+143, 226, 185, 238, 192, 143, 226, 193, 143, 226, 199, 143, 226, 203, 143, 226,
+209, 143, 226, 212, 188, 242, 143, 226, 220, 189, 183, 185, 243, 143, 226, 228,
+238, 204, 143, 226, 237, 143, 226, 240, 238, 208, 238, 211, 143, 226, 254, 238,
+216, 143, 227, 164, 191, 203, 182, 252, 143, 227, 179, 143, 227, 182, 143, 227,
+187, 143, 227, 193, 143, 227, 198, 143, 227, 203, 143, 227, 207, 143, 227, 213,
+197, 180, 143, 227, 223, 143, 227, 226, 200, 173, 143, 227, 236, 143, 227, 242,
+189, 198, 143, 227, 251, 143, 227, 254, 143, 228, 164, 143, 228, 169, 238, 248,
+143, 228, 181, 143, 228, 188, 143, 228, 193, 143, 228, 200, 143, 228, 205, 181,
+248, 143, 228, 212, 143, 228, 214, 191, 238, 239, 162, 207, 163, 143, 228, 230,
+238, 253, 143, 228, 235, 143, 228, 241, 143, 228, 243, 239, 171, 143, 229, 161,
+143, 229, 167, 143, 229, 172, 143, 229, 176, 143, 229, 181, 143, 229, 183, 143,
+229, 188, 143, 229, 195, 239, 178, 182, 192, 143, 229, 207, 143, 229, 212, 143,
+229, 217, 143, 229, 222, 239, 197, 239, 195, 239, 196, 143, 229, 231, 143, 229,
+236, 143, 229, 238, 143, 229, 241, 239, 206, 239, 209, 239, 216, 196, 185, 239,
+217, 143, 230, 164, 239, 221, 239, 224, 143, 230, 173, 143, 230, 176, 239, 234,
+239, 235, 198, 174, 239, 243, 201, 236, 143, 230, 201, 143, 230, 203, 193, 203,
+239, 251, 143, 230, 214, 143, 230, 217, 240, 165, 198, 171, 143, 230, 224, 231,
+161, 240, 168, 143, 230, 233, 143, 230, 237, 143, 230, 240, 191, 253, 143, 230,
+242, 240, 186, 143, 230, 249, 143, 230, 250, 206, 237, 188, 251, 206, 238, 240,
+195, 143, 231, 167, 240, 199, 240, 201, 240, 205, 192, 196, 240, 208, 240, 211,
+240, 215, 143, 231, 191, 240, 217, 240, 223, 143, 231, 199, 240, 228, 202, 220,
+143, 231, 210, 240, 231, 143, 231, 223, 143, 231, 228, 143, 231, 235, 240, 236,
+143, 231, 240, 202, 199, 240, 243, 143, 231, 249, 143, 231, 252, 143, 232, 161,
+143, 232, 167, 143, 232, 170, 179, 220, 180, 234, 143, 232, 180, 143, 232, 185,
+201, 247, 143, 232, 190, 143, 232, 195, 143, 232, 199, 200, 244, 143, 232, 202,
+200, 211, 187, 244, 143, 232, 209, 143, 232, 211, 143, 232, 216, 143, 232, 220,
+143, 232, 223, 143, 232, 230, 241, 189, 241, 190, 143, 232, 242, 188, 243, 241,
+198, 143, 232, 251, 143, 233, 162, 194, 204, 195, 243, 143, 233, 170, 143, 233,
+173, 241, 209, 241, 211, 241, 215, 241, 214, 241, 217, 143, 233, 194, 143, 233,
+197, 241, 219, 143, 233, 204, 143, 233, 207, 241, 225, 241, 229, 241, 233, 185,
+252, 143, 233, 218, 241, 238, 143, 233, 228, 143, 233, 231, 143, 233, 236, 143,
+233, 240, 241, 249, 143, 233, 247, 143, 233, 254, 143, 234, 167, 242, 163, 242,
+166, 143, 234, 178, 143, 234, 182, 179, 161, 143, 234, 187, 143, 234, 189, 143,
+234, 194, 143, 234, 200, 143, 234, 205, 143, 234, 209, 143, 234, 215, 242, 184,
+143, 234, 223, 143, 234, 226, 143, 234, 230, 143, 234, 234, 242, 196, 143, 234,
+242, 194, 228, 143, 234, 247, 143, 234, 251, 143, 235, 161, 242, 218, 143, 235,
+168, 143, 235, 172, 143, 235, 177, 201, 201, 143, 235, 186, 143, 235, 188, 143,
+235, 194, 143, 235, 200, 143, 235, 205, 143, 235, 211, 242, 233, 196, 187, 242,
+236, 143, 235, 222, 178, 170, 143, 235, 225, 242, 245, 143, 235, 229, 143, 235,
+234, 242, 247, 243, 165, 177, 173, 143, 235, 248, 143, 235, 252, 143, 236, 163,
+143, 236, 167, 143, 236, 173, 143, 236, 175, 243, 170, 143, 236, 180, 143, 236,
+183, 143, 236, 186, 243, 186, 143, 236, 193, 143, 236, 198, 143, 236, 202, 243,
+191, 143, 236, 207, 143, 236, 210, 243, 193, 243, 195, 188, 175, 243, 200, 243,
+203, 206, 219, 243, 207, 143, 236, 238, 221, 224, 143, 236, 242, 185, 245, 243,
+217, 143, 236, 247, 143, 236, 252, 243, 228, 243, 231, 143, 237, 168, 143, 237,
+175, 143, 237, 178, 143, 237, 182, 201, 161, 143, 237, 194, 240, 237, 143, 237,
+202, 243, 245, 143, 237, 210, 143, 237, 214, 206, 182, 143, 237, 222, 143, 237,
+224, 161, 170, 161, 220, 163, 181, 161, 169, 163, 201, 163, 211, 161, 207, 163,
+231, 163, 241, 161, 208, 142, 165, 142, 175, 142, 185, 142, 195, 142, 205, 142,
+215, 161, 177
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic () throws CharacterCodingException {
+ encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+ decoder.onMalformedInput(CodingErrorAction.REPORT);
+ CharBuffer inputCB = CharBuffer.allocate(65536);
+ for (int code = 32; code <= 65533; code ++) {
+ if ((encoder.canEncode((char) code))
+ && (code != 165) && (code != 8254) && (code != 63599)) {
+ inputCB.put((char) code);
+ }
+ }
+ inputCB.rewind();
+ ByteBuffer intermediateBB = encoder.encode(inputCB);
+ inputCB.rewind();
+ intermediateBB.rewind();
+ CharBuffer outputCB = decoder.decode(intermediateBB);
+ outputCB.rewind();
+ assertEqualCBs("decode(encode(A)) must be identical with A!",
+ inputCB, outputCB);
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_KR.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_KR.java
new file mode 100644
index 0000000..c64e0b9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_EUC_KR.java
@@ -0,0 +1,477 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_MultiByte_EUC_KR extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "EUC-KR";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 164, 167, 168, 170, 173, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186,
+188, 189, 190, 191, 198, 208, 215, 216, 222, 223, 230, 240, 247, 248, 254, 273,
+294, 305, 319, 329, 339, 358, 711, 728, 913, 923, 933, 945, 955, 965, 1025, 1040,
+1050, 1060, 1070, 1080, 1090, 1100, 8213, 8224, 8240, 8251, 8308, 8319, 8451, 8467, 8481, 8491,
+8531, 8541, 8551, 8561, 8592, 8658, 8704, 8715, 8730, 8741, 8756, 8786, 8800, 8810, 8834, 8857,
+8869, 8978, 9312, 9322, 9332, 9342, 9372, 9382, 9392, 9424, 9434, 9444, 9472, 9484, 9494, 9504,
+9514, 9524, 9534, 9544, 9618, 9632, 9650, 9660, 9670, 9680, 9733, 9743, 9756, 9792, 9824, 9834,
+12288, 12298, 12308, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12449, 12459, 12469, 12479,
+12489, 12499, 12509, 12519, 12529, 12593, 12603, 12613, 12623, 12633, 12643, 12653, 12663, 12673, 12683, 12800,
+12810, 12820, 12896, 12906, 12916, 12927, 13184, 13194, 13204, 13214, 13224, 13234, 13244, 13254, 13264, 13275,
+19968, 19978, 19988, 19998, 20013, 20024, 20034, 20045, 20056, 20075, 20086, 20098, 20108, 20120, 20130, 20140,
+20150, 20160, 20170, 20180, 20191, 20208, 20219, 20233, 20271, 20282, 20294, 20304, 20314, 20329, 20339, 20350,
+20360, 20374, 20398, 20415, 20425, 20435, 20445, 20462, 20472, 20482, 20493, 20505, 20515, 20525, 20539, 20551,
+20565, 20581, 20596, 20608, 20621, 20632, 20652, 20663, 20677, 20687, 20698, 20709, 20729, 20740, 20754, 20767,
+20778, 20791, 20801, 20811, 20828, 20839, 20849, 20860, 20870, 20882, 20896, 20906, 20918, 20932, 20956, 20976,
+20986, 20998, 21009, 21021, 21033, 21046, 21059, 21069, 21083, 21097, 21109, 21119, 21129, 21147, 21161, 21182,
+21193, 21205, 21215, 21235, 21246, 21256, 21269, 21280, 21290, 21305, 21315, 21325, 21335, 21350, 21360, 21373,
+21395, 21407, 21421, 21435, 21448, 21460, 21473, 21483, 21496, 21507, 21517, 21531, 21542, 21555, 21566, 21576,
+21608, 21619, 21629, 21644, 21668, 21683, 21693, 21704, 21729, 21741, 21754, 21764, 21774, 21788, 21807, 21822,
+21839, 21854, 21884, 21894, 21912, 21927, 21957, 21972, 21983, 22013, 22025, 22036, 22063, 22099, 22120, 22132,
+22150, 22181, 22196, 22218, 22234, 22256, 22266, 22276, 22290, 22303, 22317, 22331, 22343, 22353, 22369, 22382,
+22396, 22408, 22419, 22432, 22467, 22478, 22495, 22512, 22522, 22533, 22558, 22570, 22580, 22602, 22612, 22622,
+22645, 22659, 22675, 22686, 22696, 22707, 22718, 22734, 22744, 22756, 22767, 22777, 22799, 22809, 22823, 22833,
+22846, 22856, 22868, 22880, 22890, 22900, 22914, 22931, 22949, 22969, 22979, 22992, 23002, 23014, 23032, 23043,
+23057, 23067, 23077, 23094, 23105, 23130, 23142, 23186, 23204, 23233, 23244, 23265, 23301, 23318, 23338, 23360,
+23376, 23386, 23396, 23408, 23418, 23429, 23439, 23449, 23459, 23470, 23480, 23490, 23500, 23511, 23521, 23531,
+23541, 23553, 23563, 23574, 23588, 23601, 23611, 23621, 23633, 23643, 23653, 23663, 23673, 23696, 23713, 23723,
+23733, 23744, 23769, 23784, 23796, 23815, 23825, 23847, 23883, 23913, 23943, 23965, 23978, 23992, 24013, 24029,
+24039, 24049, 24061, 24076, 24086, 24101, 24115, 24125, 24135, 24149, 24159, 24178, 24188, 24199, 24213, 24224,
+24235, 24245, 24258, 24272, 24282, 24300, 24310, 24321, 24335, 24347, 24358, 24369, 24380, 24392, 24406, 24418,
+24428, 24439, 24449, 24459, 24471, 24481, 24494, 24505, 24515, 24525, 24535, 24555, 24565, 24575, 24591, 24604,
+24615, 24641, 24653, 24665, 24675, 24685, 24709, 24724, 24735, 24752, 24764, 24775, 24785, 24796, 24816, 24826,
+24838, 24853, 24863, 24880, 24892, 24903, 24915, 24925, 24935, 24950, 24961, 24974, 24984, 24996, 25006, 25018,
+25031, 25062, 25074, 25084, 25095, 25105, 25119, 25130, 25140, 25150, 25160, 25171, 25198, 25209, 25220, 25233,
+25243, 25259, 25269, 25282, 25292, 25302, 25324, 25335, 25345, 25361, 25387, 25402, 25417, 25429, 25447, 25458,
+25471, 25481, 25494, 25504, 25514, 25536, 25551, 25562, 25581, 25591, 25613, 25623, 25634, 25644, 25658, 25688,
+25705, 25720, 25736, 25746, 25758, 25771, 25787, 25797, 25810, 25825, 25836, 25850, 25860, 25880, 25891, 25903,
+25913, 25925, 25935, 25950, 25964, 25975, 25986, 25996, 26007, 26017, 26027, 26039, 26049, 26059, 26071, 26083,
+26093, 26106, 26118, 26128, 26142, 26152, 26164, 26177, 26187, 26201, 26212, 26222, 26232, 26244, 26254, 26264,
+26274, 26286, 26297, 26308, 26326, 26336, 26352, 26362, 26376, 26388, 26398, 26408, 26420, 26438, 26448, 26460,
+26477, 26487, 26503, 26515, 26525, 26543, 26558, 26575, 26586, 26601, 26611, 26622, 26642, 26657, 26671, 26681,
+26691, 26702, 26733, 26751, 26767, 26781, 26791, 26801, 26820, 26834, 26847, 26862, 26873, 26885, 26898, 26919,
+26941, 26954, 26964, 26974, 26984, 26997, 27029, 27045, 27060, 27073, 27083, 27112, 27131, 27146, 27159, 27169,
+27189, 27204, 27218, 27231, 27243, 27264, 27277, 27287, 27298, 27315, 27330, 27347, 27382, 27396, 27410, 27424,
+27442, 27453, 27463, 27487, 27498, 27511, 27523, 27542, 27566, 27578, 27589, 27599, 27611, 27627, 27656, 27667,
+27683, 27700, 27710, 27726, 27738, 27752, 27762, 27773, 27783, 27794, 27819, 27832, 27842, 27852, 27863, 27873,
+27883, 27915, 27927, 27941, 27954, 27965, 27993, 28003, 28014, 28024, 28037, 28049, 28079, 28096, 28107, 28120,
+28136, 28147, 28183, 28193, 28203, 28214, 28227, 28237, 28248, 28263, 28274, 28304, 28316, 28330, 28342, 28354,
+28364, 28399, 28414, 28431, 28448, 28459, 28472, 28497, 28507, 28525, 28538, 28548, 28558, 28579, 28590, 28601,
+28611, 28629, 28639, 28649, 28670, 28681, 28693, 28703, 28719, 28734, 28748, 28760, 28771, 28784, 28796, 28810,
+28824, 28836, 28847, 28857, 28872, 28888, 28913, 28925, 28937, 28953, 28966, 28976, 28999, 29014, 29028, 29038,
+29053, 29065, 29076, 29087, 29100, 29113, 29123, 29134, 29151, 29165, 29179, 29190, 29200, 29211, 29226, 29237,
+29248, 29260, 29272, 29282, 29298, 29309, 29346, 29356, 29376, 29390, 29401, 29417, 29432, 29450, 29462, 29477,
+29494, 29508, 29520, 29544, 29554, 29572, 29582, 29592, 29607, 29618, 29632, 29642, 29654, 29664, 29674, 29687,
+29697, 29715, 29728, 29738, 29748, 29759, 29771, 29781, 29791, 29801, 29822, 29833, 29848, 29859, 29872, 29885,
+29898, 29908, 29920, 29934, 29953, 29969, 29979, 29989, 30000, 30010, 30023, 30033, 30043, 30053, 30063, 30074,
+30086, 30097, 30109, 30123, 30133, 30146, 30157, 30168, 30178, 30192, 30202, 30221, 30233, 30244, 30267, 30284,
+30294, 30305, 30316, 30328, 30340, 30350, 30382, 30394, 30406, 30418, 30428, 30439, 30450, 30460, 30472, 30494,
+30505, 30519, 30541, 30555, 30566, 30585, 30603, 30622, 30636, 30651, 30679, 30690, 30701, 30722, 30738, 30757,
+30770, 30789, 30799, 30813, 30827, 30844, 30855, 30865, 30883, 30906, 30917, 30928, 30952, 30965, 30977, 30990,
+31018, 31034, 31047, 31062, 31072, 31085, 31098, 31117, 31142, 31153, 31165, 31177, 31189, 31199, 31209, 31227,
+31237, 31252, 31263, 31278, 31291, 31302, 31319, 31329, 31339, 31350, 31361, 31378, 31391, 31401, 31418, 31428,
+31447, 31459, 31469, 31481, 31503, 31513, 31526, 31545, 31558, 31568, 31584, 31596, 31613, 31623, 31636, 31649,
+31661, 31672, 31684, 31698, 31712, 31751, 31762, 31774, 31786, 31805, 31820, 31840, 31852, 31875, 31890, 31903,
+31918, 31929, 31946, 31958, 31968, 31995, 32005, 32016, 32026, 32043, 32053, 32066, 32080, 32094, 32104, 32114,
+32127, 32142, 32156, 32172, 32184, 32199, 32214, 32224, 32236, 32251, 32265, 32277, 32287, 32299, 32311, 32321,
+32338, 32350, 32361, 32377, 32396, 32406, 32566, 32588, 32618, 32629, 32645, 32660, 32670, 32680, 32690, 32701,
+32714, 32724, 32735, 32745, 32761, 32771, 32784, 32813, 32829, 32842, 32854, 32879, 32893, 32903, 32918, 32929,
+32943, 32954, 32964, 32974, 32986, 32996, 33009, 33021, 33031, 33048, 33059, 33071, 33081, 33099, 33109, 33125,
+33136, 33146, 33160, 33178, 33192, 33203, 33213, 33229, 33240, 33251, 33261, 33274, 33285, 33298, 33308, 33322,
+33333, 33344, 33369, 33380, 33390, 33400, 33419, 33433, 33445, 33455, 33465, 33489, 33499, 33509, 33521, 33533,
+33545, 33559, 33576, 33588, 33600, 33610, 33651, 33673, 33686, 33698, 33725, 33737, 33747, 33769, 33780, 33795,
+33805, 33833, 33848, 33865, 33879, 33889, 33899, 33909, 33936, 33948, 33970, 33980, 33990, 34001, 34028, 34044,
+34065, 34078, 34092, 34109, 34121, 34131, 34147, 34157, 34180, 34191, 34203, 34214, 34224, 34234, 34249, 34261,
+34276, 34295, 34306, 34326, 34349, 34367, 34382, 34395, 34407, 34425, 34442, 34467, 34503, 34516, 34527, 34541,
+34558, 34568, 34584, 34638, 34655, 34676, 34690, 34701, 34719, 34739, 34756, 34784, 34796, 34809, 34821, 34847,
+34865, 34875, 34886, 34898, 34909, 34920, 34930, 34942, 34952, 34962, 34974, 34987, 35009, 35023, 35033, 35048,
+35059, 35069, 35079, 35090, 35109, 35126, 35137, 35167, 35178, 35199, 35211, 35222, 35233, 35250, 35261, 35282,
+35299, 35316, 35328, 35338, 35350, 35363, 35373, 35386, 35408, 35419, 35430, 35440, 35461, 35475, 35486, 35496,
+35506, 35516, 35527, 35538, 35548, 35558, 35569, 35582, 35598, 35609, 35624, 35635, 35649, 35662, 35672, 35686,
+35696, 35709, 35722, 35734, 35895, 35905, 35916, 35930, 35946, 35961, 35978, 35997, 36007, 36019, 36029, 36039,
+36049, 36060, 36070, 36084, 36100, 36115, 36196, 36208, 36229, 36249, 36259, 36275, 36286, 36299, 36315, 36328,
+36339, 36362, 36382, 36394, 36405, 36418, 36441, 36468, 36481, 36493, 36522, 36544, 36554, 36575, 36587, 36600,
+36611, 36626, 36636, 36646, 36659, 36670, 36681, 36701, 36763, 36774, 36784, 36802, 36814, 36838, 36848, 36861,
+36872, 36884, 36894, 36910, 36920, 36930, 36941, 36953, 36963, 36973, 36983, 36993, 37007, 37017, 37027, 37039,
+37057, 37086, 37096, 37109, 37122, 37138, 37159, 37170, 37193, 37218, 37228, 37239, 37255, 37266, 37276, 37291,
+37301, 37312, 37323, 37335, 37347, 37365, 37389, 37399, 37428, 37439, 37449, 37463, 37474, 37504, 37521, 37532,
+37555, 37580, 37604, 37624, 37636, 37648, 37658, 37668, 37678, 37704, 37716, 37742, 37756, 37772, 37782, 37795,
+37805, 37827, 37841, 37854, 37878, 37892, 37912, 37925, 37941, 37956, 37969, 37979, 38013, 38263, 38275, 38287,
+38307, 38317, 38331, 38343, 38356, 38369, 38428, 38442, 38459, 38475, 38491, 38506, 38517, 38533, 38548, 38563,
+38577, 38587, 38597, 38613, 38626, 38639, 38649, 38662, 38673, 38684, 38695, 38706, 38717, 38728, 38742, 38753,
+38765, 38775, 38795, 38816, 38827, 38854, 38867, 38899, 38911, 38922, 38935, 38957, 38968, 38982, 38996, 39006,
+39019, 39080, 39108, 39131, 39149, 39164, 39177, 39187, 39198, 39208, 39237, 39249, 39318, 39333, 39345, 39361,
+39376, 39389, 39405, 39423, 39438, 39449, 39467, 39478, 39488, 39501, 39511, 39522, 39592, 39608, 39635, 39653,
+39706, 39719, 39729, 39740, 39759, 39770, 39791, 39822, 39839, 39851, 39881, 39894, 39908, 39949, 39973, 39986,
+40007, 40023, 40165, 40179, 40201, 40219, 40230, 40251, 40273, 40285, 40300, 40361, 40372, 40388, 40407, 40434,
+40474, 40565, 40575, 40594, 40605, 40628, 40638, 40653, 40664, 40680, 40692, 40711, 40723, 40736, 40763, 40778,
+40799, 40810, 40823, 40845, 40860, 44032, 44042, 44052, 44064, 44076, 44088, 44107, 44120, 44144, 44154, 44164,
+44176, 44188, 44200, 44216, 44228, 44245, 44256, 44266, 44277, 44288, 44300, 44312, 44329, 44340, 44356, 44368,
+44385, 44396, 44406, 44417, 44428, 44444, 44471, 44481, 44496, 44508, 44536, 44552, 44564, 44592, 44602, 44613,
+44624, 44636, 44648, 44664, 44676, 44732, 44748, 44760, 44776, 44788, 44807, 44844, 44860, 44872, 44892, 44921,
+44932, 44944, 44956, 44984, 44999, 45012, 45032, 45044, 45056, 45068, 45084, 45096, 45124, 45134, 45145, 45180,
+45196, 45208, 45218, 45228, 45240, 45252, 45264, 45280, 45320, 45330, 45340, 45352, 45364, 45376, 45392, 45404,
+45432, 45442, 45453, 45464, 45480, 45516, 45532, 45544, 45561, 45572, 45588, 45600, 45620, 45656, 45672, 45684,
+45700, 45712, 45722, 45733, 45744, 45768, 45778, 45789, 45800, 45811, 45823, 45840, 45852, 45908, 45918, 45929,
+45940, 45952, 45964, 45984, 45996, 46020, 46030, 46041, 46052, 46076, 46096, 46108, 46120, 46132, 46160, 46176,
+46188, 46208, 46237, 46248, 46261, 46272, 46288, 46300, 46310, 46321, 46356, 46372, 46384, 46400, 46411, 46428,
+46496, 46506, 46516, 46528, 46540, 46552, 46572, 46608, 46629, 46644, 46664, 46692, 46748, 46763, 46804, 46832,
+46848, 46888, 46904, 46916, 46932, 46944, 46960, 46972, 46988, 46998, 47008, 47019, 47029, 47047, 47084, 47100,
+47111, 47128, 47140, 47156, 47168, 47185, 47196, 47212, 47224, 47245, 47272, 47284, 47296, 47308, 47325, 47336,
+47352, 47364, 47384, 47420, 47436, 47448, 47464, 47476, 47492, 47502, 47532, 47548, 47560, 47570, 47581, 47592,
+47604, 47616, 47637, 47672, 47682, 47693, 47704, 47716, 47728, 47747, 47784, 47794, 47805, 47816, 47832, 47868,
+47885, 47896, 47913, 47924, 47934, 47945, 47956, 47969, 47980, 48008, 48036, 48052, 48064, 48080, 48120, 48130,
+48140, 48150, 48164, 48176, 48192, 48204, 48221, 48260, 48270, 48281, 48292, 48304, 48316, 48333, 48344, 48372,
+48388, 48400, 48420, 48448, 48460, 48472, 48484, 48512, 48522, 48533, 48548, 48560, 48596, 48617, 48628, 48640,
+48652, 48668, 48708, 48718, 48729, 48740, 48752, 48763, 48780, 48792, 48808, 48848, 48864, 48876, 48897, 48920,
+48960, 48976, 49044, 49072, 49093, 49104, 49116, 49212, 49233, 49244, 49256, 49296, 49312, 49324, 49334, 49344,
+49356, 49368, 49380, 49396, 49408, 49424, 49436, 49446, 49456, 49468, 49480, 49492, 49508, 49520, 49541, 49552,
+49564, 49576, 49597, 49608, 49620, 49632, 49648, 49660, 49676, 49688, 49704, 49714, 49736, 49748, 49760, 49772,
+49788, 49800, 49816, 49828, 49844, 49884, 49899, 49910, 49920, 49932, 49944, 49956, 49989, 50024, 50034, 50044,
+50056, 50112, 50136, 50146, 50157, 50168, 50184, 50212, 50224, 50236, 50248, 50276, 50292, 50304, 50324, 50360,
+50409, 50420, 50431, 50444, 50460, 50472, 50488, 50500, 50510, 50520, 50532, 50544, 50556, 50567, 50577, 50588,
+50601, 50612, 50622, 50632, 50644, 50656, 50668, 50678, 50688, 50700, 50712, 50724, 50734, 50745, 50756, 50768,
+50780, 50796, 50808, 50824, 50836, 50852, 50864, 50874, 50885, 50896, 50908, 50920, 50936, 50948, 50964, 50976,
+50992, 51004, 51018, 51028, 51040, 51051, 51061, 51075, 51086, 51096, 51107, 51117, 51132, 51144, 51160, 51172,
+51200, 51210, 51221, 51232, 51244, 51256, 51272, 51284, 51312, 51322, 51333, 51348, 51359, 51388, 51400, 51412,
+51424, 51445, 51456, 51468, 51480, 51500, 51536, 51552, 51564, 51580, 51592, 51608, 51648, 51658, 51669, 51680,
+51692, 51704, 51720, 51732, 51753, 51788, 51804, 51816, 51837, 51864, 51900, 51916, 51928, 51948, 51976, 51988,
+52000, 52033, 52044, 52056, 52068, 52088, 52124, 52152, 52180, 52196, 52236, 52252, 52263, 52280, 52292, 52308,
+52320, 52336, 52376, 52392, 52404, 52420, 52432, 52452, 52464, 52481, 52492, 52504, 52516, 52537, 52572, 52588,
+52600, 52616, 52628, 52644, 52656, 52676, 52688, 52712, 52728, 52740, 52756, 52768, 52784, 52824, 52840, 52852,
+52868, 52880, 52896, 52908, 52929, 52964, 52980, 52992, 53008, 53020, 53036, 53048, 53076, 53092, 53104, 53120,
+53132, 53153, 53168, 53188, 53216, 53232, 53244, 53265, 53293, 53304, 53316, 53328, 53344, 53356, 53372, 53412,
+53428, 53440, 53456, 53468, 53484, 53496, 53517, 53552, 53562, 53572, 53584, 53596, 53608, 53628, 53640, 53664,
+53680, 53690, 53720, 53748, 53767, 53804, 53820, 53832, 53852, 53888, 53904, 53916, 53932, 53944, 53954, 53972,
+53988, 54000, 54016, 54028, 54038, 54048, 54060, 54072, 54084, 54140, 54156, 54168, 54184, 54196, 54212, 54224,
+54241, 54252, 54268, 54280, 54301, 54336, 54364, 54381, 54392, 54402, 54413, 54441, 54476, 54492, 54504, 54520,
+54532, 54548, 54588, 54604, 54616, 54629, 54644, 54660, 54672, 54693, 54728, 54738, 54749, 54760, 54772, 54784,
+54800, 54812, 54829, 54840, 54853, 54865, 54876, 54887, 54897, 54915, 54925, 54941, 54952, 54969, 54980, 54993,
+55008, 55024, 55036, 55057, 55068, 55080, 55092, 55108, 55120, 55136, 55148, 55164, 55176, 55192, 63744, 63754,
+63764, 63774, 63784, 63794, 63804, 63814, 63824, 63834, 63844, 63854, 63864, 63874, 63884, 63894, 63904, 63914,
+63924, 63934, 63944, 63954, 63964, 63974, 63984, 63994, 64004, 65281, 65291, 65301, 65311, 65321, 65331, 65341,
+65351, 65361, 65371, 65504, 65536
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+162, 174, 162, 180, 161, 215, 161, 167, 168, 163, 161, 169, 161, 198, 161, 190,
+169, 247, 169, 248, 162, 165, 162, 210, 161, 164, 162, 172, 169, 246, 168, 172,
+168, 249, 168, 246, 168, 250, 162, 175, 168, 161, 168, 162, 161, 191, 168, 170,
+168, 173, 169, 172, 169, 161, 169, 163, 161, 192, 169, 170, 169, 173, 169, 162,
+168, 164, 169, 165, 168, 168, 169, 176, 169, 171, 168, 174, 162, 167, 162, 168,
+165, 193, 165, 203, 165, 212, 165, 225, 165, 235, 165, 244, 172, 167, 172, 161,
+172, 172, 172, 182, 172, 192, 172, 218, 172, 228, 172, 238, 161, 170, 162, 211,
+162, 182, 161, 216, 169, 249, 169, 250, 161, 201, 167, 164, 162, 229, 161, 202,
+168, 247, 168, 253, 165, 183, 165, 162, 161, 231, 162, 161, 162, 163, 161, 245,
+161, 238, 161, 171, 161, 197, 161, 214, 161, 193, 161, 236, 161, 248, 162, 193,
+161, 209, 161, 210, 168, 231, 168, 241, 169, 231, 169, 241, 169, 205, 169, 215,
+169, 225, 168, 205, 168, 215, 168, 225, 166, 161, 166, 163, 166, 197, 166, 183,
+166, 208, 166, 170, 166, 218, 166, 226, 162, 198, 161, 225, 161, 227, 161, 229,
+161, 223, 162, 196, 161, 218, 162, 206, 162, 208, 161, 207, 162, 188, 162, 220,
+161, 161, 161, 182, 161, 178, 170, 161, 170, 171, 170, 181, 170, 191, 170, 201,
+170, 211, 170, 221, 170, 231, 170, 241, 171, 161, 171, 171, 171, 181, 171, 191,
+171, 201, 171, 211, 171, 221, 171, 231, 171, 241, 164, 161, 164, 171, 164, 181,
+164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 164, 251, 169, 177,
+169, 187, 169, 197, 168, 177, 168, 187, 168, 197, 162, 222, 167, 201, 167, 220,
+167, 216, 167, 176, 167, 190, 167, 193, 167, 208, 167, 239, 167, 234, 167, 228,
+236, 233, 223, 190, 243, 166, 227, 170, 241, 233, 252, 175, 231, 209, 222, 191,
+227, 171, 202, 225, 220, 227, 213, 175, 236, 163, 208, 230, 249, 241, 204, 200,
+211, 162, 228, 167, 208, 209, 237, 168, 244, 181, 228, 230, 236, 242, 249, 242,
+219, 215, 222, 195, 211, 163, 241, 165, 236, 234, 248, 165, 202, 162, 236, 235,
+246, 182, 215, 194, 217, 178, 248, 181, 231, 235, 204, 201, 220, 193, 225, 243,
+220, 228, 220, 177, 219, 195, 253, 166, 219, 167, 232, 222, 229, 166, 202, 163,
+250, 165, 203, 237, 246, 176, 206, 211, 219, 168, 223, 161, 245, 202, 223, 191,
+208, 193, 223, 192, 214, 246, 232, 233, 202, 164, 229, 226, 234, 227, 223, 193,
+233, 208, 213, 227, 235, 195, 208, 186, 212, 223, 210, 174, 205, 236, 204, 194,
+229, 247, 217, 179, 206, 174, 216, 241, 229, 167, 244, 162, 215, 207, 252, 197,
+245, 243, 221, 194, 250, 253, 244, 248, 215, 215, 240, 164, 244, 239, 238, 241,
+203, 167, 237, 165, 243, 220, 244, 249, 215, 177, 213, 244, 240, 190, 250, 182,
+216, 245, 212, 209, 217, 180, 253, 179, 206, 254, 253, 214, 221, 226, 237, 221,
+221, 227, 249, 175, 244, 182, 216, 179, 209, 245, 206, 207, 236, 212, 241, 237,
+228, 237, 234, 171, 230, 244, 203, 219, 233, 209, 226, 210, 231, 213, 208, 163,
+222, 201, 253, 222, 217, 163, 207, 214, 220, 250, 231, 239, 231, 238, 239, 208,
+241, 178, 218, 171, 217, 164, 251, 250, 246, 227, 250, 166, 236, 214, 249, 235,
+234, 172, 205, 214, 248, 212, 248, 166, 215, 218, 216, 197, 234, 230, 246, 228,
+217, 253, 228, 175, 240, 166, 244, 202, 244, 183, 253, 189, 253, 171, 242, 199,
+243, 170, 225, 245, 202, 169, 207, 165, 225, 176, 250, 198, 208, 239, 221, 196,
+252, 247, 230, 191, 229, 241, 210, 165, 225, 246, 205, 221, 205, 179, 229, 216,
+234, 174, 247, 207, 208, 164, 208, 240, 208, 179, 203, 213, 247, 231, 211, 221,
+246, 243, 211, 220, 250, 167, 235, 217, 228, 239, 224, 242, 230, 180, 243, 241,
+208, 241, 204, 177, 244, 220, 202, 237, 237, 222, 206, 212, 247, 178, 223, 221,
+242, 200, 204, 209, 217, 215, 241, 242, 217, 248, 221, 197, 202, 203, 253, 181,
+215, 164, 229, 189, 237, 224, 236, 236, 249, 190, 226, 212, 211, 222, 227, 247,
+250, 241, 210, 175, 221, 198, 238, 245, 247, 172, 210, 191, 229, 253, 208, 245,
+246, 230, 216, 217, 239, 209, 238, 187, 232, 238, 202, 205, 230, 193, 232, 223,
+222, 207, 231, 244, 228, 176, 246, 165, 215, 165, 251, 230, 220, 254, 216, 218,
+227, 184, 202, 170, 250, 238, 238, 213, 251, 251, 248, 198, 222, 174, 223, 197,
+237, 173, 221, 161, 205, 181, 226, 213, 234, 232, 211, 235, 206, 219, 241, 181,
+224, 190, 207, 224, 227, 228, 238, 214, 221, 163, 210, 188, 205, 251, 222, 208,
+245, 193, 220, 230, 227, 252, 244, 211, 233, 214, 246, 166, 205, 182, 203, 220,
+224, 218, 220, 179, 215, 219, 212, 234, 253, 223, 208, 247, 203, 170, 225, 251,
+251, 192, 225, 252, 246, 185, 228, 177, 250, 214, 226, 253, 205, 223, 226, 254,
+218, 174, 227, 161, 207, 169, 212, 241, 229, 245, 231, 174, 232, 228, 244, 185,
+206, 229, 208, 249, 225, 222, 253, 241, 244, 222, 225, 253, 237, 227, 217, 182,
+219, 172, 216, 173, 246, 186, 202, 206, 234, 234, 221, 231, 238, 188, 223, 202,
+205, 183, 228, 221, 223, 203, 207, 170, 241, 183, 213, 230, 230, 197, 220, 167,
+227, 210, 236, 172, 250, 215, 229, 176, 249, 176, 247, 165, 211, 167, 251, 161,
+222, 175, 219, 173, 239, 214, 215, 200, 212, 240, 229, 217, 218, 176, 244, 203,
+227, 253, 236, 219, 242, 164, 246, 225, 210, 183, 221, 200, 228, 232, 214, 187,
+224, 245, 236, 246, 252, 200, 229, 191, 237, 176, 205, 241, 230, 237, 252, 226,
+231, 246, 240, 245, 211, 250, 212, 195, 251, 227, 224, 173, 246, 231, 224, 246,
+203, 240, 228, 195, 202, 239, 252, 202, 227, 229, 235, 219, 248, 244, 247, 228,
+251, 180, 204, 212, 245, 195, 241, 243, 253, 243, 221, 201, 217, 228, 211, 188,
+202, 208, 209, 215, 243, 164, 207, 171, 211, 212, 228, 178, 208, 189, 239, 184,
+211, 227, 213, 232, 251, 195, 246, 232, 221, 202, 221, 235, 244, 252, 229, 228,
+248, 216, 249, 169, 238, 189, 221, 217, 218, 229, 246, 233, 206, 192, 205, 184,
+242, 165, 211, 251, 241, 169, 239, 216, 243, 181, 248, 218, 220, 233, 207, 236,
+223, 242, 211, 252, 228, 250, 213, 211, 240, 194, 202, 209, 217, 218, 229, 192,
+204, 169, 223, 186, 225, 223, 211, 253, 242, 202, 218, 230, 253, 205, 238, 215,
+216, 164, 217, 184, 214, 206, 223, 174, 211, 213, 217, 232, 211, 181, 244, 186,
+208, 211, 211, 228, 235, 244, 247, 236, 247, 204, 229, 193, 213, 253, 242, 168,
+203, 199, 205, 186, 218, 194, 243, 226, 204, 215, 221, 167, 214, 176, 222, 176,
+212, 224, 228, 214, 237, 197, 211, 168, 219, 177, 224, 193, 208, 253, 208, 254,
+233, 239, 232, 218, 205, 224, 221, 203, 220, 181, 237, 198, 217, 219, 240, 197,
+242, 204, 241, 219, 231, 251, 220, 197, 239, 221, 253, 190, 231, 178, 229, 195,
+243, 229, 217, 186, 224, 231, 231, 165, 228, 242, 206, 199, 232, 216, 240, 198,
+234, 197, 222, 253, 209, 161, 217, 202, 218, 211, 202, 210, 238, 167, 212, 225,
+249, 248, 247, 237, 221, 237, 212, 226, 242, 171, 205, 189, 227, 194, 219, 218,
+234, 246, 207, 175, 215, 179, 239, 222, 226, 227, 206, 232, 233, 241, 208, 198,
+211, 254, 242, 238, 242, 205, 202, 212, 205, 217, 240, 201, 231, 252, 205, 225,
+209, 165, 220, 234, 212, 214, 223, 181, 212, 161, 235, 245, 245, 161, 217, 167,
+230, 203, 229, 197, 224, 219, 215, 209, 239, 223, 208, 191, 233, 190, 252, 206,
+215, 180, 205, 190, 207, 176, 206, 170, 208, 167, 219, 224, 238, 192, 217, 188,
+245, 163, 202, 244, 233, 248, 209, 166, 252, 244, 211, 170, 229, 229, 219, 252,
+203, 254, 222, 177, 212, 162, 214, 208, 250, 203, 213, 177, 213, 178, 253, 226,
+233, 176, 253, 227, 250, 206, 230, 162, 232, 224, 213, 246, 228, 234, 227, 214,
+214, 177, 223, 175, 235, 246, 216, 223, 217, 190, 251, 198, 238, 253, 216, 236,
+209, 168, 226, 169, 219, 240, 219, 241, 231, 253, 205, 231, 208, 227, 209, 169,
+230, 204, 217, 210, 216, 200, 221, 243, 251, 162, 249, 178, 222, 223, 248, 220,
+250, 218, 229, 199, 225, 169, 242, 208, 241, 189, 253, 231, 239, 186, 232, 203,
+221, 169, 246, 217, 230, 238, 225, 215, 228, 243, 239, 227, 215, 250, 212, 163,
+239, 228, 226, 232, 223, 182, 212, 164, 224, 222, 231, 183, 219, 203, 211, 172,
+223, 207, 233, 192, 234, 184, 234, 185, 215, 182, 205, 162, 233, 193, 219, 181,
+244, 175, 244, 242, 205, 227, 215, 169, 216, 174, 216, 188, 239, 194, 218, 254,
+237, 214, 211, 193, 237, 210, 243, 165, 248, 177, 249, 212, 252, 232, 211, 194,
+210, 216, 227, 165, 240, 173, 251, 205, 213, 235, 222, 225, 222, 181, 225, 190,
+231, 187, 213, 179, 206, 180, 247, 168, 216, 189, 252, 233, 237, 199, 246, 167,
+253, 220, 225, 191, 251, 166, 239, 195, 214, 173, 251, 244, 204, 222, 220, 235,
+229, 234, 219, 204, 245, 165, 230, 251, 253, 200, 209, 238, 216, 224, 237, 180,
+224, 195, 233, 251, 233, 194, 226, 217, 232, 162, 253, 248, 230, 215, 214, 250,
+231, 189, 245, 183, 253, 184, 248, 239, 214, 211, 213, 180, 240, 208, 237, 201,
+223, 209, 248, 171, 212, 186, 214, 239, 223, 229, 204, 178, 212, 187, 204, 179,
+223, 210, 228, 228, 238, 195, 226, 173, 215, 225, 231, 217, 243, 233, 232, 229,
+235, 162, 232, 171, 237, 239, 212, 188, 252, 242, 250, 220, 239, 233, 209, 172,
+235, 201, 214, 188, 218, 214, 223, 166, 206, 203, 241, 193, 208, 168, 217, 238,
+224, 196, 232, 205, 239, 162, 209, 174, 208, 214, 251, 234, 234, 212, 249, 194,
+227, 162, 251, 169, 208, 200, 214, 162, 215, 243, 209, 176, 252, 187, 223, 222,
+204, 225, 231, 194, 251, 210, 232, 183, 220, 186, 241, 247, 244, 214, 223, 231,
+239, 163, 239, 235, 208, 180, 239, 165, 242, 213, 213, 212, 241, 225, 203, 177,
+203, 178, 235, 247, 223, 168, 230, 185, 237, 183, 202, 178, 236, 183, 212, 227,
+215, 229, 211, 195, 221, 246, 229, 203, 225, 196, 215, 187, 215, 170, 228, 223,
+219, 254, 246, 194, 224, 200, 205, 164, 238, 220, 206, 235, 249, 171, 245, 212,
+221, 206, 249, 236, 212, 168, 214, 212, 216, 238, 218, 240, 247, 175, 242, 216,
+250, 223, 207, 239, 250, 224, 239, 236, 217, 206, 212, 169, 242, 217, 216, 190,
+226, 235, 244, 215, 245, 184, 227, 197, 211, 173, 222, 227, 221, 247, 242, 178,
+248, 223, 208, 169, 230, 218, 245, 166, 215, 188, 221, 221, 239, 237, 221, 248,
+202, 229, 252, 172, 219, 182, 218, 241, 216, 168, 202, 216, 245, 167, 245, 168,
+213, 236, 227, 198, 209, 182, 240, 211, 222, 230, 240, 174, 209, 184, 252, 161,
+229, 221, 212, 170, 208, 216, 220, 188, 221, 249, 240, 213, 242, 241, 236, 185,
+225, 170, 236, 249, 249, 162, 240, 250, 212, 171, 217, 207, 226, 180, 223, 226,
+252, 174, 207, 188, 212, 205, 242, 242, 207, 223, 232, 192, 208, 170, 243, 193,
+217, 223, 241, 226, 202, 230, 241, 211, 251, 238, 223, 233, 221, 172, 225, 171,
+249, 182, 206, 204, 208, 181, 224, 254, 232, 164, 203, 205, 218, 216, 206, 183,
+239, 169, 238, 198, 219, 244, 227, 217, 225, 198, 240, 234, 243, 194, 211, 175,
+237, 216, 244, 216, 241, 195, 214, 235, 215, 230, 221, 251, 216, 163, 225, 216,
+213, 219, 226, 182, 251, 213, 211, 216, 203, 179, 205, 167, 251, 245, 210, 239,
+208, 228, 237, 185, 238, 199, 240, 251, 204, 191, 206, 237, 235, 214, 222, 234,
+207, 189, 239, 242, 240, 252, 226, 184, 215, 198, 246, 197, 223, 253, 244, 243,
+216, 251, 246, 198, 242, 219, 232, 178, 233, 178, 220, 238, 215, 172, 219, 229,
+241, 249, 233, 164, 227, 177, 230, 186, 225, 217, 224, 233, 221, 174, 229, 162,
+241, 170, 216, 225, 212, 254, 205, 196, 226, 186, 224, 204, 253, 253, 233, 226,
+236, 205, 223, 214, 238, 225, 248, 187, 206, 238, 205, 197, 210, 177, 209, 190,
+247, 176, 214, 253, 225, 161, 214, 164, 244, 233, 240, 220, 245, 171, 205, 198,
+208, 233, 248, 203, 241, 176, 247, 195, 219, 207, 235, 202, 206, 205, 210, 246,
+250, 247, 232, 210, 226, 238, 248, 225, 243, 236, 228, 253, 232, 211, 225, 163,
+233, 166, 224, 205, 204, 174, 221, 177, 248, 179, 224, 206, 211, 197, 240, 176,
+213, 196, 227, 237, 246, 171, 211, 230, 207, 192, 224, 162, 226, 239, 249, 254,
+246, 236, 221, 178, 243, 237, 235, 250, 202, 221, 245, 172, 233, 227, 221, 179,
+203, 206, 228, 165, 208, 202, 234, 189, 202, 180, 229, 180, 231, 200, 205, 201,
+216, 201, 217, 171, 237, 188, 252, 237, 226, 240, 251, 170, 212, 229, 215, 233,
+204, 236, 250, 248, 216, 213, 214, 225, 206, 162, 220, 204, 228, 224, 245, 254,
+248, 195, 245, 215, 235, 173, 231, 168, 238, 202, 248, 227, 251, 217, 208, 173,
+226, 189, 223, 170, 248, 228, 243, 239, 224, 182, 222, 238, 220, 239, 214, 254,
+217, 161, 215, 173, 225, 202, 248, 204, 245, 175, 233, 254, 226, 242, 225, 203,
+218, 221, 235, 251, 224, 224, 244, 192, 253, 185, 240, 177, 237, 190, 233, 228,
+212, 246, 238, 203, 231, 222, 229, 238, 213, 181, 213, 161, 251, 219, 250, 200,
+253, 208, 251, 246, 218, 165, 205, 247, 222, 239, 252, 238, 206, 241, 242, 244,
+228, 182, 232, 165, 242, 187, 202, 233, 234, 218, 251, 221, 213, 204, 235, 215,
+217, 173, 211, 217, 246, 222, 218, 246, 224, 209, 250, 175, 227, 178, 213, 197,
+205, 204, 216, 193, 241, 235, 250, 229, 245, 250, 248, 250, 210, 164, 208, 218,
+202, 183, 211, 178, 205, 229, 249, 172, 238, 174, 215, 234, 207, 217, 222, 165,
+223, 215, 240, 178, 220, 220, 248, 230, 233, 179, 227, 168, 203, 186, 208, 220,
+216, 202, 224, 164, 204, 184, 227, 202, 204, 175, 208, 204, 213, 194, 202, 199,
+250, 176, 223, 216, 229, 235, 227, 242, 253, 225, 204, 193, 224, 226, 242, 224,
+222, 241, 238, 204, 227, 203, 253, 254, 241, 202, 224, 165, 229, 222, 252, 239,
+206, 164, 235, 254, 211, 200, 213, 223, 244, 227, 244, 244, 253, 201, 209, 231,
+218, 186, 204, 197, 217, 200, 207, 196, 252, 166, 253, 210, 227, 219, 204, 237,
+236, 161, 231, 226, 220, 168, 243, 217, 205, 219, 252, 195, 232, 213, 212, 202,
+251, 223, 248, 251, 216, 231, 248, 175, 222, 184, 236, 195, 236, 194, 237, 192,
+242, 225, 222, 244, 221, 183, 214, 243, 242, 190, 237, 252, 238, 229, 241, 203,
+245, 177, 240, 225, 246, 172, 240, 235, 242, 191, 219, 162, 247, 245, 206, 165,
+212, 175, 233, 201, 203, 230, 241, 161, 241, 162, 235, 179, 245, 236, 245, 237,
+240, 226, 229, 184, 215, 245, 207, 198, 243, 179, 230, 227, 242, 226, 245, 238,
+206, 242, 244, 229, 246, 202, 214, 166, 241, 205, 239, 173, 239, 174, 230, 172,
+227, 244, 247, 253, 242, 227, 233, 230, 231, 202, 202, 188, 226, 251, 245, 218,
+251, 173, 212, 178, 214, 193, 244, 245, 236, 239, 226, 196, 248, 188, 233, 171,
+204, 186, 240, 228, 244, 195, 216, 228, 213, 164, 216, 215, 209, 225, 202, 251,
+233, 244, 213, 205, 221, 187, 233, 232, 228, 199, 245, 219, 212, 248, 211, 179,
+235, 183, 245, 178, 226, 198, 251, 229, 226, 245, 225, 165, 245, 221, 236, 162,
+203, 217, 229, 212, 224, 183, 225, 242, 240, 229, 243, 251, 212, 239, 235, 205,
+214, 194, 239, 175, 250, 232, 204, 198, 219, 164, 235, 222, 224, 213, 249, 231,
+231, 229, 239, 251, 224, 167, 203, 234, 214, 226, 245, 222, 238, 182, 209, 197,
+205, 209, 231, 204, 228, 200, 235, 185, 246, 221, 204, 199, 225, 240, 251, 175,
+242, 229, 240, 236, 238, 235, 233, 203, 243, 161, 252, 245, 241, 164, 224, 214,
+244, 209, 241, 209, 202, 252, 206, 206, 243, 200, 237, 254, 224, 236, 235, 206,
+202, 200, 213, 239, 231, 162, 228, 225, 249, 239, 244, 197, 221, 189, 248, 161,
+240, 230, 215, 176, 248, 206, 219, 214, 215, 213, 233, 234, 204, 176, 215, 246,
+235, 223, 244, 180, 228, 186, 240, 231, 215, 238, 218, 167, 218, 223, 239, 253,
+239, 197, 223, 220, 217, 246, 214, 218, 240, 184, 214, 196, 239, 254, 218, 188,
+236, 229, 236, 230, 251, 185, 207, 211, 207, 212, 244, 199, 249, 219, 235, 229,
+250, 194, 233, 245, 247, 246, 212, 233, 204, 242, 206, 168, 228, 212, 215, 190,
+239, 181, 249, 166, 248, 253, 222, 171, 246, 208, 222, 248, 250, 195, 228, 187,
+239, 182, 206, 189, 216, 195, 209, 199, 226, 207, 220, 224, 246, 238, 218, 224,
+241, 210, 246, 239, 250, 180, 241, 231, 209, 200, 248, 190, 203, 246, 245, 226,
+216, 233, 253, 164, 250, 208, 213, 240, 205, 233, 250, 181, 226, 208, 231, 163,
+226, 209, 215, 162, 234, 166, 208, 161, 234, 224, 229, 224, 214, 219, 239, 198,
+228, 213, 206, 247, 215, 239, 244, 237, 205, 230, 245, 227, 252, 191, 232, 167,
+203, 190, 215, 247, 240, 232, 220, 243, 228, 188, 234, 196, 228, 236, 251, 248,
+204, 187, 228, 189, 221, 223, 217, 208, 249, 205, 205, 174, 207, 206, 246, 175,
+229, 164, 214, 221, 214, 227, 209, 203, 222, 250, 207, 213, 253, 203, 224, 168,
+217, 249, 211, 218, 218, 189, 232, 168, 205, 213, 224, 169, 222, 172, 240, 186,
+238, 210, 243, 187, 228, 203, 215, 163, 207, 207, 176, 161, 176, 167, 176, 172,
+176, 181, 176, 183, 176, 188, 176, 192, 176, 195, 176, 197, 176, 202, 176, 206,
+176, 213, 176, 215, 176, 220, 176, 226, 176, 232, 176, 235, 176, 237, 176, 242,
+176, 248, 176, 252, 177, 161, 177, 165, 177, 168, 177, 171, 177, 175, 177, 179,
+177, 182, 177, 184, 177, 190, 177, 195, 177, 199, 177, 201, 177, 204, 177, 206,
+177, 209, 177, 212, 177, 215, 177, 221, 177, 225, 177, 226, 177, 231, 177, 235,
+177, 241, 177, 244, 177, 250, 177, 254, 178, 165, 178, 168, 178, 173, 178, 178,
+178, 181, 178, 184, 178, 187, 178, 191, 178, 196, 178, 202, 178, 205, 178, 209,
+178, 211, 178, 213, 178, 216, 178, 217, 178, 221, 178, 227, 178, 229, 178, 233,
+178, 235, 178, 238, 178, 241, 178, 243, 178, 244, 178, 249, 178, 254, 179, 162,
+179, 166, 179, 170, 179, 177, 179, 181, 179, 189, 179, 191, 179, 196, 179, 200,
+179, 202, 179, 207, 179, 212, 179, 217, 179, 219, 179, 224, 179, 228, 179, 233,
+179, 235, 179, 239, 179, 243, 179, 247, 179, 249, 179, 250, 179, 253, 180, 162,
+180, 166, 180, 169, 180, 174, 180, 178, 180, 179, 180, 181, 180, 184, 180, 186,
+180, 189, 180, 192, 180, 197, 180, 201, 180, 205, 180, 207, 180, 211, 180, 215,
+180, 220, 180, 226, 180, 234, 180, 239, 180, 244, 180, 245, 180, 251, 181, 162,
+181, 167, 181, 169, 181, 174, 181, 177, 181, 180, 181, 181, 181, 186, 181, 191,
+181, 195, 181, 197, 181, 198, 181, 200, 181, 202, 181, 205, 181, 206, 181, 210,
+181, 214, 181, 215, 181, 217, 181, 219, 181, 221, 181, 224, 181, 227, 181, 229,
+181, 234, 181, 238, 181, 240, 181, 245, 181, 251, 182, 161, 182, 166, 182, 171,
+182, 176, 182, 180, 182, 185, 182, 190, 182, 192, 182, 197, 182, 198, 182, 199,
+182, 203, 182, 205, 182, 206, 182, 207, 182, 209, 182, 213, 182, 216, 182, 217,
+182, 220, 182, 223, 182, 228, 182, 231, 182, 234, 182, 236, 182, 239, 182, 243,
+182, 247, 182, 253, 183, 164, 183, 167, 183, 171, 183, 173, 183, 175, 183, 179,
+183, 184, 183, 189, 183, 193, 183, 197, 183, 202, 183, 204, 183, 206, 183, 210,
+183, 214, 183, 216, 183, 217, 183, 219, 183, 221, 183, 225, 183, 228, 183, 231,
+183, 235, 183, 239, 183, 240, 183, 242, 183, 246, 183, 249, 183, 253, 184, 163,
+184, 167, 184, 173, 184, 174, 184, 178, 184, 182, 184, 189, 184, 193, 184, 199,
+184, 201, 184, 207, 184, 210, 184, 211, 184, 215, 184, 219, 184, 224, 184, 226,
+184, 231, 184, 235, 184, 240, 184, 245, 184, 249, 184, 251, 184, 252, 184, 254,
+185, 163, 185, 166, 185, 169, 185, 171, 185, 178, 185, 182, 185, 186, 185, 188,
+185, 190, 185, 191, 185, 194, 185, 197, 185, 199, 185, 202, 185, 204, 185, 209,
+185, 213, 185, 219, 185, 227, 185, 232, 185, 236, 185, 242, 185, 245, 185, 246,
+185, 251, 186, 161, 186, 165, 186, 168, 186, 173, 186, 177, 186, 182, 186, 184,
+186, 189, 186, 193, 186, 195, 186, 197, 186, 200, 186, 202, 186, 204, 186, 206,
+186, 212, 186, 216, 186, 220, 186, 221, 186, 223, 186, 227, 186, 229, 186, 231,
+186, 234, 186, 238, 186, 241, 186, 245, 186, 249, 186, 254, 187, 163, 187, 168,
+187, 173, 187, 178, 187, 180, 187, 181, 187, 186, 187, 190, 187, 191, 187, 194,
+187, 199, 187, 203, 187, 206, 187, 207, 187, 208, 187, 211, 187, 213, 187, 216,
+187, 217, 187, 219, 187, 221, 187, 223, 187, 227, 187, 231, 187, 238, 187, 242,
+187, 247, 187, 249, 187, 254, 188, 164, 188, 168, 188, 171, 188, 173, 188, 180,
+188, 185, 188, 190, 188, 192, 188, 197, 188, 201, 188, 206, 188, 209, 188, 213,
+188, 216, 188, 221, 188, 225, 188, 227, 188, 229, 188, 232, 188, 235, 188, 238,
+188, 242, 188, 246, 188, 251, 189, 163, 189, 165, 189, 168, 189, 170, 189, 172,
+189, 176, 189, 180, 189, 183, 189, 186, 189, 191, 189, 195, 189, 200, 189, 205,
+189, 210, 189, 213, 189, 218, 189, 220, 189, 224, 189, 225, 189, 229, 189, 232,
+189, 235, 189, 237, 189, 238, 189, 243, 189, 246, 189, 249, 189, 250, 189, 252,
+189, 254, 190, 162, 190, 164, 190, 165, 190, 169, 190, 172, 190, 173, 190, 175,
+190, 177, 190, 180, 190, 183, 190, 186, 190, 189, 190, 190, 190, 194, 190, 198,
+190, 205, 190, 210, 190, 216, 190, 218, 190, 223, 190, 227, 190, 231, 190, 235,
+190, 237, 190, 238, 190, 245, 190, 250, 191, 163, 191, 165, 191, 169, 191, 174,
+191, 180, 191, 186, 191, 188, 191, 192, 191, 197, 191, 203, 191, 207, 191, 209,
+191, 214, 191, 217, 191, 220, 191, 224, 191, 228, 191, 232, 191, 236, 191, 241,
+191, 245, 191, 248, 191, 250, 191, 254, 192, 164, 192, 167, 192, 171, 192, 175,
+192, 179, 192, 184, 192, 188, 192, 195, 192, 201, 192, 203, 192, 205, 192, 210,
+192, 217, 192, 223, 192, 227, 192, 232, 192, 235, 192, 240, 192, 245, 192, 247,
+192, 250, 192, 254, 193, 164, 193, 168, 193, 170, 193, 174, 193, 177, 193, 181,
+193, 182, 193, 186, 193, 190, 193, 196, 193, 198, 193, 201, 193, 204, 193, 206,
+193, 210, 193, 213, 193, 216, 193, 220, 193, 224, 193, 225, 193, 227, 193, 231,
+193, 234, 193, 237, 193, 238, 193, 242, 193, 246, 193, 251, 194, 161, 194, 167,
+194, 171, 194, 176, 194, 180, 194, 185, 194, 187, 194, 188, 194, 192, 194, 197,
+194, 198, 194, 200, 194, 201, 194, 205, 194, 210, 194, 213, 194, 215, 194, 217,
+194, 219, 194, 221, 194, 224, 194, 226, 194, 229, 194, 230, 194, 232, 194, 233,
+194, 234, 194, 235, 194, 238, 194, 242, 194, 246, 194, 252, 195, 164, 195, 168,
+195, 173, 195, 177, 195, 179, 195, 183, 195, 188, 195, 192, 195, 196, 195, 198,
+195, 200, 195, 201, 195, 204, 195, 206, 195, 210, 195, 213, 195, 214, 195, 217,
+195, 221, 195, 222, 195, 223, 195, 227, 195, 231, 195, 232, 195, 234, 195, 235,
+195, 238, 195, 242, 195, 245, 195, 247, 195, 251, 196, 161, 196, 167, 196, 171,
+196, 175, 196, 179, 196, 183, 196, 188, 196, 190, 196, 191, 196, 196, 196, 201,
+196, 205, 196, 209, 196, 212, 196, 217, 196, 218, 196, 222, 196, 226, 196, 230,
+196, 232, 196, 233, 196, 235, 196, 236, 196, 237, 196, 241, 196, 245, 196, 248,
+196, 250, 196, 253, 197, 161, 197, 165, 197, 168, 197, 169, 197, 173, 197, 176,
+197, 180, 197, 184, 197, 189, 197, 194, 197, 198, 197, 203, 197, 204, 197, 205,
+197, 209, 197, 213, 197, 217, 197, 219, 197, 223, 197, 225, 197, 227, 197, 228,
+197, 232, 197, 236, 197, 239, 197, 240, 197, 242, 197, 245, 197, 249, 197, 253,
+197, 254, 198, 162, 198, 166, 198, 169, 198, 172, 198, 174, 198, 179, 198, 183,
+198, 186, 198, 188, 198, 192, 198, 196, 198, 201, 198, 205, 198, 210, 198, 212,
+198, 217, 198, 219, 198, 223, 198, 228, 198, 232, 198, 236, 198, 239, 198, 243,
+198, 245, 198, 247, 198, 251, 199, 161, 199, 162, 199, 163, 199, 165, 199, 168,
+199, 170, 199, 175, 199, 179, 199, 181, 199, 182, 199, 185, 199, 187, 199, 190,
+199, 193, 199, 196, 199, 199, 199, 203, 199, 207, 199, 211, 199, 216, 199, 220,
+199, 225, 199, 226, 199, 227, 199, 231, 199, 235, 199, 238, 199, 240, 199, 244,
+199, 248, 199, 253, 200, 162, 200, 163, 200, 167, 200, 172, 200, 176, 200, 177,
+200, 180, 200, 182, 200, 185, 200, 188, 200, 191, 200, 194, 200, 196, 200, 200,
+200, 204, 200, 207, 200, 209, 200, 213, 200, 216, 200, 218, 200, 222, 200, 226,
+200, 229, 200, 236, 200, 241, 200, 244, 200, 247, 200, 251, 203, 208, 208, 221,
+209, 226, 209, 239, 210, 167, 210, 196, 210, 208, 210, 222, 210, 234, 212, 230,
+219, 228, 224, 241, 229, 187, 229, 254, 230, 184, 230, 223, 230, 241, 231, 172,
+231, 208, 232, 247, 234, 244, 235, 189, 235, 216, 236, 186, 236, 225, 237, 238,
+247, 200, 163, 161, 163, 171, 163, 181, 163, 191, 163, 201, 163, 211, 163, 221,
+163, 231, 163, 241, 163, 251, 161, 203, 0
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GB2312.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GB2312.java
new file mode 100644
index 0000000..4f6123a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GB2312.java
@@ -0,0 +1,193 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+public class OldCharset_MultiByte_GB2312 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "GB2312";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+164, 167, 168, 176, 177, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243, 247,
+249, 250, 252, 257, 275, 333, 363, 462, 711, 913, 945, 1025, 1055, 1085, 8213, 8243,
+8451, 8544, 8592, 8712, 8743, 8776, 8814, 8857, 8978, 9312, 9342, 9472, 9502, 9532, 9632, 9670,
+9733, 9792, 12288, 12353, 12383, 12413, 12449, 12479, 12509, 12539, 12569, 12832, 19968, 19998, 20029, 20060,
+20094, 20127, 20159, 20189, 20219, 20249, 20280, 20311, 20342, 20372, 20405, 20439, 20472, 20504, 20538, 20570,
+20603, 20643, 20687, 20717, 20747, 20799, 20834, 20864, 20896, 20928, 20960, 20991, 21021, 21051, 21084, 21117,
+21147, 21182, 21215, 21246, 21277, 21307, 21338, 21368, 21400, 21430, 21460, 21490, 21520, 21550, 21584, 21617,
+21647, 21677, 21708, 21738, 21769, 21799, 21830, 21860, 21890, 21927, 21957, 21987, 22017, 22047, 22079, 22114,
+22149, 22179, 22218, 22251, 22281, 22312, 22343, 22374, 22404, 22434, 22466, 22496, 22528, 22558, 22596, 22629,
+22659, 22696, 22737, 22768, 22799, 22829, 22859, 22899, 22930, 22962, 22992, 23033, 23064, 23094, 23125, 23156,
+23186, 23218, 23250, 23281, 23318, 23348, 23379, 23409, 23439, 23472, 23504, 23534, 23567, 23601, 23631, 23662,
+23692, 23723, 23755, 23786, 23822, 23853, 23883, 23913, 23961, 23991, 24027, 24061, 24091, 24123, 24155, 24186,
+24217, 24247, 24278, 24308, 24339, 24369, 24400, 24432, 24464, 24494, 24524, 24554, 24586, 24616, 24651, 24681,
+24713, 24744, 24774, 24806, 24838, 24868, 24904, 24935, 24971, 25001, 25032, 25062, 25094, 25124, 25155, 25187,
+25220, 25250, 25282, 25314, 25345, 25375, 25405, 25438, 25472, 25504, 25534, 25566, 25597, 25627, 25658, 25688,
+25720, 25750, 25781, 25815, 25856, 25893, 25925, 25955, 25991, 26021, 26051, 26082, 26112, 26143, 26174, 26207,
+26238, 26269, 26302, 26332, 26364, 26395, 26426, 26460, 26492, 26522, 26552, 26584, 26621, 26653, 26684, 26720,
+26753, 26786, 26816, 26848, 26881, 26911, 26941, 26973, 27004, 27035, 27067, 27099, 27133, 27167, 27197, 27227,
+27257, 27287, 27424, 27454, 27490, 27521, 27553, 27583, 27617, 27653, 27684, 27714, 27744, 27774, 27807, 27837,
+27867, 27898, 27929, 27961, 27993, 28023, 28053, 28085, 28118, 28151, 28182, 28212, 28243, 28286, 28316, 28346,
+28378, 28409, 28448, 28478, 28508, 28538, 28572, 28608, 28638, 28689, 28725, 28766, 28796, 28828, 28859, 28889,
+28919, 28949, 28982, 29020, 29050, 29080, 29113, 29152, 29190, 29224, 29255, 29286, 29316, 29356, 29389, 29420,
+29450, 29481, 29517, 29548, 29579, 29609, 29640, 29671, 29701, 29733, 29781, 29814, 29852, 29882, 29916, 29951,
+29983, 30014, 30044, 30079, 30109, 30140, 30171, 30201, 30231, 30261, 30292, 30328, 30358, 30388, 30418, 30449,
+30489, 30519, 30554, 30585, 30623, 30653, 30683, 30717, 30748, 30778, 30813, 30844, 30874, 30905, 30937, 30967,
+31006, 31036, 31066, 31096, 31130, 31161, 31192, 31224, 31255, 31287, 31319, 31350, 31381, 31411, 31446, 31481,
+31513, 31544, 31574, 31605, 31636, 31668, 31699, 31729, 31759, 31800, 31859, 31889, 31921, 31957, 31992, 32032,
+32110, 32166, 32315, 32386, 32416, 32446, 32476, 32506, 32536, 32566, 32596, 32626, 32660, 32690, 32724, 32755,
+32786, 32817, 32850, 32881, 32915, 32945, 32982, 33012, 33042, 33073, 33104, 33134, 33167, 33203, 33251, 33281,
+33311, 33342, 33375, 33405, 33436, 33469, 33499, 33529, 33559, 33589, 33620, 33655, 33688, 33718, 33748, 33778,
+33809, 33841, 33873, 33905, 33943, 33976, 34006, 34044, 34074, 34104, 34134, 34164, 34203, 34233, 34268, 34299,
+34343, 34381, 34411, 34442, 34472, 34502, 34532, 34562, 34593, 34623, 34656, 34686, 34719, 34749, 34779, 34809,
+34843, 34873, 34903, 34935, 34966, 34999, 35029, 35059, 35090, 35120, 35166, 35199, 35265, 35299, 35335, 35390,
+35449, 35591, 35622, 35686, 35744, 35774, 35804, 35834, 35864, 35894, 35925, 35955, 35988, 36125, 36155, 36185,
+36215, 36255, 36286, 36317, 36347, 36381, 36413, 36454, 36485, 36523, 36558, 36710, 36740, 36771, 36801, 36831,
+36861, 36891, 36923, 36955, 36989, 37019, 37049, 37079, 37112, 37145, 37177, 37207, 37237, 37274, 37306, 37340,
+37492, 37550, 37694, 37738, 37775, 37834, 37950, 37995, 38025, 38055, 38085, 38115, 38145, 38175, 38206, 38236,
+38271, 38376, 38406, 38442, 38472, 38503, 38533, 38567, 38597, 38632, 38662, 38698, 38738, 38771, 38801, 38831,
+38886, 39029, 39059, 39118, 39181, 39214, 39252, 39282, 39312, 39532, 39562, 39592, 39627, 39659, 39695, 39727,
+39757, 40060, 40090, 40120, 40150, 40479, 40509, 40539, 40574, 40605, 40635, 40667, 40697, 40727, 40759, 40831,
+40863, 65281, 65311, 65341, 65371, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 193, 168, 164, 168, 162,
+168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174, 161, 194,
+168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 173, 168, 177, 168, 163,
+161, 166, 166, 161, 166, 193, 167, 167, 167, 177, 167, 223, 161, 170, 161, 229,
+161, 230, 162, 241, 161, 251, 161, 202, 161, 196, 161, 214, 161, 218, 161, 209,
+161, 208, 162, 217, 162, 207, 169, 164, 169, 194, 169, 224, 161, 246, 161, 244,
+161, 239, 161, 226, 161, 161, 164, 161, 164, 191, 164, 221, 165, 161, 165, 191,
+165, 221, 161, 164, 168, 217, 162, 229, 210, 187, 216, 169, 192, 246, 216, 191,
+199, 172, 216, 189, 210, 218, 217, 218, 200, 206, 187, 239, 201, 236, 217, 162,
+217, 165, 217, 176, 199, 214, 203, 215, 217, 186, 204, 200, 213, 174, 215, 246,
+217, 205, 180, 246, 207, 241, 217, 212, 217, 217, 182, 249, 190, 164, 188, 189,
+185, 218, 190, 187, 188, 184, 212, 228, 179, 245, 191, 204, 216, 224, 216, 226,
+193, 166, 219, 192, 196, 188, 185, 180, 212, 209, 210, 189, 178, 169, 208, 182,
+192, 229, 219, 204, 202, 229, 202, 183, 205, 194, 203, 177, 196, 197, 223, 201,
+211, 189, 223, 210, 223, 223, 196, 196, 176, 166, 223, 243, 201, 204, 198, 161,
+206, 185, 208, 250, 208, 225, 203, 195, 224, 210, 224, 189, 186, 217, 224, 222,
+224, 233, 207, 249, 196, 210, 224, 241, 224, 246, 212, 218, 190, 249, 204, 185,
+194, 162, 185, 184, 185, 161, 178, 186, 220, 165, 220, 166, 220, 168, 220, 170,
+190, 179, 196, 171, 219, 214, 201, 249, 207, 196, 216, 178, 183, 220, 197, 174,
+182, 202, 230, 167, 189, 227, 230, 177, 196, 239, 200, 162, 230, 188, 211, 164,
+195, 189, 230, 199, 230, 200, 230, 205, 230, 212, 217, 248, 230, 222, 229, 238,
+186, 234, 212, 215, 195, 194, 229, 188, 208, 161, 190, 205, 198, 193, 229, 248,
+225, 167, 225, 182, 225, 190, 211, 248, 198, 233, 213, 184, 225, 210, 225, 212,
+225, 215, 225, 218, 231, 221, 217, 227, 178, 175, 224, 253, 225, 164, 231, 219,
+195, 237, 191, 181, 193, 206, 219, 200, 185, 173, 200, 245, 229, 230, 213, 195,
+208, 236, 206, 162, 188, 201, 226, 236, 226, 247, 212, 185, 193, 181, 182, 247,
+207, 164, 196, 250, 227, 176, 181, 235, 237, 169, 183, 223, 180, 200, 187, 219,
+177, 239, 237, 172, 208, 184, 197, 179, 237, 176, 234, 174, 236, 231, 191, 219,
+179, 173, 199, 192, 183, 247, 194, 163, 179, 214, 208, 174, 205, 236, 192, 204,
+207, 198, 194, 211, 222, 242, 222, 238, 192, 191, 222, 246, 208, 175, 213, 170,
+195, 254, 222, 254, 196, 236, 223, 168, 197, 202, 223, 172, 185, 202, 201, 162,
+206, 196, 179, 226, 236, 185, 188, 200, 234, 192, 208, 199, 207, 212, 234, 201,
+193, 192, 234, 212, 234, 213, 234, 215, 194, 252, 205, 251, 187, 250, 182, 197,
+232, 204, 195, 182, 232, 219, 232, 207, 232, 223, 232, 233, 184, 241, 232, 226,
+193, 186, 201, 210, 188, 236, 204, 196, 233, 164, 232, 252, 180, 170, 233, 172,
+194, 165, 233, 187, 233, 189, 188, 247, 178, 219, 213, 193, 233, 215, 233, 211,
+233, 214, 233, 222, 199, 183, 191, 238, 214, 185, 233, 226, 233, 235, 181, 238,
+213, 177, 235, 169, 235, 179, 199, 243, 179, 216, 183, 218, 185, 181, 185, 193,
+183, 186, 227, 248, 228, 168, 228, 161, 213, 227, 186, 163, 204, 233, 186, 173,
+196, 215, 187, 236, 228, 201, 191, 202, 228, 212, 205, 229, 193, 239, 196, 231,
+185, 246, 228, 239, 196, 174, 209, 250, 199, 177, 228, 253, 192, 189, 188, 164,
+229, 168, 198, 217, 229, 175, 229, 177, 215, 198, 236, 191, 236, 194, 192, 211,
+205, 233, 187, 192, 200, 187, 236, 207, 236, 213, 236, 214, 236, 228, 236, 219,
+177, 172, 236, 224, 198, 172, 234, 243, 234, 247, 200, 174, 225, 243, 182, 192,
+226, 165, 208, 201, 226, 176, 226, 179, 205, 245, 205, 230, 231, 236, 231, 242,
+192, 197, 231, 250, 232, 166, 209, 254, 232, 171, 232, 183, 185, 207, 234, 179,
+201, 250, 231, 222, 208, 243, 231, 220, 240, 222, 204, 219, 205, 180, 177, 212,
+240, 249, 241, 169, 241, 175, 185, 239, 205, 238, 241, 229, 186, 208, 237, 236,
+237, 244, 190, 236, 237, 253, 182, 195, 238, 169, 238, 173, 195, 172, 206, 249,
+237, 191, 237, 194, 207, 245, 197, 240, 237, 213, 237, 219, 237, 222, 193, 215,
+237, 230, 192, 241, 236, 241, 187, 246, 236, 250, 211, 237, 195, 216, 189, 213,
+176, 222, 240, 162, 203, 235, 190, 191, 241, 187, 241, 193, 202, 250, 214, 241,
+243, 207, 243, 205, 178, 223, 243, 219, 178, 173, 243, 240, 194, 168, 192, 233,
+243, 252, 244, 164, 195, 215, 244, 206, 193, 187, 184, 226, 244, 233, 203, 216,
+208, 245, 244, 235, 247, 227, 215, 235, 190, 192, 231, 163, 194, 231, 231, 184,
+212, 181, 243, 190, 216, 232, 202, 240, 184, 225, 244, 203, 207, 232, 244, 232,
+241, 231, 241, 242, 241, 248, 241, 250, 235, 193, 235, 197, 197, 214, 235, 216,
+235, 223, 205, 209, 184, 175, 200, 249, 184, 224, 201, 197, 179, 188, 244, 168,
+214, 219, 244, 184, 244, 190, 220, 180, 206, 223, 209, 191, 191, 193, 198, 187,
+220, 248, 210, 240, 192, 243, 186, 201, 221, 183, 221, 178, 221, 202, 183, 198,
+221, 200, 221, 230, 221, 215, 180, 208, 221, 245, 213, 244, 177, 205, 222, 164,
+206, 181, 221, 250, 222, 161, 212, 204, 209, 166, 222, 183, 222, 188, 212, 229,
+222, 190, 242, 174, 179, 230, 206, 195, 242, 182, 199, 249, 184, 242, 183, 228,
+192, 175, 242, 234, 242, 240, 242, 238, 195, 248, 243, 174, 243, 178, 208, 183,
+243, 186, 243, 188, 189, 214, 214, 212, 208, 228, 241, 202, 212, 163, 201, 209,
+176, 253, 229, 189, 244, 197, 206, 247, 188, 251, 189, 226, 217, 234, 246, 164,
+213, 178, 229, 192, 246, 165, 190, 175, 218, 165, 201, 232, 218, 183, 197, 181,
+218, 209, 218, 223, 245, 185, 225, 217, 245, 249, 177, 180, 234, 221, 234, 231,
+198, 240, 204, 203, 214, 186, 190, 224, 245, 210, 245, 215, 245, 225, 177, 196,
+245, 238, 201, 237, 234, 166, 179, 181, 233, 252, 192, 177, 199, 168, 179, 217,
+215, 183, 185, 228, 194, 223, 229, 222, 229, 225, 218, 246, 215, 222, 219, 173,
+181, 166, 177, 201, 219, 184, 208, 239, 189, 205, 195, 209, 245, 184, 184, 170,
+188, 248, 246, 199, 246, 201, 246, 202, 246, 204, 246, 203, 246, 205, 246, 206,
+182, 164, 190, 251, 199, 166, 207, 179, 203, 248, 239, 191, 239, 204, 190, 181,
+179, 164, 195, 197, 227, 207, 218, 230, 179, 194, 218, 237, 211, 231, 203, 237,
+209, 197, 211, 234, 246, 170, 246, 175, 199, 224, 189, 249, 247, 178, 247, 181,
+206, 164, 210, 179, 205, 199, 183, 231, 247, 208, 247, 209, 247, 211, 203, 199,
+226, 202, 194, 237, 230, 234, 185, 199, 247, 197, 247, 216, 247, 221, 219, 203,
+247, 205, 211, 227, 246, 221, 190, 168, 177, 238, 196, 241, 184, 235, 240, 204,
+245, 186, 247, 234, 194, 233, 247, 236, 237, 233, 216, 187, 247, 251, 179, 221,
+185, 234, 163, 161, 163, 191, 163, 221, 163, 251, 161, 233
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic() throws CharacterCodingException {
+ super.test_CodecDynamic();
+ }
+
+ @Override
+ public void test_Decode() throws CharacterCodingException {
+ super.test_Decode();
+ }
+
+ @Override
+ public void test_Encode() throws CharacterCodingException {
+ super.test_Encode();
+ }
+
+ @Override
+ public void test_nameMatch() {
+ super.test_nameMatch();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK.java
new file mode 100644
index 0000000..8de181b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK.java
@@ -0,0 +1,511 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** @hide
+ * SEE correspondig_Android test class:
+ */
+
+public class OldCharset_MultiByte_GBK extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "GBK";
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+164, 167, 168, 176, 177, 183, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243,
+247, 249, 250, 252, 257, 275, 299, 324, 363, 462, 472, 593, 609, 711, 729, 913,
+923, 933, 945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230,
+8240, 8251, 8451, 8470, 8481, 8544, 8554, 8564, 8592, 8712, 8725, 8735, 8745, 8756, 8776, 8786,
+8800, 8814, 8857, 8869, 8895, 8978, 9312, 9332, 9342, 9352, 9362, 9472, 9482, 9492, 9502, 9512,
+9522, 9532, 9542, 9552, 9562, 9572, 9582, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733,
+9792, 12288, 12298, 12308, 12318, 12328, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443,
+12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523, 12533, 12549, 12559, 12569, 12579, 12832, 12849, 12963,
+13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20038, 20048, 20058, 20068, 20078,
+20088, 20098, 20108, 20118, 20128, 20138, 20148, 20158, 20168, 20178, 20188, 20198, 20208, 20218, 20228, 20238,
+20248, 20258, 20268, 20278, 20288, 20298, 20308, 20318, 20328, 20338, 20348, 20358, 20368, 20378, 20388, 20398,
+20408, 20418, 20428, 20438, 20448, 20458, 20468, 20478, 20488, 20498, 20508, 20518, 20528, 20538, 20548, 20558,
+20568, 20578, 20588, 20598, 20608, 20618, 20628, 20638, 20648, 20658, 20668, 20678, 20688, 20698, 20708, 20718,
+20728, 20738, 20748, 20758, 20768, 20778, 20788, 20798, 20808, 20818, 20828, 20838, 20848, 20858, 20868, 20878,
+20888, 20898, 20908, 20918, 20928, 20938, 20948, 20958, 20968, 20978, 20988, 20998, 21008, 21018, 21028, 21038,
+21048, 21058, 21068, 21078, 21088, 21098, 21108, 21118, 21128, 21138, 21148, 21158, 21168, 21178, 21188, 21198,
+21208, 21218, 21228, 21238, 21248, 21258, 21268, 21278, 21288, 21298, 21308, 21318, 21328, 21338, 21348, 21358,
+21368, 21378, 21388, 21398, 21408, 21418, 21428, 21438, 21448, 21458, 21468, 21478, 21488, 21498, 21508, 21518,
+21528, 21538, 21548, 21558, 21568, 21578, 21588, 21598, 21608, 21618, 21628, 21638, 21648, 21658, 21668, 21678,
+21688, 21698, 21708, 21718, 21728, 21738, 21748, 21758, 21768, 21778, 21788, 21798, 21808, 21818, 21828, 21838,
+21848, 21858, 21868, 21878, 21888, 21898, 21908, 21918, 21928, 21938, 21948, 21958, 21968, 21978, 21988, 21998,
+22008, 22018, 22028, 22038, 22048, 22058, 22068, 22078, 22088, 22098, 22108, 22118, 22128, 22138, 22148, 22158,
+22168, 22178, 22188, 22198, 22208, 22218, 22228, 22238, 22248, 22258, 22268, 22278, 22288, 22298, 22308, 22318,
+22328, 22338, 22348, 22358, 22368, 22378, 22388, 22398, 22408, 22418, 22428, 22438, 22448, 22458, 22468, 22478,
+22488, 22498, 22508, 22518, 22528, 22538, 22548, 22558, 22568, 22578, 22588, 22598, 22608, 22618, 22628, 22638,
+22648, 22658, 22668, 22678, 22688, 22698, 22708, 22718, 22728, 22738, 22748, 22758, 22768, 22778, 22788, 22798,
+22808, 22818, 22828, 22838, 22848, 22858, 22868, 22878, 22888, 22898, 22908, 22918, 22928, 22938, 22948, 22958,
+22968, 22978, 22988, 22998, 23008, 23018, 23028, 23038, 23048, 23058, 23068, 23078, 23088, 23098, 23108, 23118,
+23128, 23138, 23148, 23158, 23168, 23178, 23188, 23198, 23208, 23218, 23228, 23238, 23248, 23258, 23268, 23278,
+23288, 23298, 23308, 23318, 23328, 23338, 23348, 23358, 23368, 23378, 23388, 23398, 23408, 23418, 23428, 23438,
+23448, 23458, 23468, 23478, 23488, 23498, 23508, 23518, 23528, 23538, 23548, 23558, 23568, 23578, 23588, 23598,
+23608, 23618, 23628, 23638, 23648, 23658, 23668, 23678, 23688, 23698, 23708, 23718, 23728, 23738, 23748, 23758,
+23768, 23778, 23788, 23798, 23808, 23818, 23828, 23838, 23848, 23858, 23868, 23878, 23888, 23898, 23908, 23918,
+23928, 23938, 23948, 23958, 23968, 23978, 23988, 23998, 24008, 24018, 24028, 24038, 24048, 24058, 24068, 24078,
+24088, 24098, 24108, 24118, 24128, 24138, 24148, 24158, 24168, 24178, 24188, 24198, 24208, 24218, 24228, 24238,
+24248, 24258, 24268, 24278, 24288, 24298, 24308, 24318, 24328, 24338, 24348, 24358, 24368, 24378, 24388, 24398,
+24408, 24418, 24428, 24438, 24448, 24458, 24468, 24478, 24488, 24498, 24508, 24518, 24528, 24538, 24548, 24558,
+24568, 24578, 24588, 24598, 24608, 24618, 24628, 24638, 24648, 24658, 24668, 24678, 24688, 24698, 24708, 24718,
+24728, 24738, 24748, 24758, 24768, 24778, 24788, 24798, 24808, 24818, 24828, 24838, 24848, 24858, 24868, 24878,
+24888, 24898, 24908, 24918, 24928, 24938, 24948, 24958, 24968, 24978, 24988, 24998, 25008, 25018, 25028, 25038,
+25048, 25058, 25068, 25078, 25088, 25098, 25108, 25118, 25128, 25138, 25148, 25158, 25168, 25178, 25188, 25198,
+25208, 25218, 25228, 25238, 25248, 25258, 25268, 25278, 25288, 25298, 25308, 25318, 25328, 25338, 25348, 25358,
+25368, 25378, 25388, 25398, 25408, 25418, 25428, 25438, 25448, 25458, 25468, 25478, 25488, 25498, 25508, 25518,
+25528, 25538, 25548, 25558, 25568, 25578, 25588, 25598, 25608, 25618, 25628, 25638, 25648, 25658, 25668, 25678,
+25688, 25698, 25708, 25718, 25728, 25738, 25748, 25758, 25768, 25778, 25788, 25798, 25808, 25818, 25828, 25838,
+25848, 25858, 25868, 25878, 25888, 25898, 25908, 25918, 25928, 25938, 25948, 25958, 25968, 25978, 25988, 25998,
+26008, 26018, 26028, 26038, 26048, 26058, 26068, 26078, 26088, 26098, 26108, 26118, 26128, 26138, 26148, 26158,
+26168, 26178, 26188, 26198, 26208, 26218, 26228, 26238, 26248, 26258, 26268, 26278, 26288, 26298, 26308, 26318,
+26328, 26338, 26348, 26358, 26368, 26378, 26388, 26398, 26408, 26418, 26428, 26438, 26448, 26458, 26468, 26478,
+26488, 26498, 26508, 26518, 26528, 26538, 26548, 26558, 26568, 26578, 26588, 26598, 26608, 26618, 26628, 26638,
+26648, 26658, 26668, 26678, 26688, 26698, 26708, 26718, 26728, 26738, 26748, 26758, 26768, 26778, 26788, 26798,
+26808, 26818, 26828, 26838, 26848, 26858, 26868, 26878, 26888, 26898, 26908, 26918, 26928, 26938, 26948, 26958,
+26968, 26978, 26988, 26998, 27008, 27018, 27028, 27038, 27048, 27058, 27068, 27078, 27088, 27098, 27108, 27118,
+27128, 27138, 27148, 27158, 27168, 27178, 27188, 27198, 27208, 27218, 27228, 27238, 27248, 27258, 27268, 27278,
+27288, 27298, 27308, 27318, 27328, 27338, 27348, 27358, 27368, 27378, 27388, 27398, 27408, 27418, 27428, 27438,
+27448, 27458, 27468, 27478, 27488, 27498, 27508, 27518, 27528, 27538, 27548, 27558, 27568, 27578, 27588, 27598,
+27608, 27618, 27628, 27638, 27648, 27658, 27668, 27678, 27688, 27698, 27708, 27718, 27728, 27738, 27748, 27758,
+27768, 27778, 27788, 27798, 27808, 27818, 27828, 27838, 27848, 27858, 27868, 27878, 27888, 27898, 27908, 27918,
+27928, 27938, 27948, 27958, 27968, 27978, 27988, 27998, 28008, 28018, 28028, 28038, 28048, 28058, 28068, 28078,
+28088, 28098, 28108, 28118, 28128, 28138, 28148, 28158, 28168, 28178, 28188, 28198, 28208, 28218, 28228, 28238,
+28248, 28258, 28268, 28278, 28288, 28298, 28308, 28318, 28328, 28338, 28348, 28358, 28368, 28378, 28388, 28398,
+28408, 28418, 28428, 28438, 28448, 28458, 28468, 28478, 28488, 28498, 28508, 28518, 28528, 28538, 28548, 28558,
+28568, 28578, 28588, 28598, 28608, 28618, 28628, 28638, 28648, 28658, 28668, 28678, 28688, 28698, 28708, 28718,
+28728, 28738, 28748, 28758, 28768, 28778, 28788, 28798, 28808, 28818, 28828, 28838, 28848, 28858, 28868, 28878,
+28888, 28898, 28908, 28918, 28928, 28938, 28948, 28958, 28968, 28978, 28988, 28998, 29008, 29018, 29028, 29038,
+29048, 29058, 29068, 29078, 29088, 29098, 29108, 29118, 29128, 29138, 29148, 29158, 29168, 29178, 29188, 29198,
+29208, 29218, 29228, 29238, 29248, 29258, 29268, 29278, 29288, 29298, 29308, 29318, 29328, 29338, 29348, 29358,
+29368, 29378, 29388, 29398, 29408, 29418, 29428, 29438, 29448, 29458, 29468, 29478, 29488, 29498, 29508, 29518,
+29528, 29538, 29548, 29558, 29568, 29578, 29588, 29598, 29608, 29618, 29628, 29638, 29648, 29658, 29668, 29678,
+29688, 29698, 29708, 29718, 29728, 29738, 29748, 29758, 29768, 29778, 29788, 29798, 29808, 29818, 29828, 29838,
+29848, 29858, 29868, 29878, 29888, 29898, 29908, 29918, 29928, 29938, 29948, 29958, 29968, 29978, 29988, 29998,
+30008, 30018, 30028, 30038, 30048, 30058, 30068, 30078, 30088, 30098, 30108, 30118, 30128, 30138, 30148, 30158,
+30168, 30178, 30188, 30198, 30208, 30218, 30228, 30238, 30248, 30258, 30268, 30278, 30288, 30298, 30308, 30318,
+30328, 30338, 30348, 30358, 30368, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448, 30458, 30468, 30478,
+30488, 30498, 30508, 30518, 30528, 30538, 30548, 30558, 30568, 30578, 30588, 30598, 30608, 30618, 30628, 30638,
+30648, 30658, 30668, 30678, 30688, 30698, 30708, 30718, 30728, 30738, 30748, 30758, 30768, 30778, 30788, 30798,
+30808, 30818, 30828, 30838, 30848, 30858, 30868, 30878, 30888, 30898, 30908, 30918, 30928, 30938, 30948, 30958,
+30968, 30978, 30988, 30998, 31008, 31018, 31028, 31038, 31048, 31058, 31068, 31078, 31088, 31098, 31108, 31118,
+31128, 31138, 31148, 31158, 31168, 31178, 31188, 31198, 31208, 31218, 31228, 31238, 31248, 31258, 31268, 31278,
+31288, 31298, 31308, 31318, 31328, 31338, 31348, 31358, 31368, 31378, 31388, 31398, 31408, 31418, 31428, 31438,
+31448, 31458, 31468, 31478, 31488, 31498, 31508, 31518, 31528, 31538, 31548, 31558, 31568, 31578, 31588, 31598,
+31608, 31618, 31628, 31638, 31648, 31658, 31668, 31678, 31688, 31698, 31708, 31718, 31728, 31738, 31748, 31758,
+31768, 31778, 31788, 31798, 31808, 31818, 31828, 31838, 31848, 31858, 31868, 31878, 31888, 31898, 31908, 31918,
+31928, 31938, 31948, 31958, 31968, 31978, 31988, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068, 32078,
+32088, 32098, 32108, 32118, 32128, 32138, 32148, 32158, 32168, 32178, 32188, 32198, 32208, 32218, 32228, 32238,
+32248, 32258, 32268, 32278, 32288, 32298, 32308, 32318, 32328, 32338, 32348, 32358, 32368, 32378, 32388, 32398,
+32408, 32418, 32428, 32438, 32448, 32458, 32468, 32478, 32488, 32498, 32508, 32518, 32528, 32538, 32548, 32558,
+32568, 32578, 32588, 32598, 32608, 32618, 32628, 32638, 32648, 32658, 32668, 32678, 32688, 32698, 32708, 32718,
+32728, 32738, 32748, 32758, 32768, 32778, 32788, 32798, 32808, 32818, 32828, 32838, 32848, 32858, 32868, 32878,
+32888, 32898, 32908, 32918, 32928, 32938, 32948, 32958, 32968, 32978, 32988, 32998, 33008, 33018, 33028, 33038,
+33048, 33058, 33068, 33078, 33088, 33098, 33108, 33118, 33128, 33138, 33148, 33158, 33168, 33178, 33188, 33198,
+33208, 33218, 33228, 33238, 33248, 33258, 33268, 33278, 33288, 33298, 33308, 33318, 33328, 33338, 33348, 33358,
+33368, 33378, 33388, 33398, 33408, 33418, 33428, 33438, 33448, 33458, 33468, 33478, 33488, 33498, 33508, 33518,
+33528, 33538, 33548, 33558, 33568, 33578, 33588, 33598, 33608, 33618, 33628, 33638, 33648, 33658, 33668, 33678,
+33688, 33698, 33708, 33718, 33728, 33738, 33748, 33758, 33768, 33778, 33788, 33798, 33808, 33818, 33828, 33838,
+33848, 33858, 33868, 33878, 33888, 33898, 33908, 33918, 33928, 33938, 33948, 33958, 33968, 33978, 33988, 33998,
+34008, 34018, 34028, 34038, 34048, 34058, 34068, 34078, 34088, 34098, 34108, 34118, 34128, 34138, 34148, 34158,
+34168, 34178, 34188, 34198, 34208, 34218, 34228, 34238, 34248, 34258, 34268, 34278, 34288, 34298, 34308, 34318,
+34328, 34338, 34348, 34358, 34368, 34378, 34388, 34398, 34408, 34418, 34428, 34438, 34448, 34458, 34468, 34478,
+34488, 34498, 34508, 34518, 34528, 34538, 34548, 34558, 34568, 34578, 34588, 34598, 34608, 34618, 34628, 34638,
+34648, 34658, 34668, 34678, 34688, 34698, 34708, 34718, 34728, 34738, 34748, 34758, 34768, 34778, 34788, 34798,
+34808, 34818, 34828, 34838, 34848, 34858, 34868, 34878, 34888, 34898, 34908, 34918, 34928, 34938, 34948, 34958,
+34968, 34978, 34988, 34998, 35008, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35108, 35118,
+35128, 35138, 35148, 35158, 35168, 35178, 35188, 35198, 35208, 35218, 35228, 35238, 35248, 35258, 35268, 35278,
+35288, 35298, 35308, 35318, 35328, 35338, 35348, 35358, 35368, 35378, 35388, 35398, 35408, 35418, 35428, 35438,
+35448, 35458, 35468, 35478, 35488, 35498, 35508, 35518, 35528, 35538, 35548, 35558, 35568, 35578, 35588, 35598,
+35608, 35618, 35628, 35638, 35648, 35658, 35668, 35678, 35688, 35698, 35708, 35718, 35728, 35738, 35748, 35758,
+35768, 35778, 35788, 35798, 35808, 35818, 35828, 35838, 35848, 35858, 35868, 35878, 35888, 35898, 35908, 35918,
+35928, 35938, 35948, 35958, 35968, 35978, 35988, 35998, 36008, 36018, 36028, 36038, 36048, 36058, 36068, 36078,
+36088, 36098, 36108, 36118, 36128, 36138, 36148, 36158, 36168, 36178, 36188, 36198, 36208, 36218, 36228, 36238,
+36248, 36258, 36268, 36278, 36288, 36298, 36308, 36318, 36328, 36338, 36348, 36358, 36368, 36378, 36388, 36398,
+36408, 36418, 36428, 36438, 36448, 36458, 36468, 36478, 36488, 36498, 36508, 36518, 36528, 36538, 36548, 36558,
+36568, 36578, 36588, 36598, 36608, 36618, 36628, 36638, 36648, 36658, 36668, 36678, 36688, 36698, 36708, 36718,
+36728, 36738, 36748, 36758, 36768, 36778, 36788, 36798, 36808, 36818, 36828, 36838, 36848, 36858, 36868, 36878,
+36888, 36898, 36908, 36918, 36928, 36938, 36948, 36958, 36968, 36978, 36988, 36998, 37008, 37018, 37028, 37038,
+37048, 37058, 37068, 37078, 37088, 37098, 37108, 37118, 37128, 37138, 37148, 37158, 37168, 37178, 37188, 37198,
+37208, 37218, 37228, 37238, 37248, 37258, 37268, 37278, 37288, 37298, 37308, 37318, 37328, 37338, 37348, 37358,
+37368, 37378, 37388, 37398, 37408, 37418, 37428, 37438, 37448, 37458, 37468, 37478, 37488, 37498, 37508, 37518,
+37528, 37538, 37548, 37558, 37568, 37578, 37588, 37598, 37608, 37618, 37628, 37638, 37648, 37658, 37668, 37678,
+37688, 37698, 37708, 37718, 37728, 37738, 37748, 37758, 37768, 37778, 37788, 37798, 37808, 37818, 37828, 37838,
+37848, 37858, 37868, 37878, 37888, 37898, 37908, 37918, 37928, 37938, 37948, 37958, 37968, 37978, 37988, 37998,
+38008, 38018, 38028, 38038, 38048, 38058, 38068, 38078, 38088, 38098, 38108, 38118, 38128, 38138, 38148, 38158,
+38168, 38178, 38188, 38198, 38208, 38218, 38228, 38238, 38248, 38258, 38268, 38278, 38288, 38298, 38308, 38318,
+38328, 38338, 38348, 38358, 38368, 38378, 38388, 38398, 38408, 38418, 38428, 38438, 38448, 38458, 38468, 38478,
+38488, 38498, 38508, 38518, 38528, 38538, 38548, 38558, 38568, 38578, 38588, 38598, 38608, 38618, 38628, 38638,
+38648, 38658, 38668, 38678, 38688, 38698, 38708, 38718, 38728, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
+38808, 38818, 38828, 38838, 38848, 38858, 38868, 38878, 38888, 38898, 38908, 38918, 38928, 38938, 38948, 38958,
+38968, 38978, 38988, 38998, 39008, 39018, 39028, 39038, 39048, 39058, 39068, 39078, 39088, 39098, 39108, 39118,
+39128, 39138, 39148, 39158, 39168, 39178, 39188, 39198, 39208, 39218, 39228, 39238, 39248, 39258, 39268, 39278,
+39288, 39298, 39308, 39318, 39328, 39338, 39348, 39358, 39368, 39378, 39388, 39398, 39408, 39418, 39428, 39438,
+39448, 39458, 39468, 39478, 39488, 39498, 39508, 39518, 39528, 39538, 39548, 39558, 39568, 39578, 39588, 39598,
+39608, 39618, 39628, 39638, 39648, 39658, 39668, 39678, 39688, 39698, 39708, 39718, 39728, 39738, 39748, 39758,
+39768, 39778, 39788, 39798, 39808, 39818, 39828, 39838, 39848, 39858, 39868, 39878, 39888, 39898, 39908, 39918,
+39928, 39938, 39948, 39958, 39968, 39978, 39988, 39998, 40008, 40018, 40028, 40038, 40048, 40058, 40068, 40078,
+40088, 40098, 40108, 40118, 40128, 40138, 40148, 40158, 40168, 40178, 40188, 40198, 40208, 40218, 40228, 40238,
+40248, 40258, 40268, 40278, 40288, 40298, 40308, 40318, 40328, 40338, 40348, 40358, 40368, 40378, 40388, 40398,
+40408, 40418, 40428, 40438, 40448, 40458, 40468, 40478, 40488, 40498, 40508, 40518, 40528, 40538, 40548, 40558,
+40568, 40578, 40588, 40598, 40608, 40618, 40628, 40638, 40648, 40658, 40668, 40678, 40688, 40698, 40708, 40718,
+40728, 40738, 40748, 40758, 40768, 40778, 40788, 40798, 40808, 40818, 40828, 40838, 40848, 40858, 40868, 57344,
+57354, 57364, 57374, 57384, 57394, 57404, 57414, 57424, 57434, 57444, 57454, 57464, 57474, 57484, 57494, 57504,
+57514, 57524, 57534, 57544, 57554, 57564, 57574, 57584, 57594, 57604, 57614, 57624, 57634, 57644, 57654, 57664,
+57674, 57684, 57694, 57704, 57714, 57724, 57734, 57744, 57754, 57764, 57774, 57784, 57794, 57804, 57814, 57824,
+57834, 57844, 57854, 57864, 57874, 57884, 57894, 57904, 57914, 57924, 57934, 57944, 57954, 57964, 57974, 57984,
+57994, 58004, 58014, 58024, 58034, 58044, 58054, 58064, 58074, 58084, 58094, 58104, 58114, 58124, 58134, 58144,
+58154, 58164, 58174, 58184, 58194, 58204, 58214, 58224, 58234, 58244, 58254, 58264, 58274, 58284, 58294, 58304,
+58314, 58324, 58334, 58344, 58354, 58364, 58374, 58384, 58394, 58404, 58414, 58424, 58434, 58444, 58454, 58464,
+58474, 58484, 58494, 58504, 58514, 58524, 58534, 58544, 58554, 58564, 58574, 58584, 58594, 58604, 58614, 58624,
+58634, 58644, 58654, 58664, 58674, 58684, 58694, 58704, 58714, 58724, 58734, 58744, 58754, 58764, 58774, 58784,
+58794, 58804, 58814, 58824, 58834, 58844, 58854, 58864, 58874, 58884, 58894, 58904, 58914, 58924, 58934, 58944,
+58954, 58964, 58974, 58984, 58994, 59004, 59014, 59024, 59034, 59044, 59054, 59064, 59074, 59084, 59094, 59104,
+59114, 59124, 59134, 59144, 59154, 59164, 59174, 59184, 59194, 59204, 59214, 59224, 59234, 59244, 59254, 59264,
+59274, 59284, 59294, 59304, 59314, 59324, 59334, 59344, 59354, 59364, 59374, 59384, 59394, 59404, 59414, 59424,
+59434, 59444, 59454, 59464, 59474, 59484, 63788, 63865, 63893, 63975, 63985, 64012, 64024, 64035, 65072, 65082,
+65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65504, 65536
+ });
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 164, 161, 193, 168, 164,
+168, 162, 168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174,
+161, 194, 168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 169, 168, 189,
+168, 177, 168, 163, 168, 182, 168, 187, 168, 192, 161, 166, 168, 66, 166, 161,
+166, 171, 166, 180, 166, 193, 166, 203, 166, 212, 167, 167, 167, 161, 167, 172,
+167, 182, 167, 192, 167, 218, 167, 228, 167, 238, 169, 92, 161, 176, 161, 173,
+161, 235, 161, 249, 161, 230, 161, 237, 169, 89, 162, 241, 162, 251, 162, 165,
+161, 251, 161, 202, 168, 77, 168, 78, 161, 201, 161, 224, 161, 214, 168, 80,
+161, 217, 161, 218, 161, 209, 161, 205, 168, 83, 161, 208, 162, 217, 162, 197,
+162, 207, 162, 177, 162, 187, 169, 164, 169, 174, 169, 184, 169, 194, 169, 204,
+169, 214, 169, 224, 169, 234, 168, 84, 168, 94, 168, 104, 168, 114, 168, 120,
+168, 131, 168, 138, 161, 246, 161, 248, 168, 139, 161, 244, 168, 141, 161, 239,
+161, 226, 161, 161, 161, 182, 161, 178, 168, 149, 169, 71, 164, 161, 164, 171,
+164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 169, 97,
+165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
+165, 245, 168, 197, 168, 207, 168, 217, 168, 227, 162, 229, 169, 90, 169, 73,
+169, 74, 169, 76, 169, 80, 169, 81, 210, 187, 201, 207, 199, 210, 216, 169,
+216, 173, 180, 174, 129, 83, 129, 88, 192, 214, 129, 93, 129, 97, 129, 105,
+129, 112, 129, 121, 182, 254, 129, 129, 217, 239, 129, 136, 129, 140, 129, 147,
+129, 148, 129, 152, 129, 155, 129, 158, 209, 246, 129, 168, 129, 174, 188, 191,
+211, 197, 216, 243, 129, 192, 193, 230, 129, 203, 129, 211, 129, 215, 216, 250,
+129, 220, 129, 226, 217, 174, 129, 237, 129, 242, 129, 249, 130, 64, 206, 234,
+130, 74, 130, 83, 130, 89, 130, 95, 130, 98, 217, 179, 130, 107, 217, 194,
+130, 124, 181, 185, 217, 195, 190, 235, 130, 146, 213, 174, 130, 162, 217, 203,
+130, 176, 130, 184, 217, 204, 197, 188, 191, 254, 130, 214, 130, 223, 130, 233,
+180, 162, 176, 193, 130, 254, 131, 73, 131, 82, 193, 197, 131, 100, 217, 215,
+131, 113, 131, 122, 131, 130, 131, 139, 131, 149, 131, 158, 131, 168, 131, 178,
+207, 200, 131, 186, 182, 181, 131, 199, 192, 188, 131, 205, 131, 209, 131, 214,
+131, 220, 218, 163, 182, 172, 210, 177, 190, 187, 131, 245, 131, 251, 132, 68,
+132, 75, 132, 81, 219, 202, 183, 214, 132, 91, 184, 213, 197, 208, 185, 206,
+200, 175, 188, 193, 216, 221, 198, 202, 132, 133, 188, 244, 132, 146, 132, 155,
+197, 252, 132, 170, 132, 178, 132, 181, 132, 185, 132, 192, 132, 199, 132, 206,
+191, 177, 132, 221, 132, 230, 132, 239, 212, 200, 132, 251, 133, 67, 133, 71,
+133, 77, 133, 85, 133, 92, 133, 97, 133, 101, 178, 169, 194, 177, 216, 180,
+208, 182, 179, 167, 209, 225, 133, 133, 133, 139, 133, 143, 133, 152, 133, 160,
+211, 214, 133, 170, 133, 174, 193, 237, 204, 168, 133, 181, 184, 247, 186, 243,
+133, 190, 133, 194, 204, 253, 133, 200, 209, 189, 184, 230, 223, 190, 133, 218,
+214, 220, 223, 218, 186, 244, 197, 216, 184, 192, 223, 203, 223, 229, 134, 66,
+207, 204, 223, 211, 223, 223, 134, 80, 134, 83, 196, 196, 134, 93, 134, 100,
+134, 106, 134, 112, 134, 120, 134, 126, 224, 167, 134, 138, 215, 196, 134, 149,
+134, 156, 134, 164, 216, 196, 224, 164, 191, 166, 186, 176, 224, 184, 134, 192,
+134, 200, 134, 209, 134, 214, 134, 220, 134, 227, 134, 232, 224, 205, 134, 240,
+134, 245, 134, 251, 224, 209, 135, 75, 135, 81, 135, 88, 215, 236, 135, 100,
+135, 109, 135, 116, 224, 224, 135, 130, 135, 135, 135, 143, 135, 151, 186, 191,
+135, 166, 135, 176, 135, 185, 135, 194, 135, 202, 196, 210, 224, 236, 187, 216,
+135, 230, 135, 236, 135, 242, 212, 178, 135, 253, 136, 72, 136, 79, 219, 220,
+136, 90, 219, 224, 219, 208, 136, 106, 215, 185, 198, 186, 136, 118, 136, 124,
+136, 130, 192, 221, 136, 145, 191, 209, 136, 154, 136, 161, 136, 169, 179, 199,
+219, 245, 136, 187, 136, 196, 136, 203, 220, 165, 136, 215, 136, 222, 220, 166,
+136, 236, 136, 244, 136, 253, 137, 71, 137, 79, 137, 86, 137, 95, 137, 102,
+137, 112, 137, 119, 137, 126, 137, 135, 137, 141, 137, 149, 137, 159, 137, 168,
+137, 176, 137, 185, 137, 194, 137, 203, 201, 249, 137, 216, 180, 166, 137, 232,
+137, 238, 137, 244, 137, 248, 137, 253, 138, 67, 138, 71, 177, 188, 138, 81,
+138, 88, 138, 98, 138, 103, 215, 177, 138, 113, 138, 118, 230, 165, 196, 221,
+138, 138, 138, 145, 138, 152, 138, 157, 138, 162, 138, 169, 138, 178, 138, 186,
+230, 174, 138, 195, 196, 200, 138, 208, 138, 217, 138, 223, 138, 231, 138, 238,
+138, 247, 230, 190, 139, 72, 201, 244, 139, 86, 139, 96, 139, 105, 139, 113,
+139, 123, 230, 199, 139, 139, 139, 146, 139, 154, 139, 160, 139, 166, 139, 173,
+139, 182, 139, 192, 139, 201, 230, 212, 139, 219, 139, 229, 217, 248, 139, 246,
+140, 64, 140, 72, 215, 206, 209, 167, 202, 235, 200, 230, 229, 179, 140, 97,
+185, 217, 191, 205, 140, 107, 188, 210, 140, 117, 140, 122, 140, 129, 196, 175,
+213, 175, 140, 150, 181, 188, 189, 171, 140, 168, 201, 208, 211, 200, 140, 185,
+202, 172, 178, 227, 140, 197, 140, 202, 205, 192, 140, 215, 140, 222, 140, 230,
+225, 172, 140, 242, 225, 177, 140, 252, 141, 67, 141, 72, 225, 187, 141, 87,
+141, 96, 141, 104, 141, 109, 141, 117, 141, 126, 141, 133, 180, 222, 225, 198,
+141, 155, 141, 162, 141, 171, 141, 179, 141, 185, 141, 194, 141, 202, 141, 209,
+141, 217, 225, 214, 141, 236, 141, 246, 141, 254, 142, 73, 142, 83, 142, 92,
+142, 101, 142, 110, 142, 119, 215, 243, 142, 128, 142, 133, 142, 138, 142, 144,
+193, 177, 142, 152, 142, 160, 142, 167, 142, 172, 142, 179, 225, 163, 225, 165,
+142, 202, 184, 201, 211, 215, 199, 236, 194, 174, 184, 253, 142, 232, 142, 238,
+211, 185, 142, 251, 143, 68, 193, 206, 143, 83, 226, 222, 219, 200, 222, 195,
+222, 196, 143, 115, 143, 120, 207, 210, 143, 132, 199, 191, 143, 147, 143, 157,
+229, 233, 208, 206, 177, 242, 143, 178, 205, 249, 187, 178, 143, 191, 143, 196,
+225, 229, 143, 211, 225, 232, 210, 228, 236, 254, 143, 232, 226, 232, 226, 229,
+226, 238, 203, 203, 144, 67, 178, 192, 181, 161, 185, 214, 144, 86, 144, 93,
+144, 99, 186, 227, 144, 112, 144, 118, 199, 161, 226, 253, 199, 196, 144, 136,
+144, 143, 144, 148, 208, 252, 144, 158, 144, 165, 190, 170, 144, 180, 144, 185,
+178, 210, 144, 193, 144, 198, 237, 169, 144, 210, 211, 222, 183, 223, 144, 231,
+144, 241, 144, 250, 187, 197, 145, 73, 145, 82, 145, 89, 145, 98, 145, 106,
+145, 116, 145, 124, 145, 134, 145, 143, 145, 149, 145, 158, 145, 166, 145, 173,
+145, 180, 145, 190, 145, 199, 145, 208, 145, 217, 206, 236, 145, 226, 145, 230,
+145, 235, 145, 242, 145, 249, 145, 253, 146, 65, 146, 70, 146, 78, 176, 231,
+146, 86, 146, 91, 146, 98, 182, 182, 191, 217, 146, 112, 146, 119, 146, 124,
+196, 233, 190, 220, 176, 221, 192, 185, 146, 140, 146, 145, 146, 149, 191, 230,
+146, 163, 222, 216, 146, 169, 146, 177, 146, 184, 146, 189, 146, 193, 192, 204,
+146, 206, 146, 212, 146, 218, 146, 226, 198, 254, 146, 235, 146, 242, 222, 231,
+181, 167, 147, 65, 147, 72, 210, 190, 222, 235, 190, 190, 212, 174, 147, 104,
+147, 109, 147, 115, 203, 209, 222, 249, 147, 135, 208, 175, 201, 227, 147, 154,
+213, 170, 147, 170, 147, 178, 147, 187, 147, 194, 147, 200, 147, 208, 215, 178,
+147, 223, 147, 228, 186, 179, 147, 240, 223, 167, 147, 254, 223, 169, 148, 79,
+148, 89, 148, 98, 148, 107, 148, 116, 148, 125, 148, 135, 234, 183, 183, 197,
+208, 167, 148, 158, 148, 164, 182, 216, 202, 253, 148, 183, 148, 193, 148, 200,
+148, 206, 148, 211, 148, 216, 148, 223, 148, 230, 148, 235, 148, 240, 148, 248,
+214, 188, 149, 64, 149, 71, 192, 165, 149, 83, 149, 89, 149, 96, 149, 102,
+149, 107, 149, 114, 201, 206, 234, 205, 149, 133, 149, 139, 199, 231, 193, 192,
+149, 158, 149, 166, 149, 174, 149, 183, 149, 190, 149, 198, 149, 207, 149, 217,
+149, 227, 149, 233, 149, 241, 149, 247, 215, 238, 235, 195, 203, 183, 150, 79,
+196, 190, 150, 90, 150, 97, 184, 203, 178, 196, 150, 113, 150, 118, 150, 123,
+150, 128, 150, 134, 150, 140, 150, 148, 150, 152, 199, 185, 150, 161, 150, 167,
+150, 174, 198, 226, 185, 241, 150, 189, 232, 205, 150, 202, 150, 209, 232, 221,
+150, 216, 150, 224, 150, 232, 150, 240, 232, 238, 232, 240, 189, 219, 151, 66,
+189, 176, 151, 75, 151, 82, 176, 240, 151, 97, 151, 105, 151, 114, 151, 120,
+151, 126, 232, 249, 151, 143, 151, 150, 204, 196, 151, 166, 151, 173, 151, 179,
+151, 187, 189, 183, 151, 202, 151, 209, 210, 172, 151, 225, 151, 232, 151, 242,
+151, 250, 152, 65, 152, 72, 152, 80, 233, 175, 152, 89, 192, 198, 152, 103,
+213, 165, 152, 118, 152, 125, 152, 135, 187, 177, 152, 150, 152, 157, 152, 166,
+152, 175, 152, 183, 152, 192, 152, 202, 152, 209, 186, 225, 152, 224, 233, 208,
+152, 239, 152, 248, 153, 64, 153, 72, 153, 82, 153, 90, 207, 173, 233, 213,
+153, 113, 153, 122, 195, 202, 153, 140, 153, 150, 153, 160, 153, 170, 153, 180,
+153, 190, 153, 200, 153, 210, 153, 220, 153, 230, 153, 240, 236, 163, 153, 254,
+154, 71, 154, 78, 184, 232, 154, 93, 154, 102, 205, 225, 154, 115, 154, 122,
+154, 126, 233, 230, 154, 138, 154, 147, 154, 156, 154, 162, 154, 169, 154, 176,
+154, 179, 154, 186, 154, 194, 154, 201, 154, 209, 154, 216, 198, 248, 154, 224,
+176, 177, 235, 181, 154, 238, 217, 224, 207, 171, 155, 65, 204, 192, 155, 74,
+155, 80, 210, 202, 227, 231, 155, 95, 155, 102, 187, 166, 155, 108, 213, 180,
+155, 119, 155, 125, 155, 130, 155, 134, 204, 169, 227, 248, 228, 167, 228, 169,
+155, 159, 155, 165, 155, 171, 155, 176, 155, 181, 215, 199, 228, 177, 228, 183,
+155, 199, 155, 205, 228, 188, 155, 219, 155, 225, 155, 231, 181, 211, 228, 204,
+186, 212, 155, 250, 204, 202, 196, 215, 228, 196, 156, 83, 156, 88, 156, 94,
+156, 103, 156, 107, 156, 113, 156, 117, 156, 123, 195, 236, 228, 216, 228, 207,
+207, 230, 156, 160, 156, 169, 156, 178, 156, 186, 156, 192, 156, 200, 156, 208,
+156, 214, 228, 209, 156, 225, 156, 232, 156, 239, 185, 246, 194, 203, 156, 253,
+157, 71, 198, 175, 157, 87, 157, 93, 196, 174, 228, 244, 157, 114, 209, 250,
+157, 131, 157, 139, 199, 177, 193, 202, 157, 162, 228, 253, 179, 206, 197, 236,
+157, 191, 157, 199, 157, 208, 229, 164, 188, 164, 157, 232, 157, 240, 229, 168,
+158, 66, 158, 74, 158, 84, 158, 94, 158, 104, 229, 171, 158, 120, 158, 131,
+158, 140, 158, 149, 185, 224, 158, 167, 158, 176, 158, 186, 158, 191, 212, 214,
+158, 203, 179, 180, 236, 191, 158, 223, 158, 228, 158, 233, 158, 236, 158, 244,
+186, 230, 159, 69, 189, 253, 159, 80, 159, 87, 186, 184, 159, 103, 159, 108,
+159, 117, 159, 124, 159, 134, 159, 143, 159, 150, 159, 160, 195, 186, 214, 243,
+236, 212, 159, 188, 159, 196, 159, 204, 236, 218, 159, 219, 159, 227, 159, 235,
+159, 244, 159, 253, 160, 70, 160, 78, 160, 86, 160, 95, 160, 105, 160, 114,
+160, 124, 160, 134, 197, 192, 184, 184, 160, 151, 160, 159, 160, 166, 160, 172,
+160, 177, 201, 252, 160, 190, 160, 195, 160, 201, 160, 210, 160, 219, 160, 227,
+225, 239, 191, 241, 160, 245, 160, 251, 186, 221, 170, 73, 225, 249, 170, 79,
+170, 87, 170, 95, 178, 194, 170, 104, 170, 109, 170, 114, 170, 122, 170, 132,
+170, 139, 170, 148, 226, 179, 171, 68, 171, 77, 171, 84, 171, 91, 171, 99,
+171, 107, 193, 225, 171, 117, 171, 125, 183, 169, 171, 138, 171, 146, 171, 152,
+172, 64, 172, 74, 172, 79, 172, 87, 172, 95, 231, 247, 199, 217, 172, 112,
+172, 121, 172, 132, 232, 164, 172, 144, 185, 229, 172, 160, 173, 69, 232, 172,
+173, 85, 173, 93, 173, 100, 173, 110, 173, 119, 173, 130, 173, 139, 240, 172,
+173, 152, 173, 160, 174, 70, 174, 78, 174, 86, 201, 245, 174, 99, 174, 103,
+181, 233, 174, 111, 189, 231, 174, 124, 174, 131, 183, 172, 179, 235, 174, 154,
+175, 64, 240, 218, 175, 75, 175, 78, 240, 230, 175, 86, 240, 228, 175, 94,
+182, 187, 193, 161, 175, 109, 175, 116, 240, 246, 240, 250, 175, 137, 175, 142,
+175, 146, 175, 151, 241, 162, 176, 65, 176, 73, 176, 81, 176, 88, 176, 97,
+185, 239, 212, 237, 176, 116, 205, 238, 176, 132, 176, 141, 241, 229, 176, 157,
+211, 175, 186, 208, 177, 73, 177, 81, 177, 89, 177, 94, 237, 237, 177, 105,
+177, 115, 237, 243, 177, 128, 191, 244, 215, 197, 177, 146, 177, 154, 178, 65,
+237, 254, 178, 77, 178, 86, 178, 90, 178, 97, 178, 105, 178, 112, 178, 117,
+178, 124, 178, 132, 178, 142, 178, 151, 178, 158, 179, 66, 179, 71, 183, 175,
+179, 83, 197, 248, 237, 191, 237, 206, 197, 233, 237, 194, 179, 113, 237, 202,
+179, 124, 179, 134, 211, 178, 179, 149, 179, 157, 180, 68, 180, 73, 180, 78,
+180, 83, 237, 218, 180, 97, 180, 104, 197, 205, 180, 117, 180, 128, 180, 136,
+180, 143, 180, 151, 180, 160, 181, 72, 181, 81, 181, 90, 237, 231, 201, 231,
+198, 237, 181, 120, 236, 239, 181, 129, 181, 135, 236, 247, 194, 187, 181, 157,
+182, 69, 182, 78, 182, 87, 182, 96, 208, 227, 182, 106, 182, 112, 182, 120,
+182, 125, 182, 131, 182, 139, 239, 249, 182, 151, 214, 201, 183, 68, 183, 78,
+183, 86, 183, 91, 183, 100, 183, 109, 183, 118, 183, 129, 209, 168, 183, 142,
+241, 186, 214, 207, 180, 220, 241, 188, 184, 72, 184, 81, 184, 90, 184, 99,
+184, 108, 184, 114, 184, 121, 184, 130, 184, 136, 243, 201, 177, 202, 243, 215,
+177, 191, 185, 66, 193, 253, 185, 80, 191, 240, 243, 217, 185, 94, 243, 223,
+185, 109, 185, 115, 185, 124, 185, 131, 185, 138, 243, 236, 243, 240, 185, 155,
+186, 65, 186, 73, 186, 80, 243, 247, 186, 94, 186, 102, 186, 110, 186, 117,
+186, 125, 186, 135, 186, 142, 186, 152, 244, 166, 187, 71, 187, 80, 187, 90,
+187, 100, 187, 110, 244, 204, 187, 125, 187, 135, 187, 140, 212, 193, 193, 184,
+187, 158, 188, 66, 244, 216, 204, 199, 191, 183, 188, 92, 188, 101, 188, 109,
+188, 119, 188, 129, 188, 139, 188, 147, 188, 154, 189, 67, 189, 77, 189, 87,
+189, 97, 189, 107, 189, 117, 189, 126, 189, 136, 189, 146, 189, 156, 190, 69,
+190, 78, 190, 87, 190, 97, 190, 107, 190, 117, 190, 128, 190, 138, 190, 148,
+190, 158, 191, 71, 191, 81, 191, 91, 191, 101, 191, 111, 191, 121, 191, 131,
+191, 139, 191, 149, 191, 159, 192, 72, 192, 82, 192, 92, 192, 101, 192, 111,
+192, 121, 186, 236, 206, 179, 194, 218, 231, 164, 176, 237, 231, 171, 189, 202,
+231, 176, 231, 181, 215, 219, 192, 194, 192, 137, 184, 191, 231, 205, 201, 201,
+184, 215, 243, 191, 192, 155, 193, 64, 193, 70, 215, 239, 238, 188, 238, 192,
+193, 98, 193, 105, 193, 113, 193, 118, 244, 202, 193, 133, 193, 139, 244, 225,
+199, 204, 193, 159, 194, 69, 194, 75, 210, 171, 194, 87, 241, 232, 194, 95,
+241, 241, 194, 106, 194, 110, 241, 246, 194, 121, 190, 219, 194, 138, 194, 146,
+194, 155, 195, 66, 188, 161, 208, 164, 179, 166, 183, 190, 235, 200, 201, 246,
+195, 95, 195, 102, 202, 164, 195, 111, 210, 200, 176, 183, 195, 122, 235, 219,
+235, 228, 195, 138, 235, 227, 235, 225, 196, 64, 192, 176, 199, 187, 196, 82,
+196, 89, 196, 94, 235, 239, 196, 104, 196, 111, 196, 119, 196, 125, 196, 133,
+196, 142, 177, 219, 235, 251, 197, 66, 197, 76, 215, 212, 214, 194, 244, 167,
+197, 100, 202, 230, 203, 180, 197, 118, 189, 162, 197, 123, 244, 185, 197, 138,
+203, 210, 197, 154, 198, 66, 198, 70, 198, 75, 220, 183, 198, 85, 198, 90,
+220, 184, 198, 95, 198, 100, 198, 106, 198, 108, 198, 111, 220, 214, 198, 120,
+198, 126, 195, 175, 220, 221, 198, 140, 198, 146, 198, 154, 220, 238, 199, 64,
+199, 70, 187, 196, 220, 234, 220, 253, 199, 84, 199, 92, 199, 99, 201, 175,
+221, 183, 199, 118, 199, 124, 221, 178, 221, 210, 190, 213, 221, 202, 199, 151,
+199, 157, 183, 198, 200, 73, 221, 201, 200, 83, 200, 91, 211, 169, 200, 104,
+221, 199, 200, 120, 200, 130, 200, 139, 200, 144, 200, 151, 200, 156, 201, 65,
+221, 220, 201, 78, 203, 226, 201, 94, 201, 103, 221, 240, 208, 238, 201, 121,
+201, 128, 201, 135, 197, 238, 201, 150, 201, 158, 202, 71, 202, 78, 202, 86,
+202, 94, 202, 102, 176, 170, 202, 114, 202, 121, 202, 130, 222, 168, 202, 147,
+202, 155, 203, 64, 203, 71, 203, 80, 203, 88, 208, 189, 203, 102, 203, 110,
+203, 119, 203, 126, 222, 188, 203, 143, 203, 152, 204, 65, 204, 73, 204, 82,
+204, 90, 204, 100, 204, 108, 204, 118, 204, 126, 204, 137, 242, 175, 211, 221,
+204, 158, 205, 67, 242, 180, 205, 77, 205, 83, 205, 91, 212, 233, 205, 102,
+205, 106, 205, 114, 205, 118, 205, 123, 205, 129, 205, 137, 242, 211, 182, 234,
+242, 218, 209, 209, 195, 219, 206, 70, 206, 78, 206, 85, 206, 92, 208, 171,
+206, 105, 206, 113, 206, 120, 181, 251, 206, 133, 206, 139, 206, 146, 206, 155,
+242, 253, 207, 72, 207, 79, 243, 161, 207, 94, 207, 101, 207, 109, 243, 181,
+207, 126, 207, 135, 207, 143, 243, 182, 207, 159, 208, 70, 208, 79, 208, 87,
+208, 94, 208, 102, 208, 109, 208, 114, 203, 165, 208, 126, 176, 192, 208, 137,
+208, 145, 241, 200, 209, 64, 209, 72, 209, 80, 209, 85, 210, 225, 209, 99,
+241, 212, 209, 111, 241, 211, 209, 124, 186, 214, 241, 210, 209, 147, 209, 154,
+210, 64, 210, 73, 210, 82, 210, 92, 210, 100, 210, 109, 210, 119, 210, 129,
+210, 135, 210, 145, 210, 155, 211, 68, 211, 78, 211, 88, 185, 230, 234, 236,
+211, 101, 211, 108, 211, 114, 211, 122, 209, 212, 211, 141, 211, 151, 212, 64,
+212, 74, 212, 84, 212, 94, 212, 103, 212, 112, 212, 122, 212, 133, 212, 143,
+212, 153, 213, 65, 213, 73, 213, 82, 213, 92, 213, 102, 213, 112, 213, 122,
+213, 133, 213, 143, 213, 153, 214, 66, 214, 76, 214, 86, 214, 96, 214, 105,
+214, 115, 214, 125, 214, 135, 214, 145, 214, 155, 215, 68, 215, 78, 215, 88,
+215, 97, 215, 106, 215, 116, 215, 126, 215, 137, 215, 147, 200, 207, 210, 233,
+208, 237, 218, 172, 214, 223, 218, 180, 218, 185, 215, 158, 203, 181, 191, 206,
+204, 184, 218, 203, 195, 213, 199, 171, 192, 190, 216, 66, 216, 75, 216, 81,
+216, 90, 187, 191, 216, 105, 216, 114, 216, 121, 245, 246, 245, 249, 216, 145,
+216, 155, 217, 68, 217, 78, 217, 88, 217, 98, 217, 108, 217, 118, 217, 129,
+217, 139, 217, 149, 217, 159, 218, 72, 218, 79, 204, 176, 204, 249, 188, 214,
+234, 226, 218, 81, 216, 211, 201, 226, 215, 223, 218, 95, 244, 242, 218, 110,
+218, 118, 218, 128, 218, 137, 218, 143, 218, 148, 218, 155, 218, 160, 245, 200,
+191, 231, 219, 79, 219, 82, 219, 90, 219, 96, 219, 105, 219, 110, 245, 218,
+219, 123, 245, 229, 219, 132, 219, 140, 219, 149, 219, 157, 245, 237, 220, 72,
+220, 78, 220, 86, 245, 242, 220, 103, 220, 110, 204, 201, 220, 129, 234, 166,
+220, 148, 220, 158, 221, 71, 221, 81, 221, 91, 221, 101, 221, 111, 221, 121,
+221, 132, 221, 142, 221, 152, 222, 65, 222, 75, 222, 85, 222, 95, 194, 214,
+233, 244, 233, 251, 222, 99, 207, 189, 222, 102, 222, 109, 222, 116, 180, 239,
+194, 245, 222, 134, 212, 182, 229, 200, 202, 246, 222, 149, 229, 204, 222, 157,
+222, 160, 183, 234, 223, 74, 229, 212, 223, 85, 223, 91, 223, 95, 223, 102,
+229, 219, 223, 116, 223, 124, 223, 130, 223, 138, 223, 143, 223, 148, 211, 202,
+219, 161, 224, 64, 224, 70, 224, 75, 224, 81, 224, 86, 179, 187, 219, 177,
+224, 107, 224, 117, 224, 126, 224, 134, 224, 143, 224, 151, 224, 160, 244, 252,
+225, 72, 245, 161, 179, 234, 195, 184, 225, 87, 225, 94, 225, 98, 225, 106,
+225, 114, 225, 120, 225, 128, 225, 138, 225, 141, 225, 150, 225, 159, 226, 72,
+226, 82, 226, 92, 226, 102, 226, 112, 226, 122, 226, 133, 226, 143, 226, 153,
+227, 66, 227, 76, 227, 86, 227, 96, 227, 106, 227, 115, 227, 125, 246, 198,
+227, 145, 227, 155, 228, 68, 228, 77, 228, 87, 228, 96, 228, 106, 228, 116,
+228, 126, 228, 137, 228, 147, 228, 157, 229, 70, 229, 80, 229, 90, 229, 100,
+229, 110, 229, 119, 229, 130, 229, 140, 229, 150, 246, 202, 230, 72, 230, 82,
+230, 92, 230, 101, 230, 111, 230, 121, 230, 132, 230, 142, 230, 152, 231, 64,
+231, 73, 231, 83, 231, 93, 231, 103, 231, 113, 231, 123, 231, 134, 231, 144,
+231, 154, 232, 67, 232, 77, 232, 86, 232, 96, 232, 106, 232, 116, 232, 125,
+232, 136, 232, 146, 238, 201, 232, 150, 196, 198, 238, 214, 238, 220, 188, 216,
+238, 230, 238, 239, 205, 173, 232, 157, 189, 194, 198, 204, 179, 250, 239, 180,
+239, 187, 239, 192, 239, 196, 239, 200, 182, 198, 196, 247, 239, 217, 239, 223,
+239, 232, 239, 239, 233, 81, 233, 90, 233, 100, 233, 110, 233, 120, 233, 131,
+233, 141, 233, 151, 234, 64, 234, 74, 234, 84, 201, 193, 188, 228, 227, 204,
+227, 208, 227, 214, 184, 183, 234, 103, 234, 111, 234, 115, 184, 189, 234, 120,
+234, 128, 212, 186, 218, 238, 204, 213, 234, 153, 234, 160, 184, 244, 235, 74,
+235, 83, 235, 92, 246, 192, 188, 175, 235, 105, 235, 113, 235, 122, 235, 130,
+235, 136, 235, 142, 235, 147, 193, 216, 235, 160, 246, 175, 236, 79, 246, 178,
+236, 96, 199, 224, 236, 111, 236, 116, 236, 125, 236, 133, 236, 142, 236, 149,
+199, 202, 237, 67, 237, 75, 237, 81, 237, 91, 237, 101, 237, 111, 237, 121,
+237, 130, 237, 135, 237, 142, 237, 152, 238, 65, 238, 75, 238, 85, 238, 95,
+238, 105, 238, 115, 238, 125, 238, 136, 238, 146, 238, 156, 239, 69, 185, 203,
+190, 177, 239, 72, 209, 213, 242, 173, 239, 84, 239, 94, 239, 104, 183, 231,
+198, 174, 239, 124, 239, 133, 239, 143, 239, 153, 240, 66, 240, 74, 240, 84,
+240, 94, 240, 103, 240, 113, 240, 123, 240, 134, 240, 142, 240, 151, 210, 251,
+240, 154, 240, 158, 241, 64, 202, 215, 241, 72, 241, 80, 241, 90, 241, 100,
+241, 110, 241, 120, 241, 131, 241, 141, 241, 151, 242, 64, 242, 74, 242, 84,
+242, 94, 242, 104, 242, 114, 242, 124, 242, 135, 242, 145, 242, 155, 243, 68,
+243, 78, 243, 82, 205, 213, 194, 230, 230, 235, 201, 167, 214, 232, 243, 96,
+186, 161, 247, 196, 247, 198, 243, 121, 243, 130, 243, 138, 243, 145, 243, 153,
+247, 220, 244, 73, 244, 82, 244, 90, 244, 99, 244, 108, 198, 199, 244, 117,
+244, 124, 244, 135, 244, 145, 244, 155, 245, 68, 245, 78, 245, 88, 245, 98,
+245, 108, 245, 118, 245, 129, 245, 139, 245, 149, 245, 159, 246, 72, 246, 82,
+246, 92, 246, 102, 246, 112, 246, 122, 246, 133, 246, 143, 246, 153, 247, 66,
+247, 76, 247, 86, 247, 96, 247, 106, 247, 116, 247, 126, 247, 133, 246, 215,
+247, 141, 246, 227, 247, 145, 246, 243, 247, 150, 246, 253, 247, 167, 193, 219,
+248, 69, 248, 79, 248, 89, 248, 99, 248, 109, 248, 119, 248, 130, 248, 140,
+248, 150, 248, 160, 249, 73, 249, 83, 249, 93, 249, 103, 249, 113, 249, 123,
+249, 134, 249, 144, 249, 154, 250, 67, 250, 77, 250, 87, 250, 97, 250, 107,
+250, 117, 250, 128, 250, 138, 250, 148, 250, 158, 251, 71, 251, 81, 251, 91,
+240, 177, 240, 182, 251, 98, 240, 193, 251, 101, 240, 203, 186, 215, 251, 113,
+251, 120, 247, 228, 251, 135, 251, 143, 251, 151, 251, 160, 244, 240, 247, 226,
+252, 87, 252, 92, 247, 237, 252, 103, 252, 109, 252, 118, 252, 125, 182, 166,
+252, 140, 247, 247, 247, 248, 253, 68, 253, 73, 253, 82, 253, 90, 253, 100,
+253, 110, 253, 120, 253, 131, 246, 182, 253, 139, 185, 168, 253, 154, 170, 161,
+170, 171, 170, 181, 170, 191, 170, 201, 170, 211, 170, 221, 170, 231, 170, 241,
+170, 251, 171, 167, 171, 177, 171, 187, 171, 197, 171, 207, 171, 217, 171, 227,
+171, 237, 171, 247, 172, 163, 172, 173, 172, 183, 172, 193, 172, 203, 172, 213,
+172, 223, 172, 233, 172, 243, 172, 253, 173, 169, 173, 179, 173, 189, 173, 199,
+173, 209, 173, 219, 173, 229, 173, 239, 173, 249, 174, 165, 174, 175, 174, 185,
+174, 195, 174, 205, 174, 215, 174, 225, 174, 235, 174, 245, 175, 161, 175, 171,
+175, 181, 175, 191, 175, 201, 175, 211, 175, 221, 175, 231, 175, 241, 175, 251,
+248, 167, 248, 177, 248, 187, 248, 197, 248, 207, 248, 217, 248, 227, 248, 237,
+248, 247, 249, 163, 249, 173, 249, 183, 249, 193, 249, 203, 249, 213, 249, 223,
+249, 233, 249, 243, 249, 253, 250, 169, 250, 179, 250, 189, 250, 199, 250, 209,
+250, 219, 250, 229, 250, 239, 250, 249, 251, 165, 251, 175, 251, 185, 251, 195,
+251, 205, 251, 215, 251, 225, 251, 235, 251, 245, 252, 161, 252, 171, 252, 181,
+252, 191, 252, 201, 252, 211, 252, 221, 252, 231, 252, 241, 252, 251, 253, 167,
+253, 177, 253, 187, 253, 197, 253, 207, 253, 217, 253, 227, 253, 237, 253, 247,
+254, 163, 254, 173, 254, 183, 254, 193, 254, 203, 254, 213, 254, 223, 254, 233,
+254, 243, 254, 253, 161, 72, 161, 82, 161, 92, 161, 102, 161, 112, 161, 122,
+161, 133, 161, 143, 161, 153, 162, 66, 162, 76, 162, 86, 162, 96, 162, 106,
+162, 116, 162, 126, 162, 137, 162, 147, 162, 157, 162, 227, 163, 68, 163, 78,
+163, 88, 163, 98, 163, 108, 163, 118, 163, 129, 163, 139, 163, 149, 163, 159,
+164, 72, 164, 82, 164, 92, 164, 102, 164, 112, 164, 122, 164, 133, 164, 143,
+164, 153, 164, 246, 165, 65, 165, 75, 165, 85, 165, 95, 165, 105, 165, 115,
+165, 125, 165, 136, 165, 146, 165, 156, 165, 252, 166, 71, 166, 81, 166, 91,
+166, 101, 166, 111, 166, 121, 166, 132, 166, 142, 166, 152, 166, 186, 166, 220,
+166, 249, 167, 68, 167, 78, 167, 88, 167, 98, 167, 108, 167, 118, 167, 129,
+167, 139, 167, 149, 167, 159, 167, 202, 167, 245, 168, 150, 168, 160, 168, 237,
+168, 247, 169, 93, 169, 144, 169, 155, 169, 241, 169, 251, 254, 81, 254, 91,
+254, 101, 254, 111, 254, 121, 254, 132, 254, 142, 254, 152, 253, 156, 253, 157,
+253, 158, 253, 159, 253, 160, 254, 64, 254, 71, 254, 75, 169, 85, 166, 227,
+166, 235, 169, 109, 169, 118, 169, 129, 163, 161, 163, 171, 163, 181, 163, 191,
+163, 201, 163, 211, 163, 221, 163, 231, 163, 241, 163, 251, 161, 233, 0 });
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK_Android.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK_Android.java
new file mode 100644
index 0000000..cc0c60b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_GBK_Android.java
@@ -0,0 +1,513 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_MultiByte_GBK_Android extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "GBK";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+164, 167, 168, 176, 177, 183, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243,
+247, 249, 250, 252, 257, 275, 299, 324, 363, 462, 472, 593, 609, 711, 729, 913,
+923, 933, 945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230,
+8240, 8251, 8451, 8470, 8481, 8544, 8554, 8564, 8592, 8712, 8725, 8735, 8745, 8756, 8776, 8786,
+8800, 8814, 8857, 8869, 8895, 8978, 9312, 9332, 9342, 9352, 9362, 9472, 9482, 9492, 9502, 9512,
+9522, 9532, 9542, 9552, 9562, 9572, 9582, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733,
+9792, 12288, 12298, 12308, 12318, 12328, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443,
+12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523, 12533, 12549, 12559, 12569, 12579, 12832, 12849, 12963,
+13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20038, 20048, 20058, 20068, 20078,
+20088, 20098, 20108, 20118, 20128, 20138, 20148, 20158, 20168, 20178, 20188, 20198, 20208, 20218, 20228, 20238,
+20248, 20258, 20268, 20278, 20288, 20298, 20308, 20318, 20328, 20338, 20348, 20358, 20368, 20378, 20388, 20398,
+20408, 20418, 20428, 20438, 20448, 20458, 20468, 20478, 20488, 20498, 20508, 20518, 20528, 20538, 20548, 20558,
+20568, 20578, 20588, 20598, 20608, 20618, 20628, 20638, 20648, 20658, 20668, 20678, 20688, 20698, 20708, 20718,
+20728, 20738, 20748, 20758, 20768, 20778, 20788, 20798, 20808, 20818, 20828, 20838, 20848, 20858, 20868, 20878,
+20888, 20898, 20908, 20918, 20928, 20938, 20948, 20958, 20968, 20978, 20988, 20998, 21008, 21018, 21028, 21038,
+21048, 21058, 21068, 21078, 21088, 21098, 21108, 21118, 21128, 21138, 21148, 21158, 21168, 21178, 21188, 21198,
+21208, 21218, 21228, 21238, 21248, 21258, 21268, 21278, 21288, 21298, 21308, 21318, 21328, 21338, 21348, 21358,
+21368, 21378, 21388, 21398, 21408, 21418, 21428, 21438, 21448, 21458, 21468, 21478, 21488, 21498, 21508, 21518,
+21528, 21538, 21548, 21558, 21568, 21578, 21588, 21598, 21608, 21618, 21628, 21638, 21648, 21658, 21668, 21678,
+21688, 21698, 21708, 21718, 21728, 21738, 21748, 21758, 21768, 21778, 21788, 21798, 21808, 21818, 21828, 21838,
+21848, 21858, 21868, 21878, 21888, 21898, 21908, 21918, 21928, 21938, 21948, 21958, 21968, 21978, 21988, 21998,
+22008, 22018, 22028, 22038, 22048, 22058, 22068, 22078, 22088, 22098, 22108, 22118, 22128, 22138, 22148, 22158,
+22168, 22178, 22188, 22198, 22208, 22218, 22228, 22238, 22248, 22258, 22268, 22278, 22288, 22298, 22308, 22318,
+22328, 22338, 22348, 22358, 22368, 22378, 22388, 22398, 22408, 22418, 22428, 22438, 22448, 22458, 22468, 22478,
+22488, 22498, 22508, 22518, 22528, 22538, 22548, 22558, 22568, 22578, 22588, 22598, 22608, 22618, 22628, 22638,
+22648, 22658, 22668, 22678, 22688, 22698, 22708, 22718, 22728, 22738, 22748, 22758, 22768, 22778, 22788, 22798,
+22808, 22818, 22828, 22838, 22848, 22858, 22868, 22878, 22888, 22898, 22908, 22918, 22928, 22938, 22948, 22958,
+22968, 22978, 22988, 22998, 23008, 23018, 23028, 23038, 23048, 23058, 23068, 23078, 23088, 23098, 23108, 23118,
+23128, 23138, 23148, 23158, 23168, 23178, 23188, 23198, 23208, 23218, 23228, 23238, 23248, 23258, 23268, 23278,
+23288, 23298, 23308, 23318, 23328, 23338, 23348, 23358, 23368, 23378, 23388, 23398, 23408, 23418, 23428, 23438,
+23448, 23458, 23468, 23478, 23488, 23498, 23508, 23518, 23528, 23538, 23548, 23558, 23568, 23578, 23588, 23598,
+23608, 23618, 23628, 23638, 23648, 23658, 23668, 23678, 23688, 23698, 23708, 23718, 23728, 23738, 23748, 23758,
+23768, 23778, 23788, 23798, 23808, 23818, 23828, 23838, 23848, 23858, 23868, 23878, 23888, 23898, 23908, 23918,
+23928, 23938, 23948, 23958, 23968, 23978, 23988, 23998, 24008, 24018, 24028, 24038, 24048, 24058, 24068, 24078,
+24088, 24098, 24108, 24118, 24128, 24138, 24148, 24158, 24168, 24178, 24188, 24198, 24208, 24218, 24228, 24238,
+24248, 24258, 24268, 24278, 24288, 24298, 24308, 24318, 24328, 24338, 24348, 24358, 24368, 24378, 24388, 24398,
+24408, 24418, 24428, 24438, 24448, 24458, 24468, 24478, 24488, 24498, 24508, 24518, 24528, 24538, 24548, 24558,
+24568, 24578, 24588, 24598, 24608, 24618, 24628, 24638, 24648, 24658, 24668, 24678, 24688, 24698, 24708, 24718,
+24728, 24738, 24748, 24758, 24768, 24778, 24788, 24798, 24808, 24818, 24828, 24838, 24848, 24858, 24868, 24878,
+24888, 24898, 24908, 24918, 24928, 24938, 24948, 24958, 24968, 24978, 24988, 24998, 25008, 25018, 25028, 25038,
+25048, 25058, 25068, 25078, 25088, 25098, 25108, 25118, 25128, 25138, 25148, 25158, 25168, 25178, 25188, 25198,
+25208, 25218, 25228, 25238, 25248, 25258, 25268, 25278, 25288, 25298, 25308, 25318, 25328, 25338, 25348, 25358,
+25368, 25378, 25388, 25398, 25408, 25418, 25428, 25438, 25448, 25458, 25468, 25478, 25488, 25498, 25508, 25518,
+25528, 25538, 25548, 25558, 25568, 25578, 25588, 25598, 25608, 25618, 25628, 25638, 25648, 25658, 25668, 25678,
+25688, 25698, 25708, 25718, 25728, 25738, 25748, 25758, 25768, 25778, 25788, 25798, 25808, 25818, 25828, 25838,
+25848, 25858, 25868, 25878, 25888, 25898, 25908, 25918, 25928, 25938, 25948, 25958, 25968, 25978, 25988, 25998,
+26008, 26018, 26028, 26038, 26048, 26058, 26068, 26078, 26088, 26098, 26108, 26118, 26128, 26138, 26148, 26158,
+26168, 26178, 26188, 26198, 26208, 26218, 26228, 26238, 26248, 26258, 26268, 26278, 26288, 26298, 26308, 26318,
+26328, 26338, 26348, 26358, 26368, 26378, 26388, 26398, 26408, 26418, 26428, 26438, 26448, 26458, 26468, 26478,
+26488, 26498, 26508, 26518, 26528, 26538, 26548, 26558, 26568, 26578, 26588, 26598, 26608, 26618, 26628, 26638,
+26648, 26658, 26668, 26678, 26688, 26698, 26708, 26718, 26728, 26738, 26748, 26758, 26768, 26778, 26788, 26798,
+26808, 26818, 26828, 26838, 26848, 26858, 26868, 26878, 26888, 26898, 26908, 26918, 26928, 26938, 26948, 26958,
+26968, 26978, 26988, 26998, 27008, 27018, 27028, 27038, 27048, 27058, 27068, 27078, 27088, 27098, 27108, 27118,
+27128, 27138, 27148, 27158, 27168, 27178, 27188, 27198, 27208, 27218, 27228, 27238, 27248, 27258, 27268, 27278,
+27288, 27298, 27308, 27318, 27328, 27338, 27348, 27358, 27368, 27378, 27388, 27398, 27408, 27418, 27428, 27438,
+27448, 27458, 27468, 27478, 27488, 27498, 27508, 27518, 27528, 27538, 27548, 27558, 27568, 27578, 27588, 27598,
+27608, 27618, 27628, 27638, 27648, 27658, 27668, 27678, 27688, 27698, 27708, 27718, 27728, 27738, 27748, 27758,
+27768, 27778, 27788, 27798, 27808, 27818, 27828, 27838, 27848, 27858, 27868, 27878, 27888, 27898, 27908, 27918,
+27928, 27938, 27948, 27958, 27968, 27978, 27988, 27998, 28008, 28018, 28028, 28038, 28048, 28058, 28068, 28078,
+28088, 28098, 28108, 28118, 28128, 28138, 28148, 28158, 28168, 28178, 28188, 28198, 28208, 28218, 28228, 28238,
+28248, 28258, 28268, 28278, 28288, 28298, 28308, 28318, 28328, 28338, 28348, 28358, 28368, 28378, 28388, 28398,
+28408, 28418, 28428, 28438, 28448, 28458, 28468, 28478, 28488, 28498, 28508, 28518, 28528, 28538, 28548, 28558,
+28568, 28578, 28588, 28598, 28608, 28618, 28628, 28638, 28648, 28658, 28668, 28678, 28688, 28698, 28708, 28718,
+28728, 28738, 28748, 28758, 28768, 28778, 28788, 28798, 28808, 28818, 28828, 28838, 28848, 28858, 28868, 28878,
+28888, 28898, 28908, 28918, 28928, 28938, 28948, 28958, 28968, 28978, 28988, 28998, 29008, 29018, 29028, 29038,
+29048, 29058, 29068, 29078, 29088, 29098, 29108, 29118, 29128, 29138, 29148, 29158, 29168, 29178, 29188, 29198,
+29208, 29218, 29228, 29238, 29248, 29258, 29268, 29278, 29288, 29298, 29308, 29318, 29328, 29338, 29348, 29358,
+29368, 29378, 29388, 29398, 29408, 29418, 29428, 29438, 29448, 29458, 29468, 29478, 29488, 29498, 29508, 29518,
+29528, 29538, 29548, 29558, 29568, 29578, 29588, 29598, 29608, 29618, 29628, 29638, 29648, 29658, 29668, 29678,
+29688, 29698, 29708, 29718, 29728, 29738, 29748, 29758, 29768, 29778, 29788, 29798, 29808, 29818, 29828, 29838,
+29848, 29858, 29868, 29878, 29888, 29898, 29908, 29918, 29928, 29938, 29948, 29958, 29968, 29978, 29988, 29998,
+30008, 30018, 30028, 30038, 30048, 30058, 30068, 30078, 30088, 30098, 30108, 30118, 30128, 30138, 30148, 30158,
+30168, 30178, 30188, 30198, 30208, 30218, 30228, 30238, 30248, 30258, 30268, 30278, 30288, 30298, 30308, 30318,
+30328, 30338, 30348, 30358, 30368, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448, 30458, 30468, 30478,
+30488, 30498, 30508, 30518, 30528, 30538, 30548, 30558, 30568, 30578, 30588, 30598, 30608, 30618, 30628, 30638,
+30648, 30658, 30668, 30678, 30688, 30698, 30708, 30718, 30728, 30738, 30748, 30758, 30768, 30778, 30788, 30798,
+30808, 30818, 30828, 30838, 30848, 30858, 30868, 30878, 30888, 30898, 30908, 30918, 30928, 30938, 30948, 30958,
+30968, 30978, 30988, 30998, 31008, 31018, 31028, 31038, 31048, 31058, 31068, 31078, 31088, 31098, 31108, 31118,
+31128, 31138, 31148, 31158, 31168, 31178, 31188, 31198, 31208, 31218, 31228, 31238, 31248, 31258, 31268, 31278,
+31288, 31298, 31308, 31318, 31328, 31338, 31348, 31358, 31368, 31378, 31388, 31398, 31408, 31418, 31428, 31438,
+31448, 31458, 31468, 31478, 31488, 31498, 31508, 31518, 31528, 31538, 31548, 31558, 31568, 31578, 31588, 31598,
+31608, 31618, 31628, 31638, 31648, 31658, 31668, 31678, 31688, 31698, 31708, 31718, 31728, 31738, 31748, 31758,
+31768, 31778, 31788, 31798, 31808, 31818, 31828, 31838, 31848, 31858, 31868, 31878, 31888, 31898, 31908, 31918,
+31928, 31938, 31948, 31958, 31968, 31978, 31988, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068, 32078,
+32088, 32098, 32108, 32118, 32128, 32138, 32148, 32158, 32168, 32178, 32188, 32198, 32208, 32218, 32228, 32238,
+32248, 32258, 32268, 32278, 32288, 32298, 32308, 32318, 32328, 32338, 32348, 32358, 32368, 32378, 32388, 32398,
+32408, 32418, 32428, 32438, 32448, 32458, 32468, 32478, 32488, 32498, 32508, 32518, 32528, 32538, 32548, 32558,
+32568, 32578, 32588, 32598, 32608, 32618, 32628, 32638, 32648, 32658, 32668, 32678, 32688, 32698, 32708, 32718,
+32728, 32738, 32748, 32758, 32768, 32778, 32788, 32798, 32808, 32818, 32828, 32838, 32848, 32858, 32868, 32878,
+32888, 32898, 32908, 32918, 32928, 32938, 32948, 32958, 32968, 32978, 32988, 32998, 33008, 33018, 33028, 33038,
+33048, 33058, 33068, 33078, 33088, 33098, 33108, 33118, 33128, 33138, 33148, 33158, 33168, 33178, 33188, 33198,
+33208, 33218, 33228, 33238, 33248, 33258, 33268, 33278, 33288, 33298, 33308, 33318, 33328, 33338, 33348, 33358,
+33368, 33378, 33388, 33398, 33408, 33418, 33428, 33438, 33448, 33458, 33468, 33478, 33488, 33498, 33508, 33518,
+33528, 33538, 33548, 33558, 33568, 33578, 33588, 33598, 33608, 33618, 33628, 33638, 33648, 33658, 33668, 33678,
+33688, 33698, 33708, 33718, 33728, 33738, 33748, 33758, 33768, 33778, 33788, 33798, 33808, 33818, 33828, 33838,
+33848, 33858, 33868, 33878, 33888, 33898, 33908, 33918, 33928, 33938, 33948, 33958, 33968, 33978, 33988, 33998,
+34008, 34018, 34028, 34038, 34048, 34058, 34068, 34078, 34088, 34098, 34108, 34118, 34128, 34138, 34148, 34158,
+34168, 34178, 34188, 34198, 34208, 34218, 34228, 34238, 34248, 34258, 34268, 34278, 34288, 34298, 34308, 34318,
+34328, 34338, 34348, 34358, 34368, 34378, 34388, 34398, 34408, 34418, 34428, 34438, 34448, 34458, 34468, 34478,
+34488, 34498, 34508, 34518, 34528, 34538, 34548, 34558, 34568, 34578, 34588, 34598, 34608, 34618, 34628, 34638,
+34648, 34658, 34668, 34678, 34688, 34698, 34708, 34718, 34728, 34738, 34748, 34758, 34768, 34778, 34788, 34798,
+34808, 34818, 34828, 34838, 34848, 34858, 34868, 34878, 34888, 34898, 34908, 34918, 34928, 34938, 34948, 34958,
+34968, 34978, 34988, 34998, 35008, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35108, 35118,
+35128, 35138, 35148, 35158, 35168, 35178, 35188, 35198, 35208, 35218, 35228, 35238, 35248, 35258, 35268, 35278,
+35288, 35298, 35308, 35318, 35328, 35338, 35348, 35358, 35368, 35378, 35388, 35398, 35408, 35418, 35428, 35438,
+35448, 35458, 35468, 35478, 35488, 35498, 35508, 35518, 35528, 35538, 35548, 35558, 35568, 35578, 35588, 35598,
+35608, 35618, 35628, 35638, 35648, 35658, 35668, 35678, 35688, 35698, 35708, 35718, 35728, 35738, 35748, 35758,
+35768, 35778, 35788, 35798, 35808, 35818, 35828, 35838, 35848, 35858, 35868, 35878, 35888, 35898, 35908, 35918,
+35928, 35938, 35948, 35958, 35968, 35978, 35988, 35998, 36008, 36018, 36028, 36038, 36048, 36058, 36068, 36078,
+36088, 36098, 36108, 36118, 36128, 36138, 36148, 36158, 36168, 36178, 36188, 36198, 36208, 36218, 36228, 36238,
+36248, 36258, 36268, 36278, 36288, 36298, 36308, 36318, 36328, 36338, 36348, 36358, 36368, 36378, 36388, 36398,
+36408, 36418, 36428, 36438, 36448, 36458, 36468, 36478, 36488, 36498, 36508, 36518, 36528, 36538, 36548, 36558,
+36568, 36578, 36588, 36598, 36608, 36618, 36628, 36638, 36648, 36658, 36668, 36678, 36688, 36698, 36708, 36718,
+36728, 36738, 36748, 36758, 36768, 36778, 36788, 36798, 36808, 36818, 36828, 36838, 36848, 36858, 36868, 36878,
+36888, 36898, 36908, 36918, 36928, 36938, 36948, 36958, 36968, 36978, 36988, 36998, 37008, 37018, 37028, 37038,
+37048, 37058, 37068, 37078, 37088, 37098, 37108, 37118, 37128, 37138, 37148, 37158, 37168, 37178, 37188, 37198,
+37208, 37218, 37228, 37238, 37248, 37258, 37268, 37278, 37288, 37298, 37308, 37318, 37328, 37338, 37348, 37358,
+37368, 37378, 37388, 37398, 37408, 37418, 37428, 37438, 37448, 37458, 37468, 37478, 37488, 37498, 37508, 37518,
+37528, 37538, 37548, 37558, 37568, 37578, 37588, 37598, 37608, 37618, 37628, 37638, 37648, 37658, 37668, 37678,
+37688, 37698, 37708, 37718, 37728, 37738, 37748, 37758, 37768, 37778, 37788, 37798, 37808, 37818, 37828, 37838,
+37848, 37858, 37868, 37878, 37888, 37898, 37908, 37918, 37928, 37938, 37948, 37958, 37968, 37978, 37988, 37998,
+38008, 38018, 38028, 38038, 38048, 38058, 38068, 38078, 38088, 38098, 38108, 38118, 38128, 38138, 38148, 38158,
+38168, 38178, 38188, 38198, 38208, 38218, 38228, 38238, 38248, 38258, 38268, 38278, 38288, 38298, 38308, 38318,
+38328, 38338, 38348, 38358, 38368, 38378, 38388, 38398, 38408, 38418, 38428, 38438, 38448, 38458, 38468, 38478,
+38488, 38498, 38508, 38518, 38528, 38538, 38548, 38558, 38568, 38578, 38588, 38598, 38608, 38618, 38628, 38638,
+38648, 38658, 38668, 38678, 38688, 38698, 38708, 38718, 38728, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
+38808, 38818, 38828, 38838, 38848, 38858, 38868, 38878, 38888, 38898, 38908, 38918, 38928, 38938, 38948, 38958,
+38968, 38978, 38988, 38998, 39008, 39018, 39028, 39038, 39048, 39058, 39068, 39078, 39088, 39098, 39108, 39118,
+39128, 39138, 39148, 39158, 39168, 39178, 39188, 39198, 39208, 39218, 39228, 39238, 39248, 39258, 39268, 39278,
+39288, 39298, 39308, 39318, 39328, 39338, 39348, 39358, 39368, 39378, 39388, 39398, 39408, 39418, 39428, 39438,
+39448, 39458, 39468, 39478, 39488, 39498, 39508, 39518, 39528, 39538, 39548, 39558, 39568, 39578, 39588, 39598,
+39608, 39618, 39628, 39638, 39648, 39658, 39668, 39678, 39688, 39698, 39708, 39718, 39728, 39738, 39748, 39758,
+39768, 39778, 39788, 39798, 39808, 39818, 39828, 39838, 39848, 39858, 39868, 39878, 39888, 39898, 39908, 39918,
+39928, 39938, 39948, 39958, 39968, 39978, 39988, 39998, 40008, 40018, 40028, 40038, 40048, 40058, 40068, 40078,
+40088, 40098, 40108, 40118, 40128, 40138, 40148, 40158, 40168, 40178, 40188, 40198, 40208, 40218, 40228, 40238,
+40248, 40258, 40268, 40278, 40288, 40298, 40308, 40318, 40328, 40338, 40348, 40358, 40368, 40378, 40388, 40398,
+40408, 40418, 40428, 40438, 40448, 40458, 40468, 40478, 40488, 40498, 40508, 40518, 40528, 40538, 40548, 40558,
+40568, 40578, 40588, 40598, 40608, 40618, 40628, 40638, 40648, 40658, 40668, 40678, 40688, 40698, 40708, 40718,
+40728, 40738, 40748, 40758, 40768, 40778, 40788, 40798, 40808, 40818, 40828, 40838, 40848, 40858, 40868, 57344,
+57354, 57364, 57374, 57384, 57394, 57404, 57414, 57424, 57434, 57444, 57454, 57464, 57474, 57484, 57494, 57504,
+57514, 57524, 57534, 57544, 57554, 57564, 57574, 57584, 57594, 57604, 57614, 57624, 57634, 57644, 57654, 57664,
+57674, 57684, 57694, 57704, 57714, 57724, 57734, 57744, 57754, 57764, 57774, 57784, 57794, 57804, 57814, 57824,
+57834, 57844, 57854, 57864, 57874, 57884, 57894, 57904, 57914, 57924, 57934, 57944, 57954, 57964, 57974, 57984,
+57994, 58004, 58014, 58024, 58034, 58044, 58054, 58064, 58074, 58084, 58094, 58104, 58114, 58124, 58134, 58144,
+58154, 58164, 58174, 58184, 58194, 58204, 58214, 58224, 58234, 58244, 58254, 58264, 58274, 58284, 58294, 58304,
+58314, 58324, 58334, 58344, 58354, 58364, 58374, 58384, 58394, 58404, 58414, 58424, 58434, 58444, 58454, 58464,
+58474, 58484, 58494, 58504, 58514, 58524, 58534, 58544, 58554, 58564, 58574, 58584, 58594, 58604, 58614, 58624,
+58634, 58644, 58654, 58664, 58674, 58684, 58694, 58704, 58714, 58724, 58734, 58744, 58754, 58764, 58774, 58784,
+58794, 58804, 58814, 58824, 58834, 58844, 58854, 58864, 58874, 58884, 58894, 58904, 58914, 58924, 58934, 58944,
+58954, 58964, 58974, 58984, 58994, 59004, 59014, 59024, 59034, 59044, 59054, 59064, 59074, 59084, 59094, 59104,
+59114, 59124, 59134, 59144, 59154, 59164, 59174, 59184, 59194, 59204, 59214, 59224, 59234, 59244, 59254, 59264,
+59274, 59284, 59294, 59304, 59314, 59324, 59334, 59344, 59354, 59364, 59374, 59384, 59394, 59404, 59414, 59424,
+59434, 59444, 59454, 59464, 59474, 59484, 63788, 63865, 63893, 63975, 63985, 64012, 64024, 64035, 65072, 65082,
+65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65504, 65536
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 164, 161, 193, 168, 164,
+168, 162, 168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174,
+161, 194, 168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 169, 168, 189,
+168, 177, 168, 163, 168, 182, 168, 187, 168, 192, 161, 166, 168, 66, 166, 161,
+166, 171, 166, 180, 166, 193, 166, 203, 166, 212, 167, 167, 167, 161, 167, 172,
+167, 182, 167, 192, 167, 218, 167, 228, 167, 238, 169, 92, 161, 176, 161, 173,
+161, 235, 161, 249, 161, 230, 161, 237, 169, 89, 162, 241, 162, 251, 162, 165,
+161, 251, 161, 202, 168, 77, 168, 78, 161, 201, 161, 224, 161, 214, 168, 80,
+161, 217, 161, 218, 161, 209, 161, 205, 168, 83, 161, 208, 162, 217, 162, 197,
+162, 207, 162, 177, 162, 187, 169, 164, 169, 174, 169, 184, 169, 194, 169, 204,
+169, 214, 169, 224, 169, 234, 168, 84, 168, 94, 168, 104, 168, 114, 168, 120,
+168, 131, 168, 138, 161, 246, 161, 248, 168, 139, 161, 244, 168, 141, 161, 239,
+161, 226, 161, 161, 161, 182, 161, 178, 168, 149, 169, 71, 164, 161, 164, 171,
+164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 169, 97,
+165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
+165, 245, 168, 197, 168, 207, 168, 217, 168, 227, 162, 229, 169, 90, 169, 73,
+169, 74, 169, 76, 169, 80, 169, 81, 210, 187, 201, 207, 199, 210, 216, 169,
+216, 173, 180, 174, 129, 83, 129, 88, 192, 214, 129, 93, 129, 97, 129, 105,
+129, 112, 129, 121, 182, 254, 129, 129, 217, 239, 129, 136, 129, 140, 129, 147,
+129, 148, 129, 152, 129, 155, 129, 158, 209, 246, 129, 168, 129, 174, 188, 191,
+211, 197, 216, 243, 129, 192, 193, 230, 129, 203, 129, 211, 129, 215, 216, 250,
+129, 220, 129, 226, 217, 174, 129, 237, 129, 242, 129, 249, 130, 64, 206, 234,
+130, 74, 130, 83, 130, 89, 130, 95, 130, 98, 217, 179, 130, 107, 217, 194,
+130, 124, 181, 185, 217, 195, 190, 235, 130, 146, 213, 174, 130, 162, 217, 203,
+130, 176, 130, 184, 217, 204, 197, 188, 191, 254, 130, 214, 130, 223, 130, 233,
+180, 162, 176, 193, 130, 254, 131, 73, 131, 82, 193, 197, 131, 100, 217, 215,
+131, 113, 131, 122, 131, 130, 131, 139, 131, 149, 131, 158, 131, 168, 131, 178,
+207, 200, 131, 186, 182, 181, 131, 199, 192, 188, 131, 205, 131, 209, 131, 214,
+131, 220, 218, 163, 182, 172, 210, 177, 190, 187, 131, 245, 131, 251, 132, 68,
+132, 75, 132, 81, 219, 202, 183, 214, 132, 91, 184, 213, 197, 208, 185, 206,
+200, 175, 188, 193, 216, 221, 198, 202, 132, 133, 188, 244, 132, 146, 132, 155,
+197, 252, 132, 170, 132, 178, 132, 181, 132, 185, 132, 192, 132, 199, 132, 206,
+191, 177, 132, 221, 132, 230, 132, 239, 212, 200, 132, 251, 133, 67, 133, 71,
+133, 77, 133, 85, 133, 92, 133, 97, 133, 101, 178, 169, 194, 177, 216, 180,
+208, 182, 179, 167, 209, 225, 133, 133, 133, 139, 133, 143, 133, 152, 133, 160,
+211, 214, 133, 170, 133, 174, 193, 237, 204, 168, 133, 181, 184, 247, 186, 243,
+133, 190, 133, 194, 204, 253, 133, 200, 209, 189, 184, 230, 223, 190, 133, 218,
+214, 220, 223, 218, 186, 244, 197, 216, 184, 192, 223, 203, 223, 229, 134, 66,
+207, 204, 223, 211, 223, 223, 134, 80, 134, 83, 196, 196, 134, 93, 134, 100,
+134, 106, 134, 112, 134, 120, 134, 126, 224, 167, 134, 138, 215, 196, 134, 149,
+134, 156, 134, 164, 216, 196, 224, 164, 191, 166, 186, 176, 224, 184, 134, 192,
+134, 200, 134, 209, 134, 214, 134, 220, 134, 227, 134, 232, 224, 205, 134, 240,
+134, 245, 134, 251, 224, 209, 135, 75, 135, 81, 135, 88, 215, 236, 135, 100,
+135, 109, 135, 116, 224, 224, 135, 130, 135, 135, 135, 143, 135, 151, 186, 191,
+135, 166, 135, 176, 135, 185, 135, 194, 135, 202, 196, 210, 224, 236, 187, 216,
+135, 230, 135, 236, 135, 242, 212, 178, 135, 253, 136, 72, 136, 79, 219, 220,
+136, 90, 219, 224, 219, 208, 136, 106, 215, 185, 198, 186, 136, 118, 136, 124,
+136, 130, 192, 221, 136, 145, 191, 209, 136, 154, 136, 161, 136, 169, 179, 199,
+219, 245, 136, 187, 136, 196, 136, 203, 220, 165, 136, 215, 136, 222, 220, 166,
+136, 236, 136, 244, 136, 253, 137, 71, 137, 79, 137, 86, 137, 95, 137, 102,
+137, 112, 137, 119, 137, 126, 137, 135, 137, 141, 137, 149, 137, 159, 137, 168,
+137, 176, 137, 185, 137, 194, 137, 203, 201, 249, 137, 216, 180, 166, 137, 232,
+137, 238, 137, 244, 137, 248, 137, 253, 138, 67, 138, 71, 177, 188, 138, 81,
+138, 88, 138, 98, 138, 103, 215, 177, 138, 113, 138, 118, 230, 165, 196, 221,
+138, 138, 138, 145, 138, 152, 138, 157, 138, 162, 138, 169, 138, 178, 138, 186,
+230, 174, 138, 195, 196, 200, 138, 208, 138, 217, 138, 223, 138, 231, 138, 238,
+138, 247, 230, 190, 139, 72, 201, 244, 139, 86, 139, 96, 139, 105, 139, 113,
+139, 123, 230, 199, 139, 139, 139, 146, 139, 154, 139, 160, 139, 166, 139, 173,
+139, 182, 139, 192, 139, 201, 230, 212, 139, 219, 139, 229, 217, 248, 139, 246,
+140, 64, 140, 72, 215, 206, 209, 167, 202, 235, 200, 230, 229, 179, 140, 97,
+185, 217, 191, 205, 140, 107, 188, 210, 140, 117, 140, 122, 140, 129, 196, 175,
+213, 175, 140, 150, 181, 188, 189, 171, 140, 168, 201, 208, 211, 200, 140, 185,
+202, 172, 178, 227, 140, 197, 140, 202, 205, 192, 140, 215, 140, 222, 140, 230,
+225, 172, 140, 242, 225, 177, 140, 252, 141, 67, 141, 72, 225, 187, 141, 87,
+141, 96, 141, 104, 141, 109, 141, 117, 141, 126, 141, 133, 180, 222, 225, 198,
+141, 155, 141, 162, 141, 171, 141, 179, 141, 185, 141, 194, 141, 202, 141, 209,
+141, 217, 225, 214, 141, 236, 141, 246, 141, 254, 142, 73, 142, 83, 142, 92,
+142, 101, 142, 110, 142, 119, 215, 243, 142, 128, 142, 133, 142, 138, 142, 144,
+193, 177, 142, 152, 142, 160, 142, 167, 142, 172, 142, 179, 225, 163, 225, 165,
+142, 202, 184, 201, 211, 215, 199, 236, 194, 174, 184, 253, 142, 232, 142, 238,
+211, 185, 142, 251, 143, 68, 193, 206, 143, 83, 226, 222, 219, 200, 222, 195,
+222, 196, 143, 115, 143, 120, 207, 210, 143, 132, 199, 191, 143, 147, 143, 157,
+229, 233, 208, 206, 177, 242, 143, 178, 205, 249, 187, 178, 143, 191, 143, 196,
+225, 229, 143, 211, 225, 232, 210, 228, 236, 254, 143, 232, 226, 232, 226, 229,
+226, 238, 203, 203, 144, 67, 178, 192, 181, 161, 185, 214, 144, 86, 144, 93,
+144, 99, 186, 227, 144, 112, 144, 118, 199, 161, 226, 253, 199, 196, 144, 136,
+144, 143, 144, 148, 208, 252, 144, 158, 144, 165, 190, 170, 144, 180, 144, 185,
+178, 210, 144, 193, 144, 198, 237, 169, 144, 210, 211, 222, 183, 223, 144, 231,
+144, 241, 144, 250, 187, 197, 145, 73, 145, 82, 145, 89, 145, 98, 145, 106,
+145, 116, 145, 124, 145, 134, 145, 143, 145, 149, 145, 158, 145, 166, 145, 173,
+145, 180, 145, 190, 145, 199, 145, 208, 145, 217, 206, 236, 145, 226, 145, 230,
+145, 235, 145, 242, 145, 249, 145, 253, 146, 65, 146, 70, 146, 78, 176, 231,
+146, 86, 146, 91, 146, 98, 182, 182, 191, 217, 146, 112, 146, 119, 146, 124,
+196, 233, 190, 220, 176, 221, 192, 185, 146, 140, 146, 145, 146, 149, 191, 230,
+146, 163, 222, 216, 146, 169, 146, 177, 146, 184, 146, 189, 146, 193, 192, 204,
+146, 206, 146, 212, 146, 218, 146, 226, 198, 254, 146, 235, 146, 242, 222, 231,
+181, 167, 147, 65, 147, 72, 210, 190, 222, 235, 190, 190, 212, 174, 147, 104,
+147, 109, 147, 115, 203, 209, 222, 249, 147, 135, 208, 175, 201, 227, 147, 154,
+213, 170, 147, 170, 147, 178, 147, 187, 147, 194, 147, 200, 147, 208, 215, 178,
+147, 223, 147, 228, 186, 179, 147, 240, 223, 167, 147, 254, 223, 169, 148, 79,
+148, 89, 148, 98, 148, 107, 148, 116, 148, 125, 148, 135, 234, 183, 183, 197,
+208, 167, 148, 158, 148, 164, 182, 216, 202, 253, 148, 183, 148, 193, 148, 200,
+148, 206, 148, 211, 148, 216, 148, 223, 148, 230, 148, 235, 148, 240, 148, 248,
+214, 188, 149, 64, 149, 71, 192, 165, 149, 83, 149, 89, 149, 96, 149, 102,
+149, 107, 149, 114, 201, 206, 234, 205, 149, 133, 149, 139, 199, 231, 193, 192,
+149, 158, 149, 166, 149, 174, 149, 183, 149, 190, 149, 198, 149, 207, 149, 217,
+149, 227, 149, 233, 149, 241, 149, 247, 215, 238, 235, 195, 203, 183, 150, 79,
+196, 190, 150, 90, 150, 97, 184, 203, 178, 196, 150, 113, 150, 118, 150, 123,
+150, 128, 150, 134, 150, 140, 150, 148, 150, 152, 199, 185, 150, 161, 150, 167,
+150, 174, 198, 226, 185, 241, 150, 189, 232, 205, 150, 202, 150, 209, 232, 221,
+150, 216, 150, 224, 150, 232, 150, 240, 232, 238, 232, 240, 189, 219, 151, 66,
+189, 176, 151, 75, 151, 82, 176, 240, 151, 97, 151, 105, 151, 114, 151, 120,
+151, 126, 232, 249, 151, 143, 151, 150, 204, 196, 151, 166, 151, 173, 151, 179,
+151, 187, 189, 183, 151, 202, 151, 209, 210, 172, 151, 225, 151, 232, 151, 242,
+151, 250, 152, 65, 152, 72, 152, 80, 233, 175, 152, 89, 192, 198, 152, 103,
+213, 165, 152, 118, 152, 125, 152, 135, 187, 177, 152, 150, 152, 157, 152, 166,
+152, 175, 152, 183, 152, 192, 152, 202, 152, 209, 186, 225, 152, 224, 233, 208,
+152, 239, 152, 248, 153, 64, 153, 72, 153, 82, 153, 90, 207, 173, 233, 213,
+153, 113, 153, 122, 195, 202, 153, 140, 153, 150, 153, 160, 153, 170, 153, 180,
+153, 190, 153, 200, 153, 210, 153, 220, 153, 230, 153, 240, 236, 163, 153, 254,
+154, 71, 154, 78, 184, 232, 154, 93, 154, 102, 205, 225, 154, 115, 154, 122,
+154, 126, 233, 230, 154, 138, 154, 147, 154, 156, 154, 162, 154, 169, 154, 176,
+154, 179, 154, 186, 154, 194, 154, 201, 154, 209, 154, 216, 198, 248, 154, 224,
+176, 177, 235, 181, 154, 238, 217, 224, 207, 171, 155, 65, 204, 192, 155, 74,
+155, 80, 210, 202, 227, 231, 155, 95, 155, 102, 187, 166, 155, 108, 213, 180,
+155, 119, 155, 125, 155, 130, 155, 134, 204, 169, 227, 248, 228, 167, 228, 169,
+155, 159, 155, 165, 155, 171, 155, 176, 155, 181, 215, 199, 228, 177, 228, 183,
+155, 199, 155, 205, 228, 188, 155, 219, 155, 225, 155, 231, 181, 211, 228, 204,
+186, 212, 155, 250, 204, 202, 196, 215, 228, 196, 156, 83, 156, 88, 156, 94,
+156, 103, 156, 107, 156, 113, 156, 117, 156, 123, 195, 236, 228, 216, 228, 207,
+207, 230, 156, 160, 156, 169, 156, 178, 156, 186, 156, 192, 156, 200, 156, 208,
+156, 214, 228, 209, 156, 225, 156, 232, 156, 239, 185, 246, 194, 203, 156, 253,
+157, 71, 198, 175, 157, 87, 157, 93, 196, 174, 228, 244, 157, 114, 209, 250,
+157, 131, 157, 139, 199, 177, 193, 202, 157, 162, 228, 253, 179, 206, 197, 236,
+157, 191, 157, 199, 157, 208, 229, 164, 188, 164, 157, 232, 157, 240, 229, 168,
+158, 66, 158, 74, 158, 84, 158, 94, 158, 104, 229, 171, 158, 120, 158, 131,
+158, 140, 158, 149, 185, 224, 158, 167, 158, 176, 158, 186, 158, 191, 212, 214,
+158, 203, 179, 180, 236, 191, 158, 223, 158, 228, 158, 233, 158, 236, 158, 244,
+186, 230, 159, 69, 189, 253, 159, 80, 159, 87, 186, 184, 159, 103, 159, 108,
+159, 117, 159, 124, 159, 134, 159, 143, 159, 150, 159, 160, 195, 186, 214, 243,
+236, 212, 159, 188, 159, 196, 159, 204, 236, 218, 159, 219, 159, 227, 159, 235,
+159, 244, 159, 253, 160, 70, 160, 78, 160, 86, 160, 95, 160, 105, 160, 114,
+160, 124, 160, 134, 197, 192, 184, 184, 160, 151, 160, 159, 160, 166, 160, 172,
+160, 177, 201, 252, 160, 190, 160, 195, 160, 201, 160, 210, 160, 219, 160, 227,
+225, 239, 191, 241, 160, 245, 160, 251, 186, 221, 170, 73, 225, 249, 170, 79,
+170, 87, 170, 95, 178, 194, 170, 104, 170, 109, 170, 114, 170, 122, 170, 132,
+170, 139, 170, 148, 226, 179, 171, 68, 171, 77, 171, 84, 171, 91, 171, 99,
+171, 107, 193, 225, 171, 117, 171, 125, 183, 169, 171, 138, 171, 146, 171, 152,
+172, 64, 172, 74, 172, 79, 172, 87, 172, 95, 231, 247, 199, 217, 172, 112,
+172, 121, 172, 132, 232, 164, 172, 144, 185, 229, 172, 160, 173, 69, 232, 172,
+173, 85, 173, 93, 173, 100, 173, 110, 173, 119, 173, 130, 173, 139, 240, 172,
+173, 152, 173, 160, 174, 70, 174, 78, 174, 86, 201, 245, 174, 99, 174, 103,
+181, 233, 174, 111, 189, 231, 174, 124, 174, 131, 183, 172, 179, 235, 174, 154,
+175, 64, 240, 218, 175, 75, 175, 78, 240, 230, 175, 86, 240, 228, 175, 94,
+182, 187, 193, 161, 175, 109, 175, 116, 240, 246, 240, 250, 175, 137, 175, 142,
+175, 146, 175, 151, 241, 162, 176, 65, 176, 73, 176, 81, 176, 88, 176, 97,
+185, 239, 212, 237, 176, 116, 205, 238, 176, 132, 176, 141, 241, 229, 176, 157,
+211, 175, 186, 208, 177, 73, 177, 81, 177, 89, 177, 94, 237, 237, 177, 105,
+177, 115, 237, 243, 177, 128, 191, 244, 215, 197, 177, 146, 177, 154, 178, 65,
+237, 254, 178, 77, 178, 86, 178, 90, 178, 97, 178, 105, 178, 112, 178, 117,
+178, 124, 178, 132, 178, 142, 178, 151, 178, 158, 179, 66, 179, 71, 183, 175,
+179, 83, 197, 248, 237, 191, 237, 206, 197, 233, 237, 194, 179, 113, 237, 202,
+179, 124, 179, 134, 211, 178, 179, 149, 179, 157, 180, 68, 180, 73, 180, 78,
+180, 83, 237, 218, 180, 97, 180, 104, 197, 205, 180, 117, 180, 128, 180, 136,
+180, 143, 180, 151, 180, 160, 181, 72, 181, 81, 181, 90, 237, 231, 201, 231,
+198, 237, 181, 120, 236, 239, 181, 129, 181, 135, 236, 247, 194, 187, 181, 157,
+182, 69, 182, 78, 182, 87, 182, 96, 208, 227, 182, 106, 182, 112, 182, 120,
+182, 125, 182, 131, 182, 139, 239, 249, 182, 151, 214, 201, 183, 68, 183, 78,
+183, 86, 183, 91, 183, 100, 183, 109, 183, 118, 183, 129, 209, 168, 183, 142,
+241, 186, 214, 207, 180, 220, 241, 188, 184, 72, 184, 81, 184, 90, 184, 99,
+184, 108, 184, 114, 184, 121, 184, 130, 184, 136, 243, 201, 177, 202, 243, 215,
+177, 191, 185, 66, 193, 253, 185, 80, 191, 240, 243, 217, 185, 94, 243, 223,
+185, 109, 185, 115, 185, 124, 185, 131, 185, 138, 243, 236, 243, 240, 185, 155,
+186, 65, 186, 73, 186, 80, 243, 247, 186, 94, 186, 102, 186, 110, 186, 117,
+186, 125, 186, 135, 186, 142, 186, 152, 244, 166, 187, 71, 187, 80, 187, 90,
+187, 100, 187, 110, 244, 204, 187, 125, 187, 135, 187, 140, 212, 193, 193, 184,
+187, 158, 188, 66, 244, 216, 204, 199, 191, 183, 188, 92, 188, 101, 188, 109,
+188, 119, 188, 129, 188, 139, 188, 147, 188, 154, 189, 67, 189, 77, 189, 87,
+189, 97, 189, 107, 189, 117, 189, 126, 189, 136, 189, 146, 189, 156, 190, 69,
+190, 78, 190, 87, 190, 97, 190, 107, 190, 117, 190, 128, 190, 138, 190, 148,
+190, 158, 191, 71, 191, 81, 191, 91, 191, 101, 191, 111, 191, 121, 191, 131,
+191, 139, 191, 149, 191, 159, 192, 72, 192, 82, 192, 92, 192, 101, 192, 111,
+192, 121, 186, 236, 206, 179, 194, 218, 231, 164, 176, 237, 231, 171, 189, 202,
+231, 176, 231, 181, 215, 219, 192, 194, 192, 137, 184, 191, 231, 205, 201, 201,
+184, 215, 243, 191, 192, 155, 193, 64, 193, 70, 215, 239, 238, 188, 238, 192,
+193, 98, 193, 105, 193, 113, 193, 118, 244, 202, 193, 133, 193, 139, 244, 225,
+199, 204, 193, 159, 194, 69, 194, 75, 210, 171, 194, 87, 241, 232, 194, 95,
+241, 241, 194, 106, 194, 110, 241, 246, 194, 121, 190, 219, 194, 138, 194, 146,
+194, 155, 195, 66, 188, 161, 208, 164, 179, 166, 183, 190, 235, 200, 201, 246,
+195, 95, 195, 102, 202, 164, 195, 111, 210, 200, 176, 183, 195, 122, 235, 219,
+235, 228, 195, 138, 235, 227, 235, 225, 196, 64, 192, 176, 199, 187, 196, 82,
+196, 89, 196, 94, 235, 239, 196, 104, 196, 111, 196, 119, 196, 125, 196, 133,
+196, 142, 177, 219, 235, 251, 197, 66, 197, 76, 215, 212, 214, 194, 244, 167,
+197, 100, 202, 230, 203, 180, 197, 118, 189, 162, 197, 123, 244, 185, 197, 138,
+203, 210, 197, 154, 198, 66, 198, 70, 198, 75, 220, 183, 198, 85, 198, 90,
+220, 184, 198, 95, 198, 100, 198, 106, 198, 108, 198, 111, 220, 214, 198, 120,
+198, 126, 195, 175, 220, 221, 198, 140, 198, 146, 198, 154, 220, 238, 199, 64,
+199, 70, 187, 196, 220, 234, 220, 253, 199, 84, 199, 92, 199, 99, 201, 175,
+221, 183, 199, 118, 199, 124, 221, 178, 221, 210, 190, 213, 221, 202, 199, 151,
+199, 157, 183, 198, 200, 73, 221, 201, 200, 83, 200, 91, 211, 169, 200, 104,
+221, 199, 200, 120, 200, 130, 200, 139, 200, 144, 200, 151, 200, 156, 201, 65,
+221, 220, 201, 78, 203, 226, 201, 94, 201, 103, 221, 240, 208, 238, 201, 121,
+201, 128, 201, 135, 197, 238, 201, 150, 201, 158, 202, 71, 202, 78, 202, 86,
+202, 94, 202, 102, 176, 170, 202, 114, 202, 121, 202, 130, 222, 168, 202, 147,
+202, 155, 203, 64, 203, 71, 203, 80, 203, 88, 208, 189, 203, 102, 203, 110,
+203, 119, 203, 126, 222, 188, 203, 143, 203, 152, 204, 65, 204, 73, 204, 82,
+204, 90, 204, 100, 204, 108, 204, 118, 204, 126, 204, 137, 242, 175, 211, 221,
+204, 158, 205, 67, 242, 180, 205, 77, 205, 83, 205, 91, 212, 233, 205, 102,
+205, 106, 205, 114, 205, 118, 205, 123, 205, 129, 205, 137, 242, 211, 182, 234,
+242, 218, 209, 209, 195, 219, 206, 70, 206, 78, 206, 85, 206, 92, 208, 171,
+206, 105, 206, 113, 206, 120, 181, 251, 206, 133, 206, 139, 206, 146, 206, 155,
+242, 253, 207, 72, 207, 79, 243, 161, 207, 94, 207, 101, 207, 109, 243, 181,
+207, 126, 207, 135, 207, 143, 243, 182, 207, 159, 208, 70, 208, 79, 208, 87,
+208, 94, 208, 102, 208, 109, 208, 114, 203, 165, 208, 126, 176, 192, 208, 137,
+208, 145, 241, 200, 209, 64, 209, 72, 209, 80, 209, 85, 210, 225, 209, 99,
+241, 212, 209, 111, 241, 211, 209, 124, 186, 214, 241, 210, 209, 147, 209, 154,
+210, 64, 210, 73, 210, 82, 210, 92, 210, 100, 210, 109, 210, 119, 210, 129,
+210, 135, 210, 145, 210, 155, 211, 68, 211, 78, 211, 88, 185, 230, 234, 236,
+211, 101, 211, 108, 211, 114, 211, 122, 209, 212, 211, 141, 211, 151, 212, 64,
+212, 74, 212, 84, 212, 94, 212, 103, 212, 112, 212, 122, 212, 133, 212, 143,
+212, 153, 213, 65, 213, 73, 213, 82, 213, 92, 213, 102, 213, 112, 213, 122,
+213, 133, 213, 143, 213, 153, 214, 66, 214, 76, 214, 86, 214, 96, 214, 105,
+214, 115, 214, 125, 214, 135, 214, 145, 214, 155, 215, 68, 215, 78, 215, 88,
+215, 97, 215, 106, 215, 116, 215, 126, 215, 137, 215, 147, 200, 207, 210, 233,
+208, 237, 218, 172, 214, 223, 218, 180, 218, 185, 215, 158, 203, 181, 191, 206,
+204, 184, 218, 203, 195, 213, 199, 171, 192, 190, 216, 66, 216, 75, 216, 81,
+216, 90, 187, 191, 216, 105, 216, 114, 216, 121, 245, 246, 245, 249, 216, 145,
+216, 155, 217, 68, 217, 78, 217, 88, 217, 98, 217, 108, 217, 118, 217, 129,
+217, 139, 217, 149, 217, 159, 218, 72, 218, 79, 204, 176, 204, 249, 188, 214,
+234, 226, 218, 81, 216, 211, 201, 226, 215, 223, 218, 95, 244, 242, 218, 110,
+218, 118, 218, 128, 218, 137, 218, 143, 218, 148, 218, 155, 218, 160, 245, 200,
+191, 231, 219, 79, 219, 82, 219, 90, 219, 96, 219, 105, 219, 110, 245, 218,
+219, 123, 245, 229, 219, 132, 219, 140, 219, 149, 219, 157, 245, 237, 220, 72,
+220, 78, 220, 86, 245, 242, 220, 103, 220, 110, 204, 201, 220, 129, 234, 166,
+220, 148, 220, 158, 221, 71, 221, 81, 221, 91, 221, 101, 221, 111, 221, 121,
+221, 132, 221, 142, 221, 152, 222, 65, 222, 75, 222, 85, 222, 95, 194, 214,
+233, 244, 233, 251, 222, 99, 207, 189, 222, 102, 222, 109, 222, 116, 180, 239,
+194, 245, 222, 134, 212, 182, 229, 200, 202, 246, 222, 149, 229, 204, 222, 157,
+222, 160, 183, 234, 223, 74, 229, 212, 223, 85, 223, 91, 223, 95, 223, 102,
+229, 219, 223, 116, 223, 124, 223, 130, 223, 138, 223, 143, 223, 148, 211, 202,
+219, 161, 224, 64, 224, 70, 224, 75, 224, 81, 224, 86, 179, 187, 219, 177,
+224, 107, 224, 117, 224, 126, 224, 134, 224, 143, 224, 151, 224, 160, 244, 252,
+225, 72, 245, 161, 179, 234, 195, 184, 225, 87, 225, 94, 225, 98, 225, 106,
+225, 114, 225, 120, 225, 128, 225, 138, 225, 141, 225, 150, 225, 159, 226, 72,
+226, 82, 226, 92, 226, 102, 226, 112, 226, 122, 226, 133, 226, 143, 226, 153,
+227, 66, 227, 76, 227, 86, 227, 96, 227, 106, 227, 115, 227, 125, 246, 198,
+227, 145, 227, 155, 228, 68, 228, 77, 228, 87, 228, 96, 228, 106, 228, 116,
+228, 126, 228, 137, 228, 147, 228, 157, 229, 70, 229, 80, 229, 90, 229, 100,
+229, 110, 229, 119, 229, 130, 229, 140, 229, 150, 246, 202, 230, 72, 230, 82,
+230, 92, 230, 101, 230, 111, 230, 121, 230, 132, 230, 142, 230, 152, 231, 64,
+231, 73, 231, 83, 231, 93, 231, 103, 231, 113, 231, 123, 231, 134, 231, 144,
+231, 154, 232, 67, 232, 77, 232, 86, 232, 96, 232, 106, 232, 116, 232, 125,
+232, 136, 232, 146, 238, 201, 232, 150, 196, 198, 238, 214, 238, 220, 188, 216,
+238, 230, 238, 239, 205, 173, 232, 157, 189, 194, 198, 204, 179, 250, 239, 180,
+239, 187, 239, 192, 239, 196, 239, 200, 182, 198, 196, 247, 239, 217, 239, 223,
+239, 232, 239, 239, 233, 81, 233, 90, 233, 100, 233, 110, 233, 120, 233, 131,
+233, 141, 233, 151, 234, 64, 234, 74, 234, 84, 201, 193, 188, 228, 227, 204,
+227, 208, 227, 214, 184, 183, 234, 103, 234, 111, 234, 115, 184, 189, 234, 120,
+234, 128, 212, 186, 218, 238, 204, 213, 234, 153, 234, 160, 184, 244, 235, 74,
+235, 83, 235, 92, 246, 192, 188, 175, 235, 105, 235, 113, 235, 122, 235, 130,
+235, 136, 235, 142, 235, 147, 193, 216, 235, 160, 246, 175, 236, 79, 246, 178,
+236, 96, 199, 224, 236, 111, 236, 116, 236, 125, 236, 133, 236, 142, 236, 149,
+199, 202, 237, 67, 237, 75, 237, 81, 237, 91, 237, 101, 237, 111, 237, 121,
+237, 130, 237, 135, 237, 142, 237, 152, 238, 65, 238, 75, 238, 85, 238, 95,
+238, 105, 238, 115, 238, 125, 238, 136, 238, 146, 238, 156, 239, 69, 185, 203,
+190, 177, 239, 72, 209, 213, 242, 173, 239, 84, 239, 94, 239, 104, 183, 231,
+198, 174, 239, 124, 239, 133, 239, 143, 239, 153, 240, 66, 240, 74, 240, 84,
+240, 94, 240, 103, 240, 113, 240, 123, 240, 134, 240, 142, 240, 151, 210, 251,
+240, 154, 240, 158, 241, 64, 202, 215, 241, 72, 241, 80, 241, 90, 241, 100,
+241, 110, 241, 120, 241, 131, 241, 141, 241, 151, 242, 64, 242, 74, 242, 84,
+242, 94, 242, 104, 242, 114, 242, 124, 242, 135, 242, 145, 242, 155, 243, 68,
+243, 78, 243, 82, 205, 213, 194, 230, 230, 235, 201, 167, 214, 232, 243, 96,
+186, 161, 247, 196, 247, 198, 243, 121, 243, 130, 243, 138, 243, 145, 243, 153,
+247, 220, 244, 73, 244, 82, 244, 90, 244, 99, 244, 108, 198, 199, 244, 117,
+244, 124, 244, 135, 244, 145, 244, 155, 245, 68, 245, 78, 245, 88, 245, 98,
+245, 108, 245, 118, 245, 129, 245, 139, 245, 149, 245, 159, 246, 72, 246, 82,
+246, 92, 246, 102, 246, 112, 246, 122, 246, 133, 246, 143, 246, 153, 247, 66,
+247, 76, 247, 86, 247, 96, 247, 106, 247, 116, 247, 126, 247, 133, 246, 215,
+247, 141, 246, 227, 247, 145, 246, 243, 247, 150, 246, 253, 247, 167, 193, 219,
+248, 69, 248, 79, 248, 89, 248, 99, 248, 109, 248, 119, 248, 130, 248, 140,
+248, 150, 248, 160, 249, 73, 249, 83, 249, 93, 249, 103, 249, 113, 249, 123,
+249, 134, 249, 144, 249, 154, 250, 67, 250, 77, 250, 87, 250, 97, 250, 107,
+250, 117, 250, 128, 250, 138, 250, 148, 250, 158, 251, 71, 251, 81, 251, 91,
+240, 177, 240, 182, 251, 98, 240, 193, 251, 101, 240, 203, 186, 215, 251, 113,
+251, 120, 247, 228, 251, 135, 251, 143, 251, 151, 251, 160, 244, 240, 247, 226,
+252, 87, 252, 92, 247, 237, 252, 103, 252, 109, 252, 118, 252, 125, 182, 166,
+252, 140, 247, 247, 247, 248, 253, 68, 253, 73, 253, 82, 253, 90, 253, 100,
+253, 110, 253, 120, 253, 131, 246, 182, 253, 139, 185, 168, 253, 154, 170, 161,
+170, 171, 170, 181, 170, 191, 170, 201, 170, 211, 170, 221, 170, 231, 170, 241,
+170, 251, 171, 167, 171, 177, 171, 187, 171, 197, 171, 207, 171, 217, 171, 227,
+171, 237, 171, 247, 172, 163, 172, 173, 172, 183, 172, 193, 172, 203, 172, 213,
+172, 223, 172, 233, 172, 243, 172, 253, 173, 169, 173, 179, 173, 189, 173, 199,
+173, 209, 173, 219, 173, 229, 173, 239, 173, 249, 174, 165, 174, 175, 174, 185,
+174, 195, 174, 205, 174, 215, 174, 225, 174, 235, 174, 245, 175, 161, 175, 171,
+175, 181, 175, 191, 175, 201, 175, 211, 175, 221, 175, 231, 175, 241, 175, 251,
+248, 167, 248, 177, 248, 187, 248, 197, 248, 207, 248, 217, 248, 227, 248, 237,
+248, 247, 249, 163, 249, 173, 249, 183, 249, 193, 249, 203, 249, 213, 249, 223,
+249, 233, 249, 243, 249, 253, 250, 169, 250, 179, 250, 189, 250, 199, 250, 209,
+250, 219, 250, 229, 250, 239, 250, 249, 251, 165, 251, 175, 251, 185, 251, 195,
+251, 205, 251, 215, 251, 225, 251, 235, 251, 245, 252, 161, 252, 171, 252, 181,
+252, 191, 252, 201, 252, 211, 252, 221, 252, 231, 252, 241, 252, 251, 253, 167,
+253, 177, 253, 187, 253, 197, 253, 207, 253, 217, 253, 227, 253, 237, 253, 247,
+254, 163, 254, 173, 254, 183, 254, 193, 254, 203, 254, 213, 254, 223, 254, 233,
+254, 243, 254, 253, 161, 72, 161, 82, 161, 92, 161, 102, 161, 112, 161, 122,
+161, 133, 161, 143, 161, 153, 162, 66, 162, 76, 162, 86, 162, 96, 162, 106,
+162, 116, 162, 126, 162, 137, 162, 147, 162, 157, 163, 70, 163, 80, 163, 90,
+163, 100, 163, 110, 163, 120, 163, 131, 163, 141, 163, 151, 164, 64, 164, 74,
+164, 84, 164, 94, 164, 104, 164, 114, 164, 124, 164, 135, 164, 145, 164, 155,
+165, 68, 165, 78, 165, 88, 165, 98, 165, 108, 165, 118, 165, 129, 165, 139,
+165, 149, 165, 159, 166, 72, 166, 82, 166, 92, 166, 102, 166, 112, 166, 122,
+166, 133, 166, 143, 166, 153, 167, 66, 167, 76, 167, 86, 167, 96, 167, 106,
+167, 116, 167, 126, 167, 137, 167, 147, 167, 157, 162, 227, 164, 248, 165, 250,
+166, 190, 166, 236, 166, 253, 167, 202, 167, 245, 168, 150, 168, 160, 168, 237,
+168, 247, 169, 93, 169, 144, 169, 155, 169, 241, 169, 251, 254, 81, 254, 91,
+254, 101, 254, 111, 254, 121, 254, 132, 254, 142, 254, 152, 253, 156, 253, 157,
+253, 158, 253, 159, 253, 160, 254, 64, 254, 71, 254, 75, 169, 85, 166, 227,
+166, 235, 169, 109, 169, 118, 169, 129, 163, 161, 163, 171, 163, 181, 163, 191,
+163, 201, 163, 211, 163, 221, 163, 231, 163, 241, 163, 251, 161, 233, 0
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_ISO_2022_JP.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_ISO_2022_JP.java
new file mode 100644
index 0000000..b789ce3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_ISO_2022_JP.java
@@ -0,0 +1,381 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+public class OldCharset_MultiByte_ISO_2022_JP extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "ISO-2022-JP";
+
+ testChars = theseChars(new int[]{
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+162, 163, 165, 167, 168, 172, 176, 177, 180, 182, 215, 247, 913, 914, 924, 934,
+945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230, 8240, 8251,
+8451, 8491, 8592, 8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472,
+9484, 9495, 9507, 9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298,
+12308, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493,
+12503, 12513, 12523, 12533, 19968, 19978, 19988, 19998, 20010, 20022, 20034, 20045, 20055, 20066, 20081, 20094,
+20104, 20114, 20124, 20134, 20144, 20154, 20164, 20174, 20184, 20195, 20205, 20215, 20225, 20237, 20250, 20271,
+20282, 20294, 20304, 20314, 20329, 20339, 20351, 20363, 20374, 20384, 20395, 20405, 20415, 20426, 20436, 20447,
+20462, 20472, 20485, 20495, 20505, 20515, 20525, 20537, 20547, 20559, 20570, 20581, 20594, 20605, 20621, 20632,
+20652, 20663, 20674, 20685, 20698, 20709, 20725, 20736, 20754, 20767, 20778, 20791, 20801, 20811, 20826, 20837,
+20849, 20860, 20870, 20880, 20896, 20906, 20916, 20932, 20950, 20960, 20970, 20981, 20992, 21002, 21012, 21028,
+21038, 21048, 21059, 21069, 21083, 21093, 21103, 21117, 21127, 21137, 21147, 21161, 21172, 21182, 21193, 21205,
+21215, 21234, 21246, 21256, 21269, 21280, 21290, 21304, 21315, 21325, 21335, 21350, 21360, 21371, 21398, 21408,
+21421, 21435, 21448, 21460, 21471, 21481, 21491, 21505, 21515, 21531, 21542, 21558, 21568, 21578, 21599, 21610,
+21621, 21632, 21643, 21666, 21676, 21688, 21698, 21720, 21730, 21741, 21754, 21764, 21775, 21806, 21816, 21828,
+21839, 21852, 21883, 21895, 21912, 21927, 21942, 21956, 21972, 21983, 22007, 22022, 22036, 22057, 22068, 22082,
+22092, 22107, 22120, 22132, 22144, 22154, 22164, 22176, 22190, 22204, 22216, 22227, 22238, 22254, 22265, 22275,
+22285, 22296, 22310, 22320, 22331, 22343, 22353, 22369, 22399, 22409, 22419, 22432, 22442, 22464, 22475, 22486,
+22496, 22516, 22528, 22538, 22549, 22561, 22575, 22586, 22602, 22612, 22622, 22633, 22645, 22659, 22675, 22687,
+22699, 22712, 22725, 22737, 22748, 22763, 22775, 22786, 22799, 22809, 22821, 22833, 22846, 22856, 22868, 22880,
+22890, 22900, 22913, 22925, 22937, 22947, 22962, 22974, 22985, 22995, 23013, 23030, 23041, 23057, 23068, 23081,
+23093, 23104, 23130, 23142, 23167, 23186, 23228, 23241, 23254, 23265, 23290, 23305, 23318, 23330, 23340, 23350,
+23360, 23376, 23386, 23396, 23408, 23418, 23429, 23439, 23449, 23459, 23470, 23480, 23490, 23500, 23515, 23525,
+23536, 23546, 23556, 23566, 23578, 23588, 23601, 23611, 23621, 23631, 23646, 23660, 23670, 23692, 23713, 23723,
+23734, 23749, 23769, 23784, 23798, 23815, 23825, 23835, 23849, 23883, 23900, 23913, 23923, 23938, 23948, 23965,
+23980, 23991, 24009, 24019, 24029, 24039, 24049, 24059, 24070, 24081, 24091, 24101, 24111, 24125, 24135, 24148,
+24159, 24178, 24188, 24199, 24213, 24224, 24235, 24245, 24257, 24271, 24282, 24296, 24307, 24318, 24329, 24339,
+24351, 24361, 24373, 24385, 24396, 24406, 24417, 24427, 24439, 24449, 24459, 24471, 24481, 24493, 24505, 24515,
+24525, 24535, 24548, 24560, 24571, 24590, 24601, 24613, 24623, 24634, 24646, 24656, 24666, 24676, 24687, 24705,
+24715, 24726, 24736, 24746, 24756, 24773, 24785, 24796, 24807, 24817, 24827, 24838, 24853, 24863, 24876, 24892,
+24903, 24915, 24925, 24935, 24945, 24958, 24970, 24980, 24996, 25006, 25018, 25030, 25040, 25059, 25074, 25084,
+25096, 25106, 25117, 25130, 25140, 25151, 25161, 25171, 25182, 25192, 25206, 25216, 25226, 25236, 25246, 25259,
+25269, 25282, 25292, 25303, 25313, 25324, 25334, 25345, 25356, 25369, 25383, 25402, 25417, 25429, 25447, 25458,
+25472, 25484, 25494, 25504, 25514, 25524, 25534, 25545, 25558, 25569, 25582, 25594, 25606, 25619, 25638, 25652,
+25662, 25678, 25688, 25703, 25718, 25731, 25746, 25758, 25769, 25785, 25797, 25810, 25824, 25836, 25846, 25856,
+25880, 25891, 25903, 25913, 25925, 25935, 25945, 25955, 25968, 25986, 25996, 26007, 26017, 26027, 26039, 26049,
+26059, 26071, 26081, 26092, 26106, 26118, 26131, 26143, 26157, 26172, 26185, 26205, 26215, 26228, 26241, 26254,
+26264, 26274, 26286, 26296, 26308, 26326, 26336, 26352, 26364, 26376, 26388, 26398, 26408, 26420, 26431, 26441,
+26451, 26462, 26474, 26485, 26495, 26505, 26517, 26528, 26543, 26553, 26564, 26574, 26584, 26594, 26604, 26619,
+26643, 26654, 26665, 26676, 26688, 26701, 26713, 26723, 26740, 26750, 26765, 26775, 26786, 26797, 26809, 26820,
+26834, 26847, 26862, 26873, 26884, 26894, 26905, 26915, 26928, 26941, 26954, 26964, 26974, 26986, 26996, 27006,
+27018, 27028, 27040, 27054, 27067, 27079, 27091, 27101, 27111, 27122, 27133, 27146, 27156, 27166, 27177, 27189,
+27204, 27224, 27234, 27250, 27263, 27277, 27287, 27298, 27308, 27320, 27330, 27345, 27355, 27368, 27386, 27396,
+27410, 27421, 27431, 27442, 27453, 27463, 27475, 27487, 27497, 27507, 27519, 27529, 27541, 27556, 27567, 27578,
+27589, 27602, 27615, 27627, 27656, 27667, 27683, 27700, 27710, 27726, 27738, 27752, 27762, 27773, 27784, 27794,
+27809, 27819, 27832, 27844, 27859, 27869, 27880, 27891, 27915, 27927, 27941, 27954, 27965, 27993, 28003, 28014,
+28024, 28037, 28051, 28079, 28092, 28102, 28113, 28126, 28136, 28147, 28165, 28179, 28189, 28201, 28216, 28227,
+28237, 28248, 28263, 28274, 28286, 28300, 28310, 28322, 28335, 28346, 28356, 28369, 28381, 28396, 28407, 28417,
+28431, 28448, 28459, 28472, 28485, 28500, 28511, 28525, 28536, 28546, 28558, 28577, 28593, 28608, 28628, 28639,
+28651, 28662, 28673, 28683, 28693, 28703, 28716, 28734, 28748, 28760, 28771, 28783, 28796, 28809, 28825, 28844,
+28856, 28872, 28889, 28913, 28925, 28937, 28948, 28961, 28982, 29001, 29013, 29026, 29036, 29053, 29064, 29076,
+29087, 29100, 29113, 29123, 29134, 29151, 29164, 29177, 29190, 29200, 29211, 29224, 29234, 29244, 29254, 29266,
+29277, 29287, 29298, 29309, 29319, 29330, 29344, 29356, 29366, 29378, 29390, 29401, 29417, 29431, 29450, 29462,
+29477, 29487, 29502, 29518, 29539, 29552, 29562, 29572, 29590, 29609, 29619, 29632, 29642, 29662, 29674, 29688,
+29699, 29730, 29746, 29759, 29781, 29791, 29801, 29811, 29822, 29835, 29854, 29872, 29885, 29898, 29908, 29920,
+29934, 29944, 29955, 29965, 29976, 29987, 30000, 30010, 30020, 30031, 30041, 30052, 30064, 30079, 30089, 30100,
+30115, 30129, 30140, 30151, 30162, 30174, 30185, 30195, 30206, 30217, 30239, 30256, 30267, 30278, 30290, 30300,
+30311, 30322, 30332, 30342, 30352, 30362, 30382, 30392, 30402, 30413, 30423, 30433, 30446, 30456, 30468, 30491,
+30501, 30519, 30535, 30554, 30565, 30585, 30603, 30622, 30636, 30646, 30663, 30679, 30690, 30701, 30716, 30732,
+30752, 30770, 30783, 30813, 30827, 30844, 30854, 30865, 30883, 30895, 30906, 30917, 30928, 30938, 30951, 30964,
+30977, 30990, 31001, 31014, 31034, 31047, 31059, 31069, 31080, 31095, 31105, 31117, 31133, 31143, 31155, 31165,
+31177, 31189, 31199, 31209, 31227, 31240, 31252, 31263, 31278, 31291, 31302, 31312, 31329, 31339, 31350, 31361,
+31378, 31391, 31401, 31414, 31427, 31437, 31449, 31459, 31469, 31480, 31490, 31503, 31513, 31525, 31539, 31557,
+31567, 31581, 31591, 31601, 31622, 31634, 31644, 31658, 31668, 31680, 31691, 31709, 31721, 31731, 31744, 31757,
+31767, 31777, 31787, 31799, 31811, 31821, 31832, 31844, 31859, 31870, 31881, 31893, 31903, 31915, 31929, 31941,
+31954, 31964, 31975, 31986, 31998, 32010, 32020, 32032, 32043, 32053, 32063, 32075, 32086, 32097, 32110, 32121,
+32137, 32147, 32159, 32171, 32181, 32191, 32202, 32213, 32224, 32236, 32251, 32261, 32274, 32286, 32299, 32309,
+32321, 32331, 32341, 32358, 32368, 32379, 32392, 32402, 32412, 32566, 32581, 32592, 32607, 32617, 32629, 32642,
+32652, 32666, 32676, 32686, 32696, 32709, 32722, 32736, 32747, 32761, 32771, 32784, 32796, 32808, 32819, 32829,
+32842, 32854, 32865, 32879, 32889, 32900, 32915, 32925, 32937, 32948, 32963, 32974, 32985, 32996, 33007, 33020,
+33030, 33050, 33065, 33075, 33086, 33099, 33109, 33119, 33131, 33144, 33154, 33167, 33178, 33188, 33200, 33210,
+33222, 33233, 33247, 33258, 33268, 33278, 33288, 33298, 33308, 33321, 33331, 33344, 33368, 33378, 33390, 33400,
+33419, 33433, 33445, 33455, 33465, 33477, 33489, 33499, 33509, 33521, 33531, 33541, 33558, 33571, 33583, 33593,
+33605, 33615, 33651, 33669, 33683, 33694, 33704, 33717, 33729, 33740, 33750, 33760, 33771, 33783, 33795, 33805,
+33824, 33834, 33845, 33862, 33879, 33889, 33899, 33909, 33922, 33936, 33948, 33965, 33976, 33988, 34000, 34010,
+34028, 34044, 34054, 34065, 34079, 34092, 34109, 34120, 34133, 34147, 34157, 34167, 34180, 34192, 34203, 34214,
+34233, 34249, 34261, 34276, 34295, 34306, 34323, 34338, 34349, 34367, 34381, 34394, 34407, 34417, 34427, 34442,
+34453, 34467, 34479, 34500, 34510, 34521, 34532, 34542, 34552, 34562, 34573, 34584, 34597, 34612, 34623, 34633,
+34643, 34655, 34666, 34676, 34687, 34701, 34719, 34731, 34746, 34756, 34768, 34784, 34799, 34809, 34821, 34831,
+34849, 34865, 34875, 34886, 34898, 34909, 34920, 34930, 34941, 34952, 34962, 34974, 34987, 34997, 35007, 35023,
+35033, 35048, 35058, 35068, 35079, 35090, 35101, 35114, 35126, 35137, 35148, 35158, 35168, 35178, 35188, 35198,
+35208, 35219, 35233, 35244, 35258, 35282, 35292, 35302, 35316, 35328, 35338, 35350, 35363, 35373, 35386, 35398,
+35408, 35419, 35430, 35440, 35452, 35463, 35473, 35486, 35496, 35506, 35516, 35527, 35538, 35548, 35558, 35569,
+35582, 35596, 35606, 35616, 35627, 35641, 35657, 35670, 35686, 35696, 35709, 35722, 35734, 35895, 35905, 35916,
+35930, 35946, 35960, 35970, 35980, 35992, 36002, 36012, 36022, 36032, 36042, 36058, 36068, 36090, 36100, 36111,
+36196, 36208, 36225, 36249, 36259, 36275, 36286, 36299, 36310, 36321, 36331, 36341, 36351, 36361, 36381, 36394,
+36404, 36418, 36428, 36441, 36451, 36466, 36476, 36487, 36497, 36513, 36523, 36542, 36552, 36562, 36575, 36587,
+36600, 36611, 36626, 36636, 36646, 36659, 36670, 36681, 36695, 36705, 36763, 36775, 36785, 36795, 36805, 36817,
+36834, 36845, 36855, 36865, 36875, 36885, 36895, 36910, 36920, 36930, 36941, 36952, 36963, 36973, 36983, 36993,
+37007, 37027, 37039, 37057, 37070, 37083, 37096, 37109, 37122, 37138, 37165, 37193, 37204, 37218, 37228, 37239,
+37250, 37261, 37271, 37282, 37295, 37306, 37318, 37328, 37339, 37350, 37365, 37375, 37389, 37406, 37417, 37428,
+37439, 37449, 37463, 37474, 37489, 37502, 37521, 37531, 37549, 37559, 37583, 37604, 37618, 37628, 37638, 37648,
+37658, 37670, 37682, 37700, 37716, 37728, 37740, 37756, 37772, 37782, 37799, 37817, 37827, 37840, 37853, 37864,
+37891, 37904, 37914, 37931, 37941, 37953, 37969, 37979, 37994, 38005, 38015, 38263, 38274, 38287, 38297, 38307,
+38317, 38329, 38339, 38349, 38360, 38370, 38428, 38440, 38450, 38463, 38475, 38491, 38501, 38512, 38522, 38533,
+38543, 38553, 38563, 38576, 38587, 38597, 38609, 38619, 38632, 38642, 38656, 38666, 38678, 38692, 38704, 38717,
+38728, 38738, 38748, 38758, 38769, 38780, 38790, 38800, 38812, 38822, 38835, 38851, 38867, 38893, 38907, 38917,
+38927, 38938, 38948, 38964, 38982, 38996, 39006, 39019, 39080, 39094, 39107, 39131, 39145, 39156, 39166, 39177,
+39187, 39197, 39208, 39229, 39241, 39253, 39318, 39333, 39347, 39361, 39376, 39387, 39405, 39416, 39429, 39439,
+39449, 39464, 39479, 39490, 39501, 39511, 39522, 39592, 39608, 39620, 39631, 39646, 39658, 39668, 39686, 39704,
+39714, 39726, 39739, 39749, 39759, 39770, 39791, 39811, 39822, 39839, 39850, 39860, 39872, 39882, 39892, 39905,
+39920, 39940, 39952, 39963, 39973, 39983, 39993, 40006, 40018, 40032, 40054, 40165, 40176, 40195, 40206, 40219,
+40230, 40251, 40262, 40272, 40284, 40300, 40314, 40327, 40346, 40356, 40367, 40378, 40388, 40399, 40409, 40422,
+40434, 40445, 40474, 40565, 40575, 40587, 40597, 40607, 40617, 40632, 40644, 40654, 40664, 40677, 40687, 40697,
+40711, 40723, 40736, 40748, 40763, 40778, 40788, 40799, 40810, 40822, 40845, 40860, 65281, 65291, 65301, 65311,
+65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401, 65411, 65421, 65431, 65507
+ });
+
+ testBytes = theseBytes(new int[]{
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+27, 36, 66, 33, 113, 33, 114, 27, 40, 74, 92, 27, 36, 66, 33, 120,
+33, 47, 34, 76, 33, 107, 33, 94, 33, 45, 34, 121, 33, 95, 33, 96,
+38, 33, 38, 34, 38, 44, 38, 53, 38, 65, 38, 75, 38, 84, 39, 39,
+39, 33, 39, 44, 39, 54, 39, 64, 39, 90, 39, 100, 39, 110, 33, 62,
+33, 72, 33, 68, 34, 115, 34, 40, 33, 110, 34, 114, 34, 43, 34, 77,
+34, 79, 34, 59, 34, 101, 34, 74, 33, 104, 34, 98, 33, 98, 34, 99,
+34, 62, 34, 93, 34, 94, 40, 33, 40, 35, 40, 49, 40, 50, 40, 56,
+40, 53, 40, 54, 34, 35, 34, 37, 34, 39, 34, 33, 34, 126, 33, 122,
+33, 106, 34, 118, 33, 33, 33, 84, 33, 76, 36, 33, 36, 43, 36, 53,
+36, 63, 36, 73, 36, 83, 36, 93, 36, 103, 36, 113, 33, 43, 37, 37,
+37, 47, 37, 57, 37, 67, 37, 77, 37, 87, 37, 97, 37, 107, 37, 117,
+48, 108, 62, 101, 51, 110, 62, 103, 80, 36, 80, 38, 80, 41, 70, 99,
+62, 104, 86, 38, 77, 112, 52, 37, 77, 61, 56, 95, 48, 33, 75, 114,
+80, 55, 63, 77, 80, 60, 80, 58, 73, 85, 66, 101, 80, 65, 80, 67,
+52, 107, 56, 96, 50, 113, 71, 108, 59, 71, 67, 34, 58, 52, 80, 69,
+80, 80, 50, 66, 59, 72, 78, 99, 80, 85, 54, 34, 85, 37, 63, 47,
+74, 88, 61, 83, 80, 87, 80, 88, 61, 36, 74, 112, 80, 102, 96, 71,
+56, 117, 74, 111, 79, 65, 55, 112, 80, 112, 74, 80, 80, 118, 55, 114,
+60, 69, 53, 54, 75, 53, 59, 49, 58, 69, 61, 125, 81, 36, 70, 47,
+78, 61, 81, 39, 81, 44, 53, 55, 60, 116, 61, 126, 77, 37, 81, 54,
+48, 116, 57, 110, 69, 94, 70, 126, 54, 38, 55, 115, 49, 95, 102, 110,
+52, 39, 81, 81, 58, 99, 64, 40, 82, 69, 81, 92, 70, 100, 81, 97,
+69, 97, 52, 41, 81, 101, 72, 61, 81, 105, 55, 116, 68, 102, 65, 48,
+57, 100, 71, 109, 73, 123, 81, 119, 55, 96, 81, 125, 78, 79, 61, 117,
+79, 43, 51, 47, 74, 89, 70, 48, 74, 103, 55, 46, 56, 123, 82, 51,
+82, 56, 62, 34, 72, 91, 82, 62, 64, 105, 82, 68, 70, 110, 55, 53,
+48, 117, 82, 74, 82, 77, 82, 78, 49, 94, 53, 110, 75, 116, 61, 71,
+82, 87, 67, 33, 49, 38, 82, 94, 49, 37, 55, 47, 72, 93, 82, 101,
+82, 96, 57, 112, 82, 108, 60, 118, 82, 106, 82, 114, 58, 112, 82, 120,
+82, 123, 82, 121, 83, 34, 83, 38, 83, 47, 83, 45, 83, 46, 49, 52,
+83, 41, 83, 52, 83, 57, 66, 111, 76, 100, 83, 53, 83, 65, 83, 73,
+83, 67, 55, 118, 49, 68, 83, 78, 83, 81, 83, 77, 83, 83, 67, 50,
+83, 82, 50, 94, 83, 92, 49, 61, 65, 57, 51, 122, 52, 111, 74, 46,
+83, 102, 83, 103, 83, 105, 83, 104, 83, 108, 83, 112, 83, 116, 83, 119,
+50, 115, 83, 121, 83, 122, 74, 96, 84, 35, 84, 37, 84, 41, 67, 79,
+84, 45, 54, 81, 57, 35, 84, 51, 84, 52, 84, 53, 84, 54, 84, 55,
+84, 58, 84, 49, 75, 100, 84, 66, 73, 86, 62, 125, 75, 89, 84, 65,
+66, 68, 84, 72, 116, 33, 58, 102, 50, 116, 69, 99, 58, 73, 49, 118,
+63, 80, 54, 45, 74, 104, 84, 82, 84, 83, 84, 87, 84, 89, 84, 91,
+84, 96, 59, 78, 68, 91, 84, 105, 50, 70, 61, 72, 84, 110, 60, 58,
+84, 115, 70, 96, 75, 91, 84, 123, 67, 37, 69, 91, 85, 34, 85, 43,
+76, 47, 85, 38, 85, 39, 62, 42, 59, 80, 64, 43, 49, 56, 48, 40,
+48, 82, 85, 48, 85, 49, 74, 90, 85, 55, 85, 52, 58, 39, 73, 88,
+76, 59, 71, 94, 85, 60, 60, 59, 85, 69, 67, 100, 85, 70, 52, 114,
+85, 74, 62, 110, 68, 92, 85, 78, 85, 82, 59, 82, 85, 85, 56, 73,
+85, 89, 85, 94, 66, 112, 57, 40, 67, 104, 64, 107, 53, 92, 85, 98,
+60, 100, 73, 89, 52, 50, 85, 108, 85, 110, 59, 123, 60, 77, 70, 51,
+62, 48, 76, 96, 61, 34, 63, 44, 53, 111, 86, 34, 66, 48, 86, 36,
+86, 39, 86, 41, 50, 44, 86, 45, 86, 47, 86, 50, 86, 53, 50, 101,
+69, 103, 63, 114, 86, 66, 86, 65, 74, 120, 86, 75, 86, 63, 63, 115,
+86, 77, 86, 81, 86, 58, 86, 83, 86, 84, 86, 88, 86, 90, 86, 92,
+64, 110, 57, 42, 56, 74, 52, 44, 72, 65, 86, 102, 86, 103, 63, 99,
+66, 83, 75, 57, 86, 115, 86, 111, 86, 112, 52, 51, 77, 68, 72, 95,
+68, 108, 86, 121, 56, 75, 48, 67, 86, 122, 86, 126, 87, 36, 87, 40,
+87, 44, 87, 48, 87, 50, 53, 93, 68, 111, 87, 56, 68, 37, 87, 59,
+87, 61, 87, 65, 87, 68, 68, 38, 87, 71, 64, 44, 78, 39, 70, 64,
+56, 102, 87, 84, 69, 48, 63, 52, 71, 38, 59, 86, 87, 88, 88, 45,
+87, 87, 87, 99, 87, 96, 53, 94, 54, 49, 87, 106, 87, 113, 54, 50,
+87, 107, 87, 117, 66, 41, 87, 122, 88, 39, 88, 35, 77, 42, 48, 45,
+88, 44, 62, 112, 79, 71, 64, 75, 87, 124, 88, 61, 88, 60, 88, 52,
+88, 51, 52, 54, 88, 71, 88, 70, 88, 64, 88, 88, 88, 87, 55, 69,
+88, 85, 77, 93, 88, 96, 88, 94, 74, 48, 88, 99, 88, 107, 88, 106,
+50, 123, 88, 112, 68, 40, 88, 118, 88, 121, 50, 124, 108, 67, 89, 35,
+66, 87, 75, 60, 72, 98, 66, 71, 89, 42, 89, 46, 73, 94, 53, 59,
+71, 68, 89, 56, 66, 114, 72, 100, 68, 113, 89, 68, 89, 66, 89, 57,
+51, 72, 51, 103, 59, 34, 59, 125, 89, 72, 53, 115, 89, 75, 68, 114,
+66, 42, 74, 97, 74, 123, 55, 126, 89, 87, 62, 56, 89, 85, 78, 43,
+65, 60, 68, 79, 89, 97, 89, 102, 77, 44, 48, 46, 52, 120, 77, 73,
+89, 108, 89, 109, 89, 110, 89, 107, 58, 113, 89, 119, 69, 38, 89, 116,
+89, 118, 55, 98, 59, 53, 70, 53, 89, 124, 51, 73, 90, 35, 90, 34,
+90, 43, 53, 60, 90, 49, 90, 53, 90, 55, 90, 59, 59, 89, 50, 126,
+56, 78, 73, 82, 54, 53, 59, 54, 63, 116, 90, 76, 73, 76, 69, 77,
+48, 54, 90, 81, 90, 82, 90, 85, 64, 123, 52, 122, 90, 92, 61, 92,
+50, 34, 58, 43, 48, 87, 64, 49, 62, 60, 67, 107, 90, 105, 90, 108,
+90, 110, 64, 50, 54, 71, 90, 117, 90, 120, 68, 42, 74, 107, 91, 34,
+91, 33, 91, 35, 91, 37, 91, 41, 82, 88, 55, 110, 58, 115, 91, 46,
+76, 90, 75, 81, 91, 51, 63, 121, 60, 93, 91, 57, 91, 66, 53, 79,
+72, 68, 91, 62, 75, 109, 79, 72, 56, 79, 91, 84, 74, 65, 91, 85,
+68, 83, 91, 82, 91, 75, 58, 58, 64, 114, 91, 89, 91, 91, 64, 115,
+91, 92, 91, 93, 91, 98, 91, 99, 91, 111, 91, 117, 91, 116, 57, 60,
+62, 63, 91, 104, 91, 110, 52, 126, 75, 64, 69, 111, 63, 57, 92, 42,
+92, 38, 68, 71, 63, 122, 92, 48, 92, 63, 92, 61, 77, 76, 92, 56,
+92, 65, 92, 68, 92, 60, 92, 57, 58, 103, 79, 49, 92, 85, 92, 70,
+92, 80, 116, 34, 92, 74, 92, 79, 92, 97, 92, 96, 65, 101, 92, 104,
+92, 102, 92, 100, 56, 34, 62, 65, 92, 109, 53, 76, 92, 115, 92, 111,
+51, 96, 92, 122, 93, 33, 92, 125, 93, 40, 93, 38, 93, 37, 93, 42,
+54, 123, 72, 39, 93, 50, 77, 115, 93, 51, 49, 53, 50, 36, 77, 95,
+54, 86, 93, 60, 52, 63, 93, 67, 74, 98, 58, 80, 93, 71, 61, 94,
+93, 77, 93, 79, 93, 82, 59, 38, 53, 35, 70, 71, 93, 91, 93, 93,
+93, 97, 93, 98, 93, 102, 63, 101, 72, 69, 72, 70, 49, 120, 93, 113,
+53, 98, 53, 37, 68, 64, 93, 115, 75, 87, 75, 119, 74, 40, 93, 117,
+93, 119, 93, 123, 67, 109, 49, 75, 77, 78, 64, 118, 68, 69, 61, 39,
+94, 42, 94, 54, 94, 49, 73, 98, 63, 59, 94, 58, 94, 50, 51, 54,
+78, 67, 94, 66, 61, 74, 94, 68, 94, 70, 61, 95, 64, 54, 55, 76,
+94, 97, 50, 57, 94, 98, 94, 92, 94, 90, 62, 69, 77, 47, 94, 83,
+79, 81, 72, 46, 61, 96, 48, 110, 94, 106, 69, 46, 94, 107, 51, 106,
+66, 108, 94, 118, 95, 35, 53, 121, 79, 51, 71, 121, 76, 33, 65, 50,
+52, 67, 55, 105, 51, 99, 95, 44, 95, 38, 95, 45, 95, 48, 95, 54,
+69, 67, 55, 99, 95, 62, 95, 59, 77, 116, 111, 105, 95, 71, 95, 68,
+73, 78, 95, 79, 64, 37, 95, 81, 94, 117, 70, 103, 95, 84, 69, 116,
+60, 94, 79, 39, 95, 85, 95, 89, 95, 90, 78, 117, 95, 96, 95, 88,
+95, 98, 95, 97, 49, 107, 76, 53, 65, 51, 78, 123, 95, 102, 95, 105,
+95, 108, 64, 122, 95, 103, 77, 80, 61, 79, 95, 114, 95, 116, 71, 51,
+95, 121, 83, 91, 95, 123, 96, 33, 71, 122, 96, 36, 96, 37, 96, 38,
+96, 42, 96, 44, 96, 47, 68, 45, 76, 70, 75, 82, 64, 55, 56, 35,
+96, 54, 96, 55, 53, 62, 56, 36, 62, 117, 54, 56, 96, 64, 65, 64,
+60, 109, 96, 70, 96, 73, 96, 75, 96, 80, 96, 78, 96, 81, 96, 82,
+61, 67, 96, 88, 96, 92, 56, 60, 54, 106, 52, 97, 96, 94, 96, 97,
+59, 57, 96, 100, 55, 62, 96, 105, 53, 101, 66, 118, 96, 106, 96, 109,
+96, 108, 96, 110, 96, 114, 58, 60, 96, 119, 96, 120, 96, 121, 52, 68,
+60, 37, 96, 123, 96, 125, 97, 33, 97, 37, 97, 41, 97, 44, 97, 48,
+52, 69, 59, 58, 69, 68, 68, 46, 97, 55, 48, 90, 78, 49, 97, 63,
+48, 91, 53, 38, 97, 73, 97, 75, 97, 79, 97, 87, 97, 86, 62, 73,
+97, 90, 97, 93, 65, 105, 97, 101, 97, 94, 97, 104, 97, 105, 97, 112,
+97, 113, 97, 116, 76, 126, 97, 117, 97, 124, 98, 33, 98, 36, 51, 39,
+59, 41, 98, 45, 72, 105, 98, 48, 98, 51, 98, 52, 69, 112, 98, 56,
+76, 92, 65, 106, 98, 64, 98, 70, 98, 68, 98, 71, 98, 73, 98, 74,
+98, 78, 98, 81, 98, 83, 98, 86, 61, 86, 98, 88, 98, 94, 98, 96,
+76, 112, 67, 59, 98, 101, 98, 102, 98, 105, 75, 36, 57, 92, 62, 75,
+78, 50, 98, 111, 98, 110, 72, 106, 98, 114, 98, 117, 51, 78, 98, 124,
+72, 88, 99, 34, 99, 33, 99, 36, 62, 76, 65, 67, 99, 40, 98, 104,
+60, 40, 53, 64, 99, 49, 61, 75, 73, 60, 69, 120, 54, 88, 50, 82,
+99, 53, 99, 54, 99, 58, 54, 89, 99, 61, 99, 62, 65, 69, 67, 97,
+48, 92, 99, 67, 76, 45, 99, 72, 60, 111, 99, 75, 75, 84, 48, 44,
+99, 81, 51, 79, 53, 102, 70, 77, 67, 98, 55, 34, 99, 93, 99, 96,
+51, 118, 99, 103, 99, 107, 61, 87, 99, 113, 81, 63, 99, 115, 99, 116,
+99, 121, 63, 90, 99, 119, 100, 38, 72, 53, 100, 56, 100, 42, 100, 44,
+74, 79, 100, 54, 100, 51, 67, 61, 100, 62, 64, 97, 100, 58, 100, 64,
+100, 65, 100, 74, 100, 71, 100, 77, 100, 76, 52, 74, 100, 84, 100, 83,
+100, 87, 64, 82, 100, 92, 100, 94, 74, 70, 76, 98, 74, 52, 71, 116,
+48, 64, 100, 104, 100, 111, 100, 114, 100, 117, 100, 118, 78, 72, 100, 122,
+53, 106, 101, 36, 61, 99, 65, 71, 59, 103, 101, 42, 101, 41, 101, 38,
+101, 45, 77, 109, 101, 49, 56, 40, 101, 53, 101, 52, 101, 70, 101, 64,
+101, 61, 76, 74, 54, 91, 101, 110, 68, 121, 76, 75, 101, 76, 101, 79,
+101, 83, 60, 74, 75, 37, 101, 92, 72, 75, 55, 82, 65, 54, 101, 90,
+55, 43, 101, 108, 101, 114, 101, 117, 101, 124, 52, 76, 102, 33, 102, 37,
+102, 42, 102, 45, 71, 77, 102, 48, 102, 53, 102, 57, 55, 50, 102, 62,
+102, 64, 102, 66, 61, 44, 63, 105, 52, 101, 102, 75, 57, 77, 66, 81,
+102, 83, 102, 85, 60, 42, 67, 63, 102, 88, 64, 59, 65, 111, 78, 126,
+102, 100, 102, 103, 102, 107, 52, 78, 56, 42, 58, 104, 48, 95, 66, 91,
+102, 114, 48, 125, 102, 120, 103, 38, 64, 72, 53, 83, 102, 123, 71, 62,
+103, 35, 102, 126, 79, 83, 103, 53, 60, 112, 68, 50, 103, 48, 57, 81,
+73, 102, 103, 51, 103, 56, 103, 63, 50, 50, 103, 66, 103, 71, 60, 43,
+67, 87, 103, 76, 54, 61, 80, 48, 61, 88, 103, 85, 103, 88, 103, 89,
+103, 91, 103, 96, 58, 49, 103, 103, 48, 114, 73, 103, 51, 41, 63, 68,
+54, 92, 52, 35, 49, 113, 50, 87, 60, 99, 49, 81, 103, 120, 51, 125,
+104, 35, 104, 52, 104, 42, 104, 39, 104, 41, 49, 65, 104, 58, 104, 46,
+103, 118, 52, 80, 104, 62, 104, 57, 104, 71, 54, 93, 62, 84, 104, 74,
+104, 65, 104, 72, 104, 68, 104, 76, 104, 78, 104, 84, 104, 98, 104, 94,
+67, 120, 73, 114, 104, 89, 48, 42, 104, 92, 61, 47, 73, 71, 104, 90,
+62, 120, 67, 95, 104, 108, 104, 107, 75, 41, 104, 122, 104, 81, 74, 78,
+104, 119, 104, 118, 74, 67, 104, 126, 105, 36, 104, 124, 105, 43, 105, 49,
+71, 118, 105, 51, 105, 45, 65, 38, 105, 55, 105, 52, 105, 57, 70, 35,
+61, 115, 105, 34, 105, 63, 105, 68, 77, 118, 105, 71, 105, 72, 53, 117,
+105, 76, 105, 77, 48, 58, 50, 99, 59, 61, 105, 79, 105, 85, 105, 86,
+51, 66, 51, 63, 72, 58, 72, 90, 66, 125, 75, 42, 105, 107, 67, 88,
+105, 114, 105, 110, 105, 111, 64, 102, 106, 33, 105, 118, 106, 35, 105, 122,
+71, 104, 77, 59, 106, 38, 106, 46, 77, 102, 106, 47, 106, 44, 106, 54,
+106, 52, 51, 42, 106, 36, 106, 55, 106, 66, 106, 67, 106, 71, 61, 48,
+106, 74, 62, 87, 73, 61, 106, 85, 106, 83, 55, 54, 106, 88, 106, 81,
+72, 111, 106, 84, 106, 95, 78, 34, 106, 101, 106, 107, 106, 108, 106, 105,
+74, 35, 75, 43, 106, 124, 106, 116, 106, 121, 106, 118, 106, 123, 50, 40,
+106, 125, 107, 36, 107, 38, 107, 40, 107, 42, 107, 44, 107, 46, 107, 49,
+107, 52, 51, 81, 107, 57, 63, 40, 107, 60, 56, 64, 63, 86, 107, 63,
+55, 109, 64, 95, 63, 71, 107, 73, 58, 62, 107, 71, 59, 110, 53, 77,
+107, 75, 56, 88, 107, 84, 56, 108, 107, 82, 50, 93, 53, 67, 67, 76,
+78, 74, 68, 53, 68, 124, 107, 97, 66, 122, 107, 104, 107, 108, 107, 111,
+107, 115, 54, 96, 107, 122, 107, 123, 55, 89, 53, 68, 108, 37, 90, 78,
+108, 43, 67, 43, 108, 47, 108, 50, 70, 90, 57, 107, 108, 56, 108, 58,
+75, 70, 108, 66, 57, 87, 64, 85, 108, 74, 50, 108, 66, 49, 108, 79,
+108, 77, 108, 81, 108, 83, 108, 87, 64, 86, 65, 118, 108, 99, 108, 100,
+60, 113, 66, 45, 108, 102, 108, 109, 108, 106, 64, 87, 108, 111, 65, 41,
+108, 117, 108, 116, 108, 118, 109, 41, 108, 125, 108, 122, 109, 35, 109, 38,
+109, 42, 109, 45, 109, 46, 109, 48, 109, 54, 109, 58, 63, 72, 109, 63,
+109, 65, 56, 46, 70, 112, 109, 71, 60, 52, 51, 83, 109, 76, 109, 79,
+109, 83, 109, 84, 109, 89, 109, 91, 109, 94, 55, 37, 63, 73, 82, 33,
+63, 43, 68, 84, 63, 87, 54, 97, 109, 107, 69, 51, 76, 66, 65, 119,
+109, 121, 109, 116, 66, 46, 66, 97, 48, 111, 63, 107, 74, 87, 110, 41,
+56, 47, 65, 120, 65, 43, 110, 50, 110, 54, 70, 97, 110, 56, 48, 106,
+79, 58, 110, 62, 73, 116, 77, 57, 110, 63, 110, 64, 69, 34, 70, 83,
+63, 108, 63, 93, 61, 55, 57, 115, 110, 78, 66, 105, 72, 48, 110, 79,
+110, 81, 110, 85, 72, 80, 110, 90, 110, 94, 75, 85, 110, 96, 110, 99,
+70, 95, 110, 98, 111, 79, 78, 107, 110, 111, 110, 107, 110, 105, 72, 45,
+57, 91, 75, 72, 65, 45, 110, 117, 65, 44, 110, 121, 110, 119, 61, 123,
+73, 70, 57, 93, 59, 44, 63, 109, 111, 35, 54, 83, 79, 63, 110, 125,
+68, 87, 111, 41, 55, 45, 111, 42, 51, 121, 58, 63, 51, 59, 111, 49,
+111, 55, 111, 57, 111, 56, 111, 52, 111, 63, 111, 65, 111, 60, 111, 67,
+111, 68, 111, 71, 52, 85, 111, 74, 111, 78, 111, 81, 111, 88, 68, 57,
+111, 89, 49, 60, 111, 95, 51, 85, 111, 99, 111, 102, 111, 106, 111, 107,
+70, 46, 111, 115, 73, 108, 111, 117, 75, 73, 48, 36, 111, 123, 74, 69,
+52, 89, 49, 34, 56, 49, 54, 121, 63, 111, 55, 100, 78, 89, 112, 46,
+64, 73, 50, 109, 59, 40, 63, 119, 49, 43, 49, 64, 60, 123, 78, 110,
+112, 67, 112, 69, 112, 71, 112, 73, 112, 77, 64, 68, 112, 80, 112, 83,
+112, 87, 112, 90, 112, 93, 112, 96, 112, 97, 112, 99, 112, 101, 112, 103,
+52, 90, 112, 108, 49, 36, 57, 96, 112, 114, 55, 91, 112, 117, 49, 80,
+112, 121, 52, 105, 78, 96, 112, 124, 73, 119, 113, 39, 113, 41, 72, 116,
+113, 43, 48, 59, 62, 126, 113, 46, 50, 110, 113, 51, 52, 91, 113, 57,
+113, 60, 113, 67, 60, 115, 113, 70, 67, 90, 71, 125, 67, 115, 113, 75,
+113, 79, 113, 84, 113, 87, 113, 86, 113, 89, 66, 77, 113, 91, 113, 93,
+113, 98, 113, 100, 113, 102, 57, 124, 51, 60, 63, 113, 113, 112, 113, 116,
+72, 49, 113, 124, 114, 34, 114, 35, 114, 38, 114, 45, 100, 120, 76, 37,
+114, 50, 53, 123, 79, 37, 114, 57, 48, 62, 114, 61, 75, 110, 114, 64,
+114, 65, 114, 66, 114, 75, 114, 76, 114, 80, 114, 90, 79, 76, 114, 92,
+114, 93, 48, 115, 51, 111, 114, 99, 75, 112, 114, 102, 114, 104, 68, 59,
+114, 108, 114, 112, 50, 42, 49, 117, 114, 115, 57, 99, 114, 125, 115, 37,
+49, 45, 75, 50, 115, 44, 115, 41, 115, 45, 115, 46, 114, 116, 115, 53,
+115, 49, 115, 55, 115, 57, 115, 60, 79, 73, 115, 63, 115, 64, 115, 67,
+60, 47, 115, 72, 115, 75, 78, 91, 115, 79, 115, 80, 50, 43, 115, 85,
+96, 84, 115, 93, 115, 95, 115, 99, 115, 103, 56, 93, 65, 77, 115, 108,
+73, 33, 115, 110, 115, 112, 115, 114, 115, 120, 115, 123, 78, 54, 115, 125,
+33, 42, 33, 92, 35, 53, 33, 41, 35, 73, 35, 83, 33, 79, 35, 103,
+35, 113, 33, 80, 27, 40, 73, 37, 47, 57, 67, 77, 87, 27, 36, 66,
+33, 49
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic() throws CharacterCodingException {
+ super.test_CodecDynamic();
+ }
+
+ @Override
+ public void test_Decode() throws CharacterCodingException {
+ super.test_Decode();
+ }
+
+ @Override
+ public void test_Encode() throws CharacterCodingException {
+ super.test_Encode();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16.java
new file mode 100644
index 0000000..29c42a3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16.java
@@ -0,0 +1,382 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** @hide
+ * SEE correspondig_Android test class:
+ */
+
+public class OldCharset_MultiByte_UTF_16 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "UTF-16";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
+896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
+1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
+2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
+2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
+3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
+4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
+4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
+5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
+6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
+6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
+7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
+7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
+8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
+9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
+9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
+10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
+11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
+11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
+12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
+13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
+13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
+14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
+14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
+15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
+16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
+16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
+17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
+18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
+18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
+19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
+20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
+20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
+21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
+22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
+22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
+23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
+23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
+24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
+25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
+25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
+26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
+27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
+27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
+28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
+29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
+29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
+30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
+30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
+31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
+32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
+32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
+33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
+34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
+34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
+35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
+36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
+36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
+37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
+38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
+38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
+39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
+39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
+40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
+41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
+41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
+42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
+43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
+43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
+44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
+45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
+45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
+46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
+46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
+47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
+48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
+48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
+49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
+50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
+50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
+51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
+52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
+52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
+53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
+54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
+54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
+57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
+57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
+58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
+59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
+59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
+60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
+61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
+61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
+62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
+63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
+63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
+64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
+65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+254, 255, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6,
+0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14,
+0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22,
+0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30,
+0, 31, 0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38,
+0, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46,
+0, 47, 0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54,
+0, 55, 0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62,
+0, 63, 0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70,
+0, 71, 0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78,
+0, 79, 0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86,
+0, 87, 0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94,
+0, 95, 0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102,
+0, 103, 0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110,
+0, 111, 0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118,
+0, 119, 0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126,
+0, 127, 0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134,
+0, 135, 0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142,
+0, 143, 0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150,
+0, 151, 0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158,
+0, 159, 0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166,
+0, 167, 0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174,
+0, 175, 0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182,
+0, 183, 0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190,
+0, 191, 0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198,
+0, 199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206,
+0, 207, 0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214,
+0, 215, 0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222,
+0, 223, 0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230,
+0, 231, 0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238,
+0, 239, 0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246,
+0, 247, 0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254,
+0, 255, 1, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240,
+2, 24, 2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 3, 8, 3, 48,
+3, 88, 3, 128, 3, 168, 3, 208, 3, 248, 4, 32, 4, 72, 4, 112,
+4, 152, 4, 192, 4, 232, 5, 16, 5, 56, 5, 96, 5, 136, 5, 176,
+5, 216, 6, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240,
+7, 24, 7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 8, 8, 8, 48,
+8, 88, 8, 128, 8, 168, 8, 208, 8, 248, 9, 32, 9, 72, 9, 112,
+9, 152, 9, 192, 9, 232, 10, 16, 10, 56, 10, 96, 10, 136, 10, 176,
+10, 216, 11, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240,
+12, 24, 12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 13, 8, 13, 48,
+13, 88, 13, 128, 13, 168, 13, 208, 13, 248, 14, 32, 14, 72, 14, 112,
+14, 152, 14, 192, 14, 232, 15, 16, 15, 56, 15, 96, 15, 136, 15, 176,
+15, 216, 16, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240,
+17, 24, 17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 18, 8, 18, 48,
+18, 88, 18, 128, 18, 168, 18, 208, 18, 248, 19, 32, 19, 72, 19, 112,
+19, 152, 19, 192, 19, 232, 20, 16, 20, 56, 20, 96, 20, 136, 20, 176,
+20, 216, 21, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240,
+22, 24, 22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 23, 8, 23, 48,
+23, 88, 23, 128, 23, 168, 23, 208, 23, 248, 24, 32, 24, 72, 24, 112,
+24, 152, 24, 192, 24, 232, 25, 16, 25, 56, 25, 96, 25, 136, 25, 176,
+25, 216, 26, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240,
+27, 24, 27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 28, 8, 28, 48,
+28, 88, 28, 128, 28, 168, 28, 208, 28, 248, 29, 32, 29, 72, 29, 112,
+29, 152, 29, 192, 29, 232, 30, 16, 30, 56, 30, 96, 30, 136, 30, 176,
+30, 216, 31, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240,
+32, 24, 32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 33, 8, 33, 48,
+33, 88, 33, 128, 33, 168, 33, 208, 33, 248, 34, 32, 34, 72, 34, 112,
+34, 152, 34, 192, 34, 232, 35, 16, 35, 56, 35, 96, 35, 136, 35, 176,
+35, 216, 36, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240,
+37, 24, 37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 38, 8, 38, 48,
+38, 88, 38, 128, 38, 168, 38, 208, 38, 248, 39, 32, 39, 72, 39, 112,
+39, 152, 39, 192, 39, 232, 40, 16, 40, 56, 40, 96, 40, 136, 40, 176,
+40, 216, 41, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240,
+42, 24, 42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 43, 8, 43, 48,
+43, 88, 43, 128, 43, 168, 43, 208, 43, 248, 44, 32, 44, 72, 44, 112,
+44, 152, 44, 192, 44, 232, 45, 16, 45, 56, 45, 96, 45, 136, 45, 176,
+45, 216, 46, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240,
+47, 24, 47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 48, 8, 48, 48,
+48, 88, 48, 128, 48, 168, 48, 208, 48, 248, 49, 32, 49, 72, 49, 112,
+49, 152, 49, 192, 49, 232, 50, 16, 50, 56, 50, 96, 50, 136, 50, 176,
+50, 216, 51, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240,
+52, 24, 52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 53, 8, 53, 48,
+53, 88, 53, 128, 53, 168, 53, 208, 53, 248, 54, 32, 54, 72, 54, 112,
+54, 152, 54, 192, 54, 232, 55, 16, 55, 56, 55, 96, 55, 136, 55, 176,
+55, 216, 56, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240,
+57, 24, 57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 58, 8, 58, 48,
+58, 88, 58, 128, 58, 168, 58, 208, 58, 248, 59, 32, 59, 72, 59, 112,
+59, 152, 59, 192, 59, 232, 60, 16, 60, 56, 60, 96, 60, 136, 60, 176,
+60, 216, 61, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240,
+62, 24, 62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 63, 8, 63, 48,
+63, 88, 63, 128, 63, 168, 63, 208, 63, 248, 64, 32, 64, 72, 64, 112,
+64, 152, 64, 192, 64, 232, 65, 16, 65, 56, 65, 96, 65, 136, 65, 176,
+65, 216, 66, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240,
+67, 24, 67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 68, 8, 68, 48,
+68, 88, 68, 128, 68, 168, 68, 208, 68, 248, 69, 32, 69, 72, 69, 112,
+69, 152, 69, 192, 69, 232, 70, 16, 70, 56, 70, 96, 70, 136, 70, 176,
+70, 216, 71, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240,
+72, 24, 72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 73, 8, 73, 48,
+73, 88, 73, 128, 73, 168, 73, 208, 73, 248, 74, 32, 74, 72, 74, 112,
+74, 152, 74, 192, 74, 232, 75, 16, 75, 56, 75, 96, 75, 136, 75, 176,
+75, 216, 76, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240,
+77, 24, 77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 78, 8, 78, 48,
+78, 88, 78, 128, 78, 168, 78, 208, 78, 248, 79, 32, 79, 72, 79, 112,
+79, 152, 79, 192, 79, 232, 80, 16, 80, 56, 80, 96, 80, 136, 80, 176,
+80, 216, 81, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240,
+82, 24, 82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 83, 8, 83, 48,
+83, 88, 83, 128, 83, 168, 83, 208, 83, 248, 84, 32, 84, 72, 84, 112,
+84, 152, 84, 192, 84, 232, 85, 16, 85, 56, 85, 96, 85, 136, 85, 176,
+85, 216, 86, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240,
+87, 24, 87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 88, 8, 88, 48,
+88, 88, 88, 128, 88, 168, 88, 208, 88, 248, 89, 32, 89, 72, 89, 112,
+89, 152, 89, 192, 89, 232, 90, 16, 90, 56, 90, 96, 90, 136, 90, 176,
+90, 216, 91, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240,
+92, 24, 92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 93, 8, 93, 48,
+93, 88, 93, 128, 93, 168, 93, 208, 93, 248, 94, 32, 94, 72, 94, 112,
+94, 152, 94, 192, 94, 232, 95, 16, 95, 56, 95, 96, 95, 136, 95, 176,
+95, 216, 96, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240,
+97, 24, 97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 98, 8, 98, 48,
+98, 88, 98, 128, 98, 168, 98, 208, 98, 248, 99, 32, 99, 72, 99, 112,
+99, 152, 99, 192, 99, 232, 100, 16, 100, 56, 100, 96, 100, 136, 100, 176,
+100, 216, 101, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240,
+102, 24, 102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 103, 8, 103, 48,
+103, 88, 103, 128, 103, 168, 103, 208, 103, 248, 104, 32, 104, 72, 104, 112,
+104, 152, 104, 192, 104, 232, 105, 16, 105, 56, 105, 96, 105, 136, 105, 176,
+105, 216, 106, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240,
+107, 24, 107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 108, 8, 108, 48,
+108, 88, 108, 128, 108, 168, 108, 208, 108, 248, 109, 32, 109, 72, 109, 112,
+109, 152, 109, 192, 109, 232, 110, 16, 110, 56, 110, 96, 110, 136, 110, 176,
+110, 216, 111, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240,
+112, 24, 112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 113, 8, 113, 48,
+113, 88, 113, 128, 113, 168, 113, 208, 113, 248, 114, 32, 114, 72, 114, 112,
+114, 152, 114, 192, 114, 232, 115, 16, 115, 56, 115, 96, 115, 136, 115, 176,
+115, 216, 116, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240,
+117, 24, 117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 118, 8, 118, 48,
+118, 88, 118, 128, 118, 168, 118, 208, 118, 248, 119, 32, 119, 72, 119, 112,
+119, 152, 119, 192, 119, 232, 120, 16, 120, 56, 120, 96, 120, 136, 120, 176,
+120, 216, 121, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240,
+122, 24, 122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 123, 8, 123, 48,
+123, 88, 123, 128, 123, 168, 123, 208, 123, 248, 124, 32, 124, 72, 124, 112,
+124, 152, 124, 192, 124, 232, 125, 16, 125, 56, 125, 96, 125, 136, 125, 176,
+125, 216, 126, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240,
+127, 24, 127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 128, 8, 128, 48,
+128, 88, 128, 128, 128, 168, 128, 208, 128, 248, 129, 32, 129, 72, 129, 112,
+129, 152, 129, 192, 129, 232, 130, 16, 130, 56, 130, 96, 130, 136, 130, 176,
+130, 216, 131, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240,
+132, 24, 132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 133, 8, 133, 48,
+133, 88, 133, 128, 133, 168, 133, 208, 133, 248, 134, 32, 134, 72, 134, 112,
+134, 152, 134, 192, 134, 232, 135, 16, 135, 56, 135, 96, 135, 136, 135, 176,
+135, 216, 136, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240,
+137, 24, 137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 138, 8, 138, 48,
+138, 88, 138, 128, 138, 168, 138, 208, 138, 248, 139, 32, 139, 72, 139, 112,
+139, 152, 139, 192, 139, 232, 140, 16, 140, 56, 140, 96, 140, 136, 140, 176,
+140, 216, 141, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240,
+142, 24, 142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 143, 8, 143, 48,
+143, 88, 143, 128, 143, 168, 143, 208, 143, 248, 144, 32, 144, 72, 144, 112,
+144, 152, 144, 192, 144, 232, 145, 16, 145, 56, 145, 96, 145, 136, 145, 176,
+145, 216, 146, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240,
+147, 24, 147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 148, 8, 148, 48,
+148, 88, 148, 128, 148, 168, 148, 208, 148, 248, 149, 32, 149, 72, 149, 112,
+149, 152, 149, 192, 149, 232, 150, 16, 150, 56, 150, 96, 150, 136, 150, 176,
+150, 216, 151, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240,
+152, 24, 152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 153, 8, 153, 48,
+153, 88, 153, 128, 153, 168, 153, 208, 153, 248, 154, 32, 154, 72, 154, 112,
+154, 152, 154, 192, 154, 232, 155, 16, 155, 56, 155, 96, 155, 136, 155, 176,
+155, 216, 156, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240,
+157, 24, 157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 158, 8, 158, 48,
+158, 88, 158, 128, 158, 168, 158, 208, 158, 248, 159, 32, 159, 72, 159, 112,
+159, 152, 159, 192, 159, 232, 160, 16, 160, 56, 160, 96, 160, 136, 160, 176,
+160, 216, 161, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240,
+162, 24, 162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 163, 8, 163, 48,
+163, 88, 163, 128, 163, 168, 163, 208, 163, 248, 164, 32, 164, 72, 164, 112,
+164, 152, 164, 192, 164, 232, 165, 16, 165, 56, 165, 96, 165, 136, 165, 176,
+165, 216, 166, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240,
+167, 24, 167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 168, 8, 168, 48,
+168, 88, 168, 128, 168, 168, 168, 208, 168, 248, 169, 32, 169, 72, 169, 112,
+169, 152, 169, 192, 169, 232, 170, 16, 170, 56, 170, 96, 170, 136, 170, 176,
+170, 216, 171, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240,
+172, 24, 172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 173, 8, 173, 48,
+173, 88, 173, 128, 173, 168, 173, 208, 173, 248, 174, 32, 174, 72, 174, 112,
+174, 152, 174, 192, 174, 232, 175, 16, 175, 56, 175, 96, 175, 136, 175, 176,
+175, 216, 176, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240,
+177, 24, 177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 178, 8, 178, 48,
+178, 88, 178, 128, 178, 168, 178, 208, 178, 248, 179, 32, 179, 72, 179, 112,
+179, 152, 179, 192, 179, 232, 180, 16, 180, 56, 180, 96, 180, 136, 180, 176,
+180, 216, 181, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240,
+182, 24, 182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 183, 8, 183, 48,
+183, 88, 183, 128, 183, 168, 183, 208, 183, 248, 184, 32, 184, 72, 184, 112,
+184, 152, 184, 192, 184, 232, 185, 16, 185, 56, 185, 96, 185, 136, 185, 176,
+185, 216, 186, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240,
+187, 24, 187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 188, 8, 188, 48,
+188, 88, 188, 128, 188, 168, 188, 208, 188, 248, 189, 32, 189, 72, 189, 112,
+189, 152, 189, 192, 189, 232, 190, 16, 190, 56, 190, 96, 190, 136, 190, 176,
+190, 216, 191, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240,
+192, 24, 192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 193, 8, 193, 48,
+193, 88, 193, 128, 193, 168, 193, 208, 193, 248, 194, 32, 194, 72, 194, 112,
+194, 152, 194, 192, 194, 232, 195, 16, 195, 56, 195, 96, 195, 136, 195, 176,
+195, 216, 196, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240,
+197, 24, 197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 198, 8, 198, 48,
+198, 88, 198, 128, 198, 168, 198, 208, 198, 248, 199, 32, 199, 72, 199, 112,
+199, 152, 199, 192, 199, 232, 200, 16, 200, 56, 200, 96, 200, 136, 200, 176,
+200, 216, 201, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240,
+202, 24, 202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 203, 8, 203, 48,
+203, 88, 203, 128, 203, 168, 203, 208, 203, 248, 204, 32, 204, 72, 204, 112,
+204, 152, 204, 192, 204, 232, 205, 16, 205, 56, 205, 96, 205, 136, 205, 176,
+205, 216, 206, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240,
+207, 24, 207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 208, 8, 208, 48,
+208, 88, 208, 128, 208, 168, 208, 208, 208, 248, 209, 32, 209, 72, 209, 112,
+209, 152, 209, 192, 209, 232, 210, 16, 210, 56, 210, 96, 210, 136, 210, 176,
+210, 216, 211, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240,
+212, 24, 212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 213, 8, 213, 48,
+213, 88, 213, 128, 213, 168, 213, 208, 213, 248, 214, 32, 214, 72, 214, 112,
+214, 152, 214, 192, 214, 232, 215, 16, 215, 56, 215, 96, 215, 136, 215, 176,
+215, 216, 224, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240,
+225, 24, 225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 226, 8, 226, 48,
+226, 88, 226, 128, 226, 168, 226, 208, 226, 248, 227, 32, 227, 72, 227, 112,
+227, 152, 227, 192, 227, 232, 228, 16, 228, 56, 228, 96, 228, 136, 228, 176,
+228, 216, 229, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240,
+230, 24, 230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 231, 8, 231, 48,
+231, 88, 231, 128, 231, 168, 231, 208, 231, 248, 232, 32, 232, 72, 232, 112,
+232, 152, 232, 192, 232, 232, 233, 16, 233, 56, 233, 96, 233, 136, 233, 176,
+233, 216, 234, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240,
+235, 24, 235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 236, 8, 236, 48,
+236, 88, 236, 128, 236, 168, 236, 208, 236, 248, 237, 32, 237, 72, 237, 112,
+237, 152, 237, 192, 237, 232, 238, 16, 238, 56, 238, 96, 238, 136, 238, 176,
+238, 216, 239, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240,
+240, 24, 240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 241, 8, 241, 48,
+241, 88, 241, 128, 241, 168, 241, 208, 241, 248, 242, 32, 242, 72, 242, 112,
+242, 152, 242, 192, 242, 232, 243, 16, 243, 56, 243, 96, 243, 136, 243, 176,
+243, 216, 244, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240,
+245, 24, 245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 246, 8, 246, 48,
+246, 88, 246, 128, 246, 168, 246, 208, 246, 248, 247, 32, 247, 72, 247, 112,
+247, 152, 247, 192, 247, 232, 248, 16, 248, 56, 248, 96, 248, 136, 248, 176,
+248, 216, 249, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240,
+250, 24, 250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 251, 8, 251, 48,
+251, 88, 251, 128, 251, 168, 251, 208, 251, 248, 252, 32, 252, 72, 252, 112,
+252, 152, 252, 192, 252, 232, 253, 16, 253, 56, 253, 96, 253, 136, 253, 176,
+253, 216, 254, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240,
+255, 24, 255, 64, 255, 104, 255, 144, 255, 184, 255, 224
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16BE.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16BE.java
new file mode 100644
index 0000000..2200718
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16BE.java
@@ -0,0 +1,378 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_MultiByte_UTF_16BE extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "UTF-16BE";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
+896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
+1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
+2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
+2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
+3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
+4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
+4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
+5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
+6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
+6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
+7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
+7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
+8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
+9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
+9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
+10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
+11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
+11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
+12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
+13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
+13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
+14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
+14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
+15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
+16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
+16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
+17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
+18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
+18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
+19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
+20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
+20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
+21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
+22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
+22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
+23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
+23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
+24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
+25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
+25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
+26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
+27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
+27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
+28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
+29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
+29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
+30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
+30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
+31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
+32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
+32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
+33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
+34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
+34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
+35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
+36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
+36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
+37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
+38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
+38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
+39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
+39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
+40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
+41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
+41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
+42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
+43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
+43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
+44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
+45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
+45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
+46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
+46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
+47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
+48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
+48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
+49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
+50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
+50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
+51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
+52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
+52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
+53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
+54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
+54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
+57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
+57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
+58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
+59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
+59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
+60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
+61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
+61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
+62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
+63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
+63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
+64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
+65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7,
+0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15,
+0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23,
+0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31,
+0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39,
+0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47,
+0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55,
+0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63,
+0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71,
+0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79,
+0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0, 87,
+0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95,
+0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103,
+0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111,
+0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119,
+0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127,
+0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0, 135,
+0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0, 143,
+0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0, 151,
+0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0, 159,
+0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0, 167,
+0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0, 175,
+0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0, 183,
+0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0, 191,
+0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0, 199,
+0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0, 207,
+0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 215,
+0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0, 223,
+0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0, 231,
+0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 239,
+0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0, 247,
+0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 255,
+1, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 2, 24,
+2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 3, 8, 3, 48, 3, 88,
+3, 128, 3, 168, 3, 208, 3, 248, 4, 32, 4, 72, 4, 112, 4, 152,
+4, 192, 4, 232, 5, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5, 216,
+6, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 7, 24,
+7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 8, 8, 8, 48, 8, 88,
+8, 128, 8, 168, 8, 208, 8, 248, 9, 32, 9, 72, 9, 112, 9, 152,
+9, 192, 9, 232, 10, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10, 216,
+11, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 12, 24,
+12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 13, 8, 13, 48, 13, 88,
+13, 128, 13, 168, 13, 208, 13, 248, 14, 32, 14, 72, 14, 112, 14, 152,
+14, 192, 14, 232, 15, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15, 216,
+16, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 17, 24,
+17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 18, 8, 18, 48, 18, 88,
+18, 128, 18, 168, 18, 208, 18, 248, 19, 32, 19, 72, 19, 112, 19, 152,
+19, 192, 19, 232, 20, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20, 216,
+21, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 22, 24,
+22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 23, 8, 23, 48, 23, 88,
+23, 128, 23, 168, 23, 208, 23, 248, 24, 32, 24, 72, 24, 112, 24, 152,
+24, 192, 24, 232, 25, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25, 216,
+26, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 27, 24,
+27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 28, 8, 28, 48, 28, 88,
+28, 128, 28, 168, 28, 208, 28, 248, 29, 32, 29, 72, 29, 112, 29, 152,
+29, 192, 29, 232, 30, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30, 216,
+31, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 32, 24,
+32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 33, 8, 33, 48, 33, 88,
+33, 128, 33, 168, 33, 208, 33, 248, 34, 32, 34, 72, 34, 112, 34, 152,
+34, 192, 34, 232, 35, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35, 216,
+36, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 37, 24,
+37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 38, 8, 38, 48, 38, 88,
+38, 128, 38, 168, 38, 208, 38, 248, 39, 32, 39, 72, 39, 112, 39, 152,
+39, 192, 39, 232, 40, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40, 216,
+41, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 42, 24,
+42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 43, 8, 43, 48, 43, 88,
+43, 128, 43, 168, 43, 208, 43, 248, 44, 32, 44, 72, 44, 112, 44, 152,
+44, 192, 44, 232, 45, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45, 216,
+46, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 47, 24,
+47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 48, 8, 48, 48, 48, 88,
+48, 128, 48, 168, 48, 208, 48, 248, 49, 32, 49, 72, 49, 112, 49, 152,
+49, 192, 49, 232, 50, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50, 216,
+51, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 52, 24,
+52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 53, 8, 53, 48, 53, 88,
+53, 128, 53, 168, 53, 208, 53, 248, 54, 32, 54, 72, 54, 112, 54, 152,
+54, 192, 54, 232, 55, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55, 216,
+56, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 57, 24,
+57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 58, 8, 58, 48, 58, 88,
+58, 128, 58, 168, 58, 208, 58, 248, 59, 32, 59, 72, 59, 112, 59, 152,
+59, 192, 59, 232, 60, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60, 216,
+61, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 62, 24,
+62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 63, 8, 63, 48, 63, 88,
+63, 128, 63, 168, 63, 208, 63, 248, 64, 32, 64, 72, 64, 112, 64, 152,
+64, 192, 64, 232, 65, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65, 216,
+66, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 67, 24,
+67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 68, 8, 68, 48, 68, 88,
+68, 128, 68, 168, 68, 208, 68, 248, 69, 32, 69, 72, 69, 112, 69, 152,
+69, 192, 69, 232, 70, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70, 216,
+71, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 72, 24,
+72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 73, 8, 73, 48, 73, 88,
+73, 128, 73, 168, 73, 208, 73, 248, 74, 32, 74, 72, 74, 112, 74, 152,
+74, 192, 74, 232, 75, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75, 216,
+76, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 77, 24,
+77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 78, 8, 78, 48, 78, 88,
+78, 128, 78, 168, 78, 208, 78, 248, 79, 32, 79, 72, 79, 112, 79, 152,
+79, 192, 79, 232, 80, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80, 216,
+81, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 82, 24,
+82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 83, 8, 83, 48, 83, 88,
+83, 128, 83, 168, 83, 208, 83, 248, 84, 32, 84, 72, 84, 112, 84, 152,
+84, 192, 84, 232, 85, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85, 216,
+86, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 87, 24,
+87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 88, 8, 88, 48, 88, 88,
+88, 128, 88, 168, 88, 208, 88, 248, 89, 32, 89, 72, 89, 112, 89, 152,
+89, 192, 89, 232, 90, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90, 216,
+91, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 92, 24,
+92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 93, 8, 93, 48, 93, 88,
+93, 128, 93, 168, 93, 208, 93, 248, 94, 32, 94, 72, 94, 112, 94, 152,
+94, 192, 94, 232, 95, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95, 216,
+96, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 97, 24,
+97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 98, 8, 98, 48, 98, 88,
+98, 128, 98, 168, 98, 208, 98, 248, 99, 32, 99, 72, 99, 112, 99, 152,
+99, 192, 99, 232, 100, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100, 216,
+101, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 102, 24,
+102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 103, 8, 103, 48, 103, 88,
+103, 128, 103, 168, 103, 208, 103, 248, 104, 32, 104, 72, 104, 112, 104, 152,
+104, 192, 104, 232, 105, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105, 216,
+106, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 107, 24,
+107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 108, 8, 108, 48, 108, 88,
+108, 128, 108, 168, 108, 208, 108, 248, 109, 32, 109, 72, 109, 112, 109, 152,
+109, 192, 109, 232, 110, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110, 216,
+111, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 112, 24,
+112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 113, 8, 113, 48, 113, 88,
+113, 128, 113, 168, 113, 208, 113, 248, 114, 32, 114, 72, 114, 112, 114, 152,
+114, 192, 114, 232, 115, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115, 216,
+116, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 117, 24,
+117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 118, 8, 118, 48, 118, 88,
+118, 128, 118, 168, 118, 208, 118, 248, 119, 32, 119, 72, 119, 112, 119, 152,
+119, 192, 119, 232, 120, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120, 216,
+121, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 122, 24,
+122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 123, 8, 123, 48, 123, 88,
+123, 128, 123, 168, 123, 208, 123, 248, 124, 32, 124, 72, 124, 112, 124, 152,
+124, 192, 124, 232, 125, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125, 216,
+126, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 127, 24,
+127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 128, 8, 128, 48, 128, 88,
+128, 128, 128, 168, 128, 208, 128, 248, 129, 32, 129, 72, 129, 112, 129, 152,
+129, 192, 129, 232, 130, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130, 216,
+131, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 132, 24,
+132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 133, 8, 133, 48, 133, 88,
+133, 128, 133, 168, 133, 208, 133, 248, 134, 32, 134, 72, 134, 112, 134, 152,
+134, 192, 134, 232, 135, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135, 216,
+136, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 137, 24,
+137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 138, 8, 138, 48, 138, 88,
+138, 128, 138, 168, 138, 208, 138, 248, 139, 32, 139, 72, 139, 112, 139, 152,
+139, 192, 139, 232, 140, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140, 216,
+141, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 142, 24,
+142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 143, 8, 143, 48, 143, 88,
+143, 128, 143, 168, 143, 208, 143, 248, 144, 32, 144, 72, 144, 112, 144, 152,
+144, 192, 144, 232, 145, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145, 216,
+146, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 147, 24,
+147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 148, 8, 148, 48, 148, 88,
+148, 128, 148, 168, 148, 208, 148, 248, 149, 32, 149, 72, 149, 112, 149, 152,
+149, 192, 149, 232, 150, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150, 216,
+151, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 152, 24,
+152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 153, 8, 153, 48, 153, 88,
+153, 128, 153, 168, 153, 208, 153, 248, 154, 32, 154, 72, 154, 112, 154, 152,
+154, 192, 154, 232, 155, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155, 216,
+156, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 157, 24,
+157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 158, 8, 158, 48, 158, 88,
+158, 128, 158, 168, 158, 208, 158, 248, 159, 32, 159, 72, 159, 112, 159, 152,
+159, 192, 159, 232, 160, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160, 216,
+161, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 162, 24,
+162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 163, 8, 163, 48, 163, 88,
+163, 128, 163, 168, 163, 208, 163, 248, 164, 32, 164, 72, 164, 112, 164, 152,
+164, 192, 164, 232, 165, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165, 216,
+166, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 167, 24,
+167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 168, 8, 168, 48, 168, 88,
+168, 128, 168, 168, 168, 208, 168, 248, 169, 32, 169, 72, 169, 112, 169, 152,
+169, 192, 169, 232, 170, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170, 216,
+171, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 172, 24,
+172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 173, 8, 173, 48, 173, 88,
+173, 128, 173, 168, 173, 208, 173, 248, 174, 32, 174, 72, 174, 112, 174, 152,
+174, 192, 174, 232, 175, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175, 216,
+176, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 177, 24,
+177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 178, 8, 178, 48, 178, 88,
+178, 128, 178, 168, 178, 208, 178, 248, 179, 32, 179, 72, 179, 112, 179, 152,
+179, 192, 179, 232, 180, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180, 216,
+181, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 182, 24,
+182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 183, 8, 183, 48, 183, 88,
+183, 128, 183, 168, 183, 208, 183, 248, 184, 32, 184, 72, 184, 112, 184, 152,
+184, 192, 184, 232, 185, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185, 216,
+186, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 187, 24,
+187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 188, 8, 188, 48, 188, 88,
+188, 128, 188, 168, 188, 208, 188, 248, 189, 32, 189, 72, 189, 112, 189, 152,
+189, 192, 189, 232, 190, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190, 216,
+191, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 192, 24,
+192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 193, 8, 193, 48, 193, 88,
+193, 128, 193, 168, 193, 208, 193, 248, 194, 32, 194, 72, 194, 112, 194, 152,
+194, 192, 194, 232, 195, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195, 216,
+196, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 197, 24,
+197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 198, 8, 198, 48, 198, 88,
+198, 128, 198, 168, 198, 208, 198, 248, 199, 32, 199, 72, 199, 112, 199, 152,
+199, 192, 199, 232, 200, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200, 216,
+201, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 202, 24,
+202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 203, 8, 203, 48, 203, 88,
+203, 128, 203, 168, 203, 208, 203, 248, 204, 32, 204, 72, 204, 112, 204, 152,
+204, 192, 204, 232, 205, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205, 216,
+206, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 207, 24,
+207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 208, 8, 208, 48, 208, 88,
+208, 128, 208, 168, 208, 208, 208, 248, 209, 32, 209, 72, 209, 112, 209, 152,
+209, 192, 209, 232, 210, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210, 216,
+211, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 212, 24,
+212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 213, 8, 213, 48, 213, 88,
+213, 128, 213, 168, 213, 208, 213, 248, 214, 32, 214, 72, 214, 112, 214, 152,
+214, 192, 214, 232, 215, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215, 216,
+224, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 225, 24,
+225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 226, 8, 226, 48, 226, 88,
+226, 128, 226, 168, 226, 208, 226, 248, 227, 32, 227, 72, 227, 112, 227, 152,
+227, 192, 227, 232, 228, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228, 216,
+229, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 230, 24,
+230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 231, 8, 231, 48, 231, 88,
+231, 128, 231, 168, 231, 208, 231, 248, 232, 32, 232, 72, 232, 112, 232, 152,
+232, 192, 232, 232, 233, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233, 216,
+234, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 235, 24,
+235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 236, 8, 236, 48, 236, 88,
+236, 128, 236, 168, 236, 208, 236, 248, 237, 32, 237, 72, 237, 112, 237, 152,
+237, 192, 237, 232, 238, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238, 216,
+239, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 240, 24,
+240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 241, 8, 241, 48, 241, 88,
+241, 128, 241, 168, 241, 208, 241, 248, 242, 32, 242, 72, 242, 112, 242, 152,
+242, 192, 242, 232, 243, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243, 216,
+244, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 245, 24,
+245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 246, 8, 246, 48, 246, 88,
+246, 128, 246, 168, 246, 208, 246, 248, 247, 32, 247, 72, 247, 112, 247, 152,
+247, 192, 247, 232, 248, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248, 216,
+249, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 250, 24,
+250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 251, 8, 251, 48, 251, 88,
+251, 128, 251, 168, 251, 208, 251, 248, 252, 32, 252, 72, 252, 112, 252, 152,
+252, 192, 252, 232, 253, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253, 216,
+254, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 255, 24,
+255, 64, 255, 104, 255, 144, 255, 184, 255, 224
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16LE.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16LE.java
new file mode 100644
index 0000000..d83d79d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16LE.java
@@ -0,0 +1,378 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_MultiByte_UTF_16LE extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "UTF-16LE";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
+896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
+1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
+2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
+2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
+3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
+4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
+4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
+5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
+6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
+6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
+7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
+7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
+8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
+9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
+9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
+10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
+11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
+11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
+12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
+13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
+13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
+14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
+14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
+15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
+16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
+16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
+17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
+18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
+18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
+19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
+20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
+20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
+21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
+22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
+22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
+23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
+23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
+24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
+25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
+25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
+26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
+27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
+27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
+28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
+29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
+29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
+30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
+30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
+31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
+32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
+32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
+33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
+34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
+34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
+35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
+36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
+36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
+37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
+38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
+38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
+39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
+39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
+40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
+41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
+41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
+42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
+43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
+43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
+44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
+45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
+45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
+46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
+46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
+47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
+48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
+48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
+49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
+50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
+50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
+51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
+52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
+52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
+53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
+54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
+54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
+57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
+57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
+58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
+59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
+59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
+60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
+61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
+61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
+62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
+63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
+63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
+64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
+65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0,
+8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0,
+16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
+24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0,
+32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0,
+40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0,
+48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0,
+56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0,
+64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71, 0,
+72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79, 0,
+80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0, 87, 0,
+88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0,
+96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0,
+104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0,
+112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119, 0,
+120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127, 0,
+128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0, 135, 0,
+136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0, 143, 0,
+144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0, 151, 0,
+152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0, 159, 0,
+160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0, 167, 0,
+168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0, 175, 0,
+176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0, 183, 0,
+184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0, 191, 0,
+192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0, 199, 0,
+200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0, 207, 0,
+208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 215, 0,
+216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0, 223, 0,
+224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0, 231, 0,
+232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 239, 0,
+240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0, 247, 0,
+248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 255, 0,
+0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 1, 24, 2,
+64, 2, 104, 2, 144, 2, 184, 2, 224, 2, 8, 3, 48, 3, 88, 3,
+128, 3, 168, 3, 208, 3, 248, 3, 32, 4, 72, 4, 112, 4, 152, 4,
+192, 4, 232, 4, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5, 216, 5,
+0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 6, 24, 7,
+64, 7, 104, 7, 144, 7, 184, 7, 224, 7, 8, 8, 48, 8, 88, 8,
+128, 8, 168, 8, 208, 8, 248, 8, 32, 9, 72, 9, 112, 9, 152, 9,
+192, 9, 232, 9, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10, 216, 10,
+0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 11, 24, 12,
+64, 12, 104, 12, 144, 12, 184, 12, 224, 12, 8, 13, 48, 13, 88, 13,
+128, 13, 168, 13, 208, 13, 248, 13, 32, 14, 72, 14, 112, 14, 152, 14,
+192, 14, 232, 14, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15, 216, 15,
+0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 16, 24, 17,
+64, 17, 104, 17, 144, 17, 184, 17, 224, 17, 8, 18, 48, 18, 88, 18,
+128, 18, 168, 18, 208, 18, 248, 18, 32, 19, 72, 19, 112, 19, 152, 19,
+192, 19, 232, 19, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20, 216, 20,
+0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 21, 24, 22,
+64, 22, 104, 22, 144, 22, 184, 22, 224, 22, 8, 23, 48, 23, 88, 23,
+128, 23, 168, 23, 208, 23, 248, 23, 32, 24, 72, 24, 112, 24, 152, 24,
+192, 24, 232, 24, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25, 216, 25,
+0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 26, 24, 27,
+64, 27, 104, 27, 144, 27, 184, 27, 224, 27, 8, 28, 48, 28, 88, 28,
+128, 28, 168, 28, 208, 28, 248, 28, 32, 29, 72, 29, 112, 29, 152, 29,
+192, 29, 232, 29, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30, 216, 30,
+0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 31, 24, 32,
+64, 32, 104, 32, 144, 32, 184, 32, 224, 32, 8, 33, 48, 33, 88, 33,
+128, 33, 168, 33, 208, 33, 248, 33, 32, 34, 72, 34, 112, 34, 152, 34,
+192, 34, 232, 34, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35, 216, 35,
+0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 36, 24, 37,
+64, 37, 104, 37, 144, 37, 184, 37, 224, 37, 8, 38, 48, 38, 88, 38,
+128, 38, 168, 38, 208, 38, 248, 38, 32, 39, 72, 39, 112, 39, 152, 39,
+192, 39, 232, 39, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40, 216, 40,
+0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 41, 24, 42,
+64, 42, 104, 42, 144, 42, 184, 42, 224, 42, 8, 43, 48, 43, 88, 43,
+128, 43, 168, 43, 208, 43, 248, 43, 32, 44, 72, 44, 112, 44, 152, 44,
+192, 44, 232, 44, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45, 216, 45,
+0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 46, 24, 47,
+64, 47, 104, 47, 144, 47, 184, 47, 224, 47, 8, 48, 48, 48, 88, 48,
+128, 48, 168, 48, 208, 48, 248, 48, 32, 49, 72, 49, 112, 49, 152, 49,
+192, 49, 232, 49, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50, 216, 50,
+0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 51, 24, 52,
+64, 52, 104, 52, 144, 52, 184, 52, 224, 52, 8, 53, 48, 53, 88, 53,
+128, 53, 168, 53, 208, 53, 248, 53, 32, 54, 72, 54, 112, 54, 152, 54,
+192, 54, 232, 54, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55, 216, 55,
+0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 56, 24, 57,
+64, 57, 104, 57, 144, 57, 184, 57, 224, 57, 8, 58, 48, 58, 88, 58,
+128, 58, 168, 58, 208, 58, 248, 58, 32, 59, 72, 59, 112, 59, 152, 59,
+192, 59, 232, 59, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60, 216, 60,
+0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 61, 24, 62,
+64, 62, 104, 62, 144, 62, 184, 62, 224, 62, 8, 63, 48, 63, 88, 63,
+128, 63, 168, 63, 208, 63, 248, 63, 32, 64, 72, 64, 112, 64, 152, 64,
+192, 64, 232, 64, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65, 216, 65,
+0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 66, 24, 67,
+64, 67, 104, 67, 144, 67, 184, 67, 224, 67, 8, 68, 48, 68, 88, 68,
+128, 68, 168, 68, 208, 68, 248, 68, 32, 69, 72, 69, 112, 69, 152, 69,
+192, 69, 232, 69, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70, 216, 70,
+0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 71, 24, 72,
+64, 72, 104, 72, 144, 72, 184, 72, 224, 72, 8, 73, 48, 73, 88, 73,
+128, 73, 168, 73, 208, 73, 248, 73, 32, 74, 72, 74, 112, 74, 152, 74,
+192, 74, 232, 74, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75, 216, 75,
+0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 76, 24, 77,
+64, 77, 104, 77, 144, 77, 184, 77, 224, 77, 8, 78, 48, 78, 88, 78,
+128, 78, 168, 78, 208, 78, 248, 78, 32, 79, 72, 79, 112, 79, 152, 79,
+192, 79, 232, 79, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80, 216, 80,
+0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 81, 24, 82,
+64, 82, 104, 82, 144, 82, 184, 82, 224, 82, 8, 83, 48, 83, 88, 83,
+128, 83, 168, 83, 208, 83, 248, 83, 32, 84, 72, 84, 112, 84, 152, 84,
+192, 84, 232, 84, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85, 216, 85,
+0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 86, 24, 87,
+64, 87, 104, 87, 144, 87, 184, 87, 224, 87, 8, 88, 48, 88, 88, 88,
+128, 88, 168, 88, 208, 88, 248, 88, 32, 89, 72, 89, 112, 89, 152, 89,
+192, 89, 232, 89, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90, 216, 90,
+0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 91, 24, 92,
+64, 92, 104, 92, 144, 92, 184, 92, 224, 92, 8, 93, 48, 93, 88, 93,
+128, 93, 168, 93, 208, 93, 248, 93, 32, 94, 72, 94, 112, 94, 152, 94,
+192, 94, 232, 94, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95, 216, 95,
+0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 96, 24, 97,
+64, 97, 104, 97, 144, 97, 184, 97, 224, 97, 8, 98, 48, 98, 88, 98,
+128, 98, 168, 98, 208, 98, 248, 98, 32, 99, 72, 99, 112, 99, 152, 99,
+192, 99, 232, 99, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100, 216, 100,
+0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 101, 24, 102,
+64, 102, 104, 102, 144, 102, 184, 102, 224, 102, 8, 103, 48, 103, 88, 103,
+128, 103, 168, 103, 208, 103, 248, 103, 32, 104, 72, 104, 112, 104, 152, 104,
+192, 104, 232, 104, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105, 216, 105,
+0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 106, 24, 107,
+64, 107, 104, 107, 144, 107, 184, 107, 224, 107, 8, 108, 48, 108, 88, 108,
+128, 108, 168, 108, 208, 108, 248, 108, 32, 109, 72, 109, 112, 109, 152, 109,
+192, 109, 232, 109, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110, 216, 110,
+0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 111, 24, 112,
+64, 112, 104, 112, 144, 112, 184, 112, 224, 112, 8, 113, 48, 113, 88, 113,
+128, 113, 168, 113, 208, 113, 248, 113, 32, 114, 72, 114, 112, 114, 152, 114,
+192, 114, 232, 114, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115, 216, 115,
+0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 116, 24, 117,
+64, 117, 104, 117, 144, 117, 184, 117, 224, 117, 8, 118, 48, 118, 88, 118,
+128, 118, 168, 118, 208, 118, 248, 118, 32, 119, 72, 119, 112, 119, 152, 119,
+192, 119, 232, 119, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120, 216, 120,
+0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 121, 24, 122,
+64, 122, 104, 122, 144, 122, 184, 122, 224, 122, 8, 123, 48, 123, 88, 123,
+128, 123, 168, 123, 208, 123, 248, 123, 32, 124, 72, 124, 112, 124, 152, 124,
+192, 124, 232, 124, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125, 216, 125,
+0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 126, 24, 127,
+64, 127, 104, 127, 144, 127, 184, 127, 224, 127, 8, 128, 48, 128, 88, 128,
+128, 128, 168, 128, 208, 128, 248, 128, 32, 129, 72, 129, 112, 129, 152, 129,
+192, 129, 232, 129, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130, 216, 130,
+0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 131, 24, 132,
+64, 132, 104, 132, 144, 132, 184, 132, 224, 132, 8, 133, 48, 133, 88, 133,
+128, 133, 168, 133, 208, 133, 248, 133, 32, 134, 72, 134, 112, 134, 152, 134,
+192, 134, 232, 134, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135, 216, 135,
+0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 136, 24, 137,
+64, 137, 104, 137, 144, 137, 184, 137, 224, 137, 8, 138, 48, 138, 88, 138,
+128, 138, 168, 138, 208, 138, 248, 138, 32, 139, 72, 139, 112, 139, 152, 139,
+192, 139, 232, 139, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140, 216, 140,
+0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 141, 24, 142,
+64, 142, 104, 142, 144, 142, 184, 142, 224, 142, 8, 143, 48, 143, 88, 143,
+128, 143, 168, 143, 208, 143, 248, 143, 32, 144, 72, 144, 112, 144, 152, 144,
+192, 144, 232, 144, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145, 216, 145,
+0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 146, 24, 147,
+64, 147, 104, 147, 144, 147, 184, 147, 224, 147, 8, 148, 48, 148, 88, 148,
+128, 148, 168, 148, 208, 148, 248, 148, 32, 149, 72, 149, 112, 149, 152, 149,
+192, 149, 232, 149, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150, 216, 150,
+0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 151, 24, 152,
+64, 152, 104, 152, 144, 152, 184, 152, 224, 152, 8, 153, 48, 153, 88, 153,
+128, 153, 168, 153, 208, 153, 248, 153, 32, 154, 72, 154, 112, 154, 152, 154,
+192, 154, 232, 154, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155, 216, 155,
+0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 156, 24, 157,
+64, 157, 104, 157, 144, 157, 184, 157, 224, 157, 8, 158, 48, 158, 88, 158,
+128, 158, 168, 158, 208, 158, 248, 158, 32, 159, 72, 159, 112, 159, 152, 159,
+192, 159, 232, 159, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160, 216, 160,
+0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 161, 24, 162,
+64, 162, 104, 162, 144, 162, 184, 162, 224, 162, 8, 163, 48, 163, 88, 163,
+128, 163, 168, 163, 208, 163, 248, 163, 32, 164, 72, 164, 112, 164, 152, 164,
+192, 164, 232, 164, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165, 216, 165,
+0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 166, 24, 167,
+64, 167, 104, 167, 144, 167, 184, 167, 224, 167, 8, 168, 48, 168, 88, 168,
+128, 168, 168, 168, 208, 168, 248, 168, 32, 169, 72, 169, 112, 169, 152, 169,
+192, 169, 232, 169, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170, 216, 170,
+0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 171, 24, 172,
+64, 172, 104, 172, 144, 172, 184, 172, 224, 172, 8, 173, 48, 173, 88, 173,
+128, 173, 168, 173, 208, 173, 248, 173, 32, 174, 72, 174, 112, 174, 152, 174,
+192, 174, 232, 174, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175, 216, 175,
+0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 176, 24, 177,
+64, 177, 104, 177, 144, 177, 184, 177, 224, 177, 8, 178, 48, 178, 88, 178,
+128, 178, 168, 178, 208, 178, 248, 178, 32, 179, 72, 179, 112, 179, 152, 179,
+192, 179, 232, 179, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180, 216, 180,
+0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 181, 24, 182,
+64, 182, 104, 182, 144, 182, 184, 182, 224, 182, 8, 183, 48, 183, 88, 183,
+128, 183, 168, 183, 208, 183, 248, 183, 32, 184, 72, 184, 112, 184, 152, 184,
+192, 184, 232, 184, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185, 216, 185,
+0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 186, 24, 187,
+64, 187, 104, 187, 144, 187, 184, 187, 224, 187, 8, 188, 48, 188, 88, 188,
+128, 188, 168, 188, 208, 188, 248, 188, 32, 189, 72, 189, 112, 189, 152, 189,
+192, 189, 232, 189, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190, 216, 190,
+0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 191, 24, 192,
+64, 192, 104, 192, 144, 192, 184, 192, 224, 192, 8, 193, 48, 193, 88, 193,
+128, 193, 168, 193, 208, 193, 248, 193, 32, 194, 72, 194, 112, 194, 152, 194,
+192, 194, 232, 194, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195, 216, 195,
+0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 196, 24, 197,
+64, 197, 104, 197, 144, 197, 184, 197, 224, 197, 8, 198, 48, 198, 88, 198,
+128, 198, 168, 198, 208, 198, 248, 198, 32, 199, 72, 199, 112, 199, 152, 199,
+192, 199, 232, 199, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200, 216, 200,
+0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 201, 24, 202,
+64, 202, 104, 202, 144, 202, 184, 202, 224, 202, 8, 203, 48, 203, 88, 203,
+128, 203, 168, 203, 208, 203, 248, 203, 32, 204, 72, 204, 112, 204, 152, 204,
+192, 204, 232, 204, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205, 216, 205,
+0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 206, 24, 207,
+64, 207, 104, 207, 144, 207, 184, 207, 224, 207, 8, 208, 48, 208, 88, 208,
+128, 208, 168, 208, 208, 208, 248, 208, 32, 209, 72, 209, 112, 209, 152, 209,
+192, 209, 232, 209, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210, 216, 210,
+0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 211, 24, 212,
+64, 212, 104, 212, 144, 212, 184, 212, 224, 212, 8, 213, 48, 213, 88, 213,
+128, 213, 168, 213, 208, 213, 248, 213, 32, 214, 72, 214, 112, 214, 152, 214,
+192, 214, 232, 214, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215, 216, 215,
+0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 224, 24, 225,
+64, 225, 104, 225, 144, 225, 184, 225, 224, 225, 8, 226, 48, 226, 88, 226,
+128, 226, 168, 226, 208, 226, 248, 226, 32, 227, 72, 227, 112, 227, 152, 227,
+192, 227, 232, 227, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228, 216, 228,
+0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 229, 24, 230,
+64, 230, 104, 230, 144, 230, 184, 230, 224, 230, 8, 231, 48, 231, 88, 231,
+128, 231, 168, 231, 208, 231, 248, 231, 32, 232, 72, 232, 112, 232, 152, 232,
+192, 232, 232, 232, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233, 216, 233,
+0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 234, 24, 235,
+64, 235, 104, 235, 144, 235, 184, 235, 224, 235, 8, 236, 48, 236, 88, 236,
+128, 236, 168, 236, 208, 236, 248, 236, 32, 237, 72, 237, 112, 237, 152, 237,
+192, 237, 232, 237, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238, 216, 238,
+0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 239, 24, 240,
+64, 240, 104, 240, 144, 240, 184, 240, 224, 240, 8, 241, 48, 241, 88, 241,
+128, 241, 168, 241, 208, 241, 248, 241, 32, 242, 72, 242, 112, 242, 152, 242,
+192, 242, 232, 242, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243, 216, 243,
+0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 244, 24, 245,
+64, 245, 104, 245, 144, 245, 184, 245, 224, 245, 8, 246, 48, 246, 88, 246,
+128, 246, 168, 246, 208, 246, 248, 246, 32, 247, 72, 247, 112, 247, 152, 247,
+192, 247, 232, 247, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248, 216, 248,
+0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 249, 24, 250,
+64, 250, 104, 250, 144, 250, 184, 250, 224, 250, 8, 251, 48, 251, 88, 251,
+128, 251, 168, 251, 208, 251, 248, 251, 32, 252, 72, 252, 112, 252, 152, 252,
+192, 252, 232, 252, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253, 216, 253,
+0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 254, 24, 255,
+64, 255, 104, 255, 144, 255, 184, 255, 224, 255
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16_Android.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16_Android.java
new file mode 100644
index 0000000..b9c7c03
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_16_Android.java
@@ -0,0 +1,374 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_MultiByte_UTF_16_Android extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "UTF-16";
+
+ testChars = theseChars(new int[]{
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
+896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
+1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
+2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
+2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
+3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
+4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
+4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
+5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
+6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
+6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
+7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
+7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
+8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
+9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
+9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
+10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
+11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
+11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
+12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
+13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
+13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
+14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
+14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
+15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
+16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
+16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
+17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
+18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
+18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
+19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
+20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
+20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
+21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
+22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
+22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
+23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
+23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
+24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
+25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
+25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
+26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
+27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
+27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
+28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
+29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
+29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
+30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
+30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
+31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
+32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
+32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
+33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
+34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
+34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
+35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
+36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
+36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
+37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
+38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
+38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
+39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
+39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
+40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
+41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
+41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
+42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
+43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
+43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
+44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
+45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
+45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
+46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
+46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
+47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
+48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
+48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
+49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
+50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
+50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
+51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
+52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
+52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
+53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
+54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
+54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
+57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
+57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
+58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
+59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
+59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
+60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
+61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
+61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
+62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
+63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
+63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
+64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
+65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+255, 254, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0,
+39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0,
+47, 0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0,
+55, 0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0,
+63, 0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0,
+71, 0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0,
+79, 0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0,
+87, 0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0,
+95, 0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0,
+103, 0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0,
+111, 0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0,
+119, 0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0,
+127, 0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0,
+135, 0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0,
+143, 0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0,
+151, 0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0,
+159, 0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0,
+167, 0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0,
+175, 0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0,
+183, 0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0,
+191, 0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0,
+199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0,
+207, 0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0,
+215, 0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0,
+223, 0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0,
+231, 0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0,
+239, 0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0,
+247, 0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0,
+255, 0, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 1,
+24, 2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 2, 8, 3, 48, 3,
+88, 3, 128, 3, 168, 3, 208, 3, 248, 3, 32, 4, 72, 4, 112, 4,
+152, 4, 192, 4, 232, 4, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5,
+216, 5, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 6,
+24, 7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 7, 8, 8, 48, 8,
+88, 8, 128, 8, 168, 8, 208, 8, 248, 8, 32, 9, 72, 9, 112, 9,
+152, 9, 192, 9, 232, 9, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10,
+216, 10, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 11,
+24, 12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 12, 8, 13, 48, 13,
+88, 13, 128, 13, 168, 13, 208, 13, 248, 13, 32, 14, 72, 14, 112, 14,
+152, 14, 192, 14, 232, 14, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15,
+216, 15, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 16,
+24, 17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 17, 8, 18, 48, 18,
+88, 18, 128, 18, 168, 18, 208, 18, 248, 18, 32, 19, 72, 19, 112, 19,
+152, 19, 192, 19, 232, 19, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20,
+216, 20, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 21,
+24, 22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 22, 8, 23, 48, 23,
+88, 23, 128, 23, 168, 23, 208, 23, 248, 23, 32, 24, 72, 24, 112, 24,
+152, 24, 192, 24, 232, 24, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25,
+216, 25, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 26,
+24, 27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 27, 8, 28, 48, 28,
+88, 28, 128, 28, 168, 28, 208, 28, 248, 28, 32, 29, 72, 29, 112, 29,
+152, 29, 192, 29, 232, 29, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30,
+216, 30, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 31,
+24, 32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 32, 8, 33, 48, 33,
+88, 33, 128, 33, 168, 33, 208, 33, 248, 33, 32, 34, 72, 34, 112, 34,
+152, 34, 192, 34, 232, 34, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35,
+216, 35, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 36,
+24, 37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 37, 8, 38, 48, 38,
+88, 38, 128, 38, 168, 38, 208, 38, 248, 38, 32, 39, 72, 39, 112, 39,
+152, 39, 192, 39, 232, 39, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40,
+216, 40, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 41,
+24, 42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 42, 8, 43, 48, 43,
+88, 43, 128, 43, 168, 43, 208, 43, 248, 43, 32, 44, 72, 44, 112, 44,
+152, 44, 192, 44, 232, 44, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45,
+216, 45, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 46,
+24, 47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 47, 8, 48, 48, 48,
+88, 48, 128, 48, 168, 48, 208, 48, 248, 48, 32, 49, 72, 49, 112, 49,
+152, 49, 192, 49, 232, 49, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50,
+216, 50, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 51,
+24, 52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 52, 8, 53, 48, 53,
+88, 53, 128, 53, 168, 53, 208, 53, 248, 53, 32, 54, 72, 54, 112, 54,
+152, 54, 192, 54, 232, 54, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55,
+216, 55, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 56,
+24, 57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 57, 8, 58, 48, 58,
+88, 58, 128, 58, 168, 58, 208, 58, 248, 58, 32, 59, 72, 59, 112, 59,
+152, 59, 192, 59, 232, 59, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60,
+216, 60, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 61,
+24, 62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 62, 8, 63, 48, 63,
+88, 63, 128, 63, 168, 63, 208, 63, 248, 63, 32, 64, 72, 64, 112, 64,
+152, 64, 192, 64, 232, 64, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65,
+216, 65, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 66,
+24, 67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 67, 8, 68, 48, 68,
+88, 68, 128, 68, 168, 68, 208, 68, 248, 68, 32, 69, 72, 69, 112, 69,
+152, 69, 192, 69, 232, 69, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70,
+216, 70, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 71,
+24, 72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 72, 8, 73, 48, 73,
+88, 73, 128, 73, 168, 73, 208, 73, 248, 73, 32, 74, 72, 74, 112, 74,
+152, 74, 192, 74, 232, 74, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75,
+216, 75, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 76,
+24, 77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 77, 8, 78, 48, 78,
+88, 78, 128, 78, 168, 78, 208, 78, 248, 78, 32, 79, 72, 79, 112, 79,
+152, 79, 192, 79, 232, 79, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80,
+216, 80, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 81,
+24, 82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 82, 8, 83, 48, 83,
+88, 83, 128, 83, 168, 83, 208, 83, 248, 83, 32, 84, 72, 84, 112, 84,
+152, 84, 192, 84, 232, 84, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85,
+216, 85, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 86,
+24, 87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 87, 8, 88, 48, 88,
+88, 88, 128, 88, 168, 88, 208, 88, 248, 88, 32, 89, 72, 89, 112, 89,
+152, 89, 192, 89, 232, 89, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90,
+216, 90, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 91,
+24, 92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 92, 8, 93, 48, 93,
+88, 93, 128, 93, 168, 93, 208, 93, 248, 93, 32, 94, 72, 94, 112, 94,
+152, 94, 192, 94, 232, 94, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95,
+216, 95, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 96,
+24, 97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 97, 8, 98, 48, 98,
+88, 98, 128, 98, 168, 98, 208, 98, 248, 98, 32, 99, 72, 99, 112, 99,
+152, 99, 192, 99, 232, 99, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100,
+216, 100, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 101,
+24, 102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 102, 8, 103, 48, 103,
+88, 103, 128, 103, 168, 103, 208, 103, 248, 103, 32, 104, 72, 104, 112, 104,
+152, 104, 192, 104, 232, 104, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105,
+216, 105, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 106,
+24, 107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 107, 8, 108, 48, 108,
+88, 108, 128, 108, 168, 108, 208, 108, 248, 108, 32, 109, 72, 109, 112, 109,
+152, 109, 192, 109, 232, 109, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110,
+216, 110, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 111,
+24, 112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 112, 8, 113, 48, 113,
+88, 113, 128, 113, 168, 113, 208, 113, 248, 113, 32, 114, 72, 114, 112, 114,
+152, 114, 192, 114, 232, 114, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115,
+216, 115, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 116,
+24, 117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 117, 8, 118, 48, 118,
+88, 118, 128, 118, 168, 118, 208, 118, 248, 118, 32, 119, 72, 119, 112, 119,
+152, 119, 192, 119, 232, 119, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120,
+216, 120, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 121,
+24, 122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 122, 8, 123, 48, 123,
+88, 123, 128, 123, 168, 123, 208, 123, 248, 123, 32, 124, 72, 124, 112, 124,
+152, 124, 192, 124, 232, 124, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125,
+216, 125, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 126,
+24, 127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 127, 8, 128, 48, 128,
+88, 128, 128, 128, 168, 128, 208, 128, 248, 128, 32, 129, 72, 129, 112, 129,
+152, 129, 192, 129, 232, 129, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130,
+216, 130, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 131,
+24, 132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 132, 8, 133, 48, 133,
+88, 133, 128, 133, 168, 133, 208, 133, 248, 133, 32, 134, 72, 134, 112, 134,
+152, 134, 192, 134, 232, 134, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135,
+216, 135, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 136,
+24, 137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 137, 8, 138, 48, 138,
+88, 138, 128, 138, 168, 138, 208, 138, 248, 138, 32, 139, 72, 139, 112, 139,
+152, 139, 192, 139, 232, 139, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140,
+216, 140, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 141,
+24, 142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 142, 8, 143, 48, 143,
+88, 143, 128, 143, 168, 143, 208, 143, 248, 143, 32, 144, 72, 144, 112, 144,
+152, 144, 192, 144, 232, 144, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145,
+216, 145, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 146,
+24, 147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 147, 8, 148, 48, 148,
+88, 148, 128, 148, 168, 148, 208, 148, 248, 148, 32, 149, 72, 149, 112, 149,
+152, 149, 192, 149, 232, 149, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150,
+216, 150, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 151,
+24, 152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 152, 8, 153, 48, 153,
+88, 153, 128, 153, 168, 153, 208, 153, 248, 153, 32, 154, 72, 154, 112, 154,
+152, 154, 192, 154, 232, 154, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155,
+216, 155, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 156,
+24, 157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 157, 8, 158, 48, 158,
+88, 158, 128, 158, 168, 158, 208, 158, 248, 158, 32, 159, 72, 159, 112, 159,
+152, 159, 192, 159, 232, 159, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160,
+216, 160, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 161,
+24, 162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 162, 8, 163, 48, 163,
+88, 163, 128, 163, 168, 163, 208, 163, 248, 163, 32, 164, 72, 164, 112, 164,
+152, 164, 192, 164, 232, 164, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165,
+216, 165, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 166,
+24, 167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 167, 8, 168, 48, 168,
+88, 168, 128, 168, 168, 168, 208, 168, 248, 168, 32, 169, 72, 169, 112, 169,
+152, 169, 192, 169, 232, 169, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170,
+216, 170, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 171,
+24, 172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 172, 8, 173, 48, 173,
+88, 173, 128, 173, 168, 173, 208, 173, 248, 173, 32, 174, 72, 174, 112, 174,
+152, 174, 192, 174, 232, 174, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175,
+216, 175, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 176,
+24, 177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 177, 8, 178, 48, 178,
+88, 178, 128, 178, 168, 178, 208, 178, 248, 178, 32, 179, 72, 179, 112, 179,
+152, 179, 192, 179, 232, 179, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180,
+216, 180, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 181,
+24, 182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 182, 8, 183, 48, 183,
+88, 183, 128, 183, 168, 183, 208, 183, 248, 183, 32, 184, 72, 184, 112, 184,
+152, 184, 192, 184, 232, 184, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185,
+216, 185, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 186,
+24, 187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 187, 8, 188, 48, 188,
+88, 188, 128, 188, 168, 188, 208, 188, 248, 188, 32, 189, 72, 189, 112, 189,
+152, 189, 192, 189, 232, 189, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190,
+216, 190, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 191,
+24, 192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 192, 8, 193, 48, 193,
+88, 193, 128, 193, 168, 193, 208, 193, 248, 193, 32, 194, 72, 194, 112, 194,
+152, 194, 192, 194, 232, 194, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195,
+216, 195, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 196,
+24, 197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 197, 8, 198, 48, 198,
+88, 198, 128, 198, 168, 198, 208, 198, 248, 198, 32, 199, 72, 199, 112, 199,
+152, 199, 192, 199, 232, 199, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200,
+216, 200, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 201,
+24, 202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 202, 8, 203, 48, 203,
+88, 203, 128, 203, 168, 203, 208, 203, 248, 203, 32, 204, 72, 204, 112, 204,
+152, 204, 192, 204, 232, 204, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205,
+216, 205, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 206,
+24, 207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 207, 8, 208, 48, 208,
+88, 208, 128, 208, 168, 208, 208, 208, 248, 208, 32, 209, 72, 209, 112, 209,
+152, 209, 192, 209, 232, 209, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210,
+216, 210, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 211,
+24, 212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 212, 8, 213, 48, 213,
+88, 213, 128, 213, 168, 213, 208, 213, 248, 213, 32, 214, 72, 214, 112, 214,
+152, 214, 192, 214, 232, 214, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215,
+216, 215, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 224,
+24, 225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 225, 8, 226, 48, 226,
+88, 226, 128, 226, 168, 226, 208, 226, 248, 226, 32, 227, 72, 227, 112, 227,
+152, 227, 192, 227, 232, 227, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228,
+216, 228, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 229,
+24, 230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 230, 8, 231, 48, 231,
+88, 231, 128, 231, 168, 231, 208, 231, 248, 231, 32, 232, 72, 232, 112, 232,
+152, 232, 192, 232, 232, 232, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233,
+216, 233, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 234,
+24, 235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 235, 8, 236, 48, 236,
+88, 236, 128, 236, 168, 236, 208, 236, 248, 236, 32, 237, 72, 237, 112, 237,
+152, 237, 192, 237, 232, 237, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238,
+216, 238, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 239,
+24, 240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 240, 8, 241, 48, 241,
+88, 241, 128, 241, 168, 241, 208, 241, 248, 241, 32, 242, 72, 242, 112, 242,
+152, 242, 192, 242, 232, 242, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243,
+216, 243, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 244,
+24, 245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 245, 8, 246, 48, 246,
+88, 246, 128, 246, 168, 246, 208, 246, 248, 246, 32, 247, 72, 247, 112, 247,
+152, 247, 192, 247, 232, 247, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248,
+216, 248, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 249,
+24, 250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 250, 8, 251, 48, 251,
+88, 251, 128, 251, 168, 251, 208, 251, 248, 251, 32, 252, 72, 252, 112, 252,
+152, 252, 192, 252, 232, 252, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253,
+216, 253, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 254,
+24, 255, 64, 255, 104, 255, 144, 255, 184, 255, 224, 255
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_8.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_8.java
new file mode 100644
index 0000000..d899057
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_UTF_8.java
@@ -0,0 +1,466 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_MultiByte_UTF_8 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "UTF-8";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
+256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
+896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
+1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
+2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
+2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
+3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
+4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
+4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
+5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
+6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
+6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
+7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
+7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
+8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
+9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
+9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
+10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
+11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
+11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
+12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
+13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
+13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
+14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
+14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
+15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
+16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
+16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
+17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
+18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
+18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
+19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
+20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
+20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
+21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
+22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
+22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
+23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
+23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
+24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
+25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
+25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
+26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
+27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
+27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
+28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
+29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
+29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
+30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
+30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
+31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
+32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
+32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
+33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
+34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
+34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
+35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
+36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
+36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
+37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
+38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
+38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
+39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
+39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
+40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
+41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
+41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
+42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
+43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
+43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
+44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
+45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
+45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
+46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
+46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
+47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
+48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
+48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
+49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
+50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
+50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
+51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
+52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
+52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
+53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
+54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
+54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
+57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
+57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
+58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
+59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
+59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
+60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
+61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
+61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
+62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
+63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
+63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
+64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
+65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+194, 128, 194, 129, 194, 130, 194, 131, 194, 132, 194, 133, 194, 134, 194, 135,
+194, 136, 194, 137, 194, 138, 194, 139, 194, 140, 194, 141, 194, 142, 194, 143,
+194, 144, 194, 145, 194, 146, 194, 147, 194, 148, 194, 149, 194, 150, 194, 151,
+194, 152, 194, 153, 194, 154, 194, 155, 194, 156, 194, 157, 194, 158, 194, 159,
+194, 160, 194, 161, 194, 162, 194, 163, 194, 164, 194, 165, 194, 166, 194, 167,
+194, 168, 194, 169, 194, 170, 194, 171, 194, 172, 194, 173, 194, 174, 194, 175,
+194, 176, 194, 177, 194, 178, 194, 179, 194, 180, 194, 181, 194, 182, 194, 183,
+194, 184, 194, 185, 194, 186, 194, 187, 194, 188, 194, 189, 194, 190, 194, 191,
+195, 128, 195, 129, 195, 130, 195, 131, 195, 132, 195, 133, 195, 134, 195, 135,
+195, 136, 195, 137, 195, 138, 195, 139, 195, 140, 195, 141, 195, 142, 195, 143,
+195, 144, 195, 145, 195, 146, 195, 147, 195, 148, 195, 149, 195, 150, 195, 151,
+195, 152, 195, 153, 195, 154, 195, 155, 195, 156, 195, 157, 195, 158, 195, 159,
+195, 160, 195, 161, 195, 162, 195, 163, 195, 164, 195, 165, 195, 166, 195, 167,
+195, 168, 195, 169, 195, 170, 195, 171, 195, 172, 195, 173, 195, 174, 195, 175,
+195, 176, 195, 177, 195, 178, 195, 179, 195, 180, 195, 181, 195, 182, 195, 183,
+195, 184, 195, 185, 195, 186, 195, 187, 195, 188, 195, 189, 195, 190, 195, 191,
+196, 128, 196, 168, 197, 144, 197, 184, 198, 160, 199, 136, 199, 176, 200, 152,
+201, 128, 201, 168, 202, 144, 202, 184, 203, 160, 204, 136, 204, 176, 205, 152,
+206, 128, 206, 168, 207, 144, 207, 184, 208, 160, 209, 136, 209, 176, 210, 152,
+211, 128, 211, 168, 212, 144, 212, 184, 213, 160, 214, 136, 214, 176, 215, 152,
+216, 128, 216, 168, 217, 144, 217, 184, 218, 160, 219, 136, 219, 176, 220, 152,
+221, 128, 221, 168, 222, 144, 222, 184, 223, 160, 224, 160, 136, 224, 160, 176,
+224, 161, 152, 224, 162, 128, 224, 162, 168, 224, 163, 144, 224, 163, 184, 224,
+164, 160, 224, 165, 136, 224, 165, 176, 224, 166, 152, 224, 167, 128, 224, 167,
+168, 224, 168, 144, 224, 168, 184, 224, 169, 160, 224, 170, 136, 224, 170, 176,
+224, 171, 152, 224, 172, 128, 224, 172, 168, 224, 173, 144, 224, 173, 184, 224,
+174, 160, 224, 175, 136, 224, 175, 176, 224, 176, 152, 224, 177, 128, 224, 177,
+168, 224, 178, 144, 224, 178, 184, 224, 179, 160, 224, 180, 136, 224, 180, 176,
+224, 181, 152, 224, 182, 128, 224, 182, 168, 224, 183, 144, 224, 183, 184, 224,
+184, 160, 224, 185, 136, 224, 185, 176, 224, 186, 152, 224, 187, 128, 224, 187,
+168, 224, 188, 144, 224, 188, 184, 224, 189, 160, 224, 190, 136, 224, 190, 176,
+224, 191, 152, 225, 128, 128, 225, 128, 168, 225, 129, 144, 225, 129, 184, 225,
+130, 160, 225, 131, 136, 225, 131, 176, 225, 132, 152, 225, 133, 128, 225, 133,
+168, 225, 134, 144, 225, 134, 184, 225, 135, 160, 225, 136, 136, 225, 136, 176,
+225, 137, 152, 225, 138, 128, 225, 138, 168, 225, 139, 144, 225, 139, 184, 225,
+140, 160, 225, 141, 136, 225, 141, 176, 225, 142, 152, 225, 143, 128, 225, 143,
+168, 225, 144, 144, 225, 144, 184, 225, 145, 160, 225, 146, 136, 225, 146, 176,
+225, 147, 152, 225, 148, 128, 225, 148, 168, 225, 149, 144, 225, 149, 184, 225,
+150, 160, 225, 151, 136, 225, 151, 176, 225, 152, 152, 225, 153, 128, 225, 153,
+168, 225, 154, 144, 225, 154, 184, 225, 155, 160, 225, 156, 136, 225, 156, 176,
+225, 157, 152, 225, 158, 128, 225, 158, 168, 225, 159, 144, 225, 159, 184, 225,
+160, 160, 225, 161, 136, 225, 161, 176, 225, 162, 152, 225, 163, 128, 225, 163,
+168, 225, 164, 144, 225, 164, 184, 225, 165, 160, 225, 166, 136, 225, 166, 176,
+225, 167, 152, 225, 168, 128, 225, 168, 168, 225, 169, 144, 225, 169, 184, 225,
+170, 160, 225, 171, 136, 225, 171, 176, 225, 172, 152, 225, 173, 128, 225, 173,
+168, 225, 174, 144, 225, 174, 184, 225, 175, 160, 225, 176, 136, 225, 176, 176,
+225, 177, 152, 225, 178, 128, 225, 178, 168, 225, 179, 144, 225, 179, 184, 225,
+180, 160, 225, 181, 136, 225, 181, 176, 225, 182, 152, 225, 183, 128, 225, 183,
+168, 225, 184, 144, 225, 184, 184, 225, 185, 160, 225, 186, 136, 225, 186, 176,
+225, 187, 152, 225, 188, 128, 225, 188, 168, 225, 189, 144, 225, 189, 184, 225,
+190, 160, 225, 191, 136, 225, 191, 176, 226, 128, 152, 226, 129, 128, 226, 129,
+168, 226, 130, 144, 226, 130, 184, 226, 131, 160, 226, 132, 136, 226, 132, 176,
+226, 133, 152, 226, 134, 128, 226, 134, 168, 226, 135, 144, 226, 135, 184, 226,
+136, 160, 226, 137, 136, 226, 137, 176, 226, 138, 152, 226, 139, 128, 226, 139,
+168, 226, 140, 144, 226, 140, 184, 226, 141, 160, 226, 142, 136, 226, 142, 176,
+226, 143, 152, 226, 144, 128, 226, 144, 168, 226, 145, 144, 226, 145, 184, 226,
+146, 160, 226, 147, 136, 226, 147, 176, 226, 148, 152, 226, 149, 128, 226, 149,
+168, 226, 150, 144, 226, 150, 184, 226, 151, 160, 226, 152, 136, 226, 152, 176,
+226, 153, 152, 226, 154, 128, 226, 154, 168, 226, 155, 144, 226, 155, 184, 226,
+156, 160, 226, 157, 136, 226, 157, 176, 226, 158, 152, 226, 159, 128, 226, 159,
+168, 226, 160, 144, 226, 160, 184, 226, 161, 160, 226, 162, 136, 226, 162, 176,
+226, 163, 152, 226, 164, 128, 226, 164, 168, 226, 165, 144, 226, 165, 184, 226,
+166, 160, 226, 167, 136, 226, 167, 176, 226, 168, 152, 226, 169, 128, 226, 169,
+168, 226, 170, 144, 226, 170, 184, 226, 171, 160, 226, 172, 136, 226, 172, 176,
+226, 173, 152, 226, 174, 128, 226, 174, 168, 226, 175, 144, 226, 175, 184, 226,
+176, 160, 226, 177, 136, 226, 177, 176, 226, 178, 152, 226, 179, 128, 226, 179,
+168, 226, 180, 144, 226, 180, 184, 226, 181, 160, 226, 182, 136, 226, 182, 176,
+226, 183, 152, 226, 184, 128, 226, 184, 168, 226, 185, 144, 226, 185, 184, 226,
+186, 160, 226, 187, 136, 226, 187, 176, 226, 188, 152, 226, 189, 128, 226, 189,
+168, 226, 190, 144, 226, 190, 184, 226, 191, 160, 227, 128, 136, 227, 128, 176,
+227, 129, 152, 227, 130, 128, 227, 130, 168, 227, 131, 144, 227, 131, 184, 227,
+132, 160, 227, 133, 136, 227, 133, 176, 227, 134, 152, 227, 135, 128, 227, 135,
+168, 227, 136, 144, 227, 136, 184, 227, 137, 160, 227, 138, 136, 227, 138, 176,
+227, 139, 152, 227, 140, 128, 227, 140, 168, 227, 141, 144, 227, 141, 184, 227,
+142, 160, 227, 143, 136, 227, 143, 176, 227, 144, 152, 227, 145, 128, 227, 145,
+168, 227, 146, 144, 227, 146, 184, 227, 147, 160, 227, 148, 136, 227, 148, 176,
+227, 149, 152, 227, 150, 128, 227, 150, 168, 227, 151, 144, 227, 151, 184, 227,
+152, 160, 227, 153, 136, 227, 153, 176, 227, 154, 152, 227, 155, 128, 227, 155,
+168, 227, 156, 144, 227, 156, 184, 227, 157, 160, 227, 158, 136, 227, 158, 176,
+227, 159, 152, 227, 160, 128, 227, 160, 168, 227, 161, 144, 227, 161, 184, 227,
+162, 160, 227, 163, 136, 227, 163, 176, 227, 164, 152, 227, 165, 128, 227, 165,
+168, 227, 166, 144, 227, 166, 184, 227, 167, 160, 227, 168, 136, 227, 168, 176,
+227, 169, 152, 227, 170, 128, 227, 170, 168, 227, 171, 144, 227, 171, 184, 227,
+172, 160, 227, 173, 136, 227, 173, 176, 227, 174, 152, 227, 175, 128, 227, 175,
+168, 227, 176, 144, 227, 176, 184, 227, 177, 160, 227, 178, 136, 227, 178, 176,
+227, 179, 152, 227, 180, 128, 227, 180, 168, 227, 181, 144, 227, 181, 184, 227,
+182, 160, 227, 183, 136, 227, 183, 176, 227, 184, 152, 227, 185, 128, 227, 185,
+168, 227, 186, 144, 227, 186, 184, 227, 187, 160, 227, 188, 136, 227, 188, 176,
+227, 189, 152, 227, 190, 128, 227, 190, 168, 227, 191, 144, 227, 191, 184, 228,
+128, 160, 228, 129, 136, 228, 129, 176, 228, 130, 152, 228, 131, 128, 228, 131,
+168, 228, 132, 144, 228, 132, 184, 228, 133, 160, 228, 134, 136, 228, 134, 176,
+228, 135, 152, 228, 136, 128, 228, 136, 168, 228, 137, 144, 228, 137, 184, 228,
+138, 160, 228, 139, 136, 228, 139, 176, 228, 140, 152, 228, 141, 128, 228, 141,
+168, 228, 142, 144, 228, 142, 184, 228, 143, 160, 228, 144, 136, 228, 144, 176,
+228, 145, 152, 228, 146, 128, 228, 146, 168, 228, 147, 144, 228, 147, 184, 228,
+148, 160, 228, 149, 136, 228, 149, 176, 228, 150, 152, 228, 151, 128, 228, 151,
+168, 228, 152, 144, 228, 152, 184, 228, 153, 160, 228, 154, 136, 228, 154, 176,
+228, 155, 152, 228, 156, 128, 228, 156, 168, 228, 157, 144, 228, 157, 184, 228,
+158, 160, 228, 159, 136, 228, 159, 176, 228, 160, 152, 228, 161, 128, 228, 161,
+168, 228, 162, 144, 228, 162, 184, 228, 163, 160, 228, 164, 136, 228, 164, 176,
+228, 165, 152, 228, 166, 128, 228, 166, 168, 228, 167, 144, 228, 167, 184, 228,
+168, 160, 228, 169, 136, 228, 169, 176, 228, 170, 152, 228, 171, 128, 228, 171,
+168, 228, 172, 144, 228, 172, 184, 228, 173, 160, 228, 174, 136, 228, 174, 176,
+228, 175, 152, 228, 176, 128, 228, 176, 168, 228, 177, 144, 228, 177, 184, 228,
+178, 160, 228, 179, 136, 228, 179, 176, 228, 180, 152, 228, 181, 128, 228, 181,
+168, 228, 182, 144, 228, 182, 184, 228, 183, 160, 228, 184, 136, 228, 184, 176,
+228, 185, 152, 228, 186, 128, 228, 186, 168, 228, 187, 144, 228, 187, 184, 228,
+188, 160, 228, 189, 136, 228, 189, 176, 228, 190, 152, 228, 191, 128, 228, 191,
+168, 229, 128, 144, 229, 128, 184, 229, 129, 160, 229, 130, 136, 229, 130, 176,
+229, 131, 152, 229, 132, 128, 229, 132, 168, 229, 133, 144, 229, 133, 184, 229,
+134, 160, 229, 135, 136, 229, 135, 176, 229, 136, 152, 229, 137, 128, 229, 137,
+168, 229, 138, 144, 229, 138, 184, 229, 139, 160, 229, 140, 136, 229, 140, 176,
+229, 141, 152, 229, 142, 128, 229, 142, 168, 229, 143, 144, 229, 143, 184, 229,
+144, 160, 229, 145, 136, 229, 145, 176, 229, 146, 152, 229, 147, 128, 229, 147,
+168, 229, 148, 144, 229, 148, 184, 229, 149, 160, 229, 150, 136, 229, 150, 176,
+229, 151, 152, 229, 152, 128, 229, 152, 168, 229, 153, 144, 229, 153, 184, 229,
+154, 160, 229, 155, 136, 229, 155, 176, 229, 156, 152, 229, 157, 128, 229, 157,
+168, 229, 158, 144, 229, 158, 184, 229, 159, 160, 229, 160, 136, 229, 160, 176,
+229, 161, 152, 229, 162, 128, 229, 162, 168, 229, 163, 144, 229, 163, 184, 229,
+164, 160, 229, 165, 136, 229, 165, 176, 229, 166, 152, 229, 167, 128, 229, 167,
+168, 229, 168, 144, 229, 168, 184, 229, 169, 160, 229, 170, 136, 229, 170, 176,
+229, 171, 152, 229, 172, 128, 229, 172, 168, 229, 173, 144, 229, 173, 184, 229,
+174, 160, 229, 175, 136, 229, 175, 176, 229, 176, 152, 229, 177, 128, 229, 177,
+168, 229, 178, 144, 229, 178, 184, 229, 179, 160, 229, 180, 136, 229, 180, 176,
+229, 181, 152, 229, 182, 128, 229, 182, 168, 229, 183, 144, 229, 183, 184, 229,
+184, 160, 229, 185, 136, 229, 185, 176, 229, 186, 152, 229, 187, 128, 229, 187,
+168, 229, 188, 144, 229, 188, 184, 229, 189, 160, 229, 190, 136, 229, 190, 176,
+229, 191, 152, 230, 128, 128, 230, 128, 168, 230, 129, 144, 230, 129, 184, 230,
+130, 160, 230, 131, 136, 230, 131, 176, 230, 132, 152, 230, 133, 128, 230, 133,
+168, 230, 134, 144, 230, 134, 184, 230, 135, 160, 230, 136, 136, 230, 136, 176,
+230, 137, 152, 230, 138, 128, 230, 138, 168, 230, 139, 144, 230, 139, 184, 230,
+140, 160, 230, 141, 136, 230, 141, 176, 230, 142, 152, 230, 143, 128, 230, 143,
+168, 230, 144, 144, 230, 144, 184, 230, 145, 160, 230, 146, 136, 230, 146, 176,
+230, 147, 152, 230, 148, 128, 230, 148, 168, 230, 149, 144, 230, 149, 184, 230,
+150, 160, 230, 151, 136, 230, 151, 176, 230, 152, 152, 230, 153, 128, 230, 153,
+168, 230, 154, 144, 230, 154, 184, 230, 155, 160, 230, 156, 136, 230, 156, 176,
+230, 157, 152, 230, 158, 128, 230, 158, 168, 230, 159, 144, 230, 159, 184, 230,
+160, 160, 230, 161, 136, 230, 161, 176, 230, 162, 152, 230, 163, 128, 230, 163,
+168, 230, 164, 144, 230, 164, 184, 230, 165, 160, 230, 166, 136, 230, 166, 176,
+230, 167, 152, 230, 168, 128, 230, 168, 168, 230, 169, 144, 230, 169, 184, 230,
+170, 160, 230, 171, 136, 230, 171, 176, 230, 172, 152, 230, 173, 128, 230, 173,
+168, 230, 174, 144, 230, 174, 184, 230, 175, 160, 230, 176, 136, 230, 176, 176,
+230, 177, 152, 230, 178, 128, 230, 178, 168, 230, 179, 144, 230, 179, 184, 230,
+180, 160, 230, 181, 136, 230, 181, 176, 230, 182, 152, 230, 183, 128, 230, 183,
+168, 230, 184, 144, 230, 184, 184, 230, 185, 160, 230, 186, 136, 230, 186, 176,
+230, 187, 152, 230, 188, 128, 230, 188, 168, 230, 189, 144, 230, 189, 184, 230,
+190, 160, 230, 191, 136, 230, 191, 176, 231, 128, 152, 231, 129, 128, 231, 129,
+168, 231, 130, 144, 231, 130, 184, 231, 131, 160, 231, 132, 136, 231, 132, 176,
+231, 133, 152, 231, 134, 128, 231, 134, 168, 231, 135, 144, 231, 135, 184, 231,
+136, 160, 231, 137, 136, 231, 137, 176, 231, 138, 152, 231, 139, 128, 231, 139,
+168, 231, 140, 144, 231, 140, 184, 231, 141, 160, 231, 142, 136, 231, 142, 176,
+231, 143, 152, 231, 144, 128, 231, 144, 168, 231, 145, 144, 231, 145, 184, 231,
+146, 160, 231, 147, 136, 231, 147, 176, 231, 148, 152, 231, 149, 128, 231, 149,
+168, 231, 150, 144, 231, 150, 184, 231, 151, 160, 231, 152, 136, 231, 152, 176,
+231, 153, 152, 231, 154, 128, 231, 154, 168, 231, 155, 144, 231, 155, 184, 231,
+156, 160, 231, 157, 136, 231, 157, 176, 231, 158, 152, 231, 159, 128, 231, 159,
+168, 231, 160, 144, 231, 160, 184, 231, 161, 160, 231, 162, 136, 231, 162, 176,
+231, 163, 152, 231, 164, 128, 231, 164, 168, 231, 165, 144, 231, 165, 184, 231,
+166, 160, 231, 167, 136, 231, 167, 176, 231, 168, 152, 231, 169, 128, 231, 169,
+168, 231, 170, 144, 231, 170, 184, 231, 171, 160, 231, 172, 136, 231, 172, 176,
+231, 173, 152, 231, 174, 128, 231, 174, 168, 231, 175, 144, 231, 175, 184, 231,
+176, 160, 231, 177, 136, 231, 177, 176, 231, 178, 152, 231, 179, 128, 231, 179,
+168, 231, 180, 144, 231, 180, 184, 231, 181, 160, 231, 182, 136, 231, 182, 176,
+231, 183, 152, 231, 184, 128, 231, 184, 168, 231, 185, 144, 231, 185, 184, 231,
+186, 160, 231, 187, 136, 231, 187, 176, 231, 188, 152, 231, 189, 128, 231, 189,
+168, 231, 190, 144, 231, 190, 184, 231, 191, 160, 232, 128, 136, 232, 128, 176,
+232, 129, 152, 232, 130, 128, 232, 130, 168, 232, 131, 144, 232, 131, 184, 232,
+132, 160, 232, 133, 136, 232, 133, 176, 232, 134, 152, 232, 135, 128, 232, 135,
+168, 232, 136, 144, 232, 136, 184, 232, 137, 160, 232, 138, 136, 232, 138, 176,
+232, 139, 152, 232, 140, 128, 232, 140, 168, 232, 141, 144, 232, 141, 184, 232,
+142, 160, 232, 143, 136, 232, 143, 176, 232, 144, 152, 232, 145, 128, 232, 145,
+168, 232, 146, 144, 232, 146, 184, 232, 147, 160, 232, 148, 136, 232, 148, 176,
+232, 149, 152, 232, 150, 128, 232, 150, 168, 232, 151, 144, 232, 151, 184, 232,
+152, 160, 232, 153, 136, 232, 153, 176, 232, 154, 152, 232, 155, 128, 232, 155,
+168, 232, 156, 144, 232, 156, 184, 232, 157, 160, 232, 158, 136, 232, 158, 176,
+232, 159, 152, 232, 160, 128, 232, 160, 168, 232, 161, 144, 232, 161, 184, 232,
+162, 160, 232, 163, 136, 232, 163, 176, 232, 164, 152, 232, 165, 128, 232, 165,
+168, 232, 166, 144, 232, 166, 184, 232, 167, 160, 232, 168, 136, 232, 168, 176,
+232, 169, 152, 232, 170, 128, 232, 170, 168, 232, 171, 144, 232, 171, 184, 232,
+172, 160, 232, 173, 136, 232, 173, 176, 232, 174, 152, 232, 175, 128, 232, 175,
+168, 232, 176, 144, 232, 176, 184, 232, 177, 160, 232, 178, 136, 232, 178, 176,
+232, 179, 152, 232, 180, 128, 232, 180, 168, 232, 181, 144, 232, 181, 184, 232,
+182, 160, 232, 183, 136, 232, 183, 176, 232, 184, 152, 232, 185, 128, 232, 185,
+168, 232, 186, 144, 232, 186, 184, 232, 187, 160, 232, 188, 136, 232, 188, 176,
+232, 189, 152, 232, 190, 128, 232, 190, 168, 232, 191, 144, 232, 191, 184, 233,
+128, 160, 233, 129, 136, 233, 129, 176, 233, 130, 152, 233, 131, 128, 233, 131,
+168, 233, 132, 144, 233, 132, 184, 233, 133, 160, 233, 134, 136, 233, 134, 176,
+233, 135, 152, 233, 136, 128, 233, 136, 168, 233, 137, 144, 233, 137, 184, 233,
+138, 160, 233, 139, 136, 233, 139, 176, 233, 140, 152, 233, 141, 128, 233, 141,
+168, 233, 142, 144, 233, 142, 184, 233, 143, 160, 233, 144, 136, 233, 144, 176,
+233, 145, 152, 233, 146, 128, 233, 146, 168, 233, 147, 144, 233, 147, 184, 233,
+148, 160, 233, 149, 136, 233, 149, 176, 233, 150, 152, 233, 151, 128, 233, 151,
+168, 233, 152, 144, 233, 152, 184, 233, 153, 160, 233, 154, 136, 233, 154, 176,
+233, 155, 152, 233, 156, 128, 233, 156, 168, 233, 157, 144, 233, 157, 184, 233,
+158, 160, 233, 159, 136, 233, 159, 176, 233, 160, 152, 233, 161, 128, 233, 161,
+168, 233, 162, 144, 233, 162, 184, 233, 163, 160, 233, 164, 136, 233, 164, 176,
+233, 165, 152, 233, 166, 128, 233, 166, 168, 233, 167, 144, 233, 167, 184, 233,
+168, 160, 233, 169, 136, 233, 169, 176, 233, 170, 152, 233, 171, 128, 233, 171,
+168, 233, 172, 144, 233, 172, 184, 233, 173, 160, 233, 174, 136, 233, 174, 176,
+233, 175, 152, 233, 176, 128, 233, 176, 168, 233, 177, 144, 233, 177, 184, 233,
+178, 160, 233, 179, 136, 233, 179, 176, 233, 180, 152, 233, 181, 128, 233, 181,
+168, 233, 182, 144, 233, 182, 184, 233, 183, 160, 233, 184, 136, 233, 184, 176,
+233, 185, 152, 233, 186, 128, 233, 186, 168, 233, 187, 144, 233, 187, 184, 233,
+188, 160, 233, 189, 136, 233, 189, 176, 233, 190, 152, 233, 191, 128, 233, 191,
+168, 234, 128, 144, 234, 128, 184, 234, 129, 160, 234, 130, 136, 234, 130, 176,
+234, 131, 152, 234, 132, 128, 234, 132, 168, 234, 133, 144, 234, 133, 184, 234,
+134, 160, 234, 135, 136, 234, 135, 176, 234, 136, 152, 234, 137, 128, 234, 137,
+168, 234, 138, 144, 234, 138, 184, 234, 139, 160, 234, 140, 136, 234, 140, 176,
+234, 141, 152, 234, 142, 128, 234, 142, 168, 234, 143, 144, 234, 143, 184, 234,
+144, 160, 234, 145, 136, 234, 145, 176, 234, 146, 152, 234, 147, 128, 234, 147,
+168, 234, 148, 144, 234, 148, 184, 234, 149, 160, 234, 150, 136, 234, 150, 176,
+234, 151, 152, 234, 152, 128, 234, 152, 168, 234, 153, 144, 234, 153, 184, 234,
+154, 160, 234, 155, 136, 234, 155, 176, 234, 156, 152, 234, 157, 128, 234, 157,
+168, 234, 158, 144, 234, 158, 184, 234, 159, 160, 234, 160, 136, 234, 160, 176,
+234, 161, 152, 234, 162, 128, 234, 162, 168, 234, 163, 144, 234, 163, 184, 234,
+164, 160, 234, 165, 136, 234, 165, 176, 234, 166, 152, 234, 167, 128, 234, 167,
+168, 234, 168, 144, 234, 168, 184, 234, 169, 160, 234, 170, 136, 234, 170, 176,
+234, 171, 152, 234, 172, 128, 234, 172, 168, 234, 173, 144, 234, 173, 184, 234,
+174, 160, 234, 175, 136, 234, 175, 176, 234, 176, 152, 234, 177, 128, 234, 177,
+168, 234, 178, 144, 234, 178, 184, 234, 179, 160, 234, 180, 136, 234, 180, 176,
+234, 181, 152, 234, 182, 128, 234, 182, 168, 234, 183, 144, 234, 183, 184, 234,
+184, 160, 234, 185, 136, 234, 185, 176, 234, 186, 152, 234, 187, 128, 234, 187,
+168, 234, 188, 144, 234, 188, 184, 234, 189, 160, 234, 190, 136, 234, 190, 176,
+234, 191, 152, 235, 128, 128, 235, 128, 168, 235, 129, 144, 235, 129, 184, 235,
+130, 160, 235, 131, 136, 235, 131, 176, 235, 132, 152, 235, 133, 128, 235, 133,
+168, 235, 134, 144, 235, 134, 184, 235, 135, 160, 235, 136, 136, 235, 136, 176,
+235, 137, 152, 235, 138, 128, 235, 138, 168, 235, 139, 144, 235, 139, 184, 235,
+140, 160, 235, 141, 136, 235, 141, 176, 235, 142, 152, 235, 143, 128, 235, 143,
+168, 235, 144, 144, 235, 144, 184, 235, 145, 160, 235, 146, 136, 235, 146, 176,
+235, 147, 152, 235, 148, 128, 235, 148, 168, 235, 149, 144, 235, 149, 184, 235,
+150, 160, 235, 151, 136, 235, 151, 176, 235, 152, 152, 235, 153, 128, 235, 153,
+168, 235, 154, 144, 235, 154, 184, 235, 155, 160, 235, 156, 136, 235, 156, 176,
+235, 157, 152, 235, 158, 128, 235, 158, 168, 235, 159, 144, 235, 159, 184, 235,
+160, 160, 235, 161, 136, 235, 161, 176, 235, 162, 152, 235, 163, 128, 235, 163,
+168, 235, 164, 144, 235, 164, 184, 235, 165, 160, 235, 166, 136, 235, 166, 176,
+235, 167, 152, 235, 168, 128, 235, 168, 168, 235, 169, 144, 235, 169, 184, 235,
+170, 160, 235, 171, 136, 235, 171, 176, 235, 172, 152, 235, 173, 128, 235, 173,
+168, 235, 174, 144, 235, 174, 184, 235, 175, 160, 235, 176, 136, 235, 176, 176,
+235, 177, 152, 235, 178, 128, 235, 178, 168, 235, 179, 144, 235, 179, 184, 235,
+180, 160, 235, 181, 136, 235, 181, 176, 235, 182, 152, 235, 183, 128, 235, 183,
+168, 235, 184, 144, 235, 184, 184, 235, 185, 160, 235, 186, 136, 235, 186, 176,
+235, 187, 152, 235, 188, 128, 235, 188, 168, 235, 189, 144, 235, 189, 184, 235,
+190, 160, 235, 191, 136, 235, 191, 176, 236, 128, 152, 236, 129, 128, 236, 129,
+168, 236, 130, 144, 236, 130, 184, 236, 131, 160, 236, 132, 136, 236, 132, 176,
+236, 133, 152, 236, 134, 128, 236, 134, 168, 236, 135, 144, 236, 135, 184, 236,
+136, 160, 236, 137, 136, 236, 137, 176, 236, 138, 152, 236, 139, 128, 236, 139,
+168, 236, 140, 144, 236, 140, 184, 236, 141, 160, 236, 142, 136, 236, 142, 176,
+236, 143, 152, 236, 144, 128, 236, 144, 168, 236, 145, 144, 236, 145, 184, 236,
+146, 160, 236, 147, 136, 236, 147, 176, 236, 148, 152, 236, 149, 128, 236, 149,
+168, 236, 150, 144, 236, 150, 184, 236, 151, 160, 236, 152, 136, 236, 152, 176,
+236, 153, 152, 236, 154, 128, 236, 154, 168, 236, 155, 144, 236, 155, 184, 236,
+156, 160, 236, 157, 136, 236, 157, 176, 236, 158, 152, 236, 159, 128, 236, 159,
+168, 236, 160, 144, 236, 160, 184, 236, 161, 160, 236, 162, 136, 236, 162, 176,
+236, 163, 152, 236, 164, 128, 236, 164, 168, 236, 165, 144, 236, 165, 184, 236,
+166, 160, 236, 167, 136, 236, 167, 176, 236, 168, 152, 236, 169, 128, 236, 169,
+168, 236, 170, 144, 236, 170, 184, 236, 171, 160, 236, 172, 136, 236, 172, 176,
+236, 173, 152, 236, 174, 128, 236, 174, 168, 236, 175, 144, 236, 175, 184, 236,
+176, 160, 236, 177, 136, 236, 177, 176, 236, 178, 152, 236, 179, 128, 236, 179,
+168, 236, 180, 144, 236, 180, 184, 236, 181, 160, 236, 182, 136, 236, 182, 176,
+236, 183, 152, 236, 184, 128, 236, 184, 168, 236, 185, 144, 236, 185, 184, 236,
+186, 160, 236, 187, 136, 236, 187, 176, 236, 188, 152, 236, 189, 128, 236, 189,
+168, 236, 190, 144, 236, 190, 184, 236, 191, 160, 237, 128, 136, 237, 128, 176,
+237, 129, 152, 237, 130, 128, 237, 130, 168, 237, 131, 144, 237, 131, 184, 237,
+132, 160, 237, 133, 136, 237, 133, 176, 237, 134, 152, 237, 135, 128, 237, 135,
+168, 237, 136, 144, 237, 136, 184, 237, 137, 160, 237, 138, 136, 237, 138, 176,
+237, 139, 152, 237, 140, 128, 237, 140, 168, 237, 141, 144, 237, 141, 184, 237,
+142, 160, 237, 143, 136, 237, 143, 176, 237, 144, 152, 237, 145, 128, 237, 145,
+168, 237, 146, 144, 237, 146, 184, 237, 147, 160, 237, 148, 136, 237, 148, 176,
+237, 149, 152, 237, 150, 128, 237, 150, 168, 237, 151, 144, 237, 151, 184, 237,
+152, 160, 237, 153, 136, 237, 153, 176, 237, 154, 152, 237, 155, 128, 237, 155,
+168, 237, 156, 144, 237, 156, 184, 237, 157, 160, 237, 158, 136, 237, 158, 176,
+237, 159, 152, 238, 128, 128, 238, 128, 168, 238, 129, 144, 238, 129, 184, 238,
+130, 160, 238, 131, 136, 238, 131, 176, 238, 132, 152, 238, 133, 128, 238, 133,
+168, 238, 134, 144, 238, 134, 184, 238, 135, 160, 238, 136, 136, 238, 136, 176,
+238, 137, 152, 238, 138, 128, 238, 138, 168, 238, 139, 144, 238, 139, 184, 238,
+140, 160, 238, 141, 136, 238, 141, 176, 238, 142, 152, 238, 143, 128, 238, 143,
+168, 238, 144, 144, 238, 144, 184, 238, 145, 160, 238, 146, 136, 238, 146, 176,
+238, 147, 152, 238, 148, 128, 238, 148, 168, 238, 149, 144, 238, 149, 184, 238,
+150, 160, 238, 151, 136, 238, 151, 176, 238, 152, 152, 238, 153, 128, 238, 153,
+168, 238, 154, 144, 238, 154, 184, 238, 155, 160, 238, 156, 136, 238, 156, 176,
+238, 157, 152, 238, 158, 128, 238, 158, 168, 238, 159, 144, 238, 159, 184, 238,
+160, 160, 238, 161, 136, 238, 161, 176, 238, 162, 152, 238, 163, 128, 238, 163,
+168, 238, 164, 144, 238, 164, 184, 238, 165, 160, 238, 166, 136, 238, 166, 176,
+238, 167, 152, 238, 168, 128, 238, 168, 168, 238, 169, 144, 238, 169, 184, 238,
+170, 160, 238, 171, 136, 238, 171, 176, 238, 172, 152, 238, 173, 128, 238, 173,
+168, 238, 174, 144, 238, 174, 184, 238, 175, 160, 238, 176, 136, 238, 176, 176,
+238, 177, 152, 238, 178, 128, 238, 178, 168, 238, 179, 144, 238, 179, 184, 238,
+180, 160, 238, 181, 136, 238, 181, 176, 238, 182, 152, 238, 183, 128, 238, 183,
+168, 238, 184, 144, 238, 184, 184, 238, 185, 160, 238, 186, 136, 238, 186, 176,
+238, 187, 152, 238, 188, 128, 238, 188, 168, 238, 189, 144, 238, 189, 184, 238,
+190, 160, 238, 191, 136, 238, 191, 176, 239, 128, 152, 239, 129, 128, 239, 129,
+168, 239, 130, 144, 239, 130, 184, 239, 131, 160, 239, 132, 136, 239, 132, 176,
+239, 133, 152, 239, 134, 128, 239, 134, 168, 239, 135, 144, 239, 135, 184, 239,
+136, 160, 239, 137, 136, 239, 137, 176, 239, 138, 152, 239, 139, 128, 239, 139,
+168, 239, 140, 144, 239, 140, 184, 239, 141, 160, 239, 142, 136, 239, 142, 176,
+239, 143, 152, 239, 144, 128, 239, 144, 168, 239, 145, 144, 239, 145, 184, 239,
+146, 160, 239, 147, 136, 239, 147, 176, 239, 148, 152, 239, 149, 128, 239, 149,
+168, 239, 150, 144, 239, 150, 184, 239, 151, 160, 239, 152, 136, 239, 152, 176,
+239, 153, 152, 239, 154, 128, 239, 154, 168, 239, 155, 144, 239, 155, 184, 239,
+156, 160, 239, 157, 136, 239, 157, 176, 239, 158, 152, 239, 159, 128, 239, 159,
+168, 239, 160, 144, 239, 160, 184, 239, 161, 160, 239, 162, 136, 239, 162, 176,
+239, 163, 152, 239, 164, 128, 239, 164, 168, 239, 165, 144, 239, 165, 184, 239,
+166, 160, 239, 167, 136, 239, 167, 176, 239, 168, 152, 239, 169, 128, 239, 169,
+168, 239, 170, 144, 239, 170, 184, 239, 171, 160, 239, 172, 136, 239, 172, 176,
+239, 173, 152, 239, 174, 128, 239, 174, 168, 239, 175, 144, 239, 175, 184, 239,
+176, 160, 239, 177, 136, 239, 177, 176, 239, 178, 152, 239, 179, 128, 239, 179,
+168, 239, 180, 144, 239, 180, 184, 239, 181, 160, 239, 182, 136, 239, 182, 176,
+239, 183, 152, 239, 184, 128, 239, 184, 168, 239, 185, 144, 239, 185, 184, 239,
+186, 160, 239, 187, 136, 239, 187, 176, 239, 188, 152, 239, 189, 128, 239, 189,
+168, 239, 190, 144, 239, 190, 184, 239, 191, 160
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_x_windows_950.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_x_windows_950.java
new file mode 100644
index 0000000..7525474
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_MultiByte_x_windows_950.java
@@ -0,0 +1,242 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+public class OldCharset_MultiByte_x_windows_950 extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "x-windows-950";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+167, 175, 176, 177, 183, 215, 247, 711, 713, 913, 945, 8211, 8242, 8364, 8451, 8544,
+8592, 8725, 8756, 8786, 8853, 8895, 9472, 9508, 9552, 9582, 9612, 9650, 9698, 9733, 9792, 12288,
+12318, 12549, 12579, 12963, 13198, 13252, 19968, 19998, 20028, 20060, 20094, 20126, 20160, 20190, 20221, 20253,
+20283, 20313, 20343, 20373, 20403, 20433, 20463, 20493, 20523, 20553, 20584, 20615, 20652, 20682, 20712, 20742,
+20772, 20803, 20833, 20864, 20894, 20924, 20956, 20986, 21020, 21050, 21082, 21112, 21142, 21179, 21209, 21239,
+21269, 21300, 21330, 21360, 21390, 21420, 21450, 21480, 21510, 21540, 21570, 21600, 21630, 21664, 21694, 21726,
+21756, 21786, 21816, 21846, 21877, 21907, 21937, 21967, 21999, 22029, 22060, 22090, 22120, 22150, 22181, 22211,
+22241, 22271, 22302, 22334, 22369, 22400, 22430, 22460, 22492, 22522, 22553, 22583, 22613, 22644, 22675, 22705,
+22735, 22767, 22797, 22827, 22857, 22887, 22917, 22947, 22977, 23008, 23038, 23068, 23100, 23130, 23160, 23191,
+23221, 23253, 23283, 23315, 23346, 23376, 23406, 23436, 23468, 23498, 23528, 23559, 23589, 23620, 23650, 23686,
+23716, 23750, 23784, 23814, 23844, 23874, 23906, 23936, 23966, 23996, 24029, 24061, 24091, 24125, 24155, 24185,
+24215, 24245, 24275, 24305, 24335, 24365, 24395, 24425, 24455, 24485, 24515, 24545, 24575, 24605, 24640, 24670,
+24703, 24733, 24763, 24793, 24823, 24853, 24884, 24914, 24944, 24974, 25004, 25034, 25064, 25095, 25125, 25155,
+25185, 25215, 25256, 25286, 25323, 25353, 25384, 25414, 25445, 25475, 25505, 25536, 25567, 25606, 25636, 25667,
+25697, 25727, 25757, 25787, 25817, 25847, 25877, 25907, 25937, 25967, 26000, 26030, 26060, 26092, 26122, 26152,
+26183, 26213, 26244, 26274, 26304, 26334, 26364, 26395, 26425, 26455, 26485, 26515, 26546, 26576, 26606, 26642,
+26673, 26703, 26733, 26763, 26793, 26823, 26854, 26884, 26917, 26948, 26978, 27010, 27040, 27070, 27106, 27136,
+27166, 27196, 27226, 27262, 27292, 27322, 27353, 27384, 27414, 27444, 27476, 27506, 27537, 27567, 27597, 27627,
+27657, 27687, 27718, 27749, 27779, 27819, 27849, 27879, 27911, 27941, 27992, 28022, 28052, 28082, 28112, 28142,
+28185, 28216, 28246, 28276, 28306, 28336, 28366, 28396, 28426, 28457, 28494, 28524, 28555, 28585, 28615, 28646,
+28676, 28706, 28736, 28766, 28796, 28826, 28856, 28887, 28918, 28951, 28982, 29012, 29042, 29072, 29103, 29134,
+29164, 29194, 29224, 29254, 29287, 29317, 29347, 29377, 29407, 29437, 29467, 29498, 29528, 29558, 29588, 29618,
+29650, 29684, 29718, 29748, 29778, 29808, 29840, 29871, 29903, 29934, 29964, 29994, 30024, 30054, 30084, 30114,
+30144, 30174, 30204, 30234, 30264, 30294, 30325, 30355, 30388, 30418, 30448, 30480, 30511, 30541, 30571, 30601,
+30631, 30663, 30693, 30723, 30753, 30787, 30818, 30848, 30878, 30908, 30938, 30969, 30999, 31029, 31059, 31090,
+31120, 31150, 31181, 31211, 31242, 31272, 31302, 31335, 31365, 31395, 31425, 31455, 31485, 31515, 31547, 31584,
+31618, 31648, 31678, 31708, 31739, 31769, 31799, 31831, 31861, 31892, 31922, 31952, 31982, 32012, 32043, 32074,
+32104, 32134, 32166, 32196, 32227, 32259, 32289, 32319, 32350, 32380, 32410, 32566, 32596, 32626, 32657, 32687,
+32717, 32747, 32779, 32809, 32839, 32871, 32901, 32931, 32962, 32992, 33022, 33053, 33085, 33115, 33145, 33175,
+33205, 33237, 33267, 33297, 33327, 33358, 33388, 33418, 33448, 33489, 33519, 33549, 33579, 33609, 33651, 33682,
+33712, 33742, 33772, 33802, 33833, 33863, 33893, 33926, 33956, 33986, 34023, 34054, 34084, 34115, 34145, 34176,
+34206, 34237, 34268, 34298, 34328, 34358, 34388, 34419, 34449, 34479, 34512, 34549, 34579, 34609, 34639, 34669,
+34701, 34731, 34761, 34791, 34821, 34851, 34881, 34913, 34943, 34974, 35004, 35034, 35064, 35094, 35125, 35155,
+35185, 35215, 35245, 35282, 35312, 35342, 35372, 35402, 35432, 35462, 35492, 35522, 35552, 35582, 35612, 35642,
+35672, 35703, 35733, 35895, 35925, 35955, 35985, 36015, 36047, 36077, 36109, 36196, 36228, 36259, 36289, 36319,
+36349, 36379, 36409, 36439, 36470, 36500, 36530, 36561, 36591, 36621, 36652, 36683, 36763, 36799, 36832, 36862,
+36892, 36924, 36955, 36985, 37015, 37045, 37076, 37106, 37136, 37166, 37196, 37226, 37257, 37287, 37317, 37347,
+37377, 37411, 37445, 37475, 37506, 37536, 37568, 37598, 37628, 37658, 37688, 37718, 37749, 37780, 37810, 37840,
+37870, 37900, 37930, 37960, 37992, 38263, 38296, 38326, 38356, 38428, 38458, 38488, 38518, 38548, 38579, 38610,
+38640, 38670, 38700, 38731, 38761, 38792, 38822, 38852, 38883, 38913, 38944, 38977, 39007, 39080, 39110, 39141,
+39171, 39201, 39231, 39262, 39318, 39348, 39378, 39408, 39438, 39468, 39498, 39528, 39592, 39622, 39654, 39684,
+39714, 39745, 39775, 39805, 39835, 39865, 39895, 39927, 39959, 39990, 40020, 40051, 40165, 40195, 40226, 40256,
+40287, 40317, 40347, 40377, 40407, 40437, 40467, 40565, 40595, 40628, 40659, 40690, 40720, 40750, 40780, 40810,
+40845, 57344, 57374, 57404, 57434, 57464, 57494, 57524, 57554, 57584, 57614, 57644, 57674, 57704, 57734, 57764,
+57794, 57824, 57854, 57884, 57914, 57944, 57974, 58004, 58034, 58064, 58094, 58124, 58154, 58184, 58214, 58244,
+58274, 58304, 58334, 58364, 58394, 58424, 58454, 58484, 58514, 58544, 58574, 58604, 58634, 58664, 58694, 58724,
+58754, 58784, 58814, 58844, 58874, 58904, 58934, 58964, 58994, 59024, 59054, 59084, 59114, 59144, 59174, 59204,
+59234, 59264, 59294, 59324, 59354, 59384, 59414, 59444, 59474, 59504, 59534, 59564, 59594, 59624, 59654, 59684,
+59714, 59744, 59774, 59804, 59834, 59864, 59894, 59924, 59954, 59984, 60014, 60044, 60074, 60104, 60134, 60164,
+60194, 60224, 60254, 60284, 60314, 60344, 60374, 60404, 60434, 60464, 60494, 60524, 60554, 60584, 60614, 60644,
+60674, 60704, 60734, 60764, 60794, 60824, 60854, 60884, 60914, 60944, 60974, 61004, 61034, 61064, 61094, 61124,
+61154, 61184, 61214, 61244, 61274, 61304, 61334, 61364, 61394, 61424, 61454, 61484, 61514, 61544, 61574, 61604,
+61634, 61664, 61694, 61724, 61754, 61784, 61814, 61844, 61874, 61904, 61934, 61964, 61994, 62024, 62054, 62084,
+62114, 62144, 62174, 62204, 62234, 62264, 62294, 62324, 62354, 62384, 62414, 62444, 62474, 62504, 62534, 62564,
+62594, 62624, 62654, 62684, 62714, 62744, 62774, 62804, 62834, 62864, 62894, 62924, 62954, 62984, 63014, 63044,
+63074, 63104, 63134, 63164, 63194, 63224, 63254, 63284, 63314, 63344, 63374, 63404, 63434, 63464, 63494, 63524,
+63554, 64012, 65072, 65102, 65281, 65311, 65343, 65373, 65504
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+161, 177, 161, 194, 162, 88, 161, 211, 161, 80, 161, 209, 161, 210, 163, 190,
+163, 188, 163, 68, 163, 92, 161, 86, 161, 172, 163, 225, 162, 74, 162, 185,
+161, 246, 162, 65, 161, 239, 161, 220, 161, 242, 161, 233, 162, 119, 162, 116,
+162, 164, 162, 161, 162, 109, 161, 182, 162, 168, 161, 185, 161, 240, 161, 64,
+161, 170, 163, 116, 163, 180, 161, 192, 162, 85, 162, 87, 164, 64, 165, 224,
+201, 100, 201, 65, 176, 174, 168, 200, 164, 176, 165, 81, 165, 247, 201, 180,
+202, 91, 167, 69, 203, 188, 203, 202, 205, 232, 171, 77, 173, 193, 173, 191,
+173, 219, 176, 182, 216, 91, 216, 95, 182, 202, 220, 185, 224, 243, 228, 234,
+236, 188, 164, 184, 162, 93, 190, 172, 203, 205, 203, 206, 187, 254, 165, 88,
+202, 108, 168, 235, 208, 231, 220, 199, 241, 237, 168, 241, 176, 200, 241, 238,
+164, 80, 232, 250, 168, 242, 166, 76, 202, 116, 225, 70, 164, 206, 165, 111,
+166, 91, 202, 165, 167, 102, 203, 235, 203, 227, 206, 72, 206, 76, 206, 78,
+173, 243, 208, 247, 176, 225, 176, 220, 212, 113, 216, 109, 179, 237, 220, 216,
+182, 226, 185, 198, 229, 68, 228, 251, 190, 185, 236, 195, 195, 96, 245, 196,
+201, 198, 171, 170, 249, 107, 167, 163, 169, 89, 203, 249, 206, 81, 209, 81,
+212, 177, 176, 242, 216, 161, 216, 126, 220, 233, 225, 93, 185, 211, 229, 76,
+236, 204, 167, 167, 206, 96, 164, 210, 169, 94, 182, 248, 201, 206, 167, 173,
+204, 74, 206, 115, 206, 116, 174, 82, 177, 64, 177, 66, 216, 187, 216, 197,
+220, 249, 225, 110, 225, 115, 233, 86, 236, 208, 164, 108, 212, 240, 167, 185,
+209, 104, 216, 213, 185, 235, 177, 78, 201, 213, 204, 89, 185, 240, 202, 199,
+204, 92, 206, 171, 174, 111, 177, 83, 177, 92, 216, 233, 221, 86, 225, 164,
+229, 109, 192, 172, 164, 116, 180, 83, 169, 173, 180, 85, 185, 243, 183, 70,
+169, 177, 177, 103, 185, 248, 245, 203, 166, 161, 171, 218, 233, 116, 177, 109,
+171, 224, 216, 246, 164, 223, 202, 221, 169, 193, 171, 228, 206, 202, 206, 195,
+177, 118, 209, 167, 177, 162, 213, 91, 221, 101, 180, 106, 183, 91, 225, 200,
+188, 162, 188, 168, 188, 169, 190, 210, 236, 230, 249, 186, 221, 117, 206, 211,
+201, 230, 169, 211, 169, 225, 169, 238, 206, 218, 171, 246, 174, 193, 174, 185,
+213, 103, 177, 189, 177, 196, 180, 122, 217, 99, 183, 112, 221, 126, 221, 162,
+217, 98, 225, 237, 217, 90, 190, 216, 233, 174, 194, 94, 244, 77, 233, 175,
+177, 207, 221, 188, 180, 180, 217, 124, 177, 220, 166, 175, 169, 254, 172, 81,
+209, 213, 213, 169, 183, 121, 186, 90, 233, 181, 242, 75, 176, 210, 177, 230,
+201, 240, 168, 65, 170, 83, 170, 85, 207, 86, 172, 89, 207, 79, 209, 236,
+209, 226, 209, 224, 213, 180, 213, 204, 213, 188, 217, 217, 217, 209, 217, 172,
+217, 216, 221, 228, 221, 205, 183, 167, 226, 64, 226, 76, 229, 213, 229, 202,
+188, 207, 233, 215, 233, 203, 192, 207, 192, 204, 239, 226, 242, 80, 245, 209,
+198, 86, 209, 249, 233, 223, 183, 179, 213, 218, 194, 108, 165, 192, 178, 64,
+237, 77, 174, 241, 201, 248, 203, 91, 168, 85, 170, 106, 172, 117, 204, 246,
+207, 167, 172, 122, 210, 76, 210, 72, 175, 75, 178, 71, 214, 64, 178, 97,
+181, 65, 180, 229, 180, 242, 213, 228, 222, 95, 222, 85, 226, 108, 186, 173,
+226, 126, 186, 120, 226, 118, 230, 73, 230, 90, 237, 79, 233, 236, 237, 86,
+233, 246, 242, 98, 244, 102, 197, 244, 168, 96, 205, 89, 172, 181, 210, 113,
+214, 88, 214, 75, 181, 77, 222, 108, 222, 115, 226, 187, 230, 99, 191, 82,
+192, 236, 242, 106, 198, 121, 192, 240, 170, 170, 218, 107, 242, 113, 203, 101,
+207, 194, 175, 86, 178, 114, 222, 173, 230, 117, 239, 254, 203, 107, 172, 194,
+210, 180, 214, 120, 218, 126, 181, 94, 222, 180, 186, 192, 237, 105, 237, 110,
+196, 110, 207, 216, 191, 94, 202, 70, 207, 219, 178, 165, 237, 115, 172, 207,
+210, 199, 181, 108, 222, 204, 230, 181, 191, 97, 194, 125, 249, 204, 181, 113,
+181, 114, 178, 176, 205, 120, 210, 207, 214, 169, 218, 189, 183, 251, 230, 190,
+193, 64, 195, 169, 170, 190, 207, 242, 210, 225, 178, 185, 218, 209, 222, 240,
+226, 242, 189, 88, 191, 106, 237, 172, 242, 163, 246, 246, 210, 234, 218, 212,
+227, 67, 194, 167, 207, 250, 210, 237, 218, 215, 227, 72, 191, 112, 242, 166,
+210, 248, 223, 66, 237, 185, 179, 186, 172, 242, 178, 195, 218, 223, 184, 97,
+227, 93, 189, 105, 230, 216, 234, 195, 237, 191, 240, 99, 195, 178, 246, 250,
+205, 168, 214, 222, 223, 84, 234, 202, 244, 171, 211, 90, 181, 181, 214, 238,
+181, 179, 223, 88, 227, 117, 227, 108, 189, 116, 230, 233, 234, 205, 193, 104,
+194, 182, 196, 126, 248, 254, 166, 206, 170, 201, 184, 112, 208, 78, 189, 126,
+214, 248, 230, 246, 181, 192, 234, 230, 215, 66, 230, 252, 181, 194, 205, 173,
+208, 91, 208, 88, 219, 72, 215, 80, 219, 79, 223, 119, 184, 161, 231, 68,
+234, 236, 242, 194, 166, 220, 215, 82, 211, 113, 231, 74, 247, 239, 203, 161,
+205, 191, 173, 98, 173, 102, 206, 65, 175, 237, 175, 243, 215, 94, 178, 247,
+215, 116, 219, 116, 219, 168, 181, 220, 223, 199, 223, 215, 223, 176, 223, 179,
+227, 173, 227, 178, 231, 115, 189, 183, 231, 76, 191, 187, 234, 253, 237, 244,
+237, 254, 240, 171, 242, 212, 196, 169, 245, 241, 247, 76, 176, 64, 208, 169,
+211, 189, 179, 76, 181, 241, 223, 232, 184, 187, 227, 235, 231, 187, 231, 175,
+191, 196, 193, 177, 238, 98, 240, 187, 195, 199, 196, 247, 208, 170, 191, 197,
+211, 215, 179, 79, 219, 202, 223, 247, 187, 114, 231, 202, 238, 113, 240, 210,
+247, 82, 179, 87, 238, 121, 168, 164, 231, 210, 176, 81, 215, 203, 219, 226,
+184, 229, 224, 70, 187, 126, 189, 212, 235, 126, 191, 213, 238, 174, 240, 237,
+195, 209, 197, 64, 248, 194, 168, 166, 168, 168, 193, 199, 235, 177, 182, 74,
+228, 84, 189, 228, 196, 186, 168, 170, 219, 237, 189, 236, 215, 218, 184, 242,
+228, 91, 231, 249, 191, 229, 240, 250, 195, 221, 247, 94, 184, 250, 211, 232,
+219, 252, 228, 103, 232, 71, 241, 73, 168, 175, 203, 166, 208, 182, 211, 234,
+215, 229, 185, 71, 187, 191, 235, 209, 202, 82, 170, 242, 215, 238, 215, 236,
+224, 164, 232, 90, 176, 117, 185, 84, 190, 75, 241, 80, 198, 111, 179, 168,
+220, 98, 182, 116, 185, 100, 224, 197, 228, 170, 228, 123, 232, 101, 232, 123,
+191, 251, 191, 254, 235, 228, 238, 209, 193, 228, 194, 232, 241, 102, 243, 101,
+243, 110, 245, 65, 246, 102, 247, 110, 248, 203, 170, 248, 185, 104, 236, 75,
+194, 243, 170, 250, 205, 219, 176, 164, 179, 179, 185, 106, 241, 111, 187, 220,
+220, 168, 192, 75, 243, 124, 249, 173, 173, 178, 232, 179, 194, 254, 248, 79,
+247, 114, 173, 182, 232, 187, 239, 69, 245, 81, 173, 183, 246, 116, 216, 79,
+187, 229, 192, 96, 195, 73, 198, 97, 173, 186, 185, 165, 190, 115, 236, 101,
+195, 77, 245, 93, 247, 126, 249, 195, 176, 169, 245, 102, 187, 236, 241, 188,
+198, 75, 187, 237, 228, 225, 236, 161, 239, 109, 241, 205, 243, 208, 245, 108,
+245, 116, 247, 182, 197, 235, 249, 120, 179, 190, 190, 161, 236, 171, 239, 166,
+241, 219, 243, 227, 245, 126, 246, 191, 197, 195, 247, 196, 249, 124, 179, 191,
+196, 83, 196, 84, 232, 241, 248, 118, 232, 243, 245, 185, 241, 233, 197, 198,
+192, 115, 250, 64, 250, 94, 250, 124, 250, 188, 250, 218, 250, 248, 251, 87,
+251, 117, 251, 181, 251, 211, 251, 241, 252, 80, 252, 110, 252, 174, 252, 204,
+252, 234, 253, 73, 253, 103, 253, 167, 253, 197, 253, 227, 254, 66, 254, 96,
+254, 126, 254, 190, 254, 220, 254, 250, 142, 89, 142, 119, 142, 183, 142, 213,
+142, 243, 143, 82, 143, 112, 143, 176, 143, 206, 143, 236, 144, 75, 144, 105,
+144, 169, 144, 199, 144, 229, 145, 68, 145, 98, 145, 162, 145, 192, 145, 222,
+145, 252, 146, 91, 146, 121, 146, 185, 146, 215, 146, 245, 147, 84, 147, 114,
+147, 178, 147, 208, 147, 238, 148, 77, 148, 107, 148, 171, 148, 201, 148, 231,
+149, 70, 149, 100, 149, 164, 149, 194, 149, 224, 149, 254, 150, 93, 150, 123,
+150, 187, 150, 217, 150, 247, 151, 86, 151, 116, 151, 180, 151, 210, 151, 240,
+152, 79, 152, 109, 152, 173, 152, 203, 152, 233, 153, 72, 153, 102, 153, 166,
+153, 196, 153, 226, 154, 65, 154, 95, 154, 125, 154, 189, 154, 219, 154, 249,
+155, 88, 155, 118, 155, 182, 155, 212, 155, 242, 156, 81, 156, 111, 156, 175,
+156, 205, 156, 235, 157, 74, 157, 104, 157, 168, 157, 198, 157, 228, 158, 67,
+158, 97, 158, 161, 158, 191, 158, 221, 158, 251, 159, 90, 159, 120, 159, 184,
+159, 214, 159, 244, 160, 83, 160, 113, 160, 177, 160, 207, 160, 237, 129, 76,
+129, 106, 129, 170, 129, 200, 129, 230, 130, 69, 130, 99, 130, 163, 130, 193,
+130, 223, 130, 253, 131, 92, 131, 122, 131, 186, 131, 216, 131, 246, 132, 85,
+132, 115, 132, 179, 132, 209, 132, 239, 133, 78, 133, 108, 133, 172, 133, 202,
+133, 232, 134, 71, 134, 101, 134, 165, 134, 195, 134, 225, 135, 64, 135, 94,
+135, 124, 135, 188, 135, 218, 135, 248, 136, 87, 136, 117, 136, 181, 136, 211,
+136, 241, 137, 80, 137, 110, 137, 174, 137, 204, 137, 234, 138, 73, 138, 103,
+138, 167, 138, 197, 138, 227, 139, 66, 139, 96, 139, 126, 139, 190, 139, 220,
+139, 250, 140, 89, 140, 119, 140, 183, 140, 213, 140, 243, 141, 82, 141, 112,
+141, 176, 141, 206, 141, 236, 198, 172, 198, 202, 198, 232, 199, 71, 199, 101,
+199, 165, 199, 195, 199, 225, 200, 64, 200, 94, 200, 124, 200, 188, 200, 218,
+200, 248, 201, 74, 161, 74, 161, 201, 161, 73, 161, 72, 161, 196, 161, 98,
+162, 70
+ });
+
+ super.setUp();
+ }
+
+ @Override
+ public void test_CodecDynamic() throws CharacterCodingException {
+ super.test_CodecDynamic();
+ }
+
+ @Override
+ public void test_Decode() throws CharacterCodingException {
+ super.test_Decode();
+ }
+
+ @Override
+ public void test_Encode() throws CharacterCodingException {
+ super.test_Encode();
+ }
+
+ @Override
+ public void test_nameMatch() {
+ super.test_nameMatch();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByteAbstractTest.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByteAbstractTest.java
new file mode 100644
index 0000000..8ac6eb6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByteAbstractTest.java
@@ -0,0 +1,193 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.CharacterCodingException;
+import java.nio.charset.CodingErrorAction;
+
+/**
+ * Super class for concrete charset test suites.
+ */
+public abstract class OldCharset_SingleByteAbstractTest extends OldCharset_AbstractTest {
+
+ static byte[] allBytes;
+ static char[] allChars;
+
+ @Override
+ protected void setUp() throws Exception {
+ allBytes = new byte[256];
+ for (int i = 0; i < 256; i++) {
+ allBytes[i] = (byte) i;
+ }
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+
+
+ public static void dumpDecoded () {
+ Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1();
+ ByteBuffer inputBB = ByteBuffer.wrap(allBytes);
+ CharBuffer outputCB;
+ decoder.onMalformedInput(CodingErrorAction.REPLACE);
+ try {
+ outputCB = decoder.decode(inputBB);
+ outputCB.rewind();
+ while (outputCB.hasRemaining()) {
+ out.consume(outputCB.get());
+ }
+ } catch (CharacterCodingException e) {
+ System.out.println(e);
+// e.printStackTrace();
+ }
+ }
+
+ public static void decodeReplace (byte[] input, char[] expectedOutput) throws CharacterCodingException {
+ ByteBuffer inputBB = ByteBuffer.wrap(input);
+ CharBuffer outputCB;
+ decoder.onMalformedInput(CodingErrorAction.REPLACE);
+ decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ outputCB = decoder.decode(inputBB);
+ outputCB.rewind();
+ assertEqualChars2("Decoded charactes must match!",
+ expectedOutput,
+ outputCB.array(),
+ input);
+// assertTrue("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
+// Arrays.equals(expectedOutput, outputCB.array()));
+
+// assertEqualChars("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
+// expectedOutput,
+// outputCB.array());
+
+// assertEquals("Decoded charactes must match!",
+// String.valueOf(allChars),
+// outputCB.toString());
+ }
+
+ @Override
+ public void test_Decode () throws CharacterCodingException {
+ decodeReplace(allBytes, allChars);
+// ByteBuffer inputBB = ByteBuffer.wrap(allBytes);
+// CharBuffer outputCB;
+// decoder.onMalformedInput(CodingErrorAction.REPLACE);
+// outputCB = decoder.decode(inputBB);
+// outputCB.rewind();
+// assertEqualChars("Decoded charactes must match!",
+// allChars,
+// outputCB.array());
+//// assertEquals("Decoded charactes must match!",
+//// String.valueOf(allChars),
+//// outputCB.toString());
+ }
+
+ @Override
+ public void test_Encode () throws CharacterCodingException {
+ CharBuffer inputCB = CharBuffer.wrap(allChars);
+ ByteBuffer outputBB;
+ encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
+ outputBB = encoder.encode(inputCB);
+ outputBB.rewind();
+ assertEqualBytes2("Encoded bytes must match!", allBytes, outputBB.array(), allChars);
+ }
+
+// static void assertEqualChars (String msg, char[] expected, char[] actual) {
+// int len = expected.length;
+// if (actual.length < len) len = actual.length;
+// for (int i = 0; i < len; i++) {
+// if (actual[i] != expected[i]) {
+// System.out.format("Mismatch at index %d: %d instead of expected %d.\n",
+// i, (int) actual[i], (int) expected[i]);
+// }
+//// else {
+//// System.out.format("Match index %d: %d = %d\n",
+//// i, (int) actual[i], (int) expected[i]);
+//// }
+// }
+// assertTrue(msg, Arrays.equals(actual, expected));
+// }
+
+ static void assertEqualChars2 (String msg, char[] expected, char[] actual, byte[] bytes) {
+ boolean match = true;
+ boolean replaceMatch = true;
+ int len = expected.length;
+ if (actual.length < len) len = actual.length;
+ for (int i = 0; i < len; i++) {
+ if (actual[i] == expected[i]) {
+ // Fine!
+ }
+ else {
+ if (expected[i] == 65533) {
+ if (actual[i] == (bytes[i] & 0xff)) {
+// System.out.format("REPLACE mismatch at index %d (byte %d): %d instead of expected %d.\n",
+// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
+ } else {
+// System.out.format("REPLACE mismatch at index %d (byte %d): %d instead of expected %d.\n",
+// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
+ }
+ replaceMatch = false;
+ } else {
+// System.out.format("MISMATCH at index %d (byte %d): %d instead of expected %d.\n",
+// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
+ match = false;
+ }
+ }
+// if ((actual[i] != expected[i]) &&
+// !((actual[i] == bytes[i]) && (expected[i] == 65533))) {
+//
+// match = false;
+// }
+ }
+ assertTrue(msg, match);
+ if (!replaceMatch) {
+// System.out.println("for charset " + charsetName);
+ }
+ }
+
+// static void assertEqualBytes (String msg, byte[] expected, byte[] actual) {
+// int len = expected.length;
+// if (actual.length < len) len = actual.length;
+// for (int i = 0; i < len; i++) {
+// if (actual[i] != expected[i]) {
+// System.out.format("MISMATCH at index %d: %d instead of expected %d.\n",
+// i, actual[i], expected[i]);
+// }
+// }
+// assertTrue(msg, Arrays.equals(actual, expected));
+// }
+
+ static void assertEqualBytes2 (String msg, byte[] expected, byte[] actual, char[] chars) {
+ boolean match = true;
+ int len = expected.length;
+ if (actual.length < len) len = actual.length;
+ for (int i = 0; i < len; i++) {
+ if ((actual[i] != expected[i]) &&
+ !((chars[i] == 65533)) && (actual[i] == 63)) {
+// System.out.format("MISMATCH at index %d: %d instead of expected %d.\n",
+// i, actual[i], expected[i]);
+ match = false;
+ }
+ }
+ assertTrue(msg, match);
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_IBM864.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_IBM864.java
new file mode 100644
index 0000000..8698d68
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_IBM864.java
@@ -0,0 +1,79 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_SingleByte_IBM864 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+// charsetName = "IBM864"; // ICU name "cp864", wanted Android name "CP864"
+ charsetName = "cp864"; // ICU name "cp864", wanted Android name "CP864"
+
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28/*26*/, 27, 127/*28*/, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37/*1642*/, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 26/*127*/,
+ 176, 183, 8729, 8730, 9618, 9472, 9474, 9532, 9508, 9516, 9500, 9524, 9488, 9484, 9492, 9496,
+ 946, 8734, 966, 177, 189, 188, 8776, 171, 187, 65271, 65272, 65533, 65533, 65275, 65276, 8203/*65533*/,
+ 160, 173, 65154, 163, 164, 65156, 65533, 65533, 65166, 65167, 65173, 65177, 1548, 65181, 65185, 65189,
+ 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 65233, 1563, 65201, 65205, 65209, 1567,
+ 162, 65152, 65153, 65155, 65157, 65226, 65163, 65165, 65169, 65171, 65175, 65179, 65183, 65187, 65191, 65193,
+ 65195, 65197, 65199, 65203, 65207, 65211, 65215, 65219/*65217*/, 65223/*65221*/, 65227, 65231, 166, 172, 247, 215, 65225,
+ 1600, 65235, 65239, 65243, 65247, 65251, 65255, 65259, 65261, 65263, 65267, 65213, 65228, 65230, 65229, 65249,
+ 65149, 65148/*1617*/, 65253, 65257, 65260, 65264, 65266, 65232, 65237, 65269, 65270, 65245, 65241, 65265, 9632, 65533});
+// allChars = theseChars(new int[]{
+// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+// 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+// 32, 33, 34, 35, 36, 1642, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+// 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+// 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+// 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+// 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+// 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+// 176, 183, 8729, 8730, 9618, 9472, 9474, 9532, 9508, 9516, 9500, 9524, 9488, 9484, 9492, 9496,
+// 946, 8734, 966, 177, 189, 188, 8776, 171, 187, 65271, 65272, 65533, 65533, 65275, 65276, 65533,
+// 160, 173, 65154, 163, 164, 65156, 65533, 65533, 65166, 65167, 65173, 65177, 1548, 65181, 65185, 65189,
+// 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 65233, 1563, 65201, 65205, 65209, 1567,
+// 162, 65152, 65153, 65155, 65157, 65226, 65163, 65165, 65169, 65171, 65175, 65179, 65183, 65187, 65191, 65193,
+// 65195, 65197, 65199, 65203, 65207, 65211, 65215, 65217, 65221, 65227, 65231, 166, 172, 247, 215, 65225,
+// 1600, 65235, 65239, 65243, 65247, 65251, 65255, 65259, 65261, 65263, 65267, 65213, 65228, 65230, 65229, 65249,
+// 65149, 1617, 65253, 65257, 65260, 65264, 65266, 65232, 65237, 65269, 65270, 65245, 65241, 65265, 9632, 65533});
+
+ super.setUp();
+ }
+
+// public static void _test_Bytes_DifferentOnes_RI() throws CharacterCodingException {
+// decodeReplace(
+// theseBytes(new int[]{26, 28, 37, 127, 159, 215, 216, 241}),
+// new char[] {26, 28, 1642, 127, 65533, 65217, 65221, 1617} );
+// }
+
+ public static void test_Bytes_DifferentOnes_Android() throws CharacterCodingException {
+ // Android:
+ decodeReplace(
+ theseBytes(new int[]{26, 28, 37, 127, 159, 215, 216, 241}),
+ new char[] {28, 127, 37, 26, 8203, 65219, 65223, 65148} );
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_1.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_1.java
new file mode 100644
index 0000000..31cede6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_1.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_1 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-1";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+ 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_11.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_11.java
new file mode 100644
index 0000000..7da6da4
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_11.java
@@ -0,0 +1,46 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/* charset x-iso-8859_11-2001 not supported on the RI */
+public class OldCharset_SingleByte_ISO_8859_11 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+// charsetName = "ISO-8859-11";
+ charsetName = "x-iso-8859_11-2001";
+
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599,
+ 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615,
+ 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631,
+ 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 65533, 65533, 65533, 65533, 3647,
+ 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663,
+ 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 65533, 65533, 65533, 65533});
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_13.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_13.java
new file mode 100644
index 0000000..23efed0
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_13.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_13 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-13";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 8221, 162, 163, 164, 8222, 166, 167, 216, 169, 342, 171, 172, 173, 174, 198,
+ 176, 177, 178, 179, 8220, 181, 182, 183, 248, 185, 343, 187, 188, 189, 190, 230,
+ 260, 302, 256, 262, 196, 197, 280, 274, 268, 201, 377, 278, 290, 310, 298, 315,
+ 352, 323, 325, 211, 332, 213, 214, 215, 370, 321, 346, 362, 220, 379, 381, 223,
+ 261, 303, 257, 263, 228, 229, 281, 275, 269, 233, 378, 279, 291, 311, 299, 316,
+ 353, 324, 326, 243, 333, 245, 246, 247, 371, 322, 347, 363, 252, 380, 382, 8217});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_15.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_15.java
new file mode 100644
index 0000000..76eb556
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_15.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_15 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-15";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 161, 162, 163, 8364, 165, 352, 167, 353, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 381, 181, 182, 183, 382, 185, 186, 187, 338, 339, 376, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+ 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_2.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_2.java
new file mode 100644
index 0000000..d51b203
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_2.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_2 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-2";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 260, 728, 321, 164, 317, 346, 167, 168, 352, 350, 356, 377, 173, 381, 379,
+ 176, 261, 731, 322, 180, 318, 347, 711, 184, 353, 351, 357, 378, 733, 382, 380,
+ 340, 193, 194, 258, 196, 313, 262, 199, 268, 201, 280, 203, 282, 205, 206, 270,
+ 272, 323, 327, 211, 212, 336, 214, 215, 344, 366, 218, 368, 220, 221, 354, 223,
+ 341, 225, 226, 259, 228, 314, 263, 231, 269, 233, 281, 235, 283, 237, 238, 271,
+ 273, 324, 328, 243, 244, 337, 246, 247, 345, 367, 250, 369, 252, 253, 355, 729});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_3.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_3.java
new file mode 100644
index 0000000..fe4fbf6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_3.java
@@ -0,0 +1,76 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+import java.nio.charset.CharacterCodingException;
+
+public class OldCharset_SingleByte_ISO_8859_3 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-3";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 294, 728, 163, 164, 65533, 292, 167, 168, 304, 350, 286, 308, 173, 65533, 379,
+ 176, 295, 178, 179, 180, 181, 293, 183, 184, 305, 351, 287, 309, 189, 65533, 380,
+ 192, 193, 194, 65533, 196, 266, 264, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 65533, 209, 210, 211, 212, 288, 214, 215, 284, 217, 218, 219, 220, 364, 348, 223,
+ 224, 225, 226, 65533, 228, 267, 265, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 65533, 241, 242, 243, 244, 289, 246, 247, 285, 249, 250, 251, 252, 365, 349, 729});
+ super.setUp();
+ }
+
+ public static void test_Bytes_166() throws CharacterCodingException {
+ decodeReplace(
+ new byte[] {(byte)166},
+ new char[] {292} );
+// ByteBuffer inputBB = ByteBuffer.wrap(new byte[] {(byte)166});
+// CharBuffer outputCB;
+// decoder.onMalformedInput(CodingErrorAction.REPLACE);
+// System.out.println("test_Bytes_166:");
+// outputCB = decoder.decode(inputBB);
+// outputCB.rewind();
+// assertEqualChars("Decoded charactes must match!",
+// new char[] {292},
+// outputCB.array());
+ }
+
+ public static void test_Bytes_195() throws CharacterCodingException {
+ decodeReplace(
+ new byte[] {(byte)195},
+ new char[] {65533} );
+ }
+
+ public static void test_Bytes_165() throws CharacterCodingException {
+ decodeReplace(
+ new byte[] {(byte)165},
+ new char[] {65533} );
+ }
+
+ public static void test_Bytes_165_any() throws CharacterCodingException {
+ decodeReplace(
+ new byte[] {(byte)165, 32},
+ new char[] {65533, 32} );
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_4.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_4.java
new file mode 100644
index 0000000..dbde77c
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_4.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_4 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-4";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 260, 312, 342, 164, 296, 315, 167, 168, 352, 274, 290, 358, 173, 381, 175,
+ 176, 261, 731, 343, 180, 297, 316, 711, 184, 353, 275, 291, 359, 330, 382, 331,
+ 256, 193, 194, 195, 196, 197, 198, 302, 268, 201, 280, 203, 278, 205, 206, 298,
+ 272, 325, 332, 310, 212, 213, 214, 215, 216, 370, 218, 219, 220, 360, 362, 223,
+ 257, 225, 226, 227, 228, 229, 230, 303, 269, 233, 281, 235, 279, 237, 238, 299,
+ 273, 326, 333, 311, 244, 245, 246, 247, 248, 371, 250, 251, 252, 361, 363, 729});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_5.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_5.java
new file mode 100644
index 0000000..229137c
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_5.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_5 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-5";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 173, 1038, 1039,
+ 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
+ 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071,
+ 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
+ 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103,
+ 8470, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 167, 1118, 1119});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_6.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_6.java
new file mode 100644
index 0000000..294bee5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_6.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_6 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-6";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 65533, 65533, 65533, 164, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 1548, 173, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 1563, 65533, 65533, 65533, 1567,
+ 65533, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583,
+ 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 65533, 65533, 65533, 65533, 65533,
+ 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615,
+ 1616, 1617, 1618, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_7.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_7.java
new file mode 100644
index 0000000..6249b10
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_7.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_7 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-7";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 160, 8216, 8217, 163, 65533, 65533, 166, 167, 168, 169, 65533, 171, 172, 173, 65533, 8213,
+ 176, 177, 178, 179, 900, 901, 902, 183, 904, 905, 906, 187, 908, 189, 910, 911,
+ 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927,
+ 928, 929, 65533, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943,
+ 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959,
+ 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_8.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_8.java
new file mode 100644
index 0000000..e3054f7
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_8.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_8 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-8";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 65533, 162, 163, 164, 165, 166, 167, 168, 169, 215, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 247, 187, 188, 189, 190, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 8215,
+ 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503,
+ 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 65533, 65533, 8206, 8207, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_9.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_9.java
new file mode 100644
index 0000000..c623e23
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_ISO_8859_9.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_ISO_8859_9 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "ISO-8859-9";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 286, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 304, 350, 223,
+ 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 287, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 305, 351, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_KOI8_R.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_KOI8_R.java
new file mode 100644
index 0000000..cb6532e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_KOI8_R.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_KOI8_R extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "KOI8-R";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9600, 9604, 9608, 9612, 9616,
+ 9617, 9618, 9619, 8992, 9632, 8729, 8730, 8776, 8804, 8805, 160, 8993, 176, 178, 183, 247,
+ 9552, 9553, 9554, 1105, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566,
+ 9567, 9568, 9569, 1025, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 169,
+ 1102, 1072, 1073, 1094, 1076, 1077, 1092, 1075, 1093, 1080, 1081, 1082, 1083, 1084, 1085, 1086,
+ 1087, 1103, 1088, 1089, 1090, 1091, 1078, 1074, 1100, 1099, 1079, 1096, 1101, 1097, 1095, 1098,
+ 1070, 1040, 1041, 1062, 1044, 1045, 1060, 1043, 1061, 1048, 1049, 1050, 1051, 1052, 1053, 1054,
+ 1055, 1071, 1056, 1057, 1058, 1059, 1046, 1042, 1068, 1067, 1047, 1064, 1069, 1065, 1063, 1066});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_US_ASCII.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_US_ASCII.java
new file mode 100644
index 0000000..ae15a60
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_US_ASCII.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_US_ASCII extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "US-ASCII";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1250.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1250.java
new file mode 100644
index 0000000..cbb534e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1250.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1250 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1250";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 65533, 8222, 8230, 8224, 8225, 65533, 8240, 352, 8249, 346, 356, 381, 377,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 353, 8250, 347, 357, 382, 378,
+ 160, 711, 728, 321, 164, 260, 166, 167, 168, 169, 350, 171, 172, 173, 174, 379,
+ 176, 177, 731, 322, 180, 181, 182, 183, 184, 261, 351, 187, 317, 733, 318, 380,
+ 340, 193, 194, 258, 196, 313, 262, 199, 268, 201, 280, 203, 282, 205, 206, 270,
+ 272, 323, 327, 211, 212, 336, 214, 215, 344, 366, 218, 368, 220, 221, 354, 223,
+ 341, 225, 226, 259, 228, 314, 263, 231, 269, 233, 281, 235, 283, 237, 238, 271,
+ 273, 324, 328, 243, 244, 337, 246, 247, 345, 367, 250, 369, 252, 253, 355, 729});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1251.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1251.java
new file mode 100644
index 0000000..23f5a31
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1251.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1251 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1251";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 1026, 1027, 8218, 1107, 8222, 8230, 8224, 8225, 8364, 8240, 1033, 8249, 1034, 1036, 1035, 1039,
+ 1106, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 1113, 8250, 1114, 1116, 1115, 1119,
+ 160, 1038, 1118, 1032, 164, 1168, 166, 167, 1025, 169, 1028, 171, 172, 173, 174, 1031,
+ 176, 177, 1030, 1110, 1169, 181, 182, 183, 1105, 8470, 1108, 187, 1112, 1029, 1109, 1111,
+ 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
+ 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071,
+ 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
+ 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1252.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1252.java
new file mode 100644
index 0000000..813219b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1252.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1252 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1252";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 65533, 381, 65533,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 65533, 382, 376,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
+ 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1253.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1253.java
new file mode 100644
index 0000000..c657a8e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1253.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1253 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1253";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 65533, 8240, 65533, 8249, 65533, 65533, 65533, 65533,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 65533, 8250, 65533, 65533, 65533, 65533,
+ 160, 901, 902, 163, 164, 165, 166, 167, 168, 169, 65533, 171, 172, 173, 174, 8213,
+ 176, 177, 178, 179, 900, 181, 182, 183, 904, 905, 906, 187, 908, 189, 910, 911,
+ 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927,
+ 928, 929, 65533, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943,
+ 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959,
+ 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1254.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1254.java
new file mode 100644
index 0000000..5661f1f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1254.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1254 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1254";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 65533, 65533, 65533,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 65533, 65533, 376,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
+ 286, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 304, 350, 223,
+ 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
+ 287, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 305, 351, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1255.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1255.java
new file mode 100644
index 0000000..cb279d5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1255.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1255 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1255";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 65533, 8249, 65533, 65533, 65533, 65533,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 65533, 8250, 65533, 65533, 65533, 65533,
+ 160, 161, 162, 163, 8362, 165, 166, 167, 168, 169, 215, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 247, 187, 188, 189, 190, 191,
+ 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 65533, 1467, 1468, 1469, 1470, 1471,
+ 1472, 1473, 1474, 1475, 1520, 1521, 1522, 1523, 1524, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
+ 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503,
+ 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 65533, 65533, 8206, 8207, 65533});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1256.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1256.java
new file mode 100644
index 0000000..99976b9
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1256.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1256 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1256";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 1662, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 1657, 8249, 338, 1670, 1688, 1672,
+ 1711, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 1705, 8482, 1681, 8250, 339, 8204, 8205, 1722,
+ 160, 1548, 162, 163, 164, 165, 166, 167, 168, 169, 1726, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 1563, 187, 188, 189, 190, 1567,
+ 1729, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583,
+ 1584, 1585, 1586, 1587, 1588, 1589, 1590, 215, 1591, 1592, 1593, 1594, 1600, 1601, 1602, 1603,
+ 224, 1604, 226, 1605, 1606, 1607, 1608, 231, 232, 233, 234, 235, 1609, 1610, 238, 239,
+ 1611, 1612, 1613, 1614, 244, 1615, 1616, 247, 1617, 249, 1618, 251, 252, 8206, 8207, 1746});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1257.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1257.java
new file mode 100644
index 0000000..4f60587
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1257.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1257 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1257";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 65533, 8222, 8230, 8224, 8225, 65533, 8240, 65533, 8249, 65533, 168, 711, 184,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 65533, 8250, 65533, 175, 731, 65533,
+ 160, 65533, 162, 163, 164, 65533, 166, 167, 216, 169, 342, 171, 172, 173, 174, 198,
+ 176, 177, 178, 179, 180, 181, 182, 183, 248, 185, 343, 187, 188, 189, 190, 230,
+ 260, 302, 256, 262, 196, 197, 280, 274, 268, 201, 377, 278, 290, 310, 298, 315,
+ 352, 323, 325, 211, 332, 213, 214, 215, 370, 321, 346, 362, 220, 379, 381, 223,
+ 261, 303, 257, 263, 228, 229, 281, 275, 269, 233, 378, 279, 291, 311, 299, 316,
+ 353, 324, 326, 243, 333, 245, 246, 247, 371, 322, 347, 363, 252, 380, 382, 729});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1258.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1258.java
new file mode 100644
index 0000000..f40e5ff
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_windows_1258.java
@@ -0,0 +1,42 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+public class OldCharset_SingleByte_windows_1258 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+ charsetName = "windows-1258";
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 65533, 8249, 338, 65533, 65533, 65533,
+ 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 65533, 8250, 339, 65533, 65533, 376,
+ 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
+ 192, 193, 194, 258, 196, 197, 198, 199, 200, 201, 202, 203, 768, 205, 206, 207,
+ 272, 209, 777, 211, 212, 416, 214, 215, 216, 217, 218, 219, 220, 431, 771, 223,
+ 224, 225, 226, 259, 228, 229, 230, 231, 232, 233, 234, 235, 769, 237, 238, 239,
+ 273, 241, 803, 243, 244, 417, 246, 247, 248, 249, 250, 251, 252, 432, 8363, 255});
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_x_IBM874.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_x_IBM874.java
new file mode 100644
index 0000000..c6fd869
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_SingleByte_x_IBM874.java
@@ -0,0 +1,46 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU behaves differently from the RI */
+
+public class OldCharset_SingleByte_x_IBM874 extends OldCharset_SingleByteAbstractTest {
+
+ protected void setUp() throws Exception {
+// charsetName = "x-IBM874"; // ICU name "TIS-620", wanted Android name "CP874"
+ charsetName = "TIS-620"; // ICU name "TIS-620", wanted Android name "CP874"
+
+ allChars = theseChars(new int[]{
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+ 8364, 129, 130, 131, 132, 8230, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
+ 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 152, 153, 154, 155, 156, 157, 158, 159,
+ 160, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599,
+ 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615,
+ 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631,
+ 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 63681, 63682, 63683, 63684, 3647,
+ 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663,
+ 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 63685, 63686, 63687, 63688});
+
+ super.setUp();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/nio/charset/OldCharset_macintosh.java b/luni/src/test/java/libcore/java/nio/charset/OldCharset_macintosh.java
new file mode 100644
index 0000000..93f0d1f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/nio/charset/OldCharset_macintosh.java
@@ -0,0 +1,62 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.nio.charset;
+
+/** Note: ICU only */
+public class OldCharset_macintosh extends OldCharset_AbstractTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ charsetName = "macintosh";
+
+ testChars = theseChars(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+160, 161, 162, 163, 165, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 180,
+181, 182, 183, 184, 186, 187, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
+201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
+219, 220, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
+237, 238, 239, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 255,
+305, 338, 376, 710, 937, 8211, 8249, 8364, 8482, 8706, 8747, 8800, 9674, 63743, 64257
+ });
+
+ testBytes = theseBytes(new int[]{
+0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
+32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
+48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
+96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
+202, 193, 162, 163, 180, 164, 172, 169, 187, 199, 194, 168, 248, 161, 177, 171,
+181, 166, 225, 252, 188, 200, 192, 203, 231, 229, 204, 128, 129, 174, 130, 233,
+131, 230, 232, 237, 234, 235, 236, 132, 241, 238, 239, 205, 133, 175, 244, 242,
+243, 134, 167, 136, 135, 137, 139, 138, 140, 190, 141, 143, 142, 144, 145, 147,
+146, 148, 149, 150, 152, 151, 153, 155, 154, 214, 191, 157, 156, 158, 159, 216,
+245, 206, 217, 246, 189, 208, 220, 219, 170, 182, 186, 173, 215, 240, 222
+ });
+
+ super.setUp();
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java
new file mode 100644
index 0000000..be353cc
--- /dev/null
+++ b/luni/src/test/java/libcore/java/security/KeyPairGeneratorTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.security;
+
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.TestCase;
+
+public class KeyPairGeneratorTest extends TestCase {
+
+ public void test_getInstance() throws Exception {
+ Provider[] providers = Security.getProviders();
+ for (Provider provider : providers) {
+ Set<Provider.Service> services = provider.getServices();
+ for (Provider.Service service : services) {
+ String type = service.getType();
+ if (!type.equals("KeyPairGenerator")) {
+ continue;
+ }
+ String algorithm = service.getAlgorithm();
+ try {
+ // KeyPairGenerator.getInstance(String)
+ KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
+ assertEquals(algorithm, kpg1.getAlgorithm());
+ test_KeyPairGenerator(kpg1);
+
+ // KeyPairGenerator.getInstance(String, Provider)
+ KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
+ assertEquals(algorithm, kpg2.getAlgorithm());
+ assertEquals(provider, kpg2.getProvider());
+ test_KeyPairGenerator(kpg2);
+
+ // KeyPairGenerator.getInstance(String, String)
+ KeyPairGenerator kpg3 = KeyPairGenerator.getInstance(algorithm,
+ provider.getName());
+ assertEquals(algorithm, kpg3.getAlgorithm());
+ assertEquals(provider, kpg3.getProvider());
+ test_KeyPairGenerator(kpg3);
+ } catch (Exception e) {
+ throw new Exception("Problem testing KeyPairGenerator." + algorithm, e);
+ }
+ }
+ }
+ }
+
+ private static final Map<String, List<Integer>> KEY_SIZES
+ = new HashMap<String, List<Integer>>();
+ private static void putKeySize(String algorithm, int keySize) {
+ algorithm = algorithm.toUpperCase();
+ List<Integer> keySizes = KEY_SIZES.get(algorithm);
+ if (keySizes == null) {
+ keySizes = new ArrayList<Integer>();
+ KEY_SIZES.put(algorithm, keySizes);
+ }
+ keySizes.add(keySize);
+ }
+ private static List<Integer> getKeySizes(String algorithm) throws Exception {
+ algorithm = algorithm.toUpperCase();
+ List<Integer> keySizes = KEY_SIZES.get(algorithm);
+ if (keySizes == null) {
+ throw new Exception("Unknown key sizes for KeyPairGenerator." + algorithm);
+ }
+ return keySizes;
+ }
+ static {
+ putKeySize("DSA", 512);
+ putKeySize("DSA", 512+64);
+ putKeySize("DSA", 1024);
+ putKeySize("RSA", 512);
+ putKeySize("DH", 512);
+ putKeySize("DH", 512+64);
+ putKeySize("DH", 1024);
+ putKeySize("DiffieHellman", 512);
+ putKeySize("DiffieHellman", 512+64);
+ putKeySize("DiffieHellman", 1024);
+ putKeySize("EC", 256);
+ }
+
+ private void test_KeyPairGenerator(KeyPairGenerator kpg) throws Exception {
+ // without a call to initialize
+ test_KeyPair(kpg, kpg.genKeyPair());
+ test_KeyPair(kpg, kpg.generateKeyPair());
+
+ String algorithm = kpg.getAlgorithm();
+ List<Integer> keySizes = getKeySizes(algorithm);
+ for (int keySize : keySizes) {
+ kpg.initialize(keySize);
+ test_KeyPair(kpg, kpg.genKeyPair());
+ test_KeyPair(kpg, kpg.generateKeyPair());
+
+ kpg.initialize(keySize, (SecureRandom) null);
+ test_KeyPair(kpg, kpg.genKeyPair());
+ test_KeyPair(kpg, kpg.generateKeyPair());
+
+ kpg.initialize(keySize, new SecureRandom());
+ test_KeyPair(kpg, kpg.genKeyPair());
+ test_KeyPair(kpg, kpg.generateKeyPair());
+ }
+ }
+
+ private void test_KeyPair(KeyPairGenerator kpg, KeyPair kp) throws Exception {
+ assertNotNull(kp);
+ test_Key(kpg, kp.getPrivate());
+ test_Key(kpg, kp.getPublic());
+ }
+
+ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
+ String expectedAlgorithm = kpg.getAlgorithm().toUpperCase();
+ if (StandardNames.IS_RI && expectedAlgorithm.equals("DIFFIEHELLMAN")) {
+ expectedAlgorithm = "DH";
+ }
+ assertEquals(expectedAlgorithm, k.getAlgorithm().toUpperCase());
+ assertNotNull(k.getEncoded());
+ assertNotNull(k.getFormat());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/security/KeyStoreTest.java b/luni/src/test/java/libcore/java/security/KeyStoreTest.java
index 072bd6d..17d35de 100644
--- a/luni/src/test/java/libcore/java/security/KeyStoreTest.java
+++ b/luni/src/test/java/libcore/java/security/KeyStoreTest.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.OutputStream;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStore.Builder;
@@ -53,13 +54,9 @@ import junit.framework.TestCase;
public class KeyStoreTest extends TestCase {
private static final PrivateKeyEntry PRIVATE_KEY
- = TestKeyStore.privateKey(TestKeyStore.getServer().keyStore,
- TestKeyStore.getServer().keyPassword,
- "RSA");
+ = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
private static final PrivateKeyEntry PRIVATE_KEY_2
- = TestKeyStore.privateKey(TestKeyStore.getClientCertificate().keyStore,
- TestKeyStore.getClientCertificate().keyPassword,
- "RSA");
+ = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA");
private static final SecretKey SECRET_KEY = generateSecretKey();
private static final SecretKey SECRET_KEY_2 = generateSecretKey();
@@ -91,7 +88,7 @@ public class KeyStoreTest extends TestCase {
private static final ProtectionParameter PARAM_KEY = new PasswordProtection(PASSWORD_KEY);
private static final ProtectionParameter PARAM_BAD = new PasswordProtection(PASSWORD_BAD);
- public static List<KeyStore> keyStores () throws Exception {
+ public static List<KeyStore> keyStores() throws Exception {
List<KeyStore> keyStores = new ArrayList<KeyStore>();
Provider[] providers = Security.getProviders();
for (Provider provider : providers) {
@@ -577,7 +574,8 @@ public class KeyStoreTest extends TestCase {
public void test_KeyStore_getCreationDate() throws Exception {
for (KeyStore keyStore : keyStores()) {
try {
- assertNotNull(keyStore.getCreationDate(null));
+ keyStore.getCreationDate(null);
+ fail();
} catch (KeyStoreException expected) {
}
}
@@ -905,6 +903,7 @@ public class KeyStoreTest extends TestCase {
} else {
try {
keyStore.setCertificateEntry(ALIAS_CERTIFICATE, null);
+ fail();
} catch (KeyStoreException expected) {
}
}
@@ -1245,7 +1244,9 @@ public class KeyStoreTest extends TestCase {
public void assertEqualsKeyStores(File expected, char[] storePassword, KeyStore actual)
throws Exception{
KeyStore ks = KeyStore.getInstance(actual.getType(), actual.getProvider());
- ks.load(new FileInputStream(expected), storePassword);
+ InputStream is = new FileInputStream(expected);
+ ks.load(is, storePassword);
+ is.close();
assertEqualsKeyStores(ks, actual);
}
@@ -1379,7 +1380,7 @@ public class KeyStoreTest extends TestCase {
return null;
}
});
- assertEquals(0, keyStore.size());
+ fail();
} catch (UnsupportedOperationException expected) {
}
}
@@ -1762,6 +1763,7 @@ public class KeyStoreTest extends TestCase {
Builder.newInstance(keyStore.getType(),
keyStore.getProvider(),
null);
+ fail();
} catch (NullPointerException expected) {
}
}
@@ -1806,7 +1808,9 @@ public class KeyStoreTest extends TestCase {
populate(keyStore);
File file = File.createTempFile("keystore", keyStore.getProvider().getName());
try {
- keyStore.store(new FileOutputStream(file), PASSWORD_STORE);
+ OutputStream os = new FileOutputStream(file);
+ keyStore.store(os, PASSWORD_STORE);
+ os.close();
Builder builder = Builder.newInstance(keyStore.getType(),
keyStore.getProvider(),
file,
@@ -1838,12 +1842,14 @@ public class KeyStoreTest extends TestCase {
InputStream in = new FileInputStream(System.getProperty(
"javax.net.ssl.trustStore", "/etc/security/cacerts.bks"));
ks.load(in, null);
+ in.close();
for (String alias : Collections.list(ks.aliases())) {
assert(ks.isCertificateEntry(alias));
Certificate c = ks.getCertificate(alias);
assertTrue(c instanceof X509Certificate);
X509Certificate cert = (X509Certificate) c;
assertEquals(cert.getSubjectUniqueID(), cert.getIssuerUniqueID());
+ assertNotNull(cert.getPublicKey());
}
}
}
diff --git a/luni/src/test/java/libcore/java/security/ProviderTest.java b/luni/src/test/java/libcore/java/security/ProviderTest.java
index 758e3aa..695908b 100644
--- a/luni/src/test/java/libcore/java/security/ProviderTest.java
+++ b/luni/src/test/java/libcore/java/security/ProviderTest.java
@@ -81,7 +81,7 @@ public class ProviderTest extends TestCase {
// original source before giving error
if (!(StandardNames.PROVIDER_ALGORITHMS.containsKey(type)
&& StandardNames.PROVIDER_ALGORITHMS.get(type).contains(algorithm))) {
- extra.add("Unknown " + type + " " + algorithm + "\n");
+ extra.add("Unknown " + type + " " + algorithm + " " + providerName + "\n");
}
}
if (algorithms != null && algorithms.isEmpty()) {
@@ -94,21 +94,24 @@ public class ProviderTest extends TestCase {
true,
provider.getClass().getClassLoader()));
} catch (ClassNotFoundException e) {
- missing.add(className);
+ // Sun forgot their own class
+ if (!className.equals("sun.security.pkcs11.P11MAC")) {
+ missing.add(className);
+ }
}
}
}
// assert that we don't have any extra in the implementation
Collections.sort(extra); // sort so that its grouped by type
- assertEquals(Collections.EMPTY_LIST, extra);
+ assertEquals("Extra algorithms", Collections.EMPTY_LIST, extra);
// assert that we don't have any missing in the implementation
- assertEquals(Collections.EMPTY_MAP, remaining);
+ assertEquals("Missing algorithms", Collections.EMPTY_MAP, remaining);
// assert that we don't have any missing classes
Collections.sort(missing); // sort it for readability
- assertEquals(Collections.EMPTY_LIST, missing);
+ assertEquals("Missing classes", Collections.EMPTY_LIST, missing);
}
private static final Pattern alias = Pattern.compile("Alg\\.Alias\\.([^.]*)\\.(.*)");
@@ -176,7 +179,10 @@ public class ProviderTest extends TestCase {
true,
provider.getClass().getClassLoader()));
} catch (ClassNotFoundException e) {
- fail("Could not find class " + className + " for " + typeAndAlgorithm);
+ // Sun forgot their own class
+ if (!className.equals("sun.security.pkcs11.P11MAC")) {
+ fail("Could not find class " + className + " for " + typeAndAlgorithm);
+ }
}
}
diff --git a/luni/src/test/java/libcore/java/security/SignatureTest.java b/luni/src/test/java/libcore/java/security/SignatureTest.java
new file mode 100644
index 0000000..2688909
--- /dev/null
+++ b/luni/src/test/java/libcore/java/security/SignatureTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.security;
+
+import java.security.Key;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.Signature;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import junit.framework.TestCase;
+
+public class SignatureTest extends TestCase {
+
+ // 20 bytes for DSA
+ private final byte[] DATA = new byte[20];
+
+ public void test_getInstance() throws Exception {
+ Provider[] providers = Security.getProviders();
+ for (Provider provider : providers) {
+ Set<Provider.Service> services = provider.getServices();
+ for (Provider.Service service : services) {
+ String type = service.getType();
+ if (!type.equals("Signature")) {
+ continue;
+ }
+ String algorithm = service.getAlgorithm();
+ try {
+ KeyPair kp = keyPair(algorithm);
+ // Signature.getInstance(String)
+ Signature sig1 = Signature.getInstance(algorithm);
+ assertEquals(algorithm, sig1.getAlgorithm());
+ test_Signature(sig1, kp);
+
+ // Signature.getInstance(String, Provider)
+ Signature sig2 = Signature.getInstance(algorithm, provider);
+ assertEquals(algorithm, sig2.getAlgorithm());
+ assertEquals(provider, sig2.getProvider());
+ test_Signature(sig2, kp);
+
+ // Signature.getInstance(String, String)
+ Signature sig3 = Signature.getInstance(algorithm, provider.getName());
+ assertEquals(algorithm, sig3.getAlgorithm());
+ assertEquals(provider, sig3.getProvider());
+ test_Signature(sig3, kp);
+ } catch (Exception e) {
+ throw new Exception("Problem testing Signature." + algorithm, e);
+ }
+ }
+ }
+ }
+
+ private final Map<String, KeyPair> keypairAlgorithmToInstance
+ = new HashMap<String, KeyPair>();
+
+ private KeyPair keyPair(String sigAlgorithm) throws Exception {
+ if (sigAlgorithm.endsWith("Encryption")) {
+ sigAlgorithm = sigAlgorithm.substring(0, sigAlgorithm.length()-"Encryption".length());
+ }
+
+ String kpAlgorithm;
+ // note ECDSA must be before DSA
+ if (sigAlgorithm.endsWith("ECDSA")) {
+ kpAlgorithm = "EC";
+ } else if (sigAlgorithm.endsWith("DSA")) {
+ kpAlgorithm = "DSA";
+ } else if (sigAlgorithm.endsWith("RSA")) {
+ kpAlgorithm = "RSA";
+ } else {
+ throw new Exception("Unknown KeyPair algorithm for Signature algorithm "
+ + sigAlgorithm);
+ }
+
+ KeyPair kp = keypairAlgorithmToInstance.get(kpAlgorithm);
+ if (kp == null) {
+ kp = KeyPairGenerator.getInstance(kpAlgorithm).generateKeyPair();
+ keypairAlgorithmToInstance.put(sigAlgorithm, kp);
+ }
+ return kp;
+ }
+
+ private void test_Signature(Signature sig, KeyPair keyPair) throws Exception {
+ sig.initSign(keyPair.getPrivate());
+ sig.update(DATA);
+ byte[] signature = sig.sign();
+ assertNotNull(signature);
+ assertTrue(signature.length > 0);
+
+ sig.initVerify(keyPair.getPublic());
+ sig.update(DATA);
+ assertTrue(sig.verify(signature));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/security/cert/PKIXParametersTest.java b/luni/src/test/java/libcore/java/security/cert/PKIXParametersTest.java
new file mode 100644
index 0000000..d0cdf73
--- /dev/null
+++ b/luni/src/test/java/libcore/java/security/cert/PKIXParametersTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.security.cert;
+
+import junit.framework.TestCase;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.cert.PKIXParameters;
+import libcore.java.security.TestKeyStore;
+
+public class PKIXParametersTest extends TestCase {
+
+ public void testKeyStoreConstructor() throws Exception {
+ TestKeyStore server = TestKeyStore.getServer();
+ KeyStore.PrivateKeyEntry pke = server.getPrivateKey("RSA", "RSA");
+ char[] password = "password".toCharArray();
+
+ // contains CA and server certificates
+ assertEquals(2, new PKIXParameters(server.keyStore).getTrustAnchors().size());
+
+ // just copy server certificates
+ KeyStore ks = TestKeyStore.createKeyStore();
+ ks.setKeyEntry("key", pke.getPrivateKey(), password, pke.getCertificateChain());
+ ks.setCertificateEntry("cert", pke.getCertificateChain()[0]);
+ assertEquals(1, new PKIXParameters(ks).getTrustAnchors().size());
+
+ // should fail with just key, even though cert is present in key entry
+ try {
+ KeyStore keyOnly = TestKeyStore.createKeyStore();
+ keyOnly.setKeyEntry("key", pke.getPrivateKey(), password, pke.getCertificateChain());
+ new PKIXParameters(keyOnly);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+
+ // should fail with empty KeyStore
+ try {
+ new PKIXParameters(TestKeyStore.createKeyStore());
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java b/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java
new file mode 100644
index 0000000..7f7cc66
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/OldDriverPropertyInfoTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.util.Properties;
+import junit.framework.TestCase;
+
+public class OldDriverPropertyInfoTest extends TestCase {
+
+ static final String validName = "testname";
+ static final String validValue = "testvalue";
+ static final String connectionURL = "jdbc:sqlite:/" + "Test.db";
+ static final String classname = "SQLite.JDBCDriver";
+
+ public void testDriverPropertyInfoStringString() {
+ DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
+ validName, validValue);
+
+ assertNotNull(aDriverPropertyInfo);
+
+ assertEquals(aDriverPropertyInfo.name,validName);
+ assertEquals(aDriverPropertyInfo.value,validValue);
+
+ aDriverPropertyInfo = new DriverPropertyInfo(null, null);
+
+ assertNotNull(aDriverPropertyInfo);
+ assertNull(aDriverPropertyInfo.name);
+ assertNull(aDriverPropertyInfo.value);
+ }
+
+ public void testPublicFields() throws Exception {
+ Class.forName(classname).newInstance();
+ Properties props = new Properties();
+ Driver d = DriverManager.getDriver(connectionURL);
+ DriverPropertyInfo[] info = d.getPropertyInfo(connectionURL,
+ props);
+ // get the property metadata
+ String name = info[0].name;
+ assertNotNull(name);
+ assertEquals(name, "encoding");
+ String[] choices = info[0].choices;
+ assertNull(choices);
+ boolean required = info[0].required;
+ assertFalse(required);
+ String description = info[0].description;
+ assertNull(description);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/sql/OldTimestampTest.java b/luni/src/test/java/libcore/java/sql/OldTimestampTest.java
new file mode 100644
index 0000000..1bce26d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/sql/OldTimestampTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.sql;
+
+import java.sql.Timestamp;
+import java.util.TimeZone;
+import junit.framework.TestCase;
+
+public class OldTimestampTest extends TestCase {
+
+ public void test_toString() {
+ TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+
+ Timestamp t1 = new Timestamp(Long.MIN_VALUE);
+ assertEquals("292278994-08-17 07:12:55.192", t1.toString());
+
+ Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
+ assertEquals("292278994-08-17 07:12:55.193", t2.toString());
+
+ Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
+ assertEquals("292278994-08-17 07:12:55.999", t3.toString());
+
+ Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
+ assertEquals("292269055-12-02 16:47:05.0", t4.toString());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/text/AttributedCharacterIteratorAttributeTest.java b/luni/src/test/java/libcore/java/text/AttributedCharacterIteratorAttributeTest.java
new file mode 100644
index 0000000..9119582
--- /dev/null
+++ b/luni/src/test/java/libcore/java/text/AttributedCharacterIteratorAttributeTest.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.text;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.text.AttributedCharacterIterator;
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import junit.framework.TestCase;
+
+/**
+ * AttributedCharacterIterator.Attribute is used like the base enum type and
+ * subclassed by unrelated classes.
+ */
+public final class AttributedCharacterIteratorAttributeTest extends TestCase {
+
+ public void testSerialization() throws IOException, ClassNotFoundException {
+ assertSameReserialized(AttributedCharacterIterator.Attribute.LANGUAGE);
+ assertSameReserialized(DateFormat.Field.ERA);
+ assertSameReserialized(DateFormat.Field.TIME_ZONE);
+ assertSameReserialized(NumberFormat.Field.INTEGER);
+ }
+
+ public void testSerializingSubclass() throws IOException, ClassNotFoundException {
+ AttributedCharacterIterator.Attribute a = new CustomAttribute();
+ try {
+ reserialize(a);
+ fail();
+ } catch (InvalidObjectException expected) {
+ }
+ }
+
+ private void assertSameReserialized(Object o) throws ClassNotFoundException, IOException {
+ assertSame(o, reserialize(o));
+ }
+
+ private Object reserialize(Object o) throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ new ObjectOutputStream(out).writeObject(o);
+ InputStream in = new ByteArrayInputStream(out.toByteArray());
+ return new ObjectInputStream(in).readObject();
+ }
+
+ private static class CustomAttribute extends AttributedCharacterIterator.Attribute {
+ public CustomAttribute() {
+ super("a");
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/text/CollatorTest.java b/luni/src/test/java/libcore/java/text/CollatorTest.java
index 844af5b..78cb6f0 100644
--- a/luni/src/test/java/libcore/java/text/CollatorTest.java
+++ b/luni/src/test/java/libcore/java/text/CollatorTest.java
@@ -92,9 +92,7 @@ public class CollatorTest extends junit.framework.TestCase {
RuleBasedCollator coll = new RuleBasedCollator(rule);
assertEquals(Collator.TERTIARY, coll.getStrength());
- // This is a harmony test, but it assumes that RuleBasedCollators default to
- // NO_DECOMPOSITION, which isn't true on Android.
- // assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
+ assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition());
RuleBasedCollator other = new RuleBasedCollator(rule);
assertTrue(coll.equals(other));
diff --git a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
index a4012a8..4da54e6 100644
--- a/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/OldSimpleDateFormatTest.java
@@ -408,12 +408,6 @@ public class OldSimpleDateFormatTest extends junit.framework.TestCase {
assertFalse(test.testsFailed);
}
- public void testDefaultMinimalDaysInFirstWeek() {
- Locale.setDefault(Locale.US);
- assertEquals(1, new GregorianCalendar().getMinimalDaysInFirstWeek());
- assertEquals(1, new GregorianCalendar().getFirstDayOfWeek());
- }
-
/**
* @tests java.text.SimpleDateFormat#format(java.util.Date)
*/
diff --git a/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java b/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
index 5df96f8..78445bc 100644
--- a/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
@@ -16,6 +16,7 @@
package libcore.java.text;
+import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@@ -71,7 +72,9 @@ public class SimpleDateFormatTest extends junit.framework.TestCase {
}
private String formatDate(Locale l, String fmt) {
- return new SimpleDateFormat(fmt, l).format(new Date(0));
+ DateFormat dateFormat = new SimpleDateFormat(fmt, l);
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return dateFormat.format(new Date(0));
}
private Calendar parseDate(Locale l, String fmt, String value) {
diff --git a/luni/src/test/java/libcore/java/util/OldAndroidArrayListTest.java b/luni/src/test/java/libcore/java/util/OldAndroidArrayListTest.java
new file mode 100644
index 0000000..eeaa3b3
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldAndroidArrayListTest.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import junit.framework.TestCase;
+
+import java.util.ArrayList;
+
+/**
+ * This test case tests several often used functionality of ArrayLists.
+ */
+public class OldAndroidArrayListTest extends TestCase {
+
+ @SuppressWarnings("unchecked")
+ public void testArrayList() throws Exception {
+ ArrayList array = new ArrayList();
+ assertEquals(0, array.size());
+ assertTrue(array.isEmpty());
+
+ array.add(new Integer(0));
+ array.add(0, new Integer(1));
+ array.add(1, new Integer(2));
+ array.add(new Integer(3));
+ array.add(new Integer(1));
+
+ assertEquals(5, array.size());
+ assertFalse(array.isEmpty());
+
+ assertEquals(1, ((Integer) array.get(0)).intValue());
+ assertEquals(2, ((Integer) array.get(1)).intValue());
+ assertEquals(0, ((Integer) array.get(2)).intValue());
+ assertEquals(3, ((Integer) array.get(3)).intValue());
+ assertEquals(1, ((Integer) array.get(4)).intValue());
+
+ assertFalse(array.contains(null));
+ assertTrue(array.contains(new Integer(2)));
+ assertEquals(0, array.indexOf(new Integer(1)));
+ assertEquals(4, array.lastIndexOf(new Integer(1)));
+ assertTrue(array.indexOf(new Integer(5)) < 0);
+ assertTrue(array.lastIndexOf(new Integer(5)) < 0);
+
+ array.remove(1);
+ array.remove(1);
+
+ assertEquals(3, array.size());
+ assertFalse(array.isEmpty());
+ assertEquals(1, ((Integer) array.get(0)).intValue());
+ assertEquals(3, ((Integer) array.get(1)).intValue());
+ assertEquals(1, ((Integer) array.get(2)).intValue());
+
+ assertFalse(array.contains(null));
+ assertFalse(array.contains(new Integer(2)));
+ assertEquals(0, array.indexOf(new Integer(1)));
+ assertEquals(2, array.lastIndexOf(new Integer(1)));
+ assertTrue(array.indexOf(new Integer(5)) < 0);
+ assertTrue(array.lastIndexOf(new Integer(5)) < 0);
+
+ array.clear();
+
+ assertEquals(0, array.size());
+ assertTrue(array.isEmpty());
+ assertTrue(array.indexOf(new Integer(5)) < 0);
+ assertTrue(array.lastIndexOf(new Integer(5)) < 0);
+
+ ArrayList al = new ArrayList();
+
+ assertFalse(al.remove(null));
+ assertFalse(al.remove("string"));
+
+ al.add("string");
+ al.add(null);
+
+ assertTrue(al.remove(null));
+ assertTrue(al.remove("string"));
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/OldAndroidHashMapTest.java b/luni/src/test/java/libcore/java/util/OldAndroidHashMapTest.java
new file mode 100644
index 0000000..abe419a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldAndroidHashMapTest.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import java.util.HashMap;
+import junit.framework.TestCase;
+
+public final class OldAndroidHashMapTest extends TestCase {
+
+ private static final Integer ONE = 1;
+ private static final Integer TWO = 2;
+ private static final Integer THREE = 3;
+ private static final Integer FOUR = 4;
+
+ private void addItems(HashMap<String, Integer> map) {
+ map.put("one", ONE);
+ map.put("two", TWO);
+ map.put("three", THREE);
+ map.put("four", FOUR);
+
+ assertEquals(4, map.size());
+
+ assertEquals(ONE, map.get("one"));
+ assertEquals(TWO, map.get("two"));
+ assertEquals(THREE, map.get("three"));
+ assertEquals(FOUR, map.get("four"));
+ }
+
+ public void testAdd() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+ addItems(map);
+ }
+
+ public void testClear() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ addItems(map);
+ map.clear();
+ assertEquals(0, map.size());
+ }
+
+ public void testRemove() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ addItems(map);
+ map.remove("three");
+ assertNull(map.get("three"));
+ }
+
+ public void testManipulate() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ assertTrue(map.isEmpty());
+ assertEquals(0, map.size());
+ assertNull(map.get(null));
+ assertNull(map.get("one"));
+ assertFalse(map.containsKey("one"));
+ assertFalse(map.containsValue(new Integer(1)));
+ assertNull(map.remove(null));
+ assertNull(map.remove("one"));
+
+ assertNull(map.put(null, -1));
+ assertNull(map.put("one", 1));
+ assertNull(map.put("two", 2));
+ assertNull(map.put("three", 3));
+ assertEquals(-1, map.put(null, 0).intValue());
+
+ assertEquals(0, map.get(null).intValue());
+ assertEquals(1, map.get("one").intValue());
+ assertEquals(2, map.get("two").intValue());
+ assertEquals(3, map.get("three").intValue());
+
+ assertTrue(map.containsKey(null));
+ assertTrue(map.containsKey("one"));
+ assertTrue(map.containsKey("two"));
+ assertTrue(map.containsKey("three"));
+
+ assertTrue(map.containsValue(new Integer(0)));
+ assertTrue(map.containsValue(new Integer(1)));
+ assertTrue(map.containsValue(new Integer(2)));
+ assertTrue(map.containsValue(new Integer(3)));
+
+ assertEquals(0, map.remove(null).intValue());
+ assertEquals(1, map.remove("one").intValue());
+ assertEquals(2, map.remove("two").intValue());
+ assertEquals(3, map.remove("three").intValue());
+
+ assertTrue(map.isEmpty());
+ assertEquals(0, map.size());
+ assertNull(map.get(null));
+ assertNull(map.get("one"));
+ assertFalse(map.containsKey("one"));
+ assertFalse(map.containsValue(new Integer(1)));
+ assertNull(map.remove(null));
+ assertNull(map.remove("one"));
+ }
+
+ public void testKeyIterator() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ boolean[] slots = new boolean[4];
+
+ addItems(map);
+
+ for (String s : map.keySet()) {
+ int slot = 0;
+
+ if (s.equals("one")) {
+ slot = 0;
+ } else if (s.equals("two")) {
+ slot = 1;
+ } else if (s.equals("three")) {
+ slot = 2;
+ } else if (s.equals("four")) {
+ slot = 3;
+ } else {
+ fail("Unknown key in HashMap");
+ }
+
+ if (slots[slot]) {
+ fail("key returned more than once");
+ } else {
+ slots[slot] = true;
+ }
+ }
+
+ assertTrue(slots[0]);
+ assertTrue(slots[1]);
+ assertTrue(slots[2]);
+ assertTrue(slots[3]);
+ }
+
+ public void testValueIterator() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ boolean[] slots = new boolean[4];
+
+ addItems(map);
+
+ for (Object o : map.values()) {
+ int slot = 0;
+
+ if (o.equals(ONE)) {
+ slot = 0;
+ } else if (o.equals(TWO)) {
+ slot = 1;
+ } else if (o.equals(THREE)) {
+ slot = 2;
+ } else if (o.equals(FOUR)) {
+ slot = 3;
+ } else {
+ fail("Unknown value in HashMap");
+ }
+
+ if (slots[slot]) {
+ fail("value returned more than once");
+ } else {
+ slots[slot] = true;
+ }
+ }
+
+ assertTrue(slots[0]);
+ assertTrue(slots[1]);
+ assertTrue(slots[2]);
+ assertTrue(slots[3]);
+ }
+
+ public void testEntryIterator() throws Exception {
+ HashMap<String, Integer> map = new HashMap<String, Integer>();
+
+ boolean[] slots = new boolean[4];
+
+ addItems(map);
+
+ for (Object o : map.entrySet()) {
+ int slot = 0;
+
+ if (o.toString().equals("one=1")) {
+ slot = 0;
+ } else if (o.toString().equals("two=2")) {
+ slot = 1;
+ } else if (o.toString().equals("three=3")) {
+ slot = 2;
+ } else if (o.toString().equals("four=4")) {
+ slot = 3;
+ } else {
+ fail("Unknown entry in HashMap");
+ }
+
+ if (slots[slot]) {
+ fail("entry returned more than once");
+ } else {
+ slots[slot] = true;
+ }
+ }
+
+ assertTrue(slots[0]);
+ assertTrue(slots[1]);
+ assertTrue(slots[2]);
+ assertTrue(slots[3]);
+ }
+
+ public void testEquals() throws Exception {
+ HashMap<String, String> map1 = new HashMap<String, String>();
+ HashMap<String, String> map2 = new HashMap<String, String>();
+ HashMap<String, String> map3 = new HashMap<String, String>();
+
+ map1.put("one", "1");
+ map1.put("two", "2");
+ map1.put("three", "3");
+
+ map2.put("one", "1");
+ map2.put("two", "2");
+ map2.put("three", "3");
+
+ assertTrue(map1.equals(map2));
+
+ map3.put("one", "1");
+ map3.put("two", "1");
+ map3.put("three", "1");
+
+ assertFalse(map1.equals(map3));
+ assertFalse(map2.equals(map3));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/OldAndroidLocaleTest.java b/luni/src/test/java/libcore/java/util/OldAndroidLocaleTest.java
new file mode 100644
index 0000000..547b70a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldAndroidLocaleTest.java
@@ -0,0 +1,231 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import java.nio.charset.Charset;
+import java.text.DateFormatSymbols;
+import java.util.Calendar;
+import java.util.Currency;
+import java.util.Locale;
+import java.util.Set;
+import java.util.TimeZone;
+import junit.framework.TestCase;
+
+/**
+ * Test some locale-dependent stuff for Android. This test mainly ensures that
+ * our ICU configuration is correct and contains all the needed locales and
+ * resource bundles.
+ */
+public class OldAndroidLocaleTest extends TestCase {
+
+ // Test basic Locale infrastructure.
+ public void testLocale() throws Exception {
+ Locale locale = new Locale("en");
+ assertEquals("en", locale.toString());
+
+ locale = new Locale("en", "US");
+ assertEquals("en_US", locale.toString());
+
+ locale = new Locale("en", "", "POSIX");
+ assertEquals("en__POSIX", locale.toString());
+
+ locale = new Locale("en", "US", "POSIX");
+ assertEquals("en_US_POSIX", locale.toString());
+ }
+
+ /*
+ * Tests some must-have locales. TODO: Add back "de". See discussion
+ * immediately below this method.
+ */
+ public void testResourceBundles() throws Exception {
+ Locale eng = new Locale("en", "US");
+ DateFormatSymbols engSymbols = new DateFormatSymbols(eng);
+
+ //Locale deu = new Locale("de", "DE");
+ //DateFormatSymbols deuSymbols = new DateFormatSymbols(deu);
+
+ TimeZone berlin = TimeZone.getTimeZone("Europe/Berlin");
+
+ assertEquals("January", engSymbols.getMonths()[0]);
+ //assertEquals("Januar", deuSymbols.getMonths()[0]);
+
+ assertEquals("Sunday", engSymbols.getWeekdays()[Calendar.SUNDAY]);
+ //assertEquals("Sonntag", deuSymbols.getWeekdays()[Calendar.SUNDAY]);
+
+ assertEquals("Central European Time",
+ berlin.getDisplayName(false, TimeZone.LONG, eng));
+ assertEquals("Central European Summer Time",
+ berlin.getDisplayName(true, TimeZone.LONG, eng));
+
+ //assertEquals("Mitteleurop\u00E4ische Zeit",
+ // berlin.getDisplayName(false, TimeZone.LONG, deu));
+ //assertEquals("Mitteleurop\u00E4ische Sommerzeit",
+ // berlin.getDisplayName(true, TimeZone.LONG, deu));
+
+ assertTrue(engSymbols.getZoneStrings().length > 100);
+ }
+
+ /*
+ * Disabled version of the above test. The version above omits
+ * checks for stuff in the "de" locale, because we stripped that
+ * out as part of the flash reduction effort (so that we could
+ * still ship on Dream). We expect to have a baseline target that
+ * includes a large enough system partition to include "de"
+ * immediately after the last official release for Dream (whenever
+ * that may be).
+ *
+ // Test some must-have locales.
+ @LargeTest
+ public void testResourceBundles() throws Exception {
+ Locale eng = new Locale("en", "US");
+ DateFormatSymbols engSymbols = new DateFormatSymbols(eng);
+
+ Locale deu = new Locale("de", "DE");
+ DateFormatSymbols deuSymbols = new DateFormatSymbols(deu);
+
+ TimeZone berlin = TimeZone.getTimeZone("Europe/Berlin");
+
+ assertEquals("January", engSymbols.getMonths()[0]);
+ assertEquals("Januar", deuSymbols.getMonths()[0]);
+
+ assertEquals("Sunday", engSymbols.getWeekdays()[Calendar.SUNDAY]);
+ assertEquals("Sonntag", deuSymbols.getWeekdays()[Calendar.SUNDAY]);
+
+ assertEquals("Central European Time",
+ berlin.getDisplayName(false, TimeZone.LONG, eng));
+ assertEquals("Central European Summer Time",
+ berlin.getDisplayName(true, TimeZone.LONG, eng));
+
+ assertEquals("Mitteleurop\u00E4ische Zeit",
+ berlin.getDisplayName(false, TimeZone.LONG, deu));
+ assertEquals("Mitteleurop\u00E4ische Sommerzeit",
+ berlin.getDisplayName(true, TimeZone.LONG, deu));
+
+ assertTrue(engSymbols.getZoneStrings().length > 100);
+ }
+ */
+
+ // This one makes sure we have all necessary locales installed.
+ // Suppress this flaky test for now.
+ public void testICULocales() {
+ String[] locales = new String[] {
+ // List of locales currently required for Android.
+ "en_US", "es_US", "en_GB", "fr_FR", "de_DE", "de_AT", "cs_CZ", "nl_NL" };
+
+ String[] mondays = new String[] {
+ "Monday", "lunes", "Monday", "lundi", "Montag", "Montag", "pond\u011bl\u00ed", "maandag" };
+
+ String[] currencies = new String[] {
+ "USD", "USD", "GBP", "EUR", "EUR", "EUR", "CZK", "EUR"};
+
+ for (int i = 0; i < locales.length; i++) {
+ Locale l = new Locale(locales[i].substring(0, 2), locales[i].substring(3));
+
+ // Check language part of locale.
+ DateFormatSymbols d = new DateFormatSymbols(l);
+ assertEquals("Monday name for " + locales[i] + " must match",
+ mondays[i], d.getWeekdays()[2]);
+
+ // Check country part of locale.
+ Currency c = Currency.getInstance(l);
+ assertEquals("Currency code for " + locales[i] + " must match",
+ currencies[i], c.getCurrencyCode());
+ }
+ }
+
+ // Regression test for 1118570: Create test cases for tracking ICU config
+ // changes. This one makes sure we have the necessary converters installed
+ // and don't lose the changes to the converter alias table.
+ public void testICUConverters() {
+ // List of encodings currently required for Android.
+ String[] encodings = new String[] {
+ // Encoding required by the language specification.
+ "US-ASCII",
+ "UTF-8",
+ "UTF-16",
+ "UTF-16BE",
+ "UTF-16LE",
+ "ISO-8859-1",
+
+ // Additional encodings included in standard ICU
+ "ISO-8859-2",
+ "ISO-8859-3",
+ "ISO-8859-4",
+ "ISO-8859-5",
+ "ISO-8859-6",
+ "ISO-8859-7",
+ "ISO-8859-8",
+ "ISO-8859-8-I",
+ "ISO-8859-9",
+ "ISO-8859-10",
+ "ISO-8859-11",
+ "ISO-8859-13",
+ "ISO-8859-14",
+ "ISO-8859-15",
+ "ISO-8859-16",
+ "ISO-2022-JP",
+ "Windows-950",
+ "Windows-1250",
+ "Windows-1251",
+ "Windows-1252",
+ "Windows-1253",
+ "Windows-1254",
+ "Windows-1255",
+ "Windows-1256",
+ "Windows-1257",
+ "Windows-1258",
+ "Big5",
+ "CP864",
+ "CP874",
+ "EUC-CN",
+ "EUC-JP",
+ "KOI8-R",
+ "Macintosh",
+ "GBK",
+ "GB2312",
+ "EUC-KR",
+
+ // Additional encoding not included in standard ICU.
+ "GSM0338" };
+
+ for (int i = 0; i < encodings.length; i++) {
+ assertTrue("Charset " + encodings[i] + " must be supported",
+ Charset.isSupported(encodings[i]));
+
+ Charset cs = Charset.forName(encodings[i]);
+
+ Set<String> aliases = cs.aliases();
+ System.out.println(aliases);
+ }
+
+ // Test for valid encoding that is not included in Android. IBM-37 is
+ // a perfect candidate for this, as it is being used for mainframes and
+ // thus somewhat out of the scope of Android.
+ assertFalse("Charset IBM-37 must not be supported",
+ Charset.isSupported("IBM-37"));
+
+ // Test for a bogus encoding.
+ assertFalse("Charset KLINGON must not be supported",
+ Charset.isSupported("KLINGON"));
+
+ // Make sure our local change to the real translation table used for
+ // EUC-JP doesn't get lost.
+ Charset cs = Charset.forName("EUC-JP");
+ assertTrue("EUC-JP must use 'ibm-954_P101-2007'", cs.aliases().contains("ibm-954_P101-2007"));
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/util/OldAndroidTreeMapTest.java b/luni/src/test/java/libcore/java/util/OldAndroidTreeMapTest.java
new file mode 100644
index 0000000..5279918
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldAndroidTreeMapTest.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util;
+
+import junit.framework.TestCase;
+
+import java.util.HashMap;
+import java.util.Random;
+import java.util.TreeMap;
+
+/**
+ * Tests for basic functinality of TreeMaps
+ */
+public class OldAndroidTreeMapTest extends TestCase {
+
+ private Random mRandom = new Random(1);
+
+ private static final boolean SPEW = false;
+
+ public void testTreeMap() {
+ for (int i = 0; i < 10; i++) {
+ if (SPEW) System.out.println("Running doTest cycle #" + (i + 1));
+ doTest();
+ }
+ }
+
+ private void doTest() {
+ TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
+ HashMap<Integer, String> hm = new HashMap<Integer, String>();
+
+ int minVal = Integer.MAX_VALUE;
+ int maxVal = Integer.MIN_VALUE;
+
+ for (int i = 0; i < 100; i++) {
+ int val = mRandom.nextInt(1000);
+ if (SPEW) System.out.println("Adding val = " + val);
+ if (val < minVal) {
+ minVal = val;
+ }
+ if (val > maxVal) {
+ maxVal = val;
+ }
+ tm.put(new Integer(val), "V:" + val);
+ hm.put(new Integer(val), "V:" + val);
+
+ if (SPEW) System.out.println("tm = " + tm);
+
+ if (SPEW) System.out.println("tm.size() = " + tm.size());
+ if (SPEW) System.out.println("hm.size() = " + hm.size());
+ assertEquals(tm.size(), hm.size());
+
+ if (SPEW) System.out.println("tm.firstKey() = " + tm.firstKey());
+ if (SPEW) System.out.println("minVal = " + minVal);
+ if (SPEW) System.out.println("tm.lastKey() = " + tm.lastKey());
+ if (SPEW) System.out.println("maxVal = " + maxVal);
+ assertEquals(minVal, tm.firstKey().intValue());
+ assertEquals(maxVal, tm.lastKey().intValue());
+ }
+
+ // Check for equality
+ for (int val = 0; val < 1000; val++) {
+ Integer vv = new Integer(val);
+ String tms = tm.get(vv);
+ String hms = hm.get(vv);
+ assertEquals(tms, hms);
+ }
+
+ for (int i = 0; i < 1000; i++) {
+ int val = mRandom.nextInt(1000);
+ if (SPEW) System.out.println("Removing val = " + val);
+
+ String tms = tm.remove(new Integer(val));
+ String hms = hm.remove(new Integer(val));
+
+ if (SPEW) System.out.println("tm = " + tm);
+
+ assertEquals(tm.size(), hm.size());
+ assertEquals(tms, hms);
+ }
+
+ // Check for equality
+ for (int val = 0; val < 1000; val++) {
+ Integer vv = new Integer(val);
+ String tms = tm.get(vv);
+ String hms = hm.get(vv);
+ assertEquals(tms, hms);
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/OldScannerTest.java b/luni/src/test/java/libcore/java/util/OldScannerTest.java
new file mode 100644
index 0000000..b51cfbc
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/OldScannerTest.java
@@ -0,0 +1,559 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.util;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.InetSocketAddress;
+import java.nio.CharBuffer;
+import java.nio.channels.IllegalBlockingModeException;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+import java.util.Scanner;
+import java.util.regex.MatchResult;
+import java.util.regex.Pattern;
+import junit.framework.TestCase;
+import tests.support.Support_PortManager;
+
+public final class OldScannerTest extends TestCase {
+
+ private Scanner s;
+
+ public void test_findWithinHorizon_Ljava_lang_StringI() {
+ // This method searches through the input up to the specified search
+ // horizon(exclusive).
+ s = new Scanner("123test");
+ String result = s.findWithinHorizon("\\p{Lower}", 5);
+ assertEquals("t", result);
+ MatchResult mresult = s.match();
+ assertEquals(3, mresult.start());
+ assertEquals(4, mresult.end());
+
+ s = new Scanner("12345test1234test next");
+ /*
+ * If the pattern is found the scanner advances past the input that
+ * matched and returns the string that matched the pattern.
+ */
+ result = s.findWithinHorizon("\\p{Digit}+", 2);
+ assertEquals("12", result);
+ mresult = s.match();
+ assertEquals(0, mresult.start());
+ assertEquals(2, mresult.end());
+ // Position is now pointing at the bar. "12|345test1234test next"
+
+ result = s.findWithinHorizon("\\p{Digit}+", 6);
+ assertEquals("345", result);
+
+ mresult = s.match();
+ assertEquals(2, mresult.start());
+ assertEquals(5, mresult.end());
+ // Position is now pointing at the bar. "12345|test1234test next"
+
+ // If no such pattern is detected then the null is returned and the
+ // scanner's position remains unchanged.
+ result = s.findWithinHorizon("\\p{Digit}+", 3);
+ assertNull(result);
+
+ try {
+ s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ assertEquals("345", mresult.group());
+ assertEquals(2, mresult.start());
+ assertEquals(5, mresult.end());
+ // Position is now still pointing at the bar. "12345|test1234test next"
+
+ // If horizon is 0, then the horizon is ignored and this method
+ // continues to search through the input looking for the specified
+ // pattern without bound.
+ result = s.findWithinHorizon("\\p{Digit}+", 0);
+ mresult = s.match();
+ assertEquals(9, mresult.start());
+ assertEquals(13, mresult.end());
+ // Position is now pointing at the bar. "12345test1234|test next"
+
+ assertEquals("test", s.next());
+ mresult = s.match();
+ assertEquals(13, mresult.start());
+ assertEquals(17, mresult.end());
+
+ assertEquals("next", s.next());
+ mresult = s.match();
+ assertEquals(18, mresult.start());
+ assertEquals(22, mresult.end());
+
+ try {
+ s.findWithinHorizon((String)null, 1);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ try {
+ s.findWithinHorizon("\\p{Digit}+", -1);
+ fail("Should throw IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+
+ s.close();
+ // on RI throws NullPointerException
+ /*
+ * try { System.out.println("fsdfs"); s.findWithinHorizon((String) null,
+ * -1); System.out.println("fsdfs"); fail("Should throw
+ * IllegalStateException"); } catch (IllegalStateException e) { //
+ * expected }
+ */
+ s = new Scanner("test");
+ result = s.findWithinHorizon("\\w+", 10);
+ assertEquals("test", result);
+
+ s = new Scanner("aa\n\rb");
+ String patternStr = "^(a)$";
+ result = s.findWithinHorizon("a", 5);
+ assertEquals("a", result);
+ mresult = s.match();
+ assertEquals(0, mresult.start());
+ assertEquals(1, mresult.end());
+
+ result = s.findWithinHorizon(patternStr, 5);
+ assertNull(result);
+
+ try {
+ mresult = s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ s = new Scanner("");
+ result = s.findWithinHorizon("^", 0);
+ assertEquals("", result);
+ MatchResult matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(0, matchResult.end());
+
+ result = s.findWithinHorizon("$", 0);
+ assertEquals("", result);
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(0, matchResult.end());
+
+ s = new Scanner("1 fish 2 fish red fish blue fish");
+ result = s.findWithinHorizon("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)", 10);
+ assertNull(result);
+
+ try {
+ mresult = s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ assertEquals(0, mresult.groupCount());
+
+ result = s.findWithinHorizon("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)", 100);
+ assertEquals("1 fish 2 fish red fish blue", result);
+ mresult = s.match();
+ assertEquals(4, mresult.groupCount());
+ assertEquals("1", mresult.group(1));
+ assertEquals("2", mresult.group(2));
+ assertEquals("red", mresult.group(3));
+ assertEquals("blue", mresult.group(4));
+
+ s = new Scanner("test");
+ s.close();
+ try {
+ s.findWithinHorizon("test", 1);
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ s = new Scanner("word1 WorD2 ");
+ s.close();
+ try {
+ s.findWithinHorizon("\\d+", 10);
+ fail("should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ s = new Scanner("word1 WorD2 wOrd3 ");
+ patternStr = "\\d+";
+ assertEquals("1", s.findWithinHorizon(patternStr, 10));
+ assertEquals("WorD2", s.next());
+ assertEquals("3", s.findWithinHorizon(patternStr, 15));
+
+ // Regression test
+ s = new Scanner(new MockStringReader("MockStringReader"));
+ patternStr = "test";
+ result = s.findWithinHorizon(patternStr, 10);
+ assertEquals("test", result);
+
+ // Test the situation when input length is longer than buffer size.
+ StringBuilder stringBuilder = new StringBuilder();
+ for (int i = 0; i < 1026; i++) {
+ stringBuilder.append('a');
+ }
+ s = new Scanner(stringBuilder.toString());
+ patternStr = "\\p{Lower}+";
+ result = s.findWithinHorizon(patternStr, 1026);
+ assertEquals(stringBuilder.toString(), result);
+
+ // Test the situation when input length is longer than buffer size and
+ // set horizon to buffer size.
+ stringBuilder = new StringBuilder();
+ for (int i = 0; i < 1026; i++) {
+ stringBuilder.append('a');
+ }
+ s = new Scanner(stringBuilder.toString());
+ patternStr = "\\p{Lower}+";
+ result = s.findWithinHorizon(patternStr, 1022);
+ assertEquals(1022, result.length());
+ assertEquals(stringBuilder.subSequence(0, 1022), result);
+
+ // Test the situation, under which pattern is clipped by buffer.
+ stringBuilder = new StringBuilder();
+ for (int i = 0; i < 1022; i++) {
+ stringBuilder.append(' ');
+ }
+ stringBuilder.append("bbc");
+ assertEquals(1025, stringBuilder.length());
+ s = new Scanner(stringBuilder.toString());
+ patternStr = "bbc";
+ result = s.findWithinHorizon(patternStr, 1025);
+ assertEquals(3, result.length());
+ assertEquals(stringBuilder.subSequence(1022, 1025), result);
+
+ stringBuilder = new StringBuilder();
+ for (int i = 0; i < 1026; i++) {
+ stringBuilder.append('a');
+ }
+ s = new Scanner(stringBuilder.toString());
+ patternStr = "\\p{Lower}+";
+ result = s.findWithinHorizon(patternStr, 0);
+ assertEquals(stringBuilder.toString(), result);
+
+ stringBuilder = new StringBuilder();
+ for (int i = 0; i < 10240; i++) {
+ stringBuilder.append('-');
+ }
+ stringBuilder.replace(0, 2, "aa");
+ s = new Scanner(stringBuilder.toString());
+ result = s.findWithinHorizon("aa", 0);
+ assertEquals("aa", result);
+
+ s = new Scanner("aaaa");
+ result = s.findWithinHorizon("a*", 0);
+ assertEquals("aaaa", result);
+ }
+
+ public void test_findInLine_LString() {
+ s = new Scanner("test");
+ try {
+ s.findInLine((String) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ s.close();
+ try {
+ s.findInLine((String) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+ try {
+ s.findInLine("test");
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // exptected
+ }
+
+ s = new Scanner("");
+
+ String result = s.findInLine("^");
+ assertEquals("", result);
+ MatchResult matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(0, matchResult.end());
+
+ result = s.findInLine("$");
+ assertEquals("", result);
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(0, matchResult.end());
+
+ /*
+ * When we use the operation of findInLine(Pattern), the match region
+ * should not span the line separator.
+ */
+ s = new Scanner("aa\nb.b");
+ result = s.findInLine("a\nb*");
+ assertNull(result);
+
+ s = new Scanner("aa\nbb.b");
+ result = s.findInLine("\\.");
+ assertNull(result);
+
+ s = new Scanner("abcd1234test\n");
+ result = s.findInLine("\\p{Lower}+");
+ assertEquals("abcd", result);
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(4, matchResult.end());
+
+ result = s.findInLine("\\p{Digit}{5}");
+ assertNull(result);
+ try {
+ matchResult = s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ assertEquals(0, matchResult.start());
+ assertEquals(4, matchResult.end());
+
+ result = s.findInLine("\\p{Lower}+");
+ assertEquals("test", result);
+ matchResult = s.match();
+ assertEquals(8, matchResult.start());
+ assertEquals(12, matchResult.end());
+
+ char[] chars = new char[2048];
+ Arrays.fill(chars, 'a');
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(chars);
+ stringBuilder.append("1234");
+ s = new Scanner(stringBuilder.toString());
+ result = s.findInLine("\\p{Digit}+");
+ assertEquals("1234", result);
+ matchResult = s.match();
+ assertEquals(2048, matchResult.start());
+ assertEquals(2052, matchResult.end());
+
+ s = new Scanner("test1234\n1234 test");
+ result = s.findInLine("test");
+ assertEquals("test", result);
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(4, matchResult.end());
+
+ int number = s.nextInt();
+ assertEquals(1234, number);
+ matchResult = s.match();
+ assertEquals(4, matchResult.start());
+ assertEquals(8, matchResult.end());
+
+ result = s.next();
+ assertEquals("1234", result);
+ matchResult = s.match();
+ assertEquals(9, matchResult.start());
+ assertEquals(13, matchResult.end());
+
+ result = s.findInLine("test");
+ assertEquals("test", result);
+ matchResult = s.match();
+ assertEquals(14, matchResult.start());
+ assertEquals(18, matchResult.end());
+
+ s = new Scanner("test\u0085\ntest");
+ result = s.findInLine("est");
+ assertEquals("est", result);
+ result = s.findInLine("est");
+ assertEquals("est", result);
+
+ s = new Scanner("test\ntest");
+ result = s.findInLine("est");
+ assertEquals("est", result);
+ result = s.findInLine("est");
+ assertEquals("est", result);
+
+ s = new Scanner("test\n123\ntest");
+ result = s.findInLine("est");
+ assertEquals("est", result);
+ result = s.findInLine("est");
+ }
+
+ public void test_skip_LPattern() {
+ s = new Scanner("test");
+ try {
+ s.skip((String) null);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ // If pattern does not match, NoSuchElementException will be thrown out.
+ s = new Scanner("1234");
+ try {
+ s.skip(Pattern.compile("\\p{Lower}"));
+ fail("Should throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+ // Then, no matchResult will be thrown out.
+ try {
+ s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ s.skip(Pattern.compile("\\p{Digit}"));
+ MatchResult matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(1, matchResult.end());
+
+ s.skip(Pattern.compile("\\p{Digit}+"));
+ matchResult = s.match();
+ assertEquals(1, matchResult.start());
+ assertEquals(4, matchResult.end());
+
+ s.close();
+ try {
+ s.skip(Pattern.compile("test"));
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ MockStringReader2Read reader = new MockStringReader2Read("test");
+ s = new Scanner(reader);
+ try {
+ s.skip(Pattern.compile("\\p{Digit}{4}"));
+ fail("Should throw NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ // expected
+ }
+ try {
+ s.match();
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+ s.skip(Pattern.compile("\\p{Digit}{3}\\p{Lower}"));
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(4, matchResult.end());
+
+ s.close();
+ try {
+ s.skip((Pattern) null);
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException e) {
+ // expected
+ }
+
+ StringBuilder stringBuilder = new StringBuilder();
+ char [] chars = new char[1024];
+ Arrays.fill(chars, 'a');
+ stringBuilder.append(chars);
+ stringBuilder.append('3');
+ s = new Scanner(stringBuilder.toString());
+ s.skip(Pattern.compile("\\p{Lower}+\\p{Digit}"));
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(1025, matchResult.end());
+
+ // Large amount of input may be cached
+ chars = new char[102400];
+ Arrays.fill(chars, 'a');
+ stringBuilder = new StringBuilder();
+ stringBuilder.append(chars);
+ s = new Scanner(stringBuilder.toString());
+ s.skip(Pattern.compile(".*"));
+ matchResult = s.match();
+ assertEquals(0, matchResult.start());
+ assertEquals(102400, matchResult.end());
+
+ // skip something without risking a NoSuchElementException
+ s.skip(Pattern.compile("[ \t]*"));
+ matchResult = s.match();
+ assertEquals(102400, matchResult.start());
+ assertEquals(102400, matchResult.end());
+ }
+
+ public void test_Constructor_LReadableByteChannel()
+ throws IOException {
+ InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
+ Support_PortManager.getNextPort());
+ ServerSocketChannel ssc = ServerSocketChannel.open();
+ ssc.socket().bind(localAddr);
+
+ SocketChannel sc = SocketChannel.open();
+ sc.connect(localAddr);
+ sc.configureBlocking(false);
+ assertFalse(sc.isBlocking());
+
+ ssc.accept().close();
+ ssc.close();
+ assertFalse(sc.isBlocking());
+
+ Scanner s = new Scanner(sc);
+ try {
+ s.hasNextInt();
+ fail();
+ } catch (IllegalBlockingModeException expected) {
+ }
+
+ sc.close();
+ }
+
+ private static class MockStringReader extends StringReader {
+
+ public MockStringReader(String param) {
+ super(param);
+ }
+
+ public int read(CharBuffer target) throws IOException {
+ target.append('t');
+ target.append('e');
+ target.append('s');
+ target.append('t');
+ throw new IOException();
+ }
+ }
+
+ private static class MockStringReader2Read extends StringReader {
+ private int timesRead = 1;
+
+ public MockStringReader2Read(String param) {
+ super(param);
+ }
+
+ public int read(CharBuffer target) throws IOException {
+ if (timesRead == 1) {
+ target.append('1');
+ target.append('2');
+ target.append('3');
+ timesRead++;
+ return 3;
+ } else if (timesRead == 2) {
+ target.append('t');
+ timesRead++;
+ return 1;
+ } else {
+ throw new IOException();
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/OldTimeZoneTest.java b/luni/src/test/java/libcore/java/util/OldTimeZoneTest.java
index 19abe3e..19a0bf4 100644
--- a/luni/src/test/java/libcore/java/util/OldTimeZoneTest.java
+++ b/luni/src/test/java/libcore/java/util/OldTimeZoneTest.java
@@ -204,8 +204,8 @@ public class OldTimeZoneTest extends TestCase {
// Arizona doesn't observe DST. See http://phoenix.about.com/cs/weather/qt/timezone.htm
assertFalse(tz1.hasSameRules(tz2));
assertFalse(tz1.hasSameRules(null));
- tz1 = TimeZone.getTimeZone("America/Montreal");
- tz2 = TimeZone.getTimeZone("America/New_York");
+ tz1 = TimeZone.getTimeZone("America/New_York");
+ tz2 = TimeZone.getTimeZone("US/Eastern");
assertEquals(tz1.getDisplayName(), tz2.getDisplayName());
assertFalse(tz1.getID().equals(tz2.getID()));
assertTrue(tz2.hasSameRules(tz1));
diff --git a/luni/src/test/java/libcore/java/util/OldTreeMapTest.java b/luni/src/test/java/libcore/java/util/OldTreeMapTest.java
index 9f12af3..ab27cf2 100644
--- a/luni/src/test/java/libcore/java/util/OldTreeMapTest.java
+++ b/luni/src/test/java/libcore/java/util/OldTreeMapTest.java
@@ -419,10 +419,20 @@ public class OldTreeMapTest extends junit.framework.TestCase {
tm = new TreeMap();
assertNull(tm.put(new Integer(1), new Object()));
+ }
- // regression for Harmony-2474
+ /**
+ * Android's TreeMap requires every element to be comparable, even if
+ * there's no other element to compare it to. This is more strict than the
+ * RI. See Harmony-2474.
+ */
+ public void testRemoveNonComparableFromEmptyMap() {
tm = new TreeMap();
- tm.remove(o);
+ try {
+ tm.remove(new Object()); // succeeds on RI
+ } catch (ClassCastException expected) {
+ // expected on libcore only
+ }
}
/**
diff --git a/luni/src/test/java/libcore/java/util/SerializableTester.java b/luni/src/test/java/libcore/java/util/SerializableTester.java
index e424669..1a28b64 100644
--- a/luni/src/test/java/libcore/java/util/SerializableTester.java
+++ b/luni/src/test/java/libcore/java/util/SerializableTester.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import junit.framework.AssertionFailedError;
@@ -35,6 +36,15 @@ public class SerializableTester<T> {
this.value = value;
}
+ /**
+ * Returns true if {@code a} and {@code b} are equal. Override this if
+ * {@link Object#equals} isn't appropriate or sufficient for this tester's
+ * value type.
+ */
+ protected boolean equals(T a, T b) {
+ return a.equals(b);
+ }
+
protected void verify(T deserialized) {}
public void test() {
@@ -49,14 +59,14 @@ public class SerializableTester<T> {
@SuppressWarnings("unchecked") // deserialize should return the proper type
T deserialized = (T) deserialize(hexDecode(golden));
- assertEquals("User-constructed value doesn't equal deserialized golden value",
- value, deserialized);
+ assertTrue("User-constructed value doesn't equal deserialized golden value",
+ equals(value, deserialized));
verify(deserialized);
@SuppressWarnings("unchecked") // deserialize should return the proper type
T reserialized = (T) deserialize(serialize(value));
- assertEquals("User-constructed value doesn't equal itself, reserialized",
- value, reserialized);
+ assertTrue("User-constructed value doesn't equal itself, reserialized",
+ equals(value, reserialized));
verify(reserialized);
} catch (Exception e) {
diff --git a/luni/src/test/java/libcore/java/util/beans/PropertyChangeSupportTest.java b/luni/src/test/java/libcore/java/util/beans/PropertyChangeSupportTest.java
new file mode 100644
index 0000000..4c9d88d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/beans/PropertyChangeSupportTest.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.beans;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeListenerProxy;
+import java.beans.PropertyChangeSupport;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EventListener;
+import java.util.List;
+import junit.framework.TestCase;
+import libcore.java.util.SerializableTester;
+
+public final class PropertyChangeSupportTest extends TestCase {
+
+ public void testOldAndNewAreBothNull() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ EventLog listener = new EventLog();
+ support.addPropertyChangeListener(listener);
+
+ PropertyChangeEvent nullToNull = new PropertyChangeEvent(bean, "a", null, null);
+ support.firePropertyChange(nullToNull);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(nullToNull), listener.log);
+ }
+
+ public void testOldAndNewAreTheSame() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ EventLog listener = new EventLog();
+ support.addPropertyChangeListener(listener);
+
+ PropertyChangeEvent xToX = new PropertyChangeEvent(bean, "a", "x", new String("x"));
+ support.firePropertyChange(xToX);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(), listener.log);
+ }
+
+ public void testEventsFilteredByProxies() {
+ Object bean = new Object();
+ PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
+ PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);
+ PropertyChangeEvent eventC = new PropertyChangeEvent(bean, "c", false, true);
+
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+
+ EventLog all = new EventLog();
+ support.addPropertyChangeListener(all);
+
+ EventLog proxiedA = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));
+
+ EventLog addA = new EventLog();
+ support.addPropertyChangeListener("a", addA);
+
+ EventLog addAProxiedB = new EventLog();
+ support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
+
+ EventLog proxiedAB = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy(
+ "a", new PropertyChangeListenerProxy("b", proxiedAB)));
+
+ EventLog proxiedAA = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("a", proxiedAA)));
+
+ EventLog proxiedAAC = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("c", proxiedAAC))));
+
+ support.firePropertyChange(eventA);
+ support.firePropertyChange(eventB);
+ support.firePropertyChange(eventC);
+
+ assertEquals(Arrays.asList(eventA, eventB, eventC), all.log);
+ assertEquals(Arrays.asList(eventA), proxiedA.log);
+ assertEquals(Arrays.asList(eventA), addA.log);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(), addAProxiedB.log);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAB.log);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(eventA), proxiedAA.log);
+ assertEquals(Arrays.<PropertyChangeEvent>asList(), proxiedAAC.log);
+ }
+
+ /**
+ * Test that we need to do our own equals() work to manually unwrap an
+ * arbitrary number of proxies.
+ */
+ public void testRemoveWithProxies() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+
+ EventLog all = new EventLog();
+ support.addPropertyChangeListener(all);
+ assertEquals(1, support.getPropertyChangeListeners().length);
+
+ EventLog proxiedA = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedA));
+ assertEquals(2, support.getPropertyChangeListeners().length);
+
+ EventLog addA = new EventLog();
+ support.addPropertyChangeListener("a", addA);
+ assertEquals(3, support.getPropertyChangeListeners().length);
+
+ EventLog addAProxiedB = new EventLog();
+ support.addPropertyChangeListener("a", new PropertyChangeListenerProxy("b", addAProxiedB));
+ assertEquals(4, support.getPropertyChangeListeners().length);
+
+ EventLog proxiedAB = new EventLog();
+ PropertyChangeListenerProxy proxyAB = new PropertyChangeListenerProxy(
+ "a", new PropertyChangeListenerProxy("b", proxiedAB));
+ support.addPropertyChangeListener(proxyAB);
+ assertEquals(5, support.getPropertyChangeListeners().length);
+
+ EventLog proxiedAAC = new EventLog();
+ support.addPropertyChangeListener(new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("c", proxiedAAC))));
+ assertEquals(6, support.getPropertyChangeListeners().length);
+
+ support.removePropertyChangeListener(all);
+ assertEquals(5, support.getPropertyChangeListeners().length);
+ support.removePropertyChangeListener("a", proxiedA);
+ assertEquals(4, support.getPropertyChangeListeners().length);
+ support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", addA));
+ assertEquals(3, support.getPropertyChangeListeners().length);
+ support.removePropertyChangeListener(
+ "a", new PropertyChangeListenerProxy("b", addAProxiedB));
+ assertEquals(2, support.getPropertyChangeListeners().length);
+ support.removePropertyChangeListener(proxyAB);
+ assertEquals(1, support.getPropertyChangeListeners().length);
+
+ support.removePropertyChangeListener(proxiedAAC);
+ support.removePropertyChangeListener(new PropertyChangeListenerProxy("a", proxiedAAC));
+ support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("c", proxiedAAC));
+ support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("c",
+ new PropertyChangeListenerProxy("a", proxiedAAC)));
+ assertEquals(1, support.getPropertyChangeListeners().length);
+
+ support.removePropertyChangeListener("a", new PropertyChangeListenerProxy("a",
+ new PropertyChangeListenerProxy("c", proxiedAAC)));
+ assertEquals(0, support.getPropertyChangeListeners().length);
+ }
+
+ public void testAddingOneListenerTwice() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ EventLog log = new EventLog();
+ support.addPropertyChangeListener("a", log);
+ support.addPropertyChangeListener(log);
+ support.addPropertyChangeListener(log);
+ support.addPropertyChangeListener("a", log);
+
+ PropertyChangeEvent eventA = new PropertyChangeEvent(bean, "a", false, true);
+ PropertyChangeEvent eventB = new PropertyChangeEvent(bean, "b", false, true);
+
+ support.firePropertyChange(eventA);
+ support.firePropertyChange(eventB);
+
+ assertEquals(Arrays.asList(eventA, eventA, eventA, eventA, eventB, eventB), log.log);
+ }
+
+ public void testAddingAListenerActuallyAddsAProxy() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {}
+ };
+ support.addPropertyChangeListener("a", listener);
+
+ PropertyChangeListenerProxy p1
+ = (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
+ assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
+ assertTrue(p1 != listener); // weird but consistent with the RI
+ assertEquals("a", p1.getPropertyName());
+ assertEquals(listener, p1.getListener());
+ }
+
+ public void testAddingAProxy() {
+ Object bean = new Object();
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ PropertyChangeListener listener = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {}
+ };
+ PropertyChangeListenerProxy proxy = new PropertyChangeListenerProxy("a", listener);
+ support.addPropertyChangeListener("b", proxy);
+
+ // this proxy sets us up to receive 'b' events
+ PropertyChangeListenerProxy p1
+ = (PropertyChangeListenerProxy) support.getPropertyChangeListeners()[0];
+ assertEquals(PropertyChangeListenerProxy.class, p1.getClass());
+ assertEquals("b", p1.getPropertyName());
+
+ // this proxy sets us up to receive 'a' events
+ PropertyChangeListenerProxy p2 = (PropertyChangeListenerProxy) p1.getListener();
+ assertEquals(PropertyChangeListenerProxy.class, p2.getClass());
+ assertEquals("a", p2.getPropertyName());
+ assertEquals(listener, p2.getListener());
+ }
+
+ public void testSerialize() {
+ String s = "aced0005737200206a6176612e6265616e732e50726f70657274794368616e67"
+ + "65537570706f727458d5d264574860bb03000349002a70726f706572747943686"
+ + "16e6765537570706f727453657269616c697a65644461746156657273696f6e4c"
+ + "00086368696c6472656e7400154c6a6176612f7574696c2f486173687461626c6"
+ + "53b4c0006736f757263657400124c6a6176612f6c616e672f4f626a6563743b78"
+ + "7000000002737200136a6176612e7574696c2e486173687461626c6513bb0f252"
+ + "14ae4b803000246000a6c6f6164466163746f724900097468726573686f6c6478"
+ + "703f4000000000000877080000000b00000001740001617371007e00000000000"
+ + "2707400046265616e7372003a6c6962636f72652e6a6176612e7574696c2e6265"
+ + "616e732e50726f70657274794368616e6765537570706f7274546573742445766"
+ + "56e744c6f67b92667637d0b6f450200024c00036c6f677400104c6a6176612f75"
+ + "74696c2f4c6973743b4c00046e616d657400124c6a6176612f6c616e672f53747"
+ + "2696e673b7870737200136a6176612e7574696c2e41727261794c6973747881d2"
+ + "1d99c7619d03000149000473697a6578700000000077040000000a7874000b6c6"
+ + "97374656e6572546f4171007e000c70787871007e00087371007e00097371007e"
+ + "000d0000000077040000000a7874000d6c697374656e6572546f416c6c7078";
+
+ Object bean = "bean";
+ PropertyChangeSupport support = new PropertyChangeSupport(bean);
+ EventLog listenerToAll = new EventLog();
+ listenerToAll.name = "listenerToAll";
+ EventLog listenerToA = new EventLog();
+ listenerToA.name = "listenerToA";
+ support.addPropertyChangeListener(listenerToAll);
+ support.addPropertyChangeListener("a", listenerToA);
+ support.addPropertyChangeListener("a", listenerToA);
+
+ new SerializableTester<PropertyChangeSupport>(support, s) {
+ @Override protected boolean equals(PropertyChangeSupport a, PropertyChangeSupport b) {
+ return describe(a.getPropertyChangeListeners())
+ .equals(describe(b.getPropertyChangeListeners()));
+ }
+ @Override protected void verify(PropertyChangeSupport deserialized) {
+ assertEquals("[a to listenerToA, a to listenerToA, listenerToAll]",
+ describe(deserialized.getPropertyChangeListeners()));
+ }
+ }.test();
+ }
+
+ private String describe(PropertyChangeListener[] listeners) {
+ List<String> result = new ArrayList<String>();
+ for (PropertyChangeListener listener : listeners) {
+ result.add(describe(listener));
+ }
+ Collections.sort(result);
+ return result.toString();
+ }
+
+ private String describe(EventListener listener) {
+ if (listener instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy) listener;
+ return proxy.getPropertyName() + " to " + describe(proxy.getListener());
+ } else {
+ return listener.toString();
+ }
+ }
+
+ static class EventLog implements PropertyChangeListener, Serializable {
+ String name = "EventLog";
+ List<PropertyChangeEvent> log = new ArrayList<PropertyChangeEvent>();
+ public void propertyChange(PropertyChangeEvent event) {
+ log.add(event);
+ }
+ @Override public String toString() {
+ return name;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java b/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java
new file mode 100644
index 0000000..8232881
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/concurrent/CopyOnWriteArrayListTest.java
@@ -0,0 +1,270 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.concurrent;
+
+import java.util.Arrays;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import junit.framework.TestCase;
+import libcore.java.util.SerializableTester;
+
+public final class CopyOnWriteArrayListTest extends TestCase {
+
+ public void testIteratorAndNonStructuralChanges() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ Iterator<String> abcde = list.iterator();
+ assertEquals("a", abcde.next());
+ list.set(1, "B");
+ assertEquals("b", abcde.next());
+ assertEquals("c", abcde.next());
+ assertEquals("d", abcde.next());
+ assertEquals("e", abcde.next());
+ }
+
+ /**
+ * The sub list throws on non-structural changes, even though that disagrees
+ * with the subList() documentation which suggests that only size-changing
+ * operations will trigger ConcurrentModificationException.
+ */
+ public void testSubListAndNonStructuralChanges() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ list.set(2, "C");
+ try {
+ bcd.get(1);
+ fail();
+ } catch (ConcurrentModificationException expected) {
+ }
+ }
+
+ public void testSubListAndStructuralChanges() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ list.clear();
+ try {
+ bcd.get(1);
+ fail();
+ } catch (ConcurrentModificationException expected) {
+ }
+ }
+
+ public void testSubListAndSizePreservingStructuralChanges() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ list.clear();
+ list.addAll(Arrays.asList("A", "B", "C", "D", "E"));
+ try {
+ bcd.get(1);
+ fail();
+ } catch (ConcurrentModificationException expected) {
+ }
+ }
+
+ public void testRemoveAll() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+
+ list.removeAll(Arrays.asList());
+ assertEquals(Arrays.asList("a", "b", "c", "d", "e"), list);
+
+ list.removeAll(Arrays.asList("e"));
+ assertEquals(Arrays.asList("a", "b", "c", "d"), list);
+
+ list.removeAll(Arrays.asList("b", "c"));
+ assertEquals(Arrays.asList("a", "d"), list);
+ }
+
+ public void testSubListClear() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ bcd.clear();
+ assertEquals(Arrays.asList("a", "e"), list);
+ bcd.addAll(Arrays.asList("B", "C", "D"));
+ assertEquals(Arrays.asList("a", "B", "C", "D", "e"), list);
+ }
+
+ public void testSubListClearWhenEmpty() {
+ new CopyOnWriteArrayList<String>().subList(0, 0).clear(); // the RI fails here
+ }
+
+ public void testSubListIteratorGetsSnapshot() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ Iterator<String> bcd = list.subList(1, 4).iterator();
+ list.clear();
+ assertEquals("b", bcd.next());
+ assertEquals("c", bcd.next());
+ assertEquals("d", bcd.next());
+ assertFalse(bcd.hasNext());
+ }
+
+ public void testSubListRemoveByValue() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ bcd.remove("c"); // the RI fails here
+ assertEquals(Arrays.asList("b", "d"), bcd);
+ assertEquals(Arrays.asList("a", "b", "d", "e"), list);
+ }
+
+ public void testSubListRemoveByIndex() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ bcd.remove(1);
+ assertEquals(Arrays.asList("b", "d"), bcd);
+ assertEquals(Arrays.asList("a", "b", "d", "e"), list);
+ }
+
+ public void testSubListRetainAll() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i"));
+ List<String> def = list.subList(3, 6);
+ def.retainAll(Arrays.asList("c", "e", "h")); // the RI fails here
+ assertEquals(Arrays.asList("a", "b", "c", "e", "g", "h", "i"), list);
+ assertEquals(Arrays.asList("e"), def);
+ }
+
+ public void testSubListRemoveAll() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i"));
+ List<String> def = list.subList(3, 6);
+ def.removeAll(Arrays.asList("c", "e", "h")); // the RI fails here
+ assertEquals(Arrays.asList("a", "b", "c", "d", "f", "g", "h", "i"), list);
+ assertEquals(Arrays.asList("d", "f"), def);
+ }
+
+ public void testAtomicAdds() throws Exception {
+ testAddAllIsAtomic(new CopyOnWriteArrayList<Object>());
+ }
+
+ public void testSubListAtomicAdds() throws Exception {
+ testAddAllIsAtomic(new CopyOnWriteArrayList<Object>().subList(0, 0));
+ }
+
+ /**
+ * Attempts to observe {@code list} in the middle of an add. The RI's
+ * CopyOnWriteArrayList passes this test, but its sub list doesn't.
+ */
+ private void testAddAllIsAtomic(final List<Object> list) throws Exception {
+ final CountDownLatch done = new CountDownLatch(1);
+
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+ Future<?> future = executor.submit(new Runnable() {
+ @Override public void run() {
+ while (done.getCount() > 0) {
+ int listSize = list.size();
+ assertEquals("addAll() not atomic; size=" + listSize, 0, listSize % 1000);
+ Thread.yield();
+ }
+ }
+ });
+ executor.shutdown();
+
+ List<Object> toAdd = Arrays.asList(new Object[1000]);
+ for (int i = 0; i < 100; i++) {
+ list.addAll(toAdd);
+ list.clear();
+ Thread.yield();
+ }
+
+ done.countDown();
+ future.get(); // this will throw the above exception
+ }
+
+ public void testSubListAddIsAtEnd() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ bcd.add("f");
+ assertEquals(Arrays.asList("a", "b", "c", "d", "f", "e"), list);
+ assertEquals(Arrays.asList("b", "c", "d", "f"), bcd);
+ }
+
+ public void testSubListAddAll() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ List<String> bcd = list.subList(1, 4);
+ bcd.addAll(1, Arrays.asList("f", "g", "h", "i"));
+ assertEquals(Arrays.asList("a", "b", "f", "g", "h", "i", "c", "d", "e"), list);
+ assertEquals(Arrays.asList("b", "f", "g", "h", "i", "c", "d"), bcd);
+ }
+
+ public void testListIterator() {
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>();
+ list.addAll(Arrays.asList("a", "b", "c", "d", "e"));
+ ListIterator<String> i = list.listIterator(5);
+ list.clear();
+
+ assertEquals(5, i.nextIndex());
+ assertEquals(4, i.previousIndex());
+ assertEquals("e", i.previous());
+ assertEquals(4, i.nextIndex());
+ assertEquals(3, i.previousIndex());
+ assertTrue(i.hasNext());
+ assertTrue(i.hasPrevious());
+ assertEquals("d", i.previous());
+ assertEquals(3, i.nextIndex());
+ assertEquals(2, i.previousIndex());
+ assertTrue(i.hasNext());
+ assertTrue(i.hasPrevious());
+ assertEquals("c", i.previous());
+ assertEquals(2, i.nextIndex());
+ assertEquals(1, i.previousIndex());
+ assertTrue(i.hasNext());
+ assertTrue(i.hasPrevious());
+ assertEquals("b", i.previous());
+ assertEquals(1, i.nextIndex());
+ assertEquals(0, i.previousIndex());
+ assertTrue(i.hasNext());
+ assertTrue(i.hasPrevious());
+ assertEquals("a", i.previous());
+ assertEquals(0, i.nextIndex());
+ assertEquals(-1, i.previousIndex());
+ assertTrue(i.hasNext());
+ assertFalse(i.hasPrevious());
+ try {
+ i.previous();
+ fail();
+ } catch (NoSuchElementException expected) {
+ }
+ }
+
+ public void testSerialize() {
+ String s = "aced0005737200296a6176612e7574696c2e636f6e63757272656e742e436f70"
+ + "794f6e577269746541727261794c697374785d9fd546ab90c3030000787077040"
+ + "0000005740001617400016274000163707400016578";
+
+ List<String> contents = Arrays.asList("a", "b", "c", null, "e");
+ CopyOnWriteArrayList<String> list = new CopyOnWriteArrayList<String>(contents);
+
+ new SerializableTester<CopyOnWriteArrayList<String>>(list, s).test();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/DalvikExecTest.java b/luni/src/test/java/libcore/java/util/jar/DalvikExecTest.java
new file mode 100644
index 0000000..02642a7
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/DalvikExecTest.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import junit.framework.TestCase;
+import libcore.base.Streams;
+import static tests.support.Support_Exec.execAndGetOutput;
+import tests.support.resource.Support_Resources;
+
+
+public class DalvikExecTest extends TestCase {
+
+ String execDalvik1(String classpath, String mainClass, String arg1)
+ throws IOException, InterruptedException {
+ ProcessBuilder builder = new ProcessBuilder();
+
+ File dalvikvm = new File("/system/bin/dalvikvm");
+ if (dalvikvm.exists()) {
+ builder.command().add(dalvikvm.getPath());
+ } else {
+ builder.command().add("dalvikvm"); // for host mode, assume dalvikvm is on the path
+ }
+
+ builder.command().add("-Djava.io.tmpdir=/tmp/mc");
+ builder.command().add("-Duser.language=en");
+ builder.command().add("-Duser.region=US");
+ builder.command().add("-Xbootclasspath:" + System.getProperty("java.boot.class.path"));
+ builder.command().add("-classpath");
+ builder.command().add(classpath);
+ builder.command().add(mainClass);
+
+ if (arg1 != null) {
+ builder.command().add(arg1);
+ }
+
+ return execAndGetOutput(builder);
+ }
+
+ String execDalvik (String classpath, String mainClass)
+ throws IOException, InterruptedException {
+ return execDalvik1(classpath, mainClass, null);
+ }
+
+ // Execute an existing JAR on dalvikvm using -classpath option.",
+ public void test_execExistingJar () throws IOException, InterruptedException {
+ String res;
+ File jarFile;
+ if (System.getProperty("java.vendor").contains("Android")) {
+ //
+ // Test against Android:
+ //
+ File tempDir = Support_Resources.createTempFolder();
+ jarFile = Support_Resources.copyFile(
+ tempDir, null, "cts_dalvikExecTest.jar" );
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
+ assertEquals("Hello Android World!", "Hello Android World!\n", res);
+
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
+ assertTrue("Android Resource Dumper started",
+ res.contains("Android Resource Dumper started"));
+ assertTrue("This Resource contains some text.",
+ res.contains("This Resource contains some text."));
+ } else {
+ //
+ // Test against RI:
+ //
+ // Do nothing!
+ }
+ }
+
+ // Create a temp file, fill it with contents according to Dalvik JAR format, and execute it on dalvikvm using -classpath option.",
+ public void test_execCreatedJar () throws IOException, InterruptedException {
+ File jarFile = File.createTempFile("cts_dalvikExecTest_", ".jar");
+ jarFile.deleteOnExit();
+
+ // Create a JAR output stream on the temp file:
+ JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarFile));
+
+ // Define the entry for the classes.dex:
+ jarOut.putNextEntry(new JarEntry("classes.dex"));
+
+ // Fill in the classes.dex contents, i.e. the Dalvik executable code:
+ // (See below for the detailed source code contents.)
+ Streams.copy(Support_Resources.getResourceStream("cts_dalvikExecTest_classes.dex"), jarOut);
+
+ // Now add a resource file:
+ //
+ jarOut.putNextEntry(new JarEntry("dalvikExecTest/myResource"));
+ jarOut.write("This Resource contains some text.".getBytes());
+
+ // Close the stream to the completed JAR file.
+ jarOut.close();
+
+ // The resulting JAR file contains the classes listed at the end of this text,
+ // like the 'cts_dalvikExecTest.jar' as part of the resources, too.
+
+ String res;
+
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
+ assertEquals("Hello Android World!", "Hello Android World!\n", res);
+
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
+ assertTrue("Android Resource Dumper started",
+ res.contains("Android Resource Dumper started"));
+ assertTrue("This Resource contains some text.",
+ res.contains("This Resource contains some text."));
+ }
+
+
+ /**
+ * This test does quite the same as test_execCreatedJar, but includes a manifest.
+ * Note however that the Dalvik JAR format does not require this manifest.
+ * We just test whether the manifest is placed correctly within the JAR by
+ * dumping its contents read as a simple text resource.
+ * No! We can't do that so easily either, as there are other (parent) JARs
+ * with a manifest inside, taken with precedence.
+ * So we will reopen the JAR as a JarFile and check the manifest
+ * with a top level end-to-end approach.
+ */
+ public void test_execCreatedJarWithManifest () throws IOException, InterruptedException {
+ File jarFile = File.createTempFile("cts_dalvikExecTest_", ".jar");
+ jarFile.deleteOnExit();
+
+ // Create the manifest:
+ Manifest manifest = new Manifest();
+ Attributes attrs = manifest.getMainAttributes();
+ attrs.put(Attributes.Name.MANIFEST_VERSION, "3.1415962");
+ attrs.put(Attributes.Name.MAIN_CLASS, "dalvikExecTest.HelloWorld");
+ attrs.put(Attributes.Name.CLASS_PATH, jarFile.getName());
+
+ // Create a JAR output stream on the temp file using the manifest:
+ JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarFile), manifest);
+
+ // Define the entry for the classes.dex:
+ jarOut.putNextEntry(new JarEntry("classes.dex"));
+
+ // Fill in the classes.dex contents, i.e. the Dalvik executable code:
+ // (See below for the detailed source code contents.)
+ Streams.copy(Support_Resources.getResourceStream("cts_dalvikExecTest_classes.dex"), jarOut);
+
+ // Now add a resource file:
+ //
+ jarOut.putNextEntry(new JarEntry("dalvikExecTest/myResource"));
+ jarOut.write("This Resource contains some text.".getBytes());
+
+ // Close the stream to the completed JAR file.
+ jarOut.close();
+
+ // The resulting JAR file contains the classes listed at the end of this text,
+ // like the 'cts_dalvikExecTest.jar' as part of the resources, too.
+
+ String res;
+
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
+ assertEquals("Hello Android World!", "Hello Android World!\n", res);
+
+ res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
+ assertTrue("Android Resource Dumper started",
+ res.contains("Android Resource Dumper started"));
+ assertTrue("This Resource contains some text.",
+ res.contains("This Resource contains some text."));
+
+ // And now reread the manifest:
+ //
+ JarFile jarIn = new JarFile(jarFile);
+ manifest = jarIn.getManifest();
+ attrs = manifest.getMainAttributes();
+ assertEquals("MANIFEST_VERSION must match!", "3.1415962",
+ attrs.get(Attributes.Name.MANIFEST_VERSION));
+ assertEquals("MAIN_CLASS must match!", "dalvikExecTest.HelloWorld",
+ attrs.get(Attributes.Name.MAIN_CLASS));
+ assertEquals("CLASS_PATH must match!", jarFile.getName(),
+ attrs.get(Attributes.Name.CLASS_PATH));
+ }
+
+
+ /*
+ * The following two classes are added, here, only for completeness.
+ * They form the contents of the dalvikExecTest package contained
+ * in the 'cts_dalvikExecTest_classes.dex' resource file.
+ */
+ /**
+ * @hide
+ */
+ public static class HelloWorld {
+
+ public static void main(String[] args) {
+ System.out.println("Hello Android World!");
+ }
+
+ }
+
+ public static class ResourceDumper {
+
+ static ByteArrayOutputStream outputFrom (InputStream input) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[512];
+ int total = 0;
+ int count;
+ count = input.read(buffer);
+ while (count != -1) {
+ out.write(buffer, 0, count);
+ total = total + count;
+ count = input.read(buffer);
+ }
+ return out;
+ }
+
+ public static void main(String[] args) throws IOException {
+ System.out.print("Android Resource Dumper started ");
+ String fileName;
+ if (args.length >= 1) {
+ fileName = args[0];
+ System.out.format("for argument '%s'.\n", fileName);
+ } else {
+ System.out.print("standard ");
+ fileName = "myResource";
+ System.out.println("for standard 'myResource'.");
+ }
+ InputStream is = ResourceDumper.class.getResourceAsStream(fileName);
+ if (is != null) {
+ System.out.println("Resource obtained and being dumped:");
+ System.out.println(outputFrom(is).toString());
+ }
+ }
+
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldAttributesNameTest.java b/luni/src/test/java/libcore/java/util/jar/OldAttributesNameTest.java
new file mode 100644
index 0000000..0d83715
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldAttributesNameTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.util.jar.Attributes;
+import junit.framework.TestCase;
+
+public class OldAttributesNameTest extends TestCase {
+
+ /**
+ * @tests java.util.jar.Attributes.Name#Name(java.lang.String)
+ */
+ public void test_AttributesName_Constructor() {
+ try {
+ new Attributes.Name(null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException ee) {
+ // expected
+ }
+ }
+
+ public void test_equalsLjava_lang_Object() {
+ Attributes.Name attr1 = new Attributes.Name("Attr");
+ Attributes.Name attr2 = new Attributes.Name("Attr");
+
+ assertTrue(attr1.equals(attr2));
+ attr2 = new Attributes.Name("Attr1");
+ assertFalse(attr1.equals(attr2));
+ }
+
+ public void test_hashCode() {
+ Attributes.Name attr1 = new Attributes.Name("Attr1");
+ Attributes.Name attr2 = new Attributes.Name("Attr2");
+
+ assertNotSame(attr1.hashCode(), attr2.hashCode());
+ }
+
+ public void test_toString() {
+ String str1 = "Attr1";
+ String str2 = "Attr2";
+ Attributes.Name attr1 = new Attributes.Name(str1);
+ Attributes.Name attr2 = new Attributes.Name("Attr2");
+
+ assertTrue(attr1.toString().equals(str1));
+ assertTrue(attr2.toString().equals(str2));
+ assertFalse(attr2.toString().equals(str1));
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldAttributesTest.java b/luni/src/test/java/libcore/java/util/jar/OldAttributesTest.java
new file mode 100644
index 0000000..e945e32
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldAttributesTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.util.jar.Attributes;
+import junit.framework.TestCase;
+
+public class OldAttributesTest extends TestCase {
+ private Attributes a;
+
+ @Override
+ protected void setUp() {
+ a = new Attributes();
+ a.putValue("1", "one");
+ a.putValue("2", "two");
+ a.putValue("3", "three");
+ a.putValue("4", "four");
+ }
+
+ public void test_getLjava_lang_Object() {
+
+ try {
+ a.getValue("IllegalArgumentException expected");
+ } catch (IllegalArgumentException ee) {
+ // expected
+ }
+ }
+
+ public void test_Constructor() {
+ Attributes attr = new Attributes();
+ assertTrue(attr.size() >= 0);
+ }
+
+ public void test_ConstructorI() {
+ Attributes attr = new Attributes(10);
+ assertTrue(attr.size() >= 0);
+ }
+
+ public void test_getLjava_lang_Object_true() {
+ assertEquals("a) Incorrect value returned", "one", a
+ .get(new Attributes.Name("1")));
+ assertNull("b) Incorrect value returned", a.get("0"));
+ assertNull("b) Incorrect value returned", a.get("1"));
+ }
+
+ public void test_getValueLjava_util_jar_Attributes_Name() {
+ assertEquals("a) Incorrect value returned", "one", a
+ .getValue(new Attributes.Name("1")));
+ assertNull("b) Incorrect value returned", a
+ .getValue(new Attributes.Name("0")));
+ }
+
+ public void test_hashCode() {
+ Attributes b = (Attributes) a.clone();
+ b.putValue("33", "Thirty three");
+ assertNotSame(a.hashCode(), b.hashCode());
+ b = (Attributes) a.clone();
+ b.clear();
+ assertNotSame(a.hashCode(), b.hashCode());
+ }
+
+ public void test_putValueLjava_lang_StringLjava_lang_String() {
+ Attributes b = new Attributes();
+ b.put(new Attributes.Name("1"), "one");
+ b.putValue("2", "two");
+ b.put(new Attributes.Name("3"), "three");
+ b.putValue("4", "four");
+
+ assertTrue(a.equals(b));
+
+ try {
+ b.putValue(null, "null");
+ fail("NullPointerException expected");
+ } catch (NullPointerException ee) {
+ // expected
+ }
+
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < 0x10000; i++) {
+ sb.append('3');
+ }
+ try {
+ b.putValue(new String(sb), "wrong name");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException ee) {
+ // expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldJarEntryTest.java b/luni/src/test/java/libcore/java/util/jar/OldJarEntryTest.java
new file mode 100644
index 0000000..ed24d8b
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldJarEntryTest.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
+
+
+public class OldJarEntryTest extends TestCase {
+ private ZipEntry zipEntry;
+ private JarEntry jarEntry;
+ private JarFile jarFile;
+ private final String jarName = "hyts_patch.jar";
+ private final String entryName = "foo/bar/A.class";
+ private File resources;
+
+ @Override
+ protected void setUp() throws Exception {
+ resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, jarName);
+ jarFile = new JarFile(new File(resources, jarName));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (jarFile != null) {
+ jarFile.close();
+ }
+ }
+
+ /**
+ * @throws IOException
+ * @tests java.util.jar.JarEntry#JarEntry(java.util.jar.JarEntry)
+ */
+ public void test_ConstructorLjava_util_jar_JarEntry_on_null() throws IOException {
+ JarEntry newJarEntry = new JarEntry(jarFile.getJarEntry(entryName));
+ assertNotNull(newJarEntry);
+
+ jarEntry = null;
+ try {
+ newJarEntry = new JarEntry(jarEntry);
+ fail("Should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#JarEntry(java.util.zip.ZipEntry)
+ */
+ public void test_ConstructorLjava_util_zip_ZipEntry() {
+ assertNotNull("Jar file is null", jarFile);
+ zipEntry = jarFile.getEntry(entryName);
+ assertNotNull("Zip entry is null", zipEntry);
+ jarEntry = new JarEntry(zipEntry);
+ assertNotNull("Jar entry is null", jarEntry);
+ assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
+ .getName());
+ assertEquals("Wrong entry constructed--wrong size", 311, jarEntry
+ .getSize());
+ }
+
+ /**
+ * @tests java.util.jar.JarEntry#getAttributes()
+ */
+ public void test_getAttributes() {
+ JarFile attrJar = null;
+ File file = null;
+
+ Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
+ try {
+ attrJar = new JarFile(new File(resources, "Broken_manifest.jar"));
+ jarEntry = attrJar.getJarEntry("META-INF/");
+ jarEntry.getAttributes();
+ fail("IOException expected");
+ } catch (IOException e) {
+ // expected.
+ }
+ }
+
+ public void test_ConstructorLjava_lang_String() {
+ assertNotNull("Jar file is null", jarFile);
+ zipEntry = jarFile.getEntry(entryName);
+ assertNotNull("Zip entry is null", zipEntry);
+ jarEntry = new JarEntry(entryName);
+ assertNotNull("Jar entry is null", jarEntry);
+ assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
+ .getName());
+ try {
+ jarEntry = new JarEntry((String) null);
+ fail("NullPointerException expected");
+ } catch (NullPointerException ee) {
+ // expected
+ }
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < 0x10000; i++) {
+ sb.append('3');
+ }
+ try {
+ jarEntry = new JarEntry(new String(sb));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException ee) {
+ // expected
+ }
+ }
+
+ public void test_ConstructorLjava_util_jar_JarEntry() {
+ assertNotNull("Jar file is null", jarFile);
+ JarEntry je = jarFile.getJarEntry(entryName);
+ assertNotNull("Jar entry is null", je);
+ jarEntry = new JarEntry(je);
+ assertNotNull("Jar entry is null", jarEntry);
+ assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
+ .getName());
+ assertEquals("Wrong entry constructed--wrong size", 311, jarEntry
+ .getSize());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldJarExceptionTest.java b/luni/src/test/java/libcore/java/util/jar/OldJarExceptionTest.java
new file mode 100644
index 0000000..397931a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldJarExceptionTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.util.jar.JarException;
+import junit.framework.TestCase;
+
+public class OldJarExceptionTest extends TestCase {
+ /**
+ * @tests java.util.jar.JarException#JarException(java.lang.String)
+ */
+ public void test_Constructor() throws Exception {
+ JarException ex = new JarException();
+ JarException ex1 = new JarException("Test string");
+ JarException ex2 = new JarException(null);
+ assertNotSame(ex, ex1);
+ assertNotSame(ex.getMessage(), ex1.getMessage());
+ assertNotSame(ex, ex2);
+ assertSame(ex.getMessage(), ex2.getMessage());
+ }
+
+ public void test_ConstructorLjava_lang_String() throws Exception {
+ JarException ex1 = new JarException("Test string");
+ JarException ex2 = new JarException(null);
+ assertNotSame(ex1, ex2);
+ assertNotSame(ex1.getMessage(), ex2.getMessage());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldJarFileTest.java b/luni/src/test/java/libcore/java/util/jar/OldJarFileTest.java
new file mode 100644
index 0000000..0da4d0e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldJarFileTest.java
@@ -0,0 +1,293 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.util.jar;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Permission;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
+
+public class OldJarFileTest extends TestCase {
+
+ private final String jarName = "hyts_patch.jar"; // a 'normal' jar file
+ private final String entryName = "foo/bar/A.class";
+ private File resources;
+
+ // custom security manager
+ SecurityManager sm = new SecurityManager() {
+ final String forbidenPermissionName = "user.dir";
+
+ public void checkPermission(Permission perm) {
+ if (perm.getName().equals(forbidenPermissionName)) {
+ throw new SecurityException();
+ }
+ }
+ };
+
+ @Override
+ protected void setUp() {
+ resources = Support_Resources.createTempFolder();
+ }
+
+ /**
+ * @tests java.util.jar.JarFile#JarFile(java.io.File)
+ */
+ public void test_ConstructorLjava_io_File() throws IOException {
+ try {
+ new JarFile(new File("Wrong.file"));
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ new JarFile(new File("tmp.jar"));
+ fail("Should throw SecurityException");
+ } catch (IOException e) {
+ fail("Should throw SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+
+ Support_Resources.copyFile(resources, null, jarName);
+ new JarFile(new File(resources, jarName));
+ }
+
+ /**
+ * @tests java.util.jar.JarFile#JarFile(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() throws IOException {
+ try {
+ new JarFile("Wrong.file");
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ new JarFile("tmp.jar");
+ fail("Should throw SecurityException");
+ } catch (IOException e) {
+ fail("Should throw SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+
+ Support_Resources.copyFile(resources, null, jarName);
+ String fileName = (new File(resources, jarName)).getCanonicalPath();
+ new JarFile(fileName);
+ }
+
+ /**
+ * @tests java.util.jar.JarFile#JarFile(java.lang.String, boolean)
+ */
+ public void test_ConstructorLjava_lang_StringZ() throws IOException {
+ try {
+ new JarFile("Wrong.file", false);
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ new JarFile("tmp.jar", true);
+ fail("Should throw SecurityException");
+ } catch (IOException e) {
+ fail("Should throw SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+
+ Support_Resources.copyFile(resources, null, jarName);
+ String fileName = (new File(resources, jarName)).getCanonicalPath();
+ new JarFile(fileName, true);
+ }
+
+ /**
+ * @tests java.util.jar.JarFile#JarFile(java.io.File, boolean)
+ */
+ public void test_ConstructorLjava_io_FileZ() throws IOException {
+ try {
+ new JarFile(new File("Wrong.file"), true);
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ new JarFile(new File("tmp.jar"), false);
+ fail("Should throw SecurityException");
+ } catch (IOException e) {
+ fail("Should throw SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+
+ Support_Resources.copyFile(resources, null, jarName);
+ new JarFile(new File(resources, jarName), false);
+ }
+
+ /**
+ * @tests java.util.jar.JarFile#JarFile(java.io.File, boolean, int)
+ */
+ public void test_ConstructorLjava_io_FileZI() {
+ try {
+ new JarFile(new File("Wrong.file"), true,
+ ZipFile.OPEN_READ);
+ fail("Should throw IOException");
+ } catch (IOException e) {
+ // expected
+ }
+ SecurityManager oldSm = System.getSecurityManager();
+ System.setSecurityManager(sm);
+ try {
+ new JarFile(new File("tmp.jar"), false,
+ ZipFile.OPEN_READ);
+ fail("Should throw SecurityException");
+ } catch (IOException e) {
+ fail("Should throw SecurityException");
+ } catch (SecurityException e) {
+ // expected
+ } finally {
+ System.setSecurityManager(oldSm);
+ }
+
+ try {
+ Support_Resources.copyFile(resources, null, jarName);
+ new JarFile(new File(resources, jarName), false,
+ ZipFile.OPEN_READ);
+ } catch (IOException e) {
+ fail("Should not throw IOException");
+ }
+
+ try {
+ Support_Resources.copyFile(resources, null, jarName);
+ new JarFile(new File(resources, jarName), false,
+ ZipFile.OPEN_READ | ZipFile.OPEN_DELETE + 33);
+ fail("Should throw IllegalArgumentException");
+ } catch (IOException e) {
+ fail("Should not throw IOException");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ }
+
+
+
+ public void test_close() throws IOException {
+ String modifiedJarName = "Modified_SF_EntryAttributes.jar";
+ Support_Resources.copyFile(resources, null, modifiedJarName);
+ JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
+ jarFile.entries();
+
+ jarFile.close();
+ jarFile.close();
+
+ // Can not check IOException
+ }
+
+ /**
+ * @throws IOException
+ * @tests java.util.jar.JarFile#getInputStream(java.util.zip.ZipEntry)
+ */
+ public void test_getInputStreamLjava_util_jar_JarEntry() throws IOException {
+ File localFile = null;
+ try {
+ Support_Resources.copyFile(resources, null, jarName);
+ localFile = new File(resources, jarName);
+ } catch (Exception e) {
+ fail("Failed to create local file: " + e);
+ }
+
+ byte[] b = new byte[1024];
+ try {
+ JarFile jf = new JarFile(localFile);
+ java.io.InputStream is = jf.getInputStream(jf.getEntry(entryName));
+ // BEGIN android-removed
+ // jf.close();
+ // END android-removed
+ assertTrue("Returned invalid stream", is.available() > 0);
+ int r = is.read(b, 0, 1024);
+ is.close();
+ StringBuffer sb = new StringBuffer(r);
+ for (int i = 0; i < r; i++) {
+ sb.append((char) (b[i] & 0xff));
+ }
+ String contents = sb.toString();
+ assertTrue("Incorrect stream read", contents.indexOf("bar") > 0);
+ // BEGIN android-added
+ jf.close();
+ // END android-added
+ } catch (Exception e) {
+ fail("Exception during test: " + e.toString());
+ }
+
+ try {
+ JarFile jf = new JarFile(localFile);
+ InputStream in = jf.getInputStream(new JarEntry("invalid"));
+ assertNull("Got stream for non-existent entry", in);
+ } catch (Exception e) {
+ fail("Exception during test 2: " + e);
+ }
+
+ try {
+ Support_Resources.copyFile(resources, null, jarName);
+ File signedFile = new File(resources, jarName);
+ JarFile jf = new JarFile(signedFile);
+ JarEntry jre = new JarEntry("foo/bar/A.class");
+ jf.getInputStream(jre);
+ // InputStream returned in any way, exception can be thrown in case
+ // of reading from this stream only.
+ // fail("Should throw ZipException");
+ } catch (ZipException ee) {
+ // expected
+ }
+
+ try {
+ Support_Resources.copyFile(resources, null, jarName);
+ File signedFile = new File(resources, jarName);
+ JarFile jf = new JarFile(signedFile);
+ JarEntry jre = new JarEntry("foo/bar/A.class");
+ jf.close();
+ jf.getInputStream(jre);
+ // InputStream returned in any way, exception can be thrown in case
+ // of reading from this stream only.
+ // The same for IOException
+ fail("Should throw IllegalStateException");
+ } catch (IllegalStateException ee) {
+ // expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldJarInputStreamTest.java b/luni/src/test/java/libcore/java/util/jar/OldJarInputStreamTest.java
new file mode 100644
index 0000000..77bb3ba
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldJarInputStreamTest.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.jar.JarInputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import tests.support.resource.Support_Resources;
+
+public class OldJarInputStreamTest extends junit.framework.TestCase {
+
+ public void test_ConstructorLjava_io_InputStreamZ() {
+ try {
+ // we need a buffered stream because ByteArrayInputStream.close() is a no-op
+ InputStream is = new BufferedInputStream(new ByteArrayInputStream(new byte[0]));
+ is.close();
+ new JarInputStream(is, false);
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ }
+
+
+ class Mock_JarInputStream extends JarInputStream {
+
+ public Mock_JarInputStream(InputStream in) throws IOException {
+ super(in);
+ }
+
+ public ZipEntry createZipEntry(String str) {
+ return super.createZipEntry(str);
+ }
+ }
+
+ public void test_createZipEntryLjava_lang_String() throws Exception {
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_entry.jar");
+ InputStream is = Support_Resources.getStream("Broken_entry.jar");
+ Mock_JarInputStream mjis = new Mock_JarInputStream(is);
+ assertNotNull(mjis.createZipEntry("New entry"));
+ }
+
+ public void test_read$ZII() throws Exception {
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_entry_data.jar");
+ InputStream is = Support_Resources.getStream("Broken_entry_data.jar");
+ JarInputStream jis = new JarInputStream(is, true);
+ byte b[] = new byte[100];
+
+ jis.getNextEntry();
+ jis.read(b, 0, 100);
+ jis.getNextEntry();
+ jis.getNextEntry();
+ jis.getNextEntry();
+
+ try {
+ jis.read(b, 0, 100);
+ fail("ZipException expected");
+ } catch (ZipException ee) {
+ // expected
+ }
+
+ try {
+ jis.close(); // Android throws exception here, already!
+ jis.read(b, 0, 100); // But RI here, only!
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldJarOutputStreamTest.java b/luni/src/test/java/libcore/java/util/jar/OldJarOutputStreamTest.java
new file mode 100644
index 0000000..e5e2f32
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldJarOutputStreamTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.jar;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+public class OldJarOutputStreamTest extends junit.framework.TestCase {
+
+ public void test_putNextEntryLjava_util_zip_ZipEntry() throws Exception {
+ final String entryName = "foo/bar/execjartest/MainClass.class";
+ Manifest newman = new Manifest();
+ File outputJar = File.createTempFile("hyts_", ".jar");
+ OutputStream os = new FileOutputStream(outputJar);
+ JarOutputStream jout = new JarOutputStream(os, newman);
+ os.close();
+ try {
+ jout.putNextEntry(new JarEntry(entryName));
+ fail("IOException expected");
+ } catch (IOException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java b/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java
new file mode 100644
index 0000000..9552aef
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/jar/OldManifestTest.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package libcore.java.util.jar;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
+
+public class OldManifestTest extends TestCase {
+
+ public void test_ConstructorLjava_util_jar_Manifest() {
+ // Test for method java.util.jar.Manifest()
+ Manifest emptyManifest = new Manifest();
+ Manifest emptyClone = new Manifest(emptyManifest);
+ assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
+ assertTrue("Should have no main attributes", emptyClone
+ .getMainAttributes().isEmpty());
+ assertEquals(emptyClone, emptyManifest);
+ assertEquals(emptyClone, emptyManifest.clone());
+ }
+
+ private void assertAttribute(Attributes attr, String name, String value) {
+ assertEquals("Incorrect " + name, value, attr.getValue(name));
+ }
+
+ private void checkManifest(Manifest manifest) {
+ Attributes main = manifest.getMainAttributes();
+ assertAttribute(main, "Bundle-Name", "ClientSupport");
+ assertAttribute(main, "Bundle-Description",
+ "Provides SessionService, AuthenticationService. Extends RegistryService.");
+ assertAttribute(main, "Bundle-Activator",
+ "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
+ assertAttribute(
+ main,
+ "Import-Package",
+ "com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log; specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client");
+ assertAttribute(
+ main,
+ "Import-Service",
+ "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
+ assertAttribute(
+ main,
+ "Export-Package",
+ "com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0");
+ assertAttribute(
+ main,
+ "Export-Service",
+ "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
+ assertAttribute(main, "Bundle-Vendor", "IBM");
+ assertAttribute(main, "Bundle-Version", "1.2.0");
+ }
+
+ public void test_clone() throws IOException {
+ Manifest emptyManifest = new Manifest();
+ Manifest emptyClone = (Manifest) emptyManifest.clone();
+ assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
+ assertTrue("Should have no main attributes", emptyClone
+ .getMainAttributes().isEmpty());
+ assertEquals(emptyClone, emptyManifest);
+ assertEquals(emptyManifest.clone().getClass().getName(),
+ "java.util.jar.Manifest");
+
+ Manifest manifest = new Manifest(new URL(Support_Resources
+ .getURL("manifest/hyts_MANIFEST.MF")).openStream());
+ Manifest manifestClone = (Manifest) manifest.clone();
+ manifestClone.getMainAttributes();
+ checkManifest(manifestClone);
+ }
+
+ public void test_equals() throws IOException {
+ Manifest manifest1 = new Manifest(new URL(Support_Resources.getURL(
+ "manifest/hyts_MANIFEST.MF")).openStream());
+ Manifest manifest2 = new Manifest(new URL(Support_Resources.getURL(
+ "manifest/hyts_MANIFEST.MF")).openStream());
+ Manifest manifest3 = new Manifest();
+
+ assertTrue(manifest1.equals(manifest1));
+ assertTrue(manifest1.equals(manifest2));
+ assertFalse(manifest1.equals(manifest3));
+ assertFalse(manifest1.equals(this));
+ }
+
+ public void test_writeLjava_io_OutputStream() throws IOException {
+ byte b[];
+ Manifest manifest1 = null;
+ Manifest manifest2 = null;
+ try {
+ manifest1 = new Manifest(new URL(Support_Resources
+ .getURL("manifest/hyts_MANIFEST.MF")).openStream());
+ } catch (MalformedURLException e) {
+ fail("Malformed URL");
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ manifest1.write(baos);
+
+ b = baos.toByteArray();
+
+ File f = File.createTempFile("111", "111");
+ FileOutputStream fos = new FileOutputStream(f);
+ fos.close();
+ try {
+ manifest1.write(fos);
+ fail("IOException expected");
+ } catch (IOException e) {
+ // expected
+ }
+ f.delete();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(b);
+
+ try {
+ manifest2 = new Manifest(bais);
+ } catch (MalformedURLException e) {
+ fail("Malformed URL");
+ }
+
+ assertTrue(manifest1.equals(manifest2));
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java b/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java
new file mode 100644
index 0000000..7f0c9b6
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/prefs/OldAbstractPreferencesTest.java
@@ -0,0 +1,1144 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.prefs;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.InvalidPreferencesFormatException;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+import junit.framework.TestCase;
+
+public final class OldAbstractPreferencesTest extends TestCase {
+
+ static final String nodeName = "mock";
+
+ AbstractPreferences pref;
+ AbstractPreferences root;
+ AbstractPreferences parent = null;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ root = (AbstractPreferences) Preferences.userRoot();
+ parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass());
+
+ pref = (AbstractPreferences) parent.node(nodeName);
+ }
+
+ public void testToString() {
+ assertTrue(pref.toString().contains(nodeName));
+ }
+
+ public void testPut() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.flush();
+
+ assertEquals("String", pref.get("Value", ":"));
+
+ try {
+ pref.put(null, "Exception");
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.put(new String(sb), "Exception");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_VALUE_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.put("DoubleValue", new String(sb));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.put("DoubleValue", "Exception");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGet() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertEquals("String", pref.get("Value", ":"));
+ assertEquals("true", pref.get("BoolValue", ":"));
+ assertEquals("9.10938188E-31", pref.get("DoubleValue", null));
+
+ try {
+ pref.get(null, "Exception");
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.get("DoubleValue", "Exception");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testRemove() throws BackingStoreException {
+ String[] keyArray = new String[]{"Value", "DoubleValue", "LongValue", "IntValue"};
+ pref.put(keyArray[0], "String");
+ pref.putDouble(keyArray[1], new Double(9.10938188e-31));
+ pref.putLong(keyArray[2], new Long(Long.MIN_VALUE));
+ pref.putInt(keyArray[3], 299792458);
+ pref.node("New node");
+ pref.flush();
+
+ String[] str = pref.keys();
+ assertEquals(keyArray.length, str.length);
+ for(int i = 0; i < keyArray.length; i++) {
+ pref.remove(keyArray[i]);
+ str = pref.keys();
+ assertEquals(keyArray.length - i - 1, str.length);
+ }
+ assertEquals(1, pref.childrenNames().length);
+ pref.remove("New node");
+ assertEquals(1, pref.childrenNames().length);
+
+ pref.removeNode();
+
+ try {
+ pref.remove("New node");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testClear() throws BackingStoreException {
+ AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
+ pref.putInt("IntValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+ pref.clear();
+ assertFalse(pref.getBoolean("BoolValue", false));
+ assertEquals(22, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+
+ pref.removeNode();
+
+ try {
+ pref.clear();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ ap.clear();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutInt() throws BackingStoreException {
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
+
+ try {
+ pref.putInt(null, new Integer(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putInt(new String(sb), new Integer(1));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putInt("IntValue", new Integer(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetInt() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putLong("LongValue", new Long(Long.MIN_VALUE));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(1, pref.getInt("Value", new Integer(1)));
+ assertEquals(1, pref.getInt("LongValue", new Integer(1)));
+ assertEquals(1, pref.getInt("DoubleValue", new Integer(1)));
+ assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
+
+ try {
+ pref.getInt(null, new Integer(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getInt("IntValue", new Integer(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutLong() throws BackingStoreException {
+ pref.putLong("LongValue", new Long(299792458));
+ pref.flush();
+
+ assertEquals(299792458L, pref.getLong("LongValue", new Long(1)));
+
+ try {
+ pref.putLong(null, new Long(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putLong(new String(sb), new Long(1));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putLong("LongValue", new Long(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetLong() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putLong("LongValue", new Long(Long.MIN_VALUE));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(1L, pref.getLong("Value", new Long(1)));
+ assertEquals(Long.MIN_VALUE, pref.getLong("LongValue", new Long(1)));
+ assertEquals(1L, pref.getLong("DoubleValue", new Long(1)));
+ assertEquals(299792458L, pref.getLong("IntValue", new Long(1)));
+
+ try {
+ pref.getLong(null, new Long(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getLong("LongValue", new Long(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutBoolean() throws BackingStoreException {
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+
+ try {
+ pref.putBoolean(null, true);
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putBoolean(new String(sb), true);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putBoolean("DoubleValue", true);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetBoolean() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertFalse(pref.getBoolean("Value", false));
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertFalse(pref.getBoolean("DoubleValue", false));
+
+ try {
+ pref.getBoolean(null, true);
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getBoolean("DoubleValue", true);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutFloat() throws BackingStoreException {
+ pref.putFloat("FloatValue", new Float(1.602e-19));
+ pref.flush();
+
+ assertEquals(new Float(1.602e-19), pref.getFloat("FloatValue", new Float(0.2)));
+
+ try {
+ pref.putFloat(null, new Float(0.1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putFloat(new String(sb), new Float(0.1));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putFloat("FloatValue", new Float(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetFloat() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putFloat("FloatValue", new Float(-0.123));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(new Float(0.1), pref.getFloat("Value", new Float(0.1)));
+ assertEquals(new Float(-0.123), pref.getFloat("FloatValue", new Float(0.2)));
+ assertEquals(new Float(9.109382e-31), pref.getFloat("DoubleValue", new Float(2.14)));
+ assertEquals(new Float(2.99792448e8), pref.getFloat("IntValue", new Float(5)));
+
+ try {
+ pref.getFloat(null, new Float(0.1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getFloat("FloatValue", new Float(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutDouble() throws BackingStoreException {
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.flush();
+
+ assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
+
+ try {
+ pref.putDouble(null, new Double(0.1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putDouble(new String(sb), new Double(0.1));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putDouble("DoubleValue", new Double(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetDouble() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(new Double(0.1), pref.getDouble("Value", new Double(0.1)));
+ assertEquals(new Double(0.2), pref.getDouble("BoolValue", new Double(0.2)));
+ assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
+ assertEquals(new Double(2.99792458e8), pref.getDouble("IntValue", new Double(5)));
+
+ try {
+ pref.getDouble(null, new Double(0.1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getDouble("DoubleValue", new Double(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testPutByteArray() throws BackingStoreException {
+ byte[] bArray = new byte[]{1, 2, 3, 4, 5};
+ byte[] array = null;
+ int i;
+ pref.putByteArray("Array", bArray);
+ pref.flush();
+
+ array = pref.getByteArray("Array", null);
+ assertEquals(bArray.length, array.length);
+ for(i = 0; i < bArray.length; i++) {
+ assertEquals(bArray[i], array[i]);
+ }
+
+ try {
+ pref.putByteArray(null, bArray);
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
+ try {
+ pref.putByteArray(new String(sb), bArray);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ bArray = new byte[Preferences.MAX_VALUE_LENGTH * 3 / 4 + 1];
+
+ try {
+ pref.putByteArray("Big array", bArray);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.putByteArray("Array", new byte[10]);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testGetByteArray() throws BackingStoreException {
+ byte[] bArray = new byte[]{1, 2, 3, 4, 5};
+ byte[] tmp = new byte[]{5};
+ byte[] array = null;
+ int i;
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putByteArray("Array", bArray);
+ pref.flush();
+
+ array = pref.getByteArray("Value", tmp);
+ assertEquals(tmp.length, array.length);
+ for(i = 0; i < tmp.length; i++) {
+ assertEquals(tmp[i], array[i]);
+ }
+
+ array = pref.getByteArray("DoubleValue", tmp);
+ assertEquals(tmp.length, array.length);
+ for(i = 0; i < tmp.length; i++) {
+ assertEquals(tmp[i], array[i]);
+ }
+
+ array = pref.getByteArray("Array", tmp);
+ assertEquals(bArray.length, array.length);
+ for(i = 0; i < bArray.length; i++) {
+ assertEquals(bArray[i], array[i]);
+ }
+
+ try {
+ pref.getByteArray(null, tmp);
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getByteArray("Array", tmp);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testKeys() throws BackingStoreException {
+ String[] keyArray = new String[]{"Value", "DoubleValue", "BoolValue", "IntValue"};
+ String nodeStr = "New node";
+ pref.node(nodeStr);
+ pref.put(keyArray[0], "String");
+ pref.putDouble(keyArray[1], new Double(9.10938188e-31));
+ pref.putBoolean(keyArray[2], true);
+ pref.putInt(keyArray[3], 299792458);
+ pref.flush();
+
+ String[] str = pref.keys();
+ assertEquals(keyArray.length, str.length);
+ for(int i = 0; i < str.length; i++) {
+ boolean flag = false;
+ for(int j = 0; j < keyArray.length; j++) {
+ if (str[i].compareTo(keyArray[j]) == 0) {
+ flag = true;
+ break;
+ }
+ }
+ assertTrue(str[i].compareTo(nodeStr) != 0);
+ assertTrue(flag);
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.keys();
+ fail("IllegalStateException expected");
+ } catch(IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testChildrenNames() throws BackingStoreException {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
+
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(0, first.childrenNames().length);
+ assertEquals(0, second.childrenNames().length);
+
+ second.removeNode();
+
+ try {
+ second.childrenNames();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ first.childrenNames();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void test_nodeExists() throws BackingStoreException {
+ AbstractPreferences test = (AbstractPreferences) Preferences.userRoot()
+ .node("test");
+ try {
+ test.nodeExists(null);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+
+ test.removeNode();
+ try {
+ test.nodeExists(null);
+ fail("should throw NullPointerException");
+ } catch (NullPointerException e) {
+ // Expected
+ }
+ }
+
+ public void testParent() throws BackingStoreException {
+ AbstractPreferences node = (AbstractPreferences) pref.node("First node/sub node");
+
+ assertTrue(node.parent().name().compareTo("First node") == 0);
+
+ pref.removeNode();
+
+ try {
+ node.parent();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testNode() throws BackingStoreException {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
+
+ try {
+ first.node("blabla/");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ try {
+ first.node("///invalid");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
+ sb.append('c');
+ }
+ first.node(new String(sb));
+ sb.append('c');
+
+ try {
+ first.node(new String(sb));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ second.removeNode();
+
+ try {
+ second.node("");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ pref.removeNode();
+ try {
+ first.node("");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testNodeExists() throws BackingStoreException {
+ AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
+ pref.putInt("IntegerValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertTrue(pref.nodeExists("First node"));
+ assertTrue(pref.nodeExists("Second node"));
+ assertFalse(pref.nodeExists("IntegerValue"));
+ assertFalse(pref.nodeExists("BoolValue"));
+ assertFalse(pref.nodeExists("Value"));
+ assertFalse(pref.nodeExists(nodeName));
+
+ try {
+ pref.nodeExists("///invalid");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.nodeExists("Exception");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ public void testRemoveNode() throws BackingStoreException {
+ String[] nodeArray = new String[]{"First node", "Second node", "Last node"};
+ int i;
+ pref.put("Key", "String");
+ for (i = 0; i < nodeArray.length; i++) {
+ pref.node(nodeArray[i]);
+ }
+ pref.flush();
+
+ String[] str = pref.childrenNames();
+ assertEquals(nodeArray.length, str.length);
+ for(i = 0; i < nodeArray.length; i++) {
+ pref.node(nodeArray[i]).removeNode();
+ str = pref.childrenNames();
+ assertEquals(nodeArray.length - i - 1, str.length);
+ }
+ assertEquals(1, pref.keys().length);
+ pref.node("Key").removeNode();
+ assertEquals(1, pref.keys().length);
+
+ pref.removeNode();
+
+ try {
+ pref.removeNode();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ root.removeNode();
+ fail("UnsupportedOperationException expected");
+ } catch (UnsupportedOperationException e) {
+ //expected
+ }
+ }
+
+ public void testName() {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node/sub node");
+
+ assertTrue(first.name().compareTo("First node") == 0);
+ assertFalse(first.name().compareTo("Second node") == 0);
+ assertTrue(second.name().compareTo("sub node") == 0);
+ }
+
+ public void testAbsolutePath() {
+ assertEquals(parent.absolutePath() + "/" + nodeName, pref.absolutePath());
+ assertEquals(parent.absolutePath() + "/" + "new node", parent.node("new node").absolutePath());
+ }
+
+ public void testIsUserNode() {
+ assertTrue(parent.isUserNode());
+ assertFalse(Preferences.systemRoot().isUserNode());
+ }
+
+ public void testSync() throws BackingStoreException {
+ pref.node("new node/sub node");
+ pref.sync();
+
+ pref.removeNode();
+
+ try {
+ pref.sync();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ }
+
+ class MockPreferenceChangeListener implements PreferenceChangeListener {
+ private boolean flagChange = false;
+
+ public void preferenceChange(PreferenceChangeEvent arg0) {
+ flagChange = true;
+ }
+
+ public boolean isChanged () {
+ boolean retVal = flagChange;
+ flagChange = false;
+ return retVal;
+ }
+ }
+
+ public void testAddPreferenceChangeListener() throws BackingStoreException {
+ MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
+ parent.addPreferenceChangeListener(mpcl);
+ assertFalse(mpcl.isChanged());
+ pref.node("new node");
+ pref.flush();
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ parent.node("new node");
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ parent.flush();
+ assertTrue(mpcl.isChanged());
+ assertEquals(33, parent.getInt("IntValue", 22));
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ assertEquals(22, parent.getInt("Missed Value", 22));
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ }
+
+ public void testRemovePreferenceChangeListener() throws BackingStoreException {
+ MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
+ parent.addPreferenceChangeListener(mpcl);
+ assertFalse(mpcl.isChanged());
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ assertTrue(mpcl.isChanged());
+ parent.removePreferenceChangeListener(mpcl);
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ }
+
+ class MockNodeChangeListener implements NodeChangeListener {
+ private boolean flagAdded = false;
+ private boolean flagRemoved = false;
+
+ public void childAdded(NodeChangeEvent arg0) {
+ flagAdded = true;
+ }
+
+ public void childRemoved(NodeChangeEvent arg0) {
+ flagRemoved = true;
+ }
+
+ public boolean isAdded() {
+ return flagAdded;
+ }
+
+ public boolean isRemoved() {
+ return flagRemoved;
+ }
+ }
+
+ public void testAddNodeChangeListener() throws BackingStoreException {
+ MockNodeChangeListener mncl = new MockNodeChangeListener();
+ parent.addNodeChangeListener(mncl);
+ pref.node("test");
+ pref.flush();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ pref.removeNode();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertTrue(mncl.isRemoved());
+ parent.node("new node");
+ parent.flush();
+ assertTrue(mncl.isAdded());
+ assertTrue(mncl.isRemoved());
+ }
+
+ public void testRemoveNodeChangeListener() throws BackingStoreException {
+ MockNodeChangeListener mncl = new MockNodeChangeListener();
+ parent.addNodeChangeListener(mncl);
+ pref.node("test");
+ pref.flush();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ parent.removeNodeChangeListener(mncl);
+ pref.removeNode();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ parent.node("new node");
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ }
+
+ public void testExportNode() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
+ AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
+ pref.putInt("IntValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ pref.exportNode(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+
+ String xmlData = new String(baos.toByteArray());
+
+ assertTrue(xmlData.contains("IntValue"));
+ assertTrue(xmlData.contains("BoolValue"));
+ assertTrue(xmlData.contains("33"));
+ assertTrue(xmlData.contains("true"));
+
+ pref.removeNode();
+
+ try {
+ pref.exportNode(new ByteArrayOutputStream());
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ pref.getBoolean("BoolValue", false);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ pref = (AbstractPreferences) parent.node(nodeName);
+
+ pref.importPreferences(bais);
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(0, pref.childrenNames().length);
+ }
+
+ public void testExportSubtree() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
+ AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
+ pref.putInt("IntegerValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ ap1.putInt("FirstIntValue", 11);
+ ap2.putDouble("DoubleValue", new Double(6.626e-34));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ pref.exportSubtree(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntegerValue", 22));
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(11, ap1.getInt("FirstIntValue", 22));
+ assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
+
+ String xmlData = new String(baos.toByteArray());
+
+ assertTrue(xmlData.contains("IntegerValue"));
+ assertTrue(xmlData.contains("BoolValue"));
+ assertTrue(xmlData.contains("FirstIntValue"));
+ assertTrue(xmlData.contains("DoubleValue"));
+ assertTrue(xmlData.contains("33"));
+ assertTrue(xmlData.contains("true"));
+ assertTrue(xmlData.contains("11"));
+ assertTrue(xmlData.contains("6.626E-34"));
+
+ pref.removeNode();
+
+ try {
+ pref.exportSubtree(new ByteArrayOutputStream());
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+
+ try {
+ pref.getBoolean("BoolValue", false);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ pref = (AbstractPreferences) parent.node(nodeName);
+ pref.importPreferences(bais);
+
+ ap1 = (AbstractPreferences) pref.node("First node");
+ ap2 = (AbstractPreferences) pref.node("Second node");
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntegerValue", 22));
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(11, ap1.getInt("FirstIntValue", 22));
+ assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
+ }
+
+ class MockAbstractPreferences extends AbstractPreferences {
+ protected MockAbstractPreferences(AbstractPreferences parent, String name) {
+ super(parent, name);
+ }
+
+ @Override
+ protected AbstractPreferences childSpi(String name) {
+ return null;
+ }
+
+ @Override
+ protected String[] childrenNamesSpi() throws BackingStoreException {
+ return null;
+ }
+
+ @Override
+ protected void flushSpi() throws BackingStoreException {
+ }
+
+ @Override
+ protected String getSpi(String key) {
+ return null;
+ }
+
+ @Override
+ protected String[] keysSpi() throws BackingStoreException {
+ return null;
+ }
+
+ @Override
+ protected void putSpi(String key, String value) {
+ }
+
+ @Override
+ protected void removeNodeSpi() throws BackingStoreException {
+ }
+
+ @Override
+ protected void removeSpi(String key) {
+ }
+
+ @Override
+ protected void syncSpi() throws BackingStoreException {
+ }
+ }
+
+ public void testAbstractPreferences() {
+ assertNotNull(new MockAbstractPreferences(pref, "node name"));
+ try {
+ new MockAbstractPreferences(pref, "node/name");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ try {
+ new MockAbstractPreferences(null, "node");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
+ }
+ }
+
+ public void testCachedChildren() throws BackingStoreException {
+ pref.node("First node");
+ pref.node("Second node");
+
+ assertEquals(2, pref.childrenNames().length);
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java b/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java
new file mode 100644
index 0000000..93ba485
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/prefs/OldFilePreferencesImplTest.java
@@ -0,0 +1,73 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.prefs;
+
+import java.util.prefs.Preferences;
+import junit.framework.TestCase;
+
+public final class OldFilePreferencesImplTest extends TestCase {
+
+ // AndroidOnly: the RI can't remove nodes created in the system root.
+ public void testSystemChildNodes() throws Exception {
+ Preferences sroot = Preferences.systemRoot().node("test");
+
+ Preferences child1 = sroot.node("child1");
+ Preferences child2 = sroot.node("child2");
+ Preferences grandchild = child1.node("grand");
+
+ String[] childNames = sroot.childrenNames();
+ assertContains(childNames, "child1");
+ assertContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
+
+ childNames = child1.childrenNames();
+ assertEquals(1, childNames.length);
+
+ childNames = child2.childrenNames();
+ assertEquals(0, childNames.length);
+
+ child1.removeNode();
+ childNames = sroot.childrenNames();
+ assertNotContains(childNames, "child1");
+ assertContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
+
+ child2.removeNode();
+ childNames = sroot.childrenNames();
+ assertNotContains(childNames, "child1");
+ assertNotContains(childNames, "child2");
+ assertNotContains(childNames, "grand");
+ sroot.removeNode();
+ }
+
+ private void assertContains(String[] childNames, String name) {
+ for (String childName : childNames) {
+ if (childName == name) {
+ return;
+ }
+ }
+ fail("No child with name " + name + " was found. It was expected to exist.");
+ }
+
+ private void assertNotContains(String[] childNames, String name) {
+ for (String childName : childNames) {
+ if (childName == name) {
+ fail("Child with name " + name + " was found. This was unexpected.");
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java b/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java
new file mode 100644
index 0000000..b3f57b8
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/prefs/OldNodeChangeEventTest.java
@@ -0,0 +1,168 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.prefs;
+
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.Preferences;
+import junit.framework.TestCase;
+
+public final class OldNodeChangeEventTest extends TestCase {
+
+ public void testGetChild() throws BackingStoreException {
+ AbstractPreferences parent = (AbstractPreferences) Preferences
+ .userNodeForPackage(Preferences.class);
+
+ AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
+
+ MockNodeChangeListener nl = new MockNodeChangeListener() {
+ public synchronized void childAdded(NodeChangeEvent e) {
+ Preferences child = e.getChild();
+ if (child == null) {
+ addResult = false;
+ } else {
+ if (child.name() == "mock1") {
+ addResult = true;
+ }
+ }
+ super.childAdded(e);
+ }
+
+ public synchronized void childRemoved(NodeChangeEvent e) {
+ Preferences child = e.getChild();
+ if (child == null) {
+ removeResult = false;
+ } else {
+ if (child.name() == "mock1") {
+ removeResult = true;
+ }
+ }
+ super.childRemoved(e);
+ }
+ };
+ try {
+ pref.addNodeChangeListener(nl);
+ Preferences child1 = pref.node("mock1");
+ nl.waitForEvent();
+ assertEquals(1, nl.getAdded());
+ assertTrue(nl.getAddResult());
+ nl.reset();
+ child1.removeNode();
+ nl.waitForEvent();
+ assertEquals(1, nl.getRemoved());
+ assertTrue(nl.getRemoveResult());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ }
+ }
+
+ public void testGetParent() throws BackingStoreException {
+ AbstractPreferences parent = (AbstractPreferences) Preferences
+ .userNodeForPackage(Preferences.class);
+
+ AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
+
+ MockNodeChangeListener nl = new MockNodeChangeListener() {
+ public synchronized void childAdded(NodeChangeEvent e) {
+ Preferences parent = e.getParent();
+ if (parent == null) {
+ addResult = false;
+ } else {
+ if (parent.name() == "mock") {
+ addResult = true;
+ }
+ }
+ super.childAdded(e);
+ }
+
+ public synchronized void childRemoved(NodeChangeEvent e) {
+ Preferences parent = e.getParent();
+ if (parent == null) {
+ removeResult = false;
+ } else {
+ if (parent.name() == "mock") {
+ removeResult = true;
+ }
+ }
+ super.childRemoved(e);
+ }
+ };
+ try {
+ pref.addNodeChangeListener(nl);
+ Preferences child1 = pref.node("mock1");
+ nl.waitForEvent();
+ assertEquals(1, nl.getAdded());
+ assertTrue(nl.getAddResult());
+ nl.reset();
+ child1.removeNode();
+ nl.waitForEvent();
+ assertEquals(1, nl.getRemoved());
+ assertTrue(nl.getRemoveResult());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ }
+ }
+
+ private static class MockNodeChangeListener implements NodeChangeListener {
+ private int added = 0;
+ private int removed = 0;
+ protected boolean addResult = false;
+ protected boolean removeResult = false;
+
+ public synchronized void waitForEvent() {
+ try {
+ wait(500);
+ } catch (InterruptedException ignored) {
+ }
+ }
+
+ public synchronized void childAdded(NodeChangeEvent e) {
+ ++added;
+ notifyAll();
+ }
+
+ public synchronized void childRemoved(NodeChangeEvent e) {
+ removed++;
+ notifyAll();
+ }
+
+ public synchronized boolean getAddResult() {
+ return addResult;
+ }
+
+ public synchronized boolean getRemoveResult() {
+ return removeResult;
+ }
+
+ public synchronized int getAdded() {
+ return added;
+ }
+
+ public synchronized int getRemoved() {
+ return removed;
+ }
+
+ public void reset() {
+ added = 0;
+ removed = 0;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java
new file mode 100644
index 0000000..be559ed
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/prefs/OldPreferenceChangeEventTest.java
@@ -0,0 +1,156 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.prefs;
+
+import java.util.prefs.AbstractPreferences;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+import junit.framework.TestCase;
+
+public final class OldPreferenceChangeEventTest extends TestCase {
+
+ public void testGetKey() {
+ AbstractPreferences parent = (AbstractPreferences) Preferences
+ .userNodeForPackage(Preferences.class);
+
+ AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
+
+ MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {
+ public void preferenceChange(PreferenceChangeEvent pce) {
+ if (pce != null && pce.getKey().equals("key_int")) {
+ result = true;
+ }
+ super.preferenceChange(pce);
+ }
+ };
+ pref.addPreferenceChangeListener(pl);
+ try {
+ pref.putInt("key_int", Integer.MAX_VALUE);
+ assertEquals(1, pl.getChanged());
+ assertTrue(pl.getResult());
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ }
+ }
+
+ public void testGetNewValue() {
+ AbstractPreferences parent = (AbstractPreferences) Preferences
+ .userNodeForPackage(Preferences.class);
+
+ AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
+
+ MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {
+ public void preferenceChange(PreferenceChangeEvent pce) {
+ if (pce != null && pce.getNewValue().equals(Integer.toString(Integer.MAX_VALUE))) {
+ result = true;
+ }
+ super.preferenceChange(pce);
+ }
+ };
+ pref.addPreferenceChangeListener(pl);
+ try {
+ pref.putInt("key_int", Integer.MAX_VALUE);
+ assertEquals(1, pl.getChanged());
+ assertTrue(pl.getResult());
+ pl.reset();
+
+ pref.putInt("key_int", Integer.MAX_VALUE);
+ assertEquals(1, pl.getChanged());
+ assertTrue(pl.getResult());
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ }
+ }
+
+ public void testGetNode() {
+ AbstractPreferences parent = (AbstractPreferences) Preferences
+ .userNodeForPackage(Preferences.class);
+
+ AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
+
+ MockPreferenceChangeListener pl = new MockPreferenceChangeListener() {
+ public void preferenceChange(PreferenceChangeEvent pce) {
+ if (pce != null && "mock".equals(pce.getNode().name())) {
+ result = true;
+ }
+ super.preferenceChange(pce);
+ }
+ };
+ pref.addPreferenceChangeListener(pl);
+ try {
+ pref.putInt("key_int", Integer.MAX_VALUE);
+ assertEquals(1, pl.getChanged());
+ assertTrue(pl.getResult());
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ }
+ }
+
+ private static class MockPreferenceChangeListener implements PreferenceChangeListener {
+ private int changed = 0;
+ private boolean addDispatched = false;
+ protected boolean result = false;
+
+ public synchronized void waitForEvent() {
+ try {
+ wait(500);
+ } catch (InterruptedException ignored) {
+ }
+ }
+
+ public synchronized void preferenceChange(PreferenceChangeEvent pce) {
+ changed++;
+ addDispatched = true;
+ notifyAll();
+ }
+
+ public synchronized boolean getResult() {
+ if (!addDispatched) {
+ try {
+ // TODO: don't know why must add limitation
+ this.wait(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ addDispatched = false;
+ return result;
+ }
+
+ public synchronized int getChanged() {
+ if (!addDispatched) {
+ try {
+ // TODO: don't know why must add limitation
+ this.wait(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ addDispatched = false;
+ return changed;
+ }
+
+ public void reset() {
+ changed = 0;
+ result = false;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/prefs/OldPreferencesTest.java b/luni/src/test/java/libcore/java/util/prefs/OldPreferencesTest.java
new file mode 100644
index 0000000..a12618e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/prefs/OldPreferencesTest.java
@@ -0,0 +1,1177 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.prefs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.NodeChangeEvent;
+import java.util.prefs.NodeChangeListener;
+import java.util.prefs.PreferenceChangeEvent;
+import java.util.prefs.PreferenceChangeListener;
+import java.util.prefs.Preferences;
+import junit.framework.TestCase;
+
+public final class OldPreferencesTest extends TestCase {
+
+ final static String longKey;
+ final static String longValue;
+
+ static {
+ StringBuffer key = new StringBuffer(Preferences.MAX_KEY_LENGTH);
+ for (int i = 0; i < Preferences.MAX_KEY_LENGTH; i++) {
+ key.append('a');
+ }
+ longKey = key.toString();
+
+ StringBuffer value = new StringBuffer(Preferences.MAX_VALUE_LENGTH);
+ for (int i = 0; i < Preferences.MAX_VALUE_LENGTH; i++) {
+ value.append('a');
+ }
+ longValue = value.toString();
+ }
+
+ public void testAbstractMethods() {
+ Preferences p = new MockPreferences();
+ p.absolutePath();
+ try {
+ p.childrenNames();
+ } catch (BackingStoreException e4) {
+ }
+ try {
+ p.clear();
+ } catch (BackingStoreException e5) {
+ }
+ try {
+ p.exportNode(null);
+ } catch (IOException e6) {
+ } catch (BackingStoreException e6) {
+ }
+ try {
+ p.exportSubtree(null);
+ } catch (IOException e7) {
+ } catch (BackingStoreException e7) {
+ }
+ try {
+ p.flush();
+ } catch (BackingStoreException e8) {
+ }
+ p.get(null, null);
+ p.getBoolean(null, false);
+ p.getByteArray(null, null);
+ p.getFloat(null, 0.1f);
+ p.getDouble(null, 0.1);
+ p.getInt(null, 1);
+ p.getLong(null, 1l);
+ p.isUserNode();
+ try {
+ p.keys();
+ } catch (BackingStoreException e) {
+ }
+ p.name();
+ p.node(null);
+ try {
+ p.nodeExists(null);
+ } catch (BackingStoreException e1) {
+ }
+ p.parent();
+ p.put(null, null);
+ p.putBoolean(null, false);
+ p.putByteArray(null, null);
+ p.putDouble(null, 1);
+ p.putFloat(null, 1f);
+ p.putInt(null, 1);
+ p.putLong(null, 1l);
+ p.remove(null);
+ try {
+ p.removeNode();
+ } catch (BackingStoreException e2) {
+ }
+ p.addNodeChangeListener(null);
+ p.addPreferenceChangeListener(null);
+ p.removeNodeChangeListener(null);
+ p.removePreferenceChangeListener(null);
+ try {
+ p.sync();
+ } catch (BackingStoreException e3) {
+ }
+ p.toString();
+ }
+
+ public void testConstructor() {
+ MockPreferences mp = new MockPreferences();
+ assertEquals(mp.getClass(), MockPreferences.class);
+ }
+
+ public void testToString() {
+ Preferences p1 = Preferences.userNodeForPackage(Preferences.class);
+ assertNotNull(p1.toString());
+
+ Preferences p2 = Preferences.systemRoot();
+ assertNotNull(p2.toString());
+
+ Preferences p3 = Preferences.userRoot();
+ assertNotNull(p3.toString());
+ }
+
+ public void testAbsolutePath() {
+ Preferences p = Preferences.userNodeForPackage(Preferences.class);
+ assertEquals("/java/util/prefs", p.absolutePath());
+
+ }
+
+ public void testChildrenNames() throws BackingStoreException {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+
+ Preferences child1 = pref.node("child1");
+
+ pref.node("child2");
+ pref.node("child3");
+ child1.node("subchild1");
+
+ assertSame(pref, child1.parent());
+ assertEquals(3, pref.childrenNames().length);
+ assertEquals("child1", pref.childrenNames()[0]);
+ assertEquals(1, child1.childrenNames().length);
+ assertEquals("subchild1", child1.childrenNames()[0]);
+ }
+
+ public void testClear() throws BackingStoreException {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ pref.put("testClearKey", "testClearValue");
+ pref.put("testClearKey1", "testClearValue1");
+ assertEquals("testClearValue", pref.get("testClearKey", null));
+ assertEquals("testClearValue1", pref.get("testClearKey1", null));
+ pref.clear();
+ assertNull(pref.get("testClearKey", null));
+ assertNull(pref.get("testClearKey1", null));
+ }
+
+ public void testGet() throws BackingStoreException {
+ Preferences root = Preferences.userNodeForPackage(Preferences.class);
+ Preferences pref = root.node("mock");
+ assertNull(pref.get("", null));
+ assertEquals("default", pref.get("key", "default"));
+ assertNull(pref.get("key", null));
+ pref.put("testGetkey", "value");
+ assertNull(pref.get("testGetKey", null));
+ assertEquals("value", pref.get("testGetkey", null));
+
+ try {
+ pref.get(null, "abc");
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.get("", "abc");
+ pref.get("key", null);
+ pref.get("key", "");
+ pref.putFloat("floatKey", 1.0f);
+ assertEquals("1.0", pref.get("floatKey", null));
+
+ pref.removeNode();
+ try {
+ pref.get("key", "abc");
+ fail();
+ } catch (IllegalStateException e) {
+ }
+ try {
+ pref.get(null, "abc");
+ fail();
+ } catch (NullPointerException e) {
+ }
+ }
+
+ public void testGetBoolean() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getBoolean(null, false);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.put("testGetBooleanKey", "false");
+ pref.put("testGetBooleanKey2", "value");
+ assertFalse(pref.getBoolean("testGetBooleanKey", true));
+ assertTrue(pref.getBoolean("testGetBooleanKey2", true));
+ }
+
+ public void testGetByteArray() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getByteArray(null, new byte[0]);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ byte[] b64Array = new byte[] { 0x59, 0x57, 0x4a, 0x6a };// BASE64
+
+ pref.put("testGetByteArrayKey", "abc=");
+ pref.put("testGetByteArrayKey2", new String(b64Array));
+ pref.put("invalidKey", "<>?");
+ assertTrue(Arrays.equals(new byte[] { 105, -73 }, pref.getByteArray(
+ "testGetByteArrayKey", new byte[0])));
+ assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
+ .getByteArray("testGetByteArrayKey2", new byte[0])));
+ assertTrue(Arrays.equals(new byte[0], pref.getByteArray("invalidKey",
+ new byte[0])));
+
+ pref.putByteArray("testGetByteArrayKey3", b64Array);
+ pref.putByteArray("testGetByteArrayKey4", "abc".getBytes());
+ assertTrue(Arrays.equals(b64Array, pref.getByteArray(
+ "testGetByteArrayKey3", new byte[0])));
+ assertTrue(Arrays.equals("abc".getBytes(), pref.getByteArray(
+ "testGetByteArrayKey4", new byte[0])));
+ }
+
+ public void testGetDouble() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getDouble(null, 0);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.put("testGetDoubleKey", "1");
+ pref.put("testGetDoubleKey2", "value");
+ pref.putDouble("testGetDoubleKey3", 1);
+ pref.putInt("testGetDoubleKey4", 1);
+ assertEquals(1.0, pref.getDouble("testGetDoubleKey", 0.0), 0);
+ assertEquals(0.0, pref.getDouble("testGetDoubleKey2", 0.0), 0);
+ assertEquals(1.0, pref.getDouble("testGetDoubleKey3", 0.0), 0);
+ assertEquals(1.0, pref.getDouble("testGetDoubleKey4", 0.0), 0);
+ }
+
+ public void testGetFloat() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getFloat(null, 0f);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.put("testGetFloatKey", "1");
+ pref.put("testGetFloatKey2", "value");
+ assertEquals(1f, pref.getFloat("testGetFloatKey", 0f), 0);
+ assertEquals(0f, pref.getFloat("testGetFloatKey2", 0f), 0);
+ }
+
+ public void testGetInt() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getInt(null, 0);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.put("testGetIntKey", "1");
+ pref.put("testGetIntKey2", "value");
+ assertEquals(1, pref.getInt("testGetIntKey", 0));
+ assertEquals(0, pref.getInt("testGetIntKey2", 0));
+ }
+
+ public void testGetLong() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.getLong(null, 0);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.put("testGetLongKey", "1");
+ pref.put("testGetLongKey2", "value");
+ assertEquals(1, pref.getInt("testGetLongKey", 0));
+ assertEquals(0, pref.getInt("testGetLongKey2", 0));
+ }
+
+ public void testIsUserNode() {
+ Preferences pref1 = Preferences.userNodeForPackage(Preferences.class);
+ assertTrue(pref1.isUserNode());
+
+ Preferences pref2 = Preferences.systemNodeForPackage(Preferences.class);
+ assertFalse(pref2.isUserNode());
+ }
+
+ public void testKeys() throws BackingStoreException {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ pref.clear();
+
+ pref.put("key0", "value");
+ pref.put("key1", "value1");
+ pref.put("key2", "value2");
+ pref.put("key3", "value3");
+
+ String[] keys = pref.keys();
+ assertEquals(4, keys.length);
+ for (int i = 0; i < keys.length; i++) {
+ assertEquals(0, keys[i].indexOf("key"));
+ assertEquals(4, keys[i].length());
+ }
+ }
+
+ public void testName() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ Preferences child = pref.node("mock");
+ assertEquals("mock", child.name());
+ }
+
+ public void testNode() throws BackingStoreException {
+ StringBuffer name = new StringBuffer(Preferences.MAX_NAME_LENGTH);
+ for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
+ name.append('a');
+ }
+ String longName = name.toString();
+
+ Preferences root = Preferences.userRoot();
+ Preferences parent = Preferences
+ .userNodeForPackage(Preferences.class);
+ Preferences pref = parent.node("mock");
+
+ try {
+ pref.node(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ try {
+ pref.node("/java/util/prefs/");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ pref.node("/java//util/prefs");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ pref.node(longName + "a");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ assertNotNull(pref.node(longName));
+
+ assertSame(root, pref.node("/"));
+
+ Preferences prefs = pref.node("/java/util/prefs");
+ assertSame(prefs, parent);
+
+ assertSame(pref, pref.node(""));
+ }
+
+ public void testNodeExists() throws BackingStoreException {
+
+ Preferences parent = Preferences
+ .userNodeForPackage(Preferences.class);
+ Preferences pref = parent.node("mock");
+
+ try {
+ pref.nodeExists(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ try {
+ pref.nodeExists("/java/util/prefs/");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ pref.nodeExists("/java//util/prefs");
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ assertTrue(pref.nodeExists("/"));
+
+ assertTrue(pref.nodeExists("/java/util/prefs"));
+
+ assertTrue(pref.nodeExists(""));
+
+ assertFalse(pref.nodeExists("child"));
+ Preferences grandchild = pref.node("child/grandchild");
+ assertTrue(pref.nodeExists("child"));
+ assertTrue(pref.nodeExists("child/grandchild"));
+ grandchild.removeNode();
+ assertTrue(pref.nodeExists("child"));
+ assertFalse(pref.nodeExists("child/grandchild"));
+ assertFalse(grandchild.nodeExists(""));
+
+ assertFalse(pref.nodeExists("child2/grandchild"));
+ pref.node("child2/grandchild");
+ assertTrue(pref.nodeExists("child2/grandchild"));
+ }
+
+ public void testParent() {
+ Preferences parent = Preferences
+ .userNodeForPackage(Preferences.class);
+ Preferences pref = parent.node("mock");
+
+ assertSame(parent, pref.parent());
+ }
+
+ public void testPut() throws BackingStoreException {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ pref.put("", "emptyvalue");
+ assertEquals("emptyvalue", pref.get("", null));
+ pref.put("testPutkey", "value1");
+ assertEquals("value1", pref.get("testPutkey", null));
+ pref.put("testPutkey", "value2");
+ assertEquals("value2", pref.get("testPutkey", null));
+
+ pref.put("", "emptyvalue");
+ assertEquals("emptyvalue", pref.get("", null));
+
+ try {
+ pref.put(null, "value");
+ fail();
+ } catch (NullPointerException e) {
+ }
+ try {
+ pref.put("key", null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.put(longKey, longValue);
+ try {
+ pref.put(longKey + 1, longValue);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ pref.put(longKey, longValue + 1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ pref.removeNode();
+ try {
+ pref.put(longKey, longValue + 1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ try {
+ pref.put(longKey, longValue);
+ fail();
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ public void testPutBoolean() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putBoolean(null, false);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.putBoolean(longKey, false);
+ try {
+ pref.putBoolean(longKey + "a", false);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.putBoolean("testPutBooleanKey", false);
+ assertEquals("false", pref.get("testPutBooleanKey", null));
+ assertFalse(pref.getBoolean("testPutBooleanKey", true));
+ }
+
+ public void testPutDouble() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putDouble(null, 3);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.putDouble(longKey, 3);
+ try {
+ pref.putDouble(longKey + "a", 3);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.putDouble("testPutDoubleKey", 3);
+ assertEquals("3.0", pref.get("testPutDoubleKey", null));
+ assertEquals(3, pref.getDouble("testPutDoubleKey", 0), 0);
+ }
+
+ public void testPutFloat() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putFloat(null, 3f);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.putFloat(longKey, 3f);
+ try {
+ pref.putFloat(longKey + "a", 3f);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.putFloat("testPutFloatKey", 3f);
+ assertEquals("3.0", pref.get("testPutFloatKey", null));
+ assertEquals(3f, pref.getFloat("testPutFloatKey", 0), 0);
+ }
+
+ public void testPutInt() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putInt(null, 3);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.putInt(longKey, 3);
+ try {
+ pref.putInt(longKey + "a", 3);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.putInt("testPutIntKey", 3);
+ assertEquals("3", pref.get("testPutIntKey", null));
+ assertEquals(3, pref.getInt("testPutIntKey", 0));
+ }
+
+ public void testPutLong() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putLong(null, 3L);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ pref.putLong(longKey, 3L);
+ try {
+ pref.putLong(longKey + "a", 3L);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.putLong("testPutLongKey", 3L);
+ assertEquals("3", pref.get("testPutLongKey", null));
+ assertEquals(3L, pref.getLong("testPutLongKey", 0));
+ }
+
+ public void testPutByteArray() {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ try {
+ pref.putByteArray(null, new byte[0]);
+ fail();
+ } catch (NullPointerException e) {
+ }
+ try {
+ pref.putByteArray("testPutByteArrayKey4", null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.putByteArray(longKey, new byte[0]);
+ try {
+ pref.putByteArray(longKey + "a", new byte[0]);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ byte[] longArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.74)];
+ byte[] longerArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.75) + 1];
+ pref.putByteArray(longKey, longArray);
+ try {
+ pref.putByteArray(longKey, longerArray);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ pref.putByteArray("testPutByteArrayKey", new byte[0]);
+ assertEquals("", pref.get("testPutByteArrayKey", null));
+ assertTrue(Arrays.equals(new byte[0], pref.getByteArray(
+ "testPutByteArrayKey", null)));
+
+ pref.putByteArray("testPutByteArrayKey3", new byte[] { 'a', 'b', 'c' });
+ assertEquals("YWJj", pref.get("testPutByteArrayKey3", null));
+ assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
+ .getByteArray("testPutByteArrayKey3", null)));
+ }
+
+ public void testRemove() throws BackingStoreException {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ pref.remove("key");
+
+ pref.put("key", "value");
+ assertEquals("value", pref.get("key", null));
+ pref.remove("key");
+ assertNull(pref.get("key", null));
+
+ pref.remove("key");
+
+ try {
+ pref.remove(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ pref.removeNode();
+ try {
+ pref.remove("key");
+ fail();
+ } catch (IllegalStateException e) {
+ }
+ }
+
+ public void testRemoveNode() throws BackingStoreException {
+ Preferences pref = Preferences
+ .userNodeForPackage(Preferences.class);
+ Preferences child = pref.node("child");
+ Preferences child1 = pref.node("child1");
+ Preferences grandchild = child.node("grandchild");
+
+ pref.removeNode();
+
+ assertFalse(child.nodeExists(""));
+ assertFalse(child1.nodeExists(""));
+ assertFalse(grandchild.nodeExists(""));
+ assertFalse(pref.nodeExists(""));
+ }
+
+ public void testAddNodeChangeListener() throws BackingStoreException {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.addNodeChangeListener(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ Preferences child1 = null;
+ Preferences child2 = null;
+ Preferences child3 = null;
+
+ MockNodeChangeListener nl = null;
+ // To get existed node doesn't create the change event
+ try {
+ nl = new MockNodeChangeListener();
+ pref.addNodeChangeListener(nl);
+ child1 = pref.node("mock1");
+ nl.waitForEvent();
+ assertEquals(1, nl.getAdded());
+ nl.reset();
+ child2 = pref.node("mock1");
+ nl.waitForEvent();
+ assertEquals(0, nl.getAdded());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ child1.removeNode();
+ }
+ // same listener can be added twice, and must be removed twice
+ try {
+ nl = new MockNodeChangeListener();
+ pref.addNodeChangeListener(nl);
+ pref.addNodeChangeListener(nl);
+ child1 = pref.node("mock2");
+ nl.waitForEvent();
+ assertEquals(2, nl.getAdded());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ pref.removeNodeChangeListener(nl);
+ child1.removeNode();
+ }
+ // test remove event
+ try {
+ nl = new MockNodeChangeListener();
+ pref.addNodeChangeListener(nl);
+ child1 = pref.node("mock3");
+ child1.removeNode();
+ nl.waitForEvent();
+ assertEquals(1, nl.getRemoved());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ }
+ // test remove event with two listeners
+ try {
+ nl = new MockNodeChangeListener();
+ pref.addNodeChangeListener(nl);
+ pref.addNodeChangeListener(nl);
+ child1 = pref.node("mock6");
+ child1.removeNode();
+ nl.waitForEvent();
+ assertEquals(2, nl.getRemoved());
+ nl.reset();
+ } finally {
+ pref.removeNodeChangeListener(nl);
+ pref.removeNodeChangeListener(nl);
+ }
+ // test add/remove indirect children, or remove several children at the
+ // same time
+ try {
+ nl = new MockNodeChangeListener();
+ child1 = pref.node("mock4");
+ child1.addNodeChangeListener(nl);
+ child2 = pref.node("mock4/mock5");
+ nl.waitForEvent();
+ assertEquals(1, nl.getAdded());
+ nl.reset();
+ child3 = pref.node("mock4/mock5/mock6");
+ nl.waitForEvent();
+ assertEquals(0, nl.getAdded());
+ nl.reset();
+
+ child3.removeNode();
+ nl.waitForEvent();
+ assertEquals(0, nl.getRemoved());
+ nl.reset();
+
+ child3 = pref.node("mock4/mock7");
+ nl.waitForEvent();
+ assertEquals(1, nl.getAdded());
+ nl.reset();
+
+ child1.removeNode();
+ nl.waitForEvent();
+ assertEquals(2, nl.getRemoved()); // fail 1
+ nl.reset();
+ } finally {
+ try {
+ child1.removeNode();
+ } catch (Exception e) {
+ }
+ }
+
+ }
+
+ public void testAddPreferenceChangeListener() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ MockPreferenceChangeListener pl = null;
+
+ try {
+ pref.addPreferenceChangeListener(null);
+ fail();
+ } catch (NullPointerException e) {
+ }
+
+ // To get existed node doesn't create the change event
+ try {
+ pl = new MockPreferenceChangeListener();
+ pref.addPreferenceChangeListener(pl);
+ pref.putInt("mock1", 123);
+ pl.waitForEvent(1);
+ assertEquals(1, pl.getChanged());
+ pref.putLong("long_key", Long.MAX_VALUE);
+ pl.waitForEvent(2);
+ assertEquals(2, pl.getChanged());
+ pl.reset();
+ try {
+ pref.clear();
+ pl.waitForEvent(2);
+ assertEquals(2, pl.getChanged()); // fail 1
+ } catch(BackingStoreException bse) {
+ pl.reset();
+ fail("BackingStoreException is thrown");
+ }
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ //child1.removeNode();
+ }
+
+ // same listener can be added twice, and must be removed twice
+ try {
+ pl = new MockPreferenceChangeListener();
+ pref.addPreferenceChangeListener(pl);
+ pref.addPreferenceChangeListener(pl);
+ pref.putFloat("float_key", Float.MIN_VALUE);
+ pl.waitForEvent(2);
+ assertEquals(2, pl.getChanged());
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ pref.removePreferenceChangeListener(pl);
+
+ }
+ // test remove event
+ try {
+ pl = new MockPreferenceChangeListener();
+ pref.addPreferenceChangeListener(pl);
+ pref.putDouble("double_key", Double.MAX_VALUE);
+ pl.waitForEvent(1);
+ assertEquals(1, pl.getChanged());
+ try {
+ pref.clear();
+ pl.waitForEvent(3);
+ assertEquals(3, pl.getChanged()); // fails
+ } catch(BackingStoreException bse) {
+ fail("BackingStoreException is thrown");
+ }
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ }
+ // test remove event with two listeners
+ try {
+ pl = new MockPreferenceChangeListener();
+ pref.addPreferenceChangeListener(pl);
+ pref.addPreferenceChangeListener(pl);
+ pref.putByteArray("byte_array_key", new byte [] {1 ,2 , 3});
+ try {
+ pref.clear();
+ pl.waitForEvent(4);
+ assertEquals(4, pl.getChanged());
+ } catch(BackingStoreException bse) {
+ fail("BackingStoreException is thrown");
+ }
+ pl.reset();
+ } finally {
+ pref.removePreferenceChangeListener(pl);
+ pref.removePreferenceChangeListener(pl);
+ }
+
+ }
+
+ public void testRemoveNodeChangeListener() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.removeNodeChangeListener(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ MockNodeChangeListener l1 = new MockNodeChangeListener();
+ MockNodeChangeListener l2 = new MockNodeChangeListener();
+ pref.addNodeChangeListener(l1);
+ pref.addNodeChangeListener(l1);
+
+ pref.removeNodeChangeListener(l1);
+ pref.removeNodeChangeListener(l1);
+ try {
+ pref.removeNodeChangeListener(l1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ pref.removeNodeChangeListener(l2);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testRemovePreferenceChangeListener() {
+ Preferences pref = Preferences.userNodeForPackage(Preferences.class);
+ try {
+ pref.removePreferenceChangeListener(null);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ MockPreferenceChangeListener l1 = new MockPreferenceChangeListener();
+ MockPreferenceChangeListener l2 = new MockPreferenceChangeListener();
+ pref.addPreferenceChangeListener(l1);
+ pref.addPreferenceChangeListener(l1);
+ try {
+ pref.removePreferenceChangeListener(l2);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ pref.removePreferenceChangeListener(l1);
+ pref.removePreferenceChangeListener(l1);
+ try {
+ pref.removePreferenceChangeListener(l1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+
+ }
+
+ static class MockInputStream extends InputStream {
+
+ static final int normal = 0;
+
+ static final int exception = 1;
+
+ static final int runtimeException = 2;
+
+ int result = normal;
+
+ InputStream wrapper;
+
+ public void setResult(int i) {
+ result = i;
+ }
+
+ private void checkException() throws IOException {
+ switch (result) {
+ case normal:
+ return;
+ case exception:
+ throw new IOException("test");
+ case runtimeException:
+ throw new RuntimeException("test");
+ }
+ }
+
+ public MockInputStream(InputStream in) {
+ wrapper = in;
+ }
+
+ @Override
+ public int read() throws IOException {
+ checkException();
+ return wrapper.read();
+ }
+ }
+
+ static class MockNodeChangeListener implements NodeChangeListener {
+ private int added = 0;
+ private int removed = 0;
+
+ public synchronized void waitForEvent() {
+ try {
+ wait(500);
+ } catch (InterruptedException ignored) {
+ }
+ }
+
+ public synchronized void childAdded(NodeChangeEvent e) {
+ ++added;
+ notifyAll();
+ }
+
+ public synchronized void childRemoved(NodeChangeEvent e) {
+ removed++;
+ notifyAll();
+ }
+
+ public synchronized int getAdded() {
+ return added;
+ }
+
+ public synchronized int getRemoved() {
+ return removed;
+ }
+
+ public void reset() {
+ added = 0;
+ removed = 0;
+ }
+ }
+
+ private static class MockPreferenceChangeListener implements PreferenceChangeListener {
+ private int changed = 0;
+ private boolean addDispatched = false;
+ private boolean result = false;
+
+ public void waitForEvent(int count) {
+ for (int i = 0; i < count; i++) {
+ try {
+ synchronized (this) {
+ this.wait(500);
+ }
+ } catch (InterruptedException ignored) {
+ }
+ }
+ }
+
+ public synchronized void preferenceChange(PreferenceChangeEvent pce) {
+ changed++;
+ addDispatched = true;
+ notifyAll();
+ }
+
+ public boolean getResult() {
+ if (!addDispatched) {
+ try {
+ // TODO: don't know why must add limitation
+ this.wait(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ addDispatched = false;
+ return result;
+ }
+
+ public synchronized int getChanged() {
+ if (!addDispatched) {
+ try {
+ // TODO: don't know why must add limitation
+ this.wait(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ addDispatched = false;
+ return changed;
+ }
+
+ public void reset() {
+ changed = 0;
+ result = false;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ static class MockPreferences extends Preferences {
+
+ @Override
+ public String absolutePath() {
+ return null;
+ }
+
+ @Override
+ public String[] childrenNames() throws BackingStoreException {
+ return null;
+ }
+
+ @Override
+ public void clear() throws BackingStoreException {
+ }
+
+ @Override
+ public void exportNode(OutputStream ostream) throws IOException, BackingStoreException {
+ }
+
+ @Override
+ public void exportSubtree(OutputStream ostream) throws IOException, BackingStoreException {
+ }
+
+ @Override
+ public void flush() throws BackingStoreException {
+ }
+
+ @Override
+ public String get(String key, String deflt) {
+ return null;
+ }
+
+ @Override
+ public boolean getBoolean(String key, boolean deflt) {
+ return false;
+ }
+
+ @Override
+ public byte[] getByteArray(String key, byte[] deflt) {
+ return null;
+ }
+
+ @Override
+ public double getDouble(String key, double deflt) {
+ return 0;
+ }
+
+ @Override
+ public float getFloat(String key, float deflt) {
+ return 0;
+ }
+
+ @Override
+ public int getInt(String key, int deflt) {
+ return 0;
+ }
+
+ @Override
+ public long getLong(String key, long deflt) {
+ return 0;
+ }
+
+ @Override
+ public boolean isUserNode() {
+ return false;
+ }
+
+ @Override
+ public String[] keys() throws BackingStoreException {
+ return null;
+ }
+
+ @Override
+ public String name() {
+ return null;
+ }
+
+ @Override
+ public Preferences node(String name) {
+ return null;
+ }
+
+ @Override
+ public boolean nodeExists(String name) throws BackingStoreException {
+ return false;
+ }
+
+ @Override
+ public Preferences parent() {
+ return null;
+ }
+
+ @Override
+ public void put(String key, String value) {
+ }
+
+ @Override
+ public void putBoolean(String key, boolean value) {
+ }
+
+ @Override
+ public void putByteArray(String key, byte[] value) {
+ }
+
+ @Override
+ public void putDouble(String key, double value) {
+ }
+
+ @Override
+ public void putFloat(String key, float value) {
+ }
+
+ @Override
+ public void putInt(String key, int value) {
+ }
+
+ @Override
+ public void putLong(String key, long value) {
+ }
+
+ @Override
+ public void remove(String key) {
+ }
+
+ @Override
+ public void removeNode() throws BackingStoreException {
+ }
+
+ @Override
+ public void addNodeChangeListener(NodeChangeListener ncl) {
+ }
+
+ @Override
+ public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
+ }
+
+ @Override
+ public void removeNodeChangeListener(NodeChangeListener ncl) {
+ }
+
+ @Override
+ public void removePreferenceChangeListener(PreferenceChangeListener pcl) {
+ }
+
+ @Override
+ public void sync() throws BackingStoreException {
+ }
+
+ @Override
+ public String toString() {
+ return null;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/DeflaterInputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/DeflaterInputStreamTest.java
new file mode 100644
index 0000000..938b16e
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/DeflaterInputStreamTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.zip.DeflaterInputStream;
+import java.util.zip.InflaterInputStream;
+import junit.framework.TestCase;
+
+public final class DeflaterInputStreamTest extends TestCase {
+
+ public void testReadByteByByte() throws IOException {
+ byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ assertEquals(1, in.available());
+ int b;
+ while ((b = in.read()) != -1) {
+ out.write(b);
+ }
+ assertEquals(0, in.available());
+
+ assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
+
+ in.close();
+ try {
+ in.available();
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+
+ public byte[] inflate(byte[] bytes) throws IOException {
+ java.io.InputStream in = new InflaterInputStream(new ByteArrayInputStream(bytes));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int count;
+ while ((count = in.read(buffer)) != -1) {
+ out.write(buffer, 0, count);
+ }
+ return out.toByteArray();
+ }
+
+ public void testReadWithBuffer() throws IOException {
+ byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] buffer = new byte[8];
+ InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ assertEquals(1, in.available());
+ int count;
+ while ((count = in.read(buffer, 0, 5)) != -1) {
+ assertTrue(count <= 5);
+ out.write(buffer, 0, count);
+ }
+ assertEquals(0, in.available());
+
+ assertEquals(Arrays.toString(data), Arrays.toString(inflate(out.toByteArray())));
+
+ in.close();
+ try {
+ in.available();
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+
+ public void testReadExceptions() throws IOException {
+ byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] buffer = new byte[8];
+ InputStream in = new DeflaterInputStream(new ByteArrayInputStream(data));
+ try {
+ in.read(buffer, 0, 10);
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
+ }
+ try {
+ in.read(null, 0, 5);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ try {
+ in.read(buffer, -1, 5);
+ fail();
+ } catch (IndexOutOfBoundsException expected) {
+ }
+ in.close();
+ try {
+ in.read(buffer, 0, 5);
+ fail();
+ } catch (IOException expected) {
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
index 55144ed..95e6891 100644
--- a/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/DeflaterOutputStreamTest.java
@@ -57,8 +57,7 @@ public class DeflaterOutputStreamTest extends TestCase {
* way demonstrate that data is unavailable. Ie. other techniques will cause
* the dry read to block indefinitely.
*/
- private InflaterInputStream createInflaterStream(final boolean flushing)
- throws Exception {
+ private InflaterInputStream createInflaterStream(final boolean flushing) throws Exception {
ExecutorService executor = Executors.newSingleThreadExecutor();
final PipedOutputStream pout = new PipedOutputStream();
PipedInputStream pin = new PipedInputStream(pout);
diff --git a/luni/src/test/java/libcore/java/util/zip/DeflaterTest.java b/luni/src/test/java/libcore/java/util/zip/DeflaterTest.java
index 27f3c6a..30aa7f3 100644
--- a/luni/src/test/java/libcore/java/util/zip/DeflaterTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/DeflaterTest.java
@@ -72,4 +72,14 @@ public class DeflaterTest extends TestCase {
assertEquals(expectedValue, decompressed[i]);
}
}
+
+ /**
+ * Deflating without calling setInput() is the same as deflating an empty
+ * byte array.
+ */
+ public void testDeflateWithoutSettingInput() throws Exception {
+ deflateInflate(Deflater.FULL_FLUSH);
+ assertTrue(totalDeflated > 0); // the deflated form should be non-empty
+ assertEquals(0, totalInflated);
+ }
}
diff --git a/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
new file mode 100644
index 0000000..a28fae5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import junit.framework.TestCase;
+
+public final class GZIPInputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = new byte[] {
+ 31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49,
+ 47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0
+ };
+ assertEquals("Hello World", new String(gunzip(data), "UTF-8"));
+ }
+
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, gunzip(GZIPOutputStreamTest.gzip(data))));
+ }
+
+ /** http://b/3042574 GzipInputStream.skip() causing CRC failures */
+ public void testSkip() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ byte[] gzipped = GZIPOutputStreamTest.gzip(data);
+ GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(gzipped));
+ long totalSkipped = 0;
+
+ long count;
+ do {
+ count = in.skip(Long.MAX_VALUE);
+ totalSkipped += count;
+ } while (count > 0);
+
+ assertEquals(data.length, totalSkipped);
+ in.close();
+ }
+
+ public static byte[] gunzip(byte[] bytes) throws IOException {
+ InputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buffer = new byte[1024];
+ int count;
+ while ((count = in.read(buffer)) != -1) {
+ out.write(buffer, 0, count);
+ }
+ in.close();
+ return out.toByteArray();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
new file mode 100644
index 0000000..a61880f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPOutputStreamTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+import junit.framework.TestCase;
+
+public final class GZIPOutputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = gzip(("Hello World").getBytes("UTF-8"));
+ assertEquals("[31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49, " +
+ "47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0]", Arrays.toString(data));
+ }
+
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, GZIPInputStreamTest.gunzip(gzip(data))));
+ }
+
+ public static byte[] gzip(byte[] bytes) throws IOException {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
+ gzippedOut.write(bytes);
+ gzippedOut.close();
+ return bytesOut.toByteArray();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/GzipTest.java b/luni/src/test/java/libcore/java/util/zip/GzipTest.java
deleted file mode 100644
index f7e03dc..0000000
--- a/luni/src/test/java/libcore/java/util/zip/GzipTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package libcore.java.util.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Arrays;
-import java.util.Random;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-import junit.framework.TestCase;
-
-public final class GzipTest extends TestCase {
-
- public void testRoundtripShortMessage() throws IOException {
- byte[] data = gzip(("Hello World").getBytes("UTF-8"));
- assertTrue(Arrays.equals(data, gunzip(gzip(data))));
- }
-
- public void testRoundtripLongMessage() throws IOException {
- byte[] data = new byte[1024 * 1024];
- new Random().nextBytes(data);
- assertTrue(Arrays.equals(data, gunzip(gzip(data))));
- }
-
- /** http://b/3042574 GzipInputStream.skip() causing CRC failures */
- public void testSkip() throws IOException {
- byte[] data = new byte[1024 * 1024];
- byte[] gzipped = gzip(data);
- GZIPInputStream in = new GZIPInputStream(new ByteArrayInputStream(gzipped));
- long totalSkipped = 0;
-
- long count;
- do {
- count = in.skip(Long.MAX_VALUE);
- totalSkipped += count;
- } while (count > 0);
-
-
- assertEquals(data.length, totalSkipped);
- }
-
- public byte[] gzip(byte[] bytes) throws IOException {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- OutputStream gzippedOut = new GZIPOutputStream(bytesOut);
- gzippedOut.write(bytes);
- gzippedOut.close();
- return bytesOut.toByteArray();
- }
-
- public byte[] gunzip(byte[] bytes) throws IOException {
- InputStream in = new GZIPInputStream(new ByteArrayInputStream(bytes));
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int count;
- while ((count = in.read(buffer)) != -1) {
- out.write(buffer, 0, count);
- }
- return out.toByteArray();
- }
-}
diff --git a/luni/src/test/java/libcore/java/util/zip/InflaterTest.java b/luni/src/test/java/libcore/java/util/zip/InflaterTest.java
new file mode 100644
index 0000000..f86ec70
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/InflaterTest.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayOutputStream;
+import java.util.zip.Adler32;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+import junit.framework.TestCase;
+
+public class InflaterTest extends TestCase {
+ public void testDefaultDictionary() throws Exception {
+ assertRoundTrip(null);
+ }
+
+ public void testPresetCustomDictionary() throws Exception {
+ assertRoundTrip("dictionary".getBytes("UTF-8"));
+ }
+
+ private static void assertRoundTrip(byte[] dictionary) throws Exception {
+ // Construct a nice long input byte sequence.
+ String expected = makeString();
+ byte[] expectedBytes = expected.getBytes("UTF-8");
+
+ // Compress the bytes, using the passed-in dictionary (or no dictionary).
+ byte[] deflatedBytes = deflate(expectedBytes, dictionary);
+
+ // Get ready to decompress deflatedBytes back to the original bytes ...
+ Inflater inflater = new Inflater();
+ // We'll only supply the input a little bit at a time, so that zlib has to ask for more.
+ final int CHUNK_SIZE = 16;
+ int offset = 0;
+ inflater.setInput(deflatedBytes, offset, CHUNK_SIZE);
+ offset += CHUNK_SIZE;
+ // If we used a dictionary to compress, check that we're asked for that same dictionary.
+ if (dictionary != null) {
+ // 1. there's no data available immediately...
+ assertEquals(0, inflater.inflate(new byte[8]));
+ // 2. ...because you need a dictionary.
+ assertTrue(inflater.needsDictionary());
+ // 3. ...and that dictionary has the same Adler32 as the dictionary we used.
+ assertEquals(adler32(dictionary), inflater.getAdler());
+ inflater.setDictionary(dictionary);
+ }
+ // Do the actual decompression, now the dictionary's set up appropriately...
+ // We use a tiny output buffer to ensure that we call inflate multiple times, and
+ // a tiny input buffer to ensure that zlib has to ask for more input.
+ ByteArrayOutputStream inflatedBytes = new ByteArrayOutputStream();
+ byte[] buf = new byte[8];
+ while (inflatedBytes.size() != expectedBytes.length) {
+ if (inflater.needsInput()) {
+ int nextChunkByteCount = Math.min(CHUNK_SIZE, deflatedBytes.length - offset);
+ inflater.setInput(deflatedBytes, offset, nextChunkByteCount);
+ offset += nextChunkByteCount;
+ } else {
+ int inflatedByteCount = inflater.inflate(buf);
+ if (inflatedByteCount > 0) {
+ inflatedBytes.write(buf, 0, inflatedByteCount);
+ }
+ }
+ }
+ inflater.end();
+
+ assertEquals(expected, new String(inflatedBytes.toByteArray(), "UTF-8"));
+ }
+
+ private static String makeString() {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 1024; ++i) {
+ // This is arbitrary but convenient in that it gives our string
+ // an easily-recognizable beginning and end.
+ sb.append(i + 1024);
+ }
+ return sb.toString();
+ }
+
+ private static byte[] deflate(byte[] input, byte[] dictionary) {
+ Deflater deflater = new Deflater();
+ if (dictionary != null) {
+ deflater.setDictionary(dictionary);
+ }
+ deflater.setInput(input);
+ deflater.finish();
+ ByteArrayOutputStream deflatedBytes = new ByteArrayOutputStream();
+ byte[] buf = new byte[8];
+ while (!deflater.finished()) {
+ int byteCount = deflater.deflate(buf);
+ deflatedBytes.write(buf, 0, byteCount);
+ }
+ deflater.end();
+ return deflatedBytes.toByteArray();
+ }
+
+ private static int adler32(byte[] bytes) {
+ Adler32 adler32 = new Adler32();
+ adler32.update(bytes);
+ return (int) adler32.getValue();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/OldAndroidChecksumTest.java b/luni/src/test/java/libcore/java/util/zip/OldAndroidChecksumTest.java
new file mode 100644
index 0000000..3d2406d
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldAndroidChecksumTest.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import junit.framework.TestCase;
+
+import java.util.zip.Adler32;
+import java.util.zip.CRC32;
+
+/**
+ * tests for CRC32 and Adler32 checksum algorithms.
+ */
+public class OldAndroidChecksumTest extends TestCase {
+
+ public void testChecksum() throws Exception {
+ /*
+ * Values computed experimentally, using C interfaces.
+ */
+ adler32Test(mTestString, 0x9de210dbL);
+ cRC32Test(mTestString, 0x939f04afL);
+
+ // Test for issue 1016037
+ wrongChecksumWithAdler32Test();
+ }
+
+ private void adler32Test(byte[] values, long expected) {
+ Adler32 adler = new Adler32();
+
+ // try it all at once
+ adler.update(values);
+ assertEquals(adler.getValue(), expected);
+
+ // try resetting and computing one byte at a time
+ adler.reset();
+ for (int i = 0; i < values.length; i++) {
+ adler.update(values[i]);
+ }
+ assertEquals(adler.getValue(), expected);
+ }
+
+ private void cRC32Test(byte[] values, long expected) {
+ CRC32 crc = new CRC32();
+
+ // try it all at once
+ crc.update(values);
+ assertEquals(crc.getValue(), expected);
+
+ // try resetting and computing one byte at a time
+ crc.reset();
+ for (int i = 0; i < values.length; i++) {
+ crc.update(values[i]);
+ }
+ assertEquals(crc.getValue(), expected);
+ }
+
+ // "The quick brown fox jumped over the lazy dogs\n"
+ private static byte[] mTestString = {
+ 0x54, 0x68, 0x65, 0x20, 0x71, 0x75, 0x69, 0x63,
+ 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20,
+ 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70,
+ 0x65, 0x64, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x20,
+ 0x74, 0x68, 0x65, 0x20, 0x6c, 0x61, 0x7a, 0x79,
+ 0x20, 0x64, 0x6f, 0x67, 0x73, 0x2e, 0x0a
+ };
+
+
+ // Test for issue 1016037
+ private void wrongChecksumWithAdler32Test() {
+ byte[] bytes = {1, 0, 5, 0, 15, 0, 1, 11, 0, 1};
+ Adler32 adler = new Adler32();
+ adler.update(bytes);
+ long arrayChecksum = adler.getValue();
+ adler.reset();
+ for (int i = 0; i < bytes.length; i++) {
+ adler.update(bytes[i]);
+ }
+ assertEquals("Checksums not equal: expected: " + arrayChecksum +
+ " actual: " + adler.getValue(), arrayChecksum, adler.getValue());
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/zip/OldAndroidDeflateTest.java b/luni/src/test/java/libcore/java/util/zip/OldAndroidDeflateTest.java
new file mode 100644
index 0000000..b4d05ed
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldAndroidDeflateTest.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import junit.framework.TestCase;
+
+import java.io.UnsupportedEncodingException;
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+
+public class OldAndroidDeflateTest extends TestCase {
+
+ public void testDeflate() throws Exception {
+ simpleTest();
+
+ bigTest(0, 1738149618);
+ bigTest(1, 934350518);
+ bigTest(2, -532869390);
+ }
+
+ /*
+ * Simple inflate/deflate test, taken from the reference docs for the
+ * Inflater/Deflater classes.
+ */
+ private void simpleTest()
+ throws UnsupportedEncodingException, DataFormatException {
+ // Encode a String into bytes
+ String inputString = "blahblahblah??";
+ byte[] input = inputString.getBytes("UTF-8");
+
+ // Compress the bytes
+ byte[] output = new byte[100];
+ Deflater compresser = new Deflater();
+ compresser.setInput(input);
+ compresser.finish();
+ int compressedDataLength = compresser.deflate(output);
+
+ // Decompress the bytes
+ Inflater decompresser = new Inflater();
+ decompresser.setInput(output, 0, compressedDataLength);
+ byte[] result = new byte[100];
+ int resultLength = decompresser.inflate(result);
+
+ // Decode the bytes into a String
+ String outputString = new String(result, 0, resultLength, "UTF-8");
+
+ assertEquals(inputString, outputString);
+ assertEquals(compresser.getAdler(), decompresser.getAdler());
+
+ decompresser.end();
+ }
+
+ /*
+ * "step" determines how compressible the data is.
+ *
+ * Note we must set "nowrap" to false, or the Adler-32 doesn't get
+ * computed.
+ */
+ private void bigTest(int step, int expectedAdler)
+ throws UnsupportedEncodingException, DataFormatException {
+ byte[] input = new byte[128 * 1024];
+ byte[] comp = new byte[128 * 1024 + 512];
+ byte[] output = new byte[128 * 1024 + 512];
+ Inflater inflater = new Inflater(false);
+ Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION, false);
+
+ createSample(input, step);
+
+ compress(deflater, input, comp);
+ expand(inflater, comp, (int) deflater.getBytesWritten(), output);
+
+ assertEquals(inflater.getBytesWritten(), input.length);
+ assertEquals(deflater.getAdler(), inflater.getAdler());
+ assertEquals(deflater.getAdler(), expectedAdler);
+ }
+
+ /*
+ * Create a large data sample.
+ * stepStep = 0 --> >99% compression
+ * stepStep = 1 --> ~30% compression
+ * stepStep = 2 --> no compression
+ */
+ private void createSample(byte[] sample, int stepStep) {
+ byte val, step;
+ int i, j, offset;
+
+ assertTrue(sample.length >= 128 * 1024);
+
+ val = 0;
+ step = 1;
+ offset = 0;
+ for (i = 0; i < (128 * 1024) / 256; i++) {
+ for (j = 0; j < 256; j++) {
+ sample[offset++] = val;
+ val += step;
+ }
+
+ step += stepStep;
+ }
+ }
+
+ private static final int LOCAL_BUF_SIZE = 256;
+
+ /*
+ * Compress all data in "in" to "out". We use a small window on input
+ * and output to exercise that part of the code.
+ *
+ * It's the caller's responsibility to ensure that "out" has enough
+ * space.
+ */
+ private void compress(Deflater deflater, byte[] inBuf, byte[] outBuf) {
+ int inCount = inBuf.length; // use all
+ int inPosn;
+ int outPosn;
+
+ inPosn = outPosn = 0;
+
+ //System.out.println("### starting compress");
+
+ while (!deflater.finished()) {
+ int want = -1, got;
+
+ // only read if the input buffer is empty
+ if (deflater.needsInput() && inCount != 0) {
+ want = (inCount < LOCAL_BUF_SIZE) ? inCount : LOCAL_BUF_SIZE;
+
+ deflater.setInput(inBuf, inPosn, want);
+
+ inCount -= want;
+ inPosn += want;
+ if (inCount == 0) {
+ deflater.finish();
+ }
+ }
+
+ // deflate to current position in output buffer
+ int compCount;
+
+ compCount = deflater.deflate(outBuf, outPosn, LOCAL_BUF_SIZE);
+ outPosn += compCount;
+
+ //System.out.println("Compressed " + want + ", output " + compCount);
+ }
+ }
+
+ /*
+ * Expand data from "inBuf" to "outBuf". Uses a small window to better
+ * exercise the code.
+ */
+ private void expand(Inflater inflater, byte[] inBuf, int inCount,
+ byte[] outBuf) throws DataFormatException {
+ int inPosn;
+ int outPosn;
+
+ inPosn = outPosn = 0;
+
+ //System.out.println("### starting expand, inCount is " + inCount);
+
+ while (!inflater.finished()) {
+ int want = -1, got;
+
+ // only read if the input buffer is empty
+ if (inflater.needsInput() && inCount != 0) {
+ want = (inCount < LOCAL_BUF_SIZE) ? inCount : LOCAL_BUF_SIZE;
+
+ inflater.setInput(inBuf, inPosn, want);
+
+ inCount -= want;
+ inPosn += want;
+ }
+
+ // inflate to current position in output buffer
+ int compCount;
+
+ compCount = inflater.inflate(outBuf, outPosn, LOCAL_BUF_SIZE);
+ outPosn += compCount;
+
+ //System.out.println("Expanded " + want + ", output " + compCount);
+ }
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/zip/OldAndroidGZIPStreamTest.java b/luni/src/test/java/libcore/java/util/zip/OldAndroidGZIPStreamTest.java
new file mode 100644
index 0000000..a5c40cd
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldAndroidGZIPStreamTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import junit.framework.TestCase;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+/**
+ * Deflates and inflates some test data with GZipStreams
+ */
+public class OldAndroidGZIPStreamTest extends TestCase {
+
+ public void testGZIPStream() throws Exception {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ createGZIP(bytesOut);
+
+ byte[] zipData;
+ zipData = bytesOut.toByteArray();
+
+ /*
+ FileOutputStream outFile = new FileOutputStream("/tmp/foo.gz");
+ outFile.write(zipData, 0, zipData.length);
+ outFile.close();
+ */
+
+ /*
+ FileInputStream inFile = new FileInputStream("/tmp/foo.gz");
+ int inputLength = inFile.available();
+ zipData = new byte[inputLength];
+ if (inFile.read(zipData) != inputLength)
+ throw new RuntimeException();
+ inFile.close();
+ */
+
+ ByteArrayInputStream bytesIn = new ByteArrayInputStream(zipData);
+ scanGZIP(bytesIn);
+ }
+
+ /*
+ * stepStep == 0 --> >99% compression
+ * stepStep == 1 --> ~30% compression
+ * stepStep == 2 --> no compression
+ */
+ static byte[] makeSampleFile(int stepStep) throws IOException {
+ byte[] sample = new byte[128 * 1024];
+ byte val, step;
+ int i, j, offset;
+
+ val = 0;
+ step = 1;
+ offset = 0;
+ for (i = 0; i < (128 * 1024) / 256; i++) {
+ for (j = 0; j < 256; j++) {
+ sample[offset++] = val;
+ val += step;
+ }
+
+ step += stepStep;
+ }
+
+ return sample;
+ }
+
+ static void createGZIP(ByteArrayOutputStream bytesOut) throws IOException {
+ GZIPOutputStream out = new GZIPOutputStream(bytesOut);
+ try {
+ byte[] input = makeSampleFile(1);
+ out.write(input, 0, input.length);
+ //out.finish();
+ } finally {
+ out.close();
+ }
+ }
+
+ static void scanGZIP(ByteArrayInputStream bytesIn) throws IOException {
+ GZIPInputStream in = new GZIPInputStream(bytesIn);
+ try {
+ ByteArrayOutputStream contents = new ByteArrayOutputStream();
+ byte[] buf = new byte[4096];
+ int len, totalLen = 0;
+
+ while ((len = in.read(buf)) > 0) {
+ contents.write(buf, 0, len);
+ totalLen += len;
+ }
+
+ assertEquals(totalLen, 128 * 1024);
+ } finally {
+ in.close();
+ }
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/zip/OldAndroidZipFileTest.java b/luni/src/test/java/libcore/java/util/zip/OldAndroidZipFileTest.java
new file mode 100644
index 0000000..97c0f63
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldAndroidZipFileTest.java
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+import junit.framework.TestCase;
+
+
+/**
+ * Basic tests for ZipFile.
+ */
+public class OldAndroidZipFileTest extends TestCase {
+ private static final int SAMPLE_SIZE = 128 * 1024;
+
+ public void testZipFile() throws Exception {
+
+ File file = File.createTempFile("ZipFileTest", ".zip");
+ try {
+ // create a test file; assume it's not going to collide w/anything
+ FileOutputStream outStream = new FileOutputStream(file);
+ createCompressedZip(outStream);
+
+ scanZip(file.getPath());
+ read2(file.getPath());
+ } finally {
+ file.delete();
+ }
+ }
+
+ /*
+ * stepStep == 0 --> >99% compression
+ * stepStep == 1 --> ~30% compression
+ * stepStep == 2 --> no compression
+ */
+ static byte[] makeSampleFile(int stepStep) throws IOException {
+ byte[] sample = new byte[SAMPLE_SIZE];
+ byte val, step;
+ int i, j, offset;
+
+ val = 0;
+ step = 1;
+ offset = 0;
+ for (i = 0; i < SAMPLE_SIZE / 256; i++) {
+ for (j = 0; j < 256; j++) {
+ sample[offset++] = val;
+ val += step;
+ }
+
+ step += stepStep;
+ }
+
+ return sample;
+ }
+
+ static void createCompressedZip(OutputStream bytesOut) throws IOException {
+ ZipOutputStream out = new ZipOutputStream(bytesOut);
+ try {
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ byte[] input = makeSampleFile(i);
+ ZipEntry newEntry = new ZipEntry("file-" + i);
+
+ if (i != 1) {
+ newEntry.setComment("this is file " + i);
+ }
+ out.putNextEntry(newEntry);
+ out.write(input, 0, input.length);
+ out.closeEntry();
+ }
+
+ out.setComment("This is a lovely compressed archive!");
+ } finally {
+ out.close();
+ }
+ }
+
+ static void scanZip(String fileName) throws IOException {
+ ZipFile zipFile = new ZipFile(fileName);
+ Enumeration fileList;
+ int idx = 0;
+
+// System.out.println("Contents of " + zipFile + ":");
+ for (fileList = zipFile.entries(); fileList.hasMoreElements();) {
+ ZipEntry entry = (ZipEntry) fileList.nextElement();
+// System.out.println(" " + entry.getName());
+ assertEquals(entry.getName(), "file-" + idx);
+ idx++;
+ }
+
+ zipFile.close();
+ }
+
+ /*
+ * Read compressed data from two different entries at the same time,
+ * to verify that the streams aren't getting confused. If we do
+ * something wrong, the inflater will choke and throw a ZipException.
+ *
+ * This doesn't test synchronization in multi-threaded use.
+ */
+ static void read2(String fileName) throws IOException {
+ ZipFile zipFile;
+ ZipEntry entry1, entry2;
+ byte buf[] = new byte[16384];
+ InputStream stream1, stream2;
+ int len, totalLen1, totalLen2;
+
+ /* use file-1 and file-2 because the compressed data is large */
+ zipFile = new ZipFile(fileName);
+ entry1 = zipFile.getEntry("file-1");
+ entry2 = zipFile.getEntry("file-2");
+
+ /* make sure we got the right thing */
+ assertEquals("file-1", entry1.getName());
+ assertEquals("file-2", entry2.getName());
+
+ /* create streams */
+ stream1 = zipFile.getInputStream(entry1);
+ stream2 = zipFile.getInputStream(entry2);
+
+ /*
+ * Read a piece of file #1.
+ */
+ totalLen1 = stream1.read(buf);
+ assertTrue("initial read failed on #1", totalLen1 >= 0);
+
+ /*
+ * Read a piece of file #2.
+ */
+ totalLen2 = stream2.read(buf);
+ assertTrue("initial read failed on #2", totalLen2 >= 0);
+
+ /*
+ * Read the rest of file #1, and close the stream.
+ *
+ * If our streams are crossed up, we'll fail here.
+ */
+ while ((len = stream1.read(buf)) > 0) {
+ totalLen1 += len;
+ }
+ assertEquals(SAMPLE_SIZE, totalLen1);
+ stream1.close();
+
+ /*
+ * Read the rest of file #2, and close the stream.
+ */
+ while ((len = stream2.read(buf)) > 0) {
+ totalLen2 += len;
+ }
+ assertEquals(SAMPLE_SIZE, totalLen2);
+ stream2.close();
+
+ /*
+ * Open a new one.
+ */
+ stream1 = zipFile.getInputStream(zipFile.getEntry("file-0"));
+
+ /*
+ * Close the ZipFile. According to the RI, none if its InputStreams can
+ * be read after this point.
+ */
+ zipFile.close();
+
+ Exception error = null;
+ try {
+ stream1.read(buf);
+ } catch (Exception ex) {
+ error = ex;
+ }
+
+ assertNotNull("ZipFile shouldn't allow reading of closed files.", error);
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/zip/OldAndroidZipStreamTest.java b/luni/src/test/java/libcore/java/util/zip/OldAndroidZipStreamTest.java
new file mode 100644
index 0000000..d8b6c5a
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldAndroidZipStreamTest.java
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import junit.framework.TestCase;
+
+/**
+ * Basic tests for ZipStream
+ */
+public class OldAndroidZipStreamTest extends TestCase {
+
+ public void testZipStream() throws Exception {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ createCompressedZip(bytesOut);
+
+ byte[] zipData = bytesOut.toByteArray();
+
+ /*
+ FileOutputStream outFile = new FileOutputStream("/tmp/foo.zip");
+ outFile.write(zipData, 0, zipData.length);
+ outFile.close();
+ */
+
+ /*
+ FileInputStream inFile = new FileInputStream("/tmp/foo.zip");
+ int inputLength = inFile.available();
+ zipData = new byte[inputLength];
+ if (inFile.read(zipData) != inputLength)
+ throw new RuntimeException();
+ inFile.close();
+ */
+
+ ByteArrayInputStream bytesIn = new ByteArrayInputStream(zipData);
+ scanZip(bytesIn);
+
+ bytesOut = new ByteArrayOutputStream();
+ createUncompressedZip(bytesOut);
+
+ zipData = bytesOut.toByteArray();
+
+ bytesIn = new ByteArrayInputStream(zipData);
+ scanZip(bytesIn);
+ }
+
+ /*
+ * stepStep == 0 --> >99% compression
+ * stepStep == 1 --> ~30% compression
+ * stepStep == 2 --> no compression
+ */
+ private static byte[] makeSampleFile(int stepStep) throws IOException {
+ byte[] sample = new byte[128 * 1024];
+ byte val, step;
+ int i, j, offset;
+
+ val = 0;
+ step = 1;
+ offset = 0;
+ for (i = 0; i < (128 * 1024) / 256; i++) {
+ for (j = 0; j < 256; j++) {
+ sample[offset++] = val;
+ val += step;
+ }
+
+ step += stepStep;
+ }
+
+ return sample;
+ }
+
+ private static void createCompressedZip(ByteArrayOutputStream bytesOut) throws IOException {
+ ZipOutputStream out = new ZipOutputStream(bytesOut);
+ try {
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ byte[] input = makeSampleFile(i);
+ ZipEntry newEntry = new ZipEntry("file-" + i);
+
+ if (i != 1)
+ newEntry.setComment("this is file " + i);
+ out.putNextEntry(newEntry);
+ out.write(input, 0, input.length);
+ out.closeEntry();
+ }
+
+ out.setComment("This is a lovely compressed archive!");
+ } finally {
+ out.close();
+ }
+ }
+
+ private static void createUncompressedZip(ByteArrayOutputStream bytesOut) throws IOException {
+ ZipOutputStream out = new ZipOutputStream(bytesOut);
+ try {
+ long[] crcs = {0x205fbff3, 0x906fae57L, 0x2c235131};
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ byte[] input = makeSampleFile(i);
+ ZipEntry newEntry = new ZipEntry("file-" + i);
+
+ if (i != 1)
+ newEntry.setComment("this is file " + i);
+ newEntry.setMethod(ZipEntry.STORED);
+ newEntry.setSize(128 * 1024);
+ newEntry.setCrc(crcs[i]);
+ out.putNextEntry(newEntry);
+ out.write(input, 0, input.length);
+ out.closeEntry();
+ }
+
+ out.setComment("This is a lovely, but uncompressed, archive!");
+ } finally {
+ out.close();
+ }
+ }
+
+ private static void scanZip(ByteArrayInputStream bytesIn) throws IOException {
+ ZipInputStream in = new ZipInputStream(bytesIn);
+ try {
+ int i;
+
+ for (i = 0; i < 3; i++) {
+ ZipEntry entry = in.getNextEntry();
+ ByteArrayOutputStream contents = new ByteArrayOutputStream();
+ byte[] buf = new byte[4096];
+ int len, totalLen = 0;
+
+ while ((len = in.read(buf)) > 0) {
+ contents.write(buf, 0, len);
+ totalLen += len;
+ }
+
+ assertEquals(128 * 1024, totalLen);
+
+// System.out.println("OldAndroidZipStreamTest: name='" + entry.getName()
+// + "', zero=" + contents.toByteArray()[0]
+// + ", tfs=" + contents.toByteArray()[257]
+// + ", crc=" + Long.toHexString(entry.getCrc()));
+ }
+
+ assertNull("should only be three entries", in.getNextEntry());
+ } finally {
+ in.close();
+ }
+ }
+}
+
diff --git a/luni/src/test/java/libcore/java/util/zip/OldDataFormatExceptionTest.java b/luni/src/test/java/libcore/java/util/zip/OldDataFormatExceptionTest.java
new file mode 100644
index 0000000..3439cd8
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldDataFormatExceptionTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import junit.framework.TestCase;
+
+import java.util.zip.DataFormatException;
+
+public class OldDataFormatExceptionTest extends TestCase {
+
+ public void testDataFormatException() {
+ DataFormatException dfe = new DataFormatException();
+ assertEquals(dfe.getMessage(), null);
+ }
+
+ public void testDataFormatExceptionString() {
+ DataFormatException dfe = new DataFormatException("Test");
+ assertEquals(dfe.getMessage(), "Test");
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/OldZipExceptionTest.java b/luni/src/test/java/libcore/java/util/zip/OldZipExceptionTest.java
new file mode 100644
index 0000000..f44fbf5
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldZipExceptionTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import junit.framework.TestCase;
+
+import java.util.zip.ZipException;
+
+public class OldZipExceptionTest extends TestCase {
+
+ public void testZipException() {
+ ZipException zz = new ZipException();
+ assertEquals(zz.getMessage(), null);
+ }
+
+ public void testZipExceptionLjava_lang_String() {
+ ZipException zz = new ZipException("Test");
+ assertEquals(zz.getMessage(), "Test");
+ }
+
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java b/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java
new file mode 100644
index 0000000..cd28114
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldZipFileTest.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import tests.support.Support_PlatformFile;
+import tests.support.resource.Support_Resources;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FilePermission;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.security.Permission;
+import java.util.Enumeration;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+
+public class OldZipFileTest extends junit.framework.TestCase {
+
+ public byte[] getAllBytesFromStream(InputStream is) throws IOException {
+ ByteArrayOutputStream bs = new ByteArrayOutputStream();
+ byte[] buf = new byte[512];
+ int iRead;
+ while ((iRead = is.read(buf, 0, buf.length)) != -1) {
+ bs.write(buf, 0, iRead);
+ }
+ return bs.toByteArray();
+ }
+
+ public void test_size() throws IOException {
+ zfile.close();
+ try {
+ zfile.size();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ public void test_getEntryLjava_lang_String_AndroidOnly() throws IOException {
+ java.util.zip.ZipEntry zentry = zfile.getEntry("File1.txt");
+ assertNotNull("Could not obtain ZipEntry", zentry);
+ int r;
+ InputStream in;
+
+ zentry = zfile.getEntry("testdir1");
+ assertNotNull("Must be able to obtain ZipEntry: testdir1", zentry);
+ in = zfile.getInputStream(zentry);
+ /*
+ * Android delivers empty InputStream, RI no InputStream at all. The
+ * spec doesn't clarify this, so we need to deal with both situations.
+ */
+ int data = -1;
+ if (in != null) {
+ data = in.read();
+ in.close();
+ }
+ assertEquals("Must not be able to read directory data", -1, data);
+ }
+
+ // the file hyts_zipFile.zip in setup must be included as a resource
+ private String tempFileName;
+
+ private ZipFile zfile;
+
+ /**
+ * @throws IOException
+ * @tests java.util.zip.ZipFile#close()
+ */
+ public void test_close() throws IOException {
+ // Test for method void java.util.zip.ZipFile.close()
+ File fl = new File(tempFileName);
+ ZipFile zf = new ZipFile(fl);
+ InputStream is1 = zf.getInputStream(zf.getEntry("File1.txt"));
+ InputStream is2 = zf.getInputStream(zf.getEntry("File2.txt"));
+
+ is1.read();
+ is2.read();
+
+ zf.close();
+
+ try {
+ is1.read();
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+
+ try {
+ is2.read();
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ }
+
+ public void test_getEntryLjava_lang_String_Ex() throws IOException {
+ java.util.zip.ZipEntry zentry = zfile.getEntry("File1.txt");
+ assertNotNull("Could not obtain ZipEntry", zentry);
+
+ zfile.close();
+ try {
+ zfile.getEntry("File2.txt");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException ee) {
+ }
+ }
+
+ /**
+ * @throws IOException
+ * @tests java.util.zip.ZipFile#getInputStream(java.util.zip.ZipEntry)
+ */
+ public void test_getInputStreamLjava_util_zip_ZipEntry() throws IOException {
+ // Test for method java.io.InputStream
+ // java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)
+ ZipEntry zentry = null;
+ InputStream is = null;
+
+ zentry = zfile.getEntry("File2.txt");
+ zfile.close();
+ try {
+ is = zfile.getInputStream(zentry);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException ee) {
+ // expected
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ @Override
+ protected void setUp() throws IOException {
+ // Create a local copy of the file since some tests want to alter information.
+ tempFileName = System.getProperty("java.io.tmpdir");
+ String separator = System.getProperty("file.separator");
+ if (tempFileName.charAt(tempFileName.length() - 1) == separator.charAt(0)) {
+ tempFileName = Support_PlatformFile.getNewPlatformFile(tempFileName, "gabba.zip");
+ } else {
+ tempFileName = Support_PlatformFile.getNewPlatformFile(
+ tempFileName + separator, "gabba.zip");
+ }
+
+ File f = new File(tempFileName);
+ f.delete();
+ InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
+ FileOutputStream fos = new FileOutputStream(f);
+ byte[] rbuf = getAllBytesFromStream(is);
+ fos.write(rbuf, 0, rbuf.length);
+ is.close();
+ fos.close();
+ zfile = new ZipFile(f);
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ @Override
+ protected void tearDown() throws IOException {
+ // Note zfile is a user-defined zip file used by other tests and
+ // should not be deleted
+ zfile.close();
+ tempFileName = System.getProperty("java.io.tmpdir");
+ String separator = System.getProperty("file.separator");
+ if (tempFileName.charAt(tempFileName.length() - 1) == separator
+ .charAt(0)) {
+ tempFileName = Support_PlatformFile.getNewPlatformFile(
+ tempFileName, "gabba.zip");
+ } else {
+ tempFileName = Support_PlatformFile.getNewPlatformFile(
+ tempFileName + separator, "gabba.zip");
+ }
+
+ File f = new File(tempFileName);
+ f.delete();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/OldZipInputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/OldZipInputStreamTest.java
new file mode 100644
index 0000000..f28817c
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/OldZipInputStreamTest.java
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import junit.framework.TestCase;
+import tests.support.resource.Support_Resources;
+
+public class OldZipInputStreamTest extends TestCase {
+ private ZipInputStream zis;
+ private byte[] dataBytes = "Some data in my file".getBytes();
+
+ @Override
+ protected void setUp() throws IOException {
+ InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
+ if (is == null) {
+ System.out.println("file hyts_ZipFile.zip can not be found");
+ }
+ zis = new ZipInputStream(is);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ZipOutputStream zos = new ZipOutputStream(bos);
+ ZipEntry entry = new ZipEntry("myFile");
+ zos.putNextEntry(entry);
+ zos.write(dataBytes);
+ zos.closeEntry();
+ zos.close();
+ }
+
+ @Override
+ protected void tearDown() throws IOException {
+ if (zis != null) {
+ zis.close();
+ }
+ }
+
+ public void test_skipJ() throws Exception {
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
+ FileInputStream fis = new FileInputStream(new File(resources,
+ "Broken_manifest.jar"));
+
+ ZipInputStream zis1 = new ZipInputStream(fis);
+
+ zis1.getNextEntry();
+ zis1.getNextEntry();
+
+ try {
+ zis1.skip(10);
+ fail("ZipException expected");
+ } catch (ZipException ee) {
+ // expected
+ }
+
+ try {
+ zis1.close(); // Android throws exception here, already!
+ zis1.skip(10); // But RI here, only!
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ }
+
+ public void test_read$BII() throws Exception {
+ byte[] rbuf;
+
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
+ FileInputStream fis = new FileInputStream(new File(resources,
+ "Broken_manifest.jar"));
+
+ ZipInputStream zis1 = new ZipInputStream(fis);
+
+ zis1.getNextEntry();
+ zis1.getNextEntry();
+
+ rbuf = new byte[100];
+
+ try {
+ zis1.read(rbuf, 10, 90);
+ fail("ZipException expected");
+ } catch (ZipException ee) {
+ // expected
+ }
+
+ try {
+ zis1.close(); // Android throws exception here, already!
+ zis1.read(rbuf, 10, 90); // But RI here, only!
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ }
+
+ public void test_closeEntry() throws Exception {
+ zis.getNextEntry();
+ zis.closeEntry();
+ zis.getNextEntry();
+ zis.close();
+ try {
+ zis.closeEntry();
+ fail("IOException expected");
+ } catch (IOException ee) {
+ // expected
+ }
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
+ FileInputStream fis = new FileInputStream(new File(resources,
+ "Broken_manifest.jar"));
+
+ ZipInputStream zis1 = new ZipInputStream(fis);
+
+ try {
+ for (int i = 0; i < 6; i++) {
+ zis1.getNextEntry();
+ zis1.closeEntry();
+ }
+ fail("ZipException expected");
+ } catch (ZipException ee) {
+ // expected
+ }
+ }
+
+ class Mock_ZipInputStream extends ZipInputStream {
+ boolean createFlag = false;
+
+ public Mock_ZipInputStream(InputStream arg0) {
+ super(arg0);
+ }
+
+ boolean getCreateFlag() {
+ return createFlag;
+ }
+
+ protected ZipEntry createZipEntry(String name) {
+ createFlag = true;
+ return super.createZipEntry(name);
+ }
+ }
+
+ public void test_createZipEntryLjava_lang_String() throws Exception {
+
+ File resources = Support_Resources.createTempFolder();
+ Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
+ File fl = new File(resources, "Broken_manifest.jar");
+ FileInputStream fis = new FileInputStream(fl);
+
+ Mock_ZipInputStream zis1 = new Mock_ZipInputStream(fis);
+ assertFalse(zis1.getCreateFlag());
+ zis1.getNextEntry();
+ assertTrue(zis1.getCreateFlag());
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java b/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
index 4d43ba6..b18ebb4 100644
--- a/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/ZipEntryTest.java
@@ -21,13 +21,17 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.List;
+import java.util.jar.JarEntry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
public class ZipEntryTest extends junit.framework.TestCase {
- // http://code.google.com/p/android/issues/detail?id=4690
+
+ /**
+ * http://code.google.com/p/android/issues/detail?id=4690
+ */
public void test_utf8FileNames() throws Exception {
// Create a zip file containing non-ASCII filenames.
File f = File.createTempFile("your", "mum");
@@ -58,4 +62,18 @@ public class ZipEntryTest extends junit.framework.TestCase {
assertEquals(filenames.size(), entryCount);
in.close();
}
+
+ /**
+ * http://b/2099615
+ */
+ public void testClone() {
+ byte[] extra = { 5, 7, 9 };
+ JarEntry jarEntry = new JarEntry("foo");
+ jarEntry.setExtra(extra);
+ assertSame("Expected no defensive copy of extra", extra, jarEntry.getExtra());
+
+ ZipEntry clone = (ZipEntry) jarEntry.clone();
+ assertEquals(JarEntry.class, clone.getClass());
+ assertNotSame(extra, clone.getExtra());
+ }
}
diff --git a/luni/src/test/java/libcore/java/util/zip/ZipFileTest.java b/luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
index 1e01064..89b430f 100644
--- a/luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/ZipFileTest.java
@@ -64,7 +64,7 @@ public final class ZipFileTest extends TestCase {
* Compresses a single random file into a .zip archive.
*/
private File createZipFile(int uncompressedSize) throws IOException {
- File result = File.createTempFile("ZipFileTest", "zip");
+ File result = File.createTempFile("OldZipFileTest", "zip");
result.deleteOnExit();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(result));
diff --git a/luni/src/test/java/libcore/java/util/zip/ZipInputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/ZipInputStreamTest.java
new file mode 100644
index 0000000..cb98322
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/ZipInputStreamTest.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import junit.framework.TestCase;
+
+public final class ZipInputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = "Hello World".getBytes("UTF-8");
+ byte[] zipped = ZipOutputStreamTest.zip("short", data);
+ assertEquals(Arrays.toString(data), Arrays.toString(unzip("short", zipped)));
+ }
+
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, unzip("r", ZipOutputStreamTest.zip("r", data))));
+ }
+
+ public static byte[] unzip(String name, byte[] bytes) throws IOException {
+ ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes));
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ ZipEntry entry = in.getNextEntry();
+ assertEquals(name, entry.getName());
+
+ byte[] buffer = new byte[1024];
+ int count;
+ while ((count = in.read(buffer)) != -1) {
+ out.write(buffer, 0, count);
+ }
+
+ assertNull(in.getNextEntry()); // There's only one entry in the Zip files we create.
+
+ in.close();
+ return out.toByteArray();
+ }
+}
diff --git a/luni/src/test/java/libcore/java/util/zip/ZipOutputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/ZipOutputStreamTest.java
new file mode 100644
index 0000000..e7c518f
--- /dev/null
+++ b/luni/src/test/java/libcore/java/util/zip/ZipOutputStreamTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.java.util.zip;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Random;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipOutputStream;
+import junit.framework.TestCase;
+
+public final class ZipOutputStreamTest extends TestCase {
+ public void testShortMessage() throws IOException {
+ byte[] data = "Hello World".getBytes("UTF-8");
+ byte[] zipped = zip("short", data);
+ assertEquals(Arrays.toString(data), Arrays.toString(ZipInputStreamTest.unzip("short", zipped)));
+ }
+
+ // http://b/3181430 --- a sign-extension bug on CRCs with the top bit set.
+ public void test3181430() throws IOException {
+ byte[] data = new byte[1]; // CRC32({ 0 }) == 0xd202ef8d
+ byte[] zipped = zip("z", data);
+ assertEquals(Arrays.toString(data), Arrays.toString(ZipInputStreamTest.unzip("z", zipped)));
+ }
+
+ public void testLongMessage() throws IOException {
+ byte[] data = new byte[1024 * 1024];
+ new Random().nextBytes(data);
+ assertTrue(Arrays.equals(data, ZipInputStreamTest.unzip("r", zip("r", data))));
+ }
+
+ public static byte[] zip(String name, byte[] bytes) throws IOException {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ ZipOutputStream zippedOut = new ZipOutputStream(bytesOut);
+
+ ZipEntry entry = new ZipEntry(name);
+ zippedOut.putNextEntry(entry);
+ zippedOut.write(bytes);
+ zippedOut.closeEntry();
+
+ zippedOut.close();
+ return bytesOut.toByteArray();
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherInputStreamTest.java b/luni/src/test/java/libcore/javax/crypto/CipherInputStreamTest.java
new file mode 100644
index 0000000..40fd8fd
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/crypto/CipherInputStreamTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.crypto;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import javax.crypto.Cipher;
+import javax.crypto.CipherInputStream;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.SecretKeySpec;
+import junit.framework.TestCase;
+
+public final class CipherInputStreamTest extends TestCase {
+
+ private final byte[] keyBytes = { 127, -2, -95, -39, 35, 118, 121, -92 };
+ private final String plainText = "abcde";
+ private final byte[] cipherText = { 121, -124, -106, 43, -55, -67, -105, -75 };
+ private SecretKey key;
+
+ @Override protected void setUp() throws Exception {
+ key = new SecretKeySpec(keyBytes, "DES");
+ }
+
+ public void testEncrypt() throws Exception {
+ Cipher cipher = Cipher.getInstance("DES");
+ cipher.init(Cipher.ENCRYPT_MODE, key);
+ InputStream in = new CipherInputStream(
+ new ByteArrayInputStream(plainText.getBytes("UTF-8")), cipher);
+ byte[] bytes = readAll(in);
+ assertEquals(Arrays.toString(cipherText), Arrays.toString(bytes));
+ }
+
+ public void testDecrypt() throws Exception {
+ Cipher cipher = Cipher.getInstance("DES");
+ cipher.init(Cipher.DECRYPT_MODE, key);
+ InputStream in = new CipherInputStream(new ByteArrayInputStream(cipherText), cipher);
+ byte[] bytes = readAll(in);
+ assertEquals(plainText, new String(bytes, "UTF-8"));
+ }
+
+ public void testSkip() throws Exception {
+ Cipher cipher = Cipher.getInstance("DES");
+ cipher.init(Cipher.DECRYPT_MODE, key);
+ InputStream in = new CipherInputStream(new ByteArrayInputStream(cipherText), cipher);
+ assertTrue(in.skip(5) > 0);
+ }
+
+ private byte[] readAll(InputStream in) throws IOException {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ int count;
+ byte[] buffer = new byte[1024];
+ while ((count = in.read(buffer)) != -1) {
+ out.write(buffer, 0, count);
+ }
+ return out.toByteArray();
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
new file mode 100644
index 0000000..186355f
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.crypto;
+
+import com.android.org.bouncycastle.asn1.x509.KeyUsage;
+import java.security.InvalidKeyException;
+import java.security.cert.Certificate;
+import javax.crypto.Cipher;
+import junit.framework.TestCase;
+import libcore.java.security.TestKeyStore;
+
+public final class CipherTest extends TestCase {
+
+ public void testCipherInitWithCertificate () throws Exception {
+ // no key usage specified, everything is fine
+ assertCipherInitWithKeyUsage(0, true, true, true, true);
+
+ // common case is that encrypt/wrap is prohibited when special usage is specified
+ assertCipherInitWithKeyUsage(KeyUsage.digitalSignature, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.nonRepudiation, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.keyAgreement, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.keyCertSign, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.cRLSign, false, true, false, true);
+
+ // Note they encipherOnly/decipherOnly don't have to do with
+ // ENCRYPT_MODE or DECRYPT_MODE, but restrict usage relative
+ // to keyAgreement. There is not a *_MODE option that
+ // corresponds to this in Cipher, the RI does not enforce
+ // anything in Cipher.
+ // http://code.google.com/p/android/issues/detail?id=12955
+ assertCipherInitWithKeyUsage(KeyUsage.encipherOnly, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.decipherOnly, false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.keyAgreement | KeyUsage.encipherOnly,
+ false, true, false, true);
+ assertCipherInitWithKeyUsage(KeyUsage.keyAgreement | KeyUsage.decipherOnly,
+ false, true, false, true);
+
+ // except when wraping a key is specifically allowed or
+ assertCipherInitWithKeyUsage(KeyUsage.keyEncipherment, false, true, true, true);
+ // except when wraping data encryption is specifically allowed
+ assertCipherInitWithKeyUsage(KeyUsage.dataEncipherment, true, true, false, true);
+ }
+
+ private void assertCipherInitWithKeyUsage (int keyUsage,
+ boolean allowEncrypt,
+ boolean allowDecrypt,
+ boolean allowWrap,
+ boolean allowUnwrap) throws Exception {
+ Certificate certificate = certificateWithKeyUsage(keyUsage);
+ assertCipherInitWithKeyUsage(certificate, allowEncrypt, Cipher.ENCRYPT_MODE);
+ assertCipherInitWithKeyUsage(certificate, allowDecrypt, Cipher.DECRYPT_MODE);
+ assertCipherInitWithKeyUsage(certificate, allowWrap, Cipher.WRAP_MODE);
+ assertCipherInitWithKeyUsage(certificate, allowUnwrap, Cipher.UNWRAP_MODE);
+ }
+
+ private void assertCipherInitWithKeyUsage(Certificate certificate,
+ boolean allowMode,
+ int mode) throws Exception {
+ Cipher cipher = Cipher.getInstance("RSA");
+ if (allowMode) {
+ cipher.init(mode, certificate);
+ } else {
+ try {
+ cipher.init(mode, certificate);
+ String modeString;
+ switch (mode) {
+ case Cipher.ENCRYPT_MODE:
+ modeString = "ENCRYPT_MODE";
+ break;
+ case Cipher.DECRYPT_MODE:
+ modeString = "DECRYPT_MODE";
+ break;
+ case Cipher.WRAP_MODE:
+ modeString = "WRAP_MODE";
+ break;
+ case Cipher.UNWRAP_MODE:
+ modeString = "UNWRAP_MODE";
+ break;
+ default:
+ throw new AssertionError("Unknown Cipher.*_MODE " + mode);
+ }
+ fail("Should have had InvalidKeyException for " + modeString
+ + " for " + certificate);
+ } catch (InvalidKeyException expected) {
+ }
+ }
+ }
+
+ private Certificate certificateWithKeyUsage(int keyUsage) {
+ // note the rare usage of non-zero keyUsage
+ return TestKeyStore.create(new String[] { "RSA" },
+ null,
+ null,
+ "rsa-dsa-ec",
+ TestKeyStore.localhost(),
+ keyUsage,
+ true,
+ null,
+ null).getPrivateKey("RSA", "RSA").getCertificate();
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/crypto/KeyGeneratorTest.java b/luni/src/test/java/libcore/javax/crypto/KeyGeneratorTest.java
new file mode 100644
index 0000000..cd6f886
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/crypto/KeyGeneratorTest.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.crypto;
+
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Security;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import junit.framework.TestCase;
+
+public class KeyGeneratorTest extends TestCase {
+
+ private static boolean isUnsupported(KeyGenerator kg) {
+ // Don't bother testing "Sun..." KeyGenerators
+ return (kg.getAlgorithm().startsWith("Sun"));
+ }
+
+ public void test_getInstance() throws Exception {
+ Provider[] providers = Security.getProviders();
+ for (Provider provider : providers) {
+ Set<Provider.Service> services = provider.getServices();
+ for (Provider.Service service : services) {
+ String type = service.getType();
+ if (!type.equals("KeyGenerator")) {
+ continue;
+ }
+ String algorithm = service.getAlgorithm();
+ try {
+ // KeyGenerator.getInstance(String)
+ KeyGenerator kg1 = KeyGenerator.getInstance(algorithm);
+ assertEquals(algorithm, kg1.getAlgorithm());
+ test_KeyGenerator(kg1);
+
+ // KeyGenerator.getInstance(String, Provider)
+ KeyGenerator kg2 = KeyGenerator.getInstance(algorithm, provider);
+ assertEquals(algorithm, kg2.getAlgorithm());
+ assertEquals(provider, kg2.getProvider());
+ test_KeyGenerator(kg2);
+
+ // KeyGenerator.getInstance(String, String)
+ KeyGenerator kg3 = KeyGenerator.getInstance(algorithm, provider.getName());
+ assertEquals(algorithm, kg3.getAlgorithm());
+ assertEquals(provider, kg3.getProvider());
+ test_KeyGenerator(kg3);
+ } catch (Exception e) {
+ throw new Exception("Problem testing KeyPairGenerator." + algorithm, e);
+ }
+ }
+ }
+ }
+
+ private static final Map<String, List<Integer>> KEY_SIZES
+ = new HashMap<String, List<Integer>>();
+ private static void putKeySize(String algorithm, int keySize) {
+ algorithm = algorithm.toUpperCase();
+ List<Integer> keySizes = KEY_SIZES.get(algorithm);
+ if (keySizes == null) {
+ keySizes = new ArrayList<Integer>();
+ KEY_SIZES.put(algorithm, keySizes);
+ }
+ keySizes.add(keySize);
+ }
+ private static List<Integer> getKeySizes(String algorithm) throws Exception {
+ algorithm = algorithm.toUpperCase();
+ List<Integer> keySizes = KEY_SIZES.get(algorithm);
+ if (keySizes == null) {
+ throw new Exception("Unknown key sizes for KeyGenerator." + algorithm);
+ }
+ return keySizes;
+ }
+ static {
+ putKeySize("AES", 128);
+ putKeySize("AES", 192);
+ putKeySize("AES", 256);
+ putKeySize("ARCFOUR", 40);
+ putKeySize("ARCFOUR", 41);
+ putKeySize("ARCFOUR", 1024);
+ putKeySize("Blowfish", 32);
+ putKeySize("Blowfish", 32+8);
+ putKeySize("Blowfish", 448);
+ putKeySize("DES", 56);
+ putKeySize("DESede", 112);
+ putKeySize("DESede", 168);
+ putKeySize("RC2", 40);
+ putKeySize("RC2", 41);
+ putKeySize("RC2", 1024);
+ putKeySize("RC4", 40);
+ putKeySize("RC4", 41);
+ putKeySize("RC4", 1024);
+ putKeySize("HmacMD5", 1);
+ putKeySize("HmacMD5", 1025);
+ putKeySize("HmacSHA1", 1);
+ putKeySize("HmacSHA1", 1025);
+ putKeySize("HmacSHA256", 40);
+ putKeySize("HmacSHA256", 1025);
+ putKeySize("HmacSHA384", 40);
+ putKeySize("HmacSHA384", 1025);
+ putKeySize("HmacSHA512", 40);
+ putKeySize("HmacSHA512", 1025);
+ }
+
+ private void test_KeyGenerator(KeyGenerator kg) throws Exception {
+ if (isUnsupported(kg)) {
+ return;
+ }
+
+ kg.init((SecureRandom) null);
+ test_SecretKey(kg, kg.generateKey());
+
+ kg.init(new SecureRandom());
+ test_SecretKey(kg, kg.generateKey());
+
+ String algorithm = kg.getAlgorithm();
+ List<Integer> keySizes = getKeySizes(algorithm);
+ for (int keySize : keySizes) {
+ kg.init(keySize);
+ test_SecretKey(kg, kg.generateKey());
+
+ kg.init(keySize, (SecureRandom) null);
+ test_SecretKey(kg, kg.generateKey());
+
+ kg.init(keySize, new SecureRandom());
+ test_SecretKey(kg, kg.generateKey());
+ }
+ }
+
+ private void test_SecretKey(KeyGenerator kg, SecretKey sk) throws Exception {
+ assertNotNull(sk);
+ assertEquals(kg.getAlgorithm().toUpperCase(), sk.getAlgorithm().toUpperCase());
+ assertNotNull(sk.getEncoded());
+ assertNotNull(sk.getFormat());
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java b/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
index 06ba01c..2ff9567 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/KeyManagerFactoryTest.java
@@ -17,31 +17,38 @@
package libcore.javax.net.ssl;
import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore.Builder;
+import java.security.KeyStore.PasswordProtection;
import java.security.KeyStore.PrivateKeyEntry;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.Security;
-import libcore.java.security.StandardNames;
-import libcore.java.security.TestKeyStore;
import java.security.cert.X509Certificate;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Set;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.KeyStoreBuilderParameters;
+import javax.net.ssl.ManagerFactoryParameters;
import javax.net.ssl.X509ExtendedKeyManager;
import javax.net.ssl.X509KeyManager;
import junit.framework.TestCase;
+import libcore.java.security.StandardNames;
+import libcore.java.security.TestKeyStore;
public class KeyManagerFactoryTest extends TestCase {
// note the rare usage of DSA keys here in addition to RSA
private static final TestKeyStore TEST_KEY_STORE
- = TestKeyStore.create(new String[] { "RSA", "DSA" },
+ = TestKeyStore.create(new String[] { "RSA", "DSA", "EC", "EC_RSA" },
null,
null,
- "rsa-dsa",
+ "rsa-dsa-ec",
TestKeyStore.localhost(),
+ 0,
true,
+ null,
null);
public void test_KeyManagerFactory_getDefaultAlgorithm() throws Exception {
@@ -51,7 +58,22 @@ public class KeyManagerFactoryTest extends TestCase {
test_KeyManagerFactory(kmf);
}
- private void test_KeyManagerFactory (KeyManagerFactory kmf) throws Exception {
+ private static class UseslessManagerFactoryParameters implements ManagerFactoryParameters {}
+
+ private static boolean supportsManagerFactoryParameters(String algorithm) {
+ // Only the "New" one supports ManagerFactoryParameters
+ return algorithm.equals("NewSunX509");
+ }
+
+ private static String[] keyTypes(String algorithm) {
+ // Although the "New" one supports ManagerFactoryParameters,
+ // it can't handle nulls in the key types array.
+ return (algorithm.equals("NewSunX509")
+ ? KEY_TYPES_WITH_EMPTY
+ : KEY_TYPES_WITH_EMPTY_AND_NULL);
+ }
+
+ private void test_KeyManagerFactory(KeyManagerFactory kmf) throws Exception {
assertNotNull(kmf);
assertNotNull(kmf.getAlgorithm());
assertNotNull(kmf.getProvider());
@@ -59,90 +81,181 @@ public class KeyManagerFactoryTest extends TestCase {
// before init
try {
kmf.getKeyManagers();
+ fail();
} catch (IllegalStateException expected) {
}
- // init with ManagerFactoryParameters
+ // init with null ManagerFactoryParameters
try {
kmf.init(null);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+
+ // init with useless ManagerFactoryParameters
+ try {
+ kmf.init(new UseslessManagerFactoryParameters());
+ fail();
} catch (InvalidAlgorithmParameterException expected) {
}
+ // init with KeyStoreBuilderParameters ManagerFactoryParameters
+ PasswordProtection pp = new PasswordProtection(TEST_KEY_STORE.storePassword);
+ Builder builder = Builder.newInstance(TEST_KEY_STORE.keyStore, pp);
+ KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(builder);
+ if (supportsManagerFactoryParameters(kmf.getAlgorithm())) {
+ kmf.init(ksbp);
+ test_KeyManagerFactory_getKeyManagers(kmf, false);
+ } else {
+ try {
+ kmf.init(ksbp);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+ }
+
+ // init with null for default behavior
kmf.init(null, null);
- test_KeyManagerFactory_getKeyManagers(kmf);
+ test_KeyManagerFactory_getKeyManagers(kmf, true);
+ // init with specific key store and password
kmf.init(TEST_KEY_STORE.keyStore, TEST_KEY_STORE.storePassword);
- test_KeyManagerFactory_getKeyManagers(kmf);
+ test_KeyManagerFactory_getKeyManagers(kmf, false);
}
- private void test_KeyManagerFactory_getKeyManagers (KeyManagerFactory kmf) {
+ private void test_KeyManagerFactory_getKeyManagers(KeyManagerFactory kmf, boolean empty) {
KeyManager[] keyManagers = kmf.getKeyManagers();
assertNotNull(keyManagers);
assertTrue(keyManagers.length > 0);
for (KeyManager keyManager : keyManagers) {
assertNotNull(keyManager);
if (keyManager instanceof X509KeyManager) {
- test_X509KeyManager((X509KeyManager)keyManager);
+ test_X509KeyManager((X509KeyManager) keyManager, empty, kmf.getAlgorithm());
}
}
}
- String[] KEY_TYPES
+ private static final String[] KEY_TYPES_ONLY
= StandardNames.KEY_TYPES.toArray(new String[StandardNames.KEY_TYPES.size()]);
+ private static final String[] KEY_TYPES_WITH_EMPTY
+ = new String[KEY_TYPES_ONLY.length + 1];
+ private static final String[] KEY_TYPES_WITH_EMPTY_AND_NULL
+ = new String[KEY_TYPES_ONLY.length + 2];
+ static {
+ System.arraycopy(KEY_TYPES_ONLY, 0,
+ KEY_TYPES_WITH_EMPTY, 0,
+ KEY_TYPES_ONLY.length);
+ KEY_TYPES_WITH_EMPTY[KEY_TYPES_WITH_EMPTY.length-1] = "";
+
+ System.arraycopy(KEY_TYPES_WITH_EMPTY, 0,
+ KEY_TYPES_WITH_EMPTY_AND_NULL, 0,
+ KEY_TYPES_WITH_EMPTY.length);
+ // extra null at end requires no initialization
+ }
- private void test_X509KeyManager(X509KeyManager km) {
- test_X509KeyManager_alias(km, km.chooseClientAlias(KEY_TYPES, null, null), null);
- for (String keyType : KEY_TYPES) {
- test_X509KeyManager_alias(km, km.chooseServerAlias(keyType, null, null), keyType);
+ private void test_X509KeyManager(X509KeyManager km, boolean empty, String algorithm) {
+ String[] keyTypes = keyTypes(algorithm);
+ for (String keyType : keyTypes) {
+ String[] aliases = km.getClientAliases(keyType, null);
+ if (empty || keyType == null || keyType.isEmpty()) {
+ assertNull(keyType, aliases);
+ continue;
+ }
+ assertNotNull(keyType, aliases);
+ for (String alias : aliases) {
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
+ }
}
- for (String keyType : KEY_TYPES) {
+ for (String keyType : keyTypes) {
String[] aliases = km.getServerAliases(keyType, null);
- if (aliases == null) {
+ if (empty || keyType == null || keyType.isEmpty()) {
+ assertNull(keyType, aliases);
continue;
}
+ assertNotNull(keyType, aliases);
for (String alias : aliases) {
- test_X509KeyManager_alias(km, alias, keyType);
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
}
}
+ String a = km.chooseClientAlias(keyTypes, null, null);
+ test_X509KeyManager_alias(km, a, null, true, empty);
+
+ for (String keyType : keyTypes) {
+ String[] array = new String[] { keyType };
+ String alias = km.chooseClientAlias(array, null, null);
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
+ }
+ for (String keyType : keyTypes) {
+ String alias = km.chooseServerAlias(keyType, null, null);
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
+ }
if (km instanceof X509ExtendedKeyManager) {
- test_X509ExtendedKeyManager((X509ExtendedKeyManager)km);
+ test_X509ExtendedKeyManager((X509ExtendedKeyManager) km, empty, algorithm);
}
}
- private void test_X509ExtendedKeyManager(X509ExtendedKeyManager km) {
- test_X509KeyManager_alias(km,
- km.chooseEngineClientAlias(KEY_TYPES, null, null),
- null);
- for (String keyType : KEY_TYPES) {
- test_X509KeyManager_alias(km, km.chooseEngineServerAlias(keyType, null, null), keyType);
+ private void test_X509ExtendedKeyManager(X509ExtendedKeyManager km,
+ boolean empty, String algorithm) {
+ String[] keyTypes = keyTypes(algorithm);
+ String a = km.chooseEngineClientAlias(keyTypes, null, null);
+ test_X509KeyManager_alias(km, a, null, true, empty);
+ for (String keyType : keyTypes) {
+ String[] array = new String[] { keyType };
+ String alias = km.chooseEngineClientAlias(array, null, null);
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
+ }
+ for (String keyType : keyTypes) {
+ String alias = km.chooseEngineServerAlias(keyType, null, null);
+ test_X509KeyManager_alias(km, alias, keyType, false, empty);
}
}
- private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType) {
- if (alias == null) {
- assertNull(km.getCertificateChain(alias));
- assertNull(km.getPrivateKey(alias));
+ private void test_X509KeyManager_alias(X509KeyManager km,
+ String alias,
+ String keyType,
+ boolean many,
+ boolean empty) {
+ if (empty || (!many && (keyType == null || keyType.isEmpty()))) {
+ assertNull(keyType, alias);
+ assertNull(keyType, km.getCertificateChain(alias));
+ assertNull(keyType, km.getPrivateKey(alias));
return;
}
+ assertNotNull(keyType, alias);
X509Certificate[] certificateChain = km.getCertificateChain(alias);
PrivateKey privateKey = km.getPrivateKey(alias);
+ String keyAlgName;
+ String sigAlgName;
if (keyType == null) {
- keyType = privateKey.getAlgorithm();
+ keyAlgName = privateKey.getAlgorithm();
+ sigAlgName = keyAlgName;
} else {
- assertEquals(keyType, certificateChain[0].getPublicKey().getAlgorithm());
- assertEquals(keyType, privateKey.getAlgorithm());
+ // potentially handle EC_EC or EC_RSA
+ keyAlgName = TestKeyStore.keyAlgorithm(keyType);
+ sigAlgName = TestKeyStore.signatureAlgorithm(keyType);
+ X509Certificate certificate = certificateChain[0];
+ assertEquals(keyType, keyAlgName, certificate.getPublicKey().getAlgorithm());
+ assertEquals(keyType, keyAlgName, privateKey.getAlgorithm());
+ // skip this for EC which could return EC_RSA case instead of EC_EC
+ if (!keyType.equals("EC")) {
+ String expectedSigAlgName = sigAlgName.toUpperCase();
+ String actualSigAlgName = certificate.getSigAlgName().toUpperCase();
+ String expected = actualSigAlgName + " contains " + expectedSigAlgName;
+ assertTrue(expected, actualSigAlgName.contains(expectedSigAlgName));
+ }
}
- PrivateKeyEntry privateKeyEntry
- = TestKeyStore.privateKey(TEST_KEY_STORE.keyStore,
- TEST_KEY_STORE.storePassword,
- keyType);
- assertEquals(Arrays.asList(privateKeyEntry.getCertificateChain()),
- Arrays.asList(certificateChain));
- assertEquals(privateKeyEntry.getPrivateKey(), privateKey);
+ PrivateKeyEntry privateKeyEntry = TEST_KEY_STORE.getPrivateKey(keyAlgName, sigAlgName);
+ if (!"EC".equals(keyAlgName)) {
+ assertEquals(keyType,
+ Arrays.asList(privateKeyEntry.getCertificateChain()),
+ Arrays.asList(certificateChain));
+ assertEquals(keyType,
+ privateKeyEntry.getPrivateKey(), privateKey);
+ }
}
public void test_KeyManagerFactory_getInstance() throws Exception {
@@ -155,27 +268,30 @@ public class KeyManagerFactoryTest extends TestCase {
continue;
}
String algorithm = service.getAlgorithm();
+ try {
+ {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
+ assertEquals(algorithm, kmf.getAlgorithm());
+ test_KeyManagerFactory(kmf);
+ }
- {
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm);
- assertEquals(algorithm, kmf.getAlgorithm());
- test_KeyManagerFactory(kmf);
- }
-
- {
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm,
- provider);
- assertEquals(algorithm, kmf.getAlgorithm());
- assertEquals(provider, kmf.getProvider());
- test_KeyManagerFactory(kmf);
- }
+ {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm,
+ provider);
+ assertEquals(algorithm, kmf.getAlgorithm());
+ assertEquals(provider, kmf.getProvider());
+ test_KeyManagerFactory(kmf);
+ }
- {
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm,
- provider.getName());
- assertEquals(algorithm, kmf.getAlgorithm());
- assertEquals(provider, kmf.getProvider());
- test_KeyManagerFactory(kmf);
+ {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(algorithm,
+ provider.getName());
+ assertEquals(algorithm, kmf.getAlgorithm());
+ assertEquals(provider, kmf.getProvider());
+ test_KeyManagerFactory(kmf);
+ }
+ } catch (Exception e) {
+ throw new Exception("Problem with algorithm " + algorithm, e);
}
}
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java b/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java
new file mode 100644
index 0000000..1e17a79
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/net/ssl/KeyStoreBuilderParametersTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.net.ssl;
+
+import java.security.KeyStore.Builder;
+import java.security.KeyStore.PasswordProtection;
+import javax.net.ssl.KeyStoreBuilderParameters;
+import java.util.Arrays;
+import java.util.List;
+import junit.framework.TestCase;
+import libcore.java.security.TestKeyStore;
+
+public class KeyStoreBuilderParametersTest extends TestCase {
+ public void test_init_Builder_null() {
+ // RI document claims they throw NullPointerException but they do not
+ test_init_Builder(null);
+ }
+
+ public void test_init_Builder() {
+ TestKeyStore testKeyStore = TestKeyStore.getClient();
+ Builder builder = Builder.newInstance(testKeyStore.keyStore,
+ new PasswordProtection(testKeyStore.storePassword));
+ test_init_Builder(builder);
+ }
+
+ private void test_init_Builder(Builder builder) {
+
+ KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(builder);
+ assertNotNull(ksbp);
+ assertNotNull(ksbp.getParameters());
+ assertEquals(1, ksbp.getParameters().size());
+ assertSame(builder, ksbp.getParameters().get(0));
+ }
+
+ public void test_init_List_null() {
+ try {
+ new KeyStoreBuilderParameters((List) null);
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ public void test_init_List() {
+ TestKeyStore testKeyStore1 = TestKeyStore.getClient();
+ TestKeyStore testKeyStore2 = TestKeyStore.getServer();
+ Builder builder1 = Builder.newInstance(testKeyStore1.keyStore,
+ new PasswordProtection(testKeyStore1.storePassword));
+ Builder builder2 = Builder.newInstance(testKeyStore2.keyStore,
+ new PasswordProtection(testKeyStore2.storePassword));
+
+ List list = Arrays.asList(builder1, builder2);
+ KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(list);
+ assertNotNull(ksbp);
+ assertNotNull(ksbp.getParameters());
+ assertNotSame(list, ksbp.getParameters());
+ assertEquals(2, ksbp.getParameters().size());
+ assertSame(builder1, ksbp.getParameters().get(0));
+ assertSame(builder2, ksbp.getParameters().get(1));
+
+ // confirm result is not modifiable
+ try {
+ ksbp.getParameters().set(0, builder2);
+ fail();
+ } catch (UnsupportedOperationException expected) {
+ }
+
+ // confirm result is a copy of original
+ list.set(0, builder2);
+ assertSame(builder1, ksbp.getParameters().get(0));
+ }
+}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
index 5c26a00..51570ff 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLContextTest.java
@@ -295,7 +295,7 @@ public class SSLContextTest extends TestCase {
assertNotNull(testContext.clientKeyStore);
assertNull(testContext.clientStorePassword);
assertNotNull(testContext.serverKeyStore);
- assertNull(testContext.serverStorePassword);
+ assertEquals(StandardNames.IS_RI, testContext.serverStorePassword != null);
assertNotNull(testContext.clientKeyManager);
assertNotNull(testContext.serverKeyManager);
assertNotNull(testContext.clientTrustManager);
@@ -305,5 +305,6 @@ public class SSLContextTest extends TestCase {
assertNotNull(testContext.serverSocket);
assertNotNull(testContext.host);
assertTrue(testContext.port != 0);
+ testContext.close();
}
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
index 94558db..d7e7c67 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLEngineTest.java
@@ -16,7 +16,6 @@
package libcore.javax.net.ssl;
-import dalvik.annotation.KnownFailure;
import libcore.java.security.StandardNames;
import libcore.java.security.TestKeyStore;
import java.util.Arrays;
@@ -62,40 +61,70 @@ public class SSLEngineTest extends TestCase {
TestSSLContext c = TestSSLContext.create();
SSLEngine e = c.clientContext.createSSLEngine();
String[] cipherSuites = e.getSupportedCipherSuites();
- StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
+ StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES_SSLENGINE,
+ cipherSuites);
assertNotSame(cipherSuites, e.getSupportedCipherSuites());
+ c.close();
}
- @KnownFailure("No *_WITH_NULL_* ciphers work because of 'Invalid transformation: null'")
public void test_SSLEngine_getSupportedCipherSuites_connect() throws Exception {
- // note the rare usage of DSA keys here in addition to RSA
- TestKeyStore testKeyStore = TestKeyStore.create(new String[] { "RSA", "DSA" },
- null,
- null,
- "rsa-dsa",
- TestKeyStore.localhost(),
- true,
- null);
+ // note the rare usage of non-RSA keys
+ TestKeyStore testKeyStore
+ = TestKeyStore.create(new String[] { "RSA", "DSA", "EC", "EC_RSA" },
+ null,
+ null,
+ "rsa-dsa-ec",
+ TestKeyStore.localhost(),
+ 0,
+ true,
+ null,
+ null);
+ test_SSLEngine_getSupportedCipherSuites_connect(testKeyStore, false);
+ if (StandardNames.IS_RI) {
+ test_SSLEngine_getSupportedCipherSuites_connect(testKeyStore, true);
+ }
+ }
+ private void test_SSLEngine_getSupportedCipherSuites_connect(TestKeyStore testKeyStore,
+ boolean secureRenegotiation)
+ throws Exception {
TestSSLContext c = TestSSLContext.create(testKeyStore, testKeyStore);
String[] cipherSuites = c.clientContext.createSSLEngine().getSupportedCipherSuites();
for (String cipherSuite : cipherSuites) {
- /*
- * Kerberos cipher suites require external setup. See "Kerberos Requirements" in
- * https://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#KRBRequire
- */
- if (cipherSuite.startsWith("TLS_KRB5_")) {
- continue;
- }
- // System.out.println("Trying to connect cipher suite " + cipherSuite);
- final String[] cipherSuiteArray = new String[] { cipherSuite };
- assertConnected(TestSSLEnginePair.create(c, new TestSSLEnginePair.Hooks() {
- @Override
- void beforeBeginHandshake(SSLEngine client, SSLEngine server) {
- client.setEnabledCipherSuites(cipherSuiteArray);
- server.setEnabledCipherSuites(cipherSuiteArray);
+ try {
+ /*
+ * TLS_EMPTY_RENEGOTIATION_INFO_SCSV cannot be used on
+ * its own, but instead in conjunction with other
+ * cipher suites.
+ */
+ if (cipherSuite.equals(StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION)) {
+ continue;
}
- }));
+ /*
+ * Kerberos cipher suites require external setup. See "Kerberos Requirements" in
+ * https://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html
+ * #KRBRequire
+ */
+ if (cipherSuite.startsWith("TLS_KRB5_")) {
+ continue;
+ }
+
+ final String[] cipherSuiteArray
+ = (secureRenegotiation
+ ? new String[] { cipherSuite,
+ StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION }
+ : new String[] { cipherSuite });
+ assertConnected(TestSSLEnginePair.create(c, new TestSSLEnginePair.Hooks() {
+ @Override
+ void beforeBeginHandshake(SSLEngine client, SSLEngine server) {
+ client.setEnabledCipherSuites(cipherSuiteArray);
+ server.setEnabledCipherSuites(cipherSuiteArray);
+ }
+ }));
+ } catch (Exception e) {
+ throw new Exception("Problem trying to connect cipher suite " + cipherSuite, e);
+ }
}
+ c.close();
}
public void test_SSLEngine_getEnabledCipherSuites() throws Exception {
@@ -104,6 +133,7 @@ public class SSLEngineTest extends TestCase {
String[] cipherSuites = e.getEnabledCipherSuites();
StandardNames.assertValidCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
assertNotSame(cipherSuites, e.getEnabledCipherSuites());
+ c.close();
}
public void test_SSLEngine_setEnabledCipherSuites() throws Exception {
@@ -129,6 +159,7 @@ public class SSLEngineTest extends TestCase {
e.setEnabledCipherSuites(new String[0]);
e.setEnabledCipherSuites(e.getEnabledCipherSuites());
e.setEnabledCipherSuites(e.getSupportedCipherSuites());
+ c.close();
}
public void test_SSLEngine_getSupportedProtocols() throws Exception {
@@ -137,6 +168,7 @@ public class SSLEngineTest extends TestCase {
String[] protocols = e.getSupportedProtocols();
StandardNames.assertSupportedProtocols(StandardNames.SSL_SOCKET_PROTOCOLS, protocols);
assertNotSame(protocols, e.getSupportedProtocols());
+ c.close();
}
public void test_SSLEngine_getEnabledProtocols() throws Exception {
@@ -145,6 +177,7 @@ public class SSLEngineTest extends TestCase {
String[] protocols = e.getEnabledProtocols();
StandardNames.assertValidProtocols(StandardNames.SSL_SOCKET_PROTOCOLS, protocols);
assertNotSame(protocols, e.getEnabledProtocols());
+ c.close();
}
public void test_SSLEngine_setEnabledProtocols() throws Exception {
@@ -169,6 +202,7 @@ public class SSLEngineTest extends TestCase {
e.setEnabledProtocols(new String[0]);
e.setEnabledProtocols(e.getEnabledProtocols());
e.setEnabledProtocols(e.getSupportedProtocols());
+ c.close();
}
public void test_SSLEngine_getSession() throws Exception {
@@ -177,6 +211,7 @@ public class SSLEngineTest extends TestCase {
SSLSession session = e.getSession();
assertNotNull(session);
assertFalse(session.isValid());
+ c.close();
}
public void test_SSLEngine_beginHandshake() throws Exception {
@@ -189,9 +224,10 @@ public class SSLEngineTest extends TestCase {
}
assertConnected(TestSSLEnginePair.create(null));
+
+ c.close();
}
- @KnownFailure("NO SERVER CERTIFICATE FOUND")
public void test_SSLEngine_beginHandshake_noKeyStore() throws Exception {
TestSSLContext c = TestSSLContext.create(null, null, null, null, null, null, null, null,
SSLContext.getDefault(), SSLContext.getDefault());
@@ -202,21 +238,23 @@ public class SSLEngineTest extends TestCase {
fail();
} catch (SSLHandshakeException expected) {
}
+ c.close();
}
public void test_SSLEngine_beginHandshake_noClientCertificate() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLEngine[] engines = TestSSLEnginePair.connect(c, null);
assertConnected(engines[0], engines[1]);
+ c.close();
}
public void test_SSLEngine_getUseClientMode() throws Exception {
TestSSLContext c = TestSSLContext.create();
assertFalse(c.clientContext.createSSLEngine().getUseClientMode());
assertFalse(c.clientContext.createSSLEngine(null, -1).getUseClientMode());
+ c.close();
}
- @KnownFailure("SSLHandshakeException instead assertNotConnected")
public void test_SSLEngine_setUseClientMode() throws Exception {
// client is client, server is server
assertConnected(test_SSLEngine_setUseClientMode(true, false));
@@ -266,7 +304,6 @@ public class SSLEngineTest extends TestCase {
});
}
- @KnownFailure("init - invalid private key")
public void test_SSLEngine_clientAuth() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLEngine e = c.clientContext.createSSLEngine();
@@ -305,15 +342,17 @@ public class SSLEngineTest extends TestCase {
TestKeyStore.assertChainLength(p.client.getSession().getLocalCertificates());
TestSSLContext.assertClientCertificateChain(clientAuthContext.clientTrustManager,
p.client.getSession().getLocalCertificates());
+ clientAuthContext.close();
+ c.close();
}
public void test_SSLEngine_getEnableSessionCreation() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLEngine e = c.clientContext.createSSLEngine();
assertTrue(e.getEnableSessionCreation());
+ c.close();
}
- @KnownFailure("SSLException instead assertNotConnected")
public void test_SSLEngine_setEnableSessionCreation_server() throws Exception {
TestSSLEnginePair p = TestSSLEnginePair.create(new TestSSLEnginePair.Hooks() {
@Override
@@ -324,7 +363,6 @@ public class SSLEngineTest extends TestCase {
assertNotConnected(p);
}
- @KnownFailure("AlertException instead of SSLException")
public void test_SSLEngine_setEnableSessionCreation_client() throws Exception {
try {
TestSSLEnginePair.create(new TestSSLEnginePair.Hooks() {
@@ -357,6 +395,8 @@ public class SSLEngineTest extends TestCase {
assertEquals(p.getWantClientAuth(), e.getWantClientAuth());
assertEquals(p.getNeedClientAuth(), e.getNeedClientAuth());
+
+ c.close();
}
public void test_SSLEngine_setSSLParameters() throws Exception {
@@ -409,6 +449,7 @@ public class SSLEngineTest extends TestCase {
assertFalse(e.getNeedClientAuth());
assertFalse(e.getWantClientAuth());
}
+ c.close();
}
public void test_TestSSLEnginePair_create() throws Exception {
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionContextTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionContextTest.java
index 3263c57..d75dc23 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionContextTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionContextTest.java
@@ -16,12 +16,15 @@
package libcore.javax.net.ssl;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
import javax.net.ssl.SSLSessionContext;
+import javax.net.ssl.SSLSocket;
import junit.framework.TestCase;
public class SSLSessionContextTest extends TestCase {
@@ -56,6 +59,7 @@ public class SSLSessionContextTest extends TestCase {
public void test_SSLSessionContext_getIds() {
TestSSLContext c = TestSSLContext.create();
assertSSLSessionContextSize(0, c);
+ c.close();
TestSSLSocketPair s = TestSSLSocketPair.create();
assertSSLSessionContextSize(1, s.c);
@@ -70,6 +74,7 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(32, serverId.length);
assertTrue(Arrays.equals(clientId, serverId));
}
+ s.close();
}
public void test_SSLSessionContext_getSession() {
@@ -88,6 +93,7 @@ public class SSLSessionContextTest extends TestCase {
}
assertNull(c.serverContext.getServerSessionContext().getSession(new byte[0]));
assertNull(c.serverContext.getServerSessionContext().getSession(new byte[1]));
+ c.close();
TestSSLSocketPair s = TestSSLSocketPair.create();
SSLSessionContext client = s.c.clientContext.getClientSessionContext();
@@ -102,6 +108,7 @@ public class SSLSessionContextTest extends TestCase {
assertNotNull(server.getSession(serverId));
assertTrue(Arrays.equals(serverId, server.getSession(serverId).getId()));
}
+ s.close();
}
public void test_SSLSessionContext_getSessionCacheSize() {
@@ -110,12 +117,14 @@ public class SSLSessionContextTest extends TestCase {
c.clientContext.getClientSessionContext().getSessionCacheSize());
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SERVER_SSL_SESSION_CACHE_SIZE,
c.serverContext.getServerSessionContext().getSessionCacheSize());
+ c.close();
TestSSLSocketPair s = TestSSLSocketPair.create();
assertEquals(TestSSLContext.EXPECTED_DEFAULT_CLIENT_SSL_SESSION_CACHE_SIZE,
s.c.clientContext.getClientSessionContext().getSessionCacheSize());
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SERVER_SSL_SESSION_CACHE_SIZE,
s.c.serverContext.getServerSessionContext().getSessionCacheSize());
+ s.close();
}
public void test_SSLSessionContext_setSessionCacheSize_noConnect() {
@@ -126,6 +135,7 @@ public class SSLSessionContextTest extends TestCase {
assertNoConnectSetSessionCacheSizeBehavior(
TestSSLContext.EXPECTED_DEFAULT_SERVER_SSL_SESSION_CACHE_SIZE,
c.serverContext.getServerSessionContext());
+ c.close();
}
private static void assertNoConnectSetSessionCacheSizeBehavior(int expectedDefault,
@@ -149,9 +159,10 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SERVER_SSL_SESSION_CACHE_SIZE,
server.getSessionCacheSize());
assertSSLSessionContextSize(1, s.c);
+ s.close();
}
- public void test_SSLSessionContext_setSessionCacheSize_dynamic() {
+ public void test_SSLSessionContext_setSessionCacheSize_dynamic() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLSessionContext client = c.clientContext.getClientSessionContext();
SSLSessionContext server = c.serverContext.getServerSessionContext();
@@ -201,11 +212,12 @@ public class SSLSessionContextTest extends TestCase {
String cipherSuite2 = uniqueCipherSuites.get(1);
String cipherSuite3 = uniqueCipherSuites.get(2);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null);
+ List<SSLSocket[]> toClose = new ArrayList<SSLSocket[]>();
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null));
assertSSLSessionContextSize(1, c);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null);
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null));
assertSSLSessionContextSize(2, c);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null);
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null));
assertSSLSessionContextSize(3, c);
client.setSessionCacheSize(1);
@@ -213,15 +225,22 @@ public class SSLSessionContextTest extends TestCase {
assertEquals(1, client.getSessionCacheSize());
assertEquals(1, server.getSessionCacheSize());
assertSSLSessionContextSize(1, c);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null);
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite1 }, null));
assertSSLSessionContextSize(1, c);
client.setSessionCacheSize(2);
server.setSessionCacheSize(2);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null);
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite2 }, null));
assertSSLSessionContextSize(2, c);
- TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null);
+ toClose.add(TestSSLSocketPair.connect(c, new String[] { cipherSuite3 }, null));
assertSSLSessionContextSize(2, c);
+
+ for (SSLSocket[] pair : toClose) {
+ for (SSLSocket s : pair) {
+ s.close();
+ }
+ }
+ c.close();
}
public void test_SSLSessionContext_getSessionTimeout() {
@@ -230,12 +249,14 @@ public class SSLSessionContextTest extends TestCase {
c.clientContext.getClientSessionContext().getSessionTimeout());
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SSL_SESSION_CACHE_TIMEOUT,
c.serverContext.getServerSessionContext().getSessionTimeout());
+ c.close();
TestSSLSocketPair s = TestSSLSocketPair.create();
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SSL_SESSION_CACHE_TIMEOUT,
s.c.clientContext.getClientSessionContext().getSessionTimeout());
assertEquals(TestSSLContext.EXPECTED_DEFAULT_SSL_SESSION_CACHE_TIMEOUT,
s.c.serverContext.getServerSessionContext().getSessionTimeout());
+ s.close();
}
public void test_SSLSessionContext_setSessionTimeout() throws Exception {
@@ -259,6 +280,7 @@ public class SSLSessionContextTest extends TestCase {
fail();
} catch (IllegalArgumentException expected) {
}
+ c.close();
TestSSLSocketPair s = TestSSLSocketPair.create();
assertSSLSessionContextSize(1, s.c);
@@ -266,5 +288,6 @@ public class SSLSessionContextTest extends TestCase {
s.c.clientContext.getClientSessionContext().setSessionTimeout(1);
s.c.serverContext.getServerSessionContext().setSessionTimeout(1);
assertSSLSessionContextSize(0, s.c);
+ s.close();
}
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
index d54520c..217dfe9 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSessionTest.java
@@ -30,6 +30,7 @@ public class SSLSessionTest extends TestCase {
assertFalse(s.invalid.isValid());
assertTrue(s.server.isValid());
assertTrue(s.client.isValid());
+ s.close();
}
public void test_SSLSession_getApplicationBufferSize() {
@@ -37,6 +38,7 @@ public class SSLSessionTest extends TestCase {
assertTrue(s.invalid.getApplicationBufferSize() > 0);
assertTrue(s.server.getApplicationBufferSize() > 0);
assertTrue(s.client.getApplicationBufferSize() > 0);
+ s.close();
}
public void test_SSLSession_getCipherSuite() {
@@ -48,6 +50,7 @@ public class SSLSessionTest extends TestCase {
assertEquals(s.server.getCipherSuite(),
s.client.getCipherSuite());
assertTrue(StandardNames.CIPHER_SUITES.contains(s.server.getCipherSuite()));
+ s.close();
}
public void test_SSLSession_getCreationTime() {
@@ -56,6 +59,7 @@ public class SSLSessionTest extends TestCase {
assertTrue(s.server.getCreationTime() > 0);
assertTrue(s.client.getCreationTime() > 0);
assertTrue(Math.abs(s.server.getCreationTime() - s.client.getCreationTime()) < 1 * 1000);
+ s.close();
}
public void test_SSLSession_getId() {
@@ -71,6 +75,7 @@ public class SSLSessionTest extends TestCase {
assertTrue(Arrays.equals(s.server.getId(), s.client.getId()));
}
assertEquals(32, s.client.getId().length);
+ s.close();
}
public void test_SSLSession_getLastAccessedTime() {
@@ -84,6 +89,7 @@ public class SSLSessionTest extends TestCase {
s.server.getCreationTime());
assertTrue(s.client.getLastAccessedTime() >=
s.client.getCreationTime());
+ s.close();
}
public void test_SSLSession_getLocalCertificates() throws Exception {
@@ -96,6 +102,7 @@ public class SSLSessionTest extends TestCase {
s.server.getLocalCertificates());
TestSSLContext.assertCertificateInKeyStore(s.server.getLocalCertificates()[0],
s.s.c.serverKeyStore);
+ s.close();
}
public void test_SSLSession_getLocalPrincipal() throws Exception {
@@ -106,6 +113,7 @@ public class SSLSessionTest extends TestCase {
assertNotNull(s.server.getLocalPrincipal().getName());
TestSSLContext.assertCertificateInKeyStore(s.server.getLocalPrincipal(),
s.s.c.serverKeyStore);
+ s.close();
}
public void test_SSLSession_getPacketBufferSize() {
@@ -113,6 +121,7 @@ public class SSLSessionTest extends TestCase {
assertTrue(s.invalid.getPacketBufferSize() > 0);
assertTrue(s.server.getPacketBufferSize() > 0);
assertTrue(s.client.getPacketBufferSize() > 0);
+ s.close();
}
public void test_SSLSession_getPeerCertificateChain() throws Exception {
@@ -129,6 +138,7 @@ public class SSLSessionTest extends TestCase {
fail();
} catch (SSLPeerUnverifiedException expected) {
}
+ s.close();
}
public void test_SSLSession_getPeerCertificates() throws Exception {
@@ -149,6 +159,7 @@ public class SSLSessionTest extends TestCase {
fail();
} catch (SSLPeerUnverifiedException expected) {
}
+ s.close();
}
public void test_SSLSession_getPeerHost() {
@@ -156,6 +167,7 @@ public class SSLSessionTest extends TestCase {
assertNull(s.invalid.getPeerHost());
assertNotNull(s.server.getPeerHost());
assertNotNull(s.client.getPeerHost());
+ s.close();
}
public void test_SSLSession_getPeerPort() {
@@ -163,6 +175,7 @@ public class SSLSessionTest extends TestCase {
assertEquals(-1, s.invalid.getPeerPort());
assertTrue(s.server.getPeerPort() > 0);
assertEquals(s.s.c.port, s.client.getPeerPort());
+ s.close();
}
public void test_SSLSession_getPeerPrincipal() throws Exception {
@@ -181,6 +194,7 @@ public class SSLSessionTest extends TestCase {
assertNotNull(s.client.getPeerPrincipal().getName());
TestSSLContext.assertCertificateInKeyStore(s.client.getPeerPrincipal(),
s.s.c.serverKeyStore);
+ s.close();
}
public void test_SSLSession_getProtocol() {
@@ -192,6 +206,7 @@ public class SSLSessionTest extends TestCase {
assertEquals(s.server.getProtocol(),
s.client.getProtocol());
assertTrue(StandardNames.SSL_SOCKET_PROTOCOLS.contains(s.server.getProtocol()));
+ s.close();
}
public void test_SSLSession_getSessionContext() {
@@ -205,6 +220,7 @@ public class SSLSessionTest extends TestCase {
s.client.getSessionContext());
assertNotSame(s.server.getSessionContext(),
s.client.getSessionContext());
+ s.close();
}
public void test_SSLSession_getValue() {
@@ -214,16 +230,19 @@ public class SSLSessionTest extends TestCase {
} catch (IllegalArgumentException expected) {
}
assertNull(s.invalid.getValue("BOGUS"));
+ s.close();
}
public void test_SSLSession_getValueNames() {
TestSSLSessions s = TestSSLSessions.create();
assertNotNull(s.invalid.getValueNames());
assertEquals(0, s.invalid.getValueNames().length);
+ s.close();
}
public void test_SSLSession_invalidate() {
TestSSLSessions s = TestSSLSessions.create();
+
assertFalse(s.invalid.isValid());
s.invalid.invalidate();
assertFalse(s.invalid.isValid());
@@ -238,6 +257,8 @@ public class SSLSessionTest extends TestCase {
s.client.invalidate();
assertFalse(s.client.isValid());
assertNull(s.client.getSessionContext());
+
+ s.close();
}
public void test_SSLSession_isValid() {
@@ -245,6 +266,7 @@ public class SSLSessionTest extends TestCase {
assertFalse(s.invalid.isValid());
assertTrue(s.server.isValid());
assertTrue(s.client.isValid());
+ s.close();
}
public void test_SSLSession_putValue() {
@@ -257,6 +279,7 @@ public class SSLSessionTest extends TestCase {
assertSame(value, s.invalid.getValue(key));
assertEquals(1, s.invalid.getValueNames().length);
assertEquals(key, s.invalid.getValueNames()[0]);
+ s.close();
}
public void test_SSLSession_removeValue() {
@@ -269,5 +292,6 @@ public class SSLSessionTest extends TestCase {
s.invalid.removeValue(key);
assertNull(s.invalid.getValue(key));
assertEquals(0, s.invalid.getValueNames().length);
+ s.close();
}
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketFactoryTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketFactoryTest.java
index 1165fd6..14a54fd 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketFactoryTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketFactoryTest.java
@@ -38,7 +38,7 @@ public class SSLSocketFactoryTest extends TestCase {
public void test_SSLSocketFactory_getDefaultCipherSuites() {
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
String[] cipherSuites = sf.getDefaultCipherSuites();
- StandardNames.assertValidCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
+ StandardNames.assertDefaultCipherSuites(cipherSuites);
assertNotSame(cipherSuites, sf.getDefaultCipherSuites());
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
index 621f299..79bf6e7 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
@@ -26,6 +26,8 @@ import java.security.Principal;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.net.ssl.HandshakeCompletedListener;
import javax.net.ssl.SSLContext;
@@ -52,37 +54,52 @@ public class SSLSocketTest extends TestCase {
}
public void test_SSLSocket_getSupportedCipherSuites_connect() throws Exception {
- // note the rare usage of DSA keys here in addition to RSA
- TestKeyStore testKeyStore = TestKeyStore.create(new String[] { "RSA", "DSA" },
- null,
- null,
- "rsa-dsa",
- TestKeyStore.localhost(),
- true,
- null);
+ // note the rare usage of non-RSA keys
+ TestKeyStore testKeyStore
+ = TestKeyStore.create(new String[] { "RSA", "DSA", "EC", "EC_RSA" },
+ null,
+ null,
+ "rsa-dsa-ec",
+ TestKeyStore.localhost(),
+ 0,
+ true,
+ null,
+ null);
if (StandardNames.IS_RI) {
test_SSLSocket_getSupportedCipherSuites_connect(testKeyStore,
StandardNames.JSSE_PROVIDER_NAME,
- StandardNames.JSSE_PROVIDER_NAME);
+ StandardNames.JSSE_PROVIDER_NAME,
+ true,
+ true);
} else {
test_SSLSocket_getSupportedCipherSuites_connect(testKeyStore,
"HarmonyJSSE",
- "HarmonyJSSE");
+ "HarmonyJSSE",
+ false,
+ false);
test_SSLSocket_getSupportedCipherSuites_connect(testKeyStore,
"AndroidOpenSSL",
- "AndroidOpenSSL");
+ "AndroidOpenSSL",
+ true,
+ true);
test_SSLSocket_getSupportedCipherSuites_connect(testKeyStore,
"HarmonyJSSE",
- "AndroidOpenSSL");
+ "AndroidOpenSSL",
+ false,
+ true);
test_SSLSocket_getSupportedCipherSuites_connect(testKeyStore,
"AndroidOpenSSL",
- "HarmonyJSSE");
+ "HarmonyJSSE",
+ true,
+ false);
}
}
private void test_SSLSocket_getSupportedCipherSuites_connect(TestKeyStore testKeyStore,
String clientProvider,
- String serverProvider)
+ String serverProvider,
+ boolean clientSecureRenegotiation,
+ boolean serverSecureRenegotiation)
throws Exception {
String clientToServerString = "this is sent from the client to the server...";
@@ -92,37 +109,75 @@ public class SSLSocketTest extends TestCase {
TestSSLContext c = TestSSLContext.create(testKeyStore, testKeyStore,
clientProvider, serverProvider);
- String[] cipherSuites = c.clientContext.getSocketFactory().getSupportedCipherSuites();
+ String[] cipherSuites;
+ if (clientProvider.equals(serverProvider)) {
+ cipherSuites = c.clientContext.getSocketFactory().getSupportedCipherSuites();
+ } else {
+ String[] clientSuites = c.clientContext.getSocketFactory().getSupportedCipherSuites();
+ String[] serverSuites = c.serverContext.getSocketFactory().getSupportedCipherSuites();
+ Set<String> ccs = new HashSet<String>(Arrays.asList(clientSuites));
+ Set<String> scs = new HashSet<String>(Arrays.asList(serverSuites));
+ Set<String> cs = new HashSet<String>(ccs);
+ cs.retainAll(scs);
+ cipherSuites = cs.toArray(new String[cs.size()]);
+ }
+
for (String cipherSuite : cipherSuites) {
- /*
- * Kerberos cipher suites require external setup. See "Kerberos Requirements" in
- * https://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#KRBRequire
- */
- if (cipherSuite.startsWith("TLS_KRB5_")) {
- continue;
+ try {
+ /*
+ * TLS_EMPTY_RENEGOTIATION_INFO_SCSV cannot be used on
+ * its own, but instead in conjunction with other
+ * cipher suites.
+ */
+ if (cipherSuite.equals(StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION)) {
+ continue;
+ }
+ /*
+ * Kerberos cipher suites require external setup. See "Kerberos Requirements" in
+ * https://java.sun.com/j2se/1.5.0/docs/guide/security/jsse/JSSERefGuide.html
+ * #KRBRequire
+ */
+ if (cipherSuite.startsWith("TLS_KRB5_")) {
+ continue;
+ }
+
+ String[] clientCipherSuiteArray
+ = (clientSecureRenegotiation
+ ? new String[] { cipherSuite,
+ StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION }
+ : new String[] { cipherSuite });
+ String[] serverCipherSuiteArray
+ = (serverSecureRenegotiation
+ ? new String[] { cipherSuite,
+ StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION }
+ : new String[] { cipherSuite });
+ SSLSocket[] pair = TestSSLSocketPair.connect(c,
+ clientCipherSuiteArray,
+ serverCipherSuiteArray);
+
+ SSLSocket server = pair[0];
+ SSLSocket client = pair[1];
+ server.getOutputStream().write(serverToClient);
+ client.getOutputStream().write(clientToServer);
+ // arrays are too big to make sure we get back only what we expect
+ byte[] clientFromServer = new byte[serverToClient.length+1];
+ byte[] serverFromClient = new byte[clientToServer.length+1];
+ int readFromServer = client.getInputStream().read(clientFromServer);
+ int readFromClient = server.getInputStream().read(serverFromClient);
+ assertEquals(serverToClient.length, readFromServer);
+ assertEquals(clientToServer.length, readFromClient);
+ assertEquals(clientToServerString, new String(serverFromClient, 0, readFromClient));
+ assertEquals(serverToClientString, new String(clientFromServer, 0, readFromServer));
+ client.close();
+ server.close();
+ } catch (Exception e) {
+ throw new Exception("Problem trying to connect cipher suite " + cipherSuite
+ + " client=" + clientProvider
+ + " server=" + serverProvider,
+ e);
}
- // System.out.println("Trying to connect cipher suite " + cipherSuite
- // + " client=" + clientProvider
- // + " server=" + serverProvider);
- String[] cipherSuiteArray = new String[] { cipherSuite };
- SSLSocket[] pair = TestSSLSocketPair.connect(c, cipherSuiteArray, cipherSuiteArray);
-
- SSLSocket server = pair[0];
- SSLSocket client = pair[1];
- server.getOutputStream().write(serverToClient);
- client.getOutputStream().write(clientToServer);
- // arrays are too big to make sure we get back only what we expect
- byte[] clientFromServer = new byte[serverToClient.length+1];
- byte[] serverFromClient = new byte[clientToServer.length+1];
- int readFromServer = client.getInputStream().read(clientFromServer);
- int readFromClient = server.getInputStream().read(serverFromClient);
- assertEquals(serverToClient.length, readFromServer);
- assertEquals(clientToServer.length, readFromClient);
- assertEquals(clientToServerString, new String(serverFromClient, 0, readFromClient));
- assertEquals(serverToClientString, new String(clientFromServer, 0, readFromServer));
- server.close();
- client.close();
}
+ c.close();
}
public void test_SSLSocket_getEnabledCipherSuites() throws Exception {
@@ -248,6 +303,9 @@ public class SSLSocketTest extends TestCase {
peerCertificates);
TestSSLContext.assertCertificateInKeyStore(peerCertificates[0], c.serverKeyStore);
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_startHandshake_noKeyStore() throws Exception {
@@ -256,10 +314,12 @@ public class SSLSocketTest extends TestCase {
SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host,
c.port);
try {
- SSLSocket server = (SSLSocket) c.serverSocket.accept();
+ c.serverSocket.accept();
fail();
} catch (SSLException expected) {
}
+ client.close();
+ c.close();
}
public void test_SSLSocket_startHandshake_noClientCertificate() throws Exception {
@@ -283,6 +343,9 @@ public class SSLSocketTest extends TestCase {
thread.start();
client.startHandshake();
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_HandshakeCompletedListener() throws Exception {
@@ -386,6 +449,9 @@ public class SSLSocketTest extends TestCase {
handshakeCompletedListenerCalled.wait();
}
}
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_HandshakeCompletedListener_RuntimeException() throws Exception {
@@ -412,6 +478,9 @@ public class SSLSocketTest extends TestCase {
});
client.startHandshake();
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_getUseClientMode() throws Exception {
@@ -421,6 +490,9 @@ public class SSLSocketTest extends TestCase {
SSLSocket server = (SSLSocket) c.serverSocket.accept();
assertTrue(client.getUseClientMode());
assertFalse(server.getUseClientMode());
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_setUseClientMode() throws Exception {
@@ -501,6 +573,9 @@ public class SSLSocketTest extends TestCase {
if (socketTimeoutException[0] != null) {
throw socketTimeoutException[0];
}
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_untrustedServer() throws Exception {
@@ -527,6 +602,8 @@ public class SSLSocketTest extends TestCase {
} catch (SSLHandshakeException expected) {
assertTrue(expected.getCause() instanceof CertificateException);
}
+ client.close();
+ server.close();
thread.join();
}
@@ -573,6 +650,9 @@ public class SSLSocketTest extends TestCase {
TestSSLContext.assertClientCertificateChain(c.clientTrustManager,
client.getSession().getLocalCertificates());
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_getEnableSessionCreation() throws Exception {
@@ -582,6 +662,9 @@ public class SSLSocketTest extends TestCase {
SSLSocket server = (SSLSocket) c.serverSocket.accept();
assertTrue(client.getEnableSessionCreation());
assertTrue(server.getEnableSessionCreation());
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_setEnableSessionCreation_server() throws Exception {
@@ -612,6 +695,9 @@ public class SSLSocketTest extends TestCase {
} catch (SSLException expected) {
}
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_setEnableSessionCreation_client() throws Exception {
@@ -642,6 +728,9 @@ public class SSLSocketTest extends TestCase {
} catch (SSLException expected) {
}
thread.join();
+ client.close();
+ server.close();
+ c.close();
}
public void test_SSLSocket_getSSLParameters() throws Exception {
@@ -799,6 +888,52 @@ public class SSLSocketTest extends TestCase {
fail();
} catch (IllegalArgumentException expected) {
}
+
+ pair.close();
+ }
+
+ /**
+ * b/3350645 Test to confirm that an SSLSocket.close() performing
+ * an SSL_shutdown does not throw an IOException if the peer
+ * socket has been closed.
+ */
+ public void test_SSLSocket_shutdownCloseOnClosedPeer() throws Exception {
+ TestSSLContext c = TestSSLContext.create();
+ final Socket underlying = new Socket(c.host, c.port);
+ final SSLSocket wrapping = (SSLSocket)
+ c.clientContext.getSocketFactory().createSocket(underlying,
+ c.host.getHostName(),
+ c.port,
+ false);
+ Thread clientThread = new Thread(new Runnable () {
+ public void run() {
+ try {
+ try {
+ wrapping.startHandshake();
+ wrapping.getOutputStream().write(42);
+ // close the underlying socket,
+ // so that no SSL shutdown is sent
+ underlying.close();
+ wrapping.close();
+ } catch (SSLException expected) {
+ }
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ clientThread.start();
+
+ SSLSocket server = (SSLSocket) c.serverSocket.accept();
+ server.startHandshake();
+ server.getInputStream().read();
+ // wait for thread to finish so we know client is closed.
+ clientThread.join();
+ // close should cause an SSL_shutdown which will fail
+ // because the peer has closed, but it shouldn't throw.
+ server.close();
}
/**
@@ -867,6 +1002,10 @@ public class SSLSocketTest extends TestCase {
}
public void test_SSLSocket_setSoTimeout_wrapper() throws Exception {
+ if (StandardNames.IS_RI) {
+ // RI cannot handle this case
+ return;
+ }
ServerSocket listening = new ServerSocket(0);
// setSoTimeout applies to read, not connect, so connect first
@@ -958,6 +1097,7 @@ public class SSLSocketTest extends TestCase {
assertNotNull(test.client.getSession());
assertTrue(test.server.getSession().isValid());
assertTrue(test.client.getSession().isValid());
+ test.close();
}
/**
@@ -974,6 +1114,14 @@ public class SSLSocketTest extends TestCase {
} else {
System.out.print("X");
}
+
+ /*
+ We don't close on purpose in this stress test to add
+ races in file descriptors reuse when the garbage
+ collector runs concurrently and finalizes sockets
+ */
+ // test.close();
+
}
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/TrustManagerFactoryTest.java b/luni/src/test/java/libcore/javax/net/ssl/TrustManagerFactoryTest.java
new file mode 100644
index 0000000..e92bf67
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/net/ssl/TrustManagerFactoryTest.java
@@ -0,0 +1,257 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.net.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore.PrivateKeyEntry;
+import java.security.KeyStore;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.PKIXBuilderParameters;
+import java.security.cert.PKIXParameters;
+import java.security.cert.X509CertSelector;
+import java.security.cert.X509Certificate;
+import java.util.Set;
+import javax.net.ssl.CertPathTrustManagerParameters;
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+import junit.framework.TestCase;
+import libcore.java.security.StandardNames;
+import libcore.java.security.TestKeyStore;
+
+public class TrustManagerFactoryTest extends TestCase {
+
+ private static final String [] KEY_TYPES = new String[] { "RSA", "DSA", "EC", "EC_RSA" };
+ // note the rare usage of DSA keys here in addition to RSA
+ private static final TestKeyStore TEST_KEY_STORE
+ = TestKeyStore.create(KEY_TYPES,
+ null,
+ null,
+ "rsa-dsa-ec",
+ TestKeyStore.localhost(),
+ 0,
+ true,
+ null,
+ null);
+
+ public void test_TrustManagerFactory_getDefaultAlgorithm() throws Exception {
+ String algorithm = TrustManagerFactory.getDefaultAlgorithm();
+ assertEquals(StandardNames.TRUST_MANAGER_FACTORY_DEFAULT, algorithm);
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
+ test_TrustManagerFactory(tmf, StandardNames.IS_RI);
+ }
+
+ private static class UseslessManagerFactoryParameters implements ManagerFactoryParameters {}
+
+ private void test_TrustManagerFactory(TrustManagerFactory tmf,
+ boolean supportsManagerFactoryParameters)
+ throws Exception {
+ assertNotNull(tmf);
+ assertNotNull(tmf.getAlgorithm());
+ assertNotNull(tmf.getProvider());
+
+ // before init
+ try {
+ tmf.getTrustManagers();
+ fail();
+ } catch (IllegalStateException expected) {
+ }
+
+ // init with null ManagerFactoryParameters
+ try {
+ tmf.init((ManagerFactoryParameters) null);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+
+ // init with useless ManagerFactoryParameters
+ try {
+ tmf.init(new UseslessManagerFactoryParameters());
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+
+ // init with PKIXParameters ManagerFactoryParameters
+ try {
+ PKIXParameters pp = new PKIXParameters(TEST_KEY_STORE.keyStore);
+ CertPathTrustManagerParameters cptmp = new CertPathTrustManagerParameters(pp);
+ tmf.init(cptmp);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+
+ // init with PKIXBuilderParameters ManagerFactoryParameters
+ X509CertSelector xcs = new X509CertSelector();
+ PKIXBuilderParameters pbp = new PKIXBuilderParameters(TEST_KEY_STORE.keyStore, xcs);
+ CertPathTrustManagerParameters cptmp = new CertPathTrustManagerParameters(pbp);
+ if (supportsManagerFactoryParameters) {
+ tmf.init(cptmp);
+ test_TrustManagerFactory_getTrustManagers(tmf);
+ } else {
+ try {
+ tmf.init(cptmp);
+ fail();
+ } catch (InvalidAlgorithmParameterException expected) {
+ }
+ }
+
+ // init with null for default KeyStore
+ tmf.init((KeyStore) null);
+ test_TrustManagerFactory_getTrustManagers(tmf);
+
+ // init with specific key store
+ tmf.init(TEST_KEY_STORE.keyStore);
+ test_TrustManagerFactory_getTrustManagers(tmf);
+ }
+
+ private void test_TrustManagerFactory_getTrustManagers(TrustManagerFactory tmf)
+ throws Exception {
+ TrustManager[] trustManagers = tmf.getTrustManagers();
+ assertNotNull(trustManagers);
+ assertTrue(trustManagers.length > 0);
+ for (TrustManager trustManager : trustManagers) {
+ assertNotNull(trustManager);
+ if (trustManager instanceof X509TrustManager) {
+ test_X509TrustManager((X509TrustManager) trustManager);
+ }
+ }
+ }
+
+ private void test_X509TrustManager(X509TrustManager tm) throws Exception {
+ for (String keyType : KEY_TYPES) {
+ X509Certificate[] issuers = tm.getAcceptedIssuers();
+ assertNotNull(issuers);
+ assertTrue(issuers.length > 1);
+ assertNotSame(issuers, tm.getAcceptedIssuers());
+ boolean defaultTrustmanager
+ // RI de-duplicates certs from TrustedCertificateEntry and PrivateKeyEntry
+ = issuers.length > (StandardNames.IS_RI ? 1 : 2) * KEY_TYPES.length;
+
+ String keyAlgName = TestKeyStore.keyAlgorithm(keyType);
+ String sigAlgName = TestKeyStore.signatureAlgorithm(keyType);
+ PrivateKeyEntry pke = TEST_KEY_STORE.getPrivateKey(keyAlgName, sigAlgName);
+ X509Certificate[] chain = (X509Certificate[]) pke.getCertificateChain();
+ if (defaultTrustmanager) {
+ try {
+ tm.checkClientTrusted(chain, keyType);
+ fail();
+ } catch (CertificateException expected) {
+ }
+ try {
+ tm.checkServerTrusted(chain, keyType);
+ fail();
+ } catch (CertificateException expected) {
+ }
+ } else {
+ tm.checkClientTrusted(chain, keyType);
+ tm.checkServerTrusted(chain, keyType);
+ }
+
+ }
+ }
+
+ public void test_TrustManagerFactory_getInstance() throws Exception {
+ Provider[] providers = Security.getProviders();
+ for (Provider provider : providers) {
+ Set<Provider.Service> services = provider.getServices();
+ for (Provider.Service service : services) {
+ String type = service.getType();
+ if (!type.equals("TrustManagerFactory")) {
+ continue;
+ }
+ String algorithm = service.getAlgorithm();
+ boolean supportsManagerFactoryParameters = algorithm.equals("PKIX");
+ {
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
+ assertEquals(algorithm, tmf.getAlgorithm());
+ test_TrustManagerFactory(tmf, supportsManagerFactoryParameters);
+ }
+
+ {
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm,
+ provider);
+ assertEquals(algorithm, tmf.getAlgorithm());
+ assertEquals(provider, tmf.getProvider());
+ test_TrustManagerFactory(tmf, supportsManagerFactoryParameters);
+ }
+
+ {
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm,
+ provider.getName());
+ assertEquals(algorithm, tmf.getAlgorithm());
+ assertEquals(provider, tmf.getProvider());
+ test_TrustManagerFactory(tmf, supportsManagerFactoryParameters);
+ }
+ }
+ }
+ }
+
+ public void test_TrustManagerFactory_intermediate() throws Exception {
+ // chain should be server/intermediate/root
+ PrivateKeyEntry pke = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
+ X509Certificate[] chain = (X509Certificate[])pke.getCertificateChain();
+ assertEquals(3, chain.length);
+
+ // keyStore should contain only the intermediate CA so we can
+ // test proper validation even if there are extra certs after
+ // the trusted one (in this case the original root is "extra")
+ KeyStore keyStore = TestKeyStore.createKeyStore();
+ keyStore.setCertificateEntry("alias", chain[1]);
+
+ Provider[] providers = Security.getProviders();
+ for (Provider provider : providers) {
+ Set<Provider.Service> services = provider.getServices();
+ for (Provider.Service service : services) {
+ String type = service.getType();
+ if (!type.equals("TrustManagerFactory")) {
+ continue;
+ }
+ String algorithm = service.getAlgorithm();
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
+ tmf.init(keyStore);
+ TrustManager[] trustManagers = tmf.getTrustManagers();
+ for (TrustManager trustManager : trustManagers) {
+ if (!(trustManager instanceof X509TrustManager)) {
+ continue;
+ }
+ X509TrustManager tm = (X509TrustManager) trustManager;
+ tm.checkClientTrusted(chain, "RSA");
+ tm.checkServerTrusted(chain, "RSA");
+ }
+ }
+ }
+ }
+
+ public void test_TrustManagerFactory_keyOnly() throws Exception {
+ // create a KeyStore containing only a private key with chain.
+ // unlike PKIXParameters(KeyStore), the cert chain of the key should be trusted.
+ KeyStore ks = TestKeyStore.createKeyStore();
+ KeyStore.PrivateKeyEntry pke = TEST_KEY_STORE.getPrivateKey("RSA", "RSA");
+ ks.setKeyEntry("key", pke.getPrivateKey(), "pw".toCharArray(), pke.getCertificateChain());
+
+ String algorithm = TrustManagerFactory.getDefaultAlgorithm();
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm);
+ tmf.init(ks);
+ X509TrustManager trustManager = (X509TrustManager) tmf.getTrustManagers()[0];
+ trustManager.checkServerTrusted((X509Certificate[]) pke.getCertificateChain(), "RSA");
+ }
+
+}
diff --git a/luni/src/test/java/libcore/javax/sql/OldConnectionEventTest.java b/luni/src/test/java/libcore/javax/sql/OldConnectionEventTest.java
new file mode 100644
index 0000000..e5408d1
--- /dev/null
+++ b/luni/src/test/java/libcore/javax/sql/OldConnectionEventTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.javax.sql;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import javax.sql.ConnectionEvent;
+import javax.sql.ConnectionEventListener;
+import javax.sql.PooledConnection;
+import javax.sql.StatementEventListener;
+import junit.framework.TestCase;
+
+public class OldConnectionEventTest extends TestCase {
+
+ public void testConstructorConnection() {
+ Impl_PooledConnection ipc = new Impl_PooledConnection();
+ ConnectionEvent ce = new ConnectionEvent(ipc);
+ ConnectionEvent ce2 = new ConnectionEvent(ipc,null);
+ assertSame(ce2.getSource(),ce.getSource());
+ }
+
+ public void testGetSQLException() {
+ Impl_PooledConnection ipc = new Impl_PooledConnection();
+ ConnectionEvent ce = new ConnectionEvent(ipc);
+
+ ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
+ assertNull(ce.getSQLException());
+ assertEquals(ce2.getSQLException(), ce.getSQLException());
+
+ SQLException e = new SQLException();
+ ConnectionEvent ce3 = new ConnectionEvent(ipc, e);
+ assertNotNull(ce3.getSQLException());
+ assertNotSame(ce3.getSQLException(), ce2.getSQLException());
+ }
+
+ static class Impl_PooledConnection implements PooledConnection {
+ public void addConnectionEventListener(ConnectionEventListener theListener) {}
+ public void close() throws SQLException {}
+ public Connection getConnection() throws SQLException {
+ return null;
+ }
+ public void removeConnectionEventListener(ConnectionEventListener listener) {}
+ public void addStatementEventListener(StatementEventListener listener) {}
+ public void removeStatementEventListener(StatementEventListener listener) {}
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/ExpatPullParserDtdTest.java b/luni/src/test/java/libcore/xml/ExpatPullParserDtdTest.java
new file mode 100644
index 0000000..5e62310
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/ExpatPullParserDtdTest.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import org.apache.harmony.xml.ExpatPullParser;
+import org.xmlpull.v1.XmlPullParser;
+
+public class ExpatPullParserDtdTest extends PullParserDtdTest {
+ @Override XmlPullParser newPullParser() {
+ return new ExpatPullParser();
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/ExpatPullParserTest.java b/luni/src/test/java/libcore/xml/ExpatPullParserTest.java
new file mode 100644
index 0000000..5d1725d
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/ExpatPullParserTest.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import org.apache.harmony.xml.ExpatPullParser;
+import org.xmlpull.v1.XmlPullParser;
+
+public final class ExpatPullParserTest extends PullParserTest {
+
+ @Override XmlPullParser newPullParser() {
+ return new ExpatPullParser();
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/ExpatSaxParserTest.java b/luni/src/test/java/libcore/xml/ExpatSaxParserTest.java
new file mode 100644
index 0000000..2db8e82
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/ExpatSaxParserTest.java
@@ -0,0 +1,741 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.harmony.xml.ExpatReader;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.ext.DefaultHandler2;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class ExpatSaxParserTest extends TestCase {
+
+ private static final String SNIPPET = "<dagny dad=\"bob\">hello</dagny>";
+
+ public void testGlobalReferenceTableOverflow() throws Exception {
+ // We used to use a JNI global reference per interned string.
+ // Framework apps have a limit of 2000 JNI global references per VM.
+ StringBuilder xml = new StringBuilder();
+ xml.append("<root>");
+ for (int i = 0; i < 4000; ++i) {
+ xml.append("<tag" + i + ">");
+ xml.append("</tag" + i + ">");
+ }
+ xml.append("</root>");
+ parse(xml.toString(), new DefaultHandler());
+ }
+
+ public void testExceptions() {
+ // From startElement().
+ ContentHandler contentHandler = new DefaultHandler() {
+ @Override
+ public void startElement(String uri, String localName,
+ String qName, Attributes attributes)
+ throws SAXException {
+ throw new SAXException();
+ }
+ };
+ try {
+ parse(SNIPPET, contentHandler);
+ fail();
+ } catch (SAXException checked) { /* expected */ }
+
+ // From endElement().
+ contentHandler = new DefaultHandler() {
+ @Override
+ public void endElement(String uri, String localName,
+ String qName)
+ throws SAXException {
+ throw new SAXException();
+ }
+ };
+ try {
+ parse(SNIPPET, contentHandler);
+ fail();
+ } catch (SAXException checked) { /* expected */ }
+
+ // From characters().
+ contentHandler = new DefaultHandler() {
+ @Override
+ public void characters(char ch[], int start, int length)
+ throws SAXException {
+ throw new SAXException();
+ }
+ };
+ try {
+ parse(SNIPPET, contentHandler);
+ fail();
+ } catch (SAXException checked) { /* expected */ }
+ }
+
+ public void testSax() {
+ try {
+ // Parse String.
+ TestHandler handler = new TestHandler();
+ parse(SNIPPET, handler);
+ validate(handler);
+
+ // Parse Reader.
+ handler = new TestHandler();
+ parse(new StringReader(SNIPPET), handler);
+ validate(handler);
+
+ // Parse InputStream.
+ handler = new TestHandler();
+ parse(new ByteArrayInputStream(SNIPPET.getBytes()),
+ Encoding.UTF_8, handler);
+ validate(handler);
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static void validate(TestHandler handler) {
+ assertEquals("dagny", handler.startElementName);
+ assertEquals("dagny", handler.endElementName);
+ assertEquals("hello", handler.text.toString());
+ }
+
+ static class TestHandler extends DefaultHandler {
+
+ String startElementName;
+ String endElementName;
+ StringBuilder text = new StringBuilder();
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+
+ assertNull(this.startElementName);
+ this.startElementName = localName;
+
+ // Validate attributes.
+ assertEquals(1, attributes.getLength());
+ assertEquals("", attributes.getURI(0));
+ assertEquals("dad", attributes.getLocalName(0));
+ assertEquals("bob", attributes.getValue(0));
+ assertEquals(0, attributes.getIndex("", "dad"));
+ assertEquals("bob", attributes.getValue("", "dad"));
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ assertNull(this.endElementName);
+ this.endElementName = localName;
+ }
+
+ @Override
+ public void characters(char ch[], int start, int length)
+ throws SAXException {
+ this.text.append(ch, start, length);
+ }
+ }
+
+ static final String XML =
+ "<one xmlns='ns:default' xmlns:n1='ns:1' a='b'>\n"
+ + " <n1:two c='d' n1:e='f' xmlns:n2='ns:2'>text</n1:two>\n"
+ + "</one>";
+
+ public void testNamespaces() {
+ try {
+ NamespaceHandler handler = new NamespaceHandler();
+ parse(XML, handler);
+ handler.validate();
+ } catch (SAXException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ static class NamespaceHandler implements ContentHandler {
+
+ Locator locator;
+ boolean documentStarted;
+ boolean documentEnded;
+ Map<String, String> prefixMappings = new HashMap<String, String>();
+
+ boolean oneStarted;
+ boolean twoStarted;
+ boolean oneEnded;
+ boolean twoEnded;
+
+ public void validate() {
+ assertTrue(documentEnded);
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ this.locator = locator;
+ }
+
+ public void startDocument() throws SAXException {
+ documentStarted = true;
+ assertNotNull(locator);
+ assertEquals(0, prefixMappings.size());
+ assertFalse(documentEnded);
+ }
+
+ public void endDocument() throws SAXException {
+ assertTrue(documentStarted);
+ assertTrue(oneEnded);
+ assertTrue(twoEnded);
+ assertEquals(0, prefixMappings.size());
+ documentEnded = true;
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ prefixMappings.put(prefix, uri);
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ assertNotNull(prefixMappings.remove(prefix));
+ }
+
+ public void startElement(String uri, String localName, String qName,
+ Attributes atts) throws SAXException {
+
+ if (localName == "one") {
+ assertEquals(2, prefixMappings.size());
+
+ assertEquals(1, locator.getLineNumber());
+
+ assertFalse(oneStarted);
+ assertFalse(twoStarted);
+ assertFalse(oneEnded);
+ assertFalse(twoEnded);
+
+ oneStarted = true;
+
+ assertSame("ns:default", uri);
+ assertEquals("one", qName);
+
+ // Check atts.
+ assertEquals(1, atts.getLength());
+
+ assertSame("", atts.getURI(0));
+ assertSame("a", atts.getLocalName(0));
+ assertEquals("b", atts.getValue(0));
+ assertEquals(0, atts.getIndex("", "a"));
+ assertEquals("b", atts.getValue("", "a"));
+
+ return;
+ }
+
+ if (localName == "two") {
+ assertEquals(3, prefixMappings.size());
+
+ assertTrue(oneStarted);
+ assertFalse(twoStarted);
+ assertFalse(oneEnded);
+ assertFalse(twoEnded);
+
+ twoStarted = true;
+
+ assertSame("ns:1", uri);
+ Assert.assertEquals("n1:two", qName);
+
+ // Check atts.
+ assertEquals(2, atts.getLength());
+
+ assertSame("", atts.getURI(0));
+ assertSame("c", atts.getLocalName(0));
+ assertEquals("d", atts.getValue(0));
+ assertEquals(0, atts.getIndex("", "c"));
+ assertEquals("d", atts.getValue("", "c"));
+
+ assertSame("ns:1", atts.getURI(1));
+ assertSame("e", atts.getLocalName(1));
+ assertEquals("f", atts.getValue(1));
+ assertEquals(1, atts.getIndex("ns:1", "e"));
+ assertEquals("f", atts.getValue("ns:1", "e"));
+
+ // We shouldn't find these.
+ assertEquals(-1, atts.getIndex("ns:default", "e"));
+ assertEquals(null, atts.getValue("ns:default", "e"));
+
+ return;
+ }
+
+ fail();
+ }
+
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ if (localName == "one") {
+ assertEquals(3, locator.getLineNumber());
+
+ assertTrue(oneStarted);
+ assertTrue(twoStarted);
+ assertTrue(twoEnded);
+ assertFalse(oneEnded);
+
+ oneEnded = true;
+
+ assertSame("ns:default", uri);
+ assertEquals("one", qName);
+
+ return;
+ }
+
+ if (localName == "two") {
+ assertTrue(oneStarted);
+ assertTrue(twoStarted);
+ assertFalse(twoEnded);
+ assertFalse(oneEnded);
+
+ twoEnded = true;
+
+ assertSame("ns:1", uri);
+ assertEquals("n1:two", qName);
+
+ return;
+ }
+
+ fail();
+ }
+
+ public void characters(char ch[], int start, int length)
+ throws SAXException {
+ String s = new String(ch, start, length).trim();
+
+ if (!s.equals("")) {
+ assertTrue(oneStarted);
+ assertTrue(twoStarted);
+ assertFalse(oneEnded);
+ assertFalse(twoEnded);
+ assertEquals("text", s);
+ }
+ }
+
+ public void ignorableWhitespace(char ch[], int start, int length)
+ throws SAXException {
+ fail();
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ fail();
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ fail();
+ }
+ }
+
+ private TestDtdHandler runDtdTest(String s) throws Exception {
+ Reader in = new StringReader(s);
+ ExpatReader reader = new ExpatReader();
+ TestDtdHandler handler = new TestDtdHandler();
+ reader.setContentHandler(handler);
+ reader.setDTDHandler(handler);
+ reader.setLexicalHandler(handler);
+ reader.parse(new InputSource(in));
+ return handler;
+ }
+
+ public void testDtdDoctype() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee'><a></a>");
+ assertEquals("foo", handler.name);
+ assertEquals("bar", handler.publicId);
+ assertEquals("tee", handler.systemId);
+ assertTrue(handler.ended);
+ }
+
+ public void testDtdUnparsedEntity_system() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent SYSTEM 'blah' NDATA poop> ]><a></a>");
+ assertEquals("ent", handler.ueName);
+ assertEquals(null, handler.uePublicId);
+ assertEquals("blah", handler.ueSystemId);
+ assertEquals("poop", handler.ueNotationName);
+ }
+
+ public void testDtdUnparsedEntity_public() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent PUBLIC 'a' 'b' NDATA poop> ]><a></a>");
+ assertEquals("ent", handler.ueName);
+ assertEquals("a", handler.uePublicId);
+ assertEquals("b", handler.ueSystemId);
+ assertEquals("poop", handler.ueNotationName);
+ }
+
+ public void testDtdNotation_system() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION sn SYSTEM 'nf2'> ]><a></a>");
+ assertEquals("sn", handler.ndName);
+ assertEquals(null, handler.ndPublicId);
+ assertEquals("nf2", handler.ndSystemId);
+ }
+
+ public void testDtdNotation_public() throws Exception {
+ TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION pn PUBLIC 'nf1'> ]><a></a>");
+ assertEquals("pn", handler.ndName);
+ assertEquals("nf1", handler.ndPublicId);
+ assertEquals(null, handler.ndSystemId);
+ }
+
+ static class TestDtdHandler extends DefaultHandler2 {
+
+ String name;
+ String publicId;
+ String systemId;
+ String ndName;
+ String ndPublicId;
+ String ndSystemId;
+ String ueName;
+ String uePublicId;
+ String ueSystemId;
+ String ueNotationName;
+
+ boolean ended;
+
+ Locator locator;
+
+ @Override
+ public void startDTD(String name, String publicId, String systemId) {
+ this.name = name;
+ this.publicId = publicId;
+ this.systemId = systemId;
+ }
+
+ @Override
+ public void endDTD() {
+ ended = true;
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator) {
+ this.locator = locator;
+ }
+
+ @Override
+ public void notationDecl(String name, String publicId, String systemId) {
+ this.ndName = name;
+ this.ndPublicId = publicId;
+ this.ndSystemId = systemId;
+ }
+
+ @Override
+ public void unparsedEntityDecl(String entityName, String publicId, String systemId, String notationName) {
+ this.ueName = entityName;
+ this.uePublicId = publicId;
+ this.ueSystemId = systemId;
+ this.ueNotationName = notationName;
+ }
+ }
+
+ public void testCdata() throws Exception {
+ Reader in = new StringReader(
+ "<a><![CDATA[<b></b>]]> <![CDATA[<c></c>]]></a>");
+
+ ExpatReader reader = new ExpatReader();
+ TestCdataHandler handler = new TestCdataHandler();
+ reader.setContentHandler(handler);
+ reader.setLexicalHandler(handler);
+
+ reader.parse(new InputSource(in));
+
+ assertEquals(2, handler.startCdata);
+ assertEquals(2, handler.endCdata);
+ assertEquals("<b></b> <c></c>", handler.buffer.toString());
+ }
+
+ static class TestCdataHandler extends DefaultHandler2 {
+
+ int startCdata, endCdata;
+ StringBuffer buffer = new StringBuffer();
+
+ @Override
+ public void characters(char ch[], int start, int length) {
+ buffer.append(ch, start, length);
+ }
+
+ @Override
+ public void startCDATA() throws SAXException {
+ startCdata++;
+ }
+
+ @Override
+ public void endCDATA() throws SAXException {
+ endCdata++;
+ }
+ }
+
+ public void testProcessingInstructions() throws IOException, SAXException {
+ Reader in = new StringReader(
+ "<?bob lee?><a></a>");
+
+ ExpatReader reader = new ExpatReader();
+ TestProcessingInstrutionHandler handler
+ = new TestProcessingInstrutionHandler();
+ reader.setContentHandler(handler);
+
+ reader.parse(new InputSource(in));
+
+ assertEquals("bob", handler.target);
+ assertEquals("lee", handler.data);
+ }
+
+ static class TestProcessingInstrutionHandler extends DefaultHandler2 {
+
+ String target;
+ String data;
+
+ @Override
+ public void processingInstruction(String target, String data) {
+ this.target = target;
+ this.data = data;
+ }
+ }
+
+ public void testExternalEntity() throws IOException, SAXException {
+ class Handler extends DefaultHandler {
+
+ List<String> elementNames = new ArrayList<String>();
+ StringBuilder text = new StringBuilder();
+
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws IOException, SAXException {
+ if (publicId.equals("publicA") && systemId.equals("systemA")) {
+ return new InputSource(new StringReader("<a/>"));
+ } else if (publicId.equals("publicB")
+ && systemId.equals("systemB")) {
+ /*
+ * Explicitly set the encoding here or else the parser will
+ * try to use the parent parser's encoding which is utf-16.
+ */
+ InputSource inputSource = new InputSource(
+ new ByteArrayInputStream("bob".getBytes("utf-8")));
+ inputSource.setEncoding("utf-8");
+ return inputSource;
+ }
+
+ throw new AssertionError();
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ elementNames.add(localName);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ elementNames.add("/" + localName);
+ }
+
+ @Override
+ public void characters(char ch[], int start, int length)
+ throws SAXException {
+ text.append(ch, start, length);
+ }
+ }
+
+ Reader in = new StringReader("<?xml version=\"1.0\"?>\n"
+ + "<!DOCTYPE foo [\n"
+ + " <!ENTITY a PUBLIC 'publicA' 'systemA'>\n"
+ + " <!ENTITY b PUBLIC 'publicB' 'systemB'>\n"
+ + "]>\n"
+ + "<foo>\n"
+ + " &a;<b>&b;</b></foo>");
+
+ ExpatReader reader = new ExpatReader();
+ Handler handler = new Handler();
+ reader.setContentHandler(handler);
+ reader.setEntityResolver(handler);
+
+ reader.parse(new InputSource(in));
+
+ assertEquals(Arrays.asList("foo", "a", "/a", "b", "/b", "/foo"),
+ handler.elementNames);
+ assertEquals("bob", handler.text.toString().trim());
+ }
+
+ public void testExternalEntityDownload() throws IOException, SAXException {
+ class Server implements Runnable {
+
+ private final ServerSocket serverSocket;
+
+ Server() throws IOException {
+ serverSocket = new ServerSocket(8080);
+ }
+
+ public void run() {
+ try {
+ Socket socket = serverSocket.accept();
+
+ final InputStream in = socket.getInputStream();
+ Thread inputThread = new Thread() {
+ public void run() {
+ try {
+ byte[] buffer = new byte[1024];
+ while (in.read(buffer) > -1) { /* ignore */ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ };
+ inputThread.setDaemon(true);
+ inputThread.start();
+
+ OutputStream out = socket.getOutputStream();
+
+ String body = "<bar></bar>";
+ String response = "HTTP/1.0 200 OK\n"
+ + "Content-Length: " + body.length() + "\n"
+ + "\n"
+ + body;
+
+ out.write(response.getBytes("UTF-8"));
+ out.close();
+ serverSocket.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ class Handler extends DefaultHandler {
+
+ List<String> elementNames = new ArrayList<String>();
+
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws IOException, SAXException {
+ // The parser should have resolved the systemId.
+ assertEquals("http://localhost:8080/systemBar", systemId);
+ return new InputSource(systemId);
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException {
+ elementNames.add(localName);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException {
+ elementNames.add("/" + localName);
+ }
+ }
+
+ // Start server to serve up the XML for 'systemBar'.
+ Thread serverThread = new Thread(new Server());
+ serverThread.setDaemon(true);
+ serverThread.start();
+
+ // 'systemBar', the external entity, is relative to 'systemFoo':
+ Reader in = new StringReader("<?xml version=\"1.0\"?>\n"
+ + "<!DOCTYPE foo [\n"
+ + " <!ENTITY bar SYSTEM 'systemBar'>\n"
+ + "]>\n"
+ + "<foo>&bar;</foo>");
+
+ ExpatReader reader = new ExpatReader();
+
+ Handler handler = new Handler();
+
+ reader.setContentHandler(handler);
+ reader.setEntityResolver(handler);
+
+ InputSource source = new InputSource(in);
+ source.setSystemId("http://localhost:8080/systemFoo");
+ reader.parse(source);
+
+ assertEquals(Arrays.asList("foo", "bar", "/bar", "/foo"),
+ handler.elementNames);
+ }
+
+ /**
+ * Parses the given xml string and fires events on the given SAX handler.
+ */
+ private static void parse(String xml, ContentHandler contentHandler)
+ throws SAXException {
+ try {
+ XMLReader reader = new ExpatReader();
+ reader.setContentHandler(contentHandler);
+ reader.parse(new InputSource(new StringReader(xml)));
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ /**
+ * Parses xml from the given reader and fires events on the given SAX
+ * handler.
+ */
+ private static void parse(Reader in, ContentHandler contentHandler)
+ throws IOException, SAXException {
+ XMLReader reader = new ExpatReader();
+ reader.setContentHandler(contentHandler);
+ reader.parse(new InputSource(in));
+ }
+
+ /**
+ * Parses xml from the given input stream and fires events on the given SAX
+ * handler.
+ */
+ private static void parse(InputStream in, Encoding encoding,
+ ContentHandler contentHandler) throws IOException, SAXException {
+ try {
+ XMLReader reader = new ExpatReader();
+ reader.setContentHandler(contentHandler);
+ InputSource source = new InputSource(in);
+ source.setEncoding(encoding.expatName);
+ reader.parse(source);
+ } catch (IOException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ /**
+ * Supported character encodings.
+ */
+ private enum Encoding {
+
+ US_ASCII("US-ASCII"),
+ UTF_8("UTF-8"),
+ UTF_16("UTF-16"),
+ ISO_8859_1("ISO-8859-1");
+
+ final String expatName;
+
+ Encoding(String expatName) {
+ this.expatName = expatName;
+ }
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/JaxenXPathTestSuite.java b/luni/src/test/java/libcore/xml/JaxenXPathTestSuite.java
new file mode 100644
index 0000000..eb790aa
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/JaxenXPathTestSuite.java
@@ -0,0 +1,306 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import javax.xml.xpath.XPathVariableResolver;
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The implementation-independent part of the <a
+ * href="http://jaxen.codehaus.org/">Jaxen</a> XPath test suite, adapted for use
+ * by JUnit. To run these tests on a device:
+ * <ul>
+ * <li>Obtain the Jaxen source from the project's website.
+ * <li>Copy the files to a device: <code>adb shell mkdir /data/jaxen ;
+ * adb push /home/dalvik-prebuild/jaxen /data/jaxen</code>
+ * <li>Invoke this class' main method, passing the on-device path to the test
+ * suite's root directory as an argument.
+ * </ul>
+ */
+public class JaxenXPathTestSuite {
+
+ private static final String DEFAULT_JAXEN_HOME = "/home/dalvik-prebuild/jaxen";
+
+ public static Test suite() throws Exception {
+ String jaxenHome = System.getProperty("jaxen.home", DEFAULT_JAXEN_HOME);
+ return suite(new File(jaxenHome));
+ }
+
+ /**
+ * Creates a test suite from the Jaxen tests.xml catalog.
+ */
+ public static Test suite(File jaxenHome)
+ throws ParserConfigurationException, IOException, SAXException {
+
+ /*
+ * The tests.xml document has this structure:
+ *
+ * <tests>
+ * <document url="...">
+ * <context .../>
+ * <context .../>
+ * <context .../>
+ * </document>
+ * <document url="...">
+ * <context .../>
+ * </document>
+ * </tests>
+ */
+
+ File testsXml = new File(jaxenHome + "/xml/test/tests.xml");
+ Element tests = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder().parse(testsXml).getDocumentElement();
+
+ TestSuite result = new TestSuite();
+ for (Element document : elementsOf(tests.getElementsByTagName("document"))) {
+ String url = document.getAttribute("url");
+ InputSource inputSource = new InputSource("file:" + jaxenHome + "/" + url);
+ for (final Element context : elementsOf(document.getElementsByTagName("context"))) {
+ contextToTestSuite(result, url, inputSource, context);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Populates the test suite with tests from the given XML context element.
+ */
+ private static void contextToTestSuite(TestSuite suite, String url,
+ InputSource inputSource, Element element) {
+
+ /*
+ * Each context element has this structure:
+ *
+ * <context select="...">
+ * <test .../>
+ * <test .../>
+ * <test .../>
+ * <valueOf .../>
+ * <valueOf .../>
+ * <valueOf .../>
+ * </context>
+ */
+
+ String select = element.getAttribute("select");
+ Context context = new Context(inputSource, url, select);
+
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ xpath.setXPathVariableResolver(new ElementVariableResolver(element));
+
+ for (Element test : elementsOf(element.getChildNodes())) {
+ if (test.getTagName().equals("test")) {
+ suite.addTest(createFromTest(xpath, context, test));
+
+ } else if (test.getTagName().equals("valueOf")) {
+ suite.addTest(createFromValueOf(xpath, context, test));
+
+ } else {
+ throw new UnsupportedOperationException("Unsupported test: " + context);
+ }
+ }
+ }
+
+ /**
+ * Returns the test described by the given {@code <test>} element. Such
+ * tests come in one of three varieties:
+ *
+ * <ul>
+ * <li>Expected failures.
+ * <li>String matches. These tests have a nested {@code <valueOf>} element
+ * that sub-selects an expected text.
+ * <li>Count matches. These tests specify how many nodes are expected to
+ * match.
+ * </ul>
+ */
+ private static TestCase createFromTest(
+ final XPath xpath, final Context context, final Element element) {
+ final String select = element.getAttribute("select");
+
+ /* Such as <test exception="true" select="..." count="0"/> */
+ if (element.getAttribute("exception").equals("true")) {
+ return new XPathTest(context, select) {
+ @Override void test(Node contextNode) {
+ try {
+ xpath.evaluate(select, contextNode);
+ fail("Expected exception!");
+ } catch (XPathExpressionException expected) {
+ }
+ }
+ };
+ }
+
+ /* a <test> with a nested <valueOf>, both of which have select attributes */
+ NodeList valueOfElements = element.getElementsByTagName("valueOf");
+ if (valueOfElements.getLength() == 1) {
+ final Element valueOf = (Element) valueOfElements.item(0);
+ final String valueOfSelect = valueOf.getAttribute("select");
+
+ return new XPathTest(context, select) {
+ @Override void test(Node contextNode) throws XPathExpressionException {
+ Node newContext = (Node) xpath.evaluate(
+ select, contextNode, XPathConstants.NODE);
+ assertEquals(valueOf.getTextContent(),
+ xpath.evaluate(valueOfSelect, newContext, XPathConstants.STRING));
+ }
+ };
+ }
+
+ /* Such as <test select="..." count="5"/> */
+ final String count = element.getAttribute("count");
+ if (count.length() > 0) {
+ return new XPathTest(context, select) {
+ @Override void test(Node contextNode) throws XPathExpressionException {
+ NodeList result = (NodeList) xpath.evaluate(
+ select, contextNode, XPathConstants.NODESET);
+ assertEquals(Integer.parseInt(count), result.getLength());
+ }
+ };
+ }
+
+ throw new UnsupportedOperationException("Unsupported test: " + context);
+ }
+
+ /**
+ * Returns the test described by the given {@code <valueOf>} element. These
+ * tests select an expected text.
+ */
+ private static TestCase createFromValueOf(
+ final XPath xpath, final Context context, final Element element) {
+ final String select = element.getAttribute("select");
+ return new XPathTest(context, select) {
+ @Override void test(Node contextNode) throws XPathExpressionException {
+ assertEquals(element.getTextContent(),
+ xpath.evaluate(select, contextNode, XPathConstants.STRING));
+ }
+ };
+ }
+
+ /**
+ * The subject of an XPath query. This is itself defined by an XPath query,
+ * so each test requires at least XPath expressions to be evaluated.
+ */
+ static class Context {
+ private final InputSource inputSource;
+ private final String url;
+ private final String select;
+
+ Context(InputSource inputSource, String url, String select) {
+ this.inputSource = inputSource;
+ this.url = url;
+ this.select = select;
+ }
+
+ Node getNode() {
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ try {
+ return (Node) xpath.evaluate(select, inputSource, XPathConstants.NODE);
+ } catch (XPathExpressionException e) {
+ Error error = new AssertionFailedError("Failed to get context");
+ error.initCause(e);
+ throw error;
+ }
+ }
+
+ @Override public String toString() {
+ return url + " " + select;
+ }
+ }
+
+ /**
+ * This test evaluates an XPath expression against a context node and
+ * compares the result to a known expectation.
+ */
+ public abstract static class XPathTest extends TestCase {
+ private final Context context;
+ private final String select;
+
+ public XPathTest(Context context, String select) {
+ super("test");
+ this.context = context;
+ this.select = select;
+ }
+
+ abstract void test(Node contextNode) throws XPathExpressionException;
+
+ public final void test() throws XPathExpressionException {
+ try {
+ test(context.getNode());
+ } catch (XPathExpressionException e) {
+ if (isMissingFunction(e)) {
+ fail(e.getCause().getMessage());
+ } else {
+ throw e;
+ }
+ }
+ }
+
+ private boolean isMissingFunction(XPathExpressionException e) {
+ return e.getCause() != null
+ && e.getCause().getMessage().startsWith("Could not find function");
+ }
+
+ @Override public String getName() {
+ return context + " " + select;
+ }
+ }
+
+ /**
+ * Performs XPath variable resolution by using {@code var:name="value"}
+ * attributes from the given element.
+ */
+ private static class ElementVariableResolver implements XPathVariableResolver {
+ private final Element element;
+ public ElementVariableResolver(Element element) {
+ this.element = element;
+ }
+ public Object resolveVariable(QName variableName) {
+ return element.getAttribute("var:" + variableName.getLocalPart());
+ }
+ }
+
+ private static List<Element> elementsOf(NodeList nodeList) {
+ List<Element> result = new ArrayList<Element>();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element) {
+ result.add((Element) node);
+ }
+ }
+ return result;
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/KxmlPullParserDtdTest.java b/luni/src/test/java/libcore/xml/KxmlPullParserDtdTest.java
new file mode 100644
index 0000000..3175b37
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/KxmlPullParserDtdTest.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+public class KxmlPullParserDtdTest extends PullParserDtdTest {
+ @Override XmlPullParser newPullParser() throws XmlPullParserException {
+ KXmlParser result = new KXmlParser();
+ result.setFeature(XmlPullParser.FEATURE_PROCESS_DOCDECL, true);
+ return result;
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/KxmlPullParserTest.java b/luni/src/test/java/libcore/xml/KxmlPullParserTest.java
new file mode 100644
index 0000000..71f25e9
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/KxmlPullParserTest.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import org.kxml2.io.KXmlParser;
+import org.xmlpull.v1.XmlPullParser;
+
+public class KxmlPullParserTest extends PullParserTest {
+
+ @Override XmlPullParser newPullParser() {
+ return new KXmlParser();
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/NamespacedAttributesLookupTest.java b/luni/src/test/java/libcore/xml/NamespacedAttributesLookupTest.java
new file mode 100644
index 0000000..cf12000
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/NamespacedAttributesLookupTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import junit.framework.TestCase;
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.SAXParserFactory;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Tests that we both report and retrieve attributes using the appropriate
+ * names for different combinations of namespaces and namespace prefixes.
+ */
+public class NamespacedAttributesLookupTest extends TestCase {
+
+ private static final String SAX_PROPERTY_NS =
+ "http://xml.org/sax/features/namespaces";
+ private static final String SAX_PROPERTY_NS_PREFIXES =
+ "http://xml.org/sax/features/namespace-prefixes";
+
+ private static String xml = "<?xml version='1.0' encoding='UTF-8'?>" +
+ "<test xmlns='http://foo' xmlns:bar='http://bar' xmlns:baz='http://baz' baz:c='a'>" +
+ "<b c='w' bar:c='x'/>" +
+ "<bar:e baz:c='y' bar:c='z'/>" +
+ "</test>";
+
+ public void testNamespace() throws Exception {
+ List<String> expected = Arrays.asList(
+ "http://foo,test\n" +
+ " http://baz,c\n" +
+ " http://bar+c=null,\n" +
+ " bar:c=null\n",
+
+ "http://foo,b\n" +
+ " ,c\n" +
+ " http://bar,c\n" +
+ " http://bar+c=x,\n" +
+ " bar:c=x\n",
+
+ "http://bar,e\n" +
+ " http://baz,c\n" +
+ " http://bar,c\n" +
+ " http://bar+c=z,\n" +
+ " bar:c=z\n");
+
+ boolean namespace = true;
+ boolean namespacePrefixes = false;
+ assertEquals(expected, getStartElements(xml, namespace, namespacePrefixes));
+ }
+
+ public void testNamespacePrefixes() throws Exception {
+ List<String> expected = Arrays.asList(
+ "test\n" +
+ " xmlns\n" +
+ " xmlns:bar\n" +
+ " xmlns:baz\n" +
+ " baz:c\n" +
+ " http://bar+c=null,\n" +
+ " bar:c=null\n",
+
+ "b\n" +
+ " c\n" +
+ " bar:c\n" +
+ " http://bar+c=null,\n" +
+ " bar:c=x\n",
+
+ "bar:e\n" +
+ " baz:c\n" +
+ " bar:c\n" +
+ " http://bar+c=null,\n" +
+ " bar:c=z\n");
+
+ boolean namespace = false;
+ boolean namespacePrefixes = true;
+ assertEquals(expected, getStartElements(xml, namespace, namespacePrefixes));
+ }
+
+ public List<String> getStartElements(String xml, final boolean namespace, boolean namespacePrefixes)
+ throws Exception {
+ final List<String> result = new ArrayList<String>();
+ XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
+ reader.setFeature(SAX_PROPERTY_NS, namespace);
+ reader.setFeature(SAX_PROPERTY_NS_PREFIXES, namespacePrefixes);
+ reader.setContentHandler(new DefaultHandler() {
+ @Override public final void startElement(
+ String uri, String localName, String qName, Attributes attributes) {
+ StringBuilder serialized = new StringBuilder();
+ /*
+ * Only supply the uri+localName or qname depending on whether namespaces are
+ * enabled. It's an optional parameter and the RI only supplies one or the other.
+ */
+ if (namespace) {
+ serialized.append(uri).append(",");
+ serialized.append(localName);
+ } else {
+ serialized.append(qName);
+ }
+ for (int i = 0; i < attributes.getLength(); i++) {
+ serialized.append("\n ");
+ if (namespace) {
+ serialized.append(attributes.getURI(i)).append(",");
+ serialized.append(attributes.getLocalName(i));
+ } else {
+ serialized.append(attributes.getQName(i));
+ }
+ }
+ serialized.append("\n http://bar+c=")
+ .append(attributes.getValue("http://bar", "c")).append(",")
+ .append("\n bar:c=")
+ .append(attributes.getValue("bar:c"))
+ .append("\n");
+ result.add(serialized.toString());
+ }
+ });
+ reader.parse(new InputSource(new StringReader(xml)));
+ return result;
+ }
+}
diff --git a/luni/src/test/java/libcore/xml/PullParserDtdTest.java b/luni/src/test/java/libcore/xml/PullParserDtdTest.java
new file mode 100644
index 0000000..834bf00
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/PullParserDtdTest.java
@@ -0,0 +1,541 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+/**
+ * Test doctype handling in pull parsers.
+ */
+public abstract class PullParserDtdTest extends TestCase {
+
+ private static final int READ_BUFFER_SIZE = 8192;
+
+ /**
+ * Android's Expat pull parser permits parameter entities to be declared,
+ * but it doesn't permit such entities to be used.
+ */
+ public void testDeclaringParameterEntities() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY % a \"android\">"
+ + "]><foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ while (parser.next() != XmlPullParser.END_DOCUMENT) {
+ }
+ }
+
+ public void testUsingParameterEntitiesInDtds() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY % a \"android\">"
+ + " <!ENTITY b \"%a;\">"
+ + "]><foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertParseFailure(parser);
+ }
+
+ public void testUsingParameterInDocuments() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY % a \"android\">"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertParseFailure(parser);
+ }
+
+ public void testGeneralAndParameterEntityWithTheSameName() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a \"aaa\">"
+ + " <!ENTITY % a \"bbb\">"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("aaa", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testInternalEntities() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a \"android\">"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("android", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testExternalDtdIsSilentlyIgnored() throws Exception {
+ String xml = "<!DOCTYPE foo SYSTEM \"http://127.0.0.1:1/no-such-file.dtd\"><foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testExternalAndInternalDtd() throws Exception {
+ String xml = "<!DOCTYPE foo SYSTEM \"http://127.0.0.1:1/no-such-file.dtd\" ["
+ + " <!ENTITY a \"android\">"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("android", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testInternalEntitiesAreParsed() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a \"&#38;#65;\">" // &#38; expands to '&', &#65; expands to 'A'
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("A", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testFoolishlyRecursiveInternalEntities() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a \"&#38;#38;#38;#38;\">" // expand &#38; to '&' only twice
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("&#38;#38;", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ /**
+ * Test that the output of {@code &#38;} is parsed, but {@code &amp;} isn't.
+ * http://www.w3.org/TR/2008/REC-xml-20081126/#sec-entexpand
+ */
+ public void testExpansionOfEntityAndCharacterReferences() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + "<!ENTITY example \"<p>An ampersand (&#38;#38;) may be escaped\n"
+ + "numerically (&#38;#38;#38;) or with a general entity\n"
+ + "(&amp;amp;).</p>\" >"
+ + "]><foo>&example;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("p", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("An ampersand (&) may be escaped\n"
+ + "numerically (&#38;) or with a general entity\n"
+ + "(&amp;).", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("p", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testGeneralEntitiesAreStoredUnresolved() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + "<!ENTITY b \"&a;\" >"
+ + "<!ENTITY a \"android\" >"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("android", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testStructuredEntityAndNextToken() throws Exception {
+ String xml = "<!DOCTYPE foo [<!ENTITY bb \"<bar>baz<!--quux--></bar>\">]><foo>a&bb;c</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.DOCDECL, parser.nextToken());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("a", parser.getText());
+ assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
+ assertEquals("bb", parser.getName());
+ assertEquals("", parser.getText());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("baz", parser.getText());
+ assertEquals(XmlPullParser.COMMENT, parser.nextToken());
+ assertEquals("quux", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("c", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ /**
+ * Android's Expat replaces external entities with the empty string.
+ */
+ public void testUsingExternalEntities() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a SYSTEM \"http://localhost:1/no-such-file.xml\">"
+ + "]><foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ // &a; is dropped!
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ /**
+ * Android's ExpatPullParser replaces missing entities with the empty string
+ * when an external DTD is declared.
+ */
+ public void testExternalDtdAndMissingEntity() throws Exception {
+ String xml = "<!DOCTYPE foo SYSTEM \"http://127.0.0.1:1/no-such-file.dtd\">"
+ + "<foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+
+ public void testExternalIdIsCaseSensitive() throws Exception {
+ // The spec requires 'SYSTEM' in upper case
+ String xml = "<!DOCTYPE foo ["
+ + " <!ENTITY a system \"http://localhost:1/no-such-file.xml\">"
+ + "]><foo/>";
+ XmlPullParser parser = newPullParser(xml);
+ assertParseFailure(parser);
+ }
+
+ /**
+ * Use a DTD to specify that {@code <foo>} only contains {@code <bar>} tags.
+ * Validating parsers react to this by dropping whitespace between the two
+ * tags.
+ */
+ public void testDtdDoesNotInformIgnorableWhitespace() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo (bar)*>\n"
+ + " <!ELEMENT bar ANY>\n"
+ + "]>"
+ + "<foo> \n <bar></bar> \t </foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(" \n ", parser.getText());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(" \t ", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testEmptyDoesNotInformIgnorableWhitespace() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo EMPTY>\n"
+ + "]>"
+ + "<foo> \n </foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(" \n ", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ /**
+ * Test that the parser doesn't expand the entity attributes.
+ */
+ public void testAttributeOfTypeEntity() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ENTITY a \"android\">"
+ + " <!ELEMENT foo ANY>\n"
+ + " <!ATTLIST foo\n"
+ + " bar ENTITY #IMPLIED>"
+ + "]>"
+ + "<foo bar=\"a\"></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals("a", parser.getAttributeValue(null, "bar"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testTagStructureNotValidated() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo (bar)*>\n"
+ + " <!ELEMENT bar ANY>\n"
+ + " <!ELEMENT baz ANY>\n"
+ + "]>"
+ + "<foo><bar/><bar/><baz/></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("baz", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testAttributeDefaultValues() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ATTLIST bar\n"
+ + " baz (a|b|c) \"c\">"
+ + "]>"
+ + "<foo>"
+ + "<bar/>"
+ + "<bar baz=\"a\"/>"
+ + "</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals("c", parser.getAttributeValue(null, "baz"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("bar", parser.getName());
+ assertEquals("a", parser.getAttributeValue(null, "baz"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testAttributeDefaultValueEntitiesExpanded() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ENTITY g \"ghi\">"
+ + " <!ELEMENT foo ANY>\n"
+ + " <!ATTLIST foo\n"
+ + " bar CDATA \"abc &amp; def &g; jk\">"
+ + "]>"
+ + "<foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals("abc & def ghi jk", parser.getAttributeValue(null, "bar"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testAttributeDefaultValuesAndNamespaces() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ATTLIST foo\n"
+ + " bar:a CDATA \"android\">"
+ + "]>"
+ + "<foo xmlns:bar='http://bar'></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ // In Expat, namespaces don't apply to default attributes
+ int index = indexOfAttributeWithName(parser, "bar:a");
+ assertEquals("", parser.getAttributeNamespace(index));
+ assertEquals("bar:a", parser.getAttributeName(index));
+ assertEquals("android", parser.getAttributeValue(index));
+ assertEquals("CDATA", parser.getAttributeType(index));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ private int indexOfAttributeWithName(XmlPullParser parser, String name) {
+ for (int i = 0; i < parser.getAttributeCount(); i++) {
+ if (parser.getAttributeName(i).equals(name)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ public void testAttributeEntitiesExpandedEagerly() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo ANY>\n"
+ + " <!ATTLIST foo\n"
+ + " bar CDATA \"abc &amp; def &g; jk\">"
+ + " <!ENTITY g \"ghi\">"
+ + "]>"
+ + "<foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertParseFailure(parser);
+ }
+
+ public void testRequiredAttributesOmitted() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo ANY>\n"
+ + " <!ATTLIST foo\n"
+ + " bar (a|b|c) #REQUIRED>"
+ + "]>"
+ + "<foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(null, parser.getAttributeValue(null, "bar"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testFixedAttributesWithConflictingValues() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ELEMENT foo ANY>\n"
+ + " <!ATTLIST foo\n"
+ + " bar (a|b|c) #FIXED \"c\">"
+ + "]>"
+ + "<foo bar=\"a\"></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals("a", parser.getAttributeValue(null, "bar"));
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testParsingNotations() throws Exception {
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!NOTATION type-a PUBLIC \"application/a\"> \n"
+ + " <!NOTATION type-b PUBLIC \"image/b\">\n"
+ + " <!NOTATION type-c PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n"
+ + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"> \n"
+ + " <!ENTITY file SYSTEM \"d.xml\">\n"
+ + " <!ENTITY fileWithNdata SYSTEM \"e.bin\" NDATA type-b>\n"
+ + "]>"
+ + "<foo type=\"type-a\"/>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testCommentsInDoctype() throws Exception {
+ String xml = "<!DOCTYPE foo ["
+ + " <!-- ' -->"
+ + "]><foo>android</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("android", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testDoctypeNameOnly() throws Exception {
+ String xml = "<!DOCTYPE foo><foo></foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testVeryLongEntities() throws Exception {
+ String a = repeat('a', READ_BUFFER_SIZE + 1);
+ String b = repeat('b', READ_BUFFER_SIZE + 1);
+ String c = repeat('c', READ_BUFFER_SIZE + 1);
+
+ String xml = "<!DOCTYPE foo [\n"
+ + " <!ENTITY " + a + " \"d &" + b + "; e\">"
+ + " <!ENTITY " + b + " \"f " + c + " g\">"
+ + "]>"
+ + "<foo>h &" + a + "; i</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("h d f " + c + " g e i", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testManuallyRegisteredEntitiesWithDoctypeParsing() throws Exception {
+ String xml = "<foo>&a;</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ try {
+ parser.defineEntityReplacementText("a", "android");
+ fail();
+ } catch (UnsupportedOperationException expected) {
+ } catch (IllegalStateException expected) {
+ }
+ }
+
+ public void testDoctypeWithNextToken() throws Exception {
+ String xml = "<!DOCTYPE foo [<!ENTITY bb \"bar baz\">]><foo>a&bb;c</foo>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.DOCDECL, parser.nextToken());
+ assertEquals(" foo [<!ENTITY bb \"bar baz\">]", parser.getText());
+ assertNull(parser.getName());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("abar bazc", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testDoctypeSpansBuffers() throws Exception {
+ char[] doctypeChars = new char[READ_BUFFER_SIZE + 1];
+ Arrays.fill(doctypeChars, 'x');
+ String doctypeBody = " foo [<!--" + new String(doctypeChars) + "-->]";
+ String xml = "<!DOCTYPE" + doctypeBody + "><foo/>";
+ XmlPullParser parser = newPullParser(xml);
+ assertEquals(XmlPullParser.DOCDECL, parser.nextToken());
+ assertEquals(doctypeBody, parser.getText());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ private void assertParseFailure(XmlPullParser parser) throws IOException {
+ try {
+ while (parser.next() != XmlPullParser.END_DOCUMENT) {
+ }
+ fail();
+ } catch (XmlPullParserException expected) {
+ }
+ }
+
+ private String repeat(char c, int length) {
+ char[] chars = new char[length];
+ Arrays.fill(chars, c);
+ return new String(chars);
+ }
+
+ private XmlPullParser newPullParser(String xml) throws XmlPullParserException {
+ XmlPullParser result = newPullParser();
+ result.setInput(new StringReader(xml));
+ return result;
+ }
+
+ /**
+ * Creates a new pull parser.
+ */
+ abstract XmlPullParser newPullParser() throws XmlPullParserException;
+}
diff --git a/luni/src/test/java/libcore/xml/PullParserTest.java b/luni/src/test/java/libcore/xml/PullParserTest.java
new file mode 100644
index 0000000..aaa76a6
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/PullParserTest.java
@@ -0,0 +1,734 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import junit.framework.TestCase;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+public abstract class PullParserTest extends TestCase {
+
+ public void testAttributeNoValueWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ parser.setInput(new StringReader("<input checked></input>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("input", parser.getName());
+ assertEquals("checked", parser.getAttributeName(0));
+ assertEquals("checked", parser.getAttributeValue(0));
+ }
+
+ public void testAttributeUnquotedValueWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ parser.setInput(new StringReader("<input checked=true></input>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("input", parser.getName());
+ assertEquals("checked", parser.getAttributeName(0));
+ assertEquals("true", parser.getAttributeValue(0));
+ }
+
+ public void testUnterminatedEntityWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ parser.setInput(new StringReader("<foo bar='A&W'>mac&cheese</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals("bar", parser.getAttributeName(0));
+ assertEquals("A&W", parser.getAttributeValue(0));
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("mac&cheese", parser.getText());
+ }
+
+ public void testEntitiesAndNamespaces() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true);
+ parser.setInput(new StringReader(
+ "<foo:a xmlns:foo='http://foo' xmlns:bar='http://bar'><bar:b/></foo:a>"));
+ testNamespace(parser);
+ }
+
+ public void testEntitiesAndNamespacesWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#process-namespaces", true);
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ parser.setInput(new StringReader(
+ "<foo:a xmlns:foo='http://foo' xmlns:bar='http://bar'><bar:b/></foo:a>"));
+ testNamespace(parser);
+ }
+
+ private void testNamespace(XmlPullParser parser) throws XmlPullParserException, IOException {
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("http://foo", parser.getNamespace());
+ assertEquals("a", parser.getName());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("http://bar", parser.getNamespace());
+ assertEquals("b", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("http://bar", parser.getNamespace());
+ assertEquals("b", parser.getName());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("http://foo", parser.getNamespace());
+ assertEquals("a", parser.getName());
+ }
+
+ public void testRegularNumericEntities() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&#65;</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
+ assertEquals("#65", parser.getName());
+ assertEquals("A", parser.getText());
+ }
+
+ public void testNumericEntitiesLargerThanChar() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<foo>&#2147483647; &#-2147483648;</foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testNumericEntitiesLargerThanInt() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<foo>&#2147483648;</foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testCharacterReferenceOfHexUtf16Surrogates() throws Exception {
+ testCharacterReferenceOfUtf16Surrogates("<foo>&#x10000; &#x10381; &#x10FFF0;</foo>");
+ }
+
+ public void testCharacterReferenceOfDecimalUtf16Surrogates() throws Exception {
+ testCharacterReferenceOfUtf16Surrogates("<foo>&#65536; &#66433; &#1114096;</foo>");
+ }
+
+ private void testCharacterReferenceOfUtf16Surrogates(String xml) throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(xml));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(new String(new int[] { 65536, ' ', 66433, ' ', 1114096 }, 0, 5),
+ parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testCharacterReferenceOfLastUtf16Surrogate() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&#x10FFFF;</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(new String(new int[] { 0x10FFFF }, 0, 1), parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testOmittedNumericEntities() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&#;</foo>"));
+ assertParseFailure(parser);
+ }
+
+ /**
+ * Carriage returns followed by line feeds are silently discarded.
+ */
+ public void testCarriageReturnLineFeed() throws Exception {
+ testLineEndings("\r\n<foo\r\na='b\r\nc'\r\n>d\r\ne</foo\r\n>\r\n");
+ }
+
+ /**
+ * Lone carriage returns are treated like newlines.
+ */
+ public void testLoneCarriageReturn() throws Exception {
+ testLineEndings("\r<foo\ra='b\rc'\r>d\re</foo\r>\r");
+ }
+
+ public void testLoneNewLine() throws Exception {
+ testLineEndings("\n<foo\na='b\nc'\n>d\ne</foo\n>\n");
+ }
+
+ private void testLineEndings(String xml) throws XmlPullParserException, IOException {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(xml));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals("b c", parser.getAttributeValue(0));
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("d\ne", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals("foo", parser.getName());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testXmlDeclaration() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<?xml version='1.0' encoding='UTF-8' standalone='no'?><foo/>"));
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("1.0", parser.getProperty(
+ "http://xmlpull.org/v1/doc/properties.html#xmldecl-version"));
+ assertEquals(Boolean.FALSE, parser.getProperty(
+ "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone"));
+ assertEquals("UTF-8", parser.getInputEncoding());
+ }
+
+ public void testXmlDeclarationExtraAttributes() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<?xml version='1.0' encoding='UTF-8' standalone='no' a='b'?><foo/>"));
+ try {
+ parser.nextToken();
+ fail();
+ } catch (XmlPullParserException expected) {
+ }
+ }
+
+ public void testCustomEntitiesUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<foo a='cd&aaaaaaaaaa;ef'>wx&aaaaaaaaaa;yz</foo>"));
+ parser.defineEntityReplacementText("aaaaaaaaaa", "b");
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("cdbef", parser.getAttributeValue(0));
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("wxbyz", parser.getText());
+ }
+
+ public void testCustomEntitiesUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<foo a='cd&aaaaaaaaaa;ef'>wx&aaaaaaaaaa;yz</foo>"));
+ parser.defineEntityReplacementText("aaaaaaaaaa", "b");
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("cdbef", parser.getAttributeValue(0));
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("wx", parser.getText());
+ assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
+ assertEquals("aaaaaaaaaa", parser.getName());
+ assertEquals("b", parser.getText());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("yz", parser.getText());
+ }
+
+ public void testCustomEntitiesAreNotEvaluated() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(
+ "<foo a='&a;'>&a;</foo>"));
+ parser.defineEntityReplacementText("a", "&amp; &a;");
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("&amp; &a;", parser.getAttributeValue(0));
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("&amp; &a;", parser.getText());
+ }
+
+ public void testMissingEntities() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&aaa;</foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testMissingEntitiesWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ parser.setInput(new StringReader("<foo>&aaa;</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(null, parser.getName());
+ assertEquals("Expected unresolved entities to be left in-place. The old parser "
+ + "would resolve these to the empty string.", "&aaa;", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testMissingEntitiesUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ testMissingEntitiesUsingNextToken(parser);
+ }
+
+ public void testMissingEntitiesUsingNextTokenWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ testMissingEntitiesUsingNextToken(parser);
+ }
+
+ private void testMissingEntitiesUsingNextToken(XmlPullParser parser)
+ throws XmlPullParserException, IOException {
+ parser.setInput(new StringReader("<foo>&aaa;</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
+ assertEquals("aaa", parser.getName());
+ assertEquals(null, parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testEntityInAttributeUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo bar=\"&amp;\"></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("foo", parser.getName());
+ assertEquals("&", parser.getAttributeValue(null, "bar"));
+ }
+
+ public void testMissingEntitiesInAttributesUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo b='&aaa;'></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testMissingEntitiesInAttributesUsingNextWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo b='&aaa;'></foo>"));
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(1, parser.getAttributeCount());
+ assertEquals("b", parser.getAttributeName(0));
+ assertEquals("Expected unresolved entities to be left in-place. The old parser "
+ + "would resolve these to the empty string.", "&aaa;", parser.getAttributeValue(0));
+ }
+
+ public void testMissingEntitiesInAttributesUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo b='&aaa;'></foo>"));
+ testMissingEntitiesInAttributesUsingNextToken(parser);
+ }
+
+ public void testMissingEntitiesInAttributesUsingNextTokenWithRelaxed() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo b='&aaa;'></foo>"));
+ parser.setFeature("http://xmlpull.org/v1/doc/features.html#relaxed", true);
+ testMissingEntitiesInAttributesUsingNextToken(parser);
+ }
+
+ private void testMissingEntitiesInAttributesUsingNextToken(XmlPullParser parser)
+ throws IOException, XmlPullParserException {
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(1, parser.getAttributeCount());
+ assertEquals("b", parser.getAttributeName(0));
+ assertEquals("Expected unresolved entities to be left in-place. The old parser "
+ + "would resolve these to the empty string.", "&aaa;", parser.getAttributeValue(0));
+ }
+
+ public void testGreaterThanInText() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(">", parser.getText());
+ }
+
+ public void testGreaterThanInAttribute() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo a='>'></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(">", parser.getAttributeValue(0));
+ }
+
+ public void testLessThanInText() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><</foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testLessThanInAttribute() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo a='<'></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testQuotesInAttribute() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo a='\"' b=\"'\"></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("\"", parser.getAttributeValue(0));
+ assertEquals("'", parser.getAttributeValue(1));
+ }
+
+ public void testQuotesInText() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>\" '</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("\" '", parser.getText());
+ }
+
+ public void testCdataDelimiterInAttribute() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo a=']]>'></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals("]]>", parser.getAttributeValue(0));
+ }
+
+ public void testCdataDelimiterInText() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>]]></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testUnexpectedEof() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><![C"));
+ assertParseFailure(parser);
+ }
+
+ public void testUnexpectedSequence() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><![Cdata[bar]]></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testThreeDashCommentDelimiter() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><!--a---></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testTwoDashesInComment() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><!-- -- --></foo>"));
+ assertParseFailure(parser);
+ }
+
+ public void testEmptyComment() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><!----></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.COMMENT, parser.nextToken());
+ assertEquals("", parser.getText());
+ }
+
+ /**
+ * Close braces require lookaheads because we need to defend against "]]>".
+ */
+ public void testManyCloseBraces() throws Exception{
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>]]]]]]]]]]]]]]]]]]]]]]]</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("]]]]]]]]]]]]]]]]]]]]]]]", parser.getText());
+ }
+
+ public void testCommentUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<!-- comment! -->cd</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("abcd", parser.getText());
+ }
+
+ public void testCommentUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<!-- comment! -->cd</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("ab", parser.getText());
+ assertEquals(XmlPullParser.COMMENT, parser.nextToken());
+ assertEquals(" comment! ", parser.getText());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("cd", parser.getText());
+ }
+
+ public void testCdataUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<![CDATA[cdef]]gh&amp;i]]>jk</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("abcdef]]gh&amp;ijk", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testCdataUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<![CDATA[cdef]]gh&amp;i]]>jk</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("ab", parser.getText());
+ assertEquals(XmlPullParser.CDSECT, parser.nextToken());
+ assertEquals("cdef]]gh&amp;i", parser.getText());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("jk", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ }
+
+ public void testEntityLooksLikeCdataClose() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&#93;&#93;></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("]]>", parser.getText());
+ }
+
+ public void testProcessingInstructionUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<?cd efg hij?>kl</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals("abkl", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testProcessingInstructionUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>ab<?cd efg hij?>kl</foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("ab", parser.getText());
+ assertEquals(XmlPullParser.PROCESSING_INSTRUCTION, parser.nextToken());
+ assertEquals("cd efg hij", parser.getText());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("kl", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testWhitespaceUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader(" \n <foo> \n </foo> \n "));
+ assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken());
+ assertEquals(true, parser.isWhitespace());
+ assertEquals(" \n ", parser.getText());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals(true, parser.isWhitespace());
+ assertEquals(" \n ", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken());
+ assertEquals(true, parser.isWhitespace());
+ assertEquals(" \n ", parser.getText());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken());
+ }
+
+ public void testLinesAndColumns() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("\n"
+ + " <foo><bar a='\n"
+ + "' b='cde'></bar\n"
+ + "><!--\n"
+ + "\n"
+ + "--><baz/>fg\n"
+ + "</foo>"));
+ assertEquals("1,1", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.IGNORABLE_WHITESPACE, parser.nextToken());
+ assertEquals("2,3", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("2,8", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("3,11", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ assertEquals("4,2", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.COMMENT, parser.nextToken());
+ assertEquals("6,4", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals("6,10", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ assertEquals("6,10", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.TEXT, parser.nextToken());
+ assertEquals("7,1", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ assertEquals("7,7", parser.getLineNumber() + "," + parser.getColumnNumber());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.nextToken());
+ assertEquals("7,7", parser.getLineNumber() + "," + parser.getColumnNumber());
+ }
+
+ public void testEmptyEntityReferenceUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&empty;</foo>"));
+ parser.defineEntityReplacementText("empty", "");
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testEmptyEntityReferenceUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo>&empty;</foo>"));
+ parser.defineEntityReplacementText("empty", "");
+ assertEquals(XmlPullParser.START_TAG, parser.nextToken());
+ assertEquals(XmlPullParser.ENTITY_REF, parser.nextToken());
+ assertEquals("empty", parser.getName());
+ assertEquals("", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.nextToken());
+ }
+
+ public void testEmptyCdataUsingNext() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><![CDATA[]]></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testEmptyCdataUsingNextToken() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo><![CDATA[]]></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.CDSECT, parser.nextToken());
+ assertEquals("", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ }
+
+ public void testParseReader() throws Exception {
+ String snippet = "<dagny dad=\"bob\">hello</dagny>";
+ XmlPullParser parser = newPullParser();
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
+ parser.setInput(new StringReader(snippet));
+ validate(parser);
+ }
+
+ public void testParseInputStream() throws Exception {
+ String snippet = "<dagny dad=\"bob\">hello</dagny>";
+ XmlPullParser parser = newPullParser();
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
+ parser.setInput(new ByteArrayInputStream(snippet.getBytes()), "UTF-8");
+ validate(parser);
+ }
+
+ static void validate(XmlPullParser parser)
+ throws XmlPullParserException, IOException {
+ assertEquals(XmlPullParser.START_DOCUMENT, parser.getEventType());
+ assertEquals(0, parser.getDepth());
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(1, parser.getDepth());
+ assertEquals("dagny", parser.getName());
+ assertEquals(1, parser.getAttributeCount());
+ assertEquals("dad", parser.getAttributeName(0));
+ assertEquals("bob", parser.getAttributeValue(0));
+ assertEquals("bob", parser.getAttributeValue(null, "dad"));
+ assertEquals(XmlPullParser.TEXT, parser.next());
+ assertEquals(1, parser.getDepth());
+ assertEquals("hello", parser.getText());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(1, parser.getDepth());
+ assertEquals("dagny", parser.getName());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ assertEquals(0, parser.getDepth());
+ }
+
+ public void testNextAfterEndDocument() throws Exception {
+ XmlPullParser parser = newPullParser();
+ parser.setInput(new StringReader("<foo></foo>"));
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(XmlPullParser.END_TAG, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+ }
+
+ public void testNamespaces() throws Exception {
+ String xml = "<one xmlns='ns:default' xmlns:n1='ns:1' a='b'>\n"
+ + " <n1:two c='d' n1:e='f' xmlns:n2='ns:2'>text</n1:two>\n"
+ + "</one>";
+
+ XmlPullParser parser = newPullParser();
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+ parser.setInput(new StringReader(xml));
+
+ assertEquals(0, parser.getDepth());
+ assertEquals(0, parser.getNamespaceCount(0));
+
+ try {
+ parser.getNamespaceCount(1);
+ fail();
+ } catch (IndexOutOfBoundsException e) { /* expected */ }
+
+ // one
+ assertEquals(XmlPullParser.START_TAG, parser.next());
+ assertEquals(1, parser.getDepth());
+
+ checkNamespacesInOne(parser);
+
+ // n1:two
+ assertEquals(XmlPullParser.START_TAG, parser.nextTag());
+
+ assertEquals(2, parser.getDepth());
+ checkNamespacesInTwo(parser);
+
+ // Body of two.
+ assertEquals(XmlPullParser.TEXT, parser.next());
+
+ // End of two.
+ assertEquals(XmlPullParser.END_TAG, parser.nextTag());
+
+ // Depth should still be 2.
+ assertEquals(2, parser.getDepth());
+
+ // We should still be able to see the namespaces from two.
+ checkNamespacesInTwo(parser);
+
+ // End of one.
+ assertEquals(XmlPullParser.END_TAG, parser.nextTag());
+
+ // Depth should be back to 1.
+ assertEquals(1, parser.getDepth());
+
+ // We can still see the namespaces in one.
+ checkNamespacesInOne(parser);
+
+ // We shouldn't be able to see the namespaces in two anymore.
+ try {
+ parser.getNamespaceCount(2);
+ fail();
+ } catch (IndexOutOfBoundsException e) { /* expected */ }
+
+ assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
+
+ // We shouldn't be able to see the namespaces in one anymore.
+ try {
+ parser.getNamespaceCount(1);
+ fail();
+ } catch (IndexOutOfBoundsException e) { /* expected */ }
+
+ assertEquals(0, parser.getNamespaceCount(0));
+ }
+
+ private void checkNamespacesInOne(XmlPullParser parser) throws XmlPullParserException {
+ assertEquals(2, parser.getNamespaceCount(1));
+
+ // Prefix for default namespace is null.
+ assertNull(parser.getNamespacePrefix(0));
+ assertEquals("ns:default", parser.getNamespaceUri(0));
+
+ assertEquals("n1", parser.getNamespacePrefix(1));
+ assertEquals("ns:1", parser.getNamespaceUri(1));
+
+ assertEquals("ns:default", parser.getNamespace(null));
+
+ // KXML returns null.
+ // assertEquals("ns:default", parser.getNamespace(""));
+ }
+
+ private void checkNamespacesInTwo(XmlPullParser parser) throws XmlPullParserException {
+ // These should still be valid.
+ checkNamespacesInOne(parser);
+
+ assertEquals(3, parser.getNamespaceCount(2));
+
+ // Default ns should still be in the stack
+ assertNull(parser.getNamespacePrefix(0));
+ assertEquals("ns:default", parser.getNamespaceUri(0));
+ }
+
+ private void assertParseFailure(XmlPullParser parser) throws IOException {
+ try {
+ while (parser.next() != XmlPullParser.END_DOCUMENT) {
+ }
+ fail();
+ } catch (XmlPullParserException expected) {
+ }
+ }
+
+ /**
+ * Creates a new pull parser.
+ */
+ abstract XmlPullParser newPullParser();
+}
diff --git a/luni/src/test/java/libcore/xml/XsltXPathConformanceTestSuite.java b/luni/src/test/java/libcore/xml/XsltXPathConformanceTestSuite.java
new file mode 100644
index 0000000..7bf1980
--- /dev/null
+++ b/luni/src/test/java/libcore/xml/XsltXPathConformanceTestSuite.java
@@ -0,0 +1,635 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package libcore.xml;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.ProcessingInstruction;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlPullParserFactory;
+import org.xmlpull.v1.XmlSerializer;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * The <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xslt">OASIS
+ * XSLT conformance test suite</a>, adapted for use by JUnit. To run these tests
+ * on a device:
+ * <ul>
+ * <li>Obtain the <a href="http://www.oasis-open.org/committees/download.php/12171/XSLT-testsuite-04.ZIP">test
+ * suite zip file from the OASIS project site.</li>
+ * <li>Unzip.
+ * <li>Copy the files to a device: <code>adb shell mkdir /data/oasis ;
+ * adb push ./XSLT-Conformance-TC /data/oasis</code>.
+ * <li>Invoke this class' main method, passing the on-device path to the test
+ * suite's <code>catalog.xml</code> file as an argument.
+ * </ul>
+ *
+ * <p>Unfortunately, some of the tests in the OASIS suite will fail when
+ * executed outside of their original development environment:
+ * <ul>
+ * <li>The tests assume case insensitive filesystems. Some will fail with
+ * "Couldn't open file" errors due to a mismatch in file name casing.
+ * <li>The tests assume certain network hosts will exist and serve
+ * stylesheet files. In particular, "http://webxtest/" isn't generally
+ * available.
+ * </ul>
+ */
+public class XsltXPathConformanceTestSuite {
+
+ private static final String defaultCatalogFile
+ = "/home/dalvik-prebuild/OASIS/XSLT-Conformance-TC/TESTS/catalog.xml";
+
+ /** Orders element attributes by optional URI and name. */
+ private static final Comparator<Attr> orderByName = new Comparator<Attr>() {
+ public int compare(Attr a, Attr b) {
+ int result = compareNullsFirst(a.getNamespaceURI(), b.getNamespaceURI());
+ return result == 0 ? result
+ : compareNullsFirst(a.getName(), b.getName());
+ }
+
+ <T extends Comparable<T>> int compareNullsFirst(T a, T b) {
+ return (a == b) ? 0
+ : (a == null) ? -1
+ : (b == null) ? 1
+ : a.compareTo(b);
+ }
+ };
+
+ private final DocumentBuilder documentBuilder;
+ private final TransformerFactory transformerFactory;
+ private final XmlPullParserFactory xmlPullParserFactory;
+
+ public XsltXPathConformanceTestSuite()
+ throws ParserConfigurationException, XmlPullParserException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setCoalescing(true);
+ documentBuilder = factory.newDocumentBuilder();
+
+ transformerFactory = TransformerFactory.newInstance();
+ xmlPullParserFactory = XmlPullParserFactory.newInstance();
+ }
+
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.out.println("Usage: XsltXPathConformanceTestSuite <catalog-xml>");
+ System.out.println();
+ System.out.println(" catalog-xml: an XML file describing an OASIS test suite");
+ System.out.println(" such as: " + defaultCatalogFile);
+ return;
+ }
+
+ File catalogXml = new File(args[0]);
+ // TestRunner.run(suite(catalogXml)); android-changed
+ }
+
+ public static Test suite() throws Exception {
+ return suite(new File(defaultCatalogFile));
+ }
+
+ /**
+ * Returns a JUnit test suite for the tests described by the given document.
+ */
+ public static Test suite(File catalogXml) throws Exception {
+ XsltXPathConformanceTestSuite suite = new XsltXPathConformanceTestSuite();
+
+ /*
+ * Extract the tests from an XML document with the following structure:
+ *
+ * <test-suite>
+ * <test-catalog submitter="Lotus">
+ * <creator>Lotus/IBM</creator>
+ * <major-path>Xalan_Conformance_Tests</major-path>
+ * <date>2001-11-16</date>
+ * <test-case ...> ... </test-case>
+ * <test-case ...> ... </test-case>
+ * <test-case ...> ... </test-case>
+ * </test-catalog>
+ * </test-suite>
+ */
+
+ Document document = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder().parse(catalogXml);
+ Element testSuiteElement = document.getDocumentElement();
+ TestSuite result = new TestSuite();
+ for (Element testCatalog : elementsOf(testSuiteElement.getElementsByTagName("test-catalog"))) {
+ Element majorPathElement = (Element) testCatalog.getElementsByTagName("major-path").item(0);
+ String majorPath = majorPathElement.getTextContent();
+ File base = new File(catalogXml.getParentFile(), majorPath);
+
+ for (Element testCaseElement : elementsOf(testCatalog.getElementsByTagName("test-case"))) {
+ result.addTest(suite.create(base, testCaseElement));
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns a JUnit test for the test described by the given element.
+ */
+ private TestCase create(File base, Element testCaseElement) {
+
+ /*
+ * Extract the XSLT test from a DOM entity with the following structure:
+ *
+ * <test-case category="XSLT-Result-Tree" id="attribset_attribset01">
+ * <file-path>attribset</file-path>
+ * <creator>Paul Dick</creator>
+ * <date>2001-11-08</date>
+ * <purpose>Set attribute of a LRE from single attribute set.</purpose>
+ * <spec-citation place="7.1.4" type="section" version="1.0" spec="xslt"/>
+ * <scenario operation="standard">
+ * <input-file role="principal-data">attribset01.xml</input-file>
+ * <input-file role="principal-stylesheet">attribset01.xsl</input-file>
+ * <output-file role="principal" compare="XML">attribset01.out</output-file>
+ * </scenario>
+ * </test-case>
+ */
+
+ Element filePathElement = (Element) testCaseElement.getElementsByTagName("file-path").item(0);
+ Element purposeElement = (Element) testCaseElement.getElementsByTagName("purpose").item(0);
+ Element specCitationElement = (Element) testCaseElement.getElementsByTagName("spec-citation").item(0);
+ Element scenarioElement = (Element) testCaseElement.getElementsByTagName("scenario").item(0);
+
+ String category = testCaseElement.getAttribute("category");
+ String id = testCaseElement.getAttribute("id");
+ String name = category + "." + id;
+ String purpose = purposeElement != null ? purposeElement.getTextContent() : "";
+ String spec = "place=" + specCitationElement.getAttribute("place")
+ + " type" + specCitationElement.getAttribute("type")
+ + " version=" + specCitationElement.getAttribute("version")
+ + " spec=" + specCitationElement.getAttribute("spec");
+ String operation = scenarioElement.getAttribute("operation");
+
+ Element principalDataElement = null;
+ Element principalStylesheetElement = null;
+ Element principalElement = null;
+
+ for (Element element : elementsOf(scenarioElement.getChildNodes())) {
+ String role = element.getAttribute("role");
+ if (role.equals("principal-data")) {
+ principalDataElement = element;
+ } else if (role.equals("principal-stylesheet")) {
+ principalStylesheetElement = element;
+ } else if (role.equals("principal")) {
+ principalElement = element;
+ } else if (!role.equals("supplemental-stylesheet")
+ && !role.equals("supplemental-data")) {
+ return new MisspecifiedTest("Unexpected element at " + name);
+ }
+ }
+
+ String testDirectory = filePathElement.getTextContent();
+ File inBase = new File(base, testDirectory);
+ File outBase = new File(new File(base, "REF_OUT"), testDirectory);
+
+ if (principalDataElement == null || principalStylesheetElement == null) {
+ return new MisspecifiedTest("Expected <scenario> to have "
+ + "principal=data and principal-stylesheet elements at " + name);
+ }
+
+ try {
+ File principalData = findFile(inBase, principalDataElement.getTextContent());
+ File principalStylesheet = findFile(inBase, principalStylesheetElement.getTextContent());
+
+ final File principal;
+ final String compareAs;
+ if (!operation.equals("execution-error")) {
+ if (principalElement == null) {
+ return new MisspecifiedTest("Expected <scenario> to have principal element at " + name);
+ }
+
+ principal = findFile(outBase, principalElement.getTextContent());
+ compareAs = principalElement.getAttribute("compare");
+ } else {
+ principal = null;
+ compareAs = null;
+ }
+
+ return new XsltTest(category, id, purpose, spec, principalData,
+ principalStylesheet, principal, operation, compareAs);
+ } catch (FileNotFoundException e) {
+ return new MisspecifiedTest(e.getMessage() + " at " + name);
+ }
+ }
+
+ /**
+ * Finds the named file in the named directory. This tries extra hard to
+ * avoid case-insensitive-naming problems, where the requested file is
+ * available in a different casing.
+ */
+ private File findFile(File directory, String name) throws FileNotFoundException {
+ File file = new File(directory, name);
+ if (file.exists()) {
+ return file;
+ }
+
+ for (String child : directory.list()) {
+ if (child.equalsIgnoreCase(name)) {
+ return new File(directory, child);
+ }
+ }
+
+ throw new FileNotFoundException("Missing file: " + file);
+ }
+
+ /**
+ * Placeholder for a test that couldn't be configured to run properly.
+ */
+ public class MisspecifiedTest extends TestCase {
+ private final String message;
+
+ MisspecifiedTest(String message) {
+ super("test");
+ this.message = message;
+ }
+
+ public void test() {
+ fail(message);
+ }
+ }
+
+ /**
+ * Processes an input XML file with an input XSLT stylesheet and compares
+ * the result to an expected output file.
+ */
+ public class XsltTest extends TestCase {
+ private final String category;
+ private final String id;
+ private final String purpose;
+ private final String spec;
+
+ private final File principalData;
+ private final File principalStylesheet;
+ private final File principal;
+
+ /** either "standard" or "execution-error" */
+ private final String operation;
+
+ /**
+ * The syntax to compare the output file using, such as "XML", "HTML",
+ * "manual", or null for expected execution errors.
+ */
+ private final String compareAs;
+
+ XsltTest(String category, String id, String purpose, String spec,
+ File principalData, File principalStylesheet, File principal,
+ String operation, String compareAs) {
+ super("test");
+ this.category = category;
+ this.id = id;
+ this.purpose = purpose;
+ this.spec = spec;
+ this.principalData = principalData;
+ this.principalStylesheet = principalStylesheet;
+ this.principal = principal;
+ this.operation = operation;
+ this.compareAs = compareAs;
+ }
+
+ XsltTest(File principalData, File principalStylesheet, File principal) {
+ this("standalone", "test", "", "",
+ principalData, principalStylesheet, principal, "standard", "XML");
+ }
+
+ public void test() throws Exception {
+ if (purpose != null) {
+ System.out.println("Purpose: " + purpose);
+ }
+ if (spec != null) {
+ System.out.println("Spec: " + spec);
+ }
+
+ Result result;
+ if ("XML".equals(compareAs)) {
+ DOMResult domResult = new DOMResult();
+ domResult.setNode(documentBuilder.newDocument().createElementNS("", "result"));
+ result = domResult;
+ } else {
+ result = new StreamResult(new StringWriter());
+ }
+
+ ErrorRecorder errorRecorder = new ErrorRecorder();
+ transformerFactory.setErrorListener(errorRecorder);
+
+ Transformer transformer;
+ try {
+ Source xslt = new StreamSource(principalStylesheet);
+ transformer = transformerFactory.newTransformer(xslt);
+ if (errorRecorder.error == null) {
+ transformer.setErrorListener(errorRecorder);
+ transformer.transform(new StreamSource(principalData), result);
+ }
+ } catch (TransformerConfigurationException e) {
+ errorRecorder.fatalError(e);
+ }
+
+ if (operation.equals("standard")) {
+ if (errorRecorder.error != null) {
+ throw errorRecorder.error;
+ }
+ } else if (operation.equals("execution-error")) {
+ if (errorRecorder.error != null) {
+ return;
+ }
+ fail("Expected " + operation + ", but transform completed normally."
+ + " (Warning=" + errorRecorder.warning + ")");
+ } else {
+ throw new UnsupportedOperationException("Unexpected operation: " + operation);
+ }
+
+ if ("XML".equals(compareAs)) {
+ assertNodesAreEquivalent(principal, ((DOMResult) result).getNode());
+ } else {
+ // TODO: implement support for comparing HTML etc.
+ throw new UnsupportedOperationException("Cannot compare as " + compareAs);
+ }
+ }
+
+ @Override public String getName() {
+ return category + "." + id;
+ }
+ }
+
+ /**
+ * Ensures both XML documents represent the same semantic data. Non-semantic
+ * data such as namespace prefixes, comments, and whitespace is ignored.
+ *
+ * @param actual an XML document whose root is a {@code <result>} element.
+ * @param expected a file containing an XML document fragment.
+ */
+ private void assertNodesAreEquivalent(File expected, Node actual)
+ throws ParserConfigurationException, IOException, SAXException,
+ XmlPullParserException {
+
+ Node expectedNode = fileToResultNode(expected);
+ String expectedString = nodeToNormalizedString(expectedNode);
+ String actualString = nodeToNormalizedString(actual);
+
+ Assert.assertEquals("Expected XML to match file " + expected,
+ expectedString, actualString);
+ }
+
+ /**
+ * Returns the given file's XML fragment as a single node, wrapped in
+ * {@code <result>} tags. This takes care of normalizing the following
+ * conditions:
+ *
+ * <ul>
+ * <li>Files containing XML document fragments with multiple elements:
+ * {@code <SPAN style="color=blue">Smurfs!</SPAN><br />}
+ *
+ * <li>Files containing XML document fragments with no elements:
+ * {@code Smurfs!}
+ *
+ * <li>Files containing proper XML documents with a single element and an
+ * XML declaration:
+ * {@code <?xml version="1.0"?><doc />}
+ *
+ * <li>Files prefixed with a byte order mark header, such as 0xEFBBBF.
+ * </ul>
+ */
+ private Node fileToResultNode(File file) throws IOException, SAXException {
+ String rawContents = fileToString(file);
+ String fragment = rawContents;
+
+ // If the file had an XML declaration, strip that. Otherwise wrapping
+ // it in <result> tags would result in a malformed XML document.
+ if (fragment.startsWith("<?xml")) {
+ int declarationEnd = fragment.indexOf("?>");
+ fragment = fragment.substring(declarationEnd + 2);
+ }
+
+ // Parse it as document fragment wrapped in <result> tags.
+ try {
+ fragment = "<result>" + fragment + "</result>";
+ return documentBuilder.parse(new InputSource(new StringReader(fragment)))
+ .getDocumentElement();
+ } catch (SAXParseException e) {
+ Error error = new AssertionFailedError(
+ "Failed to parse XML: " + file + "\n" + rawContents);
+ error.initCause(e);
+ throw error;
+ }
+ }
+
+ private String nodeToNormalizedString(Node node)
+ throws XmlPullParserException, IOException {
+ StringWriter writer = new StringWriter();
+ XmlSerializer xmlSerializer = xmlPullParserFactory.newSerializer();
+ xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
+ xmlSerializer.setOutput(writer);
+ emitNode(xmlSerializer, node);
+ xmlSerializer.flush();
+ return writer.toString();
+ }
+
+ private void emitNode(XmlSerializer serializer, Node node) throws IOException {
+ if (node == null) {
+ throw new UnsupportedOperationException("Cannot emit null nodes");
+
+ } else if (node.getNodeType() == Node.ELEMENT_NODE) {
+ Element element = (Element) node;
+ serializer.startTag(element.getNamespaceURI(), element.getLocalName());
+ emitAttributes(serializer, element);
+ emitChildren(serializer, element);
+ serializer.endTag(element.getNamespaceURI(), element.getLocalName());
+
+ } else if (node.getNodeType() == Node.TEXT_NODE
+ || node.getNodeType() == Node.CDATA_SECTION_NODE) {
+ // TODO: is it okay to trim whitespace in general? This may cause
+ // false positives for elements like HTML's <pre> tag
+ String trimmed = node.getTextContent().trim();
+ if (trimmed.length() > 0) {
+ serializer.text(trimmed);
+ }
+
+ } else if (node.getNodeType() == Node.DOCUMENT_NODE) {
+ Document document = (Document) node;
+ serializer.startDocument("UTF-8", true);
+ emitNode(serializer, document.getDocumentElement());
+ serializer.endDocument();
+
+ } else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
+ ProcessingInstruction processingInstruction = (ProcessingInstruction) node;
+ String data = processingInstruction.getData();
+ String target = processingInstruction.getTarget();
+ serializer.processingInstruction(target + " " + data);
+
+ } else if (node.getNodeType() == Node.COMMENT_NODE) {
+ // ignore!
+
+ } else if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
+ EntityReference entityReference = (EntityReference) node;
+ serializer.entityRef(entityReference.getNodeName());
+
+ } else {
+ throw new UnsupportedOperationException(
+ "Cannot emit " + node + " of type " + node.getNodeType());
+ }
+ }
+
+ private void emitAttributes(XmlSerializer serializer, Node node)
+ throws IOException {
+ NamedNodeMap map = node.getAttributes();
+ if (map == null) {
+ return;
+ }
+
+ List<Attr> attributes = new ArrayList<Attr>();
+ for (int i = 0; i < map.getLength(); i++) {
+ attributes.add((Attr) map.item(i));
+ }
+ Collections.sort(attributes, orderByName);
+
+ for (Attr attr : attributes) {
+ if ("xmlns".equals(attr.getPrefix()) || "xmlns".equals(attr.getLocalName())) {
+ /*
+ * Omit namespace declarations because they aren't considered
+ * data. Ie. <foo:a xmlns:bar="http://google.com"> is semantically
+ * equal to <bar:a xmlns:bar="http://google.com"> since the
+ * prefix doesn't matter, only the URI it points to.
+ *
+ * When we omit the prefix, our XML serializer will still
+ * generate one for us, using a predictable pattern.
+ */
+ } else {
+ serializer.attribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getValue());
+ }
+ }
+ }
+
+ private void emitChildren(XmlSerializer serializer, Node node)
+ throws IOException {
+ NodeList childNodes = node.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ emitNode(serializer, childNodes.item(i));
+ }
+ }
+
+ private static List<Element> elementsOf(NodeList nodeList) {
+ List<Element> result = new ArrayList<Element>();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node instanceof Element) {
+ result.add((Element) node);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Reads the given file into a string. If the file contains a byte order
+ * mark, the corresponding character set will be used. Otherwise the system
+ * default charset will be used.
+ */
+ private String fileToString(File file) throws IOException {
+ InputStream in = new BufferedInputStream(new FileInputStream(file), 1024);
+
+ // Read the byte order mark to determine the charset.
+ // TODO: use a built-in API for this...
+ Reader reader;
+ in.mark(3);
+ int byte1 = in.read();
+ int byte2 = in.read();
+ if (byte1 == 0xFF && byte2 == 0xFE) {
+ reader = new InputStreamReader(in, "UTF-16LE");
+ } else if (byte1 == 0xFF && byte2 == 0xFF) {
+ reader = new InputStreamReader(in, "UTF-16BE");
+ } else {
+ int byte3 = in.read();
+ if (byte1 == 0xEF && byte2 == 0xBB && byte3 == 0xBF) {
+ reader = new InputStreamReader(in, "UTF-8");
+ } else {
+ in.reset();
+ reader = new InputStreamReader(in);
+ }
+ }
+
+ StringWriter out = new StringWriter();
+ char[] buffer = new char[1024];
+ int count;
+ while ((count = reader.read(buffer)) != -1) {
+ out.write(buffer, 0, count);
+ }
+ return out.toString();
+ }
+
+ static class ErrorRecorder implements ErrorListener {
+ Exception warning;
+ Exception error;
+
+ public void warning(TransformerException exception) {
+ if (this.warning == null) {
+ this.warning = exception;
+ }
+ }
+
+ public void error(TransformerException exception) {
+ if (this.error == null) {
+ this.error = exception;
+ }
+ }
+
+ public void fatalError(TransformerException exception) {
+ if (this.error == null) {
+ this.error = exception;
+ }
+ }
+ }
+}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java
deleted file mode 100644
index cd3746a..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AllTests.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite for java.util.jar package.
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite(
- "Suite org.apache.harmony.archive.tests.java.util.jar");
- suite.addTestSuite(AttributesNameTest.class);
- suite.addTestSuite(AttributesTest.class);
- suite.addTestSuite(JarEntryTest.class);
- suite.addTestSuite(JarExceptionTest.class);
- suite.addTestSuite(JarExecTest.class);
- suite.addTestSuite(JarFileTest.class);
- suite.addTestSuite(JarInputStreamTest.class);
- suite.addTestSuite(JarOutputStreamTest.class);
- suite.addTestSuite(ManifestTest.class);
- suite.addTestSuite(ZipExecTest.class);
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesNameTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesNameTest.java
deleted file mode 100644
index f390ffd..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesNameTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.util.jar.Attributes;
-import junit.framework.TestCase;
-
-public class AttributesNameTest extends TestCase {
-
- /**
- * @tests java.util.jar.Attributes.Name#Name(java.lang.String)
- */
- public void test_AttributesName_Constructor() {
- // Regression for HARMONY-85
- try {
- new Attributes.Name(
- "01234567890123456789012345678901234567890123456789012345678901234567890");
- fail("Assert 0: should have thrown IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- new Attributes.Name((String) null);
- fail("NullPointerException expected");
- } catch (NullPointerException ee) {
- // expected
- }
-
- assertNotNull(new Attributes.Name("Attr"));
- }
-
- public void test_equalsLjava_lang_Object() {
- Attributes.Name attr1 = new Attributes.Name("Attr");
- Attributes.Name attr2 = new Attributes.Name("Attr");
-
- assertTrue(attr1.equals(attr2));
- attr2 = new Attributes.Name("Attr1");
- assertFalse(attr1.equals(attr2));
- }
-
- public void test_hashCode() {
- Attributes.Name attr1 = new Attributes.Name("Attr1");
- Attributes.Name attr2 = new Attributes.Name("Attr2");
-
- assertNotSame(attr1.hashCode(), attr2.hashCode());
- }
-
- public void test_toString() {
- String str1 = "Attr1";
- String str2 = "Attr2";
- Attributes.Name attr1 = new Attributes.Name(str1);
- Attributes.Name attr2 = new Attributes.Name("Attr2");
-
- assertTrue(attr1.toString().equals(str1));
- assertTrue(attr2.toString().equals(str2));
- assertFalse(attr2.toString().equals(str1));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java
deleted file mode 100644
index a4ac213..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/AttributesTest.java
+++ /dev/null
@@ -1,391 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.jar.Attributes;
-import junit.framework.TestCase;
-
-public class AttributesTest extends TestCase {
- private Attributes a;
-
- @Override
- protected void setUp() {
- a = new Attributes();
- a.putValue("1", "one");
- a.putValue("2", "two");
- a.putValue("3", "three");
- a.putValue("4", "four");
- }
-
- /**
- * @tests java.util.jar.Attributes#Attributes(java.util.jar.Attributes)
- */
- public void test_ConstructorLjava_util_jar_Attributes() {
- Attributes a2 = new Attributes(a);
- assertEquals(a, a2);
- a.putValue("1", "one(1)");
- assertTrue("equal", !a.equals(a2));
- }
-
- /**
- * @tests java.util.jar.Attributes#clear()
- */
- public void test_clear() {
- a.clear();
- assertNull("a) All entries should be null after clear", a.get("1"));
- assertNull("b) All entries should be null after clear", a.get("2"));
- assertNull("c) All entries should be null after clear", a.get("3"));
- assertNull("d) All entries should be null after clear", a.get("4"));
- assertTrue("Should not contain any keys", !a.containsKey("1"));
- }
-
- /**
- * @tests java.util.jar.Attributes#containsKey(java.lang.Object)
- */
- public void test_containsKeyLjava_lang_Object() {
- assertTrue("a) Should have returned false", !a.containsKey(new Integer(
- 1)));
- assertTrue("b) Should have returned false", !a.containsKey("0"));
- assertTrue("Should have returned true", a
- .containsKey(new Attributes.Name("1")));
- }
-
- /**
- * @tests java.util.jar.Attributes#containsValue(java.lang.Object)
- */
- public void test_containsValueLjava_lang_Object() {
- assertTrue("Should have returned false", !a.containsValue("One"));
- assertTrue("Should have returned true", a.containsValue("one"));
- }
-
- /**
- * @tests java.util.jar.Attributes#entrySet()
- */
- public void test_entrySet() {
- Set<Map.Entry<Object, Object>> entrySet = a.entrySet();
- Set<Object> keySet = new HashSet<Object>();
- Set<Object> valueSet = new HashSet<Object>();
- Iterator<?> i;
- assertEquals(4, entrySet.size());
- i = entrySet.iterator();
- while (i.hasNext()) {
- java.util.Map.Entry<?, ?> e;
- e = (Map.Entry<?, ?>) i.next();
- keySet.add(e.getKey());
- valueSet.add(e.getValue());
- }
- assertTrue("a) Should contain entry", valueSet.contains("one"));
- assertTrue("b) Should contain entry", valueSet.contains("two"));
- assertTrue("c) Should contain entry", valueSet.contains("three"));
- assertTrue("d) Should contain entry", valueSet.contains("four"));
- assertTrue("a) Should contain key", keySet
- .contains(new Attributes.Name("1")));
- assertTrue("b) Should contain key", keySet
- .contains(new Attributes.Name("2")));
- assertTrue("c) Should contain key", keySet
- .contains(new Attributes.Name("3")));
- assertTrue("d) Should contain key", keySet
- .contains(new Attributes.Name("4")));
- }
-
- /**
- * @tests java.util.jar.Attributes#get(java.lang.Object)
- */
- public void test_getLjava_lang_Object() {
- assertEquals("a) Incorrect value returned", "one", a.getValue("1"));
- assertNull("b) Incorrect value returned", a.getValue("0"));
-
- try {
- a.getValue("IllegalArgumentException expected");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.jar.Attributes#isEmpty()
- */
- public void test_isEmpty() {
- assertTrue("Should not be empty", !a.isEmpty());
- a.clear();
- assertTrue("a) Should be empty", a.isEmpty());
- a = new Attributes();
- assertTrue("b) Should be empty", a.isEmpty());
- }
-
- /**
- * @tests java.util.jar.Attributes#keySet()
- */
- public void test_keySet() {
- Set<?> s = a.keySet();
- assertEquals(4, s.size());
- assertTrue("a) Should contain entry", s.contains(new Attributes.Name(
- "1")));
- assertTrue("b) Should contain entry", s.contains(new Attributes.Name(
- "2")));
- assertTrue("c) Should contain entry", s.contains(new Attributes.Name(
- "3")));
- assertTrue("d) Should contain entry", s.contains(new Attributes.Name(
- "4")));
- }
-
- /**
- * @tests java.util.jar.Attributes#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map() {
- Attributes b = new Attributes();
- b.putValue("3", "san");
- b.putValue("4", "shi");
- b.putValue("5", "go");
- b.putValue("6", "roku");
- a.putAll(b);
- assertEquals("Should not have been replaced", "one", a.getValue("1"));
- assertEquals("Should have been replaced", "san", a.getValue("3"));
- assertEquals("Should have been added", "go", a.getValue("5"));
- Attributes atts = new Attributes();
- assertNull("Assert 0: ", atts.put(Attributes.Name.CLASS_PATH,
- "tools.jar"));
- assertNull("Assert 1: ", atts
- .put(Attributes.Name.MANIFEST_VERSION, "1"));
- Attributes atts2 = new Attributes();
- atts2.putAll(atts);
- assertEquals("Assert 2:", "tools.jar", atts2
- .get(Attributes.Name.CLASS_PATH));
- assertEquals("Assert 3: ", "1", atts2
- .get(Attributes.Name.MANIFEST_VERSION));
- try {
- atts.putAll(Collections.EMPTY_MAP);
- fail("Assert 4: no class cast from attrib parameter");
- } catch (ClassCastException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.util.jar.Attributes#putAll(java.util.Map)
- */
- public void test_putAllLjava_util_Map2() {
- // Regression for HARMONY-464
- try {
- new Attributes().putAll((Map) null);
- fail("ClassCastException expected");
- } catch (ClassCastException e) {
- }
- // verify that special care for null is done in the Attributes.putAll()
- // method
- try {
- new Attributes() {
- @Override
- public void putAll(Map<?, ?> attrib) {
- map.putAll(attrib);
- }
- }.putAll((Map<?, ?>) null);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.util.jar.Attributes#remove(java.lang.Object)
- */
- public void test_removeLjava_lang_Object() {
- a.remove(new Attributes.Name("1"));
- a.remove(new Attributes.Name("3"));
- assertNull("Should have been removed", a.getValue("1"));
- assertEquals("Should not have been removed", "four", a.getValue("4"));
- }
-
- /**
- * @tests java.util.jar.Attributes#size()
- */
- public void test_size() {
- assertEquals("Incorrect size returned", 4, a.size());
- a.clear();
- assertEquals(0, a.size());
- }
-
- /**
- * @tests java.util.jar.Attributes#values()
- */
- public void test_values() {
- Collection<?> valueCollection = a.values();
- assertTrue("a) Should contain entry", valueCollection.contains("one"));
- assertTrue("b) Should contain entry", valueCollection.contains("two"));
- assertTrue("c) Should contain entry", valueCollection.contains("three"));
- assertTrue("d) Should contain entry", valueCollection.contains("four"));
- }
-
- /**
- * @tests java.util.jar.Attributes#clone()
- */
- public void test_clone() {
- Attributes a2 = (Attributes) a.clone();
- assertEquals(a, a2);
- a.putValue("1", "one(1)");
- assertTrue("equal", !a.equals(a2));
- }
-
- /**
- * @tests java.util.jar.Attributes#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object() {
- Attributes.Name n1 = new Attributes.Name("name"), n2 = new Attributes.Name(
- "Name");
- assertEquals(n1, n2);
- Attributes a1 = new Attributes();
- a1.putValue("one", "1");
- a1.putValue("two", "2");
- Attributes a2 = new Attributes();
- a2.putValue("One", "1");
- a2.putValue("TWO", "2");
- assertEquals(a1, a2);
- }
-
- /**
- * @tests java.util.jar.Attributes.put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object() {
- Attributes atts = new Attributes();
- assertNull("Assert 0: ", atts.put(Attributes.Name.CLASS_PATH,
- "tools.jar"));
- assertEquals("Assert 1: ", "tools.jar", atts
- .getValue(Attributes.Name.CLASS_PATH));
- // Regression for HARMONY-79
- try {
- atts.put("not a name", "value");
- fail("Assert 2: no class cast from key parameter");
- } catch (ClassCastException e) {
- // Expected
- }
- try {
- atts.put(Attributes.Name.CLASS_PATH, Boolean.TRUE);
- fail("Assert 3: no class cast from value parameter");
- } catch (ClassCastException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.util.jar.Attributes.put(java.lang.Object, java.lang.Object)
- */
- public void test_putLjava_lang_ObjectLjava_lang_Object_Null() {
-
- Attributes attribute = new Attributes();
-
- assertFalse(attribute.containsKey(null));
- assertFalse(attribute.containsValue(null));
- attribute.put(null, null);
- attribute.put(null, null);
- assertEquals(1, attribute.size());
- assertTrue(attribute.containsKey(null));
- assertTrue(attribute.containsValue(null));
- assertNull(attribute.get(null));
-
- String value = "It's null";
- attribute.put(null, value);
- assertEquals(1, attribute.size());
- assertEquals(value, attribute.get(null));
-
- Attributes.Name name = new Attributes.Name("null");
- attribute.put(name, null);
- assertEquals(2, attribute.size());
- assertNull(attribute.get(name));
- }
-
- /**
- * @tests java.util.jar.Attributes.hashCode()
- */
- public void test_hashCode_consistent_with_map() {
- MockAttributes mockAttr = new MockAttributes();
- mockAttr.putValue("1", "one");
- assertEquals(mockAttr.getMap().hashCode(), mockAttr.hashCode());
- }
-
- private static class MockAttributes extends Attributes {
- public Map<Object, Object> getMap() {
- return map;
- }
- }
-
- public void test_Constructor() {
- Attributes attr = new Attributes();
- assertTrue(attr.size() >= 0);
- }
-
- public void test_ConstructorI() {
- Attributes attr = new Attributes(10);
- assertTrue(attr.size() >= 0);
- }
-
- public void test_getLjava_lang_Object_true() {
- assertEquals("a) Incorrect value returned", "one", a
- .get(new Attributes.Name("1")));
- assertNull("b) Incorrect value returned", a.get("0"));
- assertNull("b) Incorrect value returned", a.get("1"));
- }
-
- public void test_getValueLjava_util_jar_Attributes_Name() {
- assertEquals("a) Incorrect value returned", "one", a
- .getValue(new Attributes.Name("1")));
- assertNull("b) Incorrect value returned", a
- .getValue(new Attributes.Name("0")));
- }
-
- public void test_hashCode() {
- Attributes b = (Attributes) a.clone();
- b.putValue("33", "Thirty three");
- assertNotSame(a.hashCode(), b.hashCode());
- b = (Attributes) a.clone();
- b.clear();
- assertNotSame(a.hashCode(), b.hashCode());
- }
-
- public void test_putValueLjava_lang_StringLjava_lang_String() {
- Attributes b = new Attributes();
- b.put(new Attributes.Name("1"), "one");
- b.putValue("2", "two");
- b.put(new Attributes.Name("3"), "three");
- b.putValue("4", "four");
-
- assertTrue(a.equals(b));
-
- try {
- b.putValue(null, "null");
- fail("NullPointerException expected");
- } catch (NullPointerException ee) {
- // expected
- }
-
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < 0x10000; i++) {
- sb.append('3');
- }
- try {
- b.putValue(new String(sb), "wrong name");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/DalvikExecTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/DalvikExecTest.java
deleted file mode 100644
index 2df14b4..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/DalvikExecTest.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import junit.framework.TestCase;
-import static tests.support.Support_Exec.execAndGetOutput;
-import tests.support.resource.Support_Resources;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-
-public class DalvikExecTest extends TestCase {
-
- String execDalvik1(String classpath, String mainClass, String arg1)
- throws IOException, InterruptedException {
-
- ProcessBuilder builder = new ProcessBuilder();
-
- String base = System.getenv("OUT");
- builder.command().add(base + "/system/bin/dalvikvm");
-
- builder.command().add("-Djava.io.tmpdir=/tmp/mc");
- builder.command().add("-Duser.language=en");
- builder.command().add("-Duser.region=US");
-
- if ("true".equals(System.getenv("TARGET_SIMULATOR"))) {
- // Test against SIMULATOR:
-// cmdLine.add("-Xmx512M");
-// cmdLine.add("-Xcheck:jni");
- builder.command().add("-Xbootclasspath:" + System.getProperty("java.boot.class.path"));
- } else {
- // Test against EMULATOR:
- }
-
- builder.command().add("-classpath");
- builder.command().add(classpath);
- builder.command().add(mainClass);
-
- if (arg1 != null) {
- builder.command().add(arg1);
- }
-
- return execAndGetOutput(builder);
- }
-
- String execDalvik (String classpath, String mainClass)
- throws IOException, InterruptedException {
- return execDalvik1(classpath, mainClass, null);
- }
-
- // Execute an existing JAR on dalvikvm using -classpath option.",
- public void test_execExistingJar () throws IOException, InterruptedException {
- String res;
- File jarFile;
- if (System.getProperty("java.vendor").contains("Android")) {
- //
- // Test against Android:
- //
- File tempDir = Support_Resources.createTempFolder();
- jarFile = Support_Resources.copyFile(
- tempDir, null, "cts_dalvikExecTest.jar" );
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
- assertEquals("Hello Android World!", "Hello Android World!\n", res);
-
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
- assertTrue("Android Resource Dumper started",
- res.contains("Android Resource Dumper started"));
- assertTrue("This Resource contains some text.",
- res.contains("This Resource contains some text."));
- } else {
- //
- // Test against RI:
- //
- // Do nothing!
- }
- }
-
- // Create a temp file, fill it with contents according to Dalvik JAR format, and execute it on dalvikvm using -classpath option.",
- public void test_execCreatedJar () throws IOException, InterruptedException {
- File jarFile = File.createTempFile("cts_dalvikExecTest_", ".jar");
- jarFile.deleteOnExit();
-
- // Create a JAR output stream on the temp file:
- JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarFile));
-
- // Define the entry for the classes.dex:
- jarOut.putNextEntry(new JarEntry("classes.dex"));
-
- // Fill in the classes.dex contents, i.e. the Dalvik executable code:
- // (See below for the detailed source code contents.)
- Support_Resources.writeResourceToStream("cts_dalvikExecTest_classes.dex", jarOut);
-
- // Now add a resource file:
- //
- jarOut.putNextEntry(new JarEntry("dalvikExecTest/myResource"));
- jarOut.write("This Resource contains some text.".getBytes());
-
- // Close the stream to the completed JAR file.
- jarOut.close();
-
- // The resulting JAR file contains the classes listed at the end of this text,
- // like the 'cts_dalvikExecTest.jar' as part of the resources, too.
-
- String res;
-
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
- assertEquals("Hello Android World!", "Hello Android World!\n", res);
-
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
- assertTrue("Android Resource Dumper started",
- res.contains("Android Resource Dumper started"));
- assertTrue("This Resource contains some text.",
- res.contains("This Resource contains some text."));
- }
-
-
- /**
- * This test does quite the same as test_execCreatedJar, but includes a manifest.
- * Note however that the Dalvik JAR format does not require this manifest.
- * We just test whether the manifest is placed correctly within the JAR by
- * dumping its contents read as a simple text resource.
- * No! We can't do that so easily either, as there are other (parent) JARs
- * with a manifest inside, taken with precedence.
- * So we will reopen the JAR as a JarFile and check the manifest
- * with a top level end-to-end approach.
- */
- public void test_execCreatedJarWithManifest () throws IOException, InterruptedException {
- File jarFile = File.createTempFile("cts_dalvikExecTest_", ".jar");
- jarFile.deleteOnExit();
-
- // Create the manifest:
- Manifest manifest = new Manifest();
- Attributes attrs = manifest.getMainAttributes();
- attrs.put(Attributes.Name.MANIFEST_VERSION, "3.1415962");
- attrs.put(Attributes.Name.MAIN_CLASS, "dalvikExecTest.HelloWorld");
- attrs.put(Attributes.Name.CLASS_PATH, jarFile.getName());
-
- // Create a JAR output stream on the temp file using the manifest:
- JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(jarFile), manifest);
-
- // Define the entry for the classes.dex:
- jarOut.putNextEntry(new JarEntry("classes.dex"));
-
- // Fill in the classes.dex contents, i.e. the Dalvik executable code:
- // (See below for the detailed source code contents.)
- Support_Resources.writeResourceToStream("cts_dalvikExecTest_classes.dex", jarOut);
-
- // Now add a resource file:
- //
- jarOut.putNextEntry(new JarEntry("dalvikExecTest/myResource"));
- jarOut.write("This Resource contains some text.".getBytes());
-
- // Close the stream to the completed JAR file.
- jarOut.close();
-
- // The resulting JAR file contains the classes listed at the end of this text,
- // like the 'cts_dalvikExecTest.jar' as part of the resources, too.
-
- String res;
-
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
- assertEquals("Hello Android World!", "Hello Android World!\n", res);
-
- res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
- assertTrue("Android Resource Dumper started",
- res.contains("Android Resource Dumper started"));
- assertTrue("This Resource contains some text.",
- res.contains("This Resource contains some text."));
-
- // And now reread the manifest:
- //
- JarFile jarIn = new JarFile(jarFile);
- manifest = jarIn.getManifest();
- attrs = manifest.getMainAttributes();
- assertEquals("MANIFEST_VERSION must match!", "3.1415962",
- attrs.get(Attributes.Name.MANIFEST_VERSION));
- assertEquals("MAIN_CLASS must match!", "dalvikExecTest.HelloWorld",
- attrs.get(Attributes.Name.MAIN_CLASS));
- assertEquals("CLASS_PATH must match!", jarFile.getName(),
- attrs.get(Attributes.Name.CLASS_PATH));
- }
-
-
- /*
- * The following two classes are added, here, only for completeness.
- * They form the contents of the dalvikExecTest package contained
- * in the 'cts_dalvikExecTest_classes.dex' resource file.
- */
- /**
- * @hide
- */
- public static class HelloWorld {
-
- public static void main(String[] args) {
- System.out.println("Hello Android World!");
- }
-
- }
-
- public static class ResourceDumper {
-
- static ByteArrayOutputStream outputFrom (InputStream input) throws IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buffer = new byte[512];
- int total = 0;
- int count;
- count = input.read(buffer);
- while (count != -1) {
- out.write(buffer, 0, count);
- total = total + count;
- count = input.read(buffer);
- }
- return out;
- }
-
- public static void main(String[] args) throws IOException {
- System.out.print("Android Resource Dumper started ");
- String fileName;
- if (args.length >= 1) {
- fileName = args[0];
- System.out.format("for argument '%s'.\n", fileName);
- } else {
- System.out.print("standard ");
- fileName = "myResource";
- System.out.println("for standard 'myResource'.");
- }
- InputStream is = ResourceDumper.class.getResourceAsStream(fileName);
- if (is != null) {
- System.out.println("Resource obtained and being dumped:");
- System.out.println(outputFrom(is).toString());
- }
- }
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
deleted file mode 100644
index 47d2a6c..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarEntryTest.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.CodeSigner;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.zip.ZipEntry;
-import junit.framework.TestCase;
-import tests.support.resource.Support_Resources;
-
-
-public class JarEntryTest extends TestCase {
- private ZipEntry zipEntry;
-
- private JarEntry jarEntry;
-
- private JarFile jarFile;
-
- private final String jarName = "hyts_patch.jar";
-
- private final String entryName = "foo/bar/A.class";
-
- private final String entryName2 = "Blah.txt";
-
- private final String attJarName = "hyts_att.jar";
-
- private final String attEntryName = "HasAttributes.txt";
-
- private final String attEntryName2 = "NoAttributes.txt";
-
- private File resources;
-
- @Override
- protected void setUp() throws Exception {
- resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, jarName);
- jarFile = new JarFile(new File(resources, jarName));
- }
-
- @Override
- protected void tearDown() throws Exception {
- if (jarFile != null) {
- jarFile.close();
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.jar.JarEntry#JarEntry(java.util.jar.JarEntry)
- */
- public void test_ConstructorLjava_util_jar_JarEntry_on_null() throws IOException {
- JarEntry newJarEntry = new JarEntry(jarFile.getJarEntry(entryName));
- assertNotNull(newJarEntry);
-
- jarEntry = null;
- try {
- newJarEntry = new JarEntry(jarEntry);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.util.jar.JarEntry#JarEntry(java.util.zip.ZipEntry)
- */
- public void test_ConstructorLjava_util_zip_ZipEntry() {
- assertNotNull("Jar file is null", jarFile);
- zipEntry = jarFile.getEntry(entryName);
- assertNotNull("Zip entry is null", zipEntry);
- jarEntry = new JarEntry(zipEntry);
- assertNotNull("Jar entry is null", jarEntry);
- assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
- .getName());
- assertEquals("Wrong entry constructed--wrong size", 311, jarEntry
- .getSize());
- }
-
- /**
- * @tests java.util.jar.JarEntry#getAttributes()
- */
- public void test_getAttributes() {
- JarFile attrJar = null;
- File file = null;
- try {
- Support_Resources.copyFile(resources, null, attJarName);
- file = new File(resources, attJarName);
- attrJar = new JarFile(file);
- } catch (Exception e) {
- assertTrue(file + " does not exist", file.exists());
- fail("Exception opening file: " + e.toString());
- }
- try {
- jarEntry = attrJar.getJarEntry(attEntryName);
- assertNotNull("Should have Manifest attributes", jarEntry
- .getAttributes());
- } catch (Exception e) {
- fail("Exception during 2nd test: " + e.toString());
- }
- try {
- jarEntry = attrJar.getJarEntry(attEntryName2);
- assertNull("Shouldn't have any Manifest attributes", jarEntry
- .getAttributes());
- attrJar.close();
- } catch (Exception e) {
- fail("Exception during 1st test: " + e.toString());
- }
-
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- try {
- attrJar = new JarFile(new File(resources, "Broken_manifest.jar"));
- jarEntry = attrJar.getJarEntry("META-INF/");
- jarEntry.getAttributes();
- fail("IOException expected");
- } catch (IOException e) {
- // expected.
- }
- }
-
- /**
- * @tests java.util.jar.JarEntry#getCertificates()
- */
- public void test_getCertificates() throws Exception {
- zipEntry = jarFile.getEntry(entryName2);
- jarEntry = new JarEntry(zipEntry);
- assertNull("Shouldn't have any Certificates", jarEntry
- .getCertificates());
-
- // Regression Test for HARMONY-3424
- String jarFileName = "TestCodeSigners.jar";
- Support_Resources.copyFile(resources, null, jarFileName);
- File file = new File(resources, jarFileName);
- JarFile jarFile = new JarFile(file);
- JarEntry jarEntry1 = jarFile.getJarEntry("Test.class");
- JarEntry jarEntry2 = jarFile.getJarEntry("Test.class");
- InputStream in = jarFile.getInputStream(jarEntry1);
- byte[] buffer = new byte[1024];
- // BEGIN android-changed
- // the certificates are non-null too early and in.available() fails
- // while (in.available() > 0) {
- // assertNull("getCertificates() should be null until the entry is read",
- // jarEntry1.getCertificates());
- // assertNull(jarEntry2.getCertificates());
- // in.read(buffer);
- // }
- while (in.read(buffer) >= 0);
- in.close();
- // END android-changed
- assertEquals("the file is fully read", -1, in.read());
- assertNotNull(jarEntry1.getCertificates());
- assertNotNull(jarEntry2.getCertificates());
- in.close();
- }
-
- /**
- * @tests java.util.jar.JarEntry#getCodeSigners()
- */
- public void test_getCodeSigners() throws IOException {
- String jarFileName = "TestCodeSigners.jar";
- Support_Resources.copyFile(resources, null, jarFileName);
- File file = new File(resources, jarFileName);
- JarFile jarFile = new JarFile(file);
- JarEntry jarEntry = jarFile.getJarEntry("Test.class");
- InputStream in = jarFile.getInputStream(jarEntry);
- byte[] buffer = new byte[1024];
- while (in.available() > 0) {
- // BEGIN android-changed
- // the code signers are non-null too early
- // assertNull("getCodeSigners() should be null until the entry is read",
- // jarEntry.getCodeSigners());
- // END android-changed
- in.read(buffer);
- }
- assertEquals("the file is fully read", -1, in.read());
- CodeSigner[] codeSigners = jarEntry.getCodeSigners();
- assertEquals(2, codeSigners.length);
- List<?> certs_bob = codeSigners[0].getSignerCertPath()
- .getCertificates();
- List<?> certs_alice = codeSigners[1].getSignerCertPath()
- .getCertificates();
- if (1 == certs_bob.size()) {
- List<?> temp = certs_bob;
- certs_bob = certs_alice;
- certs_alice = temp;
- }
- assertEquals(2, certs_bob.size());
- assertEquals(1, certs_alice.size());
- assertNull(
- "getCodeSigners() of a primitive JarEntry should return null",
- new JarEntry("aaa").getCodeSigners());
- }
-
- public void test_ConstructorLjava_lang_String() {
- assertNotNull("Jar file is null", jarFile);
- zipEntry = jarFile.getEntry(entryName);
- assertNotNull("Zip entry is null", zipEntry);
- jarEntry = new JarEntry(entryName);
- assertNotNull("Jar entry is null", jarEntry);
- assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
- .getName());
- try {
- jarEntry = new JarEntry((String) null);
- fail("NullPointerException expected");
- } catch (NullPointerException ee) {
- // expected
- }
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < 0x10000; i++) {
- sb.append('3');
- }
- try {
- jarEntry = new JarEntry(new String(sb));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- }
-
- public void test_ConstructorLjava_util_jar_JarEntry() {
- assertNotNull("Jar file is null", jarFile);
- JarEntry je = jarFile.getJarEntry(entryName);
- assertNotNull("Jar entry is null", je);
- jarEntry = new JarEntry(je);
- assertNotNull("Jar entry is null", jarEntry);
- assertEquals("Wrong entry constructed--wrong name", entryName, jarEntry
- .getName());
- assertEquals("Wrong entry constructed--wrong size", 311, jarEntry
- .getSize());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java
deleted file mode 100644
index a23837e..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExceptionTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.jar.Manifest;
-import junit.framework.TestCase;
-import java.util.jar.JarException;
-
-public class JarExceptionTest extends TestCase {
- /**
- * @tests java.util.jar.JarException#JarException(java.lang.String)
- */
- public void test_Constructor() throws Exception {
- JarException ex = new JarException();
- JarException ex1 = new JarException("Test string");
- JarException ex2 = new JarException(null);
- assertNotSame(ex, ex1);
- assertNotSame(ex.getMessage(), ex1.getMessage());
- assertNotSame(ex, ex2);
- assertSame(ex.getMessage(), ex2.getMessage());
- }
-
- public void test_ConstructorLjava_lang_String() throws Exception {
- JarException ex1 = new JarException("Test string");
- JarException ex2 = new JarException(null);
- assertNotSame(ex1, ex2);
- assertNotSame(ex1.getMessage(), ex2.getMessage());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExecTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExecTest.java
deleted file mode 100644
index e70bb87..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarExecTest.java
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with this
- * work for additional information regarding copyright ownership. The ASF
- * licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import static tests.support.Support_Exec.execAndGetOutput;
-import static tests.support.Support_Exec.javaProcessBuilder;
-import tests.support.resource.Support_Resources;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-
-/**
- *
- * tests for various cases of java -jar ... execution
- *
- */
-
-public class JarExecTest extends junit.framework.TestCase {
- /**
- * regression test for HARMONY-1562 issue
- *
- */
- public void test_1562() throws Exception {
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
-
- File outputJar = File.createTempFile("hyts_", ".jar");
- outputJar.deleteOnExit();
- JarOutputStream jout = new JarOutputStream(new FileOutputStream(
- outputJar), man);
- File resources = Support_Resources.createTempFolder();
-
- for (String jarClass : new String[] {"Foo", "Bar"}) {
- jout.putNextEntry(new JarEntry("foo/bar/execjartest/" + jarClass
- + ".class"));
- jout.write(getResource(resources, "hyts_" + jarClass + ".ser"));
- }
-
- jout.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(outputJar.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
- /**
- * tests Class-Path entry in manifest
- *
- * @throws Exception in case of troubles
- */
- public void test_jar_class_path() throws Exception {
- File fooJar = File.createTempFile("hyts_", ".jar");
- File barJar = File.createTempFile("hyts_", ".jar");
- fooJar.deleteOnExit();
- barJar.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, barJar.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- JarOutputStream joutFoo = new JarOutputStream(new FileOutputStream(
- fooJar), man);
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.close();
-
- JarOutputStream joutBar = new JarOutputStream(new FileOutputStream(
- barJar));
- joutBar.putNextEntry(new JarEntry("foo/bar/execjartest/Bar.class"));
- joutBar.write(getResource(resources, "hyts_Bar.ser"));
- joutBar.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(fooJar.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
-
- // rewrite manifest so it contains not only reference to bar but useless
- // entries as well
- att.put(Attributes.Name.CLASS_PATH, "xx yy zz " + barJar.getName());
- joutFoo = new JarOutputStream(new FileOutputStream(fooJar), man);
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.close();
- // execute the JAR and read the result
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith( "FOOBAR"));
-
- // play with relative file names - put relative path as ../<parent dir
- // name>/xx.jar
- att.put(Attributes.Name.CLASS_PATH, ".." + File.separator
- + barJar.getParentFile().getName() + File.separator
- + barJar.getName());
- joutFoo = new JarOutputStream(new FileOutputStream(fooJar), man);
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.close();
- // execute the JAR and read the result
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith( "FOOBAR"));
- }
-
- /**
- * tests case when Main-Class is not in the jar launched but in another jar
- * referenced by Class-Path
- *
- * @throws Exception in case of troubles
- */
- public void test_main_class_in_another_jar() throws Exception {
- File fooJar = File.createTempFile("hyts_", ".jar");
- File barJar = File.createTempFile("hyts_", ".jar");
- fooJar.deleteOnExit();
- barJar.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, fooJar.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- JarOutputStream joutFoo = new JarOutputStream(new FileOutputStream(
- fooJar));
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.close();
-
- JarOutputStream joutBar = new JarOutputStream(new FileOutputStream(
- barJar), man);
- joutBar.putNextEntry(new JarEntry("foo/bar/execjartest/Bar.class"));
- joutBar.write(getResource(resources, "hyts_Bar.ser"));
- joutBar.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(barJar.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
- public void test_classpath() throws Exception {
- File resources = Support_Resources.createTempFolder();
-
- File fooJar = File.createTempFile("hyts_", ".jar");
- fooJar.deleteOnExit();
-
- JarOutputStream joutFoo = new JarOutputStream(new FileOutputStream(
- fooJar));
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Bar.class"));
- joutFoo.write(getResource(resources, "hyts_Bar.ser"));
- joutFoo.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.environment().put("CLASSPATH", fooJar.getAbsolutePath());
- builder.command().add("foo.bar.execjartest.Foo");
-
- assertTrue("Error executing class from ClassPath",
- execAndGetOutput(builder).startsWith("FOOBAR"));
-
- // ok - next try - add -cp to path - it should override env
- File booJar = File.createTempFile("hyts_", ".jar");
- booJar.deleteOnExit();
-
- JarOutputStream joutBoo = new JarOutputStream(new FileOutputStream(
- booJar));
- joutBoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- String booBody = new String(getResource(resources, "hyts_Foo.ser"),
- "iso-8859-1");
- booBody = booBody.replaceFirst("FOO", "BOO");
- joutBoo.write(booBody.getBytes("iso-8859-1"));
- joutBoo.putNextEntry(new JarEntry("foo/bar/execjartest/Bar.class"));
- String farBody = new String(getResource(resources, "hyts_Bar.ser"),
- "iso-8859-1");
- farBody = farBody.replaceFirst("BAR", "FAR");
- joutBoo.write(farBody.getBytes("iso-8859-1"));
- joutBoo.close();
-
- builder = javaProcessBuilder();
- builder.environment().put("CLASSPATH", fooJar.getAbsolutePath());
- builder.command().add("-cp");
- builder.command().add(booJar.getAbsolutePath());
- builder.command().add("foo.bar.execjartest.Foo");
-
- assertTrue("Error executing class specified by -cp",
- execAndGetOutput(builder).startsWith("BOOFAR"));
-
- // now add -jar option - it should override env and classpath
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
-
- File zooJar = File.createTempFile("hyts_", ".jar");
- zooJar.deleteOnExit();
-
- JarOutputStream joutZoo = new JarOutputStream(new FileOutputStream(
- zooJar), man);
- joutZoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- String zooBody = new String(getResource(resources, "hyts_Foo.ser"),
- "iso-8859-1");
- zooBody = zooBody.replaceFirst("FOO", "ZOO");
- joutZoo.write(zooBody.getBytes("iso-8859-1"));
- joutZoo.putNextEntry(new JarEntry("foo/bar/execjartest/Bar.class"));
- String zarBody = new String(getResource(resources, "hyts_Bar.ser"),
- "iso-8859-1");
- zarBody = zarBody.replaceFirst("BAR", "ZAR");
- joutZoo.write(zarBody.getBytes("iso-8859-1"));
- joutZoo.close();
-
- builder = javaProcessBuilder();
- builder.environment().put("CLASSPATH", fooJar.getAbsolutePath());
- builder.command().add("-cp");
- builder.command().add(booJar.getAbsolutePath());
- builder.command().add("-jar");
- builder.command().add(zooJar.getAbsolutePath());
-
- assertTrue("Error executing class specified by -jar",
- execAndGetOutput(builder).startsWith("ZOOZAR"));
- }
-
- private static byte[] getResource(File tempDir, String resourceName)
- throws IOException {
- Support_Resources.copyFile(tempDir, null, resourceName);
- File resourceFile = new File(tempDir, resourceName);
- resourceFile.deleteOnExit();
-
- // read whole resource data into memory
- byte[] resourceBody = new byte[(int) resourceFile.length()];
- FileInputStream fis = new FileInputStream(resourceFile);
- fis.read(resourceBody);
- fis.close();
-
- return resourceBody;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java
deleted file mode 100644
index b41a212..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarInputStreamTest.java
+++ /dev/null
@@ -1,533 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import tests.support.resource.Support_Resources;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-
-public class JarInputStreamTest extends junit.framework.TestCase {
- // a 'normal' jar file
- private String jarName;
-
- // same as patch.jar but without a manifest file
- private String jarName2;
-
- private final String entryName = "foo/bar/A.class";
-
- private static final int indexofDSA = 2;
-
- private static final int indexofTESTCLASS = 4;
-
- private static final int totalEntries = 4;
-
- @Override
- protected void setUp() {
- jarName = Support_Resources.getURL("morestuff/hyts_patch.jar");
- jarName2 = Support_Resources.getURL("morestuff/hyts_patch2.jar");
- }
-
- /**
- * @tests java.util.jar.JarInputStream#JarInputStream(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.util.jar.JarInputStream(java.io.InputStream)
- InputStream is = null;
- JarInputStream jis = null;
- try {
- is = new URL(jarName).openConnection().getInputStream();
- boolean hasCorrectEntry = false;
- jis = new JarInputStream(is);
- assertNotNull("The jar input stream should have a manifest", jis
- .getManifest());
- JarEntry je = jis.getNextJarEntry();
- while (je != null) {
- if (je.getName().equals(entryName)) {
- hasCorrectEntry = true;
- }
- je = jis.getNextJarEntry();
- }
- assertTrue(
- "The jar input stream does not contain the correct entries",
- hasCorrectEntry);
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
-
- try {
- is.close();
- jis = new JarInputStream(is);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.jar.JarInputStream#getManifest()
- */
- public void test_getManifest() {
- // Test for method java.util.jar.Manifest
- // java.util.jar.JarInputStream.getManifest()
- try {
- Manifest m;
-
- InputStream is = new URL(jarName2).openConnection()
- .getInputStream();
- JarInputStream jis = new JarInputStream(is);
- m = jis.getManifest();
- assertNull("The jar input stream should not have a manifest", m);
-
- is = new URL(jarName).openConnection().getInputStream();
- jis = new JarInputStream(is);
- m = jis.getManifest();
- assertNotNull("The jar input stream should have a manifest", m);
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
-
- }
-
- /**
- * @tests java.util.jar.JarInputStream#getNextJarEntry()
- */
- public void test_getNextJarEntry() throws Exception {
- final Set<String> desired = new HashSet<String>(Arrays
- .asList(new String[] {
- "foo/", "foo/bar/", "foo/bar/A.class", "Blah.txt"}));
- Set<String> actual = new HashSet<String>();
- InputStream is = new URL(jarName).openConnection().getInputStream();
- JarInputStream jis = new JarInputStream(is);
- JarEntry je = jis.getNextJarEntry();
- while (je != null) {
- actual.add(je.toString());
- je = jis.getNextJarEntry();
- }
- assertEquals(actual, desired);
- jis.close();
-
- try {
- jis.getNextJarEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry.jar");
- is = Support_Resources.getStream("Broken_entry.jar");
- jis = new JarInputStream(is, false);
- jis.getNextJarEntry();
- try {
- jis.getNextJarEntry();
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
- }
-
- public void test_getNextJarEntry_Ex() throws Exception {
- final Set<String> desired = new HashSet<String>(Arrays
- .asList("foo/", "foo/bar/", "foo/bar/A.class", "Blah.txt"));
- Set<String> actual = new HashSet<String>();
- InputStream is = new URL(jarName).openConnection().getInputStream();
- JarInputStream jis = new JarInputStream(is);
- JarEntry je = jis.getNextJarEntry();
- while (je != null) {
- actual.add(je.toString());
- je = jis.getNextJarEntry();
- }
- assertEquals(actual, desired);
- jis.close();
-
- try {
- jis.getNextJarEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry.jar");
- is = Support_Resources.getStream("Broken_entry.jar");
- jis = new JarInputStream(is, false);
- jis.getNextJarEntry();
- try {
- jis.getNextJarEntry();
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
- }
-
- public void test_JarInputStream_Integrate_Jar_getNextEntry()
- throws IOException {
- String intJarName = Support_Resources.getURL("Integrate.jar");
- InputStream is = new URL(intJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- ZipEntry entry = null;
- int count = 0;
- while (count == 0 || entry != null) {
- count++;
- entry = jin.getNextEntry();
- }
- assertEquals(totalEntries + 1, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_Class_getNextEntry()
- throws IOException {
- String modJarName = Support_Resources.getURL("Modified_Class.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- ZipEntry zipEntry = null;
-
- int count = 0;
- while (count == 0 || zipEntry != null) {
- count++;
- try {
- zipEntry = jin.getNextEntry();
- if (count == indexofTESTCLASS + 1) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count != indexofTESTCLASS + 1) {
- throw e;
- }
-
- }
- }
- assertEquals(totalEntries + 2, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_Manifest_MainAttributes_getNextEntry()
- throws IOException {
- String modJarName = Support_Resources.getURL("Modified_Manifest_MainAttributes.jar");
- InputStream is = new URL(modJarName).openConnection()
- .getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
-
- assertEquals("META-INF/TESTROOT.SF", jin.getNextEntry().getName());
- assertEquals("META-INF/TESTROOT.DSA", jin.getNextEntry().getName());
- try {
- jin.getNextEntry();
- fail();
- } catch (SecurityException expected) {
- }
- assertEquals("META-INF/", jin.getNextEntry().getName());
- assertEquals("Test.class", jin.getNextEntry().getName());
- assertNull(jin.getNextEntry());
- jin.close();
- }
-
- public void test_JarInputStream_Modified_Manifest_EntryAttributes_getNextEntry()
- throws IOException {
- String modJarName = Support_Resources
- .getURL("Modified_Manifest_EntryAttributes.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- ZipEntry zipEntry = null;
-
- int count = 0;
- while (count == 0 || zipEntry != null) {
- count++;
- try {
- zipEntry = jin.getNextEntry();
- if (count == indexofDSA + 1) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count != indexofDSA + 1) {
- throw e;
- }
- }
- }
- assertEquals(totalEntries + 2, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_SF_EntryAttributes_getNextEntry()
- throws IOException {
- String modJarName = Support_Resources
- .getURL("Modified_SF_EntryAttributes.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- ZipEntry zipEntry = null;
-
- int count = 0;
- while (count == 0 || zipEntry != null) {
- count++;
- try {
- zipEntry = jin.getNextEntry();
- if (count == indexofDSA + 1) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count != indexofDSA + 1) {
- throw e;
- }
- }
- }
- assertEquals(totalEntries + 2, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_Class_read() throws IOException {
- String modJarName = Support_Resources.getURL("Modified_Class.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- int count = 0;
- ZipEntry zipEntry = null;
- while (count == 0 || zipEntry != null) {
- count++;
- zipEntry = jin.getNextEntry();
- byte[] buffer = new byte[1024];
- try {
- int length = 0;
- while (length >= 0) {
- length = jin.read(buffer);
- }
- if (count == indexofTESTCLASS) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count < indexofTESTCLASS) {
- throw e;
- }
- }
- }
- assertEquals(totalEntries + 1, count);
- jin.close();
- }
-
- public void test_Integrate_Jar_read() throws IOException {
- String intJarName = Support_Resources.getURL("Integrate.jar");
- InputStream is = new URL(intJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- int count = 0;
- ZipEntry zipEntry = null;
- while (count == 0 || zipEntry != null) {
- count++;
- zipEntry = jin.getNextEntry();
- byte[] buffer = new byte[1024];
- int length = 0;
- while (length >= 0) {
- length = jin.read(buffer);
- }
-
- }
- assertEquals(totalEntries + 1, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_Manifest_MainAttributes_read()
- throws IOException {
- String modJarName = Support_Resources
- .getURL("Modified_Manifest_MainAttributes.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- int count = 0;
- ZipEntry zipEntry = null;
- while (count == 0 || zipEntry != null) {
- count++;
- zipEntry = jin.getNextEntry();
- byte[] buffer = new byte[1024];
- try {
- int length = 0;
- while (length >= 0) {
- length = jin.read(buffer);
- }
- if (count == indexofDSA) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count != indexofDSA) {
- throw e;
- }
- }
- }
- assertEquals(totalEntries + 1, count);
- jin.close();
- }
-
- public void test_JarInputStream_Modified_SF_EntryAttributes_read()
- throws IOException {
- String modJarName = Support_Resources
- .getURL("Modified_SF_EntryAttributes.jar");
- InputStream is = new URL(modJarName).openConnection().getInputStream();
- JarInputStream jin = new JarInputStream(is, true);
- int count = 0;
- ZipEntry zipEntry = null;
- while (count == 0 || zipEntry != null) {
- count++;
- zipEntry = jin.getNextEntry();
- byte[] buffer = new byte[1024];
- try {
- int length = 0;
- while (length >= 0) {
- length = jin.read(buffer);
- }
- if (count == indexofDSA) {
- fail("Should throw Security Exception");
- }
- } catch (SecurityException e) {
- if (count != indexofDSA) {
- throw e;
- }
- }
- }
- assertEquals(totalEntries + 1, count);
- jin.close();
- }
-
- public void test_ConstructorLjava_io_InputStreamZ() {
- // Test for method java.util.jar.JarInputStream(java.io.InputStream)
- InputStream is = null;
- JarInputStream jis = null;
- try {
- is = new URL(jarName).openConnection().getInputStream();
- boolean hasCorrectEntry = false;
- jis = new JarInputStream(is, true);
- assertNotNull("The jar input stream should have a manifest", jis
- .getManifest());
- JarEntry je = jis.getNextJarEntry();
- while (je != null) {
- if (je.getName().equals(entryName)) {
- hasCorrectEntry = true;
- }
- je = jis.getNextJarEntry();
- }
- assertTrue(
- "The jar input stream does not contain the correct entries",
- hasCorrectEntry);
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
-
- try {
- is.close();
- jis = new JarInputStream(is, false);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- public void test_closeAfterException() throws Exception {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry.jar");
- InputStream is = Support_Resources.getStream("Broken_entry.jar");
- JarInputStream jis = new JarInputStream(is, false);
- jis.getNextEntry();
- try {
- jis.getNextEntry();
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
- jis.close();
- try {
- jis.getNextEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- public void test_getNextEntry() throws Exception {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry.jar");
- InputStream is = Support_Resources.getStream("Broken_entry.jar");
- JarInputStream jis = new JarInputStream(is, false);
- jis.getNextEntry();
- try {
- jis.getNextEntry();
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- try {
- jis.close(); // Android throws exception here, already!
- jis.getNextEntry(); // But RI here, only!
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- class Mock_JarInputStream extends JarInputStream {
-
- public Mock_JarInputStream(InputStream in) throws IOException {
- super(in);
- }
-
- public ZipEntry createZipEntry(String str) {
- return super.createZipEntry(str);
- }
- }
-
- public void test_createZipEntryLjava_lang_String() throws Exception {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry.jar");
- InputStream is = Support_Resources.getStream("Broken_entry.jar");
- Mock_JarInputStream mjis = new Mock_JarInputStream(is);
- assertNotNull(mjis.createZipEntry("New entry"));
- }
-
- public void test_read$ZII() throws Exception {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_entry_data.jar");
- InputStream is = Support_Resources.getStream("Broken_entry_data.jar");
- JarInputStream jis = new JarInputStream(is, true);
- byte b[] = new byte[100];
-
- jis.getNextEntry();
- jis.read(b, 0, 100);
- jis.getNextEntry();
- jis.getNextEntry();
- jis.getNextEntry();
-
- try {
- jis.read(b, 0, 100);
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- try {
- jis.close(); // Android throws exception here, already!
- jis.read(b, 0, 100); // But RI here, only!
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java
deleted file mode 100644
index 678ec73..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/JarOutputStreamTest.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-
-import tests.support.resource.Support_Resources;
-
-public class JarOutputStreamTest extends junit.framework.TestCase {
-
- /**
- * @tests java.util.jar.JarOutputStream#putNextEntry(java.util.zip.ZipEntry)
- */
- public void test_putNextEntryLjava_util_zip_ZipEntry() throws Exception {
- // testClass file`s actual extension is .class, since having .class
- // extension files in source dir causes
- // problems on eclipse, the extension is changed into .ser or it can be
- // anything. The file is being
- // read by inputstream and being written to other file,
- // as long as the content of the file is not changed, the extension does
- // not matter
- final String testClass = "hyts_mainClass.ser";
- final String entryName = "foo/bar/execjartest/MainClass.class";
-
- // test whether specifying the main class in the manifest
- // works using either /'s or .'s as a separator
- final String[] manifestMain = {
- "foo.bar.execjartest.MainClass",
- "foo/bar/execjartest/MainClass"};
-
- for (String element : manifestMain) {
-
- // create the manifest
- Manifest newman = new Manifest();
- Attributes att = newman.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, element);
-
- File outputJar = null;
- JarOutputStream jout = null;
-
- // open the output jarfile
- outputJar = File.createTempFile("hyts_", ".jar");
- jout = new JarOutputStream(new FileOutputStream(outputJar),
- newman);
- jout.putNextEntry(new JarEntry(entryName));
-
- File resources = Support_Resources.createTempFolder();
-
- // read in the class file, and output it to the jar
- Support_Resources.copyFile(resources, null, testClass);
- URL jarURL = new URL((new File(resources, testClass)).toURL()
- .toString());
- InputStream jis = jarURL.openStream();
-
- byte[] bytes = new byte[1024];
- int len;
- while ((len = jis.read(bytes)) != -1) {
- jout.write(bytes, 0, len);
- }
-
- jout.flush();
- jout.close();
- jis.close();
-
- String res = null;
- // set up the VM parameters
- String[] args = new String[2];
- args[0] = "-jar";
- args[1] = outputJar.getAbsolutePath();
-
-// It's not that simple to execute a JAR against Dalvik VM (see DalvikExecTest):
-//
-// try {
-// // execute the JAR and read the result
-// res = Support_Exec.execJava(args, null, true);
-// } catch (Exception e) {
-// fail("Exception executing test JAR: " + e);
-// }
-//
-// assertTrue("Error executing JAR test on: " + element
-// + ". Result returned was incorrect.", res
-// .startsWith("TEST"));
- outputJar.delete();
-
- try {
- // open the output jarfile
- outputJar = File.createTempFile("hyts_", ".jar");
- OutputStream os = new FileOutputStream(outputJar);
- jout = new JarOutputStream(os, newman);
- os.close();
- jout.putNextEntry(new JarEntry(entryName));
- fail("IOException expected");
- } catch (IOException e) {
- // expected
- }
- }
- }
-
- public void test_JarOutputStreamLjava_io_OutputStreamLjava_util_jar_Manifest()
- throws IOException {
- File fooJar = File.createTempFile("hyts_", ".jar");
- File barZip = File.createTempFile("hyts_", ".zip");
-
- FileOutputStream fos = new FileOutputStream(fooJar);
-
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, barZip.getName());
-
- fos.close();
- try {
- JarOutputStream joutFoo = new JarOutputStream(fos, man);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- public void test_JarOutputStreamLjava_io_OutputStream() throws IOException {
- File fooJar = File.createTempFile("hyts_", ".jar");
-
- FileOutputStream fos = new FileOutputStream(fooJar);
- ZipEntry ze = new ZipEntry("Test");
-
- try {
- JarOutputStream joutFoo = new JarOutputStream(fos);
- joutFoo.putNextEntry(ze);
- joutFoo.write(33);
- } catch (IOException ee) {
- fail("IOException is not expected");
- }
-
- fos.close();
- fooJar.delete();
- try {
- JarOutputStream joutFoo = new JarOutputStream(fos);
- joutFoo.putNextEntry(ze);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
deleted file mode 100644
index aafda90..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ManifestTest.java
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.util.Map;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
-import junit.framework.TestCase;
-
-import tests.support.resource.Support_Resources;
-
-public class ManifestTest extends TestCase {
-
- private final String jarName = "hyts_patch.jar";
-
- private final String attJarName = "hyts_att.jar";
-
- private Manifest m;
-
- private Manifest m2;
-
- private final String ATT_ENTRY_NAME = "HasAttributes.txt";
-
- private final String MANIFEST_NAME = "manifest/hyts_MANIFEST.MF";
-
- private File resources;
-
- @Override
- protected void setUp() {
- resources = Support_Resources.createTempFolder();
- try {
- Support_Resources.copyFile(resources, null, jarName);
- JarFile jarFile = new JarFile(new File(resources, jarName));
- m = jarFile.getManifest();
- jarFile.close();
- Support_Resources.copyFile(resources, null, attJarName);
- jarFile = new JarFile(new File(resources, attJarName));
- m2 = jarFile.getManifest();
- jarFile.close();
- } catch (Exception e) {
- fail("Exception during setup: " + e.toString());
- }
- }
-
- private Manifest getManifest(String fileName) {
- try {
- Support_Resources.copyFile(resources, null, fileName);
- JarFile jarFile = new JarFile(new File(resources, fileName));
- Manifest m = jarFile.getManifest();
- jarFile.close();
- return m;
- } catch (Exception e) {
- fail("Exception during setup: " + e.toString());
- return null;
- }
- }
-
- /**
- * @tests java.util.jar.Manifest#Manifest()
- */
- public void test_Constructor() {
- // Test for method java.util.jar.Manifest()
- Manifest emptyManifest = new Manifest();
- assertTrue("Should have no entries", emptyManifest.getEntries()
- .isEmpty());
- assertTrue("Should have no main attributes", emptyManifest
- .getMainAttributes().isEmpty());
- }
-
- /**
- * @tests java.util.jar.Manifest#Manifest(java.util.jar.Manifest)
- */
- public void testCopyingConstructor() throws IOException {
- Manifest firstManifest = new Manifest(new URL(Support_Resources
- .getURL(MANIFEST_NAME)).openStream());
- Manifest secondManifest = new Manifest(firstManifest);
- assertEquals(firstManifest, secondManifest);
- }
-
- /**
- * @tests java.util.jar.Manifest#Manifest(Manifest)
- */
- public void test_ConstructorLjava_util_jar_Manifest() {
- // Test for method java.util.jar.Manifest()
- Manifest emptyManifest = new Manifest();
- Manifest emptyClone = new Manifest(emptyManifest);
- assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
- assertTrue("Should have no main attributes", emptyClone
- .getMainAttributes().isEmpty());
- assertEquals(emptyClone, emptyManifest);
- assertEquals(emptyClone, emptyManifest.clone());
- }
-
- private void assertAttribute(Attributes attr, String name, String value) {
- assertEquals("Incorrect " + name, value, attr.getValue(name));
- }
-
- private void checkManifest(Manifest manifest) {
- Attributes main = manifest.getMainAttributes();
- assertAttribute(main, "Bundle-Name", "ClientSupport");
- assertAttribute(main, "Bundle-Description",
- "Provides SessionService, AuthenticationService. Extends RegistryService.");
- assertAttribute(main, "Bundle-Activator",
- "com.ibm.ive.eccomm.client.support.ClientSupportActivator");
- assertAttribute(
- main,
- "Import-Package",
- "com.ibm.ive.eccomm.client.services.log,com.ibm.ive.eccomm.client.services.registry,com.ibm.ive.eccomm.service.registry; specification-version=1.0.0,com.ibm.ive.eccomm.service.session; specification-version=1.0.0,com.ibm.ive.eccomm.service.framework; specification-version=1.2.0,org.osgi.framework; specification-version=1.0.0,org.osgi.service.log; specification-version=1.0.0,com.ibm.ive.eccomm.flash; specification-version=1.2.0,com.ibm.ive.eccomm.client.xml,com.ibm.ive.eccomm.client.http.common,com.ibm.ive.eccomm.client.http.client");
- assertAttribute(
- main,
- "Import-Service",
- "org.osgi.service.log.LogReaderServiceorg.osgi.service.log.LogService,com.ibm.ive.eccomm.service.registry.RegistryService");
- assertAttribute(
- main,
- "Export-Package",
- "com.ibm.ive.eccomm.client.services.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.service.authentication; specification-version=1.0.0,com.ibm.ive.eccomm.common; specification-version=1.0.0,com.ibm.ive.eccomm.client.services.registry.store; specification-version=1.0.0");
- assertAttribute(
- main,
- "Export-Service",
- "com.ibm.ive.eccomm.service.authentication.AuthenticationService,com.ibm.ive.eccomm.service.session.SessionService");
- assertAttribute(main, "Bundle-Vendor", "IBM");
- assertAttribute(main, "Bundle-Version", "1.2.0");
- }
-
- /**
- * @tests java.util.jar.Manifest#Manifest(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- Manifest m = getManifest(attJarName);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- m.write(baos);
- InputStream is = new ByteArrayInputStream(baos.toByteArray());
- Manifest mCopy = new Manifest(is);
- assertEquals(m, mCopy);
-
- Manifest manifest = new Manifest(new URL(Support_Resources
- .getURL(MANIFEST_NAME)).openStream());
- checkManifest(manifest);
-
- // regression test for HARMONY-5424
- String manifestContent = "Manifest-Version: 1.0\nCreated-By: Apache\nPackage: \nBuild-Jdk: 1.4.1_01\n\n"
- + "Name: \nSpecification-Title: foo\nSpecification-Version: 1.0\nSpecification-Vendor: \n"
- + "Implementation-Title: \nImplementation-Version: 1.0\nImplementation-Vendor: \n\n";
- ByteArrayInputStream bis = new ByteArrayInputStream(manifestContent
- .getBytes("ISO-8859-1"));
-
-
- Manifest mf = new Manifest(bis);
- assertEquals("Should be 4 main attributes", 4, mf.getMainAttributes()
- .size());
-
- Map<String, Attributes> entries = mf.getEntries();
- assertEquals("Should be one named entry", 1, entries.size());
-
- Attributes namedEntryAttributes = (Attributes) (entries.get(""));
- assertEquals("Should be 6 named entry attributes", 6,
- namedEntryAttributes.size());
- }
-
- /**
- * @tests java.util.jar.Manifest#clear()
- */
- public void test_clear() {
- m2.clear();
- assertTrue("Should have no entries", m2.getEntries().isEmpty());
- assertTrue("Should have no main attributes", m2.getMainAttributes()
- .isEmpty());
- }
-
- public void test_clone() throws IOException {
- Manifest emptyManifest = new Manifest();
- Manifest emptyClone = (Manifest) emptyManifest.clone();
- assertTrue("Should have no entries", emptyClone.getEntries().isEmpty());
- assertTrue("Should have no main attributes", emptyClone
- .getMainAttributes().isEmpty());
- assertEquals(emptyClone, emptyManifest);
- assertEquals(emptyManifest.clone().getClass().getName(),
- "java.util.jar.Manifest");
-
- Manifest manifest = new Manifest(new URL(Support_Resources
- .getURL("manifest/hyts_MANIFEST.MF")).openStream());
- Manifest manifestClone = (Manifest) manifest.clone();
- manifestClone.getMainAttributes();
- checkManifest(manifestClone);
- }
-
- public void test_equals() throws IOException {
- Manifest manifest1 = new Manifest(new URL(Support_Resources.getURL(
- "manifest/hyts_MANIFEST.MF")).openStream());
- Manifest manifest2 = new Manifest(new URL(Support_Resources.getURL(
- "manifest/hyts_MANIFEST.MF")).openStream());
- Manifest manifest3 = new Manifest();
-
- assertTrue(manifest1.equals(manifest1));
- assertTrue(manifest1.equals(manifest2));
- assertFalse(manifest1.equals(manifest3));
- assertFalse(manifest1.equals(this));
- }
-
- public void test_hashCode() throws IOException {
- Manifest manifest1 = new Manifest(new URL(Support_Resources
- .getURL("manifest/hyts_MANIFEST.MF")).openStream());
- Manifest manifest2 = new Manifest();
- assertEquals(manifest1.hashCode(), manifest1.hashCode());
- assertNotSame(manifest1.hashCode(), manifest2.hashCode());
- }
-
- /**
- * @tests java.util.jar.Manifest#getAttributes(java.lang.String)
- */
- public void test_getAttributesLjava_lang_String() {
- assertNull("Should not exist",
- m2.getAttributes("Doesn't Exist"));
- assertEquals("Should exist", "OK", m2.getAttributes("HasAttributes.txt").get(
- new Attributes.Name("MyAttribute")));
- }
-
- /**
- * @tests java.util.jar.Manifest#getEntries()
- */
- public void test_getEntries() {
- Map<String, Attributes> myMap = m2.getEntries();
- assertNull("Shouldn't exist", myMap.get("Doesn't exist"));
- assertEquals("Should exist",
- "OK", myMap.get("HasAttributes.txt").get(
- new Attributes.Name("MyAttribute")));
- }
-
- /**
- * @tests java.util.jar.Manifest#getMainAttributes()
- */
- public void test_getMainAttributes() {
- // Test for method java.util.jar.Attributes
- // java.util.jar.Manifest.getMainAttributes()
- Attributes a = m.getMainAttributes();
- assertEquals("Manifest_Version should return 1.0", "1.0", a.get(
- Attributes.Name.MANIFEST_VERSION));
- }
-
- public void test_writeLjava_io_OutputStream() throws IOException {
- byte b[] = null;
- Manifest manifest1 = null;
- Manifest manifest2 = null;
- InputStream is = null;
- try {
- manifest1 = new Manifest(new URL(Support_Resources
- .getURL("manifest/hyts_MANIFEST.MF")).openStream());
- } catch (MalformedURLException e) {
- fail("Malformed URL");
- }
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- manifest1.write(baos);
-
- b = baos.toByteArray();
-
- File f = File.createTempFile("111", "111");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- try {
- manifest1.write(fos);
- fail("IOException expected");
- } catch (IOException e) {
- // expected
- }
- f.delete();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(b);
-
- try {
- manifest2 = new Manifest(bais);
- } catch (MalformedURLException e) {
- fail("Malformed URL");
- }
-
- assertTrue(manifest1.equals(manifest2));
- }
-
- /**
- * Ensures compatibility with manifests produced by gcc.
- *
- * @see <a
- * href="http://issues.apache.org/jira/browse/HARMONY-5662">HARMONY-5662</a>
- */
- public void testNul() throws IOException {
- String manifestContent =
- "Manifest-Version: 1.0\nCreated-By: nasty gcc tool\n\n\0";
-
- byte[] bytes = manifestContent.getBytes("ISO-8859-1");
- new Manifest(new ByteArrayInputStream(bytes)); // the last NUL is ok
-
- bytes[bytes.length - 1] = 26;
- new Manifest(new ByteArrayInputStream(bytes)); // the last EOF is ok
-
- bytes[bytes.length - 1] = 'A'; // the last line ignored
- new Manifest(new ByteArrayInputStream(bytes));
-
- bytes[2] = 0; // NUL char in Manifest
- try {
- new Manifest(new ByteArrayInputStream(bytes));
- fail("IOException expected");
- } catch (IOException e) {
- // desired
- }
- }
-
- public void testDecoding() throws IOException {
- Manifest m = getManifest(attJarName);
- final byte[] bVendor = new byte[] { (byte) 0xd0, (byte) 0x9C,
- (byte) 0xd0, (byte) 0xb8, (byte) 0xd0, (byte) 0xbb,
- (byte) 0xd0, (byte) 0xb0, (byte) 0xd1, (byte) 0x8f, ' ',
- (byte) 0xd0, (byte) 0xb4, (byte) 0xd0, (byte) 0xbe,
- (byte) 0xd1, (byte) 0x87, (byte) 0xd1, (byte) 0x83,
- (byte) 0xd0, (byte) 0xbd, (byte) 0xd1, (byte) 0x8C,
- (byte) 0xd0, (byte) 0xba, (byte) 0xd0, (byte) 0xb0, ' ',
- (byte) 0xd0, (byte) 0x9C, (byte) 0xd0, (byte) 0xb0,
- (byte) 0xd1, (byte) 0x88, (byte) 0xd0, (byte) 0xb0 };
-
- final byte[] bSpec = new byte[] { (byte) 0xe1, (byte) 0x88,
- (byte) 0xb0, (byte) 0xe1, (byte) 0x88, (byte) 0x8b,
- (byte) 0xe1, (byte) 0x88, (byte) 0x9d, ' ', (byte) 0xe1,
- (byte) 0x9a, (byte) 0xa0, (byte) 0xe1, (byte) 0x9a,
- (byte) 0xb1, (byte) 0xe1, (byte) 0x9b, (byte) 0x81,
- (byte) 0xe1, (byte) 0x9a, (byte) 0xa6, ' ', (byte) 0xd8,
- (byte) 0xb3, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
- (byte) 0xa7, (byte) 0xd9, (byte) 0x85, ' ', (byte) 0xd8,
- (byte) 0xb9, (byte) 0xd8, (byte) 0xb3, (byte) 0xd9,
- (byte) 0x84, (byte) 0xd8, (byte) 0xa7, (byte) 0xd9,
- (byte) 0x85, (byte) 0xd8, (byte) 0xa9, ' ', (byte) 0xdc,
- (byte) 0xab, (byte) 0xdc, (byte) 0xa0, (byte) 0xdc,
- (byte) 0xa1, (byte) 0xdc, (byte) 0x90, ' ', (byte) 0xe0,
- (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
- (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
- (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
- (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
- (byte) 0xbf, ' ', (byte) 0xd0, (byte) 0xa0, (byte) 0xd0,
- (byte) 0xb5, (byte) 0xd0, (byte) 0xba, (byte) 0xd1,
- (byte) 0x8a, (byte) 0xd0, (byte) 0xb5, (byte) 0xd0,
- (byte) 0xbb, ' ', (byte) 0xd0, (byte) 0x9c, (byte) 0xd0,
- (byte) 0xb8, (byte) 0xd1, (byte) 0x80, ' ', (byte) 0xe0,
- (byte) 0xa6, (byte) 0xb6, (byte) 0xe0, (byte) 0xa6,
- (byte) 0xbe, (byte) 0xe0, (byte) 0xa6, (byte) 0xa8,
- (byte) 0xe0, (byte) 0xa7, (byte) 0x8d, (byte) 0xe0,
- (byte) 0xa6, (byte) 0xa4, (byte) 0xe0, (byte) 0xa6,
- (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
- (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
- (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
- (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
- (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xd0,
- (byte) 0x9c, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
- (byte) 0x88, (byte) 0xd0, (byte) 0xb0, (byte) 0xd1,
- (byte) 0x80, ' ', (byte) 0xe1, (byte) 0x8f, (byte) 0x99,
- (byte) 0xe1, (byte) 0x8e, (byte) 0xaf, (byte) 0xe1,
- (byte) 0x8f, (byte) 0xb1, ' ', (byte) 0xcf, (byte) 0xa8,
- (byte) 0xce, (byte) 0xb9, (byte) 0xcf, (byte) 0x81,
- (byte) 0xce, (byte) 0xb7, (byte) 0xce, (byte) 0xbd,
- (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xde, (byte) 0x90,
- (byte) 0xde, (byte) 0xaa, (byte) 0xde, (byte) 0x85,
- (byte) 0xde, (byte) 0xa6, ' ', (byte) 0xe0, (byte) 0xbd,
- (byte) 0x82, (byte) 0xe0, (byte) 0xbd, (byte) 0x9e,
- (byte) 0xe0, (byte) 0xbd, (byte) 0xb2, (byte) 0xe0,
- (byte) 0xbc, (byte) 0x8b, (byte) 0xe0, (byte) 0xbd,
- (byte) 0x96, (byte) 0xe0, (byte) 0xbd, (byte) 0x91,
- (byte) 0xe0, (byte) 0xbd, (byte) 0xba, ' ', (byte) 0xce,
- (byte) 0x95, (byte) 0xce, (byte) 0xb9, (byte) 0xcf,
- (byte) 0x81, (byte) 0xce, (byte) 0xae, (byte) 0xce,
- (byte) 0xbd, (byte) 0xce, (byte) 0xb7, ' ', (byte) 0xd8,
- (byte) 0xb5, (byte) 0xd9, (byte) 0x84, (byte) 0xd8,
- (byte) 0xad, ' ', (byte) 0xe0, (byte) 0xaa, (byte) 0xb6,
- (byte) 0xe0, (byte) 0xaa, (byte) 0xbe, (byte) 0xe0,
- (byte) 0xaa, (byte) 0x82, (byte) 0xe0, (byte) 0xaa,
- (byte) 0xa4, (byte) 0xe0, (byte) 0xaa, (byte) 0xbf, ' ',
- (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, (byte) 0xe5,
- (byte) 0x92, (byte) 0x8c, ' ', (byte) 0xd7, (byte) 0xa9,
- (byte) 0xd7, (byte) 0x9c, (byte) 0xd7, (byte) 0x95,
- (byte) 0xd7, (byte) 0x9d, ' ', (byte) 0xd7, (byte) 0xa4,
- (byte) 0xd7, (byte) 0xa8, (byte) 0xd7, (byte) 0x99,
- (byte) 0xd7, (byte) 0x93, (byte) 0xd7, (byte) 0x9f, ' ',
- (byte) 0xe5, (byte) 0x92, (byte) 0x8c, (byte) 0xe5,
- (byte) 0xb9, (byte) 0xb3, ' ', (byte) 0xe5, (byte) 0x92,
- (byte) 0x8c, (byte) 0xe5, (byte) 0xb9, (byte) 0xb3, ' ',
- (byte) 0xd8, (byte) 0xaa, (byte) 0xd9, (byte) 0x89,
- (byte) 0xd9, (byte) 0x86, (byte) 0xda, (byte) 0x86,
- (byte) 0xd9, (byte) 0x84, (byte) 0xd9, (byte) 0x89,
- (byte) 0xd9, (byte) 0x82, ' ', (byte) 0xe0, (byte) 0xae,
- (byte) 0x85, (byte) 0xe0, (byte) 0xae, (byte) 0xae,
- (byte) 0xe0, (byte) 0xaf, (byte) 0x88, (byte) 0xe0,
- (byte) 0xae, (byte) 0xa4, (byte) 0xe0, (byte) 0xae,
- (byte) 0xbf, ' ', (byte) 0xe0, (byte) 0xb0, (byte) 0xb6,
- (byte) 0xe0, (byte) 0xb0, (byte) 0xbe, (byte) 0xe0,
- (byte) 0xb0, (byte) 0x82, (byte) 0xe0, (byte) 0xb0,
- (byte) 0xa4, (byte) 0xe0, (byte) 0xb0, (byte) 0xbf, ' ',
- (byte) 0xe0, (byte) 0xb8, (byte) 0xaa, (byte) 0xe0,
- (byte) 0xb8, (byte) 0xb1, (byte) 0xe0, (byte) 0xb8,
- (byte) 0x99, (byte) 0xe0, (byte) 0xb8, (byte) 0x95,
- (byte) 0xe0, (byte) 0xb8, (byte) 0xb4, (byte) 0xe0,
- (byte) 0xb8, (byte) 0xa0, (byte) 0xe0, (byte) 0xb8,
- (byte) 0xb2, (byte) 0xe0, (byte) 0xb8, (byte) 0x9e, ' ',
- (byte) 0xe1, (byte) 0x88, (byte) 0xb0, (byte) 0xe1,
- (byte) 0x88, (byte) 0x8b, (byte) 0xe1, (byte) 0x88,
- (byte) 0x9d, ' ', (byte) 0xe0, (byte) 0xb7, (byte) 0x83,
- (byte) 0xe0, (byte) 0xb7, (byte) 0x8f, (byte) 0xe0,
- (byte) 0xb6, (byte) 0xb8, (byte) 0xe0, (byte) 0xb6,
- (byte) 0xba, ' ', (byte) 0xe0, (byte) 0xa4, (byte) 0xb6,
- (byte) 0xe0, (byte) 0xa4, (byte) 0xbe, (byte) 0xe0,
- (byte) 0xa4, (byte) 0xa8, (byte) 0xe0, (byte) 0xa5,
- (byte) 0x8d, (byte) 0xe0, (byte) 0xa4, (byte) 0xa4,
- (byte) 0xe0, (byte) 0xa4, (byte) 0xbf, (byte) 0xe0,
- (byte) 0xa4, (byte) 0x83, ' ', (byte) 0xe1, (byte) 0x83,
- (byte) 0x9b, (byte) 0xe1, (byte) 0x83, (byte) 0xa8,
- (byte) 0xe1, (byte) 0x83, (byte) 0x95, (byte) 0xe1,
- (byte) 0x83, (byte) 0x98, (byte) 0xe1, (byte) 0x83,
- (byte) 0x93, (byte) 0xe1, (byte) 0x83, (byte) 0x9d,
- (byte) 0xe1, (byte) 0x83, (byte) 0x91, (byte) 0xe1,
- (byte) 0x83, (byte) 0x90 };
- // TODO Cannot make the following word work, encoder changes needed
- // (byte) 0xed, (byte) 0xa0, (byte) 0x80,
- // (byte) 0xed, (byte) 0xbc, (byte) 0xb2, (byte) 0xed,
- // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
- // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
- // (byte) 0xed, (byte) 0xbd, (byte) 0x85, (byte) 0xed,
- // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
- // (byte) 0xb0, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
- // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, (byte) 0xed,
- // (byte) 0xa0, (byte) 0x80, (byte) 0xed, (byte) 0xbc,
- // (byte) 0xb8, (byte) 0xed, (byte) 0xa0, (byte) 0x80,
- // (byte) 0xed, (byte) 0xbc, (byte) 0xb9, ' '
-
- final String vendor = new String(bVendor, "UTF-8");
- final String spec = new String(bSpec, "UTF-8");
- m.getMainAttributes()
- .put(Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
- m.getAttributes(ATT_ENTRY_NAME).put(
- Attributes.Name.IMPLEMENTATION_VENDOR, vendor);
- m.getEntries().get(ATT_ENTRY_NAME).put(
- Attributes.Name.SPECIFICATION_TITLE, spec);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- m.write(baos);
- m = new Manifest(new ByteArrayInputStream(baos.toByteArray()));
-
- assertEquals(vendor, m.getMainAttributes().get(
- Attributes.Name.IMPLEMENTATION_VENDOR));
- assertEquals(vendor, m.getEntries().get(ATT_ENTRY_NAME).get(
- Attributes.Name.IMPLEMENTATION_VENDOR));
- assertEquals(spec, m.getAttributes(ATT_ENTRY_NAME).get(
- Attributes.Name.SPECIFICATION_TITLE));
- }
-
- /**
- * @tests {@link java.util.jar.Manifest#read(java.io.InputStream)
- */
- public void testRead() {
- // Regression for HARMONY-89
- InputStream is = new InputStreamImpl();
- try {
- new Manifest().read(is);
- fail("IOException expected");
- } catch (IOException e) {
- // desired
- }
- }
-
- // helper class
- private class InputStreamImpl extends InputStream {
- public InputStreamImpl() {
- super();
- }
-
- @Override
- public int read() {
- return 0;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ZipExecTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ZipExecTest.java
deleted file mode 100644
index c57ccbe..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/jar/ZipExecTest.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.jar;
-
-import static tests.support.Support_Exec.javaProcessBuilder;
-import static tests.support.Support_Exec.execAndGetOutput;
-import tests.support.resource.Support_Resources;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-/**
- *
- * tests for various cases of java -jar ... execution with .zip files as args
- * some tests are just copy of JarExecTest ones
- */
-
-public class ZipExecTest extends junit.framework.TestCase {
- public void test_1562() throws Exception {
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
-
- File outputZip = File.createTempFile("hyts_", ".zip");
- outputZip.deleteOnExit();
- ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(
- outputZip));
- File resources = Support_Resources.createTempFolder();
-
- for (String zipClass : new String[] {"Foo", "Bar"}) {
- zout.putNextEntry(new ZipEntry("foo/bar/execjartest/" + zipClass
- + ".class"));
- zout.write(getResource(resources, "hyts_" + zipClass + ".ser"));
- }
-
- zout.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zout);
- zout.close();
-
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(outputZip.getAbsolutePath());
-
- assertTrue("Error executing ZIP",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
- /**
- * tests Class-Path entry in manifest
- *
- * @throws Exception in case of troubles
- */
- public void test_zip_class_path() throws Exception {
- File fooZip = File.createTempFile("hyts_", ".zip");
- File barZip = File.createTempFile("hyts_", ".zip");
- fooZip.deleteOnExit();
- barZip.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, barZip.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(
- fooZip));
- zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zoutFoo);
- zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
- zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
- zoutFoo.close();
-
- ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(
- barZip));
- zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
- zoutBar.write(getResource(resources, "hyts_Bar.ser"));
- zoutBar.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(fooZip.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith( "FOOBAR"));
-
- // rewrite manifest so it contains not only reference to bar but useless
- // entries as well
- att.put(Attributes.Name.CLASS_PATH, "xx yy zz " + barZip.getName());
- zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip));
- zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zoutFoo);
- zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
- zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
- zoutFoo.close();
- // execute the JAR and read the result
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
-
-
- // play with relative file names - put relative path as ../<parent dir
- // name>/xx.zip
- att.put(Attributes.Name.CLASS_PATH, ".." + File.separator
- + barZip.getParentFile().getName() + File.separator
- + barZip.getName());
- zoutFoo = new ZipOutputStream(new FileOutputStream(fooZip));
- zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zoutFoo);
- zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
- zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
- zoutFoo.close();
- // execute the ZIP and read the result
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
-
- public void test_zip_jar_mix() throws Exception {
- File fooJar = File.createTempFile("hyts_", ".jar");
- File barZip = File.createTempFile("hyts_", ".zip");
- fooJar.deleteOnExit();
- barZip.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, barZip.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- JarOutputStream joutFoo = new JarOutputStream(new FileOutputStream(
- fooJar), man);
- joutFoo.putNextEntry(new JarEntry("foo/bar/execjartest/Foo.class"));
- joutFoo.write(getResource(resources, "hyts_Foo.ser"));
- joutFoo.close();
-
- ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(
- barZip));
- zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
- zoutBar.write(getResource(resources, "hyts_Bar.ser"));
- zoutBar.close();
-
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(fooJar.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
- public void test_zip_jar_mix_1() throws Exception {
- File fooZip = File.createTempFile("hyts_", ".zip");
- File barJar = File.createTempFile("hyts_", ".jar");
- fooZip.deleteOnExit();
- barJar.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, barJar.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(
- fooZip));
- zoutFoo.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zoutFoo);
- zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
- zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
- zoutFoo.close();
-
- JarOutputStream joutBar = new JarOutputStream(new FileOutputStream(
- barJar));
- joutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
- joutBar.write(getResource(resources, "hyts_Bar.ser"));
- joutBar.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(fooZip.getAbsolutePath());
- assertTrue("Error executing ZIP",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
- /**
- * tests case when Main-Class is not in the zip launched but in another zip
- * referenced by Class-Path
- *
- * @throws Exception in case of troubles
- */
- public void test_main_class_in_another_zip() throws Exception {
- File fooZip = File.createTempFile("hyts_", ".zip");
- File barZip = File.createTempFile("hyts_", ".zip");
- fooZip.deleteOnExit();
- barZip.deleteOnExit();
-
- // create the manifest
- Manifest man = new Manifest();
- Attributes att = man.getMainAttributes();
- att.put(Attributes.Name.MANIFEST_VERSION, "1.0");
- att.put(Attributes.Name.MAIN_CLASS, "foo.bar.execjartest.Foo");
- att.put(Attributes.Name.CLASS_PATH, fooZip.getName());
-
- File resources = Support_Resources.createTempFolder();
-
- ZipOutputStream zoutFoo = new ZipOutputStream(new FileOutputStream(
- fooZip));
- zoutFoo.putNextEntry(new ZipEntry("foo/bar/execjartest/Foo.class"));
- zoutFoo.write(getResource(resources, "hyts_Foo.ser"));
- zoutFoo.close();
-
- ZipOutputStream zoutBar = new ZipOutputStream(new FileOutputStream(
- barZip));
- zoutBar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
- man.write(zoutBar);
-
- zoutBar.putNextEntry(new ZipEntry("foo/bar/execjartest/Bar.class"));
- zoutBar.write(getResource(resources, "hyts_Bar.ser"));
- zoutBar.close();
-
- // execute the JAR and read the result
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-jar");
- builder.command().add(barZip.getAbsolutePath());
- assertTrue("Error executing JAR",
- execAndGetOutput(builder).startsWith("FOOBAR"));
- }
-
-
- private static byte[] getResource(File tempDir, String resourceName)
- throws IOException {
- Support_Resources.copyFile(tempDir, null, resourceName);
- File resourceFile = new File(tempDir, resourceName);
- resourceFile.deleteOnExit();
-
- // read whole resource data into memory
- byte[] resourceBody = new byte[(int) resourceFile.length()];
- FileInputStream fis = new FileInputStream(resourceFile);
- fis.read(resourceBody);
- fis.close();
-
- return resourceBody;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java
deleted file mode 100644
index f68c782..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/Adler32Test.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.util.zip.Adler32;
-
-public class Adler32Test extends junit.framework.TestCase {
-
- /**
- * @tests java.util.zip.Adler32#Adler32()
- */
- public void test_Constructor() {
- // test method of java.util.zip.Adler32()
- Adler32 adl = new Adler32();
- assertEquals("Constructor of adl32 failed", 1, adl.getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#getValue()
- */
- public void test_getValue() {
- // test methods of java.util.zip.getValue()
- Adler32 adl = new Adler32();
- assertEquals("GetValue should return a zero as a result of construction an object of Adler32",
- 1, adl.getValue());
-
- adl.reset();
- adl.update(1);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 131074
- assertEquals("update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
- adl.reset();
- assertEquals("reset failed to reset the checksum value to zero", 1, adl
- .getValue());
-
- adl.reset();
- adl.update(Integer.MIN_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 65537
- assertEquals("update(min) failed to update the checksum to the correct value ",
- 65537L, adl.getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#reset()
- */
- public void test_reset() {
- // test methods of java.util.zip.reset()
- Adler32 adl = new Adler32();
- adl.update(1);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 131074
- assertEquals("update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
- adl.reset();
- assertEquals("reset failed to reset the checksum value to zero", 1, adl
- .getValue());
- }
-
- /**
- * @tests java.util.zip.Adler32#update(int)
- */
- public void test_updateI() {
- // test methods of java.util.zip.update(int)
- Adler32 adl = new Adler32();
- adl.update(1);
- // The value of the adl should be 131074
- assertEquals("update(int) failed to update the checksum to the correct value ",
- 131074, adl.getValue());
-
- adl.reset();
- adl.update(Integer.MAX_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 16777472
- assertEquals("update(max) failed to update the checksum to the correct value ",
- 16777472L, adl.getValue());
-
- adl.reset();
- adl.update(Integer.MIN_VALUE);
- // System.out.print("value of adl " + adl.getValue());
- // The value of the adl should be 65537
- assertEquals("update(min) failed to update the checksum to the correct value ",
- 65537L, adl.getValue());
-
- }
-
- /**
- * @tests java.util.zip.Adler32#update(byte[])
- */
- public void test_update$B() {
- // test method of java.util.zip.update(byte[])
- byte byteArray[] = { 1, 2 };
- Adler32 adl = new Adler32();
- adl.update(byteArray);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 393220
- assertEquals("update(byte[]) failed to update the checksum to the correct value ",
- 393220, adl.getValue());
-
- adl.reset();
- byte byteEmpty[] = new byte[10000];
- adl.update(byteEmpty);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 655360001
- assertEquals("update(byte[]) failed to update the checksum to the correct value ",
- 655360001L, adl.getValue());
-
- }
-
- /**
- * @tests java.util.zip.Adler32#update(byte[], int, int)
- */
- public void test_update$BII() {
- // test methods of java.util.zip.update(byte[],int,int)
- byte[] byteArray = { 1, 2, 3 };
- Adler32 adl = new Adler32();
- int off = 2;// accessing the 2nd element of byteArray
- int len = 1;
- int lenError = 3;
- int offError = 4;
- adl.update(byteArray, off, len);
- // System.out.print("value of adl"+adl.getValue());
- // The value of the adl should be 262148
- assertEquals("update(byte[],int,int) failed to update the checksum to the correct value ",
- 262148, adl.getValue());
- int r = 0;
-
- try {
- adl.update(byteArray, off, lenError);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("update(byte[],int,int) failed b/c lenError>byte[].length-off",
- 1, r);
-
- try {
- adl.update(byteArray, offError, len);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 2;
- }
- assertEquals("update(byte[],int,int) failed b/c offError>byte[].length",
- 2, r);
-
- }
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java
deleted file mode 100644
index cc0c46d..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/AllTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite for java.util.zip package.
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Suite org.apache.harmony.archive.tests.java.util.zip");
- suite.addTestSuite(Adler32Test.class);
- suite.addTestSuite(CheckedInputStreamTest.class);
- suite.addTestSuite(CheckedOutputStreamTest.class);
- suite.addTestSuite(CRC32Test.class);
- suite.addTestSuite(DataFormatExceptionTest.class);
- suite.addTestSuite(DeflaterInputStreamTest.class);
- suite.addTestSuite(DeflaterOutputStreamTest.class);
- suite.addTestSuite(DeflaterTest.class);
- suite.addTestSuite(GZIPInputStreamTest.class);
- suite.addTestSuite(GZIPOutputStreamTest.class);
- suite.addTestSuite(InflaterInputStreamTest.class);
- suite.addTestSuite(InflaterOutputStreamTest.class);
- suite.addTestSuite(InflaterTest.class);
- suite.addTestSuite(ZipEntryTest.class);
- suite.addTestSuite(ZipExceptionTest.class);
- suite.addTestSuite(ZipFileTest.class);
- suite.addTestSuite(ZipInputStreamTest.class);
- suite.addTestSuite(ZipOutputStreamTest.class);
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
deleted file mode 100644
index ea076d7..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CRC32Test.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.util.zip.CRC32;
-
-public class CRC32Test extends junit.framework.TestCase {
-
- /**
- * @tests java.util.zip.CRC32#CRC32()
- */
- public void test_Constructor() {
- // test methods of java.util.zip.CRC32()
- CRC32 crc = new CRC32();
- assertEquals("Constructor of CRC32 failed", 0, crc.getValue());
- }
-
- /**
- * @tests java.util.zip.CRC32#getValue()
- */
- public void test_getValue() {
- // test methods of java.util.zip.crc32.getValue()
- CRC32 crc = new CRC32();
- assertEquals("getValue() should return a zero as a result of constructing a CRC32 instance",
- 0, crc.getValue());
-
- crc.reset();
- crc.update(Integer.MAX_VALUE);
- // System.out.print("value of crc " + crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 4278190080
- assertEquals("update(max) failed to update the checksum to the correct value ",
- 4278190080L, crc.getValue());
-
- crc.reset();
- byte byteEmpty[] = new byte[10000];
- crc.update(byteEmpty);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 1295764014
- assertEquals("update(byte[]) failed to update the checksum to the correct value ",
- 1295764014L, crc.getValue());
-
- crc.reset();
- crc.update(1);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 2768625435
- // assertEquals("update(int) failed to update the checksum to the correct
- // value ",2768625435L, crc.getValue());
- crc.reset();
- assertEquals("reset failed to reset the checksum value to zero", 0, crc
- .getValue());
- }
-
- /**
- * @tests java.util.zip.CRC32#reset()
- */
- public void test_reset() {
- // test methods of java.util.zip.crc32.reset()
- CRC32 crc = new CRC32();
- crc.update(1);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 2768625435
- assertEquals("update(int) failed to update the checksum to the correct value ",
- 2768625435L, crc.getValue());
- crc.reset();
- assertEquals("reset failed to reset the checksum value to zero", 0, crc
- .getValue());
-
- }
-
- /**
- * @tests java.util.zip.CRC32#update(int)
- */
- public void test_updateI() {
- // test methods of java.util.zip.crc32.update(int)
- CRC32 crc = new CRC32();
- crc.update(1);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 2768625435
- assertEquals("update(1) failed to update the checksum to the correct value ",
- 2768625435L, crc.getValue());
-
- crc.reset();
- crc.update(Integer.MAX_VALUE);
- // System.out.print("value of crc " + crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 4278190080
- assertEquals("update(max) failed to update the checksum to the correct value ",
- 4278190080L, crc.getValue());
-
- crc.reset();
- crc.update(Integer.MIN_VALUE);
- // System.out.print("value of crc " + crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 3523407757
- assertEquals("update(min) failed to update the checksum to the correct value ",
- 3523407757L, crc.getValue());
- }
-
- /**
- * @tests java.util.zip.CRC32#update(byte[])
- */
- public void test_update$B() {
- // test methods of java.util.zip.crc32.update(byte[])
- byte byteArray[] = { 1, 2 };
- CRC32 crc = new CRC32();
- crc.update(byteArray);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 3066839698
- assertEquals("update(byte[]) failed to update the checksum to the correct value ",
- 3066839698L, crc.getValue());
-
- crc.reset();
- byte byteEmpty[] = new byte[10000];
- crc.update(byteEmpty);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 1295764014
- assertEquals("update(byte[]) failed to update the checksum to the correct value ",
- 1295764014L, crc.getValue());
- }
-
- /**
- * @tests java.util.zip.CRC32#update(byte[], int, int)
- */
- public void test_update$BII() {
- // test methods of java.util.zip.update(byte[],int,int)
- byte[] byteArray = { 1, 2, 3 };
- CRC32 crc = new CRC32();
- int off = 2;// accessing the 2nd element of byteArray
- int len = 1;
- int lenError = 3;
- int offError = 4;
- crc.update(byteArray, off, len);
- // System.out.print("value of crc"+crc.getValue());
- // Ran JDK and discovered that the value of the CRC should be
- // 1259060791
- assertEquals("update(byte[],int,int) failed to update the checksum to the correct value ",
- 1259060791L, crc.getValue());
- int r = 0;
- try {
- crc.update(byteArray, off, lenError);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("update(byte[],int,int) failed b/c lenError>byte[].length-off",
- 1, r);
-
- try {
- crc.update(byteArray, offError, len);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 2;
- }
- assertEquals("update(byte[],int,int) failed b/c offError>byte[].length",
- 2, r);
- }
-
- @Override
- protected void setUp() {
-
- }
-
- @Override
- protected void tearDown() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
deleted file mode 100644
index 748c9fa..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedInputStreamTest.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.zip.CRC32;
-import java.util.zip.CheckedInputStream;
-
-import junit.framework.TestCase;
-import tests.support.resource.Support_Resources;
-
-public class CheckedInputStreamTest extends TestCase {
-
- @Override
- protected void tearDown() {
- try {
- File deletedFile = new File("empty.txt");
- deletedFile.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
-
- }
-
- /**
- * @tests java.util.zip.CheckedInputStream#CheckedInputStream(java.io.InputStream,
- * java.util.zip.Checksum)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Checksum() throws Exception {
- InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
- assertEquals("constructor of checkedInputStream has failed", 0, checkIn.getChecksum()
- .getValue());
- checkInput.close();
- }
-
- /**
- * @tests java.util.zip.CheckedInputStream#getChecksum()
- */
- public void test_getChecksum() throws Exception {
- byte outBuf[] = new byte[100];
- // testing getChecksum for an empty file
- FileOutputStream outEmp = new FileOutputStream("empty.txt");
- outEmp.close();
- InputStream inEmp = new FileInputStream("empty.txt");
- CheckedInputStream checkEmpty = new CheckedInputStream(inEmp, new CRC32());
- while (checkEmpty.read() >= 0) {
- }
- assertEquals("the checkSum value of an empty file is not zero", 0, checkEmpty
- .getChecksum().getValue());
- inEmp.close();
-
- // testing getChecksum for the file checkInput
- InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
- while (checkIn.read() >= 0) {
- }
- // ran JDK and found that the checkSum value of this is 2036203193
- // System.out.print(" " + checkIn.getChecksum().getValue());
- assertEquals("the checksum value is incorrect", 2036203193, checkIn.getChecksum()
- .getValue());
- checkInput.close();
- // testing getChecksum for file checkInput
- checkInput = Support_Resources.getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn2 = new CheckedInputStream(checkInput, new CRC32());
- checkIn2.read(outBuf, 0, 10);
- // ran JDK and found that the checkSum value of this is 2235765342
- // System.out.print(" " + checkIn2.getChecksum().getValue());
- assertEquals("the checksum value is incorrect", 2235765342L, checkIn2.getChecksum()
- .getValue());
- checkInput.close();
- }
-
- /**
- * @tests java.util.zip.CheckedInputStream#skip(long)
- */
- public void test_skipJ() throws Exception {
- // testing that the return by skip is valid
- InputStream checkInput = Support_Resources.getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput, new CRC32());
- long skipValue = 5;
- assertEquals("the value returned by skip(n) is not the same as its parameter",
- skipValue, checkIn.skip(skipValue));
- checkIn.skip(skipValue);
- // ran JDK and found the checkSum value is 2235765342
- // System.out.print(checkIn.getChecksum().getValue());
- assertEquals("checkSum value is not correct", 2235765342L, checkIn.getChecksum()
- .getValue());
- checkInput.close();
- }
-
- public void test_read() throws Exception {
- // testing that the return by skip is valid
- InputStream checkInput = Support_Resources
- .getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput,
- new CRC32());
- checkIn.read();
- checkIn.close();
- try {
- checkIn.read();
- fail("IOException expected.");
- } catch (IOException ee) {
- // expected
- }
- checkInput.close();
- }
-
- public void test_read$byteII() throws Exception {
- // testing that the return by skip is valid
- InputStream checkInput = Support_Resources
- .getStream("hyts_checkInput.txt");
- CheckedInputStream checkIn = new CheckedInputStream(checkInput,
- new CRC32());
- byte buff[] = new byte[50];
- checkIn.read(buff, 10, 5);
- checkIn.close();
- try {
- checkIn.read(buff, 10, 5);
- fail("IOException expected.");
- } catch (IOException ee) {
- // expected
- }
- checkInput.close();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java
deleted file mode 100644
index 35ac7eb..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/CheckedOutputStreamTest.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.Adler32;
-import java.util.zip.CRC32;
-import java.util.zip.CheckedOutputStream;
-
-public class CheckedOutputStreamTest extends junit.framework.TestCase {
-
- /**
- * @tests java.util.zip.CheckedOutputStream#CheckedOutputStream(java.io.OutputStream,
- * java.util.zip.Checksum)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Checksum() {
- // test method java.util.zip.checkedOutputStream.constructor
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("chkOut", ".txt"));
- CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
- new CRC32());
- assertEquals("the checkSum value of the constructor is not 0", 0,
- chkOut.getChecksum().getValue());
- outFile.close();
- } catch (IOException e) {
- fail("Unable to find file");
- } catch (SecurityException e) {
- fail("file cannot be opened for writing due to security reasons");
- }
- }
-
- /**
- * @tests java.util.zip.CheckedOutputStream#getChecksum()
- */
- public void test_getChecksum() {
- // test method java.util.zip.checkedOutputStream.getChecksum()
- byte byteArray[] = {1, 2, 3, 'e', 'r', 't', 'g', 3, 6};
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("chkOut", ".txt"));
- CheckedOutputStream chkOut = new CheckedOutputStream(outFile,
- new Adler32());
- chkOut.write(byteArray[4]);
- // ran JDK and found that checkSum value is 7536755
- // System.out.print(chkOut.getChecksum().getValue());
-
- assertEquals("the checkSum value for writeI is incorrect", 7536755,
- chkOut.getChecksum().getValue());
- chkOut.getChecksum().reset();
- chkOut.write(byteArray, 5, 4);
- // ran JDK and found that checkSum value is 51708133
- // System.out.print(" " +chkOut.getChecksum().getValue());
-
- assertEquals("the checkSum value for writeBII is incorrect ",
- 51708133, chkOut.getChecksum().getValue());
- outFile.close();
- } catch (IOException e) {
- fail("Unable to find file");
- } catch (SecurityException e) {
- fail("file cannot be opened for writing due to security reasons");
- }
- }
-
- /**
- * @tests java.util.zip.CheckedOutputStream#write(int)
- */
- public void test_writeI() {
- // test method java.util.zip.checkedOutputStream.writeI()
- CheckedOutputStream chkOut = null;
- byte byteArray[] = {1, 2, 3, 'e', 'r', 't', 'g', 3, 6};
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("chkOut", ".txt"));
- chkOut = new CheckedOutputStream(outFile, new CRC32());
- for (byte element : byteArray) {
- chkOut.write(element);
- }
- assertTrue(
- "the checkSum value is zero, no bytes are written to the output file",
- chkOut.getChecksum().getValue() != 0);
- outFile.close();
- } catch (IOException e) {
- fail("Unable to find file");
- } catch (SecurityException e) {
- fail("File cannot be opened for writing due to security reasons");
- }
- try {
- chkOut.write(0);
- fail("IOException expected");
- } catch (IOException e) {
- // expected.
- }
- }
-
- /**
- * @tests java.util.zip.CheckedOutputStream#write(byte[], int, int)
- */
- public void test_write$BII() {
- // test method java.util.zip.checkOutputStream.writeBII()
- CheckedOutputStream chkOut = null;
- byte byteArray[] = {1, 2, 3, 'e', 'r', 't', 'g', 3, 6};
- try {
- FileOutputStream outFile = new FileOutputStream(
- File.createTempFile("chkOut", ".txt"));
- chkOut = new CheckedOutputStream(outFile, new CRC32());
- chkOut.write(byteArray, 4, 5);
- assertTrue(
- "the checkSum value is zero, no bytes are written to the output file",
- chkOut.getChecksum().getValue() != 0);
- int r = 0;
- try {
- chkOut.write(byteArray, 4, 6);
- } catch (IndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("boundary check is not performed", 1, r);
- outFile.close();
- } catch (IOException e) {
- fail("Unable to find file");
- } catch (SecurityException e) {
- fail("file cannot be opened for writing due to security reasons");
- } catch (IndexOutOfBoundsException e) {
- fail("Index for write is out of bounds");
- }
- try {
- chkOut.write(byteArray, 4, 5);
- fail("IOException expected");
- } catch (IOException e) {
- // expected
- }
- }
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
- try {
- File deletedFile = new File("chkOut.txt");
- deletedFile.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DataFormatExceptionTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DataFormatExceptionTest.java
deleted file mode 100644
index 929227d..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DataFormatExceptionTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import junit.framework.TestCase;
-
-import java.util.zip.DataFormatException;
-
-public class DataFormatExceptionTest extends TestCase {
-
- public void testDataFormatException() {
- DataFormatException dfe = new DataFormatException();
- assertEquals(dfe.getMessage(), null);
- }
-
- public void testDataFormatExceptionString() {
- DataFormatException dfe = new DataFormatException("Test");
- assertEquals(dfe.getMessage(), "Test");
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java
deleted file mode 100644
index 81874c1..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterInputStreamTest.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterInputStream;
-
-import junit.framework.TestCase;
-
-public class DeflaterInputStreamTest extends TestCase {
-
- String testStr = "Hi,this is a test";
-
- InputStream is;
-
- /**
- * @tests DeflaterInputStream#available()
- */
- public void testAvailable() throws IOException {
- byte[] buf = new byte[1024];
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- assertEquals(120, dis.read());
- assertEquals(1, dis.available());
- assertEquals(22, dis.read(buf, 0, 1024));
- assertEquals(1, dis.available());
- assertEquals(-1, dis.read());
- assertEquals(0, dis.available());
- dis.close();
- try {
- dis.available();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#close()
- */
- public void testClose() throws IOException {
- byte[] buf = new byte[1024];
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- dis.close();
- try {
- dis.available();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(buf, 0, 1024);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- // can close after close
- dis.close();
- }
-
- /**
- * @tests DeflaterInputStream#mark()
- */
- public void testMark() throws IOException {
- // mark do nothing
- DeflaterInputStream dis = new DeflaterInputStream(is);
- dis.mark(-1);
- dis.mark(0);
- dis.mark(1);
- dis.close();
- dis.mark(1);
- }
-
- /**
- * @tests DeflaterInputStream#markSupported()
- */
- public void testMarkSupported() throws IOException {
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertFalse(dis.markSupported());
- dis.close();
- assertFalse(dis.markSupported());
- }
-
- /**
- * @tests DeflaterInputStream#read()
- */
- public void testRead() throws IOException {
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- assertEquals(120, dis.read());
- assertEquals(1, dis.available());
- assertEquals(156, dis.read());
- assertEquals(1, dis.available());
- assertEquals(243, dis.read());
- assertEquals(1, dis.available());
- dis.close();
- try {
- dis.read();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#read(byte[],int,int)
- */
- public void testReadByteArrayIntInt() throws IOException {
- byte[] buf1 = new byte[256];
- byte[] buf2 = new byte[256];
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertEquals(23, dis.read(buf1, 0, 256));
- dis = new DeflaterInputStream(is);
- assertEquals(8, dis.read(buf2, 0, 256));
- is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
- dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- assertEquals(120, dis.read());
- assertEquals(1, dis.available());
- assertEquals(22, dis.read(buf2, 0, 256));
- assertEquals(1, dis.available());
- assertEquals(-1, dis.read());
- assertEquals(0, dis.available());
- try {
- dis.read(buf1, 0, 512);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- dis.read(null, 0, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- dis.read(null, -1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- dis.read(null, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- dis.read(buf1, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- dis.read(buf1, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- dis.close();
- try {
- dis.read(buf1, 0, 512);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(buf1, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(null, 0, 0);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(null, -1, 0);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(null, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(buf1, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.read(buf1, 0, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#reset()
- */
- public void testReset() throws IOException {
- DeflaterInputStream dis = new DeflaterInputStream(is);
- try {
- dis.reset();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- dis.close();
- try {
- dis.reset();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#skip()
- */
- public void testSkip() throws IOException {
- byte[] buf = new byte[1024];
- DeflaterInputStream dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- dis.skip(1);
- assertEquals(1, dis.available());
- assertEquals(22, dis.read(buf, 0, 1024));
- assertEquals(1, dis.available());
- dis.skip(1);
- assertEquals(0, dis.available());
- is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
- dis = new DeflaterInputStream(is);
- assertEquals(1, dis.available());
- dis.skip(56);
- assertEquals(0, dis.available());
- assertEquals(-1, dis.read(buf, 0, 1024));
- try {
- dis.skip(-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- assertEquals(0, dis.available());
- // can still skip
- dis.skip(1);
- dis.close();
- try {
- dis.skip(1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- dis.skip(-1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
- dis = new DeflaterInputStream(is);
- assertEquals(23, dis.skip(Long.MAX_VALUE));
- assertEquals(0, dis.available());
- }
-
- /**
- * @tests DeflaterInputStream#DeflaterInputStream(InputStream)
- */
- public void testDeflaterInputStreamInputStream() {
- // ok
- new DeflaterInputStream(is);
- // fail
- try {
- new DeflaterInputStream(null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#DeflaterInputStream(InputStream,Deflater)
- */
- public void testDeflaterInputStreamInputStreamDeflater() {
- // ok
- new DeflaterInputStream(is, new Deflater());
- // fail
- try {
- new DeflaterInputStream(is, null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DeflaterInputStream(null, new Deflater());
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests DeflaterInputStream#DeflaterInputStream(InputStream,Deflater,int)
- */
- public void testDeflaterInputStreamInputStreamDeflaterInt() {
- // ok
- new DeflaterInputStream(is, new Deflater(), 1024);
- // fail
- try {
- new DeflaterInputStream(is, null, 1024);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DeflaterInputStream(null, new Deflater(), 1024);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DeflaterInputStream(is, new Deflater(), -1);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- new DeflaterInputStream(null, new Deflater(), -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new DeflaterInputStream(is, null, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- is = new ByteArrayInputStream(testStr.getBytes("UTF-8"));
- }
-
- @Override
- protected void tearDown() throws Exception {
- is.close();
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
deleted file mode 100644
index c31e654..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterOutputStreamTest.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.Deflater;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.InflaterInputStream;
-
-import junit.framework.TestCase;
-
-public class DeflaterOutputStreamTest extends TestCase {
-
- private class MyDeflaterOutputStream extends DeflaterOutputStream {
- boolean deflateFlag = false;
-
- MyDeflaterOutputStream(OutputStream out) {
- super(out);
- }
-
- MyDeflaterOutputStream(OutputStream out, Deflater defl) {
- super(out, defl);
- }
-
- MyDeflaterOutputStream(OutputStream out, Deflater defl, int size) {
- super(out, defl, size);
- }
-
- byte[] getProtectedBuf() {
- return buf;
- }
-
- protected void deflate() throws IOException {
- deflateFlag = true;
- super.deflate();
- }
-
- boolean getDaflateFlag() {
- return deflateFlag;
- }
- }
-
- private byte outPutBuf[] = new byte[500];
-
- @Override
- protected void setUp() {
- // setting up a deflater to be used
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- int x = 0;
- Deflater deflate = new Deflater(1);
- deflate.setInput(byteArray);
- while (!(deflate.needsInput())) {
- x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- deflate.finish();
- while (!(deflate.finished())) {
- x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- deflate.end();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
- * java.util.zip.Deflater)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Deflater() throws Exception {
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- File f1 = new File("hyts_Constru(OD).tst");
- FileOutputStream fos = new FileOutputStream(f1);
- Deflater defl = null;
- MyDeflaterOutputStream dos;
- // Test for a null Deflater.
- try {
- dos = new MyDeflaterOutputStream(fos, defl);
- fail("NullPointerException Not Thrown");
- } catch (NullPointerException e) {
- }
- defl = new Deflater();
- dos = new MyDeflaterOutputStream(fos, defl);
-
- // Test to see if DeflaterOutputStream was created with the correct
- // buffer.
- assertEquals("Incorrect Buffer Size", 512, dos.getProtectedBuf().length);
-
- dos.write(byteArray);
- dos.close();
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() throws Exception {
- File f1 = new File("hyts_Constru(O).tst");
- FileOutputStream fos = new FileOutputStream(f1);
- MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
-
- // Test to see if DeflaterOutputStream was created with the correct
- // buffer.
- assertEquals("Incorrect Buffer Size", 512, dos.getProtectedBuf().length);
-
- dos.write(outPutBuf);
- dos.close();
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#DeflaterOutputStream(java.io.OutputStream,
- * java.util.zip.Deflater, int)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_DeflaterI()
- throws Exception {
- int buf = 5;
- int negBuf = -5;
- int zeroBuf = 0;
- byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
- File f1 = new File("hyts_Constru(ODI).tst");
- FileOutputStream fos = new FileOutputStream(f1);
- Deflater defl = null;
- MyDeflaterOutputStream dos;
-
- // Test for a null Deflater.
- try {
- dos = new MyDeflaterOutputStream(fos, defl, buf);
- fail("NullPointerException Not Thrown");
- } catch (NullPointerException e) {
- }
- defl = new Deflater();
-
- // Test for a negative buf.
- try {
- dos = new MyDeflaterOutputStream(fos, defl, negBuf);
- fail("IllegalArgumentException Not Thrown");
- } catch (IllegalArgumentException e) {
- }
-
- // Test for a zero buf.
- try {
- dos = new MyDeflaterOutputStream(fos, defl, zeroBuf);
- fail("IllegalArgumentException Not Thrown");
- } catch (IllegalArgumentException e) {
- }
-
- // Test to see if DeflaterOutputStream was created with the correct
- // buffer.
- dos = new MyDeflaterOutputStream(fos, defl, buf);
- assertEquals("Incorrect Buffer Size", 5, dos.getProtectedBuf().length);
-
- dos.write(byteArray);
- dos.close();
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#close()
- */
- public void test_close() throws Exception {
- File f1 = File.createTempFile("close", ".tst");
-
- InflaterInputStream iis = new InflaterInputStream(new FileInputStream(f1));
- try {
- iis.read();
- fail("EOFException Not Thrown");
- } catch (EOFException e) {
- }
-
- FileOutputStream fos = new FileOutputStream(f1);
- DeflaterOutputStream dos = new DeflaterOutputStream(fos);
- byte byteArray[] = {1, 3, 4, 6};
- dos.write(byteArray);
- dos.close();
-
- iis = new InflaterInputStream(new FileInputStream(f1));
-
- // Test to see if the finish method wrote the bytes to the file.
- assertEquals("Incorrect Byte Returned.", 1, iis.read());
- assertEquals("Incorrect Byte Returned.", 3, iis.read());
- assertEquals("Incorrect Byte Returned.", 4, iis.read());
- assertEquals("Incorrect Byte Returned.", 6, iis.read());
- assertEquals("Incorrect Byte Returned.", -1, iis.read());
- assertEquals("Incorrect Byte Returned.", -1, iis.read());
- iis.close();
-
- // Not sure if this test will stay.
- FileOutputStream fos2 = new FileOutputStream(f1);
- DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
- fos2.close();
- try {
- dos2.close();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- // Test to write to a closed DeflaterOutputStream
- try {
- dos.write(5);
- fail("DeflaterOutputStream Able To Write After Being Closed.");
- } catch (IOException e) {
- }
-
- // Test to write to a FileOutputStream that should have been closed
- // by
- // the DeflaterOutputStream.
- try {
- fos.write(("testing").getBytes());
- fail("FileOutputStream Able To Write After Being Closed.");
- } catch (IOException e) {
- }
-
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#finish()
- */
- public void test_finish() throws Exception {
- // Need test to see if method finish() actually finishes
- // Only testing possible errors, not if it actually works
-
- File f1 = new File("finish.tst");
- FileOutputStream fos1 = new FileOutputStream(f1);
- DeflaterOutputStream dos = new DeflaterOutputStream(fos1);
- byte byteArray[] = { 1, 3, 4, 6 };
- dos.write(byteArray);
- dos.finish();
-
- // Test to see if the same FileOutputStream can be used with the
- // DeflaterOutputStream after finish is called.
- try {
- dos.write(1);
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- // Test for writing with a new FileOutputStream using the same
- // DeflaterOutputStream.
- FileOutputStream fos2 = new FileOutputStream(f1);
- dos = new DeflaterOutputStream(fos2);
- dos.write(1);
-
- // Test for writing to FileOutputStream fos1, which should be open.
- fos1.write(("testing").getBytes());
-
- // Test for writing to FileOutputStream fos2, which should be open.
- fos2.write(("testing").getBytes());
-
- // Not sure if this test will stay.
- FileOutputStream fos3 = new FileOutputStream(f1);
- DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
- fos3.close();
- try {
- dos3.finish();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- // dos.close() won't close fos1 because it has been re-assigned to
- // fos2
- fos1.close();
- dos.close();
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#write(int)
- */
- public void test_writeI() throws Exception {
- File f1 = new File("writeI1.tst");
- FileOutputStream fos = new FileOutputStream(f1);
- DeflaterOutputStream dos = new DeflaterOutputStream(fos);
- for (int i = 0; i < 3; i++) {
- dos.write(i);
- }
- dos.close();
- FileInputStream fis = new FileInputStream(f1);
- InflaterInputStream iis = new InflaterInputStream(fis);
- for (int i = 0; i < 3; i++) {
- assertEquals("Incorrect Byte Returned.", i, iis.read());
- }
- assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
- assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
- iis.close();
-
- // Not sure if this test is that important.
- // Checks to see if you can write using the DeflaterOutputStream
- // after
- // the FileOutputStream has been closed.
- FileOutputStream fos2 = new FileOutputStream(f1);
- DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
- fos2.close();
- try {
- dos2.write(2);
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- f1.delete();
- }
-
- /**
- * @tests java.util.zip.DeflaterOutputStream#write(byte[], int, int)
- */
- public void test_write$BII() throws Exception {
- byte byteArray[] = { 1, 3, 4, 7, 8, 3, 6 };
-
- // Test to see if the correct bytes are saved.
- File f1 = new File("writeBII.tst");
- FileOutputStream fos1 = new FileOutputStream(f1);
- DeflaterOutputStream dos1 = new DeflaterOutputStream(fos1);
- dos1.write(byteArray, 2, 3);
- dos1.close();
- FileInputStream fis = new FileInputStream(f1);
- InflaterInputStream iis = new InflaterInputStream(fis);
- assertEquals("Incorrect Byte Returned.", 4, iis.read());
- assertEquals("Incorrect Byte Returned.", 7, iis.read());
- assertEquals("Incorrect Byte Returned.", 8, iis.read());
- assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
- assertEquals("Incorrect Byte Returned (EOF).", -1, iis.read());
- iis.close();
- f1.delete();
-
- // Test for trying to write more bytes than available from the array
- File f2 = new File("writeBII2.tst");
- FileOutputStream fos2 = new FileOutputStream(f2);
- DeflaterOutputStream dos2 = new DeflaterOutputStream(fos2);
- try {
- dos2.write(byteArray, 2, 10);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- }
-
- // Test for trying to write a negative number of bytes.
- try {
- dos2.write(byteArray, 2, Integer.MIN_VALUE);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- }
-
- // Test for trying to start writing from a byte < 0 from the array.
- try {
- dos2.write(byteArray, Integer.MIN_VALUE, 2);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- }
-
- // Test for trying to start writing from a byte > than the array
- // size.
- try {
- dos2.write(byteArray, 10, 2);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- }
- dos2.close();
-
- // Not sure if this test is that important.
- // Checks to see if you can write using the DeflaterOutputStream
- // after
- // the FileOutputStream has been closed.
- FileOutputStream fos3 = new FileOutputStream(f2);
- DeflaterOutputStream dos3 = new DeflaterOutputStream(fos3);
- fos3.close();
- try {
- dos3.write(byteArray, 2, 3);
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- f2.delete();
- }
-
- public void test_deflate() throws Exception {
- File f1 = File.createTempFile("writeI1", ".tst");
- FileOutputStream fos = new FileOutputStream(f1);
- MyDeflaterOutputStream dos = new MyDeflaterOutputStream(fos);
- assertFalse(dos.getDaflateFlag());
- for (int i = 0; i < 3; i++) {
- dos.write(i);
- }
- assertTrue(dos.getDaflateFlag());
- dos.close();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
deleted file mode 100644
index 8d3e7cd..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/DeflaterTest.java
+++ /dev/null
@@ -1,1102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.zip.Adler32;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-import junit.framework.TestCase;
-import tests.support.resource.Support_Resources;
-
-public class DeflaterTest extends TestCase {
-
- class MyDeflater extends Deflater {
- MyDeflater() {
- super();
- }
-
- MyDeflater(int lvl) {
- super(lvl);
- }
-
- MyDeflater(int lvl, boolean noHeader) {
- super(lvl, noHeader);
- }
-
- void myFinalize() {
- finalize();
- }
-
- int getDefCompression() {
- return DEFAULT_COMPRESSION;
- }
-
- int getDefStrategy() {
- return DEFAULT_STRATEGY;
- }
-
- int getHuffman() {
- return HUFFMAN_ONLY;
- }
-
- int getFiltered() {
- return FILTERED;
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#deflate(byte[])
- */
- public void test_deflate$B() {
- byte outPutBuf[] = new byte[50];
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- byte outPutInf[] = new byte[50];
- int x = 0;
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf);
- }
- assertEquals("Deflater at end of stream, should return 0", 0, defl
- .deflate(outPutBuf));
- int totalOut = defl.getTotalOut();
- int totalIn = defl.getTotalIn();
- assertEquals(x, totalOut);
- assertEquals(byteArray.length, totalIn);
- defl.end();
-
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- assertEquals(totalIn, infl.getTotalOut());
- assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(byteArray[i], outPutInf[i]);
- }
- assertEquals("Final decompressed data contained more bytes than original",
- 0, outPutInf[byteArray.length]);
- infl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#deflate(byte[], int, int)
- */
- public void test_deflate$BII() {
- byte outPutBuf[] = new byte[50];
- byte byteArray[] = { 5, 2, 3, 7, 8 };
- byte outPutInf[] = new byte[50];
- int offSet = 1;
- int length = outPutBuf.length - 1;
- int x = 0;
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf, offSet, length);
- }
- assertEquals("Deflater at end of stream, should return 0", 0, defl.deflate(
- outPutBuf, offSet, length));
- int totalOut = defl.getTotalOut();
- int totalIn = defl.getTotalIn();
- assertEquals(x, totalOut);
- assertEquals(byteArray.length, totalIn);
- defl.end();
-
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf, offSet, length);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- assertEquals(totalIn, infl.getTotalOut());
- assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(byteArray[i], outPutInf[i]);
- }
- assertEquals("Final decompressed data contained more bytes than original",
- 0, outPutInf[byteArray.length]);
- infl.end();
-
- // Set of tests testing the boundaries of the offSet/length
- defl = new Deflater();
- outPutBuf = new byte[100];
- defl.setInput(byteArray);
- for (int i = 0; i < 2; i++) {
- if (i == 0) {
- offSet = outPutBuf.length + 1;
- length = outPutBuf.length;
- } else {
- offSet = 0;
- length = outPutBuf.length + 1;
- }
- try {
- defl.deflate(outPutBuf, offSet, length);
- fail("Test " + i
- + ": ArrayIndexOutOfBoundsException not thrown");
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- }
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#end()
- */
- public void test_end() {
- byte byteArray[] = { 5, 2, 3, 7, 8 };
- byte outPutBuf[] = new byte[100];
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- defl.end();
- helper_end_test(defl, "end");
- }
-
- /**
- * @tests java.util.zip.Deflater#finalize()
- */
- public void test_finalize() {
- MyDeflater mdefl = new MyDeflater();
- mdefl.myFinalize();
- System.gc();
- helper_end_test(mdefl, "finalize");
- }
-
- /**
- * @tests java.util.zip.Deflater#finish()
- */
- public void test_finish() throws Exception {
- // This test already here, its the same as test_deflate()
- byte byteArray[] = { 5, 2, 3, 7, 8 };
- byte outPutBuf[] = new byte[100];
- byte outPutInf[] = new byte[100];
- int x = 0;
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
-
- // needsInput should never return true after finish() is called
- if (System.getProperty("java.vendor").startsWith("IBM")) {
- assertFalse("needsInput() should return false after finish() is called", defl
- .needsInput());
- }
-
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf);
- }
- int totalOut = defl.getTotalOut();
- int totalIn = defl.getTotalIn();
- assertEquals(x, totalOut);
- assertEquals(byteArray.length, totalIn);
- defl.end();
-
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- assertEquals(totalIn, infl.getTotalOut());
- assertEquals(totalOut, infl.getTotalIn());
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(byteArray[i], outPutInf[i]);
- }
- assertEquals("Final decompressed data contained more bytes than original",
- 0, outPutInf[byteArray.length]);
- infl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#finished()
- */
- public void test_finished() {
- byte byteArray[] = { 5, 2, 3, 7, 8 };
- byte outPutBuf[] = new byte[100];
- Deflater defl = new Deflater();
- assertTrue("Test 1: Deflater should not be finished.", !defl.finished());
- defl.setInput(byteArray);
- assertTrue("Test 2: Deflater should not be finished.", !defl.finished());
- defl.finish();
- assertTrue("Test 3: Deflater should not be finished.", !defl.finished());
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertTrue("Test 4: Deflater should be finished.", defl.finished());
- defl.end();
- assertTrue("Test 5: Deflater should be finished.", defl.finished());
- }
-
- /**
- * @tests java.util.zip.Deflater#getAdler()
- */
- public void test_getAdler() {
- byte byteArray[] = { 'a', 'b', 'c', 1, 2, 3 };
- byte outPutBuf[] = new byte[100];
- Deflater defl = new Deflater();
-
- // getting the checkSum value using the Adler
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- long checkSumD = defl.getAdler();
- defl.end();
-
- // getting the checkSum value through the Adler32 class
- Adler32 adl = new Adler32();
- adl.update(byteArray);
- long checkSumR = adl.getValue();
- assertEquals(
- "The checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
- checkSumD, checkSumR);
- }
-
- /**
- * @tests java.util.zip.Deflater#getTotalIn()
- */
- public void test_getTotalIn() {
- byte outPutBuf[] = new byte[5];
- byte byteArray[] = { 1, 3, 4, 7, 8 };
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertEquals(byteArray.length, defl.getTotalIn());
- defl.end();
-
- defl = new Deflater();
- int offSet = 2;
- int length = 3;
- outPutBuf = new byte[5];
- defl.setInput(byteArray, offSet, length);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertEquals(length, defl.getTotalIn());
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#getTotalOut()
- */
- public void test_getTotalOut() {
- // the getTotalOut should equal the sum of value returned by deflate()
- byte outPutBuf[] = new byte[5];
- byte byteArray[] = { 5, 2, 3, 7, 8 };
- int x = 0;
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf);
- }
- assertEquals(x, defl.getTotalOut());
- defl.end();
-
- x = 0;
- int offSet = 2;
- int length = 3;
- defl = new Deflater();
- outPutBuf = new byte[5];
- defl.setInput(byteArray, offSet, length);
- defl.finish();
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf);
- }
- assertEquals(x, defl.getTotalOut());
- }
-
- /**
- * @tests java.util.zip.Deflater#needsInput()
- */
- public void test_needsInput() {
- Deflater defl = new Deflater();
- assertTrue(
- "needsInput give the wrong boolean value as a result of no input buffer",
- defl.needsInput());
- byte byteArray[] = { 1, 2, 3 };
- defl.setInput(byteArray);
- assertFalse(
- "needsInput give wrong boolean value as a result of a full input buffer",
- defl.needsInput());
- byte[] outPutBuf = new byte[50];
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- byte emptyByteArray[] = new byte[0];
- defl.setInput(emptyByteArray);
- assertTrue(
- "needsInput give wrong boolean value as a result of an empty input buffer",
- defl.needsInput());
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- // needsInput should NOT return true after finish() has been
- // called.
- if (System.getProperty("java.vendor").startsWith("IBM")) {
- assertFalse(
- "needsInput gave wrong boolean value as a result of finish() being called",
- defl.needsInput());
- }
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#reset()
- */
- public void test_reset() {
- byte outPutBuf[] = new byte[100];
- byte outPutInf[] = new byte[100];
- byte curArray[] = new byte[5];
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- byte byteArray2[] = { 8, 7, 4, 3, 1 };
- int x = 0;
- int orgValue = 0;
- Deflater defl = new Deflater();
-
- for (int i = 0; i < 3; i++) {
- if (i == 0) {
- curArray = byteArray;
- } else if (i == 1) {
- curArray = byteArray2;
- } else {
- defl.reset();
- }
-
- defl.setInput(curArray);
- defl.finish();
- while (!defl.finished()) {
- x += defl.deflate(outPutBuf);
- }
-
- if (i == 0) {
- assertEquals(x, defl.getTotalOut());
- } else if (i == 1) {
- assertEquals(x, orgValue);
- } else {
- assertEquals(x, orgValue * 2);
- }
-
- if (i == 0) {
- orgValue = x;
- }
-
- try {
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- infl.end();
- } catch (DataFormatException e) {
- fail("Test " + i + ": Invalid input to be decompressed");
- }
-
- if (i == 1) {
- curArray = byteArray;
- }
-
- for (int j = 0; j < curArray.length; j++) {
- assertEquals(curArray[j], outPutInf[j]);
- }
- assertEquals(0, outPutInf[curArray.length]);
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#setDictionary(byte[])
- */
- public void test_setDictionary$B() {
- // This test is very close to getAdler()
- byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
- byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
- 'w', 'r' };
- byte outPutBuf[] = new byte[100];
-
- Deflater defl = new Deflater();
- long deflAdler = defl.getAdler();
- assertEquals("No dictionary set, no data deflated, getAdler should return 1",
- 1, deflAdler);
- defl.setDictionary(dictionaryArray);
- deflAdler = defl.getAdler();
-
- // getting the checkSum value through the Adler32 class
- Adler32 adl = new Adler32();
- adl.update(dictionaryArray);
- long realAdler = adl.getValue();
- assertEquals(deflAdler, realAdler);
-
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- deflAdler = defl.getAdler();
- adl = new Adler32();
- adl.update(byteArray);
- realAdler = adl.getValue();
- // Deflate is finished and there were bytes deflated that did not occur
- // in the dictionaryArray, therefore a new dictionary was automatically
- // set.
- assertEquals(realAdler, deflAdler);
- defl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#setDictionary(byte[], int, int)
- */
- public void test_setDictionary$BII() {
- // This test is very close to getAdler()
- byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3, 'o', 't' };
- byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
- 'w', 'r', 't', 'u', 'i', 'o', 4, 5, 6, 7 };
- byte outPutBuf[] = new byte[500];
-
- int offSet = 4;
- int length = 5;
-
- Deflater defl = new Deflater();
- long deflAdler = defl.getAdler();
- assertEquals("No dictionary set, no data deflated, getAdler should return 1",
- 1, deflAdler);
- defl.setDictionary(dictionaryArray, offSet, length);
- deflAdler = defl.getAdler();
-
- // getting the checkSum value through the Adler32 class
- Adler32 adl = new Adler32();
- adl.update(dictionaryArray, offSet, length);
- long realAdler = adl.getValue();
- assertEquals(deflAdler, realAdler);
-
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- deflAdler = defl.getAdler();
- adl = new Adler32();
- adl.update(byteArray);
- realAdler = adl.getValue();
- // Deflate is finished and there were bytes deflated that did not occur
- // in the dictionaryArray, therefore a new dictionary was automatically
- // set.
- assertEquals(realAdler, deflAdler);
- defl.end();
-
- // boundary check
- defl = new Deflater();
- for (int i = 0; i < 2; i++) {
- if (i == 0) {
- offSet = 0;
- length = dictionaryArray.length + 1;
- } else {
- offSet = dictionaryArray.length + 1;
- length = 1;
- }
- try {
- defl.setDictionary(dictionaryArray, offSet, length);
- fail(
- "Test "
- + i
- + ": boundary check for setDictionary failed for offset "
- + offSet + " and length " + length);
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#setInput(byte[])
- */
- public void test_setInput$B() {
- byte[] byteArray = { 1, 2, 3 };
- byte[] outPutBuf = new byte[50];
- byte[] outPutInf = new byte[50];
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray);
- assertTrue("the array buffer in setInput() is empty", !defl
- .needsInput());
- // The second setInput() should be ignored since needsInput() return
- // false
- defl.setInput(byteArray);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- defl.end();
-
- Inflater infl = new Inflater();
- try {
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(byteArray[i], outPutInf[i]);
- }
- assertEquals(byteArray.length, infl.getTotalOut());
- infl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#setInput(byte[], int, int)
- */
- public void test_setInput$BII() throws Exception {
- byte[] byteArray = { 1, 2, 3, 4, 5 };
- byte[] outPutBuf = new byte[50];
- byte[] outPutInf = new byte[50];
- int offSet = 1;
- int length = 3;
-
- Deflater defl = new Deflater();
- defl.setInput(byteArray, offSet, length);
- assertFalse("the array buffer in setInput() is empty", defl.needsInput());
- // The second setInput() should be ignored since needsInput() return
- // false
- defl.setInput(byteArray, offSet, length);
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- defl.end();
-
- Inflater infl = new Inflater();
- infl.setInput(outPutBuf);
- while (!infl.finished()) {
- infl.inflate(outPutInf);
- }
- for (int i = 0; i < length; i++) {
- assertEquals(byteArray[i + offSet], outPutInf[i]);
- }
- assertEquals(length, infl.getTotalOut());
- infl.end();
-
- // boundary check
- defl = new Deflater();
- for (int i = 0; i < 2; i++) {
- if (i == 0) {
- offSet = 0;
- length = byteArray.length + 1;
- } else {
- offSet = byteArray.length + 1;
- length = 1;
- }
- try {
- defl.setInput(byteArray, offSet, length);
- fail("Test " + i
- + ": boundary check for setInput failed for offset "
- + offSet + " and length " + length);
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#setLevel(int)
- */
- public void test_setLevelI() throws Exception {
- // Very similar to test_Constructor(int)
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- byte[] outPutBuf;
- int totalOut;
- for (int i = 0; i < 10; i++) {
- Deflater defl = new Deflater();
- defl.setLevel(i);
- outPutBuf = new byte[500];
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- totalOut = defl.getTotalOut();
- defl.end();
-
- outPutBuf = new byte[500];
- defl = new Deflater(i);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertEquals(totalOut, defl.getTotalOut());
- defl.end();
- }
-
- // testing boundaries
- try {
- Deflater boundDefl = new Deflater();
- // Level must be between 0-9
- boundDefl.setLevel(-2);
- fail(
- "IllegalArgumentException not thrown when setting level to a number < 0.");
- } catch (IllegalArgumentException e) {
- }
- try {
- Deflater boundDefl = new Deflater();
- boundDefl.setLevel(10);
- fail(
- "IllegalArgumentException not thrown when setting level to a number > 9.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#setStrategy(int)
- */
- public void test_setStrategyI() throws Exception {
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- for (int i = 0; i < 3; i++) {
- byte outPutBuf[] = new byte[500];
- MyDeflater mdefl = new MyDeflater();
-
- if (i == 0) {
- mdefl.setStrategy(mdefl.getDefStrategy());
- } else if (i == 1) {
- mdefl.setStrategy(mdefl.getHuffman());
- } else {
- mdefl.setStrategy(mdefl.getFiltered());
- }
-
- mdefl.setInput(byteArray);
- while (!mdefl.needsInput()) {
- mdefl.deflate(outPutBuf);
- }
- mdefl.finish();
- while (!mdefl.finished()) {
- mdefl.deflate(outPutBuf);
- }
-
- if (i == 0) {
- // System.out.println(mdefl.getTotalOut());
- // ran JDK and found that getTotalOut() = 86 for this particular
- // file
- assertEquals("getTotalOut() for the default strategy did not correspond with JDK",
- 86, mdefl.getTotalOut());
- } else if (i == 1) {
- // System.out.println(mdefl.getTotalOut());
- // ran JDK and found that getTotalOut() = 100 for this
- // particular file
- assertEquals("getTotalOut() for the Huffman strategy did not correspond with JDK",
- 100, mdefl.getTotalOut());
- } else {
- // System.out.println(mdefl.getTotalOut());
- // ran JDK and found that totalOut = 93 for this particular file
- assertEquals("Total Out for the Filtered strategy did not correspond with JDK",
- 93, mdefl.getTotalOut());
- }
- mdefl.end();
- }
-
- // Attempting to setStrategy to an invalid value
- try {
- Deflater defl = new Deflater();
- defl.setStrategy(-412);
- fail(
- "IllegalArgumentException not thrown when setting strategy to an invalid value.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#Deflater()
- */
- public void test_Constructor() throws Exception {
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- Deflater defl = new Deflater();
- byte[] outPutBuf = new byte[500];
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- int totalOut = defl.getTotalOut();
- defl.end();
-
- // creating a Deflater using the DEFAULT_COMPRESSION as the int
- MyDeflater mdefl = new MyDeflater();
- mdefl = new MyDeflater(mdefl.getDefCompression());
- outPutBuf = new byte[500];
- mdefl.setInput(byteArray);
- while (!mdefl.needsInput()) {
- mdefl.deflate(outPutBuf);
- }
- mdefl.finish();
- while (!mdefl.finished()) {
- mdefl.deflate(outPutBuf);
- }
- assertEquals(totalOut, mdefl.getTotalOut());
- mdefl.end();
- }
-
- /**
- * @tests java.util.zip.Deflater#Deflater(int, boolean)
- */
- public void test_ConstructorIZ() throws Exception {
- byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
- 'w', 'r' };
-
- Deflater defl = new Deflater();
- byte outPutBuf[] = new byte[500];
- defl.setLevel(2);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- int totalOut = defl.getTotalOut();
- defl.end();
-
- outPutBuf = new byte[500];
- defl = new Deflater(2, false);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertEquals(totalOut, defl.getTotalOut());
- defl.end();
-
- outPutBuf = new byte[500];
- defl = new Deflater(2, true);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertTrue(
- "getTotalOut() should not be equal comparing two Deflaters with different header options.",
- defl.getTotalOut() != totalOut);
- defl.end();
-
- byte outPutInf[] = new byte[500];
- Inflater infl = new Inflater(true);
- while (!infl.finished()) {
- if (infl.needsInput()) {
- infl.setInput(outPutBuf);
- }
- infl.inflate(outPutInf);
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals(byteArray[i], outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - constructorIZ",
- 0, outPutInf[byteArray.length]);
- infl.end();
-
- infl = new Inflater(false);
- outPutInf = new byte[500];
- int r = 0;
- try {
- while (!infl.finished()) {
- if (infl.needsInput()) {
- infl.setInput(outPutBuf);
- }
- infl.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- r = 1;
- }
- assertEquals("header option did not correspond", 1, r);
-
- // testing boundaries
- try {
- Deflater boundDefl = new Deflater();
- // Level must be between 0-9
- boundDefl.setLevel(-2);
- fail("IllegalArgumentException not thrown when setting level to a number < 0.");
- } catch (IllegalArgumentException e) {
- }
- try {
- Deflater boundDefl = new Deflater();
- boundDefl.setLevel(10);
- fail("IllegalArgumentException not thrown when setting level to a number > 9.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.Deflater#Deflater(int)
- */
- public void test_ConstructorI() throws Exception {
- byte[] byteArray = new byte[100];
- InputStream inFile = Support_Resources.getStream("hyts_checkInput.txt");
- inFile.read(byteArray);
- inFile.close();
-
- byte outPutBuf[] = new byte[500];
- Deflater defl = new Deflater(3);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- int totalOut = defl.getTotalOut();
- defl.end();
-
- // test to see if the compression ratio is the same as setting the level
- // on a deflater
- outPutBuf = new byte[500];
- defl = new Deflater();
- defl.setLevel(3);
- defl.setInput(byteArray);
- while (!defl.needsInput()) {
- defl.deflate(outPutBuf);
- }
- defl.finish();
- while (!defl.finished()) {
- defl.deflate(outPutBuf);
- }
- assertEquals(totalOut, defl.getTotalOut());
- defl.end();
-
- // testing boundaries
- try {
- Deflater boundDefl = new Deflater();
- // Level must be between 0-9
- boundDefl.setLevel(-2);
- fail("IllegalArgumentException not thrown when setting level to a number < 0.");
- } catch (IllegalArgumentException e) {
- }
- try {
- Deflater boundDefl = new Deflater();
- boundDefl.setLevel(10);
- fail("IllegalArgumentException not thrown when setting level to a number > 9.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- private void helper_end_test(Deflater defl, String desc) {
- // Help tests for test_end() and test_reset().
- byte byteArray[] = { 5, 2, 3, 7, 8 };
-
- // Methods where we expect IllegalStateException or NullPointerException
- // to be thrown
- try {
- defl.getTotalOut();
- fail("defl.getTotalOut() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- defl.getTotalIn();
- fail("defl.getTotalIn() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- defl.getAdler();
- fail("defl.getAdler() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- byte[] dict = { 'a', 'b', 'c' };
- defl.setDictionary(dict);
- fail("defl.setDictionary() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- defl.getTotalIn();
- fail("defl.getTotalIn() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- defl.getTotalIn();
- fail("defl.getTotalIn() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
- try {
- defl.deflate(byteArray);
- fail("defl.deflate() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- } catch (NullPointerException e) {
- }
-
- // Methods where we expect NullPointerException to be thrown
- try {
- defl.reset();
- fail("defl.reset() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (NullPointerException e) {
- }
-
- // Methods that should be allowed to be called after end() is called
- defl.needsInput();
- defl.setStrategy(1);
- defl.setLevel(1);
- defl.end();
-
- // Methods where exceptions should be thrown
- String vendor = System.getProperty("java.vendor");
- if (vendor.indexOf("IBM") != -1) {
- try {
- defl.setInput(byteArray);
- fail("defl.setInput() can still be used after " + desc
- + " is called in test_" + desc);
- } catch (IllegalStateException e) {
- }
- }
- }
-
- /**
- * @tests java.util.zip.Deflater()
- */
- public void test_needsDictionary() {
- Deflater inf = new Deflater();
- assertEquals(0, inf.getTotalIn());
- assertEquals(0, inf.getTotalOut());
- assertEquals(0, inf.getBytesRead());
- assertEquals(0, inf.getBytesWritten());
- }
-
- /**
- * @throws DataFormatException
- * @throws UnsupportedEncodingException
- * @tests java.util.zip.Deflater#getBytesRead()
- */
- public void test_getBytesRead() throws DataFormatException,
- UnsupportedEncodingException {
- // Regression test for HARMONY-158
- Deflater def = new Deflater();
- assertEquals(0, def.getTotalIn());
- assertEquals(0, def.getTotalOut());
- assertEquals(0, def.getBytesRead());
- // Encode a String into bytes
- String inputString = "blahblahblah??";
- byte[] input = inputString.getBytes("UTF-8");
-
- // Compress the bytes
- byte[] output = new byte[100];
- def.setInput(input);
- def.finish();
- int compressedDataLength = def.deflate(output);
- assertEquals(14, def.getTotalIn());
- assertEquals(compressedDataLength, def.getTotalOut());
- assertEquals(14, def.getBytesRead());
- }
-
- /**
- * @throws DataFormatException
- * @throws UnsupportedEncodingException
- * @tests java.util.zip.Deflater#getBytesRead()
- */
- public void test_getBytesWritten() throws DataFormatException,
- UnsupportedEncodingException {
- // Regression test for HARMONY-158
- Deflater def = new Deflater();
- assertEquals(0, def.getTotalIn());
- assertEquals(0, def.getTotalOut());
- assertEquals(0, def.getBytesWritten());
- // Encode a String into bytes
- String inputString = "blahblahblah??";
- byte[] input = inputString.getBytes("UTF-8");
-
- // Compress the bytes
- byte[] output = new byte[100];
- def.setInput(input);
- def.finish();
- int compressedDataLength = def.deflate(output);
- assertEquals(14, def.getTotalIn());
- assertEquals(compressedDataLength, def.getTotalOut());
- assertEquals(compressedDataLength, def.getBytesWritten());
- }
-
- //Regression Test for HARMONY-2481
- public void test_deflate_beforeSetInput() throws Exception {
- Deflater deflater = new Deflater();
- deflater.finish();
- byte[] buffer = new byte[1024];
- assertEquals(8, deflater.deflate(buffer));
- byte[] expectedBytes = { 120, -100, 3, 0, 0, 0, 0, 1 };
- for (int i = 0; i < expectedBytes.length; i++) {
- assertEquals(expectedBytes[i], buffer[i]);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
deleted file mode 100644
index e969387..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPInputStreamTest.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.zip.Checksum;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-
-import tests.support.resource.Support_Resources;
-
-public class GZIPInputStreamTest extends junit.framework.TestCase {
- File resources;
-
- class TestGZIPInputStream extends GZIPInputStream {
- TestGZIPInputStream(InputStream in) throws IOException {
- super(in);
- }
-
- TestGZIPInputStream(InputStream in, int size) throws IOException {
- super(in, size);
- }
-
- Checksum getChecksum() {
- return crc;
- }
-
- boolean endofInput() {
- return eos;
- }
- }
-
- /**
- * @tests java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() {
- // test method java.util.zip.GZIPInputStream.constructor
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").toURL();
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream());
- assertNotNull("the constructor for GZIPInputStream is null",
- inGZIP);
- assertEquals("the CRC value of the inputStream is not zero", 0, inGZIP
- .getChecksum().getValue());
- inGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to open the input file");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPInputStream#GZIPInputStream(java.io.InputStream,
- * int)
- */
- public void test_ConstructorLjava_io_InputStreamI() {
- // test method java.util.zip.GZIPInputStream.constructorI
- try {
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- final URL gInput = new File(resources.toString()
- + "/GZIPInputStream/hyts_gInput.txt.gz").toURL();
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream(), 200);
- assertNotNull("the constructor for GZIPInputStream is null",
- inGZIP);
- assertEquals("the CRC value of the inputStream is not zero", 0, inGZIP
- .getChecksum().getValue());
- inGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to open the input file");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPInputStream#read(byte[], int, int)
- */
- public void test_read$BII() throws IOException {
- // test method java.util.zip.GZIPInputStream.readBII
- byte orgBuf[] = { '3', '5', '2', 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
- byte outBuf[] = new byte[100];
- int result = 0;
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- String resPath = resources.toString();
- if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
- resPath = resPath.substring(1);
- }
- final URL gInput = new URL("file:/" + resPath
- + "/GZIPInputStream/hyts_gInput.txt.gz");
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream());
- while (!(inGZIP.endofInput())) {
- result += inGZIP.read(outBuf, result, outBuf.length - result);
- }
- assertEquals(
- "the checkSum value of the compressed and decompressed data does not equal",
- 2074883667L, inGZIP.getChecksum().getValue());
- for (int i = 0; i < orgBuf.length; i++) {
- assertTrue(
- "the decompressed data does not equal the original data decompressed",
- orgBuf[i] == outBuf[i]);
- // System.out.println(orgBuf[i] + " " + outBuf[i]);
- }
- int r = 0;
- try {
- inGZIP.read(outBuf, 100, 1);
- } catch (IndexOutOfBoundsException e) {
- r = 1;
- }
- inGZIP.close();
- // line below fails on RI also, comment out.
- // assertEquals("Boundary Check was not present", 1, r);
-
- // Create compressed data which is exactly 512 bytes (after the
- // header),
- // the size of the InflaterStream internal buffer
- byte[] test = new byte[507];
- for (int i = 0; i < 256; i++) {
- test[i] = (byte) i;
- }
- for (int i = 256; i < test.length; i++) {
- test[i] = (byte) (256 - i);
- }
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- GZIPOutputStream out = new GZIPOutputStream(bout);
- out.write(test);
- out.close();
- byte[] comp = bout.toByteArray();
- GZIPInputStream gin2 = new GZIPInputStream(new ByteArrayInputStream(
- comp), 512);
- int total = 0;
- while ((result = gin2.read(test)) != -1) {
- total += result;
- }
- assertEquals("Should return -1", -1, gin2.read());
- gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
-
- gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
- total = 0;
- while ((result = gin2.read(new byte[200])) != -1) {
- total += result;
- }
- assertEquals("Should return -1", -1, gin2.read());
- gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
-
- gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 516);
- total = 0;
- while ((result = gin2.read(new byte[200])) != -1) {
- total += result;
- }
- assertEquals("Should return -1", -1, gin2.read());
- gin2.close();
- assertTrue("Incorrectly decompressed", total == test.length);
-
- comp[40] = 0;
- gin2 = new GZIPInputStream(new ByteArrayInputStream(comp), 512);
- boolean exception = false;
- try {
- while (gin2.read(test) != -1) {
- ;
- }
- } catch (IOException e) {
- exception = true;
- }
- assertTrue("Exception expected", exception);
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- GZIPOutputStream zipout = new GZIPOutputStream(baos);
- zipout.write(test);
- zipout.close();
- outBuf = new byte[530];
- GZIPInputStream in= new GZIPInputStream(new ByteArrayInputStream(baos.toByteArray()));
- try {
- in.read(outBuf, 530, 1);
- fail("Test failed IOOBE was not thrown");
- } catch (IndexOutOfBoundsException e) {
- }
- while (true) {
- result = in.read(outBuf, 0, 5);
- if (result == -1) {
- //"EOF was reached";
- break;
- }
- }
- result = -10;
- result = in.read(null, 100, 1);
- result = in.read(outBuf, -100, 1);
- result = in.read(outBuf, -1, 1);// 100, 1);
- }
-
- /**
- * @tests java.util.zip.GZIPInputStream#close()
- */
- public void test_close() {
- // test method java.util.zip.GZIPInputStream.close
- byte outBuf[] = new byte[100];
- try {
- int result = 0;
- Support_Resources.copyFile(resources, "GZIPInputStream",
- "hyts_gInput.txt.gz");
- String resPath = resources.toString();
- if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\') {
- resPath = resPath.substring(1);
- }
- final URL gInput = new URL("file:/" + resPath
- + "/GZIPInputStream/hyts_gInput.txt.gz");
- TestGZIPInputStream inGZIP = new TestGZIPInputStream(gInput
- .openConnection().getInputStream());
- while (!(inGZIP.endofInput())) {
- result += inGZIP.read(outBuf, result, outBuf.length - result);
- }
- assertEquals("the checkSum value of the compressed and decompressed data does not equal",
- 2074883667L, inGZIP.getChecksum().getValue());
- inGZIP.close();
- int r = 0;
- try {
- inGZIP.read(outBuf, 0, 1);
- } catch (IOException e) {
- r = 1;
- }
- assertEquals("GZIPInputStream can still be used after close is called",
- 1, r);
- } catch (IOException e) {
- e.printStackTrace();
- fail("unexpected: " + e);
- }
- }
-
- /**
- * Regression test for HARMONY-3703.
- * @tests java.util.zip.GZIPInputStream#read()
- */
- public void test_read() throws IOException {
- GZIPInputStream gis = null;
- int result = 0;
- byte[] buffer = new byte[] {1,2,3,4,5,6,7,8,9,10};
- File f = new File(resources.getAbsolutePath() + "test.gz");
- FileOutputStream out = new FileOutputStream(f);
- GZIPOutputStream gout = new GZIPOutputStream(out);
-
- // write 100 bytes to the stream
- for(int i = 0; i < 10; i++) {
- gout.write(buffer);
- }
- gout.finish();
- out.write(1);
- out.close();
-
- gis = new GZIPInputStream(new FileInputStream(f));
- buffer = new byte[100];
- gis.read(buffer);
- result = gis.read();
- gis.close();
- f.delete();
-
- assertEquals("Incorrect value returned at the end of the file", -1, result);
- }
-
- @Override
- protected void setUp() {
- resources = Support_Resources.createTempFolder();
- }
-
- @Override
- protected void tearDown() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
deleted file mode 100644
index f381cd1..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/GZIPOutputStreamTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.zip.Checksum;
-import java.util.zip.GZIPOutputStream;
-
-public class GZIPOutputStreamTest extends junit.framework.TestCase {
-
- class TestGZIPOutputStream extends GZIPOutputStream {
- TestGZIPOutputStream(OutputStream out) throws IOException {
- super(out);
- }
-
- TestGZIPOutputStream(OutputStream out, int size) throws IOException {
- super(out, size);
- }
-
- Checksum getChecksum() {
- return crc;
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() {
- try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
- TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
- assertNotNull("the constructor for GZIPOutputStream is null",
- outGZIP);
- assertEquals("the CRC value of the outputStream is not zero", 0, outGZIP
- .getChecksum().getValue());
- outGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to find the output file or creating GZIP constructor");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#GZIPOutputStream(java.io.OutputStream,
- * int)
- */
- public void test_ConstructorLjava_io_OutputStreamI() {
- try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutCon.txt");
- TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile,
- 100);
- assertNotNull("the constructor for GZIPOutputStream is null",
- outGZIP);
- assertEquals("the CRC value of the outputStream is not zero", 0, outGZIP
- .getChecksum().getValue());
- outGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to find the output file or creating GZIP constructor");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#finish()
- */
- public void test_finish() {
- // test method java.util.zip.GZIPOutputStream.finish()
- byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
- try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutFinish.txt");
- TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
-
- outGZIP.finish();
- int r = 0;
- try {
- outGZIP.write(byteArray, 0, 1);
- } catch (IOException e) {
- r = 1;
- }
-
- assertEquals("GZIP instance can still be used after finish is called",
- 1, r);
- outGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to find the output file or creating GZIP constructor");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#close()
- */
- public void test_close() {
- // test method java.util.zip.GZIPOutputStream.close()
- byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
- try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutClose2.txt");
- TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
- outGZIP.close();
- int r = 0;
- try {
- outGZIP.write(byteArray, 0, 1);
- } catch (IOException e) {
- r = 1;
- }
- assertEquals("GZIP instance can still be used after close is called",
- 1, r);
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to find the output file or creating GZIP constructor");
- }
- }
-
- /**
- * @tests java.util.zip.GZIPOutputStream#write(byte[], int, int)
- */
- public void test_write$BII() {
- // test method java.util.zip.GZIPOutputStream.writeBII
- byte byteArray[] = { 3, 5, 2, 'r', 'g', 'e', 'f', 'd', 'e', 'w' };
- try {
- FileOutputStream outFile = new FileOutputStream("GZIPOutWrite.txt");
- TestGZIPOutputStream outGZIP = new TestGZIPOutputStream(outFile);
- outGZIP.write(byteArray, 0, 10);
- // ran JDK and found this CRC32 value is 3097700292
- // System.out.print(outGZIP.getChecksum().getValue());
- assertEquals("the checksum value was incorrect result of write from GZIP",
- 3097700292L, outGZIP.getChecksum().getValue());
-
- // test for boundary check
- int r = 0;
- try {
- outGZIP.write(byteArray, 0, 11);
- } catch (IndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("out of bounds exception is not present", 1, r);
- outGZIP.close();
- } catch (IOException e) {
- fail(
- "an IO error occured while trying to find the output file or creating GZIP constructor");
- }
- }
-
- @Override
- protected void setUp() {
- }
-
- @Override
- protected void tearDown() {
-
- try {
- File dFile = new File("GZIPOutCon.txt");
- dFile.delete();
- File dFile2 = new File("GZIPOutFinish.txt");
- dFile2.delete();
- File dFile3 = new File("GZIPOutWrite.txt");
- dFile3.delete();
- File dFile4 = new File("GZIPOutClose2.txt");
- dFile4.delete();
- } catch (SecurityException e) {
- fail("Cannot delete file for security reasons");
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
deleted file mode 100644
index 8f37652..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterInputStreamTest.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterInputStream;
-
-import junit.framework.TestCase;
-import tests.support.resource.Support_Resources;
-
-public class InflaterInputStreamTest extends TestCase {
-
- // files hyts_constru(O),hyts_constru(OD),hyts_constru(ODI) needs to be
- // included as resources
- // android-changed: we removed the parentheses for the benefit of our broken build system.
- byte outPutBuf[] = new byte[500];
-
- class MyInflaterInputStream extends InflaterInputStream {
- MyInflaterInputStream(InputStream in) {
- super(in);
- }
-
- MyInflaterInputStream(InputStream in, Inflater infl) {
- super(in, infl);
- }
-
- MyInflaterInputStream(InputStream in, Inflater infl, int size) {
- super(in, infl, size);
- }
-
- void myFill() throws IOException {
- fill();
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- //FIXME This test doesn't pass in Harmony classlib or Sun 5.0_7 RI
- /*
- int result = 0;
- int buffer[] = new int[500];
- InputStream infile = Support_Resources
- .getStream("hyts_constru_O.txt"); // android-changed
-
- InflaterInputStream inflatIP = new InflaterInputStream(infile);
-
- int i = 0;
- while ((result = inflatIP.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP.close();
- */
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
- * java.util.zip.Inflater)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_Inflater() throws IOException {
- byte byteArray[] = new byte[100];
- InputStream infile = Support_Resources.getStream("hyts_constru_OD.txt"); // android-changed
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile,
- inflate);
-
- inflatIP.read(byteArray, 0, 5);// only suppose to read in 5 bytes
- inflatIP.close();
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#InflaterInputStream(java.io.InputStream,
- * java.util.zip.Inflater, int)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_util_zip_InflaterI() throws IOException {
- int result = 0;
- int buffer[] = new int[500];
- InputStream infile = Support_Resources.getStream("hyts_constru_ODI.txt"); // android-changed
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile,
- inflate, 1);
-
- int i = 0;
- while ((result = inflatIP.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP.close();
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#mark(int)
- */
- public void test_markI() {
- InputStream is = new ByteArrayInputStream(new byte[10]);
- InflaterInputStream iis = new InflaterInputStream(is);
- // mark do nothing, do no check
- iis.mark(0);
- iis.mark(-1);
- iis.mark(10000000);
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#markSupported()
- */
- public void test_markSupported() {
- InputStream is = new ByteArrayInputStream(new byte[10]);
- InflaterInputStream iis = new InflaterInputStream(is);
- assertFalse(iis.markSupported());
- assertTrue(is.markSupported());
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#read()
- */
- public void test_read() throws IOException {
- int result = 0;
- int buffer[] = new int[500];
- byte orgBuffer[] = { 1, 3, 4, 7, 8 };
- InputStream infile = Support_Resources
- .getStream("hyts_constru_OD.txt"); // android-changed
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile,
- inflate);
-
- int i = 0;
- while ((result = inflatIP.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP.close();
-
- for (int j = 0; j < orgBuffer.length; j++) {
- assertTrue(
- "original compressed data did not equal decompressed data",
- buffer[j] == orgBuffer[j]);
- }
- }
-
- public void testAvailableNonEmptySource() throws Exception {
- // this byte[] is a deflation of these bytes: { 1, 3, 4, 6 }
- byte[] deflated = { 72, -119, 99, 100, 102, 97, 3, 0, 0, 31, 0, 15, 0 };
- InputStream in = new InflaterInputStream(new ByteArrayInputStream(deflated));
- // InflaterInputStream.available() returns either 1 or 0, even though
- // that contradicts the behavior defined in InputStream.available()
- assertEquals(1, in.read());
- assertEquals(1, in.available());
- assertEquals(3, in.read());
- assertEquals(1, in.available());
- assertEquals(4, in.read());
- assertEquals(1, in.available());
- assertEquals(6, in.read());
- assertEquals(0, in.available());
- assertEquals(-1, in.read());
- assertEquals(-1, in.read());
- }
-
- public void testAvailableSkip() throws Exception {
- // this byte[] is a deflation of these bytes: { 1, 3, 4, 6 }
- byte[] deflated = { 72, -119, 99, 100, 102, 97, 3, 0, 0, 31, 0, 15, 0 };
- InputStream in = new InflaterInputStream(new ByteArrayInputStream(deflated));
- assertEquals(1, in.available());
- assertEquals(4, in.skip(4));
- assertEquals(0, in.available());
- }
-
- public void testAvailableEmptySource() throws Exception {
- // this byte[] is a deflation of the empty file
- byte[] deflated = { 120, -100, 3, 0, 0, 0, 0, 1 };
- InputStream in = new InflaterInputStream(new ByteArrayInputStream(deflated));
- assertEquals(-1, in.read());
- assertEquals(-1, in.read());
- assertEquals(0, in.available());
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#read(byte[], int, int)
- */
- public void test_read$BII() throws IOException{
- byte[] test = new byte[507];
- for (int i = 0; i < 256; i++) {
- test[i] = (byte) i;
- }
- for (int i = 256; i < test.length; i++) {
- test[i] = (byte) (256 - i);
- }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DeflaterOutputStream dos = new DeflaterOutputStream(baos);
- dos.write(test);
- dos.close();
- InputStream is = new ByteArrayInputStream(baos.toByteArray());
- InflaterInputStream iis = new InflaterInputStream(is);
- byte[] outBuf = new byte[530];
- int result = 0;
- while (true) {
- result = iis.read(outBuf, 0, 5);
- if (result == -1) {
- //"EOF was reached";
- break;
- }
- }
- try {
- iis.read(outBuf, -1, 10);
- fail("should throw IOOBE.");
- } catch (IndexOutOfBoundsException e) {
- // expected;
- }
- }
-
- public void test_read$BII2() throws IOException {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
- InflaterInputStream iis = new InflaterInputStream(fis);
- byte[] outBuf = new byte[530];
-
- iis.close();
- try {
- iis.read(outBuf, 0, 5);
- fail("IOException expected");
- } catch (IOException ee) {
- // expected.
- }
- }
-
- public void test_read$BII3() throws IOException {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
- InflaterInputStream iis = new InflaterInputStream(fis);
- byte[] outBuf = new byte[530];
-
- try {
- iis.read();
- fail("IOException expected.");
- } catch (IOException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#reset()
- */
- public void test_reset() {
- InputStream is = new ByteArrayInputStream(new byte[10]);
- InflaterInputStream iis = new InflaterInputStream(is);
- try {
- iis.reset();
- fail("Should throw IOException");
- } catch (IOException e) {
- // correct
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#skip(long)
- */
- public void test_skipJ() throws IOException {
- InputStream is = Support_Resources.getStream("hyts_available.tst");
- InflaterInputStream iis = new InflaterInputStream(is);
-
- // Tests for skipping a negative number of bytes.
- try {
- iis.skip(-3);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- assertEquals("Incorrect Byte Returned.", 5, iis.read());
-
- try {
- iis.skip(Integer.MIN_VALUE);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- assertEquals("Incorrect Byte Returned.", 4, iis.read());
-
- // Test to make sure the correct number of bytes were skipped
- assertEquals("Incorrect Number Of Bytes Skipped.", 3, iis.skip(3));
-
- // Test to see if the number of bytes skipped returned is true.
- assertEquals("Incorrect Byte Returned.", 7, iis.read());
-
- assertEquals("Incorrect Number Of Bytes Skipped.", 0, iis.skip(0));
- assertEquals("Incorrect Byte Returned.", 0, iis.read());
-
- // Test for skipping more bytes than available in the stream
- assertEquals("Incorrect Number Of Bytes Skipped.", 2, iis.skip(4));
- assertEquals("Incorrect Byte Returned.", -1, iis.read());
- iis.close();
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#skip(long)
- */
- public void test_skipJ2() throws IOException {
- int result = 0;
- int buffer[] = new int[100];
- byte orgBuffer[] = { 1, 3, 4, 7, 8 };
-
- // testing for negative input to skip
- InputStream infile = Support_Resources
- .getStream("hyts_constru_OD.txt"); // android-changed
- Inflater inflate = new Inflater();
- InflaterInputStream inflatIP = new InflaterInputStream(infile,
- inflate, 10);
- long skip;
- try {
- skip = inflatIP.skip(Integer.MIN_VALUE);
- fail("Expected IllegalArgumentException when skip() is called with negative parameter");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- inflatIP.close();
-
- // testing for number of bytes greater than input.
- InputStream infile2 = Support_Resources
- .getStream("hyts_constru_OD.txt"); // android-changed
- InflaterInputStream inflatIP2 = new InflaterInputStream(infile2);
-
- // looked at how many bytes the skip skipped. It is
- // 5 and its supposed to be the entire input stream.
-
- skip = inflatIP2.skip(Integer.MAX_VALUE);
- // System.out.println(skip);
- assertEquals("method skip() returned wrong number of bytes skipped",
- 5, skip);
-
- // test for skipping of 2 bytes
- InputStream infile3 = Support_Resources
- .getStream("hyts_constru_OD.txt"); // android-changed
- InflaterInputStream inflatIP3 = new InflaterInputStream(infile3);
- skip = inflatIP3.skip(2);
- assertEquals("the number of bytes returned by skip did not correspond with its input parameters",
- 2, skip);
- int i = 0;
- result = 0;
- while ((result = inflatIP3.read()) != -1) {
- buffer[i] = result;
- i++;
- }
- inflatIP2.close();
-
- for (int j = 2; j < orgBuffer.length; j++) {
- assertTrue(
- "original compressed data did not equal decompressed data",
- buffer[j - 2] == orgBuffer[j]);
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#available()
- */
- public void test_available() throws IOException {
- InputStream is = Support_Resources.getStream("hyts_available.tst");
- InflaterInputStream iis = new InflaterInputStream(is);
-
- int available;
- for (int i = 0; i < 11; i++) {
- iis.read();
- available = iis.available();
- if (available == 0) {
- assertEquals("Expected no more bytes to read", -1, iis.read());
- } else {
- assertEquals("Bytes Available Should Return 1.", 1, available);
- }
- }
-
- iis.close();
- try {
- iis.available();
- fail("available after close should throw IOException.");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterInputStream#close()
- */
- public void test_close() throws IOException {
- InflaterInputStream iin = new InflaterInputStream(
- new ByteArrayInputStream(new byte[0]));
- iin.close();
-
- // test for exception
- iin.close();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterOutputStreamTest.java
deleted file mode 100644
index cf3e20e..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterOutputStreamTest.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-import java.util.zip.InflaterOutputStream;
-import java.util.zip.ZipException;
-
-import junit.framework.TestCase;
-
-public class InflaterOutputStreamTest extends TestCase {
-
- private ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- private byte[] compressedBytes = new byte[100];
-
- private String testString = "Hello world";
-
- /**
- * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() throws IOException {
- new InflaterOutputStream(os);
-
- try {
- new InflaterOutputStream(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream,Inflater)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_Inflater() {
- new InflaterOutputStream(os, new Inflater());
-
- try {
- new InflaterOutputStream(null, new Inflater());
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(os, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#InflaterOutputStream(java.io.OutputStream,Inflater,int)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_util_zip_InflaterI() {
- new InflaterOutputStream(os, new Inflater(), 20);
-
- try {
- new InflaterOutputStream(null, null, 10);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(null, new Inflater(), -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(os, null, -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(null, null, -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(os, new Inflater(), 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- new InflaterOutputStream(os, new Inflater(), -10000);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#close()
- */
- public void test_close() throws IOException {
- InflaterOutputStream ios = new InflaterOutputStream(os);
- ios.close();
- // multiple close
- ios.close();
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#flush()
- */
- public void test_flush() throws IOException {
- InflaterOutputStream ios = new InflaterOutputStream(os);
- ios.close();
- try {
- ios.flush();
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- ios = new InflaterOutputStream(os);
- ios.flush();
- ios.flush();
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#finish()
- */
- public void test_finish() throws IOException {
- InflaterOutputStream ios = new InflaterOutputStream(os);
- ios.close();
- try {
- ios.finish();
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- ios = new InflaterOutputStream(os);
- ios.finish();
- ios.finish();
- ios.flush();
- ios.flush();
- ios.finish();
-
- byte[] bytes1 = {10,20,30,40,50};
- Deflater defaultDeflater = new Deflater(Deflater.BEST_SPEED);
- defaultDeflater.setInput(bytes1);
- defaultDeflater.finish();
- int length1 = defaultDeflater.deflate(compressedBytes);
-
- byte[] bytes2 = {100,90,80,70,60};
- Deflater bestDeflater = new Deflater(Deflater.BEST_COMPRESSION );
- bestDeflater.setInput(bytes2);
- bestDeflater.finish();
- int length2 = bestDeflater.deflate(compressedBytes,length1,compressedBytes.length-length1);
-
- ios = new InflaterOutputStream(os);
- for (int i = 0; i < length1; i++) {
- ios.write(compressedBytes[i]);
- }
- ios.finish();
- ios.close();
-
- byte[] result = os.toByteArray();
- for(int i =0;i<bytes1.length; i++){
- assertEquals(bytes1[i],result[i]);
- }
-
- ios = new InflaterOutputStream(os);
- for (int i = length1; i < length2*2; i++) {
- ios.write(compressedBytes[i]);
- }
- ios.finish();
- ios.close();
-
- result = os.toByteArray();
- for(int i =0;i<bytes2.length; i++){
- assertEquals(bytes2[i],result[bytes1.length+i]);
- }
-
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#write(int)
- */
- public void test_write_I() throws IOException {
- int length = compressToBytes(testString);
-
- // uncompress the data stored in the compressedBytes
- InflaterOutputStream ios = new InflaterOutputStream(os);
- for (int i = 0; i < length; i++) {
- ios.write(compressedBytes[i]);
- }
-
- String result = new String(os.toByteArray());
- assertEquals(testString, result);
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#write(int)
- */
- public void test_write_I_Illegal() throws IOException {
-
- // write after close
- InflaterOutputStream ios = new InflaterOutputStream(os);
- ios.close();
- try {
- ios.write(-1);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#write(byte[],int,int)
- */
- public void test_write_$BII() throws IOException {
- int length = compressToBytes(testString);
-
- // uncompress the data stored in the compressedBytes
- InflaterOutputStream ios = new InflaterOutputStream(os);
- ios.write(compressedBytes, 0, length);
-
- String result = new String(os.toByteArray());
- assertEquals(testString, result);
- }
-
- /**
- * @tests java.util.zip.InflaterOutputStream#write(byte[],int,int)
- */
- public void test_write_$BII_Illegal() throws IOException {
- // write error compression (ZIP) format
- InflaterOutputStream ios = new InflaterOutputStream(os);
- byte[] bytes = { 0, 1, 2, 3 };
- try {
- ios.write(bytes, 0, 4);
- fail("Should throw ZipException");
- } catch (ZipException e) {
- // expected
- }
- try {
- ios.flush();
- fail("Should throw ZipException");
- } catch (ZipException e) {
- // expected
- }
-
- // write after close
- ios = new InflaterOutputStream(os);
- ios.close();
- try {
- ios.write(bytes, 0, 4);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- ios.write(bytes, -1, 4);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- ios.write(bytes, -1, -4);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- ios.write(bytes, 0, 400);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- try {
- ios.write(null, -1, 4);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- ios = new InflaterOutputStream(os);
- try {
- ios.write(null, 0, 4);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- ios.write(null, -1, 4);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- ios.write(null, 0, -4);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- ios.write(null, 0, 1000);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- ios.write(bytes, -1, 4);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ios.write(bytes, 0, -4);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ios.write(bytes, 0, 100);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ios.write(bytes, -100, 100);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- ios = new InflaterOutputStream(os);
- ios.finish();
-
- try {
- ios.write(bytes, -1,-100);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ios.write(null, -1,-100);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- ios = new InflaterOutputStream(os);
- ios.flush();
- try {
- ios.write(bytes, 0, 4);
- fail("Should throw ZipException");
- } catch (ZipException e) {
- // expected
- }
- }
-
- // Compress the test string into compressedBytes
- private int compressToBytes(String string) {
- byte[] input = string.getBytes();
- Deflater deflater = new Deflater();
- deflater.setInput(input);
- deflater.finish();
- return deflater.deflate(compressedBytes);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
deleted file mode 100644
index 9ec9213..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/InflaterTest.java
+++ /dev/null
@@ -1,1031 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.BufferedInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.zip.Adler32;
-import java.io.UnsupportedEncodingException;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-import java.util.zip.ZipException;
-
-import tests.support.resource.Support_Resources;
-
-public class InflaterTest extends junit.framework.TestCase {
- byte outPutBuff1[] = new byte[500];
-
- byte outPutDiction[] = new byte[500];
-
- /**
- * @tests java.util.zip.Inflater#end()
- */
- public void test_end() {
- // test method of java.util.zip.inflater.end()
- byte byteArray[] = { 5, 2, 3, 7, 8 };
-
- int r = 0;
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray);
- inflate.end();
- try {
- inflate.reset();
- inflate.setInput(byteArray);
- } catch (NullPointerException e) {
- r = 1;
- }
- assertEquals("inflate can still be used after end is called", 1, r);
-
- Inflater i = new Inflater();
- i.end();
- // check for exception
- i.end();
- }
-
- /**
- * @tests java.util.zip.Inflater#finished()
- */
- public void test_finished() {
- // test method of java.util.zip.inflater.finished()
- byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
- Inflater inflate = new Inflater(false);
- byte outPutInf[] = new byte[500];
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
-
- inflate.inflate(outPutInf);
- }
- assertTrue(
- "the method finished() returned false when no more data needs to be decompressed",
- inflate.finished());
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - finished()",
- 0, outPutInf[byteArray.length]);
- }
-
- /**
- * @tests java.util.zip.Inflater#getAdler()
- */
- public void test_getAdler() {
- // test method of java.util.zip.inflater.getAdler()
- byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
-
- Inflater inflateDiction = new Inflater();
- inflateDiction.setInput(outPutDiction);
- if (inflateDiction.needsDictionary() == true) {
- // getting the checkSum value through the Adler32 class
- Adler32 adl = new Adler32();
- adl.update(dictionaryArray);
- long checkSumR = adl.getValue();
- assertTrue(
- "the checksum value returned by getAdler() is not the same as the checksum returned by creating the adler32 instance",
- checkSumR == inflateDiction.getAdler());
- }
- }
-
- /**
- * @tests java.util.zip.Inflater#getRemaining()
- */
- public void test_getRemaining() {
- // test method of java.util.zip.inflater.getRemaining()
- byte byteArray[] = { 1, 3, 5, 6, 7 };
- Inflater inflate = new Inflater();
- assertEquals("upon creating an instance of inflate, getRemaining returned a non zero value",
- 0, inflate.getRemaining());
- inflate.setInput(byteArray);
- assertTrue(
- "getRemaining returned zero when there is input in the input buffer",
- inflate.getRemaining() != 0);
- }
-
- /**
- * @tests java.util.zip.Inflater#getTotalIn()
- */
- public void test_getTotalIn() {
- // test method of java.util.zip.inflater.getTotalIn()
- // creating the decompressed data
- byte outPutBuf[] = new byte[500];
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- byte outPutInf[] = new byte[500];
- int x = 0;
- Deflater deflate = new Deflater(1);
- deflate.setInput(byteArray);
- while (!(deflate.needsInput())) {
- x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- deflate.finish();
- while (!(deflate.finished())) {
- x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
-
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
- // System.out.print(deflate.getTotalOut() + " " + inflate.getTotalIn());
- assertTrue(
- "the total byte in outPutBuf did not equal the byte returned in getTotalIn",
- inflate.getTotalIn() == deflate.getTotalOut());
-
- Inflater inflate2 = new Inflater();
- int offSet = 0;// seems only can start as 0
- int length = 4;
- try {
- // seems no while loops allowed
- if (inflate2.needsInput()) {
- inflate2.setInput(outPutBuff1, offSet, length);
- }
-
- inflate2.inflate(outPutInf);
-
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
- // System.out.print(inflate2.getTotalIn() + " " + length);
- assertTrue(
- "total byte dictated by length did not equal byte returned in getTotalIn",
- inflate2.getTotalIn() == length);
- }
-
- /**
- * @tests java.util.zip.Inflater#getTotalOut()
- */
- public void test_getTotalOut() {
- // test method of java.util.zip.inflater.Inflater()
- // creating the decompressed data
- byte outPutBuf[] = new byte[500];
- byte byteArray[] = { 1, 3, 4, 7, 8 };
- int y = 0;
- int x = 0;
- Deflater deflate = new Deflater(1);
- deflate.setInput(byteArray);
- while (!(deflate.needsInput())) {
- x += deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- deflate.finish();
- while (!(deflate.finished())) {
- x = x + deflate.deflate(outPutBuf, x, outPutBuf.length - x);
- }
-
- Inflater inflate = new Inflater();
- byte outPutInf[] = new byte[500];
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- y += inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Input to inflate is invalid or corrupted - getTotalIn");
- }
-
- assertTrue(
- "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
- "the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
-
- // testing inflate(byte,int,int)
- inflate.reset();
- y = 0;
- int offSet = 0;// seems only can start as 0
- int length = 4;
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuf);
- }
-
- y += inflate.inflate(outPutInf, offSet, length);
- }
- } catch (DataFormatException e) {
- System.out
- .println("Input to inflate is invalid or corrupted - getTotalIn");
- }
- assertTrue(
- "the sum of the bytes returned from inflate does not equal the bytes of getTotalOut()",
- y == inflate.getTotalOut());
- assertTrue(
- "the total number of bytes to be compressed does not equal the total bytes decompressed",
- inflate.getTotalOut() == deflate.getTotalIn());
- }
-
- /**
- * @tests java.util.zip.Inflater#inflate(byte[])
- */
- public void test_inflate$B() {
- // test method of java.util.zip.inflater.inflate(byte)
-
- byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
- byte outPutInf[] = new byte[500];
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - inflateB",
- 0, outPutInf[byteArray.length]);
- // testing for an empty input array
- byte outPutBuf[] = new byte[500];
- byte emptyArray[] = new byte[11];
- int x = 0;
- Deflater defEmpty = new Deflater(3);
- defEmpty.setInput(emptyArray);
- while (!(defEmpty.needsInput())) {
- x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- defEmpty.finish();
- while (!(defEmpty.finished())) {
- x += defEmpty.deflate(outPutBuf, x, outPutBuf.length - x);
- }
- assertTrue(
- "the total number of byte from deflate did not equal getTotalOut - inflate(byte)",
- x == defEmpty.getTotalOut());
- assertTrue(
- "the number of input byte from the array did not correspond with getTotalIn - inflate(byte)",
- defEmpty.getTotalIn() == emptyArray.length);
- Inflater infEmpty = new Inflater();
- try {
- while (!(infEmpty.finished())) {
- if (infEmpty.needsInput()) {
- infEmpty.setInput(outPutBuf);
- }
- infEmpty.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < emptyArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- emptyArray[i] == outPutInf[i]);
- assertEquals("Final decompressed data does not equal zero",
- 0, outPutInf[i]);
- }
- assertEquals("Final decompressed data contains more element than original data",
- 0, outPutInf[emptyArray.length]);
- }
-
- public void test_inflate$B1() {
- byte codedData[] = {
- 120, -38, 75, -54, 73, -52, 80, 40, 46, 41, -54, -52, 75, 87,
- 72, -50, -49, 43, 73, -52, -52, 43, 86, 72, 2, 10, 34, 99,
- -123, -60, -68, 20, -80, 32, 0, -101, -69, 17, 84};
- String codedString = "blah string contains blahblahblahblah and blah";
-
- Inflater infl1 = new Inflater();
- Inflater infl2 = new Inflater();
-
- byte[] result = new byte[100];
- int decLen = 0;
-
- infl1.setInput(codedData, 0, codedData.length);
- try {
- decLen = infl1.inflate(result);
- } catch (DataFormatException e) {
- fail("Unexpected DataFormatException");
- }
-
- infl1.end();
- assertEquals(codedString, new String(result, 0, decLen));
- codedData[5] = 0;
-
- infl2.setInput(codedData, 0, codedData.length);
- try {
- decLen = infl2.inflate(result);
- fail("Expected DataFormatException");
- } catch (DataFormatException e) {
- // expected
- }
-
- infl2.end();
- }
-
- /**
- * @tests java.util.zip.Inflater#inflate(byte[], int, int)
- */
- public void test_inflate$BII() {
- // test method of java.util.zip.inflater.inflate(byte,int,int)
-
- byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
- byte outPutInf[] = new byte[100];
- int y = 0;
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- y += inflate.inflate(outPutInf, y, outPutInf.length - y);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - inflateB",
- 0, outPutInf[byteArray.length]);
-
- // test boundary checks
- inflate.reset();
- int r = 0;
- int offSet = 0;
- int lengthError = 101;
- try {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.inflate(outPutInf, offSet, lengthError);
-
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("out of bounds error did not get caught", 1, r);
- }
-
- public void test_inflate$BII1() {
- byte codedData[] = {
- 120, -38, 75, -54, 73, -52, 80, 40, 46, 41, -54, -52, 75, 87,
- 72, -50, -49, 43, 73, -52, -52, 43, 86, 72, 2, 10, 34, 99,
- -123, -60, -68, 20, -80, 32, 0, -101, -69, 17, 84};
- String codedString = "blah string";
-
- Inflater infl1 = new Inflater();
- Inflater infl2 = new Inflater();
-
- byte[] result = new byte[100];
- int decLen = 0;
-
- infl1.setInput(codedData, 0, codedData.length);
- try {
- decLen = infl1.inflate(result, 10, 11);
- } catch (DataFormatException e) {
- fail("Unexpected DataFormatException");
- }
-
- infl1.end();
- assertEquals(codedString, new String(result, 10, decLen));
- codedData[5] = 0;
-
- infl2.setInput(codedData, 0, codedData.length);
- try {
- decLen = infl2.inflate(result, 10, 11);
- fail("Expected DataFormatException");
- } catch (DataFormatException e) {
- // expected
- }
-
- infl2.end();
- }
-
- /**
- * @tests java.util.zip.Inflater#Inflater()
- */
- public void test_Constructor() {
- // test method of java.util.zip.inflater.Inflater()
- Inflater inflate = new Inflater();
- assertNotNull("failed to create the instance of inflater",
- inflate);
- }
-
- /**
- * @tests java.util.zip.Inflater#Inflater(boolean)
- */
- public void test_ConstructorZ() {
- // test method of java.util.zip.inflater.Inflater(boolean)
- // note does not throw exception if deflater has a header, but inflater
- // doesn't or vice versa.
- byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
- Inflater inflate = new Inflater(true);
- assertNotNull("failed to create the instance of inflater", inflate);
- byte outPutInf[] = new byte[500];
- int r = 0;
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
-
- inflate.inflate(outPutInf);
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertEquals("the output array from inflate should contain 0 because the header of inflate and deflate did not match, but this failed",
- 0, outPutBuff1[i]);
- }
- } catch (DataFormatException e) {
- r = 1;
- }
- assertEquals("Error: exception should be thrown because of header inconsistency",
- 1, r);
-
- }
-
- /**
- * @tests java.util.zip.Inflater#needsDictionary()
- */
- public void test_needsDictionary() {
- // test method of java.util.zip.inflater.needsDictionary()
- // note: this flag is set after inflate is called
- byte outPutInf[] = new byte[500];
-
- // testing with dictionary set.
- Inflater inflateDiction = new Inflater();
- if (inflateDiction.needsInput()) {
- inflateDiction.setInput(outPutDiction);
- }
- try {
- assertEquals("should return 0 because needs dictionary",
- 0, inflateDiction.inflate(outPutInf));
- } catch (DataFormatException e) {
- fail("Should not cause exception");
- }
- assertTrue(
- "method needsDictionary returned false when dictionary was used in deflater",
- inflateDiction.needsDictionary());
-
- // testing without dictionary
- Inflater inflate = new Inflater();
- try {
- inflate.setInput(outPutBuff1);
- inflate.inflate(outPutInf);
- assertFalse(
- "method needsDictionary returned true when dictionary was not used in deflater",
- inflate.needsDictionary());
- } catch (DataFormatException e) {
- fail(
- "Input to inflate is invalid or corrupted - needsDictionary");
- }
-
- // Regression test for HARMONY-86
- Inflater inf = new Inflater();
- assertFalse(inf.needsDictionary());
- assertEquals(0,inf.getTotalIn());
- assertEquals(0,inf.getTotalOut());
- assertEquals(0,inf.getBytesRead());
- assertEquals(0,inf.getBytesWritten());
- }
-
- /**
- * @tests java.util.zip.Inflater#needsInput()
- */
- public void test_needsInput() {
- // test method of java.util.zip.inflater.needsInput()
- Inflater inflate = new Inflater();
- assertTrue(
- "needsInput give the wrong boolean value as a result of no input buffer",
- inflate.needsInput());
-
- byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
- inflate.setInput(byteArray);
- assertFalse(
- "methodNeedsInput returned true when the input buffer is full",
- inflate.needsInput());
-
- inflate.reset();
- byte byteArrayEmpty[] = new byte[0];
- inflate.setInput(byteArrayEmpty);
- assertTrue(
- "needsInput give wrong boolean value as a result of an empty input buffer",
- inflate.needsInput());
- }
-
- /**
- * @tests java.util.zip.Inflater#reset()
- */
- public void test_reset() {
- // test method of java.util.zip.inflater.reset()
- byte byteArray[] = { 1, 3, 4, 7, 8, 'e', 'r', 't', 'y', '5' };
- byte outPutInf[] = new byte[100];
- int y = 0;
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- y += inflate.inflate(outPutInf, y, outPutInf.length - y);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - reset",
- 0, outPutInf[byteArray.length]);
-
- // testing that resetting the inflater will also return the correct
- // decompressed data
-
- inflate.reset();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutBuff1);
- }
- inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - reset",
- 0, outPutInf[byteArray.length]);
-
- }
-
- /**
- * @tests java.util.zip.Inflater#setDictionary(byte[])
- */
- public void test_setDictionary$B() {
- //FIXME This test doesn't pass in Harmony classlib or Sun 5.0_7 RI
- /*
- // test method of java.util.zip.inflater.setDictionary(byte)
- byte dictionaryArray[] = { 'e', 'r', 't', 'a', 'b', 2, 3 };
- byte byteArray[] = { 4, 5, 3, 2, 'a', 'b', 6, 7, 8, 9, 0, 's', '3',
- 'w', 'r' };
-
- byte outPutInf[] = new byte[100];
-
- // trying to inflate without setting a dictionary
-
- Inflater inflateWO = new Inflater();
- byte outPutInf2[] = new byte[100];
- int r = 0;
- try {
- while (!(inflateWO.finished())) {
- if (inflateWO.needsInput()) {
- inflateWO.setInput(outPutDiction);
- }
- inflateWO.inflate(outPutInf2);
- }
- } catch (DataFormatException e) {
- r = 1;
- }
- assertEquals("invalid input to be decompressed due to dictionary not set",
- 1, r);
- // now setting the dictionary in inflater
- Inflater inflate = new Inflater();
- try {
- while (!(inflate.finished())) {
- if (inflate.needsInput()) {
- inflate.setInput(outPutDiction);
- }
- if (inflate.needsDictionary()) {
- inflate.setDictionary(dictionaryArray);
- }
- inflate.inflate(outPutInf);
- }
- } catch (DataFormatException e) {
- fail("Invalid input to be decompressed");
- }
- for (int i = 0; i < byteArray.length; i++) {
- assertTrue(
- "Final decompressed data does not equal the original data",
- byteArray[i] == outPutInf[i]);
- }
- assertEquals("final decompressed data contained more bytes than original - deflateB",
- 0, outPutInf[byteArray.length]);
- */
- }
-
- /**
- * @tests java.util.zip.Inflater#setInput(byte[])
- */
- public void test_setInput$B() {
- // test method of java.util.zip.inflater.setInput(byte)
- byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray);
- assertTrue("setInputB did not deliver any byte to the input buffer",
- inflate.getRemaining() != 0);
- }
-
- /**
- * @tests java.util.zip.Inflater#setInput(byte[], int, int)
- */
- public void test_setInput$BII() {
- // test method of java.util.zip.inflater.setInput(byte,int,int)
- byte byteArray[] = { 2, 3, 4, 't', 'y', 'u', 'e', 'w', 7, 6, 5, 9 };
- int offSet = 6;
- int length = 6;
- Inflater inflate = new Inflater();
- inflate.setInput(byteArray, offSet, length);
- assertTrue(
- "setInputBII did not deliver the right number of bytes to the input buffer",
- inflate.getRemaining() == length);
- // boundary check
- inflate.reset();
- int r = 0;
- try {
- inflate.setInput(byteArray, 100, 100);
- } catch (ArrayIndexOutOfBoundsException e) {
- r = 1;
- }
- assertEquals("boundary check is not present for setInput", 1, r);
- }
-
- @Override
- protected void setUp() {
- try {
- java.io.InputStream infile = Support_Resources
- .getStream("hyts_compressD.txt");
- BufferedInputStream inflatIP = new BufferedInputStream(infile);
- inflatIP.read(outPutBuff1, 0, outPutBuff1.length);
- inflatIP.close();
-
- java.io.InputStream infile2 = Support_Resources
- .getStream("hyts_compDiction.txt");
- BufferedInputStream inflatIP2 = new BufferedInputStream(infile2);
- inflatIP2.read(outPutDiction, 0, outPutDiction.length);
- inflatIP2.close();
-
- } catch (FileNotFoundException e) {
- fail(
- "input file to test InflaterInputStream constructor is not found");
- } catch (ZipException e) {
- fail(
- "read() threw an zip exception while testing constructor");
- } catch (IOException e) {
- fail("read() threw an exception while testing constructor");
- }
- }
-
- @Override
- protected void tearDown() {
- }
-
- /**
- * @tests java.util.zip.Deflater#getBytesRead()
- */
- public void test_getBytesRead() throws DataFormatException,
- UnsupportedEncodingException {
- // Regression test for HARMONY-158
- Deflater def = new Deflater();
- Inflater inf = new Inflater();
- assertEquals(0, def.getTotalIn());
- assertEquals(0, def.getTotalOut());
- assertEquals(0, def.getBytesRead());
- // Encode a String into bytes
- String inputString = "blahblahblah??";
- byte[] input = inputString.getBytes("UTF-8");
-
- // Compress the bytes
- byte[] output = new byte[100];
- def.setInput(input);
- def.finish();
- def.deflate(output);
- inf.setInput(output);
- int compressedDataLength =inf.inflate(input);
- assertEquals(16, inf.getTotalIn());
- assertEquals(compressedDataLength, inf.getTotalOut());
- assertEquals(16, inf.getBytesRead());
- }
-
- /**
- * @tests java.util.zip.Deflater#getBytesRead()
- */
- public void test_getBytesWritten() throws DataFormatException, UnsupportedEncodingException {
- // Regression test for HARMONY-158
- Deflater def = new Deflater();
- Inflater inf = new Inflater();
- assertEquals(0, def.getTotalIn());
- assertEquals(0, def.getTotalOut());
- assertEquals(0, def.getBytesWritten());
- // Encode a String into bytes
- String inputString = "blahblahblah??";
- byte[] input = inputString.getBytes("UTF-8");
-
- // Compress the bytes
- byte[] output = new byte[100];
- def.setInput(input);
- def.finish();
- def.deflate(output);
- inf.setInput(output);
- int compressedDataLength =inf.inflate(input);
- assertEquals(16, inf.getTotalIn());
- assertEquals(compressedDataLength, inf.getTotalOut());
- assertEquals(14, inf.getBytesWritten());
- }
-
- /**
- * @tests java.util.zip.Deflater#inflate(byte[], int, int)
- */
- public void testInflate() throws Exception {
- // Regression for HARMONY-81
- Inflater inf = new Inflater();
- int res = inf.inflate(new byte[0], 0, 0);
-
- assertEquals(0, res);
-
- // Regression for HARMONY-2508
- Inflater inflater = new Inflater();
- byte[] b = new byte[1024];
- assertEquals(0, inflater.inflate(b));
- inflater.end();
-
- // Regression for HARMONY-2510
- inflater = new Inflater();
- inflater.setInput(new byte[] { -1 });
- try {
- inflater.inflate(b);
-
- // The RI detects malformed data on the malformed input { -1 }. Both
- // this implementation and the native zlib API return "need input"
- // on that data. This is an error if the stream is exhausted, but
- // not one that results in an exception in the Inflater API.
- assertTrue(inflater.needsInput());
- } catch (DataFormatException e) {
- // expected
- }
-
- inflater = new Inflater();
- inflater.setInput(new byte[] { -1, -1, -1 });
- try {
- inflater.inflate(b);
- } catch (DataFormatException e) {
- // expected
- }
- }
-
- public void testSetDictionary$B() throws Exception {
- int i = 0;
- String inputString = "blah string contains blahblahblahblah and blah";
- String dictionary1 = "blah";
- String dictionary2 = "1234";
-
- byte[] outputNo = new byte[100];
- byte[] output1 = new byte[100];
- byte[] output2 = new byte[100];
- Deflater defDictNo = new Deflater(9);
- Deflater defDict1 = new Deflater(9);
- Deflater defDict2 = new Deflater(9);
-
- defDict1.setDictionary(dictionary1.getBytes());
- defDict2.setDictionary(dictionary2.getBytes());
-
- defDictNo.setInput(inputString.getBytes());
- defDict1.setInput(inputString.getBytes());
- defDict2.setInput(inputString.getBytes());
-
- defDictNo.finish();
- defDict1.finish();
- defDict2.finish();
-
- int dataLenNo = defDictNo.deflate(outputNo);
- int dataLen1 = defDict1.deflate(output1);
- int dataLen2 = defDict2.deflate(output2);
-
- boolean passNo1 = false;
- boolean passNo2 = false;
- boolean pass12 = false;
-
- for (i = 0; i < (dataLenNo < dataLen1 ? dataLenNo : dataLen1); i++) {
- if (outputNo[i] != output1[i]) {
- passNo1 = true;
- break;
- }
- }
- for (i = 0; i < (dataLenNo < dataLen1 ? dataLenNo : dataLen2); i++) {
- if (outputNo[i] != output2[i]) {
- passNo2 = true;
- break;
- }
- }
- for (i = 0; i < (dataLen1 < dataLen2 ? dataLen1 : dataLen2); i++) {
- if (output1[i] != output2[i]) {
- pass12 = true;
- break;
- }
- }
-
- assertTrue(
- "Compressed data the same for stream with dictionary and without it.",
- passNo1);
- assertTrue(
- "Compressed data the same for stream with dictionary and without it.",
- passNo2);
- assertTrue(
- "Compressed data the same for stream with different dictionaries.",
- pass12);
-
- Inflater inflNo = new Inflater();
- Inflater infl1 = new Inflater();
- Inflater infl2 = new Inflater();
-
- byte[] result = new byte[100];
- int decLen;
-
- inflNo.setInput(outputNo, 0, dataLenNo);
- decLen = inflNo.inflate(result);
-
- assertFalse(inflNo.needsDictionary());
- inflNo.end();
- assertEquals(inputString, new String(result, 0, decLen));
-
- infl1.setInput(output1, 0, dataLen1);
- decLen = infl1.inflate(result);
-
- assertTrue(infl1.needsDictionary());
- infl1.setDictionary(dictionary1.getBytes());
- decLen = infl1.inflate(result);
- infl1.end();
- assertEquals(inputString, new String(result, 0, decLen));
-
- infl2.setInput(output2, 0, dataLen2);
- decLen = infl2.inflate(result);
-
- assertTrue(infl2.needsDictionary());
- infl2.setDictionary(dictionary2.getBytes());
- decLen = infl2.inflate(result);
- infl2.end();
- assertEquals(inputString, new String(result, 0, decLen));
-
-
- inflNo = new Inflater();
- infl1 = new Inflater();
- inflNo.setInput(outputNo, 0, dataLenNo);
- try {
- infl1.setDictionary(dictionary1.getBytes());
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException ee) {
- // expected.
- }
- inflNo.end();
-
- infl1.setInput(output1, 0, dataLen1);
- decLen = infl1.inflate(result);
-
- assertTrue(infl1.needsDictionary());
- try {
- infl1.setDictionary(dictionary2.getBytes());
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException ee) {
- // expected.
- }
- infl1.end();
- }
-
- public void testSetDictionary$BII() throws Exception {
- int i = 0;
- String inputString = "blah string contains blahblahblahblah and blah";
- String dictionary1 = "blah";
- String dictionary2 = "blahblahblah";
-
- byte[] output1 = new byte[100];
- byte[] output2 = new byte[100];
- byte[] output3 = new byte[100];
-
- Deflater defDict1 = new Deflater(9);
- Deflater defDict2 = new Deflater(9);
- Deflater defDict3 = new Deflater(9);
-
- defDict1.setDictionary(dictionary1.getBytes());
- defDict2.setDictionary(dictionary2.getBytes());
- defDict3.setDictionary(dictionary2.getBytes(), 4, 4);
-
- defDict1.setInput(inputString.getBytes());
- defDict2.setInput(inputString.getBytes());
- defDict3.setInput(inputString.getBytes());
-
- defDict1.finish();
- defDict2.finish();
- defDict3.finish();
-
- int dataLen1 = defDict1.deflate(output1);
- int dataLen2 = defDict2.deflate(output2);
- int dataLen3 = defDict3.deflate(output3);
-
- boolean pass12 = false;
- boolean pass23 = false;
- boolean pass13 = true;
-
- for (i = 0; i < (dataLen1 < dataLen2 ? dataLen1 : dataLen2); i++) {
- if (output1[i] != output2[i]) {
- pass12 = true;
- break;
- }
- }
- for (i = 0; i < (dataLen2 < dataLen3 ? dataLen2 : dataLen3); i++) {
- if (output2[i] != output3[i]) {
- pass23 = true;
- break;
- }
- }
- for (i = 0; i < (dataLen1 < dataLen3 ? dataLen1 : dataLen3); i++) {
- if (output1[i] != output3[i]) {
- pass13 = false;
- break;
- }
- }
-
- assertTrue(
- "Compressed data the same for stream with different dictionaries.",
- pass12);
- assertTrue(
- "Compressed data the same for stream with different dictionaries.",
- pass23);
- assertTrue(
- "Compressed data the differs for stream with the same dictionaries.",
- pass13);
-
- Inflater infl1 = new Inflater();
- Inflater infl2 = new Inflater();
- Inflater infl3 = new Inflater();
-
- byte[] result = new byte[100];
- int decLen;
-
- infl1.setInput(output1, 0, dataLen1);
- decLen = infl1.inflate(result);
-
- assertTrue(infl1.needsDictionary());
- infl1.setDictionary(dictionary2.getBytes(), 4, 4);
- decLen = infl1.inflate(result);
- infl1.end();
- assertEquals(inputString, new String(result, 0, decLen));
-
- infl2.setInput(output2, 0, dataLen2);
- decLen = infl2.inflate(result);
-
- assertTrue(infl2.needsDictionary());
- try {
- infl2.setDictionary(dictionary1.getBytes());
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException ee) {
- // expected
- }
- infl2.end();
-
- infl3.setInput(output3, 0, dataLen3);
- decLen = infl3.inflate(result);
-
- assertTrue(infl3.needsDictionary());
- infl3.setDictionary(dictionary1.getBytes());
- decLen = infl3.inflate(result);
- infl3.end();
- assertEquals(inputString, new String(result, 0, decLen));
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
deleted file mode 100644
index 9754134..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipEntryTest.java
+++ /dev/null
@@ -1,500 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.util.TimeZone;
-import java.util.zip.ZipEntry;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import tests.support.resource.Support_Resources;
-
-public class ZipEntryTest extends junit.framework.TestCase {
-
- public byte[] getAllBytesFromStream(InputStream is) throws IOException {
- ByteArrayOutputStream bs = new ByteArrayOutputStream();
- byte[] buf = new byte[512];
- int iRead;
- int off;
- while (is.available() > 0) {
- iRead = is.read(buf, 0, buf.length);
- if (iRead > 0) bs.write(buf, 0, iRead);
- }
- return bs.toByteArray();
- }
-
- // zip file hyts_ZipFile.zip must be included as a resource
- java.util.zip.ZipEntry zentry;
-
- java.util.zip.ZipFile zfile;
-
- private static final String platformId = System.getProperty(
- "com.ibm.oti.configuration", "JDK")
- + System.getProperty("java.vm.version");
-
- static final String tempFileName = platformId + "zfzezi.zip";
-
- long orgSize;
-
- long orgCompressedSize;
-
- long orgCrc;
-
- long orgTime;
-
- String orgComment;
-
- /**
- * @tests java.util.zip.ZipEntry#ZipEntry(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.util.zip.ZipEntry(java.lang.String)
- zentry = zfile.getEntry("File3.txt");
- assertNotNull("Failed to create ZipEntry", zentry);
- try {
- zentry = zfile.getEntry(null);
- fail("NullPointerException not thrown");
- } catch (NullPointerException e) {
- }
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < 65535; i++) {
- s.append('a');
- }
- try {
- zentry = new ZipEntry(s.toString());
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException During Test.");
- }
- try {
- s.append('a');
- zentry = new ZipEntry(s.toString());
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- String n = null;
- zentry = new ZipEntry(n);
- fail("NullPointerException not thrown");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getComment()
- */
- public void test_getComment() {
- // Test for method java.lang.String java.util.zip.ZipEntry.getComment()
- ZipEntry zipEntry = new ZipEntry("zippy.zip");
- assertNull("Incorrect Comment Returned.", zipEntry.getComment());
- zipEntry.setComment("This Is A Comment");
- assertEquals("Incorrect Comment Returned.",
- "This Is A Comment", zipEntry.getComment());
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getCompressedSize()
- */
- public void test_getCompressedSize() {
- // Test for method long java.util.zip.ZipEntry.getCompressedSize()
- assertTrue("Incorrect compressed size returned", zentry
- .getCompressedSize() == orgCompressedSize);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getCrc()
- */
- public void test_getCrc() {
- // Test for method long java.util.zip.ZipEntry.getCrc()
- assertTrue("Failed to get Crc", zentry.getCrc() == orgCrc);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getExtra()
- */
- public void test_getExtra() {
- // Test for method byte [] java.util.zip.ZipEntry.getExtra()
- assertNull("Incorrect extra information returned",
- zentry.getExtra());
- byte[] ba = { 'T', 'E', 'S', 'T' };
- zentry = new ZipEntry("test.tst");
- zentry.setExtra(ba);
- assertTrue("Incorrect Extra Information Returned.",
- zentry.getExtra() == ba);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getMethod()
- */
- public void test_getMethod() {
- // Test for method int java.util.zip.ZipEntry.getMethod()
- zentry = zfile.getEntry("File1.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.STORED);
- zentry = zfile.getEntry("File3.txt");
- assertTrue("Incorrect compression method returned",
- zentry.getMethod() == java.util.zip.ZipEntry.DEFLATED);
- zentry = new ZipEntry("test.tst");
- assertEquals("Incorrect Method Returned.", -1, zentry.getMethod());
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getName()
- */
- public void test_getName() {
- // Test for method java.lang.String java.util.zip.ZipEntry.getName()
- assertEquals("Incorrect name returned - Note return result somewhat ambiguous in spec",
- "File1.txt", zentry.getName());
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getSize()
- */
- public void test_getSize() {
- // Test for method long java.util.zip.ZipEntry.getSize()
- assertTrue("Incorrect size returned", zentry.getSize() == orgSize);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#getTime()
- */
- public void test_getTime() {
- // Test for method long java.util.zip.ZipEntry.getTime()
- assertTrue("Failed to get time", zentry.getTime() == orgTime);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#isDirectory()
- */
- public void test_isDirectory() {
- // Test for method boolean java.util.zip.ZipEntry.isDirectory()
- assertTrue("Entry should not answer true to isDirectory", !zentry
- .isDirectory());
- zentry = new ZipEntry("Directory/");
- assertTrue("Entry should answer true to isDirectory", zentry
- .isDirectory());
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setComment(java.lang.String)
- */
- public void test_setCommentLjava_lang_String() {
- // Test for method void
- // java.util.zip.ZipEntry.setComment(java.lang.String)
- zentry = zfile.getEntry("File1.txt");
- zentry.setComment("Set comment using api");
- assertEquals("Comment not correctly set",
- "Set comment using api", zentry.getComment());
- String n = null;
- zentry.setComment(n);
- assertNull("Comment not correctly set", zentry.getComment());
- StringBuffer s = new StringBuffer();
- for (int i = 0; i < 0xFFFF; i++) {
- s.append('a');
- }
- try {
- zentry.setComment(s.toString());
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException During Test.");
- }
- try {
- s.append('a');
- zentry.setComment(s.toString());
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setCompressedSize(long)
- */
- public void test_setCompressedSizeJ() {
- // Test for method void java.util.zip.ZipEntry.setCompressedSize(long)
- zentry.setCompressedSize(orgCompressedSize + 10);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == (orgCompressedSize + 10));
- zentry.setCompressedSize(0);
- assertEquals("Set compressed size failed",
- 0, zentry.getCompressedSize());
- zentry.setCompressedSize(-25);
- assertEquals("Set compressed size failed",
- -25, zentry.getCompressedSize());
- zentry.setCompressedSize(4294967296l);
- assertTrue("Set compressed size failed",
- zentry.getCompressedSize() == 4294967296l);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setCrc(long)
- */
- public void test_setCrcJ() {
- // Test for method void java.util.zip.ZipEntry.setCrc(long)
- zentry.setCrc(orgCrc + 100);
- assertTrue("Failed to set Crc", zentry.getCrc() == (orgCrc + 100));
- zentry.setCrc(0);
- assertEquals("Failed to set Crc", 0, zentry.getCrc());
- try {
- zentry.setCrc(-25);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- zentry.setCrc(4294967295l);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- zentry.setCrc(4294967296l);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setExtra(byte[])
- */
- public void test_setExtra$B() {
- // Test for method void java.util.zip.ZipEntry.setExtra(byte [])
- zentry = zfile.getEntry("File1.txt");
- zentry.setExtra("Test setting extra information".getBytes());
- assertEquals("Extra information not written properly", "Test setting extra information", new String(zentry
- .getExtra(), 0, zentry.getExtra().length)
- );
- zentry = new ZipEntry("test.tst");
- byte[] ba = new byte[0xFFFF];
- try {
- zentry.setExtra(ba);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- ba = new byte[0xFFFF + 1];
- zentry.setExtra(ba);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
-
- // One constructor
- ZipEntry zeInput = new ZipEntry("InputZIP");
- byte[] extraB = { 'a', 'b', 'd', 'e' };
- zeInput.setExtra(extraB);
- assertEquals(extraB, zeInput.getExtra());
- assertEquals(extraB[3], zeInput.getExtra()[3]);
- assertEquals(extraB.length, zeInput.getExtra().length);
-
- // test another constructor
- ZipEntry zeOutput = new ZipEntry(zeInput);
- assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
- assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
- assertEquals(extraB[3], zeOutput.getExtra()[3]);
- assertEquals(extraB.length, zeOutput.getExtra().length);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setMethod(int)
- */
- public void test_setMethodI() {
- // Test for method void java.util.zip.ZipEntry.setMethod(int)
- zentry = zfile.getEntry("File3.txt");
- zentry.setMethod(ZipEntry.STORED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.STORED);
- zentry.setMethod(ZipEntry.DEFLATED);
- assertTrue("Failed to set compression method",
- zentry.getMethod() == ZipEntry.DEFLATED);
- try {
- int error = 1;
- zentry = new ZipEntry("test.tst");
- zentry.setMethod(error);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setSize(long)
- */
- public void test_setSizeJ() {
- // Test for method void java.util.zip.ZipEntry.setSize(long)
- zentry.setSize(orgSize + 10);
- assertTrue("Set size failed", zentry.getSize() == (orgSize + 10));
- zentry.setSize(0);
- assertEquals("Set size failed", 0, zentry.getSize());
- try {
- zentry.setSize(-25);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- try {
- zentry.setCrc(4294967295l);
- } catch (IllegalArgumentException e) {
- fail("Unexpected IllegalArgumentException during test");
- }
- try {
- zentry.setCrc(4294967296l);
- fail("IllegalArgumentException not thrown");
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#setTime(long)
- */
- public void test_setTimeJ() {
- // Test for method void java.util.zip.ZipEntry.setTime(long)
- zentry.setTime(orgTime + 10000);
- assertTrue("Test 1: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime + 10000));
- zentry.setTime(orgTime - 10000);
- assertTrue("Test 2: Failed to set time: " + zentry.getTime(), zentry
- .getTime() == (orgTime - 10000));
- TimeZone zone = TimeZone.getDefault();
- try {
- TimeZone.setDefault(TimeZone.getTimeZone("EST"));
- zentry.setTime(0);
- assertTrue("Test 3: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- assertTrue("Test 3a: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315532800000L);
- zentry.setTime(0);
- TimeZone.setDefault(TimeZone.getTimeZone("EST"));
- assertTrue("Test 3b: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
-
- zentry.setTime(-25);
- assertTrue("Test 4: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- zentry.setTime(4354837200000L);
- assertTrue("Test 5: Failed to set time: " + zentry.getTime(),
- zentry.getTime() == 315550800000L);
- } finally {
- TimeZone.setDefault(zone);
- }
- }
-
- /**
- * @tests java.util.zip.ZipEntry#toString()
- */
- public void test_toString() {
- // Test for method java.lang.String java.util.zip.ZipEntry.toString()
- assertTrue("Returned incorrect entry name", zentry.toString().indexOf(
- "File1.txt") >= 0);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#ZipEntry(java.util.zip.ZipEntry)
- */
- public void test_ConstructorLjava_util_zip_ZipEntry() {
- // Test for method java.util.zip.ZipEntry(util.zip.ZipEntry)
- zentry.setSize(2);
- zentry.setCompressedSize(4);
- zentry.setComment("Testing");
- ZipEntry zentry2 = new ZipEntry(zentry);
- assertEquals("ZipEntry Created With Incorrect Size.",
- 2, zentry2.getSize());
- assertEquals("ZipEntry Created With Incorrect Compressed Size.", 4, zentry2
- .getCompressedSize());
- assertEquals("ZipEntry Created With Incorrect Comment.", "Testing", zentry2
- .getComment());
- assertTrue("ZipEntry Created With Incorrect Crc.",
- zentry2.getCrc() == orgCrc);
- assertTrue("ZipEntry Created With Incorrect Time.",
- zentry2.getTime() == orgTime);
- }
-
- /**
- * @tests java.util.zip.ZipEntry#clone()
- */
- public void test_clone() {
- // Test for method java.util.zip.ZipEntry.clone()
- Object obj = zentry.clone();
- assertTrue("toString()", obj.toString().equals(zentry.toString()));
- assertTrue("hashCode()", obj.hashCode() == zentry.hashCode());
-
- // One constructor
- ZipEntry zeInput = new ZipEntry("InputZIP");
- byte[] extraB = { 'a', 'b', 'd', 'e' };
- zeInput.setExtra(extraB);
- assertEquals(extraB, zeInput.getExtra());
- assertEquals(extraB[3], zeInput.getExtra()[3]);
- assertEquals(extraB.length, zeInput.getExtra().length);
-
- // test Clone()
- ZipEntry zeOutput = (ZipEntry) zeInput.clone();
- assertEquals(zeInput.getExtra()[3], zeOutput.getExtra()[3]);
- assertEquals(zeInput.getExtra().length, zeOutput.getExtra().length);
- assertEquals(extraB[3], zeOutput.getExtra()[3]);
- assertEquals(extraB.length, zeOutput.getExtra().length);
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
-
- @Override
- protected void setUp() {
- java.io.File f = null;
- try {
- // Create a local copy of the file since some tests want to alter
- // information.
- f = new java.io.File(tempFileName);
- // Create absolute filename as ZipFile does not resolve using
- // user.dir
- f = new java.io.File(f.getAbsolutePath());
- f.delete();
- java.io.InputStream is = Support_Resources
- .getStream("hyts_ZipFile.zip");
- java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
- byte[] rbuf = getAllBytesFromStream(is);
- fos.write(rbuf, 0, rbuf.length);
- is.close();
- fos.close();
- zfile = new java.util.zip.ZipFile(f);
- zentry = zfile.getEntry("File1.txt");
- orgSize = zentry.getSize();
- orgCompressedSize = zentry.getCompressedSize();
- orgCrc = zentry.getCrc();
- orgTime = zentry.getTime();
- orgComment = zentry.getComment();
- } catch (Exception e) {
- System.out.println("Exception during ZipFile setup <"
- + f.getAbsolutePath() + ">: ");
- e.printStackTrace();
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
-
- @Override
- protected void tearDown() {
- try {
- if (zfile != null) {
- zfile.close();
- }
- java.io.File f = new java.io.File(tempFileName);
- f.delete();
- } catch (java.io.IOException e) {
- System.out.println("Exception during tearDown");
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipExceptionTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipExceptionTest.java
deleted file mode 100644
index 9f3be8d..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipExceptionTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import junit.framework.TestCase;
-
-import java.util.zip.ZipException;
-
-public class ZipExceptionTest extends TestCase {
-
- public void testZipException() {
- ZipException zz = new ZipException();
- assertEquals(zz.getMessage(), null);
- }
-
- public void testZipExceptionLjava_lang_String() {
- ZipException zz = new ZipException("Test");
- assertEquals(zz.getMessage(), "Test");
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
deleted file mode 100644
index b2c0ab3..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipInputStreamTest.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import junit.framework.TestCase;
-
-import tests.support.resource.Support_Resources;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-public class ZipInputStreamTest extends TestCase {
- // the file hyts_zipFile.zip used in setup needs to included as a resource
- private ZipEntry zentry;
-
- private ZipInputStream zis;
-
- private byte[] zipBytes;
-
- private byte[] dataBytes = "Some data in my file".getBytes();
-
- @Override
- protected void setUp() {
- try {
- InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
- if (is == null) {
- System.out.println("file hyts_ZipFile.zip can not be found");
- }
- zis = new ZipInputStream(is);
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ZipOutputStream zos = new ZipOutputStream(bos);
- ZipEntry entry = new ZipEntry("myFile");
- zos.putNextEntry(entry);
- zos.write(dataBytes);
- zos.closeEntry();
- zos.close();
- zipBytes = bos.toByteArray();
- } catch (Exception e) {
- System.out.println("Exception during ZipFile setup:");
- e.printStackTrace();
- }
- }
-
- @Override
- protected void tearDown() {
- if (zis != null) {
- try {
- zis.close();
- } catch (Exception e) {
- }
- }
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#ZipInputStream(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() throws Exception {
- zentry = zis.getNextEntry();
- zis.closeEntry();
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#close()
- */
- public void test_close() {
- try {
- zis.close();
- byte[] rbuf = new byte[10];
- zis.read(rbuf, 0, 1);
- } catch (IOException e) {
- return;
- }
- fail("Read data after stream was closed");
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#close()
- */
- public void test_close2() throws Exception {
- // Regression for HARMONY-1101
- zis.close();
- // another call to close should NOT cause an exception
- zis.close();
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#closeEntry()
- */
- public void test_closeEntry() throws Exception {
- zentry = zis.getNextEntry();
- zis.closeEntry();
- zentry = zis.getNextEntry();
- zis.close();
- try {
- zis.closeEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
-
- ZipInputStream zis1 = new ZipInputStream(fis);
-
- try {
- for (int i = 0; i < 6; i++) {
- zis1.getNextEntry();
- zis1.closeEntry();
- }
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
- }
-
- public void test_closeAfterException() throws Exception {
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
-
- ZipInputStream zis1 = new ZipInputStream(fis);
-
- try {
- for (int i = 0; i < 6; i++) {
- zis1.getNextEntry();
- }
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- zis1.close();
- try {
- zis1.getNextEntry();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#getNextEntry()
- */
- public void test_getNextEntry() throws Exception {
- assertNotNull("getNextEntry failed", zis.getNextEntry());
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
-
- ZipInputStream zis1 = new ZipInputStream(fis);
-
- try {
- for (int i = 0; i < 6; i++) {
- zis1.getNextEntry();
- }
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- try {
- zis1.close(); // Android throws exception here, already!
- zis1.getNextEntry(); // But RI here, only!
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#read(byte[], int, int)
- */
- public void test_read$BII() throws Exception {
- zentry = zis.getNextEntry();
- byte[] rbuf = new byte[(int) zentry.getSize()];
- int r = zis.read(rbuf, 0, rbuf.length);
- new String(rbuf, 0, r);
- assertEquals("Failed to read entry", 12, r);
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
-
- ZipInputStream zis1 = new ZipInputStream(fis);
-
- zis1.getNextEntry();
- zis1.getNextEntry();
-
- rbuf = new byte[100];
-
- try {
- zis1.read(rbuf, 10, 90);
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- try {
- zis1.close(); // Android throws exception here, already!
- zis1.read(rbuf, 10, 90); // But RI here, only!
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- public void testReadOneByteAtATime() throws IOException {
- InputStream in = new FilterInputStream(Support_Resources.getStream("hyts_ZipFile.zip")) {
- @Override
- public int read(byte[] buffer, int offset, int count) throws IOException {
- return super.read(buffer, offset, 1); // one byte at a time
- }
-
- @Override
- public int read(byte[] buffer) throws IOException {
- return super.read(buffer, 0, 1); // one byte at a time
- }
- };
-
- zis = new ZipInputStream(in);
- while ((zentry = zis.getNextEntry()) != null) {
- zentry.getName();
- }
- zis.close();
- }
-
- /**
- * @tests java.util.zip.ZipInputStream#skip(long)
- */
- public void test_skipJ() throws Exception {
- zentry = zis.getNextEntry();
- byte[] rbuf = new byte[(int) zentry.getSize()];
- zis.skip(2);
- int r = zis.read(rbuf, 0, rbuf.length);
- assertEquals("Failed to skip data", 10, r);
-
- zentry = zis.getNextEntry();
- zentry = zis.getNextEntry();
- long s = zis.skip(1025);
- assertTrue("invalid skip: " + s, s == 1025);
-
- ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(
- zipBytes));
- zis.getNextEntry();
- long skipLen = dataBytes.length / 2;
- assertEquals("Assert 0: failed valid skip", skipLen, zis.skip(skipLen));
- zis.skip(dataBytes.length);
- assertEquals("Assert 1: performed invalid skip", 0, zis.skip(1));
- assertEquals("Assert 2: failed zero len skip", 0, zis.skip(0));
- try {
- zis.skip(-1);
- fail("Assert 3: Expected Illegal argument exception");
- } catch (IllegalArgumentException e) {
- // Expected
- }
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(new File(resources,
- "Broken_manifest.jar"));
-
- ZipInputStream zis1 = new ZipInputStream(fis);
-
- zis1.getNextEntry();
- zis1.getNextEntry();
-
- try {
- zis1.skip(10);
- fail("ZipException expected");
- } catch (ZipException ee) {
- // expected
- }
-
- try {
- zis1.close(); // Android throws exception here, already!
- zis1.skip(10); // But RI here, only!
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- public void test_available() throws Exception {
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "hyts_ZipFile.zip");
- File fl = new File(resources, "hyts_ZipFile.zip");
- FileInputStream fis = new FileInputStream(fl);
-
- ZipInputStream zis1 = new ZipInputStream(fis);
- ZipEntry entry = zis1.getNextEntry();
- assertNotNull("No entry in the archive.", entry);
- long entrySize = entry.getSize();
- assertTrue("Entry size was < 1", entrySize > 0);
- int i = 0;
- while (zis1.available() > 0) {
- zis1.skip(1);
- i++;
- }
- if (i != entrySize) {
- fail("ZipInputStream.available or ZipInputStream.skip does not " +
- "working properly. Only skipped " + i +
- " bytes instead of " + entrySize);
- }
- assertEquals(0, zis1.skip(1));
- assertEquals(0, zis1.available());
- zis1.closeEntry();
- assertEquals(1, zis.available());
- zis1.close();
- try {
- zis1.available();
- fail("IOException expected");
- } catch (IOException ee) {
- // expected
- }
- }
-
- class Mock_ZipInputStream extends ZipInputStream {
- boolean createFlag = false;
-
- public Mock_ZipInputStream(InputStream arg0) {
- super(arg0);
- }
-
- boolean getCreateFlag() {
- return createFlag;
- }
-
- protected ZipEntry createZipEntry(String name) {
- createFlag = true;
- return super.createZipEntry(name);
- }
- }
-
- public void test_createZipEntryLjava_lang_String() throws Exception {
-
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, null, "Broken_manifest.jar");
- File fl = new File(resources, "Broken_manifest.jar");
- FileInputStream fis = new FileInputStream(fl);
-
- Mock_ZipInputStream zis1 = new Mock_ZipInputStream(fis);
- assertFalse(zis1.getCreateFlag());
- zis1.getNextEntry();
- assertTrue(zis1.getCreateFlag());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java b/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
deleted file mode 100644
index 58cfe1e..0000000
--- a/luni/src/test/java/org/apache/harmony/archive/tests/java/util/zip/ZipOutputStreamTest.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.archive.tests.java.util.zip;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.CRC32;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipException;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-public class ZipOutputStreamTest extends junit.framework.TestCase {
-
- ZipOutputStream zos;
-
- ByteArrayOutputStream bos;
-
- ZipInputStream zis;
-
- static final String data = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorld";
-
- /**
- * @tests java.util.zip.ZipOutputStream#close()
- */
- public void test_close() throws Exception {
- try {
- zos.close();
- fail("Close on empty stream failed to throw exception");
- } catch (ZipException e) {
- // expected
- }
-
- zos = new ZipOutputStream(bos);
- zos.putNextEntry(new ZipEntry("XX"));
- zos.closeEntry();
- zos.close();
-
- // Regression for HARMONY-97
- ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
- zos.putNextEntry(new ZipEntry("myFile"));
- zos.close();
- zos.close(); // Should be a no-op
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#closeEntry()
- */
- public void test_closeEntry() throws IOException {
- ZipEntry ze = new ZipEntry("testEntry");
- ze.setTime(System.currentTimeMillis());
- zos.putNextEntry(ze);
- zos.write("Hello World".getBytes("UTF-8"));
- zos.closeEntry();
- assertTrue("closeEntry failed to update required fields",
- ze.getSize() == 11 && ze.getCompressedSize() == 13);
-
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#finish()
- */
- public void test_finish() throws Exception {
- ZipEntry ze = new ZipEntry("test");
- zos.putNextEntry(ze);
- zos.write("Hello World".getBytes());
- zos.finish();
- assertEquals("Finish failed to closeCurrentEntry", 11, ze.getSize());
-
- ZipOutputStream zos = new ZipOutputStream(new ByteArrayOutputStream());
- zos.putNextEntry(new ZipEntry("myFile"));
- zos.finish();
- zos.close();
- try {
- zos.finish();
- fail("Assert 0: Expected IOException");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#putNextEntry(java.util.zip.ZipEntry)
- */
- public void test_putNextEntryLjava_util_zip_ZipEntry() throws IOException {
- ZipEntry ze = new ZipEntry("testEntry");
- ze.setTime(System.currentTimeMillis());
- zos.putNextEntry(ze);
- zos.write("Hello World".getBytes());
- zos.closeEntry();
- zos.close();
- zis = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
- ZipEntry ze2 = zis.getNextEntry();
- zis.closeEntry();
- assertTrue("Failed to write correct entry", ze.getName().equals(
- ze2.getName())
- && ze.getCrc() == ze2.getCrc());
- try {
- zos.putNextEntry(ze);
- fail("Entry with incorrect setting failed to throw exception");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#setComment(java.lang.String)
- */
- public void test_setCommentLjava_lang_String() {
- // There is no way to get the comment back, so no way to determine if
- // the comment is set correct
- zos.setComment("test setComment");
-
- try {
- zos.setComment(new String(new byte[0xFFFF + 1]));
- fail("Comment over 0xFFFF in length should throw exception");
- } catch (IllegalArgumentException e) {
- // Passed
- }
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#setLevel(int)
- */
- public void test_setLevelI() throws IOException {
- ZipEntry ze = new ZipEntry("test");
- zos.putNextEntry(ze);
- zos.write(data.getBytes());
- zos.closeEntry();
- long csize = ze.getCompressedSize();
- zos.setLevel(9); // Max Compression
- zos.putNextEntry(ze = new ZipEntry("test2"));
- zos.write(data.getBytes());
- zos.closeEntry();
- assertTrue("setLevel failed", csize <= ze.getCompressedSize());
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#setMethod(int)
- */
- public void test_setMethodI() throws IOException {
- ZipEntry ze = new ZipEntry("test");
- zos.setMethod(ZipOutputStream.STORED);
- CRC32 tempCrc = new CRC32();
- tempCrc.update(data.getBytes());
- ze.setCrc(tempCrc.getValue());
- ze.setSize(new String(data).length());
- zos.putNextEntry(ze);
- zos.write(data.getBytes());
- zos.closeEntry();
- long csize = ze.getCompressedSize();
- zos.setMethod(ZipOutputStream.DEFLATED);
- zos.putNextEntry(ze = new ZipEntry("test2"));
- zos.write(data.getBytes());
- zos.closeEntry();
- assertTrue("setLevel failed", csize >= ze.getCompressedSize());
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#write(byte[], int, int)
- */
- public void test_write$BII() throws IOException {
- ZipEntry ze = new ZipEntry("test");
- zos.putNextEntry(ze);
- zos.write(data.getBytes());
- zos.closeEntry();
- zos.close();
- zos = null;
- zis = new ZipInputStream(new ByteArrayInputStream(bos.toByteArray()));
- zis.getNextEntry();
- byte[] b = new byte[data.length()];
- int r = 0;
- int count = 0;
- while (count != b.length && (r = zis.read(b, count, b.length)) != -1) {
- count += r;
- }
- zis.closeEntry();
- assertTrue("Write failed to write correct bytes", new String(b)
- .equals(data));
-
- File f = File.createTempFile("testZip", "tst");
- f.deleteOnExit();
- FileOutputStream stream = new FileOutputStream(f);
- ZipOutputStream zip = new ZipOutputStream(stream);
- zip.setMethod(ZipEntry.STORED);
-
- try {
- zip.putNextEntry(new ZipEntry("Second"));
- fail("Not set an entry. Should have thrown ZipException.");
- } catch (ZipException e) {
- // expected -- We have not set an entry
- }
-
- try {
- // We try to write data without entry
- zip.write(new byte[2]);
- fail("Writing data without an entry. Should have thrown IOException");
- } catch (IOException e) {
- // expected
- }
-
- try {
- // Try to write without an entry and with nonsense offset and
- // length
- zip.write(new byte[2], 0, 12);
- fail("Writing data without an entry. Should have thrown IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // Regression for HARMONY-4405
- try {
- zip.write(null, 0, -2);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // Close stream because ZIP is invalid
- stream.close();
- }
-
- /**
- * @tests java.util.zip.ZipOutputStream#write(byte[], int, int)
- */
- public void test_write$BII_2() throws IOException {
- // Regression for HARMONY-577
- File f1 = File.createTempFile("testZip1", "tst");
- f1.deleteOnExit();
- FileOutputStream stream1 = new FileOutputStream(f1);
- ZipOutputStream zip1 = new ZipOutputStream(stream1);
- zip1.putNextEntry(new ZipEntry("one"));
- zip1.setMethod(ZipOutputStream.STORED);
- zip1.setMethod(ZipEntry.STORED);
-
- zip1.write(new byte[2]);
-
- try {
- zip1.putNextEntry(new ZipEntry("Second"));
- fail("ZipException expected");
- } catch (ZipException e) {
- // expected - We have not set an entry
- }
-
- try {
- zip1.write(new byte[2]); // try to write data without entry
- fail("expected IOE there");
- } catch (IOException e2) {
- // expected
- }
-
- zip1.close();
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- zos = new ZipOutputStream(bos = new ByteArrayOutputStream());
- }
-
- @Override
- protected void tearDown() throws Exception {
- try {
- if (zos != null) {
- zos.close();
- }
- if (zis != null) {
- zis.close();
- }
- } catch (Exception e) {}
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java
index 4895708..4dac176 100644
--- a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java
+++ b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/CipherThread.java
@@ -35,7 +35,7 @@ public abstract class CipherThread implements Runnable {
private String paddingMode = null;
private int fails = 0;
- abstract public void crypt() throws Exception;
+ public abstract void crypt() throws Exception;
CipherThread(String name, int[] keys, String[] modes, String[] paddings) {
algName = name;
diff --git a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java
index 9772442..480ea7f 100644
--- a/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java
+++ b/luni/src/test/java/org/apache/harmony/crypto/tests/javax/crypto/func/KeyAgreementThread.java
@@ -15,6 +15,7 @@
*/
package org.apache.harmony.crypto.tests.javax.crypto.func;
+import com.android.org.bouncycastle.util.Arrays;
import java.security.AlgorithmParameterGenerator;
import java.security.AlgorithmParameters;
import java.security.KeyFactory;
@@ -24,12 +25,9 @@ import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.spec.X509EncodedKeySpec;
-
import javax.crypto.KeyAgreement;
import javax.crypto.spec.DHParameterSpec;
-import org.bouncycastle.util.Arrays;
-
public class KeyAgreementThread extends TestThread {
class KeyAgreementGen {
private PrivateKey privateKey = null;
diff --git a/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HeaderTest.java b/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HeaderTest.java
deleted file mode 100644
index 4f01c6f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HeaderTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.internal.net.www.protocol.http;
-
-import java.util.Arrays;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class HeaderTest extends junit.framework.TestCase {
- // http://code.google.com/p/android/issues/detail?id=6684
- public void test_caseInsensitiveButCasePreserving() {
- Header h = new Header();
- h.add("Content-Type", "text/plain");
- // Case-insensitive:
- assertEquals("text/plain", h.get("Content-Type"));
- assertEquals("text/plain", h.get("Content-type"));
- assertEquals("text/plain", h.get("content-type"));
- assertEquals("text/plain", h.get("CONTENT-TYPE"));
- // ...but case-preserving:
- assertEquals("Content-Type", h.getFieldMap().keySet().toArray()[0]);
-
- // We differ from the RI in that the Map we return is also case-insensitive.
- // Our behavior seems more consistent. (And code that works on the RI will work on Android.)
- assertEquals(Arrays.asList("text/plain"), h.getFieldMap().get("Content-Type"));
- assertEquals(Arrays.asList("text/plain"), h.getFieldMap().get("Content-type")); // RI fails this.
- }
-
- // The copy constructor used to be broken for headers with multiple values.
- // http://code.google.com/p/android/issues/detail?id=6722
- public void test_copyConstructor() {
- Header h1 = new Header();
- h1.add("key", "value1");
- h1.add("key", "value2");
- Header h2 = new Header(h1.getFieldMap());
- assertEquals(2, h2.length());
- assertEquals("key", h2.getKey(0));
- assertEquals("value1", h2.get(0));
- assertEquals("key", h2.getKey(1));
- assertEquals("value2", h2.get(1));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeadersTest.java b/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeadersTest.java
new file mode 100644
index 0000000..ff9aa58
--- /dev/null
+++ b/luni/src/test/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpHeadersTest.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.internal.net.www.protocol.http;
+
+import java.util.Arrays;
+import junit.framework.TestCase;
+
+public class HttpHeadersTest extends TestCase {
+ // http://code.google.com/p/android/issues/detail?id=6684
+ public void test_caseInsensitiveButCasePreserving() {
+ HttpHeaders h = new HttpHeaders();
+ h.add("Content-Type", "text/plain");
+ // Case-insensitive:
+ assertEquals("text/plain", h.get("Content-Type"));
+ assertEquals("text/plain", h.get("Content-type"));
+ assertEquals("text/plain", h.get("content-type"));
+ assertEquals("text/plain", h.get("CONTENT-TYPE"));
+ // ...but case-preserving:
+ assertEquals("Content-Type", h.toMultimap().keySet().toArray()[0]);
+
+ // We differ from the RI in that the Map we return is also case-insensitive.
+ // Our behavior seems more consistent. (And code that works on the RI will work on Android.)
+ assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-Type"));
+ assertEquals(Arrays.asList("text/plain"), h.toMultimap().get("Content-type")); // RI fails this.
+ }
+
+ // The copy constructor used to be broken for headers with multiple values.
+ // http://code.google.com/p/android/issues/detail?id=6722
+ public void test_copyConstructor() {
+ HttpHeaders h1 = new HttpHeaders();
+ h1.add("key", "value1");
+ h1.add("key", "value2");
+ HttpHeaders h2 = HttpHeaders.fromMultimap(h1.toMultimap());
+ assertEquals(2, h2.length());
+ assertEquals("key", h2.getKey(0));
+ assertEquals("value1", h2.getValue(0));
+ assertEquals("key", h2.getKey(1));
+ assertEquals("value2", h2.getValue(1));
+ }
+}
diff --git a/luni/src/test/java/org/apache/harmony/luni/platform/OSMemoryTest.java b/luni/src/test/java/org/apache/harmony/luni/platform/OSMemoryTest.java
index e5dbedc..5c283d4 100644
--- a/luni/src/test/java/org/apache/harmony/luni/platform/OSMemoryTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/platform/OSMemoryTest.java
@@ -17,115 +17,76 @@
package org.apache.harmony.luni.platform;
+import dalvik.system.VMRuntime;
import junit.framework.TestCase;
-/**
- * Tests org.apache.harmony.luni.platform.OSMemory.
- */
public class OSMemoryTest extends TestCase {
- public void testMemset() {
- int byteCount = 32;
- int ptr = OSMemory.malloc(byteCount);
- try {
- // Ensure our newly-allocated block isn't zeroed.
- OSMemory.setByte(ptr, (byte) 1);
- assertEquals((byte) 1, OSMemory.getByte(ptr));
- // Check that we can clear memory.
- OSMemory.memset(ptr, (byte) 0, byteCount);
- assertBytesEqual((byte) 0, ptr, byteCount);
- // Check that we can set an arbitrary value.
- OSMemory.memset(ptr, (byte) 1, byteCount);
- assertBytesEqual((byte) 1, ptr, byteCount);
- } finally {
- OSMemory.free(ptr);
- }
- }
-
- void assertBytesEqual(byte value, int ptr, int byteCount) {
- for (int i = 0; i < byteCount; ++i) {
- assertEquals(value, OSMemory.getByte(ptr + i));
- }
- }
-
public void testSetIntArray() {
int[] values = { 3, 7, 31, 127, 8191, 131071, 524287, 2147483647 };
int[] swappedValues = new int[values.length];
for (int i = 0; i < values.length; ++i) {
- swappedValues[i] = swapInt(values[i]);
+ swappedValues[i] = Integer.reverseBytes(values[i]);
}
- int scale = PlatformAddress.SIZEOF_JINT;
- int ptr = OSMemory.malloc(scale * values.length);
- try {
- // Regular copy. Memset first so we start from a known state.
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- OSMemory.setIntArray(ptr, values, 0, values.length, false);
- assertIntsEqual(values, ptr);
+ int scale = 4;
+ VMRuntime runtime = VMRuntime.getRuntime();
+ byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, scale * values.length);
+ int ptr = (int) runtime.addressOf(array);
+
+ // Regular copy.
+ OSMemory.pokeIntArray(ptr, values, 0, values.length, false);
+ assertIntsEqual(values, ptr, false);
+ assertIntsEqual(swappedValues, ptr, true);
- // Swapped copy.
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- OSMemory.setIntArray(ptr, values, 0, values.length, true);
- assertIntsEqual(swappedValues, ptr);
+ // Swapped copy.
+ OSMemory.pokeIntArray(ptr, values, 0, values.length, true);
+ assertIntsEqual(values, ptr, true);
+ assertIntsEqual(swappedValues, ptr, false);
- // Swapped copies of slices (to ensure we test non-zero offsets).
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- for (int i = 0; i < values.length; ++i) {
- OSMemory.setIntArray(ptr + i * scale, values, i, 1, true);
- }
- assertIntsEqual(swappedValues, ptr);
- } finally {
- OSMemory.free(ptr);
+ // Swapped copies of slices (to ensure we test non-zero offsets).
+ for (int i = 0; i < values.length; ++i) {
+ OSMemory.pokeIntArray(ptr + i * scale, values, i, 1, true);
}
+ assertIntsEqual(values, ptr, true);
+ assertIntsEqual(swappedValues, ptr, false);
}
- private void assertIntsEqual(int[] expectedValues, int ptr) {
+ private void assertIntsEqual(int[] expectedValues, int ptr, boolean swap) {
for (int i = 0; i < expectedValues.length; ++i) {
- assertEquals(expectedValues[i], OSMemory.getInt(ptr + PlatformAddress.SIZEOF_JINT * i));
+ assertEquals(expectedValues[i], OSMemory.peekInt(ptr + 4 * i, swap));
}
}
- private static int swapInt(int n) {
- return (((n >> 0) & 0xff) << 24) |
- (((n >> 8) & 0xff) << 16) |
- (((n >> 16) & 0xff) << 8) |
- (((n >> 24) & 0xff) << 0);
- }
-
public void testSetShortArray() {
short[] values = { 0x0001, 0x0020, 0x0300, 0x4000 };
short[] swappedValues = { 0x0100, 0x2000, 0x0003, 0x0040 };
- int scale = PlatformAddress.SIZEOF_JSHORT;
- int ptr = OSMemory.malloc(scale * values.length);
- try {
- // Regular copy. Memset first so we start from a known state.
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- OSMemory.setShortArray(ptr, values, 0, values.length, false);
- assertShortsEqual(values, ptr);
+ int scale = 2;
+ VMRuntime runtime = VMRuntime.getRuntime();
+ byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, scale * values.length);
+ int ptr = (int) runtime.addressOf(array);
+
+ // Regular copy. Memset first so we start from a known state.
+ OSMemory.pokeShortArray(ptr, values, 0, values.length, false);
+ assertShortsEqual(values, ptr, false);
+ assertShortsEqual(swappedValues, ptr, true);
- // Swapped copy.
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- OSMemory.setShortArray(ptr, values, 0, values.length, true);
- assertShortsEqual(swappedValues, ptr);
+ // Swapped copy.
+ OSMemory.pokeShortArray(ptr, values, 0, values.length, true);
+ assertShortsEqual(values, ptr, true);
+ assertShortsEqual(swappedValues, ptr, false);
- // Swapped copies of slices (to ensure we test non-zero offsets).
- OSMemory.memset(ptr, (byte) 0, scale * values.length);
- for (int i = 0; i < values.length; ++i) {
- OSMemory.setShortArray(ptr + i * scale, values, i, 1, true);
- }
- assertShortsEqual(swappedValues, ptr);
- } finally {
- OSMemory.free(ptr);
+ // Swapped copies of slices (to ensure we test non-zero offsets).
+ for (int i = 0; i < values.length; ++i) {
+ OSMemory.pokeShortArray(ptr + i * scale, values, i, 1, true);
}
+ assertShortsEqual(values, ptr, true);
+ assertShortsEqual(swappedValues, ptr, false);
}
- private void assertShortsEqual(short[] expectedValues, int ptr) {
+ private void assertShortsEqual(short[] expectedValues, int ptr, boolean swap) {
for (int i = 0; i < expectedValues.length; ++i) {
- assertEquals(expectedValues[i], OSMemory.getShort(ptr + PlatformAddress.SIZEOF_JSHORT * i));
+ assertEquals(expectedValues[i], OSMemory.peekShort(ptr + 2 * i, swap));
}
}
-
- private static short swapShort(short n) {
- return (short) ((((n >> 0) & 0xff) << 8) | (((n >> 8) & 0xff) << 0));
- }
}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
index 4c277bb..216af26 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java
@@ -55,6 +55,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import junit.framework.TestCase;
import libcore.java.security.TestKeyStore;
+import libcore.javax.net.ssl.TestTrustManager;
/**
* Implementation independent test for HttpsURLConnection.
@@ -686,6 +687,9 @@ public class HttpsURLConnectionTest extends TestCase {
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorthm);
tmf.init(ks);
TrustManager[] trustManagers = tmf.getTrustManagers();
+ if (DO_LOG) {
+ trustManagers = TestTrustManager.wrap(trustManagers);
+ }
SSLContext ctx = SSLContext.getInstance("TLSv1");
ctx.init(keyManagers, trustManagers, null);
@@ -959,10 +963,6 @@ public class HttpsURLConnectionTest extends TestCase {
// client connection sent some data
log("try to read client data");
String data = message.substring(message.indexOf("\r\n\r\n")+4);
- int dataNum = is.read(buff);
- if (dataNum != -1) {
- data += new String(buff, 0, dataNum);
- }
log("client's data: '" + data + "'");
// check the received data
assertEquals(clientsData, data);
@@ -1025,10 +1025,6 @@ public class HttpsURLConnectionTest extends TestCase {
// client connection sent some data
log("[Remote Server] try to read client data");
String data = message.substring(message.indexOf("\r\n\r\n")+4);
- int dataNum = is.read(buff);
- if (dataNum != -1) {
- data += new String(buff, 0, dataNum);
- }
log("[Remote Server] client's data: '" + message + "'");
// check the received data
assertEquals(clientsData, data);
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java
deleted file mode 100644
index e266b7c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/AllTests.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * Listing of all the tests that are to be run.
- */
-public class AllTests
-{
-
- public static void run() {
- TestRunner.main(new String[] { AllTests.class.getName() });
- }
-
- public static final Test suite() {
- TestSuite suite = new TestSuite("Tests for java.io");
-
- suite.addTestSuite(BufferedReaderTest.class);
- suite.addTestSuite(FilePermissionTest.class);
- suite.addTestSuite(FileTest.class);
- suite.addTestSuite(InputStreamReaderTest.class);
- suite.addTestSuite(ObjectInputStreamTest.class);
- suite.addTestSuite(ObjectStreamConstantsTest.class);
- suite.addTestSuite(OutputStreamWriterTest.class);
- suite.addTestSuite(PushBackInputStreamTest.class);
- suite.addTestSuite(RandomAccessFileTest.class);
- suite.addTestSuite(ReaderTest.class);
- suite.addTestSuite(WriterTest.class);
-
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
deleted file mode 100644
index 0581ecc..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/BufferedReaderTest.java
+++ /dev/null
@@ -1,592 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PipedReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import junit.framework.TestCase;
-import tests.support.Support_StringReader;
-
-public class BufferedReaderTest extends TestCase {
-
- BufferedReader br;
-
- String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * The spec says that BufferedReader.readLine() considers only "\r", "\n"
- * and "\r\n" to be line separators. We must not permit additional separator
- * characters.
- */
- public void test_readLine_IgnoresEbcdic85Characters() throws IOException {
- assertLines("A\u0085B", "A\u0085B");
- }
-
- public void test_readLine_Separators() throws IOException {
- assertLines("A\nB\nC", "A", "B", "C");
- assertLines("A\rB\rC", "A", "B", "C");
- assertLines("A\r\nB\r\nC", "A", "B", "C");
- assertLines("A\n\rB\n\rC", "A", "", "B", "", "C");
- assertLines("A\n\nB\n\nC", "A", "", "B", "", "C");
- assertLines("A\r\rB\r\rC", "A", "", "B", "", "C");
- assertLines("A\n\n", "A", "");
- assertLines("A\n\r", "A", "");
- assertLines("A\r\r", "A", "");
- assertLines("A\r\n", "A");
- assertLines("A\r\n\r\n", "A", "");
- }
-
- private void assertLines(String in, String... lines) throws IOException {
- BufferedReader bufferedReader
- = new BufferedReader(new Support_StringReader(in));
- for (String line : lines) {
- assertEquals(line, bufferedReader.readLine());
- }
- assertNull(bufferedReader.readLine());
- }
-
- /**
- * @tests java.io.BufferedReader#BufferedReader(java.io.Reader)
- */
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.BufferedReader(java.io.Reader)
- assertTrue("Used in tests", true);
- }
-
- /**
- * @tests java.io.BufferedReader#BufferedReader(java.io.Reader, int)
- */
- public void test_ConstructorLjava_io_ReaderI() {
- // Test for method java.io.BufferedReader(java.io.Reader, int)
- assertTrue("Used in tests", true);
- }
-
- /**
- * @tests java.io.BufferedReader#close()
- */
- public void test_close() {
- // Test for method void java.io.BufferedReader.close()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.close();
- br.read();
- fail("Read on closed stream");
- } catch (IOException x) {
- return;
- }
- }
-
- /**
- * @tests java.io.BufferedReader#mark(int)
- */
- public void test_markI() throws IOException {
- // Test for method void java.io.BufferedReader.mark(int)
- char[] buf = null;
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.mark(1000);
- br.skip(250);
- br.reset();
- buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to set mark properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
-
- try {
- br = new BufferedReader(new Support_StringReader(testString), 800);
- br.skip(500);
- br.mark(250);
- br.read(buf, 0, 1000);
- br.reset();
- fail("Failed to invalidate mark properly");
- } catch (IOException x) {
- // Expected
- }
-
- char[] chars = new char[256];
- for (int i = 0; i < 256; i++)
- chars[i] = (char) i;
- Reader in = new BufferedReader(new Support_StringReader(new String(
- chars)), 12);
-
- in.skip(6);
- in.mark(14);
- in.read(new char[14], 0, 14);
- in.reset();
- assertTrue("Wrong chars", in.read() == (char) 6
- && in.read() == (char) 7);
-
- in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
- in.skip(6);
- in.mark(8);
- in.skip(7);
- in.reset();
- assertTrue("Wrong chars 2", in.read() == (char) 6
- && in.read() == (char) 7);
-
- BufferedReader br = new BufferedReader(new StringReader("01234"), 2);
- br.mark(3);
- char[] carray = new char[3];
- int result = br.read(carray);
- assertEquals(3, result);
- assertEquals("Assert 0:", '0', carray[0]);
- assertEquals("Assert 1:", '1', carray[1]);
- assertEquals("Assert 2:", '2', carray[2]);
- assertEquals("Assert 3:", '3', br.read());
-
- br = new BufferedReader(new StringReader("01234"), 2);
- br.mark(3);
- carray = new char[4];
- result = br.read(carray);
- assertEquals("Assert 4:", 4, result);
- assertEquals("Assert 5:", '0', carray[0]);
- assertEquals("Assert 6:", '1', carray[1]);
- assertEquals("Assert 7:", '2', carray[2]);
- assertEquals("Assert 8:", '3', carray[3]);
- assertEquals("Assert 9:", '4', br.read());
- assertEquals("Assert 10:", -1, br.read());
-
- BufferedReader reader = new BufferedReader(new StringReader("01234"));
- reader.mark(Integer.MAX_VALUE);
- reader.read();
- reader.close();
- }
-
- /**
- * @tests java.io.BufferedReader#markSupported()
- */
- public void test_markSupported() {
- // Test for method boolean java.io.BufferedReader.markSupported()
- br = new BufferedReader(new Support_StringReader(testString));
- assertTrue("markSupported returned false", br.markSupported());
- }
-
- /**
- * @tests java.io.BufferedReader#read()
- */
- public void test_read() throws IOException {
- // Test for method int java.io.BufferedReader.read()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- int r = br.read();
- assertTrue("Char read improperly", testString.charAt(0) == r);
- br = new BufferedReader(new Support_StringReader(new String(
- new char[] { '\u8765' })));
- assertTrue("Wrong double byte character", br.read() == '\u8765');
- } catch (java.io.IOException e) {
- fail("Exception during read test");
- }
-
- char[] chars = new char[256];
- for (int i = 0; i < 256; i++)
- chars[i] = (char) i;
- Reader in = new BufferedReader(new Support_StringReader(new String(
- chars)), 12);
- try {
- assertEquals("Wrong initial char", 0, in.read()); // Fill the
- // buffer
- char[] buf = new char[14];
- in.read(buf, 0, 14); // Read greater than the buffer
- assertTrue("Wrong block read data", new String(buf)
- .equals(new String(chars, 1, 14)));
- assertEquals("Wrong chars", 15, in.read()); // Check next byte
- } catch (IOException e) {
- fail("Exception during read test 2:" + e);
- }
-
- // regression test for HARMONY-841
- assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
- }
-
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- public void test_read$CII() throws Exception{
- char[] ca = new char[2];
- BufferedReader toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[0])));
-
- /* Null buffer should throw NPE even when len == 0 */
- try {
- toRet.read(null, 1, 0);
- fail("null buffer reading zero bytes should throw NPE");
- } catch (NullPointerException e) {
- //expected
- }
-
- try {
- toRet.close();
- } catch (IOException e) {
- fail("unexpected 1: " + e);
- }
-
- try {
- toRet.read(null, 1, 0);
- fail("null buffer reading zero bytes on closed stream should throw IOException");
- } catch (IOException e) {
- //expected
- }
-
- /* Closed reader should throw IOException reading zero bytes */
- try {
- toRet.read(ca, 0, 0);
- fail("Reading zero bytes on a closed reader should not work");
- } catch (IOException e) {
- // expected
- }
-
- /*
- * Closed reader should throw IOException in preference to index out of
- * bounds
- */
- try {
- // Read should throw IOException before
- // ArrayIndexOutOfBoundException
- toRet.read(ca, 1, 5);
- fail("IOException should have been thrown");
- } catch (IOException e) {
- // expected
- }
-
- // Test to ensure that a drained stream returns 0 at EOF
- toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[2])));
- try {
- assertEquals("Emptying the reader should return two bytes", 2,
- toRet.read(ca, 0, 2));
- assertEquals("EOF on a reader should be -1", -1, toRet.read(ca, 0,
- 2));
- assertEquals("Reading zero bytes at EOF should work", 0, toRet
- .read(ca, 0, 0));
- } catch (IOException ex) {
- fail("Unexpected IOException : " + ex.getLocalizedMessage());
- }
-
- // Test for method int java.io.BufferedReader.read(char [], int, int)
- try {
- char[] buf = new char[testString.length()];
- br = new BufferedReader(new Support_StringReader(testString));
- br.read(buf, 50, 500);
- assertTrue("Chars read improperly", new String(buf, 50, 500)
- .equals(testString.substring(0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during read test");
- }
-
- BufferedReader bufin = new BufferedReader(new Reader() {
- int size = 2, pos = 0;
-
- char[] contents = new char[size];
-
- public int read() throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- return contents[pos++];
- }
-
- public int read(char[] buf, int off, int len) throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- int toRead = len;
- if (toRead > (size - pos))
- toRead = size - pos;
- System.arraycopy(contents, pos, buf, off, toRead);
- pos += toRead;
- return toRead;
- }
-
- public boolean ready() throws IOException {
- return size - pos > 0;
- }
-
- public void close() throws IOException {
- }
- });
- try {
- bufin.read();
- int result = bufin.read(new char[2], 0, 2);
- assertTrue("Incorrect result: " + result, result == 1);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
-
- //regression for HARMONY-831
- try{
- new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
- fail("should throw IndexOutOfBoundsException");
- }catch(IndexOutOfBoundsException e){
- }
-
- // Regression for HARMONY-54
- char[] ch = {};
- BufferedReader reader = new BufferedReader(new CharArrayReader(ch));
- try {
- // Check exception thrown when the reader is open.
- reader.read(null, 1, 0);
- fail("Assert 0: NullPointerException expected");
- } catch (NullPointerException e) {
- // Expected
- }
-
- // Now check IOException is thrown in preference to
- // NullPointerexception when the reader is closed.
- reader.close();
- try {
- reader.read(null, 1, 0);
- fail("Assert 1: IOException expected");
- } catch (IOException e) {
- // Expected
- }
-
- try {
- // And check that the IOException is thrown before
- // ArrayIndexOutOfBoundException
- reader.read(ch, 0, 42);
- fail("Assert 2: IOException expected");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- public void test_read_$CII_Exception() throws IOException {
- br = new BufferedReader(new Support_StringReader(testString));
- char[] nullCharArray = null;
- char[] charArray = testString.toCharArray();
-
- try {
- br.read(nullCharArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- br.read(nullCharArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- br.read(nullCharArray, 0, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- br.read(nullCharArray, 0, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- br.read(nullCharArray, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- br.read(charArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- br.read(charArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- br.read(charArray, 0, 0);
- br.read(charArray, 0, charArray.length);
- br.read(charArray, charArray.length, 0);
-
- try {
- br.read(charArray, charArray.length + 1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- br.read(charArray, charArray.length + 1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- br.close();
-
- try {
- br.read(nullCharArray, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- try {
- br.read(charArray, -1, 0);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- try {
- br.read(charArray, 0, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
- /**
- * @tests java.io.BufferedReader#readLine()
- */
- public void test_readLine() {
- // Test for method java.lang.String java.io.BufferedReader.readLine()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- String r = br.readLine();
- assertEquals("readLine returned incorrect string", "Test_All_Tests", r
- );
- } catch (java.io.IOException e) {
- fail("Exception during readLine test");
- }
- }
-
- /**
- * @tests java.io.BufferedReader#ready()
- */
- public void test_ready() {
- // Test for method boolean java.io.BufferedReader.ready()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- assertTrue("ready returned false", br.ready());
- } catch (java.io.IOException e) {
- fail("Exception during ready test" + e.toString());
- }
- }
-
- /**
- * @tests java.io.BufferedReader#reset()
- */
- public void test_reset() {
- // Test for method void java.io.BufferedReader.reset()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.mark(900);
- br.skip(500);
- br.reset();
- char[] buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to reset properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during reset test");
- }
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.reset();
- fail("Reset succeeded on unmarked stream");
- } catch (IOException x) {
- return;
-
- }
- }
-
- public void test_reset_IOException() throws Exception {
- int[] expected = new int[] { '1', '2', '3', '4', '5', '6', '7', '8',
- '9', '0', -1 };
- br = new BufferedReader(new Support_StringReader("1234567890"), 9);
- br.mark(9);
- for (int i = 0; i < 11; i++) {
- assertEquals(expected[i], br.read());
- }
- try {
- br.reset();
- fail("should throw IOException");
- } catch (IOException e) {
- // Expected
- }
- for (int i = 0; i < 11; i++) {
- assertEquals(-1, br.read());
- }
-
- br = new BufferedReader(new Support_StringReader("1234567890"));
- br.mark(10);
- for (int i = 0; i < 10; i++) {
- assertEquals(expected[i], br.read());
- }
- br.reset();
- for (int i = 0; i < 11; i++) {
- assertEquals(expected[i], br.read());
- }
- }
-
- /**
- * @tests java.io.BufferedReader#skip(long)
- */
- public void test_skipJ() {
- // Test for method long java.io.BufferedReader.skip(long)
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- char[] buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to set skip properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during skip test");
- }
-
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- br.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
deleted file mode 100644
index 5b5a759..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FilePermissionTest.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.File;
-import java.io.FilePermission;
-import java.security.PermissionCollection;
-
-import junit.framework.TestCase;
-
-public class FilePermissionTest extends TestCase {
-
- FilePermission readAllFiles = new FilePermission("<<ALL FILES>>", "read");
-
- FilePermission alsoReadAllFiles = new FilePermission("<<ALL FILES>>",
- "read");
-
- FilePermission allInCurrent = new FilePermission("*",
- "read, write, execute,delete");
-
- FilePermission readInCurrent = new FilePermission("*", "read");
-
- FilePermission readInFile = new FilePermission("aFile.file", "read");
-
- FilePermission readInSubdir = new FilePermission("-", "read");
-
- /**
- * @tests java.io.FilePermission#FilePermission(java.lang.String,
- * java.lang.String)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- assertTrue("Used to test", true);
- FilePermission constructFile = new FilePermission("test constructor",
- "write");
- assertEquals(
- "action given to the constructor did not correspond - constructor failed",
- "write", constructFile.getActions());
- assertTrue(
- "name given to the constructor did not correspond - constructor failed",
- constructFile.getName() == "test constructor");
-
- // Regression test for HARMONY-1050
- try {
- new FilePermission(null, "drink");
- fail("Expected IAE");
- } catch (IllegalArgumentException e) {
- // Expected
- }
-
- try {
- new FilePermission(null, "read");
- fail("Expected NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- new FilePermission(null, null);
- fail("Expected IAE");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.FilePermission#getActions()
- */
- public void test_getActions() {
- assertEquals("getActions should have returned only read", "read",
- readAllFiles.getActions());
- assertEquals("getActions should have returned all actions",
- "read,write,execute,delete", allInCurrent.getActions());
- }
-
- /**
- * @tests java.io.FilePermission#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object() {
- assertTrue(
- "Should not returned false when two instance of FilePermission is equal",
- readAllFiles.equals(alsoReadAllFiles));
- assertFalse(
- "Should not returned true when two instance of FilePermission is not equal",
- readInCurrent.equals(readInFile));
- }
-
- /**
- * @tests java.io.FilePermission#implies(java.security.Permission)
- */
- public void test_impliesLjava_security_Permission() {
- assertFalse("Should not return true for non-subset of actions", readAllFiles
- .implies(allInCurrent));
- assertFalse("Should not return true for non-subset of files", allInCurrent
- .implies(readAllFiles));
- assertTrue("Should not return false for subset of actions", allInCurrent
- .implies(readInCurrent));
- assertTrue("Should not return false for subset of files", readAllFiles
- .implies(readInCurrent));
- assertTrue("Should not return false for subset of files and actions",
- allInCurrent.implies(readInFile));
- assertTrue("Should not return false for equal FilePermissions", readAllFiles
- .implies(alsoReadAllFiles));
- assertTrue("Should not return false for subdir self", readInSubdir.implies(readInSubdir));
- assertTrue("Should not return false for current self", readInCurrent.implies(readInCurrent));
- assertTrue("Should not return false for subdir", readInSubdir.implies(readInCurrent));
-
- FilePermission fp13 = new FilePermission(File.separator, "read");
- FilePermission fp14 = new FilePermission(File.separator + "*", "read");
- assertFalse("/ should not imply /*", fp13.implies(fp14));
- fp14 = new FilePermission(File.separator + "-", "read");
- assertFalse("/ should not imply /-", fp13.implies(fp14));
-
- FilePermission fp3 = new FilePermission("/bob/*".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp4 = new FilePermission("/bob/".replace('/',
- File.separatorChar), "write");
- assertFalse("Should not return true for same dir using * and not *", fp3
- .implies(fp4));
- FilePermission fp5 = new FilePermission("/bob/file".replace('/',
- File.separatorChar), "write");
- assertTrue("Should not return false for same dir using * and file", fp3
- .implies(fp5));
-
- FilePermission fp6 = new FilePermission("/bob/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp7 = new FilePermission("/bob/*".replace('/',
- File.separatorChar), "write");
- assertFalse("Should not return true for same dir using not * and *", fp6
- .implies(fp7));
- assertTrue("Should not return false for same subdir", fp6.implies(fp4));
-
- FilePermission fp8 = new FilePermission("/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp9 = new FilePermission("/".replace('/',
- File.separatorChar), "write");
- assertTrue("Should not return false for same dir", fp8.implies(fp9));
-
- FilePermission fp10 = new FilePermission("/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp11 = new FilePermission("/".replace('/',
- File.separatorChar), "write");
- assertTrue("Should not return false for same dir", fp10.implies(fp11));
-
- FilePermission fp12 = new FilePermission("/*".replace('/',
- File.separatorChar), "read,write");
- assertFalse("Should not return true for same dir using * and dir", fp12
- .implies(fp10));
-
- // Regression for HARMONY-47
- char separator = File.separatorChar;
- char nonSeparator = (separator == '/') ? '\\' : '/';
-
- FilePermission fp1 = new FilePermission(nonSeparator + "*", "read");
- FilePermission fp2 = new FilePermission(separator + "a", "read");
- assertFalse("Assert 0: non-separator worked", fp1.implies(fp2));
- fp1 = new FilePermission(nonSeparator + "-", "read");
- assertFalse("Assert 1: non-separator worked", fp1.implies(fp2));
- }
-
- /**
- * @tests java.io.FilePermission#newPermissionCollection()
- */
- public void test_newPermissionCollection() {
- char s = File.separatorChar;
- FilePermission perm[] = new FilePermission[4];
- perm[0] = readAllFiles;
- perm[1] = allInCurrent;
- perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
- "read,write");
- perm[3] = new FilePermission(s + "tmp" + s + "test" + s
- + "collection.file", "read");
-
- PermissionCollection collect = perm[0].newPermissionCollection();
- for (int i = 0; i < perm.length; i++) {
- collect.add(perm[i]);
- }
- assertTrue("Should not return false for subset of files", collect
- .implies(new FilePermission("*", "write")));
- assertTrue("Should not return false for subset of name and action", collect
- .implies(new FilePermission(s + "tmp", "read")));
- assertTrue("Should not return false for non subset of file and action", collect
- .implies(readInFile));
-
- FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
- File.separatorChar), "read");
- PermissionCollection fpc = fp1.newPermissionCollection();
- fpc.add(fp1);
- fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
- File.separatorChar), "write"));
- FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
- .replace('/', File.separatorChar), "read,write");
- assertTrue("collection does not collate", fpc.implies(fp2));
- }
-
- /**
- * @tests java.io.FilePermission#hashCode()
- */
- public void test_hashCode() {
- assertTrue(
- "two equal filePermission instances returned different hashCode",
- readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
- assertTrue(
- "two filePermission instances with same permission name returned same hashCode",
- readInCurrent.hashCode() != allInCurrent.hashCode());
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
deleted file mode 100644
index f828c3b..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/FileTest.java
+++ /dev/null
@@ -1,2262 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.RandomAccessFile;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-import tests.support.Support_Exec;
-import tests.support.Support_PlatformFile;
-
-public class FileTest extends TestCase {
-
- private static String platformId = "JDK"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- private static void deleteTempFolder(File dir) {
- String files[] = dir.list();
- if (files != null) {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- if (f.isDirectory()) {
- deleteTempFolder(f);
- } else {
- f.delete();
- }
- }
- }
- dir.delete();
- }
-
- private static String addTrailingSlash(String path) {
- if (File.separatorChar == path.charAt(path.length() - 1)) {
- return path;
- }
- return path + File.separator;
- }
-
- /** Location to store tests in */
- private File tempDirectory;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_File\nTest_FileDescriptor\nTest_FileInputStream\nTest_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- protected void setUp() throws IOException {
- /** Setup the temporary directory */
- tempDirectory = new File(addTrailingSlash(System.getProperty("java.io.tmpdir")) + "harmony-test-" + getClass().getSimpleName() + File.separator);
- tempDirectory.mkdirs();
- }
-
- protected void tearDown() {
- if (tempDirectory != null) {
- deleteTempFolder(tempDirectory);
- tempDirectory = null;
- }
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- public void test_ConstructorLjava_io_FileLjava_lang_String0() {
- File f = new File(tempDirectory.getPath(), "input.tst");
- assertEquals("Created Incorrect File ", addTrailingSlash(tempDirectory.getPath()) + "input.tst", f.getPath());
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String1() {
- try {
- new File(tempDirectory, null);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- }
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String2() throws IOException {
- File f = new File((File)null, "input.tst");
- assertEquals("Created Incorrect File",
- new File("input.tst").getAbsolutePath(),
- f.getAbsolutePath());
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String3() {
- // Regression test for HARMONY-382
- File f = new File("/abc");
- File d = new File((File)null, "/abc");
- assertEquals("Test3: Created Incorrect File",
- d.getAbsolutePath(), f.getAbsolutePath());
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String4() {
- // Regression test for HARMONY-21
- File path = new File("/dir/file");
- File root = new File("/");
- File file = new File(root, "/dir/file");
- assertEquals("Assert 1: wrong path result ", path.getPath(), file
- .getPath());
- if (File.separatorChar == '\\') {
- assertTrue("Assert 1.1: path not absolute ", new File("\\\\\\a\b")
- .isAbsolute());
- } else {
- assertFalse("Assert 1.1: path absolute ", new File("\\\\\\a\b")
- .isAbsolute());
- }
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String5() {
- // Test data used in a few places below
- String dirName = tempDirectory.getPath();
- String fileName = "input.tst";
-
- // Check filename is preserved correctly
- File d = new File(dirName);
- File f = new File(d, fileName);
- dirName = addTrailingSlash(dirName);
- dirName += fileName;
- assertEquals("Assert 1: Created incorrect file ",
- dirName, f.getPath());
-
- // Check null argument is handled
- try {
- f = new File(d, null);
- fail("Assert 2: NullPointerException not thrown.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- public void test_ConstructorLjava_io_FileLjava_lang_String6() {
- // Regression for HARMONY-46
- File f1 = new File("a");
- File f2 = new File("a/");
- assertEquals("Trailing slash file name is incorrect", f1, f2);
- }
-
- /**
- * @tests java.io.File#File(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- String fileName = null;
- try {
- new File(fileName);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- fileName = addTrailingSlash(tempDirectory.getPath());
- fileName += "input.tst";
-
- File f = new File(fileName);
- assertEquals("Created incorrect File", fileName, f.getPath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_String() throws IOException {
- String dirName = null;
- String fileName = "input.tst";
- File f = new File(dirName, fileName);
- assertEquals("Test 1: Created Incorrect File",
- new File("input.tst").getAbsolutePath(),
- f.getAbsolutePath());
-
- dirName = tempDirectory.getPath();
- fileName = null;
- try {
- f = new File(dirName, fileName);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- fileName = "input.tst";
- f = new File(dirName, fileName);
- assertEquals("Test 2: Created Incorrect File",
- addTrailingSlash(tempDirectory.getPath()) + "input.tst",
- f.getPath());
-
- // Regression test for HARMONY-382
- String s = null;
- f = new File("/abc");
- File d = new File(s, "/abc");
- assertEquals("Test3: Created Incorrect File", d.getAbsolutePath(), f
- .getAbsolutePath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- public void test_Constructor_String_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File file1 = new File("/", "/dir1/file1");
- assertEquals("wrong result 1", ref1.getPath(), file1.getPath());
- File file2 = new File("/", "//dir1/file1");
- assertEquals("wrong result 2", ref1.getPath(), file2.getPath());
-
- if (File.separatorChar == '\\') {
- File file3 = new File("\\", "\\dir1\\file1");
- assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
- File file4 = new File("\\", "\\\\dir1\\file1");
- assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
- }
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File("/", "lib/content-types.properties");
- assertEquals("wrong result 5", ref2.getPath(), file5.getPath());
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- public void test_Constructor_File_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File root = new File("/");
- File file1 = new File(root, "/dir1/file1");
- assertEquals("wrong result 1", ref1.getPath(), file1.getPath());
- File file2 = new File(root, "//dir1/file1");
- assertEquals("wrong result 2", ref1.getPath(), file2.getPath());
-
- if (File.separatorChar == '\\') {
- File file3 = new File(root, "\\dir1\\file1");
- assertEquals("wrong result 3", ref1.getPath(), file3.getPath());
- File file4 = new File(root, "\\\\dir1\\file1");
- assertEquals("wrong result 4", ref1.getPath(), file4.getPath());
- }
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File(root, "lib/content-types.properties");
- assertEquals("wrong result 5", ref2.getPath(), file5.getPath());
- }
-
- /**
- * @tests java.io.File#File(java.net.URI)
- */
- public void test_ConstructorLjava_net_URI() throws URISyntaxException {
- URI uri = null;
- try {
- new File(uri);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- // invalid file URIs
- String[] uris = new String[] { "mailto:user@domain.com", // not
- // hierarchical
- "ftp:///path", // not file scheme
- "//host/path/", // not absolute
- "file://host/path", // non empty authority
- "file:///path?query", // non empty query
- "file:///path#fragment", // non empty fragment
- "file:///path?", "file:///path#" };
-
- for (int i = 0; i < uris.length; i++) {
- uri = new URI(uris[i]);
- try {
- new File(uri);
- fail("Expected IllegalArgumentException for new File(" + uri
- + ")");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
-
- // a valid File URI
- File f = new File(new URI("file:///pa%20th/another\u20ac/pa%25th"));
- assertTrue("Created incorrect File " + f.getPath(), f.getPath().equals(
- File.separator + "pa th" + File.separator + "another\u20ac" + File.separator + "pa%th"));
- }
-
- /**
- * @tests java.io.File#canRead()
- */
- public void test_canRead() throws IOException {
- // canRead only returns if the file exists so cannot be fully tested.
- File f = new File(tempDirectory, platformId + "canRead.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canRead returned false", f.canRead());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#canWrite()
- */
- public void test_canWrite() throws IOException {
- // canWrite only returns if the file exists so cannot be fully tested.
- File f = new File(tempDirectory, platformId + "canWrite.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canWrite returned false", f.canWrite());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#compareTo(java.io.File)
- */
- public void test_compareToLjava_io_File() {
- File f1 = new File("thisFile.file");
- File f2 = new File("thisFile.file");
- File f3 = new File("thatFile.file");
- assertEquals("Equal files did not answer zero for compareTo", 0, f1
- .compareTo(f2));
- assertTrue("f3.compareTo(f1) did not result in value < 0", f3
- .compareTo(f1) < 0);
- assertTrue("f1.compareTo(f3) did not result in value > 0", f1
- .compareTo(f3) > 0);
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- public void test_createNewFile_EmptyString() {
- File f = new File("");
- try {
- f.createNewFile();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- public void test_createNewFile() throws IOException {
- String base = tempDirectory.getPath();
- boolean dirExists = true;
- int numDir = 1;
- File dir = new File(base, String.valueOf(numDir));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making it a new directory name.)
- if (dir.exists()) {
- numDir++;
- dir = new File(base, String.valueOf(numDir));
- } else {
- dirExists = false;
- }
- }
-
- // Test for trying to create a file in a directory that does not
- // exist.
- try {
- // Try to create a file in a directory that does not exist
- File f1 = new File(dir, "tempfile.tst");
- f1.createNewFile();
- fail("IOException not thrown");
- } catch (IOException e) {
- // Expected
- }
-
- dir.mkdir();
-
- File f1 = new File(dir, "tempfile.tst");
- File f2 = new File(dir, "tempfile.tst");
- f1.deleteOnExit();
- f2.deleteOnExit();
- dir.deleteOnExit();
- assertFalse("File Should Not Exist", f1.isFile());
- f1.createNewFile();
- assertTrue("File Should Exist.", f1.isFile());
- assertTrue("File Should Exist.", f2.isFile());
- String dirName = f1.getParent();
- if (!dirName.endsWith(File.separator)) {
- dirName += File.separator;
- }
- assertEquals("File Saved To Wrong Directory.",
- dir.getPath() + File.separator, dirName);
- assertEquals("File Saved With Incorrect Name.", "tempfile.tst",
- f1.getName());
-
- // Test for creating a file that already exists.
- assertFalse("File Already Exists, createNewFile Should Return False.",
- f2.createNewFile());
-
- // Test create an illegal file
- String sep = File.separator;
- f1 = new File(sep + "..");
- try {
- f1.createNewFile();
- fail("should throw IOE");
- } catch (IOException e) {
- // expected;
- }
- f1 = new File(sep + "a" + sep + ".." + sep + ".." + sep);
- try {
- f1.createNewFile();
- fail("should throw IOE");
- } catch (IOException e) {
- // expected;
- }
-
- // This test is invalid. createNewFile should return false
- // not IOE when the file exists (in this case it exists and is
- // a directory). TODO: We should probably replace this test
- // with some that cover this behaviour. It might even be
- // different on unix and windows since it directly reflects
- // the open syscall behaviour.
- //
- // // Test create an exist path
- // f1 = new File(base);
- // try {
- // assertFalse(f1.createNewFile());
- // fail("should throw IOE");
- // } catch (IOException e) {
- // // expected;
- // }
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String)
- */
- public void test_createTempFileLjava_lang_StringLjava_lang_String()
- throws IOException {
- // Error protection against using a suffix without a "."?
- File f1 = null;
- File f2 = null;
- try {
- f1 = File.createTempFile("harmony-test-FileTest_tempFile_abc", ".tmp");
- f2 = File.createTempFile("harmony-test-FileTest_tempFile_tf", null);
-
- String fileLocation = addTrailingSlash(f1.getParent());
-
- String tempDir = addTrailingSlash(System.getProperty("java.io.tmpdir"));
-
- assertEquals(
- "File did not save to the default temporary-file location.",
- tempDir, fileLocation);
-
- // Test to see if correct suffix was used to create the tempfile.
- File currentFile;
- String fileName;
- // Testing two files, one with suffix ".tmp" and one with null
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileName = currentFile.getPath();
- assertTrue("File Created With Incorrect Suffix.", fileName
- .endsWith(".tmp"));
- }
-
- // Tests to see if the correct prefix was used to create the
- // tempfiles.
- fileName = f1.getName();
- assertTrue("Test 1: File Created With Incorrect Prefix.", fileName
- .startsWith("harmony-test-FileTest_tempFile_abc"));
- fileName = f2.getName();
- assertTrue("Test 2: File Created With Incorrect Prefix.", fileName
- .startsWith("harmony-test-FileTest_tempFile_tf"));
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f3 = File.createTempFile("ab", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- File f3 = File.createTempFile("a", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- File f3 = File.createTempFile("", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- } finally {
- if (f1 != null) {
- f1.delete();
- }
- if (f2 != null) {
- f2.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String,
- * java.io.File)
- */
- public void test_createTempFileLjava_lang_StringLjava_lang_StringLjava_io_File()
- throws IOException {
- File f1 = null;
- File f2 = null;
- String base = System.getProperty("java.io.tmpdir");
- try {
- // Test to make sure that the tempfile was saved in the correct
- // location and with the correct prefix/suffix.
- f1 = File.createTempFile("harmony-test-FileTest_tempFile2_tf", null, null);
- File dir = new File(base);
- f2 = File.createTempFile("harmony-test-FileTest_tempFile2_tf", ".tmp", dir);
- File currentFile;
- String fileLocation;
- String fileName;
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileLocation = addTrailingSlash(currentFile.getParent());
- base = addTrailingSlash(base);
- assertEquals(
- "File not created in the default temporary-file location.",
- base, fileLocation);
- fileName = currentFile.getName();
- assertTrue("File created with incorrect suffix.", fileName
- .endsWith(".tmp"));
- assertTrue("File created with incorrect prefix.", fileName
- .startsWith("harmony-test-FileTest_tempFile2_tf"));
- currentFile.delete();
- }
-
- // Test for creating a tempfile in a directory that does not exist.
- int dirNumber = 1;
- boolean dirExists = true;
- // Set dir to a non-existent directory inside the temporary
- // directory
- dir = new File(base, String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making it
- // a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- try {
- // Try to create a file in a directory that does not exist
- File f3 = File.createTempFile("harmony-test-FileTest_tempFile2_tf", null, dir);
- f3.delete();
- fail("IOException not thrown");
- } catch (IOException e) {
- // Expected
- }
- dir.delete();
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f4 = File.createTempFile("ab", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- File f4 = File.createTempFile("a", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- File f4 = File.createTempFile("", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- } finally {
- if (f1 != null) {
- f1.delete();
- }
- if (f2 != null) {
- f1.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#delete()
- */
- public void test_delete() throws IOException {
- File dir = new File(tempDirectory, platformId
- + "filechk");
- dir.mkdir();
- assertTrue("Directory does not exist", dir.exists());
- assertTrue("Directory is not directory", dir.isDirectory());
- File f = new File(dir, "filechk.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Error Creating File For Delete Test", f.exists());
- dir.delete();
- assertTrue("Directory Should Not Have Been Deleted.", dir.exists());
- f.delete();
- assertTrue("File Was Not Deleted", !f.exists());
- dir.delete();
- assertTrue("Directory Was Not Deleted", !dir.exists());
- }
-
- // GCH
- // TODO : This test passes on Windows but fails on Linux with a
- // java.lang.NoClassDefFoundError. Temporarily removing from the test
- // suite while I investigate the cause.
- // /**
- // * @tests java.io.File#deleteOnExit()
- // */
- // public void test_deleteOnExit() {
- // File f1 = new File(System.getProperty("java.io.tmpdir"), platformId
- // + "deleteOnExit.tst");
- // try {
- // FileOutputStream fos = new FileOutputStream(f1);
- // fos.close();
- // } catch (IOException e) {
- // fail("Unexpected IOException During Test : " + e.getMessage());
- // }
- // assertTrue("File Should Exist.", f1.exists());
- //
- // try {
- // Support_Exec.execJava(new String[] {
- // "tests.support.Support_DeleteOnExitTest", f1.getPath() },
- // null, true);
- // } catch (IOException e) {
- // fail("Unexpected IOException During Test + " + e.getMessage());
- // } catch (InterruptedException e) {
- // fail("Unexpected InterruptedException During Test: " + e);
- // }
- //
- // boolean gone = !f1.exists();
- // f1.delete();
- // assertTrue("File Should Already Be Deleted.", gone);
- // }
-
- /**
- * @tests java.io.File#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object() throws IOException {
- File f1 = new File("filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("xxxx");
-
- assertTrue("Equality test failed", f1.equals(f2));
- assertTrue("Files Should Not Return Equal.", !f1.equals(f3));
-
- f3 = new File("FiLeChK.tst");
- boolean onWindows = File.separatorChar == '\\';
- boolean onUnix = File.separatorChar == '/';
- if (onWindows) {
- assertTrue("Files Should Return Equal.", f1.equals(f3));
- } else if (onUnix) {
- assertTrue("Files Should NOT Return Equal.", !f1.equals(f3));
- }
-
- f1 = new File(tempDirectory, "casetest.tmp");
- f2 = new File(tempDirectory, "CaseTest.tmp");
- new FileOutputStream(f1).close(); // create the file
- if (f1.equals(f2)) {
- try {
- FileInputStream fis = new FileInputStream(f2);
- fis.close();
- } catch (IOException e) {
- fail("File system is case sensitive");
- }
- } else {
- boolean exception = false;
- try {
- FileInputStream fis = new FileInputStream(f2);
- fis.close();
- } catch (IOException e) {
- exception = true;
- }
- assertTrue("File system is case insensitive", exception);
- }
- f1.delete();
- }
-
- /**
- * @tests java.io.File#exists()
- */
- public void test_exists() throws IOException {
- File f = new File(tempDirectory, platformId
- + "exists.tst");
- assertTrue("Exists returned true for non-existent file", !f.exists());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Exists returned false file", f.exists());
- f.delete();
- }
-
- /**
- * @tests java.io.File#getAbsoluteFile()
- */
- public void test_getAbsoluteFile() {
- String base = addTrailingSlash(tempDirectory.getPath());
- File f = new File(base, "temp.tst");
- File f2 = f.getAbsoluteFile();
- assertEquals("Test 1: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + "Temp" + File.separator + File.separator + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 2: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + File.separator + ".." + File.separator + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 3: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f.delete();
- f2.delete();
- }
-
- /**
- * @tests java.io.File#getAbsolutePath()
- */
- public void test_getAbsolutePath() {
- String base = addTrailingSlash(tempDirectory.getPath());
- File f = new File(base, "temp.tst");
- assertEquals("Test 1: Incorrect Path Returned.",
- base + "temp.tst", f.getAbsolutePath());
-
- f = new File(base + "Temp" + File.separator + File.separator + File.separator + "Testing" + File.separator
- + "temp.tst");
- assertEquals("Test 2: Incorrect Path Returned.",
- base + "Temp" + File.separator + "Testing" + File.separator + "temp.tst",
- f.getAbsolutePath());
-
- f = new File(base + "a" + File.separator + File.separator + ".." + File.separator + "temp.tst");
- assertEquals("Test 3: Incorrect Path Returned.",
- base + "a" + File.separator + ".." + File.separator + "temp.tst",
- f.getAbsolutePath());
- f.delete();
- }
-
- /**
- * @tests java.io.File#getCanonicalFile()
- */
- public void test_getCanonicalFile() throws IOException {
- String base = addTrailingSlash(tempDirectory.getPath());
- File f = new File(base, "temp.tst");
- File f2 = f.getCanonicalFile();
- assertEquals("Test 1: Incorrect File Returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + File.separator + File.separator + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 2: Incorrect File Returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + File.separator + File.separator + ".." + File.separator + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 3: Incorrect File Returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
-
- // Test for when long directory/file names in Windows
- boolean onWindows = File.separatorChar == '\\';
- if (onWindows) {
- File testdir = new File(base, "long-" + platformId);
- testdir.mkdir();
- File dir = new File(testdir, "longdirectory" + platformId);
- try {
- dir.mkdir();
- f = new File(dir, "longfilename.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 4: Incorrect File Returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f2 = new File(testdir + File.separator + "longdi~1" + File.separator
- + "longfi~1.tst");
- File canonicalf2 = f2.getCanonicalFile();
- /*
- * If the "short file name" doesn't exist, then assume that the
- * 8.3 file name compatibility is disabled.
- */
- if (canonicalf2.exists()) {
- assertTrue("Test 5: Incorrect File Returned: "
- + canonicalf2, canonicalf2.compareTo(f
- .getCanonicalFile()) == 0);
- }
- } finally {
- f.delete();
- f2.delete();
- dir.delete();
- testdir.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#getCanonicalPath()
- */
- public void test_getCanonicalPath() throws IOException {
- // Should work for Unix/Windows.
- String dots = "..";
- String base = tempDirectory.getCanonicalPath();
- base = addTrailingSlash(base);
- File f = new File(base, "temp.tst");
- assertEquals("Test 1: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
- f = new File(base + "Temp" + File.separator + dots + File.separator + "temp.tst");
- assertEquals("Test 2: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
-
- // Finding a non-existent directory for tests 3 and 4
- // This is necessary because getCanonicalPath is case sensitive and
- // could cause a failure in the test if the directory exists but with
- // different case letters (e.g "Temp" and "temp")
- int dirNumber = 1;
- boolean dirExists = true;
- File dir1 = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir1.exists()) {
- dirNumber++;
- dir1 = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- f = new File(base + dirNumber + File.separator + dots + File.separator + dirNumber
- + File.separator + "temp.tst");
- assertEquals("Test 3: Incorrect Path Returned.", base + dirNumber
- + File.separator + "temp.tst", f.getCanonicalPath());
- f = new File(base + dirNumber + File.separator + "Temp" + File.separator + dots + File.separator
- + "Test" + File.separator + "temp.tst");
- assertEquals("Test 4: Incorrect Path Returned.", base + dirNumber
- + File.separator + "Test" + File.separator + "temp.tst", f.getCanonicalPath());
-
- f = new File(base + "1234.567");
- assertEquals("Test 5: Incorrect Path Returned.", base + "1234.567", f
- .getCanonicalPath());
-
- // Test for long file names on Windows
- boolean onWindows = (File.separatorChar == '\\');
- if (onWindows) {
- File testdir = new File(base, "long-" + platformId);
- testdir.mkdir();
- File f1 = new File(testdir, "longfilename" + platformId + ".tst");
- FileOutputStream fos = new FileOutputStream(f1);
- File f2 = null, f3 = null, dir2 = null;
- try {
- fos.close();
- String dirName1 = f1.getCanonicalPath();
- File f4 = new File(testdir, "longfi~1.tst");
- /*
- * If the "short file name" doesn't exist, then assume that the
- * 8.3 file name compatibility is disabled.
- */
- if (f4.exists()) {
- String dirName2 = f4.getCanonicalPath();
- assertEquals("Test 6: Incorrect Path Returned.", dirName1,
- dirName2);
- dir2 = new File(testdir, "longdirectory" + platformId);
- if (!dir2.exists()) {
- assertTrue("Could not create dir: " + dir2, dir2
- .mkdir());
- }
- f2 = new File(testdir.getPath() + File.separator + "longdirectory"
- + platformId + File.separator + "Test" + File.separator + dots
- + File.separator + "longfilename.tst");
- FileOutputStream fos2 = new FileOutputStream(f2);
- fos2.close();
- dirName1 = f2.getCanonicalPath();
- f3 = new File(testdir.getPath() + File.separator + "longdi~1"
- + File.separator + "Test" + File.separator + dots + File.separator
- + "longfi~1.tst");
- dirName2 = f3.getCanonicalPath();
- assertEquals("Test 7: Incorrect Path Returned.", dirName1,
- dirName2);
- }
- } finally {
- f1.delete();
- if (f2 != null) {
- f2.delete();
- }
- if (dir2 != null) {
- dir2.delete();
- }
- testdir.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#getName()
- */
- public void test_getName() {
- File f = new File("name.tst");
- assertEquals("Test 1: Returned incorrect name", "name.tst", f.getName());
-
- f = new File("");
- assertEquals("Test 2: Returned incorrect name", "", f.getName());
-
- f.delete();
- }
-
- /**
- * @tests java.io.File#getParent()
- */
- public void test_getParent() {
- File f = new File("p.tst");
- assertNull("Incorrect path returned", f.getParent());
- f = new File(System.getProperty("user.home"), "p.tst");
- assertEquals("Incorrect path returned",
- System.getProperty("user.home"), f.getParent());
- f.delete();
-
- File f1 = new File("/directory");
- assertEquals("Wrong parent test 1", File.separator, f1.getParent());
- f1 = new File("/directory/file");
- assertEquals("Wrong parent test 2",
- File.separator + "directory", f1.getParent());
- f1 = new File("directory/file");
- assertEquals("Wrong parent test 3", "directory", f1.getParent());
- f1 = new File("/");
- assertNull("Wrong parent test 4", f1.getParent());
- f1 = new File("directory");
- assertNull("Wrong parent test 5", f1.getParent());
-
- if (File.separatorChar == '\\' && new File("d:/").isAbsolute()) {
- f1 = new File("d:/directory");
- assertEquals("Wrong parent test 1a", "d:" + File.separator, f1.getParent());
- f1 = new File("d:/directory/file");
- assertEquals("Wrong parent test 2a",
- "d:" + File.separator + "directory", f1.getParent());
- f1 = new File("d:directory/file");
- assertEquals("Wrong parent test 3a", "d:directory", f1.getParent());
- f1 = new File("d:/");
- assertNull("Wrong parent test 4a", f1.getParent());
- f1 = new File("d:directory");
- assertEquals("Wrong parent test 5a", "d:", f1.getParent());
- }
- }
-
- /**
- * @tests java.io.File#getParentFile()
- */
- public void test_getParentFile() {
- File f = new File("tempfile.tst");
- assertNull("Incorrect path returned", f.getParentFile());
- f = new File(tempDirectory, "tempfile1.tmp");
- File f2 = new File(tempDirectory, "tempfile2.tmp");
- File f3 = new File(tempDirectory, "/a/tempfile.tmp");
- assertEquals("Incorrect File Returned", 0, f.getParentFile().compareTo(
- f2.getParentFile()));
- assertTrue("Incorrect File Returned", f.getParentFile().compareTo(
- f3.getParentFile()) != 0);
- f.delete();
- f2.delete();
- f3.delete();
- }
-
- /**
- * @tests java.io.File#getPath()
- */
- public void test_getPath() {
- String base = System.getProperty("user.home");
- String fname;
- File f1;
- if (!base.regionMatches((base.length() - 1), File.separator, 0, 1)) {
- base += File.separator;
- }
- fname = base + "filechk.tst";
- f1 = new File(base, "filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("c:");
- File f4 = new File(base + "a" + File.separator + File.separator + ".." + File.separator
- + "filechk.tst");
- assertEquals("getPath returned incorrect path(f1)",
- fname, f1.getPath());
- assertEquals("getPath returned incorrect path(f2)",
- "filechk.tst", f2.getPath());
- assertEquals("getPath returned incorrect path(f3)","c:", f3.getPath());
- assertEquals("getPath returned incorrect path(f4)",
- base + "a" + File.separator + ".." + File.separator + "filechk.tst",
- f4.getPath());
- f1.delete();
- f2.delete();
- f3.delete();
- f4.delete();
-
- // Regression for HARMONY-444
- File file;
- String separator = File.separator;
-
- file = new File((File) null, "x/y/z");
- assertEquals("x" + separator + "y" + separator + "z", file.getPath());
-
- file = new File((String) null, "x/y/z");
- assertEquals("x" + separator + "y" + separator + "z", file.getPath());
-
- // Regression for HARMONY-829
- String f1ParentName = "01";
- f1 = new File(f1ParentName, "");
- assertEquals(f1ParentName, f1.getPath());
-
- String f2ParentName = "0";
- f2 = new File(f2ParentName, "");
-
- assertEquals(-1, f2.compareTo(f1));
- assertEquals(1, f1.compareTo(f2));
-
- File parent = tempDirectory;
- f3 = new File(parent, "");
-
- assertEquals(parent.getPath(), f3.getPath());
-
- // Regression for HARMONY-3869
- File file1 = new File("", "");
- assertEquals(File.separator, file1.getPath());
-
- File file2 = new File(new File(""), "");
- assertEquals(File.separator, file2.getPath());
- }
-
- /**
- * @tests java.io.File#hashCode()
- */
- public void test_hashCode() {
- // Regression for HARMONY-53
- String mixedFname = "SoMe FiLeNaMe";
- File mfile = new File(mixedFname);
- File lfile = new File(mixedFname.toLowerCase());
-
- if (mfile.equals(lfile)) {
- assertTrue("Assert 0: wrong hashcode", mfile.hashCode() == lfile
- .hashCode());
- } else {
- assertFalse("Assert 1: wrong hashcode", mfile.hashCode() == lfile
- .hashCode());
- }
- }
-
- /**
- * @tests java.io.File#isAbsolute()
- */
- public void test_isAbsolute() {
- if (File.separatorChar == '\\') {
- File f = new File("c:\\test");
- File f1 = new File("\\test");
- // One or the other should be absolute on Windows or CE
- assertTrue("Absolute returned false", (f.isAbsolute() && !f1
- .isAbsolute())
- || (!f.isAbsolute() && f1.isAbsolute()));
-
- assertTrue(new File("C:/").isAbsolute());
- assertTrue(new File("f:/").isAbsolute());
- assertTrue(new File("f:\\").isAbsolute());
- assertFalse(new File("f:").isAbsolute());
- assertFalse(new File("K:").isAbsolute());
- assertTrue(new File("\\\\").isAbsolute());
- assertTrue(new File("\\\\\\").isAbsolute());
- assertTrue(new File("\\\\hello").isAbsolute());
- assertFalse(new File("\\").isAbsolute());
- assertFalse(new File("/").isAbsolute());
- } else {
- File f = new File("/test");
- File f1 = new File("\\test");
- assertTrue("Absolute returned false", f.isAbsolute());
- assertFalse("Absolute returned true", f1.isAbsolute());
- assertTrue(new File("//test").isAbsolute());
- assertFalse(new File("test").isAbsolute());
- assertFalse(new File("c:/").isAbsolute());
- assertFalse(new File("c:\\").isAbsolute());
- assertFalse(new File("c:").isAbsolute());
- assertFalse(new File("\\").isAbsolute());
- assertFalse(new File("\\\\").isAbsolute());
- }
- assertTrue("Non-Absolute returned true", !new File("../test")
- .isAbsolute());
- }
-
- /**
- * @tests java.io.File#isDirectory()
- */
- public void test_isDirectory() {
- String base = addTrailingSlash(tempDirectory.getPath());
- File f = new File(base);
- assertTrue("Test 1: Directory Returned False", f.isDirectory());
- f = new File(base + "zxzxzxz" + platformId);
- assertTrue("Test 2: (Not Created) Directory Returned True.", !f
- .isDirectory());
- f.mkdir();
- try {
- assertTrue("Test 3: Directory Returned False.", f.isDirectory());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#isFile()
- */
- public void test_isFile() throws IOException {
- String base = tempDirectory.getPath();
- File f = new File(base);
- assertFalse("Directory Returned True As Being A File.", f.isFile());
-
- base = addTrailingSlash(base);
- f = new File(base, platformId + "amiafile");
- assertTrue("Non-existent File Returned True", !f.isFile());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("File returned false", f.isFile());
- f.delete();
- }
-
- /**
- * @tests java.io.File#isHidden()
- */
- public void test_isHidden() throws IOException, InterruptedException {
- boolean onUnix = File.separatorChar == '/';
- File f = File.createTempFile("harmony-test-FileTest_isHidden_", ".tmp");
- // On Unix hidden files are marked with a "." at the beginning
- // of the file name.
- if (onUnix) {
- File f2 = new File(".test.tst" + platformId);
- FileOutputStream fos2 = new FileOutputStream(f2);
- fos2.close();
- assertTrue("File returned hidden on Unix", !f.isHidden());
- assertTrue("File returned visible on Unix", f2.isHidden());
- assertTrue("File did not delete.", f2.delete());
- } else {
- // For windows, the file is being set hidden by the attrib
- // command.
- Runtime r = Runtime.getRuntime();
- assertTrue("File returned hidden", !f.isHidden());
- Process p = r.exec("attrib +h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned visible", f.isHidden());
- p = r.exec("attrib -h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned hidden", !f.isHidden());
- }
- f.delete();
- }
-
- /**
- * @tests java.io.File#lastModified()
- */
- public void test_lastModified() throws IOException {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "lModTest.tst");
- f.delete();
- long lastModifiedTime = f.lastModified();
- assertEquals("LastModified Time Should Have Returned 0.", 0,
- lastModifiedTime);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f.setLastModified(315550800000L);
- lastModifiedTime = f.lastModified();
- assertEquals("LastModified Time Incorrect",
- 315550800000L, lastModifiedTime);
- f.delete();
-
- // Regression for HARMONY-2146
- f = new File("/../");
- assertTrue(f.lastModified() > 0);
- }
-
- /**
- * @tests java.io.File#length()
- */
- public void test_length() throws IOException {
- File f = new File(tempDirectory, platformId
- + "input.tst");
- assertEquals("File Length Should Have Returned 0.", 0, f.length());
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- assertEquals("Incorrect file length returned",
- fileString.length(), f.length());
- f.delete();
-
- // regression test for HARMONY-1497
- f = File.createTempFile("test", "tmp");
- f.deleteOnExit();
- RandomAccessFile raf = new RandomAccessFile(f, "rwd");
- raf.write(0x41);
- assertEquals(1, f.length());
- }
-
- /**
- * @tests java.io.File#list()
- */
- public void test_list() throws IOException {
- String base = tempDirectory.getPath();
- // Old test left behind "garbage files" so this time it creates a
- // directory that is guaranteed not to already exist (and deletes it
- // afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = null;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- String[] flist = dir.list();
-
- assertNull("Method list() Should Have Returned null.", flist);
-
- assertTrue("Could not create parent directory for list test", dir
- .mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- assertEquals(
- "Method list() Should Have Returned An Array Of Length 0.",
- 0, dir.list().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.list());
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- flist = dir.list();
- if (flist.length != files.length) {
- fail("Incorrect list returned");
- }
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++) {
- check[i] = false;
- }
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false) {
- checkCount++;
- }
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
-
- assertTrue("Could not delete parent directory for list test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listFiles()
- */
- public void test_listFiles() throws IOException, InterruptedException {
- String base = tempDirectory.getPath();
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- // Test for attempting to call listFiles on a non-existent directory.
- assertNull("listFiles Should Return Null.", dir.listFiles());
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tst", "" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0,
- dir.listFiles().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles());
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < (files.length - 1); i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- new File(dir, "doesNotExist.tst");
- File[] flist = dir.listFiles();
-
- // Test to make sure that only the 3 files that were created are
- // listed.
- assertEquals("Incorrect Number Of Files Returned.", 3, flist.length);
-
- // Test to make sure that listFiles can read hidden files.
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onWindows) {
- files[3] = "4.tst";
- File f = new File(dir, "4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib +h \"" + f.getPath() + "\"");
- p.waitFor();
- }
- if (onUnix) {
- files[3] = ".4.tst";
- File f = new File(dir, ".4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- flist = dir.listFiles();
- assertEquals("Incorrect Number Of Files Returned.", 4, flist.length);
-
- // Checking to make sure the correct files were are listed in
- // the array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++) {
- check[i] = false;
- }
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false) {
- checkCount++;
- }
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- if (onWindows) {
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib -h \""
- + new File(dir, files[3]).getPath() + "\"");
- p.waitFor();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FileFilter)
- */
- public void test_listFilesLjava_io_FileFilter() throws IOException {
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File baseDir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (baseDir.exists()) {
- dirNumber++;
- baseDir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches directories.
- FileFilter dirFilter = new FileFilter() {
- public boolean accept(File f) {
- return f.isDirectory();
- }
- };
-
- assertNull("listFiles Should Return Null.", baseDir
- .listFiles(dirFilter));
-
- assertTrue("Failed To Create Parent Directory.", baseDir.mkdir());
-
- File dir1 = null;
- String[] files = { "1.tst", "2.tst", "3.tst" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0,
- baseDir.listFiles(dirFilter).length);
-
- File file = new File(baseDir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(dirFilter));
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- dir1 = new File(baseDir, "Temp1");
- dir1.mkdir();
-
- // Creating a filter that catches files.
- FileFilter fileFilter = new FileFilter() {
- public boolean accept(File f) {
- return f.isFile();
- }
- };
-
- // Test to see if the correct number of directories are returned.
- File[] directories = baseDir.listFiles(dirFilter);
- assertEquals("Incorrect Number Of Directories Returned.", 1,
- directories.length);
-
- // Test to see if the directory was saved with the correct name.
- assertEquals("Incorrect Directory Returned.", 0, directories[0]
- .compareTo(dir1));
-
- // Test to see if the correct number of files are returned.
- File[] flist = baseDir.listFiles(fileFilter);
- assertEquals("Incorrect Number Of Files Returned.",
- files.length, flist.length);
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++) {
- check[i] = false;
- }
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false) {
- checkCount++;
- }
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- dir1.delete();
- assertTrue("Parent Directory Not Deleted.", baseDir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- if (dir1 != null) {
- dir1.delete();
- }
- baseDir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FilenameFilter)
- */
- public void test_listFilesLjava_io_FilenameFilter() throws IOException {
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches "*.tst" files.
- FilenameFilter tstFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- return fileName.endsWith(".tst");
- }
- };
-
- assertNull("listFiles Should Return Null.", dir.listFiles(tstFilter));
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tmp" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0,
- dir.listFiles(tstFilter).length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(tstFilter));
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- // Creating a filter that catches "*.tmp" files.
- FilenameFilter tmpFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- // If the suffix is ".tmp" then send it to the array
- if (fileName.endsWith(".tmp")) {
- return true;
- } else {
- return false;
- }
- }
- };
-
- // Tests to see if the correct number of files were returned.
- File[] flist = dir.listFiles(tstFilter);
- assertEquals("Incorrect Number Of Files Passed Through tstFilter.",
- 2, flist.length);
- for (int i = 0; i < flist.length; i++) {
- assertTrue("File Should Not Have Passed The tstFilter.",
- flist[i].getPath().endsWith(".tst"));
- }
-
- flist = dir.listFiles(tmpFilter);
- assertEquals("Incorrect Number Of Files Passed Through tmpFilter.",
- 1, flist.length);
- assertTrue("File Should Not Have Passed The tmpFilter.", flist[0]
- .getPath().endsWith(".tmp"));
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#list(java.io.FilenameFilter)
- */
- public void test_listLjava_io_FilenameFilter() throws IOException {
- String base = tempDirectory.getPath();
- // Old test left behind "garbage files" so this time it creates a
- // directory that is guaranteed not to already exist (and deletes it
- // afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !name.equals("mtzz1.xx");
- }
- };
-
- String[] flist = dir.list(filter);
- assertNull("Method list(FilenameFilter) Should Have Returned Null.",
- flist);
-
- assertTrue("Could not create parent directory for test", dir.mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- /*
- * Do not return null when trying to use list(Filename Filter) on a
- * file rather than a directory. All other "list" methods return
- * null for this test case.
- */
- /*
- * File file = new File(dir, "notADir.tst"); try { FileOutputStream
- * fos = new FileOutputStream(file); fos.close(); } catch
- * (IOException e) { fail("Unexpected IOException During Test."); }
- * flist = dir.list(filter); assertNull("listFiles Should Have
- * Returned Null When Used On A File Instead Of A Directory.",
- * flist); file.delete();
- */
-
- flist = dir.list(filter);
- assertEquals("Array Of Length 0 Should Have Returned.", 0,
- flist.length);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- flist = dir.list(filter);
-
- assertEquals("Incorrect list returned", flist.length,
- files.length - 1);
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++) {
- check[i] = false;
- }
- String[] wantedFiles = { "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- for (int i = 0; i < wantedFiles.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(wantedFiles[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false) {
- checkCount++;
- }
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Could not delete parent directory for test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listRoots()
- */
- public void test_listRoots() {
- File[] roots = File.listRoots();
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onUnix) {
- assertEquals("Incorrect Number Of Root Directories.", 1,
- roots.length);
- String fileLoc = roots[0].getPath();
- assertTrue("Incorrect Root Directory Returned.", fileLoc
- .startsWith(File.separator));
- } else if (onWindows) {
- // Need better test for Windows
- assertTrue("Incorrect Number Of Root Directories.",
- roots.length > 0);
- }
- }
-
- /**
- * @tests java.io.File#mkdir()
- */
- public void test_mkdir() throws IOException {
- String base = tempDirectory.getPath();
- // Old test left behind "garbage files" so this time it creates a
- // directory that is guaranteed not to already exist (and deletes it
- // afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- assertTrue("mkdir failed", dir.mkdir());
- assertTrue("mkdir worked but exists check failed", dir.exists());
- dir.deleteOnExit();
-
- String longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars
- String newbase = new String(dir + File.separator);
- StringBuilder sb = new StringBuilder(dir + File.separator);
- StringBuilder sb2 = new StringBuilder(dir + File.separator);
-
- // Test make a long path
- while (dir.getCanonicalPath().length() < 256 - longDirName.length()) {
- sb.append(longDirName + File.separator);
- dir = new File(sb.toString());
- assertTrue("mkdir failed", dir.mkdir());
- assertTrue("mkdir worked but exists check failed", dir.exists());
- dir.deleteOnExit();
- }
-
- while (dir.getCanonicalPath().length() < 256) {
- sb.append(0);
- dir = new File(sb.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir());
- assertTrue("mkdir " + dir.getCanonicalPath().length()
- + " worked but exists check failed", dir.exists());
- dir.deleteOnExit();
- }
- dir = new File(sb2.toString());
- // Test make many paths
- while (dir.getCanonicalPath().length() < 256) {
- sb2.append(0);
- dir = new File(sb2.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir());
- assertTrue("mkdir " + dir.getCanonicalPath().length()
- + " worked but exists check failed", dir.exists());
- dir.deleteOnExit();
- }
-
- // Regression test for HARMONY-3656
- String[] ss = { "dir\u3400", "abc", "abc@123", "!@#$%^&",
- "~\u4E00!\u4E8C@\u4E09$", "\u56DB\u4E94\u516D",
- "\u4E03\u516B\u4E5D" };
- for (int i = 0; i < ss.length; i++) {
- dir = new File(newbase, ss[i]);
- assertTrue("mkdir " + dir.getCanonicalPath() + " failed",
- dir.mkdir());
- assertTrue("mkdir " + dir.getCanonicalPath()
- + " worked but exists check failed",
- dir.exists());
- dir.deleteOnExit();
- }
- }
-
- /**
- * @tests java.io.File#mkdir()
- *
- * HARMONY-6041
- */
- public void test_mkdir_special_unicode() throws IOException {
- File specialDir = new File(this.tempDirectory,"\u5C73");
- int i = 0;
- while (specialDir.exists()) {
- specialDir = new File("\u5C73" + i);
- ++i;
- }
- assertFalse(specialDir.exists());
- assertTrue(specialDir.mkdir());
- assertTrue(specialDir.exists());
- }
-
- /**
- * @tests java.io.File#mkdirs()
- */
- public void test_mkdirs() {
- String userHome = addTrailingSlash(tempDirectory.getPath());
- File f = new File(userHome + "mdtest" + platformId + File.separator + "mdtest2",
- "p.tst");
- File g = new File(userHome + "mdtest" + platformId + File.separator + "mdtest2");
- File h = new File(userHome + "mdtest" + platformId);
- f.mkdirs();
- try {
- assertTrue("Base Directory not created", h.exists());
- assertTrue("Directories not created", g.exists());
- assertTrue("File not created", f.exists());
- } finally {
- f.delete();
- g.delete();
- h.delete();
- }
- }
-
- /**
- * @tests java.io.File#renameTo(java.io.File)
- */
- public void test_renameToLjava_io_File() throws IOException {
- String base = tempDirectory.getPath();
- File dir = new File(base, platformId);
- dir.mkdir();
- File f = new File(dir, "xxx.xxx");
- File rfile = new File(dir, "yyy.yyy");
- File f2 = new File(dir, "zzz.zzz");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- long lengthOfFile = f.length();
-
- rfile.delete(); // in case it already exists
-
- assertTrue("Test 1: File Rename Failed", f.renameTo(rfile));
- assertTrue("Test 2: File Rename Failed.", rfile.exists());
- assertEquals("Test 3: Size Of File Changed.",
- lengthOfFile, rfile.length());
-
- fos = new FileOutputStream(rfile);
- fos.close();
-
- f2.delete(); // in case it already exists
- assertTrue("Test 4: File Rename Failed", rfile.renameTo(f2));
- assertTrue("Test 5: File Rename Failed.", f2.exists());
- } finally {
- f.delete();
- rfile.delete();
- f2.delete();
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#setLastModified(long)
- */
- public void test_setLastModifiedJ() throws IOException {
- File f1 = null;
- try {
- f1 = new File(Support_PlatformFile.getNewPlatformFile(
- "harmony-test-FileTest_setLastModified", ".tmp"));
- f1.createNewFile();
- long orgTime = f1.lastModified();
- // Subtracting 100 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime - 100000);
- long lastModified = f1.lastModified();
- assertEquals("Test 1: LastModifed time incorrect",
- orgTime - 100000, lastModified);
- // Subtracting 10 000 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime - 10000000);
- lastModified = f1.lastModified();
- assertEquals("Test 2: LastModifed time incorrect",
- orgTime - 10000000, lastModified);
- // Adding 100 000 milliseconds to the orgTime of File f1
- f1.setLastModified(orgTime + 100000);
- lastModified = f1.lastModified();
- assertEquals("Test 3: LastModifed time incorrect",
- orgTime + 100000, lastModified);
- // Adding 10 000 000 milliseconds from the orgTime of File f1
- f1.setLastModified(orgTime + 10000000);
- lastModified = f1.lastModified();
- assertEquals("Test 4: LastModifed time incorrect",
- orgTime + 10000000, lastModified);
- // Trying to set time to an exact number
- f1.setLastModified(315550800000L);
- lastModified = f1.lastModified();
- assertEquals("Test 5: LastModified time incorrect",
- 315550800000L, lastModified);
- String osName = System.getProperty("os.name", "unknown");
- if (osName.equals("Windows 2000") || osName.equals("Windows NT")) {
- // Trying to set time to a large exact number
- boolean result = f1.setLastModified(4354837199000L);
- long next = f1.lastModified();
- // Dec 31 23:59:59 EST 2107 is overflow on FAT file systems, and
- // the call fails
- if (result) {
- assertEquals("Test 6: LastModified time incorrect",
- 4354837199000L, next);
- }
- }
- // Trying to set time to a negative number
- try {
- f1.setLastModified(-25);
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- } finally {
- if (f1 != null) {
- f1.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#setReadOnly()
- */
- public void test_setReadOnly() throws IOException, InterruptedException {
- File f1 = null;
- File f2 = null;
- try {
- f1 = File.createTempFile("harmony-test-FileTest_setReadOnly", ".tmp");
- f2 = File.createTempFile("harmony-test-FileTest_setReadOnly", ".tmp");
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f1 Is Set To ReadOnly." , f1.canWrite());
- f1.setReadOnly();
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f1 Is Not Set To ReadOnly." , !f1.canWrite());
- try {
- // Attempt to write to a file that is setReadOnly.
- new FileOutputStream(f1);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // Expected
- }
- Runtime r = Runtime.getRuntime();
- Process p;
- boolean onUnix = File.separatorChar == '/';
- if (onUnix) {
- p = r.exec("chmod +w " + f1.getAbsolutePath());
- } else {
- p = r.exec("attrib -r \"" + f1.getAbsolutePath() + "\"");
- }
- p.waitFor();
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f1 Is Set To ReadOnly." , f1.canWrite());
- FileOutputStream fos = new FileOutputStream(f1);
- fos.write(fileString.getBytes());
- fos.close();
- assertTrue("File Was Not Able To Be Written To.",
- f1.length() == fileString.length());
- assertTrue("File f1 Did Not Delete", f1.delete());
-
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Set To ReadOnly." , f2.canWrite());
- fos = new FileOutputStream(f2);
- // Write to a file.
- fos.write(fileString.getBytes());
- fos.close();
- f2.setReadOnly();
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Not Set To ReadOnly." , !f2.canWrite());
- try {
- // Attempt to write to a file that has previously been written
- // to.
- // and is now set to read only.
- fos = new FileOutputStream(f2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // Expected
- }
- r = Runtime.getRuntime();
- if (onUnix) {
- p = r.exec("chmod +w " + f2.getAbsolutePath());
- } else {
- p = r.exec("attrib -r \"" + f2.getAbsolutePath() + "\"");
- }
- p.waitFor();
- assertTrue("File f2 Is Set To ReadOnly.", f2.canWrite());
- fos = new FileOutputStream(f2);
- fos.write(fileString.getBytes());
- fos.close();
- f2.setReadOnly();
- assertTrue("File f2 Did Not Delete", f2.delete());
- // Similarly, trying to delete a read-only directory should succeed
- f2 = new File(tempDirectory, "deltestdir");
- f2.mkdir();
- f2.setReadOnly();
- assertTrue("Directory f2 Did Not Delete", f2.delete());
- assertTrue("Directory f2 Did Not Delete", !f2.exists());
- } finally {
- if (f1 != null) {
- f1.delete();
- }
- if (f2 != null) {
- f2.delete();
- }
- }
- }
-
- /**
- * @tests java.io.File#toString()
- */
- public void test_toString() {
- String fileName = System.getProperty("user.home") + File.separator + "input.tst";
- File f = new File(fileName);
- assertEquals("Incorrect string returned", fileName, f.toString());
-
- if (File.separatorChar == '\\') {
- String result = new File("c:\\").toString();
- assertEquals("Removed backslash", "c:\\", result);
- }
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- public void test_toURI() throws URISyntaxException {
- // Need a directory that exists
- File dir = tempDirectory;
-
- // Test for toURI when the file is a directory.
- String newURIPath = dir.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/")) {
- newURIPath = "/" + newURIPath;
- }
- if (!newURIPath.endsWith("/")) {
- newURIPath += '/';
- }
-
- URI uri = dir.toURI();
- assertEquals("Test 1A: Incorrect URI Returned.", dir.getAbsoluteFile(), new File(uri));
- assertEquals("Test 1B: Incorrect URI Returned.",
- new URI("file", null, newURIPath, null, null), uri);
-
- // Test for toURI with a file name with illegal chars.
- File f = new File(dir, "te% \u20ac st.tst");
- newURIPath = f.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/")) {
- newURIPath = "/" + newURIPath;
- }
-
- uri = f.toURI();
- assertEquals("Test 2A: Incorrect URI Returned.",
- f.getAbsoluteFile(), new File(uri));
- assertEquals("Test 2B: Incorrect URI Returned.",
- new URI("file", null, newURIPath, null, null), uri);
-
- // Regression test for HARMONY-3207
- dir = new File(""); // current directory
- uri = dir.toURI();
- assertTrue("Test current dir: URI does not end with slash.", uri
- .toString().endsWith("/"));
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- public void test_toURL() throws MalformedURLException {
- // Need a directory that exists
- File dir = tempDirectory;
-
- // Test for toURL when the file is a directory.
- String newDirURL = dir.getAbsolutePath();
- newDirURL = newDirURL.replace(File.separatorChar, '/');
- if (newDirURL.startsWith("/")) {
- newDirURL = "file:" + newDirURL;
- } else {
- newDirURL = "file:/" + newDirURL;
- }
- if (!newDirURL.endsWith("/")) {
- newDirURL += '/';
- }
- assertEquals("Test 1: Incorrect URL Returned.",
- dir.toURL().toString(), newDirURL);
-
- // Test for toURL with a file.
- File f = new File(dir, "test.tst");
- String newURL = f.getAbsolutePath();
- newURL = newURL.replace(File.separatorChar, '/');
- if (newURL.startsWith("/")) {
- newURL = "file:" + newURL;
- } else {
- newURL = "file:/" + newURL;
- }
- assertEquals("Test 2: Incorrect URL Returned.",
- f.toURL().toString(), newURL);
-
- // Regression test for HARMONY-3207
- dir = new File(""); // current directory
- newDirURL = dir.toURL().toString();
- assertTrue("Test current dir: URL does not end with slash.", newDirURL
- .endsWith("/"));
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- public void test_toURI2() throws URISyntaxException {
- File f = new File(tempDirectory, "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/")) {
- path = "/" + path;
- }
-
- URI uri1 = new URI("file", null, path, null);
- URI uri2 = f.toURI();
- assertEquals("uris not equal", uri1, uri2);
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- public void test_toURL2() throws MalformedURLException {
- File f = new File(tempDirectory, "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/")) {
- path = "/" + path;
- }
-
- URL url1 = new URL("file", "", path);
- URL url2 = f.toURL();
- assertEquals("urls not equal", url1, url2);
- }
-
- /**
- * @tests java.io.File#deleteOnExit()
- */
- /* BEGIN android-removed: we don't have Support_Exec.execJava.
- public void test_deleteOnExit() throws IOException, InterruptedException {
- File dir = new File("dir4filetest");
- dir.mkdir();
- assertTrue(dir.exists());
- File subDir = new File("dir4filetest/subdir");
- subDir.mkdir();
- assertTrue(subDir.exists());
-
- Support_Exec.execJava(new String[] {
- "tests.support.Support_DeleteOnExitTest",
- dir.getAbsolutePath(), subDir.getAbsolutePath() },
- new String[] {}, false);
- assertFalse(dir.exists());
- assertFalse(subDir.exists());
- }
- */
-
- /**
- * @tests serilization
- */
- public void test_objectStreamClass_getFields() throws Exception {
- // Regression for HARMONY-2674
- ObjectStreamClass objectStreamClass = ObjectStreamClass
- .lookup(File.class);
- ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
- assertEquals(1, objectStreamFields.length);
- ObjectStreamField objectStreamField = objectStreamFields[0];
- assertEquals("path", objectStreamField.getName());
- assertEquals(String.class, objectStreamField.getType());
- }
-
- // Regression test for HARMONY-4493
- public void test_list_withUnicodeFileName() throws Exception {
- File rootDir = new File("P");
- if (!rootDir.exists()) {
- rootDir.mkdir();
- rootDir.deleteOnExit();
- }
-
- String dirName = new String("src\u3400");
- File dir = new File(rootDir, dirName);
- if (!dir.exists()) {
- dir.mkdir();
- dir.deleteOnExit();
- }
- boolean exist = false;
- String[] fileNames = rootDir.list();
- for (String fileName : fileNames) {
- if (dirName.equals(fileName)) {
- exist = true;
- break;
- }
- }
- assertTrue(exist);
- }
-
- /**
- * @tests serialization/deserialization.
- */
- public void test_serialization_self() throws Exception {
- File testFile = new File("test.ser");
- SerializationTest.verifySelf(testFile);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void test_serialization_compatibility() throws Exception {
- File file = new File("FileTest.golden.ser");
- SerializationTest.verifyGolden(this, file);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
deleted file mode 100644
index e4e8046..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/InputStreamReaderTest.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-public class InputStreamReaderTest extends TestCase {
-
- static class LimitedByteArrayInputStream extends ByteArrayInputStream {
-
- // A ByteArrayInputStream that only returns a single byte per read
- byte[] bytes;
-
- int count;
-
- public LimitedByteArrayInputStream(int type) {
- super(new byte[0]);
- switch (type) {
- case 0:
- bytes = new byte[] { 0x61, 0x72 };
- break;
- case 1:
- bytes = new byte[] { (byte) 0xff, (byte) 0xfe, 0x61, 0x72 };
- break;
- case 2:
- bytes = new byte[] { '\u001b', '$', 'B', '6', 'e', 'B', 'h',
- '\u001b', '(', 'B' };
- break;
- }
- count = bytes.length;
- }
-
- @Override
- public int available() {
- return count;
- }
-
- @Override
- public int read() {
- if (count == 0) {
- return -1;
- }
- count--;
- return bytes[bytes.length - count];
- }
-
- @Override
- public int read(byte[] buffer, int offset, int length) {
- if (count == 0) {
- return -1;
- }
- if (length == 0) {
- return 0;
- }
- buffer[offset] = bytes[bytes.length - count];
- count--;
- return 1;
- }
- }
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- private InputStream fis;
-
- private InputStream in;
-
- private InputStreamReader is;
-
- private InputStreamReader reader;
-
- private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- in = new ByteArrayInputStream(source.getBytes("UTF-8"));
- reader = new InputStreamReader(in, "UTF-8");
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- OutputStreamWriter osw = new OutputStreamWriter(bos);
- char[] buf = new char[fileString.length()];
- fileString.getChars(0, fileString.length(), buf, 0);
- osw.write(buf);
- osw.close();
- fis = new ByteArrayInputStream(bos.toByteArray());
- is = new InputStreamReader(fis);
- }
-
- /*
- * @see TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- try {
- in.close();
- is.close();
- fis.close();
- } catch (IOException e) {
- // Ignored
- }
-
- super.tearDown();
- }
-
- /**
- * @tests java.io.InputStreamReader#close()
- */
- public void test_close() throws IOException {
- is.close();
- try {
- is.read();
- fail("Should throw IOException");
- } catch (IOException e) {
- // Expected
- }
-
- reader.close();
- try {
- reader.ready();
- fail("Should throw IOException");
- } catch (IOException e) {
- // Expected
- }
-
- // Should be a no-op
- reader.close();
-
- // Tests after reader closed
- in = new BufferedInputStream(
- this
- .getClass()
- .getClassLoader()
- .getResourceAsStream(
- "org/apache/harmony/luni/tests/java/io/testfile-utf8.txt"));
- reader = new InputStreamReader(in, "utf-8");
- in.close();
- try {
- int count = reader.read(new char[1]);
- fail("count:" + count);
- } catch (IOException e) {
- // Expected
- }
- try {
- reader.read();
- fail();
- } catch (IOException e) {
- // Expected
- }
-
- assertFalse(reader.ready());
- Charset cs = Charset.forName("utf-8");
- assertEquals(cs, Charset.forName(reader.getEncoding()));
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
- */
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- try {
- reader = new InputStreamReader(null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- InputStreamReader reader2 = new InputStreamReader(in);
- reader2.close();
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream,
- * java.lang.String)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_lang_String()
- throws IOException {
- is = new InputStreamReader(fis, "8859_1");
-
- try {
- is = new InputStreamReader(fis, "Bogus");
- fail("Failed to throw Unsupported Encoding exception");
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
-
- try {
- reader = new InputStreamReader(null, "utf-8");
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- reader = new InputStreamReader(in, (String) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- reader = new InputStreamReader(in, "");
- fail();
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
- try {
- reader = new InputStreamReader(in, "badname");
- fail();
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
- InputStreamReader reader2 = new InputStreamReader(in, "utf-8");
- assertEquals(Charset.forName(reader2.getEncoding()), Charset
- .forName("utf-8"));
- reader2.close();
- reader2 = new InputStreamReader(in, "utf8");
- assertEquals(Charset.forName(reader2.getEncoding()), Charset
- .forName("utf-8"));
- reader2.close();
- }
-
- /**
- * @tests java.io.InputStreamReader(java.io.InputStream,
- * java.nio.charset.Charset)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_Charset()
- throws IOException {
- Charset cs = Charset.forName("utf-8");
- try {
- reader = new InputStreamReader(null, cs);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- reader = new InputStreamReader(in, (Charset) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- InputStreamReader reader2 = new InputStreamReader(in, cs);
- assertEquals(Charset.forName(reader2.getEncoding()), cs);
- reader2.close();
- }
-
- /**
- * @tests java.io.InputStreamReader(java.io.InputStream,
- * java.nio.charset.CharsetDecoder)
- */
- public void test_ConstructorLjava_io_InputStreamLjava_nio_charset_CharsetDecoder()
- throws IOException {
- CharsetDecoder decoder = Charset.forName("utf-8").newDecoder();
- try {
- reader = new InputStreamReader(null, decoder);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- reader = new InputStreamReader(in, (CharsetDecoder) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- InputStreamReader reader2 = new InputStreamReader(in, decoder);
- assertEquals(Charset.forName(reader2.getEncoding()), decoder.charset());
- reader2.close();
- }
-
- /**
- * @tests java.io.InputStreamReader#getEncoding()
- */
- public void test_getEncoding() throws IOException {
- InputStreamReader isr = new InputStreamReader(fis, "8859_1");
- assertEquals("Returned incorrect encoding when setting 8859_1",
- "ISO8859_1", isr.getEncoding());
-
- isr = new InputStreamReader(fis, "ISO-8859-1");
- assertEquals("Returned incorrect encoding when setting ISO-8859-1",
- "ISO8859_1", isr.getEncoding());
-
- byte b[] = new byte[5];
- isr = new InputStreamReader(new ByteArrayInputStream(b), "UTF-16BE");
- isr.close();
- assertNull(isr.getEncoding());
-
- try {
- isr = new InputStreamReader(System.in, "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- // Ignored
- }
- assertEquals("UnicodeBigUnmarked", isr.getEncoding());
- }
-
- /**
- * @tests java.io.InputStreamReader#read()
- */
- public void test_read() throws IOException {
- assertEquals('T', (char) reader.read());
- assertEquals('h', (char) reader.read());
- assertEquals('i', (char) reader.read());
- assertEquals('s', (char) reader.read());
- assertEquals(' ', (char) reader.read());
- reader.read(new char[source.length() - 5], 0, source.length() - 5);
- assertEquals(-1, reader.read());
-
- int c = is.read();
- assertTrue("returned incorrect char", (char) c == fileString.charAt(0));
- InputStreamReader reader = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { (byte) 0xe8, (byte) 0x9d,
- (byte) 0xa5 }), "UTF8");
- assertTrue("wrong double byte char", reader.read() == '\u8765');
-
- // Regression for HARMONY-166
- InputStream in;
-
- in = new LimitedByteArrayInputStream(0);
- reader = new InputStreamReader(in, "UTF-16BE");
- assertEquals("Incorrect byte UTF-16BE", '\u6172', reader.read());
-
- in = new LimitedByteArrayInputStream(0);
- reader = new InputStreamReader(in, "UTF-16LE");
- assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
- in = new LimitedByteArrayInputStream(1);
- reader = new InputStreamReader(in, "UTF-16");
- assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
- /*
- * Temporarily commented out due to lack of ISO2022 support in ICU4J 3.8
- * in = new LimitedByteArrayInputStream(2); reader = new
- * InputStreamReader(in, "ISO2022JP"); assertEquals("Incorrect byte
- * ISO2022JP 1", '\u4e5d', reader.read()); assertEquals("Incorrect byte
- * ISO2022JP 2", '\u7b2c', reader.read());
- */
- }
-
- /*
- * Class under test for int read() Regression for Harmony-411
- */
- public void test_read_1() throws IOException {
- // if the decoder is constructed by InputStreamReader itself, the
- // decoder's default error action is REPLACE
- InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), "UTF-8");
- assertEquals("read() return incorrect value", 65533, isr.read());
-
- InputStreamReader isr2 = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { -32, -96 }), Charset
- .forName("UTF-8"));
- assertEquals("read() return incorrect value", 65533, isr2.read());
-
- // if the decoder is passed in, keep its status intact
- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- InputStreamReader isr3 = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { -32, -96 }), decoder);
- try {
- isr3.read();
- fail("Should throw MalformedInputException");
- } catch (MalformedInputException e) {
- // expected
- }
-
- CharsetDecoder decoder2 = Charset.forName("UTF-8").newDecoder();
- decoder2.onMalformedInput(CodingErrorAction.IGNORE);
- InputStreamReader isr4 = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { -32, -96 }), decoder2);
- assertEquals("read() return incorrect value", -1, isr4.read());
-
- CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
- decoder3.onMalformedInput(CodingErrorAction.REPLACE);
- InputStreamReader isr5 = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { -32, -96 }), decoder3);
- assertEquals("read() return incorrect value", 65533, isr5.read());
- }
-
- public void test_read_specialCharset() throws IOException {
- reader.close();
- in = this.getClass().getClassLoader().getResourceAsStream(
- "tests/api/java/io/testfile-utf8.txt");
- reader = new InputStreamReader(in, "utf-8");
- int c;
- StringBuffer sb = new StringBuffer();
- while ((c = reader.read()) != -1) {
- sb.append((char) c);
- }
- // delete BOM
- assertEquals(source, sb.deleteCharAt(0).toString());
-
- sb.setLength(0);
- reader.close();
- in = this.getClass().getClassLoader().getResourceAsStream(
- "tests/api/java/io/testfile.txt");
- try {
- reader = new InputStreamReader(in, "gb18030");
- } catch (UnsupportedEncodingException e) {
- System.out
- .println("GB18030 is not supported, abort test InputStreamReaderTest.testSpecialCharsetReading().");
- }
- while ((c = reader.read()) != -1) {
- sb.append((char) c);
- }
- assertEquals(source, sb.toString());
- }
-
- /**
- * @tests java.io.InputStreamReader#read(char[], int, int)
- */
- public void test_read$CII() throws IOException {
- char[] rbuf = new char[100];
- char[] sbuf = new char[100];
- fileString.getChars(0, 100, sbuf, 0);
- is.read(rbuf, 0, 100);
- for (int i = 0; i < rbuf.length; i++) {
- assertTrue("returned incorrect chars", rbuf[i] == sbuf[i]);
- }
-
- // Test successive reads
- byte[] data = new byte[8192 * 2];
- Arrays.fill(data, (byte) 116); // 116 = ISO-8859-1 value for 't'
- ByteArrayInputStream bis = new ByteArrayInputStream(data);
- InputStreamReader isr = new InputStreamReader(bis, "ISO-8859-1");
-
- // One less than the InputStreamReader.BUFFER_SIZE
- char[] buf = new char[8191];
- int bytesRead = isr.read(buf, 0, buf.length);
- assertFalse(-1 == bytesRead);
- bytesRead = isr.read(buf, 0, buf.length);
- assertFalse(-1 == bytesRead);
-
- bis = new ByteArrayInputStream(source.getBytes("UTF-8"));
- isr = new InputStreamReader(in, "UTF-8");
- char[] chars = new char[source.length()];
- assertEquals(source.length() - 3, isr.read(chars, 0, chars.length - 3));
- assertEquals(3, isr.read(chars, 0, 10));
- }
-
- /*
- * Class under test for int read(char[], int, int)
- */
- public void test_read$CII_1() throws IOException {
- try {
- // Throws IndexOutOfBoundsException before NullPointerException
- reader.read(null, -1, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- // Throws NullPointerException before IndexOutOfBoundsException
- reader.read(null, 0, -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- reader.read(null, 0, 1);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- reader.read(new char[3], -1, 1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- reader.read(new char[3], 0, -1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- reader.read(new char[3], 1, 3);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- assertEquals(0, reader.read(new char[3], 3, 0));
- char[] chars = new char[source.length()];
- assertEquals(0, reader.read(chars, 0, 0));
- assertEquals(0, chars[0]);
- assertEquals(3, reader.read(chars, 0, 3));
- assertEquals(5, reader.read(chars, 3, 5));
- assertEquals(source.length() - 8, reader.read(chars, 8,
- chars.length - 8));
- assertTrue(Arrays.equals(chars, source.toCharArray()));
- assertEquals(-1, reader.read(chars, 0, chars.length));
- assertTrue(Arrays.equals(chars, source.toCharArray()));
- }
-
- /**
- * @tests java.io.InputStreamReader#ready()
- */
- public void test_ready() throws IOException {
- assertTrue("Ready test failed", is.ready());
- is.read();
- assertTrue("More chars, but not ready", is.ready());
-
- assertTrue(reader.ready());
- reader.read(new char[source.length()]);
- assertFalse(reader.ready());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
deleted file mode 100644
index 467075f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ObjectStreamConstantsTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.ObjectStreamConstants;
-
-import junit.framework.TestCase;
-
-public class ObjectStreamConstantsTest extends TestCase {
-
- /**
- * @tests java.io.ObjectStreamConstants#TC_ENUM
- */
- public void test_TC_ENUM() {
- assertEquals(126, ObjectStreamConstants.TC_ENUM);
- }
-
- /**
- * @tests java.io.ObjectStreamConstants#SC_ENUM
- */
- public void test_SC_ENUM() {
- assertEquals(16, ObjectStreamConstants.SC_ENUM);
- }
-
- /**
- * @tests java.io.ObjectStreamConstants#TC_MAX
- */
- public void test_TC_MAX() {
- assertEquals(126, ObjectStreamConstants.TC_MAX);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
deleted file mode 100644
index 5283e46..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/OutputStreamWriterTest.java
+++ /dev/null
@@ -1,703 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-
-import junit.framework.TestCase;
-
-public class OutputStreamWriterTest extends TestCase {
-
- private static final int UPPER = 0xd800;
-
- private static final int BUFFER_SIZE = 10000;
-
- private ByteArrayOutputStream out;
-
- private OutputStreamWriter writer;
-
- static private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
- static private final String[] MINIMAL_CHARSETS = new String[] { "US-ASCII",
- "ISO-8859-1", "UTF-16BE", "UTF-16LE", "UTF-16", "UTF-8" };
-
- OutputStreamWriter osw;
-
- InputStreamReader isr;
-
- private ByteArrayOutputStream fos;
-
- String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- out = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(out, "utf-8");
-
- fos = new ByteArrayOutputStream();
- osw = new OutputStreamWriter(fos);
- }
-
- /*
- * @see TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- try {
- writer.close();
-
- if (isr != null) {
- isr.close();
- }
- osw.close();
- } catch (Exception e) {
- // Ignored
- }
-
- super.tearDown();
- }
-
- public void testClose() throws Exception {
- writer.flush();
- writer.close();
- try {
- writer.flush();
- fail();
- } catch (IOException e) {
- // Expected
- }
- }
-
- public void testFlush() throws Exception {
- writer.write(source);
- writer.flush();
- String result = out.toString("utf-8");
- assertEquals(source, result);
- }
-
- /*
- * Class under test for void write(char[], int, int)
- */
- public void testWritecharArrayintint() throws IOException {
- char[] chars = source.toCharArray();
-
- // Throws IndexOutOfBoundsException if offset is negative
- try {
- writer.write((char[]) null, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- // throws NullPointerException though count is negative
- try {
- writer.write((char[]) null, 1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer.write((char[]) null, 1, 1);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- writer.write(new char[0], 0, 1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, -1, 1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, 0, -1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, 1, chars.length);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- writer.write(chars, 1, 2);
- writer.flush();
- assertEquals("hi", out.toString("utf-8"));
- writer.write(chars, 0, chars.length);
- writer.flush();
- assertEquals("hi" + source, out.toString("utf-8"));
-
- writer.close();
- // After the stream is closed, should throw IOException first
- try {
- writer.write((char[]) null, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /*
- * Class under test for void write(int)
- */
- public void testWriteint() throws IOException {
- writer.write(1);
- writer.flush();
- String str = new String(out.toByteArray(), "utf-8");
- assertEquals("\u0001", str);
-
- writer.write(2);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("\u0001\u0002", str);
-
- writer.write(-1);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("\u0001\u0002\uffff", str);
-
- writer.write(0xfedcb);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("\u0001\u0002\uffff\uedcb", str);
-
- writer.close();
- // After the stream is closed, should throw IOException
- try {
- writer.write(1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /*
- * Class under test for void write(String, int, int)
- */
- public void testWriteStringintint() throws IOException {
- try {
- writer.write((String) null, 1, 1);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- writer.write("", 0, 1);
- fail();
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write("abc", -1, 1);
- fail();
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write("abc", 0, -1);
- fail();
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write("abc", 1, 3);
- fail();
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- // Throws IndexOutOfBoundsException before NullPointerException if count
- // is negative
- try {
- writer.write((String) null, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- // Throws NullPointerException before StringIndexOutOfBoundsException
- try {
- writer.write((String) null, -1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- writer.write("abc", 1, 2);
- writer.flush();
- assertEquals("bc", out.toString("utf-8"));
- writer.write(source, 0, source.length());
- writer.flush();
- assertEquals("bc" + source, out.toString("utf-8"));
-
- writer.close();
- // Throws IndexOutOfBoundsException first if count is negative
- try {
- writer.write((String) null, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write((String) null, -1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer.write("abc", -1, 0);
- fail("should throw StringIndexOutOfBoundsException");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- // Throws IOException
- try {
- writer.write("abc", 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /*
- * Class under test for void OutputStreamWriter(OutputStream)
- */
- public void testOutputStreamWriterOutputStream() throws IOException {
- try {
- writer = new OutputStreamWriter(null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- OutputStreamWriter writer2 = new OutputStreamWriter(out);
- writer2.close();
- }
-
- /*
- * Class under test for void OutputStreamWriter(OutputStream, String)
- */
- public void testOutputStreamWriterOutputStreamString() throws IOException {
- try {
- writer = new OutputStreamWriter(null, "utf-8");
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- writer = new OutputStreamWriter(out, "");
- fail();
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
- try {
- writer = new OutputStreamWriter(out, "badname");
- fail();
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
- try {
- writer = new OutputStreamWriter(out, (String) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- OutputStreamWriter writer2 = new OutputStreamWriter(out, "ascii");
- assertEquals(Charset.forName("ascii"), Charset.forName(writer2
- .getEncoding()));
- writer2.close();
- }
-
- /*
- * Class under test for void OutputStreamWriter(OutputStream)
- */
- public void testOutputStreamWriterOutputStreamCharset() throws IOException {
- Charset cs = Charset.forName("ascii");
- try {
- writer = new OutputStreamWriter(null, cs);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- writer = new OutputStreamWriter(out, (Charset) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- OutputStreamWriter writer2 = new OutputStreamWriter(out, cs);
- assertEquals(cs, Charset.forName(writer2.getEncoding()));
- writer2.close();
- }
-
- /*
- * Class under test for void OutputStreamWriter(OutputStream, String)
- */
- public void testOutputStreamWriterOutputStreamCharsetEncoder()
- throws IOException {
- Charset cs = Charset.forName("ascii");
- CharsetEncoder enc = cs.newEncoder();
- try {
- writer = new OutputStreamWriter(null, enc);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- writer = new OutputStreamWriter(out, (CharsetEncoder) null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- OutputStreamWriter writer2 = new OutputStreamWriter(out, enc);
- assertEquals(cs, Charset.forName(writer2.getEncoding()));
- writer2.close();
- }
-
- public void testGetEncoding() {
- Charset cs = Charset.forName("utf-8");
- assertEquals(cs, Charset.forName(writer.getEncoding()));
- }
-
- public void testHandleEarlyEOFChar_1() throws IOException {
- String str = "All work and no play makes Jack a dull boy\n";
- int NUMBER = 2048;
- int j = 0;
- int len = str.length() * NUMBER;
- char[] strChars = new char[len];
- for (int i = 0; i < NUMBER; ++i) {
- for (int k = 0; k < str.length(); ++k) {
- strChars[j++] = str.charAt(k);
- }
- }
-
- File f = File.createTempFile("one", "by_one");
- f.deleteOnExit();
- FileWriter fw = new FileWriter(f);
- fw.write(strChars);
- fw.close();
- FileInputStream fis = new FileInputStream(f);
- InputStreamReader in = new InputStreamReader(fis);
- for (int offset = 0; offset < strChars.length; ++offset) {
- int b = in.read();
- assertFalse("Early EOF at offset", -1 == b);
- }
- }
-
- public void testHandleEarlyEOFChar_2() throws IOException {
- int capacity = 65536;
- byte[] bytes = new byte[capacity];
- byte[] bs = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' };
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = bs[i / 8192];
- }
- String inputStr = new String(bytes);
- int len = inputStr.length();
- File f = File.createTempFile("FileWriterBugTest ", null);
- f.deleteOnExit();
- FileWriter writer = new FileWriter(f);
- writer.write(inputStr);
- writer.close();
- long flen = f.length();
-
- FileReader reader = new FileReader(f);
- char[] outChars = new char[capacity];
- int outCount = reader.read(outChars);
- String outStr = new String(outChars, 0, outCount);
-
- assertEquals(len, flen);
- assertEquals(inputStr, outStr);
- }
-
- public void testSingleCharIO() throws Exception {
- InputStreamReader isr = null;
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- out = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
- int upper = UPPER;
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- }
-
- for (int c = 0; c < upper; ++c) {
- writer.write(c);
- }
- writer.flush();
- byte[] result = out.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- for (int expected = 0; expected < upper; ++expected) {
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i], expected, isr.read());
- }
- } finally {
- try {
- isr.close();
- } catch (Exception e) {
- }
- try {
- writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- public void testBlockIO() throws Exception {
- InputStreamReader isr = null;
- char[] largeBuffer = new char[BUFFER_SIZE];
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- out = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
- int upper = UPPER;
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- }
-
- int m = 0;
- for (int c = 0; c < upper; ++c) {
- largeBuffer[m++] = (char) c;
- if (m == BUFFER_SIZE) {
- writer.write(largeBuffer);
- m = 0;
- }
- }
- writer.write(largeBuffer, 0, m);
- writer.flush();
- byte[] result = out.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- int expected = 0, read = 0, j = 0;
- while (expected < upper) {
- if (j == read) {
- read = isr.read(largeBuffer);
- j = 0;
- }
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i], expected++, largeBuffer[j++]);
- }
- } finally {
- try {
- isr.close();
- } catch (Exception e) {
- }
- try {
- writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() {
- assertTrue("Used in tests", true);
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.lang.String)
- */
- public void test_ConstructorLjava_io_OutputStreamLjava_lang_String()
- throws UnsupportedEncodingException {
- osw = new OutputStreamWriter(fos, "8859_1");
- try {
- osw = new OutputStreamWriter(fos, "Bogus");
- fail("Failed to throw Unsupported Encoding exception");
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#close()
- */
- public void test_close() throws IOException {
- osw.close();
-
- try {
- osw.write(testString, 0, testString.length());
- fail("Chars written after close");
- } catch (IOException e) {
- // Expected
- }
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- try {
- OutputStreamWriter writer = new OutputStreamWriter(bout,
- "ISO2022JP");
- writer.write(new char[] { 'a' });
- writer.close();
- // the default is ASCII, there should not be any mode changes
- String converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("invalid conversion 1: " + converted, converted
- .equals("a"));
-
- bout.reset();
- writer = new OutputStreamWriter(bout, "ISO2022JP");
- writer.write(new char[] { '\u3048' });
- writer.flush();
- // the byte sequence should not switch to ASCII mode until the
- // stream is closed
- converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("invalid conversion 2: " + converted, converted
- .equals("\u001b$B$("));
- writer.close();
- converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("invalid conversion 3: " + converted, converted
- .equals("\u001b$B$(\u001b(B"));
-
- bout.reset();
- writer = new OutputStreamWriter(bout, "ISO2022JP");
- writer.write(new char[] { '\u3048' });
- writer.write(new char[] { '\u3048' });
- writer.close();
- // there should not be a mode switch between writes
- assertEquals("invalid conversion 4", "\u001b$B$($(\u001b(B",
- new String(bout.toByteArray(), "ISO8859_1"));
- } catch (UnsupportedEncodingException e) {
- // Can't test missing converter
- System.out.println(e);
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#flush()
- */
- public void test_flush() throws IOException {
- char[] buf = new char[testString.length()];
- osw.write(testString, 0, testString.length());
- osw.flush();
- openInputStream();
- isr.read(buf, 0, buf.length);
- assertTrue("Chars not flushed", new String(buf, 0, buf.length)
- .equals(testString));
- }
-
- /**
- * @tests java.io.OutputStreamWriter#getEncoding()
- */
- public void test_getEncoding() throws IOException {
- try {
- osw = new OutputStreamWriter(fos, "8859_1");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Returned incorrect encoding", "8859_1", osw
- .getEncoding());
- }
-
- OutputStreamWriter out = new OutputStreamWriter(
- new ByteArrayOutputStream(), "UTF-16BE");
- out.close();
-
- String result = out.getEncoding();
- assertNull(result);
-
- out = null;
- try {
- out = new OutputStreamWriter(new ByteArrayOutputStream(),
- "UTF-16BE");
- } catch (UnsupportedEncodingException e) {
- // ok
- }
- result = out.getEncoding();
- assertEquals("UnicodeBigUnmarked", result);
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(char[], int, int)
- */
- public void test_write$CII() throws IOException {
- char[] buf = new char[testString.length()];
- osw.write(testString, 0, testString.length());
- osw.close();
- openInputStream();
- isr.read(buf, 0, buf.length);
- assertTrue("Incorrect chars returned", new String(buf, 0, buf.length)
- .equals(testString));
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(int)
- */
- public void test_writeI() throws IOException {
- osw.write('T');
- osw.close();
- openInputStream();
- int c = isr.read();
- assertEquals("Incorrect char returned", 'T', (char) c);
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(java.lang.String, int, int)
- */
- public void test_writeLjava_lang_StringII() throws IOException {
- char[] buf = new char[testString.length()];
- osw.write(testString, 0, testString.length());
- osw.close();
- openInputStream();
- isr.read(buf);
- assertTrue("Incorrect chars returned", new String(buf, 0, buf.length)
- .equals(testString));
- }
-
- private void openInputStream() {
- isr = new InputStreamReader(new ByteArrayInputStream(fos.toByteArray()));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/PushBackInputStreamTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/PushBackInputStreamTest.java
deleted file mode 100644
index c5f19f4..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/PushBackInputStreamTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.PushbackInputStream;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-@TestTargetClass(PushbackInputStream.class)
-public class PushBackInputStreamTest extends TestCase {
-
- /*
- * @tests java.io.PushBackInputStream(InputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "read",
- args = {}
- )
- public void test_read() {
- PushbackInputStream str = new PushbackInputStream(null);
- try {
- str.read();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- str = new PushbackInputStream(null, 1);
- try {
- str.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#unread(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "unread",
- args = {byte[].class, int.class, int.class}
- )
- public void test_unread$BII() {
- // Regression for HARMONY-49
- try {
- PushbackInputStream pb = new PushbackInputStream(
- new ByteArrayInputStream(new byte[] { 0 }), 2);
- pb.unread(new byte[1], 0, 5);
- fail("Assert 0: should throw IOE");
- } catch (IOException e) {
- // expected
- }
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- PushbackInputStream pb = new PushbackInputStream(
- new ByteArrayInputStream(new byte[] { 0 }), 2);
- try {
- pb.reset();
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mark",
- args = {int.class}
- )
- public void test_mark() {
- PushbackInputStream pb = new PushbackInputStream(
- new ByteArrayInputStream(new byte[] { 0 }), 2);
- pb.mark(Integer.MAX_VALUE);
- pb.mark(0);
- pb.mark(-1);
- pb.mark(Integer.MIN_VALUE);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java
deleted file mode 100644
index 4cd1f56..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/RandomAccessFileTest.java
+++ /dev/null
@@ -1,984 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
-import java.nio.channels.FileChannel;
-import java.nio.channels.NonWritableChannelException;
-
-public class RandomAccessFileTest extends junit.framework.TestCase {
-
- public String fileName;
-
- public boolean ufile = true;
-
- java.io.RandomAccessFile raf;
-
- java.io.File f;
-
- String unihw = "\u0048\u0065\u006C\u0801\u006C\u006F\u0020\u0057\u0081\u006F\u0072\u006C\u0064";
-
- //java.io.FileOutputStream fos;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.RandomAccessFile#RandomAccessFile(java.io.File,
- * java.lang.String)
- */
- public void test_ConstructorLjava_io_FileLjava_lang_String()
- throws Exception {
- // Test for method java.io.RandomAccessFile(java.io.File,
- // java.lang.String)
- RandomAccessFile raf = new java.io.RandomAccessFile(f, "rw");
- raf.write(20);
- raf.seek(0);
- assertEquals("Incorrect int read/written", 20, raf.read());
- raf.close();
-
- raf = new java.io.RandomAccessFile(f, "rwd");
- raf.write(20);
- raf.seek(0);
- assertEquals("Incorrect int read/written", 20, raf.read());
- raf.close();
-
- raf = new java.io.RandomAccessFile(f, "rws");
- raf.write(20);
- raf.seek(0);
- assertEquals("Incorrect int read/written", 20, raf.read());
- raf.close();
-
- // Regression for HARMONY-50
- File f = File.createTempFile("xxx", "yyy");
- f.deleteOnExit();
- raf = new RandomAccessFile(f, "rws");
- raf.close();
-
- f = File.createTempFile("xxx", "yyy");
- f.deleteOnExit();
- raf = new RandomAccessFile(f, "rwd");
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#RandomAccessFile(java.lang.String,
- * java.lang.String)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_String()
- throws IOException {
- // Test for method java.io.RandomAccessFile(java.lang.String,
- // java.lang.String)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write("Test".getBytes(), 0, 4);
- raf.close();
-
- raf = new java.io.RandomAccessFile(fileName, "rwd");
- raf.write("Test".getBytes(), 0, 4);
- raf.close();
-
- raf = new java.io.RandomAccessFile(fileName, "rws");
- raf.write("Test".getBytes(), 0, 4);
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#close()
- */
- public void test_close() {
- // Test for method void java.io.RandomAccessFile.close()
- try {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.close();
- raf.write("Test".getBytes(), 0, 4);
- fail("Failed to close file properly");
- } catch (IOException e) {}
- }
-
- /**
- * @tests java.io.RandomAccessFile#getFD()
- */
- public void test_getFD() throws IOException {
- // Test for method java.io.FileDescriptor
- // java.io.RandomAccessFile.getFD()
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- assertTrue("Returned invalid fd", raf.getFD().valid());
-
- raf.close();
- assertFalse("Returned valid fd after close", raf.getFD().valid());
- }
-
- /**
- * @tests java.io.RandomAccessFile#getFilePointer()
- */
- public void test_getFilePointer() throws IOException {
- // Test for method long java.io.RandomAccessFile.getFilePointer()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(fileString.getBytes(), 0, 1000);
- assertEquals("Incorrect filePointer returned", 1000, raf
- .getFilePointer());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#length()
- */
- public void test_length() throws IOException {
- // Test for method long java.io.RandomAccessFile.length()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(fileString.getBytes());
- assertEquals("Incorrect length returned", fileString.length(), raf
- .length());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#read()
- */
- public void test_read() throws IOException {
- // Test for method int java.io.RandomAccessFile.read()
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes("UTF-8"), 0, fileString.length());
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- assertEquals("Incorrect bytes returned from read",
- fileString.charAt(0), raf.read());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[])
- */
- public void test_read$B() throws IOException {
- // Test for method int java.io.RandomAccessFile.read(byte [])
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes(), 0, fileString.length());
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- byte[] rbuf = new byte[4000];
- raf.read(rbuf);
- assertEquals("Incorrect bytes returned from read", fileString,
- new String(rbuf, 0, fileString.length()));
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[], int, int)
- */
- public void test_read$BII() throws IOException {
- // Test for method int java.io.RandomAccessFile.read(byte [], int, int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- byte[] rbuf = new byte[4000];
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes(), 0, fileString.length());
- fos.close();
- raf.read(rbuf, 0, fileString.length());
- assertEquals("Incorrect bytes returned from read", fileString,
- new String(rbuf, 0, fileString.length()));
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readBoolean()
- */
- public void test_readBoolean() throws IOException {
- // Test for method boolean java.io.RandomAccessFile.readBoolean()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBoolean(true);
- raf.seek(0);
- assertTrue("Incorrect boolean read/written", raf.readBoolean());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readByte()
- */
- public void test_readByte() throws IOException {
- // Test for method byte java.io.RandomAccessFile.readByte()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeByte(127);
- raf.seek(0);
- assertEquals("Incorrect bytes read/written", 127, raf.readByte());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readChar()
- */
- public void test_readChar() throws IOException {
- // Test for method char java.io.RandomAccessFile.readChar()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeChar('T');
- raf.seek(0);
- assertEquals("Incorrect char read/written", 'T', raf.readChar());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readDouble()
- */
- public void test_readDouble() throws IOException {
- // Test for method double java.io.RandomAccessFile.readDouble()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeDouble(Double.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect double read/written", Double.MAX_VALUE, raf
- .readDouble(), 0);
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readFloat()
- */
- public void test_readFloat() throws IOException {
- // Test for method float java.io.RandomAccessFile.readFloat()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeFloat(Float.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect float read/written", Float.MAX_VALUE, raf
- .readFloat(), 0);
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readFully(byte[])
- */
- public void test_readFully$B() throws IOException {
- // Test for method void java.io.RandomAccessFile.readFully(byte [])
- byte[] buf = new byte[10];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes("HelloWorld");
- raf.seek(0);
- raf.readFully(buf);
- assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
- buf, 0, 10, "UTF-8"));
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readFully(byte[], int, int)
- */
- public void test_readFully$BII() throws IOException {
- // Test for method void java.io.RandomAccessFile.readFully(byte [], int,
- // int)
- byte[] buf = new byte[10];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes("HelloWorld");
- raf.seek(0);
- raf.readFully(buf, 0, buf.length);
- assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
- buf, 0, 10, "UTF-8"));
- try {
- raf.readFully(buf, 0, buf.length);
- fail("Reading past end of buffer did not throw EOFException");
- } catch (EOFException e) {}
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readInt()
- */
- public void test_readInt() throws IOException {
- // Test for method int java.io.RandomAccessFile.readInt()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeInt(Integer.MIN_VALUE);
- raf.seek(0);
- assertEquals("Incorrect int read/written", Integer.MIN_VALUE, raf
- .readInt());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readLine()
- */
- public void test_readLine() throws IOException {
- // Test for method java.lang.String java.io.RandomAccessFile.readLine()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- String s = "Goodbye\nCruel\nWorld\n";
- raf.write(s.getBytes("UTF-8"), 0, s.length());
- raf.seek(0);
-
- assertEquals("Goodbye", raf.readLine());
- assertEquals("Cruel", raf.readLine());
- assertEquals("World", raf.readLine());
-
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readLong()
- */
- public void test_readLong() throws IOException {
- // Test for method long java.io.RandomAccessFile.readLong()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeLong(Long.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect long read/written", Long.MAX_VALUE, raf
- .readLong());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readShort()
- */
- public void test_readShort() throws IOException {
- // Test for method short java.io.RandomAccessFile.readShort()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeShort(Short.MIN_VALUE);
- raf.seek(0);
- assertEquals("Incorrect long read/written", Short.MIN_VALUE, raf
- .readShort());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUnsignedByte()
- */
- public void test_readUnsignedByte() throws IOException {
- // Test for method int java.io.RandomAccessFile.readUnsignedByte()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeByte(-1);
- raf.seek(0);
- assertEquals("Incorrect byte read/written", 255, raf.readUnsignedByte());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUnsignedShort()
- */
- public void test_readUnsignedShort() throws IOException {
- // Test for method int java.io.RandomAccessFile.readUnsignedShort()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeShort(-1);
- raf.seek(0);
- assertEquals("Incorrect byte read/written", 65535, raf
- .readUnsignedShort());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUTF()
- */
- public void test_readUTF() throws IOException {
- // Test for method java.lang.String java.io.RandomAccessFile.readUTF()
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeUTF(unihw);
- raf.seek(0);
- assertEquals("Incorrect utf string read", unihw, raf.readUTF());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#seek(long)
- */
- public void test_seekJ() throws IOException {
- // Test for method void java.io.RandomAccessFile.seek(long)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(fileString.getBytes(), 0, fileString.length());
- raf.seek(12);
- assertEquals("Seek failed to set filePointer", 12, raf.getFilePointer());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#skipBytes(int)
- */
- public void test_skipBytesI() throws IOException {
- // Test for method int java.io.RandomAccessFile.skipBytes(int)
- byte[] buf = new byte[5];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes("HelloWorld");
- raf.seek(0);
- raf.skipBytes(5);
- raf.readFully(buf);
- assertEquals("Failed to skip bytes", "World", new String(buf, 0, 5, "UTF-8"));
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[])
- */
- public void test_write$B() throws IOException {
- // Test for method void java.io.RandomAccessFile.write(byte [])
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
-
- byte[] nullByteArray = null;
- try {
- raf.write(nullByteArray);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- byte[] rbuf = new byte[4000];
- raf.write(fileString.getBytes());
- raf.close();
-
- try {
- raf.write(nullByteArray);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- //will not throw IOException if array's length is 0
- raf.write(new byte[0]);
-
- try {
- raf.write(fileString.getBytes());
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
-
- FileInputStream fis = new java.io.FileInputStream(fileName);
- fis.read(rbuf, 0, fileString.length());
- assertEquals("Incorrect bytes written", fileString, new String(rbuf, 0,
- fileString.length()));
- fis.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[], int, int)
- */
- public void test_write$BII() throws IOException {
- // Test for method void java.io.RandomAccessFile.write(byte [], int,
- // int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- byte[] rbuf = new byte[4000];
- raf.write(fileString.getBytes(), 0, fileString.length());
- raf.close();
- FileInputStream fis = new java.io.FileInputStream(fileName);
- fis.read(rbuf, 0, fileString.length());
- assertEquals("Incorrect bytes written", fileString, new String(rbuf, 0,
- fileString.length()));
- fis.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[], int, int)
- */
- public void test_write_$BII_Exception() throws IOException {
- raf = new java.io.RandomAccessFile(f, "rw");
- byte[] nullByteArray = null;
- byte[] byteArray = new byte[10];
-
- try {
- raf.write(nullByteArray, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(nullByteArray, 0, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(nullByteArray, 1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(nullByteArray, 1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(nullByteArray, 1, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- raf.write(byteArray, 0, 0);
- raf.write(byteArray, 0, byteArray.length);
- raf.write(byteArray, 1, 0);
- raf.write(byteArray, byteArray.length, 0);
-
- try {
- raf.write(byteArray, byteArray.length + 1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- raf.write(byteArray, byteArray.length + 1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- raf.close();
-
- try {
- raf.write(nullByteArray, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- raf.write(byteArray, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
-
- try {
- raf.write(byteArray, 0, byteArray.length);
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
-
- try {
- raf.write(byteArray, 1, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
-
- try {
- raf.write(byteArray, byteArray.length + 1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- // will not throw IOException if count = 0
- raf.write(byteArray, 0, 0);
- raf.write(byteArray, byteArray.length, 0);
- }
-
-
- /**
- * @tests java.io.RandomAccessFile#write(int)
- */
- public void test_writeI() throws IOException {
- // Test for method void java.io.RandomAccessFile.write(int)
- byte[] rbuf = new byte[4000];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write('t');
- raf.close();
- FileInputStream fis = new java.io.FileInputStream(fileName);
- fis.read(rbuf, 0, 1);
- assertEquals("Incorrect byte written", 't', rbuf[0]);
- fis.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeBoolean(boolean)
- */
- public void test_writeBooleanZ() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeBoolean(boolean)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBoolean(true);
- raf.seek(0);
- assertTrue("Incorrect boolean read/written", raf.readBoolean());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeByte(int)
- */
- public void test_writeByteI() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeByte(int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeByte(127);
- raf.seek(0);
- assertEquals("Incorrect byte read/written", 127, raf.readByte());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeBytes(java.lang.String)
- */
- public void test_writeBytesLjava_lang_String() throws IOException {
- // Test for method void
- // java.io.RandomAccessFile.writeBytes(java.lang.String)
- byte[] buf = new byte[10];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes("HelloWorld");
- raf.seek(0);
- raf.readFully(buf);
- assertEquals("Incorrect bytes read/written", "HelloWorld", new String(
- buf, 0, 10, "UTF-8"));
- raf.close();
-
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeChar(int)
- */
- public void test_writeCharI() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeChar(int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeChar('T');
- raf.seek(0);
- assertEquals("Incorrect char read/written", 'T', raf.readChar());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeChars(java.lang.String)
- */
- public void test_writeCharsLjava_lang_String() throws IOException {
- // Test for method void
- // java.io.RandomAccessFile.writeChars(java.lang.String)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeChars("HelloWorld");
- char[] hchars = new char[10];
- "HelloWorld".getChars(0, 10, hchars, 0);
- raf.seek(0);
- for (int i = 0; i < hchars.length; i++)
- assertEquals("Incorrect string written", hchars[i], raf.readChar());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeDouble(double)
- */
- public void test_writeDoubleD() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeDouble(double)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeDouble(Double.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect double read/written", Double.MAX_VALUE, raf
- .readDouble(), 0);
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeFloat(float)
- */
- public void test_writeFloatF() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeFloat(float)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeFloat(Float.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect float read/written", Float.MAX_VALUE, raf
- .readFloat(), 0);
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeInt(int)
- */
- public void test_writeIntI() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeInt(int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeInt(Integer.MIN_VALUE);
- raf.seek(0);
- assertEquals("Incorrect int read/written", Integer.MIN_VALUE, raf
- .readInt());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeLong(long)
- */
- public void test_writeLongJ() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeLong(long)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeLong(Long.MAX_VALUE);
- raf.seek(0);
- assertEquals("Incorrect long read/written", Long.MAX_VALUE, raf
- .readLong());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeShort(int)
- */
- public void test_writeShortI() throws IOException {
- // Test for method void java.io.RandomAccessFile.writeShort(int)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeShort(Short.MIN_VALUE);
- raf.seek(0);
- assertEquals("Incorrect long read/written", Short.MIN_VALUE, raf
- .readShort());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeUTF(java.lang.String)
- */
- public void test_writeUTFLjava_lang_String() throws IOException {
- // Test for method void
- // java.io.RandomAccessFile.writeUTF(java.lang.String)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeUTF(unihw);
- raf.seek(0);
- assertEquals("Incorrect utf string", unihw, raf.readUTF());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#seek(long)
- *
- * Regression for HARMONY-374
- */
- public void test_seekI() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- try {
- raf.seek(-1);
- fail("IOException must be thrown if pos < 0");
- } catch (IOException e) {
- }
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[], int, int)
- *
- * Regression for HARMONY-377
- */
- public void test_readBII() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- try {
- raf.read(new byte[1], -1, 1);
- fail("IndexOutOfBoundsException must be thrown if off <0");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.read(new byte[1], 0, -1);
- fail("IndexOutOfBoundsException must be thrown if len <0");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.read(new byte[1], 0, 5);
- fail("IndexOutOfBoundsException must be thrown if off+len > b.length");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.read(new byte[10], Integer.MAX_VALUE, 5);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.read(new byte[10], 5, Integer.MAX_VALUE);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- }
-
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[],int,int)
- */
- public void test_read_$BII_IndexOutOfBoundsException() throws IOException {
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes(), 0, fileString.length());
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- byte[] rbuf = new byte[100];
- raf.close();
- try {
- raf.read(rbuf,-1,0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[],int,int)
- */
- public void test_read_$BII_IOException() throws IOException {
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes(), 0, fileString.length());
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- byte[] rbuf = new byte[100];
- raf.close();
- int read = raf.read(rbuf,0,0);
- assertEquals(0,read);
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[])
- */
- public void test_read_$B_IOException() throws IOException {
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(fileString.getBytes(), 0, fileString.length());
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- byte[] rbuf = new byte[0];
- raf.close();
- int read = raf.read(rbuf);
- assertEquals(0,read);
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[],int,int)
- */
- public void test_read_$BII_NullPointerException() throws IOException {
- File f = File.createTempFile("tmp", "tmp");
- f.deleteOnExit();
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- byte[] rbuf = null;
- try {
- raf.read(rbuf, 0, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[], int, int)
- *
- * Regression for HARMONY-377
- */
- public void test_writeBII() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- try {
- raf.write(new byte[1], -1, 1);
- fail("IndexOutOfBoundsException must be thrown if off <0");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.write(new byte[1], 0, -1);
- fail("IndexOutOfBoundsException must be thrown if len <0");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.write(new byte[1], 0, 5);
- fail("IndexOutOfBoundsException must be thrown if off+len > b.length");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.write(new byte[10], Integer.MAX_VALUE, 5);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- raf.write(new byte[10], 5, Integer.MAX_VALUE);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- }
- raf.close();
- }
-
- /**
- * Regression for HARMONY-69
- */
- public void testRandomAccessFile_String_String() throws IOException {
- f.createNewFile();
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- FileChannel fcr = raf.getChannel();
-
- try {
- fcr.lock(0L, Long.MAX_VALUE, false);
- fail("NonWritableChannelException expected!");
- } catch (NonWritableChannelException e) {}
- raf.close();
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
- f = File.createTempFile("raf", "tst");
- if (!f.delete()) {
- fail("Unable to delete test file : " + f);
- }
- fileName = f.getAbsolutePath();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- * @throws Exception
- */
- protected void tearDown() throws Exception {
- if (f.exists()) {
- f.delete();
- }
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java
deleted file mode 100644
index f818917..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/ReaderTest.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.nio.CharBuffer;
-
-import junit.framework.TestCase;
-import tests.support.Support_ASimpleReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(Reader.class)
-public class ReaderTest extends TestCase {
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "Reader",
- args = {}
- )
- public void test_Reader() {
- MockReader r = new MockReader();
- assertTrue("Test 1: Lock has not been set correctly.", r.lockSet(r));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "Reader",
- args = {java.lang.Object.class}
- )
- public void test_Reader_CharBuffer_null() throws IOException {
- String s = "MY TEST STRING";
- MockReader mockReader = new MockReader(s.toCharArray());
- CharBuffer charBuffer = null;
- try {
- mockReader.read(charBuffer);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected;
- }
- }
-
- @TestTargets ({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "Reader",
- args = {java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- })
- public void test_Reader_CharBuffer_ZeroChar() throws IOException {
- // If the charBuffer has a capacity of 0, then the number of char read
- // to the CharBuffer is 0. Furthermore, the MockReader is intact in
- // its content.
- String s = "MY TEST STRING";
- char[] srcBuffer = s.toCharArray();
- MockReader mockReader = new MockReader(srcBuffer);
- CharBuffer charBuffer = CharBuffer.allocate(0);
- int result = mockReader.read(charBuffer);
- assertEquals(0, result);
- char[] destBuffer = new char[srcBuffer.length];
- mockReader.read(destBuffer);
- assertEquals(s, String.valueOf(destBuffer));
- }
-
- @TestTargets ({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "Reader",
- args = {java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- })
- public void test_Reader_CharBufferChar() throws IOException {
- String s = "MY TEST STRING";
- char[] srcBuffer = s.toCharArray();
- final int CHARBUFFER_SIZE = 10;
- MockReader mockReader = new MockReader(srcBuffer);
- CharBuffer charBuffer = CharBuffer.allocate(CHARBUFFER_SIZE);
- charBuffer.append('A');
- final int CHARBUFFER_REMAINING = charBuffer.remaining();
- int result = mockReader.read(charBuffer);
- assertEquals(CHARBUFFER_REMAINING, result);
- charBuffer.rewind();
- assertEquals(s.substring(0, CHARBUFFER_REMAINING), charBuffer
- .subSequence(CHARBUFFER_SIZE - CHARBUFFER_REMAINING,
- CHARBUFFER_SIZE).toString());
- char[] destBuffer = new char[srcBuffer.length - CHARBUFFER_REMAINING];
- mockReader.read(destBuffer);
- assertEquals(s.substring(CHARBUFFER_REMAINING), String
- .valueOf(destBuffer));
-
- Support_ASimpleReader simple;
- simple = new Support_ASimpleReader("Bla bla, what else?");
- CharBuffer buf = CharBuffer.allocate(4);
- assertEquals("Wrong return value!", 4, simple.read(buf));
- buf.rewind();
- assertEquals("Wrong stuff read!", "Bla ", String.valueOf(buf));
- simple.read(buf);
- buf.rewind();
- assertEquals("Wrong stuff read!", "bla,", String.valueOf(buf));
- simple.throwExceptionOnNextUse = true;
- try {
- simple.read(buf);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {char[].class}
- )
- public void test_Read_$C() throws IOException {
- Support_ASimpleReader simple;
- simple = new Support_ASimpleReader("Bla bla, what else?");
- char[] buf = new char[4];
- assertEquals("Wrong return value!", 4, simple.read(buf));
- assertEquals("Wrong stuff read!", "Bla ", new String(buf));
- simple.read(buf);
- assertEquals("Wrong stuff read!", "bla,", new String(buf));
- simple.throwExceptionOnNextUse = true;
- try {
- simple.read(buf);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.io.Reader#mark(int)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mark",
- args = {int.class}
- )
- public void test_mark() {
- MockReader mockReader = new MockReader();
- try {
- mockReader.mark(0);
- fail("Should throw IOException for Reader do not support mark");
- } catch (IOException e) {
- // Excepted
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- assertFalse("markSupported must return false", new MockReader().markSupported());
- }
-
- /**
- * @tests {@link java.io.Reader#read()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- MockReader reader = new MockReader();
-
- // return -1 when the stream is null;
- assertEquals("Should be equal to -1", -1, reader.read());
-
- String string = "MY TEST STRING";
- char[] srcBuffer = string.toCharArray();
- MockReader mockReader = new MockReader(srcBuffer);
-
- // normal read
- for (char c : srcBuffer) {
- assertEquals("Should be equal to \'" + c + "\'", c, mockReader
- .read());
- }
-
- // return -1 when read Out of Index
- mockReader.read();
- assertEquals("Should be equal to -1", -1, reader.read());
-
- Support_ASimpleReader simple;
- simple = new Support_ASimpleReader("Bla bla, what else?");
- int res;
- res = simple.read();
- assertEquals("Wrong stuff read!", 'B', res);
- res = simple.read();
- assertEquals("Wrong stuff read!", 'l', res);
- simple.throwExceptionOnNextUse = true;
- try {
- simple.read();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.io.Reader#ready()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ready",
- args = {}
- )
- public void test_ready() throws IOException {
- MockReader mockReader = new MockReader();
- assertFalse("Should always return false", mockReader.ready());
-
- Support_ASimpleReader simple;
- simple = new Support_ASimpleReader("Bla bla, what else?");
- simple.throwExceptionOnNextUse = true;
- try {
- simple.ready();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests {@link java.io.Reader#reset()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- MockReader mockReader = new MockReader();
- try {
- mockReader.reset();
- fail("Should throw IOException");
- } catch (IOException e) {
- // Excepted
- }
- }
-
- /**
- * @tests {@link java.io.Reader#skip(long)}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skip() throws IOException {
- String string = "MY TEST STRING";
- char[] srcBuffer = string.toCharArray();
- int length = srcBuffer.length;
- MockReader mockReader = new MockReader(srcBuffer);
- assertEquals("Should be equal to \'M\'", 'M', mockReader.read());
-
- // normal skip
- mockReader.skip(length / 2);
- assertEquals("Should be equal to \'S\'", 'S', mockReader.read());
-
- // try to skip a bigger number of characters than the total
- // Should do nothing
- mockReader.skip(length);
-
- // try to skip a negative number of characters throw IllegalArgumentException
- try {
- mockReader.skip(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Excepted
- }
-
- Support_ASimpleReader simple;
- simple = new Support_ASimpleReader("Bla bla, what else?");
- char[] buf = new char[4];
- simple.read(buf);
- assertEquals("Wrong stuff read!", "Bla ", new String(buf));
- simple.skip(5);
- simple.read(buf);
- assertEquals("Wrong stuff read!", "what", new String(buf));
- simple.throwExceptionOnNextUse = true;
- try {
- simple.skip(1);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- class MockReader extends Reader {
-
- private char[] contents;
-
- private int current_offset = 0;
-
- private int length = 0;
-
- public MockReader() {
- super();
- }
-
- public MockReader(char[] data) {
- contents = data;
- length = contents.length;
- }
-
- @Override
- public void close() throws IOException {
-
- contents = null;
- }
-
- @Override
- public int read(char[] buf, int offset, int count) throws IOException {
-
- if (null == contents) {
- return -1;
- }
- if (length <= current_offset) {
- return -1;
- }
- if (buf.length < offset + count) {
- throw new IndexOutOfBoundsException();
- }
-
- count = Math.min(count, length - current_offset);
- for (int i = 0; i < count; i++) {
- buf[offset + i] = contents[current_offset + i];
- }
- current_offset += count;
- return count;
- }
-
- public boolean lockSet(Object o) {
- return (lock == o);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java
deleted file mode 100644
index e08b868..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/io/WriterTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.io;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import junit.framework.TestCase;
-
-public class WriterTest extends TestCase {
-
- /**
- * @tests java.io.Writer#append(char)
- */
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- MockWriter writer = new MockWriter(20);
- writer.append(testChar);
- assertEquals(String.valueOf(testChar), String.valueOf(writer
- .getContents()));
- writer.close();
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence)
- */
- public void test_appendCharSequence() throws IOException {
- String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString);
- assertEquals(testString, String.valueOf(writer.getContents()));
- writer.close();
-
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- public void test_appendCharSequenceIntInt() throws IOException {
- String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString, 1, 3);
- assertEquals(testString.substring(1, 3), String.valueOf(writer
- .getContents()));
- writer.close();
-
- }
-
-
-
- /**
- * @tests java.io.Writer#write(String)
- */
- public void test_writeLjava_lang_String() throws IOException {
- // Regression for HARMONY-51
- Object lock = new Object();
- Writer wr = new MockLockWriter(lock);
- wr.write("Some string");
- wr.close();
- }
-
- class MockLockWriter extends Writer {
- final Object myLock;
-
- MockLockWriter(Object lock) {
- super(lock);
- myLock = lock;
- }
-
- @Override
- public synchronized void close() throws IOException {
- // do nothing
- }
-
- @Override
- public synchronized void flush() throws IOException {
- // do nothing
- }
-
- @Override
- public void write(char[] arg0, int arg1, int arg2) throws IOException {
- assertTrue(Thread.holdsLock(myLock));
- }
- }
-
-
- class MockWriter extends Writer {
- private char[] contents;
-
- private int length;
-
- private int offset;
-
- MockWriter(int capacity) {
- contents = new char[capacity];
- length = capacity;
- offset = 0;
- }
-
- public synchronized void close() throws IOException {
- flush();
- contents = null;
- }
-
- public synchronized void flush() throws IOException {
- // do nothing
- }
-
- public void write(char[] buffer, int offset, int count)
- throws IOException {
- if (null == contents) {
- throw new IOException();
- }
- if (offset < 0 || count < 0 || offset >= buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- count = Math.min(count, buffer.length - offset);
- count = Math.min(count, this.length - this.offset);
- for (int i = 0; i < count; i++) {
- contents[this.offset + i] = buffer[offset + i];
- }
- this.offset += count;
-
- }
-
- public char[] getContents() {
- char[] result = new char[offset];
- for (int i = 0; i < offset; i++) {
- result[i] = contents[i];
- }
- return result;
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AllTests.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AllTests.java
deleted file mode 100644
index 9f5b1b3..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AllTests.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
-/**
- * Listing of all the tests that are to be run.
- */
-public class AllTests {
-
- public static void run() {
- TestRunner.main(new String[] { AllTests.class.getName() });
- }
-
- public static Test suite() {
- TestSuite suite = new TestSuite("Tests for java.lang");
-
- suite.addTestSuite(ArithmeticExceptionTest.class);
- suite.addTestSuite(ArrayIndexOutOfBoundsExceptionTest.class);
- suite.addTestSuite(ArrayStoreExceptionTest.class);
- suite.addTestSuite(AssertionErrorTest.class);
- suite.addTestSuite(BooleanTest.class);
- suite.addTestSuite(ByteTest.class);
- suite.addTestSuite(Character_SubsetTest.class);
- suite.addTestSuite(OldCharacterTest.class);
- suite.addTestSuite(Character_UnicodeBlockTest.class);
- suite.addTestSuite(ClassCastExceptionTest.class);
- suite.addTestSuite(ClassCircularityErrorTest.class);
- suite.addTestSuite(ClassFormatErrorTest.class);
- suite.addTestSuite(ClassLoaderTest.class);
- suite.addTestSuite(ClassNotFoundExceptionTest.class);
- suite.addTestSuite(ClassTest.class);
- suite.addTestSuite(ClassTest2.class);
- suite.addTestSuite(CloneNotSupportedExceptionTest.class);
- suite.addTestSuite(CompilerTest.class);
- suite.addTestSuite(DoubleTest.class);
- suite.addTestSuite(EnumConstantNotPresentExceptionTest.class);
- suite.addTestSuite(ErrorTest.class);
- suite.addTestSuite(ExceptionInInitializerErrorTest.class);
- suite.addTestSuite(ExceptionTest.class);
- suite.addTestSuite(FloatTest.class);
- suite.addTestSuite(IllegalAccessErrorTest.class);
- suite.addTestSuite(IllegalAccessExceptionTest.class);
- suite.addTestSuite(IllegalArgumentExceptionTest.class);
- suite.addTestSuite(IllegalMonitorStateExceptionTest.class);
- suite.addTestSuite(IllegalStateExceptionTest.class);
- suite.addTestSuite(IllegalThreadStateExceptionTest.class);
- suite.addTestSuite(IncompatibleClassChangeErrorTest.class);
- suite.addTestSuite(IndexOutOfBoundsExceptionTest.class);
- suite.addTestSuite(InheritableThreadLocalTest.class);
- suite.addTestSuite(InstantiationErrorTest.class);
- suite.addTestSuite(InstantiationExceptionTest.class);
- suite.addTestSuite(IntegerTest.class);
- suite.addTestSuite(InternalErrorTest.class);
- suite.addTestSuite(InterruptedExceptionTest.class);
- suite.addTestSuite(LinkageErrorTest.class);
- suite.addTestSuite(LongTest.class);
- suite.addTestSuite(MathTest.class);
- suite.addTestSuite(NegativeArraySizeExceptionTest.class);
- suite.addTestSuite(NoClassDefFoundErrorTest.class);
- suite.addTestSuite(NoSuchFieldErrorTest.class);
- suite.addTestSuite(NoSuchFieldExceptionTest.class);
- suite.addTestSuite(NoSuchMethodErrorTest.class);
- suite.addTestSuite(NoSuchMethodExceptionTest.class);
- suite.addTestSuite(NullPointerExceptionTest.class);
- suite.addTestSuite(NumberFormatExceptionTest.class);
- suite.addTestSuite(NumberTest.class);
- suite.addTestSuite(ObjectTest.class);
- suite.addTestSuite(OutOfMemoryErrorTest.class);
- suite.addTestSuite(RuntimeExceptionTest.class);
- suite.addTestSuite(RuntimePermissionTest.class);
- suite.addTestSuite(RuntimeTest.class);
- suite.addTestSuite(SecurityExceptionTest.class);
- suite.addTestSuite(SecurityManagerTest.class);
- suite.addTestSuite(ShortTest.class);
- suite.addTestSuite(StackOverflowErrorTest.class);
- suite.addTestSuite(StackTraceElementTest.class);
- suite.addTestSuite(StrictMathTest.class);
- suite.addTestSuite(StringBuffer2Test.class);
- suite.addTestSuite(StringBufferTest.class);
- suite.addTestSuite(StringBuilderTest.class);
- suite.addTestSuite(StringIndexOutOfBoundsExceptionTest.class);
- suite.addTestSuite(SystemTest.class);
- suite.addTestSuite(ThreadDeathTest.class);
- suite.addTestSuite(ThreadLocalTest.class);
- suite.addTestSuite(ThreadStateTest.class);
- suite.addTestSuite(ThrowableTest.class);
- suite.addTestSuite(TypeNotPresentExceptionTest.class);
- suite.addTestSuite(UnknownErrorTest.class);
- suite.addTestSuite(UnsatisfiedLinkErrorTest.class);
- suite.addTestSuite(UnsupportedOperationExceptionTest.class);
- suite.addTestSuite(UnsupportedClassVersionErrorTest.class);
- suite.addTestSuite(VerifyErrorTest.class);
- suite.addTestSuite(VirtualMachineErrorTest.class);
-
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java
deleted file mode 100644
index f99be20..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArithmeticExceptionTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ArithmeticExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.ArithmeticException#ArithmeticException()
- */
- public void test_Constructor() {
- ArithmeticException e = new ArithmeticException();
- assertNull(e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ArithmeticException#ArithmeticException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ArithmeticException e = new ArithmeticException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
deleted file mode 100644
index c7537c0..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayIndexOutOfBoundsExceptionTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ArrayIndexOutOfBoundsExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(int)
- */
- public void test_ConstructorI() {
- ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException(-1);
- assertNotNull(e.getMessage());
- assertTrue("Unable to find index value in 'message' property.", e.getMessage().indexOf(
- "-1", 0) >= 0);
-
- }
-
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException()
- */
- public void test_Constructor() {
- ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException();
- assertNull(e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ArrayIndexOutOfBoundsException#ArrayIndexOutOfBoundsException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ArrayIndexOutOfBoundsException e = new ArrayIndexOutOfBoundsException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java
deleted file mode 100644
index c8979d0..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ArrayStoreExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ArrayStoreExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.ArrayStoreException#ArrayStoreException()
- */
- public void test_Constructor() {
- ArrayStoreException e = new ArrayStoreException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ArrayStoreException#ArrayStoreException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ArrayStoreException e = new ArrayStoreException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AssertionErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AssertionErrorTest.java
deleted file mode 100644
index ce196ba..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/AssertionErrorTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class AssertionErrorTest extends TestCase {
-
- public void test_Constructor() {
- AssertionError e = new AssertionError();
- assertNull(e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorObject() {
- Object obj = "toString";
- AssertionError e = new AssertionError(obj);
- assertEquals("toString", e.getMessage());
- assertNull(e.getCause());
-
- NullPointerException npe = new NullPointerException("null value");
- e = new AssertionError(npe);
- assertEquals(npe.toString(), e.getMessage());
- assertSame(npe, e.getCause());
- }
-
- public void test_ConstructorBoolean() {
- AssertionError e = new AssertionError(true);
- assertEquals("true", e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorChar() {
- AssertionError e = new AssertionError('a');
- assertEquals("a", e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorInt() {
- AssertionError e = new AssertionError(1);
- assertEquals("1", e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorLong() {
- AssertionError e = new AssertionError(1L);
- assertEquals("1", e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorFloat() {
- AssertionError e = new AssertionError(1.0F);
- assertEquals("1.0", e.getMessage());
- assertNull(e.getCause());
- }
-
- public void test_ConstructorDouble() {
- AssertionError e = new AssertionError(1.0D);
- assertEquals("1.0", e.getMessage());
- assertNull(e.getCause());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/BooleanTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/BooleanTest.java
deleted file mode 100644
index d6dbb64..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/BooleanTest.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class BooleanTest extends TestCase {
-
- /**
- * @tests java.lang.Boolean#hashCode()
- */
- public void test_hashCode() {
- assertEquals(1231, Boolean.TRUE.hashCode());
- assertEquals(1237, Boolean.FALSE.hashCode());
- }
-
- /**
- * @tests java.lang.Boolean#Boolean(String)
- */
- public void test_ConstructorLjava_lang_String() {
- assertEquals(Boolean.TRUE, new Boolean("TRUE"));
- assertEquals(Boolean.TRUE, new Boolean("true"));
- assertEquals(Boolean.TRUE, new Boolean("True"));
-
- assertEquals(Boolean.FALSE, new Boolean("yes"));
- assertEquals(Boolean.FALSE, new Boolean("false"));
- }
-
- /**
- * @tests java.lang.Boolean#Boolean(boolean)
- */
- public void test_ConstructorZ() {
- assertEquals(Boolean.TRUE, new Boolean(true));
- assertEquals(Boolean.FALSE, new Boolean(false));
- }
-
- /**
- * @tests java.lang.Boolean#booleanValue()
- */
- public void test_booleanValue() {
- assertTrue(Boolean.TRUE.booleanValue());
- assertFalse(Boolean.FALSE.booleanValue());
- }
-
- /**
- * @tests java.lang.Boolean#equals(Object)
- */
- public void test_equalsLjava_lang_Object() {
- assertTrue(Boolean.TRUE.equals(Boolean.TRUE));
- assertTrue(Boolean.TRUE.equals(new Boolean(true)));
- assertFalse(Boolean.TRUE.equals("true"));
- assertFalse(Boolean.TRUE.equals(null));
- assertFalse(Boolean.FALSE.equals(Boolean.TRUE));
- assertTrue(Boolean.FALSE.equals(Boolean.FALSE));
- assertTrue(Boolean.FALSE.equals(new Boolean(false)));
- }
-
- /**
- * @tests java.lang.Boolean#getBoolean(String)
- */
- public void test_getBooleanLjava_lang_String() {
- System.setProperty(getClass().getName(), "true");
- assertTrue(Boolean.getBoolean(getClass().getName()));
-
- System.setProperty(getClass().getName(), "TRUE");
- assertTrue(Boolean.getBoolean(getClass().getName()));
-
- System.setProperty(getClass().getName(), "false");
- assertFalse(Boolean.getBoolean(getClass().getName()));
- }
-
- /**
- * @tests java.lang.Boolean#toString()
- */
- public void test_toString() {
- assertEquals("true", Boolean.TRUE.toString());
- assertEquals("false", Boolean.FALSE.toString());
- }
-
- /**
- * @tests java.lang.Boolean#toString(boolean)
- */
- public void test_toStringZ() {
- assertEquals("true", Boolean.toString(true));
- assertEquals("false", Boolean.toString(false));
- }
-
- /**
- * @tests java.lang.Boolean#valueOf(String)
- */
- public void test_valueOfLjava_lang_String() {
- assertEquals(Boolean.TRUE, Boolean.valueOf("true"));
- assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
-
- assertEquals(Boolean.TRUE, Boolean.valueOf("TRUE"));
- assertEquals(Boolean.FALSE, Boolean.valueOf("false"));
-
- assertEquals(Boolean.FALSE, Boolean.valueOf(null));
- assertEquals(Boolean.FALSE, Boolean.valueOf(""));
- assertEquals(Boolean.FALSE, Boolean.valueOf("invalid"));
-
- assertTrue("Failed to parse true to true", Boolean.valueOf("true").booleanValue());
- assertTrue("Failed to parse mixed case true to true", Boolean.valueOf("TrUe")
- .booleanValue());
- assertTrue("parsed non-true to true", !Boolean.valueOf("ddddd").booleanValue());
- }
-
- /**
- * @tests java.lang.Boolean#valueOf(boolean)
- */
- public void test_valueOfZ() {
- assertEquals(Boolean.TRUE, Boolean.valueOf(true));
- assertEquals(Boolean.FALSE, Boolean.valueOf(false));
- }
-
- /**
- * @tests java.lang.Boolean#parseBoolean(String)
- */
- public void test_parseBooleanLjava_lang_String() {
- assertTrue(Boolean.parseBoolean("true"));
- assertTrue(Boolean.parseBoolean("TRUE"));
- assertFalse(Boolean.parseBoolean("false"));
- assertFalse(Boolean.parseBoolean(null));
- assertFalse(Boolean.parseBoolean(""));
- assertFalse(Boolean.parseBoolean("invalid"));
- }
-
- /**
- * @tests java.lang.Boolean#compareTo(Boolean)
- */
- public void test_compareToLjava_lang_Boolean() {
- assertTrue(Boolean.TRUE.compareTo(Boolean.TRUE) == 0);
- assertTrue(Boolean.FALSE.compareTo(Boolean.FALSE) == 0);
- assertTrue(Boolean.TRUE.compareTo(Boolean.FALSE) > 0);
- assertTrue(Boolean.FALSE.compareTo(Boolean.TRUE) < 0);
-
- try {
- Boolean.TRUE.compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java
deleted file mode 100644
index 3e14b2b..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ByteTest.java
+++ /dev/null
@@ -1,672 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ByteTest extends TestCase {
-
- /**
- * @tests java.lang.Byte#valueOf(byte)
- */
- public void test_valueOfB() {
- assertEquals(new Byte(Byte.MIN_VALUE), Byte.valueOf(Byte.MIN_VALUE));
- assertEquals(new Byte(Byte.MAX_VALUE), Byte.valueOf(Byte.MAX_VALUE));
- assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
-
- byte b = Byte.MIN_VALUE + 1;
- while (b < Byte.MAX_VALUE) {
- assertEquals(new Byte(b), Byte.valueOf(b));
- assertSame(Byte.valueOf(b), Byte.valueOf(b));
- b++;
- }
- }
-
- /**
- * @tests java.lang.Byte#hashCode()
- */
- public void test_hashCode() {
- assertEquals(1, new Byte((byte) 1).hashCode());
- assertEquals(2, new Byte((byte) 2).hashCode());
- assertEquals(0, new Byte((byte) 0).hashCode());
- assertEquals(-1, new Byte((byte) -1).hashCode());
- }
-
- /**
- * @tests java.lang.Byte#Byte(String)
- */
- public void test_ConstructorLjava_lang_String() {
- assertEquals(new Byte((byte) 0), new Byte("0"));
- assertEquals(new Byte((byte) 1), new Byte("1"));
- assertEquals(new Byte((byte) -1), new Byte("-1"));
-
- try {
- new Byte("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- new Byte("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- new Byte("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- new Byte(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#Byte(byte)
- */
- public void test_ConstructorB() {
- assertEquals(1, new Byte((byte) 1).byteValue());
- assertEquals(2, new Byte((byte) 2).byteValue());
- assertEquals(0, new Byte((byte) 0).byteValue());
- assertEquals(-1, new Byte((byte) -1).byteValue());
- }
-
- /**
- * @tests java.lang.Byte#byteValue()
- */
- public void test_booleanValue() {
- assertEquals(1, new Byte((byte) 1).byteValue());
- assertEquals(2, new Byte((byte) 2).byteValue());
- assertEquals(0, new Byte((byte) 0).byteValue());
- assertEquals(-1, new Byte((byte) -1).byteValue());
- }
-
- /**
- * @tests java.lang.Byte#equals(Object)
- */
- public void test_equalsLjava_lang_Object() {
- assertEquals(new Byte((byte) 0), Byte.valueOf((byte) 0));
- assertEquals(new Byte((byte) 1), Byte.valueOf((byte) 1));
- assertEquals(new Byte((byte) -1), Byte.valueOf((byte) -1));
-
- Byte fixture = new Byte((byte) 25);
- assertEquals(fixture, fixture);
- assertFalse(fixture.equals(null));
- assertFalse(fixture.equals("Not a Byte"));
- }
-
- /**
- * @tests java.lang.Byte#toString()
- */
- public void test_toString() {
- assertEquals("-1", new Byte((byte) -1).toString());
- assertEquals("0", new Byte((byte) 0).toString());
- assertEquals("1", new Byte((byte) 1).toString());
- assertEquals("-1", new Byte((byte) 0xFF).toString());
- }
-
- /**
- * @tests java.lang.Byte#toString(byte)
- */
- public void test_toStringB() {
- assertEquals("-1", Byte.toString((byte) -1));
- assertEquals("0", Byte.toString((byte) 0));
- assertEquals("1", Byte.toString((byte) 1));
- assertEquals("-1", Byte.toString((byte) 0xFF));
- }
-
- /**
- * @tests java.lang.Byte#valueOf(String)
- */
- public void test_valueOfLjava_lang_String() {
- assertEquals(new Byte((byte) 0), Byte.valueOf("0"));
- assertEquals(new Byte((byte) 1), Byte.valueOf("1"));
- assertEquals(new Byte((byte) -1), Byte.valueOf("-1"));
-
- try {
- Byte.valueOf("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#valueOf(String,int)
- */
- public void test_valueOfLjava_lang_StringI() {
- assertEquals(new Byte((byte) 0), Byte.valueOf("0", 10));
- assertEquals(new Byte((byte) 1), Byte.valueOf("1", 10));
- assertEquals(new Byte((byte) -1), Byte.valueOf("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Byte.valueOf("1", 2).byteValue());
- assertEquals(Character.digit('F', 16), Byte.valueOf("F", 16).byteValue());
-
- try {
- Byte.valueOf("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.valueOf(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#parseByte(String)
- */
- public void test_parseByteLjava_lang_String() {
- assertEquals(0, Byte.parseByte("0"));
- assertEquals(1, Byte.parseByte("1"));
- assertEquals(-1, Byte.parseByte("-1"));
-
- try {
- Byte.parseByte("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#parseByte(String,int)
- */
- public void test_parseByteLjava_lang_StringI() {
- assertEquals(0, Byte.parseByte("0", 10));
- assertEquals(1, Byte.parseByte("1", 10));
- assertEquals(-1, Byte.parseByte("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Byte.parseByte("1", 2));
- assertEquals(Character.digit('F', 16), Byte.parseByte("F", 16));
-
- try {
- Byte.parseByte("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#decode(String)
- */
- public void test_decodeLjava_lang_String() {
- assertEquals(new Byte((byte) 0), Byte.decode("0"));
- assertEquals(new Byte((byte) 1), Byte.decode("1"));
- assertEquals(new Byte((byte) -1), Byte.decode("-1"));
- assertEquals(new Byte((byte) 0xF), Byte.decode("0xF"));
- assertEquals(new Byte((byte) 0xF), Byte.decode("#F"));
- assertEquals(new Byte((byte) 0xF), Byte.decode("0XF"));
- assertEquals(new Byte((byte) 07), Byte.decode("07"));
-
- try {
- Byte.decode("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.decode("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.decode(null);
- //undocumented NPE, but seems consistent across JREs
- fail("Expected NullPointerException with null string.");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#doubleValue()
- */
- public void test_doubleValue() {
- assertEquals(-1D, new Byte((byte) -1).doubleValue(), 0D);
- assertEquals(0D, new Byte((byte) 0).doubleValue(), 0D);
- assertEquals(1D, new Byte((byte) 1).doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Byte#floatValue()
- */
- public void test_floatValue() {
- assertEquals(-1F, new Byte((byte) -1).floatValue(), 0F);
- assertEquals(0F, new Byte((byte) 0).floatValue(), 0F);
- assertEquals(1F, new Byte((byte) 1).floatValue(), 0F);
- }
-
- /**
- * @tests java.lang.Byte#intValue()
- */
- public void test_intValue() {
- assertEquals(-1, new Byte((byte) -1).intValue());
- assertEquals(0, new Byte((byte) 0).intValue());
- assertEquals(1, new Byte((byte) 1).intValue());
- }
-
- /**
- * @tests java.lang.Byte#longValue()
- */
- public void test_longValue() {
- assertEquals(-1L, new Byte((byte) -1).longValue());
- assertEquals(0L, new Byte((byte) 0).longValue());
- assertEquals(1L, new Byte((byte) 1).longValue());
- }
-
- /**
- * @tests java.lang.Byte#shortValue()
- */
- public void test_shortValue() {
- assertEquals(-1, new Byte((byte) -1).shortValue());
- assertEquals(0, new Byte((byte) 0).shortValue());
- assertEquals(1, new Byte((byte) 1).shortValue());
- }
-
- /**
- * @tests java.lang.Byte#compareTo(Byte)
- */
- public void test_compareToLjava_lang_Byte() {
- final Byte min = new Byte(Byte.MIN_VALUE);
- final Byte zero = new Byte((byte) 0);
- final Byte max = new Byte(Byte.MAX_VALUE);
-
- assertTrue(max.compareTo(max) == 0);
- assertTrue(min.compareTo(min) == 0);
- assertTrue(zero.compareTo(zero) == 0);
-
- assertTrue(max.compareTo(zero) > 0);
- assertTrue(max.compareTo(min) > 0);
-
- assertTrue(zero.compareTo(max) < 0);
- assertTrue(zero.compareTo(min) > 0);
-
- assertTrue(min.compareTo(zero) < 0);
- assertTrue(min.compareTo(max) < 0);
-
- try {
- min.compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#Byte(byte)
- */
- public void test_ConstructorB2() {
- // Test for method java.lang.Byte(byte)
-
- Byte b = new Byte((byte) 127);
- assertTrue("Byte creation failed", b.byteValue() == (byte) 127);
- }
-
- /**
- * @tests java.lang.Byte#Byte(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String2() {
- // Test for method java.lang.Byte(java.lang.String)
-
- Byte b = new Byte("127");
- Byte nb = new Byte("-128");
- assertTrue("Incorrect Byte Object created", b.byteValue() == (byte) 127
- && (nb.byteValue() == (byte) -128));
-
- }
-
- /**
- * @tests java.lang.Byte#byteValue()
- */
- public void test_byteValue() {
- // Test for method byte java.lang.Byte.byteValue()
- assertTrue("Returned incorrect byte value",
- new Byte((byte) 127).byteValue() == (byte) (127));
- }
-
- /**
- * @tests java.lang.Byte#compareTo(java.lang.Byte)
- */
- public void test_compareToLjava_lang_Byte2() {
- // Test for method int java.lang.Byte.compareTo(java.lang.Byte)
- assertTrue("Comparison failed", new Byte((byte) 1).compareTo(new Byte((byte) 2)) < 0);
- assertTrue("Comparison failed", new Byte((byte) 1).compareTo(new Byte((byte) -2)) > 0);
- assertEquals("Comparison failed", 0, new Byte((byte) 1).compareTo(new Byte((byte) 1)));
- }
-
- /**
- * @tests java.lang.Byte#decode(java.lang.String)
- */
- public void test_decodeLjava_lang_String2() {
- // Test for method java.lang.Byte
- // java.lang.Byte.decode(java.lang.String)
- assertTrue("String decoded incorrectly, wanted: 1 got: " + Byte.decode("1").toString(),
- Byte.decode("1").equals(new Byte((byte) 1)));
- assertTrue("String decoded incorrectly, wanted: -1 got: "
- + Byte.decode("-1").toString(), Byte.decode("-1").equals(new Byte((byte) -1)));
- assertTrue("String decoded incorrectly, wanted: 127 got: "
- + Byte.decode("127").toString(), Byte.decode("127")
- .equals(new Byte((byte) 127)));
- assertTrue("String decoded incorrectly, wanted: -128 got: "
- + Byte.decode("-128").toString(), Byte.decode("-128").equals(
- new Byte((byte) -128)));
- assertTrue("String decoded incorrectly, wanted: 127 got: "
- + Byte.decode("0x7f").toString(), Byte.decode("0x7f").equals(
- new Byte((byte) 127)));
- assertTrue("String decoded incorrectly, wanted: -128 got: "
- + Byte.decode("-0x80").toString(), Byte.decode("-0x80").equals(
- new Byte((byte) -128)));
-
- boolean exception = false;
- try {
- Byte.decode("128");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Byte.decode("-129");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Byte.decode("0x80");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Byte.decode("-0x81");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Byte#doubleValue()
- */
- public void test_doubleValue2() {
- assertEquals(127D, new Byte((byte) 127).doubleValue(), 0.0);
- }
-
- /**
- * @tests java.lang.Byte#equals(java.lang.Object)
- */
- public void test_equalsLjava_lang_Object2() {
- // Test for method boolean java.lang.Byte.equals(java.lang.Object)
- Byte b1 = new Byte((byte) 90);
- Byte b2 = new Byte((byte) 90);
- Byte b3 = new Byte((byte) -90);
- assertTrue("Equality test failed", b1.equals(b2));
- assertTrue("Equality test failed", !b1.equals(b3));
- }
-
- /**
- * @tests java.lang.Byte#floatValue()
- */
- public void test_floatValue2() {
- assertEquals(127F, new Byte((byte) 127).floatValue(), 0.0);
- }
-
- /**
- * @tests java.lang.Byte#hashCode()
- */
- public void test_hashCode2() {
- // Test for method int java.lang.Byte.hashCode()
- assertEquals("Incorrect hash returned", 127, new Byte((byte) 127).hashCode());
- }
-
- /**
- * @tests java.lang.Byte#intValue()
- */
- public void test_intValue2() {
- // Test for method int java.lang.Byte.intValue()
- assertEquals("Returned incorrect int value", 127, new Byte((byte) 127).intValue());
- }
-
- /**
- * @tests java.lang.Byte#longValue()
- */
- public void test_longValue2() {
- // Test for method long java.lang.Byte.longValue()
- assertEquals("Returned incorrect long value", 127L, new Byte((byte) 127).longValue());
- }
-
- /**
- * @tests java.lang.Byte#parseByte(java.lang.String)
- */
- public void test_parseByteLjava_lang_String2() {
- assertEquals((byte)127, Byte.parseByte("127"));
- assertEquals((byte)-128, Byte.parseByte("-128"));
- assertEquals((byte)0, Byte.parseByte("0"));
- assertEquals((byte)0x80, Byte.parseByte("-128"));
- assertEquals((byte)0x7F, Byte.parseByte("127"));
-
- try {
- Byte.parseByte("-1000");
- fail("No NumberFormatException");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("128");
- fail("No NumberFormatException");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("-129");
- fail("No NumberFormatException");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#parseByte(java.lang.String, int)
- */
- public void test_parseByteLjava_lang_StringI2() {
- // Test for method byte java.lang.Byte.parseByte(java.lang.String, int)
- byte b = Byte.parseByte("127", 10);
- byte bn = Byte.parseByte("-128", 10);
- assertTrue("Invalid parse of dec byte", b == (byte) 127 && (bn == (byte) -128));
- assertEquals("Failed to parse hex value", 10, Byte.parseByte("A", 16));
- assertEquals("Returned incorrect value for 0 hex", 0, Byte.parseByte("0", 16));
- assertTrue("Returned incorrect value for most negative value hex", Byte.parseByte(
- "-80", 16) == (byte) 0x80);
- assertTrue("Returned incorrect value for most positive value hex", Byte.parseByte("7f",
- 16) == 0x7f);
- assertEquals("Returned incorrect value for 0 decimal", 0, Byte.parseByte("0", 10));
- assertTrue("Returned incorrect value for most negative value decimal", Byte.parseByte(
- "-128", 10) == (byte) 0x80);
- assertTrue("Returned incorrect value for most positive value decimal", Byte.parseByte(
- "127", 10) == 0x7f);
-
- try {
- Byte.parseByte("-1000", 10);
- fail("Failed to throw exception");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("128", 10);
- fail("Failed to throw exception for MAX_VALUE + 1");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("-129", 10);
- fail("Failed to throw exception for MIN_VALUE - 1");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("80", 16);
- fail("Failed to throw exception for hex MAX_VALUE + 1");
- } catch (NumberFormatException e) {
- }
-
- try {
- Byte.parseByte("-81", 16);
- fail("Failed to throw exception for hex MIN_VALUE + 1");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#shortValue()
- */
- public void test_shortValue2() {
- assertEquals((short)127, new Byte((byte)127).shortValue());
- }
-
- /**
- * @tests java.lang.Byte#toString()
- */
- public void test_toString2() {
- assertEquals("Returned incorrect String", "127", new Byte((byte) 127).toString());
- assertEquals("Returned incorrect String", "-127", new Byte((byte) -127).toString());
- assertEquals("Returned incorrect String", "-128", new Byte((byte) -128).toString());
- }
-
- /**
- * @tests java.lang.Byte#toString(byte)
- */
- public void test_toStringB2() {
- assertEquals("Returned incorrect String", "127", Byte.toString((byte) 127));
- assertEquals("Returned incorrect String", "-127", Byte.toString((byte) -127));
- assertEquals("Returned incorrect String", "-128", Byte.toString((byte) -128));
- }
-
- /**
- * @tests java.lang.Byte#valueOf(java.lang.String)
- */
- public void test_valueOfLjava_lang_String2() {
- assertEquals("Returned incorrect byte", 0, Byte.valueOf("0").byteValue());
- assertEquals("Returned incorrect byte", 127, Byte.valueOf("127").byteValue());
- assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127").byteValue());
- assertEquals("Returned incorrect byte", -128, Byte.valueOf("-128").byteValue());
-
- try {
- Byte.valueOf("128");
- fail("Failed to throw exception when passes value > byte");
- } catch (NumberFormatException e) {
- }
- }
-
- /**
- * @tests java.lang.Byte#valueOf(java.lang.String, int)
- */
- public void test_valueOfLjava_lang_StringI2() {
- assertEquals("Returned incorrect byte", 10, Byte.valueOf("A", 16).byteValue());
- assertEquals("Returned incorrect byte", 127, Byte.valueOf("127", 10).byteValue());
- assertEquals("Returned incorrect byte", -127, Byte.valueOf("-127", 10).byteValue());
- assertEquals("Returned incorrect byte", -128, Byte.valueOf("-128", 10).byteValue());
- assertEquals("Returned incorrect byte", 127, Byte.valueOf("7f", 16).byteValue());
- assertEquals("Returned incorrect byte", -127, Byte.valueOf("-7f", 16).byteValue());
- assertEquals("Returned incorrect byte", -128, Byte.valueOf("-80", 16).byteValue());
-
- try {
- Byte.valueOf("128", 10);
- fail("Failed to throw exception when passes value > byte");
- } catch (NumberFormatException e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_SubsetTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_SubsetTest.java
deleted file mode 100644
index 6845396..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_SubsetTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(Character.Subset.class)
-public class Character_SubsetTest extends TestCase {
-
- /**
- * @tests java.lang.Character.Subset#Character.Subset(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Subset",
- args = {java.lang.String.class}
- )
- public void test_Ctor() {
-
- try {
- // Regression for HARMONY-888
- new Character.Subset(null) {
- };
- fail("No expected NullPointerException");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Character.Subset#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
-
- String name = "name";
- Character.Subset subset = new Character.Subset(name) {
- };
- assertSame(name, subset.toString());
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equals() {
- Character.Subset subset1 = new Character.Subset("name") { };
- assertTrue(subset1.equals(subset1));
- assertFalse(subset1.equals(new Character.Subset("name") {}));
- assertFalse(subset1.equals(new Character.Subset("name1") {}));
- assertFalse(subset1.equals(new Integer(0)));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- Character.Subset subset1 = new Character.Subset("name") {};
- Character.Subset subset2 = new Character.Subset("name") {};
- Character.Subset subset3 = new Character.Subset("name1") {};
- assertFalse(subset1.hashCode() == subset2.hashCode());
- assertFalse(subset1.hashCode() == subset3.hashCode());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_UnicodeBlockTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_UnicodeBlockTest.java
deleted file mode 100644
index fa6bc9f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/Character_UnicodeBlockTest.java
+++ /dev/null
@@ -1,879 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class Character_UnicodeBlockTest extends TestCase {
-
- public void test_ofC() {
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.of((char)0x0));
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.of((char)0x7f));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.of((char)0x80));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.of((char)0xff));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.of((char)0x100));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.of((char)0x17f));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.of((char)0x180));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.of((char)0x24f));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.of((char)0x250));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.of((char)0x2af));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.of((char)0x2b0));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.of((char)0x2ff));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.of((char)0x300));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.of((char)0x36f));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.of((char)0x370));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.of((char)0x3ff));
- assertEquals(Character.UnicodeBlock.CYRILLIC, Character.UnicodeBlock.of((char)0x400));
- assertEquals(Character.UnicodeBlock.CYRILLIC, Character.UnicodeBlock.of((char)0x4ff));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.of((char)0x500));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.of((char)0x52f));
- assertEquals(Character.UnicodeBlock.ARMENIAN, Character.UnicodeBlock.of((char)0x530));
- assertEquals(Character.UnicodeBlock.ARMENIAN, Character.UnicodeBlock.of((char)0x58f));
- assertEquals(Character.UnicodeBlock.HEBREW, Character.UnicodeBlock.of((char)0x590));
- assertEquals(Character.UnicodeBlock.HEBREW, Character.UnicodeBlock.of((char)0x5ff));
- assertEquals(Character.UnicodeBlock.ARABIC, Character.UnicodeBlock.of((char)0x600));
- assertEquals(Character.UnicodeBlock.ARABIC, Character.UnicodeBlock.of((char)0x6ff));
- assertEquals(Character.UnicodeBlock.SYRIAC, Character.UnicodeBlock.of((char)0x700));
- assertEquals(Character.UnicodeBlock.SYRIAC, Character.UnicodeBlock.of((char)0x74f));
- assertNull(Character.UnicodeBlock.of((char)0x750));
- assertNull(Character.UnicodeBlock.of((char)0x77f));
- assertEquals(Character.UnicodeBlock.THAANA, Character.UnicodeBlock.of((char)0x780));
- assertEquals(Character.UnicodeBlock.THAANA, Character.UnicodeBlock.of((char)0x7bf));
- assertNull(Character.UnicodeBlock.of((char)0x7c0));
- assertNull(Character.UnicodeBlock.of((char)0x8ff));
- assertEquals(Character.UnicodeBlock.DEVANAGARI, Character.UnicodeBlock.of((char)0x900));
- assertEquals(Character.UnicodeBlock.DEVANAGARI, Character.UnicodeBlock.of((char)0x97f));
- assertEquals(Character.UnicodeBlock.BENGALI, Character.UnicodeBlock.of((char)0x980));
- assertEquals(Character.UnicodeBlock.BENGALI, Character.UnicodeBlock.of((char)0x9ff));
- assertEquals(Character.UnicodeBlock.GURMUKHI, Character.UnicodeBlock.of((char)0xa00));
- assertEquals(Character.UnicodeBlock.GURMUKHI, Character.UnicodeBlock.of((char)0xa7f));
- assertEquals(Character.UnicodeBlock.GUJARATI, Character.UnicodeBlock.of((char)0xa80));
- assertEquals(Character.UnicodeBlock.GUJARATI, Character.UnicodeBlock.of((char)0xaff));
- assertEquals(Character.UnicodeBlock.ORIYA, Character.UnicodeBlock.of((char)0xb00));
- assertEquals(Character.UnicodeBlock.ORIYA, Character.UnicodeBlock.of((char)0xb7f));
- assertEquals(Character.UnicodeBlock.TAMIL, Character.UnicodeBlock.of((char)0xb80));
- assertEquals(Character.UnicodeBlock.TAMIL, Character.UnicodeBlock.of((char)0xbff));
- assertEquals(Character.UnicodeBlock.TELUGU, Character.UnicodeBlock.of((char)0xc00));
- assertEquals(Character.UnicodeBlock.TELUGU, Character.UnicodeBlock.of((char)0xc7f));
- assertEquals(Character.UnicodeBlock.KANNADA, Character.UnicodeBlock.of((char)0xc80));
- assertEquals(Character.UnicodeBlock.KANNADA, Character.UnicodeBlock.of((char)0xcff));
- assertEquals(Character.UnicodeBlock.MALAYALAM, Character.UnicodeBlock.of((char)0xd00));
- assertEquals(Character.UnicodeBlock.MALAYALAM, Character.UnicodeBlock.of((char)0xd7f));
- assertEquals(Character.UnicodeBlock.SINHALA, Character.UnicodeBlock.of((char)0xd80));
- assertEquals(Character.UnicodeBlock.SINHALA, Character.UnicodeBlock.of((char)0xdff));
- assertEquals(Character.UnicodeBlock.THAI, Character.UnicodeBlock.of((char)0xe00));
- assertEquals(Character.UnicodeBlock.THAI, Character.UnicodeBlock.of((char)0xe7f));
- assertEquals(Character.UnicodeBlock.LAO, Character.UnicodeBlock.of((char)0xe80));
- assertEquals(Character.UnicodeBlock.LAO, Character.UnicodeBlock.of((char)0xeff));
- assertEquals(Character.UnicodeBlock.TIBETAN, Character.UnicodeBlock.of((char)0xf00));
- assertEquals(Character.UnicodeBlock.TIBETAN, Character.UnicodeBlock.of((char)0xfff));
- assertEquals(Character.UnicodeBlock.MYANMAR, Character.UnicodeBlock.of((char)0x1000));
- assertEquals(Character.UnicodeBlock.MYANMAR, Character.UnicodeBlock.of((char)0x109f));
- assertEquals(Character.UnicodeBlock.GEORGIAN, Character.UnicodeBlock.of((char)0x10a0));
- assertEquals(Character.UnicodeBlock.GEORGIAN, Character.UnicodeBlock.of((char)0x10ff));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.of((char)0x1100));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.of((char)0x11ff));
- assertEquals(Character.UnicodeBlock.ETHIOPIC, Character.UnicodeBlock.of((char)0x1200));
- assertEquals(Character.UnicodeBlock.ETHIOPIC, Character.UnicodeBlock.of((char)0x137f));
- assertNull(Character.UnicodeBlock.of((char)0x1380));
- assertNull(Character.UnicodeBlock.of((char)0x139f));
- assertEquals(Character.UnicodeBlock.CHEROKEE, Character.UnicodeBlock.of((char)0x13a0));
- assertEquals(Character.UnicodeBlock.CHEROKEE, Character.UnicodeBlock.of((char)0x13ff));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.of((char)0x1400));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.of((char)0x167f));
- assertEquals(Character.UnicodeBlock.OGHAM, Character.UnicodeBlock.of((char)0x1680));
- assertEquals(Character.UnicodeBlock.OGHAM, Character.UnicodeBlock.of((char)0x169f));
- assertEquals(Character.UnicodeBlock.RUNIC, Character.UnicodeBlock.of((char)0x16a0));
- assertEquals(Character.UnicodeBlock.RUNIC, Character.UnicodeBlock.of((char)0x16ff));
- assertEquals(Character.UnicodeBlock.TAGALOG, Character.UnicodeBlock.of((char)0x1700));
- assertEquals(Character.UnicodeBlock.TAGALOG, Character.UnicodeBlock.of((char)0x171f));
- assertEquals(Character.UnicodeBlock.HANUNOO, Character.UnicodeBlock.of((char)0x1720));
- assertEquals(Character.UnicodeBlock.HANUNOO, Character.UnicodeBlock.of((char)0x173f));
- assertEquals(Character.UnicodeBlock.BUHID, Character.UnicodeBlock.of((char)0x1740));
- assertEquals(Character.UnicodeBlock.BUHID, Character.UnicodeBlock.of((char)0x175f));
- assertEquals(Character.UnicodeBlock.TAGBANWA, Character.UnicodeBlock.of((char)0x1760));
- assertEquals(Character.UnicodeBlock.TAGBANWA, Character.UnicodeBlock.of((char)0x177f));
- assertEquals(Character.UnicodeBlock.KHMER, Character.UnicodeBlock.of((char)0x1780));
- assertEquals(Character.UnicodeBlock.KHMER, Character.UnicodeBlock.of((char)0x17ff));
- assertEquals(Character.UnicodeBlock.MONGOLIAN, Character.UnicodeBlock.of((char)0x1800));
- assertEquals(Character.UnicodeBlock.MONGOLIAN, Character.UnicodeBlock.of((char)0x18af));
- assertNull(Character.UnicodeBlock.of((char)0x18b0));
- assertNull(Character.UnicodeBlock.of((char)0x18ff));
- assertEquals(Character.UnicodeBlock.LIMBU, Character.UnicodeBlock.of((char)0x1900));
- assertEquals(Character.UnicodeBlock.LIMBU, Character.UnicodeBlock.of((char)0x194f));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.of((char)0x1950));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.of((char)0x197f));
- assertNull(Character.UnicodeBlock.of((char)0x1980));
- assertNull(Character.UnicodeBlock.of((char)0x19df));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.of((char)0x19e0));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.of((char)0x19ff));
- assertNull(Character.UnicodeBlock.of((char)0x1a00));
- assertNull(Character.UnicodeBlock.of((char)0x1cff));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.of((char)0x1d00));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.of((char)0x1d7f));
- assertNull(Character.UnicodeBlock.of((char)0x1d80));
- assertNull(Character.UnicodeBlock.of((char)0x1dff));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.of((char)0x1e00));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.of((char)0x1eff));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.of((char)0x1f00));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.of((char)0x1fff));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.of((char)0x2000));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.of((char)0x206f));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.of((char)0x2070));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.of((char)0x209f));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.of((char)0x20a0));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.of((char)0x20cf));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.of((char)0x20d0));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.of((char)0x20ff));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.of((char)0x2100));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.of((char)0x214f));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.of((char)0x2150));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.of((char)0x218f));
- assertEquals(Character.UnicodeBlock.ARROWS, Character.UnicodeBlock.of((char)0x2190));
- assertEquals(Character.UnicodeBlock.ARROWS, Character.UnicodeBlock.of((char)0x21ff));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of((char)0x2200));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of((char)0x22ff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.of((char)0x2300));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.of((char)0x23ff));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.of((char)0x2400));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.of((char)0x243f));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.of((char)0x2440));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.of((char)0x245f));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.of((char)0x2460));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.of((char)0x24ff));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.of((char)0x2500));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.of((char)0x257f));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.of((char)0x2580));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.of((char)0x259f));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.of((char)0x25a0));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.of((char)0x25ff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.of((char)0x2600));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.of((char)0x26ff));
- assertEquals(Character.UnicodeBlock.DINGBATS, Character.UnicodeBlock.of((char)0x2700));
- assertEquals(Character.UnicodeBlock.DINGBATS, Character.UnicodeBlock.of((char)0x27bf));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.of((char)0x27c0));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.of((char)0x27ef));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.of((char)0x27f0));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.of((char)0x27ff));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.of((char)0x2800));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.of((char)0x28ff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.of((char)0x2900));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.of((char)0x297f));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.of((char)0x2980));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.of((char)0x29ff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of((char)0x2a00));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of((char)0x2aff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.of((char)0x2b00));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.of((char)0x2bff));
- assertNull(Character.UnicodeBlock.of((char)0x2c00));
- assertNull(Character.UnicodeBlock.of((char)0x2e7f));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.of((char)0x2e80));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.of((char)0x2eff));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.of((char)0x2f00));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.of((char)0x2fdf));
- assertNull(Character.UnicodeBlock.of((char)0x2fe0));
- assertNull(Character.UnicodeBlock.of((char)0x2fef));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.of((char)0x2ff0));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.of((char)0x2fff));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.of((char)0x3000));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.of((char)0x303f));
- assertEquals(Character.UnicodeBlock.HIRAGANA, Character.UnicodeBlock.of((char)0x3040));
- assertEquals(Character.UnicodeBlock.HIRAGANA, Character.UnicodeBlock.of((char)0x309f));
- assertEquals(Character.UnicodeBlock.KATAKANA, Character.UnicodeBlock.of((char)0x30a0));
- assertEquals(Character.UnicodeBlock.KATAKANA, Character.UnicodeBlock.of((char)0x30ff));
- assertEquals(Character.UnicodeBlock.BOPOMOFO, Character.UnicodeBlock.of((char)0x3100));
- assertEquals(Character.UnicodeBlock.BOPOMOFO, Character.UnicodeBlock.of((char)0x312f));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.of((char)0x3130));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.of((char)0x318f));
- assertEquals(Character.UnicodeBlock.KANBUN, Character.UnicodeBlock.of((char)0x3190));
- assertEquals(Character.UnicodeBlock.KANBUN, Character.UnicodeBlock.of((char)0x319f));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.of((char)0x31a0));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.of((char)0x31bf));
- assertNull(Character.UnicodeBlock.of((char)0x31c0));
- assertNull(Character.UnicodeBlock.of((char)0x31ef));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.of((char)0x31f0));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.of((char)0x31ff));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.of((char)0x3200));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.of((char)0x32ff));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.of((char)0x3300));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.of((char)0x33ff));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.of((char)0x3400));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.of((char)0x4dbf));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.of((char)0x4dc0));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.of((char)0x4dff));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.of((char)0x4e00));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.of((char)0x9fff));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.of((char)0xa000));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.of((char)0xa48f));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.of((char)0xa490));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.of((char)0xa4cf));
- assertNull(Character.UnicodeBlock.of((char)0xa4d0));
- assertNull(Character.UnicodeBlock.of((char)0xabff));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.of((char)0xac00));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.of((char)0xd7af));
- assertNull(Character.UnicodeBlock.of((char)0xd7b0));
- assertNull(Character.UnicodeBlock.of((char)0xd7ff));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.of((char)0xd800));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.of((char)0xdb7f));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.of((char)0xdb80));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.of((char)0xdbff));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.of((char)0xdc00));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.of((char)0xdfff));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.of((char)0xe000));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.of((char)0xf8ff));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.of((char)0xf900));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.of((char)0xfaff));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.of((char)0xfb00));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.of((char)0xfb4f));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.of((char)0xfb50));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.of((char)0xfdff));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.of((char)0xfe00));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.of((char)0xfe0f));
- assertNull(Character.UnicodeBlock.of((char)0xfe10));
- assertNull(Character.UnicodeBlock.of((char)0xfe1f));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.of((char)0xfe20));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.of((char)0xfe2f));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.of((char)0xfe30));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.of((char)0xfe4f));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.of((char)0xfe50));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.of((char)0xfe6f));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.of((char)0xfe70));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.of((char)0xfeff));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.of((char)0xff00));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.of((char)0xffef));
- assertEquals(Character.UnicodeBlock.SPECIALS, Character.UnicodeBlock.of((char)0xfff0));
- assertEquals(Character.UnicodeBlock.SPECIALS, Character.UnicodeBlock.of((char)0xffff));
- }
- public void test_ofI() {
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.of(0x0));
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.of(0x7f));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.of(0x80));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.of(0xff));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.of(0x100));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.of(0x17f));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.of(0x180));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.of(0x24f));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.of(0x250));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.of(0x2af));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.of(0x2b0));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.of(0x2ff));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.of(0x300));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.of(0x36f));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.of(0x370));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.of(0x3ff));
- assertEquals(Character.UnicodeBlock.CYRILLIC, Character.UnicodeBlock.of(0x400));
- assertEquals(Character.UnicodeBlock.CYRILLIC, Character.UnicodeBlock.of(0x4ff));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.of(0x500));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.of(0x52f));
- assertEquals(Character.UnicodeBlock.ARMENIAN, Character.UnicodeBlock.of(0x530));
- assertEquals(Character.UnicodeBlock.ARMENIAN, Character.UnicodeBlock.of(0x58f));
- assertEquals(Character.UnicodeBlock.HEBREW, Character.UnicodeBlock.of(0x590));
- assertEquals(Character.UnicodeBlock.HEBREW, Character.UnicodeBlock.of(0x5ff));
- assertEquals(Character.UnicodeBlock.ARABIC, Character.UnicodeBlock.of(0x600));
- assertEquals(Character.UnicodeBlock.ARABIC, Character.UnicodeBlock.of(0x6ff));
- assertEquals(Character.UnicodeBlock.SYRIAC, Character.UnicodeBlock.of(0x700));
- assertEquals(Character.UnicodeBlock.SYRIAC, Character.UnicodeBlock.of(0x74f));
- assertNull(Character.UnicodeBlock.of(0x750));
- assertNull(Character.UnicodeBlock.of(0x77f));
- assertEquals(Character.UnicodeBlock.THAANA, Character.UnicodeBlock.of(0x780));
- assertEquals(Character.UnicodeBlock.THAANA, Character.UnicodeBlock.of(0x7bf));
- assertNull(Character.UnicodeBlock.of(0x7c0));
- assertNull(Character.UnicodeBlock.of(0x8ff));
- assertEquals(Character.UnicodeBlock.DEVANAGARI, Character.UnicodeBlock.of(0x900));
- assertEquals(Character.UnicodeBlock.DEVANAGARI, Character.UnicodeBlock.of(0x97f));
- assertEquals(Character.UnicodeBlock.BENGALI, Character.UnicodeBlock.of(0x980));
- assertEquals(Character.UnicodeBlock.BENGALI, Character.UnicodeBlock.of(0x9ff));
- assertEquals(Character.UnicodeBlock.GURMUKHI, Character.UnicodeBlock.of(0xa00));
- assertEquals(Character.UnicodeBlock.GURMUKHI, Character.UnicodeBlock.of(0xa7f));
- assertEquals(Character.UnicodeBlock.GUJARATI, Character.UnicodeBlock.of(0xa80));
- assertEquals(Character.UnicodeBlock.GUJARATI, Character.UnicodeBlock.of(0xaff));
- assertEquals(Character.UnicodeBlock.ORIYA, Character.UnicodeBlock.of(0xb00));
- assertEquals(Character.UnicodeBlock.ORIYA, Character.UnicodeBlock.of(0xb7f));
- assertEquals(Character.UnicodeBlock.TAMIL, Character.UnicodeBlock.of(0xb80));
- assertEquals(Character.UnicodeBlock.TAMIL, Character.UnicodeBlock.of(0xbff));
- assertEquals(Character.UnicodeBlock.TELUGU, Character.UnicodeBlock.of(0xc00));
- assertEquals(Character.UnicodeBlock.TELUGU, Character.UnicodeBlock.of(0xc7f));
- assertEquals(Character.UnicodeBlock.KANNADA, Character.UnicodeBlock.of(0xc80));
- assertEquals(Character.UnicodeBlock.KANNADA, Character.UnicodeBlock.of(0xcff));
- assertEquals(Character.UnicodeBlock.MALAYALAM, Character.UnicodeBlock.of(0xd00));
- assertEquals(Character.UnicodeBlock.MALAYALAM, Character.UnicodeBlock.of(0xd7f));
- assertEquals(Character.UnicodeBlock.SINHALA, Character.UnicodeBlock.of(0xd80));
- assertEquals(Character.UnicodeBlock.SINHALA, Character.UnicodeBlock.of(0xdff));
- assertEquals(Character.UnicodeBlock.THAI, Character.UnicodeBlock.of(0xe00));
- assertEquals(Character.UnicodeBlock.THAI, Character.UnicodeBlock.of(0xe7f));
- assertEquals(Character.UnicodeBlock.LAO, Character.UnicodeBlock.of(0xe80));
- assertEquals(Character.UnicodeBlock.LAO, Character.UnicodeBlock.of(0xeff));
- assertEquals(Character.UnicodeBlock.TIBETAN, Character.UnicodeBlock.of(0xf00));
- assertEquals(Character.UnicodeBlock.TIBETAN, Character.UnicodeBlock.of(0xfff));
- assertEquals(Character.UnicodeBlock.MYANMAR, Character.UnicodeBlock.of(0x1000));
- assertEquals(Character.UnicodeBlock.MYANMAR, Character.UnicodeBlock.of(0x109f));
- assertEquals(Character.UnicodeBlock.GEORGIAN, Character.UnicodeBlock.of(0x10a0));
- assertEquals(Character.UnicodeBlock.GEORGIAN, Character.UnicodeBlock.of(0x10ff));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.of(0x1100));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.of(0x11ff));
- assertEquals(Character.UnicodeBlock.ETHIOPIC, Character.UnicodeBlock.of(0x1200));
- assertEquals(Character.UnicodeBlock.ETHIOPIC, Character.UnicodeBlock.of(0x137f));
- assertNull(Character.UnicodeBlock.of(0x1380));
- assertNull(Character.UnicodeBlock.of(0x139f));
- assertEquals(Character.UnicodeBlock.CHEROKEE, Character.UnicodeBlock.of(0x13a0));
- assertEquals(Character.UnicodeBlock.CHEROKEE, Character.UnicodeBlock.of(0x13ff));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.of(0x1400));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.of(0x167f));
- assertEquals(Character.UnicodeBlock.OGHAM, Character.UnicodeBlock.of(0x1680));
- assertEquals(Character.UnicodeBlock.OGHAM, Character.UnicodeBlock.of(0x169f));
- assertEquals(Character.UnicodeBlock.RUNIC, Character.UnicodeBlock.of(0x16a0));
- assertEquals(Character.UnicodeBlock.RUNIC, Character.UnicodeBlock.of(0x16ff));
- assertEquals(Character.UnicodeBlock.TAGALOG, Character.UnicodeBlock.of(0x1700));
- assertEquals(Character.UnicodeBlock.TAGALOG, Character.UnicodeBlock.of(0x171f));
- assertEquals(Character.UnicodeBlock.HANUNOO, Character.UnicodeBlock.of(0x1720));
- assertEquals(Character.UnicodeBlock.HANUNOO, Character.UnicodeBlock.of(0x173f));
- assertEquals(Character.UnicodeBlock.BUHID, Character.UnicodeBlock.of(0x1740));
- assertEquals(Character.UnicodeBlock.BUHID, Character.UnicodeBlock.of(0x175f));
- assertEquals(Character.UnicodeBlock.TAGBANWA, Character.UnicodeBlock.of(0x1760));
- assertEquals(Character.UnicodeBlock.TAGBANWA, Character.UnicodeBlock.of(0x177f));
- assertEquals(Character.UnicodeBlock.KHMER, Character.UnicodeBlock.of(0x1780));
- assertEquals(Character.UnicodeBlock.KHMER, Character.UnicodeBlock.of(0x17ff));
- assertEquals(Character.UnicodeBlock.MONGOLIAN, Character.UnicodeBlock.of(0x1800));
- assertEquals(Character.UnicodeBlock.MONGOLIAN, Character.UnicodeBlock.of(0x18af));
- assertNull(Character.UnicodeBlock.of(0x18b0));
- assertNull(Character.UnicodeBlock.of(0x18ff));
- assertEquals(Character.UnicodeBlock.LIMBU, Character.UnicodeBlock.of(0x1900));
- assertEquals(Character.UnicodeBlock.LIMBU, Character.UnicodeBlock.of(0x194f));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.of(0x1950));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.of(0x197f));
- assertNull(Character.UnicodeBlock.of(0x1980));
- assertNull(Character.UnicodeBlock.of(0x19df));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.of(0x19e0));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.of(0x19ff));
- assertNull(Character.UnicodeBlock.of(0x1a00));
- assertNull(Character.UnicodeBlock.of(0x1cff));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.of(0x1d00));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.of(0x1d7f));
- assertNull(Character.UnicodeBlock.of(0x1d80));
- assertNull(Character.UnicodeBlock.of(0x1dff));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.of(0x1e00));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.of(0x1eff));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.of(0x1f00));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.of(0x1fff));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.of(0x2000));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.of(0x206f));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.of(0x2070));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.of(0x209f));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.of(0x20a0));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.of(0x20cf));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.of(0x20d0));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.of(0x20ff));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.of(0x2100));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.of(0x214f));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.of(0x2150));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.of(0x218f));
- assertEquals(Character.UnicodeBlock.ARROWS, Character.UnicodeBlock.of(0x2190));
- assertEquals(Character.UnicodeBlock.ARROWS, Character.UnicodeBlock.of(0x21ff));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of(0x2200));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of(0x22ff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.of(0x2300));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.of(0x23ff));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.of(0x2400));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.of(0x243f));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.of(0x2440));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.of(0x245f));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.of(0x2460));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.of(0x24ff));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.of(0x2500));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.of(0x257f));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.of(0x2580));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.of(0x259f));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.of(0x25a0));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.of(0x25ff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.of(0x2600));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.of(0x26ff));
- assertEquals(Character.UnicodeBlock.DINGBATS, Character.UnicodeBlock.of(0x2700));
- assertEquals(Character.UnicodeBlock.DINGBATS, Character.UnicodeBlock.of(0x27bf));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.of(0x27c0));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.of(0x27ef));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.of(0x27f0));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.of(0x27ff));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.of(0x2800));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.of(0x28ff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.of(0x2900));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.of(0x297f));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.of(0x2980));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.of(0x29ff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of(0x2a00));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.of(0x2aff));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.of(0x2b00));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.of(0x2bff));
- assertNull(Character.UnicodeBlock.of(0x2c00));
- assertNull(Character.UnicodeBlock.of(0x2e7f));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.of(0x2e80));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.of(0x2eff));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.of(0x2f00));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.of(0x2fdf));
- assertNull(Character.UnicodeBlock.of(0x2fe0));
- assertNull(Character.UnicodeBlock.of(0x2fef));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.of(0x2ff0));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.of(0x2fff));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.of(0x3000));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.of(0x303f));
- assertEquals(Character.UnicodeBlock.HIRAGANA, Character.UnicodeBlock.of(0x3040));
- assertEquals(Character.UnicodeBlock.HIRAGANA, Character.UnicodeBlock.of(0x309f));
- assertEquals(Character.UnicodeBlock.KATAKANA, Character.UnicodeBlock.of(0x30a0));
- assertEquals(Character.UnicodeBlock.KATAKANA, Character.UnicodeBlock.of(0x30ff));
- assertEquals(Character.UnicodeBlock.BOPOMOFO, Character.UnicodeBlock.of(0x3100));
- assertEquals(Character.UnicodeBlock.BOPOMOFO, Character.UnicodeBlock.of(0x312f));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.of(0x3130));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.of(0x318f));
- assertEquals(Character.UnicodeBlock.KANBUN, Character.UnicodeBlock.of(0x3190));
- assertEquals(Character.UnicodeBlock.KANBUN, Character.UnicodeBlock.of(0x319f));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.of(0x31a0));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.of(0x31bf));
- assertNull(Character.UnicodeBlock.of(0x31c0));
- assertNull(Character.UnicodeBlock.of(0x31ef));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.of(0x31f0));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.of(0x31ff));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.of(0x3200));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.of(0x32ff));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.of(0x3300));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.of(0x33ff));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.of(0x3400));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.of(0x4dbf));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.of(0x4dc0));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.of(0x4dff));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.of(0x4e00));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.of(0x9fff));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.of(0xa000));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.of(0xa48f));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.of(0xa490));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.of(0xa4cf));
- assertNull(Character.UnicodeBlock.of(0xa4d0));
- assertNull(Character.UnicodeBlock.of(0xabff));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.of(0xac00));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.of(0xd7af));
- assertNull(Character.UnicodeBlock.of(0xd7b0));
- assertNull(Character.UnicodeBlock.of(0xd7ff));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.of(0xd800));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.of(0xdb7f));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.of(0xdb80));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.of(0xdbff));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.of(0xdc00));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.of(0xdfff));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.of(0xe000));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.of(0xf8ff));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.of(0xf900));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.of(0xfaff));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.of(0xfb00));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.of(0xfb4f));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.of(0xfb50));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.of(0xfdff));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.of(0xfe00));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.of(0xfe0f));
- assertNull(Character.UnicodeBlock.of(0xfe10));
- assertNull(Character.UnicodeBlock.of(0xfe1f));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.of(0xfe20));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.of(0xfe2f));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.of(0xfe30));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.of(0xfe4f));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.of(0xfe50));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.of(0xfe6f));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.of(0xfe70));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.of(0xfeff));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.of(0xff00));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.of(0xffef));
- assertEquals(Character.UnicodeBlock.SPECIALS, Character.UnicodeBlock.of(0xfff0));
- assertEquals(Character.UnicodeBlock.SPECIALS, Character.UnicodeBlock.of(0xffff));
- assertEquals(Character.UnicodeBlock.LINEAR_B_SYLLABARY, Character.UnicodeBlock.of(0x10000));
- assertEquals(Character.UnicodeBlock.LINEAR_B_SYLLABARY, Character.UnicodeBlock.of(0x1007f));
- assertEquals(Character.UnicodeBlock.LINEAR_B_IDEOGRAMS, Character.UnicodeBlock.of(0x10080));
- assertEquals(Character.UnicodeBlock.LINEAR_B_IDEOGRAMS, Character.UnicodeBlock.of(0x100ff));
- assertEquals(Character.UnicodeBlock.AEGEAN_NUMBERS, Character.UnicodeBlock.of(0x10100));
- assertEquals(Character.UnicodeBlock.AEGEAN_NUMBERS, Character.UnicodeBlock.of(0x1013f));
- assertNull(Character.UnicodeBlock.of(0x10140));
- assertNull(Character.UnicodeBlock.of(0x102ff));
- assertEquals(Character.UnicodeBlock.OLD_ITALIC, Character.UnicodeBlock.of(0x10300));
- assertEquals(Character.UnicodeBlock.OLD_ITALIC, Character.UnicodeBlock.of(0x1032f));
- assertEquals(Character.UnicodeBlock.GOTHIC, Character.UnicodeBlock.of(0x10330));
- assertEquals(Character.UnicodeBlock.GOTHIC, Character.UnicodeBlock.of(0x1034f));
- assertNull(Character.UnicodeBlock.of(0x10350));
- assertNull(Character.UnicodeBlock.of(0x1037f));
- assertEquals(Character.UnicodeBlock.UGARITIC, Character.UnicodeBlock.of(0x10380));
- assertEquals(Character.UnicodeBlock.UGARITIC, Character.UnicodeBlock.of(0x1039f));
- assertNull(Character.UnicodeBlock.of(0x103a0));
- assertNull(Character.UnicodeBlock.of(0x103ff));
- assertEquals(Character.UnicodeBlock.DESERET, Character.UnicodeBlock.of(0x10400));
- assertEquals(Character.UnicodeBlock.DESERET, Character.UnicodeBlock.of(0x1044f));
- assertEquals(Character.UnicodeBlock.SHAVIAN, Character.UnicodeBlock.of(0x10450));
- assertEquals(Character.UnicodeBlock.SHAVIAN, Character.UnicodeBlock.of(0x1047f));
- assertEquals(Character.UnicodeBlock.OSMANYA, Character.UnicodeBlock.of(0x10480));
- assertEquals(Character.UnicodeBlock.OSMANYA, Character.UnicodeBlock.of(0x104af));
- assertNull(Character.UnicodeBlock.of(0x104b0));
- assertNull(Character.UnicodeBlock.of(0x107ff));
- assertEquals(Character.UnicodeBlock.CYPRIOT_SYLLABARY, Character.UnicodeBlock.of(0x10800));
- assertEquals(Character.UnicodeBlock.CYPRIOT_SYLLABARY, Character.UnicodeBlock.of(0x1083f));
- assertNull(Character.UnicodeBlock.of(0x10840));
- assertNull(Character.UnicodeBlock.of(0x1cfff));
- assertEquals(Character.UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS, Character.UnicodeBlock.of(0x1d000));
- assertEquals(Character.UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS, Character.UnicodeBlock.of(0x1d0ff));
- assertEquals(Character.UnicodeBlock.MUSICAL_SYMBOLS, Character.UnicodeBlock.of(0x1d100));
- assertEquals(Character.UnicodeBlock.MUSICAL_SYMBOLS, Character.UnicodeBlock.of(0x1d1ff));
- assertNull(Character.UnicodeBlock.of(0x1d200));
- assertNull(Character.UnicodeBlock.of(0x1d2ff));
- assertEquals(Character.UnicodeBlock.TAI_XUAN_JING_SYMBOLS, Character.UnicodeBlock.of(0x1d300));
- assertEquals(Character.UnicodeBlock.TAI_XUAN_JING_SYMBOLS, Character.UnicodeBlock.of(0x1d35f));
- assertNull(Character.UnicodeBlock.of(0x1d360));
- assertNull(Character.UnicodeBlock.of(0x1d3ff));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS, Character.UnicodeBlock.of(0x1d400));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS, Character.UnicodeBlock.of(0x1d7ff));
- assertNull(Character.UnicodeBlock.of(0x1d800));
- assertNull(Character.UnicodeBlock.of(0x1ffff));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, Character.UnicodeBlock.of(0x20000));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, Character.UnicodeBlock.of(0x2a6df));
- assertNull(Character.UnicodeBlock.of(0x2a6e0));
- assertNull(Character.UnicodeBlock.of(0x2f7ff));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, Character.UnicodeBlock.of(0x2f800));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, Character.UnicodeBlock.of(0x2fa1f));
- assertNull(Character.UnicodeBlock.of(0x2fa20));
- assertNull(Character.UnicodeBlock.of(0xdffff));
- assertEquals(Character.UnicodeBlock.TAGS, Character.UnicodeBlock.of(0xe0000));
- assertEquals(Character.UnicodeBlock.TAGS, Character.UnicodeBlock.of(0xe007f));
- assertNull(Character.UnicodeBlock.of(0xe0080));
- assertNull(Character.UnicodeBlock.of(0xe00ff));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT, Character.UnicodeBlock.of(0xe0100));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT, Character.UnicodeBlock.of(0xe01ef));
- assertNull(Character.UnicodeBlock.of(0xe01f0));
- assertNull(Character.UnicodeBlock.of(0xeffff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A, Character.UnicodeBlock.of(0xf0000));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A, Character.UnicodeBlock.of(0xfffff));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B, Character.UnicodeBlock.of(0x100000));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B, Character.UnicodeBlock.of(0x10ffff));
- }
-
- public void test_ofIExceptions() {
- try {
- Character.UnicodeBlock.of(Character.MAX_CODE_POINT + 1);
- fail("No illegal argument exception");
- } catch(IllegalArgumentException e) {
- }
- }
-
- @SuppressWarnings("deprecation")
- public void test_forNameLjava_lang_String() {
- assertEquals(Character.UnicodeBlock.SURROGATES_AREA, Character.UnicodeBlock.forName("SURROGATES_AREA"));
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.forName("BASIC_LATIN"));
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.forName("Basic Latin"));
- assertEquals(Character.UnicodeBlock.BASIC_LATIN, Character.UnicodeBlock.forName("BasicLatin"));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.forName("LATIN_1_SUPPLEMENT"));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.forName("Latin-1 Supplement"));
- assertEquals(Character.UnicodeBlock.LATIN_1_SUPPLEMENT, Character.UnicodeBlock.forName("Latin-1Supplement"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.forName("LATIN_EXTENDED_A"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.forName("Latin Extended-A"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_A, Character.UnicodeBlock.forName("LatinExtended-A"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.forName("LATIN_EXTENDED_B"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.forName("Latin Extended-B"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_B, Character.UnicodeBlock.forName("LatinExtended-B"));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.forName("IPA_EXTENSIONS"));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.forName("IPA Extensions"));
- assertEquals(Character.UnicodeBlock.IPA_EXTENSIONS, Character.UnicodeBlock.forName("IPAExtensions"));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.forName("SPACING_MODIFIER_LETTERS"));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.forName("Spacing Modifier Letters"));
- assertEquals(Character.UnicodeBlock.SPACING_MODIFIER_LETTERS, Character.UnicodeBlock.forName("SpacingModifierLetters"));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.forName("COMBINING_DIACRITICAL_MARKS"));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.forName("Combining Diacritical Marks"));
- assertEquals(Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS, Character.UnicodeBlock.forName("CombiningDiacriticalMarks"));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.forName("GREEK"));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.forName("Greek and Coptic"));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.forName("GreekandCoptic"));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.forName("Greek"));
- assertEquals(Character.UnicodeBlock.GREEK, Character.UnicodeBlock.forName("Greek"));
- assertEquals(Character.UnicodeBlock.CYRILLIC, Character.UnicodeBlock.forName("CYRILLIC"));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.forName("CYRILLIC_SUPPLEMENTARY"));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.forName("Cyrillic Supplementary"));
- assertEquals(Character.UnicodeBlock.CYRILLIC_SUPPLEMENTARY, Character.UnicodeBlock.forName("CyrillicSupplementary"));
- assertEquals(Character.UnicodeBlock.ARMENIAN, Character.UnicodeBlock.forName("ARMENIAN"));
- assertEquals(Character.UnicodeBlock.HEBREW, Character.UnicodeBlock.forName("HEBREW"));
- assertEquals(Character.UnicodeBlock.ARABIC, Character.UnicodeBlock.forName("ARABIC"));
- assertEquals(Character.UnicodeBlock.SYRIAC, Character.UnicodeBlock.forName("SYRIAC"));
- assertEquals(Character.UnicodeBlock.THAANA, Character.UnicodeBlock.forName("THAANA"));
- assertEquals(Character.UnicodeBlock.DEVANAGARI, Character.UnicodeBlock.forName("DEVANAGARI"));
- assertEquals(Character.UnicodeBlock.BENGALI, Character.UnicodeBlock.forName("BENGALI"));
- assertEquals(Character.UnicodeBlock.GURMUKHI, Character.UnicodeBlock.forName("GURMUKHI"));
- assertEquals(Character.UnicodeBlock.GUJARATI, Character.UnicodeBlock.forName("GUJARATI"));
- assertEquals(Character.UnicodeBlock.ORIYA, Character.UnicodeBlock.forName("ORIYA"));
- assertEquals(Character.UnicodeBlock.TAMIL, Character.UnicodeBlock.forName("TAMIL"));
- assertEquals(Character.UnicodeBlock.TELUGU, Character.UnicodeBlock.forName("TELUGU"));
- assertEquals(Character.UnicodeBlock.KANNADA, Character.UnicodeBlock.forName("KANNADA"));
- assertEquals(Character.UnicodeBlock.MALAYALAM, Character.UnicodeBlock.forName("MALAYALAM"));
- assertEquals(Character.UnicodeBlock.SINHALA, Character.UnicodeBlock.forName("SINHALA"));
- assertEquals(Character.UnicodeBlock.THAI, Character.UnicodeBlock.forName("THAI"));
- assertEquals(Character.UnicodeBlock.LAO, Character.UnicodeBlock.forName("LAO"));
- assertEquals(Character.UnicodeBlock.TIBETAN, Character.UnicodeBlock.forName("TIBETAN"));
- assertEquals(Character.UnicodeBlock.MYANMAR, Character.UnicodeBlock.forName("MYANMAR"));
- assertEquals(Character.UnicodeBlock.GEORGIAN, Character.UnicodeBlock.forName("GEORGIAN"));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.forName("HANGUL_JAMO"));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.forName("Hangul Jamo"));
- assertEquals(Character.UnicodeBlock.HANGUL_JAMO, Character.UnicodeBlock.forName("HangulJamo"));
- assertEquals(Character.UnicodeBlock.ETHIOPIC, Character.UnicodeBlock.forName("ETHIOPIC"));
- assertEquals(Character.UnicodeBlock.CHEROKEE, Character.UnicodeBlock.forName("CHEROKEE"));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.forName("UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS"));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.forName("Unified Canadian Aboriginal Syllabics"));
- assertEquals(Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS, Character.UnicodeBlock.forName("UnifiedCanadianAboriginalSyllabics"));
- assertEquals(Character.UnicodeBlock.OGHAM, Character.UnicodeBlock.forName("OGHAM"));
- assertEquals(Character.UnicodeBlock.RUNIC, Character.UnicodeBlock.forName("RUNIC"));
- assertEquals(Character.UnicodeBlock.TAGALOG, Character.UnicodeBlock.forName("TAGALOG"));
- assertEquals(Character.UnicodeBlock.HANUNOO, Character.UnicodeBlock.forName("HANUNOO"));
- assertEquals(Character.UnicodeBlock.BUHID, Character.UnicodeBlock.forName("BUHID"));
- assertEquals(Character.UnicodeBlock.TAGBANWA, Character.UnicodeBlock.forName("TAGBANWA"));
- assertEquals(Character.UnicodeBlock.KHMER, Character.UnicodeBlock.forName("KHMER"));
- assertEquals(Character.UnicodeBlock.MONGOLIAN, Character.UnicodeBlock.forName("MONGOLIAN"));
- assertEquals(Character.UnicodeBlock.LIMBU, Character.UnicodeBlock.forName("LIMBU"));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.forName("TAI_LE"));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.forName("Tai Le"));
- assertEquals(Character.UnicodeBlock.TAI_LE, Character.UnicodeBlock.forName("TaiLe"));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.forName("KHMER_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.forName("Khmer Symbols"));
- assertEquals(Character.UnicodeBlock.KHMER_SYMBOLS, Character.UnicodeBlock.forName("KhmerSymbols"));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("PHONETIC_EXTENSIONS"));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("Phonetic Extensions"));
- assertEquals(Character.UnicodeBlock.PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("PhoneticExtensions"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.forName("LATIN_EXTENDED_ADDITIONAL"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.forName("Latin Extended Additional"));
- assertEquals(Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL, Character.UnicodeBlock.forName("LatinExtendedAdditional"));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.forName("GREEK_EXTENDED"));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.forName("Greek Extended"));
- assertEquals(Character.UnicodeBlock.GREEK_EXTENDED, Character.UnicodeBlock.forName("GreekExtended"));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.forName("GENERAL_PUNCTUATION"));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.forName("General Punctuation"));
- assertEquals(Character.UnicodeBlock.GENERAL_PUNCTUATION, Character.UnicodeBlock.forName("GeneralPunctuation"));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.forName("SUPERSCRIPTS_AND_SUBSCRIPTS"));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.forName("Superscripts and Subscripts"));
- assertEquals(Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS, Character.UnicodeBlock.forName("SuperscriptsandSubscripts"));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.forName("CURRENCY_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.forName("Currency Symbols"));
- assertEquals(Character.UnicodeBlock.CURRENCY_SYMBOLS, Character.UnicodeBlock.forName("CurrencySymbols"));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.forName("COMBINING_MARKS_FOR_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.forName("Combining Diacritical Marks for Symbols"));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.forName("CombiningDiacriticalMarksforSymbols"));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.forName("Combining Marks for Symbols"));
- assertEquals(Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS, Character.UnicodeBlock.forName("CombiningMarksforSymbols"));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.forName("LETTERLIKE_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.forName("Letterlike Symbols"));
- assertEquals(Character.UnicodeBlock.LETTERLIKE_SYMBOLS, Character.UnicodeBlock.forName("LetterlikeSymbols"));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.forName("NUMBER_FORMS"));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.forName("Number Forms"));
- assertEquals(Character.UnicodeBlock.NUMBER_FORMS, Character.UnicodeBlock.forName("NumberForms"));
- assertEquals(Character.UnicodeBlock.ARROWS, Character.UnicodeBlock.forName("ARROWS"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("MATHEMATICAL_OPERATORS"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("Mathematical Operators"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("MathematicalOperators"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.forName("MISCELLANEOUS_TECHNICAL"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.forName("Miscellaneous Technical"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL, Character.UnicodeBlock.forName("MiscellaneousTechnical"));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.forName("CONTROL_PICTURES"));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.forName("Control Pictures"));
- assertEquals(Character.UnicodeBlock.CONTROL_PICTURES, Character.UnicodeBlock.forName("ControlPictures"));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.forName("OPTICAL_CHARACTER_RECOGNITION"));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.forName("Optical Character Recognition"));
- assertEquals(Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION, Character.UnicodeBlock.forName("OpticalCharacterRecognition"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.forName("ENCLOSED_ALPHANUMERICS"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.forName("Enclosed Alphanumerics"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS, Character.UnicodeBlock.forName("EnclosedAlphanumerics"));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.forName("BOX_DRAWING"));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.forName("Box Drawing"));
- assertEquals(Character.UnicodeBlock.BOX_DRAWING, Character.UnicodeBlock.forName("BoxDrawing"));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.forName("BLOCK_ELEMENTS"));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.forName("Block Elements"));
- assertEquals(Character.UnicodeBlock.BLOCK_ELEMENTS, Character.UnicodeBlock.forName("BlockElements"));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.forName("GEOMETRIC_SHAPES"));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.forName("Geometric Shapes"));
- assertEquals(Character.UnicodeBlock.GEOMETRIC_SHAPES, Character.UnicodeBlock.forName("GeometricShapes"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.forName("MISCELLANEOUS_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.forName("Miscellaneous Symbols"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS, Character.UnicodeBlock.forName("MiscellaneousSymbols"));
- assertEquals(Character.UnicodeBlock.DINGBATS, Character.UnicodeBlock.forName("DINGBATS"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.forName("MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.forName("Miscellaneous Mathematical Symbols-A"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_A, Character.UnicodeBlock.forName("MiscellaneousMathematicalSymbols-A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.forName("SUPPLEMENTAL_ARROWS_A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.forName("Supplemental Arrows-A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_A, Character.UnicodeBlock.forName("SupplementalArrows-A"));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.forName("BRAILLE_PATTERNS"));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.forName("Braille Patterns"));
- assertEquals(Character.UnicodeBlock.BRAILLE_PATTERNS, Character.UnicodeBlock.forName("BraillePatterns"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.forName("SUPPLEMENTAL_ARROWS_B"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.forName("Supplemental Arrows-B"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_ARROWS_B, Character.UnicodeBlock.forName("SupplementalArrows-B"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.forName("MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.forName("Miscellaneous Mathematical Symbols-B"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_MATHEMATICAL_SYMBOLS_B, Character.UnicodeBlock.forName("MiscellaneousMathematicalSymbols-B"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("SUPPLEMENTAL_MATHEMATICAL_OPERATORS"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("Supplemental Mathematical Operators"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTAL_MATHEMATICAL_OPERATORS, Character.UnicodeBlock.forName("SupplementalMathematicalOperators"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.forName("MISCELLANEOUS_SYMBOLS_AND_ARROWS"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.forName("Miscellaneous Symbols and Arrows"));
- assertEquals(Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS_AND_ARROWS, Character.UnicodeBlock.forName("MiscellaneousSymbolsandArrows"));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.forName("CJK_RADICALS_SUPPLEMENT"));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.forName("CJK Radicals Supplement"));
- assertEquals(Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT, Character.UnicodeBlock.forName("CJKRadicalsSupplement"));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.forName("KANGXI_RADICALS"));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.forName("Kangxi Radicals"));
- assertEquals(Character.UnicodeBlock.KANGXI_RADICALS, Character.UnicodeBlock.forName("KangxiRadicals"));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.forName("IDEOGRAPHIC_DESCRIPTION_CHARACTERS"));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.forName("Ideographic Description Characters"));
- assertEquals(Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS, Character.UnicodeBlock.forName("IdeographicDescriptionCharacters"));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.forName("CJK_SYMBOLS_AND_PUNCTUATION"));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.forName("CJK Symbols and Punctuation"));
- assertEquals(Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION, Character.UnicodeBlock.forName("CJKSymbolsandPunctuation"));
- assertEquals(Character.UnicodeBlock.HIRAGANA, Character.UnicodeBlock.forName("HIRAGANA"));
- assertEquals(Character.UnicodeBlock.KATAKANA, Character.UnicodeBlock.forName("KATAKANA"));
- assertEquals(Character.UnicodeBlock.BOPOMOFO, Character.UnicodeBlock.forName("BOPOMOFO"));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.forName("HANGUL_COMPATIBILITY_JAMO"));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.forName("Hangul Compatibility Jamo"));
- assertEquals(Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO, Character.UnicodeBlock.forName("HangulCompatibilityJamo"));
- assertEquals(Character.UnicodeBlock.KANBUN, Character.UnicodeBlock.forName("KANBUN"));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.forName("BOPOMOFO_EXTENDED"));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.forName("Bopomofo Extended"));
- assertEquals(Character.UnicodeBlock.BOPOMOFO_EXTENDED, Character.UnicodeBlock.forName("BopomofoExtended"));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("KATAKANA_PHONETIC_EXTENSIONS"));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("Katakana Phonetic Extensions"));
- assertEquals(Character.UnicodeBlock.KATAKANA_PHONETIC_EXTENSIONS, Character.UnicodeBlock.forName("KatakanaPhoneticExtensions"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.forName("ENCLOSED_CJK_LETTERS_AND_MONTHS"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.forName("Enclosed CJK Letters and Months"));
- assertEquals(Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS, Character.UnicodeBlock.forName("EnclosedCJKLettersandMonths"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.forName("CJK_COMPATIBILITY"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.forName("CJK Compatibility"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY, Character.UnicodeBlock.forName("CJKCompatibility"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.forName("CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.forName("CJK Unified Ideographs Extension A"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A, Character.UnicodeBlock.forName("CJKUnifiedIdeographsExtensionA"));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.forName("YIJING_HEXAGRAM_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.forName("Yijing Hexagram Symbols"));
- assertEquals(Character.UnicodeBlock.YIJING_HEXAGRAM_SYMBOLS, Character.UnicodeBlock.forName("YijingHexagramSymbols"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.forName("CJK_UNIFIED_IDEOGRAPHS"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.forName("CJK Unified Ideographs"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS, Character.UnicodeBlock.forName("CJKUnifiedIdeographs"));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.forName("YI_SYLLABLES"));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.forName("Yi Syllables"));
- assertEquals(Character.UnicodeBlock.YI_SYLLABLES, Character.UnicodeBlock.forName("YiSyllables"));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.forName("YI_RADICALS"));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.forName("Yi Radicals"));
- assertEquals(Character.UnicodeBlock.YI_RADICALS, Character.UnicodeBlock.forName("YiRadicals"));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.forName("HANGUL_SYLLABLES"));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.forName("Hangul Syllables"));
- assertEquals(Character.UnicodeBlock.HANGUL_SYLLABLES, Character.UnicodeBlock.forName("HangulSyllables"));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.forName("HIGH_SURROGATES"));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.forName("High Surrogates"));
- assertEquals(Character.UnicodeBlock.HIGH_SURROGATES, Character.UnicodeBlock.forName("HighSurrogates"));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.forName("HIGH_PRIVATE_USE_SURROGATES"));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.forName("High Private Use Surrogates"));
- assertEquals(Character.UnicodeBlock.HIGH_PRIVATE_USE_SURROGATES, Character.UnicodeBlock.forName("HighPrivateUseSurrogates"));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.forName("LOW_SURROGATES"));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.forName("Low Surrogates"));
- assertEquals(Character.UnicodeBlock.LOW_SURROGATES, Character.UnicodeBlock.forName("LowSurrogates"));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.forName("PRIVATE_USE_AREA"));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.forName("Private Use Area"));
- assertEquals(Character.UnicodeBlock.PRIVATE_USE_AREA, Character.UnicodeBlock.forName("PrivateUseArea"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.forName("CJK_COMPATIBILITY_IDEOGRAPHS"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.forName("CJK Compatibility Ideographs"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS, Character.UnicodeBlock.forName("CJKCompatibilityIdeographs"));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.forName("ALPHABETIC_PRESENTATION_FORMS"));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.forName("Alphabetic Presentation Forms"));
- assertEquals(Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS, Character.UnicodeBlock.forName("AlphabeticPresentationForms"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.forName("ARABIC_PRESENTATION_FORMS_A"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.forName("Arabic Presentation Forms-A"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A, Character.UnicodeBlock.forName("ArabicPresentationForms-A"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.forName("VARIATION_SELECTORS"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.forName("Variation Selectors"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS, Character.UnicodeBlock.forName("VariationSelectors"));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.forName("COMBINING_HALF_MARKS"));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.forName("Combining Half Marks"));
- assertEquals(Character.UnicodeBlock.COMBINING_HALF_MARKS, Character.UnicodeBlock.forName("CombiningHalfMarks"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.forName("CJK_COMPATIBILITY_FORMS"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.forName("CJK Compatibility Forms"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS, Character.UnicodeBlock.forName("CJKCompatibilityForms"));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.forName("SMALL_FORM_VARIANTS"));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.forName("Small Form Variants"));
- assertEquals(Character.UnicodeBlock.SMALL_FORM_VARIANTS, Character.UnicodeBlock.forName("SmallFormVariants"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.forName("ARABIC_PRESENTATION_FORMS_B"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.forName("Arabic Presentation Forms-B"));
- assertEquals(Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B, Character.UnicodeBlock.forName("ArabicPresentationForms-B"));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.forName("HALFWIDTH_AND_FULLWIDTH_FORMS"));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.forName("Halfwidth and Fullwidth Forms"));
- assertEquals(Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS, Character.UnicodeBlock.forName("HalfwidthandFullwidthForms"));
- assertEquals(Character.UnicodeBlock.SPECIALS, Character.UnicodeBlock.forName("SPECIALS"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_SYLLABARY, Character.UnicodeBlock.forName("LINEAR_B_SYLLABARY"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_SYLLABARY, Character.UnicodeBlock.forName("Linear B Syllabary"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_SYLLABARY, Character.UnicodeBlock.forName("LinearBSyllabary"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_IDEOGRAMS, Character.UnicodeBlock.forName("LINEAR_B_IDEOGRAMS"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_IDEOGRAMS, Character.UnicodeBlock.forName("Linear B Ideograms"));
- assertEquals(Character.UnicodeBlock.LINEAR_B_IDEOGRAMS, Character.UnicodeBlock.forName("LinearBIdeograms"));
- assertEquals(Character.UnicodeBlock.AEGEAN_NUMBERS, Character.UnicodeBlock.forName("AEGEAN_NUMBERS"));
- assertEquals(Character.UnicodeBlock.AEGEAN_NUMBERS, Character.UnicodeBlock.forName("Aegean Numbers"));
- assertEquals(Character.UnicodeBlock.AEGEAN_NUMBERS, Character.UnicodeBlock.forName("AegeanNumbers"));
- assertEquals(Character.UnicodeBlock.OLD_ITALIC, Character.UnicodeBlock.forName("OLD_ITALIC"));
- assertEquals(Character.UnicodeBlock.OLD_ITALIC, Character.UnicodeBlock.forName("Old Italic"));
- assertEquals(Character.UnicodeBlock.OLD_ITALIC, Character.UnicodeBlock.forName("OldItalic"));
- assertEquals(Character.UnicodeBlock.GOTHIC, Character.UnicodeBlock.forName("GOTHIC"));
- assertEquals(Character.UnicodeBlock.UGARITIC, Character.UnicodeBlock.forName("UGARITIC"));
- assertEquals(Character.UnicodeBlock.DESERET, Character.UnicodeBlock.forName("DESERET"));
- assertEquals(Character.UnicodeBlock.SHAVIAN, Character.UnicodeBlock.forName("SHAVIAN"));
- assertEquals(Character.UnicodeBlock.OSMANYA, Character.UnicodeBlock.forName("OSMANYA"));
- assertEquals(Character.UnicodeBlock.CYPRIOT_SYLLABARY, Character.UnicodeBlock.forName("CYPRIOT_SYLLABARY"));
- assertEquals(Character.UnicodeBlock.CYPRIOT_SYLLABARY, Character.UnicodeBlock.forName("Cypriot Syllabary"));
- assertEquals(Character.UnicodeBlock.CYPRIOT_SYLLABARY, Character.UnicodeBlock.forName("CypriotSyllabary"));
- assertEquals(Character.UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("BYZANTINE_MUSICAL_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("Byzantine Musical Symbols"));
- assertEquals(Character.UnicodeBlock.BYZANTINE_MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("ByzantineMusicalSymbols"));
- assertEquals(Character.UnicodeBlock.MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("MUSICAL_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("Musical Symbols"));
- assertEquals(Character.UnicodeBlock.MUSICAL_SYMBOLS, Character.UnicodeBlock.forName("MusicalSymbols"));
- assertEquals(Character.UnicodeBlock.TAI_XUAN_JING_SYMBOLS, Character.UnicodeBlock.forName("TAI_XUAN_JING_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.TAI_XUAN_JING_SYMBOLS, Character.UnicodeBlock.forName("Tai Xuan Jing Symbols"));
- assertEquals(Character.UnicodeBlock.TAI_XUAN_JING_SYMBOLS, Character.UnicodeBlock.forName("TaiXuanJingSymbols"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS, Character.UnicodeBlock.forName("MATHEMATICAL_ALPHANUMERIC_SYMBOLS"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS, Character.UnicodeBlock.forName("Mathematical Alphanumeric Symbols"));
- assertEquals(Character.UnicodeBlock.MATHEMATICAL_ALPHANUMERIC_SYMBOLS, Character.UnicodeBlock.forName("MathematicalAlphanumericSymbols"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, Character.UnicodeBlock.forName("CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, Character.UnicodeBlock.forName("CJK Unified Ideographs Extension B"));
- assertEquals(Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_B, Character.UnicodeBlock.forName("CJKUnifiedIdeographsExtensionB"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, Character.UnicodeBlock.forName("CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, Character.UnicodeBlock.forName("CJK Compatibility Ideographs Supplement"));
- assertEquals(Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS_SUPPLEMENT, Character.UnicodeBlock.forName("CJKCompatibilityIdeographsSupplement"));
- assertEquals(Character.UnicodeBlock.TAGS, Character.UnicodeBlock.forName("TAGS"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT, Character.UnicodeBlock.forName("VARIATION_SELECTORS_SUPPLEMENT"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT, Character.UnicodeBlock.forName("Variation Selectors Supplement"));
- assertEquals(Character.UnicodeBlock.VARIATION_SELECTORS_SUPPLEMENT, Character.UnicodeBlock.forName("VariationSelectorsSupplement"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A, Character.UnicodeBlock.forName("SUPPLEMENTARY_PRIVATE_USE_AREA_A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A, Character.UnicodeBlock.forName("Supplementary Private Use Area-A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_A, Character.UnicodeBlock.forName("SupplementaryPrivateUseArea-A"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B, Character.UnicodeBlock.forName("SUPPLEMENTARY_PRIVATE_USE_AREA_B"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B, Character.UnicodeBlock.forName("Supplementary Private Use Area-B"));
- assertEquals(Character.UnicodeBlock.SUPPLEMENTARY_PRIVATE_USE_AREA_B, Character.UnicodeBlock.forName("SupplementaryPrivateUseArea-B"));
- }
-
- public void test_forNameLjava_lang_StringExceptions() {
- try {
- Character.UnicodeBlock.forName(null);
- fail("No NPE");
- } catch(NullPointerException e) {
- }
-
- try {
- Character.UnicodeBlock.forName("INVALID_NAME");
- fail("No illegal argument exception");
- } catch(IllegalArgumentException e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java
deleted file mode 100644
index bc56cef..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCastExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ClassCastExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.ClassCastException#ClassCastException()
- */
- public void test_Constructor() {
- ClassCastException e = new ClassCastException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ClassCastException#ClassCastException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ClassCastException e = new ClassCastException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCircularityErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCircularityErrorTest.java
deleted file mode 100644
index 029e16c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassCircularityErrorTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase; // android-changed
-
-public class ClassCircularityErrorTest extends TestCase { // android-changed
- // Thrown when a circularity has been detected while initializing a class.
- /**
- * @tests java.lang.ClassCircularityError#ClassCircularityError()
- */
- public void test_ClassCircularityError() {
- new ClassCircularityError();
- }
-
- /**
- * @tests java.lang.ClassCircularityError#ClassCircularityError(java.lang.String)
- */
- public void test_ClassCircularityError_LString() {
- ClassCircularityError e = new ClassCircularityError(
- "Some Error message");
- assertEquals("Wrong message", "Some Error message", e.getMessage());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassFormatErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassFormatErrorTest.java
deleted file mode 100644
index 2bf8678..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassFormatErrorTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase; // android-changed
-
-public class ClassFormatErrorTest extends TestCase { // android-changed
- /**
- * Thrown when the Java Virtual Machine attempts to read a class file and
- * determines that the file is malformed or otherwise cannot be interpreted
- * as a class file.
- */
-
- /**
- * @tests java.lang.ClassFormatError#ClassFormatError()
- */
- public void test_ClassFormatError() {
- new ClassFormatError();
- }
-
- /**
- * @tests java.lang.ClassFormatError#ClassFormatError(java.lang.String)
- */
- public void test_ClassFormatError_LString() {
- ClassFormatError e = new ClassFormatError("Some Error Message");
- assertEquals("Wrong message", "Some Error Message", e.getMessage());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java
deleted file mode 100644
index ca4ae28..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassLoaderTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.InputStream;
-import java.security.CodeSource;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Policy;
-import java.security.ProtectionDomain;
-import java.security.SecurityPermission;
-
-import junit.framework.TestCase;
-
-public class ClassLoaderTest extends TestCase {
-
- public static volatile int flag;
-
- /**
- * Tests that Classloader.defineClass() assigns appropriate
- * default domains to the defined classes.
- */
- public void test_defineClass_defaultDomain() throws Exception {
- // Regression for HARMONY-765
- DynamicPolicy plc = new DynamicPolicy();
- Policy back = Policy.getPolicy();
- try {
- Policy.setPolicy(plc);
-
- Class<?> a = new Ldr().define();
-
- Permission p = new SecurityPermission("abc");
- assertFalse("impossible! misconfiguration?", a.getProtectionDomain().implies(p));
-
- plc.pc = p.newPermissionCollection();
- plc.pc.add(p);
- assertTrue("default domain is not dynamic", a.getProtectionDomain().implies(p));
- } finally {
- Policy.setPolicy(back);
- }
- }
-
- static class SyncTestClassLoader extends ClassLoader {
- Object lock;
- volatile int numFindClassCalled;
-
- SyncTestClassLoader(Object o) {
- this.lock = o;
- numFindClassCalled = 0;
- }
-
- /*
- * Byte array of bytecode equivalent to the following source code:
- * public class TestClass {
- * }
- */
- private byte[] classData = new byte[] {
- -54, -2, -70, -66, 0, 0, 0, 49, 0, 13,
- 10, 0, 3, 0, 10, 7, 0, 11, 7, 0,
- 12, 1, 0, 6, 60, 105, 110, 105, 116, 62,
- 1, 0, 3, 40, 41, 86, 1, 0, 4, 67,
- 111, 100, 101, 1, 0, 15, 76, 105, 110, 101,
- 78, 117, 109, 98, 101, 114, 84, 97, 98, 108,
- 101, 1, 0, 10, 83, 111, 117, 114, 99, 101,
- 70, 105, 108, 101, 1, 0, 14, 84, 101, 115,
- 116, 67, 108, 97, 115, 115, 46, 106, 97, 118,
- 97, 12, 0, 4, 0, 5, 1, 0, 9, 84,
- 101, 115, 116, 67, 108, 97, 115, 115, 1, 0,
- 16, 106, 97, 118, 97, 47, 108, 97, 110, 103,
- 47, 79, 98, 106, 101, 99, 116, 0, 33, 0,
- 2, 0, 3, 0, 0, 0, 0, 0, 1, 0,
- 1, 0, 4, 0, 5, 0, 1, 0, 6, 0,
- 0, 0, 29, 0, 1, 0, 1, 0, 0, 0,
- 5, 42, -73, 0, 1, -79, 0, 0, 0, 1,
- 0, 7, 0, 0, 0, 6, 0, 1, 0, 0,
- 0, 1, 0, 1, 0, 8, 0, 0, 0, 2,
- 0, 9 };
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- try {
- while (flag != 2) {
- synchronized (lock) {
- lock.wait();
- }
- }
- } catch (InterruptedException ie) {}
-
- if (name.equals("TestClass")) {
- numFindClassCalled++;
- return defineClass(null, classData, 0, classData.length);
- }
- throw new ClassNotFoundException("Class " + name + " not found.");
- }
- }
-
- static class SyncLoadTestThread extends Thread {
- volatile boolean started;
- ClassLoader cl;
- Class<?> cls;
-
- SyncLoadTestThread(ClassLoader cl) {
- this.cl = cl;
- }
-
- @Override
- public void run() {
- try {
- started = true;
- cls = Class.forName("TestClass", false, cl);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
-
- /**
- * Regression test for HARMONY-1939:
- * 2 threads simultaneously run Class.forName() method for the same classname
- * and the same classloader. It is expected that both threads succeed but
- * class must be defined just once.
- */
- public void test_loadClass_concurrentLoad() throws Exception
- {
- Object lock = new Object();
- SyncTestClassLoader cl = new SyncTestClassLoader(lock);
- SyncLoadTestThread tt1 = new SyncLoadTestThread(cl);
- SyncLoadTestThread tt2 = new SyncLoadTestThread(cl);
- flag = 1;
- tt1.start();
- tt2.start();
-
- while (!tt1.started && !tt2.started) {
- Thread.sleep(100);
- }
-
- flag = 2;
- synchronized (lock) {
- lock.notifyAll();
- }
- tt1.join();
- tt2.join();
-
- assertSame("Bad or redefined class", tt1.cls, tt2.cls);
- assertEquals("Both threads tried to define class", 1, cl.numFindClassCalled);
- }
-
- /**
- * @tests java.lang.ClassLoader#getResource(java.lang.String)
- */
- public void test_getResourceLjava_lang_String() {
- // Test for method java.net.URL
- // java.lang.ClassLoader.getResource(java.lang.String)
- java.net.URL u = ClassLoader.getSystemClassLoader().getResource("hyts_Foo.c");
- assertNotNull("Unable to find resource", u);
- java.io.InputStream is = null;
- try {
- is = u.openStream();
- assertNotNull("Resource returned is invalid", is);
- is.close();
- } catch (java.io.IOException e) {
- fail("IOException getting stream for resource : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.lang.ClassLoader#getResourceAsStream(java.lang.String)
- */
- public void test_getResourceAsStreamLjava_lang_String() {
- // Test for method java.io.InputStream
- // java.lang.ClassLoader.getResourceAsStream(java.lang.String)
- // Need better test...
-
- java.io.InputStream is = null;
- assertNotNull("Failed to find resource: hyts_Foo.c", (is = ClassLoader
- .getSystemClassLoader().getResourceAsStream("hyts_Foo.c")));
- try {
- is.close();
- } catch (java.io.IOException e) {
- fail("Exception during getResourceAsStream: " + e.toString());
- }
- }
-
- /**
- * @tests java.lang.ClassLoader#getSystemClassLoader()
- */
- public void test_getSystemClassLoader() {
- // Test for method java.lang.ClassLoader
- // java.lang.ClassLoader.getSystemClassLoader()
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- java.io.InputStream is = cl.getResourceAsStream("hyts_Foo.c");
- assertNotNull("Failed to find resource from system classpath", is);
- try {
- is.close();
- } catch (java.io.IOException e) {
- }
-
- }
-
- /**
- * @tests java.lang.ClassLoader#getSystemResource(java.lang.String)
- */
- public void test_getSystemResourceLjava_lang_String() {
- // Test for method java.net.URL
- // java.lang.ClassLoader.getSystemResource(java.lang.String)
- // Need better test...
- assertNotNull("Failed to find resource: hyts_Foo.c", ClassLoader
- .getSystemResource("hyts_Foo.c"));
- }
-
-
- //Regression Test for JIRA-2047
- public void test_getResourceAsStream_withSharpChar() throws Exception {
- InputStream in = this.getClass().getClassLoader().getResourceAsStream(
- ClassTest.FILENAME);
- assertNotNull(in);
- in.close();
- }
-}
-
-class DynamicPolicy extends Policy {
-
- public PermissionCollection pc;
-
- @Override
- public PermissionCollection getPermissions(ProtectionDomain pd) {
- return pc;
- }
-
- @Override
- public PermissionCollection getPermissions(CodeSource codesource) {
- return pc;
- }
-
- @Override
- public void refresh() {
- }
-}
-
-class A {
-}
-
-class Ldr extends ClassLoader {
- @SuppressWarnings("deprecation")
- public Class<?> define() throws Exception {
- Package p = getClass().getPackage();
- // Class loader paths use '/' character as separator
- String path = p == null ? "" : p.getName().replace('.', '/') + '/';
- InputStream is = getResourceAsStream(path + "A.class");
- byte[] buf = new byte[512];
- int len = is.read(buf);
- return defineClass(buf, 0, len);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java
deleted file mode 100644
index 3a26a79..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassNotFoundExceptionTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.IOException;
-
-import junit.framework.TestCase;
-
-public class ClassNotFoundExceptionTest extends TestCase {
- /**
- * Thrown when an application tries to load in a class through its string
- * name using the forName method in class Class.
- */
-
- /**
- * @tests java.lang.ClassNotFoundException#ClassNotFoundException()
- */
- public void test_Constructor() {
- ClassNotFoundException e = new ClassNotFoundException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ClassNotFoundException#ClassNotFoundException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ClassNotFoundException e = new ClassNotFoundException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ClassNotFoundException#ClassNotFoundException(java.lang.String, java.lang.Throwable)
- */
- public void test_ClassNotFoundException_LString_LThrowable() {
- IOException in = new IOException();
- ClassNotFoundException e = new ClassNotFoundException("SomeMessage", in);
- assertEquals("Wrong Exception", in, e.getException());
- assertEquals("Wrong message", "SomeMessage", e.getMessage());
- assertEquals("Wrong cause", in, e.getCause());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
deleted file mode 100644
index 4f373de..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
+++ /dev/null
@@ -1,1806 +0,0 @@
-/*
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.BasicPermission;
-import java.security.DomainCombiner;
-import java.security.Permission;
-import java.security.PrivilegedAction;
-import java.security.ProtectionDomain;
-import java.security.Security;
-import java.util.AbstractList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Vector;
-
-import tests.support.Support_ClassLoader;
-import tests.support.resource.Support_Resources;
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@SuppressWarnings("deprecation")
-@TestTargetClass(Class.class)
-public class ClassTest extends junit.framework.TestCase {
-
- public static final String FILENAME =
- ClassTest.class.getPackage().getName().replace('.', '/') +
- "/test#.properties";
-
- final String packageName = getClass().getPackage().getName();
- final String classNameInitError1 = packageName + ".TestClass1";
- final String classNameInitError2 = packageName + ".TestClass1B";
- final String classNameLinkageError = packageName + ".TestClass";
- final String sourceJARfile = "illegalClasses.jar";
- final String illegalClassName = "illegalClass";
-
- static class StaticMember$Class {
- class Member2$A {
- }
- }
-
- class Member$Class {
- class Member3$B {
- }
- }
-
- public static class TestClass {
- @SuppressWarnings("unused")
- private int privField = 1;
-
- public int pubField = 2;
-
- private Object cValue = null;
-
- public Object ack = new Object();
-
- @SuppressWarnings("unused")
- private int privMethod() {
- return 1;
- }
-
- public int pubMethod() {
- return 2;
- }
-
- public Object cValue() {
- return cValue;
- }
-
- public TestClass() {
- }
-
- @SuppressWarnings("unused")
- private TestClass(Object o) {
- }
- }
-
- public static class SubTestClass extends TestClass {
- }
-
- interface Intf1 {
- public int field1 = 1;
- public int field2 = 1;
- void test();
- }
-
- interface Intf2 {
- public int field1 = 1;
- void test();
- }
-
- interface Intf3 extends Intf1 {
- public int field1 = 1;
- }
-
- interface Intf4 extends Intf1, Intf2 {
- public int field1 = 1;
- void test2(int a, Object b);
- }
-
- interface Intf5 extends Intf1 {
- }
-
- class Cls1 implements Intf2 {
- public int field1 = 2;
- public int field2 = 2;
- public void test() {
- }
- }
-
- class Cls2 extends Cls1 implements Intf1 {
- public int field1 = 2;
- @Override
- public void test() {
- }
- }
-
- class Cls3 implements Intf3, Intf4 {
- public void test() {
- }
- public void test2(int a, Object b) {
- }
- }
-
- static class Cls4 {
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getAnnotations",
- args = {}
- )
- public void test_getAnnotations() {
- Annotation [] annotations = PublicTestClass.class.getAnnotations();
- assertEquals(1, annotations.length);
- assertEquals(TestAnnotation.class, annotations[0].annotationType());
-
- annotations = ExtendTestClass.class.getAnnotations();
- assertEquals(2, annotations.length);
-
- for(int i = 0; i < annotations.length; i++) {
- Class<? extends Annotation> type = annotations[i].annotationType();
- assertTrue("Annotation's type " + i + ": " + type,
- type.equals(Deprecated.class) ||
- type.equals(TestAnnotation.class));
- }
- }
-
- /**
- * @tests java.lang.Class#forName(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "java.lang.LinkageError can't be checked.",
- method = "forName",
- args = {java.lang.String.class}
- )
- @AndroidOnly("harmony specific: test with " +
- "'org.apache.harmony.luni.tests.java.lang.TestClass1'")
- public void test_forNameLjava_lang_String() throws Exception {
-
- assertSame("Class for name failed for java.lang.Object",
- Object.class, Class.forName("java.lang.Object"));
- assertSame("Class for name failed for [[Ljava.lang.Object;",
- Object[][].class, Class.forName("[[Ljava.lang.Object;"));
-
- assertSame("Class for name failed for [I",
- int[].class, Class.forName("[I"));
-
- try {
- Class.forName("int");
- fail();
- } catch (ClassNotFoundException e) {
- }
-
- try {
- Class.forName("byte");
- fail();
- } catch (ClassNotFoundException e) {
- }
- try {
- Class.forName("char");
- fail();
- } catch (ClassNotFoundException e) {
- }
-
- try {
- Class.forName("void");
- fail();
- } catch (ClassNotFoundException e) {
- }
-
- try {
- Class.forName("short");
- fail();
- } catch (ClassNotFoundException e) {
- }
- try {
- Class.forName("long");
- fail();
- } catch (ClassNotFoundException e) {
- }
-
- try {
- Class.forName("boolean");
- fail();
- } catch (ClassNotFoundException e) {
- }
- try {
- Class.forName("float");
- fail();
- } catch (ClassNotFoundException e) {
- }
- try {
- Class.forName("double");
- fail();
- } catch (ClassNotFoundException e) {
- }
-
- //regression test for JIRA 2162
- try {
- Class.forName("%");
- fail("should throw ClassNotFoundException.");
- } catch (ClassNotFoundException e) {
- }
-
- //Regression Test for HARMONY-3332
- String securityProviderClassName;
- int count = 1;
- while ((securityProviderClassName = Security
- .getProperty("security.provider." + count++)) != null) {
- Class.forName(securityProviderClassName);
- }
-
- try {
- Class.forName(classNameInitError1);
- fail("ExceptionInInitializerError or ClassNotFoundException " +
- "expected.");
- } catch (java.lang.ExceptionInInitializerError ie) {
- // Expected for the RI.
- } catch (java.lang.ClassNotFoundException ce) {
- // Expected for Android.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "forName",
- args = {java.lang.String.class, boolean.class, java.lang.ClassLoader.class}
- )
- public void test_forNameLjava_lang_StringLbooleanLClassLoader() throws Exception {
-
- ClassLoader pcl = getClass().getClassLoader();
-
- Class<?> [] classes = {PublicTestClass.class, ExtendTestClass.class,
- ExtendTestClass1.class, TestInterface.class, String.class};
-
- for(int i = 0; i < classes.length; i++) {
- Class<?> clazz = Class.forName(classes[i].getName(), true, pcl);
- assertEquals(classes[i], clazz);
-
- clazz = Class.forName(classes[i].getName(), false, pcl);
- assertEquals(classes[i], clazz);
- }
-
- Class<?> [] systemClasses = {String.class, Integer.class, Object.class,
- Object[].class};
-
- for(int i = 0; i < systemClasses.length; i++) {
- Class<?> clazz = Class.forName(systemClasses[i].getName(), true,
- ClassLoader.getSystemClassLoader());
- assertEquals(systemClasses[i], clazz);
-
- clazz = Class.forName(systemClasses[i].getName(), false,
- ClassLoader.getSystemClassLoader());
- assertEquals(systemClasses[i], clazz);
- }
-
- try {
- Class.forName(null, true, pcl);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- Class.forName("NotExistClass", true, pcl);
- fail("ClassNotFoundException is not thrown for non existent class.");
- } catch(ClassNotFoundException cnfe) {
- //expected
- }
-
- try {
- Class.forName("String", false, pcl);
- fail("ClassNotFoundException is not thrown for non existent class.");
- } catch(ClassNotFoundException cnfe) {
- //expected
- }
-
- try {
- Class.forName("org.apache.harmony.luni.tests.java.PublicTestClass",
- false, pcl);
- fail("ClassNotFoundException is not thrown for non existent class.");
- } catch(ClassNotFoundException cnfe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "forName",
- args = {java.lang.String.class, boolean.class, java.lang.ClassLoader.class}
- )
- @AndroidOnly("Class.forName method throws ClassNotFoundException on " +
- "Android.")
- public void test_forNameLjava_lang_StringLbooleanLClassLoader_AndroidOnly() throws Exception {
-
- // Android doesn't support loading class files from a jar.
- try {
-
- URL url = getClass().getClassLoader().getResource(
- packageName.replace(".", "/") + "/" + sourceJARfile);
-
- ClassLoader loader = new URLClassLoader(new URL[] { url },
- getClass().getClassLoader());
- try {
- Class.forName(classNameLinkageError, true, loader);
- fail("LinkageError or ClassNotFoundException expected.");
- } catch (java.lang.LinkageError le) {
- // Expected for the RI.
- } catch (java.lang.ClassNotFoundException ce) {
- // Expected for Android.
- }
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.toString());
- }
-
- try {
- Class.forName(classNameInitError2,
- true, getClass().getClassLoader());
- fail("ExceptionInInitializerError or ClassNotFoundException " +
- "should be thrown.");
- } catch (java.lang.ExceptionInInitializerError ie) {
- // Expected for the RI.
- // Remove this comment to let the test pass on Android.
- } catch (java.lang.ClassNotFoundException ce) {
- // Expected for Android.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getAnnotation",
- args = {java.lang.Class.class}
- )
- public void test_getAnnotation() {
- TestAnnotation target = PublicTestClass.class.getAnnotation(TestAnnotation.class);
- assertEquals(target.value(), PublicTestClass.class.getName());
-
- assertNull(PublicTestClass.class.getAnnotation(Deprecated.class));
-
- Deprecated target2 = ExtendTestClass.class.getAnnotation(Deprecated.class);
- assertNotNull(target2);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredAnnotations",
- args = {}
- )
- public void test_getDeclaredAnnotations() {
- Annotation [] annotations = PublicTestClass.class.getDeclaredAnnotations();
- assertEquals(1, annotations.length);
-
- annotations = ExtendTestClass.class.getDeclaredAnnotations();
- assertEquals(2, annotations.length);
-
- annotations = TestInterface.class.getDeclaredAnnotations();
- assertEquals(0, annotations.length);
-
- annotations = String.class.getDeclaredAnnotations();
- assertEquals(0, annotations.length);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEnclosingClass",
- args = {}
- )
- public void test_getEnclosingClass() {
- Class clazz = ExtendTestClass.class.getEnclosingClass();
- assertNull(clazz);
-
- assertEquals(getClass(), Cls1.class.getEnclosingClass());
- assertEquals(getClass(), Intf1.class.getEnclosingClass());
- assertEquals(getClass(), Cls4.class.getEnclosingClass());
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEnclosingMethod",
- args = {}
- )
- public void test_getEnclosingMethod() {
- Method clazz = ExtendTestClass.class.getEnclosingMethod();
- assertNull(clazz);
-
- PublicTestClass ptc = new PublicTestClass();
- try {
- assertEquals("getEnclosingMethod returns incorrect method.",
- PublicTestClass.class.getMethod("getLocalClass",
- (Class []) null),
- ptc.getLocalClass().getClass().getEnclosingMethod());
- } catch(NoSuchMethodException nsme) {
- fail("NoSuchMethodException was thrown.");
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEnclosingConstructor",
- args = {}
- )
- public void test_getEnclosingConstructor() {
-
- PublicTestClass ptc = new PublicTestClass();
-
- assertEquals("getEnclosingConstructor method returns incorrect class.",
- PublicTestClass.class.getConstructors()[0],
- ptc.clazz.getClass().getEnclosingConstructor());
-
- assertNull("getEnclosingConstructor should return null for local " +
- "class declared in method.",
- ptc.getLocalClass().getClass().getEnclosingConstructor());
-
- assertNull("getEnclosingConstructor should return null for local " +
- "class declared in method.",
- ExtendTestClass.class.getEnclosingConstructor());
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEnumConstants",
- args = {}
- )
- public void test_getEnumConstants() {
- Object [] clazz = ExtendTestClass.class.getEnumConstants();
- assertNull(clazz);
- Object [] constants = TestEnum.class.getEnumConstants();
- assertEquals(TestEnum.values().length, constants.length);
- for(int i = 0; i < constants.length; i++) {
- assertEquals(TestEnum.values()[i], constants[i]);
- }
- assertEquals(0, TestEmptyEnum.class.getEnumConstants().length);
- }
- public enum TestEnum {
- ONE, TWO, THREE
- }
- public enum TestEmptyEnum {
- }
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "GenericSignatureFormatError, TypeNotPresentException, " +
- "MalformedParameterizedTypeException are not verified.",
- method = "getGenericInterfaces",
- args = {}
- )
- public void test_getGenericInterfaces() {
- Type [] types = ExtendTestClass1.class.getGenericInterfaces();
- assertEquals(0, types.length);
-
- Class [] interfaces = {TestInterface.class, Serializable.class,
- Cloneable.class};
- types = PublicTestClass.class.getGenericInterfaces();
- assertEquals(interfaces.length, types.length);
- for(int i = 0; i < types.length; i++) {
- assertEquals(interfaces[i], types[i]);
- }
-
- types = TestInterface.class.getGenericInterfaces();
- assertEquals(0, types.length);
-
- types = List.class.getGenericInterfaces();
- assertEquals(1, types.length);
- assertEquals(Collection.class, ((ParameterizedType)types[0]).getRawType());
-
- assertEquals(0, int.class.getGenericInterfaces().length);
- assertEquals(0, void.class.getGenericInterfaces().length);
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "GenericSignatureFormatError, TypeNotPresentException, MalformedParameterizedTypeException are not verified.",
- method = "getGenericSuperclass",
- args = {}
- )
- public void test_getGenericSuperclass () {
- assertEquals(PublicTestClass.class,
- ExtendTestClass.class.getGenericSuperclass());
- assertEquals(ExtendTestClass.class,
- ExtendTestClass1.class.getGenericSuperclass());
- assertEquals(Object.class, PublicTestClass.class.getGenericSuperclass());
- assertEquals(Object.class, String.class.getGenericSuperclass());
- assertEquals(null, TestInterface.class.getGenericSuperclass());
-
- ParameterizedType type = (ParameterizedType) Vector.class.getGenericSuperclass();
- assertEquals(AbstractList.class, type.getRawType());
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- method = "getPackage",
- args = {}
- )
- @AndroidOnly("Uses dalvik.system.PathClassLoader.")
- @BrokenTest("Different behavior between cts host and run-core-test")
- public void test_getPackage() {
-
- Package thisPackage = getClass().getPackage();
- assertEquals("org.apache.harmony.luni.tests.java.lang",
- thisPackage.getName());
-
- Package stringPackage = String.class.getPackage();
- assertNotNull("java.lang", stringPackage.getName());
-
- String hyts_package_name = "hyts_package_dex.jar";
- File resources = Support_Resources.createTempFolder();
- Support_Resources.copyFile(resources, "Package", hyts_package_name);
-
- String resPath = resources.toString();
- if (resPath.charAt(0) == '/' || resPath.charAt(0) == '\\')
- resPath = resPath.substring(1);
-
- try {
-
- URL resourceURL = new URL("file:/" + resPath + "/Package/"
- + hyts_package_name);
-
- ClassLoader cl = Support_ClassLoader.getInstance(resourceURL,
- getClass().getClassLoader());
-
- Class clazz = cl.loadClass("C");
- assertNull("getPackage for C.class should return null",
- clazz.getPackage());
-
- clazz = cl.loadClass("a.b.C");
- Package cPackage = clazz.getPackage();
- assertNotNull("getPackage for a.b.C.class should not return null",
- cPackage);
-
- /*
- * URLClassLoader doesn't work on Android for jar files
- *
- * URL url = getClass().getClassLoader().getResource(
- * packageName.replace(".", "/") + "/" + sourceJARfile);
- *
- * ClassLoader loader = new URLClassLoader(new URL[] { url }, null);
- *
- * try {
- * Class<?> clazz = loader.loadClass(illegalClassName);
- * Package pack = clazz.getPackage();
- * assertNull(pack);
- * } catch(ClassNotFoundException cne) {
- * fail("ClassNotFoundException was thrown for " + illegalClassName);
- * }
- */
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.toString());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "getSigners",
- args = {}
- )
- public void test_getSigners() {
- assertNull(void.class.getSigners());
- assertNull(PublicTestClass.class.getSigners());
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getSimpleName",
- args = {}
- )
- public void test_getSimpleName() {
- assertEquals("PublicTestClass", PublicTestClass.class.getSimpleName());
- assertEquals("void", void.class.getSimpleName());
- assertEquals("int[]", int[].class.getSimpleName());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTypeParameters",
- args = {}
- )
- public void test_getTypeParameters() {
- assertEquals(0, PublicTestClass.class.getTypeParameters().length);
- TypeVariable [] tv = TempTestClass1.class.getTypeParameters();
- assertEquals(1, tv.length);
- assertEquals(Object.class, tv[0].getBounds()[0]);
-
- TempTestClass2<String> tc = new TempTestClass2<String>();
- tv = tc.getClass().getTypeParameters();
- assertEquals(1, tv.length);
- assertEquals(String.class, tv[0].getBounds()[0]);
- }
-
- class TempTestClass1<T> {
- }
-
- class TempTestClass2<S extends String> extends TempTestClass1<S> {
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isAnnotation",
- args = {}
- )
- public void test_isAnnotation() {
- assertTrue(Deprecated.class.isAnnotation());
- assertTrue(TestAnnotation.class.isAnnotation());
- assertFalse(PublicTestClass.class.isAnnotation());
- assertFalse(String.class.isAnnotation());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isAnnotationPresent",
- args = {java.lang.Class.class}
- )
- public void test_isAnnotationPresent() {
- assertTrue(PublicTestClass.class.isAnnotationPresent(TestAnnotation.class));
- assertFalse(ExtendTestClass1.class.isAnnotationPresent(TestAnnotation.class));
- assertFalse(String.class.isAnnotationPresent(Deprecated.class));
- assertTrue(ExtendTestClass.class.isAnnotationPresent(TestAnnotation.class));
- assertTrue(ExtendTestClass.class.isAnnotationPresent(Deprecated.class));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isAnonymousClass",
- args = {}
- )
- public void test_isAnonymousClass() {
- assertFalse(PublicTestClass.class.isAnonymousClass());
- assertTrue((new Thread() {}).getClass().isAnonymousClass());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isEnum",
- args = {}
- )
- public void test_isEnum() {
- assertFalse(PublicTestClass.class.isEnum());
- assertFalse(ExtendTestClass.class.isEnum());
- assertTrue(TestEnum.ONE.getClass().isEnum());
- assertTrue(TestEnum.class.isEnum());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isLocalClass",
- args = {}
- )
- public void test_isLocalClass() {
- assertFalse(ExtendTestClass.class.isLocalClass());
- assertFalse(TestInterface.class.isLocalClass());
- assertFalse(TestEnum.class.isLocalClass());
- class InternalClass {}
- assertTrue(InternalClass.class.isLocalClass());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isMemberClass",
- args = {}
- )
- public void test_isMemberClass() {
- assertFalse(ExtendTestClass.class.isMemberClass());
- assertFalse(TestInterface.class.isMemberClass());
- assertFalse(String.class.isMemberClass());
- assertTrue(TestEnum.class.isMemberClass());
- assertTrue(StaticMember$Class.class.isMemberClass());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isSynthetic",
- args = {}
- )
- public void test_isSynthetic() {
- assertFalse("Returned true for non synthetic class.",
- ExtendTestClass.class.isSynthetic());
- assertFalse("Returned true for non synthetic class.",
- TestInterface.class.isSynthetic());
- assertFalse("Returned true for non synthetic class.",
- String.class.isSynthetic());
-
- String className = "org.apache.harmony.luni.tests.java.lang.ClassLoaderTest$1";
-
- /*
- *try {
- * assertTrue("Returned false for synthetic class.",
- * getClass().getClassLoader().loadClass(className).
- * isSynthetic());
- *} catch(ClassNotFoundException cnfe) {
- * fail("Class " + className + " can't be found.");
- *}
- */
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInstance",
- args = {java.lang.Object.class}
- )
- public void test_isInstance() {
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCanonicalName",
- args = {}
- )
- public void test_getCanonicalName() {
- String name = int[].class.getCanonicalName();
- Class [] classArray = { int.class, int[].class, String.class,
- PublicTestClass.class, TestInterface.class,
- ExtendTestClass.class };
- String [] classNames = {"int", "int[]", "java.lang.String",
- "org.apache.harmony.luni.tests.java.lang.PublicTestClass",
- "org.apache.harmony.luni.tests.java.lang.TestInterface",
- "org.apache.harmony.luni.tests.java.lang.ExtendTestClass"};
-
- for(int i = 0; i < classArray.length; i++) {
- assertEquals(classNames[i], classArray[i].getCanonicalName());
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getClassLoader",
- args = {}
- )
- public void test_getClassLoader() {
- assertEquals(ExtendTestClass.class.getClassLoader(),
- PublicTestClass.class.getClassLoader());
-
- assertNull(int.class.getClassLoader());
- assertNull(void.class.getClassLoader());
- }
-
- /**
- * @tests java.lang.Class#getClasses()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getClasses",
- args = {}
- )
- public void test_getClasses() {
- assertEquals("Incorrect class array returned",
- 4, ClassTest.class.getClasses().length);
- }
-
- /**
- * @tests java.lang.Class#getComponentType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getComponentType",
- args = {}
- )
- public void test_getComponentType() {
- assertSame("int array does not have int component type", int.class, int[].class
- .getComponentType());
- assertSame("Object array does not have Object component type", Object.class,
- Object[].class.getComponentType());
- assertNull("Object has non-null component type", Object.class.getComponentType());
- }
-
- /**
- * @tests java.lang.Class#getConstructor(java.lang.Class[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConstructor",
- args = {java.lang.Class[].class}
- )
- public void test_getConstructor$Ljava_lang_Class()
- throws NoSuchMethodException {
- Constructor constr = TestClass.class.getConstructor(new Class[0]);
- assertNotNull(constr);
- assertEquals("org.apache.harmony.luni.tests.java.lang.ClassTest$TestClass",
- constr.getName());
- try {
- TestClass.class.getConstructor(Object.class);
- fail("Found private constructor");
- } catch (NoSuchMethodException e) {
- // Correct - constructor with obj is private
- }
- }
-
- /**
- * @tests java.lang.Class#getConstructors()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConstructors",
- args = {}
- )
- public void test_getConstructors() throws Exception {
- Constructor[] c = TestClass.class.getConstructors();
- assertEquals("Incorrect number of constructors returned", 1, c.length);
- }
-
- /**
- * @tests java.lang.Class#getDeclaredClasses()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredClasses",
- args = {}
- )
- public void test_getDeclaredClasses() {
-
- Class [] declClasses = Object.class.getDeclaredClasses();
- assertEquals("Incorrect length of declared classes array is returned " +
- "for Object.", 0, declClasses.length);
-
- declClasses = PublicTestClass.class.getDeclaredClasses();
- assertEquals(2, declClasses.length);
-
- assertEquals(0, int.class.getDeclaredClasses().length);
- assertEquals(0, void.class.getDeclaredClasses().length);
-
- for(int i = 0; i < declClasses.length; i++) {
- Constructor<?> constr = declClasses[i].getDeclaredConstructors()[0];
- constr.setAccessible(true);
- PublicTestClass publicClazz = new PublicTestClass();
- try {
- Object o = constr.newInstance(publicClazz);
- assertTrue("Returned incorrect class: " + o.toString(),
- o.toString().startsWith("PrivateClass"));
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.toString());
- }
- }
-
-
- declClasses = TestInterface.class.getDeclaredClasses();
- assertEquals(0, declClasses.length);
- }
-
-
- /**
- * @tests java.lang.Class#getDeclaredConstructor(java.lang.Class[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredConstructor",
- args = {java.lang.Class[].class}
- )
- public void test_getDeclaredConstructor$Ljava_lang_Class() throws Exception {
- Constructor<TestClass> c = TestClass.class.getDeclaredConstructor(new Class[0]);
- assertNull("Incorrect constructor returned", c.newInstance().cValue());
- c = TestClass.class.getDeclaredConstructor(Object.class);
-
- try {
- TestClass.class.getDeclaredConstructor(String.class);
- fail("NoSuchMethodException should be thrown.");
- } catch(NoSuchMethodException nsme) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getDeclaredConstructors()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredConstructors",
- args = {}
- )
- public void test_getDeclaredConstructors() throws Exception {
- Constructor[] c = TestClass.class.getDeclaredConstructors();
- assertEquals("Incorrect number of constructors returned", 2, c.length);
- }
-
- /**
- * @tests java.lang.Class#getDeclaredField(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredField",
- args = {java.lang.String.class}
- )
- public void test_getDeclaredFieldLjava_lang_String() throws Exception {
- Field f = TestClass.class.getDeclaredField("pubField");
- assertEquals("Returned incorrect field", 2, f.getInt(new TestClass()));
-
- try {
- TestClass.class.getDeclaredField(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- TestClass.class.getDeclaredField("NonExistentField");
- fail("NoSuchFieldException is not thrown.");
- } catch(NoSuchFieldException nsfe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getDeclaredFields()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredFields",
- args = {}
- )
- public void test_getDeclaredFields() throws Exception {
- Field[] f = TestClass.class.getDeclaredFields();
- assertEquals("Returned incorrect number of fields", 4, f.length);
- f = SubTestClass.class.getDeclaredFields();
- // Declared fields do not include inherited
- assertEquals("Returned incorrect number of fields", 0, f.length);
- }
-
- /**
- * @tests java.lang.Class#getDeclaredMethod(java.lang.String,
- * java.lang.Class[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredMethod",
- args = {java.lang.String.class, java.lang.Class[].class}
- )
- public void test_getDeclaredMethodLjava_lang_String$Ljava_lang_Class() throws Exception {
- Method m = TestClass.class.getDeclaredMethod("pubMethod", new Class[0]);
- assertEquals("Returned incorrect method", 2, ((Integer) (m.invoke(new TestClass())))
- .intValue());
- m = TestClass.class.getDeclaredMethod("privMethod", new Class[0]);
-
- try {
- TestClass.class.getDeclaredMethod(null, new Class[0]);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- TestClass.class.getDeclaredMethod("NonExistentMethod", new Class[0]);
- fail("NoSuchMethodException is not thrown.");
- } catch(NoSuchMethodException nsme) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getDeclaredMethods()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaredMethods",
- args = {}
- )
- public void test_getDeclaredMethods() throws Exception {
- Method[] m = TestClass.class.getDeclaredMethods();
- assertEquals("Returned incorrect number of methods", 3, m.length);
- m = SubTestClass.class.getDeclaredMethods();
- assertEquals("Returned incorrect number of methods", 0, m.length);
- }
-
- /**
- * @tests java.lang.Class#getDeclaringClass()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDeclaringClass",
- args = {}
- )
- public void test_getDeclaringClass() {
- assertEquals(ClassTest.class, TestClass.class.getDeclaringClass());
- assertNull(PublicTestClass.class.getDeclaringClass());
- }
-
- /**
- * @tests java.lang.Class#getField(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getField",
- args = {java.lang.String.class}
- )
- public void test_getFieldLjava_lang_String() throws Exception {
- Field f = TestClass.class.getField("pubField");
- assertEquals("Returned incorrect field", 2, f.getInt(new TestClass()));
-
- f = PublicTestClass.class.getField("TEST_FIELD");
- assertEquals("Returned incorrect field", "test field",
- f.get(new PublicTestClass()));
-
- f = PublicTestClass.class.getField("TEST_INTERFACE_FIELD");
- assertEquals("Returned incorrect field", 0,
- f.getInt(new PublicTestClass()));
-
- try {
- f = TestClass.class.getField("privField");
- fail("Private field access failed to throw exception");
- } catch (NoSuchFieldException e) {
- // Correct
- }
-
- try {
- TestClass.class.getField(null);
- fail("NullPointerException is thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getFields()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getFields",
- args = {}
- )
- public void test_getFields2() throws Exception {
- Field[] f;
- Field expected = null;
-
- f = PublicTestClass.class.getFields();
- assertEquals("Test 1: Incorrect number of fields;", 2, f.length);
-
- f = Cls2.class.getFields();
- assertEquals("Test 2: Incorrect number of fields;", 6, f.length);
-
- f = Cls3.class.getFields();
- assertEquals("Test 2: Incorrect number of fields;", 5, f.length);
-
- for (Field field : f) {
- if (field.toString().equals("public static final int org.apache" +
- ".harmony.luni.tests.java.lang.ClassTest$Intf3.field1")) {
- expected = field;
- break;
- }
- }
- if (expected == null) {
- fail("Test 3: getFields() did not return all fields.");
- }
- assertEquals("Test 4: Incorrect field;", expected,
- Cls3.class.getField("field1"));
-
- expected = null;
- for (Field field : f) {
- if(field.toString().equals("public static final int org.apache" +
- ".harmony.luni.tests.java.lang.ClassTest$Intf1.field2")) {
- expected = field;
- break;
- }
- }
- if (expected == null) {
- fail("Test 5: getFields() did not return all fields.");
- }
- assertEquals("Test 6: Incorrect field;", expected,
- Cls3.class.getField("field2"));
- }
-
- /**
- * @tests java.lang.Class#getFields()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getFields",
- args = {}
- )
- public void test_getFields() throws Exception {
- Field[] f = TestClass.class.getFields();
- assertEquals("Test 1: Incorrect number of fields;", 2, f.length);
- f = SubTestClass.class.getFields();
- // Check inheritance of pub fields
- assertEquals("Test 2: Incorrect number of fields;", 2, f.length);
-
- Field expected = null;
- Field[] fields = Cls2.class.getFields();
- for (Field field : fields) {
- if(field.toString().equals("public int org.apache.harmony.luni" +
- ".tests.java.lang.ClassTest$Cls2.field1")) {
- expected = field;
- break;
- }
- }
- if (expected == null) {
- fail("getFields() did not return all fields");
- }
- assertEquals(expected, Cls2.class.getField("field1"));
- }
-
- /**
- * @tests java.lang.Class#getInterfaces()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInterfaces",
- args = {}
- )
- public void test_getInterfaces() {
- Class[] interfaces;
- List<?> interfaceList;
- interfaces = Object.class.getInterfaces();
- assertEquals("Incorrect interface list for Object", 0, interfaces.length);
- interfaceList = Arrays.asList(Vector.class.getInterfaces());
- assertTrue("Incorrect interface list for Vector", interfaceList
- .contains(Cloneable.class)
- && interfaceList.contains(Serializable.class)
- && interfaceList.contains(List.class));
-
- Class [] interfaces1 = Cls1.class.getInterfaces();
- assertEquals(1, interfaces1.length);
- assertEquals(Intf2.class, interfaces1[0]);
-
- Class [] interfaces2 = Cls2.class.getInterfaces();
- assertEquals(1, interfaces2.length);
- assertEquals(Intf1.class, interfaces2[0]);
-
- Class [] interfaces3 = Cls3.class.getInterfaces();
- assertEquals(2, interfaces3.length);
- assertEquals(Intf3.class, interfaces3[0]);
- assertEquals(Intf4.class, interfaces3[1]);
-
- Class [] interfaces4 = Cls4.class.getInterfaces();
- assertEquals(0, interfaces4.length);
- }
-
- /**
- * @tests java.lang.Class#getMethod(java.lang.String, java.lang.Class[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMethod",
- args = {java.lang.String.class, java.lang.Class[].class}
- )
- public void test_getMethodLjava_lang_String$Ljava_lang_Class() throws Exception {
- Method m = TestClass.class.getMethod("pubMethod", new Class[0]);
- assertEquals("Returned incorrect method", 2, ((Integer) (m.invoke(new TestClass())))
- .intValue());
-
- m = ExtendTestClass1.class.getMethod("getCount", new Class[0]);
- assertEquals("Returned incorrect method", 0, ((Integer) (m.invoke(new ExtendTestClass1())))
- .intValue());
-
- try {
- m = TestClass.class.getMethod("privMethod", new Class[0]);
- fail("Failed to throw exception accessing private method");
- } catch (NoSuchMethodException e) {
- // Correct
- return;
- }
-
- try {
- m = TestClass.class.getMethod("init", new Class[0]);
- fail("Failed to throw exception accessing to init method");
- } catch (NoSuchMethodException e) {
- // Correct
- return;
- }
-
- try {
- TestClass.class.getMethod("pubMethod", new Class[0]);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getMethods()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMethods",
- args = {}
- )
- public void test_getMethods() throws Exception {
- Method[] m = TestClass.class.getMethods();
- assertEquals("Returned incorrect number of methods",
- 2 + Object.class.getMethods().length, m.length);
- m = SubTestClass.class.getMethods();
- assertEquals("Returned incorrect number of sub-class methods",
- 2 + Object.class.getMethods().length, m.length);
- // Number of inherited methods
-
- assertEquals("Incorrect number of methods", 10,
- Cls2.class.getMethods().length);
- assertEquals("Incorrect number of methods", 11,
- Cls3.class.getMethods().length);
-
- Method expected = null;
- Method[] methods = Cls2.class.getMethods();
- for (Method method : methods) {
- if(method.toString().equals("public void org.apache.harmony.luni" +
- ".tests.java.lang.ClassTest$Cls2.test()")) {
- expected = method;
- break;
- }
- }
- if (expected == null) {
- fail("getMethods() did not return all methods");
- }
- assertEquals(expected, Cls2.class.getMethod("test"));
-
- expected = null;
- methods = Cls3.class.getMethods();
- for (Method method : methods) {
- if(method.toString().equals("public void org.apache.harmony.luni" +
- ".tests.java.lang.ClassTest$Cls3.test()")) {
- expected = method;
- break;
- }
- }
- if (expected == null) {
- fail("getMethods() did not return all methods");
- }
- assertEquals(expected, Cls3.class.getMethod("test"));
-
- expected = null;
- methods = Cls3.class.getMethods();
- for (Method method : methods) {
- if(method.toString().equals("public void org.apache.harmony.luni" +
- ".tests.java.lang.ClassTest$Cls3.test2(int," +
- "java.lang.Object)")) {
- expected = method;
- break;
- }
- }
- if (expected == null) {
- fail("getMethods() did not return all methods");
- }
-
- assertEquals(expected, Cls3.class.getMethod("test2", int.class,
- Object.class));
-
- assertEquals("Incorrect number of methods", 1,
- Intf5.class.getMethods().length);
- }
-
- private static final class PrivateClass {
- }
- /**
- * @tests java.lang.Class#getModifiers()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getModifiers",
- args = {}
- )
- public void test_getModifiers() {
- int dcm = PrivateClass.class.getModifiers();
- assertFalse("default class is public", Modifier.isPublic(dcm));
- assertFalse("default class is protected", Modifier.isProtected(dcm));
- assertTrue("default class is not private", Modifier.isPrivate(dcm));
-
- int ocm = Object.class.getModifiers();
- assertTrue("public class is not public", Modifier.isPublic(ocm));
- assertFalse("public class is protected", Modifier.isProtected(ocm));
- assertFalse("public class is private", Modifier.isPrivate(ocm));
- }
-
- /**
- * @tests java.lang.Class#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getName",
- args = {}
- )
- public void test_getName() throws Exception {
- String className = Class.forName("java.lang.Object").getName();
- assertNotNull(className);
-
- assertEquals("Class getName printed wrong value", "java.lang.Object", className);
- assertEquals("Class getName printed wrong value", "int", int.class.getName());
- className = Class.forName("[I").getName();
- assertNotNull(className);
- assertEquals("Class getName printed wrong value", "[I", className);
-
- className = Class.forName("[Ljava.lang.Object;").getName();
- assertNotNull(className);
-
- assertEquals("Class getName printed wrong value", "[Ljava.lang.Object;", className);
- }
-
- /**
- * @tests java.lang.Class#getResource(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getResource",
- args = {java.lang.String.class}
- )
- public void test_getResourceLjava_lang_String() {
- final String name = "/";
- URL res = getClass().getResource(name + "HelloWorld.txt");
- assertNotNull(res);
- assertNull(getClass().getResource(
- "org/apache/harmony/luni/tests/java/lang/NonExistentResource"));
- assertNull(getClass().getResource(name + "NonExistentResource"));
- }
-
- /**
- * @tests java.lang.Class#getResourceAsStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getResourceAsStream",
- args = {java.lang.String.class}
- )
- public void test_getResourceAsStreamLjava_lang_String() throws Exception {
- String name = "/HelloWorld.txt";
- assertNotNull("the file " + name + " can not be found in this " +
- "directory", getClass().getResourceAsStream(name));
-
- final String nameBadURI = "org/apache/harmony/luni/tests/" +
- "test_resource.txt";
- assertNull("the file " + nameBadURI + " should not be found in this " +
- "directory",
- getClass().getResourceAsStream(nameBadURI));
-
- ClassLoader pcl = getClass().getClassLoader();
- Class<?> clazz = pcl.loadClass("org.apache.harmony.luni.tests.java.lang.ClassTest");
- assertNotNull(clazz.getResourceAsStream("HelloWorld1.txt"));
-
- try {
- getClass().getResourceAsStream(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#getSuperclass()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getSuperclass",
- args = {}
- )
- public void test_getSuperclass() {
- assertNull("Object has a superclass???", Object.class.getSuperclass());
- assertSame("Normal class has bogus superclass", InputStream.class,
- FileInputStream.class.getSuperclass());
- assertSame("Array class has bogus superclass", Object.class, FileInputStream[].class
- .getSuperclass());
- assertNull("Base class has a superclass", int.class.getSuperclass());
- assertNull("Interface class has a superclass", Cloneable.class.getSuperclass());
- }
-
- /**
- * @tests java.lang.Class#isArray()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isArray",
- args = {}
- )
- public void test_isArray() throws ClassNotFoundException {
- assertTrue("Non-array type claims to be.", !int.class.isArray());
- Class<?> clazz = null;
- clazz = Class.forName("[I");
- assertTrue("int Array type claims not to be.", clazz.isArray());
-
- clazz = Class.forName("[Ljava.lang.Object;");
- assertTrue("Object Array type claims not to be.", clazz.isArray());
-
- clazz = Class.forName("java.lang.Object");
- assertTrue("Non-array Object type claims to be.", !clazz.isArray());
- }
-
- /**
- * @tests java.lang.Class#isAssignableFrom(java.lang.Class)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isAssignableFrom",
- args = {java.lang.Class.class}
- )
- public void test_isAssignableFromLjava_lang_Class() {
- Class<?> clazz1 = null;
- Class<?> clazz2 = null;
-
- clazz1 = Object.class;
- clazz2 = Class.class;
- assertTrue("returned false for superclass",
- clazz1.isAssignableFrom(clazz2));
-
- clazz1 = TestClass.class;
- assertTrue("returned false for same class",
- clazz1.isAssignableFrom(clazz1));
-
- clazz1 = Runnable.class;
- clazz2 = Thread.class;
- assertTrue("returned false for implemented interface",
- clazz1.isAssignableFrom(clazz2));
-
- assertFalse("returned true not assignable classes",
- Integer.class.isAssignableFrom(String.class));
-
- try {
- clazz1.isAssignableFrom(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#isInterface()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInterface",
- args = {}
- )
- public void test_isInterface() throws ClassNotFoundException {
- assertTrue("Prim type claims to be interface.", !int.class.isInterface());
- Class<?> clazz = null;
- clazz = Class.forName("[I");
- assertTrue("Prim Array type claims to be interface.", !clazz.isInterface());
-
- clazz = Class.forName("java.lang.Runnable");
- assertTrue("Interface type claims not to be interface.", clazz.isInterface());
- clazz = Class.forName("java.lang.Object");
- assertTrue("Object type claims to be interface.", !clazz.isInterface());
-
- clazz = Class.forName("[Ljava.lang.Object;");
- assertTrue("Array type claims to be interface.", !clazz.isInterface());
- }
-
- /**
- * @tests java.lang.Class#isPrimitive()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isPrimitive",
- args = {}
- )
- public void test_isPrimitive() {
- assertFalse("Interface type claims to be primitive.",
- Runnable.class.isPrimitive());
- assertFalse("Object type claims to be primitive.",
- Object.class.isPrimitive());
- assertFalse("Prim Array type claims to be primitive.",
- int[].class.isPrimitive());
- assertFalse("Array type claims to be primitive.",
- Object[].class.isPrimitive());
- assertTrue("Prim type claims not to be primitive.",
- int.class.isPrimitive());
- assertFalse("Object type claims to be primitive.",
- Object.class.isPrimitive());
- }
-
- /**
- * @tests java.lang.Class#newInstance()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newInstance",
- args = {}
- )
- public void test_newInstance() throws Exception {
- Class<?> clazz = null;
- clazz = Class.forName("java.lang.Object");
- assertNotNull("new object instance was null", clazz.newInstance());
-
- clazz = Class.forName("java.lang.Throwable");
- assertSame("new Throwable instance was not a throwable",
- clazz, clazz.newInstance().getClass());
-
- clazz = Class.forName("java.lang.Integer");
- try {
- clazz.newInstance();
- fail("Exception for instantiating a newInstance with no default " +
- " constructor is not thrown");
- } catch (InstantiationException e) {
- // expected
- }
-
- try {
- TestClass3.class.newInstance();
- fail("IllegalAccessException is not thrown.");
- } catch(IllegalAccessException iae) {
- //expected
- }
-
- try {
- TestClass1C.class.newInstance();
- fail("ExceptionInInitializerError should be thrown.");
- } catch (java.lang.ExceptionInInitializerError ie) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Class#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() throws ClassNotFoundException {
- assertEquals("Class toString printed wrong value",
- "int", int.class.toString());
- Class<?> clazz = null;
- clazz = Class.forName("[I");
- assertEquals("Class toString printed wrong value",
- "class [I", clazz.toString());
-
- clazz = Class.forName("java.lang.Object");
- assertEquals("Class toString printed wrong value",
- "class java.lang.Object", clazz.toString());
-
- clazz = Class.forName("[Ljava.lang.Object;");
- assertEquals("Class toString printed wrong value",
- "class [Ljava.lang.Object;", clazz.toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getResourceAsStream",
- args = {java.lang.String.class}
- )
- // Regression Test for JIRA-2047
- public void test_getResourceAsStream_withSharpChar() throws Exception{
- InputStream in = getClass().getResourceAsStream("/" + FILENAME);
- assertNotNull(in);
- in.close();
-
- in = getClass().getResourceAsStream(FILENAME);
- assertNull(in);
-
- in = this.getClass().getClassLoader().getResourceAsStream(
- FILENAME);
- assertNotNull(in);
- in.close();
- }
-
- /*
- * Regression test for HARMONY-2644:
- * Load system and non-system array classes via Class.forName()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClassNotFoundException.",
- method = "forName",
- args = {java.lang.String.class}
- )
- public void test_forName_arrays() throws Exception {
- Class<?> c1 = getClass();
- String s = c1.getName();
- Class<?> a1 = Class.forName("[L" + s + ";");
- Class<?> a2 = Class.forName("[[L" + s + ";");
- assertSame(c1, a1.getComponentType());
- assertSame(a1, a2.getComponentType());
- Class<?> l4 = Class.forName("[[[[[J");
- assertSame(long[][][][][].class, l4);
-
- try{
- Class<?> clazz = Class.forName("[;");
- fail("1: " + clazz);
- } catch (ClassNotFoundException ok) {}
- try{
- Class<?> clazz = Class.forName("[[");
- fail("2:" + clazz);
- } catch (ClassNotFoundException ok) {}
- try{
- Class<?> clazz = Class.forName("[L");
- fail("3:" + clazz);
- } catch (ClassNotFoundException ok) {}
- try{
- Class<?> clazz = Class.forName("[L;");
- fail("4:" + clazz);
- } catch (ClassNotFoundException ok) {}
- try{
- Class<?> clazz = Class.forName(";");
- fail("5:" + clazz);
- } catch (ClassNotFoundException ok) {}
- try{
- Class<?> clazz = Class.forName("");
- fail("6:" + clazz);
- } catch (ClassNotFoundException ok) {}
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asSubclass",
- args = {java.lang.Class.class}
- )
- public void test_asSubclass1() {
- assertEquals(ExtendTestClass.class,
- ExtendTestClass.class.asSubclass(PublicTestClass.class));
-
- assertEquals(PublicTestClass.class,
- PublicTestClass.class.asSubclass(TestInterface.class));
-
- assertEquals(ExtendTestClass1.class,
- ExtendTestClass1.class.asSubclass(PublicTestClass.class));
-
- assertEquals(PublicTestClass.class,
- PublicTestClass.class.asSubclass(PublicTestClass.class));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asSubclass",
- args = {java.lang.Class.class}
- )
- public void test_asSubclass2() {
- try {
- PublicTestClass.class.asSubclass(ExtendTestClass.class);
- fail("Test 1: ClassCastException expected.");
- } catch(ClassCastException cce) {
- // Expected.
- }
-
- try {
- PublicTestClass.class.asSubclass(String.class);
- fail("Test 2: ClassCastException expected.");
- } catch(ClassCastException cce) {
- // Expected.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "cast",
- args = {java.lang.Object.class}
- )
- public void test_cast() {
- Object o = PublicTestClass.class.cast(new ExtendTestClass());
- assertTrue(o instanceof ExtendTestClass);
-
- try {
- ExtendTestClass.class.cast(new PublicTestClass());
- fail("Test 1: ClassCastException expected.");
- } catch(ClassCastException cce) {
- //expected
- }
-
- try {
- ExtendTestClass.class.cast(new String());
- fail("ClassCastException is not thrown.");
- } catch(ClassCastException cce) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "desiredAssertionStatus",
- args = {}
- )
- public void test_desiredAssertionStatus() {
- Class [] classArray = { Object.class, Integer.class,
- String.class, PublicTestClass.class,
- ExtendTestClass.class, ExtendTestClass1.class};
-
- for(int i = 0; i < classArray.length; i++) {
- assertFalse("assertion status for " + classArray[i],
- classArray[i].desiredAssertionStatus());
- }
- }
-
-
-
- SecurityManager sm = new SecurityManager() {
-
- final String forbidenPermissionName = "user.dir";
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals(forbidenPermissionName)) {
- throw new SecurityException();
- }
- }
-
- public void checkMemberAccess(Class<?> clazz,
- int which) {
- if(clazz.equals(TestClass.class)) {
- throw new SecurityException();
- }
- }
-
- public void checkPackageAccess(String pkg) {
- if(pkg.equals(TestClass.class.getPackage())) {
- throw new SecurityException();
- }
- }
-
- };
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest2.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest2.java
deleted file mode 100644
index ea69bb2..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest2.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-@TestTargetClass(Class.class)
-public class ClassTest2 extends junit.framework.TestCase {
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-
- /**
- * Tests loading a resource with a relative name.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getResourceAsStream",
- args = {java.lang.String.class}
- )
- public void testGetResourceAsStream1() throws IOException {
- Class clazz = getClass();
-
- InputStream stream = clazz.getResourceAsStream("HelloWorld.txt");
- assert(stream != null);
-
- byte[] buffer = new byte[20];
- int length = stream.read(buffer);
- String s = new String(buffer, 0, length);
- assert("Hello, World.".equals(s));
-
- stream.close();
- }
-
- /**
- * Tests loading a resource with a global name.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getResourceAsStream",
- args = {java.lang.String.class}
- )
- public void testGetResourceAsStream2() throws IOException {
- Class clazz = getClass();
-
- InputStream stream = clazz.getResourceAsStream("/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt");
- assert(stream != null);
-
- byte[] buffer = new byte[20];
- int length = stream.read(buffer);
- String s = new String(buffer, 0, length);
- assert("Hello, World.".equals(s));
-
- stream.close();
-
- try {
- clazz.getResourceAsStream(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- assertNull(clazz.getResourceAsStream("/NonExistentResource"));
- assertNull(clazz.getResourceAsStream("org/apache/harmony/luni/tests/java/lang/HelloWorld.txt"));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java
deleted file mode 100644
index da66da9..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CloneNotSupportedExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class CloneNotSupportedExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.CloneNotSupportedException#CloneNotSupportedException()
- */
- public void test_Constructor() {
- CloneNotSupportedException e = new CloneNotSupportedException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.CloneNotSupportedException#CloneNotSupportedException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- CloneNotSupportedException e = new CloneNotSupportedException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CompilerTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CompilerTest.java
deleted file mode 100644
index 4793a42..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/CompilerTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class CompilerTest extends TestCase {
-
- /**
- * @tests java.lang.Compiler#command(java.lang.Object)
- */
- public void test_commandLjava_lang_Object() {
- assertNull("Incorrect behavior.", Compiler.command(new Object()));
- }
-
- /**
- * @tests java.lang.Compiler#compileClass(java.lang.Class)
- */
- public void test_compileClassLjava_lang_Class() {
- // Do not test return value, may return true or false depending on
- // if the jit is enabled. Make the call to ensure it doesn't crash.
- Compiler.compileClass(Compiler.class);
- }
-
- /**
- * @tests java.lang.Compiler#compileClasses(java.lang.String)
- */
- public void test_compileClassesLjava_lang_String() {
- // Do not test return value, may return true or false depending on
- // if the jit is enabled. Make the call to ensure it doesn't crash.
- Compiler.compileClasses("Compiler");
- }
-
- /**
- * @tests java.lang.Compiler#disable()
- */
- public void test_disable() {
- Compiler.disable();
- Compiler.compileClass(Compiler.class);
- }
-
- /**
- * @tests java.lang.Compiler#enable()
- */
- public void test_enable() {
- Compiler.disable();
- Compiler.enable();
- Compiler.compileClass(Compiler.class);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
deleted file mode 100644
index 501e981..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/DoubleTest.java
+++ /dev/null
@@ -1,1661 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.util.Locale;
-
-@TestTargetClass(Double.class)
-public class DoubleTest extends TestCase {
- private static final long rawBitsFor3_4en324ToN1[] = { 0x1L, 0x7L, 0x45L, 0x2b0L, 0x1ae2L,
- 0x10cd1L, 0xa8028L, 0x69018dL, 0x41a0f7eL, 0x29049aedL, 0x19a2e0d44L,
- 0x1005cc84acL, 0xa039fd2ebdL, 0x64243e3d361L, 0x3e96a6e641c6L, 0x271e284fe91b8L,
- 0x1872d931f1b131L, 0x4e8f8f7e6e1d7dL, 0x8319b9af04d26eL, 0xb7e0281ac6070aL,
- 0xedd832217788ccL, 0x122a71f54eab580L, 0x15750e72a2562e0L, 0x18d2520f4aebb98L,
- 0x1c2373498ed353fL, 0x1f6c501bf28828eL, 0x22c76422ef2a332L, 0x261c9e95d57a5ffL,
- 0x2963c63b4ad8f7fL, 0x2cbcb7ca1d8f35fL, 0x3015f2de527981bL, 0x335b6f95e717e22L,
- 0x36b24b7b60dddabL, 0x3a0f6f2d1c8aa8bL, 0x3d534af863ad52dL, 0x40a81db67c98a79L,
- 0x440912920ddf68bL, 0x474b5736915742eL, 0x4a9e2d0435ad13aL, 0x4e02dc22a18c2c4L,
- 0x5143932b49ef375L, 0x549477f61c6b052L, 0x57f995f3a385c67L, 0x5b3bfdb846339c0L,
- 0x5e8afd2657c0830L, 0x61edbc6fedb0a3dL, 0x653495c5f48e666L, 0x6881bb3771b1fffL,
- 0x6be22a054e1e7ffL, 0x6f2d5a4350d30ffL, 0x7278b0d42507d3fL, 0x75d6dd092e49c8fL,
- 0x79264a25bcee1daL, 0x7c6fdcaf2c29a50L, 0x7fcbd3daf7340e4L, 0x831f6468da8088eL,
- 0x86673d831120ab2L, 0x89c10ce3d568d5fL, 0x8d18a80e656185bL, 0x905ed211feb9e72L,
- 0x93b686967e6860eL, 0x9712141e0f013c9L, 0x9a56992592c18bbL, 0x9dac3f6ef771eeaL,
- 0xa10ba7a55aa7352L, 0xa44e918eb151027L, 0xa7a235f25da5430L, 0xab0561b77a8749eL,
- 0xae46ba2559291c6L, 0xb19868aeaf73637L, 0xb4fe82da5b503c5L, 0xb83f11c8791225bL,
- 0xbb8ed63a9756af2L, 0xbef28bc93d2c5afL, 0xc237975dc63bb8dL, 0xc5857d3537caa70L,
- 0xc8e6dc8285bd50cL, 0xcc3049d19396528L, 0xcf7c5c45f87be72L, 0xd2db7357769ae0eL,
- 0xd6292816aa20cc9L, 0xd973721c54a8ffbL, 0xdcd04ea369d33faL, 0xe0223126222407cL,
- 0xe36abd6faaad09bL, 0xe6c56ccb95584c2L, 0xea1b63ff3d572f9L, 0xed623cff0cacfb8L,
- 0xf0bacc3ecfd83a5L, 0xf414bfa741e7247L, 0xf759ef911260ed9L, 0xfab06b7556f9290L,
- 0xfe0e4329565bb9aL, 0x10151d3f3abf2a80L, 0x104a648f096ef520L, 0x10807ed965e55934L,
- 0x10b49e8fbf5eaf81L, 0x10e9c633af365b61L, 0x11201be04d81f91dL, 0x115422d860e27764L,
- 0x11892b8e791b153dL, 0x11bf76721761da8cL, 0x11f3aa074e9d2898L, 0x12289489224472beL,
- 0x125eb9ab6ad58f6dL, 0x1293340b22c579a4L, 0x12c8010deb76d80dL, 0x12fe015166548e11L,
- 0x1332c0d2dff4d8caL, 0x1367710797f20efdL, 0x139d4d497dee92bcL, 0x13d2504deeb51bb6L,
- 0x1406e4616a6262a3L, 0x143c9d79c4fafb4cL, 0x1471e26c1b1cdd0fL, 0x14a65b0721e41453L,
- 0x14dbf1c8ea5d1968L, 0x1511771d927a2fe1L, 0x1545d4e4f718bbd9L, 0x157b4a1e34deead0L,
- 0x15b10e52e10b52c2L, 0x15e551e7994e2772L, 0x161aa6617fa1b14fL, 0x1650a7fcefc50ed1L,
- 0x1684d1fc2bb65286L, 0x16ba067b36a3e727L, 0x16f0440d02267078L, 0x1724551042b00c96L,
- 0x17596a54535c0fbcL, 0x178fc4e9683313abL, 0x17c3db11e11fec4bL, 0x17f8d1d65967e75eL,
- 0x182f064befc1e135L, 0x186363ef75d92cc1L, 0x18983ceb534f77f1L, 0x18ce4c26282355eeL,
- 0x1902ef97d91615b5L, 0x1937ab7dcf5b9b22L, 0x196d965d433281eaL, 0x19a27dfa49ff9132L,
- 0x19d71d78dc7f757fL, 0x1a0ce4d7139f52dfL, 0x1a420f066c4393cbL, 0x1a7692c8075478beL,
- 0x1aac377a092996edL, 0x1ae1a2ac45b9fe54L, 0x1b160b5757287de9L, 0x1b4b8e2d2cf29d64L,
- 0x1b8138dc3c17a25eL, 0x1bb587134b1d8af6L, 0x1beae8d81de4edb4L, 0x1c20d18712af1490L,
- 0x1c5505e8d75ad9b4L, 0x1c8a47630d319021L, 0x1cc06c9de83efa15L, 0x1cf487c5624eb89aL,
- 0x1d29a9b6bae266c1L, 0x1d600a1234cd8038L, 0x1d940c96c200e046L, 0x1dc90fbc72811858L,
- 0x1dff53ab8f215e6eL, 0x1e33944b3974db05L, 0x1e68795e07d211c6L, 0x1e9e97b589c69637L,
- 0x1ed31ed1761c1de3L, 0x1f07e685d3a3255bL, 0x1f3de027488beeb2L, 0x1f72ac188d57752fL,
- 0x1fa7571eb0ad527bL, 0x1fdd2ce65cd8a71aL, 0x20123c0ffa076870L, 0x2046cb13f889428cL,
- 0x207c7dd8f6ab932fL, 0x20b1cea79a2b3bfeL, 0x20e6425180b60afdL, 0x211bd2e5e0e38dbcL,
- 0x215163cfac8e3896L, 0x2185bcc397b1c6bbL, 0x21bb2bf47d9e386aL, 0x21f0fb78ce82e342L,
- 0x22253a5702239c13L, 0x225a88ecc2ac8317L, 0x22909593f9abd1efL, 0x22c4baf8f816c66aL,
- 0x22f9e9b7361c7805L, 0x2330321281d1cb03L, 0x23643e9722463dc4L, 0x23994e3cead7cd35L,
- 0x23cfa1cc258dc082L, 0x2403c51f97789851L, 0x2438b6677d56be65L, 0x246ee4015cac6dffL,
- 0x24a34e80d9ebc4bfL, 0x24d822211066b5efL, 0x250e2aa95480636bL, 0x2542daa9d4d03e23L,
- 0x257791544a044dabL, 0x25ad75a95c856116L, 0x25e26989d9d35caeL, 0x261703ec504833d9L,
- 0x264cc4e7645a40d0L, 0x2681fb109eb86882L, 0x26b679d4c66682a2L, 0x26ec1849f800234bL,
- 0x27218f2e3b00160fL, 0x2755f2f9c9c01b93L, 0x278b6fb83c302277L, 0x27c125d3259e158bL,
- 0x27f56f47ef059aedL, 0x282acb19eac701a8L, 0x2860bef032bc6109L, 0x2894eeac3f6b794cL,
- 0x28ca2a574f46579eL, 0x29005a76918bf6c3L, 0x2934711435eef474L, 0x29698d59436ab191L,
- 0x299ff0af94455df5L, 0x29d3f66dbcab5ab9L, 0x2a08f4092bd63167L, 0x2a3f310b76cbbdc1L,
- 0x2a737ea72a3f5699L, 0x2aa85e50f4cf2c3fL, 0x2ade75e53202f74fL, 0x2b1309af3f41da91L,
- 0x2b47cc1b0f125135L, 0x2b7dbf21d2d6e583L, 0x2bb2977523c64f72L, 0x2be73d526cb7e34eL,
- 0x2c1d0ca707e5dc22L, 0x2c5227e864efa995L, 0x2c86b1e27e2b93faL, 0x2cbc5e5b1db678f9L,
- 0x2cf1baf8f2920b9cL, 0x2d2629b72f368e83L, 0x2d5bb424fb043223L, 0x2d9150971ce29f56L,
- 0x2dc5a4bce41b472bL, 0x2dfb0dec1d2218f6L, 0x2e30e8b392354f9aL, 0x2e6522e076c2a380L,
- 0x2e9a6b9894734c61L, 0x2ed0833f5cc80fbcL, 0x2f04a40f33fa13abL, 0x2f39cd1300f89896L,
- 0x2f70202be09b5f5eL, 0x2fa42836d8c23735L, 0x2fd932448ef2c503L, 0x300f7ed5b2af7643L,
- 0x3043af458fada9eaL, 0x30789b16f3991465L, 0x30aec1dcb07f597eL, 0x30e33929ee4f97efL,
- 0x3118077469e37deaL, 0x314e0951845c5d65L, 0x3182c5d2f2b9ba5fL, 0x31b77747af6828f7L,
- 0x31ed55199b423335L, 0x3222553001096001L, 0x3256ea7c014bb801L, 0x328ca51b019ea601L,
- 0x32c1e730e10327c1L, 0x32f660fd1943f1b1L, 0x332bf93c5f94ee1dL, 0x33617bc5bbbd14d2L,
- 0x3395dab72aac5a07L, 0x33cb5164f5577089L, 0x340112df1956a655L, 0x34355796dfac4febL,
- 0x346aad7c979763e5L, 0x34a0ac6ddebe9e6fL, 0x34d4d789566e460bL, 0x350a0d6bac09d78eL,
- 0x354048634b8626b9L, 0x35745a7c1e67b067L, 0x35a9711b26019c81L, 0x35dfcd61ef8203a1L,
- 0x3613e05d35b14245L, 0x3648d874831d92d6L, 0x367f0e91a3e4f78bL, 0x36b3691b066f1ab7L,
- 0x36e84361c80ae165L, 0x371e543a3a0d99beL, 0x3752f4a464488017L, 0x3787b1cd7d5aa01cL,
- 0x37bd9e40dcb14823L, 0x37f282e889eecd16L, 0x382723a2ac6a805cL, 0x385cec8b57852073L,
- 0x389213d716b33448L, 0x38c698ccdc60015aL, 0x38fc3f00137801b0L, 0x3931a7600c2b010eL,
- 0x396611380f35c151L, 0x399b9586130331a6L, 0x39d13d73cbe1ff08L, 0x3a058cd0beda7ec9L,
- 0x3a3af004ee911e7cL, 0x3a70d603151ab30dL, 0x3aa50b83da615fd1L, 0x3ada4e64d0f9b7c5L,
- 0x3b1070ff029c12dbL, 0x3b448d3ec3431792L, 0x3b79b08e7413dd76L, 0x3bb00e59088c6a6aL,
- 0x3be411ef4aaf8504L, 0x3c19166b1d5b6646L, 0x3c4f5c05e4b23fd7L, 0x3c839983aeef67e6L,
- 0x3cb87fe49aab41e0L, 0x3cee9fddc1561258L, 0x3d2323ea98d5cb77L, 0x3d57ece53f0b3e55L,
- 0x3d8de81e8ece0deaL, 0x3dc2b1131940c8b2L, 0x3df75d57df90fadfL, 0x3e2d34add7753996L,
- 0x3e6240eca6a943feL, 0x3e96d127d05394fdL, 0x3ecc8571c4687a3dL, 0x3f01d3671ac14c66L,
- 0x3f364840e1719f80L, 0x3f6bda5119ce075fL, 0x3fa16872b020c49cL, 0x3fd5c28f5c28f5c3L,
- 0x400B333333333333L };
-
- private static final long rawBitsFor1_2e0To309[] = { 0x3ff3333333333333L, 0x4028000000000000L,
- 0x405e000000000000L, 0x4092c00000000000L, 0x40c7700000000000L, 0x40fd4c0000000000L,
- 0x41324f8000000000L, 0x4166e36000000000L, 0x419c9c3800000000L, 0x41d1e1a300000000L,
- 0x42065a0bc0000000L, 0x423bf08eb0000000L, 0x427176592e000000L, 0x42a5d3ef79800000L,
- 0x42db48eb57e00000L, 0x43110d9316ec0000L, 0x434550f7dca70000L, 0x437aa535d3d0c000L,
- 0x43b0a741a4627800L, 0x43e4d1120d7b1600L, 0x441a055690d9db80L, 0x445043561a882930L,
- 0x4484542ba12a337cL, 0x44b969368974c05bL, 0x44efc3842bd1f072L, 0x4523da329b633647L,
- 0x4558d0bf423c03d9L, 0x458f04ef12cb04cfL, 0x45c363156bbee301L, 0x45f83bdac6ae9bc2L,
- 0x462e4ad1785a42b2L, 0x4662eec2eb3869afL, 0x4697aa73a606841bL, 0x46cd95108f882522L,
- 0x47027d2a59b51735L, 0x47371c74f0225d03L, 0x476ce3922c2af443L, 0x47a20e3b5b9ad8aaL,
- 0x47d691ca32818ed5L, 0x480c363cbf21f28aL, 0x4841a1e5f7753796L, 0x48760a5f7552857cL,
- 0x48ab8cf752a726daL, 0x48e1381a93a87849L, 0x491586213892965bL, 0x494ae7a986b73bf1L,
- 0x4980d0c9f4328577L, 0x49b504fc713f26d5L, 0x49ea463b8d8ef08aL, 0x4a206be538795656L,
- 0x4a5486de8697abecL, 0x4a89a896283d96e6L, 0x4ac0095dd9267e50L, 0x4af40bb54f701de4L,
- 0x4b290ea2a34c255dL, 0x4b5f524b4c1f2eb4L, 0x4b93936f0f937d31L, 0x4bc8784ad3785c7dL,
- 0x4bfe965d8856739cL, 0x4c331dfa75360842L, 0x4c67e57912838a52L, 0x4c9dded757246ce6L,
- 0x4cd2ab469676c410L, 0x4d0756183c147514L, 0x4d3d2b9e4b199259L, 0x4d723b42eeeffb78L,
- 0x4da6ca13aaabfa56L, 0x4ddc7c989556f8ebL, 0x4e11cddf5d565b93L, 0x4e46415734abf278L,
- 0x4e7bd1ad01d6ef15L, 0x4eb1630c2126556dL, 0x4ee5bbcf296feac9L, 0x4f1b2ac2f3cbe57bL,
- 0x4f50fab9d85f6f6dL, 0x4f8539684e774b48L, 0x4fba87c262151e1aL, 0x4ff094d97d4d32d0L,
- 0x5024ba0fdca07f84L, 0x5059e893d3c89f65L, 0x5090315c645d639fL, 0x50c43db37d74bc87L,
- 0x50f94d205cd1eba9L, 0x512fa06874066693L, 0x5163c4414884001cL, 0x5198b5519aa50023L,
- 0x51cee2a6014e402cL, 0x52034da7c0d0e81bL, 0x52382111b1052222L, 0x526e29561d466aabL,
- 0x52a2d9d5d24c02abL, 0x52d7904b46df0355L, 0x530d745e1896c42bL, 0x534268bacf5e3a9bL,
- 0x537702e98335c941L, 0x53acc3a3e4033b92L, 0x53e1fa466e82053bL, 0x541678d80a22868aL,
- 0x544c170e0cab282cL, 0x54818e68c7eaf91cL, 0x54b5f202f9e5b763L, 0x54eb6e83b85f253bL,
- 0x55212512533b7745L, 0x55556e56e80a5516L, 0x558ac9eca20cea5cL, 0x55c0be33e5481279L,
- 0x55f4edc0de9a1718L, 0x562a293116409cdeL, 0x566059beade8620bL, 0x5694702e59627a8dL,
- 0x56c98c39efbb1931L, 0x56ffef486ba9df7dL, 0x5733f58d434a2baeL, 0x5768f2f0941cb699L,
- 0x579f2facb923e440L, 0x57d37dcbf3b66ea8L, 0x58085d3ef0a40a52L, 0x583e748eaccd0ce6L,
- 0x587308d92c002810L, 0x58a7cb0f77003214L, 0x58ddbdd354c03e99L, 0x591296a414f82720L,
- 0x59473c4d1a3630e8L, 0x597d0b6060c3bd21L, 0x59b2271c3c7a5635L, 0x59e6b0e34b98ebc2L,
- 0x5a1c5d1c1e7f26b3L, 0x5a51ba31930f7830L, 0x5a8628bdf7d3563cL, 0x5abbb2ed75c82bcaL,
- 0x5af14fd4699d1b5fL, 0x5b25a3c984046236L, 0x5b5b0cbbe5057ac4L, 0x5b90e7f56f236cbaL,
- 0x5bc521f2caec47e9L, 0x5bfa6a6f7da759e3L, 0x5c308285ae88982eL, 0x5c64a3271a2abe39L,
- 0x5c99cbf0e0b56dc8L, 0x5cd01f768c71649dL, 0x5d0427542f8dbdc4L, 0x5d3931293b712d35L,
- 0x5d6f7d738a4d7882L, 0x5da3ae6836706b51L, 0x5dd89a02440c8626L, 0x5e0ec082d50fa7afL,
- 0x5e433851c529c8ceL, 0x5e78066636743b01L, 0x5eae07ffc41149c1L, 0x5ee2c4ffda8ace19L,
- 0x5f17763fd12d819fL, 0x5f4d53cfc578e207L, 0x5f825461db6b8d44L, 0x5fb6e97a52467095L,
- 0x5feca3d8e6d80cbbL, 0x6021e667904707f5L, 0x605660017458c9f2L, 0x608bf801d16efc6eL,
- 0x60c17b0122e55dc5L, 0x60f5d9c16b9eb536L, 0x612b5031c6866284L, 0x6161121f1c13fd92L,
- 0x619556a6e318fcf7L, 0x61caac509bdf3c34L, 0x6200abb2616b85a1L, 0x6234d69ef9c66709L,
- 0x626a0c46b83800cbL, 0x62a047ac3323007fL, 0x62d459973febc09fL, 0x63096ffd0fe6b0c6L,
- 0x633fcbfc53e05cf8L, 0x6373df7db46c3a1bL, 0x63a8d75d218748a2L, 0x63df0d3469e91acaL,
- 0x64136840c231b0beL, 0x64484250f2be1ceeL, 0x647e52e52f6da42aL, 0x64b2f3cf3da4869aL,
- 0x64e7b0c30d0da840L, 0x651d9cf3d0511251L, 0x655282186232ab72L, 0x6587229e7abf564fL,
- 0x65bceb46196f2be3L, 0x65f2130bcfe57b6eL, 0x662697cec3deda49L, 0x665c3dc274d690dbL,
- 0x6691a69989061a89L, 0x66c6103feb47a12bL, 0x66fb944fe6198976L, 0x67313cb1efcff5eaL,
- 0x67658bde6bc3f364L, 0x679aeed606b4f03dL, 0x67d0d545c4311626L, 0x68050a97353d5bb0L,
- 0x683a4d3d028cb29cL, 0x687070462197efa2L, 0x68a48c57a9fdeb8aL, 0x68d9af6d947d666cL,
- 0x69100da47cce6004L, 0x6944110d9c01f805L, 0x6979155103027606L, 0x69af5aa543c31387L,
- 0x69e398a74a59ec35L, 0x6a187ed11cf06742L, 0x6a4e9e85642c8112L, 0x6a8323135e9bd0abL,
- 0x6ab7ebd83642c4d6L, 0x6aede6ce43d3760cL, 0x6b22b040ea6429c7L, 0x6b575c5124fd3439L,
- 0x6b8d33656e3c8147L, 0x6bc2401f64e5d0cdL, 0x6bf6d0273e1f4500L, 0x6c2c84310da71640L,
- 0x6c61d29ea8886de8L, 0x6c96474652aa8962L, 0x6ccbd917e7552bbaL, 0x6d0167aef0953b54L,
- 0x6d35c19aacba8a29L, 0x6d6b320157e92cb4L, 0x6da0ff40d6f1bbf0L, 0x6dd53f110cae2aedL,
- 0x6e0a8ed54fd9b5a8L, 0x6e40994551e81189L, 0x6e74bf96a66215ebL, 0x6ea9ef7c4ffa9b66L,
- 0x6ee035adb1fca120L, 0x6f1443191e7bc967L, 0x6f4953df661abbc1L, 0x6f7fa8d73fa16ab2L,
- 0x6fb3c98687c4e2afL, 0x6fe8bbe829b61b5bL, 0x701eeae23423a232L, 0x705352cd6096455fL,
- 0x70882780b8bbd6b7L, 0x70be3160e6eacc64L, 0x70f2dedc9052bfbfL, 0x71279693b4676faeL,
- 0x715d7c38a1814b9aL, 0x71926da364f0cf40L, 0x71c7090c3e2d0310L, 0x71fccb4f4db843d4L,
- 0x7231ff1190932a65L, 0x72667ed5f4b7f4feL, 0x729c1e8b71e5f23dL, 0x72d19317272fb766L,
- 0x7305f7dcf0fba540L, 0x733b75d42d3a8e90L, 0x737129a49c44991aL, 0x73a5740dc355bf60L,
- 0x73dad111342b2f39L, 0x7410c2aac09afd83L, 0x7444f35570c1bce4L, 0x747a302accf22c1dL,
- 0x74b05e1ac0175b92L, 0x74e475a1701d3277L, 0x75199309cc247f15L, 0x754ff7cc3f2d9edaL,
- 0x7583fadfa77c8348L, 0x75b8f997915ba41aL, 0x75ef37fd75b28d21L, 0x762382fe698f9834L,
- 0x765863be03f37e41L, 0x768e7cad84f05dd2L, 0x76c30dec73163aa3L, 0x76f7d1678fdbc94cL,
- 0x772dc5c173d2bb9fL, 0x77629b98e863b543L, 0x7797427f227ca294L, 0x77cd131eeb1bcb39L,
- 0x78022bf352f15f04L, 0x7836b6f027adb6c5L, 0x786c64ac31992476L, 0x78a1beeb9effb6caL,
- 0x78d62ea686bfa47cL, 0x790bba50286f8d9bL, 0x794154721945b881L, 0x7975a98e9f9726a1L,
- 0x79ab13f2477cf049L, 0x79e0ec776cae162eL, 0x7a15279547d99bb9L, 0x7a4a717a99d002a8L,
- 0x7a8086eca02201a9L, 0x7ab4a8a7c82a8213L, 0x7ae9d2d1ba352298L, 0x7b2023c31461359fL,
- 0x7b542cb3d9798307L, 0x7b8937e0cfd7e3c8L, 0x7bbf85d903cddcbaL, 0x7bf3b3a7a260a9f4L,
- 0x7c28a0918af8d472L, 0x7c5ec8b5edb7098eL, 0x7c933d71b49265f9L, 0x7cc80cce21b6ff77L,
- 0x7cfe1001aa24bf55L, 0x7d32ca010a56f795L, 0x7d677c814cecb57aL, 0x7d9d5ba1a027e2d9L,
- 0x7dd259450418edc7L, 0x7e06ef96451f2939L, 0x7e3cab7bd666f388L, 0x7e71eb2d66005835L,
- 0x7ea665f8bf806e42L, 0x7edbff76ef6089d2L, 0x7f117faa559c5623L, 0x7f45df94eb036bacL,
- 0x7f7b577a25c44697L, 0x7fb116ac579aac1fL, 0x7fe55c576d815726L, 0x7ff0000000000000L };
-
- private void doTestCompareRawBits(String originalDoubleString, long expectedRawBits,
- String expectedString) {
- double result;
- long rawBits;
- String convertedString;
- result = Double.parseDouble(originalDoubleString);
- rawBits = Double.doubleToLongBits(result);
- convertedString = new Double(result).toString();
- assertEquals(expectedRawBits, rawBits);
- assertEquals(expectedString.toLowerCase(Locale.US), convertedString
- .toLowerCase(Locale.US));
- }
-
- private void test_toString(double dd, String answer) {
- assertEquals(answer, Double.toString(dd));
- Double d = new Double(dd);
- assertEquals(answer, Double.toString(d.doubleValue()));
- assertEquals(answer, d.toString());
- }
-
- /**
- * @tests java.lang.Double#Double(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Double",
- args = {double.class}
- )
- public void test_ConstructorD() {
- Double d = new Double(39089.88888888888888888888888888888888);
- assertEquals("Created incorrect double", 39089.88888888888888888888888888888888, d
- .doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Double#Double(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Double",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- Double d = new Double("39089.88888888888888888888888888888888");
- assertEquals("Created incorrect double", 39089.88888888888888888888888888888888, d
- .doubleValue(), 0D);
-
- // REGRESSION for HARMONY-489
- try {
- d = new Double("1E+-20");
- fail("new Double(\"1E+-20\") should throw exception");
- } catch (NumberFormatException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.Double#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "byteValue",
- args = {}
- )
- public void test_byteValue() {
- Double d = new Double(1923311.47712);
- assertEquals("Returned incorrect byte value", (byte) -17, d.byteValue());
- d= new Double(Byte.MAX_VALUE);
- assertEquals("Returned incorrect byte value", Byte.MAX_VALUE, d.byteValue());
- d= new Double(Byte.MIN_VALUE);
- assertEquals("Returned incorrect byte value", Byte.MIN_VALUE, d.byteValue());
- d= new Double(Double.MAX_VALUE);
- assertEquals("Returned incorrect byte value", -1, d.byteValue());
- }
-
- /**
- * @tests java.lang.Double#compareTo(java.lang.Double)
- * @tests java.lang.Double#compare(double, double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compare",
- args = {double.class, double.class}
- )
- public void test_compare() {
- double[] values = new double[] { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -2d,
- -Double.MIN_VALUE, -0d, 0d, Double.MIN_VALUE, 2d, Double.MAX_VALUE,
- Double.POSITIVE_INFINITY, Double.NaN };
- for (int i = 0; i < values.length; i++) {
- double d1 = values[i];
- assertTrue("compare() should be equal: " + d1, Double.compare(d1, d1) == 0);
- Double D1 = new Double(d1);
- assertTrue("compareTo() should be equal: " + d1, D1.compareTo(D1) == 0);
- for (int j = i + 1; j < values.length; j++) {
- double d2 = values[j];
- assertTrue("compare() " + d1 + " should be less " + d2,
- Double.compare(d1, d2) == -1);
- assertTrue("compare() " + d2 + " should be greater " + d1, Double.compare(d2,
- d1) == 1);
- Double D2 = new Double(d2);
- assertTrue("compareTo() " + d1 + " should be less " + d2,
- D1.compareTo(D2) == -1);
- assertTrue("compareTo() " + d2 + " should be greater " + d1,
- D2.compareTo(D1) == 1);
- }
- }
-
- try {
- new Double(0.0D).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Double#doubleToLongBits(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "doubleToLongBits",
- args = {double.class}
- )
- public void test_doubleToLongBitsD() {
- // Test for method long java.lang.Double.doubleToLongBits(double)
- Double d = new Double(Double.MAX_VALUE);
- long lbits = Double.doubleToLongBits(d.doubleValue());
- double r = Double.longBitsToDouble(lbits);
-
- assertTrue("Bit conversion failed", d.doubleValue() == r);
-
- assertEquals(0x7ff8000000000000L, Double.doubleToLongBits(Double.NaN));
- assertEquals(0x7ff0000000000000L, Double.doubleToLongBits(Double.POSITIVE_INFINITY));
- assertEquals(0xfff0000000000000L, Double.doubleToLongBits(Double.NEGATIVE_INFINITY));
- }
-
- /**
- * @tests java.lang.Double#doubleToRawLongBits(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "doubleToRawLongBits",
- args = {double.class}
- )
- public void test_doubleToRawLongBitsD() {
- long l = 0x7ff80000000004d2L;
- double d = Double.longBitsToDouble(l);
- assertTrue("Wrong raw bits", Double.doubleToRawLongBits(d) == l);
-
- assertEquals(0x7ff8000000000000L, Double.doubleToLongBits(Double.NaN));
- assertEquals(0x7ff0000000000000L, Double.doubleToLongBits(Double.POSITIVE_INFINITY));
- assertEquals(0xfff0000000000000L, Double.doubleToLongBits(Double.NEGATIVE_INFINITY));
- }
-
- /**
- * @tests java.lang.Double#doubleValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "doubleValue",
- args = {}
- )
- public void test_doubleValue() {
- assertEquals("Incorrect double value returned", 999999999999999.9999999999999,
- new Double(999999999999999.9999999999999).doubleValue(), 0D);
- assertEquals(Double.POSITIVE_INFINITY, new Double("1.7976931348623159E308").doubleValue());
- assertEquals(Double.NEGATIVE_INFINITY, new Double("-1.7976931348623159E308").doubleValue());
- assertEquals(Double.MAX_VALUE, new Double("1.7976931348623157E308").doubleValue());
- assertEquals(Double.MIN_VALUE, new Double("4.9E-324").doubleValue());
- }
-
- /**
- * @tests java.lang.Double#floatValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "floatValue",
- args = {}
- )
- public void test_floatValue() {
- // Test for method float java.lang.Double.floatValue()
- assertTrue(
- "Incorrect float value returned ",
- Math.abs(new Double(999999999999999.9999999999999d).
- floatValue() - 999999999999999.9999999999999f) < 1);
- assertEquals(Float.POSITIVE_INFINITY, new Double("3.4028236E38").floatValue());
- assertEquals(Float.NEGATIVE_INFINITY, new Double("-3.4028236E38").floatValue());
- assertEquals(Float.MAX_VALUE, new Double("3.4028235E38").floatValue());
- assertEquals(Float.MIN_VALUE, new Double("1.4E-45").floatValue());
- }
-
- /**
- * @tests java.lang.Double#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- // Test for method int java.lang.Double.hashCode()
- for (int i = -1000; i < 1000; i++) {
- Double d = new Double(i);
- Double dd = new Double(i);
- assertTrue("Should not be identical ", d != dd);
- assertTrue("Should be equals 1 ", d.equals(dd));
- assertTrue("Should be equals 2 ", dd.equals(d));
- assertTrue("Should have identical values ", dd.doubleValue() == d.doubleValue());
- assertTrue("Invalid hash for equal but not identical doubles ", d.hashCode() == dd
- .hashCode());
- }
- assertEquals("Magic assumption hasCode (0.0) = 0 failed", 0, new Double(0.0).hashCode());
- }
-
- /**
- * @tests java.lang.Double#intValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "intValue",
- args = {}
- )
- public void test_intValue() {
- // Test for method int java.lang.Double.intValue()
- Double d = new Double(1923311.47712);
- assertEquals("Returned incorrect int value", 1923311, d.intValue());
- assertEquals("Returned incorrect int value", Integer.MAX_VALUE,
- new Double(2147483648d).intValue());
- assertEquals("Returned incorrect int value", Integer.MIN_VALUE,
- new Double(-2147483649d).intValue());
- }
-
- /**
- * @tests java.lang.Double#isInfinite()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInfinite",
- args = {}
- )
- public void test_isInfinite() {
- // Test for method boolean java.lang.Double.isInfinite()
- assertTrue("NEGATIVE_INFINITY returned false", new Double(Double.NEGATIVE_INFINITY)
- .isInfinite());
- assertTrue("POSITIVE_INFINITY returned false", new Double(Double.POSITIVE_INFINITY)
- .isInfinite());
- assertTrue("Non infinite number returned true", !(new Double(1000).isInfinite()));
- }
-
- /**
- * @tests java.lang.Double#isInfinite(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInfinite",
- args = {double.class}
- )
- public void test_isInfiniteD() {
- // Test for method boolean java.lang.Double.isInfinite(double)
- assertTrue("Infinity check failed", Double.isInfinite(Double.NEGATIVE_INFINITY)
- && (Double.isInfinite(Double.POSITIVE_INFINITY))
- && !(Double.isInfinite(Double.MAX_VALUE)));
- }
-
- /**
- * @tests java.lang.Double#isNaN()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isNaN",
- args = {}
- )
- public void test_isNaN() {
- // Test for method boolean java.lang.Double.isNaN()
- Double d = new Double(0.0 / 0.0);
- assertTrue("NAN returned false", d.isNaN());
- d = new Double(0);
- assertTrue("Non NAN returned true", !d.isNaN());
- }
-
- /**
- * @tests java.lang.Double#isNaN(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isNaN",
- args = {double.class}
- )
- public void test_isNaND() {
- // Test for method boolean java.lang.Double.isNaN(double)
-
- Double d = new Double(0.0 / 0.0);
- assertTrue("NAN check failed", Double.isNaN(d.doubleValue()));
-
- assertFalse("Doesn't return false value", Double.isNaN(new Double(Double.MAX_VALUE)));
- }
-
- /**
- * @tests java.lang.Double#longBitsToDouble(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "longBitsToDouble",
- args = {long.class}
- )
- public void test_longBitsToDoubleJ() {
- // Test for method double java.lang.Double.longBitsToDouble(long)
-
- Double d = new Double(Double.MAX_VALUE);
- long lbits = Double.doubleToLongBits(d.doubleValue());
- double r = Double.longBitsToDouble(lbits);
-
- assertTrue("Bit conversion failed", d.doubleValue() == r);
- }
-
- /**
- * @tests java.lang.Double#longValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "longValue",
- args = {}
- )
- public void test_longValue() {
- // Test for method long java.lang.Double.longValue()
- Double d = new Double(1923311.47712);
- assertEquals("Returned incorrect long value", 1923311, d.longValue());
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary values and the loop due to the difference in the expected output string.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDoubleLjava_lang_String() {
- assertEquals("Incorrect double returned, expected zero.", 0.0, Double
- .parseDouble("2.4703282292062327208828439643411e-324"), 0.0);
- assertTrue("Incorrect double returned, expected minimum double.", Double
- .parseDouble("2.4703282292062327208828439643412e-324") == Double.MIN_VALUE);
-
- for (int i = 324; i > 0; i--) {
- Double.parseDouble("3.4e-" + i);
- }
- for (int i = 0; i <= 309; i++) {
- Double.parseDouble("1.2e" + i);
- }
-
- /*
- * The first two cases and the last four cases have to placed outside
- * the loop due to the difference in the expected output string.
- */
- doTestCompareRawBits("3.4e-324", rawBitsFor3_4en324ToN1[0], "4.9e-324");
- doTestCompareRawBits("3.4e-323", rawBitsFor3_4en324ToN1[1], "3.5e-323");
- for (int i = 322; i > 3; i--) {
- String testString, expectedString;
- testString = expectedString = "3.4e-" + i;
- doTestCompareRawBits(testString, rawBitsFor3_4en324ToN1[324 - i], expectedString);
- }
- doTestCompareRawBits("3.4e-3", rawBitsFor3_4en324ToN1[321], "0.0034");
- doTestCompareRawBits("3.4e-2", rawBitsFor3_4en324ToN1[322], "0.034");
- doTestCompareRawBits("3.4e-1", rawBitsFor3_4en324ToN1[323], "0.34");
- doTestCompareRawBits("3.4e-0", rawBitsFor3_4en324ToN1[324], "3.4");
-
- doTestCompareRawBits("1.2e0", rawBitsFor1_2e0To309[0], "1.2");
- doTestCompareRawBits("1.2e1", rawBitsFor1_2e0To309[1], "12.0");
- doTestCompareRawBits("1.2e2", rawBitsFor1_2e0To309[2], "120.0");
- doTestCompareRawBits("1.2e3", rawBitsFor1_2e0To309[3], "1200.0");
- doTestCompareRawBits("1.2e4", rawBitsFor1_2e0To309[4], "12000.0");
- doTestCompareRawBits("1.2e5", rawBitsFor1_2e0To309[5], "120000.0");
- doTestCompareRawBits("1.2e6", rawBitsFor1_2e0To309[6], "1200000.0");
- for (int i = 7; i <= 308; i++) {
- String testString, expectedString;
- testString = expectedString = "1.2e" + i;
- doTestCompareRawBits(testString, rawBitsFor1_2e0To309[i], expectedString);
- }
- doTestCompareRawBits("1.2e309", rawBitsFor1_2e0To309[309], "Infinity");
-
- doTestCompareRawBits(
- "111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000.92233720368547758079223372036854775807",
- 0x7e054218c295e43fL, "1.1122233344455567E299");
- doTestCompareRawBits(
- "-111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000111222333444555666777888999000.92233720368547758079223372036854775807",
- 0xfe054218c295e43fL, "-1.1122233344455567E299");
-
- doTestCompareRawBits("1.234123412431233E107", 0x562ae7a25fe706ebL,
- "1.234123412431233E107");
- doTestCompareRawBits("1.2341234124312331E107", 0x562ae7a25fe706ecL,
- "1.2341234124312331E107");
- doTestCompareRawBits("1.2341234124312332E107", 0x562ae7a25fe706ecL,
- "1.2341234124312331E107");
- doTestCompareRawBits("-1.234123412431233E107", 0xd62ae7a25fe706ebL,
- "-1.234123412431233E107");
- doTestCompareRawBits("-1.2341234124312331E107", 0xd62ae7a25fe706ecL,
- "-1.2341234124312331E107");
- doTestCompareRawBits("-1.2341234124312332E107", 0xd62ae7a25fe706ecL,
- "-1.2341234124312331E107");
-
- doTestCompareRawBits("9.999999999999999e22", 0x44b52d02c7e14af6L,
- "9.999999999999999e22");
-
- /*
- * These particular tests verify that the extreme boundary conditions
- * are converted correctly.
- */
- doTestCompareRawBits("0.0e-309", 0L, "0.0");
- doTestCompareRawBits("-0.0e-309", 0x8000000000000000L, "-0.0");
- doTestCompareRawBits("0.0e309", 0L, "0.0");
- doTestCompareRawBits("-0.0e309", 0x8000000000000000L, "-0.0");
- doTestCompareRawBits("0.1e309", 0x7fe1ccf385ebc8a0L, "1.0e308");
- doTestCompareRawBits("0.2e309", 0x7ff0000000000000L, "Infinity");
- doTestCompareRawBits("65e-325", 1L, "4.9e-324");
- doTestCompareRawBits("1000e-326", 2L, "1.0e-323");
-
- doTestCompareRawBits("4.0e-306", 0x86789e3750f791L, "4.0e-306");
- doTestCompareRawBits("2.22507e-308", 0xffffe2e8159d0L, "2.22507e-308");
- doTestCompareRawBits(
- "111222333444555666777888999000111228999000.92233720368547758079223372036854775807",
- 0x48746da623f1dd8bL, "1.1122233344455567E41");
- doTestCompareRawBits(
- "-111222333444555666777888999000111228999000.92233720368547758079223372036854775807",
- 0xc8746da623f1dd8bL, "-1.1122233344455567E41");
- doTestCompareRawBits(
- "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210",
- 0x54820fe0ba17f469L, "1.2345678901234567E99");
- doTestCompareRawBits(
- "-1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210987654321098765432109876543210",
- 0xd4820fe0ba17f469L, "-1.2345678901234567E99");
-
- doTestCompareRawBits(
- "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.01",
- 0x7fefffffffffffffL, "1.7976931348623157E308");
- doTestCompareRawBits(
- "-179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.01",
- 0xffefffffffffffffL, "-1.7976931348623157E308");
- doTestCompareRawBits(
- "1112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001234567890",
- 0x7ff0000000000000L, "Infinity");
- doTestCompareRawBits(
- "-1112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001112223334445556667778889990001234567890",
- 0xfff0000000000000L, "-Infinity");
- doTestCompareRawBits(
- "179769313486231590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.01",
- 0x7ff0000000000000L, "Infinity");
- doTestCompareRawBits(
- "-179769313486231590000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.01",
- 0xfff0000000000000L, "-Infinity");
- doTestCompareRawBits(
- "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x2b392a32afcc661eL, "1.7976931348623157E-100");
- doTestCompareRawBits(
- "-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0xab392a32afcc661eL, "-1.7976931348623157E-100");
- doTestCompareRawBits(
- "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x1b3432f0cb68e61L, "1.7976931348623157E-300");
- doTestCompareRawBits(
- "-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x81b3432f0cb68e61L, "-1.7976931348623157E-300");
- doTestCompareRawBits(
- "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x2117b590b942L, "1.79769313486234E-310");
- doTestCompareRawBits(
- "-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x80002117b590b942L, "-1.79769313486234E-310");
- doTestCompareRawBits(
- "0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0xe37L, "1.798E-320");
- doTestCompareRawBits(
- "-0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000017976931348623157",
- 0x8000000000000e37L, "-1.798E-320");
- doTestCompareRawBits(
- "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
- 0x2L, "1.0E-323");
- doTestCompareRawBits(
- "-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
- 0x8000000000000002L, "-1.0E-323");
- doTestCompareRawBits(
- "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055595409854908458349204328908234982349050934129878452378432452458968024357823490509341298784523784324524589680243578234905093412987845237843245245896802435782349050934129878452378432452458968024357868024357823490509341298784523784324524589680243578234905093412987845237843245245896802435786802435782349050934129878452378432452458968024357823490509341298784523784324524589680243578",
- 0x1L, "4.9E-324");
- doTestCompareRawBits(
- "-0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055595409854908458349204328908234982349050934129878452378432452458968024357823490509341298784523784324524589680243578234905093412987845237843245245896802435782349050934129878452378432452458968024357868024357823490509341298784523784324524589680243578234905093412987845237843245245896802435786802435782349050934129878452378432452458968024357823490509341298784523784324524589680243578",
- 0x8000000000000001L, "-4.9E-324");
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NumberFormatException.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_Illegal() {
- try {
- Double.parseDouble("0.0p0D");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble("+0x.p1d");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble("0Xg.gp1D");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble("-0x1.1p");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble("+0x 1.1 p2d");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble("x1.1p2d");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble(" 0x-2.1p2");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble(" 0x2.1pad");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Double.parseDouble(" 0x111.222p 22d");
- fail("Should throw NumberFormatException.");
- } catch (NumberFormatException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check exception.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_FromHexString() {
- double actual;
- double expected;
-
- actual = Double.parseDouble("0x0.0p0D");
- assertEquals("Returned incorrect value", 0.0d, actual, 0.0D);
-
- actual = Double.parseDouble("0xa.ap+9d");
- assertEquals("Returned incorrect value", 5440.0d, actual, 0.0D);
-
- actual = Double.parseDouble("+0Xb.10ap8");
- assertEquals("Returned incorrect value", 2832.625d, actual, 0.0D);
-
- actual = Double.parseDouble("-0X.a0P2D");
- assertEquals("Returned incorrect value", -2.5d, actual, 0.0D);
-
- actual = Double.parseDouble("\r 0x22.1p2d \t");
- assertEquals("Returned incorrect value", 136.25d, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.0p-1");
- assertEquals("Returned incorrect value", 0.5, actual, 0.0D);
-
- actual = Double
- .parseDouble("0x00000000000000000000000000000000001.0p-1");
- assertEquals("Returned incorrect value", 0.5, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.0p-00000000000000000000000000001");
- assertEquals("Returned incorrect value", 0.5, actual, 0.0D);
-
- actual = Double.parseDouble("0x.100000000000000000000000000000000p1");
- assertEquals("Returned incorrect value", 0.125, actual, 0.0D);
-
- actual = Double.parseDouble("0x0.0p999999999999999999999999999999999999999999999999999999999999999");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0xf1.0p9999999999999999999999999999999999999999999999999999999999999999");
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual, 0.0D);
-
- actual = Double.parseDouble("0xffffffffffffffffffffffffffffffffffff.ffffffffffffffffffffffffffffffffffffffffffffffp1");
- expected = Double.longBitsToDouble(0x4900000000000000L);
- assertEquals("Returned incorrect value", expected, actual, 0.0D);
-
- actual = Double.parseDouble("0x0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001p1600");
- expected = Double.longBitsToDouble(0x7f30000000000000L);
- assertEquals("Returned incorrect value", expected, actual, 0.0D);
-
- actual = Double.parseDouble("0x0.0p-999999999999999999999999999999999999999999999999999999");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0xf1.0p-9999999999999999999999999999999999999999999999999999999999999999");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0x10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000p-1600");
- expected = Double.longBitsToDouble(0xf0000000000000L);
- assertEquals("Returned incorrect value", expected, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.p9223372036854775807");
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.p9223372036854775808");
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual, 0.0D);
-
- actual = Double.parseDouble("0x10.p9223372036854775808");
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual, 0.0D);
-
- actual = Double.parseDouble("0xabcd.ffffffffp+2000");
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.p-9223372036854775808");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0x1.p-9223372036854775809");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0x.1p-9223372036854775809");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
-
- actual = Double.parseDouble("0xabcd.ffffffffffffffp-2000");
- assertEquals("Returned incorrect value", 0.0, actual, 0.0D);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test for hotfix in native code of double parser.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_AndroidRegression() {
- // Android regression test
- long startTime = System.currentTimeMillis();
- double actual = Double.parseDouble("9e551027");
- assertTrue("parsing double 9e551027 took too long.",
- (System.currentTimeMillis() - startTime) < 1000);
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
- actual, 0.0D);
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies positive functionality.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_NormalPositiveExponent() {
- long[] expecteds = {
- 0x3f323456789abcdfL, 0x40e111012345678aL, 0x41a1110091a2b3c5L,
- 0x4259998091a2b3c5L, 0x4311110048d159e2L, 0x43c5554048d159e2L,
- 0x4479998048d159e2L, 0x452dddc048d159e2L, 0x45e111002468acf1L,
- 0x469333202468acf1L, 0x4751011001234568L, 0x4802112101234568L,
- 0x48b3213201234568L, 0x4964314301234568L, 0x4a15415401234568L,
- 0x4ac6516501234568L, 0x4b77617601234568L, 0x4c28718701234568L,
- 0x4cd9819801234568L, 0x4d9049048091a2b4L, 0x4e4101100091a2b4L,
- 0x4ef189188091a2b4L, 0x4fa211210091a2b4L, 0x505299298091a2b4L,
- 0x510321320091a2b4L, 0x51b3a93a8091a2b4L, 0x526431430091a2b4L,
- 0x5314b94b8091a2b4L, 0x53c841840091a2b4L, 0x5478c98c8091a2b4L,
- 0x552981980091a2b4L, 0x55da09a08091a2b4L, 0x568a91a90091a2b4L,
- 0x573b19b18091a2b4L, 0x57eba1ba0091a2b4L, 0x589c29c28091a2b4L,
- 0x594cb1cb0091a2b4L, 0x5a001d01c048d15aL, 0x5ab061060048d15aL,
- 0x5b60a50a4048d15aL, 0x5c1101100048d15aL, 0x5cc145144048d15aL,
- 0x5d7189188048d15aL, 0x5e21cd1cc048d15aL, 0x5ed211210048d15aL,
- 0x5f8255254048d15aL, 0x603419418048d15aL, 0x60e45d45c048d15aL,
- 0x6194a14a0048d15aL, 0x6244e54e4048d15aL, 0x62f541540048d15aL,
- 0x63a585584048d15aL, 0x6455c95c8048d15aL, 0x65060d60c048d15aL,
- 0x65b651650048d15aL, 0x666815814048d15aL, 0x671859858048d15aL,
- 0x67c89d89c048d15aL, 0x6878e18e0048d15aL, 0x692925924048d15aL,
- 0x69d981980048d15aL, 0x6a89c59c4048d15aL, 0x6b3a09a08048d15aL,
- 0x6bea4da4c048d15aL, 0x6c9c11c10048d15aL, 0x6d4c55c54048d15aL,
- 0x6dfc99c98048d15aL, 0x6eacddcdc048d15aL, 0x6f5d21d20048d15aL,
- 0x700d65d64048d15aL, 0x70bdc1dc0048d15aL, 0x716e05e04048d15aL,
- 0x721e49e48048d15aL, 0x72d00700602468adL, 0x73802902802468adL,
- 0x74304b04a02468adL, 0x74e06d06c02468adL, 0x75908f08e02468adL,
- 0x7640b10b002468adL, 0x76f0d30d202468adL, 0x77a10110002468adL,
- 0x78512312202468adL, 0x79020520402468adL, 0x79b22722602468adL,
- 0x7a624924802468adL, 0x7b126b26a02468adL, 0x7bc28d28c02468adL,
- 0x7c72af2ae02468adL, 0x7d22d12d002468adL, 0x7dd2f32f202468adL,
- 0x7e832132002468adL, 0x7f40011001012345L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L };
-
- for (int i = 0; i < expecteds.length; i++) {
- int part = i*11;
- String inputString = "0x" + part + "." + part + "0123456789abcdefp" + part;
-
- double actual = Double.parseDouble(inputString);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputString
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies positive functionality.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_NormalNegativeExponent() {
- long[] expecteds = {
- 0x3f323456789abcdfL, 0x3f8111012345678aL, 0x3ee1110091a2b3c5L,
- 0x3e39998091a2b3c5L, 0x3d91110048d159e2L, 0x3ce5554048d159e2L,
- 0x3c39998048d159e2L, 0x3b8dddc048d159e2L, 0x3ae111002468acf1L,
- 0x3a3333202468acf1L, 0x3991011001234568L, 0x38e2112101234568L,
- 0x3833213201234568L, 0x3784314301234568L, 0x36d5415401234568L,
- 0x3626516501234568L, 0x3577617601234568L, 0x34c8718701234568L,
- 0x3419819801234568L, 0x337049048091a2b4L, 0x32c101100091a2b4L,
- 0x321189188091a2b4L, 0x316211210091a2b4L, 0x30b299298091a2b4L,
- 0x300321320091a2b4L, 0x2f53a93a8091a2b4L, 0x2ea431430091a2b4L,
- 0x2df4b94b8091a2b4L, 0x2d4841840091a2b4L, 0x2c98c98c8091a2b4L,
- 0x2be981980091a2b4L, 0x2b3a09a08091a2b4L, 0x2a8a91a90091a2b4L,
- 0x29db19b18091a2b4L, 0x292ba1ba0091a2b4L, 0x287c29c28091a2b4L,
- 0x27ccb1cb0091a2b4L, 0x27201d01c048d15aL, 0x267061060048d15aL,
- 0x25c0a50a4048d15aL, 0x251101100048d15aL, 0x246145144048d15aL,
- 0x23b189188048d15aL, 0x2301cd1cc048d15aL, 0x225211210048d15aL,
- 0x21a255254048d15aL, 0x20f419418048d15aL, 0x20445d45c048d15aL,
- 0x1f94a14a0048d15aL, 0x1ee4e54e4048d15aL, 0x1e3541540048d15aL,
- 0x1d8585584048d15aL, 0x1cd5c95c8048d15aL, 0x1c260d60c048d15aL,
- 0x1b7651650048d15aL, 0x1ac815814048d15aL, 0x1a1859858048d15aL,
- 0x19689d89c048d15aL, 0x18b8e18e0048d15aL, 0x180925924048d15aL,
- 0x175981980048d15aL, 0x16a9c59c4048d15aL, 0x15fa09a08048d15aL,
- 0x154a4da4c048d15aL, 0x149c11c10048d15aL, 0x13ec55c54048d15aL,
- 0x133c99c98048d15aL, 0x128cddcdc048d15aL, 0x11dd21d20048d15aL,
- 0x112d65d64048d15aL, 0x107dc1dc0048d15aL, 0xfce05e04048d15aL,
- 0xf1e49e48048d15aL, 0xe700700602468adL, 0xdc02902802468adL,
- 0xd104b04a02468adL, 0xc606d06c02468adL, 0xbb08f08e02468adL,
- 0xb00b10b002468adL, 0xa50d30d202468adL, 0x9a10110002468adL,
- 0x8f12312202468adL, 0x8420520402468adL, 0x7922722602468adL,
- 0x6e24924802468adL, 0x6326b26a02468adL, 0x5828d28c02468adL,
- 0x4d2af2ae02468adL, 0x422d12d002468adL, 0x372f32f202468adL,
- 0x2c32132002468adL, 0x220011001012345L, 0x170121012012345L,
- 0xc0231023012345L, 0x10341034012345L, 0x208a208a024L,
- 0x41584158L, 0x83388L, 0x108L,
- 0x0L, 0x0L, 0x0L,
- 0x0L, 0x0L, 0x0L,
- 0x0L, 0x0L, 0x0L,
- 0x0L, 0x0L, 0x0L,
- 0x0L, 0x0L };
-
- for (int i = 0; i < expecteds.length; i++) {
- int part = i*11;
- String inputString = "0x" + part + "." + part + "0123456789abcdefp-" + part;
-
- double actual = Double.parseDouble(inputString);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputString
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies max boundary.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_MaxNormalBoundary() {
- long[] expecteds = {
- 0x7fefffffffffffffL, 0x7fefffffffffffffL, 0x7fefffffffffffffL,
- 0x7fefffffffffffffL, 0x7fefffffffffffffL, 0x7fefffffffffffffL,
- 0x7fefffffffffffffL, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
- 0x7ff0000000000000L, 0x7ff0000000000000L, 0x7ff0000000000000L,
-
- 0xffefffffffffffffL, 0xffefffffffffffffL, 0xffefffffffffffffL,
- 0xffefffffffffffffL, 0xffefffffffffffffL, 0xffefffffffffffffL,
- 0xffefffffffffffffL, 0xfff0000000000000L, 0xfff0000000000000L,
- 0xfff0000000000000L, 0xfff0000000000000L, 0xfff0000000000000L,
- 0xfff0000000000000L, 0xfff0000000000000L, 0xfff0000000000000L };
-
- String[] inputs = {
- "0x1.fffffffffffffp1023",
- "0x1.fffffffffffff000000000000000000000000001p1023",
- "0x1.fffffffffffff1p1023",
- "0x1.fffffffffffff100000000000000000000000001p1023",
- "0x1.fffffffffffff1fffffffffffffffffffffffffffffffffffffffffffffp1023",
- "0x1.fffffffffffff7p1023",
- "0x1.fffffffffffff700000000000000000000000001p1023",
- "0x1.fffffffffffff8p1023",
- "0x1.fffffffffffff800000000000000000000000001p1023",
- "0x1.fffffffffffff8fffffffffffffffffffffffffffffffffffffffffffffp1023",
- "0x1.fffffffffffff9p1023",
- "0x1.fffffffffffff900000000000000000000000001p1023",
- "0x1.ffffffffffffffp1023",
- "0x1.ffffffffffffff00000000000000000000000001p1023",
- "0x1.fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp1023",
-
- "-0x1.fffffffffffffp1023",
- "-0x1.fffffffffffff000000000000000000000000001p1023",
- "-0x1.fffffffffffff1p1023",
- "-0x1.fffffffffffff100000000000000000000000001p1023",
- "-0x1.fffffffffffff1fffffffffffffffffffffffffffffffffffffffffffffp1023",
- "-0x1.fffffffffffff7p1023",
- "-0x1.fffffffffffff700000000000000000000000001p1023",
- "-0x1.fffffffffffff8p1023",
- "-0x1.fffffffffffff800000000000000000000000001p1023",
- "-0x1.fffffffffffff8fffffffffffffffffffffffffffffffffffffffffffffp1023",
- "-0x1.fffffffffffff9p1023",
- "-0x1.fffffffffffff900000000000000000000000001p1023",
- "-0x1.ffffffffffffffp1023",
- "-0x1.ffffffffffffff00000000000000000000000001p1023",
- "-0x1.fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp1023" };
-
- for (int i = 0; i < inputs.length; i++) {
- double actual = Double.parseDouble(inputs[i]);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies Min boundary.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_MinNormalBoundary() {
- long[] expecteds = {
- 0x10000000000000L, 0x10000000000000L, 0x10000000000000L,
- 0x10000000000000L, 0x10000000000000L, 0x10000000000000L,
- 0x10000000000000L, 0x10000000000000L, 0x10000000000001L,
- 0x10000000000001L, 0x10000000000001L, 0x10000000000001L,
- 0x10000000000001L, 0x10000000000001L, 0x10000000000001L,
-
- 0x8010000000000000L, 0x8010000000000000L, 0x8010000000000000L,
- 0x8010000000000000L, 0x8010000000000000L, 0x8010000000000000L,
- 0x8010000000000000L, 0x8010000000000000L, 0x8010000000000001L,
- 0x8010000000000001L, 0x8010000000000001L, 0x8010000000000001L,
- 0x8010000000000001L, 0x8010000000000001L, 0x8010000000000001L };
-
- String[] inputs = {
- "0x1.0p-1022",
- "0x1.00000000000001p-1022",
- "0x1.000000000000010000000000000000001p-1022",
- "0x1.00000000000001fffffffffffffffffffffffffffffffffp-1022",
- "0x1.00000000000007p-1022",
- "0x1.000000000000070000000000000000001p-1022",
- "0x1.00000000000007fffffffffffffffffffffffffffffffffp-1022",
- "0x1.00000000000008p-1022",
- "0x1.000000000000080000000000000000001p-1022",
- "0x1.00000000000008fffffffffffffffffffffffffffffffffp-1022",
- "0x1.00000000000009p-1022",
- "0x1.000000000000090000000000000000001p-1022",
- "0x1.00000000000009fffffffffffffffffffffffffffffffffp-1022",
- "0x1.0000000000000fp-1022",
- "0x1.0000000000000ffffffffffffffffffffffffffffffffffp-1022",
-
- "-0x1.0p-1022",
- "-0x1.00000000000001p-1022",
- "-0x1.000000000000010000000000000000001p-1022",
- "-0x1.00000000000001fffffffffffffffffffffffffffffffffp-1022",
- "-0x1.00000000000007p-1022",
- "-0x1.000000000000070000000000000000001p-1022",
- "-0x1.00000000000007fffffffffffffffffffffffffffffffffp-1022",
- "-0x1.00000000000008p-1022",
- "-0x1.000000000000080000000000000000001p-1022",
- "-0x1.00000000000008fffffffffffffffffffffffffffffffffp-1022",
- "-0x1.00000000000009p-1022",
- "-0x1.000000000000090000000000000000001p-1022",
- "-0x1.00000000000009fffffffffffffffffffffffffffffffffp-1022",
- "-0x1.0000000000000fp-1022",
- "-0x1.0000000000000ffffffffffffffffffffffffffffffffffp-1022" };
-
- for (int i = 0; i < inputs.length; i++) {
- double actual = Double.parseDouble(inputs[i]);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies Max boundary.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_MaxSubNormalBoundary() {
- long[] expecteds = {
- 0xfffffffffffffL, 0xfffffffffffffL, 0xfffffffffffffL,
- 0xfffffffffffffL, 0xfffffffffffffL, 0xfffffffffffffL,
- 0xfffffffffffffL, 0x10000000000000L, 0x10000000000000L,
- 0x10000000000000L, 0x10000000000000L, 0x10000000000000L,
- 0x10000000000000L, 0x10000000000000L, 0x10000000000000L,
-
- 0x800fffffffffffffL, 0x800fffffffffffffL, 0x800fffffffffffffL,
- 0x800fffffffffffffL, 0x800fffffffffffffL, 0x800fffffffffffffL,
- 0x800fffffffffffffL, 0x8010000000000000L, 0x8010000000000000L,
- 0x8010000000000000L, 0x8010000000000000L, 0x8010000000000000L,
- 0x8010000000000000L, 0x8010000000000000L, 0x8010000000000000L };
-
- String[] inputs = {
- "0x0.fffffffffffffp-1022",
- "0x0.fffffffffffff00000000000000000000000000000000001p-1022",
- "0x0.fffffffffffff1p-1022",
- "0x0.fffffffffffff10000000000000000000000000000000001p-1022",
- "0x0.fffffffffffff1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "0x0.fffffffffffff7p-1022",
- "0x0.fffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "0x0.fffffffffffff8p-1022",
- "0x0.fffffffffffff80000000000000000000000000000000001p-1022",
- "0x0.fffffffffffff8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "0x0.fffffffffffff9p-1022",
- "0x0.fffffffffffff9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "0x0.ffffffffffffffp-1022",
- "0x0.ffffffffffffff0000000000000000000000000000000001p-1022",
- "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
-
- "-0x0.fffffffffffffp-1022",
- "-0x0.fffffffffffff00000000000000000000000000000000001p-1022",
- "-0x0.fffffffffffff1p-1022",
- "-0x0.fffffffffffff10000000000000000000000000000000001p-1022",
- "-0x0.fffffffffffff1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "-0x0.fffffffffffff7p-1022",
- "-0x0.fffffffffffff7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "-0x0.fffffffffffff8p-1022",
- "-0x0.fffffffffffff80000000000000000000000000000000001p-1022",
- "-0x0.fffffffffffff8ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "-0x0.fffffffffffff9p-1022",
- "-0x0.fffffffffffff9ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022",
- "-0x0.ffffffffffffffp-1022",
- "-0x0.ffffffffffffff0000000000000000000000000000000001p-1022",
- "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-1022" };
-
- for (int i = 0; i < inputs.length; i++) {
- double actual = Double.parseDouble(inputs[i]);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies Min boundary.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_MinSubNormalBoundary() {
- long[] expecteds = {
- 0x1L, 0x1L, 0x2L,
- 0x1L, 0x1L, 0x1L,
- 0x2L, 0x2L, 0x2L,
- 0x2L, 0x2L, 0x2L,
- 0x2L, 0x2L, 0x2L,
-
- 0x8000000000000001L, 0x8000000000000001L, 0x8000000000000002L,
- 0x8000000000000001L, 0x8000000000000001L, 0x8000000000000001L,
- 0x8000000000000002L, 0x8000000000000002L, 0x8000000000000002L,
- 0x8000000000000002L, 0x8000000000000002L, 0x8000000000000002L,
- 0x8000000000000002L, 0x8000000000000002L, 0x8000000000000002L };
-
- String[] inputs = {
- "0x0.0000000000001p-1022",
- "0x0.00000000000010000000000000000001p-1022",
- "0x0.0000000000001fffffffffffffffffffffffffffffffffp-1022",
- "0x0.00000000000017p-1022",
- "0x0.000000000000170000000000000000001p-1022",
- "0x0.00000000000017fffffffffffffffffffffffffffffffffp-1022",
- "0x0.00000000000018p-1022",
- "0x0.000000000000180000000000000000001p-1022",
- "0x0.00000000000018fffffffffffffffffffffffffffffffffp-1022",
- "0x0.00000000000019p-1022",
- "0x0.000000000000190000000000000000001p-1022",
- "0x0.00000000000019fffffffffffffffffffffffffffffffffp-1022",
- "0x0.0000000000001fp-1022",
- "0x0.0000000000001f0000000000000000001p-1022",
- "0x0.0000000000001ffffffffffffffffffffffffffffffffffp-1022",
-
- "-0x0.0000000000001p-1022",
- "-0x0.00000000000010000000000000000001p-1022",
- "-0x0.0000000000001fffffffffffffffffffffffffffffffffp-1022",
- "-0x0.00000000000017p-1022",
- "-0x0.000000000000170000000000000000001p-1022",
- "-0x0.00000000000017fffffffffffffffffffffffffffffffffp-1022",
- "-0x0.00000000000018p-1022",
- "-0x0.000000000000180000000000000000001p-1022",
- "-0x0.00000000000018fffffffffffffffffffffffffffffffffp-1022",
- "-0x0.00000000000019p-1022",
- "-0x0.000000000000190000000000000000001p-1022",
- "-0x0.00000000000019fffffffffffffffffffffffffffffffffp-1022",
- "-0x0.0000000000001fp-1022",
- "-0x0.0000000000001f0000000000000000001p-1022",
- "-0x0.0000000000001ffffffffffffffffffffffffffffffffffp-1022" };
-
- for (int i = 0; i < inputs.length; i++) {
- double actual = Double.parseDouble(inputs[i]);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#parseDouble(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies zero boundary.",
- method = "parseDouble",
- args = {java.lang.String.class}
- )
- public void test_parseDouble_LString_ZeroBoundary() {
- long[] expecteds = {
- 0x0L, 0x0L, 0x0L,
- 0x1L, 0x1L, 0x1L,
- 0x1L, 0x1L, 0x1L,
- 0x8000000000000000L, 0x8000000000000000L, 0x8000000000000000L,
- 0x8000000000000001L, 0x8000000000000001L, 0x8000000000000001L,
- 0x8000000000000001L, 0x8000000000000001L, 0x8000000000000001L };
-
- String[] inputs = {
- "0x0.00000000000004p-1022",
- "0x0.00000000000007ffffffffffffffffffffffp-1022",
- "0x0.00000000000008p-1022",
- "0x0.000000000000080000000000000000001p-1022",
- "0x0.00000000000008fffffffffffffffffffffffffffffffp-1022",
- "0x0.00000000000009p-1022",
- "0x0.000000000000090000000000000000001p-1022",
- "0x0.00000000000009fffffffffffffffffffffffffffffffffp-1022",
- "0x0.0000000000000fffffffffffffffffffffffffffffffffffp-1022",
-
- "-0x0.00000000000004p-1022",
- "-0x0.00000000000007ffffffffffffffffffffffp-1022",
- "-0x0.00000000000008p-1022",
- "-0x0.000000000000080000000000000000001p-1022",
- "-0x0.00000000000008fffffffffffffffffffffffffffffffp-1022",
- "-0x0.00000000000009p-1022",
- "-0x0.000000000000090000000000000000001p-1022",
- "-0x0.00000000000009fffffffffffffffffffffffffffffffffp-1022",
- "-0x0.0000000000000fffffffffffffffffffffffffffffffffffp-1022" };
-
- for (int i = 0; i < inputs.length; i++) {
- double actual = Double.parseDouble(inputs[i]);
- double expected = Double.longBitsToDouble(expecteds[i]);
-
- String expectedString = "0x" + Long.toHexString(Double.doubleToLongBits(expected));
- String actualString = "0x" + Long.toHexString(Double.doubleToLongBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0D);
- }
- }
-
- /**
- * @tests java.lang.Double#shortValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "shortValue",
- args = {}
- )
- public void test_shortValue() {
- // Test for method short java.lang.Double.shortValue()
- Double d = new Double(1923311.47712);
- assertEquals("Returned incorrect short value", 22767, d.shortValue());
- }
-
- /**
- * @tests java.lang.Double#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.lang.Double.toString()
- test_toString(1.7976931348623157E308, "1.7976931348623157E308");
- test_toString(5.0E-4, "5.0E-4");
- }
-
- /**
- * @tests java.lang.Double#toString(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {double.class}
- )
- public void test_toStringD() {
- // Test for method java.lang.String java.lang.Double.toString(double)
- test_toString(1.7976931348623157E308, "1.7976931348623157E308");
- test_toString(1.0 / 0.0, "Infinity");
- test_toString(0.0 / 0.0, "NaN");
- test_toString(-1.0 / 0.0, "-Infinity");
-
- double d;
- d = Double.longBitsToDouble(0x470fffffffffffffL);
- test_toString(d, "2.0769187434139308E34");
- d = Double.longBitsToDouble(0x4710000000000000L);
- test_toString(d, "2.076918743413931E34");
-
- d = Double.longBitsToDouble(0x470000000000000aL);
- test_toString(d, "1.0384593717069678E34");
- d = Double.longBitsToDouble(0x470000000000000bL);
- test_toString(d, "1.038459371706968E34");
-
- d = Double.longBitsToDouble(0x4700000000000017L);
- test_toString(d, "1.0384593717069708E34");
- d = Double.longBitsToDouble(0x4700000000000018L);
- test_toString(d, "1.038459371706971E34");
-
- d = Double.longBitsToDouble(0x4700000000000024L);
- test_toString(d, "1.0384593717069738E34");
- d = Double.longBitsToDouble(0x4700000000000025L);
- test_toString(d, "1.038459371706974E34");
-
- d = Double.longBitsToDouble(0x4700000000000031L);
- test_toString(d, "1.0384593717069768E34");
- d = Double.longBitsToDouble(0x4700000000000032L);
- test_toString(d, "1.038459371706977E34");
-
- d = Double.longBitsToDouble(0x470000000000003eL);
- test_toString(d, "1.0384593717069798E34");
- d = Double.longBitsToDouble(0x470000000000003fL);
- test_toString(d, "1.03845937170698E34");
-
- d = Double.longBitsToDouble(0x7e00000000000003L);
- test_toString(d, "8.371160993642719E298");
- d = Double.longBitsToDouble(0x7e00000000000004L);
- test_toString(d, "8.37116099364272E298");
-
- d = Double.longBitsToDouble(0x7e00000000000008L);
- test_toString(d, "8.371160993642728E298");
- d = Double.longBitsToDouble(0x7e00000000000009L);
- test_toString(d, "8.37116099364273E298");
-
- d = Double.longBitsToDouble(0x7e00000000000013L);
- test_toString(d, "8.371160993642749E298");
- d = Double.longBitsToDouble(0x7e00000000000014L);
- test_toString(d, "8.37116099364275E298");
-
- d = Double.longBitsToDouble(0x7e00000000000023L);
- test_toString(d, "8.371160993642779E298");
- d = Double.longBitsToDouble(0x7e00000000000024L);
- test_toString(d, "8.37116099364278E298");
-
- d = Double.longBitsToDouble(0x7e0000000000002eL);
- test_toString(d, "8.371160993642799E298");
- d = Double.longBitsToDouble(0x7e0000000000002fL);
- test_toString(d, "8.3711609936428E298");
-
- d = Double.longBitsToDouble(0xda00000000000001L);
- test_toString(d, "-3.3846065602060736E125");
- d = Double.longBitsToDouble(0xda00000000000002L);
- test_toString(d, "-3.384606560206074E125");
-
- d = Double.longBitsToDouble(0xda00000000000005L);
- test_toString(d, "-3.3846065602060766E125");
- d = Double.longBitsToDouble(0xda00000000000006L);
- test_toString(d, "-3.384606560206077E125");
-
- d = Double.longBitsToDouble(0xda00000000000009L);
- test_toString(d, "-3.3846065602060796E125");
- d = Double.longBitsToDouble(0xda0000000000000aL);
- test_toString(d, "-3.38460656020608E125");
-
- d = Double.longBitsToDouble(0xda0000000000000dL);
- test_toString(d, "-3.3846065602060826E125");
- d = Double.longBitsToDouble(0xda0000000000000eL);
- test_toString(d, "-3.384606560206083E125");
- }
-
- /**
- * @tests java.lang.Double#valueOf(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String() {
- // Test for method java.lang.Double
- // java.lang.Double.valueOf(java.lang.String)
- assertTrue("Incorrect double returned", Math.abs(Double.valueOf("999999999999.999")
- .doubleValue() - 999999999999.999d) < 1);
-
- try {
- Double.valueOf(null);
- fail("Expected Double.valueOf(null) to throw NPE.");
- } catch (NullPointerException ex) {
- // expected
- } catch (Throwable ex) {
- fail("Expected Double.valueOf(null) to throw NPE not " + ex.getClass().getName());
- }
-
- try {
- Double.valueOf("");
- fail("Expected Double.valueOf(\"\") to throw NFE");
- } catch (NumberFormatException e) {
- // expected
- }
-
- Double pi = Double.valueOf("3.141592654");
- assertEquals(3.141592654, pi.doubleValue(), 0D);
-
- Double posZero = Double.valueOf("+0.0");
- Double negZero = Double.valueOf("-0.0");
- assertFalse("Doubletest0", posZero.equals(negZero));
-
- // Tests for double values by name.
- Double expectedNaN = new Double(Double.NaN);
-
- Double posNaN = Double.valueOf("NaN");
- assertTrue("Doubletest1", posNaN.equals(expectedNaN));
-
- Double posNaNSigned = Double.valueOf("+NaN");
- assertTrue("Doubletest2", posNaNSigned.equals(expectedNaN));
-
- Double negNaNSigned = Double.valueOf("-NaN");
- assertTrue("Doubletest3", negNaNSigned.equals(expectedNaN));
-
- Double posInfinite = Double.valueOf("Infinity");
- assertTrue("Doubletest4", posInfinite.equals(new Double(Double.POSITIVE_INFINITY)));
-
- Double posInfiniteSigned = Double.valueOf("+Infinity");
- assertTrue("Doubletest5", posInfiniteSigned
- .equals(new Double(Double.POSITIVE_INFINITY)));
-
- Double negInfiniteSigned = Double.valueOf("-Infinity");
- assertTrue("Doubletest6", negInfiniteSigned
- .equals(new Double(Double.NEGATIVE_INFINITY)));
- }
-
- /**
- * @tests java.lang.Double#compareTo(java.lang.Double)
- * @tests java.lang.Double#compare(double, double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Double.class}
- )
- public void test_compareToLjava_lang_Double() {
- // A selection of double values in ascending order.
- double[] values = new double[] { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -2d,
- -Double.MIN_VALUE, -0d, 0d, Double.MIN_VALUE, 2d, Double.MAX_VALUE,
- Double.POSITIVE_INFINITY, Double.NaN };
- for (int i = 0; i < values.length; i++) {
- double d1 = values[i];
-
- // Test that each value compares equal to itself; and each object is
- // equal to another object like itself.
- assertTrue("Assert 0: compare() should be equal: " + d1,
- Double.compare(d1, d1) == 0);
- Double objDouble = new Double(d1);
- assertTrue("Assert 1: compareTo() should be equal: " + d1, objDouble
- .compareTo(objDouble) == 0);
-
- // Test that the Double-defined order is respected
- for (int j = i + 1; j < values.length; j++) {
- double d2 = values[j];
- assertTrue("Assert 2: compare() " + d1 + " should be less " + d2, Double
- .compare(d1, d2) == -1);
- assertTrue("Assert 3: compare() " + d2 + " should be greater " + d1, Double
- .compare(d2, d1) == 1);
- Double D2 = new Double(d2);
- assertTrue("Assert 4: compareTo() " + d1 + " should be less " + d2, objDouble
- .compareTo(D2) == -1);
- assertTrue("Assert 5: compareTo() " + d2 + " should be greater " + d1, D2
- .compareTo(objDouble) == 1);
- }
- }
-
- try {
- new Double(0.0D).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Double#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- Double d1 = new Double(87654321.12345d);
- Double d2 = new Double(87654321.12345d);
- Double d3 = new Double(0.0002f);
- assertTrue("Assert 0: Equality test failed", d1.equals(d2) && !(d1.equals(d3)));
-
- assertTrue("Assert 2: NaN should not be == Nan", Double.NaN != Double.NaN);
- assertTrue("Assert 3: NaN should not be == Nan", new Double(Double.NaN)
- .equals(new Double(Double.NaN)));
- assertTrue("Assert 4: -0d should be == 0d", 0d == -0d);
- assertTrue("Assert 5: -0d should not be equals() 0d", !new Double(0d)
- .equals(new Double(-0d)));
-
- Double dmax = new Double(Double.MAX_VALUE);
- Double dmax1 = new Double(Double.MAX_VALUE);
-
- assertTrue("Equality test failed", dmax.equals(dmax1) && !(dmax.equals(new Object())));
- }
-
- /**
- * @tests java.lang.Double#toHexString(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toHexString",
- args = {double.class}
- )
- public void test_toHexStringF() {
- // the follow values come from the Double Javadoc/Spec
- assertEquals("0x0.0p0", Double.toHexString(0.0D));
- assertEquals("-0x0.0p0", Double.toHexString(-0.0D));
- assertEquals("0x1.0p0", Double.toHexString(1.0D));
- assertEquals("-0x1.0p0", Double.toHexString(-1.0D));
- assertEquals("0x1.0p1", Double.toHexString(2.0D));
- assertEquals("0x1.8p1", Double.toHexString(3.0D));
- assertEquals("0x1.0p-1", Double.toHexString(0.5D));
- assertEquals("0x1.0p-2", Double.toHexString(0.25D));
- assertEquals("0x1.fffffffffffffp1023", Double.toHexString(Double.MAX_VALUE));
- assertEquals("0x0.0000000000001p-1022", Double.toHexString(Double.MIN_VALUE));
-
- // test edge cases
- assertEquals("NaN", Double.toHexString(Double.NaN));
- assertEquals("-Infinity", Double.toHexString(Double.NEGATIVE_INFINITY));
- assertEquals("Infinity", Double.toHexString(Double.POSITIVE_INFINITY));
-
- // test various numbers
- assertEquals("-0x1.da8p6", Double.toHexString(-118.625D));
- assertEquals("0x1.2957874cccccdp23", Double.toHexString(9743299.65D));
- assertEquals("0x1.2957874cccccdp23", Double.toHexString(9743299.65000D));
- assertEquals("0x1.2957874cccf63p23", Double.toHexString(9743299.650001234D));
- assertEquals("0x1.700d1061d3333p33", Double.toHexString(12349743299.65000D));
-
- // test HARMONY-2132
- assertEquals("0x1.01p10", Double.toHexString(0x1.01p10));
- }
-
- /**
- * @tests java.lang.Double#valueOf(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {double.class}
- )
- public void test_valueOfD() {
- assertEquals(new Double(Double.MIN_VALUE), Double.valueOf(Double.MIN_VALUE));
- assertEquals(new Double(Double.MAX_VALUE), Double.valueOf(Double.MAX_VALUE));
- assertEquals(new Double(0), Double.valueOf(0));
-
- int s = -128;
- while (s < 128) {
- assertEquals(new Double(s), Double.valueOf(s));
- assertEquals(new Double(s + 0.1D), Double.valueOf(s + 0.1D));
- s++;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumConstantNotPresentExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumConstantNotPresentExceptionTest.java
deleted file mode 100644
index 053c694..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/EnumConstantNotPresentExceptionTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class EnumConstantNotPresentExceptionTest extends TestCase {
-
- public enum Fixture {
- ONE,TWO,THREE
- }
-
- /**
- * @test java.lang.EnumConstantNotPresentException#EnumConstantNotPresentException(Class<?
- * extends Enum>, String)
- */
- public void test_ConstructorLjava_lang_ClassLjava_lang_String() {
- try {
- new EnumConstantNotPresentException(null, "");
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @test java.lang.EnumConstantNotPresentException#enumType()
- */
- public void test_enumType() {
- EnumConstantNotPresentException e = new EnumConstantNotPresentException(Fixture.class, "FOUR");
- assertEquals(Fixture.class, e.enumType());
- }
-
- /**
- * @test java.lang.EnumConstantNotPresentException#constantName()
- */
- public void test_constantName() {
- EnumConstantNotPresentException e = new EnumConstantNotPresentException(Fixture.class, "FOUR");
- assertEquals("FOUR", e.constantName());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java
deleted file mode 100644
index 32db9b3..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ErrorTest extends TestCase {
-
- /**
- * @tests java.lang.Error#Error()
- */
- public void test_Constructor() {
- Error e = new Error();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.Error#Error(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- Error e = new Error("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java
deleted file mode 100644
index 83c6cd8..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionInInitializerErrorTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class ExceptionInInitializerErrorTest extends junit.framework.TestCase {
-
- /**
- * @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError()
- */
- public void test_Constructor() {
- ExceptionInInitializerError e = new ExceptionInInitializerError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ExceptionInInitializerError#ExceptionInInitializerError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- ExceptionInInitializerError e = new ExceptionInInitializerError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.ExceptionInInitializerExceptionInInitializerError#ExceptionInInitializerError(java.lang.Throwable)
- */
- public void test_ConstructorLjava_lang_Throwable() {
- NullPointerException npe = new NullPointerException("fixture");
- ExceptionInInitializerError e = new ExceptionInInitializerError(npe);
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertSame(npe, e.getException());
- assertSame(npe, e.getCause());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java
deleted file mode 100644
index 88cc2e4..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.Exception#Exception()
- */
- public void test_Constructor() {
- Exception e = new Exception();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.Exception#Exception(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- Exception e = new Exception("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass.java
deleted file mode 100644
index f4944b2..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-@Deprecated
-@TestAnnotation("org.apache.harmony.luni.tests.java.lang.ExtendTestClass")
-public class ExtendTestClass extends PublicTestClass {
-
- private static final long serialVersionUID = 1L;
-
- public enum enumExm {ONE, TWO, THREE};
- @Override
- public void setCount(int value) {
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass1.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass1.java
deleted file mode 100644
index 8af91f1..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ExtendTestClass1.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class ExtendTestClass1 extends ExtendTestClass {
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
deleted file mode 100644
index a81b96e..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/FloatTest.java
+++ /dev/null
@@ -1,1293 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(Float.class)
-public class FloatTest extends TestCase {
-
- private static final int rawBitsFor3_4eN38To38[] = { 0x1394470, 0x2e7958c, 0x490bd77, 0x634ecd5,
- 0x7e2280b, 0x98d5907, 0xb30af48, 0xcdcdb1a, 0xe8a08f0, 0x102c8b2d, 0x11d7adf8,
- 0x1386ccbb, 0x15287fe9, 0x16d29fe4, 0x1883a3ee, 0x1a248cea, 0x1bcdb025, 0x1d808e17,
- 0x1f20b19d, 0x20c8de04, 0x227b1585, 0x241ced73, 0x25c428d0, 0x27753303, 0x29193fe2,
- 0x2abf8fdb, 0x2c6f73d1, 0x2e15a863, 0x2fbb127c, 0x3169d71a, 0x33122671, 0x34b6b00d,
- 0x36645c10, 0x380eb98a, 0x39b267ec, 0x3b5f01e8, 0x3d0b6131, 0x3eae397d, 0x4059c7dc,
- 0x42081cea, 0x43aa2424, 0x4554ad2d, 0x4704ec3c, 0x48a6274b, 0x4a4fb11e, 0x4c01ceb3,
- 0x4da2425f, 0x4f4ad2f7, 0x50fd87b5, 0x529e74d1, 0x54461205, 0x55f79687, 0x579abe14,
- 0x59416d99, 0x5af1c900, 0x5c971da0, 0x5e3ce508, 0x5fec1e4a, 0x619392ee, 0x633877a9,
- 0x64e69594, 0x66901d7c, 0x683424dc, 0x69e12e12, 0x6b8cbccb, 0x6d2febfe, 0x6edbe6fe,
- 0x7089705f, 0x722bcc76, 0x73d6bf94, 0x758637bc, 0x7727c5ac, 0x78d1b717, 0x7a83126e,
- 0x7c23d70a, 0x7dcccccc, 0x7f7fffff };
-
- private static final String expectedStringFor3_4eN38To38[] = { "3.4028235E-38", "3.4028235E-37",
- "3.4028233E-36", "3.4028234E-35", "3.4028236E-34", "3.4028236E-33",
- "3.4028234E-32", "3.4028234E-31", "3.4028233E-30", "3.4028236E-29",
- "3.4028235E-28", "3.4028235E-27", "3.4028233E-26", "3.4028235E-25",
- "3.4028233E-24", "3.4028235E-23", "3.4028236E-22", "3.4028235E-21",
- "3.4028236E-20", "3.4028236E-19", "3.4028236E-18", "3.4028235E-17",
- "3.4028236E-16", "3.4028234E-15", "3.4028234E-14", "3.4028235E-13",
- "3.4028234E-12", "3.4028235E-11", "3.4028236E-10", "3.4028234E-9", "3.4028236E-8",
- "3.4028236E-7", "3.4028235E-6", "3.4028235E-5", "3.4028233E-4", "0.0034028236",
- "0.034028236", "0.34028235", "3.4028234", "34.028236", "340.28235", "3402.8235",
- "34028.234", "340282.34", "3402823.5", "3.4028236E7", "3.40282336E8",
- "3.40282342E9", "3.40282348E10", "3.40282343E11", "3.40282337E12", "3.40282353E13",
- "3.4028234E14", "3.4028234E15", "3.40282356E16", "3.40282356E17", "3.40282356E18",
- "3.4028236E19", "3.4028235E20", "3.4028233E21", "3.4028235E22", "3.4028233E23",
- "3.4028236E24", "3.4028234E25", "3.4028233E26", "3.4028234E27", "3.4028235E28",
- "3.4028236E29", "3.4028233E30", "3.4028235E31", "3.4028233E32", "3.4028236E33",
- "3.4028236E34", "3.4028234E35", "3.4028236E36", "3.4028235E37", "3.4028235E38" };
-
- private static final int rawBitsFor1_17eN38To38[] = { 0x80800000, 0x82200000, 0x83c80000,
- 0x857a0000, 0x871c4000, 0x88c35000, 0x8a742400, 0x8c189680, 0x8dbebc20, 0x8f6e6b28,
- 0x911502f9, 0x92ba43b7, 0x9468d4a5, 0x961184e7, 0x97b5e621, 0x99635fa9, 0x9b0e1bca,
- 0x9cb1a2bc, 0x9e5e0b6b, 0xa00ac723, 0xa1ad78ec, 0xa358d727, 0xa5078678, 0xa6a96816,
- 0xa853c21c, 0xaa045951, 0xaba56fa6, 0xad4ecb8f, 0xaf013f39, 0xb0a18f08, 0xb249f2ca,
- 0xb3fc6f7c, 0xb59dc5ae, 0xb7453719, 0xb8f684df, 0xba9a130c, 0xbc4097ce, 0xbdf0bdc2,
- 0xbf967699, 0xc13c1440, 0xc2eb1950, 0xc492efd2, 0xc637abc6, 0xc7e596b8, 0xc98f7e33,
- 0xcb335dc0, 0xcce0352f, 0xce8c213e, 0xd02f298d, 0xd1daf3f0, 0xd388d876, 0xd52b0e94,
- 0xd6d5d239, 0xd885a363, 0xda270c3c, 0xdbd0cf4b, 0xdd82818f, 0xdf2321f3, 0xe0cbea70,
- 0xe27ee50b, 0xe41f4f27, 0xe5c722f1, 0xe778ebad, 0xe91b934c, 0xeac2781f, 0xec731627,
- 0xee17edd8, 0xefbde94f, 0xf16d63a2, 0xf3145e45, 0xf4b975d7, 0xf667d34c, 0xf810e410,
- 0xf9b51d14, 0xfb626459, 0xfd0d7eb7, 0xfeb0de65 };
-
- private static final String expectedStringFor1_17eN38To38[] = { "-1.17549435E-38",
- "-1.1754944E-37", "-1.17549435E-36", "-1.17549435E-35", "-1.1754944E-34",
- "-1.17549435E-33", "-1.17549435E-32", "-1.1754944E-31", "-1.17549435E-30",
- "-1.17549435E-29", "-1.1754944E-28", "-1.1754943E-27", "-1.17549435E-26",
- "-1.1754943E-25", "-1.1754944E-24", "-1.1754943E-23", "-1.1754944E-22",
- "-1.1754943E-21", "-1.1754943E-20", "-1.1754943E-19", "-1.1754944E-18",
- "-1.1754944E-17", "-1.1754943E-16", "-1.1754943E-15", "-1.1754944E-14",
- "-1.1754943E-13", "-1.1754944E-12", "-1.1754943E-11", "-1.1754943E-10",
- "-1.1754944E-9", "-1.1754944E-8", "-1.1754943E-7", "-1.1754944E-6",
- "-1.1754943E-5", "-1.1754943E-4", "-0.0011754944", "-0.011754943", "-0.117549434",
- "-1.1754943", "-11.754944", "-117.54944", "-1175.4944", "-11754.943", "-117549.44",
- "-1175494.4", "-1.1754944E7", "-1.17549432E8", "-1.1754944E9", "-1.17549435E10",
- "-1.17549433E11", "-1.17549433E12", "-1.17549438E13", "-1.17549438E14",
- "-1.1754943E15", "-1.17549432E16", "-1.17549432E17", "-1.17549434E18",
- "-1.1754944E19", "-1.1754944E20", "-1.1754943E21", "-1.1754943E22",
- "-1.1754944E23", "-1.17549434E24", "-1.1754943E25", "-1.1754943E26",
- "-1.17549434E27", "-1.1754943E28", "-1.1754944E29", "-1.1754943E30",
- "-1.1754943E31", "-1.1754944E32", "-1.1754943E33", "-1.1754944E34",
- "-1.1754944E35", "-1.1754944E36", "-1.1754943E37", "-1.1754943E38" };
-
- private void doTestCompareRawBits(String originalFloatString, int expectedRawBits,
- String expectedString) {
- int rawBits;
- float result = Float.parseFloat(originalFloatString);
- rawBits = Float.floatToIntBits(result);
- assertEquals("Original float(" + originalFloatString + ") Converted float(" + result
- + ") Expecting:" + Integer.toHexString(expectedRawBits) + " Got: "
- + Integer.toHexString(rawBits), expectedRawBits, rawBits);
- }
-
- /**
- * @tests java.lang.Float#Float(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Float",
- args = {float.class}
- )
- public void test_ConstructorF() {
- // Test for method java.lang.Float(float)
-
- Float f = new Float(900.89f);
- assertTrue("Created incorrect float", f.floatValue() == 900.89f);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Float",
- args = {double.class}
- )
- public void test_ConstructorD() {
-
- Float f = new Float(Double.MAX_VALUE);
- assertTrue("Created incorrect float", f.floatValue() == Float.POSITIVE_INFINITY);
- }
-
- /**
- * @tests java.lang.Float#Float(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Float",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.Float(java.lang.String)
-
- Float f = new Float("900.89");
- assertTrue("Created incorrect Float", f.floatValue() == 900.89f);
- try {
- new Float("900.89ff");
- fail("NumberFormatException is not thrown.");
- } catch(NumberFormatException nfe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Float#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "byteValue",
- args = {}
- )
- public void test_byteValue() {
- // Test for method byte java.lang.Float.byteValue()
- Float f = new Float(0.46874f);
- Float f2 = new Float(90.8f);
- assertTrue("Returned incorrect byte value", f.byteValue() == 0 && f2.byteValue() == 90);
- }
-
- /**
- * @tests java.lang.Float#compareTo(java.lang.Float)
- * @tests java.lang.Float#compare(float, float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compare",
- args = {float.class, float.class}
- )
- public void test_compare() {
- float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
- -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
- Float.POSITIVE_INFINITY, Float.NaN };
- for (int i = 0; i < values.length; i++) {
- float f1 = values[i];
- assertTrue("compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
- Float F1 = new Float(f1);
- assertTrue("compareTo() should be equal: " + f1, F1.compareTo(F1) == 0);
- for (int j = i + 1; j < values.length; j++) {
- float f2 = values[j];
- assertTrue("compare() " + f1 + " should be less " + f2,
- Float.compare(f1, f2) == -1);
- assertTrue("compare() " + f2 + " should be greater " + f1, Float
- .compare(f2, f1) == 1);
- Float F2 = new Float(f2);
- assertTrue("compareTo() " + f1 + " should be less " + f2,
- F1.compareTo(F2) == -1);
- assertTrue("compareTo() " + f2 + " should be greater " + f1,
- F2.compareTo(F1) == 1);
- }
- }
-
- try {
- new Float(0.0F).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Float#doubleValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "doubleValue",
- args = {}
- )
- public void test_doubleValue() {
- // Test for method double java.lang.Float.doubleValue()
- assertTrue("Incorrect double value returned", Math.abs(new Float(999999.999f)
- .doubleValue() - 999999.999d) < 1);
- }
-
- /**
- * @tests java.lang.Float#floatToIntBits(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "floatToIntBits",
- args = {float.class}
- )
- public void test_floatToIntBitsF() {
- float f = 9876.2345f;
- int bits = Float.floatToIntBits(f);
- float r = Float.intBitsToFloat(bits);
- assertTrue("Incorrect intBits returned", f == r);
-
- assertEquals(0x7f800000, Float.floatToIntBits(Float.POSITIVE_INFINITY));
- assertEquals(0xff800000, Float.floatToIntBits(Float.NEGATIVE_INFINITY));
- assertEquals(0x7fc00000, Float.floatToIntBits(Float.NaN));
- }
-
- /**
- * @tests java.lang.Float#floatToRawIntBits(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "floatToRawIntBits",
- args = {float.class}
- )
- public void test_floatToRawIntBitsF() {
- int i = 0x7fc004d2;
- float f = Float.intBitsToFloat(i);
- assertTrue("Wrong raw bits", Float.floatToRawIntBits(f) == i);
-
- assertEquals(0x7f800000, Float.floatToRawIntBits(Float.POSITIVE_INFINITY));
- assertEquals(0xff800000, Float.floatToRawIntBits(Float.NEGATIVE_INFINITY));
- assertEquals(0x7fc00000, Float.floatToRawIntBits(Float.NaN));
- }
-
- /**
- * @tests java.lang.Float#floatValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "floatValue",
- args = {}
- )
- public void test_floatValue() {
- // Test for method float java.lang.Float.floatValue()
- Float f = new Float(87.657f);
- Float f2 = new Float(-0.876f);
- assertTrue("Returned incorrect floatValue", f.floatValue() == 87.657f
- && (f2.floatValue() == -0.876f));
-
- }
-
- /**
- * @tests java.lang.Float#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- // Test for method int java.lang.Float.hashCode()
- Float f = new Float(1908.8786f);
- assertTrue("Returned invalid hash code for 1908.8786f", f.hashCode() == Float
- .floatToIntBits(1908.8786f));
-
- f = new Float(-1.112f);
- assertTrue("Returned invalid hash code for -1.112", f.hashCode() == Float
- .floatToIntBits(-1.112f));
-
- f = new Float(0f);
- assertTrue("Returned invalid hash code for 0", f.hashCode() == Float.floatToIntBits(0f));
-
- assertTrue(new Float(Float.MAX_VALUE).hashCode() != new Float(Float.MIN_VALUE).hashCode());
- }
-
- /**
- * @tests java.lang.Float#intBitsToFloat(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "intBitsToFloat",
- args = {int.class}
- )
- public void test_intBitsToFloatI() {
- float f = 9876.2345f;
- int bits = Float.floatToIntBits(f);
- float r = Float.intBitsToFloat(bits);
- assertEquals("Incorrect intBits returned", f, r, 0F);
-
- assertEquals(Float.POSITIVE_INFINITY, Float.intBitsToFloat(0x7f800000));
- assertEquals(Float.NEGATIVE_INFINITY, Float.intBitsToFloat(0xff800000));
-
- assertEquals(Float.NaN, Float.intBitsToFloat(0x7f800001));
- assertEquals(Float.NaN, Float.intBitsToFloat(0x7fffffff));
- assertEquals(Float.NaN, Float.intBitsToFloat(0xff800001));
- assertEquals(Float.NaN, Float.intBitsToFloat(0xffffffff));
- }
-
- /**
- * @tests java.lang.Float#intValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "intValue",
- args = {}
- )
- public void test_intValue() {
- // Test for method int java.lang.Float.intValue()
- Float f = new Float(0.46874f);
- Float f2 = new Float(90.8f);
- assertTrue("Returned incorrect int value", f.intValue() == 0 && f2.intValue() == 90);
- assertEquals(Integer.MAX_VALUE, new Float(Float.MAX_VALUE).intValue());
- assertEquals(0, new Float(Float.MIN_VALUE).intValue());
- }
-
- /**
- * @tests java.lang.Float#isInfinite()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInfinite",
- args = {}
- )
- public void test_isInfinite() {
- // Test for method boolean java.lang.Float.isInfinite()
- assertTrue("Infinity check failed",
- (new Float(Float.POSITIVE_INFINITY).isInfinite() && new Float(
- Float.NEGATIVE_INFINITY).isInfinite())
- && !(new Float(0.13131414f).isInfinite()));
- }
-
- /**
- * @tests java.lang.Float#isInfinite(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isInfinite",
- args = {float.class}
- )
- public void test_isInfiniteF() {
- // Test for method boolean java.lang.Float.isInfinite(float)
-
- assertTrue("Infinity check failed", Float.isInfinite(Float.POSITIVE_INFINITY)
- && (Float.isInfinite(Float.NEGATIVE_INFINITY)) && !(Float.isInfinite(1.0f)));
- }
-
- /**
- * @tests java.lang.Float#isNaN()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isNaN",
- args = {}
- )
- public void test_isNaN() {
- // Test for method boolean java.lang.Float.isNaN()
- assertTrue("NAN check failed", new Float(Float.NaN).isNaN()
- && !(new Float(1.0f).isNaN()));
- }
-
- /**
- * @tests java.lang.Float#isNaN(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isNaN",
- args = {float.class}
- )
- public void test_isNaNF() {
- // Test for method boolean java.lang.Float.isNaN(float)
- assertTrue("NaN check failed", Float.isNaN(Float.NaN) && !(Float.isNaN(12.09f))
- && !Float.isNaN(Float.MAX_VALUE) && !Float.isNaN(Float.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.Float#longValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "longValue",
- args = {}
- )
- public void test_longValue() {
- // Test for method long java.lang.Float.longValue()
- Float f = new Float(0.46874f);
- Float f2 = new Float(90.8f);
- assertTrue("Returned incorrect long value", f.longValue() == 0 && f2.longValue() == 90);
- assertEquals(Long.MAX_VALUE, new Float(Float.MAX_VALUE).longValue());
- assertEquals(0, new Float(Float.MIN_VALUE).longValue());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NumberFormatException.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloatLExceptions() {
- String [] incorrectStrings = {"", ";", "99999999EE999999", "99999l",
- "0x1.f.ffffep127"};
- for(int i = 0; i < incorrectStrings.length; i++) {
- try {
- Float.parseFloat(incorrectStrings[i]);
- fail("NumberFormatException is not thrown for string: "
- + incorrectStrings[i]);
- } catch(NumberFormatException nfe) {
- //expected
- }
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary cases.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloatLjava_lang_String() {
- assertEquals("Incorrect float returned, expected zero.", 0.0, Float
- .parseFloat("7.0064923216240853546186479164495e-46"), 0.0);
- assertEquals("Incorrect float returned, expected minimum float.", Float.MIN_VALUE,
- Float.parseFloat("7.0064923216240853546186479164496e-46"), 0.0);
-
- doTestCompareRawBits(
- "0.000000000000000000000000000000000000011754942807573642917278829910357665133228589927589904276829631184250030649651730385585324256680905818939208984375",
- 0x800000, "1.17549435E-38");
- doTestCompareRawBits(
- "0.00000000000000000000000000000000000001175494280757364291727882991035766513322858992758990427682963118425003064965173038558532425668090581893920898437499999f",
- 0x7fffff, "1.1754942E-38");
-
- /* Test a set of regular floats with exponents from -38 to +38 */
- for (int i = 38; i > 3; i--) {
- String testString;
- testString = "3.4028234663852886e-" + i;
- doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 - i],
- expectedStringFor3_4eN38To38[38 - i]);
- }
- doTestCompareRawBits("3.4028234663852886e-3", rawBitsFor3_4eN38To38[38 - 3],
- expectedStringFor3_4eN38To38[38 - 3]);
- doTestCompareRawBits("3.4028234663852886e-2", rawBitsFor3_4eN38To38[38 - 2],
- expectedStringFor3_4eN38To38[38 - 2]);
- doTestCompareRawBits("3.4028234663852886e-1", rawBitsFor3_4eN38To38[38 - 1],
- expectedStringFor3_4eN38To38[38 - 1]);
- doTestCompareRawBits("3.4028234663852886e-0", rawBitsFor3_4eN38To38[38 - 0],
- expectedStringFor3_4eN38To38[38 - 0]);
- doTestCompareRawBits("3.4028234663852886e+1", rawBitsFor3_4eN38To38[38 + 1],
- expectedStringFor3_4eN38To38[38 + 1]);
- doTestCompareRawBits("3.4028234663852886e+2", rawBitsFor3_4eN38To38[38 + 2],
- expectedStringFor3_4eN38To38[38 + 2]);
- doTestCompareRawBits("3.4028234663852886e+3", rawBitsFor3_4eN38To38[38 + 3],
- expectedStringFor3_4eN38To38[38 + 3]);
- doTestCompareRawBits("3.4028234663852886e+4", rawBitsFor3_4eN38To38[38 + 4],
- expectedStringFor3_4eN38To38[38 + 4]);
- doTestCompareRawBits("3.4028234663852886e+5", rawBitsFor3_4eN38To38[38 + 5],
- expectedStringFor3_4eN38To38[38 + 5]);
- doTestCompareRawBits("3.4028234663852886e+6", rawBitsFor3_4eN38To38[38 + 6],
- expectedStringFor3_4eN38To38[38 + 6]);
-
- for (int i = 7; i < 39; i++) {
- String testString;
- testString = "3.4028234663852886e+" + i;
- doTestCompareRawBits(testString, rawBitsFor3_4eN38To38[38 + i],
- expectedStringFor3_4eN38To38[38 + i]);
- }
-
- /* Test another set of regular floats with exponents from -38 to +38 */
- for (int i = 38; i > 3; i--) {
- String testString;
- testString = "-1.1754943508222875e-" + i;
- doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 - i],
- expectedStringFor1_17eN38To38[38 - i]);
- }
- doTestCompareRawBits("-1.1754943508222875e-3", rawBitsFor1_17eN38To38[38 - 3],
- expectedStringFor1_17eN38To38[38 - 3]);
- doTestCompareRawBits("-1.1754943508222875e-2", rawBitsFor1_17eN38To38[38 - 2],
- expectedStringFor1_17eN38To38[38 - 2]);
- doTestCompareRawBits("-1.1754943508222875e-1", rawBitsFor1_17eN38To38[38 - 1],
- expectedStringFor1_17eN38To38[38 - 1]);
- doTestCompareRawBits("-1.1754943508222875e-0", rawBitsFor1_17eN38To38[38 - 0],
- expectedStringFor1_17eN38To38[38 - 0]);
- doTestCompareRawBits("-1.1754943508222875e+1", rawBitsFor1_17eN38To38[38 + 1],
- expectedStringFor1_17eN38To38[38 + 1]);
- doTestCompareRawBits("-1.1754943508222875e+2", rawBitsFor1_17eN38To38[38 + 2],
- expectedStringFor1_17eN38To38[38 + 2]);
- doTestCompareRawBits("-1.1754943508222875e+3", rawBitsFor1_17eN38To38[38 + 3],
- expectedStringFor1_17eN38To38[38 + 3]);
- doTestCompareRawBits("-1.1754943508222875e+4", rawBitsFor1_17eN38To38[38 + 4],
- expectedStringFor1_17eN38To38[38 + 4]);
- doTestCompareRawBits("-1.1754943508222875e+5", rawBitsFor1_17eN38To38[38 + 5],
- expectedStringFor1_17eN38To38[38 + 5]);
- doTestCompareRawBits("-1.1754943508222875e+6", rawBitsFor1_17eN38To38[38 + 6],
- expectedStringFor1_17eN38To38[38 + 6]);
-
- for (int i = 7; i < 39; i++) {
- String testString;
- testString = "-1.1754943508222875e+" + i;
- doTestCompareRawBits(testString, rawBitsFor1_17eN38To38[38 + i],
- expectedStringFor1_17eN38To38[38 + i]);
- }
-
- /* Test denormalized floats (floats with exponents <= -38 */
- doTestCompareRawBits("1.1012984643248170E-45", 1, "1.4E-45");
- doTestCompareRawBits("-1.1012984643248170E-45", 0x80000001, "-1.4E-45");
- doTestCompareRawBits("1.0E-45", 1, "1.4E-45");
- doTestCompareRawBits("-1.0E-45", 0x80000001, "-1.4E-45");
- doTestCompareRawBits("0.9E-45", 1, "1.4E-45");
- doTestCompareRawBits("-0.9E-45", 0x80000001, "-1.4E-45");
- doTestCompareRawBits("4.203895392974451e-45", 3, "4.2E-45");
- doTestCompareRawBits("-4.203895392974451e-45", 0x80000003, "-4.2E-45");
- doTestCompareRawBits("0.004E-45", 0, "0.0");
- doTestCompareRawBits("-0.004E-45", 0x80000000, "-0.0");
-
- /*
- * Test for large floats close to and greater than 3.4028235E38 and
- * -3.4028235E38
- */
- doTestCompareRawBits("1.2E+38", 0x7eb48e52, "1.2E38");
- doTestCompareRawBits("-1.2E+38", 0xfeb48e52, "-1.2E38");
- doTestCompareRawBits("3.2E+38", 0x7f70bdc2, "3.2E38");
- doTestCompareRawBits("-3.2E+38", 0xff70bdc2, "-3.2E38");
- doTestCompareRawBits("3.4E+38", 0x7f7fc99e, "3.4E38");
- doTestCompareRawBits("-3.4E+38", 0xff7fc99e, "-3.4E38");
- doTestCompareRawBits("3.4028234663852886E+38", 0x7f7fffff, "3.4028235E38");
- doTestCompareRawBits("-3.4028234663852886E+38", 0xff7fffff, "-3.4028235E38");
- doTestCompareRawBits("3.405E+38", 0x7f800000, "Infinity");
- doTestCompareRawBits("-3.405E+38", 0xff800000, "-Infinity");
- doTestCompareRawBits("3.41E+38", 0x7f800000, "Infinity");
- doTestCompareRawBits("-3.41E+38", 0xff800000, "-Infinity");
- doTestCompareRawBits("3.42E+38", 0x7f800000, "Infinity");
- doTestCompareRawBits("-3.42E+38", 0xff800000, "-Infinity");
- doTestCompareRawBits("1.0E+39", 0x7f800000, "Infinity");
- doTestCompareRawBits("-1.0E+39", 0xff800000, "-Infinity");
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary values.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_Unusual() {
- float actual;
-
- actual = Float.parseFloat("0x00000000000000000000000000000000000000000.0000000000000000000000000000000000000p0000000000000000000000000000000000");
- assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
-
- actual = Float.parseFloat("+0Xfffff.fffffffffffffffffffffffffffffffp+99F");
- assertEquals("Returned incorrect value", 6.64614E35f, actual, 0.0F);
-
- actual = Float.parseFloat("-0X.123456789abcdefp+99f");
- assertEquals("Returned incorrect value", -4.5072022E28f, actual, 0.0F);
-
- actual = Float.parseFloat("-0X123456789abcdef.p+1f");
- assertEquals("Returned incorrect value", -1.63971062E17f, actual, 0.0F);
-
- actual = Float.parseFloat("-0X000000000000000000000000000001abcdef.0000000000000000000000000001abefp00000000000000000000000000000000000000000004f");
- assertEquals("Returned incorrect value", -4.48585472E8f, actual, 0.0F);
-
- actual = Float.parseFloat("0X0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001234p600f");
- assertEquals("Returned incorrect value", 5.907252E33f, actual, 0.0F);
-
- actual = Float.parseFloat("0x1.p9223372036854775807");
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
-
- actual = Float.parseFloat("0x1.p9223372036854775808");
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
-
- actual = Float.parseFloat("0x10.p9223372036854775808");
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
-
- actual = Float.parseFloat("0xabcd.ffffffffp+2000");
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, actual, 0.0F);
-
- actual = Float.parseFloat("0x1.p-9223372036854775808");
- assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
-
- actual = Float.parseFloat("0x1.p-9223372036854775809");
- assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
-
- actual = Float.parseFloat("0x.1p-9223372036854775809");
- assertEquals("Returned incorrect value", 0.0f, actual, 0.0F);
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies positive exponent.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_NormalPositiveExponent() {
- int[] expecteds = {
- 0x3991a2b4, 0x43cc0247, 0x47909009,
- 0x4ac0c009, 0x4e109005, 0x5140c005,
- 0x5458d805, 0x57848402, 0x5a909002,
- 0x5da8a802, 0x60c0c002, 0x63cccc02,
- 0x66e4e402, 0x69f0f002, 0x6d048401,
- 0x70109001, 0x73169601, 0x76810810,
- 0x79840840, 0x7c8a08a0, 0x7f800000,
- 0x7f800000, 0x7f800000, 0x7f800000,
- 0x7f800000,
- };
-
- for (int i = 0; i < expecteds.length; i++) {
- int part = i * 6;
- String inputString = "0x" + part + "." + part + "0123456789abcdefp" + part;
-
- float actual = Float.parseFloat(inputString);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputString
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies negative exponent.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_NormalNegativeExponent() {
- int[] expecteds = {
- 0x3991a2b4,
- 0x3d6e0247,
- 0x3aa0a009,
- 0x37848405,
- 0x3420a005,
- 0x30d4d405,
- 0x2d848402,
- 0x2a129202,
- 0x26acac02,
- 0x2346c602,
- 0x1fe0e002,
- 0x1c6eee02,
- 0x19048401,
- 0x15919101,
- 0x12189801,
- 0xf028828,
- 0xb890890,
- 0x80c88c8,
- 0x4930930,
- 0x1198998,
- 0x28028,
- 0x51c,
- 0xb,
- 0x0,
- 0x0,
- };
-
- for (int i = 0; i < expecteds.length; i++) {
- int part = i * 7;
- String inputString = "0x" + part + "." + part + "0123456789abcdefp-" + part;
-
- float actual = Float.parseFloat(inputString);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputString
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies max boundary value. Doesn't verify NumberFormatException.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_MaxNormalBoundary() {
- int[] expecteds ={
- 0x7f7fffff,
- 0x7f7fffff,
- 0x7f7fffff,
- 0x7f800000,
- 0x7f800000,
- 0x7f800000,
-
- 0xff7fffff,
- 0xff7fffff,
- 0xff7fffff,
- 0xff800000,
- 0xff800000,
- 0xff800000,
- };
-
- String[] inputs = {
- "0x1.fffffep127",
- "0x1.fffffe000000000000000000000000000000000000000000000001p127",
- "0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
- "0x1.ffffffp127",
- "0x1.ffffff000000000000000000000000000000000000000000000001p127",
- "0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
-
- "-0x1.fffffep127",
- "-0x1.fffffe000000000000000000000000000000000000000000000001p127",
- "-0x1.fffffeffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
- "-0x1.ffffffp127",
- "-0x1.ffffff000000000000000000000000000000000000000000000001p127",
- "-0x1.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp127",
- };
-
- for (int i = 0; i < inputs.length; i++) {
- float actual = Float.parseFloat(inputs[i]);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies min boundary value.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_MinNormalBoundary() {
- int expecteds[] = {
- 0x800000,
- 0x800000,
- 0x800000,
- 0x800000,
- 0x800001,
- 0x800001,
-
- 0x80800000,
- 0x80800000,
- 0x80800000,
- 0x80800000,
- 0x80800001,
- 0x80800001,
- };
-
- String inputs[] = {
- "0x1.0p-126",
- "0x1.00000000000000000000000000000000000000000000001p-126",
- "0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "0x1.000001p-126",
- "0x1.000001000000000000000000000000000000000000000001p-126",
- "0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
- "-0x1.0p-126",
- "-0x1.00000000000000000000000000000000000000000000001p-126",
- "-0x1.000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "-0x1.000001p-126",
- "-0x1.000001000000000000000000000000000000000000000001p-126",
- "-0x1.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- };
-
- for (int i = 0; i < inputs.length; i++) {
- float actual = Float.parseFloat(inputs[i]);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies max boundary value.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_MaxSubNormalBoundary() {
- int expecteds[] = {
- 0x7fffff,
- 0x7fffff,
- 0x7fffff,
- 0x800000,
- 0x800000,
- 0x800000,
-
- 0x807fffff,
- 0x807fffff,
- 0x807fffff,
- 0x80800000,
- 0x80800000,
- 0x80800000,
- };
-
- String inputs[] = {
- "0x0.fffffep-126",
- "0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
- "0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "0x0.ffffffp-126",
- "0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
- "0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
- "-0x0.fffffep-126",
- "-0x0.fffffe000000000000000000000000000000000000000000000000000001p-126",
- "-0x0.fffffefffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "-0x0.ffffffp-126",
- "-0x0.ffffff0000000000000000000000000000000000000000000000000000001p-126",
- "-0x0.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- };
-
- for (int i = 0; i < inputs.length; i++) {
- float actual = Float.parseFloat(inputs[i]);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies min boundary value.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_MinSubNormalBoundary() {
- int expecteds[] = {
- 0x1,
- 0x1,
- 0x1,
- 0x2,
- 0x2,
- 0x2,
-
- 0x80000001,
- 0x80000001,
- 0x80000001,
- 0x80000002,
- 0x80000002,
- 0x80000002,
- };
-
- String inputs[] = {
- "0x0.000002p-126",
- "0x0.00000200000000000000000000000000000000000001p-126",
- "0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "0x0.000003p-126",
- "0x0.000003000000000000000000000000000000000000001p-126",
- "0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
- "-0x0.000002p-126",
- "-0x0.00000200000000000000000000000000000000000001p-126",
- "-0x0.000002ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "-0x0.000003p-126",
- "-0x0.000003000000000000000000000000000000000000001p-126",
- "-0x0.000003ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- };
-
- for (int i = 0; i < inputs.length; i++) {
- float actual = Float.parseFloat(inputs[i]);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies zero boundary value.",
- method = "parseFloat",
- args = {java.lang.String.class}
- )
- public void test_parseFloat_LString_ZeroBoundary() {
- int expecteds[] = {
- 0x0,
- 0x0,
- 0x0,
- 0x0,
- 0x1,
- 0x1,
-
- 0x80000000,
- 0x80000000,
- 0x80000000,
- 0x80000000,
- 0x80000001,
- 0x80000001,
- };
-
- String inputs[] = {
- "0x0.000000000000000p-126",
- "0x0.000000000000000000000000000000000000000000000001p-126",
- "0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "0x0.000001p-126",
- "0x0.000001000000000000000000000000000000000000000001p-126",
- "0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
-
- "-0x0.000000000000000p-126",
- "-0x0.000000000000000000000000000000000000000000000001p-126",
- "-0x0.000000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- "-0x0.000001p-126",
- "-0x0.000001000000000000000000000000000000000000000001p-126",
- "-0x0.000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffp-126",
- };
-
- for (int i = 0; i < inputs.length; i++) {
- float actual = Float.parseFloat(inputs[i]);
- float expected = Float.intBitsToFloat(expecteds[i]);
-
- String expectedString = Integer.toHexString(Float.floatToIntBits(expected));
- String actualString = Integer.toHexString(Float.floatToIntBits(actual));
- String errorMsg = i + "th input string is:<" + inputs[i]
- + ">.The expected result should be:<" + expectedString
- + ">, but was: <" + actualString + ">. ";
-
- assertEquals(errorMsg, expected, actual, 0.0F);
- }
- }
-
- /**
- * @tests java.lang.Float#parseFloat(java.lang.String)
- */
- public void test_parseFloat_LString_Harmony6261() {
- // Regression test for HARMONY-6261
- float f = new Float("2147483648");
- assertEquals("2.1474836E9", Float.toString(f));
-
- doTestCompareRawBits("123456790528.000000000000000f", 0x51e5f4c9, "1.2345679E11");
- doTestCompareRawBits("8589934592", 0x50000000, "8.5899346E9");
- doTestCompareRawBits("8606711808", 0x50004000, "8.606712E9");
- }
-
- /**
- * @tests java.lang.Float#shortValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "shortValue",
- args = {}
- )
- public void test_shortValue() {
- // Test for method short java.lang.Float.shortValue()
- Float f = new Float(0.46874f);
- Float f2 = new Float(90.8f);
- assertTrue("Returned incorrect short value", f.shortValue() == 0
- && f2.shortValue() == 90);
- }
-
- /**
- * @tests java.lang.Float#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.lang.Float.toString()
-
- test_toString(12.90898f, "12.90898");
-
- test_toString(1.7014118346046924e+38F, "1.7014118E38");
- }
-
- /**
- * @tests java.lang.Float#toString(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {float.class}
- )
- public void test_toStringF() {
- // Test for method java.lang.String java.lang.Float.toString(float)
-
- float ff;
- String answer;
-
- ff = 12.90898f;
- answer = "12.90898";
- assertTrue("Incorrect String representation want " + answer + ", got "
- + Float.toString(ff), Float.toString(ff).equals(answer));
-
- ff = Float.MAX_VALUE;
- answer = "3.4028235E38";
- assertTrue("Incorrect String representation want " + answer + ", got "
- + Float.toString(ff), Float.toString(ff).equals(answer));
- }
-
- /**
- * @tests java.lang.Float#valueOf(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String() {
- // Test for method java.lang.Float
- // java.lang.Float.valueOf(java.lang.String)
-
- Float wanted = new Float(432.1235f);
- Float got = Float.valueOf("432.1235");
- assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
- .equals(wanted));
-
- wanted = new Float(0f);
- got = Float.valueOf("0");
- assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
- .equals(wanted));
-
- wanted = new Float(-1212.3232f);
- got = Float.valueOf("-1212.3232");
- assertTrue("Incorrect float returned--wanted: " + wanted + " but got: " + got, got
- .equals(wanted));
-
- try {
- Float.valueOf(null);
- fail("Expected Float.valueOf(null) to throw NPE.");
- } catch (NullPointerException ex) {
- // expected
- }
-
- try {
- Float.valueOf("");
- fail("Expected Float.valueOf(\"\") to throw NFE");
- } catch (NumberFormatException e) {
- // expected
- }
-
- Float posZero = Float.valueOf("+0.0");
- Float negZero = Float.valueOf("-0.0");
- assertFalse("Floattest0", posZero.equals(negZero));
- assertTrue("Floattest1", 0.0f == -0.0f);
-
- // Tests for float values by name.
- Float expectedNaN = new Float(Float.NaN);
-
- Float posNaN = Float.valueOf("NaN");
- assertTrue("Floattest2", posNaN.equals(expectedNaN));
-
- Float posNaNSigned = Float.valueOf("+NaN");
- assertTrue("Floattest3", posNaNSigned.equals(expectedNaN));
-
- Float negNaNSigned = Float.valueOf("-NaN");
- assertTrue("Floattest4", negNaNSigned.equals(expectedNaN));
-
- Float posInfinite = Float.valueOf("Infinity");
- assertTrue("Floattest5", posInfinite.equals(new Float(Float.POSITIVE_INFINITY)));
-
- Float posInfiniteSigned = Float.valueOf("+Infinity");
- assertTrue("Floattest6", posInfiniteSigned.equals(new Float(Float.POSITIVE_INFINITY)));
-
- Float negInfiniteSigned = Float.valueOf("-Infinity");
- assertTrue("Floattest7", negInfiniteSigned.equals(new Float(Float.NEGATIVE_INFINITY)));
- }
-
- private void test_toString(float ff, String answer) {
- // Test for method java.lang.String java.lang.Double.toString(double)
- assertTrue("Incorrect String representation want " + answer + ", got ("
- + Float.toString(ff) + ")", Float.toString(ff).equals(answer));
- Float f = new Float(ff);
- assertTrue("Incorrect String representation want " + answer + ", got ("
- + Float.toString(f.floatValue()) + ")", Float.toString(f.floatValue()).equals(
- answer));
- assertTrue("Incorrect String representation want " + answer + ", got (" + f.toString()
- + ")", f.toString().equals(answer));
- }
-
- /**
- * @tests java.lang.Float#compareTo(java.lang.Float)
- * @tests java.lang.Float#compare(float, float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Float.class}
- )
- public void test_compareToLjava_lang_Float() {
- // A selection of float values in ascending order.
- float[] values = new float[] { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -2f,
- -Float.MIN_VALUE, -0f, 0f, Float.MIN_VALUE, 2f, Float.MAX_VALUE,
- Float.POSITIVE_INFINITY, Float.NaN };
-
- for (int i = 0; i < values.length; i++) {
- float f1 = values[i];
-
- // Test that each value compares equal to itself; and each object is
- // equal to another object
- // like itself
- assertTrue("Assert 0: compare() should be equal: " + f1, Float.compare(f1, f1) == 0);
- Float objFloat = new Float(f1);
- assertTrue("Assert 1: compareTo() should be equal: " + objFloat, objFloat
- .compareTo(objFloat) == 0);
-
- // Test that the Float-defined order is respected
- for (int j = i + 1; j < values.length; j++) {
- float f2 = values[j];
- assertTrue("Assert 2: compare() " + f1 + " should be less " + f2, Float
- .compare(f1, f2) == -1);
- assertTrue("Assert 3: compare() " + f2 + " should be greater " + f1, Float
- .compare(f2, f1) == 1);
-
- Float F2 = new Float(f2);
- assertTrue("Assert 4: compareTo() " + f1 + " should be less " + f2, objFloat
- .compareTo(F2) == -1);
- assertTrue("Assert 5: compareTo() " + f2 + " should be greater " + f1, F2
- .compareTo(objFloat) == 1);
- }
- }
- }
-
- /**
- * @tests java.lang.Float#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- Float f1 = new Float(8765.4321f);
- Float f2 = new Float(8765.4321f);
- Float f3 = new Float(-1.0f);
- assertTrue("Assert 0: Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
-
- assertTrue("Assert 1: NaN should not be == Nan", Float.NaN != Float.NaN);
- assertTrue("Assert 2: NaN should not be == Nan", new Float(Float.NaN).equals(new Float(
- Float.NaN)));
- assertTrue("Assert 3: -0f should be == 0f", 0f == -0f);
- assertTrue("Assert 4: -0f should not be equals() 0f", !new Float(0f).equals(new Float(
- -0f)));
-
- f1 = new Float(1098.576f);
- f2 = new Float(1098.576f);
- f3 = new Float(1.0f);
- assertTrue("Equality test failed", f1.equals(f2) && !(f1.equals(f3)));
-
- assertTrue("NaN should not be == Nan", Float.NaN != Float.NaN);
- assertTrue("NaN should not be == Nan", new Float(Float.NaN)
- .equals(new Float(Float.NaN)));
- assertTrue("-0f should be == 0f", 0f == -0f);
- assertTrue("-0f should not be equals() 0f", !new Float(0f).equals(new Float(-0f)));
- }
-
- /**
- * @tests java.lang.Float#toHexString(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toHexString",
- args = {float.class}
- )
- public void test_toHexStringF() {
- // the follow values comes from the Float Javadoc/Spec
- assertEquals("0x0.0p0", Float.toHexString(0.0F));
- assertEquals("-0x0.0p0", Float.toHexString(-0.0F));
- assertEquals("0x1.0p0", Float.toHexString(1.0F));
- assertEquals("-0x1.0p0", Float.toHexString(-1.0F));
- assertEquals("0x1.0p1", Float.toHexString(2.0F));
- assertEquals("0x1.8p1", Float.toHexString(3.0F));
- assertEquals("0x1.0p-1", Float.toHexString(0.5F));
- assertEquals("0x1.0p-2", Float.toHexString(0.25F));
- assertEquals("0x1.fffffep127", Float.toHexString(Float.MAX_VALUE));
- assertEquals("0x0.000002p-126", Float.toHexString(Float.MIN_VALUE));
-
- // test edge cases
- assertEquals("NaN", Float.toHexString(Float.NaN));
- assertEquals("-Infinity", Float.toHexString(Float.NEGATIVE_INFINITY));
- assertEquals("Infinity", Float.toHexString(Float.POSITIVE_INFINITY));
-
- // test various numbers
- assertEquals("-0x1.da8p6", Float.toHexString(-118.625F));
- assertEquals("0x1.295788p23", Float.toHexString(9743299.65F));
- assertEquals("0x1.295788p23", Float.toHexString(9743299.65000F));
- assertEquals("0x1.295788p23", Float.toHexString(9743299.650001234F));
- assertEquals("0x1.700d1p33", Float.toHexString(12349743299.65000F));
-
- // test HARMONY-2132
- assertEquals("0x1.01p10", Float.toHexString(0x1.01p10f));
- }
-
- /**
- * @tests java.lang.Float#valueOf(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {float.class}
- )
- public void test_valueOfF() {
- assertEquals(new Float(Float.MIN_VALUE), Float.valueOf(Float.MIN_VALUE));
- assertEquals(new Float(Float.MAX_VALUE), Float.valueOf(Float.MAX_VALUE));
- assertEquals(new Float(0), Float.valueOf(0));
-
- int s = -128;
- while (s < 128) {
- assertEquals(new Float(s), Float.valueOf(s));
- assertEquals(new Float(s + 0.1F), Float.valueOf(s + 0.1F));
- assertEquals(Float.valueOf(s + 0.1F), Float.valueOf(s + 0.1F));
- s++;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java
deleted file mode 100644
index 5b032e1..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IllegalAccessErrorTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalAccessError#IllegalAccessError()
- */
- public void test_Constructor() {
- IllegalAccessError e = new IllegalAccessError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalAccessError#IllegalAccessError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalAccessError e = new IllegalAccessError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java
deleted file mode 100644
index 2a984cb..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalAccessExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IllegalAccessExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalAccessException#IllegalAccessException()
- */
- public void test_Constructor() {
- IllegalAccessException e = new IllegalAccessException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalAccessException#IllegalAccessException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalAccessException e = new IllegalAccessException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalArgumentExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalArgumentExceptionTest.java
deleted file mode 100644
index c9faa09..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalArgumentExceptionTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class IllegalArgumentExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalArgumentException#IllegalArgumentException()
- */
- public void test_Constructor() {
- IllegalArgumentException e = new IllegalArgumentException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalArgumentException#IllegalArgumentException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalArgumentException e = new IllegalArgumentException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests {@link java.lang.IllegalArgumentException#IllegalArgumentException(Throwable)}
- */
- public void test_ConstructorLjava_lang_Throwable() {
- Throwable emptyThrowable = new Exception();
- IllegalArgumentException emptyException = new IllegalArgumentException(emptyThrowable);
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
-
- Throwable exception = new Exception("msg");
- IllegalArgumentException e = new IllegalArgumentException(exception);
- assertEquals(exception.getClass().getName() + ": " + "msg", e.getMessage());
- assertEquals(exception.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(exception.getClass().getName(), emptyException.getCause().toString());
- }
-
- /**
- * @tests java.lang.IllegalArgumentException#IllegalArgumentException(String,Throwable)
- */
- @SuppressWarnings("nls")
- public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
- NullPointerException npe = new NullPointerException();
- IllegalArgumentException e = new IllegalArgumentException("fixture",
- npe);
- assertSame("fixture", e.getMessage());
- assertSame(npe, e.getCause());
- }
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
- SerializationTest.verifySelf(new IllegalArgumentException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
- SerializationTest.verifyGolden(this, new IllegalArgumentException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalMonitorStateExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalMonitorStateExceptionTest.java
deleted file mode 100644
index 37ce9c3..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalMonitorStateExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IllegalMonitorStateExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalMonitorStateException#IllegalMonitorStateException()
- */
- public void test_Constructor() {
- IllegalMonitorStateException e = new IllegalMonitorStateException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalMonitorStateException#IllegalMonitorStateException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalMonitorStateException e = new IllegalMonitorStateException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalStateExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalStateExceptionTest.java
deleted file mode 100644
index a926535..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalStateExceptionTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class IllegalStateExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalStateException#IllegalStateException()
- */
- public void test_Constructor() {
- IllegalStateException e = new IllegalStateException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalStateException#IllegalStateException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalStateException e = new IllegalStateException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests {@link java.land.IllegalStateException#IllIllegalStateException(java.lang.Throwable)}
- */
- public void test_ConstructorLjava_lang_Throwable() {
- Throwable emptyThrowable = new Exception();
- IllegalStateException emptyException = new IllegalStateException(emptyThrowable);
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
-
- Throwable throwable = new Exception("msg");
- IllegalStateException exception = new IllegalStateException(throwable);
- assertEquals(throwable.getClass().getName() + ": " + "msg", exception.getMessage());
- assertEquals(throwable.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(throwable.getClass().getName(), emptyException.getCause().toString());
- }
-
- /**
- * @tests {@link java.land.IllegalStateException#IllIllegalStateException(java.lang.String, java.lang.Throwable)}
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
- Throwable emptyThrowable = new Exception();
- IllegalStateException emptyException = new IllegalStateException("msg", emptyThrowable);
- assertEquals("msg", emptyException.getMessage());
- assertEquals("msg", emptyException.getLocalizedMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
-
- Throwable throwable = new Exception("msg_exception");
- IllegalStateException exception = new IllegalStateException("msg", throwable);
- assertEquals("msg", exception.getMessage());
- assertEquals("msg", exception.getLocalizedMessage());
- assertEquals(throwable.getClass().getName() + ": " + throwable.getMessage(), exception
- .getCause().toString());
- }
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalStateException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new IllegalStateException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalThreadStateExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalThreadStateExceptionTest.java
deleted file mode 100644
index 475f6bb..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IllegalThreadStateExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IllegalThreadStateExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IllegalThreadStateException#IllegalThreadStateException()
- */
- public void test_Constructor() {
- IllegalThreadStateException e = new IllegalThreadStateException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IllegalThreadStateException#IllegalThreadStateException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IllegalThreadStateException e = new IllegalThreadStateException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IncompatibleClassChangeErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IncompatibleClassChangeErrorTest.java
deleted file mode 100644
index b6a8d6a..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IncompatibleClassChangeErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IncompatibleClassChangeErrorTest extends TestCase {
-
- /**
- * @tests java.lang.IncompatibleClassChangeError#IncompatibleClassChangeError()
- */
- public void test_Constructor() {
- IncompatibleClassChangeError e = new IncompatibleClassChangeError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IncompatibleClassChangeError#IncompatibleClassChangeError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IncompatibleClassChangeError e = new IncompatibleClassChangeError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IndexOutOfBoundsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IndexOutOfBoundsExceptionTest.java
deleted file mode 100644
index 617c71c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IndexOutOfBoundsExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class IndexOutOfBoundsExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.IndexOutOfBoundsException#IndexOutOfBoundsException()
- */
- public void test_Constructor() {
- IndexOutOfBoundsException e = new IndexOutOfBoundsException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.IndexOutOfBoundsException#IndexOutOfBoundsException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- IndexOutOfBoundsException e = new IndexOutOfBoundsException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InheritableThreadLocalTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InheritableThreadLocalTest.java
deleted file mode 100644
index 752aaec..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InheritableThreadLocalTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(InheritableThreadLocal.class)
-public class InheritableThreadLocalTest extends TestCase {
-
- /**
- * @tests java.lang.InheritableThreadLocal#InheritableThreadLocal()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InheritableThreadLocal",
- args = {}
- )
- public void test_Constructor() {
- InheritableThreadLocal<String> itl = new InheritableThreadLocal<String>();
- assertNull(itl.get());
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "initialValue",
- args = {}
- )
- public void test_initialValue() {
- InheritableThreadLocal<String> itl = new InheritableThreadLocal<String>() {
- @Override
- protected String initialValue() {
- return "initial";
- }
- };
- assertEquals("initial", itl.get());
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "childValue",
- args = {java.lang.Object.class}
- )
- public void test_childValue() {
- InheritableThreadLocal<String> itl = new InheritableThreadLocal<String>() {
- @Override
- protected String initialValue() {
- return "initial";
- }
- @Override
- protected String childValue(String parentValue) {
- return "childValue";
- }
- };
- assertEquals("initial", itl.get());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationErrorTest.java
deleted file mode 100644
index 1d9722c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class InstantiationErrorTest extends TestCase {
-
- /**
- * @tests java.lang.InstantiationError#InstantiationError()
- */
- public void test_Constructor() {
- InstantiationError e = new InstantiationError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.InstantiationError#InstantiationError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- InstantiationError e = new InstantiationError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationExceptionTest.java
deleted file mode 100644
index 5f636d5..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InstantiationExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class InstantiationExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.InstantiationException#InstantiationException()
- */
- public void test_Constructor() {
- InstantiationException e = new InstantiationException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.InstantiationException#InstantiationException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- InstantiationException e = new InstantiationException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
deleted file mode 100644
index 12fb758..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/IntegerTest.java
+++ /dev/null
@@ -1,1531 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.util.Properties;
-
-@TestTargetClass(Integer.class)
-public class IntegerTest extends TestCase {
- private Properties orgProps;
-
- @Override
- protected void setUp() {
- orgProps = System.getProperties();
- }
-
- @Override
- protected void tearDown() {
- System.setProperties(orgProps);
- }
-
- /**
- * @tests java.lang.Integer#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "byteValue",
- args = {}
- )
- public void test_byteValue() {
- // Test for method byte java.lang.Integer.byteValue()
- assertEquals("Returned incorrect byte value", -1, new Integer(65535)
- .byteValue());
- assertEquals("Returned incorrect byte value", 127, new Integer(127)
- .byteValue());
- }
-
- /**
- * @tests java.lang.Integer#compareTo(java.lang.Integer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Integer.class}
- )
- public void test_compareToLjava_lang_Integer() {
- // Test for method int java.lang.Integer.compareTo(java.lang.Integer)
- assertTrue("-2 compared to 1 gave non-negative answer", new Integer(-2)
- .compareTo(new Integer(1)) < 0);
- assertEquals("-2 compared to -2 gave non-zero answer", 0, new Integer(-2)
- .compareTo(new Integer(-2)));
- assertTrue("3 compared to 2 gave non-positive answer", new Integer(3)
- .compareTo(new Integer(2)) > 0);
-
- try {
- new Integer(0).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Integer#decode(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {java.lang.String.class}
- )
- public void test_decodeLjava_lang_String2() {
- // Test for method java.lang.Integer
- // java.lang.Integer.decode(java.lang.String)
- assertEquals("Failed for 132233",
- 132233, Integer.decode("132233").intValue());
- assertEquals("Failed for 07654321",
- 07654321, Integer.decode("07654321").intValue());
- assertTrue("Failed for #1234567",
- Integer.decode("#1234567").intValue() == 0x1234567);
- assertTrue("Failed for 0xdAd",
- Integer.decode("0xdAd").intValue() == 0xdad);
- assertEquals("Failed for -23", -23, Integer.decode("-23").intValue());
- assertEquals("Returned incorrect value for 0 decimal", 0, Integer
- .decode("0").intValue());
- assertEquals("Returned incorrect value for 0 hex", 0, Integer.decode("0x0")
- .intValue());
- assertTrue("Returned incorrect value for most negative value decimal",
- Integer.decode("-2147483648").intValue() == 0x80000000);
- assertTrue("Returned incorrect value for most negative value hex",
- Integer.decode("-0x80000000").intValue() == 0x80000000);
- assertTrue("Returned incorrect value for most positive value decimal",
- Integer.decode("2147483647").intValue() == 0x7fffffff);
- assertTrue("Returned incorrect value for most positive value hex",
- Integer.decode("0x7fffffff").intValue() == 0x7fffffff);
-
- boolean exception = false;
- try {
- Integer.decode("0a");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw NumberFormatException for \"Oa\"",
- exception);
-
- exception = false;
- try {
- Integer.decode("2147483648");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.decode("-2147483649");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Integer.decode("0x80000000");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.decode("-0x80000001");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Integer.decode("9999999999");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for 9999999999", exception);
-
- try {
- Integer.decode("-");
- fail("Expected exception for -");
- } catch (NumberFormatException e) {
- // Expected
- }
-
- try {
- Integer.decode("0x");
- fail("Expected exception for 0x");
- } catch (NumberFormatException e) {
- // Expected
- }
-
- try {
- Integer.decode("#");
- fail("Expected exception for #");
- } catch (NumberFormatException e) {
- // Expected
- }
-
- try {
- Integer.decode("x123");
- fail("Expected exception for x123");
- } catch (NumberFormatException e) {
- // Expected
- }
-
- try {
- Integer.decode(null);
- fail("Expected exception for null");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- Integer.decode("");
- fail("Expected exception for empty string");
- } catch (NumberFormatException ex) {
- // Expected
- }
-
- try {
- Integer.decode(" ");
- fail("Expected exception for single space");
- } catch (NumberFormatException ex) {
- // Expected
- }
-
- }
-
- /**
- * @tests java.lang.Integer#doubleValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks integer's boundary values.",
- method = "doubleValue",
- args = {}
- )
- public void test_doubleValue2() {
- // Test for method double java.lang.Integer.doubleValue()
- assertEquals("Returned incorrect double value", 2147483647.0, new Integer(2147483647)
- .doubleValue(), 0.0D);
- assertEquals("Returned incorrect double value", -2147483647.0, new Integer(-2147483647)
- .doubleValue(), 0.0D);
- }
-
- /**
- * @tests java.lang.Integer#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object2() {
- // Test for method boolean java.lang.Integer.equals(java.lang.Object)
- Integer i1 = new Integer(1000);
- Integer i2 = new Integer(1000);
- Integer i3 = new Integer(-1000);
- assertTrue("Equality test failed", i1.equals(i2) && !(i1.equals(i3)));
- }
-
- /**
- * @tests java.lang.Integer#floatValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "floatValue",
- args = {}
- )
- public void test_floatValue2() {
- // Test for method float java.lang.Integer.floatValue()
- assertTrue("Returned incorrect float value", new Integer(65535)
- .floatValue() == 65535.0f);
- assertTrue("Returned incorrect float value", new Integer(-65535)
- .floatValue() == -65535.0f);
- }
-
- /**
- * @tests java.lang.Integer#getInteger(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInteger",
- args = {java.lang.String.class}
- )
- public void test_getIntegerLjava_lang_String() {
- // Test for method java.lang.Integer
- // java.lang.Integer.getInteger(java.lang.String)
- Properties tProps = new Properties();
- tProps.put("testInt", "99");
- System.setProperties(tProps);
- assertTrue("returned incorrect Integer", Integer.getInteger("testInt")
- .equals(new Integer(99)));
- assertNull("returned incorrect default Integer", Integer
- .getInteger("ff"));
- }
-
- /**
- * @tests java.lang.Integer#getInteger(java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInteger",
- args = {java.lang.String.class, int.class}
- )
- public void test_getIntegerLjava_lang_StringI() {
- // Test for method java.lang.Integer
- // java.lang.Integer.getInteger(java.lang.String, int)
- Properties tProps = new Properties();
- tProps.put("testInt", "99");
- tProps.put("testIncInt", "notInt");
- System.setProperties(tProps);
- assertTrue("returned incorrect Integer", Integer.getInteger("testInt",
- 4).equals(new Integer(99)));
- assertTrue("returned incorrect default Integer", Integer.getInteger(
- "ff", 4).equals(new Integer(4)));
- assertTrue("returned incorrect default Integer", Integer.getInteger(
- "testIncInt", 4).equals(new Integer(4)));
- }
-
- /**
- * @tests java.lang.Integer#getInteger(java.lang.String, java.lang.Integer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInteger",
- args = {java.lang.String.class, java.lang.Integer.class}
- )
- public void test_getIntegerLjava_lang_StringLjava_lang_Integer() {
- // Test for method java.lang.Integer
- // java.lang.Integer.getInteger(java.lang.String, java.lang.Integer)
- Properties tProps = new Properties();
- tProps.put("testInt", "99");
- tProps.put("testIncInt", "notInt");
- System.setProperties(tProps);
- assertTrue("returned incorrect Integer", Integer.getInteger("testInt",
- new Integer(4)).equals(new Integer(99)));
- assertTrue("returned incorrect default Integer", Integer.getInteger(
- "ff", new Integer(4)).equals(new Integer(4)));
- assertTrue("returned incorrect default Integer", Integer.getInteger(
- "testIncInt", new Integer(4)).equals(new Integer(4)));
- }
-
- /**
- * @tests java.lang.Integer#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode2() {
- // Test for method int java.lang.Integer.hashCode()
-
- Integer i1 = new Integer(1000);
- Integer i2 = new Integer(-1000);
- assertTrue("Returned incorrect hashcode", i1.hashCode() == 1000
- && (i2.hashCode() == -1000));
- }
-
- /**
- * @tests java.lang.Integer#intValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks one value.",
- method = "intValue",
- args = {}
- )
- public void test_intValue2() {
- // Test for method int java.lang.Integer.intValue()
-
- Integer i = new Integer(8900);
- assertEquals("Returned incorrect int value", 8900, i.intValue());
- }
-
- /**
- * @tests java.lang.Integer#longValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks one value.",
- method = "longValue",
- args = {}
- )
- public void test_longValue2() {
- // Test for method long java.lang.Integer.longValue()
- Integer i = new Integer(8900);
- assertEquals("Returned incorrect long value", 8900L, i.longValue());
- }
-
- /**
- * @tests java.lang.Integer#parseInt(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "parseInt",
- args = {java.lang.String.class}
- )
- public void test_parseIntLjava_lang_String2() {
- // Test for method int java.lang.Integer.parseInt(java.lang.String)
-
- int i = Integer.parseInt("-8900");
- assertEquals("Returned incorrect int", -8900, i);
- assertEquals("Returned incorrect value for 0", 0, Integer.parseInt("0"));
- assertTrue("Returned incorrect value for most negative value", Integer
- .parseInt("-2147483648") == 0x80000000);
- assertTrue("Returned incorrect value for most positive value", Integer
- .parseInt("2147483647") == 0x7fffffff);
-
- boolean exception = false;
- try {
- Integer.parseInt("999999999999");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for value > int", exception);
-
- exception = false;
- try {
- Integer.parseInt("2147483648");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.parseInt("-2147483649");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Integer#parseInt(java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseInt",
- args = {java.lang.String.class, int.class}
- )
- public void test_parseIntLjava_lang_StringI2() {
- // Test for method int java.lang.Integer.parseInt(java.lang.String, int)
- assertEquals("Parsed dec val incorrectly",
- -8000, Integer.parseInt("-8000", 10));
- assertEquals("Parsed hex val incorrectly",
- 255, Integer.parseInt("FF", 16));
- assertEquals("Parsed oct val incorrectly",
- 16, Integer.parseInt("20", 8));
- assertEquals("Returned incorrect value for 0 hex", 0, Integer.parseInt("0",
- 16));
- assertTrue("Returned incorrect value for most negative value hex",
- Integer.parseInt("-80000000", 16) == 0x80000000);
- assertTrue("Returned incorrect value for most positive value hex",
- Integer.parseInt("7fffffff", 16) == 0x7fffffff);
- assertEquals("Returned incorrect value for 0 decimal", 0, Integer.parseInt(
- "0", 10));
- assertTrue("Returned incorrect value for most negative value decimal",
- Integer.parseInt("-2147483648", 10) == 0x80000000);
- assertTrue("Returned incorrect value for most positive value decimal",
- Integer.parseInt("2147483647", 10) == 0x7fffffff);
-
- boolean exception = false;
- try {
- Integer.parseInt("FFFF", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue(
- "Failed to throw exception when passes hex string and dec parm",
- exception);
-
- exception = false;
- try {
- Integer.parseInt("2147483648", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.parseInt("-2147483649", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Integer.parseInt("80000000", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.parseInt("-80000001", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.parseInt("9999999999", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for 9999999999", exception);
- }
-
- /**
- * @tests java.lang.Integer#shortValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks one value.",
- method = "shortValue",
- args = {}
- )
- public void test_shortValue2() {
- // Test for method short java.lang.Integer.shortValue()
- Integer i = new Integer(2147450880);
- assertEquals("Returned incorrect long value", -32768, i.shortValue());
- }
-
- /**
- * @tests java.lang.Integer#toBinaryString(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toBinaryString",
- args = {int.class}
- )
- public void test_toBinaryStringI() {
- // Test for method java.lang.String
- // java.lang.Integer.toBinaryString(int)
- assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toBinaryString(
- Integer.MAX_VALUE));
- assertEquals("Incorrect string returned", "10000000000000000000000000000000", Integer.toBinaryString(
- Integer.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.Integer#toHexString(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toHexString",
- args = {int.class}
- )
- public void test_toHexStringI() {
- // Test for method java.lang.String java.lang.Integer.toHexString(int)
-
- String[] hexvals = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
- "a", "b", "c", "d", "e", "f" };
-
- for (int i = 0; i < 16; i++) {
- assertTrue("Incorrect string returned " + hexvals[i], Integer
- .toHexString(i).equals(hexvals[i]));
- }
-
- assertTrue("Returned incorrect hex string: "
- + Integer.toHexString(Integer.MAX_VALUE), Integer.toHexString(
- Integer.MAX_VALUE).equals("7fffffff"));
- assertTrue("Returned incorrect hex string: "
- + Integer.toHexString(Integer.MIN_VALUE), Integer.toHexString(
- Integer.MIN_VALUE).equals("80000000"));
- }
-
- /**
- * @tests java.lang.Integer#toOctalString(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toOctalString",
- args = {int.class}
- )
- public void test_toOctalStringI() {
- // Test for method java.lang.String java.lang.Integer.toOctalString(int)
- // Spec states that the int arg is treated as unsigned
- assertEquals("Returned incorrect octal string", "17777777777", Integer.toOctalString(
- Integer.MAX_VALUE));
- assertEquals("Returned incorrect octal string", "20000000000", Integer.toOctalString(
- Integer.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.Integer#toString()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks one value.",
- method = "toString",
- args = {}
- )
- public void test_toString2() {
- // Test for method java.lang.String java.lang.Integer.toString()
-
- Integer i = new Integer(-80001);
-
- assertEquals("Returned incorrect String", "-80001", i.toString());
- }
-
- /**
- * @tests java.lang.Integer#toString(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {int.class}
- )
- public void test_toStringI2() {
- // Test for method java.lang.String java.lang.Integer.toString(int)
-
- assertEquals("Returned incorrect String", "-80765", Integer.toString(-80765)
- );
- assertEquals("Returned incorrect octal string", "2147483647", Integer.toString(
- Integer.MAX_VALUE));
- assertEquals("Returned incorrect octal string", "-2147483647", Integer.toString(
- -Integer.MAX_VALUE));
- assertEquals("Returned incorrect octal string", "-2147483648", Integer.toString(
- Integer.MIN_VALUE));
-
- // Test for HARMONY-6068
- assertEquals("Returned incorrect octal String", "-1000", Integer.toString(-1000));
- assertEquals("Returned incorrect octal String", "1000", Integer.toString(1000));
- assertEquals("Returned incorrect octal String", "0", Integer.toString(0));
- assertEquals("Returned incorrect octal String", "708", Integer.toString(708));
- assertEquals("Returned incorrect octal String", "-100", Integer.toString(-100));
- assertEquals("Returned incorrect octal String", "-1000000008", Integer.toString(-1000000008));
- assertEquals("Returned incorrect octal String", "2000000008", Integer.toString(2000000008));
- }
-
- /**
- * @tests java.lang.Integer#toString(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {int.class, int.class}
- )
- public void test_toStringII() {
- // Test for method java.lang.String java.lang.Integer.toString(int, int)
- assertEquals("Returned incorrect octal string", "17777777777", Integer.toString(
- 2147483647, 8));
- assertTrue("Returned incorrect hex string--wanted 7fffffff but got: "
- + Integer.toString(2147483647, 16), Integer.toString(
- 2147483647, 16).equals("7fffffff"));
- assertEquals("Incorrect string returned", "1111111111111111111111111111111", Integer.toString(2147483647, 2)
- );
- assertEquals("Incorrect string returned", "2147483647", Integer
- .toString(2147483647, 10));
-
- assertEquals("Returned incorrect octal string", "-17777777777", Integer.toString(
- -2147483647, 8));
- assertTrue("Returned incorrect hex string--wanted -7fffffff but got: "
- + Integer.toString(-2147483647, 16), Integer.toString(
- -2147483647, 16).equals("-7fffffff"));
- assertEquals("Incorrect string returned",
- "-1111111111111111111111111111111", Integer
- .toString(-2147483647, 2));
- assertEquals("Incorrect string returned", "-2147483647", Integer.toString(-2147483647,
- 10));
-
- assertEquals("Returned incorrect octal string", "-20000000000", Integer.toString(
- -2147483648, 8));
- assertTrue("Returned incorrect hex string--wanted -80000000 but got: "
- + Integer.toString(-2147483648, 16), Integer.toString(
- -2147483648, 16).equals("-80000000"));
- assertEquals("Incorrect string returned",
- "-10000000000000000000000000000000", Integer
- .toString(-2147483648, 2));
- assertEquals("Incorrect string returned", "-2147483648", Integer.toString(-2147483648,
- 10));
- }
-
- /**
- * @tests java.lang.Integer#valueOf(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary values.",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String2() {
- // Test for method java.lang.Integer
- // java.lang.Integer.valueOf(java.lang.String)
- assertEquals("Returned incorrect int", 8888888, Integer.valueOf("8888888")
- .intValue());
- assertTrue("Returned incorrect int", Integer.valueOf("2147483647")
- .intValue() == Integer.MAX_VALUE);
- assertTrue("Returned incorrect int", Integer.valueOf("-2147483648")
- .intValue() == Integer.MIN_VALUE);
-
- boolean exception = false;
- try {
- Integer.valueOf("2147483648");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.valueOf("-2147483649");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Integer#valueOf(java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks boundary values.",
- method = "valueOf",
- args = {java.lang.String.class, int.class}
- )
- public void test_valueOfLjava_lang_StringI2() {
- // Test for method java.lang.Integer
- // java.lang.Integer.valueOf(java.lang.String, int)
- assertEquals("Returned incorrect int for hex string", 255, Integer.valueOf(
- "FF", 16).intValue());
- assertEquals("Returned incorrect int for oct string", 16, Integer.valueOf(
- "20", 8).intValue());
- assertEquals("Returned incorrect int for bin string", 4, Integer.valueOf(
- "100", 2).intValue());
-
- assertEquals("Returned incorrect int for - hex string", -255, Integer.valueOf(
- "-FF", 16).intValue());
- assertEquals("Returned incorrect int for - oct string", -16, Integer.valueOf(
- "-20", 8).intValue());
- assertEquals("Returned incorrect int for - bin string", -4, Integer.valueOf(
- "-100", 2).intValue());
- assertTrue("Returned incorrect int", Integer.valueOf("2147483647", 10)
- .intValue() == Integer.MAX_VALUE);
- assertTrue("Returned incorrect int", Integer.valueOf("-2147483648", 10)
- .intValue() == Integer.MIN_VALUE);
- assertTrue("Returned incorrect int", Integer.valueOf("7fffffff", 16)
- .intValue() == Integer.MAX_VALUE);
- assertTrue("Returned incorrect int", Integer.valueOf("-80000000", 16)
- .intValue() == Integer.MIN_VALUE);
-
- boolean exception = false;
- try {
- Integer.valueOf("FF", 2);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue(
- "Failed to throw exception with hex string and base 2 radix",
- exception);
-
- exception = false;
- try {
- Integer.valueOf("2147483648", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Integer.valueOf("-2147483649", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Integer.valueOf("80000000", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with hex MAX_VALUE + 1",
- exception);
-
- exception = false;
- try {
- Integer.valueOf("-80000001", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception with hex MIN_VALUE - 1",
- exception);
- }
-
- /**
- * @tests java.lang.Integer#valueOf(byte)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {int.class}
- )
- public void test_valueOfI() {
- assertEquals(new Integer(Integer.MIN_VALUE), Integer.valueOf(Integer.MIN_VALUE));
- assertEquals(new Integer(Integer.MAX_VALUE), Integer.valueOf(Integer.MAX_VALUE));
- assertEquals(new Integer(0), Integer.valueOf(0));
-
- short s = -128;
- while (s < 128) {
- assertEquals(new Integer(s), Integer.valueOf(s));
- assertSame(Integer.valueOf(s), Integer.valueOf(s));
- s++;
- }
- }
-
- /**
- * @tests java.lang.Integer#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- assertEquals(1, new Integer(1).hashCode());
- assertEquals(2, new Integer(2).hashCode());
- assertEquals(0, new Integer(0).hashCode());
- assertEquals(-1, new Integer(-1).hashCode());
- }
-
- /**
- * @tests java.lang.Integer#Integer(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Integer",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- assertEquals(new Integer(0), new Integer("0"));
- assertEquals(new Integer(1), new Integer("1"));
- assertEquals(new Integer(-1), new Integer("-1"));
-
- try {
- new Integer("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Integer("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Integer("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Integer(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Integer#Integer
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Integer",
- args = {int.class}
- )
- public void test_ConstructorI() {
- assertEquals(1, new Integer(1).intValue());
- assertEquals(2, new Integer(2).intValue());
- assertEquals(0, new Integer(0).intValue());
- assertEquals(-1, new Integer(-1).intValue());
-
- Integer i = new Integer(-89000);
- assertEquals("Incorrect Integer created", -89000, i.intValue());
- }
-
- /**
- * @tests java.lang.Integer#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "byteValue",
- args = {}
- )
- public void test_booleanValue() {
- assertEquals(1, new Integer(1).byteValue());
- assertEquals(2, new Integer(2).byteValue());
- assertEquals(0, new Integer(0).byteValue());
- assertEquals(-1, new Integer(-1).byteValue());
- }
-
- /**
- * @tests java.lang.Integer#equals(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- assertEquals(new Integer(0), Integer.valueOf(0));
- assertEquals(new Integer(1), Integer.valueOf(1));
- assertEquals(new Integer(-1), Integer.valueOf(-1));
-
- Integer fixture = new Integer(25);
- assertEquals(fixture, fixture);
- assertFalse(fixture.equals(null));
- assertFalse(fixture.equals("Not a Integer"));
- }
-
- /**
- * @tests java.lang.Integer#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- assertEquals("-1", new Integer(-1).toString());
- assertEquals("0", new Integer(0).toString());
- assertEquals("1", new Integer(1).toString());
- assertEquals("-1", new Integer(0xFFFFFFFF).toString());
- }
-
- /**
- * @tests java.lang.Integer#toString
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {int.class}
- )
- public void test_toStringI() {
- assertEquals("-1", Integer.toString(-1));
- assertEquals("0", Integer.toString(0));
- assertEquals("1", Integer.toString(1));
- assertEquals("-1", Integer.toString(0xFFFFFFFF));
- }
-
- /**
- * @tests java.lang.Integer#valueOf(String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundary values.",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String() {
- assertEquals(new Integer(0), Integer.valueOf("0"));
- assertEquals(new Integer(1), Integer.valueOf("1"));
- assertEquals(new Integer(-1), Integer.valueOf("-1"));
-
- try {
- Integer.valueOf("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Integer#valueOf(String,int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundary values.",
- method = "valueOf",
- args = {java.lang.String.class, int.class}
- )
- public void test_valueOfLjava_lang_StringI() {
- assertEquals(new Integer(0), Integer.valueOf("0", 10));
- assertEquals(new Integer(1), Integer.valueOf("1", 10));
- assertEquals(new Integer(-1), Integer.valueOf("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Integer.valueOf("1", 2).byteValue());
- assertEquals(Character.digit('F', 16), Integer.valueOf("F", 16).byteValue());
-
- try {
- Integer.valueOf("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.valueOf(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Integer#parseInt(String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundary values.",
- method = "parseInt",
- args = {java.lang.String.class}
- )
- public void test_parseIntLjava_lang_String() {
- assertEquals(0, Integer.parseInt("0"));
- assertEquals(1, Integer.parseInt("1"));
- assertEquals(-1, Integer.parseInt("-1"));
-
- try {
- Integer.parseInt("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Integer#parseInt(String,int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseInt",
- args = {java.lang.String.class, int.class}
- )
- public void test_parseIntLjava_lang_StringI() {
- assertEquals(0, Integer.parseInt("0", 10));
- assertEquals(1, Integer.parseInt("1", 10));
- assertEquals(-1, Integer.parseInt("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Integer.parseInt("1", 2));
- assertEquals(Character.digit('F', 16), Integer.parseInt("F", 16));
-
- try {
- Integer.parseInt("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.parseInt(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Integer#decode(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {java.lang.String.class}
- )
- public void test_decodeLjava_lang_String() {
- assertEquals(new Integer(0), Integer.decode("0"));
- assertEquals(new Integer(1), Integer.decode("1"));
- assertEquals(new Integer(-1), Integer.decode("-1"));
- assertEquals(new Integer(0xF), Integer.decode("0xF"));
- assertEquals(new Integer(0xF), Integer.decode("#F"));
- assertEquals(new Integer(0xF), Integer.decode("0XF"));
- assertEquals(new Integer(07), Integer.decode("07"));
-
- try {
- Integer.decode("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.decode("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Integer.decode(null);
- //undocumented NPE, but seems consistent across JREs
- fail("Expected NullPointerException with null string.");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.lang.Integer#doubleValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundaries.",
- method = "doubleValue",
- args = {}
- )
- public void test_doubleValue() {
- assertEquals(-1D, new Integer(-1).doubleValue(), 0D);
- assertEquals(0D, new Integer(0).doubleValue(), 0D);
- assertEquals(1D, new Integer(1).doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Integer#floatValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "floatValue",
- args = {}
- )
- public void test_floatValue() {
- assertEquals(-1F, new Integer(-1).floatValue(), 0F);
- assertEquals(0F, new Integer(0).floatValue(), 0F);
- assertEquals(1F, new Integer(1).floatValue(), 0F);
- }
-
- /**
- * @tests java.lang.Integer#intValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "intValue",
- args = {}
- )
- public void test_intValue() {
- assertEquals(-1, new Integer(-1).intValue());
- assertEquals(0, new Integer(0).intValue());
- assertEquals(1, new Integer(1).intValue());
- assertEquals(Integer.MAX_VALUE, new Integer(Integer.MAX_VALUE).intValue());
- assertEquals(Integer.MIN_VALUE, new Integer(Integer.MIN_VALUE).intValue());
- }
-
- /**
- * @tests java.lang.Integer#longValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "longValue",
- args = {}
- )
- public void test_longValue() {
- assertEquals(-1L, new Integer(-1).longValue());
- assertEquals(0L, new Integer(0).longValue());
- assertEquals(1L, new Integer(1).longValue());
- assertEquals(Integer.MAX_VALUE, new Integer(Integer.MAX_VALUE).longValue());
- assertEquals(Integer.MIN_VALUE, new Integer(Integer.MIN_VALUE).longValue());
- }
-
- /**
- * @tests java.lang.Integer#shortValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "shortValue",
- args = {}
- )
- public void test_shortValue() {
- assertEquals(-1, new Integer(-1).shortValue());
- assertEquals(0, new Integer(0).shortValue());
- assertEquals(1, new Integer(1).shortValue());
- assertEquals(-1, new Integer(Integer.MAX_VALUE).shortValue());
- assertEquals(0, new Integer(Integer.MIN_VALUE).shortValue());
- }
- /**
- * @tests java.lang.Integer#highestOneBit(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "highestOneBit",
- args = {int.class}
- )
- public void test_highestOneBitI() {
- assertEquals(0x08, Integer.highestOneBit(0x0A));
- assertEquals(0x08, Integer.highestOneBit(0x0B));
- assertEquals(0x08, Integer.highestOneBit(0x0C));
- assertEquals(0x08, Integer.highestOneBit(0x0F));
- assertEquals(0x80, Integer.highestOneBit(0xFF));
-
- assertEquals(0x080000, Integer.highestOneBit(0x0F1234));
- assertEquals(0x800000, Integer.highestOneBit(0xFF9977));
-
- assertEquals(0x80000000, Integer.highestOneBit(0xFFFFFFFF));
-
- assertEquals(0, Integer.highestOneBit(0));
- assertEquals(1, Integer.highestOneBit(1));
- assertEquals(0x80000000, Integer.highestOneBit(-1));
- }
-
- /**
- * @tests java.lang.Integer#lowestOneBit(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lowestOneBit",
- args = {int.class}
- )
- public void test_lowestOneBitI() {
- assertEquals(0x10, Integer.lowestOneBit(0xF0));
-
- assertEquals(0x10, Integer.lowestOneBit(0x90));
- assertEquals(0x10, Integer.lowestOneBit(0xD0));
-
- assertEquals(0x10, Integer.lowestOneBit(0x123490));
- assertEquals(0x10, Integer.lowestOneBit(0x1234D0));
-
- assertEquals(0x100000, Integer.lowestOneBit(0x900000));
- assertEquals(0x100000, Integer.lowestOneBit(0xD00000));
-
- assertEquals(0x40, Integer.lowestOneBit(0x40));
- assertEquals(0x40, Integer.lowestOneBit(0xC0));
-
- assertEquals(0x4000, Integer.lowestOneBit(0x4000));
- assertEquals(0x4000, Integer.lowestOneBit(0xC000));
-
- assertEquals(0x4000, Integer.lowestOneBit(0x99994000));
- assertEquals(0x4000, Integer.lowestOneBit(0x9999C000));
-
- assertEquals(0, Integer.lowestOneBit(0));
- assertEquals(1, Integer.lowestOneBit(1));
- assertEquals(1, Integer.lowestOneBit(-1));
- }
- /**
- * @tests java.lang.Integer#numberOfLeadingZeros(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "numberOfLeadingZeros",
- args = {int.class}
- )
- public void test_numberOfLeadingZerosI() {
- assertEquals(32, Integer.numberOfLeadingZeros(0x0));
- assertEquals(31, Integer.numberOfLeadingZeros(0x1));
- assertEquals(30, Integer.numberOfLeadingZeros(0x2));
- assertEquals(30, Integer.numberOfLeadingZeros(0x3));
- assertEquals(29, Integer.numberOfLeadingZeros(0x4));
- assertEquals(29, Integer.numberOfLeadingZeros(0x5));
- assertEquals(29, Integer.numberOfLeadingZeros(0x6));
- assertEquals(29, Integer.numberOfLeadingZeros(0x7));
- assertEquals(28, Integer.numberOfLeadingZeros(0x8));
- assertEquals(28, Integer.numberOfLeadingZeros(0x9));
- assertEquals(28, Integer.numberOfLeadingZeros(0xA));
- assertEquals(28, Integer.numberOfLeadingZeros(0xB));
- assertEquals(28, Integer.numberOfLeadingZeros(0xC));
- assertEquals(28, Integer.numberOfLeadingZeros(0xD));
- assertEquals(28, Integer.numberOfLeadingZeros(0xE));
- assertEquals(28, Integer.numberOfLeadingZeros(0xF));
- assertEquals(27, Integer.numberOfLeadingZeros(0x10));
- assertEquals(24, Integer.numberOfLeadingZeros(0x80));
- assertEquals(24, Integer.numberOfLeadingZeros(0xF0));
- assertEquals(23, Integer.numberOfLeadingZeros(0x100));
- assertEquals(20, Integer.numberOfLeadingZeros(0x800));
- assertEquals(20, Integer.numberOfLeadingZeros(0xF00));
- assertEquals(19, Integer.numberOfLeadingZeros(0x1000));
- assertEquals(16, Integer.numberOfLeadingZeros(0x8000));
- assertEquals(16, Integer.numberOfLeadingZeros(0xF000));
- assertEquals(15, Integer.numberOfLeadingZeros(0x10000));
- assertEquals(12, Integer.numberOfLeadingZeros(0x80000));
- assertEquals(12, Integer.numberOfLeadingZeros(0xF0000));
- assertEquals(11, Integer.numberOfLeadingZeros(0x100000));
- assertEquals(8, Integer.numberOfLeadingZeros(0x800000));
- assertEquals(8, Integer.numberOfLeadingZeros(0xF00000));
- assertEquals(7, Integer.numberOfLeadingZeros(0x1000000));
- assertEquals(4, Integer.numberOfLeadingZeros(0x8000000));
- assertEquals(4, Integer.numberOfLeadingZeros(0xF000000));
- assertEquals(3, Integer.numberOfLeadingZeros(0x10000000));
- assertEquals(0, Integer.numberOfLeadingZeros(0x80000000));
- assertEquals(0, Integer.numberOfLeadingZeros(0xF0000000));
-
- assertEquals(1, Integer.numberOfLeadingZeros(Integer.MAX_VALUE));
- assertEquals(0, Integer.numberOfLeadingZeros(Integer.MIN_VALUE));
- }
-
- /**
- * @tests
- * java.lang.Integer#numberOfTrailingZeros(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "numberOfTrailingZeros",
- args = {int.class}
- )
- public void test_numberOfTrailingZerosI() {
- assertEquals(32, Integer.numberOfTrailingZeros(0x0));
- assertEquals(31, Integer.numberOfTrailingZeros(Integer.MIN_VALUE));
- assertEquals(0, Integer.numberOfTrailingZeros(Integer.MAX_VALUE));
-
- assertEquals(0, Integer.numberOfTrailingZeros(0x1));
- assertEquals(3, Integer.numberOfTrailingZeros(0x8));
- assertEquals(0, Integer.numberOfTrailingZeros(0xF));
-
- assertEquals(4, Integer.numberOfTrailingZeros(0x10));
- assertEquals(7, Integer.numberOfTrailingZeros(0x80));
- assertEquals(4, Integer.numberOfTrailingZeros(0xF0));
-
- assertEquals(8, Integer.numberOfTrailingZeros(0x100));
- assertEquals(11, Integer.numberOfTrailingZeros(0x800));
- assertEquals(8, Integer.numberOfTrailingZeros(0xF00));
-
- assertEquals(12, Integer.numberOfTrailingZeros(0x1000));
- assertEquals(15, Integer.numberOfTrailingZeros(0x8000));
- assertEquals(12, Integer.numberOfTrailingZeros(0xF000));
-
- assertEquals(16, Integer.numberOfTrailingZeros(0x10000));
- assertEquals(19, Integer.numberOfTrailingZeros(0x80000));
- assertEquals(16, Integer.numberOfTrailingZeros(0xF0000));
-
- assertEquals(20, Integer.numberOfTrailingZeros(0x100000));
- assertEquals(23, Integer.numberOfTrailingZeros(0x800000));
- assertEquals(20, Integer.numberOfTrailingZeros(0xF00000));
-
- assertEquals(24, Integer.numberOfTrailingZeros(0x1000000));
- assertEquals(27, Integer.numberOfTrailingZeros(0x8000000));
- assertEquals(24, Integer.numberOfTrailingZeros(0xF000000));
-
- assertEquals(28, Integer.numberOfTrailingZeros(0x10000000));
- assertEquals(31, Integer.numberOfTrailingZeros(0x80000000));
- assertEquals(28, Integer.numberOfTrailingZeros(0xF0000000));
- }
-
- /**
- * @tests java.lang.Integer#bitCount(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "bitCount",
- args = {int.class}
- )
- public void test_bitCountI() {
- assertEquals(0, Integer.bitCount(0x0));
- assertEquals(1, Integer.bitCount(0x1));
- assertEquals(1, Integer.bitCount(0x2));
- assertEquals(2, Integer.bitCount(0x3));
- assertEquals(1, Integer.bitCount(0x4));
- assertEquals(2, Integer.bitCount(0x5));
- assertEquals(2, Integer.bitCount(0x6));
- assertEquals(3, Integer.bitCount(0x7));
- assertEquals(1, Integer.bitCount(0x8));
- assertEquals(2, Integer.bitCount(0x9));
- assertEquals(2, Integer.bitCount(0xA));
- assertEquals(3, Integer.bitCount(0xB));
- assertEquals(2, Integer.bitCount(0xC));
- assertEquals(3, Integer.bitCount(0xD));
- assertEquals(3, Integer.bitCount(0xE));
- assertEquals(4, Integer.bitCount(0xF));
-
- assertEquals(8, Integer.bitCount(0xFF));
- assertEquals(12, Integer.bitCount(0xFFF));
- assertEquals(16, Integer.bitCount(0xFFFF));
- assertEquals(20, Integer.bitCount(0xFFFFF));
- assertEquals(24, Integer.bitCount(0xFFFFFF));
- assertEquals(28, Integer.bitCount(0xFFFFFFF));
- assertEquals(32, Integer.bitCount(0xFFFFFFFF));
- }
-
- /**
- * @tests java.lang.Integer#rotateLeft(int,int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "rotateLeft",
- args = {int.class, int.class}
- )
- public void test_rotateLeftII() {
- assertEquals(0xF, Integer.rotateLeft(0xF, 0));
- assertEquals(0xF0, Integer.rotateLeft(0xF, 4));
- assertEquals(0xF00, Integer.rotateLeft(0xF, 8));
- assertEquals(0xF000, Integer.rotateLeft(0xF, 12));
- assertEquals(0xF0000, Integer.rotateLeft(0xF, 16));
- assertEquals(0xF00000, Integer.rotateLeft(0xF, 20));
- assertEquals(0xF000000, Integer.rotateLeft(0xF, 24));
- assertEquals(0xF0000000, Integer.rotateLeft(0xF, 28));
- assertEquals(0xF0000000, Integer.rotateLeft(0xF0000000, 32));
- }
-
- /**
- * @tests java.lang.Integer#rotateRight(int,int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "rotateRight",
- args = {int.class, int.class}
- )
- public void test_rotateRightII() {
- assertEquals(0xF, Integer.rotateRight(0xF0, 4));
- assertEquals(0xF, Integer.rotateRight(0xF00, 8));
- assertEquals(0xF, Integer.rotateRight(0xF000, 12));
- assertEquals(0xF, Integer.rotateRight(0xF0000, 16));
- assertEquals(0xF, Integer.rotateRight(0xF00000, 20));
- assertEquals(0xF, Integer.rotateRight(0xF000000, 24));
- assertEquals(0xF, Integer.rotateRight(0xF0000000, 28));
- assertEquals(0xF0000000, Integer.rotateRight(0xF0000000, 32));
- assertEquals(0xF0000000, Integer.rotateRight(0xF0000000, 0));
-
- }
-
- /**
- * @tests java.lang.Integer#reverseBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reverseBytes",
- args = {int.class}
- )
- public void test_reverseBytesI() {
- assertEquals(0xAABBCCDD, Integer.reverseBytes(0xDDCCBBAA));
- assertEquals(0x11223344, Integer.reverseBytes(0x44332211));
- assertEquals(0x00112233, Integer.reverseBytes(0x33221100));
- assertEquals(0x20000002, Integer.reverseBytes(0x02000020));
- }
-
- /**
- * @tests java.lang.Integer#reverse(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reverse",
- args = {int.class}
- )
- public void test_reverseI() {
- assertEquals(-1, Integer.reverse(-1));
- assertEquals(0x80000000,Integer.reverse(1));
- }
-
- /**
- * @tests java.lang.Integer#signum(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "signum",
- args = {int.class}
- )
- public void test_signumI() {
- for (int i = -128; i<0; i++) {
- assertEquals(-1, Integer.signum(i));
- }
- assertEquals(0, Integer.signum(0));
- for (int i = 1; i<=127; i++) {
- assertEquals(1, Integer.signum(i));
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InternalErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InternalErrorTest.java
deleted file mode 100644
index 3ff4711..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InternalErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class InternalErrorTest extends TestCase {
-
- /**
- * @tests java.lang.InternalError#InternalError()
- */
- public void test_Constructor() {
- InternalError e = new InternalError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.InternalError#InternalError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- InternalError e = new InternalError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InterruptedExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InterruptedExceptionTest.java
deleted file mode 100644
index 96c85e6..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/InterruptedExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class InterruptedExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.InterruptedException#InterruptedException()
- */
- public void test_Constructor() {
- InterruptedException e = new InterruptedException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.InterruptedException#InterruptedException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- InterruptedException e = new InterruptedException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LinkageErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LinkageErrorTest.java
deleted file mode 100644
index 9c1adcb..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LinkageErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class LinkageErrorTest extends TestCase {
-
- /**
- * @tests java.lang.LinkageError#LinkageError()
- */
- public void test_Constructor() {
- LinkageError e = new LinkageError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.LinkageError#LinkageError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- LinkageError e = new LinkageError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java
deleted file mode 100644
index 432f802..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/LongTest.java
+++ /dev/null
@@ -1,1332 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.util.Properties;
-
-@TestTargetClass(Long.class)
-public class LongTest extends TestCase {
- private Properties orgProps;
-
- @Override
- protected void setUp() {
- orgProps = System.getProperties();
- }
-
- @Override
- protected void tearDown() {
- System.setProperties(orgProps);
- }
-
- /**
- * @tests java.lang.Long#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks bounary values.",
- method = "byteValue",
- args = {}
- )
- public void test_byteValue() {
- // Test for method byte java.lang.Long.byteValue()
- Long l = new Long(127);
- assertEquals("Returned incorrect byte value", 127, l.byteValue());
- assertEquals("Returned incorrect byte value", -1, new Long(Long.MAX_VALUE)
- .byteValue());
- }
-
- /**
- * @tests java.lang.Long#compareTo(java.lang.Long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Long.class}
- )
- public void test_compareToLjava_lang_Long() {
- // Test for method int java.lang.Long.compareTo(java.lang.Long)
- assertTrue("-2 compared to 1 gave non-negative answer", new Long(-2L)
- .compareTo(new Long(1L)) < 0);
- assertEquals("-2 compared to -2 gave non-zero answer", 0, new Long(-2L)
- .compareTo(new Long(-2L)));
- assertTrue("3 compared to 2 gave non-positive answer", new Long(3L)
- .compareTo(new Long(2L)) > 0);
-
- try {
- new Long(0).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Long#decode(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {java.lang.String.class}
- )
- public void test_decodeLjava_lang_String2() {
- // Test for method java.lang.Long
- // java.lang.Long.decode(java.lang.String)
- assertEquals("Returned incorrect value for hex string", 255L, Long.decode(
- "0xFF").longValue());
- assertEquals("Returned incorrect value for dec string", -89000L, Long.decode(
- "-89000").longValue());
- assertEquals("Returned incorrect value for 0 decimal", 0, Long.decode("0")
- .longValue());
- assertEquals("Returned incorrect value for 0 hex", 0, Long.decode("0x0")
- .longValue());
- assertTrue(
- "Returned incorrect value for most negative value decimal",
- Long.decode("-9223372036854775808").longValue() == 0x8000000000000000L);
- assertTrue(
- "Returned incorrect value for most negative value hex",
- Long.decode("-0x8000000000000000").longValue() == 0x8000000000000000L);
- assertTrue(
- "Returned incorrect value for most positive value decimal",
- Long.decode("9223372036854775807").longValue() == 0x7fffffffffffffffL);
- assertTrue(
- "Returned incorrect value for most positive value hex",
- Long.decode("0x7fffffffffffffff").longValue() == 0x7fffffffffffffffL);
- assertTrue("Failed for 07654321765432", Long.decode("07654321765432")
- .longValue() == 07654321765432l);
-
- boolean exception = false;
- try {
- Long
- .decode("999999999999999999999999999999999999999999999999999999");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for value > ilong", exception);
-
- exception = false;
- try {
- Long.decode("9223372036854775808");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.decode("-9223372036854775809");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Long.decode("0x8000000000000000");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.decode("-0x8000000000000001");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Long.decode("42325917317067571199");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for 42325917317067571199",
- exception);
- }
-
- /**
- * @tests java.lang.Long#getLong(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {java.lang.String.class}
- )
- public void test_getLongLjava_lang_String() {
- // Test for method java.lang.Long
- // java.lang.Long.getLong(java.lang.String)
- Properties tProps = new Properties();
- tProps.put("testLong", "99");
- tProps.put("testIncLong", "string");
- System.setProperties(tProps);
- assertTrue("returned incorrect Long", Long.getLong("testLong").equals(
- new Long(99)));
- assertNull("returned incorrect default Long",
- Long.getLong("ff"));
- assertNull("returned incorrect default Long",
- Long.getLong("testIncLong"));
- }
-
- /**
- * @tests java.lang.Long#getLong(java.lang.String, long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {java.lang.String.class, long.class}
- )
- public void test_getLongLjava_lang_StringJ() {
- // Test for method java.lang.Long
- // java.lang.Long.getLong(java.lang.String, long)
- Properties tProps = new Properties();
- tProps.put("testLong", "99");
- tProps.put("testIncLong", "string");
- System.setProperties(tProps);
- assertTrue("returned incorrect Long", Long.getLong("testLong", 4L)
- .equals(new Long(99)));
- assertTrue("returned incorrect default Long", Long.getLong("ff", 4L)
- .equals(new Long(4)));
- assertTrue("returned incorrect default Long", Long.getLong("testIncLong", 4L)
- .equals(new Long(4)));
- }
-
- /**
- * @tests java.lang.Long#getLong(java.lang.String, java.lang.Long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {java.lang.String.class, java.lang.Long.class}
- )
- public void test_getLongLjava_lang_StringLjava_lang_Long() {
- // Test for method java.lang.Long
- // java.lang.Long.getLong(java.lang.String, java.lang.Long)
- Properties tProps = new Properties();
- tProps.put("testLong", "99");
- tProps.put("testIncLong", "string");
- System.setProperties(tProps);
- assertTrue("returned incorrect Long", Long.getLong("testLong",
- new Long(4)).equals(new Long(99)));
- assertTrue("returned incorrect default Long", Long.getLong("ff",
- new Long(4)).equals(new Long(4)));
- assertTrue("returned incorrect default Long", Long.getLong("testIncLong",
- new Long(4)).equals(new Long(4)));
- }
-
- /**
- * @tests java.lang.Long#parseLong(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks boundary values and exceptions.",
- method = "parseLong",
- args = {java.lang.String.class}
- )
- public void test_parseLongLjava_lang_String2() {
- // Test for method long java.lang.Long.parseLong(java.lang.String)
-
- long l = Long.parseLong("89000000005");
- assertEquals("Parsed to incorrect long value", 89000000005L, l);
- assertEquals("Returned incorrect value for 0", 0, Long.parseLong("0"));
- assertTrue("Returned incorrect value for most negative value", Long
- .parseLong("-9223372036854775808") == 0x8000000000000000L);
- assertTrue("Returned incorrect value for most positive value", Long
- .parseLong("9223372036854775807") == 0x7fffffffffffffffL);
-
- boolean exception = false;
- try {
- Long.parseLong("9223372036854775808");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.parseLong("-9223372036854775809");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Long#parseLong(java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseLong",
- args = {java.lang.String.class, int.class}
- )
- public void test_parseLongLjava_lang_StringI() {
- // Test for method long java.lang.Long.parseLong(java.lang.String, int)
- assertEquals("Returned incorrect value",
- 100000000L, Long.parseLong("100000000", 10));
- assertEquals("Returned incorrect value from hex string", 68719476735L, Long.parseLong(
- "FFFFFFFFF", 16));
- assertTrue("Returned incorrect value from octal string: "
- + Long.parseLong("77777777777"), Long.parseLong("77777777777",
- 8) == 8589934591L);
- assertEquals("Returned incorrect value for 0 hex", 0, Long
- .parseLong("0", 16));
- assertTrue("Returned incorrect value for most negative value hex", Long
- .parseLong("-8000000000000000", 16) == 0x8000000000000000L);
- assertTrue("Returned incorrect value for most positive value hex", Long
- .parseLong("7fffffffffffffff", 16) == 0x7fffffffffffffffL);
- assertEquals("Returned incorrect value for 0 decimal", 0, Long.parseLong(
- "0", 10));
- assertTrue(
- "Returned incorrect value for most negative value decimal",
- Long.parseLong("-9223372036854775808", 10) == 0x8000000000000000L);
- assertTrue(
- "Returned incorrect value for most positive value decimal",
- Long.parseLong("9223372036854775807", 10) == 0x7fffffffffffffffL);
-
- boolean exception = false;
- try {
- Long.parseLong("999999999999", 8);
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
-
- exception = false;
- try {
- Long.parseLong("9223372036854775808", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.parseLong("-9223372036854775809", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Long.parseLong("8000000000000000", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.parseLong("-8000000000000001", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
-
- exception = false;
- try {
- Long.parseLong("42325917317067571199", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for 42325917317067571199",
- exception);
- }
-
- /**
- * @tests java.lang.Long#toBinaryString(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toBinaryString",
- args = {long.class}
- )
- public void test_toBinaryStringJ() {
- // Test for method java.lang.String java.lang.Long.toBinaryString(long)
- assertEquals("Incorrect binary string returned", "11011001010010010000", Long.toBinaryString(
- 890000L));
- assertEquals("Incorrect binary string returned",
-
- "1000000000000000000000000000000000000000000000000000000000000000", Long
- .toBinaryString(Long.MIN_VALUE)
- );
- assertEquals("Incorrect binary string returned",
-
- "111111111111111111111111111111111111111111111111111111111111111", Long
- .toBinaryString(Long.MAX_VALUE)
- );
- }
-
- /**
- * @tests java.lang.Long#toHexString(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toHexString",
- args = {long.class}
- )
- public void test_toHexStringJ() {
- // Test for method java.lang.String java.lang.Long.toHexString(long)
- assertEquals("Incorrect hex string returned", "54e0845", Long.toHexString(89000005L)
- );
- assertEquals("Incorrect hex string returned", "8000000000000000", Long.toHexString(
- Long.MIN_VALUE));
- assertEquals("Incorrect hex string returned", "7fffffffffffffff", Long.toHexString(
- Long.MAX_VALUE));
- }
-
- /**
- * @tests java.lang.Long#toOctalString(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toOctalString",
- args = {long.class}
- )
- public void test_toOctalStringJ() {
- // Test for method java.lang.String java.lang.Long.toOctalString(long)
- assertEquals("Returned incorrect oct string", "77777777777", Long.toOctalString(
- 8589934591L));
- assertEquals("Returned incorrect oct string", "1000000000000000000000", Long.toOctalString(
- Long.MIN_VALUE));
- assertEquals("Returned incorrect oct string", "777777777777777777777", Long.toOctalString(
- Long.MAX_VALUE));
- }
-
- /**
- * @tests java.lang.Long#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString2() {
- // Test for method java.lang.String java.lang.Long.toString()
- Long l = new Long(89000000005L);
- assertEquals("Returned incorrect String",
- "89000000005", l.toString());
- assertEquals("Returned incorrect String", "-9223372036854775808", new Long(Long.MIN_VALUE)
- .toString());
- assertEquals("Returned incorrect String", "9223372036854775807", new Long(Long.MAX_VALUE)
- .toString());
- }
-
- /**
- * @tests java.lang.Long#toString(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {long.class}
- )
- public void test_toStringJ2() {
- // Test for method java.lang.String java.lang.Long.toString(long)
-
- assertEquals("Returned incorrect String", "89000000005", Long.toString(89000000005L)
- );
- assertEquals("Returned incorrect String", "-9223372036854775808", Long.toString(Long.MIN_VALUE)
- );
- assertEquals("Returned incorrect String", "9223372036854775807", Long.toString(Long.MAX_VALUE)
- );
- }
-
- /**
- * @tests java.lang.Long#toString(long, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {long.class, int.class}
- )
- public void test_toStringJI() {
- // Test for method java.lang.String java.lang.Long.toString(long, int)
- assertEquals("Returned incorrect dec string", "100000000", Long.toString(100000000L,
- 10));
- assertEquals("Returned incorrect hex string", "fffffffff", Long.toString(68719476735L,
- 16));
- assertEquals("Returned incorrect oct string", "77777777777", Long.toString(8589934591L,
- 8));
- assertEquals("Returned incorrect bin string",
- "1111111111111111111111111111111111111111111", Long.toString(
- 8796093022207L, 2));
- assertEquals("Returned incorrect min string", "-9223372036854775808", Long.toString(
- 0x8000000000000000L, 10));
- assertEquals("Returned incorrect max string", "9223372036854775807", Long.toString(
- 0x7fffffffffffffffL, 10));
- assertEquals("Returned incorrect min string", "-8000000000000000", Long.toString(
- 0x8000000000000000L, 16));
- assertEquals("Returned incorrect max string", "7fffffffffffffff", Long.toString(
- 0x7fffffffffffffffL, 16));
- }
-
- /**
- * @tests java.lang.Long#valueOf(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String2() {
- // Test for method java.lang.Long
- // java.lang.Long.valueOf(java.lang.String)
- assertEquals("Returned incorrect value", 100000000L, Long.valueOf("100000000")
- .longValue());
- assertTrue("Returned incorrect value", Long.valueOf(
- "9223372036854775807").longValue() == Long.MAX_VALUE);
- assertTrue("Returned incorrect value", Long.valueOf(
- "-9223372036854775808").longValue() == Long.MIN_VALUE);
-
- boolean exception = false;
- try {
- Long
- .valueOf("999999999999999999999999999999999999999999999999999999999999");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
-
- exception = false;
- try {
- Long.valueOf("9223372036854775808");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
-
- exception = false;
- try {
- Long.valueOf("-9223372036854775809");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
- }
-
- /**
- * @tests java.lang.Long#valueOf(java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class, int.class}
- )
- public void test_valueOfLjava_lang_StringI() {
- // Test for method java.lang.Long
- // java.lang.Long.valueOf(java.lang.String, int)
- assertEquals("Returned incorrect value", 100000000L, Long.valueOf("100000000", 10)
- .longValue());
- assertEquals("Returned incorrect value from hex string", 68719476735L, Long.valueOf(
- "FFFFFFFFF", 16).longValue());
- assertTrue("Returned incorrect value from octal string: "
- + Long.valueOf("77777777777", 8).toString(), Long.valueOf(
- "77777777777", 8).longValue() == 8589934591L);
- assertTrue("Returned incorrect value", Long.valueOf(
- "9223372036854775807", 10).longValue() == Long.MAX_VALUE);
- assertTrue("Returned incorrect value", Long.valueOf(
- "-9223372036854775808", 10).longValue() == Long.MIN_VALUE);
- assertTrue("Returned incorrect value", Long.valueOf("7fffffffffffffff",
- 16).longValue() == Long.MAX_VALUE);
- assertTrue("Returned incorrect value", Long.valueOf(
- "-8000000000000000", 16).longValue() == Long.MIN_VALUE);
-
- boolean exception = false;
- try {
- Long.valueOf("999999999999", 8);
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
-
- exception = false;
- try {
- Long.valueOf("9223372036854775808", 10);
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
-
- exception = false;
- try {
- Long.valueOf("-9223372036854775809", 10);
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Failed to throw exception when passed invalid string",
- exception);
- }
- /**
- * @tests java.lang.Long#valueOf(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {long.class}
- )
- public void test_valueOfJ() {
- assertEquals(new Long(Long.MIN_VALUE), Long.valueOf(Long.MIN_VALUE));
- assertEquals(new Long(Long.MAX_VALUE), Long.valueOf(Long.MAX_VALUE));
- assertEquals(new Long( 0), Long.valueOf( 0));
-
- long lng = -128;
- while (lng < 128) {
- assertEquals(new Long(lng), Long.valueOf(lng));
- assertSame(Long.valueOf(lng), Long.valueOf(lng));
- lng++;
- }
- }
-
- /**
- * @tests java.lang.Long#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- assertEquals((int)(1L ^ (1L >>> 32)), new Long(1).hashCode());
- assertEquals((int)(2L ^ (2L >>> 32)), new Long(2).hashCode());
- assertEquals((int)(0L ^ (0L >>> 32)), new Long(0).hashCode());
- assertEquals((int)(-1L ^ (-1L >>> 32)), new Long(-1).hashCode());
- }
-
- /**
- * @tests java.lang.Long#Long(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Long",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- assertEquals(new Long(0), new Long("0"));
- assertEquals(new Long(1), new Long("1"));
- assertEquals(new Long(-1), new Long("-1"));
-
- try {
- new Long("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Long("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Long("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Long(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Long#Long
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Long",
- args = {long.class}
- )
- public void test_ConstructorJ() {
- assertEquals(1, new Long(1).intValue());
- assertEquals(2, new Long(2).intValue());
- assertEquals(0, new Long(0).intValue());
- assertEquals(-1, new Long(-1).intValue());
- }
-
- /**
- * @tests java.lang.Long#byteValue()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundary values.",
- method = "byteValue",
- args = {}
- )
- public void test_byteValue2() {
- assertEquals(1, new Long(1).byteValue());
- assertEquals(2, new Long(2).byteValue());
- assertEquals(0, new Long(0).byteValue());
- assertEquals(-1, new Long(-1).byteValue());
- }
-
- /**
- * @tests java.lang.Long#equals(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- assertEquals(new Long(0), Long.valueOf(0));
- assertEquals(new Long(1), Long.valueOf(1));
- assertEquals(new Long(-1), Long.valueOf(-1));
-
- Long fixture = new Long(25);
- assertEquals(fixture, fixture);
- assertFalse(fixture.equals(null));
- assertFalse(fixture.equals("Not a Long"));
- }
-
- /**
- * @tests java.lang.Long#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- assertEquals("-1", new Long(-1).toString());
- assertEquals("0", new Long(0).toString());
- assertEquals("1", new Long(1).toString());
- assertEquals("-1", new Long(0xFFFFFFFF).toString());
- }
-
- /**
- * @tests java.lang.Long#toString
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {long.class}
- )
- public void test_toStringJ() {
- assertEquals("-1", Long.toString(-1));
- assertEquals("0", Long.toString(0));
- assertEquals("1", Long.toString(1));
- assertEquals("-1", Long.toString(0xFFFFFFFF));
- }
-
- /**
- * @tests java.lang.Long#valueOf(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLjava_lang_String() {
- assertEquals(new Long(0), Long.valueOf("0"));
- assertEquals(new Long(1), Long.valueOf("1"));
- assertEquals(new Long(-1), Long.valueOf("-1"));
-
- try {
- Long.valueOf("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Long#valueOf(String,long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class, int.class}
- )
- public void test_valueOfLjava_lang_StringJ() {
- assertEquals(new Long(0), Long.valueOf("0", 10));
- assertEquals(new Long(1), Long.valueOf("1", 10));
- assertEquals(new Long(-1), Long.valueOf("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Long.valueOf("1", 2).byteValue());
- assertEquals(Character.digit('F', 16), Long.valueOf("F", 16).byteValue());
-
- try {
- Long.valueOf("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.valueOf(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Long#parseLong(String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check boundary values.",
- method = "parseLong",
- args = {java.lang.String.class}
- )
- public void test_parseLongLjava_lang_String() {
- assertEquals(0, Long.parseLong("0"));
- assertEquals(1, Long.parseLong("1"));
- assertEquals(-1, Long.parseLong("-1"));
-
- try {
- Long.parseLong("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Long#parseLong(String,long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't check boundary values.",
- method = "parseLong",
- args = {java.lang.String.class, int.class}
- )
- public void test_parseLongLjava_lang_StringJ() {
- assertEquals(0, Long.parseLong("0", 10));
- assertEquals(1, Long.parseLong("1", 10));
- assertEquals(-1, Long.parseLong("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Long.parseLong("1", 2));
- assertEquals(Character.digit('F', 16), Long.parseLong("F", 16));
-
- try {
- Long.parseLong("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.parseLong(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Long#decode(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {java.lang.String.class}
- )
- public void test_decodeLjava_lang_String() {
- assertEquals(new Long(0), Long.decode("0"));
- assertEquals(new Long(1), Long.decode("1"));
- assertEquals(new Long(-1), Long.decode("-1"));
- assertEquals(new Long(0xF), Long.decode("0xF"));
- assertEquals(new Long(0xF), Long.decode("#F"));
- assertEquals(new Long(0xF), Long.decode("0XF"));
- assertEquals(new Long(07), Long.decode("07"));
-
- try {
- Long.decode("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.decode("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Long.decode(null);
- //undocumented NPE, but seems consistent across JREs
- fail("Expected NullPointerException with null string.");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.lang.Long#doubleValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "doubleValue",
- args = {}
- )
- public void test_doubleValue() {
- assertEquals(-1D, new Long(-1).doubleValue(), 0D);
- assertEquals(0D, new Long(0).doubleValue(), 0D);
- assertEquals(1D, new Long(1).doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Long#floatValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "floatValue",
- args = {}
- )
- public void test_floatValue() {
- assertEquals(-1F, new Long(-1).floatValue(), 0F);
- assertEquals(0F, new Long(0).floatValue(), 0F);
- assertEquals(1F, new Long(1).floatValue(), 0F);
-
- assertEquals(Long.MAX_VALUE, new Long(Long.MAX_VALUE).floatValue(), 0F);
- assertEquals(Long.MIN_VALUE, new Long(Long.MIN_VALUE).floatValue(), 0F);
- }
-
- /**
- * @tests java.lang.Long#intValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "intValue",
- args = {}
- )
- public void test_intValue() {
- assertEquals(-1, new Long(-1).intValue());
- assertEquals(0, new Long(0).intValue());
- assertEquals(1, new Long(1).intValue());
-
- assertEquals(-1, new Long(Long.MAX_VALUE).intValue());
- assertEquals(0, new Long(Long.MIN_VALUE).intValue());
- }
-
- /**
- * @tests java.lang.Long#longValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "longValue",
- args = {}
- )
- public void test_longValue() {
- assertEquals(-1L, new Long(-1).longValue());
- assertEquals(0L, new Long(0).longValue());
- assertEquals(1L, new Long(1).longValue());
-
- assertEquals(Long.MAX_VALUE, new Long(Long.MAX_VALUE).longValue());
- assertEquals(Long.MIN_VALUE, new Long(Long.MIN_VALUE).longValue());
- }
-
- /**
- * @tests java.lang.Long#shortValue()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "shortValue",
- args = {}
- )
- public void test_shortValue() {
- assertEquals(-1, new Long(-1).shortValue());
- assertEquals(0, new Long(0).shortValue());
- assertEquals(1, new Long(1).shortValue());
-
- assertEquals(-1, new Long(Long.MAX_VALUE).shortValue());
- assertEquals(0, new Long(Long.MIN_VALUE).shortValue());
- }
- /**
- * @tests java.lang.Long#highestOneBit(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "highestOneBit",
- args = {long.class}
- )
- public void test_highestOneBitJ() {
- assertEquals(0x08, Long.highestOneBit(0x0A));
- assertEquals(0x08, Long.highestOneBit(0x0B));
- assertEquals(0x08, Long.highestOneBit(0x0C));
- assertEquals(0x08, Long.highestOneBit(0x0F));
- assertEquals(0x80, Long.highestOneBit(0xFF));
-
- assertEquals(0x080000, Long.highestOneBit(0x0F1234));
- assertEquals(0x800000, Long.highestOneBit(0xFF9977));
-
- assertEquals(0x8000000000000000L, Long.highestOneBit(0xFFFFFFFFFFFFFFFFL));
-
- assertEquals(0, Long.highestOneBit(0));
- assertEquals(1, Long.highestOneBit(1));
- assertEquals(0x8000000000000000L, Long.highestOneBit(-1));
- }
-
- /**
- * @tests java.lang.Long#lowestOneBit(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lowestOneBit",
- args = {long.class}
- )
- public void test_lowestOneBitJ() {
- assertEquals(0x10, Long.lowestOneBit(0xF0));
-
- assertEquals(0x10, Long.lowestOneBit(0x90));
- assertEquals(0x10, Long.lowestOneBit(0xD0));
-
- assertEquals(0x10, Long.lowestOneBit(0x123490));
- assertEquals(0x10, Long.lowestOneBit(0x1234D0));
-
- assertEquals(0x100000, Long.lowestOneBit(0x900000));
- assertEquals(0x100000, Long.lowestOneBit(0xD00000));
-
- assertEquals(0x40, Long.lowestOneBit(0x40));
- assertEquals(0x40, Long.lowestOneBit(0xC0));
-
- assertEquals(0x4000, Long.lowestOneBit(0x4000));
- assertEquals(0x4000, Long.lowestOneBit(0xC000));
-
- assertEquals(0x4000, Long.lowestOneBit(0x99994000));
- assertEquals(0x4000, Long.lowestOneBit(0x9999C000));
-
- assertEquals(0, Long.lowestOneBit(0));
- assertEquals(1, Long.lowestOneBit(1));
- assertEquals(1, Long.lowestOneBit(-1));
- }
- /**
- * @tests java.lang.Long#numberOfLeadingZeros(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "numberOfLeadingZeros",
- args = {long.class}
- )
- public void test_numberOfLeadingZerosJ() {
- assertEquals(64, Long.numberOfLeadingZeros(0x0L));
- assertEquals(63, Long.numberOfLeadingZeros(0x1));
- assertEquals(62, Long.numberOfLeadingZeros(0x2));
- assertEquals(62, Long.numberOfLeadingZeros(0x3));
- assertEquals(61, Long.numberOfLeadingZeros(0x4));
- assertEquals(61, Long.numberOfLeadingZeros(0x5));
- assertEquals(61, Long.numberOfLeadingZeros(0x6));
- assertEquals(61, Long.numberOfLeadingZeros(0x7));
- assertEquals(60, Long.numberOfLeadingZeros(0x8));
- assertEquals(60, Long.numberOfLeadingZeros(0x9));
- assertEquals(60, Long.numberOfLeadingZeros(0xA));
- assertEquals(60, Long.numberOfLeadingZeros(0xB));
- assertEquals(60, Long.numberOfLeadingZeros(0xC));
- assertEquals(60, Long.numberOfLeadingZeros(0xD));
- assertEquals(60, Long.numberOfLeadingZeros(0xE));
- assertEquals(60, Long.numberOfLeadingZeros(0xF));
- assertEquals(59, Long.numberOfLeadingZeros(0x10));
- assertEquals(56, Long.numberOfLeadingZeros(0x80));
- assertEquals(56, Long.numberOfLeadingZeros(0xF0));
- assertEquals(55, Long.numberOfLeadingZeros(0x100));
- assertEquals(52, Long.numberOfLeadingZeros(0x800));
- assertEquals(52, Long.numberOfLeadingZeros(0xF00));
- assertEquals(51, Long.numberOfLeadingZeros(0x1000));
- assertEquals(48, Long.numberOfLeadingZeros(0x8000));
- assertEquals(48, Long.numberOfLeadingZeros(0xF000));
- assertEquals(47, Long.numberOfLeadingZeros(0x10000));
- assertEquals(44, Long.numberOfLeadingZeros(0x80000));
- assertEquals(44, Long.numberOfLeadingZeros(0xF0000));
- assertEquals(43, Long.numberOfLeadingZeros(0x100000));
- assertEquals(40, Long.numberOfLeadingZeros(0x800000));
- assertEquals(40, Long.numberOfLeadingZeros(0xF00000));
- assertEquals(39, Long.numberOfLeadingZeros(0x1000000));
- assertEquals(36, Long.numberOfLeadingZeros(0x8000000));
- assertEquals(36, Long.numberOfLeadingZeros(0xF000000));
- assertEquals(35, Long.numberOfLeadingZeros(0x10000000));
- assertEquals(0, Long.numberOfLeadingZeros(0x80000000));
- assertEquals(0, Long.numberOfLeadingZeros(0xF0000000));
-
- assertEquals(1, Long.numberOfLeadingZeros(Long.MAX_VALUE));
- assertEquals(0, Long.numberOfLeadingZeros(Long.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.Long#numberOfTrailingZeros(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "numberOfTrailingZeros",
- args = {long.class}
- )
- public void test_numberOfTrailingZerosJ() {
- assertEquals(64, Long.numberOfTrailingZeros(0x0));
- assertEquals(63, Long.numberOfTrailingZeros(Long.MIN_VALUE));
- assertEquals(0, Long.numberOfTrailingZeros(Long.MAX_VALUE));
-
- assertEquals(0, Long.numberOfTrailingZeros(0x1));
- assertEquals(3, Long.numberOfTrailingZeros(0x8));
- assertEquals(0, Long.numberOfTrailingZeros(0xF));
-
- assertEquals(4, Long.numberOfTrailingZeros(0x10));
- assertEquals(7, Long.numberOfTrailingZeros(0x80));
- assertEquals(4, Long.numberOfTrailingZeros(0xF0));
-
- assertEquals(8, Long.numberOfTrailingZeros(0x100));
- assertEquals(11, Long.numberOfTrailingZeros(0x800));
- assertEquals(8, Long.numberOfTrailingZeros(0xF00));
-
- assertEquals(12, Long.numberOfTrailingZeros(0x1000));
- assertEquals(15, Long.numberOfTrailingZeros(0x8000));
- assertEquals(12, Long.numberOfTrailingZeros(0xF000));
-
- assertEquals(16, Long.numberOfTrailingZeros(0x10000));
- assertEquals(19, Long.numberOfTrailingZeros(0x80000));
- assertEquals(16, Long.numberOfTrailingZeros(0xF0000));
-
- assertEquals(20, Long.numberOfTrailingZeros(0x100000));
- assertEquals(23, Long.numberOfTrailingZeros(0x800000));
- assertEquals(20, Long.numberOfTrailingZeros(0xF00000));
-
- assertEquals(24, Long.numberOfTrailingZeros(0x1000000));
- assertEquals(27, Long.numberOfTrailingZeros(0x8000000));
- assertEquals(24, Long.numberOfTrailingZeros(0xF000000));
-
- assertEquals(28, Long.numberOfTrailingZeros(0x10000000));
- assertEquals(31, Long.numberOfTrailingZeros(0x80000000));
- assertEquals(28, Long.numberOfTrailingZeros(0xF0000000));
- }
-
- /**
- * @tests java.lang.Long#bitCount(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "bitCount",
- args = {long.class}
- )
- public void test_bitCountJ() {
- assertEquals(0, Long.bitCount(0x0));
- assertEquals(1, Long.bitCount(0x1));
- assertEquals(1, Long.bitCount(0x2));
- assertEquals(2, Long.bitCount(0x3));
- assertEquals(1, Long.bitCount(0x4));
- assertEquals(2, Long.bitCount(0x5));
- assertEquals(2, Long.bitCount(0x6));
- assertEquals(3, Long.bitCount(0x7));
- assertEquals(1, Long.bitCount(0x8));
- assertEquals(2, Long.bitCount(0x9));
- assertEquals(2, Long.bitCount(0xA));
- assertEquals(3, Long.bitCount(0xB));
- assertEquals(2, Long.bitCount(0xC));
- assertEquals(3, Long.bitCount(0xD));
- assertEquals(3, Long.bitCount(0xE));
- assertEquals(4, Long.bitCount(0xF));
-
- assertEquals(8, Long.bitCount(0xFF));
- assertEquals(12, Long.bitCount(0xFFF));
- assertEquals(16, Long.bitCount(0xFFFF));
- assertEquals(20, Long.bitCount(0xFFFFF));
- assertEquals(24, Long.bitCount(0xFFFFFF));
- assertEquals(28, Long.bitCount(0xFFFFFFF));
- assertEquals(64, Long.bitCount(0xFFFFFFFFFFFFFFFFL));
- }
-
- /**
- * @tests java.lang.Long#rotateLeft(long,long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "rotateLeft",
- args = {long.class, int.class}
- )
- public void test_rotateLeftJI() {
- assertEquals(0xF, Long.rotateLeft(0xF, 0));
- assertEquals(0xF0, Long.rotateLeft(0xF, 4));
- assertEquals(0xF00, Long.rotateLeft(0xF, 8));
- assertEquals(0xF000, Long.rotateLeft(0xF, 12));
- assertEquals(0xF0000, Long.rotateLeft(0xF, 16));
- assertEquals(0xF00000, Long.rotateLeft(0xF, 20));
- assertEquals(0xF000000, Long.rotateLeft(0xF, 24));
- assertEquals(0xF0000000L, Long.rotateLeft(0xF, 28));
- assertEquals(0xF000000000000000L, Long.rotateLeft(0xF000000000000000L, 64));
- }
-
- /**
- * @tests java.lang.Long#rotateRight(long,long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "rotateRight",
- args = {long.class, int.class}
- )
- public void test_rotateRightJI() {
- assertEquals(0xF, Long.rotateRight(0xF0, 4));
- assertEquals(0xF, Long.rotateRight(0xF00, 8));
- assertEquals(0xF, Long.rotateRight(0xF000, 12));
- assertEquals(0xF, Long.rotateRight(0xF0000, 16));
- assertEquals(0xF, Long.rotateRight(0xF00000, 20));
- assertEquals(0xF, Long.rotateRight(0xF000000, 24));
- assertEquals(0xF, Long.rotateRight(0xF0000000L, 28));
- assertEquals(0xF000000000000000L, Long.rotateRight(0xF000000000000000L, 64));
- assertEquals(0xF000000000000000L, Long.rotateRight(0xF000000000000000L, 0));
-
- }
-
- /**
- * @tests java.lang.Long#reverseBytes(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reverseBytes",
- args = {long.class}
- )
- public void test_reverseBytesJ() {
- assertEquals(0xAABBCCDD00112233L, Long.reverseBytes(0x33221100DDCCBBAAL));
- assertEquals(0x1122334455667788L, Long.reverseBytes(0x8877665544332211L));
- assertEquals(0x0011223344556677L, Long.reverseBytes(0x7766554433221100L));
- assertEquals(0x2000000000000002L, Long.reverseBytes(0x0200000000000020L));
- }
-
- /**
- * @tests java.lang.Long#reverse(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reverse",
- args = {long.class}
- )
- public void test_reverseJ() {
- assertEquals(0, Long.reverse(0));
- assertEquals(-1, Long.reverse(-1));
- assertEquals(0x8000000000000000L,Long.reverse(1));
- }
-
- /**
- * @tests java.lang.Long#signum(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "signum",
- args = {long.class}
- )
- public void test_signumJ() {
- for (int i = -128; i<0; i++) {
- assertEquals(-1, Long.signum(i));
- }
- assertEquals(0, Long.signum(0));
- for (int i = 1; i<=127; i++) {
- assertEquals(1, Long.signum(i));
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
deleted file mode 100644
index ceabd2c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MathTest.java
+++ /dev/null
@@ -1,1987 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class MathTest extends junit.framework.TestCase {
-
- double HYP = Math.sqrt(2.0);
-
- double OPP = 1.0;
-
- double ADJ = 1.0;
-
- /* Required to make previous preprocessor flags work - do not remove */
- int unused = 0;
-
- /**
- * @tests java.lang.Math#abs(double)
- */
- public void test_absD() {
- // Test for method double java.lang.Math.abs(double)
-
- assertTrue("Incorrect double abs value",
- (Math.abs(-1908.8976) == 1908.8976));
- assertTrue("Incorrect double abs value",
- (Math.abs(1908.8976) == 1908.8976));
- }
-
- /**
- * @tests java.lang.Math#abs(float)
- */
- public void test_absF() {
- // Test for method float java.lang.Math.abs(float)
- assertTrue("Incorrect float abs value",
- (Math.abs(-1908.8976f) == 1908.8976f));
- assertTrue("Incorrect float abs value",
- (Math.abs(1908.8976f) == 1908.8976f));
- }
-
- /**
- * @tests java.lang.Math#abs(int)
- */
- public void test_absI() {
- // Test for method int java.lang.Math.abs(int)
- assertTrue("Incorrect int abs value", (Math.abs(-1908897) == 1908897));
- assertTrue("Incorrect int abs value", (Math.abs(1908897) == 1908897));
- }
-
- /**
- * @tests java.lang.Math#abs(long)
- */
- public void test_absJ() {
- // Test for method long java.lang.Math.abs(long)
- assertTrue("Incorrect long abs value",
- (Math.abs(-19088976000089L) == 19088976000089L));
- assertTrue("Incorrect long abs value",
- (Math.abs(19088976000089L) == 19088976000089L));
- }
-
- /**
- * @tests java.lang.Math#acos(double)
- */
- public void test_acosD() {
- // Test for method double java.lang.Math.acos(double)
- double r = Math.cos(Math.acos(ADJ / HYP));
- long lr = Double.doubleToLongBits(r);
- long t = Double.doubleToLongBits(ADJ / HYP);
- assertTrue("Returned incorrect arc cosine", lr == t || (lr + 1) == t
- || (lr - 1) == t);
- }
-
- /**
- * @tests java.lang.Math#asin(double)
- */
- public void test_asinD() {
- // Test for method double java.lang.Math.asin(double)
- double r = Math.sin(Math.asin(OPP / HYP));
- long lr = Double.doubleToLongBits(r);
- long t = Double.doubleToLongBits(OPP / HYP);
- assertTrue("Returned incorrect arc sine", lr == t || (lr + 1) == t
- || (lr - 1) == t);
- }
-
- /**
- * @tests java.lang.Math#atan(double)
- */
- public void test_atanD() {
- // Test for method double java.lang.Math.atan(double)
- double answer = Math.tan(Math.atan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.Math#atan2(double, double)
- */
- public void test_atan2DD() {
- // Test for method double java.lang.Math.atan2(double, double)
- double answer = Math.atan(Math.tan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.Math#cbrt(double)
- */
- public void test_cbrt_D() {
- //Test for special situations
- assertTrue("Should return Double.NaN", Double.isNaN(Math
- .cbrt(Double.NaN)));
- assertEquals("Should return Double.POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math
- .cbrt(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return Double.NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, Math
- .cbrt(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .cbrt(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double.doubleToLongBits(Math
- .cbrt(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double.doubleToLongBits(Math
- .cbrt(-0.0)));
-
- assertEquals("Should return 3.0", 3.0, Math.cbrt(27.0), 0D);
- assertEquals("Should return 23.111993172558684", 23.111993172558684,
- Math.cbrt(12345.6), 0D);
- assertEquals("Should return 5.643803094122362E102",
- 5.643803094122362E102, Math.cbrt(Double.MAX_VALUE), 0D);
- assertEquals("Should return 0.01", 0.01, Math.cbrt(0.000001), 0D);
-
- assertEquals("Should return -3.0", -3.0, Math.cbrt(-27.0), 0D);
- assertEquals("Should return -23.111993172558684", -23.111993172558684,
- Math.cbrt(-12345.6), 0D);
- assertEquals("Should return 1.7031839360032603E-108",
- 1.7031839360032603E-108, Math.cbrt(Double.MIN_VALUE), 0D);
- assertEquals("Should return -0.01", -0.01, Math.cbrt(-0.000001), 0D);
- }
-
- /**
- * @tests java.lang.Math#ceil(double)
- */
- public void test_ceilD() {
- // Test for method double java.lang.Math.ceil(double)
- assertEquals("Incorrect ceiling for double",
- 79, Math.ceil(78.89), 0);
- assertEquals("Incorrect ceiling for double",
- -78, Math.ceil(-78.89), 0);
- }
-
- /**
- * cases for test_copySign_DD in MathTest/StrictMathTest
- */
- static final double[] COPYSIGN_DD_CASES = new double[] {
- Double.POSITIVE_INFINITY, Double.MAX_VALUE, 3.4E302, 2.3,
- Double.MIN_NORMAL, Double.MIN_NORMAL / 2, Double.MIN_VALUE, +0.0,
- 0.0, -0.0, -Double.MIN_VALUE, -Double.MIN_NORMAL / 2,
- -Double.MIN_NORMAL, -4.5, -3.4E102, -Double.MAX_VALUE,
- Double.NEGATIVE_INFINITY };
-
- /**
- * @tests {@link java.lang.Math#copySign(double, double)}
- * @since 1.6
- *
- */
- @SuppressWarnings("boxing")
- public void test_copySign_DD() {
- for (int i = 0; i < COPYSIGN_DD_CASES.length; i++) {
- final double magnitude = COPYSIGN_DD_CASES[i];
- final long absMagnitudeBits = Double.doubleToLongBits(Math
- .abs(magnitude));
- final long negMagnitudeBits = Double.doubleToLongBits(-Math
- .abs(magnitude));
-
- // cases for NaN
- assertEquals("If the sign is NaN, the result should be positive.",
- absMagnitudeBits, Double.doubleToLongBits(Math.copySign(
- magnitude, Double.NaN)));
- assertTrue("The result should be NaN.", Double.isNaN(Math.copySign(
- Double.NaN, magnitude)));
-
- for (int j = 0; j < COPYSIGN_DD_CASES.length; j++) {
- final double sign = COPYSIGN_DD_CASES[j];
- final long resultBits = Double.doubleToLongBits(Math.copySign(
- magnitude, sign));
-
- if (sign > 0 || Double.valueOf(+0.0).equals(sign)
- || Double.valueOf(0.0).equals(sign)) {
- assertEquals(
- "If the sign is positive, the result should be positive.",
- absMagnitudeBits, resultBits);
- }
- if (sign < 0 || Double.valueOf(-0.0).equals(sign)) {
- assertEquals(
- "If the sign is negative, the result should be negative.",
- negMagnitudeBits, resultBits);
- }
- }
- }
-
- assertTrue("The result should be NaN.", Double.isNaN(Math.copySign(
- Double.NaN, Double.NaN)));
-
- try {
- Math.copySign((Double) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.copySign(2.3, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.copySign((Double) null, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * cases for test_copySign_FF in MathTest/StrictMathTest
- */
- static final float[] COPYSIGN_FF_CASES = new float[] {
- Float.POSITIVE_INFINITY, Float.MAX_VALUE, 3.4E12f, 2.3f,
- Float.MIN_NORMAL, Float.MIN_NORMAL / 2, Float.MIN_VALUE, +0.0f,
- 0.0f, -0.0f, -Float.MIN_VALUE, -Float.MIN_NORMAL / 2,
- -Float.MIN_NORMAL, -4.5f, -5.6442E21f, -Float.MAX_VALUE,
- Float.NEGATIVE_INFINITY };
-
- /**
- * @tests {@link java.lang.Math#copySign(float, float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_copySign_FF() {
- for (int i = 0; i < COPYSIGN_FF_CASES.length; i++) {
- final float magnitude = COPYSIGN_FF_CASES[i];
- final int absMagnitudeBits = Float.floatToIntBits(Math
- .abs(magnitude));
- final int negMagnitudeBits = Float.floatToIntBits(-Math
- .abs(magnitude));
-
- // cases for NaN
- assertEquals("If the sign is NaN, the result should be positive.",
- absMagnitudeBits, Float.floatToIntBits(Math.copySign(
- magnitude, Float.NaN)));
- assertTrue("The result should be NaN.", Float.isNaN(Math.copySign(
- Float.NaN, magnitude)));
-
- for (int j = 0; j < COPYSIGN_FF_CASES.length; j++) {
- final float sign = COPYSIGN_FF_CASES[j];
- final int resultBits = Float.floatToIntBits(Math.copySign(
- magnitude, sign));
- if (sign > 0 || Float.valueOf(+0.0f).equals(sign)
- || Float.valueOf(0.0f).equals(sign)) {
- assertEquals(
- "If the sign is positive, the result should be positive.",
- absMagnitudeBits, resultBits);
- }
- if (sign < 0 || Float.valueOf(-0.0f).equals(sign)) {
- assertEquals(
- "If the sign is negative, the result should be negative.",
- negMagnitudeBits, resultBits);
- }
- }
- }
-
- assertTrue("The result should be NaN.", Float.isNaN(Math.copySign(
- Float.NaN, Float.NaN)));
-
- try {
- Math.copySign((Float) null, 2.3f);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.copySign(2.3f, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.copySign((Float) null, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.Math#cos(double)
- */
- public void test_cosD() {
- // Test for method double java.lang.Math.cos(double)
- assertEquals("Incorrect answer", 1.0, Math.cos(0), 0D);
- assertEquals("Incorrect answer", 0.5403023058681398, Math.cos(1), 0D);
- }
-
- /**
- * @tests java.lang.Math#cosh(double)
- */
- public void test_cosh_D() {
- // Test for special situations
- assertTrue(Double.isNaN(Math.cosh(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.cosh(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.cosh(Double.NEGATIVE_INFINITY), 0D);
- assertEquals("Should return 1.0", 1.0, Math.cosh(+0.0), 0D);
- assertEquals("Should return 1.0", 1.0, Math.cosh(-0.0), 0D);
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.cosh(1234.56), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.cosh(-1234.56), 0D);
- assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
- .cosh(0.000001), 0D);
- assertEquals("Should return 1.0000000000005", 1.0000000000005, Math
- .cosh(-0.000001), 0D);
- assertEquals("Should return 5.212214351945598", 5.212214351945598, Math
- .cosh(2.33482), 0D);
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.cosh(Double.MAX_VALUE), 0D);
- assertEquals("Should return 1.0", 1.0, Math.cosh(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#exp(double)
- */
- public void test_expD() {
- // Test for method double java.lang.Math.exp(double)
- assertTrue("Incorrect answer returned for simple power", Math.abs(Math
- .exp(4D)
- - Math.E * Math.E * Math.E * Math.E) < 0.1D);
- assertTrue("Incorrect answer returned for larger power", Math.log(Math
- .abs(Math.exp(5.5D)) - 5.5D) < 10.0D);
- }
-
- /**
- * @tests java.lang.Math#expm1(double)
- */
- public void test_expm1_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double.isNaN(Math.expm1(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.expm1(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return -1.0", -1.0, Math
- .expm1(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .expm1(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(Math.expm1(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(Math.expm1(-0.0)));
-
- assertEquals("Should return -9.999950000166666E-6",
- -9.999950000166666E-6, Math.expm1(-0.00001), 0D);
- assertEquals("Should return 1.0145103074469635E60",
- 1.0145103074469635E60, Math.expm1(138.16951162), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math
- .expm1(123456789123456789123456789.4521584223), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.expm1(Double.MAX_VALUE), 0D);
- assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, Math
- .expm1(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#floor(double)
- */
- public void test_floorD() {
- assertEquals("Incorrect floor for int", 42, Math.floor(42), 0);
- assertEquals("Incorrect floor for -int", -2, Math.floor(-2), 0);
- assertEquals("Incorrect floor for zero", 0d, Math.floor(0d), 0);
-
- assertEquals("Incorrect floor for +double", 78, Math.floor(78.89), 0);
- assertEquals("Incorrect floor for -double", -79, Math.floor(-78.89), 0);
- assertEquals("floor large +double", 3.7314645675925406E19, Math.floor(3.7314645675925406E19), 0);
- assertEquals("floor large -double", -8.173521839218E12, Math.floor(-8.173521839218E12), 0);
- assertEquals("floor small double", 0.0d, Math.floor(1.11895241315E-102), 0);
-
- // Compare toString representations here since -0.0 = +0.0, and
- // NaN != NaN and we need to distinguish
- assertEquals("Floor failed for NaN",
- Double.toString(Double.NaN), Double.toString(Math.floor(Double.NaN)));
- assertEquals("Floor failed for +0.0",
- Double.toString(+0.0d), Double.toString(Math.floor(+0.0d)));
- assertEquals("Floor failed for -0.0",
- Double.toString(-0.0d), Double.toString(Math.floor(-0.0d)));
- assertEquals("Floor failed for +infinity",
- Double.toString(Double.POSITIVE_INFINITY), Double.toString(Math.floor(Double.POSITIVE_INFINITY)));
- assertEquals("Floor failed for -infinity",
- Double.toString(Double.NEGATIVE_INFINITY), Double.toString(Math.floor(Double.NEGATIVE_INFINITY)));
- }
-
- /**
- * cases for test_getExponent_D in MathTest/StrictMathTest
- */
- static final double GETEXPONENT_D_CASES[] = new double[] {
- Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY,
- Double.MAX_VALUE, -Double.MAX_VALUE, 2.342E231, -2.342E231, 2800.0,
- -2800.0, 5.323, -5.323, 1.323, -1.323, 0.623, -0.623, 0.323,
- -0.323, Double.MIN_NORMAL * 24, -Double.MIN_NORMAL * 24,
- Double.MIN_NORMAL, -Double.MIN_NORMAL, Double.MIN_NORMAL / 2,
- -Double.MIN_NORMAL / 2, Double.MIN_VALUE, -Double.MIN_VALUE, +0.0,
- 0.0, -0.0, Double.NaN };
-
- /**
- * result for test_getExponent_D in MathTest/StrictMathTest
- */
- static final int GETEXPONENT_D_RESULTS[] = new int[] {
- Double.MAX_EXPONENT + 1, Double.MAX_EXPONENT + 1,
- Double.MAX_EXPONENT, Double.MAX_EXPONENT, 768, 768, 11, 11, 2, 2,
- 0, 0, -1, -1, -2, -2, -1018, -1018, Double.MIN_EXPONENT,
- Double.MIN_EXPONENT, Double.MIN_EXPONENT - 1,
- Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
- Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
- Double.MIN_EXPONENT - 1, Double.MIN_EXPONENT - 1,
- Double.MAX_EXPONENT + 1 };
-
- /**
- * @tests {@link java.lang.Math#getExponent(double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_getExponent_D() {
- for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) {
- final double number = GETEXPONENT_D_CASES[i];
- final int result = GETEXPONENT_D_RESULTS[i];
- assertEquals("Wrong result of getExponent(double).", result, Math
- .getExponent(number));
- }
-
- try {
- Math.getExponent((Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * cases for test_getExponent_F in MathTest/StrictMathTest
- */
- static final float GETEXPONENT_F_CASES[] = new float[] {
- Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.MAX_VALUE,
- -Float.MAX_VALUE, 3.4256E23f, -3.4256E23f, 2800.0f, -2800.0f,
- 5.323f, -5.323f, 1.323f, -1.323f, 0.623f, -0.623f, 0.323f, -0.323f,
- Float.MIN_NORMAL * 24, -Float.MIN_NORMAL * 24, Float.MIN_NORMAL,
- -Float.MIN_NORMAL, Float.MIN_NORMAL / 2, -Float.MIN_NORMAL / 2,
- Float.MIN_VALUE, -Float.MIN_VALUE, +0.0f, 0.0f, -0.0f, Float.NaN,1,Float.MIN_NORMAL * 1.5f };
-
- /**
- * result for test_getExponent_F in MathTest/StrictMathTest
- */
- static final int GETEXPONENT_F_RESULTS[] = new int[] {
- Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT + 1, Float.MAX_EXPONENT,
- Float.MAX_EXPONENT, 78, 78, 11, 11, 2, 2, 0, 0, -1, -1, -2, -2,
- -122, -122, Float.MIN_EXPONENT, Float.MIN_EXPONENT,
- Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
- Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
- Float.MIN_EXPONENT - 1, Float.MIN_EXPONENT - 1,
- Float.MIN_EXPONENT - 1, Float.MAX_EXPONENT + 1,0,Float.MIN_EXPONENT };
-
- /**
- * @tests {@link java.lang.Math#getExponent(float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_getExponent_F() {
- for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) {
- final float number = GETEXPONENT_F_CASES[i];
- final int result = GETEXPONENT_F_RESULTS[i];
- assertEquals("Wrong result of getExponent(float).", result, Math
- .getExponent(number));
- }
- try {
- Math.getExponent((Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.Math#hypot(double, double)
- */
- public void test_hypot_DD() {
- // Test for special cases
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
- 1.0), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
- 123.324), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(-758.2587,
- Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(5687.21,
- Double.NEGATIVE_INFINITY), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.hypot(Double.NEGATIVE_INFINITY,
- Double.POSITIVE_INFINITY), 0D);
- assertTrue("Should be NaN", Double.isNaN(Math.hypot(Double.NaN,
- 2342301.89843)));
- assertTrue("Should be NaN", Double.isNaN(Math.hypot(-345.2680,
- Double.NaN)));
-
- assertEquals("Should return 2396424.905416697", 2396424.905416697, Math
- .hypot(12322.12, -2396393.2258), 0D);
- assertEquals("Should return 138.16958070558556", 138.16958070558556,
- Math.hypot(-138.16951162, 0.13817035864), 0D);
- assertEquals("Should return 1.7976931348623157E308",
- 1.7976931348623157E308, Math.hypot(Double.MAX_VALUE, 211370.35), 0D);
- assertEquals("Should return 5413.7185", 5413.7185, Math.hypot(
- -5413.7185, Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#IEEEremainder(double, double)
- */
- public void test_IEEEremainderDD() {
- // Test for method double java.lang.Math.IEEEremainder(double, double)
- assertEquals("Incorrect remainder returned",
- 0.0, Math.IEEEremainder(1.0, 1.0), 0D);
- assertTrue("Incorrect remainder returned", Math.IEEEremainder(1.32,
- 89.765) >= 1.4705063220631647E-2
- || Math.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
- }
-
- /**
- * @tests java.lang.Math#log(double)
- */
- public void test_logD() {
- // Test for method double java.lang.Math.log(double)
- for (double d = 10; d >= -10; d -= 0.5) {
- double answer = Math.log(Math.exp(d));
- assertTrue("Answer does not equal expected answer for d = " + d
- + " answer = " + answer, Math.abs(answer - d) <= Math
- .abs(d * 0.00000001));
- }
- }
-
- /**
- * @tests java.lang.Math#log10(double)
- */
- @SuppressWarnings("boxing")
- public void test_log10_D() {
- // Test for special cases
- assertTrue(Double.isNaN(Math.log10(Double.NaN)));
- assertTrue(Double.isNaN(Math.log10(-2541.05745687234187532)));
- assertTrue(Double.isNaN(Math.log10(-0.1)));
- assertEquals(Double.POSITIVE_INFINITY, Math.log10(Double.POSITIVE_INFINITY));
- assertEquals(Double.NEGATIVE_INFINITY, Math.log10(0.0));
- assertEquals(Double.NEGATIVE_INFINITY, Math.log10(+0.0));
- assertEquals(Double.NEGATIVE_INFINITY, Math.log10(-0.0));
-
- assertEquals(3.0, Math.log10(1000.0));
- assertEquals(14.0, Math.log10(Math.pow(10, 14)));
- assertEquals(3.7389561269540406, Math.log10(5482.2158));
- assertEquals(14.661551142893833, Math.log10(458723662312872.125782332587));
- assertEquals(-0.9083828622192334, Math.log10(0.12348583358871));
- assertEquals(308.25471555991675, Math.log10(Double.MAX_VALUE));
- assertEquals(-323.3062153431158, Math.log10(Double.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.Math#log1p(double)
- */
- public void test_log1p_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double.isNaN(Math.log1p(Double.NaN)));
- assertTrue("Should return NaN", Double.isNaN(Math.log1p(-32.0482175)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.log1p(Double.POSITIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .log1p(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(Math.log1p(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(Math.log1p(-0.0)));
-
- assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
- Math.log1p(-0.254856327), 0D);
- assertEquals("Should return 7.368050685564151", 7.368050685564151, Math
- .log1p(1583.542), 0D);
- assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
- Math.log1p(0.5894227), 0D);
- assertEquals("Should return 709.782712893384", 709.782712893384, Math
- .log1p(Double.MAX_VALUE), 0D);
- assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, Math
- .log1p(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#max(double, double)
- */
- public void test_maxDD() {
- // Test for method double java.lang.Math.max(double, double)
- assertEquals("Incorrect double max value", 1908897.6000089, Math.max(-1908897.6000089,
- 1908897.6000089), 0D);
- assertEquals("Incorrect double max value",
- 1908897.6000089, Math.max(2.0, 1908897.6000089), 0D);
- assertEquals("Incorrect double max value", -2.0, Math.max(-2.0,
- -1908897.6000089), 0D);
-
- // Compare toString representations here since -0.0 = +0.0, and
- // NaN != NaN and we need to distinguish
- assertEquals("Max failed for NaN",
- Double.toString(Double.NaN), Double.toString(Math.max(Double.NaN, 42.0d)));
- assertEquals("Max failed for NaN",
- Double.toString(Double.NaN), Double.toString(Math.max(42.0d, Double.NaN)));
- assertEquals("Max failed for 0.0",
- Double.toString(+0.0d), Double.toString(Math.max(+0.0d, -0.0d)));
- assertEquals("Max failed for 0.0",
- Double.toString(+0.0d), Double.toString(Math.max(-0.0d, +0.0d)));
- assertEquals("Max failed for -0.0d",
- Double.toString(-0.0d), Double.toString(Math.max(-0.0d, -0.0d)));
- assertEquals("Max failed for 0.0",
- Double.toString(+0.0d), Double.toString(Math.max(+0.0d, +0.0d)));
- }
-
- /**
- * @tests java.lang.Math#max(float, float)
- */
- public void test_maxFF() {
- // Test for method float java.lang.Math.max(float, float)
- assertTrue("Incorrect float max value", Math.max(-1908897.600f,
- 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value",
- Math.max(2.0f, 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value",
- Math.max(-2.0f, -1908897.600f) == -2.0f);
-
- // Compare toString representations here since -0.0 = +0.0, and
- // NaN != NaN and we need to distinguish
- assertEquals("Max failed for NaN",
- Float.toString(Float.NaN), Float.toString(Math.max(Float.NaN, 42.0f)));
- assertEquals("Max failed for NaN",
- Float.toString(Float.NaN), Float.toString(Math.max(42.0f, Float.NaN)));
- assertEquals("Max failed for 0.0",
- Float.toString(+0.0f), Float.toString(Math.max(+0.0f, -0.0f)));
- assertEquals("Max failed for 0.0",
- Float.toString(+0.0f), Float.toString(Math.max(-0.0f, +0.0f)));
- assertEquals("Max failed for -0.0f",
- Float.toString(-0.0f), Float.toString(Math.max(-0.0f, -0.0f)));
- assertEquals("Max failed for 0.0",
- Float.toString(+0.0f), Float.toString(Math.max(+0.0f, +0.0f)));
- }
-
- /**
- * @tests java.lang.Math#max(int, int)
- */
- public void test_maxII() {
- // Test for method int java.lang.Math.max(int, int)
- assertEquals("Incorrect int max value",
- 19088976, Math.max(-19088976, 19088976));
- assertEquals("Incorrect int max value",
- 19088976, Math.max(20, 19088976));
- assertEquals("Incorrect int max value", -20, Math.max(-20, -19088976));
- }
-
- /**
- * @tests java.lang.Math#max(long, long)
- */
- public void test_maxJJ() {
- // Test for method long java.lang.Math.max(long, long)
- assertEquals("Incorrect long max value", 19088976000089L, Math.max(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long max value",
- 19088976000089L, Math.max(20, 19088976000089L));
- assertEquals("Incorrect long max value",
- -20, Math.max(-20, -19088976000089L));
- }
-
- /**
- * @tests java.lang.Math#min(double, double)
- */
- public void test_minDD() {
- // Test for method double java.lang.Math.min(double, double)
- assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-1908897.6000089,
- 1908897.6000089), 0D);
- assertEquals("Incorrect double min value",
- 2.0, Math.min(2.0, 1908897.6000089), 0D);
- assertEquals("Incorrect double min value", -1908897.6000089, Math.min(-2.0,
- -1908897.6000089), 0D);
- assertEquals("Incorrect double min value", 1.0d, Math.min(1.0d, 1.0d));
-
- // Compare toString representations here since -0.0 = +0.0, and
- // NaN != NaN and we need to distinguish
- assertEquals("Min failed for NaN",
- Double.toString(Double.NaN), Double.toString(Math.min(Double.NaN, 42.0d)));
- assertEquals("Min failed for NaN",
- Double.toString(Double.NaN), Double.toString(Math.min(42.0d, Double.NaN)));
- assertEquals("Min failed for -0.0",
- Double.toString(-0.0d), Double.toString(Math.min(+0.0d, -0.0d)));
- assertEquals("Min failed for -0.0",
- Double.toString(-0.0d), Double.toString(Math.min(-0.0d, +0.0d)));
- assertEquals("Min failed for -0.0d",
- Double.toString(-0.0d), Double.toString(Math.min(-0.0d, -0.0d)));
- assertEquals("Min failed for 0.0",
- Double.toString(+0.0d), Double.toString(Math.min(+0.0d, +0.0d)));
- }
-
- /**
- * @tests java.lang.Math#min(float, float)
- */
- public void test_minFF() {
- // Test for method float java.lang.Math.min(float, float)
- assertTrue("Incorrect float min value", Math.min(-1908897.600f,
- 1908897.600f) == -1908897.600f);
- assertTrue("Incorrect float min value",
- Math.min(2.0f, 1908897.600f) == 2.0f);
- assertTrue("Incorrect float min value",
- Math.min(-2.0f, -1908897.600f) == -1908897.600f);
- assertEquals("Incorrect float min value", 1.0f, Math.min(1.0f, 1.0f));
-
- // Compare toString representations here since -0.0 = +0.0, and
- // NaN != NaN and we need to distinguish
- assertEquals("Min failed for NaN",
- Float.toString(Float.NaN), Float.toString(Math.min(Float.NaN, 42.0f)));
- assertEquals("Min failed for NaN",
- Float.toString(Float.NaN), Float.toString(Math.min(42.0f, Float.NaN)));
- assertEquals("Min failed for -0.0",
- Float.toString(-0.0f), Float.toString(Math.min(+0.0f, -0.0f)));
- assertEquals("Min failed for -0.0",
- Float.toString(-0.0f), Float.toString(Math.min(-0.0f, +0.0f)));
- assertEquals("Min failed for -0.0f",
- Float.toString(-0.0f), Float.toString(Math.min(-0.0f, -0.0f)));
- assertEquals("Min failed for 0.0",
- Float.toString(+0.0f), Float.toString(Math.min(+0.0f, +0.0f)));
- }
-
- /**
- * @tests java.lang.Math#min(int, int)
- */
- public void test_minII() {
- // Test for method int java.lang.Math.min(int, int)
- assertEquals("Incorrect int min value",
- -19088976, Math.min(-19088976, 19088976));
- assertEquals("Incorrect int min value", 20, Math.min(20, 19088976));
- assertEquals("Incorrect int min value",
- -19088976, Math.min(-20, -19088976));
-
- }
-
- /**
- * @tests java.lang.Math#min(long, long)
- */
- public void test_minJJ() {
- // Test for method long java.lang.Math.min(long, long)
- assertEquals("Incorrect long min value", -19088976000089L, Math.min(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long min value",
- 20, Math.min(20, 19088976000089L));
- assertEquals("Incorrect long min value",
- -19088976000089L, Math.min(-20, -19088976000089L));
- }
-
- /**
- * start number cases for test_nextAfter_DD in MathTest/StrictMathTest
- * NEXTAFTER_DD_START_CASES[i][0] is the start number
- * NEXTAFTER_DD_START_CASES[i][1] is the nextUp of start number
- * NEXTAFTER_DD_START_CASES[i][2] is the nextDown of start number
- */
- static final double NEXTAFTER_DD_START_CASES[][] = new double[][] {
- { 3.4, 3.4000000000000004, 3.3999999999999995 },
- { -3.4, -3.3999999999999995, -3.4000000000000004 },
- { 3.4233E109, 3.4233000000000005E109, 3.4232999999999996E109 },
- { -3.4233E109, -3.4232999999999996E109, -3.4233000000000005E109 },
- { +0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
- { 0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
- { -0.0, Double.MIN_VALUE, -Double.MIN_VALUE },
- { Double.MIN_VALUE, 1.0E-323, +0.0 },
- { -Double.MIN_VALUE, -0.0, -1.0E-323 },
- { Double.MIN_NORMAL, 2.225073858507202E-308, 2.225073858507201E-308 },
- { -Double.MIN_NORMAL, -2.225073858507201E-308,
- -2.225073858507202E-308 },
- { Double.MAX_VALUE, Double.POSITIVE_INFINITY,
- 1.7976931348623155E308 },
- { -Double.MAX_VALUE, -1.7976931348623155E308,
- Double.NEGATIVE_INFINITY },
- { Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY,
- Double.MAX_VALUE },
- { Double.NEGATIVE_INFINITY, -Double.MAX_VALUE,
- Double.NEGATIVE_INFINITY } };
-
- /**
- * direction number cases for test_nextAfter_DD/test_nextAfter_FD in
- * MathTest/StrictMathTest
- */
- static final double NEXTAFTER_DD_FD_DIRECTION_CASES[] = new double[] {
- Double.POSITIVE_INFINITY, Double.MAX_VALUE, 8.8, 3.4, 1.4,
- Double.MIN_NORMAL, Double.MIN_NORMAL / 2, Double.MIN_VALUE, +0.0,
- 0.0, -0.0, -Double.MIN_VALUE, -Double.MIN_NORMAL / 2,
- -Double.MIN_NORMAL, -1.4, -3.4, -8.8, -Double.MAX_VALUE,
- Double.NEGATIVE_INFINITY };
-
- /**
- * @tests {@link java.lang.Math#nextAfter(double, double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextAfter_DD() {
- // test for most cases without exception
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- final double start = NEXTAFTER_DD_START_CASES[i][0];
- final long nextUpBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
- final long nextDownBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
-
- for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
- final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
- final long resultBits = Double.doubleToLongBits(Math.nextAfter(
- start, direction));
- final long directionBits = Double.doubleToLongBits(direction);
- if (direction > start) {
- assertEquals("Result should be next up-number.",
- nextUpBits, resultBits);
- } else if (direction < start) {
- assertEquals("Result should be next down-number.",
- nextDownBits, resultBits);
- } else {
- assertEquals("Result should be direction.", directionBits,
- resultBits);
- }
- }
- }
-
- // test for cases with NaN
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- assertTrue("The result should be NaN.", Double.isNaN(Math
- .nextAfter(NEXTAFTER_DD_START_CASES[i][0], Double.NaN)));
- }
- for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
- assertTrue("The result should be NaN.", Double.isNaN(Math
- .nextAfter(Double.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
- }
- assertTrue("The result should be NaN.", Double.isNaN(Math.nextAfter(
- Double.NaN, Double.NaN)));
-
- // test for exception
- try {
- Math.nextAfter((Double) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.nextAfter(2.3, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.nextAfter((Double) null, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * start number cases for test_nextAfter_FD in MathTest/StrictMathTest
- * NEXTAFTER_FD_START_CASES[i][0] is the start number
- * NEXTAFTER_FD_START_CASES[i][1] is the nextUp of start number
- * NEXTAFTER_FD_START_CASES[i][2] is the nextDown of start number
- */
- static final float NEXTAFTER_FD_START_CASES[][] = new float[][] {
- { 3.4f, 3.4000003f, 3.3999999f },
- { -3.4f, -3.3999999f, -3.4000003f },
- { 3.4233E19f, 3.4233002E19f, 3.4232998E19f },
- { -3.4233E19f, -3.4232998E19f, -3.4233002E19f },
- { +0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
- { 0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
- { -0.0f, Float.MIN_VALUE, -Float.MIN_VALUE },
- { Float.MIN_VALUE, 2.8E-45f, +0.0f },
- { -Float.MIN_VALUE, -0.0f, -2.8E-45f },
- { Float.MIN_NORMAL, 1.1754945E-38f, 1.1754942E-38f },
- { -Float.MIN_NORMAL, -1.1754942E-38f, -1.1754945E-38f },
- { Float.MAX_VALUE, Float.POSITIVE_INFINITY, 3.4028233E38f },
- { -Float.MAX_VALUE, -3.4028233E38f, Float.NEGATIVE_INFINITY },
- { Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MAX_VALUE },
- { Float.NEGATIVE_INFINITY, -Float.MAX_VALUE,
- Float.NEGATIVE_INFINITY } };
-
- /**
- * @tests {@link java.lang.Math#nextAfter(float, double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextAfter_FD() {
- // test for most cases without exception
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- final float start = NEXTAFTER_FD_START_CASES[i][0];
- final int nextUpBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
- final int nextDownBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
-
- for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
- final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
- final int resultBits = Float.floatToIntBits(Math.nextAfter(
- start, direction));
- if (direction > start) {
- assertEquals("Result should be next up-number.",
- nextUpBits, resultBits);
- } else if (direction < start) {
- assertEquals("Result should be next down-number.",
- nextDownBits, resultBits);
- } else {
- final int equivalentBits = Float.floatToIntBits(new Float(
- direction));
- assertEquals(
- "Result should be a number equivalent to direction.",
- equivalentBits, resultBits);
- }
- }
- }
-
- // test for cases with NaN
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
- NEXTAFTER_FD_START_CASES[i][0], Float.NaN)));
- }
- for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
- assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
- Float.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
- }
- assertTrue("The result should be NaN.", Float.isNaN(Math.nextAfter(
- Float.NaN, Float.NaN)));
-
- // test for exception
- try {
- Math.nextAfter((Float) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.nextAfter(2.3, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.nextAfter((Float) null, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.Math#nextUp(double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextUp_D() {
- // This method is semantically equivalent to nextAfter(d,
- // Double.POSITIVE_INFINITY),
- // so we use the data of test_nextAfter_DD
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- final double start = NEXTAFTER_DD_START_CASES[i][0];
- final long nextUpBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
- final long resultBits = Double.doubleToLongBits(Math.nextUp(start));
- assertEquals("Result should be next up-number.", nextUpBits,
- resultBits);
- }
-
- // test for cases with NaN
- assertTrue("The result should be NaN.", Double.isNaN(Math
- .nextUp(Double.NaN)));
-
- // test for exception
- try {
- Math.nextUp((Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.Math#nextUp(float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextUp_F() {
- // This method is semantically equivalent to nextAfter(f,
- // Float.POSITIVE_INFINITY),
- // so we use the data of test_nextAfter_FD
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- final float start = NEXTAFTER_FD_START_CASES[i][0];
- final int nextUpBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
- final int resultBits = Float.floatToIntBits(Math.nextUp(start));
- assertEquals("Result should be next up-number.", nextUpBits,
- resultBits);
- }
-
- // test for cases with NaN
- assertTrue("The result should be NaN.", Float.isNaN(Math
- .nextUp(Float.NaN)));
-
- // test for exception
- try {
- Math.nextUp((Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.Math#pow(double, double)
- */
- public void test_powDD() {
- // Test for method double java.lang.Math.pow(double, double)
- double NZERO = longTodouble(doubleTolong(0.0) ^ 0x8000000000000000L);
- double p1 = 1.0;
- double p2 = 2.0;
- double p3 = 3.0;
- double p4 = 4.0;
- double p5 = 5.0;
- double p6 = 6.0;
- double p7 = 7.0;
- double p8 = 8.0;
- double p9 = 9.0;
- double p10 = 10.0;
- double p11 = 11.0;
- double p12 = 12.0;
- double p13 = 13.0;
- double p14 = 14.0;
- double p15 = 15.0;
- double p16 = 16.0;
- double[] values = { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12,
- p13, p14, p15, p16 };
-
- for (int x = 0; x < values.length; x++) {
- double dval = values[x];
- double nagateDval = negateDouble(dval);
- if (nagateDval == Double.NaN) {
- continue;
- }
-
- // If the second argument is positive or negative zero, then the
- // result is 1.0.
- assertEquals("Result should be Math.pow(" + dval
- + ",-0.0)=+1.0", 1.0, Math.pow(dval, NZERO));
- assertEquals("Result should be Math.pow(" + nagateDval
- + ",-0.0)=+1.0", 1.0, Math.pow(nagateDval, NZERO));
- assertEquals("Result should be Math.pow(" + dval
- + ",+0.0)=+1.0", 1.0, Math.pow(dval, +0.0));
- assertEquals("Result should be Math.pow(" + nagateDval
- + ",+0.0)=+1.0", 1.0, Math.pow(nagateDval, +0.0));
-
- // If the second argument is 1.0, then the result is the same as the
- // first argument.
- assertEquals("Result should be Math.pow(" + dval + "," + 1.0 + ")="
- + dval, dval, Math.pow(dval, 1.0));
- assertEquals("Result should be Math.pow(" + nagateDval + "," + 1.0
- + ")=" + nagateDval, nagateDval, Math.pow(nagateDval, 1.0));
-
- // If the second argument is NaN, then the result is NaN.
- assertEquals("Result should be Math.pow(" + dval + "," + Double.NaN
- + ")=" + Double.NaN, Double.NaN, Math.pow(dval, Double.NaN));
- assertEquals("Result should be Math.pow(" + nagateDval + ","
- + Double.NaN + ")=" + Double.NaN, Double.NaN, Math.pow(nagateDval,
- Double.NaN));
-
- if (dval > 1) {
- // If the first argument is NaN and the second argument is
- // nonzero,
- // then the result is NaN.
- assertEquals("Result should be Math.pow(" + Double.NaN + ","
- + dval + ")=" + Double.NaN, Double.NaN, Math.pow(Double.NaN, dval));
- assertEquals("Result should be Math.pow(" + Double.NaN + ","
- + nagateDval + ")=" + Double.NaN, Double.NaN, Math.pow(Double.NaN,
- nagateDval));
-
- /*
- * If the first argument is positive zero and the second
- * argument is greater than zero, or the first argument is
- * positive infinity and the second argument is less than zero,
- * then the result is positive zero.
- */
- assertEquals("Result should be Math.pow(" + 0.0 + "," + dval
- + ")=" + 0.0, +0.0, Math.pow(0.0, dval));
- assertEquals("Result should be Math.pow("
- + Double.POSITIVE_INFINITY + "," + nagateDval + ")="
- + 0.0, +0.0, Math.pow(Double.POSITIVE_INFINITY, nagateDval));
-
- /*
- * If the first argument is positive zero and the second
- * argument is less than zero, or the first argument is positive
- * infinity and the second argument is greater than zero, then
- * the result is positive infinity.
- */
- assertEquals("Result should be Math.pow(" + 0.0 + ","
- + nagateDval + ")=" + Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,
- Math.pow(0.0, nagateDval));
- assertEquals("Result should be Math.pow("
- + Double.POSITIVE_INFINITY + "," + dval + ")="
- + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(
- Double.POSITIVE_INFINITY, dval));
-
- // Not a finite odd integer
- if (dval % 2 == 0) {
- /*
- * If the first argument is negative zero and the second
- * argument is greater than zero but not a finite odd
- * integer, or the first argument is negative infinity and
- * the second argument is less than zero but not a finite
- * odd integer, then the result is positive zero.
- */
- assertEquals("Result should be Math.pow(" + NZERO + ","
- + dval + ")=" + 0.0, +0.0, Math.pow(NZERO, dval));
- assertEquals("Result should be Math.pow("
- + Double.NEGATIVE_INFINITY + "," + nagateDval
- + ")=" + 0.0, +0.0, Math.pow(Double.NEGATIVE_INFINITY,
- nagateDval));
-
- /*
- * If the first argument is negative zero and the second
- * argument is less than zero but not a finite odd integer,
- * or the first argument is negative infinity and the second
- * argument is greater than zero but not a finite odd
- * integer, then the result is positive infinity.
- */
- assertEquals("Result should be Math.pow(" + NZERO + ","
- + nagateDval + ")=" + Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,
- Math.pow(NZERO, nagateDval));
- assertEquals("Result should be Math.pow("
- + Double.NEGATIVE_INFINITY + "," + dval + ")="
- + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(
- Double.NEGATIVE_INFINITY, dval));
- }
-
- // finite odd integer
- if (dval % 2 != 0) {
- /*
- * If the first argument is negative zero and the second
- * argument is a positive finite odd integer, or the first
- * argument is negative infinity and the second argument is
- * a negative finite odd integer, then the result is
- * negative zero.
- */
- assertEquals("Result should be Math.pow(" + NZERO + ","
- + dval + ")=" + NZERO, NZERO, Math.pow(NZERO, dval));
- assertEquals("Result should be Math.pow("
- + Double.NEGATIVE_INFINITY + "," + nagateDval
- + ")=" + NZERO, NZERO, Math.pow(Double.NEGATIVE_INFINITY,
- nagateDval));
- /*
- * If the first argument is negative zero and the second
- * argument is a negative finite odd integer, or the first
- * argument is negative infinity and the second argument is
- * a positive finite odd integer then the result is negative
- * infinity.
- */
- assertEquals("Result should be Math.pow(" + NZERO + ","
- + nagateDval + ")=" + Double.NEGATIVE_INFINITY,Double.NEGATIVE_INFINITY,
- Math.pow(NZERO, nagateDval));
- assertEquals("Result should be Math.pow("
- + Double.NEGATIVE_INFINITY + "," + dval + ")="
- + Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Math.pow(
- Double.NEGATIVE_INFINITY, dval));
- }
-
- /**
- * 1. If the first argument is finite and less than zero if the
- * second argument is a finite even integer, the result is equal
- * to the result of raising the absolute value of the first
- * argument to the power of the second argument
- *
- * 2. if the second argument is a finite odd integer, the result is equal to the
- * negative of the result of raising the absolute value of the
- * first argument to the power of the second argument
- *
- * 3. if the second argument is finite and not an integer, then the result
- * is NaN.
- */
- for (int j = 1; j < values.length; j++) {
- double jval = values[j];
- if (jval % 2.0 == 0.0) {
- assertEquals("" + nagateDval + " " + jval, Math.pow(
- dval, jval), Math.pow(nagateDval, jval));
- } else {
- assertEquals("" + nagateDval + " " + jval, -1.0
- * Math.pow(dval, jval), Math.pow(nagateDval,
- jval));
- }
- assertEquals(Double.NaN, Math
- .pow(nagateDval, jval / 0.5467));
- assertEquals(Double.NaN, Math.pow(nagateDval, -1.0 * jval
- / 0.5467));
- }
- }
-
- // If the absolute value of the first argument equals 1 and the
- // second argument is infinite, then the result is NaN.
- if (dval == 1) {
- assertEquals("Result should be Math.pow(" + dval + ","
- + Double.POSITIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
- .pow(dval, Double.POSITIVE_INFINITY));
- assertEquals("Result should be Math.pow(" + dval + ","
- + Double.NEGATIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
- .pow(dval, Double.NEGATIVE_INFINITY));
-
- assertEquals("Result should be Math.pow(" + nagateDval + ","
- + Double.POSITIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
- .pow(nagateDval, Double.POSITIVE_INFINITY));
- assertEquals("Result should be Math.pow(" + nagateDval + ","
- + Double.NEGATIVE_INFINITY + ")=" + Double.NaN, Double.NaN, Math
- .pow(nagateDval, Double.NEGATIVE_INFINITY));
- }
-
- if (dval > 1) {
- /*
- * If the absolute value of the first argument is greater than 1
- * and the second argument is positive infinity, or the absolute
- * value of the first argument is less than 1 and the second
- * argument is negative infinity, then the result is positive
- * infinity.
- */
- assertEquals("Result should be Math.pow(" + dval + ","
- + Double.POSITIVE_INFINITY + ")="
- + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(dval,
- Double.POSITIVE_INFINITY));
-
- assertEquals("Result should be Math.pow(" + nagateDval + ","
- + Double.NEGATIVE_INFINITY + ")="
- + Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Math.pow(-0.13456,
- Double.NEGATIVE_INFINITY));
-
- /*
- * If the absolute value of the first argument is greater than 1
- * and the second argument is negative infinity, or the absolute
- * value of the first argument is less than 1 and the second
- * argument is positive infinity, then the result is positive
- * zero.
- */
- assertEquals("Result should be Math.pow(" + dval + ","
- + Double.NEGATIVE_INFINITY + ")= +0.0", +0.0, Math.pow(dval,
- Double.NEGATIVE_INFINITY));
- assertEquals("Result should be Math.pow(" + nagateDval + ","
- + Double.POSITIVE_INFINITY + ")= +0.0", +0.0, Math.pow(
- -0.13456, Double.POSITIVE_INFINITY));
- }
-
- assertEquals("Result should be Math.pow(" + 0.0 + "," + dval + ")="
- + 0.0, 0.0, Math.pow(0.0, dval));
- assertEquals("Result should be Math.pow(" + Double.NaN + "," + dval
- + ")=" + Double.NaN, Double.NaN, Math.pow(Double.NaN, dval));
- }
- assertTrue("pow returned incorrect value",
- (long) Math.pow(2, 8) == 256l);
- assertTrue("pow returned incorrect value",
- Math.pow(2, -8) == 0.00390625d);
- assertEquals("Incorrect root returned1",
- 2, Math.sqrt(Math.pow(Math.sqrt(2), 4)), 0);
-
- assertEquals(Double.NEGATIVE_INFINITY, Math.pow(-10.0, 3.093403029238847E15));
- assertEquals(Double.POSITIVE_INFINITY, Math.pow(10.0, 3.093403029238847E15));
- }
-
- private double longTodouble(long longvalue) {
- return Double.longBitsToDouble(longvalue);
- }
-
- private long doubleTolong(double doublevalue) {
- return Double.doubleToLongBits(doublevalue);
- }
-
- private double negateDouble(double doublevalue) {
- return doublevalue * -1.0;
- }
-
- /**
- * @tests java.lang.Math#rint(double)
- */
- public void test_rintD() {
- // Test for method double java.lang.Math.rint(double)
- assertEquals("Failed to round properly - up to odd",
- 3.0, Math.rint(2.9), 0D);
- assertTrue("Failed to round properly - NaN", Double.isNaN(Math
- .rint(Double.NaN)));
- assertEquals("Failed to round properly down to even",
- 2.0, Math.rint(2.1), 0D);
- assertTrue("Failed to round properly " + 2.5 + " to even", Math
- .rint(2.5) == 2.0);
- assertTrue("Failed to round properly " + (+0.0d),
- Math.rint(+0.0d) == +0.0d);
- assertTrue("Failed to round properly " + (-0.0d),
- Math.rint(-0.0d) == -0.0d);
- }
-
- /**
- * @tests java.lang.Math#round(double)
- */
- public void test_roundD() {
- // Test for method long java.lang.Math.round(double)
- assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89d));
- }
-
- /**
- * @tests java.lang.Math#round(float)
- */
- public void test_roundF() {
- // Test for method int java.lang.Math.round(float)
- assertEquals("Incorrect rounding of a float", -91, Math.round(-90.89f));
- }
-
- /**
- * @tests {@link java.lang.Math#scalb(double, int)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_scalb_DI() {
- // result is normal
- assertEquals(4.1422946304E7, Math.scalb(1.2345, 25));
- assertEquals(3.679096698760986E-8, Math.scalb(1.2345, -25));
- assertEquals(1.2345, Math.scalb(1.2345, 0));
- assertEquals(7868514.304, Math.scalb(0.2345, 25));
-
- double normal = Math.scalb(0.2345, -25);
- assertEquals(6.98864459991455E-9, normal);
- // precision kept
- assertEquals(0.2345, Math.scalb(normal, 25));
-
- assertEquals(0.2345, Math.scalb(0.2345, 0));
- assertEquals(-4.1422946304E7, Math.scalb(-1.2345, 25));
- assertEquals(-6.98864459991455E-9, Math.scalb(-0.2345, -25));
- assertEquals(2.0, Math.scalb(Double.MIN_NORMAL / 2, 1024));
- assertEquals(64.0, Math.scalb(Double.MIN_VALUE, 1080));
- assertEquals(234, Math.getExponent(Math.scalb(1.0, 234)));
- assertEquals(3.9999999999999996, Math.scalb(Double.MAX_VALUE,
- Double.MIN_EXPONENT));
-
- // result is near infinity
- double halfMax = Math.scalb(1.0, Double.MAX_EXPONENT);
- assertEquals(8.98846567431158E307, halfMax);
- assertEquals(Double.MAX_VALUE, halfMax - Math.ulp(halfMax) + halfMax);
- assertEquals(Double.POSITIVE_INFINITY, halfMax + halfMax);
- assertEquals(1.7976931348623155E308, Math.scalb(1.0 - Math.ulp(1.0),
- Double.MAX_EXPONENT + 1));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(1.0 - Math.ulp(1.0),
- Double.MAX_EXPONENT + 2));
-
- halfMax = Math.scalb(-1.0, Double.MAX_EXPONENT);
- assertEquals(-8.98846567431158E307, halfMax);
- assertEquals(-Double.MAX_VALUE, halfMax + Math.ulp(halfMax) + halfMax);
- assertEquals(Double.NEGATIVE_INFINITY, halfMax + halfMax);
-
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(0.345, 1234));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(44.345E102, 934));
- assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(-44.345E102, 934));
-
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
- Double.MIN_NORMAL / 2, 4000));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(Double.MIN_VALUE,
- 8000));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(Double.MAX_VALUE, 1));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
- Double.POSITIVE_INFINITY, 0));
- assertEquals(Double.POSITIVE_INFINITY, Math.scalb(
- Double.POSITIVE_INFINITY, -1));
- assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(
- Double.NEGATIVE_INFINITY, -1));
- assertEquals(Double.NEGATIVE_INFINITY, Math.scalb(
- Double.NEGATIVE_INFINITY, Double.MIN_EXPONENT));
-
- // result is subnormal/zero
- long posZeroBits = Double.doubleToLongBits(+0.0);
- long negZeroBits = Double.doubleToLongBits(-0.0);
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(+0.0,
- Integer.MAX_VALUE)));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math
- .scalb(+0.0, -123)));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(+0.0, 0)));
- assertEquals(negZeroBits, Double
- .doubleToLongBits(Math.scalb(-0.0, 123)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-0.0,
- Integer.MIN_VALUE)));
-
- assertEquals(Double.MIN_VALUE, Math.scalb(1.0, -1074));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math
- .scalb(1.0, -1075)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-1.0,
- -1075)));
-
- // precision lost
- assertEquals(Math.scalb(21.405, -1078), Math.scalb(21.405, -1079));
- assertEquals(Double.MIN_VALUE, Math.scalb(21.405, -1079));
- assertEquals(-Double.MIN_VALUE, Math.scalb(-21.405, -1079));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(21.405,
- -1080)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(-21.405,
- -1080)));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
- Double.MIN_VALUE, -1)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
- -Double.MIN_VALUE, -1)));
- assertEquals(Double.MIN_VALUE, Math.scalb(Double.MIN_NORMAL, -52));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
- Double.MIN_NORMAL, -53)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
- -Double.MIN_NORMAL, -53)));
- assertEquals(Double.MIN_VALUE, Math.scalb(Double.MAX_VALUE, -2098));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
- Double.MAX_VALUE, -2099)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
- -Double.MAX_VALUE, -2099)));
- assertEquals(Double.MIN_VALUE, Math.scalb(Double.MIN_NORMAL / 3, -51));
- assertEquals(posZeroBits, Double.doubleToLongBits(Math.scalb(
- Double.MIN_NORMAL / 3, -52)));
- assertEquals(negZeroBits, Double.doubleToLongBits(Math.scalb(
- -Double.MIN_NORMAL / 3, -52)));
- double subnormal = Math.scalb(Double.MIN_NORMAL / 3, -25);
- assertEquals(2.2104123E-316, subnormal);
- // precision lost
- assertFalse(Double.MIN_NORMAL / 3 == Math.scalb(subnormal, 25));
-
- // NaN
- assertTrue(Double.isNaN(Math.scalb(Double.NaN, 1)));
- assertTrue(Double.isNaN(Math.scalb(Double.NaN, 0)));
- assertTrue(Double.isNaN(Math.scalb(Double.NaN, -120)));
-
- assertEquals(1283457024, Double.doubleToLongBits(Math.scalb(
- Double.MIN_VALUE * 153, 23)));
- assertEquals(-9223372035571318784L, Double.doubleToLongBits(Math.scalb(
- -Double.MIN_VALUE * 153, 23)));
- assertEquals(36908406321184768L, Double.doubleToLongBits(Math.scalb(
- Double.MIN_VALUE * 153, 52)));
- assertEquals(-9186463630533591040L, Double.doubleToLongBits(Math.scalb(
- -Double.MIN_VALUE * 153, 52)));
-
- // test for exception
- try {
- Math.scalb((Double) null, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.scalb(1.0, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.scalb((Double) null, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- long b1em1022 = 0x0010000000000000L; // bit representation of
- // Double.MIN_NORMAL
- long b1em1023 = 0x0008000000000000L; // bit representation of half of
- // Double.MIN_NORMAL
- // assert exact identity
- assertEquals(b1em1023, Double.doubleToLongBits(Math.scalb(Double
- .longBitsToDouble(b1em1022), -1)));
- }
-
- /**
- * @tests {@link java.lang.Math#scalb(float, int)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_scalb_FI() {
- // result is normal
- assertEquals(4.1422946304E7f, Math.scalb(1.2345f, 25));
- assertEquals(3.679096698760986E-8f, Math.scalb(1.2345f, -25));
- assertEquals(1.2345f, Math.scalb(1.2345f, 0));
- assertEquals(7868514.304f, Math.scalb(0.2345f, 25));
-
- float normal = Math.scalb(0.2345f, -25);
- assertEquals(6.98864459991455E-9f, normal);
- // precision kept
- assertEquals(0.2345f, Math.scalb(normal, 25));
-
- assertEquals(0.2345f, Math.scalb(0.2345f, 0));
- assertEquals(-4.1422946304E7f, Math.scalb(-1.2345f, 25));
- assertEquals(-6.98864459991455E-9f, Math.scalb(-0.2345f, -25));
- assertEquals(2.0f, Math.scalb(Float.MIN_NORMAL / 2, 128));
- assertEquals(64.0f, Math.scalb(Float.MIN_VALUE, 155));
- assertEquals(34, Math.getExponent(Math.scalb(1.0f, 34)));
- assertEquals(3.9999998f, Math
- .scalb(Float.MAX_VALUE, Float.MIN_EXPONENT));
-
- // result is near infinity
- float halfMax = Math.scalb(1.0f, Float.MAX_EXPONENT);
- assertEquals(1.7014118E38f, halfMax);
- assertEquals(Float.MAX_VALUE, halfMax - Math.ulp(halfMax) + halfMax);
- assertEquals(Float.POSITIVE_INFINITY, halfMax + halfMax);
- assertEquals(3.4028233E38f, Math.scalb(1.0f - Math.ulp(1.0f),
- Float.MAX_EXPONENT + 1));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(1.0f - Math.ulp(1.0f),
- Float.MAX_EXPONENT + 2));
-
- halfMax = Math.scalb(-1.0f, Float.MAX_EXPONENT);
- assertEquals(-1.7014118E38f, halfMax);
- assertEquals(-Float.MAX_VALUE, halfMax + Math.ulp(halfMax) + halfMax);
- assertEquals(Float.NEGATIVE_INFINITY, halfMax + halfMax);
-
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(0.345f, 1234));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(44.345E10f, 934));
- assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(-44.345E10f, 934));
-
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MIN_NORMAL / 2,
- 400));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MIN_VALUE, 800));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(Float.MAX_VALUE, 1));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(
- Float.POSITIVE_INFINITY, 0));
- assertEquals(Float.POSITIVE_INFINITY, Math.scalb(
- Float.POSITIVE_INFINITY, -1));
- assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(
- Float.NEGATIVE_INFINITY, -1));
- assertEquals(Float.NEGATIVE_INFINITY, Math.scalb(
- Float.NEGATIVE_INFINITY, Float.MIN_EXPONENT));
-
- // result is subnormal/zero
- int posZeroBits = Float.floatToIntBits(+0.0f);
- int negZeroBits = Float.floatToIntBits(-0.0f);
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f,
- Integer.MAX_VALUE)));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f, -123)));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(+0.0f, 0)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-0.0f, 123)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-0.0f,
- Integer.MIN_VALUE)));
-
- assertEquals(Float.MIN_VALUE, Math.scalb(1.0f, -149));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(1.0f, -150)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-1.0f, -150)));
-
- // precision lost
- assertEquals(Math.scalb(21.405f, -154), Math.scalb(21.405f, -153));
- assertEquals(Float.MIN_VALUE, Math.scalb(21.405f, -154));
- assertEquals(-Float.MIN_VALUE, Math.scalb(-21.405f, -154));
- assertEquals(posZeroBits, Float.floatToIntBits(Math
- .scalb(21.405f, -155)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(-21.405f,
- -155)));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
- Float.MIN_VALUE, -1)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
- -Float.MIN_VALUE, -1)));
- assertEquals(Float.MIN_VALUE, Math.scalb(Float.MIN_NORMAL, -23));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
- Float.MIN_NORMAL, -24)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
- -Float.MIN_NORMAL, -24)));
- assertEquals(Float.MIN_VALUE, Math.scalb(Float.MAX_VALUE, -277));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
- Float.MAX_VALUE, -278)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
- -Float.MAX_VALUE, -278)));
- assertEquals(Float.MIN_VALUE, Math.scalb(Float.MIN_NORMAL / 3, -22));
- assertEquals(posZeroBits, Float.floatToIntBits(Math.scalb(
- Float.MIN_NORMAL / 3, -23)));
- assertEquals(negZeroBits, Float.floatToIntBits(Math.scalb(
- -Float.MIN_NORMAL / 3, -23)));
- float subnormal = Math.scalb(Float.MIN_NORMAL / 3, -11);
- assertEquals(1.913E-42f, subnormal);
- // precision lost
- assertFalse(Float.MIN_NORMAL / 3 == Math.scalb(subnormal, 11));
-
- assertEquals(68747264, Float.floatToIntBits(Math.scalb(
- Float.MIN_VALUE * 153, 23)));
- assertEquals(-2078736384, Float.floatToIntBits(Math.scalb(
- -Float.MIN_VALUE * 153, 23)));
-
- assertEquals(4896, Float.floatToIntBits(Math.scalb(
- Float.MIN_VALUE * 153, 5)));
- assertEquals(-2147478752, Float.floatToIntBits(Math.scalb(
- -Float.MIN_VALUE * 153, 5)));
-
- // NaN
- assertTrue(Float.isNaN(Math.scalb(Float.NaN, 1)));
- assertTrue(Float.isNaN(Math.scalb(Float.NaN, 0)));
- assertTrue(Float.isNaN(Math.scalb(Float.NaN, -120)));
-
- // test for exception
- try {
- Math.scalb((Float) null, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.scalb(1.0f, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- Math.scalb((Float) null, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- int b1em126 = 0x00800000; // bit representation of Float.MIN_NORMAL
- int b1em127 = 0x00400000; // bit representation of half
- // Float.MIN_NORMAL
- // assert exact identity
- assertEquals(b1em127, Float.floatToIntBits(Math.scalb(Float
- .intBitsToFloat(b1em126), -1)));
- }
-
- /**
- * @tests java.lang.Math#signum(double)
- */
- public void test_signum_D() {
- assertTrue(Double.isNaN(Math.signum(Double.NaN)));
- assertTrue(Double.isNaN(Math.signum(Double.NaN)));
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .signum(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(Math.signum(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(Math.signum(-0.0)));
-
- assertEquals(1.0, Math.signum(253681.2187962), 0D);
- assertEquals(-1.0, Math.signum(-125874693.56), 0D);
- assertEquals(1.0, Math.signum(1.2587E-308), 0D);
- assertEquals(-1.0, Math.signum(-1.2587E-308), 0D);
-
- assertEquals(1.0, Math.signum(Double.MAX_VALUE), 0D);
- assertEquals(1.0, Math.signum(Double.MIN_VALUE), 0D);
- assertEquals(-1.0, Math.signum(-Double.MAX_VALUE), 0D);
- assertEquals(-1.0, Math.signum(-Double.MIN_VALUE), 0D);
- assertEquals(1.0, Math.signum(Double.POSITIVE_INFINITY), 0D);
- assertEquals(-1.0, Math.signum(Double.NEGATIVE_INFINITY), 0D);
- }
-
- /**
- * @tests java.lang.Math#signum(float)
- */
- public void test_signum_F() {
- assertTrue(Float.isNaN(Math.signum(Float.NaN)));
- assertEquals(Float.floatToIntBits(0.0f), Float
- .floatToIntBits(Math.signum(0.0f)));
- assertEquals(Float.floatToIntBits(+0.0f), Float
- .floatToIntBits(Math.signum(+0.0f)));
- assertEquals(Float.floatToIntBits(-0.0f), Float
- .floatToIntBits(Math.signum(-0.0f)));
-
- assertEquals(1.0f, Math.signum(253681.2187962f), 0f);
- assertEquals(-1.0f, Math.signum(-125874693.56f), 0f);
- assertEquals(1.0f, Math.signum(1.2587E-11f), 0f);
- assertEquals(-1.0f, Math.signum(-1.2587E-11f), 0f);
-
- assertEquals(1.0f, Math.signum(Float.MAX_VALUE), 0f);
- assertEquals(1.0f, Math.signum(Float.MIN_VALUE), 0f);
- assertEquals(-1.0f, Math.signum(-Float.MAX_VALUE), 0f);
- assertEquals(-1.0f, Math.signum(-Float.MIN_VALUE), 0f);
- assertEquals(1.0f, Math.signum(Float.POSITIVE_INFINITY), 0f);
- assertEquals(-1.0f, Math.signum(Float.NEGATIVE_INFINITY), 0f);
- }
-
- /**
- * @tests java.lang.Math#sin(double)
- */
- public void test_sinD() {
- // Test for method double java.lang.Math.sin(double)
- assertEquals("Incorrect answer", 0.0, Math.sin(0), 0D);
- assertEquals("Incorrect answer", 0.8414709848078965, Math.sin(1), 0D);
- }
-
- /**
- * @tests java.lang.Math#sinh(double)
- */
- public void test_sinh_D() {
- // Test for special situations
- assertTrue("Should return NaN", Double.isNaN(Math.sinh(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.sinh(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, Math.sinh(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .sinh(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(Math.sinh(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(Math.sinh(-0.0)));
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.sinh(1234.56), 0D);
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, Math.sinh(-1234.56), 0D);
- assertEquals("Should return 1.0000000000001666E-6",
- 1.0000000000001666E-6, Math.sinh(0.000001), 0D);
- assertEquals("Should return -1.0000000000001666E-6",
- -1.0000000000001666E-6, Math.sinh(-0.000001), 0D);
- assertEquals("Should return 5.115386441963859", 5.115386441963859, Math
- .sinh(2.33482), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, Math.sinh(Double.MAX_VALUE), 0D);
- assertEquals("Should return 4.9E-324", 4.9E-324, Math
- .sinh(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#sqrt(double)
- */
- public void test_sqrtD() {
- // Test for method double java.lang.Math.sqrt(double)
- assertEquals("Incorrect root returned2", 7, Math.sqrt(49), 0);
- }
-
- /**
- * @tests java.lang.Math#tan(double)
- */
- public void test_tanD() {
- // Test for method double java.lang.Math.tan(double)
- assertEquals("Incorrect answer", 0.0, Math.tan(0), 0D);
- assertEquals("Incorrect answer", 1.5574077246549023, Math.tan(1), 0D);
-
- }
-
- /**
- * @tests java.lang.Math#tanh(double)
- */
- public void test_tanh_D() {
- // Test for special situations
- assertTrue("Should return NaN", Double.isNaN(Math.tanh(Double.NaN)));
- assertEquals("Should return +1.0", +1.0, Math
- .tanh(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return -1.0", -1.0, Math
- .tanh(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double.doubleToLongBits(Math
- .tanh(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(Math.tanh(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(Math.tanh(-0.0)));
-
- assertEquals("Should return 1.0", 1.0, Math.tanh(1234.56), 0D);
- assertEquals("Should return -1.0", -1.0, Math.tanh(-1234.56), 0D);
- assertEquals("Should return 9.999999999996666E-7",
- 9.999999999996666E-7, Math.tanh(0.000001), 0D);
- assertEquals("Should return 0.981422884124941", 0.981422884124941, Math
- .tanh(2.33482), 0D);
- assertEquals("Should return 1.0", 1.0, Math.tanh(Double.MAX_VALUE), 0D);
- assertEquals("Should return 4.9E-324", 4.9E-324, Math
- .tanh(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.Math#random()
- */
- public void test_random() {
- // There isn't a place for these tests so just stick them here
- assertEquals("Wrong value E",
- 4613303445314885481L, Double.doubleToLongBits(Math.E));
- assertEquals("Wrong value PI",
- 4614256656552045848L, Double.doubleToLongBits(Math.PI));
-
- for (int i = 500; i >= 0; i--) {
- double d = Math.random();
- assertTrue("Generated number is out of range: " + d, d >= 0.0
- && d < 1.0);
- }
- }
-
- /**
- * @tests java.lang.Math#toRadians(double)
- */
- public void test_toRadiansD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = Math.toDegrees(Math.toRadians(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * @tests java.lang.Math#toDegrees(double)
- */
- public void test_toDegreesD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = Math.toRadians(Math.toDegrees(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * @tests java.lang.Math#ulp(double)
- */
- @SuppressWarnings("boxing")
- public void test_ulp_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double.isNaN(Math.ulp(Double.NaN)));
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
- .ulp(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, Math
- .ulp(Double.NEGATIVE_INFINITY), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
- .ulp(0.0), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
- .ulp(+0.0), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
- .ulp(-0.0), 0D);
- assertEquals("Returned incorrect value", Math.pow(2, 971), Math
- .ulp(Double.MAX_VALUE), 0D);
- assertEquals("Returned incorrect value", Math.pow(2, 971), Math
- .ulp(-Double.MAX_VALUE), 0D);
-
- assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
- .ulp(Double.MIN_VALUE), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, Math
- .ulp(-Double.MIN_VALUE), 0D);
-
- assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
- .ulp(1.0), 0D);
- assertEquals("Returned incorrect value", 2.220446049250313E-16, Math
- .ulp(-1.0), 0D);
- assertEquals("Returned incorrect value", 2.2737367544323206E-13, Math
- .ulp(1153.0), 0D);
- }
-
- /**
- * @tests java.lang.Math#ulp(float)
- */
- @SuppressWarnings("boxing")
- public void test_ulp_f() {
- // Test for special cases
- assertTrue("Should return NaN", Float.isNaN(Math.ulp(Float.NaN)));
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
- .ulp(Float.POSITIVE_INFINITY), 0f);
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, Math
- .ulp(Float.NEGATIVE_INFINITY), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
- .ulp(0.0f), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
- .ulp(+0.0f), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, Math
- .ulp(-0.0f), 0f);
- assertEquals("Returned incorrect value", 2.028241E31f, Math
- .ulp(Float.MAX_VALUE), 0f);
- assertEquals("Returned incorrect value", 2.028241E31f, Math
- .ulp(-Float.MAX_VALUE), 0f);
-
- assertEquals("Returned incorrect value", 1.4E-45f, Math
- .ulp(Float.MIN_VALUE), 0f);
- assertEquals("Returned incorrect value", 1.4E-45f, Math
- .ulp(-Float.MIN_VALUE), 0f);
-
- assertEquals("Returned incorrect value", 1.1920929E-7f, Math.ulp(1.0f),
- 0f);
- assertEquals("Returned incorrect value", 1.1920929E-7f,
- Math.ulp(-1.0f), 0f);
- assertEquals("Returned incorrect value", 1.2207031E-4f, Math
- .ulp(1153.0f), 0f);
- assertEquals("Returned incorrect value", 5.6E-45f, Math
- .ulp(9.403954E-38f), 0f);
- }
-
- /**
- * @tests {@link java.lang.Math#shiftIntBits(int, int)}
- *
- * @since 1.6
- */
- public void test_shiftIntBits_II() {
- class Tuple {
- public int result;
-
- public int value;
-
- public int factor;
-
- public Tuple(int result, int value, int factor) {
- this.result = result;
- this.value = value;
- this.factor = factor;
- }
- }
- final Tuple[] TUPLES = new Tuple[] {
- // sub-normal to sub-normal
- new Tuple(0x00000000, 0x00000001, -1),
- // round to even
- new Tuple(0x00000002, 0x00000003, -1),
- // round to even
- new Tuple(0x00000001, 0x00000005, -3),
- // round to infinity
- new Tuple(0x00000002, 0x0000000d, -3),
- // round to infinity
-
- // normal to sub-normal
- new Tuple(0x00000002, 0x01a00000, -24),
- // round to even
- new Tuple(0x00000004, 0x01e00000, -24),
- // round to even
- new Tuple(0x00000003, 0x01c80000, -24),
- // round to infinity
- new Tuple(0x00000004, 0x01e80000, -24),
- // round to infinity
- };
- for (int i = 0; i < TUPLES.length; ++i) {
- Tuple tuple = TUPLES[i];
- assertEquals(tuple.result, Float.floatToIntBits(Math.scalb(Float
- .intBitsToFloat(tuple.value), tuple.factor)));
- assertEquals(tuple.result, Float.floatToIntBits(-Math.scalb(-Float
- .intBitsToFloat(tuple.value), tuple.factor)));
- }
- }
-
- /**
- * @tests {@link java.lang.Math#shiftLongBits(long, long)}
- *
- * Round result to nearest value on precision lost.
- *
- * @since 1.6
- */
- public void test_shiftLongBits_LL() {
- class Tuple {
- public long result;
-
- public long value;
-
- public int factor;
-
- public Tuple(long result, long value, int factor) {
- this.result = result;
- this.value = value;
- this.factor = factor;
- }
- }
- final Tuple[] TUPLES = new Tuple[] {
- // sub-normal to sub-normal
- new Tuple(0x00000000L, 0x00000001L, -1),
- //round to even
- new Tuple(0x00000002L, 0x00000003L, -1),
- //round to even
- new Tuple(0x00000001L, 0x00000005L, -3),
- //round to infinity
- new Tuple(0x00000002L, 0x0000000dL, -3),
- //round to infinity
-
- // normal to sub-normal
- new Tuple(0x0000000000000002L, 0x0034000000000000L, -53), // round to even
- new Tuple(0x0000000000000004L, 0x003c000000000000L, -53), // round to even
- new Tuple(0x0000000000000003L, 0x0035000000000000L, -53), // round to infinity
- new Tuple(0x0000000000000004L, 0x003d000000000000L, -53), // round to infinity
- };
- for (int i = 0; i < TUPLES.length; ++i) {
- Tuple tuple = TUPLES[i];
- assertEquals(tuple.result, Double.doubleToLongBits(Math.scalb(
- Double.longBitsToDouble(tuple.value), tuple.factor)));
- assertEquals(tuple.result, Double.doubleToLongBits(-Math.scalb(
- -Double.longBitsToDouble(tuple.value), tuple.factor)));
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum.java
deleted file mode 100644
index 147e7a8..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.Serializable;
-
-class MockEnum implements Serializable {
- private static final long serialVersionUID = -1678507713086705252L;
-
- enum Sample {
- LARRY, MOE, CURLY
- }
-
- enum Sample2 {
- RED, BLUE, YELLO
- }
-
- String str;
-
- int i;
-
- Sample2 samEnum;
-
- Sample larry = Sample.LARRY;
-
- MockEnum() {
- str = "test";
- i = 99;
- samEnum = Sample2.BLUE;
- }
-
- public boolean equals(Object arg0) {
- if (!(arg0 instanceof MockEnum)) {
- return false;
- }
- MockEnum test = (MockEnum) arg0;
- if (str.equals(test.str) && i == test.i && samEnum == test.samEnum) {
- return true;
- }
- return false;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum2.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum2.java
deleted file mode 100644
index cd3a8b7..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockEnum2.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.Serializable;
-
-class MockEnum2 implements Serializable {
-
- private static final long serialVersionUID = -4812214670022262730L;
-
- enum Sample {
- LARRY, MOE, CURLY
- }
-
- enum Sample2 {
- RED, BLUE, YELLO
- }
-
- String str;
-
- int i;
-
- Sample samEnum;
-
- Sample larry = Sample.LARRY;
-
- String myStr = "LARRY";
-
- MockEnum2() {
- str = "test";
- i = 99;
- samEnum = larry;
- }
-
- public boolean equals(Object arg0) {
- if (!(arg0 instanceof MockEnum2)) {
- return false;
- }
- MockEnum2 test = (MockEnum2) arg0;
- if (str.equals(test.str) && i == test.i && samEnum == test.samEnum
- && myStr.equals(test.myStr)) {
- return true;
- }
- return false;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockSecurityManager.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockSecurityManager.java
deleted file mode 100644
index adbbedf..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MockSecurityManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.FilePermission;
-import java.security.Permission;
-import java.security.SecurityPermission;
-import java.util.PropertyPermission;
-
-class MockSecurityManager extends SecurityManager {
-
- String deletedFile = "/";
- String readedFile = "/";
- String writedFile = "/";
-
- public void setInCheck(boolean inCheck) {
- super.inCheck = inCheck;
- }
-
- @Override
- public int classDepth(String name) {
- return super.classDepth(name);
- }
-
- @Override
- public int classLoaderDepth() {
- return super.classLoaderDepth();
- }
-
- @Override
- public void checkPermission(Permission perm) {
- if (perm.equals(new RuntimePermission("createSecurityManager")) ||
-// perm.equals(new AWTPermission("accessEventQueue")) ||
- perm.equals(new RuntimePermission("createClassLoader")) ||
- perm.equals(new FilePermission(deletedFile,"delete")) ||
- perm.equals(new FilePermission(readedFile,"read")) ||
- perm.equals(new PropertyPermission("*", "read,write")) ||
- perm.equals(new PropertyPermission("key", "read")) ||
- perm.equals(new SecurityPermission("getPolicy")) ||
-// perm.equals(new AWTPermission("accessClipboard")) ||
- perm.equals(new FilePermission(writedFile,"write"))) {
- throw
- new SecurityException("Unable to create Security Manager");
- }
- }
-
- @Override
- public ClassLoader currentClassLoader() {
- return super.currentClassLoader();
- }
-
- @Override
- public Class<?> currentLoadedClass() {
- return super.currentLoadedClass();
- }
-
- @Override
- public Class[] getClassContext() {
- return super.getClassContext();
- }
-
- @Override
- public boolean inClass(String name) {
- return super.inClass(name);
- }
-
- @Override
- public boolean inClassLoader() {
- return super.inClassLoader();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
deleted file mode 100644
index 36b8766..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/MutableSecurityManager.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.net.SocketPermission;
-import java.security.Permission;
-import java.security.PermissionCollection;
-import java.security.Permissions;
-
-class MutableSecurityManager extends SecurityManager {
-
- static final RuntimePermission SET_SECURITY_MANAGER = new RuntimePermission("setSecurityManager");
-
- private PermissionCollection enabled;
-
- private PermissionCollection denied;
-
- public boolean isCheckAcceptCalled = false;
- public boolean isCheckAccessThreadCalled = false;
- public boolean isCheckAccessThreadGroupCalled = false;
-
- public MutableSecurityManager() {
- super();
- this.enabled = new Permissions();
- }
-
- public MutableSecurityManager(Permission... permissions) {
- this();
- for (int i = 0; i < permissions.length; i++) {
- this.enabled.add(permissions[i]);
- }
- }
-
- void addPermission(Permission permission) {
- enabled.add(permission);
- }
-
- void clearPermissions() {
- enabled = new Permissions();
- }
-
- void denyPermission(Permission p) {
- if (denied == null) {
- denied = p.newPermissionCollection();
- }
- denied.add(p);
- }
-
- @Override
- public void checkPermission(Permission permission)
- {
- if (permission != null) {
- if (denied != null && denied.implies(permission)){
-
- throw new SecurityException("Denied " + permission);
- }
-
- if (enabled.implies(permission)) {
- return;
- }
- }
-
- super.checkPermission(permission);
- }
-
- @Override
- public void checkPermission(Permission permission, Object context)
- {
- if (permission != null) {
- if (denied != null && denied.implies(permission)){
-
- throw new SecurityException("Denied " + permission);
- }
-
- if (enabled.implies(permission)) {
- return;
- }
- }
-
- super.checkPermission(permission, context);
- }
-
- // @Override
- public void checkAccept(String host, int port) {
- isCheckAcceptCalled = true;
- super.checkAccept(host, port);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NegativeArraySizeExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NegativeArraySizeExceptionTest.java
deleted file mode 100644
index 93b6dbd..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NegativeArraySizeExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NegativeArraySizeExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.NegativeArraySizeException#NegativeArraySizeException()
- */
- public void test_Constructor() {
- NegativeArraySizeException e = new NegativeArraySizeException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NegativeArraySizeException#NegativeArraySizeException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NegativeArraySizeException e = new NegativeArraySizeException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoClassDefFoundErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoClassDefFoundErrorTest.java
deleted file mode 100644
index db7dced..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoClassDefFoundErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NoClassDefFoundErrorTest extends TestCase {
-
- /**
- * @tests java.lang.NoClassDefFoundError#NoClassDefFoundError()
- */
- public void test_Constructor() {
- NoClassDefFoundError e = new NoClassDefFoundError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NoClassDefFoundError#NoClassDefFoundError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NoClassDefFoundError e = new NoClassDefFoundError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldErrorTest.java
deleted file mode 100644
index 88889e5..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NoSuchFieldErrorTest extends TestCase {
-
- /**
- * @tests java.lang.NoSuchFieldError#NoSuchFieldError()
- */
- public void test_Constructor() {
- NoSuchFieldError e = new NoSuchFieldError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NoSuchFieldError#NoSuchFieldError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NoSuchFieldError e = new NoSuchFieldError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldExceptionTest.java
deleted file mode 100644
index 5902d86..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchFieldExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NoSuchFieldExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.NoSuchFieldException#NoSuchFieldException()
- */
- public void test_Constructor() {
- NoSuchFieldException e = new NoSuchFieldException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NoSuchFieldException#NoSuchFieldException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NoSuchFieldException e = new NoSuchFieldException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodErrorTest.java
deleted file mode 100644
index b7e711b..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NoSuchMethodErrorTest extends TestCase {
-
- /**
- * @tests java.lang.NoSuchMethodError#NoSuchMethodError()
- */
- public void test_Constructor() {
- NoSuchMethodError e = new NoSuchMethodError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NoSuchMethodError#NoSuchMethodError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NoSuchMethodError e = new NoSuchMethodError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodExceptionTest.java
deleted file mode 100644
index 68d46a2..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NoSuchMethodExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NoSuchMethodExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.NoSuchMethodException#NoSuchMethodException()
- */
- public void test_Constructor() {
- NoSuchMethodException e = new NoSuchMethodException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NoSuchMethodException#NoSuchMethodException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NoSuchMethodException e = new NoSuchMethodException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NullPointerExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NullPointerExceptionTest.java
deleted file mode 100644
index a3df668..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NullPointerExceptionTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NullPointerExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.NullPointerException#NullPointerException()
- */
- public void test_Constructor() {
- NullPointerException e = new NullPointerException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NullPointerException#NullPointerException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NullPointerException e = new NullPointerException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberFormatExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberFormatExceptionTest.java
deleted file mode 100644
index 3cdf445..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberFormatExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class NumberFormatExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.NumberFormatException#NumberFormatException()
- */
- public void test_Constructor() {
- NumberFormatException e = new NumberFormatException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.NumberFormatException#NumberFormatException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- NumberFormatException e = new NumberFormatException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java
deleted file mode 100644
index 5b7d7f7..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/NumberTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class NumberTest extends junit.framework.TestCase {
-
- /**
- * @tests java.lang.Number#byteValue()
- */
- public void test_byteValue() {
- int number = 1231243;
- assertTrue("Incorrect byte returned for: " + number,
- ((byte) new Integer(number).intValue()) == new Integer(number)
- .byteValue());
- number = 0;
- assertTrue("Incorrect byte returned for: " + number,
- ((byte) new Integer(number).intValue()) == new Integer(number)
- .byteValue());
- number = -1;
- assertTrue("Incorrect byte returned for: " + number,
- ((byte) new Integer(number).intValue()) == new Integer(number)
- .byteValue());
- number = -84109328;
- assertTrue("Incorrect byte returned for: " + number,
- ((byte) new Integer(number).intValue()) == new Integer(number)
- .byteValue());
- }
-
- /**
- * @tests java.lang.Number#shortValue()
- */
- public void test_shortValue() {
- int number = 1231243;
- assertTrue("Incorrect byte returned for: " + number,
- ((short) new Integer(number).intValue()) == new Integer(number)
- .shortValue());
- number = 0;
- assertTrue("Incorrect byte returned for: " + number,
- ((short) new Integer(number).intValue()) == new Integer(number)
- .shortValue());
- number = -1;
- assertTrue("Incorrect byte returned for: " + number,
- ((short) new Integer(number).intValue()) == new Integer(number)
- .shortValue());
- number = -84109328;
- assertTrue("Incorrect byte returned for: " + number,
- ((short) new Integer(number).intValue()) == new Integer(number)
- .shortValue());
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ObjectTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ObjectTest.java
deleted file mode 100644
index 2b3c3f3..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ObjectTest.java
+++ /dev/null
@@ -1,673 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.util.Vector;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.SideEffect;
-
-@TestTargetClass(Object.class)
-public class ObjectTest extends junit.framework.TestCase {
-
- public boolean isCalled = false;
- /**
- * Test objects.
- */
- Object obj1 = new Object();
-
- Object obj2 = new Object();
-
- /**
- * Generic state indicator.
- */
- int status = 0;
-
- int ready = 0;
- TestThread1 thr1;
- TestThread2 thr2;
-
- /**
- * @tests java.lang.Object#Object()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Object",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.lang.Object()
- assertNotNull("Constructor failed !!!", new Object());
- }
-
- /**
- * @tests java.lang.Object#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- // Test for method boolean java.lang.Object.equals(java.lang.Object)
- assertTrue("Same object should be equal", obj1.equals(obj1));
- assertTrue("Different objects should not be equal", !obj1.equals(obj2));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "finalize",
- args = {}
- )
- @SideEffect("Causes OutOfMemoryError to test finalization")
- public void test_finalize() {
- isCalled = false;
- class TestObject extends Object {
-
- Vector<StringBuffer> v = new Vector<StringBuffer>();
- public void add() {
- v.add(new StringBuffer(10000));
- }
-
- protected void finalize() throws Throwable {
- isCalled = true;
- super.finalize();
- }
- }
-
- TestObject to = new TestObject();
-
- try {
- while(true) {
- to.add();
- }
- } catch(OutOfMemoryError oome) {
- //expected
- to = null;
- }
- System.gc();
- System.runFinalization();
- assertTrue(isCalled);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clone",
- args = {}
- )
- public void test_clone() {
- MockCloneableObject mco = new MockCloneableObject();
- try {
- assertFalse(mco.equals(mco.clone()));
- assertEquals(mco.getClass(), mco.clone().getClass());
- } catch(CloneNotSupportedException cnse) {
- fail("CloneNotSupportedException was thrown.");
- }
-
- MockObject mo = new MockObject();
- try {
- mo.clone();
- fail("CloneNotSupportedException was not thrown.");
- } catch(CloneNotSupportedException cnse) {
- //expected
- }
- }
- class MockCloneableObject extends Object implements Cloneable {
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- class MockObject extends Object {
-
- boolean isCalled = false;
-
- public void finalize() throws Throwable {
- super.finalize();
- isCalled = true;
- }
-
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
- }
-
- /**
- * @tests java.lang.Object#getClass()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getClass",
- args = {}
- )
- public void test_getClass() {
- // Test for method java.lang.Class java.lang.Object.getClass()
- String classNames[] = { "java.lang.Object", "java.lang.Throwable",
- "java.lang.StringBuffer" };
- Class<?> classToTest = null;
- Object instanceToTest = null;
-
- status = 0;
- for (int i = 0; i < classNames.length; ++i) {
- try {
- classToTest = Class.forName(classNames[i]);
- instanceToTest = classToTest.newInstance();
- assertTrue("Instance didn't match creator class.",
- instanceToTest.getClass() == classToTest);
- assertTrue("Instance didn't match class with matching name.",
- instanceToTest.getClass() == Class
- .forName(classNames[i]));
- } catch (Exception ex) {
- fail("Unexpected exception : " + ex.getMessage());
- }
- }
- }
-
- /**
- * @tests java.lang.Object#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- // Test for method int java.lang.Object.hashCode()
- assertTrue("Same object should have same hash.",
- obj1.hashCode() == obj1.hashCode());
- assertTrue("Same object should have same hash.",
- obj2.hashCode() == obj2.hashCode());
- }
-
- /**
- * @tests java.lang.Object#notify()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "notify",
- args = {}
- )
- public void test_notify() {
- // Test for method void java.lang.Object.notify()
-
- // Inner class to run test thread.
- class TestThread implements Runnable {
- public void run() {
- synchronized (obj1) {
- try {
- ready += 1;
- obj1.wait();// Wait for ever.
- status += 1;
- } catch (InterruptedException ex) {
- status = -1000;
- }
- }
- }
- }
- ;
-
- // Start of test code.
-
- // Warning:
- // This code relies on each thread getting serviced within
- // 200 mSec of when it is notified. Although this
- // seems reasonable, it could lead to false-failures.
-
- ready = 0;
- status = 0;
- final int readyWaitSecs = 3;
-
- final int threadCount = 20;
- for (int i = 0; i < threadCount; ++i) {
- new Thread(new TestThread()).start();
- }
- synchronized (obj1) {
- try {
-
- // Wait up to readyWaitSeconds for all threads to be waiting on
- // monitor
- for (int i = 0; i < readyWaitSecs; i++) {
- obj1.wait(1000, 0);
- if (ready == threadCount) {
- break;
- }
- }
-
- // Check pre-conditions of testing notifyAll
- assertTrue("Not all launched threads are waiting. (ready = "
- + ready + ")", ready == threadCount);
- assertTrue("Thread woke too early. (status = " + status + ")",
- status == 0);
-
- for (int i = 1; i <= threadCount; ++i) {
- obj1.notify();
- obj1.wait(200, 0);
- assertTrue("Out of sync. (expected " + i + " but got "
- + status + ")", status == i);
- }
-
- } catch (InterruptedException ex) {
- fail(
- "Unexpectedly got an InterruptedException. (status = "
- + status + ")");
- }
- }
-
- try {
- Object obj = new Object();
- obj.notify();
- fail("IllegalMonitorStateException was not thrown.");
- } catch(IllegalMonitorStateException imse) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Object#notifyAll()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "notifyAll",
- args = {}
- )
- public void test_notifyAll() {
- // Test for method void java.lang.Object.notifyAll()
-
- // Inner class to run test thread.
- class TestThread implements Runnable {
- public void run() {
- synchronized (obj1) {
- try {
- ready += 1;
- obj1.wait();// Wait for ever.
- status += 1;
- } catch (InterruptedException ex) {
- status = -1000;
- }
- }
- }
- }
- ;
-
- // Start of test code.
-
- // Warning:
- // This code relies on all threads getting serviced within
- // 5 seconds of when they are notified. Although this
- // seems reasonable, it could lead to false-failures.
-
- status = 0;
- ready = 0;
- final int readyWaitSecs = 3;
- final int threadCount = 20;
- for (int i = 0; i < threadCount; ++i) {
- new Thread(new TestThread()).start();
- }
-
- synchronized (obj1) {
-
- try {
-
- // Wait up to readyWaitSeconds for all threads to be waiting on
- // monitor
- for (int i = 0; i < readyWaitSecs; i++) {
- obj1.wait(1000, 0);
- if (ready == threadCount) {
- break;
- }
- }
-
- // Check pre-conditions of testing notifyAll
- assertTrue("Not all launched threads are waiting. (ready = "
- + ready + ")", ready == threadCount);
- assertTrue("At least one thread woke too early. (status = "
- + status + ")", status == 0);
-
- obj1.notifyAll();
-
- obj1.wait(5000, 0);
-
- assertTrue(
- "At least one thread did not get notified. (status = "
- + status + ")", status == threadCount);
-
- } catch (InterruptedException ex) {
- fail(
- "Unexpectedly got an InterruptedException. (status = "
- + status + ")");
- }
-
- }
-
- try {
- Object obj = new Object();
- obj.notifyAll();
- fail("IllegalMonitorStateException was not thrown.");
- } catch(IllegalMonitorStateException imse) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.Object#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.lang.Object.toString()
- assertNotNull("Object toString returned null.", obj1.toString());
- }
-
- /**
- * @tests java.lang.Object#wait()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wait",
- args = {}
- )
- public void test_wait() {
- // Test for method void java.lang.Object.wait()
-
- // Inner class to run test thread.
- class TestThread implements Runnable {
- public void run() {
- synchronized (obj1) {
- try {
- obj1.wait();// Wait for ever.
- status = 1;
- } catch (InterruptedException ex) {
- status = -1;
- }
- }
- }
- }
-
-
- // Start of test code.
-
- // Warning:
- // This code relies on threads getting serviced within
- // 1 second of when they are notified. Although this
- // seems reasonable, it could lead to false-failures.
-
- status = 0;
- new Thread(new TestThread()).start();
- synchronized (obj1) {
- try {
- obj1.wait(1000, 0);
- assertTrue("Thread woke too early. (status = " + status + ")",
- status == 0);
- obj1.notifyAll();
- obj1.wait(1000, 0);
- assertTrue("Thread did not get notified. (status = " + status
- + ")", status == 1);
- } catch (InterruptedException ex) {
- fail(
- "Unexpectedly got an InterruptedException. (status = "
- + status + ")");
- }
- }
-
- try {
- Object obj = new Object();
- obj.wait();
- fail("IllegalMonitorStateException was not thrown.");
- } catch(IllegalMonitorStateException imse) {
- //expected
- } catch(InterruptedException ex) {
- fail("InterruptedException was thrown.");
- }
-
- try {
- thr1 = new TestThread1(TestThread1.CASE_WAIT);
- thr2 = new TestThread2();
- thr1.start();
- thr2.start();
- thr2.join();
- thr1.join();
- thr1 = null;
- thr2 = null;
- } catch(InterruptedException e) {
- fail("InterruptedException was thrown.");
- }
- assertEquals(3, status);
- }
-
- class TestThread1 extends Thread {
-
- static final int CASE_WAIT = 0;
- static final int CASE_WAIT_LONG = 1;
- static final int CASE_WAIT_LONG_INT = 2;
-
- int testCase = CASE_WAIT;
-
- public TestThread1(int option) {
- testCase = option;
- }
-
- public void run() {
- synchronized (obj1) {
- try {
- switch(testCase) {
- case CASE_WAIT:
- obj1.wait();// Wait for ever.
- break;
- case CASE_WAIT_LONG:
- obj1.wait(5000L);
- break;
- case CASE_WAIT_LONG_INT:
- obj1.wait(10000L, 999999);
- break;
- }
-
- } catch (InterruptedException ex) {
- status = 3;
- }
- }
- }
- }
-
- class TestThread2 extends Thread {
- public void run() {
- thr1.interrupt();
- }
- }
-
- /**
- * @tests java.lang.Object#wait(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wait",
- args = {long.class}
- )
- public void test_waitJ() {
- // Test for method void java.lang.Object.wait(long)
-
- // Start of test code.
-
- final int loopCount = 20;
- final int allowableError = 100; // millesconds
- final int delay = 200; // milliseconds
- synchronized (obj1) {
- try {
- int count = 0;
- long[][] toLong = new long[3][3];
- for (int i = 0; i < loopCount; ++i) {
- long before = System.currentTimeMillis();
- obj1.wait(delay, 0);
- long after = System.currentTimeMillis();
- long error = (after - before - delay);
- if (error < 0)
- error = -error;
- if (i > 0 && error > allowableError) {
- // Allow jit to warm up before testing
- if (count < toLong.length) {
- toLong[count][0] = i;
- toLong[count][1] = before;
- toLong[count][2] = after;
- count++;
- }
- if (error > (1000 + delay) || count == toLong.length) {
- StringBuffer sb = new StringBuffer();
- for (int j = 0; j < count; j++) {
- sb
- .append("wakeup time too inaccurate, iteration ");
- sb.append(toLong[j][0]);
- sb.append(", before: ");
- sb.append(toLong[j][1]);
- sb.append(" after: ");
- sb.append(toLong[j][2]);
- sb.append(" diff: ");
- sb.append(toLong[j][2] - toLong[j][1]);
- sb.append("\n");
- }
- fail(sb.toString());
- }
- }
- }
- } catch (InterruptedException ex) {
- fail(
- "Unexpectedly got an InterruptedException. (status = "
- + status + ")");
- }
- }
-
- try {
- Object obj = new Object();
- obj.wait(5000L);
- fail("IllegalMonitorStateException was not thrown.");
- } catch(IllegalMonitorStateException imse) {
- //expected
- } catch(InterruptedException ex) {
- fail("InterruptedException was thrown.");
- }
-
- try {
- thr1 = new TestThread1(TestThread1.CASE_WAIT_LONG);
- thr2 = new TestThread2();
- thr1.start();
- thr2.start();
- thr2.join();
- thr1.join();
- thr1 = null;
- thr2 = null;
- } catch(InterruptedException e) {
- fail("InterruptedException was thrown.");
- }
- assertEquals(3, status);
- }
-
- /**
- * @tests java.lang.Object#wait(long, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wait",
- args = {long.class, int.class}
- )
- public void test_waitJI() {
- // Test for method void java.lang.Object.wait(long, int)
-
- // Inner class to run test thread.
- class TestThread implements Runnable {
- public void run() {
- synchronized (obj1) {
- try {
- obj1.wait(0, 1); // Don't wait very long.
- status = 1;
- obj1.wait(0, 0); // Wait for ever.
- status = 2;
- } catch (InterruptedException ex) {
- status = -1;
- }
- }
- }
- }
-
-
- // Start of test code.
-
- // Warning:
- // This code relies on threads getting serviced within
- // 1 second of when they are notified. Although this
- // seems reasonable, it could lead to false-failures.
-
- status = 0;
- new Thread(new TestThread()).start();
- synchronized (obj1) {
- try {
- obj1.wait(1000, 0);
- assertTrue("Thread did not wake after 1 ms. (status = "
- + status + ")", status == 1);
- obj1.notifyAll();
- obj1.wait(1000, 0);
- assertTrue("Thread did not get notified. (status = " + status
- + ")", status == 2);
- } catch (InterruptedException ex) {
- fail(
- "Unexpectedly got an InterruptedException. (status = "
- + status + ")");
- }
- }
-
- try {
- Object obj = new Object();
- obj.wait(5000L, 1);
- fail("IllegalMonitorStateException was not thrown.");
- } catch(IllegalMonitorStateException imse) {
- //expected
- } catch(InterruptedException ex) {
- fail("InterruptedException was thrown.");
- }
-
- try {
- thr1 = new TestThread1(TestThread1.CASE_WAIT_LONG_INT);
- thr2 = new TestThread2();
- thr1.start();
- thr2.start();
- thr2.join();
- thr1.join();
- thr1 = null;
- thr2 = null;
- } catch(InterruptedException e) {
- fail("InterruptedException was thrown.");
- }
- assertEquals(3, status);
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OldCharacterTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OldCharacterTest.java
deleted file mode 100644
index 73e0405..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OldCharacterTest.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class OldCharacterTest extends TestCase {
-
-
- public void test_codePointCountLjava_lang_CharArrayII() {
-
- assertEquals(1, Character.codePointCount("\uD800\uDC00".toCharArray(),
- 0, 2));
- assertEquals(3, Character.codePointCount("a\uD800\uDC00b".toCharArray(),
- 0, 4));
- assertEquals(4, Character.codePointCount("a\uD800\uDC00b\uD800".toCharArray(),
- 0, 5));
- assertEquals(4, Character.codePointCount("ab\uD800\uDC00b\uD800".toCharArray(),
- 1, 5));
-
- try {
- Character.codePointCount((char[]) null, 0, 1);
- fail("No NPE, null char sequence.");
- } catch (NullPointerException e) {
- }
-
- try {
- Character.codePointCount("abc".toCharArray(), -1, 1);
- fail("No IOOBE, negative start.");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- Character.codePointCount("abc".toCharArray(), 0, 4);
- fail("No IOOBE, end greater than length.");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- Character.codePointCount("abc".toCharArray(), 1, 3);
- fail("No IOOBE, end greater than start.");
- } catch (IndexOutOfBoundsException e) {
- }
- }
-
- public void test_getDirectionality() throws Exception {
-
- byte[] directionalities = {
- // BEGIN android-changed
- // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
- Character.DIRECTIONALITY_LEFT_TO_RIGHT,
- // END android-changed.
-
- Character.DIRECTIONALITY_LEFT_TO_RIGHT,
- Character.DIRECTIONALITY_RIGHT_TO_LEFT,
-
- // BEGIN android-changed
- // Unicode standard 5.1 changed category of unicode point 0x0600 from AL to AN
- Character.DIRECTIONALITY_ARABIC_NUMBER,
- // END android-changed.
-
- Character.DIRECTIONALITY_EUROPEAN_NUMBER,
- // Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR,
- Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR,
- Character.DIRECTIONALITY_ARABIC_NUMBER,
- Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR,
- Character.DIRECTIONALITY_NONSPACING_MARK,
- Character.DIRECTIONALITY_BOUNDARY_NEUTRAL,
- Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR,
- Character.DIRECTIONALITY_SEGMENT_SEPARATOR,
- Character.DIRECTIONALITY_WHITESPACE,
- Character.DIRECTIONALITY_OTHER_NEUTRALS,
- Character.DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING,
- Character.DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE,
- Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING,
- Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE,
- Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT
- };
-
- char[] characters = {
- // BEGIN android-changed
- // Unicode 5.1 defines U+0370 to be Greek capital letter Heta.
- '\u0370', // 1
- // END android-changed
- '\u00B5', // 0
- '\u05BE', // 1
- // BEGIN android-changed
- '\u0600', // 6
- // END android-changed
- '\u00B2', // 3
- // '', // No common char in this group on android and java.
- '\u00B1', // 5
- '\u0660', // 6
- '\u00A0', // 7
- '\u0300', // 8
- '\u009F', // 9
- '\u0085', // 10
- '\u001F', // 11
- '\u0020', // 12
- '\u00AB', // 13
- '\u202A', // 14
- '\u202D', // 15
- '\u202B', // 16
- '\u202E', // 17
- '\u202C' // 18
- };
-
- for(int i = 0; i < directionalities.length; i++) {
- assertEquals(directionalities[i],
- Character.getDirectionality(characters[i]));
- }
-
-
- }
-
- public void test_digitCI() {
- assertEquals(-1, Character.digit('\uFFFF', 1));
- }
-
- public void test_isUpperCaseC() {
- assertFalse("Incorrect case value", Character.isUpperCase('1'));
- assertFalse("Incorrect case value", Character.isUpperCase('?'));
- }
-
- public void test_toLowerCaseC() {
- assertEquals("Failed to change case", 't', Character.toLowerCase('t'));
- assertEquals("Failed to change case", '1', Character.toLowerCase('1'));
- }
-
- public void test_toString() {
- assertEquals("Incorrect String returned", "T", new Character('T').toString());
- assertEquals("Incorrect String returned", "1", new Character('1').toString());
- assertEquals("Incorrect String returned", "$", new Character('$').toString());
- }
-
- public void test_toString_char() {
- assertEquals("Incorrect String returned", "T", Character.toString('T'));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OutOfMemoryErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OutOfMemoryErrorTest.java
deleted file mode 100644
index 72b6d3d..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/OutOfMemoryErrorTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class OutOfMemoryErrorTest extends junit.framework.TestCase {
-
- /**
- * @tests java.lang.OutOfMemoryError#OutOfMemoryError()
- */
- public void test_Constructor() {
- // Test for method java.lang.OutOfMemoryError()
- Error e = new OutOfMemoryError();
- assertNull(e.getCause());
- assertNull(e.getMessage());
- }
-
- /**
- * @tests java.lang.OutOfMemoryError#OutOfMemoryError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.OutOfMemoryError(java.lang.String)
- Error e = new OutOfMemoryError(null);
- assertNull(e.getMessage());
- assertNull(e.getCause());
-
- e= new OutOfMemoryError("msg");
- assertEquals("msg", e.getMessage());
- assertNull(e.getCause());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicClassLoader.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicClassLoader.java
deleted file mode 100644
index 6735f1e..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicClassLoader.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
- class PublicClassLoader extends ClassLoader {
-
- public PublicClassLoader() {
- super();
- }
-
- public PublicClassLoader(ClassLoader cl) {
- super(cl);
- }
-
- private byte[] getBytes( String filename ) throws IOException {
-
- File file = new File( filename );
- long len = file.length();
- byte raw[] = new byte[(int)len];
- FileInputStream fin = new FileInputStream( file );
- int r = fin.read( raw );
- if (r != len)
- throw new IOException( "Can't read all, "+r+" != "+len );
- fin.close();
- return raw;
- }
-
- public Class<?> loadClass(String name, boolean resolve)
- throws ClassNotFoundException {
-
- Class clazz = findLoadedClass(name);
- String classFileName = name.replace( '.', '/' ) + ".class";
- File classFile = new File(classFileName);
- if (classFile.exists()) {
- try {
- byte raw[] = getBytes(classFileName);
- clazz = defineClass( name, raw, 0, raw.length );
- } catch(Exception ioe) {}
- }
-
- if (clazz == null) {
- Package p = getClass().getPackage();
- InputStream is = getResourceAsStream("/" + classFileName);
- byte[] buf = new byte[512];
- int len;
- try {
- len = is.read(buf);
- clazz = defineClass(name, buf, 0, len);
- } catch (IOException e) {
- }
- }
-
- if (clazz == null) {
- clazz = findSystemClass(name);
- }
-
- if(clazz == null)
- throw new ClassNotFoundException(name);
- return clazz;
- }
-
- public Class<?> defineClassTest(byte[] b, int off, int len) {
- return defineClass(b, off, len);
- }
-
- public Package getPackage(String name) {
- return super.getPackage(name);
- }
-
- public Package [] getPackages() {
- return super.getPackages();
- }
-
- public InputStream getResourceAsStream(String name) {
- return getClass().getResourceAsStream("/" + getClass().getPackage().
- getName().replace(".", "/") + "/" + name);
- }
- }
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicTestClass.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicTestClass.java
deleted file mode 100644
index a377dbc..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/PublicTestClass.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.Serializable;
-
-interface TestInterface {
-
- public static int TEST_INTERFACE_FIELD = 0;
-
- int getCount();
- void setCount(int value);
-}
-
-@TestAnnotation("org.apache.harmony.luni.tests.java.lang.PublicTestClass")
-public class PublicTestClass implements TestInterface, Serializable, Cloneable {
-
- private static final long serialVersionUID = 1L;
-
- public static String TEST_FIELD = "test field";
-
- Object clazz;
-
- public PublicTestClass() {
- class LocalClass { }
-
- clazz = new LocalClass();
- }
-
- public Object getLocalClass() {
- class LocalClass {}
- Object returnedObject = new LocalClass();
- return returnedObject;
- }
-
- int count = 0;
-
- public int getCount() {
- return count;
- }
-
- public void setCount(int value) {
- count = value;
- }
-
- private class PrivateClass1 {
-
- public String toString() {
- return "PrivateClass0";
- }
- }
-
- public class PrivateClass2 {
-
- public String toString() {
- return "PrivateClass1";
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeExceptionTest.java
deleted file mode 100644
index 94e01ed..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeExceptionTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(RuntimeException.class)
-public class RuntimeExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.RuntimeException#RuntimeException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "RuntimeException",
- args = {}
- )
- public void test_Constructor() {
- RuntimeException e = new RuntimeException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.RuntimeException#RuntimeException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "RuntimeException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- RuntimeException e = new RuntimeException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "RuntimeException",
- args = {java.lang.String.class, java.lang.Throwable.class}
- )
- public void test_ConstructorLStringLThrowable() {
- String message = "Test message";
- NullPointerException npe = new NullPointerException();
- RuntimeException re = new RuntimeException(message, npe);
- assertEquals(message, re.getMessage());
- assertEquals(npe, re.getCause());
-
- re = new RuntimeException(null, npe);
- assertNull(re.getMessage());
-
- re = new RuntimeException(message, null);
- assertNull(re.getCause());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "RuntimeException",
- args = {java.lang.Throwable.class}
- )
- public void test_ConstructorLThrowable() {
- NullPointerException npe = new NullPointerException();
- RuntimeException re = new RuntimeException(npe);
- assertEquals(npe, re.getCause());
-
- re = new RuntimeException((Throwable) null);
- assertNull(re.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java
deleted file mode 100644
index 1d62ad9..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimePermissionTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class RuntimePermissionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.RuntimePermission(java.lang.String)
- RuntimePermission r = new RuntimePermission("createClassLoader");
- assertEquals("Returned incorrect name",
- "createClassLoader", r.getName());
-
- }
-
- /**
- * @tests java.lang.RuntimePermission#RuntimePermission(java.lang.String,
- * java.lang.String)
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.lang.RuntimePermission(java.lang.String,
- // java.lang.String)
- RuntimePermission r = new RuntimePermission("createClassLoader", null);
- assertEquals("Returned incorrect name",
- "createClassLoader", r.getName());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeTest.java
deleted file mode 100644
index 339d76c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/RuntimeTest.java
+++ /dev/null
@@ -1,830 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.security.Permission;
-import java.util.Arrays;
-import java.util.Vector;
-
-import tests.support.resource.Support_Resources;
-
-@TestTargetClass(Runtime.class)
-public class RuntimeTest extends junit.framework.TestCase {
-
- Runtime r = Runtime.getRuntime();
-
- InputStream is;
-
- String s;
-
- static boolean flag = false;
-
- static boolean ranFinalize = false;
-
- int statusCode = -1;
-
- class HasFinalizer {
- String internalString;
-
- HasFinalizer(String s) {
- internalString = s;
- }
-
- @Override
- protected void finalize() {
- internalString = "hit";
- }
- }
-
- @Override
- protected void finalize() {
- if (flag)
- ranFinalize = true;
- }
-
- protected RuntimeTest createInstance() {
- return new RuntimeTest("FT");
- }
-
- @Override protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * @tests java.lang.Runtime#exec(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- notes = "",
- method = "exec",
- args = {java.lang.String.class}
- )
- public void test_exec() {
- /* successful exec's are tested by java.lang.Process */
- try {
- Runtime.getRuntime().exec("AnInexistentProgram");
- fail("failed to throw IOException when exec'ed inexistent program");
- } catch (IOException e) { /* expected */ }
- }
-
- /**
- * @tests java.lang.Runtime#freeMemory()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "freeMemory",
- args = {}
- )
- public void test_freeMemory() {
- // Heap might grow or do GC at any time,
- // so we can't really test a lot. Hence
- // we are just doing some basic sanity
- // checks here.
- assertTrue("must have some free memory",
- r.freeMemory() > 0);
-
- assertTrue("must not exceed total memory",
- r.freeMemory() < r.totalMemory());
-
- long before = r.totalMemory() - r.freeMemory();
- Vector<byte[]> v = new Vector<byte[]>();
- for (int i = 1; i < 10; i++) {
- v.addElement(new byte[10000]);
- }
- long after = r.totalMemory() - r.freeMemory();
-
- assertTrue("free memory must change with allocations",
- after != before);
- }
-
- /**
- * @tests java.lang.Runtime#gc()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "gc",
- args = {}
- )
- public void test_gc() {
- // Test for method void java.lang.Runtime.gc()
- try {
- r.gc(); // ensure all garbage objects have been collected
- r.gc(); // two GCs force collection phase to complete
- long firstRead = r.totalMemory() - r.freeMemory();
- Vector<StringBuffer> v = new Vector<StringBuffer>();
- for (int i = 1; i < 10; i++)
- v.addElement(new StringBuffer(10000));
- long secondRead = r.totalMemory() - r.freeMemory();
- v = null;
- r.gc();
- r.gc();
- assertTrue("object memory did not grow", secondRead > firstRead);
- assertTrue("space was not reclaimed", (r.totalMemory() - r
- .freeMemory()) < secondRead);
- } catch (Throwable t) {
- System.out.println("Out of memory during gc test");
- r.gc();
- r.gc();
- }
- }
-
- /**
- * @tests java.lang.Runtime#getRuntime()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "getRuntime method is verified in initial setup for other tests.",
- method = "getRuntime",
- args = {}
- )
- public void test_getRuntime() {
- // Test for method java.lang.Runtime java.lang.Runtime.getRuntime()
- assertNotNull(Runtime.getRuntime());
- }
-
- /**
- * @tests java.lang.Runtime#runFinalization()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "runFinalization",
- args = {}
- )
- public void test_runFinalization() {
- // Test for method void java.lang.Runtime.runFinalization()
-
- flag = true;
- createInstance();
- int count = 10;
- // the gc below likely bogosifies the test, but will have to do for
- // the moment
- while (!ranFinalize && count-- > 0) {
- r.gc();
- r.runFinalization();
- }
- assertTrue("Failed to run finalization", ranFinalize);
- }
-
- /**
- * @tests java.lang.Runtime#totalMemory()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "totalMemory",
- args = {}
- )
- public void test_totalMemory() {
- // Test for method long java.lang.Runtime.totalMemory()
- assertTrue("totalMemory returned nonsense value", r.totalMemory() >= r
- .freeMemory());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "addShutdownHook",
- args = {java.lang.Thread.class}
- )
- public void test_addShutdownHook() {
- Thread thrException = new Thread () {
- public void run() {
- try {
- Runtime.getRuntime().addShutdownHook(this);
- fail("IllegalStateException was not thrown.");
- } catch(IllegalStateException ise) {
- //expected
- }
- }
- };
-
- try {
- Runtime.getRuntime().addShutdownHook(thrException);
- } catch (Throwable t) {
- fail(t.getMessage());
- }
-
- try {
- Runtime.getRuntime().addShutdownHook(thrException);
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- // expected
- }
-
- SecurityManager sm = new SecurityManager() {
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals("shutdownHooks")) {
- throw new SecurityException();
- }
- }
- };
-
- // remove previously added hook so we're not depending on the priority
- // of the Exceptions to be thrown.
- Runtime.getRuntime().removeShutdownHook(thrException);
-
- try {
- Thread.currentThread().sleep(1000);
- } catch (InterruptedException ie) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "availableProcessors",
- args = {}
- )
- public void test_availableProcessors() {
- assertTrue(Runtime.getRuntime().availableProcessors() > 0);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String.class, java.lang.String[].class}
- )
- public void test_execLjava_lang_StringLjava_lang_StringArray() {
-
- String [] envp = getEnv();
-
- checkExec(0, envp, null);
- checkExec(0, null, null);
-
- try {
- Runtime.getRuntime().exec((String)null, null);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- SecurityManager sm = new SecurityManager() {
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals("checkExec")) {
- throw new SecurityException();
- }
- }
-
- public void checkExec(String cmd) {
- throw new SecurityException();
- }
- };
-
- try {
- Runtime.getRuntime().exec("", envp);
- fail("IllegalArgumentException should be thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String[].class, java.lang.String[].class}
- )
- public void test_execLjava_lang_StringArrayLjava_lang_StringArray() {
- String [] envp = getEnv();
-
- checkExec(4, envp, null);
- checkExec(4, null, null);
-
- try {
- Runtime.getRuntime().exec((String[])null, null);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{"ls", null}, null);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- SecurityManager sm = new SecurityManager() {
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals("checkExec")) {
- throw new SecurityException();
- }
- }
-
- public void checkExec(String cmd) {
- throw new SecurityException();
- }
- };
-
- try {
- Runtime.getRuntime().exec(new String[]{}, envp);
- fail("IndexOutOfBoundsException should be thrown.");
- } catch(IndexOutOfBoundsException ioob) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{""}, envp);
- fail("IOException should be thrown.");
- } catch (IOException e) { /* expected */ }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String.class, java.lang.String[].class, java.io.File.class}
- )
- public void test_execLjava_lang_StringLjava_lang_StringArrayLjava_io_File() {
-
- String [] envp = getEnv();
-
- File workFolder = Support_Resources.createTempFolder();
-
- checkExec(2, envp, workFolder);
- checkExec(2, null, null);
-
- try {
- Runtime.getRuntime().exec((String)null, null, workFolder);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- SecurityManager sm = new SecurityManager() {
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals("checkExec")) {
- throw new SecurityException();
- }
- }
-
- public void checkExec(String cmd) {
- throw new SecurityException();
- }
- };
-
- try {
- Runtime.getRuntime().exec("", envp, workFolder);
- fail("SecurityException should be thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String[].class, java.lang.String[].class, java.io.File.class}
- )
- public void test_execLjava_lang_StringArrayLjava_lang_StringArrayLjava_io_File() {
- String [] envp = getEnv();
-
- File workFolder = Support_Resources.createTempFolder();
-
- checkExec(5, envp, workFolder);
- checkExec(5, null, null);
-
- try {
- Runtime.getRuntime().exec((String[])null, null, workFolder);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{"ls", null}, null, workFolder);
- fail("NullPointerException should be thrown.");
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- SecurityManager sm = new SecurityManager() {
-
- public void checkPermission(Permission perm) {
- if (perm.getName().equals("checkExec")) {
- throw new SecurityException();
- }
- }
-
- public void checkExec(String cmd) {
- throw new SecurityException();
- }
- };
-
- try {
- Runtime.getRuntime().exec(new String[]{""}, envp, workFolder);
- fail("IOException should be thrown.");
- } catch (IOException e) {
- //expected
- }
- }
-
- String [] getEnv() {
- Object [] valueSet = System.getenv().values().toArray();
- Object [] keySet = System.getenv().keySet().toArray();
- String [] envp = new String[valueSet.length];
- for(int i = 0; i < envp.length; i++) {
- envp[i] = keySet[i] + "=" + valueSet[i];
- }
- return envp;
- }
-
- void checkExec(int testCase, String [] envp, File file) {
- String dirName = "Test_Directory";
- String dirParentName = "Parent_Directory";
- File resources = Support_Resources.createTempFolder();
- String folder = resources.getAbsolutePath() + "/" + dirName;
- String folderWithParent = resources.getAbsolutePath() + "/" +
- dirParentName + "/" + dirName;
- String command = "mkdir " + folder;
- String [] commandArguments = {"mkdir", folder};
- try {
- Process proc = null;
- switch(testCase) {
- case 0:
- proc = Runtime.getRuntime().exec(command, envp);
- break;
- case 1:
- proc = Runtime.getRuntime().exec(command);
- break;
- case 2:
- proc = Runtime.getRuntime().exec(command, envp, file);
- break;
- case 3:
- proc = Runtime.getRuntime().exec(commandArguments);
- break;
- case 4:
- proc = Runtime.getRuntime().exec(commandArguments, envp);
- break;
- case 5:
- proc = Runtime.getRuntime().exec(commandArguments, envp, file);
- break;
- }
- assertNotNull(proc);
- try {
- Thread.sleep(3000);
- } catch(InterruptedException ie) {
- fail("InterruptedException was thrown.");
- }
- File f = new File(folder);
- assertTrue(f.exists());
- if(f.exists()) {
- f.delete();
- }
- } catch(IOException io) {
- fail("IOException was thrown.");
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String.class}
- )
- public void test_execLjava_lang_String() {
- checkExec(1, null, null);
-
- try {
- Runtime.getRuntime().exec((String) null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
-
- try {
- Runtime.getRuntime().exec("");
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "exec",
- args = {java.lang.String[].class}
- )
- public void test_execLjava_lang_StringArray() {
-
- checkExec(3, null, null);
-
- try {
- Runtime.getRuntime().exec((String[]) null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{"ls", null});
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{});
- fail("IndexOutOfBoundsException was not thrown.");
- } catch(IndexOutOfBoundsException iobe) {
- //expected
- } catch (IOException e) {
- fail("IOException was thrown.");
- }
-
- try {
- Runtime.getRuntime().exec(new String[]{""});
- fail("IOException should be thrown.");
- } catch (IOException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "runFinalizersOnExit",
- args = {boolean.class}
- )
- public void test_runFinalizersOnExit() {
- Runtime.getRuntime().runFinalizersOnExit(true);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "removeShutdownHook",
- args = {java.lang.Thread.class}
- )
- public void test_removeShutdownHookLjava_lang_Thread() {
- Thread thr1 = new Thread () {
- public void run() {
- try {
- Runtime.getRuntime().addShutdownHook(this);
- } catch(IllegalStateException ise) {
- fail("IllegalStateException shouldn't be thrown.");
- }
- }
- };
-
- try {
- Runtime.getRuntime().addShutdownHook(thr1);
- Runtime.getRuntime().removeShutdownHook(thr1);
- } catch (Throwable t) {
- fail(t.getMessage());
- }
-
- Thread thr2 = new Thread () {
- public void run() {
- try {
- Runtime.getRuntime().removeShutdownHook(this);
- fail("IllegalStateException wasn't thrown.");
- } catch(IllegalStateException ise) {
- //expected
- }
- }
- };
-
- try {
- Runtime.getRuntime().addShutdownHook(thr2);
- } catch (Throwable t) {
- fail(t.getMessage());
- }
-
- try {
- Thread.currentThread().sleep(1000);
- } catch (InterruptedException ie) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "maxMemory",
- args = {}
- )
- public void test_maxMemory() {
- assertTrue(Runtime.getRuntime().maxMemory() < Long.MAX_VALUE);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "traceInstructions",
- args = {boolean.class}
- )
- public void test_traceInstructions() {
- Runtime.getRuntime().traceInstructions(false);
- Runtime.getRuntime().traceInstructions(true);
- Runtime.getRuntime().traceInstructions(false);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "traceMethodCalls",
- args = {boolean.class}
- )
- @KnownFailure("Fails in CTS but passes under run-core-tests")
- public void test_traceMethodCalls() {
- try {
- Runtime.getRuntime().traceMethodCalls(false);
- Runtime.getRuntime().traceMethodCalls(true);
- Runtime.getRuntime().traceMethodCalls(false);
- } catch (RuntimeException ex) {
- // Slightly ugly: we default to the SD card, which may or may not
- // be there. So we also accept the error case as a success, since
- // it means we actually did enable tracing (or tried to).
- if (!"file open failed".equals(ex.getMessage())) {
- throw ex;
- }
- }
- }
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLocalizedInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_getLocalizedInputStream() {
- String simpleString = "Heart \u2f3c";
- byte[] expected = {72, 0, 101, 0, 97, 0, 114, 0, 116, 0, 32, 0, 60, 47};
- byte[] returned = new byte[expected.length];
-
- System.setProperty("file.encoding", "UTF-16LE");
-
- try {
- ByteArrayInputStream bais = new ByteArrayInputStream(
- simpleString.getBytes("UTF-8"));
-
- InputStream lcIn =
- Runtime.getRuntime().getLocalizedInputStream(bais);
- try {
- lcIn.read(returned);
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- }
-
- assertTrue("wrong result for String: " + simpleString,
- Arrays.equals(expected, returned));
- } catch (UnsupportedEncodingException e) {
- fail("UnsupportedEncodingException was thrown.");
- }
- }
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "getLocalizedOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_getLocalizedOutputStream() {
- String simpleString = "Heart \u2f3c";
- byte[] expected = {72, 0, 101, 0, 97, 0, 114, 0, 116, 0, 32, 0, 60, 47};
- byte[] returned;
-
- String oldEncoding = System.getProperty("file.encoding");
- System.setProperty("file.encoding", "UTF-16LE");
-
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- OutputStream lcOut =
- Runtime.getRuntime().getLocalizedOutputStream(out);
- try {
- lcOut.write(simpleString.getBytes("UTF-8"));
- lcOut.flush();
- lcOut.close();
- } catch(IOException ioe) {
- fail("IOException was thrown.");
- }
-
- returned = out.toByteArray();
-
- assertTrue("wrong result for String: " + returned.toString() +
- " expected string: " + expected.toString(),
- Arrays.equals(expected, returned));
- } finally {
- System.setProperty("file.encoding", oldEncoding);
- }
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "load",
- args = {java.lang.String.class}
- )
- public void test_load() {
-
- try {
- Runtime.getRuntime().load("nonExistentLibrary");
- fail("UnsatisfiedLinkError was not thrown.");
- } catch(UnsatisfiedLinkError ule) {
- //expected
- }
-
- try {
- Runtime.getRuntime().load(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "loadLibrary",
- args = {java.lang.String.class}
- )
- public void test_loadLibrary() {
- try {
- Runtime.getRuntime().loadLibrary("nonExistentLibrary");
- fail("UnsatisfiedLinkError was not thrown.");
- } catch(UnsatisfiedLinkError ule) {
- //expected
- }
-
- try {
- Runtime.getRuntime().loadLibrary(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- public RuntimeTest() {
- }
-
- public RuntimeTest(String name) {
- super(name);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityExceptionTest.java
deleted file mode 100644
index 471dd1c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityExceptionTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class SecurityExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.SecurityException#SecurityException()
- */
- public void test_Constructor() {
- SecurityException e = new SecurityException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.SecurityException#SecurityException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- SecurityException e = new SecurityException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.SecurityException#SecurityException(String, Throwable)
- */
- @SuppressWarnings("nls")
- public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
- NullPointerException npe = new NullPointerException();
- SecurityException e = new SecurityException("fixture", npe);
- assertSame("fixture", e.getMessage());
- assertSame(npe, e.getCause());
- }
-
- /**
- * @tests java.lang.SecurityException#SecurityException(Throwable)
- */
- @SuppressWarnings("nls")
- public void test_ConstructorLjava_lang_Throwable() {
- NullPointerException npe = new NullPointerException();
- SecurityException e = new SecurityException(npe);
- assertSame(npe, e.getCause());
- }
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new SecurityException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new SecurityException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
deleted file mode 100644
index 607f388..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SecurityManagerTest.java
+++ /dev/null
@@ -1,510 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FilePermission;
-import java.net.InetAddress;
-import java.net.SocketPermission;
-import java.net.UnknownHostException;
-import java.security.AccessControlContext;
-import java.security.AllPermission;
-import java.security.Permission;
-import java.security.ProtectionDomain;
-import java.security.Security;
-
-import junit.framework.TestCase;
-import tests.support.Support_Exec;
-
-/**
- * Test case for java.lang.SecurityManager
- */
-public class SecurityManagerTest extends TestCase {
- MutableSecurityManager mutableSM = null;
-
- MockSecurityManager mockSM = null;
-
- /**
- * @tests java.lang.SecurityManager#checkPackageAccess(String)
- */
- public void test_checkPackageAccessLjava_lang_String() {
- final String old = Security.getProperty("package.access");
- Security.setProperty("package.access", "a.,bbb, c.d.");
-
- mutableSM
- .denyPermission(new RuntimePermission("accessClassInPackage.*"));
-
- try {
- mutableSM.checkPackageAccess("z.z.z");
- mutableSM.checkPackageAccess("aa");
- mutableSM.checkPackageAccess("bb");
- mutableSM.checkPackageAccess("c");
-
- try {
- mutableSM.checkPackageAccess("a");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- try {
- mutableSM.checkPackageAccess("bbb");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- try {
- mutableSM.checkPackageAccess("c.d.e");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- Security.setProperty("package.access", "QWERTY");
- mutableSM.checkPackageAccess("a");
- mutableSM.checkPackageAccess("qwerty");
- try {
- mutableSM.checkPackageAccess("QWERTY");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- } finally {
- Security.setProperty("package.access", old == null ? "" : old);
- }
- }
-
- /**
- * @tests java.lang.SecurityManager#checkPackageDefinition(String)
- */
- public void test_checkPackageDefinitionLjava_lang_String() {
- final String old = Security.getProperty("package.definition");
- Security.setProperty("package.definition", "a.,bbb, c.d.");
-
- mutableSM
- .denyPermission(new RuntimePermission("defineClassInPackage.*"));
-
- try {
- mutableSM.checkPackageDefinition("z.z.z");
- mutableSM.checkPackageDefinition("aa");
- mutableSM.checkPackageDefinition("bb");
- mutableSM.checkPackageDefinition("c");
-
- try {
- mutableSM.checkPackageDefinition("a");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- try {
- mutableSM.checkPackageDefinition("bbb");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- try {
- mutableSM.checkPackageDefinition("c.d.e");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- Security.setProperty("package.definition", "QWERTY");
- mutableSM.checkPackageDefinition("a");
- mutableSM.checkPackageDefinition("qwerty");
- try {
- mutableSM.checkPackageDefinition("QWERTY");
- fail("This should throw a SecurityException.");
- } catch (SecurityException ok) {
- }
-
- } finally {
- Security.setProperty("package.definition", old == null ? "" : old);
- }
- }
-
- /**
- * @tests java.lang.SecurityManager#checkAccess(java.lang.Thread)
- */
- public void test_checkAccessLjava_lang_Thread() throws InterruptedException {
- // Regression for HARMONY-66
- Thread t = new Thread() {
- @Override
- public void run() {
- };
- };
- t.start();
- t.join();
- new SecurityManager().checkAccess(t);
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkConnect(String, int, Object)}
- */
- @SuppressWarnings("nls")
- public void test_checkConnectLjava_lang_String_int_Ljava_lang_Object() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new SocketPermission("localhost:1024-",
- "accept, connect, listen"));
- ProtectionDomain pDomain = this.getClass().getProtectionDomain();
- ProtectionDomain[] pd = { pDomain };
- AccessControlContext acc = new AccessControlContext(pd);
- try {
- mutableSM.checkConnect("localhost", 1024, acc);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkExec(String)}
- */
- @SuppressWarnings("nls")
- public void test_checkExecLjava_lang_String() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new FilePermission("<<ALL FILES>>", "execute"));
- try {
- mutableSM.checkExec("java");
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkExit(int)}
- */
- @SuppressWarnings("nls")
- public void test_checkExit_int() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new RuntimePermission("exitVM"));
- try {
- mutableSM.checkExit(0);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkLink(String)}
- */
- @SuppressWarnings("nls")
- public void test_checkLinkLjava_lang_String() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new RuntimePermission("loadLibrary.harmony"));
- try {
- mutableSM.checkLink("harmony");
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkListen(int)}
- */
- @SuppressWarnings("nls")
- public void test_checkListen_int() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM
- .denyPermission(new SocketPermission("localhost:80", "listen"));
-
- try {
- mutableSM.checkListen(80);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new SocketPermission("localhost:1024-",
- "listen"));
- try {
- mutableSM.checkListen(0);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @throws UnknownHostException
- * @tests {@link java.lang.SecurityManager#checkMulticast(java.net.InetAddress)}
- */
- @SuppressWarnings("nls")
- public void test_checkMulticastLjava_net_InetAddress()
- throws UnknownHostException {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new SocketPermission(InetAddress.getByName(
- "localhost").getHostAddress(), "accept,connect"));
- try {
- mutableSM.checkMulticast(InetAddress.getByName("localhost"));
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @throws UnknownHostException
- * @tests {@link java.lang.SecurityManager#checkMulticast(java.net.InetAddress,byte)}
- */
- @SuppressWarnings( { "nls", "deprecation" })
- public void test_checkMulticastLjava_net_InetAddress_int()
- throws UnknownHostException {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new SocketPermission(InetAddress.getByName(
- "localhost").getHostAddress(), "accept,connect"));
- try {
- // the second parameter is the TTL(time to live)
- mutableSM.checkMulticast(InetAddress.getByName("localhost"),
- (byte) 0);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- *
- * @tests {@link java.lang.SecurityManager#checkPermission(Permission, Object)}
- */
- @SuppressWarnings("nls")
- public void test_checkPermissionLjava_security_PermissionLjava_lang_Object() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- Permission denyp = new SocketPermission("localhost:1024-",
- "accept, connect, listen");
- mutableSM.denyPermission(denyp);
- ProtectionDomain pDomain = this.getClass().getProtectionDomain();
- ProtectionDomain[] pd = { pDomain };
- AccessControlContext acc = new AccessControlContext(pd);
- try {
- mutableSM.checkPermission(denyp, acc);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkPrintJobAccess()}
- */
- @SuppressWarnings("nls")
- public void test_checkPrintJobAccess() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new RuntimePermission("queuePrintJob"));
- try {
- mutableSM.checkPrintJobAccess();
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkRead(FileDescriptor)}
- */
- @SuppressWarnings("nls")
- public void test_checkReadLjava_io_FileDescriptor() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new RuntimePermission("readFileDescriptor"));
- try {
- mutableSM.checkRead(new FileDescriptor());
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkRead(String,Object)}
- */
- @SuppressWarnings("nls")
- public void test_checkReadLjava_lang_StringLjava_lang_Object() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new FilePermission("<<ALL FILES>>", "read"));
- ProtectionDomain pDomain = this.getClass().getProtectionDomain();
- ProtectionDomain[] pd = { pDomain };
- AccessControlContext acc = new AccessControlContext(pd);
- try {
- mutableSM.checkRead("aa", acc);
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#checkSetFactory()}
- */
- @SuppressWarnings("nls")
- public void test_checkSetFactory() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new RuntimePermission("setFactory"));
- try {
- mutableSM.checkSetFactory();
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#getInCheck()}
- */
- public void test_getIncheck() {
- mockSM.setInCheck(false);
- assertFalse(mockSM.getInCheck());
- mockSM.setInCheck(true);
- assertTrue(mockSM.getInCheck());
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#getSecurityContext()}
- */
- @SuppressWarnings("nls")
- public void test_getSecurityContext() {
- // enable all but one check
- mutableSM.addPermission(new AllPermission());
- mutableSM.denyPermission(new FilePermission("<<ALL FILES>>", "read"));
- try {
- mutableSM.checkRead("aa", mutableSM.getSecurityContext());
- fail("This should throw a SecurityException.");
- } catch (SecurityException e) {
- // expected
- }
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#classDepth(String)}
- */
- @SuppressWarnings("nls")
- public void test_classDepthLjava_lang_String() {
- assertEquals(-1, mockSM.classDepth("nothing"));
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#classLoaderDepth()}
- */
- public void test_classLoaderDepth() {
- assertEquals(-1, mockSM.classLoaderDepth());
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#currentClassLoader()}
- */
- public void test_currentClassLoader() {
- assertNull(mockSM.currentClassLoader());
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#currentLoadedClass()}
- */
- public void test_currentLoadedClass() {
- assertNull(mockSM.currentLoadedClass());
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#inClass(String)}
- */
- @SuppressWarnings("nls")
- public void test_inClassLjava_lang_String() {
- assertFalse(mockSM.inClass("nothing"));
- assertTrue(mockSM.inClass(MockSecurityManager.class.getName()));
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#inClassLoader()}
- */
- public void test_inClassLoader() {
- assertFalse(mockSM.inClassLoader());
- }
-
- /**
- * @tests {@link java.lang.SecurityManager#inClassLoader()}
- */
- public void test_getClassContext() {
- assertEquals("MockSecurityManager should be the first in the classes stack",
- mockSM.getClassContext()[0], MockSecurityManager.class);
- }
-
- // set some protected method to public for testing
- class MockSecurityManager extends SecurityManager {
-
- public void setInCheck(boolean inCheck) {
- super.inCheck = inCheck;
- }
-
- @Override
- public int classDepth(String name) {
- return super.classDepth(name);
- }
-
- @Override
- public int classLoaderDepth() {
- return super.classLoaderDepth();
- }
-
- @Override
- public ClassLoader currentClassLoader() {
- return super.currentClassLoader();
- }
-
- @Override
- public Class<?> currentLoadedClass() {
- return super.currentLoadedClass();
- }
-
- @Override
- public Class[] getClassContext() {
- return super.getClassContext();
- }
-
- @Override
- public boolean inClass(String name) {
- return super.inClass(name);
- }
-
- @Override
- public boolean inClassLoader() {
- return super.inClassLoader();
- }
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mutableSM = new MutableSecurityManager();
- mockSM = new MockSecurityManager();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java
deleted file mode 100644
index e1dc2d3..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java
+++ /dev/null
@@ -1,660 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ShortTest extends TestCase {
- private Short sp = new Short((short) 18000);
- private Short sn = new Short((short) -19000);
-
- /**
- * @tests java.lang.Short#byteValue()
- */
- public void test_byteValue() {
- // Test for method byte java.lang.Short.byteValue()
- assertEquals("Returned incorrect byte value", 0, new Short(Short.MIN_VALUE)
- .byteValue());
- assertEquals("Returned incorrect byte value", -1, new Short(Short.MAX_VALUE)
- .byteValue());
- }
-
- /**
- * @tests java.lang.Short#compareTo(java.lang.Short)
- */
- public void test_compareToLjava_lang_Short() {
- // Test for method int java.lang.Short.compareTo(java.lang.Short)
- Short s = new Short((short) 1);
- Short x = new Short((short) 3);
- assertTrue(
- "Should have returned negative value when compared to greater short",
- s.compareTo(x) < 0);
- x = new Short((short) -1);
- assertTrue(
- "Should have returned positive value when compared to lesser short",
- s.compareTo(x) > 0);
- x = new Short((short) 1);
- assertEquals("Should have returned zero when compared to equal short",
- 0, s.compareTo(x));
-
- try {
- new Short((short)0).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Short#decode(java.lang.String)
- */
- public void test_decodeLjava_lang_String2() {
- // Test for method java.lang.Short
- // java.lang.Short.decode(java.lang.String)
- assertTrue("Did not decode -1 correctly", Short.decode("-1")
- .shortValue() == (short) -1);
- assertTrue("Did not decode -100 correctly", Short.decode("-100")
- .shortValue() == (short) -100);
- assertTrue("Did not decode 23 correctly", Short.decode("23")
- .shortValue() == (short) 23);
- assertTrue("Did not decode 0x10 correctly", Short.decode("0x10")
- .shortValue() == (short) 16);
- assertTrue("Did not decode 32767 correctly", Short.decode("32767")
- .shortValue() == (short) 32767);
- assertTrue("Did not decode -32767 correctly", Short.decode("-32767")
- .shortValue() == (short) -32767);
- assertTrue("Did not decode -32768 correctly", Short.decode("-32768")
- .shortValue() == (short) -32768);
-
- boolean exception = false;
- try {
- Short.decode("123s");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Did not throw NumberFormatException decoding 123s",
- exception);
-
- exception = false;
- try {
- Short.decode("32768");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.decode("-32769");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Short.decode("0x8000");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.decode("-0x8001");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Short#parseShort(java.lang.String)
- */
- public void test_parseShortLjava_lang_String2() {
- // Test for method short java.lang.Short.parseShort(java.lang.String)
- short sp = Short.parseShort("32746");
- short sn = Short.parseShort("-32746");
-
- assertTrue("Incorrect parse of short", sp == (short) 32746
- && (sn == (short) -32746));
- assertEquals("Returned incorrect value for 0", 0, Short.parseShort("0"));
- assertTrue("Returned incorrect value for most negative value", Short
- .parseShort("-32768") == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value", Short
- .parseShort("32767") == 0x7fff);
-
- boolean exception = false;
- try {
- Short.parseShort("32768");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-32769");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Short#parseShort(java.lang.String, int)
- */
- public void test_parseShortLjava_lang_StringI2() {
- // Test for method short java.lang.Short.parseShort(java.lang.String,
- // int)
- boolean aThrow = true;
- assertEquals("Incorrectly parsed hex string",
- 255, Short.parseShort("FF", 16));
- assertEquals("Incorrectly parsed oct string",
- 16, Short.parseShort("20", 8));
- assertEquals("Incorrectly parsed dec string",
- 20, Short.parseShort("20", 10));
- assertEquals("Incorrectly parsed bin string",
- 4, Short.parseShort("100", 2));
- assertEquals("Incorrectly parsed -hex string", -255, Short
- .parseShort("-FF", 16));
- assertEquals("Incorrectly parsed -oct string",
- -16, Short.parseShort("-20", 8));
- assertEquals("Incorrectly parsed -bin string", -4, Short
- .parseShort("-100", 2));
- assertEquals("Returned incorrect value for 0 hex", 0, Short.parseShort("0",
- 16));
- assertTrue("Returned incorrect value for most negative value hex",
- Short.parseShort("-8000", 16) == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value hex",
- Short.parseShort("7fff", 16) == 0x7fff);
- assertEquals("Returned incorrect value for 0 decimal", 0, Short.parseShort(
- "0", 10));
- assertTrue("Returned incorrect value for most negative value decimal",
- Short.parseShort("-32768", 10) == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value decimal",
- Short.parseShort("32767", 10) == 0x7fff);
-
- try {
- Short.parseShort("FF", 2);
- } catch (NumberFormatException e) {
- // Correct
- aThrow = false;
- }
- if (aThrow) {
- fail(
- "Failed to throw exception when passed hex string and base 2 radix");
- }
-
- boolean exception = false;
- try {
- Short.parseShort("10000000000", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue(
- "Failed to throw exception when passed string larger than 16 bits",
- exception);
-
- exception = false;
- try {
- Short.parseShort("32768", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-32769", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Short.parseShort("8000", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-8001", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
- }
-
- /**
- * @tests java.lang.Short#toString()
- */
- public void test_toString2() {
- // Test for method java.lang.String java.lang.Short.toString()
- assertTrue("Invalid string returned", sp.toString().equals("18000")
- && (sn.toString().equals("-19000")));
- assertEquals("Returned incorrect string", "32767", new Short((short) 32767)
- .toString());
- assertEquals("Returned incorrect string", "-32767", new Short((short) -32767)
- .toString());
- assertEquals("Returned incorrect string", "-32768", new Short((short) -32768)
- .toString());
- }
-
- /**
- * @tests java.lang.Short#toString(short)
- */
- public void test_toStringS2() {
- // Test for method java.lang.String java.lang.Short.toString(short)
- assertEquals("Returned incorrect string", "32767", Short.toString((short) 32767)
- );
- assertEquals("Returned incorrect string", "-32767", Short.toString((short) -32767)
- );
- assertEquals("Returned incorrect string", "-32768", Short.toString((short) -32768)
- );
- }
-
- /**
- * @tests java.lang.Short#valueOf(java.lang.String)
- */
- public void test_valueOfLjava_lang_String2() {
- // Test for method java.lang.Short
- // java.lang.Short.valueOf(java.lang.String)
- assertEquals("Returned incorrect short", -32768, Short.valueOf("-32768")
- .shortValue());
- assertEquals("Returned incorrect short", 32767, Short.valueOf("32767")
- .shortValue());
- }
-
- /**
- * @tests java.lang.Short#valueOf(java.lang.String, int)
- */
- public void test_valueOfLjava_lang_StringI2() {
- // Test for method java.lang.Short
- // java.lang.Short.valueOf(java.lang.String, int)
- boolean aThrow = true;
- assertEquals("Incorrectly parsed hex string", 255, Short.valueOf("FF", 16)
- .shortValue());
- assertEquals("Incorrectly parsed oct string", 16, Short.valueOf("20", 8)
- .shortValue());
- assertEquals("Incorrectly parsed dec string", 20, Short.valueOf("20", 10)
- .shortValue());
- assertEquals("Incorrectly parsed bin string", 4, Short.valueOf("100", 2)
- .shortValue());
- assertEquals("Incorrectly parsed -hex string", -255, Short.valueOf("-FF", 16)
- .shortValue());
- assertEquals("Incorrectly parsed -oct string", -16, Short.valueOf("-20", 8)
- .shortValue());
- assertEquals("Incorrectly parsed -bin string", -4, Short.valueOf("-100", 2)
- .shortValue());
- assertTrue("Did not decode 32767 correctly", Short.valueOf("32767", 10)
- .shortValue() == (short) 32767);
- assertTrue("Did not decode -32767 correctly", Short.valueOf("-32767",
- 10).shortValue() == (short) -32767);
- assertTrue("Did not decode -32768 correctly", Short.valueOf("-32768",
- 10).shortValue() == (short) -32768);
- try {
- Short.valueOf("FF", 2);
- } catch (NumberFormatException e) {
- // Correct
- aThrow = false;
- }
- if (aThrow) {
- fail(
- "Failed to throw exception when passed hex string and base 2 radix");
- }
- try {
- Short.valueOf("10000000000", 10);
- } catch (NumberFormatException e) {
- // Correct
- return;
- }
- fail(
- "Failed to throw exception when passed string larger than 16 bits");
- }
- /**
- * @tests java.lang.Short#valueOf(byte)
- */
- public void test_valueOfS() {
- assertEquals(new Short(Short.MIN_VALUE), Short.valueOf(Short.MIN_VALUE));
- assertEquals(new Short(Short.MAX_VALUE), Short.valueOf(Short.MAX_VALUE));
- assertEquals(new Short((short) 0), Short.valueOf((short) 0));
-
- short s = -128;
- while (s < 128) {
- assertEquals(new Short(s), Short.valueOf(s));
- assertSame(Short.valueOf(s), Short.valueOf(s));
- s++;
- }
- }
-
- /**
- * @tests java.lang.Short#hashCode()
- */
- public void test_hashCode() {
- assertEquals(1, new Short((short)1).hashCode());
- assertEquals(2, new Short((short)2).hashCode());
- assertEquals(0, new Short((short)0).hashCode());
- assertEquals(-1, new Short((short)-1).hashCode());
- }
-
- /**
- * @tests java.lang.Short#Short(String)
- */
- public void test_ConstructorLjava_lang_String() {
- assertEquals(new Short((short)0), new Short("0"));
- assertEquals(new Short((short)1), new Short("1"));
- assertEquals(new Short((short)-1), new Short("-1"));
-
- try {
- new Short("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#Short(short)
- */
- public void test_ConstructorS() {
- assertEquals(1, new Short((short)1).shortValue());
- assertEquals(2, new Short((short)2).shortValue());
- assertEquals(0, new Short((short)0).shortValue());
- assertEquals(-1, new Short((short)-1).shortValue());
- }
-
- /**
- * @tests java.lang.Short#byteValue()
- */
- public void test_booleanValue() {
- assertEquals(1, new Short((short)1).byteValue());
- assertEquals(2, new Short((short)2).byteValue());
- assertEquals(0, new Short((short)0).byteValue());
- assertEquals(-1, new Short((short)-1).byteValue());
- }
-
- /**
- * @tests java.lang.Short#equals(Object)
- */
- public void test_equalsLjava_lang_Object() {
- assertEquals(new Short((short)0), Short.valueOf((short)0));
- assertEquals(new Short((short)1), Short.valueOf((short)1));
- assertEquals(new Short((short)-1), Short.valueOf((short)-1));
-
- Short fixture = new Short((short)25);
- assertEquals(fixture, fixture);
- assertFalse(fixture.equals(null));
- assertFalse(fixture.equals("Not a Short"));
- }
-
- /**
- * @tests java.lang.Short#toString()
- */
- public void test_toString() {
- assertEquals("-1", new Short((short)-1).toString());
- assertEquals("0", new Short((short)0).toString());
- assertEquals("1", new Short((short)1).toString());
- assertEquals("-1", new Short((short)0xFFFF).toString());
- }
-
- /**
- * @tests java.lang.Short#toString(short)
- */
- public void test_toStringS() {
- assertEquals("-1", Short.toString((short)-1));
- assertEquals("0", Short.toString((short)0));
- assertEquals("1", Short.toString((short)1));
- assertEquals("-1", Short.toString((short)0xFFFF));
- }
-
- /**
- * @tests java.lang.Short#valueOf(String)
- */
- public void test_valueOfLjava_lang_String() {
- assertEquals(new Short((short)0), Short.valueOf("0"));
- assertEquals(new Short((short)1), Short.valueOf("1"));
- assertEquals(new Short((short)-1), Short.valueOf("-1"));
-
- try {
- Short.valueOf("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#valueOf(String,int)
- */
- public void test_valueOfLjava_lang_StringI() {
- assertEquals(new Short((short)0), Short.valueOf("0", 10));
- assertEquals(new Short((short)1), Short.valueOf("1", 10));
- assertEquals(new Short((short)-1), Short.valueOf("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Short.valueOf("1", 2).byteValue());
- assertEquals(Character.digit('F', 16), Short.valueOf("F", 16).byteValue());
-
- try {
- Short.valueOf("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#parseShort(String)
- */
- public void test_parseShortLjava_lang_String() {
- assertEquals(0, Short.parseShort("0"));
- assertEquals(1, Short.parseShort("1"));
- assertEquals(-1, Short.parseShort("-1"));
-
- try {
- Short.parseShort("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#parseShort(String,int)
- */
- public void test_parseShortLjava_lang_StringI() {
- assertEquals(0, Short.parseShort("0", 10));
- assertEquals(1, Short.parseShort("1", 10));
- assertEquals(-1, Short.parseShort("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Short.parseShort("1", 2));
- assertEquals(Character.digit('F', 16), Short.parseShort("F", 16));
-
- try {
- Short.parseShort("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#decode(String)
- */
- public void test_decodeLjava_lang_String() {
- assertEquals(new Short((short)0), Short.decode("0"));
- assertEquals(new Short((short)1), Short.decode("1"));
- assertEquals(new Short((short)-1), Short.decode("-1"));
- assertEquals(new Short((short)0xF), Short.decode("0xF"));
- assertEquals(new Short((short)0xF), Short.decode("#F"));
- assertEquals(new Short((short)0xF), Short.decode("0XF"));
- assertEquals(new Short((short)07), Short.decode("07"));
-
- try {
- Short.decode("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.decode("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.decode(null);
- //undocumented NPE, but seems consistent across JREs
- fail("Expected NullPointerException with null string.");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.lang.Short#doubleValue()
- */
- public void test_doubleValue() {
- assertEquals(-1D, new Short((short)-1).doubleValue(), 0D);
- assertEquals(0D, new Short((short)0).doubleValue(), 0D);
- assertEquals(1D, new Short((short)1).doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Short#floatValue()
- */
- public void test_floatValue() {
- assertEquals(-1F, new Short((short)-1).floatValue(), 0F);
- assertEquals(0F, new Short((short)0).floatValue(), 0F);
- assertEquals(1F, new Short((short)1).floatValue(), 0F);
- }
-
- /**
- * @tests java.lang.Short#intValue()
- */
- public void test_intValue() {
- assertEquals(-1, new Short((short)-1).intValue());
- assertEquals(0, new Short((short)0).intValue());
- assertEquals(1, new Short((short)1).intValue());
- }
-
- /**
- * @tests java.lang.Short#longValue()
- */
- public void test_longValue() {
- assertEquals(-1L, new Short((short)-1).longValue());
- assertEquals(0L, new Short((short)0).longValue());
- assertEquals(1L, new Short((short)1).longValue());
- }
-
- /**
- * @tests java.lang.Short#shortValue()
- */
- public void test_shortValue() {
- assertEquals(-1, new Short((short)-1).shortValue());
- assertEquals(0, new Short((short)0).shortValue());
- assertEquals(1, new Short((short)1).shortValue());
- }
-
- /**
- * @tests java.lang.Short#reverseBytes(short)
- */
- public void test_reverseBytesS() {
- assertEquals((short)0xABCD, Short.reverseBytes((short)0xCDAB));
- assertEquals((short)0x1234, Short.reverseBytes((short)0x3412));
- assertEquals((short)0x0011, Short.reverseBytes((short)0x1100));
- assertEquals((short)0x2002, Short.reverseBytes((short)0x0220));
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java
deleted file mode 100644
index b4e928f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class StackOverflowErrorTest extends TestCase {
-
- /**
- * @tests java.lang.StackOverflowError#StackOverflowError()
- */
- public void test_Constructor() {
- StackOverflowError e = new StackOverflowError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.StackOverflowError#StackOverflowError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- StackOverflowError e = new StackOverflowError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementOriginal.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementOriginal.java
deleted file mode 100644
index 27b5e4f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementOriginal.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargetClass;
-import junit.framework.TestCase;
-
-@TestTargetClass(StackTraceElement.class)
-public class StackTraceElementOriginal extends TestCase {
-
- public void pureJavaMethod(Object test) throws Exception {
- throw new Exception("pure java method");
- }
-
- native public void pureNativeMethod(Object test);
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementTest.java
deleted file mode 100644
index f095a76..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackTraceElementTest.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(StackTraceElement.class)
-public class StackTraceElementTest extends TestCase {
- private StackTraceElementOriginal original;
-
- @Override
- protected void setUp() throws Exception {
- original = new StackTraceElementOriginal();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * @tests java.lang.StackTraceElement#StackTraceElement(java.lang.String,
- * java.lang.String, java.lang.String, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StackTraceElement",
- args = {java.lang.String.class, java.lang.String.class, java.lang.String.class, int.class}
- )
- public void
- test_ConstructorLjava_lang_StringLjava_lang_StringLjava_lang_StringI() {
- StackTraceElement ste2 = null;
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- StackTraceElement ste1 = e.getStackTrace()[0];
- ste2 = new StackTraceElement(ste1.getClassName(),
- ste1.getMethodName(),
- ste1.getFileName(),
- ste1.getLineNumber());
- assertEquals("Incorrect value of class name",
- ste1.getClassName(), ste2.getClassName());
- assertEquals("Incorrect value of method name",
- ste1.getMethodName(), ste2.getMethodName());
- assertEquals("Incorrect value of file name",
- ste1.getFileName(), ste2.getFileName());
- assertEquals("Incorrect value of line number",
- ste1.getLineNumber(), ste2.getLineNumber());
- }
- assertNotNull("Incorrect stack trace object", ste2);
- try {
- new StackTraceElement(null,
- ste2.getMethodName(),
- ste2.getFileName(),
- ste2.getLineNumber());
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new StackTraceElement(ste2.getClassName(),
- null,
- ste2.getFileName(),
- ste2.getLineNumber());
- fail("Expected NullPointerException was not thrown");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- new StackTraceElement(ste2.getClassName(),
- ste2.getMethodName(),
- null,
- ste2.getLineNumber());
- } catch (NullPointerException e) {
- fail("Unexpected exception " + e.toString());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- StackTraceElement ste1 = e.getStackTrace()[0];
- StackTraceElement ste2 =
- new StackTraceElement(ste1.getClassName(),
- ste1.getMethodName(),
- ste1.getFileName(),
- ste1.getLineNumber());
- assertEquals("Objects are equaled", ste1, ste2);
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#getClassName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getClassName",
- args = {}
- )
- public void test_getClassName() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- assertEquals("Incorrect class name",
- getClass().getPackage().getName() +
- ".StackTraceElementOriginal",
- e.getStackTrace()[0].getClassName());
- assertEquals("Incorrect class name",
- getClass().getPackage().getName() +
- ".StackTraceElementTest",
- e.getStackTrace()[1].getClassName());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#getFileName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getFileName",
- args = {}
- )
- public void test_getFileName() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- assertEquals("Incorrect file name",
- "StackTraceElementOriginal.java",
- e.getStackTrace()[0].getFileName());
- assertEquals("Incorrect file name",
- "StackTraceElementTest.java",
- e.getStackTrace()[1].getFileName());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#getLineNumber()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLineNumber",
- args = {}
- )
- public void test_getLineNumber() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- assertEquals("Incorrect line number",
- 26, e.getStackTrace()[0].getLineNumber());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#getMethodName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMethodName",
- args = {}
- )
- public void test_getMethodName() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- assertEquals("Incorrect method name",
- "pureJavaMethod",
- e.getStackTrace()[0].getMethodName());
- assertEquals("Incorrect method name",
- "test_getMethodName",
- e.getStackTrace()[1].getMethodName());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- StackTraceElement ste1 = e.getStackTrace()[0];
- StackTraceElement ste2 =
- new StackTraceElement(ste1.getClassName(),
- ste1.getMethodName(),
- ste1.getFileName(),
- ste1.getLineNumber());
- assertEquals("Incorrect value of hash code",
- ste1.hashCode(), ste2.hashCode());
- assertFalse("Incorrect value of hash code",
- ste1.hashCode() == e.getStackTrace()[1].hashCode());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#isNativeMethod()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isNativeMethod",
- args = {}
- )
- public void test_isNativeMethod() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- assertFalse("Incorrect method type",
- e.getStackTrace()[0].isNativeMethod());
- }
- try {
- original.pureNativeMethod(new Object());
- } catch (Error e) {
- assertTrue("Incorrect method type",
- e.getStackTrace()[0].isNativeMethod());
- }
- }
-
- /**
- * @tests java.lang.StackTraceElement#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- try {
- original.pureJavaMethod(new Object());
- } catch (Exception e) {
- StackTraceElement ste = e.getStackTrace()[0];
- assertTrue("String representation doesn't contain a package name",
- ste.toString().contains(getClass().getPackage().getName()));
- assertTrue("String representation doesn't contain a class name",
- ste.toString().contains("StackTraceElementOriginal"));
- assertTrue("String representation doesn't contain a file name",
- ste.toString().contains("StackTraceElementOriginal.java"));
- assertTrue("String representation doesn't contain a line number",
- ste.toString().contains("26"));
- assertTrue("String representation doesn't contain a method name",
- ste.toString().contains("pureJavaMethod"));
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
deleted file mode 100644
index 472e27d..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
+++ /dev/null
@@ -1,1490 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import static org.apache.harmony.luni.tests.java.lang.MathTest.COPYSIGN_DD_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.COPYSIGN_FF_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_D_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_D_RESULTS;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_F_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.GETEXPONENT_F_RESULTS;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_DD_START_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_DD_FD_DIRECTION_CASES;
-import static org.apache.harmony.luni.tests.java.lang.MathTest.NEXTAFTER_FD_START_CASES;
-
-public class StrictMathTest extends junit.framework.TestCase {
-
- double HYP = StrictMath.sqrt(2.0);
-
- double OPP = 1.0;
-
- double ADJ = 1.0;
-
- /* Required to make previous preprocessor flags work - do not remove */
- int unused = 0;
-
- /**
- * @tests java.lang.StrictMath#abs(double)
- */
- public void test_absD() {
- // Test for method double java.lang.StrictMath.abs(double)
-
- assertTrue("Incorrect double abs value",
- (StrictMath.abs(-1908.8976) == 1908.8976));
- assertTrue("Incorrect double abs value",
- (StrictMath.abs(1908.8976) == 1908.8976));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(float)
- */
- public void test_absF() {
- // Test for method float java.lang.StrictMath.abs(float)
- assertTrue("Incorrect float abs value",
- (StrictMath.abs(-1908.8976f) == 1908.8976f));
- assertTrue("Incorrect float abs value",
- (StrictMath.abs(1908.8976f) == 1908.8976f));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(int)
- */
- public void test_absI() {
- // Test for method int java.lang.StrictMath.abs(int)
- assertTrue("Incorrect int abs value",
- (StrictMath.abs(-1908897) == 1908897));
- assertTrue("Incorrect int abs value",
- (StrictMath.abs(1908897) == 1908897));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(long)
- */
- public void test_absJ() {
- // Test for method long java.lang.StrictMath.abs(long)
- assertTrue("Incorrect long abs value", (StrictMath
- .abs(-19088976000089L) == 19088976000089L));
- assertTrue("Incorrect long abs value",
- (StrictMath.abs(19088976000089L) == 19088976000089L));
- }
-
- /**
- * @tests java.lang.StrictMath#acos(double)
- */
- public void test_acosD() {
- // Test for method double java.lang.StrictMath.acos(double)
- assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
- .acos(ADJ / HYP)) == ADJ / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#asin(double)
- */
- public void test_asinD() {
- // Test for method double java.lang.StrictMath.asin(double)
- assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
- .asin(OPP / HYP)) == OPP / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#atan(double)
- */
- public void test_atanD() {
- // Test for method double java.lang.StrictMath.atan(double)
- double answer = StrictMath.tan(StrictMath.atan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#atan2(double, double)
- */
- public void test_atan2DD() {
- // Test for method double java.lang.StrictMath.atan2(double, double)
- double answer = StrictMath.atan(StrictMath.tan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#cbrt(double)
- */
- @SuppressWarnings("boxing")
- public void test_cbrt_D() {
- // Test for special situations
- assertTrue("Should return Double.NaN", Double.isNaN(StrictMath
- .cbrt(Double.NaN)));
- assertEquals("Should return Double.POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .cbrt(Double.POSITIVE_INFINITY));
- assertEquals("Should return Double.NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath
- .cbrt(Double.NEGATIVE_INFINITY));
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.cbrt(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.cbrt(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.cbrt(-0.0)));
-
- assertEquals("Should return 3.0", 3.0, StrictMath.cbrt(27.0));
- assertEquals("Should return 23.111993172558684", 23.111993172558684,
- StrictMath.cbrt(12345.6));
- assertEquals("Should return 5.643803094122362E102",
- 5.643803094122362E102, StrictMath.cbrt(Double.MAX_VALUE));
- assertEquals("Should return 0.01", 0.01, StrictMath.cbrt(0.000001));
-
- assertEquals("Should return -3.0", -3.0, StrictMath.cbrt(-27.0));
- assertEquals("Should return -23.111993172558684", -23.111993172558684,
- StrictMath.cbrt(-12345.6));
- assertEquals("Should return 1.7031839360032603E-108",
- 1.7031839360032603E-108, StrictMath.cbrt(Double.MIN_VALUE));
- assertEquals("Should return -0.01", -0.01, StrictMath.cbrt(-0.000001));
-
- try{
- StrictMath.cbrt((Double)null);
- fail("Should throw NullPointerException");
- }catch(NullPointerException e){
- //expected
- }
- }
-
- /**
- * @tests java.lang.StrictMath#ceil(double)
- */
- public void test_ceilD() {
- // Test for method double java.lang.StrictMath.ceil(double)
- assertEquals("Incorrect ceiling for double",
- 79, StrictMath.ceil(78.89), 0.0);
- assertEquals("Incorrect ceiling for double",
- -78, StrictMath.ceil(-78.89), 0.0);
- }
-
- /**
- * @tests {@link java.lang.StrictMath#copySign(double, double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_copySign_DD() {
- for (int i = 0; i < COPYSIGN_DD_CASES.length; i++) {
- final double magnitude = COPYSIGN_DD_CASES[i];
- final long absMagnitudeBits = Double.doubleToLongBits(StrictMath
- .abs(magnitude));
- final long negMagnitudeBits = Double.doubleToLongBits(-StrictMath
- .abs(magnitude));
-
- // cases for NaN
- assertEquals("If the sign is NaN, the result should be positive.",
- absMagnitudeBits, Double.doubleToLongBits(StrictMath
- .copySign(magnitude, Double.NaN)));
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .copySign(Double.NaN, magnitude)));
-
- for (int j = 0; j < COPYSIGN_DD_CASES.length; j++) {
- final double sign = COPYSIGN_DD_CASES[j];
- final long resultBits = Double.doubleToLongBits(StrictMath
- .copySign(magnitude, sign));
-
- if (sign > 0 || Double.valueOf(+0.0).equals(sign)
- || Double.valueOf(0.0).equals(sign)) {
- assertEquals(
- "If the sign is positive, the result should be positive.",
- absMagnitudeBits, resultBits);
- }
- if (sign < 0 || Double.valueOf(-0.0).equals(sign)) {
- assertEquals(
- "If the sign is negative, the result should be negative.",
- negMagnitudeBits, resultBits);
- }
- }
- }
-
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .copySign(Double.NaN, Double.NaN)));
-
- try {
- StrictMath.copySign((Double) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.copySign(2.3, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.copySign((Double) null, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- double d = Double.longBitsToDouble(0xfff8000000000000L);
- assertEquals(1.0, StrictMath.copySign(1.0, d), 0d);
- }
-
- /**
- * @tests {@link java.lang.StrictMath#copySign(float, float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_copySign_FF() {
- for (int i = 0; i < COPYSIGN_FF_CASES.length; i++) {
- final float magnitude = COPYSIGN_FF_CASES[i];
- final int absMagnitudeBits = Float.floatToIntBits(StrictMath
- .abs(magnitude));
- final int negMagnitudeBits = Float.floatToIntBits(-StrictMath
- .abs(magnitude));
-
- // cases for NaN
- assertEquals("If the sign is NaN, the result should be positive.",
- absMagnitudeBits, Float.floatToIntBits(StrictMath.copySign(
- magnitude, Float.NaN)));
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .copySign(Float.NaN, magnitude)));
-
- for (int j = 0; j < COPYSIGN_FF_CASES.length; j++) {
- final float sign = COPYSIGN_FF_CASES[j];
- final int resultBits = Float.floatToIntBits(StrictMath
- .copySign(magnitude, sign));
- if (sign > 0 || Float.valueOf(+0.0f).equals(sign)
- || Float.valueOf(0.0f).equals(sign)) {
- assertEquals(
- "If the sign is positive, the result should be positive.",
- absMagnitudeBits, resultBits);
- }
- if (sign < 0 || Float.valueOf(-0.0f).equals(sign)) {
- assertEquals(
- "If the sign is negative, the result should be negative.",
- negMagnitudeBits, resultBits);
- }
- }
- }
-
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .copySign(Float.NaN, Float.NaN)));
-
- try {
- StrictMath.copySign((Float) null, 2.3f);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.copySign(2.3f, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.copySign((Float) null, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- float f = Float.intBitsToFloat(0xffc00000);
- assertEquals(1.0f, StrictMath.copySign(1.0f, f), 0f);
- }
-
- /**
- * @tests java.lang.StrictMath#cos(double)
- */
- public void test_cosD() {
- // Test for method double java.lang.StrictMath.cos(double)
-
- assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
- .acos(ADJ / HYP)) == ADJ / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#cosh(double)
- */
- @SuppressWarnings("boxing")
- public void test_cosh_D() {
- // Test for special situations
- assertTrue("Should return NaN", Double.isNaN(StrictMath
- .cosh(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .cosh(Double.POSITIVE_INFINITY));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .cosh(Double.NEGATIVE_INFINITY));
- assertEquals("Should return 1.0", 1.0, StrictMath.cosh(+0.0));
- assertEquals("Should return 1.0", 1.0, StrictMath.cosh(-0.0));
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.cosh(1234.56));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.cosh(-1234.56));
- assertEquals("Should return 1.0000000000005", 1.0000000000005,
- StrictMath.cosh(0.000001));
- assertEquals("Should return 1.0000000000005", 1.0000000000005,
- StrictMath.cosh(-0.000001));
- assertEquals("Should return 5.212214351945598", 5.212214351945598,
- StrictMath.cosh(2.33482));
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.cosh(Double.MAX_VALUE));
- assertEquals("Should return 1.0", 1.0, StrictMath
- .cosh(Double.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.StrictMath#exp(double)
- */
- public void test_expD() {
- // Test for method double java.lang.StrictMath.exp(double)
- assertTrue("Incorrect answer returned for simple power", StrictMath
- .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
- * StrictMath.E * StrictMath.E) < 0.1D);
- assertTrue("Incorrect answer returned for larger power", StrictMath
- .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
- }
-
- /**
- * @tests java.lang.StrictMath#expm1(double)
- */
- @SuppressWarnings("boxing")
- public void test_expm1_D() {
- //Test for special cases
- assertTrue("Should return NaN", Double.isNaN(StrictMath.expm1(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.expm1(Double.POSITIVE_INFINITY));
- assertEquals("Should return -1.0", -1.0, StrictMath
- .expm1(Double.NEGATIVE_INFINITY));
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.expm1(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.expm1(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.expm1(-0.0)));
-
- assertEquals("Should return -9.999950000166666E-6",
- -9.999950000166666E-6, StrictMath.expm1(-0.00001));
- assertEquals("Should return 1.0145103074469635E60",
- 1.0145103074469635E60, StrictMath.expm1(138.16951162));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .expm1(123456789123456789123456789.4521584223));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.expm1(Double.MAX_VALUE));
- assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, StrictMath
- .expm1(Double.MIN_VALUE));
-
- }
-
- /**
- * @tests java.lang.StrictMath#floor(double)
- */
- public void test_floorD() {
- // Test for method double java.lang.StrictMath.floor(double)
- assertEquals("Incorrect floor for double",
- 78, StrictMath.floor(78.89), 0.0);
- assertEquals("Incorrect floor for double",
- -79, StrictMath.floor(-78.89), 0.0);
- }
-
- /**
- * @tests {@link java.lang.StrictMath#getExponent(double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_getExponent_D() {
- for (int i = 0; i < GETEXPONENT_D_CASES.length; i++) {
- final double number = GETEXPONENT_D_CASES[i];
- final int result = GETEXPONENT_D_RESULTS[i];
- assertEquals("Wrong result of getExponent(double).", result,
- StrictMath.getExponent(number));
- }
-
- try {
- StrictMath.getExponent((Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StrictMath#getExponent(float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_getExponent_F() {
- for (int i = 0; i < GETEXPONENT_F_CASES.length; i++) {
- final float number = GETEXPONENT_F_CASES[i];
- final int result = GETEXPONENT_F_RESULTS[i];
- assertEquals("Wrong result of getExponent(float).", result,
- StrictMath.getExponent(number));
- }
- try {
- StrictMath.getExponent((Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StrictMath#hypot(double, double)
- */
- @SuppressWarnings("boxing")
- public void test_hypot_DD() {
- // Test for special cases
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
- 1.0));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
- 123.324));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(-758.2587,
- Double.POSITIVE_INFINITY));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(5687.21,
- Double.NEGATIVE_INFINITY));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(Double.POSITIVE_INFINITY,
- Double.NEGATIVE_INFINITY));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.hypot(Double.NEGATIVE_INFINITY,
- Double.POSITIVE_INFINITY));
- assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(Double.NaN,
- 2342301.89843)));
- assertTrue("Should return NaN",Double.isNaN(StrictMath.hypot(-345.2680,
- Double.NaN)));
-
- assertEquals("Should return 2396424.905416697", 2396424.905416697, StrictMath
- .hypot(12322.12, -2396393.2258));
- assertEquals("Should return 138.16958070558556", 138.16958070558556,
- StrictMath.hypot(-138.16951162, 0.13817035864));
- assertEquals("Should return 1.7976931348623157E308",
- 1.7976931348623157E308, StrictMath.hypot(Double.MAX_VALUE, 211370.35));
- assertEquals("Should return 5413.7185", 5413.7185, StrictMath.hypot(
- -5413.7185, Double.MIN_VALUE));
-
- }
-
- /**
- * @tests java.lang.StrictMath#IEEEremainder(double, double)
- */
- public void test_IEEEremainderDD() {
- // Test for method double java.lang.StrictMath.IEEEremainder(double,
- // double)
- assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
- 1.0, 1.0), 0.0);
- assertTrue(
- "Incorrect remainder returned",
- StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
- || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
- }
-
- /**
- * @tests java.lang.StrictMath#log(double)
- */
- public void test_logD() {
- // Test for method double java.lang.StrictMath.log(double)
- for (double d = 10; d >= -10; d -= 0.5) {
- double answer = StrictMath.log(StrictMath.exp(d));
- assertTrue("Answer does not equal expected answer for d = " + d
- + " answer = " + answer,
- StrictMath.abs(answer - d) <= StrictMath
- .abs(d * 0.00000001));
- }
- }
-
- /**
- * @tests java.lang.StrictMath#log10(double)
- */
- @SuppressWarnings("boxing")
- public void test_log10_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double.isNaN(StrictMath
- .log10(Double.NaN)));
- assertTrue("Should return NaN", Double.isNaN(StrictMath
- .log10(-2541.05745687234187532)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .log10(Double.POSITIVE_INFINITY));
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath.log10(0.0));
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath.log10(+0.0));
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath.log10(-0.0));
- assertEquals("Should return 14.0", 14.0, StrictMath.log10(StrictMath
- .pow(10, 14)));
-
- assertEquals("Should return 3.7389561269540406", 3.7389561269540406,
- StrictMath.log10(5482.2158));
- assertEquals("Should return 14.661551142893833", 14.661551142893833,
- StrictMath.log10(458723662312872.125782332587));
- assertEquals("Should return -0.9083828622192334", -0.9083828622192334,
- StrictMath.log10(0.12348583358871));
- assertEquals("Should return 308.25471555991675", 308.25471555991675,
- StrictMath.log10(Double.MAX_VALUE));
- assertEquals("Should return -323.3062153431158", -323.3062153431158,
- StrictMath.log10(Double.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.StrictMath#log1p(double)
- */
- @SuppressWarnings("boxing")
- public void test_log1p_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double.isNaN(StrictMath
- .log1p(Double.NaN)));
- assertTrue("Should return NaN", Double.isNaN(StrictMath
- .log1p(-32.0482175)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .log1p(Double.POSITIVE_INFINITY));
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.log1p(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.log1p(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.log1p(-0.0)));
-
- assertEquals("Should return -0.2941782295312541", -0.2941782295312541,
- StrictMath.log1p(-0.254856327));
- assertEquals("Should return 7.368050685564151", 7.368050685564151,
- StrictMath.log1p(1583.542));
- assertEquals("Should return 0.4633708685409921", 0.4633708685409921,
- StrictMath.log1p(0.5894227));
- assertEquals("Should return 709.782712893384", 709.782712893384,
- StrictMath.log1p(Double.MAX_VALUE));
- assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE,
- StrictMath.log1p(Double.MIN_VALUE));
- }
-
- /**
- * @tests java.lang.StrictMath#max(double, double)
- */
- public void test_maxDD() {
- // Test for method double java.lang.StrictMath.max(double, double)
- assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
- -1908897.6000089, 1908897.6000089), 0D);
- assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
- 1908897.6000089), 0D);
- assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
- -1908897.6000089), 0D);
-
- }
-
- /**
- * @tests java.lang.StrictMath#max(float, float)
- */
- public void test_maxFF() {
- // Test for method float java.lang.StrictMath.max(float, float)
- assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
- 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value", StrictMath.max(2.0f,
- 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
- -1908897.600f) == -2.0f);
- }
-
- /**
- * @tests java.lang.StrictMath#max(int, int)
- */
- public void test_maxII() {
- // Test for method int java.lang.StrictMath.max(int, int)
- assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
- 19088976));
- assertEquals("Incorrect int max value",
- 19088976, StrictMath.max(20, 19088976));
- assertEquals("Incorrect int max value",
- -20, StrictMath.max(-20, -19088976));
- }
-
- /**
- * @tests java.lang.StrictMath#max(long, long)
- */
- public void test_maxJJ() {
- // Test for method long java.lang.StrictMath.max(long, long)
- assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
- 19088976000089L));
- assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
- -19088976000089L));
- }
-
- /**
- * @tests java.lang.StrictMath#min(double, double)
- */
- public void test_minDD() {
- // Test for method double java.lang.StrictMath.min(double, double)
- assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
- -1908897.6000089, 1908897.6000089), 0D);
- assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
- 1908897.6000089), 0D);
- assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
- -1908897.6000089), 0D);
- }
-
- /**
- * @tests java.lang.StrictMath#min(float, float)
- */
- public void test_minFF() {
- // Test for method float java.lang.StrictMath.min(float, float)
- assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
- 1908897.600f) == -1908897.600f);
- assertTrue("Incorrect float min value", StrictMath.min(2.0f,
- 1908897.600f) == 2.0f);
- assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
- -1908897.600f) == -1908897.600f);
- }
-
- /**
- * @tests java.lang.StrictMath#min(int, int)
- */
- public void test_minII() {
- // Test for method int java.lang.StrictMath.min(int, int)
- assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
- 19088976));
- assertEquals("Incorrect int min value",
- 20, StrictMath.min(20, 19088976));
- assertEquals("Incorrect int min value",
- -19088976, StrictMath.min(-20, -19088976));
-
- }
-
- /**
- * @tests java.lang.StrictMath#min(long, long)
- */
- public void test_minJJ() {
- // Test for method long java.lang.StrictMath.min(long, long)
- assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long min value", 20, StrictMath.min(20,
- 19088976000089L));
- assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
- -19088976000089L));
- }
-
- /**
- * @tests {@link java.lang.StrictMath#nextAfter(double, double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextAfter_DD() {
- // test for most cases without exception
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- final double start = NEXTAFTER_DD_START_CASES[i][0];
- final long nextUpBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
- final long nextDownBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][2]);
-
- for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
- final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
- final long resultBits = Double.doubleToLongBits(StrictMath
- .nextAfter(start, direction));
- final long directionBits = Double.doubleToLongBits(direction);
- if (direction > start) {
- assertEquals("Result should be next up-number.",
- nextUpBits, resultBits);
- } else if (direction < start) {
- assertEquals("Result should be next down-number.",
- nextDownBits, resultBits);
- } else {
- assertEquals("Result should be direction.", directionBits,
- resultBits);
- }
- }
- }
-
- // test for cases with NaN
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .nextAfter(NEXTAFTER_DD_START_CASES[i][0], Double.NaN)));
- }
- for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .nextAfter(Double.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
- }
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .nextAfter(Double.NaN, Double.NaN)));
-
- // test for exception
- try {
- StrictMath.nextAfter((Double) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.nextAfter(2.3, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.nextAfter((Double) null, (Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StrictMath#nextAfter(float, double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextAfter_FD() {
- // test for most cases without exception
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- final float start = NEXTAFTER_FD_START_CASES[i][0];
- final int nextUpBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
- final int nextDownBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][2]);
-
- for (int j = 0; j < NEXTAFTER_DD_FD_DIRECTION_CASES.length; j++) {
- final double direction = NEXTAFTER_DD_FD_DIRECTION_CASES[j];
- final int resultBits = Float.floatToIntBits(StrictMath
- .nextAfter(start, direction));
- if (direction > start) {
- assertEquals("Result should be next up-number.",
- nextUpBits, resultBits);
- } else if (direction < start) {
- assertEquals("Result should be next down-number.",
- nextDownBits, resultBits);
- } else {
- final int equivalentBits = Float.floatToIntBits(new Float(
- direction));
- assertEquals(
- "Result should be a number equivalent to direction.",
- equivalentBits, resultBits);
- }
- }
- }
-
- // test for cases with NaN
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .nextAfter(NEXTAFTER_FD_START_CASES[i][0], Float.NaN)));
- }
- for (int i = 0; i < NEXTAFTER_DD_FD_DIRECTION_CASES.length; i++) {
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .nextAfter(Float.NaN, NEXTAFTER_DD_FD_DIRECTION_CASES[i])));
- }
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .nextAfter(Float.NaN, Float.NaN)));
-
- // test for exception
- try {
- StrictMath.nextAfter((Float) null, 2.3);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.nextAfter(2.3, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.nextAfter((Float) null, (Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StrictMath#nextUp(double)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextUp_D() {
- // This method is semantically equivalent to nextAfter(d,
- // Double.POSITIVE_INFINITY),
- // so we use the data of test_nextAfter_DD
- for (int i = 0; i < NEXTAFTER_DD_START_CASES.length; i++) {
- final double start = NEXTAFTER_DD_START_CASES[i][0];
- final long nextUpBits = Double
- .doubleToLongBits(NEXTAFTER_DD_START_CASES[i][1]);
- final long resultBits = Double.doubleToLongBits(StrictMath
- .nextUp(start));
- assertEquals("Result should be next up-number.", nextUpBits,
- resultBits);
- }
-
- // test for cases with NaN
- assertTrue("The result should be NaN.", Double.isNaN(StrictMath
- .nextUp(Double.NaN)));
-
- // test for exception
- try {
- StrictMath.nextUp((Double) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StrictMath#nextUp(float)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_nextUp_F() {
- // This method is semantically equivalent to nextAfter(f,
- // Float.POSITIVE_INFINITY),
- // so we use the data of test_nextAfter_FD
- for (int i = 0; i < NEXTAFTER_FD_START_CASES.length; i++) {
- final float start = NEXTAFTER_FD_START_CASES[i][0];
- final int nextUpBits = Float
- .floatToIntBits(NEXTAFTER_FD_START_CASES[i][1]);
- final int resultBits = Float.floatToIntBits(StrictMath
- .nextUp(start));
- assertEquals("Result should be next up-number.", nextUpBits,
- resultBits);
- }
-
- // test for cases with NaN
- assertTrue("The result should be NaN.", Float.isNaN(StrictMath
- .nextUp(Float.NaN)));
-
- // test for exception
- try {
- StrictMath.nextUp((Float) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StrictMath#pow(double, double)
- */
- public void test_powDD() {
- // Test for method double java.lang.StrictMath.pow(double, double)
- assertTrue("pow returned incorrect value",
- (long) StrictMath.pow(2, 8) == 256l);
- assertTrue("pow returned incorrect value",
- StrictMath.pow(2, -8) == 0.00390625d);
- }
-
- /**
- * @tests java.lang.StrictMath#rint(double)
- */
- public void test_rintD() {
- // Test for method double java.lang.StrictMath.rint(double)
- assertEquals("Failed to round properly - up to odd",
- 3.0, StrictMath.rint(2.9), 0D);
- assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
- .rint(Double.NaN)));
- assertEquals("Failed to round properly down to even", 2.0, StrictMath
- .rint(2.1), 0D);
- assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
- .rint(2.5) == 2.0);
- }
-
- /**
- * @tests java.lang.StrictMath#round(double)
- */
- public void test_roundD() {
- // Test for method long java.lang.StrictMath.round(double)
- assertEquals("Incorrect rounding of a float",
- -91, StrictMath.round(-90.89d));
- }
-
- /**
- * @tests java.lang.StrictMath#round(float)
- */
- public void test_roundF() {
- // Test for method int java.lang.StrictMath.round(float)
- assertEquals("Incorrect rounding of a float",
- -91, StrictMath.round(-90.89f));
- }
-
- /**
- * @tests {@link java.lang.StrictMath#scalb(double, int)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_scalb_DI() {
- // result is normal
- assertEquals(4.1422946304E7, StrictMath.scalb(1.2345, 25));
- assertEquals(3.679096698760986E-8, StrictMath.scalb(1.2345, -25));
- assertEquals(1.2345, StrictMath.scalb(1.2345, 0));
- assertEquals(7868514.304, StrictMath.scalb(0.2345, 25));
-
- double normal = StrictMath.scalb(0.2345, -25);
- assertEquals(6.98864459991455E-9, normal);
- // precision kept
- assertEquals(0.2345, StrictMath.scalb(normal, 25));
-
- assertEquals(0.2345, StrictMath.scalb(0.2345, 0));
- assertEquals(-4.1422946304E7, StrictMath.scalb(-1.2345, 25));
- assertEquals(-6.98864459991455E-9, StrictMath.scalb(-0.2345, -25));
- assertEquals(2.0, StrictMath.scalb(Double.MIN_NORMAL / 2, 1024));
- assertEquals(64.0, StrictMath.scalb(Double.MIN_VALUE, 1080));
- assertEquals(234, StrictMath.getExponent(StrictMath.scalb(1.0, 234)));
- assertEquals(3.9999999999999996, StrictMath.scalb(Double.MAX_VALUE,
- Double.MIN_EXPONENT));
-
- // result is near infinity
- double halfMax = StrictMath.scalb(1.0, Double.MAX_EXPONENT);
- assertEquals(8.98846567431158E307, halfMax);
- assertEquals(Double.MAX_VALUE, halfMax - StrictMath.ulp(halfMax)
- + halfMax);
- assertEquals(Double.POSITIVE_INFINITY, halfMax + halfMax);
- assertEquals(1.7976931348623155E308, StrictMath.scalb(1.0 - StrictMath
- .ulp(1.0), Double.MAX_EXPONENT + 1));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- 1.0 - StrictMath.ulp(1.0), Double.MAX_EXPONENT + 2));
-
- halfMax = StrictMath.scalb(-1.0, Double.MAX_EXPONENT);
- assertEquals(-8.98846567431158E307, halfMax);
- assertEquals(-Double.MAX_VALUE, halfMax + StrictMath.ulp(halfMax)
- + halfMax);
- assertEquals(Double.NEGATIVE_INFINITY, halfMax + halfMax);
-
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(0.345, 1234));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath
- .scalb(44.345E102, 934));
- assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(-44.345E102,
- 934));
-
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- Double.MIN_NORMAL / 2, 4000));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- Double.MIN_VALUE, 8000));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- Double.MAX_VALUE, 1));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- Double.POSITIVE_INFINITY, 0));
- assertEquals(Double.POSITIVE_INFINITY, StrictMath.scalb(
- Double.POSITIVE_INFINITY, -1));
- assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(
- Double.NEGATIVE_INFINITY, -1));
- assertEquals(Double.NEGATIVE_INFINITY, StrictMath.scalb(
- Double.NEGATIVE_INFINITY, Double.MIN_EXPONENT));
-
- // result is subnormal/zero
- long posZeroBits = Double.doubleToLongBits(+0.0);
- long negZeroBits = Double.doubleToLongBits(-0.0);
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- +0.0, Integer.MAX_VALUE)));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- +0.0, -123)));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- +0.0, 0)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -0.0, 123)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -0.0, Integer.MIN_VALUE)));
-
- assertEquals(Double.MIN_VALUE, StrictMath.scalb(1.0, -1074));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(1.0,
- -1075)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -1.0, -1075)));
-
- // precision lost
- assertEquals(StrictMath.scalb(21.405, -1078), StrictMath.scalb(21.405,
- -1079));
- assertEquals(Double.MIN_VALUE, StrictMath.scalb(21.405, -1079));
- assertEquals(-Double.MIN_VALUE, StrictMath.scalb(-21.405, -1079));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- 21.405, -1080)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -21.405, -1080)));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- Double.MIN_VALUE, -1)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -Double.MIN_VALUE, -1)));
- assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL, -52));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- Double.MIN_NORMAL, -53)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -Double.MIN_NORMAL, -53)));
- assertEquals(Double.MIN_VALUE, StrictMath
- .scalb(Double.MAX_VALUE, -2098));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- Double.MAX_VALUE, -2099)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -Double.MAX_VALUE, -2099)));
- assertEquals(Double.MIN_VALUE, StrictMath.scalb(Double.MIN_NORMAL / 3,
- -51));
- assertEquals(posZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- Double.MIN_NORMAL / 3, -52)));
- assertEquals(negZeroBits, Double.doubleToLongBits(StrictMath.scalb(
- -Double.MIN_NORMAL / 3, -52)));
- double subnormal = StrictMath.scalb(Double.MIN_NORMAL / 3, -25);
- assertEquals(2.2104123E-316, subnormal);
- // precision lost
- assertFalse(Double.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 25));
-
- // NaN
- assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 1)));
- assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, 0)));
- assertTrue(Double.isNaN(StrictMath.scalb(Double.NaN, -120)));
-
- assertEquals(1283457024, Double.doubleToLongBits(StrictMath.scalb(
- Double.MIN_VALUE * 153, 23)));
- assertEquals(-9223372035571318784L, Double.doubleToLongBits(StrictMath
- .scalb(-Double.MIN_VALUE * 153, 23)));
- assertEquals(36908406321184768L, Double.doubleToLongBits(StrictMath
- .scalb(Double.MIN_VALUE * 153, 52)));
- assertEquals(-9186463630533591040L, Double.doubleToLongBits(StrictMath
- .scalb(-Double.MIN_VALUE * 153, 52)));
-
- // test for exception
- try {
- StrictMath.scalb((Double) null, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.scalb(1.0, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.scalb((Double) null, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StrictMath#scalb(float, int)}
- * @since 1.6
- */
- @SuppressWarnings("boxing")
- public void test_scalb_FI() {
- // result is normal
- assertEquals(4.1422946304E7f, StrictMath.scalb(1.2345f, 25));
- assertEquals(3.679096698760986E-8f, StrictMath.scalb(1.2345f, -25));
- assertEquals(1.2345f, StrictMath.scalb(1.2345f, 0));
- assertEquals(7868514.304f, StrictMath.scalb(0.2345f, 25));
-
- float normal = StrictMath.scalb(0.2345f, -25);
- assertEquals(6.98864459991455E-9f, normal);
- // precision kept
- assertEquals(0.2345f, StrictMath.scalb(normal, 25));
-
- assertEquals(0.2345f, StrictMath.scalb(0.2345f, 0));
- assertEquals(-4.1422946304E7f, StrictMath.scalb(-1.2345f, 25));
- assertEquals(-6.98864459991455E-9f, StrictMath.scalb(-0.2345f, -25));
- assertEquals(2.0f, StrictMath.scalb(Float.MIN_NORMAL / 2, 128));
- assertEquals(64.0f, StrictMath.scalb(Float.MIN_VALUE, 155));
- assertEquals(34, StrictMath.getExponent(StrictMath.scalb(1.0f, 34)));
- assertEquals(3.9999998f, StrictMath.scalb(Float.MAX_VALUE,
- Float.MIN_EXPONENT));
-
- // result is near infinity
- float halfMax = StrictMath.scalb(1.0f, Float.MAX_EXPONENT);
- assertEquals(1.7014118E38f, halfMax);
- assertEquals(Float.MAX_VALUE, halfMax - StrictMath.ulp(halfMax)
- + halfMax);
- assertEquals(Float.POSITIVE_INFINITY, halfMax + halfMax);
- assertEquals(3.4028233E38f, StrictMath.scalb(1.0f - StrictMath
- .ulp(1.0f), Float.MAX_EXPONENT + 1));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
- 1.0f - StrictMath.ulp(1.0f), Float.MAX_EXPONENT + 2));
-
- halfMax = StrictMath.scalb(-1.0f, Float.MAX_EXPONENT);
- assertEquals(-1.7014118E38f, halfMax);
- assertEquals(-Float.MAX_VALUE, halfMax + StrictMath.ulp(halfMax)
- + halfMax);
- assertEquals(Float.NEGATIVE_INFINITY, halfMax + halfMax);
-
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(0.345f, 1234));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(44.345E10f, 934));
- assertEquals(Float.NEGATIVE_INFINITY, StrictMath
- .scalb(-44.345E10f, 934));
-
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
- Float.MIN_NORMAL / 2, 400));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MIN_VALUE,
- 800));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(Float.MAX_VALUE,
- 1));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
- Float.POSITIVE_INFINITY, 0));
- assertEquals(Float.POSITIVE_INFINITY, StrictMath.scalb(
- Float.POSITIVE_INFINITY, -1));
- assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb(
- Float.NEGATIVE_INFINITY, -1));
- assertEquals(Float.NEGATIVE_INFINITY, StrictMath.scalb(
- Float.NEGATIVE_INFINITY, Float.MIN_EXPONENT));
-
- // result is subnormal/zero
- int posZeroBits = Float.floatToIntBits(+0.0f);
- int negZeroBits = Float.floatToIntBits(-0.0f);
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
- Integer.MAX_VALUE)));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
- -123)));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(+0.0f,
- 0)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f,
- 123)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-0.0f,
- Integer.MIN_VALUE)));
-
- assertEquals(Float.MIN_VALUE, StrictMath.scalb(1.0f, -149));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(1.0f,
- -150)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(-1.0f,
- -150)));
-
- // precision lost
- assertEquals(StrictMath.scalb(21.405f, -154), StrictMath.scalb(21.405f,
- -153));
- assertEquals(Float.MIN_VALUE, StrictMath.scalb(21.405f, -154));
- assertEquals(-Float.MIN_VALUE, StrictMath.scalb(-21.405f, -154));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
- 21.405f, -155)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
- -21.405f, -155)));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
- Float.MIN_VALUE, -1)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
- -Float.MIN_VALUE, -1)));
- assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL, -23));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
- Float.MIN_NORMAL, -24)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
- -Float.MIN_NORMAL, -24)));
- assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MAX_VALUE, -277));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
- Float.MAX_VALUE, -278)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
- -Float.MAX_VALUE, -278)));
- assertEquals(Float.MIN_VALUE, StrictMath.scalb(Float.MIN_NORMAL / 3,
- -22));
- assertEquals(posZeroBits, Float.floatToIntBits(StrictMath.scalb(
- Float.MIN_NORMAL / 3, -23)));
- assertEquals(negZeroBits, Float.floatToIntBits(StrictMath.scalb(
- -Float.MIN_NORMAL / 3, -23)));
- float subnormal = StrictMath.scalb(Float.MIN_NORMAL / 3, -11);
- assertEquals(1.913E-42f, subnormal);
- // precision lost
- assertFalse(Float.MIN_NORMAL / 3 == StrictMath.scalb(subnormal, 11));
-
- assertEquals(68747264, Float.floatToIntBits(StrictMath.scalb(
- Float.MIN_VALUE * 153, 23)));
- assertEquals(-2078736384, Float.floatToIntBits(StrictMath.scalb(
- -Float.MIN_VALUE * 153, 23)));
-
- assertEquals(4896, Float.floatToIntBits(StrictMath.scalb(
- Float.MIN_VALUE * 153, 5)));
- assertEquals(-2147478752, Float.floatToIntBits(StrictMath.scalb(
- -Float.MIN_VALUE * 153, 5)));
-
- // NaN
- assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 1)));
- assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, 0)));
- assertTrue(Float.isNaN(StrictMath.scalb(Float.NaN, -120)));
-
- // test for exception
- try {
- StrictMath.scalb((Float) null, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.scalb(1.0f, (Integer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- try {
- StrictMath.scalb((Float) null, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StrictMath#signum(double)
- */
- public void test_signum_D() {
- assertTrue(Double.isNaN(StrictMath.signum(Double.NaN)));
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.signum(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.signum(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.signum(-0.0)));
-
- assertEquals(1.0, StrictMath.signum(253681.2187962), 0D);
- assertEquals(-1.0, StrictMath.signum(-125874693.56), 0D);
- assertEquals(1.0, StrictMath.signum(1.2587E-308), 0D);
- assertEquals(-1.0, StrictMath.signum(-1.2587E-308), 0D);
-
- assertEquals(1.0, StrictMath.signum(Double.MAX_VALUE), 0D);
- assertEquals(1.0, StrictMath.signum(Double.MIN_VALUE), 0D);
- assertEquals(-1.0, StrictMath.signum(-Double.MAX_VALUE), 0D);
- assertEquals(-1.0, StrictMath.signum(-Double.MIN_VALUE), 0D);
- assertEquals(1.0, StrictMath.signum(Double.POSITIVE_INFINITY), 0D);
- assertEquals(-1.0, StrictMath.signum(Double.NEGATIVE_INFINITY), 0D);
-
- }
-
- /**
- * @tests java.lang.StrictMath#signum(float)
- */
- public void test_signum_F() {
- assertTrue(Float.isNaN(StrictMath.signum(Float.NaN)));
- assertEquals(Float.floatToIntBits(0.0f), Float
- .floatToIntBits(StrictMath.signum(0.0f)));
- assertEquals(Float.floatToIntBits(+0.0f), Float
- .floatToIntBits(StrictMath.signum(+0.0f)));
- assertEquals(Float.floatToIntBits(-0.0f), Float
- .floatToIntBits(StrictMath.signum(-0.0f)));
-
- assertEquals(1.0f, StrictMath.signum(253681.2187962f), 0f);
- assertEquals(-1.0f, StrictMath.signum(-125874693.56f), 0f);
- assertEquals(1.0f, StrictMath.signum(1.2587E-11f), 0f);
- assertEquals(-1.0f, StrictMath.signum(-1.2587E-11f), 0f);
-
- assertEquals(1.0f, StrictMath.signum(Float.MAX_VALUE), 0f);
- assertEquals(1.0f, StrictMath.signum(Float.MIN_VALUE), 0f);
- assertEquals(-1.0f, StrictMath.signum(-Float.MAX_VALUE), 0f);
- assertEquals(-1.0f, StrictMath.signum(-Float.MIN_VALUE), 0f);
- assertEquals(1.0f, StrictMath.signum(Float.POSITIVE_INFINITY), 0f);
- assertEquals(-1.0f, StrictMath.signum(Float.NEGATIVE_INFINITY), 0f);
- }
-
- /**
- * @tests java.lang.StrictMath#sin(double)
- */
- public void test_sinD() {
- // Test for method double java.lang.StrictMath.sin(double)
- assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
- .asin(OPP / HYP)) == OPP / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#sinh(double)
- */
- public void test_sinh_D() {
- // Test for special situations
- assertTrue(Double.isNaN(StrictMath.sinh(Double.NaN)));
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath
- .sinh(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath
- .sinh(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.sinh(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.sinh(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.sinh(-0.0)));
-
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.sinh(1234.56), 0D);
- assertEquals("Should return NEGATIVE_INFINITY",
- Double.NEGATIVE_INFINITY, StrictMath.sinh(-1234.56), 0D);
- assertEquals("Should return 1.0000000000001666E-6",
- 1.0000000000001666E-6, StrictMath.sinh(0.000001), 0D);
- assertEquals("Should return -1.0000000000001666E-6",
- -1.0000000000001666E-6, StrictMath.sinh(-0.000001), 0D);
- assertEquals("Should return 5.115386441963859", 5.115386441963859,
- StrictMath.sinh(2.33482), 0D);
- assertEquals("Should return POSITIVE_INFINITY",
- Double.POSITIVE_INFINITY, StrictMath.sinh(Double.MAX_VALUE), 0D);
- assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
- .sinh(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.StrictMath#sqrt(double)
- */
- public void test_sqrtD() {
- // Test for method double java.lang.StrictMath.sqrt(double)
- assertEquals("Incorrect root returned1",
- 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
- assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
- }
-
- /**
- * @tests java.lang.StrictMath#tan(double)
- */
- public void test_tanD() {
- // Test for method double java.lang.StrictMath.tan(double)
- assertTrue(
- "Returned incorrect tangent: ",
- StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
- || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#tanh(double)
- */
- public void test_tanh_D() {
- // Test for special situations
- assertTrue(Double.isNaN(StrictMath.tanh(Double.NaN)));
- assertEquals("Should return +1.0", +1.0, StrictMath
- .tanh(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Should return -1.0", -1.0, StrictMath
- .tanh(Double.NEGATIVE_INFINITY), 0D);
- assertEquals(Double.doubleToLongBits(0.0), Double
- .doubleToLongBits(StrictMath.tanh(0.0)));
- assertEquals(Double.doubleToLongBits(+0.0), Double
- .doubleToLongBits(StrictMath.tanh(+0.0)));
- assertEquals(Double.doubleToLongBits(-0.0), Double
- .doubleToLongBits(StrictMath.tanh(-0.0)));
-
- assertEquals("Should return 1.0", 1.0, StrictMath.tanh(1234.56), 0D);
- assertEquals("Should return -1.0", -1.0, StrictMath.tanh(-1234.56), 0D);
- assertEquals("Should return 9.999999999996666E-7",
- 9.999999999996666E-7, StrictMath.tanh(0.000001), 0D);
- assertEquals("Should return 0.981422884124941", 0.981422884124941,
- StrictMath.tanh(2.33482), 0D);
- assertEquals("Should return 1.0", 1.0, StrictMath
- .tanh(Double.MAX_VALUE), 0D);
- assertEquals("Should return 4.9E-324", 4.9E-324, StrictMath
- .tanh(Double.MIN_VALUE), 0D);
- }
-
- /**
- * @tests java.lang.StrictMath#random()
- */
- public void test_random() {
- // There isn't a place for these tests so just stick them here
- assertEquals("Wrong value E",
- 4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
- assertEquals("Wrong value PI",
- 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
-
- for (int i = 500; i >= 0; i--) {
- double d = StrictMath.random();
- assertTrue("Generated number is out of range: " + d, d >= 0.0
- && d < 1.0);
- }
- }
-
- /**
- * @tests java.lang.StrictMath#toRadians(double)
- */
- public void test_toRadiansD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * @tests java.lang.StrictMath#toDegrees(double)
- */
- public void test_toDegreesD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * @tests java.lang.StrictMath#ulp(double)
- */
- @SuppressWarnings("boxing")
- public void test_ulp_D() {
- // Test for special cases
- assertTrue("Should return NaN", Double
- .isNaN(StrictMath.ulp(Double.NaN)));
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
- StrictMath.ulp(Double.POSITIVE_INFINITY), 0D);
- assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY,
- StrictMath.ulp(Double.NEGATIVE_INFINITY), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
- .ulp(0.0), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
- .ulp(+0.0), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
- .ulp(-0.0), 0D);
- assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
- StrictMath.ulp(Double.MAX_VALUE), 0D);
- assertEquals("Returned incorrect value", StrictMath.pow(2, 971),
- StrictMath.ulp(-Double.MAX_VALUE), 0D);
-
- assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
- .ulp(Double.MIN_VALUE), 0D);
- assertEquals("Returned incorrect value", Double.MIN_VALUE, StrictMath
- .ulp(-Double.MIN_VALUE), 0D);
-
- assertEquals("Returned incorrect value", 2.220446049250313E-16,
- StrictMath.ulp(1.0), 0D);
- assertEquals("Returned incorrect value", 2.220446049250313E-16,
- StrictMath.ulp(-1.0), 0D);
- assertEquals("Returned incorrect value", 2.2737367544323206E-13,
- StrictMath.ulp(1153.0), 0D);
- }
-
- /**
- * @tests java.lang.StrictMath#ulp(float)
- */
- @SuppressWarnings("boxing")
- public void test_ulp_f() {
- // Test for special cases
- assertTrue("Should return NaN", Float.isNaN(StrictMath.ulp(Float.NaN)));
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
- StrictMath.ulp(Float.POSITIVE_INFINITY), 0f);
- assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY,
- StrictMath.ulp(Float.NEGATIVE_INFINITY), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
- .ulp(0.0f), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
- .ulp(+0.0f), 0f);
- assertEquals("Returned incorrect value", Float.MIN_VALUE, StrictMath
- .ulp(-0.0f), 0f);
- assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
- .ulp(Float.MAX_VALUE), 0f);
- assertEquals("Returned incorrect value", 2.028241E31f, StrictMath
- .ulp(-Float.MAX_VALUE), 0f);
-
- assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
- .ulp(Float.MIN_VALUE), 0f);
- assertEquals("Returned incorrect value", 1.4E-45f, StrictMath
- .ulp(-Float.MIN_VALUE), 0f);
-
- assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
- .ulp(1.0f), 0f);
- assertEquals("Returned incorrect value", 1.1920929E-7f, StrictMath
- .ulp(-1.0f), 0f);
- assertEquals("Returned incorrect value", 1.2207031E-4f, StrictMath
- .ulp(1153.0f), 0f);
- assertEquals("Returned incorrect value", 5.6E-45f, Math
- .ulp(9.403954E-38f), 0f);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java
deleted file mode 100644
index 0fa41b9..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuffer2Test.java
+++ /dev/null
@@ -1,1106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(StringBuffer.class)
-public class StringBuffer2Test extends junit.framework.TestCase {
-
- StringBuffer testBuffer;
-
- /**
- * @tests java.lang.StringBuffer#StringBuffer()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringBuffer",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.lang.StringBuffer()
- new StringBuffer();
- assertTrue("Invalid buffer created", true);
- }
-
- /**
- * @tests java.lang.StringBuffer#StringBuffer(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringBuffer",
- args = {int.class}
- )
- public void test_ConstructorI() {
- // Test for method java.lang.StringBuffer(int)
- StringBuffer sb = new StringBuffer(8);
- assertEquals("Newly constructed buffer is of incorrect length", 0, sb
- .length());
- }
-
- /**
- * @tests java.lang.StringBuffer#StringBuffer(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringBuffer",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.lang.StringBuffer(java.lang.String)
-
- StringBuffer sb = new StringBuffer("HelloWorld");
-
- assertTrue("Invalid buffer created", sb.length() == 10
- && (sb.toString().equals("HelloWorld")));
-
- boolean pass = false;
- try {
- new StringBuffer(null);
- } catch (NullPointerException e) {
- pass = true;
- }
- assertTrue("Should throw NullPointerException", pass);
- }
-
- /**
- * @tests java.lang.StringBuffer#append(char[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char[].class}
- )
- public void test_append$C() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(char [])
- char buf[] = new char[4];
- "char".getChars(0, 4, buf, 0);
- testBuffer.append(buf);
- assertEquals("Append of char[] failed",
- "This is a test bufferchar", testBuffer.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#append(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "append",
- args = {char[].class, int.class, int.class}
- )
- public void test_append$CII() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(char [], int, int)
- StringBuffer sb = new StringBuffer();
- char[] buf1 = { 'H', 'e', 'l', 'l', 'o' };
- char[] buf2 = { 'W', 'o', 'r', 'l', 'd' };
- sb.append(buf1, 0, buf1.length);
- assertEquals("Buffer is invalid length after append", 5, sb.length());
- sb.append(buf2, 0, buf2.length);
- assertEquals("Buffer is invalid length after append", 10, sb.length());
- assertTrue("Buffer contains invalid chars", (sb.toString()
- .equals("HelloWorld")));
- }
-
- /**
- * @tests java.lang.StringBuffer#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
- public void test_appendC() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(char)
- StringBuffer sb = new StringBuffer();
- char buf1 = 'H';
- char buf2 = 'W';
- sb.append(buf1);
- assertEquals("Buffer is invalid length after append", 1, sb.length());
- sb.append(buf2);
- assertEquals("Buffer is invalid length after append", 2, sb.length());
- assertTrue("Buffer contains invalid chars",
- (sb.toString().equals("HW")));
- }
-
- /**
- * @tests java.lang.StringBuffer#append(double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {double.class}
- )
- public void test_appendD() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(double)
- StringBuffer sb = new StringBuffer();
- sb.append(Double.MAX_VALUE);
- assertEquals("Buffer is invalid length after append", 22, sb.length());
- assertEquals("Buffer contains invalid characters",
- "1.7976931348623157E308", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#append(float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {float.class}
- )
- public void test_appendF() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(float)
- StringBuffer sb = new StringBuffer();
- final float floatNum = 900.87654F;
- sb.append(floatNum);
- assertTrue("Buffer is invalid length after append: " + sb.length(), sb
- .length() == String.valueOf(floatNum).length());
- assertTrue("Buffer contains invalid characters", sb.toString().equals(
- String.valueOf(floatNum)));
- }
-
- /**
- * @tests java.lang.StringBuffer#append(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {int.class}
- )
- public void test_appendI() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(int)
- StringBuffer sb = new StringBuffer();
- sb.append(9000);
- assertEquals("Buffer is invalid length after append", 4, sb.length());
- sb.append(1000);
- assertEquals("Buffer is invalid length after append", 8, sb.length());
- assertEquals("Buffer contains invalid characters",
- "90001000", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#append(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {long.class}
- )
- public void test_appendJ() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(long)
-
- StringBuffer sb = new StringBuffer();
- long t = 927654321098L;
- sb.append(t);
- assertEquals("Buffer is of invlaid length", 12, sb.length());
- assertEquals("Buffer contains invalid characters",
- "927654321098", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#append(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.Object.class}
- )
- public void test_appendLjava_lang_Object() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(java.lang.Object)
- StringBuffer sb = new StringBuffer();
- Object obj1 = new Object();
- Object obj2 = new Object();
- sb.append(obj1);
- sb.append(obj2);
- assertTrue("Buffer contains invalid characters", sb.toString().equals(
- obj1.toString() + obj2.toString()));
- }
-
- /**
- * @tests java.lang.StringBuffer#append(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.String.class}
- )
- public void test_appendLjava_lang_String() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(java.lang.String)
- StringBuffer sb = new StringBuffer();
- String buf1 = "Hello";
- String buf2 = "World";
- sb.append(buf1);
- assertEquals("Buffer is invalid length after append", 5, sb.length());
- sb.append(buf2);
- assertEquals("Buffer is invalid length after append", 10, sb.length());
- assertTrue("Buffer contains invalid chars", (sb.toString()
- .equals("HelloWorld")));
- }
-
- /**
- * @tests java.lang.StringBuffer#append(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {boolean.class}
- )
- public void test_appendZ() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.append(boolean)
- StringBuffer sb = new StringBuffer();
- sb.append(false);
- assertEquals("Buffer is invalid length after append", 5, sb.length());
- sb.append(true);
- assertEquals("Buffer is invalid length after append", 9, sb.length());
- assertTrue("Buffer is invalid length after append", (sb.toString()
- .equals("falsetrue")));
- }
-
- /**
- * @tests java.lang.StringBuffer#capacity()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "capacity",
- args = {}
- )
- public void test_capacity() {
- // Test for method int java.lang.StringBuffer.capacity()
- StringBuffer sb = new StringBuffer(10);
- assertEquals("Returned incorrect capacity", 10, sb.capacity());
- sb.ensureCapacity(100);
- assertTrue("Returned incorrect capacity", sb.capacity() >= 100);
- }
-
- /**
- * @tests java.lang.StringBuffer#charAt(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "charAt",
- args = {int.class}
- )
- public void test_charAtI() {
- // Test for method char java.lang.StringBuffer.charAt(int)
- assertEquals("Returned incorrect char", 's', testBuffer.charAt(3));
-
- // Test for StringIndexOutOfBoundsException
- boolean exception = false;
- try {
- testBuffer.charAt(-1);
- } catch (StringIndexOutOfBoundsException e) {
- exception = true;
- } catch (ArrayIndexOutOfBoundsException e) {
- }
- assertTrue("Should throw StringIndexOutOfBoundsException", exception);
- }
-
- /**
- * @tests java.lang.StringBuffer#delete(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "delete",
- args = {int.class, int.class}
- )
- public void test_deleteII() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.delete(int, int)
- testBuffer.delete(7, 7);
- assertEquals("Deleted chars when start == end", "This is a test buffer", testBuffer.toString()
- );
- testBuffer.delete(4, 14);
- assertEquals("Deleted incorrect chars",
- "This buffer", testBuffer.toString());
-
- testBuffer = new StringBuffer("This is a test buffer");
- String sharedStr = testBuffer.toString();
- testBuffer.delete(0, testBuffer.length());
- assertEquals("Didn't clone shared buffer", "This is a test buffer", sharedStr
- );
- assertTrue("Deleted incorrect chars", testBuffer.toString().equals(""));
- testBuffer.append("more stuff");
- assertEquals("Didn't clone shared buffer 2", "This is a test buffer", sharedStr
- );
- assertEquals("Wrong contents", "more stuff", testBuffer.toString());
- try {
- testBuffer.delete(-5, 2);
- } catch (IndexOutOfBoundsException e) {
- }
- assertEquals("Wrong contents 2",
- "more stuff", testBuffer.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#deleteCharAt(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "deleteCharAt",
- args = {int.class}
- )
- public void test_deleteCharAtI() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.deleteCharAt(int)
- testBuffer.deleteCharAt(3);
- assertEquals("Deleted incorrect char",
- "Thi is a test buffer", testBuffer.toString());
- try {
- testBuffer.deleteCharAt(testBuffer.length() + 1);
- fail("StringIndexOutOfBoundsException was not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.deleteCharAt(-1);
- fail("StringIndexOutOfBoundsException was not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#ensureCapacity(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ensureCapacity",
- args = {int.class}
- )
- public void test_ensureCapacityI() {
- // Test for method void java.lang.StringBuffer.ensureCapacity(int)
- StringBuffer sb = new StringBuffer(10);
-
- sb.ensureCapacity(-2);
- assertEquals("Failed to increase capacity.", 10, sb.capacity());
-
- sb.ensureCapacity(100);
- assertTrue("Failed to increase capacity", sb.capacity() >= 100);
-
- try {
- sb.ensureCapacity(Integer.MAX_VALUE);
- fail("OutOfMemoryError should be thrown.");
- } catch(java.lang.OutOfMemoryError oome) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#getChars(int, int, char[], int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't check exceptions.",
- method = "getChars",
- args = {int.class, int.class, char[].class, int.class}
- )
- public void test_getCharsII$CI() {
- // Test for method void java.lang.StringBuffer.getChars(int, int, char
- // [], int)
-
- char[] buf = new char[10];
- testBuffer.getChars(4, 8, buf, 2);
- assertTrue("Returned incorrect chars", new String(buf, 2, 4)
- .equals(testBuffer.toString().substring(4, 8)));
-
- StringBuffer buf2 = new StringBuffer("");
- try {
- buf2.getChars(-1, 0, new char[5], 2);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- buf2.getChars(0, -1, new char[5], 2);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- buf2.getChars(0, -1, new char[5], 2);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- buf2.getChars(2, 1, new char[5], 2);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- buf2.getChars(0, 6, new char[5], 2);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- buf2.getChars(0, 6, new char[10], 5);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, char[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, char[].class}
- )
- public void test_insertI$C() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, char [])
- char buf[] = new char[4];
- "char".getChars(0, 4, buf, 0);
- testBuffer.insert(15, buf);
- assertEquals("Insert test failed",
- "This is a test charbuffer", testBuffer.toString());
-
- boolean exception = false;
- StringBuffer buf1 = new StringBuffer("abcd");
- try {
- buf1.insert(-1, (char[]) null);
- } catch (StringIndexOutOfBoundsException e) {
- exception = true;
- } catch (NullPointerException e) {
- }
- assertTrue("Should throw StringIndexOutOfBoundsException", exception);
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, char[].class, int.class, int.class}
- )
- public void test_insertI$CII() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, char [], int, int)
- char[] c = new char[] { 'n', 'o', 't', ' ' };
- testBuffer.insert(8, c, 0, 4);
- assertEquals("This is not a test buffer", testBuffer.toString());
-
- StringBuffer buf1 = new StringBuffer("abcd");
- try {
- buf1.insert(-1, (char[]) null, 0, 0);
- fail("Should throw StringIndexOutOfBoundsException");
- } catch (StringIndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() - 1, c, -1, 1);
- } catch (StringIndexOutOfBoundsException e) {
- //expected
- }
-
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, char)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IndexOutOfBoundsException is not verified.",
- method = "insert",
- args = {int.class, char.class}
- )
- public void test_insertIC() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, char)
- testBuffer.insert(15, 'T');
- assertEquals("Insert test failed",
- "This is a test Tbuffer", testBuffer.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, double)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, double.class}
- )
- public void test_insertID() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, double)
- testBuffer.insert(15, Double.MAX_VALUE);
- assertTrue("Insert test failed", testBuffer.toString().equals(
- "This is a test " + Double.MAX_VALUE + "buffer"));
- try {
- testBuffer.insert(-1, Double.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, Double.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, float)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, float.class}
- )
- public void test_insertIF() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, float)
- testBuffer.insert(15, Float.MAX_VALUE);
- String testBufferString = testBuffer.toString();
- String expectedResult = "This is a test "
- + String.valueOf(Float.MAX_VALUE) + "buffer";
- assertTrue("Insert test failed, got: " + "\'" + testBufferString + "\'"
- + " but wanted: " + "\'" + expectedResult + "\'",
- testBufferString.equals(expectedResult));
-
- try {
- testBuffer.insert(-1, Float.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, Float.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, int.class}
- )
- public void test_insertII() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, int)
- testBuffer.insert(15, 100);
- assertEquals("Insert test failed",
- "This is a test 100buffer", testBuffer.toString());
-
- try {
- testBuffer.insert(-1, Integer.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, Integer.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, long.class}
- )
- public void test_insertIJ() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, long)
- testBuffer.insert(15, 88888888888888888L);
- assertEquals("Insert test failed",
- "This is a test 88888888888888888buffer", testBuffer.toString());
-
- try {
- testBuffer.insert(-1, Long.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, Long.MAX_VALUE);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, java.lang.Object.class}
- )
- public void test_insertILjava_lang_Object() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, java.lang.Object)
- Object obj1 = new Object();
- testBuffer.insert(15, obj1);
- assertTrue("Insert test failed", testBuffer.toString().equals(
- "This is a test " + obj1.toString() + "buffer"));
-
- try {
- testBuffer.insert(-1, obj1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, obj1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, java.lang.String.class}
- )
- public void test_insertILjava_lang_String() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, java.lang.String)
-
- testBuffer.insert(15, "STRING ");
- assertEquals("Insert test failed",
- "This is a test STRING buffer", testBuffer.toString());
-
- try {
- testBuffer.insert(-1, "");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(testBuffer.length() + 1, "");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#insert(int, boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "insert",
- args = {int.class, boolean.class}
- )
- public void test_insertIZ() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.insert(int, boolean)
- testBuffer.insert(15, true);
- assertEquals("Insert test failed",
- "This is a test truebuffer", testBuffer.toString());
- try {
- testBuffer.insert(testBuffer.length() + 1, true);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.insert(-1, true);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#length()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "length",
- args = {}
- )
- public void test_length() {
- // Test for method int java.lang.StringBuffer.length()
- assertEquals("Incorrect length returned", 21, testBuffer.length());
- }
-
- /**
- * @tests java.lang.StringBuffer#replace(int, int, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "replace",
- args = {int.class, int.class, java.lang.String.class}
- )
- public void test_replaceIILjava_lang_String() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.replace(int, int, java.lang.String)
- testBuffer.replace(5, 9, "is a replaced");
- assertTrue("Replace failed, wanted: " + "\'"
- + "This is a replaced test buffer" + "\'" + " but got: " + "\'"
- + testBuffer.toString() + "\'", testBuffer.toString().equals(
- "This is a replaced test buffer"));
- assertEquals("insert1", "text", new StringBuffer().replace(0, 0, "text")
- .toString());
- assertEquals("insert2", "123text", new StringBuffer("123").replace(3, 3, "text")
- .toString());
- assertEquals("insert2", "1text23", new StringBuffer("123").replace(1, 1, "text")
- .toString());
-
- try {
- testBuffer.replace(-1, 0, "text");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.replace(0, -1, "text");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.replace(2, 1, "text");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
-
- try {
- testBuffer.replace(testBuffer.length() + 1, testBuffer.length() + 1,
- "text");
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException sioobe) {
- //expected
- }
- }
-
- private String writeString(String in) {
- StringBuffer result = new StringBuffer();
- result.append("\"");
- for (int i = 0; i < in.length(); i++) {
- result.append(" 0x" + Integer.toHexString(in.charAt(i)));
- }
- result.append("\"");
- return result.toString();
- }
-
- private void reverseTest(String id, String org, String rev, String back) {
- // create non-shared StringBuffer
- StringBuffer sb = new StringBuffer(org);
- sb.reverse();
- String reversed = sb.toString();
- assertTrue("reversed surrogate " + id + ": " + writeString(reversed),
- reversed.equals(rev));
- // create non-shared StringBuffer
- sb = new StringBuffer(reversed);
- sb.reverse();
- reversed = sb.toString();
- assertTrue("reversed surrogate " + id + "a: " + writeString(reversed),
- reversed.equals(back));
-
- // test algorithm when StringBuffer is shared
- sb = new StringBuffer(org);
- String copy = sb.toString();
- assertEquals(org, copy);
- sb.reverse();
- reversed = sb.toString();
- assertTrue("reversed surrogate " + id + ": " + writeString(reversed),
- reversed.equals(rev));
- sb = new StringBuffer(reversed);
- copy = sb.toString();
- assertEquals(rev, copy);
- sb.reverse();
- reversed = sb.toString();
- assertTrue("reversed surrogate " + id + "a: " + writeString(reversed),
- reversed.equals(back));
-
- }
-
- /**
- * @tests java.lang.StringBuffer#reverse()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reverse",
- args = {}
- )
- public void test_reverse() {
- // Test for method java.lang.StringBuffer
- // java.lang.StringBuffer.reverse()
- String org;
- org = "a";
- reverseTest("0", org, org, org);
-
- org = "ab";
- reverseTest("1", org, "ba", org);
-
- org = "abcdef";
- reverseTest("2", org, "fedcba", org);
-
- org = "abcdefg";
- reverseTest("3", org, "gfedcba", org);
-
- }
-
- /**
- * @tests java.lang.StringBuffer#setCharAt(int, char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setCharAt",
- args = {int.class, char.class}
- )
- public void test_setCharAtIC() {
- // Test for method void java.lang.StringBuffer.setCharAt(int, char)
- StringBuffer s = new StringBuffer("HelloWorld");
- s.setCharAt(4, 'Z');
- assertEquals("Returned incorrect char", 'Z', s.charAt(4));
-
- try {
- s.setCharAt(-1, 'Z');
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
- try {
- s.setCharAt(s.length() + 1, 'Z');
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#setLength(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IndexOutOfBoundsException is not verified.",
- method = "setLength",
- args = {int.class}
- )
- public void test_setLengthI() {
- // Test for method void java.lang.StringBuffer.setLength(int)
- testBuffer.setLength(1000);
- assertEquals("Failed to increase length", 1000, testBuffer.length());
- assertTrue("Increase in length trashed buffer", testBuffer.toString()
- .startsWith("This is a test buffer"));
- testBuffer.setLength(2);
- assertEquals("Failed to decrease length", 2, testBuffer.length());
- assertEquals("Decrease in length failed",
- "Th", testBuffer.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer#substring(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "substring",
- args = {int.class}
- )
- public void test_substringI() {
- // Test for method java.lang.String
- // java.lang.StringBuffer.substring(int)
- assertEquals("Returned incorrect substring", "is a test buffer",
- testBuffer.substring(5));
-
- try {
- testBuffer.substring(testBuffer.length() + 1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException oobe) {
- //expected
- }
-
- try {
- testBuffer.substring(-1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException oobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#substring(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "substring",
- args = {int.class, int.class}
- )
- public void test_substringII() {
- // Test for method java.lang.String
- // java.lang.StringBuffer.substring(int, int)
- assertEquals("Returned incorrect substring", "is",
- testBuffer.substring(5, 7));
-
- try {
- testBuffer.substring(-1, testBuffer.length());
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException oobe) {
- //expected
- }
-
- try {
- testBuffer.substring(0, -1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException oobe) {
- //expected
- }
-
- try {
- testBuffer.substring(2, 1);
- fail("StringIndexOutOfBoundsException is not thrown.");
- } catch(StringIndexOutOfBoundsException oobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.lang.StringBuffer.toString()
- assertEquals("Incorrect string value returned", "This is a test buffer", testBuffer.toString()
- );
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "subSequence",
- args = {int.class, int.class}
- )
- public void test_subSequence() {
-
- assertEquals("Incorrect substring returned", " is",
- testBuffer.subSequence(4, 7));
- assertEquals("Incorrect substring returned", "test buffer",
- testBuffer.subSequence(10, 21));
- assertEquals("not identical", "This is a test buffer",
- testBuffer.subSequence(0, testBuffer.length()));
-
- try {
- testBuffer.subSequence(0, Integer.MAX_VALUE);
- fail("IndexOutOfBoundsException was not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- testBuffer.subSequence(Integer.MAX_VALUE, testBuffer.length());
- fail("IndexOutOfBoundsException was not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- testBuffer.subSequence(-1, testBuffer.length());
- fail("IndexOutOfBoundsException was not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
- }
-
- @Override
- protected void setUp() {
- testBuffer = new StringBuffer("This is a test buffer");
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBufferTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBufferTest.java
deleted file mode 100644
index c5499e7..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBufferTest.java
+++ /dev/null
@@ -1,622 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.Serializable;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class StringBufferTest extends TestCase {
-
- /**
- * @tests java.lang.StringBuffer#setLength(int)
- */
- public void test_setLengthI() {
- // Regression for HARMONY-90
- StringBuffer buffer = new StringBuffer("abcde");
- try {
- buffer.setLength(-1);
- fail("Assert 0: IndexOutOfBoundsException must be thrown");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- assertEquals("abcde", buffer.toString());
- buffer.setLength(1);
- buffer.append('f');
- assertEquals("af", buffer.toString());
-
- buffer = new StringBuffer("abcde");
- assertEquals("cde", buffer.substring(2));
- buffer.setLength(3);
- buffer.append('f');
- assertEquals("abcf", buffer.toString());
-
- buffer = new StringBuffer("abcde");
- buffer.setLength(2);
- try {
- buffer.charAt(3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- buffer = new StringBuffer();
- buffer.append("abcdefg");
- buffer.setLength(2);
- buffer.setLength(5);
- for (int i = 2; i < 5; i++) {
- assertEquals(0, buffer.charAt(i));
- }
-
- buffer = new StringBuffer();
- buffer.append("abcdefg");
- buffer.delete(2, 4);
- buffer.setLength(7);
- assertEquals('a', buffer.charAt(0));
- assertEquals('b', buffer.charAt(1));
- assertEquals('e', buffer.charAt(2));
- assertEquals('f', buffer.charAt(3));
- assertEquals('g', buffer.charAt(4));
- for (int i = 5; i < 7; i++) {
- assertEquals(0, buffer.charAt(i));
- }
-
- buffer = new StringBuffer();
- buffer.append("abcdefg");
- buffer.replace(2, 5, "z");
- buffer.setLength(7);
- for (int i = 5; i < 7; i++) {
- assertEquals(0, buffer.charAt(i));
- }
- }
-
- /**
- * @tests java.lang.StringBuffer#toString()
- */
- public void test_toString() throws Exception {
- StringBuffer buffer = new StringBuffer();
- assertEquals("", buffer.toString());
-
- buffer.append("abcde");
- assertEquals("abcde", buffer.toString());
- buffer.setLength(1000);
- byte[] bytes = buffer.toString().getBytes("GB18030");
- for (int i = 5; i < bytes.length; i++) {
- assertEquals(0, bytes[i]);
- }
-
- buffer.setLength(5);
- buffer.append("fghij");
- assertEquals("abcdefghij", buffer.toString());
- }
-
- /**
- * @tests StringBuffer.StringBuffer(CharSequence);
- */
- public void test_constructorLjava_lang_CharSequence() {
- try {
- new StringBuffer((CharSequence) null);
- fail("Assert 0: NPE must be thrown.");
- } catch (NullPointerException e) {}
-
- assertEquals("Assert 1: must equal 'abc'.", "abc", new StringBuffer((CharSequence)"abc").toString());
- }
-
- public void test_trimToSize() {
- StringBuffer buffer = new StringBuffer(25);
- buffer.append("abc");
- int origCapacity = buffer.capacity();
- buffer.trimToSize();
- int trimCapacity = buffer.capacity();
- assertTrue("Assert 0: capacity must be smaller.", trimCapacity < origCapacity);
- assertEquals("Assert 1: length must still be 3", 3, buffer.length());
- assertEquals("Assert 2: value must still be 'abc'.", "abc", buffer.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer.append(CharSequence)
- */
- public void test_appendLjava_lang_CharSequence() {
- StringBuffer sb = new StringBuffer();
- assertSame(sb, sb.append((CharSequence) "ab"));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "cd"));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) null));
- assertEquals("null", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer.append(CharSequence, int, int)
- */
- @SuppressWarnings("cast")
- public void test_appendLjava_lang_CharSequenceII() {
- StringBuffer sb = new StringBuffer();
- assertSame(sb, sb.append((CharSequence) "ab", 0, 2));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "cd", 0, 2));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "abcd", 0, 2));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "abcd", 2, 4));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) null, 0, 2));
- assertEquals("nu", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer.append(char[], int, int)
- */
- public void test_append$CII_2() {
- StringBuffer obj = new StringBuffer();
- try {
- obj.append(new char[0], -1, -1);
- fail("ArrayIndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.append(char[], int, int)
- */
- public void test_append$CII_3() throws Exception {
- StringBuffer obj = new StringBuffer();
- try {
- obj.append((char[]) null, -1, -1);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.insert(int, CharSequence)
- */
- public void test_insertILjava_lang_CharSequence() {
- final String fixture = "0000";
- StringBuffer sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab"));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab"));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab"));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) null));
- assertEquals("0000null", sb.toString());
- assertEquals(8, sb.length());
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(-1, (CharSequence) "ab");
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(5, (CharSequence) "ab");
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.insert(int, CharSequence, int, int)
- */
- @SuppressWarnings("cast")
- public void test_insertILjava_lang_CharSequenceII() {
- final String fixture = "0000";
- StringBuffer sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 2));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 1));
- assertEquals("a0000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 2));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 1));
- assertEquals("00a00", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 2));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 1));
- assertEquals("0000a", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuffer(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) null, 0, 2));
- assertEquals("0000nu", sb.toString());
- assertEquals(6, sb.length());
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(-1, (CharSequence) "ab", 0, 2);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(5, (CharSequence) "ab", 0, 2);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(5, (CharSequence) "ab", -1, 2);
- fail("no IOOBE, negative offset");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
- fail("no IOOBE, negative length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuffer(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
- fail("no IOOBE, too long");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.insert(int, char)
- */
- public void test_insertIC() {
- StringBuffer obj = new StringBuffer();
- try {
- obj.insert(-1, ' ');
- fail("ArrayIndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.appendCodePoint(int)'
- */
- public void test_appendCodePointI() {
- StringBuffer sb = new StringBuffer();
- sb.appendCodePoint(0x10000);
- assertEquals("\uD800\uDC00", sb.toString());
- sb.append("fixture");
- assertEquals("\uD800\uDC00fixture", sb.toString());
- sb.appendCodePoint(0x00010FFFF);
- assertEquals("\uD800\uDC00fixture\uDBFF\uDFFF", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuffer.codePointAt(int)
- */
- public void test_codePointAtI() {
- StringBuffer sb = new StringBuffer("abc");
- assertEquals('a', sb.codePointAt(0));
- assertEquals('b', sb.codePointAt(1));
- assertEquals('c', sb.codePointAt(2));
-
- sb = new StringBuffer("\uD800\uDC00");
- assertEquals(0x10000, sb.codePointAt(0));
- assertEquals('\uDC00', sb.codePointAt(1));
-
- try {
- sb.codePointAt(-1);
- fail("No IOOBE on negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointAt(sb.length());
- fail("No IOOBE on index equal to length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointAt(sb.length() + 1);
- fail("No IOOBE on index greater than length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.codePointBefore(int)
- */
- public void test_codePointBeforeI() {
- StringBuffer sb = new StringBuffer("abc");
- assertEquals('a', sb.codePointBefore(1));
- assertEquals('b', sb.codePointBefore(2));
- assertEquals('c', sb.codePointBefore(3));
-
- sb = new StringBuffer("\uD800\uDC00");
- assertEquals(0x10000, sb.codePointBefore(2));
- assertEquals('\uD800', sb.codePointBefore(1));
-
- try {
- sb.codePointBefore(0);
- fail("No IOOBE on zero index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointBefore(-1);
- fail("No IOOBE on negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointBefore(sb.length() + 1);
- fail("No IOOBE on index greater than length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.codePointCount(int, int)
- */
- public void test_codePointCountII() {
- assertEquals(1, new StringBuffer("\uD800\uDC00").codePointCount(0, 2));
- assertEquals(1, new StringBuffer("\uD800\uDC01").codePointCount(0, 2));
- assertEquals(1, new StringBuffer("\uD801\uDC01").codePointCount(0, 2));
- assertEquals(1, new StringBuffer("\uDBFF\uDFFF").codePointCount(0, 2));
-
- assertEquals(3, new StringBuffer("a\uD800\uDC00b").codePointCount(0, 4));
- assertEquals(4, new StringBuffer("a\uD800\uDC00b\uD800").codePointCount(0, 5));
-
- StringBuffer sb = new StringBuffer("abc");
- try {
- sb.codePointCount(-1, 2);
- fail("No IOOBE for negative begin index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointCount(0, 4);
- fail("No IOOBE for end index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointCount(3, 2);
- fail("No IOOBE for begin index larger than end index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.getChars(int, int, char[], int)
- */
- public void test_getCharsII$CI() {
- StringBuffer obj = new StringBuffer();
- try {
- obj.getChars(0, 0, new char[0], -1);
- fail("ArrayIndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.StringBuffer.offsetByCodePoints(int, int)'
- */
- public void test_offsetByCodePointsII() {
- int result = new StringBuffer("a\uD800\uDC00b").offsetByCodePoints(0, 2);
- assertEquals(3, result);
-
- result = new StringBuffer("abcd").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- result = new StringBuffer("a\uD800\uDC00b").offsetByCodePoints(0, 3);
- assertEquals(4, result);
-
- result = new StringBuffer("a\uD800\uDC00b").offsetByCodePoints(3, -1);
- assertEquals(1, result);
-
- result = new StringBuffer("a\uD800\uDC00b").offsetByCodePoints(3, 0);
- assertEquals(3, result);
-
- result = new StringBuffer("\uD800\uDC00bc").offsetByCodePoints(3, 0);
- assertEquals(3, result);
-
- result = new StringBuffer("a\uDC00bc").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- result = new StringBuffer("a\uD800bc").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- StringBuffer sb = new StringBuffer("abc");
- try {
- sb.offsetByCodePoints(-1, 1);
- fail("No IOOBE for negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(0, 4);
- fail("No IOOBE for offset that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(3, -4);
- fail("No IOOBE for offset that's too small.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(3, 1);
- fail("No IOOBE for index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(4, -1);
- fail("No IOOBE for index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests {@link java.lang.StringBuffer#indexOf(String, int)}
- */
- @SuppressWarnings("nls")
- public void test_IndexOfStringInt() {
- final String fixture = "0123456789";
- StringBuffer sb = new StringBuffer(fixture);
- assertEquals(0, sb.indexOf("0"));
- assertEquals(0, sb.indexOf("012"));
- assertEquals(-1, sb.indexOf("02"));
- assertEquals(8, sb.indexOf("89"));
-
- assertEquals(0, sb.indexOf("0"), 0);
- assertEquals(0, sb.indexOf("012"), 0);
- assertEquals(-1, sb.indexOf("02"), 0);
- assertEquals(8, sb.indexOf("89"), 0);
-
- assertEquals(-1, sb.indexOf("0"), 5);
- assertEquals(-1, sb.indexOf("012"), 5);
- assertEquals(-1, sb.indexOf("02"), 0);
- assertEquals(8, sb.indexOf("89"), 5);
-
- try {
- sb.indexOf(null, 0);
- fail("Should throw a NullPointerExceptionE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests {@link java.lang.StringBuffer#lastIndexOf(String, int)}
- */
- @SuppressWarnings("nls")
- public void test_lastIndexOfLjava_lang_StringI() {
- final String fixture = "0123456789";
- StringBuffer sb = new StringBuffer(fixture);
- assertEquals(0, sb.lastIndexOf("0"));
- assertEquals(0, sb.lastIndexOf("012"));
- assertEquals(-1, sb.lastIndexOf("02"));
- assertEquals(8, sb.lastIndexOf("89"));
-
- assertEquals(0, sb.lastIndexOf("0"), 0);
- assertEquals(0, sb.lastIndexOf("012"), 0);
- assertEquals(-1, sb.lastIndexOf("02"), 0);
- assertEquals(8, sb.lastIndexOf("89"), 0);
-
- assertEquals(-1, sb.lastIndexOf("0"), 5);
- assertEquals(-1, sb.lastIndexOf("012"), 5);
- assertEquals(-1, sb.lastIndexOf("02"), 0);
- assertEquals(8, sb.lastIndexOf("89"), 5);
-
- try {
- sb.lastIndexOf(null, 0);
- fail("Should throw a NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- // comparator for StringBuffer objects
- private static final SerializableAssert STRING_BUFFER_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- StringBuffer init = (StringBuffer) initial;
- StringBuffer desr = (StringBuffer) deserialized;
-
- // serializable fields are: 'count', 'shared', 'value'
- // serialization of 'shared' is not verified
- // 'count' + 'value' should result in required string
- assertEquals("toString", init.toString(), desr.toString());
- }
- };
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new StringBuffer("0123456789"),
- STRING_BUFFER_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new StringBuffer("0123456789"),
- STRING_BUFFER_COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuilderTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuilderTest.java
deleted file mode 100644
index d9acab0..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringBuilderTest.java
+++ /dev/null
@@ -1,1984 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-public class StringBuilderTest extends TestCase {
-
- /**
- * @tests java.lang.StringBuilder.StringBuilder()
- */
- public void test_Constructor() {
- StringBuilder sb = new StringBuilder();
- assertNotNull(sb);
- assertEquals(16, sb.capacity());
- }
-
- /**
- * @tests java.lang.StringBuilder.StringBuilder(int)
- */
- public void test_ConstructorI() {
- StringBuilder sb = new StringBuilder(24);
- assertNotNull(sb);
- assertEquals(24, sb.capacity());
-
- try {
- new StringBuilder(-1);
- fail("no exception");
- } catch (NegativeArraySizeException e) {
- // Expected
- }
-
- assertNotNull(new StringBuilder(0));
- }
-
- /**
- * @tests java.lang.StringBuilder.StringBuilder(CharSequence)
- */
- @SuppressWarnings("cast")
- public void test_ConstructorLjava_lang_CharSequence() {
- StringBuilder sb = new StringBuilder((CharSequence) "fixture");
- assertEquals("fixture", sb.toString());
- assertEquals("fixture".length() + 16, sb.capacity());
-
- sb = new StringBuilder((CharSequence) new StringBuffer("fixture"));
- assertEquals("fixture", sb.toString());
- assertEquals("fixture".length() + 16, sb.capacity());
-
- try {
- new StringBuilder((CharSequence) null);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.StringBuilder(String)
- */
- public void test_ConstructorLjava_lang_String() {
- StringBuilder sb = new StringBuilder("fixture");
- assertEquals("fixture", sb.toString());
- assertEquals("fixture".length() + 16, sb.capacity());
-
- try {
- new StringBuilder((String) null);
- fail("no NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.append(boolean)
- */
- public void test_appendZ() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(true));
- assertEquals("true", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(false));
- assertEquals("false", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(char)
- */
- public void test_appendC() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append('a'));
- assertEquals("a", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append('b'));
- assertEquals("b", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(char[])
- */
- public void test_append$C() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(new char[] { 'a', 'b' }));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(new char[] { 'c', 'd' }));
- assertEquals("cd", sb.toString());
- try {
- sb.append((char[]) null);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.append(char[], int, int)
- */
- public void test_append$CII() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(new char[] { 'a', 'b' }, 0, 2));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(new char[] { 'c', 'd' }, 0, 2));
- assertEquals("cd", sb.toString());
-
- sb.setLength(0);
- assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, 2));
- assertEquals("ab", sb.toString());
-
- sb.setLength(0);
- assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 2));
- assertEquals("cd", sb.toString());
-
- sb.setLength(0);
- assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 0));
- assertEquals("", sb.toString());
-
- try {
- sb.append((char[]) null, 0, 2);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- sb.append(new char[] { 'a', 'b', 'c', 'd' }, -1, 2);
- fail("no IOOBE, negative offset");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, -1);
- fail("no IOOBE, negative length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 3);
- fail("no IOOBE, offset and length overflow");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.append(CharSequence)
- */
- public void test_appendLjava_lang_CharSequence() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append((CharSequence) "ab"));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "cd"));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) null));
- assertEquals("null", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(CharSequence, int, int)
- */
- @SuppressWarnings("cast")
- public void test_appendLjava_lang_CharSequenceII() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append((CharSequence) "ab", 0, 2));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "cd", 0, 2));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "abcd", 0, 2));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) "abcd", 2, 4));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((CharSequence) null, 0, 2));
- assertEquals("nu", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(double)
- */
- public void test_appendD() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(1D));
- assertEquals(String.valueOf(1D), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(0D));
- assertEquals(String.valueOf(0D), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(-1D));
- assertEquals(String.valueOf(-1D), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Double.NaN));
- assertEquals(String.valueOf(Double.NaN), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Double.NEGATIVE_INFINITY));
- assertEquals(String.valueOf(Double.NEGATIVE_INFINITY), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Double.POSITIVE_INFINITY));
- assertEquals(String.valueOf(Double.POSITIVE_INFINITY), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Double.MIN_VALUE));
- assertEquals(String.valueOf(Double.MIN_VALUE), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Double.MAX_VALUE));
- assertEquals(String.valueOf(Double.MAX_VALUE), sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(float)
- */
- public void test_appendF() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(1F));
- assertEquals(String.valueOf(1F), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(0F));
- assertEquals(String.valueOf(0F), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(-1F));
- assertEquals(String.valueOf(-1F), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Float.NaN));
- assertEquals(String.valueOf(Float.NaN), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Float.NEGATIVE_INFINITY));
- assertEquals(String.valueOf(Float.NEGATIVE_INFINITY), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Float.POSITIVE_INFINITY));
- assertEquals(String.valueOf(Float.POSITIVE_INFINITY), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Float.MIN_VALUE));
- assertEquals(String.valueOf(Float.MIN_VALUE), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Float.MAX_VALUE));
- assertEquals(String.valueOf(Float.MAX_VALUE), sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(int)
- */
- public void test_appendI() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(1));
- assertEquals(String.valueOf(1), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(0));
- assertEquals(String.valueOf(0), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(-1));
- assertEquals(String.valueOf(-1), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Integer.MIN_VALUE));
- assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Integer.MAX_VALUE));
- assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(long)
- */
- public void test_appendL() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(1L));
- assertEquals(String.valueOf(1L), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(0L));
- assertEquals(String.valueOf(0L), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(-1L));
- assertEquals(String.valueOf(-1L), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Integer.MIN_VALUE));
- assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(Integer.MAX_VALUE));
- assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(Object)'
- */
- public void test_appendLjava_lang_Object() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(Fixture.INSTANCE));
- assertEquals(Fixture.INSTANCE.toString(), sb.toString());
-
- sb.setLength(0);
- assertSame(sb, sb.append((Object) null));
- assertEquals("null", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(String)
- */
- public void test_appendLjava_lang_String() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append("ab"));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append("cd"));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((String) null));
- assertEquals("null", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.append(StringBuffer)
- */
- public void test_appendLjava_lang_StringBuffer() {
- StringBuilder sb = new StringBuilder();
- assertSame(sb, sb.append(new StringBuffer("ab")));
- assertEquals("ab", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append(new StringBuffer("cd")));
- assertEquals("cd", sb.toString());
- sb.setLength(0);
- assertSame(sb, sb.append((StringBuffer) null));
- assertEquals("null", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.appendCodePoint(int)'
- */
- public void test_appendCodePointI() {
- StringBuilder sb = new StringBuilder();
- sb.appendCodePoint(0x10000);
- assertEquals("\uD800\uDC00", sb.toString());
- sb.append("fixture");
- assertEquals("\uD800\uDC00fixture", sb.toString());
- sb.appendCodePoint(0x00010FFFF);
- assertEquals("\uD800\uDC00fixture\uDBFF\uDFFF", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.capacity()'
- */
- public void test_capacity() {
- StringBuilder sb = new StringBuilder();
- assertEquals(16, sb.capacity());
- sb.append("0123456789ABCDEF0123456789ABCDEF");
- assertTrue(sb.capacity() > 16);
- }
-
- /**
- * @tests java.lang.StringBuilder.charAt(int)'
- */
- public void test_charAtI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- for (int i = 0; i < fixture.length(); i++) {
- assertEquals((char) ('0' + i), sb.charAt(i));
- }
-
- try {
- sb.charAt(-1);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.charAt(fixture.length());
- fail("no IOOBE, equal to length");
- } catch (IndexOutOfBoundsException e) {
- }
-
- try {
- sb.charAt(fixture.length() + 1);
- fail("no IOOBE, greater than length");
- } catch (IndexOutOfBoundsException e) {
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.codePointAt(int)
- */
- public void test_codePointAtI() {
- StringBuilder sb = new StringBuilder("abc");
- assertEquals('a', sb.codePointAt(0));
- assertEquals('b', sb.codePointAt(1));
- assertEquals('c', sb.codePointAt(2));
-
- sb = new StringBuilder("\uD800\uDC00");
- assertEquals(0x10000, sb.codePointAt(0));
- assertEquals('\uDC00', sb.codePointAt(1));
-
- sb = new StringBuilder();
- sb.append("abc");
- try {
- sb.codePointAt(-1);
- fail("No IOOBE on negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointAt(sb.length());
- fail("No IOOBE on index equal to length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointAt(sb.length() + 1);
- fail("No IOOBE on index greater than length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.codePointBefore(int)
- */
- public void test_codePointBeforeI() {
- StringBuilder sb = new StringBuilder("abc");
- assertEquals('a', sb.codePointBefore(1));
- assertEquals('b', sb.codePointBefore(2));
- assertEquals('c', sb.codePointBefore(3));
-
- sb = new StringBuilder("\uD800\uDC00");
- assertEquals(0x10000, sb.codePointBefore(2));
- assertEquals('\uD800', sb.codePointBefore(1));
-
- sb = new StringBuilder();
- sb.append("abc");
-
- try {
- sb.codePointBefore(0);
- fail("No IOOBE on zero index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointBefore(-1);
- fail("No IOOBE on negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointBefore(sb.length() + 1);
- fail("No IOOBE on index greater than length.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.codePointCount(int, int)
- */
- public void test_codePointCountII() {
- assertEquals(1, new StringBuilder("\uD800\uDC00").codePointCount(0, 2));
- assertEquals(1, new StringBuilder("\uD800\uDC01").codePointCount(0, 2));
- assertEquals(1, new StringBuilder("\uD801\uDC01").codePointCount(0, 2));
- assertEquals(1, new StringBuilder("\uDBFF\uDFFF").codePointCount(0, 2));
-
- assertEquals(3, new StringBuilder("a\uD800\uDC00b").codePointCount(0, 4));
- assertEquals(4, new StringBuilder("a\uD800\uDC00b\uD800").codePointCount(0, 5));
-
- StringBuilder sb = new StringBuilder();
- sb.append("abc");
- try {
- sb.codePointCount(-1, 2);
- fail("No IOOBE for negative begin index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointCount(0, 4);
- fail("No IOOBE for end index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.codePointCount(3, 2);
- fail("No IOOBE for begin index larger than end index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.delete(int, int)
- */
- public void test_deleteII() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.delete(0, 0));
- assertEquals(fixture, sb.toString());
- assertSame(sb, sb.delete(5, 5));
- assertEquals(fixture, sb.toString());
- assertSame(sb, sb.delete(0, 1));
- assertEquals("123456789", sb.toString());
- assertEquals(9, sb.length());
- assertSame(sb, sb.delete(0, sb.length()));
- assertEquals("", sb.toString());
- assertEquals(0, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.delete(0, 11));
- assertEquals("", sb.toString());
- assertEquals(0, sb.length());
-
- try {
- new StringBuilder(fixture).delete(-1, 2);
- fail("no SIOOBE, negative start");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- new StringBuilder(fixture).delete(11, 12);
- fail("no SIOOBE, start too far");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- new StringBuilder(fixture).delete(13, 12);
- fail("no SIOOBE, start larger than end");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- // HARMONY 6212
- sb = new StringBuilder();
- sb.append("abcde");
- String str = sb.toString();
- sb.delete(0, sb.length());
- sb.append("YY");
- assertEquals("abcde", str);
- assertEquals("YY", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.deleteCharAt(int)
- */
- public void test_deleteCharAtI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.deleteCharAt(0));
- assertEquals("123456789", sb.toString());
- assertEquals(9, sb.length());
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.deleteCharAt(5));
- assertEquals("012346789", sb.toString());
- assertEquals(9, sb.length());
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.deleteCharAt(9));
- assertEquals("012345678", sb.toString());
- assertEquals(9, sb.length());
-
- try {
- new StringBuilder(fixture).deleteCharAt(-1);
- fail("no SIOOBE, negative index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- new StringBuilder(fixture).deleteCharAt(fixture.length());
- fail("no SIOOBE, index equals length");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- new StringBuilder(fixture).deleteCharAt(fixture.length() + 1);
- fail("no SIOOBE, index exceeds length");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.ensureCapacity(int)'
- */
- public void test_ensureCapacityI() {
- StringBuilder sb = new StringBuilder(5);
- assertEquals(5, sb.capacity());
- sb.ensureCapacity(10);
- assertEquals(12, sb.capacity());
- sb.ensureCapacity(26);
- assertEquals(26, sb.capacity());
- sb.ensureCapacity(55);
- assertEquals(55, sb.capacity());
- }
-
- /**
- * @tests java.lang.StringBuilder.getChars(int, int, char[], int)'
- */
- public void test_getCharsII$CI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- char[] dst = new char[10];
- sb.getChars(0, 10, dst, 0);
- assertTrue(Arrays.equals(fixture.toCharArray(), dst));
-
- Arrays.fill(dst, '\0');
- sb.getChars(0, 5, dst, 0);
- char[] fixtureChars = new char[10];
- fixture.getChars(0, 5, fixtureChars, 0);
- assertTrue(Arrays.equals(fixtureChars, dst));
-
- Arrays.fill(dst, '\0');
- Arrays.fill(fixtureChars, '\0');
- sb.getChars(0, 5, dst, 5);
- fixture.getChars(0, 5, fixtureChars, 5);
- assertTrue(Arrays.equals(fixtureChars, dst));
-
- Arrays.fill(dst, '\0');
- Arrays.fill(fixtureChars, '\0');
- sb.getChars(5, 10, dst, 1);
- fixture.getChars(5, 10, fixtureChars, 1);
- assertTrue(Arrays.equals(fixtureChars, dst));
-
- try {
- sb.getChars(0, 10, null, 0);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- sb.getChars(-1, 10, dst, 0);
- fail("no IOOBE, srcBegin negative");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.getChars(0, 10, dst, -1);
- fail("no IOOBE, dstBegin negative");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.getChars(5, 4, dst, 0);
- fail("no IOOBE, srcBegin > srcEnd");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.getChars(0, 11, dst, 0);
- fail("no IOOBE, srcEnd > length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.getChars(0, 10, dst, 5);
- fail("no IOOBE, dstBegin and src size too large for what's left in dst");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.indexOf(String)
- */
- public void test_indexOfLjava_lang_String() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertEquals(0, sb.indexOf("0"));
- assertEquals(0, sb.indexOf("012"));
- assertEquals(-1, sb.indexOf("02"));
- assertEquals(8, sb.indexOf("89"));
-
- try {
- sb.indexOf(null);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.indexOf(String, int)
- */
- public void test_IndexOfStringInt() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertEquals(0, sb.indexOf("0"));
- assertEquals(0, sb.indexOf("012"));
- assertEquals(-1, sb.indexOf("02"));
- assertEquals(8, sb.indexOf("89"));
-
- assertEquals(0, sb.indexOf("0"), 0);
- assertEquals(0, sb.indexOf("012"), 0);
- assertEquals(-1, sb.indexOf("02"), 0);
- assertEquals(8, sb.indexOf("89"), 0);
-
- assertEquals(-1, sb.indexOf("0"), 5);
- assertEquals(-1, sb.indexOf("012"), 5);
- assertEquals(-1, sb.indexOf("02"), 0);
- assertEquals(8, sb.indexOf("89"), 5);
-
- try {
- sb.indexOf(null, 0);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, boolean)
- */
- public void test_insertIZ() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, true));
- assertEquals("true0000", sb.toString());
- assertEquals(8, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, false));
- assertEquals("false0000", sb.toString());
- assertEquals(9, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, false));
- assertEquals("00false00", sb.toString());
- assertEquals(9, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, false));
- assertEquals("0000false", sb.toString());
- assertEquals(9, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, false);
- fail("no SIOOBE, negative index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, false);
- fail("no SIOOBE, index too large index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, char)
- */
- public void test_insertIC() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 'a'));
- assertEquals("a0000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 'b'));
- assertEquals("b0000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, 'b'));
- assertEquals("00b00", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, 'b'));
- assertEquals("0000b", sb.toString());
- assertEquals(5, sb.length());
-
- // FIXME this fails on Sun JRE 5.0_5
-// try {
-// sb = new StringBuilder(fixture);
-// sb.insert(-1, 'a');
-// fail("no SIOOBE, negative index");
-// } catch (StringIndexOutOfBoundsException e) {
-// // Expected
-// }
-
- /*
- * FIXME This fails on Sun JRE 5.0_5, but that seems like a bug, since
- * the 'insert(int, char[]) behaves this way.
- */
-// try {
-// sb = new StringBuilder(fixture);
-// sb.insert(5, 'a');
-// fail("no SIOOBE, index too large index");
-// } catch (StringIndexOutOfBoundsException e) {
-// // Expected
-// }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, char)
- */
- public void test_insertIC_2() {
- StringBuilder obj = new StringBuilder();
- try {
- obj.insert(-1, '?');
- fail("ArrayIndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, char[])'
- */
- public void test_insertI$C() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- /*
- * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
- * undocumented. The assumption is that this method behaves like
- * String.valueOf(char[]), which does throw a NPE too, but that is also
- * undocumented.
- */
-
- try {
- sb.insert(0, (char[]) null);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, new char[] { 'a', 'b' });
- fail("no SIOOBE, negative index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' });
- fail("no SIOOBE, index too large index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, char[], int, int)
- */
- public void test_insertI$CII() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 2));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 1));
- assertEquals("a0000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 2));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 1));
- assertEquals("00a00", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 2));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 1));
- assertEquals("0000a", sb.toString());
- assertEquals(5, sb.length());
-
- /*
- * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
- * undocumented. The assumption is that this method behaves like
- * String.valueOf(char[]), which does throw a NPE too, but that is also
- * undocumented.
- */
-
- try {
- sb.insert(0, (char[]) null, 0, 2);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, new char[] { 'a', 'b' }, 0, 2);
- fail("no SIOOBE, negative index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, 2);
- fail("no SIOOBE, index too large index");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, -1, 2);
- fail("no SIOOBE, negative offset");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
- fail("no SIOOBE, negative length");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
- fail("no SIOOBE, too long");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, CharSequence)
- */
- public void test_insertILjava_lang_CharSequence() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab"));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab"));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab"));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) null));
- assertEquals("0000null", sb.toString());
- assertEquals(8, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, (CharSequence) "ab");
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, (CharSequence) "ab");
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, CharSequence, int, int)
- */
- @SuppressWarnings("cast")
- public void test_insertILjava_lang_CharSequenceII() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 2));
- assertEquals("ab0000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 1));
- assertEquals("a0000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 2));
- assertEquals("00ab00", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 1));
- assertEquals("00a00", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 2));
- assertEquals("0000ab", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 1));
- assertEquals("0000a", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (CharSequence) null, 0, 2));
- assertEquals("0000nu", sb.toString());
- assertEquals(6, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, (CharSequence) "ab", 0, 2);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, (CharSequence) "ab", 0, 2);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, (CharSequence) "ab", -1, 2);
- fail("no IOOBE, negative offset");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
- fail("no IOOBE, negative length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
- fail("no IOOBE, too long");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, double)
- */
- public void test_insertID() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, -1D));
- assertEquals("-1.00000", sb.toString());
- assertEquals(8, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 0D));
- assertEquals("0.00000", sb.toString());
- assertEquals(7, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, 1D));
- assertEquals("001.000", sb.toString());
- assertEquals(7, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, 2D));
- assertEquals("00002.0", sb.toString());
- assertEquals(7, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, 1D);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, 1D);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, float)
- */
- public void test_insertIF() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, -1F));
- assertEquals("-1.00000", sb.toString());
- assertEquals(8, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 0F));
- assertEquals("0.00000", sb.toString());
- assertEquals(7, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, 1F));
- assertEquals("001.000", sb.toString());
- assertEquals(7, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, 2F));
- assertEquals("00002.0", sb.toString());
- assertEquals(7, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, 1F);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, 1F);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, int)
- */
- public void test_insertII() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, -1));
- assertEquals("-10000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 0));
- assertEquals("00000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, 1));
- assertEquals("00100", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, 2));
- assertEquals("00002", sb.toString());
- assertEquals(5, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, 1);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, 1);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, long)
- */
- public void test_insertIJ() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, -1L));
- assertEquals("-10000", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, 0L));
- assertEquals("00000", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, 1L));
- assertEquals("00100", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, 2L));
- assertEquals("00002", sb.toString());
- assertEquals(5, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, 1L);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, 1L);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, Object)
- */
- public void test_insertILjava_lang_Object() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, Fixture.INSTANCE));
- assertEquals("fixture0000", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, Fixture.INSTANCE));
- assertEquals("00fixture00", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, Fixture.INSTANCE));
- assertEquals("0000fixture", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (Object) null));
- assertEquals("0000null", sb.toString());
- assertEquals(8, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, Fixture.INSTANCE);
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, Fixture.INSTANCE);
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.insert(int, String)
- */
- public void test_insertILjava_lang_String() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(0, "fixture"));
- assertEquals("fixture0000", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(2, "fixture"));
- assertEquals("00fixture00", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, "fixture"));
- assertEquals("0000fixture", sb.toString());
- assertEquals(11, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.insert(4, (Object) null));
- assertEquals("0000null", sb.toString());
- assertEquals(8, sb.length());
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(-1, "fixture");
- fail("no IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.insert(5, "fixture");
- fail("no IOOBE, index too large index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.lastIndexOf(String)
- */
- public void test_lastIndexOfLjava_lang_String() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertEquals(0, sb.lastIndexOf("0"));
- assertEquals(0, sb.lastIndexOf("012"));
- assertEquals(-1, sb.lastIndexOf("02"));
- assertEquals(8, sb.lastIndexOf("89"));
-
- try {
- sb.lastIndexOf(null);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.lastIndexOf(String, int)
- */
- public void test_lastIndexOfLjava_lang_StringI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertEquals(0, sb.lastIndexOf("0"));
- assertEquals(0, sb.lastIndexOf("012"));
- assertEquals(-1, sb.lastIndexOf("02"));
- assertEquals(8, sb.lastIndexOf("89"));
-
- assertEquals(0, sb.lastIndexOf("0"), 0);
- assertEquals(0, sb.lastIndexOf("012"), 0);
- assertEquals(-1, sb.lastIndexOf("02"), 0);
- assertEquals(8, sb.lastIndexOf("89"), 0);
-
- assertEquals(-1, sb.lastIndexOf("0"), 5);
- assertEquals(-1, sb.lastIndexOf("012"), 5);
- assertEquals(-1, sb.lastIndexOf("02"), 0);
- assertEquals(8, sb.lastIndexOf("89"), 5);
-
- try {
- sb.lastIndexOf(null, 0);
- fail("no NPE");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.length()
- */
- public void test_length() {
- StringBuilder sb = new StringBuilder();
- assertEquals(0, sb.length());
- sb.append("0000");
- assertEquals(4, sb.length());
- }
-
- /**
- * @tests java.lang.StringBuilder.offsetByCodePoints(int, int)'
- */
- public void test_offsetByCodePointsII() {
- int result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(0, 2);
- assertEquals(3, result);
-
- result = new StringBuilder("abcd").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(0, 3);
- assertEquals(4, result);
-
- result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(3, -1);
- assertEquals(1, result);
-
- result = new StringBuilder("a\uD800\uDC00b").offsetByCodePoints(3, 0);
- assertEquals(3, result);
-
- result = new StringBuilder("\uD800\uDC00bc").offsetByCodePoints(3, 0);
- assertEquals(3, result);
-
- result = new StringBuilder("a\uDC00bc").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- result = new StringBuilder("a\uD800bc").offsetByCodePoints(3, -1);
- assertEquals(2, result);
-
- StringBuilder sb = new StringBuilder();
- sb.append("abc");
- try {
- sb.offsetByCodePoints(-1, 1);
- fail("No IOOBE for negative index.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(0, 4);
- fail("No IOOBE for offset that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(3, -4);
- fail("No IOOBE for offset that's too small.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(3, 1);
- fail("No IOOBE for index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
-
- try {
- sb.offsetByCodePoints(4, -1);
- fail("No IOOBE for index that's too large.");
- } catch (IndexOutOfBoundsException e) {
-
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.replace(int, int, String)'
- */
- public void test_replaceIILjava_lang_String() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.replace(1, 3, "11"));
- assertEquals("0110", sb.toString());
- assertEquals(4, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.replace(1, 2, "11"));
- assertEquals("01100", sb.toString());
- assertEquals(5, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.replace(4, 5, "11"));
- assertEquals("000011", sb.toString());
- assertEquals(6, sb.length());
-
- sb = new StringBuilder(fixture);
- assertSame(sb, sb.replace(4, 6, "11"));
- assertEquals("000011", sb.toString());
- assertEquals(6, sb.length());
-
- // FIXME Undocumented NPE in Sun's JRE 5.0_5
- try {
- sb.replace(1, 2, null);
- fail("No NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.replace(-1, 2, "11");
- fail("No SIOOBE, negative start");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.replace(5, 2, "11");
- fail("No SIOOBE, start > length");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb = new StringBuilder(fixture);
- sb.replace(3, 2, "11");
- fail("No SIOOBE, start > end");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- // Regression for HARMONY-348
- StringBuilder buffer = new StringBuilder("1234567");
- buffer.replace(2, 6, "XXX");
- assertEquals("12XXX7",buffer.toString());
- }
-
- private void reverseTest(String org, String rev, String back) {
- // create non-shared StringBuilder
- StringBuilder sb = new StringBuilder(org);
- sb.reverse();
- String reversed = sb.toString();
- assertEquals(rev, reversed);
- // create non-shared StringBuilder
- sb = new StringBuilder(reversed);
- sb.reverse();
- reversed = sb.toString();
- assertEquals(back, reversed);
-
- // test algorithm when StringBuilder is shared
- sb = new StringBuilder(org);
- String copy = sb.toString();
- assertEquals(org, copy);
- sb.reverse();
- reversed = sb.toString();
- assertEquals(rev, reversed);
- sb = new StringBuilder(reversed);
- copy = sb.toString();
- assertEquals(rev, copy);
- sb.reverse();
- reversed = sb.toString();
- assertEquals(back, reversed);
- }
-
- /**
- * @tests java.lang.StringBuilder.reverse()
- */
- public void test_reverse() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertSame(sb, sb.reverse());
- assertEquals("9876543210", sb.toString());
-
- sb = new StringBuilder("012345678");
- assertSame(sb, sb.reverse());
- assertEquals("876543210", sb.toString());
-
- sb.setLength(1);
- assertSame(sb, sb.reverse());
- assertEquals("8", sb.toString());
-
- sb.setLength(0);
- assertSame(sb, sb.reverse());
- assertEquals("", sb.toString());
-
- String str;
- str = "a";
- reverseTest(str, str, str);
-
- str = "ab";
- reverseTest(str, "ba", str);
-
- str = "abcdef";
- reverseTest(str, "fedcba", str);
-
- str = "abcdefg";
- reverseTest(str, "gfedcba", str);
-
- str = "\ud800\udc00";
- reverseTest(str, str, str);
-
- str = "\udc00\ud800";
- reverseTest(str, "\ud800\udc00", "\ud800\udc00");
-
- str = "a\ud800\udc00";
- reverseTest(str, "\ud800\udc00a", str);
-
- str = "ab\ud800\udc00";
- reverseTest(str, "\ud800\udc00ba", str);
-
- str = "abc\ud800\udc00";
- reverseTest(str, "\ud800\udc00cba", str);
-
- str = "\ud800\udc00\udc01\ud801\ud802\udc02";
- reverseTest(str, "\ud802\udc02\ud801\udc01\ud800\udc00",
- "\ud800\udc00\ud801\udc01\ud802\udc02");
-
- str = "\ud800\udc00\ud801\udc01\ud802\udc02";
- reverseTest(str, "\ud802\udc02\ud801\udc01\ud800\udc00", str);
-
- str = "\ud800\udc00\udc01\ud801a";
- reverseTest(str, "a\ud801\udc01\ud800\udc00",
- "\ud800\udc00\ud801\udc01a");
-
- str = "a\ud800\udc00\ud801\udc01";
- reverseTest(str, "\ud801\udc01\ud800\udc00a", str);
-
- str = "\ud800\udc00\udc01\ud801ab";
- reverseTest(str, "ba\ud801\udc01\ud800\udc00",
- "\ud800\udc00\ud801\udc01ab");
-
- str = "ab\ud800\udc00\ud801\udc01";
- reverseTest(str, "\ud801\udc01\ud800\udc00ba", str);
-
- str = "\ud800\udc00\ud801\udc01";
- reverseTest(str, "\ud801\udc01\ud800\udc00", str);
-
- str = "a\ud800\udc00z\ud801\udc01";
- reverseTest(str, "\ud801\udc01z\ud800\udc00a", str);
-
- str = "a\ud800\udc00bz\ud801\udc01";
- reverseTest(str, "\ud801\udc01zb\ud800\udc00a", str);
-
- str = "abc\ud802\udc02\ud801\udc01\ud800\udc00";
- reverseTest(str, "\ud800\udc00\ud801\udc01\ud802\udc02cba", str);
-
- str = "abcd\ud802\udc02\ud801\udc01\ud800\udc00";
- reverseTest(str, "\ud800\udc00\ud801\udc01\ud802\udc02dcba", str);
- }
-
- /**
- * @tests java.lang.StringBuilder.setCharAt(int, char)
- */
- public void test_setCharAtIC() {
- final String fixture = "0000";
- StringBuilder sb = new StringBuilder(fixture);
- sb.setCharAt(0, 'A');
- assertEquals("A000", sb.toString());
- sb.setCharAt(1, 'B');
- assertEquals("AB00", sb.toString());
- sb.setCharAt(2, 'C');
- assertEquals("ABC0", sb.toString());
- sb.setCharAt(3, 'D');
- assertEquals("ABCD", sb.toString());
-
- try {
- sb.setCharAt(-1, 'A');
- fail("No IOOBE, negative index");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.setCharAt(4, 'A');
- fail("No IOOBE, index == length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.setCharAt(5, 'A');
- fail("No IOOBE, index > length");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.setLength(int)'
- */
- public void test_setLengthI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- sb.setLength(5);
- assertEquals(5, sb.length());
- assertEquals("01234", sb.toString());
- sb.setLength(6);
- assertEquals(6, sb.length());
- assertEquals("01234\0", sb.toString());
- sb.setLength(0);
- assertEquals(0, sb.length());
- assertEquals("", sb.toString());
-
- try {
- sb.setLength(-1);
- fail("No IOOBE, negative length.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- sb = new StringBuilder("abcde");
- assertEquals("abcde", sb.toString());
- sb.setLength(1);
- sb.append('g');
- assertEquals("ag", sb.toString());
-
- sb = new StringBuilder("abcde");
- sb.setLength(3);
- sb.append('g');
- assertEquals("abcg", sb.toString());
-
- sb = new StringBuilder("abcde");
- sb.setLength(2);
- try {
- sb.charAt(3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- sb = new StringBuilder();
- sb.append("abcdefg");
- sb.setLength(2);
- sb.setLength(5);
- for (int i = 2; i < 5; i++) {
- assertEquals(0, sb.charAt(i));
- }
-
- sb = new StringBuilder();
- sb.append("abcdefg");
- sb.delete(2, 4);
- sb.setLength(7);
- assertEquals('a', sb.charAt(0));
- assertEquals('b', sb.charAt(1));
- assertEquals('e', sb.charAt(2));
- assertEquals('f', sb.charAt(3));
- assertEquals('g', sb.charAt(4));
- for (int i = 5; i < 7; i++) {
- assertEquals(0, sb.charAt(i));
- }
-
- sb = new StringBuilder();
- sb.append("abcdefg");
- sb.replace(2, 5, "z");
- sb.setLength(7);
- for (int i = 5; i < 7; i++) {
- assertEquals(0, sb.charAt(i));
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.subSequence(int, int)
- */
- public void test_subSequenceII() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- CharSequence ss = sb.subSequence(0, 5);
- assertEquals("01234", ss.toString());
-
- ss = sb.subSequence(0, 0);
- assertEquals("", ss.toString());
-
- try {
- sb.subSequence(-1, 1);
- fail("No IOOBE, negative start.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.subSequence(0, -1);
- fail("No IOOBE, negative end.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.subSequence(0, fixture.length() + 1);
- fail("No IOOBE, end > length.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.subSequence(3, 2);
- fail("No IOOBE, start > end.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.substring(int)
- */
- public void test_substringI() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- String ss = sb.substring(0);
- assertEquals(fixture, ss);
-
- ss = sb.substring(10);
- assertEquals("", ss);
-
- try {
- sb.substring(-1);
- fail("No SIOOBE, negative start.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.substring(0, -1);
- fail("No SIOOBE, negative end.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.substring(fixture.length() + 1);
- fail("No SIOOBE, start > length.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.substring(int, int)
- */
- public void test_substringII() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- String ss = sb.substring(0, 5);
- assertEquals("01234", ss);
-
- ss = sb.substring(0, 0);
- assertEquals("", ss);
-
- try {
- sb.substring(-1, 1);
- fail("No SIOOBE, negative start.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.substring(0, -1);
- fail("No SIOOBE, negative end.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.substring(0, fixture.length() + 1);
- fail("No SIOOBE, end > length.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- sb.substring(3, 2);
- fail("No SIOOBE, start > end.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.lang.StringBuilder.toString()'
- */
- public void test_toString() throws Exception {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertEquals(fixture, sb.toString());
-
- sb.setLength(0);
- sb.append("abcde");
- assertEquals("abcde", sb.toString());
- sb.setLength(1000);
- byte[] bytes = sb.toString().getBytes("GB18030");
- for (int i = 5; i < bytes.length; i++) {
- assertEquals(0, bytes[i]);
- }
-
- sb.setLength(5);
- sb.append("fghij");
- assertEquals("abcdefghij", sb.toString());
- }
-
- /**
- * @tests java.lang.StringBuilder.trimToSize()'
- */
- public void test_trimToSize() {
- final String fixture = "0123456789";
- StringBuilder sb = new StringBuilder(fixture);
- assertTrue(sb.capacity() > fixture.length());
- assertEquals(fixture.length(), sb.length());
- assertEquals(fixture, sb.toString());
- int prevCapacity = sb.capacity();
- sb.trimToSize();
- assertTrue(prevCapacity > sb.capacity());
- assertEquals(fixture.length(), sb.length());
- assertEquals(fixture, sb.toString());
- }
-
- // comparator for StringBuilder objects
- private static final SerializableAssert STRING_BILDER_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- StringBuilder init = (StringBuilder) initial;
- StringBuilder desr = (StringBuilder) deserialized;
-
- assertEquals("toString", init.toString(), desr.toString());
- }
- };
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new StringBuilder("0123456789"),
- STRING_BILDER_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new StringBuilder("0123456789"),
- STRING_BILDER_COMPARATOR);
- }
-
- private static final class Fixture {
- static final Fixture INSTANCE = new Fixture();
-
- private Fixture() {
- super();
- }
-
- @Override
- public String toString() {
- return "fixture";
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringIndexOutOfBoundsExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringIndexOutOfBoundsExceptionTest.java
deleted file mode 100644
index 8ffeb3a..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StringIndexOutOfBoundsExceptionTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class StringIndexOutOfBoundsExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.StringIndexOutOfBoundsException#StringIndexOutOfBoundsException()
- */
- public void test_Constructor() {
- StringIndexOutOfBoundsException e = new StringIndexOutOfBoundsException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.StringIndexOutOfBoundsException#StringIndexOutOfBoundsException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- StringIndexOutOfBoundsException e = new StringIndexOutOfBoundsException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SystemTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SystemTest.java
deleted file mode 100644
index 1023dcc..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/SystemTest.java
+++ /dev/null
@@ -1,896 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.nio.channels.Channel;
-import java.nio.channels.spi.SelectorProvider;
-import java.security.Permission;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Vector;
-
-@TestTargetClass(System.class)
-public class SystemTest extends junit.framework.TestCase {
-
- static boolean flag = false;
-
- static boolean ranFinalize = false;
-
- /**
- * @tests java.lang.System#setIn(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setIn",
- args = {java.io.InputStream.class}
- )
- public void test_setInLjava_io_InputStream() {
- InputStream orgIn = System.in;
- InputStream in = new ByteArrayInputStream(new byte[0]);
- System.setIn(in);
- assertTrue("in not set", System.in == in);
- System.setIn(orgIn);
- }
-
- /**
- * @tests java.lang.System#setOut(java.io.PrintStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setOut",
- args = {java.io.PrintStream.class}
- )
- public void test_setOutLjava_io_PrintStream() {
- PrintStream orgOut = System.out;
- PrintStream out = new PrintStream(new ByteArrayOutputStream());
- System.setOut(out);
- assertTrue("out not set", System.out == out);
- System.setOut(orgOut);
- }
-
- /**
- * @tests java.lang.System#setErr(java.io.PrintStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setErr",
- args = {java.io.PrintStream.class}
- )
- public void test_setErrLjava_io_PrintStream() {
- PrintStream orgErr = System.err;
- PrintStream err = new PrintStream(new ByteArrayOutputStream());
- System.setErr(err);
- assertTrue("err not set", System.err == err);
- System.setErr(orgErr);
- }
-
- /**
- * @tests java.lang.System#arraycopy(java.lang.Object, int,
- * java.lang.Object, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "arraycopy",
- args = {java.lang.Object.class, int.class, java.lang.Object.class,
- int.class, int.class}
- )
- public void test_arraycopyLjava_lang_ObjectILjava_lang_ObjectII() {
- // Test for method void java.lang.System.arraycopy(java.lang.Object,
- // int, java.lang.Object, int, int)
- Integer a[] = new Integer[20];
- Integer b[] = new Integer[20];
- int i = 0;
- while (i < a.length) {
- a[i] = new Integer(i);
- ++i;
- }
- System.arraycopy(a, 0, b, 0, a.length);
- for (i = 0; i < a.length; i++)
- assertTrue("Copied elements incorrectly", a[i].equals(b[i]));
-
- /* Non primitive array types don't need to be identical */
- String[] source1 = new String[] { "element1" };
- Object[] dest1 = new Object[1];
- System.arraycopy(source1, 0, dest1, 0, dest1.length);
- assertTrue("Invalid copy 1", dest1[0] == source1[0]);
-
- char[][] source = new char[][] { { 'H', 'e', 'l', 'l', 'o' },
- { 'W', 'o', 'r', 'l', 'd' } };
- char[][] dest = new char[2][];
- System.arraycopy(source, 0, dest, 0, dest.length);
- assertTrue("Invalid copy 2", dest[0] == source[0]
- && dest[1] == source[1]);
-
- try {
- // copy from non array object into Object array
- System.arraycopy(new Object(), 0, b, 0, 0);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from Object array into non array object
- System.arraycopy(a, 0, new Object(), 0, 0);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from primitive array into object array
- System.arraycopy(new char[] {'a'}, 0, new String[1], 0, 1);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from object array into primitive array
- System.arraycopy(new String[] {"a"}, 0, new char[1], 0, 1);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from primitive array into an array of another primitive type
- System.arraycopy(new char[] {'a'}, 0, new int[1], 0, 1);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from object array into an array of another Object type
- System.arraycopy(new Character[] {'a'}, 0, new Integer[1], 0, 1);
- fail("ArrayStoreException is not thrown.");
- } catch(ArrayStoreException ase) {
- //expected
- }
-
- try {
- // copy from null into an array of a primitive type
- System.arraycopy(null, 0, new int[1], 0, 1);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- // copy from a primitive array into null
- System.arraycopy(new int[]{'1'}, 0, null, 0, 1);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- System.arraycopy(a, a.length + 1, b, 0, 1);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, -1, b, 0, 1);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, 0, b, -1, 1);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, 0, b, 0, -1);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, 11, b, 0, 10);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, Integer.MAX_VALUE, b, 0, 10);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, 0, b, Integer.MAX_VALUE, 10);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
-
- try {
- System.arraycopy(a, 0, b, 10, Integer.MAX_VALUE);
- fail("IndexOutOfBoundsException is not thrown.");
- } catch(IndexOutOfBoundsException ioobe) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.System#currentTimeMillis()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "currentTimeMillis",
- args = {}
- )
- public void test_currentTimeMillis() {
- // Test for method long java.lang.System.currentTimeMillis()
- try {
- long firstRead = System.currentTimeMillis();
- try {
- Thread.sleep(150);
- } catch (InterruptedException e) {
- }
- long secondRead = System.currentTimeMillis();
- assertTrue("Incorrect times returned: " + firstRead + ", "
- + secondRead, firstRead < secondRead);
- } catch (Exception e) {
- fail("Exception during test: " + e.toString());
- }
- }
-
- /**
- * @tests java.lang.System#getProperties()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getProperties",
- args = {}
- )
- public void test_getProperties() {
-
- // Test for method java.util.Properties java.lang.System.getProperties()
- /* String[] props = { "java.version", "java.vendor", "java.vendor.url",
- "java.home", "java.vm.specification.version",
- "java.vm.specification.vendor", "java.vm.specification.name",
- "java.vm.version", "java.vm.vendor", "java.vm.name",
- "java.specification.name", "java.specification.vendor",
- "java.specification.name", "java.class.version",
- "java.class.path", "java.ext.dirs", "os.name", "os.arch",
- "os.version", "file.separator", "path.separator",
- "line.separator", "user.name", "user.home", "user.dir", };
- */
-
- String [] props = {"java.vendor.url",
- "java.class.path", "user.home",
- "java.class.version", "os.version",
- "java.vendor", "user.dir",
- /*"user.timezone",*/ "path.separator",
- "os.name", "os.arch",
- "line.separator", "file.separator",
- "user.name", "java.version", "java.home" };
-
- /* Available properties.
- String [] props = {"java.boot.class.path", "java.class.path",
- "java.class.version", "java.compiler", "java.ext.dirs",
- "java.home", "java.io.tmpdir", "java.library.path",
- "java.vendor", "java.vendor.url", "java.version",
- "java.vm.name", "java.vm.specification.name",
- "java.vm.specification.vendor", "java.vm.specification.version",
- "java.vm.vendor", "java.vm.version", "java.specification.name",
- "java.specification.vendor", "java.specification.version",
- "os.arch", "os.name", "os.version", "user.home", "user.name",
- "user.dir", "file.separator", "line.separator",
- "path.separator", "java.runtime.name", "java.runtime.version",
- "java.vm.vendor.url", "file.encoding","user.language",
- "user.region"};
- */
-
- Properties p = System.getProperties();
- assertTrue(p.size() > 0);
-
- // Ensure spec'ed properties are non-null. See System.getProperties()
- // spec.
-
- for (int i = 0; i < props.length; i++) {
- assertNotNull("There is no property among returned properties: "
- + props[i], p.getProperty(props[i]));
- assertNotNull("System property is null: " + props[i],
- System.getProperty(props[i]));
- }
- }
-
- /**
- * @tests java.lang.System#getProperty(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getProperty",
- args = {java.lang.String.class}
- )
- public void test_getPropertyLjava_lang_String() {
- // Test for method java.lang.String
- // java.lang.System.getProperty(java.lang.String)
- assertTrue("Failed to return correct property value", System
- .getProperty("line.separator").indexOf("\n", 0) >= 0);
-
- boolean is8859_1 = true;
- String encoding = System.getProperty("file.encoding");
- byte[] bytes = new byte[128];
- char[] chars = new char[128];
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = (byte) (i + 128);
- chars[i] = (char) (i + 128);
- }
- String charResult = new String(bytes);
- byte[] byteResult = new String(chars).getBytes();
- if (charResult.length() == 128 && byteResult.length == 128) {
- for (int i = 0; i < bytes.length; i++) {
- if (charResult.charAt(i) != (char) (i + 128)
- || byteResult[i] != (byte) (i + 128))
- is8859_1 = false;
- }
- } else
- is8859_1 = false;
- String[] possibles = new String[] { "ISO8859_1", "8859_1", "ISO8859-1",
- "ISO-8859-1", "ISO_8859-1", "ISO_8859-1:1978", "ISO-IR-100",
- "LATIN1", "CSISOLATIN1" };
- boolean found8859_1 = false;
- for (int i = 0; i < possibles.length; i++) {
- if (possibles[i].equals(encoding)) {
- found8859_1 = true;
- break;
- }
- }
- assertTrue("Wrong encoding: " + encoding, !is8859_1 || found8859_1);
-
- try {
- System.getProperty(null);
- fail("NullPointerException should be thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- System.getProperty("");
- fail("IllegalArgumentException should be thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.System#getProperty(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getProperty",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_getPropertyLjava_lang_StringLjava_lang_String() {
- // Test for method java.lang.String
- // java.lang.System.getProperty(java.lang.String, java.lang.String)
- assertTrue("Failed to return correct property value: "
- + System.getProperty("line.separator", "99999"), System
- .getProperty("line.separator", "99999").indexOf("\n", 0) >= 0);
- assertEquals("Failed to return correct property value", "bogus", System
- .getProperty("bogus.prop", "bogus"));
-
- try {
- System.getProperty(null, "0.0");
- fail("NullPointerException should be thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- System.getProperty("", "0");
- fail("IllegalArgumentException should be thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- /**
- * @tests java.lang.System#setProperty(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setProperty",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_setPropertyLjava_lang_StringLjava_lang_String() {
- // Test for method java.lang.String
- // java.lang.System.setProperty(java.lang.String, java.lang.String)
-
- assertNull("Failed to return null", System.setProperty("testing",
- "value1"));
- assertTrue("Failed to return old value", System.setProperty("testing",
- "value2") == "value1");
- assertTrue("Failed to find value",
- System.getProperty("testing") == "value2");
-
- boolean exception = false;
- try {
- System.setProperty("", "default");
- } catch (IllegalArgumentException e) {
- exception = true;
- }
- assertTrue("Expected IllegalArgumentException", exception);
- }
-
- /**
- * @tests java.lang.System#getSecurityManager()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Doesn't check positive functionality.",
- method = "getSecurityManager",
- args = {}
- )
- public void test_getSecurityManager() {
- // Test for method java.lang.SecurityManager
- // java.lang.System.getSecurityManager()
- assertNull("Returned incorrect SecurityManager", System
- .getSecurityManager());
- }
-
- /**
- * @tests java.lang.System#identityHashCode(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "identityHashCode",
- args = {java.lang.Object.class}
- )
- public void test_identityHashCodeLjava_lang_Object() {
- // Test for method int
- // java.lang.System.identityHashCode(java.lang.Object)
- Object o = new Object();
- String s = "Gabba";
- assertEquals("Nonzero returned for null",
- 0, System.identityHashCode(null));
- assertTrue("Nonequal has returned for Object", System
- .identityHashCode(o) == o.hashCode());
- assertTrue("Same as usual hash returned for String", System
- .identityHashCode(s) != s.hashCode());
- }
-
- /**
- * @throws IOException
- * @tests java.lang.System#inheritedChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "inheritedChannel",
- args = {}
- )
- public void test_inheritedChannel() throws IOException {
- Channel iChannel = System.inheritedChannel();
- assertNull("Incorrect value of channel", iChannel);
- SelectorProvider sp = SelectorProvider.provider();
- assertEquals("Incorrect value of channel",
- sp.inheritedChannel(), iChannel);
- }
-
- /**
- * @tests java.lang.System#runFinalization()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "runFinalization",
- args = {}
- )
- public void test_runFinalization() {
- // Test for method void java.lang.System.runFinalization()
-
- flag = true;
- createInstance();
- int count = 10;
- // the gc below likely bogosifies the test, but will have to do for
- // the moment
- while (!ranFinalize && count-- > 0) {
- System.gc();
- System.runFinalization();
- }
- assertTrue("Failed to run finalization", ranFinalize);
- }
-
- /**
- * @tests java.lang.System#runFinalizersOnExit(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "runFinalizersOnExit",
- args = {boolean.class}
- )
- @SuppressWarnings("deprecation")
- public void test_runFinalizersOnExitZ() {
- // Can we call the method at least?
- try {
- System.runFinalizersOnExit(false);
- } catch (Throwable t) {
- fail("Failed to set runFinalizersOnExit");
- }
-
- try {
- System.runFinalizersOnExit(true);
- } catch (Throwable t) {
- fail("Failed to set runFinalizersOnExit");
- }
- }
-
- /**
- * @tests java.lang.System#setProperties(java.util.Properties)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setProperties",
- args = {java.util.Properties.class}
- )
- public void test_setPropertiesLjava_util_Properties() {
- // Test for method void
- // java.lang.System.setProperties(java.util.Properties)
-
- Properties orgProps = System.getProperties();
- java.util.Properties tProps = new java.util.Properties();
- tProps.put("test.prop", "this is a test property");
- tProps.put("bogus.prop", "bogus");
- System.setProperties(tProps);
- try {
- assertEquals("Failed to set properties", "this is a test property", System.getProperties()
- .getProperty("test.prop"));
- } finally {
- // restore the original properties
- System.setProperties(orgProps);
- }
- }
-
- //Regression Test for Harmony-2356
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getenv",
- args = {}
- )
- public void testEnvUnmodifiable() {
- Map map = System.getenv();
- try {
- map.containsKey(null);
- fail("Should throw NullPointerExcepiton.");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- map.containsKey(new Integer(10));
- fail("Should throw ClassCastException.");
- } catch (ClassCastException e) {
- // expected
- }
-
- try {
- map.containsValue(null);
- fail("Should throw NullPointerExcepiton.");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- map.containsValue(new Integer(10));
- fail("Should throw ClassCastException.");
- } catch (ClassCastException e) {
- // expected
- }
-
- try {
- map.get(null);
- fail("Should throw NullPointerExcepiton.");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- map.get(new Integer(10));
- fail("Should throw ClassCastException.");
- } catch (ClassCastException e) {
- // expected
- }
-
- try {
- map.put(null, "AAA");
- fail("Should throw UnsupportedOperationExcepiton.");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- map.put("AAA", new Integer(10));
- fail("Should throw UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- map.put("AAA", "BBB");
- fail("Should throw UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- map.clear();
- fail("Should throw UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- try {
- if (map.remove(null) != null) {
- fail("Should no-op or throw UnsupportedOperationException.");
- }
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- }
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clearProperty",
- args = {java.lang.String.class}
- )
- public void test_clearProperty() {
- System.setProperty("test", "value");
- System.clearProperty("test");
- assertNull("Property was not deleted.", System.getProperty("test"));
-
- try {
- System.clearProperty(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
-
- try {
- System.clearProperty("");
- fail("IllegalArgumentException is not thrown.");
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "gc",
- args = {}
- )
- public void test_gc() {
- Runtime rt = Runtime.getRuntime();
- Vector<StringBuffer> vec = new Vector<StringBuffer>();
- long beforeTest = rt.freeMemory();
- while(rt.freeMemory() < beforeTest * 2/3) {
- vec.add(new StringBuffer(1000));
- }
- vec = null;
- long beforeGC = rt.freeMemory();
- System.gc();
- long afterGC = rt.freeMemory();
- assertTrue("memory was not released after calling System.gc()." +
- "before gc: " + beforeGC + "; after gc: " + afterGC,
- beforeGC < afterGC);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getenv",
- args = {}
- )
- public void test_getenv() {
-
- // String[] props = { "PATH", "HOME", "USER"};
- // only PATH of these three exists on android
- String[] props = { "PATH" };
-
- Map<String,String> envMap = System.getenv();
- assertFalse("environment map is empty.", envMap.isEmpty());
- assertTrue("env map contains less than 3 keys.",
- props.length < envMap.keySet().size());
- for(int i = 0; i < props.length; i++) {
- assertNotNull("There is no property: " + props[i],
- envMap.get(props[i]));
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getenv",
- args = {java.lang.String.class}
- )
- public void test_getenvLString() {
-
- assertNotNull("PATH environment variable is not found",
- System.getenv("PATH"));
-
- assertNull("Doesn't return NULL for non existent property",
- System.getenv("nonexistent.property"));
-
- try {
- System.getenv(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "load",
- args = {java.lang.String.class}
- )
- public void test_load() {
- try {
- Runtime.getRuntime().load("nonExistentLibrary");
- fail("UnsatisfiedLinkError was not thrown.");
- } catch(UnsatisfiedLinkError e) {
- //expected
- }
-
- try {
- System.load("nonExistentLibrary");
- fail("UnsatisfiedLinkError was not thrown.");
- } catch(UnsatisfiedLinkError ule) {
- //expected
- }
-
- try {
- System.load(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "loadLibrary",
- args = {java.lang.String.class}
- )
- public void test_loadLibrary() {
-
- try {
- System.loadLibrary("nonExistentLibrary");
- fail("UnsatisfiedLinkError was not thrown.");
- } catch(UnsatisfiedLinkError ule) {
- //expected
- }
-
- try {
- System.loadLibrary(null);
- fail("NullPointerException was not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mapLibraryName",
- args = {java.lang.String.class}
- )
- public void test_mapLibraryName() {
- assertEquals("libname.so", System.mapLibraryName("name"));
-
- try {
- System.mapLibraryName(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException npe) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nanoTime",
- args = {}
- )
- public void test_nanoTime() {
- long sleepTime = 5000;
- long beginTime = System.nanoTime();
- try {
- Thread.sleep(sleepTime);
- } catch(Exception e) {
- fail("Unknown exception was thrown.");
- }
- long endTime = System.nanoTime();
- assertTrue((endTime - beginTime) > sleepTime * 1000000);
- }
-
- @Override
- protected void setUp() {
- flag = false;
- ranFinalize = false;
- }
-
- @Override protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- protected SystemTest createInstance() {
- return new SystemTest("FT");
- }
-
- @Override
- protected void finalize() {
- if (flag)
- ranFinalize = true;
- }
-
- public SystemTest() {
- }
-
- public SystemTest(String name) {
- super(name);
- }
-
- private class MockSecurityManager extends SecurityManager {
- @Override
- public void checkPermission(Permission perm) {
- if (perm.equals(new RuntimePermission("inheritedChannel")))
- throw new SecurityException("Incorrect permission");
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAnnotation.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAnnotation.java
deleted file mode 100644
index 45d16ad..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAnnotation.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-@Retention(RetentionPolicy.RUNTIME)
-public @interface TestAnnotation {
- String value();
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions.java
deleted file mode 100644
index 3006553..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestAssertions {
- boolean isTrue = false;
-
- TestAssertions() {
-
- }
-
- public void test() throws AssertionError {
- assert (isTrue == true);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions1.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions1.java
deleted file mode 100644
index 16958cb..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestAssertions1.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestAssertions1 {
- boolean isTrue = true;
-
- TestAssertions1() {
-
- }
-
- public void test() throws AssertionError {
- assert (isTrue == false);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1.java
deleted file mode 100644
index 2d21de6..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestClass1 {
- static TestClass2 tc = new TestClass2(0);
-
- TestClass1() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1B.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1B.java
deleted file mode 100644
index 7891613..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1B.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestClass1B {
- static TestClass2 tc = new TestClass2(0);
-
- TestClass1B() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1C.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1C.java
deleted file mode 100644
index 37c890f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass1C.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestClass1C {
- static TestClass2 tc = new TestClass2(0);
-
- TestClass1C() {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass2.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass2.java
deleted file mode 100644
index 26be6fa..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass2.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestClass2 {
-
- public TestClass2(int i) throws IllegalArgumentException {
- throw new IllegalArgumentException();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass3.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass3.java
deleted file mode 100644
index 21ebb38..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass3.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class TestClass3 {
- private TestClass3() {}
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass4.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass4.java
deleted file mode 100644
index e69de29..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TestClass4.java
+++ /dev/null
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadDeathTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadDeathTest.java
deleted file mode 100644
index c40e0b0..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadDeathTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class ThreadDeathTest extends junit.framework.TestCase {
-
- /**
- * @tests java.lang.ThreadDeath#ThreadDeath()
- */
- public void test_Constructor() {
- ThreadDeath td = new ThreadDeath();
- assertNull(td.getCause());
- assertNull(td.getMessage());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
deleted file mode 100644
index 659a839..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadLocalTest.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(ThreadLocal.class)
-public class ThreadLocalTest extends TestCase {
-
- /**
- * @tests java.lang.ThreadLocal#ThreadLocal()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ThreadLocal",
- args = {}
- )
- public void test_Constructor() {
- new ThreadLocal<Object>();
- }
-
- /**
- * @tests java.lang.ThreadLocal#remove()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "remove",
- args = {}
- )
- public void test_remove() {
- ThreadLocal<String> tl = new ThreadLocal<String>() {
- @Override
- protected String initialValue() {
- return "initial";
- }
- };
-
- assertEquals("initial", tl.get());
- tl.set("fixture");
- assertEquals("fixture", tl.get());
- tl.remove();
- assertEquals("initial", tl.get());
- }
-
- /**
- * @tests java.lang.ThreadLocal#get()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void test_get() {
- // Test for method java.lang.Object java.lang.ThreadLocal.get()
- ThreadLocal<Object> l = new ThreadLocal<Object>();
- assertNull("ThreadLocal's initial value is null", l.get());
-
- // The ThreadLocal has to run once for each thread that touches the
- // ThreadLocal
- final Object INITIAL_VALUE = "'foo'";
- final ThreadLocal<Object> l1 = new ThreadLocal<Object>() {
- @Override
- protected Object initialValue() {
- return INITIAL_VALUE;
- }
- };
-
- assertTrue("ThreadLocal's initial value should be " + INITIAL_VALUE
- + " but is " + l1.get(), l1.get() == INITIAL_VALUE);
-
- // We need this because inner types cannot assign to variables in
- // container method. But assigning to object slots in the container
- // method is ok.
- class ResultSlot {
- public Object result = null;
- }
-
- final ResultSlot THREADVALUE = new ResultSlot();
- Thread t = new Thread() {
- @Override
- public void run() {
- THREADVALUE.result = l1.get();
- }
- };
-
- // Wait for the other Thread assign what it observes as the value of the
- // variable
- t.start();
- try {
- t.join();
- } catch (InterruptedException ie) {
- fail("Interrupted!!");
- }
-
- assertTrue("ThreadLocal's initial value in other Thread should be "
- + INITIAL_VALUE, THREADVALUE.result == INITIAL_VALUE);
-
- /* Regression test for implementation vulnerability reported
- * on Harmony dev list.
- */
- ThreadLocal<Object> thrVar = new ThreadLocal<Object>() {
- public int hashCode() {
- fail("ThreadLocal should not be asked for it's hashCode");
- return 0; // never reached
- }
- };
- thrVar.get();
- }
-
- /**
- * @tests java.lang.ThreadLocal#set(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "set",
- args = {java.lang.Object.class}
- )
- public void test_setLjava_lang_Object() {
- // Test for method void java.lang.ThreadLocal.set(java.lang.Object)
-
- final Object OBJ = new Object();
- final ThreadLocal<Object> l = new ThreadLocal<Object>();
- l.set(OBJ);
- assertTrue("ThreadLocal's initial value is " + OBJ, l.get() == OBJ);
-
- // We need this because inner types cannot assign to variables in
- // container method.
- // But assigning to object slots in the container method is ok.
- class ResultSlot {
- public Object result = null;
- }
-
- final ResultSlot THREADVALUE = new ResultSlot();
- Thread t = new Thread() {
- @Override
- public void run() {
- THREADVALUE.result = l.get();
- }
- };
-
- // Wait for the other Thread assign what it observes as the value of the
- // variable
- t.start();
- try {
- t.join();
- } catch (InterruptedException ie) {
- fail("Interrupted!!");
- }
-
- // ThreadLocal is not inherited, so the other Thread should see it as
- // null
- assertNull("ThreadLocal's value in other Thread should be null",
- THREADVALUE.result);
-
- }
-
- /**
- * @tests java.lang.InheritableThreadLocal
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void test_Ljava_lang_InheritableThreadLocal()
- throws InterruptedException {
- final Object value = new Object();
- final Object inheritedValue = new Object();
- final ThreadLocal<Object> threadLocal
- = new InheritableThreadLocal<Object>() {
- @Override
- protected Object childValue(Object parentValue) {
- assertSame(value, parentValue);
- return inheritedValue;
- }
- };
- threadLocal.set(value);
- final Object[] holder = new Object[1];
- Thread thread = new Thread() {
- public void run() {
- holder[0] = threadLocal.get();
- }
- };
- thread.start();
- thread.join();
- assertSame(value, threadLocal.get());
- assertSame(inheritedValue, holder[0]);
-
- // Cleanup properly, so other tests are not affected.
- threadLocal.remove();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadStateTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadStateTest.java
deleted file mode 100644
index 1ae2c27..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadStateTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(Thread.State.class)
-public class ThreadStateTest extends TestCase {
-
- Thread.State [] exStates = { Thread.State.NEW, Thread.State.RUNNABLE,
- Thread.State.BLOCKED, Thread.State.WAITING,
- Thread.State.TIMED_WAITING, Thread.State.TERMINATED };
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOfLString(){
- String [] spNames = {"NEW", "RUNNABLE", "BLOCKED", "WAITING",
- "TIMED_WAITING", "TERMINATED"};
-
- for(int i = 0; i < exStates.length; i++) {
- assertEquals(exStates[i], Thread.State.valueOf(spNames[i]));
- }
-
- String [] illegalNames = {"New", "new", "", "NAME", "TIME"};
- for(String s:illegalNames) {
- try {
- Thread.State.valueOf(s);
- fail("IllegalArgumentException was not thrown for string: "+s);
- } catch(IllegalArgumentException iae) {
- //expected
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "values",
- args = {}
- )
- public void test_values() {
-
- Thread.State [] thStates = Thread.State.values();
- assertEquals(exStates.length, thStates.length);
- for(Thread.State ts:thStates) {
- assertTrue(isContain(ts));
- }
-
- }
-
- boolean isContain(Thread.State state) {
- for(Thread.State ts:exStates) {
- if(ts.equals(state)) return true;
- }
- return false;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java
deleted file mode 100644
index a8e5c7f..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThrowableTest.java
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-
-@TestTargetClass(Throwable.class)
-public class ThrowableTest extends TestCase {
-
- /**
- * @tests java.lang.Throwable#Throwable()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Throwable",
- args = {}
- )
- public void test_Constructor() {
- Throwable e = new Throwable();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.Throwable#Throwable(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Throwable",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- })
- public void test_ConstructorLjava_lang_String() {
- Throwable e = new Throwable("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Throwable",
- args = {java.lang.String.class, java.lang.Throwable.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCause",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- })
- public void test_ConstructorLStringLThrowable() {
- String message = "Test message";
- NullPointerException npe = new NullPointerException();
- Throwable thr = new Throwable(message, npe);
- assertEquals("message is incorrect.", message, thr.getMessage());
- assertEquals("cause is incorrect.", npe, thr.getCause());
-
- thr = new Throwable(null, npe);
- assertNull("message is not null.", thr.getMessage());
- assertEquals("cause is incorrect.", npe, thr.getCause());
-
- thr = new Throwable(message, null);
- assertEquals("message is incorrect.", message, thr.getMessage());
- assertNull("cause is not null.", thr.getCause());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Throwable",
- args = {java.lang.Throwable.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCause",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- })
- public void test_ConstructorLThrowable() {
-
- NullPointerException npe = new NullPointerException();
- Throwable thr = new Throwable(npe);
-
- assertEquals("Returned cause is incorrect.", npe, thr.getCause());
-
- thr = new Throwable((Throwable) null);
- assertNull("The cause is not null.", thr.getCause());
- }
-
- /**
- * @tests java.lang.Throwable#fillInStackTrace()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "fillInStackTrace",
- args = {}
- )
- public void test_fillInStackTrace() {
- // Test for method java.lang.Throwable
- // java.lang.Throwable.fillInStackTrace()
- class Test implements Runnable {
- public int x;
-
- public Test(int x) {
- this.x = x;
- }
-
- public void anotherMethod() {
- if (true)
- throw new IndexOutOfBoundsException();
- }
-
- public void run() {
- if (x == 0)
- throw new IndexOutOfBoundsException();
- try {
- anotherMethod();
- } catch (IndexOutOfBoundsException e) {
- e.fillInStackTrace();
- throw e;
- }
- }
- }
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bao);
- try {
- new Test(0).run();
- } catch (Throwable e) {
- e.printStackTrace(ps);
- }
- ps.flush();
- String s = fixStacktrace(new String(bao.toByteArray(), 0, bao.size()));
-
- bao.reset();
- try {
- new Test(1).run();
- } catch (Throwable e) {
- e.printStackTrace(ps);
- }
- ps.close();
- String s2 = fixStacktrace(new String(bao.toByteArray(), 0, bao.size()));
- assertTrue("Invalid stackTrace? length: " + s2.length() + "\n" + s2, s2
- .length() > 300);
- assertTrue("Incorrect stackTrace printed: \n" + s2
- + "\n\nCompared with:\n" + s, s2.equals(s));
- }
-
- private String fixStacktrace(String trace) {
- // remove linenumbers
- StringBuffer sb = new StringBuffer();
- int lastIndex = 0;
- while (lastIndex < trace.length()) {
- int index = trace.indexOf('\n', lastIndex);
- if (index == -1)
- index = trace.length();
- String line = trace.substring(lastIndex, index);
- lastIndex = index + 1;
-
- index = line.indexOf("(");
- if (index > -1) {
- line = line.substring(0, index);
- }
- // Usually the construction of the exception is removed
- // however if running with the JIT, it may not be removed
- if (line.indexOf("java.lang.Throwable") > -1)
- continue;
- sb.append(line);
- sb.append('\n');
- }
- return sb.toString();
- }
-
- /**
- * @tests java.lang.Throwable#printStackTrace()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printStackTrace",
- args = {}
- )
- public void test_printStackTrace() {
- // Test for method void java.lang.Throwable.printStackTrace()
- Throwable x = new ClassNotFoundException("A Test Message");
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bao);
- PrintStream err = System.err;
- System.setErr(ps);
- x.printStackTrace();
- System.setErr(err);
- ps.close();
- String s = new String(bao.toByteArray(), 0, bao.size());
- assertTrue("Incorrect stackTrace printed:\n" + s, s != null
- && s.length() > 400);
- }
-
- /**
- * @tests java.lang.Throwable#printStackTrace(java.io.PrintStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printStackTrace",
- args = {java.io.PrintStream.class}
- )
- public void test_printStackTraceLjava_io_PrintStream() {
- // Test for method void
- // java.lang.Throwable.printStackTrace(java.io.PrintStream)
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bao);
- Throwable x = new java.net.UnknownHostException("A Message");
- x.printStackTrace(ps);
- ps.close();
- String s = new String(bao.toByteArray(), 0, bao.size());
- assertTrue("Incorrect stackTrace printed:\n" + s, s != null
- && s.length() > 400);
- }
-
- /**
- * @tests java.lang.Throwable#printStackTrace(java.io.PrintWriter)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "printStackTrace",
- args = {java.io.PrintWriter.class}
- )
- public void test_printStackTraceLjava_io_PrintWriter() {
- // Test for method void
- // java.lang.Throwable.printStackTrace(java.io.PrintWriter)
- // SM
- ByteArrayOutputStream bao = new ByteArrayOutputStream();
- PrintWriter pw = new PrintWriter(bao);
- Throwable x = new java.net.UnknownHostException("A Message");
- x.printStackTrace(pw);
- pw.close();
- String s = new String(bao.toByteArray(), 0, bao.size());
- assertTrue("Incorrect stackTrace printed:\n" + s, s != null
- && s.length() > 400);
- }
-
- /**
- * @tests java.lang.Throwable#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- Throwable e = new Throwable("Throw");
- assertEquals("java.lang.Throwable: Throw", e.toString());
-
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLocalizedMessage",
- args = {}
- )
- public void test_getLocalizedMessage() {
- String testMessage = "Test message";
- Throwable e = new Throwable(testMessage);
- assertEquals("Returned incorrect localized message.",
- testMessage, e.getLocalizedMessage());
-
- TestThrowable tt = new TestThrowable(testMessage);
- assertEquals("localized message", tt.getLocalizedMessage());
- }
-
- class TestThrowable extends Throwable {
-
- public TestThrowable(String message) {
- super(message);
- }
-
- public String getLocalizedMessage() {
- return "localized message";
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getStackTrace",
- args = {}
- )
- public void test_getStackTrace() {
- String message = "Test message";
- NullPointerException npe = new NullPointerException();
- Throwable thr = new Throwable(message, npe);
- StackTraceElement[] ste = thr.getStackTrace();
- assertNotNull("Returned stack trace is empty", ste.length != 0);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "initCause",
- args = {java.lang.Throwable.class}
- )
- public void test_initCause() {
- String message = "Test message";
- NullPointerException npe = new NullPointerException();
- IllegalArgumentException iae = new IllegalArgumentException();
- Throwable thr = new Throwable();
- thr.initCause(iae);
- assertEquals("getCause returns incorrect cause.", iae, thr.getCause());
-
- thr = new Throwable("message");
- thr.initCause(npe);
- assertEquals("getCause returns incorrect cause.", npe, thr.getCause());
-
- thr = new Throwable(message, npe);
- try {
- thr.initCause(iae);
- fail("IllegalStateException was not thrown.");
- } catch(IllegalStateException ise) {
- //expected
- }
-
- thr = new Throwable(npe);
- try {
- thr.initCause(iae);
- fail("IllegalStateException was not thrown.");
- } catch(IllegalStateException ise) {
- //expected
- }
-
- thr = new Throwable();
- try {
- thr.initCause(thr);
- fail("IllegalArgumentException was not thrown.");
- } catch(IllegalArgumentException ise) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setStackTrace",
- args = {java.lang.StackTraceElement[].class}
- )
- public void test_setStackTrace() {
- NullPointerException npe = new NullPointerException();
- Throwable thr = new Throwable(npe);
- StackTraceElement[] ste = thr.getStackTrace();
- Throwable thr1 = new Throwable(npe);
- thr1.setStackTrace(ste);
- assertEquals(ste.length, thr1.getStackTrace().length);
-
- try {
- thr.setStackTrace(null);
- fail("NullPointerException is not thrown.");
- } catch(NullPointerException np) {
- //expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TypeNotPresentExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TypeNotPresentExceptionTest.java
deleted file mode 100644
index 76df014..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/TypeNotPresentExceptionTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class TypeNotPresentExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.TypeNotPresentException.TypeNotPresentException(String, Throwable)
- */
- public void test_constructorLjava_lang_StringLjava_lang_Throwable() {
- TypeNotPresentException e = new TypeNotPresentException(null, null);
- assertNotNull(e);
- String m = e.getMessage();
- assertNotNull(m);
-
- e = new TypeNotPresentException(getClass().getName(), null);
- assertNotNull(e);
- m = e.getMessage();
- assertNotNull(m);
-
- NullPointerException npe = new NullPointerException();
- e = new TypeNotPresentException(getClass().getName(), npe);
- assertNotNull(e.getMessage());
- assertSame(npe, e.getCause());
- }
-
- /**
- * @tests java.lang.TypeNotPresentException.typeName()
- */
- public void test_typeName() {
- TypeNotPresentException e = new TypeNotPresentException(null, null);
- assertNull(e.typeName());
-
- e = new TypeNotPresentException(getClass().getName(), null);
- assertEquals(getClass().getName(), e.typeName());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
deleted file mode 100644
index 15f264b..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnknownErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class UnknownErrorTest extends TestCase {
-
- /**
- * @tests java.lang.UnknownError#UnknownError()
- */
- public void test_Constructor() {
- UnknownError e = new UnknownError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.UnknownError#UnknownError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- UnknownError e = new UnknownError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java
deleted file mode 100644
index 84229d8..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsatisfiedLinkErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class UnsatisfiedLinkErrorTest extends TestCase {
-
- /**
- * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError()
- */
- public void test_Constructor() {
- UnsatisfiedLinkError e = new UnsatisfiedLinkError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.UnsatisfiedLinkError#UnsatisfiedLinkError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- UnsatisfiedLinkError e = new UnsatisfiedLinkError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedClassVersionErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedClassVersionErrorTest.java
deleted file mode 100644
index 791ec16..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedClassVersionErrorTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase; // android-changed
-
-public class UnsupportedClassVersionErrorTest extends TestCase { // android-changed
- /**
- * Thrown when the Java Virtual Machine attempts to read a class file and
- * determines that the major and minor version numbers in the file are not
- * supported.
- */
-
- /**
- * @tests java.lang.UnsupportedClassVersionError#UnsupportedClassVersionError()
- */
- public void test_UnsupportedClassVersionError() {
- UnsupportedClassVersionError error = new UnsupportedClassVersionError();
- assertNotNull(error);
- assertNull(error.getMessage());
- }
-
- /**
- *@tests java.lang.UnsupportedClassVersionError#UnsupportedClassVersionError(java.lang.String)
- */
- public void test_UnsupportedClassVersionError_LString() {
- UnsupportedClassVersionError e = new UnsupportedClassVersionError(
- "Some Error Message");
- assertEquals("Wrong message", "Some Error Message", e.getMessage());
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java
deleted file mode 100644
index 4b1dbd8..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/UnsupportedOperationExceptionTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-public class UnsupportedOperationExceptionTest extends TestCase {
-
- /**
- * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException()
- */
- public void test_Constructor() {
- UnsupportedOperationException e = new UnsupportedOperationException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.UnsupportedOperationException#UnsupportedOperationException(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- UnsupportedOperationException e = new UnsupportedOperationException("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests {@link java.land.UnsupportedOperationException#UnsupportedOperationException(java.lang.Throwable)}
- */
- public void test_ConstructorLjava_lang_Throwable() {
- Throwable emptyThrowable = new Exception();
- UnsupportedOperationException emptyException = new UnsupportedOperationException(
- emptyThrowable);
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
-
- Throwable throwable = new Exception("msg");
- UnsupportedOperationException exception = new UnsupportedOperationException(throwable);
- assertEquals(throwable.getClass().getName() + ": " + "msg", exception.getMessage());
- assertEquals(throwable.getClass().getName(), emptyException.getLocalizedMessage());
- assertEquals(throwable.getClass().getName(), emptyException.getCause().toString());
- }
-
- /**
- * @tests {@link java.land.UnsupportedOperationException#UnsupportedOperationException(java.lang.String, java.lang.Throwable)}
- */
- public void test_ConstructorLjava_lang_StringLjava_lang_Throwable() {
- Throwable emptyThrowable = new Exception();
- UnsupportedOperationException emptyException = new UnsupportedOperationException(
- "msg", emptyThrowable);
- assertEquals("msg", emptyException.getMessage());
- assertEquals("msg", emptyException.getLocalizedMessage());
- assertEquals(emptyThrowable.getClass().getName(), emptyException.getCause().toString());
-
- Throwable throwable = new Exception("msg_exception");
- UnsupportedOperationException exception = new UnsupportedOperationException(
- "msg", throwable);
- assertEquals("msg", exception.getMessage());
- assertEquals("msg", exception.getLocalizedMessage());
- assertEquals(throwable.getClass().getName() + ": " + throwable.getMessage(), exception
- .getCause().toString());
- }
-
-
- /**
- * @tests serialization/deserialization.
- */
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnsupportedOperationException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new UnsupportedOperationException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
deleted file mode 100644
index 7bd2581..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VerifyErrorTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class VerifyErrorTest extends TestCase {
-
- /**
- * @tests java.lang.VerifyError#VerifyError()
- */
- public void test_Constructor() {
- VerifyError e = new VerifyError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.VerifyError#VerifyError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- VerifyError e = new VerifyError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java
deleted file mode 100644
index c8ce58c..0000000
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/VirtualMachineErrorTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-@SuppressWarnings("serial")
-public class VirtualMachineErrorTest extends TestCase {
-
- /**
- * @tests java.lang.VirtualMachineError#VirtualMachineError()
- */
- public void test_Constructor() {
- VirtualMachineError e = new VirtualMachineError() {};
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.VirtualMachineError#VirtualMachineError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- VirtualMachineError e = new VirtualMachineError("fixture") {};
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java
index 44208df..d2c0c6c 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet4AddressTest.java
@@ -17,21 +17,28 @@
package org.apache.harmony.luni.tests.java.net;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
import dalvik.annotation.TestTargetNew;
-
import java.io.Serializable;
import java.net.Inet4Address;
import java.net.InetAddress;
-
import org.apache.harmony.testframework.serialization.SerializationTest;
import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
@TestTargetClass(Inet4Address.class)
public class Inet4AddressTest extends junit.framework.TestCase {
+ private Inet4Address ipv4Localhost;
+ private Inet4Address ipv4LoopbackIp;
+
+ @Override protected void setUp() throws Exception {
+ super.setUp();
+ byte[] ipv4Loopback = { 127, 0, 0, 1 };
+ ipv4LoopbackIp = (Inet4Address) InetAddress.getByAddress(ipv4Loopback);
+ ipv4Localhost = (Inet4Address) InetAddress.getByAddress("localhost", ipv4Loopback);
+ }
+
/**
* @tests java.net.Inet4Address#isMulticastAddress()
*/
@@ -50,17 +57,17 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "224.0.0.0"; // a multicast addr 1110 = 224-239
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("Multicast address " + addrName + " not detected.", addr
.isMulticastAddress());
addrName = "239.255.255.255"; // a multicast addr 1110 = 224-239
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Multicast address " + addrName + " not detected.", addr
.isMulticastAddress());
addrName = "42.42.42.42"; // a non-multicast address
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Non multicast address " + addrName
+ " reporting as a multicast address.", !addr
.isMulticastAddress());
@@ -83,7 +90,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "0.0.0.0";
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("ANY address " + addrName + " not detected.", addr
.isAnyLocalAddress());
} catch (Exception e) {
@@ -106,19 +113,19 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "127.0.0.0"; // a loopback address should be 127.d.d.d
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = ipv4LoopbackIp;
assertTrue("Loopback address " + addrName + " not detected.", addr
.isLoopbackAddress());
addrName = "127.42.42.42"; // a loopback address should be
// 127.d.d.d
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Loopback address " + addrName + " not detected.", addr
.isLoopbackAddress());
addrName = "42.42.42.42"; // a loopback address should be
// 127.d.d.d
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Address incorrectly " + addrName
+ " detected as a loopback address.", !addr
.isLoopbackAddress());
@@ -146,7 +153,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
// We'll test one to ensure we get "false"
addrName = "42.42.42.42";
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv4 address " + addrName
+ " incorrectly reporting as a link local address.", !addr
.isLinkLocalAddress());
@@ -171,7 +178,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
// We'll test one to ensure we get "false"
addrName = "42.42.42.42";
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv4 address " + addrName
+ " incorrectly reporting as a site local address.", !addr
.isSiteLocalAddress());
@@ -198,37 +205,37 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "224.0.0.0"; // a multicast addr 1110
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " incorrectly identified as a global multicast address.",
!addr.isMCGlobal());
addrName = "224.0.0.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " incorrectly identified as a global multicast address.",
!addr.isMCGlobal());
addrName = "224.0.1.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 global multicast address " + addrName
+ " not identified as a global multicast address.", addr
.isMCGlobal());
addrName = "238.255.255.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 global multicast address " + addrName
+ " not identified as a global multicast address.", addr
.isMCGlobal());
addrName = "239.0.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 reserved multicast address " + addrName
+ " incorrectly identified as a global multicast address.",
!addr.isMCGlobal());
addrName = "239.191.255.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 reserved multicast address " + addrName
+ " incorrectly identified as a global multicast address.",
!addr.isMCGlobal());
@@ -255,7 +262,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "224.42.42.42"; // a multicast addr 1110 = 224
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 multicast address "
+ addrName
@@ -263,7 +270,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCNodeLocal());
addrName = "239.0.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 reserved multicast address "
+ addrName
@@ -292,19 +299,19 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "224.0.0.0"; // a multicast addr 1110
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " not identified as a link-local multicast address.",
addr.isMCLinkLocal());
addrName = "224.0.0.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " not identified as a link-local multicast address.",
addr.isMCLinkLocal());
addrName = "224.0.1.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 global multicast address "
+ addrName
@@ -312,7 +319,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCLinkLocal());
addrName = "239.0.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 reserved multicast address "
+ addrName
@@ -341,7 +348,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
String addrName = "";
try {
addrName = "240.0.0.0"; // a multicast addr 1110 = 224
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 multicast address "
+ addrName
@@ -349,7 +356,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCSiteLocal());
addrName = "239.0.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 reserved multicast address "
+ addrName
@@ -357,19 +364,19 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCSiteLocal());
addrName = "239.255.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 site-local multicast address " + addrName
+ " not identified as a site-local multicast address.",
addr.isMCSiteLocal());
addrName = "239.255.255.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 site-local multicast address " + addrName
+ " not identified as a site-local multicast address.",
addr.isMCSiteLocal());
addrName = "239.255.2.2"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 site-local multicast address " + addrName
+ " not identified as a site-local multicast address.",
addr.isMCSiteLocal());
@@ -397,7 +404,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
try {
addrName = "239.191.255.255"; // a multicast addr 1110
- InetAddress addr = Inet4Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 reserved multicast address "
+ addrName
@@ -405,7 +412,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCOrgLocal());
addrName = "239.252.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv4 site-local multicast address "
+ addrName
@@ -413,13 +420,13 @@ public class Inet4AddressTest extends junit.framework.TestCase {
!addr.isMCOrgLocal());
addrName = "239.192.0.0"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 org-local multicast address " + addrName
+ " not identified as a org-local multicast address.", addr
.isMCOrgLocal());
addrName = "239.195.255.255"; // a multicast addr 1110
- addr = Inet4Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 org-local multicast address " + addrName
+ " not identified as a org-local multicast address.", addr
.isMCOrgLocal());
@@ -457,9 +464,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
args = {}
)
public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(Inet4Address.getByName("localhost"),
- COMPARATOR);
+ SerializationTest.verifySelf(ipv4LoopbackIp, COMPARATOR);
}
/**
@@ -472,9 +477,7 @@ public class Inet4AddressTest extends junit.framework.TestCase {
args = {}
)
public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, Inet4Address
- .getByName("localhost"), COMPARATOR);
+ SerializationTest.verifyGolden(this, ipv4Localhost, COMPARATOR);
}
@TestTargetNew(
@@ -484,15 +487,13 @@ public class Inet4AddressTest extends junit.framework.TestCase {
args = {java.lang.Object.class}
)
public void test_equals() throws Exception {
- InetAddress addr = Inet4Address.getByName("239.191.255.255");
+ InetAddress addr = InetAddress.getByName("239.191.255.255");
assertTrue(addr.equals(addr));
- InetAddress addr1 = Inet4Address.getByName("127.0.0.1");
- InetAddress addr2 = Inet4Address.getByName("localhost");
- assertTrue(addr1.equals(addr2));
- assertFalse(addr.equals(addr1));
+ assertTrue(ipv4LoopbackIp.equals(ipv4Localhost));
+ assertFalse(addr.equals(ipv4LoopbackIp));
- InetAddress addr3 = Inet4Address.getByName("127.0.0");
- assertFalse(addr1.equals(addr3));
+ InetAddress addr3 = InetAddress.getByName("127.0.0");
+ assertFalse(ipv4LoopbackIp.equals(addr3));
}
@TestTargetNew(
@@ -502,22 +503,19 @@ public class Inet4AddressTest extends junit.framework.TestCase {
args = {}
)
public void test_getHostAddress() throws Exception {
- InetAddress addr = Inet4Address.getByName("localhost");
- assertEquals("127.0.0.1", addr.getHostAddress());
+ assertEquals("127.0.0.1", ipv4Localhost.getHostAddress());
+ assertEquals("127.0.0.1", ipv4LoopbackIp.getHostAddress());
- addr = Inet4Address.getByName("127.0.0.1");
- assertEquals("127.0.0.1", addr.getHostAddress());
-
- addr = Inet4Address.getByName("224.0.0.0");
+ InetAddress addr = InetAddress.getByName("224.0.0.0");
assertEquals("224.0.0.0", addr.getHostAddress());
- addr = Inet4Address.getByName("1");
+ addr = InetAddress.getByName("1");
assertEquals("0.0.0.1", addr.getHostAddress());
- addr = Inet4Address.getByName("1.1");
+ addr = InetAddress.getByName("1.1");
assertEquals("1.0.0.1", addr.getHostAddress());
- addr = Inet4Address.getByName("1.1.1");
+ addr = InetAddress.getByName("1.1.1");
assertEquals("1.1.0.1", addr.getHostAddress());
}
@@ -528,15 +526,13 @@ public class Inet4AddressTest extends junit.framework.TestCase {
args = {}
)
public void test_hashCode() throws Exception {
- InetAddress addr1 = Inet4Address.getByName("1.1");
- InetAddress addr2 = Inet4Address.getByName("1.1.1");
+ InetAddress addr1 = InetAddress.getByName("1.1");
+ InetAddress addr2 = InetAddress.getByName("1.1.1");
assertFalse(addr1.hashCode() == addr2.hashCode());
addr2 = InetAddress.getByName("1.0.0.1");
assertTrue(addr1.hashCode() == addr2.hashCode());
- addr1 = Inet4Address.getByName("127.0.0.1");
- addr2 = Inet4Address.getByName("localhost");
- assertTrue(addr1.hashCode() == addr2.hashCode());
+ assertTrue(ipv4LoopbackIp.hashCode() == ipv4Localhost.hashCode());
}
}
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
index 3a85732..eab7192 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/Inet6AddressTest.java
@@ -22,6 +22,7 @@ import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import java.io.Serializable;
+import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
@@ -36,6 +37,15 @@ import org.apache.harmony.testframework.serialization.SerializationTest.Serializ
@TestTargetClass(Inet6Address.class)
public class Inet6AddressTest extends junit.framework.TestCase {
+ private Inet6Address ipv6Localhost;
+ private Inet6Address ipv6LoopbackIp;
+
+ @Override protected void setUp() throws Exception {
+ super.setUp();
+ byte[] ipv6Loopback = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
+ ipv6LoopbackIp = (Inet6Address) InetAddress.getByAddress(ipv6Loopback);
+ ipv6Localhost = (Inet6Address) InetAddress.getByAddress("localhost", ipv6Loopback);
+ }
/**
* @tests java.net.Inet6Address#isMulticastAddress()
*/
@@ -59,12 +69,12 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// The first one will be one with the prefix the second without
addrName = "FFFF::42:42"; // 11111111 = FFFF
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Multicast address " + addrName + " not detected.", addr
.isMulticastAddress());
addrName = "42::42:42"; // an non-multicast address
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("Non multicast address " + addrName
+ " reporting as a multicast address.", !addr
.isMulticastAddress());
@@ -77,13 +87,13 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// We expect these to be false
addrName = "::224.42.42.42"; // an ipv4 multicast addr 1110 = 224
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 compatable address " + addrName
+ " reported incorrectly as multicast.", !addr
.isMulticastAddress());
addrName = "::42.42.42.42"; // an ipv4 non-multicast address
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 compatable address " + addrName
+ " reported incorrectly as multicast.", !addr
.isMulticastAddress());
@@ -96,12 +106,12 @@ public class Inet6AddressTest extends junit.framework.TestCase {
addrName = "::FFFF:224.42.42.42"; // an ipv4 multicast addr 1110 =
// 224
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-mapped IPv6 multicast address " + addrName
+ " not detected.", addr.isMulticastAddress());
addrName = "::FFFF:42.42.42.42"; // an ipv4 non-multicast address
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-mapped IPv6 non-multicast address " + addrName
+ " reporting as a multicast address.", !addr
.isMulticastAddress());
@@ -170,19 +180,19 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// The loopback address for IPv6 is ::1
addrName = "::1";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 loopback address " + addrName + " not detected.",
addr.isLoopbackAddress());
addrName = "::2";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address incorrectly " + addrName
+ " detected as a loopback address.", !addr
.isLoopbackAddress());
// a loopback address should be 127.d.d.d
addrName = "42:42::42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address incorrectly " + addrName
+ " detected as a loopback address.", !addr
.isLoopbackAddress());
@@ -196,21 +206,21 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a loopback address should be 127.d.d.d
addrName = "::127.0.0.0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 address " + addrName
+ " detected incorrectly as a loopback.", !addr
.isLoopbackAddress());
addrName = "::127.42.42.42"; // a loopback address should be
// 127.d.d.d
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 address " + addrName
+ " detected incorrectly as a loopback.", !addr
.isLoopbackAddress());
// a loopback address should be 127.d.d.d
addrName = "::42.42.42.42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 address " + addrName
+ " detected incorrectly as a loopback.", !addr
.isLoopbackAddress());
@@ -223,19 +233,19 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a loopback address should be 127.d.d.d
addrName = "::FFFF:127.0.0.0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 loopback address " + addrName
+ " not detected.", addr.isLoopbackAddress());
// a loopback address should be 127.d.d.d
addrName = "::FFFF:127.42.42.42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 loopback address " + addrName
+ " not detected.", addr.isLoopbackAddress());
// a loopback address should be 127.d.d.d
addrName = "::FFFF:42.42.42.42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4-compatible IPv6 address incorrectly " + addrName
+ " detected as a loopback address.", !addr
.isLoopbackAddress());
@@ -264,31 +274,31 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// FEBF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
addrName = "FE80::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 link local address " + addrName + " not detected.",
addr.isLinkLocalAddress());
addrName = "FEBF::FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 link local address " + addrName + " not detected.",
addr.isLinkLocalAddress());
addrName = "FEC0::1";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address " + addrName
+ " detected incorrectly as a link local address.", !addr
.isLinkLocalAddress());
addrName = "FD80::1:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address " + addrName
+ " detected incorrectly as a link local address.", !addr
.isLinkLocalAddress());
addrName = "FE7F::FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address " + addrName
+ " detected incorrectly as a link local address.", !addr
.isLinkLocalAddress());
@@ -316,25 +326,25 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// FEFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
addrName = "FEC0::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 site local address " + addrName + " not detected.",
addr.isSiteLocalAddress());
addrName = "FEFF::FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 site local address " + addrName + " not detected.",
addr.isSiteLocalAddress());
addrName = "FEBF::FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address " + addrName
+ " detected incorrectly as a site local address.", !addr
.isSiteLocalAddress());
addrName = "FFC0::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 address " + addrName
+ " detected incorrectly as a site local address.", !addr
.isSiteLocalAddress());
@@ -363,66 +373,66 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// the global address space
addrName = "FF0E::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 global mutlicast address " + addrName
+ " not detected.", addr.isMCGlobal());
addrName = "FF0E:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 global multicast address " + addrName
+ " not detected.", addr.isMCGlobal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFFE::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 global mutlicast address " + addrName
+ " not detected.", addr.isMCGlobal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFFE:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 global multicast address " + addrName
+ " not detected.", addr.isMCGlobal());
// a sample MC organizational address
addrName = "FF08:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast organizational " + addrName
+ " incorrectly indicated as a global address.", !addr
.isMCGlobal());
// a sample MC site address
addrName = "FF05:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast site address " + addrName
+ " incorrectly indicated as a global address.", !addr
.isMCGlobal());
// a sample MC link address
addrName = "FF02:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast link address " + addrName
+ " incorrectly indicated as a global address.", !addr
.isMCGlobal());
// a sample MC Node
addrName = "FF01:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast node address " + addrName
+ " incorrectly indicated as a global address.", !addr
.isMCGlobal());
// IPv4-mapped IPv6 address tests
addrName = "::FFFF:224.0.1.0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 global multicast address " + addrName
+ " not identified as a global multicast address.", addr
.isMCGlobal());
addrName = "::FFFF:238.255.255.255";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 global multicast address " + addrName
+ " not identified as a global multicast address.", addr
.isMCGlobal());
@@ -451,53 +461,53 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// the global address space
addrName = "FF01::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 node-local mutlicast address " + addrName
+ " not detected.", addr.isMCNodeLocal());
addrName = "FF01:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 node-local multicast address " + addrName
+ " not detected.", addr.isMCNodeLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF1::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 node-local mutlicast address " + addrName
+ " not detected.", addr.isMCNodeLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF1:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 node-local multicast address " + addrName
+ " not detected.", addr.isMCNodeLocal());
// a sample MC organizational address
addrName = "FF08:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast organizational address " + addrName
+ " incorrectly indicated as a node-local address.", !addr
.isMCNodeLocal());
// a sample MC site address
addrName = "FF05:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast site address " + addrName
+ " incorrectly indicated as a node-local address.", !addr
.isMCNodeLocal());
// a sample MC link address
addrName = "FF02:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast link address " + addrName
+ " incorrectly indicated as a node-local address.", !addr
.isMCNodeLocal());
// a sample MC global address
addrName = "FF0E:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 mulitcast node address " + addrName
+ " incorrectly indicated as a node-local address.", !addr
.isMCNodeLocal());
@@ -526,32 +536,32 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// the global address space
addrName = "FF02::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 link local multicast address " + addrName
+ " not detected.", addr.isMCLinkLocal());
addrName = "FF02:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 link local multicast address " + addrName
+ " not detected.", addr.isMCLinkLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF2::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 link local multicast address " + addrName
+ " not detected.", addr.isMCLinkLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF2:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 link local multicast address " + addrName
+ " not detected.", addr.isMCLinkLocal());
// a sample MC organizational address
addrName = "FF08:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 organization multicast address "
+ addrName
@@ -560,7 +570,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC site address
addrName = "FF05:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 site-local mulitcast address "
+ addrName
@@ -569,7 +579,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC global address
addrName = "FF0E:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 global multicast address "
+ addrName
@@ -578,7 +588,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC Node
addrName = "FF01:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 mulitcast node address "
+ addrName
@@ -588,13 +598,13 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// Ipv4-mapped IPv6 addresses
addrName = "::FFFF:224.0.0.0"; // a multicast addr 1110
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " not identified as a link-local multicast address.",
addr.isMCLinkLocal());
addrName = "::FFFF:224.0.0.255"; // a multicast addr 1110
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 link-local multicast address " + addrName
+ " not identified as a link-local multicast address.",
addr.isMCLinkLocal());
@@ -623,32 +633,32 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// the global address space
addrName = "FF05::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 site-local mutlicast address " + addrName
+ " not detected.", addr.isMCSiteLocal());
addrName = "FF05:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 site-local multicast address " + addrName
+ " not detected.", addr.isMCSiteLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF5::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 site-local mutlicast address " + addrName
+ " not detected.", addr.isMCSiteLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF5:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 site-local multicast address " + addrName
+ " not detected.", addr.isMCSiteLocal());
// a sample MC organizational address
addrName = "FF08:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 organization multicast address "
+ addrName
@@ -657,7 +667,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC global address
addrName = "FF0E:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 global mulitcast address "
+ addrName
@@ -666,7 +676,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC link address
addrName = "FF02:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 link-local multicast address "
+ addrName
@@ -675,7 +685,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC Node
addrName = "FF01:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 mulitcast node address "
+ addrName
@@ -684,13 +694,13 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// IPv4-mapped IPv6 addresses
addrName = "::FFFF:239.255.0.0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 site-local multicast address " + addrName
+ " not identified as a site-local multicast address.",
addr.isMCSiteLocal());
addrName = "::FFFF:239.255.255.255";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 site-local multicast address " + addrName
+ " not identified as a site-local multicast address.",
addr.isMCSiteLocal());
@@ -720,32 +730,32 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// the global address space
addrName = "FF08::0";
- InetAddress addr = Inet6Address.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("IPv6 organization-local mutlicast address " + addrName
+ " not detected.", addr.isMCOrgLocal());
addrName = "FF08:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 organization-local multicast address " + addrName
+ " not detected.", addr.isMCOrgLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF8::0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 organization-local mutlicast address " + addrName
+ " not detected.", addr.isMCOrgLocal());
// a currently invalid address as the prefix FFxE
// is only valid for x = {1,0} as the rest are reserved
addrName = "FFF8:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv6 organization-local multicast address " + addrName
+ " not detected.", addr.isMCOrgLocal());
// a sample MC global address
addrName = "FF0E:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 global multicast address "
+ addrName
@@ -754,7 +764,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC site address
addrName = "FF05:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 site-local mulitcast address "
+ addrName
@@ -763,7 +773,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC link address
addrName = "FF02:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 link-local multicast address "
+ addrName
@@ -772,7 +782,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// a sample MC Node
addrName = "FF01:42:42:42:42:42:42:42";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue(
"IPv6 mulitcast node address "
+ addrName
@@ -782,13 +792,13 @@ public class Inet6AddressTest extends junit.framework.TestCase {
// IPv4-mapped IPv6 addresses
addrName = "::FFFF:239.192.0.0";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 org-local multicast address " + addrName
+ " not identified as a org-local multicast address.", addr
.isMCOrgLocal());
addrName = "::FFFF:239.195.255.255";
- addr = Inet6Address.getByName(addrName);
+ addr = InetAddress.getByName(addrName);
assertTrue("IPv4 org-local multicast address " + addrName
+ " not identified as a org-local multicast address.", addr
.isMCOrgLocal());
@@ -1125,15 +1135,13 @@ public class Inet6AddressTest extends junit.framework.TestCase {
args = {java.lang.Object.class}
)
public void test_equals() throws Exception {
- InetAddress addr = Inet6Address.getByName("239.191.255.255");
+ InetAddress addr = InetAddress.getByName("239.191.255.255");
assertTrue(addr.equals(addr));
- InetAddress addr1 = Inet6Address.getByName("127.0.0.1");
- InetAddress addr2 = Inet6Address.getByName("localhost");
- assertTrue(addr1.equals(addr2));
- assertFalse(addr.equals(addr1));
+ assertTrue(ipv6LoopbackIp.equals(ipv6Localhost));
+ assertFalse(addr.equals(ipv6LoopbackIp));
- InetAddress addr3 = Inet6Address.getByName("127.0.0");
- assertFalse(addr1.equals(addr3));
+ InetAddress addr3 = InetAddress.getByName("127.0.0");
+ assertFalse(ipv6LoopbackIp.equals(addr3));
}
@TestTargetNew(
@@ -1143,22 +1151,19 @@ public class Inet6AddressTest extends junit.framework.TestCase {
args = {}
)
public void test_getHostAddress() throws Exception {
- InetAddress aAddr = Inet6Address.getByName("localhost");
- assertEquals("127.0.0.1", aAddr.getHostAddress());
+ assertEquals("::1", ipv6Localhost.getHostAddress());
+ assertEquals("::1", InetAddress.getByName("::1").getHostAddress());
- aAddr = Inet6Address.getByName("127.0.0.1");
- assertEquals("127.0.0.1", aAddr.getHostAddress());
-
- aAddr = Inet6Address.getByName("224.0.0.0");
+ InetAddress aAddr = InetAddress.getByName("224.0.0.0");
assertEquals("224.0.0.0", aAddr.getHostAddress());
- aAddr = Inet6Address.getByName("1");
+ aAddr = InetAddress.getByName("1");
assertEquals("0.0.0.1", aAddr.getHostAddress());
- aAddr = Inet6Address.getByName("1.1");
+ aAddr = InetAddress.getByName("1.1");
assertEquals("1.0.0.1", aAddr.getHostAddress());
- aAddr = Inet6Address.getByName("1.1.1");
+ aAddr = InetAddress.getByName("1.1.1");
assertEquals("1.1.0.1", aAddr.getHostAddress());
byte[] bAddr = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0, 0x02, 0x11,
@@ -1207,16 +1212,14 @@ public class Inet6AddressTest extends junit.framework.TestCase {
args = {}
)
public void test_hashCode() throws Exception {
- InetAddress addr1 = Inet6Address.getByName("1.1");
- InetAddress addr2 = Inet6Address.getByName("1.1.1");
+ InetAddress addr1 = InetAddress.getByName("1.1");
+ InetAddress addr2 = InetAddress.getByName("1.1.1");
assertFalse(addr1.hashCode() == addr2.hashCode());
- addr2 = Inet6Address.getByName("1.0.0.1");
+ addr2 = InetAddress.getByName("1.0.0.1");
assertTrue(addr1.hashCode() == addr2.hashCode());
- addr1 = Inet6Address.getByName("127.0.0.1");
- addr2 = Inet6Address.getByName("localhost");
- assertTrue(addr1.hashCode() == addr2.hashCode());
+ assertTrue(ipv6LoopbackIp.hashCode() == ipv6Localhost.hashCode());
}
@TestTargetNew(
@@ -1240,7 +1243,7 @@ public class Inet6AddressTest extends junit.framework.TestCase {
"/0:0:0:0:0:0:0:0"};
for(int i = 0; i < validIPAddresses.length; i++) {
- InetAddress ia = Inet6Address.getByName(validIPAddresses[i]);
+ InetAddress ia = InetAddress.getByName(validIPAddresses[i]);
String result = ia.toString();
assertNotNull(result);
//assertEquals("toString method returns incorrect value: " +
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
index 4275ef3..4a47db3 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetAddressTest.java
@@ -48,8 +48,14 @@ public class InetAddressTest extends junit.framework.TestCase {
protected static String threadedTestErrorString;
+ private Inet4Address ipv4Localhost;
+ private Inet4Address ipv4LoopbackIp;
+
@Override protected void setUp() throws Exception {
super.setUp();
+ byte[] ipv4Loopback = { 127, 0, 0, 1 };
+ ipv4LoopbackIp = (Inet4Address) InetAddress.getByAddress(ipv4Loopback);
+ ipv4Localhost = (Inet4Address) InetAddress.getByAddress("localhost", ipv4Loopback);
}
@Override protected void tearDown() throws Exception {
@@ -156,16 +162,7 @@ public class InetAddressTest extends junit.framework.TestCase {
)
public void test_equalsLjava_lang_Object() {
// Test for method boolean java.net.InetAddress.equals(java.lang.Object)
- try {
- InetAddress ia1 = InetAddress
- .getByName(Support_Configuration.InetTestAddress);
- InetAddress ia2 = InetAddress
- .getByName(Support_Configuration.InetTestIP);
- assertTrue("Equals returned incorrect result - " + ia1 + " != "
- + ia2, ia1.equals(ia2));
- } catch (Exception e) {
- fail("Exception during equals test : " + e.getMessage());
- }
+ assertTrue(ipv4Localhost.equals(ipv4LoopbackIp));
}
/**
@@ -310,18 +307,7 @@ public class InetAddressTest extends junit.framework.TestCase {
args = {}
)
public void test_getHostAddress() {
- // Test for method java.lang.String
- // java.net.InetAddress.getHostAddress()
- try {
- InetAddress ia2 = InetAddress
- .getByName(Support_Configuration.InetTestAddress);
- assertTrue("getHostAddress returned incorrect result: "
- + ia2.getHostAddress() + " != "
- + Support_Configuration.InetTestIP, ia2.getHostAddress()
- .equals(Support_Configuration.InetTestIP));
- } catch (Exception e) {
- fail("Exception during getHostAddress test : " + e.getMessage());
- }
+ assertTrue(ipv4Localhost.getHostAddress().equals("127.0.0.1"));
}
/**
@@ -351,26 +337,16 @@ public class InetAddressTest extends junit.framework.TestCase {
System.setProperty("networkaddress.cache.ttl", "0");
// Test for threadsafety
- InetAddress lookup1 = InetAddress
- .getByName(Support_Configuration.InetTestAddress);
- assertTrue(lookup1 + " expected "
- + Support_Configuration.InetTestIP,
- Support_Configuration.InetTestIP.equals(lookup1
- .getHostAddress()));
- InetAddress lookup2 = InetAddress
- .getByName(Support_Configuration.InetTestAddress2);
- assertTrue(lookup2 + " expected "
- + Support_Configuration.InetTestIP2,
- Support_Configuration.InetTestIP2.equals(lookup2
- .getHostAddress()));
+ assertTrue("127.0.0.1".equals(ipv4LoopbackIp.getHostAddress()));
+ assertTrue("127.0.0.1".equals(ipv4Localhost.getHostAddress()));
threadsafeTestThread thread1 = new threadsafeTestThread("1",
- lookup1.getHostName(), lookup1, 0);
+ ipv4LoopbackIp.getHostName(), ipv4LoopbackIp, 0);
threadsafeTestThread thread2 = new threadsafeTestThread("2",
- lookup2.getHostName(), lookup2, 0);
+ ipv4Localhost.getHostName(), ipv4Localhost, 0);
threadsafeTestThread thread3 = new threadsafeTestThread("3",
- lookup1.getHostAddress(), lookup1, 1);
+ ipv4LoopbackIp.getHostAddress(), ipv4LoopbackIp, 1);
threadsafeTestThread thread4 = new threadsafeTestThread("4",
- lookup2.getHostAddress(), lookup2, 1);
+ ipv4Localhost.getHostAddress(), ipv4Localhost, 1);
// initialize the flags
threadedTestSucceeded = true;
@@ -406,8 +382,7 @@ public class InetAddressTest extends junit.framework.TestCase {
try {
// We don't know the host name or ip of the machine
// running the test, so we can't build our own address
- DatagramSocket dg = new DatagramSocket(0, InetAddress
- .getLocalHost());
+ DatagramSocket dg = new DatagramSocket(0, InetAddress.getLocalHost());
assertTrue("Incorrect host returned", InetAddress.getLocalHost()
.equals(dg.getLocalAddress()));
dg.close();
@@ -486,14 +461,11 @@ public class InetAddressTest extends junit.framework.TestCase {
)
public void test_toString() throws Exception {
// Test for method java.lang.String java.net.InetAddress.toString()
- InetAddress ia2 = InetAddress
- .getByName(Support_Configuration.InetTestIP);
+ InetAddress ia2 = InetAddress.getByName(Support_Configuration.InetTestIP);
assertEquals("/" + Support_Configuration.InetTestIP, ia2.toString());
// Regression for HARMONY-84
- InetAddress addr = InetAddress.getByName("localhost");
- assertEquals("Assert 0: wrong string from name", "localhost/127.0.0.1", addr.toString());
- InetAddress addr2 = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
- assertEquals("Assert 1: wrong string from address", "/127.0.0.1", addr2.toString());
+ assertEquals("localhost/127.0.0.1", ipv4Localhost.toString());
+ assertEquals("/127.0.0.1", ipv4LoopbackIp.toString());
}
/**
@@ -547,12 +519,10 @@ public class InetAddressTest extends junit.framework.TestCase {
args = {}
)
public void test_getCanonicalHostName() throws Exception {
- InetAddress theAddress = null;
- theAddress = InetAddress.getLocalHost();
assertTrue("getCanonicalHostName returned a zero length string ",
- theAddress.getCanonicalHostName().length() != 0);
+ ipv4Localhost.getCanonicalHostName().length() != 0);
assertTrue("getCanonicalHostName returned an empty string ",
- !theAddress.equals(""));
+ !ipv4Localhost.equals(""));
// test against an expected value
InetAddress ia = InetAddress
@@ -578,11 +548,9 @@ public class InetAddressTest extends junit.framework.TestCase {
args = {int.class}
)
public void test_isReachableI() throws Exception {
- InetAddress ia = Inet4Address.getByName("127.0.0.1");
- assertTrue(ia.isReachable(10000));
- ia = Inet4Address.getByName("127.0.0.1");
+ assertTrue(ipv4LoopbackIp.isReachable(10000));
try {
- ia.isReachable(-1);
+ ipv4LoopbackIp.isReachable(-1);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// correct
@@ -602,23 +570,22 @@ public class InetAddressTest extends junit.framework.TestCase {
"behavior with WLAN and 3G networks")
public void test_isReachableLjava_net_NetworkInterfaceII() throws Exception {
// tests local address
- InetAddress ia = Inet4Address.getByName("127.0.0.1");
- assertTrue(ia.isReachable(null, 0, 10000));
- ia = Inet4Address.getByName("127.0.0.1");
+ assertTrue(ipv4LoopbackIp.isReachable(null, 0, 10000));
+ InetAddress ia;
try {
- ia.isReachable(null, -1, 10000);
+ ipv4LoopbackIp.isReachable(null, -1, 10000);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// correct
}
try {
- ia.isReachable(null, 0, -1);
+ ipv4LoopbackIp.isReachable(null, 0, -1);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// correct
}
try {
- ia.isReachable(null, -1, -1);
+ ipv4LoopbackIp.isReachable(null, -1, -1);
fail("Should throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
// correct
@@ -629,12 +596,11 @@ public class InetAddressTest extends junit.framework.TestCase {
assertFalse(ia.isReachable(null, 0, 1000));
// Regression test for HARMONY-1842.
- ia = InetAddress.getByName("localhost");
Enumeration<NetworkInterface> nif = NetworkInterface.getNetworkInterfaces();
NetworkInterface netif;
while(nif.hasMoreElements()) {
netif = nif.nextElement();
- ia.isReachable(netif, 10, 1000);
+ ipv4Localhost.isReachable(netif, 10, 1000);
}
}
@@ -706,9 +672,7 @@ public class InetAddressTest extends junit.framework.TestCase {
args = {}
)
public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(InetAddress.getByName("localhost"),
- COMPARATOR);
+ SerializationTest.verifySelf(ipv4Localhost, COMPARATOR);
}
/**
@@ -721,9 +685,7 @@ public class InetAddressTest extends junit.framework.TestCase {
args = {}
)
public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- InetAddress.getByName("localhost"), COMPARATOR);
+ SerializationTest.verifyGolden(this, ipv4Localhost, COMPARATOR);
}
/**
@@ -826,12 +788,11 @@ public class InetAddressTest extends junit.framework.TestCase {
)
public void test_isLoopbackAddress() throws Exception {
String addrName = "127.0.0.0";
- InetAddress addr = InetAddress.getByName(addrName);
- assertTrue("Loopback address " + addrName + " not detected.", addr
- .isLoopbackAddress());
+ assertTrue("Loopback address " + addrName + " not detected.",
+ ipv4LoopbackIp.isLoopbackAddress());
addrName = "127.42.42.42";
- addr = InetAddress.getByName(addrName);
+ InetAddress addr = InetAddress.getByName(addrName);
assertTrue("Loopback address " + addrName + " not detected.", addr
.isLoopbackAddress());
diff --git a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
index 0820108..724b8c0 100644
--- a/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
+++ b/luni/src/test/java/org/apache/harmony/luni/tests/java/net/InetSocketAddressTest.java
@@ -297,10 +297,10 @@ public class InetSocketAddressTest extends TestCase {
args = {}
)
public void testSerializationCompatibility() throws Exception {
-
+ InetAddress localhost = InetAddress.getByAddress("Localhost", new byte[]{127, 0, 0, 1});
Object[] testCases = {
InetSocketAddress.createUnresolved("badhost", 1000), // unresolved
- new InetSocketAddress("Localhost", 1000) };
+ new InetSocketAddress(localhost, 1000) };
SerializationTest.verifyGolden(this, testCases, COMPARATOR);
}
@@ -311,15 +311,16 @@ public class InetSocketAddressTest extends TestCase {
method = "equals",
args = {java.lang.Object.class}
)
- public void test_equals() {
+ public void test_equals() throws Exception {
InetSocketAddress isa1 = new InetSocketAddress(1);
InetSocketAddress isa2 = new InetSocketAddress(2);
assertFalse(isa1.equals(isa2));
InetSocketAddress isa3 = new InetSocketAddress(1);
assertTrue(isa1.equals(isa3));
- isa1 = new InetSocketAddress("localhost", 80);
- isa2 = new InetSocketAddress("127.0.0.1", 80);
+ InetAddress localhost = InetAddress.getByName("localhost");
+ isa1 = new InetSocketAddress(localhost.getHostName(), 80);
+ isa2 = new InetSocketAddress(localhost.getHostAddress(), 80);
assertTrue(isa1.equals(isa2));
}
@@ -358,9 +359,10 @@ public class InetSocketAddressTest extends TestCase {
method = "hashCode",
args = {}
)
- public void test_hashCode() {
- InetSocketAddress isa1 = new InetSocketAddress("localhost", 8080);
- InetSocketAddress isa2 = new InetSocketAddress("127.0.0.1", 8080);
+ public void test_hashCode() throws Exception {
+ InetAddress localhost = InetAddress.getByName("localhost");
+ InetSocketAddress isa1 = new InetSocketAddress(localhost.getHostName(), 8080);
+ InetSocketAddress isa2 = new InetSocketAddress(localhost.getHostAddress(), 8080);
assertTrue(isa1.hashCode() == isa2.hashCode());
InetSocketAddress isa3 = new InetSocketAddress("0.0.0.0", 8080);
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java
deleted file mode 100644
index 572f681..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AbstractBufferTest.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.InvalidMarkException;
-
-import junit.framework.TestCase;
-
-/**
- * Tests a java.nio.Buffer instance.
- */
-@TestTargetClass(java.nio.Buffer.class)
-public abstract class AbstractBufferTest extends TestCase {
-
- protected Buffer baseBuf;
- protected int capacity;
-
- protected void setUp() throws Exception{
- super.setUp();
- capacity = 10;
- baseBuf = ByteBuffer.allocate(10);
- }
-
- protected void tearDown() throws Exception{
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "capacity",
- args = {}
- )
- public void testCapacity() {
- assertTrue(0 <= baseBuf.position() && baseBuf.position() <= baseBuf.limit()
- && baseBuf.limit() <= baseBuf.capacity());
- assertEquals(capacity, baseBuf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "clear",
- args = {}
- )
- public void testClear() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- Buffer ret = baseBuf.clear();
- assertSame(ret, baseBuf);
- assertEquals(0, baseBuf.position());
- assertEquals(baseBuf.limit(), baseBuf.capacity());
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "flip",
- args = {}
- )
- public void testFlip() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- baseBuf.mark();
-
- Buffer ret = baseBuf.flip();
- assertSame(ret, baseBuf);
- assertEquals(0, baseBuf.position());
- assertEquals(oldPosition, baseBuf.limit());
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasRemaining",
- args = {}
- )
- public void testHasRemaining() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- assertEquals(baseBuf.hasRemaining(), baseBuf.position() < baseBuf.limit());
- baseBuf.position(baseBuf.limit());
- assertFalse(baseBuf.hasRemaining());
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public abstract void testIsReadOnly();
-
- /*
- * Class under test for int limit()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "limit",
- args = {}
- )
- public void testLimit() {
- assertTrue(0 <= baseBuf.position() && baseBuf.position() <= baseBuf.limit()
- && baseBuf.limit() <= baseBuf.capacity());
- assertEquals(capacity, baseBuf.limit());
- }
-
- /*
- * Class under test for Buffer limit(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "limit",
- args = {int.class}
- )
- public void testLimitint() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- Buffer ret = baseBuf.limit(baseBuf.limit());
- assertSame(ret, baseBuf);
-
- baseBuf.mark();
- baseBuf.limit(baseBuf.capacity());
- assertEquals(baseBuf.limit(), baseBuf.capacity());
- // position should not change
- assertEquals(oldPosition, baseBuf.position());
- // mark should be valid
- baseBuf.reset();
-
- assertTrue("The buffer capacity was 0", baseBuf.capacity() > 0);
- baseBuf.limit(baseBuf.capacity());
- baseBuf.position(baseBuf.capacity());
- baseBuf.mark();
- baseBuf.limit(baseBuf.capacity() - 1);
- // position should be the new limit
- assertEquals(baseBuf.limit(), baseBuf.position());
- // mark should be invalid
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- try {
- baseBuf.limit(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- baseBuf.limit(baseBuf.capacity() + 1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "mark",
- args = {}
- )
- public void testMark() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- Buffer ret = baseBuf.mark();
- assertSame(ret, baseBuf);
-
- baseBuf.mark();
- baseBuf.position(baseBuf.limit());
- baseBuf.reset();
- assertEquals(oldPosition, baseBuf.position());
-
- baseBuf.mark();
- baseBuf.position(baseBuf.limit());
- baseBuf.reset();
- assertEquals(oldPosition, baseBuf.position());
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- /*
- * Class under test for int position()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "position",
- args = {}
- )
- public void testPosition() {
- assertTrue(0 <= baseBuf.position() && baseBuf.position() <= baseBuf.limit()
- && baseBuf.limit() <= baseBuf.capacity());
- assertEquals(0, baseBuf.position());
- }
-
- /*
- * Class under test for Buffer position(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "position",
- args = {int.class}
- )
- public void testPositionint() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- try {
- baseBuf.position(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- baseBuf.position(baseBuf.limit() + 1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- baseBuf.mark();
- baseBuf.position(baseBuf.position());
- baseBuf.reset();
- assertEquals(oldPosition, baseBuf.position());
-
- baseBuf.position(0);
- assertEquals(0, baseBuf.position());
- baseBuf.position(baseBuf.limit());
- assertEquals(baseBuf.limit(), baseBuf.position());
-
- assertTrue("The buffer capacity was 0.", baseBuf.capacity() > 0);
- baseBuf.limit(baseBuf.capacity());
- baseBuf.position(baseBuf.limit());
- baseBuf.mark();
- baseBuf.position(baseBuf.limit() - 1);
- assertEquals(baseBuf.limit() - 1, baseBuf.position());
- // mark should be invalid
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- Buffer ret = baseBuf.position(0);
- assertSame(ret, baseBuf);
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "remaining",
- args = {}
- )
- public void testRemaining() {
- assertEquals(baseBuf.remaining(), baseBuf.limit() - baseBuf.position());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void testReset() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- baseBuf.mark();
- baseBuf.position(baseBuf.limit());
- baseBuf.reset();
- assertEquals(oldPosition, baseBuf.position());
-
- baseBuf.mark();
- baseBuf.position(baseBuf.limit());
- baseBuf.reset();
- assertEquals(oldPosition, baseBuf.position());
-
- Buffer ret = baseBuf.reset();
- assertSame(ret, baseBuf);
-
- baseBuf.clear();
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "rewind",
- args = {}
- )
- public void testRewind() {
- // save state
- int oldPosition = baseBuf.position();
- int oldLimit = baseBuf.limit();
-
- Buffer ret = baseBuf.rewind();
- assertEquals(0, baseBuf.position());
- assertSame(ret, baseBuf);
- try {
- baseBuf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // restore state
- baseBuf.limit(oldLimit);
- baseBuf.position(oldPosition);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java
deleted file mode 100644
index d1dcd3b..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/AllTests.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite for java.nio package
- *
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Tests for java.nio");
- //$JUnit-BEGIN$
- suite.addTestSuite(BufferOverflowExceptionTest.class);
- suite.addTestSuite(BufferUnderflowExceptionTest.class);
- suite.addTestSuite(ByteOrderTest.class);
- suite.addTestSuite(DirectByteBufferTest.class);
- suite.addTestSuite(DirectCharBufferTest.class);
- suite.addTestSuite(DirectDoubleBufferTest.class);
- suite.addTestSuite(DirectFloatBufferTest.class);
- suite.addTestSuite(DirectIntBufferTest.class);
- suite.addTestSuite(DirectLongBufferTest.class);
- suite.addTestSuite(DirectShortBufferTest.class);
- suite.addTestSuite(DuplicateDirectByteBufferTest.class);
- suite.addTestSuite(DuplicateHeapByteBufferTest.class);
- suite.addTestSuite(DuplicateWrappedByteBufferTest.class);
- suite.addTestSuite(HeapByteBufferTest.class);
- suite.addTestSuite(HeapCharBufferTest.class);
- suite.addTestSuite(HeapDoubleBufferTest.class);
- suite.addTestSuite(HeapFloatBufferTest.class);
- suite.addTestSuite(HeapIntBufferTest.class);
- suite.addTestSuite(HeapLongBufferTest.class);
- suite.addTestSuite(HeapShortBufferTest.class);
- suite.addTestSuite(InvalidMarkExceptionTest.class);
- suite.addTestSuite(MappedByteBufferTest.class);
- suite.addTestSuite(ReadOnlyBufferExceptionTest.class);
- suite.addTestSuite(ReadOnlyCharBufferTest.class);
- suite.addTestSuite(ReadOnlyDirectByteBufferTest.class);
- suite.addTestSuite(ReadOnlyDoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyFloatBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapByteBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapCharBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapDoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapFloatBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapIntBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapLongBufferTest.class);
- suite.addTestSuite(ReadOnlyHeapShortBufferTest.class);
- suite.addTestSuite(ReadOnlyIntBufferTest.class);
- suite.addTestSuite(ReadOnlyLongBufferTest.class);
- suite.addTestSuite(ReadOnlyShortBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedByteBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedCharBufferTest1.class);
- suite.addTestSuite(ReadOnlyWrappedDoubleBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedFloatBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedIntBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedLongBufferTest.class);
- suite.addTestSuite(ReadOnlyWrappedShortBufferTest.class);
- suite.addTestSuite(SliceDirectByteBufferTest.class);
- suite.addTestSuite(SliceHeapByteBufferTest.class);
- suite.addTestSuite(SliceWrappedByteBufferTest.class);
- suite.addTestSuite(WrappedByteBufferTest.class);
- suite.addTestSuite(WrappedCharBufferTest1.class);
- suite.addTestSuite(WrappedCharBufferTest2.class);
- suite.addTestSuite(WrappedDoubleBufferTest.class);
- suite.addTestSuite(WrappedFloatBufferTest.class);
- suite.addTestSuite(WrappedIntBufferTest.class);
- suite.addTestSuite(WrappedLongBufferTest.class);
- suite.addTestSuite(WrappedShortBufferTest.class);
- //$JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java
deleted file mode 100644
index 4951d1d..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferOverflowExceptionTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.BufferOverflowException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(BufferOverflowException.class)
-public class BufferOverflowExceptionTest extends TestCase {
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility. And tests default constructor",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferOverflowException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new BufferOverflowException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferOverflowException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new BufferOverflowException());
- }
-
- /**
- *@tests {@link java.nio.BufferOverflowException#BufferOverflowException()}
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferOverflowException",
- args = {}
- )
- public void test_Constructor() {
- BufferOverflowException exception = new BufferOverflowException();
- assertNull(exception.getMessage());
- assertNull(exception.getLocalizedMessage());
- assertNull(exception.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java
deleted file mode 100644
index 72525a4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/BufferUnderflowExceptionTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.BufferUnderflowException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for BufferUnderflowException
- */
-@TestTargetClass(BufferUnderflowException.class)
-public class BufferUnderflowExceptionTest extends TestCase {
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferUnderflowException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new BufferUnderflowException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferUnderflowException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new BufferUnderflowException());
- }
-
- /**
- *@tests {@link java.nio.BufferUnderflowException#BufferUnderflowException()}
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "BufferUnderflowException",
- args = {}
- )
- public void test_Constructor() {
- BufferUnderflowException exception = new BufferUnderflowException();
- assertNull(exception.getMessage());
- assertNull(exception.getLocalizedMessage());
- assertNull(exception.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java
deleted file mode 100644
index 82bf938..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteBufferTest.java
+++ /dev/null
@@ -1,2822 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.CharBuffer;
-import java.nio.DoubleBuffer;
-import java.nio.FloatBuffer;
-import java.nio.IntBuffer;
-import java.nio.InvalidMarkException;
-import java.nio.LongBuffer;
-import java.nio.ReadOnlyBufferException;
-import java.nio.ShortBuffer;
-import java.util.Arrays;
-
-/**
- * Tests java.nio.ByteBuffer
- *
- */
-@TestTargetClass(ByteBuffer.class)
-public abstract class ByteBufferTest extends AbstractBufferTest {
- protected static final int SMALL_TEST_LENGTH = 5;
- protected static final int BUFFER_LENGTH = 250;
-
- protected ByteBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static ByteBuffer allocate(int capacity)
- * test covers following usecases:
- * 1. case for check ByteBuffer testBuf properties
- * 2. case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: ByteBuffer testBuf properties is satisfy the conditions
- // specification
- ByteBuffer testBuf = ByteBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = ByteBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = ByteBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- /*
- * test for method static ByteBuffer allocateDirect(int capacity)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocateDirect",
- args = {int.class}
- )
- public void test_AllocateDirectI() {
- // case: ByteBuffer testBuf properties is satisfy the conditions
- // specification
- ByteBuffer testBuf = ByteBuffer.allocateDirect(20);
- assertEquals(0, testBuf.position());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = ByteBuffer.allocateDirect(0);
- assertEquals(0, testBuf.position());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- try {
- testBuf.array();
- fail("Didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- //expected
- }
-
- try {
- testBuf.arrayOffset();
- fail("Didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException e) {
- //expected
- }
-
- // case: expected IllegalArgumentException
- try {
- testBuf = ByteBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- byte array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- byte array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = (byte) i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- ByteBuffer wrapped = ByteBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- loadTestData1(buf);
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- ByteBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(0, readonly.position());
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(0, buf.position());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
- if (buf.isReadOnly()) {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- ByteBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.capacity(), buf.position());
- assertEquals(buf.capacity(), buf.limit());
- assertContentLikeTestData1(buf, 0, (byte) 0, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(0, buf.position());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (byte) 0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- buf.position(1);
- buf.limit(SMALL_TEST_LENGTH);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(4, buf.position());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (byte) 1, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.ByteBuffer.class}
- )
- public void testCompareTo() {
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- // normal cases
- if (!buf.isReadOnly()) {
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- buf.clear();
- ByteBuffer other = ByteBuffer.allocate(buf.capacity());
- loadTestData1(buf);
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(SMALL_TEST_LENGTH);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
-
- assertTrue(ByteBuffer.wrap(new byte[21]).compareTo(ByteBuffer.allocateDirect(21)) == 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- ByteBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(0, duplicate.position());
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(0, buf.position());
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- loadTestData1(buf);
-
- // equal to self
- assertTrue(buf.equals(buf));
- ByteBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- ByteBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(1);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for byte get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- loadTestData1(buf);
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(i, buf.position());
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ByteBuffer get(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {byte[].class}
- )
- public void testGetbyteArray() {
- byte array[] = new byte[1];
- loadTestData1(buf);
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(i, buf.position());
- ByteBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i));
- assertSame(ret, buf);
- }
-
- buf.get(new byte[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((byte[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ByteBuffer get(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {byte[].class, int.class, int.class}
- )
- public void testGetbyteArrayintint() {
- loadTestData1(buf);
- buf.clear();
- byte array[] = new byte[buf.capacity()];
-
- try {
- buf.get(new byte[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(0, buf.position());
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(0, buf.position());
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((byte[])null, -1, 0);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(0, buf.position());
-
- buf.clear();
- ByteBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for byte get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- loadTestData1(buf);
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(i, buf.position());
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for wrapped ByteBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertTrue(buf.hasArray());
- assertNotNull(buf.array());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- loadTestData1(buf);
- ByteBuffer readonly = buf.asReadOnlyBuffer();
- ByteBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- duplicate.position(buf.capacity()/2);
- assertTrue(buf.hashCode()!= duplicate.hashCode());
- }
-
- //for the testHashCode() method of readonly subclasses
- protected void readOnlyHashCode(boolean direct) {
- //create a new buffer initiated with some data
- ByteBuffer buf;
- if (direct) {
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH);
- } else {
- buf = ByteBuffer.allocate(BUFFER_LENGTH);
- }
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- buf.clear();
- ByteBuffer readonly = buf.asReadOnlyBuffer();
- ByteBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(),readonly.hashCode());
- duplicate.position(buf.capacity()/2);
- assertTrue(buf.hashCode()!= duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method with not direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- // BIG_ENDIAN is the default byte order
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
-
- buf.order(ByteOrder.LITTLE_ENDIAN);
- assertEquals(ByteOrder.LITTLE_ENDIAN, buf.order());
-
- buf.order(ByteOrder.BIG_ENDIAN);
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
-
- // Regression test for HARMONY-798
- buf.order((ByteOrder)null);
- assertEquals(ByteOrder.LITTLE_ENDIAN, buf.order());
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- /*
- * test for method public final ByteBuffer order(ByteOrder bo)
- * test covers following usecases:
- * 1. case for check
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {java.nio.ByteOrder.class}
- )
- public void test_OrderLjava_lang_ByteOrder() {
- // BIG_ENDIAN is the default byte order
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
-
- buf.order(ByteOrder.LITTLE_ENDIAN);
- assertEquals(ByteOrder.LITTLE_ENDIAN, buf.order());
-
- buf.order(ByteOrder.BIG_ENDIAN);
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
-
- // Regression test for HARMONY-798
- buf.order((ByteOrder)null);
- assertEquals(ByteOrder.LITTLE_ENDIAN, buf.order());
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- /*
- * Class under test for java.nio.ByteBuffer put(byte)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {byte.class}
- )
- public void testPutbyte() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.put((byte) 0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(i, buf.position());
- ByteBuffer ret = buf.put((byte) i);
- assertEquals((byte) i, buf.get(i));
- assertSame(ret, buf);
- }
- try {
- buf.put((byte) 0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.rewind();
- buf.put(Byte.MAX_VALUE);
- assertEquals(Byte.MAX_VALUE, buf.get(0));
- buf.rewind();
- buf.put(Byte.MIN_VALUE);
- assertEquals(Byte.MIN_VALUE, buf.get(0));
- }
-
- /*
- * Class under test for java.nio.ByteBuffer put(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {byte[].class}
- )
- public void testPutbyteArray() {
- byte array[] = new byte[1];
- if (buf.isReadOnly()) {
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(i, buf.position());
- array[0] = (byte) i;
- ByteBuffer ret = buf.put(array);
- assertEquals((byte) i, buf.get(i));
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.put((byte[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ByteBuffer put(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {byte[].class, int.class, int.class}
- )
- public void testPutbyteArrayintint() {
- buf.clear();
- byte array[] = new byte[buf.capacity()];
- if (buf.isReadOnly()) {
- try {
- buf.put(array, 0, array.length);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- try {
- buf.put(new byte[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(0, buf.position());
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(0, buf.position());
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- buf.put(array, 2, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((byte[])null, 2, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- assertEquals(0, buf.position());
-
- loadTestData2(array, 0, array.length);
- ByteBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.ByteBuffer put(java.nio.ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {java.nio.ByteBuffer.class}
- )
- public void testPutByteBuffer() {
- ByteBuffer other = ByteBuffer.allocate(buf.capacity());
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.put(other);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.clear();
- buf.put((ByteBuffer)null);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(ByteBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- try {
- buf.put((ByteBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- loadTestData2(other);
- other.clear();
- buf.clear();
- ByteBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.ByteBuffer put(int, byte)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {int.class, byte.class}
- )
- public void testPutintbyte() {
- if (buf.isReadOnly()) {
- try {
- buf.put(0, (byte) 0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(0, buf.position());
- ByteBuffer ret = buf.put(i, (byte) i);
- assertEquals((byte) i, buf.get(i));
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, (byte) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), (byte) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.put(0, Byte.MAX_VALUE);
- assertEquals(Byte.MAX_VALUE, buf.get(0));
- buf.put(0, Byte.MIN_VALUE);
- assertEquals(Byte.MIN_VALUE, buf.get(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- loadTestData1(buf);
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- ByteBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(0, slice.position());
- assertEquals(buf.remaining(), slice.limit());
- assertEquals(buf.remaining(), slice.capacity());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, (byte) 0, slice.capacity());
- buf.put(2, (byte) 100);
- assertEquals(100, slice.get(1));
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Byte") >= 0 || str.indexOf("byte") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asCharBuffer",
- args = {}
- )
- public void testAsCharBuffer() {
- CharBuffer charBuffer;
- byte bytes[] = new byte[2];
- char value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN char buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- charBuffer = buf.asCharBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, charBuffer.order());
- while (charBuffer.remaining() > 0) {
- buf.get(bytes);
- value = charBuffer.get();
- assertEquals(bytes2char(bytes, buf.order()), value);
- }
-
- // test LITTLE_ENDIAN char buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- charBuffer = buf.asCharBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, charBuffer.order());
- while (charBuffer.remaining() > 0) {
- buf.get(bytes);
- value = charBuffer.get();
- assertEquals(bytes2char(bytes, buf.order()), value);
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN char buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- charBuffer = buf.asCharBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, charBuffer.order());
- while (charBuffer.remaining() > 0) {
- value = (char) charBuffer.remaining();
- charBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, char2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN char buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- charBuffer = buf.asCharBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, charBuffer.order());
- while (charBuffer.remaining() > 0) {
- value = (char) charBuffer.remaining();
- charBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, char2bytes(value, buf.order())));
- }
- }
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asDoubleBuffer",
- args = {}
- )
- public void testAsDoubleBuffer() {
- DoubleBuffer doubleBuffer;
- byte bytes[] = new byte[8];
- double value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN double buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- doubleBuffer = buf.asDoubleBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.order());
- while (doubleBuffer.remaining() > 0) {
- buf.get(bytes);
- value = doubleBuffer.get();
- if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
- .isNaN(value))) {
- assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
- }
- }
-
- // test LITTLE_ENDIAN double buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- doubleBuffer = buf.asDoubleBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.order());
- while (doubleBuffer.remaining() > 0) {
- buf.get(bytes);
- value = doubleBuffer.get();
- if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
- .isNaN(value))) {
- assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
- }
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN double buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- doubleBuffer = buf.asDoubleBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, doubleBuffer.order());
- while (doubleBuffer.remaining() > 0) {
- value = doubleBuffer.remaining();
- doubleBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN double buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- doubleBuffer = buf.asDoubleBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, doubleBuffer.order());
- while (doubleBuffer.remaining() > 0) {
- value = doubleBuffer.remaining();
- doubleBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, double2bytes(value, buf.order())));
- }
- }
-
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asFloatBuffer",
- args = {}
- )
- public void testAsFloatBuffer() {
- FloatBuffer floatBuffer;
- byte bytes[] = new byte[4];
- float value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN float buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- floatBuffer = buf.asFloatBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, floatBuffer.order());
- while (floatBuffer.remaining() > 0) {
- buf.get(bytes);
- value = floatBuffer.get();
- if (!(Float.isNaN(bytes2float(bytes, buf.order())) && Float
- .isNaN(value))) {
- assertEquals(bytes2float(bytes, buf.order()), value, 0.00);
- }
- }
-
- // test LITTLE_ENDIAN float buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- floatBuffer = buf.asFloatBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, floatBuffer.order());
- while (floatBuffer.remaining() > 0) {
- buf.get(bytes);
- value = floatBuffer.get();
- if (!(Float.isNaN(bytes2float(bytes, buf.order())) && Float
- .isNaN(value))) {
- assertEquals(bytes2float(bytes, buf.order()), value, 0.00);
- }
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN float buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- floatBuffer = buf.asFloatBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, floatBuffer.order());
- while (floatBuffer.remaining() > 0) {
- value = floatBuffer.remaining();
- floatBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, float2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN float buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- floatBuffer = buf.asFloatBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, floatBuffer.order());
- while (floatBuffer.remaining() > 0) {
- value = floatBuffer.remaining();
- floatBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, float2bytes(value, buf.order())));
- }
- }
-
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asIntBuffer",
- args = {}
- )
- public void testAsIntBuffer() {
- IntBuffer intBuffer;
- byte bytes[] = new byte[4];
- int value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN int buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- intBuffer = buf.asIntBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, intBuffer.order());
- while (intBuffer.remaining() > 0) {
- buf.get(bytes);
- value = intBuffer.get();
- assertEquals(bytes2int(bytes, buf.order()), value);
- }
-
- // test LITTLE_ENDIAN int buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- intBuffer = buf.asIntBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, intBuffer.order());
- while (intBuffer.remaining() > 0) {
- buf.get(bytes);
- value = intBuffer.get();
- assertEquals(bytes2int(bytes, buf.order()), value);
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN int buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- intBuffer = buf.asIntBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, intBuffer.order());
- while (intBuffer.remaining() > 0) {
- value = intBuffer.remaining();
- intBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, int2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN int buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- intBuffer = buf.asIntBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, intBuffer.order());
- while (intBuffer.remaining() > 0) {
- value = intBuffer.remaining();
- intBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, int2bytes(value, buf.order())));
- }
- }
-
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asLongBuffer",
- args = {}
- )
- public void testAsLongBuffer() {
- LongBuffer longBuffer;
- byte bytes[] = new byte[8];
- long value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN long buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- longBuffer = buf.asLongBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
- while (longBuffer.remaining() > 0) {
- buf.get(bytes);
- value = longBuffer.get();
- assertEquals(bytes2long(bytes, buf.order()), value);
- }
-
- // test LITTLE_ENDIAN long buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- longBuffer = buf.asLongBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
- while (longBuffer.remaining() > 0) {
- buf.get(bytes);
- value = longBuffer.get();
- assertEquals(bytes2long(bytes, buf.order()), value);
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN long buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- longBuffer = buf.asLongBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, longBuffer.order());
- while (longBuffer.remaining() > 0) {
- value = longBuffer.remaining();
- longBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN long buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- longBuffer = buf.asLongBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, longBuffer.order());
- while (longBuffer.remaining() > 0) {
- value = longBuffer.remaining();
- longBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, long2bytes(value, buf.order())));
- }
- }
-
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asShortBuffer",
- args = {}
- )
- public void testAsShortBuffer() {
- ShortBuffer shortBuffer;
- byte bytes[] = new byte[2];
- short value;
- loadTestData1(buf);
-
- // test BIG_ENDIAN short buffer, read
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- shortBuffer = buf.asShortBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, shortBuffer.order());
- while (shortBuffer.remaining() > 0) {
- buf.get(bytes);
- value = shortBuffer.get();
- assertEquals(bytes2short(bytes, buf.order()), value);
- }
-
- // test LITTLE_ENDIAN short buffer, read
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- shortBuffer = buf.asShortBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, shortBuffer.order());
- while (shortBuffer.remaining() > 0) {
- buf.get(bytes);
- value = shortBuffer.get();
- assertEquals(bytes2short(bytes, buf.order()), value);
- }
-
- if (!buf.isReadOnly()) {
- // test BIG_ENDIAN short buffer, write
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- shortBuffer = buf.asShortBuffer();
- assertSame(ByteOrder.BIG_ENDIAN, shortBuffer.order());
- while (shortBuffer.remaining() > 0) {
- value = (short) shortBuffer.remaining();
- shortBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, short2bytes(value, buf.order())));
- }
-
- // test LITTLE_ENDIAN short buffer, write
- buf.clear();
- buf.order(ByteOrder.LITTLE_ENDIAN);
- shortBuffer = buf.asShortBuffer();
- assertSame(ByteOrder.LITTLE_ENDIAN, shortBuffer.order());
- while (shortBuffer.remaining() > 0) {
- value = (short) shortBuffer.remaining();
- shortBuffer.put(value);
- buf.get(bytes);
- assertTrue(Arrays.equals(bytes, short2bytes(value, buf.order())));
- }
- }
-
- buf.clear();
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getChar",
- args = {}
- )
- public void testGetChar() {
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- char value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getChar();
- assertEquals(bytes2char(bytes, buf.order()), value);
- }
-
- try {
- buf.getChar();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getChar",
- args = {int.class}
- )
- public void testGetCharint() {
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- char value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getChar(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertEquals(bytes2char(bytes, buf.order()), value);
- }
-
- try {
- buf.getChar(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getChar(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putChar",
- args = {char.class}
- )
- public void testPutChar() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putChar((char) 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- char value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = (char) i;
- buf.mark();
- buf.putChar(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(char2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putChar(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putChar(0, Character.MAX_VALUE);
- assertEquals(Character.MAX_VALUE, buf.getChar(0));
- buf.rewind();
- buf.putChar(0, Character.MIN_VALUE);
- assertEquals(Character.MIN_VALUE, buf.getChar(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putChar",
- args = {int.class, char.class}
- )
- public void testPutCharint() {
- if (buf.isReadOnly()) {
- try {
- buf.putChar(0, (char) 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- char value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = (char) i;
- buf.position(i);
- buf.putChar(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(char2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putChar(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putChar(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- try {
- ByteBuffer.allocateDirect(16).putChar(Integer.MAX_VALUE, 'h');
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- buf.putChar(0, Character.MAX_VALUE);
- assertEquals(Character.MAX_VALUE, buf.getChar(0));
- buf.putChar(0, Character.MIN_VALUE);
- assertEquals(Character.MIN_VALUE, buf.getChar(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getDouble",
- args = {}
- )
- public void testGetDouble() {
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- double value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getDouble();
- if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
- .isNaN(value))) {
- assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
- }
- }
-
- try {
- buf.getDouble();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getDouble",
- args = {int.class}
- )
- public void testGetDoubleint() {
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- double value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getDouble(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- if (!(Double.isNaN(bytes2double(bytes, buf.order())) && Double
- .isNaN(value))) {
- assertEquals(bytes2double(bytes, buf.order()), value, 0.00);
- }
- }
-
- try {
- buf.getDouble(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getDouble(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- try {
- ByteBuffer.allocateDirect(16).getDouble(Integer.MAX_VALUE);
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putDouble",
- args = {double.class}
- )
- public void testPutDouble() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putDouble(1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- double value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.mark();
- buf.putDouble(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(double2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putDouble(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putDouble(Double.MAX_VALUE);
- assertEquals(Double.MAX_VALUE, buf.getDouble(0));
- buf.rewind();
- buf.putDouble(Double.MIN_VALUE);
- assertEquals(Double.MIN_VALUE, buf.getDouble(0));
- buf.rewind();
- buf.putDouble(Double.NaN);
- assertEquals(Double.NaN, buf.getDouble(0));
- buf.rewind();
- buf.putDouble(Double.NEGATIVE_INFINITY);
- assertEquals(Double.NEGATIVE_INFINITY, buf.getDouble(0));
- buf.rewind();
- buf.putDouble(Double.POSITIVE_INFINITY);
- assertEquals(Double.POSITIVE_INFINITY, buf.getDouble(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putDouble",
- args = {int.class, double.class}
- )
- public void testPutDoubleint() {
- if (buf.isReadOnly()) {
- try {
- buf.putDouble(0, 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- double value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.position(i);
- buf.putDouble(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(double2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putDouble(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putDouble(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putDouble(0, Double.MAX_VALUE);
- assertEquals(Double.MAX_VALUE, buf.getDouble(0));
- buf.putDouble(0, Double.MIN_VALUE);
- assertEquals(Double.MIN_VALUE, buf.getDouble(0));
- buf.putDouble(0, Double.NaN);
- assertEquals(Double.NaN, buf.getDouble(0));
- buf.putDouble(0, Double.NEGATIVE_INFINITY);
- assertEquals(Double.NEGATIVE_INFINITY, buf.getDouble(0));
- buf.putDouble(0, Double.POSITIVE_INFINITY);
- assertEquals(Double.POSITIVE_INFINITY, buf.getDouble(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getFloat",
- args = {}
- )
- public void testGetFloat() {
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- float value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getFloat();
- if (!(Float.isNaN(bytes2float(bytes, buf.order())) && Float
- .isNaN(value))) {
- assertEquals(bytes2float(bytes, buf.order()), value, 0.00);
- }
- }
-
- try {
- buf.getFloat();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getFloat",
- args = {int.class}
- )
- public void testGetFloatint() {
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- float value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getFloat(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- if (!(Float.isNaN(bytes2float(bytes, buf.order())) && Float
- .isNaN(value))) {
- assertEquals(bytes2float(bytes, buf.order()), value, 0.00);
- }
- }
-
- try {
- buf.getFloat(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getFloat(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putFloat",
- args = {float.class}
- )
- public void testPutFloat() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putFloat(1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- float value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.mark();
- buf.putFloat(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(float2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putFloat(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putFloat(Float.MAX_VALUE);
- assertEquals(Float.MAX_VALUE, buf.getFloat(0));
- buf.rewind();
- buf.putFloat(Float.MIN_VALUE);
- assertEquals(Float.MIN_VALUE, buf.getFloat(0));
- buf.rewind();
- buf.putFloat(Float.NaN);
- assertEquals(Float.NaN, buf.getFloat(0));
- buf.rewind();
- buf.putFloat(Float.NEGATIVE_INFINITY);
- assertEquals(Float.NEGATIVE_INFINITY, buf.getFloat(0));
- buf.rewind();
- buf.putFloat(Float.POSITIVE_INFINITY);
- assertEquals(Float.POSITIVE_INFINITY, buf.getFloat(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putFloat",
- args = {int.class, float.class}
- )
- public void testPutFloatint() {
- if (buf.isReadOnly()) {
- try {
- buf.putFloat(0, 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- float value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.position(i);
- buf.putFloat(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(float2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putFloat(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putFloat(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putFloat(0, Float.MAX_VALUE);
- assertEquals(Float.MAX_VALUE, buf.getFloat(0));
- buf.putFloat(0, Float.MIN_VALUE);
- assertEquals(Float.MIN_VALUE, buf.getFloat(0));
- buf.putFloat(0, Float.NaN);
- assertEquals(Float.NaN, buf.getFloat(0));
- buf.putFloat(0, Float.NEGATIVE_INFINITY);
- assertEquals(Float.NEGATIVE_INFINITY, buf.getFloat(0));
- buf.putFloat(0, Float.POSITIVE_INFINITY);
- assertEquals(Float.POSITIVE_INFINITY, buf.getFloat(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getInt",
- args = {}
- )
- public void testGetInt() {
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- int value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getInt();
- assertEquals(bytes2int(bytes, buf.order()), value);
- }
-
- try {
- buf.getInt();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getInt",
- args = {int.class}
- )
- public void testGetIntint() {
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- int value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getInt(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertEquals(bytes2int(bytes, buf.order()), value);
- }
-
- try {
- buf.getInt(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getInt(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- try {
- ByteBuffer.allocateDirect(16).getInt(Integer.MAX_VALUE);
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putInt",
- args = {int.class}
- )
- public void testPutInt() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putInt(1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- int value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.mark();
- buf.putInt(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(int2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putInt(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putInt(Integer.MAX_VALUE);
- assertEquals(Integer.MAX_VALUE, buf.getInt(0));
- buf.rewind();
- buf.putInt(Integer.MIN_VALUE);
- assertEquals(Integer.MIN_VALUE, buf.getInt(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putInt",
- args = {int.class, int.class}
- )
- public void testPutIntint() {
- if (buf.isReadOnly()) {
- try {
- buf.putInt(0, 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 4;
- byte bytes[] = new byte[nbytes];
- int value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.position(i);
- buf.putInt(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(int2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putInt(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putInt(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putInt(0, Integer.MAX_VALUE);
- assertEquals(Integer.MAX_VALUE, buf.getInt(0));
- buf.putInt(0, Integer.MIN_VALUE);
- assertEquals(Integer.MIN_VALUE, buf.getInt(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getLong",
- args = {}
- )
- public void testGetLong() {
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- long value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getLong();
- assertEquals(bytes2long(bytes, buf.order()), value);
- }
-
- try {
- buf.getLong();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getLong",
- args = {int.class}
- )
- public void testGetLongint() {
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- long value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getLong(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertEquals(bytes2long(bytes, buf.order()), value);
- }
-
- try {
- buf.getLong(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getLong(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putLong",
- args = {long.class}
- )
- public void testPutLong() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putLong(1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- long value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.mark();
- buf.putLong(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(long2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putLong(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putLong(Long.MAX_VALUE);
- assertEquals(Long.MAX_VALUE, buf.getLong(0));
- buf.rewind();
- buf.putLong(Long.MIN_VALUE);
- assertEquals(Long.MIN_VALUE, buf.getLong(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putLong",
- args = {int.class, long.class}
- )
- public void testPutLongint() {
- if (buf.isReadOnly()) {
- try {
- buf.putLong(0, 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 8;
- byte bytes[] = new byte[nbytes];
- long value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = i;
- buf.position(i);
- buf.putLong(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(long2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putLong(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putLong(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putLong(0, Long.MAX_VALUE);
- assertEquals(Long.MAX_VALUE, buf.getLong(0));
- buf.putLong(0, Long.MIN_VALUE);
- assertEquals(Long.MIN_VALUE, buf.getLong(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getShort",
- args = {}
- )
- public void testGetShort() {
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- short value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- assertEquals(i * nbytes, buf.position());
- buf.mark();
- buf.get(bytes);
- buf.reset();
- value = buf.getShort();
- assertEquals(bytes2short(bytes, buf.order()), value);
- }
-
- try {
- buf.getShort();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getShort",
- args = {int.class}
- )
- public void testGetShortint() {
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- short value;
- loadTestData1(buf);
-
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- buf.position(i);
- value = buf.getShort(i);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertEquals(bytes2short(bytes, buf.order()), value);
- }
-
- try {
- buf.getShort(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.getShort(buf.limit() - nbytes + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putShort",
- args = {short.class}
- )
- public void testPutShort() {
- if (buf.isReadOnly()) {
- try {
- buf.clear();
- buf.putShort((short) 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- short value = 0;
- buf.clear();
- for (int i = 0; buf.remaining() >= nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = (short) i;
- buf.mark();
- buf.putShort(value);
- assertEquals((i + 1) * nbytes, buf.position());
- buf.reset();
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(short2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putShort(value);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.rewind();
- buf.putShort(Short.MAX_VALUE);
- assertEquals(Short.MAX_VALUE, buf.getShort(0));
- buf.rewind();
- buf.putShort(Short.MIN_VALUE);
- assertEquals(Short.MIN_VALUE, buf.getShort(0));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "putShort",
- args = {int.class, short.class}
- )
- public void testPutShortint() {
- if (buf.isReadOnly()) {
- try {
- buf.putShort(0, (short) 1);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- return;
- }
-
- int nbytes = 2;
- byte bytes[] = new byte[nbytes];
- short value = 0;
- buf.clear();
- for (int i = 0; i <= buf.limit() - nbytes; i++) {
- buf.order(i % 2 == 0 ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN);
- value = (short) i;
- buf.position(i);
- buf.putShort(i, value);
- assertEquals(i, buf.position());
- buf.get(bytes);
- assertTrue("Wrong value at " + i,
- Arrays.equals(short2bytes(value, buf.order()), bytes));
- }
-
- try {
- buf.putShort(-1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.putShort(buf.limit() - nbytes + 1, value);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- buf.order(ByteOrder.BIG_ENDIAN);
-
- buf.putShort(0, Short.MAX_VALUE);
- assertEquals(Short.MAX_VALUE, buf.getShort(0));
- buf.putShort(0, Short.MIN_VALUE);
- assertEquals(Short.MIN_VALUE, buf.getShort(0));
- }
-
- /**
- * @tests java.nio.ByteBuffer.wrap(byte[],int,int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test. Verifies NullPointerException, IndexOutOfBoundsException.",
- method = "wrap",
- args = {byte[].class, int.class, int.class}
- )
- public void testWrappedByteBuffer_null_array() {
- // Regression for HARMONY-264
- byte array[] = null;
- try {
- ByteBuffer.wrap(array, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
- try {
- ByteBuffer.wrap(new byte[10], Integer.MAX_VALUE, 2);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- }
- }
-
- /*
- * test for method static ByteBuffer wrap(byte[] array)
- * test covers following usecases:
- * 1. case for check ByteBuffer buf2 properties
- * 2. case for check equal between buf2 and byte array[]
- * 3. case for check a buf2 dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {byte[].class}
- )
- public void test_Wrap$B() {
- byte array[] = new byte[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- ByteBuffer buf2 = ByteBuffer.wrap(array);
-
- // case: ByteBuffer buf2 properties is satisfy the conditions specification
- assertEquals(array.length, buf2.capacity());
- assertEquals(array.length, buf2.limit());
- assertEquals(0, buf2.position());
-
- // case: ByteBuffer buf2 is equal to byte array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: ByteBuffer buf2 is depended to byte array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static ByteBuffer wrap(byte[] array, int offset, int length)
- * test covers following usecases:
- * 1. case for check ByteBuffer buf2 properties
- * 2. case for check equal between buf2 and byte array[]
- * 3. case for check a buf2 dependens to array[]
- * 4. case expected IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {byte[].class, int.class, int.class}
- )
- public void test_Wrap$BII() {
- byte array[] = new byte[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- ByteBuffer buf2 = ByteBuffer.wrap(array, offset, length);
-
- // case: ByteBuffer buf2 properties is satisfy the conditions specification
- assertEquals(array.length, buf2.capacity());
- assertEquals(offset, buf2.position());
- assertEquals(offset + length, buf2.limit());
- assertEquals(0, buf2.arrayOffset());
-
- // case: ByteBuffer buf2 is equal to byte array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: ByteBuffer buf2 is depended to byte array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = ByteBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- protected void loadTestData1(byte array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (byte) i;
- }
- }
-
- protected void loadTestData2(byte array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (byte) (length - i);
- }
- }
-
- protected void loadTestData1(ByteBuffer buf) {
- if (buf.isReadOnly()) {
- return;
- }
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (byte) i);
- }
- }
-
- protected void loadTestData2(ByteBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (byte) (buf.capacity() - i));
- }
- }
-
- private void assertContentEquals(ByteBuffer buf, byte array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(array[offset + i], buf.get(i));
- }
- }
-
- private void assertContentEquals(ByteBuffer buf, ByteBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i));
- }
- }
-
- private void assertContentLikeTestData1(ByteBuffer buf,
- int startIndex, byte startValue, int length) {
- byte value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value);
- value = (byte) (value + 1);
- }
- }
-
- private int bytes2int(byte bytes[], ByteOrder order) {
- int nbytes = 4, bigHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- bigHead = 0;
- step = 1;
- } else {
- bigHead = nbytes - 1;
- step = -1;
- }
- int result = 0;
- int p = bigHead;
- for (int i = 0; i < nbytes; i++) {
- result = result << 8;
- result = result | (bytes[p] & 0xff);
- p += step;
- }
- return result;
- }
-
- private long bytes2long(byte bytes[], ByteOrder order) {
- int nbytes = 8, bigHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- bigHead = 0;
- step = 1;
- } else {
- bigHead = nbytes - 1;
- step = -1;
- }
- long result = 0;
- int p = bigHead;
- for (int i = 0; i < nbytes; i++) {
- result = result << 8;
- result = result | (bytes[p] & 0xff);
- p += step;
- }
- return result;
- }
-
- private short bytes2short(byte bytes[], ByteOrder order) {
- int nbytes = 2, bigHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- bigHead = 0;
- step = 1;
- } else {
- bigHead = nbytes - 1;
- step = -1;
- }
- short result = 0;
- int p = bigHead;
- for (int i = 0; i < nbytes; i++) {
- result = (short) (result << 8);
- result = (short) (result | (bytes[p] & 0xff));
- p += step;
- }
- return result;
- }
-
- private char bytes2char(byte bytes[], ByteOrder order) {
- return (char) bytes2short(bytes, order);
- }
-
- private float bytes2float(byte bytes[], ByteOrder order) {
- return Float.intBitsToFloat(bytes2int(bytes, order));
- }
-
- private double bytes2double(byte bytes[], ByteOrder order) {
- return Double.longBitsToDouble(bytes2long(bytes, order));
- }
-
- private byte[] int2bytes(int value, ByteOrder order) {
- int nbytes = 4, smallHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- smallHead = nbytes - 1;
- step = -1;
- } else {
- smallHead = 0;
- step = 1;
- }
- byte bytes[] = new byte[nbytes];
- int p = smallHead;
- for (int i = 0; i < nbytes; i++) {
- bytes[p] = (byte) (value & 0xff);
- value = value >> 8;
- p += step;
- }
- return bytes;
- }
-
- private byte[] long2bytes(long value, ByteOrder order) {
- int nbytes = 8, smallHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- smallHead = nbytes - 1;
- step = -1;
- } else {
- smallHead = 0;
- step = 1;
- }
- byte bytes[] = new byte[nbytes];
- int p = smallHead;
- for (int i = 0; i < nbytes; i++) {
- bytes[p] = (byte) (value & 0xff);
- value = value >> 8;
- p += step;
- }
- return bytes;
- }
-
- private byte[] short2bytes(short value, ByteOrder order) {
- int nbytes = 2, smallHead, step;
- if (order == ByteOrder.BIG_ENDIAN) {
- smallHead = nbytes - 1;
- step = -1;
- } else {
- smallHead = 0;
- step = 1;
- }
- byte bytes[] = new byte[nbytes];
- int p = smallHead;
- for (int i = 0; i < nbytes; i++) {
- bytes[p] = (byte) (value & 0xff);
- value = (short) (value >> 8);
- p += step;
- }
- return bytes;
- }
-
- private byte[] char2bytes(char value, ByteOrder order) {
- return short2bytes((short) value, order);
- }
-
- private byte[] float2bytes(float value, ByteOrder order) {
- return int2bytes(Float.floatToRawIntBits(value), order);
- }
-
- private byte[] double2bytes(double value, ByteOrder order) {
- return long2bytes(Double.doubleToRawLongBits(value), order);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteOrderTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteOrderTest.java
deleted file mode 100644
index 8ec62ca..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ByteOrderTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteOrder;
-
-import junit.framework.TestCase;
-
-/**
- * Test java.nio.ByteOrder
- *
- */
-@TestTargetClass(ByteOrder.class)
-public class ByteOrderTest extends TestCase {
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- assertEquals(ByteOrder.BIG_ENDIAN.toString(), "BIG_ENDIAN");
- assertEquals(ByteOrder.LITTLE_ENDIAN.toString(), "LITTLE_ENDIAN");
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nativeOrder",
- args = {}
- )
- public void testNativeOrder() {
- ByteOrder o = ByteOrder.nativeOrder();
- assertTrue(o == ByteOrder.BIG_ENDIAN || o == ByteOrder.LITTLE_ENDIAN);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
deleted file mode 100644
index 94b49d1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
+++ /dev/null
@@ -1,1601 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.io.IOException;
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteOrder;
-import java.nio.CharBuffer;
-import java.nio.InvalidMarkException;
-import java.nio.ReadOnlyBufferException;
-
-/**
- * Tests java.nio.CharBuffer
- *
- */
-@TestTargetClass(CharBuffer.class)
-public abstract class CharBufferTest extends AbstractBufferTest {
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected CharBuffer buf;
-
- private static char[] chars = "123456789a".toCharArray();
-
- protected void setUp() throws Exception{
- capacity = chars.length;
- char[] charscopy = new char[chars.length];
- System.arraycopy(chars, 0, charscopy, 0, chars.length);
- buf = CharBuffer.wrap(charscopy);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception{
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static CharBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check CharBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: CharBuffer testBuf properties is satisfy the conditions
- // specification
- CharBuffer testBuf = CharBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = CharBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = CharBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- char array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- char array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = (char) i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- CharBuffer wrapped = CharBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- CharBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertEquals(buf.capacity(), readonly.capacity());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- buf.clear();
- int originalPosition = (buf.position() + buf.limit()) / 2;
- buf.position(originalPosition);
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertEquals(buf.capacity(), readonly.capacity());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), originalPosition);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), originalPosition);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("fails on RI. See comment below")
- public void testCompact() {
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- CharBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (char) 0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (char) 0, buf.capacity());
- try {
- // failed on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact()
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (char) 1, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.CharBuffer.class}
- )
- public void testCompareTo() {
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- buf.clear();
- CharBuffer other = CharBuffer.allocate(buf.capacity());
- other.put(buf);
- other.clear();
- buf.clear();
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- assertTrue(buf.compareTo(other) == 0);
- assertTrue(other.compareTo(buf) == 0);
- other.limit(SMALL_TEST_LENGTH);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- // mark the position 0
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- CharBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertEquals(buf.capacity(), duplicate.capacity());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to
- // buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // mark another position
- buf.clear();
- int originalPosition = (buf.position() + buf.limit()) / 2;
- buf.position(originalPosition);
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertEquals(buf.capacity(), duplicate.capacity());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to
- // buf
- duplicate.reset();
- assertEquals(duplicate.position(), originalPosition);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), originalPosition);
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- CharBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- CharBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for char get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.CharBuffer get(char[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {char[].class}
- )
- public void testGetcharArray() {
- char array[] = new char[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- CharBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i));
- assertSame(ret, buf);
- }
-
- buf.get(new char[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((char[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.CharBuffer get(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {char[].class, int.class, int.class}
- )
- public void testGetcharArrayintint() {
- buf.clear();
- char array[] = new char[buf.capacity()];
-
- try {
- buf.get(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((char[])null, 2, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- CharBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for char get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- loadTestData1(buf);
- CharBuffer readonly = buf.asReadOnlyBuffer();
- CharBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
- assertTrue(buf.capacity() > SMALL_TEST_LENGTH);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- /*
- * Class under test for java.nio.CharBuffer put(char)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {char.class}
- )
- public void testPutchar() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- CharBuffer ret = buf.put((char) i);
- assertEquals(buf.get(i), (char) i);
- assertSame(ret, buf);
- }
- try {
- buf.put((char) 0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.CharBuffer put(char[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {char[].class}
- )
- public void testPutcharArray() {
- char array[] = new char[1];
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (char) i;
- CharBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (char) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.put((char[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.CharBuffer put(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {char[].class, int.class, int.class}
- )
- public void testPutcharArrayintint() {
- buf.clear();
- char array[] = new char[buf.capacity()];
- try {
- buf.put((char[]) null, 0, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((char[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- CharBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.CharBuffer put(java.nio.CharBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.CharBuffer.class}
- )
- public void testPutCharBuffer() {
- CharBuffer other = CharBuffer.allocate(buf.capacity());
-
- try {
- buf.put((CharBuffer) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(CharBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.flip();
- buf.put((CharBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- loadTestData2(other);
- other.clear();
- buf.clear();
- CharBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.CharBuffer put(int, char)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, char.class}
- )
- public void testPutintchar() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- CharBuffer ret = buf.put(i, (char) i);
- assertEquals(buf.get(i), (char) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, (char) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), (char) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- CharBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(0, slice.position());
- assertEquals(buf.remaining(), slice.limit());
- assertEquals(buf.remaining(), slice.capacity());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, (char) 0, slice.capacity());
- buf.put(2, (char) 500);
- assertEquals(slice.get(1), 500);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String expected = "";
- for (int i = buf.position(); i < buf.limit(); i++) {
- expected += buf.get(i);
- }
- String str = buf.toString();
- assertEquals(expected, str);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "charAt",
- args = {int.class}
- )
- public void testCharAt() {
- for (int i = 0; i < buf.remaining(); i++) {
- assertEquals(buf.get(buf.position() + i), buf.charAt(i));
- }
- try {
- buf.charAt(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.charAt(buf.remaining());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "length",
- args = {}
- )
- public void testLength() {
- assertEquals(buf.length(), buf.remaining());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "subSequence",
- args = {int.class, int.class}
- )
- public void testSubSequence() {
- try {
- buf.subSequence(-1, buf.length());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.subSequence(buf.length() + 1, buf.length() + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.subSequence(buf.length(), buf.length()).length(), 0);
- try {
- buf.subSequence(1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.subSequence(1, buf.length() + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- assertEquals(buf.subSequence(0, buf.length()).toString(), buf
- .toString());
-
- if (buf.length() >= 2) {
- assertEquals(buf.subSequence(1, buf.length() - 1).toString(), buf
- .toString().substring(1, buf.length() - 1));
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.lang.String.class}
- )
- public void testPutString() {
- String str = " ";
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- str = "" + (char) i;
- CharBuffer ret = buf.put(str);
- assertEquals(buf.get(i), (char) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(str);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.put((String) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.lang.String.class, int.class, int.class}
- )
- @AndroidOnly("Fails on RI. See commend below")
- public void testPutStringintint() {
- buf.clear();
- String str = String.valueOf(new char[buf.capacity()]);
-
- // Throw a BufferOverflowException and no character is transfered to
- // CharBuffer
- try {
- buf.put(String.valueOf(new char[buf.capacity() + 1]), 0, buf
- .capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- // Fails on RI. On RI put() starts transferring characters even if
- // there's no free space for whole string
- assertEquals(0, buf.position());
-
- try {
- buf.put((String) null, 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- assertEquals(0, buf.position());
-
- buf.clear();
- try {
- buf.put(str, -1, str.length());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(str, str.length() + 1, str.length() + 2);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((String) null, -1, 0);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- buf.put(str, str.length(), str.length());
- assertEquals(buf.position(), 0);
- try {
- buf.put(str, 2, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(str, 2, str.length() + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- char array[] = new char[buf.capacity()];
- loadTestData2(array, 0, array.length);
- str = String.valueOf(array);
-
- CharBuffer ret = buf.put(str, 0, str.length());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, str.toCharArray(), 0, str.length());
- assertSame(ret, buf);
- }
-
- protected void loadTestData1(char array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (char) i;
- }
- }
-
- protected void loadTestData2(char array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (char) (length - i);
- }
- }
-
- protected void loadTestData1(CharBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (char) i);
- }
- }
-
- protected void loadTestData2(CharBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (char) (buf.capacity() - i));
- }
- }
-
- private void assertContentEquals(CharBuffer buf, char array[], int offset,
- int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i]);
- }
- }
-
- private void assertContentEquals(CharBuffer buf, CharBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i));
- }
- }
-
- private void assertContentLikeTestData1(CharBuffer buf, int startIndex,
- char startValue, int length) {
- char value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value);
- value = (char) (value + 1);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies append method with the same CharSequence object for which it's called.",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void testAppendSelf() throws Exception {
- CharBuffer cb = CharBuffer.allocate(10);
- CharBuffer cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- assertEquals(cb2, cb);
-
- cb.put("abc");
- cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- cb2.clear();
- assertEquals(cb2, cb);
-
- cb.put("edfg");
- cb.clear();
- cb2 = cb.duplicate();
- cb.append(cb);
- assertEquals(10, cb.position());
- cb.clear();
- cb2.clear();
- assertEquals(cb, cb2);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies BufferOverflowException.",
- method = "append",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies BufferOverflowException.",
- method = "append",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies BufferOverflowException.",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- })
- public void testAppendOverFlow() throws IOException {
- CharBuffer cb = CharBuffer.allocate(1);
- CharSequence cs = "String";
- cb.put('A');
- try {
- cb.append('C');
- fail("should throw BufferOverflowException.");
- } catch (BufferOverflowException ex) {
- // expected;
- }
- try {
- cb.append(cs);
- fail("should throw BufferOverflowException.");
- } catch (BufferOverflowException ex) {
- // expected;
- }
- try {
- cb.append(cs, 1, 2);
- fail("should throw BufferOverflowException.");
- } catch (BufferOverflowException ex) {
- // expected;
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "append",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "append",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- })
- public void testReadOnlyMap() throws IOException {
- CharBuffer cb = CharBuffer.wrap("ABCDE").asReadOnlyBuffer();
- CharSequence cs = "String";
- try {
- cb.append('A');
- fail("should throw ReadOnlyBufferException.");
- } catch (ReadOnlyBufferException ex) {
- // expected;
- }
- try {
- cb.append(cs);
- fail("should throw ReadOnlyBufferException.");
- } catch (ReadOnlyBufferException ex) {
- // expected;
- }
- try {
- cb.append(cs, 1, 2);
- fail("should throw ReadOnlyBufferException.");
- } catch (ReadOnlyBufferException ex) {
- // expected;
- }
- cb.append(cs, 1, 1);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify exceptions.",
- method = "append",
- args = {char.class}
- )
- public void testAppendCNormal() throws IOException {
- CharBuffer cb = CharBuffer.allocate(2);
- cb.put('A');
- assertSame(cb, cb.append('B'));
- assertEquals('B', cb.get(1));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify exceptions.",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void testAppendCharSequenceNormal() throws IOException {
- CharBuffer cb = CharBuffer.allocate(10);
- cb.put('A');
- assertSame(cb, cb.append("String"));
- assertEquals("AString", cb.flip().toString());
- cb.append(null);
- assertEquals("null", cb.flip().toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies positive case, and null as CharSequence parameter.",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void testAppendCharSequenceIINormal() throws IOException {
- CharBuffer cb = CharBuffer.allocate(10);
- cb.put('A');
- assertSame(cb, cb.append("String", 1, 3));
- assertEquals("Atr", cb.flip().toString());
-
- cb.append(null, 0, 1);
- assertEquals("n", cb.flip().toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IndexOutOfBoundsException.",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void testAppendCharSequenceII_IllegalArgument() throws IOException {
- CharBuffer cb = CharBuffer.allocate(10);
- cb.append("String", 0, 0);
- cb.append("String", 2, 2);
- try {
- cb.append("String", -1, 1);
- fail("should throw IndexOutOfBoundsException.");
- } catch (IndexOutOfBoundsException ex) {
- // expected;
- }
- try {
- cb.append("String", -1, -1);
- fail("should throw IndexOutOfBoundsException.");
- } catch (IndexOutOfBoundsException ex) {
- // expected;
- }
- try {
- cb.append("String", 3, 2);
- fail("should throw IndexOutOfBoundsException.");
- } catch (IndexOutOfBoundsException ex) {
- // expected;
- }
- try {
- cb.append("String", 3, 0);
- fail("should throw IndexOutOfBoundsException.");
- } catch (IndexOutOfBoundsException ex) {
- // expected;
- }
- try {
- cb.append("String", 3, 110);
- fail("should throw IndexOutOfBoundsException.");
- } catch (IndexOutOfBoundsException ex) {
- // expected;
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- public void testReadCharBuffer() throws IOException {
- CharBuffer source = CharBuffer.wrap("String");
- CharBuffer target = CharBuffer.allocate(10);
- assertEquals(6, source.read(target));
- assertEquals("String", target.flip().toString());
- // return -1 when nothing to read
- assertEquals(-1, source.read(target));
- // NullPointerException
- try {
- assertEquals(-1, source.read(null));
- fail("should throw NullPointerException.");
- } catch (NullPointerException ex) {
- // expected;
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- public void testReadReadOnly() throws IOException {
- CharBuffer source = CharBuffer.wrap("String");
- CharBuffer target = CharBuffer.allocate(10).asReadOnlyBuffer();
- try {
- source.read(target);
- fail("should throw ReadOnlyBufferException.");
- } catch (ReadOnlyBufferException ex) {
- // expected;
- }
- // if target has no remaining, needn't to check the isReadOnly
- target.flip();
- assertEquals(0, source.read(target));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies read method with CharBuffer parameter which length is less than read CharBuffer.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- public void testReadOverflow() throws IOException {
- CharBuffer source = CharBuffer.wrap("String");
- CharBuffer target = CharBuffer.allocate(1);
- assertEquals(1, source.read(target));
- assertEquals("S", target.flip().toString());
- assertEquals(1, source.position());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- public void testReadSelf() throws Exception {
- CharBuffer source = CharBuffer.wrap("abuffer");
- try {
- source.read(source);
- fail("should throw IAE.");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- public void testRead_scenario1() throws Exception {
- char[] charArray = new char[] { 'a', 'b' };
- CharBuffer charBuffer = CharBuffer.wrap(charArray);
- try {
- charBuffer.read(charBuffer);
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- charBuffer.put(charArray);
- assertEquals(-1, charBuffer.read(charBuffer));
- }
-
- public void testRead_scenario2() throws Exception {
- CharBuffer charBufferA = CharBuffer.allocate(0);
- CharBuffer allocateBuffer = CharBuffer.allocate(1);
- CharBuffer charBufferB = CharBuffer.wrap(allocateBuffer);
- assertEquals(-1, charBufferA.read(charBufferB));
-
- allocateBuffer.append(allocateBuffer);
- charBufferB = CharBuffer.wrap(allocateBuffer);
- assertEquals(-1, charBufferA.read(charBufferB));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray returns true value.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertTrue(buf.hasArray());
- assertNotNull(buf.array());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
-
- /*
- * test for method static CharBuffer wrap(char[] array) test covers
- * following usecases: 1. case for check CharBuffer buf2 properties 2. case
- * for check equal between buf2 and char array[] 3. case for check a buf2
- * dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {char[].class}
- )
- public void test_Wrap$C() {
- char array[] = new char[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- CharBuffer buf2 = CharBuffer.wrap(array);
-
- // case: CharBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: CharBuffer buf2 is equal to char array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: CharBuffer buf2 is depended to char array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static CharBuffer wrap(char[] array, int offset, int length)
- * test covers following usecases:
- * 1. case for check CharBuffer buf2 properties
- * 2. case for check equal between buf2 and char array[]
- * 3. case for check a buf2 dependens to array[]
- * 4. case expected IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {char[].class, int.class, int.class}
- )
- public void test_Wrap$CII() {
- char array[] = new char[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- CharBuffer buf2 = CharBuffer.wrap(array, offset, length);
-
- // case: CharBuffer buf2 properties is satisfy the conditions specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: CharBuffer buf2 is equal to char array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: CharBuffer buf2 is depended to char array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = CharBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- }
-
- /*
- * test for method static CharBuffer wrap(CharSequence csq)
- * test covers following usecases:
- * 1. case for check StringBuffer
- * 2. case for check StringBuilder
- * 3. case for check String
- * 4. case for check CharBuffer
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {java.lang.CharSequence.class}
- )
- public void test_WrapLjava_lang_CharSequence() {
- // added this if clause to prevent Tests failing under special conditions.
- // If the test extending this test is made for a read only buffer it fails
- // when it tries to call loadTestData1.
- if(buf.isReadOnly()) {
- char[] charscopy = new char[chars.length];
- System.arraycopy(chars, 0, charscopy, 0, chars.length);
- buf = CharBuffer.wrap(charscopy);
- }
- loadTestData1(buf);
- buf.rewind();
- StringBuffer testStrBuffer = new StringBuffer(buf);
- StringBuilder testStrBuilder = new StringBuilder(buf);
- String testStr = buf.toString();
-
- //case: StringBuffer
- CharBuffer bufStrBf = CharBuffer.wrap(testStrBuffer);
- assertTrue(bufStrBf.isReadOnly());
- assertEquals(bufStrBf.capacity(), testStrBuffer.length());
- assertEquals(bufStrBf.limit(), testStrBuffer.length());
- assertEquals(bufStrBf.position(), 0);
- assertContentEquals(bufStrBf, buf);
-
- // case: StringBuilder
- CharBuffer bufStrBl = CharBuffer.wrap(testStrBuilder);
- assertTrue(bufStrBl.isReadOnly());
- assertEquals(bufStrBl.capacity(), testStrBuilder.length());
- assertEquals(bufStrBl.limit(), testStrBuilder.length());
- assertEquals(bufStrBl.position(), 0);
- assertContentEquals(bufStrBl, buf);
-
- // case: String
- CharBuffer bufStr = CharBuffer.wrap(testStr);
- assertTrue(bufStr.isReadOnly());
- assertEquals(bufStr.capacity(), testStr.length());
- assertEquals(bufStr.limit(), testStr.length());
- assertEquals(bufStr.position(), 0);
- assertContentEquals(bufStr, buf);
-
- // case: CharBuffer
- CharBuffer bufChBf = CharBuffer.wrap(buf);
- assertTrue(bufChBf.isReadOnly());
- assertEquals(bufChBf.capacity(), buf.length());
- assertEquals(bufChBf.limit(), buf.length());
- assertEquals(bufChBf.position(), 0);
- assertContentEquals(bufChBf, buf);
- }
-
- /*
- * test for method public static CharBuffer wrap(CharSequence csq, int start, int end)
- * test covers following usecases:
- * 1. case for check StringBuffer
- * 2. case for check StringBuilder
- * 3. case for check String
- * 4. case for check CharBuffer
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify exception.",
- method = "wrap",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_WrapLjava_lang_CharSequenceII() {
- int start = buf.position();
- int end = buf.limit();
- CharBuffer buf2 = CharBuffer.wrap(buf.toString() + buf.toString()); //buf.toString() + buf.toString() //"123456789a123456789a"
-
- // case: StringBuffer
- StringBuffer testStrBuffer = new StringBuffer(buf2);
- CharBuffer bufStrBf = CharBuffer.wrap(testStrBuffer, start, end);
- assertTrue(bufStrBf.isReadOnly());
- assertEquals(bufStrBf.capacity(), testStrBuffer.length());
- assertEquals(bufStrBf.limit(), end);
- assertEquals(bufStrBf.position(), start);
- assertEquals(bufStrBf.toString(), buf.toString());
-
- // case: StringBuilder
- StringBuilder testStrBuilder = new StringBuilder(buf2);
- CharBuffer bufStrBl = CharBuffer.wrap(testStrBuilder, start, end);
- assertTrue(bufStrBl.isReadOnly());
- assertEquals(bufStrBl.capacity(), testStrBuilder.length());
- assertEquals(bufStrBl.limit(), end);
- assertEquals(bufStrBl.position(), start);
- assertEquals(bufStrBl.toString(), buf.toString());
-
- // case: String
- String testStr = new String(buf2.toString());
- CharBuffer bufStr = CharBuffer.wrap(testStr, start, end);
- assertTrue(bufStr.isReadOnly());
- assertEquals(bufStr.capacity(), testStr.length());
- assertEquals(bufStr.limit(), end);
- assertEquals(bufStr.position(), start);
- assertEquals(bufStr.toString(), buf.toString());
-
- // case: CharBuffer
- CharBuffer bufChBf = CharBuffer.wrap(buf2, start, end);
- assertTrue(bufChBf.isReadOnly());
- assertEquals(bufChBf.capacity(), buf2.length());
- assertEquals(bufChBf.limit(), end);
- assertEquals(bufChBf.position(), start);
- assertEquals(bufChBf.toString(), buf.toString());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java
deleted file mode 100644
index 824d716..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectByteBufferTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-
-@TestTargetClass(ByteBuffer.class)
-public class DirectByteBufferTest extends ByteBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /**
- * @tests java.nio.ByteBuffer#allocateDirect(int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocateDirect",
- args = {int.class}
- )
- public void testAllocatedByteBuffer_IllegalArg() {
- try {
- ByteBuffer.allocateDirect(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct ByteBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct ByteBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java
deleted file mode 100644
index 397e9f6..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectCharBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class DirectCharBufferTest extends CharBufferTest {
-
- protected void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH * 2).asCharBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct CharBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct CharBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct CharBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct CharBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectDoubleBufferTest.java
deleted file mode 100644
index 5b2e5d2..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectDoubleBufferTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class DirectDoubleBufferTest extends DoubleBufferTest {
- public void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*8).asDoubleBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- public void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct DoubleBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct DoubleBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct DoubleBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct DoubleBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies order method for direct DoubleBuffer.",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectFloatBufferTest.java
deleted file mode 100644
index 184e926..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectFloatBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class DirectFloatBufferTest extends FloatBufferTest {
- public void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*4).asFloatBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- public void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct FloatBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct FloatBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct FloatBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct FloatBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies order method for direct FloatBuffer.",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
deleted file mode 100644
index a92ddbe..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectIntBufferTest.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.IntBuffer;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class DirectIntBufferTest extends IntBufferTest {
- public void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*4).asIntBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- public void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- /**
- * Regression for http://code.google.com/p/android/issues/detail?id=3279
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {int[].class, int.class, int.class}
- )
- public void testPutWhenOffsetIsNonZero() {
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
- byteBuffer.order(ByteOrder.nativeOrder());
- IntBuffer intBuffer = byteBuffer.asIntBuffer();
-
- int[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
-
- intBuffer.put(source, 2, 2);
- intBuffer.put(source, 4, 2);
- assertEquals(4, intBuffer.get(0));
- assertEquals(5, intBuffer.get(1));
- assertEquals(6, intBuffer.get(2));
- assertEquals(7, intBuffer.get(3));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct IntBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct IntBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct IntBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct IntBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies order method for direct IntBuffer.",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test for IntToByteBufferAdapter",
- clazz = ByteBuffer.class,
- method = "asIntBuffer",
- args = {}
- )
- public void testRangeChecks() {
- int[] myInts = new int[BUFFER_LENGTH];
-
- for (int i = 0; i < BUFFER_LENGTH; i++) {
- myInts[i] = 1000 + i;
- }
-
- buf.position(0);
- buf.put(myInts, 0, BUFFER_LENGTH);
- buf.position(0);
- buf.put(myInts, 0, BUFFER_LENGTH);
-
- try {
- buf.put(myInts, 0, 1); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (BufferOverflowException boe) {
- // expected
- }
-
- try {
- buf.position(0);
- buf.put(myInts, 0, BUFFER_LENGTH + 1); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (IndexOutOfBoundsException ioobe) {
- // expected
- }
-
- try {
- buf.position(BUFFER_LENGTH - 1);
- buf.put(myInts, 0, 2); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (BufferOverflowException boe) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectLongBufferTest.java
deleted file mode 100644
index 4150e38..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectLongBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class DirectLongBufferTest extends LongBufferTest {
- public void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*8).asLongBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- public void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct LongBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct LongBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct LongBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct LongBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies order method for direct LongBuffer.",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
deleted file mode 100644
index fdab359..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DirectShortBufferTest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.ShortBuffer;
-import java.nio.IntBuffer;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class DirectShortBufferTest extends ShortBufferTest {
- public void setUp(){
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.allocateDirect(BUFFER_LENGTH*2).asShortBuffer();
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- public void tearDown(){
- buf = null;
- baseBuf = null;
- }
-
- /**
- * Regression for http://code.google.com/p/android/issues/detail?id=3279
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "put",
- args = {short[].class, int.class, int.class}
- )
- public void testPutWhenOffsetIsNonZero() {
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(40);
- byteBuffer.order(ByteOrder.nativeOrder());
- ShortBuffer shortBuffer = byteBuffer.asShortBuffer();
-
- short[] source = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
-
- shortBuffer.put(source, 2, 2);
- shortBuffer.put(source, 4, 2);
- assertEquals(4, shortBuffer.get(0));
- assertEquals(5, shortBuffer.get(1));
- assertEquals(6, shortBuffer.get(2));
- assertEquals(7, shortBuffer.get(3));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for direct ShortBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies array method for direct ShortBuffer.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies arrayOffset method for direct ShortBuffer.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for direct ShortBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertTrue(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies order method for direct ShortBuffer.",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.BIG_ENDIAN, buf.order());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test for ShortToByteBufferAdapter",
- clazz = ByteBuffer.class,
- method = "asShortBuffer",
- args = {}
- )
- public void testRangeChecks() {
- short[] myShorts = new short[BUFFER_LENGTH];
-
- for (short i = 0; i < BUFFER_LENGTH; i++) {
- myShorts[i] = (short) (1000 + i);
- }
-
- buf.position(0);
- buf.put(myShorts, 0, BUFFER_LENGTH);
- buf.position(0);
- buf.put(myShorts, 0, BUFFER_LENGTH);
-
- try {
- buf.put(myShorts, 0, 1); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (BufferOverflowException boe) {
- // expected
- }
-
- try {
- buf.position(0);
- buf.put(myShorts, 0, BUFFER_LENGTH + 1); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (IndexOutOfBoundsException ioobe) {
- // expected
- }
-
- try {
- buf.position(BUFFER_LENGTH - 1);
- buf.put(myShorts, 0, 2); // should fail
- fail("BufferOverflowException expected but not thrown");
- } catch (BufferOverflowException boe) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
deleted file mode 100644
index b4154ba..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DoubleBufferTest.java
+++ /dev/null
@@ -1,971 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.DoubleBuffer;
-import java.nio.InvalidMarkException;
-
-/**
- * Tests java.nio.DoubleBuffer
- */
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public abstract class DoubleBufferTest extends AbstractBufferTest {
-
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected DoubleBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = DoubleBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static DoubleBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check DoubleBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: DoubleBuffer testBuf properties is satisfy the conditions
- // specification
- DoubleBuffer testBuf = DoubleBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = DoubleBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = DoubleBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /*
- * Test with bit sequences that represent the IEEE754 doubles Positive
- * infinity, negative infinity, and NaN.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary values.",
- method = "put",
- args = {double.class}
- )
- public void testNaNs() {
- long[] nans = new long[] { 0x7ff0000000000000L, 0xfff0000000000000L,
- 0x7ff8000000000000L };
- for (int i = 0; i < nans.length; i++) {
- long longBitsIn = nans[i];
- double dbl = Double.longBitsToDouble(longBitsIn);
- long longBitsOut = Double.doubleToRawLongBits(dbl);
- // Sanity check
- assertTrue(longBitsIn == longBitsOut);
-
- // Store the double and retrieve it
- ByteBuffer buffer = ByteBuffer.allocate(8);
- buffer.putDouble(dbl);
- double bufDoubleOut = buffer.getDouble(0);
-
- // Check the bits sequence was not normalized
- long bufLongOut = Double.doubleToRawLongBits(bufDoubleOut);
- assertTrue(longBitsIn == bufLongOut);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- double array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- double array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- DoubleBuffer wrapped = DoubleBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- DoubleBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // BEGIN android-added
- // copied from a newer version of Harmony
- DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
- DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
- DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
-
- assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
- .compareTo(dbuffer2));
- assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
- .compareTo(dbuffer1));
- assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
- .compareTo(dbuffer3));
- // END android-added
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- DoubleBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0.0, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 1.0, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.DoubleBuffer.class}
- )
- public void testCompareTo() {
- DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
-
- DoubleBuffer dbuffer1 = DoubleBuffer.wrap(new double[] { Double.NaN });
- DoubleBuffer dbuffer2 = DoubleBuffer.wrap(new double[] { Double.NaN });
- DoubleBuffer dbuffer3 = DoubleBuffer.wrap(new double[] { 42d });
-
- assertEquals("Failed equal comparison with NaN entry", 0, dbuffer1
- .compareTo(dbuffer2));
- assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer3
- .compareTo(dbuffer1));
- assertEquals("Failed greater than comparison with NaN entry", 1, dbuffer1
- .compareTo(dbuffer3));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- DoubleBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // duplicate share the same content with buf
- // FIXME
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- DoubleBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- DoubleBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for double get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i), 0.01);
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer get(double[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {double[].class}
- )
- public void testGetdoubleArray() {
- double array[] = new double[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- DoubleBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i), 0.01);
- assertSame(ret, buf);
- }
-
- buf.get(new double[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((double[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer get(double[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {double[].class, int.class, int.class}
- )
- public void testGetdoubleArrayintint() {
- buf.clear();
- double array[] = new double[buf.capacity()];
-
- try {
- buf.get(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((double[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- DoubleBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for double get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i), 0.01);
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- DoubleBuffer readonly = buf.asReadOnlyBuffer();
- DoubleBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer put(double)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify boundary values, and ReadOnlyBufferException.",
- method = "put",
- args = {double.class}
- )
- public void testPutdouble() {
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- DoubleBuffer ret = buf.put((double) i);
- assertEquals(buf.get(i), (double) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer put(double[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {double[].class}
- )
- public void testPutdoubleArray() {
- double array[] = new double[1];
-
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (double) i;
- DoubleBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (double) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer put(double[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {double[].class, int.class, int.class}
- )
- public void testPutdoubleArrayintint() {
- buf.clear();
- double array[] = new double[buf.capacity()];
-
- try {
- buf.put(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((double[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- DoubleBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer put(java.nio.DoubleBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.DoubleBuffer.class}
- )
- public void testPutDoubleBuffer() {
- DoubleBuffer other = DoubleBuffer.allocate(buf.capacity());
-
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(DoubleBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
-
- loadTestData2(other);
- other.clear();
- buf.clear();
- DoubleBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.DoubleBuffer put(int, double)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, double.class}
- )
- public void testPutintdouble() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- DoubleBuffer ret = buf.put(i, (double) i);
- assertEquals(buf.get(i), (double) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- DoubleBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(slice.position(), 0);
- assertEquals(slice.limit(), buf.remaining());
- assertEquals(slice.capacity(), buf.remaining());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- // FIXME:
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, 0, slice.capacity());
- buf.put(2, 500);
- assertEquals(slice.get(1), 500, 0.0);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Double") >= 0 || str.indexOf("double") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- /*
- * test for method static DoubleBuffer wrap(double[] array) test covers
- * following usecases: 1. case for check DoubleBuffer buf2 properties 2.
- * case for check equal between buf2 and double array[] 3. case for check a
- * buf2 dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {double[].class}
- )
- public void test_Wrap$D() {
- double array[] = new double[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- DoubleBuffer buf2 = DoubleBuffer.wrap(array);
-
- // case: DoubleBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: DoubleBuffer buf2 is equal to double array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: DoubleBuffer buf2 is depended to double array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static DoubleBuffer wrap(double[] array, int offset, int
- * length) test covers following usecases: 1. case for check DoubleBuffer
- * buf2 properties 2. case for check equal between buf2 and double array[]
- * 3. case for check a buf2 dependens to array[] 4. case expected
- * IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {double[].class, int.class, int.class}
- )
- public void test_Wrap$DII() {
- double array[] = new double[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- DoubleBuffer buf2 = DoubleBuffer.wrap(array, offset, length);
-
- // case: DoubleBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: DoubleBuffer buf2 is equal to double array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: DoubleBuffer buf2 is depended to double array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = DoubleBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- void loadTestData1(double array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (double) i;
- }
- }
-
- void loadTestData2(double array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (double) length - i;
- }
- }
-
- void loadTestData1(DoubleBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (double) i);
- }
- }
-
- void loadTestData2(DoubleBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (double) buf.capacity() - i);
- }
- }
-
- private void assertContentEquals(DoubleBuffer buf, double array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i], 0.01);
- }
- }
-
- private void assertContentEquals(DoubleBuffer buf, DoubleBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i), 0.01);
- }
- }
-
- private void assertContentLikeTestData1(DoubleBuffer buf, int startIndex,
- double startValue, int length) {
- double value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value, 0.01);
- value = value + 1.0;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateDirectByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateDirectByteBufferTest.java
deleted file mode 100644
index 7ddc788..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateDirectByteBufferTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class DuplicateDirectByteBufferTest extends DirectByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.duplicate();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateHeapByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateHeapByteBufferTest.java
deleted file mode 100644
index 875699c..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateHeapByteBufferTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class DuplicateHeapByteBufferTest extends HeapByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.duplicate();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateWrappedByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateWrappedByteBufferTest.java
deleted file mode 100644
index ce15ff4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/DuplicateWrappedByteBufferTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class DuplicateWrappedByteBufferTest extends WrappedByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.duplicate();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
deleted file mode 100644
index b4bd3ff..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/FloatBufferTest.java
+++ /dev/null
@@ -1,978 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-import java.nio.InvalidMarkException;
-
-/**
- * Tests java.nio.FloatBuffer
- *
- */
-@TestTargetClass(java.nio.FloatBuffer.class)
-public abstract class FloatBufferTest extends AbstractBufferTest {
-
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected FloatBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = FloatBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static FloatBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check FloatBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: FloatBuffer testBuf properties is satisfy the conditions
- // specification
- FloatBuffer testBuf = FloatBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = FloatBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = FloatBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies boundary values.",
- method = "put",
- args = {float.class}
- )
- public void testNaNs() {
- int[] nans = new int[] { 0x7f800000, 0xff800000, 0x7fc00000 };
- for (int i = 0; i < nans.length; i++) {
- int intBitsIn = nans[i];
- float flt = Float.intBitsToFloat(intBitsIn);
- int intBitsOut = Float.floatToRawIntBits(flt);
- // Sanity check
- assertTrue(intBitsIn == intBitsOut);
-
- // Store the float and retrieve it
- ByteBuffer buffer = ByteBuffer.allocate(8);
- buffer.putFloat(flt);
- float bufFloatOut = buffer.getFloat(0);
-
- // Check the bits sequence was not normalized
- int bufIntOut = Float.floatToRawIntBits(bufFloatOut);
- assertTrue(intBitsIn == bufIntOut);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- float array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- float array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- FloatBuffer wrapped = FloatBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- FloatBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
-
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- FloatBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0.0f, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0.0f, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 1.0f, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.FloatBuffer.class}
- )
- public void testCompareTo() {
- try {
- buf.compareTo(null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // expected
- }
-
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- // normal cases
- assertTrue(buf.capacity() > 5);
- buf.clear();
- FloatBuffer other = FloatBuffer.allocate(buf.capacity());
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
-
- FloatBuffer fbuffer1 = FloatBuffer.wrap(new float[] { Float.NaN });
- FloatBuffer fbuffer2 = FloatBuffer.wrap(new float[] { Float.NaN });
- FloatBuffer fbuffer3 = FloatBuffer.wrap(new float[] { 42f });
-
- assertEquals("Failed equal comparison with NaN entry", 0, fbuffer1
- .compareTo(fbuffer2));
- assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer3
- .compareTo(fbuffer1));
- assertEquals("Failed greater than comparison with NaN entry", 1, fbuffer1
- .compareTo(fbuffer3));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- FloatBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- FloatBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- FloatBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for float get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i), 0.01);
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.FloatBuffer get(float[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {float[].class}
- )
- public void testGetfloatArray() {
- float array[] = new float[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- FloatBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i), 0.01);
- assertSame(ret, buf);
- }
-
- buf.get(new float[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((float[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.FloatBuffer get(float[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {float[].class, int.class, int.class}
- )
- public void testGetfloatArrayintint() {
- buf.clear();
- float array[] = new float[buf.capacity()];
-
- try {
- buf.get(new float[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((float[])null, 2, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- FloatBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for float get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i), 0.01);
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- FloatBuffer readonly = buf.asReadOnlyBuffer();
- FloatBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- buf.order();
- if (buf.hasArray()) {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
- }
-
- /*
- * Class under test for java.nio.FloatBuffer put(float)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {float.class}
- )
- public void testPutfloat() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- FloatBuffer ret = buf.put((float) i);
- assertEquals(buf.get(i), (float) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.FloatBuffer put(float[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {float[].class}
- )
- public void testPutfloatArray() {
- float array[] = new float[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (float) i;
- FloatBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (float) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.position(buf.limit());
- buf.put((float[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.FloatBuffer put(float[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {float[].class, int.class, int.class}
- )
- public void testPutfloatArrayintint() {
- buf.clear();
- float array[] = new float[buf.capacity()];
- try {
- buf.put(new float[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((float[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- FloatBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.FloatBuffer put(java.nio.FloatBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.FloatBuffer.class}
- )
- public void testPutFloatBuffer() {
- FloatBuffer other = FloatBuffer.allocate(buf.capacity());
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(FloatBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.flip();
- buf.put((FloatBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- buf.clear();
- loadTestData2(other);
- other.clear();
- buf.clear();
- FloatBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.FloatBuffer put(int, float)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, float.class}
- )
- public void testPutintfloat() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- FloatBuffer ret = buf.put(i, (float) i);
- assertEquals(buf.get(i), (float) i, 0.0);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- FloatBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(slice.position(), 0);
- assertEquals(slice.limit(), buf.remaining());
- assertEquals(slice.capacity(), buf.remaining());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, 0, slice.capacity());
- buf.put(2, 500);
- assertEquals(slice.get(1), 500, 0.0);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Float") >= 0 || str.indexOf("float") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- /*
- * test for method static FloatBuffer wrap(float[] array) test covers
- * following usecases: 1. case for check FloatBuffer buf2 properties 2. case
- * for check equal between buf2 and float array[] 3. case for check a buf2
- * dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {float[].class}
- )
- public void test_Wrap$S() {
- float array[] = new float[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- FloatBuffer buf2 = FloatBuffer.wrap(array);
-
- // case: FloatBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: FloatBuffer buf2 is equal to float array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: FloatBuffer buf2 is depended to float array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static FloatBuffer wrap(float[] array, int offset, int
- * length) test covers following usecases: 1. case for check FloatBuffer
- * buf2 properties 2. case for check equal between buf2 and float array[] 3.
- * case for check a buf2 dependens to array[] 4. case expected
- * IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {float[].class, int.class, int.class}
- )
- public void test_Wrap$SII() {
- float array[] = new float[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- FloatBuffer buf2 = FloatBuffer.wrap(array, offset, length);
-
- // case: FloatBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: FloatBuffer buf2 is equal to float array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: FloatBuffer buf2 is depended to float array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = FloatBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- void loadTestData1(float array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (float) i;
- }
- }
-
- void loadTestData2(float array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (float) length - i;
- }
- }
-
- void loadTestData1(FloatBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (float) i);
- }
- }
-
- void loadTestData2(FloatBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (float) buf.capacity() - i);
- }
- }
-
- void assertContentEquals(FloatBuffer buf, float array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i], 0.01);
- }
- }
-
- void assertContentEquals(FloatBuffer buf, FloatBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i), 0.01);
- }
- }
-
- void assertContentLikeTestData1(FloatBuffer buf,
- int startIndex, float startValue, int length) {
- float value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value, 0.01);
- value = value + 1.0f;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java
deleted file mode 100644
index d0a77d9..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapByteBufferTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class HeapByteBufferTest extends ByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * @tests java.nio.ByteBuffer#allocate(int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedByteBuffer_IllegalArg() {
- try {
- ByteBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java
deleted file mode 100644
index 2267092..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapCharBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.CharBuffer;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class HeapCharBufferTest extends CharBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedCharBuffer_IllegalArg() {
- try {
- CharBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java
deleted file mode 100644
index cb995e6..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapDoubleBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.DoubleBuffer;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class HeapDoubleBufferTest extends DoubleBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedDoubleBuffer_IllegalArg() {
- try {
- DoubleBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java
deleted file mode 100644
index ef94033..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapFloatBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.FloatBuffer;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class HeapFloatBufferTest extends FloatBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedFloatBuffer_IllegalArg() {
- try {
- FloatBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java
deleted file mode 100644
index 2c1730e..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapIntBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.IntBuffer;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class HeapIntBufferTest extends IntBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedIntBuffer_IllegalArg() {
- try {
- IntBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java
deleted file mode 100644
index 39af9e3..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapLongBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.LongBuffer;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class HeapLongBufferTest extends LongBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedLongBuffer_IllegalArg() {
- try {
- LongBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java
deleted file mode 100644
index 368b0f1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/HeapShortBufferTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ShortBuffer;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class HeapShortBufferTest extends ShortBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "allocate",
- args = {int.class}
- )
- public void testAllocatedShortBuffer_IllegalArg() {
- try {
- ShortBuffer.allocate(-1);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
deleted file mode 100644
index dbe8aa4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/IntBufferTest.java
+++ /dev/null
@@ -1,954 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.IntBuffer;
-import java.nio.InvalidMarkException;
-
-/**
- * Tests java.nio.IntBuffer
- *
- */
-@TestTargetClass(java.nio.IntBuffer.class)
-public abstract class IntBufferTest extends AbstractBufferTest {
-
-
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected IntBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = IntBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static IntBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check IntBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: IntBuffer testBuf properties is satisfy the conditions
- // specification
- IntBuffer testBuf = IntBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = IntBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = IntBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- int array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- int array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- IntBuffer wrapped = IntBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- IntBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- IntBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 1, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.IntBuffer.class}
- )
- public void testCompareTo() {
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- // normal cases
- assertTrue(buf.capacity() > 5);
- buf.clear();
- IntBuffer other = IntBuffer.allocate(buf.capacity());
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- IntBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- IntBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- IntBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for int get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.IntBuffer get(int[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int[].class}
- )
- public void testGetintArray() {
- int array[] = new int[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- IntBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i));
- assertSame(ret, buf);
- }
-
- buf.get(new int[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((int[])null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.IntBuffer get(int[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int[].class, int.class, int.class}
- )
- public void testGetintArrayintint() {
- buf.clear();
- int array[] = new int[buf.capacity()];
-
- try {
- buf.get(new int[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((int[])null, 2, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- IntBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for int get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- IntBuffer readonly = buf.asReadOnlyBuffer();
- IntBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for non direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class}
- )
- public void testPutint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- IntBuffer ret = buf.put((int) i);
- assertEquals(buf.get(i), (int) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int[].class}
- )
- public void testPutintArray() {
- int array[] = new int[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (int) i;
- IntBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (int) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.position(buf.limit());
- buf.put((int[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int[].class, int.class, int.class}
- )
- public void testPutintArrayintint() {
- buf.clear();
- int array[] = new int[buf.capacity()];
- try {
- buf.put(new int[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((int[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- IntBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression Test",
- method = "put",
- args = {int[].class, int.class, int.class}
- )
- public void testPutintArrayintint2() {
- // Regression test
- ByteBuffer buf = ByteBuffer.allocateDirect(20);
- IntBuffer intBuf = buf.asIntBuffer();
- int[] src = new int[5];
- intBuf.put(src);
- intBuf.clear();
- try {
- intBuf.put(src);
- } catch (BufferOverflowException e) {
- fail("should not throw a BufferOverflowException");
- }
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(java.nio.IntBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.IntBuffer.class}
- )
- public void testPutIntBuffer() {
- IntBuffer other = IntBuffer.allocate(buf.capacity());
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(IntBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.flip();
- buf.put((IntBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- loadTestData2(other);
- other.clear();
- buf.clear();
- IntBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, int.class}
- )
- public void testPutintint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- IntBuffer ret = buf.put(i, (int) i);
- assertEquals(buf.get(i), (int) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- IntBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(slice.position(), 0);
- assertEquals(slice.limit(), buf.remaining());
- assertEquals(slice.capacity(), buf.remaining());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, 0, slice.capacity());
- buf.put(2, 500);
- assertEquals(slice.get(1), 500);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Int") >= 0 || str.indexOf("int") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- /*
- * test for method static IntBuffer wrap(int[] array) test covers following
- * usecases: 1. case for check IntBuffer buf2 properties 2. case for check
- * equal between buf2 and int array[] 3. case for check a buf2 dependens to
- * array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {int[].class}
- )
- public void test_Wrap$I() {
- int array[] = new int[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- IntBuffer buf2 = IntBuffer.wrap(array);
-
- // case: IntBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: IntBuffer buf2 is equal to int array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: IntBuffer buf2 is depended to int array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static IntBuffer wrap(int[] array, int offset, int
- * length) test covers following usecases: 1. case for check IntBuffer buf2
- * properties 2. case for check equal between buf2 and int array[] 3. case
- * for check a buf2 dependens to array[] 4. case expected
- * IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {int[].class, int.class, int.class}
- )
- public void test_Wrap$III() {
- int array[] = new int[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- IntBuffer buf2 = IntBuffer.wrap(array, offset, length);
-
- // case: IntBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: IntBuffer buf2 is equal to int array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: IntBuffer buf2 is depended to int array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = IntBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- void loadTestData1(int array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (int)i;
- }
- }
-
- void loadTestData2(int array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (int)length - i;
- }
- }
-
- void loadTestData1(IntBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (int)i);
- }
- }
-
- void loadTestData2(IntBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (int)buf.capacity() - i);
- }
- }
-
- void assertContentEquals(IntBuffer buf, int array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i]);
- }
- }
-
- void assertContentEquals(IntBuffer buf, IntBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i));
- }
- }
-
- void assertContentLikeTestData1(IntBuffer buf,
- int startIndex, int startValue, int length) {
- int value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value);
- value = value + 1;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java
deleted file mode 100644
index 67029b8..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/InvalidMarkExceptionTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.InvalidMarkException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(InvalidMarkException.class)
-public class InvalidMarkExceptionTest extends TestCase {
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new InvalidMarkException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new InvalidMarkException());
- }
-
- /**
- *@tests {@link java.nio.InvalidMarkException#InvalidMarkException()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidMarkException",
- args = {}
- )
- public void test_Constructor() {
- InvalidMarkException exception = new InvalidMarkException();
- assertNull(exception.getMessage());
- assertNull(exception.getLocalizedMessage());
- assertNull(exception.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
deleted file mode 100644
index 81d30ca..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/LongBufferTest.java
+++ /dev/null
@@ -1,936 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteOrder;
-import java.nio.InvalidMarkException;
-import java.nio.LongBuffer;
-
-/**
- * Tests java.nio.LongBuffer
- *
- */
-@TestTargetClass(java.nio.LongBuffer.class)
-public abstract class LongBufferTest extends AbstractBufferTest {
-
-
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected LongBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = LongBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static LongBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check LongBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: LongBuffer testBuf properties is satisfy the conditions
- // specification
- LongBuffer testBuf = LongBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = LongBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = LongBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- long array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- long array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- LongBuffer wrapped = LongBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- LongBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- LongBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 0, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, 1, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.LongBuffer.class}
- )
- public void testCompareTo() {
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- // normal cases
- assertTrue(buf.capacity() > 5);
- buf.clear();
- LongBuffer other = LongBuffer.allocate(buf.capacity());
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- LongBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- LongBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- LongBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for long get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.LongBuffer get(long[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {long[].class}
- )
- public void testGetlongArray() {
- long array[] = new long[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- LongBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i));
- assertSame(ret, buf);
- }
-
- buf.get(new long[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((long[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.LongBuffer get(long[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {long[].class, int.class, int.class}
- )
- public void testGetlongArrayintint() {
- buf.clear();
- long array[] = new long[buf.capacity()];
-
- try {
- buf.get(new long[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, 2, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get((long[])null, 2, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- LongBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for long get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- LongBuffer readonly = buf.asReadOnlyBuffer();
- LongBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for non direct buffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
-
- /*
- * Class under test for java.nio.LongBuffer put(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {long.class}
- )
- public void testPutlong() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- LongBuffer ret = buf.put((long) i);
- assertEquals(buf.get(i), (long) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.LongBuffer put(long[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {long[].class}
- )
- public void testPutlongArray() {
- long array[] = new long[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (long) i;
- LongBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (long) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.position(buf.limit());
- buf.put((long[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.LongBuffer put(long[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {long[].class, int.class, int.class}
- )
- public void testPutlongArrayintint() {
- buf.clear();
- long array[] = new long[buf.capacity()];
- try {
- buf.put(new long[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((long[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- LongBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.LongBuffer put(java.nio.LongBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.LongBuffer.class}
- )
- public void testPutLongBuffer() {
- LongBuffer other = LongBuffer.allocate(buf.capacity());
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(LongBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.flip();
- buf.put((LongBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- loadTestData2(other);
- other.clear();
- buf.clear();
- LongBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.LongBuffer put(int, long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, long.class}
- )
- public void testPutintlong() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- LongBuffer ret = buf.put(i, (long) i);
- assertEquals(buf.get(i), (long) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- LongBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(slice.position(), 0);
- assertEquals(slice.limit(), buf.remaining());
- assertEquals(slice.capacity(), buf.remaining());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, 0, slice.capacity());
- buf.put(2, 500);
- assertEquals(slice.get(1), 500);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Long") >= 0 || str.indexOf("long") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- /*
- * test for method public static LongBuffer wrap(long[] array) test covers
- * following usecases: 1. case for check LongBuffer buf2 properties 2. case
- * for check equal between buf2 and ling array[] 3. case for check a buf2
- * dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {long[].class}
- )
- public void test_Wrap$L() {
- long array[] = new long[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- LongBuffer buf2 = LongBuffer.wrap(array);
-
- // case: LongBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: LongBuffer buf2 is equal to long array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: LongBuffer buf2 is depended to long array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method public static LongBuffer wrap(long[] array, int offset,
- * int length) test covers following usecases: 1. case for check LongBuffer
- * buf2 properties 2. case for check equal between buf2 and long array[] 3.
- * case for check a buf2 dependens to array[] 4. case expected
- * IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {long[].class, int.class, int.class}
- )
- public void test_Wrap$LII() {
- long array[] = new long[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- LongBuffer buf2 = LongBuffer.wrap(array, offset, length);
-
- // case: LongBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: LongBuffer buf2 is equal to long array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: LongBuffer buf2 is depended to long array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = LongBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- void loadTestData1(long array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (long) i;
- }
- }
-
- void loadTestData2(long array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (long) length - i;
- }
- }
-
- void loadTestData1(LongBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (long) i);
- }
- }
-
- void loadTestData2(LongBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (long) buf.capacity() - i);
- }
- }
-
- void assertContentEquals(LongBuffer buf, long array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i]);
- }
- }
-
- void assertContentEquals(LongBuffer buf, LongBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i));
- }
- }
-
- void assertContentLikeTestData1(LongBuffer buf,
- int startIndex, long startValue, int length) {
- long value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value);
- value = value + 1;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
deleted file mode 100644
index f88a163..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/MappedByteBufferTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// BEGIN android-note
-// This test was copied from a newer version of Harmony
-// END android-note
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.IntBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileChannel.MapMode;
-
-@TestTargetClass(
- value = MappedByteBuffer.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_FEASIBLE,
- method = "isLoaded",
- args = {}
- )
- }
-)
-public class MappedByteBufferTest extends DirectByteBufferTest {
-
- File tmpFile;
- FileChannel fc;
-
- /**
- * A regression test for failing to correctly set capacity of underlying
- * wrapped buffer from a mapped byte buffer.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "A regression test for failing to correctly set capacity",
- method = "asIntBuffer",
- args = {}
- )
- public void test_asIntBuffer() {
- int len = buf.capacity();
- assertEquals("Got wrong number of bytes", BUFFER_LENGTH, len);
-
- // Read in our 26 bytes
- for (int i = 0; i < BUFFER_LENGTH - 20; i++) {
- byte b = buf.get();
- assertEquals("Got wrong byte value", (byte) i, b);
- }
-
- // Now convert to an IntBuffer to read our ints
- IntBuffer ibuffer = buf.asIntBuffer();
- for (int i = BUFFER_LENGTH - 20; i < BUFFER_LENGTH; i+=4) {
- int val = ibuffer.get();
- int res = i * 16777216 + (i + 1) * 65536 + (i + 2) * 256 + (i + 3);
- assertEquals("Got wrong int value", res, val);
- }
- }
-
- /**
- * @tests {@link java.nio.MappedByteBuffer#force()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "force",
- args = {}
- )
- public void test_force() throws IOException {
- // buffer was not mapped in read/write mode
- FileInputStream fileInputStream = new FileInputStream(tmpFile);
- FileChannel fileChannelRead = fileInputStream.getChannel();
- MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
- fileChannelRead.size());
-
- mmbRead.force();
-
- FileInputStream inputStream = new FileInputStream(tmpFile);
- FileChannel fileChannelR = inputStream.getChannel();
- MappedByteBuffer resultRead = fileChannelR.map(MapMode.READ_ONLY, 0,
- fileChannelR.size());
-
- //If this buffer was not mapped in read/write mode, then invoking this method has no effect.
- assertEquals(
- "Invoking force() should have no effect when this buffer was not mapped in read/write mode",
- mmbRead, resultRead);
-
- // Buffer was mapped in read/write mode
- RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
- FileChannel fileChannelReadWrite = randomFile.getChannel();
- MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
- FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());
-
- mmbReadWrite.put((byte) 'o');
- mmbReadWrite.force();
-
- RandomAccessFile random = new RandomAccessFile(tmpFile, "rw");
- FileChannel fileChannelRW = random.getChannel();
- MappedByteBuffer resultReadWrite = fileChannelRW.map(
- FileChannel.MapMode.READ_WRITE, 0, fileChannelRW.size());
-
- // Invoking force() will change the buffer
- assertFalse(mmbReadWrite.equals(resultReadWrite));
-
- fileChannelRead.close();
- fileChannelR.close();
- fileChannelReadWrite.close();
- fileChannelRW.close();
- }
-
- /**
- * @tests {@link java.nio.MappedByteBuffer#load()}
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "load",
- args = {}
- )
- public void test_load() throws IOException {
- FileInputStream fileInputStream = new FileInputStream(tmpFile);
- FileChannel fileChannelRead = fileInputStream.getChannel();
- MappedByteBuffer mmbRead = fileChannelRead.map(MapMode.READ_ONLY, 0,
- fileChannelRead.size());
-
- assertEquals(mmbRead, mmbRead.load());
-
- RandomAccessFile randomFile = new RandomAccessFile(tmpFile, "rw");
- FileChannel fileChannelReadWrite = randomFile.getChannel();
- MappedByteBuffer mmbReadWrite = fileChannelReadWrite.map(
- FileChannel.MapMode.READ_WRITE, 0, fileChannelReadWrite.size());
-
- assertEquals(mmbReadWrite, mmbReadWrite.load());
-
- fileChannelRead.close();
- fileChannelReadWrite.close();
- }
-
- protected void setUp() throws IOException {
- // Create temp file with 26 bytes and 5 ints
- tmpFile = File.createTempFile("MappedByteBufferTest", ".tmp");
- tmpFile.createNewFile();
- tmpFile.deleteOnExit();
-
- fillTempFile();
-
- // Map file
- RandomAccessFile raf = new RandomAccessFile(tmpFile, "rw");
- fc = raf.getChannel();
- capacity = (int) fc.size();
- buf = fc.map(FileChannel.MapMode.READ_WRITE, 0, capacity);
- baseBuf = buf;
- }
-
- protected void tearDown() throws IOException {
- fc.close();
- }
-
- private void fillTempFile() throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream(tmpFile);
- FileChannel fileChannel = fileOutputStream.getChannel();
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BUFFER_LENGTH);
-
- loadTestData1(byteBuffer);
- byteBuffer.clear();
- fileChannel.write(byteBuffer);
-
- fileChannel.close();
- fileOutputStream.close();
- }
-} \ No newline at end of file
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java
deleted file mode 100644
index 4be8a43..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyBufferExceptionTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ReadOnlyBufferException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(ReadOnlyBufferException.class)
-public class ReadOnlyBufferExceptionTest extends TestCase {
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "ReadOnlyBufferException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new ReadOnlyBufferException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "ReadOnlyBufferException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new ReadOnlyBufferException());
- }
-
- /**
- *@tests {@link java.nio.ReadOnlyBufferException#ReadOnlyBufferException()}
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "ReadOnlyBufferException",
- args = {}
- )
- public void test_Constructor() {
- ReadOnlyBufferException exception = new ReadOnlyBufferException();
- assertNull(exception.getMessage());
- assertNull(exception.getLocalizedMessage());
- assertNull(exception.getCause());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
deleted file mode 100644
index 2c25f12..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyCharBufferTest.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.CharBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class ReadOnlyCharBufferTest extends CharBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that isReadOnly returns true for read only CharBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray returns false for read only CharBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- CharBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {char.class}
- )
- public void testPutchar() {
- try {
- buf.put((char) 0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException and NullPointerException.",
- method = "put",
- args = {char[].class}
- )
- public void testPutcharArray() {
- char array[] = new char[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((char[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {char[].class, int.class, int.class}
- )
- public void testPutcharArrayintint() {
- char array[] = new char[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((char[]) null, 0, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.CharBuffer.class}
- )
- public void testPutCharBuffer() {
- CharBuffer other = CharBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((CharBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, char.class}
- )
- public void testPutintchar() {
- try {
- buf.put(0, (char) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (char) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void testPutStringintint() {
- buf.clear();
- String str = String.valueOf(new char[buf.capacity()]);
- try {
- buf.put(str, 0, str.length());
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((String) null, 0, 0);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(str, -1, str.length());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- String longStr = String.valueOf(new char[buf.capacity()+1]);
- try {
- buf.put(longStr, 0, longStr.length());
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.lang.String.class}
- )
- public void testPutString() {
- String str = " ";
- try {
- buf.put(str);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((String)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDirectByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDirectByteBufferTest.java
deleted file mode 100644
index e9e1582..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDirectByteBufferTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class ReadOnlyDirectByteBufferTest extends DirectByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only ByteBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- super.readOnlyHashCode(true);
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDoubleBufferTest.java
deleted file mode 100644
index 8a1466f..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyDoubleBufferTest.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.DoubleBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class ReadOnlyDoubleBufferTest extends DoubleBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only DoubleBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray returns false value.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- DoubleBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {double.class}
- )
- public void testPutdouble() {
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {double[].class}
- )
- public void testPutdoubleArray() {
- double array[] = new double[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((double[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {double[].class, int.class, int.class}
- )
- public void testPutdoubleArrayintint() {
- double array[] = new double[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((double[]) null, 0, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new double[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.DoubleBuffer.class}
- )
- public void testPutDoubleBuffer() {
- DoubleBuffer other = DoubleBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((DoubleBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, double.class}
- )
- public void testPutintdouble() {
- try {
- buf.put(0, (double) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (double) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyFloatBufferTest.java
deleted file mode 100644
index 414f1ac..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyFloatBufferTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.FloatBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class ReadOnlyFloatBufferTest extends FloatBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only FloatBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray returns false for Read Only FloatBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- FloatBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {float.class}
- )
- public void testPutfloat() {
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {float[].class}
- )
- public void testPutfloatArray() {
- float array[] = new float[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((float[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {float[].class, int.class, int.class}
- )
- public void testPutfloatArrayintint() {
- float array[] = new float[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((float[]) null, 0, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new float[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.FloatBuffer.class}
- )
- public void testPutFloatBuffer() {
- FloatBuffer other = FloatBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((FloatBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, float.class}
- )
- public void testPutintfloat() {
- try {
- buf.put(0, (float) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (float) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapByteBufferTest.java
deleted file mode 100644
index ccb57af..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapByteBufferTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import java.nio.ReadOnlyBufferException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class ReadOnlyHeapByteBufferTest extends HeapByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only ByteBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies false returned value.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- super.readOnlyHashCode(false);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapCharBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapCharBufferTest.java
deleted file mode 100644
index 3bcc5b1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapCharBufferTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class ReadOnlyHeapCharBufferTest extends ReadOnlyCharBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapDoubleBufferTest.java
deleted file mode 100644
index 48dfe8a..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapDoubleBufferTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class ReadOnlyHeapDoubleBufferTest extends ReadOnlyDoubleBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapFloatBufferTest.java
deleted file mode 100644
index 7e969a3..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapFloatBufferTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class ReadOnlyHeapFloatBufferTest extends ReadOnlyFloatBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapIntBufferTest.java
deleted file mode 100644
index ddddfe1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapIntBufferTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class ReadOnlyHeapIntBufferTest extends ReadOnlyIntBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapLongBufferTest.java
deleted file mode 100644
index b7fda62..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapLongBufferTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class ReadOnlyHeapLongBufferTest extends ReadOnlyLongBufferTest{
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapShortBufferTest.java
deleted file mode 100644
index b850c38..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyHeapShortBufferTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class ReadOnlyHeapShortBufferTest extends ReadOnlyShortBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyIntBufferTest.java
deleted file mode 100644
index 44262ef..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyIntBufferTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.IntBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class ReadOnlyIntBufferTest extends IntBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only IntBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method returns false for read only IntBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- IntBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class}
- )
- public void testPutint() {
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int[].class}
- )
- public void testPutintArray() {
- int array[] = new int[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((int[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int[].class, int.class, int.class}
- )
- public void testPutintArrayintint() {
- int array[] = new int[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((int[]) null, -1, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new int[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.IntBuffer.class}
- )
- public void testPutIntBuffer() {
- IntBuffer other = IntBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((IntBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, int.class}
- )
- public void testPutintint() {
- try {
- buf.put(0, (int) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (int) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyLongBufferTest.java
deleted file mode 100644
index 8b104e0..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyLongBufferTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.LongBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class ReadOnlyLongBufferTest extends LongBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only LongBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that hasArray method returns false for read only LongBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- LongBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {long.class}
- )
- public void testPutlong() {
- try {
- buf.put(0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {long[].class}
- )
- public void testPutlongArray() {
- long array[] = new long[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((long[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {long[].class, int.class, int.class}
- )
- public void testPutlongArrayintint() {
- long array[] = new long[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((long[]) null, 0, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new long[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.LongBuffer.class}
- )
- public void testPutLongBuffer() {
- LongBuffer other = LongBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((LongBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, long.class}
- )
- public void testPutintlong() {
- try {
- buf.put(0, (long) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (long) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyShortBufferTest.java
deleted file mode 100644
index ce0c777..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyShortBufferTest.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ReadOnlyBufferException;
-import java.nio.ShortBuffer;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class ReadOnlyShortBufferTest extends ShortBufferTest {
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only ShortBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for read only ShortBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- ShortBuffer duplicate = buf.duplicate();
- assertEquals(buf.hashCode(), duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "compact",
- args = {}
- )
- public void testCompact() {
- try {
- buf.compact();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {short.class}
- )
- public void testPutshort() {
- try {
- buf.put((short)0);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {short[].class}
- )
- public void testPutshortArray() {
- short array[] = new short[1];
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((short[]) null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {short[].class, int.class, int.class}
- )
- public void testPutshortArrayintint() {
- short array[] = new short[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((short[]) null, 0, 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(new short[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.ShortBuffer.class}
- )
- public void testPutShortBuffer() {
- ShortBuffer other = ShortBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((ShortBuffer) null);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException.",
- method = "put",
- args = {int.class, short.class}
- )
- public void testPutintshort() {
- try {
- buf.put(0, (short) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put(-1, (short) 0);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedByteBufferTest.java
deleted file mode 100644
index 75064de..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedByteBufferTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import java.nio.ReadOnlyBufferException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class ReadOnlyWrappedByteBufferTest extends WrappedByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isReadOnly method for read only wrapped ByteBuffer.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertTrue(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies hasArray method for read only wrapped ByteBuffer.",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- assertFalse(buf.hasArray());
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- super.readOnlyHashCode(false);
- }
-
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
deleted file mode 100644
index 3e45662..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedCharBufferTest1.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.CharBuffer;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class ReadOnlyWrappedCharBufferTest1 extends ReadOnlyCharBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java
deleted file mode 100644
index ab3f66c..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedDoubleBufferTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.DoubleBuffer;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class ReadOnlyWrappedDoubleBufferTest extends ReadOnlyDoubleBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = DoubleBuffer.wrap(new double[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf =null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java
deleted file mode 100644
index 3731683..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedFloatBufferTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.FloatBuffer;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class ReadOnlyWrappedFloatBufferTest extends ReadOnlyFloatBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = FloatBuffer.wrap(new float[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java
deleted file mode 100644
index f5bdf40..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedIntBufferTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.IntBuffer;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class ReadOnlyWrappedIntBufferTest extends ReadOnlyIntBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = IntBuffer.wrap(new int[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java
deleted file mode 100644
index ee2ba73..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedLongBufferTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.LongBuffer;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class ReadOnlyWrappedLongBufferTest extends ReadOnlyLongBufferTest{
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = LongBuffer.wrap(new long[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
deleted file mode 100644
index 34ac3e4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ReadOnlyWrappedShortBufferTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ShortBuffer;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class ReadOnlyWrappedShortBufferTest extends ReadOnlyShortBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
- loadTestData1(buf);
- buf = buf.asReadOnlyBuffer();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
deleted file mode 100644
index 02f6ce9..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/ShortBufferTest.java
+++ /dev/null
@@ -1,947 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.InvalidMarkException;
-import java.nio.ShortBuffer;
-
-/**
- * Tests java.nio.ShortBuffer
- *
- */
-@TestTargetClass(java.nio.ShortBuffer.class)
-public abstract class ShortBufferTest extends AbstractBufferTest {
-
- protected static final int SMALL_TEST_LENGTH = 5;
-
- protected static final int BUFFER_LENGTH = 20;
-
- protected ShortBuffer buf;
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ShortBuffer.allocate(BUFFER_LENGTH);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /*
- * test for method static ShortBuffer allocate(int capacity) test covers
- * following usecases: 1. case for check ShortBuffer testBuf properties 2.
- * case expected IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "allocate",
- args = {int.class}
- )
- public void test_AllocateI() {
- // case: ShortBuffer testBuf properties is satisfy the conditions
- // specification
- ShortBuffer testBuf = ShortBuffer.allocate(20);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(20, testBuf.limit());
- assertEquals(20, testBuf.capacity());
-
- testBuf = ShortBuffer.allocate(0);
- assertEquals(0, testBuf.position());
- assertNotNull(testBuf.array());
- assertEquals(0, testBuf.arrayOffset());
- assertEquals(0, testBuf.limit());
- assertEquals(0, testBuf.capacity());
-
- // case: expected IllegalArgumentException
- try {
- testBuf = ShortBuffer.allocate(-20);
- fail("allocate method does not throws expected exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "array",
- args = {}
- )
- public void testArray() {
- short array[] = buf.array();
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(array, buf.arrayOffset(), buf.capacity());
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData1(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
-
- loadTestData2(buf);
- assertContentEquals(buf, array, buf.arrayOffset(), buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- short array[] = buf.array();
- for(int i = 0; i < buf.capacity(); i++) {
- array[i] = (short) i;
- }
- int offset = buf.arrayOffset();
- assertContentEquals(buf, array, offset, buf.capacity());
-
- ShortBuffer wrapped = ShortBuffer.wrap(array, 3, array.length - 3);
-
- loadTestData1(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
-
- loadTestData2(array, wrapped.arrayOffset(), wrapped.capacity());
- assertContentEquals(buf, array, offset, buf.capacity());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "asReadOnlyBuffer",
- args = {}
- )
- public void testAsReadOnlyBuffer() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // readonly's contents should be the same as buf
- ShortBuffer readonly = buf.asReadOnlyBuffer();
- assertNotSame(buf, readonly);
- assertTrue(readonly.isReadOnly());
- assertEquals(buf.position(), readonly.position());
- assertEquals(buf.limit(), readonly.limit());
- assertEquals(buf.isDirect(), readonly.isDirect());
- assertEquals(buf.order(), readonly.order());
- assertContentEquals(buf, readonly);
-
- // readonly's position, mark, and limit should be independent to buf
- readonly.reset();
- assertEquals(readonly.position(), 0);
- readonly.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compact",
- args = {}
- )
- @AndroidOnly("Fails on RI. See comment below")
- public void testCompact() {
- // case: buffer is full
- buf.clear();
- buf.mark();
- loadTestData1(buf);
- ShortBuffer ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), buf.capacity());
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (short) 0, buf.capacity());
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: buffer is empty
- buf.position(0);
- buf.limit(0);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 0);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (short) 0, buf.capacity());
- try {
- // Fails on RI. Spec doesn't specify the behavior if
- // actually nothing to be done by compact(). So RI doesn't reset
- // mark position
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // case: normal
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(5);
- buf.mark();
- ret = buf.compact();
- assertSame(ret, buf);
- assertEquals(buf.position(), 4);
- assertEquals(buf.limit(), buf.capacity());
- assertContentLikeTestData1(buf, 0, (short) 1, 4);
- try {
- buf.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.nio.ShortBuffer.class}
- )
- public void testCompareTo() {
- // compare to self
- assertEquals(0, buf.compareTo(buf));
-
- // normal cases
- assertTrue(buf.capacity() > 5);
- buf.clear();
- ShortBuffer other = ShortBuffer.allocate(buf.capacity());
- loadTestData1(other);
- assertEquals(0, buf.compareTo(other));
- assertEquals(0, other.compareTo(buf));
- buf.position(1);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- other.position(2);
- assertTrue(buf.compareTo(other) < 0);
- assertTrue(other.compareTo(buf) > 0);
- buf.position(2);
- other.limit(5);
- assertTrue(buf.compareTo(other) > 0);
- assertTrue(other.compareTo(buf) < 0);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "duplicate",
- args = {}
- )
- public void testDuplicate() {
- buf.clear();
- buf.mark();
- buf.position(buf.limit());
-
- // duplicate's contents should be the same as buf
- ShortBuffer duplicate = buf.duplicate();
- assertNotSame(buf, duplicate);
- assertEquals(buf.position(), duplicate.position());
- assertEquals(buf.limit(), duplicate.limit());
- assertEquals(buf.isReadOnly(), duplicate.isReadOnly());
- assertEquals(buf.isDirect(), duplicate.isDirect());
- assertEquals(buf.order(), duplicate.order());
- assertContentEquals(buf, duplicate);
-
- // duplicate's position, mark, and limit should be independent to buf
- duplicate.reset();
- assertEquals(duplicate.position(), 0);
- duplicate.clear();
- assertEquals(buf.position(), buf.limit());
- buf.reset();
- assertEquals(buf.position(), 0);
-
- // duplicate share the same content with buf
- if (!duplicate.isReadOnly()) {
- loadTestData1(buf);
- assertContentEquals(buf, duplicate);
- loadTestData2(duplicate);
- assertContentEquals(buf, duplicate);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEquals() {
- // equal to self
- assertTrue(buf.equals(buf));
- ShortBuffer readonly = buf.asReadOnlyBuffer();
- assertTrue(buf.equals(readonly));
- ShortBuffer duplicate = buf.duplicate();
- assertTrue(buf.equals(duplicate));
-
- // always false, if type mismatch
- assertFalse(buf.equals(Boolean.TRUE));
-
- assertTrue(buf.capacity() > 5);
-
- buf.limit(buf.capacity()).position(0);
- readonly.limit(readonly.capacity()).position(1);
- assertFalse(buf.equals(readonly));
-
- buf.limit(buf.capacity() - 1).position(0);
- duplicate.limit(duplicate.capacity()).position(0);
- assertFalse(buf.equals(duplicate));
- }
-
- /*
- * Class under test for short get()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {}
- )
- public void testGet() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get();
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ShortBuffer get(short[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {short[].class}
- )
- public void testGetshortArray() {
- short array[] = new short[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- ShortBuffer ret = buf.get(array);
- assertEquals(array[0], buf.get(i));
- assertSame(ret, buf);
- }
-
- buf.get(new short[0]);
-
- try {
- buf.get(array);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
-
- try {
- buf.get((short[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ShortBuffer get(short[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {short[].class, int.class, int.class}
- )
- public void testGetshortArrayintint() {
- buf.clear();
- short array[] = new short[buf.capacity()];
-
- try {
- buf.get(new short[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferUnderflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.get(array, array.length, 0);
- try {
- buf.get(array, array.length + 1, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.get((short[])null, 2, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.get(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- buf.clear();
- ShortBuffer ret = buf.get(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for short get(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "get",
- args = {int.class}
- )
- public void testGetint() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- assertEquals(buf.get(), buf.get(i));
- }
- try {
- buf.get(-1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.get(buf.limit());
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hasArray",
- args = {}
- )
- public void testHasArray() {
- if (buf.hasArray()) {
- assertNotNull(buf.array());
- } else {
- try {
- buf.array();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- // expected
- // Note:can not tell when to catch
- // UnsupportedOperationException or
- // ReadOnlyBufferException, so catch all.
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "hashCode",
- args = {}
- )
- public void testHashCode() {
- buf.clear();
- ShortBuffer readonly = buf.asReadOnlyBuffer();
- ShortBuffer duplicate = buf.duplicate();
- assertTrue(buf.hashCode() == readonly.hashCode());
-
- assertTrue(buf.capacity() > 5);
- duplicate.position(buf.capacity() / 2);
- assertTrue(buf.hashCode() != duplicate.hashCode());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies isDirect method for non direct ShortBuffer.",
- method = "isDirect",
- args = {}
- )
- public void testIsDirect() {
- assertFalse(buf.isDirect());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Abstract method.",
- method = "isReadOnly",
- args = {}
- )
- public void testIsReadOnly() {
- assertFalse(buf.isReadOnly());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "order",
- args = {}
- )
- public void testOrder() {
- assertEquals(ByteOrder.nativeOrder(), buf.order());
- }
-
- /*
- * Class under test for java.nio.ShortBuffer put(short)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {short.class}
- )
- public void testPutshort() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- ShortBuffer ret = buf.put((short) i);
- assertEquals(buf.get(i), (short) i);
- assertSame(ret, buf);
- }
- try {
- buf.put((short) 0);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ShortBuffer put(short[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {short[].class}
- )
- public void testPutshortArray() {
- short array[] = new short[1];
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), i);
- array[0] = (short) i;
- ShortBuffer ret = buf.put(array);
- assertEquals(buf.get(i), (short) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(array);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.position(buf.limit());
- buf.put((short[])null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /*
- * Class under test for java.nio.ShortBuffer put(short[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {short[].class, int.class, int.class}
- )
- public void testPutshortArrayintint() {
- buf.clear();
- short array[] = new short[buf.capacity()];
- try {
- buf.put(new short[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, -1, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, array.length + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- buf.put(array, array.length, 0);
- assertEquals(buf.position(), 0);
- try {
- buf.put(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put((short[])null, 0, -1);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(array, 2, array.length);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- assertEquals(buf.position(), 0);
-
- loadTestData2(array, 0, array.length);
- ShortBuffer ret = buf.put(array, 0, array.length);
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(buf, array, 0, array.length);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.IntBuffer put(int[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test",
- method = "put",
- args = {short[].class, int.class, int.class}
- )
- public void testPutshortArrayintint2() {
- // Regression test
- ByteBuffer buf = ByteBuffer.allocateDirect(10);
- ShortBuffer shortBuf = buf.asShortBuffer();
- short[] src = new short[5];
- shortBuf.put(src);
- shortBuf.clear();
- try {
- shortBuf.put(src);
- } catch (BufferOverflowException e) {
- fail("should not throw a BufferOverflowException");
- }
- }
-
- /*
- * Class under test for java.nio.ShortBuffer put(java.nio.ShortBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {java.nio.ShortBuffer.class}
- )
- public void testPutShortBuffer() {
- ShortBuffer other = ShortBuffer.allocate(buf.capacity());
- try {
- buf.put(buf);
- fail("Should throw Exception");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- buf.put(ShortBuffer.allocate(buf.capacity() + 1));
- fail("Should throw Exception");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.flip();
- buf.put((ShortBuffer)null);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- loadTestData2(other);
- other.clear();
- buf.clear();
- ShortBuffer ret = buf.put(other);
- assertEquals(other.position(), other.capacity());
- assertEquals(buf.position(), buf.capacity());
- assertContentEquals(other, buf);
- assertSame(ret, buf);
- }
-
- /*
- * Class under test for java.nio.ShortBuffer put(int, short)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify ReadOnlyBufferException.",
- method = "put",
- args = {int.class, short.class}
- )
- public void testPutintshort() {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.position(), 0);
- ShortBuffer ret = buf.put(i, (short) i);
- assertEquals(buf.get(i), (short) i);
- assertSame(ret, buf);
- }
- try {
- buf.put(-1, (short) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- buf.put(buf.limit(), (short) 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- public void testSlice() {
- assertTrue(buf.capacity() > 5);
- buf.position(1);
- buf.limit(buf.capacity() - 1);
-
- ShortBuffer slice = buf.slice();
- assertEquals(buf.isReadOnly(), slice.isReadOnly());
- assertEquals(buf.isDirect(), slice.isDirect());
- assertEquals(buf.order(), slice.order());
- assertEquals(slice.position(), 0);
- assertEquals(slice.limit(), buf.remaining());
- assertEquals(slice.capacity(), buf.remaining());
- try {
- slice.reset();
- fail("Should throw Exception");
- } catch (InvalidMarkException e) {
- // expected
- }
-
- // slice share the same content with buf
- if (!slice.isReadOnly()) {
- loadTestData1(slice);
- assertContentLikeTestData1(buf, 1, (short) 0, slice.capacity());
- buf.put(2, (short) 500);
- assertEquals(slice.get(1), 500);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- String str = buf.toString();
- assertTrue(str.indexOf("Short") >= 0 || str.indexOf("short") >= 0);
- assertTrue(str.indexOf("" + buf.position()) >= 0);
- assertTrue(str.indexOf("" + buf.limit()) >= 0);
- assertTrue(str.indexOf("" + buf.capacity()) >= 0);
- }
-
- /*
- * test for method static ShortBuffer wrap(short[] array) test covers
- * following usecases: 1. case for check ShortBuffer buf2 properties 2. case
- * for check equal between buf2 and short array[] 3. case for check a buf2
- * dependens to array[]
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {short[].class}
- )
- public void test_Wrap$S() {
- short array[] = new short[BUFFER_LENGTH];
- loadTestData1(array, 0, BUFFER_LENGTH);
- ShortBuffer buf2 = ShortBuffer.wrap(array);
-
- // case: ShortBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.limit(), array.length);
- assertEquals(buf2.position(), 0);
-
- // case: ShortBuffer buf2 is equal to short array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: ShortBuffer buf2 is depended to short array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
- }
-
- /*
- * test for method static ShortBuffer wrap(short[] array, int offset, int
- * length) test covers following usecases: 1. case for check ShortBuffer
- * buf2 properties 2. case for check equal between buf2 and short array[] 3.
- * case for check a buf2 dependens to array[] 4. case expected
- * IndexOutOfBoundsException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {short[].class, int.class, int.class}
- )
- public void test_Wrap$SII() {
- short array[] = new short[BUFFER_LENGTH];
- int offset = 5;
- int length = BUFFER_LENGTH - offset;
- loadTestData1(array, 0, BUFFER_LENGTH);
- ShortBuffer buf2 = ShortBuffer.wrap(array, offset, length);
-
- // case: ShortBuffer buf2 properties is satisfy the conditions
- // specification
- assertEquals(buf2.capacity(), array.length);
- assertEquals(buf2.position(), offset);
- assertEquals(buf2.limit(), offset + length);
- assertEquals(buf2.arrayOffset(), 0);
-
- // case: ShortBuffer buf2 is equal to short array[]
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: ShortBuffer buf2 is depended to short array[]
- loadTestData2(array, 0, buf.capacity());
- assertContentEquals(buf2, array, 0, array.length);
-
- // case: expected IndexOutOfBoundsException
- try {
- offset = 7;
- buf2 = ShortBuffer.wrap(array, offset, length);
- fail("wrap method does not throws expected exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- void loadTestData1(short array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (short) i;
- }
- }
-
- void loadTestData2(short array[], int offset, int length) {
- for (int i = 0; i < length; i++) {
- array[offset + i] = (short) (length - i);
- }
- }
-
- void loadTestData1(ShortBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (short) i);
- }
- }
-
- void loadTestData2(ShortBuffer buf) {
- buf.clear();
- for (int i = 0; i < buf.capacity(); i++) {
- buf.put(i, (short) (buf.capacity() - i));
- }
- }
-
- void assertContentEquals(ShortBuffer buf, short array[],
- int offset, int length) {
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(i), array[offset + i]);
- }
- }
-
- void assertContentEquals(ShortBuffer buf, ShortBuffer other) {
- assertEquals(buf.capacity(), other.capacity());
- for (int i = 0; i < buf.capacity(); i++) {
- assertEquals(buf.get(i), other.get(i));
- }
- }
-
- void assertContentLikeTestData1(ShortBuffer buf,
- int startIndex, short startValue, int length) {
- short value = startValue;
- for (int i = 0; i < length; i++) {
- assertEquals(buf.get(startIndex + i), value);
- value = (short) (value + 1);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java
deleted file mode 100644
index cc1d0b4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceDirectByteBufferTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class SliceDirectByteBufferTest extends DirectByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH - 1);
- buf = buf.slice();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java
deleted file mode 100644
index 40670b2..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceHeapByteBufferTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class SliceHeapByteBufferTest extends HeapByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH - 1);
- buf = buf.slice();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java
deleted file mode 100644
index 0ddbe06..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/SliceWrappedByteBufferTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class SliceWrappedByteBufferTest extends WrappedByteBufferTest {
-
- protected void setUp() throws Exception {
- super.setUp();
- capacity = BUFFER_LENGTH - 2;
- buf.position(1).limit(BUFFER_LENGTH - 1);
- buf = buf.slice();
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java
deleted file mode 100644
index eb0e608..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedByteBufferTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ByteBuffer;
-
-@TestTargetClass(java.nio.ByteBuffer.class)
-public class WrappedByteBufferTest extends ByteBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ByteBuffer.wrap(new byte[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /**
- * @tests java.nio.ByteBuffer#allocate(byte[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IndexOutOfBoundsException, NullPointerException.",
- method = "wrap",
- args = {byte[].class, int.class, int.class}
- )
- public void testWrappedByteBuffer_IllegalArg() {
- byte array[] = new byte[BUFFER_LENGTH];
- try {
- ByteBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap(array, BUFFER_LENGTH + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap(array, 0, BUFFER_LENGTH + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ByteBuffer.wrap((byte[])null, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java
deleted file mode 100644
index d7325b0..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest1.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.CharBuffer;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class WrappedCharBufferTest1 extends CharBufferTest {
-
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = CharBuffer.wrap(new char[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- baseBuf = null;
- buf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IndexOutOfBoundsException, NullPointerException.",
- method = "wrap",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void testWrappedCharBuffer_IllegalArg() {
- char array[] = new char[BUFFER_LENGTH];
- try {
- CharBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, BUFFER_LENGTH + 1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 0, BUFFER_LENGTH + 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap((char[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
deleted file mode 100644
index 5f7a6b9..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedCharBufferTest2.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.AndroidOnly;
-
-import java.nio.BufferOverflowException;
-import java.nio.CharBuffer;
-import java.nio.ReadOnlyBufferException;
-
-@TestTargetClass(java.nio.CharBuffer.class)
-public class WrappedCharBufferTest2 extends ReadOnlyCharBufferTest {
- protected static final String TEST_STRING = "123456789abcdef12345";
-
- protected void setUp() throws Exception {
- super.setUp();
- capacity = TEST_STRING.length();
- buf = CharBuffer.wrap(TEST_STRING);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- baseBuf = null;
- buf = null;
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException, IndexOutOfBoundsException.",
- method = "wrap",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void testWrappedCharSequence_IllegalArg() {
- String str = TEST_STRING;
- try {
- CharBuffer.wrap(str, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 21, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 2, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap(str, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- CharBuffer.wrap((String)null, -1, 21);
- fail("Should throw Exception");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedOperationException for CharSequenceAdapter.",
- method = "array",
- args = {}
- )
- public void testArray() {
- try {
- buf.array();
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedOperationException.",
- method = "arrayOffset",
- args = {}
- )
- public void testArrayOffset() {
- try {
- buf.arrayOffset();
- fail("Should throw Exception");
- } catch (UnsupportedOperationException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException, NullPointerException, BufferOverflowException, IndexOutOfBoundsException.",
- method = "put",
- args = {char[].class, int.class, int.class}
- )
- public void testPutcharArrayintint() {
- char array[] = new char[1];
- try {
- buf.put(array, 0, array.length);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((char[]) null, 0, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(new char[buf.capacity() + 1], 0, buf.capacity() + 1);
- fail("Should throw BufferOverflowException");
- } catch (BufferOverflowException e) {
- // expected
- }
- try {
- buf.put(array, -1, array.length);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ReadOnlyBufferException, NullPointerException, IllegalArgumentException.",
- method = "read",
- args = {java.nio.CharBuffer.class}
- )
- public void testPutCharBuffer() {
- CharBuffer other = CharBuffer.allocate(1);
- try {
- buf.put(other);
- fail("Should throw ReadOnlyBufferException");
- } catch (ReadOnlyBufferException e) {
- // expected
- }
- try {
- buf.put((CharBuffer) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- buf.put(buf);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "slice",
- args = {}
- )
- @AndroidOnly("Fails on RI")
- public void testSlice() {
- super.testSlice();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java
deleted file mode 100644
index 20a5eba..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedDoubleBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.DoubleBuffer;
-
-@TestTargetClass(java.nio.DoubleBuffer.class)
-public class WrappedDoubleBufferTest extends DoubleBufferTest {
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = DoubleBuffer.wrap(new double[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- buf = null;
- baseBuf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {double[].class, int.class, int.class}
- )
- public void testWrappedDoubleuffer_IllegalArg() {
- double array[] = new double[20];
- try {
- DoubleBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap(array, 21, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap(array, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- DoubleBuffer.wrap((double[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
-
- DoubleBuffer buf = DoubleBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java
deleted file mode 100644
index eb3f2b8..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedFloatBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.FloatBuffer;
-
-@TestTargetClass(java.nio.FloatBuffer.class)
-public class WrappedFloatBufferTest extends FloatBufferTest {
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = FloatBuffer.wrap(new float[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- baseBuf = null;
- buf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {float[].class, int.class, int.class}
- )
- public void testWrappedFloatBuffer_IllegalArg() {
- float array[] = new float[20];
- try {
- FloatBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap(array, 21, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap(array, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- FloatBuffer.wrap((float[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
-
- FloatBuffer buf = FloatBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java
deleted file mode 100644
index 90a4dab..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedIntBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.IntBuffer;
-
-@TestTargetClass(java.nio.IntBuffer.class)
-public class WrappedIntBufferTest extends IntBufferTest {
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = IntBuffer.wrap(new int[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- baseBuf = null;
- buf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {int[].class, int.class, int.class}
- )
- public void testWrappedIntBuffer_IllegalArg() {
- int array[] = new int[20];
- try {
- IntBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap(array, 21, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap(array, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- IntBuffer.wrap((int[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
-
- IntBuffer buf = IntBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java
deleted file mode 100644
index dcf6465..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedLongBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.LongBuffer;
-
-@TestTargetClass(java.nio.LongBuffer.class)
-public class WrappedLongBufferTest extends LongBufferTest {
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = LongBuffer.wrap(new long[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- baseBuf = null;
- buf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {long[].class, int.class, int.class}
- )
- public void testWrappedLongBuffer_IllegalArg() {
- long array[] = new long[20];
- try {
- LongBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap(array, 21, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap(array, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- LongBuffer.wrap((long[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
-
- LongBuffer buf = LongBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java
deleted file mode 100644
index 1d1c2c4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/WrappedShortBufferTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.ShortBuffer;
-
-@TestTargetClass(java.nio.ShortBuffer.class)
-public class WrappedShortBufferTest extends ShortBufferTest {
- protected void setUp() throws Exception {
- capacity = BUFFER_LENGTH;
- buf = ShortBuffer.wrap(new short[BUFFER_LENGTH]);
- loadTestData1(buf);
- baseBuf = buf;
- }
-
- protected void tearDown() throws Exception {
- baseBuf = null;
- buf = null;
- }
-
- /**
- * @tests java.nio.CharBuffer#allocate(char[],int,int)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "wrap",
- args = {short[].class, int.class, int.class}
- )
- public void testWrappedShortBuffer_IllegalArg() {
- short array[] = new short[20];
- try {
- ShortBuffer.wrap(array, -1, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap(array, 21, 0);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap(array, 0, -1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap(array, 0, 21);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap(array, Integer.MAX_VALUE, 1);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap(array, 1, Integer.MAX_VALUE);
- fail("Should throw Exception");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- ShortBuffer.wrap((short[])null, -1, 0);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- }
-
- ShortBuffer buf = ShortBuffer.wrap(array, 2, 16);
- assertEquals(buf.position(), 2);
- assertEquals(buf.limit(), 18);
- assertEquals(buf.capacity(), 20);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AllTests.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AllTests.java
deleted file mode 100644
index 0f6c837..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AllTests.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite(AllTests.class.getName());
- //$JUnit-BEGIN$
- suite.addTestSuite(AlreadyConnectedExceptionTest.class);
- suite.addTestSuite(AsynchronousCloseExceptionTest.class);
- suite.addTestSuite(CancelledKeyExceptionTest.class);
- suite.addTestSuite(ChannelsTest.class);
- suite.addTestSuite(ClosedByInterruptExceptionTest.class);
- suite.addTestSuite(ClosedChannelExceptionTest.class);
- suite.addTestSuite(ClosedSelectorExceptionTest.class);
- suite.addTestSuite(ConnectionPendingExceptionTest.class);
- suite.addTestSuite(DatagramChannelTest.class);
- suite.addTestSuite(FileLockInterruptionExceptionTest.class);
- suite.addTestSuite(FileLockTest.class);
- suite.addTestSuite(IllegalBlockingModeExceptionTest.class);
- suite.addTestSuite(IllegalSelectorExceptionTest.class);
- suite.addTestSuite(MapModeTest.class);
- suite.addTestSuite(NoConnectionPendingExceptionTest.class);
- suite.addTestSuite(NonReadableChannelExceptionTest.class);
- suite.addTestSuite(NonWritableChannelExceptionTest.class);
- suite.addTestSuite(NotYetBoundExceptionTest.class);
- suite.addTestSuite(NotYetConnectedExceptionTest.class);
- suite.addTestSuite(OverlappingFileLockExceptionTest.class);
- suite.addTestSuite(PipeTest.class);
- suite.addTestSuite(SelectableChannelTest.class);
- suite.addTestSuite(SelectionKeyTest.class);
- suite.addTestSuite(SelectorTest.class);
- suite.addTestSuite(SinkChannelTest.class);
- suite.addTestSuite(SourceChannelTest.class);
- suite.addTestSuite(UnresolvedAddressExceptionTest.class);
- suite.addTestSuite(UnsupportedAddressTypeExceptionTest.class);
- // $JUnit-END$
- return suite;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AlreadyConnectedExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AlreadyConnectedExceptionTest.java
deleted file mode 100644
index 3b0dfc9..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AlreadyConnectedExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.AlreadyConnectedException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(AlreadyConnectedException.class)
-/**
- * Tests for AlreadyConnectedException
- */
-public class AlreadyConnectedExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.AlreadyConnectedException#AlreadyConnectedException()}
- */
- public void test_Constructor() {
- AlreadyConnectedException e = new AlreadyConnectedException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "AlreadyConnectedException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new AlreadyConnectedException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "AlreadyConnectedException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new AlreadyConnectedException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AsynchronousCloseExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AsynchronousCloseExceptionTest.java
deleted file mode 100644
index 7f7ca65..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/AsynchronousCloseExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.AsynchronousCloseException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for AsynchronousCloseException
- */
-@TestTargetClass(AsynchronousCloseException.class)
-public class AsynchronousCloseExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.AsynchronousCloseException#AsynchronousCloseException()}
- */
- public void test_Constructor() {
- AsynchronousCloseException e = new AsynchronousCloseException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "AsynchronousCloseException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new AsynchronousCloseException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "AsynchronousCloseException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new AsynchronousCloseException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/CancelledKeyExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/CancelledKeyExceptionTest.java
deleted file mode 100644
index 60e0c3a..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/CancelledKeyExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.CancelledKeyException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for CancelledKeyException
- */
-@TestTargetClass(CancelledKeyException.class)
-public class CancelledKeyExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.CancelledKeyException#CancelledKeyException()}
- */
- public void test_Constructor() {
- CancelledKeyException e = new CancelledKeyException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "CancelledKeyException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new CancelledKeyException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "CancelledKeyException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new CancelledKeyException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java
deleted file mode 100644
index f0c44f4..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ChannelsTest.java
+++ /dev/null
@@ -1,1141 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.channels.Channels;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.WritableByteChannel;
-import java.nio.charset.Charset;
-import java.nio.charset.UnsupportedCharsetException;
-
-import tests.support.Support_PortManager;
-
-import junit.framework.TestCase;
-
-/**
- * Note: the test case uses a temp text file named "test" which contains 31
- * characters : "P@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]"
- *
- */
-@TestTargetClass(Channels.class)
-public class ChannelsTest extends TestCase {
- private static final String CODE_SET = "GB2312";
-
- private static final String BAD_CODE_SET = "GB2313";
-
- private FileInputStream fins;
-
- private FileOutputStream fouts;
-
- private final int writebufSize = 60;
-
- private final int testNum = 10;
-
- private final int fileSize = 31;// the file size
-
- private File tmpFile;
-
- protected void setUp() throws Exception {
- super.setUp();
- // Make the test file same in every test
- tmpFile = File.createTempFile("test","tmp");
- tmpFile.deleteOnExit();
- this.writeFileSame();
- }
-
- protected void tearDown() throws Exception {
- if (null != this.fins) {
- this.fins.close();
- this.fins = null;
- }
- if (null != this.fouts) {
- this.fouts.close();
- this.fouts = null;
- }
-
- tmpFile.delete();
- super.tearDown();
-
- }
-
- private void writeFileSame() throws IOException {
- this.fouts = new FileOutputStream(tmpFile);
- byte[] bit = new byte[1];
- bit[0] = 80;
- this.fouts.write(bit);
- this.fouts.flush();
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- this.fouts.write(writebuf.getBytes());
- }
-
- /*
- * This private method is to assert if the file size is the same as the
- * compare Number in the test
- */
- private void assertFileSizeSame(File fileToTest, int compareNumber)
- throws IOException {
- FileInputStream file = new FileInputStream(fileToTest);
- assertEquals(file.available(), compareNumber);
- file.close();
- }
-
- // test if new Channel to input is null
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.InputStream.class}
- )
- public void testNewChannelInputStream_InputNull() throws IOException {
- ByteBuffer byteBuf = ByteBuffer.allocate(this.testNum);
- this.fins = null;
- int readres = this.testNum;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- assertNotNull(rbChannel);
- try {
- readres = rbChannel.read(byteBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(this.testNum, readres);
- }
-
- // test if buffer to read is null
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.InputStream.class}
- )
- public void testNewChannelInputStream_BufferNull() throws IOException {
- ByteBuffer byteBuf = ByteBuffer.allocate(this.testNum);
- int readres = this.testNum;
- this.fins = new FileInputStream(tmpFile);
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- assertNotNull(rbChannel);
- try {
- readres = rbChannel.read(null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(this.testNum, readres);
- readres = 0;
- try {
- readres = rbChannel.read(byteBuf);
- } catch (NullPointerException e) {
- fail();
- }
- assertEquals(this.testNum, readres);
- }
-
- /*
- * Test method for 'java.nio.channels.Channels.NewChannel'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.InputStream.class}
- )
- public void testNewChannelInputStream() throws IOException {
- int bufSize = 10;
- int readres = 0;
- byte[] byteArray = new byte[bufSize];
- ByteBuffer byteBuf = ByteBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- readres = this.fins.read(byteArray);
-
- assertEquals(bufSize, readres);
- assertFalse(0 == this.fins.available());
-
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- // fins still reads.
- assertFalse(0 == this.fins.available());
- readres = this.fins.read(byteArray);
- assertEquals(bufSize, readres);
-
- // rbChannel also reads.
- assertNotNull(rbChannel);
- readres = rbChannel.read(byteBuf);
-
- assertEquals(bufSize, readres);
- InputStream ins = Channels.newInputStream(rbChannel);
- assertNotNull(ins);
- assertEquals(0, ins.available());
- }
-
- // test if fout to change is null
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.OutputStream.class}
- )
- public void testNewChannelOutputStream_inputNull() throws IOException {
- int writeres = this.testNum;
- ByteBuffer writebuf = ByteBuffer.allocate(this.writebufSize);
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf.putChar((char) (val + 64));
- }
- this.fouts = null;
- WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
- writeres = rbChannel.write(writebuf);
- assertEquals(0, writeres);
-
- writebuf.flip();
- try {
- writeres = rbChannel.write(writebuf);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- }
- }
-
- // test if write buf is null
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.OutputStream.class}
- )
- public void testNewChannelOutputStream_BufNull() throws IOException {
- int writeres = this.testNum;
- ByteBuffer writebuf = null;
- try {
- this.fouts = new FileOutputStream(tmpFile);
- } catch (FileNotFoundException e) {
- fail();
- }
-
- WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
- try {
- writeres = rbChannel.write(writebuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(this.testNum, writeres);
- }
-
- /*
- * Test method for 'java.nio.channels.Channels.NewChannel(OutputStream)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newChannel",
- args = {java.io.OutputStream.class}
- )
- public void testNewChannelOutputStream() throws IOException {
- int writeNum = 0;
- ByteBuffer writebuf = ByteBuffer.allocateDirect(this.writebufSize);
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf.putChar((char) (val + 64));
- }
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel testChannel = this.fouts.getChannel();
- WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
-
- assertTrue(testChannel.isOpen());
- assertTrue(rbChannel.isOpen());
-
- byte[] bit = new byte[1];
- bit[0] = 80;
- this.fouts.write(bit);
- this.fouts.flush();
- this.fins = new FileInputStream(tmpFile);
- assertEquals(this.fins.available(), 1);
- this.fins.close();
-
- writeNum = rbChannel.write(writebuf);
- // write success ,but output null
- assertEquals(0, writeNum);
- // close of fouts does not affect on channel
- this.fouts.close();
- writeNum = rbChannel.write(writebuf);
- assertEquals(0, writeNum);
- try {
- writeNum = testChannel.write(writebuf);
- fail();
- } catch (ClosedChannelException e) {
- // correct
- }
- assertEquals(0, writeNum);
- // close of rbchannel does affect on testchannel(same channel)
- rbChannel.close();
- try {
- writeNum = testChannel.write(writebuf);
- fail();
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newInputStream",
- args = {java.nio.channels.ReadableByteChannel.class}
- )
- public void testNewInputStreamReadableByteChannel_InputNull()
- throws Exception {
- byte[] readbuf = new byte[this.testNum];
- this.fins = new FileInputStream(tmpFile);
- ReadableByteChannel readbc = this.fins.getChannel();
- assertEquals(this.fileSize, this.fins.available());
- assertTrue(readbc.isOpen());
- InputStream testins = Channels.newInputStream(null);
- assertNotNull(testins);
-
- try {
- testins.read(readbuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, testins.available());
- try {
- testins.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newInputStream",
- args = {java.nio.channels.ReadableByteChannel.class}
- )
- public void testNewInputStreamReadableByteChannel() throws Exception {
- ByteBuffer readbcbuf = ByteBuffer.allocateDirect(this.testNum);
- byte[] readbuf = new byte[this.testNum];
- this.fins = new FileInputStream(tmpFile);
- ReadableByteChannel readbc = this.fins.getChannel();
- assertEquals(this.fileSize, this.fins.available());
- assertTrue(readbc.isOpen());
- InputStream testins = Channels.newInputStream(readbc);
- // read in testins and fins use the same pointer
- testins.read(readbuf);
- assertEquals(this.fins.available(), this.fileSize - this.testNum);
- int readNum = readbc.read(readbcbuf);
- assertEquals(readNum, this.testNum);
- assertEquals(this.fins.available(), this.fileSize - this.testNum * 2);
- testins.read(readbuf);
- assertEquals(this.fins.available(), this.fileSize - this.testNum * 3);
-
- assertFalse(testins.markSupported());
- try {
- testins.mark(10);
- } catch (UnsupportedOperationException e) {
- // expected;
- }
-
- try {
- testins.reset();
- } catch (IOException e) {
- // expected;
- }
-
- // readbc.close() affect testins
- readbc.close();
- assertFalse(readbc.isOpen());
- try {
- testins.read(readbuf);
- fail();
- } catch (ClosedChannelException e) {
- // correct
- }
-
- // Read methods throw IllegalBlockingModeException if underlying channel
- // is in non-blocking mode.
- SocketChannel chan = SocketChannel.open();
- chan.configureBlocking(false);
- testins = Channels.newInputStream(chan);
- try {
- testins.read();
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- testins.read(new byte[1]);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- testins.read(new byte[1], 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newOutputStream",
- args = {java.nio.channels.WritableByteChannel.class}
- )
- public void testNewOutputStreamWritableByteChannel_InputNull()
- throws Exception {
- byte[] writebuf = new byte[this.testNum];
- OutputStream testouts = Channels.newOutputStream(null);
- assertNotNull(testouts);
- try {
- testouts.write(writebuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- testouts.flush();
- try {
- testouts.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- WritableByteChannel writebc = Channels.newChannel((OutputStream) null);
- assertTrue(writebc.isOpen());
- OutputStream testoutputS = Channels.newOutputStream(writebc);
- try {
- testoutputS.write(writebuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newOutputStream",
- args = {java.nio.channels.WritableByteChannel.class}
- )
- public void testNewOutputStreamWritableByteChannel() throws Exception {
- byte[] writebuf = new byte[this.testNum];
- ByteBuffer writebcbuf = ByteBuffer.allocateDirect(this.testNum);
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel writebc = this.fouts.getChannel();
-
- assertTrue(writebc.isOpen());
- OutputStream testouts = Channels.newOutputStream(writebc);
-
- // read in testins and fins use the same pointer
- testouts.write(writebuf);
- this.assertFileSizeSame(tmpFile, this.testNum);
- writebc.write(writebcbuf);
- this.assertFileSizeSame(tmpFile, this.testNum * 2);
- testouts.write(writebuf);
- this.assertFileSizeSame(tmpFile, this.testNum * 3);
- // readbc.close() affect testins
- writebc.close();
- assertFalse(writebc.isOpen());
- try {
- testouts.write(writebuf);
- fail();
- } catch (ClosedChannelException e) {
- // correct
- }
-
- // Write methods throw IllegalBlockingModeException if underlying
- // channel is in non-blocking mode.
- SocketChannel chan = SocketChannel.open();
- chan.configureBlocking(false);
- testouts = Channels.newOutputStream(chan);
- try {
- testouts.write(10);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- testouts.write(new byte[1]);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- testouts.write(new byte[1], 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedCharsetException.",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.nio.charset.CharsetDecoder.class, int.class}
- )
- public void testnewReaderCharsetError() throws Exception {
- this.fins = new FileInputStream(tmpFile);
-
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- try {
- Channels.newReader(rbChannel, Charset.forName(BAD_CODE_SET)
- .newDecoder(),
- -1);
- fail();
- } catch (UnsupportedCharsetException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedCharsetException.",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.lang.String.class}
- )
- public void testnewReaderCharsetError2() throws Exception {
- this.fins = new FileInputStream(tmpFile);
-
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- try {
- Channels.newReader(rbChannel, BAD_CODE_SET);
- fail();
- } catch (UnsupportedCharsetException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedCharsetException.",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.nio.charset.CharsetEncoder.class, int.class}
- )
- public void testnewWriterCharsetError() throws Exception {
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- try {
- Channels.newWriter(wbChannel, Charset.forName(BAD_CODE_SET)
- .newEncoder(), -1);
- fail();
- } catch (UnsupportedCharsetException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedCharsetException.",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.lang.String.class}
- )
- public void testnewWriterCharsetError2() throws Exception {
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- try {
- Channels.newWriter(wbChannel, BAD_CODE_SET);
- fail();
- } catch (UnsupportedCharsetException e) {
- // correct
- }
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newReader(ReadableByteChannel, String)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.nio.charset.CharsetDecoder.class, int.class}
- )
- public void testNewReaderReadableByteChannelCharsetDecoderI_InputNull()
- throws IOException {
- int bufSize = this.testNum;
- int readres = 0;
- CharBuffer charBuf = CharBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- // channel null
- Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
- .newDecoder(), -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read((CharBuffer) null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- // channel with null inputs
- testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
- .newDecoder(),
- -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newReader(ReadableByteChannel, String)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.lang.String.class}
- )
- public void testNewReaderReadableByteChannelString_InputNull()
- throws IOException {
- int bufSize = this.testNum;
- int readres = 0;
- CharBuffer charBuf = CharBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- // channel null
- Reader testReader = Channels.newReader(null, CODE_SET);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read((CharBuffer) null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- // channel with null inputs
- testReader = Channels.newReader(rbChannel, CODE_SET);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newReader(ReadableByteChannel, String)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.nio.charset.CharsetDecoder.class, int.class}
- )
- public void testNewReaderReadableByteChannelCharsetDecoderI_internalBufferZero()
- throws IOException {
- int bufSize = this.testNum;
- int readres = 0;
- CharBuffer charBuf = CharBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- // channel null
- Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
- .newDecoder(),
- 0);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read((CharBuffer) null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- // channel with null inputs
- testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
- .newDecoder(),
- -1);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newReader(ReadableByteChannel, String)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.lang.String.class}
- )
- public void testNewReaderReadableByteChannelString_internalBufferZero()
- throws IOException {
- int bufSize = this.testNum;
- int readres = 0;
- CharBuffer charBuf = CharBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- // channel null
- Reader testReader = Channels.newReader(null, CODE_SET);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read((CharBuffer) null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, readres);
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- this.fins = null;
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- // channel with null inputs
- testReader = Channels.newReader(rbChannel, CODE_SET);
- assertNotNull(testReader);
- assertFalse(testReader.ready());
- try {
- readres = testReader.read(charBuf);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newReader(ReadableByteChannel, String)'
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newReader",
- args = {java.nio.channels.ReadableByteChannel.class, java.nio.charset.CharsetDecoder.class, int.class}
- )
- })
- public void testNewReaderReadableByteChannel() throws IOException {
- int bufSize = this.testNum;
- int readres = 0;
- CharBuffer charBuf = CharBuffer.allocate(bufSize);
- this.fins = new FileInputStream(tmpFile);
- ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
- Reader testReader = Channels.newReader(rbChannel, Charset.forName(
- CODE_SET).newDecoder(),
- -1);
- Reader testReader_s = Channels.newReader(rbChannel, CODE_SET);
-
- assertEquals(this.fileSize, this.fins.available());
- // not ready...
- assertFalse(testReader.ready());
- assertFalse(testReader_s.ready());
- // still reads
- readres = testReader.read(charBuf);
- assertEquals(bufSize, readres);
- assertEquals(0, this.fins.available());
-
- try {
- readres = testReader.read((CharBuffer) null);
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- readres = testReader_s.read(charBuf);
- assertEquals(0, readres);
- assertTrue(testReader.ready());
- assertFalse(testReader_s.ready());
- }
-
- /*
- * Zero-Buffer
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.nio.charset.CharsetEncoder.class, int.class}
- )
- public void testNewWriterWritableByteChannelCharsetEncoderI_internalBufZero()
- throws IOException {
-
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- // null channel
- Writer testWriter = Channels.newWriter(null, Charset.forName(CODE_SET)
- .newEncoder(),
- -1);
- // can write to buffer
- testWriter.write(writebuf);
- try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- // channel with null input
- this.fouts = null;
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- testWriter = Channels.newWriter(wbChannel, Charset.forName(CODE_SET)
- .newEncoder(),
- -1);
- // can write to buffer
- testWriter.write(writebuf);
- try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Zero-Buffer
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.lang.String.class}
- )
- public void testNewWriterWritableByteChannelString_internalBufZero()
- throws IOException {
-
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- // null channel
- Writer testWriter = Channels.newWriter(null, CODE_SET);
- // can write to buffer
- testWriter.write(writebuf);
- try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
-
- // channel with null input
- this.fouts = null;
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- testWriter = Channels.newWriter(wbChannel, CODE_SET);
- // can write to buffer
- testWriter.write(writebuf);
- try {
- testWriter.flush();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- try {
- testWriter.close();
- fail();
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * this test cannot be passed when buffer set to 0!
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.nio.charset.CharsetEncoder.class, int.class}
- )
- public void testNewWriterWritableByteChannelCharsetEncoderI_InputNull()
- throws IOException {
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- Writer testWriter = Channels.newWriter(wbChannel, Charset.forName(
- CODE_SET).newEncoder(),
- 1);
-
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- // can write to buffer
- testWriter.write(writebuf);
- testWriter.flush();
- testWriter.close();
-
- }
-
- /*
- * this test cannot be passed when buffer set to 0!
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.lang.String.class}
- )
- public void testNewWriterWritableByteChannelString_InputNull()
- throws IOException {
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- Writer testWriter = Channels.newWriter(wbChannel, CODE_SET);
-
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- // can write to buffer
- testWriter.write(writebuf);
- testWriter.flush();
- testWriter.close();
-
- }
-
- /*
- * Test method for
- * 'java.nio.channels.Channels.newWriter(WritableByteChannel, String)'
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.nio.charset.CharsetEncoder.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "newWriter",
- args = {java.nio.channels.WritableByteChannel.class, java.lang.String.class}
- )
- })
- public void testNewWriterWritableByteChannelString() throws IOException {
- this.fouts = new FileOutputStream(tmpFile);
- WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
- Writer testWriter = Channels.newWriter(wbChannel, CODE_SET);
- Writer testWriter_s = Channels.newWriter(wbChannel, Charset.forName(
- CODE_SET).newEncoder(),
- -1);
-
- String writebuf = "";
- for (int val = 0; val < this.writebufSize / 2; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- byte[] bit = new byte[1];
- bit[0] = 80;
- this.fouts.write(bit);
- this.assertFileSizeSame(tmpFile, 1);
-
- // writer continues to write after '1',what the fouts write
- testWriter.write(writebuf);
- testWriter.flush();
- this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
- // testwriter_s does not know if testwrite writes
- testWriter_s.write(writebuf);
- testWriter.flush();
- this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
- // testwriter_s even does not know if himself writes?
- testWriter_s.write(writebuf);
- testWriter.flush();
- this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
-
- // close the fouts, no longer writable for testWriter
- for (int val = 0; val < this.writebufSize; val++) {
- writebuf = writebuf + ((char) (val + 64));
- }
- this.fouts.close();
- testWriter_s.write(writebuf);
- testWriter.flush();
- this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
-
- SocketChannel chan = SocketChannel.open();
- chan.configureBlocking(false);
- Writer writer = Channels.newWriter(chan, CODE_SET);
- try {
- writer.write(10);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write(new char[10]);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write("test");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write(new char[10], 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write("test", 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
-
- writer = Channels.newWriter(chan, Charset.forName(
- CODE_SET).newEncoder(),
- -1);
- try {
- writer.write(10);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write(new char[10]);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write("test");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write(new char[10], 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- writer.write("test", 0, 1);
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Channels#newReader(ReadableByteChannel channel,
- * String charsetName)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalBlockingModeException.",
- method = "newInputStream",
- args = {java.nio.channels.ReadableByteChannel.class}
- )
- public void test_newInputStream_LReadableByteChannel()
- throws IOException {
- InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
- Support_PortManager.getNextPort());
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ssc.socket().bind(localAddr);
-
- SocketChannel sc = SocketChannel.open();
- sc.connect(localAddr);
- sc.configureBlocking(false);
- assertFalse(sc.isBlocking());
-
- ssc.accept().close();
- ssc.close();
- assertFalse(sc.isBlocking());
-
- Reader reader = Channels.newReader(sc, "UTF16");
- int i = reader.read();
- assertEquals(-1, i);
-
- try {
- Channels.newInputStream(sc).read();
- fail("should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
-
- sc.close();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedByInterruptExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedByInterruptExceptionTest.java
deleted file mode 100644
index 85b9649..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedByInterruptExceptionTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.ClosedByInterruptException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for ClosedByInterruptException
- */
-@TestTargetClass(ClosedByInterruptException.class)
-public class ClosedByInterruptExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.ClosedByInterruptException#ClosedByInterruptException()}
- */
- public void test_Constructor() {
- ClosedByInterruptException e = new ClosedByInterruptException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedByInterruptException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new ClosedByInterruptException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedByInterruptException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new ClosedByInterruptException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedChannelExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedChannelExceptionTest.java
deleted file mode 100644
index de58615..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedChannelExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.ClosedChannelException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for ClosedChannelException
- */
-@TestTargetClass(ClosedChannelException.class)
-public class ClosedChannelExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.ClosedChannelException#ClosedChannelException()}
- */
- public void test_Constructor() {
- ClosedChannelException e = new ClosedChannelException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedChannelException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new ClosedChannelException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedChannelException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new ClosedChannelException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedSelectorExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedSelectorExceptionTest.java
deleted file mode 100644
index c1a9ecd..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ClosedSelectorExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.ClosedSelectorException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for ClosedSelectorException
- */
-@TestTargetClass(ClosedSelectorException.class)
-public class ClosedSelectorExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.ClosedSelectorException#ClosedSelectorException()}
- */
- public void test_Constructor() {
- ClosedSelectorException e = new ClosedSelectorException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedSelectorException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new ClosedSelectorException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ClosedSelectorException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new ClosedSelectorException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ConnectionPendingExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ConnectionPendingExceptionTest.java
deleted file mode 100644
index 30749fe..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/ConnectionPendingExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-
-import java.nio.channels.ConnectionPendingException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for ConnectionPendingException
- */
-@TestTargetClass(ConnectionPendingException.class)
-public class ConnectionPendingExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.ConnectionPendingException#ConnectionPendingException()}
- */
- public void test_Constructor() {
- ConnectionPendingException e = new ConnectionPendingException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ConnectionPendingException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new ConnectionPendingException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "ConnectionPendingException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new ConnectionPendingException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
deleted file mode 100644
index b304d45..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/DatagramChannelTest.java
+++ /dev/null
@@ -1,4703 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.net.SocketException;
-import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousCloseException;
-import java.nio.channels.ClosedByInterruptException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.NotYetConnectedException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.UnresolvedAddressException;
-import java.nio.channels.UnsupportedAddressTypeException;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-import tests.support.Support_PortManager;
-
-/**
- * Test for DatagramChannel
- *
- */
-@TestTargetClass(
- value = DatagramChannel.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "connect",
- args = {java.net.SocketAddress.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "connect",
- args = {java.net.SocketAddress.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- }
-)
-public class DatagramChannelTest extends TestCase {
-
- private static final int CAPACITY_NORMAL = 200;
-
- private static final int CAPACITY_1KB = 1024;
-
- private static final int CAPACITY_64KB = 65536;
-
- private static final int CAPACITY_ZERO = 0;
-
- private static final int CAPACITY_ONE = 1;
-
- private static final int TIME_UNIT = 500;
-
- private InetSocketAddress localAddr1;
-
- private InetSocketAddress localAddr2;
-
- private DatagramChannel channel1;
-
- private DatagramChannel channel2;
-
- private DatagramSocket datagramSocket1;
-
- private DatagramSocket datagramSocket2;
-
- // The port to be used in test cases.
- private int testPort;
-
- protected void setUp() throws Exception {
- super.setUp();
- this.channel1 = DatagramChannel.open();
- this.channel2 = DatagramChannel.open();
- int[] ports = Support_PortManager.getNextPortsForUDP(5);
- this.localAddr1 = new InetSocketAddress("127.0.0.1", ports[0]);
- this.localAddr2 = new InetSocketAddress("127.0.0.1", ports[1]);
- this.datagramSocket1 = new DatagramSocket(ports[2]);
- this.datagramSocket2 = new DatagramSocket(ports[3]);
- testPort = ports[4];
- }
-
- protected void tearDown() throws Exception {
- if (null != this.channel1) {
- try {
- this.channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- if (null != this.channel2) {
- try {
- this.channel2.close();
- } catch (Exception e) {
- //ignore
- }
- }
- if (null != this.datagramSocket1) {
- try {
- this.datagramSocket1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- if (null != this.datagramSocket2) {
- try {
- this.datagramSocket2.close();
- } catch (Exception e) {
- //ignore
- }
- }
- localAddr1 = null;
- localAddr2 = null;
- super.tearDown();
- }
-
- // -------------------------------------------------------------------
- // Test for methods in abstract class.
- // -------------------------------------------------------------------
- /*
- * Test method for 'java.nio.channels.DatagramChannel()'
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "DatagramChannel",
- args = {java.nio.channels.spi.SelectorProvider.class}
- )
- public void testConstructor() throws IOException {
- DatagramChannel channel =
- SelectorProvider.provider().openDatagramChannel();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(),channel.provider());
- channel = DatagramChannel.open();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(), channel.provider());
- }
-
- /*
- * Test method for 'java.nio.channels.DatagramChannel.validOps()'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "validOps",
- args = {}
- )
- public void testValidOps() {
- MockDatagramChannel testMock = new MockDatagramChannel(SelectorProvider
- .provider());
- MockDatagramChannel testMocknull = new MockDatagramChannel(null);
- int val = this.channel1.validOps();
- assertEquals(5, val);
- assertEquals(val, testMock.validOps());
- assertEquals(val, testMocknull.validOps());
- }
-
- /*
- * Test method for 'java.nio.channels.DatagramChannel.open()'
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the result of the setUp method.",
- method = "open",
- args = {}
- )
- public void testOpen() {
- MockDatagramChannel testMock = new MockDatagramChannel(SelectorProvider
- .provider());
- MockDatagramChannel testMocknull = new MockDatagramChannel(null);
- assertNull(testMocknull.provider());
- assertNotNull(testMock.provider());
- assertEquals(this.channel1.provider(), testMock.provider());
- assertEquals(5, testMock.validOps());
- }
-
- /*
- * Test method for 'java.nio.channels.DatagramChannel.open()'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- public void testIsOpen() throws Exception {
- assertTrue(this.channel1.isOpen());
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies default status of DatagramChannel.",
- method = "validOps",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies default status of DatagramChannel.",
- method = "provider",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies default status of DatagramChannel.",
- method = "isRegistered",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies default status of DatagramChannel.",
- method = "isBlocking",
- args = {}
- )
- })
- public void testChannelBasicStatus() {
- DatagramSocket gotSocket = this.channel1.socket();
- assertFalse(gotSocket.isClosed());
- assertTrue(this.channel1.isBlocking());
- assertFalse(this.channel1.isRegistered());
- assertEquals((SelectionKey.OP_READ | SelectionKey.OP_WRITE),
- this.channel1.validOps());
- assertEquals(SelectorProvider.provider(), this.channel1.provider());
- }
-
- /*
- * Test method for 'java.nio.channels.DatagramChannel.read(ByteBuffer)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testReadByteBufferArray() throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.read(readBuf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- assertEquals(0, this.channel1.read(readBuf));
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- assertEquals(0, this.channel1.read(readBuf));
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testReadByteBufferArray_ConnectedBufNull()
- throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- try {
- this.channel1.read((ByteBuffer[])null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- datagramSocket1.close();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testReadByteBufferArray_NotConnectedBufNull()
- throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.read((ByteBuffer[])null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer[])'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify all exceptions according to specification.",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_Block() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.write(writeBuf);
- fail("Should throw NotYetConnectedException.");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf));
- // cannot be buffered again!
- assertEquals(0, this.channel1.write(writeBuf));
- }
-
- public void disabled_testWriteByteBufferArray_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.write(targetBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testWriteByteBufferArray_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
- channel1.write(targetBuf);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer[])'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_NonBlock() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- // non-block mode
- this.channel1.configureBlocking(false);
- try {
- this.channel1.write(writeBuf);
- fail("Should throw NotYetConnectedException.");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf));
- // cannot be buffered again!
- assertEquals(0, this.channel1.write(writeBuf));
- this.channel1.close();
- try {
- this.channel1.write(writeBuf, 0, 1);
- fail("Should throw ClosedChannelEception.");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_BlockClosed() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- // non-block mode
- this.channel1.configureBlocking(false);
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_NonBlockClosed() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer[])'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_NotConnectedBufNull()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- this.channel1.write((ByteBuffer[])null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer[])'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testWriteByteBufferArray_ConnectedBufNull()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- this.channel1.write((ByteBuffer[])null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // correct
- }
- datagramSocket1.close();
- try {
- this.channel1.write((ByteBuffer[])null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- // -------------------------------------------------------------------
- // Test for socket()
- // -------------------------------------------------------------------
-
- /**
- * Test method for 'DatagramChannelImpl.socket()'
- *
- * @throws SocketException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_BasicStatusBeforeConnect() throws SocketException {
- assertFalse(this.channel1.isConnected());// not connected
- DatagramSocket s1 = this.channel1.socket();
- assertSocketBeforeConnect(s1);
- DatagramSocket s2 = this.channel1.socket();
- // same
- assertSame(s1, s2);
- }
-
- /**
- * Test method for 'DatagramChannelImpl.socket()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_Block_BasicStatusAfterConnect() throws IOException {
- this.channel1.connect(localAddr1);
- DatagramSocket s1 = this.channel1.socket();
- assertSocketAfterConnect(s1);
- DatagramSocket s2 = this.channel1.socket();
- // same
- assertSame(s1, s2);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_NonBlock_BasicStatusAfterConnect()
- throws IOException {
- this.channel1.connect(localAddr1);
- this.channel1.configureBlocking(false);
- DatagramSocket s1 = this.channel1.socket();
- assertSocketAfterConnect(s1);
- DatagramSocket s2 = this.channel1.socket();
- // same
- assertSame(s1, s2);
- }
-
- /**
- * Test method for 'DatagramChannelImpl.socket()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_ActionsBeforeConnect() throws IOException {
- assertFalse(this.channel1.isConnected());// not connected
- DatagramSocket s = this.channel1.socket();
- assertSocketActionBeforeConnect(s);
- }
-
- /**
- * Test method for 'DatagramChannelImpl.socket()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_Block_ActionsAfterConnect() throws IOException {
- assertFalse(this.channel1.isConnected());// not connected
- this.channel1.connect(localAddr1);
- DatagramSocket s = this.channel1.socket();
- assertSocketActionAfterConnect(s);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_NonBlock_ActionsAfterConnect() throws IOException {
- this.channel1.connect(localAddr1);
- this.channel1.configureBlocking(false);
- DatagramSocket s = this.channel1.socket();
- assertSocketActionAfterConnect(s);
- }
-
- private void assertSocketBeforeConnect(DatagramSocket s)
- throws SocketException {
- assertFalse(s.isBound());
- assertFalse(s.isClosed());
- assertFalse(s.isConnected());
- assertFalse(s.getBroadcast());
- assertFalse(s.getReuseAddress());
- assertNull(s.getInetAddress());
- assertTrue(s.getLocalAddress().isAnyLocalAddress());
- assertEquals(s.getLocalPort(), 0);
- assertNull(s.getLocalSocketAddress());
- assertEquals(s.getPort(), -1);
- assertTrue(s.getReceiveBufferSize() >= 8192);
- assertNull(s.getRemoteSocketAddress());
- assertFalse(s.getReuseAddress());
- assertTrue(s.getSendBufferSize() >= 8192);
- assertEquals(s.getSoTimeout(), 0);
- assertEquals(s.getTrafficClass(), 0);
- }
-
- private void assertSocketAfterConnect(DatagramSocket s)
- throws SocketException {
- assertTrue(s.isBound());
- assertFalse(s.isClosed());
- assertTrue(s.isConnected());
- assertFalse(s.getBroadcast());
- assertFalse(s.getReuseAddress());
- assertSame(s.getInetAddress(), localAddr1.getAddress());
- assertEquals(s.getLocalAddress(), localAddr1.getAddress());
- assertNotNull(s.getLocalSocketAddress());
- assertEquals(s.getPort(), localAddr1.getPort());
- assertTrue(s.getReceiveBufferSize() >= 8192);
- // not same , but equals
- assertNotSame(s.getRemoteSocketAddress(), localAddr1);
- assertEquals(s.getRemoteSocketAddress(), localAddr1);
- assertFalse(s.getReuseAddress());
- assertTrue(s.getSendBufferSize() >= 8192);
- assertEquals(s.getSoTimeout(), 0);
- assertEquals(s.getTrafficClass(), 0);
- }
-
- private void assertSocketActionBeforeConnect(DatagramSocket s)
- throws IOException {
- s.connect(localAddr2);
- assertFalse(this.channel1.isConnected());
- assertFalse(s.isConnected());
-
- s.disconnect();
- assertFalse(this.channel1.isConnected());
- assertFalse(s.isConnected());
-
- s.close();
- assertTrue(s.isClosed());
- assertFalse(this.channel1.isOpen());
- }
-
- private void assertSocketActionAfterConnect(DatagramSocket s)
- throws IOException {
- assertEquals(s.getPort(), localAddr1.getPort());
- s.connect(localAddr2);
- assertTrue(this.channel1.isConnected());
- assertTrue(s.isConnected());
- // not changed
- assertEquals(s.getPort(), localAddr1.getPort());
-
- s.disconnect();
- assertFalse(this.channel1.isConnected());
- assertFalse(s.isConnected());
-
- s.close();
- assertTrue(s.isClosed());
- assertFalse(this.channel1.isOpen());
- }
-
- // -------------------------------------------------------------------
- // Test for configureBlocking()
- // -------------------------------------------------------------------
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {ByteBuffer.class}
- )
- public void testConfigureBlocking_Read() throws Exception {
- assertTrue(this.channel1.isBlocking());
- ByteBuffer buf = ByteBuffer.allocate(CAPACITY_1KB);
- new Thread() {
- public void run() {
- try {
- sleep(TIME_UNIT * 5);
- channel1.configureBlocking(false);
- assertFalse(channel1.isBlocking());
- datagramSocket1.close();
- } catch (Exception e) {
- // do nothing
- }
- }
- }.start();
- SocketAddress addr = channel1.receive(buf);
- assertNull(addr);
- }
-
- // -------------------------------------------------------------------
- // Test for isConnected()
- // -------------------------------------------------------------------
-
- /**
- * Test method for 'DatagramChannelImpl.isConnected()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isConnected",
- args = {}
- )
- public void testIsConnected_WithServer() throws IOException {
- connectLocalServer();
- assertTrue(this.channel1.isConnected());
- disconnectAfterConnected();
- this.datagramSocket1.close();
- this.channel1.close();
- assertFalse(this.channel1.isConnected());
- }
-
- // -------------------------------------------------------------------
- // Test for connect()
- // -------------------------------------------------------------------
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_BlockWithServer() throws IOException {
- // blocking mode
- assertTrue(this.channel1.isBlocking());
- connectLocalServer();
- datagramSocket1.close();
- disconnectAfterConnected();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_BlockNoServer() throws IOException {
- connectWithoutServer();
- disconnectAfterConnected();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_NonBlockWithServer() throws IOException {
- // Non blocking mode
- this.channel1.configureBlocking(false);
- connectLocalServer();
- datagramSocket1.close();
- disconnectAfterConnected();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_Null() throws IOException {
- assertFalse(this.channel1.isConnected());
- try {
- this.channel1.connect(null);
- fail("Should throw an IllegalArgumentException here.");
- } catch (IllegalArgumentException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnsupportedAddressTypeException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_UnsupportedType() throws IOException {
- assertFalse(this.channel1.isConnected());
- class SubSocketAddress extends SocketAddress {
- private static final long serialVersionUID = 1L;
-
- public SubSocketAddress() {
- super();
- }
- }
- SocketAddress newTypeAddress = new SubSocketAddress();
- try {
- this.channel1.connect(newTypeAddress);
- fail("Should throw an UnsupportedAddressTypeException here.");
- } catch (UnsupportedAddressTypeException e) {
- // OK.
- }
- }
-
- public void disabled_testConnect_Block_close() throws Exception {
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.connect(localAddr1);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testConnect_Block_interrupt() throws Exception {
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- channel1.connect(localAddr1);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies UnresolvedAddressException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_Unresolved() throws IOException {
- assertFalse(this.channel1.isConnected());
- InetSocketAddress unresolved = new InetSocketAddress(
- "unresolved address", 1080);
- try {
- this.channel1.connect(unresolved);
- fail("Should throw an UnresolvedAddressException here.");
- } catch (UnresolvedAddressException e) {
- // OK.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_EmptyHost() throws Exception {
- assertFalse(this.channel1.isConnected());
-
- assertEquals(this.channel1, this.channel1
- .connect(new InetSocketAddress("", 1081)));
-
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_ClosedChannelException() throws IOException {
- assertFalse(this.channel1.isConnected());
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- this.channel1.connect(localAddr1);
- fail("Should throw ClosedChannelException.");
- } catch (ClosedChannelException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalStateException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_IllegalStateException() throws IOException {
- assertFalse(this.channel1.isConnected());
- this.channel1.connect(localAddr1);
- assertTrue(this.channel1.isConnected());
- // connect after connected.
- try {
- this.channel1.connect(localAddr1);
- fail("Should throw IllegalStateException.");
- } catch (IllegalStateException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
- *
- * @throws IOException
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException.",
- method = "connect",
- args = {java.net.SocketAddress.class}
- )
- public void testConnect_CheckOpenBeforeStatus() throws IOException {
- assertFalse(this.channel1.isConnected());
- this.channel1.connect(localAddr1);
- assertTrue(this.channel1.isConnected());
- // connect after connected.
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- // checking open is before checking status.
- try {
- this.channel1.connect(localAddr1);
- fail("Should throw ClosedChannelException.");
- } catch (ClosedChannelException e) {
- // OK.
- }
- }
-
- private void disconnectAfterConnected() throws IOException {
- assertTrue(this.channel1.isConnected());
- this.channel1.disconnect();
- assertFalse(this.channel1.isConnected());
- }
-
- private void disconnectAfterClosed() throws IOException {
- assertFalse(this.channel1.isOpen());
- assertFalse(this.channel1.isConnected());
- this.channel1.disconnect();
- assertFalse(this.channel1.isConnected());
- }
-
- private void connectLocalServer() throws IOException {
- assertFalse(this.channel1.isConnected());
- assertTrue(this.datagramSocket1.isBound());
- assertSame(this.channel1, this.channel1.connect(localAddr1));
- assertTrue(this.channel1.isConnected());
- }
-
- private void connectWithoutServer() throws IOException {
- assertFalse(this.channel1.isConnected());
- this.datagramSocket1.close();
- assertTrue(this.datagramSocket1.isClosed());
- assertSame(this.channel1, this.channel1.connect(localAddr1));
- assertTrue(this.channel1.isConnected());
- }
-
- // -------------------------------------------------------------------
- // Test for disconnect()
- // -------------------------------------------------------------------
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify IOException.",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_BeforeConnect() throws IOException {
- assertFalse(this.channel1.isConnected());
- assertEquals(this.channel1, this.channel1.disconnect());
- assertFalse(this.channel1.isConnected());
- }
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_UnconnectedClosed() throws IOException {
- assertFalse(this.channel1.isConnected());
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- assertEquals(this.channel1, this.channel1.disconnect());
- assertFalse(this.channel1.isConnected());
- }
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_BlockWithServerChannelClosed()
- throws IOException {
- assertTrue(this.channel1.isBlocking());
- connectLocalServer();
- // disconnect after channel close
- this.channel1.close();
- disconnectAfterClosed();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_NonBlockWithServerChannelClosed()
- throws IOException {
- this.channel1.configureBlocking(false);
- connectLocalServer();
- // disconnect after channel close
- this.channel1.close();
- disconnectAfterClosed();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_BlockWithServerServerClosed()
- throws IOException {
- assertTrue(this.channel1.isBlocking());
- connectLocalServer();
- // disconnect after server close
- this.datagramSocket1.close();
- assertTrue(this.channel1.isOpen());
- assertTrue(this.channel1.isConnected());
- disconnectAfterConnected();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.disconnect()'
- *
- * @throws IOException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "disconnect",
- args = {}
- )
- public void testDisconnect_NonBlockWithServerServerClosed()
- throws IOException {
- this.channel1.configureBlocking(false);
- assertFalse(this.channel1.isBlocking());
- connectLocalServer();
- // disconnect after server close
- this.datagramSocket1.close();
- assertTrue(this.channel1.isOpen());
- assertTrue(this.channel1.isConnected());
- disconnectAfterConnected();
- }
-
- // -------------------------------------------------------------------
- // Test for receive(): Behavior Without Server.
- // -------------------------------------------------------------------
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedNull() throws Exception {
- assertFalse(this.channel1.isConnected());
- try {
- this.channel1.receive(null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedReadonly() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL)
- .asReadOnlyBuffer();
- assertTrue(dst.isReadOnly());
- try {
- this.channel1.receive(dst);
- fail("Should throw an IllegalArgumentException here.");
- } catch (IllegalArgumentException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedBufEmpty() throws Exception {
- this.channel1.configureBlocking(false);
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- assertNull(this.channel1.receive(dst));
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedBufZero() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_ZERO);
- assertNull(this.channel1.receive(dst));
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedBufNotEmpty() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- // buf is not empty
- dst.put((byte) 88);
- assertEquals(dst.position() + CAPACITY_NORMAL - 1, dst.limit());
- assertNull(this.channel1.receive(dst));
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedBufFull() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_ONE);
- // buf is full
- dst.put((byte) 88);
- assertEquals(dst.position(), dst.limit());
- assertNull(this.channel1.receive(dst));
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedClose() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- assertNull(this.channel1.receive(dst));
- fail("Should throw a ClosedChannelException here.");
- } catch (ClosedChannelException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedCloseNull() throws Exception {
- assertFalse(this.channel1.isConnected());
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- // checking buffer before checking open
- try {
- this.channel1.receive(null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_UnconnectedCloseReadonly() throws Exception {
- assertFalse(this.channel1.isConnected());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL)
- .asReadOnlyBuffer();
- assertTrue(dst.isReadOnly());
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- this.channel1.receive(dst);
- fail("Should throw an IllegalArgumentException here.");
- } catch (IllegalArgumentException e) {
- // OK.
- }
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerBufEmpty() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNonBlockNoServer(CAPACITY_NORMAL);
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_BlockNoServerNull() throws Exception {
- assertTrue(this.channel1.isBlocking());
- receiveNoServerNull();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerNull() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNoServerNull();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_BlockNoServerReadonly() throws Exception {
- assertTrue(this.channel1.isBlocking());
- receiveNoServerReadonly();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerReadonly() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNoServerReadonly();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerBufZero() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNonBlockNoServer(CAPACITY_ZERO);
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerBufNotEmpty() throws Exception {
- this.channel1.configureBlocking(false);
- connectWithoutServer();
- ByteBuffer dst = allocateNonEmptyBuf();
- assertNull(this.channel1.receive(dst));
- }
-
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerBufFull() throws Exception {
- this.channel1.configureBlocking(false);
- connectWithoutServer();
- ByteBuffer dst = allocateFullBuf();
- assertNull(this.channel1.receive(dst));
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_BlockNoServerChannelClose() throws Exception {
- assertTrue(this.channel1.isBlocking());
- receiveNoServerChannelClose();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerChannelClose() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNoServerChannelClose();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_BlockNoServerCloseNull() throws Exception {
- assertTrue(this.channel1.isBlocking());
- receiveNoServerChannelCloseNull();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerCloseNull() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNoServerChannelCloseNull();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_NonBlockNoServerCloseReadonly() throws Exception {
- this.channel1.configureBlocking(false);
- receiveNoServerChannelCloseReadonly();
- }
-
- /**
- * Test method for 'DatagramChannelImpl.receive(ByteBuffer)'
- *
- * @throws Exception
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_BlockNoServerCloseReadonly() throws Exception {
- assertTrue(this.channel1.isBlocking());
- receiveNoServerChannelCloseReadonly();
- }
-
- private void receiveNoServerNull() throws IOException {
- connectWithoutServer();
- try {
- this.channel1.receive(null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // OK.
- }
- }
-
- private void receiveNoServerReadonly() throws IOException {
- connectWithoutServer();
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL)
- .asReadOnlyBuffer();
- assertTrue(dst.isReadOnly());
- try {
- this.channel1.receive(dst);
- fail("Should throw an IllegalArgumentException here.");
- } catch (IllegalArgumentException e) {
- // OK.
- }
- }
-
- private void receiveNonBlockNoServer(int size) throws IOException {
- connectWithoutServer();
- ByteBuffer dst = ByteBuffer.allocateDirect(size);
- assertNull(this.channel1.receive(dst));
- }
-
- private void receiveNoServerChannelClose() throws IOException {
- connectWithoutServer();
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- assertNull(this.channel1.receive(dst));
- fail("Should throw a ClosedChannelException here.");
- } catch (ClosedChannelException e) {
- // OK.
- }
- }
-
- private void receiveNoServerChannelCloseNull() throws IOException {
- connectWithoutServer();
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- this.channel1.receive(null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // OK.
- }
- }
-
- private void receiveNoServerChannelCloseReadonly() throws IOException {
- connectWithoutServer();
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL)
- .asReadOnlyBuffer();
- assertTrue(dst.isReadOnly());
- try {
- this.channel1.receive(dst);
- fail("Should throw an IllegalArgumentException here.");
- } catch (IllegalArgumentException e) {
- // OK.
- }
- }
-
- private ByteBuffer allocateFullBuf() {
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_ONE);
- // buf is full
- dst.put((byte) 88);
- assertEquals(dst.position(), dst.limit());
- return dst;
- }
-
- private ByteBuffer allocateNonEmptyBuf() {
- ByteBuffer dst = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- // buf is not empty
- dst.put((byte) 88);
- dst.put((byte) 99);
- assertEquals(dst.position() + CAPACITY_NORMAL - 2, dst.limit());
- return dst;
- }
-
- // -------------------------------------------------------------------
- // Test for send(): Behavior without server.
- // -------------------------------------------------------------------
-
- private void sendDataBlocking(InetSocketAddress addr, ByteBuffer writeBuf)
- throws IOException {
- InetSocketAddress ipAddr = addr;
- assertEquals(CAPACITY_NORMAL, this.channel1.send(writeBuf, ipAddr));
- assertTrue(this.channel1.isOpen());
- assertTrue(this.channel1.isBlocking());
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- }
-
- private void sendDataNonBlocking(InetSocketAddress addr, ByteBuffer writeBuf)
- throws IOException {
- InetSocketAddress ipAddr = addr;
- this.channel1.configureBlocking(false);
- assertEquals(CAPACITY_NORMAL, this.channel1.send(writeBuf, ipAddr));
- assertTrue(this.channel1.isOpen());
- assertFalse(this.channel1.isBlocking());
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- }
-
- /*
- * Test method for 'DatagramChannelImpl.send(ByteBuffer, SocketAddress)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerBlockingCommon() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- sendDataBlocking(localAddr1, writeBuf);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerNonblockingCommon() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- sendDataNonBlocking(localAddr1, writeBuf);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerTwice() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- sendDataBlocking(localAddr1, writeBuf);
- // can not buffer twice!
- assertEquals(0, this.channel1.send(writeBuf, localAddr1));
- try {
- channel1.send(writeBuf, localAddr2);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerNonBlockingTwice() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- sendDataNonBlocking(localAddr1, writeBuf);
- // can not buffer twice!
- assertEquals(0, this.channel1.send(writeBuf, localAddr1));
- try {
- channel1.send(writeBuf, localAddr2);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerBufNull() throws IOException {
- try {
- sendDataBlocking(localAddr1, null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerBufNullTwice() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- sendDataBlocking(localAddr1, null);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // correct
- }
- sendDataBlocking(localAddr1, writeBuf);
- try {
- channel1.send(null, localAddr2);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "DOesn't verify all exceptions according to spec.",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerAddrNull() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- sendDataBlocking(null, writeBuf);
- fail("Should throw a NPE here.");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_NoServerAddrNullTwice() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- sendDataBlocking(null, writeBuf);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- sendDataBlocking(localAddr1, writeBuf);
- try {
- channel1.send(writeBuf, null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- // -------------------------------------------------------------------
- // Test for receive()and send(): Send and Receive with Real Data
- // -------------------------------------------------------------------
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Normal() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByChannel("some normal string in testReceiveSend_Normal",
- localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2,
- "some normal string in testReceiveSend_Normal");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_NotBound() throws Exception {
- // not bound
- sendByChannel("some normal string in testReceiveSend_Normal",
- localAddr2);
- ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
- assertNull(channel1.receive(buf));
- assertFalse(channel1.socket().isBound());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_NotBound() throws Exception {
- // not bound
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- sendByChannel("some normal string in testReceiveSend_Normal",
- localAddr2);
- ByteBuffer buf = ByteBuffer.wrap(new byte[CAPACITY_NORMAL]);
- assertNull(this.channel1.receive(buf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Normal_S2C() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByDatagramSocket(
- "some normal string in testReceiveSend_Normal_S2C", localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2,
- "some normal string in testReceiveSend_Normal_S2C");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Normal_C2S() throws Exception {
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- String str1 = "some normal string in testReceiveSend_Normal_C2S";
- sendByChannel(str1, localAddr2);
- receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, str1);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_Normal_C2S() throws Exception {
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- String str1 = "some normal string in testReceiveSend_Normal_C2S";
- sendByChannel(str1, localAddr2);
- receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, str1);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Normal_S2S() throws Exception {
- String msg = "normal string in testReceiveSend_Normal_S2S";
- this.datagramSocket1 = new DatagramSocket(testPort);
- DatagramPacket rdp = new DatagramPacket(msg.getBytes(), msg.length(),
- localAddr2);
- datagramSocket2 = new DatagramSocket(localAddr2.getPort());
- this.datagramSocket1.send(rdp);
- byte[] buf = new byte[CAPACITY_NORMAL];
- this.datagramSocket2.setSoTimeout(TIME_UNIT);
- rdp = new DatagramPacket(buf, buf.length);
- this.datagramSocket2.receive(rdp);
- assertEquals(new String(buf, 0, CAPACITY_NORMAL).trim(), msg);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Empty() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByChannel("", localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_Empty() throws Exception {
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- this.channel1.socket().bind(localAddr2);
- sendByChannel("", localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Empty_S2C() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByDatagramSocket("", localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_Empty_S2C() throws Exception {
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- this.channel1.socket().bind(localAddr2);
- sendByDatagramSocket("", localAddr2);
- receiveByChannel(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Empty_C2S() throws Exception {
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- sendByChannel("", localAddr2);
- receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_Empty_C2S() throws Exception {
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- sendByChannel("", localAddr2);
- receiveByDatagramSocket(CAPACITY_NORMAL, localAddr2, "");
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceiveSend_Empty_S2S() throws Exception {
- String msg = "";
- this.datagramSocket1 = new DatagramSocket(testPort);
- DatagramPacket rdp = new DatagramPacket(msg.getBytes(), msg.length(),
- localAddr2);
- datagramSocket2 = new DatagramSocket(localAddr2.getPort());
- this.datagramSocket1.send(rdp);
- byte[] buf = new byte[CAPACITY_NORMAL];
- this.datagramSocket2.setSoTimeout(TIME_UNIT);
- rdp = new DatagramPacket(buf, buf.length);
- this.datagramSocket2.receive(rdp);
- assertEquals(new String(buf, 0, CAPACITY_NORMAL).trim(), msg);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Oversize() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByChannel("0123456789", localAddr2);
- receiveByChannel(5, localAddr2, "01234");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Oversize_C2S() throws Exception {
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- sendByChannel("0123456789", localAddr2);
- receiveByDatagramSocket(5, localAddr2, "01234");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_NonBlock_Oversize_C2S() throws Exception {
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
- this.datagramSocket1 = new DatagramSocket(localAddr2.getPort());
- sendByChannel("0123456789", localAddr2);
- receiveByDatagramSocket(5, localAddr2, "01234");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_Block_Oversize_S2C() throws Exception {
- this.channel1.socket().bind(localAddr2);
- sendByDatagramSocket("0123456789", localAddr2);
- receiveByChannel(5, localAddr2, "01234");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- })
- public void testReceiveSend_8K() throws Exception {
- StringBuffer str8k = new StringBuffer();
- for (int i = 0; i < 8 * CAPACITY_1KB; i++) {
- str8k.append("a");
- }
- String str = str8k.toString();
- this.channel1.socket().bind(localAddr2);
- sendByChannel(str, localAddr2);
- receiveByChannel(8 * CAPACITY_1KB, localAddr2, str);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testReceiveSend_64K() throws Exception {
- StringBuffer str64k = new StringBuffer();
- for (int i = 0; i < CAPACITY_64KB; i++) {
- str64k.append("a");
- }
- String str = str64k.toString();
- try {
- Thread.sleep(TIME_UNIT);
- channel2.send(ByteBuffer.wrap(str.getBytes()), localAddr1);
- fail("Should throw SocketException!");
- } catch (SocketException e) {
- //expected
- }
- }
-
- private void sendByChannel(String data, InetSocketAddress address)
- throws Exception {
- try {
- assertEquals(data.length(), this.channel2.send(ByteBuffer.wrap(data
- .getBytes()), address));
- } finally {
- this.channel2.close();
- }
- }
-
- private void sendByDatagramSocket(String data, InetSocketAddress address)
- throws Exception {
- this.datagramSocket1 = new DatagramSocket(testPort);
- DatagramPacket rdp = new DatagramPacket(data.getBytes(), data.length(),
- address);
- this.datagramSocket1.send(rdp);
- }
-
- private void receiveByChannel(int bufSize, InetSocketAddress address,
- String expectedString) throws IOException {
- try {
- ByteBuffer buf = ByteBuffer.wrap(new byte[bufSize]);
- InetSocketAddress returnAddr = null;
- long startTime = System.currentTimeMillis();
- do {
- returnAddr = (InetSocketAddress) this.channel1.receive(buf);
- // continue loop when channel1 is non-blocking and no data was
- // received.
- if (channel1.isBlocking() || null != returnAddr) {
- break;
- }
- // avoid dead loop
- assertTimeout(startTime, 10000);
- } while (true);
- int length = returnAddr.getAddress().getAddress().length;
- for (int i = 0; i < length; i++) {
- assertEquals(returnAddr.getAddress().getAddress()[i],
- InetAddress.getByName("127.0.0.1").getAddress()[i]);
- }
- // port is NOT equal
- assertFalse(returnAddr.getPort() == address.getPort());
- assertEquals(new String(buf.array(), 0, bufSize).trim(),
- expectedString);
- } finally {
- this.channel1.close();
- }
- }
-
- /*
- * Fails if the difference between current time and start time is greater
- * than timeout.
- */
- private void assertTimeout(long startTime, long timeout) {
- long currentTime = System.currentTimeMillis();
- if ((currentTime - startTime) > timeout) {
- fail("Timeout");
- }
- }
-
- private void receiveByDatagramSocket(int bufSize,
- InetSocketAddress address, String expectedString)
- throws IOException {
- byte[] buf = new byte[bufSize];
- this.datagramSocket1.setSoTimeout(6000);
- DatagramPacket rdp = new DatagramPacket(buf, buf.length);
- this.datagramSocket1.receive(rdp);
- assertEquals(new String(buf, 0, bufSize).trim(), expectedString);
- }
-
- // -------------------------------------------------------------------
- // Test for security check of receive and send
- // -------------------------------------------------------------------
-
- private class mockAddress extends SocketAddress {
- private static final long serialVersionUID = 1L;
- }
-
- public void disabled_testSend_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.send(targetBuf, localAddr1);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testSend_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
- channel1.send(targetBuf, localAddr1);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.receive(targetBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "receive",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReceive_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
- channel1.receive(targetBuf);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- // -------------------------------------------------------------------
- // Test for write()
- // -------------------------------------------------------------------
-
- private void connectWriteBuf(InetSocketAddress ipAddr, ByteBuffer buf)
- throws IOException {
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- assertEquals(CAPACITY_NORMAL, this.channel1.write(buf));
- assertEquals(0, this.channel1.write(buf));
- }
-
- private void noconnectWrite(ByteBuffer buf) throws IOException {
- try {
- this.channel1.write(buf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_Block() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- connectWriteBuf(localAddr1, writeBuf);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_NonBlock() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- this.channel1.configureBlocking(false);
- connectWriteBuf(localAddr1, writeBuf);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_BlockClosed() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- noconnectWrite(writeBuf);
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_NonBlockClosed() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- // non block mode
- this.channel1.configureBlocking(false);
- noconnectWrite(writeBuf);
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_BlockBufNull() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(0);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, this.channel1.write(writeBuf));
- datagramSocket1.close();
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_NonBlockBufNull() throws IOException {
- ByteBuffer writeBuf = ByteBuffer.allocateDirect(0);
- InetSocketAddress ipAddr = localAddr1;
-
- // non block mode
- this.channel1.configureBlocking(false);
-
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, this.channel1.write(writeBuf));
- datagramSocket1.close();
- try {
- this.channel1.write((ByteBuffer) null);
- fail("Should throw NPE.");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- /*
- * Test method for 'DatagramChannelImpl.write(ByteBuffer[], int, int)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify all exceptions according to specification.",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_Block() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.write(writeBuf, 0, 2);
- fail("Should throw NotYetConnectedException.");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
- // cannot be buffered again!
- assertEquals(0, this.channel1.write(writeBuf, 0, 1));
- this.channel1.close();
- try {
- this.channel1.write(writeBuf, 0, 1);
- fail("Should throw ClosedChannelEception.");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- public void disabled_testWriteByteBufferArrayII_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.write(targetBuf, 0 ,2);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testWriteByteBufferArrayII_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
- channel1.write(targetBuf, 0, 2);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_NonBlock() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- // non-block mode
- this.channel1.configureBlocking(false);
- try {
- this.channel1.write(writeBuf, 0, 2);
- fail("Should throw NotYetConnectedException.");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- assertEquals(CAPACITY_NORMAL * 2, this.channel1.write(writeBuf, 0, 2));
- // cannot be buffered again!
- assertEquals(0, this.channel1.write(writeBuf, 0, 1));
- this.channel1.close();
- try {
- this.channel1.write(writeBuf, 0, 1);
- fail("Should throw ClosedChannelEception.");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_BlockClosed() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- // non-block mode
- this.channel1.configureBlocking(false);
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf, 0, 2);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_NonBlockClosed() throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.close();
- try {
- channel1.write(writeBuf, 0, 2);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_NotConnectedIndexBad()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.write(writeBuf, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 1, 2);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 2, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 3, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_ConnectedIndexBad()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- writeBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- this.channel1.write(writeBuf, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 1, 2);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 2, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 3, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_NotConnectedBufNull()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- this.channel1.write(null, 0, 20);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, 2);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testWriteByteBufferArrayII_ConnectedBufNull()
- throws IOException {
- ByteBuffer[] writeBuf = new ByteBuffer[2];
- writeBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- this.channel1.write(null, 0, 20);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, 2);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // correct
- }
- datagramSocket1.close();
- try {
- this.channel1.write(null, 0, 20);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.write(writeBuf, 0, 2);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // correct
- }
- }
-
- // -------------------------------------------------------------------
- // Test for read()
- // -------------------------------------------------------------------
-
- /*
- * Test method for 'DatagramChannelImpl.read(ByteBuffer)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- try {
- this.channel1.read(readBuf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(localAddr1);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- assertEquals(0, this.channel1.read(readBuf));
- this.channel1.close();
- try {
- this.channel1.read(readBuf);
- fail("Should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // OK.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer_BufNull() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocateDirect(0);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.read(readBuf);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- try {
- channel1.read((ByteBuffer) null);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- assertEquals(0, this.channel1.read(readBuf));
- datagramSocket1.close();
- }
-
- /*
- * Test method for 'DatagramChannelImpl.read(ByteBuffer[], int, int)'
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify AsynchronousCloseException, ClosedByInterruptException, IOException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII() throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.read(readBuf, 0, 2);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- assertEquals(0, this.channel1.read(readBuf, 0, 1));
- assertEquals(0, this.channel1.read(readBuf, 0, 2));
- this.channel1.close();
- assertFalse(this.channel1.isOpen());
- try {
- assertEquals(0, this.channel1.read(readBuf, 0, 1));
- } catch (ClosedChannelException e) {
- // correct
- }
-
- datagramSocket1.close();
- //regression test for HARMONY-932
- try {
- DatagramChannel.open().read(new ByteBuffer[] {}, 2, Integer.MAX_VALUE);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- DatagramChannel.open().write(new ByteBuffer[] {}, 2, Integer.MAX_VALUE);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- DatagramChannel.open().write((ByteBuffer[])null, -1, 2);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII_ConnectedBufNull()
- throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- try {
- this.channel1.read(null, 0, 2);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- assertEquals(0, this.channel1.read(readBuf, 0, 1));
- try {
- this.channel1.read(readBuf, 0, 2);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- datagramSocket1.close();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII_NotConnectedBufNull()
- throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.read(null, 0, 2);
- fail("should throw NPE");
- } catch (NullPointerException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 0, 2);
- fail("should throw NotYetConnectedException");
- } catch (NotYetConnectedException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII_ConnectedIndexBad() throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- this.channel1.connect(ipAddr);
- assertTrue(this.channel1.isConnected());
- this.channel1.configureBlocking(false);
- // note : blocking-mode will make the read process endless!
- try {
- this.channel1.read(readBuf, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 1, 2);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 2, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.read(readBuf, 3, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII_NotConnectedIndexBad()
- throws IOException {
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- InetSocketAddress ipAddr = localAddr1;
- try {
- this.channel1.write(readBuf, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(readBuf, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(readBuf, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(readBuf, 1, 2);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(readBuf, 2, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- try {
- this.channel1.write(readBuf, 3, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // correct
- }
- }
-
- public void disabled_testReadByteBufferArrayII_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.read(targetBuf, 0, 2);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
- channel1.read(targetBuf, 0, 2);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- // -------------------------------------------------------------------
- // test read and write
- // -------------------------------------------------------------------
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadWrite_configureBlock() throws Exception {
- byte[] targetArray = new byte[2];
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.configureBlocking(false);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.read(targetBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- this.channel1.close();
- try {
- this.channel1.configureBlocking(true);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- this.channel1 = SelectorProvider.provider().openDatagramChannel();
- this.channel1.configureBlocking(false);
- this.channel1.register(SelectorProvider.provider().openSelector(),
- SelectionKey.OP_READ);
- try {
- this.channel1.configureBlocking(true);
- fail("should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_Zero() throws Exception {
- byte[] sourceArray = new byte[0];
- byte[] targetArray = new byte[0];
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(0, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_Normal() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- readWriteReadData(this.channel1, sourceArray, this.channel2,
- targetArray, CAPACITY_NORMAL, "testReadWrite_Block_Normal");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_Empty() throws Exception {
- // empty buf
- byte[] sourceArray = "".getBytes();
- byte[] targetArray = new byte[CAPACITY_NORMAL];
-
- // bind and connect
-
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(0, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- // empty message let the reader blocked
- closeBlockedReaderChannel2(targetBuf);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_changeBlock_Empty() throws Exception {
- // empty buf
- byte[] sourceArray = "".getBytes();
- byte[] targetArray = new byte[CAPACITY_NORMAL];
-
- // bind and connect
-
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(0, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- // empty message let the reader blocked
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel2.configureBlocking(false);
- Thread.sleep(TIME_UNIT * 5);
- channel2.close();
- } catch (Exception e) {
- // do nothing
- }
- }
- }.start();
- try {
- assertTrue(this.channel2.isBlocking());
- this.channel2.read(targetBuf);
- fail("Should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- assertFalse(this.channel2.isBlocking());
- // OK.
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_8KB() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_1KB * 8];
- byte[] targetArray = new byte[CAPACITY_1KB * 8];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- readWriteReadData(this.channel1, sourceArray, this.channel2,
- targetArray, 8 * CAPACITY_1KB, "testReadWrite_Block_8KB");
- }
-
- /*
- * sender write the sourceArray whose size is dataSize, and receiver read
- * the data into targetArray
- */
- private void readWriteReadData(DatagramChannel sender, byte[] sourceArray,
- DatagramChannel receiver, byte[] targetArray, int dataSize,
- String methodName) throws IOException {
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(dataSize, sender.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
-
- int count = 0;
- int total = 0;
- long beginTime = System.currentTimeMillis();
- while (total < dataSize && (count = receiver.read(targetBuf)) != -1) {
- total = total + count;
- // 3s timeout to avoid dead loop
- if (System.currentTimeMillis() - beginTime > 3000){
- break;
- }
- }
-
- assertEquals(dataSize, total);
- assertEquals(targetBuf.position(), total);
- targetBuf.flip();
- targetArray = targetBuf.array();
- for (int i = 0; i < targetArray.length; i++) {
- assertEquals(targetArray[i], (byte) i);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadWrite_Block_64K() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_64KB];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- try {
- channel1.write(sourceBuf);
- fail("Should throw IOException");
- } catch (IOException e) {
- // too big
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_DifferentAddr() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr1);// the different addr
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- // the wrong connected addr will make the read blocked.
- // we close the blocked channel
- closeBlockedReaderChannel2(targetBuf);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_WriterNotBind() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- closeBlockedReaderChannel2(targetBuf);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_WriterBindLater() throws Exception {
-
- byte[] targetArray = new byte[CAPACITY_NORMAL];
-
- // bind and connect
- // writer channel1 is bound later
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- // bind later
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
- channel1.socket().bind(localAddr2);
- channel1.connect(localAddr1);
- // write later
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, channel1.write(sourceBuf));
- } catch (Exception e) {
- // do nothing
- }
- }
- }.start();
-
- int count = 0;
- int total = 0;
- long beginTime = System.currentTimeMillis();
- while (total < CAPACITY_NORMAL && (count = channel2.read(targetBuf)) != -1) {
- total = total + count;
- // 3s timeout to avoid dead loop
- if (System.currentTimeMillis() - beginTime > 3000){
- break;
- }
- }
-
- assertEquals(CAPACITY_NORMAL, total);
- assertEquals(targetBuf.position(), total);
- targetBuf.flip();
- targetArray = targetBuf.array();
- for (int i = 0; i < targetArray.length; i++) {
- assertEquals(targetArray[i], (byte) i);
- }
-
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_Block_ReaderNotBind() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- // reader channel2 is not bound
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- closeBlockedReaderChannel2(targetBuf);
-
- }
-
- private void closeBlockedReaderChannel2(ByteBuffer targetBuf)
- throws IOException {
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel2.close();
- } catch (Exception e) {
- // do nothing
- }
- }
- }.start();
- try {
- assertTrue(this.channel2.isBlocking());
- this.channel2.read(targetBuf);
- fail("Should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // OK.
- }
- }
-
- // -------------------------------------------------------------------
- // Test read and write in non-block mode.
- // -------------------------------------------------------------------
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_Normal() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- readWriteReadData(this.channel1, sourceArray, this.channel2,
- targetArray, CAPACITY_NORMAL, "testReadWrite_NonBlock_Normal");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_8KB() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_1KB * 8];
- byte[] targetArray = new byte[CAPACITY_1KB * 8];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- readWriteReadData(this.channel1, sourceArray, this.channel2,
- targetArray, 8 * CAPACITY_1KB, "testReadWrite_NonBlock_8KB");
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_DifferentAddr() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr1);// the different addr
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_Empty() throws Exception {
- // empty buf
- byte[] sourceArray = "".getBytes();
- byte[] targetArray = new byte[CAPACITY_NORMAL];
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
-
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(0, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_WriterNotBind() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_Zero() throws Exception {
- byte[] sourceArray = new byte[0];
- byte[] targetArray = new byte[0];
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(0, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testReadWrite_NonBlock_ReaderNotBind() throws Exception {
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- byte[] targetArray = new byte[CAPACITY_NORMAL];
- for (int i = 0; i < sourceArray.length; i++) {
- sourceArray[i] = (byte) i;
- }
-
- this.channel1.configureBlocking(false);
- this.channel2.configureBlocking(false);
-
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.connect(localAddr2);
-
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- assertEquals(CAPACITY_NORMAL, this.channel1.write(sourceBuf));
-
- // read
- ByteBuffer targetBuf = ByteBuffer.wrap(targetArray);
- assertEquals(0, this.channel2.read(targetBuf));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void testWriteByteBuffer_Positioned() throws Exception {
- // Regression test for Harmony-683
- int postion = 16;
- DatagramChannel dc = DatagramChannel.open();
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- dc.connect(localAddr1);
- // write
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- sourceBuf.position(postion);
- assertEquals(CAPACITY_NORMAL - postion, dc.write(sourceBuf));
- }
-
- public void disabled_testWriteByteBuffer_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.send(targetBuf, localAddr1);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testWriteByteBuffer_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
- channel1.send(targetBuf, localAddr1);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_PositonNotZero()
- throws Exception {
- // regression test for Harmony-701
- int CAPACITY_NORMAL = 256;
- int postion = 16;
- DatagramChannel dc = DatagramChannel.open();
- byte[] sourceArray = new byte[CAPACITY_NORMAL];
- // send ByteBuffer whose position is not zero
- ByteBuffer sourceBuf = ByteBuffer.wrap(sourceArray);
- sourceBuf.position(postion);
- int ret = dc.send(sourceBuf, localAddr1);
- // assert send (256 - 16) bytes
- assertEquals(CAPACITY_NORMAL - postion, ret);
- // assert the position of ByteBuffer has been set
- assertEquals(CAPACITY_NORMAL, sourceBuf.position());
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer2() throws Exception {
- // regression test for Harmony-754
- channel2.socket().bind(localAddr1);
- channel1.socket().bind(localAddr2);
- channel1.connect(localAddr1);
- channel2.connect(localAddr2);
- channel2.write(ByteBuffer.allocate(CAPACITY_NORMAL));
-
- ByteBuffer readBuf = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
-
- channel1.configureBlocking(true);
- assertEquals(CAPACITY_NORMAL, channel1.read(readBuf));
- }
-
- public void disabled_testReadByteBuffer_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.read(targetBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer_Block_interrupt() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer targetBuf = ByteBuffer.wrap(new byte[2]);
- channel1.read(targetBuf);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void testReadByteBufferArray2() throws Exception {
- // regression test for Harmony-754
- channel2.socket().bind(localAddr1);
- channel1.socket().bind(localAddr2);
- channel1.connect(localAddr1);
- channel2.connect(localAddr2);
- channel2.write(ByteBuffer.allocate(CAPACITY_NORMAL));
-
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
-
- channel1.configureBlocking(true);
- assertEquals(CAPACITY_NORMAL, channel1.read(readBuf));
- }
-
- public void disabled_testReadByteBufferArray_Block_close() throws Exception {
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
-
- new Thread() {
- public void run() {
- try {
- Thread.sleep(TIME_UNIT);
- channel1.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- this.channel1.read(targetBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- public void disabled_testReadByteBufferArray_Block_interrupt() throws Exception {
- // makes emulator hang
- // bind and connect
- this.channel1.socket().bind(localAddr2);
- this.channel1.connect(localAddr1);
- this.channel2.socket().bind(localAddr1);
- this.channel2.connect(localAddr2);
-
- class MyThread extends Thread {
- public String errMsg = null;
- public void run() {
- try {
- ByteBuffer[] targetBuf = new ByteBuffer[2];
- targetBuf[0] = ByteBuffer.wrap(new byte[2]);
- targetBuf[1] = ByteBuffer.wrap(new byte[2]);
- channel1.read(targetBuf);
- errMsg = "should throw ClosedByInterruptException";
- } catch (ClosedByInterruptException e) {
- // expected
- } catch (IOException e) {
- errMsg = "Unexcted Exception was thrown: " + e.getClass() +
- ": " + e.getMessage();
- }
- }
- }
- MyThread thread = new MyThread();
- thread.start();
- try {
- Thread.sleep(TIME_UNIT);
- thread.interrupt();
- } catch (InterruptedException e) {
- // ok
- }
- thread.join(TIME_UNIT);
- if (thread.errMsg != null) {
- fail(thread.errMsg);
- }
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer[],int,int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void testReadByteBufferArrayII2() throws Exception {
- // regression test for Harmony-754
- channel2.socket().bind(localAddr1);
- channel1.socket().bind(localAddr2);
- channel1.connect(localAddr1);
- channel2.connect(localAddr2);
- channel2.write(ByteBuffer.allocate(CAPACITY_NORMAL));
-
- ByteBuffer[] readBuf = new ByteBuffer[2];
- readBuf[0] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
- readBuf[1] = ByteBuffer.allocateDirect(CAPACITY_NORMAL);
-
- channel1.configureBlocking(true);
- assertEquals(CAPACITY_NORMAL, channel1.read(readBuf,0,2));
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer_closed_nullBuf() throws Exception {
- // regression test for Harmony-754
- ByteBuffer c = null;
- DatagramChannel channel = DatagramChannel.open();
- channel.close();
- try{
- channel.read(c);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e){
- // expected
- }
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer_NotConnected_nullBuf() throws Exception {
- // regression test for Harmony-754
- ByteBuffer c = null;
- DatagramChannel channel = DatagramChannel.open();
- try{
- channel.read(c);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e){
- // expected
- }
- }
-
- /**
- * @tests DatagramChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer.class}
- )
- public void testReadByteBuffer_readOnlyBuf() throws Exception {
- // regression test for Harmony-754
- ByteBuffer c = ByteBuffer.allocate(1);
- DatagramChannel channel = DatagramChannel.open();
- try{
- channel.read(c.asReadOnlyBuffer());
- fail("Should throw NotYetConnectedException");
- } catch (NotYetConnectedException e){
- // expected
- }
- channel.connect(localAddr1);
- try{
- channel.read(c.asReadOnlyBuffer());
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e){
- // expected
- }
- }
-
- /**
- * @tests DatagramChannel#send(ByteBuffer, SocketAddress)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "send",
- args = {java.nio.ByteBuffer.class, java.net.SocketAddress.class}
- )
- public void testSend_Closed() throws IOException{
- // regression test for Harmony-913
- channel1.close();
- ByteBuffer buf = ByteBuffer.allocate(CAPACITY_NORMAL);
- try {
- channel1.send(buf, localAddr1);
- fail("Should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- //pass
- }
- try {
- channel1.send(null,localAddr1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //pass
- }
- try {
- channel1.send(buf, null);
- fail("Should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- //pass
- }
- try {
- channel1.send(null, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //pass
- }
- }
-
- /**
- * @tests DatagramChannel#socket()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "socket",
- args = {}
- )
- public void testSocket_NonBlock_IllegalBlockingModeException() throws Exception {
- // regression test for Harmony-1036
- DatagramChannel channel = DatagramChannel.open();
- channel.configureBlocking(false);
- DatagramSocket socket = channel.socket();
- try {
- socket.send(null);
- fail("should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- try {
- socket.receive(null);
- fail("should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockInterruptionExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockInterruptionExceptionTest.java
deleted file mode 100644
index 679efe1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockInterruptionExceptionTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.FileLockInterruptionException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for FileLockInterruptionException
- */
-@TestTargetClass(FileLockInterruptionException.class)
-public class FileLockInterruptionExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.FileLockInterruptionException#FileLockInterruptionException()}
- */
- public void test_Constructor() {
- FileLockInterruptionException e = new FileLockInterruptionException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "FileLockInterruptionException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new FileLockInterruptionException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "FileLockInterruptionException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new FileLockInterruptionException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java
deleted file mode 100644
index f8dfc8a..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/FileLockTest.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-
-import junit.framework.TestCase;
-@TestTargetClass(FileLock.class)
-/**
- * Tests class FileLock.
- */
-public class FileLockTest extends TestCase {
-
- private FileChannel readWriteChannel;
-
- private MockFileLock mockLock;
-
- class MockFileLock extends FileLock {
-
- boolean isValid = true;
-
- protected MockFileLock(FileChannel channel, long position, long size,
- boolean shared) {
- super(channel, position, size, shared);
- }
-
- public boolean isValid() {
- return isValid;
- }
-
- public void release() throws IOException {
- isValid = false;
- }
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- File tempFile = File.createTempFile("testing", "tmp");
- tempFile.deleteOnExit();
- RandomAccessFile randomAccessFile = new RandomAccessFile(tempFile, "rw");
- readWriteChannel = randomAccessFile.getChannel();
- mockLock = new MockFileLock(readWriteChannel, 10, 100, false);
- }
-
- protected void tearDown() throws IOException {
- if (readWriteChannel != null) {
- readWriteChannel.close();
- }
- }
-
- /**
- * @tests java.nio.channels.FileLock#FileLock(FileChannel, long, long,
- * boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "FileLock",
- args = {java.nio.channels.FileChannel.class, long.class, long.class, boolean.class}
- )
- public void test_Constructor_Ljava_nio_channels_FileChannelJJZ() {
- FileLock fileLock1 = new MockFileLock(null, 0, 0, false);
- assertNull(fileLock1.channel());
-
- try {
- new MockFileLock(readWriteChannel, -1, 0, false);
- fail("should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- try {
- new MockFileLock(readWriteChannel, 0, -1, false);
- fail("should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- // Harmony-682 regression test
- try {
- new MockFileLock(readWriteChannel, Long.MAX_VALUE, 1, false);
- fail("should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ex) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.FileLock#channel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "channel",
- args = {}
- )
- public void test_channel() {
- assertSame(readWriteChannel, mockLock.channel());
- FileLock lock = new MockFileLock(null, 0, 10, true);
- assertNull(lock.channel());
- }
-
- /**
- * @tests java.nio.channels.FileLock#position()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "position",
- args = {}
- )
- public void test_position() {
- FileLock fileLock1 = new MockFileLock(readWriteChannel, 20, 100, true);
- assertEquals(20, fileLock1.position());
-
- final long position = ((long) Integer.MAX_VALUE + 1);
- FileLock fileLock2 = new MockFileLock(readWriteChannel, position, 100,
- true);
- assertEquals(position, fileLock2.position());
- }
-
- /**
- * @tests java.nio.channels.FileLock#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "size",
- args = {}
- )
- public void test_size() {
- FileLock fileLock1 = new MockFileLock(readWriteChannel, 20, 100, true);
- assertEquals(100, fileLock1.size());
-
- final long position = 0x0FFFFFFFFFFFFFFFL;
- final long size = ((long) Integer.MAX_VALUE + 1);
- FileLock fileLock2 = new MockFileLock(readWriteChannel, position, size,
- true);
- assertEquals(size, fileLock2.size());
- }
-
- /**
- * @tests java.nio.channels.FileLock#isShared()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "[check with false shared parameter]",
- method = "isShared",
- args = {}
- )
- public void test_isShared() {
- assertFalse(mockLock.isShared());
- FileLock lock = new MockFileLock(null, 0, 10, true);
- assertTrue(lock.isShared());
- }
-
- /**
- * @tests java.nio.channels.FileLock#overlaps(long, long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "overlaps",
- args = {long.class, long.class}
- )
- public void test_overlaps_JJ() {
- assertTrue(mockLock.overlaps(0, 11));
- assertFalse(mockLock.overlaps(0, 10));
- assertTrue(mockLock.overlaps(100, 110));
- assertTrue(mockLock.overlaps(99, 110));
- assertFalse(mockLock.overlaps(-1, 10));
- //Harmony-671 regression test
- assertTrue(mockLock.overlaps(1, 120));
- assertTrue(mockLock.overlaps(20, 50));
- }
-
- /**
- * @tests java.nio.channels.FileLock#isValid()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid() throws IOException {
- FileLock fileLock = readWriteChannel.lock();
- assertTrue(fileLock.isValid());
- fileLock.release();
- assertFalse(fileLock.isValid());
- }
-
- /**
- * @tests java.nio.channels.FileLock#release()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "release",
- args = {}
- )
- public void test_release() throws Exception {
- File file = File.createTempFile("test", "tmp");
- file.deleteOnExit();
- FileOutputStream fout = new FileOutputStream(file);
- FileChannel fileChannel = fout.getChannel();
- FileLock fileLock = fileChannel.lock();
- fileChannel.close();
- try {
- fileLock.release();
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- // release after release
- fout = new FileOutputStream(file);
- fileChannel = fout.getChannel();
- fileLock = fileChannel.lock();
- fileLock.release();
- fileChannel.close();
- try {
- fileLock.release();
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- //expected
- }
- }
-
- /**
- * @tests java.nio.channels.FileLock#release()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() throws Exception {
- File file = File.createTempFile("test", "tmp");
- file.deleteOnExit();
- FileOutputStream fout = new FileOutputStream(file);
- FileChannel fileChannel = fout.getChannel();
- FileLock fileLock = fileChannel.lock();
- assertTrue(fileLock.toString().length() > 0);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Regression test",
- method = "release",
- args = {}
- )
- public void testFileLock() throws Exception {
- String fileName = File.createTempFile("test", "tmp").getAbsolutePath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- FileLock lock = raf.getChannel().tryLock();
- raf.write("file lock test".getBytes());
- lock.release();
- raf.close();
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalBlockingModeExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalBlockingModeExceptionTest.java
deleted file mode 100644
index 704763f..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalBlockingModeExceptionTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.IllegalBlockingModeException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for IllegalBlockingModeException
- */
-@TestTargetClass(IllegalBlockingModeException.class)
-public class IllegalBlockingModeExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.IllegalBlockingModeException#IllegalBlockingModeException()}
- */
- public void test_Constructor() {
- IllegalBlockingModeException e = new IllegalBlockingModeException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "IllegalBlockingModeException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalBlockingModeException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "IllegalBlockingModeException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest
- .verifyGolden(this, new IllegalBlockingModeException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalSelectorExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalSelectorExceptionTest.java
deleted file mode 100644
index 7b3ae4a..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/IllegalSelectorExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.IllegalSelectorException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for IllegalSelectorException
- */
-@TestTargetClass(IllegalSelectorException.class)
-public class IllegalSelectorExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.IllegalSelectorException#IllegalSelectorException()}
- */
- public void test_Constructor() {
- IllegalSelectorException e = new IllegalSelectorException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "IllegalSelectorException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalSelectorException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "IllegalSelectorException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new IllegalSelectorException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MapModeTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MapModeTest.java
deleted file mode 100644
index c4f4222..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MapModeTest.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.FileChannel;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for FileChannel.MapMode
- */
-@TestTargetClass(java.nio.channels.FileChannel.MapMode.class)
-public class MapModeTest extends TestCase {
-
- /**
- * java.nio.channels.FileChannel.MapMode#PRIVATE,READONLY,READWRITE
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies fields.",
- method = "!Constants",
- args = {}
- )
- public void test_PRIVATE_READONLY_READWRITE() {
- assertNotNull(FileChannel.MapMode.PRIVATE);
- assertNotNull(FileChannel.MapMode.READ_ONLY);
- assertNotNull(FileChannel.MapMode.READ_WRITE);
-
- assertFalse(FileChannel.MapMode.PRIVATE
- .equals(FileChannel.MapMode.READ_ONLY));
- assertFalse(FileChannel.MapMode.PRIVATE
- .equals(FileChannel.MapMode.READ_WRITE));
- assertFalse(FileChannel.MapMode.READ_ONLY
- .equals(FileChannel.MapMode.READ_WRITE));
- }
-
- /**
- * java.nio.channels.FileChannel.MapMode#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- assertNotNull(FileChannel.MapMode.PRIVATE.toString());
- assertNotNull(FileChannel.MapMode.READ_ONLY.toString());
- assertNotNull(FileChannel.MapMode.READ_WRITE.toString());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockDatagramChannel.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockDatagramChannel.java
deleted file mode 100644
index c8dc2af..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockDatagramChannel.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import java.io.IOException;
-import java.net.DatagramSocket;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-class MockDatagramChannel extends DatagramChannel {
-
- public MockDatagramChannel(SelectorProvider arg0) {
- super(arg0);
- }
-
- public DatagramSocket socket() {
- return null;
- }
-
- public boolean isConnected() {
- return false;
- }
-
- public DatagramChannel connect(SocketAddress arg0) throws IOException {
- return null;
- }
-
- public DatagramChannel disconnect() throws IOException {
- return null;
- }
-
- public SocketAddress receive(ByteBuffer arg0) throws IOException {
- return null;
- }
-
- public int send(ByteBuffer arg0, SocketAddress arg1) throws IOException {
- return 0;
- }
-
- public int read(ByteBuffer arg0) throws IOException {
- return 0;
- }
-
- public long read(ByteBuffer[] arg0, int arg1, int arg2) throws IOException {
- return 0;
- }
-
- public int write(ByteBuffer arg0) throws IOException {
- return 0;
- }
-
- public long write(ByteBuffer[] arg0, int arg1, int arg2) throws IOException {
- return 0;
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- // empty
- }
-
- protected void implConfigureBlocking(boolean arg0) throws IOException {
- // empty
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSecurityManager.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSecurityManager.java
deleted file mode 100644
index 916140f..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSecurityManager.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import java.security.Permission;
-
-class MockSecurityManager extends SecurityManager {
-
- String validHost = null;
-
- int validPort = -1;
-
- public boolean checkAcceptCalled = false;
- public boolean checkConnectCalled = false;
-
- MockSecurityManager() {
- super();
- this.validHost = null;
- }
-
- MockSecurityManager(String host) {
- super();
- this.validHost = host;
- }
-
- MockSecurityManager(int port) {
- super();
- this.validPort = port;
- }
-
- public void checkPermission(Permission perm) {
- // no-op
- }
-
- public void checkPermission(Permission perm, Object context) {
- // no-op
- }
-
- public void checkConnect(String host, int port) {
- checkConnectCalled = true;
- // our local addr is OK.
- if (null != this.validHost) {
- if (!this.validHost.equals(host)) {
- throw new SecurityException();
- }
- }
- if ("127.0.0.1".equals(host)) {
- return;
- }
- super.checkConnect(host, port);
- }
-
- public void checkAccept(String host, int port) {
- checkAcceptCalled = true;
- // our local addr is OK.
- if (null != this.validHost) {
- if (!this.validHost.equals(host)) {
- throw new SecurityException();
- }
- }
- if (-1 != this.validPort) {
- if (this.validPort != port) {
- throw new SecurityException();
- }
- }
- if ("127.0.0.1".equals(host)) {
- return;
- }
- super.checkAccept(host, port);
- }
-} \ No newline at end of file
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockServerSocketChannel.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockServerSocketChannel.java
deleted file mode 100644
index 2058a7a..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockServerSocketChannel.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-class MockServerSocketChannel extends ServerSocketChannel {
-
- protected MockServerSocketChannel(SelectorProvider arg0) {
- super(arg0);
- }
-
- public ServerSocket socket() {
- return null;
- }
-
- public SocketChannel accept() throws IOException {
- return null;
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- }
-
- protected void implConfigureBlocking(boolean arg0) throws IOException {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSocketChannel.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSocketChannel.java
deleted file mode 100644
index 9d130ca..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/MockSocketChannel.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-class MockSocketChannel extends SocketChannel {
-
- protected MockSocketChannel(SelectorProvider arg0) {
- super(arg0);
- }
-
- public Socket socket() {
- return null;
- }
-
- public boolean isConnected() {
- return false;
- }
-
- public boolean isConnectionPending() {
- return false;
- }
-
- public boolean connect(SocketAddress arg0) throws IOException {
- return false;
- }
-
- public boolean finishConnect() throws IOException {
- return false;
- }
-
- public int read(ByteBuffer arg0) throws IOException {
- return 0;
- }
-
- public long read(ByteBuffer[] arg0, int arg1, int arg2) throws IOException {
- return 0;
- }
-
- public int write(ByteBuffer arg0) throws IOException {
- return 0;
- }
-
- public long write(ByteBuffer[] arg0, int arg1, int arg2) throws IOException {
- return 0;
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- }
-
- protected void implConfigureBlocking(boolean arg0) throws IOException {
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NoConnectionPendingExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NoConnectionPendingExceptionTest.java
deleted file mode 100644
index 36ee09e..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NoConnectionPendingExceptionTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.NoConnectionPendingException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for NoConnectionPendingException
- */
-@TestTargetClass(NoConnectionPendingException.class)
-public class NoConnectionPendingExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.NoConnectionPendingException#NoConnectionPendingException()}
- */
- public void test_Constructor() {
- NoConnectionPendingException e = new NoConnectionPendingException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NoConnectionPendingException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new NoConnectionPendingException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NoConnectionPendingException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest
- .verifyGolden(this, new NoConnectionPendingException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonReadableChannelExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonReadableChannelExceptionTest.java
deleted file mode 100644
index c908328..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonReadableChannelExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.NonReadableChannelException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for NonReadableChannelException
- */
-@TestTargetClass(NonReadableChannelException.class)
-public class NonReadableChannelExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.NonReadableChannelException#NonReadableChannelException()}
- */
- public void test_Constructor() {
- NonReadableChannelException e = new NonReadableChannelException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NonReadableChannelException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new NonReadableChannelException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NonReadableChannelException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new NonReadableChannelException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonWritableChannelExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonWritableChannelExceptionTest.java
deleted file mode 100644
index 9de01b0..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NonWritableChannelExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.NonWritableChannelException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for NonWritableChannelException
- */
-@TestTargetClass(NonWritableChannelException.class)
-public class NonWritableChannelExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.NonWritableChannelException#NonWritableChannelException()}
- */
- public void test_Constructor() {
- NonWritableChannelException e = new NonWritableChannelException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NonWritableChannelException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new NonWritableChannelException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NonWritableChannelException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new NonWritableChannelException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetBoundExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetBoundExceptionTest.java
deleted file mode 100644
index 94fb682..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetBoundExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.NotYetBoundException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for NotYetBoundException
- */
-@TestTargetClass(NotYetBoundException.class)
-public class NotYetBoundExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.NotYetBoundException#NotYetBoundException()}
- */
- public void test_Constructor() {
- NotYetBoundException e = new NotYetBoundException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NotYetBoundException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new NotYetBoundException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NotYetBoundException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new NotYetBoundException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetConnectedExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetConnectedExceptionTest.java
deleted file mode 100644
index 423e4a6..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/NotYetConnectedExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.NotYetConnectedException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for NotYetConnectedException
- */
-@TestTargetClass(NotYetConnectedException.class)
-public class NotYetConnectedExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.NotYetConnectedException#NotYetConnectedException()}
- */
- public void test_Constructor() {
- NotYetConnectedException e = new NotYetConnectedException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NotYetConnectedException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new NotYetConnectedException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "NotYetConnectedException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new NotYetConnectedException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/OverlappingFileLockExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/OverlappingFileLockExceptionTest.java
deleted file mode 100644
index c465211..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/OverlappingFileLockExceptionTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.OverlappingFileLockException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for OverlappingFileLockException
- */
-@TestTargetClass(OverlappingFileLockException.class)
-public class OverlappingFileLockExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.OverlappingFileLockException#OverlappingFileLockException()}
- */
- public void test_Constructor() {
- OverlappingFileLockException e = new OverlappingFileLockException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "OverlappingFileLockException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new OverlappingFileLockException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "OverlappingFileLockException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest
- .verifyGolden(this, new OverlappingFileLockException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java
deleted file mode 100644
index 72b5b5c..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/PipeTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.nio.channels.Pipe;
-import java.nio.channels.Pipe.SinkChannel;
-import java.nio.channels.Pipe.SourceChannel;
-
-import junit.framework.TestCase;
-@TestTargetClass(
- value = Pipe.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- method = "Pipe",
- args = {}
- )
- }
-)
-/*
- * Tests for Pipe and its default implementation
- */
-public class PipeTest extends TestCase {
-
- /**
- * @tests java.nio.channels.Pipe#open()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "open",
- args = {}
- )
- public void test_open() throws IOException{
- Pipe pipe = Pipe.open();
- assertNotNull(pipe);
- }
-
- /**
- * @tests java.nio.channels.Pipe#sink()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "sink",
- args = {}
- )
- public void test_sink() throws IOException {
- Pipe pipe = Pipe.open();
- SinkChannel sink = pipe.sink();
- assertTrue(sink.isBlocking());
- }
-
- /**
- * @tests java.nio.channels.Pipe#source()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "source",
- args = {}
- )
- public void test_source() throws IOException {
- Pipe pipe = Pipe.open();
- SourceChannel source = pipe.source();
- assertTrue(source.isBlocking());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectableChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectableChannelTest.java
deleted file mode 100644
index 5fb6359..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectableChannelTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.SelectorProvider;
-import junit.framework.TestCase;
-
-/*
- * Tests for SelectableChannel
- */
-@TestTargetClass(
- value = SelectableChannel.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "empty protected constructor",
- method = "SelectableChannel",
- args = {}
- )
- }
-)
-public class SelectableChannelTest extends TestCase {
-
- /**
- * @tests SelectableChannel#register(Selector, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Abstract method.",
- method = "register",
- args = {java.nio.channels.Selector.class, int.class}
- )
- public void test_register_LSelectorI() throws IOException {
- MockSelectableChannel msc = new MockSelectableChannel();
- // Verify that calling register(Selector, int) leads to the method
- // register(Selector, int, Object) being called with a null value
- // for the third argument.
- msc.register(Selector.open(), SelectionKey.OP_ACCEPT);
- assertTrue(msc.isCalled);
- }
-
- private class MockSelectableChannel extends SelectableChannel {
-
- private boolean isCalled = false;
-
- public Object blockingLock() {
- return null;
- }
-
- public SelectableChannel configureBlocking(boolean block)
- throws IOException {
- return null;
- }
-
- public boolean isBlocking() {
- return false;
- }
-
- public boolean isRegistered() {
- return false;
- }
-
- public SelectionKey keyFor(Selector sel) {
- return null;
- }
-
- public SelectorProvider provider() {
- return null;
- }
-
- public SelectionKey register(Selector sel, int ops, Object att)
- throws ClosedChannelException {
- if (null == att) {
- isCalled = true;
- }
- return null;
- }
-
- public int validOps() {
- return 0;
- }
-
- protected void implCloseChannel() throws IOException {
- // empty
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectionKeyTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectionKeyTest.java
deleted file mode 100644
index 9961398..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectionKeyTest.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.nio.channels.CancelledKeyException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-import tests.support.Support_PortManager;
-
-/*
- * Tests for SelectionKey and its default implementation
- */
-@TestTargetClass(
- value = SelectionKey.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "empty protected constructor",
- method = "SelectionKey",
- args = {}
- )
- }
-)
-public class SelectionKeyTest extends TestCase {
-
- Selector selector;
-
- SocketChannel sc;
-
- SelectionKey selectionKey;
-
- private static String LOCAL_ADDR = "127.0.0.1";
-
- protected void setUp() throws Exception {
- super.setUp();
- selector = Selector.open();
- sc = SocketChannel.open();
- sc.configureBlocking(false);
- selectionKey = sc.register(selector, SelectionKey.OP_CONNECT);
- }
-
- protected void tearDown() throws Exception {
- selectionKey.cancel();
- selectionKey = null;
- selector.close();
- selector = null;
- super.tearDown();
- }
-
- static class MockSelectionKey extends SelectionKey {
- private int interestOps;
-
- MockSelectionKey(int ops) {
- interestOps = ops;
- }
-
- public void cancel() {
- // do nothing
- }
-
- public SelectableChannel channel() {
- return null;
- }
-
- public int interestOps() {
- return 0;
- }
-
- public SelectionKey interestOps(int operations) {
- return null;
- }
-
- public boolean isValid() {
- return true;
- }
-
- public int readyOps() {
- return interestOps;
- }
-
- public Selector selector() {
- return null;
- }
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#attach(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "attach",
- args = {java.lang.Object.class}
- )
- public void test_attach() {
- MockSelectionKey mockSelectionKey = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- // no previous, return null
- Object o = new Object();
- Object check = mockSelectionKey.attach(o);
- assertNull(check);
-
- // null parameter is ok
- check = mockSelectionKey.attach(null);
- assertSame(o, check);
-
- check = mockSelectionKey.attach(o);
- assertNull(check);
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#attachment()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "attachment",
- args = {}
- )
- public void test_attachment() {
- MockSelectionKey mockSelectionKey = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- assertNull(mockSelectionKey.attachment());
- Object o = new Object();
- mockSelectionKey.attach(o);
- assertSame(o, mockSelectionKey.attachment());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#channel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "channel",
- args = {}
- )
- public void test_channel() {
- assertSame(sc, selectionKey.channel());
- // can be invoked even canceled
- selectionKey.cancel();
- assertSame(sc, selectionKey.channel());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#interestOps()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "interestOps",
- args = {}
- )
- public void test_interestOps() {
- assertEquals(SelectionKey.OP_CONNECT, selectionKey.interestOps());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#interestOps(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Doesn't verify CancelledKeyException.",
- method = "interestOps",
- args = {int.class}
- )
- public void test_interestOpsI() {
- selectionKey.interestOps(SelectionKey.OP_WRITE);
- assertEquals(SelectionKey.OP_WRITE, selectionKey.interestOps());
-
- try {
- selectionKey.interestOps(SelectionKey.OP_ACCEPT);
- fail("should throw IAE.");
- } catch (IllegalArgumentException ex) {
- // expected;
- }
-
- try {
- selectionKey.interestOps(~sc.validOps());
- fail("should throw IAE.");
- } catch (IllegalArgumentException ex) {
- // expected;
- }
- try {
- selectionKey.interestOps(-1);
- fail("should throw IAE.");
- } catch (IllegalArgumentException ex) {
- // expected;
- }
-
- selectionKey.cancel();
- try {
- selectionKey.interestOps(-1);
- fail("should throw IAE.");
- } catch (CancelledKeyException ex) {
- // expected;
- }
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isValid()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid() {
- assertTrue(selectionKey.isValid());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isValid()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid_KeyCancelled() {
- selectionKey.cancel();
- assertFalse(selectionKey.isValid());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isValid()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid_ChannelColsed() throws IOException {
- sc.close();
- assertFalse(selectionKey.isValid());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isValid()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid_SelectorClosed() throws IOException {
- selector.close();
- assertFalse(selectionKey.isValid());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isAcceptable()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isAcceptable",
- args = {}
- )
- public void test_isAcceptable() throws IOException {
- MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- assertTrue(mockSelectionKey1.isAcceptable());
- MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_CONNECT);
- assertFalse(mockSelectionKey2.isAcceptable());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isConnectable()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isConnectable",
- args = {}
- )
- public void test_isConnectable() {
- MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_CONNECT);
- assertTrue(mockSelectionKey1.isConnectable());
- MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- assertFalse(mockSelectionKey2.isConnectable());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isReadable()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isReadable",
- args = {}
- )
- public void test_isReadable() {
- MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_READ);
- assertTrue(mockSelectionKey1.isReadable());
- MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- assertFalse(mockSelectionKey2.isReadable());
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#isWritable()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isWritable",
- args = {}
- )
- public void test_isWritable() throws Exception {
- MockSelectionKey mockSelectionKey1 = new MockSelectionKey(SelectionKey.OP_WRITE);
- assertTrue(mockSelectionKey1.isWritable());
- MockSelectionKey mockSelectionKey2 = new MockSelectionKey(SelectionKey.OP_ACCEPT);
- assertFalse(mockSelectionKey2.isWritable());
-
- Selector selector = SelectorProvider.provider().openSelector();
-
- Pipe pipe = SelectorProvider.provider().openPipe();
- pipe.open();
- pipe.sink().configureBlocking(false);
- SelectionKey key = pipe.sink().register(selector, SelectionKey.OP_WRITE);
-
- key.cancel();
- try {
- key.isWritable();
- fail("should throw IAE.");
- } catch (CancelledKeyException ex) {
- // expected;
- }
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#cancel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "cancel",
- args = {}
- )
- public void test_cancel() {
- selectionKey.cancel();
- try {
- selectionKey.isAcceptable();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
- try {
- selectionKey.isConnectable();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
- try {
- selectionKey.isReadable();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
- try {
- selectionKey.isWritable();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
-
- try {
- selectionKey.readyOps();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
-
- try {
- selectionKey.interestOps(SelectionKey.OP_CONNECT);
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
-
- try {
- selectionKey.interestOps();
- fail("should throw CancelledKeyException.");
- } catch (CancelledKeyException ex) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#readyOps()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readyOps",
- args = {}
- )
- public void test_readyOps() throws IOException {
- int port = Support_PortManager.getNextPort();
- ServerSocket ss = new ServerSocket(port);
- try {
- sc.connect(new InetSocketAddress(LOCAL_ADDR, port));
- assertEquals(0, selectionKey.readyOps());
- assertFalse(selectionKey.isConnectable());
- selector.select();
- assertEquals(SelectionKey.OP_CONNECT, selectionKey.readyOps());
- } finally {
- ss.close();
- ss = null;
- }
-
- selectionKey.cancel();
- try {
- selectionKey.readyOps();
- fail("should throw IAE.");
- } catch (CancelledKeyException ex) {
- // expected;
- }
- }
-
- /**
- * @tests java.nio.channels.SelectionKey#selector()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "selector",
- args = {}
- )
- public void test_selector() {
- assertSame(selector, selectionKey.selector());
- selectionKey.cancel();
- assertSame(selector, selectionKey.selector());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java
deleted file mode 100644
index e15ad27..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SelectorTest.java
+++ /dev/null
@@ -1,736 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.ClosedSelectorException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
-import junit.framework.TestCase;
-import tests.support.Support_PortManager;
-
-/*
- * Tests for Selector and its default implementation
- */
-@TestTargetClass(
- value = Selector.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "empty protected constructor",
- method = "Selector",
- args = {}
- )
- }
-)
-public class SelectorTest extends TestCase {
-
- private static final int WAIT_TIME = 100;
-
- private static final int PORT = Support_PortManager.getNextPort();
-
- private static final InetSocketAddress LOCAL_ADDRESS = new InetSocketAddress(
- "127.0.0.1", PORT);
-
- Selector selector;
-
- ServerSocketChannel ssc;
-
- enum SelectType {
- NULL, TIMEOUT, NOW
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- ssc = ServerSocketChannel.open();
- ssc.configureBlocking(false);
- ServerSocket ss = ssc.socket();
- InetSocketAddress address = new InetSocketAddress(PORT);
- ss.bind(address);
- selector = Selector.open();
- }
-
- protected void tearDown() throws Exception {
- try {
- ssc.close();
- } catch (Exception e) {
- // do nothing
- }
- try {
- selector.close();
- } catch (Exception e) {
- // do nothing
- }
- super.tearDown();
- }
-
- /**
- * @tests java.nio.channels.Selector#open()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "open",
- args = {}
- )
- public void test_open() throws IOException {
- assertNotNull(selector);
- }
-
- /**
- * @tests Selector#isOpen()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- public void test_isOpen() throws IOException {
- assertTrue(selector.isOpen());
- selector.close();
- assertFalse(selector.isOpen());
- }
-
- /**
- * @tests java.nio.channels.Selector#provider()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "provider",
- args = {}
- )
- public void test_provider() throws IOException {
- // should be system default provider
- assertNotNull(selector.provider());
- assertSame(SelectorProvider.provider(), selector.provider());
- }
-
- /**
- * @tests java.nio.channels.Selector#keys()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "keys",
- args = {}
- )
- public void test_keys() throws IOException {
- SelectionKey key = ssc.register(selector, SelectionKey.OP_ACCEPT);
-
- Set<SelectionKey> keySet = selector.keys();
- Set<SelectionKey> keySet2 = selector.keys();
-
- assertSame(keySet, keySet2);
- assertEquals(1,keySet.size());
- SelectionKey key2 = keySet.iterator().next();
- assertEquals(key,key2);
-
- // Any attempt to modify keys will cause UnsupportedOperationException
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- SelectionKey key3 = sc.register(selector, SelectionKey.OP_READ);
- try {
- keySet2.add(key3);
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- try {
- keySet2.remove(key3);
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
- try {
- keySet2.clear();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- selector.close();
- try {
- selector.keys();
- fail("should throw ClosedSelectorException");
- } catch (ClosedSelectorException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Selector#keys()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "selectedKeys",
- args = {}
- )
- public void test_selectedKeys() throws IOException {
- SocketChannel sc = SocketChannel.open();
- ssc.register(selector, SelectionKey.OP_ACCEPT);
- try {
- int count = 0;
- sc.connect(LOCAL_ADDRESS);
- count = blockingSelect(SelectType.NULL, 0);
- assertEquals(1, count);
- Set<SelectionKey> selectedKeys = selector.selectedKeys();
- Set<SelectionKey> selectedKeys2 = selector.selectedKeys();
- assertSame(selectedKeys, selectedKeys2);
-
- assertEquals(1, selectedKeys.size());
- assertEquals(ssc.keyFor(selector), selectedKeys.iterator().next());
- // add one key into selectedKeys
- try {
- selectedKeys.add(ssc.keyFor(selector));
- fail("Should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- // expected
- }
-
- // no exception should be thrown
- selectedKeys.clear();
-
- Set<SelectionKey> selectedKeys3 = selector.selectedKeys();
- assertSame(selectedKeys, selectedKeys3);
-
- ssc.keyFor(selector).cancel();
- assertEquals(0, selectedKeys.size());
- selector.close();
- try {
- selector.selectedKeys();
- fail("should throw ClosedSelectorException");
- } catch (ClosedSelectorException e) {
- // expected
- }
- } finally {
- sc.close();
- }
- }
-
- /**
- * @tests java.nio.channel.Selector#selectNow()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies selectNow() method for Selector registered with SelectionKeys.OP_ACCEPT, SelectionKeys.OP_CONNECT, SelectionKeys.OP_READ, SelectionKeys.OP_WRITE keys.",
- method = "selectNow",
- args = {}
- )
- public void test_selectNow() throws IOException {
- assert_select_OP_ACCEPT(SelectType.NOW, 0);
- assert_select_OP_CONNECT(SelectType.NOW, 0);
- assert_select_OP_READ(SelectType.NOW, 0);
- assert_select_OP_WRITE(SelectType.NOW, 0);
- }
-
- /**
- * @tests java.nio.channel.Selector#selectNow()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that ClosedSelectorException is thrown if selectNow() method is called for closed Selector.",
- method = "selectNow",
- args = {}
- )
- public void test_selectNow_SelectorClosed() throws IOException {
- assert_select_SelectorClosed(SelectType.NOW, 0);
- }
-
- /**
- * @test java.nio.channels.Selector#selectNow()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that selectNow() method doesn't block.",
- method = "selectNow",
- args = {}
- )
- public void test_selectNow_Timeout() throws IOException {
- // make sure selectNow doesn't block
- selector.selectNow();
- }
-
- /**
- * @tests java.nio.channel.Selector#select()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies select() method for Selector registered with SelectionKeys.OP_ACCEPT, SelectionKeys.OP_CONNECT, SelectionKeys.OP_READ, SelectionKeys.OP_WRITE keys.",
- method = "select",
- args = {}
- )
- public void test_select() throws IOException {
- assert_select_OP_ACCEPT(SelectType.NULL, 0);
- assert_select_OP_CONNECT(SelectType.NULL, 0);
- assert_select_OP_READ(SelectType.NULL, 0);
- assert_select_OP_WRITE(SelectType.NULL, 0);
- }
-
- /**
- * @tests java.nio.channel.Selector#select()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that ClosedSelectorException is thrown if select() method is called for closed Selector.",
- method = "select",
- args = {}
- )
- public void test_select_SelectorClosed() throws IOException {
- assert_select_SelectorClosed(SelectType.NULL, 0);
- }
-
- /**
- * @tests java.nio.channel.Selector#select(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies select(long) method for Selector registered with SelectionKeys.OP_ACCEPT, SelectionKeys.OP_CONNECT, SelectionKeys.OP_READ, SelectionKeys.OP_WRITE keys and different timeout's values.",
- method = "select",
- args = {long.class}
- )
- public void test_selectJ() throws IOException {
- assert_select_OP_ACCEPT(SelectType.TIMEOUT, 0);
- assert_select_OP_CONNECT(SelectType.TIMEOUT, 0);
- assert_select_OP_READ(SelectType.TIMEOUT, 0);
- assert_select_OP_WRITE(SelectType.TIMEOUT, 0);
-
- assert_select_OP_ACCEPT(SelectType.TIMEOUT, WAIT_TIME);
- assert_select_OP_CONNECT(SelectType.TIMEOUT, WAIT_TIME);
- assert_select_OP_READ(SelectType.TIMEOUT, WAIT_TIME);
- assert_select_OP_WRITE(SelectType.TIMEOUT, WAIT_TIME);
- }
-
- /**
- * @tests java.nio.channel.Selector#select(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that ClosedSelectorException is thrown if select(long) method is called for closed Selector.",
- method = "select",
- args = {long.class}
- )
- public void test_selectJ_SelectorClosed() throws IOException {
- assert_select_SelectorClosed(SelectType.TIMEOUT, 0);
- selector = Selector.open();
- assert_select_SelectorClosed(SelectType.TIMEOUT, WAIT_TIME);
- }
-
- /**
- * @tests java.nio.channel.Selector#select(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IllegalArgumentException.",
- method = "select",
- args = {long.class}
- )
- public void test_selectJ_Exception() throws IOException {
- try {
- selector.select(-1);
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @test java.nio.channels.Selector#select(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that select(timeout) doesn't block.",
- method = "select",
- args = {long.class}
- )
- public void test_selectJ_Timeout() throws IOException {
- // make sure select(timeout) doesn't block
- selector.select(WAIT_TIME);
- }
-
- /**
- * @test java.nio.channels.Selector#select(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies select(long) method for empty selection keys.",
- method = "select",
- args = {long.class}
- )
- public void test_selectJ_Empty_Keys() throws IOException {
- // regression test, see HARMONY-3888.
- // make sure select(long) does wait for specified amount of
- // time if keys.size() == 0 (initial state of selector).
-
- final long SELECT_TIMEOUT = 2000;
-
- long time1 = System.currentTimeMillis();
- selector.select(SELECT_TIMEOUT);
- long time2 = System.currentTimeMillis();
- assertEquals("elapsed time", SELECT_TIMEOUT, (time2 - time1),
- SELECT_TIMEOUT * 0.05); // 5% accuracy
- }
-
- /**
- * @tests java.nio.channels.Selector#wakeup()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wakeup",
- args = {}
- )
- public void test_wakeup() throws IOException {
- /*
- * make sure the test does not block on select
- */
- selector.wakeup();
- selectOnce(SelectType.NULL, 0);
- selector.wakeup();
- selectOnce(SelectType.TIMEOUT, 0);
-
- // try to wakeup select. The invocation sequence of wakeup and select
- // doesn't affect test result.
- new Thread() {
- public void run() {
-
- try {
- Thread.sleep(WAIT_TIME);
- } catch (InterruptedException e) {
- // ignore
- }
- selector.wakeup();
- }
- }.start();
- selectOnce(SelectType.NULL, 0);
-
- // try to wakeup select. The invocation sequence of wakeup and select
- // doesn't affect test result.
- new Thread() {
- public void run() {
-
- try {
- Thread.sleep(WAIT_TIME);
- } catch (InterruptedException e) {
- // ignore
- }
- selector.wakeup();
- }
- }.start();
- selectOnce(SelectType.TIMEOUT, 0);
- }
-
- public void test_keySetViewsModifications() throws IOException {
- Set<SelectionKey> keys = selector.keys();
-
- SelectionKey key1 = ssc.register(selector, SelectionKey.OP_ACCEPT);
-
- assertTrue(keys.contains(key1));
-
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- SelectionKey key2 = sc.register(selector, SelectionKey.OP_READ);
-
- assertTrue(keys.contains(key1));
- assertTrue(keys.contains(key2));
-
- key1.cancel();
- assertTrue(keys.contains(key1));
-
- selector.selectNow();
- assertFalse(keys.contains(key1));
- assertTrue(keys.contains(key2));
- }
-
- /**
- * This test cancels a key while selecting to verify that the cancelled
- * key set is processed both before and after the call to the underlying
- * operating system.
- */
- public void test_cancelledKeys() throws Exception {
- final AtomicReference<Throwable> failure = new AtomicReference<Throwable>();
- final AtomicBoolean complete = new AtomicBoolean();
-
- final Pipe pipe = Pipe.open();
- pipe.source().configureBlocking(false);
- final SelectionKey key = pipe.source().register(selector, SelectionKey.OP_READ);
-
- Thread thread = new Thread() {
- public void run() {
- try {
- // make sure to call key.cancel() while the main thread is selecting
- Thread.sleep(500);
- key.cancel();
- assertFalse(key.isValid());
- pipe.sink().write(ByteBuffer.allocate(4)); // unblock select()
- } catch (Throwable e) {
- failure.set(e);
- } finally {
- complete.set(true);
- }
- }
- };
- assertTrue(key.isValid());
-
- thread.start();
- do {
- assertEquals(0, selector.select(5000)); // blocks
- assertEquals(0, selector.selectedKeys().size());
- } while (!complete.get()); // avoid spurious interrupts
- assertFalse(key.isValid());
-
- thread.join();
- assertNull(failure.get());
- }
-
- private void assert_select_SelectorClosed(SelectType type, int timeout)
- throws IOException {
- // selector is closed
- selector.close();
- try {
- selectOnce(type, timeout);
- fail("should throw ClosedSelectorException");
- } catch (ClosedSelectorException e) {
- // expected
- }
- }
-
- private void assert_select_OP_ACCEPT(SelectType type, int timeout)
- throws IOException, ClosedChannelException {
- SocketChannel sc = SocketChannel.open();
- SocketChannel client = null;
- try {
- ssc.register(selector, SelectionKey.OP_ACCEPT);
- sc.connect(LOCAL_ADDRESS);
- int count = blockingSelect(type, timeout);
- assertEquals(1, count);
- Set<SelectionKey> selectedKeys = selector.selectedKeys();
- assertEquals(1, selectedKeys.size());
- SelectionKey key = selectedKeys.iterator().next();
- assertEquals(ssc.keyFor(selector), key);
- assertEquals(SelectionKey.OP_ACCEPT, key.readyOps());
- // select again, it should return 0
- count = selectOnce(type, timeout);
- assertEquals(0,count);
- // but selectedKeys remains the same as previous
- assertSame(selectedKeys, selector.selectedKeys());
- client = ssc.accept();
- selectedKeys.clear();
- } finally {
- try {
- sc.close();
- } catch (IOException e) {
- // do nothing
- }
- if (null != client) {
- client.close();
- }
- }
- ssc.keyFor(selector).cancel();
- }
-
- private void assert_select_OP_CONNECT(SelectType type, int timeout)
- throws IOException, ClosedChannelException {
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- sc.register(selector, SelectionKey.OP_CONNECT);
- try {
- sc.connect(LOCAL_ADDRESS);
- int count = blockingSelect(type, timeout);
- assertEquals(1, count);
- Set<SelectionKey> selectedKeys = selector.selectedKeys();
- assertEquals(1, selectedKeys.size());
- SelectionKey key = selectedKeys.iterator().next();
- assertEquals(sc.keyFor(selector), key);
- assertEquals(SelectionKey.OP_CONNECT, key.readyOps());
- // select again, it should return 0
- count = selectOnce(type, timeout);
- assertEquals(0, count);
- // but selectedKeys remains the same as previous
- assertSame(selectedKeys, selector.selectedKeys());
- sc.finishConnect();
- selectedKeys.clear();
- } finally {
- try {
- ssc.accept().close();
- } catch (Exception e) {
- // do nothing
- }
-
- try {
- sc.close();
- } catch (IOException e) {
- // do nothing
- }
- }
- }
-
- private void assert_select_OP_READ(SelectType type, int timeout)
- throws IOException {
- SocketChannel sc = SocketChannel.open();
- SocketChannel client = null;
- SocketChannel sc2 = SocketChannel.open();
- SocketChannel client2 = null;
- try {
- ssc.configureBlocking(true);
- sc.connect(LOCAL_ADDRESS);
- client = ssc.accept();
- sc.configureBlocking(false);
- sc.register(selector, SelectionKey.OP_READ);
- client.configureBlocking(true);
-
- sc2.connect(LOCAL_ADDRESS);
- client2 = ssc.accept();
- sc2.configureBlocking(false);
- sc2.register(selector, SelectionKey.OP_READ);
- client2.configureBlocking(true);
-
- client.write(ByteBuffer.wrap("a".getBytes()));
- int count = blockingSelect(type, timeout);
- assertEquals(1, count);
- Set<SelectionKey> selectedKeys = selector.selectedKeys();
- assertEquals(1, selectedKeys.size());
- SelectionKey key = selectedKeys.iterator().next();
- assertEquals(sc.keyFor(selector), key);
- assertEquals(SelectionKey.OP_READ, key.readyOps());
- // select again, it should return 0
- count = selectOnce(type, timeout);
- assertEquals(0, count);
- // but selectedKeys remains the same as previous
- assertSame(selectedKeys, selector.selectedKeys());
-
- sc.read(ByteBuffer.allocate(8));
-
- // the second SocketChannel should be selected this time
- client2.write(ByteBuffer.wrap("a".getBytes()));
- count = blockingSelect(type, timeout);
- assertEquals(1, count);
- // selectedKeys still includes the key of sc, because the key of sc
- // is not removed last time.
- selectedKeys = selector.selectedKeys();
- assertEquals(2, selectedKeys.size());
- } finally {
- if (null != client) {
- try {
- client.close();
- } catch (Exception e) {
- // ignore
- }
- }
- if (null != client2) {
- try {
- client2.close();
- } catch (Exception e) {
- // ignore
- }
- }
- try {
- sc.close();
- } catch (Exception e) {
- // ignore
- }
- try {
- sc2.close();
- } catch (Exception e) {
- // ignore
- }
- ssc.configureBlocking(false);
- }
- }
-
- private void assert_select_OP_WRITE(SelectType type, int timeout)
- throws IOException {
- SocketChannel sc = SocketChannel.open();
- SocketChannel client = null;
- try {
- sc.connect(LOCAL_ADDRESS);
- ssc.configureBlocking(true);
- client = ssc.accept();
- sc.configureBlocking(false);
- sc.register(selector, SelectionKey.OP_WRITE);
- int count = blockingSelect(type, timeout);
- assertEquals(1, count);
- Set<SelectionKey> selectedKeys = selector.selectedKeys();
- assertEquals(1, selectedKeys.size());
- SelectionKey key = selectedKeys.iterator().next();
- assertEquals(sc.keyFor(selector), key);
- assertEquals(SelectionKey.OP_WRITE, key.readyOps());
- // select again, it should return 0
- count = selectOnce(type, timeout);
- assertEquals(0, count);
- // but selectedKeys remains the same as previous
- assertSame(selectedKeys, selector.selectedKeys());
- } finally {
- if (null != client) {
- client.close();
- }
- try {
- sc.close();
- } catch (IOException e) {
- // do nothing
- }
- ssc.configureBlocking(false);
- }
- }
-
- private int blockingSelect(SelectType type, int timeout) throws IOException {
- int ret = 0;
- do {
- ret = selectOnce(type, timeout);
- if (ret > 0) {
- return ret;
- }
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- // ignore
- }
- } while (true);
- }
-
- private int selectOnce(SelectType type, int timeout) throws IOException {
- int ret = 0;
- switch (type) {
- case NULL:
- ret = selector.select();
- break;
- case TIMEOUT:
- ret = selector.select(timeout);
- break;
- case NOW:
- ret = selector.selectNow();
- break;
- }
- return ret;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java
deleted file mode 100644
index eb2f9dd..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SinkChannelTest.java
+++ /dev/null
@@ -1,751 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.AndroidOnly;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousCloseException;
-import java.nio.channels.ClosedByInterruptException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.Pipe.SinkChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-
-/**
- * Tests for Pipe.SinkChannel class
- */
-@TestTargetClass(
- value = java.nio.channels.Pipe.SinkChannel.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "ClosedByInterruptException can not easily be tested",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- }
-)
-public class SinkChannelTest extends TestCase {
-
- private static final int BUFFER_SIZE = 5;
-
- private static final String ISO8859_1 = "ISO8859-1";
-
- private Pipe pipe;
-
- private Pipe.SinkChannel sink;
-
- private Pipe.SourceChannel source;
-
- private ByteBuffer buffer;
-
- private ByteBuffer positionedBuffer;
-
- protected void setUp() throws Exception {
- super.setUp();
- pipe = Pipe.open();
- sink = pipe.sink();
- source = pipe.source();
- buffer = ByteBuffer.wrap("bytes".getBytes(ISO8859_1));
- positionedBuffer = ByteBuffer.wrap("12345bytes".getBytes(ISO8859_1));
- positionedBuffer.position(BUFFER_SIZE);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#validOps()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "validOps",
- args = {}
- )
- public void test_validOps() {
- assertEquals(SelectionKey.OP_WRITE, sink.validOps());
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer [])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_LByteBuffer() throws IOException {
- ByteBuffer[] bufArray = { buffer, positionedBuffer };
- boolean[] sinkBlockingMode = { true, true, false, false };
- boolean[] sourceBlockingMode = { true, false, true, false };
- int oldPosition;
- int currentPosition;
- for (int i = 0; i < sinkBlockingMode.length; ++i) {
- sink.configureBlocking(sinkBlockingMode[i]);
- source.configureBlocking(sourceBlockingMode[i]);
- // if sink and source both are blocking mode, source only needs read
- // once to get what sink write.
- boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
- for (ByteBuffer buf : bufArray) {
- buf.mark();
- oldPosition = buf.position();
- sink.write(buf);
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- int totalCount = 0;
- do {
- int count = source.read(readBuf);
- if (count > 0) {
- totalCount += count;
- }
- } while (totalCount != BUFFER_SIZE && !isBlocking);
- currentPosition = buf.position();
- assertEquals(BUFFER_SIZE, currentPosition - oldPosition);
- assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
- buf.reset();
- }
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_LByteBuffer_mutliThread() throws IOException,
- InterruptedException {
- final int THREAD_NUM = 20;
- final byte[] strbytes = "bytes".getBytes(ISO8859_1);
- Thread[] thread = new Thread[THREAD_NUM];
- for (int i = 0; i < THREAD_NUM; i++) {
- thread[i] = new Thread() {
- public void run() {
- try {
- sink.write(ByteBuffer.wrap(strbytes));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- };
- }
- for (int i = 0; i < THREAD_NUM; i++) {
- thread[i].start();
- }
- for (int i = 0; i < THREAD_NUM; i++) {
- thread[i].join();
- }
- ByteBuffer readBuf = ByteBuffer.allocate(THREAD_NUM * BUFFER_SIZE);
-
- long totalCount = 0;
- do {
- long count = source.read(readBuf);
- if (count < 0) {
- break;
- }
- totalCount += count;
- } while (totalCount != (THREAD_NUM * BUFFER_SIZE));
-
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < THREAD_NUM; i++) {
- buf.append("bytes");
- }
- String readString = buf.toString();
- assertEquals(readString, new String(readBuf.array(), ISO8859_1));
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- public void disabled_test_read_LByteBuffer_mutliThread_close() throws Exception {
-
- ByteBuffer sourceBuf = ByteBuffer.allocate(1000);
- sink.configureBlocking(true);
-
- new Thread() {
- public void run() {
- try {
- Thread.currentThread().sleep(500);
- sink.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- sink.write(sourceBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- public void disabled_test_read_LByteBuffer_mutliThread_interrupt() throws Exception {
-
- sink.configureBlocking(true);
-
- Thread thread = new Thread() {
- public void run() {
- try {
- sink.write(ByteBuffer.allocate(10));
- fail("should have thrown a ClosedByInterruptException.");
- } catch (ClosedByInterruptException e) {
- // expected
- return;
- } catch (IOException e) {
- fail("should throw a ClosedByInterruptException but " +
- "threw " + e.getClass() + ": " + e.getMessage());
- }
- }
- };
-
- thread.start();
- Thread.currentThread().sleep(500);
- thread.interrupt();
-
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_LByteBuffer_Exception() throws IOException {
- // write null ByteBuffer
- ByteBuffer nullBuf = null;
- try {
- sink.write(nullBuf);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- @AndroidOnly("seems to run on newer RI versions")
- public void test_write_LByteBuffer_SourceClosed() throws IOException {
- source.close();
- int written = sink.write(buffer);
- assertEquals(BUFFER_SIZE, written);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException, NullPointerException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_LByteBuffer_SinkClosed() throws IOException {
- sink.close();
- try {
- sink.write(buffer);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- // write null ByteBuffer
- ByteBuffer nullBuf = null;
- try {
- sink.write(nullBuf);
- fail("should throw NullPointerException");
- } catch (ClosedChannelException e) {
- // expected on RI
- } catch (NullPointerException e) {
- // expected on Harmony/Android
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_$LByteBuffer() throws IOException {
- ByteBuffer[] bufArray = { buffer, positionedBuffer };
- boolean[] sinkBlockingMode = { true, true, false, false };
- boolean[] sourceBlockingMode = { true, false, true, false };
- for (int i = 0; i < sinkBlockingMode.length; ++i) {
- sink.configureBlocking(sinkBlockingMode[i]);
- source.configureBlocking(sourceBlockingMode[i]);
- buffer.position(0);
- positionedBuffer.position(BUFFER_SIZE);
- sink.write(bufArray);
- // if sink and source both are blocking mode, source only needs read
- // once to get what sink write.
- boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
- for (int j = 0; j < bufArray.length; ++j) {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- int totalCount = 0;
- do {
- int count = source.read(readBuf);
- if (count < 0) {
- break;
- }
- totalCount += count;
- } while (totalCount != BUFFER_SIZE && !isBlocking);
- assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
- }
- assertEquals(BUFFER_SIZE, buffer.position());
- assertEquals(10, positionedBuffer.position());
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_$LByteBuffer_Exception() throws IOException {
- // write null ByteBuffer[]
- ByteBuffer[] nullBufArrayRef = null;
- try {
- sink.write(nullBufArrayRef);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // write ByteBuffer[] contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray = { buffer, nullBuf };
- try {
- sink.write(nullBufArray);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- @AndroidOnly("seems to run on newer RI versions")
- public void test_write_$LByteBuffer_SourceClosed() throws IOException {
- ByteBuffer[] bufArray = { buffer };
- source.close();
- long written = sink.write(bufArray);
- assertEquals(BUFFER_SIZE, written);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException, NullPointerException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_write_$LByteBuffer_SinkClosed() throws IOException {
- ByteBuffer[] bufArray = { buffer };
- sink.close();
- try {
- sink.write(bufArray);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArrayRef = null;
- try {
- sink.write(nullBufArrayRef);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray = { nullBuf };
- // write ByteBuffer[] contains null element
- try {
- sink.write(nullBufArray);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_write_$LByteBufferII() throws IOException {
- ByteBuffer[] bufArray = { buffer, positionedBuffer };
- boolean[] sinkBlockingMode = { true, true, false, false };
- boolean[] sourceBlockingMode = { true, false, true, false };
- for (int i = 0; i < sinkBlockingMode.length; ++i) {
- sink.configureBlocking(sinkBlockingMode[i]);
- source.configureBlocking(sourceBlockingMode[i]);
- positionedBuffer.position(BUFFER_SIZE);
- sink.write(bufArray, 1, 1);
- // if sink and source both are blocking mode, source only needs read
- // once to get what sink write.
- boolean isBlocking = sinkBlockingMode[i] && sourceBlockingMode[i];
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- int totalCount = 0;
- do {
- int count = source.read(readBuf);
- if (count < 0) {
- break;
- }
- totalCount += count;
- } while (totalCount != BUFFER_SIZE && !isBlocking);
- assertEquals("bytes", new String(readBuf.array(), ISO8859_1));
- assertEquals(10, positionedBuffer.position());
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException, IndexOutOfBoundsException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_write_$LByteBufferII_Exception() throws IOException {
- // write null ByteBuffer[]
- ByteBuffer[] nullBufArrayRef = null;
- try {
- sink.write(nullBufArrayRef, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- sink.write(nullBufArrayRef, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // write ByteBuffer[] contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray = { nullBuf };
- try {
- sink.write(nullBufArray, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- sink.write(nullBufArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- ByteBuffer[] bufArray = { buffer, nullBuf };
- try {
- sink.write(bufArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray, 0, 2);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- @AndroidOnly("seems to run on newer RI versions")
- public void test_write_$LByteBufferII_SourceClosed() throws IOException {
- ByteBuffer[] bufArray = { buffer };
- source.close();
- long written = sink.write(bufArray, 0, 1);
- assertEquals(BUFFER_SIZE, written);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#write(ByteBuffer[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException, NullPointerException, IndexOutOfBoundsException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_write_$LByteBufferII_SinkClosed() throws IOException {
- ByteBuffer[] bufArray = { buffer };
- sink.close();
- try {
- sink.write(bufArray, 0, 1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- // write null ByteBuffer[]
- ByteBuffer[] nullBufArrayRef = null;
- try {
- sink.write(nullBufArrayRef, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- // illegal array index
- try {
- sink.write(nullBufArrayRef, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // write ByteBuffer[] contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray = { nullBuf };
- try {
- sink.write(nullBufArray, 0, 1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- // illegal array index
- try {
- sink.write(nullBufArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- ByteBuffer[] bufArray2 = { buffer, nullBuf };
- // illegal array index
- try {
- sink.write(bufArray2, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray2, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray2, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray2, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- sink.write(bufArray2, 0, 2);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SinkChannel#close()
- * @tests {@link java.nio.channels.Pipe.SinkChannel#isOpen()}
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- ),@TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- })
- public void test_close() throws IOException {
- assertTrue(sink.isOpen());
- sink.close();
- assertFalse(sink.isOpen());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SinkChannel",
- args = {java.nio.channels.spi.SelectorProvider.class}
- )
- public void testConstructor() throws IOException {
- SinkChannel channel =
- SelectorProvider.provider().openPipe().sink();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(),channel.provider());
- channel = Pipe.open().sink();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(),channel.provider());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that NullPointerException is thrown if write" +
- "method is called for closed channel.",
- method = "write",
- args = {java.nio.ByteBuffer.class}
- )
- public void test_socketChannel_closed() throws Exception {
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(),49999));
- SocketChannel sc = SocketChannel.open();
- ByteBuffer buf = null;
- try{
- sc.write(buf);
- fail("should throw NPE");
- }catch (NullPointerException e){
- // expected
- }
- sc.connect(new InetSocketAddress(InetAddress.getLocalHost(),49999));
- SocketChannel sock = ssc.accept();
- ssc.close();
- sc.close();
- try{
- sc.write(buf);
- fail("should throw NPE");
- }catch (NullPointerException e){
- // expected
- }
- sock.close();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException.",
- method = "write",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_socketChannel_empty() throws Exception {
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(),49999));
- SocketChannel sc = SocketChannel.open();
- sc.connect(new InetSocketAddress(InetAddress.getLocalHost(),49999));
- SocketChannel sock = ssc.accept();
- ByteBuffer[] buf = {ByteBuffer.allocate(10),null};
- try{
- sc.write(buf,0,2);
- fail("should throw NPE");
- }catch (NullPointerException e){
- // expected
- }
- ssc.close();
- sc.close();
- ByteBuffer target = ByteBuffer.allocate(10);
- assertEquals(-1, sock.read(target));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SourceChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SourceChannelTest.java
deleted file mode 100644
index 55a0144..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/SourceChannelTest.java
+++ /dev/null
@@ -1,721 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargets;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.AsynchronousCloseException;
-import java.nio.channels.ClosedByInterruptException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Pipe.SourceChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-@TestTargetClass(
- value = java.nio.channels.Pipe.SourceChannel.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "AsynchronousCloseException can not easily be tested",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- }
-)
-/**
- * Tests for java.nio.channels.Pipe.SourceChannel
- */
-public class SourceChannelTest extends TestCase {
-
- private static final int BUFFER_SIZE = 5;
-
- private static final String ISO8859_1 = "ISO8859-1";
-
- private Pipe pipe;
-
- private Pipe.SinkChannel sink;
-
- private Pipe.SourceChannel source;
-
- private ByteBuffer buffer;
-
- private ByteBuffer positionedBuffer;
-
- protected void setUp() throws Exception {
- super.setUp();
- pipe = Pipe.open();
- sink = pipe.sink();
- source = pipe.source();
- buffer = ByteBuffer.wrap("bytes".getBytes(ISO8859_1));
- positionedBuffer = ByteBuffer.wrap("12345bytes".getBytes(ISO8859_1));
- positionedBuffer.position(BUFFER_SIZE);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#validOps()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "validOps",
- args = {}
- )
- public void test_validOps() {
- assertEquals(SelectionKey.OP_READ, source.validOps());
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_LByteBuffer_DataAvailable() throws IOException {
- // if anything can read, read method will not block
- sink.write(ByteBuffer.allocate(1));
- int count = source.read(ByteBuffer.allocate(10));
- assertEquals(1, count);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_LByteBuffer_Exception() throws IOException {
- ByteBuffer nullBuf = null;
- try {
- source.read(nullBuf);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_LByteBuffer_SinkClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- sink.write(buffer);
- sink.close();
- long count = source.read(readBuf);
- assertEquals(BUFFER_SIZE, count);
- // readBuf is full, read 0 byte expected
- count = source.read(readBuf);
- assertEquals(0, count);
- // readBuf is not null, -1 is expected
- readBuf.position(0);
- count = source.read(readBuf);
- assertEquals(-1, count);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException, NullPointerException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_LByteBuffer_SourceClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- source.close();
- try {
- source.read(readBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- readBuf.position(BUFFER_SIZE);
- try {
- // readBuf is full
- source.read(readBuf);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- ByteBuffer nullBuf = null;
- try {
- source.read(nullBuf);
- fail("should throw NullPointerException");
- } catch (ClosedChannelException e) {
- // expected on RI
- } catch (NullPointerException e) {
- // expected on Harmony/Android
- }
-
- ByteBuffer[] bufArray = null;
- try {
- source.read(bufArray);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArray = {nullBuf};
- try {
- source.read(nullBufArray);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_$LByteBuffer() throws IOException {
- ByteBuffer[] bufArray = { buffer, positionedBuffer };
- boolean[] sinkBlockingMode = { true, true, false, false };
- boolean[] sourceBlockingMode = { true, false, true, false };
- for (int i = 0; i < sinkBlockingMode.length; ++i) {
- // open new pipe everytime, will be closed in finally block
- pipe = Pipe.open();
- sink = pipe.sink();
- source = pipe.source();
- sink.configureBlocking(sinkBlockingMode[i]);
- source.configureBlocking(sourceBlockingMode[i]);
- buffer.position(0);
- positionedBuffer.position(BUFFER_SIZE);
- try {
- long writeCount = sink.write(bufArray);
- assertEquals(10, writeCount);
- // invoke close to ensure all data will be sent out
- sink.close();
- // read until EOF is meet or readBufArray is full.
- ByteBuffer[] readBufArray = { ByteBuffer.allocate(BUFFER_SIZE),
- ByteBuffer.allocate(BUFFER_SIZE) };
- long totalCount = 0;
- do {
- long count = source.read(readBufArray);
- if (count < 0) {
- break;
- }
- if (0 == count && BUFFER_SIZE == readBufArray[1].position()) {
- // source.read returns 0 because readBufArray is full
- break;
- }
- totalCount += count;
- } while (totalCount <= 10);
- // assert read result
- for (ByteBuffer readBuf : readBufArray) {
- // RI may fail because of its bug implementation
- assertEquals(BUFFER_SIZE, readBuf.position());
- assertEquals("bytes",
- new String(readBuf.array(), ISO8859_1));
- }
- } finally {
- // close pipe everytime
- sink.close();
- source.close();
- }
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_$LByteBuffer_Exception() throws IOException {
- ByteBuffer[] nullBufArrayRef = null;
- try {
- source.read(nullBufArrayRef);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // ByteBuffer array contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray1 = { nullBuf };
- try {
- source.read(nullBufArray1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
- try {
- source.read(nullBufArray2);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_$LByteBuffer_SinkClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- ByteBuffer[] readBufArray = { readBuf };
- sink.write(buffer);
- sink.close();
- long count = source.read(readBufArray);
- assertEquals(BUFFER_SIZE, count);
- // readBuf is full, read 0 byte expected
- count = source.read(readBufArray);
- assertEquals(0, count);
- // readBuf is not null, -1 is expected
- readBuf.position(0);
- assertTrue(readBuf.hasRemaining());
- count = source.read(readBufArray);
- assertEquals(-1, count);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedChannelException, NullPointerException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_$LByteBuffer_SourceClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- ByteBuffer[] readBufArray = { readBuf };
- source.close();
- try {
- source.read(readBufArray);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- readBuf.position(BUFFER_SIZE);
- try {
- // readBuf is full
- source.read(readBufArray);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArrayRef = null;
- try {
- source.read(nullBufArrayRef);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // ByteBuffer array contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray1 = { nullBuf };
- try {
- source.read(nullBufArray1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_read_$LByteBufferII() throws IOException {
- ByteBuffer[] bufArray = { buffer, positionedBuffer };
- boolean[] sinkBlockingMode = { true, true, false, false };
- boolean[] sourceBlockingMode = { true, false, true, false };
- for (int i = 0; i < sinkBlockingMode.length; ++i) {
- Pipe pipe = Pipe.open();
- sink = pipe.sink();
- source = pipe.source();
-
- sink.configureBlocking(sinkBlockingMode[i]);
- source.configureBlocking(sourceBlockingMode[i]);
-
- buffer.position(0);
- positionedBuffer.position(BUFFER_SIZE);
- try {
- sink.write(bufArray);
- // invoke close to ensure all data will be sent out
- sink.close();
- // read until EOF is meet or readBufArray is full.
- ByteBuffer[] readBufArray = { ByteBuffer.allocate(BUFFER_SIZE),
- ByteBuffer.allocate(BUFFER_SIZE) };
- long totalCount = 0;
- do {
- long count = source.read(readBufArray, 0, 2);
- if (count < 0) {
- break;
- }
- if (0 == count && BUFFER_SIZE == readBufArray[1].position()) {
- // source.read returns 0 because readBufArray is full
- break;
- }
- totalCount += count;
- } while (totalCount != 10);
-
- // assert read result
- for (ByteBuffer readBuf : readBufArray) {
- // RI may fail because of its bug implementation
- assertEquals(BUFFER_SIZE, readBuf.position());
- assertEquals("bytes",
- new String(readBuf.array(), ISO8859_1));
- }
- } finally {
- sink.close();
- source.close();
- }
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies NullPointerException, IndexOutOfBoundsException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_read_$LByteBufferII_Exception() throws IOException {
-
- ByteBuffer[] nullBufArrayRef = null;
- try {
- source.read(nullBufArrayRef, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- source.read(nullBufArrayRef, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // ByteBuffer array contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray1 = { nullBuf };
- try {
- source.read(nullBufArray1, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
-
- try {
- source.read(nullBufArray1, 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- source.read(nullBufArray2, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- source.read(nullBufArray2, 0, 2);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_read_$LByteBufferII_SinkClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- ByteBuffer[] readBufArray = { readBuf };
- sink.write(buffer);
- sink.close();
- long count = source.read(readBufArray, 0, 1);
- assertEquals(BUFFER_SIZE, count);
- // readBuf is full, read 0 byte expected
- count = source.read(readBufArray);
- assertEquals(0, count);
- // readBuf is not null, -1 is expected
- readBuf.position(0);
- count = source.read(readBufArray, 0, 1);
- assertEquals(-1, count);
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies IndexOutOfBoundsException, ClosedChannelException.",
- method = "read",
- args = {java.nio.ByteBuffer[].class, int.class, int.class}
- )
- public void test_read_$LByteBufferII_SourceClosed() throws IOException {
- ByteBuffer readBuf = ByteBuffer.allocate(BUFFER_SIZE);
- ByteBuffer[] readBufArray = { readBuf };
- source.close();
- try {
- source.read(readBufArray, 0, 1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- readBuf.position(BUFFER_SIZE);
- try {
- // readBuf is full
- source.read(readBufArray, 0, 1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArrayRef = null;
- try {
- source.read(nullBufArrayRef, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- source.read(nullBufArrayRef, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // ByteBuffer array contains null element
- ByteBuffer nullBuf = null;
- ByteBuffer[] nullBufArray1 = { nullBuf };
- try {
- source.read(nullBufArray1, 0, 1);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- source.read(nullBufArray1, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- ByteBuffer[] nullBufArray2 = { buffer, nullBuf };
-
- try {
- source.read(nullBufArray1, 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- source.read(nullBufArray2, 0, 3);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- source.read(nullBufArray2, 0, 2);
- fail("should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#close()
- * @tests {@link java.nio.channels.Pipe.SourceChannel#isOpen()}
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- ),@TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- })
- public void test_close() throws IOException {
- assertTrue(sink.isOpen());
- sink.close();
- assertFalse(sink.isOpen());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SourceChannel",
- args = {java.nio.channels.spi.SelectorProvider.class}
- )
- public void testConstructor() throws IOException {
- SourceChannel channel =
- SelectorProvider.provider().openPipe().source();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(),channel.provider());
- channel = Pipe.open().source();
- assertNotNull(channel);
- assertSame(SelectorProvider.provider(),channel.provider());
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies ClosedByInterruptException",
- method = "read",
- args = {java.nio.ByteBuffer[].class}
- )
- public void test_read_LByteBuffer_mutliThread_interrupt() throws Exception {
-
- source.configureBlocking(true);
-
- Thread thread = new Thread() {
- public void run() {
- try {
- source.read(ByteBuffer.allocate(10));
- fail("should have thrown a ClosedByInterruptException.");
- } catch (ClosedByInterruptException e) {
- // expected
- return;
- } catch (IOException e) {
- fail("should throw a ClosedByInterruptException but " +
- "threw " + e.getClass() + ": " + e.getMessage());
- }
- }
- };
-
- thread.start();
- Thread.currentThread().sleep(500);
- thread.interrupt();
-
- }
-
- /**
- * @tests java.nio.channels.Pipe.SourceChannel#read(ByteBuffer)
- */
- public void disabled_test_read_LByteBuffer_mutliThread_close() throws Exception {
-
- ByteBuffer sourceBuf = ByteBuffer.allocate(1000);
- source.configureBlocking(true);
-
- new Thread() {
- public void run() {
- try {
- Thread.currentThread().sleep(500);
- source.close();
- } catch (Exception e) {
- //ignore
- }
- }
- }.start();
- try {
- source.read(sourceBuf);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // ok
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnresolvedAddressExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnresolvedAddressExceptionTest.java
deleted file mode 100644
index d248509..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnresolvedAddressExceptionTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.UnresolvedAddressException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for UnresolvedAddressException
- */
-@TestTargetClass(UnresolvedAddressException.class)
-public class UnresolvedAddressExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.UnresolvedAddressException#UnresolvedAddressException()}
- */
- public void test_Constructor() {
- UnresolvedAddressException e = new UnresolvedAddressException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "UnresolvedAddressException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnresolvedAddressException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "UnresolvedAddressException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new UnresolvedAddressException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnsupportedAddressTypeExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnsupportedAddressTypeExceptionTest.java
deleted file mode 100644
index ba5b41c..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/UnsupportedAddressTypeExceptionTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.harmony.nio.tests.java.nio.channels;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.UnsupportedAddressTypeException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- * Tests for UnsupportedAddressTypeException
- */
-@TestTargetClass(UnsupportedAddressTypeException.class)
-public class UnsupportedAddressTypeExceptionTest extends TestCase {
-
- /**
- * @tests {@link java.nio.channels.UnsupportedAddressTypeException#UnsupportedAddressTypeException()}
- */
- public void test_Constructor() {
- UnsupportedAddressTypeException e = new UnsupportedAddressTypeException();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationSelf",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "UnsupportedAddressTypeException",
- args = {}
- )
- })
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnsupportedAddressTypeException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "!SerializationGolden",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies serialization/deserialization compatibility.",
- method = "UnsupportedAddressTypeException",
- args = {}
- )
- })
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new UnsupportedAddressTypeException());
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractInterruptibleChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractInterruptibleChannelTest.java
deleted file mode 100644
index 05fa362..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractInterruptibleChannelTest.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.nio.channels.AsynchronousCloseException;
-import java.nio.channels.spi.AbstractInterruptibleChannel;
-
-import junit.framework.TestCase;
-@TestTargetClass(
- value = AbstractInterruptibleChannel.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "empty protected constructor",
- method = "AbstractInterruptibleChannel",
- args = {}
- )
- }
-)
-public class AbstractInterruptibleChannelTest extends TestCase {
-
- /**
- * @tests AbstractInterruptibleChannel#close()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- })
- public void test_close() throws IOException {
- MockInterruptibleChannel testMiChannel = new MockInterruptibleChannel();
- assertTrue(testMiChannel.isOpen());
- testMiChannel.isImplCloseCalled = false;
- testMiChannel.close();
- assertTrue(testMiChannel.isImplCloseCalled);
- assertFalse(testMiChannel.isOpen());
- }
-
- /**
- * @tests AbstractInterruptibleChannel#begin/end()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "begin",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "end",
- args = {boolean.class}
- )
- })
- public void test_begin_end() throws IOException {
- boolean complete = false;
- MockInterruptibleChannel testChannel = new MockInterruptibleChannel();
- try {
- testChannel.superBegin();
- complete = true;
- } finally {
- testChannel.superEnd(complete);
- }
-
- try {
- testChannel.superBegin();
- complete = false;
- } finally {
- testChannel.superEnd(complete);
- }
-
- try {
- testChannel.superBegin();
- complete = true;
- } finally {
- testChannel.superEnd(complete);
- }
- testChannel.superEnd(complete);
-
- testChannel.superBegin();
- try {
- testChannel.superBegin();
- complete = true;
- } finally {
- testChannel.superEnd(complete);
- }
- assertTrue(testChannel.isOpen());
- testChannel.close();
- }
-
- /**
- * @tests AbstractInterruptibleChannel#close/begin/end()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "begin",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "end",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- })
- public void test_close_begin_end() throws IOException {
- boolean complete = false;
- MockInterruptibleChannel testChannel = new MockInterruptibleChannel();
- assertTrue(testChannel.isOpen());
- try {
- testChannel.superBegin();
- complete = true;
- } finally {
- testChannel.superEnd(complete);
- }
- assertTrue(testChannel.isOpen());
- testChannel.close();
- try {
- testChannel.superBegin();
- complete = false;
- } finally {
- try {
- testChannel.superEnd(complete);
- fail("should throw AsynchronousCloseException");
- } catch (AsynchronousCloseException e) {
- // expected
- }
- }
- assertFalse(testChannel.isOpen());
- try {
- testChannel.superBegin();
- complete = true;
- } finally {
- testChannel.superEnd(complete);
- }
- assertFalse(testChannel.isOpen());
- }
-
- private class MockInterruptibleChannel extends AbstractInterruptibleChannel {
-
- private boolean isImplCloseCalled = false;
-
- public MockInterruptibleChannel() {
- super();
- }
-
- protected void implCloseChannel() throws IOException {
- isImplCloseCalled = true;
- }
-
- // call super.begin() for test
- void superBegin() {
- super.begin();
- }
-
- // call super.end() for test
- void superEnd(boolean completed) throws AsynchronousCloseException {
- super.end(completed);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectableChannelTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectableChannelTest.java
deleted file mode 100644
index 67d66d6..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectableChannelTest.java
+++ /dev/null
@@ -1,437 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.IOException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.IllegalBlockingModeException;
-import java.nio.channels.IllegalSelectorException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.nio.tests.java.nio.channels.spi.AbstractSelectorTest.MockSelectorProvider;
-
-/**
- * Tests for AbstractSelectableChannel
- */
-@TestTargetClass(AbstractSelectableChannel.class)
-public class AbstractSelectableChannelTest extends TestCase {
-
- private MockSelectableChannel testChannel;
-
- protected void setUp() throws Exception {
- super.setUp();
- testChannel = new MockSelectableChannel(SelectorProvider.provider());
- }
-
- protected void tearDown() throws Exception {
- if (testChannel.isOpen()) {
- testChannel.close();
- }
- }
-
- /**
- * @tests AbstractSelectableChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "AbstractSelectableChannel",
- args = {SelectorProvider.class}
- )
- public void test_Constructor_LSelectorProvider() throws Exception {
- assertSame(SelectorProvider.provider(), testChannel.provider());
- }
-
- /**
- * @tests AbstractSelectableChannel#implCloseChannel()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "implCloseChannel",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "implCloseSelectableChannel",
- args = {}
- )
- })
- public void test_implClose() throws IOException {
- testChannel.isImplCloseSelectableChannelCalled = false;
- testChannel.implCloseSelectableChannelCount = 0;
- testChannel.close();
- assertFalse(testChannel.isOpen());
- assertTrue(testChannel.isImplCloseSelectableChannelCalled);
- assertEquals(1, testChannel.implCloseSelectableChannelCount);
-
- testChannel = new MockSelectableChannel(SelectorProvider.provider());
- testChannel.isImplCloseSelectableChannelCalled = false;
- testChannel.implCloseSelectableChannelCount = 0;
- // close twice.
- // make sure implCloseSelectableChannelCount is called only once.
- testChannel.close();
- testChannel.close();
- assertFalse(testChannel.isOpen());
- assertTrue(testChannel.isImplCloseSelectableChannelCalled);
- assertEquals(1, testChannel.implCloseSelectableChannelCount);
- }
-
- /**
- * @tests AbstractSelectableChannel#provider()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "provider",
- args = {}
- )
- public void test_provider() {
- SelectorProvider provider = testChannel.provider();
- assertSame(SelectorProvider.provider(), provider);
- testChannel = new MockSelectableChannel(null);
- provider = testChannel.provider();
- assertNull(provider);
- }
-
- /**
- * @tests AbstractSelectableChannel#isBlocking()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "isBlocking",
- args = {}
- )
- public void test_isBlocking() throws IOException {
- assertTrue(testChannel.isBlocking());
- testChannel.configureBlocking(false);
- assertFalse(testChannel.isBlocking());
- testChannel.configureBlocking(true);
- assertTrue(testChannel.isBlocking());
- }
-
- /**
- *
- * @tests AbstractSelectableChannel#blockingLock()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "blockingLock",
- args = {}
- )
- public void test_blockingLock() {
- Object gotObj = testChannel.blockingLock();
- assertNotNull(gotObj);
- }
-
- /**
- * @tests AbstractSelectableChannel#register(Selector, int, Object)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "register",
- args = {java.nio.channels.Selector.class, int.class, java.lang.Object.class}
- )
- public void test_register_LSelectorILObject() throws IOException {
- assertFalse(testChannel.isRegistered());
- Selector acceptSelector1 = SelectorProvider.provider().openSelector();
- Selector acceptSelector2 = new MockAbstractSelector(SelectorProvider
- .provider());
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- SelectionKey acceptKey = sc.register(acceptSelector1,
- SelectionKey.OP_READ, null);
- assertNotNull(acceptKey);
- assertTrue(acceptKey.isValid());
- assertSame(sc, acceptKey.channel());
-
- //test that sc.register invokes Selector.register()
- acceptKey = sc.register(acceptSelector2, SelectionKey.OP_READ, null);
- assertTrue(((MockAbstractSelector)acceptSelector2).isRegisterCalled);
-
- // Regression test to ensure acceptance of a selector with empty
- // interest set.
- SocketChannel channel = SocketChannel.open();
- channel.configureBlocking(false);
- Selector selector = Selector.open();
- channel.register(selector, 0);
- selector.close();
- channel.close();
- }
-
- /**
- * @tests AbstractSelectableChannel#register(Selector, int, Object)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "register",
- args = {java.nio.channels.Selector.class, int.class, java.lang.Object.class}
- )
- public void test_register_LSelectorILObject_IllegalArgument()
- throws IOException {
- Selector acceptSelector = SelectorProvider.provider().openSelector();
- assertTrue(acceptSelector.isOpen());
- MockSelectableChannel msc = new MockSelectableChannel(SelectorProvider
- .provider());
- msc.configureBlocking(false);
- // in nonblocking mode
- try {
- //different SelectionKey with validOps
- msc.register(acceptSelector, SelectionKey.OP_READ, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- msc.register(null, 0, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- // in nonblocking mode, if selector closed
- acceptSelector.close();
- try {
- msc.register(acceptSelector, SelectionKey.OP_READ, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- msc.register(null, 0, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- msc.register(acceptSelector, 0, null);
- fail("Should throw IllegalSelectorException");
- } catch (IllegalSelectorException e) {
- // expected
- }
-
- acceptSelector = SelectorProvider.provider().openSelector();
- // test in blocking mode
- msc.configureBlocking(true);
- try {
- msc.register(acceptSelector, SelectionKey.OP_READ, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- msc.register(null, 0, null);
- fail("Should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- acceptSelector.close();
- // in blocking mode, if selector closed
- try {
- msc.register(acceptSelector, SelectionKey.OP_READ, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- msc.register(null, 0, null);
- fail("Should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
-
- // register with an object
- Object argObj = new Object();
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- try {
- sc.register(null, SelectionKey.OP_READ, argObj);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // if channel closed
- msc.close();
- try {
- msc.register(acceptSelector, SelectionKey.OP_READ, null);
- fail("Should throw ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
-
- SelectorProvider prov1 = MockSelectorProvider.provider();
- SelectorProvider prov2 = MockSelectorProvider.provider();
-
- Selector sel = prov2.openSelector();
-
- sc = prov1.openSocketChannel();
- sc.configureBlocking(false);
- try {
- sc.register(sel, SelectionKey.OP_READ, null);
- } catch (IllegalSelectorException e) {
- // expected
- }
- }
-
- /**
- * @tests AbstractSelectableChannel#keyFor(Selector)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "keyFor",
- args = {java.nio.channels.Selector.class}
- )
- public void test_keyfor_LSelector() throws Exception {
- SocketChannel sc = SocketChannel.open();
- Object argObj = new Object();
- sc.configureBlocking(false);
- Selector acceptSelector = SelectorProvider.provider().openSelector();
- Selector acceptSelectorOther = SelectorProvider.provider()
- .openSelector();
- SelectionKey acceptKey = sc.register(acceptSelector,
- SelectionKey.OP_READ, argObj);
- assertEquals(sc.keyFor(acceptSelector), acceptKey);
- SelectionKey acceptKeyObjNull = sc.register(acceptSelector,
- SelectionKey.OP_READ, null);
- assertSame(sc.keyFor(acceptSelector), acceptKeyObjNull);
- assertSame(acceptKeyObjNull, acceptKey);
- SelectionKey acceptKeyOther = sc.register(acceptSelectorOther,
- SelectionKey.OP_READ, null);
- assertSame(sc.keyFor(acceptSelectorOther), acceptKeyOther);
- }
-
- /**
- * @tests AbstractSelectableChannel#configureBlocking(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "configureBlocking",
- args = {boolean.class}
- )
- public void test_configureBlocking_Z_IllegalBlockingMode() throws Exception {
- SocketChannel sc = SocketChannel.open();
- sc.configureBlocking(false);
- Selector acceptSelector = SelectorProvider.provider().openSelector();
- SelectionKey acceptKey = sc.register(acceptSelector,
- SelectionKey.OP_READ, null);
- assertEquals(sc.keyFor(acceptSelector), acceptKey);
- SelectableChannel getChannel = sc.configureBlocking(false);
- assertEquals(getChannel, sc);
- try {
- sc.configureBlocking(true);
- fail("Should throw IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
- }
-
- /**
- * @tests AbstractSelectableChannel#configureBlocking(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "configureBlocking",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "implConfigureBlocking",
- args = {boolean.class}
- )
- })
- public void test_configureBlocking_Z() throws Exception {
- testChannel = new MockSelectableChannel(SelectorProvider
- .provider());
- // default blocking mode is true. The implConfigureBlocking is only
- // invoked if the given mode is different with current one.
- testChannel.configureBlocking(true);
- assertFalse(testChannel.implConfigureBlockingCalled);
- testChannel.configureBlocking(false);
- assertTrue(testChannel.implConfigureBlockingCalled);
-
- AbstractSelectableChannel channel =
- SelectorProvider.provider().openDatagramChannel();
- channel.configureBlocking(false);
- channel.register(SelectorProvider.provider().openSelector(),
- SelectionKey.OP_READ);
- try {
- channel.configureBlocking(true);
- fail("Should have thrown IllegalBlockingModeException");
- } catch (IllegalBlockingModeException e) {
- // expected
- }
-
- testChannel.close();
- try {
- testChannel.configureBlocking(false);
- fail("Should have thrown ClosedChannelException");
- } catch (ClosedChannelException e) {
- // expected
- }
- }
-
- private class MockSelectableChannel extends AbstractSelectableChannel {
-
- private boolean isImplCloseSelectableChannelCalled = false;
-
- private int implCloseSelectableChannelCount = 0;
-
- private boolean implConfigureBlockingCalled = false;
-
- public MockSelectableChannel(SelectorProvider arg0) {
- super(arg0);
- }
-
- protected void implCloseSelectableChannel() throws IOException {
- isImplCloseSelectableChannelCalled = true;
- ++implCloseSelectableChannelCount;
- }
-
- protected void implConfigureBlocking(boolean arg0) throws IOException {
- implConfigureBlockingCalled = true;
- }
-
- public int validOps() {
- return SelectionKey.OP_ACCEPT;
- }
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectionKeyTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectionKeyTest.java
deleted file mode 100644
index 6393071..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectionKeyTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.AbstractSelectionKey;
-
-import junit.framework.TestCase;
-@TestTargetClass(
- value = AbstractSelectionKey.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "empty protected constructor",
- method = "AbstractSelectionKey",
- args = {}
- )
- }
-)
-public class AbstractSelectionKeyTest extends TestCase {
-
- /**
- * @tests AbstractSelectionKey#isValid() without selector
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isValid",
- args = {}
- )
- public void test_isValid() throws Exception {
- MockSelectionKey testKey = new MockSelectionKey();
- assertTrue(testKey.isValid());
- }
-
- /**
- * @tests AbstractSelectionKey#cancel
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "cancel",
- args = {}
- )
- public void test_cancel() throws Exception {
- MockSelectionKey testKey = new MockSelectionKey();
- try {
- testKey.cancel();
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected: no selector available
- }
- assertFalse(testKey.isValid());
- }
-
- private class MockSelectionKey extends AbstractSelectionKey {
-
- MockSelectionKey() {
- super();
- }
-
- public SelectableChannel channel() {
- return null;
- }
-
- public Selector selector() {
- return null;
- }
-
- public int interestOps() {
- return 0;
- }
-
- public SelectionKey interestOps(int arg0) {
- return null;
- }
-
- public int readyOps() {
- return 0;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectorTest.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectorTest.java
deleted file mode 100644
index 517dc46..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AbstractSelectorTest.java
+++ /dev/null
@@ -1,281 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.nio.channels.DatagramChannel;
-import java.nio.channels.Pipe;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.AbstractSelectionKey;
-import java.nio.channels.spi.SelectorProvider;
-import java.nio.channels.spi.AbstractSelector;
-import java.util.Set;
-
-import junit.framework.TestCase;
-@TestTargetClass(AbstractSelector.class)
-/**
- * Tests for AbstractSelector and register of its default implementation
- */
-public class AbstractSelectorTest extends TestCase {
-
- /**
- * @tests AbstractSelector#provider()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "provider",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "AbstractSelector",
- args = {SelectorProvider.class}
- )
- })
- public void test_provider() throws IOException {
- Selector mockSelector = new MockAbstractSelector(SelectorProvider
- .provider());
- assertTrue(mockSelector.isOpen());
- assertSame(SelectorProvider.provider(), mockSelector.provider());
- mockSelector = new MockAbstractSelector(null);
- assertNull(mockSelector.provider());
- }
-
- /**
- * @tests AbstractSelector#close()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "implCloseSelector",
- args = {}
- )
- })
- public void test_close() throws IOException {
- MockAbstractSelector mockSelector = new MockAbstractSelector(
- SelectorProvider.provider());
- mockSelector.close();
- assertTrue(mockSelector.isImplCloseSelectorCalled);
- }
-
- /**
- *
- * @tests AbstractSelector#begin/end()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "begin",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "end",
- args = {}
- )
- })
- public void test_begin_end() throws IOException {
- MockAbstractSelector mockSelector = new MockAbstractSelector(
- SelectorProvider.provider());
- try {
- mockSelector.superBegin();
- } finally {
- mockSelector.superEnd();
- }
-
- mockSelector = new MockAbstractSelector(SelectorProvider.provider());
- try {
- mockSelector.superBegin();
- mockSelector.close();
- } finally {
- mockSelector.superEnd();
- }
-
- try {
- // begin twice
- mockSelector.superBegin();
- mockSelector.superBegin();
- } finally {
- mockSelector.superEnd();
- }
-
- try {
- mockSelector.superBegin();
- } finally {
- // end twice
- mockSelector.superEnd();
- mockSelector.superEnd();
- }
-
- mockSelector.close();
- try {
- mockSelector.superBegin();
- } finally {
- mockSelector.superEnd();
- }
- }
-
- /**
- * @tests AbstractSelector#isOpen()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isOpen",
- args = {}
- )
- public void test_isOpen() throws Exception {
- Selector acceptSelector = SelectorProvider.provider().openSelector();
- assertTrue(acceptSelector.isOpen());
- acceptSelector.close();
- assertFalse(acceptSelector.isOpen());
- }
-
- /**
- * @tests AbstractSelector()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "AbstractSelector",
- args = {SelectorProvider.class}
- )
- public void test_Constructor_LSelectorProvider() throws Exception {
- Selector acceptSelector = new MockAbstractSelector(
- SelectorProvider.provider());
- assertSame(SelectorProvider.provider(), acceptSelector.provider());
- }
-
- /**
- * @tests AbstractSelector#register(AbstractSelectableChannel,int,Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies register method from SelectableChannel class.",
- method = "register",
- args = {AbstractSelectableChannel.class, int.class, java.lang.Object.class}
- )
- public void test_register_LAbstractSelectableChannelIObject()
- throws Exception {
- Selector acceptSelector = new MockSelectorProvider().openSelector();
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ssc.configureBlocking(false);
-
- assertFalse(ssc.isRegistered());
- ssc.register(acceptSelector, SelectionKey.OP_ACCEPT);
- assertTrue(ssc.isRegistered());
- assertTrue(((MockAbstractSelector)acceptSelector).isRegisterCalled);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "cancelledKeys",
- args = {}
- )
- public void test_cancelledKeys() throws Exception {
- MockSelectorProvider prov = new MockSelectorProvider();
- Selector acceptSelector = prov.openSelector();
- SocketChannel sc = prov.openSocketChannel();
- sc.configureBlocking(false);
-
- SelectionKey acceptKey = sc.register(acceptSelector,
- SelectionKey.OP_READ, null);
- acceptKey.cancel();
- Set<SelectionKey> cKeys =
- ((MockAbstractSelector)acceptSelector).getCancelledKeys();
- assertTrue(cKeys.contains(acceptKey));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "deregister",
- args = {AbstractSelectionKey.class}
- )
- public void test_deregister() throws Exception {
- MockSelectorProvider prov = new MockSelectorProvider();
- AbstractSelector acceptSelector = prov.openSelector();
- SocketChannel sc = prov.openSocketChannel();
- sc.configureBlocking(false);
-
- SelectionKey acceptKey = sc.register(acceptSelector,
- SelectionKey.OP_READ, null);
- assertTrue(sc.isRegistered());
- assertNotNull(acceptKey);
- ((MockAbstractSelector)acceptSelector).mockDeregister(
- (MockAbstractSelector.MockSelectionKey)acceptKey);
- assertFalse(sc.isRegistered());
- }
-
- static class MockSelectorProvider extends SelectorProvider {
-
- private MockSelectorProvider() {
- // do nothing
- }
-
- @Override
- public DatagramChannel openDatagramChannel() {
- return null;
- }
-
- @Override
- public Pipe openPipe() {
- return null;
- }
-
- @Override
- public AbstractSelector openSelector() {
- return new MockAbstractSelector(provider());
- }
-
- @Override
- public ServerSocketChannel openServerSocketChannel() {
- return null;
- }
-
- @Override
- public SocketChannel openSocketChannel() throws IOException {
- return SocketChannel.open();
- }
-
- public static SelectorProvider provider() {
- return new MockSelectorProvider();
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AllTests.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AllTests.java
deleted file mode 100644
index 6175b60..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/AllTests.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for tests.api.java.nio.channels.spi");
- //$JUnit-BEGIN$
- suite.addTestSuite(AbstractInterruptibleChannelTest.class);
- suite.addTestSuite(AbstractSelectorTest.class);
- suite.addTestSuite(AbstractSelectableChannelTest.class);
- suite.addTestSuite(SelectorProviderTest.class);
- suite.addTestSuite(AbstractSelectionKeyTest.class);
- //$JUnit-END$
- return suite;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/MockAbstractSelector.java b/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/MockAbstractSelector.java
deleted file mode 100644
index 59364c8..0000000
--- a/luni/src/test/java/org/apache/harmony/nio/tests/java/nio/channels/spi/MockAbstractSelector.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio.tests.java.nio.channels.spi;
-
-import java.io.IOException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.AbstractSelectableChannel;
-import java.nio.channels.spi.AbstractSelectionKey;
-import java.nio.channels.spi.AbstractSelector;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.HashSet;
-import java.util.Set;
-
-public class MockAbstractSelector extends AbstractSelector {
-
- class MockSelectionKey extends AbstractSelectionKey {
-
- boolean cancelled = false;
- Selector selector;
- SelectableChannel channel;
-
- MockSelectionKey(Selector sel, SelectableChannel chan) {
- selector = sel;
- channel = chan;
- }
-
- @Override
- public SelectableChannel channel() {
- return channel;
- }
-
- @Override
- public int interestOps() {
- return 0;
- }
-
- @Override
- public SelectionKey interestOps(int operations) {
- return null;
- }
-
- @Override
- public int readyOps() {
- return 0;
- }
-
- @Override
- public Selector selector() {
- return selector;
- }
- }
-
- public boolean isImplCloseSelectorCalled = false;
- private Set<SelectionKey> keys = new HashSet<SelectionKey>();
- public boolean isRegisterCalled = false;
-
- public MockAbstractSelector(SelectorProvider arg0) {
- super(arg0);
- }
-
- public static MockAbstractSelector openSelector() {
- return new MockAbstractSelector(SelectorProvider.provider());
- }
-
- public Set<SelectionKey> getCancelledKeys() {
- return super.cancelledKeys();
- }
-
- protected void implCloseSelector() throws IOException {
- isImplCloseSelectorCalled = true;
- }
-
- protected SelectionKey register(AbstractSelectableChannel arg0, int arg1,
- Object arg2) {
- isRegisterCalled = true;
-
- SelectionKey key = new MockSelectionKey(this, arg0);
- keys.add(key);
- return key;
- }
-
- public void superBegin() {
- super.begin();
- }
-
- public void superEnd() {
- super.end();
- }
-
- public void mockDeregister(AbstractSelectionKey key) {
- super.deregister(key);
- }
-
- public Set<SelectionKey> keys() {
- return keys;
- }
-
- public Set<SelectionKey> selectedKeys() {
- return null;
- }
-
- public int selectNow() throws IOException {
- return 0;
- }
-
- public int select(long arg0) throws IOException {
- return 0;
- }
-
- public int select() throws IOException {
- return 0;
- }
-
- public Selector wakeup() {
- return null;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
deleted file mode 100644
index 682c027..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/ASCIICharsetEncoderTest.java
+++ /dev/null
@@ -1,620 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.nio.charset.UnmappableCharacterException;
-
-import junit.framework.TestCase;
-@TestTargetClass(CharsetEncoder.class)
-public class ASCIICharsetEncoderTest extends TestCase {
-
- // charset for ascii
- private static final Charset cs = Charset.forName("ascii");
- private static final CharsetEncoder encoder = cs.newEncoder();
- private static final int MAXCODEPOINT = 0x7F;
- /*
- * @see CharsetEncoderTest#setUp()
- */
- protected void setUp() throws Exception {
- }
-
- /*
- * @see CharsetEncoderTest#tearDown()
- */
- protected void tearDown() throws Exception {
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed.",
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- )
- public void testCanEncodeCharSequence() {
- // normal case for ascCS
- assertTrue(encoder.canEncode("\u0077"));
- assertFalse(encoder.canEncode("\uc2a3"));
- assertFalse(encoder.canEncode("\ud800\udc00"));
- try {
- encoder.canEncode(null);
- } catch (NullPointerException e) {
- }
- assertTrue(encoder.canEncode(""));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed.",
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed.",
- method = "canEncode",
- args = {char.class}
- )
- })
- public void testCanEncodeSurrogate () {
- assertFalse(encoder.canEncode('\ud800'));
- assertFalse(encoder.canEncode("\udc00"));
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed.",
- method = "canEncode",
- args = {char.class}
- )
- public void testCanEncodechar() throws CharacterCodingException {
- assertTrue(encoder.canEncode('\u0077'));
- assertFalse(encoder.canEncode('\uc2a3'));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "averageBytesPerChar",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "maxBytesPerChar",
- args = {}
- )
- })
- public void testSpecificDefaultValue() {
- assertEquals(1.0, encoder.averageBytesPerChar(), 0.0);
- assertEquals(1.0, encoder.maxBytesPerChar(), 0.0);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class}
- )
- })
- public void testMultiStepEncode() throws CharacterCodingException {
- encoder.onMalformedInput(CodingErrorAction.REPORT);
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- try {
- encoder.encode(CharBuffer.wrap("\ud800\udc00"));
- fail("should unmappable");
- } catch (UnmappableCharacterException e) {
- }
- encoder.reset();
- ByteBuffer out = ByteBuffer.allocate(10);
- assertTrue(encoder.encode(CharBuffer.wrap("\ud800"), out, true)
- .isMalformed());
- encoder.flush(out);
- encoder.reset();
- out = ByteBuffer.allocate(10);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(CharBuffer
- .wrap("\ud800"), out, false));
- assertTrue(encoder.encode(CharBuffer.wrap("\udc00"), out, true)
- .isMalformed());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "encode",
- args = {java.nio.CharBuffer.class}
- )
- public void testEncodeMapping() throws CharacterCodingException {
- encoder.reset();
-
- for (int i =0; i <= MAXCODEPOINT; i++) {
- char[] chars = Character.toChars(i);
- CharBuffer cb = CharBuffer.wrap(chars);
- ByteBuffer bb = encoder.encode(cb);
- assertEquals(i, bb.get(0));
- }
-
- CharBuffer cb = CharBuffer.wrap("\u0080");
- try {
- encoder.encode(cb);
- } catch (UnmappableCharacterException e) {
- //expected
- }
-
- cb = CharBuffer.wrap("\ud800");
- try {
- encoder.encode(cb);
- } catch (MalformedInputException e) {
- //expected
- }
-
- ByteBuffer bb = ByteBuffer.allocate(0x10);
- cb = CharBuffer.wrap("A");
- encoder.reset();
- encoder.encode(cb, bb, false);
- try {
- encoder.encode(cb);
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "reset",
- args = {}
- )
- })
- public void testInternalState() {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
-
- //normal encoding process
- encoder.reset();
- encoder.encode(in, out, false);
- in = CharBuffer.wrap("B");
- encoder.encode(in, out, true);
- encoder.flush(out);
- }
-
- //reset could be called at any time
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks functionality. Exceptions checking missed.",
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testInternalState_Reset() {
- CharsetEncoder newEncoder = cs.newEncoder();
- //Init - > reset
- newEncoder.reset();
-
- //reset - > reset
- newEncoder.reset();
-
- //encoding - >reset
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- newEncoder.reset();
- }
-
- //encoding end -> reset
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.reset();
- }
- //flused -> reset
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.flush(out);
- newEncoder.reset();
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testInternalState_Encoding() {
- CharsetEncoder newEncoder = cs.newEncoder();
- //Init - > encoding
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- }
-
- //reset - > encoding
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.reset();
- newEncoder.encode(in, out, false);
- }
- //reset - > encoding - > encoding
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in, out, false);
- }
-
- //encoding_end - > encoding
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- in = CharBuffer.wrap("BC");
- try {
- newEncoder.encode(in, out, false);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- //expected
- }
- }
- //flushed - > encoding
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.flush(out);
- in = CharBuffer.wrap("BC");
- try {
- newEncoder.encode(in, out, false);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- //expected
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testInternalState_Encoding_END() {
- CharsetEncoder newEncoder = cs.newEncoder();
-
- //Init - >encoding_end
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- }
-
- //Reset -> encoding_end
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.reset();
- newEncoder.encode(in, out, true);
- }
-
- //encoding -> encoding_end
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in, out, true);
- }
-
- //Reset -> encoding_end
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in, out, true);
- }
-
- //Flushed -> encoding_end
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.flush(out);
- in = CharBuffer.wrap("BC");
- try {
- newEncoder.encode(in, out, true);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- //expected
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testInternalState_Flushed() {
- CharsetEncoder newEncoder = cs.newEncoder();
-
- //init -> flushed
- {
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.flush(out);
- }
-
- //reset - > flushed
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.reset();
- newEncoder.flush(out);
- }
-
- //encoding - > flushed
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- try {
-
- newEncoder.flush(out);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- //encoding_end -> flushed
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.flush(out);
- }
-
- //flushd - > flushed
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- newEncoder.flush(out);
- try {
- newEncoder.flush(out);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "encode",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "reset",
- args = {}
- )
- })
- public void testInternalState_Encode() throws CharacterCodingException {
- CharsetEncoder newEncoder = cs.newEncoder();
- //Init - > encode
- {
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- }
-
- //Reset - > encode
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- }
-
- //Encoding -> encode
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, false);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in);
- }
-
- //Encoding_end -> encode
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in);
- }
-
- //Flushed -> reset
- {
- newEncoder.reset();
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = ByteBuffer.allocate(0x10);
- newEncoder.encode(in, out, true);
- in = CharBuffer.wrap("BC");
- newEncoder.flush(out);
- out = newEncoder.encode(in);
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "CoderMalfunctionError checking missed.",
- method = "reset",
- args = {}
- )
- })
- public void testInternalState_from_Encode() throws CharacterCodingException {
- CharsetEncoder newEncoder = cs.newEncoder();
-
- //Encode -> Reset
- {
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- newEncoder.reset();
- }
-
- // Encode -> encoding
- {
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- ByteBuffer out = ByteBuffer.allocate(0x10);
- try {
- newEncoder.encode(in, out, false);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- //Encode -> Encoding_end
- {
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- ByteBuffer out = ByteBuffer.allocate(0x10);
- try {
- newEncoder.encode(in, out, true);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
- //Encode -> Flushed
- {
- CharBuffer in = CharBuffer.wrap("A");
- ByteBuffer out = newEncoder.encode(in);
- try {
- newEncoder.flush(out);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- //Encode - > encode
- {
- CharBuffer in = CharBuffer.wrap("A");
- newEncoder.encode(in);
- in = CharBuffer.wrap("BC");
- newEncoder.encode(in);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java
deleted file mode 100644
index 24b8efe..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/AllTests.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Test for org.apache.harmony.nio_char.tests.java.nio.charset");
- //$JUnit-BEGIN$
- suite.addTestSuite(ASCIICharsetEncoderTest.class);
- suite.addTestSuite(CharacterCodingExceptionTest.class);
- suite.addTestSuite(CharsetEncoderTest.class);
- suite.addTestSuite(CharsetTest.class);
- suite.addTestSuite(CharsetDecoderTest.class);
- suite.addTestSuite(MalformedInputExceptionTest.class);
- suite.addTestSuite(IllegalCharsetNameExceptionTest.class);
- suite.addTestSuite(UnmappableCharacterExceptionTest.class);
- suite.addTestSuite(UnsupportedCharsetExceptionTest.class);
- suite.addTestSuite(CoderMalfunctionErrorTest.class);
- //$JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java
deleted file mode 100644
index e232363..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharacterCodingExceptionTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.nio.charset.CharacterCodingException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(CharacterCodingException.class)
-/**
- * Test CharacterCodingException
- */
-public class CharacterCodingExceptionTest extends TestCase {
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CharacterCodingException",
- args = {}
- )
- public void testConstructor() {
- CharacterCodingException ex = new CharacterCodingException();
- assertTrue(ex instanceof IOException);
- assertNull(ex.getCause());
- assertNull(ex.getMessage());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new CharacterCodingException());
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- SerializationTest.verifyGolden(this, new CharacterCodingException());
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java
deleted file mode 100644
index 8e28ad1..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetDecoderTest.java
+++ /dev/null
@@ -1,323 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderMalfunctionError;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-@TestTargetClass(CharsetDecoder.class)
-public class CharsetDecoderTest extends TestCase {
-
- /**
- * @tests java.nio.charset.CharsetDecoder.CharsetDecoder(Charset, float,
- * float)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks IllegalArgumentException.",
- method = "CharsetDecoder",
- args = {java.nio.charset.Charset.class, float.class, float.class}
- )
- public void test_ConstructorLjava_nio_charset_CharsetFF() {
- // Regression for HARMONY-142
- try {
- Charset cs = Charset.forName("UTF-8");
- new MockCharsetDecoderForHarmony142(cs, 1.1f, 1);
- fail("Assert 0: Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /*
- * MockCharsetDecoderForHarmony142: for constructor test
- */
- static class MockCharsetDecoderForHarmony142 extends CharsetDecoder {
- protected MockCharsetDecoderForHarmony142(Charset cs,
- float averageBytesPerChar, float maxBytesPerChar) {
- super(cs, averageBytesPerChar, maxBytesPerChar);
- }
-
- protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
- return null;
- }
- }
-
- /**
- * @tests java.nio.charset.CharsetDecoder#decode(java.nio.ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test.",
- method = "decode",
- args = {java.nio.ByteBuffer.class}
- )
- public void test_decode() throws CharacterCodingException {
- // Regression for HARMONY-33
-// ByteBuffer bb = ByteBuffer.allocate(1);
-// bb.put(0, (byte) 77);
-// CharsetDecoder decoder = Charset.forName("UTF-16").newDecoder();
-// decoder.onMalformedInput(CodingErrorAction.REPLACE);
-// decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
-// decoder.decode(bb);
-
- // Regression for HARMONY-67
-// byte[] b = new byte[] { (byte) 1 };
-// ByteBuffer buf = ByteBuffer.wrap(b);
-// CharBuffer charbuf = Charset.forName("UTF-16").decode(buf);
-// assertEquals("Assert 0: charset UTF-16", 1, charbuf.length());
-//
-// charbuf = Charset.forName("UTF-16BE").decode(buf);
-// assertEquals("Assert 1: charset UTF-16BE", 0, charbuf.length());
-//
-// charbuf = Charset.forName("UTF-16LE").decode(buf);
-// assertEquals("Assert 2: charset UTF16LE", 0, charbuf.length());
-
- // Regression for HARMONY-99
- CharsetDecoder decoder2 = Charset.forName("UTF-16").newDecoder();
- decoder2.onMalformedInput(CodingErrorAction.REPORT);
- decoder2.onUnmappableCharacter(CodingErrorAction.REPORT);
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 109, 97, 109 });
- try {
- decoder2.decode(in);
- fail("Assert 3: MalformedInputException should have thrown");
- } catch (MalformedInputException e) {
- //expected
- }
- }
-
- /*
- * Test malfunction decode(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test. Checks CoderMalfunctionError",
- method = "decode",
- args = {java.nio.ByteBuffer.class}
- )
- public void test_decodeLjava_nio_ByteBuffer() throws Exception {
- MockMalfunctionCharset cs1 = new MockMalfunctionCharset(
- "Harmony-124-1", null);
- try {
- cs1.newDecoder().onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE).decode(
- ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
- fail("Assert 0: should throw CoderMalfunctionError");
- } catch (CoderMalfunctionError e) {
- // expected
- }
-
- MockMalfunctionCharset cs2 = new MockMalfunctionCharset(
- "Harmony-124-2", null);
- try {
- cs2.decode(ByteBuffer.wrap(new byte[] { 0x00, 0x11 }));
- fail("Assert 1: Charset.decode should throw CoderMalfunctionError");
- } catch (CoderMalfunctionError e) {
- // expected
- }
- }
-
- /*
- * Mock charset class with malfunction decode & encode.
- */
- static final class MockMalfunctionCharset extends Charset {
-
- public MockMalfunctionCharset(String canonicalName, String[] aliases) {
- super(canonicalName, aliases);
- }
-
- public boolean contains(Charset cs) {
- return false;
- }
-
- public CharsetDecoder newDecoder() {
- return new MockMalfunctionDecoder(this);
- }
-
- public CharsetEncoder newEncoder() {
- return new MockMalfunctionEncoder(this);
- }
- }
-
- /*
- * Mock decoder. decodeLoop always throws unexpected exception.
- */
- static class MockMalfunctionDecoder extends java.nio.charset.CharsetDecoder {
-
- public MockMalfunctionDecoder(Charset cs) {
- super(cs, 1, 10);
- }
-
- protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
- throw new BufferOverflowException();
- }
- }
-
- /*
- * Mock encoder. encodeLoop always throws unexpected exception.
- */
- static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
-
- public MockMalfunctionEncoder(Charset cs) {
- super(cs, 1, 3, new byte[] { (byte) '?' });
- }
-
- protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
- throw new BufferOverflowException();
- }
- }
-
- /*
- * Test the method decode(ByteBuffer) .
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "implOnMalformedInput",
- args = {java.nio.charset.CodingErrorAction.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "replaceWith",
- args = {java.lang.String.class}
- )
- })
- public void testDecodeLjava_nio_ByteBuffer_ReplaceOverflow()
- throws Exception {
- String replaceString = "a";
- Charset cs = Charset.forName("UTF-8");
- MockMalformedDecoder decoder = new MockMalformedDecoder(cs);
- decoder.onMalformedInput(CodingErrorAction.REPLACE);
- decoder.replaceWith(replaceString);
- CharBuffer out = CharBuffer.allocate(1);
- // MockMalformedDecoder treats the second byte '0x38' as malformed,
- // but "out" doesn't have enough space for replace string.
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 0x45, 0x38, 0x45, 0x45 });
- CoderResult result = decoder.decode(in, out, false);
- assertTrue(result.isOverflow());
-
- // allocate enough space for "out"
- out = CharBuffer.allocate(10);
- // replace string should be put into "out" firstly,
- // and then decode "in".
- result = decoder.decode(in, out, true);
- out.flip();
- assertTrue(result.isUnderflow());
- assertEquals("bb", out.toString());
- }
-
- /*
- * Mock decoder. It treats byte whose value is less than "0x40" as
- * malformed.
- */
- static class MockMalformedDecoder extends java.nio.charset.CharsetDecoder {
-
- public MockMalformedDecoder(Charset cs) {
- super(cs, 1, 10);
- }
-
- /*
- * It treats byte whose value is less than "0x40" as malformed.
- * Otherwise, it's decoded as 'b'.
- */
- protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
- while (in.hasRemaining()) {
- byte b = in.get();
- if (b < 0x40) {
- return CoderResult.malformedForLength(1);
- }
- if (!out.hasRemaining()) {
- return CoderResult.OVERFLOW;
- }
- out.put((char) 'b');
- }
- return CoderResult.UNDERFLOW;
- }
- }
-
-
- public void testInvalidDecoding() throws IOException {
-
- byte[][] invalidSequences = new byte[][] {
- // overlong NULL
- { (byte) 0xC0, (byte) 0x80 },
- // overlong ascii 'A'
- { (byte) 0xC0, (byte) 0xC1 },
- // overlong "/../"
- { (byte) 0x2F, (byte) 0xC0, (byte) 0xAE, (byte) 0x2E, (byte) 0x2F },
- // Invalid encoding 2r11111000 (sequence too long)
- { (byte) 0xF8 },
- // Invalid encoding 2r10000000 (sequence too short)
- { (byte) 0x80 }
- };
-
- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
- decoder.onMalformedInput(CodingErrorAction.REPORT);
-
- /*
- * When bytebuffer has a backing array...
- */
- for (byte[] bytes : invalidSequences) {
- try {
- decoder.decode(ByteBuffer.wrap(bytes));
- fail("No exception thrown on " + Arrays.toString(bytes));
- } catch (MalformedInputException e) {
- // expected
- }
- }
-
- /*
- * When bytebuffer has _not_ got a backing array...
- */
- for (byte[] bytes : invalidSequences) {
- try {
- ByteBuffer bb = ByteBuffer.allocateDirect(8);
- bb.put(bytes).flip();
- decoder.decode(bb);
- fail("No exception thrown on " + Arrays.toString(bytes));
- } catch (MalformedInputException e) {
- // expected
- }
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java
deleted file mode 100644
index 62fff39..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetEncoderTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.nio.BufferOverflowException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderMalfunctionError;
-import java.nio.charset.CoderResult;
-
-import junit.framework.TestCase;
-@TestTargetClass(CharsetEncoder.class)
-public class CharsetEncoderTest extends TestCase {
-
- /**
- * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
- * java.nio.charset.Charset, float, float)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IllegalArgumentException",
- method = "CharsetEncoder",
- args = {java.nio.charset.Charset.class, float.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IllegalArgumentException",
- method = "CharsetEncoder",
- args = {java.nio.charset.Charset.class, float.class, float.class, byte[].class}
- )
- })
- public void test_ConstructorLjava_nio_charset_CharsetFF() {
- // Regression for HARMONY-141
- try {
- Charset cs = Charset.forName("UTF-8");
- new MockCharsetEncoderForHarmony141(cs, 1.1f, 1);
- fail("Assert 0: Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Charset cs = Charset.forName("ISO8859-1");
- new MockCharsetEncoderForHarmony141(cs, 1.1f, 1,
- new byte[] { 0x1a });
- fail("Assert 1: Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.nio.charset.CharsetEncoder.CharsetEncoder(
- * java.nio.charset.Charset, float, float)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "CharsetEncoder",
- args = {java.nio.charset.Charset.class, float.class, float.class}
- )
- public void test_ConstructorLjava_nio_charset_CharsetNull() {
- // Regression for HARMONY-491
- CharsetEncoder ech = new MockCharsetEncoderForHarmony491(null, 1, 1);
- assertNull(ech.charset());
- }
-
- /**
- * Helper for constructor tests
- */
-
- public static class MockCharsetEncoderForHarmony141 extends CharsetEncoder {
-
- protected MockCharsetEncoderForHarmony141(Charset cs,
- float averageBytesPerChar, float maxBytesPerChar) {
- super(cs, averageBytesPerChar, maxBytesPerChar);
- }
-
- public MockCharsetEncoderForHarmony141(Charset cs,
- float averageBytesPerChar, float maxBytesPerChar,
- byte[] replacement) {
- super(cs, averageBytesPerChar, maxBytesPerChar, replacement);
- }
-
- protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
- return null;
- }
- }
-
- public static class MockCharsetEncoderForHarmony491 extends CharsetEncoder {
-
- public MockCharsetEncoderForHarmony491(Charset arg0, float arg1,
- float arg2) {
- super(arg0, arg1, arg2);
- }
-
- protected CoderResult encodeLoop(CharBuffer arg0, ByteBuffer arg1) {
- return null;
- }
-
- public boolean isLegalReplacement(byte[] arg0) {
- return true;
- }
- }
-
- /*
- * Test malfunction encode(CharBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test checks CoderMalfunctionError",
- method = "encode",
- args = {java.nio.CharBuffer.class}
- )
- public void test_EncodeLjava_nio_CharBuffer() throws Exception {
- MockMalfunctionCharset cs = new MockMalfunctionCharset("mock", null);
- try {
- cs.encode(CharBuffer.wrap("AB"));
- fail("should throw CoderMalfunctionError");
- } catch (CoderMalfunctionError e) {
- // expected
- }
- }
-
- /*
- * Mock charset class with malfunction decode & encode.
- */
- static final class MockMalfunctionCharset extends Charset {
-
- public MockMalfunctionCharset(String canonicalName, String[] aliases) {
- super(canonicalName, aliases);
- }
-
- public boolean contains(Charset cs) {
- return false;
- }
-
- public CharsetDecoder newDecoder() {
- return Charset.forName("UTF-8").newDecoder();
- }
-
- public CharsetEncoder newEncoder() {
- return new MockMalfunctionEncoder(this);
- }
- }
-
- /*
- * Mock encoder. encodeLoop always throws unexpected exception.
- */
- static class MockMalfunctionEncoder extends java.nio.charset.CharsetEncoder {
-
- public MockMalfunctionEncoder(Charset cs) {
- super(cs, 1, 3, new byte[] { (byte) '?' });
- }
-
- protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
- throw new BufferOverflowException();
- }
- }
-
- /*
- * Test reserve bytes encode(CharBuffer,ByteBuffer,boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Functional test.",
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void test_EncodeLjava_nio_CharBufferLjava_nio_ByteBufferB() {
- CharsetEncoder encoder = Charset.forName("utf-8").newEncoder();
- CharBuffer in1 = CharBuffer.wrap("\ud800");
- CharBuffer in2 = CharBuffer.wrap("\udc00");
- ByteBuffer out = ByteBuffer.allocate(4);
- encoder.reset();
- CoderResult result = encoder.encode(in1, out, false);
- assertEquals(4, out.remaining());
- assertTrue(result.isUnderflow());
- result = encoder.encode(in2, out, true);
- assertEquals(4, out.remaining());
- assertTrue(result.isMalformed());
- }
-
- /**
- * @tests {@link java.nio.charset.Charset#encode(java.nio.CharBuffer)
- */
- public void testUtf8Encoding() throws IOException {
- byte[] orig = new byte[] { (byte) 0xed, (byte) 0xa0,
- (byte) 0x80 };
- String s = new String(orig, "UTF-8");
- assertEquals(1, s.length());
- assertEquals(55296, s.charAt(0));
- Charset.forName("UTF-8").encode(CharBuffer.wrap(s));
-// ByteBuffer buf = <result>
-// for (byte o : orig) {
-// byte b = 0;
-// buf.get(b);
-// assertEquals(o, b);
-// }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
deleted file mode 100644
index 79a1b56..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CharsetTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import junit.framework.TestCase;
-
-import java.nio.charset.Charset;
-import java.nio.charset.IllegalCharsetNameException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-@TestTargetClass(Charset.class)
-public class CharsetTest extends TestCase {
-
- // Will contain names of charsets registered with IANA
- Set knownRegisteredCharsets = new HashSet();
-
- // Will contain names of charsets not known to be registered with IANA
- Set unknownRegisteredCharsets = new HashSet();
-
- /**
- * JUnit set-up method
- */
- public void setUp() {
-
- // Populate the known charset vars
- Set names = Charset.availableCharsets().keySet();
- for (Iterator nameItr = names.iterator(); nameItr.hasNext();) {
- String name = (String) nameItr.next();
- if (name.toLowerCase().startsWith("x-"))
- unknownRegisteredCharsets.add(name);
- else
- knownRegisteredCharsets.add(name);
- }
- }
-
- /**
- * @tests java.nio.charset.Charset#isRegistered()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isRegistered",
- args = {}
- )
- public void test_isRegistered() {
- // Regression for HARMONY-45
- for (Iterator nameItr = knownRegisteredCharsets.iterator(); nameItr.hasNext();) {
- String name = (String) nameItr.next();
- assertTrue("Assert 0: isRegistered() failed for " + name,
- Charset.forName(name).isRegistered());
- }
- for (Iterator nameItr = unknownRegisteredCharsets.iterator(); nameItr.hasNext();) {
- String name = (String) nameItr.next();
- assertFalse("Assert 0: isRegistered() failed for " + name,
- Charset.forName(name).isRegistered());
- }
- }
-
- /**
- * @tests java.nio.charset.Charset#isSupported(String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks IllegalCharsetNameException",
- method = "isSupported",
- args = {java.lang.String.class}
- )
- public void testIsSupported_EmptyString() {
- // Regression for HARMONY-113
- try {
- Charset.isSupported("");
- fail("Assert 0: Should throw IllegalCharsetNameException");
- } catch (IllegalCharsetNameException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.nio.charset.Charset#defaultCharset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "defaultCharset",
- args = {}
- )
- public void test_defaultCharset() {
- String charsetName = null;
- String defaultCharsetName = null;
- String oldDefaultEncoding = System.getProperty("file.encoding");
- try {
- // Normal behavior
- charsetName = "UTF-8";
- System.setProperty("file.encoding", charsetName);
- defaultCharsetName = Charset.defaultCharset().name();
- assertEquals(charsetName, defaultCharsetName);
-
- charsetName = "ISO-8859-1";
- System.setProperty("file.encoding", charsetName);
- defaultCharsetName = Charset.defaultCharset().name();
- assertEquals(charsetName, defaultCharsetName);
-
- // Unsupported behavior
- charsetName = "IMPOSSIBLE-8";
- System.setProperty("file.encoding", charsetName);
- defaultCharsetName = Charset.defaultCharset().name();
- assertEquals("UTF-8", defaultCharsetName);
-
- // Null behavior
- try {
- Properties currentProps = System.getProperties();
- currentProps.remove("file.encoding");
- Charset.defaultCharset().name();
- fail("Should throw illegal IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // IllegalCharsetName behavior
- try {
- charsetName = "IMP~~OSSIBLE-8";
- System.setProperty("file.encoding", charsetName);
- Charset.defaultCharset().name();
- fail("Should throw IllegalCharsetNameException");
- } catch (IllegalCharsetNameException e) {
- // expected
- }
- } finally {
- System.setProperty("file.encoding", oldDefaultEncoding);
- }
- }
-
- /**
- * @tests java.nio.charset.Charset#forName(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed.",
- method = "forName",
- args = {java.lang.String.class}
- )
- public void test_forNameLjava_lang_String() {
- /*
- * invoke forName two times with the same canonical name, it
- * should return the same reference.
- */
- Charset cs1 = Charset.forName("UTF-8");
- Charset cs2 = Charset.forName("UTF-8");
- assertSame(cs1, cs2);
-
- /*
- * test forName: invoke forName two times for the same Charset using
- * canonical name and alias, it should return the same reference.
- */
- Charset cs3 = Charset.forName("ASCII");
- Charset cs4 = Charset.forName("US-ASCII");
- assertSame(cs3, cs4);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java
deleted file mode 100644
index 28f758e..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/CoderMalfunctionErrorTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-
-import java.nio.charset.CoderMalfunctionError;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-@TestTargetClass(CoderMalfunctionError.class)
-/**
- * Test java.nio.CoderMalfunctionError.
- */
-public class CoderMalfunctionErrorTest extends TestCase {
-
- /*
- * Test constructor with normal param.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CoderMalfunctionError",
- args = {java.lang.Exception.class}
- )
- public void testConstructor_Normal() {
- Exception ex = new Exception();
- CoderMalfunctionError e = new CoderMalfunctionError(ex);
- assertSame(ex, e.getCause());
- }
-
- /*
- * Test constructor with null param.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CoderMalfunctionError",
- args = {java.lang.Exception.class}
- )
- public void testConstructor_Null() {
- CoderMalfunctionError e = new CoderMalfunctionError(null);
- assertNull(e.getCause());
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new CoderMalfunctionError(null));
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- SerializationTest.verifyGolden(this, new CoderMalfunctionError(null));
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java
deleted file mode 100644
index 10375e2..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/IllegalCharsetNameExceptionTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-
-import java.io.Serializable;
-import java.nio.charset.IllegalCharsetNameException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(IllegalCharsetNameException.class)
-/**
- * Test class IllegalCharsetNameException.
- */
-public class IllegalCharsetNameExceptionTest extends TestCase {
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "IllegalCharsetNameException",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCharsetName",
- args = {}
- )
- })
- public void testConstructor() {
- IllegalCharsetNameException ex = new IllegalCharsetNameException(
- "impossible");
- assertTrue(ex instanceof IllegalArgumentException);
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "impossible");
- assertTrue(ex.getMessage().indexOf("impossible") != -1);
-
- ex = new IllegalCharsetNameException("ascii");
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "ascii");
- assertTrue(ex.getMessage().indexOf("ascii") != -1);
-
- ex = new IllegalCharsetNameException("");
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "");
- ex.getMessage();
-
- ex = new IllegalCharsetNameException(null);
- assertNull(ex.getCause());
- assertNull(ex.getCharsetName());
- assertTrue(ex.getMessage().indexOf("null") != -1);
-
- }
-
- // comparator for IllegalCharsetNameException objects
- private static final SerializableAssert COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // FIXME?: getMessage() returns more helpful string but
- // this leads to incompatible message in serial form
- //
- // do common checks for all throwable objects
- // SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- // deserialized);
-
- IllegalCharsetNameException initEx = (IllegalCharsetNameException) initial;
- IllegalCharsetNameException desrEx = (IllegalCharsetNameException) deserialized;
-
- assertEquals("CharsetName", initEx.getCharsetName(), desrEx
- .getCharsetName());
- }
- };
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new IllegalCharsetNameException(
- "charsetName"), COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new IllegalCharsetNameException(
- "charsetName"), COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java
deleted file mode 100644
index 6e476af..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/MalformedInputExceptionTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.Serializable;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.MalformedInputException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(MalformedInputException.class)
-/**
- * Test class MalformedInputException.
- */
-public class MalformedInputExceptionTest extends TestCase {
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "MalformedInputException",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInputLength",
- args = {}
- )
- })
- public void testConstructor() {
- MalformedInputException ex = new MalformedInputException(3);
- assertTrue(ex instanceof CharacterCodingException);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), 3);
- assertTrue(ex.getMessage().indexOf("3") != -1);
-
- ex = new MalformedInputException(-3);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), -3);
- assertTrue(ex.getMessage().indexOf("-3") != -1);
-
- ex = new MalformedInputException(0);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), 0);
- assertTrue(ex.getMessage().indexOf("0") != -1);
- }
-
- // comparator for MalformedInputException objects
- private static final SerializableAssert COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- MalformedInputException initEx = (MalformedInputException) initial;
- MalformedInputException desrEx = (MalformedInputException) deserialized;
-
- assertEquals("InputLength", initEx.getInputLength(), desrEx
- .getInputLength());
- }
- };
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new MalformedInputException(11),
- COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new MalformedInputException(11),
- COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java
deleted file mode 100644
index b4a3b4c..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnmappableCharacterExceptionTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.Serializable;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.UnmappableCharacterException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(UnmappableCharacterException.class)
-/**
- * Test class UnmappableCharacterException.
- */
-public class UnmappableCharacterExceptionTest extends TestCase {
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "UnmappableCharacterException",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInputLength",
- args = {}
- )
- })
- public void testConstructor() {
- UnmappableCharacterException ex = new UnmappableCharacterException(3);
- assertTrue(ex instanceof CharacterCodingException);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), 3);
- assertTrue(ex.getMessage().indexOf("3") != -1);
-
- ex = new UnmappableCharacterException(-3);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), -3);
- assertTrue(ex.getMessage().indexOf("-3") != -1);
-
- ex = new UnmappableCharacterException(0);
- assertNull(ex.getCause());
- assertEquals(ex.getInputLength(), 0);
- assertTrue(ex.getMessage().indexOf("0") != -1);
-
- }
-
- // comparator for UnmappableCharacterException objects
- private static final SerializableAssert COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- UnmappableCharacterException initEx = (UnmappableCharacterException) initial;
- UnmappableCharacterException desrEx = (UnmappableCharacterException) deserialized;
-
- assertEquals("InputLength", initEx.getInputLength(), desrEx
- .getInputLength());
- }
- };
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnmappableCharacterException(11),
- COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new UnmappableCharacterException(
- 11), COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java
deleted file mode 100644
index 105e5e74..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/UnsupportedCharsetExceptionTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.Serializable;
-import java.nio.charset.UnsupportedCharsetException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(UnsupportedCharsetException.class)
-/**
- * Test class UnsupportedCharsetException.
- */
-public class UnsupportedCharsetExceptionTest extends TestCase {
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "UnsupportedCharsetException",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCharsetName",
- args = {}
- )
- })
- public void testConstructor() {
- UnsupportedCharsetException ex = new UnsupportedCharsetException(
- "impossible");
- assertTrue(ex instanceof IllegalArgumentException);
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "impossible");
- assertTrue(ex.getMessage().indexOf("impossible") != -1);
-
- ex = new UnsupportedCharsetException("ascii");
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "ascii");
- assertTrue(ex.getMessage().indexOf("ascii") != -1);
-
- ex = new UnsupportedCharsetException("");
- assertNull(ex.getCause());
- assertEquals(ex.getCharsetName(), "");
- ex.getMessage();
-
- ex = new UnsupportedCharsetException(null);
- assertNull(ex.getCause());
- assertNull(ex.getCharsetName());
- assertTrue(ex.getMessage().indexOf("null") != -1);
- }
-
- // comparator for UnsupportedCharsetException objects
- private static final SerializableAssert COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // FIXME?: getMessage() returns more helpful string but
- // this leads to incompatible message in serial form
- //
- // do common checks for all throwable objects
- // SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- // deserialized);
-
- UnsupportedCharsetException initEx = (UnsupportedCharsetException) initial;
- UnsupportedCharsetException desrEx = (UnsupportedCharsetException) deserialized;
-
- assertEquals("CharsetName", initEx.getCharsetName(), desrEx
- .getCharsetName());
- }
- };
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new UnsupportedCharsetException(
- "charsetName"), COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization.",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new UnsupportedCharsetException(
- "charsetName"), COMPARATOR);
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java
deleted file mode 100644
index 3aaf72b..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/AllTests.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset.spi;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Suite of tests for the java.nio.charset.spi package.");
- // $JUnit-BEGIN$
- suite.addTestSuite(CharsetProviderTest.class);
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java b/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java
deleted file mode 100644
index 66490c0..0000000
--- a/luni/src/test/java/org/apache/harmony/nio_char/tests/java/nio/charset/spi/CharsetProviderTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.nio_char.tests.java.nio.charset.spi;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.nio.charset.Charset;
-import java.nio.charset.spi.CharsetProvider;
-import java.security.Permission;
-import java.util.Iterator;
-
-import junit.framework.TestCase;
-@TestTargetClass(CharsetProvider.class)
-/**
- * Test class java.nio.charset.spi.CharsetProvider.
- */
-public class CharsetProviderTest extends TestCase {
-
- /*
- * Test the security check in the constructor.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "CharsetProvider",
- args = {}
- )
- public void testConstructor() {
- // with sufficient privilege
- new MockCharsetProvider();
- }
-
- /*
- * Test the signature.
- */
- static class MockCharsetProvider extends CharsetProvider {
-
- public Charset charsetForName(String charsetName) {
- return null;
- }
-
- public Iterator charsets() {
- return null;
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
deleted file mode 100644
index e605d6e..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
+++ /dev/null
@@ -1,1484 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import junit.framework.TestCase;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.prefs.AbstractPreferences;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.InvalidPreferencesFormatException;
-import java.util.prefs.NodeChangeEvent;
-import java.util.prefs.NodeChangeListener;
-import java.util.prefs.PreferenceChangeEvent;
-import java.util.prefs.PreferenceChangeListener;
-import java.util.prefs.Preferences;
-
-@TestTargetClass(AbstractPreferences.class)
-public class AbstractPreferencesTest extends TestCase {
-
- AbstractPreferences pref;
-
- static AbstractPreferences root;
-
- static final String nodeName = "mock";
-
- static AbstractPreferences parent = null;
-
- String oldUserHome = System.getProperty("user.home");
- String oldJavaHome = System.getProperty("java.home");
-
- protected void setUp() throws Exception {
- super.setUp();
-
- root = (AbstractPreferences) Preferences.userRoot();
- parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass());
-
- pref = (AbstractPreferences) parent.node(nodeName);
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- assertTrue(pref.toString().contains(nodeName));
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests putSpi indirectly",
- method = "put",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tests putSpi indirectly",
- method = "putSpi",
- args = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void testPut() throws BackingStoreException {
- pref.put("Value", "String");
- pref.flush();
-
- assertEquals("String", pref.get("Value", ":"));
-
- try {
- pref.put(null, "Exception");
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.put(new String(sb), "Exception");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_VALUE_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.put("DoubleValue", new String(sb));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.put("DoubleValue", "Exception");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "getSpi tested indirectly.",
- method = "get",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "getSpi tested indirectly.",
- method = "getSpi",
- args = {java.lang.String.class}
- )
- })
- public void testGet() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- assertEquals("String", pref.get("Value", ":"));
- assertEquals("true", pref.get("BoolValue", ":"));
- assertEquals("9.10938188E-31", pref.get("DoubleValue", null));
-
- try {
- pref.get(null, "Exception");
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.get("DoubleValue", "Exception");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirectly checks removeSpi",
- method = "remove",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirectly checks removeSpi",
- method = "removeSpi",
- args = {java.lang.String.class}
- )
- })
- public void testRemove() throws BackingStoreException {
- String[] keyArray = new String[]{"Value", "DoubleValue", "LongValue", "IntValue"};
- pref.put(keyArray[0], "String");
- pref.putDouble(keyArray[1], new Double(9.10938188e-31));
- pref.putLong(keyArray[2], new Long(Long.MIN_VALUE));
- pref.putInt(keyArray[3], 299792458);
- pref.node("New node");
- pref.flush();
-
- String[] str = pref.keys();
- assertEquals(keyArray.length, str.length);
- for(int i = 0; i < keyArray.length; i++) {
- pref.remove(keyArray[i]);
- str = pref.keys();
- assertEquals(keyArray.length - i - 1, str.length);
- }
- assertEquals(1, pref.childrenNames().length);
- pref.remove("New node");
- assertEquals(1, pref.childrenNames().length);
-
- pref.removeNode();
-
- try {
- pref.remove("New node");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "clear",
- args = {}
- )
- public void testClear() throws BackingStoreException {
- AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
- pref.putInt("IntValue", 33);
- pref.putBoolean("BoolValue", true);
- pref.flush();
- assertTrue(pref.getBoolean("BoolValue", false));
- assertEquals(33, pref.getInt("IntValue", 22));
- assertEquals(1, pref.childrenNames().length);
- pref.clear();
- assertFalse(pref.getBoolean("BoolValue", false));
- assertEquals(22, pref.getInt("IntValue", 22));
- assertEquals(1, pref.childrenNames().length);
-
- pref.removeNode();
-
- try {
- pref.clear();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
-
- try {
- ap.clear();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putInt",
- args = {java.lang.String.class, int.class}
- )
- public void testPutInt() throws BackingStoreException {
- pref.putInt("IntValue", 299792458);
- pref.flush();
-
- assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
-
- try {
- pref.putInt(null, new Integer(1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putInt(new String(sb), new Integer(1));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putInt("IntValue", new Integer(1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInt",
- args = {java.lang.String.class, int.class}
- )
- public void testGetInt() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putLong("LongValue", new Long(Long.MIN_VALUE));
- pref.putInt("IntValue", 299792458);
- pref.flush();
-
- assertEquals(1, pref.getInt("Value", new Integer(1)));
- assertEquals(1, pref.getInt("LongValue", new Integer(1)));
- assertEquals(1, pref.getInt("DoubleValue", new Integer(1)));
- assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
-
- try {
- pref.getInt(null, new Integer(1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getInt("IntValue", new Integer(1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putLong",
- args = {java.lang.String.class, long.class}
- )
- public void testPutLong() throws BackingStoreException {
- pref.putLong("LongValue", new Long(299792458));
- pref.flush();
-
- assertEquals(299792458L, pref.getLong("LongValue", new Long(1)));
-
- try {
- pref.putLong(null, new Long(1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putLong(new String(sb), new Long(1));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putLong("LongValue", new Long(1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLong",
- args = {java.lang.String.class, long.class}
- )
- public void testGetLong() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putLong("LongValue", new Long(Long.MIN_VALUE));
- pref.putInt("IntValue", 299792458);
- pref.flush();
-
- assertEquals(1L, pref.getLong("Value", new Long(1)));
- assertEquals(Long.MIN_VALUE, pref.getLong("LongValue", new Long(1)));
- assertEquals(1L, pref.getLong("DoubleValue", new Long(1)));
- assertEquals(299792458L, pref.getLong("IntValue", new Long(1)));
-
- try {
- pref.getLong(null, new Long(1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getLong("LongValue", new Long(1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putBoolean",
- args = {java.lang.String.class, boolean.class}
- )
- public void testPutBoolean() throws BackingStoreException {
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- assertTrue(pref.getBoolean("BoolValue", false));
-
- try {
- pref.putBoolean(null, true);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putBoolean(new String(sb), true);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putBoolean("DoubleValue", true);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBoolean",
- args = {java.lang.String.class, boolean.class}
- )
- public void testGetBoolean() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- assertFalse(pref.getBoolean("Value", false));
- assertTrue(pref.getBoolean("BoolValue", false));
- assertFalse(pref.getBoolean("DoubleValue", false));
-
- try {
- pref.getBoolean(null, true);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getBoolean("DoubleValue", true);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putFloat",
- args = {java.lang.String.class, float.class}
- )
- public void testPutFloat() throws BackingStoreException {
- pref.putFloat("FloatValue", new Float(1.602e-19));
- pref.flush();
-
- assertEquals(new Float(1.602e-19), pref.getFloat("FloatValue", new Float(0.2)));
-
- try {
- pref.putFloat(null, new Float(0.1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putFloat(new String(sb), new Float(0.1));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putFloat("FloatValue", new Float(0.1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getFloat",
- args = {java.lang.String.class, float.class}
- )
- public void testGetFloat() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putFloat("FloatValue", new Float(-0.123));
- pref.putInt("IntValue", 299792458);
- pref.flush();
-
- assertEquals(new Float(0.1), pref.getFloat("Value", new Float(0.1)));
- assertEquals(new Float(-0.123), pref.getFloat("FloatValue", new Float(0.2)));
- assertEquals(new Float(9.109382e-31), pref.getFloat("DoubleValue", new Float(2.14)));
- assertEquals(new Float(2.99792448e8), pref.getFloat("IntValue", new Float(5)));
-
- try {
- pref.getFloat(null, new Float(0.1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getFloat("FloatValue", new Float(0.1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putDouble",
- args = {java.lang.String.class, double.class}
- )
- public void testPutDouble() throws BackingStoreException {
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.flush();
-
- assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
-
- try {
- pref.putDouble(null, new Double(0.1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- int i;
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putDouble(new String(sb), new Double(0.1));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putDouble("DoubleValue", new Double(0.1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDouble",
- args = {java.lang.String.class, double.class}
- )
- public void testGetDouble() throws BackingStoreException {
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putBoolean("BoolValue", true);
- pref.putInt("IntValue", 299792458);
- pref.flush();
-
- assertEquals(new Double(0.1), pref.getDouble("Value", new Double(0.1)));
- assertEquals(new Double(0.2), pref.getDouble("BoolValue", new Double(0.2)));
- assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
- assertEquals(new Double(2.99792458e8), pref.getDouble("IntValue", new Double(5)));
-
- try {
- pref.getDouble(null, new Double(0.1));
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getDouble("DoubleValue", new Double(0.1));
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "putByteArray",
- args = {java.lang.String.class, byte[].class}
- )
- public void testPutByteArray() throws BackingStoreException {
- byte[] bArray = new byte[]{1, 2, 3, 4, 5};
- byte[] array = null;
- int i;
- pref.putByteArray("Array", bArray);
- pref.flush();
-
- array = pref.getByteArray("Array", null);
- assertEquals(bArray.length, array.length);
- for(i = 0; i < bArray.length; i++) {
- assertEquals(bArray[i], array[i]);
- }
-
- try {
- pref.putByteArray(null, bArray);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- StringBuffer sb = new StringBuffer();
-
- for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
- sb.append('c');
- }
-
- try {
- pref.putByteArray(new String(sb), bArray);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- bArray = new byte[Preferences.MAX_VALUE_LENGTH * 3 / 4 + 1];
-
- try {
- pref.putByteArray("Big array", bArray);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.putByteArray("Array", new byte[10]);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getByteArray",
- args = {java.lang.String.class, byte[].class}
- )
- public void testGetByteArray() throws BackingStoreException {
- byte[] bArray = new byte[]{1, 2, 3, 4, 5};
- byte[] tmp = new byte[]{5};
- byte[] array = null;
- int i;
- pref.put("Value", "String");
- pref.putDouble("DoubleValue", new Double(9.10938188e-31));
- pref.putByteArray("Array", bArray);
- pref.flush();
-
- array = pref.getByteArray("Value", tmp);
- assertEquals(tmp.length, array.length);
- for(i = 0; i < tmp.length; i++) {
- assertEquals(tmp[i], array[i]);
- }
-
- array = pref.getByteArray("DoubleValue", tmp);
- assertEquals(tmp.length, array.length);
- for(i = 0; i < tmp.length; i++) {
- assertEquals(tmp[i], array[i]);
- }
-
- array = pref.getByteArray("Array", tmp);
- assertEquals(bArray.length, array.length);
- for(i = 0; i < bArray.length; i++) {
- assertEquals(bArray[i], array[i]);
- }
-
- try {
- pref.getByteArray(null, tmp);
- fail("NullPointerException expected");
- } catch (NullPointerException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.getByteArray("Array", tmp);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "keysSpi tested indirectly",
- method = "keys",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "keysSpi tested indirectly",
- method = "keysSpi",
- args = {}
- )
- })
- public void testKeys() throws BackingStoreException {
- String[] keyArray = new String[]{"Value", "DoubleValue", "BoolValue", "IntValue"};
- String nodeStr = "New node";
- pref.node(nodeStr);
- pref.put(keyArray[0], "String");
- pref.putDouble(keyArray[1], new Double(9.10938188e-31));
- pref.putBoolean(keyArray[2], true);
- pref.putInt(keyArray[3], 299792458);
- pref.flush();
-
- String[] str = pref.keys();
- assertEquals(keyArray.length, str.length);
- for(int i = 0; i < str.length; i++) {
- boolean flag = false;
- for(int j = 0; j < keyArray.length; j++) {
- if (str[i].compareTo(keyArray[j]) == 0) {
- flag = true;
- break;
- }
- }
- assertTrue(str[i].compareTo(nodeStr) != 0);
- assertTrue(flag);
- }
-
- pref.removeNode();
-
- try {
- pref.keys();
- fail("IllegalStateException expected");
- } catch(IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException can not be checked. childrenNamesSpi checked indirectly.",
- method = "childrenNames",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException can not be checked. childrenNamesSpi checked indirectly.",
- method = "childrenNamesSpi",
- args = {}
- )
- })
- public void testChildrenNames() throws BackingStoreException {
- AbstractPreferences first = (AbstractPreferences) pref.node("First node");
- AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
-
- assertEquals(2, pref.childrenNames().length);
- assertEquals(0, first.childrenNames().length);
- assertEquals(0, second.childrenNames().length);
-
- second.removeNode();
-
- try {
- second.childrenNames();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- first.childrenNames();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nodeExists",
- args = {String.class}
- )
- public void test_nodeExists() throws BackingStoreException {
- AbstractPreferences test = (AbstractPreferences) Preferences.userRoot()
- .node("test");
- try {
- test.nodeExists(null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
-
- test.removeNode();
- try {
- test.nodeExists(null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parent",
- args = {}
- )
- public void testParent() throws BackingStoreException {
- AbstractPreferences node = (AbstractPreferences) pref.node("First node/sub node");
-
- assertTrue(node.parent().name().compareTo("First node") == 0);
-
- pref.removeNode();
-
- try {
- node.parent();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirecly checks childSpi",
- method = "node",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirecly checks childSpi",
- method = "childSpi",
- args = {java.lang.String.class}
- )
- })
- public void testNode() throws BackingStoreException {
- AbstractPreferences first = (AbstractPreferences) pref.node("First node");
- AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
-
- try {
- first.node("blabla/");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try {
- first.node("///invalid");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- StringBuffer sb = new StringBuffer();
-
- for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
- sb.append('c');
- }
- first.node(new String(sb));
- sb.append('c');
-
- try {
- first.node(new String(sb));
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- second.removeNode();
-
- try {
- second.node("");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- pref.removeNode();
- try {
- first.node("");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "getChild tested indirectly",
- method = "nodeExists",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "getChild tested indirectly",
- method = "getChild",
- args = {java.lang.String.class}
- )
- })
- public void testNodeExists() throws BackingStoreException {
- AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
- AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
- pref.putInt("IntegerValue", 33);
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- assertTrue(pref.nodeExists("First node"));
- assertTrue(pref.nodeExists("Second node"));
- assertFalse(pref.nodeExists("IntegerValue"));
- assertFalse(pref.nodeExists("BoolValue"));
- assertFalse(pref.nodeExists("Value"));
- assertFalse(pref.nodeExists(nodeName));
-
- try {
- pref.nodeExists("///invalid");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- pref.removeNode();
-
- try {
- pref.nodeExists("Exception");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "removeNode",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "removeNodeSpi",
- args = {}
- )
- })
- public void testRemoveNode() throws BackingStoreException {
- String[] nodeArray = new String[]{"First node", "Second node", "Last node"};
- int i;
- pref.put("Key", "String");
- for (i = 0; i < nodeArray.length; i++) {
- pref.node(nodeArray[i]);
- }
- pref.flush();
-
- String[] str = pref.childrenNames();
- assertEquals(nodeArray.length, str.length);
- for(i = 0; i < nodeArray.length; i++) {
- pref.node(nodeArray[i]).removeNode();
- str = pref.childrenNames();
- assertEquals(nodeArray.length - i - 1, str.length);
- }
- assertEquals(1, pref.keys().length);
- pref.node("Key").removeNode();
- assertEquals(1, pref.keys().length);
-
- pref.removeNode();
-
- try {
- pref.removeNode();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
-
- try {
- root.removeNode();
- fail("UnsupportedOperationException expected");
- } catch (UnsupportedOperationException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "name",
- args = {}
- )
- public void testName() {
- AbstractPreferences first = (AbstractPreferences) pref.node("First node");
- AbstractPreferences second = (AbstractPreferences) pref.node("Second node/sub node");
-
- assertTrue(first.name().compareTo("First node") == 0);
- assertFalse(first.name().compareTo("Second node") == 0);
- assertTrue(second.name().compareTo("sub node") == 0);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "absolutePath",
- args = {}
- )
- public void testAbsolutePath() {
- assertEquals(parent.absolutePath() + "/" + nodeName, pref.absolutePath());
- assertEquals(parent.absolutePath() + "/" + "new node", parent.node("new node").absolutePath());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isUserNode",
- args = {}
- )
- public void testIsUserNode() {
- assertTrue(parent.isUserNode());
- assertFalse(Preferences.systemRoot().isUserNode());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirectly checks syncSpi",
- method = "sync",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Indirectly checks syncSpi",
- method = "syncSpi",
- args = {}
- )
- })
- public void testSync() throws BackingStoreException {
- pref.node("new node/sub node");
- pref.sync();
-
- pref.removeNode();
-
- try {
- pref.sync();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- class MockPreferenceChangeListener implements PreferenceChangeListener {
- private boolean flagChange = false;
-
- public void preferenceChange(PreferenceChangeEvent arg0) {
- flagChange = true;
- }
-
- public boolean isChanged () {
- boolean retVal = flagChange;
- flagChange = false;
- return retVal;
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "addPreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- )
- public void testAddPreferenceChangeListener() throws BackingStoreException {
- MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
- parent.addPreferenceChangeListener(mpcl);
- assertFalse(mpcl.isChanged());
- pref.node("new node");
- pref.flush();
- parent.flush();
- assertFalse(mpcl.isChanged());
- parent.node("new node");
- parent.flush();
- assertFalse(mpcl.isChanged());
- parent.putInt("IntValue", 33);
- parent.flush();
- parent.flush();
- assertTrue(mpcl.isChanged());
- assertEquals(33, parent.getInt("IntValue", 22));
- parent.flush();
- assertFalse(mpcl.isChanged());
- assertEquals(22, parent.getInt("Missed Value", 22));
- parent.flush();
- assertFalse(mpcl.isChanged());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "removePreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- )
- public void testRemovePreferenceChangeListener() throws BackingStoreException {
- MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
- parent.addPreferenceChangeListener(mpcl);
- assertFalse(mpcl.isChanged());
- parent.putInt("IntValue", 33);
- parent.flush();
- assertTrue(mpcl.isChanged());
- parent.removePreferenceChangeListener(mpcl);
- parent.putInt("IntValue", 33);
- parent.flush();
- assertFalse(mpcl.isChanged());
- }
-
- class MockNodeChangeListener implements NodeChangeListener {
- private boolean flagAdded = false;
- private boolean flagRemoved = false;
-
- public void childAdded(NodeChangeEvent arg0) {
- flagAdded = true;
- }
-
- public void childRemoved(NodeChangeEvent arg0) {
- flagRemoved = true;
- }
-
- public boolean isAdded() {
- return flagAdded;
- }
-
- public boolean isRemoved() {
- return flagRemoved;
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "addNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- )
- public void testAddNodeChangeListener() throws BackingStoreException {
- MockNodeChangeListener mncl = new MockNodeChangeListener();
- parent.addNodeChangeListener(mncl);
- pref.node("test");
- pref.flush();
- parent.flush();
- assertFalse(mncl.isAdded());
- assertFalse(mncl.isRemoved());
- pref.removeNode();
- parent.flush();
- assertFalse(mncl.isAdded());
- assertTrue(mncl.isRemoved());
- parent.node("new node");
- parent.flush();
- assertTrue(mncl.isAdded());
- assertTrue(mncl.isRemoved());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "removeNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- )
- public void testRemoveNodeChangeListener() throws BackingStoreException {
- MockNodeChangeListener mncl = new MockNodeChangeListener();
- parent.addNodeChangeListener(mncl);
- pref.node("test");
- pref.flush();
- parent.flush();
- assertFalse(mncl.isAdded());
- assertFalse(mncl.isRemoved());
- parent.removeNodeChangeListener(mncl);
- pref.removeNode();
- parent.flush();
- assertFalse(mncl.isAdded());
- assertFalse(mncl.isRemoved());
- parent.node("new node");
- parent.flush();
- assertFalse(mncl.isAdded());
- assertFalse(mncl.isRemoved());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "exportNode",
- args = {java.io.OutputStream.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "flush",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "flushSpi",
- args = {}
- )
- })
- public void testExportNode() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
- AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
- pref.putInt("IntValue", 33);
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- pref.exportNode(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- assertTrue(pref.getBoolean("BoolValue", false));
- assertEquals(33, pref.getInt("IntValue", 22));
- assertEquals(1, pref.childrenNames().length);
-
- String xmlData = new String(baos.toByteArray());
-
- assertTrue(xmlData.contains("IntValue"));
- assertTrue(xmlData.contains("BoolValue"));
- assertTrue(xmlData.contains("33"));
- assertTrue(xmlData.contains("true"));
-
- pref.removeNode();
-
- try {
- pref.exportNode(new ByteArrayOutputStream());
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
-
- try {
- pref.getBoolean("BoolValue", false);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- pref = (AbstractPreferences) parent.node(nodeName);
-
- pref.importPreferences(bais);
-
- assertTrue(pref.getBoolean("BoolValue", false));
- assertEquals(33, pref.getInt("IntValue", 22));
- assertEquals(0, pref.childrenNames().length);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "exportSubtree",
- args = {java.io.OutputStream.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "flush",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "BackingStoreException, IOException can not be checked.",
- method = "flushSpi",
- args = {}
- )
- })
- public void testExportSubtree() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
- AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
- AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
- pref.putInt("IntegerValue", 33);
- pref.putBoolean("BoolValue", true);
- pref.flush();
-
- ap1.putInt("FirstIntValue", 11);
- ap2.putDouble("DoubleValue", new Double(6.626e-34));
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
- pref.exportSubtree(baos);
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
- assertTrue(pref.getBoolean("BoolValue", false));
- assertEquals(33, pref.getInt("IntegerValue", 22));
- assertEquals(2, pref.childrenNames().length);
- assertEquals(11, ap1.getInt("FirstIntValue", 22));
- assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
-
- String xmlData = new String(baos.toByteArray());
-
- assertTrue(xmlData.contains("IntegerValue"));
- assertTrue(xmlData.contains("BoolValue"));
- assertTrue(xmlData.contains("FirstIntValue"));
- assertTrue(xmlData.contains("DoubleValue"));
- assertTrue(xmlData.contains("33"));
- assertTrue(xmlData.contains("true"));
- assertTrue(xmlData.contains("11"));
- assertTrue(xmlData.contains("6.626E-34"));
-
- pref.removeNode();
-
- try {
- pref.exportSubtree(new ByteArrayOutputStream());
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
-
- try {
- pref.getBoolean("BoolValue", false);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- pref = (AbstractPreferences) parent.node(nodeName);
- pref.importPreferences(bais);
-
- ap1 = (AbstractPreferences) pref.node("First node");
- ap2 = (AbstractPreferences) pref.node("Second node");
-
- assertTrue(pref.getBoolean("BoolValue", false));
- assertEquals(33, pref.getInt("IntegerValue", 22));
- assertEquals(2, pref.childrenNames().length);
- assertEquals(11, ap1.getInt("FirstIntValue", 22));
- assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
- }
-
- class MockAbstractPreferences extends AbstractPreferences {
- protected MockAbstractPreferences(AbstractPreferences parent, String name) {
- super(parent, name);
- }
-
- @Override
- protected AbstractPreferences childSpi(String name) {
- return null;
- }
-
- @Override
- protected String[] childrenNamesSpi() throws BackingStoreException {
- return null;
- }
-
- @Override
- protected void flushSpi() throws BackingStoreException {
- }
-
- @Override
- protected String getSpi(String key) {
- return null;
- }
-
- @Override
- protected String[] keysSpi() throws BackingStoreException {
- return null;
- }
-
- @Override
- protected void putSpi(String key, String value) {
- }
-
- @Override
- protected void removeNodeSpi() throws BackingStoreException {
- }
-
- @Override
- protected void removeSpi(String key) {
- }
-
- @Override
- protected void syncSpi() throws BackingStoreException {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "AbstractPreferences",
- args = {java.util.prefs.AbstractPreferences.class, java.lang.String.class}
- )
- public void testAbstractPreferences() {
- assertNotNull(new MockAbstractPreferences(pref, "node name"));
- try {
- new MockAbstractPreferences(pref, "node/name");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try {
- new MockAbstractPreferences(null, "node");
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Tested indirectly",
- method = "cachedChildren",
- args = {}
- )
- public void testCachedChildren() throws BackingStoreException {
- pref.node("First node");
- pref.node("Second node");
-
- assertEquals(2, pref.childrenNames().length);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "No reason to check dummy implementation",
- method = "isRemoved",
- args = {}
- )
- public void testIsRemoved() {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
deleted file mode 100644
index 503d21a..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Suite for package org.apache.harmony.prefs.tests.java.util.prefs
- *
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("Suite for org.apache.harmony.prefs.tests.java.util.prefs");
- // $JUnit-BEGIN$
- suite.addTestSuite(NodeChangeListenerTest.class);
- suite.addTestSuite(PreferenceChangeListenerTest.class);
- suite.addTestSuite(PreferencesFactoryTest.class);
- suite.addTestSuite(BackingStoreExceptionTest.class);
- suite.addTestSuite(InvalidPreferencesFormatExceptionTest.class);
- suite.addTestSuite(PreferenceChangeEventTest.class);
- suite.addTestSuite(NodeChangeEventTest.class);
- suite.addTestSuite(PreferencesTest.class);
- suite.addTestSuite(AbstractPreferencesTest.class);
- suite.addTestSuite(FilePreferencesImplTest.class);
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java
deleted file mode 100644
index 17c8622..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.util.prefs.BackingStoreException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- *
- *
- */
-@TestTargetClass(BackingStoreException.class)
-public class BackingStoreExceptionTest extends TestCase {
-
- /*
- * Class under test for void BackingStoreException(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BackingStoreException",
- args = {java.lang.String.class}
- )
- public void testBackingStoreExceptionString() {
- BackingStoreException e = new BackingStoreException("msg");
- assertNull(e.getCause());
- assertEquals("msg", e.getMessage());
- }
-
- /*
- * Class under test for void BackingStoreException(Throwable)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BackingStoreException",
- args = {java.lang.Throwable.class}
- )
- public void testBackingStoreExceptionThrowable() {
- Throwable t = new Throwable("msg");
- BackingStoreException e = new BackingStoreException(t);
- assertTrue(e.getMessage().indexOf(t.getClass().getName()) >= 0);
- assertTrue(e.getMessage().indexOf("msg") >= 0);
- assertEquals(t, e.getCause());
- }
-
- /**
- * @tests serialization/deserialization.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new BackingStoreException("msg"));
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this, new BackingStoreException("msg"));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
deleted file mode 100644
index 70c837e..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import junit.framework.TestCase;
-
-import java.io.FilePermission;
-import java.security.Permission;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
-
-@TestTargetClass(java.util.prefs.Preferences.class)
-public class FilePreferencesImplTest extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "put",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "get",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "keys",
- args = {}
- )
- })
- public void testUserPutGet() throws BackingStoreException {
- Preferences uroot = Preferences.userRoot().node("test");
- uroot.put("ukey1", "value1");
- assertEquals("value1", uroot.get("ukey1", null));
- String[] names = uroot.keys();
- assertTrue(names.length >= 1);
-
- uroot.put("ukey2", "value3");
- assertEquals("value3", uroot.get("ukey2", null));
- uroot.put("\u4e2d key1", "\u4e2d value1");
- assertEquals("\u4e2d value1", uroot.get("\u4e2d key1", null));
- names = uroot.keys();
- assertEquals(3, names.length);
-
- uroot.clear();
- names = uroot.keys();
- assertEquals(0, names.length);
- uroot.removeNode();
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "put",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "get",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "keys",
- args = {}
- )
- })
- public void testSystemPutGet() throws BackingStoreException {
- Preferences sroot = Preferences.systemRoot().node("test");
- sroot.put("skey1", "value1");
- assertEquals("value1", sroot.get("skey1", null));
- sroot.put("\u4e2d key1", "\u4e2d value1");
- assertEquals("\u4e2d value1", sroot.get("\u4e2d key1", null));
- sroot.removeNode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "childrenNames",
- args = {}
- )
- public void testUserChildNodes() throws Exception {
- Preferences uroot = Preferences.userRoot().node("test");
-
- Preferences child1 = uroot.node("child1");
- Preferences child2 = uroot.node("\u4e2d child2");
- Preferences grandchild = child1.node("grand");
- assertNotNull(grandchild);
-
- String[] childNames = uroot.childrenNames();
- assertContains(childNames, "child1");
- assertContains(childNames, "\u4e2d child2");
- assertNotContains(childNames, "grand");
-
- childNames = child1.childrenNames();
- assertContains(childNames, "grand");
-
- childNames = child2.childrenNames();
- assertEquals(0, childNames.length);
-
- child1.removeNode();
- childNames = uroot.childrenNames();
- assertNotContains(childNames, "child1");
- assertContains(childNames, "\u4e2d child2");
- assertNotContains(childNames, "grand");
-
- child2.removeNode();
- childNames = uroot.childrenNames();
- assertNotContains(childNames, "child1");
- assertNotContains(childNames, "\u4e2d child2");
- assertNotContains(childNames, "grand");
-
- uroot.removeNode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "childrenNames",
- args = {}
- )
- @AndroidOnly("It seems like the RI can't remove nodes created in the system root.")
- public void testSystemChildNodes() throws Exception {
- Preferences sroot = Preferences.systemRoot().node("test");
-
- Preferences child1 = sroot.node("child1");
- Preferences child2 = sroot.node("child2");
- Preferences grandchild = child1.node("grand");
-
- String[] childNames = sroot.childrenNames();
- assertContains(childNames, "child1");
- assertContains(childNames, "child2");
- assertNotContains(childNames, "grand");
-
- childNames = child1.childrenNames();
- assertEquals(1, childNames.length);
-
- childNames = child2.childrenNames();
- assertEquals(0, childNames.length);
-
- child1.removeNode();
- childNames = sroot.childrenNames();
- assertNotContains(childNames, "child1");
- assertContains(childNames, "child2");
- assertNotContains(childNames, "grand");
-
- child2.removeNode();
- childNames = sroot.childrenNames();
- assertNotContains(childNames, "child1");
- assertNotContains(childNames, "child2");
- assertNotContains(childNames, "grand");
- sroot.removeNode();
- }
-
- private void assertContains(String[] childNames, String name) {
- for (String childName : childNames) {
- if (childName == name) {
- return;
- }
- }
- fail("No child with name " + name + " was found. It was expected to exist.");
- }
-
- private void assertNotContains(String[] childNames, String name) {
- for (String childName : childNames) {
- if (childName == name) {
- fail("Child with name " + name + " was found. This was unexpected.");
- }
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
deleted file mode 100644
index a12da0d..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.util.prefs.InvalidPreferencesFormatException;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-/**
- *
- */
-@TestTargetClass(InvalidPreferencesFormatException.class)
-public class InvalidPreferencesFormatExceptionTest extends TestCase {
-
- /*
- * Class under test for void InvalidPreferencesFormatException(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidPreferencesFormatException",
- args = {java.lang.String.class}
- )
- public void testInvalidPreferencesFormatExceptionString() {
- InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
- "msg");
- assertNull(e.getCause());
- assertEquals("msg", e.getMessage());
- }
-
- /*
- * Class under test for void InvalidPreferencesFormatException(String,
- * Throwable)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidPreferencesFormatException",
- args = {java.lang.String.class, java.lang.Throwable.class}
- )
- public void testInvalidPreferencesFormatExceptionStringThrowable() {
- Throwable t = new Throwable("root");
- InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
- "msg", t);
- assertSame(t, e.getCause());
- assertTrue(e.getMessage().indexOf("root") < 0);
- assertTrue(e.getMessage().indexOf(t.getClass().getName()) < 0);
- assertTrue(e.getMessage().indexOf("msg") >= 0);
- }
-
- /*
- * Class under test for void InvalidPreferencesFormatException(Throwable)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidPreferencesFormatException",
- args = {java.lang.Throwable.class}
- )
- public void testInvalidPreferencesFormatExceptionThrowable() {
- Throwable t = new Throwable("root");
- InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
- t);
- assertSame(t, e.getCause());
- assertTrue(e.getMessage().indexOf("root") >= 0);
- assertTrue(e.getMessage().indexOf(t.getClass().getName()) >= 0);
- }
-
- /**
- * @tests serialization/deserialization.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
-
- SerializationTest.verifySelf(new InvalidPreferencesFormatException(
- "msg"));
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SerializationTest.verifyGolden(this,
- new InvalidPreferencesFormatException("msg"));
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
deleted file mode 100644
index 7d66246..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockAbstractPreferences.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.prefs.AbstractPreferences;
-import java.util.prefs.BackingStoreException;
-
-public class MockAbstractPreferences extends AbstractPreferences {
- static final int NORMAL = 0;
-
- static final int backingException = 1;
-
- static final int runtimeException = 2;
-
- static final int returnNull = 3;
-
- int result = NORMAL;
-
- Properties attr = new Properties();
-
- Map<String, MockAbstractPreferences> childs = new HashMap<String, MockAbstractPreferences>();
-
- private int flushedTimes;
-
- private int syncTimes;
-
- protected MockAbstractPreferences(AbstractPreferences parent, String name) {
- this(parent, name, false);
-
- }
-
- protected MockAbstractPreferences(AbstractPreferences parent, String name,
- boolean newNode) {
- super(parent, name);
- super.newNode = newNode;
- if (parent instanceof MockAbstractPreferences) {
- ((MockAbstractPreferences) parent).addChild(this);
- }
- }
-
- public int getFlushedTimes() {
- return flushedTimes;
- }
-
- public void resetFlushedTimes() {
- flushedTimes = 0;
- }
-
- public int getSyncTimes() {
- return syncTimes;
- }
-
- public void resetSyncTimes() {
- syncTimes = 0;
- }
-
- private void addChild(MockAbstractPreferences c) {
- childs.put(c.name(), c);
- }
-
- public void setResult(int r) {
- result = r;
- }
-
- public Object lock() {
- return lock;
- }
-
- @Override
- public String[] childrenNamesSpi() throws BackingStoreException {
- checkException();
- if (result == returnNull)
- return null;
- String[] r = new String[childs.size()];
- childs.keySet().toArray(r);
- return r;
- }
-
- private void checkException() throws BackingStoreException {
- switch (result) {
- case NORMAL:
- return;
- case backingException:
- throw new BackingStoreException("test");
- case runtimeException:
- throw new MockRuntimeException("test");
- }
- }
-
- public AbstractPreferences publicChildSpi(String name) {
- return childSpi(name);
- }
-
- @Override
- public AbstractPreferences childSpi(String name) {
- try {
- checkException();
- } catch (BackingStoreException e) {
- }
- if (result == returnNull)
- return null;
- AbstractPreferences r = childs.get(name);
- if (r == null) {
- r = new MockAbstractPreferences(this, name, true);
-
- }
- return r;
- }
-
- @Override
- public void flushSpi() throws BackingStoreException {
- checkException();
- flushedTimes++;
- }
-
- @Override
- public String getSpi(String key) {
- try {
- checkException();
- } catch (BackingStoreException e) {
- }
- if (null == key) {
- return null;
- }
- return result == returnNull ? null : attr.getProperty(key);
- }
-
- @Override
- public String[] keysSpi() throws BackingStoreException {
- checkException();
- Set<Object> keys = attr.keySet();
- String[] results = new String[keys.size()];
- keys.toArray(results);
- return result == returnNull ? null : results;
- }
-
- @Override
- public void putSpi(String name, String value) {
- try {
- checkException();
- } catch (BackingStoreException e) {
- }
- if (name == null || value == null) {
- return;
- }
- attr.put(name, value);
- }
-
- @Override
- protected void removeNodeSpi() throws BackingStoreException {
- checkException();
- ((MockAbstractPreferences) parent()).childs.remove(name());
- }
-
- @Override
- public void removeSpi(String key) {
- try {
- checkException();
- } catch (BackingStoreException e) {
- }
- if (null == key) {
- return;
- }
- attr.remove(key);
- }
-
- @Override
- public void syncSpi() throws BackingStoreException {
- checkException();
- syncTimes++;
- }
-
- public boolean getNewNode() {
- return newNode;
- }
-
- public Object getLock() {
- return lock;
- }
-
- public void protectedAbstractMethod() {
- try {
- childrenNamesSpi();
- } catch (BackingStoreException e) {
- }
- childSpi("mock");
- try {
- flushSpi();
- } catch (BackingStoreException e1) {
- }
- getSpi(null);
- isRemoved();
- try {
- keysSpi();
- } catch (BackingStoreException e2) {
- }
- putSpi(null, null);
- try {
- removeNodeSpi();
- } catch (BackingStoreException e3) {
- }
- removeSpi(null);
- try {
- syncSpi();
- } catch (BackingStoreException e4) {
- }
- }
-
- public boolean isRemovedImpl() {
- return super.isRemoved();
- }
-
- public AbstractPreferences getChildImpl(String name)
- throws BackingStoreException {
- return super.getChild(name);
- }
-
- public AbstractPreferences[] cachedChildrenImpl() {
- return super.cachedChildren();
- }
-
-}
-
-class MockRuntimeException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- public MockRuntimeException(String s) {
- super(s);
- }
-
- public MockRuntimeException() {
- super();
- }
-}
-
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java
deleted file mode 100644
index 092144e..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java
+++ /dev/null
@@ -1,132 +0,0 @@
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import java.util.prefs.NodeChangeEvent;
-import java.util.prefs.NodeChangeListener;
-import java.util.prefs.Preferences;
-
-public class MockNodeChangeListener implements NodeChangeListener {
- private Object addLock = new Object();
-
- private Object removeLock = new Object();
-
- private int added = 0;
-
- private int removed = 0;
-
- private int testNum = 0;
-
- public static final int TEST_GET_CHILD = 1;
-
- public static final int TEST_GET_PARENT = 2;
-
- boolean addResult = false;
-
- boolean removeResult = false;
-
- public MockNodeChangeListener(int test) {
- testNum = test;
- }
-
- public MockNodeChangeListener() {
-
- }
-
- public void waitForEvent() {
- try {
- synchronized (addLock) {
- addLock.wait(500);
- }
- } catch (InterruptedException e) {
- }
- }
-
- public void childAdded(NodeChangeEvent e) {
-
- synchronized (addLock) {
- switch (testNum) {
- case TEST_GET_CHILD:
- Preferences child = e.getChild();
- if (child == null) {
- addResult = false;
- } else {
- if (child.name() == "mock1") {
- addResult = true;
- }
- }
- break;
- case TEST_GET_PARENT:
- Preferences parent = e.getParent();
- if (parent == null) {
- addResult = false;
- } else {
- if (parent.name() == "mock") {
- addResult = true;
- }
- }
-
- break;
- }
- ++added;
- addLock.notifyAll();
- }
- }
-
- public void childRemoved(NodeChangeEvent e) {
- synchronized (removeLock) {
- switch (testNum) {
- case TEST_GET_CHILD:
- Preferences child = e.getChild();
- if (child == null) {
- removeResult = false;
- } else {
- if (child.name() == "mock1") {
- removeResult = true;
- }
- }
- break;
- case TEST_GET_PARENT:
- Preferences parent = e.getParent();
- if (parent == null) {
- addResult = false;
- } else {
- if (parent.name() == "mock") {
- addResult = true;
- }
- }
-
- break;
- }
- removed++;
- removeLock.notifyAll();
- }
- }
-
- public boolean getAddResult() {
- synchronized (addLock) {
- return addResult;
- }
- }
-
- public boolean getRemoveResult() {
- synchronized (removeLock) {
- return removeResult;
- }
- }
-
- public int getAdded() {
- synchronized (addLock) {
- return added;
- }
- }
-
- public int getRemoved() {
- synchronized (removeLock) {
- return removed;
- }
- }
-
- public void reset() {
- added = 0;
- removed = 0;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java
deleted file mode 100644
index 98a8897..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import java.util.prefs.PreferenceChangeEvent;
-import java.util.prefs.PreferenceChangeListener;
-
-public class MockPreferenceChangeListener implements PreferenceChangeListener {
- private Object lock = new Object();
-
- private int changed = 0;
-
- private boolean addDispatched = false;
-
- public static final int TEST_GET_KEY = 1;
-
- public static final int TEST_GET_NEW_VALUE = 2;
-
- public static final int TEST_GET_NODE = 3;
-
- boolean result = false;
-
- int testNum = 0;
-
-
- public MockPreferenceChangeListener() {
-
- }
-
- public MockPreferenceChangeListener(int test) {
- testNum = test;
- }
-
- public void waitForEvent() {
- waitForEvent(1);
- }
-
-
- public void waitForEvent(int count) {
- for (int i = 0; i < count; i++) {
- try {
- synchronized (lock) {
- lock.wait(500);
- }
- } catch (InterruptedException e) {
- }
- }
- }
-
- // private Object lock = new Object();
-
- public void preferenceChange(PreferenceChangeEvent pce) {
- synchronized (lock) {
- switch(testNum) {
- case TEST_GET_KEY:
- if(pce != null) {
- if(pce.getKey().equals("key_int")) {
- result = true;
- }
- }
- break;
- case TEST_GET_NEW_VALUE:
- if(pce != null) {
- if(pce.getNewValue().equals(new Integer(Integer.MAX_VALUE).toString())) {
- result = true;
- }
- }
- break;
- case TEST_GET_NODE:
- if(pce != null) {
- if("mock".equals(pce.getNode().name())) {
- result = true;
- }
- }
-
- break;
- }
- changed++;
- addDispatched = true;
- lock.notifyAll();
- }
- }
-
- public boolean getResult() {
- synchronized (lock) {
-
- if (!addDispatched) {
- try {
- // TODO: don't know why must add limitation
- lock.wait(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- addDispatched = false;
- return result;
- }
- }
-
- public int getChanged() {
- synchronized (lock) {
-
- if (!addDispatched) {
- try {
- // TODO: don't know why must add limitation
- lock.wait(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- addDispatched = false;
- return changed;
- }
- }
-
- public void reset() {
- changed = 0;
- result = false;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java
deleted file mode 100644
index 953f21e..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import junit.framework.TestCase;
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-import java.io.NotSerializableException;
-import java.util.prefs.AbstractPreferences;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.NodeChangeEvent;
-import java.util.prefs.Preferences;
-
-/**
- *
- */
-@TestTargetClass(NodeChangeEvent.class)
-public class NodeChangeEventTest extends TestCase {
-
- NodeChangeEvent event;
-
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "NodeChangeEvent",
- args = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
- )
- public void testConstructor() {
- event = new NodeChangeEvent(Preferences.systemRoot(), Preferences
- .userRoot());
- assertSame(Preferences.systemRoot(), event.getParent());
- assertSame(Preferences.userRoot(), event.getChild());
- assertSame(Preferences.systemRoot(), event.getSource());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "NodeChangeEvent",
- args = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
- )
- public void testConstructorNullParam() {
- try {
- event = new NodeChangeEvent(null, Preferences.userRoot());
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- event = new NodeChangeEvent(Preferences.systemRoot(), null);
- assertSame(Preferences.systemRoot(), event.getParent());
- assertNull(event.getChild());
- assertSame(Preferences.systemRoot(), event.getSource());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!Serialization",
- args = {}
- )
- public void testSerialization() throws Exception {
-
- event = new NodeChangeEvent(Preferences.systemRoot(), null);
-
- try {
- SerializationTest.copySerializable(event);
- fail("No expected NotSerializableException");
- } catch (NotSerializableException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test is correct, functionality checked in separate Mock class.",
- method = "getChild",
- args = {}
- )
- public void testGetChild() throws BackingStoreException {
-
- AbstractPreferences parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
-
- AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
-
- MockNodeChangeListener nl = new MockNodeChangeListener(
- MockNodeChangeListener.TEST_GET_CHILD);
- try {
- pref.addNodeChangeListener(nl);
- Preferences child1 = pref.node("mock1");
- nl.waitForEvent();
- assertEquals(1, nl.getAdded());
- assertTrue(nl.getAddResult());
- nl.reset();
- child1.removeNode();
- nl.waitForEvent();
- assertEquals(1, nl.getRemoved());
- assertTrue(nl.getRemoveResult());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test is correct, functionality checked in separate Mock class.",
- method = "getParent",
- args = {}
- )
- public void testGetParent() throws BackingStoreException {
-
- AbstractPreferences parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
-
- AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
-
- MockNodeChangeListener nl = new MockNodeChangeListener(
- MockNodeChangeListener.TEST_GET_CHILD);
- try {
- pref.addNodeChangeListener(nl);
- Preferences child1 = pref.node("mock1");
- nl.waitForEvent();
- assertEquals(1, nl.getAdded());
- assertTrue(nl.getAddResult());
- nl.reset();
- child1.removeNode();
- nl.waitForEvent();
- assertEquals(1, nl.getRemoved());
- assertTrue(nl.getRemoveResult());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
deleted file mode 100644
index 5065d91..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import junit.framework.TestCase;
-
-import java.util.prefs.NodeChangeEvent;
-import java.util.prefs.NodeChangeListener;
-import java.util.prefs.Preferences;
-
-/**
- *
- */
-@TestTargetClass(NodeChangeListener.class)
-public class NodeChangeListenerTest extends TestCase {
-
- NodeChangeListener l;
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- l = new NodeChangeListenerImpl();
- }
-
- /*
- * @see TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing Interface",
- method = "childAdded",
- args = {java.util.prefs.NodeChangeEvent.class}
- )
- public void testChildAdded() {
- l.childAdded(new NodeChangeEvent(Preferences.userRoot(), Preferences
- .userRoot()));
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing Interface",
- method = "childRemoved",
- args = {java.util.prefs.NodeChangeEvent.class}
- )
- public void testChildRemoved() {
- l.childRemoved(new NodeChangeEvent(Preferences.userRoot(), Preferences
- .userRoot()));
- }
-
- public static class NodeChangeListenerImpl implements NodeChangeListener {
-
- public void childAdded(NodeChangeEvent e) {
- }
-
- public void childRemoved(NodeChangeEvent e) {
- }
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java
deleted file mode 100644
index aac5170..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import junit.framework.TestCase;
-import org.apache.harmony.testframework.serialization.SerializationTest;
-
-import java.io.NotSerializableException;
-import java.util.prefs.AbstractPreferences;
-import java.util.prefs.PreferenceChangeEvent;
-import java.util.prefs.Preferences;
-
-/**
- *
- */
-@TestTargetClass(PreferenceChangeEvent.class)
-public class PreferenceChangeEventTest extends TestCase {
-
- PreferenceChangeEvent event;
-
- @Override protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Checks exception.",
- method = "PreferenceChangeEvent",
- args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- public void testPreferenceChangeEventException() {
- try {
- event = new PreferenceChangeEvent(null, "key", "value");
- fail();
- } catch (IllegalArgumentException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PreferenceChangeEvent",
- args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- public void testConstructorNullValue() {
- event = new PreferenceChangeEvent(Preferences.userRoot(), "key", null);
- assertEquals("key", event.getKey());
- assertNull(event.getNewValue());
- assertSame(Preferences.userRoot(), event.getNode());
- assertSame(Preferences.userRoot(), event.getSource());
-
- event = new PreferenceChangeEvent(Preferences.userRoot(), "", null);
- assertEquals("", event.getKey());
- assertNull(event.getNewValue());
- assertSame(Preferences.userRoot(), event.getNode());
- assertSame(Preferences.userRoot(), event.getSource());
-
- event = new PreferenceChangeEvent(Preferences.userRoot(), null, "value");
- assertNull(event.getKey());
- assertEquals("value", event.getNewValue());
- assertSame(Preferences.userRoot(), event.getNode());
- assertSame(Preferences.userRoot(), event.getSource());
-
- event = new PreferenceChangeEvent(Preferences.userRoot(), null, "");
- assertNull(event.getKey());
- assertEquals("", event.getNewValue());
- assertSame(Preferences.userRoot(), event.getNode());
- assertSame(Preferences.userRoot(), event.getSource());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PreferenceChangeEvent",
- args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- public void testConstructor() {
- event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
- "value");
- assertEquals("key", event.getKey());
- assertEquals("value", event.getNewValue());
- assertSame(Preferences.userRoot(), event.getNode());
- assertSame(Preferences.userRoot(), event.getSource());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies serialization",
- method = "!Serialization",
- args = {}
- )
- public void testSerialization() throws Exception {
- event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
- "value");
- try {
- SerializationTest.copySerializable(event);
- fail("No expected NotSerializableException");
- } catch (NotSerializableException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test is correct, functionality checked in separate Mock class.",
- method = "getKey",
- args = {}
- )
- public void testGetKey() {
- AbstractPreferences parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
-
- AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
-
- MockPreferenceChangeListener pl = new MockPreferenceChangeListener(
- MockPreferenceChangeListener.TEST_GET_KEY);
- pref.addPreferenceChangeListener(pl);
- try {
- pref.putInt("key_int", Integer.MAX_VALUE);
- assertEquals(1, pl.getChanged());
- assertTrue(pl.getResult());
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test is correct, functionality checked in separate Mock class.",
- method = "getNewValue",
- args = {}
- )
- public void testGetNewValue() {
- AbstractPreferences parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
-
- AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
-
- MockPreferenceChangeListener pl = new MockPreferenceChangeListener(
- MockPreferenceChangeListener.TEST_GET_NEW_VALUE);
- pref.addPreferenceChangeListener(pl);
- try {
- pref.putInt("key_int", Integer.MAX_VALUE);
- assertEquals(1, pl.getChanged());
- assertTrue(pl.getResult());
- pl.reset();
-
- pref.putInt("key_int", Integer.MAX_VALUE);
- assertEquals(1, pl.getChanged());
- assertTrue(pl.getResult());
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test is correct, functionality checked in separate Mock class.",
- method = "getNode",
- args = {}
- )
- public void testGetNode() {
- AbstractPreferences parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
-
- AbstractPreferences pref = (AbstractPreferences) parent.node("mock");
-
- MockPreferenceChangeListener pl = new MockPreferenceChangeListener(
- MockPreferenceChangeListener.TEST_GET_NODE);
- pref.addPreferenceChangeListener(pl);
- try {
- pref.putInt("key_int", Integer.MAX_VALUE);
- assertEquals(1, pl.getChanged());
- assertTrue(pl.getResult());
- pl.reset();
-
- } finally {
- pref.removePreferenceChangeListener(pl);
- }
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
deleted file mode 100644
index 563354f..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.util.prefs.PreferenceChangeEvent;
-import java.util.prefs.PreferenceChangeListener;
-import java.util.prefs.Preferences;
-
-import junit.framework.TestCase;
-
-/**
- *
- */
-@TestTargetClass(PreferenceChangeListener.class)
-public class PreferenceChangeListenerTest extends TestCase {
-
- PreferenceChangeListener l;
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- l = new PreferenceChangeListenerImpl();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing Interface",
- method = "preferenceChange",
- args = {java.util.prefs.PreferenceChangeEvent.class}
- )
- public void testPreferenceChange() {
- l.preferenceChange(new PreferenceChangeEvent(Preferences.userRoot(),
- "", ""));
- }
-
- public static class PreferenceChangeListenerImpl implements
- PreferenceChangeListener {
- public void preferenceChange(PreferenceChangeEvent pce) {
- }
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
deleted file mode 100644
index 5808a15..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.util.prefs.Preferences;
-import java.util.prefs.PreferencesFactory;
-
-import junit.framework.TestCase;
-
-/**
- *
- */
-@TestTargetClass(PreferencesFactory.class)
-public class PreferencesFactoryTest extends TestCase {
-
- PreferencesFactory f;
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- f = new PreferencesFactoryImpl();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing Interface",
- method = "userRoot",
- args = {}
- )
- public void testUserRoot() {
- assertNull(f.userRoot());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Testing Interface",
- method = "systemRoot",
- args = {}
- )
- public void testSystemRoot() {
- assertNull(f.systemRoot());
- }
-
- public static class PreferencesFactoryImpl implements PreferencesFactory {
-
- public Preferences userRoot() {
- return null;
- }
-
- public Preferences systemRoot() {
- return null;
- }
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java b/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
deleted file mode 100644
index afef18e..0000000
--- a/luni/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
+++ /dev/null
@@ -1,1919 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import junit.framework.TestCase;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.util.Arrays;
-import java.util.prefs.AbstractPreferences;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.InvalidPreferencesFormatException;
-import java.util.prefs.NodeChangeListener;
-import java.util.prefs.PreferenceChangeListener;
-import java.util.prefs.Preferences;
-
-/**
- *
- */
-@TestTargetClass(Preferences.class)
-public class PreferencesTest extends TestCase {
-
- MockInputStream stream = null;
-
- final static String longKey;
-
- final static String longValue;
-
- InputStream in;
- static {
- StringBuffer key = new StringBuffer(Preferences.MAX_KEY_LENGTH);
- for (int i = 0; i < Preferences.MAX_KEY_LENGTH; i++) {
- key.append('a');
- }
- longKey = key.toString();
-
- StringBuffer value = new StringBuffer(Preferences.MAX_VALUE_LENGTH);
- for (int i = 0; i < Preferences.MAX_VALUE_LENGTH; i++) {
- value.append('a');
- }
- longValue = value.toString();
- }
-
- /*
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- in = new ByteArrayInputStream(
- "<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>"
- .getBytes("UTF-8"));
- stream = new MockInputStream(in);
- }
-
- /*
- * @see TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- stream.close();
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "systemNodeForPackage",
- args = {java.lang.Class.class}
- )
- public void testSystemNodeForPackage() {
- Preferences p = null;
- try {
- p = Preferences.systemNodeForPackage(Object.class);
- } catch (SecurityException e) {
- // may be caused by absence of privileges on the underlying OS
- return;
- }
- assertEquals("/java/lang", p.absolutePath());
- assertTrue(p instanceof AbstractPreferences);
- Preferences root = Preferences.systemRoot();
- Preferences parent = root.node("java");
- assertSame(parent, p.parent());
- assertFalse(p.isUserNode());
- assertEquals("lang", p.name());
- assertEquals("System Preference Node: " + p.absolutePath(), p
- .toString());
- try {
- assertEquals(0, p.childrenNames().length);
- } catch (BackingStoreException e) {
- // could be thrown according to specification
- }
- try {
- assertEquals(0, p.keys().length);
- } catch (BackingStoreException e) {
- // could be thrown according to specification
- }
-
- try {
- p = Preferences.systemNodeForPackage(null);
- fail("NullPointerException has not been thrown");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "SecurityException checking missed.",
- method = "systemRoot",
- args = {}
- )
- public void testSystemRoot() {
- Preferences p = Preferences.systemRoot();
- assertTrue(p instanceof AbstractPreferences);
- assertEquals("/", p.absolutePath());
- assertSame(null, p.parent());
- assertFalse(p.isUserNode());
- assertEquals("", p.name());
- assertEquals("System Preference Node: " + p.absolutePath(), p
- .toString());
- // assertEquals(0, p.childrenNames().length);
- // assertEquals(0, p.keys().length);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Checks constant values",
- method = "!Constants",
- args = {}
- )
- public void testConsts() {
- assertEquals(80, Preferences.MAX_KEY_LENGTH);
- assertEquals(80, Preferences.MAX_NAME_LENGTH);
- assertEquals(8192, Preferences.MAX_VALUE_LENGTH);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "SecurityException checking missed.",
- method = "userNodeForPackage",
- args = {java.lang.Class.class}
- )
- public void testUserNodeForPackage() throws BackingStoreException {
- Preferences p = Preferences.userNodeForPackage(Object.class);
- assertEquals("/java/lang", p.absolutePath());
- assertTrue(p instanceof AbstractPreferences);
- Preferences root = Preferences.userRoot();
- Preferences parent = root.node("java");
- assertSame(parent, p.parent());
- assertTrue(p.isUserNode());
- assertEquals("lang", p.name());
- assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
- assertEquals(0, p.childrenNames().length);
- assertEquals(0, p.keys().length);
-
- try {
- p = Preferences.userNodeForPackage(null);
- fail();
- } catch (NullPointerException e) {
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "SecurityException checking missed.",
- method = "userRoot",
- args = {}
- )
- public void testUserRoot() {
- Preferences p = Preferences.userRoot();
- assertTrue(p instanceof AbstractPreferences);
- assertEquals("/", p.absolutePath());
- assertSame(null, p.parent());
- assertTrue(p.isUserNode());
- assertEquals("", p.name());
- assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
- // assertEquals(0, p.childrenNames().length);
- // assertEquals(p.keys().length, 0);
- }
-
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "SecurityException & IOException checking missed.",
- method = "importPreferences",
- args = {java.io.InputStream.class}
- )
- public void testImportPreferences2() throws Exception {
- InputStream in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-badtype.xml");
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- }
-
- in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-badencoding.xml");
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- } catch (UnsupportedEncodingException e) {
- }
-
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "SecurityException & IOException checking missed.",
- method = "importPreferences",
- args = {java.io.InputStream.class}
- )
- public void testImportPreferences() throws Exception {
- Preferences prefs = null;
- try {
- prefs = Preferences.userNodeForPackage(PreferencesTest.class);
- // assertEquals(0, prefs.childrenNames().length);
- // assertFalse(prefs.nodeExists("mock/child/grandson"));
-
- prefs.put("prefskey", "oldvalue");
- prefs.put("prefskey2", "oldvalue2");
- in = getClass().getResourceAsStream("/prefs/java/util/prefs/userprefs.xml");
- Preferences.importPreferences(in);
-
- prefs = Preferences.userNodeForPackage(PreferencesTest.class);
- assertEquals(1, prefs.childrenNames().length);
- assertTrue(prefs.nodeExists("mock/child/grandson"));
- assertEquals("newvalue", prefs.get("prefskey", null));
- assertEquals("oldvalue2", prefs.get("prefskey2", null));
- assertEquals("newvalue3", prefs.get("prefskey3", null));
-
- in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-badform.xml");
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- }
-
- in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-higherversion.xml");
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- }
-
- in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-ascii.xml");
- Preferences.importPreferences(in);
- prefs = Preferences.userNodeForPackage(PreferencesTest.class);
- } finally {
- try {
- prefs = Preferences.userRoot().node("tests");
- prefs.removeNode();
- } catch (Exception e) {
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Test for Exceptions only.",
- method = "importPreferences",
- args = {java.io.InputStream.class}
- )
- public void testImportPreferencesException() throws Exception {
- try {
- Preferences.importPreferences(null);
- fail();
- } catch (MalformedURLException e) {
- }
-
- byte[] source = new byte[0];
- InputStream in = new ByteArrayInputStream(source);
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- }
-
- stream.setResult(MockInputStream.exception);
- try {
- Preferences.importPreferences(stream);
- fail();
- } catch (IOException e) {
- }
-
- stream.setResult(MockInputStream.runtimeException);
- try {
- Preferences.importPreferences(stream);
- fail();
- } catch (RuntimeException e) {
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "absolutePath",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "childrenNames",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "clear",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "exportNode",
- args = {java.io.OutputStream.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "exportSubtree",
- args = {java.io.OutputStream.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "flush",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "get",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getBoolean",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getByteArray",
- args = {java.lang.String.class, byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getFloat",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getDouble",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getInt",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "getLong",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "isUserNode",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "keys",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "name",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "node",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "nodeExists",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "parent",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "put",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putBoolean",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putByteArray",
- args = {java.lang.String.class, byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putDouble",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putFloat",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putInt",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "putLong",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "remove",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "removeNode",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "addNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "addPreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "removeNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "removePreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "sync",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test for abstract methods.",
- method = "toString",
- args = {}
- )
- })
- public void testAbstractMethods() {
- Preferences p = new MockPreferences();
- p.absolutePath();
- try {
- p.childrenNames();
- } catch (BackingStoreException e4) {
- }
- try {
- p.clear();
- } catch (BackingStoreException e5) {
- }
- try {
- p.exportNode(null);
- } catch (IOException e6) {
- } catch (BackingStoreException e6) {
- }
- try {
- p.exportSubtree(null);
- } catch (IOException e7) {
- } catch (BackingStoreException e7) {
- }
- try {
- p.flush();
- } catch (BackingStoreException e8) {
- }
- p.get(null, null);
- p.getBoolean(null, false);
- p.getByteArray(null, null);
- p.getFloat(null, 0.1f);
- p.getDouble(null, 0.1);
- p.getInt(null, 1);
- p.getLong(null, 1l);
- p.isUserNode();
- try {
- p.keys();
- } catch (BackingStoreException e) {
- }
- p.name();
- p.node(null);
- try {
- p.nodeExists(null);
- } catch (BackingStoreException e1) {
- }
- p.parent();
- p.put(null, null);
- p.putBoolean(null, false);
- p.putByteArray(null, null);
- p.putDouble(null, 1);
- p.putFloat(null, 1f);
- p.putInt(null, 1);
- p.putLong(null, 1l);
- p.remove(null);
- try {
- p.removeNode();
- } catch (BackingStoreException e2) {
- }
- p.addNodeChangeListener(null);
- p.addPreferenceChangeListener(null);
- p.removeNodeChangeListener(null);
- p.removePreferenceChangeListener(null);
- try {
- p.sync();
- } catch (BackingStoreException e3) {
- }
- p.toString();
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Preferences",
- args = {}
- )
- public void testConstructor() {
- MockPreferences mp = new MockPreferences();
- assertEquals(mp.getClass(), MockPreferences.class);
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Check existed implementation",
- method = "toString",
- args = {}
- )
- public void testToString() {
- Preferences p1 = Preferences.userNodeForPackage(Preferences.class);
- assertNotNull(p1.toString());
-
- Preferences p2 = Preferences.systemRoot();
- assertNotNull(p2.toString());
-
- Preferences p3 = Preferences.userRoot();
- assertNotNull(p3.toString());
- }
- /**
- * @test java.util.prefs.Preferences#absolutePath()
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "absolutePath",
- args = {}
- )
- public void testAbsolutePath() {
- Preferences p = Preferences.userNodeForPackage(Preferences.class);
- assertEquals("/java/util/prefs", p.absolutePath());
-
- }
-
- /**
- * @test java.util.prefs.Preferences#childrenNames()
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "childrenNames",
- args = {}
- )
- public void testChildrenNames() throws BackingStoreException {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
-
- Preferences child1 = pref.node("child1");
-
- pref.node("child2");
- pref.node("child3");
- child1.node("subchild1");
-
- assertSame(pref, child1.parent());
- assertEquals(3, pref.childrenNames().length);
- assertEquals("child1", pref.childrenNames()[0]);
- assertEquals(1, child1.childrenNames().length);
- assertEquals("subchild1", child1.childrenNames()[0]);
- }
-
- /**
- * @test java.util.prefs.Preferences#clear()
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "clear",
- args = {}
- )
- public void testClear() throws BackingStoreException {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- pref.put("testClearKey", "testClearValue");
- pref.put("testClearKey1", "testClearValue1");
- assertEquals("testClearValue", pref.get("testClearKey", null));
- assertEquals("testClearValue1", pref.get("testClearKey1", null));
- pref.clear();
- assertNull(pref.get("testClearKey", null));
- assertNull(pref.get("testClearKey1", null));
- }
-
- /**
- * @test java.util.prefs.Preferences#get(String key, String def)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "get",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testGet() throws BackingStoreException {
- Preferences root = Preferences.userNodeForPackage(Preferences.class);
- Preferences pref = root.node("mock");
- assertNull(pref.get("", null));
- assertEquals("default", pref.get("key", "default"));
- assertNull(pref.get("key", null));
- pref.put("testGetkey", "value");
- assertNull(pref.get("testGetKey", null));
- assertEquals("value", pref.get("testGetkey", null));
-
- try {
- pref.get(null, "abc");
- fail();
- } catch (NullPointerException e) {
- }
- pref.get("", "abc");
- pref.get("key", null);
- pref.get("key", "");
- pref.putFloat("floatKey", 1.0f);
- assertEquals("1.0", pref.get("floatKey", null));
-
- pref.removeNode();
- try {
- pref.get("key", "abc");
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.get(null, "abc");
- fail();
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @test java.util.prefs.Preferences#getBoolean(String key, boolean def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getBoolean",
- args = {java.lang.String.class, boolean.class}
- )
- public void testGetBoolean() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getBoolean(null, false);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.put("testGetBooleanKey", "false");
- pref.put("testGetBooleanKey2", "value");
- assertFalse(pref.getBoolean("testGetBooleanKey", true));
- assertTrue(pref.getBoolean("testGetBooleanKey2", true));
- }
-
- /**
- * @test java.util.prefs.Preferences#getByteArray(String key, byte[] def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getByteArray",
- args = {java.lang.String.class, byte[].class}
- )
- public void testGetByteArray() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
- }
- byte[] b64Array = new byte[] { 0x59, 0x57, 0x4a, 0x6a };// BASE64
-
- pref.put("testGetByteArrayKey", "abc=");
- pref.put("testGetByteArrayKey2", new String(b64Array));
- pref.put("invalidKey", "<>?");
- assertTrue(Arrays.equals(new byte[] { 105, -73 }, pref.getByteArray(
- "testGetByteArrayKey", new byte[0])));
- assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
- .getByteArray("testGetByteArrayKey2", new byte[0])));
- assertTrue(Arrays.equals(new byte[0], pref.getByteArray("invalidKey",
- new byte[0])));
-
- pref.putByteArray("testGetByteArrayKey3", b64Array);
- pref.putByteArray("testGetByteArrayKey4", "abc".getBytes());
- assertTrue(Arrays.equals(b64Array, pref.getByteArray(
- "testGetByteArrayKey3", new byte[0])));
- assertTrue(Arrays.equals("abc".getBytes(), pref.getByteArray(
- "testGetByteArrayKey4", new byte[0])));
- }
-
- /**
- * @test java.util.prefs.Preferences#getDouble(String key, double def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getDouble",
- args = {java.lang.String.class, double.class}
- )
- public void testGetDouble() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getDouble(null, 0);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.put("testGetDoubleKey", "1");
- pref.put("testGetDoubleKey2", "value");
- pref.putDouble("testGetDoubleKey3", 1);
- pref.putInt("testGetDoubleKey4", 1);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey", 0.0), 0);
- assertEquals(0.0, pref.getDouble("testGetDoubleKey2", 0.0), 0);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey3", 0.0), 0);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey4", 0.0), 0);
- }
-
- /**
- * @test java.util.prefs.Preferences#getFloat(String key, float def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getFloat",
- args = {java.lang.String.class, float.class}
- )
- public void testGetFloat() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getFloat(null, 0f);
- fail();
- } catch (NullPointerException e) {
- }
- pref.put("testGetFloatKey", "1");
- pref.put("testGetFloatKey2", "value");
- assertEquals(1f, pref.getFloat("testGetFloatKey", 0f), 0);
- assertEquals(0f, pref.getFloat("testGetFloatKey2", 0f), 0);
- }
-
- /**
- * @test java.util.prefs.Preferences#getInt(String key, int def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getInt",
- args = {java.lang.String.class, int.class}
- )
- public void testGetInt() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getInt(null, 0);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.put("testGetIntKey", "1");
- pref.put("testGetIntKey2", "value");
- assertEquals(1, pref.getInt("testGetIntKey", 0));
- assertEquals(0, pref.getInt("testGetIntKey2", 0));
- }
-
- /**
- * @test java.util.prefs.Preferences#getLong(String key, long def)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "getLong",
- args = {java.lang.String.class, long.class}
- )
- public void testGetLong() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.getLong(null, 0);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.put("testGetLongKey", "1");
- pref.put("testGetLongKey2", "value");
- assertEquals(1, pref.getInt("testGetLongKey", 0));
- assertEquals(0, pref.getInt("testGetLongKey2", 0));
- }
-
- /**
- * @test java.util.prefs.Preferences#isUserNode()
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isUserNode",
- args = {}
- )
- public void testIsUserNode() {
- Preferences pref1 = Preferences.userNodeForPackage(Preferences.class);
- assertTrue(pref1.isUserNode());
-
- Preferences pref2 = Preferences.systemNodeForPackage(Preferences.class);
- assertFalse(pref2.isUserNode());
- }
-
- /**
- * @test java.util.prefs.Preferences#keys()
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "keys",
- args = {}
- )
- public void testKeys() throws BackingStoreException {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- pref.clear();
-
- pref.put("key0", "value");
- pref.put("key1", "value1");
- pref.put("key2", "value2");
- pref.put("key3", "value3");
-
- String[] keys = pref.keys();
- assertEquals(4, keys.length);
- for (int i = 0; i < keys.length; i++) {
- assertEquals(0, keys[i].indexOf("key"));
- assertEquals(4, keys[i].length());
- }
- }
-
- /**
- * @test java.util.prefs.Preferences#name()
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "name",
- args = {}
- )
- public void testName() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- Preferences child = pref.node("mock");
- assertEquals("mock", child.name());
- }
-
- /**
- * @test java.util.prefs.Preferences#node(String pathName)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "node",
- args = {java.lang.String.class}
- )
- public void testNode() throws BackingStoreException {
- StringBuffer name = new StringBuffer(Preferences.MAX_NAME_LENGTH);
- for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
- name.append('a');
- }
- String longName = name.toString();
-
- Preferences root = Preferences.userRoot();
- Preferences parent = Preferences
- .userNodeForPackage(Preferences.class);
- Preferences pref = parent.node("mock");
-
- try {
- pref.node(null);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- pref.node("/java/util/prefs/");
- fail();
- } catch (IllegalArgumentException e) {
- }
- try {
- pref.node("/java//util/prefs");
- fail();
- } catch (IllegalArgumentException e) {
- }
- try {
- pref.node(longName + "a");
- fail();
- } catch (IllegalArgumentException e) {
- }
- assertNotNull(pref.node(longName));
-
- assertSame(root, pref.node("/"));
-
- Preferences prefs = pref.node("/java/util/prefs");
- assertSame(prefs, parent);
-
- assertSame(pref, pref.node(""));
-
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences child = (MockAbstractPreferences) ((MockAbstractPreferences) pref)
- .publicChildSpi("child");
- assertSame(child, pref.node("child"));
-
- Preferences child2 = pref.node("child2");
- assertSame(child2, ((MockAbstractPreferences) pref)
- .publicChildSpi("child2"));
-
- Preferences grandchild = pref.node("child/grandchild");
- assertSame(grandchild, child.childSpi("grandchild"));
- assertSame(grandchild, child.cachedChildrenImpl()[0]);
- grandchild.removeNode();
- assertNotSame(grandchild, pref.node("child/grandchild"));
-
- grandchild = pref.node("child3/grandchild");
- AbstractPreferences[] childs = ((MockAbstractPreferences) pref)
- .cachedChildrenImpl();
- Preferences child3 = child;
- for (int i = 0; i < childs.length; i++) {
- if (childs[i].name().equals("child3")) {
- child3 = childs[i];
- break;
- }
- }
- assertSame(child3, grandchild.parent());
- }
-
- /**
- * @test java.util.prefs.Preferences#nodeExists(String pathName)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException & BackingStoreException checking missed, but method is abstract, probably it is OK",
- method = "nodeExists",
- args = {java.lang.String.class}
- )
- public void testNodeExists() throws BackingStoreException {
-
- Preferences parent = Preferences
- .userNodeForPackage(Preferences.class);
- Preferences pref = parent.node("mock");
-
- try {
- pref.nodeExists(null);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- pref.nodeExists("/java/util/prefs/");
- fail();
- } catch (IllegalArgumentException e) {
- }
- try {
- pref.nodeExists("/java//util/prefs");
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- assertTrue(pref.nodeExists("/"));
-
- assertTrue(pref.nodeExists("/java/util/prefs"));
-
- assertTrue(pref.nodeExists(""));
-
- assertFalse(pref.nodeExists("child"));
- Preferences grandchild = pref.node("child/grandchild");
- assertTrue(pref.nodeExists("child"));
- assertTrue(pref.nodeExists("child/grandchild"));
- grandchild.removeNode();
- assertTrue(pref.nodeExists("child"));
- assertFalse(pref.nodeExists("child/grandchild"));
- assertFalse(grandchild.nodeExists(""));
-
- assertFalse(pref.nodeExists("child2/grandchild"));
- pref.node("child2/grandchild");
- assertTrue(pref.nodeExists("child2/grandchild"));
- }
-
- /**
- * @test java.util.prefs.Preferences#parent()
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "parent",
- args = {}
- )
- public void testParent() {
- Preferences parent = Preferences
- .userNodeForPackage(Preferences.class);
- Preferences pref = parent.node("mock");
-
- assertSame(parent, pref.parent());
-
- }
-
- /**
- * @test java.util.prefs.Preferences#put(String key, String value)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "put",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testPut() throws BackingStoreException {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- pref.put("", "emptyvalue");
- assertEquals("emptyvalue", pref.get("", null));
- pref.put("testPutkey", "value1");
- assertEquals("value1", pref.get("testPutkey", null));
- pref.put("testPutkey", "value2");
- assertEquals("value2", pref.get("testPutkey", null));
-
- pref.put("", "emptyvalue");
- assertEquals("emptyvalue", pref.get("", null));
-
- try {
- pref.put(null, "value");
- fail();
- } catch (NullPointerException e) {
- }
- try {
- pref.put("key", null);
- fail();
- } catch (NullPointerException e) {
- }
- pref.put(longKey, longValue);
- try {
- pref.put(longKey + 1, longValue);
- fail();
- } catch (IllegalArgumentException e) {
- }
- try {
- pref.put(longKey, longValue + 1);
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- pref.removeNode();
- try {
- pref.put(longKey, longValue + 1);
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- try {
- pref.put(longKey, longValue);
- fail();
- } catch (IllegalStateException e) {
- }
- }
-
- /**
- * @test java.util.prefs.Preferences#putBoolean(String key, boolean value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putBoolean",
- args = {java.lang.String.class, boolean.class}
- )
- public void testPutBoolean() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putBoolean(null, false);
- fail();
- } catch (NullPointerException e) {
- }
- pref.putBoolean(longKey, false);
- try {
- pref.putBoolean(longKey + "a", false);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.putBoolean("testPutBooleanKey", false);
- assertEquals("false", pref.get("testPutBooleanKey", null));
- assertFalse(pref.getBoolean("testPutBooleanKey", true));
- }
-
- /**
- * @test java.util.prefs.Preferences#putDouble(String key, double value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putDouble",
- args = {java.lang.String.class, double.class}
- )
- public void testPutDouble() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putDouble(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- pref.putDouble(longKey, 3);
- try {
- pref.putDouble(longKey + "a", 3);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.putDouble("testPutDoubleKey", 3);
- assertEquals("3.0", pref.get("testPutDoubleKey", null));
- assertEquals(3, pref.getDouble("testPutDoubleKey", 0), 0);
- }
-
- /**
- * @test java.util.prefs.Preferences#putFloat(String key, float value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putFloat",
- args = {java.lang.String.class, float.class}
- )
- public void testPutFloat() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putFloat(null, 3f);
- fail();
- } catch (NullPointerException e) {
- }
- pref.putFloat(longKey, 3f);
- try {
- pref.putFloat(longKey + "a", 3f);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.putFloat("testPutFloatKey", 3f);
- assertEquals("3.0", pref.get("testPutFloatKey", null));
- assertEquals(3f, pref.getFloat("testPutFloatKey", 0), 0);
- }
-
- /**
- * @test java.util.prefs.Preferences#putInt(String key, int value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putInt",
- args = {java.lang.String.class, int.class}
- )
- public void testPutInt() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putInt(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- pref.putInt(longKey, 3);
- try {
- pref.putInt(longKey + "a", 3);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.putInt("testPutIntKey", 3);
- assertEquals("3", pref.get("testPutIntKey", null));
- assertEquals(3, pref.getInt("testPutIntKey", 0));
- }
-
- /**
- * @test java.util.prefs.Preferences#putLong(String key, long value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putLong",
- args = {java.lang.String.class, long.class}
- )
- public void testPutLong() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putLong(null, 3L);
- fail();
- } catch (NullPointerException e) {
- }
- pref.putLong(longKey, 3L);
- try {
- pref.putLong(longKey + "a", 3L);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.putLong("testPutLongKey", 3L);
- assertEquals("3", pref.get("testPutLongKey", null));
- assertEquals(3L, pref.getLong("testPutLongKey", 0));
- }
-
- /**
- * @test java.util.prefs.Preferences#putByteArray(String key, byte[] value)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "putByteArray",
- args = {java.lang.String.class, byte[].class}
- )
- public void testPutByteArray() {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- try {
- pref.putByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- pref.putByteArray("testPutByteArrayKey4", null);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.putByteArray(longKey, new byte[0]);
- try {
- pref.putByteArray(longKey + "a", new byte[0]);
- fail();
- } catch (IllegalArgumentException e) {
- }
- byte[] longArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.74)];
- byte[] longerArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.75) + 1];
- pref.putByteArray(longKey, longArray);
- try {
- pref.putByteArray(longKey, longerArray);
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- pref.putByteArray("testPutByteArrayKey", new byte[0]);
- assertEquals("", pref.get("testPutByteArrayKey", null));
- assertTrue(Arrays.equals(new byte[0], pref.getByteArray(
- "testPutByteArrayKey", null)));
-
- pref.putByteArray("testPutByteArrayKey3", new byte[] { 'a', 'b', 'c' });
- assertEquals("YWJj", pref.get("testPutByteArrayKey3", null));
- assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
- .getByteArray("testPutByteArrayKey3", null)));
- }
-
- /**
- * @test java.util.prefs.Preferences#remove(String key)
- *
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "remove",
- args = {java.lang.String.class}
- )
- public void testRemove() throws BackingStoreException {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- pref.remove("key");
-
- pref.put("key", "value");
- assertEquals("value", pref.get("key", null));
- pref.remove("key");
- assertNull(pref.get("key", null));
-
- pref.remove("key");
-
- try {
- pref.remove(null);
- fail();
- } catch (NullPointerException e) {
- }
-
- pref.removeNode();
- try {
- pref.remove("key");
- fail();
- } catch (IllegalStateException e) {
- }
- }
-
- /**
- * @test java.util.prefs.Preferences#removeNode()
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Exceptions checking missed, but method is abstract, probably it is OK",
- method = "removeNode",
- args = {}
- )
- public void testRemoveNode() throws BackingStoreException {
- Preferences pref = Preferences
- .userNodeForPackage(Preferences.class);
- Preferences child = pref.node("child");
- Preferences child1 = pref.node("child1");
- Preferences grandchild = child.node("grandchild");
-
- pref.removeNode();
-
- assertFalse(child.nodeExists(""));
- assertFalse(child1.nodeExists(""));
- assertFalse(grandchild.nodeExists(""));
- assertFalse(pref.nodeExists(""));
- }
-
-
- /**
- * @test java.util.prefs.Preferences#addNodeChangeListener(NodeChangeListener ncl)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Only NullPointerException checked, but method is abstract, probably it is OK",
- method = "addNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- )
- public void testAddNodeChangeListener() throws BackingStoreException {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.addNodeChangeListener(null);
- fail();
- } catch (NullPointerException e) {
- }
-
- Preferences child1 = null;
- Preferences child2 = null;
- Preferences child3 = null;
-
- MockNodeChangeListener nl = null;
- // To get existed node doesn't create the change event
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock1");
- nl.waitForEvent();
- assertEquals(1, nl.getAdded());
- nl.reset();
- child2 = pref.node("mock1");
- nl.waitForEvent();
- assertEquals(0, nl.getAdded());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- child1.removeNode();
- }
- // same listener can be added twice, and must be removed twice
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock2");
- nl.waitForEvent();
- assertEquals(2, nl.getAdded());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- pref.removeNodeChangeListener(nl);
- child1.removeNode();
- }
- // test remove event
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock3");
- child1.removeNode();
- nl.waitForEvent();
- assertEquals(1, nl.getRemoved());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- }
- // test remove event with two listeners
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock6");
- child1.removeNode();
- nl.waitForEvent();
- assertEquals(2, nl.getRemoved());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- pref.removeNodeChangeListener(nl);
- }
- // test add/remove indirect children, or remove several children at the
- // same time
- try {
- nl = new MockNodeChangeListener();
- child1 = pref.node("mock4");
- child1.addNodeChangeListener(nl);
- child2 = pref.node("mock4/mock5");
- nl.waitForEvent();
- assertEquals(1, nl.getAdded());
- nl.reset();
- child3 = pref.node("mock4/mock5/mock6");
- nl.waitForEvent();
- assertEquals(0, nl.getAdded());
- nl.reset();
-
- child3.removeNode();
- nl.waitForEvent();
- assertEquals(0, nl.getRemoved());
- nl.reset();
-
- child3 = pref.node("mock4/mock7");
- nl.waitForEvent();
- assertEquals(1, nl.getAdded());
- nl.reset();
-
- child1.removeNode();
- nl.waitForEvent();
- assertEquals(2, nl.getRemoved()); // fail 1
- nl.reset();
- } finally {
- try {
- child1.removeNode();
- } catch (Exception e) {
- }
- }
-
- }
-
- /**
- * @test java.util.prefs.Preferences#addPreferenceChangeListener(PreferenceChangeListener pcl)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Only NullPointerException checked, but method is abstract, probably it is OK",
- method = "addPreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- )
- public void testAddPreferenceChangeListener() {
-
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- MockPreferenceChangeListener pl = null;
-
- try {
- pref.addPreferenceChangeListener(null);
- fail();
- } catch (NullPointerException e) {
- }
-
- // To get existed node doesn't create the change event
- try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.putInt("mock1", 123);
- pl.waitForEvent();
- assertEquals(1, pl.getChanged());
- pref.putLong("long_key", Long.MAX_VALUE);
- pl.waitForEvent(2);
- assertEquals(2, pl.getChanged());
- pl.reset();
- try {
- pref.clear();
- pl.waitForEvent(2);
- assertEquals(2, pl.getChanged()); // fail 1
- } catch(BackingStoreException bse) {
- pl.reset();
- fail("BackingStoreException is thrown");
- }
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- //child1.removeNode();
- }
-
- // same listener can be added twice, and must be removed twice
- try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.addPreferenceChangeListener(pl);
- pref.putFloat("float_key", Float.MIN_VALUE);
- pl.waitForEvent(2);
- assertEquals(2, pl.getChanged());
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- pref.removePreferenceChangeListener(pl);
-
- }
- // test remove event
- try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.putDouble("double_key", Double.MAX_VALUE);
- pl.waitForEvent();
- assertEquals(1, pl.getChanged());
- try {
- pref.clear();
- pl.waitForEvent(3);
- assertEquals(3, pl.getChanged()); // fails
- } catch(BackingStoreException bse) {
- fail("BackingStoreException is thrown");
- }
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- }
- // test remove event with two listeners
- try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.addPreferenceChangeListener(pl);
- pref.putByteArray("byte_array_key", new byte [] {1 ,2 , 3});
- try {
- pref.clear();
- pl.waitForEvent(4);
- assertEquals(4, pl.getChanged());
- } catch(BackingStoreException bse) {
- fail("BackingStoreException is thrown");
- }
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- pref.removePreferenceChangeListener(pl);
- }
-
- }
-
- /**
- * @test java.util.prefs.Preferences#removeNodeChangeListener(NodeChangeListener ncl)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "removeNodeChangeListener",
- args = {java.util.prefs.NodeChangeListener.class}
- )
- public void testRemoveNodeChangeListener() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.removeNodeChangeListener(null);
- fail();
- } catch (IllegalArgumentException e) {
- }
- MockNodeChangeListener l1 = new MockNodeChangeListener();
- MockNodeChangeListener l2 = new MockNodeChangeListener();
- pref.addNodeChangeListener(l1);
- pref.addNodeChangeListener(l1);
-
- pref.removeNodeChangeListener(l1);
- pref.removeNodeChangeListener(l1);
- try {
- pref.removeNodeChangeListener(l1);
- fail();
- } catch (IllegalArgumentException e) {
- }
- try {
- pref.removeNodeChangeListener(l2);
- fail();
- } catch (IllegalArgumentException e) {
- }
- }
-
- /**
- * @test java.util.prefs.Preferences#removePreferenceChangeListener(PreferenceChangeListener pcl)
- *
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- method = "removePreferenceChangeListener",
- args = {java.util.prefs.PreferenceChangeListener.class}
- )
- public void testRemovePreferenceChangeListener() {
- Preferences pref = Preferences.userNodeForPackage(Preferences.class);
- try {
- pref.removePreferenceChangeListener(null);
- fail();
- } catch (IllegalArgumentException e) {
- }
- MockPreferenceChangeListener l1 = new MockPreferenceChangeListener();
- MockPreferenceChangeListener l2 = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(l1);
- pref.addPreferenceChangeListener(l1);
- try {
- pref.removePreferenceChangeListener(l2);
- fail();
- } catch (IllegalArgumentException e) {
- }
- pref.removePreferenceChangeListener(l1);
- pref.removePreferenceChangeListener(l1);
- try {
- pref.removePreferenceChangeListener(l1);
- fail();
- } catch (IllegalArgumentException e) {
- }
-
- }
-
- static class MockInputStream extends InputStream {
-
- static final int normal = 0;
-
- static final int exception = 1;
-
- static final int runtimeException = 2;
-
- int result = normal;
-
- InputStream wrapper;
-
- public void setResult(int i) {
- result = i;
- }
-
- private void checkException() throws IOException {
- switch (result) {
- case normal:
- return;
- case exception:
- throw new IOException("test");
- case runtimeException:
- throw new RuntimeException("test");
- }
- }
-
- public MockInputStream(InputStream in) {
- wrapper = in;
- }
-
- @Override
- public int read() throws IOException {
- checkException();
- return wrapper.read();
- }
- }
-
- @SuppressWarnings("unused")
- static class MockPreferences extends Preferences {
-
- public MockPreferences() {
- super();
- }
-
- @Override
- public String absolutePath() {
- return null;
- }
-
- @Override
- public String[] childrenNames() throws BackingStoreException {
- return null;
- }
-
- @Override
- public void clear() throws BackingStoreException {
- }
-
- @Override
- public void exportNode(OutputStream ostream) throws IOException,
- BackingStoreException {
- }
-
- @Override
- public void exportSubtree(OutputStream ostream) throws IOException,
- BackingStoreException {
- }
-
- @Override
- public void flush() throws BackingStoreException {
- }
-
- @Override
- public String get(String key, String deflt) {
- return null;
- }
-
- @Override
- public boolean getBoolean(String key, boolean deflt) {
- return false;
- }
-
- @Override
- public byte[] getByteArray(String key, byte[] deflt) {
- return null;
- }
-
- @Override
- public double getDouble(String key, double deflt) {
- return 0;
- }
-
- @Override
- public float getFloat(String key, float deflt) {
- return 0;
- }
-
- @Override
- public int getInt(String key, int deflt) {
- return 0;
- }
-
- @Override
- public long getLong(String key, long deflt) {
- return 0;
- }
-
- @Override
- public boolean isUserNode() {
- return false;
- }
-
- @Override
- public String[] keys() throws BackingStoreException {
- return null;
- }
-
- @Override
- public String name() {
- return null;
- }
-
- @Override
- public Preferences node(String name) {
- return null;
- }
-
- @Override
- public boolean nodeExists(String name) throws BackingStoreException {
- return false;
- }
-
- @Override
- public Preferences parent() {
- return null;
- }
-
- @Override
- public void put(String key, String value) {
-
- }
-
- @Override
- public void putBoolean(String key, boolean value) {
-
- }
-
- @Override
- public void putByteArray(String key, byte[] value) {
-
- }
-
- @Override
- public void putDouble(String key, double value) {
-
- }
-
- @Override
- public void putFloat(String key, float value) {
-
- }
-
- @Override
- public void putInt(String key, int value) {
-
- }
-
- @Override
- public void putLong(String key, long value) {
-
- }
-
- @Override
- public void remove(String key) {
-
- }
-
- @Override
- public void removeNode() throws BackingStoreException {
-
- }
-
- @Override
- public void addNodeChangeListener(NodeChangeListener ncl) {
-
- }
-
- @Override
- public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
-
- }
-
- @Override
- public void removeNodeChangeListener(NodeChangeListener ncl) {
-
- }
-
- @Override
- public void removePreferenceChangeListener(PreferenceChangeListener pcl) {
-
- }
-
- @Override
- public void sync() throws BackingStoreException {
-
- }
-
- @Override
- public String toString() {
- return null;
- }
-
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
index 88cc015..cf030c7 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandom2Test.java
@@ -17,20 +17,14 @@
package org.apache.harmony.security.tests.java.security;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.SecureRandomSpi;
import java.security.Security;
-
import junit.framework.TestCase;
-@TestTargetClass(SecureRandom.class)
+
public class SecureRandom2Test extends TestCase {
private static final byte[] SEED_BYTES = { (byte) 33, (byte) 15, (byte) -3,
@@ -40,12 +34,6 @@ public class SecureRandom2Test extends TestCase {
private static final long SEED_VALUE = 5335486759L;
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getProvider",
- args = {}
- )
public void testGetProvider() {
SecureRandom sr1 = new SecureRandom();
assertNotNull(sr1.getProvider());
@@ -66,14 +54,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#SecureRandom()
+ * java.security.SecureRandom#SecureRandom()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SecureRandom",
- args = {}
- )
public void test_Constructor() {
// Test for method java.security.SecureRandom()
try {
@@ -84,14 +66,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#SecureRandom(byte[])
+ * java.security.SecureRandom#SecureRandom(byte[])
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SecureRandom",
- args = {byte[].class}
- )
public void test_Constructor$B() {
// Test for method java.security.SecureRandom(byte [])
try {
@@ -109,15 +85,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#SecureRandom(java.security.SecureRandomSpi,
- * java.security.Provider)
+ * java.security.SecureRandom#SecureRandom(java.security.SecureRandomSpi, java.security.Provider)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SecureRandom",
- args = {java.security.SecureRandomSpi.class, java.security.Provider.class}
- )
public void test_ConstructorLjava_security_SecureRandomSpi_java_security_Provider() {
try {
new MySecureRandom(null, null);
@@ -140,14 +109,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#generateSeed(int)
+ * java.security.SecureRandom#generateSeed(int)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "generateSeed",
- args = {int.class}
- )
public void test_generateSeedI() {
// Test for method byte [] java.security.SecureRandom.generateSeed(int)
byte[] seed = new SecureRandom().generateSeed(SEED_SIZE);
@@ -162,14 +125,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#getInstance(java.lang.String)
+ * java.security.SecureRandom#getInstance(java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {java.lang.String.class}
- )
public void test_getInstanceLjava_lang_String() {
// Test for method java.security.SecureRandom
// java.security.SecureRandom.getInstance(java.lang.String)
@@ -188,15 +145,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#getInstance(java.lang.String,
- * java.lang.String)
+ * java.security.SecureRandom#getInstance(java.lang.String, java.lang.String)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException checking missed",
- method = "getInstance",
- args = {java.lang.String.class, java.lang.String.class}
- )
public void test_getInstanceLjava_lang_StringLjava_lang_String() {
// Test for method java.security.SecureRandom
// java.security.SecureRandom.getInstance(java.lang.String,
@@ -220,14 +170,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#getSeed(int)
+ * java.security.SecureRandom#getSeed(int)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verification of negative parameter missed",
- method = "getSeed",
- args = {int.class}
- )
public void test_getSeedI() {
// Test for method byte [] java.security.SecureRandom.getSeed(int)
byte[] seed = SecureRandom.getSeed(SEED_SIZE);
@@ -242,14 +186,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#nextBytes(byte[])
+ * java.security.SecureRandom#nextBytes(byte[])
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Null array checking missed",
- method = "nextBytes",
- args = {byte[].class}
- )
public void test_nextBytes$B() {
// Test for method void java.security.SecureRandom.nextBytes(byte [])
byte[] bytes = new byte[313];
@@ -268,14 +206,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#setSeed(byte[])
+ * java.security.SecureRandom#setSeed(byte[])
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Null array checking missed",
- method = "setSeed",
- args = {byte[].class}
- )
public void test_setSeed$B() {
// Test for method void java.security.SecureRandom.setSeed(byte [])
try {
@@ -293,14 +225,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#setSeed(long)
+ * java.security.SecureRandom#setSeed(long)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setSeed",
- args = {long.class}
- )
public void test_setSeedJ() {
// Test for method void java.security.SecureRandom.setSeed(long)
try {
@@ -317,14 +243,8 @@ public class SecureRandom2Test extends TestCase {
}
/**
- * @tests java.security.SecureRandom#getAlgorithm()
+ * java.security.SecureRandom#getAlgorithm()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getAlgorithm",
- args = {}
- )
public void test_getAlgorithm() {
// Regression for HARMONY-750
@@ -350,12 +270,6 @@ public class SecureRandom2Test extends TestCase {
}
// Regression Test for HARMONY-3552.
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "next",
- args = {int.class}
- )
public void test_nextJ() throws Exception {
MySecureRandom mySecureRandom = new MySecureRandom(
new MySecureRandomSpi(), null);
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandomSpiTest.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandomSpiTest.java
index 4f04de7..dd0f3d0 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandomSpiTest.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/SecureRandomSpiTest.java
@@ -17,53 +17,19 @@
package org.apache.harmony.security.tests.java.security;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.security.SecureRandomSpi;
-
import junit.framework.TestCase;
/**
* Tests for <code>SecureRandomSpi</code> class constructors
* and methods.
- *
*/
-@TestTargetClass(SecureRandomSpi.class)
public class SecureRandomSpiTest extends TestCase {
/**
* Test for <code>SecureRandomSpi</code> constructor
* Assertion: constructs SecureRandomSpi
*/
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SecureRandomSpi",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "engineGenerateSeed",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "engineNextBytes",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "engineSetSeed",
- args = {byte[].class}
- )
- })
public void testSecureRandomSpi() {
try {
MySecureRandomSpi srs = new MySecureRandomSpi();
@@ -89,4 +55,4 @@ public class SecureRandomSpiTest extends TestCase {
return null;
}
}
-} \ No newline at end of file
+}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/AllTests.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/AllTests.java
deleted file mode 100644
index 1b0bb59..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/AllTests.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * This is autogenerated source file. Includes tests for package org.apache.harmony.sql.tests.java.sql;
- */
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All tests for package org.apache.harmony.sql.tests.java.sql;");
- // $JUnit-BEGIN$
-
- suite.addTestSuite(BatchUpdateExceptionTest.class);
- suite.addTestSuite(ConnectionTest.class);
- suite.addTestSuite(DataTruncationTest.class);
- suite.addTestSuite(DatabaseMetaDataTest.class);
- suite.addTestSuite(DateTest.class);
- suite.addTestSuite(DriverManagerTest.class);
- suite.addTestSuite(DriverPropertyInfoTest.class);
- suite.addTestSuite(ParameterMetaDataTest.class);
- suite.addTestSuite(ResultSetMetaDataTest.class);
- suite.addTestSuite(ResultSetTest.class);
- suite.addTestSuite(SQLExceptionTest.class);
- suite.addTestSuite(SQLPermissionTest.class);
- suite.addTestSuite(SQLWarningTest.class);
- suite.addTestSuite(StatementTest.class);
- suite.addTestSuite(TimeTest.class);
- suite.addTestSuite(TimestampTest.class);
- suite.addTestSuite(TypesTest.class);
-
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/BatchUpdateExceptionTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/BatchUpdateExceptionTest.java
deleted file mode 100644
index 6c84a03..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/BatchUpdateExceptionTest.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.Serializable;
-import java.sql.BatchUpdateException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(BatchUpdateException.class)
-public class BatchUpdateExceptionTest extends TestCase {
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BatchUpdateException",
- args = {}
- )
- public void testBatchUpdateException() {
-
- int[] theFinalStates1 = { 0 }; // Error Code state
- int[][] theFinalStates2 = { null }; // Update Counts array state
- String[] theFinalStates3 = { null }; // SQL State state value
- String[] theFinalStates4 = { null }; // Message state
-
- Exception[] theExceptions = { null };
-
- BatchUpdateException aBatchUpdateException;
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException();
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testBatchUpdateException
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BatchUpdateException",
- args = {int[].class}
- )
- public void testBatchUpdateExceptionintArray() {
-
- int[][] init1 = { { 1, 2, 3 }, null };
-
- int[] theFinalStates1 = { 0, 0 }; // Error Code state
- int[][] theFinalStates2 = init1; // Update Counts array state
- String[] theFinalStates3 = { null, null }; // SQL State state value
- String[] theFinalStates4 = { null, null }; // Message state
-
- Exception[] theExceptions = { null, null };
-
- BatchUpdateException aBatchUpdateException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException(init1[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testBatchUpdateExceptionintArray
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BatchUpdateException",
- args = {java.lang.String.class, int[].class}
- )
- public void testBatchUpdateExceptionStringintArray() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
- ".", "a" };
- int[][] init2 = { { 1, 2, 3 }, {}, { 3 }, null, { 5, 5 }, { 6 },
- { 121, 2, 1 }, { 1 }, { 1, 2 } };
-
- int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error Code
- // state
- // Update Counts array state
- int[][] theFinalStates2 = init2;
- // SQL State state value
- String[] theFinalStates3 = { null, null, null, null, null, null, null,
- null, null };
- String[] theFinalStates4 = init1; // Message state
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null };
-
- BatchUpdateException aBatchUpdateException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException(init1[i],
- init2[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testBatchUpdateExceptionStringintArray
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BatchUpdateException",
- args = {java.lang.String.class, java.lang.String.class, int[].class}
- )
- public void testBatchUpdateExceptionStringStringintArray() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
- ".", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", null,
- "", ".", "a" };
- int[][] init3 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
- { 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
-
- int[] theFinalStates1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // Error
- // Code
- // state
- // Update Counts array state
- int[][] theFinalStates2 = init3;
- // SQL State state value
- String[] theFinalStates3 = init2;
- String[] theFinalStates4 = init1; // Message state
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null };
-
- BatchUpdateException aBatchUpdateException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException(init1[i],
- init2[i], init3[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testBatchUpdateExceptionStringStringintArray
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "BatchUpdateException",
- args = {java.lang.String.class, java.lang.String.class, int.class, int[].class}
- )
- public void testBatchUpdateExceptionStringStringintintArray() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
- ".", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", null,
- "", ".", "a" };
- int[] init3 = { -2147483648, 2147483647, 0, -492417162, -156220255,
- -173012890, -631026360, -2147483648, -2147483648, -2147483648,
- -2147483648 };
- int[][] init4 = { { 1, 2, 3 }, {}, { 3 }, { 5, 5 }, { 6 },
- { 121, 2, 1 }, { 1 }, { 1, 2 }, { 1 }, { 2 }, null };
-
- int[] theFinalStates1 = init3; // Error Code state
- // Update Counts array state
- int[][] theFinalStates2 = init4;
- // SQL State state value
- String[] theFinalStates3 = init2;
- String[] theFinalStates4 = init1; // Message state
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null };
-
- BatchUpdateException aBatchUpdateException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException(init1[i],
- init2[i], init3[i], init4[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testBatchUpdateExceptionStringStringintintArray
-
- /*
- * Method test for getUpdateCounts
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getUpdateCounts",
- args = {}
- )
- public void testGetUpdateCounts() {
-
- BatchUpdateException aBatchUpdateException;
- int[][] init1 = { { 1, 2, 3 }, {}, null };
-
- int[] theReturn;
- int[][] theReturns = init1;
-
- int[] theFinalStates1 = { 0, 0, 0 }; // Error Code state
- int[][] theFinalStates2 = init1; // Update Counts array state
- String[] theFinalStates3 = { null, null, null }; // SQL State state
- // value
- String[] theFinalStates4 = { null, null, null }; // Message state
-
- Exception[] theExceptions = { null, null, null };
-
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aBatchUpdateException = new BatchUpdateException(init1[i]);
- theReturn = aBatchUpdateException.getUpdateCounts();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getErrorCode(),
- theFinalStates1[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getUpdateCounts(),
- theFinalStates2[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getSQLState(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch: ",
- aBatchUpdateException.getMessage(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetUpdateCounts
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Serialization test",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- BatchUpdateException object = new BatchUpdateException();
- SerializationTest.verifySelf(object, BATCHUPDATEEXCEPTION_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Serialization test",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- int vendorCode = 10;
- int[] updateCounts = { 1, 2, 3, 4 };
- BatchUpdateException object = new BatchUpdateException("reason",
- "SQLState", vendorCode, updateCounts);
- SerializationTest.verifyGolden(this, object,
- BATCHUPDATEEXCEPTION_COMPARATOR);
- }
-
- // comparator for BatchUpdateException field updateCounts
- private static final SerializableAssert BATCHUPDATEEXCEPTION_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- BatchUpdateException initThr = (BatchUpdateException) initial;
- BatchUpdateException dserThr = (BatchUpdateException) deserialized;
-
- // verify updateCounts
- int[] initUpdateCounts = initThr.getUpdateCounts();
- int[] dserUpdateCounts = dserThr.getUpdateCounts();
- assertTrue(Arrays.equals(initUpdateCounts, dserUpdateCounts));
- }
- };
-
-} // end class BatchUpdateExceptionTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ConnectionTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ConnectionTest.java
deleted file mode 100644
index 69f9e7c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ConnectionTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.Connection.class)
-public class ConnectionTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("TRANSACTION_SERIALIZABLE", new Integer(8));
- thePublicStatics.put("TRANSACTION_REPEATABLE_READ", new Integer(4));
- thePublicStatics.put("TRANSACTION_READ_COMMITTED", new Integer(2));
- thePublicStatics.put("TRANSACTION_READ_UNCOMMITTED", new Integer(1));
- thePublicStatics.put("TRANSACTION_NONE", new Integer(0));
-
- /*
- * System.out.println( "TRANSACTION_SERIALIZABLE: " +
- * Connection.TRANSACTION_SERIALIZABLE ); System.out.println(
- * "TRANSACTION_REPEATABLE_READ: " +
- * Connection.TRANSACTION_REPEATABLE_READ ); System.out.println(
- * "TRANSACTION_READ_COMMITTED: " +
- * Connection.TRANSACTION_READ_COMMITTED ); System.out.println(
- * "TRANSACTION_READ_UNCOMMITTED: " +
- * Connection.TRANSACTION_READ_UNCOMMITTED ); System.out.println(
- * "TRANSACTION_NONE: " + Connection.TRANSACTION_NONE );
- */
-
- Class<?> connectionClass;
- try {
- connectionClass = Class.forName("java.sql.Connection");
- } catch (ClassNotFoundException e) {
- fail("java.sql.Connection class not found!");
- return;
- } // end try
-
- Field[] theFields = connectionClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class ConnectionTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DataTruncationTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DataTruncationTest.java
deleted file mode 100644
index 92b7715..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DataTruncationTest.java
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.Serializable;
-import java.sql.DataTruncation;
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(DataTruncation.class)
-public class DataTruncationTest extends TestCase {
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "DataTruncation",
- args = {int.class, boolean.class, boolean.class, int.class, int.class}
- )
- public void testDataTruncationintbooleanbooleanintint() {
-
- int[] init1 = { -2147483648, 2147483647, 0, 329751502, 318587557,
- -1217247045, 329474146 };
- boolean[] init2 = { false, true, false, false, false, true, false };
- boolean[] init3 = { false, true, false, false, false, false, true };
- int[] init4 = { -2147483648, 2147483647, 0, 1761409290, -1331044048,
- -576231606, 661635011 };
- int[] init5 = { -2147483648, 2147483647, 0, 540816689, -1890783845,
- -105552912, -85923935 };
-
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- DataTruncation aDataTruncation;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testDataTruncationintbooleanbooleanintint
-
- /*
- * Method test for getIndex
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getIndex",
- args = {}
- )
- public void testGetIndex() {
-
- DataTruncation aDataTruncation;
- int[] init1 = { -2147483648, 2147483647, 0, -2045829673, 1977156911,
- 478985827, 1687271915 };
- boolean[] init2 = { false, true, false, false, true, true, true };
- boolean[] init3 = { false, true, false, false, true, true, true };
- int[] init4 = { -2147483648, 2147483647, 0, -631377748, 21025030,
- 1215194589, 1064137121 };
- int[] init5 = { -2147483648, 2147483647, 0, -897998505, 997578180,
- 735015866, 264619424 };
-
- int theReturn;
- int[] theReturns = init1;
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- theReturn = aDataTruncation.getIndex();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetIndex
-
- /*
- * Method test for getParameter
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getParameter",
- args = {}
- )
- public void testGetParameter() {
-
- DataTruncation aDataTruncation;
- int[] init1 = { -2147483648, 2147483647, 0, -492314242, 1637665948,
- -305785075, 258819883 };
- boolean[] init2 = { false, true, false, true, true, false, true };
- boolean[] init3 = { false, true, false, false, false, true, true };
- int[] init4 = { -2147483648, 2147483647, 0, 1134512579, 533874007,
- 1709608139, 990656593 };
- int[] init5 = { -2147483648, 2147483647, 0, -1566784226, -744009101,
- -444614454, 356465980 };
-
- boolean theReturn;
- boolean[] theReturns = init2;
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- theReturn = aDataTruncation.getParameter();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetParameter
-
- /*
- * Method test for getRead
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getRead",
- args = {}
- )
- public void testGetRead() {
-
- DataTruncation aDataTruncation;
- int[] init1 = { -2147483648, 2147483647, 0, 2092420209, -1695764964,
- 1832837995, -80199594 };
- boolean[] init2 = { false, true, false, false, false, true, true };
- boolean[] init3 = { false, true, false, false, true, true, false };
- int[] init4 = { -2147483648, 2147483647, 0, 1762375167, -604897453,
- 1362491587, 1007466498 };
- int[] init5 = { -2147483648, 2147483647, 0, 1494407222, -1696982311,
- -940493360, -1777579868 };
-
- boolean theReturn;
- boolean[] theReturns = init3;
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- theReturn = aDataTruncation.getRead();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetRead
-
- /*
- * Method test for getDataSize
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDataSize",
- args = {}
- )
- public void testGetDataSize() {
-
- DataTruncation aDataTruncation;
- int[] init1 = { -2147483648, 2147483647, 0, 1146707040, -2020665632,
- 1268632617, -1595624039 };
- boolean[] init2 = { false, true, false, true, false, true, true };
- boolean[] init3 = { false, true, false, true, true, false, false };
- int[] init4 = { -2147483648, 2147483647, 0, -367493363, 328996907,
- -1581326731, 835022052 };
- int[] init5 = { -2147483648, 2147483647, 0, -886134194, 908213800,
- 1123419516, -429606389 };
-
- int theReturn;
- int[] theReturns = init4;
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- theReturn = aDataTruncation.getDataSize();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetDataSize
-
- /*
- * Method test for getTransferSize
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTransferSize",
- args = {}
- )
- public void testGetTransferSize() {
-
- DataTruncation aDataTruncation;
- int[] init1 = { -2147483648, 2147483647, 0, 78096124, 1719192600,
- -1661234694, -1205825753 };
- boolean[] init2 = { false, true, false, false, true, false, true };
- boolean[] init3 = { false, true, false, false, false, false, false };
- int[] init4 = { -2147483648, 2147483647, 0, -493779295, -2042560243,
- -217347438, 1357818664 };
- int[] init5 = { -2147483648, 2147483647, 0, -1647009002, -717544563,
- -1368171905, -918209633 };
-
- int theReturn;
- int[] theReturns = init5;
- String[] theFinalStates1 = { "01004", "01004", "01004", "01004",
- "01004", "01004", "01004" };
- String state2 = "Data truncation";
- String[] theFinalStates2 = { state2, state2, state2, state2, state2,
- state2, state2 };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0 };
- int[] theFinalStates4 = init1;
- int[] theFinalStates5 = init4;
- int[] theFinalStates6 = init5;
- boolean[] theFinalStates7 = init2;
- boolean[] theFinalStates8 = init3;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aDataTruncation = new DataTruncation(init1[i], init2[i],
- init3[i], init4[i], init5[i]);
- theReturn = aDataTruncation.getTransferSize();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getSQLState(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getMessage(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getIndex(), theFinalStates4[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getDataSize(), theFinalStates5[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getTransferSize(), theFinalStates6[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getParameter(), theFinalStates7[i]);
- assertEquals(i + " Final state mismatch", aDataTruncation
- .getRead(), theFinalStates8[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetTransferSize
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Serialization test",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- DataTruncation object = new DataTruncation(10, true, true, 10, 10);
- SerializationTest.verifySelf(object, DATATRUNCATION_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Serialization test",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- DataTruncation object = new DataTruncation(10, true, true, 10, 10);
- SerializationTest.verifyGolden(this, object, DATATRUNCATION_COMPARATOR);
- }
-
- // comparator for DataTruncation objects
- private static final SerializableAssert DATATRUNCATION_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- DataTruncation initThr = (DataTruncation) initial;
- DataTruncation dserThr = (DataTruncation) deserialized;
-
- // verify index
- assertEquals(initThr.getIndex(), dserThr.getIndex());
-
- // verify parameter
- assertEquals(initThr.getParameter(), dserThr.getParameter());
-
- // verify read
- assertEquals(initThr.getRead(), dserThr.getRead());
-
- // verify dataSize
- assertEquals(initThr.getDataSize(), dserThr.getDataSize());
-
- // verify transferSize
- assertEquals(initThr.getTransferSize(), dserThr.getTransferSize());
- }
- };
-
-} // end class DataTruncationTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java
deleted file mode 100644
index 6c7a42c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DatabaseMetaDataTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.DatabaseMetaData;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.DatabaseMetaData.class)
-public class DatabaseMetaDataTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
- assertEquals(0, DatabaseMetaData.attributeNoNulls);
- assertEquals(1, DatabaseMetaData.attributeNullable);
- assertEquals(2, DatabaseMetaData.attributeNullableUnknown);
- assertEquals(1, DatabaseMetaData.bestRowNotPseudo);
- assertEquals(2, DatabaseMetaData.bestRowPseudo);
- assertEquals(2, DatabaseMetaData.bestRowSession);
- assertEquals(0, DatabaseMetaData.bestRowTemporary);
- assertEquals(1, DatabaseMetaData.bestRowTransaction);
- assertEquals(0, DatabaseMetaData.bestRowUnknown);
- assertEquals(0, DatabaseMetaData.columnNoNulls);
- assertEquals(1, DatabaseMetaData.columnNullable);
- assertEquals(2, DatabaseMetaData.columnNullableUnknown);
- assertEquals(1, DatabaseMetaData.functionColumnIn);
- assertEquals(2, DatabaseMetaData.functionColumnInOut);
- assertEquals(3, DatabaseMetaData.functionColumnOut);
- assertEquals(5, DatabaseMetaData.functionColumnResult);
- assertEquals(0, DatabaseMetaData.functionColumnUnknown);
- assertEquals(0, DatabaseMetaData.functionNoNulls);
- assertEquals(1, DatabaseMetaData.functionNoTable);
- assertEquals(1, DatabaseMetaData.functionNullable);
- assertEquals(2, DatabaseMetaData.functionNullableUnknown);
- assertEquals(0, DatabaseMetaData.functionResultUnknown);
- assertEquals(4, DatabaseMetaData.functionReturn);
- assertEquals(2, DatabaseMetaData.functionReturnsTable);
- assertEquals(0, DatabaseMetaData.importedKeyCascade);
- assertEquals(5, DatabaseMetaData.importedKeyInitiallyDeferred);
- assertEquals(6, DatabaseMetaData.importedKeyInitiallyImmediate);
- assertEquals(3, DatabaseMetaData.importedKeyNoAction);
- assertEquals(7, DatabaseMetaData.importedKeyNotDeferrable);
- assertEquals(1, DatabaseMetaData.importedKeyRestrict);
- assertEquals(4, DatabaseMetaData.importedKeySetDefault);
- assertEquals(2, DatabaseMetaData.importedKeySetNull);
- assertEquals(1, DatabaseMetaData.procedureColumnIn);
- assertEquals(2, DatabaseMetaData.procedureColumnInOut);
- assertEquals(4, DatabaseMetaData.procedureColumnOut);
- assertEquals(3, DatabaseMetaData.procedureColumnResult);
- assertEquals(5, DatabaseMetaData.procedureColumnReturn);
- assertEquals(0, DatabaseMetaData.procedureColumnUnknown);
- assertEquals(0, DatabaseMetaData.procedureNoNulls);
- assertEquals(1, DatabaseMetaData.procedureNoResult);
- assertEquals(1, DatabaseMetaData.procedureNullable);
- assertEquals(2, DatabaseMetaData.procedureNullableUnknown);
- assertEquals(0, DatabaseMetaData.procedureResultUnknown);
- assertEquals(2, DatabaseMetaData.procedureReturnsResult);
- assertEquals(2, DatabaseMetaData.sqlStateSQL);
- assertEquals(2, DatabaseMetaData.sqlStateSQL99);
- assertEquals(1, DatabaseMetaData.sqlStateXOpen);
- assertEquals(1, DatabaseMetaData.tableIndexClustered);
- assertEquals(2, DatabaseMetaData.tableIndexHashed);
- assertEquals(3, DatabaseMetaData.tableIndexOther);
- assertEquals(0, DatabaseMetaData.tableIndexStatistic);
- assertEquals(0, DatabaseMetaData.typeNoNulls);
- assertEquals(1, DatabaseMetaData.typeNullable);
- assertEquals(2, DatabaseMetaData.typeNullableUnknown);
- assertEquals(2, DatabaseMetaData.typePredBasic);
- assertEquals(1, DatabaseMetaData.typePredChar);
- assertEquals(0, DatabaseMetaData.typePredNone);
- assertEquals(3, DatabaseMetaData.typeSearchable);
- assertEquals(1, DatabaseMetaData.versionColumnNotPseudo);
- assertEquals(2, DatabaseMetaData.versionColumnPseudo);
- assertEquals(0, DatabaseMetaData.versionColumnUnknown);
- } // end method testPublicStatics
-
-} // end class DatabaseMetaDataTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
deleted file mode 100644
index dc04269..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DateTest.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.Date;
-import java.util.Calendar;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-@TestTargetClass(Date.class)
-/**
- * JUnit Testcase for the java.sql.Date class
- *
- */
-public class DateTest extends TestCase {
-
- // A calendar object created in the GMT time zone
- static Calendar aCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-
- // Some interesting millisecond time values
- // These millisecond times are all in GMT, effectively
- static long TIME_AN_HOUR = 3600000; // 1000 * 60 * 60 ms
-
- static long TIME_EPOCH = 0;
-
- static long TIME_NOW = System.currentTimeMillis();
-
- static long TIME_NEGATIVE = -3600001;
-
- static long TIME_TESTDATE1 = getTime(1999, Calendar.DECEMBER, 31, 23, 59,
- 59);
-
- static long TIME_TESTDATE2 = getTime(2010, Calendar.JUNE, 10, 20, 3, 16);
-
- static long TIME_TESTDATE3 = getTime(1931, Calendar.APRIL, 21, 1, 25, 1);
-
- static long TIME_LOWERLIMIT = Long.MIN_VALUE;
-
- static long TIME_UPPERLIMIT = Long.MAX_VALUE;
-
- // Date strings
- static String SQL_DATESTRING1 = "1999-12-31";
-
- static String SQL_DATESTRING2 = "2010-06-10";
-
- static String SQL_DATESTRING3 = "1931-04-21";
-
- static String SQL_EPOCHSTRING = "1970-01-01";
-
- static String SQL_DATEDAY1 = "1970-01-02";
-
- static String SQL_NEGATIVE = "1969-12-31";
-
- static long[] TIME_ARRAY = new long[] { TIME_TESTDATE1, TIME_TESTDATE2,
- TIME_TESTDATE3, TIME_NEGATIVE, TIME_EPOCH };
-
- // Date string array for London (GMT)
- static String[] SQL_DATEARRAY = new String[] { SQL_DATESTRING1,
- SQL_DATESTRING2, SQL_DATESTRING3, SQL_NEGATIVE, SQL_EPOCHSTRING };
-
- // Date string array for New York - sometimes a day earlier than London
- static String[] SQL_NYARRAY = new String[] { "1999-12-31", "2010-06-10",
- "1931-04-20", "1969-12-31", "1969-12-31" };
-
- // Date string for Tokyo
- static String[] SQL_JAPANARRAY = new String[] { "2000-01-01", "2010-06-11",
- "1931-04-21", "1970-01-01", "1970-01-01" };
-
- static String[][] SQL_TZ_DATEARRAYS = new String[][] { SQL_DATEARRAY,
- SQL_NYARRAY, SQL_JAPANARRAY };
-
- // Timezones
- static String TZ_LONDON = "Europe/London"; // Note: != GMT
-
- static String TZ_PACIFIC = "America/Los_Angeles"; // GNT - 8
-
- static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
-
- static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
-
- /*
- * Helper method to create a long milliseconds time from a supplied date and
- * time
- */
- static private long getTime(int year, int month, int date, int hour,
- int minute, int second) {
- aCal.set(year, month, date, hour, minute, second);
- return aCal.getTimeInMillis();
- } // end method getTime( int, int, int, int, int, int )
-
- /*
- * Test of the Date(int, int, int) constructor - now deprecated but still
- * functioning
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Date",
- args = {int.class, int.class, int.class}
- )
- @SuppressWarnings("deprecation")
- public void testDateintintint() {
-
- int init1[] = { 99, 8099, 9000, 99999, 99, 99, -1, -100 };
- int init2[] = { 11, 0, 0, 0, 999, 0, 0, -111 };
- int init3[] = { 31, 0, 0, 0, 0, 999, 0, -999 };
-
- for (int i = 0; i < init1.length; i++) {
- Date theDate = new Date(init1[i], init2[i], init3[i]);
- assertNotNull(theDate);
- } // end for
-
- } // end method testDateintintint
-
- /*
- * Test of the Date( long ) constructor
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Date",
- args = {long.class}
- )
- public void testDatelong() {
-
- long init1[] = { TIME_TESTDATE1, TIME_TESTDATE2, TIME_TESTDATE3,
- TIME_NEGATIVE, TIME_LOWERLIMIT, TIME_UPPERLIMIT, TIME_EPOCH,
- TIME_NOW };
-
- for (long element : init1) {
- Date theDate = new Date(element);
- assertNotNull(theDate);
- } // end for
-
- } // end method testDatelong
-
- /*
- * Test of the (deprecated) int Date.getHours() method - which always throws
- * an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getHours",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetHours() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.getHours();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
- } // end method testGetHours()
-
- /*
- * Test of the (deprecated) int Date.getMinutes() method - which always
- * throws an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMinutes",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetMinutes() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.getMinutes();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
- } // end method testGetMinutes()
-
- /*
- * Test of the (deprecated) int Date.getSeconds() method - which always
- * throws an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getSeconds",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetSeconds() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.getSeconds();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
- } // end method testGetSeconds()
-
- /*
- * Test of the (deprecated) Date.setHours( int ) method - which always
- * throws an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setHours",
- args = {int.class}
- )
- @SuppressWarnings("deprecation")
- public void testSetHours() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.setHours(22);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
- } // end method testSetHours( int )
-
- /*
- * Test of the (deprecated) Date.setMinutes( int ) method - which always
- * throws an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setMinutes",
- args = {int.class}
- )
- @SuppressWarnings("deprecation")
- public void testSetMinutes() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.setMinutes(54);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
-
- } // end method testSetMinutes( int )
-
- /*
- * Test of the (deprecated) Date.setSeconds( int ) method - which always
- * throws an IllegalArgumentException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setSeconds",
- args = {int.class}
- )
- @SuppressWarnings("deprecation")
- public void testSetSeconds() {
- Date theDate = new Date(TIME_TESTDATE1);
- try {
- theDate.setSeconds(36);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException ie) {
- //expected
- } // end try
- } // end method testSetSeconds( int )
-
- /*
- * Test of the String Date.toString() method This method is sensitive to the
- * time zone setting and this test sets the time zone before calling the
- * toString() method.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- // Loop through the timezones testing the String conversion for each
- for (int i = 0; i < TIMEZONES.length; i++) {
- testToString(TIMEZONES[i], TIME_ARRAY, SQL_TZ_DATEARRAYS[i]);
- } // end for
-
- } // end method testToString()
-
- private void testToString(String timeZone, long[] theDates, String[] theDateStrings) {
- // Set the timezone
- TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
-
- for (int i = 0; i < theDates.length; i++) {
- // Create the Date object
- Date theDate = new Date(theDates[i]);
- // Convert to a date string ... and compare
- String JDBCString = theDate.toString();
- assertEquals(theDateStrings[i], JDBCString);
- } // end for
-
- } // end testToString( String, long[], String[] )
-
- /*
- * Test of the void setTime(int) method This does depend on the Time Zone
- * settings and sets up the time zone to one of a group of specific time
- * zones and tests the method using each of these time zones in turn.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {long.class}
- )
- public void testSetTimelong() {
-
- // Loop over the array of test timezones
- for (int i = 0; i < TIMEZONES.length; i++) {
- testSetTimelong(TIMEZONES[i], SQL_TZ_DATEARRAYS[i]);
- } // end for
-
- } // end method testSetTimelong()
-
- /*
- * Internal method for testing Date.setTime with a specific time zone
- */
- private void testSetTimelong(String timeZoneName, String[] dateArray) {
-
- if (timeZoneName != null) {
- TimeZone.setDefault(TimeZone.getTimeZone(timeZoneName));
- } // end if
-
- Date theDate = new Date(TIME_TESTDATE1);
-
- // Loop over the array of test times & dates
- for (int i = 0; i < dateArray.length; i++) {
- theDate.setTime(TIME_ARRAY[i]);
- assertEquals(dateArray[i], theDate.toString());
- } // end for
-
- } // end method testSetTimelong()
-
- /*
- * Test of the Date.valueOf( String ) method This test is not dependent on
- * the default Time Zone setting
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void testValueOf() {
- String SQL_NOTVALID1 = "ABCDEF"; // Invalid date string
- String SQL_NOTVALID2 = "12321.43.56"; // Invalid date string
- String SQL_NOTVALID3 = null; // Invalid date string
- String[] SQL_INVALIDARRAY = { SQL_NOTVALID1, SQL_NOTVALID2,
- SQL_NOTVALID3 };
-
- Date theDate;
-
- for (String element : SQL_DATEARRAY) {
- theDate = Date.valueOf(element);
- assertEquals(element, theDate.toString());
- } // end for
-
- for (String element : SQL_INVALIDARRAY) {
- try {
- theDate = Date.valueOf(element);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // expected
- } // end try
- } // end for
-
- } // end method testValueOf()
-
- /**
- * @tests java.sql.Date#valueOf(String )
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOf_IllegalArgumentException() {
- try {
- Date.valueOf("1996-10-07-01");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Date.valueOf("-10-07-01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("--01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("1991--");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("-01-");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("-10-w2-01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("07-w2-");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- Date.valueOf("1997-w2-w2");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
-
- try {
- Date.valueOf("1996--01");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- // expected
- }
- }
-
- // Reset defualt timezone
- static TimeZone defaultTimeZone = TimeZone.getDefault();
-
- protected void tearDown(){
- TimeZone.setDefault(defaultTimeZone);
- }
-
-} // end class DateTest
-
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
deleted file mode 100644
index 276fdb3..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
+++ /dev/null
@@ -1,713 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.io.PrintWriter;
-import java.lang.reflect.Method;
-import java.security.Permission;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.DriverPropertyInfo;
-import java.sql.SQLException;
-import java.sql.SQLPermission;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-import static tests.support.Support_Exec.javaProcessBuilder;
-import static tests.support.Support_Exec.execAndGetOutput;
-
-@TestTargetClass(DriverManager.class)
-/**
- * JUnit Testcase for the java.sql.DriverManager class
- *
- */
-public class DriverManagerTest extends TestCase {
-
- // Set of driver names to use
- static final String DRIVER1 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1";
-
- static final String DRIVER2 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2";
-
- static final String DRIVER3 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
-
- static final String DRIVER4 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4";
-
- static final String DRIVER5 = "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5";
-
- static final String INVALIDDRIVER1 = "abc.klm.Foo";
-
- static String[] driverNames = { DRIVER1, DRIVER2 };
-
- static int numberLoaded;
-
- static String baseURL1 = "jdbc:mikes1";
-
- static String baseURL4 = "jdbc:mikes4";
-
- static final String JDBC_PROPERTY = "jdbc.drivers";
-
- static TestHelper_ClassLoader testClassLoader = new TestHelper_ClassLoader();
-
- // Static initializer to load the drivers so that they are available to all
- // the
- // test methods as needed.
- @Override
- public void setUp() {
- numberLoaded = loadDrivers();
- } // end setUp()
-
- /**
- * Test for the method DriverManager.deregisterDriver
- * @throws SQLException
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SQLException checking missed: not feasible.",
- method = "deregisterDriver",
- args = {java.sql.Driver.class}
- )
- @KnownFailure("Not all Drivers are loaded in testsetup. Classloader issue in DriverManager.")
- public void testDeregisterDriver() throws Exception {
- // First get one of the drivers loaded by the test
- Driver aDriver;
- aDriver = DriverManager.getDriver(baseURL4);
-
- // Deregister this driver
- DriverManager.deregisterDriver(aDriver);
-
- assertFalse("testDeregisterDriver: Driver was not deregistered.",
- isDriverLoaded(aDriver));
-
- // Re-register this driver (so subsequent tests have it available)
- DriverManager.registerDriver(aDriver);
- assertTrue("testDeregisterDriver: Driver did not reload.",
- isDriverLoaded(aDriver));
-
- // Test deregistering a null driver
- DriverManager.deregisterDriver(null);
-
- // Test deregistering a driver which was not loaded by this test's
- // classloader
- // TODO - need to load a driver with a different classloader!!
- aDriver = DriverManager.getDriver(baseURL1);
-
- try {
- Class<?> driverClass = Class
- .forName(
- "org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager",
- true, testClassLoader);
-
- // Give the Helper class one of our drivers....
- Class<?>[] methodClasses = {Class.forName("java.sql.Driver")};
- Method theMethod = driverClass.getDeclaredMethod("setDriver",
- methodClasses);
- Object[] args = {aDriver};
- assertNotNull(args);
- theMethod.invoke(null, args);
- } catch (Exception e) {
- fail("testDeregisterDriver: Got exception allocating TestHelper: "
- + e.getMessage());
- e.printStackTrace();
- return;
- } // end try
-
- // Check that the driver was not deregistered
- assertTrue(
- "testDeregisterDriver: Driver was incorrectly deregistered.",
- DriverManagerTest.isDriverLoaded(aDriver));
-
- } // end method testDeregisterDriver()
-
- static void printClassLoader(Object theObject) {
- Class<? extends Object> theClass = theObject.getClass();
- ClassLoader theClassLoader = theClass.getClassLoader();
- System.out.println("ClassLoader is: " + theClassLoader.toString()
- + " for object: " + theObject.toString());
- } // end method printClassLoader( Object )
-
- static boolean isDriverLoaded(Driver theDriver) {
- Enumeration<?> driverList = DriverManager.getDrivers();
- while (driverList.hasMoreElements()) {
- if ((Driver) driverList.nextElement() == theDriver) {
- return true;
- }
- } // end while
- return false;
- } // end method isDriverLoaded( Driver )
-
- /*
- * Class under test for Connection getConnection(String)
- */
- // valid connection - data1 does not require a user and password...
- static String validConnectionURL = "jdbc:mikes1:data1";
-
- // invalid connection - data2 requires a user & password
- static String invalidConnectionURL1 = "jdbc:mikes1:data2";
-
- // invalid connection - URL is gibberish
- static String invalidConnectionURL2 = "xyz1:abc3:456q";
-
- // invalid connection - URL is null
- static String invalidConnectionURL3 = null;
-
- static String[] invalidConnectionURLs = { invalidConnectionURL2,
- invalidConnectionURL3 };
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConnection",
- args = {java.lang.String.class}
- )
- public void testGetConnectionString() throws SQLException {
- Connection theConnection = null;
- // validConnection - no user & password required
- theConnection = DriverManager.getConnection(validConnectionURL);
- assertNotNull(theConnection);
- assertNotNull(DriverManager.getConnection(invalidConnectionURL1));
-
- for (String element : invalidConnectionURLs) {
- try {
- theConnection = DriverManager
- .getConnection(element);
- fail("Should throw SQLException");
- } catch (SQLException e) {
- //expected
- } // end try
- } // end for
- } // end method testGetConnectionString()
-
- /**
- * @tests java.sql.DriverManager#getConnection(String, Properties)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConnection",
- args = {java.lang.String.class, java.util.Properties.class}
- )
- public void test_getConnection_LStringLProperties() {
- try {
- DriverManager.getConnection("fff",
- new Properties());
- fail("Should throw SQLException.");
- } catch (SQLException e) {
- assertEquals("08001", e.getSQLState());
- }
-
- try {
- DriverManager.getConnection(null,
- new Properties());
- fail("Should throw SQLException.");
- } catch (SQLException e) {
- assertEquals("08001", e.getSQLState());
- }
- }
-
- /*
- * Class under test for Connection getConnection(String, Properties)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConnection",
- args = {java.lang.String.class, java.util.Properties.class}
- )
- public void testGetConnectionStringProperties() throws SQLException {
- String validURL1 = "jdbc:mikes1:data2";
- String validuser1 = "theuser";
- String validpassword1 = "thepassword";
- String invalidURL1 = "xyz:abc1:foo";
- String invalidURL2 = "jdbc:mikes1:crazyone";
- String invalidURL3 = "";
- String invaliduser1 = "jonny nouser";
- String invalidpassword1 = "whizz";
- Properties nullProps = null;
- Properties validProps = new Properties();
- validProps.setProperty("user", validuser1);
- validProps.setProperty("password", validpassword1);
- Properties invalidProps1 = new Properties();
- invalidProps1.setProperty("user", invaliduser1);
- invalidProps1.setProperty("password", invalidpassword1);
- String[] invalidURLs = { null, invalidURL1,
- invalidURL2, invalidURL3 };
- Properties[] invalidProps = { nullProps, invalidProps1};
-
-
-
- Connection theConnection = null;
- // validConnection - user & password required
- theConnection = DriverManager.getConnection(validURL1, validProps);
- assertNotNull(theConnection);
-
- // invalid Connections
- for (int i = 0; i < invalidURLs.length; i++) {
- theConnection = null;
- try {
- theConnection = DriverManager.getConnection(invalidURLs[i],
- validProps);
- fail("Should throw SQLException");
- } catch (SQLException e) {
- //expected
- } // end try
- } // end for
- for (Properties invalidProp : invalidProps) {
- assertNotNull(DriverManager.getConnection(validURL1, invalidProp));
- }
- } // end method testGetConnectionStringProperties()
-
- /*
- * Class under test for Connection getConnection(String, String, String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getConnection",
- args = {java.lang.String.class, java.lang.String.class, java.lang.String.class}
- )
- public void testGetConnectionStringStringString() throws SQLException {
- String validURL1 = "jdbc:mikes1:data2";
- String validuser1 = "theuser";
- String validpassword1 = "thepassword";
- String invalidURL1 = "xyz:abc1:foo";
- String invaliduser1 = "jonny nouser";
- String invalidpassword1 = "whizz";
- String[] invalid1 = { null, validuser1, validpassword1 };
- String[] invalid2 = { validURL1, null, validpassword1 };
- String[] invalid3 = { validURL1, validuser1, null };
- String[] invalid4 = { invalidURL1, validuser1, validpassword1 };
- String[] invalid5 = { validURL1, invaliduser1, invalidpassword1 };
- String[] invalid6 = { validURL1, validuser1, invalidpassword1 };
- String[][] invalids1 = { invalid1, invalid4};
- String[][] invalids2 = {invalid2, invalid3, invalid5, invalid6 };
-
- Connection theConnection = null;
- // validConnection - user & password required
- theConnection = DriverManager.getConnection(validURL1, validuser1,
- validpassword1);
- assertNotNull(theConnection);
- for (String[] theData : invalids1) {
- theConnection = null;
- try {
- theConnection = DriverManager.getConnection(theData[0],
- theData[1], theData[2]);
- fail("Should throw SQLException.");
- } catch (SQLException e) {
- //expected
- } // end try
- } // end for
- for (String[] theData : invalids2) {
- assertNotNull(DriverManager.getConnection(theData[0], theData[1],
- theData[2]));
- }
- } // end method testGetConnectionStringStringString()
-
- static String validURL1 = "jdbc:mikes1";
-
- static String validURL2 = "jdbc:mikes2";
-
- static String invalidURL1 = "xyz:acb";
-
- static String invalidURL2 = null;
-
- static String[] validURLs = { validURL1, validURL2 };
-
- static String[] invalidURLs = { invalidURL1, invalidURL2 };
-
- static String exceptionMsg1 = "No suitable driver";
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDriver",
- args = {java.lang.String.class}
- )
- public void testGetDriver() throws SQLException {
- for (String element : validURLs) {
- Driver validDriver = DriverManager.getDriver(element);
- assertNotNull("Driver " + element + " not loaded", validDriver);
- } // end for
-
- for (String element : invalidURLs) {
- try {
- DriverManager.getDriver(element);
- fail("Should throw SQLException");
- } catch (SQLException e) {
- assertEquals("08001", e.getSQLState());
- assertEquals(exceptionMsg1, e.getMessage());
- } // end try
- } // end for
-
- } // end method testGetDriver()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "test only passes in CTS host environment.",
- method = "getDrivers",
- args = {}
- )
- public void testGetDrivers() {
- // Load a driver manager
- Enumeration<Driver> driverList = DriverManager.getDrivers();
- int i = 0;
- while (driverList.hasMoreElements()) {
- Driver theDriver = driverList.nextElement();
- assertNotNull(theDriver);
- i++;
- } // end while
-
- // Check that all the drivers are in the list...
- // There might be other drivers loaded in other classes
- assertTrue("testGetDrivers: Don't see all the loaded drivers - ",
- i >= numberLoaded);
- } // end method testGetDrivers()
-
- static int timeout1 = 25;
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLoginTimeout",
- args = {}
- )
- public void testGetLoginTimeout() {
- DriverManager.setLoginTimeout(timeout1);
- assertEquals(timeout1, DriverManager.getLoginTimeout());
- } // end method testGetLoginTimeout()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLogStream",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetLogStream() {
- assertNull(DriverManager.getLogStream());
-
- DriverManager.setLogStream(testPrintStream);
- assertTrue(DriverManager.getLogStream() == testPrintStream);
-
- DriverManager.setLogStream(null);
- } // end method testGetLogStream()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLogWriter",
- args = {}
- )
- public void testGetLogWriter() {
- assertNull(DriverManager.getLogWriter());
-
- DriverManager.setLogWriter(testPrintWriter);
-
- assertTrue(DriverManager.getLogWriter() == testPrintWriter);
-
- DriverManager.setLogWriter(null);
- } // end method testGetLogWriter()
-
- static String testMessage = "DriverManagerTest: test message for print stream";
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "println",
- args = {java.lang.String.class}
- )
- @SuppressWarnings("deprecation")
- public void testPrintln() {
- // System.out.println("testPrintln");
- DriverManager.println(testMessage);
-
- DriverManager.setLogWriter(testPrintWriter);
- DriverManager.println(testMessage);
-
- String theOutput = outputStream.toString();
- // System.out.println("testPrintln: output= " + theOutput );
- assertTrue(theOutput.startsWith(testMessage));
-
- DriverManager.setLogWriter(null);
-
- DriverManager.setLogStream(testPrintStream);
- DriverManager.println(testMessage);
-
- theOutput = outputStream2.toString();
- // System.out.println("testPrintln: output= " + theOutput );
- assertTrue(theOutput.startsWith(testMessage));
-
- DriverManager.setLogStream(null);
- } // end method testPrintln()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "SQLException checking missed: not feasible",
- method = "registerDriver",
- args = {java.sql.Driver.class}
- )
- public void testRegisterDriver() throws ClassNotFoundException,
- SQLException, IllegalAccessException, InstantiationException {
- // This is DRIVER3
- // String EXTRA_DRIVER_NAME =
- // "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver3";
-
- try {
- DriverManager.registerDriver(null);
- fail("Should throw NullPointerException.");
- } catch (NullPointerException e) {
- // expected
- } // end try
-
- Driver theDriver = null;
- // Load another Driver that isn't in the basic set
- Class<?> driverClass = Class.forName(DRIVER3);
- theDriver = (Driver) driverClass.newInstance();
- DriverManager.registerDriver(theDriver);
-
- assertTrue("testRegisterDriver: driver not in loaded set",
- isDriverLoaded(theDriver));
-
-
-
- } // end testRegisterDriver()
-
- static int validTimeout1 = 15;
-
- static int validTimeout2 = 0;
-
- static int[] validTimeouts = { validTimeout1, validTimeout2 };
-
- static int invalidTimeout1 = -10;
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLoginTimeout",
- args = {int.class}
- )
- public void testSetLoginTimeout() {
- for (int element : validTimeouts) {
- DriverManager.setLoginTimeout(element);
-
- assertEquals(element, DriverManager.getLoginTimeout());
- } // end for
- // Invalid timeouts
- DriverManager.setLoginTimeout(invalidTimeout1);
- assertEquals(invalidTimeout1, DriverManager.getLoginTimeout());
- } // end testSetLoginTimeout()
-
- static ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream();
-
- static PrintStream testPrintStream = new PrintStream(outputStream2);
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLogStream",
- args = {java.io.PrintStream.class}
- )
- @SuppressWarnings("deprecation")
- public void testSetLogStream() {
- // System.out.println("testSetLogStream");
- DriverManager.setLogStream(testPrintStream);
-
- assertSame(testPrintStream, DriverManager.getLogStream());
-
- DriverManager.setLogStream(null);
-
- assertNull(DriverManager.getLogStream());
- } // end method testSetLogStream()
-
- static ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
-
- static PrintWriter testPrintWriter = new PrintWriter(outputStream);
-
- /**
- * Test for the setLogWriter method
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLogWriter",
- args = {java.io.PrintWriter.class}
- )
- public void testSetLogWriter() {
- // System.out.println("testSetLogWriter");
- DriverManager.setLogWriter(testPrintWriter);
-
- assertSame(testPrintWriter, DriverManager.getLogWriter());
-
- DriverManager.setLogWriter(null);
-
- assertNull("testDriverManager: Log writer not null:", DriverManager
- .getLogWriter());
- } // end method testSetLogWriter()
-
- /*
- * Method which loads a set of JDBC drivers ready for use by the various
- * tests @return the number of drivers loaded
- */
- static boolean driversLoaded = false;
-
- private static int loadDrivers() {
- if (driversLoaded) {
- return numberLoaded;
- }
- /*
- * First define a value for the System property "jdbc.drivers" - before
- * the DriverManager class is loaded - this property defines a set of
- * drivers which the DriverManager will load during its initialization
- * and which will be loaded on the System ClassLoader - unlike the ones
- * loaded later by this method which are loaded on the Application
- * ClassLoader.
- */
- int numberLoaded = 0;
- String theSystemDrivers = DRIVER4 + ":" + DRIVER5 + ":"
- + INVALIDDRIVER1;
- System.setProperty(JDBC_PROPERTY, theSystemDrivers);
- numberLoaded += 2;
-
- for (String element : driverNames) {
- try {
- Class<?> driverClass = Class.forName(element);
- assertNotNull(driverClass);
- System.out.println("Loaded driver - classloader = " +
- driverClass.getClassLoader());
- numberLoaded++;
- } catch (ClassNotFoundException e) {
- System.out.println("DriverManagerTest: failed to load Driver: "
- + element);
- } // end try
- } // end for
- driversLoaded = true;
- return numberLoaded;
- } // end method loadDrivers()
-
- class TestSecurityManager extends SecurityManager {
-
- boolean logAccess = true;
-
- SQLPermission sqlPermission = new SQLPermission("setLog");
-
- RuntimePermission setManagerPermission = new RuntimePermission(
- "setSecurityManager");
-
- TestSecurityManager() {
- super();
- } // end method TestSecurityManager()
-
- void setLogAccess(boolean allow) {
- logAccess = allow;
- } // end method setLogAccess( boolean )
-
- @Override
- public void checkPermission(Permission thePermission) {
- if (thePermission.equals(sqlPermission)) {
- if (!logAccess) {
- throw new SecurityException("Cannot set the sql Log Writer");
- } // end if
- return;
- } // end if
-
- if (thePermission.equals(setManagerPermission)) {
- return;
- } // end if
- // super.checkPermission( thePermission );
- } // end method checkPermission( Permission )
-
- } // end class TestSecurityManager
-
- /**
- * @tests {@link java.sql.DriverManager#registerDriver(Driver)}
- *
- * Registers a driver for multiple times and deregisters it only once.
- *
- * Regression for HARMONY-4205
- */
- public void test_registerDriver_MultiTimes() throws SQLException {
- int register_count = 10;
- int deregister_count = 1;
-
- Driver dummy = new DummyDriver();
- DriverManager.registerDriver(new BadDummyDriver());
- for (int i = 0; i < register_count; i++) {
- DriverManager.registerDriver(dummy);
- }
- DriverManager.registerDriver(new BadDummyDriver());
- for (int i = 0; i < deregister_count; i++) {
- DriverManager.deregisterDriver(dummy);
- }
- Driver d = DriverManager.getDriver("jdbc:dummy_protocol:dummy_subname");
- assertNotNull(d);
- }
-
- /**
- * Regression for HARMONY-4303
- */
- public void test_initClass() throws Exception {
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("org/apache/harmony/sql/tests/java/sql/TestMainForDriver");
- assertEquals("", execAndGetOutput(builder));
- }
-
- private static class BadDummyDriver extends DummyDriver {
- public boolean acceptsURL(String url) {
- return false;
- }
- }
-
- private static class DummyDriver implements Driver {
-
- String goodurl = "jdbc:dummy_protocol:dummy_subname";
-
- public boolean acceptsURL(String url) {
- return url.equals(goodurl);
- }
-
- public Connection connect(String url, Properties info) {
- return null;
- }
-
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
- return null;
- }
-
- public int getMajorVersion() {
- return 0;
- }
-
- public int getMinorVersion() {
- return 0;
- }
-
- public boolean jdbcCompliant() {
- return true;
- }
-
- }
-
-} // end class DriverManagerTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java
deleted file mode 100644
index af3cc6c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverPropertyInfoTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import SQLite.JDBCDriver;
-import dalvik.annotation.BrokenTest;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.DriverPropertyInfo;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-@TestTargetClass(DriverPropertyInfo.class)
-/**
- * JUnit Testcase for the java.sql.DriverPropertyInfo class
- *
- */
-
-public class DriverPropertyInfoTest extends TestCase {
-
- /*
- * Constructor test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verification with invalid parameters missed: no feasible behaviour not specified (black box approach).",
- method = "DriverPropertyInfo",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testDriverPropertyInfoStringString() {
-
- DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
- validName, validValue);
-
- assertNotNull(aDriverPropertyInfo);
-
- assertEquals(aDriverPropertyInfo.name,validName);
- assertEquals(aDriverPropertyInfo.value,validValue);
-
- aDriverPropertyInfo = new DriverPropertyInfo(null, null);
-
- assertNotNull(aDriverPropertyInfo);
- assertNull(aDriverPropertyInfo.name);
- assertNull(aDriverPropertyInfo.value);
-
- } // end method testDriverPropertyInfoStringString
-
- /*
- * Public fields test
- */
- static String validName = "testname";
-
- static String validValue = "testvalue";
-
- static String[] updateChoices = { "Choice1", "Choice2", "Choice3" };
-
- static String updateValue = "updateValue";
-
- static boolean updateRequired = true;
-
- static String updateDescription = "update description";
-
- static String updateName = "updateName";
-
- String connectionURL = "jdbc:sqlite:/" + "Test.db";
-
- String classname = "SQLite.JDBCDriver";
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicFields() {
-
- // Constructor here...
- DriverPropertyInfo aDriverPropertyInfo = new DriverPropertyInfo(
- validName, validValue);
-
- assertTrue(Arrays.equals(testChoices, aDriverPropertyInfo.choices));
- assertEquals(testValue, aDriverPropertyInfo.value);
- assertEquals(testRequired, aDriverPropertyInfo.required);
- assertEquals(testDescription, aDriverPropertyInfo.description);
- assertEquals(testName, aDriverPropertyInfo.name);
-
- aDriverPropertyInfo.choices = updateChoices;
- aDriverPropertyInfo.value = updateValue;
- aDriverPropertyInfo.required = updateRequired;
- aDriverPropertyInfo.description = updateDescription;
- aDriverPropertyInfo.name = updateName;
-
- assertTrue(Arrays.equals(updateChoices, aDriverPropertyInfo.choices));
- assertEquals(updateValue, aDriverPropertyInfo.value);
- assertEquals(updateRequired, aDriverPropertyInfo.required);
- assertEquals(updateDescription, aDriverPropertyInfo.description);
- assertEquals(updateName, aDriverPropertyInfo.name);
-
- //functional test
- try {
- Class.forName(classname).newInstance();
- Properties props = new Properties();
- Driver d = DriverManager.getDriver(connectionURL);
- DriverPropertyInfo[] info = d.getPropertyInfo(connectionURL,
- props);
- // get the property metadata
- String name = info[0].name;
- assertNotNull(name);
- assertEquals(name, "encoding");
- String[] choices = info[0].choices;
- assertNull(choices);
- boolean required = info[0].required;
- assertFalse(required);
- String description = info[0].description;
- assertNull(description);
-
- } catch (SQLException e) {
- System.out.println("Error in test setup: " + e.getMessage());
- e.printStackTrace();
- } catch (Exception ex) {
- System.err.println("Unexpected exception " + ex.toString());
- }
-
-
- } // end method testPublicFields
-
- // Default values...
- static String[] testChoices = null;
-
- static java.lang.String testValue = validValue;
-
- static boolean testRequired = false;
-
- static java.lang.String testDescription = null;
-
- static java.lang.String testName = validName;
-
-} // end class DriverPropertyInfoTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ParameterMetaDataTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ParameterMetaDataTest.java
deleted file mode 100644
index 8c16a39..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ParameterMetaDataTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.ParameterMetaData.class)
-public class ParameterMetaDataTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("parameterModeOut", new Integer(4));
- thePublicStatics.put("parameterModeInOut", new Integer(2));
- thePublicStatics.put("parameterModeIn", new Integer(1));
- thePublicStatics.put("parameterModeUnknown", new Integer(0));
- thePublicStatics.put("parameterNullableUnknown", new Integer(2));
- thePublicStatics.put("parameterNullable", new Integer(1));
- thePublicStatics.put("parameterNoNulls", new Integer(0));
-
- /*
- * System.out.println( "parameterModeOut: " +
- * ParameterMetaData.parameterModeOut ); System.out.println(
- * "parameterModeInOut: " + ParameterMetaData.parameterModeInOut );
- * System.out.println( "parameterModeIn: " +
- * ParameterMetaData.parameterModeIn ); System.out.println(
- * "parameterModeUnknown: " + ParameterMetaData.parameterModeUnknown );
- * System.out.println( "parameterNullableUnknown: " +
- * ParameterMetaData.parameterNullableUnknown ); System.out.println(
- * "parameterNullable: " + ParameterMetaData.parameterNullable );
- * System.out.println( "parameterNoNulls: " +
- * ParameterMetaData.parameterNoNulls );
- */
-
- Class<?> parameterMetaDataClass;
- try {
- parameterMetaDataClass = Class
- .forName("java.sql.ParameterMetaData");
- } catch (ClassNotFoundException e) {
- fail("java.sql.ParameterMetaData class not found!");
- return;
- } // end try
-
- Field[] theFields = parameterMetaDataClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class ParameterMetaDataTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetMetaDataTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetMetaDataTest.java
deleted file mode 100644
index f0c231b..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetMetaDataTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.ResultSetMetaData.class)
-public class ResultSetMetaDataTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("columnNullableUnknown", new Integer(2));
- thePublicStatics.put("columnNullable", new Integer(1));
- thePublicStatics.put("columnNoNulls", new Integer(0));
-
- /*
- * System.out.println( "columnNullableUnknown: " +
- * ResultSetMetaData.columnNullableUnknown ); System.out.println(
- * "columnNullable: " + ResultSetMetaData.columnNullable );
- * System.out.println( "columnNoNulls: " +
- * ResultSetMetaData.columnNoNulls );
- */
-
- Class<?> resultSetMetaDataClass;
- try {
- resultSetMetaDataClass = Class
- .forName("java.sql.ResultSetMetaData");
- } catch (ClassNotFoundException e) {
- fail("java.sql.ResultSetMetaData class not found!");
- return;
- } // end try
-
- Field[] theFields = resultSetMetaDataClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class ResultSetMetaDataTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetTest.java
deleted file mode 100644
index 87ffc61..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/ResultSetTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.ResultSet.class)
-public class ResultSetTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("CLOSE_CURSORS_AT_COMMIT",
- new java.lang.Integer(2));
- thePublicStatics.put("HOLD_CURSORS_OVER_COMMIT", new java.lang.Integer(
- 1));
- thePublicStatics.put("CONCUR_UPDATABLE", new java.lang.Integer(1008));
- thePublicStatics.put("CONCUR_READ_ONLY", new java.lang.Integer(1007));
- thePublicStatics.put("TYPE_SCROLL_SENSITIVE", new java.lang.Integer(
- 1005));
- thePublicStatics.put("TYPE_SCROLL_INSENSITIVE", new java.lang.Integer(
- 1004));
- thePublicStatics.put("TYPE_FORWARD_ONLY", new java.lang.Integer(1003));
- thePublicStatics.put("FETCH_UNKNOWN", new java.lang.Integer(1002));
- thePublicStatics.put("FETCH_REVERSE", new java.lang.Integer(1001));
- thePublicStatics.put("FETCH_FORWARD", new java.lang.Integer(1000));
-
- /*
- * System.out.println( "CLOSE_CURSORS_AT_COMMIT: " +
- * ResultSet.CLOSE_CURSORS_AT_COMMIT ); System.out.println(
- * "HOLD_CURSORS_OVER_COMMIT: " + ResultSet.HOLD_CURSORS_OVER_COMMIT );
- * System.out.println( "CONCUR_UPDATABLE: " + ResultSet.CONCUR_UPDATABLE );
- * System.out.println( "CONCUR_READ_ONLY: " + ResultSet.CONCUR_READ_ONLY );
- * System.out.println( "TYPE_SCROLL_SENSITIVE: " +
- * ResultSet.TYPE_SCROLL_SENSITIVE ); System.out.println(
- * "TYPE_SCROLL_INSENSITIVE: " + ResultSet.TYPE_SCROLL_INSENSITIVE );
- * System.out.println( "TYPE_FORWARD_ONLY: " +
- * ResultSet.TYPE_FORWARD_ONLY ); System.out.println( "FETCH_UNKNOWN: " +
- * ResultSet.FETCH_UNKNOWN ); System.out.println( "FETCH_REVERSE: " +
- * ResultSet.FETCH_REVERSE ); System.out.println( "FETCH_FORWARD: " +
- * ResultSet.FETCH_FORWARD );
- */
-
- Class<?> resultSetClass;
- try {
- resultSetClass = Class.forName("java.sql.ResultSet");
- } catch (ClassNotFoundException e) {
- fail("java.sql.ResultSet class not found!");
- return;
- } // end try
-
- Field[] theFields = resultSetClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class ResultSetTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java
deleted file mode 100644
index bca96ae..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLExceptionTest.java
+++ /dev/null
@@ -1,619 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.sql.SQLException;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-@TestTargetClass(SQLException.class)
-public class SQLExceptionTest extends TestCase {
-
- static long theFixedSUID = 2135244094396331484L;
-
- /*
- * SUID test
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testSUID() {
-
- try {
- Class<?> theClass = Class.forName("java.sql.SQLException");
- Field theField = theClass.getDeclaredField("serialVersionUID");
- theField.setAccessible(true);
- long theSUID = theField.getLong(null);
- assertEquals("SUID mismatch: ", theFixedSUID, theSUID);
- } catch (Exception e) {
- System.out.println("SUID check got exception: " + e.getMessage());
- // assertTrue("Exception while testing SUID ", false );
- } // end catch
-
- } // end method testSUID
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLException",
- args = {java.lang.String.class, java.lang.String.class, int.class}
- )
- public void testSQLExceptionStringStringint() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", "1", "a",
- null, "", "\u0000", "a", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a",
- "&valid*", "a", "a", "a", null, "", "\u0000" };
- int[] init3 = { -2147483648, 2147483647, 0, 48429456, 1770127344,
- 1047282235, -545472907, -2147483648, -2147483648, -2147483648,
- -2147483648, -2147483648, -2147483648 };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLException[] theFinalStates4 = { null, null, null, null, null, null,
- null, null, null, null, null, null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null, null, null };
-
- SQLException aSQLException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i], init3[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLExceptionStringStringint
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLException",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testSQLExceptionStringString() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
- "\u0000", "a", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", "a",
- "a", null, "", "\u0000" };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = { 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0 };
- SQLException[] theFinalStates4 = { null, null, null, null, null, null,
- null, null, null, null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null };
-
- SQLException aSQLException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLExceptionStringString
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLException",
- args = {java.lang.String.class}
- )
- public void testSQLExceptionString() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null,
- "", "\u0000" };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = { null, null, null, null, null, null, null,
- null };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0,
- 0, 0, 0 };
- SQLException[] theFinalStates4 = { null, null, null, null, null, null,
- null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null };
-
- SQLException aSQLException;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLExceptionString
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLException",
- args = {}
- )
- public void testSQLException() {
-
- String[] theFinalStates1 = { null };
- String[] theFinalStates2 = { null };
- int[] theFinalStates3 = { 0 };
- SQLException[] theFinalStates4 = { null };
-
- Exception[] theExceptions = { null };
-
- SQLException aSQLException;
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException();
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLException
-
- /*
- * Method test for getErrorCode
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getErrorCode",
- args = {}
- )
- public void testGetErrorCode() {
-
- SQLException aSQLException;
- String[] init1 = { "a", "1", "valid1", "----", null, "&valid*", "1" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", null, "a" };
- int[] init3 = { -2147483648, 2147483647, 0, 48429456, 1770127344,
- 1047282235, -545472907 };
-
- int theReturn;
- int[] theReturns = init3;
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLException[] theFinalStates4 = { null, null, null, null, null, null,
- null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i], init3[i]);
- theReturn = aSQLException.getErrorCode();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetErrorCode
-
- /*
- * Method test for getNextException
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getNextException",
- args = {}
- )
- public void testGetNextException() {
-
- SQLException aSQLException;
- String[] init1 = { "a", "1", "valid1", "----", null, "&valid*", "1" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", null, "a" };
- int[] init3 = { -2147483648, 2147483647, 0, 48429456, 1770127344,
- 1047282235, -545472907 };
- SQLException[] init4 = { new SQLException(), null, new SQLException(),
- new SQLException(), new SQLException(), null,
- new SQLException() };
-
- SQLException theReturn;
- SQLException[] theReturns = init4;
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLException[] theFinalStates4 = init4;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i], init3[i]);
- aSQLException.setNextException(init4[i]);
- theReturn = aSQLException.getNextException();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetNextException
-
- /*
- * Method test for getSQLState
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getSQLState",
- args = {}
- )
- public void testGetSQLState() {
-
- SQLException aSQLException;
- String[] init1 = { "a", "1", "valid1", "----", null, "&valid*", "1" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", null, "a" };
- int[] init3 = { -2147483648, 2147483647, 0, 48429456, 1770127344,
- 1047282235, -545472907 };
-
- String theReturn;
- String[] theReturns = init2;
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLException[] theFinalStates4 = { null, null, null, null, null, null,
- null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i], init3[i]);
- theReturn = aSQLException.getSQLState();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetSQLState
-
- /*
- * Method test for setNextException
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setNextException",
- args = {java.sql.SQLException.class}
- )
- public void testSetNextExceptionSQLException() {
-
- SQLException[] parm1 = { new SQLException(), null, new SQLException(),
- new SQLException(), new SQLException(), null,
- new SQLException() };
-
- SQLException aSQLException;
-
- String[] init1 = { "a", "1", "valid1", "----", null, "&valid*", "1" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", null, "a" };
- int[] init3 = { -2147483648, 2147483647, 0, 48429456, 1770127344,
- 1047282235, -545472907 };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLException[] theFinalStates4 = parm1;
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null };
-
- int loopCount = parm1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLException = new SQLException(init1[i], init2[i], init3[i]);
- aSQLException.setNextException(parm1[i]);
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + " Final state mismatch", aSQLException
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLException
- .getNextException(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSetNextExceptionSQLException
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Serialization test",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- SQLException object = new SQLException();
- SerializationTest.verifySelf(object, SQLEXCEPTION_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Serialization test",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
-
- SQLException nextSQLException = new SQLException("nextReason",
- "nextSQLState", 33);
-
- int vendorCode = 10;
- SQLException object = new SQLException("reason", "SQLState", vendorCode);
-
- object.setNextException(nextSQLException);
-
- SerializationTest.verifyGolden(this, object, SQLEXCEPTION_COMPARATOR);
- }
-
- // comparator for SQLException objects
- private static final SerializableAssert SQLEXCEPTION_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- SQLException initThr = (SQLException) initial;
- SQLException dserThr = (SQLException) deserialized;
-
- // verify SQLState
- Assert.assertEquals("SQLState", initThr.getSQLState(), dserThr
- .getSQLState());
-
- // verify vendorCode
- Assert.assertEquals("vendorCode", initThr.getErrorCode(), dserThr
- .getErrorCode());
-
- // verify next
- if (initThr.getNextException() == null) {
- assertNull(dserThr.getNextException());
- } else {
- // use the same comparator
- SQLEXCEPTION_COMPARATOR.assertDeserialized(initThr
- .getNextException(), dserThr.getNextException());
- }
- }
- };
-
- /**
- * @tests java.sql.SQLException#setNextException(java.sql.SQLException)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setNextException",
- args = {java.sql.SQLException.class}
- )
- public void test_setNextException_LSQLException() {
- SQLException se1 = new SQLException("reason" , "SQLState" , 1);
- SQLException se2 = new SQLException("reason" , "SQLState" , 2);
- SQLException se3 = new SQLException("reason" , "SQLState" , 3);
- SQLException se4 = new SQLException("reason" , "SQLState" , 4);
-
- se1.setNextException(se2);
- assertSame(se2, se1.getNextException());
-
- se1.setNextException(se3);
- assertSame(se2, se1.getNextException());
- assertSame(se3, se2.getNextException());
- assertNull(se3.getNextException());
-
- se3.setNextException(null);
- assertNull(se3.getNextException());
-
- se3.setNextException(se4);
- assertSame(se4, se3.getNextException());
- }
-
-} // end class SQLExceptionTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java
deleted file mode 100644
index 9ecf4cc..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLPermissionTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.SQLPermission;
-
-import junit.framework.TestCase;
-@TestTargetClass(SQLPermission.class)
-/**
- * JUnit Testcase for the java.sql.SQLPermission class
- *
- * Note that the SQLPermission class only defines 2 constructors and all other
- * methods are inherited. This testcase explicitly tets the constructors but also
- * implicitly tests some of the inherited query methods.
- *
- */
-
-public class SQLPermissionTest extends TestCase {
-
- /*
- * Constructor test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "invalid parameters checking missed. not fully supported",
- method = "SQLPermission",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testSQLPermissionStringString() {
- String validName = "setLog";
- String validActions = "theActions";
-
- SQLPermission thePermission = new SQLPermission(validName, validActions);
-
- assertNotNull(thePermission);
- assertEquals(validName, thePermission.getName());
- // System.out.println("The actions: " + thePermission.getActions() + "."
- // );
- assertEquals("", thePermission.getActions());
- } // end method testSQLPermissionStringString
-
- /*
- * Constructor test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "not fully supported",
- method = "SQLPermission",
- args = {java.lang.String.class}
- )
- public void testSQLPermissionString() {
- String validName = "setLog";
-
- SQLPermission thePermission = new SQLPermission(validName);
-
- assertNotNull(thePermission);
- assertEquals(validName, thePermission.getName());
-
- // Set an invalid name ...
- String invalidName = "foo";
-
- thePermission = new SQLPermission(invalidName);
-
- assertNotNull(thePermission);
- assertEquals(invalidName, thePermission.getName());
- assertEquals("", thePermission.getActions());
- } // end method testSQLPermissionString
-
-} // end class SQLPermissionTest
-
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java
deleted file mode 100644
index 25d962e..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/SQLWarningTest.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.Serializable;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(SQLWarning.class)
-public class SQLWarningTest extends TestCase {
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "SQLWarning",
- args = {}
- )
- public void testSQLWarning() {
-
- String[] theFinalStates1 = { null };
- String[] theFinalStates2 = { null };
- int[] theFinalStates3 = { 0 };
- SQLWarning[] theFinalStates4 = { null };
-
- Exception[] theExceptions = { null };
-
- SQLWarning aSQLWarning;
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning();
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLWarning
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLWarning",
- args = {java.lang.String.class}
- )
- public void testSQLWarningString() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null,
- "", "\u0000" };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = { null, null, null, null, null, null, null,
- null };
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0, 0 };
- SQLWarning[] theFinalStates4 = { null, null, null, null, null, null,
- null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null };
-
- SQLWarning aSQLWarning;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning(init1[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLWarningString
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SQLWarning",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testSQLWarningStringString() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", null, "",
- "\u0000", "a", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "a", "a",
- "a", null, "", "\u0000" };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- SQLWarning[] theFinalStates4 = { null, null, null, null, null, null,
- null, null, null, null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null };
-
- SQLWarning aSQLWarning;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning(init1[i], init2[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLWarningStringString
-
- /*
- * ConstructorTest
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "SQLWarning",
- args = {java.lang.String.class, java.lang.String.class, int.class}
- )
- public void testSQLWarningStringStringint() {
-
- String[] init1 = { "a", "1", "valid1", "----", "&valid*", "----",
- "----", null, "", "\u0000", "a", "a", "a" };
- String[] init2 = { "a", "1", "valid1", "----", "&valid*", "valid1",
- "----", "a", "a", "a", null, "", "\u0000" };
- int[] init3 = { -2147483648, 2147483647, 0, 1412862821, -733923487,
- 488067774, -1529953616, -2147483648, -2147483648, -2147483648,
- -2147483648, -2147483648, -2147483648 };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = init2;
- int[] theFinalStates3 = init3;
- SQLWarning[] theFinalStates4 = { null, null, null, null, null, null,
- null, null, null, null, null, null, null };
-
- Exception[] theExceptions = { null, null, null, null, null, null, null,
- null, null, null, null, null, null };
-
- SQLWarning aSQLWarning;
- int loopCount = init1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning(init1[i], init2[i], init3[i]);
- if (theExceptions[i] != null) {
- fail();
- }
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSQLWarningStringStringint
-
- /*
- * Method test for getNextWarning
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getNextWarning",
- args = {}
- )
- public void testGetNextWarning() {
-
- SQLWarning aSQLWarning;
- String[] init1 = { "a", "1", "valid1", "----", "&valid*" };
-
- SQLWarning theReturn;
- SQLWarning[] theReturns = { null };
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = { null };
- int[] theFinalStates3 = { 0 };
- SQLWarning[] theFinalStates4 = { null };
-
- Exception[] theExceptions = { null };
-
- int loopCount = 1;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning(init1[i]);
- theReturn = aSQLWarning.getNextWarning();
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + "Return value mismatch", theReturn,
- theReturns[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testGetNextWarning
-
- /*
- * Method test for setNextWarning
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setNextWarning",
- args = {java.sql.SQLWarning.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getNextWarning",
- args = {}
- )
- })
- public void testSetNextWarningSQLWarning() {
-
- SQLWarning[] parm1 = { new SQLWarning(), null };
-
- SQLWarning aSQLWarning;
- String[] init1 = { "a", "1" };
-
- String[] theFinalStates1 = init1;
- String[] theFinalStates2 = { null, null };
- int[] theFinalStates3 = { 0, 0 };
- SQLWarning[] theFinalStates4 = parm1;
-
- Exception[] theExceptions = { null, null };
-
- int loopCount = parm1.length;
- for (int i = 0; i < loopCount; i++) {
- try {
- aSQLWarning = new SQLWarning(init1[i]);
- aSQLWarning.setNextWarning(parm1[i]);
- if (theExceptions[i] != null) {
- fail(i + "Exception missed");
- }
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getMessage(), theFinalStates1[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getSQLState(), theFinalStates2[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getErrorCode(), theFinalStates3[i]);
- assertEquals(i + " Final state mismatch", aSQLWarning
- .getNextWarning(), theFinalStates4[i]);
-
- } catch (Exception e) {
- if (theExceptions[i] == null) {
- fail(i + "Unexpected exception");
- }
- assertEquals(i + "Exception mismatch", e.getClass(),
- theExceptions[i].getClass());
- assertEquals(i + "Exception mismatch", e.getMessage(),
- theExceptions[i].getMessage());
- } // end try
- } // end for
-
- } // end method testSetNextWarningSQLWarning
-
- /**
- * @tests java.sql.SQLWarning#setNextWarning(java.sql.SQLWarning)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setNextWarning",
- args = {java.sql.SQLWarning.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "getNextWarning",
- args = {}
- )
- })
- public void test_setNextWarning_SQLWarning() {
- SQLWarning sw = new SQLWarning("reason", "SQLState", 0);
- SQLWarning sw1 = new SQLWarning("reason", "SQLState", 1);
- SQLWarning sw2 = new SQLWarning("reason", "SQLState", 2);
- SQLWarning sw3 = new SQLWarning("reason", "SQLState", 3);
-
- SQLException se = new SQLException("reason", "SQLState", 4);
-
- sw.setNextWarning(sw1);
- assertSame(sw1, sw.getNextException());
- assertSame(sw1, sw.getNextWarning());
-
-
- sw.setNextWarning(sw2);
- assertSame(sw2, sw1.getNextException());
- assertSame(sw2, sw1.getNextWarning());
-
- sw.setNextException(sw3);
- assertSame(sw3, sw2.getNextException());
- assertSame(sw3, sw2.getNextWarning());
-
- sw.setNextException(se);
- assertSame(se, sw3.getNextException());
- try {
- sw3.getNextWarning();
- fail("should throw Error");
- } catch (Error e) {
- //expected
- }
- }
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Serialization test",
- method = "SQLWarning",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- SQLWarning object = new SQLWarning();
- SerializationTest.verifySelf(object, SQLWARNING_COMPARATOR);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Serialization test",
- method = "SQLWarning",
- args = {java.lang.String.class, java.lang.String.class, int.class}
- )
- public void testSerializationCompatibility() throws Exception {
- SQLWarning object = new SQLWarning();
-
- SQLWarning nextSQLWarning = new SQLWarning("nextReason",
- "nextSQLState", 10);
-
- object.setNextWarning(nextSQLWarning);
-
- SerializationTest.verifyGolden(this, object, SQLWARNING_COMPARATOR);
- }
-
- // comparator for SQLWarning objects
- private static final SerializableAssert SQLWARNING_COMPARATOR = new SerializableAssert() {
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
-
- // do common checks for all throwable objects
- SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
- deserialized);
-
- SQLWarning initThr = (SQLWarning) initial;
- SQLWarning dserThr = (SQLWarning) deserialized;
-
- // verify getNextWarning() method
- if (initThr.getNextWarning() == null) {
- assertNull(dserThr.getNextWarning());
- } else {
- // use the same comparator
- SQLWARNING_COMPARATOR.assertDeserialized(initThr
- .getNextWarning(), dserThr.getNextWarning());
- }
- }
- };
-
-} // end class SQLWarningTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java
deleted file mode 100644
index 607a51c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/StatementTest.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.Statement.class)
-public class StatementTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("NO_GENERATED_KEYS", new Integer(2));
- thePublicStatics.put("RETURN_GENERATED_KEYS", new Integer(1));
- thePublicStatics.put("EXECUTE_FAILED", new Integer(-3));
- thePublicStatics.put("SUCCESS_NO_INFO", new Integer(-2));
- thePublicStatics.put("CLOSE_ALL_RESULTS", new Integer(3));
- thePublicStatics.put("KEEP_CURRENT_RESULT", new Integer(2));
- thePublicStatics.put("CLOSE_CURRENT_RESULT", new Integer(1));
-
- /*
- * System.out.println( "NO_GENERATED_KEYS: " +
- * Statement.NO_GENERATED_KEYS ); System.out.println(
- * "RETURN_GENERATED_KEYS: " + Statement.RETURN_GENERATED_KEYS );
- * System.out.println( "EXECUTE_FAILED: " + Statement.EXECUTE_FAILED );
- * System.out.println( "SUCCESS_NO_INFO: " + Statement.SUCCESS_NO_INFO );
- * System.out.println( "CLOSE_ALL_RESULTS: " +
- * Statement.CLOSE_ALL_RESULTS ); System.out.println(
- * "KEEP_CURRENT_RESULT: " + Statement.KEEP_CURRENT_RESULT );
- * System.out.println( "CLOSE_CURRENT_RESULT: " +
- * Statement.CLOSE_CURRENT_RESULT );
- */
-
- Class<?> statementClass;
- try {
- statementClass = Class.forName("java.sql.Statement");
- } catch (ClassNotFoundException e) {
- fail("java.sql.Statement class not found!");
- return;
- } // end try
-
- Field[] theFields = statementClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class StatementTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java
deleted file mode 100644
index bc20769..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_ClassLoader.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-public class TestHelper_ClassLoader extends ClassLoader {
-
- public TestHelper_ClassLoader() {
- super();
- }
-
- /**
- * Loads a class specified by its name
- * <p>
- * This classloader makes the assumption that any class it is asked to load
- * is in the current directory....
- */
- @Override
- public Class<?> findClass(String className) throws ClassNotFoundException {
- Class<?> theClass = null;
-
- if (!className.equals("org.apache.harmony.sql.tests.java.sql.TestHelper_DriverManager")) {
- return null;
- }
-
- String classNameAsFile = className.replace('.', '/') + ".class";
- // System.out.println("findClass - class filename = " + classNameAsFile
- // );
-
- String classPath = System.getProperty("java.class.path");
- // System.out.println("Test class loader - classpath = " + classPath );
-
- String theSeparator = String.valueOf(File.pathSeparatorChar);
- String[] theClassPaths = classPath.split(theSeparator);
- for (int i = 0; (i < theClassPaths.length) && (theClass == null); i++) {
- // Ignore jar files...
- if (theClassPaths[i].endsWith(".jar")) {
- theClass = loadClassFromJar(theClassPaths[i], className,
- classNameAsFile);
- } else {
- theClass = loadClassFromFile(theClassPaths[i], className,
- classNameAsFile);
- } // end if
- } // end for
-
- return theClass;
- } // end method findClass( String )
-
- @Override
- public Class<?> loadClass(String className) throws ClassNotFoundException {
- // Allowed classes:
- String[] disallowedClasses = { "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver1",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver2",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver4",
- "org.apache.harmony.sql.tests.java.sql.TestHelper_Driver5" };
-
- Class<?> theClass;
-
- theClass = findLoadedClass(className);
- if (theClass != null) {
- return theClass;
- }
-
- theClass = this.findClass(className);
-
- if (theClass == null) {
- for (String element : disallowedClasses) {
- if (element.equals(className)) {
- return null;
- } // end if
- } // end for
- theClass = Class.forName(className);
- } // end if
-
- return theClass;
- } // end method loadClass( String )
-
- private Class<?> loadClassFromFile(String pathName, String className,
- String classNameAsFile) {
- Class<?> theClass = null;
- FileInputStream theInput = null;
- File theFile = null;
- try {
- theFile = new File(pathName, classNameAsFile);
- if (theFile.exists()) {
- int length = (int) theFile.length();
- theInput = new FileInputStream(theFile);
- byte[] theBytes = new byte[length + 100];
- int dataRead = 0;
- while (dataRead < length) {
- int count = theInput.read(theBytes, dataRead,
- theBytes.length - dataRead);
- if (count == -1) {
- break;
- }
- dataRead += count;
- }
-
- if (dataRead > 0) {
- // Create the class from the bytes read in...
- theClass = this.defineClass(className, theBytes, 0, dataRead);
- ClassLoader testClassLoader = theClass.getClassLoader();
- if (testClassLoader != this) {
- System.out.println("findClass - wrong classloader!!");
- }
- }
- }
- } catch (Exception e) {
- System.out.println("findClass - exception reading class file.");
- e.printStackTrace();
- } finally {
- try {
- if (theInput != null) {
- theInput.close();
- }
- } catch (Exception e) {
- }
- }
- return theClass;
- }
-
- /*
- * Loads a named class from a specified JAR file
- */
- private Class<?> loadClassFromJar(String jarfileName, String className,
- String classNameAsFile) {
- Class<?> theClass = null;
-
- // First, try to open the Jar file
- JarFile theJar = null;
- try {
- theJar = new JarFile(jarfileName);
- JarEntry theEntry = theJar.getJarEntry(classNameAsFile);
-
- if (theEntry == null) {
- // System.out.println("TestHelper_Classloader - did not find
- // class file in Jar " + jarfileName );
- return theClass;
- } // end if
-
- theEntry.getMethod();
- InputStream theStream = theJar.getInputStream(theEntry);
-
- long size = theEntry.getSize();
- if (size < 0) {
- size = 100000;
- }
- byte[] theBytes = new byte[(int) size + 100];
-
- int dataRead = 0;
- while (dataRead < size) {
- int count = theStream.read(theBytes, dataRead, theBytes.length
- - dataRead);
- if (count == -1) {
- break;
- }
- dataRead += count;
- } // end while
-
- // System.out.println("loadClassFromJar: read " + dataRead + " bytes
- // from class file");
- if (dataRead > 0) {
- // Create the class from the bytes read in...
- theClass = this.defineClass(className, theBytes, 0, dataRead);
- /* System.out.println("findClass: created Class object."); */
- ClassLoader testClassLoader = theClass.getClassLoader();
- if (testClassLoader != this) {
- System.out.println("findClass - wrong classloader!!");
- } else {
- System.out
- .println("Testclassloader loaded class from jar: "
- + className);
- } // end if
- } // end if
- } catch (IOException ie) {
- System.out
- .println("TestHelper_ClassLoader: IOException opening Jar "
- + jarfileName);
- } catch (Exception e) {
- System.out
- .println("TestHelper_ClassLoader: Exception loading class from Jar ");
- } catch (ClassFormatError ce) {
- System.out
- .println("TestHelper_ClassLoader: ClassFormatException loading class from Jar ");
- } finally {
- try {
- if (theJar != null) {
- theJar.close();
- }
- } catch (Exception e) {
- } // end try
- } // end try
-
- return theClass;
- } // end method loadClassFromJar(
-
-} // end class TestHelper_ClassLoader
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java
deleted file mode 100644
index b18ea3c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Connection1.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.CallableStatement;
-import java.sql.Clob;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.NClob;
-import java.sql.PreparedStatement;
-import java.sql.SQLClientInfoException;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.SQLXML;
-import java.sql.Savepoint;
-import java.sql.Statement;
-import java.sql.Struct;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Helper class for the java.sql tests - a skeleton class which implements the
- * java.sql.Connection interface
- *
- */
-public class TestHelper_Connection1 implements Connection {
- public void clearWarnings() throws SQLException {
- }
-
- public void close() throws SQLException {
- }
-
- public void commit() throws SQLException {
- }
-
- public Statement createStatement() throws SQLException {
- return null;
- }
-
- public Statement createStatement(int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- return null;
- }
-
- public Statement createStatement(int resultSetType, int resultSetConcurrency)
- throws SQLException {
- return null;
- }
-
- public boolean getAutoCommit() throws SQLException {
- return false;
- }
-
- public String getCatalog() throws SQLException {
- return null;
- }
-
- public int getHoldability() throws SQLException {
- return 0;
- }
-
- public DatabaseMetaData getMetaData() throws SQLException {
- return null;
- }
-
- public int getTransactionIsolation() throws SQLException {
- return 0;
- }
-
- public Map<String, Class<?>> getTypeMap() throws SQLException {
- return null;
- }
-
- public SQLWarning getWarnings() throws SQLException {
- return null;
- }
-
- public boolean isClosed() throws SQLException {
- return false;
- }
-
- public boolean isReadOnly() throws SQLException {
- return false;
- }
-
- public String nativeSQL(String sql) throws SQLException {
- return null;
- }
-
- public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- return null;
- }
-
- public CallableStatement prepareCall(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
- return null;
- }
-
- public CallableStatement prepareCall(String sql) throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql, int resultSetType,
- int resultSetConcurrency) throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
- throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
- throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql, String[] columnNames)
- throws SQLException {
- return null;
- }
-
- public PreparedStatement prepareStatement(String sql) throws SQLException {
- return null;
- }
-
- public void releaseSavepoint(Savepoint savepoint) throws SQLException {
- }
-
- public void rollback() throws SQLException {
- }
-
- public void rollback(Savepoint savepoint) throws SQLException {
- }
-
- public void setAutoCommit(boolean autoCommit) throws SQLException {
- }
-
- public void setCatalog(String catalog) throws SQLException {
- }
-
- public void setHoldability(int holdability) throws SQLException {
- }
-
- public void setReadOnly(boolean readOnly) throws SQLException {
- }
-
- public Savepoint setSavepoint() throws SQLException {
- return null;
- }
-
- public Savepoint setSavepoint(String name) throws SQLException {
- return null;
- }
-
- public void setTransactionIsolation(int level) throws SQLException {
- }
-
- public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
- }
-
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return false;
- }
-
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return null;
- }
-
- public Array createArrayOf(String typeName, Object[] elements)
- throws SQLException {
- return null;
- }
-
- public Blob createBlob() throws SQLException {
- return null;
- }
-
- public Clob createClob() throws SQLException {
- return null;
- }
-
- public NClob createNClob() throws SQLException {
- return null;
- }
-
- public SQLXML createSQLXML() throws SQLException {
- return null;
- }
-
- public Struct createStruct(String typeName, Object[] attributes)
- throws SQLException {
- return null;
- }
-
- public String getClientInfo(String name) throws SQLException {
- return null;
- }
-
- public Properties getClientInfo() throws SQLException {
- return null;
- }
-
- public boolean isValid(int timeout) throws SQLException {
- return false;
- }
-
- public void setClientInfo(String name, String value)
- throws SQLClientInfoException {
-
- }
-
- public void setClientInfo(Properties properties)
- throws SQLClientInfoException {
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
deleted file mode 100644
index 8c38efb..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver1.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.DriverPropertyInfo;
-import java.sql.SQLException;
-import java.util.Properties;
-
-/**
- * A simple implementation of a class implementing a JDBC Driver, for use in the
- * testing of the java.sql.DriverManager class
- *
- */
-public class TestHelper_Driver1 implements Driver {
- int majorVersion = 1;
-
- int minorVersion = 0;
-
- String baseURL = "jdbc:mikes1";
-
- String[] dataSources = { "data1", "data2", "data3" };
-
- static Driver theDriver;
- static {
- theDriver = new TestHelper_Driver1();
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
-
- protected TestHelper_Driver1() {
- super();
- } // end constructor TestHelper_Driver1()
-
- public boolean acceptsURL(String url) throws SQLException {
- // Check on the supplied String...
- if (url == null) {
- return false;
- }
- // Everything's fine if the quoted url starts with the base url for this
- // driver
- if (url.startsWith(baseURL)) {
- return true;
- }
- return false;
- } // end method acceptsURL
-
- static String validuser = "theuser";
-
- static String validpassword = "thepassword";
-
- static String userProperty = "user";
-
- static String passwordProperty = "password";
-
- public Connection connect(String url, Properties info) throws SQLException {
- // Does the URL have the right form?
- if (this.acceptsURL(url)) {
- // The datasource name is the remainder of the url after the ":"
- String datasource = url.substring(baseURL.length() + 1);
- for (String element : dataSources) {
- if (datasource.equals(element)) {
- /*
- * Check for user and password, except for datasource =
- * data1 which is set up not to require a user/password
- * combination
- */
- // It all checks out - so return a connection
- Connection connection = new TestHelper_Connection1();
- return connection;
- } // end if
- } // end for
- } // end if
- return null;
- } // end method connect(String, Properties)
-
- public int getMajorVersion() {
- return majorVersion;
- } // end method getMajorVersion()
-
- public int getMinorVersion() {
- return minorVersion;
- } // end method getMinorVersion()
-
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
- throws SQLException {
- DriverPropertyInfo[] theInfos = {
- new DriverPropertyInfo(userProperty, "*"),
- new DriverPropertyInfo(passwordProperty, "*"), };
- return theInfos;
- }
-
- public boolean jdbcCompliant() {
- // Basic version here returns false
- return false;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java
deleted file mode 100644
index 1aff886..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver2.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-/**
- * Basic JDBC driver implementation to help with tests
- *
- */
-public class TestHelper_Driver2 extends TestHelper_Driver1 {
-
- static {
- Driver theDriver = new TestHelper_Driver2();
- /*
- * System.out.println("Driver2 classloader: " +
- * theDriver.getClass().getClassLoader() ); System.out.println("Driver2
- * object is: " + theDriver );
- */
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
-
- protected TestHelper_Driver2() {
- super();
- baseURL = "jdbc:mikes2";
- } // end constructor TestHelper_Driver1()
-
-} // end class TestHelper_Driver2
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java
deleted file mode 100644
index fdd0b0c..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver3.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-/**
- * TODO Type description
- *
- */
-public class TestHelper_Driver3 extends TestHelper_Driver1 {
-
- /*
- * This driver does NOT automatically register itself...
- */
-
- public TestHelper_Driver3() {
- super();
- baseURL = "jdbc:mikes3";
- } // end constructor TestHelper_Driver1()
-
-} // end class TestHelper_Driver3
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java
deleted file mode 100644
index 3ed1479..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver4.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.DriverPropertyInfo;
-import java.sql.SQLException;
-import java.util.Properties;
-
-/**
- * Basic JDBC driver implementation to help with tests
- *
- */
-public class TestHelper_Driver4 implements Driver {
- int majorVersion = 1;
-
- int minorVersion = 0;
-
- String baseURL;
-
- String[] dataSources = { "data1", "data2", "data3" };
- static {
- Driver theDriver = new TestHelper_Driver4();
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
-
- protected TestHelper_Driver4() {
- super();
- baseURL = "jdbc:mikes4";
- } // end constructor TestHelper_Driver4()
-
- public boolean acceptsURL(String url) throws SQLException {
- // Check on the supplied String...
- if (url == null) {
- return false;
- }
- // Everything's fine if the quoted url starts with the base url for this
- // driver
- if (url.startsWith(baseURL)) {
- return true;
- }
- return false;
- } // end method acceptsURL
-
- static String validuser = "theuser";
-
- static String validpassword = "thepassword";
-
- static String userProperty = "user";
-
- static String passwordProperty = "password";
-
- public Connection connect(String url, Properties info) throws SQLException {
- // Does the URL have the right form?
- if (this.acceptsURL(url)) {
- // The datasource name is the remainder of the url after the ":"
- String datasource = url.substring(baseURL.length() + 1);
- for (String element : dataSources) {
- if (datasource.equals(element)) {
- /*
- * Check for user and password, except for datasource =
- * data1 which is set up not to require a user/password
- * combination
- */
- if (datasource.equals("data1")) {
- // do nothing...
- } else {
- if (info == null) {
- throw new SQLException("Properties bundle is null");
- }
- String user = (String) info.get(userProperty);
- String password = (String) info.get(passwordProperty);
- if (user == null || password == null) {
- throw new SQLException(
- "Userid and/or password not supplied");
- }
- if (!user.equals(validuser)
- || !password.equals(validpassword)) {
- throw new SQLException(
- "Userid and/or password not valid");
- } // end if
- } // end if
- // It all checks out - so return a connection
- Connection connection = new TestHelper_Connection1();
- return connection;
- } // end if
- } // end for
- } // end if
- return null;
- } // end method connect(String, Properties)
-
- public int getMajorVersion() {
- return majorVersion;
- } // end method getMajorVersion()
-
- public int getMinorVersion() {
- return minorVersion;
- } // end method getMinorVersion()
-
- public DriverPropertyInfo[] getPropertyInfo(String url, Properties info)
- throws SQLException {
- DriverPropertyInfo[] theInfos = {
- new DriverPropertyInfo(userProperty, "*"),
- new DriverPropertyInfo(passwordProperty, "*"), };
- return theInfos;
- }
-
- public boolean jdbcCompliant() {
- // Basic version here returns false
- return false;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java
deleted file mode 100644
index 9e1c305..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_Driver5.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-/**
- * Basic JDBC driver implementation to help with tests
- *
- */
-public class TestHelper_Driver5 extends TestHelper_Driver4 {
-
- static {
- Driver theDriver = new TestHelper_Driver5();
- try {
- DriverManager.registerDriver(theDriver);
- } catch (SQLException e) {
- System.out.println("Failed to register driver!");
- }
- } // end static block initializer
-
- protected TestHelper_Driver5() {
- super();
- baseURL = "jdbc:mikes5";
- } // end constructor TestHelper_Driver5()
-
-} // end class TestHelper_Driver5
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java
deleted file mode 100644
index 885d29e..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TestHelper_DriverManager.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-
-import java.sql.Driver;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.logging.Logger;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(DriverManager.class)
-/**
- * Helper class for the Driver manager tes - it allows the test code to be
- * loaded under a different classloader, necessary for testing the
- * DeregisterDriver function of DriverManager
- *
- */
-public class TestHelper_DriverManager extends TestCase {
-
- static Driver testDriver = null;
-
- static TestHelper_DriverManager theHelper;
-
- static {
- theHelper = new TestHelper_DriverManager();
- // theHelper.testDeregister();
- } // end static
-
- public TestHelper_DriverManager() {
- super();
- } // end constructor TestHelper_DriverManager()
-
- public static void setDriver(Driver theDriver) {
- testDriver = theDriver;
- // Logger.global.info("TestHelper_DriverManager: Test Driver set!");
-
- theHelper.checkDeregister();
- } // end method setDriver( Driver )
-
- public void checkDeregister() {
-
- String baseURL = "jdbc:mikes1";
-
- // Logger.global.info("Calling checkDeregister in TestHelper_DriverManager....");
-
- Driver aDriver;
-
- // Logger.global.info("checkDeregister classloader: this.getClass().getClassLoader()");
-
- // Try to get a driver from the general pool... this should fail
- try {
- aDriver = DriverManager.getDriver(baseURL);
- fail("testDeregisterDriver: Didn't get exception when getting valid driver from other classloader.");
- } catch (SQLException e) {
- // e.printStackTrace();
- assertTrue(
- "testDeregisterDriver: Got exception when getting valid driver from other classloader.",
- true);
- // return;
- } // end try
-
- // OK, now THIS driver was loaded by someone else....
- aDriver = testDriver;
-
- // printClassLoader( aDriver );
-
- // Deregister this driver
- try {
- DriverManager.deregisterDriver(aDriver);
- // We shouldn't get here - but if we do, we need to re-register the
- // driver to
- // prevent subsequent tests from failing due to inability to get to
- // this driver...
- DriverManager.registerDriver(aDriver);
- fail("checkDeregisterDriver: Didn't get Security Exception deregistering invalid driver.");
- } catch (SecurityException s) {
- // This is the exception we should get...
- // System.out.println("checkDeregisterDriver: got expected Security
- // Exception");
- } catch (Exception e) {
- fail("checkDeregisterDriver: Got wrong exception type when deregistering invalid driver.");
- } // end try
-
- } // end method testDeRegister
-
- static void printClassLoader(Object theObject) {
- Class<? extends Object> theClass = theObject.getClass();
- ClassLoader theClassLoader = theClass.getClassLoader();
- System.out.println("ClassLoader is: " + theClassLoader.toString()
- + " for object: " + theObject.toString());
- } // end method printClassLoader( Object )
-
-} // end class TestHelper_DriverManager
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
deleted file mode 100644
index 2f3b8ff..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.Time;
-import java.util.TimeZone;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(Time.class)
-/**
- * JUnit Testcase for the java.sql.Time class
- *
- */
-public class TimeTest extends TestCase {
-
- static long TIME_TEST1 = 38720000; // 10:45:20 GMT
-
- static long TIME_TEST2 = 80279000; // 22:17:59 GMT
-
- static long TIME_TEST3 = -38720000; // 13:14:40 GMT
-
- static String STRING_TEST1 = "10:45:20";
-
- static String STRING_TEST2 = "22:17:59";
-
- static String STRING_TEST3 = "13:14:40";
-
- static String STRING_INVALID1 = "ABCDEFGHI";
-
- static String STRING_INVALID2 = "233104";
-
- static String STRING_INVALID3 = "21-43-48";
-
- static String STRING_OUTRANGE = "35:99:66";
-
- static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
-
- static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
- STRING_TEST3 };
-
- static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
-
- static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
-
- static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
- STRING_INVALID3 };
-
- // Timezones
- static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
-
- static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
-
- static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
-
- static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
-
- static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
- STRING_JP_ARRAY };
-
- private TimeZone old;
-
- @Override
- protected void setUp() {
- old = TimeZone.getDefault();
- }
-
- @Override
- protected void tearDown() {
- TimeZone.setDefault(old);
- }
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecated method",
- method = "Time",
- args = {int.class, int.class, int.class}
- )
- public void testTimeintintint() {
- Time theTime = new Time(10, 45, 20);
-
- // The date should have been created
- assertNotNull(theTime);
- } // end method testTimeintintint()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Incorrect parameter checking missed",
- method = "Time",
- args = {long.class}
- )
- public void testTime() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- Time theTime = new Time(TIME_TEST1);
-
- // The date should have been created
- assertNotNull(theTime);
- assertTrue(theTime.toString().contains(STRING_TEST1));
- } // end method testTime()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- // Loop through the timezones testing the String conversion for each
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- testToString(TIMEZONES[i], TIME_ARRAY, STRING_ARRAYS[i]);
- } // end for
-
- } // end method test
-
- private void testToString(String timeZone, long[] theTimes,
- String[] theTimeStrings) {
- // Set the timezone
- TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
-
- for (int i = 0; i < theTimes.length; i++) {
- // Create the Time object
- Time theTime = new Time(theTimes[i]);
- // Convert to a time string ... and compare
- String JDBCString = theTime.toString();
- assertEquals(theTimeStrings[i], JDBCString);
- } // end for
-
- } // end testToString( String, long[], String[] )
-
- /*
- * Method test for valueOf
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void testValueOfString() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
-
- Time[] theReturns = { new Time(38720000), new Time(80279000),
- new Time(47680000)};
- String[] validTime = { STRING_TEST1, STRING_TEST2, STRING_TEST3, };
- String[] invalidTime = { null, "ABCDEFGHI", "233104", "21-43-48" };
-
- for (int i = 0; i < validTime.length; i++) {
- Time theReturn = Time.valueOf(validTime[i]);
- assertEquals(theReturns[i], theReturn);
- } // end for
-
- for (String element : invalidTime) {
- try {
- Time.valueOf(element);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- } // end method testValueOfString
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {long.class}
- )
- public void testSetTime() {
- // Ensure that the timezone is set to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- Time theTime = new Time(TIME_TEST1);
- assertEquals(STRING_TEST1, theTime.toString());
-
- theTime.setTime(TIME_TEST2);
- assertEquals(STRING_TEST2, theTime.toString());
- } // end method testSetTime()
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setDate",
- args = {int.class}
- )
- @SuppressWarnings("deprecation")
- public void testSetDate() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.setDate(10);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetDate()
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setMonth",
- args = {int.class}
- )
- public void testSetMonth() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.setMonth(2);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetMonth()
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setYear",
- args = {int.class}
- )
- public void testSetYear() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.setYear(99);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method testSetYear()
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDate",
- args = {}
- )
- public void testGetDate() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.getDate();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getDay",
- args = {}
- )
- public void testGetDay() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.getDay();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMonth",
- args = {}
- )
- public void testGetMonth() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.getMonth();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
-
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getYear",
- args = {}
- )
- public void testGetYear() {
- Time theTime = new Time(TIME_TEST1);
-
- try {
- theTime.getYear();
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
- } // end method test
-
- /**
- * @tests java.sql.Time#valueOf(String )
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void test_valueOf_IllegalArgumentException() {
- try{
- Time.valueOf("15:43:12:34");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
-
- try{
- Time.valueOf(":10:07:01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("::01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("11::");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf(":01:");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf(":10:w2:01");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("07:w2:");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- }
-
- try{
- Time.valueOf("17:w2:w2");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
-
- try{
- Time.valueOf("16::01");
- fail("should throw NumberFormatException");
- } catch (NumberFormatException e) {
- //expected
- }
- }
-} // end class TimeTest
-
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
deleted file mode 100644
index 172d85e..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TimestampTest.java
+++ /dev/null
@@ -1,873 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.TimeZone;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import junit.framework.TestCase;
-
-@TestTargetClass(Timestamp.class)
-/**
- * JUnit Testcase for the java.sql.Timestamp class
- *
- */
-
-public class TimestampTest extends TestCase {
-
- static class MockTimestamp extends Timestamp{
- private String holiday;
-
- public MockTimestamp(long theTime) {
- super(theTime);
- holiday = "Christmas";
- }
-
- // Constructor should not call this public API,
- // since it may be overrided to use variables uninitialized.
- public void setTime(long theTime){
- super.setTime(theTime);
- holiday.hashCode();
- }
- }
-
- static long TIME_TEST1 = 38720231; // 10:45:20.231 GMT
-
- static long TIME_TEST2 = 80279000; // 22:17:59.000 GMT
-
- static long TIME_TEST3 = -38720691; // 13:14:39.309 GMT
-
- static long TIME_COMPARE = 123498845;
-
- static long TIME_EARLY = -2347889122L;// A time well before the Epoch
-
- static long TIME_LATE = 2347889122L; // A time well after the Epoch
-
- static String STRING_TEST1 = "1970-01-01 10:45:20.231"; // "1970-01-01
- // 10:45:20.231000000";
-
- static String STRING_TEST2 = "1970-01-01 22:17:59.0"; // "1970-01-01
- // 22:17:59.000000000";
-
- static String STRING_TEST3 = "1969-12-31 13:14:39.309"; // "1969-12-31
- // 13:14:39.309000000";
-
- static String STRING_INVALID1 = "ABCDEFGHI";
-
- static String STRING_INVALID2 = "233104";
-
- static String STRING_INVALID3 = "21-43-48";
-
- // A timepoint in the correct format but with numeric values out of range
- // ...this is accepted despite being a crazy date specification
- // ...it is treated as the correct format date 3000-06-08 12:40:06.875 !!
- static String STRING_OUTRANGE = "2999-15-99 35:99:66.875";
-
- static long[] TIME_ARRAY = { TIME_TEST1, TIME_TEST2, TIME_TEST3 };
-
- static int[] YEAR_ARRAY = { 70, 70, 69 };
-
- static int[] MONTH_ARRAY = { 0, 0, 11 };
-
- static int[] DATE_ARRAY = { 1, 1, 31 };
-
- static int[] HOURS_ARRAY = { 10, 22, 13 };
-
- static int[] MINUTES_ARRAY = { 45, 17, 14 };
-
- static int[] SECONDS_ARRAY = { 20, 59, 39 };
-
- static int[] NANOS_ARRAY = { 231000000, 000000000, 309000000 };
-
- static int[] NANOS_ARRAY2 = { 137891990, 635665198, 109985421 };
-
- static String[] STRING_NANOS_ARRAY = { "1970-01-01 10:45:20.13789199",
- "1970-01-01 22:17:59.635665198", "1969-12-31 13:14:39.109985421" };
-
- static String[] STRING_GMT_ARRAY = { STRING_TEST1, STRING_TEST2,
- STRING_TEST3 };
-
- static String[] STRING_LA_ARRAY = { "02:45:20", "14:17:59", "05:14:40" };
-
- static String[] STRING_JP_ARRAY = { "19:45:20", "07:17:59", "22:14:40" };
-
- static String[] INVALID_STRINGS = { STRING_INVALID1, STRING_INVALID2,
- STRING_INVALID3 };
-
- // Timezones
- static String TZ_LONDON = "GMT"; // GMT (!) PS London != GMT (?!?)
-
- static String TZ_PACIFIC = "America/Los_Angeles"; // GMT - 8
-
- static String TZ_JAPAN = "Asia/Tokyo"; // GMT + 9
-
- static String[] TIMEZONES = { TZ_LONDON, TZ_PACIFIC, TZ_JAPAN };
-
- static String[][] STRING_ARRAYS = { STRING_GMT_ARRAY, STRING_LA_ARRAY,
- STRING_JP_ARRAY };
-
- /*
- * Constructor test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Incorrect parameter checking missed",
- method = "Timestamp",
- args = {long.class}
- )
- public void testTimestamplong() {
- Timestamp theTimestamp = new Timestamp(TIME_TEST1);
-
- // The Timestamp should have been created
- assertNotNull(theTimestamp);
-
- Timestamp mockTimestamp = new MockTimestamp(TIME_TEST1);
- assertNotNull(mockTimestamp);
- } // end method testTimestamplong
-
- /*
- * Constructor test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Timestamp",
- args = {int.class, int.class, int.class, int.class, int.class, int.class, int.class}
- )
- @SuppressWarnings("deprecation")
- public void testTimestampintintintintintintint() {
- int[][] valid = { { 99, 2, 14, 17, 52, 3, 213577212 }, // 0 valid
- { 0, 0, 1, 0, 0, 0, 0 }, // 1 valid
- { 106, 11, 31, 23, 59, 59, 999999999 }, // 2 valid
- { 106, 11, 31, 23, 59, 61, 999999999 }, // 5 Seconds out of
- // range
- { 106, 11, 31, 23, 59, -1, 999999999 }, // 6 Seconds out of
- // range
- { 106, 11, 31, 23, 61, 59, 999999999 }, // 7 Minutes out of
- // range
- { 106, 11, 31, 23, -1, 59, 999999999 }, // 8 Minutes out of
- // range
- { 106, 11, 31, 25, 59, 59, 999999999 }, // 9 Hours out of range
- { 106, 11, 31, -1, 59, 59, 999999999 }, // 10 Hours out of range
- { 106, 11, 35, 23, 59, 59, 999999999 }, // 11 Days out of range
- { 106, 11, -1, 23, 59, 59, 999999999 }, // 12 Days out of range
- { 106, 15, 31, 23, 59, 59, 999999999 }, // 13 Months out of
- // range
- { 106, -1, 31, 23, 59, 59, 999999999 }, // 14 Months out of
- // range
- { -10, 11, 31, 23, 59, 59, 999999999 }, // 15 valid - Years
- // negative
- };
-
- for (int[] element : valid) {
- Timestamp theTimestamp = new Timestamp(element[0],
- element[1], element[2], element[3],
- element[4], element[5], element[6]);
- assertNotNull("Timestamp not generated: ", theTimestamp);
- } // end for
-
- int[][] invalid = {
- { 106, 11, 31, 23, 59, 59, 1999999999 },
- { 106, 11, 31, 23, 59, 59, -999999999 },
- };
- for (int[] element : invalid) {
- try {
- new Timestamp(element[0],
- element[1], element[2], element[3],
- element[4], element[5], element[6]);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- } // end method testTimestampintintintintintintint
-
- /*
- * Method test for setTime
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setTime",
- args = {long.class}
- )
- public void testSetTimelong() {
- // First set the timezone to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- Timestamp theTimestamp = new Timestamp(TIME_TEST1);
-
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- theTimestamp.setTime(TIME_ARRAY[i]);
-
- assertEquals(TIME_ARRAY[i], theTimestamp.getTime());
- assertEquals(NANOS_ARRAY[i], theTimestamp.getNanos());
- } // end for
-
- } // end method testsetTimelong
-
- /*
- * Method test for getTime
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTime",
- args = {}
- )
- public void testGetTime() {
- // First set the timezone to GMT
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- assertEquals(element, theTimestamp.getTime());
- } // end for
-
- } // end method testgetTime
-
- /*
- * Method test for getYear
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getYear",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetYear() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(YEAR_ARRAY[i], theTimestamp.getYear());
- } // end for
-
- } // end method testgetYear
-
- /*
- * Method test for getMonth
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getMonth",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetMonth() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(MONTH_ARRAY[i], theTimestamp.getMonth());
- } // end for
-
- } // end method testgetMonth
-
- /*
- * Method test for getDate
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getDate",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetDate() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(DATE_ARRAY[i], theTimestamp.getDate());
- } // end for
-
- } // end method testgetDate
-
- /*
- * Method test for getHours
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getHours",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetHours() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(HOURS_ARRAY[i], theTimestamp.getHours());
- } // end for
-
- } // end method testgetHours
-
- /*
- * Method test for getMinutes
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getMinutes",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetMinutes() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(MINUTES_ARRAY[i], theTimestamp.getMinutes());
- } // end for
-
- } // end method testgetMinutes
-
- /*
- * Method test for getSeconds
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Deprecation",
- method = "getSeconds",
- args = {}
- )
- @SuppressWarnings("deprecation")
- public void testGetSeconds() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals(SECONDS_ARRAY[i], theTimestamp.getSeconds());
- } // end for
-
- } // end method testgetSeconds
-
- /*
- * Method test for valueOf
- */
- static String theExceptionMessage = "Timestamp format must be yyyy-mm-dd hh:mm:ss.fffffffff";
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void testValueOfString() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- Timestamp theTimestamp2 = Timestamp.valueOf(STRING_GMT_ARRAY[i]);
- assertEquals(theTimestamp, theTimestamp2);
- } // end for
-
- // Test for a string in correct format but with number values out of
- // range
- Timestamp theTimestamp = Timestamp.valueOf(STRING_OUTRANGE);
- assertNotNull(theTimestamp);
- /*
- * System.out.println("testValueOfString: outrange timestamp: " +
- * theTimestamp.toString() );
- */
-
- for (String element : INVALID_STRINGS) {
- try {
- Timestamp.valueOf(element);
- fail("Should throw IllegalArgumentException.");
- } catch (IllegalArgumentException e) {
- // expected
- } // end try
-
- } // end for
-
- } // end method testvalueOfString
-
- /*
- * Method test for valueOf
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "valueOf",
- args = {java.lang.String.class}
- )
- public void testValueOfString1() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- Timestamp theReturn;
-
- theReturn = Timestamp.valueOf("1970-01-01 10:45:20.231");
- assertEquals("Wrong result for time test", 38720231,
- theReturn.getTime());
- assertEquals("Wrong result for nanos test", 231000000,
- theReturn.getNanos());
-
- theReturn = Timestamp.valueOf("1970-01-01 10:45:20.231987654");
- assertEquals("Wrong result for time test", 38720231,
- theReturn.getTime());
- assertEquals("Wrong result for nanos test", 231987654,
- theReturn.getNanos());
-
- theReturn = Timestamp.valueOf("1970-01-01 22:17:59.0");
- assertEquals("Wrong result for time test", 80279000,
- theReturn.getTime());
- assertEquals("Wrong result for nanos test", 0,
- theReturn.getNanos());
-
- theReturn = Timestamp.valueOf("1969-12-31 13:14:39.309");
- assertEquals("Wrong result for time test", -38720691,
- theReturn.getTime());
- assertEquals("Wrong result for nanos test", 309000000,
- theReturn.getNanos());
-
- theReturn = Timestamp.valueOf("1970-01-01 10:45:20");
- assertEquals("Wrong result for time test", 38720000,
- theReturn.getTime());
- assertEquals("Wrong result for nanos test", 0,
- theReturn.getNanos());
-
- String[] invalid = {
- null,
- "ABCDEFGHI",
- "233104", "1970-01-01 22:17:59.",
- "1970-01-01 10:45:20.231987654690645322",
- "1970-01-01 10:45:20&231987654",
- "1970-01-01 10:45:20.-31987654",
- "1970-01-01 10:45:20.ABCD87654",
- "21-43-48",
- };
- for (String element : invalid) {
- try {
- theReturn = Timestamp.valueOf(element);
- fail("Should throw IllegalArgumentException for " + element);
- } catch (IllegalArgumentException e) {
- //expected
- }
- }
-
- // Regression test for HARMONY-5506
- String date = "1970-01-01 22:17:59.0 ";
- Timestamp t = Timestamp.valueOf(date);
- assertEquals(80279000,t.getTime());
-
- } // end method testValueOfString
-
- public void testValueOf_IAE() {
- try {
- java.sql.Timestamp.valueOf("2008-12-22 15:00:01.");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
-
- try {
- // bug of RI 5, passed on RI 6
- java.sql.Timestamp.valueOf("178548938-12-22 15:00:01.000000001");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
-
- try {
- java.sql.Timestamp.valueOf("2008-12-22 15:00:01.0000000011");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
-
- /*
- * Method test for toString
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void testToString() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals("Wrong conversion for test " + i, STRING_GMT_ARRAY[i],
- theTimestamp.toString());
- } // end for
-
- Timestamp t1 = new Timestamp(Long.MIN_VALUE);
- assertEquals("292278994-08-17 07:12:55.192", t1.toString());
-
- Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
- assertEquals("292278994-08-17 07:12:55.193", t2.toString());
-
- Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
- assertEquals("292278994-08-17 07:12:55.999", t3.toString());
-
- Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
- assertEquals("292269055-12-02 16:47:05.0", t4.toString());
- } // end method testtoString
-
- private void testToString(String timeZone, long[] theTimeStamps, String[] theTimeStampStrings) {
- TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(theTimeStamps[i]);
- assertEquals(theTimeStampStrings[i], theTimestamp.toString());
- } // end for
-
- }
-
- /*
- * Method test for getNanos
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getNanos",
- args = {}
- )
- public void testGetNanos() {
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- assertEquals("Wrong conversion for test " + i, NANOS_ARRAY[i],
- theTimestamp.getNanos());
- } // end for
-
- } // end method testgetNanos
-
- /*
- * Method test for setNanos
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setNanos",
- args = {int.class}
- )
- public void testSetNanosint() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
-
- int[] NANOS_INVALID = { -137891990, 1635665198, -1 };
- for (int i = 0; i < TIME_ARRAY.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
-
- theTimestamp.setNanos(NANOS_ARRAY2[i]);
-
- assertEquals("Wrong conversion for test " + i, NANOS_ARRAY2[i],
- theTimestamp.getNanos());
- // Also check that these Timestamps with detailed nanos values
- // convert to
- // strings correctly
- assertEquals("Wrong conversion for test " + i,
- STRING_NANOS_ARRAY[i], theTimestamp.toString());
- } // end for
-
- for (int i = 0; i < NANOS_INVALID.length; i++) {
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[i]);
- int originalNanos = theTimestamp.getNanos();
- try {
- theTimestamp.setNanos(NANOS_INVALID[i]);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- //expected
- } // end try
-
- assertEquals(originalNanos, theTimestamp.getNanos());
- } // end for
-
- } // end method testsetNanosint
-
- /*
- * Method test for equals
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.sql.Timestamp.class}
- )
- public void testEqualsTimestamp() {
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Timestamp theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.equals(theTimestamp2));
- } // end for
-
- Timestamp theTest = new Timestamp(TIME_COMPARE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- assertFalse(theTimestamp.equals(theTest));
- } // end for
-
- // Regression for HARMONY-526
- assertFalse(new Timestamp(0).equals((Timestamp) null));
- } // end method testequalsTimestamp
-
- /*
- * Method test for equals
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void testEqualsObject() {
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- Object theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.equals(theTimestamp2));
- } // end for
-
- Object theTest = new Timestamp(TIME_COMPARE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertFalse(theTimestamp.equals(theTest));
- } // end for
-
- Object nastyTest = new String("Test ");
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
- assertFalse(theTimestamp.equals(nastyTest));
-
- // Regression for HARMONY-526
- assertFalse(new Timestamp(0).equals((Object) null));
- } // end method testequalsObject
-
- /*
- * Method test for before
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "before",
- args = {java.sql.Timestamp.class}
- )
- public void testBeforeTimestamp() {
- Timestamp theTest = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertTrue(theTimestamp.before(theTest));
- } // end for
-
- theTest = new Timestamp(TIME_EARLY);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertFalse(theTimestamp.before(theTest));
- } // end for
-
- for (long element : TIME_ARRAY) {
- theTest = new Timestamp(element);
- Timestamp theTimestamp = new Timestamp(element);
-
- assertFalse(theTimestamp.before(theTest));
- theTest.setNanos(theTest.getNanos() + 1);
- assertTrue(theTimestamp.before(theTest));
- } // end for
-
- } // end method testbeforeTimestamp
-
- /*
- * Method test for after
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "after",
- args = {java.sql.Timestamp.class}
- )
- public void testAfterTimestamp() {
- Timestamp theTest = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertFalse(theTimestamp.after(theTest));
- } // end for
-
- theTest = new Timestamp(TIME_EARLY);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
-
- assertTrue(theTimestamp.after(theTest));
- } // end for
-
- for (long element : TIME_ARRAY) {
- theTest = new Timestamp(element);
- Timestamp theTimestamp = new Timestamp(element);
-
- assertFalse(theTimestamp.after(theTest));
- theTimestamp.setNanos(theTimestamp.getNanos() + 1);
- assertTrue(theTimestamp.after(theTest));
- } // end for
-
- } // end method testafterTimestamp
-
- /*
- * Method test for compareTo
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.sql.Timestamp.class}
- )
- @SuppressWarnings("deprecation")
- public void testCompareToTimestamp() {
- Timestamp theTest = new Timestamp(TIME_EARLY);
- Timestamp theTest2 = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Timestamp theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.compareTo(theTest) > 0);
- assertTrue(theTimestamp.compareTo(theTest2) < 0);
- assertEquals(0, theTimestamp.compareTo(theTimestamp2));
- } // end for
-
- Timestamp t1 = new Timestamp(-1L);
- Timestamp t2 = new Timestamp(-1L);
-
- t1.setTime(Long.MIN_VALUE);
- t2.setDate(Integer.MIN_VALUE);
- assertEquals(1, t1.compareTo(t2));
- assertEquals(-1, t2.compareTo(t1));
-
- t1.setTime(Long.MAX_VALUE);
- t2.setTime(Long.MAX_VALUE - 1);
- assertEquals(1, t1.compareTo(t2));
- assertEquals(-1, t2.compareTo(t1));
-
- t1.setTime(Integer.MAX_VALUE);
- t2.setTime(Integer.MAX_VALUE);
- assertEquals(0, t1.compareTo(t2));
- assertEquals(0, t2.compareTo(t1));
-
- } // end method testcompareToTimestamp
-
- /**
- * @tests java.sql.Timestamp#compareTo(java.util.Date)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.util.Date.class}
- )
- public void testCompareToDate() {
- Date theTest = new Timestamp(TIME_EARLY);
- Date theTest2 = new Timestamp(TIME_LATE);
-
- for (long element : TIME_ARRAY) {
- Timestamp theTimestamp = new Timestamp(element);
- Date theTimestamp2 = new Timestamp(element);
-
- assertTrue(theTimestamp.compareTo(theTest) > 0);
- assertTrue(theTimestamp.compareTo(theTest2) < 0);
- assertEquals(0, theTimestamp.compareTo(theTimestamp2));
- } // end for
-
- Date nastyTest = new Date();
- Timestamp theTimestamp = new Timestamp(TIME_ARRAY[1]);
- try {
- theTimestamp.compareTo(nastyTest);
- // It throws ClassCastException in JDK 1.5.0_06 but in 1.5.0_07 it
- // does not throw the expected exception.
- fail("testCompareToObject: Did not get expected ClassCastException");
- } catch (ClassCastException e) {
- // Should get here
- /*
- * System.out.println("testCompareToObject: ClassCastException as
- * expected"); System.out.println("Exception message: " +
- * e.getMessage());
- */
- } // end try
-
- } // end method testcompareToObject
-
- /**
- * @tests serialization/deserialization compatibility.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Serialization test",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- Timestamp object = new Timestamp(100L);
- SerializationTest.verifySelf(object);
- }
-
- /**
- * @tests serialization/deserialization compatibility with RI.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Serialization test",
- method = "!SerializationGolden",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- Timestamp object = new Timestamp(100L);
- SerializationTest.verifyGolden(this, object);
- }
-
- /**
- * @tests java.sql.Timestamp#toString()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
-
- Timestamp t1 = new Timestamp(Long.MIN_VALUE);
- assertEquals("292278994-08-17 07:12:55.192", t1.toString());
-
- Timestamp t2 = new Timestamp(Long.MIN_VALUE + 1);
- assertEquals("292278994-08-17 07:12:55.193", t2.toString());
-
- Timestamp t3 = new Timestamp(Long.MIN_VALUE + 807);
- assertEquals("292278994-08-17 07:12:55.999", t3.toString());
-
- Timestamp t4 = new Timestamp(Long.MIN_VALUE + 808);
- assertEquals("292269055-12-02 16:47:05.0", t4.toString());
- }
-
- // Reset defualt timezone
- TimeZone defaultTimeZone = TimeZone.getDefault();
-
- protected void tearDown() {
- TimeZone.setDefault(defaultTimeZone);
- }
-} // end class TimestampTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TypesTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TypesTest.java
deleted file mode 100644
index b314a4f..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/java/sql/TypesTest.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.java.sql;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(java.sql.Types.class)
-public class TypesTest extends TestCase {
-
- /*
- * Public statics test
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Field testing",
- method = "!Constants",
- args = {}
- )
- public void testPublicStatics() {
-
- HashMap<String, Integer> thePublicStatics = new HashMap<String, Integer>();
- thePublicStatics.put("BOOLEAN", new Integer(16));
- thePublicStatics.put("DATALINK", new Integer(70));
- thePublicStatics.put("REF", new Integer(2006));
- thePublicStatics.put("CLOB", new Integer(2005));
- thePublicStatics.put("BLOB", new Integer(2004));
- thePublicStatics.put("ARRAY", new Integer(2003));
- thePublicStatics.put("STRUCT", new Integer(2002));
- thePublicStatics.put("DISTINCT", new Integer(2001));
- thePublicStatics.put("JAVA_OBJECT", new Integer(2000));
- thePublicStatics.put("OTHER", new Integer(1111));
- thePublicStatics.put("NULL", new Integer(0));
- thePublicStatics.put("LONGVARBINARY", new Integer(-4));
- thePublicStatics.put("VARBINARY", new Integer(-3));
- thePublicStatics.put("BINARY", new Integer(-2));
- thePublicStatics.put("TIMESTAMP", new Integer(93));
- thePublicStatics.put("TIME", new Integer(92));
- thePublicStatics.put("DATE", new Integer(91));
- thePublicStatics.put("LONGVARCHAR", new Integer(-1));
- thePublicStatics.put("VARCHAR", new Integer(12));
- thePublicStatics.put("CHAR", new Integer(1));
- thePublicStatics.put("DECIMAL", new Integer(3));
- thePublicStatics.put("NUMERIC", new Integer(2));
- thePublicStatics.put("DOUBLE", new Integer(8));
- thePublicStatics.put("REAL", new Integer(7));
- thePublicStatics.put("FLOAT", new Integer(6));
- thePublicStatics.put("BIGINT", new Integer(-5));
- thePublicStatics.put("INTEGER", new Integer(4));
- thePublicStatics.put("SMALLINT", new Integer(5));
- thePublicStatics.put("TINYINT", new Integer(-6));
- thePublicStatics.put("BIT", new Integer(-7));
-
- Class<?> typesClass;
- try {
- typesClass = Class.forName("java.sql.Types");
- } catch (ClassNotFoundException e) {
- fail("java.sql.Types class not found!");
- return;
- } // end try
-
- Field[] theFields = typesClass.getDeclaredFields();
- int requiredModifier = Modifier.PUBLIC + Modifier.STATIC
- + Modifier.FINAL;
-
- int countPublicStatics = 0;
- for (Field element : theFields) {
- String fieldName = element.getName();
- int theMods = element.getModifiers();
- if (Modifier.isPublic(theMods) && Modifier.isStatic(theMods)) {
- try {
- Object fieldValue = element.get(null);
- Object expectedValue = thePublicStatics.get(fieldName);
- if (expectedValue == null) {
- fail("Field " + fieldName + " missing!");
- } // end
- assertEquals("Field " + fieldName + " value mismatch: ",
- expectedValue, fieldValue);
- assertEquals("Field " + fieldName + " modifier mismatch: ",
- requiredModifier, theMods);
- countPublicStatics++;
- } catch (IllegalAccessException e) {
- fail("Illegal access to Field " + fieldName);
- } // end try
- } // end if
- } // end for
-
- } // end method testPublicStatics
-
-} // end class TypesTest
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/AllTests.java b/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/AllTests.java
deleted file mode 100644
index 8183bbf..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/AllTests.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.javax.sql;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * This is autogenerated source file. Includes tests for package org.apache.harmony.sql.tests.javax.sql;
- */
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All tests for package org.apache.harmony.sql.tests.javax.sql;");
- // $JUnit-BEGIN$
-
- suite.addTestSuite(ConnectionEventTest.class);
- suite.addTestSuite(RowSetEventTest.class);
-
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/ConnectionEventTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/ConnectionEventTest.java
deleted file mode 100644
index 4c2c374..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/ConnectionEventTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.javax.sql;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.sql.SQLException;
-import java.io.Serializable;
-
-import javax.sql.ConnectionEvent;
-import javax.sql.PooledConnection;
-
-import org.apache.harmony.testframework.serialization.SerializationTest;
-import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
-@TestTargetClass(ConnectionEvent.class)
-public class ConnectionEventTest extends TestCase {
-
- /**
- * @tests {@link javax.sql.ConnectionEvent#ConnectionEvent(PooledConnection)}
- *
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "functional test missing but not feasible: no implementation available.",
- method = "ConnectionEvent",
- args = {javax.sql.PooledConnection.class}
- )
- public void testConstructorConnection() {
- try {
- new ConnectionEvent(null);
- fail("illegal argument exception expected");
- } catch (IllegalArgumentException e) {
- }
-
- Impl_PooledConnection ipc = new Impl_PooledConnection();
- ConnectionEvent ce = new ConnectionEvent(ipc);
- assertSame(ipc, ce.getSource());
- assertNull(ce.getSQLException());
-
- //cross test
- ConnectionEvent ce2 = new ConnectionEvent(ipc,null);
- assertSame(ce2.getSource(),ce.getSource());
- }
-
-
-
- /**
- * @tests {@link javax.sql.ConnectionEvent#ConnectionEvent(PooledConnection, SQLException)}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "functional test missing but not feasible: no implementation available.",
- method = "ConnectionEvent",
- args = {javax.sql.PooledConnection.class, java.sql.SQLException.class}
- )
- public void testConstructorConnectionSQLException() {
- try {
- new ConnectionEvent(null, null);
- fail("illegal argument exception expected");
- } catch (IllegalArgumentException e) {
- }
-
- Impl_PooledConnection ipc = new Impl_PooledConnection();
- ConnectionEvent ce = new ConnectionEvent(ipc, null);
- assertSame(ipc, ce.getSource());
- assertNull(ce.getSQLException());
-
- SQLException e = new SQLException();
- ce = new ConnectionEvent(ipc, e);
- assertSame(ipc, ce.getSource());
- assertSame(e, ce.getSQLException());
- }
-
- /**
- * @tests {@link javax.sql.ConnectionEvent#getSQLException()}
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "functional test missing but not feasible: no implementation available.",
- method = "getSQLException",
- args = {}
- )
- public void testGetSQLException() {
-
- Impl_PooledConnection ipc = new Impl_PooledConnection();
- ConnectionEvent ce = new ConnectionEvent(ipc);
-
- ConnectionEvent ce2 = new ConnectionEvent(ipc, null);
- assertNull(ce.getSQLException());
- assertEquals(ce2.getSQLException(), ce.getSQLException());
-
- SQLException e = new SQLException();
- ConnectionEvent ce3 = new ConnectionEvent(ipc, e);
- assertNotNull(ce3.getSQLException());
- assertNotSame(ce3.getSQLException(), ce2.getSQLException());
-
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "!SerializationSelf",
- args = {}
- )
- public void testSerializationSelf() throws Exception {
- Impl_PooledConnection ipc = new Impl_PooledConnection();
- SQLException e = new SQLException();
- ConnectionEvent ce = new ConnectionEvent(ipc, e);
- SerializationTest.verifySelf(ce, CONNECTIONEVENT_COMPARATOR);
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "!Serialization",
- args = {}
- )
- public void testSerializationCompatibility() throws Exception {
- Impl_PooledConnection ipc = new Impl_PooledConnection();
- SQLException nextSQLException = new SQLException("nextReason",
- "nextSQLState", 33);
-
- int vendorCode = 10;
- SQLException sqlException = new SQLException("reason", "SQLState",
- vendorCode);
-
- sqlException.setNextException(nextSQLException);
-
- ConnectionEvent ce = new ConnectionEvent(ipc, sqlException);
-
- SerializationTest.verifyGolden(this, ce, CONNECTIONEVENT_COMPARATOR);
- }
-
- private static final SerializableAssert CONNECTIONEVENT_COMPARATOR = new SerializableAssert() {
-
- public void assertDeserialized(Serializable initial,
- Serializable deserialized) {
- ConnectionEvent ceInitial = (ConnectionEvent) initial;
- ConnectionEvent ceDeser = (ConnectionEvent) deserialized;
-
- SQLException initThr = ceInitial.getSQLException();
- SQLException dserThr = ceDeser.getSQLException();
-
- // verify SQLState
- assertEquals(initThr.getSQLState(), dserThr.getSQLState());
-
- // verify vendorCode
- assertEquals(initThr.getErrorCode(), dserThr.getErrorCode());
-
- // verify next
- if (initThr.getNextException() == null) {
- assertNull(dserThr.getNextException());
- }
- }
-
- };
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_PooledConnection.java b/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_PooledConnection.java
deleted file mode 100644
index 28943fa..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_PooledConnection.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.javax.sql;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import javax.sql.ConnectionEventListener;
-import javax.sql.PooledConnection;
-import javax.sql.StatementEventListener;
-
-class Impl_PooledConnection implements PooledConnection {
- public void addConnectionEventListener(ConnectionEventListener theListener) {
- }
-
- public void close() throws SQLException {
- }
-
- public Connection getConnection() throws SQLException {
- return null;
- }
-
- public void removeConnectionEventListener(
- ConnectionEventListener theListener) {
- }
-
- public void addStatementEventListener(StatementEventListener listener) {
- }
-
- public void removeStatementEventListener(StatementEventListener listener) {
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_RowSet.java b/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_RowSet.java
deleted file mode 100644
index 342bfea..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/Impl_RowSet.java
+++ /dev/null
@@ -1,1272 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.javax.sql;
-
-import java.io.InputStream;
-import java.io.Reader;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.sql.Array;
-import java.sql.Blob;
-import java.sql.Clob;
-import java.sql.Date;
-import java.sql.NClob;
-import java.sql.Ref;
-import java.sql.ResultSetMetaData;
-import java.sql.RowId;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.SQLXML;
-import java.sql.Statement;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Calendar;
-import java.util.Map;
-import javax.sql.RowSet;
-import javax.sql.RowSetListener;
-
-@SuppressWarnings("deprecation")
-class Impl_RowSet implements RowSet {
- public void addRowSetListener(RowSetListener theListener) {
- }
-
- public void clearParameters() throws SQLException {
- }
-
- public void execute() throws SQLException {
- }
-
- public String getCommand() {
- return null;
- }
-
- public String getDataSourceName() {
- return null;
- }
-
- public boolean getEscapeProcessing() throws SQLException {
- return false;
- }
-
- public int getMaxFieldSize() throws SQLException {
- return 0;
- }
-
- public int getMaxRows() throws SQLException {
- return 0;
- }
-
- public String getPassword() {
- return null;
- }
-
- public int getQueryTimeout() throws SQLException {
- return 0;
- }
-
- public int getTransactionIsolation() {
- return 0;
- }
-
- public Map<String, Class<?>> getTypeMap() throws SQLException {
- return null;
- }
-
- public String getUrl() throws SQLException {
- return null;
- }
-
- public String getUsername() {
- return null;
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- public void removeRowSetListener(RowSetListener theListener) {
- }
-
- public void setArray(int parameterIndex, Array theArray)
- throws SQLException {
- }
-
- public void setAsciiStream(int parameterIndex, InputStream theInputStream,
- int length) throws SQLException {
- }
-
- public void setBigDecimal(int parameterIndex, BigDecimal theBigDecimal)
- throws SQLException {
- }
-
- public void setBinaryStream(int parameterIndex, InputStream theInputStream,
- int length) throws SQLException {
- }
-
- public void setBlob(int parameterIndex, Blob theBlob) throws SQLException {
- }
-
- public void setBoolean(int parameterIndex, boolean theBoolean)
- throws SQLException {
- }
-
- public void setByte(int parameterIndex, byte theByte) throws SQLException {
- }
-
- public void setBytes(int parameterIndex, byte[] theByteArray)
- throws SQLException {
- }
-
- public void setCharacterStream(int parameterIndex, Reader theReader,
- int length) throws SQLException {
- }
-
- public void setClob(int parameterIndex, Clob theClob) throws SQLException {
- }
-
- public void setCommand(String cmd) throws SQLException {
- }
-
- public void setConcurrency(int concurrency) throws SQLException {
- }
-
- public void setDataSourceName(String name) throws SQLException {
- }
-
- public void setDate(int parameterIndex, Date theDate, Calendar theCalendar)
- throws SQLException {
- }
-
- public void setDate(int parameterIndex, Date theDate) throws SQLException {
- }
-
- public void setDouble(int parameterIndex, double theDouble)
- throws SQLException {
- }
-
- public void setEscapeProcessing(boolean enable) throws SQLException {
- }
-
- public void setFloat(int parameterIndex, float theFloat)
- throws SQLException {
- }
-
- public void setInt(int parameterIndex, int theInteger) throws SQLException {
- }
-
- public void setLong(int parameterIndex, long theLong) throws SQLException {
- }
-
- public void setMaxFieldSize(int max) throws SQLException {
- }
-
- public void setMaxRows(int max) throws SQLException {
- }
-
- public void setNull(int parameterIndex, int sqlType, String typeName)
- throws SQLException {
- }
-
- public void setNull(int parameterIndex, int sqlType) throws SQLException {
- }
-
- public void setObject(int parameterIndex, Object theObject,
- int targetSqlType, int scale) throws SQLException {
- }
-
- public void setObject(int parameterIndex, Object theObject,
- int targetSqlType) throws SQLException {
- }
-
- public void setObject(int parameterIndex, Object theObject)
- throws SQLException {
- }
-
- public void setPassword(String password) throws SQLException {
- }
-
- public void setQueryTimeout(int seconds) throws SQLException {
- }
-
- public void setReadOnly(boolean readOnly) throws SQLException {
- }
-
- public void setRef(int parameterIndex, Ref theRef) throws SQLException {
- }
-
- public void setShort(int parameterIndex, short theShort)
- throws SQLException {
- }
-
- public void setString(int parameterIndex, String theString)
- throws SQLException {
- }
-
- public void setTime(int parameterIndex, Time theTime, Calendar theCalendar)
- throws SQLException {
- }
-
- public void setTime(int parameterIndex, Time theTime) throws SQLException {
- }
-
- public void setTimestamp(int parameterIndex, Timestamp theTimestamp,
- Calendar theCalendar) throws SQLException {
- }
-
- public void setTimestamp(int parameterIndex, Timestamp theTimestamp)
- throws SQLException {
- }
-
- public void setTransactionIsolation(int level) throws SQLException {
- }
-
- public void setType(int type) throws SQLException {
- }
-
- public void setTypeMap(Map<String, Class<?>> theTypeMap)
- throws SQLException {
- }
-
- public void setUrl(String theURL) throws SQLException {
- }
-
- public void setUsername(String theUsername) throws SQLException {
- }
-
- public boolean absolute(int row) throws SQLException {
- return false;
- }
-
- public void afterLast() throws SQLException {
- }
-
- public void beforeFirst() throws SQLException {
- }
-
- public void cancelRowUpdates() throws SQLException {
- }
-
- public void clearWarnings() throws SQLException {
- }
-
- public void close() throws SQLException {
- }
-
- public void deleteRow() throws SQLException {
- }
-
- public int findColumn(String columnName) throws SQLException {
- return 0;
- }
-
- public boolean first() throws SQLException {
- return false;
- }
-
- public Array getArray(int columnIndex) throws SQLException {
- return null;
- }
-
- public Array getArray(String colName) throws SQLException {
- return null;
- }
-
- public InputStream getAsciiStream(int columnIndex) throws SQLException {
- return null;
- }
-
- public InputStream getAsciiStream(String columnName) throws SQLException {
- return null;
- }
-
- public BigDecimal getBigDecimal(int columnIndex, int scale)
- throws SQLException {
- return null;
- }
-
- public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
- return null;
- }
-
- public BigDecimal getBigDecimal(String columnName, int scale)
- throws SQLException {
- return null;
- }
-
- public BigDecimal getBigDecimal(String columnName) throws SQLException {
- return null;
- }
-
- public InputStream getBinaryStream(int columnIndex) throws SQLException {
- return null;
- }
-
- public InputStream getBinaryStream(String columnName) throws SQLException {
- return null;
- }
-
- public Blob getBlob(int columnIndex) throws SQLException {
- return null;
- }
-
- public Blob getBlob(String columnName) throws SQLException {
- return null;
- }
-
- public boolean getBoolean(int columnIndex) throws SQLException {
- return false;
- }
-
- public boolean getBoolean(String columnName) throws SQLException {
- return false;
- }
-
- public byte getByte(int columnIndex) throws SQLException {
- return 0;
- }
-
- public byte getByte(String columnName) throws SQLException {
- return 0;
- }
-
- public byte[] getBytes(int columnIndex) throws SQLException {
- return null;
- }
-
- public byte[] getBytes(String columnName) throws SQLException {
- return null;
- }
-
- public Reader getCharacterStream(int columnIndex) throws SQLException {
- return null;
- }
-
- public Reader getCharacterStream(String columnName) throws SQLException {
- return null;
- }
-
- public Clob getClob(int columnIndex) throws SQLException {
- return null;
- }
-
- public Clob getClob(String colName) throws SQLException {
- return null;
- }
-
- public int getConcurrency() throws SQLException {
- return 0;
- }
-
- public String getCursorName() throws SQLException {
- return null;
- }
-
- public Date getDate(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- public Date getDate(int columnIndex) throws SQLException {
- return null;
- }
-
- public Date getDate(String columnName, Calendar cal) throws SQLException {
- return null;
- }
-
- public Date getDate(String columnName) throws SQLException {
- return null;
- }
-
- public double getDouble(int columnIndex) throws SQLException {
- return 0;
- }
-
- public double getDouble(String columnName) throws SQLException {
- return 0;
- }
-
- public int getFetchDirection() throws SQLException {
- return 0;
- }
-
- public int getFetchSize() throws SQLException {
- return 0;
- }
-
- public float getFloat(int columnIndex) throws SQLException {
- return 0;
- }
-
- public float getFloat(String columnName) throws SQLException {
- return 0;
- }
-
- public int getInt(int columnIndex) throws SQLException {
- return 0;
- }
-
- public int getInt(String columnName) throws SQLException {
- return 0;
- }
-
- public long getLong(int columnIndex) throws SQLException {
- return 0;
- }
-
- public long getLong(String columnName) throws SQLException {
- return 0;
- }
-
- public ResultSetMetaData getMetaData() throws SQLException {
- return null;
- }
-
- public Object getObject(int columnIndex, Map<String, Class<?>> map)
- throws SQLException {
- return null;
- }
-
- public Object getObject(int columnIndex) throws SQLException {
- return null;
- }
-
- public Object getObject(String columnName, Map<String, Class<?>> map)
- throws SQLException {
- return null;
- }
-
- public Object getObject(String columnName) throws SQLException {
- return null;
- }
-
- public Ref getRef(int columnIndex) throws SQLException {
- return null;
- }
-
- public Ref getRef(String colName) throws SQLException {
- return null;
- }
-
- public int getRow() throws SQLException {
- return 0;
- }
-
- public short getShort(int columnIndex) throws SQLException {
- return 0;
- }
-
- public short getShort(String columnName) throws SQLException {
- return 0;
- }
-
- public Statement getStatement() throws SQLException {
- return null;
- }
-
- public String getString(int columnIndex) throws SQLException {
- return null;
- }
-
- public String getString(String columnName) throws SQLException {
- return null;
- }
-
- public Time getTime(int columnIndex, Calendar cal) throws SQLException {
- return null;
- }
-
- public Time getTime(int columnIndex) throws SQLException {
- return null;
- }
-
- public Time getTime(String columnName, Calendar cal) throws SQLException {
- return null;
- }
-
- public Time getTime(String columnName) throws SQLException {
- return null;
- }
-
- public Timestamp getTimestamp(int columnIndex, Calendar cal)
- throws SQLException {
- return null;
- }
-
- public Timestamp getTimestamp(int columnIndex) throws SQLException {
- return null;
- }
-
- public Timestamp getTimestamp(String columnName, Calendar cal)
- throws SQLException {
- return null;
- }
-
- public Timestamp getTimestamp(String columnName) throws SQLException {
- return null;
- }
-
- public int getType() throws SQLException {
- return 0;
- }
-
- public InputStream getUnicodeStream(int columnIndex) throws SQLException {
- return null;
- }
-
- public InputStream getUnicodeStream(String columnName) throws SQLException {
- return null;
- }
-
- public URL getURL(int columnIndex) throws SQLException {
- return null;
- }
-
- public URL getURL(String columnName) throws SQLException {
- return null;
- }
-
- public SQLWarning getWarnings() throws SQLException {
- return null;
- }
-
- public void insertRow() throws SQLException {
- }
-
- public boolean isAfterLast() throws SQLException {
- return false;
- }
-
- public boolean isBeforeFirst() throws SQLException {
- return false;
- }
-
- public boolean isFirst() throws SQLException {
- return false;
- }
-
- public boolean isLast() throws SQLException {
- return false;
- }
-
- public boolean last() throws SQLException {
- return false;
- }
-
- public void moveToCurrentRow() throws SQLException {
- }
-
- public void moveToInsertRow() throws SQLException {
- }
-
- public boolean next() throws SQLException {
- return false;
- }
-
- public boolean previous() throws SQLException {
- return false;
- }
-
- public void refreshRow() throws SQLException {
- }
-
- public boolean relative(int rows) throws SQLException {
- return false;
- }
-
- public boolean rowDeleted() throws SQLException {
- return false;
- }
-
- public boolean rowInserted() throws SQLException {
- return false;
- }
-
- public boolean rowUpdated() throws SQLException {
- return false;
- }
-
- public void setFetchDirection(int direction) throws SQLException {
- }
-
- public void setFetchSize(int rows) throws SQLException {
- }
-
- public void updateArray(int columnIndex, Array x) throws SQLException {
- }
-
- public void updateArray(String columnName, Array x) throws SQLException {
- }
-
- public void updateAsciiStream(int columnIndex, InputStream x, int length)
- throws SQLException {
- }
-
- public void updateAsciiStream(String columnName, InputStream x, int length)
- throws SQLException {
- }
-
- public void updateBigDecimal(int columnIndex, BigDecimal x)
- throws SQLException {
- }
-
- public void updateBigDecimal(String columnName, BigDecimal x)
- throws SQLException {
- }
-
- public void updateBinaryStream(int columnIndex, InputStream x, int length)
- throws SQLException {
- }
-
- public void updateBinaryStream(String columnName, InputStream x, int length)
- throws SQLException {
- }
-
- public void updateBlob(int columnIndex, Blob x) throws SQLException {
- }
-
- public void updateBlob(String columnName, Blob x) throws SQLException {
- }
-
- public void updateBoolean(int columnIndex, boolean x) throws SQLException {
- }
-
- public void updateBoolean(String columnName, boolean x) throws SQLException {
- }
-
- public void updateByte(int columnIndex, byte x) throws SQLException {
- }
-
- public void updateByte(String columnName, byte x) throws SQLException {
- }
-
- public void updateBytes(int columnIndex, byte[] x) throws SQLException {
- }
-
- public void updateBytes(String columnName, byte[] x) throws SQLException {
- }
-
- public void updateCharacterStream(int columnIndex, Reader x, int length)
- throws SQLException {
- }
-
- public void updateCharacterStream(String columnName, Reader reader,
- int length) throws SQLException {
- }
-
- public void updateClob(int columnIndex, Clob x) throws SQLException {
- }
-
- public void updateClob(String columnName, Clob x) throws SQLException {
- }
-
- public void updateDate(int columnIndex, Date x) throws SQLException {
- }
-
- public void updateDate(String columnName, Date x) throws SQLException {
- }
-
- public void updateDouble(int columnIndex, double x) throws SQLException {
- }
-
- public void updateDouble(String columnName, double x) throws SQLException {
- }
-
- public void updateFloat(int columnIndex, float x) throws SQLException {
- }
-
- public void updateFloat(String columnName, float x) throws SQLException {
- }
-
- public void updateInt(int columnIndex, int x) throws SQLException {
- }
-
- public void updateInt(String columnName, int x) throws SQLException {
- }
-
- public void updateLong(int columnIndex, long x) throws SQLException {
- }
-
- public void updateLong(String columnName, long x) throws SQLException {
- }
-
- public void updateNull(int columnIndex) throws SQLException {
- }
-
- public void updateNull(String columnName) throws SQLException {
- }
-
- public void updateObject(int columnIndex, Object x, int scale)
- throws SQLException {
- }
-
- public void updateObject(int columnIndex, Object x) throws SQLException {
- }
-
- public void updateObject(String columnName, Object x, int scale)
- throws SQLException {
- }
-
- public void updateObject(String columnName, Object x) throws SQLException {
- }
-
- public void updateRef(int columnIndex, Ref x) throws SQLException {
- }
-
- public void updateRef(String columnName, Ref x) throws SQLException {
- }
-
- public void updateRow() throws SQLException {
- }
-
- public void updateShort(int columnIndex, short x) throws SQLException {
- }
-
- public void updateShort(String columnName, short x) throws SQLException {
- }
-
- public void updateString(int columnIndex, String x) throws SQLException {
- }
-
- public void updateString(String columnName, String x) throws SQLException {
- }
-
- public void updateTime(int columnIndex, Time x) throws SQLException {
- }
-
- public void updateTime(String columnName, Time x) throws SQLException {
- }
-
- public void updateTimestamp(int columnIndex, Timestamp x)
- throws SQLException {
- }
-
- public void updateTimestamp(String columnName, Timestamp x)
- throws SQLException {
- }
-
- public boolean wasNull() throws SQLException {
- return false;
- }
-
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return false;
- }
-
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return null;
- }
-
- public int getHoldability() throws SQLException {
- return 0;
- }
-
- public Reader getNCharacterStream(int columnIndex) throws SQLException {
- return null;
- }
-
- public Reader getNCharacterStream(String columnLabel) throws SQLException {
- return null;
- }
-
- public NClob getNClob(int columnIndex) throws SQLException {
- return null;
- }
-
- public NClob getNClob(String columnLabel) throws SQLException {
- return null;
- }
-
- public String getNString(int columnIndex) throws SQLException {
- return null;
- }
-
- public String getNString(String columnLabel) throws SQLException {
- return null;
- }
-
- public RowId getRowId(int columnIndex) throws SQLException {
- return null;
- }
-
- public RowId getRowId(String columnLabel) throws SQLException {
- return null;
- }
-
- public SQLXML getSQLXML(int columnIndex) throws SQLException {
- return null;
- }
-
- public SQLXML getSQLXML(String columnLabel) throws SQLException {
- return null;
- }
-
- public boolean isClosed() throws SQLException {
- return false;
- }
-
- public void updateAsciiStream(int columnIndex, InputStream x, long length)
- throws SQLException {
-
- }
-
- public void updateAsciiStream(String columnLabel, InputStream x, long length)
- throws SQLException {
-
- }
-
- public void updateAsciiStream(int columnIndex, InputStream x)
- throws SQLException {
-
- }
-
- public void updateAsciiStream(String columnLabel, InputStream x)
- throws SQLException {
-
- }
-
- public void updateBinaryStream(int columnIndex, InputStream x, long length)
- throws SQLException {
-
- }
-
- public void updateBinaryStream(String columnLabel, InputStream x,
- long length) throws SQLException {
-
- }
-
- public void updateBinaryStream(int columnIndex, InputStream x)
- throws SQLException {
-
- }
-
- public void updateBinaryStream(String columnLabel, InputStream x)
- throws SQLException {
-
- }
-
- public void updateBlob(int columnIndex, InputStream inputStream, long length)
- throws SQLException {
-
- }
-
- public void updateBlob(String columnLabel, InputStream inputStream,
- long length) throws SQLException {
-
- }
-
- public void updateBlob(int columnIndex, InputStream inputStream)
- throws SQLException {
-
- }
-
- public void updateBlob(String columnLabel, InputStream inputStream)
- throws SQLException {
-
- }
-
- public void updateCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
-
- }
-
- public void updateCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
-
- }
-
- public void updateCharacterStream(int columnIndex, Reader x)
- throws SQLException {
-
- }
-
- public void updateCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
-
- }
-
- public void updateClob(int columnIndex, Reader reader, long length)
- throws SQLException {
-
- }
-
- public void updateClob(String columnLabel, Reader reader, long length)
- throws SQLException {
-
- }
-
- public void updateClob(int columnIndex, Reader reader) throws SQLException {
-
- }
-
- public void updateClob(String columnLabel, Reader reader)
- throws SQLException {
-
- }
-
- public void updateNCharacterStream(int columnIndex, Reader x, long length)
- throws SQLException {
-
- }
-
- public void updateNCharacterStream(String columnLabel, Reader reader,
- long length) throws SQLException {
-
- }
-
- public void updateNCharacterStream(int columnIndex, Reader x)
- throws SQLException {
-
- }
-
- public void updateNCharacterStream(String columnLabel, Reader reader)
- throws SQLException {
-
- }
-
- public void updateNClob(int columnIndex, NClob nClob) throws SQLException {
-
- }
-
- public void updateNClob(String columnLabel, NClob nClob)
- throws SQLException {
-
- }
-
- public void updateNClob(int columnIndex, Reader reader, long length)
- throws SQLException {
-
- }
-
- public void updateNClob(String columnLabel, Reader reader, long length)
- throws SQLException {
-
- }
-
- public void updateNClob(int columnIndex, Reader reader) throws SQLException {
-
- }
-
- public void updateNClob(String columnLabel, Reader reader)
- throws SQLException {
-
- }
-
- public void updateNString(int columnIndex, String nString)
- throws SQLException {
-
- }
-
- public void updateNString(String columnLabel, String nString)
- throws SQLException {
-
- }
-
- public void updateRowId(int columnIndex, RowId x) throws SQLException {
-
- }
-
- public void updateRowId(String columnLabel, RowId x) throws SQLException {
-
- }
-
- public void updateSQLXML(int columnIndex, SQLXML xmlObject)
- throws SQLException {
-
- }
-
- public void updateSQLXML(String columnLabel, SQLXML xmlObject)
- throws SQLException {
-
- }
-
- public void setAsciiStream(int parameterIndex, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setAsciiStream(String parameterName, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setAsciiStream(String parameterName,
- InputStream theInputStream, int length) throws SQLException {
-
- }
-
- public void setBigDecimal(String parameterName, BigDecimal theBigDecimal)
- throws SQLException {
-
- }
-
- public void setBinaryStream(int parameterIndex, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setBinaryStream(String parameterName, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setBinaryStream(String parameterName,
- InputStream theInputStream, int length) throws SQLException {
-
- }
-
- public void setBlob(int parameterIndex, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setBlob(int parameterIndex, InputStream theInputStream,
- long length) throws SQLException {
-
- }
-
- public void setBlob(String parameterName, InputStream theInputStream)
- throws SQLException {
-
- }
-
- public void setBlob(String parameterName, InputStream theInputStream,
- long length) throws SQLException {
-
- }
-
- public void setBlob(String parameterName, Blob theBlob) throws SQLException {
-
- }
-
- public void setBoolean(String parameterName, boolean theBoolean)
- throws SQLException {
-
- }
-
- public void setByte(String parameterName, byte theByte) throws SQLException {
-
- }
-
- public void setBytes(String parametername, byte[] theByteArray)
- throws SQLException {
-
- }
-
- public void setCharacterStream(int parameterIndex, Reader theReader)
- throws SQLException {
-
- }
-
- public void setCharacterStream(String parameterName, Reader theReader)
- throws SQLException {
-
- }
-
- public void setCharacterStream(String parameterName, Reader theReader,
- int length) throws SQLException {
-
- }
-
- public void setClob(int parameterIndex, Reader theReader)
- throws SQLException {
-
- }
-
- public void setClob(int parameterIndex, Reader theReader, long length)
- throws SQLException {
-
- }
-
- public void setClob(String parameterName, Reader theReader)
- throws SQLException {
-
- }
-
- public void setClob(String parameterName, Reader theReader, long length)
- throws SQLException {
-
- }
-
- public void setDate(String parameterName, Date theDate) throws SQLException {
-
- }
-
- public void setDate(String parameterName, Date theDate, Calendar theCalendar)
- throws SQLException {
-
- }
-
- public void setDouble(String parameterName, double theDouble)
- throws SQLException {
-
- }
-
- public void setFloat(String parameterName, float theFloat)
- throws SQLException {
-
- }
-
- public void setInt(String parameterName, int theInteger)
- throws SQLException {
-
- }
-
- public void setLong(String parameterName, long theLong) throws SQLException {
-
- }
-
- public void setNCharacterStream(int parameterIndex, Reader theReader)
- throws SQLException {
-
- }
-
- public void setNCharacterStream(int parameterIndex, Reader theReader,
- long length) throws SQLException {
-
- }
-
- public void setNCharacterStream(String parameterName, Reader theReader)
- throws SQLException {
-
- }
-
- public void setNCharacterStream(String parameterName, Reader theReader,
- long length) throws SQLException {
-
- }
-
- public void setNClob(int parameterIndex, NClob theNClob)
- throws SQLException {
-
- }
-
- public void setNClob(int parameterIndex, Reader theReader)
- throws SQLException {
-
- }
-
- public void setNClob(int parameterIndex, Reader theReader, long length)
- throws SQLException {
-
- }
-
- public void setNClob(String parameterName, Reader theReader)
- throws SQLException {
-
- }
-
- public void setNClob(String parameterName, Reader theReader, long length)
- throws SQLException {
-
- }
-
- public void setNString(int parameterIndex, String theNString)
- throws SQLException {
-
- }
-
- public void setNString(String parameterName, String theNString)
- throws SQLException {
-
- }
-
- public void setNull(String parameterName, int sqlType) throws SQLException {
-
- }
-
- public void setNull(String parameterName, int sqlType, String typeName)
- throws SQLException {
-
- }
-
- public void setObject(String parameterName, Object theObject)
- throws SQLException {
-
- }
-
- public void setObject(String parameterName, Object theObject,
- int targetSqlType) throws SQLException {
-
- }
-
- public void setObject(String parameterName, Object theObject,
- int targetSqlType, int scale) throws SQLException {
-
- }
-
- public void setRowId(int parameterIndex, RowId theRowId)
- throws SQLException {
-
- }
-
- public void setRowId(String parameterName, RowId theRowId)
- throws SQLException {
-
- }
-
- public void setSQLXML(int parameterIndex, SQLXML theSQLXML)
- throws SQLException {
-
- }
-
- public void setSQLXML(String parameterName, SQLXML theSQLXML)
- throws SQLException {
-
- }
-
- public void setShort(String parameterName, short theShort)
- throws SQLException {
-
- }
-
- public void setString(String parameterName, String theString)
- throws SQLException {
-
- }
-
- public void setTime(String parameterName, Time theTime) throws SQLException {
-
- }
-
- public void setTime(String parameterName, Time theTime, Calendar theCalendar)
- throws SQLException {
-
- }
-
- public void setTimestamp(String parameterName, Timestamp theTimestamp)
- throws SQLException {
-
- }
-
- public void setTimestamp(String parameterName, Timestamp theTimestamp,
- Calendar theCalendar) throws SQLException {
-
- }
-
- public void setURL(int parameterIndex, URL theURL) throws SQLException {
-
- }
-
- public void setClob(String parameterName, Clob x) throws SQLException {
-
- }
-
- public void setNClob(String parameterName, NClob value) throws SQLException {
-
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/RowSetEventTest.java b/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/RowSetEventTest.java
deleted file mode 100644
index 1af384b..0000000
--- a/luni/src/test/java/org/apache/harmony/sql/tests/javax/sql/RowSetEventTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.sql.tests.javax.sql;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import javax.sql.ConnectionEvent;
-import javax.sql.RowSet;
-import javax.sql.RowSetEvent;
-import junit.framework.TestCase;
-
-@TestTargetClass(RowSetEvent.class)
-public class RowSetEventTest extends TestCase {
-
- /**
- * @tests {@link javax.sql.RowSetEvent#RowSetEvent(javax.sql.RowSet)}.
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "functional test missing but not feasible: no implementation available.",
- method = "RowSetEvent",
- args = {javax.sql.RowSet.class}
- )
- public void testConstructor() {
- try {
- new RowSetEvent(null);
- fail("illegal argument exception expected");
- } catch (IllegalArgumentException e) {
- }
-
- Impl_RowSet irs = new Impl_RowSet();
- RowSetEvent rse = new RowSetEvent(irs);
- assertSame(irs, rse.getSource());
- }
-
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/xml/AllTests.java b/luni/src/test/java/org/apache/harmony/xml/AllTests.java
deleted file mode 100644
index c04c1b5..0000000
--- a/luni/src/test/java/org/apache/harmony/xml/AllTests.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(ExpatParserTest.class);
- return suite;
- }
-
-}
diff --git a/luni/src/test/java/org/apache/harmony/xml/ExpatParserTest.java b/luni/src/test/java/org/apache/harmony/xml/ExpatParserTest.java
deleted file mode 100644
index ff25ade..0000000
--- a/luni/src/test/java/org/apache/harmony/xml/ExpatParserTest.java
+++ /dev/null
@@ -1,892 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import org.kxml2.io.KXmlParser;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.ext.DefaultHandler2;
-import org.xml.sax.helpers.DefaultHandler;
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-public class ExpatParserTest extends TestCase {
-
- private static final String SNIPPET = "<dagny dad=\"bob\">hello</dagny>";
-
- public void testExceptions() {
- // From startElement().
- ContentHandler contentHandler = new DefaultHandler() {
- @Override
- public void startElement(String uri, String localName,
- String qName, Attributes attributes)
- throws SAXException {
- throw new SAXException();
- }
- };
- try {
- parse(SNIPPET, contentHandler);
- fail();
- } catch (SAXException checked) { /* expected */ }
-
- // From endElement().
- contentHandler = new DefaultHandler() {
- @Override
- public void endElement(String uri, String localName,
- String qName)
- throws SAXException {
- throw new SAXException();
- }
- };
- try {
- parse(SNIPPET, contentHandler);
- fail();
- } catch (SAXException checked) { /* expected */ }
-
- // From characters().
- contentHandler = new DefaultHandler() {
- @Override
- public void characters(char ch[], int start, int length)
- throws SAXException {
- throw new SAXException();
- }
- };
- try {
- parse(SNIPPET, contentHandler);
- fail();
- } catch (SAXException checked) { /* expected */ }
- }
-
- public void testSax() {
- try {
- // Parse String.
- TestHandler handler = new TestHandler();
- parse(SNIPPET, handler);
- validate(handler);
-
- // Parse Reader.
- handler = new TestHandler();
- parse(new StringReader(SNIPPET), handler);
- validate(handler);
-
- // Parse InputStream.
- handler = new TestHandler();
- parse(new ByteArrayInputStream(SNIPPET.getBytes()),
- Encoding.UTF_8, handler);
- validate(handler);
- } catch (SAXException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- static void validate(TestHandler handler) {
- assertEquals("dagny", handler.startElementName);
- assertEquals("dagny", handler.endElementName);
- assertEquals("hello", handler.text.toString());
- }
-
- static class TestHandler extends DefaultHandler {
-
- String startElementName;
- String endElementName;
- StringBuilder text = new StringBuilder();
-
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
-
- assertNull(this.startElementName);
- this.startElementName = localName;
-
- // Validate attributes.
- assertEquals(1, attributes.getLength());
- assertEquals("", attributes.getURI(0));
- assertEquals("dad", attributes.getLocalName(0));
- assertEquals("bob", attributes.getValue(0));
- assertEquals(0, attributes.getIndex("", "dad"));
- assertEquals("bob", attributes.getValue("", "dad"));
- }
-
- @Override
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- assertNull(this.endElementName);
- this.endElementName = localName;
- }
-
- @Override
- public void characters(char ch[], int start, int length)
- throws SAXException {
- this.text.append(ch, start, length);
- }
- }
-
- public void testPullParser() {
- try {
- XmlPullParser parser = newPullParser();
-
- // Test reader.
- parser.setInput(new StringReader(SNIPPET));
- validate(parser);
-
- // Test input stream.
- parser.setInput(new ByteArrayInputStream(SNIPPET.getBytes()),
- "UTF-8");
- validate(parser);
- } catch (XmlPullParserException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- static void validate(XmlPullParser parser)
- throws XmlPullParserException, IOException {
- assertEquals(XmlPullParser.START_DOCUMENT, parser.getEventType());
-
- assertEquals(0, parser.getDepth());
-
- assertEquals(XmlPullParser.START_TAG, parser.next());
-
- assertEquals(1, parser.getDepth());
-
- assertEquals("dagny", parser.getName());
- assertEquals(1, parser.getAttributeCount());
- assertEquals("dad", parser.getAttributeName(0));
- assertEquals("bob", parser.getAttributeValue(0));
- assertEquals("bob", parser.getAttributeValue(null, "dad"));
-
- assertEquals(XmlPullParser.TEXT, parser.next());
-
- assertEquals(1, parser.getDepth());
-
- assertEquals("hello", parser.getText());
-
- assertEquals(XmlPullParser.END_TAG, parser.next());
-
- assertEquals(1, parser.getDepth());
-
- assertEquals("dagny", parser.getName());
-
- assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
-
- assertEquals(0, parser.getDepth());
- }
-
- static final String XML =
- "<one xmlns='ns:default' xmlns:n1='ns:1' a='b'>\n"
- + " <n1:two c='d' n1:e='f' xmlns:n2='ns:2'>text</n1:two>\n"
- + "</one>";
-
- public void testExpatPullParserNamespaces() throws Exception {
- XmlPullParser pullParser = newPullParser();
- pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- pullParser.setInput(new StringReader(XML));
- testPullParserNamespaces(pullParser);
- }
-
- public void testKxmlPullParserNamespaces() throws Exception {
- XmlPullParser pullParser = new KXmlParser();
- pullParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
- pullParser.setInput(new StringReader(XML));
- testPullParserNamespaces(pullParser);
- }
-
- private void testPullParserNamespaces(XmlPullParser parser) throws Exception {
- assertEquals(0, parser.getDepth());
- assertEquals(0, parser.getNamespaceCount(0));
-
- try {
- parser.getNamespaceCount(1);
- fail();
- } catch (IndexOutOfBoundsException e) { /* expected */ }
-
- // one
- assertEquals(XmlPullParser.START_TAG, parser.next());
- assertEquals(1, parser.getDepth());
-
- checkNamespacesInOne(parser);
-
- // n1:two
- assertEquals(XmlPullParser.START_TAG, parser.nextTag());
-
- assertEquals(2, parser.getDepth());
- checkNamespacesInTwo(parser);
-
- // Body of two.
- assertEquals(XmlPullParser.TEXT, parser.next());
-
- // End of two.
- assertEquals(XmlPullParser.END_TAG, parser.nextTag());
-
- // Depth should still be 2.
- assertEquals(2, parser.getDepth());
-
- // We should still be able to see the namespaces from two.
- checkNamespacesInTwo(parser);
-
- // End of one.
- assertEquals(XmlPullParser.END_TAG, parser.nextTag());
-
- // Depth should be back to 1.
- assertEquals(1, parser.getDepth());
-
- // We can still see the namespaces in one.
- checkNamespacesInOne(parser);
-
- // We shouldn't be able to see the namespaces in two anymore.
- try {
- parser.getNamespaceCount(2);
- fail();
- } catch (IndexOutOfBoundsException e) { /* expected */ }
-
- assertEquals(XmlPullParser.END_DOCUMENT, parser.next());
-
- // We shouldn't be able to see the namespaces in one anymore.
- try {
- parser.getNamespaceCount(1);
- fail();
- } catch (IndexOutOfBoundsException e) { /* expected */ }
-
- assertEquals(0, parser.getNamespaceCount(0));
- }
-
- private void checkNamespacesInOne(XmlPullParser parser) throws XmlPullParserException {
- assertEquals(2, parser.getNamespaceCount(1));
-
- // Prefix for default namespace is null.
- assertNull(parser.getNamespacePrefix(0));
- assertEquals("ns:default", parser.getNamespaceUri(0));
-
- assertEquals("n1", parser.getNamespacePrefix(1));
- assertEquals("ns:1", parser.getNamespaceUri(1));
-
- assertEquals("ns:default", parser.getNamespace(null));
-
- // KXML returns null.
- // assertEquals("ns:default", parser.getNamespace(""));
- }
-
- private void checkNamespacesInTwo(XmlPullParser parser) throws XmlPullParserException {
- // These should still be valid.
- checkNamespacesInOne(parser);
-
- assertEquals(3, parser.getNamespaceCount(2));
-
- // Default ns should still be in the stack
- assertNull(parser.getNamespacePrefix(0));
- assertEquals("ns:default", parser.getNamespaceUri(0));
- }
-
- public void testNamespaces() {
- try {
- NamespaceHandler handler = new NamespaceHandler();
- parse(XML, handler);
- handler.validate();
- } catch (SAXException e) {
- throw new RuntimeException(e);
- }
- }
-
- static class NamespaceHandler implements ContentHandler {
-
- Locator locator;
- boolean documentStarted;
- boolean documentEnded;
- Map<String, String> prefixMappings = new HashMap<String, String>();
-
- boolean oneStarted;
- boolean twoStarted;
- boolean oneEnded;
- boolean twoEnded;
-
- public void validate() {
- assertTrue(documentEnded);
- }
-
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- public void startDocument() throws SAXException {
- documentStarted = true;
- assertNotNull(locator);
- assertEquals(0, prefixMappings.size());
- assertFalse(documentEnded);
- }
-
- public void endDocument() throws SAXException {
- assertTrue(documentStarted);
- assertTrue(oneEnded);
- assertTrue(twoEnded);
- assertEquals(0, prefixMappings.size());
- documentEnded = true;
- }
-
- public void startPrefixMapping(String prefix, String uri)
- throws SAXException {
- prefixMappings.put(prefix, uri);
- }
-
- public void endPrefixMapping(String prefix) throws SAXException {
- assertNotNull(prefixMappings.remove(prefix));
- }
-
- public void startElement(String uri, String localName, String qName,
- Attributes atts) throws SAXException {
-
- if (localName == "one") {
- assertEquals(2, prefixMappings.size());
-
- assertEquals(1, locator.getLineNumber());
-
- assertFalse(oneStarted);
- assertFalse(twoStarted);
- assertFalse(oneEnded);
- assertFalse(twoEnded);
-
- oneStarted = true;
-
- assertSame("ns:default", uri);
- assertEquals("one", qName);
-
- // Check atts.
- assertEquals(1, atts.getLength());
-
- assertSame("", atts.getURI(0));
- assertSame("a", atts.getLocalName(0));
- assertEquals("b", atts.getValue(0));
- assertEquals(0, atts.getIndex("", "a"));
- assertEquals("b", atts.getValue("", "a"));
-
- return;
- }
-
- if (localName == "two") {
- assertEquals(3, prefixMappings.size());
-
- assertTrue(oneStarted);
- assertFalse(twoStarted);
- assertFalse(oneEnded);
- assertFalse(twoEnded);
-
- twoStarted = true;
-
- assertSame("ns:1", uri);
- Assert.assertEquals("n1:two", qName);
-
- // Check atts.
- assertEquals(2, atts.getLength());
-
- assertSame("", atts.getURI(0));
- assertSame("c", atts.getLocalName(0));
- assertEquals("d", atts.getValue(0));
- assertEquals(0, atts.getIndex("", "c"));
- assertEquals("d", atts.getValue("", "c"));
-
- assertSame("ns:1", atts.getURI(1));
- assertSame("e", atts.getLocalName(1));
- assertEquals("f", atts.getValue(1));
- assertEquals(1, atts.getIndex("ns:1", "e"));
- assertEquals("f", atts.getValue("ns:1", "e"));
-
- // We shouldn't find these.
- assertEquals(-1, atts.getIndex("ns:default", "e"));
- assertEquals(null, atts.getValue("ns:default", "e"));
-
- return;
- }
-
- fail();
- }
-
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- if (localName == "one") {
- assertEquals(3, locator.getLineNumber());
-
- assertTrue(oneStarted);
- assertTrue(twoStarted);
- assertTrue(twoEnded);
- assertFalse(oneEnded);
-
- oneEnded = true;
-
- assertSame("ns:default", uri);
- assertEquals("one", qName);
-
- return;
- }
-
- if (localName == "two") {
- assertTrue(oneStarted);
- assertTrue(twoStarted);
- assertFalse(twoEnded);
- assertFalse(oneEnded);
-
- twoEnded = true;
-
- assertSame("ns:1", uri);
- assertEquals("n1:two", qName);
-
- return;
- }
-
- fail();
- }
-
- public void characters(char ch[], int start, int length)
- throws SAXException {
- String s = new String(ch, start, length).trim();
-
- if (!s.equals("")) {
- assertTrue(oneStarted);
- assertTrue(twoStarted);
- assertFalse(oneEnded);
- assertFalse(twoEnded);
- assertEquals("text", s);
- }
- }
-
- public void ignorableWhitespace(char ch[], int start, int length)
- throws SAXException {
- fail();
- }
-
- public void processingInstruction(String target, String data)
- throws SAXException {
- fail();
- }
-
- public void skippedEntity(String name) throws SAXException {
- fail();
- }
- }
-
- private TestDtdHandler runDtdTest(String s) throws Exception {
- Reader in = new StringReader(s);
- ExpatReader reader = new ExpatReader();
- TestDtdHandler handler = new TestDtdHandler();
- reader.setContentHandler(handler);
- reader.setDTDHandler(handler);
- reader.setLexicalHandler(handler);
- reader.parse(new InputSource(in));
- return handler;
- }
-
- public void testDtdDoctype() throws Exception {
- TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee'><a></a>");
- assertEquals("foo", handler.name);
- assertEquals("bar", handler.publicId);
- assertEquals("tee", handler.systemId);
- assertTrue(handler.ended);
- }
-
- public void testDtdUnparsedEntity_system() throws Exception {
- TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent SYSTEM 'blah' NDATA poop> ]><a></a>");
- assertEquals("ent", handler.ueName);
- assertEquals(null, handler.uePublicId);
- assertEquals("blah", handler.ueSystemId);
- assertEquals("poop", handler.ueNotationName);
- }
-
- public void testDtdUnparsedEntity_public() throws Exception {
- TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!ENTITY ent PUBLIC 'a' 'b' NDATA poop> ]><a></a>");
- assertEquals("ent", handler.ueName);
- assertEquals("a", handler.uePublicId);
- assertEquals("b", handler.ueSystemId);
- assertEquals("poop", handler.ueNotationName);
- }
-
- public void testDtdNotation_system() throws Exception {
- TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION sn SYSTEM 'nf2'> ]><a></a>");
- assertEquals("sn", handler.ndName);
- assertEquals(null, handler.ndPublicId);
- assertEquals("nf2", handler.ndSystemId);
- }
-
- public void testDtdNotation_public() throws Exception {
- TestDtdHandler handler = runDtdTest("<?xml version=\"1.0\"?><!DOCTYPE foo PUBLIC 'bar' 'tee' [ <!NOTATION pn PUBLIC 'nf1'> ]><a></a>");
- assertEquals("pn", handler.ndName);
- assertEquals("nf1", handler.ndPublicId);
- assertEquals(null, handler.ndSystemId);
- }
-
- static class TestDtdHandler extends DefaultHandler2 {
-
- String name;
- String publicId;
- String systemId;
- String ndName;
- String ndPublicId;
- String ndSystemId;
- String ueName;
- String uePublicId;
- String ueSystemId;
- String ueNotationName;
-
- boolean ended;
-
- Locator locator;
-
- @Override
- public void startDTD(String name, String publicId, String systemId) {
- this.name = name;
- this.publicId = publicId;
- this.systemId = systemId;
- }
-
- @Override
- public void endDTD() {
- ended = true;
- }
-
- @Override
- public void setDocumentLocator(Locator locator) {
- this.locator = locator;
- }
-
- @Override
- public void notationDecl(String name, String publicId, String systemId) {
- this.ndName = name;
- this.ndPublicId = publicId;
- this.ndSystemId = systemId;
- }
-
- @Override
- public void unparsedEntityDecl(String entityName, String publicId, String systemId, String notationName) {
- this.ueName = entityName;
- this.uePublicId = publicId;
- this.ueSystemId = systemId;
- this.ueNotationName = notationName;
- }
- }
-
- public void testCdata() throws Exception {
- Reader in = new StringReader(
- "<a><![CDATA[<b></b>]]> <![CDATA[<c></c>]]></a>");
-
- ExpatReader reader = new ExpatReader();
- TestCdataHandler handler = new TestCdataHandler();
- reader.setContentHandler(handler);
- reader.setLexicalHandler(handler);
-
- reader.parse(new InputSource(in));
-
- assertEquals(2, handler.startCdata);
- assertEquals(2, handler.endCdata);
- assertEquals("<b></b> <c></c>", handler.buffer.toString());
- }
-
- static class TestCdataHandler extends DefaultHandler2 {
-
- int startCdata, endCdata;
- StringBuffer buffer = new StringBuffer();
-
- @Override
- public void characters(char ch[], int start, int length) {
- buffer.append(ch, start, length);
- }
-
- @Override
- public void startCDATA() throws SAXException {
- startCdata++;
- }
-
- @Override
- public void endCDATA() throws SAXException {
- endCdata++;
- }
- }
-
- public void testProcessingInstructions() throws IOException, SAXException {
- Reader in = new StringReader(
- "<?bob lee?><a></a>");
-
- ExpatReader reader = new ExpatReader();
- TestProcessingInstrutionHandler handler
- = new TestProcessingInstrutionHandler();
- reader.setContentHandler(handler);
-
- reader.parse(new InputSource(in));
-
- assertEquals("bob", handler.target);
- assertEquals("lee", handler.data);
- }
-
- static class TestProcessingInstrutionHandler extends DefaultHandler2 {
-
- String target;
- String data;
-
- @Override
- public void processingInstruction(String target, String data) {
- this.target = target;
- this.data = data;
- }
- }
-
- public void testExternalEntity() throws IOException, SAXException {
- class Handler extends DefaultHandler {
-
- List<String> elementNames = new ArrayList<String>();
- StringBuilder text = new StringBuilder();
-
- public InputSource resolveEntity(String publicId, String systemId)
- throws IOException, SAXException {
- if (publicId.equals("publicA") && systemId.equals("systemA")) {
- return new InputSource(new StringReader("<a/>"));
- } else if (publicId.equals("publicB")
- && systemId.equals("systemB")) {
- /*
- * Explicitly set the encoding here or else the parser will
- * try to use the parent parser's encoding which is utf-16.
- */
- InputSource inputSource = new InputSource(
- new ByteArrayInputStream("bob".getBytes("utf-8")));
- inputSource.setEncoding("utf-8");
- return inputSource;
- }
-
- throw new AssertionError();
- }
-
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- elementNames.add(localName);
- }
-
- @Override
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- elementNames.add("/" + localName);
- }
-
- @Override
- public void characters(char ch[], int start, int length)
- throws SAXException {
- text.append(ch, start, length);
- }
- }
-
- Reader in = new StringReader("<?xml version=\"1.0\"?>\n"
- + "<!DOCTYPE foo [\n"
- + " <!ENTITY a PUBLIC 'publicA' 'systemA'>\n"
- + " <!ENTITY b PUBLIC 'publicB' 'systemB'>\n"
- + "]>\n"
- + "<foo>\n"
- + " &a;<b>&b;</b></foo>");
-
- ExpatReader reader = new ExpatReader();
- Handler handler = new Handler();
- reader.setContentHandler(handler);
- reader.setEntityResolver(handler);
-
- reader.parse(new InputSource(in));
-
- assertEquals(Arrays.asList("foo", "a", "/a", "b", "/b", "/foo"),
- handler.elementNames);
- assertEquals("bob", handler.text.toString().trim());
- }
-
- public void testExternalEntityDownload() throws IOException, SAXException {
- class Server implements Runnable {
-
- private final ServerSocket serverSocket;
-
- Server() throws IOException {
- serverSocket = new ServerSocket(8080);
- }
-
- public void run() {
- try {
- Socket socket = serverSocket.accept();
-
- final InputStream in = socket.getInputStream();
- Thread inputThread = new Thread() {
- public void run() {
- try {
- byte[] buffer = new byte[1024];
- while (in.read(buffer) > -1) { /* ignore */ }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
- inputThread.setDaemon(true);
- inputThread.start();
-
- OutputStream out = socket.getOutputStream();
-
- String body = "<bar></bar>";
- String response = "HTTP/1.0 200 OK\n"
- + "Content-Length: " + body.length() + "\n"
- + "\n"
- + body;
-
- out.write(response.getBytes("UTF-8"));
- out.close();
- serverSocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- class Handler extends DefaultHandler {
-
- List<String> elementNames = new ArrayList<String>();
-
- public InputSource resolveEntity(String publicId, String systemId)
- throws IOException, SAXException {
- // The parser should have resolved the systemId.
- assertEquals("http://localhost:8080/systemBar", systemId);
- return new InputSource(systemId);
- }
-
- @Override
- public void startElement(String uri, String localName, String qName,
- Attributes attributes) throws SAXException {
- elementNames.add(localName);
- }
-
- @Override
- public void endElement(String uri, String localName, String qName)
- throws SAXException {
- elementNames.add("/" + localName);
- }
- }
-
- // Start server to serve up the XML for 'systemBar'.
- Thread serverThread = new Thread(new Server());
- serverThread.setDaemon(true);
- serverThread.start();
-
- // 'systemBar', the external entity, is relative to 'systemFoo':
- Reader in = new StringReader("<?xml version=\"1.0\"?>\n"
- + "<!DOCTYPE foo [\n"
- + " <!ENTITY bar SYSTEM 'systemBar'>\n"
- + "]>\n"
- + "<foo>&bar;</foo>");
-
- ExpatReader reader = new ExpatReader();
-
- Handler handler = new Handler();
-
- reader.setContentHandler(handler);
- reader.setEntityResolver(handler);
-
- InputSource source = new InputSource(in);
- source.setSystemId("http://localhost:8080/systemFoo");
- reader.parse(source);
-
- assertEquals(Arrays.asList("foo", "bar", "/bar", "/foo"),
- handler.elementNames);
- }
-
- /**
- * Parses the given xml string and fires events on the given SAX handler.
- */
- private static void parse(String xml, ContentHandler contentHandler)
- throws SAXException {
- try {
- XMLReader reader = new ExpatReader();
- reader.setContentHandler(contentHandler);
- reader.parse(new InputSource(new StringReader(xml)));
- }
- catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-
- /**
- * Parses xml from the given reader and fires events on the given SAX
- * handler.
- */
- private static void parse(Reader in, ContentHandler contentHandler)
- throws IOException, SAXException {
- XMLReader reader = new ExpatReader();
- reader.setContentHandler(contentHandler);
- reader.parse(new InputSource(in));
- }
-
- /**
- * Parses xml from the given input stream and fires events on the given SAX
- * handler.
- */
- private static void parse(InputStream in, Encoding encoding,
- ContentHandler contentHandler) throws IOException, SAXException {
- try {
- XMLReader reader = new ExpatReader();
- reader.setContentHandler(contentHandler);
- InputSource source = new InputSource(in);
- source.setEncoding(encoding.expatName);
- reader.parse(source);
- } catch (IOException e) {
- throw new AssertionError(e);
- }
- }
-
- /**
- * Supported character encodings.
- */
- private enum Encoding {
-
- US_ASCII("US-ASCII"),
- UTF_8("UTF-8"),
- UTF_16("UTF-16"),
- ISO_8859_1("ISO-8859-1");
-
- final String expatName;
-
- Encoding(String expatName) {
- this.expatName = expatName;
- }
- }
-
- /**
- * Creates a new pull parser with namespace support.
- */
- private static XmlPullParser newPullParser() {
- ExpatPullParser parser = new ExpatPullParser();
- parser.setNamespaceProcessingEnabled(true);
- return parser;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/xml/JaxenXPathTestSuite.java b/luni/src/test/java/org/apache/harmony/xml/JaxenXPathTestSuite.java
deleted file mode 100644
index 17f0341..0000000
--- a/luni/src/test/java/org/apache/harmony/xml/JaxenXPathTestSuite.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.namespace.QName;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-import javax.xml.xpath.XPathVariableResolver;
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The implementation-independent part of the <a
- * href="http://jaxen.codehaus.org/">Jaxen</a> XPath test suite, adapted for use
- * by JUnit. To run these tests on a device:
- * <ul>
- * <li>Obtain the Jaxen source from the project's website.
- * <li>Copy the files to a device: <code>adb shell mkdir /data/jaxen ;
- * adb push /home/dalvik-prebuild/jaxen /data/jaxen</code>
- * <li>Invoke this class' main method, passing the on-device path to the test
- * suite's root directory as an argument.
- * </ul>
- */
-public class JaxenXPathTestSuite {
-
- private static final String DEFAULT_JAXEN_HOME = "/home/dalvik-prebuild/jaxen";
-
- public static Test suite() throws Exception {
- String jaxenHome = System.getProperty("jaxen.home", DEFAULT_JAXEN_HOME);
- return suite(new File(jaxenHome));
- }
-
- /**
- * Creates a test suite from the Jaxen tests.xml catalog.
- */
- public static Test suite(File jaxenHome)
- throws ParserConfigurationException, IOException, SAXException {
-
- /*
- * The tests.xml document has this structure:
- *
- * <tests>
- * <document url="...">
- * <context .../>
- * <context .../>
- * <context .../>
- * </document>
- * <document url="...">
- * <context .../>
- * </document>
- * </tests>
- */
-
- File testsXml = new File(jaxenHome + "/xml/test/tests.xml");
- Element tests = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder().parse(testsXml).getDocumentElement();
-
- TestSuite result = new TestSuite();
- for (Element document : elementsOf(tests.getElementsByTagName("document"))) {
- String url = document.getAttribute("url");
- InputSource inputSource = new InputSource("file:" + jaxenHome + "/" + url);
- for (final Element context : elementsOf(document.getElementsByTagName("context"))) {
- contextToTestSuite(result, url, inputSource, context);
- }
- }
-
- return result;
- }
-
- /**
- * Populates the test suite with tests from the given XML context element.
- */
- private static void contextToTestSuite(TestSuite suite, String url,
- InputSource inputSource, Element element) {
-
- /*
- * Each context element has this structure:
- *
- * <context select="...">
- * <test .../>
- * <test .../>
- * <test .../>
- * <valueOf .../>
- * <valueOf .../>
- * <valueOf .../>
- * </context>
- */
-
- String select = element.getAttribute("select");
- Context context = new Context(inputSource, url, select);
-
- XPath xpath = XPathFactory.newInstance().newXPath();
- xpath.setXPathVariableResolver(new ElementVariableResolver(element));
-
- for (Element test : elementsOf(element.getChildNodes())) {
- if (test.getTagName().equals("test")) {
- suite.addTest(createFromTest(xpath, context, test));
-
- } else if (test.getTagName().equals("valueOf")) {
- suite.addTest(createFromValueOf(xpath, context, test));
-
- } else {
- throw new UnsupportedOperationException("Unsupported test: " + context);
- }
- }
- }
-
- /**
- * Returns the test described by the given {@code <test>} element. Such
- * tests come in one of three varieties:
- *
- * <ul>
- * <li>Expected failures.
- * <li>String matches. These tests have a nested {@code <valueOf>} element
- * that sub-selects an expected text.
- * <li>Count matches. These tests specify how many nodes are expected to
- * match.
- * </ul>
- */
- private static TestCase createFromTest(
- final XPath xpath, final Context context, final Element element) {
- final String select = element.getAttribute("select");
-
- /* Such as <test exception="true" select="..." count="0"/> */
- if (element.getAttribute("exception").equals("true")) {
- return new XPathTest(context, select) {
- @Override void test(Node contextNode) {
- try {
- xpath.evaluate(select, contextNode);
- fail("Expected exception!");
- } catch (XPathExpressionException expected) {
- }
- }
- };
- }
-
- /* a <test> with a nested <valueOf>, both of which have select attributes */
- NodeList valueOfElements = element.getElementsByTagName("valueOf");
- if (valueOfElements.getLength() == 1) {
- final Element valueOf = (Element) valueOfElements.item(0);
- final String valueOfSelect = valueOf.getAttribute("select");
-
- return new XPathTest(context, select) {
- @Override void test(Node contextNode) throws XPathExpressionException {
- Node newContext = (Node) xpath.evaluate(
- select, contextNode, XPathConstants.NODE);
- assertEquals(valueOf.getTextContent(),
- xpath.evaluate(valueOfSelect, newContext, XPathConstants.STRING));
- }
- };
- }
-
- /* Such as <test select="..." count="5"/> */
- final String count = element.getAttribute("count");
- if (count.length() > 0) {
- return new XPathTest(context, select) {
- @Override void test(Node contextNode) throws XPathExpressionException {
- NodeList result = (NodeList) xpath.evaluate(
- select, contextNode, XPathConstants.NODESET);
- assertEquals(Integer.parseInt(count), result.getLength());
- }
- };
- }
-
- throw new UnsupportedOperationException("Unsupported test: " + context);
- }
-
- /**
- * Returns the test described by the given {@code <valueOf>} element. These
- * tests select an expected text.
- */
- private static TestCase createFromValueOf(
- final XPath xpath, final Context context, final Element element) {
- final String select = element.getAttribute("select");
- return new XPathTest(context, select) {
- @Override void test(Node contextNode) throws XPathExpressionException {
- assertEquals(element.getTextContent(),
- xpath.evaluate(select, contextNode, XPathConstants.STRING));
- }
- };
- }
-
- /**
- * The subject of an XPath query. This is itself defined by an XPath query,
- * so each test requires at least XPath expressions to be evaluated.
- */
- static class Context {
- private final InputSource inputSource;
- private final String url;
- private final String select;
-
- Context(InputSource inputSource, String url, String select) {
- this.inputSource = inputSource;
- this.url = url;
- this.select = select;
- }
-
- Node getNode() {
- XPath xpath = XPathFactory.newInstance().newXPath();
- try {
- return (Node) xpath.evaluate(select, inputSource, XPathConstants.NODE);
- } catch (XPathExpressionException e) {
- Error error = new AssertionFailedError("Failed to get context");
- error.initCause(e);
- throw error;
- }
- }
-
- @Override public String toString() {
- return url + " " + select;
- }
- }
-
- /**
- * This test evaluates an XPath expression against a context node and
- * compares the result to a known expectation.
- */
- public abstract static class XPathTest extends TestCase {
- private final Context context;
- private final String select;
-
- public XPathTest(Context context, String select) {
- super("test");
- this.context = context;
- this.select = select;
- }
-
- abstract void test(Node contextNode) throws XPathExpressionException;
-
- public final void test() throws XPathExpressionException {
- try {
- test(context.getNode());
- } catch (XPathExpressionException e) {
- if (isMissingFunction(e)) {
- fail(e.getCause().getMessage());
- } else {
- throw e;
- }
- }
- }
-
- private boolean isMissingFunction(XPathExpressionException e) {
- return e.getCause() != null
- && e.getCause().getMessage().startsWith("Could not find function");
- }
-
- @Override public String getName() {
- return context + " " + select;
- }
- }
-
- /**
- * Performs XPath variable resolution by using {@code var:name="value"}
- * attributes from the given element.
- */
- private static class ElementVariableResolver implements XPathVariableResolver {
- private final Element element;
- public ElementVariableResolver(Element element) {
- this.element = element;
- }
- public Object resolveVariable(QName variableName) {
- return element.getAttribute("var:" + variableName.getLocalPart());
- }
- }
-
- private static List<Element> elementsOf(NodeList nodeList) {
- List<Element> result = new ArrayList<Element>();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element) {
- result.add((Element) node);
- }
- }
- return result;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/xml/NamespacedAttributesLookupTest.java b/luni/src/test/java/org/apache/harmony/xml/NamespacedAttributesLookupTest.java
deleted file mode 100644
index 4f58262..0000000
--- a/luni/src/test/java/org/apache/harmony/xml/NamespacedAttributesLookupTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml;
-
-import junit.framework.TestCase;
-import org.xml.sax.Attributes;
-import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.DefaultHandler;
-
-import javax.xml.parsers.SAXParserFactory;
-import java.io.StringReader;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Tests that we both report and retrieve attributes using the appropriate
- * names for different combinations of namespaces and namespace prefixes.
- */
-public class NamespacedAttributesLookupTest extends TestCase {
-
- private static final String SAX_PROPERTY_NS =
- "http://xml.org/sax/features/namespaces";
- private static final String SAX_PROPERTY_NS_PREFIXES =
- "http://xml.org/sax/features/namespace-prefixes";
-
- private static String xml = "<?xml version='1.0' encoding='UTF-8'?>" +
- "<test xmlns='http://foo' xmlns:bar='http://bar' xmlns:baz='http://baz' baz:c='a'>" +
- "<b c='w' bar:c='x'/>" +
- "<bar:e baz:c='y' bar:c='z'/>" +
- "</test>";
-
- public void testNamespace() throws Exception {
- List<String> expected = Arrays.asList(
- "http://foo,test\n" +
- " http://baz,c\n" +
- " http://bar+c=null,\n" +
- " bar:c=null\n",
-
- "http://foo,b\n" +
- " ,c\n" +
- " http://bar,c\n" +
- " http://bar+c=x,\n" +
- " bar:c=x\n",
-
- "http://bar,e\n" +
- " http://baz,c\n" +
- " http://bar,c\n" +
- " http://bar+c=z,\n" +
- " bar:c=z\n");
-
- boolean namespace = true;
- boolean namespacePrefixes = false;
- assertEquals(expected, getStartElements(xml, namespace, namespacePrefixes));
- }
-
- public void testNamespacePrefixes() throws Exception {
- List<String> expected = Arrays.asList(
- "test\n" +
- " xmlns\n" +
- " xmlns:bar\n" +
- " xmlns:baz\n" +
- " baz:c\n" +
- " http://bar+c=null,\n" +
- " bar:c=null\n",
-
- "b\n" +
- " c\n" +
- " bar:c\n" +
- " http://bar+c=null,\n" +
- " bar:c=x\n",
-
- "bar:e\n" +
- " baz:c\n" +
- " bar:c\n" +
- " http://bar+c=null,\n" +
- " bar:c=z\n");
-
- boolean namespace = false;
- boolean namespacePrefixes = true;
- assertEquals(expected, getStartElements(xml, namespace, namespacePrefixes));
- }
-
- public List<String> getStartElements(String xml, final boolean namespace, boolean namespacePrefixes)
- throws Exception {
- final List<String> result = new ArrayList<String>();
- XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();
- reader.setFeature(SAX_PROPERTY_NS, namespace);
- reader.setFeature(SAX_PROPERTY_NS_PREFIXES, namespacePrefixes);
- reader.setContentHandler(new DefaultHandler() {
- @Override public final void startElement(
- String uri, String localName, String qName, Attributes attributes) {
- StringBuilder serialized = new StringBuilder();
- /*
- * Only supply the uri+localName or qname depending on whether namespaces are
- * enabled. It's an optional parameter and the RI only supplies one or the other.
- */
- if (namespace) {
- serialized.append(uri).append(",");
- serialized.append(localName);
- } else {
- serialized.append(qName);
- }
- for (int i = 0; i < attributes.getLength(); i++) {
- serialized.append("\n ");
- if (namespace) {
- serialized.append(attributes.getURI(i)).append(",");
- serialized.append(attributes.getLocalName(i));
- } else {
- serialized.append(attributes.getQName(i));
- }
- }
- serialized.append("\n http://bar+c=")
- .append(attributes.getValue("http://bar", "c")).append(",")
- .append("\n bar:c=")
- .append(attributes.getValue("bar:c"))
- .append("\n");
- result.add(serialized.toString());
- }
- });
- reader.parse(new InputSource(new StringReader(xml)));
- return result;
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/xml/XsltXPathConformanceTestSuite.java b/luni/src/test/java/org/apache/harmony/xml/XsltXPathConformanceTestSuite.java
deleted file mode 100644
index 8623d58..0000000
--- a/luni/src/test/java/org/apache/harmony/xml/XsltXPathConformanceTestSuite.java
+++ /dev/null
@@ -1,635 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.xml;
-
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.EntityReference;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.ProcessingInstruction;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-import org.xmlpull.v1.XmlPullParserException;
-import org.xmlpull.v1.XmlPullParserFactory;
-import org.xmlpull.v1.XmlSerializer;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.ErrorListener;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMResult;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-/**
- * The <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=xslt">OASIS
- * XSLT conformance test suite</a>, adapted for use by JUnit. To run these tests
- * on a device:
- * <ul>
- * <li>Obtain the <a href="http://www.oasis-open.org/committees/download.php/12171/XSLT-testsuite-04.ZIP">test
- * suite zip file from the OASIS project site.</li>
- * <li>Unzip.
- * <li>Copy the files to a device: <code>adb shell mkdir /data/oasis ;
- * adb push ./XSLT-Conformance-TC /data/oasis</code>.
- * <li>Invoke this class' main method, passing the on-device path to the test
- * suite's <code>catalog.xml</code> file as an argument.
- * </ul>
- *
- * <p>Unfortunately, some of the tests in the OASIS suite will fail when
- * executed outside of their original development environment:
- * <ul>
- * <li>The tests assume case insensitive filesystems. Some will fail with
- * "Couldn't open file" errors due to a mismatch in file name casing.
- * <li>The tests assume certain network hosts will exist and serve
- * stylesheet files. In particular, "http://webxtest/" isn't generally
- * available.
- * </ul>
- */
-public class XsltXPathConformanceTestSuite {
-
- private static final String defaultCatalogFile
- = "/home/dalvik-prebuild/OASIS/XSLT-Conformance-TC/TESTS/catalog.xml";
-
- /** Orders element attributes by optional URI and name. */
- private static final Comparator<Attr> orderByName = new Comparator<Attr>() {
- public int compare(Attr a, Attr b) {
- int result = compareNullsFirst(a.getNamespaceURI(), b.getNamespaceURI());
- return result == 0 ? result
- : compareNullsFirst(a.getName(), b.getName());
- }
-
- <T extends Comparable<T>> int compareNullsFirst(T a, T b) {
- return (a == b) ? 0
- : (a == null) ? -1
- : (b == null) ? 1
- : a.compareTo(b);
- }
- };
-
- private final DocumentBuilder documentBuilder;
- private final TransformerFactory transformerFactory;
- private final XmlPullParserFactory xmlPullParserFactory;
-
- public XsltXPathConformanceTestSuite()
- throws ParserConfigurationException, XmlPullParserException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setNamespaceAware(true);
- factory.setCoalescing(true);
- documentBuilder = factory.newDocumentBuilder();
-
- transformerFactory = TransformerFactory.newInstance();
- xmlPullParserFactory = XmlPullParserFactory.newInstance();
- }
-
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.out.println("Usage: XsltXPathConformanceTestSuite <catalog-xml>");
- System.out.println();
- System.out.println(" catalog-xml: an XML file describing an OASIS test suite");
- System.out.println(" such as: " + defaultCatalogFile);
- return;
- }
-
- File catalogXml = new File(args[0]);
- // TestRunner.run(suite(catalogXml)); android-changed
- }
-
- public static Test suite() throws Exception {
- return suite(new File(defaultCatalogFile));
- }
-
- /**
- * Returns a JUnit test suite for the tests described by the given document.
- */
- public static Test suite(File catalogXml) throws Exception {
- XsltXPathConformanceTestSuite suite = new XsltXPathConformanceTestSuite();
-
- /*
- * Extract the tests from an XML document with the following structure:
- *
- * <test-suite>
- * <test-catalog submitter="Lotus">
- * <creator>Lotus/IBM</creator>
- * <major-path>Xalan_Conformance_Tests</major-path>
- * <date>2001-11-16</date>
- * <test-case ...> ... </test-case>
- * <test-case ...> ... </test-case>
- * <test-case ...> ... </test-case>
- * </test-catalog>
- * </test-suite>
- */
-
- Document document = DocumentBuilderFactory.newInstance()
- .newDocumentBuilder().parse(catalogXml);
- Element testSuiteElement = document.getDocumentElement();
- TestSuite result = new TestSuite();
- for (Element testCatalog : elementsOf(testSuiteElement.getElementsByTagName("test-catalog"))) {
- Element majorPathElement = (Element) testCatalog.getElementsByTagName("major-path").item(0);
- String majorPath = majorPathElement.getTextContent();
- File base = new File(catalogXml.getParentFile(), majorPath);
-
- for (Element testCaseElement : elementsOf(testCatalog.getElementsByTagName("test-case"))) {
- result.addTest(suite.create(base, testCaseElement));
- }
- }
-
- return result;
- }
-
- /**
- * Returns a JUnit test for the test described by the given element.
- */
- private TestCase create(File base, Element testCaseElement) {
-
- /*
- * Extract the XSLT test from a DOM entity with the following structure:
- *
- * <test-case category="XSLT-Result-Tree" id="attribset_attribset01">
- * <file-path>attribset</file-path>
- * <creator>Paul Dick</creator>
- * <date>2001-11-08</date>
- * <purpose>Set attribute of a LRE from single attribute set.</purpose>
- * <spec-citation place="7.1.4" type="section" version="1.0" spec="xslt"/>
- * <scenario operation="standard">
- * <input-file role="principal-data">attribset01.xml</input-file>
- * <input-file role="principal-stylesheet">attribset01.xsl</input-file>
- * <output-file role="principal" compare="XML">attribset01.out</output-file>
- * </scenario>
- * </test-case>
- */
-
- Element filePathElement = (Element) testCaseElement.getElementsByTagName("file-path").item(0);
- Element purposeElement = (Element) testCaseElement.getElementsByTagName("purpose").item(0);
- Element specCitationElement = (Element) testCaseElement.getElementsByTagName("spec-citation").item(0);
- Element scenarioElement = (Element) testCaseElement.getElementsByTagName("scenario").item(0);
-
- String category = testCaseElement.getAttribute("category");
- String id = testCaseElement.getAttribute("id");
- String name = category + "." + id;
- String purpose = purposeElement != null ? purposeElement.getTextContent() : "";
- String spec = "place=" + specCitationElement.getAttribute("place")
- + " type" + specCitationElement.getAttribute("type")
- + " version=" + specCitationElement.getAttribute("version")
- + " spec=" + specCitationElement.getAttribute("spec");
- String operation = scenarioElement.getAttribute("operation");
-
- Element principalDataElement = null;
- Element principalStylesheetElement = null;
- Element principalElement = null;
-
- for (Element element : elementsOf(scenarioElement.getChildNodes())) {
- String role = element.getAttribute("role");
- if (role.equals("principal-data")) {
- principalDataElement = element;
- } else if (role.equals("principal-stylesheet")) {
- principalStylesheetElement = element;
- } else if (role.equals("principal")) {
- principalElement = element;
- } else if (!role.equals("supplemental-stylesheet")
- && !role.equals("supplemental-data")) {
- return new MisspecifiedTest("Unexpected element at " + name);
- }
- }
-
- String testDirectory = filePathElement.getTextContent();
- File inBase = new File(base, testDirectory);
- File outBase = new File(new File(base, "REF_OUT"), testDirectory);
-
- if (principalDataElement == null || principalStylesheetElement == null) {
- return new MisspecifiedTest("Expected <scenario> to have "
- + "principal=data and principal-stylesheet elements at " + name);
- }
-
- try {
- File principalData = findFile(inBase, principalDataElement.getTextContent());
- File principalStylesheet = findFile(inBase, principalStylesheetElement.getTextContent());
-
- final File principal;
- final String compareAs;
- if (!operation.equals("execution-error")) {
- if (principalElement == null) {
- return new MisspecifiedTest("Expected <scenario> to have principal element at " + name);
- }
-
- principal = findFile(outBase, principalElement.getTextContent());
- compareAs = principalElement.getAttribute("compare");
- } else {
- principal = null;
- compareAs = null;
- }
-
- return new XsltTest(category, id, purpose, spec, principalData,
- principalStylesheet, principal, operation, compareAs);
- } catch (FileNotFoundException e) {
- return new MisspecifiedTest(e.getMessage() + " at " + name);
- }
- }
-
- /**
- * Finds the named file in the named directory. This tries extra hard to
- * avoid case-insensitive-naming problems, where the requested file is
- * available in a different casing.
- */
- private File findFile(File directory, String name) throws FileNotFoundException {
- File file = new File(directory, name);
- if (file.exists()) {
- return file;
- }
-
- for (String child : directory.list()) {
- if (child.equalsIgnoreCase(name)) {
- return new File(directory, child);
- }
- }
-
- throw new FileNotFoundException("Missing file: " + file);
- }
-
- /**
- * Placeholder for a test that couldn't be configured to run properly.
- */
- public class MisspecifiedTest extends TestCase {
- private final String message;
-
- MisspecifiedTest(String message) {
- super("test");
- this.message = message;
- }
-
- public void test() {
- fail(message);
- }
- }
-
- /**
- * Processes an input XML file with an input XSLT stylesheet and compares
- * the result to an expected output file.
- */
- public class XsltTest extends TestCase {
- private final String category;
- private final String id;
- private final String purpose;
- private final String spec;
-
- private final File principalData;
- private final File principalStylesheet;
- private final File principal;
-
- /** either "standard" or "execution-error" */
- private final String operation;
-
- /**
- * The syntax to compare the output file using, such as "XML", "HTML",
- * "manual", or null for expected execution errors.
- */
- private final String compareAs;
-
- XsltTest(String category, String id, String purpose, String spec,
- File principalData, File principalStylesheet, File principal,
- String operation, String compareAs) {
- super("test");
- this.category = category;
- this.id = id;
- this.purpose = purpose;
- this.spec = spec;
- this.principalData = principalData;
- this.principalStylesheet = principalStylesheet;
- this.principal = principal;
- this.operation = operation;
- this.compareAs = compareAs;
- }
-
- XsltTest(File principalData, File principalStylesheet, File principal) {
- this("standalone", "test", "", "",
- principalData, principalStylesheet, principal, "standard", "XML");
- }
-
- public void test() throws Exception {
- if (purpose != null) {
- System.out.println("Purpose: " + purpose);
- }
- if (spec != null) {
- System.out.println("Spec: " + spec);
- }
-
- Result result;
- if ("XML".equals(compareAs)) {
- DOMResult domResult = new DOMResult();
- domResult.setNode(documentBuilder.newDocument().createElementNS("", "result"));
- result = domResult;
- } else {
- result = new StreamResult(new StringWriter());
- }
-
- ErrorRecorder errorRecorder = new ErrorRecorder();
- transformerFactory.setErrorListener(errorRecorder);
-
- Transformer transformer;
- try {
- Source xslt = new StreamSource(principalStylesheet);
- transformer = transformerFactory.newTransformer(xslt);
- if (errorRecorder.error == null) {
- transformer.setErrorListener(errorRecorder);
- transformer.transform(new StreamSource(principalData), result);
- }
- } catch (TransformerConfigurationException e) {
- errorRecorder.fatalError(e);
- }
-
- if (operation.equals("standard")) {
- if (errorRecorder.error != null) {
- throw errorRecorder.error;
- }
- } else if (operation.equals("execution-error")) {
- if (errorRecorder.error != null) {
- return;
- }
- fail("Expected " + operation + ", but transform completed normally."
- + " (Warning=" + errorRecorder.warning + ")");
- } else {
- throw new UnsupportedOperationException("Unexpected operation: " + operation);
- }
-
- if ("XML".equals(compareAs)) {
- assertNodesAreEquivalent(principal, ((DOMResult) result).getNode());
- } else {
- // TODO: implement support for comparing HTML etc.
- throw new UnsupportedOperationException("Cannot compare as " + compareAs);
- }
- }
-
- @Override public String getName() {
- return category + "." + id;
- }
- }
-
- /**
- * Ensures both XML documents represent the same semantic data. Non-semantic
- * data such as namespace prefixes, comments, and whitespace is ignored.
- *
- * @param actual an XML document whose root is a {@code <result>} element.
- * @param expected a file containing an XML document fragment.
- */
- private void assertNodesAreEquivalent(File expected, Node actual)
- throws ParserConfigurationException, IOException, SAXException,
- XmlPullParserException {
-
- Node expectedNode = fileToResultNode(expected);
- String expectedString = nodeToNormalizedString(expectedNode);
- String actualString = nodeToNormalizedString(actual);
-
- Assert.assertEquals("Expected XML to match file " + expected,
- expectedString, actualString);
- }
-
- /**
- * Returns the given file's XML fragment as a single node, wrapped in
- * {@code <result>} tags. This takes care of normalizing the following
- * conditions:
- *
- * <ul>
- * <li>Files containing XML document fragments with multiple elements:
- * {@code <SPAN style="color=blue">Smurfs!</SPAN><br />}
- *
- * <li>Files containing XML document fragments with no elements:
- * {@code Smurfs!}
- *
- * <li>Files containing proper XML documents with a single element and an
- * XML declaration:
- * {@code <?xml version="1.0"?><doc />}
- *
- * <li>Files prefixed with a byte order mark header, such as 0xEFBBBF.
- * </ul>
- */
- private Node fileToResultNode(File file) throws IOException, SAXException {
- String rawContents = fileToString(file);
- String fragment = rawContents;
-
- // If the file had an XML declaration, strip that. Otherwise wrapping
- // it in <result> tags would result in a malformed XML document.
- if (fragment.startsWith("<?xml")) {
- int declarationEnd = fragment.indexOf("?>");
- fragment = fragment.substring(declarationEnd + 2);
- }
-
- // Parse it as document fragment wrapped in <result> tags.
- try {
- fragment = "<result>" + fragment + "</result>";
- return documentBuilder.parse(new InputSource(new StringReader(fragment)))
- .getDocumentElement();
- } catch (SAXParseException e) {
- Error error = new AssertionFailedError(
- "Failed to parse XML: " + file + "\n" + rawContents);
- error.initCause(e);
- throw error;
- }
- }
-
- private String nodeToNormalizedString(Node node)
- throws XmlPullParserException, IOException {
- StringWriter writer = new StringWriter();
- XmlSerializer xmlSerializer = xmlPullParserFactory.newSerializer();
- xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
- xmlSerializer.setOutput(writer);
- emitNode(xmlSerializer, node);
- xmlSerializer.flush();
- return writer.toString();
- }
-
- private void emitNode(XmlSerializer serializer, Node node) throws IOException {
- if (node == null) {
- throw new UnsupportedOperationException("Cannot emit null nodes");
-
- } else if (node.getNodeType() == Node.ELEMENT_NODE) {
- Element element = (Element) node;
- serializer.startTag(element.getNamespaceURI(), element.getLocalName());
- emitAttributes(serializer, element);
- emitChildren(serializer, element);
- serializer.endTag(element.getNamespaceURI(), element.getLocalName());
-
- } else if (node.getNodeType() == Node.TEXT_NODE
- || node.getNodeType() == Node.CDATA_SECTION_NODE) {
- // TODO: is it okay to trim whitespace in general? This may cause
- // false positives for elements like HTML's <pre> tag
- String trimmed = node.getTextContent().trim();
- if (trimmed.length() > 0) {
- serializer.text(trimmed);
- }
-
- } else if (node.getNodeType() == Node.DOCUMENT_NODE) {
- Document document = (Document) node;
- serializer.startDocument("UTF-8", true);
- emitNode(serializer, document.getDocumentElement());
- serializer.endDocument();
-
- } else if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
- ProcessingInstruction processingInstruction = (ProcessingInstruction) node;
- String data = processingInstruction.getData();
- String target = processingInstruction.getTarget();
- serializer.processingInstruction(target + " " + data);
-
- } else if (node.getNodeType() == Node.COMMENT_NODE) {
- // ignore!
-
- } else if (node.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
- EntityReference entityReference = (EntityReference) node;
- serializer.entityRef(entityReference.getNodeName());
-
- } else {
- throw new UnsupportedOperationException(
- "Cannot emit " + node + " of type " + node.getNodeType());
- }
- }
-
- private void emitAttributes(XmlSerializer serializer, Node node)
- throws IOException {
- NamedNodeMap map = node.getAttributes();
- if (map == null) {
- return;
- }
-
- List<Attr> attributes = new ArrayList<Attr>();
- for (int i = 0; i < map.getLength(); i++) {
- attributes.add((Attr) map.item(i));
- }
- Collections.sort(attributes, orderByName);
-
- for (Attr attr : attributes) {
- if ("xmlns".equals(attr.getPrefix()) || "xmlns".equals(attr.getLocalName())) {
- /*
- * Omit namespace declarations because they aren't considered
- * data. Ie. <foo:a xmlns:bar="http://google.com"> is semantically
- * equal to <bar:a xmlns:bar="http://google.com"> since the
- * prefix doesn't matter, only the URI it points to.
- *
- * When we omit the prefix, our XML serializer will still
- * generate one for us, using a predictable pattern.
- */
- } else {
- serializer.attribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getValue());
- }
- }
- }
-
- private void emitChildren(XmlSerializer serializer, Node node)
- throws IOException {
- NodeList childNodes = node.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- emitNode(serializer, childNodes.item(i));
- }
- }
-
- private static List<Element> elementsOf(NodeList nodeList) {
- List<Element> result = new ArrayList<Element>();
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node node = nodeList.item(i);
- if (node instanceof Element) {
- result.add((Element) node);
- }
- }
- return result;
- }
-
- /**
- * Reads the given file into a string. If the file contains a byte order
- * mark, the corresponding character set will be used. Otherwise the system
- * default charset will be used.
- */
- private String fileToString(File file) throws IOException {
- InputStream in = new BufferedInputStream(new FileInputStream(file), 1024);
-
- // Read the byte order mark to determine the charset.
- // TODO: use a built-in API for this...
- Reader reader;
- in.mark(3);
- int byte1 = in.read();
- int byte2 = in.read();
- if (byte1 == 0xFF && byte2 == 0xFE) {
- reader = new InputStreamReader(in, "UTF-16LE");
- } else if (byte1 == 0xFF && byte2 == 0xFF) {
- reader = new InputStreamReader(in, "UTF-16BE");
- } else {
- int byte3 = in.read();
- if (byte1 == 0xEF && byte2 == 0xBB && byte3 == 0xBF) {
- reader = new InputStreamReader(in, "UTF-8");
- } else {
- in.reset();
- reader = new InputStreamReader(in);
- }
- }
-
- StringWriter out = new StringWriter();
- char[] buffer = new char[1024];
- int count;
- while ((count = reader.read(buffer)) != -1) {
- out.write(buffer, 0, count);
- }
- return out.toString();
- }
-
- static class ErrorRecorder implements ErrorListener {
- Exception warning;
- Exception error;
-
- public void warning(TransformerException exception) {
- if (this.warning == null) {
- this.warning = exception;
- }
- }
-
- public void error(TransformerException exception) {
- if (this.error == null) {
- this.error = exception;
- }
- }
-
- public void fatalError(TransformerException exception) {
- if (this.error == null) {
- this.error = exception;
- }
- }
- }
-}
diff --git a/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java b/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
new file mode 100644
index 0000000..7adecaf
--- /dev/null
+++ b/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.xnet.provider.jsse;
+
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.crypto.Cipher;
+import javax.crypto.Mac;
+import junit.framework.TestCase;
+import libcore.java.security.StandardNames;
+import org.apache.harmony.xnet.provider.jsse.CipherSuite;
+
+public class CipherSuiteTest extends TestCase {
+ public void test_getByName() throws Exception {
+ for (String name : StandardNames.CIPHER_SUITES) {
+ if (name.equals(StandardNames.CIPHER_SUITE_SECURE_RENEGOTIATION)) {
+ assertNull(CipherSuite.getByName(name));
+ } else {
+ test_CipherSuite(name);
+ }
+ }
+
+ assertNull(CipherSuite.getByName("bogus"));
+ try {
+ CipherSuite.getByName(null);
+ fail();
+ } catch (NullPointerException expected) {
+ }
+ }
+
+ private void test_CipherSuite(String name) throws Exception {
+ CipherSuite cs = CipherSuite.getByName(name);
+ assertNotNull(name, cs);
+ assertEquals(name, cs.getName());
+ test_CipherSuite(cs);
+ }
+
+ private void test_CipherSuite(CipherSuite cs) throws Exception {
+ assertNotNull(cs);
+
+ String name = cs.getName();
+ assertNotNull(name);
+ assertSame(name, cs, CipherSuite.getByName(name));
+ assertTrue(name, StandardNames.CIPHER_SUITES.contains(name));
+ assertTrue(name, name.startsWith("SSL_") || name.startsWith("TLS_"));
+
+ assertEquals(cs.isAnonymous(), name.contains("_anon_"));
+
+ byte[] bytes = cs.toBytes();
+ assertNotNull(name, bytes);
+ assertEquals(name, 2, bytes.length);
+ assertTrue(name + bytes[0], bytes[0] == (byte) 0x00 || bytes[0] == (byte) 0xc0);
+ assertSame(name, cs, CipherSuite.getByCode(bytes[0], bytes[1]));
+ assertSame(name, cs, CipherSuite.getByCode((byte) 0, bytes[0], bytes[1]));
+
+ assertTrue(name, cs.toString().contains(name));
+
+ String bulkEncryptionAlgorithm = cs.getBulkEncryptionAlgorithm();
+ int blockSize = cs.getBlockSize();
+ if (bulkEncryptionAlgorithm == null) {
+ assertTrue(name, name.contains("_NULL_"));
+ assertEquals(name, 0, blockSize);
+ } else {
+ assertNotNull(name, Cipher.getInstance(cs.getBulkEncryptionAlgorithm()));
+ assertTrue(name, blockSize == 0 || blockSize == 8 || blockSize == 16);
+ }
+
+ String hmacName = cs.getHmacName();
+ assertNotNull(name, hmacName);
+ assertNotNull(name, Mac.getInstance(hmacName));
+
+ String hashName = cs.getHashName();
+ assertNotNull(name, hashName);
+ assertNotNull(name, MessageDigest.getInstance(hashName));
+
+ int macLength = cs.getMACLength();
+ assertTrue(name, macLength == 0 || macLength == 16 || macLength == 20);
+
+ assertTrue(name,
+ cs.isExportable() == name.contains("_EXPORT_")
+ || cs.isExportable() == name.contains("_NULL_"));
+
+ String keyType = cs.getServerKeyType();
+ assertEquals(name, cs.isAnonymous(), keyType == null);
+ assertTrue(name, keyType == null || StandardNames.KEY_TYPES.contains(keyType));
+ }
+
+ public void test_getByCode() {
+ // CipherSuite.getByCode is also covered by test_CipherSuite
+ assertUnknown(CipherSuite.getByCode((byte) 0x12, (byte) 0x34));
+ assertUnknown(CipherSuite.getByCode((byte) 0x12, (byte) 0x34, (byte) 0x56));
+ assertUnknown(CipherSuite.getByCode((byte) -1, (byte) -1));
+ assertUnknown(CipherSuite.getByCode((byte) -1, (byte) -1, (byte) -1));
+ }
+ private void assertUnknown(CipherSuite cs) {
+ assertNotNull(cs);
+ assertNotNull(cs.getName().contains("UNKNOWN"));
+ }
+
+ public void test_getSupported() throws Exception {
+ CipherSuite[] suites = CipherSuite.getSupported();
+ List<String> names = new ArrayList<String>(suites.length);
+ for (CipherSuite cs : suites) {
+ test_CipherSuite(cs);
+ names.add(cs.getName());
+ }
+ assertEquals(Arrays.asList(CipherSuite.getSupportedCipherSuiteNames()), names);
+ }
+
+ public void test_getSupportedCipherSuiteNames() throws Exception {
+ String[] names = CipherSuite.getSupportedCipherSuiteNames();
+ StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES_SSLENGINE, names);
+ for (String name : names) {
+ test_CipherSuite(name);
+ }
+ }
+
+ public void test_getClientKeyType() throws Exception {
+ byte b = Byte.MIN_VALUE;
+ do {
+ String byteString = Byte.toString(b);
+ String keyType = CipherSuite.getClientKeyType(b);
+ switch (b) {
+ case 1:
+ assertEquals(byteString, "RSA", keyType);
+ break;
+ case 2:
+ assertEquals(byteString, "DSA", keyType);
+ break;
+ case 3:
+ assertEquals(byteString, "DH_RSA", keyType);
+ break;
+ case 4:
+ assertEquals(byteString, "DH_DSA", keyType);
+ break;
+ case 64:
+ assertEquals(byteString, "EC", keyType);
+ break;
+ case 65:
+ assertEquals(byteString, "EC_RSA", keyType);
+ break;
+ case 66:
+ assertEquals(byteString, "EC_EC", keyType);
+ break;
+ default:
+ assertNull(byteString, keyType);
+ }
+ b++;
+ } while (b != Byte.MIN_VALUE);
+ }
+}
diff --git a/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java b/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java
index 1787fe6..b40c6c8 100644
--- a/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java
+++ b/luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java
@@ -42,6 +42,7 @@ import javax.net.ssl.SSLException;
import javax.net.ssl.SSLProtocolException;
import javax.security.auth.x500.X500Principal;
import junit.framework.TestCase;
+import org.apache.harmony.xnet.provider.jsse.CipherSuite;
import org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSLHandshakeCallbacks;
public class NativeCryptoTest extends TestCase {
@@ -107,17 +108,13 @@ public class NativeCryptoTest extends TestCase {
}
private static final PrivateKeyEntry SERVER_PRIVATE_KEY_ENTRY
- = TestKeyStore.privateKey(TestKeyStore.getServer().keyStore,
- TestKeyStore.getServer().keyPassword,
- "RSA");
+ = TestKeyStore.getServer().getPrivateKey("RSA", "RSA");
private static final byte[] SERVER_PRIVATE_KEY
= SERVER_PRIVATE_KEY_ENTRY.getPrivateKey().getEncoded();
private static final byte[][] SERVER_CERTIFICATES;
private static final PrivateKeyEntry CLIENT_PRIVATE_KEY_ENTRY
- = TestKeyStore.privateKey(TestKeyStore.getClientCertificate().keyStore,
- TestKeyStore.getClientCertificate().keyPassword,
- "RSA");
+ = TestKeyStore.getClientCertificate().getPrivateKey("RSA", "RSA");
private static final byte[] CLIENT_PRIVATE_KEY
= CLIENT_PRIVATE_KEY_ENTRY.getPrivateKey().getEncoded();
private static final byte[][] CLIENT_CERTIFICATES;
@@ -695,9 +692,9 @@ public class NativeCryptoTest extends TestCase {
// this depends on the SSL_set_cipher_lists call in beforeHandshake
// the three returned are the non-ephemeral cases.
assertEquals(3, clientCallback.keyTypes.length);
- assertEquals("RSA", NativeCrypto.keyType(clientCallback.keyTypes[0]));
- assertEquals("DSA", NativeCrypto.keyType(clientCallback.keyTypes[1]));
- assertEquals("EC", NativeCrypto.keyType(clientCallback.keyTypes[2]));
+ assertEquals("RSA", CipherSuite.getClientKeyType(clientCallback.keyTypes[0]));
+ assertEquals("DSA", CipherSuite.getClientKeyType(clientCallback.keyTypes[1]));
+ assertEquals("EC", CipherSuite.getClientKeyType(clientCallback.keyTypes[2]));
assertEqualPrincipals(CA_PRINCIPALS,
clientCallback.asn1DerEncodedX500Principals);
assertFalse(serverCallback.clientCertificateRequestedCalled);
diff --git a/luni/src/test/java/org/bouncycastle/crypto/digests/DigestTest.java b/luni/src/test/java/org/bouncycastle/crypto/digests/DigestTest.java
deleted file mode 100644
index 7ad6254..0000000
--- a/luni/src/test/java/org/bouncycastle/crypto/digests/DigestTest.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bouncycastle.crypto.digests;
-
-import junit.framework.TestCase;
-import org.bouncycastle.crypto.Digest;
-import org.bouncycastle.crypto.ExtendedDigest;
-
-/**
- * Implements unit tests for our JNI wrapper around OpenSSL. We use the
- * existing Bouncy Castle implementation as our test oracle.
- */
-public class DigestTest extends TestCase {
-
- /**
- * Processes the two given message digests for the same data and checks
- * the results. Requirement is that the results must be equal, the digest
- * implementations must have the same properties, and the new implementation
- * must be faster than the old one.
- *
- * @param oldDigest The old digest implementation, provided by Bouncy Castle
- * @param newDigest The new digest implementation, provided by OpenSSL
- */
- public void doTestMessageDigest(Digest oldDigest, Digest newDigest) {
- final int ITERATIONS = 10;
-
- byte[] data = new byte[1024];
-
- byte[] oldHash = new byte[oldDigest.getDigestSize()];
- byte[] newHash = new byte[newDigest.getDigestSize()];
-
- assertEquals("Hash names must be equal",
- oldDigest.getAlgorithmName(), newDigest.getAlgorithmName());
- assertEquals("Hash sizes must be equal",
- oldHash.length, newHash.length);
- assertEquals("Hash block sizes must be equal",
- ((ExtendedDigest)oldDigest).getByteLength(),
- ((ExtendedDigest)newDigest).getByteLength());
- for (int i = 0; i < data.length; i++) {
- data[i] = (byte)i;
- }
-
- long oldTime = 0;
- long newTime = 0;
-
- for (int j = 0; j < ITERATIONS; j++) {
- long t0 = System.currentTimeMillis();
- for (int i = 0; i < 4; i++) {
- oldDigest.update(data, 0, data.length);
- }
- int oldLength = oldDigest.doFinal(oldHash, 0);
- long t1 = System.currentTimeMillis();
-
- oldTime = oldTime + (t1 - t0);
-
- long t2 = System.currentTimeMillis();
- for (int i = 0; i < 4; i++) {
- newDigest.update(data, 0, data.length);
- }
- int newLength = newDigest.doFinal(newHash, 0);
- long t3 = System.currentTimeMillis();
-
- newTime = newTime + (t3 - t2);
-
- assertEquals("Hash sizes must be equal", oldLength, newLength);
-
- for (int i = 0; i < oldLength; i++) {
- assertEquals("Hashes[" + i + "] must be equal", oldHash[i], newHash[i]);
- }
- }
-
- System.out.println("Time for " + ITERATIONS + " x old hash processing: " + oldTime + " ms");
- System.out.println("Time for " + ITERATIONS + " x new hash processing: " + newTime + " ms");
-
- assertTrue("New hash should be faster", newTime < oldTime);
- }
-
- /**
- * Tests the MD5 implementation.
- */
- public void testMD5() {
- Digest oldDigest = new MD5Digest();
- Digest newDigest = new OpenSSLDigest.MD5();
- doTestMessageDigest(oldDigest, newDigest);
- }
-
- /**
- * Tests the SHA-1 implementation.
- */
- public void testSHA1() {
- Digest oldDigest = new SHA1Digest();
- Digest newDigest = new OpenSSLDigest.SHA1();
- doTestMessageDigest(oldDigest, newDigest);
- }
-
- /**
- * Tests the SHA-256 implementation.
- */
- public void testSHA256() {
- Digest oldDigest = new SHA256Digest();
- Digest newDigest = new OpenSSLDigest.SHA256();
- doTestMessageDigest(oldDigest, newDigest);
- }
-
- /**
- * Tests the SHA-384 implementation.
- */
- public void testSHA384() {
- Digest oldDigest = new SHA384Digest();
- Digest newDigest = new OpenSSLDigest.SHA384();
- doTestMessageDigest(oldDigest, newDigest);
- }
-
- /**
- * Tests the SHA-512 implementation.
- */
- public void testSHA512() {
- Digest oldDigest = new SHA512Digest();
- Digest newDigest = new OpenSSLDigest.SHA512();
- doTestMessageDigest(oldDigest, newDigest);
- }
-}
diff --git a/luni/src/test/java/org/bouncycastle/jce/provider/AllTests.java b/luni/src/test/java/org/bouncycastle/jce/provider/AllTests.java
deleted file mode 100644
index f9bf52f..0000000
--- a/luni/src/test/java/org/bouncycastle/jce/provider/AllTests.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bouncycastle.jce.provider;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All tests for " + AllTests.class.getPackage());
- suite.addTestSuite(PKIXCertPathValidatorSpiTest.class);
- return suite;
- }
-}
diff --git a/luni/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java b/luni/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
deleted file mode 100644
index 6008cdb..0000000
--- a/luni/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bouncycastle.jce.provider;
-
-import java.io.IOException;
-import java.security.InvalidAlgorithmParameterException;
-import java.security.KeyStoreException;
-import java.security.cert.CertPathValidatorException;
-import java.security.cert.CertificateException;
-import java.security.cert.TrustAnchor;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Set;
-import junit.framework.TestCase;
-import org.apache.harmony.security.provider.cert.X509CertImpl;
-import org.apache.harmony.security.provider.cert.X509CertPathImpl;
-import org.apache.harmony.xnet.provider.jsse.IndexedPKIXParameters;
-import org.bouncycastle.asn1.ASN1InputStream;
-import org.bouncycastle.asn1.ASN1Sequence;
-import org.bouncycastle.asn1.x509.X509CertificateStructure;
-
-/**
- * Verify the behavior of PKIXCertPathValidatorSpi.
- */
-public class PKIXCertPathValidatorSpiTest extends TestCase {
-
- /**
- * A chain of 3 ASN1-encoded certificates for https://service.sprint.com.
- * The certificate subjects are "service.sprint.com", "Entrust Certification
- * Authority - L1B", and "Entrust.net Certification Authority (2048)". The
- * last certificate uses UTF8 encoding for its X509 name.
- */
- private final byte[][] serviceSprintComCertChain = new byte[][] {
- new byte[] { 48, -126, 6, 89, 48, -126, 5, 65, -96, 3, 2, 1, 2, 2, 4, 72, 13, 115, -81, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, 30, 23, 13, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, 23, 13, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 120, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 15, 48, 13, 6, 3, 85, 4, 8, 19, 6, 75, 65, 78, 83, 65, 83, 49, 22, 48, 20, 6, 3, 85, 4, 7, 19, 13, 79, 118, 101, 114, 108, 97, 110, 100, 32, 80, 97, 114, 107, 49, 15, 48, 13, 6, 3, 85, 4, 10, 19, 6, 83, 112, 114, 105, 110, 116, 49, 18, 48, 16, 6, 3, 85, 4, 11, 19, 9, 100, 97, 115, 110, 109, 112, 48, 52, 98, 49, 27, 48, 25, 6, 3, 85, 4, 3, 19, 18, 115, 101, 114, 118, 105, 99, 101, 46, 115, 112, 114, 105, 110, 116, 46, 99, 111, 109, 48, -127, -97, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -127, -115, 0, 48, -127, -119, 2, -127, -127, 0, -80, 99, 109, 108, 94, -41, -78, 88, 56, -97, 33, -23, 65, -74, -118, 0, 1, 119, 126, 122, -59, -83, -25, -16, -75, -87, 100, 46, 37, -98, 65, -104, 54, -87, 56, -81, 96, -38, -4, -78, 11, 101, -29, 70, -13, -110, -76, -125, -106, -35, 41, 83, 71, 56, 6, 67, -8, 82, -58, -81, -113, 90, 91, 79, 74, -38, 34, 28, 39, -37, -12, 54, 87, 61, 48, 33, -16, 10, 112, -40, -37, -15, 59, -72, 112, 96, 85, 109, 123, -122, 58, 18, 95, 56, -81, 49, 43, -39, 99, 69, -28, -81, -106, -64, 8, -62, 40, -92, 95, -109, -122, 94, 53, -13, -33, 88, -104, 3, -77, -30, -27, 23, 92, -69, 12, -23, -9, 125, 2, 3, 1, 0, 1, -93, -126, 2, -81, 48, -126, 2, -85, 48, 11, 6, 3, 85, 29, 15, 4, 4, 3, 2, 5, -96, 48, 43, 6, 3, 85, 29, 16, 4, 36, 48, 34, -128, 15, 50, 48, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, -127, 15, 50, 48, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 19, 6, 3, 85, 29, 37, 4, 12, 48, 10, 6, 8, 43, 6, 1, 5, 5, 7, 3, 1, 48, 51, 6, 3, 85, 29, 31, 4, 44, 48, 42, 48, 40, -96, 38, -96, 36, -122, 34, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 108, 101, 118, 101, 108, 49, 98, 46, 99, 114, 108, 48, 100, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 88, 48, 86, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 47, 6, 8, 43, 6, 1, 5, 5, 7, 48, 2, -122, 35, 104, 116, 116, 112, 58, 47, 47, 97, 105, 97, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 45, 108, 49, 98, 46, 99, 101, 114, 48, -126, 1, 87, 6, 3, 85, 29, 32, 4, -126, 1, 78, 48, -126, 1, 74, 48, -126, 1, 70, 6, 9, 42, -122, 72, -122, -10, 125, 7, 75, 2, 48, -126, 1, 55, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 48, -126, 1, 11, 6, 8, 43, 6, 1, 5, 5, 7, 2, 2, 48, -127, -2, 26, -127, -5, 84, 104, 101, 32, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 80, 114, 97, 99, 116, 105, 99, 101, 32, 83, 116, 97, 116, 101, 109, 101, 110, 116, 32, 40, 67, 80, 83, 41, 32, 97, 118, 97, 105, 108, 97, 98, 108, 101, 32, 97, 116, 32, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 32, 32, 105, 115, 32, 104, 101, 114, 101, 98, 121, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 105, 110, 116, 111, 32, 121, 111, 117, 114, 32, 117, 115, 101, 32, 111, 114, 32, 114, 101, 108, 105, 97, 110, 99, 101, 32, 111, 110, 32, 116, 104, 105, 115, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 46, 32, 32, 84, 104, 105, 115, 32, 67, 80, 83, 32, 99, 111, 110, 116, 97, 105, 110, 115, 32, 108, 105, 109, 105, 116, 97, 116, 105, 111, 110, 115, 32, 111, 110, 32, 119, 97, 114, 114, 97, 110, 116, 105, 101, 115, 32, 97, 110, 100, 32, 108, 105, 97, 98, 105, 108, 105, 116, 105, 101, 115, 46, 32, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 32, 76, 105, 109, 105, 116, 101, 100, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 68, 101, 26, -23, -69, -107, 32, 89, 18, 28, -123, 32, 74, -116, -33, -48, 70, -52, 68, 77, 48, 9, 6, 3, 85, 29, 19, 4, 2, 48, 0, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 3, 40, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 18, 56, 92, -74, -100, -56, 95, 121, 27, -84, -88, -104, -27, -98, -12, 58, 48, -26, 40, -7, 25, -68, -124, -104, -54, -121, 84, 52, 3, 22, -106, 88, 44, -39, 126, 17, 96, 4, -41, -84, -101, 74, -92, -113, -12, -99, 77, 108, -30, 38, 19, 78, 48, 32, -126, 95, -10, -114, 58, 98, -49, -108, -109, -87, 5, -80, -43, 121, 21, -99, 43, -73, 26, 51, 31, 87, -38, -119, 78, -113, -59, -100, -118, -84, -46, -48, 93, 99, 2, 40, -39, 76, -48, -122, -60, -25, -73, 103, 126, 83, -86, -26, 66, 122, -65, -89, -102, 115, 105, -124, -85, -18, -66, 85, 30, -29, -96, 104, 65, -66, 40, 69, -91, 101, -19, 39, -86, -21, -18, 39, 51, -1, 36, -52, 53, -65, 53, 12, -62, -97, -45, -26, 113, -20, 102, 56, 102, 104, 37, 17, 57, -96, -83, -71, 106, 63, -64, -122, 61, 59, 8, -123, 108, 22, 62, -58, -105, 88, 38, 96, -6, -29, -114, 105, 110, -102, -72, 109, -33, 56, 61, 52, 70, -75, -92, 97, -9, -6, -64, 53, -76, 81, -100, 90, -50, 19, -87, 30, -24, -53, 109, -75, 45, -38, 14, 119, -31, 44, -30, -93, -76, 14, 97, -53, -107, 60, 30, -102, 68, 12, 26, 76, -114, 73, -13, -127, 21, 94, -42, 94, 30, -50, -3, 116, 41, -3, -89, 23, -27, -49, -3, -95, 119, -104, -45, 112, 35, 66, 59, 84, 116, 19, -102, -68, -104, 1 },
- new byte[] { 48, -126, 5, -111, 48, -126, 4, 121, -96, 3, 2, 1, 2, 2, 4, 56, 99, -59, -82, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 48, 56, 48, 56, 50, 53, 49, 56, 49, 52, 50, 54, 90, 23, 13, 49, 56, 48, 56, 50, 53, 49, 56, 52, 52, 50, 54, 90, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -36, 33, -11, 104, -7, 122, -50, -121, -14, 120, -33, -40, 59, 77, 6, 125, -58, 36, -28, -87, -51, -99, 1, 86, -28, -10, 113, 23, -86, 127, 117, 34, 24, -28, 116, 109, 27, 62, 86, -43, -79, -90, 30, -35, 89, 38, 83, -54, 6, -26, -70, 11, 111, 55, -69, -88, -58, -100, 21, 59, 6, 27, -121, 12, -62, 26, 77, -45, -127, -82, -37, 80, 101, -91, 58, 100, 79, 48, 52, -102, 43, -87, 31, -3, 43, -47, 56, 113, 25, 104, -14, -114, -21, 123, -55, 64, 60, 72, -60, 25, -79, -73, 16, 37, -17, 68, -89, -26, 119, -101, 125, 34, -102, -34, -40, 94, -39, -61, -50, -55, 113, 34, -69, -82, -17, 5, -42, -14, 23, -25, 86, 120, -31, 83, 5, 74, 38, 115, -72, -57, 73, 103, -109, 35, 15, 86, -78, -113, -35, -55, 89, 5, -27, 99, 21, -76, -121, 126, 64, 70, -23, -75, 0, 123, 3, -76, 13, -28, -106, 103, 44, -34, 27, 89, 11, 26, 31, -72, 99, 68, -82, -63, -41, 68, -121, -60, -111, 89, -100, 0, 67, 109, -58, -33, 10, -80, -79, 4, -51, -2, -66, 48, 94, 58, 37, 114, -35, -94, 62, -19, 70, 58, -57, -92, 92, 92, -28, 37, -14, 19, 7, -24, -82, -38, -101, 25, -101, -94, -39, 96, -99, -50, -112, 71, 106, 97, 123, 64, -24, 20, -62, -2, 47, -124, 90, 102, 23, -64, -105, -45, 73, 56, -34, 99, 2, -97, 2, 3, 1, 0, 1, -93, -126, 1, 38, 48, -126, 1, 34, 48, 14, 6, 3, 85, 29, 15, 1, 1, -1, 4, 4, 3, 2, 1, 6, 48, 15, 6, 3, 85, 29, 19, 1, 1, -1, 4, 5, 48, 3, 1, 1, -1, 48, 51, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 39, 48, 37, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 50, 6, 3, 85, 29, 31, 4, 43, 48, 41, 48, 39, -96, 37, -96, 35, -122, 33, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 99, 97, 46, 99, 114, 108, 48, 59, 6, 3, 85, 29, 32, 4, 52, 48, 50, 48, 48, 6, 4, 85, 29, 32, 0, 48, 40, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 0, -127, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 11, 37, 60, 88, -6, -114, -36, -94, 66, 59, 118, 113, 110, 108, -44, 79, 43, -71, 83, 92, -78, 88, -71, -79, -36, 111, 26, -28, -29, -60, 80, -14, 65, -126, -70, -12, 125, -57, -63, -7, -6, -116, 83, -65, -71, 98, -73, 73, -29, 29, 10, -4, 31, -42, -60, 118, 106, -109, -53, 119, 30, 44, 127, -48, 63, 22, 99, 76, 114, 76, 103, 96, 15, -8, -128, -42, -89, -102, -54, -94, 51, -111, 15, 68, -78, 102, 61, -114, 104, 12, 64, -123, 18, 55, -111, -71, -126, 119, 52, 89, 45, 92, -33, -126, 110, 44, -74, 122, -46, 4, -112, 103, 104, 75, 112, -4, 45, -72, -1, -112, 100, 111, 126, -111, -9, -47, 71, 51, -13, 91, -72, 88, 46, 33, -40, 117, 96, 27, 19, -52, -8, -78, -88, -6, 106, -87, 42, 90, 79, 69, -123, 64, -76, -35, 52, 5, -73, 112, -54, 1, -17, -31, -127, -25, 17, 80, -37, 62, -30, -41, 16, 46, 106, 21, 127, -73, -44, -93, 98, -78, -119, 105, 97, 87, -58, 127, -114, -98, -44, 36, 122, -13, -95, 67, 95, -96, 122, -119, -36, 89, -51, 125, -41, 117, -89, -68, 83, -43, 71, 53, -58, 49, 48, 32, -97, -101, -70, -75, -125, -26, -119, 85, 1, 77, -111, 59, -42, -119, 53, -121, 60, -125, 107, 122, 41, -126, -44, 75, -44, -26, 22, 116, -80, 1, 16, -85, 105, 6, 20, 55, 123, -9, 102, 48, 58, -59 },
- new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 },
- };
-
- /**
- * ASN1-encoded trusted certificate #946059622 for Entrust.net. This
- * certificate uses the TELETEX encoding for its X509 name.
- */
- private final byte[] trustedCert = new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 };
-
- public void testTrustAndRemoteCertificatesWithDifferentEncodings()
- throws IOException, CertificateException, KeyStoreException,
- InvalidAlgorithmParameterException, CertPathValidatorException {
-
- X509CertPathImpl certPath = new X509CertPathImpl(Arrays.asList(
- new X509CertImpl(serviceSprintComCertChain[0]),
- new X509CertImpl(serviceSprintComCertChain[1]),
- new X509CertImpl(serviceSprintComCertChain[2])));
-
- Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
- trustAnchors.add(new TrustAnchor(new X509CertificateObject(
- new X509CertificateStructure(
- (ASN1Sequence) new ASN1InputStream(trustedCert).readObject())), null));
-
- IndexedPKIXParameters indexedPKIXParameters = new IndexedPKIXParameters(trustAnchors);
- indexedPKIXParameters.setRevocationEnabled(false);
-
- new PKIXCertPathValidatorSpi().engineValidate(certPath, indexedPKIXParameters);
- // completing normally indicates that the certificate was valid
- }
-}
diff --git a/luni/src/test/java/tests/AllTests.java b/luni/src/test/java/tests/AllTests.java
index be91bd0..fb4d0e3 100644
--- a/luni/src/test/java/tests/AllTests.java
+++ b/luni/src/test/java/tests/AllTests.java
@@ -29,12 +29,11 @@ public class AllTests
TestRunner.main(new String[] { AllTests.class.getName() });
}
- public static final Test suite() {
+ public static Test suite() {
TestSuite suite = new TestSuite();
// Harmony-written test suites (often with Android tests added in).
suite.addTest(tests.annotation.AllTests.suite());
- suite.addTest(tests.archive.AllTests.suite());
suite.addTest(tests.concurrent.AllTests.suite());
suite.addTest(tests.dom.AllTests.suite());
suite.addTest(tests.luni.AllTestsIo.suite());
@@ -42,9 +41,6 @@ public class AllTests
suite.addTest(tests.luni.AllTestsNet.suite());
suite.addTest(tests.luni.AllTestsUtil.suite());
suite.addTest(tests.math.AllTests.suite());
- suite.addTest(tests.nio.AllTests.suite());
- suite.addTest(tests.nio_char.AllTests.suite());
- suite.addTest(tests.prefs.AllTests.suite());
suite.addTest(tests.regex.AllTests.suite());
suite.addTest(tests.security.AllTests.suite());
suite.addTest(tests.sql.AllTests.suite());
diff --git a/luni/src/test/java/tests/api/java/io/AllTests.java b/luni/src/test/java/tests/api/java/io/AllTests.java
index c41968e..d75d2c9 100644
--- a/luni/src/test/java/tests/api/java/io/AllTests.java
+++ b/luni/src/test/java/tests/api/java/io/AllTests.java
@@ -26,77 +26,7 @@ import junit.framework.TestSuite;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("All tests for package tests.api.java.io;");
- // $JUnit-BEGIN$
-
- suite.addTestSuite(BufferedInputStreamTest.class);
- suite.addTestSuite(BufferedOutputStreamTest.class);
- suite.addTestSuite(BufferedReaderTest.class);
- suite.addTestSuite(BufferedWriterTest.class);
- suite.addTestSuite(ByteArrayInputStreamTest.class);
- suite.addTestSuite(ByteArrayOutputStreamTest.class);
- suite.addTestSuite(CharArrayReaderTest.class);
- suite.addTestSuite(CharArrayWriterTest.class);
- suite.addTestSuite(CharConversionExceptionTest.class);
- suite.addTestSuite(ComputeSerialVersionUIDTest.class);
- suite.addTestSuite(DataInputStreamTest.class);
- suite.addTestSuite(DataInputOutputStreamTest.class);
- suite.addTestSuite(DataOutputStreamTest.class);
- suite.addTestSuite(EOFExceptionTest.class);
- suite.addTestSuite(FileDescriptorTest.class);
- suite.addTestSuite(FileInputStreamTest.class);
- suite.addTestSuite(FileNotFoundExceptionTest.class);
- suite.addTestSuite(FileOutputStreamTest.class);
- suite.addTestSuite(FilePermissionTest.class);
- suite.addTestSuite(FileReaderTest.class);
- suite.addTestSuite(FileTest.class);
- suite.addTestSuite(FileWriterTest.class);
- suite.addTestSuite(FilterInputStreamTest.class);
- suite.addTestSuite(FilterOutputStreamTest.class);
- suite.addTestSuite(FilterReaderTest.class);
- suite.addTestSuite(FilterWriterTest.class);
- suite.addTestSuite(IOExceptionTest.class);
- suite.addTestSuite(InputStreamReaderTest.class);
- suite.addTestSuite(InterruptedIOExceptionTest.class);
- suite.addTestSuite(InvalidClassExceptionTest.class);
- suite.addTestSuite(InvalidObjectExceptionTest.class);
- suite.addTestSuite(LineNumberInputStreamTest.class);
- suite.addTestSuite(LineNumberReaderTest.class);
- suite.addTestSuite(NotActiveExceptionTest.class);
- suite.addTestSuite(NotSerializableExceptionTest.class);
suite.addTestSuite(ObjectInputStreamTest.class);
- suite.addTestSuite(ObjectInputStreamGetFieldTest.class);
- suite.addTestSuite(ObjectInputOutputStreamTest.class);
- suite.addTestSuite(ObjectOutputStreamTest.class);
- suite.addTestSuite(ObjectOutputStreamPutFieldTest.class);
- suite.addTestSuite(ObjectStreamClassTest.class);
- suite.addTestSuite(ObjectStreamExceptionTest.class);
- suite.addTestSuite(ObjectStreamFieldTest.class);
- suite.addTestSuite(OpenRandomFileTest.class);
- suite.addTestSuite(OutputStreamTest.class);
- suite.addTestSuite(OutputStreamWriterTest.class);
- suite.addTestSuite(PipedInputStreamTest.class);
- suite.addTestSuite(PipedOutputStreamTest.class);
- suite.addTestSuite(PipedReaderTest.class);
- suite.addTestSuite(PipedWriterTest.class);
- suite.addTestSuite(PrintStreamTest.class);
- suite.addTestSuite(PrintWriterTest.class);
- suite.addTestSuite(PushbackInputStreamTest.class);
- suite.addTestSuite(PushbackReaderTest.class);
- suite.addTestSuite(RandomAccessFileTest.class);
- suite.addTestSuite(SequenceInputStreamTest.class);
- suite.addTestSuite(SerializablePermissionTest.class);
- suite.addTestSuite(StreamCorruptedExceptionTest.class);
- suite.addTestSuite(StreamTokenizerTest.class);
- suite.addTestSuite(StringBufferInputStreamTest.class);
- suite.addTestSuite(StringReaderTest.class);
- suite.addTestSuite(StringWriterTest.class);
- suite.addTestSuite(SyncFailedExceptionTest.class);
- suite.addTestSuite(UTFDataFormatExceptionTest.class);
- suite.addTestSuite(UnsupportedEncodingExceptionTest.class);
- suite.addTestSuite(WriteAbortedExceptionTest.class);
- suite.addTestSuite(WriterTest.class);
-
- // $JUnit-END$
return suite;
}
}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java b/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java
deleted file mode 100644
index 27515d3..0000000
--- a/luni/src/test/java/tests/api/java/io/BufferedInputStreamTest.java
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import junit.framework.TestCase;
-import tests.support.Support_ASimpleInputStream;
-import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(BufferedInputStream.class)
-public class BufferedInputStreamTest extends TestCase {
-
- public String fileName;
-
- private BufferedInputStream is;
-
- private FileInputStream isFile;
-
- byte[] ibuf = new byte[4096];
-
- public String fileString = "Test_All_Tests\nTest_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#BufferedInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- is = new BufferedInputStream(isFile);
-
- try {
- is.read();
- } catch (Exception e) {
- fail("Test 1: Read failed on a freshly constructed buffer.");
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#BufferedInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedInputStream",
- args = {java.io.InputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_InputStreamI() throws IOException {
- // Test for method java.io.BufferedInputStream(java.io.InputStream, int)
- boolean exceptionFired = false;
-
- try {
- is = new BufferedInputStream(isFile, -1);
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- try {
- // Create buffer with exact size of file
- is = new BufferedInputStream(isFile, this.fileString
- .length());
- // Ensure buffer gets filled by evaluating one read
- is.read();
- // Close underlying FileInputStream, all but 1 buffered bytes should
- // still be available.
- isFile.close();
- // Read the remaining buffered characters, no IOException should
- // occur.
- is.skip(this.fileString.length() - 2);
- is.read();
- try {
- // is.read should now throw an exception because it will have to
- // be filled.
- is.read();
- } catch (IOException e) {
- exceptionFired = true;
- }
- assertTrue("Exception should have been triggered by read()",
- exceptionFired);
- } catch (IOException e) {
- fail("Exception during test_1_Constructor");
- }
-
- // regression test for harmony-2407
- new testBufferedInputStream(null);
- assertNotNull(testBufferedInputStream.buf);
- testBufferedInputStream.buf = null;
- new testBufferedInputStream(null, 100);
- assertNotNull(testBufferedInputStream.buf);
- }
-
- static class testBufferedInputStream extends BufferedInputStream {
- static byte[] buf;
- testBufferedInputStream(InputStream is) throws IOException {
- super(is);
- buf = super.buf;
- }
-
- testBufferedInputStream(InputStream is, int size) throws IOException {
- super(is, size);
- buf = super.buf;
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the available() method.",
- method = "available",
- args = {}
- )
- public void test_available() {
- // Test for method int java.io.BufferedInputStream.available()
- try {
- assertTrue("Returned incorrect number of available bytes", is
- .available() == fileString.length());
- } catch (IOException e) {
- fail("Exception during available test");
- }
-
- // Test that a closed stream throws an IOE for available()
- BufferedInputStream bis = new BufferedInputStream(
- new ByteArrayInputStream(new byte[] { 'h', 'e', 'l', 'l', 'o',
- ' ', 't', 'i', 'm' }));
- int available = 0;
- try {
- available = bis.available();
- bis.close();
- } catch (IOException ex) {
- fail();
- }
- assertTrue(available != 0);
-
- try {
- bis.available();
- fail("Expected test to throw IOE.");
- } catch (IOException ex) {
- // expected
- } catch (Throwable ex) {
- fail("Expected test to throw IOE not "
- + ex.getClass().getName());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.BufferedInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- is.close();
-
- try {
- is.read();
- fail("Test 1: IOException expected when reading after closing " +
- "the stream.");
- } catch (IOException e) {
- // Expected.
- }
-
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
- is = new BufferedInputStream(sis);
- try {
- is.close();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sis.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.BufferedInputStream#mark(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- ) /* ,
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "read",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks that a marked position is invalidated.",
- method = "skip",
- args = {long.class}
- ) */
- })
- public void test_markI_reset() throws IOException {
- byte[] buf1 = new byte[100];
- byte[] buf2 = new byte[100];
-
- // Test 1: Check that reset fails if no mark has been set.
- try {
- is.reset();
- fail("Test 1: IOException expected if no mark has been set.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 2: Check that mark / reset works when the mark is not invalidated.
- is.skip(10);
- is.mark(100);
- is.read(buf1, 0, buf1.length);
- is.reset();
- is.read(buf2, 0, buf2.length);
- is.reset();
- assertTrue("Test 2: Failed to mark correct position or reset failed.",
- new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
-
- // Tests 3 and 4: Check that skipping less than readlimit bytes does
- // not invalidate the mark.
- is.skip(10);
- try {
- is.reset();
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException " + e.getMessage());
- }
- is.read(buf2, 0, buf2.length);
- is.reset();
- assertTrue("Test 4: Failed to mark correct position, or reset failed.",
- new String(buf1, 0, buf1.length).equals(new String(buf2, 0, buf2.length)));
-
-/* Tests disabled because they fail. The specification is ambiguous
- * regarding the invalidation of a set mark by read and skip operations.
-
- // Test 5: Check that the mark is invalidated by a sequence of reads.
- is.skip(200);
- is.mark(10);
- for (int i = 0; i < 11; i++) {
- is.read();
- }
- try {
- is.reset();
- fail("Test 5: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 6: Check that the mark is invalidated by a buffer read.
- is.skip(200);
- is.mark(10);
- is.read(buf1, 0, buf1.length);
- try {
- is.reset();
- fail("Test 6: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Test 7: Check that the mark is invalidated by a skip.
- is.mark(10);
- is.skip(11);
- try {
- is.reset();
- fail("Test 7: IOException expected because the mark should be invalid.");
- } catch (IOException e) {
- // Expected.
- }
-*/
-
- // Test 8: Check that reset fails for a closed input stream.
- is.close();
- try {
- is.reset();
- fail("Test 8: IOException expected because the input stream is closed.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.BufferedInputStream.markSupported()
- assertTrue("markSupported returned incorrect value", is.markSupported());
- }
-
- /**
- * @tests java.io.BufferedInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "A partial read test in test_markI_reset() is disabled at " +
- "the moment because it fails. If this test is ever " +
- "enabled, then the level here must be changed to " +
- "PARTIAL_COMPLETE.",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- int c = is.read();
- assertTrue("Test 1: Incorrect character read.",
- c == fileString.charAt(0));
-
- byte[] bytes = new byte[256];
- for (int i = 0; i < 256; i++) {
- bytes[i] = (byte) i;
- }
-
- BufferedInputStream in = new BufferedInputStream(
- new ByteArrayInputStream(bytes), 5);
-
- // Read more bytes than are buffered.
- for (int i = 0; i < 10; i++) {
- assertEquals("Test 2: Incorrect byte read;", bytes[i], in.read());
- }
-
- in.close();
- try {
- in.read();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks exceptions only.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- BufferedInputStream bis = new BufferedInputStream(null);
-
- try {
- bis.read(null, -1, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- try {
- bis.read(new byte[0], -1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bis.read(new byte[0], 1, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bis.read(new byte[0], 1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- bis.close();
-
- try {
- bis.read(null, -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- //expected
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Functional test.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int java.io.BufferedInputStream.read(byte [], int,
- // int)
- byte[] buf1 = new byte[100];
- try {
- is.skip(3000);
- is.mark(1000);
- is.read(buf1, 0, buf1.length);
- assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(fileString.substring(3000, 3100)));
-
- } catch (IOException e) {
- fail("Exception during read test");
- }
-
- BufferedInputStream bufin = new BufferedInputStream(new InputStream() {
- int size = 2, pos = 0;
-
- byte[] contents = new byte[size];
-
- @Override
- public int read() throws IOException {
- if (pos >= size) {
- throw new IOException("Read past end of data");
- }
- return contents[pos++];
- }
-
- @Override
- public int read(byte[] buf, int off, int len) throws IOException {
- if (pos >= size) {
- throw new IOException("Read past end of data");
- }
- int toRead = len;
- if (toRead > available()) {
- toRead = available();
- }
- System.arraycopy(contents, pos, buf, off, toRead);
- pos += toRead;
- return toRead;
- }
-
- @Override
- public int available() {
- return size - pos;
- }
- });
- try {
- bufin.read();
- int result = bufin.read(new byte[2], 0, 2);
- assertTrue("Incorrect result: " + result, result == 1);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
- }
-
- /**
- * @tests java.io.BufferedInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long n) method.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.BufferedInputStream.skip(long)
- byte[] buf1 = new byte[10];
- try {
- is.mark(2000);
- is.skip(1000);
- is.read(buf1, 0, buf1.length);
- is.reset();
- assertTrue("Failed to skip to correct position", new String(buf1,
- 0, buf1.length).equals(fileString.substring(1000, 1010)));
- } catch (IOException e) {
- fail("Exception during skip test");
- }
-
- //regression for HARMONY-667
- BufferedInputStream buf = new BufferedInputStream(null, 5);
- try {
- buf.skip(10);
- fail("Should throw IOException");
- } catch (IOException e) {
- //expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- @Override
- protected void setUp() {
-
- try {
- fileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (fileName.charAt(fileName.length() - 1) == separator.charAt(0)) {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName,
- "input.tst");
- } else {
- fileName = Support_PlatformFile.getNewPlatformFile(fileName
- + separator, "input.tst");
- }
- OutputStream fos = new FileOutputStream(fileName);
- fos.write(fileString.getBytes());
- fos.close();
- isFile = new FileInputStream(fileName);
- is = new BufferedInputStream(isFile, 1000);
- } catch (IOException e) {
- System.out.println("Exception during setup");
- e.printStackTrace();
- }
-
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- @Override
- protected void tearDown() {
-
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- System.out.println("Exception 1 during BIS tearDown: " + e.getMessage());
- }
- }
- try {
- File f = new File(fileName);
- f.delete();
- } catch (Exception e) {
- System.out.println("Exception 2 during BIS tearDown: " + e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java
deleted file mode 100644
index 7ed516c..0000000
--- a/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(BufferedOutputStream.class)
-public class BufferedOutputStreamTest extends junit.framework.TestCase {
-
- private java.io.OutputStream os;
-
- java.io.ByteArrayOutputStream baos;
-
- java.io.ByteArrayInputStream bais;
-
- Support_OutputStream sos;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.BufferedOutputStream#BufferedOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() {
- try {
- baos = new java.io.ByteArrayOutputStream();
- os = new java.io.BufferedOutputStream(baos);
- os.write(fileString.getBytes(), 0, 500);
- } catch (java.io.IOException e) {
- fail("Constrcutor test failed");
- }
-
- }
-
- /**
- * @tests java.io.BufferedOutputStream#BufferedOutputStream(java.io.OutputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IllegalArgumentException checking missed.",
- method = "BufferedOutputStream",
- args = {java.io.OutputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_OutputStreamI() {
- baos = new java.io.ByteArrayOutputStream();
-
- try {
- os = new java.io.BufferedOutputStream(baos, -1);
- fail("Test 1: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- try {
- os = new java.io.BufferedOutputStream(baos, 1024);
- os.write(fileString.getBytes(), 0, 500);
- } catch (java.io.IOException e) {
- fail("Test 2: Unexpected IOException.");
- }
- }
-
- /**
- * @tests java.io.BufferedOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws IOException {
- baos = new ByteArrayOutputStream();
- os = new java.io.BufferedOutputStream(baos, 600);
- os.write(fileString.getBytes(), 0, 500);
- os.flush();
- assertEquals("Test 1: Bytes not written after flush;",
- 500, ((ByteArrayOutputStream) baos).size());
- os.close();
-
- sos = new Support_OutputStream(true);
- os = new BufferedOutputStream(sos, 10);
- try {
- os.flush();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // To avoid exception during tearDown().
- sos.setThrowsException(false);
- }
-
- /**
- * @tests java.io.BufferedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws IOException {
- os = new java.io.BufferedOutputStream(
- baos = new java.io.ByteArrayOutputStream(),512);
- os.write(fileString.getBytes(), 0, 500);
- bais = new java.io.ByteArrayInputStream(baos.toByteArray());
- assertEquals("Test 1: Bytes written, not buffered;",
- 0, bais.available());
- os.flush();
- bais = new java.io.ByteArrayInputStream(baos.toByteArray());
- assertEquals("Test 2: Bytes not written after flush;",
- 500, bais.available());
- os.write(fileString.getBytes(), 500, 513);
- bais = new java.io.ByteArrayInputStream(baos.toByteArray());
- assertTrue("Test 3: Bytes not written when buffer full.",
- bais.available() >= 1000);
- byte[] wbytes = new byte[1013];
- bais.read(wbytes, 0, 1013);
- assertTrue("Test 4: Incorrect bytes written or read.",
- fileString.substring(0, 1013).equals(
- new String(wbytes, 0, wbytes.length)));
- os.close();
-
- sos = new Support_OutputStream(true);
- os = new BufferedOutputStream(sos, 10);
- try {
- os.write(fileString.getBytes(), 0, 500);
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // To avoid exception during tearDown().
- sos.setThrowsException(false);
- }
-
- /**
- * @tests java.io.BufferedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII_Exception() throws IOException {
- OutputStream bos = new BufferedOutputStream(new ByteArrayOutputStream());
- byte[] nullByteArray = null;
- byte[] byteArray = new byte[10];
-
- try {
- bos.write(nullByteArray, 0, 1);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- bos.write(byteArray, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bos.write(byteArray, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bos.write(byteArray, 1, 10);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.BufferedOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- baos = new java.io.ByteArrayOutputStream();
- os = new java.io.BufferedOutputStream(baos);
- os.write('t');
- bais = new java.io.ByteArrayInputStream(baos.toByteArray());
- assertEquals("Test 1: Byte written, not buffered;",
- 0, bais.available());
- os.flush();
- bais = new java.io.ByteArrayInputStream(baos.toByteArray());
- assertEquals("Test 2: Byte not written after flush;",
- 1, bais.available());
- byte[] wbytes = new byte[1];
- bais.read(wbytes, 0, 1);
- assertEquals("Test 3: Incorrect byte written or read;",
- 't', wbytes[0]);
- os.close();
-
- sos = new Support_OutputStream(true);
- os = new BufferedOutputStream(sos, 1);
- os.write('t');
- try {
- // Exception is only thrown when the buffer is flushed.
- os.write('e');
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // To avoid exception during tearDown().
- sos.setThrowsException(false);
- }
-
- protected void tearDown() {
- try {
- if (bais != null)
- bais.close();
- if (os != null)
- os.close();
- if (baos != null)
- baos.close();
- } catch (Exception e) {
- System.out.println("Exception during tearDown" + e.toString());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java b/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
deleted file mode 100644
index ba75bbe..0000000
--- a/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PipedReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import tests.support.Support_ASimpleReader;
-import tests.support.Support_StringReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import tests.support.ThrowingReader;
-
-@TestTargetClass(BufferedReader.class)
-public class BufferedReaderTest extends junit.framework.TestCase {
-
- BufferedReader br;
-
- String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.BufferedReader#BufferedReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.BufferedReader(java.io.Reader)
- br = new BufferedReader(new Support_StringReader(testString));
- assertNotNull(br);
- }
-
- /**
- * @tests java.io.BufferedReader#BufferedReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedReader",
- args = {java.io.Reader.class, int.class}
- )
- public void test_ConstructorLjava_io_ReaderI() {
- // Illegal negative size argument test.
- try {
- br = new BufferedReader(new Support_StringReader(testString), 0);
- fail("IllegalArgumentException expected");
- } catch (IllegalArgumentException expected) {
- }
- br = new BufferedReader(new Support_StringReader(testString), 1024);
- assertNotNull(br);
- }
-
- /**
- * @tests java.io.BufferedReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() {
- Support_ASimpleReader ssr = new Support_ASimpleReader(true);
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.close();
- br.read();
- fail("Test 1: Read on closed stream.");
- } catch (IOException x) {
- // Expected.
- } catch (Exception e) {
- fail("Exception during close test " + e.toString());
- }
-
- br = new BufferedReader(ssr);
- try {
- br.close();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // Avoid IOException in tearDown().
- ssr.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.BufferedReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- // Test for method void java.io.BufferedReader.mark(int)
- char[] buf = null;
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.mark(1000);
- br.skip(250);
- br.reset();
- buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to set mark properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during mark test");
- }
- try {
- br = new BufferedReader(new Support_StringReader(testString), 800);
- br.skip(500);
- br.mark(250);
- br.read(buf, 0, 1000);
- br.reset();
- fail("Failed to invalidate mark properly");
- } catch (IOException x) {
- }
-
- char[] chars = new char[256];
- for (int i = 0; i < 256; i++)
- chars[i] = (char) i;
- Reader in = new BufferedReader(new Support_StringReader(new String(
- chars)), 12);
- try {
- in.skip(6);
- in.mark(14);
- in.read(new char[14], 0, 14);
- in.reset();
- assertTrue("Wrong chars", in.read() == (char) 6
- && in.read() == (char) 7);
- } catch (IOException e) {
- fail("Exception during mark test 2:" + e);
- }
-
- in = new BufferedReader(new Support_StringReader(new String(chars)), 12);
- try {
- in.skip(6);
- in.mark(8);
- in.skip(7);
- in.reset();
- assertTrue("Wrong chars 2", in.read() == (char) 6
- && in.read() == (char) 7);
- } catch (IOException e) {
- fail("Exception during mark test 3:" + e);
- }
- }
-
- /**
- * @tests java.io.BufferedReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.BufferedReader.markSupported()
- br = new BufferedReader(new Support_StringReader(testString));
- assertTrue("markSupported returned false.", br.markSupported());
- }
-
- /**
- * @tests java.io.BufferedReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- Support_ASimpleReader ssr = new Support_ASimpleReader(true);
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- int r = br.read();
- assertTrue("Char read improperly", testString.charAt(0) == r);
- br = new BufferedReader(new Support_StringReader(new String(
- new char[] { '\u8765' })));
- assertTrue("Wrong double byte character", br.read() == '\u8765');
- } catch (java.io.IOException e) {
- fail("Exception during read test");
- }
-
- char[] chars = new char[256];
- for (int i = 0; i < 256; i++)
- chars[i] = (char) i;
- Reader in = new BufferedReader(new Support_StringReader(new String(
- chars)), 12);
- try {
- assertEquals("Wrong initial char", 0, in.read()); // Fill the
- // buffer
- char[] buf = new char[14];
- in.read(buf, 0, 14); // Read greater than the buffer
- assertTrue("Wrong block read data", new String(buf)
- .equals(new String(chars, 1, 14)));
- assertEquals("Wrong chars", 15, in.read()); // Check next byte
- } catch (IOException e) {
- fail("Exception during read test 2:" + e);
- }
-
- // regression test for HARMONY-841
- assertTrue(new BufferedReader(new CharArrayReader(new char[5], 1, 0), 2).read() == -1);
-
- br.close();
- br = new BufferedReader(ssr);
- try {
- br.read();
- fail("IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // Avoid IOException in tearDown().
- ssr.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "The test verifies read(char[] cbuf, int off, int len) method.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws Exception {
- char[] ca = new char[2];
- BufferedReader toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[0])));
- try {
- toRet.close();
- } catch (IOException e) {
- fail("unexpected 1: " + e);
- }
-
- /* Closed reader should throw IOException reading zero bytes */
- try {
- toRet.read(ca, 0, 0);
- fail("Reading zero bytes on a closed reader should not work");
- } catch (IOException e) {
- // expected
- }
-
- // Test to ensure that a drained stream returns 0 at EOF
- toRet = new BufferedReader(new InputStreamReader(
- new ByteArrayInputStream(new byte[2])));
- try {
- assertEquals("Emptying the reader should return two bytes", 2,
- toRet.read(ca, 0, 2));
- assertEquals("EOF on a reader should be -1", -1, toRet.read(ca, 0,
- 2));
- assertEquals("Reading zero bytes at EOF should work", 0, toRet
- .read(ca, 0, 0));
- } catch (IOException ex) {
- fail("Unexpected IOException : " + ex.getLocalizedMessage());
- }
-
- // Test for method int java.io.BufferedReader.read(char [], int, int)
- try {
- char[] buf = new char[testString.length()];
- br = new BufferedReader(new Support_StringReader(testString));
- br.read(buf, 50, 500);
- assertTrue("Chars read improperly", new String(buf, 50, 500)
- .equals(testString.substring(0, 500)));
-
- br = new BufferedReader(new Support_StringReader(testString));
- assertEquals(0, br.read(buf, 0, 0));
- assertEquals(buf.length, br.read(buf, 0, buf.length));
- assertEquals(0, br.read(buf, buf.length, 0));
- } catch (java.io.IOException e) {
- fail("Exception during read test");
- }
-
- BufferedReader bufin = new BufferedReader(new Reader() {
- int size = 2, pos = 0;
-
- char[] contents = new char[size];
-
- public int read() throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- return contents[pos++];
- }
-
- public int read(char[] buf, int off, int len) throws IOException {
- if (pos >= size)
- throw new IOException("Read past end of data");
- int toRead = len;
- if (toRead > (size - pos))
- toRead = size - pos;
- System.arraycopy(contents, pos, buf, off, toRead);
- pos += toRead;
- return toRead;
- }
-
- public boolean ready() throws IOException {
- return size - pos > 0;
- }
-
- public void close() throws IOException {
- }
- });
- try {
- bufin.read();
- int result = bufin.read(new char[2], 0, 2);
- assertTrue("Incorrect result: " + result, result == 1);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
- }
-
- /**
- * @tests java.io.BufferedReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "The test verifies read(char[] cbuf, int off, int len) method.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII_Exception() throws Exception {
- br = new BufferedReader(new Support_StringReader(testString));
- try{
- br.read(new char[10], -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try{
- br.read(new char[10], 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try{
- br.read(new char[10], 10, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- //regression for HARMONY-831
- try{
- new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
- fail("should throw IndexOutOfBoundsException");
- }catch(IndexOutOfBoundsException e){
- }
- }
-
- /**
- * @tests java.io.BufferedReader#readLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
- public void test_readLine() throws IOException {
- String line;
- br = new BufferedReader(new Support_StringReader("Lorem\nipsum\rdolor sit amet..."));
-
- line = br.readLine();
- assertTrue("Test 1: Incorrect line written or read: " + line,
- line.equals("Lorem"));
- line = br.readLine();
- assertTrue("Test 2: Incorrect line written or read: " + line,
- line.equals("ipsum"));
- line = br.readLine();
- assertTrue("Test 3: Incorrect line written or read: " + line,
- line.equals("dolor sit amet..."));
-
- br.close();
- try {
- br.readLine();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ready",
- args = {}
- )
- public void test_ready() throws IOException {
- Support_ASimpleReader ssr = new Support_ASimpleReader(true);
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- assertTrue("Test 1: ready() returned false", br.ready());
- } catch (java.io.IOException e) {
- fail("Exception during ready test" + e.toString());
- }
-
- br.close();
- br = new BufferedReader(ssr);
- try {
- br.close();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // Avoid IOException in tearDown().
- ssr.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.BufferedReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "The test verifies reset() method.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.BufferedReader.reset()
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.mark(900);
- br.skip(500);
- br.reset();
- char[] buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Failed to reset properly", testString.substring(500,
- 1000).equals(new String(buf, 0, 500)));
- } catch (java.io.IOException e) {
- fail("Exception during reset test");
- }
- try {
- br = new BufferedReader(new Support_StringReader(testString));
- br.skip(500);
- br.reset();
- fail("Reset succeeded on unmarked stream");
- } catch (IOException x) {
- return;
-
- }
-
- }
-
- /**
- * @tests java.io.BufferedReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- Support_ASimpleReader ssr = new Support_ASimpleReader(true);
- br = new BufferedReader(new Support_StringReader(testString));
-
- try {
- br.skip(-1);
- fail("Test 1: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- br.skip(500);
- char[] buf = new char[testString.length()];
- br.read(buf, 0, 500);
- assertTrue("Test 2: Failed to set skip properly.",
- testString.substring(500, 1000).equals(
- new String(buf, 0, 500)));
-
- br.close();
- br = new BufferedReader(ssr);
- try {
- br.skip(1);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // Avoid IOException in tearDown().
- ssr.throwExceptionOnNextUse = false;
- }
-
- public void testReadZeroLengthArray() throws IOException {
- br = new BufferedReader(new Support_StringReader("ABCDEF"));
- br.read();
- br.read();
- assertEquals(0, br.read(new char[6], 3, 0));
- }
-
- public void testSourceThrowsWithMark() throws IOException {
- br = new BufferedReader(new ThrowingReader(
- new StringReader("ABCDEFGHI"), 4));
-
- br.read();
- br.read();
- br.mark(10);
- br.read();
- br.read();
-
- try {
- br.read();
- fail();
- } catch (IOException fromThrowingReader) {
- }
-
- assertEquals('E', br.read());
- assertEquals('F', br.read());
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- br.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/BufferedWriterTest.java b/luni/src/test/java/tests/api/java/io/BufferedWriterTest.java
deleted file mode 100644
index 0d2783c..0000000
--- a/luni/src/test/java/tests/api/java/io/BufferedWriterTest.java
+++ /dev/null
@@ -1,412 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedWriter;
-import java.io.IOException;
-
-import tests.support.Support_ASimpleWriter;
-import tests.support.Support_StringWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(BufferedWriter.class)
-public class BufferedWriterTest extends junit.framework.TestCase {
-
- BufferedWriter bw;
-
- Support_StringWriter sw;
-
- Support_ASimpleWriter ssw;
-
- public String testString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.BufferedWriter#BufferedWriter(java.io.Writer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedWriter",
- args = {java.io.Writer.class}
- )
- public void test_ConstructorLjava_io_Writer() {
- bw = new BufferedWriter(sw);
- try {
- bw.write("Hi", 0, 2);
- assertTrue("Test 1: Buffering failed.", sw.toString().equals(""));
- bw.flush();
- assertEquals("Test 2: Incorrect value;", "Hi", sw.toString());
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException.");
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#BufferedWriter(java.io.Writer, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "BufferedWriter",
- args = {java.io.Writer.class, int.class}
- )
- public void test_ConstructorLjava_io_WriterI() {
- try {
- bw = new BufferedWriter(sw, 0);
- fail("Test 1: IllegalArgumentException expected.");
- } catch (IllegalArgumentException expected) {
- // Expected.
- }
-
- bw = new BufferedWriter(sw, 10);
- try {
- bw.write("Hi", 0, 2);
- assertTrue("Test 2: Buffering failed.", sw.toString().equals(""));
- bw.flush();
- assertEquals("Test 3: Incorrect value;", "Hi", sw.toString());
- } catch (IOException e) {
- fail("Test 4: Unexpected IOException.");
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.BufferedWriter.close()
- try {
- bw.close();
- bw.write(testString);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- assertFalse("Test 2: Write after close.", sw.toString().equals(testString));
-
- bw = new BufferedWriter(ssw);
- try {
- bw.close();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws IOException {
- bw.write("This should not cause a flush");
- assertTrue("Test 1: Bytes written without flush.",
- sw.toString().equals(""));
- bw.flush();
- assertEquals("Test 2: Bytes not flushed.",
- "This should not cause a flush", sw.toString());
-
- bw.close();
- bw = new BufferedWriter(ssw);
- try {
- bw.flush();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#newLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "newLine",
- args = {}
- )
- public void test_newLine() throws IOException {
- String separator = System.getProperty("line.separator");
- bw.write("Hello");
- bw.newLine();
- bw.write("World");
- bw.flush();
- assertTrue("Test 1: Incorrect string written: " + sw.toString(),
- sw.toString().equals("Hello" + separator + "World"));
-
- bw.close();
- bw = new BufferedWriter(ssw, 1);
- try {
- bw.newLine();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() {
- // Test for method void java.io.BufferedWriter.write(char [], int, int)
- try {
- char[] testCharArray = testString.toCharArray();
- bw.write(testCharArray, 500, 1000);
- bw.flush();
- assertTrue("Incorrect string written", sw.toString().equals(
- testString.substring(500, 1500)));
-
- int idx = sw.toString().length();
- bw.write(testCharArray, 0, testCharArray.length);
- assertEquals(idx + testCharArray.length, sw.toString().length());
- bw.write(testCharArray, 0, 0);
- assertEquals(idx + testCharArray.length, sw.toString().length());
- bw.write(testCharArray, testCharArray.length, 0);
- assertEquals(idx + testCharArray.length, sw.toString().length());
- } catch (Exception e) {
- fail("Exception during write test");
- }
-
- }
-
- /**
- * @tests java.io.BufferedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument tests.",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() throws IOException {
- char[] nullCharArray = null;
- char[] charArray = testString.toCharArray();
-
- try {
- bw.write(nullCharArray, 0, 1);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- bw.write(charArray, -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bw.write(charArray, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bw.write(charArray, charArray.length + 1, 0);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bw.write(charArray, charArray.length, 1);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bw.write(charArray, 0, charArray.length + 1);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- bw.write(charArray, 1, charArray.length);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- bw.close();
-
- try {
- bw.write(charArray, 0, 1);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- bw = new BufferedWriter(ssw, charArray.length / 2);
- try {
- bw.write(charArray, 0, charArray.length);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- bw.write('T');
- assertTrue("Test 1: Char written without flush.",
- sw.toString().equals(""));
- bw.flush();
- assertEquals("Test 2: Incorrect char written;",
- "T", sw.toString());
-
- bw.close();
- try {
- bw.write('E');
- fail("Test 3: IOException expected since the target writer is closed.");
- } catch (IOException e) {
- // Expected.
- }
-
- // IOException should be thrown when the buffer is full and data is
- // written out to the target writer.
- bw = new BufferedWriter(ssw, 1);
- bw.write('S');
- try {
- bw.write('T');
- fail("Test 4: IOException expected since the target writer throws it.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.BufferedWriter.write(java.lang.String,
- // int, int)
- try {
- bw.write(testString);
- bw.flush();
- assertTrue("Incorrect string written", sw.toString().equals(
- testString));
- } catch (Exception e) {
- fail("Exception during write test");
- }
- }
-
- /**
- * @tests java.io.BufferedWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checking.",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII_Exception() throws IOException {
-
- bw.write((String) null , -1, -1);
- bw.write((String) null , -1, 0);
- bw.write((String) null , 0 , -1);
- bw.write((String) null , 0 , 0);
-
- try {
- bw.write((String) null, 0, 1);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- bw.write(testString, -1, 1);
- fail("Test 2: StringIndexOutOfBoundsException expected.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- bw.write(testString, 1, testString.length());
- fail("Test 3: StringIndexOutOfBoundsException expected.");
- } catch (StringIndexOutOfBoundsException e) {
- // Expected.
- }
-
- bw.close();
-
- try {
- bw.write(testString, 0, 1);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- bw = new BufferedWriter(ssw, testString.length() / 2);
- try {
- bw.write(testString, 0, testString.length());
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- sw = new Support_StringWriter();
- ssw = new Support_ASimpleWriter(true);
- bw = new BufferedWriter(sw, 500);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- ssw.throwExceptionOnNextUse = false;
- try {
- bw.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java b/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java
deleted file mode 100644
index cf9673a..0000000
--- a/luni/src/test/java/tests/api/java/io/ByteArrayInputStreamTest.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(ByteArrayInputStream.class)
-public class ByteArrayInputStreamTest extends junit.framework.TestCase {
-
- private ByteArrayInputStream is;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- /**
- * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayInputStream",
- args = {byte[].class}
- )
- public void test_Constructor$B() {
- // Test for method java.io.ByteArrayInputStream(byte [])
-
- java.io.InputStream bis = new java.io.ByteArrayInputStream(fileString
- .getBytes());
-
- try {
- assertTrue("Unable to create ByteArrayInputStream",
- bis.available() == fileString.length());
- } catch (Exception e) {
- System.out.println("Exception during Constructor test");
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.ByteArrayInputStream#ByteArrayInputStream(byte[], int,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayInputStream",
- args = {byte[].class, int.class, int.class}
- )
- public void test_Constructor$BII() throws IOException {
- // Test for method java.io.ByteArrayInputStream(byte [], int, int)
-
- byte[] zz = fileString.getBytes();
- java.io.InputStream bis = new java.io.ByteArrayInputStream(zz, 0, 100);
-
- try {
- assertEquals("Unable to create ByteArrayInputStream",
- 100, bis.available());
- } catch (Exception e) {
- fail("Exception during Constructor test");
- }
-
- // Regression test for Harmony-2405
- new SubByteArrayInputStream(new byte[] { 1, 2 }, 444, 13);
- assertEquals(444, SubByteArrayInputStream.pos);
- assertEquals(444, SubByteArrayInputStream.mark);
- assertEquals(2, SubByteArrayInputStream.count);
- }
-
- static class SubByteArrayInputStream extends ByteArrayInputStream {
- public static byte[] buf;
-
- public static int mark, pos, count;
-
- SubByteArrayInputStream(byte[] buf, int offset, int length)
- throws IOException {
- super(buf, offset, length);
- buf = super.buf;
- mark = super.mark;
- pos = super.pos;
- count = super.count;
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies available() method.",
- method = "available",
- args = {}
- )
- public void test_available() {
- // Test for method int java.io.ByteArrayInputStream.available()
- try {
- assertTrue("Returned incorrect number of available bytes", is
- .available() == fileString.length());
- } catch (Exception e) {
- fail("Exception during available test");
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() {
- is.read();
- try {
- is.close();
- } catch (java.io.IOException e) {
- fail("Test 1: Failed to close the input stream.");
- }
- try {
- is.read();
- } catch (Exception e) {
- fail("Test 2: Should be able to read from closed stream.");
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int readAheadLimit) method.",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- // Test for method void java.io.ByteArrayInputStream.mark(int)
- byte[] buf1 = new byte[100];
- byte[] buf2 = new byte[100];
- try {
- is.skip(3000);
- is.mark(1000);
- is.read(buf1, 0, buf1.length);
- is.reset();
- is.read(buf2, 0, buf2.length);
- is.reset();
- assertTrue("Failed to mark correct position", new String(buf1, 0,
- buf1.length).equals(new String(buf2, 0, buf2.length)));
-
- } catch (Exception e) {
- fail("Exception during mark test");
- }
-
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.ByteArrayInputStream.markSupported()
- assertTrue("markSupported returned incorrect value", is.markSupported());
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read() method.",
- method = "read",
- args = {}
- )
- public void test_read() {
- // Test for method int java.io.ByteArrayInputStream.read()
- try {
-
- int c = is.read();
- is.reset();
- assertTrue("read returned incorrect char", c == fileString
- .charAt(0));
- } catch (Exception e) {
- fail("Exception during read test");
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte[] buf1 = new byte[20];
- is.skip(50);
- is.mark(100);
- is.read(buf1, 0, buf1.length);
- assertTrue("Test 1: Failed to read correct data.",
- new String(buf1, 0, buf1.length).equals(
- fileString.substring(50, 70)));
-
- // Illegal argument checks.
- try {
- is.read(null, 1, 0);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- is.read(buf1 , -1, 1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- is.read(buf1 , 1, -1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- is.read(buf1, 1, buf1.length);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "The test verifies reset() method.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.ByteArrayInputStream.reset()
- byte[] buf1 = new byte[10];
- byte[] buf2 = new byte[10];
- try {
- is.mark(200);
- is.read(buf1, 0, 10);
- is.reset();
- is.read(buf2, 0, 10);
- is.reset();
- assertTrue("Reset failed", new String(buf1, 0, buf1.length)
- .equals(new String(buf2, 0, buf2.length)));
- } catch (Exception e) {
- fail("Exception during reset test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.ByteArrayInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.ByteArrayInputStream.skip(long)
- byte[] buf1 = new byte[10];
- try {
- is.skip(100);
- is.read(buf1, 0, buf1.length);
- assertTrue("Failed to skip to correct position", new String(buf1,
- 0, buf1.length).equals(fileString.substring(100, 110)));
- } catch (Exception e) {
- fail("Exception during skip test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- is = new java.io.ByteArrayInputStream(fileString.getBytes());
-
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- try {
- is.close();
-
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java
deleted file mode 100644
index 00cf373..0000000
--- a/luni/src/test/java/tests/api/java/io/ByteArrayOutputStreamTest.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-
-import junit.framework.TestCase;
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-/**
- * Automated Test Suite for class java.io.ByteArrayOutputStream
- *
- * @see java.io.ByteArrayOutputStream
- */
-@TestTargetClass(ByteArrayOutputStream.class)
-public class ByteArrayOutputStreamTest extends TestCase {
-
- ByteArrayOutputStream bos = null;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- /**
- * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayOutputStream",
- args = {int.class}
- )
- public void test_ConstructorI() {
- bos = new java.io.ByteArrayOutputStream(100);
- assertEquals("Test 1: Failed to create stream;", 0, bos.size());
-
- try {
- bos = new ByteArrayOutputStream(-1);
- fail("Test 2: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#ByteArrayOutputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ByteArrayOutputStream",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.ByteArrayOutputStream()
- bos = new java.io.ByteArrayOutputStream();
- assertEquals("Failed to create stream", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException check since it is never thrown.",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.ByteArrayOutputStream.close()
-
- assertTrue(
- "close() does nothing for this implementation of OutputSteam",
- true);
-
- // The spec seems to say that a closed output stream can't be written
- // to. We don't throw an exception if attempt is made to write.
- // Right now our implementation doesn't do anything testable but
- // should we decide to throw an exception if a closed stream is
- // written to, the appropriate test is commented out below.
-
- /***********************************************************************
- * java.io.ByteArrayOutputStream bos = new
- * java.io.ByteArrayOutputStream(); bos.write (fileString.getBytes(), 0,
- * 100); try { bos.close(); } catch (java.io.IOException e) {
- * fail("IOException closing stream"); } try { bos.write
- * (fileString.getBytes(), 0, 100); bos.toByteArray(); fail("Wrote
- * to closed stream"); } catch (Exception e) { }
- **********************************************************************/
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.ByteArrayOutputStream.reset()
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- bos.reset();
- assertEquals("Test 1: Reset failed;", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.ByteArrayOutputStream.size()
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- assertEquals("size test failed", 100, bos.size());
- bos.reset();
- assertEquals("size test failed", 0, bos.size());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toByteArray()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toByteArray() method.",
- method = "toByteArray",
- args = {}
- )
- public void test_toByteArray() {
- // Test for method byte [] java.io.ByteArrayOutputStream.toByteArray()
- byte[] bytes;
- byte[] sbytes = fileString.getBytes();
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- bytes = bos.toByteArray();
- for (int i = 0; i < fileString.length(); i++) {
- assertTrue("Error in byte array", bytes[i] == sbytes[i]);
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "toString",
- args = {java.lang.String.class}
- )
- public void test_toStringLjava_lang_String() throws Exception {
- bos = new ByteArrayOutputStream();
-
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Test 1: Returned incorrect 8859-1 String",
- bos.toString("8859_1").equals(fileString));
- assertTrue("Test 2: Returned incorrect 8859-2 String",
- bos.toString("8859_2").equals(fileString));
-
- try {
- bos.toString("NotAnEcoding");
- fail("Test 3: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String
- // java.io.ByteArrayOutputStream.toString()
- java.io.ByteArrayOutputStream bos = null;
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Returned incorrect String", bos.toString().equals(
- fileString));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#toString(int)
- */
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString(int hibyte) method.",
- method = "toString",
- args = {int.class}
- )
- public void test_toStringI() {
- // Test for method java.lang.String
- // java.io.ByteArrayOutputStream.toString(int)
- java.io.ByteArrayOutputStream bos = null;
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, fileString.length());
- assertTrue("Returned incorrect String",
- bos.toString(5).length() == fileString.length());
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.ByteArrayOutputStream.write(int)
- bos = new java.io.ByteArrayOutputStream();
- bos.write('t');
- byte[] result = bos.toByteArray();
- assertEquals("Wrote incorrect bytes",
- "t", new String(result, 0, result.length));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() {
- // Test for method void java.io.ByteArrayOutputStream.write(byte [],
- // int, int)
- java.io.ByteArrayOutputStream bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 100);
- byte[] result = bos.toByteArray();
- assertTrue("Wrote incorrect bytes",
- new String(result, 0, result.length).equals(fileString
- .substring(0, 100)));
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII_Exception() {
- byte[] target = new byte[10];
- bos = new ByteArrayOutputStream();
- try {
- bos.write(target, -1, 1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(target, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(target, 1, target.length);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- bos.write(null, 1, 1);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ByteArrayOutputStream#writeTo(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeTo",
- args = {java.io.OutputStream.class}
- )
- public void test_writeToLjava_io_OutputStream() throws Exception {
- Support_OutputStream sos = new Support_OutputStream();
- bos = new java.io.ByteArrayOutputStream();
- bos.write(fileString.getBytes(), 0, 10);
- bos.writeTo(sos);
- assertTrue("Test 1: Incorrect string written.",
- sos.toString().equals(
- fileString.substring(0, 10)));
-
- sos.setThrowsException(true);
- try {
- bos.writeTo(sos);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java b/luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java
deleted file mode 100644
index 95d3734..0000000
--- a/luni/src/test/java/tests/api/java/io/CharArrayReaderTest.java
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.CharArrayReader;
-import java.io.IOException;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharArrayReader.class)
-public class CharArrayReaderTest extends junit.framework.TestCase {
-
- char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
-
- CharArrayReader cr;
-
- /**
- * @tests java.io.CharArrayReader#CharArrayReader(char[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies CharArrayReader(char[] buf) constructor.",
- method = "CharArrayReader",
- args = {char[].class}
- )
- public void test_Constructor$C() {
- // Test for method java.io.CharArrayReader(char [])
-
- try {
- cr = new CharArrayReader(hw);
- assertTrue("Failed to create reader", cr.ready());
- } catch (IOException e) {
- fail("Exception determining ready state : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayReader#CharArrayReader(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharArrayReader",
- args = {char[].class, int.class, int.class}
- )
- public void test_Constructor$CII() throws IOException {
- try {
- cr = new CharArrayReader(null, 0, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- try {
- cr = new CharArrayReader(hw, -1, 0);
- fail("Test 2: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- try {
- cr = new CharArrayReader(hw, 0, -1);
- fail("Test 3: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- try {
- cr = new CharArrayReader(hw, hw.length + 1, 1);
- fail("Test 4: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- cr = new CharArrayReader(hw, 5, 5);
- assertTrue("Test 5: Failed to create reader", cr.ready());
- assertEquals("Test 6: Incorrect character read;",
- 'W', cr.read());
- }
-
- /**
- * @tests java.io.CharArrayReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close() method.",
- method = "close",
- args = {}
- )
- public void test_close() {
- cr = new CharArrayReader(hw);
- cr.close();
- try {
- cr.read();
- fail("Failed to throw exception on read from closed stream");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- /**
- * @tests java.io.CharArrayReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- // Test for method void java.io.CharArrayReader.mark(int)
- cr = new CharArrayReader(hw);
- cr.skip(5L);
- cr.mark(100);
- cr.read();
- cr.reset();
- assertEquals("Test 1: Failed to mark correct position;",
- 'W', cr.read());
-
- cr.close();
- try {
- cr.mark(100);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.CharArrayReader.markSupported()
- cr = new CharArrayReader(hw);
- assertTrue("markSupported returned false", cr.markSupported());
- }
-
- /**
- * @tests java.io.CharArrayReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- cr = new CharArrayReader(hw);
- assertEquals("Test 1: Read returned incorrect char;",
- 'H', cr.read());
- cr = new CharArrayReader(new char[] { '\u8765' });
- assertTrue("Test 2: Incorrect double byte char;",
- cr.read() == '\u8765');
-
- cr.close();
- try {
- cr.read();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- @AndroidOnly("The RI throws an IndexOutOfBoundsException instead of an" +
- "ArrayIndexOutOfBoundsException. The RI specification does not" +
- "define the expected behavior.")
- public void test_read$CII() throws IOException {
- // Test for method int java.io.CharArrayReader.read(char [], int, int)
- char[] c = new char[11];
- cr = new CharArrayReader(hw);
- cr.read(c, 1, 10);
- assertTrue("Test 1: Read returned incorrect chars.",
- new String(c, 1, 10).equals(new String(hw, 0, 10)));
-
- // Illegal argument checks.
- try {
- cr.read(null, 1, 0);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- cr.read(c , -1, 1);
- fail("Test 3: ArrayIndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- cr.read(c , 1, -1);
- fail("Test 4: ArrayIndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- cr.read(c, 1, c.length);
- fail("Test 5: ArrayIndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- cr.close();
- try {
- cr.read(c, 1, 1);
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ready() method.",
- method = "ready",
- args = {}
- )
- public void test_ready() {
- // Test for method boolean java.io.CharArrayReader.ready()
- cr = new CharArrayReader(hw);
- boolean expectException = false;
- try {
- assertTrue("ready returned false", cr.ready());
- cr.skip(1000);
- assertTrue("ready returned true", !cr.ready());
- cr.close();
- expectException = true;
- cr.ready();
- fail("No exception 1");
- } catch (IOException e) {
- if (!expectException)
- fail("Unexpected: " + e);
- }
- try {
- cr = new CharArrayReader(hw);
- cr.close();
- cr.ready();
- fail("No exception 2");
- } catch (IOException e) {
- }
-
- }
-
- /**
- * @tests java.io.CharArrayReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- cr = new CharArrayReader(hw);
- cr.skip(5L);
- cr.mark(100);
- cr.read();
- cr.reset();
- assertEquals("Test 1: Reset failed to return to marker position.",
- 'W', cr.read());
-
- cr.close();
- try {
- cr.reset();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- long skipped = 0;
- cr = new CharArrayReader(hw);
- skipped = cr.skip(5L);
- assertEquals("Test 1: Failed to skip correct number of chars;",
- 5L, skipped);
- assertEquals("Test 2: Skip skipped wrong chars;",
- 'W', cr.read());
-
- cr.close();
- try {
- cr.skip(1);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- if (cr != null)
- cr.close();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java b/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
deleted file mode 100644
index 692c043..0000000
--- a/luni/src/test/java/tests/api/java/io/CharArrayWriterTest.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.CharArrayReader;
-import java.io.CharArrayWriter;
-import java.io.IOException;
-import java.io.StringWriter;
-
-import tests.support.Support_ASimpleWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharArrayWriter.class)
-public class CharArrayWriterTest extends junit.framework.TestCase {
-
- char[] hw = { 'H', 'e', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd' };
-
- CharArrayWriter cw;
-
- CharArrayReader cr;
-
- /**
- * @tests java.io.CharArrayWriter#CharArrayWriter(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharArrayWriter",
- args = {int.class}
- )
- public void test_ConstructorI() {
- // Test for method java.io.CharArrayWriter(int)
- cw = new CharArrayWriter(90);
- assertEquals("Test 1: Incorrect writer created.", 0, cw.size());
-
- try {
- cw = new CharArrayWriter(-1);
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#CharArrayWriter()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies CharArrayWriter() method.",
- method = "CharArrayWriter",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.CharArrayWriter()
- cw = new CharArrayWriter();
- assertEquals("Created incorrect writer", 0, cw.size());
- }
-
- /**
- * @tests java.io.CharArrayWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close() method.",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.CharArrayWriter.close()
- cw.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies flush() method.",
- method = "flush",
- args = {}
- )
- public void test_flush() {
- // Test for method void java.io.CharArrayWriter.flush()
- cw.flush();
- }
-
- /**
- * @tests java.io.CharArrayWriter#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() method.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.CharArrayWriter.reset()
- cw.write("HelloWorld", 5, 5);
- cw.reset();
- cw.write("HelloWorld", 0, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Reset failed to reset buffer",
- "Hello", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during reset test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.CharArrayWriter.size()
- assertEquals("Returned incorrect size", 0, cw.size());
- cw.write(hw, 5, 5);
- assertEquals("Returned incorrect size", 5, cw.size());
- }
-
- /**
- * @tests java.io.CharArrayWriter#toCharArray()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toCharArray() method.",
- method = "toCharArray",
- args = {}
- )
- public void test_toCharArray() {
- // Test for method char [] java.io.CharArrayWriter.toCharArray()
- cw.write("HelloWorld", 0, 10);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 10);
- assertEquals("toCharArray failed to return correct array",
- "HelloWorld", new String(c, 0, 10));
- } catch (IOException e) {
- fail("Exception during toCharArray test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.CharArrayWriter.toString()
- cw.write("HelloWorld", 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- assertEquals("Returned incorrect string",
- "World", cw.toString());
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() {
- // Test for method void java.io.CharArrayWriter.write(char [], int, int)
- cw.write(hw, 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Writer failed to write correct chars",
- "World", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(char[], int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() {
- char[] target = new char[10];
- cw = new CharArrayWriter();
- try {
- cw.write(target, -1, 1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write(target, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write(target, 1, target.length);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- cw.write((char[]) null, 1, 1);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(int) method.",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.CharArrayWriter.write(int)
- cw.write('T');
- cr = new CharArrayReader(cw.toCharArray());
- try {
- assertEquals("Writer failed to write char", 'T', cr.read());
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(java.lang.String, int, int) method. [Need to check different strings?]",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.CharArrayWriter.write(java.lang.String,
- // int, int)
- cw.write("HelloWorld", 5, 5);
- cr = new CharArrayReader(cw.toCharArray());
- try {
- char[] c = new char[100];
- cr.read(c, 0, 5);
- assertEquals("Writer failed to write correct chars",
- "World", new String(c, 0, 5));
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#write(java.lang.String, int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression for write(java.lang.String, int, int) method.",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII_2() throws StringIndexOutOfBoundsException {
- CharArrayWriter obj = new CharArrayWriter();
- try {
- obj.write((String) null, -1, 0);
- fail("NullPointerException expected");
- } catch (NullPointerException t) {
- }
- }
-
- /**
- * @tests java.io.CharArrayWriter#writeTo(java.io.Writer)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeTo",
- args = {java.io.Writer.class}
- )
- public void test_writeToLjava_io_Writer() {
- Support_ASimpleWriter ssw = new Support_ASimpleWriter(true);
- cw.write("HelloWorld", 0, 10);
- StringWriter sw = new StringWriter();
- try {
- cw.writeTo(sw);
- assertEquals("Test 1: Writer failed to write correct chars;",
- "HelloWorld", sw.toString());
- } catch (IOException e) {
- fail("Exception during writeTo test : " + e.getMessage());
- }
-
- try {
- cw.writeTo(ssw);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- cw = new CharArrayWriter();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- if (cr != null)
- cr.close();
- cw.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies append(char c) method.",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- CharArrayWriter writer = new CharArrayWriter(10);
- writer.append(testChar);
- writer.flush();
- assertEquals(String.valueOf(testChar), writer.toString());
- writer.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies append(CharSequence csq) method.",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() {
-
- String testString = "My Test String";
- CharArrayWriter writer = new CharArrayWriter(10);
- writer.append(testString);
- writer.flush();
- assertEquals(testString, writer.toString());
- writer.close();
- }
-
- /**
- * @tests java.io.CharArrayWriter#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_appendLjava_langCharSequenceII() {
- String testString = "My Test String";
- CharArrayWriter writer = new CharArrayWriter(10);
-
- // Illegal argument checks.
- try {
- writer.append(testString, -1, 0);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 1, 0);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- writer.append(testString, 1, testString.length() + 1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- writer.append(testString, 1, 3);
- writer.flush();
- assertEquals("Test 5: Appending failed;",
- testString.substring(1, 3), writer.toString());
- writer.close();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java b/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java
deleted file mode 100644
index 537ab77..0000000
--- a/luni/src/test/java/tests/api/java/io/CharConversionExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.CharConversionException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(CharConversionException.class)
-public class CharConversionExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.CharConversionException#CharConversionException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharConversionException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new CharConversionException();
- fail("Test 1: CharConversionException expected.");
- } catch (CharConversionException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.CharConversionException#CharConversionException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "CharConversionException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new CharConversionException("Something went wrong.");
- fail("Test 1: CharConversionException expected.");
- } catch (CharConversionException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java
deleted file mode 100644
index 7d8d6a1..0000000
--- a/luni/src/test/java/tests/api/java/io/DataInputOutputStreamTest.java
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.IOException;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(DataOutputStream.class)
-public class DataInputOutputStreamTest extends junit.framework.TestCase {
-
- private DataOutputStream os;
-
- private DataInputStream dis;
-
- private Support_OutputStream sos;
-
- String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
-
- /**
- * @tests java.io.DataInputStream#readBoolean()
- * @tests java.io.DataOutputStream#writeBoolean(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeBoolean",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readBoolean",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeBoolean() throws IOException {
- os.writeBoolean(true);
- sos.setThrowsException(true);
- try {
- os.writeBoolean(false);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertTrue("Test 2: Incorrect boolean written or read.",
- dis.readBoolean());
-
- try {
- dis.readBoolean();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readBoolean();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readByte()
- * @tests java.io.DataOutputStream#writeByte(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeByte",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readByte",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeByte() throws IOException {
- os.writeByte((byte) 127);
- sos.setThrowsException(true);
- try {
- os.writeByte((byte) 127);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 2: Incorrect byte written or read;",
- (byte) 127, dis.readByte());
-
- try {
- dis.readByte();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readByte();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readChar()
- * @tests java.io.DataOutputStream#writeChar(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readChar",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeChar() throws IOException {
- os.writeChar('b');
- sos.setThrowsException(true);
- try {
- os.writeChar('k');
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 2: Incorrect char written or read;",
- 'b', dis.readChar());
-
- try {
- dis.readChar();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readChar();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readDouble()
- * @tests java.io.DataOutputStream#writeDouble(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeDouble",
- args = {double.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readDouble",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeDouble() throws IOException {
- os.writeDouble(2345.76834720202);
- sos.setThrowsException(true);
- try {
- os.writeDouble(2345.76834720202);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 1: Incorrect double written or read;",
- 2345.76834720202, dis.readDouble());
-
- try {
- dis.readDouble();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readDouble();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readFloat()
- * @tests java.io.DataOutputStream#writeFloat(float)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeFloat",
- args = {float.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFloat",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeFloat() throws IOException {
- os.writeFloat(29.08764f);
- sos.setThrowsException(true);
- try {
- os.writeFloat(29.08764f);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 2: Incorrect float written or read;",
- 29.08764f, dis.readFloat());
-
- try {
- dis.readFloat();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readFloat();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readInt()
- * @tests java.io.DataOutputStream#writeInt(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readInt",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeInt() throws IOException {
- os.writeInt(768347202);
- sos.setThrowsException(true);
- try {
- os.writeInt(768347202);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 1: Incorrect int written or read;",
- 768347202, dis.readInt());
-
- try {
- dis.readInt();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readInt();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readLong()
- * @tests java.io.DataOutputStream#writeLong(long)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeLong",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readLong",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeLong() throws IOException {
- os.writeLong(9875645283333L);
- sos.setThrowsException(true);
- try {
- os.writeLong(9875645283333L);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 2: Incorrect long written or read;",
- 9875645283333L, dis.readLong());
-
- try {
- dis.readLong();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readLong();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readShort()
- * @tests java.io.DataOutputStream#writeShort(short)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeShort",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readShort",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeShort() throws IOException {
- os.writeShort(9875);
- sos.setThrowsException(true);
- try {
- os.writeShort(9875);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertEquals("Test 1: Incorrect short written or read;",
- 9875, dis.readShort());
-
- try {
- dis.readShort();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readShort();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
-
- /**
- * @tests java.io.DataInputStream#readUTF()
- * @tests java.io.DataOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeUTF",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUTF",
- args = {},
- clazz = DataInputStream.class
- )
- })
- public void test_read_writeUTF() throws IOException {
- os.writeUTF(unihw);
- sos.setThrowsException(true);
- try {
- os.writeUTF(unihw);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- os.close();
- openDataInputStream();
- assertTrue("Test 1: Incorrect UTF-8 string written or read.",
- dis.readUTF().equals(unihw));
-
- try {
- dis.readUTF();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readUTF();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- private void openDataInputStream() throws IOException {
- dis = new DataInputStream(new ByteArrayInputStream(sos.toByteArray()));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- sos = new Support_OutputStream(256);
- os = new DataOutputStream(sos);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- dis.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/DataInputStreamTest.java b/luni/src/test/java/tests/api/java/io/DataInputStreamTest.java
deleted file mode 100644
index 08dcb77..0000000
--- a/luni/src/test/java/tests/api/java/io/DataInputStreamTest.java
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.IOException;
-
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(DataInputStream.class)
-public class DataInputStreamTest extends junit.framework.TestCase {
-
- private DataOutputStream os;
-
- private DataInputStream dis;
-
- private ByteArrayOutputStream bos;
-
- String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_DataInputStream\n";
-
- private final int testLength = fileString.length();
-
- /**
- * @tests java.io.DataInputStream#DataInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies DataInputStream(java.io.InputStream) constructor.",
- method = "DataInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.DataInputStream(java.io.InputStream)
- try {
- os.writeChar('t');
- os.close();
- openDataInputStream();
- } catch (IOException e) {
- fail("IOException during constructor test : " + e.getMessage());
- } finally {
- try {
- dis.close();
- } catch (IOException e) {
- fail("IOException during constructor test : " + e.getMessage());
- }
- }
- }
-
- /**
- * @tests java.io.DataInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
- public void test_read$B() throws IOException {
- byte rbytes[] = new byte[testLength - 5];
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
- int r;
-
- os.write(fileString.getBytes());
- os.close();
- openDataInputStream();
-
- r = dis.read(rbytes);
- assertEquals("Test 1: Incorrect number of bytes read;",
- testLength - 5, r);
- assertTrue("Test 2: Incorrect data written or read.",
- new String(rbytes).equals(fileString.substring(0, testLength - 5)));
-
- r = dis.read(rbytes);
- assertEquals("Test 3: Incorrect number of bytes read;", 5, r);
- assertTrue("Test 4: Incorrect data written or read.",
- new String(rbytes, 0, 5).equals(fileString.substring(testLength - 5)));
-
- dis.close();
- sis.throwExceptionOnNextUse = true;
- dis = new DataInputStream(sis);
- try {
- dis.read(rbytes);
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte rbytes[] = new byte[testLength - 5];
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
- int r;
-
- os.write(fileString.getBytes());
- os.close();
- openDataInputStream();
-
- r = dis.read(rbytes, 1, testLength - 10);
- assertEquals("Test 1: Incorrect number of bytes read;",
- testLength - 10, r);
- assertEquals("Test 2: Incorrect data read.", 0, rbytes[0]);
- assertTrue("Test 3: Incorrect data written or read.",
- new String(rbytes, 1, r).equals(fileString.substring(0, r)));
-
- r = dis.read(rbytes, 0, 15);
- assertEquals("Test 3: Incorrect number of bytes read;", 10, r);
- assertTrue("Test 4: Incorrect data written or read.",
- new String(rbytes, 0, r).equals(fileString.substring(testLength - 10)));
-
- dis.close();
- sis.throwExceptionOnNextUse = true;
- dis = new DataInputStream(sis);
- try {
- dis.read(rbytes, 1, 5);
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte rbytes[] = new byte[testLength - 5];
-
- os.write(fileString.getBytes());
- os.close();
- openDataInputStream();
-
- try {
- dis.read(rbytes, -1, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- dis.read(rbytes, 0, -1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- dis.read(rbytes, rbytes.length, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readFully",
- args = {byte[].class}
- )
- public void test_readFully$B() throws IOException {
- byte rbytes[] = new byte[testLength];
-
- os.write(fileString.getBytes());
- os.close();
- openDataInputStream();
-
- dis.readFully(rbytes);
- assertTrue("Test 1: Incorrect data written or read.",
- new String(rbytes, 0, testLength).equals(fileString));
-
- dis.close();
- try {
- dis.readFully(rbytes);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- openDataInputStream();
- dis.readByte();
- try {
- dis.readFully(rbytes);
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies everything except illegal argument values.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
- public void test_readFully$BII() throws IOException {
- byte rbytes[] = new byte[testLength];
-
- os.write(fileString.getBytes());
- os.close();
- openDataInputStream();
-
- dis.readFully(rbytes, 2, testLength - 4);
- assertTrue("Test 1: Incorrect data written or read.",
- new String(rbytes, 2, testLength - 4).equals(
- fileString.substring(0, testLength - 4)));
-
- dis.close();
- try {
- dis.readFully(rbytes, 0, testLength);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- openDataInputStream();
- dis.readByte();
- try {
- dis.readFully(rbytes, 0, testLength);
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that exceptions are thrown for illegal arguments.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
- public void test_readFully$BII_Exception() throws IOException {
- DataInputStream is = new DataInputStream(new ByteArrayInputStream(new byte[testLength]));
-
- byte[] byteArray = new byte[testLength];
-
- try {
- is.readFully(byteArray, 0, -1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.readFully(byteArray, 0, byteArray.length + 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.readFully(byteArray, 1, byteArray.length);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.readFully(byteArray, -1, byteArray.length);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.readFully(null, 0, 1);
- fail("Test 5: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- is = new DataInputStream(null);
-
- try {
- is.readFully(byteArray, 0, 1);
- fail("Test 6: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readLine()
- */
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
- public void test_readLine() throws IOException {
- String line;
- os.writeBytes("Lorem\nipsum\rdolor sit amet...");
- os.close();
- openDataInputStream();
- line = dis.readLine();
- assertTrue("Test 1: Incorrect line written or read: " + line,
- line.equals("Lorem"));
- line = dis.readLine();
- assertTrue("Test 2: Incorrect line written or read: " + line,
- line.equals("ipsum"));
- line = dis.readLine();
- assertTrue("Test 3: Incorrect line written or read: " + line,
- line.equals("dolor sit amet..."));
-
- dis.close();
- try {
- dis.readLine();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readUnsignedByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedByte",
- args = {}
- )
- public void test_readUnsignedByte() throws IOException {
- os.writeByte((byte) -127);
- os.close();
- openDataInputStream();
- assertEquals("Test 1: Incorrect byte written or read;",
- 129, dis.readUnsignedByte());
-
- try {
- dis.readUnsignedByte();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readUnsignedByte();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readUnsignedShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedShort",
- args = {}
- )
- public void test_readUnsignedShort() throws IOException {
- os.writeShort(Short.MIN_VALUE);
- os.close();
- openDataInputStream();
- assertEquals("Test 1: Incorrect short written or read;",
- (Short.MAX_VALUE + 1), dis.readUnsignedShort());
-
- try {
- dis.readUnsignedShort();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- dis.readUnsignedShort();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#readUTF(java.io.DataInput)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUTF",
- args = {java.io.DataInput.class}
- )
- public void test_readUTFLjava_io_DataInput() throws IOException {
- os.writeUTF(unihw);
- os.close();
- openDataInputStream();
- assertTrue("Test 1: Incorrect UTF-8 string written or read.",
- DataInputStream.readUTF(dis).equals(unihw));
-
- try {
- DataInputStream.readUTF(dis);
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- dis.close();
- try {
- DataInputStream.readUTF(dis);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skipBytes",
- args = {int.class}
- )
- public void test_skipBytesI() {
- // Test for method int java.io.DataInputStream.skipBytes(int)
- try {
- byte fileBytes[] = fileString.getBytes();
- os.write(fileBytes);
- os.close();
- openDataInputStream();
- dis.skipBytes(100);
- byte rbytes[] = new byte[testLength];
- dis.read(rbytes, 0, 50);
- dis.close();
- assertTrue("Incorrect data read", new String(rbytes, 0, 50)
- .equals(fileString.substring(100, 150)));
- } catch (IOException e) {
- fail("IOException during skipBytes test 1 : " + e.getMessage());
- }
- try {
- // boolean eofException = false; //what is this var for?
- int skipped = 0;
- openDataInputStream();
- try {
- skipped = dis.skipBytes(50000);
- } catch (EOFException e) {
- // eofException = true;
- }
- ;
- assertTrue("Skipped should report " + testLength + " not "
- + skipped, skipped == testLength);
- } catch (IOException e) {
- fail("IOException during skipBytes test 2 : " + e.getMessage());
- }
- }
-
- private void openDataInputStream() throws IOException {
- dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- bos = new ByteArrayOutputStream();
- os = new DataOutputStream(bos);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- dis.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java
deleted file mode 100644
index 9325b91..0000000
--- a/luni/src/test/java/tests/api/java/io/DataOutputStreamTest.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = DataOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- level = TestLevel.NOT_NECESSARY,
- notes = "Implicitely tested in setUp().",
- method = "DataOutputStream",
- args = {java.io.OutputStream.class}
- )
- }
-)
-public class DataOutputStreamTest extends junit.framework.TestCase {
-
- private DataOutputStream os;
-
- private DataInputStream dis;
-
- private ByteArrayOutputStream bos;
-
- private Support_OutputStream sos;
-
- String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
-
- private static final String testString = "Lorem ipsum dolor sit amet,\n" +
- "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
- "labore et dolore magna aliqua.\n";
-
- private static final int testLength = testString.length();
-
- /**
- * @tests java.io.DataOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws IOException {
- BufferedOutputStream buf = new BufferedOutputStream(bos);
-
- os = new DataOutputStream(buf);
- os.writeInt(9087589);
- assertTrue("Test 1: Written data should not be available.",
- bos.toByteArray().length == 0);
- os.flush();
- assertTrue("Test 2: Written data should be available.",
- bos.toByteArray().length > 0);
- os.close();
-
- openDataInputStream();
- int c = dis.readInt();
- assertEquals("Test 3: Failed to flush correctly;", 9087589, c);
- dis.close();
-
- os = new DataOutputStream(sos);
- try {
- os.flush();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#size()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies size() method.",
- method = "size",
- args = {}
- )
- public void test_size() {
- // Test for method int java.io.DataOutputStream.size()
-
- try {
- os.write(testString.getBytes(), 0, testLength / 2);
- os.close();
- assertEquals("Incorrect size returned", testLength / 2, os.size());
- openDataInputStream();
- byte[] rbuf = new byte[testLength / 2];
- dis.read(rbuf, 0, testLength / 2);
- dis.close();
- } catch (IOException e) {
- fail("Exception during write test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws IOException {
- int r;
- os.write(testString.getBytes(), 5, testLength - 7);
- os.close();
- openDataInputStream();
- byte[] rbuf = new byte[testLength];
- r = dis.read(rbuf, 0, testLength);
- assertEquals("Test 1: Incorrect number of bytes read;",
- testLength - 7, r);
- dis.close();
- assertTrue("Test 2: Incorrect bytes written or read.",
- new String(rbuf, 0, r).equals(
- testString.substring(5, testLength - 2)));
- }
-
- /**
- * @tests java.io.DataOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII_Exception() throws IOException {
- byte[] nullByteArray = null;
- byte[] byteArray = new byte[10];
-
- try {
- os.write(nullByteArray, 0, 1);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- os.write(byteArray, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- os.write(byteArray, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- os.write(byteArray, 1, 10);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- os.write(42);
- os.close();
-
- openDataInputStream();
- assertEquals("Test 1: Incorrect int written or read;",
- 42, dis.read());
- dis.close();
-
- os = new DataOutputStream(sos);
- try {
- os.write(42);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#writeBytes(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeBytes",
- args = {java.lang.String.class}
- )
- public void test_writeBytesLjava_lang_String() throws IOException {
- os.writeBytes(testString);
- os.close();
-
- openDataInputStream();
- byte[] rbuf = new byte[testLength];
- dis.read(rbuf, 0, testLength);
- dis.close();
- assertTrue("Test 1: Incorrect bytes written or read.",
- new String(rbuf, 0, testLength).equals(testString));
-
- os = new DataOutputStream(sos);
- try {
- os.writeBytes(testString);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.DataOutputStream#writeChars(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "writeChars",
- args = {java.lang.String.class}
- )
- public void test_writeCharsLjava_lang_String() throws IOException {
- os.writeChars(unihw);
- os.close();
- openDataInputStream();
- char[] chars = new char[unihw.length()];
- int i, a = dis.available() / 2;
- for (i = 0; i < a; i++) chars[i] = dis.readChar();
- assertEquals("Test 1: Incorrect chars written or read;",
- unihw, new String(chars, 0, i)
- );
- dis.close();
-
- os = new DataOutputStream(sos);
- try {
- os.writeChars(unihw);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- private void openDataInputStream() throws IOException {
- dis = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- sos = new Support_OutputStream(true);
- bos = new ByteArrayOutputStream();
- os = new DataOutputStream(bos);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- sos.setThrowsException(false);
- try {
- if (os != null)
- os.close();
- if (dis != null)
- dis.close();
- } catch (IOException e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java b/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java
deleted file mode 100644
index 0144134..0000000
--- a/luni/src/test/java/tests/api/java/io/EOFExceptionTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-
-@TestTargetClass(EOFException.class)
-public class EOFExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.EOFException#EOFException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "EOFException",
- args = {}
- )
- public void test_Constructor() {
- try {
- new DataInputStream(new ByteArrayInputStream(new byte[1]))
- .readShort();
- fail("Test 1: EOFException expected.");
- } catch (EOFException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- } catch (Exception e) {
- fail("Test 3: Unexpected exception: " + e.toString());
- }
- }
-
- /**
- * @tests java.io.EOFException#EOFException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "EOFException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new EOFException("Something went wrong.");
- fail("Test 1: EOFException expected.");
- } catch (EOFException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ExternalizableTest.java b/luni/src/test/java/tests/api/java/io/ExternalizableTest.java
deleted file mode 100644
index 4c6d033..0000000
--- a/luni/src/test/java/tests/api/java/io/ExternalizableTest.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.Externalizable;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = Externalizable.class,
- untestedMethods = {
- @TestTargetNew(
- method = "readExternal",
- args = {ObjectInput.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- ),
- @TestTargetNew(
- method = "writeExternal",
- args = {ObjectOutput.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class ExternalizableTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java b/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
deleted file mode 100644
index e7a2ac4..0000000
--- a/luni/src/test/java/tests/api/java/io/FileDescriptorTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.RandomAccessFile;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileDescriptor.class)
-public class FileDescriptorTest extends junit.framework.TestCase {
-
- private static String platformId = "JDK"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- FileOutputStream fos;
-
- BufferedOutputStream os;
-
- FileInputStream fis;
-
- File f;
-
- /**
- * @tests java.io.FileDescriptor#FileDescriptor()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileDescriptor",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.FileDescriptor()
- FileDescriptor fd = new FileDescriptor();
- assertTrue("Failed to create FileDescriptor",
- fd instanceof FileDescriptor);
- }
-
- /**
- * @tests java.io.FileDescriptor#sync()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "SyncFailedException not checked since it is only thrown" +
- "by the native implementation of sync().",
- method = "sync",
- args = {}
- )
- public void test_sync() throws Exception {
- // Test for method void java.io.FileDescriptor.sync()
- f = File.createTempFile("fd" + platformId, ".tst");
- f.delete();
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fis = new FileInputStream(f.getPath());
- FileDescriptor fd = fos.getFD();
- fd.sync();
- int length = "Test String".length();
- assertEquals("Bytes were not written after sync", length, fis
- .available());
-
- // Regression test for Harmony-1494
- fd = fis.getFD();
- fd.sync();
- assertEquals("Bytes were not written after sync", length, fis
- .available());
-
- RandomAccessFile raf = new RandomAccessFile(f, "r");
- fd = raf.getFD();
- fd.sync();
- raf.close();
- }
-
- /**
- * @tests java.io.FileDescriptor#valid()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "valid",
- args = {}
- )
- public void test_valid() {
- // Test for method boolean java.io.FileDescriptor.valid()
- try {
- f = new File(System.getProperty("java.io.tmpdir"), "fd.tst");
- f.delete();
- os = new BufferedOutputStream(fos = new FileOutputStream(f
- .getPath()), 4096);
- FileDescriptor fd = fos.getFD();
- assertTrue("Valid fd returned false", fd.valid());
- os.close();
- assertTrue("Invalid fd returned true", !fd.valid());
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
-
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- fis.close();
- } catch (Exception e) {
- }
- try {
- fos.close();
- } catch (Exception e) {
- }
- try {
- f.delete();
- } catch (Exception e) {
- }
- }
-
- protected void doneSuite() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileFilterTest.java b/luni/src/test/java/tests/api/java/io/FileFilterTest.java
deleted file mode 100644
index 68bafc8..0000000
--- a/luni/src/test/java/tests/api/java/io/FileFilterTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileFilter;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileFilter.class,
- untestedMethods = {
- @TestTargetNew(
- method = "accept",
- args = {File.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class FileFilterTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java b/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
deleted file mode 100644
index 2296f26..0000000
--- a/luni/src/test/java/tests/api/java/io/FileInputStreamTest.java
+++ /dev/null
@@ -1,511 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.channels.FileChannel;
-
-import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileInputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "finalize",
- args = {},
- level = TestLevel.NOT_FEASIBLE,
- notes = "Hard to test since it requires that the " +
- "garbage collector runs; add test later."
- )
- }
-)
-public class FileInputStreamTest extends junit.framework.TestCase {
-
- public String fileName;
-
- private FileInputStream is;
-
- byte[] ibuf = new byte[4096];
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests FileInputStream#FileInputStream(File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method FileInputStream(File)
- try {
- File f = new File(fileName);
- is = new FileInputStream(f);
- is.close();
- } catch (Exception e) {
- fail("Failed to create FileInputStream : " + e.getMessage());
- }
- File f2 = new File("ImprobableFile.42");
- try {
- is = new FileInputStream(f2);
- is.close();
- f2.delete();
- fail("FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#FileInputStream(FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method FileInputStream(FileDescriptor)
- try {
- FileOutputStream fos = new FileOutputStream(fileName);
- FileInputStream fis = new FileInputStream(fos.getFD());
- fos.close();
- fis.close();
- } catch (Exception e) {
- fail("Exception during constrcutor test: " + e.toString());
- }
- try {
- FileInputStream fis = new FileInputStream((FileDescriptor) null);
- fis.close();
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#FileInputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileInputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method FileInputStream(java.lang.String)
- try {
- is = new FileInputStream(fileName);
- is.close();
- } catch (Exception e) {
- fail("Failed to create FileInputStream : " + e.getMessage());
- }
- try {
- is = new FileInputStream("ImprobableFile.42");
- is.close();
- new File("ImprobableFile.42").delete();
- fail("FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- is = new FileInputStream(fileName);
- assertEquals("Test 1: Returned incorrect number of available bytes;",
- fileString.length(), is.available());
- is.close();
- try {
- is.available();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException test since this is only thrown" +
- "by a native method.",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- is = new FileInputStream(fileName);
- is.close();
-
- try {
- is.read();
- fail("Test 1: Read from closed stream succeeded.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#getChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getChannel",
- args = {}
- )
- public void test_getChannel() {
- // Test for method FileChannel FileInputStream.getChannel()
- FileChannel channel;
- byte[] buffer = new byte[100];
- byte[] stringBytes;
- final int offset = 5;
- boolean equal = true;
-
- try {
- FileInputStream fis = new FileInputStream(fileName);
- channel = fis.getChannel();
- assertNotNull(channel);
- assertTrue("Channel is closed.", channel.isOpen());
-
- // Check that the channel is associated with the input stream.
- channel.position(offset);
- fis.read(buffer, 0, 10);
- stringBytes = fileString.getBytes();
- for (int i = 0; i < 10; i++) {
- equal &= (buffer[i] == stringBytes[i + offset]);
- }
- assertTrue("Channel is not associated with this stream.", equal);
-
- fis.close();
- assertFalse("Channel has not been closed.", channel.isOpen());
- } catch (FileNotFoundException e) {
- fail("Could not find : " + fileName);
- }
-
- catch (IOException e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#getFD()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException check since it is never thrown.",
- method = "getFD",
- args = {}
- )
- public void test_getFD() {
- // Test for method FileDescriptor
- // FileInputStream.getFD()
- try {
-
- FileInputStream fis = new FileInputStream(fileName);
- assertTrue("Returned invalid fd", fis.getFD().valid());
- fis.close();
- assertTrue("Returned invalid fd", !fis.getFD().valid());
- } catch (FileNotFoundException e) {
- fail("Could not find : " + fileName);
- }
- catch (IOException e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- is = new FileInputStream(fileName);
- int c = is.read();
- assertEquals("Test 1: Read returned incorrect char;",
- fileString.charAt(0), c);
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
- public void test_read$B() throws IOException {
- byte[] buf1 = new byte[100];
- is = new FileInputStream(fileName);
- is.skip(3000);
- is.read(buf1);
- is.close();
- assertTrue("Test 1: Failed to read correct data.",
- new String(buf1, 0, buf1.length).equals(
- fileString.substring(3000, 3100)));
-
- is.close();
- try {
- is.read(buf1);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int FileInputStream.read(byte [], int, int)
- byte[] buf1 = new byte[100];
- try {
- is = new FileInputStream(fileName);
- is.skip(3000);
- is.read(buf1, 0, buf1.length);
- is.close();
- assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(fileString.substring(3000, 3100)));
-
- } catch (Exception e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests FileInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte[] buf = null;
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- buf = new byte[1000];
- try {
- is = new FileInputStream(fileName);
- is.read(buf, -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, -1, -1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 0, 1001);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 1001, 0);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.read(buf, 500, 501);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- } finally {
- is.close();
- }
-
- try {
- is = new FileInputStream(fileName);
- is.close();
- is.read(buf, 0, 100);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- } finally {
- is.close();
- }
- }
-
- /**
- * @tests FileInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- byte[] buf1 = new byte[10];
- is = new FileInputStream(fileName);
- is.skip(1000);
- is.read(buf1, 0, buf1.length);
- assertTrue("Test 1: Failed to skip to correct position.",
- new String(buf1, 0, buf1.length).equals(
- fileString.substring(1000, 1010)));
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests FileInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that skip(long) method throws IOException if " +
- "this method is called with negative argument.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipNegativeArgumentJ() throws IOException{
-
- FileInputStream fis = new FileInputStream(fileName);
-
- try {
- fis.skip(-5);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected IOException
- } catch (Exception e) {
- fail("Test 2: IOException expected but found: " + e.getMessage());
- }
-
- fis.close();
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- try {
- fileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (fileName.charAt(fileName.length() - 1) == separator.charAt(0))
- fileName = Support_PlatformFile.getNewPlatformFile(fileName,
- "input.tst");
- else
- fileName = Support_PlatformFile.getNewPlatformFile(fileName
- + separator, "input.tst");
- java.io.OutputStream fos = new FileOutputStream(fileName);
- fos.write(fileString.getBytes());
- fos.close();
- } catch (java.io.IOException e) {
- System.out.println("Exception during setup");
- e.printStackTrace();
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- if (is != null) {
- is.close();
- }
- new File(fileName).delete();
- } catch (IOException e) {
- // Ignored.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java b/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
deleted file mode 100644
index f87d647..0000000
--- a/luni/src/test/java/tests/api/java/io/FileNotFoundExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.FileNotFoundException;
-
-@TestTargetClass(FileNotFoundException.class)
-public class FileNotFoundExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.FileNotFoundException#FileNotFoundException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileNotFoundException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new FileNotFoundException();
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.FileNotFoundException#FileNotFoundException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileNotFoundException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new FileNotFoundException("Something went wrong.");
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
deleted file mode 100644
index 39543b4..0000000
--- a/luni/src/test/java/tests/api/java/io/FileOutputStreamTest.java
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(
- value = FileOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "finalize",
- args = {},
- level = TestLevel.NOT_FEASIBLE,
- notes = "Hard to test since it requires that the " +
- "garbage collector runs; add test later."
- )
- }
-)
-public class FileOutputStreamTest extends junit.framework.TestCase {
-
- public String fileName;
-
- FileOutputStream fos;
-
- FileInputStream fis;
-
- File f;
-
- String tmpDirName = System.getProperty("java.io.tmpdir");
-
- File tmpDir = new File(tmpDirName);
-
- byte[] ibuf = new byte[4096];
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() throws Exception {
- try {
- fos = new FileOutputStream(tmpDir);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(fileName = System.getProperty("java.io.tmpdir"), "fos.tst");
- fos = new FileOutputStream(f);
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String,
- * boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ() throws Exception {
- try {
- fos = new FileOutputStream(tmpDir, false);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fos = new FileOutputStream(f, false);
- fos.write("FZ1".getBytes(), 0, 3);
- fos.close();
- // Append data to existing file
- fos = new FileOutputStream(f, true);
- fos.write(fileString.getBytes());
- fos.close();
- byte[] buf = new byte[fileString.length() + 3];
- fis = new FileInputStream(f);
- fis.read(buf, 0, buf.length);
- assertTrue("Test 2: Failed to create appending stream.", new String(buf, 0,
- buf.length).equals("FZ1" + fileString));
- fis.close();
-
- // Check that the existing file is overwritten
- fos = new FileOutputStream(f, false);
- fos.write("FZ2".getBytes(), 0, 3);
- fos.close();
- fis = new FileInputStream(f);
- int bytesRead = fis.read(buf, 0, buf.length);
- assertTrue("Test 3: Failed to overwrite stream.", new String(buf, 0,
- bytesRead).equals("FZ2"));
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() throws Exception {
- // Test for method java.io.FileOutputStream(java.io.FileDescriptor)
- f = new File(tmpDirName, "fos.tst");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(fileName);
- fos.write('l');
- fos.close();
- fis = new FileInputStream(fileName);
- fos = new FileOutputStream(fis.getFD());
- fos.close();
- fis.close();
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() throws Exception {
- try {
- fos = new FileOutputStream(tmpDirName);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(fileName);
- }
-
- /**
- * @tests java.io.FileOutputStream#FileOutputStream(java.lang.String,
- * boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileOutputStream",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ() throws Exception {
- try {
- fos = new FileOutputStream(tmpDirName, true);
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
-
- f = new File(tmpDirName, "fos.tst");
- fos = new FileOutputStream(f.getPath(), false);
- fos.write("HI".getBytes(), 0, 2);
- fos.close();
- // Append data to existing file
- fos = new FileOutputStream(f.getPath(), true);
- fos.write(fileString.getBytes());
- fos.close();
- byte[] buf = new byte[fileString.length() + 2];
- fis = new FileInputStream(f.getPath());
- fis.read(buf, 0, buf.length);
- assertTrue("Failed to create appending stream", new String(buf, 0,
- buf.length).equals("HI" + fileString));
- fis.close();
-
- // Check that the existing file is overwritten
- fos = new FileOutputStream(f.getPath(), false);
- fos.write("HI".getBytes(), 0, 2);
- fos.close();
- fis = new FileInputStream(f.getPath());
- int bytesRead = fis.read(buf, 0, buf.length);
- assertTrue("Failed to overwrite stream", new String(buf, 0,
- bytesRead).equals("HI"));
- }
-
- /**
- * @tests java.io.FileOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked because it would be thrown" +
- "by a native method.",
- method = "close",
- args = {}
- )
- public void test_close() throws Exception {
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.close();
-
- try {
- fos.write(fileString.getBytes());
- fail("Test 1: IOException expected.");
- } catch (java.io.IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileOutputStream#getFD()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked because it never gets thrown.",
- method = "getFD",
- args = {}
- )
- public void test_getFD() throws Exception {
- // Test for method java.io.FileDescriptor
- // java.io.FileOutputStream.getFD()
- f = new File(fileName = System.getProperty("java.io.tmpdir"), "testfd");
- fileName = f.getAbsolutePath();
- fos = new FileOutputStream(f);
- assertTrue("Returned invalid fd", fos.getFD().valid());
- fos.close();
- assertTrue("Returned invalid fd", !fos.getFD().valid());
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws Exception {
- // Test for method void java.io.FileOutputStream.write(byte [])
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write(fileString.getBytes());
- fos.close();
- try {
- fos.write(fileString.getBytes());
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- fis = new FileInputStream(f.getPath());
- byte rbytes[] = new byte[4000];
- fis.read(rbytes, 0, fileString.length());
- assertTrue("Test 2: Incorrect string written or read.",
- new String(rbytes, 0, fileString.length()).equals(fileString));
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws Exception {
- // Test for method void java.io.FileOutputStream.write(byte [], int,
- // int)
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write(fileString.getBytes(), 0, fileString.length());
- fis = new FileInputStream(f.getPath());
- byte rbytes[] = new byte[4000];
- fis.read(rbytes, 0, fileString.length());
- assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString
- .length()).equals(fileString));
- }
-
- /**
- * @tests java.io.FileOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- // Test for method void java.io.FileOutputStream.write(int)
- f = new File(System.getProperty("java.io.tmpdir"), "output.tst");
- fos = new FileOutputStream(f.getPath());
- fos.write('t');
- fos.close();
- try {
- fos.write(42);
- fail("Test: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- fis = new FileInputStream(f.getPath());
- assertEquals("Test 1: Incorrect char written or read.",
- 't', fis.read());
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument and IOException checks.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII2() throws Exception {
- f = new File(tmpDirName, "output.tst");
- fos = new FileOutputStream(f.getPath());
-
- try {
- fos.write(null, 0, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {}
-
- try {
- fos.write(new byte[1], -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[1], 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[1], 0, 5);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[10], Integer.MAX_VALUE, 5);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- fos.write(new byte[10], 5, Integer.MAX_VALUE);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- fos.close();
- try {
- fos.write(new byte[10], 5, 4);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- /**
- * @tests java.io.FileOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII3() {
- try {
- new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0);
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
- }
-
- /**
- * @tests java.io.FileOutputStream#getChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getChannel() method.",
- method = "getChannel",
- args = {}
- )
- @AndroidOnly("The position of the FileChannel for a file opened in " +
- "append mode is 0 for the RI and corresponds to the " +
- "next position to write to on Android.")
- public void test_getChannel() throws Exception {
- // Make sure that system properties are set correctly
- if (tmpDir == null) {
- throw new Exception("System property java.io.tmpdir not defined.");
- }
- File tmpfile = File.createTempFile("FileOutputStream", "tmp");
- tmpfile.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(tmpfile);
- byte[] b = new byte[10];
- for (int i = 10; i < b.length; i++) {
- b[i] = (byte) i;
- }
- fos.write(b);
- fos.flush();
- fos.close();
- FileOutputStream f = new FileOutputStream(tmpfile, true);
- assertEquals(10, f.getChannel().position());
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- try {
- if (f != null)
- f.delete();
- if (fis != null)
- fis.close();
- if (fos != null)
- fos.close();
- } catch (Exception e) {}
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilePermissionTest.java b/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
deleted file mode 100644
index fc499c4..0000000
--- a/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.File;
-import java.io.FilePermission;
-import java.security.PermissionCollection;
-
-@TestTargetClass(FilePermission.class)
-public class FilePermissionTest extends junit.framework.TestCase {
-
- FilePermission readAllFiles;
- FilePermission alsoReadAllFiles;
- FilePermission allInCurrent;
- FilePermission readInCurrent;
- FilePermission readInFile;
-
- @Override protected void setUp() throws Exception {
- super.setUp();
-
- readAllFiles = new FilePermission("<<ALL FILES>>", "read");
- alsoReadAllFiles = new FilePermission("<<ALL FILES>>", "read");
- allInCurrent = new FilePermission("*", "read, write, execute,delete");
- readInCurrent = new FilePermission("*", "read");
- readInFile = new FilePermission("aFile.file", "read");
- }
-
- /**
- * @tests java.io.FilePermission#FilePermission(java.lang.String,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FilePermission(java.lang.String, java.lang.String) constructor.",
- method = "FilePermission",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.FilePermission(java.lang.String,
- // java.lang.String)
- assertTrue("Used to test", true);
- FilePermission constructFile = new FilePermission("test constructor",
- "write");
- assertEquals("action given to the constructor did not correspond - constructor failed",
- "write", constructFile.getActions());
- assertEquals(
- "name given to the constructor did not correspond - constructor failed",
- "test constructor", constructFile.getName());
-
- // Regression test for HARMONY-1050
- try {
- new FilePermission(null, "drink");
- fail("Expected IAE");
- } catch (IllegalArgumentException e) {
- // Expected
- }
-
- try {
- new FilePermission(null, "read");
- fail("Expected NPE");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- new FilePermission(null, null);
- fail("Expected IAE");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.FilePermission#getActions()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getActions() method.",
- method = "getActions",
- args = {}
- )
- public void test_getActions() {
- // Test for method java.lang.String java.io.FilePermission.getActions()
- assertEquals("getActions should have returned only read", "read", readAllFiles
- .getActions());
- assertEquals("getActions should have returned all actions", "read,write,execute,delete", allInCurrent
- .getActions());
- }
-
- /**
- * @tests java.io.FilePermission#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies equals(java.lang.Object) method.",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- // test for method java.io.FilePermission.equals()
- assertTrue(
- "returned false when two instance of FilePermission is equal",
- readAllFiles.equals(alsoReadAllFiles));
- assertTrue(
- "returned true when two instance of FilePermission is not equal",
- !(readInCurrent.equals(readInFile)));
- }
-
- /**
- * @tests java.io.FilePermission#implies(java.security.Permission)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies implies(java.security.Permission) method.",
- method = "implies",
- args = {java.security.Permission.class}
- )
- public void test_impliesLjava_security_Permission() {
- // Test for method boolean
- // java.io.FilePermission.implies(java.security.Permission)
- assertTrue("Returned true for non-subset of actions", !readAllFiles
- .implies(allInCurrent));
- assertTrue("Returned true for non-subset of files", !allInCurrent
- .implies(readAllFiles));
- assertTrue("Returned false for subset of actions", allInCurrent
- .implies(readInCurrent));
- assertTrue("Returned false for subset of files", readAllFiles
- .implies(readInCurrent));
- assertTrue("Returned false for subset of files and actions",
- allInCurrent.implies(readInFile));
- assertTrue("Returned false for equal FilePermissions", readAllFiles
- .implies(alsoReadAllFiles));
-
- FilePermission fp3 = new FilePermission("/bob/*".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp4 = new FilePermission("/bob/".replace('/',
- File.separatorChar), "write");
- assertTrue("returned true for same dir using * and not *", !fp3
- .implies(fp4));
- FilePermission fp5 = new FilePermission("/bob/file".replace('/',
- File.separatorChar), "write");
- assertTrue("returned false for same dir using * and file", fp3
- .implies(fp5));
-
- FilePermission fp6 = new FilePermission("/bob/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp7 = new FilePermission("/bob/*".replace('/',
- File.separatorChar), "write");
- assertTrue("returned false for same dir using not * and *", !fp6
- .implies(fp7));
- assertTrue("returned false for same subdir", fp6.implies(fp4));
-
- FilePermission fp8 = new FilePermission("/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp9 = new FilePermission("/".replace('/',
- File.separatorChar), "write");
- assertTrue("returned false for same dir", fp8.implies(fp9));
-
- FilePermission fp10 = new FilePermission("/".replace('/',
- File.separatorChar), "read,write");
- FilePermission fp11 = new FilePermission("/".replace('/',
- File.separatorChar), "write");
- assertTrue("returned false for same dir", fp10.implies(fp11));
-
- FilePermission fp12 = new FilePermission("/*".replace('/',
- File.separatorChar), "read,write");
- assertTrue("returned false for same dir using * and dir", !fp12
- .implies(fp10));
- }
-
- /**
- * @tests java.io.FilePermission#newPermissionCollection()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies newPermissionCollection() method.",
- method = "newPermissionCollection",
- args = {}
- )
- public void test_newPermissionCollection() {
- // test for method java.io.FilePermission.newPermissionCollection
- char s = File.separatorChar;
- FilePermission perm[] = new FilePermission[4];
- perm[0] = readAllFiles;
- perm[1] = allInCurrent;
- perm[2] = new FilePermission(s + "tmp" + s + "test" + s + "*",
- "read,write");
- perm[3] = new FilePermission(s + "tmp" + s + "test" + s
- + "collection.file", "read");
-
- PermissionCollection collect = perm[0].newPermissionCollection();
- for (int i = 0; i < perm.length; i++) {
- collect.add(perm[i]);
- }
- assertTrue("returned false for subset of files", collect
- .implies(new FilePermission("*", "write")));
- assertTrue("returned false for subset of name and action", collect
- .implies(new FilePermission(s + "tmp", "read")));
- assertTrue("returned true for non subset of file and action", collect
- .implies(readInFile));
-
- FilePermission fp1 = new FilePermission("/tmp/-".replace('/',
- File.separatorChar), "read");
- PermissionCollection fpc = fp1.newPermissionCollection();
- fpc.add(fp1);
- fpc.add(new FilePermission("/tmp/scratch/foo/*".replace('/',
- File.separatorChar), "write"));
- FilePermission fp2 = new FilePermission("/tmp/scratch/foo/file"
- .replace('/', File.separatorChar), "read,write");
- assertTrue("collection does not collate", fpc.implies(fp2));
- }
-
- /**
- * @tests java.io.FilePermission#hashCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies hashCode() method.",
- method = "hashCode",
- args = {}
- )
- public void test_hashCode() {
- // test method java.io.FilePermission.hasCode()
- assertTrue(
- "two equal filePermission instances returned different hashCode",
- readAllFiles.hashCode() == alsoReadAllFiles.hashCode());
- assertTrue(
- "two filePermission instances with same permission name returned same hashCode",
- readInCurrent.hashCode() != allInCurrent.hashCode());
-
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileReaderTest.java b/luni/src/test/java/tests/api/java/io/FileReaderTest.java
deleted file mode 100644
index f16e9ad..0000000
--- a/luni/src/test/java/tests/api/java/io/FileReaderTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileReader.class)
-public class FileReaderTest extends junit.framework.TestCase {
-
- FileReader br;
-
- BufferedWriter bw;
-
- FileInputStream fis;
-
- File f;
-
- /**
- * @tests java.io.FileReader#FileReader(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileReader",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method java.io.FileReader(java.io.File)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new FileReader(f);
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Test 1: Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- File noFile = new File(System.getProperty("java.io.tmpdir"), "noreader.tst");
- try {
- br = new FileReader(noFile);
- fail("Test 2: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileReader#FileReader(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FileReader(java.io.FileDescriptor) constructor.",
- method = "FileReader",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method java.io.FileReader(java.io.FileDescriptor)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- FileInputStream fis = new FileInputStream(f.getPath());
- br = new FileReader(fis.getFD());
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- fis.close();
- assertEquals("Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileReader#FileReader(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "FileReader",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.FileReader(java.lang.String)
- try {
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new FileReader(f.getPath());
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Test 1: Failed to read correct chars",
- " After test string", new String(buf, 0, r));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- try {
- br = new FileReader(System.getProperty("java.io.tmpdir") + "/noreader.tst");
- fail("Test 2: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- f = new File(System.getProperty("java.io.tmpdir"), "reader.tst");
-
- if (f.exists()) {
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- try {
- bw.close();
- br.close();
- } catch (Exception e) {
- }
-
- try {
- if (fis != null)
- fis.close();
- } catch (Exception e) {
- }
- f.delete();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileTest.java b/luni/src/test/java/tests/api/java/io/FileTest.java
deleted file mode 100644
index 43332ba..0000000
--- a/luni/src/test/java/tests/api/java/io/FileTest.java
+++ /dev/null
@@ -1,2532 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.RandomAccessFile;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import static tests.support.Support_Exec.javaProcessBuilder;
-import static tests.support.Support_Exec.execAndGetOutput;
-
-@TestTargetClass(File.class)
-public class FileTest extends junit.framework.TestCase {
-
- /** Location to store tests in */
- private File tempDirectory;
-
- /** Temp file that does exist */
- private File tempFile;
-
- /** File separator */
- private String slash = File.separator;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_File\nTest_FileDescriptor\nTest_FileInputStream\nTest_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- private static String platformId = "Android"
- + System.getProperty("java.vm.version").replace('.', '-');
-
- {
- // Delete all old temporary files
- File tempDir = new File(System.getProperty("java.io.tmpdir"));
- String[] files = tempDir.list();
- for (int i = 0; i < files.length; i++) {
- File f = new File(tempDir, files[i]);
- if (f.isDirectory()) {
- if (files[i].startsWith("hyts_resources"))
- deleteTempFolder(f);
- }
- if (files[i].startsWith("hyts_") || files[i].startsWith("hyjar_"))
- new File(tempDir, files[i]).delete();
- }
- }
-
- private void deleteTempFolder(File dir) {
- String files[] = dir.list();
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- if (f.isDirectory())
- deleteTempFolder(f);
- else {
- f.delete();
- }
- }
- dir.delete();
-
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
- String error;
- String dirName = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", dirName);
-
- File d = new File(dirName);
- File f = new File(d, "input.tst");
- if (!dirName.regionMatches((dirName.length() - 1), slash, 0, 1))
- dirName += slash;
- dirName += "input.tst";
- error = String.format("Test 1: Incorrect file created: %s; %s expected.", f.getPath(), dirName);
- assertTrue(error, f.getPath().equals(dirName));
-
- String fileName = null;
- try {
- f = new File(d, fileName);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- }
-
- d = null;
- f = new File(d, "input.tst");
- error = String.format("Test 3: Incorrect file created: %s; %s expected.",
- f.getAbsolutePath(), dirName);
- assertTrue(error, f.getAbsolutePath().equals(dirName));
-
- // Regression test for Harmony-382
- File s = null;
- f = new File("/abc");
- d = new File(s, "/abc");
- assertEquals("Test 4: Incorrect file created;",
- f.getAbsolutePath(), d.getAbsolutePath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies File(java.lang.String) constructor.",
- method = "File",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.File(java.lang.String)
- String fileName = null;
- try {
- new File(fileName);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- }
-
- fileName = System.getProperty("java.io.tmpdir");
- if (!fileName.regionMatches((fileName.length() - 1), slash, 0, 1))
- fileName += slash;
- fileName += "input.tst";
-
- File f = new File(fileName);
- assertTrue("Created incorrect file " + f.getPath(), f.getPath().equals(
- fileName));
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- String error;
- String dirName = null;
- String fileName = "input.tst";
-
- String userDir = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", userDir);
-
- File f = new File(dirName, fileName);
- if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
- userDir += slash;
- userDir += "input.tst";
- error = String.format("Test 1: Incorrect file created: %s; %s expected.",
- f.getAbsolutePath(), userDir);
- assertTrue(error, f.getAbsolutePath().equals(userDir));
-
- dirName = System.getProperty("java.io.tmpdir");
- fileName = null;
- try {
- f = new File(dirName, fileName);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- fileName = "input.tst";
- f = new File(dirName, fileName);
- assertTrue("Test 3: Incorrect file created.", f.getPath()
- .equals(userDir));
-
- // Regression test for Harmony-382
- String s = null;
- f = new File("/abc");
- File d = new File(s, "/abc");
- assertEquals("Test 4: Incorrect file created;", d.getAbsolutePath(), f
- .getAbsolutePath());
- assertEquals("Test3: Created Incorrect File", "/abc", f
- .getAbsolutePath());
- }
-
- /**
- * @tests java.io.File#File(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File file1 = new File("/", "/dir1/file1");
- assertEquals("wrong result 1: " + file1, ref1.getPath(), file1
- .getPath());
- File file2 = new File("/", "//dir1/file1");
- assertTrue("wrong result 2: " + file2, file2.getPath().equals(
- ref1.getPath()));
- File file3 = new File("\\", "\\dir1\\file1");
- assertTrue("wrong result 3: " + file3, file3.getPath().equals(
- "\\/\\dir1\\file1"));
- File file4 = new File("\\", "\\\\dir1\\file1");
- assertTrue("wrong result 4: " + file4, file4.getPath().equals(
- "\\/\\\\dir1\\file1"));
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File("/", "lib/content-types.properties");
- assertTrue("wrong result 5: " + file5, file5.getPath().equals(
- ref2.getPath()));
-
- }
-
- /**
- * @tests java.io.File#File(java.io.File, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "File",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String_112270() {
- File ref1 = new File("/dir1/file1");
-
- File root = new File("/");
- File file1 = new File(root, "/dir1/file1");
- assertTrue("wrong result 1: " + file1, file1.getPath().equals(
- ref1.getPath()));
- File file2 = new File(root, "//dir1/file1");
- assertTrue("wrong result 2: " + file2, file2.getPath().equals(
- ref1.getPath()));
- File file3 = new File(root, "\\dir1\\file1");
- assertTrue("wrong result 3: " + file3, file3.getPath().equals(
- "/\\dir1\\file1"));
- File file4 = new File(root, "\\\\dir1\\file1");
- assertTrue("wrong result 4: " + file4, file4.getPath().equals(
- "/\\\\dir1\\file1"));
-
- File ref2 = new File("/lib/content-types.properties");
- File file5 = new File(root, "lib/content-types.properties");
- assertTrue("wrong result 5: " + file5, file5.getPath().equals(
- ref2.getPath()));
- }
-
- /**
- * @tests java.io.File#File(java.net.URI)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies File(java.net.URI) constructor with incorrect parameter.",
- method = "File",
- args = {java.net.URI.class}
- )
- public void test_ConstructorLjava_net_URI() {
- // Test for method java.io.File(java.net.URI)
- URI uri = null;
- try {
- new File(uri);
- fail("NullPointerException Not Thrown.");
- } catch (NullPointerException e) {
- }
-
- // invalid file URIs
- String[] uris = new String[] { "mailto:user@domain.com", // not
- // hierarchical
- "ftp:///path", // not file scheme
- "//host/path/", // not absolute
- "file://host/path", // non empty authority
- "file:///path?query", // non empty query
- "file:///path#fragment", // non empty fragment
- "file:///path?", "file:///path#" };
-
- for (int i = 0; i < uris.length; i++) {
- try {
- uri = new URI(uris[i]);
- } catch (URISyntaxException e) {
- fail("Unexpected exception:" + e);
- }
- try {
- new File(uri);
- fail("Expected IllegalArgumentException for new File(" + uri
- + ")");
- } catch (IllegalArgumentException e) {
- }
- }
-
- // a valid File URI
- try {
- File f = new File(new URI("file:///pa%20th/another\u20ac/pa%25th"));
- assertTrue("Created incorrect File " + f.getPath(), f.getPath()
- .equals(
- slash + "pa th" + slash + "another\u20ac" + slash
- + "pa%th"));
- } catch (URISyntaxException e) {
- fail("Unexpected exception:" + e);
- } catch (IllegalArgumentException e) {
- fail("Unexpected exception:" + e);
- }
- }
-
- /**
- * @tests java.io.File#canRead()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canRead",
- args = {}
- )
- public void test_canRead() {
- // Test for method boolean java.io.File.canRead()
- // canRead only returns if the file exists so cannot be fully tested.
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "canRead.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canRead returned false", f.canRead());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#canWrite()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canWrite",
- args = {}
- )
- public void test_canWrite() {
- // Test for method boolean java.io.File.canWrite()
- // canWrite only returns if the file exists so cannot be fully tested.
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "canWrite.tst");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("canWrite returned false", f.canWrite());
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#compareTo(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies compareTo(java.io.File) method.",
- method = "compareTo",
- args = {java.io.File.class}
- )
- public void test_compareToLjava_io_File() {
- File f1 = new File("thisFile.file");
- File f2 = new File("thisFile.file");
- File f3 = new File("thatFile.file");
- assertEquals("Equal files did not answer zero for compareTo", 0, f1
- .compareTo(f2));
- assertTrue("f3.compareTo(f1) did not result in value < 0", f3
- .compareTo(f1) < 0);
- assertTrue("f1.compareTo(f3) did not result in vale > 0", f1
- .compareTo(f3) > 0);
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checked.",
- method = "createNewFile",
- args = {}
- )
- public void test_createNewFile_EmptyString() {
- File f = new File("");
- try {
- f.createNewFile();
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.File#createNewFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createNewFile",
- args = {}
- )
- public void test_createNewFile() throws IOException {
- // Test for method java.io.File.createNewFile()
- String base = System.getProperty("java.io.tmpdir");
- boolean dirExists = true;
- int numDir = 1;
- File dir = new File(base, String.valueOf(numDir));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making
- // it a new directory name.)
- if (dir.exists()) {
- numDir++;
- dir = new File(base, String.valueOf(numDir));
- } else {
- dirExists = false;
- }
- }
-
- // Test for trying to create a file in a directory that does not
- // exist.
- try {
- // Try to create a file in a directory that does not exist
- File f1 = new File(dir, "tempfile.tst");
- f1.createNewFile();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- dir.mkdir();
-
- File f1 = new File(dir, "tempfile.tst");
- File f2 = new File(dir, "tempfile.tst");
- f1.deleteOnExit();
- f2.deleteOnExit();
- dir.deleteOnExit();
- assertFalse("Test 2: File should not exist.", f1.isFile());
- f1.createNewFile();
- assertTrue("Test 3: File should exist.", f1.isFile());
- assertTrue("Test 4: File should exist.", f2.isFile());
- String dirName = f1.getParent();
- if (!dirName.endsWith(slash))
- dirName += slash;
- assertTrue("Test 5: File saved in the wrong directory.",
- dirName.equals(dir.getPath() + slash));
- assertEquals("Test 6: File saved with incorrect name;",
- "tempfile.tst", f1.getName());
-
- // Test for creating a file that already exists.
- assertFalse("Test 7: File already exists, createNewFile should " +
- "return false.", f2.createNewFile());
-
- // Trying to create an illegal file.
- String sep = File.separator;
- f1 = new File(sep+"a"+sep+".."+sep+".."+sep);
- try {
- f1.createNewFile();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- f1 = new File(base);
- assertFalse("Test 9: False expected when trying to create an " +
- "existing file", f1.createNewFile());
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createTempFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- @AndroidOnly("The RI does not throw an IOException when an illegal" +
- "file prefix is passed to createTempFile.")
- public void test_createTempFileLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.File.createTempFile(String, String)
- // Error protection against using a suffix without a "."?
- File f1 = null;
- File f2 = null;
- try {
- f1 = File.createTempFile("hyts_abc", ".tmp");
- f2 = File.createTempFile("hyts_tf", null);
- String fileLocation = f1.getParent();
- if (!fileLocation.endsWith(slash))
- ;
- fileLocation += slash;
- String tempDir = System.getProperty("java.io.tmpdir");
- if (!tempDir.endsWith(slash))
- tempDir += slash;
- assertTrue(
- "File did not save to the default temporary-file location.",
- fileLocation.equals(tempDir));
-
- // Test to see if correct suffix was used to create the tempfile.
- File currentFile;
- String fileName;
- // Testing two files, one with suffix ".tmp" and one with null
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileName = currentFile.getPath();
- assertTrue("File Created With Incorrect Suffix.", fileName
- .endsWith(".tmp"));
- }
-
- // Tests to see if the correct prefix was used to create the
- // tempfiles.
- fileName = f1.getName();
- assertTrue("Test 1: File Created With Incorrect Prefix.", fileName
- .startsWith("hyts_abc"));
- fileName = f2.getName();
- assertTrue("Test 2: File Created With Incorrect Prefix.", fileName
- .startsWith("hyts_tf"));
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f3 = File.createTempFile("ab", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f3 = File.createTempFile("a", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f3 = File.createTempFile("", ".tst");
- f3.delete();
- fail("IllegalArgumentException Not Thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- // Providing an illegal file prefix.
- File f3 = File.createTempFile("/../../../../../", null);
- f3.delete();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
-
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f2.delete();
- }
- }
-
- /**
- * @tests java.io.File#createTempFile(java.lang.String, java.lang.String,
- * java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "createTempFile",
- args = {java.lang.String.class, java.lang.String.class, java.io.File.class}
- )
- public void test_createTempFileLjava_lang_StringLjava_lang_StringLjava_io_File() {
- // Test for method java.io.File.createTempFile(String, String, File)
- File f1 = null;
- File f2 = null;
- String base = System.getProperty("java.io.tmpdir");
- try {
-
- // Test to make sure that the tempfile was saved in the correct
- // location
- // and with the correct prefix/suffix.
- f1 = File.createTempFile("hyts_tf", null, null);
- File dir = new File(base);
- f2 = File.createTempFile("hyts_tf", ".tmp", dir);
- File currentFile;
- String fileLocation;
- String fileName;
- for (int i = 0; i < 2; i++) {
- currentFile = i == 0 ? f1 : f2;
- fileLocation = currentFile.getParent();
- if (!fileLocation.endsWith(slash))
- fileLocation += slash;
- if (!base.endsWith(slash))
- base += slash;
- assertTrue(
- "File not created in the default temporary-file location.",
- fileLocation.equals(base));
- fileName = currentFile.getName();
- assertTrue("File created with incorrect suffix.", fileName
- .endsWith(".tmp"));
- assertTrue("File created with incorrect prefix.", fileName
- .startsWith("hyts_tf"));
- currentFile.delete();
- }
-
- // Test for creating a tempfile in a directory that does not exist.
- int dirNumber = 1;
- boolean dirExists = true;
- // Set dir to a non-existent directory inside the temporary
- // directory
- dir = new File(base, String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making it
- // a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- try {
- // Try to create a file in a directory that does not exist
- File f3 = File.createTempFile("hyts_tf", null, dir);
- f3.delete();
- fail("IOException not thrown");
- } catch (IOException e) {
- }
- dir.delete();
-
- // Tests for creating a tempfile with a filename shorter than 3
- // characters.
- try {
- File f4 = File.createTempFile("ab", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f4 = File.createTempFile("a", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
- try {
- File f4 = File.createTempFile("", null, null);
- f4.delete();
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
-
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f1.delete();
- }
- }
-
- /**
- * @tests java.io.File#delete()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "delete",
- args = {}
- )
- public void test_delete() {
- // Test for method boolean java.io.File.delete()
- try {
- File dir = new File(System.getProperty("java.io.tmpdir"), platformId
- + "filechk");
- dir.mkdir();
- assertTrue("Directory Does Not Exist", dir.exists()
- && dir.isDirectory());
- File f = new File(dir, "filechk.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Error Creating File For Delete Test", f.exists());
- dir.delete();
- assertTrue("Directory Should Not Have Been Deleted.", dir.exists());
- f.delete();
- assertTrue("File Was Not Deleted", !f.exists());
- dir.delete();
- assertTrue("Directory Was Not Deleted", !dir.exists());
- } catch (IOException e) {
- fail("Unexpected IOException During Delete Test : "
- + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#equals(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies equals() method.",
- method = "equals",
- args = {java.lang.Object.class}
- )
- public void test_equalsLjava_lang_Object() {
- // Test for method boolean java.io.File.equals(java.lang.Object)
- File f1 = new File("filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("xxxx");
-
- assertTrue("Equality test failed", f1.equals(f2));
- assertTrue("Files Should Not Return Equal.", !f1.equals(f3));
-
- f3 = new File("FiLeChK.tst");
- boolean onWindows = File.separatorChar == '\\';
- boolean onUnix = File.separatorChar == '/';
- if (onWindows)
- assertTrue("Files Should Return Equal.", f1.equals(f3));
- else if (onUnix)
- assertTrue("Files Should NOT Return Equal.", !f1.equals(f3));
-
- try {
- f1 = new File(System.getProperty("java.io.tmpdir"), "casetest.tmp");
- f2 = new File(System.getProperty("java.io.tmpdir"), "CaseTest.tmp");
- new FileOutputStream(f1).close(); // create the file
- if (f1.equals(f2)) {
- try {
- new FileInputStream(f2);
- } catch (IOException e) {
- fail("File system is case sensitive");
- }
- } else {
- boolean exception = false;
- try {
- new FileInputStream(f2);
- } catch (IOException e) {
- exception = true;
- }
- assertTrue("File system is case insensitive", exception);
- }
- f1.delete();
- } catch (IOException e) {
- fail("Unexpected using case sensitive test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#exists()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "exists",
- args = {}
- )
- public void test_exists() {
- // Test for method boolean java.io.File.exists()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "exists.tst");
- assertTrue("Exists returned true for non-existent file", !f
- .exists());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("Exists returned false file", f.exists());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getAbsoluteFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "getAbsoluteFile",
- args = {}
- )
- public void test_getAbsoluteFile() {
- // Test for method java.io.File getAbsoluteFile()
- String base = System.getProperty("java.io.tmpdir");
- if (!base.endsWith(slash))
- base += slash;
- File f = new File(base, "temp.tst");
- File f2 = f.getAbsoluteFile();
- assertEquals("Test 1: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + "Temp" + slash + slash + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 2: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f = new File(base + slash + ".." + slash + "temp.tst");
- f2 = f.getAbsoluteFile();
- assertEquals("Test 3: Incorrect File Returned.", 0, f2.compareTo(f
- .getAbsoluteFile()));
- f.delete();
- f2.delete();
- }
-
- /**
- * @tests java.io.File#getAbsolutePath()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "getAbsolutePath",
- args = {}
- )
- public void test_getAbsolutePath() {
- // Test for method java.lang.String java.io.File.getAbsolutePath()
- String base = System.getProperty("java.io.tmpdir");
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base, "temp.tst");
- assertTrue("Test 1: Incorrect path returned.", f.getAbsolutePath()
- .equals(base + "temp.tst"));
- f = new File(base + "Temp" + slash + slash + slash + "Testing" + slash
- + "temp.tst");
- assertTrue("Test 2: Incorrect path returned.", f.getAbsolutePath()
- .equals(base + "Temp" + slash + "Testing" + slash + "temp.tst"));
- f = new File(base + "a" + slash + slash + ".." + slash + "temp.tst");
- assertTrue("Test 3: Incorrect path returned." + f.getAbsolutePath(), f
- .getAbsolutePath().equals(
- base + "a" + slash + ".." + slash + "temp.tst"));
- f.delete();
- }
-
- /**
- * @tests java.io.File#getCanonicalFile()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked since it may only occur if" +
- "the native access to the filesystem fails.",
- method = "getCanonicalFile",
- args = {}
- )
- public void test_getCanonicalFile() {
- // Test for method java.io.File.getCanonicalFile()
- try {
- String base = System.getProperty("java.io.tmpdir");
- if (!base.endsWith(slash))
- base += slash;
- File f = new File(base, "temp.tst");
- File f2 = f.getCanonicalFile();
- assertEquals("Test 1: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + slash + slash + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 2: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
- f = new File(base + "Temp" + slash + slash + ".." + slash
- + "temp.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 3: Incorrect file returned.", 0, f2
- .getCanonicalFile().compareTo(f.getCanonicalFile()));
-
- // Test for when long directory/file names in Windows
- boolean onWindows = File.separatorChar == '\\';
- // String userDir = System.getProperty("java.io.tmpdir");
- if (onWindows) {
- File testdir = new File(base, "long-" + platformId);
- testdir.mkdir();
- File dir = new File(testdir, "longdirectory" + platformId);
- try {
- dir.mkdir();
- f = new File(dir, "longfilename.tst");
- f2 = f.getCanonicalFile();
- assertEquals("Test 4: Incorrect file returned.",
- 0, f2.getCanonicalFile().compareTo(
- f.getCanonicalFile()));
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f2 = new File(testdir + slash + "longdi~1" + slash
- + "longfi~1.tst");
- File canonicalf2 = f2.getCanonicalFile();
- /*
- * If the "short file name" doesn't exist, then assume that
- * the 8.3 file name compatibility is disabled.
- */
- if (canonicalf2.exists()) {
- assertTrue("Test 5: Incorrect file returned: "
- + canonicalf2, canonicalf2.compareTo(f
- .getCanonicalFile()) == 0);
- }
- } finally {
- f.delete();
- f2.delete();
- dir.delete();
- testdir.delete();
- }
- }
- } catch (IOException e) {
- fail ("Unexpected IOException during Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getCanonicalPath()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException not checked since it may only occur if" +
- "the native access to the filesystem fails.",
- method = "getCanonicalPath",
- args = {}
- )
- public void test_getCanonicalPath() {
- // Test for method java.lang.String java.io.File.getCanonicalPath()
- // Should work for Unix/Windows.
- String dots = "..";
- String expected;
- String error;
- String tmpDir = System.getProperty("java.io.tmpdir");
- System.setProperty("user.dir", tmpDir);
- try {
- String base = new File(tmpDir).getCanonicalPath();
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base, "temp.tst");
- assertEquals("Test 1: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
- f = new File(base + "Temp" + slash + dots + slash + "temp.tst");
- assertEquals("Test 2: Incorrect Path Returned.", base + "temp.tst", f
- .getCanonicalPath());
-
- // Finding a non-existent directory for tests 3 and 4
- // This is necessary because getCanonicalPath is case sensitive and
- // could
- // cause a failure in the test if the directory exists but with
- // different
- // case letters (e.g "Temp" and "temp")
- int dirNumber = 1;
- boolean dirExists = true;
- File dir1 = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir1.exists()) {
- dirNumber++;
- dir1 = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- f = new File(base + dirNumber + slash + dots + slash + dirNumber + slash
- + "temp.tst");
- assertEquals("Test 3: Incorrect path returned.", base + dirNumber + slash
- + "temp.tst", f.getCanonicalPath());
- f = new File(base + dirNumber + slash + "Temp" + slash + dots + slash + "Test"
- + slash + "temp.tst");
- assertEquals("Test 4: Incorrect path returned.", base + dirNumber + slash + "Test"
- + slash + "temp.tst", f.getCanonicalPath());
-
- // Check that the implicit "user.dir" in a relative path gets canonicalized.
- f = new File("1234.567");
- File expectedFile = new File(System.getProperty("user.dir"), "1234.567");
- assertEquals(expectedFile.getCanonicalPath(), f.getCanonicalPath());
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getName() method.",
- method = "getName",
- args = {}
- )
- public void test_getName() {
- // Test for method java.lang.String java.io.File.getName()
- File f = new File("name.tst");
- assertEquals("Test 1: Returned incorrect name",
- "name.tst", f.getName());
-
- f = new File("");
- assertTrue("Test 2: Returned incorrect name", f.getName().equals(""));
-
- f.delete();
- }
-
- /**
- * @tests java.io.File#getParent()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getParent() method.",
- method = "getParent",
- args = {}
- )
- public void test_getParent() throws Exception {
- // Test for method java.lang.String java.io.File.getParent()
- String dir = System.getProperty("java.io.tmpdir");
- if (dir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
-
- File f = new File("p.tst");
- assertNull("Test 1: Incorrect path returned", f.getParent());
- f = new File(dir, "p.tst");
- assertTrue("Test 2: Incorrect path returned",
- f.getParent().equals(dir));
- try {
- f.delete();
- } catch (Exception e) {
- fail("Unexpected exception during tests : " + e.getMessage());
- }
-
- File f1 = new File("/directory");
- assertTrue("Wrong parent test 1", f1.getParent().equals(slash));
- f1 = new File("/directory/file");
- assertTrue("Wrong parent test 2", f1.getParent().equals(
- slash + "directory"));
- f1 = new File("directory/file");
- assertEquals("Wrong parent test 3", "directory", f1.getParent());
- f1 = new File("/");
- assertNull("Wrong parent test 4", f1.getParent());
- f1 = new File("directory");
- assertNull("Wrong parent test 5", f1.getParent());
-
- if (File.separatorChar == '\\' && new File("d:/").isAbsolute()) {
- f1 = new File("d:/directory");
- assertTrue("Wrong parent test 1a", f1.getParent().equals(
- "d:" + slash));
- f1 = new File("d:/directory/file");
- assertTrue("Wrong parent test 2a", f1.getParent().equals(
- "d:" + slash + "directory"));
- f1 = new File("d:directory/file");
- assertEquals("Wrong parent test 3a",
- "d:directory", f1.getParent());
- f1 = new File("d:/");
- assertNull("Wrong parent test 4a", f1.getParent());
- f1 = new File("d:directory");
- assertEquals("Wrong parent test 5a", "d:", f1.getParent());
- }
- }
-
- /**
- * @tests java.io.File#getParentFile()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getParentFile() method.",
- method = "getParentFile",
- args = {}
- )
- public void test_getParentFile() {
- // Test for method java.io.File.getParentFile()
- File f = new File("tempfile.tst");
- assertNull("Incorrect path returned", f.getParentFile());
- f = new File(System.getProperty("java.io.tmpdir"), "tempfile1.tmp");
- File f2 = new File(System.getProperty("java.io.tmpdir"), "tempfile2.tmp");
- File f3 = new File(System.getProperty("java.io.tmpdir"), "/a/tempfile.tmp");
- assertEquals("Incorrect file returned", 0, f.getParentFile().compareTo(
- f2.getParentFile()));
- assertTrue("Incorrect file returned", f.getParentFile().compareTo(
- f3.getParentFile()) != 0);
- f.delete();
- f2.delete();
- f3.delete();
- }
-
- /**
- * @tests java.io.File#getPath()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getPath() method.",
- method = "getPath",
- args = {}
- )
- public void test_getPath() {
- System.setProperty("user.dir", System.getProperty("java.io.tmpdir"));
- String base = System.getProperty("user.dir");
- String fname;
- File f1;
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- fname = base + "filechk.tst";
- f1 = new File(base, "filechk.tst");
- File f2 = new File("filechk.tst");
- File f3 = new File("c:");
- File f4 = new File(base + "a" + slash + slash + ".." + slash
- + "filechk.tst");
- assertTrue("getPath returned incorrect path(f1) " + f1.getPath(), f1
- .getPath().equals(fname));
- assertTrue("getPath returned incorrect path(f2) " + f2.getPath(), f2
- .getPath().equals("filechk.tst"));
- assertTrue("getPath returned incorrect path(f3) " + f3.getPath(), f3
- .getPath().equals("c:"));
- assertTrue("getPath returned incorrect path(f4) " + f4.getPath(), f4
- .getPath().equals(
- base + "a" + slash + ".." + slash + "filechk.tst"));
- f1.delete();
- f2.delete();
- f3.delete();
- f4.delete();
- }
-
- /**
- * @tests java.io.File#isAbsolute()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies isAbsolute() method.",
- method = "isAbsolute",
- args = {}
- )
- public void test_isAbsolute() {
- // Test for method boolean java.io.File.isAbsolute()
- if (File.separatorChar == '\\') {
- File f = new File("c:\\test");
- File f1 = new File("\\test");
- // One or the other should be absolute on Windows or CE
- assertTrue("Absolute returned false", (f.isAbsolute() && !f1
- .isAbsolute())
- || (!f.isAbsolute() && f1.isAbsolute()));
- } else {
- File f = new File("/test");
- assertTrue("Absolute returned false", f.isAbsolute());
- }
- assertTrue("Non-Absolute returned true", !new File("../test")
- .isAbsolute());
- }
-
- /**
- * @tests java.io.File#isDirectory()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isDirectory",
- args = {}
- )
- public void test_isDirectory() {
- // Test for method boolean java.io.File.isDirectory()
-
- String base = System.getProperty("java.io.tmpdir");
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- File f = new File(base);
- assertTrue("Test 1: Directory returned false", f.isDirectory());
- f = new File(base + "zxzxzxz" + platformId);
- assertTrue("Test 2: (Not created) directory returned true.", !f
- .isDirectory());
- f.mkdir();
- try {
- assertTrue("Test 3: Directory returned false.", f.isDirectory());
- } finally {
- f.delete();
- }
- }
-
- /**
- * @tests java.io.File#isFile()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isFile",
- args = {}
- )
- public void test_isFile() {
- // Test for method boolean java.io.File.isFile()
- try {
- String base = System.getProperty("java.io.tmpdir");
- File f = new File(base);
- assertTrue("Directory returned true as being a file.", !f.isFile());
- if (!base.regionMatches((base.length() - 1), slash, 0, 1))
- base += slash;
- f = new File(base, platformId + "amiafile");
- assertTrue("Non-existent file returned true", !f.isFile());
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- assertTrue("File returned false", f.isFile());
- f.delete();
- } catch (IOException e) {
- fail("IOException during isFile " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#isHidden()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isHidden",
- args = {}
- )
- public void test_isHidden() {
- // Test for method boolean java.io.File.isHidden()
- boolean onUnix = File.separatorChar == '/';
-
- try {
- File f = File.createTempFile("hyts_", ".tmp");
- // On Unix hidden files are marked with a "." at the beginning
- // of the file name.
- if (onUnix) {
- File f2 = new File(System.getProperty("java.io.tmpdir"), ".test.tst" + platformId);
- FileOutputStream fos2 = new FileOutputStream(f2);
- fos2.close();
- assertTrue("File returned hidden on Unix", !f.isHidden());
- assertTrue("File returned visible on Unix", f2.isHidden());
- assertTrue("File did not delete.", f2.delete());
- } else {
- // For windows, the file is being set hidden by the attrib
- // command.
- Runtime r = Runtime.getRuntime();
- assertTrue("File returned hidden", !f.isHidden());
- Process p = r.exec("attrib +h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned visible", f.isHidden());
- p = r.exec("attrib -h \"" + f.getAbsolutePath() + "\"");
- p.waitFor();
- assertTrue("File returned hidden", !f.isHidden());
- }
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Unexpected InterruptedException during test : "
- + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#lastModified()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "lastModified",
- args = {}
- )
- public void test_lastModified() {
- // Test for method long java.io.File.lastModified()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "lModTest.tst");
- f.delete();
- long lastModifiedTime = f.lastModified();
- assertEquals("LastModified Time Should Have Returned 0.",
- 0, lastModifiedTime);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- f.setLastModified(315550800000L);
- lastModifiedTime = f.lastModified();
- assertTrue("LastModified Time Incorrect: " + lastModifiedTime,
- lastModifiedTime == 315550800000L);
- f.delete();
-
- // Regression for Harmony-2146
- f = new File("/../");
- assertTrue(f.lastModified() > 0);
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#length()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "length",
- args = {}
- )
- public void test_length() throws Exception {
- // Test for method long java.io.File.length()
- try {
- File f = new File(System.getProperty("java.io.tmpdir"), platformId
- + "input.tst");
- assertEquals("File length should have returned 0.", 0, f.length());
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- assertTrue("Incorrect file length returned: " + f.length(), f
- .length() == fileString.length());
- f.delete();
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- // regression test for Harmony-1497
- File f = File.createTempFile("cts", ".tmp");
- f.deleteOnExit();
- RandomAccessFile raf = new RandomAccessFile(f, "rwd");
- raf.write(0x41);
- assertEquals(1, f.length());
- }
-
- /**
- * @tests java.io.File#list()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "list",
- args = {}
- )
- public void test_list() {
- // Test for method java.lang.String [] java.io.File.list()
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = null;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- String[] flist = dir.list();
-
- assertNull("Method list() Should Have Returned null.", flist);
-
- assertTrue("Could not create parent directory for list test", dir
- .mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- assertEquals("Method list() Should Have Returned An Array Of Length 0.",
- 0, dir.list().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.list());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- flist = dir.list();
- if (flist.length != files.length) {
- fail("Incorrect list returned");
- }
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
-
- assertTrue("Could not delete parent directory for list test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
-
- }
-
- /**
- * @tests java.io.File#listFiles()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {}
- )
- public void test_listFiles() {
- // Test for method java.io.File.listFiles()
-
- try {
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number
- // (making
- // it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
- // Test for attempting to cal listFiles on a non-existent directory.
- assertNull("listFiles Should Return Null.", dir.listFiles());
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tst", "" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, dir
- .listFiles().length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- for (int i = 0; i < (files.length - 1); i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
-
- new File(dir, "doesNotExist.tst");
- File[] flist = dir.listFiles();
-
- // Test to make sure that only the 3 files that were created are
- // listed.
- assertEquals("Incorrect Number Of Files Returned.",
- 3, flist.length);
-
- // Test to make sure that listFiles can read hidden files.
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onWindows) {
- files[3] = "4.tst";
- File f = new File(dir, "4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib +h \"" + f.getPath() + "\"");
- p.waitFor();
- }
- if (onUnix) {
- files[3] = ".4.tst";
- File f = new File(dir, ".4.tst");
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- flist = dir.listFiles();
- assertEquals("Incorrect Number Of Files Returned.",
- 4, flist.length);
-
- // Checking to make sure the correct files were are listed in
- // the array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- if (onWindows) {
- Runtime r = Runtime.getRuntime();
- Process p = r.exec("attrib -h \""
- + new File(dir, files[3]).getPath() + "\"");
- p.waitFor();
- }
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Unexpected InterruptedException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FileFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {java.io.FileFilter.class}
- )
- public void test_listFilesLjava_io_FileFilter() {
- // Test for method java.io.File.listFiles(File Filter filter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File baseDir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (baseDir.exists()) {
- dirNumber++;
- baseDir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches directories.
- FileFilter dirFilter = new FileFilter() {
- public boolean accept(File f) {
- if (f.isDirectory())
- return true;
- else
- return false;
- }
- };
-
- assertNull("listFiles Should Return Null.", baseDir
- .listFiles(dirFilter));
-
- assertTrue("Failed To Create Parent Directory.", baseDir.mkdir());
-
- File dir1 = null;
- String[] files = { "1.tst", "2.tst", "3.tst" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, baseDir
- .listFiles(dirFilter).length);
-
- File file = new File(baseDir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(dirFilter));
- } catch (IOException e) {
- fail("Unexpected IOException During Test.");
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
- dir1 = new File(baseDir, "Temp1");
- dir1.mkdir();
-
- // Creating a filter that catches files.
- FileFilter fileFilter = new FileFilter() {
- public boolean accept(File f) {
- if (f.isFile())
- return true;
- else
- return false;
- }
- };
-
- // Test to see if the correct number of directories are returned.
- File[] directories = baseDir.listFiles(dirFilter);
- assertEquals("Incorrect Number Of Directories Returned.",
- 1, directories.length);
-
- // Test to see if the directory was saved with the correct name.
- assertEquals("Incorrect Directory Returned.", 0, directories[0]
- .compareTo(dir1));
-
- // Test to see if the correct number of files are returned.
- File[] flist = baseDir.listFiles(fileFilter);
- assertTrue("Incorrect Number Of Files Returned.",
- flist.length == files.length);
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- for (int i = 0; i < files.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].getName().equals(files[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- dir1.delete();
- assertTrue("Parent Directory Not Deleted.", baseDir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(baseDir, files[i]);
- f.delete();
- }
- if (dir1 != null)
- dir1.delete();
- baseDir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listFiles(java.io.FilenameFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "listFiles",
- args = {java.io.FilenameFilter.class}
- )
- public void test_listFilesLjava_io_FilenameFilter() {
- // Test for method java.io.File.listFiles(FilenameFilter filter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Finding a non-existent directory to create.
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- // Making sure that the directory does not exist.
- while (dirExists) {
- // If the directory exists, add one to the directory number (making
- // it a new directory name.)
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, platformId + String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- // Creating a filter that catches "*.tst" files.
- FilenameFilter tstFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- // If the suffix is ".tst" then send it to the array
- if (fileName.endsWith(".tst"))
- return true;
- else
- return false;
- }
- };
-
- assertNull("listFiles Should Return Null.",
- dir.listFiles(tstFilter));
-
- assertTrue("Failed To Create Parent Directory.", dir.mkdir());
-
- String[] files = { "1.tst", "2.tst", "3.tmp" };
- try {
- assertEquals("listFiles Should Return An Array Of Length 0.", 0, dir
- .listFiles(tstFilter).length);
-
- File file = new File(dir, "notADir.tst");
- try {
- FileOutputStream fos = new FileOutputStream(file);
- fos.close();
- assertNull(
- "listFiles Should Have Returned Null When Used On A File Instead Of A Directory.",
- file.listFiles(tstFilter));
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- file.delete();
- }
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException During Test : " + e.getMessage());
- }
-
- // Creating a filter that catches "*.tmp" files.
- FilenameFilter tmpFilter = new FilenameFilter() {
- public boolean accept(File f, String fileName) {
- // If the suffix is ".tmp" then send it to the array
- if (fileName.endsWith(".tmp"))
- return true;
- else
- return false;
- }
- };
-
- // Tests to see if the correct number of files were returned.
- File[] flist = dir.listFiles(tstFilter);
- assertEquals("Incorrect Number Of Files Passed Through tstFilter.",
- 2, flist.length);
- for (int i = 0; i < flist.length; i++)
- assertTrue("File Should Not Have Passed The tstFilter.",
- flist[i].getPath().endsWith(".tst"));
-
- flist = dir.listFiles(tmpFilter);
- assertEquals("Incorrect Number Of Files Passed Through tmpFilter.",
- 1, flist.length);
- assertTrue("File Should Not Have Passed The tmpFilter.", flist[0]
- .getPath().endsWith(".tmp"));
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Parent Directory Not Deleted.", dir.delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#list(java.io.FilenameFilter)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "list",
- args = {java.io.FilenameFilter.class}
- )
- public void test_listLjava_io_FilenameFilter() {
- // Test for method java.lang.String []
- // java.io.File.list(java.io.FilenameFilter)
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, platformId + String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- FilenameFilter filter = new FilenameFilter() {
- public boolean accept(File dir, String name) {
- return !name.equals("mtzz1.xx");
- }
- };
-
- String[] flist = dir.list(filter);
- assertNull("Method list(FilenameFilter) Should Have Returned Null.",
- flist);
-
- assertTrue("Could not create parent directory for test", dir.mkdir());
-
- String[] files = { "mtzz1.xx", "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- try {
- /*
- * Do not return null when trying to use list(Filename Filter) on a
- * file rather than a directory. All other "list" methods return
- * null for this test case.
- */
- /*
- * File file = new File(dir, "notADir.tst"); try { FileOutputStream
- * fos = new FileOutputStream(file); fos.close(); } catch
- * (IOException e) { fail("Unexpected IOException During
- * Test."); } flist = dir.list(filter); assertNull("listFiles
- * Should Have Returned Null When Used On A File Instead Of A
- * Directory.", flist); file.delete();
- */
-
- flist = dir.list(filter);
- assertEquals("Array Of Length 0 Should Have Returned.",
- 0, flist.length);
-
- try {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- FileOutputStream fos = new FileOutputStream(f);
- fos.close();
- }
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- }
-
- flist = dir.list(filter);
-
- if (flist.length != files.length - 1) {
- fail("Incorrect list returned");
- }
-
- // Checking to make sure the correct files were are listed in the
- // array.
- boolean[] check = new boolean[flist.length];
- for (int i = 0; i < check.length; i++)
- check[i] = false;
- String[] wantedFiles = { "mtzz2.xx", "mtzz3.yy", "mtzz4.yy" };
- for (int i = 0; i < wantedFiles.length; i++) {
- for (int j = 0; j < flist.length; j++) {
- if (flist[j].equals(wantedFiles[i])) {
- check[i] = true;
- break;
- }
- }
- }
- int checkCount = 0;
- for (int i = 0; i < check.length; i++) {
- if (check[i] == false)
- checkCount++;
- }
- assertEquals("Invalid file returned in listing", 0, checkCount);
-
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- assertTrue("Could not delete parent directory for test.", dir
- .delete());
- } finally {
- for (int i = 0; i < files.length; i++) {
- File f = new File(dir, files[i]);
- f.delete();
- }
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#listRoots()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies listRoots() method.",
- method = "listRoots",
- args = {}
- )
- public void test_listRoots() {
- // Test for method java.io.File.listRoots()
-
- File[] roots = File.listRoots();
- boolean onUnix = File.separatorChar == '/';
- boolean onWindows = File.separatorChar == '\\';
- if (onUnix) {
- assertEquals("Incorrect Number Of Root Directories.",
- 1, roots.length);
- String fileLoc = roots[0].getPath();
- assertTrue("Incorrect Root Directory Returned.", fileLoc
- .startsWith(slash));
- } else if (onWindows) {
- // Need better test for Windows
- assertTrue("Incorrect Number Of Root Directories.",
- roots.length > 0);
- }
- }
-
- /**
- * @tests java.io.File#mkdir()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mkdir",
- args = {}
- )
- public void test_mkdir() throws IOException {
- // Test for method boolean java.io.File.mkdir()
-
- String base = System.getProperty("java.io.tmpdir");
- // Old test left behind "garbage files" so this time it creates a
- // directory
- // that is guaranteed not to already exist (and deletes it afterward.)
- int dirNumber = 1;
- boolean dirExists = true;
- File dir = new File(base, String.valueOf(dirNumber));
- while (dirExists) {
- if (dir.exists()) {
- dirNumber++;
- dir = new File(base, String.valueOf(dirNumber));
- } else {
- dirExists = false;
- }
- }
-
- assertTrue("mkdir failed", dir.mkdir() && dir.exists());
- dir.deleteOnExit();
-
- String longDirName = "abcdefghijklmnopqrstuvwx";// 24 chars
- StringBuilder sb = new StringBuilder(dir + File.separator);
- StringBuilder sb2 = new StringBuilder(dir + File.separator);
-
- // Test make a long path
- while (dir.getCanonicalPath().length() < 256 - longDirName.length()) {
- sb.append(longDirName + File.separator);
- dir = new File(sb.toString());
- assertTrue("mkdir failed", dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
-
- while (dir.getCanonicalPath().length() < 256) {
- sb.append(0);
- dir = new File(sb.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
-
- // Test make many paths
- while (dir.getCanonicalPath().length() < 256) {
- sb2.append(0);
- dir = new File(sb2.toString());
- assertTrue("mkdir " + dir.getCanonicalPath().length() + " failed",
- dir.mkdir() && dir.exists());
- dir.deleteOnExit();
- }
- }
-
- /**
- * @tests java.io.File#mkdirs()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "mkdirs",
- args = {}
- )
- public void test_mkdirs() {
- // Test for method boolean java.io.File.mkdirs()
-
- String userHome = System.getProperty("java.io.tmpdir");
- if (!userHome.endsWith(slash))
- userHome += slash;
- File f = new File(userHome + "mdtest" + platformId + slash + "mdtest2",
- "p.tst");
- File g = new File(userHome + "mdtest" + platformId + slash + "mdtest2");
- File h = new File(userHome + "mdtest" + platformId);
- f.mkdirs();
- try {
- assertTrue("Base Directory not created", h.exists());
- assertTrue("Directories not created", g.exists());
- assertTrue("File not created", f.exists());
- } finally {
- f.delete();
- g.delete();
- h.delete();
- }
- }
-
- /**
- * @tests java.io.File#renameTo(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "renameTo",
- args = {java.io.File.class}
- )
- public void test_renameToLjava_io_File() {
- // Test for method boolean java.io.File.renameTo(java.io.File)
- String base = System.getProperty("java.io.tmpdir");
- File dir = new File(base, platformId);
- dir.mkdir();
- File f = new File(dir, "xxx.xxx");
- File rfile = new File(dir, "yyy.yyy");
- File f2 = new File(dir, "zzz.zzz");
- try {
- FileOutputStream fos = new FileOutputStream(f);
- fos.write(fileString.getBytes());
- fos.close();
- long lengthOfFile = f.length();
-
- rfile.delete(); // in case it already exists
-
- try {
- f.renameTo(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- assertTrue("Test 2: File rename failed.", f.renameTo(rfile));
- assertTrue("Test 3: File rename failed.", rfile.exists());
- assertTrue("Test 4: Size Of File Changed.",
- rfile.length() == lengthOfFile);
-
- fos = new FileOutputStream(rfile);
- fos.close();
-
- f2.delete(); // in case it already exists
- assertTrue("Test 5: File rename failed.", rfile.renameTo(f2));
- assertTrue("Test 6: File rename failed.", f2.exists());
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- f.delete();
- rfile.delete();
- f2.delete();
- dir.delete();
- }
- }
-
- /**
- * @tests java.io.File#setLastModified(long)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "setLastModified",
- args = {long.class}
- )
- public void test_setLastModifiedJ() {
- // Test for method java.io.File.setLastModified()
- File f1 = null;
- try {
- // f1 = File.createTempFile("hyts_tf" , ".tmp");
- // jclRM does not include File.createTempFile
- f1 = new File(System.getProperty("java.io.tmpdir"),
- platformId + "hyts_tf_slm.tst");
- f1.createNewFile();
- long orgTime = f1.lastModified();
- // Subtracting 100 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime - 100000));
- long lastModified = f1.lastModified();
- assertTrue("Test 1: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime - 100000));
- // Subtracting 10 000 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime - 10000000));
- lastModified = f1.lastModified();
- assertTrue("Test 2: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime - 10000000));
- // Adding 100 000 milliseconds to the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime + 100000));
- lastModified = f1.lastModified();
- assertTrue("Test 3: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime + 100000));
- // Adding 10 000 000 milliseconds from the orgTime of File f1
- assertTrue(f1.setLastModified(orgTime + 10000000));
- lastModified = f1.lastModified();
- assertTrue("Test 4: LastModifed time incorrect: " + lastModified,
- lastModified == (orgTime + 10000000));
- // Trying to set time to an exact number
- assertTrue(f1.setLastModified(315550800000L));
- lastModified = f1.lastModified();
- assertTrue("Test 5: LastModified time incorrect: " + lastModified,
- lastModified == 315550800000L);
- String osName = System.getProperty("os.name", "unknown");
- if (osName.equals("Windows 2000") || osName.equals("Windows NT")) {
- // Trying to set time to a large exact number
- boolean result = f1.setLastModified(4354837199000L);
- long next = f1.lastModified();
- // Dec 31 23:59:59 EST 2107 is overflow on FAT file systems, and
- // the call fails
- assertTrue("Test 6: LastModified time incorrect: " + next,
- !result || next == 4354837199000L);
- }
- // Trying to set time to a negative number
- try {
- f1.setLastModified(-25);
- fail("IllegalArgumentException not thrown.");
- } catch (IllegalArgumentException e) {
- }
-
- File f2 = new File("/does not exist.txt");
- assertFalse(f2.setLastModified(42));
- } catch (IOException e) {
- fail("Unexpected IOException during test : " + e.getMessage());
- } finally {
- if (f1 != null)
- f1.delete();
- }
- }
-
- /**
- * @tests java.io.File#setReadOnly()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "setReadOnly",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canWrite",
- args = {}
- )
- })
- public void test_setReadOnly() {
- // Test for method java.io.File.setReadOnly()
-
- File f1 = null;
- File f2 = null;
- Runtime r = Runtime.getRuntime();
- Process p;
- try {
- f1 = File.createTempFile("hyts_tf", ".tmp");
- f2 = File.createTempFile("hyts_tf", ".tmp");
-
- assertTrue("Test 1: File is read-only." , f1.canWrite());
- f1.setReadOnly();
- assertTrue("Test 2: File is not read-only." , !f1.canWrite());
-
- try {
- // Attempt to write to a file that is read-only.
- new FileOutputStream(f1);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- p = r.exec("chmod +w " + f1.getAbsolutePath());
- p.waitFor();
-
- assertTrue("Test 4: File is read-only." , f1.canWrite());
- try {
- FileOutputStream fos = new FileOutputStream(f1);
- fos.write(fileString.getBytes());
- fos.close();
- assertTrue("Test 5: Unable to write to the file.",
- f1.length() == fileString.length());
- } catch (IOException e) {
- fail("Test 6: Unexpected IOException while attempting to " +
- "write to the file. " + e);
- }
- assertTrue("Test 7: File has not been deleted.", f1.delete());
-
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Set To ReadOnly." , f2.canWrite());
- FileOutputStream fos = new FileOutputStream(f2);
- // Write to a file.
- fos.write(fileString.getBytes());
- fos.close();
- f2.setReadOnly();
- // Assert is flawed because canWrite does not work.
- // assertTrue("File f2 Is Not Set To ReadOnly." , !f2.canWrite());
- try {
- // Attempt to write to a file that has previously been written
- // to.
- // and is now set to read only.
- fos = new FileOutputStream(f2);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- }
- p = r.exec("chmod +w " + f2.getAbsolutePath());
- p.waitFor();
- assertTrue("Test 9: File is read-only.", f2.canWrite());
- try {
- fos = new FileOutputStream(f2);
- fos.write(fileString.getBytes());
- fos.close();
- } catch (IOException e) {
- fail("Test 10: Unexpected IOException while attempting to " +
- "write to the file. " + e);
- }
- f2.setReadOnly();
- assertTrue("Test 11: File has not been deleted.", f2.delete());
- // Similarly, trying to delete a read-only directory should succeed
- f2 = new File(System.getProperty("java.io.tmpdir"), "deltestdir");
- f2.mkdir();
- f2.setReadOnly();
- assertTrue("Test 12: Directory has not been deleted.",
- f2.delete());
- assertTrue("Test 13: Directory has not been deleted.",
- ! f2.exists());
-
- } catch (IOException e) {
- fail("Test 14: Unexpected IOException: " + e.getMessage());
- } catch (InterruptedException e) {
- fail("Test 15: Unexpected InterruptedException: " + e);
- } finally {
- if (f1 != null)
- f1.delete();
- if (f2 != null)
- f2.delete();
- }
- }
-
- /**
- * @tests java.io.File#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies toString() method.",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.File.toString()
- String fileName = System.getProperty("java.io.tmpdir") + slash + "input.tst";
- File f = new File(fileName);
- assertTrue("Incorrect string returned", f.toString().equals(fileName));
-
- if (File.separatorChar == '\\') {
- String result = new File("c:\\").toString();
- assertTrue("Removed backslash: " + result, result.equals("c:\\"));
- }
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies toURI() method.",
- method = "toURI",
- args = {}
- )
- public void test_toURI() {
- // Test for method java.io.File.toURI()
- try {
- // Need a directory that exists
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- // Test for toURI when the file is a directory.
- String newURIPath = dir.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/"))
- newURIPath = "/" + newURIPath;
- if (!newURIPath.endsWith("/"))
- newURIPath += '/';
-
- URI uri = dir.toURI();
- assertTrue("Test 1A: Incorrect URI Returned.", new File(uri)
- .equals(dir.getAbsoluteFile()));
- assertTrue("Test 1B: Incorrect URI Returned.", uri.equals(new URI(
- "file", null, newURIPath, null, null)));
-
- // Test for toURI with a file name with illegal chars.
- File f = new File(dir, "te% \u20ac st.tst");
- newURIPath = f.getAbsolutePath();
- newURIPath = newURIPath.replace(File.separatorChar, '/');
- if (!newURIPath.startsWith("/"))
- newURIPath = "/" + newURIPath;
-
- uri = f.toURI();
- assertTrue("Test 2A: Incorrect URI Returned.", new File(uri)
- .equals(f.getAbsoluteFile()));
- assertTrue("Test 2B: Incorrect URI Returned.", uri.equals(new URI(
- "file", null, newURIPath, null, null)));
-
- // Regression test for HARMONY-3207
- dir = new File(""); // current directory
- uri = dir.toURI();
- assertTrue("Test current dir: URI does not end with slash.",
- uri.toString().endsWith("/"));
- } catch (URISyntaxException e1) {
- fail("Unexpected URISyntaxException: " + e1);
- }
- }
-
- /**
- * @tests java.io.File#toURI()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that toURI() method works with URIs created with null parameters.",
- method = "toURI",
- args = {}
- )
- public void test_toURI2() {
-
- File f = new File(System.getProperty("java.io.tmpdir"), "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/"))
- path = "/" + path;
-
- try {
- URI uri1 = new URI("file", null, path, null);
- URI uri2 = f.toURI();
- assertEquals("uris not equal", uri1, uri2);
- } catch (URISyntaxException e1) {
- fail("Unexpected URISyntaxException," + e1);
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- public void test_toURL() {
- // Test for method java.io.File.toURL()
-
- try {
- // Need a directory that exists
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- // Test for toURL when the file is a directory.
- String newDirURL = dir.getAbsolutePath();
- newDirURL = newDirURL.replace(File.separatorChar, '/');
- if (newDirURL.startsWith("/"))
- newDirURL = "file:" + newDirURL;
- else
- newDirURL = "file:/" + newDirURL;
- if (!newDirURL.endsWith("/"))
- newDirURL += '/';
- assertEquals("Test 1: Incorrect URL returned;", newDirURL,
- dir.toURL().toString());
-
- // Test for toURL with a file.
- File f = new File(dir, "test.tst");
- String newURL = f.getAbsolutePath();
- newURL = newURL.replace(File.separatorChar, '/');
- if (newURL.startsWith("/"))
- newURL = "file:" + newURL;
- else
- newURL = "file:/" + newURL;
- assertEquals("Test 2: Incorrect URL returned;", newURL,
- f.toURL().toString());
- } catch (java.net.MalformedURLException e) {
- fail("Unexpected java.net.MalformedURLException during test.");
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- public void test_toURL2() {
-
- File f = new File(System.getProperty("java.io.tmpdir"), "a/b/c/../d/e/./f");
-
- String path = f.getAbsolutePath();
- path = path.replace(File.separatorChar, '/');
- if (!path.startsWith("/"))
- path = "/" + path;
-
- try {
- URL url1 = new URL("file", "", path);
- URL url2 = f.toURL();
- assertEquals("urls not equal", url1, url2);
- } catch (MalformedURLException e) {
- fail("Unexpected MalformedURLException," + e);
- }
- }
-
- /**
- * @tests java.io.File#toURL()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "toURL",
- args = {}
- )
- @AndroidOnly("Incorrectly fails on the RI.")
- public void test_toURL3() throws MalformedURLException {
- File dir = new File(""); // current directory
- String newDirURL = dir.toURL().toString();
- assertTrue("Test 1: URL does not end with slash.",
- newDirURL.endsWith("/"));
- }
-
- /**
- * @tests java.io.File#deleteOnExit()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "deleteOnExit",
- args = {}
- )
- @AndroidOnly("This test only runs on Android because it instantiates " +
- "a second Dalvik VM.")
- @KnownFailure("Fails in CTS but passes under run-core-tests")
- public void test_deleteOnExit() throws IOException, InterruptedException {
- String cts = System.getProperty("java.io.tmpdir");
- File dir = new File(cts + "/hello");
- dir.mkdir();
- assertTrue(dir.exists());
- File subDir = new File(cts + "/hello/world");
- subDir.mkdir();
- assertTrue(subDir.exists());
-
- URL url = getClass().getResource("/HelloWorld.txt");
- String classPath = url.toString();
- int idx = classPath.indexOf("!");
- assertTrue("could not find the path of the test jar/apk", idx > 0);
- classPath = classPath.substring(9, idx); // cutting off jar:file:
-
- ProcessBuilder builder = javaProcessBuilder();
- builder.command().add("-cp");
- builder.command().add(System.getProperty("java.class.path"));
- builder.command().add("tests.support.Support_DeleteOnExitTest");
- builder.command().add(dir.getAbsolutePath());
- builder.command().add(subDir.getAbsolutePath());
- execAndGetOutput(builder);
-
- assertFalse(dir.exists());
- assertFalse(subDir.exists());
- }
-
- /**
- * @tests serialization
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "regression test",
- method = "!Serialization",
- args = {}
- )
- public void test_objectStreamClass_getFields() throws Exception {
- //Regression for HARMONY-2674
- ObjectStreamClass objectStreamClass = ObjectStreamClass
- .lookup(File.class);
- ObjectStreamField[] objectStreamFields = objectStreamClass.getFields();
- assertEquals(1, objectStreamFields.length);
- ObjectStreamField objectStreamField = objectStreamFields[0];
- assertEquals("path", objectStreamField.getName());
- assertEquals(String.class, objectStreamField.getType());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- // Make sure that system properties are set correctly
- String userDir = System.getProperty("java.io.tmpdir");
- if (userDir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
- System.setProperty("java.io.tmpdir", userDir);
-
- /** Setup the temporary directory */
- if (!userDir.regionMatches((userDir.length() - 1), slash, 0, 1))
- userDir += slash;
- tempDirectory = new File(userDir + "tempDir"
- + String.valueOf(System.currentTimeMillis()));
- if (!tempDirectory.mkdir())
- System.out.println("Setup for FileTest failed (1).");
-
- /** Setup the temporary file */
- tempFile = new File(tempDirectory, "tempfile");
- FileOutputStream tempStream;
- try {
- tempStream = new FileOutputStream(tempFile.getPath(), false);
- tempStream.close();
- } catch (IOException e) {
- System.out.println("Setup for FileTest failed (2).");
- return;
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- if (tempFile.exists() && !tempFile.delete())
- System.out
- .println("FileTest.tearDown() failed, could not delete file!");
- if (!tempDirectory.delete())
- System.out
- .println("FileTest.tearDown() failed, could not delete directory!");
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FileWriterTest.java b/luni/src/test/java/tests/api/java/io/FileWriterTest.java
deleted file mode 100644
index 4f8358c..0000000
--- a/luni/src/test/java/tests/api/java/io/FileWriterTest.java
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FileWriter.class)
-public class FileWriterTest extends junit.framework.TestCase {
-
- FileWriter fw;
-
- FileInputStream fis;
-
- BufferedWriter bw;
-
- File f;
-
- FileOutputStream fos;
-
- BufferedReader br;
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() {
- // Test for method java.io.FileWriter(java.io.File)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to write correct chars", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File_IOException() {
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- try {
- fw = new FileWriter(dir);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies FileWriter(java.io.File, boolean) constructor.",
- method = "FileWriter",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ() throws Exception {
- // Test for method java.io.FileWriter(java.io.File)
- //append = true
- {
- FileWriter fileWriter = new FileWriter(f);
-
- String first = "The first string for testing. ";
- fileWriter.write(first);
- fileWriter.close();
-
- fileWriter = new FileWriter(f, true);
- String second = "The second String for testing.";
- fileWriter.write(second);
- fileWriter.close();
-
- FileReader fileReader = new FileReader(f);
- char[] out = new char[first.length() + second.length() + 10];
- int length = fileReader.read(out);
- fileReader.close();
- assertEquals(first + second, new String(out, 0, length));
- }
- //append = false
- {
- FileWriter fileWriter = new FileWriter(f);
- String first = "The first string for testing. ";
- fileWriter.write(first);
- fileWriter.close();
-
- fileWriter = new FileWriter(f, false);
- String second = "The second String for testing.";
- fileWriter.write(second);
- fileWriter.close();
-
- FileReader fileReader = new FileReader(f);
- char[] out = new char[first.length() + second.length() + 10];
- int length = fileReader.read(out);
- fileReader.close();
- assertEquals(second, new String(out, 0, length));
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.File, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.io.File.class, boolean.class}
- )
- public void test_ConstructorLjava_io_FileZ_IOException() {
- File dir = new File(System.getProperty("java.io.tmpdir"));
-
- try {
- fw = new FileWriter(dir, true);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.io.FileDescriptor)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FileWriter(java.io.FileDescriptor) constructor.",
- method = "FileWriter",
- args = {java.io.FileDescriptor.class}
- )
- public void test_ConstructorLjava_io_FileDescriptor() {
- // Test for method java.io.FileWriter(java.io.FileDescriptor)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- fis = new FileInputStream(f.getPath());
- br = new BufferedReader(new FileReader(fis.getFD()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- fis.close();
- assertTrue("Failed to write correct chars: "
- + new String(buf, 0, r), new String(buf, 0, r)
- .equals("Test String"));
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.FileWriter(java.lang.String)
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath()));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to write correct chars", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String_IOException() {
- try {
- fw = new FileWriter(System.getProperty("java.io.tmpdir"));
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "FileWriter",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ() {
- // Test for method java.io.FileWriter(java.lang.String, boolean)
-
- try {
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath(), true));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- char[] buf = new char[100];
- int r = br.read(buf);
- br.close();
- assertEquals("Failed to append to file", "Test String After test string", new String(buf, 0, r)
- );
-
- fos = new FileOutputStream(f.getPath());
- fos.write("Test String".getBytes());
- fos.close();
- bw = new BufferedWriter(new FileWriter(f.getPath(), false));
- bw.write(" After test string", 0, 18);
- bw.close();
- br = new BufferedReader(new FileReader(f.getPath()));
- buf = new char[100];
- r = br.read(buf);
- br.close();
- assertEquals("Failed to overwrite file", " After test string", new String(buf, 0, r)
- );
- } catch (Exception e) {
- fail("Exception during Constructor test " + e.toString());
- }
-
- }
-
- /**
- * @tests java.io.FileWriter#FileWriter(java.lang.String, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "FileWriter",
- args = {java.lang.String.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringZ_IOException() {
- try {
- fw = new FileWriter(System.getProperty("java.io.tmpdir"), false);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_handleEarlyEOFChar_1() {
- String str = "All work and no play makes Jack a dull boy\n";
- int NUMBER = 2048;
- int j = 0;
- int len = str.length() * NUMBER;
- /* == 88064 *//* NUMBER compulsively written copies of the same string */
- char[] strChars = new char[len];
- for (int i = 0; i < NUMBER; ++i) {
- for (int k = 0; k < str.length(); ++k) {
- strChars[j++] = str.charAt(k);
- }
- }
- File f = null;
- FileWriter fw = null;
- try {
- f = File.createTempFile("ony", "by_one");
- fw = new FileWriter(f);
- fw.write(strChars);
- fw.close();
- InputStreamReader in = null;
- FileInputStream fis = new FileInputStream(f);
- in = new InputStreamReader(fis);
- int b;
- int errors = 0;
- for (int offset = 0; offset < strChars.length; ++offset) {
- b = in.read();
- if (b == -1) {
- fail("Early EOF at offset " + offset + "\n");
- return;
- }
- }
- assertEquals(0, errors);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_handleEarlyEOFChar_2() throws IOException {
- int capacity = 65536;
- byte[] bytes = new byte[capacity];
- byte[] bs = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
- };
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = bs[i / 8192];
- }
- String inputStr = new String(bytes);
- int len = inputStr.length();
- File f = File.createTempFile("FileWriterBugTest ", null);
- FileWriter writer = new FileWriter(f);
- writer.write(inputStr);
- writer.close();
- long flen = f.length();
-
- FileReader reader = new FileReader(f);
- char[] outChars = new char[capacity];
- int outCount = reader.read(outChars);
- String outStr = new String(outChars, 0, outCount);
-
- f.deleteOnExit();
- assertEquals(len, flen);
- assertEquals(inputStr, outStr);
- }
-
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
-
- f = File.createTempFile("writer", ".tst");
-
- if (f.exists())
- if (!f.delete()) {
- fail("Unable to delete test file");
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- bw.close();
- } catch (Exception e) {
- }
- try {
- fis.close();
- } catch (Exception e) {
- }
- f.delete();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java b/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java
deleted file mode 100644
index 32dfc5c..0000000
--- a/luni/src/test/java/tests/api/java/io/FilenameFilterTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.FilenameFilter;
-import java.io.File;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = FilenameFilter.class,
- untestedMethods = {
- @TestTargetNew(
- method = "accept",
- args = {File.class , String.class},
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class FilenameFilterTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java b/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java
deleted file mode 100644
index 0c4848e..0000000
--- a/luni/src/test/java/tests/api/java/io/FilterInputStreamTest.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.util.Arrays;
-
-import tests.support.Support_ASimpleInputStream;
-import tests.support.Support_PlatformFile;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(FilterInputStream.class)
-public class FilterInputStreamTest extends junit.framework.TestCase {
-
- static class MyFilterInputStream extends java.io.FilterInputStream {
- public MyFilterInputStream(java.io.InputStream is) {
- super(is);
- }
- }
-
- private String fileName;
-
- private FilterInputStream is;
-
- byte[] ibuf = new byte[4096];
-
- private static final String testString = "Lorem ipsum dolor sit amet,\n" +
- "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
- "labore et dolore magna aliqua.\n";
-
- private static final int testLength = testString.length();
-
- /**
- * @tests java.io.FilterInputStream#InputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterInputStream(InputStream).",
- method = "FilterInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_Constructor() {
- // The FilterInputStream object has already been created in setUp().
- // If anything has gone wrong, closing it should throw a
- // NullPointerException.
- try {
- is.close();
- } catch (IOException e) {
- fail("Unexpected IOException: " + e.getMessage());
- } catch (NullPointerException npe) {
- fail("Unexpected NullPointerException.");
- }
- }
-
- /**
- * @tests java.io.FilterInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- assertEquals("Test 1: Returned incorrect number of available bytes;",
- testLength, is.available());
-
- is.close();
- try {
- is.available();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- is.close();
-
- try {
- is.read();
- fail("Test 1: Read from closed stream succeeded.");
- } catch (IOException e) {
- // Expected.
- }
-
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream(true);
- is = new MyFilterInputStream(sis);
- try {
- is.close();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sis.throwExceptionOnNextUse = false;
- }
-
- /**
- * @tests java.io.FilterInputStream#mark(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int) in combination with reset().",
- method = "mark",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int) in combination with reset().",
- method = "reset",
- args = {}
- )
- })
- public void test_markI() throws Exception {
- // Test for method void java.io.FilterInputStream.mark(int)
- final int bufSize = 10;
- byte[] buf1 = new byte[bufSize];
- byte[] buf2 = new byte[bufSize];
-
- // Purpose 1: Check that mark() does nothing if the filtered stream
- // is a FileInputStream.
- is.read(buf1, 0, bufSize);
- is.mark(2 * bufSize);
- is.read(buf1, 0, bufSize);
- try {
- is.reset();
- } catch (IOException e) {
- // Expected
- }
- is.read(buf2, 0, bufSize);
- assertFalse("Test 1: mark() should have no effect.",
- Arrays.equals(buf1, buf2));
- is.close();
-
- // Purpose 2: Check that mark() in combination with reset() works if
- // the filtered stream is a BufferedInputStream.
- is = new MyFilterInputStream(new BufferedInputStream(
- new java.io.FileInputStream(fileName), 100));
- is.read(buf1, 0, bufSize);
- is.mark(2 * bufSize);
- is.read(buf1, 0, bufSize);
- is.reset();
- is.read(buf2, 0, bufSize);
- assertTrue("Test 2: mark() or reset() has failed.",
- Arrays.equals(buf1, buf2));
- }
-
- /**
- * @tests java.io.FilterInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported() method.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() throws Exception {
- // Test for method boolean java.io.FilterInputStream.markSupported()
-
- // Test 1: Check that markSupported() returns false for a filtered
- // input stream that is known to not support mark().
- assertFalse("Test 1: markSupported() incorrectly returned true " +
- "for a FileInputStream.", is.markSupported());
- is.close();
- // Test 2: Check that markSupported() returns true for a filtered
- // input stream that is known to support mark().
- is = new MyFilterInputStream(new BufferedInputStream(
- new java.io.FileInputStream(fileName), 100));
- assertTrue("Test 2: markSupported() incorrectly returned false " +
- "for a BufferedInputStream.", is.markSupported());
- }
-
- /**
- * @tests java.io.FilterInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- int c = is.read();
- assertEquals("Test 1: Read returned incorrect char;",
- testString.charAt(0), c);
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterInputStream#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {byte[].class}
- )
- public void test_read$B() throws IOException {
- // Test for method int java.io.FilterInputStream.read(byte [])
- byte[] buf1 = new byte[100];
- is.read(buf1);
- assertTrue("Test 1: Failed to read correct data.",
- new String(buf1, 0, buf1.length).equals(
- testString.substring(0, 100)));
-
- is.close();
- try {
- is.read(buf1);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte[] buf1 = new byte[20];
- is.skip(10);
- is.read(buf1, 0, buf1.length);
- assertTrue("Failed to read correct data", new String(buf1, 0,
- buf1.length).equals(testString.substring(10, 30)));
- }
-
- /**
- * @tests FilterInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Illegal argument checks.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte[] buf = null;
- try {
- is.read(buf, -1, 0);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- buf = new byte[1000];
- try {
- is.read(buf, -1, 0);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.read(buf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.read(buf, -1, -1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.read(buf, 0, 1001);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.read(buf, 1001, 0);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- is.read(buf, 500, 501);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.read(buf, 0, 100);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterInputStream#reset()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() in combination with mark().",
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset() in combination with mark().",
- method = "mark",
- args = { int.class }
- )
- })
- public void test_reset() throws Exception {
- // Test for method void java.io.FilterInputStream.reset()
-
- // Test 1: Check that reset() throws an IOException if the
- // filtered stream is a FileInputStream.
- try {
- is.reset();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // expected
- }
-
- // Test 2: Check that reset() throws an IOException if the
- // filtered stream is a BufferedInputStream but mark() has not
- // yet been called.
- is = new MyFilterInputStream(new BufferedInputStream(
- new java.io.FileInputStream(fileName), 100));
- try {
- is.reset();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // expected
- }
-
- // Test 3: Check that reset() in combination with mark()
- // works correctly.
- final int bufSize = 10;
- byte[] buf1 = new byte[bufSize];
- byte[] buf2 = new byte[bufSize];
- is.read(buf1, 0, bufSize);
- is.mark(2 * bufSize);
- is.read(buf1, 0, bufSize);
- try {
- is.reset();
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException.");
- }
- is.read(buf2, 0, bufSize);
- assertTrue("Test 4: mark() or reset() has failed.",
- Arrays.equals(buf1, buf2));
- }
-
- /**
- * @tests java.io.FilterInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- byte[] buf1 = new byte[10];
- is.skip(10);
- is.read(buf1, 0, buf1.length);
- assertTrue("Test 1: Failed to skip to the correct position.",
- new String(buf1, 0, buf1.length).equals(
- testString.substring(10, 20)));
-
- is.close();
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- try {
- fileName = System.getProperty("java.io.tmpdir");
- String separator = System.getProperty("file.separator");
- if (fileName.charAt(fileName.length() - 1) == separator.charAt(0))
- fileName = Support_PlatformFile.getNewPlatformFile(fileName,
- "input.tst");
- else
- fileName = Support_PlatformFile.getNewPlatformFile(fileName
- + separator, "input.tst");
- java.io.OutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(testString.getBytes());
- fos.close();
- is = new MyFilterInputStream(new java.io.FileInputStream(fileName));
- } catch (java.io.IOException e) {
- System.out.println("Exception during setup");
- e.printStackTrace();
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- is.close();
- } catch (Exception e) {
- System.out.println("Unexpected exception in tearDown().");
- }
- new java.io.File(fileName).delete();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java
deleted file mode 100644
index 3ae1271..0000000
--- a/luni/src/test/java/tests/api/java/io/FilterOutputStreamTest.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(java.io.FilterOutputStream.class)
-public class FilterOutputStreamTest extends junit.framework.TestCase {
-
- private java.io.FilterOutputStream os;
-
- java.io.ByteArrayOutputStream bos;
-
- java.io.ByteArrayInputStream bis;
-
- byte[] ibuf = new byte[4096];
-
- private final String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- private final int testLength = fileString.length();
-
-
- /**
- * @tests java.io.FilterOutputStream#FilterOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies FilterOutputStream(java.io.OutputStream) constructor.",
- method = "FilterOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() {
- // Test for method java.io.FilterOutputStream(java.io.OutputStream)
- try {
- bos = new ByteArrayOutputStream();
- os = new FilterOutputStream(bos);
- os.write('t');
- } catch (java.io.IOException e) {
- fail("Constructor test failed : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.FilterOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- Support_OutputStream sos = new Support_OutputStream();
- os = new FilterOutputStream(sos);
- os.close();
-
- try {
- os.write(42);
- } catch (java.io.IOException e) {
- fail("Test 1: Unexpected IOException.");
- }
-
- sos.setThrowsException(true);
- try {
- os.write(42);
- fail("Test 2: IOException expected.");
- } catch (java.io.IOException e) {
- // Expected.
- }
-
- os = new FilterOutputStream(sos);
- try {
- os.close();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws IOException {
- Support_OutputStream sos = new Support_OutputStream(550);
- os = new FilterOutputStream(sos);
- os.write(fileString.getBytes(), 0, 500);
- os.flush();
- assertEquals("Test 1: Bytes not written after flush;",
- 500, sos.size());
-
- sos.setThrowsException(true);
- try {
- os.flush();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
- }
-
- /**
- * @tests java.io.FilterOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws IOException {
- Support_OutputStream sos = new Support_OutputStream(testLength);
- os = new FilterOutputStream(sos);
- os.write(fileString.getBytes());
-
- bis = new ByteArrayInputStream(sos.toByteArray());
- assertTrue("Test 1: Bytes have not been written.",
- bis.available() == testLength);
- byte[] wbytes = new byte[testLength];
- bis.read(wbytes, 0, testLength);
- assertTrue("Test 2: Incorrect bytes written or read.",
- fileString.equals(new String(wbytes)));
-
- try {
- // Support_OutputStream throws an IOException if the internal
- // buffer is full, which it should be now.
- os.write(42);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws IOException {
- Support_OutputStream sos = new Support_OutputStream(testLength);
- os = new FilterOutputStream(sos);
- os.write(fileString.getBytes(), 10, testLength - 10);
-
- bis = new ByteArrayInputStream(sos.toByteArray());
- assertTrue("Test 1: Bytes have not been written.",
- bis.available() == testLength - 10);
- byte[] wbytes = new byte[testLength - 10];
- bis.read(wbytes);
- assertTrue("Test 2: Incorrect bytes written or read.",
- fileString.substring(10).equals(new String(wbytes)));
-
- try {
- // Support_OutputStream throws an IOException if the internal
- // buffer is full, which it should be eventually.
- os.write(fileString.getBytes());
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII_Exception() throws IOException {
- Support_OutputStream sos = new Support_OutputStream(testLength);
- os = new FilterOutputStream(sos);
- byte[] buf = new byte[10];
-
- try {
- os.write(buf, -1, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- os.write(buf, 0, -1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- os.write(buf, 10, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- Support_OutputStream sos = new Support_OutputStream(1);
- os = new FilterOutputStream(sos);
- os.write(42);
-
- bis = new ByteArrayInputStream(sos.toByteArray());
- assertTrue("Test 1: Byte has not been written.",
- bis.available() == 1);
- assertEquals("Test 2: Incorrect byte written or read;",
- 42, bis.read());
-
- try {
- // Support_OutputStream throws an IOException if the internal
- // buffer is full, which it should be now.
- os.write(42);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- if (bos != null)
- bos.close();
- if (bis != null)
- bis.close();
- if (os != null)
- os.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilterReaderTest.java b/luni/src/test/java/tests/api/java/io/FilterReaderTest.java
deleted file mode 100644
index 644a511..0000000
--- a/luni/src/test/java/tests/api/java/io/FilterReaderTest.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.FilterReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FilterReader.class)
-public class FilterReaderTest extends junit.framework.TestCase {
-
- private boolean called;
- private FilterReader fr;
-
- static class MyFilterReader extends java.io.FilterReader {
- public MyFilterReader(java.io.Reader reader) {
- super(reader);
- }
- }
-
- class MockReader extends java.io.Reader {
- public MockReader() {
- }
-
- public void close() throws IOException {
- called = true;
- }
-
- public void mark(int readLimit) throws IOException {
- called = true;
- }
-
- public boolean markSupported() {
- called = true;
- return false;
- }
-
- public int read() throws IOException {
- called = true;
- return 0;
- }
-
- public int read(char[] buffer, int offset, int count) throws IOException {
- called = true;
- return 0;
- }
-
- public boolean ready() throws IOException {
- called = true;
- return true;
- }
-
- public void reset() throws IOException {
- called = true;
- }
-
- public long skip(long count) throws IOException {
- called = true;
- return 0;
- }
- }
-
- /**
- * @tests java.io.FilterReader#FilterReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterReader(java.io.Reader).",
- method = "FilterReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() {
-
- FilterReader myReader = null;
-
- called = true;
-
- try {
- myReader = new MyFilterReader(null);
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.FilterReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close().",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- fr.close();
- assertTrue("close() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int).",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- fr.mark(0);
- assertTrue("mark(int) has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies markSupported().",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- fr.markSupported();
- assertTrue("markSupported() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read().",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- fr.read();
- assertTrue("read() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies read(char[], int, int).",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws IOException {
- char[] buffer = new char[5];
- fr.read(buffer, 0, 5);
- assertTrue("read(char[], int, int) has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies read(char[], int, int).",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII_Exception() throws IOException {
- byte[] bbuffer = new byte[20];
- char[] buffer = new char[10];
-
- fr = new MyFilterReader(new InputStreamReader(
- new ByteArrayInputStream(bbuffer)));
-
- try {
- fr.read(buffer, 0, -1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- fr.read(buffer, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- fr.read(buffer, 10, 1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ready().",
- method = "ready",
- args = {}
- )
- public void test_ready() throws IOException {
- fr.ready();
- assertTrue("ready() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies reset().",
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- fr.reset();
- assertTrue("reset() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#skip()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long).",
- method = "skip",
- args = {long.class}
- )
- public void test_skip() throws IOException {
- fr.skip(10);
- assertTrue("skip(long) has not been called.", called);
- }
-
- /**
- * This method is called before a test is executed. It creates a
- * FilterReader instance.
- */
- protected void setUp() {
-
- fr = new MyFilterReader(new MockReader());
- called = false;
- }
-
- /**
- * This method is called after a test is executed. It closes the
- * FilterReader instance.
- */
- protected void tearDown() {
-
- try {
- fr.close();
- } catch (Exception e) {
- System.out.println("Exception during FilterReaderTest tear down.");
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/FilterWriterTest.java b/luni/src/test/java/tests/api/java/io/FilterWriterTest.java
deleted file mode 100644
index 99ddc6a..0000000
--- a/luni/src/test/java/tests/api/java/io/FilterWriterTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import tests.api.java.io.FilterReaderTest.MyFilterReader;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FilterWriter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(FilterWriter.class)
-public class FilterWriterTest extends junit.framework.TestCase {
-
- private boolean called;
- private FilterWriter fw;
-
- static class MyFilterWriter extends java.io.FilterWriter {
- public MyFilterWriter(java.io.Writer writer) {
- super(writer);
- }
- }
-
- class MockWriter extends java.io.Writer {
- public MockWriter() {
- }
-
- public void close() throws IOException {
- called = true;
- }
-
- public void flush() throws IOException {
- called = true;
- }
-
- public void write(char[] buffer, int offset, int count) throws IOException {
- called = true;
- }
-
- public void write(int oneChar) throws IOException {
- called = true;
- }
-
- public void write(String str, int offset, int count) throws IOException {
- called = true;
- }
-
- public long skip(long count) throws IOException {
- called = true;
- return 0;
- }
- }
-
- /**
- * @tests java.io.FilterWriter#FilterReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor FilterWriter(java.io.Writer).",
- method = "FilterWriter",
- args = {java.io.Writer.class}
- )
- public void test_ConstructorLjava_io_Writer() {
-
- FilterWriter myWriter = null;
-
- called = true;
-
- try {
- myWriter = new MyFilterWriter(null);
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.FilterWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close().",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- fw.close();
- assertTrue("close() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies flush().",
- method = "flush",
- args = {}
- )
- public void test_flush() throws IOException {
- fw.flush();
- assertTrue("flush() has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(int).",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- fw.write(0);
- assertTrue("write(int) has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(char[], int, int).",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() throws IOException {
- char[] buffer = new char[5];
- fw.write(buffer, 0, 5);
- assertTrue("write(char[], int, int) has not been called.", called);
- }
-
- /**
- * @tests java.io.FilterReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(char[], int, int).",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() throws IOException {
- char[] buffer = new char[10];
-
- fw = new MyFilterWriter(new OutputStreamWriter(
- new ByteArrayOutputStream()));
-
- try {
- fw.write(buffer, 0, -1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- fw.write(buffer, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- fw.write(buffer, 10, 1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.FilterWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(String, int, int).",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() throws IOException {
- fw.write("Hello world", 0, 5);
- assertTrue("write(String, int, int) has not been called.", called);
- }
-
- /**
- * This method is called before a test is executed. It creates a
- * FilterWriter instance.
- */
- protected void setUp() {
-
- fw = new MyFilterWriter(new MockWriter());
- called = false;
- }
-
- /**
- * This method is called after a test is executed. It closes the
- * FilterWriter instance.
- */
- protected void tearDown() {
-
- try {
- fw.close();
- } catch (Exception e) {
- System.out.println("Exception during FilterWriterTest tear down.");
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/IOExceptionTest.java b/luni/src/test/java/tests/api/java/io/IOExceptionTest.java
deleted file mode 100644
index 8223beb..0000000
--- a/luni/src/test/java/tests/api/java/io/IOExceptionTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.IOException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(IOException.class)
-public class IOExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.IOException#IOException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "IOException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new IOException();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.IOException#IOException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "IOException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // Needed to avoid unreachable code compilation error.
- throw new IOException("Something went wrong.");
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java b/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
deleted file mode 100644
index 879bf4e..0000000
--- a/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
+++ /dev/null
@@ -1,756 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.util.Arrays;
-
-import tests.support.Support_ASimpleInputStream;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-/**
- *
- */
-@TestTargetClass(InputStreamReader.class)
-public class InputStreamReaderTest extends TestCase {
-
- private final String source = "This is a test message with Unicode character. \u4e2d\u56fd is China's name in Chinese";
-
- private InputStream in;
-
- private InputStreamReader reader;
-
- private InputStreamReader is;
-
- private InputStream fis;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\n";
-
- static class LimitedByteArrayInputStream extends ByteArrayInputStream {
-
- // A ByteArrayInputStream that only returns a single byte per read
- byte[] bytes;
-
- int count;
-
- public LimitedByteArrayInputStream(int type) {
- super(new byte[0]);
- switch (type) {
- case 0:
- bytes = new byte[] { 0x61, 0x72 };
- break;
- case 1:
- bytes = new byte[] { (byte) 0xff, (byte) 0xfe, 0x61, 0x72 };
- break;
- case 2:
- bytes = new byte[] { '\u001b', '$', 'B', '6', 'e', 'B', 'h',
- '\u001b', '(', 'B' };
- break;
- }
- count = bytes.length;
- }
-
- public int read() {
- if (count == 0)
- return -1;
- count--;
- return bytes[bytes.length - count];
- }
-
- public int read(byte[] buffer, int offset, int length) {
- if (count == 0)
- return -1;
- if (length == 0)
- return 0;
- buffer[offset] = bytes[bytes.length - count];
- count--;
- return 1;
- }
-
- public int available() {
- return count;
- }
- }
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- try {
- in = new ByteArrayInputStream(source.getBytes("UTF-8"));
- reader = new InputStreamReader(in, "UTF-8");
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- OutputStreamWriter osw = new OutputStreamWriter(bos);
- char[] buf = new char[fileString.length()];
- fileString.getChars(0, fileString.length(), buf, 0);
- osw.write(buf);
- osw.close();
- fis = new ByteArrayInputStream(bos.toByteArray());
- is = new InputStreamReader(fis);
- } catch (Exception e) {
- fail("Exception during setUp : " + e.getMessage());
- }
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- try {
- in.close();
- is.close();
- fis.close();
- } catch (IOException e) {
- }
-
- super.tearDown();
- }
-
- /*
- * Class under test for int read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
- public void testRead() throws IOException {
- assertEquals('T', (char) reader.read());
- assertEquals('h', (char) reader.read());
- assertEquals('i', (char) reader.read());
- assertEquals('s', (char) reader.read());
- assertEquals(' ', (char) reader.read());
- reader.read(new char[source.length() - 5], 0, source.length() - 5);
- assertEquals(-1, reader.read());
- }
-
- /*
- * Class under test for int read()
- * Regression for Harmony-411
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
-
- public void testRead1() throws IOException {
- // if the decoder is constructed by InputStreamReader itself, the decoder's
- // default error action is REPLACE
- InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), "UTF-8");
- assertEquals("read() return incorrect value", 65533, isr.read());
-
- InputStreamReader isr2 = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), Charset.forName("UTF-8"));
- assertEquals("read() return incorrect value", 65533, isr2.read());
-
- // if the decoder is passed in, keep its status intacted
- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- InputStreamReader isr3 = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), decoder);
- try{
- isr3.read();
- fail("Should throw MalformedInputException");
- }catch(MalformedInputException e){
- //expected
- }
-
- CharsetDecoder decoder2 = Charset.forName("UTF-8").newDecoder();
- decoder2.onMalformedInput(CodingErrorAction.IGNORE);
- InputStreamReader isr4 = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), decoder2);
- assertEquals("read() return incorrect value", -1, isr4.read());
-
- CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
- decoder3.onMalformedInput(CodingErrorAction.REPLACE);
- InputStreamReader isr5 = new InputStreamReader(new ByteArrayInputStream(
- new byte[] { -32, -96 }), decoder3);
- assertEquals("read() return incorrect value", 65533, isr5.read());
- }
-
- /*
- * Class under test for int read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void testReadcharArrayintint() throws IOException {
- try {
- reader.read(new char[3], -1, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 0, -1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 4, 0);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 3, 1);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 1, 3);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
- try {
- reader.read(new char[3], 0, 4);
- fail("Should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- //expected
- }
-
- try {
- reader.read(null, 0, 0);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- //expected
- }
-
- assertEquals(0, reader.read(new char[3], 3, 0));
- char[] chars = new char[source.length()];
- assertEquals(0, reader.read(chars, 0, 0));
- assertEquals(0, chars[0]);
- assertEquals(3, reader.read(chars, 0, 3));
- assertEquals(5, reader.read(chars, 3, 5));
- assertEquals(source.length() - 8, reader.read(chars, 8,
- chars.length - 8));
- assertTrue(Arrays.equals(chars, source.toCharArray()));
- assertEquals(-1, reader.read(chars, 0, chars.length));
- assertTrue(Arrays.equals(chars, source.toCharArray()));
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void testReadcharArrayintint2() throws IOException {
- char[] chars = new char[source.length()];
- assertEquals(source.length() - 3, reader.read(chars, 0,
- chars.length - 3));
- assertEquals(3, reader.read(chars, 0, 10));
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "ready",
- args = {}
- )
- public void testReady() throws IOException {
- assertTrue(reader.ready());
- reader.read(new char[source.length()]);
- assertFalse(reader.ready());
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking missed.",
- method = "read",
- args = {}
- )
- public void testSpecialCharsetReading() throws Exception {
- reader.close();
- in = this.getClass().getClassLoader().getResourceAsStream(
- "tests/api/java/io/testfile-utf8.txt");
- reader = new InputStreamReader(in, "utf-8");
- int c;
- StringBuffer sb = new StringBuffer();
- while ((c = reader.read()) != -1) {
- sb.append((char) c);
- }
- // delete BOM
- assertEquals(source, sb.deleteCharAt(0).toString());
-
- sb.setLength(0);
- reader.close();
- in = this.getClass().getClassLoader().getResourceAsStream(
- "tests/api/java/io/testfile.txt");
- reader = new InputStreamReader(in, "GB2312");
-
- while ((c = reader.read()) != -1) {
- sb.append((char) c);
- }
- assertEquals(source, sb.toString());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "read",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IOException checking.",
- method = "ready",
- args = {}
- )
- })
- public void testAfterClose() throws IOException {
- reader.close();
- in = new BufferedInputStream(this.getClass().getClassLoader()
- .getResourceAsStream("tests/api/java/io/testfile-utf8.txt"));
- reader = new InputStreamReader(in, "utf-8");
- in.close();
- try {
- int count = reader.read(new char[1]);
- fail("count:" + count);
- } catch (IOException e) {
- }
- try {
- reader.read();
- fail();
- } catch (IOException e) {
- }
-
- assertFalse(reader.ready());
- Charset cs = Charset.forName("utf-8");
- assertEquals(cs, Charset.forName(reader.getEncoding()));
- reader.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- public void testInputStreamReaderInputStream() throws IOException {
- try {
- reader = new InputStreamReader(null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in);
- reader2.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.lang.String.class}
- )
- public void testInputStreamReaderInputStreamString() throws IOException {
- try {
- reader = new InputStreamReader(null, "utf-8");
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (String) null);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, "");
- fail();
- } catch (UnsupportedEncodingException e) {
- }
- try {
- reader = new InputStreamReader(in, "badname");
- fail();
- } catch (UnsupportedEncodingException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in, "utf-8");
- assertEquals(Charset.forName(reader2.getEncoding()), Charset
- .forName("utf-8"));
- reader2.close();
- reader2 = new InputStreamReader(in, "utf8");
- assertEquals(Charset.forName(reader2.getEncoding()), Charset
- .forName("utf-8"));
- reader2.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, CharsetDecoder)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.nio.charset.CharsetDecoder.class}
- )
- public void testInputStreamReaderInputStreamCharsetDecoder()
- throws Exception {
- CharsetDecoder decoder = Charset.forName("utf-8").newDecoder();
- try {
- reader = new InputStreamReader(null, decoder);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (CharsetDecoder) null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in, decoder);
- assertEquals(Charset.forName(reader2.getEncoding()), decoder.charset());
- reader2.close();
- }
-
- /*
- * Class under test for void InputStreamReader(InputStream, Charset)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InputStreamReader",
- args = {java.io.InputStream.class, java.nio.charset.Charset.class}
- )
- public void testInputStreamReaderInputStreamCharset() throws IOException {
- Charset cs = Charset.forName("utf-8");
- try {
- reader = new InputStreamReader(null, cs);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- reader = new InputStreamReader(in, (Charset) null);
- fail();
- } catch (NullPointerException e) {
- }
- InputStreamReader reader2 = new InputStreamReader(in, cs);
- assertEquals(Charset.forName(reader2.getEncoding()), cs);
- reader2.close();
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void testInputStreamReaderSuccessiveReads() throws IOException {
- byte[] data = new byte[8192 * 2];
- Arrays.fill(data, (byte) 116); // 116 = ISO-8859-1 value for 't'
- ByteArrayInputStream bis = new ByteArrayInputStream(data);
- InputStreamReader isr = new InputStreamReader(bis, "ISO-8859-1");
-
- // One less than the InputStreamReader.BUFFER_SIZE
- char[] buf = new char[8191];
- int bytesRead = isr.read(buf, 0, buf.length);
- if (bytesRead == -1) {
- throw new RuntimeException();
- }
- bytesRead = isr.read(buf, 0, buf.length);
- if (bytesRead == -1) {
- throw new RuntimeException();
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "See setUp.",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.InputStreamReader(java.io.InputStream)
- assertTrue("Used to test other methods", true);
- }
-
- /**
- * @tests java.io.InputStreamReader#InputStreamReader(java.io.InputStream,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies InputStreamReader(java.io.InputStream) constructor.",
- method = "InputStreamReader",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
- // Test for method java.io.InputStreamReader(java.io.InputStream,
- // java.lang.String)
- try {
- is = new InputStreamReader(fis, "8859_1");
- } catch (UnsupportedEncodingException e) {
- fail("Unable to create input stream : " + e.getMessage());
- }
-
- try {
- is = new InputStreamReader(fis, "Bogus");
- } catch (UnsupportedEncodingException e) {
- return;
- }
- fail("Failed to throw Unsupported Encoding exception");
- }
-
- /**
- * @tests java.io.InputStreamReader#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.InputStreamReader.close()
- try {
- is.close();
- } catch (IOException e) {
- fail("Failed to close reader : " + e.getMessage());
- }
- try {
- is.read();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Exception means read failed due to close
- }
-
- is = new InputStreamReader(new Support_ASimpleInputStream(true));
- try {
- is.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "close",
- args = {}
- )
- public void testClose() throws IOException {
- reader.close();
- try {
- reader.ready();
- fail("Should throw IOException");
- } catch (IOException e) {
- }
- reader.close();
- }
-
- /**
- * @tests java.io.InputStreamReader#getEncoding()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies getEncoding() method.",
- method = "getEncoding",
- args = {}
- )
- public void test_getEncoding() {
- // Test for method java.lang.String
- // java.io.InputStreamReader.getEncoding()
- try {
- is = new InputStreamReader(fis, "8859_1");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Returned incorrect encoding",
- "8859_1", is.getEncoding());
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException{
- // Test for method int java.io.InputStreamReader.read()
- try {
- int c = is.read();
- assertTrue("returned incorrect char", (char) c == fileString
- .charAt(0));
- InputStreamReader reader = new InputStreamReader(
- new ByteArrayInputStream(new byte[] { (byte) 0xe8,
- (byte) 0x9d, (byte) 0xa5 }), "UTF8");
- assertTrue("wrong double byte char", reader.read() == '\u8765');
- } catch (IOException e) {
- fail("Exception during read test : " + e.getMessage());
- }
-
- // Regression for HARMONY-166
- InputStream in;
- InputStreamReader reader;
-
- in = new LimitedByteArrayInputStream(0);
- reader = new InputStreamReader(in, "UTF-16BE");
- assertEquals("Incorrect byte UTF-16BE", '\u6172', reader.read());
-
- in = new LimitedByteArrayInputStream(0);
- reader = new InputStreamReader(in, "UTF-16LE");
- assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
- in = new LimitedByteArrayInputStream(1);
- reader = new InputStreamReader(in, "UTF-16");
- assertEquals("Incorrect byte UTF-16BE", '\u7261', reader.read());
-
- in = new LimitedByteArrayInputStream(2);
- reader = new InputStreamReader(in, "ISO2022JP");
- assertEquals("Incorrect byte ISO2022JP 1", '\u4e5d', reader.read());
- assertEquals("Incorrect byte ISO2022JP 2", '\u7b2c', reader.read());
- }
-
- /**
- * @tests java.io.InputStreamReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() {
- // Test for method int java.io.InputStreamReader.read(char [], int, int)
- try {
- char[] rbuf = new char[100];
- char[] sbuf = new char[100];
- fileString.getChars(0, 100, sbuf, 0);
- is.read(rbuf, 0, 100);
- for (int i = 0; i < rbuf.length; i++)
- assertTrue("returned incorrect chars", rbuf[i] == sbuf[i]);
- } catch (IOException e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.InputStreamReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "[No verification for empty buffer]",
- method = "ready",
- args = {}
- )
- public void test_ready() {
- // Test for method boolean java.io.InputStreamReader.ready()
- try {
- assertTrue("Ready test failed", is.ready());
- is.read();
- assertTrue("More chars, but not ready", is.ready());
- } catch (IOException e) {
- fail("Exception during ready test : " + e.getMessage());
- }
- }
-
- /**
- * Test for regression of a bug that dropped characters when
- * multibyte encodings spanned buffer boundaries.
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_readWhenCharacterSpansBuffer() {
- final byte[] suffix = {
- (byte) 0x93, (byte) 0xa1, (byte) 0x8c, (byte) 0xb4,
- (byte) 0x97, (byte) 0x43, (byte) 0x88, (byte) 0xea,
- (byte) 0x98, (byte) 0x59
- };
- final char[] decodedSuffix = {
- (char) 0x85e4, (char) 0x539f, (char) 0x4f51, (char) 0x4e00,
- (char) 0x90ce
- };
- final int prefixLength = 8189;
-
- byte[] bytes = new byte[prefixLength + 10];
- Arrays.fill(bytes, (byte) ' ');
- System.arraycopy(suffix, 0, bytes, prefixLength, suffix.length);
- ByteArrayInputStream is = new ByteArrayInputStream(bytes);
-
- try {
- InputStreamReader isr = new InputStreamReader(is, "SHIFT_JIS");
- char[] chars = new char[8192];
- int at = 0;
-
- for (;;) {
- int amt = isr.read(chars);
- if (amt <= 0) {
- break;
- }
-
- for (int i = 0; i < amt; i++) {
- char c = chars[i];
- if (at < prefixLength) {
- if (c != ' ') {
- fail("Found bad prefix character " +
- (int) c + " at " + at);
- }
- } else {
- char decoded = decodedSuffix[at - prefixLength];
- if (c != decoded) {
- fail("Found mismatched character " +
- (int) c + " at " + at);
- }
- }
- at++;
- }
- }
- } catch (IOException ex) {
- throw new RuntimeException("unexpected exception", ex);
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InputStreamTest.java b/luni/src/test/java/tests/api/java/io/InputStreamTest.java
deleted file mode 100644
index d1f531c..0000000
--- a/luni/src/test/java/tests/api/java/io/InputStreamTest.java
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-
-@TestTargetClass(InputStream.class)
-public class InputStreamTest extends junit.framework.TestCase {
-
- public static final String testString = "Lorem ipsum dolor sit amet,\n" +
- "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
- "labore et dolore magna aliqua.\n";
-
- private InputStream is;
-
- class MockInputStream extends java.io.InputStream {
-
- private byte[] input;
- private int position;
-
- public MockInputStream() {
- super();
- input = testString.getBytes();
- position = 0;
- }
-
- public int read() throws IOException {
- int result = -1;
- if (position < input.length) {
- result = input[position];
- position++;
- }
- return result;
- }
- }
-
- /**
- * @tests java.io.InputStream#InputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies constructor InputStream(). Since this constructor does nothing, this test is intentionally kept basic.",
- method = "InputStream",
- args = {}
- )
- public void test_Constructor() {
- try {
- InputStream myIS = new MockInputStream();
- myIS.close();
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.InputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that available() returns 0.",
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- assertEquals(is.available(), 0);
- }
-
- /**
- * @tests java.io.InputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies close(). Since this method does nothing, this test is intentionally kept basic.",
- method = "close",
- args = {}
- )
- public void test_close() {
- try {
- is.close();
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.InputStream#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies mark(int). Since this method does nothing, this test is intentionally kept basic.",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- try {
- is.mark(10);
- } catch (Exception e) {
- fail("Unexpected exception: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.InputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that markSupported() returns false.",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() throws IOException {
- assertFalse("markSupported() has returned the wrong default value.",
- is.markSupported());
- }
-
- /**
- * @tests java.io.InputStream#read(byte[])
- */
- @TestTargets (
- { @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read(byte[]).",
- method = "read",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectInput.read(byte[]) since " +
- "ObjectInputStream inherits the implementation " +
- "of read(byte[]) from InputStream.",
- clazz = ObjectInput.class,
- method = "read",
- args = {byte[].class}
- )
- }
-
- )
- public void test_read$B() throws IOException {
- byte[] b = new byte[10];
- byte[] ref = testString.getBytes();
- boolean equal = true;
- int bytesRead = 0;
- int i;
-
- // Test 1: This read operation should complete without an error.
- assertEquals("Test 1: Incorrect count of bytes read.",
- is.read(b), 10);
-
- for (i = 0; i < 10; i++) {
- equal &= (b[i] == ref[i]);
- }
- assertTrue("Test 1: Wrong bytes read.", equal);
-
- // Test 2: Test that the correct number of bytes read is returned
- // if the source has less bytes available than fit in the buffer.
- b = new byte[ref.length];
- bytesRead = is.read(b);
- assertEquals("Test 2: Incorrect count of bytes read.",
- bytesRead, ref.length - 10);
-
- for (i = 0; i < bytesRead; i++) {
- equal &= (b[i] == ref[i + 10]);
- }
- assertTrue("Test 2: Wrong bytes read.", equal);
-
- // Test 3: Since we have now reached the end of the source,
- // the next call of read(byte[]) should return -1.
- bytesRead = is.read(b);
- assertEquals("Test 3:", bytesRead, -1);
- }
-
- /**
- * @tests java.io.InputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verifies argument checking of read(byte[], int, int).",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte[] b = new byte[10];
- int bytesRead = 0;
-
- // Test 1: Invalid offset.
- try {
- bytesRead = is.read(b, -1, 5);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // Test 2: Invalid length.
- try {
- bytesRead = is.read(b, 5, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // Test 3: Invalid offset and length combination (sum is larger
- // than the length of b).
- try {
- bytesRead = is.read(b, 6, 5);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- // Test 4: Border case.
- try {
- bytesRead = is.read(b, 6, 4);
- } catch (IndexOutOfBoundsException e) {
- fail("Test 4: Unexpected IndexOutOfBoundsException.");
- }
- assertEquals("Test 4:", bytesRead, 4);
-
- // Test 5: Border case.
- try {
- bytesRead = is.read(b, 6, 0);
- } catch (Exception e) {
- fail("Test 5: Unexpected Exception " + e.getMessage());
- }
- assertEquals("Test 5:", bytesRead, 0);
- }
-
- /**
- * @tests java.io.InputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies read(byte[], int, int).",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte[] b = new byte[10];
- byte[] ref = testString.getBytes();
- boolean equal = true;
- int bytesRead = 0;
- int i;
-
- // Test 1: This read operation should complete without an error.
- assertEquals("Test 1: Incorrect count of bytes read.",
- is.read(b, 0, 5), 5);
-
- for (i = 0; i < 5; i++) {
- equal &= (b[i] == ref[i]);
- }
- assertTrue("Test 1: Wrong bytes read.", equal);
-
- // Test 2: Read operation with offset.
- assertEquals("Test 2: Incorrect count of bytes read.",
- is.read(b, 5, 3), 3);
-
- for (i = 5; i < 8; i++) {
- equal &= (b[i] == ref[i]);
- }
- assertTrue("Test 2: Wrong bytes read.", equal);
-
- // Test 3: Test that the correct number of bytes read is returned
- // if the source has less bytes available than fit in the buffer.
- b = new byte[ref.length];
- bytesRead = is.read(b, 2, b.length - 2);
-
- // 8 bytes have been read during tests 1 and 2.
- assertEquals("Test 3: Incorrect count of bytes read.",
- bytesRead, ref.length - 8);
-
- // The first two bytes of b should be 0 because of the offset.
- assertEquals("Test 3:", b[0], 0);
- assertEquals("Test 3:", b[1], 0);
- for (i = 0; i < bytesRead; i++) {
- equal &= (b[i + 2] == ref[i + 8]);
- }
- assertTrue("Test 2: Wrong bytes read.", equal);
-
- // Test 4: Since we have now reached the end of the source,
- // the next call of read(byte[], int, int) should return -1.
- assertEquals("Test 4:", is.read(b, 0, 2), -1);
- }
-
- /**
- * @tests java.io.InputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that reset() throws an IOException.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- try {
- is.reset();
- fail("IOException expected.");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.InputStream#skip(long)
- */
- @TestTargets (
- { @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies skip(long).",
- method = "skip",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectInput.skip(long) since " +
- "ObjectInputStream inherits the implementation " +
- "of skip(long) from InputStream.",
- clazz = ObjectInput.class,
- method = "skip",
- args = {long.class}
- )
- }
- )
- public void test_skipL() throws IOException {
- byte[] b = new byte[12];
- byte[] ref = testString.getBytes();
- int i;
- boolean equal = true;
-
- // Test 1: Check that skip(long) just returns 0 if called with a
- // negative number.
- assertEquals("Test 1:", is.skip(-42), 0);
- assertEquals("Test 1: Incorrect count of bytes read.",
- is.read(b), 12);
- for (i = 0; i < 12; i++) {
- equal &= (b[i] == ref[i]);
- }
- assertTrue("Test 1: Wrong bytes read.", equal);
-
- // Test 2: Check if the number of bytes skipped matches the requested
- // number of bytes to skip.
- assertEquals("Test 2: Incorrect count of bytes skipped.",
- is.skip(17), 17);
-
- // Test 3: Check that bytes have actually been skipped
- is.read(b, 0, 10);
- for (i = 0; i < 10; i++) {
- equal &= (b[i] == ref[i + 29]);
- }
- assertTrue("Test 3: Wrong bytes read.", equal);
-
- // Test 4: Test that the correct number of bytes skipped is returned
- // if the source has less bytes available than fit in the buffer.
- assertEquals("Test 4: Incorrect count of bytes skipped.",
- is.skip(ref.length), ref.length - 39);
-
- // Test 5: Since we have now reached the end of the source,
- // the next call of read(byte[]) should return -1 and calling
- // skip(long) should return 0.
- assertEquals("Test 5:", is.read(b), -1);
- assertEquals("Test 5:", is.skip(10), 0);
- }
-
- /**
- * This method is called before a test is executed. It creates a
- * MockInputStream instance.
- */
- protected void setUp() {
- is = new MockInputStream();
- }
-
- /**
- * This method is called after a test is executed. It closes the
- * MockInputStream instance.
- */
- protected void tearDown() {
- try {
- is.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java b/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java
deleted file mode 100644
index 90ad5d8..0000000
--- a/luni/src/test/java/tests/api/java/io/InterruptedIOExceptionTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.InterruptedIOException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(InterruptedIOException.class)
-public class InterruptedIOExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InterruptedIOException#InterruptedIOException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InterruptedIOException",
- args = {}
- )
- public void test_Constructor() {
- // Test for method java.io.InterruptedIOException()
- try {
- throw new InterruptedIOException();
- } catch (InterruptedIOException e) {
- return;
- } catch (Exception e) {
- fail("Exception during InterruptedIOException test"
- + e.toString());
- }
- fail("Failed to generate exception");
- }
-
- /**
- * @tests java.io.InterruptedIOException#InterruptedIOException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InterruptedIOException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.InterruptedIOException(java.lang.String)
- try {
- throw new InterruptedIOException("Some error message");
- } catch (InterruptedIOException e) {
- return;
- } catch (Exception e) {
- fail("Exception during InterruptedIOException test"
- + e.toString());
- }
- fail("Failed to generate exception");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java b/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java
deleted file mode 100644
index 6bd184b..0000000
--- a/luni/src/test/java/tests/api/java/io/InvalidClassExceptionTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import java.io.InvalidClassException;
-
-@TestTargetClass(InvalidClassException.class)
-public class InvalidClassExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidClassException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- final String message = "A message";
- try {
- if (true)
- throw new java.io.InvalidClassException(message);
- } catch (InvalidClassException e) {
- // correct
- assertTrue("Incorrect message read", e.getMessage().equals(message));
- return;
- }
- fail("Failed to throw exception");
- }
-
- /**
- * @tests java.io.InvalidClassException#InvalidClassException(java.lang.String,
- * java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "InvalidClassException",
- args = {java.lang.String.class, java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- })
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.InvalidClassException(java.lang.String,
- // java.lang.String)
- final String message = "A message";
- final String className = "Object";
- try {
- if (true)
- throw new java.io.InvalidClassException(className, message);
- } catch (InvalidClassException e) {
- // correct
- String returnedMessage = e.getMessage();
- assertTrue("Incorrect message read: " + e.getMessage(),
- returnedMessage.indexOf(className) >= 0
- && returnedMessage.indexOf(message) >= 0);
- return;
- }
- fail("Failed to throw exception");
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java b/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java
deleted file mode 100644
index a3322f2..0000000
--- a/luni/src/test/java/tests/api/java/io/InvalidObjectExceptionTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.InvalidObjectException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(java.io.InvalidObjectException.class)
-public class InvalidObjectExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.InvalidObjectException#InvalidObjectException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the InvalidObjectException(java.lang.String) constructor.",
- method = "InvalidObjectException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.InvalidObjectException(java.lang.String)
- try {
- if (true) throw new InvalidObjectException("This object is not valid.");
- fail("Exception not thrown.");
- } catch (InvalidObjectException e) {
- assertEquals("The exception message is not equal to the one " +
- "passed to the constructor.",
- "This object is not valid.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java b/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java
deleted file mode 100644
index 119df10..0000000
--- a/luni/src/test/java/tests/api/java/io/LineNumberInputStreamTest.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.LineNumberInputStream;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@SuppressWarnings("deprecation")
-@TestTargetClass(
- value = LineNumberInputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "LineNumberInputStream",
- args = {java.io.InputStream.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "Simply calls super(in). If this fails, " +
- "none of the other tests would work."
- )
- }
-)
-public class LineNumberInputStreamTest extends junit.framework.TestCase {
-
- final String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n501";
-
- String dosText = "0\r\n1\r\n2";
-
- LineNumberInputStream lnis;
-
- LineNumberInputStream lnis2;
-
- /**
- * @tests java.io.LineNumberInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- assertEquals("Test 1: Returned incorrect number of available bytes;",
- text.length() / 2, lnis.available());
-
- lnis.close();
- try {
- lnis.available();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#getLineNumber()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLineNumber",
- args = {}
- )
- public void test_getLineNumber() {
- // Test for method int java.io.LineNumberInputStream.getLineNumber()
- assertEquals("New stream returned line number other than zero", 0, lnis
- .getLineNumber());
- try {
- lnis.read();
- lnis.read();
- } catch (IOException e) {
- fail("Exception during getLineNumber test : " + e.getMessage());
- }
- assertEquals("stream returned incorrect line number after read", 1, lnis
- .getLineNumber());
- lnis.setLineNumber(89);
- assertEquals("stream returned incorrect line number after set", 89, lnis
- .getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberInputStream#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- // Test for method void java.io.LineNumberInputStream.mark(int)
- try {
- lnis.mark(40);
- lnis.skip(4);
- lnis.reset();
- assertEquals("Failed to mark", 0, lnis.getLineNumber());
- assertEquals("Failed to mark", '0', lnis.read());
- } catch (IOException e) {
- fail("Exception during mark test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- assertEquals("Test 1: Failed to read correct byte;",
- '0', lnis.read());
- assertEquals("Test 2: Failed to read correct byte on dos text;",
- '0', lnis2.read());
- assertEquals("Test 3: Failed to read correct byte on dos text;",
- '\n', lnis2.read());
- assertEquals("Test 4: Failed to read correct byte on dos text;",
- '1', lnis2.read());
- assertEquals("Test 5: Failed to read correct byte on dos text;",
- '\n', lnis2.read());
- assertEquals("Test 6: Failed to read correct byte on dos text;",
- '2', lnis2.read());
-
- lnis.close();
- try {
- lnis.read();
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- byte[] buf = new byte[100];
- lnis.read(buf, 0, 100);
- assertTrue("Test 1: Incorrect bytes read.",
- new String(buf, 0, 100).equals(text.substring(0, 100)));
-
- lnis.close();
- try {
- lnis.read(buf, 0, 100);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- byte[] buf = new byte[10];
-
- try {
- lnis.read(buf, -1, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnis.read(buf, 0, -1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnis.read(buf, 10, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException checking missed.",
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- lnis.mark(40);
- lnis.skip(4);
- lnis.reset();
- assertEquals("Test 1: Failed to reset", 0, lnis.getLineNumber());
- assertEquals("Test 2: Failed to reset", '0', lnis.read());
- lnis.reset();
-
- try {
- lnis.mark(5);
- lnis.skip(100);
- lnis.reset();
- fail("Test 3: Failed to invalidate mark.");
- } catch (IOException e) {
- // Correct; mark has been invalidated.
- }
-
- lnis.mark(5);
- lnis.close();
- try {
- lnis.reset();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberInputStream#setLineNumber(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLineNumber",
- args = {int.class}
- )
- public void test_setLineNumberI() {
- lnis.setLineNumber(42);
- assertEquals("Test 1: Failed to set line number;",
- 42, lnis.getLineNumber());
- // Repeat the test with a different number to make sure that the
- // line number is really set.
- lnis.setLineNumber(89);
- assertEquals("Test 2: Failed to set line number;",
- 89, lnis.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- long skipped = lnis.skip(4);
- assertEquals("Test 1: Incorrect number of characters skipped;",
- 4, skipped);
- assertEquals("Test 2: Skip failed to increment line number;",
- 2, lnis.getLineNumber());
-
- lnis.close();
- try {
- lnis.skip(4);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- protected void setUp() {
- /*
- * In order for IOException to be thrown in reset(),the inputStream to
- * the constructor cannot be a byteArrayInputstream because the reset()
- * in byteArrayInputStream does not throw IOException. When
- * BufferedInputStream is used, the size of the buffer must be smaller
- * than the readlimit in mark inorder for IOException to be thrown
- */
- BufferedInputStream buftemp = new BufferedInputStream(
- new ByteArrayInputStream(text.getBytes()), 4);
- lnis = new LineNumberInputStream(buftemp);
- lnis2 = new LineNumberInputStream(new ByteArrayInputStream(dosText
- .getBytes()));
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java b/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java
deleted file mode 100644
index 316ff44..0000000
--- a/luni/src/test/java/tests/api/java/io/LineNumberReaderTest.java
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.IOException;
-import java.io.LineNumberReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(LineNumberReader.class)
-public class LineNumberReaderTest extends junit.framework.TestCase {
-
- String text = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n80\n81\n82\n83\n84\n85\n86\n87\n88\n89\n90\n91\n92\n93\n94\n95\n96\n97\n98\n99\n100\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n146\n147\n148\n149\n150\n151\n152\n153\n154\n155\n156\n157\n158\n159\n160\n161\n162\n163\n164\n165\n166\n167\n168\n169\n170\n171\n172\n173\n174\n175\n176\n177\n178\n179\n180\n181\n182\n183\n184\n185\n186\n187\n188\n189\n190\n191\n192\n193\n194\n195\n196\n197\n198\n199\n200\n201\n202\n203\n204\n205\n206\n207\n208\n209\n210\n211\n212\n213\n214\n215\n216\n217\n218\n219\n220\n221\n222\n223\n224\n225\n226\n227\n228\n229\n230\n231\n232\n233\n234\n235\n236\n237\n238\n239\n240\n241\n242\n243\n244\n245\n246\n247\n248\n249\n250\n251\n252\n253\n254\n255\n256\n257\n258\n259\n260\n261\n262\n263\n264\n265\n266\n267\n268\n269\n270\n271\n272\n273\n274\n275\n276\n277\n278\n279\n280\n281\n282\n283\n284\n285\n286\n287\n288\n289\n290\n291\n292\n293\n294\n295\n296\n297\n298\n299\n300\n301\n302\n303\n304\n305\n306\n307\n308\n309\n310\n311\n312\n313\n314\n315\n316\n317\n318\n319\n320\n321\n322\n323\n324\n325\n326\n327\n328\n329\n330\n331\n332\n333\n334\n335\n336\n337\n338\n339\n340\n341\n342\n343\n344\n345\n346\n347\n348\n349\n350\n351\n352\n353\n354\n355\n356\n357\n358\n359\n360\n361\n362\n363\n364\n365\n366\n367\n368\n369\n370\n371\n372\n373\n374\n375\n376\n377\n378\n379\n380\n381\n382\n383\n384\n385\n386\n387\n388\n389\n390\n391\n392\n393\n394\n395\n396\n397\n398\n399\n400\n401\n402\n403\n404\n405\n406\n407\n408\n409\n410\n411\n412\n413\n414\n415\n416\n417\n418\n419\n420\n421\n422\n423\n424\n425\n426\n427\n428\n429\n430\n431\n432\n433\n434\n435\n436\n437\n438\n439\n440\n441\n442\n443\n444\n445\n446\n447\n448\n449\n450\n451\n452\n453\n454\n455\n456\n457\n458\n459\n460\n461\n462\n463\n464\n465\n466\n467\n468\n469\n470\n471\n472\n473\n474\n475\n476\n477\n478\n479\n480\n481\n482\n483\n484\n485\n486\n487\n488\n489\n490\n491\n492\n493\n494\n495\n496\n497\n498\n499\n500\n";
-
- LineNumberReader lnr;
-
- /**
- * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "LineNumberReader",
- args = {java.io.Reader.class, int.class}
- )
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.LineNumberReader(java.io.Reader)
- lnr = new LineNumberReader(new StringReader(text), 4092);
- assertEquals("Failed to create reader", 0, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#LineNumberReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "LineNumberReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_ReaderI() {
- // Test for method java.io.LineNumberReader(java.io.Reader, int)
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Failed to create reader", 0, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#getLineNumber()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getLineNumber",
- args = {}
- )
- public void test_getLineNumber() {
- // Test for method int java.io.LineNumberReader.getLineNumber()
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Returned incorrect line number--expected 0, got ", 0, lnr
- .getLineNumber());
- try {
- lnr.readLine();
- lnr.readLine();
- } catch (IOException e) {
- fail("Exception during getLineNumberTest: " + e.toString());
- }
- assertTrue("Returned incorrect line number--expected 2, got: "
- + lnr.getLineNumber(), lnr.getLineNumber() == 2);
- }
-
- /**
- * @tests java.io.LineNumberReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- String line;
- lnr.skip(80);
- lnr.mark(100);
- line = lnr.readLine();
- lnr.reset();
- assertTrue("Test 1: Failed to return to marked position.",
- line.equals(lnr.readLine()));
-
- lnr.close();
- try {
- lnr.mark(42);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- // The spec does not say the mark has to be invalidated
- }
-
- /**
- * @tests java.io.LineNumberReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
-
- int c = lnr.read();
- assertEquals("Test 1: Read returned incorrect character;",
- '0', c);
- lnr.read();
- assertEquals("Test 2: Read failed to increase the line number;",
- 1, lnr.getLineNumber());
-
- lnr.close();
- try {
- lnr.read();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[100];
- lnr.read(c, 0, 4);
- assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n"
- .equals(new String(c, 0, 4)));
- assertEquals("Test 2: Read failed to inc lineNumber",
- 2, lnr.getLineNumber());
-
- lnr.close();
- try {
- lnr.read(c, 0, 4);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII_Exception() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[10];
-
- try {
- lnr.read(c, -1, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnr.read(c, 0, -1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- lnr.read(c, 10, 1);
- fail("IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#readLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readLine",
- args = {}
- )
- public void test_readLine() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Returned incorrect line number", 0, lnr.getLineNumber());
- String line = null;
- lnr.readLine();
- line = lnr.readLine();
- assertEquals("Test 1: Returned incorrect string;", "1", line);
- assertTrue("Test 2: Returned incorrect line number:" + lnr.getLineNumber(),
- lnr.getLineNumber() == 2);
-
- lnr.close();
- try {
- lnr.readLine();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.LineNumberReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- assertEquals("Test 1: Returned incorrect line number;",
- 0, lnr.getLineNumber());
- String line = null;
- lnr.mark(100);
- lnr.readLine();
- lnr.reset();
- line = lnr.readLine();
- assertEquals("Test 2: Failed to reset reader", "0", line);
-
- lnr.mark(100);
- lnr.close();
- try {
- lnr.reset();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- public void testReadLineSourceThrows() throws IOException {
- lnr = new LineNumberReader(new Reader() {
- private StringReader delegate = new StringReader("hello\nworld");
- private int calls = 0;
- @Override public void close() throws IOException {}
- @Override public int read(char[] buf, int offset, int len) throws IOException {
- if (calls++ < 2) {
- throw new IOException();
- } else {
- return delegate.read(buf, offset, len);
- }
- }
- });
-
- assertEquals(0, lnr.getLineNumber());
- try {
- lnr.readLine();
- fail();
- } catch (IOException expected) {
- }
-
- assertEquals(0, lnr.getLineNumber());
- try {
- lnr.readLine();
- fail();
- } catch (IOException expected) {
- }
-
- assertEquals(0, lnr.getLineNumber());
- assertEquals("hello", lnr.readLine());
- assertEquals(1, lnr.getLineNumber());
- assertEquals("world", lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- }
-
- public void testGetLineNumberAfterEnd() throws IOException {
- lnr = new LineNumberReader(new StringReader("hello\nworld"));
- assertEquals(0, lnr.getLineNumber());
- assertEquals("hello", lnr.readLine());
- assertEquals(1, lnr.getLineNumber());
- assertEquals("world", lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- assertEquals(null, lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- assertEquals(null, lnr.readLine());
- assertEquals(2, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#setLineNumber(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLineNumber",
- args = {int.class}
- )
- public void test_setLineNumberI() {
- // Test for method void java.io.LineNumberReader.setLineNumber(int)
- lnr = new LineNumberReader(new StringReader(text));
- lnr.setLineNumber(1001);
- assertEquals("set incorrect line number", 1001, lnr.getLineNumber());
- }
-
- /**
- * @tests java.io.LineNumberReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- lnr = new LineNumberReader(new StringReader(text));
- char[] c = new char[100];
- long skipped = lnr.skip(80);
- assertEquals("Test 1: Incorrect number of characters skipped;",
- 80, skipped);
- lnr.read(c, 0, 100);
- assertTrue("Test 2: Failed to skip to correct position.",
- text.substring(80, 180).equals(new String(c, 0, c.length)));
-
- try {
- lnr.skip(-1);
- fail("Test 3: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- lnr.close();
- try {
- lnr.skip(1);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java b/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java
deleted file mode 100644
index 8f9ffe3..0000000
--- a/luni/src/test/java/tests/api/java/io/NotActiveExceptionTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.NotActiveException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(NotActiveException.class)
-public class NotActiveExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.NotActiveException#NotActiveException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotActiveException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotActiveException();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.NotActiveException#NotActiveException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotActiveException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotActiveException("Something went wrong.");
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java b/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java
deleted file mode 100644
index 9bc7999..0000000
--- a/luni/src/test/java/tests/api/java/io/NotSerializableExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.NotSerializableException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(NotSerializableException.class)
-public class NotSerializableExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.NotSerializableException#NotSerializableException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotSerializableException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotSerializableException();
- fail("Test 1: NotSerializableException expected.");
- } catch (NotSerializableException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.NotSerializableException#NotSerializableException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "NotSerializableException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new NotSerializableException("Something went wrong.");
- fail("Test 1: NotSerializableException expected.");
- } catch (NotSerializableException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java
deleted file mode 100644
index 68dff00..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectInputOutputStreamTest.java
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(ObjectOutputStream.class)
-public class ObjectInputOutputStreamTest extends junit.framework.TestCase {
-
- private ObjectOutputStream os;
-
- private ObjectInputStream is;
-
- private Support_OutputStream sos;
-
- String unihw = "\u0048\u0065\u006C\u006C\u006F\u0020\u0057\u006F\u0072\u006C\u0064";
-
- /**
- * @tests java.io.ObjectInputStream#readBoolean()
- * @tests java.io.ObjectOutputStream#writeBoolean(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeBoolean",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readBoolean",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeBoolean() throws IOException {
- os.writeBoolean(true);
-
- os.close();
- openObjectInputStream();
- assertTrue("Test 1: Incorrect boolean written or read.",
- is.readBoolean());
-
- try {
- is.readBoolean();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readBoolean();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readByte()
- * @tests java.io.ObjectOutputStream#writeByte(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeByte",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readByte",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeByte() throws IOException {
- os.writeByte((byte) 127);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect byte written or read;",
- (byte) 127, is.readByte());
-
- try {
- is.readByte();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readByte();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readChar()
- * @tests java.io.ObjectOutputStream#writeChar(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readChar",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeChar() throws IOException {
- os.writeChar('b');
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect char written or read;",
- 'b', is.readChar());
-
- try {
- is.readChar();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readChar();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readDouble()
- * @tests java.io.ObjectOutputStream#writeDouble(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeDouble",
- args = {double.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readDouble",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeDouble() throws IOException {
- os.writeDouble(2345.76834720202);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect double written or read;",
- 2345.76834720202, is.readDouble());
-
- try {
- is.readDouble();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readDouble();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readFloat()
- * @tests java.io.ObjectOutputStream#writeFloat(float)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeFloat",
- args = {float.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFloat",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeFloat() throws IOException {
- os.writeFloat(29.08764f);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect float written or read;",
- 29.08764f, is.readFloat());
-
- try {
- is.readFloat();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readFloat();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readInt()
- * @tests java.io.ObjectOutputStream#writeInt(int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readInt",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeInt() throws IOException {
- os.writeInt(768347202);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect int written or read;",
- 768347202, is.readInt());
-
- try {
- is.readInt();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readInt();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readLong()
- * @tests java.io.ObjectOutputStream#writeLong(long)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeLong",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readLong",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeLong() throws IOException {
- os.writeLong(9875645283333L);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect long written or read;",
- 9875645283333L, is.readLong());
-
- try {
- is.readLong();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readLong();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#readShort()
- * @tests java.io.ObjectOutputStream#writeShort(short)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeShort",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readShort",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeShort() throws IOException {
- os.writeShort(9875);
-
- os.close();
- openObjectInputStream();
- assertEquals("Test 1: Incorrect short written or read;",
- 9875, is.readShort());
-
- try {
- is.readShort();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readShort();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
-
- /**
- * @tests java.io.ObjectInputStream#readUTF()
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeUTF",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUTF",
- args = {},
- clazz = ObjectInputStream.class
- )
- })
- public void test_read_writeUTF() throws IOException {
- os.writeUTF(unihw);
-
- os.close();
- openObjectInputStream();
- assertTrue("Test 1: Incorrect UTF-8 string written or read.",
- is.readUTF().equals(unihw));
-
- try {
- is.readUTF();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- is.close();
- try {
- is.readUTF();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- private void openObjectInputStream() throws IOException {
- is = new ObjectInputStream(
- new ByteArrayInputStream(sos.toByteArray()));
- }
-
- protected void setUp() throws IOException {
- sos = new Support_OutputStream(256);
- os = new ObjectOutputStream(sos);
- }
-
- protected void tearDown() {
- try {
- os.close();
- } catch (Exception e) {
- }
- try {
- is.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java
deleted file mode 100644
index 13d5419..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectInputStreamGetFieldTest.java
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ObjectInputStream;
-
-import tests.support.Support_GetPutFields;
-import tests.support.Support_GetPutFieldsDefaulted;
-
-
-/**
- * Tests the methods of {@code ObjectInputStream.GetField}. Three things make
- * this class somewhat difficult to test:
- * <ol>
- * <li>It is a completely abstract class; none of the methods is implemented in
- * {@code ObjectInputStream.GetField}.</li>
- * <li>There is no public class that implements
- * {@code ObjectInputStream.GetField}. The only way to get an implementation is
- * by calling {@code ObjectInputStream.getFields()}.</li>
- * <li>Invoking {@code ObjectOutputStream.getFields()} only works from within
- * the private {@code readObject(ObjectInputStream)} method of a class that
- * implements {@code Serializable}; an exception is thrown otherwise.</li>
- * </ol>
- * <p>
- * Given these restrictions, an indirect approach is used to test
- * {@code ObjectInputStream.GetField}: Three serializable helper classes in
- * package {@code tests.support} ({@code Support_GetPutFields},
- * {@code Support_GetPutFieldsDeprecated} and
- * {@code Support_GetPutFieldsDefaulted}) implement
- * {@code readObject(ObjectInputStream)} to read data from an input stream.
- * This input stream in turn reads from one of the corresponding files
- * ({@code testFields.ser}, {@code testFieldsDeprecated.ser} and
- * {@code testFieldsDefaulted.ser}) that have been created with
- * {@code tests.util.FieldTestFileGenerator} on a reference platform.
- * </p>
- * <p>
- * The test method in this class expects to find the reference files as a
- * resource stored at {@code tests/api/java/io}.
- * </p>
- */
-@TestTargetClass(ObjectInputStream.GetField.class)
-public class ObjectInputStreamGetFieldTest extends junit.framework.TestCase {
-
- private ObjectInputStream ois = null;
-
- private final String FILENAME =
- "/tests/api/java/io/testFields.ser";
- private final String DEFAULTED_FILENAME =
- "/tests/api/java/io/testFieldsDefaulted.ser";
-
- public boolean booleanValue;
- public byte byteValue;
- public char charValue;
- public int intValue;
-
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with valid arguments.",
- method = "get",
- args = {java.lang.String.class, short.class}
- )
- })
- public void test_get() throws Exception {
-
- initOis(FILENAME);
- Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
- Support_GetPutFields newObject = new Support_GetPutFields();
- newObject.initTestValues();
-
- assertTrue("Test 1: The object read from the reference file does " +
- "not match a locally created instance of the same class.",
- object.equals(newObject));
-
- initOis(DEFAULTED_FILENAME);
- Support_GetPutFieldsDefaulted defaulted =
- (Support_GetPutFieldsDefaulted) ois.readObject();
- Support_GetPutFieldsDefaulted newDefaulted =
- new Support_GetPutFieldsDefaulted();
- newDefaulted.initTestValues();
-
- assertTrue("Test 2: The object read from the reference file does " +
- "not match a locally created instance of the same class.",
- defaulted.equals(newDefaulted));
-
- // Executing the same procedure against the file created with the
- // deprecated ObjectOutputStream.PutFields.write(ObjectOutput) method
- // is not possible since there is no corresponding read(ObjectInput)
- // method. When trying to do it as in tests 1 and 2, a
- // NullPointerException is thrown.
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies defaulted(String).",
- method = "defaulted",
- args = {java.lang.String.class}
- )
- public void test_defaultedLjava_lang_String() throws Exception {
-
- initOis(FILENAME);
- Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
- ObjectInputStream.GetField fields = object.getField;
-
- try {
- fields.defaulted("noField");
- fail("IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {}
-
- assertFalse("The field longValue should not be defaulted.",
- fields.defaulted("longValue"));
-
- // Now the same with defaulted fields.
- initOis(DEFAULTED_FILENAME);
- Support_GetPutFieldsDefaulted defaultedObject =
- (Support_GetPutFieldsDefaulted) ois.readObject();
- fields = defaultedObject.getField;
-
- assertTrue("The field longValue should be defaulted.",
- fields.defaulted("longValue"));
-
- }
-
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies the get(String, X) methods with invalid arguments.",
- method = "get",
- args = {java.lang.String.class, short.class}
- )
- })
- public void test_getException() throws Exception {
-
- initOis(FILENAME);
- Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
- ObjectInputStream.GetField fields = object.getField;
-
- // Methods called with invalid field name.
- try {
- fields.get("noValue", false);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, boolean).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", (byte) 0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, byte).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", (char) 0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, char).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", 0.0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, double).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", 0.0f);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, float).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", (long) 0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, long).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", 0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, int).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", new Object());
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, Object).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("noValue", (short) 0);
- fail("IllegalArgumentException expected for not existing name " +
- "argument in get(String, short).");
- } catch (IllegalArgumentException e) {}
-
- // Methods called with correct field name but non-matching type.
- try {
- fields.get("byteValue", false);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, boolean).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("booleanValue", (byte) 0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, byte).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("intValue", (char) 0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, char).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("floatValue", 0.0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, double).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("doubleValue", 0.0f);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, float).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("intValue", (long) 0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, long).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("shortValue", 0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, int).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("booleanValue", new Object());
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, Object).");
- } catch (IllegalArgumentException e) {}
-
- try {
- fields.get("longValue", (short) 0);
- fail("IllegalArgumentException expected for non-matching name " +
- "and type arguments in get(String, short).");
- } catch (IllegalArgumentException e) {}
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that getObjectStreamClass() does not return null.",
- method = "getObjectStreamClass",
- args = {}
- )
- public void test_getObjectStreamClass() throws Exception {
-
- initOis(FILENAME);
- Support_GetPutFields object = (Support_GetPutFields) ois.readObject();
- assertNotNull("Return value of getObjectStreamClass() should not be null.",
- object.getField.getObjectStreamClass());
- }
-
-
- private void initOis(String fileName) throws Exception {
- if (ois != null) {
- ois.close();
- }
- ois = new ObjectInputStream(
- getClass().getResourceAsStream(fileName));
- }
-
- protected void tearDown() throws Exception {
-
- if (ois != null) {
- ois.close();
- }
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
index 4f91e7d..434d31c 100644
--- a/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
+++ b/luni/src/test/java/tests/api/java/io/ObjectInputStreamTest.java
@@ -17,38 +17,24 @@
package tests.api.java.io;
-import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.NotActiveException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamClass;
-import java.io.OptionalDataException;
import java.io.OutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.Vector;
-
import org.apache.harmony.testframework.serialization.SerializationTest;
import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
-
import tests.support.Support_ASimpleInputStream;
-import tests.support.Support_IOTestSecurityManager;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-@TestTargetClass(ObjectInputStream.class)
public class ObjectInputStreamTest extends junit.framework.TestCase implements
Serializable {
@@ -66,37 +52,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
private final int testLength = testString.length();
- /**
- * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "ObjectInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- // Test for method java.io.ObjectInputStream(java.io.InputStream)
- oos.writeDouble(Double.MAX_VALUE);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.close();
- oos.close();
-
- try {
- ois = new ObjectInputStream(new ByteArrayInputStream(new byte[90]));
- fail("StreamCorruptedException expected");
- } catch (StreamCorruptedException e) {}
- }
-
- /**
- * @tests java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "ObjectInputStream",
- args = {java.io.InputStream.class}
- )
public void test_ConstructorLjava_io_InputStream_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -112,20 +67,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
sis.throwExceptionOnNextUse = false;
}
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies that object can be serialized and deserialized correctly with reading descriptor from serialization stream.",
- method = "readClassDescriptor",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that object can be serialized and deserialized correctly with reading descriptor from serialization stream.",
- method = "readObject",
- args = {}
- )
- })
public void test_ClassDescriptor() throws IOException,
ClassNotFoundException {
@@ -143,14 +84,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
assertEquals(cls, obj);
}
- /**
- * @tests java.io.ObjectInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "available",
- args = {}
- )
public void test_available() throws IOException {
// Test for method int java.io.ObjectInputStream.available()
oos.writeBytes(testString);
@@ -162,15 +95,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "available",
- args = {}
- )
public void test_available_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -188,14 +112,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
public void test_close() throws Exception {
// Test for method void java.io.ObjectInputStream.close()
oos.writeObject(testString);
@@ -214,42 +130,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#defaultReadObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "defaultReadObject",
- args = {}
- )
- public void test_defaultReadObject() throws Exception {
- // Test for method void java.io.ObjectInputStream.defaultReadObject()
- // SM. This method may as well be private, as if called directly it
- // throws an exception.
- String s = testString;
- oos.writeObject(s);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- try {
- ois.defaultReadObject();
- fail("NotActiveException expected");
- } catch (NotActiveException e) {
- // Desired behavior
- } finally {
- ois.close();
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#enableResolveObject(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verifies enableResolveObject(boolean).",
- method = "enableResolveObject",
- args = {boolean.class}
- )
public void test_enableResolveObjectB() throws IOException {
// Start testing without a SecurityManager.
BasicObjectInputStream bois = new BasicObjectInputStream();
@@ -260,32 +140,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
bois.enableResolveObject(false));
}
- /**
- * @tests java.io.ObjectInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- // Test for method int java.io.ObjectInputStream.read()
- oos.write('T');
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect byte value", 'T', ois.read());
- ois.close();
- }
-
- /**
- * @tests java.io.ObjectInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "read",
- args = {}
- )
public void test_read_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -303,14 +157,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII() throws IOException {
// Test for method int java.io.ObjectInputStream.read(byte [], int, int)
byte[] buf = new byte[testLength];
@@ -322,15 +168,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
assertEquals("Read incorrect bytes", testString, new String(buf));
}
- /**
- * @tests java.io.ObjectInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks Exceptions.",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
public void test_read$BII_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -371,55 +208,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readFields()
- * @tests java.io.ObjectOutputStream#writeFields()
- */
- @TestTargets({
- @TestTargetNew(
- method = "readFields",
- args = {},
- level = TestLevel.COMPLETE
- ),
- @TestTargetNew(
- method = "writeFields",
- args = {},
- clazz = ObjectOutputStream.class,
- level = TestLevel.COMPLETE
- )
- })
- public void test_readFields() throws Exception {
- // Test for method java.io.ObjectInputStream$GetField
- // java.io.ObjectInputStream.readFields()
-
- SerializableTestHelper sth;
-
- /*
- * "SerializableTestHelper" is an object created for these tests with
- * two fields (Strings) and simple implementations of readObject and
- * writeObject which simply read and write the first field but not the
- * second
- */
-
- oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
- oos.flush();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- sth = (SerializableTestHelper) (ois.readObject());
- assertEquals("readFields / writeFields failed--first field not set",
- "Gabba", sth.getText1());
- assertNull(
- "readFields / writeFields failed--second field should not have been set",
- sth.getText2());
- }
-
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readFully",
- args = {byte[].class}
- )
public void test_readFully$B() throws IOException {
byte[] buf = new byte[testLength];
oos.writeBytes(testString);
@@ -440,15 +228,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
}
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "readFully",
- args = {byte[].class}
- )
public void test_readFully$B_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -467,14 +246,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII() throws IOException {
// Test for method void java.io.ObjectInputStream.readFully(byte [],
// int, int)
@@ -496,15 +267,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
}
}
- /**
- * @tests java.io.ObjectInputStream#readFully(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks Exceptions.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
public void test_readFully$BII_Exception() throws IOException {
byte[] buf = new byte[testLength];
oos.writeObject(testString);
@@ -544,15 +306,7 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readLine()
- */
@SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "readLine",
- args = {}
- )
public void test_readLine() throws IOException {
String line;
oos.writeBytes("Lorem\nipsum\rdolor sit amet...");
@@ -571,16 +325,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readLine()
- */
- @SuppressWarnings("deprecation")
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "readLine",
- args = {}
- )
public void test_readLine_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -598,102 +342,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
- public void test_readObject() throws Exception {
- // Test for method java.lang.Object
- // java.io.ObjectInputStream.readObject()
- String s = testString;
- oos.writeObject(s);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect Object value", s, ois.readObject());
- ois.close();
-
- // Regression for HARMONY-91
- // dynamically create serialization byte array for the next hierarchy:
- // - class A implements Serializable
- // - class C extends A
-
- byte[] cName = C.class.getName().getBytes();
- byte[] aName = A.class.getName().getBytes();
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- byte[] begStream = new byte[] { (byte) 0xac, (byte) 0xed, // STREAM_MAGIC
- (byte) 0x00, (byte) 0x05, // STREAM_VERSION
- (byte) 0x73, // TC_OBJECT
- (byte) 0x72, // TC_CLASSDESC
- (byte) 0x00, // only first byte for C class name length
- };
-
- out.write(begStream, 0, begStream.length);
- out.write(cName.length); // second byte for C class name length
- out.write(cName, 0, cName.length); // C class name
-
- byte[] midStream = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x21, // serialVersionUID = 33L
- (byte) 0x02, // flags
- (byte) 0x00, (byte) 0x00, // fields : none
- (byte) 0x78, // TC_ENDBLOCKDATA
- (byte) 0x72, // Super class for C: TC_CLASSDESC for A class
- (byte) 0x00, // only first byte for A class name length
- };
-
- out.write(midStream, 0, midStream.length);
- out.write(aName.length); // second byte for A class name length
- out.write(aName, 0, aName.length); // A class name
-
- byte[] endStream = new byte[] { (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
- (byte) 0x0b, // serialVersionUID = 11L
- (byte) 0x02, // flags
- (byte) 0x00, (byte) 0x01, // fields
-
- (byte) 0x4c, // field description: type L (object)
- (byte) 0x00, (byte) 0x04, // length
- // field = 'name'
- (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65,
-
- (byte) 0x74, // className1: TC_STRING
- (byte) 0x00, (byte) 0x12, // length
- //
- (byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
- (byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61,
- (byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53,
- (byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
- (byte) 0x67, (byte) 0x3b,
-
- (byte) 0x78, // TC_ENDBLOCKDATA
- (byte) 0x70, // NULL super class for A class
-
- // classdata
- (byte) 0x74, // TC_STRING
- (byte) 0x00, (byte) 0x04, // length
- (byte) 0x6e, (byte) 0x61, (byte) 0x6d, (byte) 0x65, // value
- };
-
- out.write(endStream, 0, endStream.length);
- out.flush();
-
- // read created serial. form
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- out.toByteArray()));
- Object o = ois.readObject();
- assertEquals(C.class, o.getClass());
-
- // Regression for HARMONY-846
- assertNull(new ObjectInputStream() {}.readObject());
- }
-
private void fillStreamHeader(byte[] buffer) {
short magic = java.io.ObjectStreamConstants.STREAM_MAGIC;
short version = java.io.ObjectStreamConstants.STREAM_VERSION;
@@ -709,15 +357,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
buffer[3] = (byte) (version);
}
- /**
- * @tests java.io.ObjectInputStream#readObjectOverride()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies readObjectOverride().",
- method = "readObjectOverride",
- args = {}
- )
public void test_readObjectOverride() throws Exception {
byte[] buffer = new byte[4];
@@ -740,15 +379,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
bois.close();
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
public void test_readObjectMissingClasses() throws Exception {
SerializationTest.verifySelf(new A1(), new SerializableAssert() {
public void assertDeserialized(Serializable initial,
@@ -758,15 +388,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
});
}
- /**
- * @tests java.io.ObjectInputStream#readObject()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
public void test_readObjectCorrupt() {
byte[] bytes = { 00, 00, 00, 0x64, 0x43, 0x48, (byte) 0xFD, 0x71, 00,
00, 0x0B, (byte) 0xB8, 0x4D, 0x65 };
@@ -786,15 +407,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
assertTrue("Expected StreamCorruptedException", exception);
}
- /**
- * @tests java.io.ObjectInputStream#readStreamHeader()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies readStreamHeader().",
- method = "readStreamHeader",
- args = {}
- )
public void test_readStreamHeader() throws IOException {
String testString = "Lorem ipsum";
BasicObjectInputStream bois;
@@ -849,14 +461,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
readStreamHeaderCalled);
}
- /**
- * @tests java.io.ObjectInputStream#readUnsignedByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedByte",
- args = {}
- )
public void test_readUnsignedByte() throws IOException {
oos.writeByte(-1);
oos.close();
@@ -881,14 +485,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
}
}
- /**
- * @tests java.io.ObjectInputStream#readUnsignedShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "readUnsignedShort",
- args = {}
- )
public void test_readUnsignedShort() throws IOException {
// Test for method int java.io.ObjectInputStream.readUnsignedShort()
oos.writeShort(-1);
@@ -914,15 +510,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
}
}
- /**
- * @tests java.io.ObjectInputStream#resolveProxyClass(String[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies resolveProxyClass(String[]).",
- method = "resolveProxyClass",
- args = {java.lang.String[].class}
- )
public void test_resolveProxyClass() throws IOException {
BasicObjectInputStream bois;
byte[] buffer = new byte[10];
@@ -967,44 +554,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
bois.close();
}
- /**
- * @tests java.io.ObjectInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "skipBytes",
- args = {int.class}
- )
- public void test_skipBytesI() throws IOException {
- // Test for method int java.io.ObjectInputStream.skipBytes(int)
- byte[] buf = new byte[testLength];
- oos.writeBytes(testString);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.skipBytes(5);
- ois.read(buf, 0, 5);
- ois.close();
- assertEquals("Skipped incorrect bytes", testString.substring(5, 10),
- new String(buf, 0, 5));
-
- // Regression for HARMONY-844
- try {
- new ObjectInputStream() {}.skipBytes(0);
- fail("NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks IOException.",
- method = "skipBytes",
- args = {int.class}
- )
public void test_skipBytesI_IOException() throws IOException {
oos.writeObject(testString);
oos.close();
@@ -1022,32 +571,6 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
ois.close();
}
- // Regression Test for JIRA 2192
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "readObject",
- args = {}
- )
- public void test_readObject_withPrimitiveClass() throws Exception {
- // Make sure that system properties are set correctly
- String dir = System.getProperty("java.io.tmpdir");
- if (dir == null)
- throw new Exception("System property java.io.tmpdir not defined.");
- File file = new File(dir, "test.ser");
- file.deleteOnExit();
- Test test = new Test();
- ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(
- file));
- out.writeObject(test);
- out.close();
-
- ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
- Test another = (Test) in.readObject();
- in.close();
- assertEquals(test, another);
- }
-
public static class A implements Serializable {
private static final long serialVersionUID = 11L;
@@ -1080,60 +603,12 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
Hashtable h = new Hashtable();
}
- public class SerializableTestHelper implements Serializable {
-
- public String aField1;
-
- public String aField2;
-
- SerializableTestHelper() {
- aField1 = null;
- aField2 = null;
- }
-
- SerializableTestHelper(String s, String t) {
- aField1 = s;
- aField2 = t;
- }
-
- private void readObject(ObjectInputStream ois) throws Exception {
- // note aField2 is not read
- ObjectInputStream.GetField fields = ois.readFields();
- aField1 = (String) fields.get("aField1", "Zap");
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException {
- // note aField2 is not written
- ObjectOutputStream.PutField fields = oos.putFields();
- fields.put("aField1", aField1);
- oos.writeFields();
- }
-
- public String getText1() {
- return aField1;
- }
-
- public void setText1(String s) {
- aField1 = s;
- }
-
- public String getText2() {
- return aField2;
- }
-
- public void setText2(String s) {
- aField2 = s;
- }
- }
-
-
class BasicObjectInputStream extends ObjectInputStream {
public BasicObjectInputStream() throws IOException, SecurityException {
super();
}
- public BasicObjectInputStream(InputStream input)
- throws StreamCorruptedException, IOException {
+ public BasicObjectInputStream(InputStream input) throws IOException {
super(input);
}
@@ -1142,13 +617,11 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
return super.enableResolveObject(enable);
}
- public Object readObjectOverride() throws OptionalDataException,
- ClassNotFoundException, IOException {
+ public Object readObjectOverride() throws ClassNotFoundException, IOException {
return super.readObjectOverride();
}
- public void readStreamHeader() throws IOException,
- StreamCorruptedException {
+ public void readStreamHeader() throws IOException {
readStreamHeaderCalled = true;
super.readStreamHeader();
}
@@ -1193,272 +666,12 @@ public class ObjectInputStreamTest extends junit.framework.TestCase implements
private static final long serialVersionUID = 1L;
}
-
- // Regression Test for JIRA-2340
- public static class ObjectOutputStreamWithWriteDesc1 extends
- ObjectOutputStream {
- public ObjectOutputStreamWithWriteDesc1(OutputStream os)
- throws IOException {
- super(os);
- }
-
- public void writeClassDescriptor(ObjectStreamClass desc)
- throws IOException {
- super.writeClassDescriptor(desc);
- }
- }
-
- public static class ObjectInputStreamWithReadDesc1 extends
- ObjectInputStream {
-
- public ObjectInputStreamWithReadDesc1(InputStream is)
- throws IOException {
- super(is);
- }
-
- public ObjectStreamClass readClassDescriptor() throws IOException,
- ClassNotFoundException {
- return super.readClassDescriptor();
- }
- }
-
- // Regression test for Harmony-1921
- public static class ObjectInputStreamWithResolve extends ObjectInputStream {
- public ObjectInputStreamWithResolve(InputStream in) throws IOException {
- super(in);
- }
-
- protected Class<?> resolveClass(ObjectStreamClass desc)
- throws IOException, ClassNotFoundException {
- if (desc.getName().equals(
- "org.apache.harmony.luni.tests.pkg1.TestClass")) {
- return org.apache.harmony.luni.tests.pkg2.TestClass.class;
- }
- return super.resolveClass(desc);
- }
- }
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException testing since this seems not to be thrown.",
- method = "resolveClass",
- args = {java.io.ObjectStreamClass.class}
- )
- public void test_resolveClass() throws Exception {
- org.apache.harmony.luni.tests.pkg1.TestClass to1 = new org.apache.harmony.luni.tests.pkg1.TestClass();
- to1.i = 555;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(to1);
- oos.flush();
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStreamWithResolve(bais);
- org.apache.harmony.luni.tests.pkg2.TestClass to2 = (org.apache.harmony.luni.tests.pkg2.TestClass) ois
- .readObject();
-
- if (to2.i != to1.i) {
- fail("Wrong object read. Expected val: " + to1.i + ", got: " + to2.i);
- }
- }
-
- static class ObjectInputStreamWithResolveObject extends ObjectInputStream {
-
- public static Integer intObj = Integer.valueOf(1000);
-
- public ObjectInputStreamWithResolveObject(InputStream in) throws IOException {
- super(in);
- enableResolveObject(true);
- }
-
- protected Object resolveObject(Object obj) throws IOException {
- if(obj instanceof Integer){
- obj = intObj;
- }
- return super.resolveObject(obj);
- }
- }
-
- /**
- * @tests java.io.ObjectInputStream#resolveObject(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "resolveObject",
- args = {java.lang.Object.class}
- )
- public void test_resolveObjectLjava_lang_Object() throws Exception {
- // Write an Integer object into memory
- Integer original = new Integer(10);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(original);
- oos.flush();
- oos.close();
-
- // Read the object from memory
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStreamWithResolveObject ois =
- new ObjectInputStreamWithResolveObject(bais);
- Integer actual = (Integer) ois.readObject();
- ois.close();
-
- // object should be resolved from 10 to 1000
- assertEquals(ObjectInputStreamWithResolveObject.intObj, actual);
- }
-
- /**
- * @tests java.io.ObjectInputStream#readClassDescriptor()
- * @tests java.io.ObjectOutputStream#writeClassDescriptor(ObjectStreamClass)
- */
- @TestTargets(
- {
- @TestTargetNew(
- method = "readClassDescriptor",
- args = {},
- level = TestLevel.PARTIAL_COMPLETE
- ),
- @TestTargetNew(
- method = "writeClassDescriptor",
- args = {ObjectStreamClass.class},
- clazz = ObjectOutputStream.class,
- level = TestLevel.COMPLETE
- )
- }
- )
- public void test_readClassDescriptor() throws IOException,
- ClassNotFoundException {
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithWriteDesc1 oos = new ObjectOutputStreamWithWriteDesc1(
- baos);
- ObjectStreamClass desc = ObjectStreamClass
- .lookup(TestClassForSerialization.class);
- oos.writeClassDescriptor(desc);
- oos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStreamWithReadDesc1 ois = new ObjectInputStreamWithReadDesc1(
- bais);
- Object obj = ois.readClassDescriptor();
- ois.close();
- assertEquals(desc.getClass(), obj.getClass());
-
- //eof
- bais = new ByteArrayInputStream(bytes);
- ExceptionalBufferedInputStream bis = new ExceptionalBufferedInputStream(
- bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setEOF(true);
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- //throw exception
- bais = new ByteArrayInputStream(bytes);
- bis = new ExceptionalBufferedInputStream(bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setException(new IOException());
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- //corrupt
- bais = new ByteArrayInputStream(bytes);
- bis = new ExceptionalBufferedInputStream(bais);
- ois = new ObjectInputStreamWithReadDesc1(bis);
-
- bis.setCorrupt(true);
-
- try {
- obj = ois.readClassDescriptor();
- } catch (IOException e) {
- //e.printStackTrace();
- } finally {
- ois.close();
- }
-
- }
-
- static class ExceptionalBufferedInputStream extends BufferedInputStream {
- private boolean eof = false;
- private IOException exception = null;
- private boolean corrupt = false;
-
- public ExceptionalBufferedInputStream(InputStream in) {
- super(in);
- }
-
- public int read() throws IOException {
- if (exception != null) {
- throw exception;
- }
-
- if (eof) {
- return -1;
- }
-
- if (corrupt) {
- return 0;
- }
- return super.read();
- }
-
- public void setEOF(boolean eof) {
- this.eof = eof;
- }
-
- public void setException(IOException exception) {
- this.exception = exception;
- }
-
- public void setCorrupt(boolean corrupt) {
- this.corrupt = corrupt;
- }
- }
-
- // Regression Test for Harmony-2402
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "registerValidation",
- args = {java.io.ObjectInputValidation.class, int.class}
- )
- public void test_registerValidation() throws Exception {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- new ObjectOutputStream(baos);
- ObjectInputStream ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
-
- try {
- ois.registerValidation(null, 256);
- fail("NotActiveException should be thrown");
- } catch (NotActiveException nae) {
- // expected
- }
- }
-
protected void setUp() throws Exception {
super.setUp();
oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
}
}
-
class Test implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java b/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java
deleted file mode 100644
index 53bc31a..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectInputValidationTest.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package tests.api.java.io;
-
-import junit.framework.TestCase;
-
-import java.io.ObjectInputValidation;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-@TestTargetClass(
- value = ObjectInputValidation.class,
- untestedMethods = {
- @TestTargetNew(
- method = "validateObject",
- level = TestLevel.NOT_FEASIBLE,
- notes = "There are no classes in the current core " +
- "libraries that implement this method."
- )
- }
-)
-public class ObjectInputValidationTest extends TestCase {
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java b/luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java
deleted file mode 100644
index ff264bc..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamPutFieldTest.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.util.Arrays;
-
-import tests.support.Support_GetPutFields;
-import tests.support.Support_GetPutFieldsDeprecated;
-
-/**
- * Tests the methods of {@code ObjectOutputStream.PutField}. Three things make
- * this class somewhat difficult to test:
- * <ol>
- * <li>It is a completely abstract class; none of the methods is implemented in
- * {@code ObjectOutputStream.PutField}.</li>
- * <li>There is no public class that implements
- * {@code ObjectOutputStream.PutField}. The only way to get an implementation
- * is by calling {@code ObjectOutputStream.putFields()}.</li>
- * <li>Invoking the methods of {@code ObjectOutputStream.PutField} only works
- * from within the private {@code writeObject(ObjectOutputStream)} method of a
- * class that implements {@code Serializable}; an exception is thrown
- * otherwise.</li>
- * </ol>
- * <p>
- * Given these restrictions, an indirect approach is used to test
- * {@code ObjectOutputStream.PutField}: The serializable helper class
- * {@code tests.support.Support_GetPutFields} implements
- * {@code writeObject(ObjectOutputStream)} and uses all {@code putX} methods in
- * {@code PutField} to write data to the output stream. A second helper class,
- * {@code tests.support.Support_GetPutFieldsDeprecated}, also uses the
- * deprecated {@code ObjectOutputStream.PutField.write(ObjectOutput)}.
- * {@code tests.util.FieldTestFileGenerator} can then be used on a reference
- * platform to write these two classes to the file {@code testFields.ser} and
- * {@code testFieldsDeprecated.ser} respectively.
- * </p>
- * <p>
- * The test methods in this class expect to find {@code testFields.ser} and
- * {@code testFieldsDeprecated.ser} as a resource stored at
- * {@code tests/api/java/io}. The contents of these files is compared to what
- * is written when {@code Support_GetPutFields.writeObject(ObjectOutputStream)}
- * and {@code Support_GetPutFieldsDeprecated.writeObject(ObjectOutputStream)} is
- * called by the test methods.
- * </p>
- */
-@TestTargetClass(ObjectOutputStream.PutField.class)
-public class ObjectOutputStreamPutFieldTest extends junit.framework.TestCase {
-
- private final String FILENAME =
- "/tests/api/java/io/testFields.ser";
- private final String DEPRECATED_FILENAME =
- "/tests/api/java/io/testFieldsDeprecated.ser";
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, byte.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, char.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, double.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, float.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, long.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that content is written correctly to a stream.",
- method = "put",
- args = {java.lang.String.class, short.class}
- )
- })
- public void test_put() throws Exception {
- Support_GetPutFields toSerialize = new Support_GetPutFields();
- byte[] content;
- byte[] refContent;
- ObjectOutputStream oos = null;
- ByteArrayOutputStream baos;
-
- toSerialize.initTestValues();
-
- try {
- refContent = getRefContent(FILENAME);
-
- baos = new ByteArrayOutputStream(refContent.length);
- oos = new ObjectOutputStream(baos);
-
- oos.writeObject(toSerialize);
- content = baos.toByteArray();
- assertTrue("Serialization is not equal to reference platform.",
- Arrays.equals(content, refContent));
- }
- finally {
- if (oos != null) oos.close();
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies the deprecated write(ObjectOutput) method.",
- method = "write",
- args = {java.io.ObjectOutput.class}
- )
- public void test_writeLjava_io_ObjectOutputStream() throws Exception {
- Support_GetPutFieldsDeprecated toSerialize = new Support_GetPutFieldsDeprecated();
- byte[] content;
- byte[] refContent;
- ObjectOutputStream oos = null;
- ByteArrayOutputStream baos;
-
- toSerialize.initTestValues();
-
- try {
- refContent = getRefContent(DEPRECATED_FILENAME);
-
- baos = new ByteArrayOutputStream(refContent.length);
- oos = new ObjectOutputStream(baos);
-
- oos.writeObject(toSerialize);
- content = baos.toByteArray();
- assertTrue("Serialization is not equal to reference platform.",
- Arrays.equals(content, refContent));
- }
- finally {
- if (oos != null) oos.close();
- }
- }
-
- private byte[] getRefContent(String path) throws Exception {
- int bytesRead;
- byte[] refContent;
- byte[] streamContent = new byte[2000];
- InputStream refStream = null;
-
- try {
- refStream = getClass().getResourceAsStream(path);
- bytesRead = refStream.read(streamContent);
- assertTrue("Test case implementation error: The byte array to " +
- "store the reference file is too small.",
- (refStream.read() == -1));
- refContent = new byte[bytesRead];
- System.arraycopy(streamContent, 0, refContent, 0, bytesRead);
- }
- finally {
- if (refStream != null) refStream.close();
- }
- return refContent;
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
deleted file mode 100644
index 054986d..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectOutputStreamTest.java
+++ /dev/null
@@ -1,1518 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Externalizable;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.NotActiveException;
-import java.io.NotSerializableException;
-import java.io.ObjectInput;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamException;
-import java.io.ObjectStreamField;
-import java.io.OutputStream;
-import java.io.Serializable;
-import java.io.SerializablePermission;
-import java.io.WriteAbortedException;
-import java.security.Permission;
-import java.util.Arrays;
-
-import tests.support.Support_ASimpleOutputStream;
-import tests.support.Support_IOTestSecurityManager;
-import tests.support.Support_OutputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-@TestTargetClass(
- value = ObjectOutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "annotateClass",
- args = {Class.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- ),
- @TestTargetNew(
- method = "annotateProxyClass",
- args = {Class.class},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- )
- }
-)
-public class ObjectOutputStreamTest extends junit.framework.TestCase implements
- Serializable {
-
- static final long serialVersionUID = 1L;
-
- java.io.File f;
-
- public class SerializableTestHelper implements Serializable {
- public String aField1;
-
- public String aField2;
-
- SerializableTestHelper() {
- aField1 = null;
- aField2 = null;
- }
-
- SerializableTestHelper(String s, String t) {
- aField1 = s;
- aField2 = t;
- }
-
- private void readObject(ObjectInputStream ois) throws IOException {
- // note aField2 is not read
- try {
- ObjectInputStream.GetField fields = ois.readFields();
- aField1 = (String) fields.get("aField1", "Zap");
- } catch (Exception e) {
- }
- }
-
- private void writeObject(ObjectOutputStream oos) throws IOException {
- // note aField2 is not written
- ObjectOutputStream.PutField fields = oos.putFields();
- fields.put("aField1", aField1);
- oos.writeFields();
- }
-
- public String getText1() {
- return aField1;
- }
-
- public void setText1(String s) {
- aField1 = s;
- }
-
- public String getText2() {
- return aField2;
- }
-
- public void setText2(String s) {
- aField2 = s;
- }
- }
-
- private static class SpecTestSuperClass implements Runnable, Serializable {
- static final long serialVersionUID = 1L;
- protected java.lang.String instVar;
-
- public void run() {
- }
- }
-
- private static class SpecTest extends SpecTestSuperClass implements
- Cloneable, Serializable {
- static final long serialVersionUID = 1L;
-
- public java.lang.String instVar1;
-
- public static java.lang.String staticVar1;
-
- public static java.lang.String staticVar2;
- {
- instVar1 = "NonStaticInitialValue";
- }
- static {
- staticVar1 = "StaticInitialValue";
- staticVar1 = new String(staticVar1);
- }
-
- public Object method(Object objParam, Object objParam2) {
- return new Object();
- }
-
- public boolean method(boolean bParam, Object objParam) {
- return true;
- }
-
- public boolean method(boolean bParam, Object objParam, Object objParam2) {
- return true;
- }
-
- }
-
- private static class SpecTestSubclass extends SpecTest implements
- Serializable {
- static final long serialVersionUID = 1L;
- public transient java.lang.String transientInstVar = "transientValue";
- }
-
- private static class ReadWriteObject implements java.io.Serializable {
- static final long serialVersionUID = 1L;
-
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public ReadWriteObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class PublicReadWriteObject implements java.io.Serializable {
- public boolean calledWriteObject = false;
-
- public boolean calledReadObject = false;
-
- public PublicReadWriteObject() {
- super();
- }
-
- public void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.readObject();
- }
-
- public void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException {
- calledWriteObject = true;
- out.writeObject(FOO);
- }
- }
-
- private static class FieldOrder implements Serializable {
- String aaa1NonPrimitive = "aaa1";
-
- int bbb1PrimitiveInt = 5;
-
- boolean aaa2PrimitiveBoolean = true;
-
- String bbb2NonPrimitive = "bbb2";
- }
-
- private static class JustReadObject implements java.io.Serializable {
- public boolean calledReadObject = false;
-
- public JustReadObject() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- calledReadObject = true;
- in.defaultReadObject();
- }
- }
-
- private static class JustWriteObject implements java.io.Serializable {
- static final long serialVersionUID = 1L;
- public boolean calledWriteObject = false;
-
- public JustWriteObject() {
- super();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- calledWriteObject = true;
- out.defaultWriteObject();
- }
- }
-
- private static class ClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- public boolean calledReplacement = false;
-
- public ClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- calledReplacement = true;
- return FOO; // Replacement is a String
- }
- }
-
- private static class MultipleClassBasedReplacementWhenDumping implements
- java.io.Serializable {
- private static class C1 implements java.io.Serializable {
- private Object writeReplace() {
- return new C2();
- }
- }
-
- private static class C2 implements java.io.Serializable {
- private Object writeReplace() {
- return new C3();
- }
- }
-
- private static class C3 implements java.io.Serializable {
- private Object writeReplace() {
- return FOO;
- }
- }
-
- public MultipleClassBasedReplacementWhenDumping() {
- super();
- }
-
- private Object writeReplace() {
- return new C1();
- }
- }
-
- private static class ClassBasedReplacementWhenLoading implements
- java.io.Serializable {
- public ClassBasedReplacementWhenLoading() {
- super();
- }
-
- private Object readResolve() {
- return FOO; // Replacement is a String
- }
- }
-
- private static class ClassBasedReplacementWhenLoadingViolatesFieldType
- implements java.io.Serializable {
- public ClassBasedReplacementWhenLoading classBasedReplacementWhenLoading = new ClassBasedReplacementWhenLoading();
-
- public ClassBasedReplacementWhenLoadingViolatesFieldType() {
- super();
- }
- }
-
- private static class MyExceptionWhenDumping implements java.io.Serializable {
- private static class MyException extends java.io.IOException {
- };
-
- public boolean anInstanceVar = false;
-
- public MyExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class NonSerializableExceptionWhenDumping implements
- java.io.Serializable {
- public Object anInstanceVar = new Object();
-
- public NonSerializableExceptionWhenDumping() {
- super();
- }
- }
-
- private static class MyUnserializableExceptionWhenDumping implements
- java.io.Serializable {
- private static class MyException extends java.io.IOException {
- private Object notSerializable = new Object();
- };
-
- public boolean anInstanceVar = false;
-
- public MyUnserializableExceptionWhenDumping() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.defaultReadObject();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- throw new MyException();
- }
- }
-
- private static class WithUnmatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "value", String.class) };
-
- public int anInstanceVar = 5;
-
- public WithUnmatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class WithMatchingSerialPersistentFields implements
- java.io.Serializable {
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- "anInstanceVar", String.class) };
-
- public String anInstanceVar = FOO + FOO;
-
- public WithMatchingSerialPersistentFields() {
- super();
- }
- }
-
- private static class SerialPersistentFields implements java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public SerialPersistentFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- ObjectInputStream.GetField fields = in.readFields();
- anInstanceVar = Integer.parseInt((String) fields.get(
- SIMULATED_FIELD_NAME, "-5"));
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- ObjectOutputStream.PutField fields = out.putFields();
- fields.put(SIMULATED_FIELD_NAME, Integer.toString(anInstanceVar));
- out.writeFields();
- }
- }
-
- private static class WriteFieldsWithoutFetchingPutFields implements
- java.io.Serializable {
- private static final String SIMULATED_FIELD_NAME = "text";
-
- private static final ObjectStreamField[] serialPersistentFields = { new ObjectStreamField(
- SIMULATED_FIELD_NAME, String.class) };
-
- public int anInstanceVar = 5;
-
- public WriteFieldsWithoutFetchingPutFields() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.writeFields();
- }
- }
-
- private static class SerialPersistentFieldsWithoutField implements
- java.io.Serializable {
- public int anInstanceVar = 5;
-
- public SerialPersistentFieldsWithoutField() {
- super();
- }
-
- private void readObject(java.io.ObjectInputStream in)
- throws java.io.IOException, ClassNotFoundException {
- in.readFields();
- }
-
- private void writeObject(java.io.ObjectOutputStream out)
- throws java.io.IOException, ClassNotFoundException {
- out.putFields();
- out.writeFields();
- }
- }
-
- private static class NotSerializable {
- private int foo;
-
- public NotSerializable() {
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
- }
-
- private static class WriteReplaceObject implements Serializable {
- private Object replaceObject;
-
- private static enum Color {
- red, blue, green
- };
-
- public WriteReplaceObject(Object o) {
- replaceObject = o;
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return replaceObject;
- }
- }
-
- private static class ExternalizableWithReplace implements Externalizable {
- private int foo;
-
- public ExternalizableWithReplace() {
- }
-
- protected Object writeReplace() throws ObjectStreamException {
- return new Integer(42);
- }
-
- public void writeExternal(ObjectOutput out) {
- }
-
- public void readExternal(ObjectInput in) {
- }
- }
-
- private static class ObjectOutputStreamWithReplace extends ObjectOutputStream {
- public ObjectOutputStreamWithReplace(OutputStream out) throws IOException {
- super(out);
- enableReplaceObject(true);
- }
-
- protected Object replaceObject(Object obj) throws IOException {
- if (obj instanceof NotSerializable) {
- return new Long(10);
- } else if (obj instanceof Integer) {
- return new Long(((Integer) obj).longValue());
- } else {
- return obj;
- }
- }
- }
-
- private static class ObjectOutputStreamWithReplace2 extends
- ObjectOutputStream {
- public ObjectOutputStreamWithReplace2(OutputStream out)
- throws IOException {
- super(out);
- enableReplaceObject(true);
- }
-
- protected Object replaceObject(Object obj) throws IOException {
- return new Long(10);
- }
- }
-
- private static class BasicObjectOutputStream extends ObjectOutputStream {
- public boolean writeStreamHeaderCalled;
-
- public BasicObjectOutputStream() throws IOException, SecurityException {
- super();
- writeStreamHeaderCalled = false;
- }
-
- public BasicObjectOutputStream(OutputStream output) throws IOException {
- super(output);
- }
-
- public void drain() throws IOException {
- super.drain();
- }
-
- public boolean enableReplaceObject(boolean enable)
- throws SecurityException {
- return super.enableReplaceObject(enable);
- }
-
- public void writeObjectOverride(Object object) throws IOException {
- super.writeObjectOverride(object);
- }
-
- public void writeStreamHeader() throws IOException {
- super.writeStreamHeader();
- writeStreamHeaderCalled = true;
- }
-}
-
- private static class NoFlushTestOutputStream extends ByteArrayOutputStream {
- public boolean flushCalled;
-
- public NoFlushTestOutputStream() {
- super();
- flushCalled = false;
- }
-
- public void flush() throws IOException {
- super.flush();
- flushCalled = true;
- }
- }
-
- protected static final String MODE_XLOAD = "xload";
-
- protected static final String MODE_XDUMP = "xdump";
-
- static final String FOO = "foo";
-
- static final String MSG_WITE_FAILED = "Failed to write: ";
-
- private static final boolean DEBUG = false;
-
- protected static boolean xload = false;
-
- protected static boolean xdump = false;
-
- protected static String xFileName = null;
-
- protected ObjectInputStream ois;
-
- protected ObjectOutputStream oos;
-
- protected ObjectOutputStream oos_ioe;
-
- protected Support_OutputStream sos;
-
- protected ByteArrayOutputStream bao;
-
- static final int INIT_INT_VALUE = 7;
-
- static final String INIT_STR_VALUE = "a string that is blortz";
-
- /**
- * @tests java.io.ObjectOutputStream#ObjectOutputStream(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks valid construction, NullPointerException and IOException.",
- method = "ObjectOutputStream",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() throws IOException {
- oos.close();
- oos = new ObjectOutputStream(new ByteArrayOutputStream());
- oos.close();
-
- try {
- oos = new ObjectOutputStream(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- Support_ASimpleOutputStream sos = new Support_ASimpleOutputStream(true);
- try {
- oos = new ObjectOutputStream(sos);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- int outputSize = bao.size();
- // Writing of a primitive type should be buffered.
- oos.writeInt(42);
- assertTrue("Test 1: Primitive data unexpectedly written to the target stream.",
- bao.size() == outputSize);
- // Closing should write the buffered data to the target stream.
- oos.close();
- assertTrue("Test 2: Primitive data has not been written to the the target stream.",
- bao.size() > outputSize);
-
- try {
- oos_ioe.close();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#drain()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "drain",
- args = {}
- )
- public void test_drain() throws IOException {
- NoFlushTestOutputStream target = new NoFlushTestOutputStream();
- BasicObjectOutputStream boos = new BasicObjectOutputStream(target);
- int initialSize = target.size();
- boolean written = false;
-
- boos.writeBytes("Lorem ipsum");
- // If there is no buffer then the bytes have already been written.
- written = (target.size() > initialSize);
-
- boos.drain();
- assertTrue("Content has not been written to the target.",
- written || (target.size() > initialSize));
- assertFalse("flush() has been called on the target.",
- target.flushCalled);
- }
-
- /**
- * @tests java.io.ObjectOutputStream#defaultWriteObject()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException can not be tested because this method" +
- "always throws a NotActiveException if called directly.",
- method = "defaultWriteObject",
- args = {}
- )
- public void test_defaultWriteObject() throws IOException {
- try {
- oos.defaultWriteObject();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#enableReplaceObject(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "enableReplaceObject",
- args = {boolean.class}
- )
- public void test_enableReplaceObjectB() throws IOException {
- // Start testing without a SecurityManager.
- BasicObjectOutputStream boos = new BasicObjectOutputStream();
- assertFalse("Test 1: Object resolving must be disabled by default.",
- boos.enableReplaceObject(true));
-
- assertTrue("Test 2: enableReplaceObject did not return the previous value.",
- boos.enableReplaceObject(false));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "flush",
- args = {}
- )
- public void test_flush() throws Exception {
- // Test for method void java.io.ObjectOutputStream.flush()
- int size = bao.size();
- oos.writeByte(127);
- assertTrue("Test 1: Data already flushed.", bao.size() == size);
- oos.flush();
- assertTrue("Test 2: Failed to flush data.", bao.size() > size);
-
- try {
- oos_ioe.flush();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#putFields()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException can not be tested because this method" +
- "always throws a NotActiveException if called directly.",
- method = "putFields",
- args = {}
- )
- public void test_putFields() throws Exception {
- /*
- * "SerializableTestHelper" is an object created for these tests with
- * two fields (Strings) and simple implementations of readObject and
- * writeObject which simply read and write the first field but not the
- * second one.
- */
- SerializableTestHelper sth;
-
- try {
- oos.putFields();
- fail("Test 1: NotActiveException expected.");
- } catch (NotActiveException e) {
- // Expected.
- }
-
- oos.writeObject(new SerializableTestHelper("Gabba", "Jabba"));
- oos.flush();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- sth = (SerializableTestHelper) (ois.readObject());
- assertEquals("Test 2: readFields or writeFields failed; first field not set.",
- "Gabba", sth.getText1());
- assertNull("Test 3: readFields or writeFields failed; second field should not have been set.",
- sth.getText2());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() throws Exception {
- String o = "HelloWorld";
- sos = new Support_OutputStream(200);
- oos.close();
- oos = new ObjectOutputStream(sos);
- oos.writeObject(o);
- oos.writeObject(o);
- oos.reset();
- oos.writeObject(o);
-
- sos.setThrowsException(true);
- try {
- oos.reset();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- sos.setThrowsException(false);
-
- ois = new ObjectInputStream(new ByteArrayInputStream(sos.toByteArray()));
- assertEquals("Test 2: Incorrect object read.", o, ois.readObject());
- assertEquals("Test 3: Incorrect object read.", o, ois.readObject());
- assertEquals("Test 4: Incorrect object read.", o, ois.readObject());
- ois.close();
- }
-
- private static class ExternalTest implements Externalizable {
- public String value;
-
- public ExternalTest() {
- }
-
- public void setValue(String val) {
- value = val;
- }
-
- public String getValue() {
- return value;
- }
-
- public void writeExternal(ObjectOutput output) {
- try {
- output.writeUTF(value);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void readExternal(ObjectInput input) {
- try {
- value = input.readUTF();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "IOException seems to be never thrown, therefore there is no such test.",
- method = "useProtocolVersion",
- args = {int.class}
- )
- public void test_useProtocolVersionI() throws Exception {
-
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
- ExternalTest t1 = new ExternalTest();
- t1.setValue("hello1");
- oos.writeObject(t1);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ExternalTest t2 = (ExternalTest) ois.readObject();
- ois.close();
- assertTrue(
- "Cannot read/write PROTOCAL_VERSION_1 Externalizable objects: "
- + t2.getValue(), t1.getValue().equals(t2.getValue()));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(byte [])
- byte[] buf = new byte[10];
- oos.write("HelloWorld".getBytes());
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.read(buf, 0, 10);
- ois.close();
- assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
- 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(byte [], int,
- // int)
- byte[] buf = new byte[10];
- oos.write("HelloWorld".getBytes(), 0, 10);
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.read(buf, 0, 10);
- ois.close();
- assertEquals("Read incorrect bytes", "HelloWorld", new String(buf, 0,
- 10));
-
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- try {
- ois.read(buf, 0, -1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- ois.read(buf, -1, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- ois.read(buf, 10, 1);
- fail("IndexOutOfBoundsException not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- ois.close();
-
- }
-
- /**
- * @tests java.io.ObjectOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws Exception {
- // Test for method void java.io.ObjectOutputStream.write(int)
- oos.write('T');
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Read incorrect byte", 'T', ois.read());
- ois.close();
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeBytes(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeBytes",
- args = {java.lang.String.class}
- )
- public void test_writeBytesLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeBytes(java.lang.String)
- byte[] buf = new byte[10];
- oos.writeBytes("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- ois.readFully(buf);
- ois.close();
- assertEquals("Wrote incorrect bytes value", "HelloWorld", new String(
- buf, 0, 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeChars(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing. IOException can " +
- "not be checked since is never thrown (primitive data " +
- "is written into a self-expanding buffer).",
- method = "writeChars",
- args = {java.lang.String.class}
- )
- public void test_writeCharsLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeChars(java.lang.String)
- int avail = 0;
- char[] buf = new char[10];
- oos.writeChars("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- // Number of prim data bytes in stream / 2 to give char index
- avail = ois.available() / 2;
- for (int i = 0; i < avail; ++i)
- buf[i] = ois.readChar();
- ois.close();
- assertEquals("Wrote incorrect chars", "HelloWorld", new String(buf, 0,
- 10));
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObjectLjava_lang_Object() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeObject(java.lang.Object)
-
- Object objToSave = null;
- Object objLoaded;
-
- SerialPersistentFieldsWithoutField spf = new SerialPersistentFieldsWithoutField();
- final int CONST = -500;
- spf.anInstanceVar = CONST;
- objToSave = spf;
- if (DEBUG)
- System.out.println("Obj = " + objToSave);
- objLoaded = dumpAndReload(objToSave);
- assertTrue(
- "serialPersistentFields do not work properly in this implementation",
- ((SerialPersistentFieldsWithoutField) objLoaded).anInstanceVar != CONST);
-
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObject_NotSerializable() throws Exception {
- ObjectOutput out = null;
- try {
- out = new ObjectOutputStream(new ByteArrayOutputStream());
- out.writeObject(new NotSerializable());
- fail("Expected NotSerializableException");
- } catch (NotSerializableException e) {}
- out.writeObject(new ExternalizableWithReplace());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObjectOverride(Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies that writeObjectOverride() throws an IOException.",
- method = "writeObjectOverride",
- args = {java.lang.Object.class}
- )
- public void test_writeObjectOverrideLjava_lang_Object() throws IOException {
- BasicObjectOutputStream boos =
- new BasicObjectOutputStream(new ByteArrayOutputStream());
-
- try {
- boos.writeObjectOverride(new Object());
- fail("IOException expected.");
- }
- catch (IOException e) {
- }
- finally {
- boos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeStreamHeader()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies writeStreamHeader().",
- method = "writeStreamHeader",
- args = {}
- )
- public void test_writeStreamHeader() throws IOException {
- BasicObjectOutputStream boos;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- short s;
- byte[] buffer;
-
- // Test 1: Make sure that writeStreamHeader() has been called.
- boos = new BasicObjectOutputStream(baos);
- try {
- assertTrue("Test 1: writeStreamHeader() has not been called.",
- boos.writeStreamHeaderCalled);
-
- // Test 2: Check that at least four bytes have been written.
- buffer = baos.toByteArray();
- assertTrue("Test 2: At least four bytes should have been written",
- buffer.length >= 4);
-
- // Test 3: Check the magic number.
- s = buffer[0];
- s <<= 8;
- s += ((short) buffer[1] & 0x00ff);
- assertEquals("Test 3: Invalid magic number written.",
- java.io.ObjectStreamConstants.STREAM_MAGIC, s);
-
- // Test 4: Check the stream version number.
- s = buffer[2];
- s <<= 8;
- s += ((short) buffer[3] & 0x00ff);
- assertEquals("Invalid stream version number written.",
- java.io.ObjectStreamConstants.STREAM_VERSION, s);
- }
- finally {
- boos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IOException checking missed.",
- method = "writeUTF",
- args = {java.lang.String.class}
- )
- public void test_writeUTFLjava_lang_String() throws Exception {
- // Test for method void
- // java.io.ObjectOutputStream.writeUTF(java.lang.String)
- oos.writeUTF("HelloWorld");
- oos.close();
- ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
- assertEquals("Wrote incorrect UTF value", "HelloWorld", ois.readUTF());
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- )
- public void test_writeObject_Exception() throws ClassNotFoundException, IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- try {
- oos.writeObject(new Object());
- fail("should throw ObjectStreamException");
- } catch (ObjectStreamException e) {
- // expected
- } finally {
- oos.close();
- baos.close();
- }
-
- byte[] bytes = baos.toByteArray();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(
- bytes));
- try {
- ois.readObject();
- fail("should throw WriteAbortedException");
- } catch (WriteAbortedException e) {
- // expected
- } finally {
- ois.close();
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
- sos.setThrowsException(true);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- if (oos != null) {
- try {
- oos.close();
- } catch (Exception e) {}
- }
- if (oos_ioe != null) {
- try {
- oos_ioe.close();
- } catch (Exception e) {}
- }
- if (f != null && f.exists()) {
- if (!f.delete()) {
- fail("Error cleaning up files during teardown");
- }
- }
- }
-
- protected Object reload() throws IOException, ClassNotFoundException {
-
- // Choose the load stream
- if (xload || xdump) {
- // Load from pre-existing file
- ois = new ObjectInputStream(new FileInputStream(xFileName + "-"
- + getName() + ".ser"));
- } else {
- // Just load from memory, we dumped to memory
- ois = new ObjectInputStream(new ByteArrayInputStream(bao
- .toByteArray()));
- }
-
- try {
- return ois.readObject();
- } finally {
- ois.close();
- }
- }
-
- protected void dump(Object o) throws IOException, ClassNotFoundException {
-
- // Choose the dump stream
- if (xdump) {
- oos = new ObjectOutputStream(new FileOutputStream(
- f = new java.io.File(xFileName + "-" + getName() + ".ser")));
- } else {
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- }
-
- // Dump the object
- try {
- oos.writeObject(o);
- } finally {
- oos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeInt(int)
- * @tests java.io.ObjectOutputStream#writeObject(java.lang.Object)
- * @tests java.io.ObjectOutputStream#writeUTF(java.lang.String)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeObject",
- args = {java.lang.Object.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "writeUTF",
- args = {java.lang.String.class}
- )
- })
- public void testMixPrimitivesAndObjects() throws Exception {
- int i = 7;
- String s1 = "string 1";
- String s2 = "string 2";
- byte[] bytes = { 1, 2, 3 };
- try {
- oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
- oos.writeInt(i);
- oos.writeObject(s1);
- oos.writeUTF(s2);
- oos.writeObject(bytes);
- oos.close();
-
- ois = new ObjectInputStream(new ByteArrayInputStream(bao
- .toByteArray()));
-
- int j = ois.readInt();
- assertTrue("Wrong int :" + j, i == j);
-
- String l1 = (String) ois.readObject();
- assertTrue("Wrong obj String :" + l1, s1.equals(l1));
-
- String l2 = ois.readUTF();
- assertTrue("Wrong UTF String :" + l2, s2.equals(l2));
-
- byte[] bytes2 = (byte[]) ois.readObject();
- assertTrue("Wrong byte[]", Arrays.equals(bytes, bytes2));
- } finally {
- try {
- if (oos != null)
- oos.close();
- if (ois != null)
- ois.close();
- } catch (IOException e) {}
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeUnshared",
- args = {java.lang.Object.class}
- )
- public void test_writeUnshared() throws Exception {
- //Regression for HARMONY-187
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- Object o = "foobar";
- oos.writeObject(o);
- oos.writeUnshared(o);
- oos.writeObject(o);
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
-
- Object[] oa = new Object[3];
- for (int i = 0; i < oa.length; i++) {
- oa[i] = ois.readObject();
- }
-
- oos.close();
- ois.close();
-
- // All three conditions must be met
- assertNotSame("oa[0] != oa[1]", oa[0], oa[1]);
- assertNotSame("oa[1] != oa[2]", oa[1], oa[2]);
- assertSame("oa[0] == oa[2]", oa[0], oa[2]);
- }
-
- /**
- * @tests java.io.ObjectOutputStream#writeUnshared(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "writeUnshared",
- args = {java.lang.Object.class}
- )
- public void test_writeUnshared2() throws Exception {
- //Regression for HARMONY-187
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
-
- Object o = new Object[1];
- oos.writeObject(o);
- oos.writeUnshared(o);
- oos.writeObject(o);
- oos.flush();
-
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
-
- Object[] oa = new Object[3];
- for (int i = 0; i < oa.length; i++) {
- oa[i] = ois.readObject();
- }
-
- oos.close();
- ois.close();
-
- // All three conditions must be met
- assertNotSame("oa[0] != oa[1]", oa[0], oa[1]);
- assertNotSame("oa[1] != oa[2]", oa[1], oa[2]);
- assertSame("oa[0] == oa[2]", oa[0], oa[2]);
- }
-
- protected Object dumpAndReload(Object o) throws IOException,
- ClassNotFoundException {
- dump(o);
- return reload();
- }
-
- /**
- * @tests java.io.ObjectOutputStream#useProtocolVersion(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "IOException & IllegalStateException checking missed.",
- method = "useProtocolVersion",
- args = {int.class}
- )
- public void test_useProtocolVersionI_2() throws Exception {
- ObjectOutputStream oos = new ObjectOutputStream(
- new ByteArrayOutputStream());
-
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_1);
- oos.useProtocolVersion(ObjectOutputStream.PROTOCOL_VERSION_2);
- try {
- oos.useProtocolVersion(3);
- fail("Protocol 3 should not be accepted");
- } catch (IllegalArgumentException e) {
- // expected
- } finally {
- oos.close();
- }
- }
-
- /**
- * @tests java.io.ObjectOutputStream#replaceObject(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "replaceObject",
- args = {java.lang.Object.class}
- )
- public void test_replaceObject() throws Exception {
- //Regression for HARMONY-1429
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace oos = new ObjectOutputStreamWithReplace(baos);
-
- oos.writeObject(new NotSerializable());
- oos.flush();
- ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
- Object obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- //Regression for HARMONY-2239
- Object replaceObject = int.class;
- baos = new ByteArrayOutputStream();
- ObjectOutputStreamWithReplace2 oos2 = new ObjectOutputStreamWithReplace2(
- baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = ObjectStreamClass.lookup(Integer.class);
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- replaceObject = WriteReplaceObject.Color.red;
- baos = new ByteArrayOutputStream();
- oos2 = new ObjectOutputStreamWithReplace2(baos);
- oos2.writeObject(new WriteReplaceObject(replaceObject));
- oos2.flush();
- ois = new ObjectInputStream(
- new ByteArrayInputStream(baos.toByteArray()));
- obj = ois.readObject();
- oos.close();
- ois.close();
- assertTrue("replaceObject has not been called", (obj instanceof Long));
-
- // Regression for HARMONY-3158
- Object obj1;
- Object obj2;
- Object obj3;
-
- baos = new ByteArrayOutputStream();
- oos = new ObjectOutputStreamWithReplace(baos);
-
- oos.writeObject(new Integer(99));
- oos.writeObject(Integer.class);
- oos.writeObject(ObjectStreamClass.lookup(Integer.class));
- oos.flush();
-
- ois = new ObjectInputStream(new ByteArrayInputStream (baos.toByteArray()));
- obj1 = ois.readObject();
- obj2 = ois.readObject();
- obj3 = ois.readObject();
- oos.close();
- ois.close();
-
- assertTrue("1st replaceObject worked incorrectly", obj1 instanceof Long);
- assertEquals("1st replaceObject worked incorrectly",
- 99, ((Long) obj1).longValue());
- assertEquals("2nd replaceObject worked incorrectly", Integer.class, obj2);
- assertEquals("3rd replaceObject worked incorrectly",
- ObjectStreamClass.class, obj3.getClass());
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java
deleted file mode 100644
index bc2e24e..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamClassTest.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.lang.reflect.Proxy;
-
-import junit.framework.TestCase;
-
-public class ObjectStreamClassTest extends TestCase {
-
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999999L;
-
- long bam = 999L;
-
- int ham = 9999;
-
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- /**
- * @tests java.io.ObjectStreamClass#forClass()
- */
- public void test_forClass() {
- // Need to test during serialization to be sure an instance is
- // returned
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals("forClass returned an object: " + osc.forClass(),
- DummyClass.class, osc.forClass());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getField(java.lang.String)
- */
- public void test_getFieldLjava_lang_String() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals("getField did not return correct field", 'J', osc
- .getField("bam").getTypeCode());
- assertNull("getField did not null for non-existent field", osc
- .getField("wham"));
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getFields()
- */
- public void test_getFields() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- ObjectStreamField[] osfArray = osc.getFields();
- assertTrue(
- "Array of fields should be of length 2 but is instead of length: "
- + osfArray.length, osfArray.length == 2);
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getName()
- */
- public void test_getName() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals(
- "getName returned incorrect name: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", // android-changed
- osc.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertTrue("getSerialversionUID returned incorrect uid: "
- + osc.getSerialVersionUID() + " instead of "
- + DummyClass.getUID(), osc.getSerialVersionUID() == DummyClass
- .getUID());
- }
-
- static class SyntheticTest implements Serializable {
- private int i;
-
- private class X implements Serializable {
- public int get() {
- return i;
- }
- }
-
- public X foo() {
- return new X();
- }
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID_inner_private_class() {
- ObjectStreamClass osc1 = ObjectStreamClass.lookup(SyntheticTest.class);
- assertEquals("SyntheticTest unexpected UID: "
- + osc1.getSerialVersionUID(), 4405770616475181267L, osc1
- .getSerialVersionUID());
-
- ObjectStreamClass osc2 = ObjectStreamClass
- .lookup(SyntheticTest.X.class);
- assertEquals("SyntheticTest.X unexpected UID: "
- + osc2.getSerialVersionUID(), 676101599466902119L, osc2
- .getSerialVersionUID());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#getSerialVersionUID()
- */
- public void test_getSerialVersionUID_classloader() throws Exception {
- File file = new File(
- "resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar");
- ClassLoader loader = new URLClassLoader(new URL[] { file.toURL() },
- null);
- Class cl1 = Class.forName("Test1$TestVarArgs", false, loader);
- ObjectStreamClass osc1 = ObjectStreamClass.lookup(cl1);
- assertEquals("Test1$TestVarArgs unexpected UID: "
- + osc1.getSerialVersionUID(), -6051121963037986215L, osc1
- .getSerialVersionUID());
-
- Class cl2 = Class.forName("Test1$TestBridge", false, loader);
- ObjectStreamClass osc2 = ObjectStreamClass.lookup(cl2);
- assertEquals("Test1$TestBridge unexpected UID: "
- + osc2.getSerialVersionUID(), 568585976855071180L, osc2
- .getSerialVersionUID());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#lookup(java.lang.Class)
- */
- public void test_lookupLjava_lang_Class() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- assertEquals(
- "lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", // android-changed
- osc.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamClass#toString()
- */
- public void test_toString() {
- ObjectStreamClass osc = ObjectStreamClass.lookup(DummyClass.class);
- String oscString = osc.toString();
-
- // The previous test was more specific than the spec so it was replaced
- // with the test below
- assertTrue("toString returned incorrect string: " + osc.toString(),
- oscString.indexOf("serialVersionUID") >= 0
- && oscString.indexOf("999999999999999L") >= 0);
- }
-
- public void testSerialization() {
- ObjectStreamClass osc = ObjectStreamClass
- .lookup(ObjectStreamClass.class);
- assertEquals(0, osc.getFields().length);
- }
-
- public void test_specialTypes() {
- Class<?> proxyClass = Proxy.getProxyClass(this.getClass()
- .getClassLoader(), new Class[] { Runnable.class });
-
- ObjectStreamClass proxyStreamClass = ObjectStreamClass
- .lookup(proxyClass);
-
- assertEquals("Proxy classes should have zero serialVersionUID", 0,
- proxyStreamClass.getSerialVersionUID());
- ObjectStreamField[] proxyFields = proxyStreamClass.getFields();
- assertEquals("Proxy classes should have no serialized fields", 0,
- proxyFields.length);
-
- ObjectStreamClass enumStreamClass = ObjectStreamClass
- .lookup(Thread.State.class);
-
- assertEquals("Enum classes should have zero serialVersionUID", 0,
- enumStreamClass.getSerialVersionUID());
- ObjectStreamField[] enumFields = enumStreamClass.getFields();
- assertEquals("Enum classes should have no serialized fields", 0,
- enumFields.length);
- }
-
- /**
- * @since 1.6
- */
- static class NonSerialzableClass {
- private static final long serialVersionUID = 1l;
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- /**
- * @since 1.6
- */
- static class ExternalizableClass implements Externalizable {
-
- private static final long serialVersionUID = -4285635779249689129L;
-
- public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException {
- throw new ClassNotFoundException();
- }
-
- public void writeExternal(ObjectOutput output) throws IOException {
- throw new IOException();
- }
-
- }
-
- /**
- * @tests java.io.ObjectStreamClass#lookupAny(java.lang.Class)
- * @since 1.6
- */
- public void test_lookupAnyLjava_lang_Class() {
- // Test for method java.io.ObjectStreamClass
- // java.io.ObjectStreamClass.lookupAny(java.lang.Class)
- ObjectStreamClass osc = ObjectStreamClass.lookupAny(DummyClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$DummyClass", osc // android-changed
- .getName());
-
- osc = ObjectStreamClass.lookupAny(NonSerialzableClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$NonSerialzableClass", // android-changed
- osc.getName());
-
- osc = ObjectStreamClass.lookupAny(ExternalizableClass.class);
- assertEquals("lookup returned wrong class: " + osc.getName(),
- "tests.api.java.io.ObjectStreamClassTest$ExternalizableClass", // android-changed
- osc.getName());
-
- osc = ObjectStreamClass.lookup(NonSerialzableClass.class);
- assertNull(osc);
-
- }
-
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java
deleted file mode 100644
index 30a0c4e..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamExceptionTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ObjectStreamException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(ObjectStreamException.class)
-public class ObjectStreamExceptionTest extends junit.framework.TestCase {
-
- class MyObjectStreamException extends ObjectStreamException {
- private static final long serialVersionUID = 1L;
-
- public MyObjectStreamException() {
- super();
- }
-
- public MyObjectStreamException(String detailMessage) {
- super(detailMessage);
- }
- }
-
- /**
- * @tests java.io.ObjectStreamException#ObjectStreamException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ObjectStreamException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new MyObjectStreamException();
- fail("Test 1: MyObjectStreamException expected.");
- } catch (MyObjectStreamException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.ObjectStreamException#ObjectStreamException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "ObjectStreamException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new MyObjectStreamException("Something went wrong.");
- fail("Test 1: MyObjectStreamException expected.");
- } catch (MyObjectStreamException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java b/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java
deleted file mode 100644
index dd8545b..0000000
--- a/luni/src/test/java/tests/api/java/io/ObjectStreamFieldTest.java
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.NotActiveException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.ObjectStreamClass;
-import java.io.ObjectStreamField;
-import java.io.Serializable;
-import java.io.StreamCorruptedException;
-import java.util.Date;
-
-@TestTargetClass(ObjectStreamField.class)
-public class ObjectStreamFieldTest extends junit.framework.TestCase {
-
- static class DummyClass implements Serializable {
- private static final long serialVersionUID = 999999999999998L;
-
- boolean bField = true;
- char cField = 'c';
- double dField = 424242.4242;
- float fField = 24.12F;
- int iField = 1965;
- long lField = 9999999L;
- short sField = 42;
-
- long bam = 999L;
-
- int ham = 9999;
-
- int sam = 8888;
-
- Object hola = new Object();
-
- public static long getUID() {
- return serialVersionUID;
- }
- }
-
- class MyObjectStreamField extends ObjectStreamField {
- public MyObjectStreamField(String name, Class<?> cl) {
- super(name, cl);
- }
-
- public void setOffset(int newValue) {
- super.setOffset(newValue);
- }
- }
-
- ObjectStreamClass osc;
-
- ObjectStreamField hamField;
-
- ObjectStreamField samField;
-
- ObjectStreamField bamField;
-
- ObjectStreamField holaField;
-
- /**
- * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
- * java.lang.Class)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectStreamField(String, Class<T>)",
- method = "ObjectStreamField",
- args = {java.lang.String.class, java.lang.Class.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_Class() {
- ObjectStreamField osf = new ObjectStreamField("aField", int.class);
- assertTrue("Test 1: Name member not set correctly.",
- osf.getName().equals("aField"));
- assertTrue("Test 2: Type member not set correctly.",
- osf.getType().equals(int.class));
-
- // Repeat the tests with a different object to make sure
- // that we have not tested against default values.
- osf = new ObjectStreamField("anotherField", String.class);
- assertTrue("Test 3: Name member not set correctly.",
- osf.getName().equals("anotherField"));
- assertTrue("Test 4: Type member not set correctly.",
- osf.getType().equals(String.class));
-
- // Invalid argument tests.
- try {
- osf = new ObjectStreamField(null, boolean.class);
- fail("Test 5: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- try {
- osf = new ObjectStreamField("thisField", null);
- fail("Test 6: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#ObjectStreamField(java.lang.String,
- * java.lang.Class)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies ObjectStreamField(String, Class<T>, boolean)",
- method = "ObjectStreamField",
- args = {java.lang.String.class, java.lang.Class.class, boolean.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_ClassB() {
- ObjectStreamField osf = new ObjectStreamField("aField", int.class, false);
- assertTrue("Test 1: Name member not set correctly.",
- osf.getName().equals("aField"));
- assertTrue("Test 2: Type member not set correctly.",
- osf.getType().equals(int.class));
- assertFalse("Test 3: Unshared member not set correctly.",
- osf.isUnshared());
-
- // Repeat the tests with a different object to make sure
- // that we have not tested against default values.
- osf = new ObjectStreamField("anotherField", String.class, true);
- assertTrue("Test 4: Name member not set correctly.",
- osf.getName().equals("anotherField"));
- assertTrue("Test 5: Type member not set correctly.",
- osf.getType().equals(String.class));
- assertTrue("Test 6: Unshared member not set correctly.",
- osf.isUnshared());
-
- // Invalid argument tests.
- try {
- osf = new ObjectStreamField(null, boolean.class);
- fail("Test 7: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- try {
- osf = new ObjectStreamField("thisField", null);
- fail("Test 8: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#compareTo(java.lang.Object)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "compareTo",
- args = {java.lang.Object.class}
- )
- public void test_compareToLjava_lang_Object() {
- // Test for method int
- // java.io.ObjectStreamField.compareTo(java.lang.Object)
- assertTrue("Object compared to int did not return > 0", holaField
- .compareTo(hamField) > 0);
- assertEquals("Int compared to itself did not return 0", 0, hamField
- .compareTo(hamField));
- assertTrue("(Int)ham compared to (Int)sam did not return < 0", hamField
- .compareTo(samField) < 0);
- }
-
- /**
- * @tests java.io.ObjectStreamField#getName()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getName",
- args = {}
- )
- public void test_getName() {
- // Test for method java.lang.String java.io.ObjectStreamField.getName()
- assertEquals("Field did not return correct name", "hola", holaField.getName());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getOffset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getOffset",
- args = {}
- )
- public void test_getOffset() {
- // Test for method int java.io.ObjectStreamField.getOffset()
- ObjectStreamField[] osfArray;
- osfArray = osc.getFields();
- int[] expectedOffsets = {0, 1, 9, 11, 19, 23, 27, 31, 39, 41, 0};
-
- assertTrue("getOffset() did not return reasonable values.", osfArray[0]
- .getOffset() != osfArray[1].getOffset());
-
- for (int i = 0; i < expectedOffsets.length; i++) {
- assertEquals(String.format("Unexpected value for osfArray[%d].getOffset(): ", i),
- expectedOffsets[i], osfArray[i].getOffset());
-
- }
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType() {
- // Test for method java.lang.Class java.io.ObjectStreamField.getType()
- assertTrue("getType on an Object field did not answer Object",
- holaField.getType().equals(Object.class));
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeCode()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTypeCode",
- args = {}
- )
- public void test_getTypeCode() {
- // Test for method char java.io.ObjectStreamField.getTypeCode()
- assertEquals("getTypeCode on an Object field did not answer 'L'",
- 'L', holaField.getTypeCode());
- assertEquals("getTypeCode on a long field did not answer 'J'", 'J', bamField
- .getTypeCode());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getTypeString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getTypeString",
- args = {}
- )
- public void test_getTypeString() {
- assertTrue("getTypeString returned: " + holaField.getTypeString(),
- holaField.getTypeString().indexOf("Object") >= 0);
- assertNull("Primitive types' strings should be null", hamField.getTypeString());
-
- ObjectStreamField osf = new ObjectStreamField("s", String.class, true);
- assertTrue(osf.getTypeString() == "Ljava/lang/String;");
- }
-
- /**
- * @tests java.io.ObjectStreamField#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.ObjectStreamField.toString()
- assertTrue("toString on a long returned: " + bamField.toString(),
- bamField.toString().indexOf("bam") >= 0);
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType_Deserialized() throws IOException,
- ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new SerializableObject());
- oos.close();
- baos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- SerializableObject obj = (SerializableObject) ois.readObject();
-
- ObjectStreamClass oc = obj.getObjectStreamClass();
- ObjectStreamField field = oc.getField("i");
- assertEquals(Object.class, field.getType());
- }
-
- /**
- * @tests java.io.ObjectStreamField#setOffset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setOffset",
- args = {int.class}
- )
- public void test_setOffsetI() {
- MyObjectStreamField f = new MyObjectStreamField("aField", int.class);
- f.setOffset(42);
- assertEquals("Test 1: Unexpected offset value.", 42, f.getOffset());
- f.setOffset(2008);
- assertEquals("Test 2: Unexpected offset value.", 2008, f.getOffset());
- }
-
- /**
- * @tests java.io.ObjectStreamField#getType()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getType",
- args = {}
- )
- public void test_getType_MockObjectInputStream() throws IOException, ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(new SerializableObject());
- oos.close();
- baos.close();
-
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- MockObjectInputStream ois = new MockObjectInputStream(bais);
- ois.readObject();
-
- ObjectStreamClass oc = ois.getObjectStreamClass();
- ObjectStreamField field = oc.getField("i");
- assertEquals(Object.class, field.getType());
- }
-
- /**
- * @tests java.io.ObjectStreamField#isPrimitive()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isPrimitive",
- args = {}
- )
- public void test_isPrimitive() {
- // Test for method int java.io.ObjectStreamField.getOffset()
- ObjectStreamField[] osfArray;
- osfArray = osc.getFields();
-
- for (int i = 0; i < (osfArray.length - 1); i++) {
- assertTrue(String.format("osfArray[%d].isPrimitive() should return true.", i),
- osfArray[i].isPrimitive());
- }
- assertFalse(String.format("osfArray[%d].isPrimitive() should return false.",
- osfArray.length - 1),
- osfArray[(osfArray.length - 1)].isPrimitive());
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "isUnshared",
- args = {}
- )
- public void test_isUnshared() throws Exception {
- SerializableObject2 obj = new SerializableObject2();
-
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(obj);
- oos.close();
- baos.close();
- byte[] bytes = baos.toByteArray();
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- SerializableObject2 newObj = (SerializableObject2) ois.readObject();
-
- ObjectInputStream.GetField getField = newObj.getGetField();
- ObjectStreamClass objectStreamClass = getField.getObjectStreamClass();
-
- assertTrue(objectStreamClass.getField("i").isUnshared());
- assertFalse(objectStreamClass.getField("d").isUnshared());
- assertTrue(objectStreamClass.getField("s").isUnshared());
-
- assertEquals(1000, getField.get("i", null));
- assertEquals(SerializableObject2.today, getField.get("d", null));
- assertEquals("Richard", getField.get("s", null));
-
- assertTrue(objectStreamClass.getField("s").getTypeString() == "Ljava/lang/String;");
-
- assertEquals(0, objectStreamClass.getField("d").getOffset());
- assertEquals(1, objectStreamClass.getField("i").getOffset());
- assertEquals(2, objectStreamClass.getField("s").getOffset());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- osc = ObjectStreamClass.lookup(DummyClass.class);
- bamField = osc.getField("bam");
- samField = osc.getField("sam");
- hamField = osc.getField("ham");
- holaField = osc.getField("hola");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
-
-class SerializableObject implements Serializable {
- public ObjectInputStream.GetField getField = null;
-
- private static final long serialVersionUID = -2953957835918368056L;
-
- public Date d;
-
- public Integer i;
-
- public Exception e;
-
- public SerializableObject() {
- d = new Date();
- i = new Integer(1);
- e = new Exception("e");
- }
-
- private void writeObject(ObjectOutputStream o) throws IOException {
- o.putFields().put("d", new Date());
- o.putFields().put("i", new Integer(11));
- o.writeFields();
- }
-
- private void readObject(ObjectInputStream in) throws NotActiveException,
- IOException, ClassNotFoundException {
- getField = in.readFields();
- d = (Date) getField.get("d", null);
- i = (Integer) getField.get("i", null);
- }
-
- public ObjectStreamClass getObjectStreamClass() {
- return getField.getObjectStreamClass();
- }
-}
-
-class MockObjectInputStream extends ObjectInputStream {
- private ObjectStreamClass temp = null;
-
- public MockObjectInputStream() throws SecurityException, IOException {
- super();
- }
-
- public MockObjectInputStream(InputStream in)
- throws StreamCorruptedException, IOException {
- super(in);
- }
-
- public ObjectStreamClass readClassDescriptor() throws IOException,
- ClassNotFoundException {
- ObjectStreamClass osc = super.readClassDescriptor();
- //To get the ObjectStreamClass of SerializableObject
- if (osc.getSerialVersionUID() == -2953957835918368056L) {
- temp = osc;
- }
- return osc;
- }
-
- public ObjectStreamClass getObjectStreamClass() {
- return temp;
- }
-}
-
-class SerializableObject2 implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private static final ObjectStreamField[] serialPersistentFields = {
- new ObjectStreamField("i", Integer.class, true),
- new ObjectStreamField("d", Date.class, false),
- new ObjectStreamField("s", String.class, true),
- };
-
- private ObjectInputStream.GetField getField;
-
- public static Date today = new Date(1172632429156l);
-
- public ObjectInputStream.GetField getGetField() {
- return getField;
- }
-
- private void writeObject(ObjectOutputStream o) throws IOException {
- ObjectOutputStream.PutField putField = o.putFields();
- putField.put("i", new Integer(1000));
- putField.put("d", today);
- putField.put("s", "Richard");
- o.writeFields();
- }
-
- private void readObject(ObjectInputStream in) throws NotActiveException,
- IOException, ClassNotFoundException {
- getField = in.readFields();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java b/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java
deleted file mode 100644
index b2a1406..0000000
--- a/luni/src/test/java/tests/api/java/io/OpenRandomFileTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
-import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-/**
- * TODO Type description
- */
-@TestTargetClass(RandomAccessFile.class)
-public class OpenRandomFileTest extends TestCase {
-
- public static void main(String[] args) {
- new OpenRandomFileTest().testOpenEmptyFile();
- }
-
- public OpenRandomFileTest() {
- super();
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testOpenNonEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
- FileOutputStream fos = new FileOutputStream(file);
- fos.write(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
- fos.close();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void testOpenEmptyFile() {
- try {
- File file = File.createTempFile("test", "tmp");
- assertTrue(file.exists());
- file.deleteOnExit();
-
- String fileName = file.getCanonicalPath();
- RandomAccessFile raf = new RandomAccessFile(fileName, "rw");
- raf.close();
- } catch (IOException ex) {
- fail(ex.getLocalizedMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/OutputStreamTest.java b/luni/src/test/java/tests/api/java/io/OutputStreamTest.java
deleted file mode 100644
index 7acd737..0000000
--- a/luni/src/test/java/tests/api/java/io/OutputStreamTest.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.OutputStream;
-import java.io.IOException;
-
-@TestTargetClass(
- value = OutputStream.class,
- untestedMethods = {
- @TestTargetNew(
- method = "OutputStream",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "Constructor just calls super()."
- ),
- @TestTargetNew(
- method = "close",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- ),
- @TestTargetNew(
- method = "flush",
- args = {},
- level = TestLevel.NOT_NECESSARY,
- notes = "According to specification, the implementation " +
- "does nothing."
- )
- }
-)
-public class OutputStreamTest extends junit.framework.TestCase {
-
- class BasicOutputStream extends OutputStream {
-
- private static final int BUFFER_SIZE = 20;
- private byte[] buffer;
- private int position;
-
- public BasicOutputStream() {
- buffer = new byte[BUFFER_SIZE];
- position = 0;
- }
-
- public void write(int oneByte) throws IOException {
- if (position < BUFFER_SIZE) {
- buffer[position] = (byte) (oneByte & 255);
- position++;
- } else {
- throw new IOException("Internal buffer overflow.");
- }
- }
-
- public byte[] getBuffer() {
- return buffer;
- }
- }
-
- private final byte[] shortByteArray = "Lorem ipsum...".getBytes();
- private final byte[] longByteArray = "Lorem ipsum dolor sit amet...".getBytes();
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(byte[]).",
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() {
- BasicOutputStream bos = new BasicOutputStream();
- boolean expected;
- byte[] buffer;
-
- try {
- bos.write(shortByteArray);
- } catch (IOException e) {
- fail("Test 1: Unexpected IOException encountered.");
- }
-
- expected = true;
- buffer = bos.getBuffer();
- for (int i = 0; i < (shortByteArray.length) && expected; i++) {
- expected = (shortByteArray[i] == buffer[i]);
- }
- assertTrue("Test 1: Test byte array has not been written correctly.",
- expected);
-
- try {
- bos.write(longByteArray);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {}
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Verifies write(byte[], int, int).",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() {
- BasicOutputStream bos = new BasicOutputStream();
- boolean expected;
- byte[] buffer;
-
- try {
- bos.write(shortByteArray, 6, 5);
- } catch (IOException e) {
- fail("Test 1: Unexpected IOException encountered.");
- }
-
- expected = true;
- buffer = bos.getBuffer();
- for (int i = 6, j = 0; j < 5 && expected; i++, j++) {
- expected = (shortByteArray[i] == buffer[j]);
- }
- assertTrue("Test 1: Test byte array has not been written correctly.",
- expected);
-
- try {
- bos.write(longByteArray, 5, 20);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {}
-
- try {
- bos.write(longByteArray, -1, 10);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException encountered.");
- }
-
- try {
- bos.write(longByteArray, 10, -1);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- } catch (IOException e) {
- fail("Test 4: Unexpected IOException encountered.");
- }
-
- try {
- bos.write(longByteArray, 20, 10);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- } catch (IOException e) {
- fail("Test 5: Unexpected IOException encountered.");
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java b/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
deleted file mode 100644
index fe6e3f2..0000000
--- a/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
+++ /dev/null
@@ -1,878 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetEncoder;
-
-import tests.support.Support_OutputStream;
-
-import junit.framework.TestCase;
-
-/**
- *
- */
-@TestTargetClass(OutputStreamWriter.class)
-public class OutputStreamWriterTest extends TestCase {
-
- private static final int UPPER = 0xd800;
-
- private static final int BUFFER_SIZE = 10000;
-
- static private final String[] MINIMAL_CHARSETS = new String[] { "US-ASCII",
- "ISO-8859-1", "UTF-16BE", "UTF-16LE", "UTF-16", "UTF-8" };
-
- OutputStreamWriter osw;
-
- InputStreamReader isr;
-
- private Support_OutputStream fos;
-
- public String testString = "This is a test message with Unicode characters. \u4e2d\u56fd is China's name in Chinese";
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- fos = new Support_OutputStream(500);
- osw = new OutputStreamWriter(fos, "UTF-8");
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- try {
- if (isr != null) isr.close();
- osw.close();
- } catch (Exception e) {
- }
-
- super.tearDown();
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class}
- )
- public void test_ConstructorLjava_io_OutputStream() throws IOException {
- OutputStreamWriter writer = null;
-
- try {
- writer = new OutputStreamWriter(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer = new OutputStreamWriter(new Support_OutputStream());
- } catch (Exception e) {
- fail("Test 2: Unexpected exception: " + e.getMessage());
- }
-
- // Test that the default encoding has been used.
- assertEquals("Test 3: Incorrect default encoding used.",
- Charset.defaultCharset(),
- Charset.forName(writer.getEncoding()));
-
- if (writer != null) writer.close();
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_OutputStreamLjava_lang_String()
- throws UnsupportedEncodingException {
-
- try {
- osw = new OutputStreamWriter(null, "utf-8");
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- osw = new OutputStreamWriter(fos, (String) null);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- osw = new OutputStreamWriter(fos, "");
- fail("Test 3: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
-
- try {
- osw = new OutputStreamWriter(fos, "Bogus");
- fail("Test 4: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- // Expected
- }
-
- try {
- osw = new OutputStreamWriter(fos, "8859_1");
- } catch (UnsupportedEncodingException e) {
- fail("Test 5: Unexpected UnsupportedEncodingException.");
- }
-
- assertEquals("Test 6: Encoding not set correctly. ",
- Charset.forName("8859_1"),
- Charset.forName(osw.getEncoding()));
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.nio.charset.Charset)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.nio.charset.Charset.class}
- )
- public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_Charset()
- throws IOException {
- OutputStreamWriter writer;
- Support_OutputStream out = new Support_OutputStream();
- Charset cs = Charset.forName("ascii");
-
- try {
- writer = new OutputStreamWriter(null, cs);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer = new OutputStreamWriter(out, (Charset) null);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- writer = new OutputStreamWriter(out, cs);
- assertEquals("Test 3: Encoding not set correctly. ",
- cs, Charset.forName(writer.getEncoding()));
- writer.close();
- }
-
- /**
- * @tests java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream,
- * java.nio.charset.CharsetEncoder)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "OutputStreamWriter",
- args = {java.io.OutputStream.class, java.nio.charset.CharsetEncoder.class}
- )
- public void test_ConstructorLjava_io_OutputStreamLjava_nio_charset_CharsetEncoder()
- throws IOException {
- OutputStreamWriter writer;
- Support_OutputStream out = new Support_OutputStream();
- Charset cs = Charset.forName("ascii");
- CharsetEncoder enc = cs.newEncoder();
-
- try {
- writer = new OutputStreamWriter(null, enc);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer = new OutputStreamWriter(out, (CharsetEncoder) null);
- fail("Test 2: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- writer = new OutputStreamWriter(out, cs);
- assertEquals("Test 3: CharacterEncoder not set correctly. ",
- cs, Charset.forName(writer.getEncoding()));
- writer.close();
- }
-
- /**
- * @tests java.io.OutputStreamWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "An issue in the API code has been identified (ticket #87). This test must be updated when the ticket is closed.",
- method = "close",
- args = {}
- )
- public void test_close() {
-
- fos.setThrowsException(true);
- try {
- osw.close();
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
-/* Test 2 does not work and has therefore been disabled (see Ticket #87).
- // Test 2: Write should not fail since the closing
- // in test 1 has not been successful.
- try {
- osw.write("Lorem ipsum...");
- } catch (IOException e) {
- fail("Test 2: Unexpected IOException.");
- }
-
- // Test 3: Close should succeed.
- fos.setThrowsException(false);
- try {
- osw.close();
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException.");
- }
-*/
-
- ByteArrayOutputStream bout = new ByteArrayOutputStream();
- try {
- OutputStreamWriter writer = new OutputStreamWriter(bout,
- "ISO2022JP");
- writer.write(new char[] { 'a' });
- writer.close();
- // The default is ASCII, there should not be any mode changes.
- String converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("Test 4: Invalid conversion: " + converted,
- converted.equals("a"));
-
- bout.reset();
- writer = new OutputStreamWriter(bout, "ISO2022JP");
- writer.write(new char[] { '\u3048' });
- writer.flush();
- // The byte sequence should not switch to ASCII mode until the
- // stream is closed.
- converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("Test 5: Invalid conversion: " + converted,
- converted.equals("\u001b$B$("));
- writer.close();
- converted = new String(bout.toByteArray(), "ISO8859_1");
- assertTrue("Test 6: Invalid conversion: " + converted,
- converted.equals("\u001b$B$(\u001b(B"));
-
- bout.reset();
- writer = new OutputStreamWriter(bout, "ISO2022JP");
- writer.write(new char[] { '\u3048' });
- writer.write(new char[] { '\u3048' });
- writer.close();
- // There should not be a mode switch between writes.
- assertEquals("Test 7: Invalid conversion. ",
- "\u001b$B$($(\u001b(B",
- new String(bout.toByteArray(), "ISO8859_1"));
- } catch (UnsupportedEncodingException e) {
- // Can't test missing converter.
- System.out.println(e);
- } catch (IOException e) {
- fail("Unexpected: " + e);
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
- public void test_flush() {
- // Test for method void java.io.OutputStreamWriter.flush()
- try {
- char[] buf = new char[testString.length()];
- osw.write(testString, 0, testString.length());
- osw.flush();
- openInputStream();
- isr.read(buf, 0, buf.length);
- assertTrue("Test 1: Characters have not been flushed.",
- new String(buf, 0, buf.length).equals(testString));
- } catch (Exception e) {
- fail("Test 1: Unexpected exception: " + e.getMessage());
- }
-
- fos.setThrowsException(true);
- try {
- osw.flush();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- fos.setThrowsException(false);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {},
- clazz = InputStreamReader.class
- )
- })
- public void test_singleCharIO() throws Exception {
- int upper;
- OutputStreamWriter writer = null;
- ByteArrayOutputStream out;
- InputStreamReader isr = null;
-
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- out = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(out, MINIMAL_CHARSETS[i]);
-
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- default:
- upper = UPPER;
- }
-
- for (int c = 0; c < upper; ++c) {
- writer.write(c);
- }
- writer.flush();
- byte[] result = out.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- for (int expected = 0; expected < upper; ++expected) {
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i], expected, isr.read());
- }
- } finally {
- try {
- if (isr != null) isr.close();
- } catch (Exception e) {
- }
- try {
- if (writer != null) writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "write",
- args = {char[].class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {},
- clazz = InputStreamReader.class
- )
- })
- public void test_write$C() throws Exception {
- int upper;
- InputStreamReader isr = null;
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OutputStreamWriter writer = null;
-
- char[] largeBuffer = new char[BUFFER_SIZE];
- for (int i = 0; i < MINIMAL_CHARSETS.length; ++i) {
- try {
- baos = new ByteArrayOutputStream();
- writer = new OutputStreamWriter(baos, MINIMAL_CHARSETS[i]);
-
- switch (i) {
- case 0:
- upper = 128;
- break;
- case 1:
- upper = 256;
- break;
- default:
- upper = UPPER;
- }
-
- int m = 0;
- for (int c = 0; c < upper; ++c) {
- largeBuffer[m++] = (char) c;
- if (m == BUFFER_SIZE) {
- writer.write(largeBuffer);
- m = 0;
- }
- }
- writer.write(largeBuffer, 0, m);
- writer.flush();
- byte[] result = baos.toByteArray();
-
- isr = new InputStreamReader(new ByteArrayInputStream(result),
- MINIMAL_CHARSETS[i]);
- int expected = 0, read = 0, j = 0;
- while (expected < upper) {
- if (j == read) {
- read = isr.read(largeBuffer);
- j = 0;
- }
- assertEquals("Error when reading bytes in "
- + MINIMAL_CHARSETS[i] + " at " + j, expected++, largeBuffer[j++]);
- }
- } finally {
- try {
- if (isr != null) isr.close();
- } catch (Exception e) {
- }
- try {
- if (writer != null) writer.close();
- } catch (Exception e) {
- }
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_US_ASCII() throws Exception {
- testEncodeCharset("US-ASCII", 128);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_ISO_8859_1() throws Exception {
- testEncodeCharset("ISO-8859-1", 256);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_UTF_16BE() throws Exception {
- testEncodeCharset("UTF-16BE", 0xd800);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_UTF_16LE() throws Exception {
- testEncodeCharset("UTF-16LE", 0xd800);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_UTF_16() throws Exception {
- testEncodeCharset("UTF-16", 0xd800);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write_UTF_8() throws Exception {
- testEncodeCharset("UTF-8", 0xd800);
- }
-
- private void testEncodeCharset(String charset, int maxChar) throws Exception {
- char[] chars = new char[maxChar];
- for (int i = 0; i < maxChar; i++) {
- chars[i] = (char) i;
- }
-
- // to byte array
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- OutputStreamWriter charsOut = new OutputStreamWriter(bytesOut, charset);
- charsOut.write(chars);
- charsOut.flush();
-
- // decode from byte array, one character at a time
- ByteArrayInputStream bytesIn = new ByteArrayInputStream(bytesOut.toByteArray());
- InputStreamReader charsIn = new InputStreamReader(bytesIn, charset);
- for (int i = 0; i < maxChar; i++) {
- assertEquals(i, charsIn.read());
- }
- assertEquals(-1, charsIn.read());
-
- // decode from byte array, using byte buffers
- bytesIn = new ByteArrayInputStream(bytesOut.toByteArray());
- charsIn = new InputStreamReader(bytesIn, charset);
- char[] decoded = new char[maxChar];
- for (int r = 0; r < maxChar; ) {
- r += charsIn.read(decoded, r, maxChar - r);
- }
- assertEquals(-1, charsIn.read());
- for (int i = 0; i < maxChar; i++) {
- assertEquals(i, decoded[i]);
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#getEncoding()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getEncoding",
- args = {}
- )
- public void test_getEncoding() throws IOException {
- OutputStreamWriter writer;
- writer = new OutputStreamWriter(new Support_OutputStream(), "utf-8");
- assertEquals("Test 1: Incorrect encoding returned.",
- Charset.forName("utf-8"),
- Charset.forName(writer.getEncoding()));
-
- writer.close();
- assertNull("Test 2: getEncoding() did not return null for a closed writer.",
- writer.getEncoding());
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() throws IOException {
- char[] chars = testString.toCharArray();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Support_OutputStream out = new Support_OutputStream(500);
- OutputStreamWriter writer;
-
- writer = new OutputStreamWriter(out, "utf-8");
-
- try {
- writer.write(chars, -1, 1);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(chars, 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(new char[0], 0, 1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write((char[]) null, 0, 1);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- try {
- writer.write(chars, 1, chars.length);
- fail("Test 5a: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, 0, chars.length + 1);
- fail("Test 5b: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, chars.length, 1);
- fail("Test 5c: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- writer.write(chars, chars.length + 1, 0);
- fail("Test 5d: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- out.setThrowsException(true);
- try {
- for (int i = 0; i < 200; i++) {
- writer.write(chars, 0, chars.length);
- }
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- out.setThrowsException(false);
-
- writer.close();
- writer = new OutputStreamWriter(baos, "utf-8");
- writer.write(chars, 1, 2);
- writer.flush();
- assertEquals("Test 7: write(char[], int, int) has not produced the " +
- "expected content in the output stream.",
- "hi", baos.toString("utf-8"));
-
- writer.write(chars, 0, chars.length);
- writer.flush();
- assertEquals("Test 8: write(char[], int, int) has not produced the " +
- "expected content in the output stream.",
- "hi" + testString, baos.toString("utf-8"));
-
- writer.close();
- try {
- writer.write((char[]) null, -1, -1);
- fail("Test 9: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- Support_OutputStream out = new Support_OutputStream(500);
- OutputStreamWriter writer;
-
- out.setThrowsException(true);
- writer = new OutputStreamWriter(out, "utf-8");
- try {
- // Since there is an internal buffer in the encoder, more than
- // one character needs to be written.
- for (int i = 0; i < 200; i++) {
- for (int j = 0; j < testString.length(); j++) {
- writer.write(testString.charAt(j));
- }
- }
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- out.setThrowsException(false);
- writer.close();
-
- writer = new OutputStreamWriter(out, "utf-8");
- writer.write(1);
- writer.flush();
- String str = new String(out.toByteArray(), "utf-8");
- assertEquals("Test 2: ", "\u0001", str);
-
- writer.write(2);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("Test 3: ", "\u0001\u0002", str);
-
- writer.write(-1);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("Test 4: ", "\u0001\u0002\uffff", str);
-
- writer.write(0xfedcb);
- writer.flush();
- str = new String(out.toByteArray(), "utf-8");
- assertEquals("Test 5: ", "\u0001\u0002\uffff\uedcb", str);
-
- writer.close();
- try {
- writer.write(1);
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.OutputStreamWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Support_OutputStream out = new Support_OutputStream(500);
- OutputStreamWriter writer;
-
- writer = new OutputStreamWriter(out, "utf-8");
-
- try {
- writer.write("Lorem", -1, 0);
- fail("Test 1: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write("Lorem", 0, -1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write("", 0, 1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(testString, 1, testString.length());
- fail("Test 4a: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(testString, 0, testString.length() + 1);
- fail("Test 4b: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(testString, testString.length(), 1);
- fail("Test 4c: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write(testString, testString.length() + 1, 0);
- fail("Test 4d: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- writer.write((String) null, 0, 1);
- fail("Test 5: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected
- }
-
- out.setThrowsException(true);
- try {
- for (int i = 0; i < 200; i++) {
- writer.write(testString, 0, testString.length());
- }
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- out.setThrowsException(false);
-
- writer.close();
- writer = new OutputStreamWriter(baos, "utf-8");
-
- writer.write("abc", 1, 2);
- writer.flush();
- assertEquals("Test 7: write(String, int, int) has not produced the " +
- "expected content in the output stream.",
- "bc", baos.toString("utf-8"));
-
- writer.write(testString, 0, testString.length());
- writer.flush();
- assertEquals("Test 7: write(String, int, int) has not produced the " +
- "expected content in the output stream.",
- "bc" + testString, baos.toString("utf-8"));
-
- writer.close();
- try {
- writer.write("abc", 0, 1);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected
- }
- }
-
- private void openInputStream() {
- try {
- isr = new InputStreamReader(new ByteArrayInputStream(fos.toByteArray()), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- fail("UTF-8 not supported");
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java b/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
deleted file mode 100644
index 171912b..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedInputStreamTest.java
+++ /dev/null
@@ -1,451 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-
-public class PipedInputStreamTest extends junit.framework.TestCase {
-
- private final int BUFFER_SIZE = 1024;
-
- static class PWriter implements Runnable {
- PipedOutputStream pos;
-
- public byte bytes[];
-
- public void run() {
- try {
- pos.write(bytes);
- synchronized (this) {
- notify();
- }
- } catch (IOException e) {
- e.printStackTrace(System.out);
- System.out.println("Could not write bytes");
- }
- }
-
- public PWriter(PipedOutputStream pout, int nbytes) {
- pos = pout;
- bytes = new byte[nbytes];
- for (int i = 0; i < bytes.length; i++) {
- bytes[i] = (byte) (System.currentTimeMillis() % 9);
- }
- }
- }
-
- Thread t;
-
- PWriter pw;
-
- PipedInputStream pis;
-
- PipedOutputStream pos;
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream()
- */
- public void test_Constructor() {
- // Test for method java.io.PipedInputStream()
- // Used in tests
- }
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream)
- */
- public void test_ConstructorLjava_io_PipedOutputStream() throws Exception {
- // Test for method java.io.PipedInputStream(java.io.PipedOutputStream)
- pis = new PipedInputStream(new PipedOutputStream());
- pis.available();
- }
-
-
- /**
- * @test java.io.PipedInputStream#read()
- */
- public void test_readException() throws IOException {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- try {
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
- assertTrue(t.isAlive());
- while (true) {
- pis.read();
- t.interrupt();
- }
- } catch (IOException e) {
- if (!e.getMessage().contains("Write end dead") && !e.getMessage().contains("Pipe broken")) { // android-changed
- throw e;
- }
- } finally {
- try {
- pis.close();
- pos.close();
- } catch (IOException ee) {}
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#available()
- */
- public void test_available() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertTrue("Available returned incorrect number of bytes: "
- + pis.available(), pis.available() == 1000);
-
- PipedInputStream pin = new PipedInputStream();
- PipedOutputStream pout = new PipedOutputStream(pin);
- // Writing another byte would cause the write to wait
- // for a read before returning
- for (int i = 0; i < BUFFER_SIZE; i++) {
- pout.write(i);
- }
- assertEquals("Incorrect available count", BUFFER_SIZE , pin.available());
- }
-
- /**
- * @tests java.io.PipedInputStream#close()
- */
- public void test_close() throws IOException {
- // Test for method void java.io.PipedInputStream.close()
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
- pis.connect(pos);
- pis.close();
- try {
- pos.write((byte) 127);
- fail("Failed to throw expected exception");
- } catch (IOException e) {
- // The spec for PipedInput saya an exception should be thrown if
- // a write is attempted to a closed input. The PipedOuput spec
- // indicates that an exception should be thrown only when the
- // piped input thread is terminated without closing
- return;
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#connect(java.io.PipedOutputStream)
- */
- public void test_connectLjava_io_PipedOutputStream() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
- assertEquals("Non-conected pipe returned non-zero available bytes", 0,
- pis.available());
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertEquals("Available returned incorrect number of bytes", 1000, pis
- .available());
- }
-
- /**
- * @tests java.io.PipedInputStream#read()
- */
- public void test_read() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- synchronized (pw) {
- pw.wait(10000);
- }
- assertEquals("Available returned incorrect number of bytes", 1000, pis
- .available());
- assertEquals("read returned incorrect byte", pw.bytes[0], (byte) pis
- .read());
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII() throws Exception {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- t = new Thread(pw = new PWriter(pos, 1000));
- t.start();
-
- byte[] buf = new byte[400];
- synchronized (pw) {
- pw.wait(10000);
- }
- assertTrue("Available returned incorrect number of bytes: "
- + pis.available(), pis.available() == 1000);
- pis.read(buf, 0, 400);
- for (int i = 0; i < 400; i++) {
- assertEquals("read returned incorrect byte[]", pw.bytes[i], buf[i]);
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- * Regression for HARMONY-387
- */
- public void test_read$BII_2() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII_3() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], -1, 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#read(byte[], int, int)
- */
- public void test_read$BII_4() throws IOException {
- PipedInputStream obj = new PipedInputStream();
- try {
- obj.read(new byte[0], -1, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#receive(int)
- */
- public void test_receive() throws IOException {
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- // test if writer recognizes dead reader
- pis.connect(pos);
- class WriteRunnable implements Runnable {
-
- boolean pass = false;
-
- volatile boolean readerAlive = true;
-
- public void run() {
- try {
- pos.write(1);
- while (readerAlive) {
- ;
- }
- try {
- pos.write(new byte[BUFFER_SIZE]);
- // should throw exception since buffer is full and
- // reader thread is now dead
- pos.write(1);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
-
- boolean pass;
-
- public void run() {
- try {
- pis.read();
- pass = true;
- } catch (IOException e) {
- }
- }
- }
- ;
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- ;
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- ;
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
-
- // attempt to write to stream after writer closed
- pis = new PipedInputStream();
- pos = new PipedOutputStream();
-
- pis.connect(pos);
- class MyRunnable implements Runnable {
-
- boolean pass;
-
- public void run() {
- try {
- pos.write(1);
- } catch (IOException e) {
- pass = true;
- }
- }
- }
- MyRunnable myRun = new MyRunnable();
- synchronized (pis) {
- t = new Thread(myRun);
- // thread t will be blocked inside pos.write(1)
- // when it tries to call the synchronized method pis.receive
- // because we hold the monitor for object pis
- t.start();
- try {
- // wait for thread t to get to the call to pis.receive
- Thread.sleep(100);
- } catch (InterruptedException e) {
- }
- // now we close
- pos.close();
- }
- // we have exited the synchronized block, so now thread t will make
- // a call to pis.receive AFTER the output stream was closed,
- // in which case an IOException should be thrown
- while (t.isAlive()) {
- ;
- }
- assertTrue(
- "write failed to throw IOException on closed PipedOutputStream",
- myRun.pass);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- try {
- if (t != null) {
- t.interrupt();
- }
- } catch (Exception ignore) {
- }
- super.tearDown();
- }
-
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(java.io.PipedOutputStream,
- * int)
- * @since 1.6
- */
- public void test_Constructor_LPipedOutputStream_I() throws Exception {
- // Test for method java.io.PipedInputStream(java.io.PipedOutputStream,
- // int)
- MockPipedInputStream mpis = new MockPipedInputStream(
- new PipedOutputStream(), 100);
- int bufferLength = mpis.bufferLength();
- assertEquals(100, bufferLength);
-
- try {
- pis = new PipedInputStream(null, -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- pis = new PipedInputStream(null, 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedInputStream#PipedInputStream(int)
- * @since 1.6
- */
- public void test_Constructor_I() throws Exception {
- // Test for method java.io.PipedInputStream(int)
- MockPipedInputStream mpis = new MockPipedInputStream(100);
- int bufferLength = mpis.bufferLength();
- assertEquals(100, bufferLength);
-
- try {
- pis = new PipedInputStream(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- pis = new PipedInputStream(0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- static class MockPipedInputStream extends PipedInputStream {
-
- public MockPipedInputStream(java.io.PipedOutputStream src,
- int bufferSize) throws IOException {
- super(src, bufferSize);
- }
-
- public MockPipedInputStream(int bufferSize) {
- super(bufferSize);
- }
-
- public int bufferLength() {
- return super.buffer.length;
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java b/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
deleted file mode 100644
index 6a6e28c..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedOutputStreamTest.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-
-@TestTargetClass(PipedOutputStream.class)
-public class PipedOutputStreamTest extends junit.framework.TestCase {
-
- static class PReader implements Runnable {
- PipedInputStream reader;
-
- public PipedInputStream getReader() {
- return reader;
- }
-
- public PReader(PipedOutputStream out) {
- try {
- reader = new PipedInputStream(out);
- } catch (Exception e) {
- System.out.println("Exception setting up reader: "
- + e.toString());
- }
- }
-
- public int available() {
- try {
- return reader.available();
- } catch (Exception e) {
- return -1;
- }
- }
-
- public void run() {
- try {
- while (true) {
- Thread.sleep(1000);
- Thread.yield();
- }
- } catch (InterruptedException e) {
- }
- }
-
- public String read(int nbytes) {
- byte[] buf = new byte[nbytes];
- try {
- reader.read(buf, 0, nbytes);
- return new String(buf);
- } catch (IOException e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
- return "ERROR";
- }
- }
- }
-
- static final String testString = "Lorem ipsum dolor sit amet,\n" +
- "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
- "labore et dolore magna aliqua.\n";
- static final int testLength = testString.length();
-
- Thread rt;
-
- PReader reader;
-
- PipedOutputStream out;
-
- /**
- * @tests java.io.PipedOutputStream#PipedOutputStream()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedOutputStream",
- args = {}
- )
- public void test_Constructor() {
- out = new PipedOutputStream();
- assertNotNull(out);
- try {
- out.close();
- } catch (IOException e) {
- fail("Unexpeceted IOException.");
- }
- }
-
- /**
- * @tests java.io.PipedOutputStream#PipedOutputStream(java.io.PipedInputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedOutputStream",
- args = {java.io.PipedInputStream.class}
- )
- public void test_ConstructorLjava_io_PipedInputStream() throws IOException {
- // Test for method java.io.PipedOutputStream(java.io.PipedInputStream)
-
- try {
- out = new PipedOutputStream(new PipedInputStream());
- out.write('b');
- } catch (Exception e) {
- fail("Test 1: Constructor failed: " + e.getMessage());
- }
- out.close();
-
- PipedInputStream pis = new PipedInputStream(new PipedOutputStream());
- try {
- out = new PipedOutputStream(pis);
- fail("Test 2: IOException expected because the input stream is already connected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedOutputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() {
- out = new PipedOutputStream();
- rt = new Thread(reader = new PReader(out));
- rt.start();
- try {
- out.close();
- } catch (IOException e) {
- fail("Test 1: Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PipedOutputStream#connect(java.io.PipedInputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "connect",
- args = {java.io.PipedInputStream.class}
- )
- public void test_connectLjava_io_PipedInputStream() throws IOException {
- out = new PipedOutputStream();
-
- try {
- out.connect(new PipedInputStream());
- } catch (Exception e) {
- fail("Test 1: Unexpected exception when connecting: " +
- e.getLocalizedMessage());
- }
-
- try {
- out.write('B');
- } catch (IOException e) {
- fail("Test 2: Unexpected IOException when writing after connecting.");
- }
-
- try {
- out.connect(new PipedInputStream());
- fail("Test 3: IOException expected when reconnecting the stream.");
- } catch (IOException e) {
- // Expected.
- }
-
- try {
- out.connect(null);
- fail("Test 4: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedOutputStream#flush()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking because it is never thrown in the source code.",
- method = "flush",
- args = {}
- )
- public void test_flush() throws Exception {
- out = new PipedOutputStream();
- rt = new Thread(reader = new PReader(out));
- rt.start();
- out.write(testString.getBytes(), 0, 10);
- assertTrue("Test 1: Bytes have been written before flush.", reader.available() != 0);
- out.flush();
- assertEquals("Test 2: Flush failed. ",
- testString.substring(0, 10), reader.read(10));
- }
-
- /**
- * @tests java.io.PipedOutputStream#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test 6 disabled due to incomplete implementation, see ticket #92.",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws IOException {
- out = new PipedOutputStream();
-
- try {
- out.write(testString.getBytes(), 0, 5);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- out = new PipedOutputStream(new PipedInputStream());
-
- try {
- out.write(testString.getBytes(), -1, 10);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- out.write(testString.getBytes(), 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- out.write(testString.getBytes(), 5, testString.length());
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- out.close();
- out = new PipedOutputStream();
- try {
- rt = new Thread(reader = new PReader(out));
- rt.start();
- out.write(testString.getBytes(), 0, testString.length());
- out.flush();
- assertEquals("Test 5: Bytes read do not match the bytes written. ",
- testString, reader.read(testString.length()));
- } catch (IOException e) {
- fail("Test 5: Unexpected IOException: " + e.getMessage());
- }
-
- reader.getReader().close();
- try {
- out.write(testString.getBytes(), 0, 5);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
-
- /**
- * @tests java.io.PipedOutputStream#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "Test 3 disabled due to incomplete implementation, see ticket #92.",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- out = new PipedOutputStream();
-
- try {
- out.write(42);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- rt = new Thread(reader = new PReader(out));
- rt.start();
- out.write('c');
- out.flush();
- assertEquals("Test 2: The byte read does not match the byte written. ",
- "c", reader.read(1));
-
-/* Test disabled due to incomplete implementation, see ticket #92.
- rt.interrupt();
-
- try {
- out.write(42);
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-*/
- reader.getReader().close();
- try {
- out.write(42);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- if (rt != null)
- rt.interrupt();
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedReaderTest.java b/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
deleted file mode 100644
index f237b9a..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedReaderTest.java
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedReader;
-import java.io.PipedWriter;
-
-import junit.framework.TestCase;
-
-public class PipedReaderTest extends TestCase {
-
- static class PWriter implements Runnable {
- public PipedWriter pw;
-
- public PWriter(PipedReader reader) {
- try {
- pw = new PipedWriter(reader);
- } catch (Exception e) {
- System.out.println("Couldn't create writer");
- }
- }
-
- public PWriter() {
- pw = new PipedWriter();
- }
-
- public void run() {
- try {
- char[] c = new char[11];
- "Hello World".getChars(0, 11, c, 0);
- pw.write(c);
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- } catch (Exception e) {
- System.out.println("Exception occurred: " + e.toString());
- }
- }
- }
-
- PipedReader preader;
-
- PWriter pwriter;
-
- Thread t;
-
- /**
- * @tests java.io.PipedReader#PipedReader()
- */
- public void test_Constructor() {
- // Used in test
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter)
- */
- public void test_ConstructorLjava_io_PipedWriter() throws IOException {
- preader = new PipedReader(new PipedWriter());
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(java.io.PipedWriter,
- * int)
- * @since 1.6
- */
- public void test_Constructor_LPipedWriter_I() throws Exception {
- // Test for method java.io.PipedReader(java.io.PipedWriter,
- // int)
- try {
- preader = new PipedReader(null, -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- preader = new PipedReader(null, 0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#PipedReader(int)
- * @since 1.6
- */
- public void test_Constructor_I() throws Exception {
- // Test for method java.io.PipedReader(int)
- try {
- preader = new PipedReader(-1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- try {
- preader = new PipedReader(0);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#close()
- */
- public void test_close() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- preader.read(c, 0, 11);
- preader.close();
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- }
-
- /**
- * @tests java.io.PipedReader#connect(java.io.PipedWriter)
- */
- public void test_connectLjava_io_PipedWriter() throws Exception {
- char[] c = null;
-
- preader = new PipedReader();
- t = new Thread(pwriter = new PWriter(), "");
- preader.connect(pwriter.pw);
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- preader.read(c, 0, 11);
-
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- try {
- preader.connect(pwriter.pw);
- fail("Failed to throw exception connecting to pre-connected reader");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read()
- */
- public void test_read() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- for (int i = 0; i < c.length; i++) {
- c[i] = (char) preader.read();
- }
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- c = new char[11];
- int n = 0;
- int x = n;
- while (x < 11) {
- n = preader.read(c, x, 11 - x);
- x = x + n;
- }
- assertEquals("Read incorrect chars", "Hello World", new String(c));
- try {
- preader.close();
- preader.read(c, 8, 7);
- fail("Failed to throw exception reading from closed reader");
- } catch (IOException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_2() throws IOException {
- // Regression for HARMONY-387
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) 0, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- assertEquals(
- "IndexOutOfBoundsException rather than a subclass expected",
- IndexOutOfBoundsException.class, t.getClass());
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_3() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) -1, (int) 0);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read$CII_4() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader obj = null;
- try {
- obj = new PipedReader(pw);
- obj.read(new char[0], (int) -1, (int) -1);
- fail("IndexOutOfBoundsException expected");
- } catch (ArrayIndexOutOfBoundsException t) {
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException t) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PipedReader#read(char[], int, int)
- */
- public void test_read_$CII_IOException() throws IOException {
- PipedWriter pw = new PipedWriter();
- PipedReader pr = new PipedReader(pw);
- char[] buf = null;
- pr.close();
- try {
- pr.read(buf, 0, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pr = new PipedReader();
- buf = null;
- pr.close();
- try {
- pr.read(buf, 0, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, -1, 0);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, 0, -1);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- buf = new char[10];
- pr.close();
- try {
- pr.read(buf, 1, 10);
- fail("Should throws IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- pr.close();
- try {
- pr.read(new char[0], -1, -1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- pr.close();
- try {
- pr.read(null, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, -1, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (NullPointerException expected) { // android-added
- } catch (IndexOutOfBoundsException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, 0, -1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(new char[10], 11, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
-
- pw = new PipedWriter();
- pr = new PipedReader(pw);
- try {
- pr.read(null, 1, 0);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- } finally {
- pw = null;
- pr = null;
- }
- }
-
- /**
- * @tests java.io.PipedReader#ready()
- */
- public void test_ready() throws Exception {
- char[] c = null;
- preader = new PipedReader();
- t = new Thread(new PWriter(preader), "");
- t.start();
- Thread.sleep(500); // Allow writer to start
- assertTrue("Reader should be ready", preader.ready());
- c = new char[11];
- for (int i = 0; i < c.length; i++)
- c[i] = (char) preader.read();
- assertFalse("Reader should not be ready after reading all chars",
- preader.ready());
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() throws Exception {
- if (t != null) {
- t.interrupt();
- }
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PipedWriterTest.java b/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
deleted file mode 100644
index bc18294..0000000
--- a/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.IOException;
-import java.io.PipedReader;
-import java.io.PipedWriter;
-import java.util.Arrays;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PipedWriter.class)
-public class PipedWriterTest extends junit.framework.TestCase {
-
- static final String testString = "Lorem ipsum...";
- static final int testLength = testString.length();
-
- static class PReader implements Runnable {
- public PipedReader pr;
-
- public char[] buf;
-
- public PReader(PipedWriter pw) {
- try {
- pr = new PipedReader(pw);
- } catch (IOException e) {
- System.out.println("Exception setting up reader: "
- + e.toString());
- }
- }
-
- public PReader(PipedReader pr) {
- this.pr = pr;
- }
-
-/* public void run() {
- try {
- int r = 0;
- for (int i = 0; i < buf.length; i++) {
- r = pr.read();
- if (r == -1)
- break;
- buf[i] = (char) r;
- }
- } catch (Exception e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
- }
- } */
-
- public void run() {
- try {
- while (true) {
- Thread.sleep(1000);
- Thread.yield();
- }
- } catch (InterruptedException e) {
- }
- }
-
- public String read(int nbytes) {
- buf = new char[nbytes];
- try {
- pr.read(buf, 0, nbytes);
- return new String(buf);
- } catch (IOException e) {
- System.out.println("Exception reading ("
- + Thread.currentThread().getName() + "): "
- + e.toString());
- return "ERROR";
- }
- }
- }
-
- Thread readerThread;
- PReader reader;
- PipedWriter pw;
- char[] testBuf;
-
- /**
- * @tests java.io.PipedWriter#PipedWriter()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedWriter",
- args = {}
- )
- public void test_Constructor() {
- pw = new PipedWriter();
- assertNotNull(pw);
- try {
- pw.close();
- } catch (IOException e) {
- fail("Unexpeceted IOException.");
- }
- }
-
- /**
- * @tests java.io.PipedWriter#PipedWriter(java.io.PipedReader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PipedWriter",
- args = {java.io.PipedReader.class}
- )
- public void test_ConstructorLjava_io_PipedReader() throws Exception {
- PipedReader rd = new PipedReader();
-
- try {
- pw = new PipedWriter(rd);
- } catch (Exception e) {
- fail("Test 1: Construtor failed:" + e.getMessage());
- }
-
- readerThread = new Thread(reader = new PReader(rd), "Constructor(Reader)");
- readerThread.start();
- try {
- pw.write(testBuf);
- } catch (Exception e) {
- fail("Test 2: Could not write to the constructed writer: "
- + e.getMessage());
- }
- pw.close();
- assertEquals("Test 3: Incorrect character string received.", testString,
- reader.read(testLength));
-
- rd = new PipedReader(new PipedWriter());
- try {
- pw = new PipedWriter(rd);
- fail("Test 4: IOException expected because the reader is already connected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws Exception {
- PipedReader rd = new PipedReader();
- pw = new PipedWriter(rd);
- reader = new PReader(rd);
- try {
- pw.close();
- } catch (IOException e) {
- fail("Test 1: Unexpected IOException: " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PipedWriter#connect(java.io.PipedReader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "connect",
- args = {java.io.PipedReader.class}
- )
- public void test_connectLjava_io_PipedReader() throws Exception {
- PipedReader rd = new PipedReader();
- pw = new PipedWriter();
-
- try {
- pw.connect(rd);
- } catch (Exception e) {
- fail("Test 1: Unexpected exception when connecting: " +
- e.getLocalizedMessage());
- }
-
- readerThread = new Thread(reader = new PReader(rd), "connect");
- readerThread.start();
-
- try {
- pw.write(testBuf);
- } catch (IOException e) {
- fail("Test 2: Unexpected IOException when writing after connecting.");
- }
- assertEquals("Test 3: Incorrect character string received.", testString,
- reader.read(testLength));
-
- try {
- pw.connect(new PipedReader());
- fail("Test 4: IOException expected when reconnecting the writer.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking because it is never thrown in the source code.",
- method = "flush",
- args = {}
- )
- public void test_flush() throws Exception {
- // Test for method void java.io.PipedWriter.flush()
- pw = new PipedWriter();
- readerThread = new Thread(reader = new PReader(pw), "flush");
- readerThread.start();
- pw.write(testBuf);
- pw.flush();
- assertEquals("Test 1: Flush failed. ", testString,
- reader.read(testLength));
- }
-
- /**
- * @tests java.io.PipedWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() throws Exception {
- pw = new PipedWriter();
-
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- pw = new PipedWriter(new PipedReader());
-
- try {
- pw.write(testBuf, -1, 1);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- pw.write(testBuf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- try {
- pw.write(testBuf, 5, testString.length());
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- pw.close();
- pw = new PipedWriter();
- try {
- readerThread = new Thread(reader = new PReader(pw), "writeCII");
- readerThread.start();
- pw.write(testBuf, 0, testLength);
- pw.close();
- reader.read(testLength);
- assertTrue("Test 5: Characters read do not match the characters written.",
- Arrays.equals( testBuf, reader.buf));
- } catch (IOException e) {
- fail("Test 5: Unexpected IOException: " + e.getMessage());
- }
-
- readerThread.interrupt();
-
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 6: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- reader.pr.close();
- try {
- pw.write(testBuf, 0, 5);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PipedWriter#write(char[],int,int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_MultiThread() throws Exception {
- final PipedReader pr = new PipedReader();
- final PipedWriter pw = new PipedWriter();
-
- // test if writer recognizes dead reader
- pr.connect(pw);
-
- class WriteRunnable implements Runnable {
- boolean pass = false;
-
- boolean readerAlive = true;
-
- public void run() {
- try {
- pw.write(1);
- while (readerAlive) {
- // wait the reader thread dead
- Thread.sleep(100);
- }
- try {
- // should throw exception since reader thread
- // is now dead
- char[] buf = new char[10];
- pw.write(buf, 0, 10);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- //ignore
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
- boolean pass;
-
- public void run() {
- try {
- pr.read();
- pass = true;
- } catch (IOException e) {
- //ignore
- }
- }
- }
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- //wait the reader thread dead
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- //wait the writer thread dead
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
- }
-
- /**
- * @tests java.io.PipedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws Exception {
- // Test for method void java.io.PipedWriter.write(int)
-
- pw = new PipedWriter();
-
- try {
- pw.write(42);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- readerThread = new Thread(reader = new PReader(pw), "writeI");
- readerThread.start();
- pw.write(1);
- pw.write(2);
- pw.write(3);
- pw.close();
- reader.read(3);
- assertTrue("Test 2: The charaacters read do not match the characters written: " +
- (int) reader.buf[0] + " " + (int) reader.buf[1] + " " + (int) reader.buf[2],
- reader.buf[0] == 1 && reader.buf[1] == 2 && reader.buf[2] == 3);
- }
-
- /**
- * @tests java.io.PipedWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI_MultiThread() throws IOException {
- final PipedReader pr = new PipedReader();
- final PipedWriter pw = new PipedWriter();
- // test if writer recognizes dead reader
- pr.connect(pw);
-
- class WriteRunnable implements Runnable {
- boolean pass = false;
- boolean readerAlive = true;
- public void run() {
- try {
- pw.write(1);
- while (readerAlive) {
- // wait the reader thread dead
- Thread.sleep(100);
- }
- try {
- // should throw exception since reader thread
- // is now dead
- pw.write(1);
- } catch (IOException e) {
- pass = true;
- }
- } catch (IOException e) {
- //ignore
- } catch (InterruptedException e) {
- //ignore
- }
- }
- }
- WriteRunnable writeRunnable = new WriteRunnable();
- Thread writeThread = new Thread(writeRunnable);
- class ReadRunnable implements Runnable {
- boolean pass;
- public void run() {
- try {
- pr.read();
- pass = true;
- } catch (IOException e) {
- //ignore
- }
- }
- }
- ReadRunnable readRunnable = new ReadRunnable();
- Thread readThread = new Thread(readRunnable);
- writeThread.start();
- readThread.start();
- while (readThread.isAlive()) {
- //wait the reader thread dead
- }
- writeRunnable.readerAlive = false;
- assertTrue("reader thread failed to read", readRunnable.pass);
- while (writeThread.isAlive()) {
- //wait the writer thread dead
- }
- assertTrue("writer thread failed to recognize dead reader",
- writeRunnable.pass);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- testBuf = new char[testLength];
- testString.getChars(0, testLength, testBuf, 0);
- }
-
- protected void tearDown() throws Exception {
- try {
- if (readerThread != null) {
- readerThread.interrupt();
- }
- } catch (Exception ignore) {}
- try {
- if (pw != null) {
- pw.close();
- }
- } catch (Exception ignore) {}
- super.tearDown();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java b/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
deleted file mode 100644
index 7cd0fcb..0000000
--- a/luni/src/test/java/tests/api/java/io/PrintStreamTest.java
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStreamReader;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Locale;
-
-public class PrintStreamTest extends junit.framework.TestCase {
-
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
- byte[] ibuf = new byte[4096];
-
- private File testFile = null;
-
- private String testFilePath = null;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- private static class MockPrintStream extends PrintStream {
-
- public MockPrintStream(String fileName) throws FileNotFoundException {
- super(fileName);
- }
-
- public MockPrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException {
- super(fileName, csn);
- }
-
- public MockPrintStream(OutputStream os) {
- super(os);
- }
-
- @Override
- public void clearError() {
- super.clearError();
- }
-
- @Override
- public void setError() {
- super.setError();
- }
- }
-
- /**
- * @tests {@link java.io.PrintStream#PrintStream(String)}
- */
- public void test_Constructor_Ljava_lang_String() throws IOException {
- MockPrintStream os = new MockPrintStream(testFilePath);
- assertNotNull(os);
- os.close();
- }
-
- /**
- * @tests {@link java.io.PrintStream#PrintStream(String, String)}
- */
- public void test_Constructor_Ljava_lang_String_Ljava_lang_String() throws Exception {
- MockPrintStream os = new MockPrintStream(testFilePath, "utf-8");
- assertNotNull(os);
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() throws Exception {
- // Test for method java.io.PrintStream(java.io.OutputStream)
- PrintStream os = new PrintStream(bos);
- os.print(2345.76834720202);
- os.close();
-
- // regression for HARMONY-1195
- try {
- os = new PrintStream(bos, true, null);
- fail("Should throw NPE");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean)
- */
- public void test_ConstructorLjava_io_OutputStreamZ() {
- // Test for method java.io.PrintStream(java.io.OutputStream, boolean)
- PrintStream os = new PrintStream(bos);
- os.println(2345.76834720202);
- os.flush();
- assertTrue("Bytes not written", bos.size() > 0);
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#PrintStream(java.io.OutputStream, boolean, String)
- */
- public void test_ConstructorLjava_io_OutputStreamZLjava_lang_String() {
- try {
- new PrintStream(new ByteArrayOutputStream(), false,
- "%Illegal_name!");
- fail("Expected UnsupportedEncodingException");
- } catch (UnsupportedEncodingException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PrintStream#checkError()
- */
- public void test_checkError() throws Exception {
- // Test for method boolean java.io.PrintStream.checkError()
- PrintStream os = new PrintStream(new OutputStream() {
-
- public void write(int b) throws IOException {
- throw new IOException();
- }
-
- public void write(byte[] b, int o, int l) throws IOException {
- throw new IOException();
- }
- });
- os.print(fileString.substring(0, 501));
-
- assertTrue("Checkerror should return true", os.checkError());
- }
-
- /**
- * @tests {@link java.io.PrintStream#clearError()}
- */
- public void test_clearError() throws FileNotFoundException {
- MockPrintStream os = new MockPrintStream(testFilePath);
- assertFalse(os.checkError());
- os.setError();
- assertTrue(os.checkError());
- os.clearError();
- assertFalse(os.checkError());
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#close()
- */
- public void test_close() throws Exception {
- // Test for method void java.io.PrintStream.close()
- PrintStream os = new PrintStream(bos);
- os.close();
- bos.close();
- }
-
- /**
- * @tests java.io.PrintStream#flush()
- */
- public void test_flush() throws Exception {
- // Test for method void java.io.PrintStream.flush()
- PrintStream os = new PrintStream(bos);
- os.print(fileString.substring(0, 501));
- os.flush();
- assertEquals("Bytes not written after flush", 501, bos.size());
- bos.close();
- os.close();
- }
-
- /**
- * @tests java.io.PrintStream#print(char[])
- */
- public void test_print$C() {
- // Test for method void java.io.PrintStream.print(char [])
- PrintStream os = new PrintStream(bos, true);
- try {
- os.print((char[]) null);
- fail("NPE expected");
- } catch (NullPointerException ok) {}
-
- os = new PrintStream(bos, true);
- char[] sc = new char[4000];
- fileString.getChars(0, fileString.length(), sc, 0);
- os.print(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- os.close();
-
- byte[] rbytes = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertEquals("Incorrect char[] written", fileString, new String(rbytes,
- 0, fileString.length()));
- }
-
- /**
- * @tests java.io.PrintStream#print(char)
- */
- public void test_printC() throws Exception {
- // Test for method void java.io.PrintStream.print(char)
- PrintStream os = new PrintStream(bos, true);
- os.print('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertEquals("Incorrect char written", 't', isr.read());
- }
-
- /**
- * @tests java.io.PrintStream#print(double)
- */
- public void test_printD() {
- // Test for method void java.io.PrintStream.print(double)
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.print(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 16);
- assertEquals("Incorrect double written", "2345.76834720202",
- new String(rbuf, 0, 16));
- }
-
- /**
- * @tests java.io.PrintStream#print(float)
- */
- public void test_printF() {
- // Test for method void java.io.PrintStream.print(float)
- PrintStream os = new PrintStream(bos, true);
- byte rbuf[] = new byte[10];
- os.print(29.08764f);
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 8);
- assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
- 8));
-
- }
-
- /**
- * @tests java.io.PrintStream#print(int)
- */
- public void test_printI() {
- // Test for method void java.io.PrintStream.print(int)
- PrintStream os = new PrintStream(bos, true);
- os.print(768347202);
- byte[] rbuf = new byte[18];
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 9);
- assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
- 9));
- }
-
- /**
- * @tests java.io.PrintStream#print(long)
- */
- public void test_printJ() {
- // Test for method void java.io.PrintStream.print(long)
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.print(9875645283333L);
- os.close();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- bis.read(rbuf, 0, 13);
- assertEquals("Incorrect long written", "9875645283333", new String(
- rbuf, 0, 13));
- }
-
- /**
- * @tests java.io.PrintStream#print(java.lang.Object)
- */
- public void test_printLjava_lang_Object() throws Exception {
- // Test for method void java.io.PrintStream.print(java.lang.Object)
- PrintStream os = new PrintStream(bos, true);
- os.print((Object) null);
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] nullbytes = new byte[4];
- bis.read(nullbytes, 0, 4);
- assertEquals("null should be written", "null", new String(nullbytes, 0,
- 4));
-
- bis.close();
- bos.close();
- os.close();
-
- ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
- os = new PrintStream(bos1, true);
- os.print(new java.util.Vector());
- bis = new ByteArrayInputStream(bos1.toByteArray());
- byte[] rbytes = new byte[2];
- bis.read(rbytes, 0, 2);
- assertEquals("Incorrect Object written", "[]", new String(rbytes, 0, 2));
- }
-
- /**
- * @tests java.io.PrintStream#print(java.lang.String)
- */
- public void test_printLjava_lang_String() throws Exception {
- // Test for method void java.io.PrintStream.print(java.lang.String)
- PrintStream os = new PrintStream(bos, true);
- os.print((String) null);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] nullbytes = new byte[4];
- bis.read(nullbytes, 0, 4);
- assertEquals("null should be written", "null", new String(nullbytes, 0,
- 4));
-
- bis.close();
- bos.close();
- os.close();
-
- ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
- os = new PrintStream(bos1, true);
- os.print("Hello World");
- bis = new ByteArrayInputStream(bos1.toByteArray());
- byte rbytes[] = new byte[100];
- bis.read(rbytes, 0, 11);
- assertEquals("Incorrect string written", "Hello World", new String(
- rbytes, 0, 11));
- }
-
- /**
- * @tests java.io.PrintStream#print(boolean)
- */
- public void test_printZ() throws Exception {
- // Test for method void java.io.PrintStream.print(boolean)
- PrintStream os = new PrintStream(bos, true);
- os.print(true);
- DataInputStream dis = new DataInputStream(new ByteArrayInputStream(bos
- .toByteArray()));
-
- assertTrue("Incorrect boolean written", dis.readBoolean());
- }
-
- /**
- * @tests java.io.PrintStream#println()
- */
- public void test_println() throws Exception {
- // Test for method void java.io.PrintStream.println()
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println("");
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(char[])
- */
- public void test_println$C() throws Exception {
- // Test for method void java.io.PrintStream.println(char [])
- PrintStream os = new PrintStream(bos, true);
- char[] sc = new char[4000];
- fileString.getChars(0, fileString.length(), sc, 0);
- os.println(sc);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbytes = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertEquals("Incorrect char[] written", fileString, new String(rbytes,
- 0, fileString.length()));
-
- // In this particular test method, the end of data is not immediately
- // followed by newLine separator in the reading buffer, instead its
- // followed by zeros. The newline is written as the last entry
- // in the inputStream buffer. Therefore, we must keep reading until we
- // hit a new line.
- int r;
- boolean newline = false;
- while ((r = isr.read()) != -1) {
- if (r == '\r' || r == '\n')
- newline = true;
- }
- assertTrue("Newline not written", newline);
- }
-
- /**
- * @tests java.io.PrintStream#println(char)
- */
- public void test_printlnC() throws Exception {
- // Test for method void java.io.PrintStream.println(char)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- assertEquals("Incorrect char written", 't', isr.read());
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(double)
- */
- public void test_printlnD() throws Exception {
- // Test for method void java.io.PrintStream.println(double)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(2345.76834720202);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 16);
- assertEquals("Incorrect double written", "2345.76834720202",
- new String(rbuf, 0, 16));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(float)
- */
- public void test_printlnF() throws Exception {
- // Test for method void java.io.PrintStream.println(float)
- int c;
- byte[] rbuf = new byte[100];
- PrintStream os = new PrintStream(bos, true);
- os.println(29.08764f);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- bis.read(rbuf, 0, 8);
- assertEquals("Incorrect float written", "29.08764", new String(rbuf, 0,
- 8));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(int)
- */
- public void test_printlnI() throws Exception {
- // Test for method void java.io.PrintStream.println(int)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(768347202);
- byte[] rbuf = new byte[100];
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- bis.read(rbuf, 0, 9);
- assertEquals("Incorrect int written", "768347202", new String(rbuf, 0,
- 9));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(long)
- */
- public void test_printlnJ() throws Exception {
- // Test for method void java.io.PrintStream.println(long)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(9875645283333L);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 13);
- assertEquals("Incorrect long written", "9875645283333", new String(
- rbuf, 0, 13));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(java.lang.Object)
- */
- public void test_printlnLjava_lang_Object() throws Exception {
- // Test for method void java.io.PrintStream.println(java.lang.Object)
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println(new java.util.Vector());
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbytes = new byte[2];
- bis.read(rbytes, 0, 2);
- assertEquals("Incorrect Vector written", "[]", new String(rbytes, 0, 2));
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(java.lang.String)
- */
- public void test_printlnLjava_lang_String() throws Exception {
- // Test for method void java.io.PrintStream.println(java.lang.String)
- char c;
- PrintStream os = new PrintStream(bos, true);
- os.println("Hello World");
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte rbytes[] = new byte[100];
- bis.read(rbytes, 0, 11);
- assertEquals("Incorrect string written", "Hello World", new String(
- rbytes, 0, 11));
- assertTrue("Newline not written", (c = (char) isr.read()) == '\r'
- || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#println(boolean)
- */
- public void test_printlnZ() throws Exception {
- // Test for method void java.io.PrintStream.println(boolean)
- int c;
- PrintStream os = new PrintStream(bos, true);
- os.println(true);
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- InputStreamReader isr = new InputStreamReader(bis);
- byte[] rbuf = new byte[100];
- bis.read(rbuf, 0, 4);
- assertEquals("Incorrect boolean written", "true",
- new String(rbuf, 0, 4));
- assertTrue("Newline not written", (c = isr.read()) == '\r' || c == '\n');
- }
-
- /**
- * @tests java.io.PrintStream#write(byte[], int, int)
- */
- public void test_write$BII() {
- // Test for method void java.io.PrintStream.write(byte [], int, int)
- PrintStream os = new PrintStream(bos, true);
- os.write(fileString.getBytes(), 0, fileString.length());
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte rbytes[] = new byte[4000];
- bis.read(rbytes, 0, fileString.length());
- assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString
- .length()).equals(fileString));
- }
-
- /**
- * @tests java.io.PrintStream#write(int)
- */
- public void test_writeI() {
- // Test for method void java.io.PrintStream.write(int)
- PrintStream os = new PrintStream(bos, true);
- os.write('t');
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- assertEquals("Incorrect char written", 't', bis.read());
- }
-
- /**
- * @tests java.io.PrintStream#append(char)
- */
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testChar);
- printStream.flush();
- assertEquals(String.valueOf(testChar), out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#append(CharSequence)
- */
- public void test_appendCharSequence() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testString);
- printStream.flush();
- assertEquals(testString, out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#append(CharSequence, int, int)
- */
- public void test_appendCharSequenceIntInt() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(out);
- printStream.append(testString, 1, 3);
- printStream.flush();
- assertEquals(testString.substring(1, 3), out.toString());
- printStream.close();
- }
-
- /**
- * @tests java.io.PrintStream#format(java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_lang_String$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.format("%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
-
- }
-
- /**
- * @tests java.io.PrintStream#format(java.util.Locale, java.lang.String,
- * java.lang.Object...)
- */
- public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.format(Locale.US, "%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- /**
- * @tests java.io.PrintStream#printf(java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_lang_String$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.printf("%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- /**
- * @tests java.io.PrintStream#printf(java.util.Locale, java.lang.String,
- * java.lang.Object...)
- */
- public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- PrintStream os = new PrintStream(bos, false);
- os.printf(Locale.US, "%s %s", "Hello", "World");
- os.flush();
- ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
- byte[] rbytes = new byte[11];
- bis.read(rbytes, 0, rbytes.length);
- assertEquals("Wrote incorrect string", "Hello World",
- new String(rbytes));
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- testFile = File.createTempFile("test", null);
- testFilePath = testFile.getAbsolutePath();
- }
-
- @Override
- protected void tearDown() throws Exception {
- testFile.delete();
- testFile = null;
- testFilePath = null;
- super.tearDown();
- }
-
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java b/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
deleted file mode 100644
index dfaa4a5..0000000
--- a/luni/src/test/java/tests/api/java/io/PrintWriterTest.java
+++ /dev/null
@@ -1,778 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.nio.charset.Charset;
-import java.util.Locale;
-
-import tests.support.Support_StringReader;
-import tests.support.Support_StringWriter;
-
-public class PrintWriterTest extends junit.framework.TestCase {
-
- static class Bogus {
- public String toString() {
- return "Bogus";
- }
- }
-
- /**
- * @since 1.6
- */
- static class MockPrintWriter extends PrintWriter {
-
- public MockPrintWriter(OutputStream out, boolean autoflush) {
- super(out, autoflush);
- }
-
- @Override
- public void clearError() {
- super.clearError();
- }
-
- }
-
- PrintWriter pw;
-
- ByteArrayOutputStream bao;
-
- ByteArrayInputStream bai;
-
- BufferedReader br;
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream)
- */
- public void test_ConstructorLjava_io_OutputStream() {
- // Test for method java.io.PrintWriter(java.io.OutputStream)
- String s;
- pw.println("Random Chars");
- pw.write("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Hello World"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
- */
- public void test_ConstructorLjava_io_OutputStreamZ() {
- // Test for method java.io.PrintWriter(java.io.OutputStream, boolean)
- String s;
- pw = new PrintWriter(bao, true);
- pw.println("Random Chars");
- pw.write("Hello World");
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- pw.flush();
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Random Chars"));
- s = br.readLine();
- assertTrue("Incorrect string written/read: " + s, s
- .equals("Hello World"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.Writer)
- */
- public void test_ConstructorLjava_io_Writer() {
- // Test for method java.io.PrintWriter(java.io.Writer)
- Support_StringWriter sw;
- pw = new PrintWriter(sw = new Support_StringWriter());
- pw.print("Hello");
- pw.flush();
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.Writer, boolean)
- */
- public void test_ConstructorLjava_io_WriterZ() {
- // Test for method java.io.PrintWriter(java.io.Writer, boolean)
- Support_StringWriter sw;
- pw = new PrintWriter(sw = new Support_StringWriter(), true);
- pw.print("Hello");
- // Auto-flush should have happened
- assertEquals("Failed to construct proper writer",
- "Hello", sw.toString());
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.File)
- */
- public void test_ConstructorLjava_io_File() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file);
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.io.File, java.lang.String)
- */
- public void test_ConstructorLjava_io_File_Ljava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file,
- Charset.defaultCharset().name());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file.getPath());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#PrintWriter(java.lang.String, java.lang.String)
- */
- public void test_ConstructorLjava_lang_String_Ljava_lang_String() throws Exception {
- File file = File.createTempFile(getClass().getName(), null);
- try {
- PrintWriter writer = new PrintWriter(file.getPath(),
- Charset.defaultCharset().name());
- writer.close();
- } finally {
- file.delete();
- }
- }
-
- /**
- * @tests java.io.PrintWriter#checkError()
- */
- public void test_checkError() {
- // Test for method boolean java.io.PrintWriter.checkError()
- pw.close();
- pw.print(490000000000.08765);
- assertTrue("Failed to return error", pw.checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#clearError()
- * @since 1.6
- */
- public void test_clearError() {
- // Test for method boolean java.io.PrintWriter.clearError()
- MockPrintWriter mpw = new MockPrintWriter(new ByteArrayOutputStream(), false);
- mpw.close();
- mpw.print(490000000000.08765);
- assertTrue("Failed to return error", mpw.checkError());
- mpw.clearError();
- assertFalse("Internal error state has not be cleared", mpw.checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#close()
- */
- public void test_close() {
- // Test for method void java.io.PrintWriter.close()
- pw.close();
- pw.println("l");
- assertTrue("Write on closed stream failed to generate error", pw
- .checkError());
- }
-
- /**
- * @tests java.io.PrintWriter#flush()
- */
- public void test_flush() {
- // Test for method void java.io.PrintWriter.flush()
- final double dub = 490000000000.08765;
- pw.print(dub);
- pw.flush();
- assertTrue("Failed to flush", new String(bao.toByteArray())
- .equals(String.valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(char[])
- */
- public void test_print$C() {
- // Test for method void java.io.PrintWriter.print(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.print(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- int r = 0;
- try {
- pw.print((char[]) null);
- } catch (NullPointerException e) {
- r = 1;
- }
- assertEquals("null pointer exception for printing null char[] is not caught",
- 1, r);
- }
-
- /**
- * @tests java.io.PrintWriter#print(char)
- */
- public void test_printC() {
- // Test for method void java.io.PrintWriter.print(char)
- pw.print('c');
- pw.flush();
- assertEquals("Wrote incorrect char string", "c", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(double)
- */
- public void test_printD() {
- // Test for method void java.io.PrintWriter.print(double)
- final double dub = 490000000000.08765;
- pw.print(dub);
- pw.flush();
- assertTrue("Wrote incorrect double string", new String(bao
- .toByteArray()).equals(String.valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(float)
- */
- public void test_printF() {
- // Test for method void java.io.PrintWriter.print(float)
- final float flo = 49.08765f;
- pw.print(flo);
- pw.flush();
- assertTrue("Wrote incorrect float string",
- new String(bao.toByteArray()).equals(String.valueOf(flo)));
- }
-
- /**
- * @tests java.io.PrintWriter#print(int)
- */
- public void test_printI() {
- // Test for method void java.io.PrintWriter.print(int)
- pw.print(4908765);
- pw.flush();
- assertEquals("Wrote incorrect int string", "4908765", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(long)
- */
- public void test_printJ() {
- // Test for method void java.io.PrintWriter.print(long)
- pw.print(49087650000L);
- pw.flush();
- assertEquals("Wrote incorrect long string", "49087650000", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(java.lang.Object)
- */
- public void test_printLjava_lang_Object() {
- // Test for method void java.io.PrintWriter.print(java.lang.Object)
- pw.print((Object) null);
- pw.flush();
- assertEquals("Did not write null", "null", new String(bao.toByteArray())
- );
- bao.reset();
-
- pw.print(new Bogus());
- pw.flush();
- assertEquals("Wrote in incorrect Object string", "Bogus", new String(bao
- .toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#print(java.lang.String)
- */
- public void test_printLjava_lang_String() {
- // Test for method void java.io.PrintWriter.print(java.lang.String)
- pw.print((String) null);
- pw.flush();
- assertEquals("did not write null", "null", new String(bao.toByteArray())
- );
- bao.reset();
-
- pw.print("Hello World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World", new String(bao.toByteArray())
- );
- }
-
- /**
- * @tests java.io.PrintWriter#print(boolean)
- */
- public void test_printZ() {
- // Test for method void java.io.PrintWriter.print(boolean)
- pw.print(true);
- pw.flush();
- assertEquals("Wrote in incorrect boolean string", "true", new String(bao
- .toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#println()
- */
- public void test_println() {
- // Test for method void java.io.PrintWriter.println()
- String s;
- pw.println("Blarg");
- pw.println();
- pw.println("Bleep");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals("Blarg"));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals(""));
- s = br.readLine();
- assertTrue("Wrote incorrect line: " + s, s.equals("Bleep"));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PrintWriter#println(char[])
- */
- public void test_println$C() {
- // Test for method void java.io.PrintWriter.println(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.println(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(char)
- */
- public void test_printlnC() {
- // Test for method void java.io.PrintWriter.println(char)
- String s = null;
- pw.println("Random Chars");
- pw.println('c');
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- s = br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char string: " + s, s.equals("c"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(double)
- */
- public void test_printlnD() {
- // Test for method void java.io.PrintWriter.println(double)
- String s = null;
- final double dub = 4000000000000000.657483;
- pw.println("Random Chars");
- pw.println(dub);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect double string: " + s, s.equals(String
- .valueOf(dub)));
- }
-
- /**
- * @tests java.io.PrintWriter#println(float)
- */
- public void test_printlnF() {
- // Test for method void java.io.PrintWriter.println(float)
- String s;
- final float flo = 40.4646464f;
- pw.println("Random Chars");
- pw.println(flo);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- assertTrue("Wrote incorrect float string: " + s + " wanted: "
- + String.valueOf(flo), s.equals(String.valueOf(flo)));
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
-
- }
-
- /**
- * @tests java.io.PrintWriter#println(int)
- */
- public void test_printlnI() {
- // Test for method void java.io.PrintWriter.println(int)
- String s = null;
- pw.println("Random Chars");
- pw.println(400000);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect int string: " + s, s.equals("400000"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(long)
- */
- public void test_printlnJ() {
- // Test for method void java.io.PrintWriter.println(long)
- String s = null;
- pw.println("Random Chars");
- pw.println(4000000000000L);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect long string: " + s, s
- .equals("4000000000000"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(java.lang.Object)
- */
- public void test_printlnLjava_lang_Object() {
- // Test for method void java.io.PrintWriter.println(java.lang.Object)
- String s = null;
- pw.println("Random Chars");
- pw.println(new Bogus());
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect Object string: " + s, s.equals("Bogus"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(java.lang.String)
- */
- public void test_printlnLjava_lang_String() {
- // Test for method void java.io.PrintWriter.println(java.lang.String)
- String s = null;
- pw.println("Random Chars");
- pw.println("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect string: " + s, s.equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#println(boolean)
- */
- public void test_printlnZ() {
- // Test for method void java.io.PrintWriter.println(boolean)
- String s = null;
- pw.println("Random Chars");
- pw.println(false);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect boolean string: " + s, s.equals("false"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(char[])
- */
- public void test_write$C() {
- // Test for method void java.io.PrintWriter.write(char [])
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.write(schars);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test: " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(char[], int, int)
- */
- public void test_write$CII() {
- // Test for method void java.io.PrintWriter.write(char [], int, int)
- String s = null;
- char[] schars = new char[11];
- "Hello World".getChars(0, 11, schars, 0);
- pw.println("Random Chars");
- pw.write(schars, 6, 5);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(int)
- */
- public void test_writeI() throws IOException {
- // Test for method void java.io.PrintWriter.write(int)
- char[] cab = new char[3];
- pw.write('a');
- pw.write('b');
- pw.write('c');
- pw.flush();
- InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(bao.toByteArray()));
- cab[0] = (char) isr.read();
- cab[1] = (char) isr.read();
- cab[2] = (char) isr.read();
- assertTrue("Wrote incorrect ints", cab[0] == 'a' && cab[1] == 'b'
- && cab[2] == 'c');
-
- }
-
- /**
- * @tests java.io.PrintWriter#write(java.lang.String)
- */
- public void test_writeLjava_lang_String() {
- // Test for method void java.io.PrintWriter.write(java.lang.String)
- String s = null;
- pw.println("Random Chars");
- pw.write("Hello World");
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s
- .equals("Hello World"));
- }
-
- /**
- * @tests java.io.PrintWriter#write(java.lang.String, int, int)
- */
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.PrintWriter.write(java.lang.String, int,
- // int)
- String s = null;
- pw.println("Random Chars");
- pw.write("Hello World", 6, 5);
- pw.flush();
- try {
- br = new BufferedReader(new Support_StringReader(bao.toString()));
- br.readLine();
- s = br.readLine();
- } catch (IOException e) {
- fail("IOException during test : " + e.getMessage());
- }
- assertTrue("Wrote incorrect char[] string: " + s, s.equals("World"));
- }
-
- /**
- * @tests java.io.PrintWriter#append(char)
- */
- public void test_appendChar() {
- char testChar = ' ';
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testChar);
- printWriter.flush();
- assertEquals(String.valueOf(testChar),out.toString());
- printWriter.close();
- }
- /**
- * @tests java.io.PrintWriter#append(CharSequence)
- */
- public void test_appendCharSequence() {
-
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString);
- printWriter.flush();
- assertEquals(testString, out.toString());
- printWriter.close();
-
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence, int, int)
- */
- public void test_appendCharSequenceIntInt() {
- String testString = "My Test String";
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- PrintWriter printWriter = new PrintWriter(out);
- printWriter.append(testString, 1, 3);
- printWriter.flush();
- assertEquals(testString.substring(1, 3), out.toString());
- printWriter.close();
-
- }
-
- /**
- * @tests java.io.PrintWriter#format(java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_lang_String$Ljava_lang_Object() {
- pw.format("%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#format(java.util.Locale, java.lang.String, java.lang.Object...)
- */
- public void test_formatLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- pw.format(Locale.US, "%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#printf(java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_lang_String$Ljava_lang_Object() {
- pw.printf("%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * @tests java.io.PrintWriter#printf(java.util.Locale, java.lang.String, java.lang.Object...)
- */
- public void test_printfLjava_util_Locale_Ljava_lang_String_$Ljava_lang_Object() {
- pw.printf(Locale.US, "%s %s", "Hello", "World");
- pw.flush();
- assertEquals("Wrote incorrect string", "Hello World",
- new String(bao.toByteArray()));
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- bao = new ByteArrayOutputStream();
- pw = new PrintWriter(bao, false);
-
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- pw.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java b/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java
deleted file mode 100644
index a648840..0000000
--- a/luni/src/test/java/tests/api/java/io/PushbackInputStreamTest.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.PushbackInputStream;
-
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PushbackInputStream.class)
-public class PushbackInputStreamTest extends junit.framework.TestCase {
-
- Support_ASimpleInputStream underlying = new Support_ASimpleInputStream();
- PushbackInputStream pis;
-
- public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_java_io_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n";
-
- /**
- * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "PushbackInputStream",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- // Test for method java.io.PushbackInputStream(java.io.InputStream)
- try {
- pis = new PushbackInputStream(new ByteArrayInputStream("Hello"
- .getBytes()));
- pis.unread("He".getBytes());
- } catch (IOException e) {
- // Correct
- // Pushback buffer should be full
- return;
-
- }
- fail("Failed to throw exception on unread when buffer full");
- }
-
- /**
- * @tests java.io.PushbackInputStream#PushbackInputStream(java.io.InputStream,
- * int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackInputStream",
- args = {java.io.InputStream.class, int.class}
- )
- public void test_ConstructorLjava_io_InputStreamI() {
- ByteArrayInputStream bas = new ByteArrayInputStream("Hello".getBytes());
- try {
- pis = new PushbackInputStream(bas, 0);
- fail("Test 1: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- try {
- pis = new PushbackInputStream(bas, -1);
- fail("Test 2: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- pis = new PushbackInputStream(bas , 5);
- try {
- pis.unread("Hello world".getBytes());
- fail("Test 3: IOException expected when the unread buffer is full.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- PushbackInputStream tobj;
-
- tobj = new PushbackInputStream(underlying);
- tobj.close();
- tobj.close();
- tobj = new PushbackInputStream(underlying);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.close();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- PushbackInputStream tobj;
-
- tobj = new PushbackInputStream(underlying);
- assertEquals("Wrong number!", 30, tobj.available());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.available();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.PushbackInputStream.markSupported()
- assertTrue("markSupported returned true", !pis.markSupported());
- }
-
- /**
- * @tests java.io.PushbackInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- PushbackInputStream tobj;
-
- tobj = new PushbackInputStream(underlying);
- assertEquals("Test 1: Incorrect byte read;", 66, tobj.read());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // expected
- }
-
- assertEquals("Test 3: Incorrect byte read;",
- fileString.getBytes()[0], pis.read());
- }
-
- /**
- * @tests java.io.PushbackInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- PushbackInputStream tobj;
- byte[] buf = ("01234567890123456789").getBytes();
-
- tobj = new PushbackInputStream(underlying);
- tobj.read(buf, 6, 5);
- assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
- assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf, 6, 5);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() throws IOException {
- PushbackInputStream tobj;
- byte[] buf = new byte[10];
-
- tobj = new PushbackInputStream(underlying);
- try {
- tobj.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- tobj.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- tobj.read(buf, 10, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() throws IOException {
- PushbackInputStream tobj;
- byte[] buf = ("01234567890123456789").getBytes();
-
- tobj = new PushbackInputStream(underlying);
- tobj.skip(6);
- assertEquals("Wrong number!", 30 - 6, tobj.available());
- tobj.skip(1000000);
- tobj.skip(1000000);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.skip(1);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method long java.io.PushbackInputStream.skip(long)
- try {
- buf = new byte[50];
- pis.skip(50);
- pis.read(buf, 0, buf.length);
- assertTrue("a) Incorrect bytes read", new String(buf)
- .equals(fileString.substring(50, 100)));
- pis.unread(buf);
- pis.skip(25);
- byte[] buf2 = new byte[25];
- pis.read(buf2, 0, buf2.length);
- assertTrue("b) Incorrect bytes read", new String(buf2)
- .equals(fileString.substring(75, 100)));
- } catch (Exception e) {
- fail("Exception during test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#unread(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {byte[].class}
- )
- public void test_unread$B() throws IOException {
- PushbackInputStream tobj;
- String str2 = "0123456789";
- byte[] buf2 = str2.getBytes();
- byte[] readBuf = new byte[10];
-
- tobj = new PushbackInputStream(underlying, 10);
- tobj.unread(buf2);
- assertEquals("Wrong number!", 30 + 10, tobj.available());
- try {
- tobj.unread(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", str2, new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackInputStream.unread(byte [])
- try {
- byte[] buf = new byte[100];
- pis.read(buf, 0, buf.length);
- assertTrue("Incorrect bytes read", new String(buf)
- .equals(fileString.substring(0, 100)));
- pis.unread(buf);
- pis.read(buf, 0, 50);
- assertTrue("Failed to unread bytes", new String(buf, 0, 50)
- .equals(fileString.substring(0, 50)));
- } catch (IOException e) {
- fail("IOException during unread test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#unread(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {byte[].class, int.class, int.class}
- )
- public void test_unread$BII() throws IOException {
- PushbackInputStream tobj;
- String str2 = "0123456789";
- byte[] buf2 = (str2 + str2 + str2).getBytes();
- byte[] readBuf = new byte[10];
-
- tobj = new PushbackInputStream(underlying, 10);
- tobj.unread(buf2, 15, 10);
- assertEquals("Wrong number!", 30 + 10, tobj.available());
- try {
- tobj.unread(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackInputStream.unread(byte [], int,
- // int)
- try {
- byte[] buf = new byte[100];
- pis.read(buf, 0, buf.length);
- assertTrue("Incorrect bytes read", new String(buf)
- .equals(fileString.substring(0, 100)));
- pis.unread(buf, 50, 50);
- pis.read(buf, 0, 50);
- assertTrue("Failed to unread bytes", new String(buf, 0, 50)
- .equals(fileString.substring(50, 100)));
- } catch (IOException e) {
- fail("IOException during unread test : " + e.getMessage());
- }
-
- try {
- byte[] buf = new byte[10];
- pis.unread(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- byte[] buf = new byte[10];
- pis.unread(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- byte[] buf = new byte[10];
- pis.unread(buf, 10, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.PushbackInputStream#unread(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {int.class}
- )
- public void test_unreadI() throws IOException {
- PushbackInputStream tobj;
-
- tobj = new PushbackInputStream(underlying);
- tobj.unread(23); // Why does this work?!?
- tobj.skip(2);
- tobj.unread(23);
- assertEquals("Wrong number!", 30, tobj.available());
- assertEquals("Wrong value read!", 23, tobj.read());
- tobj.unread(13);
- try {
- tobj.unread(13);
- fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackInputStream.unread(int)
- try {
- int x;
- assertTrue("Incorrect byte read", (x = pis.read()) == fileString
- .getBytes()[0]);
- pis.unread(x);
- assertTrue("Failed to unread", pis.read() == x);
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- pis = new PushbackInputStream(new ByteArrayInputStream(fileString
- .getBytes()), 65535);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- pis.close();
- } catch (IOException e) {
- fail("IOException during tearDown : " + e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java b/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java
deleted file mode 100644
index e4c0c7f..0000000
--- a/luni/src/test/java/tests/api/java/io/PushbackReaderTest.java
+++ /dev/null
@@ -1,673 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.CharArrayReader;
-import java.io.FilterReader;
-import java.io.IOException;
-import java.io.PushbackReader;
-import java.io.Reader;
-import java.io.StringReader;
-
-import tests.support.Support_ASimpleReader;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(PushbackReader.class)
-public class PushbackReaderTest extends junit.framework.TestCase {
-
- Support_ASimpleReader underlying = new Support_ASimpleReader();
- PushbackReader pbr;
-
- String pbString = "Hello World";
-
- /**
- * @tests java.io.PushbackReader#PushbackReader(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackReader",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() {
- // Test for method java.io.PushbackReader(java.io.Reader)
- try {
- pbr.close();
- pbr = new PushbackReader(new StringReader(pbString));
- char buf[] = new char[5];
- pbr.read(buf, 0, 5);
- pbr.unread(buf);
- fail("Created reader with buffer larger than 1");;
- } catch (IOException e) {
- // Expected
- }
-
- try {
- pbr = new PushbackReader(null);
- } catch (NullPointerException e) {
- // EXpected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#PushbackReader(java.io.Reader, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "PushbackReader",
- args = {java.io.Reader.class, int.class}
- )
- public void test_ConstructorLjava_io_ReaderI() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying, 10000);
- tobj = new PushbackReader(underlying, 1);
-
- try {
- tobj = new PushbackReader(underlying, -1);
- tobj.close();
- fail("IOException not thrown.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- tobj = new PushbackReader(underlying, 0);
- tobj.close();
- fail("IOException not thrown.");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.close();
- tobj.close();
- tobj = new PushbackReader(underlying);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.close();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.close()
- try {
- pbr.close();
- pbr.read();
- } catch (Exception e) {
- return;
- }
- fail("Failed to throw exception reading from closed reader");
-
- }
-
- /**
- * @tests java.io.PushbackReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "mark",
- args = {int.class}
- )
- public void test_markI() {
- try {
- pbr.mark(3);
- fail("Test 1: IOException expected because marking is not supported.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.PushbackReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- assertFalse("Test 1: markSupported() must return false.",
- pbr.markSupported());
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- assertEquals("Wrong value read!", 66, tobj.read());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method int java.io.PushbackReader.read()
- try {
- char c;
- pbr.read();
- c = (char) pbr.read();
- assertTrue("Failed to read char: " + c, c == pbString.charAt(1));
- Reader reader = new PushbackReader(new CharArrayReader(
- new char[] { '\u8765' }));
- assertTrue("Wrong double byte character", reader.read() == '\u8765');
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws IOException {
- PushbackReader tobj;
- char[] buf = ("01234567890123456789").toCharArray();
-
- tobj = new PushbackReader(underlying);
- tobj.read(buf, 6, 5);
- assertEquals("Wrong value read!", "BEGIN", new String(buf, 6, 5));
- assertEquals("Too much read!", "012345BEGIN123456789", new String(buf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf, 6, 5);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method int java.io.PushbackReader.read(char [], int, int)
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- assertTrue("Failed to read chars", new String(c).equals(pbString
- .substring(0, 5)));
-
- assertEquals(0, pbr.read(c, 0, 0));
- assertEquals(c.length, pbr.read(c, 0, c.length));
- assertEquals(0, pbr.read(c, c.length, 0));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Checks exceptions.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read_$CII_Exception() throws IOException {
- pbr = new PushbackReader(new StringReader(pbString), 10);
-
- char[] nullCharArray = null;
- char[] charArray = new char[10];
-
- try {
- pbr.read(nullCharArray, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 0, -1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, -1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, charArray.length + 1, 0);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, charArray.length, 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 1, charArray.length);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- try {
- pbr.read(charArray, 0, charArray.length + 1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
-
- pbr.close();
-
- try {
- pbr.read(charArray, 0, 1);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Could also add tests where underlying says no but push back buffer has contents.",
- method = "ready",
- args = {}
- )
- public void test_ready() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- assertTrue("Should be ready!", tobj.ready());
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.ready();
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method boolean java.io.PushbackReader.ready()
- try {
- char[] c = new char[11];
- if (c.length > 0)
- ;// use c to avoid warning msg
- assertTrue("Ready stream returned false to ready()", pbr.ready());
- } catch (IOException e) {
- fail("IOException during ready() test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "reset",
- args = {}
- )
- public void test_reset() {
- try {
- pbr.reset();
- } catch (IOException e) {
- // correct
- return;
- }
- fail("reset failed to throw expected IOException");
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(char[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "unread",
- args = {char[].class}
- )
- public void test_unread$C() throws IOException {
- PushbackReader tobj;
- String str2 = "0123456789";
- char[] buf2 = str2.toCharArray();
- char[] readBuf = new char[10];
-
- tobj = new PushbackReader(underlying, 10);
- tobj.unread(buf2);
- try {
- tobj.unread(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", str2, new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(char [])
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- pbr.unread(c);
- pbr.read(c, 0, 5);
- assertTrue("Failed to unread chars", new String(c).equals(pbString
- .substring(0, 5)));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "skip",
- args = {long.class}
- )
- public void test_skip$J() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.skip(6);
- tobj.skip(1000000);
- tobj.skip(1000000);
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.skip(1);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- char chars[] = new char[] { 'h', 'e', 'l', 'l', 'o' };
- for (int i = 0; i < 3; i++) {
- Reader reader, reader2;
- switch (i) {
- case 0:
- reader = new StringReader(new String(chars));
- reader2 = new StringReader(new String(chars));
- break;
- case 1:
- reader = new FilterReader(new StringReader(new String(chars))) {
- };
- reader2 = new FilterReader(new StringReader(new String(chars))) {
- };
- break;
- default:
- reader = new CharArrayReader(chars);
- reader2 = new CharArrayReader(chars);
- }
- PushbackReader pReader = new PushbackReader(reader, 2);
- PushbackReader pReader2 = new PushbackReader(reader2, 2);
- boolean skipped = false;
- long numSkipped = 0;
- try {
- numSkipped = pReader2.skip(3);
- pReader2.unread('a');
- pReader2.unread('b');
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- numSkipped += pReader2.skip(10);
- assertEquals("Did not skip correct number of characters",
- 7, numSkipped);
- numSkipped = 0;
- numSkipped += pReader.skip(2);
- pReader.unread('i');
- numSkipped += pReader.skip(2);
- numSkipped += pReader.skip(0);
- skipped = true;
- numSkipped += pReader.skip(-1);
- fail("Failed to throw "
- + new IllegalArgumentException().getClass().getName());
- } catch (IllegalArgumentException e) {
- assertTrue("Failed to skip characters" + e, skipped);
- } catch (IOException e) {
- fail("Failed to skip characters" + e);
- }
- try {
- numSkipped += pReader.skip(1);
- numSkipped += pReader.skip(1);
- numSkipped += pReader.skip(1);
- assertEquals("Failed to skip all characters", 6, numSkipped);
- long nextSkipped = pReader.skip(1);
- assertEquals("skipped empty reader", 0, nextSkipped);
- } catch (IOException e) {
- fail("Failed to skip more characters" + e);
- }
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread$CII() throws IOException {
- PushbackReader tobj;
- String str2 = "0123456789";
- char[] buf2 = (str2 + str2 + str2).toCharArray();
- char[] readBuf = new char[10];
-
- tobj = new PushbackReader(underlying, 10);
- tobj.unread(buf2, 15, 10);
- try {
- tobj.unread(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
- tobj.read(readBuf);
- assertEquals("Incorrect bytes read", "5678901234", new String(readBuf));
- underlying.throwExceptionOnNextUse = true;
- try {
- tobj.read(buf2, 15, 10);
- fail("IOException not thrown.");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(char [], int, int)
- try {
- char[] c = new char[5];
- pbr.read(c, 0, 5);
- pbr.unread(c, 0, 2);
- pbr.read(c, 0, 5);
- assertTrue("Failed to unread chars", new String(c).equals(pbString
- .substring(0, 2)
- + pbString.substring(5, 8)));
- } catch (IOException e) {
- fail("IOException during unread test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_NullPointerException() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- try {
- pbr.unread(null, 0, 1);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_Exception_InsufficientBuffer() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- //if count > buffer's size , should throw IOException
- try {
- pbr.unread(new char[pbString.length()], 0, 2);
- fail("should throw IOException");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PushbackReader#unread(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unread",
- args = {char[].class, int.class, int.class}
- )
- public void test_unread_$CII_ArrayIndexOutOfBoundsException() throws IOException {
- //a pushback reader with one character buffer
- pbr = new PushbackReader(new StringReader(pbString));
-
- try {
- pbr.unread(new char[pbString.length()], -1 , 1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- pbr.unread(new char[pbString.length()], 0 , -1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- pbr.unread(new char[10], 10 , 1);
- fail("should throw ArrayIndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.PushbackReader#unread(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "unread",
- args = {int.class}
- )
- public void test_unreadI() throws IOException {
- PushbackReader tobj;
-
- tobj = new PushbackReader(underlying);
- tobj.unread(23); // Why does this work?!?
- tobj.skip(2);
- tobj.unread(23);
- assertEquals("Wrong value read!", 23, tobj.read());
- tobj.unread(13);
- try {
- tobj.unread(13);
- fail("IOException not thrown (ACTUALLY NOT SURE WHETHER IT REALLY MUST BE THROWN!).");
- } catch (IOException e) {
- // expected
- }
-
- // Test for method void java.io.PushbackReader.unread(int)
- try {
- int c;
- pbr.read();
- c = pbr.read();
- pbr.unread(c);
- assertTrue("Failed to unread char", pbr.read() == c);
- } catch (IOException e) {
- fail("IOException during unread test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- pbr = new PushbackReader(new StringReader(pbString), 10);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- try {
- pbr.close();
- } catch (IOException e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/RandomAccessFileTest.java b/luni/src/test/java/tests/api/java/io/RandomAccessFileTest.java
deleted file mode 100644
index 91636bb..0000000
--- a/luni/src/test/java/tests/api/java/io/RandomAccessFileTest.java
+++ /dev/null
@@ -1,1524 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-
-import java.nio.channels.FileChannel;
-import java.nio.channels.NonWritableChannelException;
-
-@TestTargetClass(RandomAccessFile.class)
-public class RandomAccessFileTest extends junit.framework.TestCase {
-
- public String fileName;
-
- public boolean ufile = true;
-
- java.io.RandomAccessFile raf;
-
- java.io.File f;
-
- String unihw = "\u0048\u0065\u006C\u0801\u006C\u006F\u0020\u0057\u0081\u006F\u0072\u006C\u0064";
-
- static final String testString = "Lorem ipsum dolor sit amet,\n" +
- "consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut" +
- "labore et dolore magna aliqua.\n";
- static final int testLength = testString.length();
-
- /**
- * @tests java.io.RandomAccessFile#RandomAccessFile(java.io.File,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String() throws Exception {
- RandomAccessFile raf = null;
- File tmpFile = new File(fileName);
-
- try {
- raf = new java.io.RandomAccessFile(tmpFile, "r");
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IllegalArgumentException e) {
- fail("Test 2: Unexpected IllegalArgumentException: " + e.getMessage());
- }
-
- tmpFile.createNewFile();
-
- try {
- // Checking the remaining valid mode parameters.
- try {
- raf = new java.io.RandomAccessFile(tmpFile, "rwd");
- } catch (IllegalArgumentException e) {
- fail("Test 3: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
- try {
- raf = new java.io.RandomAccessFile(tmpFile, "rws");
- } catch (IllegalArgumentException e) {
- fail("Test 4: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
- try {
- raf = new java.io.RandomAccessFile(tmpFile, "rw");
- } catch (IllegalArgumentException e) {
- fail("Test 5: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
-
- // Checking an invalid mode parameter.
- try {
- raf = new java.io.RandomAccessFile(tmpFile, "i");
- fail("Test 6: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
- } finally {
- if (raf != null ) raf.close();
- tmpFile.delete();
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#RandomAccessFile(java.lang.String,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "RandomAccessFile",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String()
- throws IOException {
- RandomAccessFile raf = null;
- File tmpFile = new File(fileName);
-
- try {
- raf = new java.io.RandomAccessFile(fileName, "r");
- fail("Test 1: FileNotFoundException expected.");
- } catch (FileNotFoundException e) {
- // Expected.
- } catch (IllegalArgumentException e) {
- fail("Test 2: Unexpected IllegalArgumentException: " + e.getMessage());
- }
-
- try {
- // Checking the remaining valid mode parameters.
- try {
- raf = new java.io.RandomAccessFile(fileName, "rwd");
- } catch (IllegalArgumentException e) {
- fail("Test 3: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
- try {
- raf = new java.io.RandomAccessFile(fileName, "rws");
- } catch (IllegalArgumentException e) {
- fail("Test 4: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
- try {
- raf = new java.io.RandomAccessFile(fileName, "rw");
- } catch (IllegalArgumentException e) {
- fail("Test 5: Unexpected IllegalArgumentException: " + e.getMessage());
- }
- raf.close();
-
- // Checking an invalid mode parameter.
- try {
- raf = new java.io.RandomAccessFile(fileName, "i");
- fail("Test 6: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- // Checking for NoWritableChannelException.
- raf = new java.io.RandomAccessFile(fileName, "r");
- FileChannel fcr = raf.getChannel();
-
- try {
- fcr.lock(0L, Long.MAX_VALUE, false);
- fail("Test 7: NonWritableChannelException expected.");
- } catch (NonWritableChannelException e) {
- // Expected.
- }
-
- } finally {
- if (raf != null ) raf.close();
- if (tmpFile.exists()) tmpFile.delete();
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#close()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking, requires native code that can be forced to throw such an exception.",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.RandomAccessFile.close()
- try {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.close();
- raf.write("Test".getBytes(), 0, 4);
- fail("Failed to close file properly.");
- } catch (IOException e) {}
- }
-
- /**
- * @tests java.io.RandomAccessFile#getChannel()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getChannel",
- args = {}
- )
- public void test_getChannel() throws IOException {
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- FileChannel fc = raf.getChannel();
-
- // Indirect test: If the file's file pointer moves then the position
- // in the channel has to move accordingly.
- assertTrue("Test 1: Channel position expected to be 0.", fc.position() == 0);
-
- raf.write(testString.getBytes());
- assertEquals("Test 2: Unexpected channel position.",
- testLength, fc.position());
- assertTrue("Test 3: Channel position is not equal to file pointer.",
- fc.position() == raf.getFilePointer());
- raf.close();
- }
-
- /**
- * @tests java.io.RandomAccessFile#getFD()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "No IOException checking since this exception is not thrown.",
- method = "getFD",
- args = {}
- )
- public void test_getFD() throws IOException {
- // Test for method java.io.FileDescriptor
- // java.io.RandomAccessFile.getFD()
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- assertTrue("Test 1: Returned invalid fd.", raf.getFD().valid());
-
- raf.close();
- assertFalse("Test 2: Returned valid fd after close", raf.getFD().valid());
- }
-
- /**
- * @tests java.io.RandomAccessFile#getFilePointer()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getFilePointer",
- args = {}
- )
- public void test_getFilePointer() throws IOException {
- // Test for method long java.io.RandomAccessFile.getFilePointer()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(testString.getBytes(), 0, testLength);
- assertEquals("Test 1: Incorrect filePointer returned. ", testLength, raf
- .getFilePointer());
- raf.close();
- try {
- raf.getFilePointer();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#length()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "length",
- args = {}
- )
- public void test_length() throws IOException {
- // Test for method long java.io.RandomAccessFile.length()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(testString.getBytes());
- assertEquals("Test 1: Incorrect length returned. ", testLength,
- raf.length());
- raf.close();
- try {
- raf.length();
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#read()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- })
- public void test_read_write() throws IOException {
- int i;
- byte[] testBuf = testString.getBytes();
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- for (i = 0; i < testString.length(); i++) {
- try {
- raf.write(testBuf[i]);
- } catch (Exception e) {
- fail("Test 1: Unexpected exception while writing: "
- + e.getMessage());
- }
- }
-
- raf.seek(0);
-
- for (i = 0; i < testString.length(); i++) {
- assertEquals(String.format("Test 2: Incorrect value written or read at index %d; ", i),
- testBuf[i], raf.read());
- }
-
- assertTrue("Test 3: End of file indicator (-1) expected.", raf.read() == -1);
-
- raf.close();
- try {
- raf.write(42);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.read();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class}
- )
- public void test_read$B() throws IOException {
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(testString.getBytes(), 0, testLength);
- fos.close();
-
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "r");
- byte[] rbuf = new byte[testLength + 10];
-
- int bytesRead = raf.read(rbuf);
- assertEquals("Test 1: Incorrect number of bytes read. ",
- testLength, bytesRead);
- assertEquals("Test 2: Incorrect bytes read. ", testString,
- new String(rbuf, 0, testLength));
-
- bytesRead = raf.read(rbuf);
- assertTrue("Test 3: EOF (-1) expected. ", bytesRead == -1);
-
- raf.close();
- try {
- bytesRead = raf.read(rbuf);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- int bytesRead;
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- byte[] rbuf = new byte[4000];
-
- FileOutputStream fos = new java.io.FileOutputStream(fileName);
- fos.write(testString.getBytes(), 0, testLength);
- fos.close();
-
- // Read half of the file contents.
- bytesRead = raf.read(rbuf, 10, testLength / 2);
- assertEquals("Test 1: Incorrect number of bytes read. ",
- testLength / 2, bytesRead);
- assertEquals("Test 2: Incorrect bytes read. ",
- testString.substring(0, testLength / 2),
- new String(rbuf, 10, testLength / 2));
-
- // Read the rest of the file contents.
- bytesRead = raf.read(rbuf, 0, testLength);
- assertEquals("Test 3: Incorrect number of bytes read. ",
- testLength - (testLength / 2), bytesRead);
- assertEquals("Test 4: Incorrect bytes read. ",
- testString.substring(testLength / 2, (testLength / 2) + bytesRead),
- new String(rbuf, 0, bytesRead));
-
- // Try to read even more.
- bytesRead = raf.read(rbuf, 0, 1);
- assertTrue("Test 5: EOF (-1) expected. ", bytesRead == -1);
-
- // Illegal parameter value tests.
- try {
- raf.read(rbuf, -1, 1);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- raf.read(rbuf, 0, -1);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- raf.read(rbuf, 2000, 2001);
- fail("Test 8: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- // IOException test.
- raf.close();
- try {
- bytesRead = raf.read(rbuf, 0, 1);
- fail("Test 9: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readBoolean()
- * @tests java.io.RandomAccessFile#writeBoolean(boolean)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeBoolean",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readBoolean",
- args = {}
- )
- })
- public void test_read_writeBoolean() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBoolean(true);
- raf.writeBoolean(false);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- true, raf.readBoolean());
- assertEquals("Test 2: Incorrect value written or read;",
- false, raf.readBoolean());
-
- try {
- raf.readBoolean();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeBoolean(false);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readBoolean();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readByte()
- * @tests java.io.RandomAccessFile#writeByte(byte)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeByte",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readByte",
- args = {}
- )
- })
- public void test_read_writeByte() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeByte(Byte.MIN_VALUE);
- raf.writeByte(11);
- raf.writeByte(Byte.MAX_VALUE);
- raf.writeByte(Byte.MIN_VALUE - 1);
- raf.writeByte(Byte.MAX_VALUE + 1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Byte.MIN_VALUE, raf.readByte());
- assertEquals("Test 2: Incorrect value written or read;",
- 11, raf.readByte());
- assertEquals("Test 3: Incorrect value written or read;",
- Byte.MAX_VALUE, raf.readByte());
- assertEquals("Test 4: Incorrect value written or read;",
- 127, raf.readByte());
- assertEquals("Test 5: Incorrect value written or read;",
- -128, raf.readByte());
-
- try {
- raf.readByte();
- fail("Test 6: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeByte(13);
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readByte();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readChar()
- * @tests java.io.RandomAccessFile#writeChar(char)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readChar",
- args = {}
- )
- })
- public void test_read_writeChar() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeChar(Character.MIN_VALUE);
- raf.writeChar('T');
- raf.writeChar(Character.MAX_VALUE);
- raf.writeChar(Character.MIN_VALUE - 1);
- raf.writeChar(Character.MAX_VALUE + 1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Character.MIN_VALUE, raf.readChar());
- assertEquals("Test 2: Incorrect value written or read;",
- 'T', raf.readChar());
- assertEquals("Test 3: Incorrect value written or read;",
- Character.MAX_VALUE, raf.readChar());
- assertEquals("Test 4: Incorrect value written or read;",
- 0xffff, raf.readChar());
- assertEquals("Test 5: Incorrect value written or read;",
- 0, raf.readChar());
-
- try {
- raf.readChar();
- fail("Test 6: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeChar('E');
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readChar();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readDouble()
- * @tests java.io.RandomAccessFile#writeDouble(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeDouble",
- args = {double.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readDouble",
- args = {}
- )
- })
- public void test_read_writeDouble() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeDouble(Double.MAX_VALUE);
- raf.writeDouble(424242.4242);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Double.MAX_VALUE, raf.readDouble());
- assertEquals("Test 2: Incorrect value written or read;",
- 424242.4242, raf.readDouble());
-
- try {
- raf.readDouble();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeDouble(Double.MIN_VALUE);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readDouble();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readFloat()
- * @tests java.io.RandomAccessFile#writeFloat(double)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeFloat",
- args = {float.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFloat",
- args = {}
- )
- })
- public void test_read_writeFloat() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeFloat(Float.MAX_VALUE);
- raf.writeFloat(555.55f);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read. ",
- Float.MAX_VALUE, raf.readFloat());
- assertEquals("Test 2: Incorrect value written or read. ",
- 555.55f, raf.readFloat());
-
- try {
- raf.readFloat();
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeFloat(Float.MIN_VALUE);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readFloat();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readInt()
- * @tests java.io.RandomAccessFile#writeInt(char)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeInt",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readInt",
- args = {}
- )
- })
- public void test_read_writeInt() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeInt(Integer.MIN_VALUE);
- raf.writeInt('T');
- raf.writeInt(Integer.MAX_VALUE);
- raf.writeInt(Integer.MIN_VALUE - 1);
- raf.writeInt(Integer.MAX_VALUE + 1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Integer.MIN_VALUE, raf.readInt());
- assertEquals("Test 2: Incorrect value written or read;",
- 'T', raf.readInt());
- assertEquals("Test 3: Incorrect value written or read;",
- Integer.MAX_VALUE, raf.readInt());
- assertEquals("Test 4: Incorrect value written or read;",
- 0x7fffffff, raf.readInt());
- assertEquals("Test 5: Incorrect value written or read;",
- 0x80000000, raf.readInt());
-
- try {
- raf.readInt();
- fail("Test 6: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeInt('E');
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readInt();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readLong()
- * @tests java.io.RandomAccessFile#writeLong(char)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeLong",
- args = {long.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readLong",
- args = {}
- )
- })
- public void test_read_writeLong() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeLong(Long.MIN_VALUE);
- raf.writeLong('T');
- raf.writeLong(Long.MAX_VALUE);
- raf.writeLong(Long.MIN_VALUE - 1);
- raf.writeLong(Long.MAX_VALUE + 1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Long.MIN_VALUE, raf.readLong());
- assertEquals("Test 2: Incorrect value written or read;",
- 'T', raf.readLong());
- assertEquals("Test 3: Incorrect value written or read;",
- Long.MAX_VALUE, raf.readLong());
- assertEquals("Test 4: Incorrect value written or read;",
- 0x7fffffffffffffffl, raf.readLong());
- assertEquals("Test 5: Incorrect value written or read;",
- 0x8000000000000000l, raf.readLong());
-
- try {
- raf.readLong();
- fail("Test 6: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeLong('E');
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readLong();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readShort()
- * @tests java.io.RandomAccessFile#writeShort(short)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeShort",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readShort",
- args = {}
- )
- })
- public void test_read_writeShort() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeShort(Short.MIN_VALUE);
- raf.writeShort('T');
- raf.writeShort(Short.MAX_VALUE);
- raf.writeShort(Short.MIN_VALUE - 1);
- raf.writeShort(Short.MAX_VALUE + 1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- Short.MIN_VALUE, raf.readShort());
- assertEquals("Test 2: Incorrect value written or read;",
- 'T', raf.readShort());
- assertEquals("Test 3: Incorrect value written or read;",
- Short.MAX_VALUE, raf.readShort());
- assertEquals("Test 4: Incorrect value written or read;",
- 0x7fff, raf.readShort());
- assertEquals("Test 5: Incorrect value written or read;",
- (short) 0x8000, raf.readShort());
-
- try {
- raf.readShort();
- fail("Test 6: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeShort('E');
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readShort();
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUTF()
- * @tests java.io.RandomAccessFile#writeShort(char)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeUTF",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUTF",
- args = {}
- )
- })
- public void test_read_writeUTF() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeUTF(unihw);
- raf.seek(0);
- assertEquals("Test 1: Incorrect UTF string written or read;",
- unihw, raf.readUTF());
-
- try {
- raf.readUTF();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeUTF("Already closed.");
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readUTF();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeBytes(java.lang.String)
- * @tests java.io.RandomAccessFile#readFully(byte[])
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeBytes",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFully",
- args = {byte[].class}
- )
- })
- public void test_readFully$B_writeBytesLjava_lang_String() throws IOException {
- byte[] buf = new byte[testLength];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes(testString);
- raf.seek(0);
-
- try {
- raf.readFully(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- raf.readFully(buf);
- assertEquals("Test 2: Incorrect bytes written or read;",
- testString, new String(buf));
-
- try {
- raf.readFully(buf);
- fail("Test 3: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.writeBytes("Already closed.");
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- try {
- raf.readFully(buf);
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeBytes(java.lang.String)
- * @tests java.io.RandomAccessFile#readFully(byte[], int, int)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeBytes",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readFully",
- args = {byte[].class, int.class, int.class}
- )
- })
- public void test_readFully$BII() throws IOException {
- byte[] buf = new byte[testLength];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes(testString);
- raf.seek(0);
-
- try {
- raf.readFully(null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- raf.readFully(buf, 5, testLength - 10);
- for (int i = 0; i < 5; i++) {
- assertEquals("Test 2: Incorrect bytes read;", 0, buf[i]);
- }
- assertEquals("Test 3: Incorrect bytes written or read;",
- testString.substring(0, testLength - 10),
- new String(buf, 5, testLength - 10));
-
- // Reading past the end of the file.
- try {
- raf.readFully(buf, 3, testLength - 6);
- fail("Test 4: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- // Passing invalid arguments.
- try {
- raf.readFully(buf, -1, 1);
- fail("Test 5: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- raf.readFully(buf, 0, -1);
- fail("Test 6: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
- try {
- raf.readFully(buf, 2, testLength);
- fail("Test 7: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- }
-
- // Reading from a closed file.
- raf.close();
- try {
- raf.readFully(buf);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUnsignedByte()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUnsignedByte",
- args = {}
- )
- public void test_readUnsignedByte() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeByte(-1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- 255, raf.readUnsignedByte());
-
- try {
- raf.readUnsignedByte();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.readUnsignedByte();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readUnsignedShort()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "readUnsignedShort",
- args = {}
- )
- public void test_readUnsignedShort() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeShort(-1);
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect value written or read;",
- 65535, raf.readUnsignedShort());
-
- try {
- raf.readUnsignedShort();
- fail("Test 2: EOFException expected.");
- } catch (EOFException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.readUnsignedShort();
- fail("Test 3: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#readLine()
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "",
- method = "readLine",
- args = {}
- )
- public void test_readLine() throws IOException {
- // Test for method java.lang.String java.io.RandomAccessFile.readLine()
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- String s = "Goodbye\nCruel\nWorld\n";
- raf.write(s.getBytes(), 0, s.length());
- raf.seek(0);
-
- assertEquals("Test 1: Incorrect line read;", "Goodbye", raf.readLine());
- assertEquals("Test 2: Incorrect line read;", "Cruel", raf.readLine());
- assertEquals("Test 3: Incorrect line read;", "World", raf.readLine());
- assertNull("Test 4: Incorrect line read; null expected.", raf.readLine());
-
- raf.close();
- try {
- raf.readLine();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- }
-
- /**
- * @tests java.io.RandomAccessFile#seek(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "seek",
- args = {long.class}
- )
- public void test_seekJ() throws IOException {
- // Test for method void java.io.RandomAccessFile.seek(long)
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
-
- try {
- raf.seek(-1);
- fail("Test 1: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // BEGIN android-added
- try {
- // Android uses 32-bit off_t, so anything larger than a signed 32-bit int won't work.
- raf.seek(((long) Integer.MAX_VALUE) + 1);
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // END android-added
-
- raf.write(testString.getBytes(), 0, testLength);
- raf.seek(12);
- assertEquals("Test 3: Seek failed to set file pointer.", 12,
- raf.getFilePointer());
-
- raf.close();
- try {
- raf.seek(1);
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skipBytes",
- args = {int.class}
- )
- public void test_skipBytesI() throws IOException {
- byte[] buf = new byte[5];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeBytes("HelloWorld");
- raf.seek(0);
-
- assertTrue("Test 1: Nothing should be skipped if parameter is less than zero",
- raf.skipBytes(-1) == 0);
-
- assertEquals("Test 4: Incorrect number of bytes skipped; ",
- 5, raf.skipBytes(5));
-
- raf.readFully(buf);
- assertEquals("Test 3: Failed to skip bytes.",
- "World", new String(buf, 0, 5));
-
- raf.seek(0);
- assertEquals("Test 4: Incorrect number of bytes skipped; ",
- 10, raf.skipBytes(20));
-
- raf.close();
- try {
- raf.skipBytes(1);
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#skipBytes(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "setLength",
- args = {long.class}
- )
- public void test_setLengthJ() throws IOException {
- int bytesRead;
- long truncLength = (long) (testLength * 0.75);
- byte[] rbuf = new byte[testLength + 10];
-
- // Setup the test file.
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.write(testString.getBytes());
- assertEquals("Test 1: Incorrect file length;",
- testLength, raf.length());
-
- // Truncate the file.
- raf.setLength(truncLength);
- assertTrue("Test 2: File pointer not moved to the end of the truncated file.",
- raf.getFilePointer() == truncLength);
-
- raf.close();
- raf = new java.io.RandomAccessFile(fileName, "rw");
- assertEquals("Test 3: Incorrect file length;",
- truncLength, raf.length());
- bytesRead = raf.read(rbuf);
- assertEquals("Test 4: Incorrect number of bytes read;",
- truncLength, bytesRead);
- assertEquals("Test 5: Incorrect bytes read. ",
- testString.substring(0, bytesRead),
- new String(rbuf, 0, bytesRead));
-
- // Expand the file.
- raf.setLength(testLength + 2);
- assertTrue("Test 6: File pointer incorrectly moved.",
- raf.getFilePointer() == truncLength);
- assertEquals("Test 7: Incorrect file length;",
- testLength + 2, raf.length());
-
- // BEGIN android-added
- // Exception testing.
- try {
- // Android uses 32-bit off_t, so anything larger than a signed 32-bit int won't work.
- raf.setLength(((long) Integer.MAX_VALUE) + 1);
- fail("Test 8: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- // END android-added
-
- // Exception testing.
- try {
- raf.setLength(-1);
- fail("Test 9: IllegalArgumentException expected.");
- } catch (IllegalArgumentException e) {
- // Expected.
- }
-
- raf.close();
- try {
- raf.setLength(truncLength);
- fail("Test 10: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[])
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class}
- )
- public void test_write$B() throws IOException {
- byte[] rbuf = new byte[4000];
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
-
- byte[] nullByteArray = null;
- try {
- raf.write(nullByteArray);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- try {
- raf.write(testString.getBytes());
- } catch (Exception e) {
- fail("Test 2: Unexpected exception: " + e.getMessage());
- }
-
- raf.close();
-
- try {
- raf.write(new byte[0]);
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException: " + e.getMessage());
- }
-
- try {
- raf.write(testString.getBytes());
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- FileInputStream fis = new java.io.FileInputStream(fileName);
- fis.read(rbuf, 0, testLength);
- assertEquals("Incorrect bytes written", testString, new String(rbuf, 0,
- testLength));
- }
-
- /**
- * @tests java.io.RandomAccessFile#write(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {byte[].class, int.class, int.class}
- )
- public void test_write$BII() throws Exception {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- byte[] rbuf = new byte[4000];
- byte[] testBuf = null;
- int bytesRead;
-
- try {
- raf.write(testBuf, 1, 1);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- testBuf = testString.getBytes();
-
- try {
- raf.write(testBuf, -1, 10);
- fail("Test 2: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- assertEquals(
- "Test 2: IndexOutOfBoundsException rather than a subclass expected.",
- IndexOutOfBoundsException.class, e.getClass());
- }
-
- try {
- raf.write(testBuf, 0, -1);
- fail("Test 3: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- assertEquals(
- "Test 3: IndexOutOfBoundsException rather than a subclass expected.",
- IndexOutOfBoundsException.class, e.getClass());
- }
-
- try {
- raf.write(testBuf, 5, testLength);
- fail("Test 4: IndexOutOfBoundsException expected.");
- } catch (IndexOutOfBoundsException e) {
- // Expected.
- assertEquals(
- "Test 4: IndexOutOfBoundsException rather than a subclass expected.",
- IndexOutOfBoundsException.class, e.getClass());
- }
-
- // Positive test: The following write should not fail.
- try {
- raf.write(testBuf, 3, testLength - 5);
- } catch (Exception e) {
- fail("Test 5: Unexpected exception: " + e.getMessage());
- }
-
- raf.close();
-
- // Writing nothing to a closed file should not fail either.
- try {
- raf.write(new byte[0]);
- } catch (IOException e) {
- fail("Test 6: Unexpected IOException: " + e.getMessage());
- }
-
- // Writing something to a closed file should fail.
- try {
- raf.write(testString.getBytes());
- fail("Test 7: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- FileInputStream fis = new java.io.FileInputStream(fileName);
- bytesRead = fis.read(rbuf, 0, testLength);
- assertEquals("Test 8: Incorrect number of bytes written or read;",
- testLength - 5, bytesRead);
- assertEquals("Test 9: Incorrect bytes written or read; ",
- testString.substring(3, testLength - 2),
- new String(rbuf, 0, bytesRead));
- }
-
- /**
- * @tests java.io.RandomAccessFile#writeChars(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Tests against golden file missing.",
- method = "writeChars",
- args = {java.lang.String.class}
- )
- public void test_writeCharsLjava_lang_String() throws IOException {
- RandomAccessFile raf = new java.io.RandomAccessFile(fileName, "rw");
- raf.writeChars(unihw);
- char[] hchars = new char[unihw.length()];
- unihw.getChars(0, unihw.length(), hchars, 0);
- raf.seek(0);
- for (int i = 0; i < hchars.length; i++)
- assertEquals("Test 1: Incorrect character written or read at index " + i + ";",
- hchars[i], raf.readChar());
- raf.close();
- try {
- raf.writeChars("Already closed.");
- fail("Test 2: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() throws Exception {
- super.setUp();
-
- f = File.createTempFile("raf", "tst");
- if (!f.delete()) {
- fail("Unable to delete test file : " + f);
- }
- fileName = f.getAbsolutePath();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- * @throws Exception
- */
- protected void tearDown() throws Exception {
- if (f.exists()) {
- f.delete();
- }
- super.tearDown();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java b/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
deleted file mode 100644
index 0b9d2a4..0000000
--- a/luni/src/test/java/tests/api/java/io/SequenceInputStreamTest.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.SequenceInputStream;
-import java.util.Enumeration;
-
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(SequenceInputStream.class)
-public class SequenceInputStreamTest extends junit.framework.TestCase {
-
- Support_ASimpleInputStream simple1, simple2;
- SequenceInputStream si;
- String s1 = "Hello";
- String s2 = "World";
-
- /**
- * @tests SequenceInputStream#SequenceInputStream(java.io.InputStream,
- * java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Checks NullPointerException. A positive test of this " +
- "constructor is implicitely done in setUp(); if it would " +
- "fail, all other tests will also fail.",
- method = "SequenceInputStream",
- args = {java.io.InputStream.class, java.io.InputStream.class}
- )
- public void test_Constructor_LInputStreamLInputStream_Null() {
- try {
- si = new SequenceInputStream(null , null);
- fail("Test 1: NullPointerException expected.");
- } catch (NullPointerException e) {
- // Expected.
- }
-
- //will not throw NullPointerException if the first InputStream is not null
- InputStream is = new ByteArrayInputStream(s1.getBytes());
- si = new SequenceInputStream(is , null);
- }
-
- /**
- * @tests java.io.SequenceInputStream#SequenceInputStream(java.util.Enumeration)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SequenceInputStream",
- args = {java.util.Enumeration.class}
- )
- public void test_ConstructorLjava_util_Enumeration() {
- // Test for method java.io.SequenceInputStream(java.util.Enumeration)
- class StreamEnumerator implements Enumeration<InputStream> {
- InputStream streams[] = new InputStream[2];
-
- int count = 0;
-
- public StreamEnumerator() {
- streams[0] = new ByteArrayInputStream(s1.getBytes());
- streams[1] = new ByteArrayInputStream(s2.getBytes());
- }
-
- public boolean hasMoreElements() {
- return count < streams.length;
- }
-
- public InputStream nextElement() {
- return streams[count++];
- }
- }
-
- try {
- si = new SequenceInputStream(new StreamEnumerator());
- byte buf[] = new byte[s1.length() + s2.length()];
- si.read(buf, 0, s1.length());
- si.read(buf, s1.length(), s2.length());
- assertTrue("Read incorrect bytes: " + new String(buf), new String(
- buf).equals(s1 + s2));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
-
- }
-
- /**
- * @throws IOException
- * @tests java.io.SequenceInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() throws IOException {
- assertEquals("Returned incorrect number of bytes!", s1.length(), si.available());
- simple2.throwExceptionOnNextUse = true;
- assertTrue("IOException on second stream should not affect at this time!",
- si.available() == s1.length());
- simple1.throwExceptionOnNextUse = true;
- try {
- si.available();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- assertTrue("Something is available!", si.available() > 0);
- si.close();
- //will not throw IOException to close a stream which is closed already
- si.close();
- assertTrue("Nothing is available, now!", si.available() <= 0);
-// assertEquals("And not on the underlying streams either!", 0, simple1.available());
-// assertTrue("And not on the underlying streams either!", simple1.available() <= 0);
-// assertTrue("And not on the underlying streams either!", simple2.available() <= 0);
- }
-
- /**
- * @tests java.io.SequenceInputStream#close()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close2() throws IOException {
- simple1.throwExceptionOnNextUse = true;
- try {
- si.close();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() throws IOException {
- si.read();
- assertEquals("Test 1: Incorrect char read;",
- s1.charAt(1), (char) si.read());
-
- // We are still reading from the first input stream, should be ok.
- simple2.throwExceptionOnNextUse = true;
- try {
- assertEquals("Test 2: Incorrect char read;",
- s1.charAt(2), (char) si.read());
- } catch (IOException e) {
- fail("Test 3: Unexpected IOException.");
- }
-
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read();
- fail("Test 4: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- simple1.throwExceptionOnNextUse = false;
-
- // Reading bytes 4 and 5 of the first input stream should be ok again.
- si.read();
- si.read();
-
- // Reading the first byte of the second input stream should fail.
- try {
- si.read();
- fail("Test 5: IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
-
- // Reading from the second input stream should be ok now.
- simple2.throwExceptionOnNextUse = false;
- try {
- assertEquals("Test 6: Incorrect char read;",
- s2.charAt(0), (char) si.read());
- } catch (IOException e) {
- fail("Test 7: Unexpected IOException.");
- }
-
- si.close();
- assertTrue("Test 8: -1 expected when reading from a closed " +
- "sequence input stream.", si.read() == -1);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read_exc() throws IOException {
- simple2.throwExceptionOnNextUse = true;
- assertEquals("IOException on second stream should not affect at this time!", 72, si.read());
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read();
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.SequenceInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() throws IOException {
- // Test for method int java.io.SequenceInputStream.read(byte [], int,
- // int)
- try {
- byte buf[] = new byte[s1.length() + s2.length()];
- si.read(buf, 0, s1.length());
- si.read(buf, s1.length(), s2.length());
- assertTrue("Read incorrect bytes: " + new String(buf), new String(
- buf).equals(s1 + s2));
- } catch (IOException e) {
- fail("IOException during read test : " + e.getMessage());
- }
-
- ByteArrayInputStream bis1 = new ByteArrayInputStream(
- new byte[] { 1, 2, 3, 4 });
- ByteArrayInputStream bis2 = new ByteArrayInputStream(
- new byte[] { 5, 6, 7, 8 });
- SequenceInputStream sis = new SequenceInputStream(bis1, bis2);
-
- try {
- sis.read(null, 0, 2);
- fail("Expected NullPointerException exception");
- } catch (NullPointerException e) {
- // expected
- }
-
- assertEquals(4, sis.read(new byte[10], 0, 8));
- // The call to read will return after the end of the first substream is
- // reached. So the next call to read will close the first substream
- // because the read call to that substream will return -1, and
- // it will continue reading from the second substream.
- assertEquals(5, sis.read());
-
- //returns -1 if the stream is closed , do not throw IOException
- byte[] array = new byte[] { 1 , 2 , 3 ,4 };
- sis.close();
- int result = sis.read(array , 0 , 5);
- assertEquals(-1 , result);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Excpetion() throws IOException {
- byte[] buf = new byte[4];
- si.read(buf, 0, 2);
- si.read(buf, 2, 1);
- simple2.throwExceptionOnNextUse = true;
- si.read(buf, 3, 1);
- assertEquals("Wrong stuff read!", "Hell", new String(buf));
- simple1.throwExceptionOnNextUse = true;
- try {
- si.read(buf, 3, 1);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
-
- buf = new byte[10];
- simple1 = new Support_ASimpleInputStream(s1);
- simple2 = new Support_ASimpleInputStream(s2);
- si = new SequenceInputStream(simple1, simple2);
- try {
- si.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- si.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- si.read(buf, 1, 10);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- simple1 = new Support_ASimpleInputStream(s1);
- simple2 = new Support_ASimpleInputStream(s2);
- si = new SequenceInputStream(simple1, simple2);
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java b/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java
deleted file mode 100644
index 22b5998..0000000
--- a/luni/src/test/java/tests/api/java/io/SerializablePermissionTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
-import java.io.SerializablePermission;
-
-@TestTargetClass(SerializablePermission.class)
-public class SerializablePermissionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SerializablePermission",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.SerializablePermission(java.lang.String)
- assertEquals("permission ill-formed",
- "enableSubclassImplementation", new SerializablePermission(
- "enableSubclassImplementation").getName());
- }
-
- /**
- * @tests java.io.SerializablePermission#SerializablePermission(java.lang.String,
- * java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SerializablePermission",
- args = {java.lang.String.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_String() {
- // Test for method java.io.SerializablePermission(java.lang.String,
- // java.lang.String)
- assertEquals("permission ill-formed",
- "enableSubclassImplementation", new SerializablePermission(
- "enableSubclassImplementation", "").getName());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java b/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java
deleted file mode 100644
index de062f3..0000000
--- a/luni/src/test/java/tests/api/java/io/StreamCorruptedExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.StreamCorruptedException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(StreamCorruptedException.class)
-public class StreamCorruptedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.StreamCorruptedException#StreamCorruptedException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "StreamCorruptedException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new StreamCorruptedException();
- fail("Test 1: StreamCorruptedException expected.");
- } catch (StreamCorruptedException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StreamCorruptedException#StreamCorruptedException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "StreamCorruptedException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new StreamCorruptedException("Something went wrong.");
- fail("Test 1: StreamCorruptedException expected.");
- } catch (StreamCorruptedException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java b/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
deleted file mode 100644
index a91a97d..0000000
--- a/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java
+++ /dev/null
@@ -1,757 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.ByteArrayInputStream;
-import java.io.CharArrayReader;
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.Reader;
-import java.io.StreamTokenizer;
-import java.io.StringBufferInputStream;
-import java.io.StringReader;
-
-import junit.framework.Assert;
-import tests.support.Support_StringReader;
-import tests.support.Support_ASimpleInputStream;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-// TODO: most of the assertTrue calls in this test case should be
-// replaced with assertEquals (possibly two assertEquals) see
-// test_ConstructorLjava_io_InputStream for example.
-// This gives much more helpful error messages.
-
-@TestTargetClass(StreamTokenizer.class)
-public class StreamTokenizerTest extends junit.framework.TestCase {
- Support_StringReader r;
-
- StreamTokenizer st;
-
- String testString;
-
- /**
- * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StreamTokenizer",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() throws IOException {
- st = new StreamTokenizer(new StringBufferInputStream(
- "/comments\n d 8 'h'"));
-
- assertEquals("the next token returned should be the letter d",
- StreamTokenizer.TT_WORD, st.nextToken());
- assertEquals("the next token returned should be the letter d",
- "d", st.sval);
-
- assertEquals("the next token returned should be the digit 8",
- StreamTokenizer.TT_NUMBER, st.nextToken());
- assertEquals("the next token returned should be the digit 8",
- 8.0, st.nval);
-
- assertEquals("the next token returned should be the quote character",
- 39, st.nextToken());
- assertEquals("the next token returned should be the quote character",
- "h", st.sval);
- }
-
- /**
- * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.Reader)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StreamTokenizer",
- args = {java.io.Reader.class}
- )
- public void test_ConstructorLjava_io_Reader() throws IOException {
- setTest("/testing\n d 8 'h' ");
- assertEquals("the next token returned should be the letter d skipping the comments",
- StreamTokenizer.TT_WORD, st.nextToken());
- assertEquals("the next token returned should be the letter d",
- "d", st.sval);
-
- assertEquals("the next token returned should be the digit 8",
- StreamTokenizer.TT_NUMBER, st.nextToken());
- assertEquals("the next token returned should be the digit 8",
- 8.0, st.nval);
-
- assertEquals("the next token returned should be the quote character",
- 39, st.nextToken());
- assertEquals("the next token returned should be the quote character",
- "h", st.sval);
- }
-
- /**
- * @tests java.io.StreamTokenizer#commentChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "commentChar",
- args = {int.class}
- )
- public void test_commentCharI() throws IOException {
- setTest("*comment \n / 8 'h' ");
- st.ordinaryChar('/');
- st.commentChar('*');
- assertEquals("nextToken() did not return the character / skiping the comments starting with *",
- 47, st.nextToken());
- assertTrue("the next token returned should be the digit 8", st
- .nextToken() == StreamTokenizer.TT_NUMBER
- && st.nval == 8.0);
- assertTrue("the next token returned should be the quote character",
- st.nextToken() == 39 && st.sval.equals("h"));
- }
-
- /**
- * @tests java.io.StreamTokenizer#eolIsSignificant(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "eolIsSignificant",
- args = {boolean.class}
- )
- public void test_eolIsSignificantZ() throws IOException {
- setTest("d 8\n");
- // by default end of line characters are not significant
- assertTrue("nextToken did not return d",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("d"));
- assertTrue("nextToken did not return 8",
- st.nextToken() == StreamTokenizer.TT_NUMBER
- && st.nval == 8.0);
- assertTrue("nextToken should be the end of file",
- st.nextToken() == StreamTokenizer.TT_EOF);
- setTest("d\n");
- st.eolIsSignificant(true);
- // end of line characters are significant
- assertTrue("nextToken did not return d",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("d"));
- assertTrue("nextToken is the end of line",
- st.nextToken() == StreamTokenizer.TT_EOL);
- }
-
- /**
- * @tests java.io.StreamTokenizer#lineno()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lineno",
- args = {}
- )
- public void test_lineno() throws IOException {
- setTest("d\n 8\n");
- assertEquals("the lineno should be 1", 1, st.lineno());
- st.nextToken();
- st.nextToken();
- assertEquals("the lineno should be 2", 2, st.lineno());
- st.nextToken();
- assertEquals("the next line no should be 3", 3, st.lineno());
- }
-
- /**
- * @tests java.io.StreamTokenizer#lowerCaseMode(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "lowerCaseMode",
- args = {boolean.class}
- )
- public void test_lowerCaseModeZ() throws Exception {
- // SM.
- setTest("HELLOWORLD");
- st.lowerCaseMode(true);
-
- st.nextToken();
- assertEquals("sval not converted to lowercase.", "helloworld", st.sval
- );
- }
-
- /**
- * @tests java.io.StreamTokenizer#nextToken()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "nextToken",
- args = {}
- )
- public void test_nextToken() throws IOException {
- setTest("\r\n/* fje fje 43.4 f \r\n f g */ 456.459 \r\n"
- + "Hello / \r\n \r\n \n \r \257 Hi \'Hello World\'");
- st.ordinaryChar('/');
- st.slashStarComments(true);
- st.nextToken();
- assertTrue("Wrong Token type1: " + (char) st.ttype,
- st.ttype == StreamTokenizer.TT_NUMBER);
- st.nextToken();
- assertTrue("Wrong Token type2: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type3: " + st.ttype, st.ttype == '/');
- st.nextToken();
- assertTrue("Wrong Token type4: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type5: " + st.ttype,
- st.ttype == StreamTokenizer.TT_WORD);
- st.nextToken();
- assertTrue("Wrong Token type6: " + st.ttype, st.ttype == '\'');
- assertTrue("Wrong Token type7: " + st.ttype, st.sval
- .equals("Hello World"));
- st.nextToken();
- assertTrue("Wrong Token type8: " + st.ttype, st.ttype == -1);
-
- final PipedInputStream pin = new PipedInputStream();
- PipedOutputStream pout = new PipedOutputStream(pin);
- pout.write("hello\n\r\r".getBytes());
- st = new StreamTokenizer(pin);
- st.eolIsSignificant(true);
- assertTrue("Wrong token 1,1",
- st.nextToken() == StreamTokenizer.TT_WORD
- && st.sval.equals("hello"));
- assertTrue("Wrong token 1,2", st.nextToken() == '\n');
- assertTrue("Wrong token 1,3", st.nextToken() == '\n');
- assertTrue("Wrong token 1,4", st.nextToken() == '\n');
- pout.close();
- assertTrue("Wrong token 1,5",
- st.nextToken() == StreamTokenizer.TT_EOF);
-
- st = new StreamTokenizer(new Support_StringReader("\n \r\n#"));
- st.ordinaryChar('\n'); // make \n ordinary
- st.eolIsSignificant(true);
- assertTrue("Wrong token 2,1", st.nextToken() == '\n');
- assertTrue("Wrong token 2,2", st.nextToken() == '\n');
- assertEquals("Wrong token 2,3", '#', st.nextToken());
-
- Support_ASimpleInputStream sis = new Support_ASimpleInputStream();
- sis.throwExceptionOnNextUse = true;
- st = new StreamTokenizer(sis);
- try {
- st.nextToken();
- fail("IOException expected.");
- } catch (IOException e) {
- // Expected.
- }
- }
-
- /**
- * @tests java.io.StreamTokenizer#ordinaryChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ordinaryChar",
- args = {int.class}
- )
- public void test_ordinaryCharI() throws IOException {
- // SM.
- setTest("Ffjein 893");
- st.ordinaryChar('F');
- st.nextToken();
- assertTrue("OrdinaryChar failed." + (char) st.ttype,
- st.ttype == 'F');
- }
-
- /**
- * @tests java.io.StreamTokenizer#ordinaryChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ordinaryChars",
- args = {int.class, int.class}
- )
- public void test_ordinaryCharsII() throws IOException {
- // SM.
- setTest("azbc iof z 893");
- st.ordinaryChars('a', 'z');
- assertEquals("OrdinaryChars failed.", 'a', st.nextToken());
- assertEquals("OrdinaryChars failed.", 'z', st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#parseNumbers()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseNumbers",
- args = {}
- )
- public void test_parseNumbers() throws IOException {
- // SM
- setTest("9.9 678");
- assertTrue("Base behavior failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- st.ordinaryChars('0', '9');
- assertEquals("setOrdinary failed.", '6', st.nextToken());
- st.parseNumbers();
- assertTrue("parseNumbers failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#pushBack()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "pushBack",
- args = {}
- )
- public void test_pushBack() throws IOException {
- // SM.
- setTest("Hello 897");
- st.nextToken();
- st.pushBack();
- assertTrue("PushBack failed.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- }
-
- /**
- * @tests java.io.StreamTokenizer#quoteChar(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "quoteChar",
- args = {int.class}
- )
- public void test_quoteCharI() throws IOException {
- // SM
- setTest("<Hello World< HelloWorldH");
- st.quoteChar('<');
- assertEquals("QuoteChar failed.", '<', st.nextToken());
- assertEquals("QuoteChar failed.", "Hello World", st.sval);
- st.quoteChar('H');
- st.nextToken();
- assertEquals("QuoteChar failed for word.", "elloWorld", st.sval
- );
- }
-
- /**
- * @tests java.io.StreamTokenizer#resetSyntax()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "resetSyntax",
- args = {}
- )
- public void test_resetSyntax() throws IOException {
- // SM
- setTest("H 9\' ello World");
- st.resetSyntax();
- assertTrue("resetSyntax failed1." + (char) st.ttype,
- st.nextToken() == 'H');
- assertTrue("resetSyntax failed1." + (char) st.ttype,
- st.nextToken() == ' ');
- assertTrue("resetSyntax failed2." + (char) st.ttype,
- st.nextToken() == '9');
- assertTrue("resetSyntax failed3." + (char) st.ttype,
- st.nextToken() == '\'');
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashCommentsZ() throws IOException {
- // SM.
- setTest("// foo \r\n /fiji \r\n -456");
- st.ordinaryChar('/');
- st.slashSlashComments(true);
- assertEquals("Test failed.", '/', st.nextToken());
- assertTrue("Test failed.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSOpen() throws IOException {
- Reader reader = new CharArrayReader( "t // t t t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(true);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSOpen_NoComment() throws IOException {
- Reader reader = new CharArrayReader( "// t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(true);
- st.ordinaryChar('/');
-
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashSlashComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashSlashComments",
- args = {boolean.class}
- )
- public void test_slashSlashComments_withSSClosed() throws IOException {
- Reader reader = new CharArrayReader( "// t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashSlashComments(false);
- st.ordinaryChar('/');
-
- assertEquals('/',st.nextToken());
- assertEquals('/',st.nextToken());
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarCommentsZ() throws IOException {
- setTest("/* foo \r\n /fiji \r\n*/ -456");
- st.ordinaryChar('/');
- st.slashStarComments(true);
- assertTrue("Test failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarComments_withSTOpen() throws IOException {
- Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashStarComments(true);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#slashStarComments(boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "slashStarComments",
- args = {boolean.class}
- )
- public void test_slashStarComments_withSTClosed() throws IOException {
- Reader reader = new CharArrayReader( "t /* t */ t".toCharArray());
-
- StreamTokenizer st = new StreamTokenizer(reader);
- st.slashStarComments(false);
-
- assertEquals(StreamTokenizer.TT_WORD,st.nextToken());
- assertEquals(StreamTokenizer.TT_EOF,st.nextToken());
- }
-
- /**
- * @tests java.io.StreamTokenizer#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() throws IOException {
- setTest("ABC Hello World");
- st.nextToken();
- assertTrue("toString failed." + st.toString(),
- st.toString().equals(
- "Token[ABC], line 1"));
- }
-
- /**
- * @tests java.io.StreamTokenizer#whitespaceChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "whitespaceChars",
- args = {int.class, int.class}
- )
- public void test_whitespaceCharsII() throws IOException {
- setTest("azbc iof z 893");
- st.whitespaceChars('a', 'z');
- assertTrue("OrdinaryChar failed.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- }
-
- /**
- * @tests java.io.StreamTokenizer#wordChars(int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "wordChars",
- args = {int.class, int.class}
- )
- public void test_wordCharsII() throws IOException {
- setTest("A893 -9B87");
- st.wordChars('0', '9');
- assertTrue("WordChar failed1.",
- st.nextToken() == StreamTokenizer.TT_WORD);
- assertEquals("WordChar failed2.", "A893", st.sval);
- assertTrue("WordChar failed3.",
- st.nextToken() == StreamTokenizer.TT_NUMBER);
- st.nextToken();
- assertEquals("WordChar failed4.", "B87", st.sval);
-
- setTest(" Hello World");
- st.wordChars(' ', ' ');
- st.nextToken();
- assertEquals("WordChars failed for whitespace.", "Hello World", st.sval
- );
-
- setTest(" Hello World\r\n \'Hello World\' Hello\' World");
- st.wordChars(' ', ' ');
- st.wordChars('\'', '\'');
- st.nextToken();
- assertTrue("WordChars failed for whitespace: " + st.sval, st.sval
- .equals("Hello World"));
- st.nextToken();
- assertTrue("WordChars failed for quote1: " + st.sval, st.sval
- .equals("\'Hello World\' Hello\' World"));
- }
-
- private void setTest(String s) {
- testString = s;
- r = new Support_StringReader(testString);
- st = new StreamTokenizer(r);
- }
-
- protected void setUp() {
- }
-
- protected void tearDown() {
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "lineno",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "General functionality of these methods tested in separate tests.",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "toString",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "commentChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "eolIsSignificant",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "lowerCaseMode",
- args = {boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "ordinaryChar",
- args = {int.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "General functionality of these methods tested in separate tests.",
- method = "slashStarComments",
- args = {boolean.class}
- )
- })
- public void test_basicStringTokenizerMethods()
- {
- String str = "Testing 12345 \n alpha \r\n omega";
- String strb = "-3.8 'BLIND mice' \r sEe /* how */ they run";
- StringReader aa = new StringReader(str);
- StringReader ba = new StringReader(strb);
- StreamTokenizer a = new StreamTokenizer(aa);
- StreamTokenizer b = new StreamTokenizer(ba);
-
- try {
- Assert.assertTrue(a.lineno() == 1);
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[Testing], line 1"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_NUMBER);
- Assert.assertTrue(a.toString().equals("Token[n=12345.0], line 1"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[alpha], line 2"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(a.toString().equals("Token[omega], line 3"));
- Assert.assertTrue(a.nextToken() == StreamTokenizer.TT_EOF);
- Assert.assertTrue(a.toString().equals("Token[EOF], line 3"));
-
- b.commentChar('u');
- b.eolIsSignificant(true);
- b.lowerCaseMode(true);
- b.ordinaryChar('y');
- b.slashStarComments(true);
-
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_NUMBER);
- Assert.assertTrue(b.nval == -3.8);
- Assert.assertTrue(b.toString().equals("Token[n=-3.8], line 1"));
- Assert.assertTrue(b.nextToken() == 39); // '
- Assert.assertTrue(b.toString().equals("Token[BLIND mice], line 1"));
- Assert.assertTrue(b.nextToken() == 10); // \n
- Assert.assertTrue(b.toString().equals("Token[EOL], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[see], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[the], line 2"));
- Assert.assertTrue(b.nextToken() == 121); // y
- Assert.assertTrue(b.toString().equals("Token['y'], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_WORD);
- Assert.assertTrue(b.toString().equals("Token[r], line 2"));
- Assert.assertTrue(b.nextToken() == StreamTokenizer.TT_EOF);
- Assert.assertTrue(b.toString().equals("Token[EOF], line 2"));
- }
- catch (Exception ex){
- System.out.println("Exception found in StreamTokenizer");
- ex.printStackTrace();
- throw new RuntimeException("error in test, see stdout");
- }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "toString",
- args = {}
- )
- })
- public void test_harmonyRegressionTest() {
- byte[] data = new byte[] {(byte) '-'};
- StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
- try {
- tokenizer.nextToken();
- } catch(Exception e) {
- Assert.fail(e.getMessage());
- }
- String result = tokenizer.toString();
- Assert.assertEquals("Token['-'], line 1", result);
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nextToken",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "",
- method = "toString",
- args = {}
- )
- })
- public void test_harmonyRegressionTest2() {
- byte[] data = new byte[] {(byte) '"',
- (byte) 'H',
- (byte) 'e',
- (byte) 'l',
- (byte) 'l',
- (byte) 'o',
- (byte) '"'};
- StreamTokenizer tokenizer = new StreamTokenizer(new ByteArrayInputStream(data));
- try {
- tokenizer.nextToken();
- } catch (Exception e) {
- e.printStackTrace();
- }
- String result = tokenizer.toString();
- Assert.assertEquals("Token[Hello], line 1", result);
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java b/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java
deleted file mode 100644
index d82a497..0000000
--- a/luni/src/test/java/tests/api/java/io/StringBufferInputStreamTest.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.StringBufferInputStream;
-
-@TestTargetClass(StringBufferInputStream.class)
-public class StringBufferInputStreamTest extends junit.framework.TestCase {
-
- StringBufferInputStream sbis;
-
- /**
- * @tests java.io.StringBufferInputStream#StringBufferInputStream(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringBufferInputStream",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- new StringBufferInputStream("");
- } catch (Exception ee) {
- fail("Exception " + ee.getMessage() + " does not expected in this case");
- }
- // Test for method java.io.StringBufferInputStream(java.lang.String)
- }
-
- /**
- * @tests java.io.StringBufferInputStream#available()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "available",
- args = {}
- )
- public void test_available() {
- // Test for method int java.io.StringBufferInputStream.available()
- assertEquals("Returned incorrect number of available bytes", 11, sbis
- .available());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII() {
- // Test for method int java.io.StringBufferInputStream.read()
- byte[] buf = new byte[5];
- sbis.skip(6);
- sbis.read(buf, 0, 5);
- assertEquals("Returned incorrect chars", "World", new String(buf));
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read()
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "read",
- args = {byte[].class, int.class, int.class}
- )
- public void test_read$BII_Exception() {
- // Test for method int java.io.StringBufferInputStream.read()
- byte[] buf = new byte[10];
- try {
- sbis.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sbis.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sbis.read(buf, 10, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringBufferInputStream#read(byte[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "read",
- args = {}
- )
- public void test_read() {
- // Test for method int java.io.StringBufferInputStream.read(byte [],
- // int, int)
- assertEquals("Read returned incorrect char", 'H', sbis.read());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.StringBufferInputStream.reset()
- long s = sbis.skip(6);
- assertEquals("Unable to skip correct umber of chars", 6, s);
- sbis.reset();
- assertEquals("Failed to reset", 'H', sbis.read());
- }
-
- /**
- * @tests java.io.StringBufferInputStream#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.StringBufferInputStream.skip(long)
- long s = sbis.skip(6);
- assertEquals("Unable to skip correct umber of chars", 6, s);
- assertEquals("Skip positioned at incorrect char", 'W', sbis.read());
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- sbis = new StringBufferInputStream("Hello World");
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringReaderTest.java b/luni/src/test/java/tests/api/java/io/StringReaderTest.java
deleted file mode 100644
index 4cb8e02..0000000
--- a/luni/src/test/java/tests/api/java/io/StringReaderTest.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.StringReader;
-
-@TestTargetClass(StringReader.class)
-public class StringReaderTest extends junit.framework.TestCase {
-
- String testString = "This is a test string";
-
- StringReader sr;
-
- /**
- * @tests java.io.StringReader#StringReader(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringReader",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- // Test for method java.io.StringReader(java.lang.String)
- try {
- new StringReader("Test string");
- } catch (Exception ee) {
- fail ("Exception " + ee.getMessage() + " does not expected in this case");
- }
- }
-
- /**
- * @tests java.io.StringReader#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.StringReader.close()
- try {
- sr = new StringReader(testString);
- sr.close();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- fail("Close failed");
- } catch (java.io.IOException e) {
- return;
- }
- }
-
- /**
- * @throws IOException
- * @tests java.io.StringReader#mark(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "mark",
- args = {int.class}
- )
- public void test_markI() throws IOException {
- sr = new StringReader(testString);
- sr.skip(5);
- sr.mark(0);
- sr.skip(5);
- sr.reset();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to return to mark", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- try {
- sr.mark(-1);
- fail("IllegalArgumentException not thrown!");
- } catch (IllegalArgumentException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.StringReader#markSupported()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "markSupported",
- args = {}
- )
- public void test_markSupported() {
- // Test for method boolean java.io.StringReader.markSupported()
-
- sr = new StringReader(testString);
- assertTrue("markSupported returned false", sr.markSupported());
- }
-
- /**
- * @tests java.io.StringReader#read()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "read",
- args = {}
- )
- public void test_read() {
- // Test for method int java.io.StringReader.read()
- try {
- sr = new StringReader(testString);
- int r = sr.read();
- assertEquals("Failed to read char", 'T', r);
- sr = new StringReader(new String(new char[] { '\u8765' }));
- assertTrue("Wrong double byte char", sr.read() == '\u8765');
- } catch (Exception e) {
- fail("Exception during read test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#read(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "read",
- args = {char[].class, int.class, int.class}
- )
- public void test_read$CII() throws Exception {
- // Test for method int java.io.StringReader.read(char [], int, int)
- try {
- sr = new StringReader(testString);
- char[] buf = new char[testString.length()];
- int r = sr.read(buf, 0, testString.length());
- assertTrue("Failed to read chars", r == testString.length());
- assertTrue("Read chars incorrectly", new String(buf, 0, r)
- .equals(testString));
- } catch (Exception e) {
- fail("Exception during read test : " + e.getMessage());
- }
-
- char[] buf = new char[testString.length()];
- sr = new StringReader(testString);
- try {
- sr.read(buf, 0, -1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sr.read(buf, -1, 1);
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- sr.read(buf, 1, testString.length());
- fail("IndexOutOfBoundsException was not thrown");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringReader#ready()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "ready",
- args = {}
- )
- public void test_ready() {
- // Test for method boolean java.io.StringReader.ready()
- try {
- sr = new StringReader(testString);
- assertTrue("Steam not ready", sr.ready());
- sr.close();
- int r = 0;
- try {
- sr.ready();
- } catch (IOException e) {
- r = 1;
- }
- assertEquals("Expected IOException not thrown in read()", 1, r);
- } catch (IOException e) {
- fail("IOException during ready test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#reset()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "reset",
- args = {}
- )
- public void test_reset() {
- // Test for method void java.io.StringReader.reset()
- try {
- sr = new StringReader(testString);
- sr.skip(5);
- sr.mark(0);
- sr.skip(5);
- sr.reset();
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to reset properly", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- } catch (Exception e) {
- fail("Exception during reset test : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringReader#skip(long)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "IOException will never be thrown for this implementation.",
- method = "skip",
- args = {long.class}
- )
- public void test_skipJ() {
- // Test for method long java.io.StringReader.skip(long)
- try {
- sr = new StringReader(testString);
- sr.skip(5);
- char[] buf = new char[10];
- sr.read(buf, 0, 2);
- assertTrue("Failed to skip properly", new String(buf, 0, 2)
- .equals(testString.substring(5, 7)));
- } catch (Exception e) {
- fail("Exception during skip test : " + e.getMessage());
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
-
- try {
- sr.close();
- } catch (Exception e) {
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/StringWriterTest.java b/luni/src/test/java/tests/api/java/io/StringWriterTest.java
deleted file mode 100644
index aeb3934..0000000
--- a/luni/src/test/java/tests/api/java/io/StringWriterTest.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-@TestTargetClass(StringWriter.class)
-public class StringWriterTest extends junit.framework.TestCase {
-
- StringWriter sw;
-
- /**
- * @tests java.io.StringWriter#StringWriter()
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringWriter",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "StringWriter",
- args = {int.class}
- )
- })
- public void test_Constructor() {
- new StringWriter();
- new StringWriter(10);
- new StringWriter(10000);
- }
-
- /**
- * @tests java.io.StringWriter#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "There won't be IOException, ever!",
- method = "close",
- args = {}
- )
- public void test_close() {
- // Test for method void java.io.StringWriter.close()
- try {
- sw.close();
- } catch (IOException e) {
- fail("IOException closing StringWriter : " + e.getMessage());
- }
- }
-
- /**
- * @tests java.io.StringWriter#flush()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "flush",
- args = {}
- )
- public void test_flush() {
- // Test for method void java.io.StringWriter.flush()
- sw.flush();
- sw.write('c');
- assertEquals("Failed to flush char", "c", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#getBuffer()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getBuffer",
- args = {}
- )
- public void test_getBuffer() {
- // Test for method java.lang.StringBuffer
- // java.io.StringWriter.getBuffer()
-
- sw.write("This is a test string");
- StringBuffer sb = sw.getBuffer();
- assertEquals("Incorrect buffer returned",
- "This is a test string", sb.toString());
- }
-
- /**
- * @tests java.io.StringWriter#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- // Test for method java.lang.String java.io.StringWriter.toString()
- sw.write("This is a test string");
- assertEquals("Incorrect string returned",
- "This is a test string", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(char[], int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII() {
- // Test for method void java.io.StringWriter.write(char [], int, int)
- char[] c = new char[1000];
- "This is a test string".getChars(0, 21, c, 0);
- sw.write(c, 4, 14);
- assertEquals("Chars not written properly",
- " is a test str", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(char[], int, int)
- * Regression for HARMONY-387
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class, int.class, int.class}
- )
- public void test_write$CII_Exception() {
- StringWriter obj = new StringWriter();
- try {
- obj.write(new char[10], 0, -1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- obj.write(new char[10], -1, 1);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
-
- try {
- obj.write(new char[10], 2, 9);
- fail("IndexOutOfBoundsException expected");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- }
-
- /**
- * @tests java.io.StringWriter#write(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() {
- // Test for method void java.io.StringWriter.write(int)
- sw.write('c');
- assertEquals("Char not written properly", "c", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class}
- )
- public void test_writeLjava_lang_String() {
- // Test for method void java.io.StringWriter.write(java.lang.String)
- sw.write("This is a test string");
- assertEquals("String not written properly",
- "This is a test string", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() {
- // Test for method void java.io.StringWriter.write(java.lang.String,
- // int, int)
- sw.write("This is a test string", 2, 2);
- assertEquals("String not written properly", "is", sw.toString());
- }
-
- /**
- * @tests java.io.StringWriter#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testChar);
- assertEquals(String.valueOf(testChar), stringWriter.toString());
- stringWriter.close();
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() throws IOException {
-
- String testString = "My Test String";
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testString);
- assertEquals(String.valueOf(testString), stringWriter.toString());
- stringWriter.close();
- }
-
- /**
- * @tests java.io.PrintWriter#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class, int.class, int.class}
- )
- public void test_appendCharSequenceIntInt() throws IOException {
- String testString = "My Test String";
- StringWriter stringWriter = new StringWriter(20);
- stringWriter.append(testString, 1, 3);
- assertEquals(testString.substring(1, 3), stringWriter.toString());
- stringWriter.close();
-
- try {
- StringWriter tobj = new StringWriter(9);
- tobj.append("01234567890123456789", 19, 2);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- StringWriter tobj = new StringWriter(9);
- tobj.append("01234567890123456789", 29, 2);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
-
- sw = new StringWriter();
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java b/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java
deleted file mode 100644
index 9ec7c86..0000000
--- a/luni/src/test/java/tests/api/java/io/SyncFailedExceptionTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.SyncFailedException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(SyncFailedException.class)
-public class SyncFailedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.SyncFailedException#SyncFailedException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "SyncFailedException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new SyncFailedException("Something went wrong.");
- fail("Test 1: SyncFailedException expected.");
- } catch (SyncFailedException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java b/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java
deleted file mode 100644
index 8798785..0000000
--- a/luni/src/test/java/tests/api/java/io/UTFDataFormatExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.UTFDataFormatException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(UTFDataFormatException.class)
-public class UTFDataFormatExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.UTFDataFormatException#UTFDataFormatException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UTFDataFormatException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UTFDataFormatException();
- fail("Test 1: UTFDataFormatException expected.");
- } catch (UTFDataFormatException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.UTFDataFormatException#UTFDataFormatException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UTFDataFormatException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UTFDataFormatException("Something went wrong.");
- fail("Test 1: UTFDataFormatException expected.");
- } catch (UTFDataFormatException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java b/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java
deleted file mode 100644
index 7fe4d11..0000000
--- a/luni/src/test/java/tests/api/java/io/UnsupportedEncodingExceptionTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import java.io.UnsupportedEncodingException;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(UnsupportedEncodingException.class)
-public class UnsupportedEncodingExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.UnsupportedEncodingException#UnsupportedEncodingException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UnsupportedEncodingException",
- args = {}
- )
- public void test_Constructor() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UnsupportedEncodingException();
- fail("Test 1: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- assertNull("Test 2: Null expected for exceptions constructed without a message.",
- e.getMessage());
- }
- }
-
- /**
- * @tests java.io.UnsupportedEncodingException#UnsupportedEncodingException(java.lang.String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "UnsupportedEncodingException",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- try {
- if (true) // To avoid unreachable code compilation error.
- throw new UnsupportedEncodingException("Something went wrong.");
- fail("Test 1: UnsupportedEncodingException expected.");
- } catch (UnsupportedEncodingException e) {
- assertEquals("Test 2: Incorrect message;",
- "Something went wrong.", e.getMessage());
- }
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java b/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java
deleted file mode 100644
index 813b1e8..0000000
--- a/luni/src/test/java/tests/api/java/io/WriteAbortedExceptionTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.io;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.IOException;
-import java.io.WriteAbortedException;
-
-@TestTargetClass(WriteAbortedException.class)
-public class WriteAbortedExceptionTest extends junit.framework.TestCase {
-
- /**
- * @tests java.io.WriteAbortedException#WriteAbortedException(java.lang.String,
- * java.lang.Exception)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "WriteAbortedException",
- args = {java.lang.String.class, java.lang.Exception.class}
- )
- public void test_ConstructorLjava_lang_StringLjava_lang_Exception() {
- // Test for method java.io.WriteAbortedException(java.lang.String,
- // java.lang.Exception)
- try {
- if (true)
- throw new WriteAbortedException("HelloWorld",
- new WriteAbortedException("ByeWorld", null));
- } catch (WriteAbortedException e) {
- return;
- }
- fail("Failed to generate expected Exception");
- }
-
- /**
- * @tests java.io.WriteAbortedException#getMessage()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCause",
- args = {}
- )
- public void test_getCause() {
- try {
- if (true) {
- throw new WriteAbortedException("HelloWorld",
- new IOException("Something went wrong."));
- }
- fail("Test 1: WriteAbortedException expected.");
- } catch (WriteAbortedException e) {
- Throwable cause = e.getCause();
- assertTrue("Test 2: Incorrect exception cause: " + cause,
- cause.getClass().equals(IOException.class) &&
- cause.getMessage().equals("Something went wrong."));
- }
- }
-
- /**
- * @tests java.io.WriteAbortedException#getMessage()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getMessage",
- args = {}
- )
- public void test_getMessage() {
- // Test for method java.lang.String
- // java.io.WriteAbortedException.getMessage()
- try {
- if (true)
- throw new WriteAbortedException("HelloWorld",
- new WriteAbortedException("ByeWorld", null));
- } catch (WriteAbortedException e) {
- assertTrue("WriteAbortedException::getMessage() failed"
- + e.getMessage(), e.getMessage().equals(
- "HelloWorld; java.io.WriteAbortedException: ByeWorld"));
- return;
- }
- fail("Failed to generate expected Exception");
- }
-}
diff --git a/luni/src/test/java/tests/api/java/io/WriterTest.java b/luni/src/test/java/tests/api/java/io/WriterTest.java
deleted file mode 100644
index d8ff8b2..0000000
--- a/luni/src/test/java/tests/api/java/io/WriterTest.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.io;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import junit.framework.TestCase;
-import tests.support.Support_ASimpleWriter;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-@TestTargetClass(Writer.class)
-public class WriterTest extends TestCase {
-
- /**
- * @tests java.io.Writer#append(char)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {char.class}
- )
- public void test_appendChar() throws IOException {
- char testChar = ' ';
- MockWriter writer = new MockWriter(20);
- writer.append(testChar);
- assertEquals(String.valueOf(testChar), String.valueOf(writer
- .getContents()));
- writer.close();
-
- Writer tobj = new Support_ASimpleWriter(2);
- tobj.append('a');
- tobj.append('b');
- assertEquals("Wrong stuff written!", "ab", tobj.toString());
- try {
- tobj.append('c');
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "append",
- args = {java.lang.CharSequence.class}
- )
- public void test_appendCharSequence() throws IOException {
- String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString);
- assertEquals(testString, String.valueOf(writer.getContents()));
- writer.close();
-
- Writer tobj = new Support_ASimpleWriter(20);
- tobj.append(testString);
- assertEquals("Wrong stuff written!", testString, tobj.toString());
- try {
- tobj.append(testString);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "append",
- args = {CharSequence.class, int.class, int.class}
- )
- public void test_appendCharSequenceIntInt() throws IOException {
- String testString = "My Test String";
- MockWriter writer = new MockWriter(20);
- writer.append(testString, 1, 3);
- assertEquals(testString.substring(1, 3), String.valueOf(writer
- .getContents()));
- writer.close();
-
- Writer tobj = new Support_ASimpleWriter(21);
- testString = "0123456789abcdefghijABCDEFGHIJ";
- tobj.append(testString, 0, 5);
- assertEquals("Wrong stuff written!", "01234", tobj.toString());
- tobj.append(testString, 10, 15);
- assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
- tobj.append(testString, 20, 30);
- assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
- try {
- tobj.append(testString, 30, 31);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- tobj.append(testString, 20, 21); // Just fill the writer to its limit!
- try {
- tobj.append(testString, 29, 30);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "append",
- args = {CharSequence.class, int.class, int.class}
- )
- public void test_appendCharSequenceIntInt_Exception() throws IOException {
- String testString = "My Test String";
- Writer tobj = new Support_ASimpleWriter(21);
- try {
- tobj.append(testString, 30, 31);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- tobj.append(testString, -1, 1);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- tobj.append(testString, 0, -1);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {char[].class}
- )
- public void test_write$C() throws IOException {
- Writer tobj = new Support_ASimpleWriter(21);
- tobj.write("01234".toCharArray());
- assertEquals("Wrong stuff written!", "01234", tobj.toString());
- tobj.write("abcde".toCharArray());
- assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
- tobj.write("ABCDEFGHIJ".toCharArray());
- assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
- tobj.write("z".toCharArray()); // Just fill the writer to its limit!
- try {
- tobj.write("LES JEUX SONT FAITS".toCharArray());
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {int.class}
- )
- public void test_writeI() throws IOException {
- Writer tobj = new Support_ASimpleWriter(2);
- tobj.write('a');
- tobj.write('b');
- assertEquals("Wrong stuff written!", "ab", tobj.toString());
- try {
- tobj.write('c');
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "write",
- args = {java.lang.String.class}
- )
- public void test_writeLjava_lang_String() throws IOException {
- Writer tobj = new Support_ASimpleWriter(21);
- tobj.write("01234");
- assertEquals("Wrong stuff written!", "01234", tobj.toString());
- tobj.write("abcde");
- assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
- tobj.write("ABCDEFGHIJ");
- assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
- tobj.write("z"); // Just fill the writer to its limit!
- try {
- tobj.write("LES JEUX SONT FAITS");
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.PrintWriter#write(java.lang.String, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII() throws IOException {
- String testString;
- Writer tobj = new Support_ASimpleWriter(21);
- testString = "0123456789abcdefghijABCDEFGHIJ";
- tobj.write(testString, 0, 5);
- assertEquals("Wrong stuff written!", "01234", tobj.toString());
- tobj.write(testString, 10, 5);
- assertEquals("Wrong stuff written!", "01234abcde", tobj.toString());
- tobj.write(testString, 20, 10);
- assertEquals("Wrong stuff written!", "01234abcdeABCDEFGHIJ", tobj.toString());
- try {
- tobj.write(testString, 30, 1);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- tobj.write(testString, 20, 1); // Just fill the writer to its limit!
- try {
- tobj.write(testString, 29, 1);
- fail("IOException not thrown!");
- } catch (IOException e) {
- // expected
- }
- }
-
- /**
- * @tests java.io.Writer#append(CharSequence, int, int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "write",
- args = {String.class, int.class, int.class}
- )
- public void test_writeLjava_lang_StringII_Exception() throws IOException {
- String testString = "My Test String";
- Writer tobj = new Support_ASimpleWriter(21);
- try {
- tobj.write(testString, 30, 31);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- tobj.write(testString, -1, 1);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- try {
- tobj.write(testString, 0, -1);
- fail("IndexOutOfBoundsException not thrown!");
- } catch (IndexOutOfBoundsException e) {
- // expected
- }
- }
-
- class MockWriter extends Writer {
- private char[] contents;
-
- private int length;
-
- private int offset;
-
- MockWriter(int capacity) {
- contents = new char[capacity];
- length = capacity;
- offset = 0;
- }
-
- public synchronized void close() throws IOException {
- flush();
- contents = null;
- }
-
- public synchronized void flush() throws IOException {
- // do nothing
- }
-
- public void write(char[] buffer, int offset, int count)
- throws IOException {
- if (null == contents) {
- throw new IOException();
- }
- if (offset < 0 || count < 0 || offset >= buffer.length) {
- throw new IndexOutOfBoundsException();
- }
- count = Math.min(count, buffer.length - offset);
- count = Math.min(count, this.length - this.offset);
- for (int i = 0; i < count; i++) {
- contents[this.offset + i] = buffer[offset + i];
- }
- this.offset += count;
-
- }
-
- public char[] getContents() {
- char[] result = new char[offset];
- for (int i = 0; i < offset; i++) {
- result[i] = contents[i];
- }
- return result;
- }
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/lang/reflect/ProxyTest.java b/luni/src/test/java/tests/api/java/lang/reflect/ProxyTest.java
index 0eb175e..23d2c10 100644
--- a/luni/src/test/java/tests/api/java/lang/reflect/ProxyTest.java
+++ b/luni/src/test/java/tests/api/java/lang/reflect/ProxyTest.java
@@ -17,7 +17,6 @@
package tests.api.java.lang.reflect;
-import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
@@ -102,38 +101,19 @@ public class ProxyTest extends junit.framework.TestCase {
.isProxyClass(Proxy.getProxyClass(null,
new Class[] { Comparable.class })));
- boolean aborted = false;
-// TODO: We load the test classes in the bootclasspath, so they are visible
-// to the default loader. We can re-enable this test once we move the CTS
-// tests to the system classpath.
-//
-// try {
-// Proxy.getProxyClass(null, new Class[] { Support_Proxy_I1.class,
-// Support_Proxy_I2.class });
-// } catch (IllegalArgumentException e) {
-// aborted = true;
-// }
-// assertTrue("Default classLoader should not see app class ", aborted);
-
- aborted = false;
try {
Proxy.getProxyClass(Support_Proxy_I1.class.getClassLoader(),
(Class<?>[]) null);
fail("NPE expected");
- } catch (NullPointerException e) {
- aborted = true;
+ } catch (NullPointerException expected) {
}
- assertTrue("NPE not thrown", aborted);
- aborted = false;
try {
Proxy.getProxyClass(Support_Proxy_I1.class.getClassLoader(),
new Class<?>[] {Support_Proxy_I1.class, null});
fail("NPE expected");
- } catch (NullPointerException e) {
- aborted = true;
+ } catch (NullPointerException expected) {
}
- assertTrue("NPE not thrown", aborted);
}
/**
diff --git a/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetDecoderTestCase.java b/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetDecoderTestCase.java
deleted file mode 100644
index acae58d..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetDecoderTestCase.java
+++ /dev/null
@@ -1,762 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.nio.charset.UnmappableCharacterException;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(CharsetDecoder.class)
-
-/**
- * Super class for concrete charset test suites.
- */
-public class AbstractCharsetDecoderTestCase extends TestCase {
-
- Charset cs;
-
- // Target decoder (tobj):
- protected static CharsetDecoder decoder;
-
- static final String unistr = " buffer";// \u8000\u8001\u00a5\u3000\r\n";
-
- byte[] unibytes;
-
- String bom = "";
-
-
- protected void setUp() throws Exception {
- super.setUp();
- decoder = cs.newDecoder();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "charset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "detectedCharset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isCharsetDetected",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isAutoDetecting",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "malformedInputAction",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unmappableCharacterAction",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "replacement",
- args = {}
- )
- })
- public void testDefaultValues() {
- assertSame(cs, decoder.charset());
- try {
- decoder.detectedCharset();
- fail("should unsupported");
- } catch (UnsupportedOperationException e) {
- }
- try {
- assertTrue(decoder.isCharsetDetected());
- fail("should unsupported");
- } catch (UnsupportedOperationException e) {
- }
- assertFalse(decoder.isAutoDetecting());
- assertSame(CodingErrorAction.REPORT, decoder.malformedInputAction());
- assertSame(CodingErrorAction.REPORT, decoder
- .unmappableCharacterAction());
- assertEquals(decoder.replacement(), "\ufffd");
- }
-
-
-
- /*
- * test onMalformedInput
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "malformedInputAction",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "onMalformedInput",
- args = {java.nio.charset.CodingErrorAction.class}
- )
- })
- public void testOnMalformedInput() {
- assertSame(CodingErrorAction.REPORT, decoder.malformedInputAction());
- try {
- decoder.onMalformedInput(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- decoder.onMalformedInput(CodingErrorAction.IGNORE);
- assertSame(CodingErrorAction.IGNORE, decoder.malformedInputAction());
- }
-
- /*
- * test unmappableCharacter
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "unmappableCharacterAction",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "onUnmappableCharacter",
- args = {java.nio.charset.CodingErrorAction.class}
- )
- })
- public void testOnUnmappableCharacter() {
- assertSame(CodingErrorAction.REPORT, decoder
- .unmappableCharacterAction());
- try {
- decoder.onUnmappableCharacter(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- assertSame(CodingErrorAction.IGNORE, decoder
- .unmappableCharacterAction());
- }
-
- /*
- * test replaceWith
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "replaceWith",
- args = {java.lang.String.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "replacement",
- args = {}
- )
- })
- public void testReplaceWith() {
- try {
- decoder.replaceWith(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- try {
- decoder.replaceWith("");
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- try {
- decoder.replaceWith("testReplaceWith");
- fail("should throw illegal argument exception");
- } catch (IllegalArgumentException e) {
- }
-
- decoder.replaceWith("a");
- assertSame("a", decoder.replacement());
- }
-
- /*
- * Class under test for CharBuffer decode(ByteBuffer)
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testDecodeByteBuffer() throws CharacterCodingException {
- implTestDecodeByteBuffer();
- }
-
- void implTestDecodeByteBuffer() throws CharacterCodingException {
- // Null pointer
- try {
- decoder.decode(null);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
-
- // empty input buffer
- CharBuffer out = decoder.decode(ByteBuffer.allocate(0));
- assertCharBufferValue(out, "");
-
- // normal case
- ByteBuffer in = ByteBuffer.wrap(getUnibytes());
- out = decoder.decode(in);
- assertEquals(out.position(), 0);
- assertEquals(out.limit(), unistr.length());
- assertEquals(out.remaining(), unistr.length());
- assertEquals(new String(out.array(), 0, out.limit()), unistr);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class}
- )
- public void testDecodeByteBufferException()
- throws CharacterCodingException, UnsupportedEncodingException {
- CharBuffer out;
- ByteBuffer in;
- String replaceStr = decoder.replacement() + " buffer";
-
- // MalformedException:
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- in = getMalformByteBuffer();
- if (in != null) {
- try {
- CharBuffer buffer = decoder.decode(in);
- assertTrue(buffer.remaining() > 0);
- fail("should throw MalformedInputException");
- } catch (MalformedInputException e) {
- }
-
- decoder.reset();
- in.rewind();
- decoder.onMalformedInput(CodingErrorAction.IGNORE);
- out = decoder.decode(in);
- assertCharBufferValue(out, " buffer");
-
- decoder.reset();
- in.rewind();
- decoder.onMalformedInput(CodingErrorAction.REPLACE);
- out = decoder.decode(in);
- assertCharBufferValue(out, replaceStr);
- }
-
- // Unmapped Exception:
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- in = getUnmappedByteBuffer();
- if (in != null) {
- try {
- decoder.decode(in);
- fail("should throw UnmappableCharacterException");
- } catch (UnmappableCharacterException e) {
- }
-
- decoder.reset();
- in.rewind();
- decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- out = decoder.decode(in);
- assertCharBufferValue(out, " buffer");
-
- decoder.reset();
- in.rewind();
- decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- out = decoder.decode(in);
- assertCharBufferValue(out, replaceStr);
- }
-
- // RuntimeException
- try {
- decoder.decode(getExceptionByteArray());
- fail("should throw runtime exception");
- } catch (RuntimeException e) {
- }
- }
-
- /*
- * Class under test for CoderResult decode(ByteBuffer, CharBuffer, boolean)
- */
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- public void testDecodeByteBufferCharBufferboolean() {
- implTestDecodeByteBufferCharBufferboolean();
- }
-
- void implTestDecodeByteBufferCharBufferboolean() {
- byte[] gb = getUnibytes();
- ByteBuffer in = ByteBuffer.wrap(gb);
- CharBuffer out = CharBuffer.allocate(100);
-
- // Null pointer
- try {
- decoder.decode(null, out, true);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
- try {
- decoder.decode(in, null, true);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
-
- // normal case, one complete operation
- decoder.reset();
- in.rewind();
- out.rewind();
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
- assertEquals(out.limit(), 100);
- assertEquals(out.position(), unistr.length());
- assertEquals(out.remaining(), 100 - unistr.length());
- assertEquals(out.capacity(), 100);
- assertCharBufferValue(out, unistr);
- decoder.flush(out);
-
- // normal case, one complete operation, but call twice, first time set
- // endOfInput to false
- decoder.reset();
- in.rewind();
- out.clear();
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
- assertEquals(out.limit(), 100);
- assertEquals(out.position(), unistr.length());
- assertEquals(out.remaining(), 100 - unistr.length());
- assertEquals(out.capacity(), 100);
- assertCharBufferValue(out, unistr);
-
- decoder.reset();
- in.rewind();
- out.clear();
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
- in = ByteBuffer.wrap(unibytes);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
- in.rewind();
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
- assertEquals(out.limit(), 100);
- assertTrue(out.position() > 0);
- assertEquals(out.remaining(), out.capacity() - out.position());
- assertEquals(out.capacity(), 100);
- assertCharBufferValue(out, unistr + unistr + unistr);
-
- // overflow
- out = CharBuffer.allocate(4);
- decoder.reset();
- in = ByteBuffer.wrap(getUnibytes());
- out.rewind();
- assertSame(CoderResult.OVERFLOW, decoder.decode(in, out, false));
-
- assertEquals(new String(out.array()), unistr.substring(0, 4));
- out = CharBuffer.allocate(100);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
- assertCharBufferValue(out, unistr.substring(4));
- in.rewind();
- out = CharBuffer.allocate(100);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
- assertCharBufferValue(out, bom + unistr);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- public void testDecodeCharBufferByteBufferbooleanExceptionTrue()
- throws CharacterCodingException, UnsupportedEncodingException {
- implTestDecodeCharBufferByteBufferbooleanException(true);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- public void testDecodeCharBufferByteBufferbooleanExceptionFalse()
- throws CharacterCodingException, UnsupportedEncodingException {
- implTestDecodeCharBufferByteBufferbooleanException(false);
- }
-
- void implTestDecodeCharBufferByteBufferbooleanException(boolean endOfInput)
- throws CharacterCodingException, UnsupportedEncodingException {
- CharBuffer out;
- ByteBuffer in;
-
- // Unmapped Exception:
- in = getUnmappedByteBuffer();
- out = CharBuffer.allocate(50);
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- if (null != in) {
- decoder.reset();
- decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- CoderResult result = decoder.decode(in, out, endOfInput);
- assertTrue(result.isUnmappable());
-
- decoder.reset();
- out.clear();
- in.rewind();
- decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out,
- endOfInput));
- assertCharBufferValue(out, " buffer");
-
- decoder.reset();
- out.clear();
- in.rewind();
- decoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out,
- endOfInput));
- assertCharBufferValue(out, decoder.replacement() + " buffer");
- } else if (endOfInput) {
- // System.err.println("Cannot find unmappable byte array for "
- // + cs.name());
- }
-
- // MalformedException:
- in = getMalformByteBuffer();
- out = CharBuffer.allocate(50);
- decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- if (null != in) {
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- CoderResult result = decoder.decode(in, out, endOfInput);
- assertTrue(result.isMalformed());
-
- decoder.reset();
- out.clear();
- in.rewind();
- decoder.onMalformedInput(CodingErrorAction.IGNORE);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out,
- endOfInput));
- assertCharBufferValue(out, " buffer");
-
- decoder.reset();
- out.clear();
- in.rewind();
- decoder.onMalformedInput(CodingErrorAction.REPLACE);
- assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out,
- endOfInput));
- assertCharBufferValue(out, decoder.replacement() + " buffer");
- } else if (endOfInput) {
- // System.err.println("Cannot find malform byte array for "
- // + cs.name());
- }
-
- // RuntimeException
- in = getExceptionByteArray();
- try {
- decoder.decode(in, out, endOfInput);
- fail("should throw runtime exception");
- } catch (RuntimeException e) {
- }
- }
-
- ByteBuffer getExceptionByteArray() throws UnsupportedEncodingException {
- // "runtime"
- return ByteBuffer
- .wrap(new byte[] { 114, 117, 110, 116, 105, 109, 101 });
- }
-
- ByteBuffer getUnmappedByteBuffer() throws UnsupportedEncodingException {
- // "unmap buffer"
- byte[] ba = new byte[] { 117, 110, 109, 97, 112, 32, 98, 117, 102, 102,
- 101, 114 };
- return ByteBuffer.wrap(ba);
- }
-
- ByteBuffer getMalformByteBuffer() throws UnsupportedEncodingException {
- // "malform buffer"
- byte[] ba = new byte[] { 109, 97, 108, 102, 111, 114, 109, 32, 98, 117,
- 102, 102, 101, 114 };
- return ByteBuffer.wrap(ba);
- }
-
- void assertCharBufferValue(CharBuffer out, String expected) {
- if (out.position() != 0) {
- out.flip();
- }
- assertEquals(new String(out.array(), 0, out.limit()), expected);
- }
-
- /*
- * test flush
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.CharBuffer.class}
- )
- public void testFlush() throws CharacterCodingException {
- CharBuffer out = CharBuffer.allocate(10);
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 12, 12 });
- decoder.decode(in, out, true);
- assertSame(CoderResult.UNDERFLOW, decoder.flush(out));
-
- decoder.reset();
- decoder.decode((ByteBuffer) in.rewind(), (CharBuffer) out.rewind(),
- true);
- assertSame(CoderResult.UNDERFLOW, decoder
- .flush(CharBuffer.allocate(10)));
- }
-
-
- /*
- * ---------------------------------- methods to test illegal state
- * -----------------------------------
- */
-
- // Normal case: just after reset, and it also means reset can be done
- // anywhere
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- )
- public void testResetIllegalState() throws CharacterCodingException {
- byte[] gb = getUnibytes();
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb));
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb), CharBuffer.allocate(3), false);
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb), CharBuffer.allocate(3), true);
- decoder.reset();
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- )
- })
- public void testFlushIllegalState() throws CharacterCodingException {
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 98, 98 });
- CharBuffer out = CharBuffer.allocate(5);
- // Normal case: after decode with endOfInput is true
- decoder.reset();
- decoder.decode(in, out, true);
- out.rewind();
- CoderResult result = decoder.flush(out);
- assertSame(result, CoderResult.UNDERFLOW);
-
- // Illegal state: flush twice
- try {
- decoder.flush(out);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- }
-
- // Illegal state: flush after decode with endOfInput is false
- decoder.reset();
- decoder.decode(in, out, false);
- try {
- decoder.flush(out);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- }
- }
-
- byte[] getUnibytes() {
- return unibytes;
- }
-
- // test illegal states for decode facade
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- })
- public void testDecodeFacadeIllegalState() throws CharacterCodingException {
- // decode facade can be execute in anywhere
- byte[] gb = getUnibytes();
- ByteBuffer in = ByteBuffer.wrap(gb);
- // Normal case: just created
- decoder.decode(in);
- in.rewind();
-
- // Normal case: just after decode facade
- decoder.decode(in);
- in.rewind();
-
- // Normal case: just after decode with that endOfInput is true
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb), CharBuffer.allocate(30), true);
- decoder.decode(in);
- in.rewind();
-
- // Normal case:just after decode with that endOfInput is false
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb), CharBuffer.allocate(30), false);
- decoder.decode(in);
- in.rewind();
-
- // Normal case: just after flush
- decoder.reset();
- decoder.decode(ByteBuffer.wrap(gb), CharBuffer.allocate(30), true);
- decoder.flush(CharBuffer.allocate(10));
- decoder.decode(in);
- in.rewind();
- }
-
- // test illegal states for two decode method with endOfInput is true
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- public void testDecodeTrueIllegalState() throws CharacterCodingException {
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 98, 98 });
- CharBuffer out = CharBuffer.allocate(100);
- // Normal case: just created
- decoder.decode(in, out, true);
- in.rewind();
- out.rewind();
-
- // Normal case: just after decode with that endOfInput is true
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), true);
- in.rewind();
- decoder.decode(in, out, true);
- in.rewind();
- out.rewind();
-
- // Normal case:just after decode with that endOfInput is false
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), false);
- in.rewind();
- decoder.decode(in, out, true);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after flush
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), true);
- decoder.flush(CharBuffer.allocate(10));
- in.rewind();
- try {
- decoder.decode(in, out, true);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
- in.rewind();
- out.rewind();
-
- }
-
- // test illegal states for two decode method with endOfInput is false
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "decode",
- args = {java.nio.ByteBuffer.class, java.nio.CharBuffer.class, boolean.class}
- )
- public void testDecodeFalseIllegalState() throws CharacterCodingException {
- ByteBuffer in = ByteBuffer.wrap(new byte[] { 98, 98 });
- CharBuffer out = CharBuffer.allocate(5);
- // Normal case: just created
- decoder.decode(in, out, false);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after decode facade
- decoder.reset();
- decoder.decode(in);
- in.rewind();
- try {
- decoder.decode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
- in.rewind();
- out.rewind();
-
- // Illegal state: just after decode with that endOfInput is true
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), true);
- in.rewind();
- try {
- decoder.decode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
- in.rewind();
- out.rewind();
-
- // Normal case:just after decode with that endOfInput is false
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), false);
- in.rewind();
- decoder.decode(in, out, false);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after flush
- decoder.reset();
- decoder.decode(in, CharBuffer.allocate(30), true);
- in.rewind();
- decoder.flush(CharBuffer.allocate(10));
- try {
- decoder.decode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
- }
-
- /*
- * --------------------------------- illegal state test end
- * ---------------------------------
- */
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetEncoderTestCase.java b/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetEncoderTestCase.java
deleted file mode 100644
index 32fa2fe..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/AbstractCharsetEncoderTestCase.java
+++ /dev/null
@@ -1,1048 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CoderResult;
-import java.nio.charset.CodingErrorAction;
-import java.nio.charset.MalformedInputException;
-import java.nio.charset.UnmappableCharacterException;
-import java.nio.charset.UnsupportedCharsetException;
-import java.util.Arrays;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(CharsetEncoder.class)
-
-/**
- * Super class for concrete charset test suites.
- */
-public class AbstractCharsetEncoderTestCase extends TestCase {
-
- Charset cs;
-
- // Target encoder (tobj):
- CharsetEncoder encoder;
-
- static final String unistr = " buffer";// \u8000\u8001\u00a5\u3000\r\n";
-
- byte[] unibytes = new byte[] { 32, 98, 117, 102, 102, 101, 114 };
-
-
- // default for Charset abstract class
- byte[] defaultReplacement = new byte[] { 63 };
-
- // specific for Charset implementation subclass
- byte[] specifiedReplacement = new byte[] { 26 };
-
- byte[] unibytesWithRep = null;
-
- byte[] surrogate = new byte[0];
-
-
- protected void setUp() throws Exception {
- super.setUp();
- encoder = cs.newEncoder();
- if (null == unibytesWithRep) {
- byte[] replacement = encoder.replacement();
- unibytesWithRep = new byte[replacement.length + unibytes.length];
- System.arraycopy(replacement, 0, unibytesWithRep, 0,
- replacement.length);
- System.arraycopy(unibytes, 0, unibytesWithRep, replacement.length,
- unibytes.length);
- }
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-
- /*
- * Class under test for boolean canEncode(char)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- )
- public void testCanEncodechar() throws CharacterCodingException {
- // for non-mapped char
- assertTrue(encoder.canEncode('\uc2c0'));
- // surrogate char for unicode
- // 1st byte: d800-dbff
- // 2nd byte: dc00-dfff
- assertTrue(encoder.canEncode('\ud800'));
- // valid surrogate pair
- assertTrue(encoder.canEncode('\udc00'));
- }
-
- /*-----------------------------------------
- * Class under test for illegal state case
- * methods which can change internal states are two encode, flush, two canEncode, reset
- * -----------------------------------------
- */
-
- // Normal case: just after reset, and it also means reset can be done
- // anywhere
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- )
- })
- public void testResetIllegalState() throws CharacterCodingException {
- assertSame(encoder, encoder.reset());
- encoder.canEncode('\ud901');
- assertSame(encoder, encoder.reset());
- encoder.canEncode("\ud901\udc00");
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("aaa"));
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("aaa"), ByteBuffer.allocate(3), false);
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("aaa"), ByteBuffer.allocate(3), true);
- assertSame(encoder, encoder.reset());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testFlushIllegalState() throws CharacterCodingException {
- CharBuffer in = CharBuffer.wrap("aaa");
- ByteBuffer out = ByteBuffer.allocate(5);
-
- // Normal case: after encode with endOfInput is true
- assertSame(encoder, encoder.reset());
- encoder.encode(in, out, true);
- out.rewind();
- CoderResult result = encoder.flush(out);
-
- // Illegal state: flush twice
- try {
- encoder.flush(out);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- }
-
- // Illegal state: flush after encode with endOfInput is false
- assertSame(encoder, encoder.reset());
- encoder.encode(in, out, false);
- try {
- encoder.flush(out);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- }
- }
-
- // test illegal states for encode facade
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testEncodeFacadeIllegalState() throws CharacterCodingException {
- // encode facade can be execute in anywhere
- CharBuffer in = CharBuffer.wrap("aaa");
- // Normal case: just created
- encoder.encode(in);
- in.rewind();
-
- // Normal case: just after encode facade
- encoder.encode(in);
- in.rewind();
-
- // Normal case: just after canEncode
- assertSame(encoder, encoder.reset());
- encoder.canEncode("\ud902\udc00");
- encoder.encode(in);
- in.rewind();
- assertSame(encoder, encoder.reset());
- encoder.canEncode('\ud902');
- encoder.encode(in);
- in.rewind();
-
- // Normal case: just after encode with that endOfInput is true
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState2"),
- ByteBuffer.allocate(30), true);
- encoder.encode(in);
- in.rewind();
-
- // Normal case:just after encode with that endOfInput is false
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState3"),
- ByteBuffer.allocate(30), false);
- encoder.encode(in);
- in.rewind();
-
- // Normal case: just after flush
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState4"),
- ByteBuffer.allocate(30), true);
- encoder.flush(ByteBuffer.allocate(10));
- encoder.encode(in);
- in.rewind();
- }
-
- // test illegal states for two encode method with endOfInput is true
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testEncodeTrueIllegalState() throws CharacterCodingException {
- CharBuffer in = CharBuffer.wrap("aaa");
- ByteBuffer out = ByteBuffer.allocate(5);
- // Normal case: just created
- encoder.encode(in, out, true);
- in.rewind();
- out.rewind();
-
- in.rewind();
- out.rewind();
-
- // Normal case: just after encode with that endOfInput is true
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState2"),
- ByteBuffer.allocate(30), true);
- encoder.encode(in, out, true);
- in.rewind();
- out.rewind();
-
- // Normal case:just after encode with that endOfInput is false
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState3"),
- ByteBuffer.allocate(30), false);
- encoder.encode(in, out, true);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after flush
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState4"),
- ByteBuffer.allocate(30), true);
- encoder.flush(ByteBuffer.allocate(10));
- try {
- encoder.encode(in, out, true);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
-
- // Normal case: after canEncode
- assertSame(encoder, encoder.reset());
- encoder.canEncode("\ud906\udc00");
- encoder.encode(in, out, true);
- in.rewind();
- out.rewind();
- assertSame(encoder, encoder.reset());
- encoder.canEncode('\ud905');
- encoder.encode(in, out, true);
- }
-
- // test illegal states for two encode method with endOfInput is false
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testEncodeFalseIllegalState() throws CharacterCodingException {
- CharBuffer in = CharBuffer.wrap("aaa");
- ByteBuffer out = ByteBuffer.allocate(5);
- // Normal case: just created
- encoder.encode(in, out, false);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after encode facade
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState1"));
- try {
- encoder.encode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
-
- // Illegal state: just after encode with that endOfInput is true
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState2"),
- ByteBuffer.allocate(30), true);
- try {
- encoder.encode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
-
- // Normal case:just after encode with that endOfInput is false
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState3"),
- ByteBuffer.allocate(30), false);
- encoder.encode(in, out, false);
- in.rewind();
- out.rewind();
-
- // Illegal state: just after flush
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState4"),
- ByteBuffer.allocate(30), true);
- encoder.flush(ByteBuffer.allocate(10));
- try {
- encoder.encode(in, out, false);
- fail("should illegal state");
- } catch (IllegalStateException e) {
- }
-
- // Normal case: after canEncode
- assertSame(encoder, encoder.reset());
- encoder.canEncode("\ud906\udc00");
- encoder.encode(in, out, false);
- in.rewind();
- out.rewind();
- assertSame(encoder, encoder.reset());
- encoder.canEncode('\ud905');
- encoder.encode(in, out, false);
- }
-
- // test illegal states for two canEncode methods
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {char.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "reset",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "flush",
- args = {java.nio.ByteBuffer.class}
- )
- })
- public void testCanEncodeIllegalState() throws CharacterCodingException {
- // Normal case: just created
- encoder.canEncode("\ud900\udc00");
- encoder.canEncode('\ud900');
-
- // Illegal state: just after encode with that endOfInput is true
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState2"),
- ByteBuffer.allocate(30), true);
- try {
- encoder.canEncode("\ud903\udc00");
- fail("should throw illegal state exception");
- } catch (IllegalStateException e) {
- }
-
- // Illegal state:just after encode with that endOfInput is false
- assertSame(encoder, encoder.reset());
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState3"),
- ByteBuffer.allocate(30), false);
- try {
- encoder.canEncode("\ud904\udc00");
- fail("should throw illegal state exception");
- } catch (IllegalStateException e) {
- }
-
- // Normal case: just after flush
- encoder.encode(CharBuffer.wrap("testCanEncodeIllegalState4"),
- ByteBuffer.allocate(30), true);
- encoder.flush(ByteBuffer.allocate(10));
- encoder.canEncode("\ud905\udc00");
- encoder.canEncode('\ud906');
-
- // Normal case: after reset again
- assertSame(encoder, encoder.reset());
- encoder.canEncode("\ud906\udc00");
- encoder.canEncode('\ud905');
- }
-
- /*
- * --------------------------------- illegal state test end
- * ---------------------------------
- */
-
- /*
- * Class under test for boolean canEncode(CharSequence)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "canEncode",
- args = {java.lang.CharSequence.class}
- )
- public void testCanEncodeCharSequence() {
- // for non-mapped char
- assertTrue(encoder.canEncode("\uc2c0"));
- // surrogate char for unicode
- // 1st byte: d800-dbff
- // 2nd byte: dc00-dfff
- assertTrue(encoder.canEncode("\ud800"));
- // valid surrogate pair
- assertTrue(encoder.canEncode("\ud800\udc00"));
- // invalid surrogate pair
- assertTrue(encoder.canEncode("\ud800\udb00"));
- }
-
-
-
- /*
- * Class under test for ByteBuffer encode(CharBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class}
- )
- public void testEncodeCharBuffer() throws CharacterCodingException {
- // Null pointer
- try {
- encoder.encode(null);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
-
- // empty input buffer
- ByteBuffer out = encoder.encode(CharBuffer.wrap(""));
- assertEquals(out.position(), 0);
- assertByteArray(out, new byte[0]);
- // assertByteArray(out, surrogate);
-
- // normal case
- out = encoder.encode(CharBuffer.wrap(unistr));
- assertEquals(out.position(), 0);
- assertByteArray(out, addSurrogate(unibytes));
-
- // Regression test for harmony-3378
- Charset cs = Charset.forName("UTF-8");
- CharsetEncoder encoder = cs.newEncoder();
- encoder.onMalformedInput(CodingErrorAction.REPLACE);
- encoder = encoder.replaceWith(new byte[] { (byte) 0xef, (byte) 0xbf,
- (byte) 0xbd, });
- CharBuffer in = CharBuffer.wrap("\ud800");
- out = encoder.encode(in);
- assertNotNull(out);
- }
-
- private byte[] addSurrogate(byte[] expected) {
- if (surrogate.length > 0) {
- byte[] temp = new byte[surrogate.length + expected.length];
- System.arraycopy(surrogate, 0, temp, 0, surrogate.length);
- System.arraycopy(expected, 0, temp, surrogate.length,
- expected.length);
- expected = temp;
- }
- return expected;
- }
-
- /**
- * @return
- */
- protected byte[] getEmptyByteArray() {
- return new byte[0];
- }
-
- CharBuffer getMalformedCharBuffer() {
- return CharBuffer.wrap("malform buffer");
- }
-
- CharBuffer getUnmapCharBuffer() {
- return CharBuffer.wrap("unmap buffer");
- }
-
- CharBuffer getExceptionCharBuffer() {
- return CharBuffer.wrap("runtime buffer");
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class}
- )
- public void testEncodeCharBufferException() throws CharacterCodingException {
- ByteBuffer out;
- CharBuffer in;
- // MalformedException:
- in = getMalformedCharBuffer();
- encoder.onMalformedInput(CodingErrorAction.REPORT);
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- if (in != null) {
- try {
- // regression test for Harmony-1379
- encoder.encode(in);
- fail("should throw MalformedInputException");
- } catch (MalformedInputException e) {
- }
-
- encoder.reset();
- in.rewind();
- encoder.onMalformedInput(CodingErrorAction.IGNORE);
- out = encoder.encode(in);
- assertByteArray(out, addSurrogate(unibytes));
-
- encoder.reset();
- in.rewind();
- encoder.onMalformedInput(CodingErrorAction.REPLACE);
- out = encoder.encode(in);
- assertByteArray(out, addSurrogate(unibytesWithRep));
- }
-
- // Unmapped Exception:
- in = getUnmapCharBuffer();
- encoder.onMalformedInput(CodingErrorAction.REPORT);
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- if (in != null) {
- encoder.reset();
- try {
- encoder.encode(in);
- fail("should throw UnmappableCharacterException");
- } catch (UnmappableCharacterException e) {
- }
-
- encoder.reset();
- in.rewind();
- encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- out = encoder.encode(in);
- assertByteArray(out, unibytes);
-
- encoder.reset();
- in.rewind();
- encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- out = encoder.encode(in);
- assertByteArray(out, unibytesWithRep);
- }
-
- // RuntimeException
- try {
- encoder.encode(getExceptionCharBuffer());
- fail("should throw runtime exception");
- } catch (RuntimeException e) {
- }
- }
-
- /*
- * utility method, extract given bytebuffer to a string and compare with
- * give string
- */
- void assertByteArray(ByteBuffer out, byte[] expected) {
- out = out.duplicate();
- if (out.position() != 0) {
- out.flip();
- }
- byte[] ba = new byte[out.limit() - out.position()];
- out.get(ba);
- // byte[] ba = out.array();
- assertTrue(Arrays.equals(ba, expected));
- }
-
- /*
- * Class under test for CoderResult encode(CharBuffer, ByteBuffer, boolean)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testEncodeCharBufferByteBufferboolean()
- throws CharacterCodingException {
- ByteBuffer out = ByteBuffer.allocate(200);
- CharBuffer in = CharBuffer.wrap(unistr);
- // Null pointer
- try {
- encoder.encode(null, out, true);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
- try {
- encoder.encode(in, null, true);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
-
- // normal case, one complete operation
- assertSame(encoder, encoder.reset());
- in.rewind();
- out.rewind();
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, true));
- assertEquals(out.limit(), 200);
- assertTrue(out.position() > 0);
- assertTrue(out.remaining() > 0);
- assertEquals(out.capacity(), 200);
- assertByteArray(out, addSurrogate(unibytes));
- in.rewind();
-
- encoder.flush(out);
-
- // normal case, one complete operation, but call twice, first time set
- // endOfInput to false
- assertSame(encoder, encoder.reset());
- in.rewind();
- out = ByteBuffer.allocate(200);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, false));
- assertEquals(out.limit(), 200);
- assertTrue(out.position() > 0);
- assertTrue(out.remaining() > 0);
- assertEquals(out.capacity(), 200);
- assertByteArray(out, addSurrogate(unibytes));
-
- in.rewind();
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, false));
- in.rewind();
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, true));
- assertEquals(out.limit(), 200);
- assertTrue(out.position() > 0);
- assertTrue(out.remaining() > 0);
- assertEquals(out.capacity(), 200);
-
- assertByteArray(out, addSurrogate(duplicateByteArray(unibytes, 3)));
-
- // overflow
- out = ByteBuffer.allocate(4);
- assertSame(encoder, encoder.reset());
- in.rewind();
- out.rewind();
- assertSame(CoderResult.OVERFLOW, encoder.encode(in, out, true));
- assertEquals(out.limit(), 4);
- assertEquals(out.position(), 4);
- assertEquals(out.remaining(), 0);
- assertEquals(out.capacity(), 4);
- ByteBuffer temp = ByteBuffer.allocate(200);
- out.flip();
- temp.put(out);
- out = temp;
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, true));
- assertEquals(out.limit(), 200);
- assertTrue(out.position() > 0);
- assertTrue(out.remaining() > 0);
- assertEquals(out.capacity(), 200);
- assertByteArray(out, addSurrogate(unibytes));
-
- assertSame(encoder, encoder.reset());
- in.rewind();
- out = ByteBuffer.allocate(4);
- assertSame(CoderResult.OVERFLOW, encoder.encode(in, out, false));
- assertEquals(out.limit(), 4);
- assertEquals(out.position(), 4);
- assertEquals(out.remaining(), 0);
- assertEquals(out.capacity(), 4);
- temp = ByteBuffer.allocate(200);
- out.flip();
- temp.put(out);
- out = temp;
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, false));
- assertEquals(out.limit(), 200);
- assertTrue(out.position() > 0);
- assertTrue(out.remaining() > 0);
- assertEquals(out.capacity(), 200);
- assertByteArray(out, addSurrogate(unibytes));
- }
-
- void printByteBuffer(ByteBuffer buffer) {
- System.out.println("print buffer");
- if (buffer.position() != 0) {
- buffer.flip();
- }
- byte[] ba = buffer.array();
- for (int i = 0; i < ba.length; i++) {
- System.out.println(Integer.toHexString(ba[i]));
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testEncodeCharBufferByteBufferbooleanExceptionFalse()
- throws CharacterCodingException {
- implTestEncodeCharBufferByteBufferbooleanException(false);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testEncodeCharBufferByteBufferbooleanExceptionTrue()
- throws CharacterCodingException {
- implTestEncodeCharBufferByteBufferbooleanException(true);
- }
-
- private byte[] duplicateByteArray(byte[] ba, int times) {
- byte[] result = new byte[ba.length * times];
- for (int i = 0; i < times; i++) {
- System.arraycopy(ba, 0, result, i * ba.length, ba.length);
- }
- return result;
- }
-
- protected void implTestEncodeCharBufferByteBufferbooleanException(
- boolean endOfInput) throws CharacterCodingException {
- ByteBuffer out = ByteBuffer.allocate(100);
-
- // MalformedException:
- CharBuffer in = getMalformedCharBuffer();
- encoder.onMalformedInput(CodingErrorAction.REPORT);
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- if (in != null) {
- encoder.reset();
- CoderResult r = encoder.encode(in, out, endOfInput);
- assertTrue(r.isMalformed());
-
- encoder.reset();
- out.clear();
- in.rewind();
- encoder.onMalformedInput(CodingErrorAction.IGNORE);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out,
- endOfInput));
- assertCodingErrorAction(endOfInput, out, in, unibytes);
-
- encoder.reset();
- out.clear();
- in.rewind();
- encoder.onMalformedInput(CodingErrorAction.REPLACE);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out,
- endOfInput));
- assertCodingErrorAction(endOfInput, out, in, unibytesWithRep);
- } else {
- // System.out.println("Cannot find malformed char buffer for "
- // + cs.name());
- }
-
- // Unmapped Exception:
- in = getUnmapCharBuffer();
- encoder.onMalformedInput(CodingErrorAction.REPORT);
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- if (in != null) {
- encoder.reset();
- out.clear();
- assertTrue(encoder.encode(in, out, endOfInput).isUnmappable());
-
- encoder.reset();
- out.clear();
- in.rewind();
- encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out,
- endOfInput));
- assertCodingErrorAction(endOfInput, out, in, unibytes);
-
- encoder.reset();
- out.clear();
- in.rewind();
- encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out,
- endOfInput));
- assertCodingErrorAction(endOfInput, out, in, unibytesWithRep);
- } else {
- // System.out.println("Cannot find unmapped char buffer for "
- // + cs.name());
- }
-
- // RuntimeException
- try {
- encoder.encode(getExceptionCharBuffer());
- fail("should throw runtime exception");
- } catch (RuntimeException e) {
- }
- }
-
- private void assertCodingErrorAction(boolean endOfInput, ByteBuffer out,
- CharBuffer in, byte[] expect) {
- if (endOfInput) {
- assertByteArray(out, addSurrogate(expect));
- } else {
- in.rewind();
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out,
- endOfInput));
- in.rewind();
- assertSame(CoderResult.UNDERFLOW, encoder.encode(in, out, true));
- assertByteArray(out, addSurrogate(duplicateByteArray(expect, 3)));
- }
- }
-
- /*
- * Class under test for CoderResult flush(ByteBuffer)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "encode",
- args = {java.nio.CharBuffer.class, java.nio.ByteBuffer.class, boolean.class}
- )
- public void testFlush() throws CharacterCodingException {
- ByteBuffer out = ByteBuffer.allocate(6);
- CharBuffer in = CharBuffer.wrap("aaa");
- assertEquals(in.remaining(), 3);
-
- // by encode facade, so that internal state will be wrong
- encoder.encode(CharBuffer.wrap("testFlush"), ByteBuffer.allocate(20),
- true);
- assertSame(CoderResult.UNDERFLOW, encoder
- .flush(ByteBuffer.allocate(50)));
- }
-
- /*
- * test isLegalReplacement(byte[])
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isLegalReplacement",
- args = {byte[].class}
- )
- public void testIsLegalReplacement() {
- try {
- encoder.isLegalReplacement(null);
- fail("should throw null pointer exception");
- } catch (NullPointerException e) {
- }
- assertTrue(encoder.isLegalReplacement(specifiedReplacement));
-
- assertTrue(encoder.isLegalReplacement(new byte[200]));
- byte[] ba = getIllegalByteArray();
- if (ba != null) {
- assertFalse(encoder.isLegalReplacement(ba));
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "isLegalReplacement",
- args = {byte[].class}
- )
- public void testIsLegalReplacementEmptyArray() {
- // ISO, ASC, GB, UTF8 encoder will throw exception in RI
- // others will pass
- // try {
- assertTrue(encoder.isLegalReplacement(new byte[0]));
- // fail("should throw ArrayIndexOutOfBoundsException");
- // } catch (ArrayIndexOutOfBoundsException e) {
- // }
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onMalformedInput",
- args = {java.nio.charset.CodingErrorAction.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "malformedInputAction",
- args = {}
- )
- })
- public void testOnMalformedInput() {
- assertSame(CodingErrorAction.REPORT, encoder.malformedInputAction());
- try {
- encoder.onMalformedInput(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- encoder.onMalformedInput(CodingErrorAction.IGNORE);
- assertSame(CodingErrorAction.IGNORE, encoder.malformedInputAction());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "onUnmappableCharacter",
- args = {java.nio.charset.CodingErrorAction.class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "unmappableCharacterAction",
- args = {}
- )
- })
- public void testOnUnmappableCharacter() {
- assertSame(CodingErrorAction.REPORT, encoder
- .unmappableCharacterAction());
- try {
- encoder.onUnmappableCharacter(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
- assertSame(CodingErrorAction.IGNORE, encoder
- .unmappableCharacterAction());
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "replaceWith",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "replacement",
- args = {}
- )
- })
- public void testReplacement() {
- try {
- encoder.replaceWith(null);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- try {
- encoder.replaceWith(new byte[0]);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- try {
- encoder.replaceWith(new byte[100]);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
-
- byte[] nr = getLegalByteArray();
- assertSame(encoder, encoder.replaceWith(nr));
- assertSame(nr, encoder.replacement());
-
- nr = getIllegalByteArray();
- try {
- encoder.replaceWith(new byte[100]);
- fail("should throw null pointer exception");
- } catch (IllegalArgumentException e) {
- }
- }
-
- protected byte[] getLegalByteArray() {
- return new byte[] { 'a' };
- }
-
- protected byte[] getIllegalByteArray() {
- return new byte[155];
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/AllTests.java b/luni/src/test/java/tests/api/java/nio/charset/AllTests.java
deleted file mode 100644
index d965612..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/AllTests.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2007 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.nio.charset;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All tests for package tests.api.java.nio.charset;");
-
- suite.addTestSuite(Charset_MultiByte_EUC_KR.class);
- suite.addTestSuite(Charset_MultiByte_UTF_8.class);
- suite.addTestSuite(Charset_MultiByte_UTF_16BE.class);
- suite.addTestSuite(Charset_MultiByte_UTF_16LE.class);
-
-// suite.addTestSuite(Charset_MultiByte_UTF_16.class);
- suite.addTestSuite(Charset_MultiByte_UTF_16_Android.class);
-// suite.addTestSuite(Charset_MultiByte_EUC_JP.class);
- suite.addTestSuite(Charset_MultiByte_EUC_JP_Android.class);
- suite.addTestSuite(Charset_MultiByte_ISO_2022_JP.class); // IS HIDDENLY MAPPED TO ASCII OR WHAT?!?
-// suite.addTestSuite(Charset_MultiByte_ISO_2022_JP_Android.class); // IS HIDDENLY MAPPED TO ASCII OR WHAT?!?
-
-// suite.addTestSuite(Charset_MultiByte_Big5.class);
- suite.addTestSuite(Charset_MultiByte_Big5_Android.class);
- suite.addTestSuite(Charset_MultiByte_x_windows_950.class); // IS MAPPED TO Big5!!!
-// suite.addTestSuite(Charset_MultiByte_x_windows_950_Android.class); // IS MAPPED TO Big5!!!
-
-// suite.addTestSuite(Charset_MultiByte_GBK.class);
- suite.addTestSuite(Charset_MultiByte_GBK_Android.class);
- suite.addTestSuite(Charset_MultiByte_GB2312.class); // IS HIDDENLY MAPPED TO ASCII OR WHAT?!?
-// suite.addTestSuite(Charset_MultiByte_GB2312_Android.class); // IS MAPPED TO GBK!!!
-
- suite.addTestSuite(Charset_SingleByte_US_ASCII.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_1.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_2.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_3.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_4.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_5.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_6.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_7.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_8.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_9.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_11.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_13.class);
- suite.addTestSuite(Charset_SingleByte_ISO_8859_15.class);
- suite.addTestSuite(Charset_SingleByte_IBM864.class);
- suite.addTestSuite(Charset_SingleByte_x_IBM874.class);
- suite.addTestSuite(Charset_SingleByte_windows_1250.class);
- suite.addTestSuite(Charset_SingleByte_windows_1251.class);
- suite.addTestSuite(Charset_SingleByte_windows_1252.class);
- suite.addTestSuite(Charset_SingleByte_windows_1253.class);
- suite.addTestSuite(Charset_SingleByte_windows_1254.class);
- suite.addTestSuite(Charset_SingleByte_windows_1255.class);
- suite.addTestSuite(Charset_SingleByte_windows_1256.class);
- suite.addTestSuite(Charset_SingleByte_windows_1257.class);
- suite.addTestSuite(Charset_SingleByte_windows_1258.class);
- suite.addTestSuite(Charset_SingleByte_KOI8_R.class);
-
- // NOT SUPPORTED BY RI:
- suite.addTestSuite(Charset_ISO_8859_10.class);
- suite.addTestSuite(Charset_ISO_8859_14.class);
- suite.addTestSuite(Charset_ISO_8859_16.class);
- suite.addTestSuite(Charset_macintosh.class);
- suite.addTestSuite(Charset_GSM0338.class);
-
- suite.addTestSuite(CharsetEncoderDecoderBufferTest.class);
-
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/CharsetEncoderDecoderBufferTest.java b/luni/src/test/java/tests/api/java/nio/charset/CharsetEncoderDecoderBufferTest.java
deleted file mode 100644
index 5e4c3d0..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/CharsetEncoderDecoderBufferTest.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.nio.charset;
-
-import junit.framework.TestCase;
-
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestLevel;
-
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-
-
-/* See bug 1844104.
- * Checks for ICU encoder/decoder buffer corruption.
- */
-@TestTargetClass(CharsetDecoder.class)
-public class CharsetEncoderDecoderBufferTest extends TestCase {
-
- /* Checks for a buffer corruption that happens in ICU
- * (CharsetDecoderICU) when a decode operation
- * is done first with an out-buffer with hasArray()==true, and next with an out-buffer with
- * hasArray()==false. In that situation ICU may overwrite the first out-buffer.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {}
- )
- })
- public void testDecoderOutputBuffer() {
- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
-
- char[] cBuf = new char[10];
- CharBuffer out = CharBuffer.wrap(cBuf);
- assertTrue(out.hasArray());
- decoder.decode(ByteBuffer.wrap(new byte[]{(byte)'a', (byte)'b', (byte)'c', (byte)'d'}),
- out, false);
-
- assertEquals("abcd", new String(cBuf, 0, 4));
- assertEquals(0, cBuf[4]);
- assertEquals(0, cBuf[5]);
-
- byte[] bBuf = new byte[10];
- out = ByteBuffer.wrap(bBuf).asCharBuffer();
- assertFalse(out.hasArray());
- decoder.decode(ByteBuffer.wrap(new byte[]{(byte)'x'}), out, true);
-
- assertEquals('x', bBuf[1]);
- assertEquals(0, bBuf[3]);
-
- // check if the first buffer was corrupted by the second decode
- assertEquals("abcd", new String(cBuf, 0, 4));
- assertEquals(0, cBuf[4]);
- assertEquals(0, cBuf[5]);
- }
-
- /* Checks for a buffer corruption that happens in ICU
- * (CharsetDecoderICU) when a decode operation
- * is done first with an in-buffer with hasArray()==true, and next with an in-buffer with
- * hasArray()==false. In that situation ICU may overwrite the array of the first in-buffer.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "decode",
- args = {}
- )
- })
- public void testDecoderInputBuffer() {
- CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
- CharBuffer out = CharBuffer.wrap(new char[10]);
-
- byte[] inArray = {(byte)'a', (byte)'b'};
- ByteBuffer inWithArray = ByteBuffer.wrap(inArray);
- assertTrue(inWithArray.hasArray());
- decoder.decode(inWithArray, out, false);
- assertEquals('a', inArray[0]);
- assertEquals('b', inArray[1]);
-
- ByteBuffer inWithoutArray = ByteBuffer.allocateDirect(1);
- inWithoutArray.put(0, (byte)'x');
- assertFalse(inWithoutArray.hasArray());
- decoder.decode(inWithoutArray, out, true);
-
- // check whether the first buffer was corrupted by the second decode
- assertEquals('a', inArray[0]);
- assertEquals('b', inArray[1]);
- }
-
- /* Checks for a buffer corruption that happens in ICU
- * (CharsetEncoderICU) when an encode operation
- * is done first with an out-buffer with hasArray()==true, and next with an out-buffer with
- * hasArray()==false. In that situation ICU may overwrite the first out-buffer.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "encode",
- args = {}
- )
- })
- public void testEncoderOutputBuffer() {
- CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
-
- byte[] buffer = new byte[10];
- ByteBuffer out = ByteBuffer.wrap(buffer);
-
- assertTrue(out.hasArray());
- encoder.encode(CharBuffer.wrap("ab"), out, false);
-
- assertEquals('a', buffer[0]);
- assertEquals('b', buffer[1]);
- assertEquals(0, buffer[2]);
-
- out = ByteBuffer.allocateDirect(10);
- assertFalse(out.hasArray());
- encoder.encode(CharBuffer.wrap("x"), out, true);
-
- // check whether the second decode corrupted the first buffer
- assertEquals('a', buffer[0]);
- assertEquals('b', buffer[1]);
- assertEquals(0, buffer[2]);
- }
-
- /* Checks for a buffer corruption that happens in ICU
- * (CharsetEncoderICU) when an encode operation
- * is done first with an in-buffer with hasArray()==true, and next with an in-buffer with
- * hasArray()==false. In that situation ICU may overwrite the array of the first in-buffer.
- */
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "encode",
- args = {}
- )
- })
- public void testEncoderInputBuffer() {
- CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
- ByteBuffer out = ByteBuffer.wrap(new byte[10]);
-
- char[] inArray = {'a', 'b'};
- CharBuffer inWithArray = CharBuffer.wrap(inArray);
- assertTrue(inWithArray.hasArray());
- encoder.encode(inWithArray, out, false);
-
- assertEquals('a', inArray[0]);
- assertEquals('b', inArray[1]);
-
- CharBuffer inWithoutArray = CharBuffer.wrap("x");
- assertFalse(inWithoutArray.hasArray());
- encoder.encode(inWithoutArray, out, true);
-
- // check whether the second decode corrupted the first buffer
- assertEquals('a', inArray[0]);
- assertEquals('b', inArray[1]);
- }
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_AbstractTest.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_AbstractTest.java
deleted file mode 100644
index 386d5c5..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_AbstractTest.java
+++ /dev/null
@@ -1,342 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-import java.util.Arrays;
-
-/**
- * Super class for concrete charset test suites.
- */
-public class Charset_AbstractTest extends TestCase {
-
- static String charsetName;
- static private Charset charset;
- static CharsetDecoder decoder;
- static CharsetEncoder encoder;
-
- static final int[] codes = Charset_TestGenerator.codes;
-
- static final char[] chars = new char[codes.length]; // Is filled with
- // contents of codes.
-
- static char[] testChars;
- static byte[] testBytes;
-
- static char[] theseChars (int[] codes) {
- char[] chars = new char[codes.length];
- for (int i = 0; i < codes.length; i++) chars[i] = (char) codes[i];
- return chars;
- }
-
- static byte[] theseBytes (int[] codes) {
- byte[] bytes = new byte[codes.length];
- for (int i = 0; i < codes.length; i++) bytes[i] = (byte) codes[i];
- return bytes;
- }
-
-
- @Override
- protected void setUp() throws Exception {
- charset = charset.forName(charsetName);
- decoder = charset.newDecoder();
- encoder = charset.newEncoder();
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_nameMatch () {
- assertEquals("Name of charset must match!", charsetName, charset.name());
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_dumpEncodableChars () {
- if (testChars == null) return;
- if (testChars.length > 0) return;
- System.out.format("\ntest_dumpEncodableChars() for name %s => %s (class = %s)\n",
- charsetName, charset.name(), getClass().getName());
- Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1(16);
- int code = 0;
- while (code < 256) {
- while (!encoder.canEncode((char) code)) code ++;
- if (code < 65536) {
- out.consume(code);
- code += 1;
- }
- }
- while (code < 65536) {
- while (!encoder.canEncode((char) code)) code ++;
- if (code < 65536) {
- out.consume(code);
- code += 20;
- }
- }
- System.out.println();
- System.out.println("Encodable Chars dumped for Test Class " + getClass().getName());
- fail("Encodable Chars dumped for Test Class " + getClass().getName());
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_dumpEncoded () throws CharacterCodingException {
- if (testChars == null) return;
- if (testChars.length == 0) return;
- if (testBytes.length > 0) return;
- System.out.format("\ntest_dumpEncoded() for name %s => %s (class = %s)\n",
- charsetName, charset.name(), getClass().getName());
- Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1();
- CharBuffer inputCB = CharBuffer.wrap(testChars);
- ByteBuffer outputBB;
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- outputBB = encoder.encode(inputCB);
- outputBB.rewind();
- while (outputBB.hasRemaining()) {
- out.consume(outputBB.get() & 0xff);
- }
- System.out.println();
- System.out.println("Encoded Bytes dumped for Test Class " + getClass().getName());
- fail("Encoded Bytes dumped for Test Class " + getClass().getName());
- }
-
-
- static void decode (byte[] input, char[] expectedOutput) throws CharacterCodingException {
- ByteBuffer inputBB = ByteBuffer.wrap(input);
- CharBuffer outputCB;
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- outputCB = decoder.decode(inputBB);
- outputCB.rewind();
-
-// assertTrue("Decoded charactes must match!",
-// Arrays.equals(expectedOutput, outputCB.array()));
- assertEqualChars("Decoded charactes must match!",
- expectedOutput, outputCB);
-
-// assertEqualChars2("Decoded charactes must match!",
-// expectedOutput,
-// outputCB.array(),
-// input);
-// assertTrue("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
-// Arrays.equals(expectedOutput, outputCB.array()));
-
-// assertEqualChars("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
-// expectedOutput,
-// outputCB.array());
-
-// assertEquals("Decoded charactes must match!",
-// String.valueOf(allChars),
-// outputCB.toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_Decode () throws CharacterCodingException {
- decode(testBytes, testChars);
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_Encode () throws CharacterCodingException {
- CharBuffer inputCB = CharBuffer.wrap(testChars);
- ByteBuffer outputBB;
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- outputBB = encoder.encode(inputCB);
- outputBB.rewind();
-// assertTrue("Encoded bytes must match!",
-// Arrays.equals(testBytes, outputBB.array()));
- assertEqualBytes("Encoded bytes must match!", testBytes, outputBB);
- }
-
-
- public void NNtest_CodecDynamicIndividuals () throws CharacterCodingException {
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- decoder.onMalformedInput(CodingErrorAction.REPORT);
-
- for (int code = 32; code <= 65533; code ++) {
- if (encoder.canEncode((char) code)) {
-// inputCB.rewind();
- CharBuffer inputCB = CharBuffer.allocate(1);
- inputCB.put((char) code);
- inputCB.rewind();
- ByteBuffer intermediateBB = encoder.encode(inputCB);
- inputCB.rewind();
- intermediateBB.rewind();
- try {
- CharBuffer outputCB = decoder.decode(intermediateBB);
- outputCB.rewind();
- assertEqualCBs("decode(encode(A)) must be identical with A = " + code,
- inputCB, outputCB);
- if (code == 165) {
- outputCB.rewind();
- System.out.println("WOW:" + outputCB.get());
- }
- } catch (CharacterCodingException e) {
- fail("failed to decode(encode(" + code + "))");
- }
- }
- }
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public void test_CodecDynamic () throws CharacterCodingException {
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- CharBuffer inputCB = CharBuffer.allocate(65536);
- for (int code = 32; code <= 65533; code ++) {
- if (encoder.canEncode((char) code)) {
- inputCB.put((char) code);
- }
- }
- inputCB.rewind();
- ByteBuffer intermediateBB = encoder.encode(inputCB);
- inputCB.rewind();
- intermediateBB.rewind();
- CharBuffer outputCB = decoder.decode(intermediateBB);
- outputCB.rewind();
- assertEqualCBs("decode(encode(A)) must be identical with A!",
- inputCB, outputCB);
- }
-
- static void assertEqualCBs (String msg, CharBuffer expectedCB, CharBuffer actualCB) {
- boolean match = true;
- boolean lenMatch = true;
- char expected, actual;
- int len = actualCB.length();
- if (expectedCB.length() != len) {
- lenMatch = false;
- if (expectedCB.length() < len) len = expectedCB.length();
- }
- for (int i = 0; i < len; i++) {
- expected = expectedCB.get();
- actual = actualCB.get();
- if (actual != expected) {
- String detail = String.format(
- "Mismatch at index %d: %d instead of expected %d.\n",
- i, (int) actual, (int) expected);
- match = false;
- fail(msg + ": " + detail);
- }
-// else {
-// System.out.format("Match index %d: %d = %d\n",
-// i, (int) actual[i], (int) expected[i]);
-// }
- }
- assertTrue(msg, match);
- assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
-// assertTrue(msg, Arrays.equals(actual, expected));
- }
-
- static void assertEqualChars (String msg, char[] expected, CharBuffer actualCB) {
- boolean match = true;
- boolean lenMatch = true;
- char actual;
- int len = actualCB.length();
- if (expected.length != len) {
- lenMatch = false;
- if (expected.length < len) len = expected.length;
- }
- for (int i = 0; i < len; i++) {
- actual = actualCB.get();
- if (actual != expected[i]) {
- String detail = String.format(
- "Mismatch at index %d: %d instead of expected %d.\n",
- i, (int) actual, (int) expected[i]);
- match = false;
- fail(msg + ": " + detail);
- }
-// else {
-// System.out.format("Match index %d: %d = %d\n",
-// i, (int) actual[i], (int) expected[i]);
-// }
- }
- assertTrue(msg, match);
- assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
-// assertTrue(msg, Arrays.equals(actual, expected));
- }
-
- static void assertEqualBytes (String msg, byte[] expected, ByteBuffer actualBB) {
- boolean match = true;
- boolean lenMatch = true;
- byte actual;
- int len = actualBB.remaining();
- if (expected.length != len) {
- lenMatch = false;
- if (expected.length < len) len = expected.length;
- }
- for (int i = 0; i < len; i++) {
- actual = actualBB.get();
- if (actual != expected[i]) {
- String detail = String.format(
- "Mismatch at index %d: %d instead of expected %d.\n",
- i, actual & 0xff, expected[i] & 0xff);
- match = false;
- fail(msg + ": " + detail);
- }
- }
- assertTrue(msg, match);
- assertTrue(msg + "(IN LENGTH ALSO!)", lenMatch);
- }
-
-
- static abstract class CodesGenerator {
- int row = 0, col = 0;
-
- abstract void consume(int code);
-
- boolean isAccepted(int code) {
- return Character.isLetterOrDigit(code);
- }
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_GSM0338.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_GSM0338.java
deleted file mode 100644
index 977d4d7..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_GSM0338.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-@AndroidOnly("gsm specific")
-public class Charset_GSM0338 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
-// charsetName = "GSM0338";
- charsetName = "x-gsm-03.38-2000";
-
- testChars = theseChars(new int[]{
-10, 13, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
-46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
-62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
-78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 95, 97, 98,
-99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
-115, 116, 117, 118, 119, 120, 121, 122, 161, 163, 164, 165, 167, 191, 196, 197,
-198, 201, 209, 214, 216, 220, 223, 224, 228, 229, 230, 231, 232, 233, 236, 241,
-242, 246, 248, 249, 252, 915, 916
- });
-
- testBytes = theseBytes(new int[]{
-10, 13, 32, 33, 34, 35, 2, 37, 38, 39, 40, 41, 42, 43, 44, 45,
-46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
-62, 63, 0, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
-78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 17, 97, 98,
-99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
-115, 116, 117, 118, 119, 120, 121, 122, 64, 1, 36, 3, 95, 96, 91, 14,
-28, 31, 93, 92, 11, 94, 30, 127, 123, 15, 29, 9, 4, 5, 7, 125,
-8, 124, 12, 6, 126, 19, 16
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.SUFFICIENT,
- notes = "Not applicable to this charset.",
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic () throws CharacterCodingException {
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_10.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_10.java
deleted file mode 100644
index 051e72d..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_10.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargetClass;
-
-@AndroidOnly("icu")
-public class Charset_ISO_8859_10 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-10";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 167, 173, 176, 183, 193, 194, 195, 196, 197, 198, 201, 203, 205, 206, 207,
-208, 211, 212, 213, 214, 216, 218, 219, 220, 221, 222, 223, 225, 226, 227, 228,
-229, 230, 233, 235, 237, 238, 239, 240, 243, 244, 245, 246, 248, 250, 251, 252,
-253, 254, 256, 257, 290, 325, 358, 8213
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 167, 173, 176, 183, 193, 194, 195, 196, 197, 198, 201, 203, 205, 206, 207,
-208, 211, 212, 213, 214, 216, 218, 219, 220, 221, 222, 223, 225, 226, 227, 228,
-229, 230, 233, 235, 237, 238, 239, 240, 243, 244, 245, 246, 248, 250, 251, 252,
-253, 254, 192, 224, 163, 209, 171, 189
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_14.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_14.java
deleted file mode 100644
index a53fbc9..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_14.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-@AndroidOnly("icu")
-public class Charset_ISO_8859_14 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-14";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 163, 167, 169, 173, 174, 182, 192, 193, 194, 195, 196, 197, 198, 199, 200,
-201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
-219, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
-236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253,
-255, 266, 372, 7682, 7744, 7776, 7808, 7922
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 163, 167, 169, 173, 174, 182, 192, 193, 194, 195, 196, 197, 198, 199, 200,
-201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
-219, 220, 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235,
-236, 237, 238, 239, 241, 242, 243, 244, 245, 246, 248, 249, 250, 251, 252, 253,
-255, 164, 208, 161, 180, 187, 168, 172
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_16.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_16.java
deleted file mode 100644
index b740582..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_ISO_8859_16.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargetClass;
-
-@AndroidOnly("icu")
-public class Charset_ISO_8859_16 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-16";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 167, 169, 171, 173, 176, 177, 182, 183, 187, 192, 193, 194, 196, 198, 199,
-200, 201, 202, 203, 204, 205, 206, 207, 210, 211, 212, 214, 217, 218, 219, 220,
-223, 224, 225, 226, 228, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 242,
-243, 244, 246, 249, 250, 251, 252, 255, 258, 321, 352, 382, 536, 8221, 8364
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 167, 169, 171, 173, 176, 177, 182, 183, 187, 192, 193, 194, 196, 198, 199,
-200, 201, 202, 203, 204, 205, 206, 207, 210, 211, 212, 214, 217, 218, 219, 220,
-223, 224, 225, 226, 228, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 242,
-243, 244, 246, 249, 250, 251, 252, 255, 195, 163, 166, 184, 170, 181, 164
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_.java
deleted file mode 100644
index fc002f4..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_MultiByte_ extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "";
-
- testChars = theseChars(new int[]{
-
- });
-
- testBytes = theseBytes(new int[]{
-
- });
-
-//testChars = new char[0];
-//testBytes = new byte[0];
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5.java
deleted file mode 100644
index 1847278..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5.java
+++ /dev/null
@@ -1,435 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-/** @hide
- * SEE correspondig_Android test class:
- */
-
-public class Charset_MultiByte_Big5 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "Big5";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-162, 163, 165, 167, 176, 177, 183, 215, 247, 711, 713, 729, 913, 923, 933, 945,
-955, 965, 1025, 1044, 1059, 1069, 1079, 1089, 1099, 8211, 8221, 8242, 8254, 8451, 8544, 8592,
-8730, 8741, 8756, 8786, 8800, 8869, 8895, 9312, 9332, 9472, 9484, 9496, 9508, 9524, 9552, 9566,
-9578, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733, 9792, 12288, 12298, 12308, 12318, 12328,
-12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12445, 12455, 12465, 12475, 12485, 12495, 12505,
-12515, 12525, 12542, 12552, 12562, 12572, 12582, 12963, 13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998,
-20011, 20024, 20034, 20045, 20056, 20073, 20083, 20094, 20104, 20114, 20126, 20136, 20147, 20160, 20170, 20180,
-20190, 20200, 20210, 20221, 20232, 20242, 20253, 20268, 20278, 20289, 20300, 20310, 20320, 20330, 20340, 20350,
-20360, 20370, 20380, 20398, 20409, 20419, 20429, 20439, 20449, 20460, 20470, 20480, 20491, 20501, 20511, 20521,
-20531, 20544, 20554, 20565, 20575, 20585, 20595, 20605, 20615, 20625, 20635, 20652, 20662, 20673, 20683, 20693,
-20704, 20714, 20725, 20735, 20745, 20755, 20767, 20777, 20787, 20797, 20807, 20818, 20828, 20839, 20849, 20860,
-20871, 20881, 20894, 20906, 20918, 20932, 20942, 20952, 20976, 20986, 20998, 21008, 21020, 21032, 21042, 21057,
-21067, 21077, 21087, 21097, 21108, 21119, 21129, 21139, 21151, 21161, 21179, 21191, 21202, 21213, 21225, 21235,
-21246, 21256, 21266, 21276, 21290, 21300, 21310, 21320, 21330, 21340, 21350, 21360, 21371, 21386, 21396, 21406,
-21420, 21433, 21443, 21453, 21463, 21473, 21483, 21493, 21505, 21515, 21528, 21540, 21550, 21560, 21570, 21582,
-21600, 21611, 21621, 21631, 21643, 21653, 21664, 21674, 21686, 21696, 21710, 21726, 21736, 21746, 21756, 21766,
-21776, 21786, 21798, 21808, 21819, 21829, 21839, 21852, 21862, 21877, 21887, 21897, 21907, 21917, 21927, 21937,
-21947, 21957, 21967, 21977, 21987, 21999, 22009, 22020, 22030, 22043, 22055, 22066, 22077, 22088, 22099, 22110,
-22120, 22130, 22142, 22156, 22167, 22181, 22194, 22204, 22214, 22225, 22235, 22245, 22256, 22266, 22276, 22290,
-22300, 22312, 22323, 22334, 22345, 22369, 22379, 22389, 22400, 22411, 22421, 22431, 22446, 22456, 22466, 22476,
-22492, 22503, 22513, 22523, 22533, 22544, 22555, 22565, 22575, 22585, 22600, 22610, 22621, 22632, 22644, 22654,
-22664, 22675, 22685, 22696, 22707, 22717, 22727, 22737, 22747, 22759, 22772, 22782, 22796, 22806, 22816, 22826,
-22839, 22852, 22862, 22872, 22882, 22893, 22903, 22913, 22925, 22935, 22945, 22958, 22969, 22979, 22989, 23000,
-23011, 23021, 23031, 23041, 23052, 23062, 23072, 23085, 23095, 23105, 23116, 23126, 23136, 23146, 23159, 23171,
-23182, 23194, 23205, 23215, 23225, 23236, 23253, 23263, 23273, 23283, 23293, 23303, 23315, 23325, 23335, 23346,
-23356, 23367, 23377, 23387, 23397, 23408, 23418, 23428, 23438, 23448, 23458, 23468, 23478, 23488, 23498, 23508,
-23518, 23528, 23538, 23553, 23563, 23573, 23583, 23594, 23607, 23617, 23627, 23637, 23648, 23658, 23668, 23678,
-23688, 23698, 23709, 23719, 23729, 23750, 23760, 23770, 23784, 23796, 23807, 23819, 23830, 23840, 23854, 23864,
-23874, 23884, 23897, 23907, 23919, 23929, 23940, 23954, 23964, 23975, 23985, 23996, 24006, 24017, 24029, 24039,
-24049, 24061, 24074, 24084, 24095, 24105, 24115, 24125, 24138, 24148, 24159, 24169, 24179, 24189, 24199, 24213,
-24224, 24234, 24244, 24254, 24264, 24274, 24284, 24294, 24305, 24318, 24328, 24338, 24349, 24359, 24369, 24380,
-24390, 24404, 24418, 24428, 24438, 24448, 24458, 24470, 24480, 24490, 24501, 24511, 24521, 24532, 24542, 24552,
-24563, 24573, 24585, 24595, 24605, 24615, 24626, 24640, 24652, 24664, 24674, 24684, 24703, 24713, 24724, 24735,
-24752, 24762, 24772, 24782, 24792, 24802, 24816, 24826, 24836, 24846, 24856, 24867, 24878, 24891, 24901, 24911,
-24922, 24933, 24944, 24954, 24969, 24979, 24989, 24999, 25009, 25020, 25030, 25046, 25056, 25066, 25077, 25087,
-25097, 25108, 25119, 25129, 25139, 25149, 25159, 25169, 25179, 25189, 25199, 25209, 25219, 25230, 25240, 25256,
-25267, 25277, 25287, 25297, 25307, 25323, 25333, 25343, 25353, 25363, 25384, 25394, 25404, 25414, 25424, 25434,
-25445, 25455, 25466, 25476, 25486, 25496, 25506, 25516, 25533, 25543, 25554, 25564, 25575, 25585, 25606, 25616,
-25626, 25636, 25646, 25657, 25667, 25677, 25688, 25701, 25711, 25721, 25733, 25743, 25753, 25763, 25773, 25787,
-25797, 25807, 25817, 25827, 25837, 25847, 25857, 25868, 25878, 25888, 25898, 25910, 25921, 25935, 25945, 25955,
-25967, 25977, 25987, 26000, 26011, 26021, 26031, 26041, 26051, 26061, 26071, 26081, 26092, 26106, 26116, 26126,
-26140, 26150, 26161, 26177, 26188, 26201, 26212, 26222, 26232, 26244, 26256, 26269, 26280, 26290, 26301, 26311,
-26322, 26332, 26342, 26352, 26364, 26376, 26386, 26397, 26407, 26417, 26427, 26437, 26447, 26457, 26474, 26484,
-26494, 26505, 26515, 26525, 26542, 26552, 26562, 26572, 26584, 26594, 26604, 26614, 26642, 26652, 26662, 26673,
-26683, 26693, 26703, 26731, 26741, 26751, 26761, 26771, 26781, 26791, 26801, 26820, 26830, 26840, 26851, 26862,
-26872, 26884, 26894, 26917, 26927, 26937, 26948, 26958, 26968, 26978, 26988, 26998, 27010, 27021, 27031, 27041,
-27051, 27061, 27071, 27081, 27091, 27106, 27116, 27126, 27136, 27146, 27156, 27166, 27176, 27186, 27196, 27206,
-27216, 27226, 27236, 27247, 27262, 27273, 27283, 27294, 27304, 27315, 27325, 27335, 27345, 27355, 27365, 27375,
-27385, 27395, 27407, 27417, 27427, 27437, 27447, 27457, 27467, 27477, 27487, 27498, 27510, 27520, 27530, 27540,
-27550, 27562, 27573, 27583, 27593, 27603, 27614, 27624, 27634, 27644, 27654, 27664, 27674, 27684, 27694, 27704,
-27714, 27724, 27735, 27745, 27755, 27766, 27776, 27786, 27796, 27819, 27830, 27840, 27850, 27860, 27870, 27880,
-27890, 27904, 27914, 27926, 27936, 27946, 27956, 27966, 27992, 28002, 28012, 28022, 28032, 28042, 28052, 28074,
-28084, 28094, 28104, 28114, 28124, 28134, 28144, 28154, 28165, 28185, 28195, 28205, 28216, 28227, 28237, 28248,
-28258, 28270, 28280, 28296, 28306, 28316, 28326, 28336, 28346, 28356, 28366, 28376, 28395, 28405, 28415, 28425,
-28435, 28446, 28457, 28467, 28478, 28494, 28504, 28514, 28524, 28534, 28544, 28555, 28565, 28576, 28586, 28596,
-28607, 28617, 28628, 28638, 28648, 28658, 28668, 28678, 28689, 28699, 28710, 28720, 28730, 28740, 28753, 28763,
-28773, 28784, 28794, 28804, 28814, 28824, 28836, 28846, 28856, 28869, 28879, 28889, 28900, 28911, 28921, 28932,
-28942, 28953, 28963, 28974, 28986, 28996, 29006, 29016, 29026, 29036, 29048, 29058, 29071, 29081, 29092, 29103,
-29113, 29123, 29134, 29144, 29154, 29164, 29176, 29186, 29196, 29209, 29219, 29229, 29240, 29250, 29260, 29270,
-29280, 29290, 29300, 29310, 29320, 29330, 29341, 29351, 29364, 29375, 29385, 29396, 29407, 29417, 29427, 29437,
-29447, 29457, 29467, 29477, 29488, 29498, 29508, 29518, 29528, 29538, 29548, 29558, 29568, 29578, 29588, 29599,
-29609, 29619, 29630, 29640, 29650, 29660, 29671, 29684, 29694, 29704, 29718, 29728, 29738, 29748, 29759, 29770,
-29780, 29790, 29801, 29811, 29821, 29831, 29842, 29852, 29862, 29872, 29882, 29893, 29903, 29913, 29923, 29934,
-29947, 29959, 29969, 29980, 29990, 30000, 30010, 30023, 30036, 30047, 30058, 30070, 30080, 30090, 30100, 30114,
-30128, 30138, 30148, 30158, 30168, 30178, 30189, 30199, 30209, 30219, 30229, 30239, 30249, 30259, 30269, 30279,
-30290, 30300, 30313, 30325, 30335, 30345, 30355, 30365, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448,
-30458, 30468, 30480, 30490, 30501, 30511, 30521, 30532, 30542, 30553, 30563, 30573, 30585, 30595, 30605, 30615,
-30625, 30635, 30645, 30655, 30665, 30675, 30686, 30696, 30706, 30716, 30726, 30736, 30749, 30759, 30769, 30787,
-30797, 30812, 30824, 30841, 30851, 30862, 30872, 30882, 30892, 30906, 30916, 30926, 30938, 30949, 30959, 30969,
-30980, 30990, 31001, 31011, 31021, 31032, 31042, 31052, 31062, 31072, 31082, 31092, 31103, 31114, 31124, 31136,
-31146, 31156, 31166, 31176, 31186, 31196, 31206, 31222, 31232, 31242, 31252, 31262, 31272, 31287, 31300, 31310,
-31320, 31330, 31340, 31350, 31360, 31370, 31380, 31390, 31400, 31410, 31422, 31434, 31448, 31459, 31469, 31479,
-31489, 31502, 31512, 31522, 31532, 31544, 31556, 31566, 31576, 31587, 31597, 31607, 31618, 31628, 31638, 31648,
-31660, 31671, 31681, 31691, 31701, 31711, 31721, 31731, 31741, 31751, 31761, 31772, 31782, 31792, 31803, 31813,
-31824, 31834, 31844, 31854, 31864, 31876, 31889, 31902, 31912, 31922, 31932, 31944, 31954, 31964, 31975, 31985,
-31995, 32005, 32015, 32025, 32040, 32050, 32060, 32070, 32080, 32091, 32102, 32112, 32122, 32132, 32142, 32156,
-32166, 32176, 32186, 32196, 32206, 32216, 32227, 32238, 32249, 32259, 32269, 32279, 32289, 32299, 32309, 32319,
-32329, 32339, 32350, 32360, 32370, 32380, 32390, 32401, 32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631,
-32643, 32653, 32666, 32676, 32687, 32697, 32707, 32717, 32727, 32737, 32747, 32757, 32767, 32779, 32789, 32799,
-32809, 32819, 32829, 32839, 32849, 32860, 32871, 32881, 32893, 32903, 32914, 32924, 32937, 32948, 32962, 32972,
-32982, 32992, 33005, 33016, 33026, 33045, 33055, 33065, 33081, 33091, 33101, 33115, 33125, 33135, 33145, 33155,
-33165, 33175, 33186, 33196, 33207, 33218, 33228, 33239, 33249, 33260, 33271, 33281, 33291, 33301, 33311, 33322,
-33332, 33343, 33353, 33363, 33374, 33384, 33394, 33404, 33418, 33428, 33438, 33448, 33459, 33469, 33489, 33499,
-33509, 33519, 33529, 33539, 33549, 33559, 33570, 33580, 33590, 33600, 33610, 33620, 33651, 33661, 33671, 33682,
-33693, 33703, 33725, 33735, 33745, 33755, 33765, 33775, 33785, 33795, 33805, 33819, 33833, 33843, 33853, 33863,
-33873, 33883, 33893, 33903, 33913, 33926, 33936, 33946, 33956, 33966, 33976, 33986, 33996, 34006, 34023, 34033,
-34043, 34054, 34065, 34076, 34086, 34096, 34107, 34117, 34129, 34139, 34149, 34161, 34171, 34181, 34191, 34201,
-34211, 34223, 34233, 34243, 34253, 34263, 34273, 34283, 34294, 34304, 34314, 34327, 34337, 34348, 34358, 34368,
-34379, 34389, 34399, 34409, 34419, 34437, 34448, 34458, 34468, 34479, 34489, 34499, 34512, 34522, 34532, 34549,
-34560, 34570, 34584, 34594, 34604, 34615, 34625, 34636, 34646, 34656, 34666, 34676, 34689, 34701, 34711, 34722,
-34732, 34742, 34752, 34762, 34772, 34782, 34792, 34802, 34812, 34822, 34832, 34843, 34853, 34863, 34873, 34883,
-34893, 34903, 34913, 34923, 34933, 34943, 34953, 34963, 34974, 34984, 34994, 35004, 35017, 35028, 35038, 35048,
-35058, 35068, 35078, 35088, 35098, 35109, 35119, 35131, 35142, 35152, 35162, 35172, 35182, 35193, 35203, 35215,
-35227, 35238, 35250, 35261, 35282, 35292, 35302, 35312, 35322, 35332, 35342, 35352, 35362, 35372, 35382, 35392,
-35402, 35412, 35422, 35432, 35442, 35452, 35462, 35473, 35486, 35496, 35506, 35516, 35526, 35537, 35547, 35558,
-35568, 35578, 35588, 35598, 35608, 35618, 35628, 35638, 35648, 35658, 35668, 35679, 35690, 35700, 35710, 35720,
-35730, 35740, 35895, 35905, 35915, 35925, 35935, 35945, 35955, 35965, 35977, 35987, 35997, 36007, 36018, 36028,
-36039, 36049, 36060, 36070, 36080, 36090, 36100, 36111, 36121, 36196, 36206, 36216, 36228, 36238, 36249, 36259,
-36269, 36279, 36289, 36299, 36309, 36319, 36329, 36339, 36349, 36359, 36369, 36379, 36389, 36400, 36412, 36423,
-36435, 36445, 36455, 36466, 36476, 36486, 36496, 36506, 36516, 36530, 36541, 36553, 36563, 36573, 36583, 36593,
-36603, 36613, 36624, 36634, 36644, 36654, 36664, 36674, 36685, 36695, 36705, 36763, 36774, 36784, 36799, 36809,
-36819, 36832, 36842, 36852, 36862, 36875, 36885, 36895, 36909, 36920, 36930, 36941, 36952, 36962, 36973, 36983,
-36993, 37003, 37013, 37023, 37034, 37044, 37054, 37064, 37076, 37087, 37097, 37107, 37117, 37127, 37137, 37147,
-37158, 37168, 37178, 37188, 37198, 37208, 37218, 37228, 37239, 37249, 37259, 37273, 37283, 37293, 37303, 37313,
-37323, 37333, 37346, 37356, 37367, 37377, 37388, 37398, 37411, 37421, 37431, 37445, 37455, 37466, 37476, 37487,
-37497, 37507, 37517, 37527, 37537, 37547, 37557, 37568, 37578, 37589, 37599, 37609, 37623, 37633, 37643, 37653,
-37663, 37673, 37683, 37702, 37712, 37722, 37732, 37744, 37754, 37768, 37778, 37789, 37799, 37809, 37824, 37834,
-37844, 37854, 37864, 37877, 37887, 37897, 37907, 37920, 37930, 37941, 37951, 37961, 37973, 37984, 37994, 38004,
-38014, 38263, 38274, 38284, 38296, 38307, 38317, 38327, 38339, 38349, 38362, 38372, 38428, 38440, 38450, 38460,
-38474, 38484, 38494, 38506, 38516, 38526, 38536, 38546, 38556, 38567, 38577, 38587, 38597, 38610, 38620, 38632,
-38642, 38653, 38663, 38673, 38684, 38694, 38704, 38714, 38724, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
-38808, 38818, 38828, 38838, 38849, 38859, 38869, 38879, 38893, 38904, 38914, 38924, 38934, 38944, 38955, 38965,
-38977, 38988, 38999, 39010, 39023, 39080, 39090, 39100, 39110, 39131, 39141, 39151, 39161, 39171, 39184, 39194,
-39204, 39214, 39226, 39237, 39248, 39259, 39318, 39329, 39339, 39349, 39361, 39371, 39381, 39391, 39401, 39412,
-39422, 39433, 39444, 39454, 39465, 39476, 39486, 39496, 39506, 39518, 39528, 39592, 39603, 39614, 39626, 39636,
-39647, 39659, 39670, 39681, 39691, 39701, 39711, 39721, 39731, 39742, 39752, 39762, 39775, 39788, 39798, 39808,
-39824, 39834, 39844, 39854, 39864, 39875, 39891, 39902, 39912, 39927, 39941, 39954, 39964, 39976, 39986, 39996,
-40006, 40016, 40030, 40040, 40051, 40165, 40177, 40187, 40197, 40208, 40219, 40229, 40239, 40251, 40261, 40271,
-40281, 40295, 40305, 40315, 40325, 40336, 40346, 40356, 40367, 40377, 40387, 40397, 40407, 40417, 40427, 40437,
-40447, 40457, 40467, 40477, 40565, 40575, 40585, 40595, 40605, 40615, 40628, 40638, 40648, 40659, 40669, 40679,
-40690, 40700, 40710, 40720, 40730, 40740, 40750, 40760, 40770, 40780, 40790, 40800, 40810, 40820, 40830, 40845,
-40856, 40866, 64012, 65072, 65082, 65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65343,
-65353, 65363, 65373, 65536
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-162, 70, 162, 71, 162, 68, 161, 177, 162, 88, 161, 211, 161, 80, 161, 209,
-161, 210, 163, 190, 163, 188, 163, 187, 163, 68, 163, 78, 163, 87, 163, 92,
-163, 102, 163, 111, 199, 179, 199, 177, 199, 187, 199, 197, 199, 208, 199, 218,
-199, 228, 161, 86, 161, 168, 161, 172, 161, 194, 162, 74, 162, 185, 161, 246,
-161, 212, 161, 252, 161, 239, 161, 220, 161, 218, 161, 230, 161, 233, 199, 233,
-199, 243, 162, 119, 162, 122, 162, 125, 162, 116, 162, 114, 162, 164, 162, 165,
-162, 166, 162, 98, 162, 110, 162, 121, 161, 189, 161, 182, 161, 191, 161, 187,
-162, 168, 161, 185, 161, 240, 161, 64, 161, 109, 161, 101, 161, 170, 162, 202,
-198, 165, 198, 175, 198, 185, 198, 195, 198, 205, 198, 215, 198, 225, 198, 235,
-198, 245, 198, 162, 198, 254, 199, 73, 199, 83, 199, 93, 199, 103, 199, 113,
-199, 123, 199, 167, 198, 161, 163, 119, 163, 163, 163, 173, 163, 183, 161, 192,
-162, 85, 162, 80, 162, 87, 162, 83, 164, 64, 164, 87, 165, 66, 165, 224,
-164, 88, 164, 89, 201, 64, 165, 69, 173, 188, 165, 228, 168, 197, 176, 174,
-164, 169, 164, 172, 168, 200, 166, 235, 173, 189, 164, 176, 164, 181, 165, 74,
-165, 81, 201, 101, 165, 242, 165, 247, 201, 179, 201, 187, 201, 180, 201, 173,
-167, 68, 202, 100, 203, 189, 202, 90, 167, 65, 203, 191, 203, 185, 168, 219,
-168, 215, 203, 200, 203, 197, 171, 86, 205, 238, 171, 80, 205, 221, 171, 85,
-171, 72, 205, 239, 208, 212, 173, 206, 173, 211, 212, 91, 173, 201, 173, 197,
-208, 209, 212, 99, 212, 89, 176, 186, 212, 93, 212, 94, 212, 101, 176, 176,
-216, 95, 179, 199, 216, 81, 182, 202, 220, 195, 220, 190, 220, 193, 185, 178,
-224, 254, 224, 246, 187, 248, 228, 230, 187, 252, 232, 245, 192, 118, 236, 190,
-195, 95, 247, 208, 165, 251, 168, 224, 176, 194, 164, 186, 166, 64, 173, 221,
-201, 78, 171, 96, 203, 205, 190, 173, 167, 77, 208, 226, 208, 229, 225, 64,
-176, 196, 165, 88, 164, 192, 201, 191, 202, 108, 167, 83, 203, 209, 168, 239,
-171, 103, 208, 235, 208, 234, 179, 209, 179, 207, 182, 207, 188, 66, 190, 176,
-165, 92, 167, 85, 168, 241, 171, 105, 176, 199, 179, 211, 225, 67, 190, 177,
-164, 196, 166, 73, 216, 98, 201, 108, 173, 234, 232, 250, 176, 208, 164, 200,
-168, 242, 164, 82, 168, 246, 166, 76, 171, 111, 201, 196, 203, 218, 208, 239,
-225, 70, 201, 88, 176, 209, 164, 207, 168, 252, 232, 251, 165, 115, 165, 114,
-166, 83, 166, 84, 202, 126, 202, 165, 167, 109, 167, 108, 167, 102, 167, 96,
-203, 235, 203, 225, 168, 254, 203, 220, 169, 81, 169, 66, 206, 72, 171, 125,
-206, 69, 171, 115, 171, 117, 206, 78, 173, 239, 173, 245, 173, 243, 173, 246,
-173, 240, 208, 247, 208, 240, 212, 124, 212, 168, 212, 126, 176, 221, 176, 227,
-176, 213, 212, 113, 216, 120, 179, 239, 216, 109, 179, 220, 179, 217, 179, 237,
-179, 235, 182, 229, 220, 216, 220, 223, 182, 224, 182, 226, 225, 85, 225, 83,
-185, 199, 185, 192, 225, 71, 188, 74, 229, 67, 228, 246, 188, 78, 233, 69,
-190, 185, 233, 68, 236, 198, 236, 193, 239, 188, 195, 96, 243, 254, 196, 90,
-246, 215, 197, 241, 165, 124, 202, 169, 167, 120, 169, 84, 174, 70, 182, 233,
-233, 71, 166, 98, 166, 96, 167, 163, 202, 173, 169, 89, 203, 245, 203, 250,
-203, 249, 171, 172, 206, 94, 206, 82, 171, 177, 209, 82, 174, 71, 209, 74,
-212, 177, 212, 197, 212, 200, 212, 173, 176, 237, 212, 196, 216, 170, 216, 168,
-179, 243, 216, 175, 216, 167, 182, 246, 220, 235, 220, 227, 225, 93, 185, 209,
-225, 101, 185, 211, 229, 75, 190, 165, 188, 88, 233, 74, 190, 194, 192, 164,
-241, 248, 247, 211, 206, 95, 225, 105, 204, 66, 165, 126, 176, 247, 164, 211,
-166, 105, 169, 97, 171, 182, 174, 78, 176, 248, 188, 93, 201, 209, 166, 113,
-167, 176, 202, 181, 202, 187, 169, 103, 169, 102, 204, 77, 169, 107, 171, 185,
-171, 187, 206, 118, 206, 110, 171, 194, 174, 91, 209, 92, 174, 87, 209, 93,
-216, 194, 176, 250, 212, 231, 212, 236, 212, 206, 176, 253, 180, 64, 216, 198,
-212, 227, 180, 65, 216, 190, 216, 181, 221, 70, 220, 244, 225, 110, 225, 124,
-185, 224, 225, 115, 229, 86, 229, 94, 233, 86, 190, 197, 236, 211, 236, 208,
-239, 193, 245, 200, 164, 109, 167, 184, 204, 86, 177, 69, 192, 169, 201, 115,
-202, 188, 169, 120, 171, 200, 209, 104, 174, 97, 212, 242, 216, 213, 216, 211,
-185, 230, 185, 235, 236, 217, 171, 202, 180, 77, 201, 212, 221, 75, 202, 191,
-192, 170, 167, 190, 171, 206, 174, 105, 177, 79, 239, 195, 201, 118, 201, 217,
-202, 194, 202, 197, 204, 104, 204, 103, 169, 167, 206, 171, 206, 121, 206, 162,
-174, 111, 174, 115, 209, 109, 212, 245, 177, 86, 212, 248, 213, 68, 216, 236,
-216, 233, 180, 79, 216, 232, 221, 78, 183, 68, 225, 176, 185, 241, 229, 101,
-229, 106, 233, 97, 233, 95, 192, 172, 244, 68, 246, 222, 164, 116, 165, 169,
-164, 118, 180, 83, 202, 203, 204, 110, 171, 212, 209, 115, 177, 98, 180, 85,
-221, 90, 185, 247, 188, 109, 229, 110, 165, 173, 171, 213, 167, 200, 169, 179,
-171, 214, 209, 119, 213, 72, 177, 104, 183, 72, 225, 188, 225, 185, 233, 113,
-245, 203, 164, 123, 171, 217, 183, 73, 202, 211, 169, 183, 174, 122, 180, 93,
-185, 251, 204, 116, 167, 206, 177, 108, 202, 213, 169, 185, 171, 222, 213, 79,
-177, 116, 180, 96, 188, 120, 242, 64, 201, 123, 201, 225, 204, 120, 202, 218,
-202, 220, 169, 191, 204, 175, 204, 172, 171, 228, 169, 202, 204, 125, 206, 202,
-206, 201, 206, 207, 171, 236, 171, 239, 177, 118, 177, 120, 174, 172, 174, 169,
-213, 85, 213, 86, 216, 253, 216, 252, 177, 166, 216, 251, 180, 107, 180, 105,
-217, 79, 180, 112, 217, 75, 180, 104, 221, 108, 225, 210, 221, 105, 221, 111,
-186, 70, 225, 209, 188, 162, 225, 207, 229, 126, 229, 162, 233, 118, 188, 165,
-229, 123, 236, 225, 233, 123, 239, 207, 236, 227, 239, 204, 195, 106, 197, 116,
-201, 124, 204, 177, 180, 117, 225, 214, 194, 87, 204, 178, 174, 176, 165, 183,
-166, 170, 201, 236, 167, 232, 167, 229, 202, 231, 202, 233, 167, 233, 169, 225,
-204, 187, 169, 226, 169, 230, 204, 181, 169, 219, 206, 218, 206, 215, 174, 179,
-171, 246, 206, 225, 174, 193, 213, 102, 209, 189, 174, 185, 174, 189, 209, 199,
-213, 103, 213, 114, 177, 204, 177, 193, 213, 113, 177, 184, 177, 180, 177, 197,
-213, 107, 217, 107, 180, 161, 217, 102, 221, 183, 221, 120, 183, 112, 221, 122,
-221, 178, 221, 126, 221, 185, 221, 166, 221, 162, 225, 218, 186, 75, 225, 242,
-188, 176, 188, 177, 229, 177, 229, 180, 188, 193, 229, 184, 188, 189, 190, 216,
-190, 213, 233, 167, 233, 174, 236, 234, 192, 195, 194, 94, 239, 213, 242, 70,
-244, 76, 246, 225, 197, 205, 166, 172, 206, 231, 177, 211, 177, 208, 180, 178,
-221, 188, 229, 191, 192, 197, 180, 180, 177, 216, 165, 184, 180, 181, 164, 232,
-209, 208, 213, 168, 186, 88, 201, 94, 166, 175, 169, 244, 204, 198, 169, 250,
-206, 239, 206, 240, 172, 82, 174, 208, 174, 206, 213, 172, 177, 224, 180, 182,
-221, 199, 183, 121, 221, 194, 186, 92, 186, 91, 229, 198, 233, 185, 190, 232,
-236, 242, 194, 96, 196, 102, 164, 234, 176, 210, 164, 235, 209, 215, 180, 194,
-196, 103, 166, 182, 201, 242, 202, 253, 167, 246, 203, 64, 170, 87, 204, 220,
-170, 81, 170, 80, 170, 85, 170, 75, 207, 91, 172, 101, 207, 81, 207, 90,
-207, 67, 172, 107, 172, 90, 207, 78, 209, 236, 209, 227, 209, 238, 209, 226,
-209, 222, 174, 233, 209, 224, 213, 196, 213, 189, 177, 236, 213, 206, 177, 234,
-177, 248, 177, 239, 177, 238, 177, 243, 217, 205, 180, 198, 180, 208, 180, 203,
-217, 197, 217, 172, 180, 213, 217, 216, 221, 242, 221, 210, 221, 228, 221, 204,
-221, 230, 221, 205, 221, 218, 221, 229, 183, 167, 226, 74, 226, 93, 226, 90,
-186, 103, 226, 96, 226, 78, 225, 254, 186, 98, 229, 213, 229, 212, 229, 235,
-229, 202, 188, 212, 229, 220, 188, 207, 233, 202, 233, 194, 233, 215, 233, 221,
-233, 209, 233, 203, 233, 208, 233, 212, 192, 207, 236, 247, 236, 253, 236, 251,
-237, 66, 194, 98, 239, 223, 239, 229, 242, 79, 192, 205, 195, 111, 244, 90,
-244, 87, 245, 208, 247, 226, 248, 242, 170, 89, 209, 247, 213, 216, 221, 250,
-226, 101, 233, 222, 194, 106, 172, 110, 230, 209, 204, 234, 174, 237, 217, 222,
-226, 102, 233, 226, 172, 113, 183, 181, 239, 233, 183, 182, 204, 236, 210, 64,
-217, 228, 221, 254, 233, 232, 165, 194, 203, 74, 174, 244, 180, 225, 165, 195,
-168, 68, 202, 64, 166, 189, 166, 195, 203, 77, 168, 90, 205, 69, 205, 67,
-168, 92, 170, 106, 204, 243, 205, 71, 170, 121, 204, 244, 205, 70, 170, 96,
-204, 254, 207, 124, 207, 116, 210, 100, 207, 168, 172, 120, 207, 110, 172, 163,
-210, 76, 210, 77, 175, 64, 210, 72, 210, 98, 175, 71, 175, 75, 178, 101,
-213, 226, 213, 240, 213, 236, 178, 89, 213, 242, 178, 104, 213, 249, 178, 76,
-178, 77, 181, 65, 180, 237, 180, 244, 180, 229, 180, 251, 180, 248, 180, 240,
-217, 240, 180, 243, 218, 78, 217, 236, 222, 95, 183, 200, 222, 87, 222, 85,
-183, 196, 183, 201, 226, 108, 222, 93, 226, 170, 226, 109, 186, 161, 226, 117,
-186, 118, 226, 183, 186, 120, 186, 115, 186, 121, 226, 118, 188, 239, 230, 67,
-230, 73, 230, 72, 192, 223, 230, 90, 230, 93, 191, 73, 233, 251, 191, 74,
-233, 253, 234, 65, 237, 81, 237, 87, 237, 91, 237, 88, 239, 246, 194, 112,
-194, 114, 195, 115, 239, 245, 196, 106, 244, 100, 245, 212, 197, 120, 247, 228,
-249, 163, 166, 199, 203, 95, 205, 85, 170, 162, 205, 81, 172, 183, 172, 182,
-172, 181, 210, 119, 175, 81, 175, 79, 175, 78, 178, 109, 178, 105, 214, 79,
-214, 91, 181, 72, 218, 94, 218, 92, 218, 100, 222, 161, 183, 206, 222, 120,
-222, 114, 183, 213, 222, 116, 226, 191, 226, 192, 186, 179, 230, 109, 230, 99,
-191, 81, 191, 85, 191, 82, 234, 84, 237, 98, 192, 236, 194, 119, 242, 108,
-242, 105, 245, 220, 248, 177, 170, 167, 170, 168, 210, 125, 181, 80, 188, 248,
-168, 101, 205, 91, 172, 187, 214, 92, 218, 104, 186, 185, 234, 89, 196, 235,
-202, 67, 203, 97, 205, 95, 205, 98, 207, 194, 172, 188, 210, 168, 175, 86,
-214, 98, 214, 99, 178, 114, 181, 84, 218, 111, 222, 173, 186, 187, 188, 250,
-230, 117, 230, 161, 234, 94, 239, 254, 197, 122, 201, 167, 203, 107, 170, 179,
-170, 177, 172, 197, 207, 210, 207, 201, 210, 180, 210, 179, 210, 176, 214, 120,
-178, 123, 214, 121, 218, 126, 218, 169, 181, 88, 181, 94, 183, 233, 222, 178,
-222, 190, 183, 231, 188, 252, 226, 207, 230, 167, 230, 162, 234, 102, 191, 88,
-192, 245, 192, 244, 244, 111, 242, 116, 196, 110, 246, 242, 195, 164, 207, 216,
-218, 171, 230, 173, 237, 112, 178, 162, 181, 100, 165, 208, 203, 109, 207, 218,
-175, 96, 210, 194, 181, 102, 183, 237, 234, 106, 197, 124, 203, 111, 172, 207,
-210, 195, 210, 202, 210, 198, 214, 124, 181, 107, 181, 103, 222, 210, 222, 202,
-183, 241, 186, 198, 226, 221, 189, 69, 189, 68, 234, 111, 234, 110, 237, 119,
-194, 161, 240, 74, 196, 238, 249, 204, 202, 71, 214, 166, 181, 113, 230, 185,
-244, 113, 181, 114, 244, 114, 172, 213, 178, 176, 181, 115, 234, 117, 205, 120,
-207, 231, 207, 226, 210, 207, 210, 214, 214, 176, 214, 169, 214, 168, 218, 188,
-218, 192, 222, 225, 183, 254, 222, 226, 184, 64, 226, 234, 230, 188, 234, 161,
-234, 120, 237, 123, 237, 122, 194, 163, 242, 121, 196, 239, 218, 195, 207, 233,
-244, 120, 205, 123, 207, 234, 207, 238, 175, 124, 175, 122, 210, 229, 178, 185,
-214, 182, 218, 200, 218, 207, 222, 238, 222, 237, 184, 72, 184, 75, 226, 246,
-226, 245, 189, 84, 230, 201, 230, 197, 191, 106, 234, 164, 193, 70, 237, 172,
-237, 174, 194, 166, 195, 170, 244, 122, 245, 225, 248, 181, 205, 162, 207, 245,
-175, 170, 175, 168, 214, 191, 218, 210, 184, 83, 226, 249, 226, 253, 230, 205,
-193, 73, 246, 247, 165, 221, 170, 196, 172, 237, 210, 243, 175, 179, 214, 198,
-181, 125, 218, 215, 184, 90, 184, 92, 227, 72, 189, 94, 234, 175, 191, 111,
-237, 180, 194, 169, 244, 163, 168, 115, 207, 254, 210, 251, 214, 201, 223, 68,
-227, 74, 230, 211, 237, 183, 197, 209, 210, 253, 181, 164, 186, 220, 244, 165,
-208, 67, 211, 70, 214, 211, 214, 208, 178, 196, 214, 219, 218, 224, 218, 227,
-218, 229, 223, 83, 223, 72, 184, 95, 227, 93, 227, 85, 227, 83, 189, 105,
-230, 217, 230, 214, 189, 104, 230, 215, 234, 187, 234, 198, 191, 122, 237, 195,
-237, 201, 193, 76, 191, 117, 240, 97, 240, 104, 240, 108, 242, 172, 244, 170,
-196, 240, 246, 254, 197, 210, 198, 89, 208, 69, 211, 73, 211, 74, 218, 232,
-218, 233, 223, 84, 227, 96, 230, 224, 234, 199, 193, 83, 194, 179, 247, 65,
-168, 116, 172, 245, 211, 89, 175, 200, 214, 240, 178, 216, 178, 209, 178, 204,
-181, 178, 184, 108, 181, 185, 181, 187, 223, 93, 223, 100, 223, 94, 186, 238,
-227, 117, 186, 237, 186, 246, 227, 108, 227, 107, 189, 112, 189, 116, 230, 239,
-189, 123, 230, 233, 234, 219, 234, 206, 234, 205, 193, 95, 193, 103, 193, 104,
-237, 215, 240, 119, 194, 182, 242, 184, 242, 182, 196, 126, 245, 235, 247, 66,
-249, 65, 166, 206, 234, 223, 245, 237, 208, 77, 214, 241, 223, 103, 189, 125,
-242, 187, 208, 79, 178, 220, 184, 115, 189, 126, 195, 188, 211, 99, 214, 248,
-219, 68, 187, 66, 230, 246, 239, 168, 244, 177, 181, 192, 175, 209, 214, 254,
-234, 230, 166, 213, 175, 212, 215, 66, 219, 69, 227, 163, 230, 252, 193, 109,
-197, 165, 187, 70, 203, 119, 203, 120, 170, 211, 170, 212, 208, 91, 173, 73,
-173, 68, 208, 88, 175, 218, 175, 221, 175, 215, 215, 78, 215, 74, 178, 231,
-181, 200, 219, 74, 219, 80, 223, 119, 184, 123, 223, 126, 184, 161, 227, 166,
-227, 168, 231, 68, 231, 66, 234, 239, 234, 242, 193, 117, 237, 234, 242, 193,
-249, 68, 175, 229, 219, 84, 211, 112, 244, 181, 227, 171, 166, 224, 175, 232,
-215, 86, 219, 90, 223, 164, 231, 71, 240, 163, 244, 182, 166, 226, 202, 75,
-203, 161, 208, 106, 205, 188, 205, 191, 170, 218, 170, 222, 173, 98, 173, 86,
-173, 89, 173, 102, 208, 109, 173, 83, 206, 65, 175, 250, 211, 126, 211, 179,
-175, 249, 175, 251, 175, 240, 175, 239, 215, 94, 215, 104, 215, 119, 178, 247,
-215, 107, 179, 65, 178, 245, 219, 163, 219, 164, 219, 175, 219, 111, 181, 216,
-219, 94, 181, 209, 181, 211, 219, 174, 223, 199, 223, 217, 184, 168, 223, 215,
-223, 177, 184, 175, 223, 176, 223, 211, 223, 173, 223, 179, 187, 96, 227, 187,
-227, 173, 227, 180, 187, 93, 227, 178, 227, 196, 227, 201, 231, 115, 223, 169,
-231, 88, 189, 183, 189, 176, 231, 87, 231, 114, 231, 122, 231, 77, 234, 249,
-235, 70, 235, 74, 235, 86, 235, 75, 237, 251, 238, 81, 237, 245, 238, 75,
-237, 250, 193, 166, 194, 202, 240, 167, 194, 197, 242, 205, 242, 202, 242, 198,
-244, 190, 244, 189, 196, 173, 196, 244, 245, 250, 247, 74, 247, 76, 247, 241,
-249, 199, 179, 66, 184, 185, 240, 186, 208, 169, 211, 196, 211, 205, 211, 195,
-176, 68, 179, 76, 215, 167, 215, 174, 181, 241, 219, 182, 181, 240, 223, 232,
-184, 190, 184, 196, 187, 106, 187, 103, 227, 224, 187, 108, 227, 225, 189, 193,
-231, 161, 189, 187, 231, 176, 189, 185, 235, 97, 191, 196, 235, 93, 191, 195,
-238, 93, 238, 107, 193, 172, 238, 105, 240, 197, 238, 111, 240, 208, 194, 206,
-242, 228, 242, 227, 244, 197, 246, 66, 247, 81, 247, 215, 197, 251, 211, 207,
-173, 108, 181, 243, 191, 197, 173, 109, 211, 210, 211, 215, 215, 178, 215, 195,
-179, 79, 215, 180, 219, 205, 219, 202, 219, 207, 184, 199, 223, 245, 187, 116,
-227, 248, 227, 252, 231, 201, 189, 197, 187, 117, 191, 200, 235, 122, 193, 182,
-240, 214, 240, 215, 242, 234, 196, 176, 246, 74, 249, 72, 181, 247, 179, 87,
-223, 251, 191, 204, 194, 209, 196, 253, 168, 164, 224, 67, 224, 68, 231, 210,
-246, 76, 208, 176, 176, 81, 176, 79, 179, 96, 215, 203, 182, 70, 219, 218,
-219, 226, 182, 64, 181, 252, 184, 229, 184, 211, 184, 217, 224, 70, 187, 165,
-187, 121, 187, 163, 189, 210, 189, 203, 231, 213, 231, 216, 189, 219, 191, 205,
-235, 169, 191, 206, 193, 195, 193, 188, 238, 161, 238, 166, 194, 213, 240, 232,
-242, 249, 242, 248, 242, 252, 196, 183, 244, 207, 196, 254, 247, 86, 248, 67,
-197, 254, 198, 109, 168, 166, 193, 197, 224, 83, 168, 168, 219, 229, 228, 82,
-193, 199, 215, 209, 184, 232, 191, 223, 168, 169, 179, 104, 184, 237, 182, 75,
-184, 234, 187, 172, 189, 231, 189, 225, 235, 183, 193, 200, 240, 244, 196, 185,
-248, 69, 168, 170, 235, 186, 211, 228, 219, 237, 224, 96, 187, 175, 189, 236,
-243, 77, 211, 230, 215, 218, 182, 91, 219, 247, 184, 242, 224, 109, 184, 245,
-228, 91, 228, 94, 231, 251, 231, 249, 231, 245, 235, 198, 235, 195, 238, 191,
-238, 188, 241, 67, 240, 254, 195, 219, 195, 218, 244, 215, 247, 97, 247, 95,
-249, 80, 184, 250, 235, 200, 249, 172, 211, 233, 215, 221, 220, 69, 220, 73,
-182, 97, 224, 120, 228, 100, 232, 74, 232, 72, 235, 202, 191, 233, 193, 212,
-194, 225, 244, 220, 197, 175, 168, 175, 191, 236, 168, 176, 203, 166, 203, 165,
-205, 206, 208, 182, 173, 125, 176, 106, 211, 234, 215, 227, 179, 119, 179, 116,
-220, 77, 182, 104, 185, 69, 185, 77, 187, 184, 187, 189, 190, 68, 190, 69,
-193, 218, 195, 229, 176, 111, 203, 167, 168, 184, 205, 212, 208, 188, 208, 191,
-215, 238, 211, 247, 215, 241, 215, 237, 179, 163, 220, 90, 224, 167, 228, 113,
-232, 89, 190, 70, 241, 75, 246, 91, 212, 64, 215, 243, 220, 96, 185, 83,
-187, 197, 232, 94, 190, 76, 238, 200, 193, 222, 243, 95, 244, 227, 198, 93,
-196, 192, 212, 66, 212, 67, 215, 247, 216, 65, 220, 98, 220, 105, 220, 119,
-182, 116, 228, 186, 185, 87, 185, 100, 224, 188, 185, 103, 185, 95, 224, 191,
-228, 164, 224, 182, 228, 126, 228, 165, 228, 175, 228, 163, 232, 161, 232, 101,
-232, 115, 232, 120, 232, 106, 232, 108, 235, 244, 235, 233, 236, 64, 192, 67,
-235, 224, 235, 249, 191, 248, 235, 234, 238, 216, 193, 237, 238, 208, 193, 236,
-235, 227, 241, 96, 241, 85, 241, 88, 241, 90, 241, 100, 243, 115, 243, 108,
-243, 109, 243, 96, 195, 245, 244, 243, 244, 254, 244, 251, 244, 232, 244, 234,
-246, 102, 197, 75, 246, 94, 247, 111, 248, 75, 197, 224, 198, 68, 249, 114,
-198, 113, 170, 248, 173, 172, 220, 122, 185, 104, 187, 213, 190, 91, 238, 243,
-238, 241, 236, 71, 243, 119, 246, 108, 170, 250, 203, 174, 168, 190, 205, 218,
-208, 198, 208, 194, 176, 165, 179, 173, 179, 178, 220, 125, 220, 126, 224, 209,
-187, 217, 192, 71, 193, 244, 176, 166, 182, 174, 187, 220, 194, 248, 171, 66,
-182, 179, 224, 215, 190, 95, 192, 76, 193, 247, 243, 126, 196, 197, 246, 111,
-198, 71, 171, 67, 192, 82, 192, 83, 220, 170, 228, 192, 228, 198, 232, 178,
-192, 84, 241, 161, 241, 121, 243, 163, 197, 183, 173, 179, 239, 66, 243, 166,
-173, 180, 236, 88, 179, 187, 185, 124, 228, 203, 232, 187, 190, 102, 236, 89,
-239, 69, 195, 68, 243, 170, 245, 79, 197, 227, 173, 183, 232, 190, 196, 66,
-246, 116, 173, 184, 216, 79, 182, 186, 224, 227, 187, 229, 192, 92, 192, 97,
-236, 92, 195, 75, 241, 174, 196, 67, 245, 84, 247, 119, 173, 186, 239, 87,
-249, 178, 224, 231, 187, 233, 232, 207, 190, 114, 190, 111, 236, 104, 239, 90,
-239, 97, 241, 177, 243, 192, 243, 190, 245, 96, 245, 91, 197, 91, 247, 125,
-247, 162, 248, 211, 249, 195, 176, 169, 232, 210, 239, 100, 245, 101, 197, 233,
-212, 73, 232, 212, 236, 110, 239, 103, 243, 194, 246, 163, 248, 85, 241, 190,
-236, 114, 228, 221, 239, 105, 246, 168, 228, 225, 232, 227, 232, 222, 236, 115,
-236, 124, 239, 106, 239, 113, 194, 65, 241, 201, 241, 197, 241, 202, 243, 202,
-196, 72, 245, 108, 245, 109, 245, 110, 246, 171, 246, 174, 247, 180, 247, 177,
-247, 170, 248, 89, 248, 218, 249, 90, 249, 120, 179, 190, 228, 226, 232, 236,
-232, 238, 236, 172, 192, 112, 236, 163, 239, 123, 194, 69, 239, 161, 241, 209,
-241, 213, 239, 120, 243, 221, 243, 235, 243, 233, 245, 125, 245, 167, 245, 121,
-197, 97, 246, 191, 246, 187, 246, 199, 197, 195, 248, 105, 248, 101, 247, 196,
-248, 229, 248, 228, 249, 124, 249, 207, 179, 191, 179, 192, 239, 171, 196, 83,
-197, 101, 228, 229, 196, 84, 190, 163, 239, 174, 232, 241, 194, 75, 245, 182,
-248, 118, 243, 245, 248, 120, 232, 243, 246, 208, 239, 178, 245, 185, 248, 122,
-247, 204, 241, 233, 243, 250, 245, 187, 197, 198, 248, 235, 249, 211, 192, 115,
-249, 213, 247, 207, 201, 74, 161, 74, 161, 104, 161, 124, 161, 201, 161, 125,
-161, 223, 161, 73, 161, 207, 162, 180, 161, 72, 162, 215, 162, 225, 161, 196,
-162, 241, 162, 251, 161, 98, 0
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5_Android.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5_Android.java
deleted file mode 100644
index 663023b..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_Big5_Android.java
+++ /dev/null
@@ -1,304 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargetClass;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_MultiByte_Big5_Android extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "Big5";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 167, 175, 176, 177, 183, 215, 247, 711, 713, 913, 933, 953, 8211, 8231, 8251,
-8364, 8451, 8544, 8592, 8725, 8745, 8786, 8806, 8853, 8895, 9472, 9492, 9516, 9552, 9572, 9601,
-9621, 9650, 9670, 9698, 9733, 9792, 12288, 12308, 12328, 12549, 12569, 12963, 13198, 13252, 19968, 19988,
-20011, 20034, 20054, 20083, 20104, 20126, 20147, 20167, 20188, 20208, 20228, 20248, 20268, 20289, 20309, 20329,
-20349, 20369, 20398, 20418, 20438, 20460, 20480, 20500, 20520, 20540, 20561, 20581, 20602, 20622, 20642, 20662,
-20682, 20704, 20725, 20745, 20767, 20787, 20807, 20827, 20849, 20871, 20894, 20918, 20938, 20958, 20979, 20999,
-21020, 21040, 21060, 21082, 21102, 21122, 21142, 21162, 21182, 21202, 21222, 21242, 21262, 21282, 21303, 21324,
-21344, 21365, 21386, 21406, 21426, 21448, 21471, 21491, 21511, 21531, 21552, 21573, 21600, 21620, 21640, 21664,
-21686, 21710, 21730, 21751, 21771, 21798, 21819, 21839, 21859, 21879, 21899, 21919, 21939, 21959, 21979, 21999,
-22020, 22043, 22063, 22085, 22105, 22125, 22145, 22165, 22186, 22206, 22227, 22247, 22271, 22291, 22312, 22334,
-22354, 22374, 22395, 22415, 22435, 22456, 22476, 22496, 22516, 22536, 22556, 22576, 22600, 22621, 22641, 22661,
-22684, 22705, 22725, 22745, 22767, 22787, 22807, 22827, 22848, 22868, 22889, 22909, 22930, 22950, 22970, 22990,
-23011, 23031, 23052, 23072, 23093, 23113, 23133, 23159, 23179, 23199, 23219, 23239, 23259, 23283, 23303, 23323,
-23343, 23363, 23383, 23403, 23423, 23443, 23463, 23487, 23507, 23527, 23553, 23573, 23594, 23614, 23636, 23656,
-23676, 23696, 23716, 23736, 23756, 23784, 23805, 23825, 23845, 23865, 23886, 23906, 23927, 23949, 23969, 23989,
-24009, 24029, 24049, 24070, 24090, 24115, 24138, 24159, 24179, 24199, 24219, 24240, 24260, 24280, 24300, 24321,
-24341, 24361, 24384, 24404, 24425, 24445, 24465, 24485, 24505, 24525, 24545, 24565, 24585, 24605, 24626, 24646,
-24666, 24686, 24707, 24727, 24752, 24772, 24792, 24816, 24836, 24856, 24876, 24896, 24916, 24936, 24956, 24976,
-24996, 25016, 25036, 25056, 25077, 25097, 25119, 25139, 25159, 25179, 25199, 25219, 25239, 25259, 25279, 25299,
-25323, 25343, 25363, 25384, 25404, 25424, 25445, 25466, 25486, 25506, 25533, 25554, 25575, 25606, 25626, 25646,
-25667, 25688, 25708, 25730, 25750, 25771, 25791, 25812, 25832, 25852, 25872, 25892, 25912, 25935, 25955, 25975,
-25996, 26016, 26038, 26059, 26079, 26099, 26119, 26140, 26161, 26181, 26201, 26222, 26244, 26264, 26286, 26308,
-26328, 26348, 26368, 26388, 26408, 26428, 26448, 26474, 26494, 26514, 26542, 26562, 26584, 26604, 26642, 26662,
-26682, 26702, 26731, 26751, 26771, 26791, 26820, 26840, 26860, 26884, 26917, 26937, 26958, 26978, 26998, 27021,
-27041, 27061, 27081, 27106, 27126, 27146, 27166, 27186, 27206, 27226, 27247, 27267, 27287, 27308, 27330, 27353,
-27374, 27394, 27414, 27436, 27457, 27477, 27498, 27518, 27540, 27562, 27583, 27603, 27623, 27643, 27663, 27683,
-27704, 27724, 27744, 27764, 27784, 27804, 27824, 27844, 27865, 27885, 27905, 27926, 27946, 27966, 27992, 28012,
-28032, 28052, 28074, 28094, 28114, 28134, 28154, 28185, 28205, 28225, 28245, 28265, 28296, 28316, 28336, 28356,
-28376, 28396, 28416, 28436, 28457, 28478, 28498, 28518, 28538, 28558, 28578, 28598, 28618, 28638, 28658, 28678,
-28698, 28719, 28739, 28759, 28779, 28802, 28822, 28843, 28869, 28889, 28911, 28932, 28953, 28974, 28994, 29014,
-29034, 29056, 29076, 29096, 29116, 29136, 29156, 29176, 29196, 29218, 29238, 29258, 29278, 29298, 29318, 29338,
-29358, 29378, 29398, 29418, 29438, 29458, 29478, 29498, 29518, 29538, 29558, 29578, 29599, 29619, 29639, 29659,
-29684, 29704, 29725, 29745, 29766, 29786, 29806, 29827, 29847, 29867, 29887, 29908, 29928, 29949, 29969, 29989,
-30009, 30030, 30050, 30070, 30090, 30114, 30134, 30154, 30174, 30194, 30216, 30236, 30256, 30278, 30298, 30318,
-30338, 30358, 30378, 30398, 30418, 30438, 30458, 30480, 30501, 30521, 30541, 30561, 30585, 30605, 30625, 30645,
-30665, 30686, 30706, 30726, 30749, 30769, 30789, 30812, 30832, 30852, 30872, 30892, 30913, 30933, 30953, 30973,
-30993, 31013, 31033, 31055, 31075, 31097, 31117, 31137, 31158, 31179, 31199, 31222, 31242, 31262, 31287, 31307,
-31327, 31348, 31368, 31390, 31410, 31431, 31455, 31478, 31498, 31518, 31538, 31558, 31584, 31604, 31624, 31644,
-31665, 31686, 31706, 31728, 31749, 31769, 31789, 31811, 31831, 31851, 31871, 31892, 31912, 31932, 31952, 31975,
-31995, 32015, 32040, 32060, 32080, 32102, 32122, 32142, 32162, 32183, 32203, 32223, 32243, 32264, 32284, 32304,
-32324, 32344, 32365, 32385, 32405, 32566, 32586, 32606, 32626, 32646, 32666, 32687, 32707, 32727, 32747, 32767,
-32788, 32808, 32829, 32849, 32871, 32893, 32914, 32937, 32962, 32982, 33005, 33025, 33045, 33065, 33085, 33105,
-33125, 33145, 33165, 33186, 33207, 33228, 33248, 33268, 33288, 33308, 33330, 33351, 33371, 33391, 33411, 33432,
-33452, 33472, 33492, 33512, 33534, 33558, 33578, 33599, 33619, 33651, 33671, 33691, 33711, 33731, 33751, 33771,
-33791, 33811, 33833, 33853, 33873, 33893, 33913, 33933, 33953, 33974, 33994, 34023, 34043, 34063, 34083, 34107,
-34129, 34149, 34169, 34189, 34209, 34229, 34249, 34269, 34289, 34309, 34329, 34349, 34371, 34393, 34413, 34437,
-34457, 34479, 34499, 34519, 34539, 34560, 34584, 34604, 34624, 34644, 34664, 34689, 34710, 34730, 34750, 34770,
-34790, 34810, 34832, 34852, 34872, 34892, 34913, 34933, 34953, 34974, 34994, 35017, 35037, 35057, 35077, 35097,
-35117, 35137, 35158, 35178, 35198, 35219, 35242, 35262, 35282, 35302, 35322, 35342, 35362, 35382, 35402, 35422,
-35442, 35462, 35482, 35504, 35524, 35544, 35565, 35585, 35605, 35626, 35646, 35666, 35686, 35706, 35726, 35895,
-35915, 35935, 35955, 35977, 35997, 36018, 36039, 36060, 36080, 36100, 36121, 36196, 36216, 36236, 36256, 36276,
-36296, 36316, 36336, 36356, 36376, 36398, 36418, 36438, 36458, 36481, 36501, 36521, 36541, 36561, 36581, 36601,
-36621, 36643, 36663, 36683, 36703, 36763, 36783, 36804, 36832, 36852, 36875, 36895, 36916, 36937, 36957, 36978,
-36998, 37019, 37039, 37059, 37079, 37099, 37119, 37140, 37160, 37182, 37202, 37224, 37248, 37273, 37293, 37313,
-37333, 37353, 37373, 37393, 37413, 37433, 37453, 37473, 37494, 37514, 37536, 37556, 37576, 37597, 37617, 37638,
-37658, 37678, 37702, 37722, 37744, 37768, 37789, 37809, 37831, 37852, 37877, 37897, 37920, 37941, 37961, 37981,
-38001, 38263, 38283, 38303, 38325, 38345, 38366, 38428, 38448, 38468, 38488, 38508, 38528, 38548, 38568, 38588,
-38610, 38632, 38653, 38673, 38693, 38713, 38738, 38758, 38778, 38798, 38818, 38838, 38859, 38879, 38899, 38919,
-38939, 38959, 38979, 38999, 39019, 39080, 39100, 39131, 39151, 39171, 39191, 39211, 39231, 39251, 39318, 39339,
-39361, 39381, 39401, 39421, 39441, 39461, 39481, 39501, 39522, 39592, 39612, 39632, 39654, 39674, 39694, 39714,
-39735, 39755, 39775, 39796, 39816, 39838, 39861, 39881, 39902, 39927, 39947, 39969, 39990, 40010, 40030, 40051,
-40165, 40185, 40208, 40229, 40251, 40271, 40295, 40315, 40336, 40356, 40376, 40396, 40417, 40437, 40457, 40477,
-40565, 40585, 40605, 40628, 40648, 40668, 40688, 40710, 40730, 40750, 40770, 40790, 40810, 40830, 40850, 57344,
-57364, 57384, 57404, 57424, 57444, 57464, 57484, 57504, 57524, 57544, 57564, 57584, 57604, 57624, 57644, 57664,
-57684, 57704, 57724, 57744, 57764, 57784, 57804, 57824, 57844, 57864, 57884, 57904, 57924, 57944, 57964, 57984,
-58004, 58024, 58044, 58064, 58084, 58104, 58124, 58144, 58164, 58184, 58204, 58224, 58244, 58264, 58284, 58304,
-58324, 58344, 58364, 58384, 58404, 58424, 58444, 58464, 58484, 58504, 58524, 58544, 58564, 58584, 58604, 58624,
-58644, 58664, 58684, 58704, 58724, 58744, 58764, 58784, 58804, 58824, 58844, 58864, 58884, 58904, 58924, 58944,
-58964, 58984, 59004, 59024, 59044, 59064, 59084, 59104, 59124, 59144, 59164, 59184, 59204, 59224, 59244, 59264,
-59284, 59304, 59324, 59344, 59364, 59384, 59404, 59424, 59444, 59464, 59484, 59504, 59524, 59544, 59564, 59584,
-59604, 59624, 59644, 59664, 59684, 59704, 59724, 59744, 59764, 59784, 59804, 59824, 59844, 59864, 59884, 59904,
-59924, 59944, 59964, 59984, 60004, 60024, 60044, 60064, 60084, 60104, 60124, 60144, 60164, 60184, 60204, 60224,
-60244, 60264, 60284, 60304, 60324, 60344, 60364, 60384, 60404, 60424, 60444, 60464, 60484, 60504, 60524, 60544,
-60564, 60584, 60604, 60624, 60644, 60664, 60684, 60704, 60724, 60744, 60764, 60784, 60804, 60824, 60844, 60864,
-60884, 60904, 60924, 60944, 60964, 60984, 61004, 61024, 61044, 61064, 61084, 61104, 61124, 61144, 61164, 61184,
-61204, 61224, 61244, 61264, 61284, 61304, 61324, 61344, 61364, 61384, 61404, 61424, 61444, 61464, 61484, 61504,
-61524, 61544, 61564, 61584, 61604, 61624, 61644, 61664, 61684, 61704, 61724, 61744, 61764, 61784, 61804, 61824,
-61844, 61864, 61884, 61904, 61924, 61944, 61964, 61984, 62004, 62024, 62044, 62064, 62084, 62104, 62124, 62144,
-62164, 62184, 62204, 62224, 62244, 62264, 62284, 62304, 62324, 62344, 62364, 62384, 62404, 62424, 62444, 62464,
-62484, 62504, 62524, 62544, 62564, 62584, 62604, 62624, 62644, 62664, 62684, 62704, 62724, 62744, 62764, 62784,
-62804, 62824, 62844, 62864, 62884, 62904, 62924, 62944, 62964, 62984, 63004, 63024, 63044, 63064, 63084, 63104,
-63124, 63144, 63164, 63184, 63204, 63224, 63244, 63264, 63284, 63304, 63324, 63344, 63364, 63384, 63404, 63424,
-63444, 63464, 63484, 63504, 63524, 63544, 63736, 64012, 65072, 65092, 65113, 65281, 65301, 65321, 65343, 65363,
-65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 161, 177, 161, 194, 162, 88, 161, 211, 161, 80, 161, 209, 161, 210, 163,
-190, 163, 188, 163, 68, 163, 87, 163, 100, 161, 86, 161, 69, 161, 176, 163,
-225, 162, 74, 162, 185, 161, 246, 162, 65, 161, 228, 161, 220, 161, 216, 161,
-242, 161, 233, 162, 119, 162, 124, 162, 115, 249, 249, 249, 231, 162, 98, 162,
-121, 161, 182, 161, 187, 162, 168, 161, 185, 161, 240, 161, 64, 161, 101, 162,
-202, 163, 116, 163, 170, 161, 192, 162, 85, 162, 87, 164, 64, 165, 66, 164,
-88, 201, 64, 168, 196, 168, 197, 164, 169, 168, 200, 173, 189, 164, 179, 201,
-102, 165, 245, 201, 185, 201, 172, 201, 173, 202, 100, 166, 243, 168, 216, 203,
-181, 168, 221, 171, 86, 171, 89, 205, 235, 205, 239, 173, 206, 173, 207, 173,
-208, 173, 200, 212, 103, 176, 183, 176, 175, 216, 89, 179, 195, 220, 195, 220,
-185, 224, 254, 187, 248, 187, 252, 192, 118, 195, 95, 165, 251, 162, 90, 166,
-64, 201, 78, 203, 205, 167, 77, 208, 225, 232, 249, 185, 185, 164, 193, 202,
-108, 168, 236, 205, 240, 208, 231, 212, 108, 185, 187, 241, 237, 167, 86, 168,
-240, 176, 199, 182, 211, 164, 99, 208, 238, 201, 193, 243, 253, 201, 109, 165,
-101, 167, 90, 201, 196, 208, 239, 188, 70, 164, 83, 173, 238, 165, 107, 201,
-197, 167, 103, 202, 118, 202, 122, 203, 235, 203, 230, 203, 224, 206, 72, 206,
-69, 171, 117, 208, 241, 209, 66, 209, 71, 208, 240, 212, 168, 176, 221, 176,
-229, 216, 106, 179, 227, 179, 231, 179, 229, 182, 222, 220, 203, 182, 226, 225,
-83, 185, 192, 188, 83, 216, 107, 190, 178, 233, 67, 236, 201, 194, 80, 241,
-244, 245, 198, 248, 165, 202, 168, 171, 170, 182, 234, 166, 98, 167, 163, 202,
-175, 169, 90, 203, 251, 206, 90, 171, 174, 209, 82, 209, 74, 176, 240, 212,
-178, 212, 182, 216, 169, 179, 247, 216, 167, 220, 235, 220, 241, 185, 214, 188,
-89, 229, 76, 190, 195, 194, 82, 167, 167, 201, 90, 201, 112, 164, 210, 202,
-177, 169, 98, 185, 221, 166, 110, 167, 170, 202, 178, 204, 69, 204, 71, 171,
-187, 206, 110, 174, 91, 174, 87, 212, 212, 176, 251, 212, 222, 180, 64, 216,
-199, 216, 183, 183, 64, 220, 243, 225, 118, 225, 115, 229, 94, 233, 83, 236,
-213, 196, 93, 166, 114, 174, 93, 197, 112, 204, 87, 209, 102, 177, 74, 180,
-74, 185, 231, 171, 202, 201, 212, 202, 191, 167, 192, 209, 107, 192, 171, 201,
-214, 167, 193, 204, 92, 169, 164, 206, 123, 174, 111, 174, 108, 177, 88, 212,
-253, 216, 234, 216, 225, 221, 86, 225, 169, 225, 175, 229, 107, 233, 98, 196,
-96, 164, 116, 164, 118, 166, 124, 169, 170, 177, 98, 221, 90, 188, 109, 165,
-173, 167, 200, 206, 184, 206, 181, 180, 92, 225, 181, 195, 102, 165, 175, 164,
-222, 169, 184, 221, 98, 204, 116, 177, 109, 204, 119, 174, 124, 216, 246, 185,
-253, 167, 212, 202, 221, 169, 192, 204, 175, 171, 228, 204, 125, 171, 237, 209,
-125, 206, 209, 209, 168, 209, 171, 213, 85, 216, 253, 177, 166, 180, 107, 217,
-79, 217, 75, 225, 194, 221, 113, 225, 206, 180, 110, 188, 161, 188, 166, 188,
-171, 233, 162, 233, 125, 236, 227, 195, 106, 201, 124, 180, 117, 194, 87, 174,
-176, 166, 170, 167, 232, 202, 231, 167, 220, 169, 220, 169, 215, 169, 221, 206,
-218, 174, 179, 206, 225, 174, 193, 209, 189, 174, 189, 213, 103, 177, 204, 213,
-113, 177, 180, 213, 107, 180, 161, 221, 183, 183, 112, 221, 178, 221, 185, 221,
-162, 186, 75, 225, 239, 225, 230, 229, 175, 188, 190, 190, 223, 190, 225, 236,
-237, 239, 215, 242, 67, 197, 117, 167, 241, 177, 211, 180, 178, 188, 197, 217,
-121, 225, 245, 236, 240, 177, 219, 244, 79, 202, 250, 170, 64, 206, 239, 172,
-82, 174, 207, 213, 172, 180, 182, 183, 121, 183, 122, 188, 199, 190, 231, 239,
-220, 197, 206, 179, 204, 174, 210, 164, 236, 201, 245, 167, 247, 170, 87, 170,
-81, 204, 214, 207, 91, 207, 81, 207, 67, 172, 90, 209, 236, 209, 238, 209,
-242, 209, 232, 213, 196, 177, 236, 177, 234, 177, 239, 177, 243, 180, 198, 217,
-175, 217, 172, 217, 216, 221, 210, 221, 204, 221, 205, 221, 229, 226, 74, 226,
-90, 226, 96, 225, 254, 229, 213, 229, 235, 188, 212, 188, 207, 233, 194, 233,
-221, 233, 203, 233, 212, 237, 65, 192, 208, 194, 99, 194, 103, 242, 80, 244,
-89, 245, 206, 198, 86, 209, 245, 221, 250, 233, 222, 172, 110, 204, 235, 217,
-222, 233, 226, 183, 181, 183, 182, 210, 67, 221, 253, 164, 243, 174, 240, 165,
-195, 202, 64, 166, 192, 168, 88, 168, 72, 203, 88, 205, 75, 170, 110, 204,
-242, 204, 253, 207, 161, 210, 100, 172, 120, 172, 163, 210, 76, 175, 64, 210,
-98, 175, 75, 178, 101, 213, 240, 178, 89, 178, 104, 178, 76, 181, 65, 180,
-244, 217, 243, 218, 81, 181, 70, 217, 236, 183, 200, 222, 85, 183, 201, 222,
-93, 186, 173, 230, 83, 186, 116, 186, 120, 186, 121, 230, 77, 188, 227, 188,
-235, 188, 234, 234, 64, 191, 71, 233, 244, 237, 87, 237, 88, 194, 112, 195,
-118, 244, 93, 245, 211, 246, 234, 164, 245, 205, 88, 205, 87, 172, 175, 210,
-119, 175, 79, 178, 109, 214, 79, 181, 72, 218, 92, 222, 119, 183, 220, 222,
-117, 226, 189, 186, 178, 188, 247, 234, 85, 191, 77, 237, 96, 194, 119, 242,
-105, 247, 230, 164, 247, 207, 185, 202, 66, 172, 185, 218, 106, 230, 116, 201,
-165, 168, 103, 205, 92, 207, 195, 210, 166, 218, 109, 218, 118, 222, 173, 188,
-250, 230, 161, 239, 254, 201, 167, 170, 179, 172, 197, 207, 209, 210, 181, 214,
-120, 214, 121, 218, 167, 218, 164, 222, 188, 183, 228, 226, 212, 188, 254, 237,
-102, 237, 104, 194, 123, 196, 237, 205, 111, 222, 194, 237, 112, 181, 99, 203,
-110, 172, 202, 178, 166, 183, 237, 197, 124, 172, 207, 210, 201, 178, 172, 181,
-108, 183, 242, 226, 219, 230, 179, 234, 115, 192, 247, 240, 80, 197, 125, 168,
-109, 181, 112, 244, 113, 244, 114, 178, 176, 234, 117, 207, 231, 210, 207, 214,
-176, 214, 168, 218, 189, 186, 206, 184, 64, 230, 188, 234, 120, 237, 122, 242,
-121, 218, 195, 244, 120, 207, 234, 175, 124, 210, 229, 214, 186, 218, 200, 218,
-205, 222, 232, 184, 75, 226, 245, 186, 207, 189, 87, 234, 163, 237, 166, 240,
-93, 244, 121, 248, 250, 210, 232, 214, 192, 222, 246, 186, 215, 230, 204, 248,
-183, 172, 238, 175, 178, 214, 198, 218, 215, 184, 92, 189, 94, 191, 114, 240,
-96, 165, 222, 175, 183, 223, 68, 230, 211, 196, 117, 179, 186, 196, 118, 211,
-69, 178, 199, 214, 218, 181, 167, 184, 97, 223, 73, 227, 78, 227, 79, 189,
-99, 189, 102, 234, 189, 237, 203, 237, 186, 240, 99, 240, 102, 196, 120, 246,
-250, 248, 252, 208, 71, 214, 222, 218, 233, 227, 96, 234, 202, 194, 179, 168,
-116, 211, 89, 214, 240, 178, 209, 181, 178, 181, 185, 223, 93, 223, 94, 186,
-247, 227, 99, 227, 110, 230, 240, 229, 114, 191, 162, 234, 212, 237, 220, 237,
-223, 240, 113, 195, 181, 244, 174, 247, 238, 166, 206, 242, 186, 211, 93, 184,
-112, 242, 188, 178, 220, 189, 126, 211, 99, 219, 68, 230, 246, 244, 177, 208,
-84, 191, 174, 175, 212, 219, 69, 230, 252, 197, 165, 203, 119, 170, 211, 208,
-91, 173, 68, 175, 218, 211, 109, 215, 78, 178, 231, 219, 79, 181, 198, 184,
-123, 184, 161, 227, 168, 231, 66, 234, 242, 237, 234, 249, 67, 173, 80, 191,
-179, 181, 207, 215, 87, 184, 165, 237, 240, 168, 125, 203, 162, 205, 182, 170,
-226, 205, 179, 173, 97, 208, 111, 208, 108, 211, 168, 211, 164, 211, 122, 211,
-177, 215, 94, 215, 119, 215, 108, 215, 113, 219, 167, 219, 172, 219, 106, 219,
-113, 219, 166, 223, 199, 184, 168, 223, 177, 223, 176, 223, 173, 223, 175, 227,
-174, 227, 203, 187, 99, 231, 115, 231, 88, 231, 78, 189, 177, 231, 77, 235,
-70, 235, 86, 238, 82, 238, 74, 238, 67, 240, 170, 194, 199, 195, 192, 242,
-199, 244, 193, 245, 247, 196, 245, 248, 188, 215, 123, 205, 201, 211, 196, 211,
-198, 179, 76, 215, 174, 219, 189, 219, 185, 184, 190, 187, 106, 227, 224, 227,
-217, 231, 168, 189, 190, 235, 97, 235, 98, 238, 89, 238, 88, 193, 175, 240,
-188, 242, 220, 244, 197, 246, 68, 248, 189, 166, 230, 191, 197, 211, 210, 215,
-178, 179, 79, 219, 205, 219, 207, 184, 203, 227, 247, 231, 194, 231, 200, 235,
-115, 238, 117, 195, 205, 196, 251, 202, 80, 179, 86, 191, 203, 247, 84, 168,
-164, 224, 68, 246, 76, 176, 81, 179, 96, 182, 70, 219, 226, 181, 252, 184,
-211, 224, 70, 187, 166, 189, 214, 189, 206, 231, 224, 191, 217, 191, 214, 238,
-169, 240, 218, 240, 227, 243, 66, 196, 181, 246, 80, 248, 65, 168, 166, 224,
-83, 219, 229, 193, 199, 184, 232, 168, 169, 184, 237, 184, 234, 189, 231, 235,
-183, 240, 244, 248, 69, 168, 170, 211, 228, 224, 95, 231, 239, 173, 119, 219,
-249, 219, 245, 224, 103, 228, 99, 232, 66, 231, 247, 191, 228, 240, 251, 243,
-82, 196, 188, 247, 93, 249, 171, 235, 200, 211, 232, 220, 67, 220, 64, 228,
-103, 232, 76, 235, 206, 241, 73, 197, 70, 168, 175, 197, 71, 168, 180, 208,
-182, 176, 106, 215, 227, 179, 116, 220, 78, 224, 162, 187, 190, 191, 240, 235,
-211, 202, 84, 205, 213, 173, 168, 211, 251, 215, 239, 220, 83, 224, 169, 241,
-74, 241, 77, 176, 115, 221, 115, 232, 97, 238, 200, 243, 95, 198, 93, 212,
-66, 179, 171, 220, 109, 182, 122, 220, 100, 185, 101, 185, 99, 224, 193, 228,
-120, 228, 176, 228, 123, 232, 164, 232, 116, 232, 110, 232, 105, 235, 225, 191,
-254, 192, 68, 235, 234, 193, 237, 193, 236, 241, 96, 241, 88, 241, 100, 243,
-97, 195, 237, 244, 243, 244, 251, 244, 234, 197, 75, 247, 111, 248, 76, 249,
-85, 170, 248, 182, 125, 224, 205, 236, 77, 238, 240, 245, 69, 170, 250, 203,
-173, 170, 254, 176, 164, 179, 181, 220, 163, 185, 106, 192, 72, 212, 71, 187,
-220, 171, 66, 224, 215, 192, 76, 241, 120, 197, 82, 171, 67, 192, 83, 228,
-192, 232, 178, 241, 161, 243, 163, 173, 179, 243, 166, 173, 181, 220, 172, 232,
-188, 236, 90, 239, 74, 243, 170, 197, 184, 173, 183, 196, 66, 173, 184, 182,
-186, 187, 229, 232, 196, 239, 76, 195, 73, 245, 89, 173, 186, 249, 178, 187,
-233, 190, 114, 236, 104, 239, 96, 241, 180, 243, 182, 246, 120, 197, 187, 198,
-106, 176, 169, 192, 102, 247, 164, 187, 236, 236, 111, 243, 196, 198, 75, 243,
-198, 241, 194, 228, 225, 232, 219, 236, 162, 239, 108, 241, 200, 195, 85, 243,
-202, 245, 108, 245, 106, 246, 177, 247, 182, 248, 90, 248, 218, 249, 120, 179,
-190, 232, 235, 236, 172, 236, 163, 194, 69, 241, 209, 239, 120, 243, 235, 245,
-125, 245, 121, 197, 100, 246, 197, 248, 105, 247, 196, 248, 228, 249, 207, 179,
-191, 239, 171, 197, 101, 196, 84, 239, 174, 194, 74, 247, 200, 248, 120, 246,
-208, 245, 185, 247, 204, 243, 250, 197, 198, 249, 211, 246, 213, 250, 64, 250,
-84, 250, 104, 250, 124, 250, 178, 250, 198, 250, 218, 250, 238, 251, 67, 251,
-87, 251, 107, 251, 161, 251, 181, 251, 201, 251, 221, 251, 241, 252, 70, 252,
-90, 252, 110, 252, 164, 252, 184, 252, 204, 252, 224, 252, 244, 253, 73, 253,
-93, 253, 113, 253, 167, 253, 187, 253, 207, 253, 227, 253, 247, 254, 76, 254,
-96, 254, 116, 254, 170, 254, 190, 254, 210, 254, 230, 254, 250, 142, 79, 142,
-99, 142, 119, 142, 173, 142, 193, 142, 213, 142, 233, 142, 253, 143, 82, 143,
-102, 143, 122, 143, 176, 143, 196, 143, 216, 143, 236, 144, 65, 144, 85, 144,
-105, 144, 125, 144, 179, 144, 199, 144, 219, 144, 239, 145, 68, 145, 88, 145,
-108, 145, 162, 145, 182, 145, 202, 145, 222, 145, 242, 146, 71, 146, 91, 146,
-111, 146, 165, 146, 185, 146, 205, 146, 225, 146, 245, 147, 74, 147, 94, 147,
-114, 147, 168, 147, 188, 147, 208, 147, 228, 147, 248, 148, 77, 148, 97, 148,
-117, 148, 171, 148, 191, 148, 211, 148, 231, 148, 251, 149, 80, 149, 100, 149,
-120, 149, 174, 149, 194, 149, 214, 149, 234, 149, 254, 150, 83, 150, 103, 150,
-123, 150, 177, 150, 197, 150, 217, 150, 237, 151, 66, 151, 86, 151, 106, 151,
-126, 151, 180, 151, 200, 151, 220, 151, 240, 152, 69, 152, 89, 152, 109, 152,
-163, 152, 183, 152, 203, 152, 223, 152, 243, 153, 72, 153, 92, 153, 112, 153,
-166, 153, 186, 153, 206, 153, 226, 153, 246, 154, 75, 154, 95, 154, 115, 154,
-169, 154, 189, 154, 209, 154, 229, 154, 249, 155, 78, 155, 98, 155, 118, 155,
-172, 155, 192, 155, 212, 155, 232, 155, 252, 156, 81, 156, 101, 156, 121, 156,
-175, 156, 195, 156, 215, 156, 235, 157, 64, 157, 84, 157, 104, 157, 124, 157,
-178, 157, 198, 157, 218, 157, 238, 158, 67, 158, 87, 158, 107, 158, 161, 158,
-181, 158, 201, 158, 221, 158, 241, 159, 70, 159, 90, 159, 110, 159, 164, 159,
-184, 159, 204, 159, 224, 159, 244, 160, 73, 160, 93, 160, 113, 160, 167, 160,
-187, 160, 207, 160, 227, 160, 247, 129, 76, 129, 96, 129, 116, 129, 170, 129,
-190, 129, 210, 129, 230, 129, 250, 130, 79, 130, 99, 130, 119, 130, 173, 130,
-193, 130, 213, 130, 233, 130, 253, 131, 82, 131, 102, 131, 122, 131, 176, 131,
-196, 131, 216, 131, 236, 132, 65, 132, 85, 132, 105, 132, 125, 132, 179, 132,
-199, 132, 219, 132, 239, 133, 68, 133, 88, 133, 108, 133, 162, 133, 182, 133,
-202, 133, 222, 133, 242, 134, 71, 134, 91, 134, 111, 134, 165, 134, 185, 134,
-205, 134, 225, 134, 245, 135, 74, 135, 94, 135, 114, 135, 168, 135, 188, 135,
-208, 135, 228, 135, 248, 136, 77, 136, 97, 136, 117, 136, 171, 136, 191, 136,
-211, 136, 231, 136, 251, 137, 80, 137, 100, 137, 120, 137, 174, 137, 194, 137,
-214, 137, 234, 137, 254, 138, 83, 138, 103, 138, 123, 138, 177, 138, 197, 138,
-217, 138, 237, 139, 66, 139, 86, 139, 106, 139, 126, 139, 180, 139, 200, 139,
-220, 139, 240, 140, 69, 140, 89, 140, 109, 140, 163, 140, 183, 140, 203, 140,
-223, 140, 243, 141, 72, 141, 92, 141, 112, 141, 166, 141, 186, 141, 206, 141,
-226, 141, 246, 198, 172, 198, 192, 198, 212, 198, 232, 198, 252, 199, 81, 199,
-101, 199, 121, 199, 175, 199, 195, 199, 215, 199, 235, 200, 64, 200, 84, 200,
-104, 200, 124, 200, 178, 200, 198, 200, 218, 200, 238, 255, 201, 74, 161, 74,
-161, 124, 161, 125, 161, 73, 162, 180, 162, 215, 161, 196, 162, 251, 162, 70
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP.java
deleted file mode 100644
index 2dbff5e..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP.java
+++ /dev/null
@@ -1,540 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-/** @hide
- * SEE correspondig_Android test class:
- */
-
-public class Charset_MultiByte_EUC_JP extends Charset_AbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "EUC-JP";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 162, 163, 164, /*165,*/ 166, 167, 168, 169, 170, 172, 174, 175, 176, 177, 180,
-182, 184, 186, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
-204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
-221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
-237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
-253, 254, 255, 256, 266, 278, 288, 298, 308, 318, 328, 338, 348, 358, 368, 378,
-461, 471, 501, 711, 728, 900, 910, 920, 931, 941, 951, 961, 971, 1025, 1035, 1045,
-1055, 1065, 1075, 1085, 1095, 1105, 1115, 8208, 8220, 8230, 8240, 8251, 8451, 8470, 8482, 8592,
-8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472, 9484, 9495, 9507,
-9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298, 12308, 12353, 12363,
-12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523,
-12533, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20039, 20049, 20060, 20072, 20083, 20094, 20104, 20114,
-20124, 20134, 20144, 20154, 20164, 20174, 20184, 20194, 20205, 20215, 20225, 20235, 20245, 20270, 20280, 20290,
-20300, 20310, 20320, 20330, 20341, 20351, 20361, 20371, 20381, 20395, 20405, 20415, 20425, 20436, 20447, 20462,
-20472, 20484, 20494, 20504, 20514, 20524, 20534, 20544, 20554, 20565, 20575, 20586, 20596, 20608, 20618, 20628,
-20638, 20650, 20660, 20670, 20681, 20691, 20701, 20711, 20721, 20731, 20742, 20752, 20762, 20775, 20785, 20795,
-20805, 20815, 20826, 20836, 20846, 20856, 20866, 20876, 20886, 20896, 20906, 20916, 20926, 20936, 20946, 20956,
-20966, 20976, 20986, 20996, 21006, 21016, 21026, 21038, 21048, 21059, 21069, 21079, 21089, 21102, 21112, 21122,
-21132, 21142, 21152, 21162, 21172, 21182, 21192, 21202, 21212, 21222, 21232, 21242, 21253, 21263, 21273, 21283,
-21293, 21304, 21314, 21324, 21335, 21345, 21356, 21367, 21378, 21390, 21400, 21412, 21422, 21432, 21442, 21452,
-21462, 21472, 21482, 21493, 21505, 21515, 21530, 21542, 21553, 21563, 21574, 21585, 21598, 21608, 21619, 21629,
-21640, 21650, 21660, 21670, 21681, 21691, 21702, 21720, 21730, 21740, 21750, 21760, 21772, 21782, 21802, 21813,
-21824, 21834, 21846, 21856, 21883, 21894, 21905, 21916, 21927, 21938, 21951, 21961, 21971, 21982, 21993, 22006,
-22021, 22031, 22041, 22057, 22067, 22077, 22089, 22100, 22110, 22120, 22130, 22144, 22154, 22164, 22174, 22184,
-22195, 22206, 22216, 22227, 22237, 22247, 22257, 22269, 22279, 22289, 22299, 22309, 22319, 22331, 22341, 22351,
-22369, 22379, 22389, 22399, 22409, 22419, 22429, 22439, 22451, 22461, 22471, 22482, 22492, 22502, 22512, 22522,
-22532, 22549, 22559, 22570, 22580, 22591, 22601, 22612, 22622, 22632, 22642, 22652, 22663, 22675, 22685, 22696,
-22706, 22716, 22727, 22737, 22748, 22761, 22771, 22781, 22793, 22803, 22813, 22823, 22833, 22846, 22856, 22866,
-22877, 22887, 22898, 22908, 22922, 22933, 22943, 22956, 22967, 22977, 22987, 23001, 23011, 23022, 23035, 23049,
-23059, 23070, 23080, 23093, 23104, 23116, 23130, 23141, 23159, 23179, 23190, 23200, 23212, 23224, 23234, 23244,
-23254, 23264, 23274, 23285, 23296, 23307, 23318, 23329, 23340, 23350, 23360, 23371, 23381, 23391, 23401, 23411,
-23421, 23431, 23441, 23451, 23461, 23471, 23481, 23491, 23501, 23511, 23521, 23531, 23541, 23551, 23561, 23571,
-23582, 23592, 23602, 23612, 23622, 23632, 23642, 23652, 23662, 23673, 23687, 23697, 23709, 23720, 23730, 23740,
-23751, 23762, 23773, 23784, 23794, 23805, 23815, 23825, 23835, 23846, 23857, 23869, 23880, 23890, 23900, 23913,
-23923, 23934, 23944, 23954, 23965, 23975, 23986, 23996, 24007, 24018, 24029, 24039, 24049, 24059, 24070, 24081,
-24091, 24101, 24111, 24125, 24135, 24145, 24155, 24168, 24178, 24188, 24199, 24213, 24224, 24234, 24245, 24255,
-24265, 24275, 24285, 24296, 24307, 24318, 24328, 24339, 24349, 24359, 24369, 24379, 24389, 24400, 24411, 24422,
-24432, 24442, 24452, 24463, 24473, 24484, 24494, 24504, 24515, 24525, 24535, 24545, 24555, 24565, 24575, 24586,
-24596, 24607, 24617, 24627, 24640, 24650, 24660, 24671, 24681, 24693, 24703, 24713, 24723, 24733, 24743, 24753,
-24763, 24773, 24783, 24793, 24803, 24816, 24826, 24838, 24848, 24858, 24871, 24881, 24892, 24902, 24915, 24925,
-24935, 24945, 24955, 24967, 24977, 24988, 24999, 25010, 25020, 25030, 25040, 25052, 25062, 25074, 25084, 25095,
-25105, 25115, 25126, 25136, 25147, 25158, 25168, 25178, 25188, 25198, 25209, 25219, 25229, 25239, 25254, 25265,
-25275, 25285, 25295, 25305, 25322, 25332, 25342, 25352, 25363, 25375, 25385, 25397, 25407, 25417, 25427, 25445,
-25457, 25467, 25479, 25490, 25502, 25512, 25522, 25533, 25544, 25554, 25564, 25577, 25587, 25606, 25616, 25628,
-25638, 25648, 25658, 25675, 25688, 25699, 25709, 25720, 25731, 25743, 25753, 25763, 25773, 25785, 25796, 25806,
-25816, 25826, 25836, 25846, 25856, 25866, 25876, 25886, 25897, 25908, 25918, 25928, 25938, 25949, 25959, 25970,
-25981, 25991, 26001, 26011, 26021, 26031, 26041, 26051, 26062, 26072, 26082, 26092, 26105, 26115, 26125, 26140,
-26150, 26160, 26172, 26182, 26193, 26203, 26214, 26224, 26234, 26244, 26254, 26264, 26274, 26285, 26296, 26306,
-26316, 26326, 26336, 26347, 26357, 26367, 26377, 26387, 26397, 26407, 26417, 26429, 26439, 26449, 26460, 26470,
-26480, 26491, 26501, 26511, 26521, 26534, 26544, 26555, 26565, 26575, 26585, 26596, 26606, 26617, 26627, 26643,
-26653, 26663, 26673, 26683, 26693, 26704, 26715, 26727, 26737, 26747, 26757, 26767, 26778, 26789, 26799, 26809,
-26820, 26831, 26841, 26851, 26861, 26873, 26884, 26894, 26905, 26915, 26928, 26939, 26949, 26963, 26973, 26984,
-26994, 27004, 27018, 27028, 27040, 27051, 27063, 27073, 27083, 27094, 27106, 27117, 27129, 27139, 27151, 27161,
-27171, 27182, 27192, 27204, 27214, 27224, 27234, 27249, 27262, 27273, 27287, 27298, 27308, 27320, 27330, 27340,
-27350, 27364, 27376, 27386, 27396, 27407, 27419, 27431, 27442, 27453, 27463, 27474, 27485, 27495, 27507, 27517,
-27529, 27541, 27551, 27561, 27571, 27581, 27593, 27603, 27615, 27627, 27639, 27650, 27661, 27671, 27683, 27694,
-27704, 27714, 27725, 27735, 27746, 27757, 27768, 27778, 27788, 27798, 27809, 27819, 27832, 27842, 27852, 27862,
-27872, 27882, 27892, 27908, 27918, 27929, 27941, 27951, 27961, 27972, 27991, 28001, 28012, 28023, 28034, 28044,
-28054, 28074, 28084, 28095, 28106, 28117, 28127, 28137, 28147, 28160, 28170, 28181, 28191, 28201, 28214, 28227,
-28237, 28247, 28258, 28270, 28283, 28300, 28310, 28320, 28330, 28342, 28352, 28362, 28372, 28382, 28395, 28407,
-28417, 28428, 28438, 28448, 28458, 28470, 28481, 28495, 28505, 28516, 28526, 28536, 28546, 28556, 28566, 28576,
-28586, 28597, 28608, 28618, 28628, 28638, 28648, 28659, 28669, 28679, 28689, 28699, 28710, 28720, 28732, 28744,
-28756, 28766, 28779, 28789, 28801, 28814, 28824, 28836, 28846, 28856, 28872, 28883, 28893, 28913, 28925, 28935,
-28948, 28958, 28971, 28982, 28993, 29003, 29013, 29024, 29036, 29049, 29060, 29071, 29081, 29096, 29106, 29118,
-29128, 29138, 29148, 29158, 29173, 29183, 29193, 29203, 29213, 29224, 29234, 29244, 29254, 29264, 29274, 29287,
-29297, 29307, 29319, 29330, 29344, 29356, 29366, 29377, 29388, 29398, 29408, 29420, 29431, 29442, 29453, 29463,
-29474, 29484, 29494, 29507, 29517, 29527, 29539, 29550, 29560, 29571, 29582, 29592, 29602, 29613, 29623, 29634,
-29644, 29654, 29664, 29674, 29684, 29694, 29705, 29722, 29732, 29742, 29753, 29763, 29773, 29783, 29794, 29805,
-29822, 29833, 29848, 29858, 29870, 29881, 29896, 29907, 29918, 29928, 29938, 29948, 29958, 29969, 29980, 29990,
-30000, 30010, 30020, 30030, 30041, 30052, 30063, 30073, 30085, 30095, 30105, 30115, 30129, 30140, 30150, 30162,
-30172, 30183, 30193, 30204, 30215, 30226, 30236, 30246, 30256, 30266, 30276, 30290, 30300, 30311, 30321, 30331,
-30341, 30352, 30362, 30372, 30382, 30392, 30402, 30412, 30422, 30432, 30442, 30452, 30462, 30472, 30482, 30492,
-30502, 30516, 30526, 30538, 30550, 30560, 30570, 30580, 30590, 30603, 30613, 30623, 30634, 30645, 30655, 30665,
-30677, 30687, 30697, 30707, 30722, 30732, 30749, 30759, 30770, 30783, 30796, 30812, 30824, 30834, 30844, 30854,
-30865, 30877, 30887, 30897, 30907, 30917, 30928, 30938, 30948, 30959, 30970, 30982, 30992, 31002, 31013, 31025,
-31035, 31045, 31055, 31066, 31077, 31090, 31100, 31114, 31124, 31137, 31147, 31160, 31170, 31183, 31194, 31204,
-31216, 31227, 31239, 31249, 31259, 31271, 31281, 31291, 31301, 31311, 31321, 31331, 31341, 31352, 31362, 31376,
-31390, 31401, 31411, 31423, 31433, 31443, 31453, 31464, 31476, 31486, 31496, 31508, 31518, 31528, 31539, 31549,
-31559, 31569, 31581, 31591, 31601, 31620, 31630, 31640, 31653, 31663, 31674, 31684, 31695, 31705, 31716, 31730,
-31740, 31750, 31761, 31771, 31781, 31793, 31805, 31818, 31828, 31838, 31849, 31859, 31869, 31879, 31890, 31902,
-31912, 31922, 31932, 31943, 31954, 31964, 31974, 31986, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068,
-32078, 32089, 32099, 32110, 32120, 32130, 32140, 32150, 32162, 32172, 32182, 32194, 32204, 32215, 32225, 32235,
-32245, 32256, 32266, 32277, 32287, 32299, 32309, 32319, 32330, 32340, 32350, 32361, 32371, 32381, 32391, 32401,
-32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631, 32642, 32652, 32662, 32673, 32685, 32696, 32707, 32718,
-32731, 32741, 32751, 32761, 32771, 32781, 32791, 32801, 32812, 32822, 32832, 32842, 32854, 32864, 32877, 32887,
-32897, 32907, 32918, 32929, 32939, 32952, 32963, 32973, 32983, 32993, 33005, 33016, 33026, 33046, 33056, 33068,
-33081, 33093, 33104, 33119, 33129, 33140, 33151, 33162, 33173, 33184, 33198, 33208, 33218, 33229, 33239, 33249,
-33259, 33269, 33279, 33289, 33299, 33309, 33320, 33330, 33344, 33355, 33366, 33376, 33386, 33396, 33406, 33417,
-33428, 33439, 33449, 33459, 33469, 33488, 33498, 33508, 33519, 33529, 33539, 33550, 33560, 33570, 33580, 33590,
-33600, 33610, 33620, 33648, 33659, 33669, 33682, 33692, 33702, 33713, 33725, 33735, 33745, 33756, 33768, 33778,
-33788, 33798, 33809, 33824, 33834, 33845, 33861, 33871, 33881, 33891, 33901, 33911, 33921, 33931, 33941, 33951,
-33961, 33972, 33982, 33992, 34003, 34023, 34033, 34043, 34054, 34064, 34074, 34084, 34095, 34109, 34120, 34130,
-34140, 34152, 34167, 34177, 34187, 34199, 34210, 34220, 34230, 34241, 34251, 34261, 34271, 34281, 34291, 34302,
-34314, 34326, 34337, 34349, 34360, 34370, 34381, 34391, 34401, 34411, 34421, 34440, 34451, 34465, 34475, 34485,
-34495, 34505, 34516, 34526, 34537, 34552, 34562, 34573, 34584, 34595, 34606, 34617, 34627, 34637, 34647, 34657,
-34670, 34680, 34690, 34700, 34711, 34722, 34732, 34746, 34756, 34766, 34777, 34787, 34797, 34807, 34817, 34827,
-34837, 34847, 34861, 34873, 34883, 34893, 34903, 34913, 34923, 34933, 34943, 34955, 34966, 34976, 34986, 34996,
-35006, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35109, 35120, 35130, 35140, 35151, 35162,
-35172, 35182, 35194, 35206, 35216, 35226, 35237, 35247, 35258, 35282, 35292, 35302, 35313, 35325, 35335, 35345,
-35355, 35365, 35375, 35386, 35397, 35408, 35419, 35429, 35440, 35450, 35460, 35471, 35481, 35491, 35501, 35511,
-35522, 35532, 35542, 35552, 35563, 35573, 35583, 35594, 35604, 35614, 35624, 35635, 35646, 35656, 35666, 35676,
-35686, 35696, 35708, 35722, 35732, 35742, 35895, 35905, 35915, 35925, 35937, 35947, 35957, 35970, 35980, 35992,
-36002, 36012, 36022, 36032, 36042, 36053, 36064, 36074, 36085, 36095, 36105, 36115, 36196, 36206, 36223, 36234,
-36245, 36255, 36267, 36277, 36288, 36298, 36308, 36319, 36330, 36340, 36351, 36361, 36372, 36382, 36394, 36404,
-36416, 36426, 36436, 36446, 36457, 36468, 36481, 36491, 36501, 36513, 36523, 36533, 36544, 36554, 36564, 36575,
-36587, 36599, 36610, 36620, 36630, 36640, 36650, 36660, 36670, 36681, 36691, 36701, 36763, 36773, 36783, 36794,
-36804, 36814, 36826, 36836, 36846, 36856, 36866, 36876, 36886, 36896, 36906, 36916, 36926, 36937, 36947, 36957,
-36967, 36978, 36988, 36999, 37009, 37019, 37029, 37039, 37053, 37063, 37074, 37084, 37096, 37108, 37118, 37128,
-37138, 37148, 37159, 37169, 37180, 37191, 37202, 37217, 37228, 37239, 37249, 37259, 37269, 37281, 37291, 37301,
-37311, 37321, 37331, 37341, 37351, 37361, 37371, 37381, 37392, 37404, 37414, 37424, 37434, 37444, 37454, 37464,
-37474, 37486, 37496, 37507, 37517, 37527, 37540, 37551, 37561, 37571, 37581, 37591, 37601, 37612, 37624, 37634,
-37645, 37656, 37666, 37676, 37686, 37700, 37712, 37722, 37732, 37742, 37754, 37768, 37778, 37790, 37800, 37812,
-37825, 37835, 37846, 37857, 37879, 37889, 37901, 37911, 37921, 37931, 37941, 37951, 37962, 37973, 37983, 37994,
-38005, 38015, 38263, 38274, 38284, 38294, 38304, 38315, 38326, 38339, 38349, 38360, 38370, 38428, 38438, 38449,
-38459, 38475, 38486, 38497, 38508, 38518, 38529, 38539, 38549, 38559, 38569, 38579, 38592, 38602, 38613, 38623,
-38633, 38646, 38656, 38666, 38678, 38689, 38704, 38717, 38728, 38738, 38748, 38758, 38769, 38779, 38789, 38799,
-38809, 38819, 38829, 38840, 38851, 38861, 38871, 38881, 38893, 38903, 38913, 38924, 38934, 38944, 38955, 38965,
-38980, 38990, 39000, 39010, 39020, 39080, 39092, 39103, 39116, 39131, 39141, 39151, 39164, 39175, 39185, 39195,
-39206, 39217, 39227, 39237, 39248, 39259, 39318, 39333, 39344, 39354, 39364, 39376, 39386, 39399, 39409, 39419,
-39429, 39439, 39449, 39459, 39469, 39479, 39489, 39499, 39509, 39519, 39529, 39592, 39602, 39612, 39622, 39632,
-39643, 39653, 39663, 39673, 39683, 39693, 39704, 39714, 39725, 39735, 39745, 39755, 39765, 39777, 39787, 39797,
-39807, 39817, 39827, 39837, 39847, 39857, 39867, 39878, 39888, 39899, 39909, 39919, 39929, 39940, 39951, 39961,
-39971, 39981, 39991, 40001, 40014, 40024, 40035, 40046, 40056, 40165, 40176, 40194, 40206, 40216, 40227, 40239,
-40250, 40260, 40272, 40284, 40297, 40310, 40323, 40333, 40343, 40353, 40363, 40373, 40383, 40393, 40403, 40414,
-40425, 40435, 40445, 40455, 40465, 40475, 40565, 40575, 40587, 40597, 40607, 40617, 40627, 40638, 40648, 40658,
-40668, 40679, 40689, 40699, 40711, 40721, 40731, 40742, 40753, 40763, 40773, 40783, 40794, 40806, 40816, 40826,
-40845, 40855, 40865, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401,
-65411, 65421, 65431, 65507
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-143, 162, 194, 161, 241, 161, 242, 143, 162, 240, /*92,*/ 143, 162, 195, 161, 248,
-161, 175, 143, 162, 237, 143, 162, 236, 162, 204, 143, 162, 238, 143, 162, 180,
-161, 235, 161, 222, 161, 173, 162, 249, 143, 162, 177, 143, 162, 235, 143, 162,
-196, 143, 170, 162, 143, 170, 161, 143, 170, 164, 143, 170, 170, 143, 170, 163,
-143, 170, 169, 143, 169, 161, 143, 170, 174, 143, 170, 178, 143, 170, 177, 143,
-170, 180, 143, 170, 179, 143, 170, 192, 143, 170, 191, 143, 170, 194, 143, 170,
-193, 143, 170, 208, 143, 170, 210, 143, 170, 209, 143, 170, 212, 143, 170, 216,
-143, 170, 211, 161, 223, 143, 169, 172, 143, 170, 227, 143, 170, 226, 143, 170,
-229, 143, 170, 228, 143, 170, 242, 143, 169, 176, 143, 169, 206, 143, 171, 162,
-143, 171, 161, 143, 171, 164, 143, 171, 170, 143, 171, 163, 143, 171, 169, 143,
-169, 193, 143, 171, 174, 143, 171, 178, 143, 171, 177, 143, 171, 180, 143, 171,
-179, 143, 171, 192, 143, 171, 191, 143, 171, 194, 143, 171, 193, 143, 169, 195,
-143, 171, 208, 143, 171, 210, 143, 171, 209, 143, 171, 212, 143, 171, 216, 143,
-171, 211, 161, 224, 143, 169, 204, 143, 171, 227, 143, 171, 226, 143, 171, 229,
-143, 171, 228, 143, 171, 242, 143, 169, 208, 143, 171, 243, 143, 170, 167, 143,
-170, 175, 143, 170, 182, 143, 170, 189, 143, 170, 197, 143, 170, 200, 143, 171,
-203, 143, 171, 206, 143, 169, 173, 143, 170, 221, 143, 169, 175, 143, 170, 232,
-143, 171, 245, 143, 170, 166, 143, 170, 237, 143, 171, 185, 143, 162, 176, 143,
-162, 175, 143, 162, 184, 143, 166, 233, 166, 168, 166, 178, 143, 166, 242, 166,
-199, 166, 209, 143, 166, 250, 167, 167, 143, 167, 203, 167, 166, 167, 177, 167,
-187, 167, 212, 167, 223, 167, 233, 167, 215, 143, 167, 251, 161, 190, 161, 200,
-161, 196, 162, 243, 162, 168, 161, 238, 143, 162, 241, 143, 162, 239, 162, 171,
-162, 205, 162, 207, 162, 187, 162, 229, 162, 202, 161, 232, 162, 226, 161, 226,
-162, 227, 162, 190, 162, 221, 162, 222, 168, 161, 168, 163, 168, 177, 168, 178,
-168, 184, 168, 181, 168, 182, 162, 163, 162, 165, 162, 167, 162, 161, 162, 254,
-161, 250, 161, 234, 162, 246, 161, 161, 161, 212, 161, 204, 164, 161, 164, 171,
-164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 161, 171,
-165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
-165, 245, 176, 236, 190, 229, 179, 238, 190, 231, 143, 176, 169, 182, 250, 208,
-167, 143, 176, 178, 143, 176, 179, 143, 176, 181, 143, 176, 183, 198, 253, 180,
-165, 205, 189, 184, 223, 176, 161, 203, 242, 208, 183, 191, 205, 208, 188, 208,
-186, 201, 213, 143, 176, 201, 208, 193, 208, 195, 180, 235, 143, 176, 214, 143,
-176, 217, 143, 176, 221, 191, 173, 143, 176, 231, 143, 176, 235, 143, 176, 238,
-143, 176, 223, 143, 176, 242, 202, 187, 187, 200, 143, 177, 162, 143, 177, 168,
-176, 205, 213, 165, 191, 175, 202, 216, 143, 177, 187, 208, 215, 208, 216, 189,
-164, 202, 240, 143, 177, 203, 143, 177, 207, 143, 177, 211, 143, 177, 216, 208,
-235, 182, 230, 143, 177, 223, 143, 177, 228, 208, 243, 143, 177, 236, 143, 177,
-242, 194, 166, 208, 250, 143, 177, 251, 143, 178, 163, 143, 178, 167, 143, 178,
-172, 208, 253, 183, 185, 209, 161, 143, 178, 185, 143, 178, 189, 193, 206, 143,
-178, 197, 202, 200, 143, 178, 202, 143, 178, 210, 209, 179, 143, 178, 218, 143,
-178, 223, 209, 184, 189, 188, 143, 178, 231, 197, 222, 143, 178, 237, 209, 194,
-197, 181, 209, 196, 209, 198, 209, 204, 180, 167, 209, 209, 186, 227, 143, 178,
-252, 143, 179, 161, 143, 179, 164, 244, 165, 189, 232, 209, 224, 189, 208, 209,
-227, 209, 230, 143, 179, 183, 143, 179, 184, 209, 233, 183, 244, 196, 230, 193,
-176, 143, 179, 193, 143, 179, 199, 143, 179, 201, 143, 179, 203, 143, 179, 206,
-143, 179, 209, 143, 179, 212, 178, 195, 197, 216, 207, 171, 179, 175, 143, 179,
-232, 240, 213, 143, 179, 239, 210, 171, 143, 179, 246, 188, 219, 202, 241, 210,
-183, 186, 252, 210, 186, 143, 180, 175, 210, 190, 143, 180, 182, 143, 180, 183,
-198, 238, 143, 180, 187, 143, 180, 190, 210, 203, 210, 204, 143, 180, 198, 206,
-210, 143, 180, 204, 210, 209, 143, 180, 212, 187, 178, 193, 208, 188, 232, 143,
-180, 224, 194, 254, 143, 180, 227, 210, 222, 177, 165, 143, 180, 230, 200, 221,
-143, 180, 236, 202, 173, 202, 242, 198, 221, 143, 180, 244, 188, 254, 204, 163,
-204, 191, 143, 181, 164, 210, 240, 143, 181, 170, 143, 181, 173, 143, 181, 179,
-143, 181, 183, 143, 181, 185, 211, 166, 211, 175, 143, 181, 191, 143, 181, 193,
-143, 181, 197, 143, 181, 202, 176, 162, 143, 181, 206, 143, 181, 209, 211, 177,
-143, 181, 217, 211, 183, 143, 181, 225, 211, 193, 143, 181, 232, 143, 181, 236,
-180, 238, 183, 246, 143, 181, 244, 143, 181, 245, 143, 181, 249, 143, 182, 161,
-143, 182, 165, 143, 182, 167, 143, 182, 168, 143, 182, 170, 143, 182, 175, 143,
-182, 179, 178, 222, 143, 182, 182, 143, 182, 188, 143, 182, 195, 143, 182, 199,
-143, 182, 200, 180, 239, 143, 182, 210, 211, 230, 211, 231, 211, 233, 143, 182,
-221, 143, 182, 225, 143, 182, 231, 143, 182, 233, 211, 244, 211, 247, 143, 182,
-244, 143, 182, 250, 143, 182, 252, 185, 241, 143, 183, 165, 143, 183, 168, 143,
-183, 171, 143, 183, 177, 143, 183, 182, 212, 173, 143, 183, 188, 212, 175, 212,
-179, 143, 183, 197, 143, 183, 205, 212, 180, 212, 181, 212, 182, 143, 183, 220,
-143, 183, 225, 212, 184, 143, 183, 230, 143, 183, 231, 212, 191, 199, 184, 143,
-183, 239, 143, 183, 243, 180, 240, 143, 183, 251, 194, 196, 143, 184, 165, 180,
-174, 190, 236, 143, 184, 172, 143, 184, 173, 197, 227, 186, 201, 143, 184, 183,
-212, 199, 143, 184, 185, 143, 184, 189, 202, 232, 143, 184, 199, 203, 207, 143,
-184, 206, 143, 184, 208, 195, 197, 212, 219, 212, 224, 143, 184, 221, 143, 184,
-222, 212, 232, 202, 209, 143, 184, 228, 143, 184, 231, 194, 231, 188, 186, 212,
-243, 198, 224, 143, 184, 244, 143, 184, 248, 212, 252, 143, 185, 162, 143, 185,
-167, 199, 165, 143, 185, 172, 143, 185, 174, 197, 202, 143, 185, 182, 143, 185,
-185, 187, 207, 213, 172, 143, 185, 195, 143, 185, 198, 176, 249, 213, 178, 143,
-185, 210, 143, 185, 211, 143, 185, 215, 213, 183, 213, 180, 143, 185, 223, 186,
-167, 143, 185, 228, 143, 185, 231, 143, 185, 235, 143, 185, 238, 143, 185, 243,
-143, 185, 246, 143, 185, 251, 213, 191, 183, 249, 213, 197, 143, 186, 167, 143,
-186, 169, 143, 186, 171, 143, 186, 174, 213, 201, 213, 202, 143, 186, 182, 196,
-220, 213, 206, 213, 210, 143, 186, 187, 213, 212, 204, 210, 213, 216, 213, 218,
-143, 186, 196, 177, 167, 143, 186, 205, 176, 184, 205, 168, 143, 186, 213, 205,
-198, 213, 227, 143, 186, 221, 143, 186, 224, 178, 201, 213, 237, 195, 254, 188,
-247, 176, 211, 213, 245, 143, 186, 235, 213, 248, 143, 186, 244, 198, 244, 213,
-252, 214, 161, 143, 186, 248, 193, 216, 214, 165, 214, 168, 143, 187, 169, 214,
-170, 143, 187, 174, 193, 187, 143, 187, 181, 214, 176, 214, 180, 143, 187, 187,
-143, 187, 188, 178, 229, 143, 187, 192, 214, 183, 191, 242, 214, 194, 214, 193,
-143, 187, 201, 143, 187, 203, 143, 187, 206, 143, 187, 211, 214, 201, 214, 191,
-191, 243, 214, 205, 143, 187, 226, 143, 187, 230, 143, 187, 232, 214, 211, 143,
-187, 240, 143, 230, 244, 214, 217, 143, 187, 247, 214, 221, 192, 238, 185, 170,
-184, 202, 180, 172, 200, 193, 214, 230, 214, 231, 191, 227, 194, 211, 203, 185,
-214, 243, 143, 188, 181, 143, 188, 184, 143, 188, 187, 180, 179, 205, 196, 200,
-223, 196, 236, 214, 249, 143, 188, 201, 176, 195, 143, 188, 207, 206, 247, 179,
-199, 215, 163, 215, 168, 215, 172, 215, 176, 143, 188, 223, 181, 221, 143, 188,
-227, 184, 204, 188, 229, 143, 188, 239, 143, 188, 244, 143, 188, 247, 143, 188,
-250, 201, 167, 190, 180, 143, 189, 166, 183, 194, 143, 189, 171, 215, 208, 143,
-189, 178, 200, 249, 143, 189, 183, 191, 180, 199, 166, 187, 214, 143, 189, 195,
-178, 247, 199, 176, 215, 221, 143, 189, 210, 143, 189, 213, 143, 189, 217, 215,
-226, 143, 189, 220, 143, 189, 222, 215, 240, 143, 189, 228, 215, 239, 178, 184,
-183, 195, 143, 189, 236, 188, 189, 143, 189, 243, 143, 189, 246, 216, 166, 143,
-189, 253, 143, 190, 161, 190, 240, 143, 190, 170, 143, 190, 173, 193, 218, 194,
-198, 216, 185, 216, 180, 143, 190, 188, 182, 242, 216, 195, 143, 190, 202, 216,
-198, 143, 190, 209, 216, 216, 216, 215, 183, 197, 216, 213, 143, 190, 216, 216,
-220, 216, 225, 143, 190, 229, 198, 180, 183, 251, 143, 190, 239, 216, 234, 178,
-251, 143, 190, 246, 216, 239, 196, 168, 216, 246, 143, 191, 167, 178, 230, 216,
-254, 192, 239, 217, 165, 204, 225, 143, 191, 182, 143, 191, 184, 143, 191, 189,
-143, 191, 191, 202, 177, 200, 227, 217, 183, 143, 191, 197, 185, 179, 143, 191,
-201, 202, 250, 217, 187, 195, 180, 217, 188, 192, 219, 143, 191, 214, 143, 191,
-216, 189, 166, 217, 205, 143, 191, 225, 182, 180, 143, 191, 228, 143, 191, 231,
-193, 222, 194, 170, 143, 191, 244, 143, 191, 248, 143, 191, 252, 199, 177, 143,
-192, 167, 199, 211, 143, 192, 174, 191, 228, 183, 199, 143, 192, 180, 143, 192,
-183, 217, 231, 143, 192, 189, 217, 226, 143, 192, 195, 217, 236, 143, 192, 201,
-217, 211, 217, 238, 143, 192, 213, 183, 200, 143, 192, 217, 197, 166, 143, 192,
-230, 143, 192, 231, 204, 206, 183, 226, 143, 192, 238, 143, 192, 242, 143, 192,
-247, 199, 197, 179, 201, 143, 193, 161, 143, 193, 166, 218, 166, 197, 167, 181,
-188, 218, 177, 218, 181, 143, 193, 185, 143, 193, 188, 143, 193, 192, 143, 193,
-196, 218, 189, 202, 252, 218, 195, 143, 193, 206, 218, 201, 143, 193, 210, 218,
-202, 143, 193, 213, 202, 184, 200, 195, 218, 207, 192, 205, 187, 219, 202, 253,
-218, 211, 143, 193, 232, 143, 193, 236, 180, 251, 189, 220, 143, 193, 242, 218,
-224, 143, 193, 249, 218, 230, 143, 194, 166, 143, 194, 172, 195, 235, 143, 194,
-179, 143, 194, 182, 143, 194, 187, 179, 162, 218, 242, 195, 210, 218, 247, 218,
-245, 218, 248, 196, 170, 143, 194, 217, 219, 162, 143, 194, 224, 143, 194, 227,
-219, 163, 219, 165, 143, 194, 234, 219, 170, 194, 216, 205, 173, 143, 194, 241,
-196, 171, 219, 176, 188, 235, 181, 224, 143, 194, 249, 194, 188, 197, 206, 143,
-195, 161, 219, 191, 143, 195, 166, 219, 199, 143, 195, 170, 143, 195, 175, 219,
-197, 143, 195, 177, 143, 195, 181, 143, 195, 188, 199, 240, 143, 195, 193, 219,
-207, 219, 211, 143, 195, 184, 198, 202, 192, 242, 143, 195, 204, 143, 195, 207,
-143, 195, 212, 143, 195, 214, 143, 195, 217, 182, 205, 143, 195, 223, 201, 176,
-143, 195, 228, 143, 195, 233, 199, 223, 219, 231, 143, 195, 241, 143, 195, 245,
-196, 244, 219, 238, 180, 254, 143, 195, 254, 143, 196, 165, 220, 168, 143, 196,
-173, 220, 170, 220, 166, 196, 199, 191, 250, 220, 176, 220, 191, 143, 196, 193,
-143, 196, 195, 201, 246, 220, 194, 143, 196, 204, 143, 196, 209, 207, 176, 186,
-231, 207, 177, 220, 213, 143, 196, 222, 143, 196, 225, 220, 201, 185, 189, 143,
-196, 232, 143, 196, 234, 220, 229, 220, 223, 143, 196, 244, 143, 196, 245, 201,
-184, 220, 235, 220, 211, 220, 247, 220, 237, 143, 197, 170, 181, 204, 220, 243,
-143, 197, 180, 143, 197, 182, 143, 197, 187, 221, 161, 220, 253, 221, 168, 221,
-166, 221, 165, 143, 197, 206, 143, 197, 210, 143, 197, 213, 143, 197, 216, 221,
-178, 205, 243, 143, 197, 226, 143, 197, 230, 178, 164, 205, 223, 182, 214, 221,
-188, 143, 197, 244, 143, 197, 247, 143, 197, 249, 186, 208, 143, 197, 254, 189,
-222, 221, 205, 143, 198, 166, 143, 198, 171, 221, 213, 143, 198, 178, 143, 198,
-182, 221, 218, 221, 219, 221, 221, 143, 198, 192, 143, 198, 195, 143, 198, 199,
-181, 164, 221, 230, 143, 198, 209, 177, 202, 181, 225, 143, 198, 218, 180, 192,
-221, 233, 143, 198, 226, 143, 198, 230, 221, 235, 198, 217, 178, 173, 203, 215,
-203, 247, 202, 168, 143, 198, 246, 200, 231, 143, 198, 254, 143, 199, 163, 222,
-165, 143, 199, 170, 143, 199, 171, 143, 199, 174, 222, 172, 196, 197, 143, 199,
-184, 143, 199, 186, 190, 244, 143, 199, 189, 143, 199, 192, 179, 189, 179, 164,
-143, 199, 198, 205, 176, 143, 199, 203, 143, 199, 206, 143, 199, 208, 143, 199,
-212, 143, 199, 215, 222, 204, 143, 199, 221, 143, 199, 225, 189, 223, 143, 199,
-231, 222, 189, 222, 188, 222, 219, 178, 185, 143, 199, 237, 222, 220, 222, 218,
-143, 199, 251, 143, 200, 161, 222, 208, 143, 200, 165, 200, 174, 189, 224, 143,
-200, 170, 222, 228, 205, 207, 143, 200, 178, 143, 200, 183, 222, 237, 194, 218,
-143, 200, 187, 223, 163, 181, 249, 143, 200, 196, 143, 200, 198, 199, 249, 143,
-200, 204, 143, 200, 208, 222, 243, 143, 200, 212, 143, 200, 217, 189, 225, 196,
-172, 223, 166, 223, 173, 143, 200, 231, 143, 200, 237, 143, 200, 240, 223, 186,
-143, 200, 248, 183, 227, 143, 200, 254, 223, 190, 143, 201, 162, 143, 201, 163,
-223, 171, 143, 201, 169, 143, 201, 173, 223, 198, 223, 202, 195, 245, 223, 208,
-143, 201, 182, 143, 201, 185, 143, 201, 189, 143, 201, 192, 178, 208, 143, 201,
-198, 143, 201, 201, 177, 234, 143, 201, 208, 143, 201, 210, 223, 220, 223, 218,
-206, 245, 143, 201, 218, 223, 223, 223, 216, 223, 226, 143, 201, 230, 177, 235,
-143, 201, 234, 143, 201, 236, 193, 179, 143, 201, 242, 143, 201, 247, 223, 230,
-143, 201, 254, 223, 236, 143, 202, 162, 223, 239, 223, 237, 244, 166, 223, 241,
-143, 202, 174, 223, 245, 197, 245, 223, 246, 143, 202, 187, 187, 184, 223, 253,
-224, 162, 143, 202, 193, 143, 202, 194, 143, 202, 197, 224, 166, 224, 170, 224,
-172, 224, 175, 143, 202, 211, 143, 202, 215, 203, 210, 143, 202, 224, 143, 202,
-227, 224, 182, 224, 183, 181, 190, 184, 164, 190, 245, 143, 202, 242, 143, 202,
-245, 143, 202, 247, 224, 195, 198, 200, 224, 198, 143, 203, 162, 143, 203, 167,
-224, 200, 143, 203, 173, 143, 203, 177, 205, 177, 143, 203, 184, 143, 203, 185,
-224, 213, 189, 195, 143, 203, 199, 224, 217, 143, 203, 207, 143, 203, 210, 143,
-203, 215, 143, 203, 220, 143, 203, 225, 143, 203, 227, 178, 209, 143, 203, 236,
-143, 203, 240, 188, 238, 183, 190, 143, 203, 248, 184, 189, 206, 176, 143, 204,
-168, 143, 204, 170, 143, 204, 178, 143, 204, 182, 143, 204, 184, 143, 204, 189,
-143, 204, 192, 143, 204, 194, 143, 204, 199, 224, 247, 143, 204, 208, 143, 204,
-213, 224, 229, 143, 204, 226, 143, 204, 231, 143, 204, 234, 143, 204, 238, 143,
-204, 242, 143, 204, 245, 225, 166, 143, 204, 252, 143, 204, 254, 185, 249, 197,
-188, 225, 180, 197, 196, 196, 174, 225, 183, 143, 205, 180, 206, 177, 225, 191,
-143, 205, 187, 143, 205, 189, 143, 205, 196, 193, 193, 143, 205, 201, 225, 207,
-225, 215, 225, 214, 143, 205, 211, 225, 218, 143, 205, 216, 143, 205, 221, 143,
-205, 225, 225, 224, 143, 205, 231, 143, 205, 236, 143, 205, 242, 143, 205, 247,
-225, 240, 143, 206, 161, 143, 206, 167, 204, 254, 225, 245, 225, 252, 143, 206,
-179, 197, 208, 143, 206, 182, 187, 169, 226, 173, 143, 206, 193, 200, 233, 226,
-176, 226, 179, 143, 206, 205, 226, 181, 143, 206, 209, 226, 187, 196, 190, 189,
-226, 226, 190, 143, 206, 222, 143, 206, 228, 226, 197, 143, 206, 234, 143, 206,
-239, 143, 206, 243, 143, 206, 248, 143, 206, 253, 143, 207, 163, 143, 207, 168,
-226, 208, 226, 211, 143, 207, 176, 143, 207, 179, 143, 207, 182, 143, 207, 186,
-226, 218, 143, 207, 189, 143, 207, 192, 143, 207, 195, 182, 235, 192, 208, 186,
-189, 226, 230, 143, 207, 212, 181, 206, 203, 164, 185, 220, 143, 207, 225, 143,
-207, 228, 143, 207, 234, 200, 163, 226, 239, 226, 238, 200, 234, 143, 207, 244,
-202, 203, 143, 207, 252, 143, 208, 161, 226, 252, 200, 216, 227, 162, 143, 208,
-173, 176, 235, 143, 208, 185, 143, 208, 188, 143, 208, 190, 143, 208, 191, 143,
-208, 196, 143, 208, 200, 143, 208, 203, 143, 208, 207, 143, 208, 211, 227, 175,
-190, 205, 143, 208, 220, 143, 208, 223, 227, 180, 143, 208, 229, 143, 208, 235,
-143, 208, 238, 143, 208, 242, 143, 208, 244, 143, 208, 249, 143, 208, 252, 199,
-233, 190, 206, 176, 220, 143, 209, 172, 143, 209, 176, 143, 209, 178, 143, 209,
-181, 227, 202, 227, 203, 143, 209, 192, 178, 186, 143, 209, 198, 190, 247, 143,
-209, 206, 143, 209, 208, 143, 209, 211, 143, 209, 216, 143, 209, 219, 227, 221,
-143, 209, 223, 227, 227, 143, 209, 229, 227, 234, 227, 237, 143, 209, 234, 143,
-209, 239, 143, 209, 242, 181, 232, 143, 209, 244, 227, 250, 227, 252, 227, 247,
-143, 210, 163, 143, 210, 167, 195, 222, 228, 184, 228, 170, 228, 172, 143, 210,
-180, 143, 210, 182, 228, 176, 143, 210, 189, 143, 210, 191, 143, 210, 196, 200,
-207, 228, 189, 143, 210, 207, 198, 198, 143, 210, 212, 143, 210, 218, 143, 210,
-224, 228, 194, 143, 210, 231, 143, 210, 233, 143, 210, 237, 228, 213, 143, 210,
-244, 228, 216, 143, 210, 254, 143, 211, 164, 202, 198, 143, 211, 171, 143, 211,
-173, 206, 179, 143, 211, 176, 228, 234, 228, 236, 143, 211, 184, 143, 211, 187,
-228, 245, 228, 246, 143, 211, 199, 228, 250, 181, 234, 143, 211, 205, 143, 211,
-209, 229, 162, 143, 211, 215, 186, 217, 186, 176, 193, 200, 229, 174, 143, 211,
-230, 229, 179, 229, 177, 143, 211, 238, 143, 211, 243, 143, 211, 249, 143, 211,
-252, 229, 194, 188, 250, 143, 212, 166, 143, 212, 169, 143, 212, 174, 143, 212,
-177, 229, 206, 143, 212, 184, 143, 212, 187, 143, 212, 179, 229, 208, 143, 212,
-194, 229, 213, 203, 165, 229, 220, 143, 212, 206, 193, 161, 191, 165, 229, 229,
-229, 234, 143, 212, 221, 229, 239, 143, 212, 226, 143, 212, 229, 229, 251, 180,
-204, 143, 212, 240, 230, 163, 230, 169, 143, 212, 250, 143, 212, 254, 200, 237,
-230, 176, 230, 181, 143, 213, 171, 143, 213, 174, 143, 213, 178, 230, 192, 143,
-213, 183, 143, 213, 185, 143, 213, 187, 143, 213, 190, 143, 213, 194, 230, 203,
-185, 205, 143, 213, 203, 204, 215, 230, 212, 143, 213, 216, 204, 237, 143, 213,
-226, 230, 216, 192, 187, 143, 213, 228, 143, 213, 231, 191, 166, 143, 213, 234,
-207, 190, 190, 211, 184, 212, 143, 213, 241, 143, 213, 242, 176, 223, 143, 213,
-245, 143, 213, 250, 184, 213, 143, 213, 253, 182, 187, 187, 233, 143, 214, 170,
-143, 214, 175, 143, 214, 178, 196, 177, 143, 214, 183, 201, 229, 231, 181, 143,
-214, 193, 231, 171, 194, 220, 231, 174, 231, 178, 231, 177, 143, 214, 209, 231,
-187, 231, 190, 231, 193, 143, 214, 220, 143, 214, 224, 143, 214, 226, 143, 214,
-231, 143, 214, 236, 218, 170, 143, 214, 240, 143, 214, 244, 143, 214, 247, 143,
-214, 248, 231, 217, 143, 215, 161, 143, 215, 165, 143, 215, 167, 231, 226, 143,
-215, 171, 231, 232, 143, 215, 180, 143, 215, 184, 231, 236, 143, 215, 195, 203,
-167, 178, 234, 143, 215, 207, 143, 215, 209, 143, 215, 212, 143, 215, 216, 231,
-249, 231, 247, 183, 212, 232, 173, 143, 215, 233, 143, 215, 234, 195, 227, 232,
-166, 183, 213, 143, 215, 227, 143, 215, 253, 178, 174, 232, 174, 143, 216, 168,
-143, 216, 174, 143, 216, 176, 205, 233, 232, 207, 143, 216, 183, 143, 216, 187,
-186, 218, 143, 216, 191, 232, 203, 143, 216, 196, 143, 216, 198, 143, 216, 201,
-232, 206, 232, 212, 232, 226, 143, 216, 207, 143, 216, 212, 143, 216, 217, 198,
-161, 232, 211, 232, 216, 143, 216, 232, 190, 213, 143, 216, 236, 232, 231, 143,
-216, 240, 143, 216, 244, 143, 216, 247, 143, 216, 251, 143, 216, 254, 143, 217,
-162, 143, 217, 166, 143, 217, 171, 232, 209, 143, 217, 178, 177, 182, 143, 217,
-183, 143, 217, 188, 202, 195, 232, 254, 143, 217, 197, 143, 217, 201, 207, 207,
-233, 177, 143, 217, 216, 143, 217, 220, 177, 242, 143, 217, 228, 204, 244, 143,
-217, 232, 207, 206, 143, 217, 242, 233, 185, 143, 217, 247, 200, 205, 143, 217,
-252, 233, 193, 233, 190, 221, 177, 143, 218, 174, 205, 246, 143, 218, 178, 143,
-218, 183, 233, 200, 143, 218, 188, 143, 218, 193, 195, 238, 143, 218, 200, 143,
-218, 237, 233, 206, 143, 218, 210, 233, 219, 143, 218, 218, 143, 218, 222, 233,
-217, 233, 220, 233, 221, 233, 222, 194, 253, 203, 170, 233, 235, 195, 216, 143,
-218, 254, 143, 219, 162, 143, 219, 166, 143, 219, 172, 143, 219, 174, 233, 251,
-143, 219, 177, 233, 253, 233, 247, 234, 167, 143, 219, 192, 143, 219, 196, 234,
-165, 143, 219, 203, 205, 230, 234, 175, 143, 219, 214, 143, 219, 217, 143, 219,
-222, 143, 219, 226, 234, 187, 143, 219, 232, 143, 219, 237, 234, 192, 143, 219,
-248, 143, 219, 250, 234, 197, 143, 220, 164, 222, 167, 179, 185, 185, 213, 234,
-206, 234, 210, 182, 222, 194, 222, 194, 181, 143, 220, 190, 143, 220, 192, 184,
-211, 143, 220, 195, 143, 220, 197, 234, 227, 143, 220, 206, 234, 235, 234, 236,
-234, 233, 143, 220, 214, 179, 236, 143, 220, 222, 234, 243, 143, 220, 228, 143,
-220, 233, 234, 247, 143, 220, 240, 143, 220, 243, 235, 162, 143, 220, 250, 143,
-220, 254, 202, 164, 143, 221, 166, 179, 208, 143, 221, 173, 235, 178, 235, 180,
-179, 209, 235, 185, 191, 168, 143, 221, 189, 143, 221, 193, 143, 221, 197, 143,
-221, 199, 235, 194, 235, 196, 143, 221, 210, 191, 199, 143, 221, 217, 186, 190,
-235, 199, 143, 221, 229, 181, 205, 143, 221, 235, 235, 209, 143, 221, 243, 143,
-221, 248, 235, 216, 198, 201, 143, 222, 162, 235, 219, 180, 210, 207, 192, 235,
-227, 235, 221, 143, 222, 180, 143, 222, 183, 143, 222, 191, 235, 226, 143, 222,
-189, 235, 245, 235, 240, 235, 244, 143, 222, 201, 143, 222, 202, 201, 232, 183,
-217, 181, 196, 143, 222, 213, 218, 206, 143, 222, 221, 143, 222, 224, 195, 171,
-236, 175, 143, 222, 233, 236, 181, 190, 221, 208, 174, 143, 222, 250, 236, 186,
-203, 198, 236, 194, 185, 215, 192, 213, 236, 202, 178, 236, 194, 177, 143, 223,
-178, 199, 229, 188, 193, 143, 223, 187, 143, 223, 191, 143, 223, 194, 236, 219,
-192, 214, 143, 223, 201, 143, 223, 202, 177, 219, 143, 223, 209, 143, 223, 211,
-143, 223, 214, 143, 223, 218, 143, 223, 222, 143, 223, 227, 143, 223, 230, 236,
-240, 236, 238, 143, 223, 242, 236, 245, 236, 244, 143, 223, 250, 236, 247, 237,
-169, 236, 253, 143, 224, 171, 236, 254, 143, 224, 177, 143, 224, 181, 143, 224,
-184, 189, 179, 237, 175, 237, 179, 143, 224, 198, 237, 186, 191, 200, 143, 224,
-209, 143, 224, 212, 188, 214, 143, 224, 219, 198, 240, 237, 199, 143, 224, 225,
-143, 224, 230, 237, 210, 143, 224, 235, 143, 224, 239, 206, 216, 143, 224, 248,
-237, 217, 237, 219, 143, 225, 166, 143, 225, 170, 191, 201, 143, 225, 177, 237,
-231, 202, 213, 203, 248, 183, 222, 237, 233, 143, 225, 195, 143, 225, 197, 237,
-254, 143, 225, 203, 143, 225, 206, 237, 248, 194, 164, 143, 225, 212, 143, 225,
-216, 238, 167, 238, 166, 198, 187, 143, 225, 223, 143, 225, 226, 238, 175, 206,
-203, 237, 238, 205, 184, 143, 225, 241, 143, 225, 245, 238, 184, 143, 225, 251,
-143, 226, 163, 143, 226, 173, 143, 226, 169, 201, 244, 143, 226, 178, 143, 226,
-179, 143, 226, 185, 238, 192, 143, 226, 193, 143, 226, 199, 143, 226, 203, 143,
-226, 209, 143, 226, 212, 188, 242, 143, 226, 220, 189, 183, 185, 243, 143, 226,
-228, 238, 204, 143, 226, 237, 143, 226, 240, 238, 208, 238, 211, 143, 226, 254,
-238, 216, 143, 227, 164, 191, 203, 182, 252, 143, 227, 179, 143, 227, 182, 143,
-227, 187, 143, 227, 193, 143, 227, 198, 143, 227, 203, 143, 227, 207, 143, 227,
-213, 197, 180, 143, 227, 223, 143, 227, 226, 200, 173, 143, 227, 236, 143, 227,
-242, 189, 198, 143, 227, 251, 143, 227, 254, 143, 228, 164, 143, 228, 169, 238,
-248, 143, 228, 181, 143, 228, 188, 143, 228, 193, 143, 228, 200, 143, 228, 205,
-181, 248, 143, 228, 212, 143, 228, 214, 191, 238, 239, 162, 207, 163, 143, 228,
-230, 238, 253, 143, 228, 235, 143, 228, 241, 143, 228, 243, 239, 171, 143, 229,
-161, 143, 229, 167, 143, 229, 172, 143, 229, 176, 143, 229, 181, 143, 229, 183,
-143, 229, 188, 143, 229, 195, 239, 178, 182, 192, 143, 229, 207, 143, 229, 212,
-143, 229, 217, 143, 229, 222, 239, 197, 239, 195, 239, 196, 143, 229, 231, 143,
-229, 236, 143, 229, 238, 143, 229, 241, 239, 206, 239, 209, 239, 216, 196, 185,
-239, 217, 143, 230, 164, 239, 221, 239, 224, 143, 230, 173, 143, 230, 176, 239,
-234, 239, 235, 198, 174, 239, 243, 201, 236, 143, 230, 201, 143, 230, 203, 193,
-203, 239, 251, 143, 230, 214, 143, 230, 217, 240, 165, 198, 171, 143, 230, 224,
-231, 161, 240, 168, 143, 230, 233, 143, 230, 237, 143, 230, 240, 191, 253, 143,
-230, 242, 240, 186, 143, 230, 249, 143, 230, 250, 206, 237, 188, 251, 206, 238,
-240, 195, 143, 231, 167, 240, 199, 240, 201, 240, 205, 192, 196, 240, 208, 240,
-211, 240, 215, 143, 231, 191, 240, 217, 240, 223, 143, 231, 199, 240, 228, 202,
-220, 143, 231, 210, 240, 231, 143, 231, 223, 143, 231, 228, 143, 231, 235, 240,
-236, 143, 231, 240, 202, 199, 240, 243, 143, 231, 249, 143, 231, 252, 143, 232,
-161, 143, 232, 167, 143, 232, 170, 179, 220, 180, 234, 143, 232, 180, 143, 232,
-185, 201, 247, 143, 232, 190, 143, 232, 195, 143, 232, 199, 200, 244, 143, 232,
-202, 200, 211, 187, 244, 143, 232, 209, 143, 232, 211, 143, 232, 216, 143, 232,
-220, 143, 232, 223, 143, 232, 230, 241, 189, 241, 190, 143, 232, 242, 188, 243,
-241, 198, 143, 232, 251, 143, 233, 162, 194, 204, 195, 243, 143, 233, 170, 143,
-233, 173, 241, 209, 241, 211, 241, 215, 241, 214, 241, 217, 143, 233, 194, 143,
-233, 197, 241, 219, 143, 233, 204, 143, 233, 207, 241, 225, 241, 229, 241, 233,
-185, 252, 143, 233, 218, 241, 238, 143, 233, 228, 143, 233, 231, 143, 233, 236,
-143, 233, 240, 241, 249, 143, 233, 247, 143, 233, 254, 143, 234, 167, 242, 163,
-242, 166, 143, 234, 178, 143, 234, 182, 179, 161, 143, 234, 187, 143, 234, 189,
-143, 234, 194, 143, 234, 200, 143, 234, 205, 143, 234, 209, 143, 234, 215, 242,
-184, 143, 234, 223, 143, 234, 226, 143, 234, 230, 143, 234, 234, 242, 196, 143,
-234, 242, 194, 228, 143, 234, 247, 143, 234, 251, 143, 235, 161, 242, 218, 143,
-235, 168, 143, 235, 172, 143, 235, 177, 201, 201, 143, 235, 186, 143, 235, 188,
-143, 235, 194, 143, 235, 200, 143, 235, 205, 143, 235, 211, 242, 233, 196, 187,
-242, 236, 143, 235, 222, 178, 170, 143, 235, 225, 242, 245, 143, 235, 229, 143,
-235, 234, 242, 247, 243, 165, 177, 173, 143, 235, 248, 143, 235, 252, 143, 236,
-163, 143, 236, 167, 143, 236, 173, 143, 236, 175, 243, 170, 143, 236, 180, 143,
-236, 183, 143, 236, 186, 243, 186, 143, 236, 193, 143, 236, 198, 143, 236, 202,
-243, 191, 143, 236, 207, 143, 236, 210, 243, 193, 243, 195, 188, 175, 243, 200,
-243, 203, 206, 219, 243, 207, 143, 236, 238, 221, 224, 143, 236, 242, 185, 245,
-243, 217, 143, 236, 247, 143, 236, 252, 243, 228, 243, 231, 143, 237, 168, 143,
-237, 175, 143, 237, 178, 143, 237, 182, 201, 161, 143, 237, 194, 240, 237, 143,
-237, 202, 243, 245, 143, 237, 210, 143, 237, 214, 206, 182, 143, 237, 222, 143,
-237, 224, 161, 170, 161, 220, 163, 181, 161, 169, 163, 201, 163, 211, 161, 207,
-163, 231, 163, 241, 161, 208, 142, 165, 142, 175, 142, 185, 142, 195, 142, 205,
-142, 215, 161, 177
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Duplicate Characters.",
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic () throws CharacterCodingException {
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- CharBuffer inputCB = CharBuffer.allocate(65536);
- for (int code = 32; code <= 65533; code ++) {
- if ((encoder.canEncode((char) code))
- && (code != 165) && (code != 8254)) {
- inputCB.put((char) code);
- }
- }
- inputCB.rewind();
- ByteBuffer intermediateBB = encoder.encode(inputCB);
- inputCB.rewind();
- intermediateBB.rewind();
- CharBuffer outputCB = decoder.decode(intermediateBB);
- outputCB.rewind();
- assertEqualCBs("decode(encode(A)) must be identical with A!",
- inputCB, outputCB);
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP_Android.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP_Android.java
deleted file mode 100644
index 3f80cd8..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_JP_Android.java
+++ /dev/null
@@ -1,534 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.CodingErrorAction;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_MultiByte_EUC_JP_Android extends Charset_AbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "EUC-JP";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 162, 163, 164, /*165,*/ 166, 167, 168, 169, 170, 172, 174, 175, 176, 177, 180,
-182, 184, 186, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
-204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
-221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
-237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252,
-253, 254, 255, 256, 266, 278, 288, 298, 308, 318, 328, 338, 348, 358, 368, 378,
-461, 471, 501, 711, 728, 900, 910, 920, 931, 941, 951, 961, 971, 1025, 1035, 1045,
-1055, 1065, 1075, 1085, 1095, 1105, 1115, 8208, 8220, 8230, 8240, 8251, 8451, 8470, 8482, 8592,
-8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472, 9484, 9495, 9507,
-9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298, 12308, 12353, 12363,
-12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523,
-12533, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20039, 20049, 20060, 20072, 20083, 20094, 20104, 20114,
-20124, 20134, 20144, 20154, 20164, 20174, 20184, 20194, 20205, 20215, 20225, 20235, 20245, 20270, 20280, 20290,
-20300, 20310, 20320, 20330, 20341, 20351, 20361, 20371, 20381, 20395, 20405, 20415, 20425, 20436, 20447, 20462,
-20472, 20484, 20494, 20504, 20514, 20524, 20534, 20544, 20554, 20565, 20575, 20586, 20596, 20608, 20618, 20628,
-20638, 20650, 20660, 20670, 20681, 20691, 20701, 20711, 20721, 20731, 20742, 20752, 20762, 20775, 20785, 20795,
-20805, 20815, 20826, 20836, 20846, 20856, 20866, 20876, 20886, 20896, 20906, 20916, 20926, 20936, 20946, 20956,
-20966, 20976, 20986, 20996, 21006, 21016, 21026, 21038, 21048, 21059, 21069, 21079, 21089, 21102, 21112, 21122,
-21132, 21142, 21152, 21162, 21172, 21182, 21192, 21202, 21212, 21222, 21232, 21242, 21253, 21263, 21273, 21283,
-21293, 21304, 21314, 21324, 21335, 21345, 21356, 21367, 21378, 21390, 21400, 21412, 21422, 21432, 21442, 21452,
-21462, 21472, 21482, 21493, 21505, 21515, 21530, 21542, 21553, 21563, 21574, 21585, 21598, 21608, 21619, 21629,
-21640, 21650, 21660, 21670, 21681, 21691, 21702, 21720, 21730, 21740, 21750, 21760, 21772, 21782, 21802, 21813,
-21824, 21834, 21846, 21856, 21883, 21894, 21905, 21916, 21927, 21938, 21951, 21961, 21971, 21982, 21993, 22006,
-22021, 22031, 22041, 22057, 22067, 22077, 22089, 22100, 22110, 22120, 22130, 22144, 22154, 22164, 22174, 22184,
-22195, 22206, 22216, 22227, 22237, 22247, 22257, 22269, 22279, 22289, 22299, 22309, 22319, 22331, 22341, 22351,
-22369, 22379, 22389, 22399, 22409, 22419, 22429, 22439, 22451, 22461, 22471, 22482, 22492, 22502, 22512, 22522,
-22532, 22549, 22559, 22570, 22580, 22591, 22601, 22612, 22622, 22632, 22642, 22652, 22663, 22675, 22685, 22696,
-22706, 22716, 22727, 22737, 22748, 22761, 22771, 22781, 22793, 22803, 22813, 22823, 22833, 22846, 22856, 22866,
-22877, 22887, 22898, 22908, 22922, 22933, 22943, 22956, 22967, 22977, 22987, 23001, 23011, 23022, 23035, 23049,
-23059, 23070, 23080, 23093, 23104, 23116, 23130, 23141, 23159, 23179, 23190, 23200, 23212, 23224, 23234, 23244,
-23254, 23264, 23274, 23285, 23296, 23307, 23318, 23329, 23340, 23350, 23360, 23371, 23381, 23391, 23401, 23411,
-23421, 23431, 23441, 23451, 23461, 23471, 23481, 23491, 23501, 23511, 23521, 23531, 23541, 23551, 23561, 23571,
-23582, 23592, 23602, 23612, 23622, 23632, 23642, 23652, 23662, 23673, 23687, 23697, 23709, 23720, 23730, 23740,
-23751, 23762, 23773, 23784, 23794, 23805, 23815, 23825, 23835, 23846, 23857, 23869, 23880, 23890, 23900, 23913,
-23923, 23934, 23944, 23954, 23965, 23975, 23986, 23996, 24007, 24018, 24029, 24039, 24049, 24059, 24070, 24081,
-24091, 24101, 24111, 24125, 24135, 24145, 24155, 24168, 24178, 24188, 24199, 24213, 24224, 24234, 24245, 24255,
-24265, 24275, 24285, 24296, 24307, 24318, 24328, 24339, 24349, 24359, 24369, 24379, 24389, 24400, 24411, 24422,
-24432, 24442, 24452, 24463, 24473, 24484, 24494, 24504, 24515, 24525, 24535, 24545, 24555, 24565, 24575, 24586,
-24596, 24607, 24617, 24627, 24640, 24650, 24660, 24671, 24681, 24693, 24703, 24713, 24723, 24733, 24743, 24753,
-24763, 24773, 24783, 24793, 24803, 24816, 24826, 24838, 24848, 24858, 24871, 24881, 24892, 24902, 24915, 24925,
-24935, 24945, 24955, 24967, 24977, 24988, 24999, 25010, 25020, 25030, 25040, 25052, 25062, 25074, 25084, 25095,
-25105, 25115, 25126, 25136, 25147, 25158, 25168, 25178, 25188, 25198, 25209, 25219, 25229, 25239, 25254, 25265,
-25275, 25285, 25295, 25305, 25322, 25332, 25342, 25352, 25363, 25375, 25385, 25397, 25407, 25417, 25427, 25445,
-25457, 25467, 25479, 25490, 25502, 25512, 25522, 25533, 25544, 25554, 25564, 25577, 25587, 25606, 25616, 25628,
-25638, 25648, 25658, 25675, 25688, 25699, 25709, 25720, 25731, 25743, 25753, 25763, 25773, 25785, 25796, 25806,
-25816, 25826, 25836, 25846, 25856, 25866, 25876, 25886, 25897, 25908, 25918, 25928, 25938, 25949, 25959, 25970,
-25981, 25991, 26001, 26011, 26021, 26031, 26041, 26051, 26062, 26072, 26082, 26092, 26105, 26115, 26125, 26140,
-26150, 26160, 26172, 26182, 26193, 26203, 26214, 26224, 26234, 26244, 26254, 26264, 26274, 26285, 26296, 26306,
-26316, 26326, 26336, 26347, 26357, 26367, 26377, 26387, 26397, 26407, 26417, 26429, 26439, 26449, 26460, 26470,
-26480, 26491, 26501, 26511, 26521, 26534, 26544, 26555, 26565, 26575, 26585, 26596, 26606, 26617, 26627, 26643,
-26653, 26663, 26673, 26683, 26693, 26704, 26715, 26727, 26737, 26747, 26757, 26767, 26778, 26789, 26799, 26809,
-26820, 26831, 26841, 26851, 26861, 26873, 26884, 26894, 26905, 26915, 26928, 26939, 26949, 26963, 26973, 26984,
-26994, 27004, 27018, 27028, 27040, 27051, 27063, 27073, 27083, 27094, 27106, 27117, 27129, 27139, 27151, 27161,
-27171, 27182, 27192, 27204, 27214, 27224, 27234, 27249, 27262, 27273, 27287, 27298, 27308, 27320, 27330, 27340,
-27350, 27364, 27376, 27386, 27396, 27407, 27419, 27431, 27442, 27453, 27463, 27474, 27485, 27495, 27507, 27517,
-27529, 27541, 27551, 27561, 27571, 27581, 27593, 27603, 27615, 27627, 27639, 27650, 27661, 27671, 27683, 27694,
-27704, 27714, 27725, 27735, 27746, 27757, 27768, 27778, 27788, 27798, 27809, 27819, 27832, 27842, 27852, 27862,
-27872, 27882, 27892, 27908, 27918, 27929, 27941, 27951, 27961, 27972, 27991, 28001, 28012, 28023, 28034, 28044,
-28054, 28074, 28084, 28095, 28106, 28117, 28127, 28137, 28147, 28160, 28170, 28181, 28191, 28201, 28214, 28227,
-28237, 28247, 28258, 28270, 28283, 28300, 28310, 28320, 28330, 28342, 28352, 28362, 28372, 28382, 28395, 28407,
-28417, 28428, 28438, 28448, 28458, 28470, 28481, 28495, 28505, 28516, 28526, 28536, 28546, 28556, 28566, 28576,
-28586, 28597, 28608, 28618, 28628, 28638, 28648, 28659, 28669, 28679, 28689, 28699, 28710, 28720, 28732, 28744,
-28756, 28766, 28779, 28789, 28801, 28814, 28824, 28836, 28846, 28856, 28872, 28883, 28893, 28913, 28925, 28935,
-28948, 28958, 28971, 28982, 28993, 29003, 29013, 29024, 29036, 29049, 29060, 29071, 29081, 29096, 29106, 29118,
-29128, 29138, 29148, 29158, 29173, 29183, 29193, 29203, 29213, 29224, 29234, 29244, 29254, 29264, 29274, 29287,
-29297, 29307, 29319, 29330, 29344, 29356, 29366, 29377, 29388, 29398, 29408, 29420, 29431, 29442, 29453, 29463,
-29474, 29484, 29494, 29507, 29517, 29527, 29539, 29550, 29560, 29571, 29582, 29592, 29602, 29613, 29623, 29634,
-29644, 29654, 29664, 29674, 29684, 29694, 29705, 29722, 29732, 29742, 29753, 29763, 29773, 29783, 29794, 29805,
-29822, 29833, 29848, 29858, 29870, 29881, 29896, 29907, 29918, 29928, 29938, 29948, 29958, 29969, 29980, 29990,
-30000, 30010, 30020, 30030, 30041, 30052, 30063, 30073, 30085, 30095, 30105, 30115, 30129, 30140, 30150, 30162,
-30172, 30183, 30193, 30204, 30215, 30226, 30236, 30246, 30256, 30266, 30276, 30290, 30300, 30311, 30321, 30331,
-30341, 30352, 30362, 30372, 30382, 30392, 30402, 30412, 30422, 30432, 30442, 30452, 30462, 30472, 30482, 30492,
-30502, 30516, 30526, 30538, 30550, 30560, 30570, 30580, 30590, 30603, 30613, 30623, 30634, 30645, 30655, 30665,
-30677, 30687, 30697, 30707, 30722, 30732, 30749, 30759, 30770, 30783, 30796, 30812, 30824, 30834, 30844, 30854,
-30865, 30877, 30887, 30897, 30907, 30917, 30928, 30938, 30948, 30959, 30970, 30982, 30992, 31002, 31013, 31025,
-31035, 31045, 31055, 31066, 31077, 31090, 31100, 31114, 31124, 31137, 31147, 31160, 31170, 31183, 31194, 31204,
-31216, 31227, 31239, 31249, 31259, 31271, 31281, 31291, 31301, 31311, 31321, 31331, 31341, 31352, 31362, 31376,
-31390, 31401, 31411, 31423, 31433, 31443, 31453, 31464, 31476, 31486, 31496, 31508, 31518, 31528, 31539, 31549,
-31559, 31569, 31581, 31591, 31601, 31620, 31630, 31640, 31653, 31663, 31674, 31684, 31695, 31705, 31716, 31730,
-31740, 31750, 31761, 31771, 31781, 31793, 31805, 31818, 31828, 31838, 31849, 31859, 31869, 31879, 31890, 31902,
-31912, 31922, 31932, 31943, 31954, 31964, 31974, 31986, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068,
-32078, 32089, 32099, 32110, 32120, 32130, 32140, 32150, 32162, 32172, 32182, 32194, 32204, 32215, 32225, 32235,
-32245, 32256, 32266, 32277, 32287, 32299, 32309, 32319, 32330, 32340, 32350, 32361, 32371, 32381, 32391, 32401,
-32411, 32566, 32579, 32589, 32600, 32611, 32621, 32631, 32642, 32652, 32662, 32673, 32685, 32696, 32707, 32718,
-32731, 32741, 32751, 32761, 32771, 32781, 32791, 32801, 32812, 32822, 32832, 32842, 32854, 32864, 32877, 32887,
-32897, 32907, 32918, 32929, 32939, 32952, 32963, 32973, 32983, 32993, 33005, 33016, 33026, 33046, 33056, 33068,
-33081, 33093, 33104, 33119, 33129, 33140, 33151, 33162, 33173, 33184, 33198, 33208, 33218, 33229, 33239, 33249,
-33259, 33269, 33279, 33289, 33299, 33309, 33320, 33330, 33344, 33355, 33366, 33376, 33386, 33396, 33406, 33417,
-33428, 33439, 33449, 33459, 33469, 33488, 33498, 33508, 33519, 33529, 33539, 33550, 33560, 33570, 33580, 33590,
-33600, 33610, 33620, 33648, 33659, 33669, 33682, 33692, 33702, 33713, 33725, 33735, 33745, 33756, 33768, 33778,
-33788, 33798, 33809, 33824, 33834, 33845, 33861, 33871, 33881, 33891, 33901, 33911, 33921, 33931, 33941, 33951,
-33961, 33972, 33982, 33992, 34003, 34023, 34033, 34043, 34054, 34064, 34074, 34084, 34095, 34109, 34120, 34130,
-34140, 34152, 34167, 34177, 34187, 34199, 34210, 34220, 34230, 34241, 34251, 34261, 34271, 34281, 34291, 34302,
-34314, 34326, 34337, 34349, 34360, 34370, 34381, 34391, 34401, 34411, 34421, 34440, 34451, 34465, 34475, 34485,
-34495, 34505, 34516, 34526, 34537, 34552, 34562, 34573, 34584, 34595, 34606, 34617, 34627, 34637, 34647, 34657,
-34670, 34680, 34690, 34700, 34711, 34722, 34732, 34746, 34756, 34766, 34777, 34787, 34797, 34807, 34817, 34827,
-34837, 34847, 34861, 34873, 34883, 34893, 34903, 34913, 34923, 34933, 34943, 34955, 34966, 34976, 34986, 34996,
-35006, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35109, 35120, 35130, 35140, 35151, 35162,
-35172, 35182, 35194, 35206, 35216, 35226, 35237, 35247, 35258, 35282, 35292, 35302, 35313, 35325, 35335, 35345,
-35355, 35365, 35375, 35386, 35397, 35408, 35419, 35429, 35440, 35450, 35460, 35471, 35481, 35491, 35501, 35511,
-35522, 35532, 35542, 35552, 35563, 35573, 35583, 35594, 35604, 35614, 35624, 35635, 35646, 35656, 35666, 35676,
-35686, 35696, 35708, 35722, 35732, 35742, 35895, 35905, 35915, 35925, 35937, 35947, 35957, 35970, 35980, 35992,
-36002, 36012, 36022, 36032, 36042, 36053, 36064, 36074, 36085, 36095, 36105, 36115, 36196, 36206, 36223, 36234,
-36245, 36255, 36267, 36277, 36288, 36298, 36308, 36319, 36330, 36340, 36351, 36361, 36372, 36382, 36394, 36404,
-36416, 36426, 36436, 36446, 36457, 36468, 36481, 36491, 36501, 36513, 36523, 36533, 36544, 36554, 36564, 36575,
-36587, 36599, 36610, 36620, 36630, 36640, 36650, 36660, 36670, 36681, 36691, 36701, 36763, 36773, 36783, 36794,
-36804, 36814, 36826, 36836, 36846, 36856, 36866, 36876, 36886, 36896, 36906, 36916, 36926, 36937, 36947, 36957,
-36967, 36978, 36988, 36999, 37009, 37019, 37029, 37039, 37053, 37063, 37074, 37084, 37096, 37108, 37118, 37128,
-37138, 37148, 37159, 37169, 37180, 37191, 37202, 37217, 37228, 37239, 37249, 37259, 37269, 37281, 37291, 37301,
-37311, 37321, 37331, 37341, 37351, 37361, 37371, 37381, 37392, 37404, 37414, 37424, 37434, 37444, 37454, 37464,
-37474, 37486, 37496, 37507, 37517, 37527, 37540, 37551, 37561, 37571, 37581, 37591, 37601, 37612, 37624, 37634,
-37645, 37656, 37666, 37676, 37686, 37700, 37712, 37722, 37732, 37742, 37754, 37768, 37778, 37790, 37800, 37812,
-37825, 37835, 37846, 37857, 37879, 37889, 37901, 37911, 37921, 37931, 37941, 37951, 37962, 37973, 37983, 37994,
-38005, 38015, 38263, 38274, 38284, 38294, 38304, 38315, 38326, 38339, 38349, 38360, 38370, 38428, 38438, 38449,
-38459, 38475, 38486, 38497, 38508, 38518, 38529, 38539, 38549, 38559, 38569, 38579, 38592, 38602, 38613, 38623,
-38633, 38646, 38656, 38666, 38678, 38689, 38704, 38717, 38728, 38738, 38748, 38758, 38769, 38779, 38789, 38799,
-38809, 38819, 38829, 38840, 38851, 38861, 38871, 38881, 38893, 38903, 38913, 38924, 38934, 38944, 38955, 38965,
-38980, 38990, 39000, 39010, 39020, 39080, 39092, 39103, 39116, 39131, 39141, 39151, 39164, 39175, 39185, 39195,
-39206, 39217, 39227, 39237, 39248, 39259, 39318, 39333, 39344, 39354, 39364, 39376, 39386, 39399, 39409, 39419,
-39429, 39439, 39449, 39459, 39469, 39479, 39489, 39499, 39509, 39519, 39529, 39592, 39602, 39612, 39622, 39632,
-39643, 39653, 39663, 39673, 39683, 39693, 39704, 39714, 39725, 39735, 39745, 39755, 39765, 39777, 39787, 39797,
-39807, 39817, 39827, 39837, 39847, 39857, 39867, 39878, 39888, 39899, 39909, 39919, 39929, 39940, 39951, 39961,
-39971, 39981, 39991, 40001, 40014, 40024, 40035, 40046, 40056, 40165, 40176, 40194, 40206, 40216, 40227, 40239,
-40250, 40260, 40272, 40284, 40297, 40310, 40323, 40333, 40343, 40353, 40363, 40373, 40383, 40393, 40403, 40414,
-40425, 40435, 40445, 40455, 40465, 40475, 40565, 40575, 40587, 40597, 40607, 40617, 40627, 40638, 40648, 40658,
-40668, 40679, 40689, 40699, 40711, 40721, 40731, 40742, 40753, 40763, 40773, 40783, 40794, 40806, 40816, 40826,
-40845, 40855, 40865, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401,
-65411, 65421, 65431, 65507
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-143, 162, 194, 142, 224, 142, 225, 143, 162, 240, 143, 162, 195, 161, 248, 161,
-175, 143, 162, 237, 143, 162, 236, 142, 226, 143, 162, 238, 143, 162, 180, 161,
-235, 161, 222, 161, 173, 162, 249, 143, 162, 177, 143, 162, 235, 143, 162, 196,
-143, 170, 162, 143, 170, 161, 143, 170, 164, 143, 170, 170, 143, 170, 163, 143,
-170, 169, 143, 169, 161, 143, 170, 174, 143, 170, 178, 143, 170, 177, 143, 170,
-180, 143, 170, 179, 143, 170, 192, 143, 170, 191, 143, 170, 194, 143, 170, 193,
-143, 170, 208, 143, 170, 210, 143, 170, 209, 143, 170, 212, 143, 170, 216, 143,
-170, 211, 161, 223, 143, 169, 172, 143, 170, 227, 143, 170, 226, 143, 170, 229,
-143, 170, 228, 143, 170, 242, 143, 169, 176, 143, 169, 206, 143, 171, 162, 143,
-171, 161, 143, 171, 164, 143, 171, 170, 143, 171, 163, 143, 171, 169, 143, 169,
-193, 143, 171, 174, 143, 171, 178, 143, 171, 177, 143, 171, 180, 143, 171, 179,
-143, 171, 192, 143, 171, 191, 143, 171, 194, 143, 171, 193, 143, 169, 195, 143,
-171, 208, 143, 171, 210, 143, 171, 209, 143, 171, 212, 143, 171, 216, 143, 171,
-211, 161, 224, 143, 169, 204, 143, 171, 227, 143, 171, 226, 143, 171, 229, 143,
-171, 228, 143, 171, 242, 143, 169, 208, 143, 171, 243, 143, 170, 167, 143, 170,
-175, 143, 170, 182, 143, 170, 189, 143, 170, 197, 143, 170, 200, 143, 171, 203,
-143, 171, 206, 143, 169, 173, 143, 170, 221, 143, 169, 175, 143, 170, 232, 143,
-171, 245, 143, 170, 166, 143, 170, 237, 143, 171, 185, 143, 162, 176, 143, 162,
-175, 143, 162, 184, 143, 166, 233, 166, 168, 166, 178, 143, 166, 242, 166, 199,
-166, 209, 143, 166, 250, 167, 167, 143, 167, 203, 167, 166, 167, 177, 167, 187,
-167, 212, 167, 223, 167, 233, 167, 215, 143, 167, 251, 161, 190, 161, 200, 161,
-196, 162, 243, 162, 168, 161, 238, 143, 162, 241, 143, 162, 239, 162, 171, 162,
-205, 162, 207, 162, 187, 162, 229, 162, 202, 161, 232, 162, 226, 161, 226, 162,
-227, 162, 190, 162, 221, 162, 222, 168, 161, 168, 163, 168, 177, 168, 178, 168,
-184, 168, 181, 168, 182, 162, 163, 162, 165, 162, 167, 162, 161, 162, 254, 161,
-250, 161, 234, 162, 246, 161, 161, 161, 212, 161, 204, 164, 161, 164, 171, 164,
-181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 161, 171, 165,
-165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235, 165,
-245, 176, 236, 190, 229, 179, 238, 190, 231, 143, 176, 169, 182, 250, 208, 167,
-143, 176, 178, 143, 176, 179, 143, 176, 181, 143, 176, 183, 198, 253, 180, 165,
-205, 189, 184, 223, 176, 161, 203, 242, 208, 183, 191, 205, 208, 188, 208, 186,
-201, 213, 143, 176, 201, 208, 193, 208, 195, 180, 235, 143, 176, 214, 143, 176,
-217, 143, 176, 221, 191, 173, 143, 176, 231, 143, 176, 235, 143, 176, 238, 143,
-176, 223, 143, 176, 242, 202, 187, 187, 200, 143, 177, 162, 143, 177, 168, 176,
-205, 213, 165, 191, 175, 202, 216, 143, 177, 187, 208, 215, 208, 216, 189, 164,
-202, 240, 143, 177, 203, 143, 177, 207, 143, 177, 211, 143, 177, 216, 208, 235,
-182, 230, 143, 177, 223, 143, 177, 228, 208, 243, 143, 177, 236, 143, 177, 242,
-194, 166, 208, 250, 143, 177, 251, 143, 178, 163, 143, 178, 167, 143, 178, 172,
-208, 253, 183, 185, 209, 161, 143, 178, 185, 143, 178, 189, 193, 206, 143, 178,
-197, 202, 200, 143, 178, 202, 143, 178, 210, 209, 179, 143, 178, 218, 143, 178,
-223, 209, 184, 189, 188, 143, 178, 231, 197, 222, 143, 178, 237, 209, 194, 197,
-181, 209, 196, 209, 198, 209, 204, 180, 167, 209, 209, 186, 227, 143, 178, 252,
-143, 179, 161, 143, 179, 164, 244, 165, 189, 232, 209, 224, 189, 208, 209, 227,
-209, 230, 143, 179, 183, 143, 179, 184, 209, 233, 183, 244, 196, 230, 193, 176,
-143, 179, 193, 143, 179, 199, 143, 179, 201, 143, 179, 203, 143, 179, 206, 143,
-179, 209, 143, 179, 212, 178, 195, 197, 216, 207, 171, 179, 175, 143, 179, 232,
-240, 213, 143, 179, 239, 210, 171, 143, 179, 246, 188, 219, 202, 241, 210, 183,
-186, 252, 210, 186, 143, 180, 175, 210, 190, 143, 180, 182, 143, 180, 183, 198,
-238, 143, 180, 187, 143, 180, 190, 210, 203, 210, 204, 143, 180, 198, 206, 210,
-143, 180, 204, 210, 209, 143, 180, 212, 187, 178, 193, 208, 188, 232, 143, 180,
-224, 194, 254, 143, 180, 227, 210, 222, 177, 165, 143, 180, 230, 200, 221, 143,
-180, 236, 202, 173, 202, 242, 198, 221, 143, 180, 244, 188, 254, 204, 163, 204,
-191, 143, 181, 164, 210, 240, 143, 181, 170, 143, 181, 173, 143, 181, 179, 143,
-181, 183, 143, 181, 185, 211, 166, 211, 175, 143, 181, 191, 143, 181, 193, 143,
-181, 197, 143, 181, 202, 176, 162, 143, 181, 206, 143, 181, 209, 211, 177, 143,
-181, 217, 211, 183, 143, 181, 225, 211, 193, 143, 181, 232, 143, 181, 236, 180,
-238, 183, 246, 143, 181, 244, 143, 181, 245, 143, 181, 249, 143, 182, 161, 143,
-182, 165, 143, 182, 167, 143, 182, 168, 143, 182, 170, 143, 182, 175, 143, 182,
-179, 178, 222, 143, 182, 182, 143, 182, 188, 143, 182, 195, 143, 182, 199, 143,
-182, 200, 180, 239, 143, 182, 210, 211, 230, 211, 231, 211, 233, 143, 182, 221,
-143, 182, 225, 143, 182, 231, 143, 182, 233, 211, 244, 211, 247, 143, 182, 244,
-143, 182, 250, 143, 182, 252, 185, 241, 143, 183, 165, 143, 183, 168, 143, 183,
-171, 143, 183, 177, 143, 183, 182, 212, 173, 143, 183, 188, 212, 175, 212, 179,
-143, 183, 197, 143, 183, 205, 212, 180, 212, 181, 212, 182, 143, 183, 220, 143,
-183, 225, 212, 184, 143, 183, 230, 143, 183, 231, 212, 191, 199, 184, 143, 183,
-239, 143, 183, 243, 180, 240, 143, 183, 251, 194, 196, 143, 184, 165, 180, 174,
-190, 236, 143, 184, 172, 143, 184, 173, 197, 227, 186, 201, 143, 184, 183, 212,
-199, 143, 184, 185, 143, 184, 189, 202, 232, 143, 184, 199, 203, 207, 143, 184,
-206, 143, 184, 208, 195, 197, 212, 219, 212, 224, 143, 184, 221, 143, 184, 222,
-212, 232, 202, 209, 143, 184, 228, 143, 184, 231, 194, 231, 188, 186, 212, 243,
-198, 224, 143, 184, 244, 143, 184, 248, 212, 252, 143, 185, 162, 143, 185, 167,
-199, 165, 143, 185, 172, 143, 185, 174, 197, 202, 143, 185, 182, 143, 185, 185,
-187, 207, 213, 172, 143, 185, 195, 143, 185, 198, 176, 249, 213, 178, 143, 185,
-210, 143, 185, 211, 143, 185, 215, 213, 183, 213, 180, 143, 185, 223, 186, 167,
-143, 185, 228, 143, 185, 231, 143, 185, 235, 143, 185, 238, 143, 185, 243, 143,
-185, 246, 143, 185, 251, 213, 191, 183, 249, 213, 197, 143, 186, 167, 143, 186,
-169, 143, 186, 171, 143, 186, 174, 213, 201, 213, 202, 143, 186, 182, 196, 220,
-213, 206, 213, 210, 143, 186, 187, 213, 212, 204, 210, 213, 216, 213, 218, 143,
-186, 196, 177, 167, 143, 186, 205, 176, 184, 205, 168, 143, 186, 213, 205, 198,
-213, 227, 143, 186, 221, 143, 186, 224, 178, 201, 213, 237, 195, 254, 188, 247,
-176, 211, 213, 245, 143, 186, 235, 213, 248, 143, 186, 244, 198, 244, 213, 252,
-214, 161, 143, 186, 248, 193, 216, 214, 165, 214, 168, 143, 187, 169, 214, 170,
-143, 187, 174, 193, 187, 143, 187, 181, 214, 176, 214, 180, 143, 187, 187, 143,
-187, 188, 178, 229, 143, 187, 192, 214, 183, 191, 242, 214, 194, 214, 193, 143,
-187, 201, 143, 187, 203, 143, 187, 206, 143, 187, 211, 214, 201, 214, 191, 191,
-243, 214, 205, 143, 187, 226, 143, 187, 230, 143, 187, 232, 214, 211, 143, 187,
-240, 143, 230, 244, 214, 217, 143, 187, 247, 214, 221, 192, 238, 185, 170, 184,
-202, 180, 172, 200, 193, 214, 230, 214, 231, 191, 227, 194, 211, 203, 185, 214,
-243, 143, 188, 181, 143, 188, 184, 143, 188, 187, 180, 179, 205, 196, 200, 223,
-196, 236, 214, 249, 143, 188, 201, 176, 195, 143, 188, 207, 206, 247, 179, 199,
-215, 163, 215, 168, 215, 172, 215, 176, 143, 188, 223, 181, 221, 143, 188, 227,
-184, 204, 188, 229, 143, 188, 239, 143, 188, 244, 143, 188, 247, 143, 188, 250,
-201, 167, 190, 180, 143, 189, 166, 183, 194, 143, 189, 171, 215, 208, 143, 189,
-178, 200, 249, 143, 189, 183, 191, 180, 199, 166, 187, 214, 143, 189, 195, 178,
-247, 199, 176, 215, 221, 143, 189, 210, 143, 189, 213, 143, 189, 217, 215, 226,
-143, 189, 220, 143, 189, 222, 215, 240, 143, 189, 228, 215, 239, 178, 184, 183,
-195, 143, 189, 236, 188, 189, 143, 189, 243, 143, 189, 246, 216, 166, 143, 189,
-253, 143, 190, 161, 190, 240, 143, 190, 170, 143, 190, 173, 193, 218, 194, 198,
-216, 185, 216, 180, 143, 190, 188, 182, 242, 216, 195, 143, 190, 202, 216, 198,
-143, 190, 209, 216, 216, 216, 215, 183, 197, 216, 213, 143, 190, 216, 216, 220,
-216, 225, 143, 190, 229, 198, 180, 183, 251, 143, 190, 239, 216, 234, 178, 251,
-143, 190, 246, 216, 239, 196, 168, 216, 246, 143, 191, 167, 178, 230, 216, 254,
-192, 239, 217, 165, 204, 225, 143, 191, 182, 143, 191, 184, 143, 191, 189, 143,
-191, 191, 202, 177, 200, 227, 217, 183, 143, 191, 197, 185, 179, 143, 191, 201,
-202, 250, 217, 187, 195, 180, 217, 188, 192, 219, 143, 191, 214, 143, 191, 216,
-189, 166, 217, 205, 143, 191, 225, 182, 180, 143, 191, 228, 143, 191, 231, 193,
-222, 194, 170, 143, 191, 244, 143, 191, 248, 143, 191, 252, 199, 177, 143, 192,
-167, 199, 211, 143, 192, 174, 191, 228, 183, 199, 143, 192, 180, 143, 192, 183,
-217, 231, 143, 192, 189, 217, 226, 143, 192, 195, 217, 236, 143, 192, 201, 217,
-211, 217, 238, 143, 192, 213, 183, 200, 143, 192, 217, 197, 166, 143, 192, 230,
-143, 192, 231, 204, 206, 183, 226, 143, 192, 238, 143, 192, 242, 143, 192, 247,
-199, 197, 179, 201, 143, 193, 161, 143, 193, 166, 218, 166, 197, 167, 181, 188,
-218, 177, 218, 181, 143, 193, 185, 143, 193, 188, 143, 193, 192, 143, 193, 196,
-218, 189, 202, 252, 218, 195, 143, 193, 206, 218, 201, 143, 193, 210, 218, 202,
-143, 193, 213, 202, 184, 200, 195, 218, 207, 192, 205, 187, 219, 202, 253, 218,
-211, 143, 193, 232, 143, 193, 236, 180, 251, 189, 220, 143, 193, 242, 218, 224,
-143, 193, 249, 218, 230, 143, 194, 166, 143, 194, 172, 195, 235, 143, 194, 179,
-143, 194, 182, 143, 194, 187, 179, 162, 218, 242, 195, 210, 218, 247, 218, 245,
-218, 248, 196, 170, 143, 194, 217, 219, 162, 143, 194, 224, 143, 194, 227, 219,
-163, 219, 165, 143, 194, 234, 219, 170, 194, 216, 205, 173, 143, 194, 241, 196,
-171, 219, 176, 188, 235, 181, 224, 143, 194, 249, 194, 188, 197, 206, 143, 195,
-161, 219, 191, 143, 195, 166, 219, 199, 143, 195, 170, 143, 195, 175, 219, 197,
-143, 195, 177, 143, 195, 181, 143, 195, 188, 199, 240, 143, 195, 193, 219, 207,
-219, 211, 143, 195, 184, 198, 202, 192, 242, 143, 195, 204, 143, 195, 207, 143,
-195, 212, 143, 195, 214, 143, 195, 217, 182, 205, 143, 195, 223, 201, 176, 143,
-195, 228, 143, 195, 233, 199, 223, 219, 231, 143, 195, 241, 143, 195, 245, 196,
-244, 219, 238, 180, 254, 143, 195, 254, 143, 196, 165, 220, 168, 143, 196, 173,
-220, 170, 220, 166, 196, 199, 191, 250, 220, 176, 220, 191, 143, 196, 193, 143,
-196, 195, 201, 246, 220, 194, 143, 196, 204, 143, 196, 209, 207, 176, 186, 231,
-207, 177, 220, 213, 143, 196, 222, 143, 196, 225, 220, 201, 185, 189, 143, 196,
-232, 143, 196, 234, 220, 229, 220, 223, 143, 196, 244, 143, 196, 245, 201, 184,
-220, 235, 220, 211, 220, 247, 220, 237, 143, 197, 170, 181, 204, 220, 243, 143,
-197, 180, 143, 197, 182, 143, 197, 187, 221, 161, 220, 253, 221, 168, 221, 166,
-221, 165, 143, 197, 206, 143, 197, 210, 143, 197, 213, 143, 197, 216, 221, 178,
-205, 243, 143, 197, 226, 143, 197, 230, 178, 164, 205, 223, 182, 214, 221, 188,
-143, 197, 244, 143, 197, 247, 143, 197, 249, 186, 208, 143, 197, 254, 189, 222,
-221, 205, 143, 198, 166, 143, 198, 171, 221, 213, 143, 198, 178, 143, 198, 182,
-221, 218, 221, 219, 221, 221, 143, 198, 192, 143, 198, 195, 143, 198, 199, 181,
-164, 221, 230, 143, 198, 209, 177, 202, 181, 225, 143, 198, 218, 180, 192, 221,
-233, 143, 198, 226, 143, 198, 230, 221, 235, 198, 217, 178, 173, 203, 215, 203,
-247, 202, 168, 143, 198, 246, 200, 231, 143, 198, 254, 143, 199, 163, 222, 165,
-143, 199, 170, 143, 199, 171, 143, 199, 174, 222, 172, 196, 197, 143, 199, 184,
-143, 199, 186, 190, 244, 143, 199, 189, 143, 199, 192, 179, 189, 179, 164, 143,
-199, 198, 205, 176, 143, 199, 203, 143, 199, 206, 143, 199, 208, 143, 199, 212,
-143, 199, 215, 222, 204, 143, 199, 221, 143, 199, 225, 189, 223, 143, 199, 231,
-222, 189, 222, 188, 222, 219, 178, 185, 143, 199, 237, 222, 220, 222, 218, 143,
-199, 251, 143, 200, 161, 222, 208, 143, 200, 165, 200, 174, 189, 224, 143, 200,
-170, 222, 228, 205, 207, 143, 200, 178, 143, 200, 183, 222, 237, 194, 218, 143,
-200, 187, 223, 163, 181, 249, 143, 200, 196, 143, 200, 198, 199, 249, 143, 200,
-204, 143, 200, 208, 222, 243, 143, 200, 212, 143, 200, 217, 189, 225, 196, 172,
-223, 166, 223, 173, 143, 200, 231, 143, 200, 237, 143, 200, 240, 223, 186, 143,
-200, 248, 183, 227, 143, 200, 254, 223, 190, 143, 201, 162, 143, 201, 163, 223,
-171, 143, 201, 169, 143, 201, 173, 223, 198, 223, 202, 195, 245, 223, 208, 143,
-201, 182, 143, 201, 185, 143, 201, 189, 143, 201, 192, 178, 208, 143, 201, 198,
-143, 201, 201, 177, 234, 143, 201, 208, 143, 201, 210, 223, 220, 223, 218, 206,
-245, 143, 201, 218, 223, 223, 223, 216, 223, 226, 143, 201, 230, 177, 235, 143,
-201, 234, 143, 201, 236, 193, 179, 143, 201, 242, 143, 201, 247, 223, 230, 143,
-201, 254, 223, 236, 143, 202, 162, 223, 239, 223, 237, 244, 166, 223, 241, 143,
-202, 174, 223, 245, 197, 245, 223, 246, 143, 202, 187, 187, 184, 223, 253, 224,
-162, 143, 202, 193, 143, 202, 194, 143, 202, 197, 224, 166, 224, 170, 224, 172,
-224, 175, 143, 202, 211, 143, 202, 215, 203, 210, 143, 202, 224, 143, 202, 227,
-224, 182, 224, 183, 181, 190, 184, 164, 190, 245, 143, 202, 242, 143, 202, 245,
-143, 202, 247, 224, 195, 198, 200, 224, 198, 143, 203, 162, 143, 203, 167, 224,
-200, 143, 203, 173, 143, 203, 177, 205, 177, 143, 203, 184, 143, 203, 185, 224,
-213, 189, 195, 143, 203, 199, 224, 217, 143, 203, 207, 143, 203, 210, 143, 203,
-215, 143, 203, 220, 143, 203, 225, 143, 203, 227, 178, 209, 143, 203, 236, 143,
-203, 240, 188, 238, 183, 190, 143, 203, 248, 184, 189, 206, 176, 143, 204, 168,
-143, 204, 170, 143, 204, 178, 143, 204, 182, 143, 204, 184, 143, 204, 189, 143,
-204, 192, 143, 204, 194, 143, 204, 199, 224, 247, 143, 204, 208, 143, 204, 213,
-224, 229, 143, 204, 226, 143, 204, 231, 143, 204, 234, 143, 204, 238, 143, 204,
-242, 143, 204, 245, 225, 166, 143, 204, 252, 143, 204, 254, 185, 249, 197, 188,
-225, 180, 197, 196, 196, 174, 225, 183, 143, 205, 180, 206, 177, 225, 191, 143,
-205, 187, 143, 205, 189, 143, 205, 196, 193, 193, 143, 205, 201, 225, 207, 225,
-215, 225, 214, 143, 205, 211, 225, 218, 143, 205, 216, 143, 205, 221, 143, 205,
-225, 225, 224, 143, 205, 231, 143, 205, 236, 143, 205, 242, 143, 205, 247, 225,
-240, 143, 206, 161, 143, 206, 167, 204, 254, 225, 245, 225, 252, 143, 206, 179,
-197, 208, 143, 206, 182, 187, 169, 226, 173, 143, 206, 193, 200, 233, 226, 176,
-226, 179, 143, 206, 205, 226, 181, 143, 206, 209, 226, 187, 196, 190, 189, 226,
-226, 190, 143, 206, 222, 143, 206, 228, 226, 197, 143, 206, 234, 143, 206, 239,
-143, 206, 243, 143, 206, 248, 143, 206, 253, 143, 207, 163, 143, 207, 168, 226,
-208, 226, 211, 143, 207, 176, 143, 207, 179, 143, 207, 182, 143, 207, 186, 226,
-218, 143, 207, 189, 143, 207, 192, 143, 207, 195, 182, 235, 192, 208, 186, 189,
-226, 230, 143, 207, 212, 181, 206, 203, 164, 185, 220, 143, 207, 225, 143, 207,
-228, 143, 207, 234, 200, 163, 226, 239, 226, 238, 200, 234, 143, 207, 244, 202,
-203, 143, 207, 252, 143, 208, 161, 226, 252, 200, 216, 227, 162, 143, 208, 173,
-176, 235, 143, 208, 185, 143, 208, 188, 143, 208, 190, 143, 208, 191, 143, 208,
-196, 143, 208, 200, 143, 208, 203, 143, 208, 207, 143, 208, 211, 227, 175, 190,
-205, 143, 208, 220, 143, 208, 223, 227, 180, 143, 208, 229, 143, 208, 235, 143,
-208, 238, 143, 208, 242, 143, 208, 244, 143, 208, 249, 143, 208, 252, 199, 233,
-190, 206, 176, 220, 143, 209, 172, 143, 209, 176, 143, 209, 178, 143, 209, 181,
-227, 202, 227, 203, 143, 209, 192, 178, 186, 143, 209, 198, 190, 247, 143, 209,
-206, 143, 209, 208, 143, 209, 211, 143, 209, 216, 143, 209, 219, 227, 221, 143,
-209, 223, 227, 227, 143, 209, 229, 227, 234, 227, 237, 143, 209, 234, 143, 209,
-239, 143, 209, 242, 181, 232, 143, 209, 244, 227, 250, 227, 252, 227, 247, 143,
-210, 163, 143, 210, 167, 195, 222, 228, 184, 228, 170, 228, 172, 143, 210, 180,
-143, 210, 182, 228, 176, 143, 210, 189, 143, 210, 191, 143, 210, 196, 200, 207,
-228, 189, 143, 210, 207, 198, 198, 143, 210, 212, 143, 210, 218, 143, 210, 224,
-228, 194, 143, 210, 231, 143, 210, 233, 143, 210, 237, 228, 213, 143, 210, 244,
-228, 216, 143, 210, 254, 143, 211, 164, 202, 198, 143, 211, 171, 143, 211, 173,
-206, 179, 143, 211, 176, 228, 234, 228, 236, 143, 211, 184, 143, 211, 187, 228,
-245, 228, 246, 143, 211, 199, 228, 250, 181, 234, 143, 211, 205, 143, 211, 209,
-229, 162, 143, 211, 215, 186, 217, 186, 176, 193, 200, 229, 174, 143, 211, 230,
-229, 179, 229, 177, 143, 211, 238, 143, 211, 243, 143, 211, 249, 143, 211, 252,
-229, 194, 188, 250, 143, 212, 166, 143, 212, 169, 143, 212, 174, 143, 212, 177,
-229, 206, 143, 212, 184, 143, 212, 187, 143, 212, 179, 229, 208, 143, 212, 194,
-229, 213, 203, 165, 229, 220, 143, 212, 206, 193, 161, 191, 165, 229, 229, 229,
-234, 143, 212, 221, 229, 239, 143, 212, 226, 143, 212, 229, 229, 251, 180, 204,
-143, 212, 240, 230, 163, 230, 169, 143, 212, 250, 143, 212, 254, 200, 237, 230,
-176, 230, 181, 143, 213, 171, 143, 213, 174, 143, 213, 178, 230, 192, 143, 213,
-183, 143, 213, 185, 143, 213, 187, 143, 213, 190, 143, 213, 194, 230, 203, 185,
-205, 143, 213, 203, 204, 215, 230, 212, 143, 213, 216, 204, 237, 143, 213, 226,
-230, 216, 192, 187, 143, 213, 228, 143, 213, 231, 191, 166, 143, 213, 234, 207,
-190, 190, 211, 184, 212, 143, 213, 241, 143, 213, 242, 176, 223, 143, 213, 245,
-143, 213, 250, 184, 213, 143, 213, 253, 182, 187, 187, 233, 143, 214, 170, 143,
-214, 175, 143, 214, 178, 196, 177, 143, 214, 183, 201, 229, 231, 181, 143, 214,
-193, 231, 171, 194, 220, 231, 174, 231, 178, 231, 177, 143, 214, 209, 231, 187,
-231, 190, 231, 193, 143, 214, 220, 143, 214, 224, 143, 214, 226, 143, 214, 231,
-143, 214, 236, 218, 170, 143, 214, 240, 143, 214, 244, 143, 214, 247, 143, 214,
-248, 231, 217, 143, 215, 161, 143, 215, 165, 143, 215, 167, 231, 226, 143, 215,
-171, 231, 232, 143, 215, 180, 143, 215, 184, 231, 236, 143, 215, 195, 203, 167,
-178, 234, 143, 215, 207, 143, 215, 209, 143, 215, 212, 143, 215, 216, 231, 249,
-231, 247, 183, 212, 232, 173, 143, 215, 233, 143, 215, 234, 195, 227, 232, 166,
-183, 213, 143, 215, 227, 143, 215, 253, 178, 174, 232, 174, 143, 216, 168, 143,
-216, 174, 143, 216, 176, 205, 233, 232, 207, 143, 216, 183, 143, 216, 187, 186,
-218, 143, 216, 191, 232, 203, 143, 216, 196, 143, 216, 198, 143, 216, 201, 232,
-206, 232, 212, 232, 226, 143, 216, 207, 143, 216, 212, 143, 216, 217, 198, 161,
-232, 211, 232, 216, 143, 216, 232, 190, 213, 143, 216, 236, 232, 231, 143, 216,
-240, 143, 216, 244, 143, 216, 247, 143, 216, 251, 143, 216, 254, 143, 217, 162,
-143, 217, 166, 143, 217, 171, 232, 209, 143, 217, 178, 177, 182, 143, 217, 183,
-143, 217, 188, 202, 195, 232, 254, 143, 217, 197, 143, 217, 201, 207, 207, 233,
-177, 143, 217, 216, 143, 217, 220, 177, 242, 143, 217, 228, 204, 244, 143, 217,
-232, 207, 206, 143, 217, 242, 233, 185, 143, 217, 247, 200, 205, 143, 217, 252,
-233, 193, 233, 190, 221, 177, 143, 218, 174, 205, 246, 143, 218, 178, 143, 218,
-183, 233, 200, 143, 218, 188, 143, 218, 193, 195, 238, 143, 218, 200, 143, 218,
-237, 233, 206, 143, 218, 210, 233, 219, 143, 218, 218, 143, 218, 222, 233, 217,
-233, 220, 233, 221, 233, 222, 194, 253, 203, 170, 233, 235, 195, 216, 143, 218,
-254, 143, 219, 162, 143, 219, 166, 143, 219, 172, 143, 219, 174, 233, 251, 143,
-219, 177, 233, 253, 233, 247, 234, 167, 143, 219, 192, 143, 219, 196, 234, 165,
-143, 219, 203, 205, 230, 234, 175, 143, 219, 214, 143, 219, 217, 143, 219, 222,
-143, 219, 226, 234, 187, 143, 219, 232, 143, 219, 237, 234, 192, 143, 219, 248,
-143, 219, 250, 234, 197, 143, 220, 164, 222, 167, 179, 185, 185, 213, 234, 206,
-234, 210, 182, 222, 194, 222, 194, 181, 143, 220, 190, 143, 220, 192, 184, 211,
-143, 220, 195, 143, 220, 197, 234, 227, 143, 220, 206, 234, 235, 234, 236, 234,
-233, 143, 220, 214, 179, 236, 143, 220, 222, 234, 243, 143, 220, 228, 143, 220,
-233, 234, 247, 143, 220, 240, 143, 220, 243, 235, 162, 143, 220, 250, 143, 220,
-254, 202, 164, 143, 221, 166, 179, 208, 143, 221, 173, 235, 178, 235, 180, 179,
-209, 235, 185, 191, 168, 143, 221, 189, 143, 221, 193, 143, 221, 197, 143, 221,
-199, 235, 194, 235, 196, 143, 221, 210, 191, 199, 143, 221, 217, 186, 190, 235,
-199, 143, 221, 229, 181, 205, 143, 221, 235, 235, 209, 143, 221, 243, 143, 221,
-248, 235, 216, 198, 201, 143, 222, 162, 235, 219, 180, 210, 207, 192, 235, 227,
-235, 221, 143, 222, 180, 143, 222, 183, 143, 222, 191, 235, 226, 143, 222, 189,
-235, 245, 235, 240, 235, 244, 143, 222, 201, 143, 222, 202, 201, 232, 183, 217,
-181, 196, 143, 222, 213, 218, 206, 143, 222, 221, 143, 222, 224, 195, 171, 236,
-175, 143, 222, 233, 236, 181, 190, 221, 208, 174, 143, 222, 250, 236, 186, 203,
-198, 236, 194, 185, 215, 192, 213, 236, 202, 178, 236, 194, 177, 143, 223, 178,
-199, 229, 188, 193, 143, 223, 187, 143, 223, 191, 143, 223, 194, 236, 219, 192,
-214, 143, 223, 201, 143, 223, 202, 177, 219, 143, 223, 209, 143, 223, 211, 143,
-223, 214, 143, 223, 218, 143, 223, 222, 143, 223, 227, 143, 223, 230, 236, 240,
-236, 238, 143, 223, 242, 236, 245, 236, 244, 143, 223, 250, 236, 247, 237, 169,
-236, 253, 143, 224, 171, 236, 254, 143, 224, 177, 143, 224, 181, 143, 224, 184,
-189, 179, 237, 175, 237, 179, 143, 224, 198, 237, 186, 191, 200, 143, 224, 209,
-143, 224, 212, 188, 214, 143, 224, 219, 198, 240, 237, 199, 143, 224, 225, 143,
-224, 230, 237, 210, 143, 224, 235, 143, 224, 239, 206, 216, 143, 224, 248, 237,
-217, 237, 219, 143, 225, 166, 143, 225, 170, 191, 201, 143, 225, 177, 237, 231,
-202, 213, 203, 248, 183, 222, 237, 233, 143, 225, 195, 143, 225, 197, 237, 254,
-143, 225, 203, 143, 225, 206, 237, 248, 194, 164, 143, 225, 212, 143, 225, 216,
-238, 167, 238, 166, 198, 187, 143, 225, 223, 143, 225, 226, 238, 175, 206, 203,
-237, 238, 205, 184, 143, 225, 241, 143, 225, 245, 238, 184, 143, 225, 251, 143,
-226, 163, 143, 226, 173, 143, 226, 169, 201, 244, 143, 226, 178, 143, 226, 179,
-143, 226, 185, 238, 192, 143, 226, 193, 143, 226, 199, 143, 226, 203, 143, 226,
-209, 143, 226, 212, 188, 242, 143, 226, 220, 189, 183, 185, 243, 143, 226, 228,
-238, 204, 143, 226, 237, 143, 226, 240, 238, 208, 238, 211, 143, 226, 254, 238,
-216, 143, 227, 164, 191, 203, 182, 252, 143, 227, 179, 143, 227, 182, 143, 227,
-187, 143, 227, 193, 143, 227, 198, 143, 227, 203, 143, 227, 207, 143, 227, 213,
-197, 180, 143, 227, 223, 143, 227, 226, 200, 173, 143, 227, 236, 143, 227, 242,
-189, 198, 143, 227, 251, 143, 227, 254, 143, 228, 164, 143, 228, 169, 238, 248,
-143, 228, 181, 143, 228, 188, 143, 228, 193, 143, 228, 200, 143, 228, 205, 181,
-248, 143, 228, 212, 143, 228, 214, 191, 238, 239, 162, 207, 163, 143, 228, 230,
-238, 253, 143, 228, 235, 143, 228, 241, 143, 228, 243, 239, 171, 143, 229, 161,
-143, 229, 167, 143, 229, 172, 143, 229, 176, 143, 229, 181, 143, 229, 183, 143,
-229, 188, 143, 229, 195, 239, 178, 182, 192, 143, 229, 207, 143, 229, 212, 143,
-229, 217, 143, 229, 222, 239, 197, 239, 195, 239, 196, 143, 229, 231, 143, 229,
-236, 143, 229, 238, 143, 229, 241, 239, 206, 239, 209, 239, 216, 196, 185, 239,
-217, 143, 230, 164, 239, 221, 239, 224, 143, 230, 173, 143, 230, 176, 239, 234,
-239, 235, 198, 174, 239, 243, 201, 236, 143, 230, 201, 143, 230, 203, 193, 203,
-239, 251, 143, 230, 214, 143, 230, 217, 240, 165, 198, 171, 143, 230, 224, 231,
-161, 240, 168, 143, 230, 233, 143, 230, 237, 143, 230, 240, 191, 253, 143, 230,
-242, 240, 186, 143, 230, 249, 143, 230, 250, 206, 237, 188, 251, 206, 238, 240,
-195, 143, 231, 167, 240, 199, 240, 201, 240, 205, 192, 196, 240, 208, 240, 211,
-240, 215, 143, 231, 191, 240, 217, 240, 223, 143, 231, 199, 240, 228, 202, 220,
-143, 231, 210, 240, 231, 143, 231, 223, 143, 231, 228, 143, 231, 235, 240, 236,
-143, 231, 240, 202, 199, 240, 243, 143, 231, 249, 143, 231, 252, 143, 232, 161,
-143, 232, 167, 143, 232, 170, 179, 220, 180, 234, 143, 232, 180, 143, 232, 185,
-201, 247, 143, 232, 190, 143, 232, 195, 143, 232, 199, 200, 244, 143, 232, 202,
-200, 211, 187, 244, 143, 232, 209, 143, 232, 211, 143, 232, 216, 143, 232, 220,
-143, 232, 223, 143, 232, 230, 241, 189, 241, 190, 143, 232, 242, 188, 243, 241,
-198, 143, 232, 251, 143, 233, 162, 194, 204, 195, 243, 143, 233, 170, 143, 233,
-173, 241, 209, 241, 211, 241, 215, 241, 214, 241, 217, 143, 233, 194, 143, 233,
-197, 241, 219, 143, 233, 204, 143, 233, 207, 241, 225, 241, 229, 241, 233, 185,
-252, 143, 233, 218, 241, 238, 143, 233, 228, 143, 233, 231, 143, 233, 236, 143,
-233, 240, 241, 249, 143, 233, 247, 143, 233, 254, 143, 234, 167, 242, 163, 242,
-166, 143, 234, 178, 143, 234, 182, 179, 161, 143, 234, 187, 143, 234, 189, 143,
-234, 194, 143, 234, 200, 143, 234, 205, 143, 234, 209, 143, 234, 215, 242, 184,
-143, 234, 223, 143, 234, 226, 143, 234, 230, 143, 234, 234, 242, 196, 143, 234,
-242, 194, 228, 143, 234, 247, 143, 234, 251, 143, 235, 161, 242, 218, 143, 235,
-168, 143, 235, 172, 143, 235, 177, 201, 201, 143, 235, 186, 143, 235, 188, 143,
-235, 194, 143, 235, 200, 143, 235, 205, 143, 235, 211, 242, 233, 196, 187, 242,
-236, 143, 235, 222, 178, 170, 143, 235, 225, 242, 245, 143, 235, 229, 143, 235,
-234, 242, 247, 243, 165, 177, 173, 143, 235, 248, 143, 235, 252, 143, 236, 163,
-143, 236, 167, 143, 236, 173, 143, 236, 175, 243, 170, 143, 236, 180, 143, 236,
-183, 143, 236, 186, 243, 186, 143, 236, 193, 143, 236, 198, 143, 236, 202, 243,
-191, 143, 236, 207, 143, 236, 210, 243, 193, 243, 195, 188, 175, 243, 200, 243,
-203, 206, 219, 243, 207, 143, 236, 238, 221, 224, 143, 236, 242, 185, 245, 243,
-217, 143, 236, 247, 143, 236, 252, 243, 228, 243, 231, 143, 237, 168, 143, 237,
-175, 143, 237, 178, 143, 237, 182, 201, 161, 143, 237, 194, 240, 237, 143, 237,
-202, 243, 245, 143, 237, 210, 143, 237, 214, 206, 182, 143, 237, 222, 143, 237,
-224, 161, 170, 161, 220, 163, 181, 161, 169, 163, 201, 163, 211, 161, 207, 163,
-231, 163, 241, 161, 208, 142, 165, 142, 175, 142, 185, 142, 195, 142, 205, 142,
-215, 161, 177
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Duplicate Characters.",
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic () throws CharacterCodingException {
- encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
- decoder.onMalformedInput(CodingErrorAction.REPORT);
- CharBuffer inputCB = CharBuffer.allocate(65536);
- for (int code = 32; code <= 65533; code ++) {
- if ((encoder.canEncode((char) code))
- && (code != 165) && (code != 8254) && (code != 63599)) {
- inputCB.put((char) code);
- }
- }
- inputCB.rewind();
- ByteBuffer intermediateBB = encoder.encode(inputCB);
- inputCB.rewind();
- intermediateBB.rewind();
- CharBuffer outputCB = decoder.decode(intermediateBB);
- outputCB.rewind();
- assertEqualCBs("decode(encode(A)) must be identical with A!",
- inputCB, outputCB);
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_KR.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_KR.java
deleted file mode 100644
index 90ae541..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_EUC_KR.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_MultiByte_EUC_KR extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "EUC-KR";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 164, 167, 168, 170, 173, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186,
-188, 189, 190, 191, 198, 208, 215, 216, 222, 223, 230, 240, 247, 248, 254, 273,
-294, 305, 319, 329, 339, 358, 711, 728, 913, 923, 933, 945, 955, 965, 1025, 1040,
-1050, 1060, 1070, 1080, 1090, 1100, 8213, 8224, 8240, 8251, 8308, 8319, 8451, 8467, 8481, 8491,
-8531, 8541, 8551, 8561, 8592, 8658, 8704, 8715, 8730, 8741, 8756, 8786, 8800, 8810, 8834, 8857,
-8869, 8978, 9312, 9322, 9332, 9342, 9372, 9382, 9392, 9424, 9434, 9444, 9472, 9484, 9494, 9504,
-9514, 9524, 9534, 9544, 9618, 9632, 9650, 9660, 9670, 9680, 9733, 9743, 9756, 9792, 9824, 9834,
-12288, 12298, 12308, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12449, 12459, 12469, 12479,
-12489, 12499, 12509, 12519, 12529, 12593, 12603, 12613, 12623, 12633, 12643, 12653, 12663, 12673, 12683, 12800,
-12810, 12820, 12896, 12906, 12916, 12927, 13184, 13194, 13204, 13214, 13224, 13234, 13244, 13254, 13264, 13275,
-19968, 19978, 19988, 19998, 20013, 20024, 20034, 20045, 20056, 20075, 20086, 20098, 20108, 20120, 20130, 20140,
-20150, 20160, 20170, 20180, 20191, 20208, 20219, 20233, 20271, 20282, 20294, 20304, 20314, 20329, 20339, 20350,
-20360, 20374, 20398, 20415, 20425, 20435, 20445, 20462, 20472, 20482, 20493, 20505, 20515, 20525, 20539, 20551,
-20565, 20581, 20596, 20608, 20621, 20632, 20652, 20663, 20677, 20687, 20698, 20709, 20729, 20740, 20754, 20767,
-20778, 20791, 20801, 20811, 20828, 20839, 20849, 20860, 20870, 20882, 20896, 20906, 20918, 20932, 20956, 20976,
-20986, 20998, 21009, 21021, 21033, 21046, 21059, 21069, 21083, 21097, 21109, 21119, 21129, 21147, 21161, 21182,
-21193, 21205, 21215, 21235, 21246, 21256, 21269, 21280, 21290, 21305, 21315, 21325, 21335, 21350, 21360, 21373,
-21395, 21407, 21421, 21435, 21448, 21460, 21473, 21483, 21496, 21507, 21517, 21531, 21542, 21555, 21566, 21576,
-21608, 21619, 21629, 21644, 21668, 21683, 21693, 21704, 21729, 21741, 21754, 21764, 21774, 21788, 21807, 21822,
-21839, 21854, 21884, 21894, 21912, 21927, 21957, 21972, 21983, 22013, 22025, 22036, 22063, 22099, 22120, 22132,
-22150, 22181, 22196, 22218, 22234, 22256, 22266, 22276, 22290, 22303, 22317, 22331, 22343, 22353, 22369, 22382,
-22396, 22408, 22419, 22432, 22467, 22478, 22495, 22512, 22522, 22533, 22558, 22570, 22580, 22602, 22612, 22622,
-22645, 22659, 22675, 22686, 22696, 22707, 22718, 22734, 22744, 22756, 22767, 22777, 22799, 22809, 22823, 22833,
-22846, 22856, 22868, 22880, 22890, 22900, 22914, 22931, 22949, 22969, 22979, 22992, 23002, 23014, 23032, 23043,
-23057, 23067, 23077, 23094, 23105, 23130, 23142, 23186, 23204, 23233, 23244, 23265, 23301, 23318, 23338, 23360,
-23376, 23386, 23396, 23408, 23418, 23429, 23439, 23449, 23459, 23470, 23480, 23490, 23500, 23511, 23521, 23531,
-23541, 23553, 23563, 23574, 23588, 23601, 23611, 23621, 23633, 23643, 23653, 23663, 23673, 23696, 23713, 23723,
-23733, 23744, 23769, 23784, 23796, 23815, 23825, 23847, 23883, 23913, 23943, 23965, 23978, 23992, 24013, 24029,
-24039, 24049, 24061, 24076, 24086, 24101, 24115, 24125, 24135, 24149, 24159, 24178, 24188, 24199, 24213, 24224,
-24235, 24245, 24258, 24272, 24282, 24300, 24310, 24321, 24335, 24347, 24358, 24369, 24380, 24392, 24406, 24418,
-24428, 24439, 24449, 24459, 24471, 24481, 24494, 24505, 24515, 24525, 24535, 24555, 24565, 24575, 24591, 24604,
-24615, 24641, 24653, 24665, 24675, 24685, 24709, 24724, 24735, 24752, 24764, 24775, 24785, 24796, 24816, 24826,
-24838, 24853, 24863, 24880, 24892, 24903, 24915, 24925, 24935, 24950, 24961, 24974, 24984, 24996, 25006, 25018,
-25031, 25062, 25074, 25084, 25095, 25105, 25119, 25130, 25140, 25150, 25160, 25171, 25198, 25209, 25220, 25233,
-25243, 25259, 25269, 25282, 25292, 25302, 25324, 25335, 25345, 25361, 25387, 25402, 25417, 25429, 25447, 25458,
-25471, 25481, 25494, 25504, 25514, 25536, 25551, 25562, 25581, 25591, 25613, 25623, 25634, 25644, 25658, 25688,
-25705, 25720, 25736, 25746, 25758, 25771, 25787, 25797, 25810, 25825, 25836, 25850, 25860, 25880, 25891, 25903,
-25913, 25925, 25935, 25950, 25964, 25975, 25986, 25996, 26007, 26017, 26027, 26039, 26049, 26059, 26071, 26083,
-26093, 26106, 26118, 26128, 26142, 26152, 26164, 26177, 26187, 26201, 26212, 26222, 26232, 26244, 26254, 26264,
-26274, 26286, 26297, 26308, 26326, 26336, 26352, 26362, 26376, 26388, 26398, 26408, 26420, 26438, 26448, 26460,
-26477, 26487, 26503, 26515, 26525, 26543, 26558, 26575, 26586, 26601, 26611, 26622, 26642, 26657, 26671, 26681,
-26691, 26702, 26733, 26751, 26767, 26781, 26791, 26801, 26820, 26834, 26847, 26862, 26873, 26885, 26898, 26919,
-26941, 26954, 26964, 26974, 26984, 26997, 27029, 27045, 27060, 27073, 27083, 27112, 27131, 27146, 27159, 27169,
-27189, 27204, 27218, 27231, 27243, 27264, 27277, 27287, 27298, 27315, 27330, 27347, 27382, 27396, 27410, 27424,
-27442, 27453, 27463, 27487, 27498, 27511, 27523, 27542, 27566, 27578, 27589, 27599, 27611, 27627, 27656, 27667,
-27683, 27700, 27710, 27726, 27738, 27752, 27762, 27773, 27783, 27794, 27819, 27832, 27842, 27852, 27863, 27873,
-27883, 27915, 27927, 27941, 27954, 27965, 27993, 28003, 28014, 28024, 28037, 28049, 28079, 28096, 28107, 28120,
-28136, 28147, 28183, 28193, 28203, 28214, 28227, 28237, 28248, 28263, 28274, 28304, 28316, 28330, 28342, 28354,
-28364, 28399, 28414, 28431, 28448, 28459, 28472, 28497, 28507, 28525, 28538, 28548, 28558, 28579, 28590, 28601,
-28611, 28629, 28639, 28649, 28670, 28681, 28693, 28703, 28719, 28734, 28748, 28760, 28771, 28784, 28796, 28810,
-28824, 28836, 28847, 28857, 28872, 28888, 28913, 28925, 28937, 28953, 28966, 28976, 28999, 29014, 29028, 29038,
-29053, 29065, 29076, 29087, 29100, 29113, 29123, 29134, 29151, 29165, 29179, 29190, 29200, 29211, 29226, 29237,
-29248, 29260, 29272, 29282, 29298, 29309, 29346, 29356, 29376, 29390, 29401, 29417, 29432, 29450, 29462, 29477,
-29494, 29508, 29520, 29544, 29554, 29572, 29582, 29592, 29607, 29618, 29632, 29642, 29654, 29664, 29674, 29687,
-29697, 29715, 29728, 29738, 29748, 29759, 29771, 29781, 29791, 29801, 29822, 29833, 29848, 29859, 29872, 29885,
-29898, 29908, 29920, 29934, 29953, 29969, 29979, 29989, 30000, 30010, 30023, 30033, 30043, 30053, 30063, 30074,
-30086, 30097, 30109, 30123, 30133, 30146, 30157, 30168, 30178, 30192, 30202, 30221, 30233, 30244, 30267, 30284,
-30294, 30305, 30316, 30328, 30340, 30350, 30382, 30394, 30406, 30418, 30428, 30439, 30450, 30460, 30472, 30494,
-30505, 30519, 30541, 30555, 30566, 30585, 30603, 30622, 30636, 30651, 30679, 30690, 30701, 30722, 30738, 30757,
-30770, 30789, 30799, 30813, 30827, 30844, 30855, 30865, 30883, 30906, 30917, 30928, 30952, 30965, 30977, 30990,
-31018, 31034, 31047, 31062, 31072, 31085, 31098, 31117, 31142, 31153, 31165, 31177, 31189, 31199, 31209, 31227,
-31237, 31252, 31263, 31278, 31291, 31302, 31319, 31329, 31339, 31350, 31361, 31378, 31391, 31401, 31418, 31428,
-31447, 31459, 31469, 31481, 31503, 31513, 31526, 31545, 31558, 31568, 31584, 31596, 31613, 31623, 31636, 31649,
-31661, 31672, 31684, 31698, 31712, 31751, 31762, 31774, 31786, 31805, 31820, 31840, 31852, 31875, 31890, 31903,
-31918, 31929, 31946, 31958, 31968, 31995, 32005, 32016, 32026, 32043, 32053, 32066, 32080, 32094, 32104, 32114,
-32127, 32142, 32156, 32172, 32184, 32199, 32214, 32224, 32236, 32251, 32265, 32277, 32287, 32299, 32311, 32321,
-32338, 32350, 32361, 32377, 32396, 32406, 32566, 32588, 32618, 32629, 32645, 32660, 32670, 32680, 32690, 32701,
-32714, 32724, 32735, 32745, 32761, 32771, 32784, 32813, 32829, 32842, 32854, 32879, 32893, 32903, 32918, 32929,
-32943, 32954, 32964, 32974, 32986, 32996, 33009, 33021, 33031, 33048, 33059, 33071, 33081, 33099, 33109, 33125,
-33136, 33146, 33160, 33178, 33192, 33203, 33213, 33229, 33240, 33251, 33261, 33274, 33285, 33298, 33308, 33322,
-33333, 33344, 33369, 33380, 33390, 33400, 33419, 33433, 33445, 33455, 33465, 33489, 33499, 33509, 33521, 33533,
-33545, 33559, 33576, 33588, 33600, 33610, 33651, 33673, 33686, 33698, 33725, 33737, 33747, 33769, 33780, 33795,
-33805, 33833, 33848, 33865, 33879, 33889, 33899, 33909, 33936, 33948, 33970, 33980, 33990, 34001, 34028, 34044,
-34065, 34078, 34092, 34109, 34121, 34131, 34147, 34157, 34180, 34191, 34203, 34214, 34224, 34234, 34249, 34261,
-34276, 34295, 34306, 34326, 34349, 34367, 34382, 34395, 34407, 34425, 34442, 34467, 34503, 34516, 34527, 34541,
-34558, 34568, 34584, 34638, 34655, 34676, 34690, 34701, 34719, 34739, 34756, 34784, 34796, 34809, 34821, 34847,
-34865, 34875, 34886, 34898, 34909, 34920, 34930, 34942, 34952, 34962, 34974, 34987, 35009, 35023, 35033, 35048,
-35059, 35069, 35079, 35090, 35109, 35126, 35137, 35167, 35178, 35199, 35211, 35222, 35233, 35250, 35261, 35282,
-35299, 35316, 35328, 35338, 35350, 35363, 35373, 35386, 35408, 35419, 35430, 35440, 35461, 35475, 35486, 35496,
-35506, 35516, 35527, 35538, 35548, 35558, 35569, 35582, 35598, 35609, 35624, 35635, 35649, 35662, 35672, 35686,
-35696, 35709, 35722, 35734, 35895, 35905, 35916, 35930, 35946, 35961, 35978, 35997, 36007, 36019, 36029, 36039,
-36049, 36060, 36070, 36084, 36100, 36115, 36196, 36208, 36229, 36249, 36259, 36275, 36286, 36299, 36315, 36328,
-36339, 36362, 36382, 36394, 36405, 36418, 36441, 36468, 36481, 36493, 36522, 36544, 36554, 36575, 36587, 36600,
-36611, 36626, 36636, 36646, 36659, 36670, 36681, 36701, 36763, 36774, 36784, 36802, 36814, 36838, 36848, 36861,
-36872, 36884, 36894, 36910, 36920, 36930, 36941, 36953, 36963, 36973, 36983, 36993, 37007, 37017, 37027, 37039,
-37057, 37086, 37096, 37109, 37122, 37138, 37159, 37170, 37193, 37218, 37228, 37239, 37255, 37266, 37276, 37291,
-37301, 37312, 37323, 37335, 37347, 37365, 37389, 37399, 37428, 37439, 37449, 37463, 37474, 37504, 37521, 37532,
-37555, 37580, 37604, 37624, 37636, 37648, 37658, 37668, 37678, 37704, 37716, 37742, 37756, 37772, 37782, 37795,
-37805, 37827, 37841, 37854, 37878, 37892, 37912, 37925, 37941, 37956, 37969, 37979, 38013, 38263, 38275, 38287,
-38307, 38317, 38331, 38343, 38356, 38369, 38428, 38442, 38459, 38475, 38491, 38506, 38517, 38533, 38548, 38563,
-38577, 38587, 38597, 38613, 38626, 38639, 38649, 38662, 38673, 38684, 38695, 38706, 38717, 38728, 38742, 38753,
-38765, 38775, 38795, 38816, 38827, 38854, 38867, 38899, 38911, 38922, 38935, 38957, 38968, 38982, 38996, 39006,
-39019, 39080, 39108, 39131, 39149, 39164, 39177, 39187, 39198, 39208, 39237, 39249, 39318, 39333, 39345, 39361,
-39376, 39389, 39405, 39423, 39438, 39449, 39467, 39478, 39488, 39501, 39511, 39522, 39592, 39608, 39635, 39653,
-39706, 39719, 39729, 39740, 39759, 39770, 39791, 39822, 39839, 39851, 39881, 39894, 39908, 39949, 39973, 39986,
-40007, 40023, 40165, 40179, 40201, 40219, 40230, 40251, 40273, 40285, 40300, 40361, 40372, 40388, 40407, 40434,
-40474, 40565, 40575, 40594, 40605, 40628, 40638, 40653, 40664, 40680, 40692, 40711, 40723, 40736, 40763, 40778,
-40799, 40810, 40823, 40845, 40860, 44032, 44042, 44052, 44064, 44076, 44088, 44107, 44120, 44144, 44154, 44164,
-44176, 44188, 44200, 44216, 44228, 44245, 44256, 44266, 44277, 44288, 44300, 44312, 44329, 44340, 44356, 44368,
-44385, 44396, 44406, 44417, 44428, 44444, 44471, 44481, 44496, 44508, 44536, 44552, 44564, 44592, 44602, 44613,
-44624, 44636, 44648, 44664, 44676, 44732, 44748, 44760, 44776, 44788, 44807, 44844, 44860, 44872, 44892, 44921,
-44932, 44944, 44956, 44984, 44999, 45012, 45032, 45044, 45056, 45068, 45084, 45096, 45124, 45134, 45145, 45180,
-45196, 45208, 45218, 45228, 45240, 45252, 45264, 45280, 45320, 45330, 45340, 45352, 45364, 45376, 45392, 45404,
-45432, 45442, 45453, 45464, 45480, 45516, 45532, 45544, 45561, 45572, 45588, 45600, 45620, 45656, 45672, 45684,
-45700, 45712, 45722, 45733, 45744, 45768, 45778, 45789, 45800, 45811, 45823, 45840, 45852, 45908, 45918, 45929,
-45940, 45952, 45964, 45984, 45996, 46020, 46030, 46041, 46052, 46076, 46096, 46108, 46120, 46132, 46160, 46176,
-46188, 46208, 46237, 46248, 46261, 46272, 46288, 46300, 46310, 46321, 46356, 46372, 46384, 46400, 46411, 46428,
-46496, 46506, 46516, 46528, 46540, 46552, 46572, 46608, 46629, 46644, 46664, 46692, 46748, 46763, 46804, 46832,
-46848, 46888, 46904, 46916, 46932, 46944, 46960, 46972, 46988, 46998, 47008, 47019, 47029, 47047, 47084, 47100,
-47111, 47128, 47140, 47156, 47168, 47185, 47196, 47212, 47224, 47245, 47272, 47284, 47296, 47308, 47325, 47336,
-47352, 47364, 47384, 47420, 47436, 47448, 47464, 47476, 47492, 47502, 47532, 47548, 47560, 47570, 47581, 47592,
-47604, 47616, 47637, 47672, 47682, 47693, 47704, 47716, 47728, 47747, 47784, 47794, 47805, 47816, 47832, 47868,
-47885, 47896, 47913, 47924, 47934, 47945, 47956, 47969, 47980, 48008, 48036, 48052, 48064, 48080, 48120, 48130,
-48140, 48150, 48164, 48176, 48192, 48204, 48221, 48260, 48270, 48281, 48292, 48304, 48316, 48333, 48344, 48372,
-48388, 48400, 48420, 48448, 48460, 48472, 48484, 48512, 48522, 48533, 48548, 48560, 48596, 48617, 48628, 48640,
-48652, 48668, 48708, 48718, 48729, 48740, 48752, 48763, 48780, 48792, 48808, 48848, 48864, 48876, 48897, 48920,
-48960, 48976, 49044, 49072, 49093, 49104, 49116, 49212, 49233, 49244, 49256, 49296, 49312, 49324, 49334, 49344,
-49356, 49368, 49380, 49396, 49408, 49424, 49436, 49446, 49456, 49468, 49480, 49492, 49508, 49520, 49541, 49552,
-49564, 49576, 49597, 49608, 49620, 49632, 49648, 49660, 49676, 49688, 49704, 49714, 49736, 49748, 49760, 49772,
-49788, 49800, 49816, 49828, 49844, 49884, 49899, 49910, 49920, 49932, 49944, 49956, 49989, 50024, 50034, 50044,
-50056, 50112, 50136, 50146, 50157, 50168, 50184, 50212, 50224, 50236, 50248, 50276, 50292, 50304, 50324, 50360,
-50409, 50420, 50431, 50444, 50460, 50472, 50488, 50500, 50510, 50520, 50532, 50544, 50556, 50567, 50577, 50588,
-50601, 50612, 50622, 50632, 50644, 50656, 50668, 50678, 50688, 50700, 50712, 50724, 50734, 50745, 50756, 50768,
-50780, 50796, 50808, 50824, 50836, 50852, 50864, 50874, 50885, 50896, 50908, 50920, 50936, 50948, 50964, 50976,
-50992, 51004, 51018, 51028, 51040, 51051, 51061, 51075, 51086, 51096, 51107, 51117, 51132, 51144, 51160, 51172,
-51200, 51210, 51221, 51232, 51244, 51256, 51272, 51284, 51312, 51322, 51333, 51348, 51359, 51388, 51400, 51412,
-51424, 51445, 51456, 51468, 51480, 51500, 51536, 51552, 51564, 51580, 51592, 51608, 51648, 51658, 51669, 51680,
-51692, 51704, 51720, 51732, 51753, 51788, 51804, 51816, 51837, 51864, 51900, 51916, 51928, 51948, 51976, 51988,
-52000, 52033, 52044, 52056, 52068, 52088, 52124, 52152, 52180, 52196, 52236, 52252, 52263, 52280, 52292, 52308,
-52320, 52336, 52376, 52392, 52404, 52420, 52432, 52452, 52464, 52481, 52492, 52504, 52516, 52537, 52572, 52588,
-52600, 52616, 52628, 52644, 52656, 52676, 52688, 52712, 52728, 52740, 52756, 52768, 52784, 52824, 52840, 52852,
-52868, 52880, 52896, 52908, 52929, 52964, 52980, 52992, 53008, 53020, 53036, 53048, 53076, 53092, 53104, 53120,
-53132, 53153, 53168, 53188, 53216, 53232, 53244, 53265, 53293, 53304, 53316, 53328, 53344, 53356, 53372, 53412,
-53428, 53440, 53456, 53468, 53484, 53496, 53517, 53552, 53562, 53572, 53584, 53596, 53608, 53628, 53640, 53664,
-53680, 53690, 53720, 53748, 53767, 53804, 53820, 53832, 53852, 53888, 53904, 53916, 53932, 53944, 53954, 53972,
-53988, 54000, 54016, 54028, 54038, 54048, 54060, 54072, 54084, 54140, 54156, 54168, 54184, 54196, 54212, 54224,
-54241, 54252, 54268, 54280, 54301, 54336, 54364, 54381, 54392, 54402, 54413, 54441, 54476, 54492, 54504, 54520,
-54532, 54548, 54588, 54604, 54616, 54629, 54644, 54660, 54672, 54693, 54728, 54738, 54749, 54760, 54772, 54784,
-54800, 54812, 54829, 54840, 54853, 54865, 54876, 54887, 54897, 54915, 54925, 54941, 54952, 54969, 54980, 54993,
-55008, 55024, 55036, 55057, 55068, 55080, 55092, 55108, 55120, 55136, 55148, 55164, 55176, 55192, 63744, 63754,
-63764, 63774, 63784, 63794, 63804, 63814, 63824, 63834, 63844, 63854, 63864, 63874, 63884, 63894, 63904, 63914,
-63924, 63934, 63944, 63954, 63964, 63974, 63984, 63994, 64004, 65281, 65291, 65301, 65311, 65321, 65331, 65341,
-65351, 65361, 65371, 65504, 65536
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-162, 174, 162, 180, 161, 215, 161, 167, 168, 163, 161, 169, 161, 198, 161, 190,
-169, 247, 169, 248, 162, 165, 162, 210, 161, 164, 162, 172, 169, 246, 168, 172,
-168, 249, 168, 246, 168, 250, 162, 175, 168, 161, 168, 162, 161, 191, 168, 170,
-168, 173, 169, 172, 169, 161, 169, 163, 161, 192, 169, 170, 169, 173, 169, 162,
-168, 164, 169, 165, 168, 168, 169, 176, 169, 171, 168, 174, 162, 167, 162, 168,
-165, 193, 165, 203, 165, 212, 165, 225, 165, 235, 165, 244, 172, 167, 172, 161,
-172, 172, 172, 182, 172, 192, 172, 218, 172, 228, 172, 238, 161, 170, 162, 211,
-162, 182, 161, 216, 169, 249, 169, 250, 161, 201, 167, 164, 162, 229, 161, 202,
-168, 247, 168, 253, 165, 183, 165, 162, 161, 231, 162, 161, 162, 163, 161, 245,
-161, 238, 161, 171, 161, 197, 161, 214, 161, 193, 161, 236, 161, 248, 162, 193,
-161, 209, 161, 210, 168, 231, 168, 241, 169, 231, 169, 241, 169, 205, 169, 215,
-169, 225, 168, 205, 168, 215, 168, 225, 166, 161, 166, 163, 166, 197, 166, 183,
-166, 208, 166, 170, 166, 218, 166, 226, 162, 198, 161, 225, 161, 227, 161, 229,
-161, 223, 162, 196, 161, 218, 162, 206, 162, 208, 161, 207, 162, 188, 162, 220,
-161, 161, 161, 182, 161, 178, 170, 161, 170, 171, 170, 181, 170, 191, 170, 201,
-170, 211, 170, 221, 170, 231, 170, 241, 171, 161, 171, 171, 171, 181, 171, 191,
-171, 201, 171, 211, 171, 221, 171, 231, 171, 241, 164, 161, 164, 171, 164, 181,
-164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 164, 251, 169, 177,
-169, 187, 169, 197, 168, 177, 168, 187, 168, 197, 162, 222, 167, 201, 167, 220,
-167, 216, 167, 176, 167, 190, 167, 193, 167, 208, 167, 239, 167, 234, 167, 228,
-236, 233, 223, 190, 243, 166, 227, 170, 241, 233, 252, 175, 231, 209, 222, 191,
-227, 171, 202, 225, 220, 227, 213, 175, 236, 163, 208, 230, 249, 241, 204, 200,
-211, 162, 228, 167, 208, 209, 237, 168, 244, 181, 228, 230, 236, 242, 249, 242,
-219, 215, 222, 195, 211, 163, 241, 165, 236, 234, 248, 165, 202, 162, 236, 235,
-246, 182, 215, 194, 217, 178, 248, 181, 231, 235, 204, 201, 220, 193, 225, 243,
-220, 228, 220, 177, 219, 195, 253, 166, 219, 167, 232, 222, 229, 166, 202, 163,
-250, 165, 203, 237, 246, 176, 206, 211, 219, 168, 223, 161, 245, 202, 223, 191,
-208, 193, 223, 192, 214, 246, 232, 233, 202, 164, 229, 226, 234, 227, 223, 193,
-233, 208, 213, 227, 235, 195, 208, 186, 212, 223, 210, 174, 205, 236, 204, 194,
-229, 247, 217, 179, 206, 174, 216, 241, 229, 167, 244, 162, 215, 207, 252, 197,
-245, 243, 221, 194, 250, 253, 244, 248, 215, 215, 240, 164, 244, 239, 238, 241,
-203, 167, 237, 165, 243, 220, 244, 249, 215, 177, 213, 244, 240, 190, 250, 182,
-216, 245, 212, 209, 217, 180, 253, 179, 206, 254, 253, 214, 221, 226, 237, 221,
-221, 227, 249, 175, 244, 182, 216, 179, 209, 245, 206, 207, 236, 212, 241, 237,
-228, 237, 234, 171, 230, 244, 203, 219, 233, 209, 226, 210, 231, 213, 208, 163,
-222, 201, 253, 222, 217, 163, 207, 214, 220, 250, 231, 239, 231, 238, 239, 208,
-241, 178, 218, 171, 217, 164, 251, 250, 246, 227, 250, 166, 236, 214, 249, 235,
-234, 172, 205, 214, 248, 212, 248, 166, 215, 218, 216, 197, 234, 230, 246, 228,
-217, 253, 228, 175, 240, 166, 244, 202, 244, 183, 253, 189, 253, 171, 242, 199,
-243, 170, 225, 245, 202, 169, 207, 165, 225, 176, 250, 198, 208, 239, 221, 196,
-252, 247, 230, 191, 229, 241, 210, 165, 225, 246, 205, 221, 205, 179, 229, 216,
-234, 174, 247, 207, 208, 164, 208, 240, 208, 179, 203, 213, 247, 231, 211, 221,
-246, 243, 211, 220, 250, 167, 235, 217, 228, 239, 224, 242, 230, 180, 243, 241,
-208, 241, 204, 177, 244, 220, 202, 237, 237, 222, 206, 212, 247, 178, 223, 221,
-242, 200, 204, 209, 217, 215, 241, 242, 217, 248, 221, 197, 202, 203, 253, 181,
-215, 164, 229, 189, 237, 224, 236, 236, 249, 190, 226, 212, 211, 222, 227, 247,
-250, 241, 210, 175, 221, 198, 238, 245, 247, 172, 210, 191, 229, 253, 208, 245,
-246, 230, 216, 217, 239, 209, 238, 187, 232, 238, 202, 205, 230, 193, 232, 223,
-222, 207, 231, 244, 228, 176, 246, 165, 215, 165, 251, 230, 220, 254, 216, 218,
-227, 184, 202, 170, 250, 238, 238, 213, 251, 251, 248, 198, 222, 174, 223, 197,
-237, 173, 221, 161, 205, 181, 226, 213, 234, 232, 211, 235, 206, 219, 241, 181,
-224, 190, 207, 224, 227, 228, 238, 214, 221, 163, 210, 188, 205, 251, 222, 208,
-245, 193, 220, 230, 227, 252, 244, 211, 233, 214, 246, 166, 205, 182, 203, 220,
-224, 218, 220, 179, 215, 219, 212, 234, 253, 223, 208, 247, 203, 170, 225, 251,
-251, 192, 225, 252, 246, 185, 228, 177, 250, 214, 226, 253, 205, 223, 226, 254,
-218, 174, 227, 161, 207, 169, 212, 241, 229, 245, 231, 174, 232, 228, 244, 185,
-206, 229, 208, 249, 225, 222, 253, 241, 244, 222, 225, 253, 237, 227, 217, 182,
-219, 172, 216, 173, 246, 186, 202, 206, 234, 234, 221, 231, 238, 188, 223, 202,
-205, 183, 228, 221, 223, 203, 207, 170, 241, 183, 213, 230, 230, 197, 220, 167,
-227, 210, 236, 172, 250, 215, 229, 176, 249, 176, 247, 165, 211, 167, 251, 161,
-222, 175, 219, 173, 239, 214, 215, 200, 212, 240, 229, 217, 218, 176, 244, 203,
-227, 253, 236, 219, 242, 164, 246, 225, 210, 183, 221, 200, 228, 232, 214, 187,
-224, 245, 236, 246, 252, 200, 229, 191, 237, 176, 205, 241, 230, 237, 252, 226,
-231, 246, 240, 245, 211, 250, 212, 195, 251, 227, 224, 173, 246, 231, 224, 246,
-203, 240, 228, 195, 202, 239, 252, 202, 227, 229, 235, 219, 248, 244, 247, 228,
-251, 180, 204, 212, 245, 195, 241, 243, 253, 243, 221, 201, 217, 228, 211, 188,
-202, 208, 209, 215, 243, 164, 207, 171, 211, 212, 228, 178, 208, 189, 239, 184,
-211, 227, 213, 232, 251, 195, 246, 232, 221, 202, 221, 235, 244, 252, 229, 228,
-248, 216, 249, 169, 238, 189, 221, 217, 218, 229, 246, 233, 206, 192, 205, 184,
-242, 165, 211, 251, 241, 169, 239, 216, 243, 181, 248, 218, 220, 233, 207, 236,
-223, 242, 211, 252, 228, 250, 213, 211, 240, 194, 202, 209, 217, 218, 229, 192,
-204, 169, 223, 186, 225, 223, 211, 253, 242, 202, 218, 230, 253, 205, 238, 215,
-216, 164, 217, 184, 214, 206, 223, 174, 211, 213, 217, 232, 211, 181, 244, 186,
-208, 211, 211, 228, 235, 244, 247, 236, 247, 204, 229, 193, 213, 253, 242, 168,
-203, 199, 205, 186, 218, 194, 243, 226, 204, 215, 221, 167, 214, 176, 222, 176,
-212, 224, 228, 214, 237, 197, 211, 168, 219, 177, 224, 193, 208, 253, 208, 254,
-233, 239, 232, 218, 205, 224, 221, 203, 220, 181, 237, 198, 217, 219, 240, 197,
-242, 204, 241, 219, 231, 251, 220, 197, 239, 221, 253, 190, 231, 178, 229, 195,
-243, 229, 217, 186, 224, 231, 231, 165, 228, 242, 206, 199, 232, 216, 240, 198,
-234, 197, 222, 253, 209, 161, 217, 202, 218, 211, 202, 210, 238, 167, 212, 225,
-249, 248, 247, 237, 221, 237, 212, 226, 242, 171, 205, 189, 227, 194, 219, 218,
-234, 246, 207, 175, 215, 179, 239, 222, 226, 227, 206, 232, 233, 241, 208, 198,
-211, 254, 242, 238, 242, 205, 202, 212, 205, 217, 240, 201, 231, 252, 205, 225,
-209, 165, 220, 234, 212, 214, 223, 181, 212, 161, 235, 245, 245, 161, 217, 167,
-230, 203, 229, 197, 224, 219, 215, 209, 239, 223, 208, 191, 233, 190, 252, 206,
-215, 180, 205, 190, 207, 176, 206, 170, 208, 167, 219, 224, 238, 192, 217, 188,
-245, 163, 202, 244, 233, 248, 209, 166, 252, 244, 211, 170, 229, 229, 219, 252,
-203, 254, 222, 177, 212, 162, 214, 208, 250, 203, 213, 177, 213, 178, 253, 226,
-233, 176, 253, 227, 250, 206, 230, 162, 232, 224, 213, 246, 228, 234, 227, 214,
-214, 177, 223, 175, 235, 246, 216, 223, 217, 190, 251, 198, 238, 253, 216, 236,
-209, 168, 226, 169, 219, 240, 219, 241, 231, 253, 205, 231, 208, 227, 209, 169,
-230, 204, 217, 210, 216, 200, 221, 243, 251, 162, 249, 178, 222, 223, 248, 220,
-250, 218, 229, 199, 225, 169, 242, 208, 241, 189, 253, 231, 239, 186, 232, 203,
-221, 169, 246, 217, 230, 238, 225, 215, 228, 243, 239, 227, 215, 250, 212, 163,
-239, 228, 226, 232, 223, 182, 212, 164, 224, 222, 231, 183, 219, 203, 211, 172,
-223, 207, 233, 192, 234, 184, 234, 185, 215, 182, 205, 162, 233, 193, 219, 181,
-244, 175, 244, 242, 205, 227, 215, 169, 216, 174, 216, 188, 239, 194, 218, 254,
-237, 214, 211, 193, 237, 210, 243, 165, 248, 177, 249, 212, 252, 232, 211, 194,
-210, 216, 227, 165, 240, 173, 251, 205, 213, 235, 222, 225, 222, 181, 225, 190,
-231, 187, 213, 179, 206, 180, 247, 168, 216, 189, 252, 233, 237, 199, 246, 167,
-253, 220, 225, 191, 251, 166, 239, 195, 214, 173, 251, 244, 204, 222, 220, 235,
-229, 234, 219, 204, 245, 165, 230, 251, 253, 200, 209, 238, 216, 224, 237, 180,
-224, 195, 233, 251, 233, 194, 226, 217, 232, 162, 253, 248, 230, 215, 214, 250,
-231, 189, 245, 183, 253, 184, 248, 239, 214, 211, 213, 180, 240, 208, 237, 201,
-223, 209, 248, 171, 212, 186, 214, 239, 223, 229, 204, 178, 212, 187, 204, 179,
-223, 210, 228, 228, 238, 195, 226, 173, 215, 225, 231, 217, 243, 233, 232, 229,
-235, 162, 232, 171, 237, 239, 212, 188, 252, 242, 250, 220, 239, 233, 209, 172,
-235, 201, 214, 188, 218, 214, 223, 166, 206, 203, 241, 193, 208, 168, 217, 238,
-224, 196, 232, 205, 239, 162, 209, 174, 208, 214, 251, 234, 234, 212, 249, 194,
-227, 162, 251, 169, 208, 200, 214, 162, 215, 243, 209, 176, 252, 187, 223, 222,
-204, 225, 231, 194, 251, 210, 232, 183, 220, 186, 241, 247, 244, 214, 223, 231,
-239, 163, 239, 235, 208, 180, 239, 165, 242, 213, 213, 212, 241, 225, 203, 177,
-203, 178, 235, 247, 223, 168, 230, 185, 237, 183, 202, 178, 236, 183, 212, 227,
-215, 229, 211, 195, 221, 246, 229, 203, 225, 196, 215, 187, 215, 170, 228, 223,
-219, 254, 246, 194, 224, 200, 205, 164, 238, 220, 206, 235, 249, 171, 245, 212,
-221, 206, 249, 236, 212, 168, 214, 212, 216, 238, 218, 240, 247, 175, 242, 216,
-250, 223, 207, 239, 250, 224, 239, 236, 217, 206, 212, 169, 242, 217, 216, 190,
-226, 235, 244, 215, 245, 184, 227, 197, 211, 173, 222, 227, 221, 247, 242, 178,
-248, 223, 208, 169, 230, 218, 245, 166, 215, 188, 221, 221, 239, 237, 221, 248,
-202, 229, 252, 172, 219, 182, 218, 241, 216, 168, 202, 216, 245, 167, 245, 168,
-213, 236, 227, 198, 209, 182, 240, 211, 222, 230, 240, 174, 209, 184, 252, 161,
-229, 221, 212, 170, 208, 216, 220, 188, 221, 249, 240, 213, 242, 241, 236, 185,
-225, 170, 236, 249, 249, 162, 240, 250, 212, 171, 217, 207, 226, 180, 223, 226,
-252, 174, 207, 188, 212, 205, 242, 242, 207, 223, 232, 192, 208, 170, 243, 193,
-217, 223, 241, 226, 202, 230, 241, 211, 251, 238, 223, 233, 221, 172, 225, 171,
-249, 182, 206, 204, 208, 181, 224, 254, 232, 164, 203, 205, 218, 216, 206, 183,
-239, 169, 238, 198, 219, 244, 227, 217, 225, 198, 240, 234, 243, 194, 211, 175,
-237, 216, 244, 216, 241, 195, 214, 235, 215, 230, 221, 251, 216, 163, 225, 216,
-213, 219, 226, 182, 251, 213, 211, 216, 203, 179, 205, 167, 251, 245, 210, 239,
-208, 228, 237, 185, 238, 199, 240, 251, 204, 191, 206, 237, 235, 214, 222, 234,
-207, 189, 239, 242, 240, 252, 226, 184, 215, 198, 246, 197, 223, 253, 244, 243,
-216, 251, 246, 198, 242, 219, 232, 178, 233, 178, 220, 238, 215, 172, 219, 229,
-241, 249, 233, 164, 227, 177, 230, 186, 225, 217, 224, 233, 221, 174, 229, 162,
-241, 170, 216, 225, 212, 254, 205, 196, 226, 186, 224, 204, 253, 253, 233, 226,
-236, 205, 223, 214, 238, 225, 248, 187, 206, 238, 205, 197, 210, 177, 209, 190,
-247, 176, 214, 253, 225, 161, 214, 164, 244, 233, 240, 220, 245, 171, 205, 198,
-208, 233, 248, 203, 241, 176, 247, 195, 219, 207, 235, 202, 206, 205, 210, 246,
-250, 247, 232, 210, 226, 238, 248, 225, 243, 236, 228, 253, 232, 211, 225, 163,
-233, 166, 224, 205, 204, 174, 221, 177, 248, 179, 224, 206, 211, 197, 240, 176,
-213, 196, 227, 237, 246, 171, 211, 230, 207, 192, 224, 162, 226, 239, 249, 254,
-246, 236, 221, 178, 243, 237, 235, 250, 202, 221, 245, 172, 233, 227, 221, 179,
-203, 206, 228, 165, 208, 202, 234, 189, 202, 180, 229, 180, 231, 200, 205, 201,
-216, 201, 217, 171, 237, 188, 252, 237, 226, 240, 251, 170, 212, 229, 215, 233,
-204, 236, 250, 248, 216, 213, 214, 225, 206, 162, 220, 204, 228, 224, 245, 254,
-248, 195, 245, 215, 235, 173, 231, 168, 238, 202, 248, 227, 251, 217, 208, 173,
-226, 189, 223, 170, 248, 228, 243, 239, 224, 182, 222, 238, 220, 239, 214, 254,
-217, 161, 215, 173, 225, 202, 248, 204, 245, 175, 233, 254, 226, 242, 225, 203,
-218, 221, 235, 251, 224, 224, 244, 192, 253, 185, 240, 177, 237, 190, 233, 228,
-212, 246, 238, 203, 231, 222, 229, 238, 213, 181, 213, 161, 251, 219, 250, 200,
-253, 208, 251, 246, 218, 165, 205, 247, 222, 239, 252, 238, 206, 241, 242, 244,
-228, 182, 232, 165, 242, 187, 202, 233, 234, 218, 251, 221, 213, 204, 235, 215,
-217, 173, 211, 217, 246, 222, 218, 246, 224, 209, 250, 175, 227, 178, 213, 197,
-205, 204, 216, 193, 241, 235, 250, 229, 245, 250, 248, 250, 210, 164, 208, 218,
-202, 183, 211, 178, 205, 229, 249, 172, 238, 174, 215, 234, 207, 217, 222, 165,
-223, 215, 240, 178, 220, 220, 248, 230, 233, 179, 227, 168, 203, 186, 208, 220,
-216, 202, 224, 164, 204, 184, 227, 202, 204, 175, 208, 204, 213, 194, 202, 199,
-250, 176, 223, 216, 229, 235, 227, 242, 253, 225, 204, 193, 224, 226, 242, 224,
-222, 241, 238, 204, 227, 203, 253, 254, 241, 202, 224, 165, 229, 222, 252, 239,
-206, 164, 235, 254, 211, 200, 213, 223, 244, 227, 244, 244, 253, 201, 209, 231,
-218, 186, 204, 197, 217, 200, 207, 196, 252, 166, 253, 210, 227, 219, 204, 237,
-236, 161, 231, 226, 220, 168, 243, 217, 205, 219, 252, 195, 232, 213, 212, 202,
-251, 223, 248, 251, 216, 231, 248, 175, 222, 184, 236, 195, 236, 194, 237, 192,
-242, 225, 222, 244, 221, 183, 214, 243, 242, 190, 237, 252, 238, 229, 241, 203,
-245, 177, 240, 225, 246, 172, 240, 235, 242, 191, 219, 162, 247, 245, 206, 165,
-212, 175, 233, 201, 203, 230, 241, 161, 241, 162, 235, 179, 245, 236, 245, 237,
-240, 226, 229, 184, 215, 245, 207, 198, 243, 179, 230, 227, 242, 226, 245, 238,
-206, 242, 244, 229, 246, 202, 214, 166, 241, 205, 239, 173, 239, 174, 230, 172,
-227, 244, 247, 253, 242, 227, 233, 230, 231, 202, 202, 188, 226, 251, 245, 218,
-251, 173, 212, 178, 214, 193, 244, 245, 236, 239, 226, 196, 248, 188, 233, 171,
-204, 186, 240, 228, 244, 195, 216, 228, 213, 164, 216, 215, 209, 225, 202, 251,
-233, 244, 213, 205, 221, 187, 233, 232, 228, 199, 245, 219, 212, 248, 211, 179,
-235, 183, 245, 178, 226, 198, 251, 229, 226, 245, 225, 165, 245, 221, 236, 162,
-203, 217, 229, 212, 224, 183, 225, 242, 240, 229, 243, 251, 212, 239, 235, 205,
-214, 194, 239, 175, 250, 232, 204, 198, 219, 164, 235, 222, 224, 213, 249, 231,
-231, 229, 239, 251, 224, 167, 203, 234, 214, 226, 245, 222, 238, 182, 209, 197,
-205, 209, 231, 204, 228, 200, 235, 185, 246, 221, 204, 199, 225, 240, 251, 175,
-242, 229, 240, 236, 238, 235, 233, 203, 243, 161, 252, 245, 241, 164, 224, 214,
-244, 209, 241, 209, 202, 252, 206, 206, 243, 200, 237, 254, 224, 236, 235, 206,
-202, 200, 213, 239, 231, 162, 228, 225, 249, 239, 244, 197, 221, 189, 248, 161,
-240, 230, 215, 176, 248, 206, 219, 214, 215, 213, 233, 234, 204, 176, 215, 246,
-235, 223, 244, 180, 228, 186, 240, 231, 215, 238, 218, 167, 218, 223, 239, 253,
-239, 197, 223, 220, 217, 246, 214, 218, 240, 184, 214, 196, 239, 254, 218, 188,
-236, 229, 236, 230, 251, 185, 207, 211, 207, 212, 244, 199, 249, 219, 235, 229,
-250, 194, 233, 245, 247, 246, 212, 233, 204, 242, 206, 168, 228, 212, 215, 190,
-239, 181, 249, 166, 248, 253, 222, 171, 246, 208, 222, 248, 250, 195, 228, 187,
-239, 182, 206, 189, 216, 195, 209, 199, 226, 207, 220, 224, 246, 238, 218, 224,
-241, 210, 246, 239, 250, 180, 241, 231, 209, 200, 248, 190, 203, 246, 245, 226,
-216, 233, 253, 164, 250, 208, 213, 240, 205, 233, 250, 181, 226, 208, 231, 163,
-226, 209, 215, 162, 234, 166, 208, 161, 234, 224, 229, 224, 214, 219, 239, 198,
-228, 213, 206, 247, 215, 239, 244, 237, 205, 230, 245, 227, 252, 191, 232, 167,
-203, 190, 215, 247, 240, 232, 220, 243, 228, 188, 234, 196, 228, 236, 251, 248,
-204, 187, 228, 189, 221, 223, 217, 208, 249, 205, 205, 174, 207, 206, 246, 175,
-229, 164, 214, 221, 214, 227, 209, 203, 222, 250, 207, 213, 253, 203, 224, 168,
-217, 249, 211, 218, 218, 189, 232, 168, 205, 213, 224, 169, 222, 172, 240, 186,
-238, 210, 243, 187, 228, 203, 215, 163, 207, 207, 176, 161, 176, 167, 176, 172,
-176, 181, 176, 183, 176, 188, 176, 192, 176, 195, 176, 197, 176, 202, 176, 206,
-176, 213, 176, 215, 176, 220, 176, 226, 176, 232, 176, 235, 176, 237, 176, 242,
-176, 248, 176, 252, 177, 161, 177, 165, 177, 168, 177, 171, 177, 175, 177, 179,
-177, 182, 177, 184, 177, 190, 177, 195, 177, 199, 177, 201, 177, 204, 177, 206,
-177, 209, 177, 212, 177, 215, 177, 221, 177, 225, 177, 226, 177, 231, 177, 235,
-177, 241, 177, 244, 177, 250, 177, 254, 178, 165, 178, 168, 178, 173, 178, 178,
-178, 181, 178, 184, 178, 187, 178, 191, 178, 196, 178, 202, 178, 205, 178, 209,
-178, 211, 178, 213, 178, 216, 178, 217, 178, 221, 178, 227, 178, 229, 178, 233,
-178, 235, 178, 238, 178, 241, 178, 243, 178, 244, 178, 249, 178, 254, 179, 162,
-179, 166, 179, 170, 179, 177, 179, 181, 179, 189, 179, 191, 179, 196, 179, 200,
-179, 202, 179, 207, 179, 212, 179, 217, 179, 219, 179, 224, 179, 228, 179, 233,
-179, 235, 179, 239, 179, 243, 179, 247, 179, 249, 179, 250, 179, 253, 180, 162,
-180, 166, 180, 169, 180, 174, 180, 178, 180, 179, 180, 181, 180, 184, 180, 186,
-180, 189, 180, 192, 180, 197, 180, 201, 180, 205, 180, 207, 180, 211, 180, 215,
-180, 220, 180, 226, 180, 234, 180, 239, 180, 244, 180, 245, 180, 251, 181, 162,
-181, 167, 181, 169, 181, 174, 181, 177, 181, 180, 181, 181, 181, 186, 181, 191,
-181, 195, 181, 197, 181, 198, 181, 200, 181, 202, 181, 205, 181, 206, 181, 210,
-181, 214, 181, 215, 181, 217, 181, 219, 181, 221, 181, 224, 181, 227, 181, 229,
-181, 234, 181, 238, 181, 240, 181, 245, 181, 251, 182, 161, 182, 166, 182, 171,
-182, 176, 182, 180, 182, 185, 182, 190, 182, 192, 182, 197, 182, 198, 182, 199,
-182, 203, 182, 205, 182, 206, 182, 207, 182, 209, 182, 213, 182, 216, 182, 217,
-182, 220, 182, 223, 182, 228, 182, 231, 182, 234, 182, 236, 182, 239, 182, 243,
-182, 247, 182, 253, 183, 164, 183, 167, 183, 171, 183, 173, 183, 175, 183, 179,
-183, 184, 183, 189, 183, 193, 183, 197, 183, 202, 183, 204, 183, 206, 183, 210,
-183, 214, 183, 216, 183, 217, 183, 219, 183, 221, 183, 225, 183, 228, 183, 231,
-183, 235, 183, 239, 183, 240, 183, 242, 183, 246, 183, 249, 183, 253, 184, 163,
-184, 167, 184, 173, 184, 174, 184, 178, 184, 182, 184, 189, 184, 193, 184, 199,
-184, 201, 184, 207, 184, 210, 184, 211, 184, 215, 184, 219, 184, 224, 184, 226,
-184, 231, 184, 235, 184, 240, 184, 245, 184, 249, 184, 251, 184, 252, 184, 254,
-185, 163, 185, 166, 185, 169, 185, 171, 185, 178, 185, 182, 185, 186, 185, 188,
-185, 190, 185, 191, 185, 194, 185, 197, 185, 199, 185, 202, 185, 204, 185, 209,
-185, 213, 185, 219, 185, 227, 185, 232, 185, 236, 185, 242, 185, 245, 185, 246,
-185, 251, 186, 161, 186, 165, 186, 168, 186, 173, 186, 177, 186, 182, 186, 184,
-186, 189, 186, 193, 186, 195, 186, 197, 186, 200, 186, 202, 186, 204, 186, 206,
-186, 212, 186, 216, 186, 220, 186, 221, 186, 223, 186, 227, 186, 229, 186, 231,
-186, 234, 186, 238, 186, 241, 186, 245, 186, 249, 186, 254, 187, 163, 187, 168,
-187, 173, 187, 178, 187, 180, 187, 181, 187, 186, 187, 190, 187, 191, 187, 194,
-187, 199, 187, 203, 187, 206, 187, 207, 187, 208, 187, 211, 187, 213, 187, 216,
-187, 217, 187, 219, 187, 221, 187, 223, 187, 227, 187, 231, 187, 238, 187, 242,
-187, 247, 187, 249, 187, 254, 188, 164, 188, 168, 188, 171, 188, 173, 188, 180,
-188, 185, 188, 190, 188, 192, 188, 197, 188, 201, 188, 206, 188, 209, 188, 213,
-188, 216, 188, 221, 188, 225, 188, 227, 188, 229, 188, 232, 188, 235, 188, 238,
-188, 242, 188, 246, 188, 251, 189, 163, 189, 165, 189, 168, 189, 170, 189, 172,
-189, 176, 189, 180, 189, 183, 189, 186, 189, 191, 189, 195, 189, 200, 189, 205,
-189, 210, 189, 213, 189, 218, 189, 220, 189, 224, 189, 225, 189, 229, 189, 232,
-189, 235, 189, 237, 189, 238, 189, 243, 189, 246, 189, 249, 189, 250, 189, 252,
-189, 254, 190, 162, 190, 164, 190, 165, 190, 169, 190, 172, 190, 173, 190, 175,
-190, 177, 190, 180, 190, 183, 190, 186, 190, 189, 190, 190, 190, 194, 190, 198,
-190, 205, 190, 210, 190, 216, 190, 218, 190, 223, 190, 227, 190, 231, 190, 235,
-190, 237, 190, 238, 190, 245, 190, 250, 191, 163, 191, 165, 191, 169, 191, 174,
-191, 180, 191, 186, 191, 188, 191, 192, 191, 197, 191, 203, 191, 207, 191, 209,
-191, 214, 191, 217, 191, 220, 191, 224, 191, 228, 191, 232, 191, 236, 191, 241,
-191, 245, 191, 248, 191, 250, 191, 254, 192, 164, 192, 167, 192, 171, 192, 175,
-192, 179, 192, 184, 192, 188, 192, 195, 192, 201, 192, 203, 192, 205, 192, 210,
-192, 217, 192, 223, 192, 227, 192, 232, 192, 235, 192, 240, 192, 245, 192, 247,
-192, 250, 192, 254, 193, 164, 193, 168, 193, 170, 193, 174, 193, 177, 193, 181,
-193, 182, 193, 186, 193, 190, 193, 196, 193, 198, 193, 201, 193, 204, 193, 206,
-193, 210, 193, 213, 193, 216, 193, 220, 193, 224, 193, 225, 193, 227, 193, 231,
-193, 234, 193, 237, 193, 238, 193, 242, 193, 246, 193, 251, 194, 161, 194, 167,
-194, 171, 194, 176, 194, 180, 194, 185, 194, 187, 194, 188, 194, 192, 194, 197,
-194, 198, 194, 200, 194, 201, 194, 205, 194, 210, 194, 213, 194, 215, 194, 217,
-194, 219, 194, 221, 194, 224, 194, 226, 194, 229, 194, 230, 194, 232, 194, 233,
-194, 234, 194, 235, 194, 238, 194, 242, 194, 246, 194, 252, 195, 164, 195, 168,
-195, 173, 195, 177, 195, 179, 195, 183, 195, 188, 195, 192, 195, 196, 195, 198,
-195, 200, 195, 201, 195, 204, 195, 206, 195, 210, 195, 213, 195, 214, 195, 217,
-195, 221, 195, 222, 195, 223, 195, 227, 195, 231, 195, 232, 195, 234, 195, 235,
-195, 238, 195, 242, 195, 245, 195, 247, 195, 251, 196, 161, 196, 167, 196, 171,
-196, 175, 196, 179, 196, 183, 196, 188, 196, 190, 196, 191, 196, 196, 196, 201,
-196, 205, 196, 209, 196, 212, 196, 217, 196, 218, 196, 222, 196, 226, 196, 230,
-196, 232, 196, 233, 196, 235, 196, 236, 196, 237, 196, 241, 196, 245, 196, 248,
-196, 250, 196, 253, 197, 161, 197, 165, 197, 168, 197, 169, 197, 173, 197, 176,
-197, 180, 197, 184, 197, 189, 197, 194, 197, 198, 197, 203, 197, 204, 197, 205,
-197, 209, 197, 213, 197, 217, 197, 219, 197, 223, 197, 225, 197, 227, 197, 228,
-197, 232, 197, 236, 197, 239, 197, 240, 197, 242, 197, 245, 197, 249, 197, 253,
-197, 254, 198, 162, 198, 166, 198, 169, 198, 172, 198, 174, 198, 179, 198, 183,
-198, 186, 198, 188, 198, 192, 198, 196, 198, 201, 198, 205, 198, 210, 198, 212,
-198, 217, 198, 219, 198, 223, 198, 228, 198, 232, 198, 236, 198, 239, 198, 243,
-198, 245, 198, 247, 198, 251, 199, 161, 199, 162, 199, 163, 199, 165, 199, 168,
-199, 170, 199, 175, 199, 179, 199, 181, 199, 182, 199, 185, 199, 187, 199, 190,
-199, 193, 199, 196, 199, 199, 199, 203, 199, 207, 199, 211, 199, 216, 199, 220,
-199, 225, 199, 226, 199, 227, 199, 231, 199, 235, 199, 238, 199, 240, 199, 244,
-199, 248, 199, 253, 200, 162, 200, 163, 200, 167, 200, 172, 200, 176, 200, 177,
-200, 180, 200, 182, 200, 185, 200, 188, 200, 191, 200, 194, 200, 196, 200, 200,
-200, 204, 200, 207, 200, 209, 200, 213, 200, 216, 200, 218, 200, 222, 200, 226,
-200, 229, 200, 236, 200, 241, 200, 244, 200, 247, 200, 251, 203, 208, 208, 221,
-209, 226, 209, 239, 210, 167, 210, 196, 210, 208, 210, 222, 210, 234, 212, 230,
-219, 228, 224, 241, 229, 187, 229, 254, 230, 184, 230, 223, 230, 241, 231, 172,
-231, 208, 232, 247, 234, 244, 235, 189, 235, 216, 236, 186, 236, 225, 237, 238,
-247, 200, 163, 161, 163, 171, 163, 181, 163, 191, 163, 201, 163, 211, 163, 221,
-163, 231, 163, 241, 163, 251, 161, 203, 0
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GB2312.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GB2312.java
deleted file mode 100644
index 9b178d8..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GB2312.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-public class Charset_MultiByte_GB2312 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "GB2312";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-164, 167, 168, 176, 177, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243, 247,
-249, 250, 252, 257, 275, 333, 363, 462, 711, 913, 945, 1025, 1055, 1085, 8213, 8243,
-8451, 8544, 8592, 8712, 8743, 8776, 8814, 8857, 8978, 9312, 9342, 9472, 9502, 9532, 9632, 9670,
-9733, 9792, 12288, 12353, 12383, 12413, 12449, 12479, 12509, 12539, 12569, 12832, 19968, 19998, 20029, 20060,
-20094, 20127, 20159, 20189, 20219, 20249, 20280, 20311, 20342, 20372, 20405, 20439, 20472, 20504, 20538, 20570,
-20603, 20643, 20687, 20717, 20747, 20799, 20834, 20864, 20896, 20928, 20960, 20991, 21021, 21051, 21084, 21117,
-21147, 21182, 21215, 21246, 21277, 21307, 21338, 21368, 21400, 21430, 21460, 21490, 21520, 21550, 21584, 21617,
-21647, 21677, 21708, 21738, 21769, 21799, 21830, 21860, 21890, 21927, 21957, 21987, 22017, 22047, 22079, 22114,
-22149, 22179, 22218, 22251, 22281, 22312, 22343, 22374, 22404, 22434, 22466, 22496, 22528, 22558, 22596, 22629,
-22659, 22696, 22737, 22768, 22799, 22829, 22859, 22899, 22930, 22962, 22992, 23033, 23064, 23094, 23125, 23156,
-23186, 23218, 23250, 23281, 23318, 23348, 23379, 23409, 23439, 23472, 23504, 23534, 23567, 23601, 23631, 23662,
-23692, 23723, 23755, 23786, 23822, 23853, 23883, 23913, 23961, 23991, 24027, 24061, 24091, 24123, 24155, 24186,
-24217, 24247, 24278, 24308, 24339, 24369, 24400, 24432, 24464, 24494, 24524, 24554, 24586, 24616, 24651, 24681,
-24713, 24744, 24774, 24806, 24838, 24868, 24904, 24935, 24971, 25001, 25032, 25062, 25094, 25124, 25155, 25187,
-25220, 25250, 25282, 25314, 25345, 25375, 25405, 25438, 25472, 25504, 25534, 25566, 25597, 25627, 25658, 25688,
-25720, 25750, 25781, 25815, 25856, 25893, 25925, 25955, 25991, 26021, 26051, 26082, 26112, 26143, 26174, 26207,
-26238, 26269, 26302, 26332, 26364, 26395, 26426, 26460, 26492, 26522, 26552, 26584, 26621, 26653, 26684, 26720,
-26753, 26786, 26816, 26848, 26881, 26911, 26941, 26973, 27004, 27035, 27067, 27099, 27133, 27167, 27197, 27227,
-27257, 27287, 27424, 27454, 27490, 27521, 27553, 27583, 27617, 27653, 27684, 27714, 27744, 27774, 27807, 27837,
-27867, 27898, 27929, 27961, 27993, 28023, 28053, 28085, 28118, 28151, 28182, 28212, 28243, 28286, 28316, 28346,
-28378, 28409, 28448, 28478, 28508, 28538, 28572, 28608, 28638, 28689, 28725, 28766, 28796, 28828, 28859, 28889,
-28919, 28949, 28982, 29020, 29050, 29080, 29113, 29152, 29190, 29224, 29255, 29286, 29316, 29356, 29389, 29420,
-29450, 29481, 29517, 29548, 29579, 29609, 29640, 29671, 29701, 29733, 29781, 29814, 29852, 29882, 29916, 29951,
-29983, 30014, 30044, 30079, 30109, 30140, 30171, 30201, 30231, 30261, 30292, 30328, 30358, 30388, 30418, 30449,
-30489, 30519, 30554, 30585, 30623, 30653, 30683, 30717, 30748, 30778, 30813, 30844, 30874, 30905, 30937, 30967,
-31006, 31036, 31066, 31096, 31130, 31161, 31192, 31224, 31255, 31287, 31319, 31350, 31381, 31411, 31446, 31481,
-31513, 31544, 31574, 31605, 31636, 31668, 31699, 31729, 31759, 31800, 31859, 31889, 31921, 31957, 31992, 32032,
-32110, 32166, 32315, 32386, 32416, 32446, 32476, 32506, 32536, 32566, 32596, 32626, 32660, 32690, 32724, 32755,
-32786, 32817, 32850, 32881, 32915, 32945, 32982, 33012, 33042, 33073, 33104, 33134, 33167, 33203, 33251, 33281,
-33311, 33342, 33375, 33405, 33436, 33469, 33499, 33529, 33559, 33589, 33620, 33655, 33688, 33718, 33748, 33778,
-33809, 33841, 33873, 33905, 33943, 33976, 34006, 34044, 34074, 34104, 34134, 34164, 34203, 34233, 34268, 34299,
-34343, 34381, 34411, 34442, 34472, 34502, 34532, 34562, 34593, 34623, 34656, 34686, 34719, 34749, 34779, 34809,
-34843, 34873, 34903, 34935, 34966, 34999, 35029, 35059, 35090, 35120, 35166, 35199, 35265, 35299, 35335, 35390,
-35449, 35591, 35622, 35686, 35744, 35774, 35804, 35834, 35864, 35894, 35925, 35955, 35988, 36125, 36155, 36185,
-36215, 36255, 36286, 36317, 36347, 36381, 36413, 36454, 36485, 36523, 36558, 36710, 36740, 36771, 36801, 36831,
-36861, 36891, 36923, 36955, 36989, 37019, 37049, 37079, 37112, 37145, 37177, 37207, 37237, 37274, 37306, 37340,
-37492, 37550, 37694, 37738, 37775, 37834, 37950, 37995, 38025, 38055, 38085, 38115, 38145, 38175, 38206, 38236,
-38271, 38376, 38406, 38442, 38472, 38503, 38533, 38567, 38597, 38632, 38662, 38698, 38738, 38771, 38801, 38831,
-38886, 39029, 39059, 39118, 39181, 39214, 39252, 39282, 39312, 39532, 39562, 39592, 39627, 39659, 39695, 39727,
-39757, 40060, 40090, 40120, 40150, 40479, 40509, 40539, 40574, 40605, 40635, 40667, 40697, 40727, 40759, 40831,
-40863, 65281, 65311, 65341, 65371, 65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 193, 168, 164, 168, 162,
-168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174, 161, 194,
-168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 173, 168, 177, 168, 163,
-161, 166, 166, 161, 166, 193, 167, 167, 167, 177, 167, 223, 161, 170, 161, 229,
-161, 230, 162, 241, 161, 251, 161, 202, 161, 196, 161, 214, 161, 218, 161, 209,
-161, 208, 162, 217, 162, 207, 169, 164, 169, 194, 169, 224, 161, 246, 161, 244,
-161, 239, 161, 226, 161, 161, 164, 161, 164, 191, 164, 221, 165, 161, 165, 191,
-165, 221, 161, 164, 168, 217, 162, 229, 210, 187, 216, 169, 192, 246, 216, 191,
-199, 172, 216, 189, 210, 218, 217, 218, 200, 206, 187, 239, 201, 236, 217, 162,
-217, 165, 217, 176, 199, 214, 203, 215, 217, 186, 204, 200, 213, 174, 215, 246,
-217, 205, 180, 246, 207, 241, 217, 212, 217, 217, 182, 249, 190, 164, 188, 189,
-185, 218, 190, 187, 188, 184, 212, 228, 179, 245, 191, 204, 216, 224, 216, 226,
-193, 166, 219, 192, 196, 188, 185, 180, 212, 209, 210, 189, 178, 169, 208, 182,
-192, 229, 219, 204, 202, 229, 202, 183, 205, 194, 203, 177, 196, 197, 223, 201,
-211, 189, 223, 210, 223, 223, 196, 196, 176, 166, 223, 243, 201, 204, 198, 161,
-206, 185, 208, 250, 208, 225, 203, 195, 224, 210, 224, 189, 186, 217, 224, 222,
-224, 233, 207, 249, 196, 210, 224, 241, 224, 246, 212, 218, 190, 249, 204, 185,
-194, 162, 185, 184, 185, 161, 178, 186, 220, 165, 220, 166, 220, 168, 220, 170,
-190, 179, 196, 171, 219, 214, 201, 249, 207, 196, 216, 178, 183, 220, 197, 174,
-182, 202, 230, 167, 189, 227, 230, 177, 196, 239, 200, 162, 230, 188, 211, 164,
-195, 189, 230, 199, 230, 200, 230, 205, 230, 212, 217, 248, 230, 222, 229, 238,
-186, 234, 212, 215, 195, 194, 229, 188, 208, 161, 190, 205, 198, 193, 229, 248,
-225, 167, 225, 182, 225, 190, 211, 248, 198, 233, 213, 184, 225, 210, 225, 212,
-225, 215, 225, 218, 231, 221, 217, 227, 178, 175, 224, 253, 225, 164, 231, 219,
-195, 237, 191, 181, 193, 206, 219, 200, 185, 173, 200, 245, 229, 230, 213, 195,
-208, 236, 206, 162, 188, 201, 226, 236, 226, 247, 212, 185, 193, 181, 182, 247,
-207, 164, 196, 250, 227, 176, 181, 235, 237, 169, 183, 223, 180, 200, 187, 219,
-177, 239, 237, 172, 208, 184, 197, 179, 237, 176, 234, 174, 236, 231, 191, 219,
-179, 173, 199, 192, 183, 247, 194, 163, 179, 214, 208, 174, 205, 236, 192, 204,
-207, 198, 194, 211, 222, 242, 222, 238, 192, 191, 222, 246, 208, 175, 213, 170,
-195, 254, 222, 254, 196, 236, 223, 168, 197, 202, 223, 172, 185, 202, 201, 162,
-206, 196, 179, 226, 236, 185, 188, 200, 234, 192, 208, 199, 207, 212, 234, 201,
-193, 192, 234, 212, 234, 213, 234, 215, 194, 252, 205, 251, 187, 250, 182, 197,
-232, 204, 195, 182, 232, 219, 232, 207, 232, 223, 232, 233, 184, 241, 232, 226,
-193, 186, 201, 210, 188, 236, 204, 196, 233, 164, 232, 252, 180, 170, 233, 172,
-194, 165, 233, 187, 233, 189, 188, 247, 178, 219, 213, 193, 233, 215, 233, 211,
-233, 214, 233, 222, 199, 183, 191, 238, 214, 185, 233, 226, 233, 235, 181, 238,
-213, 177, 235, 169, 235, 179, 199, 243, 179, 216, 183, 218, 185, 181, 185, 193,
-183, 186, 227, 248, 228, 168, 228, 161, 213, 227, 186, 163, 204, 233, 186, 173,
-196, 215, 187, 236, 228, 201, 191, 202, 228, 212, 205, 229, 193, 239, 196, 231,
-185, 246, 228, 239, 196, 174, 209, 250, 199, 177, 228, 253, 192, 189, 188, 164,
-229, 168, 198, 217, 229, 175, 229, 177, 215, 198, 236, 191, 236, 194, 192, 211,
-205, 233, 187, 192, 200, 187, 236, 207, 236, 213, 236, 214, 236, 228, 236, 219,
-177, 172, 236, 224, 198, 172, 234, 243, 234, 247, 200, 174, 225, 243, 182, 192,
-226, 165, 208, 201, 226, 176, 226, 179, 205, 245, 205, 230, 231, 236, 231, 242,
-192, 197, 231, 250, 232, 166, 209, 254, 232, 171, 232, 183, 185, 207, 234, 179,
-201, 250, 231, 222, 208, 243, 231, 220, 240, 222, 204, 219, 205, 180, 177, 212,
-240, 249, 241, 169, 241, 175, 185, 239, 205, 238, 241, 229, 186, 208, 237, 236,
-237, 244, 190, 236, 237, 253, 182, 195, 238, 169, 238, 173, 195, 172, 206, 249,
-237, 191, 237, 194, 207, 245, 197, 240, 237, 213, 237, 219, 237, 222, 193, 215,
-237, 230, 192, 241, 236, 241, 187, 246, 236, 250, 211, 237, 195, 216, 189, 213,
-176, 222, 240, 162, 203, 235, 190, 191, 241, 187, 241, 193, 202, 250, 214, 241,
-243, 207, 243, 205, 178, 223, 243, 219, 178, 173, 243, 240, 194, 168, 192, 233,
-243, 252, 244, 164, 195, 215, 244, 206, 193, 187, 184, 226, 244, 233, 203, 216,
-208, 245, 244, 235, 247, 227, 215, 235, 190, 192, 231, 163, 194, 231, 231, 184,
-212, 181, 243, 190, 216, 232, 202, 240, 184, 225, 244, 203, 207, 232, 244, 232,
-241, 231, 241, 242, 241, 248, 241, 250, 235, 193, 235, 197, 197, 214, 235, 216,
-235, 223, 205, 209, 184, 175, 200, 249, 184, 224, 201, 197, 179, 188, 244, 168,
-214, 219, 244, 184, 244, 190, 220, 180, 206, 223, 209, 191, 191, 193, 198, 187,
-220, 248, 210, 240, 192, 243, 186, 201, 221, 183, 221, 178, 221, 202, 183, 198,
-221, 200, 221, 230, 221, 215, 180, 208, 221, 245, 213, 244, 177, 205, 222, 164,
-206, 181, 221, 250, 222, 161, 212, 204, 209, 166, 222, 183, 222, 188, 212, 229,
-222, 190, 242, 174, 179, 230, 206, 195, 242, 182, 199, 249, 184, 242, 183, 228,
-192, 175, 242, 234, 242, 240, 242, 238, 195, 248, 243, 174, 243, 178, 208, 183,
-243, 186, 243, 188, 189, 214, 214, 212, 208, 228, 241, 202, 212, 163, 201, 209,
-176, 253, 229, 189, 244, 197, 206, 247, 188, 251, 189, 226, 217, 234, 246, 164,
-213, 178, 229, 192, 246, 165, 190, 175, 218, 165, 201, 232, 218, 183, 197, 181,
-218, 209, 218, 223, 245, 185, 225, 217, 245, 249, 177, 180, 234, 221, 234, 231,
-198, 240, 204, 203, 214, 186, 190, 224, 245, 210, 245, 215, 245, 225, 177, 196,
-245, 238, 201, 237, 234, 166, 179, 181, 233, 252, 192, 177, 199, 168, 179, 217,
-215, 183, 185, 228, 194, 223, 229, 222, 229, 225, 218, 246, 215, 222, 219, 173,
-181, 166, 177, 201, 219, 184, 208, 239, 189, 205, 195, 209, 245, 184, 184, 170,
-188, 248, 246, 199, 246, 201, 246, 202, 246, 204, 246, 203, 246, 205, 246, 206,
-182, 164, 190, 251, 199, 166, 207, 179, 203, 248, 239, 191, 239, 204, 190, 181,
-179, 164, 195, 197, 227, 207, 218, 230, 179, 194, 218, 237, 211, 231, 203, 237,
-209, 197, 211, 234, 246, 170, 246, 175, 199, 224, 189, 249, 247, 178, 247, 181,
-206, 164, 210, 179, 205, 199, 183, 231, 247, 208, 247, 209, 247, 211, 203, 199,
-226, 202, 194, 237, 230, 234, 185, 199, 247, 197, 247, 216, 247, 221, 219, 203,
-247, 205, 211, 227, 246, 221, 190, 168, 177, 238, 196, 241, 184, 235, 240, 204,
-245, 186, 247, 234, 194, 233, 247, 236, 237, 233, 216, 187, 247, 251, 179, 221,
-185, 234, 163, 161, 163, 191, 163, 221, 163, 251, 161, 233
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic() throws CharacterCodingException {
- super.test_CodecDynamic();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Decode() throws CharacterCodingException {
- super.test_Decode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Encode() throws CharacterCodingException {
- super.test_Encode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_nameMatch() {
- super.test_nameMatch();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK.java
deleted file mode 100644
index dc446df..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK.java
+++ /dev/null
@@ -1,525 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-/** @hide
- * SEE correspondig_Android test class:
- */
-
-public class Charset_MultiByte_GBK extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "GBK";
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-164, 167, 168, 176, 177, 183, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243,
-247, 249, 250, 252, 257, 275, 299, 324, 363, 462, 472, 593, 609, 711, 729, 913,
-923, 933, 945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230,
-8240, 8251, 8451, 8470, 8481, 8544, 8554, 8564, 8592, 8712, 8725, 8735, 8745, 8756, 8776, 8786,
-8800, 8814, 8857, 8869, 8895, 8978, 9312, 9332, 9342, 9352, 9362, 9472, 9482, 9492, 9502, 9512,
-9522, 9532, 9542, 9552, 9562, 9572, 9582, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733,
-9792, 12288, 12298, 12308, 12318, 12328, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443,
-12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523, 12533, 12549, 12559, 12569, 12579, 12832, 12849, 12963,
-13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20038, 20048, 20058, 20068, 20078,
-20088, 20098, 20108, 20118, 20128, 20138, 20148, 20158, 20168, 20178, 20188, 20198, 20208, 20218, 20228, 20238,
-20248, 20258, 20268, 20278, 20288, 20298, 20308, 20318, 20328, 20338, 20348, 20358, 20368, 20378, 20388, 20398,
-20408, 20418, 20428, 20438, 20448, 20458, 20468, 20478, 20488, 20498, 20508, 20518, 20528, 20538, 20548, 20558,
-20568, 20578, 20588, 20598, 20608, 20618, 20628, 20638, 20648, 20658, 20668, 20678, 20688, 20698, 20708, 20718,
-20728, 20738, 20748, 20758, 20768, 20778, 20788, 20798, 20808, 20818, 20828, 20838, 20848, 20858, 20868, 20878,
-20888, 20898, 20908, 20918, 20928, 20938, 20948, 20958, 20968, 20978, 20988, 20998, 21008, 21018, 21028, 21038,
-21048, 21058, 21068, 21078, 21088, 21098, 21108, 21118, 21128, 21138, 21148, 21158, 21168, 21178, 21188, 21198,
-21208, 21218, 21228, 21238, 21248, 21258, 21268, 21278, 21288, 21298, 21308, 21318, 21328, 21338, 21348, 21358,
-21368, 21378, 21388, 21398, 21408, 21418, 21428, 21438, 21448, 21458, 21468, 21478, 21488, 21498, 21508, 21518,
-21528, 21538, 21548, 21558, 21568, 21578, 21588, 21598, 21608, 21618, 21628, 21638, 21648, 21658, 21668, 21678,
-21688, 21698, 21708, 21718, 21728, 21738, 21748, 21758, 21768, 21778, 21788, 21798, 21808, 21818, 21828, 21838,
-21848, 21858, 21868, 21878, 21888, 21898, 21908, 21918, 21928, 21938, 21948, 21958, 21968, 21978, 21988, 21998,
-22008, 22018, 22028, 22038, 22048, 22058, 22068, 22078, 22088, 22098, 22108, 22118, 22128, 22138, 22148, 22158,
-22168, 22178, 22188, 22198, 22208, 22218, 22228, 22238, 22248, 22258, 22268, 22278, 22288, 22298, 22308, 22318,
-22328, 22338, 22348, 22358, 22368, 22378, 22388, 22398, 22408, 22418, 22428, 22438, 22448, 22458, 22468, 22478,
-22488, 22498, 22508, 22518, 22528, 22538, 22548, 22558, 22568, 22578, 22588, 22598, 22608, 22618, 22628, 22638,
-22648, 22658, 22668, 22678, 22688, 22698, 22708, 22718, 22728, 22738, 22748, 22758, 22768, 22778, 22788, 22798,
-22808, 22818, 22828, 22838, 22848, 22858, 22868, 22878, 22888, 22898, 22908, 22918, 22928, 22938, 22948, 22958,
-22968, 22978, 22988, 22998, 23008, 23018, 23028, 23038, 23048, 23058, 23068, 23078, 23088, 23098, 23108, 23118,
-23128, 23138, 23148, 23158, 23168, 23178, 23188, 23198, 23208, 23218, 23228, 23238, 23248, 23258, 23268, 23278,
-23288, 23298, 23308, 23318, 23328, 23338, 23348, 23358, 23368, 23378, 23388, 23398, 23408, 23418, 23428, 23438,
-23448, 23458, 23468, 23478, 23488, 23498, 23508, 23518, 23528, 23538, 23548, 23558, 23568, 23578, 23588, 23598,
-23608, 23618, 23628, 23638, 23648, 23658, 23668, 23678, 23688, 23698, 23708, 23718, 23728, 23738, 23748, 23758,
-23768, 23778, 23788, 23798, 23808, 23818, 23828, 23838, 23848, 23858, 23868, 23878, 23888, 23898, 23908, 23918,
-23928, 23938, 23948, 23958, 23968, 23978, 23988, 23998, 24008, 24018, 24028, 24038, 24048, 24058, 24068, 24078,
-24088, 24098, 24108, 24118, 24128, 24138, 24148, 24158, 24168, 24178, 24188, 24198, 24208, 24218, 24228, 24238,
-24248, 24258, 24268, 24278, 24288, 24298, 24308, 24318, 24328, 24338, 24348, 24358, 24368, 24378, 24388, 24398,
-24408, 24418, 24428, 24438, 24448, 24458, 24468, 24478, 24488, 24498, 24508, 24518, 24528, 24538, 24548, 24558,
-24568, 24578, 24588, 24598, 24608, 24618, 24628, 24638, 24648, 24658, 24668, 24678, 24688, 24698, 24708, 24718,
-24728, 24738, 24748, 24758, 24768, 24778, 24788, 24798, 24808, 24818, 24828, 24838, 24848, 24858, 24868, 24878,
-24888, 24898, 24908, 24918, 24928, 24938, 24948, 24958, 24968, 24978, 24988, 24998, 25008, 25018, 25028, 25038,
-25048, 25058, 25068, 25078, 25088, 25098, 25108, 25118, 25128, 25138, 25148, 25158, 25168, 25178, 25188, 25198,
-25208, 25218, 25228, 25238, 25248, 25258, 25268, 25278, 25288, 25298, 25308, 25318, 25328, 25338, 25348, 25358,
-25368, 25378, 25388, 25398, 25408, 25418, 25428, 25438, 25448, 25458, 25468, 25478, 25488, 25498, 25508, 25518,
-25528, 25538, 25548, 25558, 25568, 25578, 25588, 25598, 25608, 25618, 25628, 25638, 25648, 25658, 25668, 25678,
-25688, 25698, 25708, 25718, 25728, 25738, 25748, 25758, 25768, 25778, 25788, 25798, 25808, 25818, 25828, 25838,
-25848, 25858, 25868, 25878, 25888, 25898, 25908, 25918, 25928, 25938, 25948, 25958, 25968, 25978, 25988, 25998,
-26008, 26018, 26028, 26038, 26048, 26058, 26068, 26078, 26088, 26098, 26108, 26118, 26128, 26138, 26148, 26158,
-26168, 26178, 26188, 26198, 26208, 26218, 26228, 26238, 26248, 26258, 26268, 26278, 26288, 26298, 26308, 26318,
-26328, 26338, 26348, 26358, 26368, 26378, 26388, 26398, 26408, 26418, 26428, 26438, 26448, 26458, 26468, 26478,
-26488, 26498, 26508, 26518, 26528, 26538, 26548, 26558, 26568, 26578, 26588, 26598, 26608, 26618, 26628, 26638,
-26648, 26658, 26668, 26678, 26688, 26698, 26708, 26718, 26728, 26738, 26748, 26758, 26768, 26778, 26788, 26798,
-26808, 26818, 26828, 26838, 26848, 26858, 26868, 26878, 26888, 26898, 26908, 26918, 26928, 26938, 26948, 26958,
-26968, 26978, 26988, 26998, 27008, 27018, 27028, 27038, 27048, 27058, 27068, 27078, 27088, 27098, 27108, 27118,
-27128, 27138, 27148, 27158, 27168, 27178, 27188, 27198, 27208, 27218, 27228, 27238, 27248, 27258, 27268, 27278,
-27288, 27298, 27308, 27318, 27328, 27338, 27348, 27358, 27368, 27378, 27388, 27398, 27408, 27418, 27428, 27438,
-27448, 27458, 27468, 27478, 27488, 27498, 27508, 27518, 27528, 27538, 27548, 27558, 27568, 27578, 27588, 27598,
-27608, 27618, 27628, 27638, 27648, 27658, 27668, 27678, 27688, 27698, 27708, 27718, 27728, 27738, 27748, 27758,
-27768, 27778, 27788, 27798, 27808, 27818, 27828, 27838, 27848, 27858, 27868, 27878, 27888, 27898, 27908, 27918,
-27928, 27938, 27948, 27958, 27968, 27978, 27988, 27998, 28008, 28018, 28028, 28038, 28048, 28058, 28068, 28078,
-28088, 28098, 28108, 28118, 28128, 28138, 28148, 28158, 28168, 28178, 28188, 28198, 28208, 28218, 28228, 28238,
-28248, 28258, 28268, 28278, 28288, 28298, 28308, 28318, 28328, 28338, 28348, 28358, 28368, 28378, 28388, 28398,
-28408, 28418, 28428, 28438, 28448, 28458, 28468, 28478, 28488, 28498, 28508, 28518, 28528, 28538, 28548, 28558,
-28568, 28578, 28588, 28598, 28608, 28618, 28628, 28638, 28648, 28658, 28668, 28678, 28688, 28698, 28708, 28718,
-28728, 28738, 28748, 28758, 28768, 28778, 28788, 28798, 28808, 28818, 28828, 28838, 28848, 28858, 28868, 28878,
-28888, 28898, 28908, 28918, 28928, 28938, 28948, 28958, 28968, 28978, 28988, 28998, 29008, 29018, 29028, 29038,
-29048, 29058, 29068, 29078, 29088, 29098, 29108, 29118, 29128, 29138, 29148, 29158, 29168, 29178, 29188, 29198,
-29208, 29218, 29228, 29238, 29248, 29258, 29268, 29278, 29288, 29298, 29308, 29318, 29328, 29338, 29348, 29358,
-29368, 29378, 29388, 29398, 29408, 29418, 29428, 29438, 29448, 29458, 29468, 29478, 29488, 29498, 29508, 29518,
-29528, 29538, 29548, 29558, 29568, 29578, 29588, 29598, 29608, 29618, 29628, 29638, 29648, 29658, 29668, 29678,
-29688, 29698, 29708, 29718, 29728, 29738, 29748, 29758, 29768, 29778, 29788, 29798, 29808, 29818, 29828, 29838,
-29848, 29858, 29868, 29878, 29888, 29898, 29908, 29918, 29928, 29938, 29948, 29958, 29968, 29978, 29988, 29998,
-30008, 30018, 30028, 30038, 30048, 30058, 30068, 30078, 30088, 30098, 30108, 30118, 30128, 30138, 30148, 30158,
-30168, 30178, 30188, 30198, 30208, 30218, 30228, 30238, 30248, 30258, 30268, 30278, 30288, 30298, 30308, 30318,
-30328, 30338, 30348, 30358, 30368, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448, 30458, 30468, 30478,
-30488, 30498, 30508, 30518, 30528, 30538, 30548, 30558, 30568, 30578, 30588, 30598, 30608, 30618, 30628, 30638,
-30648, 30658, 30668, 30678, 30688, 30698, 30708, 30718, 30728, 30738, 30748, 30758, 30768, 30778, 30788, 30798,
-30808, 30818, 30828, 30838, 30848, 30858, 30868, 30878, 30888, 30898, 30908, 30918, 30928, 30938, 30948, 30958,
-30968, 30978, 30988, 30998, 31008, 31018, 31028, 31038, 31048, 31058, 31068, 31078, 31088, 31098, 31108, 31118,
-31128, 31138, 31148, 31158, 31168, 31178, 31188, 31198, 31208, 31218, 31228, 31238, 31248, 31258, 31268, 31278,
-31288, 31298, 31308, 31318, 31328, 31338, 31348, 31358, 31368, 31378, 31388, 31398, 31408, 31418, 31428, 31438,
-31448, 31458, 31468, 31478, 31488, 31498, 31508, 31518, 31528, 31538, 31548, 31558, 31568, 31578, 31588, 31598,
-31608, 31618, 31628, 31638, 31648, 31658, 31668, 31678, 31688, 31698, 31708, 31718, 31728, 31738, 31748, 31758,
-31768, 31778, 31788, 31798, 31808, 31818, 31828, 31838, 31848, 31858, 31868, 31878, 31888, 31898, 31908, 31918,
-31928, 31938, 31948, 31958, 31968, 31978, 31988, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068, 32078,
-32088, 32098, 32108, 32118, 32128, 32138, 32148, 32158, 32168, 32178, 32188, 32198, 32208, 32218, 32228, 32238,
-32248, 32258, 32268, 32278, 32288, 32298, 32308, 32318, 32328, 32338, 32348, 32358, 32368, 32378, 32388, 32398,
-32408, 32418, 32428, 32438, 32448, 32458, 32468, 32478, 32488, 32498, 32508, 32518, 32528, 32538, 32548, 32558,
-32568, 32578, 32588, 32598, 32608, 32618, 32628, 32638, 32648, 32658, 32668, 32678, 32688, 32698, 32708, 32718,
-32728, 32738, 32748, 32758, 32768, 32778, 32788, 32798, 32808, 32818, 32828, 32838, 32848, 32858, 32868, 32878,
-32888, 32898, 32908, 32918, 32928, 32938, 32948, 32958, 32968, 32978, 32988, 32998, 33008, 33018, 33028, 33038,
-33048, 33058, 33068, 33078, 33088, 33098, 33108, 33118, 33128, 33138, 33148, 33158, 33168, 33178, 33188, 33198,
-33208, 33218, 33228, 33238, 33248, 33258, 33268, 33278, 33288, 33298, 33308, 33318, 33328, 33338, 33348, 33358,
-33368, 33378, 33388, 33398, 33408, 33418, 33428, 33438, 33448, 33458, 33468, 33478, 33488, 33498, 33508, 33518,
-33528, 33538, 33548, 33558, 33568, 33578, 33588, 33598, 33608, 33618, 33628, 33638, 33648, 33658, 33668, 33678,
-33688, 33698, 33708, 33718, 33728, 33738, 33748, 33758, 33768, 33778, 33788, 33798, 33808, 33818, 33828, 33838,
-33848, 33858, 33868, 33878, 33888, 33898, 33908, 33918, 33928, 33938, 33948, 33958, 33968, 33978, 33988, 33998,
-34008, 34018, 34028, 34038, 34048, 34058, 34068, 34078, 34088, 34098, 34108, 34118, 34128, 34138, 34148, 34158,
-34168, 34178, 34188, 34198, 34208, 34218, 34228, 34238, 34248, 34258, 34268, 34278, 34288, 34298, 34308, 34318,
-34328, 34338, 34348, 34358, 34368, 34378, 34388, 34398, 34408, 34418, 34428, 34438, 34448, 34458, 34468, 34478,
-34488, 34498, 34508, 34518, 34528, 34538, 34548, 34558, 34568, 34578, 34588, 34598, 34608, 34618, 34628, 34638,
-34648, 34658, 34668, 34678, 34688, 34698, 34708, 34718, 34728, 34738, 34748, 34758, 34768, 34778, 34788, 34798,
-34808, 34818, 34828, 34838, 34848, 34858, 34868, 34878, 34888, 34898, 34908, 34918, 34928, 34938, 34948, 34958,
-34968, 34978, 34988, 34998, 35008, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35108, 35118,
-35128, 35138, 35148, 35158, 35168, 35178, 35188, 35198, 35208, 35218, 35228, 35238, 35248, 35258, 35268, 35278,
-35288, 35298, 35308, 35318, 35328, 35338, 35348, 35358, 35368, 35378, 35388, 35398, 35408, 35418, 35428, 35438,
-35448, 35458, 35468, 35478, 35488, 35498, 35508, 35518, 35528, 35538, 35548, 35558, 35568, 35578, 35588, 35598,
-35608, 35618, 35628, 35638, 35648, 35658, 35668, 35678, 35688, 35698, 35708, 35718, 35728, 35738, 35748, 35758,
-35768, 35778, 35788, 35798, 35808, 35818, 35828, 35838, 35848, 35858, 35868, 35878, 35888, 35898, 35908, 35918,
-35928, 35938, 35948, 35958, 35968, 35978, 35988, 35998, 36008, 36018, 36028, 36038, 36048, 36058, 36068, 36078,
-36088, 36098, 36108, 36118, 36128, 36138, 36148, 36158, 36168, 36178, 36188, 36198, 36208, 36218, 36228, 36238,
-36248, 36258, 36268, 36278, 36288, 36298, 36308, 36318, 36328, 36338, 36348, 36358, 36368, 36378, 36388, 36398,
-36408, 36418, 36428, 36438, 36448, 36458, 36468, 36478, 36488, 36498, 36508, 36518, 36528, 36538, 36548, 36558,
-36568, 36578, 36588, 36598, 36608, 36618, 36628, 36638, 36648, 36658, 36668, 36678, 36688, 36698, 36708, 36718,
-36728, 36738, 36748, 36758, 36768, 36778, 36788, 36798, 36808, 36818, 36828, 36838, 36848, 36858, 36868, 36878,
-36888, 36898, 36908, 36918, 36928, 36938, 36948, 36958, 36968, 36978, 36988, 36998, 37008, 37018, 37028, 37038,
-37048, 37058, 37068, 37078, 37088, 37098, 37108, 37118, 37128, 37138, 37148, 37158, 37168, 37178, 37188, 37198,
-37208, 37218, 37228, 37238, 37248, 37258, 37268, 37278, 37288, 37298, 37308, 37318, 37328, 37338, 37348, 37358,
-37368, 37378, 37388, 37398, 37408, 37418, 37428, 37438, 37448, 37458, 37468, 37478, 37488, 37498, 37508, 37518,
-37528, 37538, 37548, 37558, 37568, 37578, 37588, 37598, 37608, 37618, 37628, 37638, 37648, 37658, 37668, 37678,
-37688, 37698, 37708, 37718, 37728, 37738, 37748, 37758, 37768, 37778, 37788, 37798, 37808, 37818, 37828, 37838,
-37848, 37858, 37868, 37878, 37888, 37898, 37908, 37918, 37928, 37938, 37948, 37958, 37968, 37978, 37988, 37998,
-38008, 38018, 38028, 38038, 38048, 38058, 38068, 38078, 38088, 38098, 38108, 38118, 38128, 38138, 38148, 38158,
-38168, 38178, 38188, 38198, 38208, 38218, 38228, 38238, 38248, 38258, 38268, 38278, 38288, 38298, 38308, 38318,
-38328, 38338, 38348, 38358, 38368, 38378, 38388, 38398, 38408, 38418, 38428, 38438, 38448, 38458, 38468, 38478,
-38488, 38498, 38508, 38518, 38528, 38538, 38548, 38558, 38568, 38578, 38588, 38598, 38608, 38618, 38628, 38638,
-38648, 38658, 38668, 38678, 38688, 38698, 38708, 38718, 38728, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
-38808, 38818, 38828, 38838, 38848, 38858, 38868, 38878, 38888, 38898, 38908, 38918, 38928, 38938, 38948, 38958,
-38968, 38978, 38988, 38998, 39008, 39018, 39028, 39038, 39048, 39058, 39068, 39078, 39088, 39098, 39108, 39118,
-39128, 39138, 39148, 39158, 39168, 39178, 39188, 39198, 39208, 39218, 39228, 39238, 39248, 39258, 39268, 39278,
-39288, 39298, 39308, 39318, 39328, 39338, 39348, 39358, 39368, 39378, 39388, 39398, 39408, 39418, 39428, 39438,
-39448, 39458, 39468, 39478, 39488, 39498, 39508, 39518, 39528, 39538, 39548, 39558, 39568, 39578, 39588, 39598,
-39608, 39618, 39628, 39638, 39648, 39658, 39668, 39678, 39688, 39698, 39708, 39718, 39728, 39738, 39748, 39758,
-39768, 39778, 39788, 39798, 39808, 39818, 39828, 39838, 39848, 39858, 39868, 39878, 39888, 39898, 39908, 39918,
-39928, 39938, 39948, 39958, 39968, 39978, 39988, 39998, 40008, 40018, 40028, 40038, 40048, 40058, 40068, 40078,
-40088, 40098, 40108, 40118, 40128, 40138, 40148, 40158, 40168, 40178, 40188, 40198, 40208, 40218, 40228, 40238,
-40248, 40258, 40268, 40278, 40288, 40298, 40308, 40318, 40328, 40338, 40348, 40358, 40368, 40378, 40388, 40398,
-40408, 40418, 40428, 40438, 40448, 40458, 40468, 40478, 40488, 40498, 40508, 40518, 40528, 40538, 40548, 40558,
-40568, 40578, 40588, 40598, 40608, 40618, 40628, 40638, 40648, 40658, 40668, 40678, 40688, 40698, 40708, 40718,
-40728, 40738, 40748, 40758, 40768, 40778, 40788, 40798, 40808, 40818, 40828, 40838, 40848, 40858, 40868, 57344,
-57354, 57364, 57374, 57384, 57394, 57404, 57414, 57424, 57434, 57444, 57454, 57464, 57474, 57484, 57494, 57504,
-57514, 57524, 57534, 57544, 57554, 57564, 57574, 57584, 57594, 57604, 57614, 57624, 57634, 57644, 57654, 57664,
-57674, 57684, 57694, 57704, 57714, 57724, 57734, 57744, 57754, 57764, 57774, 57784, 57794, 57804, 57814, 57824,
-57834, 57844, 57854, 57864, 57874, 57884, 57894, 57904, 57914, 57924, 57934, 57944, 57954, 57964, 57974, 57984,
-57994, 58004, 58014, 58024, 58034, 58044, 58054, 58064, 58074, 58084, 58094, 58104, 58114, 58124, 58134, 58144,
-58154, 58164, 58174, 58184, 58194, 58204, 58214, 58224, 58234, 58244, 58254, 58264, 58274, 58284, 58294, 58304,
-58314, 58324, 58334, 58344, 58354, 58364, 58374, 58384, 58394, 58404, 58414, 58424, 58434, 58444, 58454, 58464,
-58474, 58484, 58494, 58504, 58514, 58524, 58534, 58544, 58554, 58564, 58574, 58584, 58594, 58604, 58614, 58624,
-58634, 58644, 58654, 58664, 58674, 58684, 58694, 58704, 58714, 58724, 58734, 58744, 58754, 58764, 58774, 58784,
-58794, 58804, 58814, 58824, 58834, 58844, 58854, 58864, 58874, 58884, 58894, 58904, 58914, 58924, 58934, 58944,
-58954, 58964, 58974, 58984, 58994, 59004, 59014, 59024, 59034, 59044, 59054, 59064, 59074, 59084, 59094, 59104,
-59114, 59124, 59134, 59144, 59154, 59164, 59174, 59184, 59194, 59204, 59214, 59224, 59234, 59244, 59254, 59264,
-59274, 59284, 59294, 59304, 59314, 59324, 59334, 59344, 59354, 59364, 59374, 59384, 59394, 59404, 59414, 59424,
-59434, 59444, 59454, 59464, 59474, 59484, 63788, 63865, 63893, 63975, 63985, 64012, 64024, 64035, 65072, 65082,
-65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65504, 65536
- });
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 164, 161, 193, 168, 164,
-168, 162, 168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174,
-161, 194, 168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 169, 168, 189,
-168, 177, 168, 163, 168, 182, 168, 187, 168, 192, 161, 166, 168, 66, 166, 161,
-166, 171, 166, 180, 166, 193, 166, 203, 166, 212, 167, 167, 167, 161, 167, 172,
-167, 182, 167, 192, 167, 218, 167, 228, 167, 238, 169, 92, 161, 176, 161, 173,
-161, 235, 161, 249, 161, 230, 161, 237, 169, 89, 162, 241, 162, 251, 162, 165,
-161, 251, 161, 202, 168, 77, 168, 78, 161, 201, 161, 224, 161, 214, 168, 80,
-161, 217, 161, 218, 161, 209, 161, 205, 168, 83, 161, 208, 162, 217, 162, 197,
-162, 207, 162, 177, 162, 187, 169, 164, 169, 174, 169, 184, 169, 194, 169, 204,
-169, 214, 169, 224, 169, 234, 168, 84, 168, 94, 168, 104, 168, 114, 168, 120,
-168, 131, 168, 138, 161, 246, 161, 248, 168, 139, 161, 244, 168, 141, 161, 239,
-161, 226, 161, 161, 161, 182, 161, 178, 168, 149, 169, 71, 164, 161, 164, 171,
-164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 169, 97,
-165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
-165, 245, 168, 197, 168, 207, 168, 217, 168, 227, 162, 229, 169, 90, 169, 73,
-169, 74, 169, 76, 169, 80, 169, 81, 210, 187, 201, 207, 199, 210, 216, 169,
-216, 173, 180, 174, 129, 83, 129, 88, 192, 214, 129, 93, 129, 97, 129, 105,
-129, 112, 129, 121, 182, 254, 129, 129, 217, 239, 129, 136, 129, 140, 129, 147,
-129, 148, 129, 152, 129, 155, 129, 158, 209, 246, 129, 168, 129, 174, 188, 191,
-211, 197, 216, 243, 129, 192, 193, 230, 129, 203, 129, 211, 129, 215, 216, 250,
-129, 220, 129, 226, 217, 174, 129, 237, 129, 242, 129, 249, 130, 64, 206, 234,
-130, 74, 130, 83, 130, 89, 130, 95, 130, 98, 217, 179, 130, 107, 217, 194,
-130, 124, 181, 185, 217, 195, 190, 235, 130, 146, 213, 174, 130, 162, 217, 203,
-130, 176, 130, 184, 217, 204, 197, 188, 191, 254, 130, 214, 130, 223, 130, 233,
-180, 162, 176, 193, 130, 254, 131, 73, 131, 82, 193, 197, 131, 100, 217, 215,
-131, 113, 131, 122, 131, 130, 131, 139, 131, 149, 131, 158, 131, 168, 131, 178,
-207, 200, 131, 186, 182, 181, 131, 199, 192, 188, 131, 205, 131, 209, 131, 214,
-131, 220, 218, 163, 182, 172, 210, 177, 190, 187, 131, 245, 131, 251, 132, 68,
-132, 75, 132, 81, 219, 202, 183, 214, 132, 91, 184, 213, 197, 208, 185, 206,
-200, 175, 188, 193, 216, 221, 198, 202, 132, 133, 188, 244, 132, 146, 132, 155,
-197, 252, 132, 170, 132, 178, 132, 181, 132, 185, 132, 192, 132, 199, 132, 206,
-191, 177, 132, 221, 132, 230, 132, 239, 212, 200, 132, 251, 133, 67, 133, 71,
-133, 77, 133, 85, 133, 92, 133, 97, 133, 101, 178, 169, 194, 177, 216, 180,
-208, 182, 179, 167, 209, 225, 133, 133, 133, 139, 133, 143, 133, 152, 133, 160,
-211, 214, 133, 170, 133, 174, 193, 237, 204, 168, 133, 181, 184, 247, 186, 243,
-133, 190, 133, 194, 204, 253, 133, 200, 209, 189, 184, 230, 223, 190, 133, 218,
-214, 220, 223, 218, 186, 244, 197, 216, 184, 192, 223, 203, 223, 229, 134, 66,
-207, 204, 223, 211, 223, 223, 134, 80, 134, 83, 196, 196, 134, 93, 134, 100,
-134, 106, 134, 112, 134, 120, 134, 126, 224, 167, 134, 138, 215, 196, 134, 149,
-134, 156, 134, 164, 216, 196, 224, 164, 191, 166, 186, 176, 224, 184, 134, 192,
-134, 200, 134, 209, 134, 214, 134, 220, 134, 227, 134, 232, 224, 205, 134, 240,
-134, 245, 134, 251, 224, 209, 135, 75, 135, 81, 135, 88, 215, 236, 135, 100,
-135, 109, 135, 116, 224, 224, 135, 130, 135, 135, 135, 143, 135, 151, 186, 191,
-135, 166, 135, 176, 135, 185, 135, 194, 135, 202, 196, 210, 224, 236, 187, 216,
-135, 230, 135, 236, 135, 242, 212, 178, 135, 253, 136, 72, 136, 79, 219, 220,
-136, 90, 219, 224, 219, 208, 136, 106, 215, 185, 198, 186, 136, 118, 136, 124,
-136, 130, 192, 221, 136, 145, 191, 209, 136, 154, 136, 161, 136, 169, 179, 199,
-219, 245, 136, 187, 136, 196, 136, 203, 220, 165, 136, 215, 136, 222, 220, 166,
-136, 236, 136, 244, 136, 253, 137, 71, 137, 79, 137, 86, 137, 95, 137, 102,
-137, 112, 137, 119, 137, 126, 137, 135, 137, 141, 137, 149, 137, 159, 137, 168,
-137, 176, 137, 185, 137, 194, 137, 203, 201, 249, 137, 216, 180, 166, 137, 232,
-137, 238, 137, 244, 137, 248, 137, 253, 138, 67, 138, 71, 177, 188, 138, 81,
-138, 88, 138, 98, 138, 103, 215, 177, 138, 113, 138, 118, 230, 165, 196, 221,
-138, 138, 138, 145, 138, 152, 138, 157, 138, 162, 138, 169, 138, 178, 138, 186,
-230, 174, 138, 195, 196, 200, 138, 208, 138, 217, 138, 223, 138, 231, 138, 238,
-138, 247, 230, 190, 139, 72, 201, 244, 139, 86, 139, 96, 139, 105, 139, 113,
-139, 123, 230, 199, 139, 139, 139, 146, 139, 154, 139, 160, 139, 166, 139, 173,
-139, 182, 139, 192, 139, 201, 230, 212, 139, 219, 139, 229, 217, 248, 139, 246,
-140, 64, 140, 72, 215, 206, 209, 167, 202, 235, 200, 230, 229, 179, 140, 97,
-185, 217, 191, 205, 140, 107, 188, 210, 140, 117, 140, 122, 140, 129, 196, 175,
-213, 175, 140, 150, 181, 188, 189, 171, 140, 168, 201, 208, 211, 200, 140, 185,
-202, 172, 178, 227, 140, 197, 140, 202, 205, 192, 140, 215, 140, 222, 140, 230,
-225, 172, 140, 242, 225, 177, 140, 252, 141, 67, 141, 72, 225, 187, 141, 87,
-141, 96, 141, 104, 141, 109, 141, 117, 141, 126, 141, 133, 180, 222, 225, 198,
-141, 155, 141, 162, 141, 171, 141, 179, 141, 185, 141, 194, 141, 202, 141, 209,
-141, 217, 225, 214, 141, 236, 141, 246, 141, 254, 142, 73, 142, 83, 142, 92,
-142, 101, 142, 110, 142, 119, 215, 243, 142, 128, 142, 133, 142, 138, 142, 144,
-193, 177, 142, 152, 142, 160, 142, 167, 142, 172, 142, 179, 225, 163, 225, 165,
-142, 202, 184, 201, 211, 215, 199, 236, 194, 174, 184, 253, 142, 232, 142, 238,
-211, 185, 142, 251, 143, 68, 193, 206, 143, 83, 226, 222, 219, 200, 222, 195,
-222, 196, 143, 115, 143, 120, 207, 210, 143, 132, 199, 191, 143, 147, 143, 157,
-229, 233, 208, 206, 177, 242, 143, 178, 205, 249, 187, 178, 143, 191, 143, 196,
-225, 229, 143, 211, 225, 232, 210, 228, 236, 254, 143, 232, 226, 232, 226, 229,
-226, 238, 203, 203, 144, 67, 178, 192, 181, 161, 185, 214, 144, 86, 144, 93,
-144, 99, 186, 227, 144, 112, 144, 118, 199, 161, 226, 253, 199, 196, 144, 136,
-144, 143, 144, 148, 208, 252, 144, 158, 144, 165, 190, 170, 144, 180, 144, 185,
-178, 210, 144, 193, 144, 198, 237, 169, 144, 210, 211, 222, 183, 223, 144, 231,
-144, 241, 144, 250, 187, 197, 145, 73, 145, 82, 145, 89, 145, 98, 145, 106,
-145, 116, 145, 124, 145, 134, 145, 143, 145, 149, 145, 158, 145, 166, 145, 173,
-145, 180, 145, 190, 145, 199, 145, 208, 145, 217, 206, 236, 145, 226, 145, 230,
-145, 235, 145, 242, 145, 249, 145, 253, 146, 65, 146, 70, 146, 78, 176, 231,
-146, 86, 146, 91, 146, 98, 182, 182, 191, 217, 146, 112, 146, 119, 146, 124,
-196, 233, 190, 220, 176, 221, 192, 185, 146, 140, 146, 145, 146, 149, 191, 230,
-146, 163, 222, 216, 146, 169, 146, 177, 146, 184, 146, 189, 146, 193, 192, 204,
-146, 206, 146, 212, 146, 218, 146, 226, 198, 254, 146, 235, 146, 242, 222, 231,
-181, 167, 147, 65, 147, 72, 210, 190, 222, 235, 190, 190, 212, 174, 147, 104,
-147, 109, 147, 115, 203, 209, 222, 249, 147, 135, 208, 175, 201, 227, 147, 154,
-213, 170, 147, 170, 147, 178, 147, 187, 147, 194, 147, 200, 147, 208, 215, 178,
-147, 223, 147, 228, 186, 179, 147, 240, 223, 167, 147, 254, 223, 169, 148, 79,
-148, 89, 148, 98, 148, 107, 148, 116, 148, 125, 148, 135, 234, 183, 183, 197,
-208, 167, 148, 158, 148, 164, 182, 216, 202, 253, 148, 183, 148, 193, 148, 200,
-148, 206, 148, 211, 148, 216, 148, 223, 148, 230, 148, 235, 148, 240, 148, 248,
-214, 188, 149, 64, 149, 71, 192, 165, 149, 83, 149, 89, 149, 96, 149, 102,
-149, 107, 149, 114, 201, 206, 234, 205, 149, 133, 149, 139, 199, 231, 193, 192,
-149, 158, 149, 166, 149, 174, 149, 183, 149, 190, 149, 198, 149, 207, 149, 217,
-149, 227, 149, 233, 149, 241, 149, 247, 215, 238, 235, 195, 203, 183, 150, 79,
-196, 190, 150, 90, 150, 97, 184, 203, 178, 196, 150, 113, 150, 118, 150, 123,
-150, 128, 150, 134, 150, 140, 150, 148, 150, 152, 199, 185, 150, 161, 150, 167,
-150, 174, 198, 226, 185, 241, 150, 189, 232, 205, 150, 202, 150, 209, 232, 221,
-150, 216, 150, 224, 150, 232, 150, 240, 232, 238, 232, 240, 189, 219, 151, 66,
-189, 176, 151, 75, 151, 82, 176, 240, 151, 97, 151, 105, 151, 114, 151, 120,
-151, 126, 232, 249, 151, 143, 151, 150, 204, 196, 151, 166, 151, 173, 151, 179,
-151, 187, 189, 183, 151, 202, 151, 209, 210, 172, 151, 225, 151, 232, 151, 242,
-151, 250, 152, 65, 152, 72, 152, 80, 233, 175, 152, 89, 192, 198, 152, 103,
-213, 165, 152, 118, 152, 125, 152, 135, 187, 177, 152, 150, 152, 157, 152, 166,
-152, 175, 152, 183, 152, 192, 152, 202, 152, 209, 186, 225, 152, 224, 233, 208,
-152, 239, 152, 248, 153, 64, 153, 72, 153, 82, 153, 90, 207, 173, 233, 213,
-153, 113, 153, 122, 195, 202, 153, 140, 153, 150, 153, 160, 153, 170, 153, 180,
-153, 190, 153, 200, 153, 210, 153, 220, 153, 230, 153, 240, 236, 163, 153, 254,
-154, 71, 154, 78, 184, 232, 154, 93, 154, 102, 205, 225, 154, 115, 154, 122,
-154, 126, 233, 230, 154, 138, 154, 147, 154, 156, 154, 162, 154, 169, 154, 176,
-154, 179, 154, 186, 154, 194, 154, 201, 154, 209, 154, 216, 198, 248, 154, 224,
-176, 177, 235, 181, 154, 238, 217, 224, 207, 171, 155, 65, 204, 192, 155, 74,
-155, 80, 210, 202, 227, 231, 155, 95, 155, 102, 187, 166, 155, 108, 213, 180,
-155, 119, 155, 125, 155, 130, 155, 134, 204, 169, 227, 248, 228, 167, 228, 169,
-155, 159, 155, 165, 155, 171, 155, 176, 155, 181, 215, 199, 228, 177, 228, 183,
-155, 199, 155, 205, 228, 188, 155, 219, 155, 225, 155, 231, 181, 211, 228, 204,
-186, 212, 155, 250, 204, 202, 196, 215, 228, 196, 156, 83, 156, 88, 156, 94,
-156, 103, 156, 107, 156, 113, 156, 117, 156, 123, 195, 236, 228, 216, 228, 207,
-207, 230, 156, 160, 156, 169, 156, 178, 156, 186, 156, 192, 156, 200, 156, 208,
-156, 214, 228, 209, 156, 225, 156, 232, 156, 239, 185, 246, 194, 203, 156, 253,
-157, 71, 198, 175, 157, 87, 157, 93, 196, 174, 228, 244, 157, 114, 209, 250,
-157, 131, 157, 139, 199, 177, 193, 202, 157, 162, 228, 253, 179, 206, 197, 236,
-157, 191, 157, 199, 157, 208, 229, 164, 188, 164, 157, 232, 157, 240, 229, 168,
-158, 66, 158, 74, 158, 84, 158, 94, 158, 104, 229, 171, 158, 120, 158, 131,
-158, 140, 158, 149, 185, 224, 158, 167, 158, 176, 158, 186, 158, 191, 212, 214,
-158, 203, 179, 180, 236, 191, 158, 223, 158, 228, 158, 233, 158, 236, 158, 244,
-186, 230, 159, 69, 189, 253, 159, 80, 159, 87, 186, 184, 159, 103, 159, 108,
-159, 117, 159, 124, 159, 134, 159, 143, 159, 150, 159, 160, 195, 186, 214, 243,
-236, 212, 159, 188, 159, 196, 159, 204, 236, 218, 159, 219, 159, 227, 159, 235,
-159, 244, 159, 253, 160, 70, 160, 78, 160, 86, 160, 95, 160, 105, 160, 114,
-160, 124, 160, 134, 197, 192, 184, 184, 160, 151, 160, 159, 160, 166, 160, 172,
-160, 177, 201, 252, 160, 190, 160, 195, 160, 201, 160, 210, 160, 219, 160, 227,
-225, 239, 191, 241, 160, 245, 160, 251, 186, 221, 170, 73, 225, 249, 170, 79,
-170, 87, 170, 95, 178, 194, 170, 104, 170, 109, 170, 114, 170, 122, 170, 132,
-170, 139, 170, 148, 226, 179, 171, 68, 171, 77, 171, 84, 171, 91, 171, 99,
-171, 107, 193, 225, 171, 117, 171, 125, 183, 169, 171, 138, 171, 146, 171, 152,
-172, 64, 172, 74, 172, 79, 172, 87, 172, 95, 231, 247, 199, 217, 172, 112,
-172, 121, 172, 132, 232, 164, 172, 144, 185, 229, 172, 160, 173, 69, 232, 172,
-173, 85, 173, 93, 173, 100, 173, 110, 173, 119, 173, 130, 173, 139, 240, 172,
-173, 152, 173, 160, 174, 70, 174, 78, 174, 86, 201, 245, 174, 99, 174, 103,
-181, 233, 174, 111, 189, 231, 174, 124, 174, 131, 183, 172, 179, 235, 174, 154,
-175, 64, 240, 218, 175, 75, 175, 78, 240, 230, 175, 86, 240, 228, 175, 94,
-182, 187, 193, 161, 175, 109, 175, 116, 240, 246, 240, 250, 175, 137, 175, 142,
-175, 146, 175, 151, 241, 162, 176, 65, 176, 73, 176, 81, 176, 88, 176, 97,
-185, 239, 212, 237, 176, 116, 205, 238, 176, 132, 176, 141, 241, 229, 176, 157,
-211, 175, 186, 208, 177, 73, 177, 81, 177, 89, 177, 94, 237, 237, 177, 105,
-177, 115, 237, 243, 177, 128, 191, 244, 215, 197, 177, 146, 177, 154, 178, 65,
-237, 254, 178, 77, 178, 86, 178, 90, 178, 97, 178, 105, 178, 112, 178, 117,
-178, 124, 178, 132, 178, 142, 178, 151, 178, 158, 179, 66, 179, 71, 183, 175,
-179, 83, 197, 248, 237, 191, 237, 206, 197, 233, 237, 194, 179, 113, 237, 202,
-179, 124, 179, 134, 211, 178, 179, 149, 179, 157, 180, 68, 180, 73, 180, 78,
-180, 83, 237, 218, 180, 97, 180, 104, 197, 205, 180, 117, 180, 128, 180, 136,
-180, 143, 180, 151, 180, 160, 181, 72, 181, 81, 181, 90, 237, 231, 201, 231,
-198, 237, 181, 120, 236, 239, 181, 129, 181, 135, 236, 247, 194, 187, 181, 157,
-182, 69, 182, 78, 182, 87, 182, 96, 208, 227, 182, 106, 182, 112, 182, 120,
-182, 125, 182, 131, 182, 139, 239, 249, 182, 151, 214, 201, 183, 68, 183, 78,
-183, 86, 183, 91, 183, 100, 183, 109, 183, 118, 183, 129, 209, 168, 183, 142,
-241, 186, 214, 207, 180, 220, 241, 188, 184, 72, 184, 81, 184, 90, 184, 99,
-184, 108, 184, 114, 184, 121, 184, 130, 184, 136, 243, 201, 177, 202, 243, 215,
-177, 191, 185, 66, 193, 253, 185, 80, 191, 240, 243, 217, 185, 94, 243, 223,
-185, 109, 185, 115, 185, 124, 185, 131, 185, 138, 243, 236, 243, 240, 185, 155,
-186, 65, 186, 73, 186, 80, 243, 247, 186, 94, 186, 102, 186, 110, 186, 117,
-186, 125, 186, 135, 186, 142, 186, 152, 244, 166, 187, 71, 187, 80, 187, 90,
-187, 100, 187, 110, 244, 204, 187, 125, 187, 135, 187, 140, 212, 193, 193, 184,
-187, 158, 188, 66, 244, 216, 204, 199, 191, 183, 188, 92, 188, 101, 188, 109,
-188, 119, 188, 129, 188, 139, 188, 147, 188, 154, 189, 67, 189, 77, 189, 87,
-189, 97, 189, 107, 189, 117, 189, 126, 189, 136, 189, 146, 189, 156, 190, 69,
-190, 78, 190, 87, 190, 97, 190, 107, 190, 117, 190, 128, 190, 138, 190, 148,
-190, 158, 191, 71, 191, 81, 191, 91, 191, 101, 191, 111, 191, 121, 191, 131,
-191, 139, 191, 149, 191, 159, 192, 72, 192, 82, 192, 92, 192, 101, 192, 111,
-192, 121, 186, 236, 206, 179, 194, 218, 231, 164, 176, 237, 231, 171, 189, 202,
-231, 176, 231, 181, 215, 219, 192, 194, 192, 137, 184, 191, 231, 205, 201, 201,
-184, 215, 243, 191, 192, 155, 193, 64, 193, 70, 215, 239, 238, 188, 238, 192,
-193, 98, 193, 105, 193, 113, 193, 118, 244, 202, 193, 133, 193, 139, 244, 225,
-199, 204, 193, 159, 194, 69, 194, 75, 210, 171, 194, 87, 241, 232, 194, 95,
-241, 241, 194, 106, 194, 110, 241, 246, 194, 121, 190, 219, 194, 138, 194, 146,
-194, 155, 195, 66, 188, 161, 208, 164, 179, 166, 183, 190, 235, 200, 201, 246,
-195, 95, 195, 102, 202, 164, 195, 111, 210, 200, 176, 183, 195, 122, 235, 219,
-235, 228, 195, 138, 235, 227, 235, 225, 196, 64, 192, 176, 199, 187, 196, 82,
-196, 89, 196, 94, 235, 239, 196, 104, 196, 111, 196, 119, 196, 125, 196, 133,
-196, 142, 177, 219, 235, 251, 197, 66, 197, 76, 215, 212, 214, 194, 244, 167,
-197, 100, 202, 230, 203, 180, 197, 118, 189, 162, 197, 123, 244, 185, 197, 138,
-203, 210, 197, 154, 198, 66, 198, 70, 198, 75, 220, 183, 198, 85, 198, 90,
-220, 184, 198, 95, 198, 100, 198, 106, 198, 108, 198, 111, 220, 214, 198, 120,
-198, 126, 195, 175, 220, 221, 198, 140, 198, 146, 198, 154, 220, 238, 199, 64,
-199, 70, 187, 196, 220, 234, 220, 253, 199, 84, 199, 92, 199, 99, 201, 175,
-221, 183, 199, 118, 199, 124, 221, 178, 221, 210, 190, 213, 221, 202, 199, 151,
-199, 157, 183, 198, 200, 73, 221, 201, 200, 83, 200, 91, 211, 169, 200, 104,
-221, 199, 200, 120, 200, 130, 200, 139, 200, 144, 200, 151, 200, 156, 201, 65,
-221, 220, 201, 78, 203, 226, 201, 94, 201, 103, 221, 240, 208, 238, 201, 121,
-201, 128, 201, 135, 197, 238, 201, 150, 201, 158, 202, 71, 202, 78, 202, 86,
-202, 94, 202, 102, 176, 170, 202, 114, 202, 121, 202, 130, 222, 168, 202, 147,
-202, 155, 203, 64, 203, 71, 203, 80, 203, 88, 208, 189, 203, 102, 203, 110,
-203, 119, 203, 126, 222, 188, 203, 143, 203, 152, 204, 65, 204, 73, 204, 82,
-204, 90, 204, 100, 204, 108, 204, 118, 204, 126, 204, 137, 242, 175, 211, 221,
-204, 158, 205, 67, 242, 180, 205, 77, 205, 83, 205, 91, 212, 233, 205, 102,
-205, 106, 205, 114, 205, 118, 205, 123, 205, 129, 205, 137, 242, 211, 182, 234,
-242, 218, 209, 209, 195, 219, 206, 70, 206, 78, 206, 85, 206, 92, 208, 171,
-206, 105, 206, 113, 206, 120, 181, 251, 206, 133, 206, 139, 206, 146, 206, 155,
-242, 253, 207, 72, 207, 79, 243, 161, 207, 94, 207, 101, 207, 109, 243, 181,
-207, 126, 207, 135, 207, 143, 243, 182, 207, 159, 208, 70, 208, 79, 208, 87,
-208, 94, 208, 102, 208, 109, 208, 114, 203, 165, 208, 126, 176, 192, 208, 137,
-208, 145, 241, 200, 209, 64, 209, 72, 209, 80, 209, 85, 210, 225, 209, 99,
-241, 212, 209, 111, 241, 211, 209, 124, 186, 214, 241, 210, 209, 147, 209, 154,
-210, 64, 210, 73, 210, 82, 210, 92, 210, 100, 210, 109, 210, 119, 210, 129,
-210, 135, 210, 145, 210, 155, 211, 68, 211, 78, 211, 88, 185, 230, 234, 236,
-211, 101, 211, 108, 211, 114, 211, 122, 209, 212, 211, 141, 211, 151, 212, 64,
-212, 74, 212, 84, 212, 94, 212, 103, 212, 112, 212, 122, 212, 133, 212, 143,
-212, 153, 213, 65, 213, 73, 213, 82, 213, 92, 213, 102, 213, 112, 213, 122,
-213, 133, 213, 143, 213, 153, 214, 66, 214, 76, 214, 86, 214, 96, 214, 105,
-214, 115, 214, 125, 214, 135, 214, 145, 214, 155, 215, 68, 215, 78, 215, 88,
-215, 97, 215, 106, 215, 116, 215, 126, 215, 137, 215, 147, 200, 207, 210, 233,
-208, 237, 218, 172, 214, 223, 218, 180, 218, 185, 215, 158, 203, 181, 191, 206,
-204, 184, 218, 203, 195, 213, 199, 171, 192, 190, 216, 66, 216, 75, 216, 81,
-216, 90, 187, 191, 216, 105, 216, 114, 216, 121, 245, 246, 245, 249, 216, 145,
-216, 155, 217, 68, 217, 78, 217, 88, 217, 98, 217, 108, 217, 118, 217, 129,
-217, 139, 217, 149, 217, 159, 218, 72, 218, 79, 204, 176, 204, 249, 188, 214,
-234, 226, 218, 81, 216, 211, 201, 226, 215, 223, 218, 95, 244, 242, 218, 110,
-218, 118, 218, 128, 218, 137, 218, 143, 218, 148, 218, 155, 218, 160, 245, 200,
-191, 231, 219, 79, 219, 82, 219, 90, 219, 96, 219, 105, 219, 110, 245, 218,
-219, 123, 245, 229, 219, 132, 219, 140, 219, 149, 219, 157, 245, 237, 220, 72,
-220, 78, 220, 86, 245, 242, 220, 103, 220, 110, 204, 201, 220, 129, 234, 166,
-220, 148, 220, 158, 221, 71, 221, 81, 221, 91, 221, 101, 221, 111, 221, 121,
-221, 132, 221, 142, 221, 152, 222, 65, 222, 75, 222, 85, 222, 95, 194, 214,
-233, 244, 233, 251, 222, 99, 207, 189, 222, 102, 222, 109, 222, 116, 180, 239,
-194, 245, 222, 134, 212, 182, 229, 200, 202, 246, 222, 149, 229, 204, 222, 157,
-222, 160, 183, 234, 223, 74, 229, 212, 223, 85, 223, 91, 223, 95, 223, 102,
-229, 219, 223, 116, 223, 124, 223, 130, 223, 138, 223, 143, 223, 148, 211, 202,
-219, 161, 224, 64, 224, 70, 224, 75, 224, 81, 224, 86, 179, 187, 219, 177,
-224, 107, 224, 117, 224, 126, 224, 134, 224, 143, 224, 151, 224, 160, 244, 252,
-225, 72, 245, 161, 179, 234, 195, 184, 225, 87, 225, 94, 225, 98, 225, 106,
-225, 114, 225, 120, 225, 128, 225, 138, 225, 141, 225, 150, 225, 159, 226, 72,
-226, 82, 226, 92, 226, 102, 226, 112, 226, 122, 226, 133, 226, 143, 226, 153,
-227, 66, 227, 76, 227, 86, 227, 96, 227, 106, 227, 115, 227, 125, 246, 198,
-227, 145, 227, 155, 228, 68, 228, 77, 228, 87, 228, 96, 228, 106, 228, 116,
-228, 126, 228, 137, 228, 147, 228, 157, 229, 70, 229, 80, 229, 90, 229, 100,
-229, 110, 229, 119, 229, 130, 229, 140, 229, 150, 246, 202, 230, 72, 230, 82,
-230, 92, 230, 101, 230, 111, 230, 121, 230, 132, 230, 142, 230, 152, 231, 64,
-231, 73, 231, 83, 231, 93, 231, 103, 231, 113, 231, 123, 231, 134, 231, 144,
-231, 154, 232, 67, 232, 77, 232, 86, 232, 96, 232, 106, 232, 116, 232, 125,
-232, 136, 232, 146, 238, 201, 232, 150, 196, 198, 238, 214, 238, 220, 188, 216,
-238, 230, 238, 239, 205, 173, 232, 157, 189, 194, 198, 204, 179, 250, 239, 180,
-239, 187, 239, 192, 239, 196, 239, 200, 182, 198, 196, 247, 239, 217, 239, 223,
-239, 232, 239, 239, 233, 81, 233, 90, 233, 100, 233, 110, 233, 120, 233, 131,
-233, 141, 233, 151, 234, 64, 234, 74, 234, 84, 201, 193, 188, 228, 227, 204,
-227, 208, 227, 214, 184, 183, 234, 103, 234, 111, 234, 115, 184, 189, 234, 120,
-234, 128, 212, 186, 218, 238, 204, 213, 234, 153, 234, 160, 184, 244, 235, 74,
-235, 83, 235, 92, 246, 192, 188, 175, 235, 105, 235, 113, 235, 122, 235, 130,
-235, 136, 235, 142, 235, 147, 193, 216, 235, 160, 246, 175, 236, 79, 246, 178,
-236, 96, 199, 224, 236, 111, 236, 116, 236, 125, 236, 133, 236, 142, 236, 149,
-199, 202, 237, 67, 237, 75, 237, 81, 237, 91, 237, 101, 237, 111, 237, 121,
-237, 130, 237, 135, 237, 142, 237, 152, 238, 65, 238, 75, 238, 85, 238, 95,
-238, 105, 238, 115, 238, 125, 238, 136, 238, 146, 238, 156, 239, 69, 185, 203,
-190, 177, 239, 72, 209, 213, 242, 173, 239, 84, 239, 94, 239, 104, 183, 231,
-198, 174, 239, 124, 239, 133, 239, 143, 239, 153, 240, 66, 240, 74, 240, 84,
-240, 94, 240, 103, 240, 113, 240, 123, 240, 134, 240, 142, 240, 151, 210, 251,
-240, 154, 240, 158, 241, 64, 202, 215, 241, 72, 241, 80, 241, 90, 241, 100,
-241, 110, 241, 120, 241, 131, 241, 141, 241, 151, 242, 64, 242, 74, 242, 84,
-242, 94, 242, 104, 242, 114, 242, 124, 242, 135, 242, 145, 242, 155, 243, 68,
-243, 78, 243, 82, 205, 213, 194, 230, 230, 235, 201, 167, 214, 232, 243, 96,
-186, 161, 247, 196, 247, 198, 243, 121, 243, 130, 243, 138, 243, 145, 243, 153,
-247, 220, 244, 73, 244, 82, 244, 90, 244, 99, 244, 108, 198, 199, 244, 117,
-244, 124, 244, 135, 244, 145, 244, 155, 245, 68, 245, 78, 245, 88, 245, 98,
-245, 108, 245, 118, 245, 129, 245, 139, 245, 149, 245, 159, 246, 72, 246, 82,
-246, 92, 246, 102, 246, 112, 246, 122, 246, 133, 246, 143, 246, 153, 247, 66,
-247, 76, 247, 86, 247, 96, 247, 106, 247, 116, 247, 126, 247, 133, 246, 215,
-247, 141, 246, 227, 247, 145, 246, 243, 247, 150, 246, 253, 247, 167, 193, 219,
-248, 69, 248, 79, 248, 89, 248, 99, 248, 109, 248, 119, 248, 130, 248, 140,
-248, 150, 248, 160, 249, 73, 249, 83, 249, 93, 249, 103, 249, 113, 249, 123,
-249, 134, 249, 144, 249, 154, 250, 67, 250, 77, 250, 87, 250, 97, 250, 107,
-250, 117, 250, 128, 250, 138, 250, 148, 250, 158, 251, 71, 251, 81, 251, 91,
-240, 177, 240, 182, 251, 98, 240, 193, 251, 101, 240, 203, 186, 215, 251, 113,
-251, 120, 247, 228, 251, 135, 251, 143, 251, 151, 251, 160, 244, 240, 247, 226,
-252, 87, 252, 92, 247, 237, 252, 103, 252, 109, 252, 118, 252, 125, 182, 166,
-252, 140, 247, 247, 247, 248, 253, 68, 253, 73, 253, 82, 253, 90, 253, 100,
-253, 110, 253, 120, 253, 131, 246, 182, 253, 139, 185, 168, 253, 154, 170, 161,
-170, 171, 170, 181, 170, 191, 170, 201, 170, 211, 170, 221, 170, 231, 170, 241,
-170, 251, 171, 167, 171, 177, 171, 187, 171, 197, 171, 207, 171, 217, 171, 227,
-171, 237, 171, 247, 172, 163, 172, 173, 172, 183, 172, 193, 172, 203, 172, 213,
-172, 223, 172, 233, 172, 243, 172, 253, 173, 169, 173, 179, 173, 189, 173, 199,
-173, 209, 173, 219, 173, 229, 173, 239, 173, 249, 174, 165, 174, 175, 174, 185,
-174, 195, 174, 205, 174, 215, 174, 225, 174, 235, 174, 245, 175, 161, 175, 171,
-175, 181, 175, 191, 175, 201, 175, 211, 175, 221, 175, 231, 175, 241, 175, 251,
-248, 167, 248, 177, 248, 187, 248, 197, 248, 207, 248, 217, 248, 227, 248, 237,
-248, 247, 249, 163, 249, 173, 249, 183, 249, 193, 249, 203, 249, 213, 249, 223,
-249, 233, 249, 243, 249, 253, 250, 169, 250, 179, 250, 189, 250, 199, 250, 209,
-250, 219, 250, 229, 250, 239, 250, 249, 251, 165, 251, 175, 251, 185, 251, 195,
-251, 205, 251, 215, 251, 225, 251, 235, 251, 245, 252, 161, 252, 171, 252, 181,
-252, 191, 252, 201, 252, 211, 252, 221, 252, 231, 252, 241, 252, 251, 253, 167,
-253, 177, 253, 187, 253, 197, 253, 207, 253, 217, 253, 227, 253, 237, 253, 247,
-254, 163, 254, 173, 254, 183, 254, 193, 254, 203, 254, 213, 254, 223, 254, 233,
-254, 243, 254, 253, 161, 72, 161, 82, 161, 92, 161, 102, 161, 112, 161, 122,
-161, 133, 161, 143, 161, 153, 162, 66, 162, 76, 162, 86, 162, 96, 162, 106,
-162, 116, 162, 126, 162, 137, 162, 147, 162, 157, 162, 227, 163, 68, 163, 78,
-163, 88, 163, 98, 163, 108, 163, 118, 163, 129, 163, 139, 163, 149, 163, 159,
-164, 72, 164, 82, 164, 92, 164, 102, 164, 112, 164, 122, 164, 133, 164, 143,
-164, 153, 164, 246, 165, 65, 165, 75, 165, 85, 165, 95, 165, 105, 165, 115,
-165, 125, 165, 136, 165, 146, 165, 156, 165, 252, 166, 71, 166, 81, 166, 91,
-166, 101, 166, 111, 166, 121, 166, 132, 166, 142, 166, 152, 166, 186, 166, 220,
-166, 249, 167, 68, 167, 78, 167, 88, 167, 98, 167, 108, 167, 118, 167, 129,
-167, 139, 167, 149, 167, 159, 167, 202, 167, 245, 168, 150, 168, 160, 168, 237,
-168, 247, 169, 93, 169, 144, 169, 155, 169, 241, 169, 251, 254, 81, 254, 91,
-254, 101, 254, 111, 254, 121, 254, 132, 254, 142, 254, 152, 253, 156, 253, 157,
-253, 158, 253, 159, 253, 160, 254, 64, 254, 71, 254, 75, 169, 85, 166, 227,
-166, 235, 169, 109, 169, 118, 169, 129, 163, 161, 163, 171, 163, 181, 163, 191,
-163, 201, 163, 211, 163, 221, 163, 231, 163, 241, 163, 251, 161, 233, 0 });
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK_Android.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK_Android.java
deleted file mode 100644
index 71a9932..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_GBK_Android.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargetClass;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_MultiByte_GBK_Android extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "GBK";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-164, 167, 168, 176, 177, 183, 215, 224, 225, 232, 233, 234, 236, 237, 242, 243,
-247, 249, 250, 252, 257, 275, 299, 324, 363, 462, 472, 593, 609, 711, 729, 913,
-923, 933, 945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230,
-8240, 8251, 8451, 8470, 8481, 8544, 8554, 8564, 8592, 8712, 8725, 8735, 8745, 8756, 8776, 8786,
-8800, 8814, 8857, 8869, 8895, 8978, 9312, 9332, 9342, 9352, 9362, 9472, 9482, 9492, 9502, 9512,
-9522, 9532, 9542, 9552, 9562, 9572, 9582, 9601, 9611, 9621, 9632, 9650, 9660, 9670, 9698, 9733,
-9792, 12288, 12298, 12308, 12318, 12328, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443,
-12453, 12463, 12473, 12483, 12493, 12503, 12513, 12523, 12533, 12549, 12559, 12569, 12579, 12832, 12849, 12963,
-13198, 13212, 13252, 13262, 19968, 19978, 19988, 19998, 20008, 20018, 20028, 20038, 20048, 20058, 20068, 20078,
-20088, 20098, 20108, 20118, 20128, 20138, 20148, 20158, 20168, 20178, 20188, 20198, 20208, 20218, 20228, 20238,
-20248, 20258, 20268, 20278, 20288, 20298, 20308, 20318, 20328, 20338, 20348, 20358, 20368, 20378, 20388, 20398,
-20408, 20418, 20428, 20438, 20448, 20458, 20468, 20478, 20488, 20498, 20508, 20518, 20528, 20538, 20548, 20558,
-20568, 20578, 20588, 20598, 20608, 20618, 20628, 20638, 20648, 20658, 20668, 20678, 20688, 20698, 20708, 20718,
-20728, 20738, 20748, 20758, 20768, 20778, 20788, 20798, 20808, 20818, 20828, 20838, 20848, 20858, 20868, 20878,
-20888, 20898, 20908, 20918, 20928, 20938, 20948, 20958, 20968, 20978, 20988, 20998, 21008, 21018, 21028, 21038,
-21048, 21058, 21068, 21078, 21088, 21098, 21108, 21118, 21128, 21138, 21148, 21158, 21168, 21178, 21188, 21198,
-21208, 21218, 21228, 21238, 21248, 21258, 21268, 21278, 21288, 21298, 21308, 21318, 21328, 21338, 21348, 21358,
-21368, 21378, 21388, 21398, 21408, 21418, 21428, 21438, 21448, 21458, 21468, 21478, 21488, 21498, 21508, 21518,
-21528, 21538, 21548, 21558, 21568, 21578, 21588, 21598, 21608, 21618, 21628, 21638, 21648, 21658, 21668, 21678,
-21688, 21698, 21708, 21718, 21728, 21738, 21748, 21758, 21768, 21778, 21788, 21798, 21808, 21818, 21828, 21838,
-21848, 21858, 21868, 21878, 21888, 21898, 21908, 21918, 21928, 21938, 21948, 21958, 21968, 21978, 21988, 21998,
-22008, 22018, 22028, 22038, 22048, 22058, 22068, 22078, 22088, 22098, 22108, 22118, 22128, 22138, 22148, 22158,
-22168, 22178, 22188, 22198, 22208, 22218, 22228, 22238, 22248, 22258, 22268, 22278, 22288, 22298, 22308, 22318,
-22328, 22338, 22348, 22358, 22368, 22378, 22388, 22398, 22408, 22418, 22428, 22438, 22448, 22458, 22468, 22478,
-22488, 22498, 22508, 22518, 22528, 22538, 22548, 22558, 22568, 22578, 22588, 22598, 22608, 22618, 22628, 22638,
-22648, 22658, 22668, 22678, 22688, 22698, 22708, 22718, 22728, 22738, 22748, 22758, 22768, 22778, 22788, 22798,
-22808, 22818, 22828, 22838, 22848, 22858, 22868, 22878, 22888, 22898, 22908, 22918, 22928, 22938, 22948, 22958,
-22968, 22978, 22988, 22998, 23008, 23018, 23028, 23038, 23048, 23058, 23068, 23078, 23088, 23098, 23108, 23118,
-23128, 23138, 23148, 23158, 23168, 23178, 23188, 23198, 23208, 23218, 23228, 23238, 23248, 23258, 23268, 23278,
-23288, 23298, 23308, 23318, 23328, 23338, 23348, 23358, 23368, 23378, 23388, 23398, 23408, 23418, 23428, 23438,
-23448, 23458, 23468, 23478, 23488, 23498, 23508, 23518, 23528, 23538, 23548, 23558, 23568, 23578, 23588, 23598,
-23608, 23618, 23628, 23638, 23648, 23658, 23668, 23678, 23688, 23698, 23708, 23718, 23728, 23738, 23748, 23758,
-23768, 23778, 23788, 23798, 23808, 23818, 23828, 23838, 23848, 23858, 23868, 23878, 23888, 23898, 23908, 23918,
-23928, 23938, 23948, 23958, 23968, 23978, 23988, 23998, 24008, 24018, 24028, 24038, 24048, 24058, 24068, 24078,
-24088, 24098, 24108, 24118, 24128, 24138, 24148, 24158, 24168, 24178, 24188, 24198, 24208, 24218, 24228, 24238,
-24248, 24258, 24268, 24278, 24288, 24298, 24308, 24318, 24328, 24338, 24348, 24358, 24368, 24378, 24388, 24398,
-24408, 24418, 24428, 24438, 24448, 24458, 24468, 24478, 24488, 24498, 24508, 24518, 24528, 24538, 24548, 24558,
-24568, 24578, 24588, 24598, 24608, 24618, 24628, 24638, 24648, 24658, 24668, 24678, 24688, 24698, 24708, 24718,
-24728, 24738, 24748, 24758, 24768, 24778, 24788, 24798, 24808, 24818, 24828, 24838, 24848, 24858, 24868, 24878,
-24888, 24898, 24908, 24918, 24928, 24938, 24948, 24958, 24968, 24978, 24988, 24998, 25008, 25018, 25028, 25038,
-25048, 25058, 25068, 25078, 25088, 25098, 25108, 25118, 25128, 25138, 25148, 25158, 25168, 25178, 25188, 25198,
-25208, 25218, 25228, 25238, 25248, 25258, 25268, 25278, 25288, 25298, 25308, 25318, 25328, 25338, 25348, 25358,
-25368, 25378, 25388, 25398, 25408, 25418, 25428, 25438, 25448, 25458, 25468, 25478, 25488, 25498, 25508, 25518,
-25528, 25538, 25548, 25558, 25568, 25578, 25588, 25598, 25608, 25618, 25628, 25638, 25648, 25658, 25668, 25678,
-25688, 25698, 25708, 25718, 25728, 25738, 25748, 25758, 25768, 25778, 25788, 25798, 25808, 25818, 25828, 25838,
-25848, 25858, 25868, 25878, 25888, 25898, 25908, 25918, 25928, 25938, 25948, 25958, 25968, 25978, 25988, 25998,
-26008, 26018, 26028, 26038, 26048, 26058, 26068, 26078, 26088, 26098, 26108, 26118, 26128, 26138, 26148, 26158,
-26168, 26178, 26188, 26198, 26208, 26218, 26228, 26238, 26248, 26258, 26268, 26278, 26288, 26298, 26308, 26318,
-26328, 26338, 26348, 26358, 26368, 26378, 26388, 26398, 26408, 26418, 26428, 26438, 26448, 26458, 26468, 26478,
-26488, 26498, 26508, 26518, 26528, 26538, 26548, 26558, 26568, 26578, 26588, 26598, 26608, 26618, 26628, 26638,
-26648, 26658, 26668, 26678, 26688, 26698, 26708, 26718, 26728, 26738, 26748, 26758, 26768, 26778, 26788, 26798,
-26808, 26818, 26828, 26838, 26848, 26858, 26868, 26878, 26888, 26898, 26908, 26918, 26928, 26938, 26948, 26958,
-26968, 26978, 26988, 26998, 27008, 27018, 27028, 27038, 27048, 27058, 27068, 27078, 27088, 27098, 27108, 27118,
-27128, 27138, 27148, 27158, 27168, 27178, 27188, 27198, 27208, 27218, 27228, 27238, 27248, 27258, 27268, 27278,
-27288, 27298, 27308, 27318, 27328, 27338, 27348, 27358, 27368, 27378, 27388, 27398, 27408, 27418, 27428, 27438,
-27448, 27458, 27468, 27478, 27488, 27498, 27508, 27518, 27528, 27538, 27548, 27558, 27568, 27578, 27588, 27598,
-27608, 27618, 27628, 27638, 27648, 27658, 27668, 27678, 27688, 27698, 27708, 27718, 27728, 27738, 27748, 27758,
-27768, 27778, 27788, 27798, 27808, 27818, 27828, 27838, 27848, 27858, 27868, 27878, 27888, 27898, 27908, 27918,
-27928, 27938, 27948, 27958, 27968, 27978, 27988, 27998, 28008, 28018, 28028, 28038, 28048, 28058, 28068, 28078,
-28088, 28098, 28108, 28118, 28128, 28138, 28148, 28158, 28168, 28178, 28188, 28198, 28208, 28218, 28228, 28238,
-28248, 28258, 28268, 28278, 28288, 28298, 28308, 28318, 28328, 28338, 28348, 28358, 28368, 28378, 28388, 28398,
-28408, 28418, 28428, 28438, 28448, 28458, 28468, 28478, 28488, 28498, 28508, 28518, 28528, 28538, 28548, 28558,
-28568, 28578, 28588, 28598, 28608, 28618, 28628, 28638, 28648, 28658, 28668, 28678, 28688, 28698, 28708, 28718,
-28728, 28738, 28748, 28758, 28768, 28778, 28788, 28798, 28808, 28818, 28828, 28838, 28848, 28858, 28868, 28878,
-28888, 28898, 28908, 28918, 28928, 28938, 28948, 28958, 28968, 28978, 28988, 28998, 29008, 29018, 29028, 29038,
-29048, 29058, 29068, 29078, 29088, 29098, 29108, 29118, 29128, 29138, 29148, 29158, 29168, 29178, 29188, 29198,
-29208, 29218, 29228, 29238, 29248, 29258, 29268, 29278, 29288, 29298, 29308, 29318, 29328, 29338, 29348, 29358,
-29368, 29378, 29388, 29398, 29408, 29418, 29428, 29438, 29448, 29458, 29468, 29478, 29488, 29498, 29508, 29518,
-29528, 29538, 29548, 29558, 29568, 29578, 29588, 29598, 29608, 29618, 29628, 29638, 29648, 29658, 29668, 29678,
-29688, 29698, 29708, 29718, 29728, 29738, 29748, 29758, 29768, 29778, 29788, 29798, 29808, 29818, 29828, 29838,
-29848, 29858, 29868, 29878, 29888, 29898, 29908, 29918, 29928, 29938, 29948, 29958, 29968, 29978, 29988, 29998,
-30008, 30018, 30028, 30038, 30048, 30058, 30068, 30078, 30088, 30098, 30108, 30118, 30128, 30138, 30148, 30158,
-30168, 30178, 30188, 30198, 30208, 30218, 30228, 30238, 30248, 30258, 30268, 30278, 30288, 30298, 30308, 30318,
-30328, 30338, 30348, 30358, 30368, 30378, 30388, 30398, 30408, 30418, 30428, 30438, 30448, 30458, 30468, 30478,
-30488, 30498, 30508, 30518, 30528, 30538, 30548, 30558, 30568, 30578, 30588, 30598, 30608, 30618, 30628, 30638,
-30648, 30658, 30668, 30678, 30688, 30698, 30708, 30718, 30728, 30738, 30748, 30758, 30768, 30778, 30788, 30798,
-30808, 30818, 30828, 30838, 30848, 30858, 30868, 30878, 30888, 30898, 30908, 30918, 30928, 30938, 30948, 30958,
-30968, 30978, 30988, 30998, 31008, 31018, 31028, 31038, 31048, 31058, 31068, 31078, 31088, 31098, 31108, 31118,
-31128, 31138, 31148, 31158, 31168, 31178, 31188, 31198, 31208, 31218, 31228, 31238, 31248, 31258, 31268, 31278,
-31288, 31298, 31308, 31318, 31328, 31338, 31348, 31358, 31368, 31378, 31388, 31398, 31408, 31418, 31428, 31438,
-31448, 31458, 31468, 31478, 31488, 31498, 31508, 31518, 31528, 31538, 31548, 31558, 31568, 31578, 31588, 31598,
-31608, 31618, 31628, 31638, 31648, 31658, 31668, 31678, 31688, 31698, 31708, 31718, 31728, 31738, 31748, 31758,
-31768, 31778, 31788, 31798, 31808, 31818, 31828, 31838, 31848, 31858, 31868, 31878, 31888, 31898, 31908, 31918,
-31928, 31938, 31948, 31958, 31968, 31978, 31988, 31998, 32008, 32018, 32028, 32038, 32048, 32058, 32068, 32078,
-32088, 32098, 32108, 32118, 32128, 32138, 32148, 32158, 32168, 32178, 32188, 32198, 32208, 32218, 32228, 32238,
-32248, 32258, 32268, 32278, 32288, 32298, 32308, 32318, 32328, 32338, 32348, 32358, 32368, 32378, 32388, 32398,
-32408, 32418, 32428, 32438, 32448, 32458, 32468, 32478, 32488, 32498, 32508, 32518, 32528, 32538, 32548, 32558,
-32568, 32578, 32588, 32598, 32608, 32618, 32628, 32638, 32648, 32658, 32668, 32678, 32688, 32698, 32708, 32718,
-32728, 32738, 32748, 32758, 32768, 32778, 32788, 32798, 32808, 32818, 32828, 32838, 32848, 32858, 32868, 32878,
-32888, 32898, 32908, 32918, 32928, 32938, 32948, 32958, 32968, 32978, 32988, 32998, 33008, 33018, 33028, 33038,
-33048, 33058, 33068, 33078, 33088, 33098, 33108, 33118, 33128, 33138, 33148, 33158, 33168, 33178, 33188, 33198,
-33208, 33218, 33228, 33238, 33248, 33258, 33268, 33278, 33288, 33298, 33308, 33318, 33328, 33338, 33348, 33358,
-33368, 33378, 33388, 33398, 33408, 33418, 33428, 33438, 33448, 33458, 33468, 33478, 33488, 33498, 33508, 33518,
-33528, 33538, 33548, 33558, 33568, 33578, 33588, 33598, 33608, 33618, 33628, 33638, 33648, 33658, 33668, 33678,
-33688, 33698, 33708, 33718, 33728, 33738, 33748, 33758, 33768, 33778, 33788, 33798, 33808, 33818, 33828, 33838,
-33848, 33858, 33868, 33878, 33888, 33898, 33908, 33918, 33928, 33938, 33948, 33958, 33968, 33978, 33988, 33998,
-34008, 34018, 34028, 34038, 34048, 34058, 34068, 34078, 34088, 34098, 34108, 34118, 34128, 34138, 34148, 34158,
-34168, 34178, 34188, 34198, 34208, 34218, 34228, 34238, 34248, 34258, 34268, 34278, 34288, 34298, 34308, 34318,
-34328, 34338, 34348, 34358, 34368, 34378, 34388, 34398, 34408, 34418, 34428, 34438, 34448, 34458, 34468, 34478,
-34488, 34498, 34508, 34518, 34528, 34538, 34548, 34558, 34568, 34578, 34588, 34598, 34608, 34618, 34628, 34638,
-34648, 34658, 34668, 34678, 34688, 34698, 34708, 34718, 34728, 34738, 34748, 34758, 34768, 34778, 34788, 34798,
-34808, 34818, 34828, 34838, 34848, 34858, 34868, 34878, 34888, 34898, 34908, 34918, 34928, 34938, 34948, 34958,
-34968, 34978, 34988, 34998, 35008, 35018, 35028, 35038, 35048, 35058, 35068, 35078, 35088, 35098, 35108, 35118,
-35128, 35138, 35148, 35158, 35168, 35178, 35188, 35198, 35208, 35218, 35228, 35238, 35248, 35258, 35268, 35278,
-35288, 35298, 35308, 35318, 35328, 35338, 35348, 35358, 35368, 35378, 35388, 35398, 35408, 35418, 35428, 35438,
-35448, 35458, 35468, 35478, 35488, 35498, 35508, 35518, 35528, 35538, 35548, 35558, 35568, 35578, 35588, 35598,
-35608, 35618, 35628, 35638, 35648, 35658, 35668, 35678, 35688, 35698, 35708, 35718, 35728, 35738, 35748, 35758,
-35768, 35778, 35788, 35798, 35808, 35818, 35828, 35838, 35848, 35858, 35868, 35878, 35888, 35898, 35908, 35918,
-35928, 35938, 35948, 35958, 35968, 35978, 35988, 35998, 36008, 36018, 36028, 36038, 36048, 36058, 36068, 36078,
-36088, 36098, 36108, 36118, 36128, 36138, 36148, 36158, 36168, 36178, 36188, 36198, 36208, 36218, 36228, 36238,
-36248, 36258, 36268, 36278, 36288, 36298, 36308, 36318, 36328, 36338, 36348, 36358, 36368, 36378, 36388, 36398,
-36408, 36418, 36428, 36438, 36448, 36458, 36468, 36478, 36488, 36498, 36508, 36518, 36528, 36538, 36548, 36558,
-36568, 36578, 36588, 36598, 36608, 36618, 36628, 36638, 36648, 36658, 36668, 36678, 36688, 36698, 36708, 36718,
-36728, 36738, 36748, 36758, 36768, 36778, 36788, 36798, 36808, 36818, 36828, 36838, 36848, 36858, 36868, 36878,
-36888, 36898, 36908, 36918, 36928, 36938, 36948, 36958, 36968, 36978, 36988, 36998, 37008, 37018, 37028, 37038,
-37048, 37058, 37068, 37078, 37088, 37098, 37108, 37118, 37128, 37138, 37148, 37158, 37168, 37178, 37188, 37198,
-37208, 37218, 37228, 37238, 37248, 37258, 37268, 37278, 37288, 37298, 37308, 37318, 37328, 37338, 37348, 37358,
-37368, 37378, 37388, 37398, 37408, 37418, 37428, 37438, 37448, 37458, 37468, 37478, 37488, 37498, 37508, 37518,
-37528, 37538, 37548, 37558, 37568, 37578, 37588, 37598, 37608, 37618, 37628, 37638, 37648, 37658, 37668, 37678,
-37688, 37698, 37708, 37718, 37728, 37738, 37748, 37758, 37768, 37778, 37788, 37798, 37808, 37818, 37828, 37838,
-37848, 37858, 37868, 37878, 37888, 37898, 37908, 37918, 37928, 37938, 37948, 37958, 37968, 37978, 37988, 37998,
-38008, 38018, 38028, 38038, 38048, 38058, 38068, 38078, 38088, 38098, 38108, 38118, 38128, 38138, 38148, 38158,
-38168, 38178, 38188, 38198, 38208, 38218, 38228, 38238, 38248, 38258, 38268, 38278, 38288, 38298, 38308, 38318,
-38328, 38338, 38348, 38358, 38368, 38378, 38388, 38398, 38408, 38418, 38428, 38438, 38448, 38458, 38468, 38478,
-38488, 38498, 38508, 38518, 38528, 38538, 38548, 38558, 38568, 38578, 38588, 38598, 38608, 38618, 38628, 38638,
-38648, 38658, 38668, 38678, 38688, 38698, 38708, 38718, 38728, 38738, 38748, 38758, 38768, 38778, 38788, 38798,
-38808, 38818, 38828, 38838, 38848, 38858, 38868, 38878, 38888, 38898, 38908, 38918, 38928, 38938, 38948, 38958,
-38968, 38978, 38988, 38998, 39008, 39018, 39028, 39038, 39048, 39058, 39068, 39078, 39088, 39098, 39108, 39118,
-39128, 39138, 39148, 39158, 39168, 39178, 39188, 39198, 39208, 39218, 39228, 39238, 39248, 39258, 39268, 39278,
-39288, 39298, 39308, 39318, 39328, 39338, 39348, 39358, 39368, 39378, 39388, 39398, 39408, 39418, 39428, 39438,
-39448, 39458, 39468, 39478, 39488, 39498, 39508, 39518, 39528, 39538, 39548, 39558, 39568, 39578, 39588, 39598,
-39608, 39618, 39628, 39638, 39648, 39658, 39668, 39678, 39688, 39698, 39708, 39718, 39728, 39738, 39748, 39758,
-39768, 39778, 39788, 39798, 39808, 39818, 39828, 39838, 39848, 39858, 39868, 39878, 39888, 39898, 39908, 39918,
-39928, 39938, 39948, 39958, 39968, 39978, 39988, 39998, 40008, 40018, 40028, 40038, 40048, 40058, 40068, 40078,
-40088, 40098, 40108, 40118, 40128, 40138, 40148, 40158, 40168, 40178, 40188, 40198, 40208, 40218, 40228, 40238,
-40248, 40258, 40268, 40278, 40288, 40298, 40308, 40318, 40328, 40338, 40348, 40358, 40368, 40378, 40388, 40398,
-40408, 40418, 40428, 40438, 40448, 40458, 40468, 40478, 40488, 40498, 40508, 40518, 40528, 40538, 40548, 40558,
-40568, 40578, 40588, 40598, 40608, 40618, 40628, 40638, 40648, 40658, 40668, 40678, 40688, 40698, 40708, 40718,
-40728, 40738, 40748, 40758, 40768, 40778, 40788, 40798, 40808, 40818, 40828, 40838, 40848, 40858, 40868, 57344,
-57354, 57364, 57374, 57384, 57394, 57404, 57414, 57424, 57434, 57444, 57454, 57464, 57474, 57484, 57494, 57504,
-57514, 57524, 57534, 57544, 57554, 57564, 57574, 57584, 57594, 57604, 57614, 57624, 57634, 57644, 57654, 57664,
-57674, 57684, 57694, 57704, 57714, 57724, 57734, 57744, 57754, 57764, 57774, 57784, 57794, 57804, 57814, 57824,
-57834, 57844, 57854, 57864, 57874, 57884, 57894, 57904, 57914, 57924, 57934, 57944, 57954, 57964, 57974, 57984,
-57994, 58004, 58014, 58024, 58034, 58044, 58054, 58064, 58074, 58084, 58094, 58104, 58114, 58124, 58134, 58144,
-58154, 58164, 58174, 58184, 58194, 58204, 58214, 58224, 58234, 58244, 58254, 58264, 58274, 58284, 58294, 58304,
-58314, 58324, 58334, 58344, 58354, 58364, 58374, 58384, 58394, 58404, 58414, 58424, 58434, 58444, 58454, 58464,
-58474, 58484, 58494, 58504, 58514, 58524, 58534, 58544, 58554, 58564, 58574, 58584, 58594, 58604, 58614, 58624,
-58634, 58644, 58654, 58664, 58674, 58684, 58694, 58704, 58714, 58724, 58734, 58744, 58754, 58764, 58774, 58784,
-58794, 58804, 58814, 58824, 58834, 58844, 58854, 58864, 58874, 58884, 58894, 58904, 58914, 58924, 58934, 58944,
-58954, 58964, 58974, 58984, 58994, 59004, 59014, 59024, 59034, 59044, 59054, 59064, 59074, 59084, 59094, 59104,
-59114, 59124, 59134, 59144, 59154, 59164, 59174, 59184, 59194, 59204, 59214, 59224, 59234, 59244, 59254, 59264,
-59274, 59284, 59294, 59304, 59314, 59324, 59334, 59344, 59354, 59364, 59374, 59384, 59394, 59404, 59414, 59424,
-59434, 59444, 59454, 59464, 59474, 59484, 63788, 63865, 63893, 63975, 63985, 64012, 64024, 64035, 65072, 65082,
-65092, 65102, 65113, 65123, 65281, 65291, 65301, 65311, 65321, 65331, 65341, 65351, 65361, 65371, 65504, 65536
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 232, 161, 236, 161, 167, 161, 227, 161, 192, 161, 164, 161, 193, 168, 164,
-168, 162, 168, 168, 168, 166, 168, 186, 168, 172, 168, 170, 168, 176, 168, 174,
-161, 194, 168, 180, 168, 178, 168, 185, 168, 161, 168, 165, 168, 169, 168, 189,
-168, 177, 168, 163, 168, 182, 168, 187, 168, 192, 161, 166, 168, 66, 166, 161,
-166, 171, 166, 180, 166, 193, 166, 203, 166, 212, 167, 167, 167, 161, 167, 172,
-167, 182, 167, 192, 167, 218, 167, 228, 167, 238, 169, 92, 161, 176, 161, 173,
-161, 235, 161, 249, 161, 230, 161, 237, 169, 89, 162, 241, 162, 251, 162, 165,
-161, 251, 161, 202, 168, 77, 168, 78, 161, 201, 161, 224, 161, 214, 168, 80,
-161, 217, 161, 218, 161, 209, 161, 205, 168, 83, 161, 208, 162, 217, 162, 197,
-162, 207, 162, 177, 162, 187, 169, 164, 169, 174, 169, 184, 169, 194, 169, 204,
-169, 214, 169, 224, 169, 234, 168, 84, 168, 94, 168, 104, 168, 114, 168, 120,
-168, 131, 168, 138, 161, 246, 161, 248, 168, 139, 161, 244, 168, 141, 161, 239,
-161, 226, 161, 161, 161, 182, 161, 178, 168, 149, 169, 71, 164, 161, 164, 171,
-164, 181, 164, 191, 164, 201, 164, 211, 164, 221, 164, 231, 164, 241, 169, 97,
-165, 165, 165, 175, 165, 185, 165, 195, 165, 205, 165, 215, 165, 225, 165, 235,
-165, 245, 168, 197, 168, 207, 168, 217, 168, 227, 162, 229, 169, 90, 169, 73,
-169, 74, 169, 76, 169, 80, 169, 81, 210, 187, 201, 207, 199, 210, 216, 169,
-216, 173, 180, 174, 129, 83, 129, 88, 192, 214, 129, 93, 129, 97, 129, 105,
-129, 112, 129, 121, 182, 254, 129, 129, 217, 239, 129, 136, 129, 140, 129, 147,
-129, 148, 129, 152, 129, 155, 129, 158, 209, 246, 129, 168, 129, 174, 188, 191,
-211, 197, 216, 243, 129, 192, 193, 230, 129, 203, 129, 211, 129, 215, 216, 250,
-129, 220, 129, 226, 217, 174, 129, 237, 129, 242, 129, 249, 130, 64, 206, 234,
-130, 74, 130, 83, 130, 89, 130, 95, 130, 98, 217, 179, 130, 107, 217, 194,
-130, 124, 181, 185, 217, 195, 190, 235, 130, 146, 213, 174, 130, 162, 217, 203,
-130, 176, 130, 184, 217, 204, 197, 188, 191, 254, 130, 214, 130, 223, 130, 233,
-180, 162, 176, 193, 130, 254, 131, 73, 131, 82, 193, 197, 131, 100, 217, 215,
-131, 113, 131, 122, 131, 130, 131, 139, 131, 149, 131, 158, 131, 168, 131, 178,
-207, 200, 131, 186, 182, 181, 131, 199, 192, 188, 131, 205, 131, 209, 131, 214,
-131, 220, 218, 163, 182, 172, 210, 177, 190, 187, 131, 245, 131, 251, 132, 68,
-132, 75, 132, 81, 219, 202, 183, 214, 132, 91, 184, 213, 197, 208, 185, 206,
-200, 175, 188, 193, 216, 221, 198, 202, 132, 133, 188, 244, 132, 146, 132, 155,
-197, 252, 132, 170, 132, 178, 132, 181, 132, 185, 132, 192, 132, 199, 132, 206,
-191, 177, 132, 221, 132, 230, 132, 239, 212, 200, 132, 251, 133, 67, 133, 71,
-133, 77, 133, 85, 133, 92, 133, 97, 133, 101, 178, 169, 194, 177, 216, 180,
-208, 182, 179, 167, 209, 225, 133, 133, 133, 139, 133, 143, 133, 152, 133, 160,
-211, 214, 133, 170, 133, 174, 193, 237, 204, 168, 133, 181, 184, 247, 186, 243,
-133, 190, 133, 194, 204, 253, 133, 200, 209, 189, 184, 230, 223, 190, 133, 218,
-214, 220, 223, 218, 186, 244, 197, 216, 184, 192, 223, 203, 223, 229, 134, 66,
-207, 204, 223, 211, 223, 223, 134, 80, 134, 83, 196, 196, 134, 93, 134, 100,
-134, 106, 134, 112, 134, 120, 134, 126, 224, 167, 134, 138, 215, 196, 134, 149,
-134, 156, 134, 164, 216, 196, 224, 164, 191, 166, 186, 176, 224, 184, 134, 192,
-134, 200, 134, 209, 134, 214, 134, 220, 134, 227, 134, 232, 224, 205, 134, 240,
-134, 245, 134, 251, 224, 209, 135, 75, 135, 81, 135, 88, 215, 236, 135, 100,
-135, 109, 135, 116, 224, 224, 135, 130, 135, 135, 135, 143, 135, 151, 186, 191,
-135, 166, 135, 176, 135, 185, 135, 194, 135, 202, 196, 210, 224, 236, 187, 216,
-135, 230, 135, 236, 135, 242, 212, 178, 135, 253, 136, 72, 136, 79, 219, 220,
-136, 90, 219, 224, 219, 208, 136, 106, 215, 185, 198, 186, 136, 118, 136, 124,
-136, 130, 192, 221, 136, 145, 191, 209, 136, 154, 136, 161, 136, 169, 179, 199,
-219, 245, 136, 187, 136, 196, 136, 203, 220, 165, 136, 215, 136, 222, 220, 166,
-136, 236, 136, 244, 136, 253, 137, 71, 137, 79, 137, 86, 137, 95, 137, 102,
-137, 112, 137, 119, 137, 126, 137, 135, 137, 141, 137, 149, 137, 159, 137, 168,
-137, 176, 137, 185, 137, 194, 137, 203, 201, 249, 137, 216, 180, 166, 137, 232,
-137, 238, 137, 244, 137, 248, 137, 253, 138, 67, 138, 71, 177, 188, 138, 81,
-138, 88, 138, 98, 138, 103, 215, 177, 138, 113, 138, 118, 230, 165, 196, 221,
-138, 138, 138, 145, 138, 152, 138, 157, 138, 162, 138, 169, 138, 178, 138, 186,
-230, 174, 138, 195, 196, 200, 138, 208, 138, 217, 138, 223, 138, 231, 138, 238,
-138, 247, 230, 190, 139, 72, 201, 244, 139, 86, 139, 96, 139, 105, 139, 113,
-139, 123, 230, 199, 139, 139, 139, 146, 139, 154, 139, 160, 139, 166, 139, 173,
-139, 182, 139, 192, 139, 201, 230, 212, 139, 219, 139, 229, 217, 248, 139, 246,
-140, 64, 140, 72, 215, 206, 209, 167, 202, 235, 200, 230, 229, 179, 140, 97,
-185, 217, 191, 205, 140, 107, 188, 210, 140, 117, 140, 122, 140, 129, 196, 175,
-213, 175, 140, 150, 181, 188, 189, 171, 140, 168, 201, 208, 211, 200, 140, 185,
-202, 172, 178, 227, 140, 197, 140, 202, 205, 192, 140, 215, 140, 222, 140, 230,
-225, 172, 140, 242, 225, 177, 140, 252, 141, 67, 141, 72, 225, 187, 141, 87,
-141, 96, 141, 104, 141, 109, 141, 117, 141, 126, 141, 133, 180, 222, 225, 198,
-141, 155, 141, 162, 141, 171, 141, 179, 141, 185, 141, 194, 141, 202, 141, 209,
-141, 217, 225, 214, 141, 236, 141, 246, 141, 254, 142, 73, 142, 83, 142, 92,
-142, 101, 142, 110, 142, 119, 215, 243, 142, 128, 142, 133, 142, 138, 142, 144,
-193, 177, 142, 152, 142, 160, 142, 167, 142, 172, 142, 179, 225, 163, 225, 165,
-142, 202, 184, 201, 211, 215, 199, 236, 194, 174, 184, 253, 142, 232, 142, 238,
-211, 185, 142, 251, 143, 68, 193, 206, 143, 83, 226, 222, 219, 200, 222, 195,
-222, 196, 143, 115, 143, 120, 207, 210, 143, 132, 199, 191, 143, 147, 143, 157,
-229, 233, 208, 206, 177, 242, 143, 178, 205, 249, 187, 178, 143, 191, 143, 196,
-225, 229, 143, 211, 225, 232, 210, 228, 236, 254, 143, 232, 226, 232, 226, 229,
-226, 238, 203, 203, 144, 67, 178, 192, 181, 161, 185, 214, 144, 86, 144, 93,
-144, 99, 186, 227, 144, 112, 144, 118, 199, 161, 226, 253, 199, 196, 144, 136,
-144, 143, 144, 148, 208, 252, 144, 158, 144, 165, 190, 170, 144, 180, 144, 185,
-178, 210, 144, 193, 144, 198, 237, 169, 144, 210, 211, 222, 183, 223, 144, 231,
-144, 241, 144, 250, 187, 197, 145, 73, 145, 82, 145, 89, 145, 98, 145, 106,
-145, 116, 145, 124, 145, 134, 145, 143, 145, 149, 145, 158, 145, 166, 145, 173,
-145, 180, 145, 190, 145, 199, 145, 208, 145, 217, 206, 236, 145, 226, 145, 230,
-145, 235, 145, 242, 145, 249, 145, 253, 146, 65, 146, 70, 146, 78, 176, 231,
-146, 86, 146, 91, 146, 98, 182, 182, 191, 217, 146, 112, 146, 119, 146, 124,
-196, 233, 190, 220, 176, 221, 192, 185, 146, 140, 146, 145, 146, 149, 191, 230,
-146, 163, 222, 216, 146, 169, 146, 177, 146, 184, 146, 189, 146, 193, 192, 204,
-146, 206, 146, 212, 146, 218, 146, 226, 198, 254, 146, 235, 146, 242, 222, 231,
-181, 167, 147, 65, 147, 72, 210, 190, 222, 235, 190, 190, 212, 174, 147, 104,
-147, 109, 147, 115, 203, 209, 222, 249, 147, 135, 208, 175, 201, 227, 147, 154,
-213, 170, 147, 170, 147, 178, 147, 187, 147, 194, 147, 200, 147, 208, 215, 178,
-147, 223, 147, 228, 186, 179, 147, 240, 223, 167, 147, 254, 223, 169, 148, 79,
-148, 89, 148, 98, 148, 107, 148, 116, 148, 125, 148, 135, 234, 183, 183, 197,
-208, 167, 148, 158, 148, 164, 182, 216, 202, 253, 148, 183, 148, 193, 148, 200,
-148, 206, 148, 211, 148, 216, 148, 223, 148, 230, 148, 235, 148, 240, 148, 248,
-214, 188, 149, 64, 149, 71, 192, 165, 149, 83, 149, 89, 149, 96, 149, 102,
-149, 107, 149, 114, 201, 206, 234, 205, 149, 133, 149, 139, 199, 231, 193, 192,
-149, 158, 149, 166, 149, 174, 149, 183, 149, 190, 149, 198, 149, 207, 149, 217,
-149, 227, 149, 233, 149, 241, 149, 247, 215, 238, 235, 195, 203, 183, 150, 79,
-196, 190, 150, 90, 150, 97, 184, 203, 178, 196, 150, 113, 150, 118, 150, 123,
-150, 128, 150, 134, 150, 140, 150, 148, 150, 152, 199, 185, 150, 161, 150, 167,
-150, 174, 198, 226, 185, 241, 150, 189, 232, 205, 150, 202, 150, 209, 232, 221,
-150, 216, 150, 224, 150, 232, 150, 240, 232, 238, 232, 240, 189, 219, 151, 66,
-189, 176, 151, 75, 151, 82, 176, 240, 151, 97, 151, 105, 151, 114, 151, 120,
-151, 126, 232, 249, 151, 143, 151, 150, 204, 196, 151, 166, 151, 173, 151, 179,
-151, 187, 189, 183, 151, 202, 151, 209, 210, 172, 151, 225, 151, 232, 151, 242,
-151, 250, 152, 65, 152, 72, 152, 80, 233, 175, 152, 89, 192, 198, 152, 103,
-213, 165, 152, 118, 152, 125, 152, 135, 187, 177, 152, 150, 152, 157, 152, 166,
-152, 175, 152, 183, 152, 192, 152, 202, 152, 209, 186, 225, 152, 224, 233, 208,
-152, 239, 152, 248, 153, 64, 153, 72, 153, 82, 153, 90, 207, 173, 233, 213,
-153, 113, 153, 122, 195, 202, 153, 140, 153, 150, 153, 160, 153, 170, 153, 180,
-153, 190, 153, 200, 153, 210, 153, 220, 153, 230, 153, 240, 236, 163, 153, 254,
-154, 71, 154, 78, 184, 232, 154, 93, 154, 102, 205, 225, 154, 115, 154, 122,
-154, 126, 233, 230, 154, 138, 154, 147, 154, 156, 154, 162, 154, 169, 154, 176,
-154, 179, 154, 186, 154, 194, 154, 201, 154, 209, 154, 216, 198, 248, 154, 224,
-176, 177, 235, 181, 154, 238, 217, 224, 207, 171, 155, 65, 204, 192, 155, 74,
-155, 80, 210, 202, 227, 231, 155, 95, 155, 102, 187, 166, 155, 108, 213, 180,
-155, 119, 155, 125, 155, 130, 155, 134, 204, 169, 227, 248, 228, 167, 228, 169,
-155, 159, 155, 165, 155, 171, 155, 176, 155, 181, 215, 199, 228, 177, 228, 183,
-155, 199, 155, 205, 228, 188, 155, 219, 155, 225, 155, 231, 181, 211, 228, 204,
-186, 212, 155, 250, 204, 202, 196, 215, 228, 196, 156, 83, 156, 88, 156, 94,
-156, 103, 156, 107, 156, 113, 156, 117, 156, 123, 195, 236, 228, 216, 228, 207,
-207, 230, 156, 160, 156, 169, 156, 178, 156, 186, 156, 192, 156, 200, 156, 208,
-156, 214, 228, 209, 156, 225, 156, 232, 156, 239, 185, 246, 194, 203, 156, 253,
-157, 71, 198, 175, 157, 87, 157, 93, 196, 174, 228, 244, 157, 114, 209, 250,
-157, 131, 157, 139, 199, 177, 193, 202, 157, 162, 228, 253, 179, 206, 197, 236,
-157, 191, 157, 199, 157, 208, 229, 164, 188, 164, 157, 232, 157, 240, 229, 168,
-158, 66, 158, 74, 158, 84, 158, 94, 158, 104, 229, 171, 158, 120, 158, 131,
-158, 140, 158, 149, 185, 224, 158, 167, 158, 176, 158, 186, 158, 191, 212, 214,
-158, 203, 179, 180, 236, 191, 158, 223, 158, 228, 158, 233, 158, 236, 158, 244,
-186, 230, 159, 69, 189, 253, 159, 80, 159, 87, 186, 184, 159, 103, 159, 108,
-159, 117, 159, 124, 159, 134, 159, 143, 159, 150, 159, 160, 195, 186, 214, 243,
-236, 212, 159, 188, 159, 196, 159, 204, 236, 218, 159, 219, 159, 227, 159, 235,
-159, 244, 159, 253, 160, 70, 160, 78, 160, 86, 160, 95, 160, 105, 160, 114,
-160, 124, 160, 134, 197, 192, 184, 184, 160, 151, 160, 159, 160, 166, 160, 172,
-160, 177, 201, 252, 160, 190, 160, 195, 160, 201, 160, 210, 160, 219, 160, 227,
-225, 239, 191, 241, 160, 245, 160, 251, 186, 221, 170, 73, 225, 249, 170, 79,
-170, 87, 170, 95, 178, 194, 170, 104, 170, 109, 170, 114, 170, 122, 170, 132,
-170, 139, 170, 148, 226, 179, 171, 68, 171, 77, 171, 84, 171, 91, 171, 99,
-171, 107, 193, 225, 171, 117, 171, 125, 183, 169, 171, 138, 171, 146, 171, 152,
-172, 64, 172, 74, 172, 79, 172, 87, 172, 95, 231, 247, 199, 217, 172, 112,
-172, 121, 172, 132, 232, 164, 172, 144, 185, 229, 172, 160, 173, 69, 232, 172,
-173, 85, 173, 93, 173, 100, 173, 110, 173, 119, 173, 130, 173, 139, 240, 172,
-173, 152, 173, 160, 174, 70, 174, 78, 174, 86, 201, 245, 174, 99, 174, 103,
-181, 233, 174, 111, 189, 231, 174, 124, 174, 131, 183, 172, 179, 235, 174, 154,
-175, 64, 240, 218, 175, 75, 175, 78, 240, 230, 175, 86, 240, 228, 175, 94,
-182, 187, 193, 161, 175, 109, 175, 116, 240, 246, 240, 250, 175, 137, 175, 142,
-175, 146, 175, 151, 241, 162, 176, 65, 176, 73, 176, 81, 176, 88, 176, 97,
-185, 239, 212, 237, 176, 116, 205, 238, 176, 132, 176, 141, 241, 229, 176, 157,
-211, 175, 186, 208, 177, 73, 177, 81, 177, 89, 177, 94, 237, 237, 177, 105,
-177, 115, 237, 243, 177, 128, 191, 244, 215, 197, 177, 146, 177, 154, 178, 65,
-237, 254, 178, 77, 178, 86, 178, 90, 178, 97, 178, 105, 178, 112, 178, 117,
-178, 124, 178, 132, 178, 142, 178, 151, 178, 158, 179, 66, 179, 71, 183, 175,
-179, 83, 197, 248, 237, 191, 237, 206, 197, 233, 237, 194, 179, 113, 237, 202,
-179, 124, 179, 134, 211, 178, 179, 149, 179, 157, 180, 68, 180, 73, 180, 78,
-180, 83, 237, 218, 180, 97, 180, 104, 197, 205, 180, 117, 180, 128, 180, 136,
-180, 143, 180, 151, 180, 160, 181, 72, 181, 81, 181, 90, 237, 231, 201, 231,
-198, 237, 181, 120, 236, 239, 181, 129, 181, 135, 236, 247, 194, 187, 181, 157,
-182, 69, 182, 78, 182, 87, 182, 96, 208, 227, 182, 106, 182, 112, 182, 120,
-182, 125, 182, 131, 182, 139, 239, 249, 182, 151, 214, 201, 183, 68, 183, 78,
-183, 86, 183, 91, 183, 100, 183, 109, 183, 118, 183, 129, 209, 168, 183, 142,
-241, 186, 214, 207, 180, 220, 241, 188, 184, 72, 184, 81, 184, 90, 184, 99,
-184, 108, 184, 114, 184, 121, 184, 130, 184, 136, 243, 201, 177, 202, 243, 215,
-177, 191, 185, 66, 193, 253, 185, 80, 191, 240, 243, 217, 185, 94, 243, 223,
-185, 109, 185, 115, 185, 124, 185, 131, 185, 138, 243, 236, 243, 240, 185, 155,
-186, 65, 186, 73, 186, 80, 243, 247, 186, 94, 186, 102, 186, 110, 186, 117,
-186, 125, 186, 135, 186, 142, 186, 152, 244, 166, 187, 71, 187, 80, 187, 90,
-187, 100, 187, 110, 244, 204, 187, 125, 187, 135, 187, 140, 212, 193, 193, 184,
-187, 158, 188, 66, 244, 216, 204, 199, 191, 183, 188, 92, 188, 101, 188, 109,
-188, 119, 188, 129, 188, 139, 188, 147, 188, 154, 189, 67, 189, 77, 189, 87,
-189, 97, 189, 107, 189, 117, 189, 126, 189, 136, 189, 146, 189, 156, 190, 69,
-190, 78, 190, 87, 190, 97, 190, 107, 190, 117, 190, 128, 190, 138, 190, 148,
-190, 158, 191, 71, 191, 81, 191, 91, 191, 101, 191, 111, 191, 121, 191, 131,
-191, 139, 191, 149, 191, 159, 192, 72, 192, 82, 192, 92, 192, 101, 192, 111,
-192, 121, 186, 236, 206, 179, 194, 218, 231, 164, 176, 237, 231, 171, 189, 202,
-231, 176, 231, 181, 215, 219, 192, 194, 192, 137, 184, 191, 231, 205, 201, 201,
-184, 215, 243, 191, 192, 155, 193, 64, 193, 70, 215, 239, 238, 188, 238, 192,
-193, 98, 193, 105, 193, 113, 193, 118, 244, 202, 193, 133, 193, 139, 244, 225,
-199, 204, 193, 159, 194, 69, 194, 75, 210, 171, 194, 87, 241, 232, 194, 95,
-241, 241, 194, 106, 194, 110, 241, 246, 194, 121, 190, 219, 194, 138, 194, 146,
-194, 155, 195, 66, 188, 161, 208, 164, 179, 166, 183, 190, 235, 200, 201, 246,
-195, 95, 195, 102, 202, 164, 195, 111, 210, 200, 176, 183, 195, 122, 235, 219,
-235, 228, 195, 138, 235, 227, 235, 225, 196, 64, 192, 176, 199, 187, 196, 82,
-196, 89, 196, 94, 235, 239, 196, 104, 196, 111, 196, 119, 196, 125, 196, 133,
-196, 142, 177, 219, 235, 251, 197, 66, 197, 76, 215, 212, 214, 194, 244, 167,
-197, 100, 202, 230, 203, 180, 197, 118, 189, 162, 197, 123, 244, 185, 197, 138,
-203, 210, 197, 154, 198, 66, 198, 70, 198, 75, 220, 183, 198, 85, 198, 90,
-220, 184, 198, 95, 198, 100, 198, 106, 198, 108, 198, 111, 220, 214, 198, 120,
-198, 126, 195, 175, 220, 221, 198, 140, 198, 146, 198, 154, 220, 238, 199, 64,
-199, 70, 187, 196, 220, 234, 220, 253, 199, 84, 199, 92, 199, 99, 201, 175,
-221, 183, 199, 118, 199, 124, 221, 178, 221, 210, 190, 213, 221, 202, 199, 151,
-199, 157, 183, 198, 200, 73, 221, 201, 200, 83, 200, 91, 211, 169, 200, 104,
-221, 199, 200, 120, 200, 130, 200, 139, 200, 144, 200, 151, 200, 156, 201, 65,
-221, 220, 201, 78, 203, 226, 201, 94, 201, 103, 221, 240, 208, 238, 201, 121,
-201, 128, 201, 135, 197, 238, 201, 150, 201, 158, 202, 71, 202, 78, 202, 86,
-202, 94, 202, 102, 176, 170, 202, 114, 202, 121, 202, 130, 222, 168, 202, 147,
-202, 155, 203, 64, 203, 71, 203, 80, 203, 88, 208, 189, 203, 102, 203, 110,
-203, 119, 203, 126, 222, 188, 203, 143, 203, 152, 204, 65, 204, 73, 204, 82,
-204, 90, 204, 100, 204, 108, 204, 118, 204, 126, 204, 137, 242, 175, 211, 221,
-204, 158, 205, 67, 242, 180, 205, 77, 205, 83, 205, 91, 212, 233, 205, 102,
-205, 106, 205, 114, 205, 118, 205, 123, 205, 129, 205, 137, 242, 211, 182, 234,
-242, 218, 209, 209, 195, 219, 206, 70, 206, 78, 206, 85, 206, 92, 208, 171,
-206, 105, 206, 113, 206, 120, 181, 251, 206, 133, 206, 139, 206, 146, 206, 155,
-242, 253, 207, 72, 207, 79, 243, 161, 207, 94, 207, 101, 207, 109, 243, 181,
-207, 126, 207, 135, 207, 143, 243, 182, 207, 159, 208, 70, 208, 79, 208, 87,
-208, 94, 208, 102, 208, 109, 208, 114, 203, 165, 208, 126, 176, 192, 208, 137,
-208, 145, 241, 200, 209, 64, 209, 72, 209, 80, 209, 85, 210, 225, 209, 99,
-241, 212, 209, 111, 241, 211, 209, 124, 186, 214, 241, 210, 209, 147, 209, 154,
-210, 64, 210, 73, 210, 82, 210, 92, 210, 100, 210, 109, 210, 119, 210, 129,
-210, 135, 210, 145, 210, 155, 211, 68, 211, 78, 211, 88, 185, 230, 234, 236,
-211, 101, 211, 108, 211, 114, 211, 122, 209, 212, 211, 141, 211, 151, 212, 64,
-212, 74, 212, 84, 212, 94, 212, 103, 212, 112, 212, 122, 212, 133, 212, 143,
-212, 153, 213, 65, 213, 73, 213, 82, 213, 92, 213, 102, 213, 112, 213, 122,
-213, 133, 213, 143, 213, 153, 214, 66, 214, 76, 214, 86, 214, 96, 214, 105,
-214, 115, 214, 125, 214, 135, 214, 145, 214, 155, 215, 68, 215, 78, 215, 88,
-215, 97, 215, 106, 215, 116, 215, 126, 215, 137, 215, 147, 200, 207, 210, 233,
-208, 237, 218, 172, 214, 223, 218, 180, 218, 185, 215, 158, 203, 181, 191, 206,
-204, 184, 218, 203, 195, 213, 199, 171, 192, 190, 216, 66, 216, 75, 216, 81,
-216, 90, 187, 191, 216, 105, 216, 114, 216, 121, 245, 246, 245, 249, 216, 145,
-216, 155, 217, 68, 217, 78, 217, 88, 217, 98, 217, 108, 217, 118, 217, 129,
-217, 139, 217, 149, 217, 159, 218, 72, 218, 79, 204, 176, 204, 249, 188, 214,
-234, 226, 218, 81, 216, 211, 201, 226, 215, 223, 218, 95, 244, 242, 218, 110,
-218, 118, 218, 128, 218, 137, 218, 143, 218, 148, 218, 155, 218, 160, 245, 200,
-191, 231, 219, 79, 219, 82, 219, 90, 219, 96, 219, 105, 219, 110, 245, 218,
-219, 123, 245, 229, 219, 132, 219, 140, 219, 149, 219, 157, 245, 237, 220, 72,
-220, 78, 220, 86, 245, 242, 220, 103, 220, 110, 204, 201, 220, 129, 234, 166,
-220, 148, 220, 158, 221, 71, 221, 81, 221, 91, 221, 101, 221, 111, 221, 121,
-221, 132, 221, 142, 221, 152, 222, 65, 222, 75, 222, 85, 222, 95, 194, 214,
-233, 244, 233, 251, 222, 99, 207, 189, 222, 102, 222, 109, 222, 116, 180, 239,
-194, 245, 222, 134, 212, 182, 229, 200, 202, 246, 222, 149, 229, 204, 222, 157,
-222, 160, 183, 234, 223, 74, 229, 212, 223, 85, 223, 91, 223, 95, 223, 102,
-229, 219, 223, 116, 223, 124, 223, 130, 223, 138, 223, 143, 223, 148, 211, 202,
-219, 161, 224, 64, 224, 70, 224, 75, 224, 81, 224, 86, 179, 187, 219, 177,
-224, 107, 224, 117, 224, 126, 224, 134, 224, 143, 224, 151, 224, 160, 244, 252,
-225, 72, 245, 161, 179, 234, 195, 184, 225, 87, 225, 94, 225, 98, 225, 106,
-225, 114, 225, 120, 225, 128, 225, 138, 225, 141, 225, 150, 225, 159, 226, 72,
-226, 82, 226, 92, 226, 102, 226, 112, 226, 122, 226, 133, 226, 143, 226, 153,
-227, 66, 227, 76, 227, 86, 227, 96, 227, 106, 227, 115, 227, 125, 246, 198,
-227, 145, 227, 155, 228, 68, 228, 77, 228, 87, 228, 96, 228, 106, 228, 116,
-228, 126, 228, 137, 228, 147, 228, 157, 229, 70, 229, 80, 229, 90, 229, 100,
-229, 110, 229, 119, 229, 130, 229, 140, 229, 150, 246, 202, 230, 72, 230, 82,
-230, 92, 230, 101, 230, 111, 230, 121, 230, 132, 230, 142, 230, 152, 231, 64,
-231, 73, 231, 83, 231, 93, 231, 103, 231, 113, 231, 123, 231, 134, 231, 144,
-231, 154, 232, 67, 232, 77, 232, 86, 232, 96, 232, 106, 232, 116, 232, 125,
-232, 136, 232, 146, 238, 201, 232, 150, 196, 198, 238, 214, 238, 220, 188, 216,
-238, 230, 238, 239, 205, 173, 232, 157, 189, 194, 198, 204, 179, 250, 239, 180,
-239, 187, 239, 192, 239, 196, 239, 200, 182, 198, 196, 247, 239, 217, 239, 223,
-239, 232, 239, 239, 233, 81, 233, 90, 233, 100, 233, 110, 233, 120, 233, 131,
-233, 141, 233, 151, 234, 64, 234, 74, 234, 84, 201, 193, 188, 228, 227, 204,
-227, 208, 227, 214, 184, 183, 234, 103, 234, 111, 234, 115, 184, 189, 234, 120,
-234, 128, 212, 186, 218, 238, 204, 213, 234, 153, 234, 160, 184, 244, 235, 74,
-235, 83, 235, 92, 246, 192, 188, 175, 235, 105, 235, 113, 235, 122, 235, 130,
-235, 136, 235, 142, 235, 147, 193, 216, 235, 160, 246, 175, 236, 79, 246, 178,
-236, 96, 199, 224, 236, 111, 236, 116, 236, 125, 236, 133, 236, 142, 236, 149,
-199, 202, 237, 67, 237, 75, 237, 81, 237, 91, 237, 101, 237, 111, 237, 121,
-237, 130, 237, 135, 237, 142, 237, 152, 238, 65, 238, 75, 238, 85, 238, 95,
-238, 105, 238, 115, 238, 125, 238, 136, 238, 146, 238, 156, 239, 69, 185, 203,
-190, 177, 239, 72, 209, 213, 242, 173, 239, 84, 239, 94, 239, 104, 183, 231,
-198, 174, 239, 124, 239, 133, 239, 143, 239, 153, 240, 66, 240, 74, 240, 84,
-240, 94, 240, 103, 240, 113, 240, 123, 240, 134, 240, 142, 240, 151, 210, 251,
-240, 154, 240, 158, 241, 64, 202, 215, 241, 72, 241, 80, 241, 90, 241, 100,
-241, 110, 241, 120, 241, 131, 241, 141, 241, 151, 242, 64, 242, 74, 242, 84,
-242, 94, 242, 104, 242, 114, 242, 124, 242, 135, 242, 145, 242, 155, 243, 68,
-243, 78, 243, 82, 205, 213, 194, 230, 230, 235, 201, 167, 214, 232, 243, 96,
-186, 161, 247, 196, 247, 198, 243, 121, 243, 130, 243, 138, 243, 145, 243, 153,
-247, 220, 244, 73, 244, 82, 244, 90, 244, 99, 244, 108, 198, 199, 244, 117,
-244, 124, 244, 135, 244, 145, 244, 155, 245, 68, 245, 78, 245, 88, 245, 98,
-245, 108, 245, 118, 245, 129, 245, 139, 245, 149, 245, 159, 246, 72, 246, 82,
-246, 92, 246, 102, 246, 112, 246, 122, 246, 133, 246, 143, 246, 153, 247, 66,
-247, 76, 247, 86, 247, 96, 247, 106, 247, 116, 247, 126, 247, 133, 246, 215,
-247, 141, 246, 227, 247, 145, 246, 243, 247, 150, 246, 253, 247, 167, 193, 219,
-248, 69, 248, 79, 248, 89, 248, 99, 248, 109, 248, 119, 248, 130, 248, 140,
-248, 150, 248, 160, 249, 73, 249, 83, 249, 93, 249, 103, 249, 113, 249, 123,
-249, 134, 249, 144, 249, 154, 250, 67, 250, 77, 250, 87, 250, 97, 250, 107,
-250, 117, 250, 128, 250, 138, 250, 148, 250, 158, 251, 71, 251, 81, 251, 91,
-240, 177, 240, 182, 251, 98, 240, 193, 251, 101, 240, 203, 186, 215, 251, 113,
-251, 120, 247, 228, 251, 135, 251, 143, 251, 151, 251, 160, 244, 240, 247, 226,
-252, 87, 252, 92, 247, 237, 252, 103, 252, 109, 252, 118, 252, 125, 182, 166,
-252, 140, 247, 247, 247, 248, 253, 68, 253, 73, 253, 82, 253, 90, 253, 100,
-253, 110, 253, 120, 253, 131, 246, 182, 253, 139, 185, 168, 253, 154, 170, 161,
-170, 171, 170, 181, 170, 191, 170, 201, 170, 211, 170, 221, 170, 231, 170, 241,
-170, 251, 171, 167, 171, 177, 171, 187, 171, 197, 171, 207, 171, 217, 171, 227,
-171, 237, 171, 247, 172, 163, 172, 173, 172, 183, 172, 193, 172, 203, 172, 213,
-172, 223, 172, 233, 172, 243, 172, 253, 173, 169, 173, 179, 173, 189, 173, 199,
-173, 209, 173, 219, 173, 229, 173, 239, 173, 249, 174, 165, 174, 175, 174, 185,
-174, 195, 174, 205, 174, 215, 174, 225, 174, 235, 174, 245, 175, 161, 175, 171,
-175, 181, 175, 191, 175, 201, 175, 211, 175, 221, 175, 231, 175, 241, 175, 251,
-248, 167, 248, 177, 248, 187, 248, 197, 248, 207, 248, 217, 248, 227, 248, 237,
-248, 247, 249, 163, 249, 173, 249, 183, 249, 193, 249, 203, 249, 213, 249, 223,
-249, 233, 249, 243, 249, 253, 250, 169, 250, 179, 250, 189, 250, 199, 250, 209,
-250, 219, 250, 229, 250, 239, 250, 249, 251, 165, 251, 175, 251, 185, 251, 195,
-251, 205, 251, 215, 251, 225, 251, 235, 251, 245, 252, 161, 252, 171, 252, 181,
-252, 191, 252, 201, 252, 211, 252, 221, 252, 231, 252, 241, 252, 251, 253, 167,
-253, 177, 253, 187, 253, 197, 253, 207, 253, 217, 253, 227, 253, 237, 253, 247,
-254, 163, 254, 173, 254, 183, 254, 193, 254, 203, 254, 213, 254, 223, 254, 233,
-254, 243, 254, 253, 161, 72, 161, 82, 161, 92, 161, 102, 161, 112, 161, 122,
-161, 133, 161, 143, 161, 153, 162, 66, 162, 76, 162, 86, 162, 96, 162, 106,
-162, 116, 162, 126, 162, 137, 162, 147, 162, 157, 163, 70, 163, 80, 163, 90,
-163, 100, 163, 110, 163, 120, 163, 131, 163, 141, 163, 151, 164, 64, 164, 74,
-164, 84, 164, 94, 164, 104, 164, 114, 164, 124, 164, 135, 164, 145, 164, 155,
-165, 68, 165, 78, 165, 88, 165, 98, 165, 108, 165, 118, 165, 129, 165, 139,
-165, 149, 165, 159, 166, 72, 166, 82, 166, 92, 166, 102, 166, 112, 166, 122,
-166, 133, 166, 143, 166, 153, 167, 66, 167, 76, 167, 86, 167, 96, 167, 106,
-167, 116, 167, 126, 167, 137, 167, 147, 167, 157, 162, 227, 164, 248, 165, 250,
-166, 190, 166, 236, 166, 253, 167, 202, 167, 245, 168, 150, 168, 160, 168, 237,
-168, 247, 169, 93, 169, 144, 169, 155, 169, 241, 169, 251, 254, 81, 254, 91,
-254, 101, 254, 111, 254, 121, 254, 132, 254, 142, 254, 152, 253, 156, 253, 157,
-253, 158, 253, 159, 253, 160, 254, 64, 254, 71, 254, 75, 169, 85, 166, 227,
-166, 235, 169, 109, 169, 118, 169, 129, 163, 161, 163, 171, 163, 181, 163, 191,
-163, 201, 163, 211, 163, 221, 163, 231, 163, 241, 163, 251, 161, 233, 0
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_ISO_2022_JP.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_ISO_2022_JP.java
deleted file mode 100644
index 0e1aaa6..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_ISO_2022_JP.java
+++ /dev/null
@@ -1,401 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-public class Charset_MultiByte_ISO_2022_JP extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "ISO-2022-JP";
-
- testChars = theseChars(new int[]{
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-162, 163, 165, 167, 168, 172, 176, 177, 180, 182, 215, 247, 913, 914, 924, 934,
-945, 955, 965, 1025, 1040, 1050, 1060, 1070, 1080, 1090, 1100, 8208, 8220, 8230, 8240, 8251,
-8451, 8491, 8592, 8658, 8704, 8715, 8730, 8743, 8756, 8786, 8800, 8810, 8834, 8869, 8978, 9472,
-9484, 9495, 9507, 9519, 9531, 9547, 9632, 9650, 9660, 9670, 9711, 9733, 9792, 9834, 12288, 12298,
-12308, 12353, 12363, 12373, 12383, 12393, 12403, 12413, 12423, 12433, 12443, 12453, 12463, 12473, 12483, 12493,
-12503, 12513, 12523, 12533, 19968, 19978, 19988, 19998, 20010, 20022, 20034, 20045, 20055, 20066, 20081, 20094,
-20104, 20114, 20124, 20134, 20144, 20154, 20164, 20174, 20184, 20195, 20205, 20215, 20225, 20237, 20250, 20271,
-20282, 20294, 20304, 20314, 20329, 20339, 20351, 20363, 20374, 20384, 20395, 20405, 20415, 20426, 20436, 20447,
-20462, 20472, 20485, 20495, 20505, 20515, 20525, 20537, 20547, 20559, 20570, 20581, 20594, 20605, 20621, 20632,
-20652, 20663, 20674, 20685, 20698, 20709, 20725, 20736, 20754, 20767, 20778, 20791, 20801, 20811, 20826, 20837,
-20849, 20860, 20870, 20880, 20896, 20906, 20916, 20932, 20950, 20960, 20970, 20981, 20992, 21002, 21012, 21028,
-21038, 21048, 21059, 21069, 21083, 21093, 21103, 21117, 21127, 21137, 21147, 21161, 21172, 21182, 21193, 21205,
-21215, 21234, 21246, 21256, 21269, 21280, 21290, 21304, 21315, 21325, 21335, 21350, 21360, 21371, 21398, 21408,
-21421, 21435, 21448, 21460, 21471, 21481, 21491, 21505, 21515, 21531, 21542, 21558, 21568, 21578, 21599, 21610,
-21621, 21632, 21643, 21666, 21676, 21688, 21698, 21720, 21730, 21741, 21754, 21764, 21775, 21806, 21816, 21828,
-21839, 21852, 21883, 21895, 21912, 21927, 21942, 21956, 21972, 21983, 22007, 22022, 22036, 22057, 22068, 22082,
-22092, 22107, 22120, 22132, 22144, 22154, 22164, 22176, 22190, 22204, 22216, 22227, 22238, 22254, 22265, 22275,
-22285, 22296, 22310, 22320, 22331, 22343, 22353, 22369, 22399, 22409, 22419, 22432, 22442, 22464, 22475, 22486,
-22496, 22516, 22528, 22538, 22549, 22561, 22575, 22586, 22602, 22612, 22622, 22633, 22645, 22659, 22675, 22687,
-22699, 22712, 22725, 22737, 22748, 22763, 22775, 22786, 22799, 22809, 22821, 22833, 22846, 22856, 22868, 22880,
-22890, 22900, 22913, 22925, 22937, 22947, 22962, 22974, 22985, 22995, 23013, 23030, 23041, 23057, 23068, 23081,
-23093, 23104, 23130, 23142, 23167, 23186, 23228, 23241, 23254, 23265, 23290, 23305, 23318, 23330, 23340, 23350,
-23360, 23376, 23386, 23396, 23408, 23418, 23429, 23439, 23449, 23459, 23470, 23480, 23490, 23500, 23515, 23525,
-23536, 23546, 23556, 23566, 23578, 23588, 23601, 23611, 23621, 23631, 23646, 23660, 23670, 23692, 23713, 23723,
-23734, 23749, 23769, 23784, 23798, 23815, 23825, 23835, 23849, 23883, 23900, 23913, 23923, 23938, 23948, 23965,
-23980, 23991, 24009, 24019, 24029, 24039, 24049, 24059, 24070, 24081, 24091, 24101, 24111, 24125, 24135, 24148,
-24159, 24178, 24188, 24199, 24213, 24224, 24235, 24245, 24257, 24271, 24282, 24296, 24307, 24318, 24329, 24339,
-24351, 24361, 24373, 24385, 24396, 24406, 24417, 24427, 24439, 24449, 24459, 24471, 24481, 24493, 24505, 24515,
-24525, 24535, 24548, 24560, 24571, 24590, 24601, 24613, 24623, 24634, 24646, 24656, 24666, 24676, 24687, 24705,
-24715, 24726, 24736, 24746, 24756, 24773, 24785, 24796, 24807, 24817, 24827, 24838, 24853, 24863, 24876, 24892,
-24903, 24915, 24925, 24935, 24945, 24958, 24970, 24980, 24996, 25006, 25018, 25030, 25040, 25059, 25074, 25084,
-25096, 25106, 25117, 25130, 25140, 25151, 25161, 25171, 25182, 25192, 25206, 25216, 25226, 25236, 25246, 25259,
-25269, 25282, 25292, 25303, 25313, 25324, 25334, 25345, 25356, 25369, 25383, 25402, 25417, 25429, 25447, 25458,
-25472, 25484, 25494, 25504, 25514, 25524, 25534, 25545, 25558, 25569, 25582, 25594, 25606, 25619, 25638, 25652,
-25662, 25678, 25688, 25703, 25718, 25731, 25746, 25758, 25769, 25785, 25797, 25810, 25824, 25836, 25846, 25856,
-25880, 25891, 25903, 25913, 25925, 25935, 25945, 25955, 25968, 25986, 25996, 26007, 26017, 26027, 26039, 26049,
-26059, 26071, 26081, 26092, 26106, 26118, 26131, 26143, 26157, 26172, 26185, 26205, 26215, 26228, 26241, 26254,
-26264, 26274, 26286, 26296, 26308, 26326, 26336, 26352, 26364, 26376, 26388, 26398, 26408, 26420, 26431, 26441,
-26451, 26462, 26474, 26485, 26495, 26505, 26517, 26528, 26543, 26553, 26564, 26574, 26584, 26594, 26604, 26619,
-26643, 26654, 26665, 26676, 26688, 26701, 26713, 26723, 26740, 26750, 26765, 26775, 26786, 26797, 26809, 26820,
-26834, 26847, 26862, 26873, 26884, 26894, 26905, 26915, 26928, 26941, 26954, 26964, 26974, 26986, 26996, 27006,
-27018, 27028, 27040, 27054, 27067, 27079, 27091, 27101, 27111, 27122, 27133, 27146, 27156, 27166, 27177, 27189,
-27204, 27224, 27234, 27250, 27263, 27277, 27287, 27298, 27308, 27320, 27330, 27345, 27355, 27368, 27386, 27396,
-27410, 27421, 27431, 27442, 27453, 27463, 27475, 27487, 27497, 27507, 27519, 27529, 27541, 27556, 27567, 27578,
-27589, 27602, 27615, 27627, 27656, 27667, 27683, 27700, 27710, 27726, 27738, 27752, 27762, 27773, 27784, 27794,
-27809, 27819, 27832, 27844, 27859, 27869, 27880, 27891, 27915, 27927, 27941, 27954, 27965, 27993, 28003, 28014,
-28024, 28037, 28051, 28079, 28092, 28102, 28113, 28126, 28136, 28147, 28165, 28179, 28189, 28201, 28216, 28227,
-28237, 28248, 28263, 28274, 28286, 28300, 28310, 28322, 28335, 28346, 28356, 28369, 28381, 28396, 28407, 28417,
-28431, 28448, 28459, 28472, 28485, 28500, 28511, 28525, 28536, 28546, 28558, 28577, 28593, 28608, 28628, 28639,
-28651, 28662, 28673, 28683, 28693, 28703, 28716, 28734, 28748, 28760, 28771, 28783, 28796, 28809, 28825, 28844,
-28856, 28872, 28889, 28913, 28925, 28937, 28948, 28961, 28982, 29001, 29013, 29026, 29036, 29053, 29064, 29076,
-29087, 29100, 29113, 29123, 29134, 29151, 29164, 29177, 29190, 29200, 29211, 29224, 29234, 29244, 29254, 29266,
-29277, 29287, 29298, 29309, 29319, 29330, 29344, 29356, 29366, 29378, 29390, 29401, 29417, 29431, 29450, 29462,
-29477, 29487, 29502, 29518, 29539, 29552, 29562, 29572, 29590, 29609, 29619, 29632, 29642, 29662, 29674, 29688,
-29699, 29730, 29746, 29759, 29781, 29791, 29801, 29811, 29822, 29835, 29854, 29872, 29885, 29898, 29908, 29920,
-29934, 29944, 29955, 29965, 29976, 29987, 30000, 30010, 30020, 30031, 30041, 30052, 30064, 30079, 30089, 30100,
-30115, 30129, 30140, 30151, 30162, 30174, 30185, 30195, 30206, 30217, 30239, 30256, 30267, 30278, 30290, 30300,
-30311, 30322, 30332, 30342, 30352, 30362, 30382, 30392, 30402, 30413, 30423, 30433, 30446, 30456, 30468, 30491,
-30501, 30519, 30535, 30554, 30565, 30585, 30603, 30622, 30636, 30646, 30663, 30679, 30690, 30701, 30716, 30732,
-30752, 30770, 30783, 30813, 30827, 30844, 30854, 30865, 30883, 30895, 30906, 30917, 30928, 30938, 30951, 30964,
-30977, 30990, 31001, 31014, 31034, 31047, 31059, 31069, 31080, 31095, 31105, 31117, 31133, 31143, 31155, 31165,
-31177, 31189, 31199, 31209, 31227, 31240, 31252, 31263, 31278, 31291, 31302, 31312, 31329, 31339, 31350, 31361,
-31378, 31391, 31401, 31414, 31427, 31437, 31449, 31459, 31469, 31480, 31490, 31503, 31513, 31525, 31539, 31557,
-31567, 31581, 31591, 31601, 31622, 31634, 31644, 31658, 31668, 31680, 31691, 31709, 31721, 31731, 31744, 31757,
-31767, 31777, 31787, 31799, 31811, 31821, 31832, 31844, 31859, 31870, 31881, 31893, 31903, 31915, 31929, 31941,
-31954, 31964, 31975, 31986, 31998, 32010, 32020, 32032, 32043, 32053, 32063, 32075, 32086, 32097, 32110, 32121,
-32137, 32147, 32159, 32171, 32181, 32191, 32202, 32213, 32224, 32236, 32251, 32261, 32274, 32286, 32299, 32309,
-32321, 32331, 32341, 32358, 32368, 32379, 32392, 32402, 32412, 32566, 32581, 32592, 32607, 32617, 32629, 32642,
-32652, 32666, 32676, 32686, 32696, 32709, 32722, 32736, 32747, 32761, 32771, 32784, 32796, 32808, 32819, 32829,
-32842, 32854, 32865, 32879, 32889, 32900, 32915, 32925, 32937, 32948, 32963, 32974, 32985, 32996, 33007, 33020,
-33030, 33050, 33065, 33075, 33086, 33099, 33109, 33119, 33131, 33144, 33154, 33167, 33178, 33188, 33200, 33210,
-33222, 33233, 33247, 33258, 33268, 33278, 33288, 33298, 33308, 33321, 33331, 33344, 33368, 33378, 33390, 33400,
-33419, 33433, 33445, 33455, 33465, 33477, 33489, 33499, 33509, 33521, 33531, 33541, 33558, 33571, 33583, 33593,
-33605, 33615, 33651, 33669, 33683, 33694, 33704, 33717, 33729, 33740, 33750, 33760, 33771, 33783, 33795, 33805,
-33824, 33834, 33845, 33862, 33879, 33889, 33899, 33909, 33922, 33936, 33948, 33965, 33976, 33988, 34000, 34010,
-34028, 34044, 34054, 34065, 34079, 34092, 34109, 34120, 34133, 34147, 34157, 34167, 34180, 34192, 34203, 34214,
-34233, 34249, 34261, 34276, 34295, 34306, 34323, 34338, 34349, 34367, 34381, 34394, 34407, 34417, 34427, 34442,
-34453, 34467, 34479, 34500, 34510, 34521, 34532, 34542, 34552, 34562, 34573, 34584, 34597, 34612, 34623, 34633,
-34643, 34655, 34666, 34676, 34687, 34701, 34719, 34731, 34746, 34756, 34768, 34784, 34799, 34809, 34821, 34831,
-34849, 34865, 34875, 34886, 34898, 34909, 34920, 34930, 34941, 34952, 34962, 34974, 34987, 34997, 35007, 35023,
-35033, 35048, 35058, 35068, 35079, 35090, 35101, 35114, 35126, 35137, 35148, 35158, 35168, 35178, 35188, 35198,
-35208, 35219, 35233, 35244, 35258, 35282, 35292, 35302, 35316, 35328, 35338, 35350, 35363, 35373, 35386, 35398,
-35408, 35419, 35430, 35440, 35452, 35463, 35473, 35486, 35496, 35506, 35516, 35527, 35538, 35548, 35558, 35569,
-35582, 35596, 35606, 35616, 35627, 35641, 35657, 35670, 35686, 35696, 35709, 35722, 35734, 35895, 35905, 35916,
-35930, 35946, 35960, 35970, 35980, 35992, 36002, 36012, 36022, 36032, 36042, 36058, 36068, 36090, 36100, 36111,
-36196, 36208, 36225, 36249, 36259, 36275, 36286, 36299, 36310, 36321, 36331, 36341, 36351, 36361, 36381, 36394,
-36404, 36418, 36428, 36441, 36451, 36466, 36476, 36487, 36497, 36513, 36523, 36542, 36552, 36562, 36575, 36587,
-36600, 36611, 36626, 36636, 36646, 36659, 36670, 36681, 36695, 36705, 36763, 36775, 36785, 36795, 36805, 36817,
-36834, 36845, 36855, 36865, 36875, 36885, 36895, 36910, 36920, 36930, 36941, 36952, 36963, 36973, 36983, 36993,
-37007, 37027, 37039, 37057, 37070, 37083, 37096, 37109, 37122, 37138, 37165, 37193, 37204, 37218, 37228, 37239,
-37250, 37261, 37271, 37282, 37295, 37306, 37318, 37328, 37339, 37350, 37365, 37375, 37389, 37406, 37417, 37428,
-37439, 37449, 37463, 37474, 37489, 37502, 37521, 37531, 37549, 37559, 37583, 37604, 37618, 37628, 37638, 37648,
-37658, 37670, 37682, 37700, 37716, 37728, 37740, 37756, 37772, 37782, 37799, 37817, 37827, 37840, 37853, 37864,
-37891, 37904, 37914, 37931, 37941, 37953, 37969, 37979, 37994, 38005, 38015, 38263, 38274, 38287, 38297, 38307,
-38317, 38329, 38339, 38349, 38360, 38370, 38428, 38440, 38450, 38463, 38475, 38491, 38501, 38512, 38522, 38533,
-38543, 38553, 38563, 38576, 38587, 38597, 38609, 38619, 38632, 38642, 38656, 38666, 38678, 38692, 38704, 38717,
-38728, 38738, 38748, 38758, 38769, 38780, 38790, 38800, 38812, 38822, 38835, 38851, 38867, 38893, 38907, 38917,
-38927, 38938, 38948, 38964, 38982, 38996, 39006, 39019, 39080, 39094, 39107, 39131, 39145, 39156, 39166, 39177,
-39187, 39197, 39208, 39229, 39241, 39253, 39318, 39333, 39347, 39361, 39376, 39387, 39405, 39416, 39429, 39439,
-39449, 39464, 39479, 39490, 39501, 39511, 39522, 39592, 39608, 39620, 39631, 39646, 39658, 39668, 39686, 39704,
-39714, 39726, 39739, 39749, 39759, 39770, 39791, 39811, 39822, 39839, 39850, 39860, 39872, 39882, 39892, 39905,
-39920, 39940, 39952, 39963, 39973, 39983, 39993, 40006, 40018, 40032, 40054, 40165, 40176, 40195, 40206, 40219,
-40230, 40251, 40262, 40272, 40284, 40300, 40314, 40327, 40346, 40356, 40367, 40378, 40388, 40399, 40409, 40422,
-40434, 40445, 40474, 40565, 40575, 40587, 40597, 40607, 40617, 40632, 40644, 40654, 40664, 40677, 40687, 40697,
-40711, 40723, 40736, 40748, 40763, 40778, 40788, 40799, 40810, 40822, 40845, 40860, 65281, 65291, 65301, 65311,
-65321, 65331, 65341, 65351, 65361, 65371, 65381, 65391, 65401, 65411, 65421, 65431, 65507
- });
-
- testBytes = theseBytes(new int[]{
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-27, 36, 66, 33, 113, 33, 114, 27, 40, 74, 92, 27, 36, 66, 33, 120,
-33, 47, 34, 76, 33, 107, 33, 94, 33, 45, 34, 121, 33, 95, 33, 96,
-38, 33, 38, 34, 38, 44, 38, 53, 38, 65, 38, 75, 38, 84, 39, 39,
-39, 33, 39, 44, 39, 54, 39, 64, 39, 90, 39, 100, 39, 110, 33, 62,
-33, 72, 33, 68, 34, 115, 34, 40, 33, 110, 34, 114, 34, 43, 34, 77,
-34, 79, 34, 59, 34, 101, 34, 74, 33, 104, 34, 98, 33, 98, 34, 99,
-34, 62, 34, 93, 34, 94, 40, 33, 40, 35, 40, 49, 40, 50, 40, 56,
-40, 53, 40, 54, 34, 35, 34, 37, 34, 39, 34, 33, 34, 126, 33, 122,
-33, 106, 34, 118, 33, 33, 33, 84, 33, 76, 36, 33, 36, 43, 36, 53,
-36, 63, 36, 73, 36, 83, 36, 93, 36, 103, 36, 113, 33, 43, 37, 37,
-37, 47, 37, 57, 37, 67, 37, 77, 37, 87, 37, 97, 37, 107, 37, 117,
-48, 108, 62, 101, 51, 110, 62, 103, 80, 36, 80, 38, 80, 41, 70, 99,
-62, 104, 86, 38, 77, 112, 52, 37, 77, 61, 56, 95, 48, 33, 75, 114,
-80, 55, 63, 77, 80, 60, 80, 58, 73, 85, 66, 101, 80, 65, 80, 67,
-52, 107, 56, 96, 50, 113, 71, 108, 59, 71, 67, 34, 58, 52, 80, 69,
-80, 80, 50, 66, 59, 72, 78, 99, 80, 85, 54, 34, 85, 37, 63, 47,
-74, 88, 61, 83, 80, 87, 80, 88, 61, 36, 74, 112, 80, 102, 96, 71,
-56, 117, 74, 111, 79, 65, 55, 112, 80, 112, 74, 80, 80, 118, 55, 114,
-60, 69, 53, 54, 75, 53, 59, 49, 58, 69, 61, 125, 81, 36, 70, 47,
-78, 61, 81, 39, 81, 44, 53, 55, 60, 116, 61, 126, 77, 37, 81, 54,
-48, 116, 57, 110, 69, 94, 70, 126, 54, 38, 55, 115, 49, 95, 102, 110,
-52, 39, 81, 81, 58, 99, 64, 40, 82, 69, 81, 92, 70, 100, 81, 97,
-69, 97, 52, 41, 81, 101, 72, 61, 81, 105, 55, 116, 68, 102, 65, 48,
-57, 100, 71, 109, 73, 123, 81, 119, 55, 96, 81, 125, 78, 79, 61, 117,
-79, 43, 51, 47, 74, 89, 70, 48, 74, 103, 55, 46, 56, 123, 82, 51,
-82, 56, 62, 34, 72, 91, 82, 62, 64, 105, 82, 68, 70, 110, 55, 53,
-48, 117, 82, 74, 82, 77, 82, 78, 49, 94, 53, 110, 75, 116, 61, 71,
-82, 87, 67, 33, 49, 38, 82, 94, 49, 37, 55, 47, 72, 93, 82, 101,
-82, 96, 57, 112, 82, 108, 60, 118, 82, 106, 82, 114, 58, 112, 82, 120,
-82, 123, 82, 121, 83, 34, 83, 38, 83, 47, 83, 45, 83, 46, 49, 52,
-83, 41, 83, 52, 83, 57, 66, 111, 76, 100, 83, 53, 83, 65, 83, 73,
-83, 67, 55, 118, 49, 68, 83, 78, 83, 81, 83, 77, 83, 83, 67, 50,
-83, 82, 50, 94, 83, 92, 49, 61, 65, 57, 51, 122, 52, 111, 74, 46,
-83, 102, 83, 103, 83, 105, 83, 104, 83, 108, 83, 112, 83, 116, 83, 119,
-50, 115, 83, 121, 83, 122, 74, 96, 84, 35, 84, 37, 84, 41, 67, 79,
-84, 45, 54, 81, 57, 35, 84, 51, 84, 52, 84, 53, 84, 54, 84, 55,
-84, 58, 84, 49, 75, 100, 84, 66, 73, 86, 62, 125, 75, 89, 84, 65,
-66, 68, 84, 72, 116, 33, 58, 102, 50, 116, 69, 99, 58, 73, 49, 118,
-63, 80, 54, 45, 74, 104, 84, 82, 84, 83, 84, 87, 84, 89, 84, 91,
-84, 96, 59, 78, 68, 91, 84, 105, 50, 70, 61, 72, 84, 110, 60, 58,
-84, 115, 70, 96, 75, 91, 84, 123, 67, 37, 69, 91, 85, 34, 85, 43,
-76, 47, 85, 38, 85, 39, 62, 42, 59, 80, 64, 43, 49, 56, 48, 40,
-48, 82, 85, 48, 85, 49, 74, 90, 85, 55, 85, 52, 58, 39, 73, 88,
-76, 59, 71, 94, 85, 60, 60, 59, 85, 69, 67, 100, 85, 70, 52, 114,
-85, 74, 62, 110, 68, 92, 85, 78, 85, 82, 59, 82, 85, 85, 56, 73,
-85, 89, 85, 94, 66, 112, 57, 40, 67, 104, 64, 107, 53, 92, 85, 98,
-60, 100, 73, 89, 52, 50, 85, 108, 85, 110, 59, 123, 60, 77, 70, 51,
-62, 48, 76, 96, 61, 34, 63, 44, 53, 111, 86, 34, 66, 48, 86, 36,
-86, 39, 86, 41, 50, 44, 86, 45, 86, 47, 86, 50, 86, 53, 50, 101,
-69, 103, 63, 114, 86, 66, 86, 65, 74, 120, 86, 75, 86, 63, 63, 115,
-86, 77, 86, 81, 86, 58, 86, 83, 86, 84, 86, 88, 86, 90, 86, 92,
-64, 110, 57, 42, 56, 74, 52, 44, 72, 65, 86, 102, 86, 103, 63, 99,
-66, 83, 75, 57, 86, 115, 86, 111, 86, 112, 52, 51, 77, 68, 72, 95,
-68, 108, 86, 121, 56, 75, 48, 67, 86, 122, 86, 126, 87, 36, 87, 40,
-87, 44, 87, 48, 87, 50, 53, 93, 68, 111, 87, 56, 68, 37, 87, 59,
-87, 61, 87, 65, 87, 68, 68, 38, 87, 71, 64, 44, 78, 39, 70, 64,
-56, 102, 87, 84, 69, 48, 63, 52, 71, 38, 59, 86, 87, 88, 88, 45,
-87, 87, 87, 99, 87, 96, 53, 94, 54, 49, 87, 106, 87, 113, 54, 50,
-87, 107, 87, 117, 66, 41, 87, 122, 88, 39, 88, 35, 77, 42, 48, 45,
-88, 44, 62, 112, 79, 71, 64, 75, 87, 124, 88, 61, 88, 60, 88, 52,
-88, 51, 52, 54, 88, 71, 88, 70, 88, 64, 88, 88, 88, 87, 55, 69,
-88, 85, 77, 93, 88, 96, 88, 94, 74, 48, 88, 99, 88, 107, 88, 106,
-50, 123, 88, 112, 68, 40, 88, 118, 88, 121, 50, 124, 108, 67, 89, 35,
-66, 87, 75, 60, 72, 98, 66, 71, 89, 42, 89, 46, 73, 94, 53, 59,
-71, 68, 89, 56, 66, 114, 72, 100, 68, 113, 89, 68, 89, 66, 89, 57,
-51, 72, 51, 103, 59, 34, 59, 125, 89, 72, 53, 115, 89, 75, 68, 114,
-66, 42, 74, 97, 74, 123, 55, 126, 89, 87, 62, 56, 89, 85, 78, 43,
-65, 60, 68, 79, 89, 97, 89, 102, 77, 44, 48, 46, 52, 120, 77, 73,
-89, 108, 89, 109, 89, 110, 89, 107, 58, 113, 89, 119, 69, 38, 89, 116,
-89, 118, 55, 98, 59, 53, 70, 53, 89, 124, 51, 73, 90, 35, 90, 34,
-90, 43, 53, 60, 90, 49, 90, 53, 90, 55, 90, 59, 59, 89, 50, 126,
-56, 78, 73, 82, 54, 53, 59, 54, 63, 116, 90, 76, 73, 76, 69, 77,
-48, 54, 90, 81, 90, 82, 90, 85, 64, 123, 52, 122, 90, 92, 61, 92,
-50, 34, 58, 43, 48, 87, 64, 49, 62, 60, 67, 107, 90, 105, 90, 108,
-90, 110, 64, 50, 54, 71, 90, 117, 90, 120, 68, 42, 74, 107, 91, 34,
-91, 33, 91, 35, 91, 37, 91, 41, 82, 88, 55, 110, 58, 115, 91, 46,
-76, 90, 75, 81, 91, 51, 63, 121, 60, 93, 91, 57, 91, 66, 53, 79,
-72, 68, 91, 62, 75, 109, 79, 72, 56, 79, 91, 84, 74, 65, 91, 85,
-68, 83, 91, 82, 91, 75, 58, 58, 64, 114, 91, 89, 91, 91, 64, 115,
-91, 92, 91, 93, 91, 98, 91, 99, 91, 111, 91, 117, 91, 116, 57, 60,
-62, 63, 91, 104, 91, 110, 52, 126, 75, 64, 69, 111, 63, 57, 92, 42,
-92, 38, 68, 71, 63, 122, 92, 48, 92, 63, 92, 61, 77, 76, 92, 56,
-92, 65, 92, 68, 92, 60, 92, 57, 58, 103, 79, 49, 92, 85, 92, 70,
-92, 80, 116, 34, 92, 74, 92, 79, 92, 97, 92, 96, 65, 101, 92, 104,
-92, 102, 92, 100, 56, 34, 62, 65, 92, 109, 53, 76, 92, 115, 92, 111,
-51, 96, 92, 122, 93, 33, 92, 125, 93, 40, 93, 38, 93, 37, 93, 42,
-54, 123, 72, 39, 93, 50, 77, 115, 93, 51, 49, 53, 50, 36, 77, 95,
-54, 86, 93, 60, 52, 63, 93, 67, 74, 98, 58, 80, 93, 71, 61, 94,
-93, 77, 93, 79, 93, 82, 59, 38, 53, 35, 70, 71, 93, 91, 93, 93,
-93, 97, 93, 98, 93, 102, 63, 101, 72, 69, 72, 70, 49, 120, 93, 113,
-53, 98, 53, 37, 68, 64, 93, 115, 75, 87, 75, 119, 74, 40, 93, 117,
-93, 119, 93, 123, 67, 109, 49, 75, 77, 78, 64, 118, 68, 69, 61, 39,
-94, 42, 94, 54, 94, 49, 73, 98, 63, 59, 94, 58, 94, 50, 51, 54,
-78, 67, 94, 66, 61, 74, 94, 68, 94, 70, 61, 95, 64, 54, 55, 76,
-94, 97, 50, 57, 94, 98, 94, 92, 94, 90, 62, 69, 77, 47, 94, 83,
-79, 81, 72, 46, 61, 96, 48, 110, 94, 106, 69, 46, 94, 107, 51, 106,
-66, 108, 94, 118, 95, 35, 53, 121, 79, 51, 71, 121, 76, 33, 65, 50,
-52, 67, 55, 105, 51, 99, 95, 44, 95, 38, 95, 45, 95, 48, 95, 54,
-69, 67, 55, 99, 95, 62, 95, 59, 77, 116, 111, 105, 95, 71, 95, 68,
-73, 78, 95, 79, 64, 37, 95, 81, 94, 117, 70, 103, 95, 84, 69, 116,
-60, 94, 79, 39, 95, 85, 95, 89, 95, 90, 78, 117, 95, 96, 95, 88,
-95, 98, 95, 97, 49, 107, 76, 53, 65, 51, 78, 123, 95, 102, 95, 105,
-95, 108, 64, 122, 95, 103, 77, 80, 61, 79, 95, 114, 95, 116, 71, 51,
-95, 121, 83, 91, 95, 123, 96, 33, 71, 122, 96, 36, 96, 37, 96, 38,
-96, 42, 96, 44, 96, 47, 68, 45, 76, 70, 75, 82, 64, 55, 56, 35,
-96, 54, 96, 55, 53, 62, 56, 36, 62, 117, 54, 56, 96, 64, 65, 64,
-60, 109, 96, 70, 96, 73, 96, 75, 96, 80, 96, 78, 96, 81, 96, 82,
-61, 67, 96, 88, 96, 92, 56, 60, 54, 106, 52, 97, 96, 94, 96, 97,
-59, 57, 96, 100, 55, 62, 96, 105, 53, 101, 66, 118, 96, 106, 96, 109,
-96, 108, 96, 110, 96, 114, 58, 60, 96, 119, 96, 120, 96, 121, 52, 68,
-60, 37, 96, 123, 96, 125, 97, 33, 97, 37, 97, 41, 97, 44, 97, 48,
-52, 69, 59, 58, 69, 68, 68, 46, 97, 55, 48, 90, 78, 49, 97, 63,
-48, 91, 53, 38, 97, 73, 97, 75, 97, 79, 97, 87, 97, 86, 62, 73,
-97, 90, 97, 93, 65, 105, 97, 101, 97, 94, 97, 104, 97, 105, 97, 112,
-97, 113, 97, 116, 76, 126, 97, 117, 97, 124, 98, 33, 98, 36, 51, 39,
-59, 41, 98, 45, 72, 105, 98, 48, 98, 51, 98, 52, 69, 112, 98, 56,
-76, 92, 65, 106, 98, 64, 98, 70, 98, 68, 98, 71, 98, 73, 98, 74,
-98, 78, 98, 81, 98, 83, 98, 86, 61, 86, 98, 88, 98, 94, 98, 96,
-76, 112, 67, 59, 98, 101, 98, 102, 98, 105, 75, 36, 57, 92, 62, 75,
-78, 50, 98, 111, 98, 110, 72, 106, 98, 114, 98, 117, 51, 78, 98, 124,
-72, 88, 99, 34, 99, 33, 99, 36, 62, 76, 65, 67, 99, 40, 98, 104,
-60, 40, 53, 64, 99, 49, 61, 75, 73, 60, 69, 120, 54, 88, 50, 82,
-99, 53, 99, 54, 99, 58, 54, 89, 99, 61, 99, 62, 65, 69, 67, 97,
-48, 92, 99, 67, 76, 45, 99, 72, 60, 111, 99, 75, 75, 84, 48, 44,
-99, 81, 51, 79, 53, 102, 70, 77, 67, 98, 55, 34, 99, 93, 99, 96,
-51, 118, 99, 103, 99, 107, 61, 87, 99, 113, 81, 63, 99, 115, 99, 116,
-99, 121, 63, 90, 99, 119, 100, 38, 72, 53, 100, 56, 100, 42, 100, 44,
-74, 79, 100, 54, 100, 51, 67, 61, 100, 62, 64, 97, 100, 58, 100, 64,
-100, 65, 100, 74, 100, 71, 100, 77, 100, 76, 52, 74, 100, 84, 100, 83,
-100, 87, 64, 82, 100, 92, 100, 94, 74, 70, 76, 98, 74, 52, 71, 116,
-48, 64, 100, 104, 100, 111, 100, 114, 100, 117, 100, 118, 78, 72, 100, 122,
-53, 106, 101, 36, 61, 99, 65, 71, 59, 103, 101, 42, 101, 41, 101, 38,
-101, 45, 77, 109, 101, 49, 56, 40, 101, 53, 101, 52, 101, 70, 101, 64,
-101, 61, 76, 74, 54, 91, 101, 110, 68, 121, 76, 75, 101, 76, 101, 79,
-101, 83, 60, 74, 75, 37, 101, 92, 72, 75, 55, 82, 65, 54, 101, 90,
-55, 43, 101, 108, 101, 114, 101, 117, 101, 124, 52, 76, 102, 33, 102, 37,
-102, 42, 102, 45, 71, 77, 102, 48, 102, 53, 102, 57, 55, 50, 102, 62,
-102, 64, 102, 66, 61, 44, 63, 105, 52, 101, 102, 75, 57, 77, 66, 81,
-102, 83, 102, 85, 60, 42, 67, 63, 102, 88, 64, 59, 65, 111, 78, 126,
-102, 100, 102, 103, 102, 107, 52, 78, 56, 42, 58, 104, 48, 95, 66, 91,
-102, 114, 48, 125, 102, 120, 103, 38, 64, 72, 53, 83, 102, 123, 71, 62,
-103, 35, 102, 126, 79, 83, 103, 53, 60, 112, 68, 50, 103, 48, 57, 81,
-73, 102, 103, 51, 103, 56, 103, 63, 50, 50, 103, 66, 103, 71, 60, 43,
-67, 87, 103, 76, 54, 61, 80, 48, 61, 88, 103, 85, 103, 88, 103, 89,
-103, 91, 103, 96, 58, 49, 103, 103, 48, 114, 73, 103, 51, 41, 63, 68,
-54, 92, 52, 35, 49, 113, 50, 87, 60, 99, 49, 81, 103, 120, 51, 125,
-104, 35, 104, 52, 104, 42, 104, 39, 104, 41, 49, 65, 104, 58, 104, 46,
-103, 118, 52, 80, 104, 62, 104, 57, 104, 71, 54, 93, 62, 84, 104, 74,
-104, 65, 104, 72, 104, 68, 104, 76, 104, 78, 104, 84, 104, 98, 104, 94,
-67, 120, 73, 114, 104, 89, 48, 42, 104, 92, 61, 47, 73, 71, 104, 90,
-62, 120, 67, 95, 104, 108, 104, 107, 75, 41, 104, 122, 104, 81, 74, 78,
-104, 119, 104, 118, 74, 67, 104, 126, 105, 36, 104, 124, 105, 43, 105, 49,
-71, 118, 105, 51, 105, 45, 65, 38, 105, 55, 105, 52, 105, 57, 70, 35,
-61, 115, 105, 34, 105, 63, 105, 68, 77, 118, 105, 71, 105, 72, 53, 117,
-105, 76, 105, 77, 48, 58, 50, 99, 59, 61, 105, 79, 105, 85, 105, 86,
-51, 66, 51, 63, 72, 58, 72, 90, 66, 125, 75, 42, 105, 107, 67, 88,
-105, 114, 105, 110, 105, 111, 64, 102, 106, 33, 105, 118, 106, 35, 105, 122,
-71, 104, 77, 59, 106, 38, 106, 46, 77, 102, 106, 47, 106, 44, 106, 54,
-106, 52, 51, 42, 106, 36, 106, 55, 106, 66, 106, 67, 106, 71, 61, 48,
-106, 74, 62, 87, 73, 61, 106, 85, 106, 83, 55, 54, 106, 88, 106, 81,
-72, 111, 106, 84, 106, 95, 78, 34, 106, 101, 106, 107, 106, 108, 106, 105,
-74, 35, 75, 43, 106, 124, 106, 116, 106, 121, 106, 118, 106, 123, 50, 40,
-106, 125, 107, 36, 107, 38, 107, 40, 107, 42, 107, 44, 107, 46, 107, 49,
-107, 52, 51, 81, 107, 57, 63, 40, 107, 60, 56, 64, 63, 86, 107, 63,
-55, 109, 64, 95, 63, 71, 107, 73, 58, 62, 107, 71, 59, 110, 53, 77,
-107, 75, 56, 88, 107, 84, 56, 108, 107, 82, 50, 93, 53, 67, 67, 76,
-78, 74, 68, 53, 68, 124, 107, 97, 66, 122, 107, 104, 107, 108, 107, 111,
-107, 115, 54, 96, 107, 122, 107, 123, 55, 89, 53, 68, 108, 37, 90, 78,
-108, 43, 67, 43, 108, 47, 108, 50, 70, 90, 57, 107, 108, 56, 108, 58,
-75, 70, 108, 66, 57, 87, 64, 85, 108, 74, 50, 108, 66, 49, 108, 79,
-108, 77, 108, 81, 108, 83, 108, 87, 64, 86, 65, 118, 108, 99, 108, 100,
-60, 113, 66, 45, 108, 102, 108, 109, 108, 106, 64, 87, 108, 111, 65, 41,
-108, 117, 108, 116, 108, 118, 109, 41, 108, 125, 108, 122, 109, 35, 109, 38,
-109, 42, 109, 45, 109, 46, 109, 48, 109, 54, 109, 58, 63, 72, 109, 63,
-109, 65, 56, 46, 70, 112, 109, 71, 60, 52, 51, 83, 109, 76, 109, 79,
-109, 83, 109, 84, 109, 89, 109, 91, 109, 94, 55, 37, 63, 73, 82, 33,
-63, 43, 68, 84, 63, 87, 54, 97, 109, 107, 69, 51, 76, 66, 65, 119,
-109, 121, 109, 116, 66, 46, 66, 97, 48, 111, 63, 107, 74, 87, 110, 41,
-56, 47, 65, 120, 65, 43, 110, 50, 110, 54, 70, 97, 110, 56, 48, 106,
-79, 58, 110, 62, 73, 116, 77, 57, 110, 63, 110, 64, 69, 34, 70, 83,
-63, 108, 63, 93, 61, 55, 57, 115, 110, 78, 66, 105, 72, 48, 110, 79,
-110, 81, 110, 85, 72, 80, 110, 90, 110, 94, 75, 85, 110, 96, 110, 99,
-70, 95, 110, 98, 111, 79, 78, 107, 110, 111, 110, 107, 110, 105, 72, 45,
-57, 91, 75, 72, 65, 45, 110, 117, 65, 44, 110, 121, 110, 119, 61, 123,
-73, 70, 57, 93, 59, 44, 63, 109, 111, 35, 54, 83, 79, 63, 110, 125,
-68, 87, 111, 41, 55, 45, 111, 42, 51, 121, 58, 63, 51, 59, 111, 49,
-111, 55, 111, 57, 111, 56, 111, 52, 111, 63, 111, 65, 111, 60, 111, 67,
-111, 68, 111, 71, 52, 85, 111, 74, 111, 78, 111, 81, 111, 88, 68, 57,
-111, 89, 49, 60, 111, 95, 51, 85, 111, 99, 111, 102, 111, 106, 111, 107,
-70, 46, 111, 115, 73, 108, 111, 117, 75, 73, 48, 36, 111, 123, 74, 69,
-52, 89, 49, 34, 56, 49, 54, 121, 63, 111, 55, 100, 78, 89, 112, 46,
-64, 73, 50, 109, 59, 40, 63, 119, 49, 43, 49, 64, 60, 123, 78, 110,
-112, 67, 112, 69, 112, 71, 112, 73, 112, 77, 64, 68, 112, 80, 112, 83,
-112, 87, 112, 90, 112, 93, 112, 96, 112, 97, 112, 99, 112, 101, 112, 103,
-52, 90, 112, 108, 49, 36, 57, 96, 112, 114, 55, 91, 112, 117, 49, 80,
-112, 121, 52, 105, 78, 96, 112, 124, 73, 119, 113, 39, 113, 41, 72, 116,
-113, 43, 48, 59, 62, 126, 113, 46, 50, 110, 113, 51, 52, 91, 113, 57,
-113, 60, 113, 67, 60, 115, 113, 70, 67, 90, 71, 125, 67, 115, 113, 75,
-113, 79, 113, 84, 113, 87, 113, 86, 113, 89, 66, 77, 113, 91, 113, 93,
-113, 98, 113, 100, 113, 102, 57, 124, 51, 60, 63, 113, 113, 112, 113, 116,
-72, 49, 113, 124, 114, 34, 114, 35, 114, 38, 114, 45, 100, 120, 76, 37,
-114, 50, 53, 123, 79, 37, 114, 57, 48, 62, 114, 61, 75, 110, 114, 64,
-114, 65, 114, 66, 114, 75, 114, 76, 114, 80, 114, 90, 79, 76, 114, 92,
-114, 93, 48, 115, 51, 111, 114, 99, 75, 112, 114, 102, 114, 104, 68, 59,
-114, 108, 114, 112, 50, 42, 49, 117, 114, 115, 57, 99, 114, 125, 115, 37,
-49, 45, 75, 50, 115, 44, 115, 41, 115, 45, 115, 46, 114, 116, 115, 53,
-115, 49, 115, 55, 115, 57, 115, 60, 79, 73, 115, 63, 115, 64, 115, 67,
-60, 47, 115, 72, 115, 75, 78, 91, 115, 79, 115, 80, 50, 43, 115, 85,
-96, 84, 115, 93, 115, 95, 115, 99, 115, 103, 56, 93, 65, 77, 115, 108,
-73, 33, 115, 110, 115, 112, 115, 114, 115, 120, 115, 123, 78, 54, 115, 125,
-33, 42, 33, 92, 35, 53, 33, 41, 35, 73, 35, 83, 33, 79, 35, 103,
-35, 113, 33, 80, 27, 40, 73, 37, 47, 57, 67, 77, 87, 27, 36, 66,
-33, 49
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic() throws CharacterCodingException {
- super.test_CodecDynamic();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Decode() throws CharacterCodingException {
- super.test_Decode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Encode() throws CharacterCodingException {
- super.test_Encode();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16.java
deleted file mode 100644
index 7457a87..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-/** @hide
- * SEE correspondig_Android test class:
- */
-
-public class Charset_MultiByte_UTF_16 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "UTF-16";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
-176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
-192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
-208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
-224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
-240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
-896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
-1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
-2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
-2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
-3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
-4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
-4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
-5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
-6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
-6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
-7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
-7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
-8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
-9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
-9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
-10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
-11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
-11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
-12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
-13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
-13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
-14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
-14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
-15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
-16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
-16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
-17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
-18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
-18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
-19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
-20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
-20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
-21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
-22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
-22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
-23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
-23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
-24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
-25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
-25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
-26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
-27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
-27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
-28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
-29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
-29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
-30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
-30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
-31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
-32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
-32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
-33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
-34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
-34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
-35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
-36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
-36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
-37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
-38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
-38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
-39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
-39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
-40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
-41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
-41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
-42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
-43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
-43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
-44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
-45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
-45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
-46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
-46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
-47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
-48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
-48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
-49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
-50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
-50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
-51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
-52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
-52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
-53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
-54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
-54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
-57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
-57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
-58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
-59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
-59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
-60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
-61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
-61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
-62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
-63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
-63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
-64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
-65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
- });
-
- testBytes = theseBytes(new int[]{
-254, 255, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6,
-0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14,
-0, 15, 0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22,
-0, 23, 0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30,
-0, 31, 0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38,
-0, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46,
-0, 47, 0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54,
-0, 55, 0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62,
-0, 63, 0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70,
-0, 71, 0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78,
-0, 79, 0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86,
-0, 87, 0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94,
-0, 95, 0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102,
-0, 103, 0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110,
-0, 111, 0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118,
-0, 119, 0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126,
-0, 127, 0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134,
-0, 135, 0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142,
-0, 143, 0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150,
-0, 151, 0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158,
-0, 159, 0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166,
-0, 167, 0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174,
-0, 175, 0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182,
-0, 183, 0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190,
-0, 191, 0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198,
-0, 199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206,
-0, 207, 0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214,
-0, 215, 0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222,
-0, 223, 0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230,
-0, 231, 0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238,
-0, 239, 0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246,
-0, 247, 0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254,
-0, 255, 1, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240,
-2, 24, 2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 3, 8, 3, 48,
-3, 88, 3, 128, 3, 168, 3, 208, 3, 248, 4, 32, 4, 72, 4, 112,
-4, 152, 4, 192, 4, 232, 5, 16, 5, 56, 5, 96, 5, 136, 5, 176,
-5, 216, 6, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240,
-7, 24, 7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 8, 8, 8, 48,
-8, 88, 8, 128, 8, 168, 8, 208, 8, 248, 9, 32, 9, 72, 9, 112,
-9, 152, 9, 192, 9, 232, 10, 16, 10, 56, 10, 96, 10, 136, 10, 176,
-10, 216, 11, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240,
-12, 24, 12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 13, 8, 13, 48,
-13, 88, 13, 128, 13, 168, 13, 208, 13, 248, 14, 32, 14, 72, 14, 112,
-14, 152, 14, 192, 14, 232, 15, 16, 15, 56, 15, 96, 15, 136, 15, 176,
-15, 216, 16, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240,
-17, 24, 17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 18, 8, 18, 48,
-18, 88, 18, 128, 18, 168, 18, 208, 18, 248, 19, 32, 19, 72, 19, 112,
-19, 152, 19, 192, 19, 232, 20, 16, 20, 56, 20, 96, 20, 136, 20, 176,
-20, 216, 21, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240,
-22, 24, 22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 23, 8, 23, 48,
-23, 88, 23, 128, 23, 168, 23, 208, 23, 248, 24, 32, 24, 72, 24, 112,
-24, 152, 24, 192, 24, 232, 25, 16, 25, 56, 25, 96, 25, 136, 25, 176,
-25, 216, 26, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240,
-27, 24, 27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 28, 8, 28, 48,
-28, 88, 28, 128, 28, 168, 28, 208, 28, 248, 29, 32, 29, 72, 29, 112,
-29, 152, 29, 192, 29, 232, 30, 16, 30, 56, 30, 96, 30, 136, 30, 176,
-30, 216, 31, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240,
-32, 24, 32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 33, 8, 33, 48,
-33, 88, 33, 128, 33, 168, 33, 208, 33, 248, 34, 32, 34, 72, 34, 112,
-34, 152, 34, 192, 34, 232, 35, 16, 35, 56, 35, 96, 35, 136, 35, 176,
-35, 216, 36, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240,
-37, 24, 37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 38, 8, 38, 48,
-38, 88, 38, 128, 38, 168, 38, 208, 38, 248, 39, 32, 39, 72, 39, 112,
-39, 152, 39, 192, 39, 232, 40, 16, 40, 56, 40, 96, 40, 136, 40, 176,
-40, 216, 41, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240,
-42, 24, 42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 43, 8, 43, 48,
-43, 88, 43, 128, 43, 168, 43, 208, 43, 248, 44, 32, 44, 72, 44, 112,
-44, 152, 44, 192, 44, 232, 45, 16, 45, 56, 45, 96, 45, 136, 45, 176,
-45, 216, 46, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240,
-47, 24, 47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 48, 8, 48, 48,
-48, 88, 48, 128, 48, 168, 48, 208, 48, 248, 49, 32, 49, 72, 49, 112,
-49, 152, 49, 192, 49, 232, 50, 16, 50, 56, 50, 96, 50, 136, 50, 176,
-50, 216, 51, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240,
-52, 24, 52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 53, 8, 53, 48,
-53, 88, 53, 128, 53, 168, 53, 208, 53, 248, 54, 32, 54, 72, 54, 112,
-54, 152, 54, 192, 54, 232, 55, 16, 55, 56, 55, 96, 55, 136, 55, 176,
-55, 216, 56, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240,
-57, 24, 57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 58, 8, 58, 48,
-58, 88, 58, 128, 58, 168, 58, 208, 58, 248, 59, 32, 59, 72, 59, 112,
-59, 152, 59, 192, 59, 232, 60, 16, 60, 56, 60, 96, 60, 136, 60, 176,
-60, 216, 61, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240,
-62, 24, 62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 63, 8, 63, 48,
-63, 88, 63, 128, 63, 168, 63, 208, 63, 248, 64, 32, 64, 72, 64, 112,
-64, 152, 64, 192, 64, 232, 65, 16, 65, 56, 65, 96, 65, 136, 65, 176,
-65, 216, 66, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240,
-67, 24, 67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 68, 8, 68, 48,
-68, 88, 68, 128, 68, 168, 68, 208, 68, 248, 69, 32, 69, 72, 69, 112,
-69, 152, 69, 192, 69, 232, 70, 16, 70, 56, 70, 96, 70, 136, 70, 176,
-70, 216, 71, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240,
-72, 24, 72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 73, 8, 73, 48,
-73, 88, 73, 128, 73, 168, 73, 208, 73, 248, 74, 32, 74, 72, 74, 112,
-74, 152, 74, 192, 74, 232, 75, 16, 75, 56, 75, 96, 75, 136, 75, 176,
-75, 216, 76, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240,
-77, 24, 77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 78, 8, 78, 48,
-78, 88, 78, 128, 78, 168, 78, 208, 78, 248, 79, 32, 79, 72, 79, 112,
-79, 152, 79, 192, 79, 232, 80, 16, 80, 56, 80, 96, 80, 136, 80, 176,
-80, 216, 81, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240,
-82, 24, 82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 83, 8, 83, 48,
-83, 88, 83, 128, 83, 168, 83, 208, 83, 248, 84, 32, 84, 72, 84, 112,
-84, 152, 84, 192, 84, 232, 85, 16, 85, 56, 85, 96, 85, 136, 85, 176,
-85, 216, 86, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240,
-87, 24, 87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 88, 8, 88, 48,
-88, 88, 88, 128, 88, 168, 88, 208, 88, 248, 89, 32, 89, 72, 89, 112,
-89, 152, 89, 192, 89, 232, 90, 16, 90, 56, 90, 96, 90, 136, 90, 176,
-90, 216, 91, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240,
-92, 24, 92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 93, 8, 93, 48,
-93, 88, 93, 128, 93, 168, 93, 208, 93, 248, 94, 32, 94, 72, 94, 112,
-94, 152, 94, 192, 94, 232, 95, 16, 95, 56, 95, 96, 95, 136, 95, 176,
-95, 216, 96, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240,
-97, 24, 97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 98, 8, 98, 48,
-98, 88, 98, 128, 98, 168, 98, 208, 98, 248, 99, 32, 99, 72, 99, 112,
-99, 152, 99, 192, 99, 232, 100, 16, 100, 56, 100, 96, 100, 136, 100, 176,
-100, 216, 101, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240,
-102, 24, 102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 103, 8, 103, 48,
-103, 88, 103, 128, 103, 168, 103, 208, 103, 248, 104, 32, 104, 72, 104, 112,
-104, 152, 104, 192, 104, 232, 105, 16, 105, 56, 105, 96, 105, 136, 105, 176,
-105, 216, 106, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240,
-107, 24, 107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 108, 8, 108, 48,
-108, 88, 108, 128, 108, 168, 108, 208, 108, 248, 109, 32, 109, 72, 109, 112,
-109, 152, 109, 192, 109, 232, 110, 16, 110, 56, 110, 96, 110, 136, 110, 176,
-110, 216, 111, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240,
-112, 24, 112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 113, 8, 113, 48,
-113, 88, 113, 128, 113, 168, 113, 208, 113, 248, 114, 32, 114, 72, 114, 112,
-114, 152, 114, 192, 114, 232, 115, 16, 115, 56, 115, 96, 115, 136, 115, 176,
-115, 216, 116, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240,
-117, 24, 117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 118, 8, 118, 48,
-118, 88, 118, 128, 118, 168, 118, 208, 118, 248, 119, 32, 119, 72, 119, 112,
-119, 152, 119, 192, 119, 232, 120, 16, 120, 56, 120, 96, 120, 136, 120, 176,
-120, 216, 121, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240,
-122, 24, 122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 123, 8, 123, 48,
-123, 88, 123, 128, 123, 168, 123, 208, 123, 248, 124, 32, 124, 72, 124, 112,
-124, 152, 124, 192, 124, 232, 125, 16, 125, 56, 125, 96, 125, 136, 125, 176,
-125, 216, 126, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240,
-127, 24, 127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 128, 8, 128, 48,
-128, 88, 128, 128, 128, 168, 128, 208, 128, 248, 129, 32, 129, 72, 129, 112,
-129, 152, 129, 192, 129, 232, 130, 16, 130, 56, 130, 96, 130, 136, 130, 176,
-130, 216, 131, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240,
-132, 24, 132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 133, 8, 133, 48,
-133, 88, 133, 128, 133, 168, 133, 208, 133, 248, 134, 32, 134, 72, 134, 112,
-134, 152, 134, 192, 134, 232, 135, 16, 135, 56, 135, 96, 135, 136, 135, 176,
-135, 216, 136, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240,
-137, 24, 137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 138, 8, 138, 48,
-138, 88, 138, 128, 138, 168, 138, 208, 138, 248, 139, 32, 139, 72, 139, 112,
-139, 152, 139, 192, 139, 232, 140, 16, 140, 56, 140, 96, 140, 136, 140, 176,
-140, 216, 141, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240,
-142, 24, 142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 143, 8, 143, 48,
-143, 88, 143, 128, 143, 168, 143, 208, 143, 248, 144, 32, 144, 72, 144, 112,
-144, 152, 144, 192, 144, 232, 145, 16, 145, 56, 145, 96, 145, 136, 145, 176,
-145, 216, 146, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240,
-147, 24, 147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 148, 8, 148, 48,
-148, 88, 148, 128, 148, 168, 148, 208, 148, 248, 149, 32, 149, 72, 149, 112,
-149, 152, 149, 192, 149, 232, 150, 16, 150, 56, 150, 96, 150, 136, 150, 176,
-150, 216, 151, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240,
-152, 24, 152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 153, 8, 153, 48,
-153, 88, 153, 128, 153, 168, 153, 208, 153, 248, 154, 32, 154, 72, 154, 112,
-154, 152, 154, 192, 154, 232, 155, 16, 155, 56, 155, 96, 155, 136, 155, 176,
-155, 216, 156, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240,
-157, 24, 157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 158, 8, 158, 48,
-158, 88, 158, 128, 158, 168, 158, 208, 158, 248, 159, 32, 159, 72, 159, 112,
-159, 152, 159, 192, 159, 232, 160, 16, 160, 56, 160, 96, 160, 136, 160, 176,
-160, 216, 161, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240,
-162, 24, 162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 163, 8, 163, 48,
-163, 88, 163, 128, 163, 168, 163, 208, 163, 248, 164, 32, 164, 72, 164, 112,
-164, 152, 164, 192, 164, 232, 165, 16, 165, 56, 165, 96, 165, 136, 165, 176,
-165, 216, 166, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240,
-167, 24, 167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 168, 8, 168, 48,
-168, 88, 168, 128, 168, 168, 168, 208, 168, 248, 169, 32, 169, 72, 169, 112,
-169, 152, 169, 192, 169, 232, 170, 16, 170, 56, 170, 96, 170, 136, 170, 176,
-170, 216, 171, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240,
-172, 24, 172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 173, 8, 173, 48,
-173, 88, 173, 128, 173, 168, 173, 208, 173, 248, 174, 32, 174, 72, 174, 112,
-174, 152, 174, 192, 174, 232, 175, 16, 175, 56, 175, 96, 175, 136, 175, 176,
-175, 216, 176, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240,
-177, 24, 177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 178, 8, 178, 48,
-178, 88, 178, 128, 178, 168, 178, 208, 178, 248, 179, 32, 179, 72, 179, 112,
-179, 152, 179, 192, 179, 232, 180, 16, 180, 56, 180, 96, 180, 136, 180, 176,
-180, 216, 181, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240,
-182, 24, 182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 183, 8, 183, 48,
-183, 88, 183, 128, 183, 168, 183, 208, 183, 248, 184, 32, 184, 72, 184, 112,
-184, 152, 184, 192, 184, 232, 185, 16, 185, 56, 185, 96, 185, 136, 185, 176,
-185, 216, 186, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240,
-187, 24, 187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 188, 8, 188, 48,
-188, 88, 188, 128, 188, 168, 188, 208, 188, 248, 189, 32, 189, 72, 189, 112,
-189, 152, 189, 192, 189, 232, 190, 16, 190, 56, 190, 96, 190, 136, 190, 176,
-190, 216, 191, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240,
-192, 24, 192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 193, 8, 193, 48,
-193, 88, 193, 128, 193, 168, 193, 208, 193, 248, 194, 32, 194, 72, 194, 112,
-194, 152, 194, 192, 194, 232, 195, 16, 195, 56, 195, 96, 195, 136, 195, 176,
-195, 216, 196, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240,
-197, 24, 197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 198, 8, 198, 48,
-198, 88, 198, 128, 198, 168, 198, 208, 198, 248, 199, 32, 199, 72, 199, 112,
-199, 152, 199, 192, 199, 232, 200, 16, 200, 56, 200, 96, 200, 136, 200, 176,
-200, 216, 201, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240,
-202, 24, 202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 203, 8, 203, 48,
-203, 88, 203, 128, 203, 168, 203, 208, 203, 248, 204, 32, 204, 72, 204, 112,
-204, 152, 204, 192, 204, 232, 205, 16, 205, 56, 205, 96, 205, 136, 205, 176,
-205, 216, 206, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240,
-207, 24, 207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 208, 8, 208, 48,
-208, 88, 208, 128, 208, 168, 208, 208, 208, 248, 209, 32, 209, 72, 209, 112,
-209, 152, 209, 192, 209, 232, 210, 16, 210, 56, 210, 96, 210, 136, 210, 176,
-210, 216, 211, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240,
-212, 24, 212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 213, 8, 213, 48,
-213, 88, 213, 128, 213, 168, 213, 208, 213, 248, 214, 32, 214, 72, 214, 112,
-214, 152, 214, 192, 214, 232, 215, 16, 215, 56, 215, 96, 215, 136, 215, 176,
-215, 216, 224, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240,
-225, 24, 225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 226, 8, 226, 48,
-226, 88, 226, 128, 226, 168, 226, 208, 226, 248, 227, 32, 227, 72, 227, 112,
-227, 152, 227, 192, 227, 232, 228, 16, 228, 56, 228, 96, 228, 136, 228, 176,
-228, 216, 229, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240,
-230, 24, 230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 231, 8, 231, 48,
-231, 88, 231, 128, 231, 168, 231, 208, 231, 248, 232, 32, 232, 72, 232, 112,
-232, 152, 232, 192, 232, 232, 233, 16, 233, 56, 233, 96, 233, 136, 233, 176,
-233, 216, 234, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240,
-235, 24, 235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 236, 8, 236, 48,
-236, 88, 236, 128, 236, 168, 236, 208, 236, 248, 237, 32, 237, 72, 237, 112,
-237, 152, 237, 192, 237, 232, 238, 16, 238, 56, 238, 96, 238, 136, 238, 176,
-238, 216, 239, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240,
-240, 24, 240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 241, 8, 241, 48,
-241, 88, 241, 128, 241, 168, 241, 208, 241, 248, 242, 32, 242, 72, 242, 112,
-242, 152, 242, 192, 242, 232, 243, 16, 243, 56, 243, 96, 243, 136, 243, 176,
-243, 216, 244, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240,
-245, 24, 245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 246, 8, 246, 48,
-246, 88, 246, 128, 246, 168, 246, 208, 246, 248, 247, 32, 247, 72, 247, 112,
-247, 152, 247, 192, 247, 232, 248, 16, 248, 56, 248, 96, 248, 136, 248, 176,
-248, 216, 249, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240,
-250, 24, 250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 251, 8, 251, 48,
-251, 88, 251, 128, 251, 168, 251, 208, 251, 248, 252, 32, 252, 72, 252, 112,
-252, 152, 252, 192, 252, 232, 253, 16, 253, 56, 253, 96, 253, 136, 253, 176,
-253, 216, 254, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240,
-255, 24, 255, 64, 255, 104, 255, 144, 255, 184, 255, 224
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16BE.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16BE.java
deleted file mode 100644
index 5f5a2bf..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16BE.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_MultiByte_UTF_16BE extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "UTF-16BE";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
-176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
-192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
-208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
-224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
-240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
-896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
-1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
-2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
-2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
-3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
-4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
-4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
-5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
-6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
-6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
-7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
-7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
-8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
-9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
-9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
-10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
-11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
-11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
-12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
-13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
-13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
-14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
-14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
-15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
-16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
-16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
-17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
-18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
-18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
-19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
-20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
-20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
-21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
-22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
-22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
-23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
-23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
-24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
-25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
-25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
-26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
-27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
-27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
-28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
-29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
-29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
-30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
-30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
-31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
-32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
-32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
-33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
-34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
-34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
-35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
-36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
-36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
-37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
-38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
-38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
-39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
-39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
-40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
-41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
-41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
-42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
-43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
-43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
-44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
-45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
-45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
-46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
-46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
-47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
-48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
-48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
-49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
-50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
-50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
-51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
-52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
-52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
-53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
-54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
-54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
-57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
-57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
-58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
-59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
-59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
-60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
-61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
-61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
-62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
-63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
-63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
-64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
-65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7,
-0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15,
-0, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23,
-0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31,
-0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39,
-0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47,
-0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55,
-0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63,
-0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71,
-0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79,
-0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0, 87,
-0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95,
-0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103,
-0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111,
-0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119,
-0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127,
-0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0, 135,
-0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0, 143,
-0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0, 151,
-0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0, 159,
-0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0, 167,
-0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0, 175,
-0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0, 183,
-0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0, 191,
-0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0, 199,
-0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0, 207,
-0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 215,
-0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0, 223,
-0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0, 231,
-0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 239,
-0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0, 247,
-0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 255,
-1, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 2, 24,
-2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 3, 8, 3, 48, 3, 88,
-3, 128, 3, 168, 3, 208, 3, 248, 4, 32, 4, 72, 4, 112, 4, 152,
-4, 192, 4, 232, 5, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5, 216,
-6, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 7, 24,
-7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 8, 8, 8, 48, 8, 88,
-8, 128, 8, 168, 8, 208, 8, 248, 9, 32, 9, 72, 9, 112, 9, 152,
-9, 192, 9, 232, 10, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10, 216,
-11, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 12, 24,
-12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 13, 8, 13, 48, 13, 88,
-13, 128, 13, 168, 13, 208, 13, 248, 14, 32, 14, 72, 14, 112, 14, 152,
-14, 192, 14, 232, 15, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15, 216,
-16, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 17, 24,
-17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 18, 8, 18, 48, 18, 88,
-18, 128, 18, 168, 18, 208, 18, 248, 19, 32, 19, 72, 19, 112, 19, 152,
-19, 192, 19, 232, 20, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20, 216,
-21, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 22, 24,
-22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 23, 8, 23, 48, 23, 88,
-23, 128, 23, 168, 23, 208, 23, 248, 24, 32, 24, 72, 24, 112, 24, 152,
-24, 192, 24, 232, 25, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25, 216,
-26, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 27, 24,
-27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 28, 8, 28, 48, 28, 88,
-28, 128, 28, 168, 28, 208, 28, 248, 29, 32, 29, 72, 29, 112, 29, 152,
-29, 192, 29, 232, 30, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30, 216,
-31, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 32, 24,
-32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 33, 8, 33, 48, 33, 88,
-33, 128, 33, 168, 33, 208, 33, 248, 34, 32, 34, 72, 34, 112, 34, 152,
-34, 192, 34, 232, 35, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35, 216,
-36, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 37, 24,
-37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 38, 8, 38, 48, 38, 88,
-38, 128, 38, 168, 38, 208, 38, 248, 39, 32, 39, 72, 39, 112, 39, 152,
-39, 192, 39, 232, 40, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40, 216,
-41, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 42, 24,
-42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 43, 8, 43, 48, 43, 88,
-43, 128, 43, 168, 43, 208, 43, 248, 44, 32, 44, 72, 44, 112, 44, 152,
-44, 192, 44, 232, 45, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45, 216,
-46, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 47, 24,
-47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 48, 8, 48, 48, 48, 88,
-48, 128, 48, 168, 48, 208, 48, 248, 49, 32, 49, 72, 49, 112, 49, 152,
-49, 192, 49, 232, 50, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50, 216,
-51, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 52, 24,
-52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 53, 8, 53, 48, 53, 88,
-53, 128, 53, 168, 53, 208, 53, 248, 54, 32, 54, 72, 54, 112, 54, 152,
-54, 192, 54, 232, 55, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55, 216,
-56, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 57, 24,
-57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 58, 8, 58, 48, 58, 88,
-58, 128, 58, 168, 58, 208, 58, 248, 59, 32, 59, 72, 59, 112, 59, 152,
-59, 192, 59, 232, 60, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60, 216,
-61, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 62, 24,
-62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 63, 8, 63, 48, 63, 88,
-63, 128, 63, 168, 63, 208, 63, 248, 64, 32, 64, 72, 64, 112, 64, 152,
-64, 192, 64, 232, 65, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65, 216,
-66, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 67, 24,
-67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 68, 8, 68, 48, 68, 88,
-68, 128, 68, 168, 68, 208, 68, 248, 69, 32, 69, 72, 69, 112, 69, 152,
-69, 192, 69, 232, 70, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70, 216,
-71, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 72, 24,
-72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 73, 8, 73, 48, 73, 88,
-73, 128, 73, 168, 73, 208, 73, 248, 74, 32, 74, 72, 74, 112, 74, 152,
-74, 192, 74, 232, 75, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75, 216,
-76, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 77, 24,
-77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 78, 8, 78, 48, 78, 88,
-78, 128, 78, 168, 78, 208, 78, 248, 79, 32, 79, 72, 79, 112, 79, 152,
-79, 192, 79, 232, 80, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80, 216,
-81, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 82, 24,
-82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 83, 8, 83, 48, 83, 88,
-83, 128, 83, 168, 83, 208, 83, 248, 84, 32, 84, 72, 84, 112, 84, 152,
-84, 192, 84, 232, 85, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85, 216,
-86, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 87, 24,
-87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 88, 8, 88, 48, 88, 88,
-88, 128, 88, 168, 88, 208, 88, 248, 89, 32, 89, 72, 89, 112, 89, 152,
-89, 192, 89, 232, 90, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90, 216,
-91, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 92, 24,
-92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 93, 8, 93, 48, 93, 88,
-93, 128, 93, 168, 93, 208, 93, 248, 94, 32, 94, 72, 94, 112, 94, 152,
-94, 192, 94, 232, 95, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95, 216,
-96, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 97, 24,
-97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 98, 8, 98, 48, 98, 88,
-98, 128, 98, 168, 98, 208, 98, 248, 99, 32, 99, 72, 99, 112, 99, 152,
-99, 192, 99, 232, 100, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100, 216,
-101, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 102, 24,
-102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 103, 8, 103, 48, 103, 88,
-103, 128, 103, 168, 103, 208, 103, 248, 104, 32, 104, 72, 104, 112, 104, 152,
-104, 192, 104, 232, 105, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105, 216,
-106, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 107, 24,
-107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 108, 8, 108, 48, 108, 88,
-108, 128, 108, 168, 108, 208, 108, 248, 109, 32, 109, 72, 109, 112, 109, 152,
-109, 192, 109, 232, 110, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110, 216,
-111, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 112, 24,
-112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 113, 8, 113, 48, 113, 88,
-113, 128, 113, 168, 113, 208, 113, 248, 114, 32, 114, 72, 114, 112, 114, 152,
-114, 192, 114, 232, 115, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115, 216,
-116, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 117, 24,
-117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 118, 8, 118, 48, 118, 88,
-118, 128, 118, 168, 118, 208, 118, 248, 119, 32, 119, 72, 119, 112, 119, 152,
-119, 192, 119, 232, 120, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120, 216,
-121, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 122, 24,
-122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 123, 8, 123, 48, 123, 88,
-123, 128, 123, 168, 123, 208, 123, 248, 124, 32, 124, 72, 124, 112, 124, 152,
-124, 192, 124, 232, 125, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125, 216,
-126, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 127, 24,
-127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 128, 8, 128, 48, 128, 88,
-128, 128, 128, 168, 128, 208, 128, 248, 129, 32, 129, 72, 129, 112, 129, 152,
-129, 192, 129, 232, 130, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130, 216,
-131, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 132, 24,
-132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 133, 8, 133, 48, 133, 88,
-133, 128, 133, 168, 133, 208, 133, 248, 134, 32, 134, 72, 134, 112, 134, 152,
-134, 192, 134, 232, 135, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135, 216,
-136, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 137, 24,
-137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 138, 8, 138, 48, 138, 88,
-138, 128, 138, 168, 138, 208, 138, 248, 139, 32, 139, 72, 139, 112, 139, 152,
-139, 192, 139, 232, 140, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140, 216,
-141, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 142, 24,
-142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 143, 8, 143, 48, 143, 88,
-143, 128, 143, 168, 143, 208, 143, 248, 144, 32, 144, 72, 144, 112, 144, 152,
-144, 192, 144, 232, 145, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145, 216,
-146, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 147, 24,
-147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 148, 8, 148, 48, 148, 88,
-148, 128, 148, 168, 148, 208, 148, 248, 149, 32, 149, 72, 149, 112, 149, 152,
-149, 192, 149, 232, 150, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150, 216,
-151, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 152, 24,
-152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 153, 8, 153, 48, 153, 88,
-153, 128, 153, 168, 153, 208, 153, 248, 154, 32, 154, 72, 154, 112, 154, 152,
-154, 192, 154, 232, 155, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155, 216,
-156, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 157, 24,
-157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 158, 8, 158, 48, 158, 88,
-158, 128, 158, 168, 158, 208, 158, 248, 159, 32, 159, 72, 159, 112, 159, 152,
-159, 192, 159, 232, 160, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160, 216,
-161, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 162, 24,
-162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 163, 8, 163, 48, 163, 88,
-163, 128, 163, 168, 163, 208, 163, 248, 164, 32, 164, 72, 164, 112, 164, 152,
-164, 192, 164, 232, 165, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165, 216,
-166, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 167, 24,
-167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 168, 8, 168, 48, 168, 88,
-168, 128, 168, 168, 168, 208, 168, 248, 169, 32, 169, 72, 169, 112, 169, 152,
-169, 192, 169, 232, 170, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170, 216,
-171, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 172, 24,
-172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 173, 8, 173, 48, 173, 88,
-173, 128, 173, 168, 173, 208, 173, 248, 174, 32, 174, 72, 174, 112, 174, 152,
-174, 192, 174, 232, 175, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175, 216,
-176, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 177, 24,
-177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 178, 8, 178, 48, 178, 88,
-178, 128, 178, 168, 178, 208, 178, 248, 179, 32, 179, 72, 179, 112, 179, 152,
-179, 192, 179, 232, 180, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180, 216,
-181, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 182, 24,
-182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 183, 8, 183, 48, 183, 88,
-183, 128, 183, 168, 183, 208, 183, 248, 184, 32, 184, 72, 184, 112, 184, 152,
-184, 192, 184, 232, 185, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185, 216,
-186, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 187, 24,
-187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 188, 8, 188, 48, 188, 88,
-188, 128, 188, 168, 188, 208, 188, 248, 189, 32, 189, 72, 189, 112, 189, 152,
-189, 192, 189, 232, 190, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190, 216,
-191, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 192, 24,
-192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 193, 8, 193, 48, 193, 88,
-193, 128, 193, 168, 193, 208, 193, 248, 194, 32, 194, 72, 194, 112, 194, 152,
-194, 192, 194, 232, 195, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195, 216,
-196, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 197, 24,
-197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 198, 8, 198, 48, 198, 88,
-198, 128, 198, 168, 198, 208, 198, 248, 199, 32, 199, 72, 199, 112, 199, 152,
-199, 192, 199, 232, 200, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200, 216,
-201, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 202, 24,
-202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 203, 8, 203, 48, 203, 88,
-203, 128, 203, 168, 203, 208, 203, 248, 204, 32, 204, 72, 204, 112, 204, 152,
-204, 192, 204, 232, 205, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205, 216,
-206, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 207, 24,
-207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 208, 8, 208, 48, 208, 88,
-208, 128, 208, 168, 208, 208, 208, 248, 209, 32, 209, 72, 209, 112, 209, 152,
-209, 192, 209, 232, 210, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210, 216,
-211, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 212, 24,
-212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 213, 8, 213, 48, 213, 88,
-213, 128, 213, 168, 213, 208, 213, 248, 214, 32, 214, 72, 214, 112, 214, 152,
-214, 192, 214, 232, 215, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215, 216,
-224, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 225, 24,
-225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 226, 8, 226, 48, 226, 88,
-226, 128, 226, 168, 226, 208, 226, 248, 227, 32, 227, 72, 227, 112, 227, 152,
-227, 192, 227, 232, 228, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228, 216,
-229, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 230, 24,
-230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 231, 8, 231, 48, 231, 88,
-231, 128, 231, 168, 231, 208, 231, 248, 232, 32, 232, 72, 232, 112, 232, 152,
-232, 192, 232, 232, 233, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233, 216,
-234, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 235, 24,
-235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 236, 8, 236, 48, 236, 88,
-236, 128, 236, 168, 236, 208, 236, 248, 237, 32, 237, 72, 237, 112, 237, 152,
-237, 192, 237, 232, 238, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238, 216,
-239, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 240, 24,
-240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 241, 8, 241, 48, 241, 88,
-241, 128, 241, 168, 241, 208, 241, 248, 242, 32, 242, 72, 242, 112, 242, 152,
-242, 192, 242, 232, 243, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243, 216,
-244, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 245, 24,
-245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 246, 8, 246, 48, 246, 88,
-246, 128, 246, 168, 246, 208, 246, 248, 247, 32, 247, 72, 247, 112, 247, 152,
-247, 192, 247, 232, 248, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248, 216,
-249, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 250, 24,
-250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 251, 8, 251, 48, 251, 88,
-251, 128, 251, 168, 251, 208, 251, 248, 252, 32, 252, 72, 252, 112, 252, 152,
-252, 192, 252, 232, 253, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253, 216,
-254, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 255, 24,
-255, 64, 255, 104, 255, 144, 255, 184, 255, 224
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16LE.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16LE.java
deleted file mode 100644
index c907f52..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16LE.java
+++ /dev/null
@@ -1,392 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_MultiByte_UTF_16LE extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "UTF-16LE";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
-176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
-192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
-208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
-224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
-240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
-896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
-1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
-2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
-2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
-3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
-4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
-4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
-5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
-6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
-6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
-7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
-7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
-8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
-9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
-9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
-10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
-11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
-11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
-12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
-13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
-13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
-14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
-14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
-15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
-16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
-16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
-17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
-18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
-18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
-19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
-20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
-20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
-21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
-22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
-22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
-23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
-23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
-24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
-25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
-25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
-26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
-27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
-27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
-28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
-29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
-29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
-30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
-30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
-31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
-32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
-32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
-33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
-34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
-34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
-35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
-36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
-36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
-37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
-38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
-38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
-39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
-39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
-40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
-41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
-41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
-42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
-43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
-43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
-44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
-45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
-45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
-46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
-46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
-47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
-48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
-48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
-49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
-50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
-50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
-51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
-52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
-52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
-53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
-54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
-54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
-57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
-57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
-58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
-59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
-59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
-60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
-61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
-61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
-62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
-63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
-63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
-64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
-65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0,
-8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0,
-16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0,
-24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0,
-32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0,
-40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0,
-48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0,
-56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0,
-64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71, 0,
-72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79, 0,
-80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0, 87, 0,
-88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0,
-96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0,
-104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0,
-112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119, 0,
-120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127, 0,
-128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0, 135, 0,
-136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0, 143, 0,
-144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0, 151, 0,
-152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0, 159, 0,
-160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0, 167, 0,
-168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0, 175, 0,
-176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0, 183, 0,
-184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0, 191, 0,
-192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0, 199, 0,
-200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0, 207, 0,
-208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0, 215, 0,
-216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0, 223, 0,
-224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0, 231, 0,
-232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0, 239, 0,
-240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0, 247, 0,
-248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0, 255, 0,
-0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 1, 24, 2,
-64, 2, 104, 2, 144, 2, 184, 2, 224, 2, 8, 3, 48, 3, 88, 3,
-128, 3, 168, 3, 208, 3, 248, 3, 32, 4, 72, 4, 112, 4, 152, 4,
-192, 4, 232, 4, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5, 216, 5,
-0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 6, 24, 7,
-64, 7, 104, 7, 144, 7, 184, 7, 224, 7, 8, 8, 48, 8, 88, 8,
-128, 8, 168, 8, 208, 8, 248, 8, 32, 9, 72, 9, 112, 9, 152, 9,
-192, 9, 232, 9, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10, 216, 10,
-0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 11, 24, 12,
-64, 12, 104, 12, 144, 12, 184, 12, 224, 12, 8, 13, 48, 13, 88, 13,
-128, 13, 168, 13, 208, 13, 248, 13, 32, 14, 72, 14, 112, 14, 152, 14,
-192, 14, 232, 14, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15, 216, 15,
-0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 16, 24, 17,
-64, 17, 104, 17, 144, 17, 184, 17, 224, 17, 8, 18, 48, 18, 88, 18,
-128, 18, 168, 18, 208, 18, 248, 18, 32, 19, 72, 19, 112, 19, 152, 19,
-192, 19, 232, 19, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20, 216, 20,
-0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 21, 24, 22,
-64, 22, 104, 22, 144, 22, 184, 22, 224, 22, 8, 23, 48, 23, 88, 23,
-128, 23, 168, 23, 208, 23, 248, 23, 32, 24, 72, 24, 112, 24, 152, 24,
-192, 24, 232, 24, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25, 216, 25,
-0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 26, 24, 27,
-64, 27, 104, 27, 144, 27, 184, 27, 224, 27, 8, 28, 48, 28, 88, 28,
-128, 28, 168, 28, 208, 28, 248, 28, 32, 29, 72, 29, 112, 29, 152, 29,
-192, 29, 232, 29, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30, 216, 30,
-0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 31, 24, 32,
-64, 32, 104, 32, 144, 32, 184, 32, 224, 32, 8, 33, 48, 33, 88, 33,
-128, 33, 168, 33, 208, 33, 248, 33, 32, 34, 72, 34, 112, 34, 152, 34,
-192, 34, 232, 34, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35, 216, 35,
-0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 36, 24, 37,
-64, 37, 104, 37, 144, 37, 184, 37, 224, 37, 8, 38, 48, 38, 88, 38,
-128, 38, 168, 38, 208, 38, 248, 38, 32, 39, 72, 39, 112, 39, 152, 39,
-192, 39, 232, 39, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40, 216, 40,
-0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 41, 24, 42,
-64, 42, 104, 42, 144, 42, 184, 42, 224, 42, 8, 43, 48, 43, 88, 43,
-128, 43, 168, 43, 208, 43, 248, 43, 32, 44, 72, 44, 112, 44, 152, 44,
-192, 44, 232, 44, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45, 216, 45,
-0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 46, 24, 47,
-64, 47, 104, 47, 144, 47, 184, 47, 224, 47, 8, 48, 48, 48, 88, 48,
-128, 48, 168, 48, 208, 48, 248, 48, 32, 49, 72, 49, 112, 49, 152, 49,
-192, 49, 232, 49, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50, 216, 50,
-0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 51, 24, 52,
-64, 52, 104, 52, 144, 52, 184, 52, 224, 52, 8, 53, 48, 53, 88, 53,
-128, 53, 168, 53, 208, 53, 248, 53, 32, 54, 72, 54, 112, 54, 152, 54,
-192, 54, 232, 54, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55, 216, 55,
-0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 56, 24, 57,
-64, 57, 104, 57, 144, 57, 184, 57, 224, 57, 8, 58, 48, 58, 88, 58,
-128, 58, 168, 58, 208, 58, 248, 58, 32, 59, 72, 59, 112, 59, 152, 59,
-192, 59, 232, 59, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60, 216, 60,
-0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 61, 24, 62,
-64, 62, 104, 62, 144, 62, 184, 62, 224, 62, 8, 63, 48, 63, 88, 63,
-128, 63, 168, 63, 208, 63, 248, 63, 32, 64, 72, 64, 112, 64, 152, 64,
-192, 64, 232, 64, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65, 216, 65,
-0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 66, 24, 67,
-64, 67, 104, 67, 144, 67, 184, 67, 224, 67, 8, 68, 48, 68, 88, 68,
-128, 68, 168, 68, 208, 68, 248, 68, 32, 69, 72, 69, 112, 69, 152, 69,
-192, 69, 232, 69, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70, 216, 70,
-0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 71, 24, 72,
-64, 72, 104, 72, 144, 72, 184, 72, 224, 72, 8, 73, 48, 73, 88, 73,
-128, 73, 168, 73, 208, 73, 248, 73, 32, 74, 72, 74, 112, 74, 152, 74,
-192, 74, 232, 74, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75, 216, 75,
-0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 76, 24, 77,
-64, 77, 104, 77, 144, 77, 184, 77, 224, 77, 8, 78, 48, 78, 88, 78,
-128, 78, 168, 78, 208, 78, 248, 78, 32, 79, 72, 79, 112, 79, 152, 79,
-192, 79, 232, 79, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80, 216, 80,
-0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 81, 24, 82,
-64, 82, 104, 82, 144, 82, 184, 82, 224, 82, 8, 83, 48, 83, 88, 83,
-128, 83, 168, 83, 208, 83, 248, 83, 32, 84, 72, 84, 112, 84, 152, 84,
-192, 84, 232, 84, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85, 216, 85,
-0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 86, 24, 87,
-64, 87, 104, 87, 144, 87, 184, 87, 224, 87, 8, 88, 48, 88, 88, 88,
-128, 88, 168, 88, 208, 88, 248, 88, 32, 89, 72, 89, 112, 89, 152, 89,
-192, 89, 232, 89, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90, 216, 90,
-0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 91, 24, 92,
-64, 92, 104, 92, 144, 92, 184, 92, 224, 92, 8, 93, 48, 93, 88, 93,
-128, 93, 168, 93, 208, 93, 248, 93, 32, 94, 72, 94, 112, 94, 152, 94,
-192, 94, 232, 94, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95, 216, 95,
-0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 96, 24, 97,
-64, 97, 104, 97, 144, 97, 184, 97, 224, 97, 8, 98, 48, 98, 88, 98,
-128, 98, 168, 98, 208, 98, 248, 98, 32, 99, 72, 99, 112, 99, 152, 99,
-192, 99, 232, 99, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100, 216, 100,
-0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 101, 24, 102,
-64, 102, 104, 102, 144, 102, 184, 102, 224, 102, 8, 103, 48, 103, 88, 103,
-128, 103, 168, 103, 208, 103, 248, 103, 32, 104, 72, 104, 112, 104, 152, 104,
-192, 104, 232, 104, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105, 216, 105,
-0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 106, 24, 107,
-64, 107, 104, 107, 144, 107, 184, 107, 224, 107, 8, 108, 48, 108, 88, 108,
-128, 108, 168, 108, 208, 108, 248, 108, 32, 109, 72, 109, 112, 109, 152, 109,
-192, 109, 232, 109, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110, 216, 110,
-0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 111, 24, 112,
-64, 112, 104, 112, 144, 112, 184, 112, 224, 112, 8, 113, 48, 113, 88, 113,
-128, 113, 168, 113, 208, 113, 248, 113, 32, 114, 72, 114, 112, 114, 152, 114,
-192, 114, 232, 114, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115, 216, 115,
-0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 116, 24, 117,
-64, 117, 104, 117, 144, 117, 184, 117, 224, 117, 8, 118, 48, 118, 88, 118,
-128, 118, 168, 118, 208, 118, 248, 118, 32, 119, 72, 119, 112, 119, 152, 119,
-192, 119, 232, 119, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120, 216, 120,
-0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 121, 24, 122,
-64, 122, 104, 122, 144, 122, 184, 122, 224, 122, 8, 123, 48, 123, 88, 123,
-128, 123, 168, 123, 208, 123, 248, 123, 32, 124, 72, 124, 112, 124, 152, 124,
-192, 124, 232, 124, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125, 216, 125,
-0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 126, 24, 127,
-64, 127, 104, 127, 144, 127, 184, 127, 224, 127, 8, 128, 48, 128, 88, 128,
-128, 128, 168, 128, 208, 128, 248, 128, 32, 129, 72, 129, 112, 129, 152, 129,
-192, 129, 232, 129, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130, 216, 130,
-0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 131, 24, 132,
-64, 132, 104, 132, 144, 132, 184, 132, 224, 132, 8, 133, 48, 133, 88, 133,
-128, 133, 168, 133, 208, 133, 248, 133, 32, 134, 72, 134, 112, 134, 152, 134,
-192, 134, 232, 134, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135, 216, 135,
-0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 136, 24, 137,
-64, 137, 104, 137, 144, 137, 184, 137, 224, 137, 8, 138, 48, 138, 88, 138,
-128, 138, 168, 138, 208, 138, 248, 138, 32, 139, 72, 139, 112, 139, 152, 139,
-192, 139, 232, 139, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140, 216, 140,
-0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 141, 24, 142,
-64, 142, 104, 142, 144, 142, 184, 142, 224, 142, 8, 143, 48, 143, 88, 143,
-128, 143, 168, 143, 208, 143, 248, 143, 32, 144, 72, 144, 112, 144, 152, 144,
-192, 144, 232, 144, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145, 216, 145,
-0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 146, 24, 147,
-64, 147, 104, 147, 144, 147, 184, 147, 224, 147, 8, 148, 48, 148, 88, 148,
-128, 148, 168, 148, 208, 148, 248, 148, 32, 149, 72, 149, 112, 149, 152, 149,
-192, 149, 232, 149, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150, 216, 150,
-0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 151, 24, 152,
-64, 152, 104, 152, 144, 152, 184, 152, 224, 152, 8, 153, 48, 153, 88, 153,
-128, 153, 168, 153, 208, 153, 248, 153, 32, 154, 72, 154, 112, 154, 152, 154,
-192, 154, 232, 154, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155, 216, 155,
-0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 156, 24, 157,
-64, 157, 104, 157, 144, 157, 184, 157, 224, 157, 8, 158, 48, 158, 88, 158,
-128, 158, 168, 158, 208, 158, 248, 158, 32, 159, 72, 159, 112, 159, 152, 159,
-192, 159, 232, 159, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160, 216, 160,
-0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 161, 24, 162,
-64, 162, 104, 162, 144, 162, 184, 162, 224, 162, 8, 163, 48, 163, 88, 163,
-128, 163, 168, 163, 208, 163, 248, 163, 32, 164, 72, 164, 112, 164, 152, 164,
-192, 164, 232, 164, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165, 216, 165,
-0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 166, 24, 167,
-64, 167, 104, 167, 144, 167, 184, 167, 224, 167, 8, 168, 48, 168, 88, 168,
-128, 168, 168, 168, 208, 168, 248, 168, 32, 169, 72, 169, 112, 169, 152, 169,
-192, 169, 232, 169, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170, 216, 170,
-0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 171, 24, 172,
-64, 172, 104, 172, 144, 172, 184, 172, 224, 172, 8, 173, 48, 173, 88, 173,
-128, 173, 168, 173, 208, 173, 248, 173, 32, 174, 72, 174, 112, 174, 152, 174,
-192, 174, 232, 174, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175, 216, 175,
-0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 176, 24, 177,
-64, 177, 104, 177, 144, 177, 184, 177, 224, 177, 8, 178, 48, 178, 88, 178,
-128, 178, 168, 178, 208, 178, 248, 178, 32, 179, 72, 179, 112, 179, 152, 179,
-192, 179, 232, 179, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180, 216, 180,
-0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 181, 24, 182,
-64, 182, 104, 182, 144, 182, 184, 182, 224, 182, 8, 183, 48, 183, 88, 183,
-128, 183, 168, 183, 208, 183, 248, 183, 32, 184, 72, 184, 112, 184, 152, 184,
-192, 184, 232, 184, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185, 216, 185,
-0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 186, 24, 187,
-64, 187, 104, 187, 144, 187, 184, 187, 224, 187, 8, 188, 48, 188, 88, 188,
-128, 188, 168, 188, 208, 188, 248, 188, 32, 189, 72, 189, 112, 189, 152, 189,
-192, 189, 232, 189, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190, 216, 190,
-0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 191, 24, 192,
-64, 192, 104, 192, 144, 192, 184, 192, 224, 192, 8, 193, 48, 193, 88, 193,
-128, 193, 168, 193, 208, 193, 248, 193, 32, 194, 72, 194, 112, 194, 152, 194,
-192, 194, 232, 194, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195, 216, 195,
-0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 196, 24, 197,
-64, 197, 104, 197, 144, 197, 184, 197, 224, 197, 8, 198, 48, 198, 88, 198,
-128, 198, 168, 198, 208, 198, 248, 198, 32, 199, 72, 199, 112, 199, 152, 199,
-192, 199, 232, 199, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200, 216, 200,
-0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 201, 24, 202,
-64, 202, 104, 202, 144, 202, 184, 202, 224, 202, 8, 203, 48, 203, 88, 203,
-128, 203, 168, 203, 208, 203, 248, 203, 32, 204, 72, 204, 112, 204, 152, 204,
-192, 204, 232, 204, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205, 216, 205,
-0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 206, 24, 207,
-64, 207, 104, 207, 144, 207, 184, 207, 224, 207, 8, 208, 48, 208, 88, 208,
-128, 208, 168, 208, 208, 208, 248, 208, 32, 209, 72, 209, 112, 209, 152, 209,
-192, 209, 232, 209, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210, 216, 210,
-0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 211, 24, 212,
-64, 212, 104, 212, 144, 212, 184, 212, 224, 212, 8, 213, 48, 213, 88, 213,
-128, 213, 168, 213, 208, 213, 248, 213, 32, 214, 72, 214, 112, 214, 152, 214,
-192, 214, 232, 214, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215, 216, 215,
-0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 224, 24, 225,
-64, 225, 104, 225, 144, 225, 184, 225, 224, 225, 8, 226, 48, 226, 88, 226,
-128, 226, 168, 226, 208, 226, 248, 226, 32, 227, 72, 227, 112, 227, 152, 227,
-192, 227, 232, 227, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228, 216, 228,
-0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 229, 24, 230,
-64, 230, 104, 230, 144, 230, 184, 230, 224, 230, 8, 231, 48, 231, 88, 231,
-128, 231, 168, 231, 208, 231, 248, 231, 32, 232, 72, 232, 112, 232, 152, 232,
-192, 232, 232, 232, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233, 216, 233,
-0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 234, 24, 235,
-64, 235, 104, 235, 144, 235, 184, 235, 224, 235, 8, 236, 48, 236, 88, 236,
-128, 236, 168, 236, 208, 236, 248, 236, 32, 237, 72, 237, 112, 237, 152, 237,
-192, 237, 232, 237, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238, 216, 238,
-0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 239, 24, 240,
-64, 240, 104, 240, 144, 240, 184, 240, 224, 240, 8, 241, 48, 241, 88, 241,
-128, 241, 168, 241, 208, 241, 248, 241, 32, 242, 72, 242, 112, 242, 152, 242,
-192, 242, 232, 242, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243, 216, 243,
-0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 244, 24, 245,
-64, 245, 104, 245, 144, 245, 184, 245, 224, 245, 8, 246, 48, 246, 88, 246,
-128, 246, 168, 246, 208, 246, 248, 246, 32, 247, 72, 247, 112, 247, 152, 247,
-192, 247, 232, 247, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248, 216, 248,
-0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 249, 24, 250,
-64, 250, 104, 250, 144, 250, 184, 250, 224, 250, 8, 251, 48, 251, 88, 251,
-128, 251, 168, 251, 208, 251, 248, 251, 32, 252, 72, 252, 112, 252, 152, 252,
-192, 252, 232, 252, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253, 216, 253,
-0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 254, 24, 255,
-64, 255, 104, 255, 144, 255, 184, 255, 224, 255
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16_Android.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16_Android.java
deleted file mode 100644
index ebdd9fc..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_16_Android.java
+++ /dev/null
@@ -1,377 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestTargetClass;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_MultiByte_UTF_16_Android extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "UTF-16";
-
- testChars = theseChars(new int[]{
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
-176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
-192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
-208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
-224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
-240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
-896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
-1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
-2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
-2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
-3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
-4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
-4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
-5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
-6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
-6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
-7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
-7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
-8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
-9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
-9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
-10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
-11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
-11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
-12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
-13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
-13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
-14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
-14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
-15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
-16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
-16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
-17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
-18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
-18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
-19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
-20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
-20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
-21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
-22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
-22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
-23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
-23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
-24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
-25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
-25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
-26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
-27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
-27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
-28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
-29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
-29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
-30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
-30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
-31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
-32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
-32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
-33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
-34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
-34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
-35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
-36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
-36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
-37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
-38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
-38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
-39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
-39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
-40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
-41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
-41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
-42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
-43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
-43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
-44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
-45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
-45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
-46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
-46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
-47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
-48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
-48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
-49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
-50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
-50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
-51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
-52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
-52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
-53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
-54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
-54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
-57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
-57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
-58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
-59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
-59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
-60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
-61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
-61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
-62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
-63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
-63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
-64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
-65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
- });
-
- testBytes = theseBytes(new int[]{
-255, 254, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0,
-39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0,
-47, 0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0,
-55, 0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0,
-63, 0, 64, 0, 65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0,
-71, 0, 72, 0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0,
-79, 0, 80, 0, 81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0,
-87, 0, 88, 0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0,
-95, 0, 96, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0,
-103, 0, 104, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0,
-111, 0, 112, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0,
-119, 0, 120, 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0,
-127, 0, 128, 0, 129, 0, 130, 0, 131, 0, 132, 0, 133, 0, 134, 0,
-135, 0, 136, 0, 137, 0, 138, 0, 139, 0, 140, 0, 141, 0, 142, 0,
-143, 0, 144, 0, 145, 0, 146, 0, 147, 0, 148, 0, 149, 0, 150, 0,
-151, 0, 152, 0, 153, 0, 154, 0, 155, 0, 156, 0, 157, 0, 158, 0,
-159, 0, 160, 0, 161, 0, 162, 0, 163, 0, 164, 0, 165, 0, 166, 0,
-167, 0, 168, 0, 169, 0, 170, 0, 171, 0, 172, 0, 173, 0, 174, 0,
-175, 0, 176, 0, 177, 0, 178, 0, 179, 0, 180, 0, 181, 0, 182, 0,
-183, 0, 184, 0, 185, 0, 186, 0, 187, 0, 188, 0, 189, 0, 190, 0,
-191, 0, 192, 0, 193, 0, 194, 0, 195, 0, 196, 0, 197, 0, 198, 0,
-199, 0, 200, 0, 201, 0, 202, 0, 203, 0, 204, 0, 205, 0, 206, 0,
-207, 0, 208, 0, 209, 0, 210, 0, 211, 0, 212, 0, 213, 0, 214, 0,
-215, 0, 216, 0, 217, 0, 218, 0, 219, 0, 220, 0, 221, 0, 222, 0,
-223, 0, 224, 0, 225, 0, 226, 0, 227, 0, 228, 0, 229, 0, 230, 0,
-231, 0, 232, 0, 233, 0, 234, 0, 235, 0, 236, 0, 237, 0, 238, 0,
-239, 0, 240, 0, 241, 0, 242, 0, 243, 0, 244, 0, 245, 0, 246, 0,
-247, 0, 248, 0, 249, 0, 250, 0, 251, 0, 252, 0, 253, 0, 254, 0,
-255, 0, 0, 1, 40, 1, 80, 1, 120, 1, 160, 1, 200, 1, 240, 1,
-24, 2, 64, 2, 104, 2, 144, 2, 184, 2, 224, 2, 8, 3, 48, 3,
-88, 3, 128, 3, 168, 3, 208, 3, 248, 3, 32, 4, 72, 4, 112, 4,
-152, 4, 192, 4, 232, 4, 16, 5, 56, 5, 96, 5, 136, 5, 176, 5,
-216, 5, 0, 6, 40, 6, 80, 6, 120, 6, 160, 6, 200, 6, 240, 6,
-24, 7, 64, 7, 104, 7, 144, 7, 184, 7, 224, 7, 8, 8, 48, 8,
-88, 8, 128, 8, 168, 8, 208, 8, 248, 8, 32, 9, 72, 9, 112, 9,
-152, 9, 192, 9, 232, 9, 16, 10, 56, 10, 96, 10, 136, 10, 176, 10,
-216, 10, 0, 11, 40, 11, 80, 11, 120, 11, 160, 11, 200, 11, 240, 11,
-24, 12, 64, 12, 104, 12, 144, 12, 184, 12, 224, 12, 8, 13, 48, 13,
-88, 13, 128, 13, 168, 13, 208, 13, 248, 13, 32, 14, 72, 14, 112, 14,
-152, 14, 192, 14, 232, 14, 16, 15, 56, 15, 96, 15, 136, 15, 176, 15,
-216, 15, 0, 16, 40, 16, 80, 16, 120, 16, 160, 16, 200, 16, 240, 16,
-24, 17, 64, 17, 104, 17, 144, 17, 184, 17, 224, 17, 8, 18, 48, 18,
-88, 18, 128, 18, 168, 18, 208, 18, 248, 18, 32, 19, 72, 19, 112, 19,
-152, 19, 192, 19, 232, 19, 16, 20, 56, 20, 96, 20, 136, 20, 176, 20,
-216, 20, 0, 21, 40, 21, 80, 21, 120, 21, 160, 21, 200, 21, 240, 21,
-24, 22, 64, 22, 104, 22, 144, 22, 184, 22, 224, 22, 8, 23, 48, 23,
-88, 23, 128, 23, 168, 23, 208, 23, 248, 23, 32, 24, 72, 24, 112, 24,
-152, 24, 192, 24, 232, 24, 16, 25, 56, 25, 96, 25, 136, 25, 176, 25,
-216, 25, 0, 26, 40, 26, 80, 26, 120, 26, 160, 26, 200, 26, 240, 26,
-24, 27, 64, 27, 104, 27, 144, 27, 184, 27, 224, 27, 8, 28, 48, 28,
-88, 28, 128, 28, 168, 28, 208, 28, 248, 28, 32, 29, 72, 29, 112, 29,
-152, 29, 192, 29, 232, 29, 16, 30, 56, 30, 96, 30, 136, 30, 176, 30,
-216, 30, 0, 31, 40, 31, 80, 31, 120, 31, 160, 31, 200, 31, 240, 31,
-24, 32, 64, 32, 104, 32, 144, 32, 184, 32, 224, 32, 8, 33, 48, 33,
-88, 33, 128, 33, 168, 33, 208, 33, 248, 33, 32, 34, 72, 34, 112, 34,
-152, 34, 192, 34, 232, 34, 16, 35, 56, 35, 96, 35, 136, 35, 176, 35,
-216, 35, 0, 36, 40, 36, 80, 36, 120, 36, 160, 36, 200, 36, 240, 36,
-24, 37, 64, 37, 104, 37, 144, 37, 184, 37, 224, 37, 8, 38, 48, 38,
-88, 38, 128, 38, 168, 38, 208, 38, 248, 38, 32, 39, 72, 39, 112, 39,
-152, 39, 192, 39, 232, 39, 16, 40, 56, 40, 96, 40, 136, 40, 176, 40,
-216, 40, 0, 41, 40, 41, 80, 41, 120, 41, 160, 41, 200, 41, 240, 41,
-24, 42, 64, 42, 104, 42, 144, 42, 184, 42, 224, 42, 8, 43, 48, 43,
-88, 43, 128, 43, 168, 43, 208, 43, 248, 43, 32, 44, 72, 44, 112, 44,
-152, 44, 192, 44, 232, 44, 16, 45, 56, 45, 96, 45, 136, 45, 176, 45,
-216, 45, 0, 46, 40, 46, 80, 46, 120, 46, 160, 46, 200, 46, 240, 46,
-24, 47, 64, 47, 104, 47, 144, 47, 184, 47, 224, 47, 8, 48, 48, 48,
-88, 48, 128, 48, 168, 48, 208, 48, 248, 48, 32, 49, 72, 49, 112, 49,
-152, 49, 192, 49, 232, 49, 16, 50, 56, 50, 96, 50, 136, 50, 176, 50,
-216, 50, 0, 51, 40, 51, 80, 51, 120, 51, 160, 51, 200, 51, 240, 51,
-24, 52, 64, 52, 104, 52, 144, 52, 184, 52, 224, 52, 8, 53, 48, 53,
-88, 53, 128, 53, 168, 53, 208, 53, 248, 53, 32, 54, 72, 54, 112, 54,
-152, 54, 192, 54, 232, 54, 16, 55, 56, 55, 96, 55, 136, 55, 176, 55,
-216, 55, 0, 56, 40, 56, 80, 56, 120, 56, 160, 56, 200, 56, 240, 56,
-24, 57, 64, 57, 104, 57, 144, 57, 184, 57, 224, 57, 8, 58, 48, 58,
-88, 58, 128, 58, 168, 58, 208, 58, 248, 58, 32, 59, 72, 59, 112, 59,
-152, 59, 192, 59, 232, 59, 16, 60, 56, 60, 96, 60, 136, 60, 176, 60,
-216, 60, 0, 61, 40, 61, 80, 61, 120, 61, 160, 61, 200, 61, 240, 61,
-24, 62, 64, 62, 104, 62, 144, 62, 184, 62, 224, 62, 8, 63, 48, 63,
-88, 63, 128, 63, 168, 63, 208, 63, 248, 63, 32, 64, 72, 64, 112, 64,
-152, 64, 192, 64, 232, 64, 16, 65, 56, 65, 96, 65, 136, 65, 176, 65,
-216, 65, 0, 66, 40, 66, 80, 66, 120, 66, 160, 66, 200, 66, 240, 66,
-24, 67, 64, 67, 104, 67, 144, 67, 184, 67, 224, 67, 8, 68, 48, 68,
-88, 68, 128, 68, 168, 68, 208, 68, 248, 68, 32, 69, 72, 69, 112, 69,
-152, 69, 192, 69, 232, 69, 16, 70, 56, 70, 96, 70, 136, 70, 176, 70,
-216, 70, 0, 71, 40, 71, 80, 71, 120, 71, 160, 71, 200, 71, 240, 71,
-24, 72, 64, 72, 104, 72, 144, 72, 184, 72, 224, 72, 8, 73, 48, 73,
-88, 73, 128, 73, 168, 73, 208, 73, 248, 73, 32, 74, 72, 74, 112, 74,
-152, 74, 192, 74, 232, 74, 16, 75, 56, 75, 96, 75, 136, 75, 176, 75,
-216, 75, 0, 76, 40, 76, 80, 76, 120, 76, 160, 76, 200, 76, 240, 76,
-24, 77, 64, 77, 104, 77, 144, 77, 184, 77, 224, 77, 8, 78, 48, 78,
-88, 78, 128, 78, 168, 78, 208, 78, 248, 78, 32, 79, 72, 79, 112, 79,
-152, 79, 192, 79, 232, 79, 16, 80, 56, 80, 96, 80, 136, 80, 176, 80,
-216, 80, 0, 81, 40, 81, 80, 81, 120, 81, 160, 81, 200, 81, 240, 81,
-24, 82, 64, 82, 104, 82, 144, 82, 184, 82, 224, 82, 8, 83, 48, 83,
-88, 83, 128, 83, 168, 83, 208, 83, 248, 83, 32, 84, 72, 84, 112, 84,
-152, 84, 192, 84, 232, 84, 16, 85, 56, 85, 96, 85, 136, 85, 176, 85,
-216, 85, 0, 86, 40, 86, 80, 86, 120, 86, 160, 86, 200, 86, 240, 86,
-24, 87, 64, 87, 104, 87, 144, 87, 184, 87, 224, 87, 8, 88, 48, 88,
-88, 88, 128, 88, 168, 88, 208, 88, 248, 88, 32, 89, 72, 89, 112, 89,
-152, 89, 192, 89, 232, 89, 16, 90, 56, 90, 96, 90, 136, 90, 176, 90,
-216, 90, 0, 91, 40, 91, 80, 91, 120, 91, 160, 91, 200, 91, 240, 91,
-24, 92, 64, 92, 104, 92, 144, 92, 184, 92, 224, 92, 8, 93, 48, 93,
-88, 93, 128, 93, 168, 93, 208, 93, 248, 93, 32, 94, 72, 94, 112, 94,
-152, 94, 192, 94, 232, 94, 16, 95, 56, 95, 96, 95, 136, 95, 176, 95,
-216, 95, 0, 96, 40, 96, 80, 96, 120, 96, 160, 96, 200, 96, 240, 96,
-24, 97, 64, 97, 104, 97, 144, 97, 184, 97, 224, 97, 8, 98, 48, 98,
-88, 98, 128, 98, 168, 98, 208, 98, 248, 98, 32, 99, 72, 99, 112, 99,
-152, 99, 192, 99, 232, 99, 16, 100, 56, 100, 96, 100, 136, 100, 176, 100,
-216, 100, 0, 101, 40, 101, 80, 101, 120, 101, 160, 101, 200, 101, 240, 101,
-24, 102, 64, 102, 104, 102, 144, 102, 184, 102, 224, 102, 8, 103, 48, 103,
-88, 103, 128, 103, 168, 103, 208, 103, 248, 103, 32, 104, 72, 104, 112, 104,
-152, 104, 192, 104, 232, 104, 16, 105, 56, 105, 96, 105, 136, 105, 176, 105,
-216, 105, 0, 106, 40, 106, 80, 106, 120, 106, 160, 106, 200, 106, 240, 106,
-24, 107, 64, 107, 104, 107, 144, 107, 184, 107, 224, 107, 8, 108, 48, 108,
-88, 108, 128, 108, 168, 108, 208, 108, 248, 108, 32, 109, 72, 109, 112, 109,
-152, 109, 192, 109, 232, 109, 16, 110, 56, 110, 96, 110, 136, 110, 176, 110,
-216, 110, 0, 111, 40, 111, 80, 111, 120, 111, 160, 111, 200, 111, 240, 111,
-24, 112, 64, 112, 104, 112, 144, 112, 184, 112, 224, 112, 8, 113, 48, 113,
-88, 113, 128, 113, 168, 113, 208, 113, 248, 113, 32, 114, 72, 114, 112, 114,
-152, 114, 192, 114, 232, 114, 16, 115, 56, 115, 96, 115, 136, 115, 176, 115,
-216, 115, 0, 116, 40, 116, 80, 116, 120, 116, 160, 116, 200, 116, 240, 116,
-24, 117, 64, 117, 104, 117, 144, 117, 184, 117, 224, 117, 8, 118, 48, 118,
-88, 118, 128, 118, 168, 118, 208, 118, 248, 118, 32, 119, 72, 119, 112, 119,
-152, 119, 192, 119, 232, 119, 16, 120, 56, 120, 96, 120, 136, 120, 176, 120,
-216, 120, 0, 121, 40, 121, 80, 121, 120, 121, 160, 121, 200, 121, 240, 121,
-24, 122, 64, 122, 104, 122, 144, 122, 184, 122, 224, 122, 8, 123, 48, 123,
-88, 123, 128, 123, 168, 123, 208, 123, 248, 123, 32, 124, 72, 124, 112, 124,
-152, 124, 192, 124, 232, 124, 16, 125, 56, 125, 96, 125, 136, 125, 176, 125,
-216, 125, 0, 126, 40, 126, 80, 126, 120, 126, 160, 126, 200, 126, 240, 126,
-24, 127, 64, 127, 104, 127, 144, 127, 184, 127, 224, 127, 8, 128, 48, 128,
-88, 128, 128, 128, 168, 128, 208, 128, 248, 128, 32, 129, 72, 129, 112, 129,
-152, 129, 192, 129, 232, 129, 16, 130, 56, 130, 96, 130, 136, 130, 176, 130,
-216, 130, 0, 131, 40, 131, 80, 131, 120, 131, 160, 131, 200, 131, 240, 131,
-24, 132, 64, 132, 104, 132, 144, 132, 184, 132, 224, 132, 8, 133, 48, 133,
-88, 133, 128, 133, 168, 133, 208, 133, 248, 133, 32, 134, 72, 134, 112, 134,
-152, 134, 192, 134, 232, 134, 16, 135, 56, 135, 96, 135, 136, 135, 176, 135,
-216, 135, 0, 136, 40, 136, 80, 136, 120, 136, 160, 136, 200, 136, 240, 136,
-24, 137, 64, 137, 104, 137, 144, 137, 184, 137, 224, 137, 8, 138, 48, 138,
-88, 138, 128, 138, 168, 138, 208, 138, 248, 138, 32, 139, 72, 139, 112, 139,
-152, 139, 192, 139, 232, 139, 16, 140, 56, 140, 96, 140, 136, 140, 176, 140,
-216, 140, 0, 141, 40, 141, 80, 141, 120, 141, 160, 141, 200, 141, 240, 141,
-24, 142, 64, 142, 104, 142, 144, 142, 184, 142, 224, 142, 8, 143, 48, 143,
-88, 143, 128, 143, 168, 143, 208, 143, 248, 143, 32, 144, 72, 144, 112, 144,
-152, 144, 192, 144, 232, 144, 16, 145, 56, 145, 96, 145, 136, 145, 176, 145,
-216, 145, 0, 146, 40, 146, 80, 146, 120, 146, 160, 146, 200, 146, 240, 146,
-24, 147, 64, 147, 104, 147, 144, 147, 184, 147, 224, 147, 8, 148, 48, 148,
-88, 148, 128, 148, 168, 148, 208, 148, 248, 148, 32, 149, 72, 149, 112, 149,
-152, 149, 192, 149, 232, 149, 16, 150, 56, 150, 96, 150, 136, 150, 176, 150,
-216, 150, 0, 151, 40, 151, 80, 151, 120, 151, 160, 151, 200, 151, 240, 151,
-24, 152, 64, 152, 104, 152, 144, 152, 184, 152, 224, 152, 8, 153, 48, 153,
-88, 153, 128, 153, 168, 153, 208, 153, 248, 153, 32, 154, 72, 154, 112, 154,
-152, 154, 192, 154, 232, 154, 16, 155, 56, 155, 96, 155, 136, 155, 176, 155,
-216, 155, 0, 156, 40, 156, 80, 156, 120, 156, 160, 156, 200, 156, 240, 156,
-24, 157, 64, 157, 104, 157, 144, 157, 184, 157, 224, 157, 8, 158, 48, 158,
-88, 158, 128, 158, 168, 158, 208, 158, 248, 158, 32, 159, 72, 159, 112, 159,
-152, 159, 192, 159, 232, 159, 16, 160, 56, 160, 96, 160, 136, 160, 176, 160,
-216, 160, 0, 161, 40, 161, 80, 161, 120, 161, 160, 161, 200, 161, 240, 161,
-24, 162, 64, 162, 104, 162, 144, 162, 184, 162, 224, 162, 8, 163, 48, 163,
-88, 163, 128, 163, 168, 163, 208, 163, 248, 163, 32, 164, 72, 164, 112, 164,
-152, 164, 192, 164, 232, 164, 16, 165, 56, 165, 96, 165, 136, 165, 176, 165,
-216, 165, 0, 166, 40, 166, 80, 166, 120, 166, 160, 166, 200, 166, 240, 166,
-24, 167, 64, 167, 104, 167, 144, 167, 184, 167, 224, 167, 8, 168, 48, 168,
-88, 168, 128, 168, 168, 168, 208, 168, 248, 168, 32, 169, 72, 169, 112, 169,
-152, 169, 192, 169, 232, 169, 16, 170, 56, 170, 96, 170, 136, 170, 176, 170,
-216, 170, 0, 171, 40, 171, 80, 171, 120, 171, 160, 171, 200, 171, 240, 171,
-24, 172, 64, 172, 104, 172, 144, 172, 184, 172, 224, 172, 8, 173, 48, 173,
-88, 173, 128, 173, 168, 173, 208, 173, 248, 173, 32, 174, 72, 174, 112, 174,
-152, 174, 192, 174, 232, 174, 16, 175, 56, 175, 96, 175, 136, 175, 176, 175,
-216, 175, 0, 176, 40, 176, 80, 176, 120, 176, 160, 176, 200, 176, 240, 176,
-24, 177, 64, 177, 104, 177, 144, 177, 184, 177, 224, 177, 8, 178, 48, 178,
-88, 178, 128, 178, 168, 178, 208, 178, 248, 178, 32, 179, 72, 179, 112, 179,
-152, 179, 192, 179, 232, 179, 16, 180, 56, 180, 96, 180, 136, 180, 176, 180,
-216, 180, 0, 181, 40, 181, 80, 181, 120, 181, 160, 181, 200, 181, 240, 181,
-24, 182, 64, 182, 104, 182, 144, 182, 184, 182, 224, 182, 8, 183, 48, 183,
-88, 183, 128, 183, 168, 183, 208, 183, 248, 183, 32, 184, 72, 184, 112, 184,
-152, 184, 192, 184, 232, 184, 16, 185, 56, 185, 96, 185, 136, 185, 176, 185,
-216, 185, 0, 186, 40, 186, 80, 186, 120, 186, 160, 186, 200, 186, 240, 186,
-24, 187, 64, 187, 104, 187, 144, 187, 184, 187, 224, 187, 8, 188, 48, 188,
-88, 188, 128, 188, 168, 188, 208, 188, 248, 188, 32, 189, 72, 189, 112, 189,
-152, 189, 192, 189, 232, 189, 16, 190, 56, 190, 96, 190, 136, 190, 176, 190,
-216, 190, 0, 191, 40, 191, 80, 191, 120, 191, 160, 191, 200, 191, 240, 191,
-24, 192, 64, 192, 104, 192, 144, 192, 184, 192, 224, 192, 8, 193, 48, 193,
-88, 193, 128, 193, 168, 193, 208, 193, 248, 193, 32, 194, 72, 194, 112, 194,
-152, 194, 192, 194, 232, 194, 16, 195, 56, 195, 96, 195, 136, 195, 176, 195,
-216, 195, 0, 196, 40, 196, 80, 196, 120, 196, 160, 196, 200, 196, 240, 196,
-24, 197, 64, 197, 104, 197, 144, 197, 184, 197, 224, 197, 8, 198, 48, 198,
-88, 198, 128, 198, 168, 198, 208, 198, 248, 198, 32, 199, 72, 199, 112, 199,
-152, 199, 192, 199, 232, 199, 16, 200, 56, 200, 96, 200, 136, 200, 176, 200,
-216, 200, 0, 201, 40, 201, 80, 201, 120, 201, 160, 201, 200, 201, 240, 201,
-24, 202, 64, 202, 104, 202, 144, 202, 184, 202, 224, 202, 8, 203, 48, 203,
-88, 203, 128, 203, 168, 203, 208, 203, 248, 203, 32, 204, 72, 204, 112, 204,
-152, 204, 192, 204, 232, 204, 16, 205, 56, 205, 96, 205, 136, 205, 176, 205,
-216, 205, 0, 206, 40, 206, 80, 206, 120, 206, 160, 206, 200, 206, 240, 206,
-24, 207, 64, 207, 104, 207, 144, 207, 184, 207, 224, 207, 8, 208, 48, 208,
-88, 208, 128, 208, 168, 208, 208, 208, 248, 208, 32, 209, 72, 209, 112, 209,
-152, 209, 192, 209, 232, 209, 16, 210, 56, 210, 96, 210, 136, 210, 176, 210,
-216, 210, 0, 211, 40, 211, 80, 211, 120, 211, 160, 211, 200, 211, 240, 211,
-24, 212, 64, 212, 104, 212, 144, 212, 184, 212, 224, 212, 8, 213, 48, 213,
-88, 213, 128, 213, 168, 213, 208, 213, 248, 213, 32, 214, 72, 214, 112, 214,
-152, 214, 192, 214, 232, 214, 16, 215, 56, 215, 96, 215, 136, 215, 176, 215,
-216, 215, 0, 224, 40, 224, 80, 224, 120, 224, 160, 224, 200, 224, 240, 224,
-24, 225, 64, 225, 104, 225, 144, 225, 184, 225, 224, 225, 8, 226, 48, 226,
-88, 226, 128, 226, 168, 226, 208, 226, 248, 226, 32, 227, 72, 227, 112, 227,
-152, 227, 192, 227, 232, 227, 16, 228, 56, 228, 96, 228, 136, 228, 176, 228,
-216, 228, 0, 229, 40, 229, 80, 229, 120, 229, 160, 229, 200, 229, 240, 229,
-24, 230, 64, 230, 104, 230, 144, 230, 184, 230, 224, 230, 8, 231, 48, 231,
-88, 231, 128, 231, 168, 231, 208, 231, 248, 231, 32, 232, 72, 232, 112, 232,
-152, 232, 192, 232, 232, 232, 16, 233, 56, 233, 96, 233, 136, 233, 176, 233,
-216, 233, 0, 234, 40, 234, 80, 234, 120, 234, 160, 234, 200, 234, 240, 234,
-24, 235, 64, 235, 104, 235, 144, 235, 184, 235, 224, 235, 8, 236, 48, 236,
-88, 236, 128, 236, 168, 236, 208, 236, 248, 236, 32, 237, 72, 237, 112, 237,
-152, 237, 192, 237, 232, 237, 16, 238, 56, 238, 96, 238, 136, 238, 176, 238,
-216, 238, 0, 239, 40, 239, 80, 239, 120, 239, 160, 239, 200, 239, 240, 239,
-24, 240, 64, 240, 104, 240, 144, 240, 184, 240, 224, 240, 8, 241, 48, 241,
-88, 241, 128, 241, 168, 241, 208, 241, 248, 241, 32, 242, 72, 242, 112, 242,
-152, 242, 192, 242, 232, 242, 16, 243, 56, 243, 96, 243, 136, 243, 176, 243,
-216, 243, 0, 244, 40, 244, 80, 244, 120, 244, 160, 244, 200, 244, 240, 244,
-24, 245, 64, 245, 104, 245, 144, 245, 184, 245, 224, 245, 8, 246, 48, 246,
-88, 246, 128, 246, 168, 246, 208, 246, 248, 246, 32, 247, 72, 247, 112, 247,
-152, 247, 192, 247, 232, 247, 16, 248, 56, 248, 96, 248, 136, 248, 176, 248,
-216, 248, 0, 249, 40, 249, 80, 249, 120, 249, 160, 249, 200, 249, 240, 249,
-24, 250, 64, 250, 104, 250, 144, 250, 184, 250, 224, 250, 8, 251, 48, 251,
-88, 251, 128, 251, 168, 251, 208, 251, 248, 251, 32, 252, 72, 252, 112, 252,
-152, 252, 192, 252, 232, 252, 16, 253, 56, 253, 96, 253, 136, 253, 176, 253,
-216, 253, 0, 254, 40, 254, 80, 254, 120, 254, 160, 254, 200, 254, 240, 254,
-24, 255, 64, 255, 104, 255, 144, 255, 184, 255, 224, 255
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_8.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_8.java
deleted file mode 100644
index fb3e4ba..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_UTF_8.java
+++ /dev/null
@@ -1,480 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_MultiByte_UTF_8 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "UTF-8";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
-144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
-160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
-176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
-192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
-208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
-224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
-240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-256, 296, 336, 376, 416, 456, 496, 536, 576, 616, 656, 696, 736, 776, 816, 856,
-896, 936, 976, 1016, 1056, 1096, 1136, 1176, 1216, 1256, 1296, 1336, 1376, 1416, 1456, 1496,
-1536, 1576, 1616, 1656, 1696, 1736, 1776, 1816, 1856, 1896, 1936, 1976, 2016, 2056, 2096, 2136,
-2176, 2216, 2256, 2296, 2336, 2376, 2416, 2456, 2496, 2536, 2576, 2616, 2656, 2696, 2736, 2776,
-2816, 2856, 2896, 2936, 2976, 3016, 3056, 3096, 3136, 3176, 3216, 3256, 3296, 3336, 3376, 3416,
-3456, 3496, 3536, 3576, 3616, 3656, 3696, 3736, 3776, 3816, 3856, 3896, 3936, 3976, 4016, 4056,
-4096, 4136, 4176, 4216, 4256, 4296, 4336, 4376, 4416, 4456, 4496, 4536, 4576, 4616, 4656, 4696,
-4736, 4776, 4816, 4856, 4896, 4936, 4976, 5016, 5056, 5096, 5136, 5176, 5216, 5256, 5296, 5336,
-5376, 5416, 5456, 5496, 5536, 5576, 5616, 5656, 5696, 5736, 5776, 5816, 5856, 5896, 5936, 5976,
-6016, 6056, 6096, 6136, 6176, 6216, 6256, 6296, 6336, 6376, 6416, 6456, 6496, 6536, 6576, 6616,
-6656, 6696, 6736, 6776, 6816, 6856, 6896, 6936, 6976, 7016, 7056, 7096, 7136, 7176, 7216, 7256,
-7296, 7336, 7376, 7416, 7456, 7496, 7536, 7576, 7616, 7656, 7696, 7736, 7776, 7816, 7856, 7896,
-7936, 7976, 8016, 8056, 8096, 8136, 8176, 8216, 8256, 8296, 8336, 8376, 8416, 8456, 8496, 8536,
-8576, 8616, 8656, 8696, 8736, 8776, 8816, 8856, 8896, 8936, 8976, 9016, 9056, 9096, 9136, 9176,
-9216, 9256, 9296, 9336, 9376, 9416, 9456, 9496, 9536, 9576, 9616, 9656, 9696, 9736, 9776, 9816,
-9856, 9896, 9936, 9976, 10016, 10056, 10096, 10136, 10176, 10216, 10256, 10296, 10336, 10376, 10416, 10456,
-10496, 10536, 10576, 10616, 10656, 10696, 10736, 10776, 10816, 10856, 10896, 10936, 10976, 11016, 11056, 11096,
-11136, 11176, 11216, 11256, 11296, 11336, 11376, 11416, 11456, 11496, 11536, 11576, 11616, 11656, 11696, 11736,
-11776, 11816, 11856, 11896, 11936, 11976, 12016, 12056, 12096, 12136, 12176, 12216, 12256, 12296, 12336, 12376,
-12416, 12456, 12496, 12536, 12576, 12616, 12656, 12696, 12736, 12776, 12816, 12856, 12896, 12936, 12976, 13016,
-13056, 13096, 13136, 13176, 13216, 13256, 13296, 13336, 13376, 13416, 13456, 13496, 13536, 13576, 13616, 13656,
-13696, 13736, 13776, 13816, 13856, 13896, 13936, 13976, 14016, 14056, 14096, 14136, 14176, 14216, 14256, 14296,
-14336, 14376, 14416, 14456, 14496, 14536, 14576, 14616, 14656, 14696, 14736, 14776, 14816, 14856, 14896, 14936,
-14976, 15016, 15056, 15096, 15136, 15176, 15216, 15256, 15296, 15336, 15376, 15416, 15456, 15496, 15536, 15576,
-15616, 15656, 15696, 15736, 15776, 15816, 15856, 15896, 15936, 15976, 16016, 16056, 16096, 16136, 16176, 16216,
-16256, 16296, 16336, 16376, 16416, 16456, 16496, 16536, 16576, 16616, 16656, 16696, 16736, 16776, 16816, 16856,
-16896, 16936, 16976, 17016, 17056, 17096, 17136, 17176, 17216, 17256, 17296, 17336, 17376, 17416, 17456, 17496,
-17536, 17576, 17616, 17656, 17696, 17736, 17776, 17816, 17856, 17896, 17936, 17976, 18016, 18056, 18096, 18136,
-18176, 18216, 18256, 18296, 18336, 18376, 18416, 18456, 18496, 18536, 18576, 18616, 18656, 18696, 18736, 18776,
-18816, 18856, 18896, 18936, 18976, 19016, 19056, 19096, 19136, 19176, 19216, 19256, 19296, 19336, 19376, 19416,
-19456, 19496, 19536, 19576, 19616, 19656, 19696, 19736, 19776, 19816, 19856, 19896, 19936, 19976, 20016, 20056,
-20096, 20136, 20176, 20216, 20256, 20296, 20336, 20376, 20416, 20456, 20496, 20536, 20576, 20616, 20656, 20696,
-20736, 20776, 20816, 20856, 20896, 20936, 20976, 21016, 21056, 21096, 21136, 21176, 21216, 21256, 21296, 21336,
-21376, 21416, 21456, 21496, 21536, 21576, 21616, 21656, 21696, 21736, 21776, 21816, 21856, 21896, 21936, 21976,
-22016, 22056, 22096, 22136, 22176, 22216, 22256, 22296, 22336, 22376, 22416, 22456, 22496, 22536, 22576, 22616,
-22656, 22696, 22736, 22776, 22816, 22856, 22896, 22936, 22976, 23016, 23056, 23096, 23136, 23176, 23216, 23256,
-23296, 23336, 23376, 23416, 23456, 23496, 23536, 23576, 23616, 23656, 23696, 23736, 23776, 23816, 23856, 23896,
-23936, 23976, 24016, 24056, 24096, 24136, 24176, 24216, 24256, 24296, 24336, 24376, 24416, 24456, 24496, 24536,
-24576, 24616, 24656, 24696, 24736, 24776, 24816, 24856, 24896, 24936, 24976, 25016, 25056, 25096, 25136, 25176,
-25216, 25256, 25296, 25336, 25376, 25416, 25456, 25496, 25536, 25576, 25616, 25656, 25696, 25736, 25776, 25816,
-25856, 25896, 25936, 25976, 26016, 26056, 26096, 26136, 26176, 26216, 26256, 26296, 26336, 26376, 26416, 26456,
-26496, 26536, 26576, 26616, 26656, 26696, 26736, 26776, 26816, 26856, 26896, 26936, 26976, 27016, 27056, 27096,
-27136, 27176, 27216, 27256, 27296, 27336, 27376, 27416, 27456, 27496, 27536, 27576, 27616, 27656, 27696, 27736,
-27776, 27816, 27856, 27896, 27936, 27976, 28016, 28056, 28096, 28136, 28176, 28216, 28256, 28296, 28336, 28376,
-28416, 28456, 28496, 28536, 28576, 28616, 28656, 28696, 28736, 28776, 28816, 28856, 28896, 28936, 28976, 29016,
-29056, 29096, 29136, 29176, 29216, 29256, 29296, 29336, 29376, 29416, 29456, 29496, 29536, 29576, 29616, 29656,
-29696, 29736, 29776, 29816, 29856, 29896, 29936, 29976, 30016, 30056, 30096, 30136, 30176, 30216, 30256, 30296,
-30336, 30376, 30416, 30456, 30496, 30536, 30576, 30616, 30656, 30696, 30736, 30776, 30816, 30856, 30896, 30936,
-30976, 31016, 31056, 31096, 31136, 31176, 31216, 31256, 31296, 31336, 31376, 31416, 31456, 31496, 31536, 31576,
-31616, 31656, 31696, 31736, 31776, 31816, 31856, 31896, 31936, 31976, 32016, 32056, 32096, 32136, 32176, 32216,
-32256, 32296, 32336, 32376, 32416, 32456, 32496, 32536, 32576, 32616, 32656, 32696, 32736, 32776, 32816, 32856,
-32896, 32936, 32976, 33016, 33056, 33096, 33136, 33176, 33216, 33256, 33296, 33336, 33376, 33416, 33456, 33496,
-33536, 33576, 33616, 33656, 33696, 33736, 33776, 33816, 33856, 33896, 33936, 33976, 34016, 34056, 34096, 34136,
-34176, 34216, 34256, 34296, 34336, 34376, 34416, 34456, 34496, 34536, 34576, 34616, 34656, 34696, 34736, 34776,
-34816, 34856, 34896, 34936, 34976, 35016, 35056, 35096, 35136, 35176, 35216, 35256, 35296, 35336, 35376, 35416,
-35456, 35496, 35536, 35576, 35616, 35656, 35696, 35736, 35776, 35816, 35856, 35896, 35936, 35976, 36016, 36056,
-36096, 36136, 36176, 36216, 36256, 36296, 36336, 36376, 36416, 36456, 36496, 36536, 36576, 36616, 36656, 36696,
-36736, 36776, 36816, 36856, 36896, 36936, 36976, 37016, 37056, 37096, 37136, 37176, 37216, 37256, 37296, 37336,
-37376, 37416, 37456, 37496, 37536, 37576, 37616, 37656, 37696, 37736, 37776, 37816, 37856, 37896, 37936, 37976,
-38016, 38056, 38096, 38136, 38176, 38216, 38256, 38296, 38336, 38376, 38416, 38456, 38496, 38536, 38576, 38616,
-38656, 38696, 38736, 38776, 38816, 38856, 38896, 38936, 38976, 39016, 39056, 39096, 39136, 39176, 39216, 39256,
-39296, 39336, 39376, 39416, 39456, 39496, 39536, 39576, 39616, 39656, 39696, 39736, 39776, 39816, 39856, 39896,
-39936, 39976, 40016, 40056, 40096, 40136, 40176, 40216, 40256, 40296, 40336, 40376, 40416, 40456, 40496, 40536,
-40576, 40616, 40656, 40696, 40736, 40776, 40816, 40856, 40896, 40936, 40976, 41016, 41056, 41096, 41136, 41176,
-41216, 41256, 41296, 41336, 41376, 41416, 41456, 41496, 41536, 41576, 41616, 41656, 41696, 41736, 41776, 41816,
-41856, 41896, 41936, 41976, 42016, 42056, 42096, 42136, 42176, 42216, 42256, 42296, 42336, 42376, 42416, 42456,
-42496, 42536, 42576, 42616, 42656, 42696, 42736, 42776, 42816, 42856, 42896, 42936, 42976, 43016, 43056, 43096,
-43136, 43176, 43216, 43256, 43296, 43336, 43376, 43416, 43456, 43496, 43536, 43576, 43616, 43656, 43696, 43736,
-43776, 43816, 43856, 43896, 43936, 43976, 44016, 44056, 44096, 44136, 44176, 44216, 44256, 44296, 44336, 44376,
-44416, 44456, 44496, 44536, 44576, 44616, 44656, 44696, 44736, 44776, 44816, 44856, 44896, 44936, 44976, 45016,
-45056, 45096, 45136, 45176, 45216, 45256, 45296, 45336, 45376, 45416, 45456, 45496, 45536, 45576, 45616, 45656,
-45696, 45736, 45776, 45816, 45856, 45896, 45936, 45976, 46016, 46056, 46096, 46136, 46176, 46216, 46256, 46296,
-46336, 46376, 46416, 46456, 46496, 46536, 46576, 46616, 46656, 46696, 46736, 46776, 46816, 46856, 46896, 46936,
-46976, 47016, 47056, 47096, 47136, 47176, 47216, 47256, 47296, 47336, 47376, 47416, 47456, 47496, 47536, 47576,
-47616, 47656, 47696, 47736, 47776, 47816, 47856, 47896, 47936, 47976, 48016, 48056, 48096, 48136, 48176, 48216,
-48256, 48296, 48336, 48376, 48416, 48456, 48496, 48536, 48576, 48616, 48656, 48696, 48736, 48776, 48816, 48856,
-48896, 48936, 48976, 49016, 49056, 49096, 49136, 49176, 49216, 49256, 49296, 49336, 49376, 49416, 49456, 49496,
-49536, 49576, 49616, 49656, 49696, 49736, 49776, 49816, 49856, 49896, 49936, 49976, 50016, 50056, 50096, 50136,
-50176, 50216, 50256, 50296, 50336, 50376, 50416, 50456, 50496, 50536, 50576, 50616, 50656, 50696, 50736, 50776,
-50816, 50856, 50896, 50936, 50976, 51016, 51056, 51096, 51136, 51176, 51216, 51256, 51296, 51336, 51376, 51416,
-51456, 51496, 51536, 51576, 51616, 51656, 51696, 51736, 51776, 51816, 51856, 51896, 51936, 51976, 52016, 52056,
-52096, 52136, 52176, 52216, 52256, 52296, 52336, 52376, 52416, 52456, 52496, 52536, 52576, 52616, 52656, 52696,
-52736, 52776, 52816, 52856, 52896, 52936, 52976, 53016, 53056, 53096, 53136, 53176, 53216, 53256, 53296, 53336,
-53376, 53416, 53456, 53496, 53536, 53576, 53616, 53656, 53696, 53736, 53776, 53816, 53856, 53896, 53936, 53976,
-54016, 54056, 54096, 54136, 54176, 54216, 54256, 54296, 54336, 54376, 54416, 54456, 54496, 54536, 54576, 54616,
-54656, 54696, 54736, 54776, 54816, 54856, 54896, 54936, 54976, 55016, 55056, 55096, 55136, 55176, 55216, 55256,
-57344, 57384, 57424, 57464, 57504, 57544, 57584, 57624, 57664, 57704, 57744, 57784, 57824, 57864, 57904, 57944,
-57984, 58024, 58064, 58104, 58144, 58184, 58224, 58264, 58304, 58344, 58384, 58424, 58464, 58504, 58544, 58584,
-58624, 58664, 58704, 58744, 58784, 58824, 58864, 58904, 58944, 58984, 59024, 59064, 59104, 59144, 59184, 59224,
-59264, 59304, 59344, 59384, 59424, 59464, 59504, 59544, 59584, 59624, 59664, 59704, 59744, 59784, 59824, 59864,
-59904, 59944, 59984, 60024, 60064, 60104, 60144, 60184, 60224, 60264, 60304, 60344, 60384, 60424, 60464, 60504,
-60544, 60584, 60624, 60664, 60704, 60744, 60784, 60824, 60864, 60904, 60944, 60984, 61024, 61064, 61104, 61144,
-61184, 61224, 61264, 61304, 61344, 61384, 61424, 61464, 61504, 61544, 61584, 61624, 61664, 61704, 61744, 61784,
-61824, 61864, 61904, 61944, 61984, 62024, 62064, 62104, 62144, 62184, 62224, 62264, 62304, 62344, 62384, 62424,
-62464, 62504, 62544, 62584, 62624, 62664, 62704, 62744, 62784, 62824, 62864, 62904, 62944, 62984, 63024, 63064,
-63104, 63144, 63184, 63224, 63264, 63304, 63344, 63384, 63424, 63464, 63504, 63544, 63584, 63624, 63664, 63704,
-63744, 63784, 63824, 63864, 63904, 63944, 63984, 64024, 64064, 64104, 64144, 64184, 64224, 64264, 64304, 64344,
-64384, 64424, 64464, 64504, 64544, 64584, 64624, 64664, 64704, 64744, 64784, 64824, 64864, 64904, 64944, 64984,
-65024, 65064, 65104, 65144, 65184, 65224, 65264, 65304, 65344, 65384, 65424, 65464, 65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-194, 128, 194, 129, 194, 130, 194, 131, 194, 132, 194, 133, 194, 134, 194, 135,
-194, 136, 194, 137, 194, 138, 194, 139, 194, 140, 194, 141, 194, 142, 194, 143,
-194, 144, 194, 145, 194, 146, 194, 147, 194, 148, 194, 149, 194, 150, 194, 151,
-194, 152, 194, 153, 194, 154, 194, 155, 194, 156, 194, 157, 194, 158, 194, 159,
-194, 160, 194, 161, 194, 162, 194, 163, 194, 164, 194, 165, 194, 166, 194, 167,
-194, 168, 194, 169, 194, 170, 194, 171, 194, 172, 194, 173, 194, 174, 194, 175,
-194, 176, 194, 177, 194, 178, 194, 179, 194, 180, 194, 181, 194, 182, 194, 183,
-194, 184, 194, 185, 194, 186, 194, 187, 194, 188, 194, 189, 194, 190, 194, 191,
-195, 128, 195, 129, 195, 130, 195, 131, 195, 132, 195, 133, 195, 134, 195, 135,
-195, 136, 195, 137, 195, 138, 195, 139, 195, 140, 195, 141, 195, 142, 195, 143,
-195, 144, 195, 145, 195, 146, 195, 147, 195, 148, 195, 149, 195, 150, 195, 151,
-195, 152, 195, 153, 195, 154, 195, 155, 195, 156, 195, 157, 195, 158, 195, 159,
-195, 160, 195, 161, 195, 162, 195, 163, 195, 164, 195, 165, 195, 166, 195, 167,
-195, 168, 195, 169, 195, 170, 195, 171, 195, 172, 195, 173, 195, 174, 195, 175,
-195, 176, 195, 177, 195, 178, 195, 179, 195, 180, 195, 181, 195, 182, 195, 183,
-195, 184, 195, 185, 195, 186, 195, 187, 195, 188, 195, 189, 195, 190, 195, 191,
-196, 128, 196, 168, 197, 144, 197, 184, 198, 160, 199, 136, 199, 176, 200, 152,
-201, 128, 201, 168, 202, 144, 202, 184, 203, 160, 204, 136, 204, 176, 205, 152,
-206, 128, 206, 168, 207, 144, 207, 184, 208, 160, 209, 136, 209, 176, 210, 152,
-211, 128, 211, 168, 212, 144, 212, 184, 213, 160, 214, 136, 214, 176, 215, 152,
-216, 128, 216, 168, 217, 144, 217, 184, 218, 160, 219, 136, 219, 176, 220, 152,
-221, 128, 221, 168, 222, 144, 222, 184, 223, 160, 224, 160, 136, 224, 160, 176,
-224, 161, 152, 224, 162, 128, 224, 162, 168, 224, 163, 144, 224, 163, 184, 224,
-164, 160, 224, 165, 136, 224, 165, 176, 224, 166, 152, 224, 167, 128, 224, 167,
-168, 224, 168, 144, 224, 168, 184, 224, 169, 160, 224, 170, 136, 224, 170, 176,
-224, 171, 152, 224, 172, 128, 224, 172, 168, 224, 173, 144, 224, 173, 184, 224,
-174, 160, 224, 175, 136, 224, 175, 176, 224, 176, 152, 224, 177, 128, 224, 177,
-168, 224, 178, 144, 224, 178, 184, 224, 179, 160, 224, 180, 136, 224, 180, 176,
-224, 181, 152, 224, 182, 128, 224, 182, 168, 224, 183, 144, 224, 183, 184, 224,
-184, 160, 224, 185, 136, 224, 185, 176, 224, 186, 152, 224, 187, 128, 224, 187,
-168, 224, 188, 144, 224, 188, 184, 224, 189, 160, 224, 190, 136, 224, 190, 176,
-224, 191, 152, 225, 128, 128, 225, 128, 168, 225, 129, 144, 225, 129, 184, 225,
-130, 160, 225, 131, 136, 225, 131, 176, 225, 132, 152, 225, 133, 128, 225, 133,
-168, 225, 134, 144, 225, 134, 184, 225, 135, 160, 225, 136, 136, 225, 136, 176,
-225, 137, 152, 225, 138, 128, 225, 138, 168, 225, 139, 144, 225, 139, 184, 225,
-140, 160, 225, 141, 136, 225, 141, 176, 225, 142, 152, 225, 143, 128, 225, 143,
-168, 225, 144, 144, 225, 144, 184, 225, 145, 160, 225, 146, 136, 225, 146, 176,
-225, 147, 152, 225, 148, 128, 225, 148, 168, 225, 149, 144, 225, 149, 184, 225,
-150, 160, 225, 151, 136, 225, 151, 176, 225, 152, 152, 225, 153, 128, 225, 153,
-168, 225, 154, 144, 225, 154, 184, 225, 155, 160, 225, 156, 136, 225, 156, 176,
-225, 157, 152, 225, 158, 128, 225, 158, 168, 225, 159, 144, 225, 159, 184, 225,
-160, 160, 225, 161, 136, 225, 161, 176, 225, 162, 152, 225, 163, 128, 225, 163,
-168, 225, 164, 144, 225, 164, 184, 225, 165, 160, 225, 166, 136, 225, 166, 176,
-225, 167, 152, 225, 168, 128, 225, 168, 168, 225, 169, 144, 225, 169, 184, 225,
-170, 160, 225, 171, 136, 225, 171, 176, 225, 172, 152, 225, 173, 128, 225, 173,
-168, 225, 174, 144, 225, 174, 184, 225, 175, 160, 225, 176, 136, 225, 176, 176,
-225, 177, 152, 225, 178, 128, 225, 178, 168, 225, 179, 144, 225, 179, 184, 225,
-180, 160, 225, 181, 136, 225, 181, 176, 225, 182, 152, 225, 183, 128, 225, 183,
-168, 225, 184, 144, 225, 184, 184, 225, 185, 160, 225, 186, 136, 225, 186, 176,
-225, 187, 152, 225, 188, 128, 225, 188, 168, 225, 189, 144, 225, 189, 184, 225,
-190, 160, 225, 191, 136, 225, 191, 176, 226, 128, 152, 226, 129, 128, 226, 129,
-168, 226, 130, 144, 226, 130, 184, 226, 131, 160, 226, 132, 136, 226, 132, 176,
-226, 133, 152, 226, 134, 128, 226, 134, 168, 226, 135, 144, 226, 135, 184, 226,
-136, 160, 226, 137, 136, 226, 137, 176, 226, 138, 152, 226, 139, 128, 226, 139,
-168, 226, 140, 144, 226, 140, 184, 226, 141, 160, 226, 142, 136, 226, 142, 176,
-226, 143, 152, 226, 144, 128, 226, 144, 168, 226, 145, 144, 226, 145, 184, 226,
-146, 160, 226, 147, 136, 226, 147, 176, 226, 148, 152, 226, 149, 128, 226, 149,
-168, 226, 150, 144, 226, 150, 184, 226, 151, 160, 226, 152, 136, 226, 152, 176,
-226, 153, 152, 226, 154, 128, 226, 154, 168, 226, 155, 144, 226, 155, 184, 226,
-156, 160, 226, 157, 136, 226, 157, 176, 226, 158, 152, 226, 159, 128, 226, 159,
-168, 226, 160, 144, 226, 160, 184, 226, 161, 160, 226, 162, 136, 226, 162, 176,
-226, 163, 152, 226, 164, 128, 226, 164, 168, 226, 165, 144, 226, 165, 184, 226,
-166, 160, 226, 167, 136, 226, 167, 176, 226, 168, 152, 226, 169, 128, 226, 169,
-168, 226, 170, 144, 226, 170, 184, 226, 171, 160, 226, 172, 136, 226, 172, 176,
-226, 173, 152, 226, 174, 128, 226, 174, 168, 226, 175, 144, 226, 175, 184, 226,
-176, 160, 226, 177, 136, 226, 177, 176, 226, 178, 152, 226, 179, 128, 226, 179,
-168, 226, 180, 144, 226, 180, 184, 226, 181, 160, 226, 182, 136, 226, 182, 176,
-226, 183, 152, 226, 184, 128, 226, 184, 168, 226, 185, 144, 226, 185, 184, 226,
-186, 160, 226, 187, 136, 226, 187, 176, 226, 188, 152, 226, 189, 128, 226, 189,
-168, 226, 190, 144, 226, 190, 184, 226, 191, 160, 227, 128, 136, 227, 128, 176,
-227, 129, 152, 227, 130, 128, 227, 130, 168, 227, 131, 144, 227, 131, 184, 227,
-132, 160, 227, 133, 136, 227, 133, 176, 227, 134, 152, 227, 135, 128, 227, 135,
-168, 227, 136, 144, 227, 136, 184, 227, 137, 160, 227, 138, 136, 227, 138, 176,
-227, 139, 152, 227, 140, 128, 227, 140, 168, 227, 141, 144, 227, 141, 184, 227,
-142, 160, 227, 143, 136, 227, 143, 176, 227, 144, 152, 227, 145, 128, 227, 145,
-168, 227, 146, 144, 227, 146, 184, 227, 147, 160, 227, 148, 136, 227, 148, 176,
-227, 149, 152, 227, 150, 128, 227, 150, 168, 227, 151, 144, 227, 151, 184, 227,
-152, 160, 227, 153, 136, 227, 153, 176, 227, 154, 152, 227, 155, 128, 227, 155,
-168, 227, 156, 144, 227, 156, 184, 227, 157, 160, 227, 158, 136, 227, 158, 176,
-227, 159, 152, 227, 160, 128, 227, 160, 168, 227, 161, 144, 227, 161, 184, 227,
-162, 160, 227, 163, 136, 227, 163, 176, 227, 164, 152, 227, 165, 128, 227, 165,
-168, 227, 166, 144, 227, 166, 184, 227, 167, 160, 227, 168, 136, 227, 168, 176,
-227, 169, 152, 227, 170, 128, 227, 170, 168, 227, 171, 144, 227, 171, 184, 227,
-172, 160, 227, 173, 136, 227, 173, 176, 227, 174, 152, 227, 175, 128, 227, 175,
-168, 227, 176, 144, 227, 176, 184, 227, 177, 160, 227, 178, 136, 227, 178, 176,
-227, 179, 152, 227, 180, 128, 227, 180, 168, 227, 181, 144, 227, 181, 184, 227,
-182, 160, 227, 183, 136, 227, 183, 176, 227, 184, 152, 227, 185, 128, 227, 185,
-168, 227, 186, 144, 227, 186, 184, 227, 187, 160, 227, 188, 136, 227, 188, 176,
-227, 189, 152, 227, 190, 128, 227, 190, 168, 227, 191, 144, 227, 191, 184, 228,
-128, 160, 228, 129, 136, 228, 129, 176, 228, 130, 152, 228, 131, 128, 228, 131,
-168, 228, 132, 144, 228, 132, 184, 228, 133, 160, 228, 134, 136, 228, 134, 176,
-228, 135, 152, 228, 136, 128, 228, 136, 168, 228, 137, 144, 228, 137, 184, 228,
-138, 160, 228, 139, 136, 228, 139, 176, 228, 140, 152, 228, 141, 128, 228, 141,
-168, 228, 142, 144, 228, 142, 184, 228, 143, 160, 228, 144, 136, 228, 144, 176,
-228, 145, 152, 228, 146, 128, 228, 146, 168, 228, 147, 144, 228, 147, 184, 228,
-148, 160, 228, 149, 136, 228, 149, 176, 228, 150, 152, 228, 151, 128, 228, 151,
-168, 228, 152, 144, 228, 152, 184, 228, 153, 160, 228, 154, 136, 228, 154, 176,
-228, 155, 152, 228, 156, 128, 228, 156, 168, 228, 157, 144, 228, 157, 184, 228,
-158, 160, 228, 159, 136, 228, 159, 176, 228, 160, 152, 228, 161, 128, 228, 161,
-168, 228, 162, 144, 228, 162, 184, 228, 163, 160, 228, 164, 136, 228, 164, 176,
-228, 165, 152, 228, 166, 128, 228, 166, 168, 228, 167, 144, 228, 167, 184, 228,
-168, 160, 228, 169, 136, 228, 169, 176, 228, 170, 152, 228, 171, 128, 228, 171,
-168, 228, 172, 144, 228, 172, 184, 228, 173, 160, 228, 174, 136, 228, 174, 176,
-228, 175, 152, 228, 176, 128, 228, 176, 168, 228, 177, 144, 228, 177, 184, 228,
-178, 160, 228, 179, 136, 228, 179, 176, 228, 180, 152, 228, 181, 128, 228, 181,
-168, 228, 182, 144, 228, 182, 184, 228, 183, 160, 228, 184, 136, 228, 184, 176,
-228, 185, 152, 228, 186, 128, 228, 186, 168, 228, 187, 144, 228, 187, 184, 228,
-188, 160, 228, 189, 136, 228, 189, 176, 228, 190, 152, 228, 191, 128, 228, 191,
-168, 229, 128, 144, 229, 128, 184, 229, 129, 160, 229, 130, 136, 229, 130, 176,
-229, 131, 152, 229, 132, 128, 229, 132, 168, 229, 133, 144, 229, 133, 184, 229,
-134, 160, 229, 135, 136, 229, 135, 176, 229, 136, 152, 229, 137, 128, 229, 137,
-168, 229, 138, 144, 229, 138, 184, 229, 139, 160, 229, 140, 136, 229, 140, 176,
-229, 141, 152, 229, 142, 128, 229, 142, 168, 229, 143, 144, 229, 143, 184, 229,
-144, 160, 229, 145, 136, 229, 145, 176, 229, 146, 152, 229, 147, 128, 229, 147,
-168, 229, 148, 144, 229, 148, 184, 229, 149, 160, 229, 150, 136, 229, 150, 176,
-229, 151, 152, 229, 152, 128, 229, 152, 168, 229, 153, 144, 229, 153, 184, 229,
-154, 160, 229, 155, 136, 229, 155, 176, 229, 156, 152, 229, 157, 128, 229, 157,
-168, 229, 158, 144, 229, 158, 184, 229, 159, 160, 229, 160, 136, 229, 160, 176,
-229, 161, 152, 229, 162, 128, 229, 162, 168, 229, 163, 144, 229, 163, 184, 229,
-164, 160, 229, 165, 136, 229, 165, 176, 229, 166, 152, 229, 167, 128, 229, 167,
-168, 229, 168, 144, 229, 168, 184, 229, 169, 160, 229, 170, 136, 229, 170, 176,
-229, 171, 152, 229, 172, 128, 229, 172, 168, 229, 173, 144, 229, 173, 184, 229,
-174, 160, 229, 175, 136, 229, 175, 176, 229, 176, 152, 229, 177, 128, 229, 177,
-168, 229, 178, 144, 229, 178, 184, 229, 179, 160, 229, 180, 136, 229, 180, 176,
-229, 181, 152, 229, 182, 128, 229, 182, 168, 229, 183, 144, 229, 183, 184, 229,
-184, 160, 229, 185, 136, 229, 185, 176, 229, 186, 152, 229, 187, 128, 229, 187,
-168, 229, 188, 144, 229, 188, 184, 229, 189, 160, 229, 190, 136, 229, 190, 176,
-229, 191, 152, 230, 128, 128, 230, 128, 168, 230, 129, 144, 230, 129, 184, 230,
-130, 160, 230, 131, 136, 230, 131, 176, 230, 132, 152, 230, 133, 128, 230, 133,
-168, 230, 134, 144, 230, 134, 184, 230, 135, 160, 230, 136, 136, 230, 136, 176,
-230, 137, 152, 230, 138, 128, 230, 138, 168, 230, 139, 144, 230, 139, 184, 230,
-140, 160, 230, 141, 136, 230, 141, 176, 230, 142, 152, 230, 143, 128, 230, 143,
-168, 230, 144, 144, 230, 144, 184, 230, 145, 160, 230, 146, 136, 230, 146, 176,
-230, 147, 152, 230, 148, 128, 230, 148, 168, 230, 149, 144, 230, 149, 184, 230,
-150, 160, 230, 151, 136, 230, 151, 176, 230, 152, 152, 230, 153, 128, 230, 153,
-168, 230, 154, 144, 230, 154, 184, 230, 155, 160, 230, 156, 136, 230, 156, 176,
-230, 157, 152, 230, 158, 128, 230, 158, 168, 230, 159, 144, 230, 159, 184, 230,
-160, 160, 230, 161, 136, 230, 161, 176, 230, 162, 152, 230, 163, 128, 230, 163,
-168, 230, 164, 144, 230, 164, 184, 230, 165, 160, 230, 166, 136, 230, 166, 176,
-230, 167, 152, 230, 168, 128, 230, 168, 168, 230, 169, 144, 230, 169, 184, 230,
-170, 160, 230, 171, 136, 230, 171, 176, 230, 172, 152, 230, 173, 128, 230, 173,
-168, 230, 174, 144, 230, 174, 184, 230, 175, 160, 230, 176, 136, 230, 176, 176,
-230, 177, 152, 230, 178, 128, 230, 178, 168, 230, 179, 144, 230, 179, 184, 230,
-180, 160, 230, 181, 136, 230, 181, 176, 230, 182, 152, 230, 183, 128, 230, 183,
-168, 230, 184, 144, 230, 184, 184, 230, 185, 160, 230, 186, 136, 230, 186, 176,
-230, 187, 152, 230, 188, 128, 230, 188, 168, 230, 189, 144, 230, 189, 184, 230,
-190, 160, 230, 191, 136, 230, 191, 176, 231, 128, 152, 231, 129, 128, 231, 129,
-168, 231, 130, 144, 231, 130, 184, 231, 131, 160, 231, 132, 136, 231, 132, 176,
-231, 133, 152, 231, 134, 128, 231, 134, 168, 231, 135, 144, 231, 135, 184, 231,
-136, 160, 231, 137, 136, 231, 137, 176, 231, 138, 152, 231, 139, 128, 231, 139,
-168, 231, 140, 144, 231, 140, 184, 231, 141, 160, 231, 142, 136, 231, 142, 176,
-231, 143, 152, 231, 144, 128, 231, 144, 168, 231, 145, 144, 231, 145, 184, 231,
-146, 160, 231, 147, 136, 231, 147, 176, 231, 148, 152, 231, 149, 128, 231, 149,
-168, 231, 150, 144, 231, 150, 184, 231, 151, 160, 231, 152, 136, 231, 152, 176,
-231, 153, 152, 231, 154, 128, 231, 154, 168, 231, 155, 144, 231, 155, 184, 231,
-156, 160, 231, 157, 136, 231, 157, 176, 231, 158, 152, 231, 159, 128, 231, 159,
-168, 231, 160, 144, 231, 160, 184, 231, 161, 160, 231, 162, 136, 231, 162, 176,
-231, 163, 152, 231, 164, 128, 231, 164, 168, 231, 165, 144, 231, 165, 184, 231,
-166, 160, 231, 167, 136, 231, 167, 176, 231, 168, 152, 231, 169, 128, 231, 169,
-168, 231, 170, 144, 231, 170, 184, 231, 171, 160, 231, 172, 136, 231, 172, 176,
-231, 173, 152, 231, 174, 128, 231, 174, 168, 231, 175, 144, 231, 175, 184, 231,
-176, 160, 231, 177, 136, 231, 177, 176, 231, 178, 152, 231, 179, 128, 231, 179,
-168, 231, 180, 144, 231, 180, 184, 231, 181, 160, 231, 182, 136, 231, 182, 176,
-231, 183, 152, 231, 184, 128, 231, 184, 168, 231, 185, 144, 231, 185, 184, 231,
-186, 160, 231, 187, 136, 231, 187, 176, 231, 188, 152, 231, 189, 128, 231, 189,
-168, 231, 190, 144, 231, 190, 184, 231, 191, 160, 232, 128, 136, 232, 128, 176,
-232, 129, 152, 232, 130, 128, 232, 130, 168, 232, 131, 144, 232, 131, 184, 232,
-132, 160, 232, 133, 136, 232, 133, 176, 232, 134, 152, 232, 135, 128, 232, 135,
-168, 232, 136, 144, 232, 136, 184, 232, 137, 160, 232, 138, 136, 232, 138, 176,
-232, 139, 152, 232, 140, 128, 232, 140, 168, 232, 141, 144, 232, 141, 184, 232,
-142, 160, 232, 143, 136, 232, 143, 176, 232, 144, 152, 232, 145, 128, 232, 145,
-168, 232, 146, 144, 232, 146, 184, 232, 147, 160, 232, 148, 136, 232, 148, 176,
-232, 149, 152, 232, 150, 128, 232, 150, 168, 232, 151, 144, 232, 151, 184, 232,
-152, 160, 232, 153, 136, 232, 153, 176, 232, 154, 152, 232, 155, 128, 232, 155,
-168, 232, 156, 144, 232, 156, 184, 232, 157, 160, 232, 158, 136, 232, 158, 176,
-232, 159, 152, 232, 160, 128, 232, 160, 168, 232, 161, 144, 232, 161, 184, 232,
-162, 160, 232, 163, 136, 232, 163, 176, 232, 164, 152, 232, 165, 128, 232, 165,
-168, 232, 166, 144, 232, 166, 184, 232, 167, 160, 232, 168, 136, 232, 168, 176,
-232, 169, 152, 232, 170, 128, 232, 170, 168, 232, 171, 144, 232, 171, 184, 232,
-172, 160, 232, 173, 136, 232, 173, 176, 232, 174, 152, 232, 175, 128, 232, 175,
-168, 232, 176, 144, 232, 176, 184, 232, 177, 160, 232, 178, 136, 232, 178, 176,
-232, 179, 152, 232, 180, 128, 232, 180, 168, 232, 181, 144, 232, 181, 184, 232,
-182, 160, 232, 183, 136, 232, 183, 176, 232, 184, 152, 232, 185, 128, 232, 185,
-168, 232, 186, 144, 232, 186, 184, 232, 187, 160, 232, 188, 136, 232, 188, 176,
-232, 189, 152, 232, 190, 128, 232, 190, 168, 232, 191, 144, 232, 191, 184, 233,
-128, 160, 233, 129, 136, 233, 129, 176, 233, 130, 152, 233, 131, 128, 233, 131,
-168, 233, 132, 144, 233, 132, 184, 233, 133, 160, 233, 134, 136, 233, 134, 176,
-233, 135, 152, 233, 136, 128, 233, 136, 168, 233, 137, 144, 233, 137, 184, 233,
-138, 160, 233, 139, 136, 233, 139, 176, 233, 140, 152, 233, 141, 128, 233, 141,
-168, 233, 142, 144, 233, 142, 184, 233, 143, 160, 233, 144, 136, 233, 144, 176,
-233, 145, 152, 233, 146, 128, 233, 146, 168, 233, 147, 144, 233, 147, 184, 233,
-148, 160, 233, 149, 136, 233, 149, 176, 233, 150, 152, 233, 151, 128, 233, 151,
-168, 233, 152, 144, 233, 152, 184, 233, 153, 160, 233, 154, 136, 233, 154, 176,
-233, 155, 152, 233, 156, 128, 233, 156, 168, 233, 157, 144, 233, 157, 184, 233,
-158, 160, 233, 159, 136, 233, 159, 176, 233, 160, 152, 233, 161, 128, 233, 161,
-168, 233, 162, 144, 233, 162, 184, 233, 163, 160, 233, 164, 136, 233, 164, 176,
-233, 165, 152, 233, 166, 128, 233, 166, 168, 233, 167, 144, 233, 167, 184, 233,
-168, 160, 233, 169, 136, 233, 169, 176, 233, 170, 152, 233, 171, 128, 233, 171,
-168, 233, 172, 144, 233, 172, 184, 233, 173, 160, 233, 174, 136, 233, 174, 176,
-233, 175, 152, 233, 176, 128, 233, 176, 168, 233, 177, 144, 233, 177, 184, 233,
-178, 160, 233, 179, 136, 233, 179, 176, 233, 180, 152, 233, 181, 128, 233, 181,
-168, 233, 182, 144, 233, 182, 184, 233, 183, 160, 233, 184, 136, 233, 184, 176,
-233, 185, 152, 233, 186, 128, 233, 186, 168, 233, 187, 144, 233, 187, 184, 233,
-188, 160, 233, 189, 136, 233, 189, 176, 233, 190, 152, 233, 191, 128, 233, 191,
-168, 234, 128, 144, 234, 128, 184, 234, 129, 160, 234, 130, 136, 234, 130, 176,
-234, 131, 152, 234, 132, 128, 234, 132, 168, 234, 133, 144, 234, 133, 184, 234,
-134, 160, 234, 135, 136, 234, 135, 176, 234, 136, 152, 234, 137, 128, 234, 137,
-168, 234, 138, 144, 234, 138, 184, 234, 139, 160, 234, 140, 136, 234, 140, 176,
-234, 141, 152, 234, 142, 128, 234, 142, 168, 234, 143, 144, 234, 143, 184, 234,
-144, 160, 234, 145, 136, 234, 145, 176, 234, 146, 152, 234, 147, 128, 234, 147,
-168, 234, 148, 144, 234, 148, 184, 234, 149, 160, 234, 150, 136, 234, 150, 176,
-234, 151, 152, 234, 152, 128, 234, 152, 168, 234, 153, 144, 234, 153, 184, 234,
-154, 160, 234, 155, 136, 234, 155, 176, 234, 156, 152, 234, 157, 128, 234, 157,
-168, 234, 158, 144, 234, 158, 184, 234, 159, 160, 234, 160, 136, 234, 160, 176,
-234, 161, 152, 234, 162, 128, 234, 162, 168, 234, 163, 144, 234, 163, 184, 234,
-164, 160, 234, 165, 136, 234, 165, 176, 234, 166, 152, 234, 167, 128, 234, 167,
-168, 234, 168, 144, 234, 168, 184, 234, 169, 160, 234, 170, 136, 234, 170, 176,
-234, 171, 152, 234, 172, 128, 234, 172, 168, 234, 173, 144, 234, 173, 184, 234,
-174, 160, 234, 175, 136, 234, 175, 176, 234, 176, 152, 234, 177, 128, 234, 177,
-168, 234, 178, 144, 234, 178, 184, 234, 179, 160, 234, 180, 136, 234, 180, 176,
-234, 181, 152, 234, 182, 128, 234, 182, 168, 234, 183, 144, 234, 183, 184, 234,
-184, 160, 234, 185, 136, 234, 185, 176, 234, 186, 152, 234, 187, 128, 234, 187,
-168, 234, 188, 144, 234, 188, 184, 234, 189, 160, 234, 190, 136, 234, 190, 176,
-234, 191, 152, 235, 128, 128, 235, 128, 168, 235, 129, 144, 235, 129, 184, 235,
-130, 160, 235, 131, 136, 235, 131, 176, 235, 132, 152, 235, 133, 128, 235, 133,
-168, 235, 134, 144, 235, 134, 184, 235, 135, 160, 235, 136, 136, 235, 136, 176,
-235, 137, 152, 235, 138, 128, 235, 138, 168, 235, 139, 144, 235, 139, 184, 235,
-140, 160, 235, 141, 136, 235, 141, 176, 235, 142, 152, 235, 143, 128, 235, 143,
-168, 235, 144, 144, 235, 144, 184, 235, 145, 160, 235, 146, 136, 235, 146, 176,
-235, 147, 152, 235, 148, 128, 235, 148, 168, 235, 149, 144, 235, 149, 184, 235,
-150, 160, 235, 151, 136, 235, 151, 176, 235, 152, 152, 235, 153, 128, 235, 153,
-168, 235, 154, 144, 235, 154, 184, 235, 155, 160, 235, 156, 136, 235, 156, 176,
-235, 157, 152, 235, 158, 128, 235, 158, 168, 235, 159, 144, 235, 159, 184, 235,
-160, 160, 235, 161, 136, 235, 161, 176, 235, 162, 152, 235, 163, 128, 235, 163,
-168, 235, 164, 144, 235, 164, 184, 235, 165, 160, 235, 166, 136, 235, 166, 176,
-235, 167, 152, 235, 168, 128, 235, 168, 168, 235, 169, 144, 235, 169, 184, 235,
-170, 160, 235, 171, 136, 235, 171, 176, 235, 172, 152, 235, 173, 128, 235, 173,
-168, 235, 174, 144, 235, 174, 184, 235, 175, 160, 235, 176, 136, 235, 176, 176,
-235, 177, 152, 235, 178, 128, 235, 178, 168, 235, 179, 144, 235, 179, 184, 235,
-180, 160, 235, 181, 136, 235, 181, 176, 235, 182, 152, 235, 183, 128, 235, 183,
-168, 235, 184, 144, 235, 184, 184, 235, 185, 160, 235, 186, 136, 235, 186, 176,
-235, 187, 152, 235, 188, 128, 235, 188, 168, 235, 189, 144, 235, 189, 184, 235,
-190, 160, 235, 191, 136, 235, 191, 176, 236, 128, 152, 236, 129, 128, 236, 129,
-168, 236, 130, 144, 236, 130, 184, 236, 131, 160, 236, 132, 136, 236, 132, 176,
-236, 133, 152, 236, 134, 128, 236, 134, 168, 236, 135, 144, 236, 135, 184, 236,
-136, 160, 236, 137, 136, 236, 137, 176, 236, 138, 152, 236, 139, 128, 236, 139,
-168, 236, 140, 144, 236, 140, 184, 236, 141, 160, 236, 142, 136, 236, 142, 176,
-236, 143, 152, 236, 144, 128, 236, 144, 168, 236, 145, 144, 236, 145, 184, 236,
-146, 160, 236, 147, 136, 236, 147, 176, 236, 148, 152, 236, 149, 128, 236, 149,
-168, 236, 150, 144, 236, 150, 184, 236, 151, 160, 236, 152, 136, 236, 152, 176,
-236, 153, 152, 236, 154, 128, 236, 154, 168, 236, 155, 144, 236, 155, 184, 236,
-156, 160, 236, 157, 136, 236, 157, 176, 236, 158, 152, 236, 159, 128, 236, 159,
-168, 236, 160, 144, 236, 160, 184, 236, 161, 160, 236, 162, 136, 236, 162, 176,
-236, 163, 152, 236, 164, 128, 236, 164, 168, 236, 165, 144, 236, 165, 184, 236,
-166, 160, 236, 167, 136, 236, 167, 176, 236, 168, 152, 236, 169, 128, 236, 169,
-168, 236, 170, 144, 236, 170, 184, 236, 171, 160, 236, 172, 136, 236, 172, 176,
-236, 173, 152, 236, 174, 128, 236, 174, 168, 236, 175, 144, 236, 175, 184, 236,
-176, 160, 236, 177, 136, 236, 177, 176, 236, 178, 152, 236, 179, 128, 236, 179,
-168, 236, 180, 144, 236, 180, 184, 236, 181, 160, 236, 182, 136, 236, 182, 176,
-236, 183, 152, 236, 184, 128, 236, 184, 168, 236, 185, 144, 236, 185, 184, 236,
-186, 160, 236, 187, 136, 236, 187, 176, 236, 188, 152, 236, 189, 128, 236, 189,
-168, 236, 190, 144, 236, 190, 184, 236, 191, 160, 237, 128, 136, 237, 128, 176,
-237, 129, 152, 237, 130, 128, 237, 130, 168, 237, 131, 144, 237, 131, 184, 237,
-132, 160, 237, 133, 136, 237, 133, 176, 237, 134, 152, 237, 135, 128, 237, 135,
-168, 237, 136, 144, 237, 136, 184, 237, 137, 160, 237, 138, 136, 237, 138, 176,
-237, 139, 152, 237, 140, 128, 237, 140, 168, 237, 141, 144, 237, 141, 184, 237,
-142, 160, 237, 143, 136, 237, 143, 176, 237, 144, 152, 237, 145, 128, 237, 145,
-168, 237, 146, 144, 237, 146, 184, 237, 147, 160, 237, 148, 136, 237, 148, 176,
-237, 149, 152, 237, 150, 128, 237, 150, 168, 237, 151, 144, 237, 151, 184, 237,
-152, 160, 237, 153, 136, 237, 153, 176, 237, 154, 152, 237, 155, 128, 237, 155,
-168, 237, 156, 144, 237, 156, 184, 237, 157, 160, 237, 158, 136, 237, 158, 176,
-237, 159, 152, 238, 128, 128, 238, 128, 168, 238, 129, 144, 238, 129, 184, 238,
-130, 160, 238, 131, 136, 238, 131, 176, 238, 132, 152, 238, 133, 128, 238, 133,
-168, 238, 134, 144, 238, 134, 184, 238, 135, 160, 238, 136, 136, 238, 136, 176,
-238, 137, 152, 238, 138, 128, 238, 138, 168, 238, 139, 144, 238, 139, 184, 238,
-140, 160, 238, 141, 136, 238, 141, 176, 238, 142, 152, 238, 143, 128, 238, 143,
-168, 238, 144, 144, 238, 144, 184, 238, 145, 160, 238, 146, 136, 238, 146, 176,
-238, 147, 152, 238, 148, 128, 238, 148, 168, 238, 149, 144, 238, 149, 184, 238,
-150, 160, 238, 151, 136, 238, 151, 176, 238, 152, 152, 238, 153, 128, 238, 153,
-168, 238, 154, 144, 238, 154, 184, 238, 155, 160, 238, 156, 136, 238, 156, 176,
-238, 157, 152, 238, 158, 128, 238, 158, 168, 238, 159, 144, 238, 159, 184, 238,
-160, 160, 238, 161, 136, 238, 161, 176, 238, 162, 152, 238, 163, 128, 238, 163,
-168, 238, 164, 144, 238, 164, 184, 238, 165, 160, 238, 166, 136, 238, 166, 176,
-238, 167, 152, 238, 168, 128, 238, 168, 168, 238, 169, 144, 238, 169, 184, 238,
-170, 160, 238, 171, 136, 238, 171, 176, 238, 172, 152, 238, 173, 128, 238, 173,
-168, 238, 174, 144, 238, 174, 184, 238, 175, 160, 238, 176, 136, 238, 176, 176,
-238, 177, 152, 238, 178, 128, 238, 178, 168, 238, 179, 144, 238, 179, 184, 238,
-180, 160, 238, 181, 136, 238, 181, 176, 238, 182, 152, 238, 183, 128, 238, 183,
-168, 238, 184, 144, 238, 184, 184, 238, 185, 160, 238, 186, 136, 238, 186, 176,
-238, 187, 152, 238, 188, 128, 238, 188, 168, 238, 189, 144, 238, 189, 184, 238,
-190, 160, 238, 191, 136, 238, 191, 176, 239, 128, 152, 239, 129, 128, 239, 129,
-168, 239, 130, 144, 239, 130, 184, 239, 131, 160, 239, 132, 136, 239, 132, 176,
-239, 133, 152, 239, 134, 128, 239, 134, 168, 239, 135, 144, 239, 135, 184, 239,
-136, 160, 239, 137, 136, 239, 137, 176, 239, 138, 152, 239, 139, 128, 239, 139,
-168, 239, 140, 144, 239, 140, 184, 239, 141, 160, 239, 142, 136, 239, 142, 176,
-239, 143, 152, 239, 144, 128, 239, 144, 168, 239, 145, 144, 239, 145, 184, 239,
-146, 160, 239, 147, 136, 239, 147, 176, 239, 148, 152, 239, 149, 128, 239, 149,
-168, 239, 150, 144, 239, 150, 184, 239, 151, 160, 239, 152, 136, 239, 152, 176,
-239, 153, 152, 239, 154, 128, 239, 154, 168, 239, 155, 144, 239, 155, 184, 239,
-156, 160, 239, 157, 136, 239, 157, 176, 239, 158, 152, 239, 159, 128, 239, 159,
-168, 239, 160, 144, 239, 160, 184, 239, 161, 160, 239, 162, 136, 239, 162, 176,
-239, 163, 152, 239, 164, 128, 239, 164, 168, 239, 165, 144, 239, 165, 184, 239,
-166, 160, 239, 167, 136, 239, 167, 176, 239, 168, 152, 239, 169, 128, 239, 169,
-168, 239, 170, 144, 239, 170, 184, 239, 171, 160, 239, 172, 136, 239, 172, 176,
-239, 173, 152, 239, 174, 128, 239, 174, 168, 239, 175, 144, 239, 175, 184, 239,
-176, 160, 239, 177, 136, 239, 177, 176, 239, 178, 152, 239, 179, 128, 239, 179,
-168, 239, 180, 144, 239, 180, 184, 239, 181, 160, 239, 182, 136, 239, 182, 176,
-239, 183, 152, 239, 184, 128, 239, 184, 168, 239, 185, 144, 239, 185, 184, 239,
-186, 160, 239, 187, 136, 239, 187, 176, 239, 188, 152, 239, 189, 128, 239, 189,
-168, 239, 190, 144, 239, 190, 184, 239, 191, 160
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_x_windows_950.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_x_windows_950.java
deleted file mode 100644
index 0823dc8..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_MultiByte_x_windows_950.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-public class Charset_MultiByte_x_windows_950 extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "x-windows-950";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-167, 175, 176, 177, 183, 215, 247, 711, 713, 913, 945, 8211, 8242, 8364, 8451, 8544,
-8592, 8725, 8756, 8786, 8853, 8895, 9472, 9508, 9552, 9582, 9612, 9650, 9698, 9733, 9792, 12288,
-12318, 12549, 12579, 12963, 13198, 13252, 19968, 19998, 20028, 20060, 20094, 20126, 20160, 20190, 20221, 20253,
-20283, 20313, 20343, 20373, 20403, 20433, 20463, 20493, 20523, 20553, 20584, 20615, 20652, 20682, 20712, 20742,
-20772, 20803, 20833, 20864, 20894, 20924, 20956, 20986, 21020, 21050, 21082, 21112, 21142, 21179, 21209, 21239,
-21269, 21300, 21330, 21360, 21390, 21420, 21450, 21480, 21510, 21540, 21570, 21600, 21630, 21664, 21694, 21726,
-21756, 21786, 21816, 21846, 21877, 21907, 21937, 21967, 21999, 22029, 22060, 22090, 22120, 22150, 22181, 22211,
-22241, 22271, 22302, 22334, 22369, 22400, 22430, 22460, 22492, 22522, 22553, 22583, 22613, 22644, 22675, 22705,
-22735, 22767, 22797, 22827, 22857, 22887, 22917, 22947, 22977, 23008, 23038, 23068, 23100, 23130, 23160, 23191,
-23221, 23253, 23283, 23315, 23346, 23376, 23406, 23436, 23468, 23498, 23528, 23559, 23589, 23620, 23650, 23686,
-23716, 23750, 23784, 23814, 23844, 23874, 23906, 23936, 23966, 23996, 24029, 24061, 24091, 24125, 24155, 24185,
-24215, 24245, 24275, 24305, 24335, 24365, 24395, 24425, 24455, 24485, 24515, 24545, 24575, 24605, 24640, 24670,
-24703, 24733, 24763, 24793, 24823, 24853, 24884, 24914, 24944, 24974, 25004, 25034, 25064, 25095, 25125, 25155,
-25185, 25215, 25256, 25286, 25323, 25353, 25384, 25414, 25445, 25475, 25505, 25536, 25567, 25606, 25636, 25667,
-25697, 25727, 25757, 25787, 25817, 25847, 25877, 25907, 25937, 25967, 26000, 26030, 26060, 26092, 26122, 26152,
-26183, 26213, 26244, 26274, 26304, 26334, 26364, 26395, 26425, 26455, 26485, 26515, 26546, 26576, 26606, 26642,
-26673, 26703, 26733, 26763, 26793, 26823, 26854, 26884, 26917, 26948, 26978, 27010, 27040, 27070, 27106, 27136,
-27166, 27196, 27226, 27262, 27292, 27322, 27353, 27384, 27414, 27444, 27476, 27506, 27537, 27567, 27597, 27627,
-27657, 27687, 27718, 27749, 27779, 27819, 27849, 27879, 27911, 27941, 27992, 28022, 28052, 28082, 28112, 28142,
-28185, 28216, 28246, 28276, 28306, 28336, 28366, 28396, 28426, 28457, 28494, 28524, 28555, 28585, 28615, 28646,
-28676, 28706, 28736, 28766, 28796, 28826, 28856, 28887, 28918, 28951, 28982, 29012, 29042, 29072, 29103, 29134,
-29164, 29194, 29224, 29254, 29287, 29317, 29347, 29377, 29407, 29437, 29467, 29498, 29528, 29558, 29588, 29618,
-29650, 29684, 29718, 29748, 29778, 29808, 29840, 29871, 29903, 29934, 29964, 29994, 30024, 30054, 30084, 30114,
-30144, 30174, 30204, 30234, 30264, 30294, 30325, 30355, 30388, 30418, 30448, 30480, 30511, 30541, 30571, 30601,
-30631, 30663, 30693, 30723, 30753, 30787, 30818, 30848, 30878, 30908, 30938, 30969, 30999, 31029, 31059, 31090,
-31120, 31150, 31181, 31211, 31242, 31272, 31302, 31335, 31365, 31395, 31425, 31455, 31485, 31515, 31547, 31584,
-31618, 31648, 31678, 31708, 31739, 31769, 31799, 31831, 31861, 31892, 31922, 31952, 31982, 32012, 32043, 32074,
-32104, 32134, 32166, 32196, 32227, 32259, 32289, 32319, 32350, 32380, 32410, 32566, 32596, 32626, 32657, 32687,
-32717, 32747, 32779, 32809, 32839, 32871, 32901, 32931, 32962, 32992, 33022, 33053, 33085, 33115, 33145, 33175,
-33205, 33237, 33267, 33297, 33327, 33358, 33388, 33418, 33448, 33489, 33519, 33549, 33579, 33609, 33651, 33682,
-33712, 33742, 33772, 33802, 33833, 33863, 33893, 33926, 33956, 33986, 34023, 34054, 34084, 34115, 34145, 34176,
-34206, 34237, 34268, 34298, 34328, 34358, 34388, 34419, 34449, 34479, 34512, 34549, 34579, 34609, 34639, 34669,
-34701, 34731, 34761, 34791, 34821, 34851, 34881, 34913, 34943, 34974, 35004, 35034, 35064, 35094, 35125, 35155,
-35185, 35215, 35245, 35282, 35312, 35342, 35372, 35402, 35432, 35462, 35492, 35522, 35552, 35582, 35612, 35642,
-35672, 35703, 35733, 35895, 35925, 35955, 35985, 36015, 36047, 36077, 36109, 36196, 36228, 36259, 36289, 36319,
-36349, 36379, 36409, 36439, 36470, 36500, 36530, 36561, 36591, 36621, 36652, 36683, 36763, 36799, 36832, 36862,
-36892, 36924, 36955, 36985, 37015, 37045, 37076, 37106, 37136, 37166, 37196, 37226, 37257, 37287, 37317, 37347,
-37377, 37411, 37445, 37475, 37506, 37536, 37568, 37598, 37628, 37658, 37688, 37718, 37749, 37780, 37810, 37840,
-37870, 37900, 37930, 37960, 37992, 38263, 38296, 38326, 38356, 38428, 38458, 38488, 38518, 38548, 38579, 38610,
-38640, 38670, 38700, 38731, 38761, 38792, 38822, 38852, 38883, 38913, 38944, 38977, 39007, 39080, 39110, 39141,
-39171, 39201, 39231, 39262, 39318, 39348, 39378, 39408, 39438, 39468, 39498, 39528, 39592, 39622, 39654, 39684,
-39714, 39745, 39775, 39805, 39835, 39865, 39895, 39927, 39959, 39990, 40020, 40051, 40165, 40195, 40226, 40256,
-40287, 40317, 40347, 40377, 40407, 40437, 40467, 40565, 40595, 40628, 40659, 40690, 40720, 40750, 40780, 40810,
-40845, 57344, 57374, 57404, 57434, 57464, 57494, 57524, 57554, 57584, 57614, 57644, 57674, 57704, 57734, 57764,
-57794, 57824, 57854, 57884, 57914, 57944, 57974, 58004, 58034, 58064, 58094, 58124, 58154, 58184, 58214, 58244,
-58274, 58304, 58334, 58364, 58394, 58424, 58454, 58484, 58514, 58544, 58574, 58604, 58634, 58664, 58694, 58724,
-58754, 58784, 58814, 58844, 58874, 58904, 58934, 58964, 58994, 59024, 59054, 59084, 59114, 59144, 59174, 59204,
-59234, 59264, 59294, 59324, 59354, 59384, 59414, 59444, 59474, 59504, 59534, 59564, 59594, 59624, 59654, 59684,
-59714, 59744, 59774, 59804, 59834, 59864, 59894, 59924, 59954, 59984, 60014, 60044, 60074, 60104, 60134, 60164,
-60194, 60224, 60254, 60284, 60314, 60344, 60374, 60404, 60434, 60464, 60494, 60524, 60554, 60584, 60614, 60644,
-60674, 60704, 60734, 60764, 60794, 60824, 60854, 60884, 60914, 60944, 60974, 61004, 61034, 61064, 61094, 61124,
-61154, 61184, 61214, 61244, 61274, 61304, 61334, 61364, 61394, 61424, 61454, 61484, 61514, 61544, 61574, 61604,
-61634, 61664, 61694, 61724, 61754, 61784, 61814, 61844, 61874, 61904, 61934, 61964, 61994, 62024, 62054, 62084,
-62114, 62144, 62174, 62204, 62234, 62264, 62294, 62324, 62354, 62384, 62414, 62444, 62474, 62504, 62534, 62564,
-62594, 62624, 62654, 62684, 62714, 62744, 62774, 62804, 62834, 62864, 62894, 62924, 62954, 62984, 63014, 63044,
-63074, 63104, 63134, 63164, 63194, 63224, 63254, 63284, 63314, 63344, 63374, 63404, 63434, 63464, 63494, 63524,
-63554, 64012, 65072, 65102, 65281, 65311, 65343, 65373, 65504
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-161, 177, 161, 194, 162, 88, 161, 211, 161, 80, 161, 209, 161, 210, 163, 190,
-163, 188, 163, 68, 163, 92, 161, 86, 161, 172, 163, 225, 162, 74, 162, 185,
-161, 246, 162, 65, 161, 239, 161, 220, 161, 242, 161, 233, 162, 119, 162, 116,
-162, 164, 162, 161, 162, 109, 161, 182, 162, 168, 161, 185, 161, 240, 161, 64,
-161, 170, 163, 116, 163, 180, 161, 192, 162, 85, 162, 87, 164, 64, 165, 224,
-201, 100, 201, 65, 176, 174, 168, 200, 164, 176, 165, 81, 165, 247, 201, 180,
-202, 91, 167, 69, 203, 188, 203, 202, 205, 232, 171, 77, 173, 193, 173, 191,
-173, 219, 176, 182, 216, 91, 216, 95, 182, 202, 220, 185, 224, 243, 228, 234,
-236, 188, 164, 184, 162, 93, 190, 172, 203, 205, 203, 206, 187, 254, 165, 88,
-202, 108, 168, 235, 208, 231, 220, 199, 241, 237, 168, 241, 176, 200, 241, 238,
-164, 80, 232, 250, 168, 242, 166, 76, 202, 116, 225, 70, 164, 206, 165, 111,
-166, 91, 202, 165, 167, 102, 203, 235, 203, 227, 206, 72, 206, 76, 206, 78,
-173, 243, 208, 247, 176, 225, 176, 220, 212, 113, 216, 109, 179, 237, 220, 216,
-182, 226, 185, 198, 229, 68, 228, 251, 190, 185, 236, 195, 195, 96, 245, 196,
-201, 198, 171, 170, 249, 107, 167, 163, 169, 89, 203, 249, 206, 81, 209, 81,
-212, 177, 176, 242, 216, 161, 216, 126, 220, 233, 225, 93, 185, 211, 229, 76,
-236, 204, 167, 167, 206, 96, 164, 210, 169, 94, 182, 248, 201, 206, 167, 173,
-204, 74, 206, 115, 206, 116, 174, 82, 177, 64, 177, 66, 216, 187, 216, 197,
-220, 249, 225, 110, 225, 115, 233, 86, 236, 208, 164, 108, 212, 240, 167, 185,
-209, 104, 216, 213, 185, 235, 177, 78, 201, 213, 204, 89, 185, 240, 202, 199,
-204, 92, 206, 171, 174, 111, 177, 83, 177, 92, 216, 233, 221, 86, 225, 164,
-229, 109, 192, 172, 164, 116, 180, 83, 169, 173, 180, 85, 185, 243, 183, 70,
-169, 177, 177, 103, 185, 248, 245, 203, 166, 161, 171, 218, 233, 116, 177, 109,
-171, 224, 216, 246, 164, 223, 202, 221, 169, 193, 171, 228, 206, 202, 206, 195,
-177, 118, 209, 167, 177, 162, 213, 91, 221, 101, 180, 106, 183, 91, 225, 200,
-188, 162, 188, 168, 188, 169, 190, 210, 236, 230, 249, 186, 221, 117, 206, 211,
-201, 230, 169, 211, 169, 225, 169, 238, 206, 218, 171, 246, 174, 193, 174, 185,
-213, 103, 177, 189, 177, 196, 180, 122, 217, 99, 183, 112, 221, 126, 221, 162,
-217, 98, 225, 237, 217, 90, 190, 216, 233, 174, 194, 94, 244, 77, 233, 175,
-177, 207, 221, 188, 180, 180, 217, 124, 177, 220, 166, 175, 169, 254, 172, 81,
-209, 213, 213, 169, 183, 121, 186, 90, 233, 181, 242, 75, 176, 210, 177, 230,
-201, 240, 168, 65, 170, 83, 170, 85, 207, 86, 172, 89, 207, 79, 209, 236,
-209, 226, 209, 224, 213, 180, 213, 204, 213, 188, 217, 217, 217, 209, 217, 172,
-217, 216, 221, 228, 221, 205, 183, 167, 226, 64, 226, 76, 229, 213, 229, 202,
-188, 207, 233, 215, 233, 203, 192, 207, 192, 204, 239, 226, 242, 80, 245, 209,
-198, 86, 209, 249, 233, 223, 183, 179, 213, 218, 194, 108, 165, 192, 178, 64,
-237, 77, 174, 241, 201, 248, 203, 91, 168, 85, 170, 106, 172, 117, 204, 246,
-207, 167, 172, 122, 210, 76, 210, 72, 175, 75, 178, 71, 214, 64, 178, 97,
-181, 65, 180, 229, 180, 242, 213, 228, 222, 95, 222, 85, 226, 108, 186, 173,
-226, 126, 186, 120, 226, 118, 230, 73, 230, 90, 237, 79, 233, 236, 237, 86,
-233, 246, 242, 98, 244, 102, 197, 244, 168, 96, 205, 89, 172, 181, 210, 113,
-214, 88, 214, 75, 181, 77, 222, 108, 222, 115, 226, 187, 230, 99, 191, 82,
-192, 236, 242, 106, 198, 121, 192, 240, 170, 170, 218, 107, 242, 113, 203, 101,
-207, 194, 175, 86, 178, 114, 222, 173, 230, 117, 239, 254, 203, 107, 172, 194,
-210, 180, 214, 120, 218, 126, 181, 94, 222, 180, 186, 192, 237, 105, 237, 110,
-196, 110, 207, 216, 191, 94, 202, 70, 207, 219, 178, 165, 237, 115, 172, 207,
-210, 199, 181, 108, 222, 204, 230, 181, 191, 97, 194, 125, 249, 204, 181, 113,
-181, 114, 178, 176, 205, 120, 210, 207, 214, 169, 218, 189, 183, 251, 230, 190,
-193, 64, 195, 169, 170, 190, 207, 242, 210, 225, 178, 185, 218, 209, 222, 240,
-226, 242, 189, 88, 191, 106, 237, 172, 242, 163, 246, 246, 210, 234, 218, 212,
-227, 67, 194, 167, 207, 250, 210, 237, 218, 215, 227, 72, 191, 112, 242, 166,
-210, 248, 223, 66, 237, 185, 179, 186, 172, 242, 178, 195, 218, 223, 184, 97,
-227, 93, 189, 105, 230, 216, 234, 195, 237, 191, 240, 99, 195, 178, 246, 250,
-205, 168, 214, 222, 223, 84, 234, 202, 244, 171, 211, 90, 181, 181, 214, 238,
-181, 179, 223, 88, 227, 117, 227, 108, 189, 116, 230, 233, 234, 205, 193, 104,
-194, 182, 196, 126, 248, 254, 166, 206, 170, 201, 184, 112, 208, 78, 189, 126,
-214, 248, 230, 246, 181, 192, 234, 230, 215, 66, 230, 252, 181, 194, 205, 173,
-208, 91, 208, 88, 219, 72, 215, 80, 219, 79, 223, 119, 184, 161, 231, 68,
-234, 236, 242, 194, 166, 220, 215, 82, 211, 113, 231, 74, 247, 239, 203, 161,
-205, 191, 173, 98, 173, 102, 206, 65, 175, 237, 175, 243, 215, 94, 178, 247,
-215, 116, 219, 116, 219, 168, 181, 220, 223, 199, 223, 215, 223, 176, 223, 179,
-227, 173, 227, 178, 231, 115, 189, 183, 231, 76, 191, 187, 234, 253, 237, 244,
-237, 254, 240, 171, 242, 212, 196, 169, 245, 241, 247, 76, 176, 64, 208, 169,
-211, 189, 179, 76, 181, 241, 223, 232, 184, 187, 227, 235, 231, 187, 231, 175,
-191, 196, 193, 177, 238, 98, 240, 187, 195, 199, 196, 247, 208, 170, 191, 197,
-211, 215, 179, 79, 219, 202, 223, 247, 187, 114, 231, 202, 238, 113, 240, 210,
-247, 82, 179, 87, 238, 121, 168, 164, 231, 210, 176, 81, 215, 203, 219, 226,
-184, 229, 224, 70, 187, 126, 189, 212, 235, 126, 191, 213, 238, 174, 240, 237,
-195, 209, 197, 64, 248, 194, 168, 166, 168, 168, 193, 199, 235, 177, 182, 74,
-228, 84, 189, 228, 196, 186, 168, 170, 219, 237, 189, 236, 215, 218, 184, 242,
-228, 91, 231, 249, 191, 229, 240, 250, 195, 221, 247, 94, 184, 250, 211, 232,
-219, 252, 228, 103, 232, 71, 241, 73, 168, 175, 203, 166, 208, 182, 211, 234,
-215, 229, 185, 71, 187, 191, 235, 209, 202, 82, 170, 242, 215, 238, 215, 236,
-224, 164, 232, 90, 176, 117, 185, 84, 190, 75, 241, 80, 198, 111, 179, 168,
-220, 98, 182, 116, 185, 100, 224, 197, 228, 170, 228, 123, 232, 101, 232, 123,
-191, 251, 191, 254, 235, 228, 238, 209, 193, 228, 194, 232, 241, 102, 243, 101,
-243, 110, 245, 65, 246, 102, 247, 110, 248, 203, 170, 248, 185, 104, 236, 75,
-194, 243, 170, 250, 205, 219, 176, 164, 179, 179, 185, 106, 241, 111, 187, 220,
-220, 168, 192, 75, 243, 124, 249, 173, 173, 178, 232, 179, 194, 254, 248, 79,
-247, 114, 173, 182, 232, 187, 239, 69, 245, 81, 173, 183, 246, 116, 216, 79,
-187, 229, 192, 96, 195, 73, 198, 97, 173, 186, 185, 165, 190, 115, 236, 101,
-195, 77, 245, 93, 247, 126, 249, 195, 176, 169, 245, 102, 187, 236, 241, 188,
-198, 75, 187, 237, 228, 225, 236, 161, 239, 109, 241, 205, 243, 208, 245, 108,
-245, 116, 247, 182, 197, 235, 249, 120, 179, 190, 190, 161, 236, 171, 239, 166,
-241, 219, 243, 227, 245, 126, 246, 191, 197, 195, 247, 196, 249, 124, 179, 191,
-196, 83, 196, 84, 232, 241, 248, 118, 232, 243, 245, 185, 241, 233, 197, 198,
-192, 115, 250, 64, 250, 94, 250, 124, 250, 188, 250, 218, 250, 248, 251, 87,
-251, 117, 251, 181, 251, 211, 251, 241, 252, 80, 252, 110, 252, 174, 252, 204,
-252, 234, 253, 73, 253, 103, 253, 167, 253, 197, 253, 227, 254, 66, 254, 96,
-254, 126, 254, 190, 254, 220, 254, 250, 142, 89, 142, 119, 142, 183, 142, 213,
-142, 243, 143, 82, 143, 112, 143, 176, 143, 206, 143, 236, 144, 75, 144, 105,
-144, 169, 144, 199, 144, 229, 145, 68, 145, 98, 145, 162, 145, 192, 145, 222,
-145, 252, 146, 91, 146, 121, 146, 185, 146, 215, 146, 245, 147, 84, 147, 114,
-147, 178, 147, 208, 147, 238, 148, 77, 148, 107, 148, 171, 148, 201, 148, 231,
-149, 70, 149, 100, 149, 164, 149, 194, 149, 224, 149, 254, 150, 93, 150, 123,
-150, 187, 150, 217, 150, 247, 151, 86, 151, 116, 151, 180, 151, 210, 151, 240,
-152, 79, 152, 109, 152, 173, 152, 203, 152, 233, 153, 72, 153, 102, 153, 166,
-153, 196, 153, 226, 154, 65, 154, 95, 154, 125, 154, 189, 154, 219, 154, 249,
-155, 88, 155, 118, 155, 182, 155, 212, 155, 242, 156, 81, 156, 111, 156, 175,
-156, 205, 156, 235, 157, 74, 157, 104, 157, 168, 157, 198, 157, 228, 158, 67,
-158, 97, 158, 161, 158, 191, 158, 221, 158, 251, 159, 90, 159, 120, 159, 184,
-159, 214, 159, 244, 160, 83, 160, 113, 160, 177, 160, 207, 160, 237, 129, 76,
-129, 106, 129, 170, 129, 200, 129, 230, 130, 69, 130, 99, 130, 163, 130, 193,
-130, 223, 130, 253, 131, 92, 131, 122, 131, 186, 131, 216, 131, 246, 132, 85,
-132, 115, 132, 179, 132, 209, 132, 239, 133, 78, 133, 108, 133, 172, 133, 202,
-133, 232, 134, 71, 134, 101, 134, 165, 134, 195, 134, 225, 135, 64, 135, 94,
-135, 124, 135, 188, 135, 218, 135, 248, 136, 87, 136, 117, 136, 181, 136, 211,
-136, 241, 137, 80, 137, 110, 137, 174, 137, 204, 137, 234, 138, 73, 138, 103,
-138, 167, 138, 197, 138, 227, 139, 66, 139, 96, 139, 126, 139, 190, 139, 220,
-139, 250, 140, 89, 140, 119, 140, 183, 140, 213, 140, 243, 141, 82, 141, 112,
-141, 176, 141, 206, 141, 236, 198, 172, 198, 202, 198, 232, 199, 71, 199, 101,
-199, 165, 199, 195, 199, 225, 200, 64, 200, 94, 200, 124, 200, 188, 200, 218,
-200, 248, 201, 74, 161, 74, 161, 201, 161, 73, 161, 72, 161, 196, 161, 98,
-162, 70
- });
-
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_CodecDynamic() throws CharacterCodingException {
- super.test_CodecDynamic();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Decode() throws CharacterCodingException {
- super.test_Decode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Encode() throws CharacterCodingException {
- super.test_Encode();
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_nameMatch() {
- super.test_nameMatch();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByteAbstractTest.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByteAbstractTest.java
deleted file mode 100644
index f895c0c..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByteAbstractTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CodingErrorAction;
-import java.util.Arrays;
-
-/**
- * Super class for concrete charset test suites.
- */
-public class Charset_SingleByteAbstractTest extends Charset_AbstractTest {
-
- static byte[] allBytes;
- static char[] allChars;
-
- @Override
- protected void setUp() throws Exception {
- allBytes = new byte[256];
- for (int i = 0; i < 256; i++) {
- allBytes[i] = (byte) i;
- }
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
-
-
- public static void dumpDecoded () {
- Charset_TestGenerator.Dumper out = new Charset_TestGenerator.Dumper1();
- ByteBuffer inputBB = ByteBuffer.wrap(allBytes);
- CharBuffer outputCB;
- decoder.onMalformedInput(CodingErrorAction.REPLACE);
- try {
- outputCB = decoder.decode(inputBB);
- outputCB.rewind();
- while (outputCB.hasRemaining()) {
- out.consume(outputCB.get());
- }
- } catch (CharacterCodingException e) {
- System.out.println(e);
-// e.printStackTrace();
- }
- }
-
- public static void decodeReplace (byte[] input, char[] expectedOutput) throws CharacterCodingException {
- ByteBuffer inputBB = ByteBuffer.wrap(input);
- CharBuffer outputCB;
- decoder.onMalformedInput(CodingErrorAction.REPLACE);
- outputCB = decoder.decode(inputBB);
- outputCB.rewind();
- assertEqualChars2("Decoded charactes must match!",
- expectedOutput,
- outputCB.array(),
- input);
-// assertTrue("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
-// Arrays.equals(expectedOutput, outputCB.array()));
-
-// assertEqualChars("Decoded charactes (REPLACEed ones INCLUSIVE) must match!",
-// expectedOutput,
-// outputCB.array());
-
-// assertEquals("Decoded charactes must match!",
-// String.valueOf(allChars),
-// outputCB.toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Decode () throws CharacterCodingException {
- decodeReplace(allBytes, allChars);
-// ByteBuffer inputBB = ByteBuffer.wrap(allBytes);
-// CharBuffer outputCB;
-// decoder.onMalformedInput(CodingErrorAction.REPLACE);
-// outputCB = decoder.decode(inputBB);
-// outputCB.rewind();
-// assertEqualChars("Decoded charactes must match!",
-// allChars,
-// outputCB.array());
-//// assertEquals("Decoded charactes must match!",
-//// String.valueOf(allChars),
-//// outputCB.toString());
- }
-
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- method = "functionalCoDec_REPR",
- args = {}
- )
- @Override
- public void test_Encode () throws CharacterCodingException {
- CharBuffer inputCB = CharBuffer.wrap(allChars);
- ByteBuffer outputBB;
- encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- outputBB = encoder.encode(inputCB);
- outputBB.rewind();
- assertEqualBytes2("Encoded bytes must match!", allBytes, outputBB.array(), allChars);
- }
-
-// static void assertEqualChars (String msg, char[] expected, char[] actual) {
-// int len = expected.length;
-// if (actual.length < len) len = actual.length;
-// for (int i = 0; i < len; i++) {
-// if (actual[i] != expected[i]) {
-// System.out.format("Mismatch at index %d: %d instead of expected %d.\n",
-// i, (int) actual[i], (int) expected[i]);
-// }
-//// else {
-//// System.out.format("Match index %d: %d = %d\n",
-//// i, (int) actual[i], (int) expected[i]);
-//// }
-// }
-// assertTrue(msg, Arrays.equals(actual, expected));
-// }
-
- static void assertEqualChars2 (String msg, char[] expected, char[] actual, byte[] bytes) {
- boolean match = true;
- boolean replaceMatch = true;
- int len = expected.length;
- if (actual.length < len) len = actual.length;
- for (int i = 0; i < len; i++) {
- if (actual[i] == expected[i]) {
- // Fine!
- }
- else {
- if (expected[i] == 65533) {
- if (actual[i] == (bytes[i] & 0xff)) {
-// System.out.format("REPLACE mismatch at index %d (byte %d): %d instead of expected %d.\n",
-// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
- } else {
-// System.out.format("REPLACE mismatch at index %d (byte %d): %d instead of expected %d.\n",
-// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
- }
- replaceMatch = false;
- } else {
-// System.out.format("MISMATCH at index %d (byte %d): %d instead of expected %d.\n",
-// i, bytes[i] & 0xff, (int) actual[i], (int) expected[i]);
- match = false;
- }
- }
-// if ((actual[i] != expected[i]) &&
-// !((actual[i] == bytes[i]) && (expected[i] == 65533))) {
-//
-// match = false;
-// }
- }
- assertTrue(msg, match);
- if (!replaceMatch) {
-// System.out.println("for charset " + charsetName);
- }
- }
-
-// static void assertEqualBytes (String msg, byte[] expected, byte[] actual) {
-// int len = expected.length;
-// if (actual.length < len) len = actual.length;
-// for (int i = 0; i < len; i++) {
-// if (actual[i] != expected[i]) {
-// System.out.format("MISMATCH at index %d: %d instead of expected %d.\n",
-// i, actual[i], expected[i]);
-// }
-// }
-// assertTrue(msg, Arrays.equals(actual, expected));
-// }
-
- static void assertEqualBytes2 (String msg, byte[] expected, byte[] actual, char[] chars) {
- boolean match = true;
- int len = expected.length;
- if (actual.length < len) len = actual.length;
- for (int i = 0; i < len; i++) {
- if ((actual[i] != expected[i]) &&
- !((chars[i] == 65533)) && (actual[i] == 63)) {
-// System.out.format("MISMATCH at index %d: %d instead of expected %d.\n",
-// i, actual[i], expected[i]);
- match = false;
- }
- }
- assertTrue(msg, match);
- }
-
- public static void main(String[] args) {
-// charset = Charset.defaultCharset();
-// decoder = charset.newDecoder();
-// System.out.println(charset.name());
- dumpDecoded();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_.java
deleted file mode 100644
index f4e82d8..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "";
- allChars = theseChars(new int[]{
- });
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_IBM864.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_IBM864.java
deleted file mode 100644
index 730285b..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_IBM864.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_SingleByte_IBM864 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
-// charsetName = "IBM864"; // ICU name "cp864", wanted Android name "CP864"
- charsetName = "cp864"; // ICU name "cp864", wanted Android name "CP864"
-
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28/*26*/, 27, 127/*28*/, 29, 30, 31,
- 32, 33, 34, 35, 36, 37/*1642*/, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 26/*127*/,
- 176, 183, 8729, 8730, 9618, 9472, 9474, 9532, 9508, 9516, 9500, 9524, 9488, 9484, 9492, 9496,
- 946, 8734, 966, 177, 189, 188, 8776, 171, 187, 65271, 65272, 65533, 65533, 65275, 65276, 8203/*65533*/,
- 160, 173, 65154, 163, 164, 65156, 65533, 65533, 65166, 65167, 65173, 65177, 1548, 65181, 65185, 65189,
- 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 65233, 1563, 65201, 65205, 65209, 1567,
- 162, 65152, 65153, 65155, 65157, 65226, 65163, 65165, 65169, 65171, 65175, 65179, 65183, 65187, 65191, 65193,
- 65195, 65197, 65199, 65203, 65207, 65211, 65215, 65219/*65217*/, 65223/*65221*/, 65227, 65231, 166, 172, 247, 215, 65225,
- 1600, 65235, 65239, 65243, 65247, 65251, 65255, 65259, 65261, 65263, 65267, 65213, 65228, 65230, 65229, 65249,
- 65149, 65148/*1617*/, 65253, 65257, 65260, 65264, 65266, 65232, 65237, 65269, 65270, 65245, 65241, 65265, 9632, 65533});
-// allChars = theseChars(new int[]{
-// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-// 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-// 32, 33, 34, 35, 36, 1642, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-// 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-// 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-// 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-// 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-// 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-// 176, 183, 8729, 8730, 9618, 9472, 9474, 9532, 9508, 9516, 9500, 9524, 9488, 9484, 9492, 9496,
-// 946, 8734, 966, 177, 189, 188, 8776, 171, 187, 65271, 65272, 65533, 65533, 65275, 65276, 65533,
-// 160, 173, 65154, 163, 164, 65156, 65533, 65533, 65166, 65167, 65173, 65177, 1548, 65181, 65185, 65189,
-// 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 65233, 1563, 65201, 65205, 65209, 1567,
-// 162, 65152, 65153, 65155, 65157, 65226, 65163, 65165, 65169, 65171, 65175, 65179, 65183, 65187, 65191, 65193,
-// 65195, 65197, 65199, 65203, 65207, 65211, 65215, 65217, 65221, 65227, 65231, 166, 172, 247, 215, 65225,
-// 1600, 65235, 65239, 65243, 65247, 65251, 65255, 65259, 65261, 65263, 65267, 65213, 65228, 65230, 65229, 65249,
-// 65149, 1617, 65253, 65257, 65260, 65264, 65266, 65232, 65237, 65269, 65270, 65245, 65241, 65265, 9632, 65533});
-
- super.setUp();
- }
-
-// public static void _test_Bytes_DifferentOnes_RI() throws CharacterCodingException {
-// decodeReplace(
-// theseBytes(new int[]{26, 28, 37, 127, 159, 215, 216, 241}),
-// new char[] {26, 28, 1642, 127, 65533, 65217, 65221, 1617} );
-// }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public static void test_Bytes_DifferentOnes_Android() throws CharacterCodingException {
- // Android:
- decodeReplace(
- theseBytes(new int[]{26, 28, 37, 127, 159, 215, 216, 241}),
- new char[] {28, 127, 37, 26, 8203, 65219, 65223, 65148} );
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_1.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_1.java
deleted file mode 100644
index 4d28cf8..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_1.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_1 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-1";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_11.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_11.java
deleted file mode 100644
index 04a544d..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_11.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-@AndroidOnly("charset x-iso-8859_11-2001 not supported ")
-public class Charset_SingleByte_ISO_8859_11 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
-// charsetName = "ISO-8859-11";
- charsetName = "x-iso-8859_11-2001";
-
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599,
- 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615,
- 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631,
- 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 65533, 65533, 65533, 65533, 3647,
- 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663,
- 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 65533, 65533, 65533, 65533});
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_13.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_13.java
deleted file mode 100644
index b65038f..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_13.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_13 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-13";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 8221, 162, 163, 164, 8222, 166, 167, 216, 169, 342, 171, 172, 173, 174, 198,
- 176, 177, 178, 179, 8220, 181, 182, 183, 248, 185, 343, 187, 188, 189, 190, 230,
- 260, 302, 256, 262, 196, 197, 280, 274, 268, 201, 377, 278, 290, 310, 298, 315,
- 352, 323, 325, 211, 332, 213, 214, 215, 370, 321, 346, 362, 220, 379, 381, 223,
- 261, 303, 257, 263, 228, 229, 281, 275, 269, 233, 378, 279, 291, 311, 299, 316,
- 353, 324, 326, 243, 333, 245, 246, 247, 371, 322, 347, 363, 252, 380, 382, 8217});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_15.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_15.java
deleted file mode 100644
index 228cdfd..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_15.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_15 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-15";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 161, 162, 163, 8364, 165, 352, 167, 353, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 381, 181, 182, 183, 382, 185, 186, 187, 338, 339, 376, 191,
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_2.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_2.java
deleted file mode 100644
index a0952b9..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_2.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_2 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-2";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 260, 728, 321, 164, 317, 346, 167, 168, 352, 350, 356, 377, 173, 381, 379,
- 176, 261, 731, 322, 180, 318, 347, 711, 184, 353, 351, 357, 378, 733, 382, 380,
- 340, 193, 194, 258, 196, 313, 262, 199, 268, 201, 280, 203, 282, 205, 206, 270,
- 272, 323, 327, 211, 212, 336, 214, 215, 344, 366, 218, 368, 220, 221, 354, 223,
- 341, 225, 226, 259, 228, 314, 263, 231, 269, 233, 281, 235, 283, 237, 238, 271,
- 273, 324, 328, 243, 244, 337, 246, 247, 345, 367, 250, 369, 252, 253, 355, 729});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_3.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_3.java
deleted file mode 100644
index 1af2add..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_3.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_3 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-3";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 294, 728, 163, 164, 65533, 292, 167, 168, 304, 350, 286, 308, 173, 65533, 379,
- 176, 295, 178, 179, 180, 181, 293, 183, 184, 305, 351, 287, 309, 189, 65533, 380,
- 192, 193, 194, 65533, 196, 266, 264, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 65533, 209, 210, 211, 212, 288, 214, 215, 284, 217, 218, 219, 220, 364, 348, 223,
- 224, 225, 226, 65533, 228, 267, 265, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 65533, 241, 242, 243, 244, 289, 246, 247, 285, 249, 250, 251, 252, 365, 349, 729});
- super.setUp();
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public static void test_Bytes_166() throws CharacterCodingException {
- decodeReplace(
- new byte[] {(byte)166},
- new char[] {292} );
-// ByteBuffer inputBB = ByteBuffer.wrap(new byte[] {(byte)166});
-// CharBuffer outputCB;
-// decoder.onMalformedInput(CodingErrorAction.REPLACE);
-// System.out.println("test_Bytes_166:");
-// outputCB = decoder.decode(inputBB);
-// outputCB.rewind();
-// assertEqualChars("Decoded charactes must match!",
-// new char[] {292},
-// outputCB.array());
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public static void test_Bytes_195() throws CharacterCodingException {
- decodeReplace(
- new byte[] {(byte)195},
- new char[] {65533} );
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public static void test_Bytes_165() throws CharacterCodingException {
- decodeReplace(
- new byte[] {(byte)165},
- new char[] {65533} );
- }
-
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "functionalCoDec_REPR",
- args = {}
- )
- public static void test_Bytes_165_any() throws CharacterCodingException {
- decodeReplace(
- new byte[] {(byte)165, 32},
- new char[] {65533, 32} );
- }
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_4.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_4.java
deleted file mode 100644
index c5c0778..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_4.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_4 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-4";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 260, 312, 342, 164, 296, 315, 167, 168, 352, 274, 290, 358, 173, 381, 175,
- 176, 261, 731, 343, 180, 297, 316, 711, 184, 353, 275, 291, 359, 330, 382, 331,
- 256, 193, 194, 195, 196, 197, 198, 302, 268, 201, 280, 203, 278, 205, 206, 298,
- 272, 325, 332, 310, 212, 213, 214, 215, 216, 370, 218, 219, 220, 360, 362, 223,
- 257, 225, 226, 227, 228, 229, 230, 303, 269, 233, 281, 235, 279, 237, 238, 299,
- 273, 326, 333, 311, 244, 245, 246, 247, 248, 371, 250, 251, 252, 361, 363, 729});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_5.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_5.java
deleted file mode 100644
index 0bf11f6..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_5.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_5 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-5";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 173, 1038, 1039,
- 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
- 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071,
- 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
- 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103,
- 8470, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 167, 1118, 1119});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_6.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_6.java
deleted file mode 100644
index b2caf2a..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_6.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_6 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-6";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 65533, 65533, 65533, 164, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 1548, 173, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 1563, 65533, 65533, 65533, 1567,
- 65533, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583,
- 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 65533, 65533, 65533, 65533, 65533,
- 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615,
- 1616, 1617, 1618, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_7.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_7.java
deleted file mode 100644
index 7a920d3..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_7.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_7 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-7";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 160, 8216, 8217, 163, 65533, 65533, 166, 167, 168, 169, 65533, 171, 172, 173, 65533, 8213,
- 176, 177, 178, 179, 900, 901, 902, 183, 904, 905, 906, 187, 908, 189, 910, 911,
- 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927,
- 928, 929, 65533, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943,
- 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959,
- 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_8.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_8.java
deleted file mode 100644
index 72a26eb..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_8.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_8 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-8";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 65533, 162, 163, 164, 165, 166, 167, 168, 169, 215, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 247, 187, 188, 189, 190, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 8215,
- 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503,
- 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 65533, 65533, 8206, 8207, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_9.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_9.java
deleted file mode 100644
index 99e7617..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_ISO_8859_9.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_ISO_8859_9 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "ISO-8859-9";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 286, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 304, 350, 223,
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 287, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 305, 351, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_KOI8_R.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_KOI8_R.java
deleted file mode 100644
index 0247752..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_KOI8_R.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_KOI8_R extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "KOI8-R";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 9472, 9474, 9484, 9488, 9492, 9496, 9500, 9508, 9516, 9524, 9532, 9600, 9604, 9608, 9612, 9616,
- 9617, 9618, 9619, 8992, 9632, 8729, 8730, 8776, 8804, 8805, 160, 8993, 176, 178, 183, 247,
- 9552, 9553, 9554, 1105, 9555, 9556, 9557, 9558, 9559, 9560, 9561, 9562, 9563, 9564, 9565, 9566,
- 9567, 9568, 9569, 1025, 9570, 9571, 9572, 9573, 9574, 9575, 9576, 9577, 9578, 9579, 9580, 169,
- 1102, 1072, 1073, 1094, 1076, 1077, 1092, 1075, 1093, 1080, 1081, 1082, 1083, 1084, 1085, 1086,
- 1087, 1103, 1088, 1089, 1090, 1091, 1078, 1074, 1100, 1099, 1079, 1096, 1101, 1097, 1095, 1098,
- 1070, 1040, 1041, 1062, 1044, 1045, 1060, 1043, 1061, 1048, 1049, 1050, 1051, 1052, 1053, 1054,
- 1055, 1071, 1056, 1057, 1058, 1059, 1046, 1042, 1068, 1067, 1047, 1064, 1069, 1065, 1063, 1066});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_US_ASCII.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_US_ASCII.java
deleted file mode 100644
index a76d619..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_US_ASCII.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_US_ASCII extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "US-ASCII";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1250.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1250.java
deleted file mode 100644
index 09b7ed2..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1250.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1250 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1250";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 65533, 8222, 8230, 8224, 8225, 65533, 8240, 352, 8249, 346, 356, 381, 377,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 353, 8250, 347, 357, 382, 378,
- 160, 711, 728, 321, 164, 260, 166, 167, 168, 169, 350, 171, 172, 173, 174, 379,
- 176, 177, 731, 322, 180, 181, 182, 183, 184, 261, 351, 187, 317, 733, 318, 380,
- 340, 193, 194, 258, 196, 313, 262, 199, 268, 201, 280, 203, 282, 205, 206, 270,
- 272, 323, 327, 211, 212, 336, 214, 215, 344, 366, 218, 368, 220, 221, 354, 223,
- 341, 225, 226, 259, 228, 314, 263, 231, 269, 233, 281, 235, 283, 237, 238, 271,
- 273, 324, 328, 243, 244, 337, 246, 247, 345, 367, 250, 369, 252, 253, 355, 729});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1251.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1251.java
deleted file mode 100644
index eaaf422..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1251.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1251 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1251";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 1026, 1027, 8218, 1107, 8222, 8230, 8224, 8225, 8364, 8240, 1033, 8249, 1034, 1036, 1035, 1039,
- 1106, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 1113, 8250, 1114, 1116, 1115, 1119,
- 160, 1038, 1118, 1032, 164, 1168, 166, 167, 1025, 169, 1028, 171, 172, 173, 174, 1031,
- 176, 177, 1030, 1110, 1169, 181, 182, 183, 1105, 8470, 1108, 187, 1112, 1029, 1109, 1111,
- 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055,
- 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071,
- 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087,
- 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1252.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1252.java
deleted file mode 100644
index f2baf89..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1252.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1252 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1252";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 65533, 381, 65533,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 65533, 382, 376,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1253.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1253.java
deleted file mode 100644
index b231f8b..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1253.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1253 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1253";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 65533, 8240, 65533, 8249, 65533, 65533, 65533, 65533,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 65533, 8250, 65533, 65533, 65533, 65533,
- 160, 901, 902, 163, 164, 165, 166, 167, 168, 169, 65533, 171, 172, 173, 174, 8213,
- 176, 177, 178, 179, 900, 181, 182, 183, 904, 905, 906, 187, 908, 189, 910, 911,
- 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927,
- 928, 929, 65533, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943,
- 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959,
- 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1254.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1254.java
deleted file mode 100644
index df65bbe..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1254.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1254 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1254";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 65533, 65533, 65533,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 65533, 65533, 376,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
- 286, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 304, 350, 223,
- 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
- 287, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 305, 351, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1255.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1255.java
deleted file mode 100644
index 6adb2be..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1255.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1255 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1255";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 65533, 8249, 65533, 65533, 65533, 65533,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 65533, 8250, 65533, 65533, 65533, 65533,
- 160, 161, 162, 163, 8362, 165, 166, 167, 168, 169, 215, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 247, 187, 188, 189, 190, 191,
- 1456, 1457, 1458, 1459, 1460, 1461, 1462, 1463, 1464, 1465, 65533, 1467, 1468, 1469, 1470, 1471,
- 1472, 1473, 1474, 1475, 1520, 1521, 1522, 1523, 1524, 65533, 65533, 65533, 65533, 65533, 65533, 65533,
- 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503,
- 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 65533, 65533, 8206, 8207, 65533});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1256.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1256.java
deleted file mode 100644
index 4284f78..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1256.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1256 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1256";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 1662, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 1657, 8249, 338, 1670, 1688, 1672,
- 1711, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 1705, 8482, 1681, 8250, 339, 8204, 8205, 1722,
- 160, 1548, 162, 163, 164, 165, 166, 167, 168, 169, 1726, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 1563, 187, 188, 189, 190, 1567,
- 1729, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583,
- 1584, 1585, 1586, 1587, 1588, 1589, 1590, 215, 1591, 1592, 1593, 1594, 1600, 1601, 1602, 1603,
- 224, 1604, 226, 1605, 1606, 1607, 1608, 231, 232, 233, 234, 235, 1609, 1610, 238, 239,
- 1611, 1612, 1613, 1614, 244, 1615, 1616, 247, 1617, 249, 1618, 251, 252, 8206, 8207, 1746});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1257.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1257.java
deleted file mode 100644
index c68b08c..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1257.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1257 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1257";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 65533, 8222, 8230, 8224, 8225, 65533, 8240, 65533, 8249, 65533, 168, 711, 184,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 65533, 8482, 65533, 8250, 65533, 175, 731, 65533,
- 160, 65533, 162, 163, 164, 65533, 166, 167, 216, 169, 342, 171, 172, 173, 174, 198,
- 176, 177, 178, 179, 180, 181, 182, 183, 248, 185, 343, 187, 188, 189, 190, 230,
- 260, 302, 256, 262, 196, 197, 280, 274, 268, 201, 377, 278, 290, 310, 298, 315,
- 352, 323, 325, 211, 332, 213, 214, 215, 370, 321, 346, 362, 220, 379, 381, 223,
- 261, 303, 257, 263, 228, 229, 281, 275, 269, 233, 378, 279, 291, 311, 299, 316,
- 353, 324, 326, 243, 333, 245, 246, 247, 371, 322, 347, 363, 252, 380, 382, 729});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1258.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1258.java
deleted file mode 100644
index 638db84..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_windows_1258.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-public class Charset_SingleByte_windows_1258 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
- charsetName = "windows-1258";
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 65533, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 65533, 8249, 338, 65533, 65533, 65533,
- 65533, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 65533, 8250, 339, 65533, 65533, 376,
- 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
- 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
- 192, 193, 194, 258, 196, 197, 198, 199, 200, 201, 202, 203, 768, 205, 206, 207,
- 272, 209, 777, 211, 212, 416, 214, 215, 216, 217, 218, 219, 220, 431, 771, 223,
- 224, 225, 226, 259, 228, 229, 230, 231, 232, 233, 234, 235, 769, 237, 238, 239,
- 273, 241, 803, 243, 244, 417, 246, 247, 248, 249, 250, 251, 252, 432, 8363, 255});
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_x_IBM874.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_x_IBM874.java
deleted file mode 100644
index 81293d2..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_SingleByte_x_IBM874.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import java.nio.charset.CharacterCodingException;
-
-@AndroidOnly("icu different from RI")
-
-public class Charset_SingleByte_x_IBM874 extends Charset_SingleByteAbstractTest {
-
- protected void setUp() throws Exception {
-// charsetName = "x-IBM874"; // ICU name "TIS-620", wanted Android name "CP874"
- charsetName = "TIS-620"; // ICU name "TIS-620", wanted Android name "CP874"
-
- allChars = theseChars(new int[]{
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
- 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
- 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
- 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
- 8364, 129, 130, 131, 132, 8230, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
- 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 152, 153, 154, 155, 156, 157, 158, 159,
- 160, 3585, 3586, 3587, 3588, 3589, 3590, 3591, 3592, 3593, 3594, 3595, 3596, 3597, 3598, 3599,
- 3600, 3601, 3602, 3603, 3604, 3605, 3606, 3607, 3608, 3609, 3610, 3611, 3612, 3613, 3614, 3615,
- 3616, 3617, 3618, 3619, 3620, 3621, 3622, 3623, 3624, 3625, 3626, 3627, 3628, 3629, 3630, 3631,
- 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3642, 63681, 63682, 63683, 63684, 3647,
- 3648, 3649, 3650, 3651, 3652, 3653, 3654, 3655, 3656, 3657, 3658, 3659, 3660, 3661, 3662, 3663,
- 3664, 3665, 3666, 3667, 3668, 3669, 3670, 3671, 3672, 3673, 3674, 3675, 63685, 63686, 63687, 63688});
-
- super.setUp();
- }
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator.java
deleted file mode 100644
index 387ebf5..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator.java
+++ /dev/null
@@ -1,267 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-/**
- * Super class for concrete charset test suites.
- */
-public class Charset_TestGenerator {
-
- Charset charset;
- CharsetDecoder decoder;
- CharsetEncoder encoder;
-
-
- static final int[] codes = {
- 9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
- 89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 170, 181, 186, 192, 195, 198,
- 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246,
- 249, 252, 255, 258, 261, 264, 267, 270, 273, 276, 279, 282, 285, 288, 291, 294,
- 297, 300, 303, 306, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342,
- 345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, 384, 387, 390,
- 393, 396, 399, 402, 405, 408, 411, 414, 417, 420, 423, 426, 429, 432, 435, 438,
- 441, 444, 447, 450, 453, 456, 459, 462, 465, 468, 471, 474, 477, 480, 483, 486,
- 489, 492, 495, 498, 501, 504, 507, 510, 513, 516, 519, 522, 525, 528, 531, 534,
- 537, 540, 543, 546, 549, 552, 555, 558, 561, 564, 592, 595, 598, 601, 604, 607,
- 610, 613, 616, 619, 622, 625, 628, 631, 634, 637, 640, 643, 646, 649, 652, 655,
- 658, 661, 664, 667, 670, 673, 676, 679, 682, 685, 688, 691, 694, 697, 700, 703,
- 710, 713, 716, 719, 736, 739, 750, 890, 902, 905, 908, 911, 914, 917, 920, 923,
- 926, 929, 932, 935, 938, 941, 944, 947, 950, 953, 956, 959, 962, 965, 968, 971,
- 974, 977, 980, 983, 986, 989, 992, 995, 998, 1001, 1004, 1007, 1010, 1013, 1016, 1019,
- 1024, 1027, 1060, 1093, 1126, 1162, 1195, 1228, 1261, 1294, 1329, 1362, 1395, 1488, 1521, 1569,
- 1602, 1635, 1668, 1701, 1734, 1774, 1808, 1869, 1920, 1953, 2308, 2341, 2384, 2437, 2470, 2524,
- 2565, 2598, 2649, 2693, 2726, 2768, 2821, 2854, 2908, 2947, 2980, 3047, 3080, 3114, 3168, 3205,
- 3238, 3294, 3333, 3366, 3424, 3461, 3494, 3585, 3618, 3651, 3713, 3746, 3779, 3840, 3873, 3906,
- 3939, 3976, 4096, 4129, 4162, 4256, 4289, 4322, 4355, 4388, 4421, 4454, 4487, 4520, 4553, 4586,
- 4619, 4652, 4685, 4718, 4752, 4786, 4819, 4852, 4885, 4918, 4951, 5024, 5057, 5090, 5123, 5156,
- 5189, 5222, 5255, 5288, 5321, 5354, 5387, 5420, 5453, 5486, 5519, 5552, 5585, 5618, 5651, 5684,
- 5717, 5750, 5783, 5816, 5849, 5888, 5921, 5954, 5987, 6020, 6053, 6103, 6158, 6191, 6224, 6257,
- 6290, 6400, 6470, 6503, 7424, 7457, 7490, 7523, 7680, 7713, 7746, 7779, 7812, 7845, 7878, 7911,
- 7944, 7977, 8010, 8043, 8076, 8109, 8144, 8178, 8232, 8287, 8450, 8484, 8517, 12288, 12337, 12370,
- 12403, 12436, 12469, 12502, 12535, 12568, 12601, 12634, 12667, 12704, 12784, 13312, 13345, 13378, 13411, 13444,
- 13477, 13510, 13543, 13576, 13609, 13642, 13675, 13708, 13741, 13774, 13807, 13840, 13873, 13906, 13939, 13972,
- 14005, 14038, 14071, 14104, 14137, 14170, 14203, 14236, 14269, 14302, 14335, 14368, 14401, 14434, 14467, 14500,
- 14533, 14566, 14599, 14632, 14665, 14698, 14731, 14764, 14797, 14830, 14863, 14896, 14929, 14962, 14995, 15028,
- 15061, 15094, 15127, 15160, 15193, 15226, 15259, 15292, 15325, 15358, 15391, 15424, 15457, 15490, 15523, 15556,
- 15589, 15622, 15655, 15688, 15721, 15754, 15787, 15820, 15853, 15886, 15919, 15952, 15985, 16018, 16051, 16084,
- 16117, 16150, 16183, 16216, 16249, 16282, 16315, 16348, 16381, 16414, 16447, 16480, 16513, 16546, 16579, 16612,
- 16645, 16678, 16711, 16744, 16777, 16810, 16843, 16876, 16909, 16942, 16975, 17008, 17041, 17074, 17107, 17140,
- 17173, 17206, 17239, 17272, 17305, 17338, 17371, 17404, 17437, 17470, 17503, 17536, 17569, 17602, 17635, 17668,
- 17701, 17734, 17767, 17800, 17833, 17866, 17899, 17932, 17965, 17998, 18031, 18064, 18097, 18130, 18163, 18196,
- 18229, 18262, 18295, 18328, 18361, 18394, 18427, 18460, 18493, 18526, 18559, 18592, 18625, 18658, 18691, 18724,
- 18757, 18790, 18823, 18856, 18889, 18922, 18955, 18988, 19021, 19054, 19087, 19120, 19153, 19186, 19219, 19252,
- 19285, 19318, 19351, 19384, 19417, 19450, 19483, 19516, 19549, 19582, 19615, 19648, 19681, 19714, 19747, 19780,
- 19813, 19846, 19879, 19968, 20001, 20034, 20067, 20100, 20133, 20166, 20199, 20232, 20265, 20298, 20331, 20364,
- 20397, 20430, 20463, 20496, 20529, 20562, 20595, 20628, 20661, 20694, 20727, 20760, 20793, 20826, 20859, 20892,
- 20925, 20958, 20991, 21024, 21057, 21090, 21123, 21156, 21189, 21222, 21255, 21288, 21321, 21354, 21387, 21420,
- 21453, 21486, 21519, 21552, 21585, 21618, 21651, 21684, 21717, 21750, 21783, 21816, 21849, 21882, 21915, 21948,
- 21981, 22014, 22047, 22080, 22113, 22146, 22179, 22212, 22245, 22278, 22311, 22344, 22377, 22410, 22443, 22476,
- 22509, 22542, 22575, 22608, 22641, 22674, 22707, 22740, 22773, 22806, 22839, 22872, 22905, 22938, 22971, 23004,
- 23037, 23070, 23103, 23136, 23169, 23202, 23235, 23268, 23301, 23334, 23367, 23400, 23433, 23466, 23499, 23532,
- 23565, 23598, 23631, 23664, 23697, 23730, 23763, 23796, 23829, 23862, 23895, 23928, 23961, 23994, 24027, 24060,
- 24093, 24126, 24159, 24192, 24225, 24258, 24291, 24324, 24357, 24390, 24423, 24456, 24489, 24522, 24555, 24588,
- 24621, 24654, 24687, 24720, 24753, 24786, 24819, 24852, 24885, 24918, 24951, 24984, 25017, 25050, 25083, 25116,
- 25149, 25182, 25215, 25248, 25281, 25314, 25347, 25380, 25413, 25446, 25479, 25512, 25545, 25578, 25611, 25644,
- 25677, 25710, 25743, 25776, 25809, 25842, 25875, 25908, 25941, 25974, 26007, 26040, 26073, 26106, 26139, 26172,
- 26205, 26238, 26271, 26304, 26337, 26370, 26403, 26436, 26469, 26502, 26535, 26568, 26601, 26634, 26667, 26700,
- 26733, 26766, 26799, 26832, 26865, 26898, 26931, 26964, 26997, 27030, 27063, 27096, 27129, 27162, 27195, 27228,
- 27261, 27294, 27327, 27360, 27393, 27426, 27459, 27492, 27525, 27558, 27591, 27624, 27657, 27690, 27723, 27756,
- 27789, 27822, 27855, 27888, 27921, 27954, 27987, 28020, 28053, 28086, 28119, 28152, 28185, 28218, 28251, 28284,
- 28317, 28350, 28383, 28416, 28449, 28482, 28515, 28548, 28581, 28614, 28647, 28680, 28713, 28746, 28779, 28812,
- 28845, 28878, 28911, 28944, 28977, 29010, 29043, 29076, 29109, 29142, 29175, 29208, 29241, 29274, 29307, 29340,
- 29373, 29406, 29439, 29472, 29505, 29538, 29571, 29604, 29637, 29670, 29703, 29736, 29769, 29802, 29835, 29868,
- 29901, 29934, 29967, 30000, 30033, 30066, 30099, 30132, 30165, 30198, 30231, 30264, 30297, 30330, 30363, 30396,
- 30429, 30462, 30495, 30528, 30561, 30594, 30627, 30660, 30693, 30726, 30759, 30792, 30825, 30858, 30891, 30924,
- 30957, 30990, 31023, 31056, 31089, 31122, 31155, 31188, 31221, 31254, 31287, 31320, 31353, 31386, 31419, 31452,
- 31485, 31518, 31551, 31584, 31617, 31650, 31683, 31716, 31749, 31782, 31815, 31848, 31881, 31914, 31947, 31980,
- 32013, 32046, 32079, 32112, 32145, 32178, 32211, 32244, 32277, 32310, 32343, 32376, 32409, 32442, 32475, 32508,
- 32541, 32574, 32607, 32640, 32673, 32706, 32739
- };
- static final char[] chars = Charset_AbstractTest.theseChars(codes);
-
- static abstract class CodesGenerator {
- int row = 0, col = 0;
- abstract void consume (int code);
-
- boolean isAccepted (int code)
- {
- return Character.isLetterOrDigit(code);
- }
- }
-
- static class CodesGenerator1 extends CodesGenerator {
- @Override
- void consume (int code) {
- System.out.print(code);
- System.out.print(", ");
- col++;
- if (col == 16) {
- System.out.println();
- row++;
- col = 0;
- }
- }
-
- @Override
- boolean isAccepted (int code)
- {
- return Character.isLetterOrDigit(code) || Character.isWhitespace(code);
- }
- }
-
- static class CodesGenerator2 extends CodesGenerator {
- @Override
- void consume (int code) {
-// System.out.print(code);
-// System.out.print(", ");
- System.out.print((char) code);
- col++;
- if (col == 80) {
- System.out.println();
- row++;
- col = 0;
- }
- }
- }
-
- static class CodesGenerator3 extends CodesGenerator {
- char[] buf = new char[8];
-
- @Override
- void consume (int code) {
- buf[col] = (char) code;
- System.out.print(code);
- System.out.print(", ");
- col++;
- if (col == 8) {
- System.out.print(" // ");
- System.out.println(buf);
- row++;
- col = 0;
- }
- }
-
- @Override
- boolean isAccepted (int code)
- {
- return Character.isLetterOrDigit(code);
-// || Character.isWhitespace(code);
- }
- }
-
- static void genCodes () {
- CodesGenerator gen = new CodesGenerator1();
- int code = 0;
- while (code < (1 << 10)) {
- while (!gen.isAccepted(code)) code ++;
- gen.consume(code);
- code += 3;
- }
- while (code < (1 << 15)) {
- while (!gen.isAccepted(code)) code ++;
- gen.consume(code);
- code += 33;
- }
- }
-
-
- static abstract class Dumper {
- int row = 0, col = 0;
- abstract void consume (int code);
- }
-
- static class Dumper1 extends Dumper {
- int colMax;
-
- Dumper1 () {
- colMax = 16;
- }
-
- Dumper1 (int colums) {
- colMax = colums;
- }
-
- @Override
- void consume (int code) {
- System.out.print(code);
- System.out.print(", ");
- col++;
- if (col == colMax) {
- System.out.println();
- row++;
- col = 0;
- }
- }
- }
-
- static void genEncoded (Charset charset, CharBuffer cb) {
- System.out.println(charset.name());
- Dumper out = new Dumper1();
- CharsetEncoder encoder = charset.newEncoder();
- encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
- try {
- ByteBuffer bb = encoder.encode(cb);
-// bb.rewind();
- while (bb.hasRemaining()) {
- out.consume(bb.get());
- }
- } catch (CharacterCodingException e) {
- System.out.println(e);
-// e.printStackTrace();
- }
- }
-
- static void genDecoded (Charset charset, ByteBuffer bb) {
- CharsetDecoder decoder = charset.newDecoder();
-// System.out.println(code);
-// bytes[0] = (byte) code;
-// System.out.println(bytes[0]);
-// ByteBuffer inputBB = ByteBuffer.wrap(bytes);
-// CharBuffer outputCB;
-// try {
-// outputCB = decoder.decode(inputBB);
-// outputCB.rewind();
-// System.out.println(outputCB);
-// } catch (CharacterCodingException e) {
-// System.out.println(e);
-//// e.printStackTrace();
-// }
- }
-
-
- public static void main(String[] args) {
-// charset = Charset.defaultCharset();
-// decoder = charset.newDecoder();
-// System.out.println(charset.name());
- genEncoded(Charset.forName("MacRoman"), CharBuffer.wrap(chars));
-// genEncoded(Charset.forName(charsetNames[37]), CharBuffer.wrap(chars));
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator_Res.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator_Res.java
deleted file mode 100644
index 1974a62..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_TestGenerator_Res.java
+++ /dev/null
@@ -1,2672 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-
-/**
- * Super class for concrete charset test suites.
- */
-public class Charset_TestGenerator_Res {
-
- Charset charset;
- CharsetDecoder decoder;
- CharsetEncoder encoder;
-
- // List of encodings currently required for Android.
- static String[] charsetNames = new String[] {
- // Encoding required by Java specification.
- "US-ASCII",
- "UTF-8",
- "UTF-16",
- "UTF-16BE",
- "UTF-16LE",
- "ISO-8859-1",
-
- // Additional encodings included in standard ICU
- "ISO-8859-2",
- "ISO-8859-3",
- "ISO-8859-4",
- "ISO-8859-5",
- "ISO-8859-6",
- "ISO-8859-7",
- "ISO-8859-8",
-//jdk NoSup "ISO-8859-8-I",
- "ISO-8859-9",
-//jdk NoSup "ISO-8859-10",
- "ISO-8859-11", //jdk x-...
- "ISO-8859-13",
-//jdk NoSup "ISO-8859-14",
- "ISO-8859-15",
-//jdk NoSup "ISO-8859-16",
- "ISO-2022-JP",
- "Windows-950", //jdk x-...
- "Windows-1250", //jdk x-...
- "Windows-1251",
- "Windows-1252",
- "Windows-1253",
- "Windows-1254",
- "Windows-1255",
- "Windows-1256",
- "Windows-1257",
- "Windows-1258",
- "Big5",
- "CP864",
- "CP874",
- "EUC-CN",
- "EUC-JP",
- "KOI8-R",
-//jdk NoSup "Macintosh",
- "GBK",
- "GB2312",
- "EUC-KR"};
-
- static final short[] codes = {
- 9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
- 89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 170, 181, 186, 192, 195, 198,
- 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246,
- 249, 252, 255, 258, 261, 264, 267, 270, 273, 276, 279, 282, 285, 288, 291, 294,
- 297, 300, 303, 306, 309, 312, 315, 318, 321, 324, 327, 330, 333, 336, 339, 342,
- 345, 348, 351, 354, 357, 360, 363, 366, 369, 372, 375, 378, 381, 384, 387, 390,
- 393, 396, 399, 402, 405, 408, 411, 414, 417, 420, 423, 426, 429, 432, 435, 438,
- 441, 444, 447, 450, 453, 456, 459, 462, 465, 468, 471, 474, 477, 480, 483, 486,
- 489, 492, 495, 498, 501, 504, 507, 510, 513, 516, 519, 522, 525, 528, 531, 534,
- 537, 540, 543, 546, 549, 552, 555, 558, 561, 564, 592, 595, 598, 601, 604, 607,
- 610, 613, 616, 619, 622, 625, 628, 631, 634, 637, 640, 643, 646, 649, 652, 655,
- 658, 661, 664, 667, 670, 673, 676, 679, 682, 685, 688, 691, 694, 697, 700, 703,
- 710, 713, 716, 719, 736, 739, 750, 890, 902, 905, 908, 911, 914, 917, 920, 923,
- 926, 929, 932, 935, 938, 941, 944, 947, 950, 953, 956, 959, 962, 965, 968, 971,
- 974, 977, 980, 983, 986, 989, 992, 995, 998, 1001, 1004, 1007, 1010, 1013, 1016, 1019,
- 1024, 1027, 1060, 1093, 1126, 1162, 1195, 1228, 1261, 1294, 1329, 1362, 1395, 1488, 1521, 1569,
- 1602, 1635, 1668, 1701, 1734, 1774, 1808, 1869, 1920, 1953, 2308, 2341, 2384, 2437, 2470, 2524,
- 2565, 2598, 2649, 2693, 2726, 2768, 2821, 2854, 2908, 2947, 2980, 3047, 3080, 3114, 3168, 3205,
- 3238, 3294, 3333, 3366, 3424, 3461, 3494, 3585, 3618, 3651, 3713, 3746, 3779, 3840, 3873, 3906,
- 3939, 3976, 4096, 4129, 4162, 4256, 4289, 4322, 4355, 4388, 4421, 4454, 4487, 4520, 4553, 4586,
- 4619, 4652, 4685, 4718, 4752, 4786, 4819, 4852, 4885, 4918, 4951, 5024, 5057, 5090, 5123, 5156,
- 5189, 5222, 5255, 5288, 5321, 5354, 5387, 5420, 5453, 5486, 5519, 5552, 5585, 5618, 5651, 5684,
- 5717, 5750, 5783, 5816, 5849, 5888, 5921, 5954, 5987, 6020, 6053, 6103, 6158, 6191, 6224, 6257,
- 6290, 6400, 6470, 6503, 7424, 7457, 7490, 7523, 7680, 7713, 7746, 7779, 7812, 7845, 7878, 7911,
- 7944, 7977, 8010, 8043, 8076, 8109, 8144, 8178, 8232, 8287, 8450, 8484, 8517, 12288, 12337, 12370,
- 12403, 12436, 12469, 12502, 12535, 12568, 12601, 12634, 12667, 12704, 12784, 13312, 13345, 13378, 13411, 13444,
- 13477, 13510, 13543, 13576, 13609, 13642, 13675, 13708, 13741, 13774, 13807, 13840, 13873, 13906, 13939, 13972,
- 14005, 14038, 14071, 14104, 14137, 14170, 14203, 14236, 14269, 14302, 14335, 14368, 14401, 14434, 14467, 14500,
- 14533, 14566, 14599, 14632, 14665, 14698, 14731, 14764, 14797, 14830, 14863, 14896, 14929, 14962, 14995, 15028,
- 15061, 15094, 15127, 15160, 15193, 15226, 15259, 15292, 15325, 15358, 15391, 15424, 15457, 15490, 15523, 15556,
- 15589, 15622, 15655, 15688, 15721, 15754, 15787, 15820, 15853, 15886, 15919, 15952, 15985, 16018, 16051, 16084,
- 16117, 16150, 16183, 16216, 16249, 16282, 16315, 16348, 16381, 16414, 16447, 16480, 16513, 16546, 16579, 16612,
- 16645, 16678, 16711, 16744, 16777, 16810, 16843, 16876, 16909, 16942, 16975, 17008, 17041, 17074, 17107, 17140,
- 17173, 17206, 17239, 17272, 17305, 17338, 17371, 17404, 17437, 17470, 17503, 17536, 17569, 17602, 17635, 17668,
- 17701, 17734, 17767, 17800, 17833, 17866, 17899, 17932, 17965, 17998, 18031, 18064, 18097, 18130, 18163, 18196,
- 18229, 18262, 18295, 18328, 18361, 18394, 18427, 18460, 18493, 18526, 18559, 18592, 18625, 18658, 18691, 18724,
- 18757, 18790, 18823, 18856, 18889, 18922, 18955, 18988, 19021, 19054, 19087, 19120, 19153, 19186, 19219, 19252,
- 19285, 19318, 19351, 19384, 19417, 19450, 19483, 19516, 19549, 19582, 19615, 19648, 19681, 19714, 19747, 19780,
- 19813, 19846, 19879, 19968, 20001, 20034, 20067, 20100, 20133, 20166, 20199, 20232, 20265, 20298, 20331, 20364,
- 20397, 20430, 20463, 20496, 20529, 20562, 20595, 20628, 20661, 20694, 20727, 20760, 20793, 20826, 20859, 20892,
- 20925, 20958, 20991, 21024, 21057, 21090, 21123, 21156, 21189, 21222, 21255, 21288, 21321, 21354, 21387, 21420,
- 21453, 21486, 21519, 21552, 21585, 21618, 21651, 21684, 21717, 21750, 21783, 21816, 21849, 21882, 21915, 21948,
- 21981, 22014, 22047, 22080, 22113, 22146, 22179, 22212, 22245, 22278, 22311, 22344, 22377, 22410, 22443, 22476,
- 22509, 22542, 22575, 22608, 22641, 22674, 22707, 22740, 22773, 22806, 22839, 22872, 22905, 22938, 22971, 23004,
- 23037, 23070, 23103, 23136, 23169, 23202, 23235, 23268, 23301, 23334, 23367, 23400, 23433, 23466, 23499, 23532,
- 23565, 23598, 23631, 23664, 23697, 23730, 23763, 23796, 23829, 23862, 23895, 23928, 23961, 23994, 24027, 24060,
- 24093, 24126, 24159, 24192, 24225, 24258, 24291, 24324, 24357, 24390, 24423, 24456, 24489, 24522, 24555, 24588,
- 24621, 24654, 24687, 24720, 24753, 24786, 24819, 24852, 24885, 24918, 24951, 24984, 25017, 25050, 25083, 25116,
- 25149, 25182, 25215, 25248, 25281, 25314, 25347, 25380, 25413, 25446, 25479, 25512, 25545, 25578, 25611, 25644,
- 25677, 25710, 25743, 25776, 25809, 25842, 25875, 25908, 25941, 25974, 26007, 26040, 26073, 26106, 26139, 26172,
- 26205, 26238, 26271, 26304, 26337, 26370, 26403, 26436, 26469, 26502, 26535, 26568, 26601, 26634, 26667, 26700,
- 26733, 26766, 26799, 26832, 26865, 26898, 26931, 26964, 26997, 27030, 27063, 27096, 27129, 27162, 27195, 27228,
- 27261, 27294, 27327, 27360, 27393, 27426, 27459, 27492, 27525, 27558, 27591, 27624, 27657, 27690, 27723, 27756,
- 27789, 27822, 27855, 27888, 27921, 27954, 27987, 28020, 28053, 28086, 28119, 28152, 28185, 28218, 28251, 28284,
- 28317, 28350, 28383, 28416, 28449, 28482, 28515, 28548, 28581, 28614, 28647, 28680, 28713, 28746, 28779, 28812,
- 28845, 28878, 28911, 28944, 28977, 29010, 29043, 29076, 29109, 29142, 29175, 29208, 29241, 29274, 29307, 29340,
- 29373, 29406, 29439, 29472, 29505, 29538, 29571, 29604, 29637, 29670, 29703, 29736, 29769, 29802, 29835, 29868,
- 29901, 29934, 29967, 30000, 30033, 30066, 30099, 30132, 30165, 30198, 30231, 30264, 30297, 30330, 30363, 30396,
- 30429, 30462, 30495, 30528, 30561, 30594, 30627, 30660, 30693, 30726, 30759, 30792, 30825, 30858, 30891, 30924,
- 30957, 30990, 31023, 31056, 31089, 31122, 31155, 31188, 31221, 31254, 31287, 31320, 31353, 31386, 31419, 31452,
- 31485, 31518, 31551, 31584, 31617, 31650, 31683, 31716, 31749, 31782, 31815, 31848, 31881, 31914, 31947, 31980,
- 32013, 32046, 32079, 32112, 32145, 32178, 32211, 32244, 32277, 32310, 32343, 32376, 32409, 32442, 32475, 32508,
- 32541, 32574, 32607, 32640, 32673, 32706, 32739
- };
- static final char[] chars = new char[codes.length]; // Is filled with contents of codes.
-
-// {
-// System.out.println("TEST");
-//// System.arraycopy(codes, 0, chars, 0, codes.length); // Na super! Der Compiler nimmt's, aber Runtime gibt's ArrayStoreException.
-// for (int i = 0; i < codes.length; i++) chars[i] = (char) codes[i];
-// }
-
-
-
-/*
-US-ASCII
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
- */
-
-/*
-UTF-8
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -62, -86, -62, -75, -62, -70,
--61, -128, -61, -125, -61, -122, -61, -119, -61, -116, -61, -113, -61, -110, -61, -107,
--61, -104, -61, -101, -61, -98, -61, -95, -61, -92, -61, -89, -61, -86, -61, -83,
--61, -80, -61, -77, -61, -74, -61, -71, -61, -68, -61, -65, -60, -126, -60, -123,
--60, -120, -60, -117, -60, -114, -60, -111, -60, -108, -60, -105, -60, -102, -60, -99,
--60, -96, -60, -93, -60, -90, -60, -87, -60, -84, -60, -81, -60, -78, -60, -75,
--60, -72, -60, -69, -60, -66, -59, -127, -59, -124, -59, -121, -59, -118, -59, -115,
--59, -112, -59, -109, -59, -106, -59, -103, -59, -100, -59, -97, -59, -94, -59, -91,
--59, -88, -59, -85, -59, -82, -59, -79, -59, -76, -59, -73, -59, -70, -59, -67,
--58, -128, -58, -125, -58, -122, -58, -119, -58, -116, -58, -113, -58, -110, -58, -107,
--58, -104, -58, -101, -58, -98, -58, -95, -58, -92, -58, -89, -58, -86, -58, -83,
--58, -80, -58, -77, -58, -74, -58, -71, -58, -68, -58, -65, -57, -126, -57, -123,
--57, -120, -57, -117, -57, -114, -57, -111, -57, -108, -57, -105, -57, -102, -57, -99,
--57, -96, -57, -93, -57, -90, -57, -87, -57, -84, -57, -81, -57, -78, -57, -75,
--57, -72, -57, -69, -57, -66, -56, -127, -56, -124, -56, -121, -56, -118, -56, -115,
--56, -112, -56, -109, -56, -106, -56, -103, -56, -100, -56, -97, -56, -94, -56, -91,
--56, -88, -56, -85, -56, -82, -56, -79, -56, -76, -55, -112, -55, -109, -55, -106,
--55, -103, -55, -100, -55, -97, -55, -94, -55, -91, -55, -88, -55, -85, -55, -82,
--55, -79, -55, -76, -55, -73, -55, -70, -55, -67, -54, -128, -54, -125, -54, -122,
--54, -119, -54, -116, -54, -113, -54, -110, -54, -107, -54, -104, -54, -101, -54, -98,
--54, -95, -54, -92, -54, -89, -54, -86, -54, -83, -54, -80, -54, -77, -54, -74,
--54, -71, -54, -68, -54, -65, -53, -122, -53, -119, -53, -116, -53, -113, -53, -96,
--53, -93, -53, -82, -51, -70, -50, -122, -50, -119, -50, -116, -50, -113, -50, -110,
--50, -107, -50, -104, -50, -101, -50, -98, -50, -95, -50, -92, -50, -89, -50, -86,
--50, -83, -50, -80, -50, -77, -50, -74, -50, -71, -50, -68, -50, -65, -49, -126,
--49, -123, -49, -120, -49, -117, -49, -114, -49, -111, -49, -108, -49, -105, -49, -102,
--49, -99, -49, -96, -49, -93, -49, -90, -49, -87, -49, -84, -49, -81, -49, -78,
--49, -75, -49, -72, -49, -69, -48, -128, -48, -125, -48, -92, -47, -123, -47, -90,
--46, -118, -46, -85, -45, -116, -45, -83, -44, -114, -44, -79, -43, -110, -43, -77,
--41, -112, -41, -79, -40, -95, -39, -126, -39, -93, -38, -124, -38, -91, -37, -122,
--37, -82, -36, -112, -35, -115, -34, -128, -34, -95, -32, -92, -124, -32, -92, -91,
--32, -91, -112, -32, -90, -123, -32, -90, -90, -32, -89, -100, -32, -88, -123, -32,
--88, -90, -32, -87, -103, -32, -86, -123, -32, -86, -90, -32, -85, -112, -32, -84,
--123, -32, -84, -90, -32, -83, -100, -32, -82, -125, -32, -82, -92, -32, -81, -89,
--32, -80, -120, -32, -80, -86, -32, -79, -96, -32, -78, -123, -32, -78, -90, -32,
--77, -98, -32, -76, -123, -32, -76, -90, -32, -75, -96, -32, -74, -123, -32, -74,
--90, -32, -72, -127, -32, -72, -94, -32, -71, -125, -32, -70, -127, -32, -70, -94,
--32, -69, -125, -32, -68, -128, -32, -68, -95, -32, -67, -126, -32, -67, -93, -32,
--66, -120, -31, -128, -128, -31, -128, -95, -31, -127, -126, -31, -126, -96, -31, -125,
--127, -31, -125, -94, -31, -124, -125, -31, -124, -92, -31, -123, -123, -31, -123, -90,
--31, -122, -121, -31, -122, -88, -31, -121, -119, -31, -121, -86, -31, -120, -117, -31,
--120, -84, -31, -119, -115, -31, -119, -82, -31, -118, -112, -31, -118, -78, -31, -117,
--109, -31, -117, -76, -31, -116, -107, -31, -116, -74, -31, -115, -105, -31, -114, -96,
--31, -113, -127, -31, -113, -94, -31, -112, -125, -31, -112, -92, -31, -111, -123, -31,
--111, -90, -31, -110, -121, -31, -110, -88, -31, -109, -119, -31, -109, -86, -31, -108,
--117, -31, -108, -84, -31, -107, -115, -31, -107, -82, -31, -106, -113, -31, -106, -80,
--31, -105, -111, -31, -105, -78, -31, -104, -109, -31, -104, -76, -31, -103, -107, -31,
--103, -74, -31, -102, -105, -31, -102, -72, -31, -101, -103, -31, -100, -128, -31, -100,
--95, -31, -99, -126, -31, -99, -93, -31, -98, -124, -31, -98, -91, -31, -97, -105,
--31, -96, -114, -31, -96, -81, -31, -95, -112, -31, -95, -79, -31, -94, -110, -31,
--92, -128, -31, -91, -122, -31, -91, -89, -31, -76, -128, -31, -76, -95, -31, -75,
--126, -31, -75, -93, -31, -72, -128, -31, -72, -95, -31, -71, -126, -31, -71, -93,
--31, -70, -124, -31, -70, -91, -31, -69, -122, -31, -69, -89, -31, -68, -120, -31,
--68, -87, -31, -67, -118, -31, -67, -85, -31, -66, -116, -31, -66, -83, -31, -65,
--112, -31, -65, -78, -30, -128, -88, -30, -127, -97, -30, -124, -126, -30, -124, -92,
--30, -123, -123, -29, -128, -128, -29, -128, -79, -29, -127, -110, -29, -127, -77, -29,
--126, -108, -29, -126, -75, -29, -125, -106, -29, -125, -73, -29, -124, -104, -29, -124,
--71, -29, -123, -102, -29, -123, -69, -29, -122, -96, -29, -121, -80, -29, -112, -128,
--29, -112, -95, -29, -111, -126, -29, -111, -93, -29, -110, -124, -29, -110, -91, -29,
--109, -122, -29, -109, -89, -29, -108, -120, -29, -108, -87, -29, -107, -118, -29, -107,
--85, -29, -106, -116, -29, -106, -83, -29, -105, -114, -29, -105, -81, -29, -104, -112,
--29, -104, -79, -29, -103, -110, -29, -103, -77, -29, -102, -108, -29, -102, -75, -29,
--101, -106, -29, -101, -73, -29, -100, -104, -29, -100, -71, -29, -99, -102, -29, -99,
--69, -29, -98, -100, -29, -98, -67, -29, -97, -98, -29, -97, -65, -29, -96, -96,
--29, -95, -127, -29, -95, -94, -29, -94, -125, -29, -94, -92, -29, -93, -123, -29,
--93, -90, -29, -92, -121, -29, -92, -88, -29, -91, -119, -29, -91, -86, -29, -90,
--117, -29, -90, -84, -29, -89, -115, -29, -89, -82, -29, -88, -113, -29, -88, -80,
--29, -87, -111, -29, -87, -78, -29, -86, -109, -29, -86, -76, -29, -85, -107, -29,
--85, -74, -29, -84, -105, -29, -84, -72, -29, -83, -103, -29, -83, -70, -29, -82,
--101, -29, -82, -68, -29, -81, -99, -29, -81, -66, -29, -80, -97, -29, -79, -128,
--29, -79, -95, -29, -78, -126, -29, -78, -93, -29, -77, -124, -29, -77, -91, -29,
--76, -122, -29, -76, -89, -29, -75, -120, -29, -75, -87, -29, -74, -118, -29, -74,
--85, -29, -73, -116, -29, -73, -83, -29, -72, -114, -29, -72, -81, -29, -71, -112,
--29, -71, -79, -29, -70, -110, -29, -70, -77, -29, -69, -108, -29, -69, -75, -29,
--68, -106, -29, -68, -73, -29, -67, -104, -29, -67, -71, -29, -66, -102, -29, -66,
--69, -29, -65, -100, -29, -65, -67, -28, -128, -98, -28, -128, -65, -28, -127, -96,
--28, -126, -127, -28, -126, -94, -28, -125, -125, -28, -125, -92, -28, -124, -123, -28,
--124, -90, -28, -123, -121, -28, -123, -88, -28, -122, -119, -28, -122, -86, -28, -121,
--117, -28, -121, -84, -28, -120, -115, -28, -120, -82, -28, -119, -113, -28, -119, -80,
--28, -118, -111, -28, -118, -78, -28, -117, -109, -28, -117, -76, -28, -116, -107, -28,
--116, -74, -28, -115, -105, -28, -115, -72, -28, -114, -103, -28, -114, -70, -28, -113,
--101, -28, -113, -68, -28, -112, -99, -28, -112, -66, -28, -111, -97, -28, -110, -128,
--28, -110, -95, -28, -109, -126, -28, -109, -93, -28, -108, -124, -28, -108, -91, -28,
--107, -122, -28, -107, -89, -28, -106, -120, -28, -106, -87, -28, -105, -118, -28, -105,
--85, -28, -104, -116, -28, -104, -83, -28, -103, -114, -28, -103, -81, -28, -102, -112,
--28, -102, -79, -28, -101, -110, -28, -101, -77, -28, -100, -108, -28, -100, -75, -28,
--99, -106, -28, -99, -73, -28, -98, -104, -28, -98, -71, -28, -97, -102, -28, -97,
--69, -28, -96, -100, -28, -96, -67, -28, -95, -98, -28, -95, -65, -28, -94, -96,
--28, -93, -127, -28, -93, -94, -28, -92, -125, -28, -92, -92, -28, -91, -123, -28,
--91, -90, -28, -90, -121, -28, -90, -88, -28, -89, -119, -28, -89, -86, -28, -88,
--117, -28, -88, -84, -28, -87, -115, -28, -87, -82, -28, -86, -113, -28, -86, -80,
--28, -85, -111, -28, -85, -78, -28, -84, -109, -28, -84, -76, -28, -83, -107, -28,
--83, -74, -28, -82, -105, -28, -82, -72, -28, -81, -103, -28, -81, -70, -28, -80,
--101, -28, -80, -68, -28, -79, -99, -28, -79, -66, -28, -78, -97, -28, -77, -128,
--28, -77, -95, -28, -76, -126, -28, -76, -93, -28, -75, -124, -28, -75, -91, -28,
--74, -122, -28, -74, -89, -28, -72, -128, -28, -72, -95, -28, -71, -126, -28, -71,
--93, -28, -70, -124, -28, -70, -91, -28, -69, -122, -28, -69, -89, -28, -68, -120,
--28, -68, -87, -28, -67, -118, -28, -67, -85, -28, -66, -116, -28, -66, -83, -28,
--65, -114, -28, -65, -81, -27, -128, -112, -27, -128, -79, -27, -127, -110, -27, -127,
--77, -27, -126, -108, -27, -126, -75, -27, -125, -106, -27, -125, -73, -27, -124, -104,
--27, -124, -71, -27, -123, -102, -27, -123, -69, -27, -122, -100, -27, -122, -67, -27,
--121, -98, -27, -121, -65, -27, -120, -96, -27, -119, -127, -27, -119, -94, -27, -118,
--125, -27, -118, -92, -27, -117, -123, -27, -117, -90, -27, -116, -121, -27, -116, -88,
--27, -115, -119, -27, -115, -86, -27, -114, -117, -27, -114, -84, -27, -113, -115, -27,
--113, -82, -27, -112, -113, -27, -112, -80, -27, -111, -111, -27, -111, -78, -27, -110,
--109, -27, -110, -76, -27, -109, -107, -27, -109, -74, -27, -108, -105, -27, -108, -72,
--27, -107, -103, -27, -107, -70, -27, -106, -101, -27, -106, -68, -27, -105, -99, -27,
--105, -66, -27, -104, -97, -27, -103, -128, -27, -103, -95, -27, -102, -126, -27, -102,
--93, -27, -101, -124, -27, -101, -91, -27, -100, -122, -27, -100, -89, -27, -99, -120,
--27, -99, -87, -27, -98, -118, -27, -98, -85, -27, -97, -116, -27, -97, -83, -27,
--96, -114, -27, -96, -81, -27, -95, -112, -27, -95, -79, -27, -94, -110, -27, -94,
--77, -27, -93, -108, -27, -93, -75, -27, -92, -106, -27, -92, -73, -27, -91, -104,
--27, -91, -71, -27, -90, -102, -27, -90, -69, -27, -89, -100, -27, -89, -67, -27,
--88, -98, -27, -88, -65, -27, -87, -96, -27, -86, -127, -27, -86, -94, -27, -85,
--125, -27, -85, -92, -27, -84, -123, -27, -84, -90, -27, -83, -121, -27, -83, -88,
--27, -82, -119, -27, -82, -86, -27, -81, -117, -27, -81, -84, -27, -80, -115, -27,
--80, -82, -27, -79, -113, -27, -79, -80, -27, -78, -111, -27, -78, -78, -27, -77,
--109, -27, -77, -76, -27, -76, -107, -27, -76, -74, -27, -75, -105, -27, -75, -72,
--27, -74, -103, -27, -74, -70, -27, -73, -101, -27, -73, -68, -27, -72, -99, -27,
--72, -66, -27, -71, -97, -27, -70, -128, -27, -70, -95, -27, -69, -126, -27, -69,
--93, -27, -68, -124, -27, -68, -91, -27, -67, -122, -27, -67, -89, -27, -66, -120,
--27, -66, -87, -27, -65, -118, -27, -65, -85, -26, -128, -116, -26, -128, -83, -26,
--127, -114, -26, -127, -81, -26, -126, -112, -26, -126, -79, -26, -125, -110, -26, -125,
--77, -26, -124, -108, -26, -124, -75, -26, -123, -106, -26, -123, -73, -26, -122, -104,
--26, -122, -71, -26, -121, -102, -26, -121, -69, -26, -120, -100, -26, -120, -67, -26,
--119, -98, -26, -119, -65, -26, -118, -96, -26, -117, -127, -26, -117, -94, -26, -116,
--125, -26, -116, -92, -26, -115, -123, -26, -115, -90, -26, -114, -121, -26, -114, -88,
--26, -113, -119, -26, -113, -86, -26, -112, -117, -26, -112, -84, -26, -111, -115, -26,
--111, -82, -26, -110, -113, -26, -110, -80, -26, -109, -111, -26, -109, -78, -26, -108,
--109, -26, -108, -76, -26, -107, -107, -26, -107, -74, -26, -106, -105, -26, -106, -72,
--26, -105, -103, -26, -105, -70, -26, -104, -101, -26, -104, -68, -26, -103, -99, -26,
--103, -66, -26, -102, -97, -26, -101, -128, -26, -101, -95, -26, -100, -126, -26, -100,
--93, -26, -99, -124, -26, -99, -91, -26, -98, -122, -26, -98, -89, -26, -97, -120,
--26, -97, -87, -26, -96, -118, -26, -96, -85, -26, -95, -116, -26, -95, -83, -26,
--94, -114, -26, -94, -81, -26, -93, -112, -26, -93, -79, -26, -92, -110, -26, -92,
--77, -26, -91, -108, -26, -91, -75, -26, -90, -106, -26, -90, -73, -26, -89, -104,
--26, -89, -71, -26, -88, -102, -26, -88, -69, -26, -87, -100, -26, -87, -67, -26,
--86, -98, -26, -86, -65, -26, -85, -96, -26, -84, -127, -26, -84, -94, -26, -83,
--125, -26, -83, -92, -26, -82, -123, -26, -82, -90, -26, -81, -121, -26, -81, -88,
--26, -80, -119, -26, -80, -86, -26, -79, -117, -26, -79, -84, -26, -78, -115, -26,
--78, -82, -26, -77, -113, -26, -77, -80, -26, -76, -111, -26, -76, -78, -26, -75,
--109, -26, -75, -76, -26, -74, -107, -26, -74, -74, -26, -73, -105, -26, -73, -72,
--26, -72, -103, -26, -72, -70, -26, -71, -101, -26, -71, -68, -26, -70, -99, -26,
--70, -66, -26, -69, -97, -26, -68, -128, -26, -68, -95, -26, -67, -126, -26, -67,
--93, -26, -66, -124, -26, -66, -91, -26, -65, -122, -26, -65, -89, -25, -128, -120,
--25, -128, -87, -25, -127, -118, -25, -127, -85, -25, -126, -116, -25, -126, -83, -25,
--125, -114, -25, -125, -81, -25, -124, -112, -25, -124, -79, -25, -123, -110, -25, -123,
--77, -25, -122, -108, -25, -122, -75, -25, -121, -106, -25, -121, -73, -25, -120, -104,
--25, -120, -71, -25, -119, -102, -25, -119, -69, -25, -118, -100, -25, -118, -67, -25,
--117, -98, -25, -117, -65, -25, -116, -96, -25, -115, -127, -25, -115, -94, -25, -114,
--125, -25, -114, -92, -25, -113, -123, -25, -113, -90, -25, -112, -121, -25, -112, -88,
--25, -111, -119, -25, -111, -86, -25, -110, -117, -25, -110, -84, -25, -109, -115, -25,
--109, -82, -25, -108, -113, -25, -108, -80, -25, -107, -111, -25, -107, -78, -25, -106,
--109, -25, -106, -76, -25, -105, -107, -25, -105, -74, -25, -104, -105, -25, -104, -72,
--25, -103, -103, -25, -103, -70, -25, -102, -101, -25, -102, -68, -25, -101, -99, -25,
--101, -66, -25, -100, -97, -25, -99, -128, -25, -99, -95, -25, -98, -126, -25, -98,
--93, -25, -97, -124, -25, -97, -91, -25, -96, -122, -25, -96, -89, -25, -95, -120,
--25, -95, -87, -25, -94, -118, -25, -94, -85, -25, -93, -116, -25, -93, -83, -25,
--92, -114, -25, -92, -81, -25, -91, -112, -25, -91, -79, -25, -90, -110, -25, -90,
--77, -25, -89, -108, -25, -89, -75, -25, -88, -106, -25, -88, -73, -25, -87, -104,
--25, -87, -71, -25, -86, -102, -25, -86, -69, -25, -85, -100, -25, -85, -67, -25,
--84, -98, -25, -84, -65, -25, -83, -96, -25, -82, -127, -25, -82, -94, -25, -81,
--125, -25, -81, -92, -25, -80, -123, -25, -80, -90, -25, -79, -121, -25, -79, -88,
--25, -78, -119, -25, -78, -86, -25, -77, -117, -25, -77, -84, -25, -76, -115, -25,
--76, -82, -25, -75, -113, -25, -75, -80, -25, -74, -111, -25, -74, -78, -25, -73,
--109, -25, -73, -76, -25, -72, -107, -25, -72, -74, -25, -71, -105, -25, -71, -72,
--25, -70, -103, -25, -70, -70, -25, -69, -101, -25, -69, -68, -25, -68, -99, -25,
--68, -66, -25, -67, -97, -25, -66, -128, -25, -66, -95, -25, -65, -126, -25, -65,
--93,
- */
-
-/*
-UTF-16
--2, -1, 0, 9, 0, 12, 0, 28, 0, 31, 0, 48, 0, 51, 0, 54,
-0, 57, 0, 65, 0, 68, 0, 71, 0, 74, 0, 77, 0, 80, 0, 83,
-0, 86, 0, 89, 0, 97, 0, 100, 0, 103, 0, 106, 0, 109, 0, 112,
-0, 115, 0, 118, 0, 121, 0, -86, 0, -75, 0, -70, 0, -64, 0, -61,
-0, -58, 0, -55, 0, -52, 0, -49, 0, -46, 0, -43, 0, -40, 0, -37,
-0, -34, 0, -31, 0, -28, 0, -25, 0, -22, 0, -19, 0, -16, 0, -13,
-0, -10, 0, -7, 0, -4, 0, -1, 1, 2, 1, 5, 1, 8, 1, 11,
-1, 14, 1, 17, 1, 20, 1, 23, 1, 26, 1, 29, 1, 32, 1, 35,
-1, 38, 1, 41, 1, 44, 1, 47, 1, 50, 1, 53, 1, 56, 1, 59,
-1, 62, 1, 65, 1, 68, 1, 71, 1, 74, 1, 77, 1, 80, 1, 83,
-1, 86, 1, 89, 1, 92, 1, 95, 1, 98, 1, 101, 1, 104, 1, 107,
-1, 110, 1, 113, 1, 116, 1, 119, 1, 122, 1, 125, 1, -128, 1, -125,
-1, -122, 1, -119, 1, -116, 1, -113, 1, -110, 1, -107, 1, -104, 1, -101,
-1, -98, 1, -95, 1, -92, 1, -89, 1, -86, 1, -83, 1, -80, 1, -77,
-1, -74, 1, -71, 1, -68, 1, -65, 1, -62, 1, -59, 1, -56, 1, -53,
-1, -50, 1, -47, 1, -44, 1, -41, 1, -38, 1, -35, 1, -32, 1, -29,
-1, -26, 1, -23, 1, -20, 1, -17, 1, -14, 1, -11, 1, -8, 1, -5,
-1, -2, 2, 1, 2, 4, 2, 7, 2, 10, 2, 13, 2, 16, 2, 19,
-2, 22, 2, 25, 2, 28, 2, 31, 2, 34, 2, 37, 2, 40, 2, 43,
-2, 46, 2, 49, 2, 52, 2, 80, 2, 83, 2, 86, 2, 89, 2, 92,
-2, 95, 2, 98, 2, 101, 2, 104, 2, 107, 2, 110, 2, 113, 2, 116,
-2, 119, 2, 122, 2, 125, 2, -128, 2, -125, 2, -122, 2, -119, 2, -116,
-2, -113, 2, -110, 2, -107, 2, -104, 2, -101, 2, -98, 2, -95, 2, -92,
-2, -89, 2, -86, 2, -83, 2, -80, 2, -77, 2, -74, 2, -71, 2, -68,
-2, -65, 2, -58, 2, -55, 2, -52, 2, -49, 2, -32, 2, -29, 2, -18,
-3, 122, 3, -122, 3, -119, 3, -116, 3, -113, 3, -110, 3, -107, 3, -104,
-3, -101, 3, -98, 3, -95, 3, -92, 3, -89, 3, -86, 3, -83, 3, -80,
-3, -77, 3, -74, 3, -71, 3, -68, 3, -65, 3, -62, 3, -59, 3, -56,
-3, -53, 3, -50, 3, -47, 3, -44, 3, -41, 3, -38, 3, -35, 3, -32,
-3, -29, 3, -26, 3, -23, 3, -20, 3, -17, 3, -14, 3, -11, 3, -8,
-3, -5, 4, 0, 4, 3, 4, 36, 4, 69, 4, 102, 4, -118, 4, -85,
-4, -52, 4, -19, 5, 14, 5, 49, 5, 82, 5, 115, 5, -48, 5, -15,
-6, 33, 6, 66, 6, 99, 6, -124, 6, -91, 6, -58, 6, -18, 7, 16,
-7, 77, 7, -128, 7, -95, 9, 4, 9, 37, 9, 80, 9, -123, 9, -90,
-9, -36, 10, 5, 10, 38, 10, 89, 10, -123, 10, -90, 10, -48, 11, 5,
-11, 38, 11, 92, 11, -125, 11, -92, 11, -25, 12, 8, 12, 42, 12, 96,
-12, -123, 12, -90, 12, -34, 13, 5, 13, 38, 13, 96, 13, -123, 13, -90,
-14, 1, 14, 34, 14, 67, 14, -127, 14, -94, 14, -61, 15, 0, 15, 33,
-15, 66, 15, 99, 15, -120, 16, 0, 16, 33, 16, 66, 16, -96, 16, -63,
-16, -30, 17, 3, 17, 36, 17, 69, 17, 102, 17, -121, 17, -88, 17, -55,
-17, -22, 18, 11, 18, 44, 18, 77, 18, 110, 18, -112, 18, -78, 18, -45,
-18, -12, 19, 21, 19, 54, 19, 87, 19, -96, 19, -63, 19, -30, 20, 3,
-20, 36, 20, 69, 20, 102, 20, -121, 20, -88, 20, -55, 20, -22, 21, 11,
-21, 44, 21, 77, 21, 110, 21, -113, 21, -80, 21, -47, 21, -14, 22, 19,
-22, 52, 22, 85, 22, 118, 22, -105, 22, -72, 22, -39, 23, 0, 23, 33,
-23, 66, 23, 99, 23, -124, 23, -91, 23, -41, 24, 14, 24, 47, 24, 80,
-24, 113, 24, -110, 25, 0, 25, 70, 25, 103, 29, 0, 29, 33, 29, 66,
-29, 99, 30, 0, 30, 33, 30, 66, 30, 99, 30, -124, 30, -91, 30, -58,
-30, -25, 31, 8, 31, 41, 31, 74, 31, 107, 31, -116, 31, -83, 31, -48,
-31, -14, 32, 40, 32, 95, 33, 2, 33, 36, 33, 69, 48, 0, 48, 49,
-48, 82, 48, 115, 48, -108, 48, -75, 48, -42, 48, -9, 49, 24, 49, 57,
-49, 90, 49, 123, 49, -96, 49, -16, 52, 0, 52, 33, 52, 66, 52, 99,
-52, -124, 52, -91, 52, -58, 52, -25, 53, 8, 53, 41, 53, 74, 53, 107,
-53, -116, 53, -83, 53, -50, 53, -17, 54, 16, 54, 49, 54, 82, 54, 115,
-54, -108, 54, -75, 54, -42, 54, -9, 55, 24, 55, 57, 55, 90, 55, 123,
-55, -100, 55, -67, 55, -34, 55, -1, 56, 32, 56, 65, 56, 98, 56, -125,
-56, -92, 56, -59, 56, -26, 57, 7, 57, 40, 57, 73, 57, 106, 57, -117,
-57, -84, 57, -51, 57, -18, 58, 15, 58, 48, 58, 81, 58, 114, 58, -109,
-58, -76, 58, -43, 58, -10, 59, 23, 59, 56, 59, 89, 59, 122, 59, -101,
-59, -68, 59, -35, 59, -2, 60, 31, 60, 64, 60, 97, 60, -126, 60, -93,
-60, -60, 60, -27, 61, 6, 61, 39, 61, 72, 61, 105, 61, -118, 61, -85,
-61, -52, 61, -19, 62, 14, 62, 47, 62, 80, 62, 113, 62, -110, 62, -77,
-62, -44, 62, -11, 63, 22, 63, 55, 63, 88, 63, 121, 63, -102, 63, -69,
-63, -36, 63, -3, 64, 30, 64, 63, 64, 96, 64, -127, 64, -94, 64, -61,
-64, -28, 65, 5, 65, 38, 65, 71, 65, 104, 65, -119, 65, -86, 65, -53,
-65, -20, 66, 13, 66, 46, 66, 79, 66, 112, 66, -111, 66, -78, 66, -45,
-66, -12, 67, 21, 67, 54, 67, 87, 67, 120, 67, -103, 67, -70, 67, -37,
-67, -4, 68, 29, 68, 62, 68, 95, 68, -128, 68, -95, 68, -62, 68, -29,
-69, 4, 69, 37, 69, 70, 69, 103, 69, -120, 69, -87, 69, -54, 69, -21,
-70, 12, 70, 45, 70, 78, 70, 111, 70, -112, 70, -79, 70, -46, 70, -13,
-71, 20, 71, 53, 71, 86, 71, 119, 71, -104, 71, -71, 71, -38, 71, -5,
-72, 28, 72, 61, 72, 94, 72, 127, 72, -96, 72, -63, 72, -30, 73, 3,
-73, 36, 73, 69, 73, 102, 73, -121, 73, -88, 73, -55, 73, -22, 74, 11,
-74, 44, 74, 77, 74, 110, 74, -113, 74, -80, 74, -47, 74, -14, 75, 19,
-75, 52, 75, 85, 75, 118, 75, -105, 75, -72, 75, -39, 75, -6, 76, 27,
-76, 60, 76, 93, 76, 126, 76, -97, 76, -64, 76, -31, 77, 2, 77, 35,
-77, 68, 77, 101, 77, -122, 77, -89, 78, 0, 78, 33, 78, 66, 78, 99,
-78, -124, 78, -91, 78, -58, 78, -25, 79, 8, 79, 41, 79, 74, 79, 107,
-79, -116, 79, -83, 79, -50, 79, -17, 80, 16, 80, 49, 80, 82, 80, 115,
-80, -108, 80, -75, 80, -42, 80, -9, 81, 24, 81, 57, 81, 90, 81, 123,
-81, -100, 81, -67, 81, -34, 81, -1, 82, 32, 82, 65, 82, 98, 82, -125,
-82, -92, 82, -59, 82, -26, 83, 7, 83, 40, 83, 73, 83, 106, 83, -117,
-83, -84, 83, -51, 83, -18, 84, 15, 84, 48, 84, 81, 84, 114, 84, -109,
-84, -76, 84, -43, 84, -10, 85, 23, 85, 56, 85, 89, 85, 122, 85, -101,
-85, -68, 85, -35, 85, -2, 86, 31, 86, 64, 86, 97, 86, -126, 86, -93,
-86, -60, 86, -27, 87, 6, 87, 39, 87, 72, 87, 105, 87, -118, 87, -85,
-87, -52, 87, -19, 88, 14, 88, 47, 88, 80, 88, 113, 88, -110, 88, -77,
-88, -44, 88, -11, 89, 22, 89, 55, 89, 88, 89, 121, 89, -102, 89, -69,
-89, -36, 89, -3, 90, 30, 90, 63, 90, 96, 90, -127, 90, -94, 90, -61,
-90, -28, 91, 5, 91, 38, 91, 71, 91, 104, 91, -119, 91, -86, 91, -53,
-91, -20, 92, 13, 92, 46, 92, 79, 92, 112, 92, -111, 92, -78, 92, -45,
-92, -12, 93, 21, 93, 54, 93, 87, 93, 120, 93, -103, 93, -70, 93, -37,
-93, -4, 94, 29, 94, 62, 94, 95, 94, -128, 94, -95, 94, -62, 94, -29,
-95, 4, 95, 37, 95, 70, 95, 103, 95, -120, 95, -87, 95, -54, 95, -21,
-96, 12, 96, 45, 96, 78, 96, 111, 96, -112, 96, -79, 96, -46, 96, -13,
-97, 20, 97, 53, 97, 86, 97, 119, 97, -104, 97, -71, 97, -38, 97, -5,
-98, 28, 98, 61, 98, 94, 98, 127, 98, -96, 98, -63, 98, -30, 99, 3,
-99, 36, 99, 69, 99, 102, 99, -121, 99, -88, 99, -55, 99, -22, 100, 11,
-100, 44, 100, 77, 100, 110, 100, -113, 100, -80, 100, -47, 100, -14, 101, 19,
-101, 52, 101, 85, 101, 118, 101, -105, 101, -72, 101, -39, 101, -6, 102, 27,
-102, 60, 102, 93, 102, 126, 102, -97, 102, -64, 102, -31, 103, 2, 103, 35,
-103, 68, 103, 101, 103, -122, 103, -89, 103, -56, 103, -23, 104, 10, 104, 43,
-104, 76, 104, 109, 104, -114, 104, -81, 104, -48, 104, -15, 105, 18, 105, 51,
-105, 84, 105, 117, 105, -106, 105, -73, 105, -40, 105, -7, 106, 26, 106, 59,
-106, 92, 106, 125, 106, -98, 106, -65, 106, -32, 107, 1, 107, 34, 107, 67,
-107, 100, 107, -123, 107, -90, 107, -57, 107, -24, 108, 9, 108, 42, 108, 75,
-108, 108, 108, -115, 108, -82, 108, -49, 108, -16, 109, 17, 109, 50, 109, 83,
-109, 116, 109, -107, 109, -74, 109, -41, 109, -8, 110, 25, 110, 58, 110, 91,
-110, 124, 110, -99, 110, -66, 110, -33, 111, 0, 111, 33, 111, 66, 111, 99,
-111, -124, 111, -91, 111, -58, 111, -25, 112, 8, 112, 41, 112, 74, 112, 107,
-112, -116, 112, -83, 112, -50, 112, -17, 113, 16, 113, 49, 113, 82, 113, 115,
-113, -108, 113, -75, 113, -42, 113, -9, 114, 24, 114, 57, 114, 90, 114, 123,
-114, -100, 114, -67, 114, -34, 114, -1, 115, 32, 115, 65, 115, 98, 115, -125,
-115, -92, 115, -59, 115, -26, 116, 7, 116, 40, 116, 73, 116, 106, 116, -117,
-116, -84, 116, -51, 116, -18, 117, 15, 117, 48, 117, 81, 117, 114, 117, -109,
-117, -76, 117, -43, 117, -10, 118, 23, 118, 56, 118, 89, 118, 122, 118, -101,
-118, -68, 118, -35, 118, -2, 119, 31, 119, 64, 119, 97, 119, -126, 119, -93,
-119, -60, 119, -27, 120, 6, 120, 39, 120, 72, 120, 105, 120, -118, 120, -85,
-120, -52, 120, -19, 121, 14, 121, 47, 121, 80, 121, 113, 121, -110, 121, -77,
-121, -44, 121, -11, 122, 22, 122, 55, 122, 88, 122, 121, 122, -102, 122, -69,
-122, -36, 122, -3, 123, 30, 123, 63, 123, 96, 123, -127, 123, -94, 123, -61,
-123, -28, 124, 5, 124, 38, 124, 71, 124, 104, 124, -119, 124, -86, 124, -53,
-124, -20, 125, 13, 125, 46, 125, 79, 125, 112, 125, -111, 125, -78, 125, -45,
-125, -12, 126, 21, 126, 54, 126, 87, 126, 120, 126, -103, 126, -70, 126, -37,
-126, -4, 127, 29, 127, 62, 127, 95, 127, -128, 127, -95, 127, -62, 127, -29,
- */
-
-/*
-UTF-16BE
-0, 9, 0, 12, 0, 28, 0, 31, 0, 48, 0, 51, 0, 54, 0, 57,
-0, 65, 0, 68, 0, 71, 0, 74, 0, 77, 0, 80, 0, 83, 0, 86,
-0, 89, 0, 97, 0, 100, 0, 103, 0, 106, 0, 109, 0, 112, 0, 115,
-0, 118, 0, 121, 0, -86, 0, -75, 0, -70, 0, -64, 0, -61, 0, -58,
-0, -55, 0, -52, 0, -49, 0, -46, 0, -43, 0, -40, 0, -37, 0, -34,
-0, -31, 0, -28, 0, -25, 0, -22, 0, -19, 0, -16, 0, -13, 0, -10,
-0, -7, 0, -4, 0, -1, 1, 2, 1, 5, 1, 8, 1, 11, 1, 14,
-1, 17, 1, 20, 1, 23, 1, 26, 1, 29, 1, 32, 1, 35, 1, 38,
-1, 41, 1, 44, 1, 47, 1, 50, 1, 53, 1, 56, 1, 59, 1, 62,
-1, 65, 1, 68, 1, 71, 1, 74, 1, 77, 1, 80, 1, 83, 1, 86,
-1, 89, 1, 92, 1, 95, 1, 98, 1, 101, 1, 104, 1, 107, 1, 110,
-1, 113, 1, 116, 1, 119, 1, 122, 1, 125, 1, -128, 1, -125, 1, -122,
-1, -119, 1, -116, 1, -113, 1, -110, 1, -107, 1, -104, 1, -101, 1, -98,
-1, -95, 1, -92, 1, -89, 1, -86, 1, -83, 1, -80, 1, -77, 1, -74,
-1, -71, 1, -68, 1, -65, 1, -62, 1, -59, 1, -56, 1, -53, 1, -50,
-1, -47, 1, -44, 1, -41, 1, -38, 1, -35, 1, -32, 1, -29, 1, -26,
-1, -23, 1, -20, 1, -17, 1, -14, 1, -11, 1, -8, 1, -5, 1, -2,
-2, 1, 2, 4, 2, 7, 2, 10, 2, 13, 2, 16, 2, 19, 2, 22,
-2, 25, 2, 28, 2, 31, 2, 34, 2, 37, 2, 40, 2, 43, 2, 46,
-2, 49, 2, 52, 2, 80, 2, 83, 2, 86, 2, 89, 2, 92, 2, 95,
-2, 98, 2, 101, 2, 104, 2, 107, 2, 110, 2, 113, 2, 116, 2, 119,
-2, 122, 2, 125, 2, -128, 2, -125, 2, -122, 2, -119, 2, -116, 2, -113,
-2, -110, 2, -107, 2, -104, 2, -101, 2, -98, 2, -95, 2, -92, 2, -89,
-2, -86, 2, -83, 2, -80, 2, -77, 2, -74, 2, -71, 2, -68, 2, -65,
-2, -58, 2, -55, 2, -52, 2, -49, 2, -32, 2, -29, 2, -18, 3, 122,
-3, -122, 3, -119, 3, -116, 3, -113, 3, -110, 3, -107, 3, -104, 3, -101,
-3, -98, 3, -95, 3, -92, 3, -89, 3, -86, 3, -83, 3, -80, 3, -77,
-3, -74, 3, -71, 3, -68, 3, -65, 3, -62, 3, -59, 3, -56, 3, -53,
-3, -50, 3, -47, 3, -44, 3, -41, 3, -38, 3, -35, 3, -32, 3, -29,
-3, -26, 3, -23, 3, -20, 3, -17, 3, -14, 3, -11, 3, -8, 3, -5,
-4, 0, 4, 3, 4, 36, 4, 69, 4, 102, 4, -118, 4, -85, 4, -52,
-4, -19, 5, 14, 5, 49, 5, 82, 5, 115, 5, -48, 5, -15, 6, 33,
-6, 66, 6, 99, 6, -124, 6, -91, 6, -58, 6, -18, 7, 16, 7, 77,
-7, -128, 7, -95, 9, 4, 9, 37, 9, 80, 9, -123, 9, -90, 9, -36,
-10, 5, 10, 38, 10, 89, 10, -123, 10, -90, 10, -48, 11, 5, 11, 38,
-11, 92, 11, -125, 11, -92, 11, -25, 12, 8, 12, 42, 12, 96, 12, -123,
-12, -90, 12, -34, 13, 5, 13, 38, 13, 96, 13, -123, 13, -90, 14, 1,
-14, 34, 14, 67, 14, -127, 14, -94, 14, -61, 15, 0, 15, 33, 15, 66,
-15, 99, 15, -120, 16, 0, 16, 33, 16, 66, 16, -96, 16, -63, 16, -30,
-17, 3, 17, 36, 17, 69, 17, 102, 17, -121, 17, -88, 17, -55, 17, -22,
-18, 11, 18, 44, 18, 77, 18, 110, 18, -112, 18, -78, 18, -45, 18, -12,
-19, 21, 19, 54, 19, 87, 19, -96, 19, -63, 19, -30, 20, 3, 20, 36,
-20, 69, 20, 102, 20, -121, 20, -88, 20, -55, 20, -22, 21, 11, 21, 44,
-21, 77, 21, 110, 21, -113, 21, -80, 21, -47, 21, -14, 22, 19, 22, 52,
-22, 85, 22, 118, 22, -105, 22, -72, 22, -39, 23, 0, 23, 33, 23, 66,
-23, 99, 23, -124, 23, -91, 23, -41, 24, 14, 24, 47, 24, 80, 24, 113,
-24, -110, 25, 0, 25, 70, 25, 103, 29, 0, 29, 33, 29, 66, 29, 99,
-30, 0, 30, 33, 30, 66, 30, 99, 30, -124, 30, -91, 30, -58, 30, -25,
-31, 8, 31, 41, 31, 74, 31, 107, 31, -116, 31, -83, 31, -48, 31, -14,
-32, 40, 32, 95, 33, 2, 33, 36, 33, 69, 48, 0, 48, 49, 48, 82,
-48, 115, 48, -108, 48, -75, 48, -42, 48, -9, 49, 24, 49, 57, 49, 90,
-49, 123, 49, -96, 49, -16, 52, 0, 52, 33, 52, 66, 52, 99, 52, -124,
-52, -91, 52, -58, 52, -25, 53, 8, 53, 41, 53, 74, 53, 107, 53, -116,
-53, -83, 53, -50, 53, -17, 54, 16, 54, 49, 54, 82, 54, 115, 54, -108,
-54, -75, 54, -42, 54, -9, 55, 24, 55, 57, 55, 90, 55, 123, 55, -100,
-55, -67, 55, -34, 55, -1, 56, 32, 56, 65, 56, 98, 56, -125, 56, -92,
-56, -59, 56, -26, 57, 7, 57, 40, 57, 73, 57, 106, 57, -117, 57, -84,
-57, -51, 57, -18, 58, 15, 58, 48, 58, 81, 58, 114, 58, -109, 58, -76,
-58, -43, 58, -10, 59, 23, 59, 56, 59, 89, 59, 122, 59, -101, 59, -68,
-59, -35, 59, -2, 60, 31, 60, 64, 60, 97, 60, -126, 60, -93, 60, -60,
-60, -27, 61, 6, 61, 39, 61, 72, 61, 105, 61, -118, 61, -85, 61, -52,
-61, -19, 62, 14, 62, 47, 62, 80, 62, 113, 62, -110, 62, -77, 62, -44,
-62, -11, 63, 22, 63, 55, 63, 88, 63, 121, 63, -102, 63, -69, 63, -36,
-63, -3, 64, 30, 64, 63, 64, 96, 64, -127, 64, -94, 64, -61, 64, -28,
-65, 5, 65, 38, 65, 71, 65, 104, 65, -119, 65, -86, 65, -53, 65, -20,
-66, 13, 66, 46, 66, 79, 66, 112, 66, -111, 66, -78, 66, -45, 66, -12,
-67, 21, 67, 54, 67, 87, 67, 120, 67, -103, 67, -70, 67, -37, 67, -4,
-68, 29, 68, 62, 68, 95, 68, -128, 68, -95, 68, -62, 68, -29, 69, 4,
-69, 37, 69, 70, 69, 103, 69, -120, 69, -87, 69, -54, 69, -21, 70, 12,
-70, 45, 70, 78, 70, 111, 70, -112, 70, -79, 70, -46, 70, -13, 71, 20,
-71, 53, 71, 86, 71, 119, 71, -104, 71, -71, 71, -38, 71, -5, 72, 28,
-72, 61, 72, 94, 72, 127, 72, -96, 72, -63, 72, -30, 73, 3, 73, 36,
-73, 69, 73, 102, 73, -121, 73, -88, 73, -55, 73, -22, 74, 11, 74, 44,
-74, 77, 74, 110, 74, -113, 74, -80, 74, -47, 74, -14, 75, 19, 75, 52,
-75, 85, 75, 118, 75, -105, 75, -72, 75, -39, 75, -6, 76, 27, 76, 60,
-76, 93, 76, 126, 76, -97, 76, -64, 76, -31, 77, 2, 77, 35, 77, 68,
-77, 101, 77, -122, 77, -89, 78, 0, 78, 33, 78, 66, 78, 99, 78, -124,
-78, -91, 78, -58, 78, -25, 79, 8, 79, 41, 79, 74, 79, 107, 79, -116,
-79, -83, 79, -50, 79, -17, 80, 16, 80, 49, 80, 82, 80, 115, 80, -108,
-80, -75, 80, -42, 80, -9, 81, 24, 81, 57, 81, 90, 81, 123, 81, -100,
-81, -67, 81, -34, 81, -1, 82, 32, 82, 65, 82, 98, 82, -125, 82, -92,
-82, -59, 82, -26, 83, 7, 83, 40, 83, 73, 83, 106, 83, -117, 83, -84,
-83, -51, 83, -18, 84, 15, 84, 48, 84, 81, 84, 114, 84, -109, 84, -76,
-84, -43, 84, -10, 85, 23, 85, 56, 85, 89, 85, 122, 85, -101, 85, -68,
-85, -35, 85, -2, 86, 31, 86, 64, 86, 97, 86, -126, 86, -93, 86, -60,
-86, -27, 87, 6, 87, 39, 87, 72, 87, 105, 87, -118, 87, -85, 87, -52,
-87, -19, 88, 14, 88, 47, 88, 80, 88, 113, 88, -110, 88, -77, 88, -44,
-88, -11, 89, 22, 89, 55, 89, 88, 89, 121, 89, -102, 89, -69, 89, -36,
-89, -3, 90, 30, 90, 63, 90, 96, 90, -127, 90, -94, 90, -61, 90, -28,
-91, 5, 91, 38, 91, 71, 91, 104, 91, -119, 91, -86, 91, -53, 91, -20,
-92, 13, 92, 46, 92, 79, 92, 112, 92, -111, 92, -78, 92, -45, 92, -12,
-93, 21, 93, 54, 93, 87, 93, 120, 93, -103, 93, -70, 93, -37, 93, -4,
-94, 29, 94, 62, 94, 95, 94, -128, 94, -95, 94, -62, 94, -29, 95, 4,
-95, 37, 95, 70, 95, 103, 95, -120, 95, -87, 95, -54, 95, -21, 96, 12,
-96, 45, 96, 78, 96, 111, 96, -112, 96, -79, 96, -46, 96, -13, 97, 20,
-97, 53, 97, 86, 97, 119, 97, -104, 97, -71, 97, -38, 97, -5, 98, 28,
-98, 61, 98, 94, 98, 127, 98, -96, 98, -63, 98, -30, 99, 3, 99, 36,
-99, 69, 99, 102, 99, -121, 99, -88, 99, -55, 99, -22, 100, 11, 100, 44,
-100, 77, 100, 110, 100, -113, 100, -80, 100, -47, 100, -14, 101, 19, 101, 52,
-101, 85, 101, 118, 101, -105, 101, -72, 101, -39, 101, -6, 102, 27, 102, 60,
-102, 93, 102, 126, 102, -97, 102, -64, 102, -31, 103, 2, 103, 35, 103, 68,
-103, 101, 103, -122, 103, -89, 103, -56, 103, -23, 104, 10, 104, 43, 104, 76,
-104, 109, 104, -114, 104, -81, 104, -48, 104, -15, 105, 18, 105, 51, 105, 84,
-105, 117, 105, -106, 105, -73, 105, -40, 105, -7, 106, 26, 106, 59, 106, 92,
-106, 125, 106, -98, 106, -65, 106, -32, 107, 1, 107, 34, 107, 67, 107, 100,
-107, -123, 107, -90, 107, -57, 107, -24, 108, 9, 108, 42, 108, 75, 108, 108,
-108, -115, 108, -82, 108, -49, 108, -16, 109, 17, 109, 50, 109, 83, 109, 116,
-109, -107, 109, -74, 109, -41, 109, -8, 110, 25, 110, 58, 110, 91, 110, 124,
-110, -99, 110, -66, 110, -33, 111, 0, 111, 33, 111, 66, 111, 99, 111, -124,
-111, -91, 111, -58, 111, -25, 112, 8, 112, 41, 112, 74, 112, 107, 112, -116,
-112, -83, 112, -50, 112, -17, 113, 16, 113, 49, 113, 82, 113, 115, 113, -108,
-113, -75, 113, -42, 113, -9, 114, 24, 114, 57, 114, 90, 114, 123, 114, -100,
-114, -67, 114, -34, 114, -1, 115, 32, 115, 65, 115, 98, 115, -125, 115, -92,
-115, -59, 115, -26, 116, 7, 116, 40, 116, 73, 116, 106, 116, -117, 116, -84,
-116, -51, 116, -18, 117, 15, 117, 48, 117, 81, 117, 114, 117, -109, 117, -76,
-117, -43, 117, -10, 118, 23, 118, 56, 118, 89, 118, 122, 118, -101, 118, -68,
-118, -35, 118, -2, 119, 31, 119, 64, 119, 97, 119, -126, 119, -93, 119, -60,
-119, -27, 120, 6, 120, 39, 120, 72, 120, 105, 120, -118, 120, -85, 120, -52,
-120, -19, 121, 14, 121, 47, 121, 80, 121, 113, 121, -110, 121, -77, 121, -44,
-121, -11, 122, 22, 122, 55, 122, 88, 122, 121, 122, -102, 122, -69, 122, -36,
-122, -3, 123, 30, 123, 63, 123, 96, 123, -127, 123, -94, 123, -61, 123, -28,
-124, 5, 124, 38, 124, 71, 124, 104, 124, -119, 124, -86, 124, -53, 124, -20,
-125, 13, 125, 46, 125, 79, 125, 112, 125, -111, 125, -78, 125, -45, 125, -12,
-126, 21, 126, 54, 126, 87, 126, 120, 126, -103, 126, -70, 126, -37, 126, -4,
-127, 29, 127, 62, 127, 95, 127, -128, 127, -95, 127, -62, 127, -29, */
-
-/*
-UTF-16LE
-9, 0, 12, 0, 28, 0, 31, 0, 48, 0, 51, 0, 54, 0, 57, 0,
-65, 0, 68, 0, 71, 0, 74, 0, 77, 0, 80, 0, 83, 0, 86, 0,
-89, 0, 97, 0, 100, 0, 103, 0, 106, 0, 109, 0, 112, 0, 115, 0,
-118, 0, 121, 0, -86, 0, -75, 0, -70, 0, -64, 0, -61, 0, -58, 0,
--55, 0, -52, 0, -49, 0, -46, 0, -43, 0, -40, 0, -37, 0, -34, 0,
--31, 0, -28, 0, -25, 0, -22, 0, -19, 0, -16, 0, -13, 0, -10, 0,
--7, 0, -4, 0, -1, 0, 2, 1, 5, 1, 8, 1, 11, 1, 14, 1,
-17, 1, 20, 1, 23, 1, 26, 1, 29, 1, 32, 1, 35, 1, 38, 1,
-41, 1, 44, 1, 47, 1, 50, 1, 53, 1, 56, 1, 59, 1, 62, 1,
-65, 1, 68, 1, 71, 1, 74, 1, 77, 1, 80, 1, 83, 1, 86, 1,
-89, 1, 92, 1, 95, 1, 98, 1, 101, 1, 104, 1, 107, 1, 110, 1,
-113, 1, 116, 1, 119, 1, 122, 1, 125, 1, -128, 1, -125, 1, -122, 1,
--119, 1, -116, 1, -113, 1, -110, 1, -107, 1, -104, 1, -101, 1, -98, 1,
--95, 1, -92, 1, -89, 1, -86, 1, -83, 1, -80, 1, -77, 1, -74, 1,
--71, 1, -68, 1, -65, 1, -62, 1, -59, 1, -56, 1, -53, 1, -50, 1,
--47, 1, -44, 1, -41, 1, -38, 1, -35, 1, -32, 1, -29, 1, -26, 1,
--23, 1, -20, 1, -17, 1, -14, 1, -11, 1, -8, 1, -5, 1, -2, 1,
-1, 2, 4, 2, 7, 2, 10, 2, 13, 2, 16, 2, 19, 2, 22, 2,
-25, 2, 28, 2, 31, 2, 34, 2, 37, 2, 40, 2, 43, 2, 46, 2,
-49, 2, 52, 2, 80, 2, 83, 2, 86, 2, 89, 2, 92, 2, 95, 2,
-98, 2, 101, 2, 104, 2, 107, 2, 110, 2, 113, 2, 116, 2, 119, 2,
-122, 2, 125, 2, -128, 2, -125, 2, -122, 2, -119, 2, -116, 2, -113, 2,
--110, 2, -107, 2, -104, 2, -101, 2, -98, 2, -95, 2, -92, 2, -89, 2,
--86, 2, -83, 2, -80, 2, -77, 2, -74, 2, -71, 2, -68, 2, -65, 2,
--58, 2, -55, 2, -52, 2, -49, 2, -32, 2, -29, 2, -18, 2, 122, 3,
--122, 3, -119, 3, -116, 3, -113, 3, -110, 3, -107, 3, -104, 3, -101, 3,
--98, 3, -95, 3, -92, 3, -89, 3, -86, 3, -83, 3, -80, 3, -77, 3,
--74, 3, -71, 3, -68, 3, -65, 3, -62, 3, -59, 3, -56, 3, -53, 3,
--50, 3, -47, 3, -44, 3, -41, 3, -38, 3, -35, 3, -32, 3, -29, 3,
--26, 3, -23, 3, -20, 3, -17, 3, -14, 3, -11, 3, -8, 3, -5, 3,
-0, 4, 3, 4, 36, 4, 69, 4, 102, 4, -118, 4, -85, 4, -52, 4,
--19, 4, 14, 5, 49, 5, 82, 5, 115, 5, -48, 5, -15, 5, 33, 6,
-66, 6, 99, 6, -124, 6, -91, 6, -58, 6, -18, 6, 16, 7, 77, 7,
--128, 7, -95, 7, 4, 9, 37, 9, 80, 9, -123, 9, -90, 9, -36, 9,
-5, 10, 38, 10, 89, 10, -123, 10, -90, 10, -48, 10, 5, 11, 38, 11,
-92, 11, -125, 11, -92, 11, -25, 11, 8, 12, 42, 12, 96, 12, -123, 12,
--90, 12, -34, 12, 5, 13, 38, 13, 96, 13, -123, 13, -90, 13, 1, 14,
-34, 14, 67, 14, -127, 14, -94, 14, -61, 14, 0, 15, 33, 15, 66, 15,
-99, 15, -120, 15, 0, 16, 33, 16, 66, 16, -96, 16, -63, 16, -30, 16,
-3, 17, 36, 17, 69, 17, 102, 17, -121, 17, -88, 17, -55, 17, -22, 17,
-11, 18, 44, 18, 77, 18, 110, 18, -112, 18, -78, 18, -45, 18, -12, 18,
-21, 19, 54, 19, 87, 19, -96, 19, -63, 19, -30, 19, 3, 20, 36, 20,
-69, 20, 102, 20, -121, 20, -88, 20, -55, 20, -22, 20, 11, 21, 44, 21,
-77, 21, 110, 21, -113, 21, -80, 21, -47, 21, -14, 21, 19, 22, 52, 22,
-85, 22, 118, 22, -105, 22, -72, 22, -39, 22, 0, 23, 33, 23, 66, 23,
-99, 23, -124, 23, -91, 23, -41, 23, 14, 24, 47, 24, 80, 24, 113, 24,
--110, 24, 0, 25, 70, 25, 103, 25, 0, 29, 33, 29, 66, 29, 99, 29,
-0, 30, 33, 30, 66, 30, 99, 30, -124, 30, -91, 30, -58, 30, -25, 30,
-8, 31, 41, 31, 74, 31, 107, 31, -116, 31, -83, 31, -48, 31, -14, 31,
-40, 32, 95, 32, 2, 33, 36, 33, 69, 33, 0, 48, 49, 48, 82, 48,
-115, 48, -108, 48, -75, 48, -42, 48, -9, 48, 24, 49, 57, 49, 90, 49,
-123, 49, -96, 49, -16, 49, 0, 52, 33, 52, 66, 52, 99, 52, -124, 52,
--91, 52, -58, 52, -25, 52, 8, 53, 41, 53, 74, 53, 107, 53, -116, 53,
--83, 53, -50, 53, -17, 53, 16, 54, 49, 54, 82, 54, 115, 54, -108, 54,
--75, 54, -42, 54, -9, 54, 24, 55, 57, 55, 90, 55, 123, 55, -100, 55,
--67, 55, -34, 55, -1, 55, 32, 56, 65, 56, 98, 56, -125, 56, -92, 56,
--59, 56, -26, 56, 7, 57, 40, 57, 73, 57, 106, 57, -117, 57, -84, 57,
--51, 57, -18, 57, 15, 58, 48, 58, 81, 58, 114, 58, -109, 58, -76, 58,
--43, 58, -10, 58, 23, 59, 56, 59, 89, 59, 122, 59, -101, 59, -68, 59,
--35, 59, -2, 59, 31, 60, 64, 60, 97, 60, -126, 60, -93, 60, -60, 60,
--27, 60, 6, 61, 39, 61, 72, 61, 105, 61, -118, 61, -85, 61, -52, 61,
--19, 61, 14, 62, 47, 62, 80, 62, 113, 62, -110, 62, -77, 62, -44, 62,
--11, 62, 22, 63, 55, 63, 88, 63, 121, 63, -102, 63, -69, 63, -36, 63,
--3, 63, 30, 64, 63, 64, 96, 64, -127, 64, -94, 64, -61, 64, -28, 64,
-5, 65, 38, 65, 71, 65, 104, 65, -119, 65, -86, 65, -53, 65, -20, 65,
-13, 66, 46, 66, 79, 66, 112, 66, -111, 66, -78, 66, -45, 66, -12, 66,
-21, 67, 54, 67, 87, 67, 120, 67, -103, 67, -70, 67, -37, 67, -4, 67,
-29, 68, 62, 68, 95, 68, -128, 68, -95, 68, -62, 68, -29, 68, 4, 69,
-37, 69, 70, 69, 103, 69, -120, 69, -87, 69, -54, 69, -21, 69, 12, 70,
-45, 70, 78, 70, 111, 70, -112, 70, -79, 70, -46, 70, -13, 70, 20, 71,
-53, 71, 86, 71, 119, 71, -104, 71, -71, 71, -38, 71, -5, 71, 28, 72,
-61, 72, 94, 72, 127, 72, -96, 72, -63, 72, -30, 72, 3, 73, 36, 73,
-69, 73, 102, 73, -121, 73, -88, 73, -55, 73, -22, 73, 11, 74, 44, 74,
-77, 74, 110, 74, -113, 74, -80, 74, -47, 74, -14, 74, 19, 75, 52, 75,
-85, 75, 118, 75, -105, 75, -72, 75, -39, 75, -6, 75, 27, 76, 60, 76,
-93, 76, 126, 76, -97, 76, -64, 76, -31, 76, 2, 77, 35, 77, 68, 77,
-101, 77, -122, 77, -89, 77, 0, 78, 33, 78, 66, 78, 99, 78, -124, 78,
--91, 78, -58, 78, -25, 78, 8, 79, 41, 79, 74, 79, 107, 79, -116, 79,
--83, 79, -50, 79, -17, 79, 16, 80, 49, 80, 82, 80, 115, 80, -108, 80,
--75, 80, -42, 80, -9, 80, 24, 81, 57, 81, 90, 81, 123, 81, -100, 81,
--67, 81, -34, 81, -1, 81, 32, 82, 65, 82, 98, 82, -125, 82, -92, 82,
--59, 82, -26, 82, 7, 83, 40, 83, 73, 83, 106, 83, -117, 83, -84, 83,
--51, 83, -18, 83, 15, 84, 48, 84, 81, 84, 114, 84, -109, 84, -76, 84,
--43, 84, -10, 84, 23, 85, 56, 85, 89, 85, 122, 85, -101, 85, -68, 85,
--35, 85, -2, 85, 31, 86, 64, 86, 97, 86, -126, 86, -93, 86, -60, 86,
--27, 86, 6, 87, 39, 87, 72, 87, 105, 87, -118, 87, -85, 87, -52, 87,
--19, 87, 14, 88, 47, 88, 80, 88, 113, 88, -110, 88, -77, 88, -44, 88,
--11, 88, 22, 89, 55, 89, 88, 89, 121, 89, -102, 89, -69, 89, -36, 89,
--3, 89, 30, 90, 63, 90, 96, 90, -127, 90, -94, 90, -61, 90, -28, 90,
-5, 91, 38, 91, 71, 91, 104, 91, -119, 91, -86, 91, -53, 91, -20, 91,
-13, 92, 46, 92, 79, 92, 112, 92, -111, 92, -78, 92, -45, 92, -12, 92,
-21, 93, 54, 93, 87, 93, 120, 93, -103, 93, -70, 93, -37, 93, -4, 93,
-29, 94, 62, 94, 95, 94, -128, 94, -95, 94, -62, 94, -29, 94, 4, 95,
-37, 95, 70, 95, 103, 95, -120, 95, -87, 95, -54, 95, -21, 95, 12, 96,
-45, 96, 78, 96, 111, 96, -112, 96, -79, 96, -46, 96, -13, 96, 20, 97,
-53, 97, 86, 97, 119, 97, -104, 97, -71, 97, -38, 97, -5, 97, 28, 98,
-61, 98, 94, 98, 127, 98, -96, 98, -63, 98, -30, 98, 3, 99, 36, 99,
-69, 99, 102, 99, -121, 99, -88, 99, -55, 99, -22, 99, 11, 100, 44, 100,
-77, 100, 110, 100, -113, 100, -80, 100, -47, 100, -14, 100, 19, 101, 52, 101,
-85, 101, 118, 101, -105, 101, -72, 101, -39, 101, -6, 101, 27, 102, 60, 102,
-93, 102, 126, 102, -97, 102, -64, 102, -31, 102, 2, 103, 35, 103, 68, 103,
-101, 103, -122, 103, -89, 103, -56, 103, -23, 103, 10, 104, 43, 104, 76, 104,
-109, 104, -114, 104, -81, 104, -48, 104, -15, 104, 18, 105, 51, 105, 84, 105,
-117, 105, -106, 105, -73, 105, -40, 105, -7, 105, 26, 106, 59, 106, 92, 106,
-125, 106, -98, 106, -65, 106, -32, 106, 1, 107, 34, 107, 67, 107, 100, 107,
--123, 107, -90, 107, -57, 107, -24, 107, 9, 108, 42, 108, 75, 108, 108, 108,
--115, 108, -82, 108, -49, 108, -16, 108, 17, 109, 50, 109, 83, 109, 116, 109,
--107, 109, -74, 109, -41, 109, -8, 109, 25, 110, 58, 110, 91, 110, 124, 110,
--99, 110, -66, 110, -33, 110, 0, 111, 33, 111, 66, 111, 99, 111, -124, 111,
--91, 111, -58, 111, -25, 111, 8, 112, 41, 112, 74, 112, 107, 112, -116, 112,
--83, 112, -50, 112, -17, 112, 16, 113, 49, 113, 82, 113, 115, 113, -108, 113,
--75, 113, -42, 113, -9, 113, 24, 114, 57, 114, 90, 114, 123, 114, -100, 114,
--67, 114, -34, 114, -1, 114, 32, 115, 65, 115, 98, 115, -125, 115, -92, 115,
--59, 115, -26, 115, 7, 116, 40, 116, 73, 116, 106, 116, -117, 116, -84, 116,
--51, 116, -18, 116, 15, 117, 48, 117, 81, 117, 114, 117, -109, 117, -76, 117,
--43, 117, -10, 117, 23, 118, 56, 118, 89, 118, 122, 118, -101, 118, -68, 118,
--35, 118, -2, 118, 31, 119, 64, 119, 97, 119, -126, 119, -93, 119, -60, 119,
--27, 119, 6, 120, 39, 120, 72, 120, 105, 120, -118, 120, -85, 120, -52, 120,
--19, 120, 14, 121, 47, 121, 80, 121, 113, 121, -110, 121, -77, 121, -44, 121,
--11, 121, 22, 122, 55, 122, 88, 122, 121, 122, -102, 122, -69, 122, -36, 122,
--3, 122, 30, 123, 63, 123, 96, 123, -127, 123, -94, 123, -61, 123, -28, 123,
-5, 124, 38, 124, 71, 124, 104, 124, -119, 124, -86, 124, -53, 124, -20, 124,
-13, 125, 46, 125, 79, 125, 112, 125, -111, 125, -78, 125, -45, 125, -12, 125,
-21, 126, 54, 126, 87, 126, 120, 126, -103, 126, -70, 126, -37, 126, -4, 126,
-29, 127, 62, 127, 95, 127, -128, 127, -95, 127, -62, 127, -29, 127, */
-
-/* 1-BYTE:
-US-ASCII
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-1
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, -61, -58,
--55, -52, -49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -13, -10,
--7, -4, -1, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-2
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
--55, 63, 63, 63, 63, 63, 63, 63, -31, -28, -25, 63, -19, 63, -13, -10,
-63, -4, 63, -61, -79, 63, 63, -49, -16, 63, 63, -52, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -75, -93, -15, -46, 63, 63, -43, 63, 63,
--8, 63, -70, -34, -69, 63, 63, -39, -5, 63, 63, -68, -82, 63, 63, 63,
-
-ISO-8859-3
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, -64, 63, 63,
--55, -52, -49, -46, 63, 63, -37, 63, -31, -28, -25, -22, -19, 63, -13, -10,
--7, -4, 63, 63, 63, -58, -27, 63, 63, 63, 63, 63, -8, -43, 63, -95,
-63, 63, 63, 63, -68, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -34, -70, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-4
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, -61, -58,
--55, 63, 63, 63, -43, -40, -37, 63, -31, -28, 63, 63, -19, 63, 63, -10,
-63, -4, 63, 63, -79, 63, 63, 63, -16, 63, -20, 63, 63, 63, -69, 63,
--75, 63, -25, 63, 63, -94, -90, 63, 63, 63, 63, -67, -14, 63, 63, -93,
-63, 63, 63, 63, 63, -35, -2, 63, 63, 63, 63, 63, -82, 63, 63, 63,
-
-ISO-8859-5
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -93, -60, -27, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-6
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -63,
--30, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-7
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -74, -71, -68, -65, -62, -59, -56, -53,
--50, -47, -44, -41, -38, -35, -32, -29, -26, -23, -20, -17, -14, -11, -8, -5,
--2, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-8
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -32, 63, 63,
-
-ISO-8859-9
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, -61, -58,
--55, -52, -49, -46, -43, -40, -37, 63, -31, -28, -25, -22, -19, 63, -13, -10,
--7, -4, -1, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-x-iso-8859-11
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -95, -62, -29, 63, 63, 63, 63, 63, 63,
-
-ISO-8859-13
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, -81,
--55, 63, 63, 63, -43, -88, 63, 63, 63, -28, 63, 63, 63, 63, -13, -10,
-63, -4, 63, 63, -32, 63, 63, 63, 63, 63, -21, 63, 63, 63, -20, 63,
-63, 63, -31, 63, 63, 63, -49, 63, -39, -15, 63, 63, -12, 63, 63, -86,
-63, 63, 63, 63, 63, 63, -5, 63, 63, 63, 63, -22, -34, 63, 63, 63,
-
-ISO-8859-15
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, -61, -58,
--55, -52, -49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -13, -10,
--7, -4, -1, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -67, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -76, 63, 63, 63,
-
- */
-
-/*
-ISO-2022-JP // MaxBytes = 8 !!!
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 27, 36, 66, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 38, 34, 38, 37, 38, 40, 38, 43, 38, 46, 38, 49, 38, 51, 38,
-54, 33, 41, 33, 41, 33, 41, 38, 67, 38, 70, 38, 73, 38, 76, 38,
-79, 33, 41, 38, 84, 38, 87, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 39, 54, 39,
-103, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 33, 33, 41, 36, 50, 36, 83, 33, 41, 37, 53, 37,
-86, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 48,
-108, 78, 62, 80, 41, 33, 41, 33, 41, 48, 103, 80, 61, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 75, 121, 80, 89, 80, 109, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 58, 68, 81, 37, 33, 41, 80,
-86, 33, 41, 69, 94, 33, 41, 33, 41, 81, 88, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 51, 68, 33, 41, 68, 60, 82, 43, 33, 41, 33,
-41, 82, 67, 33, 41, 33, 41, 33, 41, 72, 63, 82, 90, 77, 121, 33,
-41, 70, 93, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 83,
-57, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 83, 85, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 48, 53, 33,
-41, 84, 48, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 116, 33, 33,
-41, 33, 41, 33, 41, 74, 47, 33, 41, 33, 41, 51, 48, 48, 80, 84,
-121, 33, 41, 33, 41, 58, 74, 85, 42, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 48, 66, 33, 41, 33, 41, 33, 41, 85, 116, 33, 41, 86, 34, 33,
-41, 86, 42, 33, 41, 33, 41, 33, 41, 86, 61, 33, 41, 33, 41, 33,
-41, 33, 41, 78, 102, 86, 95, 33, 41, 68, 107, 33, 41, 86, 112, 33,
-41, 33, 41, 86, 123, 87, 34, 79, 46, 76, 111, 33, 41, 33, 41, 87,
-76, 73, 124, 33, 41, 50, 119, 33, 41, 33, 41, 33, 41, 66, 41, 33,
-41, 33, 41, 33, 41, 65, 91, 33, 41, 33, 41, 33, 41, 88, 77, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 89, 42, 62, 53, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 63,
-100, 89, 102, 33, 41, 33, 41, 72, 66, 33, 41, 33, 41, 33, 41, 64,
-113, 33, 41, 90, 51, 33, 41, 90, 61, 90, 69, 33, 41, 69, 77, 33,
-41, 90, 90, 50, 34, 33, 41, 67, 107, 90, 108, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 77, 104, 33, 41, 33, 41, 33,
-41, 91, 77, 33, 41, 91, 97, 33, 41, 33, 41, 33, 41, 68, 116, 33,
-41, 33, 41, 92, 37, 33, 41, 92, 56, 54, 75, 33, 41, 33, 41, 77,
-77, 92, 95, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 93, 61, 58, 33, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 93, 108, 93, 124, 33, 41, 66,
-89, 33, 41, 61, 39, 33, 41, 77, 97, 94, 56, 33, 41, 33, 41, 33,
-41, 94, 82, 94, 93, 67, 57, 33, 41, 57, 66, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 64, 33, 33, 41, 95, 57, 33, 41, 33,
-41, 33, 41, 33, 41, 50, 80, 33, 41, 67, 58, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 77, 80, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 96, 117, 96, 120, 33, 41, 33, 41, 97, 37, 33, 41, 69,
-68, 72, 42, 33, 41, 33, 41, 33, 41, 58, 47, 33, 41, 33, 41, 33,
-41, 33, 41, 72, 47, 33, 41, 33, 41, 33, 41, 61, 98, 63, 63, 67,
-101, 63, 103, 33, 41, 33, 41, 33, 41, 67, 78, 33, 41, 53, 78, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 65, 67, 33, 41, 77,
-52, 33, 41, 33, 41, 99, 58, 33, 41, 33, 41, 33, 41, 99, 77, 33,
-41, 99, 86, 33, 41, 33, 41, 78, 53, 33, 41, 99, 122, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 70, 70, 33, 41, 33, 41, 33, 41, 33,
-41, 74, 52, 33, 41, 33, 41, 33, 41, 71, 60, 101, 39, 101, 50, 33,
-41, 33, 41, 76, 86, 33, 41, 78, 125, 33, 41, 33, 41, 33, 41, 33,
-41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 33, 41, 102, 42, 33,
-41, 33, 41, 33, 41, 33, 41, */
-
-/*
-x-windows-950
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -93, -68, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -93, 69, -93,
-72, -93, 75, -93, 78, -93, 81, -93, 84, -93, 86, -93, 89, 63, 63, 63,
--93, 94, -93, 97, -93, 100, -93, 103, -93, 106, 63, -93, 111, -93, 114, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, 64, 63,
-63, 63, 63, 63, 63, 63, -93, -87, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, -92, 64, 63, -55, 64, 63, -36, -78, -91, -24, -92,
--78, 63, -55, -77, 63, 63, -53, -53, 63, 63, -85, 91, -83, -63, 63, -48,
--36, 63, -44, 101, -40, 83, -74, -59, -71, -81, 63, -66, -88, -11, -63, -48,
--34, 63, 63, -88, -26, -24, -7, 63, 63, -88, -17, -48, -20, -71, -70, 63,
-63, -74, -45, 63, 63, -91, 99, 63, 63, -31, 70, -92, -49, -91, 109, -90,
-79, -54, 118, 63, -50, 77, 63, 63, 63, 63, -48, -14, -80, -31, 63, 63,
-63, 63, -36, -48, -71, -66, -71, -54, -27, 65, 63, -20, -57, 63, 63, -54,
--87, 63, 63, 63, -87, 88, 63, 63, -47, 74, -44, -76, -44, -62, -77, -13,
-63, -36, -15, 63, -68, 88, -20, -53, 63, -91, 126, -90, 105, -82, 78, -90,
-111, 63, -87, 100, -85, -72, -50, 105, -47, 99, 63, -44, -50, 63, -40, -71,
-63, 63, -27, 95, -20, -44, -11, -56, 63, -90, 119, 63, -40, -46, -68, 101,
--71, -17, 63, -85, -52, 63, -89, -62, 63, -50, -89, -82, 115, 63, -40, -17,
-63, 63, -27, 98, -64, -83, 63, 63, -85, -46, -43, 69, -68, 109, -55, 121,
-63, -76, 91, -68, 115, -89, -53, 63, -71, -5, -47, 123, -85, -36, -76, 95,
-63, -89, -42, -52, -82, -52, 122, 63, -82, -89, -43, 82, -43, 94, 63, -73,
-81, -40, -2, 63, -31, -43, -70, 66, 63, 63, 63, -14, 65, 63, -52, -78,
--55, -28, -87, -45, 63, 63, 63, -50, -39, 63, -47, -74, 63, -43, 115, -79,
--64, -76, 124, -76, -86, -35, -74, -73, 104, -31, -38, -27, -83, -27, -76, -68,
--74, 63, -62, 89, -12, 78, 63, -79, -43, -27, -67, -92, -26, -8, -16, 63,
--87, -12, 63, 63, -79, -34, -76, -67, -31, -8, -23, -75, 63, 63, -23, -67,
-63, 63, -52, -38, 63, -50, -3, -84, 94, 63, -47, -27, -82, -32, -43, -76,
-63, -79, -24, -39, -58, -39, -79, -76, -44, -35, -37, -73, -92, -73, -91, -30,
-66, -70, 101, 63, 63, 63, -23, -52, 63, 63, -20, -5, 63, -14, 77, 63,
-63, -35, -9, -90, -71, 63, -27, -12, -23, -27, -46, 64, -19, 77, -43, -33,
--55, -2, 63, -88, 91, -86, 113, -51, 77, -82, -11, -49, 123, -84, 119, 63,
--81, 68, -82, -9, 63, -42, 68, 63, -75, 65, -76, -7, -76, -17, 63, -73,
--66, -34, 90, 63, -26, 83, -30, -71, 63, -26, 94, -68, -31, -23, -9, -27,
--3, -19, 85, 63, -14, 100, -11, -43, -92, -11, 63, -84, -76, -46, 123, -78,
-109, -42, 81, -38, 93, -34, 109, 63, -70, -78, -26, 105, -22, 75, 63, 63,
--81, 82, -38, 103, -42, 93, 63, -53, 98, 63, -42, 103, 63, 63, -26, -95,
--9, -23, -51, 102, -49, -54, 63, -42, 113, -75, 98, 63, -70, -65, -68, -3,
-63, 63, -49, -40, -19, 114, -91, -48, 63, 63, 63, 63, -78, -86, -34, -47,
-63, -65, 97, -16, 76, 63, -26, -69, 63, -34, -41, -84, -34, -81, 117, 63,
--70, -50, -30, -27, -22, 124, -14, 123, -86, -66, -49, -22, -81, 122, -42, -77,
--38, -50, 63, -30, -15, -26, -61, -22, -85, -62, -90, -11, -29, -81, -89, 63,
--29, 66, -59, -95, 63, 63, 63, -67, 94, -19, -76, -86, -58, 63, 63, 63,
--84, -14, -78, -57, 63, -72, 97, 63, 63, 63, -65, 119, -19, -70, -16, 104,
--12, -87, 63, -81, -69, 63, -26, -30, -14, -83, -81, -57, -78, -49, -38, -14,
--75, -69, -72, 105, -70, -12, 63, -67, 109, -22, -43, -19, -34, -16, 118, -14,
--79, -7, 66, 63, 63, 63, 63, -38, -4, -81, -53, 63, -37, 67, -45, 100,
--29, 124, */
-
-/* 1-BYTE:
-windows-1250
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
--55, 63, 63, 63, 63, 63, 63, 63, -31, -28, -25, 63, -19, 63, -13, -10,
-63, -4, 63, -61, -71, 63, 63, -49, -16, 63, 63, -52, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -66, -93, -15, -46, 63, 63, -43, 63, 63,
--8, 63, -70, -34, -99, 63, 63, -39, -5, 63, 63, -97, -114, 63, 63, 63,
-
-windows-1251
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -127, -44, -11, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-windows-1252
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, -61, -58,
--55, -52, -49, -46, -43, -40, -37, -34, -31, -28, -25, -22, -19, -16, -13, -10,
--7, -4, -1, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -100, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -114, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--120, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-windows-1253
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -94, -71, -68, -65, -62, -59, -56, -53,
--50, -47, -44, -41, -38, -35, -32, -29, -26, -23, -20, -17, -14, -11, -8, -5,
--2, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-windows-1254
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, -61, -58,
--55, -52, -49, -46, -43, -40, -37, 63, -31, -28, -25, -22, -19, 63, -13, -10,
--7, -4, -1, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -100, 63,
-63, 63, -2, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-windows-1255
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--120, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -32, -43, 63,
-
-windows-1256
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -25, -22, 63, 63, 63, 63,
--7, -4, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -100, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--120, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -63,
--34, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-windows-1257
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, -75, 63, 63, 63, -81,
--55, 63, 63, 63, -43, -88, 63, 63, 63, -28, 63, 63, 63, 63, -13, -10,
-63, -4, 63, 63, -32, 63, 63, 63, 63, 63, -21, 63, 63, 63, -20, 63,
-63, 63, -31, 63, 63, 63, -49, 63, -39, -15, 63, 63, -12, 63, 63, -86,
-63, 63, 63, 63, 63, 63, -5, 63, 63, 63, 63, -22, -34, 63, 63, 63,
-
-windows-1258
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -86, -75, -70, -64, 63, -58,
--55, 63, -49, 63, 63, -40, -37, 63, -31, -28, -25, -22, -19, 63, -13, -10,
--7, -4, -1, -61, 63, 63, 63, 63, -16, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -100, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -125, 63, 63, 63, 63, -11, 63, 63, 63, 63, -3, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--120, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-
- */
-
-/*
-Big5
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -93, -68, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -93, 69, -93,
-72, -93, 75, -93, 78, -93, 81, -93, 84, -93, 86, -93, 89, 63, 63, 63,
--93, 94, -93, 97, -93, 100, -93, 103, -93, 106, 63, -93, 111, -93, 114, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -57, -68, -57, -34, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95,
-64, 63, -58, -74, -58, -41, 63, -57, 77, -57, 110, 63, -93, -87, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -92, 64, 63, -55, 64,
-63, -36, -78, -91, -24, -92, -78, 63, -55, -77, 63, 63, -53, -53, 63, 63,
--85, 91, -83, -63, 63, -48, -36, 63, -44, 101, -40, 83, -74, -59, -71, -81,
-63, -66, -88, -11, -63, -48, -34, 63, 63, -88, -26, -24, -7, 63, 63, -88,
--17, -48, -20, -71, -70, 63, 63, -74, -45, 63, 63, -91, 99, 63, 63, -31,
-70, -92, -49, -91, 109, -90, 79, -54, 118, 63, -50, 77, 63, 63, 63, 63,
--48, -14, -80, -31, 63, 63, 63, 63, -36, -48, -71, -66, -71, -54, -27, 65,
-63, -20, -57, 63, 63, -54, -87, 63, 63, 63, -87, 88, 63, 63, -47, 74,
--44, -76, -44, -62, -77, -13, 63, -36, -15, 63, -68, 88, -20, -53, 63, -91,
-126, -90, 105, -82, 78, -90, 111, 63, -87, 100, -85, -72, -50, 105, -47, 99,
-63, -44, -50, 63, -40, -71, 63, 63, -27, 95, -20, -44, -11, -56, 63, -90,
-119, 63, -40, -46, -68, 101, -71, -17, 63, -85, -52, 63, -89, -62, 63, -50,
--89, -82, 115, 63, -40, -17, 63, 63, -27, 98, -64, -83, 63, 63, -85, -46,
--43, 69, -68, 109, -55, 121, 63, -76, 91, -68, 115, -89, -53, 63, -71, -5,
--47, 123, -85, -36, -76, 95, 63, -89, -42, -52, -82, -52, 122, 63, -82, -89,
--43, 82, -43, 94, 63, -73, 81, -40, -2, 63, -31, -43, -70, 66, 63, 63,
-63, -14, 65, 63, -52, -78, -55, -28, -87, -45, 63, 63, 63, -50, -39, 63,
--47, -74, 63, -43, 115, -79, -64, -76, 124, -76, -86, -35, -74, -73, 104, -31,
--38, -27, -83, -27, -76, -68, -74, 63, -62, 89, -12, 78, 63, -79, -43, -27,
--67, -92, -26, -8, -16, 63, -87, -12, 63, 63, -79, -34, -76, -67, -31, -8,
--23, -75, 63, 63, -23, -67, 63, 63, -52, -38, 63, -50, -3, -84, 94, 63,
--47, -27, -82, -32, -43, -76, 63, -79, -24, -39, -58, -39, -79, -76, -44, -35,
--37, -73, -92, -73, -91, -30, 66, -70, 101, 63, 63, 63, -23, -52, 63, 63,
--20, -5, 63, -14, 77, 63, 63, -35, -9, -90, -71, 63, -27, -12, -23, -27,
--46, 64, -19, 77, -43, -33, -55, -2, 63, -88, 91, -86, 113, -51, 77, -82,
--11, -49, 123, -84, 119, 63, -81, 68, -82, -9, 63, -42, 68, 63, -75, 65,
--76, -7, -76, -17, 63, -73, -66, -34, 90, 63, -26, 83, -30, -71, 63, -26,
-94, -68, -31, -23, -9, -27, -3, -19, 85, 63, -14, 100, -11, -43, -92, -11,
-63, -84, -76, -46, 123, -78, 109, -42, 81, -38, 93, -34, 109, 63, -70, -78,
--26, 105, -22, 75, 63, 63, -81, 82, -38, 103, -42, 93, 63, -53, 98, 63,
--42, 103, 63, 63, -26, -95, -9, -23, -51, 102, -49, -54, 63, -42, 113, -75,
-98, 63, -70, -65, -68, -3, 63, 63, -49, -40, -19, 114, -91, -48, 63, 63,
-63, 63, -78, -86, -34, -47, 63, -65, 97, -16, 76, 63, -26, -69, 63, -34,
--41, -84, -34, -81, 117, 63, -70, -50, -30, -27, -22, 124, -14, 123, -86, -66,
--49, -22, -81, 122, -42, -77, -38, -50, 63, -30, -15, -26, -61, -22, -85, -62,
--90, -11, -29, -81, -89, 63, -29, 66, -59, -95, 63, 63, 63, -67, 94, -19,
--76, -86, -58, 63, 63, 63, -84, -14, -78, -57, 63, -72, 97, 63, 63, 63,
--65, 119, -19, -70, -16, 104, -12, -87, 63, -81, -69, 63, -26, -30, -14, -83,
--81, -57, -78, -49, -38, -14, -75, -69, -72, 105, -70, -12, 63, -67, 109, -22,
--43, -19, -34, -16, 118, -14, -79, -7, 66, 63, 63, 63, 63, -38, -4, -81,
--53, 63, -37, 67, -45, 100, -29, 124, */
-
-/* 1-BYTE:
-IBM864
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, -77, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-x-IBM874
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -95, -62, -29, 63, 63, 63, 63, 63, 63,
- */
-
-/*
-GB2312
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -88, -94, 63, 63, -88, -70, -88, -86,
-63, -88, -82, 63, -88, -76, -88, -71, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -88, -83, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88, -79, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88,
--93, 63, -88, -77, 63, -88, -73, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -91, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -90, -94, -90, -91, -90, -88, -90, -85,
--90, -82, -90, -79, -90, -77, -90, -74, 63, 63, 63, -90, -61, -90, -58, -90,
--55, -90, -52, -90, -49, 63, -90, -44, -90, -41, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -89, -74, -89,
--25, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -95, 63, -92, -78, -92,
--45, 63, -91, -75, -91, -42, 63, -88, -40, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, -46, -69, 63, 63, 63, 63, -70, -91, -58, -51,
-63, 63, 63, 63, 63, 63, 63, -39, -34, -72, -87, 63, 63, 63, 63, 63,
-63, -39, -46, 63, 63, 63, -75, -77, -47, -8, -59, -87, -39, -3, 63, -44,
--28, -55, -66, -74, -25, 63, 63, 63, 63, 63, 63, 63, -69, -36, 63, -47,
--71, 63, -73, -76, -74, -93, -64, -12, 63, 63, -33, -38, 63, -33, -44, -33,
--36, 63, 63, 63, 63, 63, 63, 63, -32, -61, -32, -43, -32, -67, 63, 63,
-63, -49, -7, 63, 63, -44, -78, 63, 63, -37, -31, 63, -75, -26, 63, -36,
--92, 63, 63, 63, 63, -55, -54, 63, 63, 63, -51, -30, -46, -60, -34, -54,
--53, -3, 63, -58, -34, -67, -86, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -80, -78, -49, -36, 63, 63, 63, 63, -58, -63, 63, -31, -81,
-63, 63, 63, 63, 63, 63, 63, -31, -41, 63, -25, -35, 63, -75, -37, 63,
-63, -30, -49, 63, 63, 63, -59, -86, -61, -42, 63, 63, -70, -36, 63, 63,
--65, -20, 63, 63, 63, -49, -94, 63, -29, -83, 63, -49, -21, 63, 63, 63,
--65, -74, 63, 63, 63, 63, 63, -20, -26, 63, -77, -48, -65, -39, 63, -62,
--93, 63, -68, -73, -51, -79, 63, -74, -34, -51, -58, -56, -32, -66, -66, -34,
--11, -80, -31, 63, 63, 63, -41, -85, 63, 63, 63, -22, -73, -21, -73, 63,
--74, -73, 63, 63, -51, -6, 63, -42, -25, 63, -63, -64, 63, 63, 63, 63,
-63, 63, -64, -76, 63, -24, -59, 63, -24, -47, -24, -48, 63, -41, -64, 63,
-63, -52, -35, 63, -64, -30, -67, -73, 63, -48, -88, 63, 63, -56, -74, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -69, -74, -20, -90, -76, -53, 63,
-63, 63, 63, 63, -21, -76, 63, 63, 63, -66, -38, 63, -52, -87, 63, -42,
--34, -59, -88, -44, -95, -52, -23, 63, 63, 63, 63, -61, -20, -43, -65, 63,
-63, 63, -28, -39, 63, 63, 63, 63, -77, -50, 63, 63, 63, 63, 63, 63,
--69, -16, 63, -52, -65, 63, -49, -87, -20, -55, -20, -51, 63, -20, -50, -56,
--37, -20, -40, 63, 63, 63, -75, -7, 63, 63, 63, 63, -60, -4, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -25, -5, 63, 63, -24, -80, 63, 63, -50,
--51, -22, -76, -52, -17, 63, -18, -76, 63, -16, -30, -70, -37, 63, -16, -7,
--56, -77, 63, 63, 63, 63, 63, -74, -36, -43, -26, -41, -59, -53, -81, 63,
-63, 63, -42, -86, 63, -43, -24, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -20, -4, 63, 63, 63, -16, -94, 63, -15, -73, 63, 63, 63, -13,
--60, -13, -41, 63, -13, -34, 63, -13, -18, 63, 63, 63, -12, -93, 63, 63,
--73, -37, -73, -32, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -73, -60, -25, -83, -41, -37, -73, -20, 63, -18, -71, 63, -49,
--37, 63, 63, */
-
-/*
-EUC-JP
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -113, -94, -20, 63, -113, -94,
--21, -113, -86, -94, -113, -86, -86, -113, -87, -95, -113, -86, -79, -113, -86, -64,
--113, -86, -63, -113, -86, -46, -113, -86, -40, -113, -87, -84, -113, -86, -27, -113,
--87, -80, -113, -85, -95, -113, -85, -93, -113, -85, -82, -113, -85, -76, -113, -85,
--65, -113, -87, -61, -113, -85, -47, -113, -85, -45, -113, -85, -29, -113, -85, -28,
--113, -85, -13, -113, -86, -91, -113, -85, -88, -113, -86, -84, -113, -85, -81, -113,
--86, -80, -113, -87, -62, 63, -113, -85, -74, -113, -86, -75, -113, -85, -70, -113,
--86, -67, 63, -113, -87, -92, -113, -85, -57, 63, -113, -85, -58, -113, -87, -90,
--113, -85, -56, -113, -87, -57, -113, -86, -52, -113, -85, -53, -113, -87, -88, -113,
--85, -51, -113, -86, -50, -113, -87, -85, -113, -85, -41, -113, -86, -42, -113, -87,
--51, -113, -86, -37, -113, -85, -38, -113, -86, -35, -113, -85, -33, -113, -86, -31,
--113, -85, -32, -113, -86, -20, -113, -85, -23, -113, -86, -21, -113, -85, -24, -113,
--86, -15, -113, -85, -12, -113, -85, -11, -113, -86, -10, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, -113, -85, -90, -113, -86, -43, -113, -85, -25, -113, -86,
--19, -113, -85, -17, 63, 63, 63, 63, 63, 63, 63, 63, -113, -85, -71, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -113, -90, -31, -113, -90, -29, -113, -90, -25, -113, -90, -20, -90, -94,
--90, -91, -90, -88, -90, -85, -90, -82, -90, -79, -90, -77, -90, -74, -113, -90,
--27, -113, -90, -14, -113, -90, -5, -90, -61, -90, -58, -90, -55, -90, -52, -90,
--49, -113, -90, -8, -90, -44, -90, -41, -113, -90, -6, -113, -90, -4, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -113, -89,
--61, -89, -74, -89, -25, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -95,
-63, -92, -78, -92, -45, 63, -91, -75, -91, -42, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -80, -20, -50, -66, -48, -87, -113,
--80, -74, 63, -80, -25, -48, -67, 63, -113, -80, -43, 63, 63, 63, -113, -79,
--92, -53, -7, -48, -39, -48, -19, -113, -79, -48, 63, -113, -79, -24, 63, -113,
--78, -93, -70, -60, -47, -91, 63, -48, -42, -113, -78, -28, -59, -34, 63, 63,
--47, -40, -113, -77, -88, 63, 63, 63, 63, -77, -60, -113, -77, -39, -60, -68,
--46, -85, 63, -113, -76, -85, -46, -61, 63, 63, 63, -56, -65, -46, -38, -51,
--7, 63, -58, -35, 63, 63, 63, 63, -113, -75, -63, 63, -45, -71, 63, 63,
-63, 63, 63, -45, -43, 63, -113, -74, -66, -113, -74, -54, 63, 63, 63, -113,
--74, -8, 63, -80, -75, 63, -44, -80, 63, 63, -113, -73, -23, -113, -73, -14,
-63, -12, -95, -113, -72, -79, 63, 63, -54, -81, -113, -72, -41, 63, -77, -80,
--80, -48, -44, -7, -113, -71, -91, 63, -70, -54, -43, -86, 63, -113, -71, -45,
-63, 63, 63, -113, -71, -12, 63, 63, 63, 63, 63, -113, -70, -64, -80, -62,
-63, 63, 63, -43, -12, -113, -70, -14, -42, -94, -113, -69, -94, -42, -86, -113,
--69, -75, 63, -113, -69, -63, -42, -67, 63, 63, 63, -113, -69, -20, -50, -26,
--42, -33, 63, -60, -21, -113, -68, -79, -42, -16, -113, -68, -62, 63, -42, -5,
--41, -94, -49, -82, -52, -17, 63, -113, -68, -2, -41, -52, -55, -4, 63, -78,
--9, 63, -113, -67, -37, 63, -62, -87, 63, -113, -67, -3, 63, -63, -37, -113,
--66, -64, -113, -66, -53, 63, -40, -51, -113, -66, -28, -113, -66, -18, 63, 63,
--113, -65, -86, -113, -65, -78, -39, -86, -66, -75, 63, 63, 63, -113, -65, -37,
-63, 63, -113, -65, -7, -113, -64, -89, -65, -28, -39, -26, -113, -64, -64, 63,
--56, -62, 63, 63, -113, -64, -18, -64, -15, -113, -63, -88, -38, -77, -113, -63,
--69, -38, -67, -38, -59, 63, -59, -51, 63, -38, -38, -78, -94, 63, -61, -21,
--38, -20, -113, -62, -61, -113, -62, -42, -113, -62, -33, 63, 63, 63, 63, -51,
--24, 63, 63, -113, -61, -67, -37, -51, 63, -37, -31, -113, -61, -37, 63, 63,
--60, -12, -113, -60, -95, -113, -60, -81, -36, -91, -113, -60, -66, -36, -72, -74,
--53, -113, -60, -40, -113, -60, -31, -51, -51, -36, -33, -113, -60, -8, -113, -59,
--93, 63, 63, -113, -59, -64, -113, -59, -54, 63, 63, 63, -35, -67, -70, -95,
--113, -58, -93, 63, 63, 63, -113, -58, -58, 63, -113, -58, -39, 63, -35, -20,
--35, -4, -113, -58, -7, -62, -39, -113, -57, -80, -67, -89, 63, -51, -31, -34,
--72, 63, 63, 63, -34, -46, -34, -35, -61, -71, 63, -71, -62, 63, 63, 63,
-63, 63, 63, -64, -95, -113, -56, -15, -33, -71, 63, 63, 63, -113, -55, -69,
--78, -48, 63, -61, -70, 63, 63, 63, -113, -55, -16, -113, -55, -7, 63, -51,
--48, 63, -113, -54, -72, 63, 63, -113, -54, -52, -113, -54, -41, -113, -54, -29,
-63, 63, 63, 63, 63, 63, 63, -113, -53, -49, 63, -113, -53, -24, -113, -53,
--11, -113, -52, -91, -113, -52, -84, 63, -32, -11, -32, -8, 63, 63, -31, -91,
-63, -59, -60, -56, -86, 63, -113, -51, -57, -113, -51, -51, -70, -81, 63, 63,
--113, -51, -3, -113, -50, -84, -56, -81, -113, -50, -70, 63, 63, -67, -30, -65,
--65, -61, -27, -65, -25, 63, 63, 63, -61, -50, -113, -49, -49, -75, -50, -113,
--49, -32, 63, -113, -49, -17, 63, -113, -48, -89, 63, -63, -61, 63, -51, -76,
-63, 63, -29, -70, -113, -48, -6, 63, 63, -29, -51, 63, -29, -42, 63, -113,
--47, -30, -50, -75, -113, -47, -15, -29, -6, -113, -46, -92, -113, -46, -86, 63,
-63, 63, -58, -58, 63, -113, -46, -22, 63, 63, -54, -76, 63, 63, 63, -57,
--68, -27, -89, -27, -78, -113, -45, -19, -113, -45, -5, -52, -42, 63, -50, -3,
--113, -44, -62, -113, -44, -51, 63, -113, -44, -34, 63, 63, 63, 63, 63, -113,
--44, -18, -26, -86, -113, -43, -91, -113, -43, -82, 63, -113, -43, -67, */
-
-/* 1-BYTE:
-KOI8-R
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -26, -56, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-
-x-MacRoman
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -69, -75, -68, -53, -52, -82,
--125, -19, -20, -15, -51, -81, -13, 63, -121, -118, -115, -112, -110, 63, -105, -102,
--99, -97, -40, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -49, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -60, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--10, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
- */
-
-/*
-GBK
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -88, -94, 63, 63, -88, -70, -88, -86,
-63, -88, -82, 63, -88, -76, -88, -71, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88,
--67, 63, 63, -88, -83, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88, -79,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--88, -93, 63, -88, -77, 63, -88, -73, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -91, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -90, -94, -90, -91, -90, -88, -90,
--85, -90, -82, -90, -79, -90, -77, -90, -74, 63, 63, 63, -90, -61, -90, -58,
--90, -55, -90, -52, -90, -49, 63, -90, -44, -90, -41, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -89, -74,
--89, -25, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -95, 63, -92, -78,
--92, -45, 63, -91, -75, -91, -42, 63, -88, -40, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -46, -69, -127, 73, -127, 86, -127, 96, -127,
-123, -70, -91, -58, -51, -127, -97, -127, -78, -127, -65, -127, -45, -127, -34, -127,
--16, -126, 66, -39, -34, -72, -87, -126, -126, -126, -109, -126, -85, -126, -57, -126,
--33, -126, -7, -39, -46, -125, 112, -125, -115, -125, -83, -75, -77, -47, -8, -59,
--87, -39, -3, -124, 68, -44, -28, -55, -66, -74, -25, -124, -122, -124, -99, -124,
--77, -124, -56, -124, -32, -124, -7, -123, 77, -69, -36, -123, 109, -47, -71, -123,
--111, -73, -76, -74, -93, -64, -12, -123, -58, -123, -41, -33, -38, -123, -9, -33,
--44, -33, -36, -122, 95, -122, 116, -122, -120, -122, -99, -122, -80, -122, -65, -122,
--42, -32, -61, -32, -43, -32, -67, -121, 101, -121, 126, -121, -107, -49, -7, -121,
--50, -121, -29, -44, -78, -120, 82, -120, 99, -37, -31, -120, -124, -75, -26, -120,
--80, -36, -92, -120, -39, -120, -14, -119, 79, -119, 105, -55, -54, -119, -98, -119,
--69, -119, -43, -51, -30, -46, -60, -34, -54, -53, -3, -118, 118, -58, -34, -67,
--86, -118, -71, -118, -52, -118, -29, -118, -2, -117, 87, -117, 117, -117, -113, -117,
--90, -117, -61, -117, -31, -117, -2, -116, 78, -80, -78, -49, -36, -116, 123, -116,
--110, -116, -90, -116, -71, -58, -63, -116, -37, -31, -81, -115, 68, -115, 91, -115,
-115, -115, -114, -115, -91, -115, -64, -115, -39, -31, -41, -114, 88, -25, -35, -114,
--121, -75, -37, -114, -86, -114, -61, -30, -49, -114, -27, -114, -5, -113, 86, -59,
--86, -61, -42, -113, -107, -113, -86, -70, -36, -113, -51, -113, -30, -65, -20, -112,
-67, -112, 80, -112, 103, -49, -94, -112, -118, -29, -83, -112, -78, -49, -21, -112,
--42, -112, -18, -111, 73, -65, -74, -111, -126, -111, -99, -111, -74, -111, -43, -111,
--28, -20, -26, -110, 73, -77, -48, -65, -39, -110, 126, -62, -93, -110, -108, -68,
--73, -51, -79, -110, -51, -74, -34, -51, -58, -56, -32, -66, -66, -34, -11, -80,
--31, -109, -103, -109, -77, -109, -51, -41, -85, -109, -8, -108, 83, -108, 113, -22,
--73, -21, -73, -108, -76, -74, -73, -108, -31, -108, -13, -51, -6, -107, 90, -42,
--25, -107, -125, -63, -64, -107, -80, -107, -53, -107, -24, -107, -3, -106, 83, -106,
-101, -64, -76, -106, -119, -24, -59, -106, -82, -24, -47, -24, -48, -106, -25, -41,
--64, -105, 70, -105, 96, -52, -35, -105, -110, -64, -30, -67, -73, -105, -36, -48,
--88, -104, 79, -104, 98, -56, -74, -104, -108, -104, -80, -104, -52, -104, -26, -103,
-64, -103, 92, -103, 119, -103, -107, -103, -74, -103, -41, -69, -74, -20, -90, -76,
--53, -102, 125, -102, -109, -102, -85, -102, -64, -102, -41, -21, -76, -102, -11, -101,
-72, -101, 90, -66, -38, -101, 123, -52, -87, -101, -102, -42, -34, -59, -88, -44,
--95, -52, -23, -101, -15, -100, 72, -100, 91, -100, 111, -61, -20, -43, -65, -100,
--72, -100, -49, -100, -30, -28, -39, -99, 78, -99, 103, -99, 126, -99, -104, -77,
--50, -99, -54, -99, -27, -98, 65, -98, 96, -98, 125, -98, -99, -69, -16, -98,
--51, -52, -65, -98, -12, -49, -87, -20, -55, -20, -51, -97, -104, -20, -50, -56,
--37, -20, -40, -96, 64, -96, 93, -96, 124, -75, -7, -96, -86, -96, -67, -96,
--44, -96, -21, -60, -4, -86, 80, -86, 101, -86, 119, -86, -108, -85, 80, -85,
-103, -85, 124, -85, -109, -84, 76, -25, -5, -84, 122, -84, -108, -24, -80, -83,
-100, -83, -123, -50, -51, -22, -76, -52, -17, -82, 120, -18, -76, -81, 71, -16,
--30, -70, -37, -81, 116, -16, -7, -56, -77, -80, 80, -80, 107, -80, 126, -80,
--101, -79, 74, -74, -36, -43, -26, -41, -59, -53, -81, -78, 88, -78, 111, -78,
--122, -42, -86, -77, 81, -43, -24, -77, 115, -77, -115, -76, 68, -76, 86, -76,
-107, -76, -121, -75, 65, -75, 95, -75, 118, -75, -120, -75, -96, -20, -4, -74,
-112, -74, -122, -74, -100, -16, -94, -73, 110, -15, -73, -73, -100, -72, 82, -72,
-111, -13, -60, -13, -41, -71, 74, -13, -34, -71, 114, -13, -18, -71, -97, -70,
-86, -70, 111, -12, -93, -69, 68, -69, 100, -73, -37, -73, -32, -68, 71, -68,
-94, -68, 123, -68, -103, -67, 88, -67, 120, -67, -103, -66, 87, -66, 120, -66,
--102, -65, 90, -65, 123, -65, -102, -64, 90, -64, 122, -73, -60, -25, -83, -41,
--37, -73, -20, -64, -112, -18, -71, -63, 91, -49, -37, -63, -119, -63, -96, */
-
-/*
-GB2312
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -88, -94, 63, 63, -88, -70, -88, -86,
-63, -88, -82, 63, -88, -76, -88, -71, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -88, -83, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88, -79, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -88,
--93, 63, -88, -77, 63, -88, -73, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -91, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, -90, -94, -90, -91, -90, -88, -90, -85,
--90, -82, -90, -79, -90, -77, -90, -74, 63, 63, 63, -90, -61, -90, -58, -90,
--55, -90, -52, -90, -49, 63, -90, -44, -90, -41, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -89, -74, -89,
--25, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -95, 63, -92, -78, -92,
--45, 63, -91, -75, -91, -42, 63, -88, -40, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, -46, -69, 63, 63, 63, 63, -70, -91, -58, -51,
-63, 63, 63, 63, 63, 63, 63, -39, -34, -72, -87, 63, 63, 63, 63, 63,
-63, -39, -46, 63, 63, 63, -75, -77, -47, -8, -59, -87, -39, -3, 63, -44,
--28, -55, -66, -74, -25, 63, 63, 63, 63, 63, 63, 63, -69, -36, 63, -47,
--71, 63, -73, -76, -74, -93, -64, -12, 63, 63, -33, -38, 63, -33, -44, -33,
--36, 63, 63, 63, 63, 63, 63, 63, -32, -61, -32, -43, -32, -67, 63, 63,
-63, -49, -7, 63, 63, -44, -78, 63, 63, -37, -31, 63, -75, -26, 63, -36,
--92, 63, 63, 63, 63, -55, -54, 63, 63, 63, -51, -30, -46, -60, -34, -54,
--53, -3, 63, -58, -34, -67, -86, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -80, -78, -49, -36, 63, 63, 63, 63, -58, -63, 63, -31, -81,
-63, 63, 63, 63, 63, 63, 63, -31, -41, 63, -25, -35, 63, -75, -37, 63,
-63, -30, -49, 63, 63, 63, -59, -86, -61, -42, 63, 63, -70, -36, 63, 63,
--65, -20, 63, 63, 63, -49, -94, 63, -29, -83, 63, -49, -21, 63, 63, 63,
--65, -74, 63, 63, 63, 63, 63, -20, -26, 63, -77, -48, -65, -39, 63, -62,
--93, 63, -68, -73, -51, -79, 63, -74, -34, -51, -58, -56, -32, -66, -66, -34,
--11, -80, -31, 63, 63, 63, -41, -85, 63, 63, 63, -22, -73, -21, -73, 63,
--74, -73, 63, 63, -51, -6, 63, -42, -25, 63, -63, -64, 63, 63, 63, 63,
-63, 63, -64, -76, 63, -24, -59, 63, -24, -47, -24, -48, 63, -41, -64, 63,
-63, -52, -35, 63, -64, -30, -67, -73, 63, -48, -88, 63, 63, -56, -74, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -69, -74, -20, -90, -76, -53, 63,
-63, 63, 63, 63, -21, -76, 63, 63, 63, -66, -38, 63, -52, -87, 63, -42,
--34, -59, -88, -44, -95, -52, -23, 63, 63, 63, 63, -61, -20, -43, -65, 63,
-63, 63, -28, -39, 63, 63, 63, 63, -77, -50, 63, 63, 63, 63, 63, 63,
--69, -16, 63, -52, -65, 63, -49, -87, -20, -55, -20, -51, 63, -20, -50, -56,
--37, -20, -40, 63, 63, 63, -75, -7, 63, 63, 63, 63, -60, -4, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -25, -5, 63, 63, -24, -80, 63, 63, -50,
--51, -22, -76, -52, -17, 63, -18, -76, 63, -16, -30, -70, -37, 63, -16, -7,
--56, -77, 63, 63, 63, 63, 63, -74, -36, -43, -26, -41, -59, -53, -81, 63,
-63, 63, -42, -86, 63, -43, -24, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, -20, -4, 63, 63, 63, -16, -94, 63, -15, -73, 63, 63, 63, -13,
--60, -13, -41, 63, -13, -34, 63, -13, -18, 63, 63, 63, -12, -93, 63, 63,
--73, -37, -73, -32, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, -73, -60, -25, -83, -41, -37, -73, -20, 63, -18, -71, 63, -49,
--37, 63, 63, */
-
-/*
-EUC-KR
-9, 12, 28, 31, 48, 51, 54, 57, 65, 68, 71, 74, 77, 80, 83, 86,
-89, 97, 100, 103, 106, 109, 112, 115, 118, 121, -88, -93, 63, -88, -84, 63,
-63, -88, -95, 63, 63, 63, 63, 63, -88, -86, 63, -88, -83, 63, 63, 63,
-63, 63, -87, -93, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -87, -94,
-63, 63, 63, 63, 63, 63, -88, -92, 63, 63, 63, -88, -90, 63, -87, -89,
-63, 63, -88, -87, 63, 63, -88, -81, 63, 63, -87, -85, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -91, -62, -91, -59, -91, -56, -91,
--53, -91, -50, -91, -47, -91, -45, -91, -42, 63, 63, 63, -91, -29, -91, -26,
--91, -23, -91, -20, -91, -17, 63, -91, -12, -91, -9, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -84, -74,
--84, -25, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, -95, -95, 63, -86, -78,
--86, -45, 63, -85, -75, -85, -42, 63, 63, -92, -87, -92, -54, -92, -21, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -20, -23, 63, -25, -47, 63, 63,
--6, -92, 63, 63, 63, 63, 63, 63, 63, 63, -16, -69, -36, -10, 63, 63,
-63, 63, 63, -13, -16, -3, -22, 63, 63, 63, 63, 63, 63, -42, -87, -3,
--21, 63, 63, 63, 63, -4, -15, -48, -62, -10, -49, 63, 63, 63, -3, -63,
-63, 63, 63, -38, -29, 63, -41, -39, 63, -9, -94, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -15, -77, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, 63, 63, -24, -21, 63, 63, 63, -35, -59,
-63, 63, -24, -30, -20, -88, 63, 63, 63, -12, -93, -53, -87, 63, 63, 63,
-63, 63, 63, 63, 63, -5, -5, 63, 63, 63, -28, -52, 63, 63, -50, -80,
--45, -33, 63, 63, 63, -19, -44, 63, 63, -6, -42, 63, 63, 63, 63, 63,
--42, -70, 63, 63, -16, -88, 63, -10, -70, 63, 63, -33, -53, -50, -58, -42,
--25, 63, 63, -23, -18, 63, -36, -42, 63, -10, -31, 63, 63, 63, -29, -45,
-63, 63, 63, -33, -52, 63, 63, 63, -53, -81, -3, -13, 63, 63, 63, 63,
-63, 63, -29, -81, 63, 63, 63, 63, 63, 63, 63, 63, -11, -49, 63, 63,
-63, -38, -26, 63, 63, 63, -13, -68, 63, -12, -83, 63, 63, 63, 63, -44,
--32, 63, 63, -24, -38, 63, 63, -15, -72, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, -49, -81, 63, 63, 63, -14, -51, 63, -16, -84, 63, 63,
--11, -95, 63, -32, -37, -48, -65, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, -13, -82, 63, 63, 63, 63, 63, 63, 63, 63, 63,
--18, -63, 63, -9, -63, -36, -57, -15, -67, 63, -23, -79, -12, -15, 63, 63,
--12, -24, -4, -71, -39, -35, -45, -64, 63, -49, -75, 63, 63, 63, 63, 63,
-63, -13, -91, 63, 63, 63, 63, 63, 63, -5, -3, 63, -9, -87, 63, 63,
-63, 63, 63, 63, -23, -62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, 63, 63, 63, 63, 63, 63, -6, -64, -30, -81, -51, -28, 63, -40, -91,
--19, -16, 63, 63, -24, -73, 63, -17, -93, -17, -91, 63, 63, 63, -3, -35,
-63, 63, 63, 63, 63, 63, 63, 63, -30, -22, 63, -13, -73, -30, -78, 63,
-63, 63, -14, -79, 63, -10, -37, 63, 63, 63, 63, 63, 63, -11, -88, 63,
--23, -34, 63, 63, -27, -52, 63, 63, 63, -14, -61, 63, -49, -30, 63, 63,
-63, 63, -9, -62, 63, -48, -75, 63, 63, 63, -44, -65, 63, 63, 63, 63,
--35, -49, 63, 63, 63, -46, -95, -13, -49, 63, 63, 63, -40, -47, 63, -42,
--93, -24, -78, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63,
-63, */
-
-
-/*
-~/ddeclipse/dalvik$ ./run-core-tests.sh tests.api.java.nio.charset.Charset_DomainEndToEnd_Test
-mode: simulator
-Running selected tests...
-.US-ASCII MaxBytes = 1.0
- - IBM367
- - iso_646.irv:1983
- - csASCII
- - US-ASCII
- - ascii7
- - cp367
- - windows-20127
- - ASCII
- - ANSI_X3.4-1986
- - 646
- - ISO646-US
- - ANSI_X3.4-1968
- - iso-ir-6
- - ibm-367
- - ISO_646.irv:1991
- - us
-UTF-8 MaxBytes = 3.0
- - ibm-17593
- - ibm-1208
- - UTF-8
- - ibm-1209
- - cp1208
- - ibm-13496
- - ibm-13497
- - windows-65001
- - ibm-5304
- - ibm-5305
- - ibm-17592
-UTF-16 MaxBytes = 2.0
- - ucs-2
- - UTF-16
- - csUnicode
- - unicode
- - ibm-1204
- - ISO-10646-UCS-2
- - ibm-1205
-UTF-16BE MaxBytes = 2.0
- - x-utf-16be
- - ibm-61955
- - ibm-61956
- - UTF16_BigEndian
- - windows-1201
- - cp1200
- - UTF-16BE
- - cp1201
- - ibm-17584
- - ibm-17585
- - ibm-21680
- - ibm-21681
- - ibm-13488
- - ibm-1200
- - ibm-13489
- - ibm-25776
- - ibm-1201
- - ibm-25777
-UTF-16LE MaxBytes = 2.0
- - UTF16_LittleEndian
- - UTF-16LE
- - windows-1200
- - ibm-13490
- - ibm-13491
- - ibm-17586
- - ibm-17587
- - ibm-21682
- - x-utf-16le
- - ibm-21683
- - ibm-1202
- - ibm-25778
- - ibm-1203
- - ibm-25779
-ISO-8859-1 MaxBytes = 1.0
- - 819
- - ISO-8859-1
- - csISOLatin1
- - cp819
- - l1
- - iso-ir-100
- - 8859_1
- - ibm-819
- - IBM819
- - latin1
- - ISO_8859-1:1987
-ISO-8859-2 MaxBytes = 1.0
- - ISO-8859-2
- - ibm-912
- - ibm-912_P100-1995
- - csISOLatin2
- - l2
- - iso-ir-101
- - 8859_2
- - 912
- - cp912
- - windows-28592
- - latin2
- - ISO_8859-2:1987
-ISO-8859-3 MaxBytes = 1.0
- - ISO-8859-3
- - ibm-913
- - csISOLatin3
- - l3
- - 8859_3
- - 913
- - ibm-913_P100-2000
- - cp913
- - iso-ir-109
- - ISO_8859-3:1988
- - windows-28593
- - latin3
-ISO-8859-4 MaxBytes = 1.0
- - windows-28594
- - latin4
- - ISO-8859-4
- - ibm-914
- - iso-ir-110
- - ibm-914_P100-1995
- - csISOLatin4
- - l4
- - 8859_4
- - 914
- - ISO_8859-4:1988
- - cp914
-ISO-8859-5 MaxBytes = 1.0
- - cp915
- - windows-28595
- - ISO-8859-5
- - ibm-915
- - iso-ir-144
- - ibm-915_P100-1995
- - csISOLatinCyrillic
- - cyrillic
- - 8859_5
- - ISO_8859-5:1988
- - 915
-ISO-8859-6 MaxBytes = 1.0
- - 1089
- - windows-28596
- - ASMO-708
- - ibm-1089_P100-1995
- - arabic
- - ISO-8859-6-E
- - cp1089
- - ISO-8859-6-I
- - ISO-8859-6
- - ibm-1089
- - ECMA-114
- - iso-ir-127
- - ISO_8859-6:1987
- - csISOLatinArabic
- - 8859_6
-ISO-8859-7 MaxBytes = 1.0
- - greek
- - ibm-9005_X110-2007
- - csISOLatinGreek
- - windows-28597
- - sun_eu_greek
- - ibm-9005
- - ISO-8859-7
- - greek8
- - ISO_8859-7:1987
- - iso-ir-126
- - ELOT_928
- - ECMA-118
-ISO-8859-8 MaxBytes = 1.0
- - ISO-8859-8-I
- - windows-28598
- - ibm-5012
- - ISO-8859-8
- - ISO_8859-8:1988
- - iso-ir-138
- - ibm-5012_P100-1999
- - 8859_8
- - csISOLatinHebrew
- - ISO-8859-8-E
- - hebrew
-ISO-8859-8 MaxBytes = 1.0
- - ISO-8859-8-I
- - windows-28598
- - ibm-5012
- - ISO-8859-8
- - ISO_8859-8:1988
- - iso-ir-138
- - ibm-5012_P100-1999
- - 8859_8
- - csISOLatinHebrew
- - ISO-8859-8-E
- - hebrew
-ISO-8859-9 MaxBytes = 1.0
- - windows-28599
- - csISOLatin5
- - l5
- - cp920
- - ibm-920_P100-1995
- - latin5
- - 920
- - ISO-8859-9
- - iso-ir-148
- - ISO_8859-9:1989
- - ECMA-128
- - ibm-920
- - 8859_9
-ISO-8859-10 MaxBytes = 1.0
- - ISO-8859-10
- - latin6
- - iso-8859_10-1998
- - csISOLatin6
- - iso-ir-157
- - l6
- - ISO_8859-10:1992
-x-iso-8859_11-2001 MaxBytes = 1.0
- - ISO-8859-11
- - iso-8859_11-2001
- - thai8
-ISO-8859-13 MaxBytes = 1.0
- - ibm-921_P100-1995
- - ISO-8859-13
- - 921
- - windows-28603
- - cp921
- - 8859_13
- - ibm-921
-ISO-8859-14 MaxBytes = 1.0
- - latin8
- - ISO-8859-14
- - iso-ir-199
- - l8
- - iso-celtic
- - iso-8859_14-1998
- - ISO_8859-14:1998
-ISO-8859-15 MaxBytes = 1.0
- - ibm-923
- - csisolatin0
- - ISO-8859-15
- - csisolatin9
- - windows-28605
- - latin0
- - l9
- - iso8859_15_fdis
- - cp923
- - Latin-9
- - ibm-923_P100-1998
- - 923
- - 8859_15
-ISO-8859-16 MaxBytes = 1.0
- - latin10
- - iso-8859_16-2001
- - ISO_8859-16:2001
- - ISO-8859-16
- - iso-ir-226
- - l10
-ISO-2022-JP MaxBytes = 6.0
- - csISO2022JP
- - ISO-2022-JP
-Big5 MaxBytes = 2.0
- - windows-950-2000
- - csBig5
- - Big5
- - x-big5
- - windows-950
-windows-1250 MaxBytes = 1.0
- - windows-1250
- - cp1250
- - ibm-5346
- - ibm-5346_P100-1998
-windows-1251 MaxBytes = 1.0
- - ANSI1251
- - windows-1251
- - cp1251
- - ibm-5347
- - ibm-5347_P100-1998
-windows-1252 MaxBytes = 1.0
- - windows-1252
- - cp1252
- - ibm-5348
- - ibm-5348_P100-1997
-windows-1253 MaxBytes = 1.0
- - ibm-5349_P100-1998
- - windows-1253
- - cp1253
- - ibm-5349
-windows-1254 MaxBytes = 1.0
- - ibm-5350
- - ibm-5350_P100-1998
- - windows-1254
- - cp1254
-windows-1255 MaxBytes = 1.0
- - ibm-9447_P100-2002
- - ibm-9447
- - windows-1255
- - cp1255
-windows-1256 MaxBytes = 1.0
- - ibm-9448_X100-2005
- - ibm-9448
- - windows-1256
- - cp1256
-windows-1257 MaxBytes = 1.0
- - cp1257
- - ibm-9449_P100-2002
- - ibm-9449
- - windows-1257
-windows-1258 MaxBytes = 1.0
- - cp1258
- - ibm-5354
- - ibm-5354_P100-1998
- - windows-1258
-Big5 MaxBytes = 2.0
- - windows-950-2000
- - csBig5
- - Big5
- - x-big5
- - windows-950
-cp864 MaxBytes = 1.0
- - csIBM864
- - IBM864
- - cp864
- - ibm-864_X110-1999
- - ibm-864
-TIS-620 MaxBytes = 1.0
- - ibm-9066
- - TIS-620
- - eucTH
- - cp874
- - tis620.2533
- - ibm-874
- - ibm-874_P100-1995
-GBK MaxBytes = 2.0
- - EUC-CN
- - csISO58GB231280
- - chinese
- - csGB2312
- - CP936
- - GBK
- - gb2312-1980
- - windows-936
- - MS936
- - windows-936-2000
- - GB2312
- - iso-ir-58
- - GB_2312-80
-EUC-JP MaxBytes = 3.0
- - EUC-JP
- - ibm-954_P101-2007
- - eucjis
- - X-EUC-JP
- - csEUCPkdFmtJapanese
- - Extended_UNIX_Code_Packed_Format_for_Japanese
- - ujis
- - ibm-954
-KOI8-R MaxBytes = 1.0
- - windows-20866
- - ibm-878
- - ibm-878_P100-1996
- - koi8
- - KOI8-R
- - cp878
- - csKOI8R
-macintosh MaxBytes = 1.0
- - csMacintosh
- - macintosh
- - windows-10000
- - macos-0_2-10.2
- - mac
-GBK MaxBytes = 2.0
- - EUC-CN
- - csISO58GB231280
- - chinese
- - csGB2312
- - CP936
- - GBK
- - gb2312-1980
- - windows-936
- - MS936
- - windows-936-2000
- - GB2312
- - iso-ir-58
- - GB_2312-80
-GBK MaxBytes = 2.0
- - EUC-CN
- - csISO58GB231280
- - chinese
- - csGB2312
- - CP936
- - GBK
- - gb2312-1980
- - windows-936
- - MS936
- - windows-936-2000
- - GB2312
- - iso-ir-58
- - GB_2312-80
-EUC-KR MaxBytes = 2.0
- - KS_C_5601-1989
- - EUC-KR
- - 5601
- - korean
- - csKSC56011987
- - windows-949
- - KSC_5601
- - windows-949-2000
- - ms949
- - csEUCKR
- - iso-ir-149
- - KS_C_5601-1987
-Big5
- - windows-950-2000
- - csBig5
- - Big5
- - x-big5
- - windows-950
-BOCU-1
- - csBOCU-1
- - BOCU-1
- - ibm-1214
- - ibm-1215
-CESU-8
- - ibm-9400
- - CESU-8
-cp864
- - csIBM864
- - IBM864
- - cp864
- - ibm-864_X110-1999
- - ibm-864
-EUC-JP
- - EUC-JP
- - ibm-954_P101-2007
- - eucjis
- - X-EUC-JP
- - csEUCPkdFmtJapanese
- - Extended_UNIX_Code_Packed_Format_for_Japanese
- - ujis
- - ibm-954
-EUC-KR
- - KS_C_5601-1989
- - EUC-KR
- - 5601
- - korean
- - csKSC56011987
- - windows-949
- - KSC_5601
- - windows-949-2000
- - ms949
- - csEUCKR
- - iso-ir-149
- - KS_C_5601-1987
-GBK
- - EUC-CN
- - csISO58GB231280
- - chinese
- - csGB2312
- - CP936
- - GBK
- - gb2312-1980
- - windows-936
- - MS936
- - windows-936-2000
- - GB2312
- - iso-ir-58
- - GB_2312-80
-HZ-GB-2312
- - HZ
- - HZ-GB-2312
-ISO-2022-JP
- - csISO2022JP
- - ISO-2022-JP
-ISO-8859-1
- - 819
- - ISO-8859-1
- - csISOLatin1
- - cp819
- - l1
- - iso-ir-100
- - 8859_1
- - ibm-819
- - IBM819
- - latin1
- - ISO_8859-1:1987
-ISO-8859-10
- - ISO-8859-10
- - latin6
- - iso-8859_10-1998
- - csISOLatin6
- - iso-ir-157
- - l6
- - ISO_8859-10:1992
-ISO-8859-13
- - ibm-921_P100-1995
- - ISO-8859-13
- - 921
- - windows-28603
- - cp921
- - 8859_13
- - ibm-921
-ISO-8859-14
- - latin8
- - ISO-8859-14
- - iso-ir-199
- - l8
- - iso-celtic
- - iso-8859_14-1998
- - ISO_8859-14:1998
-ISO-8859-15
- - ibm-923
- - csisolatin0
- - ISO-8859-15
- - csisolatin9
- - windows-28605
- - latin0
- - l9
- - iso8859_15_fdis
- - cp923
- - Latin-9
- - ibm-923_P100-1998
- - 923
- - 8859_15
-ISO-8859-16
- - latin10
- - iso-8859_16-2001
- - ISO_8859-16:2001
- - ISO-8859-16
- - iso-ir-226
- - l10
-ISO-8859-2
- - ISO-8859-2
- - ibm-912
- - ibm-912_P100-1995
- - csISOLatin2
- - l2
- - iso-ir-101
- - 8859_2
- - 912
- - cp912
- - windows-28592
- - latin2
- - ISO_8859-2:1987
-ISO-8859-3
- - ISO-8859-3
- - ibm-913
- - csISOLatin3
- - l3
- - 8859_3
- - 913
- - ibm-913_P100-2000
- - cp913
- - iso-ir-109
- - ISO_8859-3:1988
- - windows-28593
- - latin3
-ISO-8859-4
- - windows-28594
- - latin4
- - ISO-8859-4
- - ibm-914
- - iso-ir-110
- - ibm-914_P100-1995
- - csISOLatin4
- - l4
- - 8859_4
- - 914
- - ISO_8859-4:1988
- - cp914
-ISO-8859-5
- - cp915
- - windows-28595
- - ISO-8859-5
- - ibm-915
- - iso-ir-144
- - ibm-915_P100-1995
- - csISOLatinCyrillic
- - cyrillic
- - 8859_5
- - ISO_8859-5:1988
- - 915
-ISO-8859-6
- - 1089
- - windows-28596
- - ASMO-708
- - ibm-1089_P100-1995
- - arabic
- - ISO-8859-6-E
- - cp1089
- - ISO-8859-6-I
- - ISO-8859-6
- - ibm-1089
- - ECMA-114
- - iso-ir-127
- - ISO_8859-6:1987
- - csISOLatinArabic
- - 8859_6
-ISO-8859-7
- - greek
- - ibm-9005_X110-2007
- - csISOLatinGreek
- - windows-28597
- - sun_eu_greek
- - ibm-9005
- - ISO-8859-7
- - greek8
- - ISO_8859-7:1987
- - iso-ir-126
- - ELOT_928
- - ECMA-118
-ISO-8859-8
- - ISO-8859-8-I
- - windows-28598
- - ibm-5012
- - ISO-8859-8
- - ISO_8859-8:1988
- - iso-ir-138
- - ibm-5012_P100-1999
- - 8859_8
- - csISOLatinHebrew
- - ISO-8859-8-E
- - hebrew
-ISO-8859-9
- - windows-28599
- - csISOLatin5
- - l5
- - cp920
- - ibm-920_P100-1995
- - latin5
- - 920
- - ISO-8859-9
- - iso-ir-148
- - ISO_8859-9:1989
- - ECMA-128
- - ibm-920
- - 8859_9
-KOI8-R
- - windows-20866
- - ibm-878
- - ibm-878_P100-1996
- - koi8
- - KOI8-R
- - cp878
- - csKOI8R
-macintosh
- - csMacintosh
- - macintosh
- - windows-10000
- - macos-0_2-10.2
- - mac
-SCSU
- - SCSU
- - ibm-1212
- - ibm-1213
-Shift_JIS
- - sjis
- - ibm-943_P15A-2003
- - csShiftJIS
- - windows-31j
- - IBM-943C
- - cp932
- - windows-932
- - ms932
- - x-sjis
- - Shift_JIS
- - pck
- - cp943c
- - csWindows31J
- - x-ms-cp932
- - ibm-943_VSUB_VPUA
- - MS_Kanji
- - ibm-943
-TIS-620
- - ibm-9066
- - TIS-620
- - eucTH
- - cp874
- - tis620.2533
- - ibm-874
- - ibm-874_P100-1995
-US-ASCII
- - IBM367
- - iso_646.irv:1983
- - csASCII
- - US-ASCII
- - ascii7
- - cp367
- - windows-20127
- - ASCII
- - ANSI_X3.4-1986
- - 646
- - ISO646-US
- - ANSI_X3.4-1968
- - iso-ir-6
- - ibm-367
- - ISO_646.irv:1991
- - us
-UTF-16
- - ucs-2
- - UTF-16
- - csUnicode
- - unicode
- - ibm-1204
- - ISO-10646-UCS-2
- - ibm-1205
-UTF-16BE
- - x-utf-16be
- - ibm-61955
- - ibm-61956
- - UTF16_BigEndian
- - windows-1201
- - cp1200
- - UTF-16BE
- - cp1201
- - ibm-17584
- - ibm-17585
- - ibm-21680
- - ibm-21681
- - ibm-13488
- - ibm-1200
- - ibm-13489
- - ibm-25776
- - ibm-1201
- - ibm-25777
-UTF-16LE
- - UTF16_LittleEndian
- - UTF-16LE
- - windows-1200
- - ibm-13490
- - ibm-13491
- - ibm-17586
- - ibm-17587
- - ibm-21682
- - x-utf-16le
- - ibm-21683
- - ibm-1202
- - ibm-25778
- - ibm-1203
- - ibm-25779
-UTF-32
- - ISO-10646-UCS-4
- - UTF-32
- - ucs-4
- - ibm-1236
- - ibm-1237
- - csUCS4
-UTF-32BE
- - UTF32_BigEndian
- - UTF-32BE
- - ibm-1232
- - ibm-1233
-UTF-32LE
- - UTF32_LittleEndian
- - ibm-1234
- - ibm-1235
- - UTF-32LE
-UTF-7
- - UTF-7
- - windows-65000
-UTF-8
- - ibm-17593
- - ibm-1208
- - UTF-8
- - ibm-1209
- - cp1208
- - ibm-13496
- - ibm-13497
- - windows-65001
- - ibm-5304
- - ibm-5305
- - ibm-17592
-windows-1250
- - windows-1250
- - cp1250
- - ibm-5346
- - ibm-5346_P100-1998
-windows-1251
- - ANSI1251
- - windows-1251
- - cp1251
- - ibm-5347
- - ibm-5347_P100-1998
-windows-1252
- - windows-1252
- - cp1252
- - ibm-5348
- - ibm-5348_P100-1997
-windows-1253
- - ibm-5349_P100-1998
- - windows-1253
- - cp1253
- - ibm-5349
-windows-1254
- - ibm-5350
- - ibm-5350_P100-1998
- - windows-1254
- - cp1254
-windows-1255
- - ibm-9447_P100-2002
- - ibm-9447
- - windows-1255
- - cp1255
-windows-1256
- - ibm-9448_X100-2005
- - ibm-9448
- - windows-1256
- - cp1256
-windows-1257
- - cp1257
- - ibm-9449_P100-2002
- - ibm-9449
- - windows-1257
-windows-1258
- - cp1258
- - ibm-5354
- - ibm-5354_P100-1998
- - windows-1258
-x-gsm-03.38-2000
- - gsm-03.38-2000
- - GSM0338
-x-ibm-1383_P110-1999
- - ibm-eucCN
- - ibm-1383
- - hp15CN
- - cp1383
- - ibm-1383_P110-1999
- - 1383
- - ibm-1383_VPUA
-x-IMAP-mailbox-name
- - IMAP-mailbox-name
-x-iscii-be
- - iscii-bng
- - windows-57003
- - windows-57006
- - x-iscii-as
- - x-iscii-be
-x-iscii-de
- - ibm-4902
- - iscii-dev
- - windows-57002
- - x-iscii-de
-x-iscii-gu
- - windows-57010
- - x-iscii-gu
- - iscii-guj
-x-iscii-ka
- - windows-57008
- - iscii-knd
- - x-iscii-ka
-x-iscii-ma
- - iscii-mlm
- - windows-57009
- - x-iscii-ma
-x-iscii-or
- - iscii-ori
- - windows-57007
- - x-iscii-or
-x-iscii-pa
- - iscii-gur
- - windows-57011
- - x-iscii-pa
-x-iscii-ta
- - x-iscii-ta
- - windows-57004
- - iscii-tml
-x-iscii-te
- - windows-57005
- - x-iscii-te
- - iscii-tlg
-x-iso-8859_11-2001
- - ISO-8859-11
- - iso-8859_11-2001
- - thai8
-x-UTF16_OppositeEndian
- - UTF16_OppositeEndian
-x-UTF16_PlatformEndian
- - UTF16_PlatformEndian
-x-UTF32_OppositeEndian
- - UTF32_OppositeEndian
-x-UTF32_PlatformEndian
- - UTF32_PlatformEndian
- */
-}
diff --git a/luni/src/test/java/tests/api/java/nio/charset/Charset_macintosh.java b/luni/src/test/java/tests/api/java/nio/charset/Charset_macintosh.java
deleted file mode 100644
index 9427d62..0000000
--- a/luni/src/test/java/tests/api/java/nio/charset/Charset_macintosh.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.nio.charset;
-
-import dalvik.annotation.AndroidOnly;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-
-import junit.framework.TestCase;
-
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.CharacterCodingException;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.nio.charset.CharsetEncoder;
-import java.nio.charset.CodingErrorAction;
-
-@AndroidOnly("icu")
-public class Charset_macintosh extends Charset_AbstractTest {
-
- @Override
- protected void setUp() throws Exception {
- charsetName = "macintosh";
-
- testChars = theseChars(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-160, 161, 162, 163, 165, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 180,
-181, 182, 183, 184, 186, 187, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200,
-201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218,
-219, 220, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236,
-237, 238, 239, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 255,
-305, 338, 376, 710, 937, 8211, 8249, 8364, 8482, 8706, 8747, 8800, 9674, 63743, 64257
- });
-
- testBytes = theseBytes(new int[]{
-0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
-16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
-80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
-96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
-112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127,
-202, 193, 162, 163, 180, 164, 172, 169, 187, 199, 194, 168, 248, 161, 177, 171,
-181, 166, 225, 252, 188, 200, 192, 203, 231, 229, 204, 128, 129, 174, 130, 233,
-131, 230, 232, 237, 234, 235, 236, 132, 241, 238, 239, 205, 133, 175, 244, 242,
-243, 134, 167, 136, 135, 137, 139, 138, 140, 190, 141, 143, 142, 144, 145, 147,
-146, 148, 149, 150, 152, 151, 153, 155, 154, 214, 191, 157, 156, 158, 159, 216,
-245, 206, 217, 246, 189, 208, 220, 219, 170, 182, 186, 173, 215, 240, 222
- });
-
- super.setUp();
- }
-
-}
diff --git a/luni/src/test/java/tests/api/java/util/AllTests.java b/luni/src/test/java/tests/api/java/util/AllTests.java
index 71ca767..fe1c93d 100644
--- a/luni/src/test/java/tests/api/java/util/AllTests.java
+++ b/luni/src/test/java/tests/api/java/util/AllTests.java
@@ -64,7 +64,6 @@ public class AllTests {
suite.addTestSuite(PropertyResourceBundleTest.class);
suite.addTestSuite(RandomTest.class);
suite.addTestSuite(ResourceBundleTest.class);
- suite.addTestSuite(ScannerTest.class);
suite.addTestSuite(SimpleTimeZoneTest.class);
suite.addTestSuite(StackTest.class);
suite.addTestSuite(StringTokenizerTest.class);
diff --git a/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java b/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
index d44be4b..1b360f7 100644
--- a/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
+++ b/luni/src/test/java/tests/api/java/util/GregorianCalendarTest.java
@@ -785,8 +785,7 @@ public class GregorianCalendarTest extends junit.framework.TestCase {
g = new GregorianCalendar(TimeZone.getTimeZone("Europe/London"),
new Locale("fr", "CA"));
minimalDaysInFirstWeek = g.getMinimalDaysInFirstWeek();
- // Android's locale data says 4 but the RI says 1
- assertTrue(minimalDaysInFirstWeek == 4 || minimalDaysInFirstWeek == 1);
+ assertEquals(4, minimalDaysInFirstWeek); // RI returns 1 here
}
/**
diff --git a/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java b/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
index 83cb5c7..a9f5082 100644
--- a/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
+++ b/luni/src/test/java/tests/api/java/util/ResourceBundleTest.java
@@ -18,34 +18,25 @@
package tests.api.java.util;
import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;
-
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.security.Permission;
import java.util.Enumeration;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.StringTokenizer;
import java.util.Vector;
-
import tests.api.java.util.support.B;
import tests.support.resource.Support_Resources;
@TestTargetClass(ResourceBundle.class)
public class ResourceBundleTest extends junit.framework.TestCase {
- SecurityManager sm = new SecurityManager() {
-
- @Override
- public void checkPermission(Permission perm) {
- }
- };
/**
* @tests java.util.ResourceBundle#getBundle(java.lang.String,
@@ -64,22 +55,20 @@ public class ResourceBundleTest extends junit.framework.TestCase {
Locale.setDefault(new Locale("en", "US"));
bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "VAR"));
- assertEquals("Wrong bundle fr_FR_VAR", "frFRVARValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle fr_FR_VAR", "frFRVARValue4", bundle.getString("parent4"));
+
bundle = ResourceBundle.getBundle(name, new Locale("fr", "FR", "v1"));
- assertEquals("Wrong bundle fr_FR_v1",
- "frFRValue4", bundle.getString("parent4"));
+ assertEquals("Wrong bundle fr_FR_v1", "frFRValue4", bundle.getString("parent4"));
+
bundle = ResourceBundle.getBundle(name, new Locale("fr", "US", "VAR"));
- assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4"));
+
bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "VAR"));
- assertEquals("Wrong bundle de_FR_var", "enUSValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle de_FR_var", "enUSValue4", bundle.getString("parent4"));
Locale.setDefault(new Locale("fr", "FR", "VAR"));
bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "v1"));
- assertEquals("Wrong bundle de_FR_var 2", "frFRVARValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle de_FR_var 2", "frFRVARValue4", bundle.getString("parent4"));
Locale.setDefault(new Locale("de", "US"));
bundle = ResourceBundle.getBundle(name, new Locale("de", "FR", "var"));
@@ -340,13 +329,13 @@ public class ResourceBundleTest extends junit.framework.TestCase {
assertEquals("Wrong value parent3",
"frFRValue3", (String)bundle.getObject("parent3"));
assertEquals("Wrong value parent2",
- "frValue2", (String)bundle.getObject("parent2"));
+ "frValue2", (String) bundle.getObject("parent2"));
assertEquals("Wrong value parent1",
"parentValue1", (String)bundle.getObject("parent1"));
assertEquals("Wrong value child3",
"frFRVARChildValue3", (String)bundle.getObject("child3"));
assertEquals("Wrong value child2",
- "frFRVARChildValue2", (String)bundle.getObject("child2"));
+ "frFRVARChildValue2", (String) bundle.getObject("child2"));
assertEquals("Wrong value child1",
"frFRVARChildValue1", (String)bundle.getObject("child1"));
assertEquals("Wrong value IntegerVal",
@@ -427,28 +416,27 @@ public class ResourceBundleTest extends junit.framework.TestCase {
Locale.setDefault(new Locale("en", "US"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("enUSValue4", bundle.getString("parent4")
- );
+ assertEquals("enUSValue4", bundle.getString("parent4"));
+
Locale.setDefault(new Locale("fr", "FR", "v1"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("Wrong bundle fr_FR_v1",
- "frFRValue4", bundle.getString("parent4"));
+ assertEquals("Wrong bundle fr_FR_v1", "frFRValue4", bundle.getString("parent4"));
+
Locale.setDefault(new Locale("fr", "US", "VAR"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle fr_US_var", "frValue4", bundle.getString("parent4"));
+
Locale.setDefault(new Locale("de", "FR", "VAR"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("Wrong bundle de_FR_var", "parentValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle de_FR_var", "parentValue4", bundle.getString("parent4"));
+
Locale.setDefault(new Locale("de", "FR", "v1"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4"));
+
Locale.setDefault(new Locale("de", "FR", "var"));
bundle = ResourceBundle.getBundle(name);
- assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4")
- );
+ assertEquals("Wrong bundle de_FR_var 2", "parentValue4", bundle.getString("parent4"));
try {
ResourceBundle.getBundle(null);
@@ -463,11 +451,7 @@ public class ResourceBundleTest extends junit.framework.TestCase {
} catch (MissingResourceException ee) {
//expected
}
- }
-
- protected void setUp() {
- }
- protected void tearDown() {
+ Locale.setDefault(defLocale);
}
}
diff --git a/luni/src/test/java/tests/api/java/util/ScannerTest.java b/luni/src/test/java/tests/api/java/util/ScannerTest.java
deleted file mode 100644
index 5587a42..0000000
--- a/luni/src/test/java/tests/api/java/util/ScannerTest.java
+++ /dev/null
@@ -1,6918 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.api.java.util;
-
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.KnownFailure;
-
-import java.io.Closeable;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PipedInputStream;
-import java.io.StringReader;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.nio.CharBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.ReadableByteChannel;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.nio.charset.Charset;
-import java.util.Arrays;
-import java.util.InputMismatchException;
-import java.util.Locale;
-import java.util.NoSuchElementException;
-import java.util.Scanner;
-import java.util.regex.MatchResult;
-import java.util.regex.Pattern;
-
-import tests.support.Support_Locale;
-import tests.support.Support_PortManager;
-
-import junit.framework.TestCase;
-
-@TestTargetClass(Scanner.class)
-public class ScannerTest extends TestCase {
- static final boolean disableRIBugs = false;
-
- private Scanner s;
-
- private ServerSocket server;
-
- private SocketAddress address;
-
- private SocketChannel client;
-
- private Socket serverSocket;
-
- private OutputStream os;
-
- private static class MockCloseable implements Closeable, Readable {
-
- public void close() throws IOException {
- throw new IOException();
- }
-
- public int read(CharBuffer cb) throws IOException {
- throw new EOFException();
- }
-
- }
-
- /**
- * @tests java.util.Scanner#Scanner(File)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.io.File.class}
- )
- public void test_ConstructorLjava_io_File() throws IOException {
- File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- s = new Scanner(tmpFile);
- assertNotNull(s);
- s.close();
- assertTrue(tmpFile.delete());
-
- try {
- s = new Scanner(tmpFile);
- fail("should throw FileNotFoundException");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- FileOutputStream fos = new FileOutputStream(tmpFile);
- fos.write("test".getBytes());
-
- s = new Scanner(tmpFile);
- tmpFile.delete();
-
- // Scanner(File = null)
- try {
- s = new Scanner((File) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // TODO: test if the default charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(File, String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.io.File.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_FileLjava_lang_String()
- throws IOException {
- File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- s = new Scanner(tmpFile, Charset.defaultCharset().name());
- assertNotNull(s);
- s.close();
- assertTrue(tmpFile.delete());
-
- try {
- s = new Scanner(tmpFile, Charset.defaultCharset().name());
- fail("should throw FileNotFoundException");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- try {
- s = new Scanner(tmpFile, null);
- fail("should throw FileNotFoundException");
- } catch (FileNotFoundException e) {
- // expected
- }
-
- tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- try {
- s = new Scanner(tmpFile, "invalid charset");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- //fail on RI. File is opened but not closed when exception is thrown on
- // RI.
- assertTrue(tmpFile.delete());
-
- // Scanner(File = null, Charset = null)
- try {
- s = new Scanner((File) null, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // Scanner(File = null, Charset = UTF-8)
- try {
- s = new Scanner((File) null, "UTF-8");
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // Scanner(File = null, Charset = invalid)
- try {
- s = new Scanner((File) null, "invalid");
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // Scanner(File, Charset = null)
- try {
- File f = File.createTempFile("test", ".tmp");
- s = new Scanner(f, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // TODO: test if the specified charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(InputStream)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.io.InputStream.class}
- )
- public void test_ConstructorLjava_io_InputStream() {
- s = new Scanner(new PipedInputStream());
- assertNotNull(s);
- s.close();
-
- // Scanner(InputStream)
- try {
- s = new Scanner((InputStream) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // TODO: test if the default charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(InputStream, String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.io.InputStream.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_io_InputStreamLjava_lang_String() {
- s = new Scanner(new PipedInputStream(), Charset.defaultCharset().name());
- assertNotNull(s);
- s.close();
-
- try {
- s = new Scanner((PipedInputStream) null, "invalid charset");
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- s = new Scanner(new PipedInputStream(), null);
- fail("should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- s = new Scanner(new PipedInputStream(), "invalid charset");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- // TODO: test if the specified charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(Readable)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.lang.Readable.class}
- )
- public void test_ConstructorLjava_lang_Readable() {
- s = new Scanner(new StringReader("test string"));
- assertNotNull(s);
- s.close();
-
- // Scanner(Readable)
- try {
- s = new Scanner((Readable) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.Scanner#Scanner(ReadableByteChannel)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.nio.channels.ReadableByteChannel.class}
- )
- public void test_ConstructorLjava_nio_channels_ReadableByteChannel()
- throws IOException {
- File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- FileChannel fc = new FileOutputStream(tmpFile).getChannel();
- s = new Scanner(fc);
- assertNotNull(s);
- s.close();
- assertTrue(tmpFile.delete());
-
- // Scanner(ReadableByteChannel)
- try {
- s = new Scanner((ReadableByteChannel) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // TODO: test if the default charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(ReadableByteChannel, String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.nio.channels.ReadableByteChannel.class, java.lang.String.class}
- )
- public void test_ConstructorLjava_nio_channels_ReadableByteChannelLjava_lang_String()
- throws IOException {
- File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- FileChannel fc = new FileOutputStream(tmpFile).getChannel();
- s = new Scanner(fc, Charset.defaultCharset().name());
- assertNotNull(s);
- s.close();
-
- fc = new FileOutputStream(tmpFile).getChannel();
- try {
- s = new Scanner(fc, "invalid charset");
- fail("should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- fc.close();
- assertTrue(tmpFile.delete());
-
- // Scanner(ReadableByteChannel = null, Charset = null)
- try {
- s = new Scanner((ReadableByteChannel) null, null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // Scanner(ReadableByteChannel = null, Charset = invalid)
- try {
- s = new Scanner((ReadableByteChannel) null, "invalid");
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // Scanner(ReadableByteChannel, Charset = null)
- try {
- s = new Scanner(fc, null);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- // TODO: test if the specified charset is used.
- }
-
- /**
- * @tests java.util.Scanner#Scanner(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.lang.String.class}
- )
- public void test_ConstructorLjava_lang_String() {
- s = new Scanner("test string");
- assertNotNull(s);
- s.close();
-
- // Scanner(String)
- try {
- s = new Scanner((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @tests java.util.Scanner#close()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "close",
- args = {}
- )
- public void test_close() throws IOException {
- File tmpFile = File.createTempFile("TestFileForScanner", ".tmp");
- FileOutputStream fos = new FileOutputStream(tmpFile);
- FileChannel fc = fos.getChannel();
- s = new Scanner(fc);
-
- // Write out a int before the scanner is closed, should be OK.
- fos.write(12);
-
- s.close();
- assertFalse(fc.isOpen());
-
- // Write out a int after the scanner is closed, IOException should be
- // thrown out.
- try {
- fos.write(12);
- fail("Should throw IOException");
- } catch (IOException e) {
- // expected
- }
-
- s.close(); // no exception should be thrown
- assertTrue(tmpFile.delete());
- }
-
- /**
- * @tests java.util.Scanner#ioException()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "ioException",
- args = {}
- )
- public void test_ioException() throws IOException {
- MockCloseable mc = new MockCloseable();
- s = new Scanner(mc);
- assertNull(s.ioException()); // No operation, no exception
-
- s.close(); // IOException should be cached
- assertNotNull(s.ioException());
- assertTrue(s.ioException() instanceof IOException);
- }
-
- /**
- * @tests java.util.Scanner#delimiter()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "delimiter",
- args = {}
- )
- public void test_delimiter() {
- s = new Scanner("test");
- Pattern pattern = s.delimiter();
- assertEquals("\\p{javaWhitespace}+", pattern.toString());
- }
-
- /**
- * @tests java.util.Scanner#useDelimiter(Pattern)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "useDelimiter",
- args = {java.util.regex.Pattern.class}
- )
- public void test_useDelimiter_LPattern() {
- s = new Scanner("test");
- s.useDelimiter(Pattern.compile("\\w+"));
- assertEquals("\\w+", s.delimiter().toString());
-
- s = new Scanner("test");
- s.useDelimiter((Pattern) null);
- assertNull(s.delimiter());
- }
-
- /**
- * @tests java.util.Scanner#useDelimiter(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "useDelimiter",
- args = {java.lang.String.class}
- )
- public void test_useDelimiter_String() {
- s = new Scanner("test");
- try {
- s.useDelimiter((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- s = new Scanner("test");
- s.useDelimiter("\\w+");
- assertEquals("\\w+", s.delimiter().toString());
- }
-
- /**
- * @tests java.util.Scanner#locale()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "locale",
- args = {}
- )
- public void test_locale() {
- s = new Scanner("test");
- assertEquals(Locale.getDefault(), s.locale());
- }
-
- /**
- * @tests java.util.Scanner#useLocale(Locale)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "useLocale",
- args = {java.util.Locale.class}
- )
- public void test_useLocale_LLocale() {
- s = new Scanner("test");
- try {
- s.useLocale(null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- s.useLocale(new Locale("test", "test"));
- assertEquals(new Locale("test", "test"), s.locale());
- }
-
- /**
- * @tests java.util.Scanner#radix()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "radix",
- args = {}
- )
- public void test_radix() {
- s = new Scanner("test");
- assertEquals(10, s.radix());
- }
-
- /**
- * @tests java.util.Scanner#useRadix()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "useRadix",
- args = {int.class}
- )
- public void test_useRadix_I() {
- s = new Scanner("test");
- try {
- s.useRadix(Character.MIN_RADIX - 1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- try {
- s.useRadix(Character.MAX_RADIX + 1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
- s.useRadix(11);
- assertEquals(11, s.radix());
- }
-
- /**
- * @tests java.util.Scanner#remove()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "remove",
- args = {}
- )
- public void test_remove() {
- s = new Scanner("aab*b*").useDelimiter("\\*");
- try {
- s.remove();
- fail("should throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- //Expected
- }
- }
-
- /**
- * @tests java.util.Scanner#match()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "match",
- args = {}
- )
- public void test_match() {
- MatchResult result ;
- s = new Scanner("1 2 ");
- try {
- s.match();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
- assertEquals("1", s.next());
- assertEquals("2", s.next());
- result = s.match();
- assertEquals(2, result.start());
- assertEquals(3, result.end());
- assertEquals(2, result.start(0));
- assertEquals(3, result.end(0));
- assertEquals("2", result.group());
- assertEquals("2", result.group(0));
- assertEquals(0, result.groupCount());
- try {
- result.start(1);
- fail("should throw IndexOutOfBoundsException");
- } catch (IndexOutOfBoundsException e) {
- // Expected
- }
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- s.match();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
-
- s = new Scanner("True faLse");
- try {
- s.match();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
- assertTrue(s.nextBoolean());
- result = s.match();
- assertEquals(0, result.start());
- assertEquals(4, result.end());
- assertEquals(0, result.start(0));
- assertEquals(4, result.end(0));
- assertEquals("True", result.group());
- assertEquals(0, result.groupCount());
- assertFalse(s.nextBoolean());
- try {
- s.nextBoolean();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- try {
- s.match();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
-
- s = new Scanner("True faLse");
- assertTrue(s.nextBoolean());
- result = s.match();
- assertEquals(0, result.start());
- assertEquals(4, result.end());
- assertEquals(0, result.start(0));
- assertEquals(4, result.end(0));
- assertEquals("True", result.group());
- assertEquals(0, result.groupCount());
- s.close();
- try {
- s.nextBoolean();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
- result = s.match();
- assertEquals(0, result.start());
- assertEquals(4, result.end());
- assertEquals(0, result.start(0));
- assertEquals(4, result.end(0));
- assertEquals("True", result.group());
- assertEquals(0, result.groupCount());
-
- s = new Scanner("True fase");
- assertTrue(s.nextBoolean());
- assertEquals(0, result.groupCount());
- try {
- s.nextBoolean();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- try {
- s.match();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // Expected
- }
-
- s = new Scanner("True fase");
- assertTrue(s.nextBoolean());
- try {
- s.next((Pattern)null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- result = s.match();
- assertEquals(0, result.start());
- assertEquals(4, result.end());
- assertEquals(0, result.start(0));
- assertEquals(4, result.end(0));
- assertEquals("True", result.group());
- assertEquals(0, result.groupCount());
-
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#next()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "next",
- args = {}
- )
- public void test_next() throws IOException {
- // use special delimiter
- s = new Scanner("1**2").useDelimiter("\\*");
- assertEquals("1", s.next());
- assertEquals("", s.next());
- assertEquals("2", s.next());
-
- s = new Scanner(" \t 1 \t 2").useDelimiter("\\s*");
- assertEquals("1", s.next());
- assertEquals("2", s.next());
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("a").useDelimiter("a?");
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("aa").useDelimiter("a?");
- assertEquals("", s.next());
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
-
- s = new Scanner("word( )test( )").useDelimiter("\\( \\)");
- assertEquals("word", s.next());
- assertEquals("test", s.next());
-
- s = new Scanner("? next ").useDelimiter("( )");
- assertEquals("?", s.next());
- assertEquals("next", s.next());
- assertEquals("", s.next());
-
- s = new Scanner("word1 word2 ");
- assertEquals("word1", s.next());
- assertEquals("word2", s.next());
- // test boundary case
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // just delimiter exists in this scanner
- s = new Scanner(" ");
- try {
- s.next();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // nothing exists in this scanner
- s = new Scanner("");
- try {
- s.next();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // no delimiter exists in this scanner
- s = new Scanner("test");
- assertEquals("test", s.next());
-
- // input resourse starts with delimiter
- s = new Scanner(" test");
- assertEquals("test", s.next());
-
- // input resource ends with delimiter
- s = new Scanner(" test ");
- assertEquals("test", s.next());
-
- // Harmony uses 1024 as default buffer size,
- // What if a sentence can not be read in all in once.
- StringBuilder longSentence = new StringBuilder(1025);
- for (int i = 0; i < 11; i++) {
- longSentence.append(" ");
- }
- for (int i = 11; i < 1026; i++) {
- longSentence.append("a");
- }
- s = new Scanner(longSentence.toString());
- assertEquals(longSentence.toString().trim(), s.next());
-
- s = new Scanner(" test test");
- assertEquals("test", s.next());
- assertEquals("test", s.next());
-
- // What if use a delimiter of length 0.
- s = new Scanner("test\ntest").useDelimiter(Pattern.compile("^",
- Pattern.MULTILINE));
- assertEquals("test\n", s.next());
- assertEquals("test", s.next());
-
- s = new Scanner("").useDelimiter(Pattern.compile("^",
- Pattern.MULTILINE));
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("").useDelimiter(Pattern.compile("^*",
- Pattern.MULTILINE));
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("test\ntest").useDelimiter(Pattern.compile("^*",
- Pattern.MULTILINE));
- assertEquals("t", s.next());
- assertEquals("e", s.next());
-
- s = new Scanner("\ntest\ntest").useDelimiter(Pattern.compile("$",
- Pattern.MULTILINE));
- assertEquals("\ntest", s.next());
- assertEquals("\ntest", s.next());
-
- // test socket inputStream
- // Harmony uses 1024 as default buffer size,
- // what if the leading delimiter is larger than 1023
- for (int i = 0; i < 1024; i++) {
- os.write(" ".getBytes());
- }
- os.write(" 1 2 ".getBytes());
- s = new Scanner(client);
- assertEquals("1", s.next());
- assertEquals("2", s.next());
- os.write(" 1 2".getBytes());
- serverSocket.close();
- assertEquals("1", s.next());
- assertEquals("2", s.next());
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s.close();
- try {
- s.next();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#next(Pattern)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "next",
- args = {java.util.regex.Pattern.class}
- )
- public void test_nextLPattern() throws IOException {
- Pattern pattern;
- s = new Scanner("aab*2*").useDelimiter("\\*");
- pattern = Pattern.compile("a*b");
- assertEquals("aab", s.next(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word ? ");
- pattern = Pattern.compile("\\w+");
- assertEquals("word", s.next(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word1 word2 ");
- pattern = Pattern.compile("\\w+");
- assertEquals("word1", s.next(pattern));
- assertEquals("word2", s.next(pattern));
- // test boundary case
- try {
- s.next(pattern);
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // test socket inputStream
-
- os.write("aab 2".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- pattern = Pattern.compile("a*b");
- assertEquals("aab", s.next(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s.close();
- try {
- s.next(pattern);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#next(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "next",
- args = {java.lang.String.class}
- )
- public void test_nextLString() throws IOException {
- s = new Scanner("b*a*").useDelimiter("\\*");
- assertEquals("b", s.next("a*b"));
- try {
- s.next("a*b");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word ? ");
- assertEquals("word", s.next("\\w+"));
- try {
- s.next("\\w+");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word1 next ");
- assertEquals("word1", s.next("\\w+"));
- assertEquals("next", s.next("\\w+"));
- // test boundary case
- try {
- s.next("\\w+");
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // test socket inputStream
- os.write("aab 2".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- assertEquals("aab", s.next("a*b"));
- try {
- s.next("a*b");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s.close();
- try {
- s.next("a*b");
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextBoolean()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextBoolean",
- args = {}
- )
- public void test_nextBoolean() throws IOException {
- // case insensitive
- s = new Scanner("TRue");
- assertTrue(s.nextBoolean());
-
- s = new Scanner("tRue false");
- assertTrue(s.nextBoolean());
- assertFalse(s.nextBoolean());
- try {
- s.nextBoolean();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("true1");
- try {
- s.nextBoolean();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- try {
- s = new Scanner("");
- s.nextBoolean();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // test socket inputStream
- os.write("true false".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- assertTrue(s.nextBoolean());
- assertFalse(s.nextBoolean());
-
- // ues '*' as delimiter
- s = new Scanner("true**false").useDelimiter("\\*");
- assertTrue(s.nextBoolean());
- try {
- s.nextBoolean();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("false( )").useDelimiter("\\( \\)");
- assertFalse(s.nextBoolean());
-
- s.close();
- try {
- s.nextBoolean();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextInt(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextInt",
- args = {int.class}
- )
- public void test_nextIntI() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextInt(10));
- assertEquals(456, s.nextInt(10));
- try {
- s.nextInt(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertEquals(38, s.nextInt(5));
- try {
- s.nextInt(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt(10));
- assertEquals(23456, s.nextInt(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt(10));
- assertEquals(23456, s.nextInt(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextInt(10));
- try {
- s.nextInt(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertEquals(162, s.nextInt(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt(10));
- assertEquals(23456, s.nextInt(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextInt(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextInt(10));
-
- s = new Scanner("E3456");
- assertEquals(930902, s.nextInt(16));
- // The following test case fails on RI, because RI does not support
- // letter as leading digit
- if (!disableRIBugs) {
- s = new Scanner("E3,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(930902, s.nextInt(16));
- }
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt(10));
-
- /*
- * There are three types of negative prefix all in all. '' '-' '(' There
- * are three types of negative suffix all in all. '' '-' ')' '(' and ')'
- * must be used togethor. Prefix '-' and suffix '-' must be used
- * exclusively.
- */
-
- /*
- * According to Integer regular expression: Integer :: = ( [-+]? (*
- * Numeral ) ) | LocalPositivePrefix Numeral LocalPositiveSuffix |
- * LocalNegativePrefix Numeral LocalNegativeSuffix 123- should be
- * recognized by scanner with locale ar_AE, (123) shouble be recognized
- * by scanner with locale mk_MK. But this is not the case on RI.
- */
- if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) {
- s = new Scanner("-123 123- -123-");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextInt(10));
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertEquals(-123, s.nextInt(10));
- }
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- }
-
- // locale dependent test, bug 1943269
- if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK")})) {
- s = new Scanner("-123 123- (123)");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextInt(10));
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- // Skip the un-recognizable token 123-.
- assertEquals("123-", s.next());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertEquals(-123, s.nextInt(10));
-
- // If the parameter radix is illegal, the following test cases fail on
- // RI
- try {
- s.nextInt(Character.MIN_RADIX - 1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- try {
- s.nextInt(Character.MAX_RADIX + 1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
- }
-
- s.close();
- try {
- s.nextInt(10);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextInt()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextInt",
- args = {}
- )
- public void test_nextInt() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.CHINESE, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextInt());
- assertEquals(456, s.nextInt());
- try {
- s.nextInt();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertEquals(38, s.nextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt());
- assertEquals(23456, s.nextInt());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt());
- assertEquals(23456, s.nextInt());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextInt());
- s.useRadix(5);
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertEquals(162, s.nextInt());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextInt());
- assertEquals(23456, s.nextInt());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextInt());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextInt());
-
- s = new Scanner("E3456");
- s.useRadix(16);
- assertEquals(930902, s.nextInt());
-
- // The following test case fails on RI, because RI does not support
- // letter as leading digit
- s = new Scanner("E3,456");
- s.useLocale(Locale.ENGLISH);
- s.useRadix(16);
- if (!disableRIBugs) {
- assertEquals(930902, s.nextInt());
- }
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextInt());
-
- /*
- * There are three types of negative prefix all in all. '' '-' '(' There
- * are three types of negative suffix all in all. '' '-' ')' '(' and ')'
- * must be used togethor. Prefix '-' and suffix '-' must be used
- * exclusively.
- */
-
- /*
- * According to Integer regular expression: Integer :: = ( [-+]? (*
- * Numeral ) ) | LocalPositivePrefix Numeral LocalPositiveSuffix |
- * LocalNegativePrefix Numeral LocalNegativeSuffix 123- should be
- * recognized by scanner with locale ar_AE, (123) shouble be recognized
- * by scanner with locale mk_MK. But this is not the case on RI.
- */
- if (Support_Locale.areLocalesAvailable(new Locale[] {new Locale("ar", "AE")})) {
- s = new Scanner("-123 123- -123-");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextInt());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertEquals(-123, s.nextInt());
- }
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- }
-
- // locale dependent test, bug 1943269
- if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK")})) {
- s = new Scanner("-123 123- (123)");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- // Skip the un-recognizable token 123-.
- assertEquals("123-", s.next());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertEquals(-123, s.nextInt());
- }
- }
-
- s.close();
- try {
- s.nextInt();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextByte(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextByte",
- args = {int.class}
- )
- public void test_nextByteI() throws IOException {
- s = new Scanner("123 126");
- assertEquals(123, s.nextByte(10));
- assertEquals(126, s.nextByte(10));
- try {
- s.nextByte(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 126");
- assertEquals(38, s.nextByte(5));
- try {
- s.nextByte(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("1234");
- try {
- s.nextByte(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 12\u0666");
- assertEquals(102, s.nextByte(10));
- try {
- s.nextByte(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertEquals(126, s.nextByte(10));
-
- s = new Scanner("012");
- assertEquals(12, s.nextByte(10));
-
- s = new Scanner("E");
- assertEquals(14, s.nextByte(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("100");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("1\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("1\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextByte(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextByte(10));
-
- s.close();
- try {
- s.nextByte(10);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextByte",
- args = {}
- )
- public void test_nextByte() throws IOException {
- s = new Scanner("123 126");
- assertEquals(123, s.nextByte());
- assertEquals(126, s.nextByte());
- try {
- s.nextByte();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 126");
- s.useRadix(5);
- assertEquals(38, s.nextByte());
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("1234");
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 12\u0666");
- assertEquals(102, s.nextByte());
- s.useRadix(5);
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertEquals(126, s.nextByte());
-
- s = new Scanner("012");
- assertEquals(12, s.nextByte());
-
- s = new Scanner("E");
- s.useRadix(16);
- assertEquals(14, s.nextByte());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("100");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte());
-
- s = new Scanner("1\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte());
-
- s = new Scanner("1\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(100, s.nextByte());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextByte());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextByte());
-
- s.close();
- try {
- s.nextByte();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextFloat()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextFloat",
- args = {}
- )
- public void test_nextFloat() throws IOException {
- Locale[] requiredLocales = {Locale.ENGLISH, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)123.0, s.nextFloat());
- assertEquals((float)456.0, s.nextFloat());
- assertEquals((float)123.4, s.nextFloat());
- assertEquals((float)0.123, s.nextFloat());
- try {
- s.nextFloat();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)123.4, s.nextFloat());
- assertEquals((float)-456.7, s.nextFloat());
- assertEquals((float)123456.789, s.nextFloat());
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)1.234E12, s.nextFloat());
- assertEquals((float)-4.567E14, s.nextFloat());
- assertEquals((float)1.23456789E-5, s.nextFloat());
-
- s = new Scanner("NaN Infinity -Infinity");
- assertEquals(Float.NaN, s.nextFloat());
- assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
- assertEquals(Float.NEGATIVE_INFINITY, s.nextFloat());
-
- String str=String.valueOf(Float.MAX_VALUE*2);
- s=new Scanner(str);
- assertEquals(Float.POSITIVE_INFINITY,s.nextFloat());
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)23456.0, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertEquals((float)23.456, s.nextFloat());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)23.456, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertEquals((float)23456.0, s.nextFloat());
-
- s = new Scanner("23,456.7 23.456,7");
- s.useLocale(Locale.ENGLISH);
- assertEquals((float)23456.7, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertEquals((float)23456.7, s.nextFloat());
-
- // locale dependent test, bug 1943269
- // Note: although "123.4-" is the correct localized form for ar_AE, the
- // RI only accepts "-123.4".
- if (false) {
- s = new Scanner("-123.4 123.4- -123.4-");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals((float)-123.4, s.nextFloat());
- //The following test case fails on RI
- if (!disableRIBugs) {
- assertEquals((float)-123.4, s.nextFloat());
- }
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- }
-
- // locale dependent test, bug 1943269
- if (Support_Locale.areLocalesAvailable(new Locale[] { new Locale("mk", "MK") })) {
- s = new Scanner("(123) 123- -123");
- s.useLocale(new Locale("mk", "MK"));
- if (!disableRIBugs) {
- assertEquals((float)-123.0, s.nextFloat());
- }
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- // Skip the un-recognizable token 123-.
- if (!disableRIBugs) {
- assertEquals("123-", s.next());
- assertEquals((float)-123.0, s.nextFloat());
- }
- }
-
- s.close();
- try {
- s.nextFloat();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextBigInteger(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextBigInteger",
- args = {int.class}
- )
- public void test_nextBigIntegerI() throws IOException {
- s = new Scanner("123 456");
- assertEquals(new BigInteger("123"), s.nextBigInteger(10));
- assertEquals(new BigInteger("456"), s.nextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertEquals(new BigInteger("38"), s.nextBigInteger(5));
- try {
- s.nextBigInteger(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(new BigInteger("102"), s.nextBigInteger(10));
- try {
- s.nextBigInteger(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertEquals(new BigInteger("162"), s.nextBigInteger(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
-
- s = new Scanner("E34");
- assertEquals(new BigInteger("3636"), s.nextBigInteger(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
-
- s.close();
- try {
- s.nextBigInteger(10);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextBigInteger()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextBigInteger",
- args = {}
- )
- public void test_nextBigInteger() throws IOException {
- s = new Scanner("123 456");
- assertEquals(new BigInteger("123"), s.nextBigInteger());
- assertEquals(new BigInteger("456"), s.nextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertEquals(new BigInteger("38"), s.nextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(new BigInteger("102"), s.nextBigInteger());
- s.useRadix(5);
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertEquals(new BigInteger("162"), s.nextBigInteger());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(new BigInteger("3456"), s.nextBigInteger());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigInteger("3456"), s.nextBigInteger());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertEquals(new BigInteger("3636"), s.nextBigInteger());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(new BigInteger("-123"), s.nextBigInteger());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(new BigInteger("-123"), s.nextBigInteger());
-
- s.close();
- try {
- s.nextBigInteger();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextShort(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextShort",
- args = {int.class}
- )
- public void test_nextShortI() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.CHINESE, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextShort(10));
- assertEquals(456, s.nextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertEquals(38, s.nextShort(5));
- try {
- s.nextShort(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789");
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort(10));
- assertEquals(23456, s.nextShort(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort(10));
- assertEquals(23456, s.nextShort(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextShort(10));
- try {
- s.nextShort(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertEquals(162, s.nextShort(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort(10));
- assertEquals(23456, s.nextShort(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextShort(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextShort(10));
-
- s = new Scanner("E34");
- assertEquals(3636, s.nextShort(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextShort(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextShort(10));
-
- s.close();
- try {
- s.nextShort(10);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextShort",
- args = {}
- )
- public void test_nextShort() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.CHINESE, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextShort());
- assertEquals(456, s.nextShort());
- try {
- s.nextShort();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertEquals(38, s.nextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789");
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort());
- assertEquals(23456, s.nextShort());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort());
- assertEquals(23456, s.nextShort());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextShort());
- s.useRadix(5);
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertEquals(162, s.nextShort());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextShort());
- assertEquals(23456, s.nextShort());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextShort());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextShort());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertEquals(3636, s.nextShort());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextShort());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextShort());
-
- s.close();
- try {
- s.nextShort();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextLong(int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextLong",
- args = {int.class}
- )
- public void test_nextLongI() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.CHINESE, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextLong(10));
- assertEquals(456, s.nextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertEquals(38, s.nextLong(5));
- try {
- s.nextLong(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextLong(10));
- try {
- s.nextLong(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertEquals(162, s.nextLong(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextLong(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextLong(10));
-
- s = new Scanner("E34");
- assertEquals(3636, s.nextLong(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextLong(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextLong(10));
-
- s.close();
- try {
- s.nextLong(10);
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextLong()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextLong",
- args = {}
- )
- public void test_nextLong() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.CHINESE, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextLong());
- assertEquals(456, s.nextLong());
- try {
- s.nextLong();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertEquals(38, s.nextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong());
- assertEquals(23456, s.nextLong());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong());
- assertEquals(23456, s.nextLong());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextLong());
- s.useRadix(5);
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertEquals(162, s.nextLong());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertEquals(23456, s.nextLong());
- assertEquals(23456, s.nextLong());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertEquals(3456, s.nextLong());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextLong());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertEquals(3636, s.nextLong());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertEquals(-123, s.nextLong());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertEquals(-123, s.nextLong());
-
- s.close();
- try {
- s.nextLong();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNext()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNext",
- args = {}
- )
- public void test_hasNext() throws IOException {
- s = new Scanner("1##2").useDelimiter("\\#");
- assertTrue(s.hasNext());
- assertEquals("1", s.next());
- assertEquals("", s.next());
- assertEquals("2", s.next());
- assertFalse(s.hasNext());
- s.close();
- try {
- s.hasNext();
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("1( )2( )").useDelimiter("\\( \\)");
- assertTrue(s.hasNext());
- assertTrue(s.hasNext());
- assertEquals("1", s.next());
- assertEquals("2", s.next());
-
- s = new Scanner("1 2 ").useDelimiter("( )");
- assertEquals("1", s.next());
- assertEquals("2", s.next());
- assertTrue(s.hasNext());
- assertEquals("", s.next());
-
- s = new Scanner("1\n2 ");
- assertEquals("1", s.next());
- assertTrue(s.hasNext());
- assertEquals("2", s.next());
- assertFalse(s.hasNext());
- // test boundary case
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("1'\n'2 ");
- assertEquals("1'", s.next());
- assertTrue(s.hasNext());
- assertEquals("'2", s.next());
- assertFalse(s.hasNext());
- // test boundary case
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner(" ");
- assertFalse(s.hasNext());
-
- // test socket inputStream
-
- os.write("1 2".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- assertEquals("1", s.next());
- assertTrue(s.hasNext());
- assertEquals("2", s.next());
- assertFalse(s.hasNext());
- try {
- s.next();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNext(Pattern)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNext",
- args = {java.util.regex.Pattern.class}
- )
- public void test_hasNextLPattern() throws IOException {
- Pattern pattern;
- s = new Scanner("aab@2@abb@").useDelimiter("\\@");
- pattern = Pattern.compile("a*b");
- assertTrue(s.hasNext(pattern));
- assertEquals("aab", s.next(pattern));
- assertFalse(s.hasNext(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word ? ");
- pattern = Pattern.compile("\\w+");
- assertTrue(s.hasNext(pattern));
- assertEquals("word", s.next(pattern));
- assertFalse(s.hasNext(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word1 WorD2 ");
- pattern = Pattern.compile("\\w+");
- assertTrue(s.hasNext(pattern));
- assertEquals("word1", s.next(pattern));
- assertTrue(s.hasNext(pattern));
- assertEquals("WorD2", s.next(pattern));
- assertFalse(s.hasNext(pattern));
- try {
- s.next(pattern);
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("word1 WorD2 ");
- pattern = Pattern.compile("\\w+");
- try {
- s.hasNext((Pattern) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- s.close();
- try {
- s.hasNext(pattern);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- // test socket inputStream
- os.write("aab b".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- pattern = Pattern.compile("a+b");
- assertTrue(s.hasNext(pattern));
- assertEquals("aab", s.next(pattern));
- assertFalse(s.hasNext(pattern));
- try {
- s.next(pattern);
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNext(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNext",
- args = {java.lang.String.class}
- )
- public void test_hasNextLString() throws IOException {
- s = new Scanner("aab@2@abb@").useDelimiter("\\@");
- try {
- s.hasNext((String)null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- s = new Scanner("aab*b*").useDelimiter("\\*");
- assertTrue(s.hasNext("a+b"));
- assertEquals("aab", s.next("a+b"));
- assertFalse(s.hasNext("a+b"));
- try {
- s.next("a+b");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.close();
- try {
- s.hasNext("a+b");
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("WORD ? ");
- assertTrue(s.hasNext("\\w+"));
- assertEquals("WORD", s.next("\\w+"));
- assertFalse(s.hasNext("\\w+"));
- try {
- s.next("\\w+");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("word1 word2 ");
- assertEquals("word1", s.next("\\w+"));
- assertEquals("word2", s.next("\\w+"));
- // test boundary case
- try {
- s.next("\\w+");
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // test socket inputStream
-
- os.write("aab 2".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- assertTrue(s.hasNext("a*b"));
- assertEquals("aab", s.next("a*b"));
- assertFalse(s.hasNext("a*b"));
- try {
- s.next("a*b");
- fail("should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextBoolean()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextBoolean",
- args = {}
- )
- public void test_hasNextBoolean() throws IOException {
-
- s = new Scanner("TRue");
- assertTrue(s.hasNextBoolean());
- assertTrue(s.nextBoolean());
-
- s = new Scanner("tRue false");
- assertTrue(s.hasNextBoolean());
- assertTrue(s.nextBoolean());
- assertTrue(s.hasNextBoolean());
- assertFalse(s.nextBoolean());
-
- s = new Scanner("");
- assertFalse(s.hasNextBoolean());
-
- // test socket inputStream
-
- os.write("true false ".getBytes());
- serverSocket.close();
-
- s = new Scanner(client);
- assertTrue(s.hasNextBoolean());
- assertTrue(s.nextBoolean());
-
- // ues '*' as delimiter
- s = new Scanner("true**false").useDelimiter("\\*");
- assertTrue(s.hasNextBoolean());
- assertTrue(s.nextBoolean());
- assertFalse(s.hasNextBoolean());
- try {
- s.nextBoolean();
- fail("should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("false( )").useDelimiter("\\( \\)");
- assertTrue(s.hasNextBoolean());
- assertFalse(s.nextBoolean());
- assertFalse(s.hasNextBoolean());
-
- s.close();
- try {
- s.hasNextBoolean();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextByte(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IllegalStateException checking missed.",
- method = "hasNextByte",
- args = {int.class}
- )
- public void test_hasNextByteI() throws IOException {
- s = new Scanner("123 126");
- assertTrue(s.hasNextByte(10));
- assertEquals(123, s.nextByte(10));
- assertTrue(s.hasNextByte(10));
- assertEquals(126, s.nextByte(10));
- assertFalse(s.hasNextByte(10));
- try {
- s.nextByte(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 126");
- assertTrue(s.hasNextByte(5));
- assertEquals(38, s.nextByte(5));
- assertFalse(s.hasNextByte(5));
- try {
- s.nextByte(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("1234");
- assertFalse(s.hasNextByte(10));
- try {
- s.nextByte(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 12\u0666");
- assertTrue(s.hasNextByte(10));
- assertEquals(102, s.nextByte(10));
- assertFalse(s.hasNextByte(5));
- try {
- s.nextByte(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertTrue(s.hasNextByte(10));
- assertEquals(126, s.nextByte(10));
-
- s = new Scanner("012");
- assertTrue(s.hasNextByte(10));
- assertEquals(12, s.nextByte(10));
-
- s = new Scanner("E");
- assertTrue(s.hasNextByte(16));
- assertEquals(14, s.nextByte(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("100");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte(10));
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("1\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte(10));
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("1\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte(10));
- assertEquals(100, s.nextByte(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextByte(10));
- assertEquals(-123, s.nextByte(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextByte(10));
- assertEquals(-123, s.nextByte(10));
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextByte(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test.",
- method = "hasNextByte",
- args = {int.class}
- )
- public void test_hasNextByteI_cache() throws IOException{
- //regression for HARMONY-2063
- s = new Scanner("123 45");
- assertTrue(s.hasNextByte(8));
- assertEquals(83, s.nextByte());
- assertEquals(45, s.nextByte());
-
- s = new Scanner("123 45");
- assertTrue(s.hasNextByte(10));
- assertTrue(s.hasNextByte(8));
- assertEquals(83, s.nextByte());
- assertEquals(45, s.nextByte());
-
- s = new Scanner("-123 -45");
- assertTrue(s.hasNextByte(8));
- assertEquals(-123, s.nextInt());
- assertEquals(-45, s.nextByte());
-
- s = new Scanner("123 45");
- assertTrue(s.hasNextByte());
- s.close();
- try {
- s.nextByte();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextByte()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextByte",
- args = {}
- )
- public void test_hasNextByte() throws IOException {
- s = new Scanner("123 126");
- assertTrue(s.hasNextByte());
- assertEquals(123, s.nextByte());
- assertTrue(s.hasNextByte());
- assertEquals(126, s.nextByte());
- assertFalse(s.hasNextByte());
- try {
- s.nextByte();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 126");
- s.useRadix(5);
- assertTrue(s.hasNextByte());
- assertEquals(38, s.nextByte());
- assertFalse(s.hasNextByte());
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("1234");
- assertFalse(s.hasNextByte());
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 12\u0666");
- assertTrue(s.hasNextByte());
- assertEquals(102, s.nextByte());
- s.useRadix(5);
- assertFalse(s.hasNextByte());
- try {
- s.nextByte();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertTrue(s.hasNextByte());
- assertEquals(126, s.nextByte());
-
- s = new Scanner("012");
- assertEquals(12, s.nextByte());
-
- s = new Scanner("E");
- s.useRadix(16);
- assertTrue(s.hasNextByte());
- assertEquals(14, s.nextByte());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("100");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte());
- assertEquals(100, s.nextByte());
-
- s = new Scanner("1\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte());
- assertEquals(100, s.nextByte());
-
- s = new Scanner("1\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextByte());
- assertEquals(100, s.nextByte());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextByte());
- assertEquals(-123, s.nextByte());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextByte());
- assertEquals(-123, s.nextByte());
-
- s.close();
- try {
- s.hasNextByte();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextBigInteger(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IllegalStateException checking missed.",
- method = "hasNextBigInteger",
- args = {int.class}
- )
- public void test_hasNextBigIntegerI() throws IOException {
- s = new Scanner("123 456");
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("123"), s.nextBigInteger(10));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("456"), s.nextBigInteger(10));
- assertFalse(s.hasNextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertTrue(s.hasNextBigInteger(5));
- assertEquals(new BigInteger("38"), s.nextBigInteger(5));
- assertFalse(s.hasNextBigInteger(5));
- try {
- s.nextBigInteger(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("102"), s.nextBigInteger(10));
- assertFalse(s.hasNextBigInteger(5));
- try {
- s.nextBigInteger(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("162"), s.nextBigInteger(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("23456"), s.nextBigInteger(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextBigInteger(10));
- try {
- s.nextBigInteger(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("3456"), s.nextBigInteger(10));
-
- s = new Scanner("E34");
- assertTrue(s.hasNextBigInteger(16));
- assertEquals(new BigInteger("3636"), s.nextBigInteger(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("12300"), s.nextBigInteger(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("-123"), s.nextBigInteger(10));
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextBigInteger(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test.",
- method = "hasNextBigInteger",
- args = {int.class}
- )
- public void test_hasNextBigIntegerI_cache() throws IOException {
- //regression for HARMONY-2063
- s = new Scanner("123 123456789123456789");
- assertTrue(s.hasNextBigInteger(16));
- assertEquals(new BigInteger("291"), s.nextBigInteger());
- assertEquals(new BigInteger("123456789123456789"), s.nextBigInteger());
-
- s = new Scanner("123456789123456789 456");
- assertTrue(s.hasNextBigInteger(16));
- assertTrue(s.hasNextBigInteger(10));
- assertEquals(new BigInteger("123456789123456789"), s.nextBigInteger());
- assertEquals(new BigInteger("456"), s.nextBigInteger());
-
- s = new Scanner("-123 -123456789123456789");
- assertTrue(s.hasNextBigInteger(8));
- assertEquals(-123, s.nextShort());
- assertEquals(new BigInteger("-123456789123456789"), s.nextBigInteger());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextBigInteger());
- s.close();
- try {
- s.nextBigInteger();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextBigInteger()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextBigInteger",
- args = {}
- )
- public void test_hasNextBigInteger() throws IOException {
- s = new Scanner("123 456");
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("123"), s.nextBigInteger());
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("456"), s.nextBigInteger());
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("38"), s.nextBigInteger());
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(new BigInteger("102"), s.nextBigInteger());
- s.useRadix(5);
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("162"), s.nextBigInteger());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("23456"), s.nextBigInteger());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextBigInteger());
- try {
- s.nextBigInteger();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("3456"), s.nextBigInteger());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("3456"), s.nextBigInteger());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("3636"), s.nextBigInteger());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("12300"), s.nextBigInteger());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("-123"), s.nextBigInteger());
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextBigInteger());
- assertEquals(new BigInteger("-123"), s.nextBigInteger());
-
- s.close();
- try {
- s.hasNextBigInteger();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextInt(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IllegalStateException checking missed.",
- method = "hasNextInt",
- args = {int.class}
- )
- public void test_hasNextIntI() throws IOException {
- Locale mkLocale = new Locale("mk", "MK");
- Locale arLocale = new Locale("ar", "AE");
- Locale deLocale = new Locale("de", "CH");
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE,
- mkLocale, arLocale, deLocale};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertEquals(123, s.nextInt(10));
- assertTrue(s.hasNextInt(10));
- assertEquals(456, s.nextInt(10));
- assertFalse(s.hasNextInt(10));
- try {
- s.nextInt(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertTrue(s.hasNextInt(5));
- assertEquals(38, s.nextInt(5));
- assertFalse(s.hasNextInt(5));
- try {
- s.nextInt(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- assertFalse(s.hasNextInt(10));
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextInt(10));
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextInt(10));
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextInt(10));
- s.useLocale(deLocale);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextInt(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06662");
- assertTrue(s.hasNextInt(10));
- assertFalse(s.hasNextInt(5));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextInt(10));
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextInt(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextInt(10));
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextInt(10));
- assertEquals(3456, s.nextInt(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextInt(10));
- assertEquals(3456, s.nextInt(10));
-
- s = new Scanner("E3456");
- assertTrue(s.hasNextInt(16));
- assertEquals(930902, s.nextInt(16));
- // The following test case fails on RI, because RI does not support
- // letter as leading digit
- s = new Scanner("E3,456");
- s.useLocale(Locale.ENGLISH);
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt(16));
- assertEquals(930902, s.nextInt(16));
-
- // If parameter radix is illegal, the following test case fails on RI
- try {
- s.hasNextInt(Character.MIN_RADIX - 1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // Expected
- }
- }
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt(10));
- assertEquals(12300, s.nextInt(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt(10));
- assertEquals(12300, s.nextInt(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt(10));
- assertEquals(12300, s.nextInt(10));
-
- /*
- * There are three types of negative prefix all in all. '' '-' '(' There
- * are three types of negative suffix all in all. '' '-' ')' '(' and ')'
- * must be used togethor. Prefix '-' and suffix '-' must be used
- * exclusively.
- */
-
- /*
- * According to Integer regular expression: Integer :: = ( [-+]? (*
- * Numeral ) ) | LocalPositivePrefix Numeral LocalPositiveSuffix |
- * LocalNegativePrefix Numeral LocalNegativeSuffix 123- should be
- * recognized by scanner with locale ar_AE, (123) shouble be recognized
- * by scanner with locale mk_MK. But this is not the case on RI.
- */
- s = new Scanner("-123 123- -123-");
- s.useLocale(arLocale);
- assertTrue(s.hasNextInt(10));
- assertEquals(-123, s.nextInt(10));
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt(10));
- assertEquals(-123, s.nextInt(10));
- }
- assertFalse(s.hasNextInt(10));
- try {
- s.nextInt(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("-123 123- (123)");
- s.useLocale(mkLocale);
- assertTrue(s.hasNextInt(10));
- assertEquals(-123, s.nextInt(10));
- assertFalse(s.hasNextInt(10));
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- // Skip the un-recognizable token 123-.
- assertEquals("123-", s.next());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt(10));
- assertEquals(-123, s.nextInt(10));
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextInt(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test",
- method = "hasNextInt",
- args = {int.class}
- )
- public void test_hasNextIntI_cache() throws IOException {
- //regression for HARMONY-2063
- s = new Scanner("123 456");
- assertTrue(s.hasNextInt(16));
- assertEquals(291, s.nextInt(10));
- assertEquals(456, s.nextInt());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextInt(16));
- assertTrue(s.hasNextInt(8));
- assertEquals(83, s.nextInt());
- assertEquals(456, s.nextInt());
-
- s = new Scanner("-123 -456 -789");
- assertTrue(s.hasNextInt(8));
- assertEquals(-123, s.nextShort());
- assertEquals(-456, s.nextInt());
- assertTrue(s.hasNextShort(16));
- assertEquals(-789, s.nextInt());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextInt());
- s.close();
- try {
- s.nextInt();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextInt()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextInt",
- args = {}
- )
- public void test_hasNextInt() throws IOException {
- Locale mkLocale = new Locale("mk", "MK");
- Locale arLocale = new Locale("ar", "AE");
- Locale deLocale = new Locale("de", "CH");
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE,
- mkLocale, arLocale, deLocale};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertTrue(s.hasNextInt());
- assertEquals(123, s.nextInt());
- assertEquals(456, s.nextInt());
- assertFalse(s.hasNextInt());
- try {
- s.nextInt();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertTrue(s.hasNextInt());
- assertEquals(38, s.nextInt());
- assertFalse(s.hasNextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- assertFalse(s.hasNextInt());
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextInt());
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextInt());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextInt());
- s.useLocale(deLocale);
- assertTrue(s.hasNextInt());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06662");
- s.useRadix(5);
- assertFalse(s.hasNextInt());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextInt());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextInt());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextInt());
- assertEquals(3456, s.nextInt());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(3456, s.nextInt());
-
- s = new Scanner("E3456");
- s.useRadix(16);
- assertTrue(s.hasNextInt());
- assertEquals(930902, s.nextInt());
-
- // The following test case fails on RI, because RI does not support
- // letter as leading digit
- s = new Scanner("E3,456");
- s.useLocale(Locale.ENGLISH);
- s.useRadix(16);
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt());
- assertEquals(930902, s.nextInt());
- }
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt());
- assertEquals(12300, s.nextInt());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt());
- assertEquals(12300, s.nextInt());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextInt());
- assertEquals(12300, s.nextInt());
-
- /*
- * There are three types of negative prefix all in all. '' '-' '(' There
- * are three types of negative suffix all in all. '' '-' ')' '(' and ')'
- * must be used togethor. Prefix '-' and suffix '-' must be used
- * exclusively.
- */
-
- /*
- * According to Integer regular expression: Integer :: = ( [-+]? (*
- * Numeral ) ) | LocalPositivePrefix Numeral LocalPositiveSuffix |
- * LocalNegativePrefix Numeral LocalNegativeSuffix 123- should be
- * recognized by scanner with locale ar_AE, (123) shouble be recognized
- * by scanner with locale mk_MK. But this is not the case on RI.
- */
- s = new Scanner("-123 123- -123-");
- s.useLocale(arLocale);
- assertTrue(s.hasNextInt());
- assertEquals(-123, s.nextInt());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt());
- assertEquals(-123, s.nextInt());
- }
- assertFalse(s.hasNextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
-
- s = new Scanner("-123 123- (123)");
- s.useLocale(mkLocale);
- assertTrue(s.hasNextInt());
- assertEquals(-123, s.nextInt());
- try {
- s.nextInt();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // expected
- }
- // Skip the un-recognizable token 123-.
- assertEquals("123-", s.next());
- // The following test case fails on RI
- if (!disableRIBugs) {
- assertTrue(s.hasNextInt());
- assertEquals(-123, s.nextInt());
- }
-
- s.close();
- try {
- s.hasNextInt();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextFloat()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextFloat",
- args = {}
- )
- public void test_hasNextFloat() throws IOException {
- Locale mkLocale = new Locale("mk", "MK");
- Locale arLocale = new Locale("ar", "AE");
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, mkLocale, arLocale};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)123.0, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)456.0, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)123.4, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)0.123, s.nextFloat());
- assertFalse(s.hasNextFloat());
- try {
- s.nextFloat();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)123.4, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)-456.7, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)123456.789, s.nextFloat());
- assertFalse(s.hasNextFloat());
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)1.234E12, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)-4.567E14, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals((float)1.23456789E-5, s.nextFloat());
-
- s = new Scanner("NaN Infinity -Infinity");
- assertTrue(s.hasNextFloat());
- assertEquals(Float.NaN, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals(Float.POSITIVE_INFINITY, s.nextFloat());
- assertTrue(s.hasNextFloat());
- assertEquals(Float.NEGATIVE_INFINITY, s.nextFloat());
-
- String str=String.valueOf(Float.MAX_VALUE*2);
- s=new Scanner(str);
- assertTrue(s.hasNextFloat());
- assertEquals(Float.POSITIVE_INFINITY,s.nextFloat());
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23456.0, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23.456, s.nextFloat());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23.456, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23456.0, s.nextFloat());
-
- s = new Scanner("23,456.7 23.456,7");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23456.7, s.nextFloat());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextFloat());
- assertEquals((float)23456.7, s.nextFloat());
-
- s = new Scanner("-123.4 123.4- -123.4-");
- s.useLocale(arLocale);
- assertTrue(s.hasNextFloat());
- assertEquals((float)-123.4, s.nextFloat());
- //The following test case fails on RI
- if (!disableRIBugs) {
- assertTrue(s.hasNextFloat());
- assertEquals((float)-123.4, s.nextFloat());
- }
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("(123) 123- -123");
- s.useLocale(mkLocale);
- if (!disableRIBugs) {
- assertTrue(s.hasNextFloat());
- assertEquals((float)-123.0, s.nextFloat());
- }
- assertFalse(s.hasNextFloat());
- try {
- s.nextFloat();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- // Skip the un-recognizable token 123-.
- if (!disableRIBugs) {
- assertEquals("123-", s.next());
- assertTrue(s.hasNextFloat());
- assertEquals((float)-123.0, s.nextFloat());
- }
-
- s = new Scanner("+123.4 -456.7");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextFloat());
- s.close();
- try{
- s.nextFloat();
- fail("Should throw IllegalStateException");
- }catch(IllegalStateException e){
- //expected
- }
-
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextShort(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IllegalStateException checking missed.",
- method = "hasNextShort",
- args = {int.class}
- )
- public void test_hasNextShortI() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort(10));
- assertEquals(123, s.nextShort(10));
- assertTrue(s.hasNextShort(10));
- assertEquals(456, s.nextShort(10));
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort(5));
- assertEquals(38, s.nextShort(5));
- assertFalse(s.hasNextShort(5));
- try {
- s.nextShort(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789");
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextInt(10));
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextInt(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextShort(10));
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextShort(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertTrue(s.hasNextShort(10));
- assertEquals(102, s.nextShort(10));
- assertFalse(s.hasNextShort(5));
- try {
- s.nextShort(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertTrue(s.hasNextShort(10));
- assertEquals(162, s.nextShort(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextShort(10));
- assertTrue(s.hasNextShort(10));
- assertEquals(23456, s.nextShort(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextShort(10));
- try {
- s.nextShort(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextShort(10));
- assertEquals(3456, s.nextShort(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextShort(10));
- assertEquals(3456, s.nextShort(10));
-
- s = new Scanner("E34");
- assertTrue(s.hasNextShort(16));
- assertEquals(3636, s.nextShort(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort(10));
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort(10));
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort(10));
- assertEquals(12300, s.nextShort(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextShort(10));
- assertEquals(-123, s.nextShort(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextShort(10));
- assertEquals(-123, s.nextShort(10));
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextShort()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextShort",
- args = {}
- )
- public void test_hasNextShort() throws IOException {
- Locale deLocale = new Locale("de", "CH");
- Locale arLocale = new Locale("ar", "AE");
- Locale mkLocale = new Locale("mk", "MK");
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE, deLocale,
- arLocale, mkLocale};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort());
- assertEquals(123, s.nextShort());
- assertTrue(s.hasNextShort());
- assertEquals(456, s.nextShort());
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertTrue(s.hasNextShort());
- assertEquals(38, s.nextShort());
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789");
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(deLocale);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextShort());
- s.useRadix(5);
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertTrue(s.hasNextShort());
- assertEquals(162, s.nextShort());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
- assertTrue(s.hasNextShort());
- assertEquals(23456, s.nextShort());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextShort());
- try {
- s.nextShort();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextShort());
- assertEquals(3456, s.nextShort());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextShort());
- assertEquals(3456, s.nextShort());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertTrue(s.hasNextShort());
- assertEquals(3636, s.nextShort());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort());
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort());
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextShort());
- assertEquals(12300, s.nextShort());
-
- s = new Scanner("-123");
- s.useLocale(arLocale);
- assertTrue(s.hasNextShort());
- assertEquals(-123, s.nextShort());
-
- s = new Scanner("-123");
- s.useLocale(mkLocale);
- assertTrue(s.hasNextShort());
- assertEquals(-123, s.nextShort());
-
- s.close();
- try {
- s.hasNextShort();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextShort(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test.",
- method = "hasNextShort",
- args = {int.class}
- )
- public void test_hasNextShortI_cache() throws IOException {
- //regression for HARMONY-2063
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort(16));
- assertEquals(291, s.nextShort());
- assertEquals(456, s.nextShort());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort(16));
- assertTrue(s.hasNextShort(8));
- assertEquals(83, s.nextShort());
- assertEquals(456, s.nextShort());
-
- s = new Scanner("-123 -456 -789");
- assertTrue(s.hasNextShort(8));
- assertEquals(-123, s.nextInt());
- assertEquals(-456, s.nextShort());
- assertTrue(s.hasNextInt(16));
- assertEquals(-789, s.nextShort());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextShort());
- s.close();
- try {
- s.nextShort();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextLong(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "IllegalStateException checking missed.",
- method = "hasNextLong",
- args = {int.class}
- )
- public void test_hasNextLongI() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong(10));
- assertEquals(123, s.nextLong(10));
- assertTrue(s.hasNextLong(10));
- assertEquals(456, s.nextLong(10));
- assertFalse(s.hasNextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong(5));
- assertEquals(38, s.nextLong(5));
- assertFalse(s.hasNextLong(5));
- try {
- s.nextLong(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- assertFalse(s.hasNextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextShort(10));
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(new Locale("de", "CH"));
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertTrue(s.hasNextLong(10));
- assertEquals(102, s.nextLong(10));
- assertFalse(s.hasNextLong(5));
- try {
- s.nextLong(5);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- assertTrue(s.hasNextLong(10));
- assertEquals(162, s.nextLong(10));
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
- assertTrue(s.hasNextLong(10));
- assertEquals(23456, s.nextLong(10));
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextLong(10));
- try {
- s.nextLong(10);
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextLong(10));
- assertEquals(3456, s.nextLong(10));
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextLong(10));
- assertEquals(3456, s.nextLong(10));
-
- s = new Scanner("E34");
- assertTrue(s.hasNextLong(16));
- assertEquals(3636, s.nextLong(16));
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong(10));
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong(10));
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong(10));
- assertEquals(12300, s.nextLong(10));
-
- s = new Scanner("-123");
- s.useLocale(new Locale("ar", "AE"));
- assertTrue(s.hasNextLong(10));
- assertEquals(-123, s.nextLong(10));
-
-
- s = new Scanner("-123");
- s.useLocale(new Locale("mk", "MK"));
- assertTrue(s.hasNextLong(10));
- assertEquals(-123, s.nextLong(10));
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextLong(int)
- */
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Regression test.",
- method = "hasNextLong",
- args = {int.class}
- )
- public void test_hasNextLongI_cache() throws IOException {
- //regression for HARMONY-2063
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong(16));
- assertEquals(291, s.nextLong());
- assertEquals(456, s.nextLong());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong(16));
- assertTrue(s.hasNextLong(8));
- assertEquals(83, s.nextLong());
- assertEquals(456, s.nextLong());
-
- s = new Scanner("-123 -456 -789");
- assertTrue(s.hasNextLong(8));
- assertEquals(-123, s.nextInt());
- assertEquals(-456, s.nextLong());
- assertTrue(s.hasNextShort(16));
- assertEquals(-789, s.nextLong());
-
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong());
- s.close();
- try {
- s.nextLong();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextLong()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextLong",
- args = {}
- )
- public void test_hasNextLong() throws IOException {
- Locale deLocale = new Locale("de", "CH");
- Locale arLocale = new Locale("ar", "AE");
- Locale mkLocale = new Locale("mk", "MK");
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH, Locale.CHINESE, deLocale,
- arLocale, mkLocale};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 456");
- assertTrue(s.hasNextLong());
- assertEquals(123, s.nextLong());
- assertTrue(s.hasNextLong());
- assertEquals(456, s.nextLong());
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- // If the radix is different from 10
- s = new Scanner("123 456");
- s.useRadix(5);
- assertTrue(s.hasNextLong());
- assertEquals(38, s.nextLong());
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // If the number is out of range
- s = new Scanner("123456789123456789123456789123456789");
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.ENGLISH);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
-
- /*
- * ''' is used in many locales as group separator.
- */
- s = new Scanner("23'456 23'456");
- s.useLocale(Locale.GERMANY);
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(deLocale);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
-
- /*
- * The input string has Arabic-Indic digits.
- */
- s = new Scanner("1\u06602 1\u06662");
- assertEquals(102, s.nextLong());
- s.useRadix(5);
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useRadix(10);
- assertTrue(s.hasNextLong());
- assertEquals(162, s.nextLong());
-
- /*
- * '.' is used in many locales as group separator. The input string
- * has Arabic-Indic digits .
- */
- s = new Scanner("23.45\u0666 23.456");
- s.useLocale(Locale.CHINESE);
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
- s.useLocale(Locale.GERMANY);
- // If exception is thrown out, input will not be advanced.
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
- assertTrue(s.hasNextLong());
- assertEquals(23456, s.nextLong());
-
- // The input string starts with zero
- s = new Scanner("03,456");
- s.useLocale(Locale.ENGLISH);
- assertFalse(s.hasNextLong());
- try {
- s.nextLong();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- s = new Scanner("03456");
- assertTrue(s.hasNextLong());
- assertEquals(3456, s.nextLong());
-
- s = new Scanner("\u06603,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextLong());
- assertEquals(3456, s.nextLong());
-
- s = new Scanner("E34");
- s.useRadix(16);
- assertTrue(s.hasNextLong());
- assertEquals(3636, s.nextLong());
-
- /*
- * There are 3 types of zero digit in all locales, '0' '\u0966' '\u0e50'
- * respectively, but they are not differentiated.
- */
- s = new Scanner("12300");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong());
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("123\u0966\u0966");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong());
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("123\u0e50\u0e50");
- s.useLocale(Locale.CHINESE);
- assertTrue(s.hasNextLong());
- assertEquals(12300, s.nextLong());
-
- s = new Scanner("-123");
- s.useLocale(arLocale);
- assertTrue(s.hasNextLong());
- assertEquals(-123, s.nextLong());
-
- s = new Scanner("-123");
- s.useLocale(mkLocale);
- assertTrue(s.hasNextLong());
- assertEquals(-123, s.nextLong());
-
- s.close();
- try {
- s.hasNextLong();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextDouble()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextDouble",
- args = {}
- )
- public void test_hasNextDouble() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(123.0, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(456.0, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(123.4, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(0.123, s.nextDouble());
- assertFalse(s.hasNextDouble());
- try {
- s.nextDouble();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(123.4, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(-456.7, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(123456.789, s.nextDouble());
- assertFalse(s.hasNextDouble());
- try {
- s.nextDouble();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(1.234E12, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(-4.567E14, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(1.23456789E-5, s.nextDouble());
-
- s = new Scanner("NaN Infinity -Infinity");
- assertTrue(s.hasNextDouble());
- assertEquals(Double.NaN, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
- assertTrue(s.hasNextDouble());
- assertEquals(Double.NEGATIVE_INFINITY, s.nextDouble());
-
- String str=String.valueOf(Double.MAX_VALUE*2);
- s=new Scanner(str);
- assertTrue(s.hasNextDouble());
- assertEquals(Double.POSITIVE_INFINITY,s.nextDouble());
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(23456.0, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextDouble());
- assertEquals(23.456, s.nextDouble());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(23.456, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextDouble());
- assertEquals(23456.0, s.nextDouble());
-
- s = new Scanner("23,456.7 23.456,7");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(23456.7, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextDouble());
- assertEquals(23456.7, s.nextDouble());
-
- s = new Scanner("-123.4");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- assertEquals(-123.4, s.nextDouble());
-
- s = new Scanner("+123.4 -456.7");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextDouble());
- s.close();
- try{
- s.nextDouble();
- fail("Should throw IllegalStateException");
- }catch(IllegalStateException e){
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#hasNextBigDecimal()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextBigDecimal",
- args = {}
- )
- public void test_hasNextBigDecimal() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("123"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("456"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("0.123"), s.nextBigDecimal());
- assertFalse(s.hasNextBigDecimal());
- try {
- s.nextBigDecimal();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("-456.7"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("123456.789"), s.nextBigDecimal());
- assertFalse(s.hasNextBigDecimal());
- try {
- s.nextBigDecimal();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
-
- s = new Scanner("NaN");
- assertFalse(s.hasNextBigDecimal());
- try {
- s.nextBigDecimal();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
- s.useLocale(Locale.GERMANY);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
-
- s = new Scanner("23,456.7");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("23456.7"), s.nextBigDecimal());
-
- s = new Scanner("-123.4");
- s.useLocale(Locale.ENGLISH);
- assertTrue(s.hasNextBigDecimal());
- assertEquals(new BigDecimal("-123.4"), s.nextBigDecimal());
-
- s.close();
- try {
- s.hasNextBigDecimal();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- private static class MockStringReader extends StringReader {
-
- public MockStringReader(String param) {
- super(param);
- }
-
- public int read(CharBuffer target) throws IOException {
- target.append('t');
- target.append('e');
- target.append('s');
- target.append('t');
- throw new IOException();
- }
-
- }
-
- private static class MockStringReader2Read extends StringReader {
- private int timesRead = 1;
-
- public MockStringReader2Read(String param) {
- super(param);
- }
-
- public int read(CharBuffer target) throws IOException {
- if (timesRead == 1) {
- target.append('1');
- target.append('2');
- target.append('3');
- timesRead++;
- return 3;
- } else if (timesRead == 2) {
- target.append('t');
- timesRead++;
- return 1;
- } else {
- throw new IOException();
- }
- }
-
- }
-
- /**
- * @tests java.util.Scanner#findWithinHorizon(Pattern, int)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "findWithinHorizon",
- args = {java.util.regex.Pattern.class, int.class}
- )
- public void test_findWithinHorizon_LPatternI(){
-
- // This method searches through the input up to the specified search
- // horizon(exclusive).
- s = new Scanner("123test");
- String result = s.findWithinHorizon(Pattern.compile("\\p{Lower}"), 5);
- assertEquals("t", result);
- MatchResult mresult = s.match();
- assertEquals(3, mresult.start());
- assertEquals(4, mresult.end());
-
- s = new Scanner("12345test1234test next");
- /*
- * If the pattern is found the scanner advances past the input that
- * matched and returns the string that matched the pattern.
- */
- result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 2);
- assertEquals("12", result);
- mresult = s.match();
- assertEquals(0, mresult.start());
- assertEquals(2, mresult.end());
- // Postion is now pointing at the bar. "12|345test1234test next"
-
- result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 6);
- assertEquals("345", result);
-
- mresult = s.match();
- assertEquals(2, mresult.start());
- assertEquals(5, mresult.end());
- // Postion is now pointing at the bar. "12345|test1234test next"
-
- // If no such pattern is detected then the null is returned and the
- // scanner's position remains unchanged.
- result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 3);
- assertNull(result);
-
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals("345", mresult.group());
- assertEquals(2, mresult.start());
- assertEquals(5, mresult.end());
- // Postion is now still pointing at the bar. "12345|test1234test next"
-
- // If horizon is 0, then the horizon is ignored and this method
- // continues to search through the input looking for the specified
- // pattern without bound.
- result = s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), 0);
- mresult = s.match();
- assertEquals(9, mresult.start());
- assertEquals(13, mresult.end());
- // Postion is now pointing at the bar. "12345test1234|test next"
-
- assertEquals("test", s.next());
- mresult = s.match();
- assertEquals(13, mresult.start());
- assertEquals(17, mresult.end());
-
- assertEquals("next", s.next());
- mresult = s.match();
- assertEquals(18, mresult.start());
- assertEquals(22, mresult.end());
-
- try {
- s.findWithinHorizon((Pattern) null, -1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- s.findWithinHorizon(Pattern.compile("\\p{Digit}+"), -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- s.close();
- try {
- s.findWithinHorizon((Pattern) null, -1);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("test");
- result = s.findWithinHorizon(Pattern.compile("\\w+"), 10);
- assertEquals("test", result);
-
- s = new Scanner("aa\n\rb");
- String patternStr = "^(a)$";
- result = s.findWithinHorizon(Pattern.compile("a"), 5);
- assertEquals("a", result);
- mresult = s.match();
- assertEquals(0, mresult.start());
- assertEquals(1, mresult.end());
-
- result = s.findWithinHorizon(Pattern.compile(patternStr,
- Pattern.MULTILINE), 5);
- assertNull(result);
-
- try {
- mresult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("");
- result = s.findWithinHorizon(Pattern.compile("^"), 0);
- assertEquals("", result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- result = s.findWithinHorizon(Pattern.compile("$"), 0);
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- s = new Scanner("1 fish 2 fish red fish blue fish");
- result = s.findWithinHorizon(Pattern
- .compile("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"), 10);
- assertNull(result);
-
- try {
- mresult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals(0, mresult.groupCount());
-
- result = s.findWithinHorizon(Pattern
- .compile("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)"), 100);
- assertEquals("1 fish 2 fish red fish blue", result);
- mresult = s.match();
- assertEquals(4, mresult.groupCount());
- assertEquals("1", mresult.group(1));
- assertEquals("2", mresult.group(2));
- assertEquals("red", mresult.group(3));
- assertEquals("blue", mresult.group(4));
-
- s = new Scanner("test");
- s.close();
- try {
- s.findWithinHorizon(Pattern.compile("test"), 1);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("word1 WorD2 ");
- s.close();
- try {
- s.findWithinHorizon(Pattern.compile("\\d+"), 10);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("word1 WorD2 wOrd3 ");
- Pattern pattern = Pattern.compile("\\d+");
- assertEquals("1", s.findWithinHorizon(pattern, 10));
- assertEquals("WorD2", s.next());
- assertEquals("3", s.findWithinHorizon(pattern, 15));
-
- // Regression test
- s = new Scanner(new MockStringReader("MockStringReader"));
- pattern = Pattern.compile("test");
- result = s.findWithinHorizon(pattern, 10);
- assertEquals("test", result);
-
- // Test the situation when input length is longer than buffer size.
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- pattern = Pattern.compile("\\p{Lower}+");
- result = s.findWithinHorizon(pattern, 1026);
- assertEquals(stringBuilder.toString(), result);
-
- // Test the situation when input length is longer than buffer size and
- // set horizon to buffer size.
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- pattern = Pattern.compile("\\p{Lower}+");
- result = s.findWithinHorizon(pattern, 1022);
- assertEquals(1022, result.length());
- assertEquals(stringBuilder.subSequence(0, 1022), result);
-
- // Test the situation, under which pattern is clipped by buffer.
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1022; i++) {
- stringBuilder.append(' ');
- }
- stringBuilder.append("bbc");
- assertEquals(1025, stringBuilder.length());
- s = new Scanner(stringBuilder.toString());
- pattern = Pattern.compile("bbc");
- result = s.findWithinHorizon(pattern, 1025);
- assertEquals(3, result.length());
- assertEquals(stringBuilder.subSequence(1022, 1025), result);
-
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- pattern = Pattern.compile("\\p{Lower}+");
- result = s.findWithinHorizon(pattern, 0);
- assertEquals(stringBuilder.toString(), result);
-
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 10240; i++) {
- stringBuilder.append('-');
- }
- stringBuilder.replace(0, 2, "aa");
- s = new Scanner(stringBuilder.toString());
- result = s.findWithinHorizon(Pattern.compile("aa"), 0);
- assertEquals("aa", result);
-
- s = new Scanner("aaaa");
- result = s.findWithinHorizon(Pattern.compile("a*"), 0);
- assertEquals("aaaa", result);
- }
-
- /**
- * @tests java.util.Scanner#findWithinHorizon(String, int) Copy of Pattern
- * test for String
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "findWithinHorizon",
- args = {java.lang.String.class, int.class}
- )
- public void test_findWithinHorizon_Ljava_lang_StringI() {
-
- // This method searches through the input up to the specified search
- // horizon(exclusive).
- s = new Scanner("123test");
- String result = s.findWithinHorizon("\\p{Lower}", 5);
- assertEquals("t", result);
- MatchResult mresult = s.match();
- assertEquals(3, mresult.start());
- assertEquals(4, mresult.end());
-
- s = new Scanner("12345test1234test next");
- /*
- * If the pattern is found the scanner advances past the input that
- * matched and returns the string that matched the pattern.
- */
- result = s.findWithinHorizon("\\p{Digit}+", 2);
- assertEquals("12", result);
- mresult = s.match();
- assertEquals(0, mresult.start());
- assertEquals(2, mresult.end());
- // Postion is now pointing at the bar. "12|345test1234test next"
-
- result = s.findWithinHorizon("\\p{Digit}+", 6);
- assertEquals("345", result);
-
- mresult = s.match();
- assertEquals(2, mresult.start());
- assertEquals(5, mresult.end());
- // Postion is now pointing at the bar. "12345|test1234test next"
-
- // If no such pattern is detected then the null is returned and the
- // scanner's position remains unchanged.
- result = s.findWithinHorizon("\\p{Digit}+", 3);
- assertNull(result);
-
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals("345", mresult.group());
- assertEquals(2, mresult.start());
- assertEquals(5, mresult.end());
- // Postion is now still pointing at the bar. "12345|test1234test next"
-
- // If horizon is 0, then the horizon is ignored and this method
- // continues to search through the input looking for the specified
- // pattern without bound.
- result = s.findWithinHorizon("\\p{Digit}+", 0);
- mresult = s.match();
- assertEquals(9, mresult.start());
- assertEquals(13, mresult.end());
- // Postion is now pointing at the bar. "12345test1234|test next"
-
- assertEquals("test", s.next());
- mresult = s.match();
- assertEquals(13, mresult.start());
- assertEquals(17, mresult.end());
-
- assertEquals("next", s.next());
- mresult = s.match();
- assertEquals(18, mresult.start());
- assertEquals(22, mresult.end());
-
- try {
- s.findWithinHorizon((String)null, 1);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- try {
- s.findWithinHorizon("\\p{Digit}+", -1);
- fail("Should throw IllegalArgumentException");
- } catch (IllegalArgumentException e) {
- // expected
- }
-
- s.close();
- // on RI throws NullPointerException
- /*
- * try { System.out.println("fsdfs"); s.findWithinHorizon((String) null,
- * -1); System.out.println("fsdfs"); fail("Should throw
- * IllegalStateException"); } catch (IllegalStateException e) { //
- * expected }
- */
- s = new Scanner("test");
- result = s.findWithinHorizon("\\w+", 10);
- assertEquals("test", result);
-
- s = new Scanner("aa\n\rb");
- String patternStr = "^(a)$";
- result = s.findWithinHorizon("a", 5);
- assertEquals("a", result);
- mresult = s.match();
- assertEquals(0, mresult.start());
- assertEquals(1, mresult.end());
-
- result = s.findWithinHorizon(patternStr, 5);
- assertNull(result);
-
- try {
- mresult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("");
- result = s.findWithinHorizon("^", 0);
- assertEquals("", result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- result = s.findWithinHorizon("$", 0);
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- s = new Scanner("1 fish 2 fish red fish blue fish");
- result = s.findWithinHorizon("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)", 10);
- assertNull(result);
-
- try {
- mresult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals(0, mresult.groupCount());
-
- result = s.findWithinHorizon("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)", 100);
- assertEquals("1 fish 2 fish red fish blue", result);
- mresult = s.match();
- assertEquals(4, mresult.groupCount());
- assertEquals("1", mresult.group(1));
- assertEquals("2", mresult.group(2));
- assertEquals("red", mresult.group(3));
- assertEquals("blue", mresult.group(4));
-
- s = new Scanner("test");
- s.close();
- try {
- s.findWithinHorizon("test", 1);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("word1 WorD2 ");
- s.close();
- try {
- s.findWithinHorizon("\\d+", 10);
- fail("should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("word1 WorD2 wOrd3 ");
- patternStr = "\\d+";
- assertEquals("1", s.findWithinHorizon(patternStr, 10));
- assertEquals("WorD2", s.next());
- assertEquals("3", s.findWithinHorizon(patternStr, 15));
-
- // Regression test
- s = new Scanner(new MockStringReader("MockStringReader"));
- patternStr = "test";
- result = s.findWithinHorizon(patternStr, 10);
- assertEquals("test", result);
-
- // Test the situation when input length is longer than buffer size.
- StringBuilder stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- patternStr = "\\p{Lower}+";
- result = s.findWithinHorizon(patternStr, 1026);
- assertEquals(stringBuilder.toString(), result);
-
- // Test the situation when input length is longer than buffer size and
- // set horizon to buffer size.
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- patternStr = "\\p{Lower}+";
- result = s.findWithinHorizon(patternStr, 1022);
- assertEquals(1022, result.length());
- assertEquals(stringBuilder.subSequence(0, 1022), result);
-
- // Test the situation, under which pattern is clipped by buffer.
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1022; i++) {
- stringBuilder.append(' ');
- }
- stringBuilder.append("bbc");
- assertEquals(1025, stringBuilder.length());
- s = new Scanner(stringBuilder.toString());
- patternStr = "bbc";
- result = s.findWithinHorizon(patternStr, 1025);
- assertEquals(3, result.length());
- assertEquals(stringBuilder.subSequence(1022, 1025), result);
-
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 1026; i++) {
- stringBuilder.append('a');
- }
- s = new Scanner(stringBuilder.toString());
- patternStr = "\\p{Lower}+";
- result = s.findWithinHorizon(patternStr, 0);
- assertEquals(stringBuilder.toString(), result);
-
- stringBuilder = new StringBuilder();
- for (int i = 0; i < 10240; i++) {
- stringBuilder.append('-');
- }
- stringBuilder.replace(0, 2, "aa");
- s = new Scanner(stringBuilder.toString());
- result = s.findWithinHorizon("aa", 0);
- assertEquals("aa", result);
-
- s = new Scanner("aaaa");
- result = s.findWithinHorizon("a*", 0);
- assertEquals("aaaa", result);
- }
-
- /**
- * @tests java.util.Scanner#findInLine(Pattern)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "findInLine",
- args = {java.util.regex.Pattern.class}
- )
- public void test_findInLine_LPattern() {
-
- Scanner s = new Scanner("");
- try {
- s.findInLine((Pattern) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // Expected
- }
- String result = s.findInLine(Pattern.compile("^"));
- assertEquals("", result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- result = s.findInLine(Pattern.compile("$"));
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- /*
- * When we use the operation of findInLine(Pattern), the match region
- * should not span the line separator.
- */
- s = new Scanner("aa\nb.b");
- result = s.findInLine(Pattern.compile("a\nb*"));
- assertNull(result);
-
- s = new Scanner("aa\nbb.b");
- result = s.findInLine(Pattern.compile("\\."));
- assertNull(result);
-
- s = new Scanner("abcd1234test\n");
- result = s.findInLine(Pattern.compile("\\p{Lower}+"));
- assertEquals("abcd", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- result = s.findInLine(Pattern.compile("\\p{Digit}{5}"));
- assertNull(result);
- try {
- matchResult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- result = s.findInLine(Pattern.compile("\\p{Lower}+"));
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(8, matchResult.start());
- assertEquals(12, matchResult.end());
-
- char[] chars = new char[2048];
- Arrays.fill(chars, 'a');
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- stringBuilder.append("1234");
- s = new Scanner(stringBuilder.toString());
- result = s.findInLine(Pattern.compile("\\p{Digit}+"));
- assertEquals("1234", result);
- matchResult = s.match();
- assertEquals(2048, matchResult.start());
- assertEquals(2052, matchResult.end());
-
- s = new Scanner("test");
- s.close();
- try {
- s.findInLine((Pattern) null);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("test1234\n1234 test");
- result = s.findInLine(Pattern.compile("test"));
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- int number = s.nextInt();
- assertEquals(1234, number);
- matchResult = s.match();
- assertEquals(4, matchResult.start());
- assertEquals(8, matchResult.end());
-
- result = s.next();
- assertEquals("1234", result);
- matchResult = s.match();
- assertEquals(9, matchResult.start());
- assertEquals(13, matchResult.end());
-
- result = s.findInLine(Pattern.compile("test"));
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(14, matchResult.start());
- assertEquals(18, matchResult.end());
-
- s = new Scanner("test\u0085\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- assertEquals("est", result);
-
- s = new Scanner("test\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- assertEquals("est", result);
-
- s = new Scanner("test\n123\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- // RI fails. It is a RI's bug.
- if (!disableRIBugs) {
- assertNull(result);
- }
- }
-
- /**
- * @tests java.util.Scanner#findInLine(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "findInLine",
- args = {java.lang.String.class}
- )
- public void test_findInLine_LString() {
- s = new Scanner("test");
- try {
- s.findInLine((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- s.close();
- try {
- s.findInLine((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- try {
- s.findInLine("test");
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // exptected
- }
-
- s = new Scanner("");
-
- String result = s.findInLine("^");
- assertEquals("", result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- result = s.findInLine("$");
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(0, matchResult.end());
-
- /*
- * When we use the operation of findInLine(Pattern), the match region
- * should not span the line separator.
- */
- s = new Scanner("aa\nb.b");
- result = s.findInLine("a\nb*");
- assertNull(result);
-
- s = new Scanner("aa\nbb.b");
- result = s.findInLine("\\.");
- assertNull(result);
-
- s = new Scanner("abcd1234test\n");
- result = s.findInLine("\\p{Lower}+");
- assertEquals("abcd", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- result = s.findInLine("\\p{Digit}{5}");
- assertNull(result);
- try {
- matchResult = s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- result = s.findInLine("\\p{Lower}+");
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(8, matchResult.start());
- assertEquals(12, matchResult.end());
-
- char[] chars = new char[2048];
- Arrays.fill(chars, 'a');
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- stringBuilder.append("1234");
- s = new Scanner(stringBuilder.toString());
- result = s.findInLine("\\p{Digit}+");
- assertEquals("1234", result);
- matchResult = s.match();
- assertEquals(2048, matchResult.start());
- assertEquals(2052, matchResult.end());
-
- s = new Scanner("test1234\n1234 test");
- result = s.findInLine("test");
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- int number = s.nextInt();
- assertEquals(1234, number);
- matchResult = s.match();
- assertEquals(4, matchResult.start());
- assertEquals(8, matchResult.end());
-
- result = s.next();
- assertEquals("1234", result);
- matchResult = s.match();
- assertEquals(9, matchResult.start());
- assertEquals(13, matchResult.end());
-
- result = s.findInLine("test");
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(14, matchResult.start());
- assertEquals(18, matchResult.end());
-
- s = new Scanner("test\u0085\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- assertEquals("est", result);
-
- s = new Scanner("test\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- assertEquals("est", result);
-
- s = new Scanner("test\n123\ntest");
- result = s.findInLine("est");
- assertEquals("est", result);
- result = s.findInLine("est");
- // RI fails. It is a RI's bug.
- if (!disableRIBugs) {
- assertNull(result);
- }
-
-
- }
-
- /**
- * @tests java.util.Scanner#skip(Pattern)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {java.util.regex.Pattern.class}
- )
- public void test_skip_LPattern() {
- s = new Scanner("test");
- try {
- s.skip((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // If pattern does not match, NoSuchElementException will be thrown out.
- s = new Scanner("1234");
- try {
- s.skip(Pattern.compile("\\p{Lower}"));
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // expected
- }
- // Then, no matchResult will be thrown out.
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s.skip(Pattern.compile("\\p{Digit}"));
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s.skip(Pattern.compile("\\p{Digit}+"));
- matchResult = s.match();
- assertEquals(1, matchResult.start());
- assertEquals(4, matchResult.end());
-
- s.close();
- try {
- s.skip(Pattern.compile("test"));
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- MockStringReader2Read reader = new MockStringReader2Read("test");
- s = new Scanner(reader);
- try {
- s.skip(Pattern.compile("\\p{Digit}{4}"));
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // expected
- }
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- s.skip(Pattern.compile("\\p{Digit}{3}\\p{Lower}"));
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- s.close();
- try {
- s.skip((Pattern) null);
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- StringBuilder stringBuilder = new StringBuilder();
- char [] chars = new char[1024];
- Arrays.fill(chars, 'a');
- stringBuilder.append(chars);
- stringBuilder.append('3');
- s = new Scanner(stringBuilder.toString());
- s.skip(Pattern.compile("\\p{Lower}+\\p{Digit}"));
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1025, matchResult.end());
-
- // Large amount of input may be cached
- chars = new char[102400];
- Arrays.fill(chars, 'a');
- stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- s = new Scanner(stringBuilder.toString());
- s.skip(Pattern.compile(".*"));
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(102400, matchResult.end());
-
- // skip something without risking a NoSuchElementException
- s.skip(Pattern.compile("[ \t]*"));
- matchResult = s.match();
- assertEquals(102400, matchResult.start());
- assertEquals(102400, matchResult.end());
- }
-
- /**
- * @tests java.util.Scanner#skip(String)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "skip",
- args = {java.lang.String.class}
- )
- public void test_skip_LString() {
- s = new Scanner("test");
- try {
- s.skip((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
-
- // If pattern does not match, NoSuchElementException will be thrown out.
- s = new Scanner("1234");
- try {
- s.skip("\\p{Lower}");
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // expected
- }
- // Then, no matchResult will be thrown out.
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s.skip("\\p{Digit}");
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s.skip("\\p{Digit}+");
- matchResult = s.match();
- assertEquals(1, matchResult.start());
- assertEquals(4, matchResult.end());
-
- s.close();
- try {
- s.skip("test");
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- MockStringReader2Read reader = new MockStringReader2Read("test");
- s = new Scanner(reader);
- try {
- s.skip("\\p{Digit}{4}");
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // expected
- }
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
- s.skip("\\p{Digit}{3}\\p{Lower}");
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(4, matchResult.end());
-
- s.close();
- try {
- s.skip("");
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- StringBuilder stringBuilder = new StringBuilder();
- char [] chars = new char[1024];
- Arrays.fill(chars, 'a');
- stringBuilder.append(chars);
- stringBuilder.append('3');
- s = new Scanner(stringBuilder.toString());
- s.skip("\\p{Lower}+\\p{Digit}");
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1025, matchResult.end());
-
- // Large amount of input may be cached
- chars = new char[102400];
- Arrays.fill(chars, 'a');
- stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- s = new Scanner(stringBuilder.toString());
- s.skip(".*");
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(102400, matchResult.end());
-
- // skip something without risking a NoSuchElementException
- s.skip("[ \t]*");
- matchResult = s.match();
- assertEquals(102400, matchResult.start());
- assertEquals(102400, matchResult.end());
-
- s = new Scanner("test");
- try {
- s.skip((String) null);
- fail("Should throw NullPointerException");
- } catch (NullPointerException e) {
- // expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextDouble()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextDouble",
- args = {}
- )
- public void test_nextDouble() throws IOException {
- Locale[] requiredLocales = {Locale.GERMANY, Locale.ENGLISH};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertEquals(123.0, s.nextDouble());
- assertEquals(456.0, s.nextDouble());
- assertEquals(123.4, s.nextDouble());
- assertEquals(0.123, s.nextDouble());
- try {
- s.nextDouble();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertEquals(123.4, s.nextDouble());
- assertEquals(-456.7, s.nextDouble());
- assertEquals(123456.789, s.nextDouble());
- try {
- s.nextDouble();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertEquals(1.234E12, s.nextDouble());
- assertEquals(-4.567E14, s.nextDouble());
- assertEquals(1.23456789E-5, s.nextDouble());
-
- s = new Scanner("NaN Infinity -Infinity");
- assertEquals(Double.NaN, s.nextDouble());
- assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
- assertEquals(Double.NEGATIVE_INFINITY, s.nextDouble());
-
- //The following test case fails on RI
- s=new Scanner("\u221e");
- s.useLocale(Locale.ENGLISH);
-// assertEquals(Double.POSITIVE_INFINITY, s.nextDouble());
-
- String str=String.valueOf(Double.MAX_VALUE*2);
- s=new Scanner(str);
- assertEquals(Double.POSITIVE_INFINITY,s.nextDouble());
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(23456.0, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertEquals(23.456, s.nextDouble());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(23.456, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertEquals(23456.0, s.nextDouble());
-
- s = new Scanner("23,456.7 23.456,7");
- s.useLocale(Locale.ENGLISH);
- assertEquals(23456.7, s.nextDouble());
- s.useLocale(Locale.GERMANY);
- assertEquals(23456.7, s.nextDouble());
-
- s = new Scanner("-123.4");
- s.useLocale(Locale.ENGLISH);
- assertEquals(-123.4, s.nextDouble());
-
- s.close();
- try {
- s.nextDouble();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @throws IOException
- * @tests java.util.Scanner#nextBigDecimal()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextBigDecimal",
- args = {}
- )
- public void test_nextBigDecimal() throws IOException {
- Locale[] requiredLocales = {Locale.ENGLISH, Locale.GERMANY};
- if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
- // locale dependent test, bug 1943269
- return;
- }
- s = new Scanner("123 45\u0666. 123.4 .123 ");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("123"), s.nextBigDecimal());
- assertEquals(new BigDecimal("456"), s.nextBigDecimal());
- assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
- assertEquals(new BigDecimal("0.123"), s.nextBigDecimal());
- try {
- s.nextBigDecimal();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // Expected
- }
-
- s = new Scanner("+123.4 -456.7 123,456.789 0.1\u06623,4");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("123.4"), s.nextBigDecimal());
- assertEquals(new BigDecimal("-456.7"), s.nextBigDecimal());
- assertEquals(new BigDecimal("123456.789"), s.nextBigDecimal());
- try {
- s.nextBigDecimal();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- // Scientific notation
- s = new Scanner("+123.4E10 -456.7e+12 123,456.789E-10");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("1.234E12"), s.nextBigDecimal());
- assertEquals(new BigDecimal("-4.567E14"), s.nextBigDecimal());
- assertEquals(new BigDecimal("1.23456789E-5"), s.nextBigDecimal());
-
- s = new Scanner("NaN");
- try {
- s.nextBigDecimal();
- fail("Should throw InputMismatchException");
- } catch (InputMismatchException e) {
- // Expected
- }
-
- /*
- * Different locale can only recognize corresponding locale sensitive
- * string. ',' is used in many locales as group separator.
- */
- s = new Scanner("23,456 23,456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
- s.useLocale(Locale.GERMANY);
- assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
-
- s = new Scanner("23.456 23.456");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("23.456"), s.nextBigDecimal());
- s.useLocale(Locale.GERMANY);
- assertEquals(new BigDecimal("23456"), s.nextBigDecimal());
-
- s = new Scanner("23,456.7");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("23456.7"), s.nextBigDecimal());
-
- s = new Scanner("-123.4");
- s.useLocale(Locale.ENGLISH);
- assertEquals(new BigDecimal("-123.4"), s.nextBigDecimal());
-
- s.close();
- try {
- s.nextBigDecimal();
- fail("IllegalStateException expected");
- } catch (IllegalStateException e) {
- //expected
- }
- }
-
- /**
- * @tests java.util.Scanner#toString()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "toString",
- args = {}
- )
- public void test_toString() {
- s = new Scanner("test");
- assertNotNull(s.toString());
- }
-
- /**
- * @tests java.util.Scanner#nextLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "nextLine",
- args = {}
- )
- public void test_nextLine() {
- s = new Scanner("");
- s.close();
- try {
- s.nextLine();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("test\r\ntest");
- String result = s.nextLine();
- assertEquals("test", result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(6, matchResult.end());
-
- s = new Scanner("\u0085");
- result = s.nextLine();
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("\u2028");
- result = s.nextLine();
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("\u2029");
- result = s.nextLine();
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("");
- try {
- result = s.nextLine();
- fail("Should throw NoSuchElementException");
- } catch (NoSuchElementException e) {
- // expected
- }
- try {
- s.match();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("Ttest");
- result = s.nextLine();
- assertEquals("Ttest", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(5, matchResult.end());
-
- s = new Scanner("\r\n");
- result = s.nextLine();
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(2, matchResult.end());
-
- char[] chars = new char[1024];
- Arrays.fill(chars, 'a');
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- chars = new char[] { '+', '-' };
- stringBuilder.append(chars);
- stringBuilder.append("\u2028");
- s = new Scanner(stringBuilder.toString());
- result = s.nextLine();
-
- assertEquals(stringBuilder.toString().substring(0, 1026), result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1027, matchResult.end());
-
- chars = new char[1023];
- Arrays.fill(chars, 'a');
- stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- stringBuilder.append("\r\n");
- s = new Scanner(stringBuilder.toString());
- result = s.nextLine();
-
- assertEquals(stringBuilder.toString().substring(0, 1023), result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1025, matchResult.end());
-
- s = new Scanner(" ");
- result = s.nextLine();
- assertEquals(" ", result);
-
- s = new Scanner("test\n\n\n");
- result = s.nextLine();
- assertEquals("test", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(5, matchResult.end());
- result = s.nextLine();
- matchResult = s.match();
- assertEquals(5, matchResult.start());
- assertEquals(6, matchResult.end());
-
- s = new Scanner("\n\n\n");
- result = s.nextLine();
- assertEquals("", result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
- result = s.nextLine();
- matchResult = s.match();
- assertEquals(1, matchResult.start());
- assertEquals(2, matchResult.end());
-
- s = new Scanner("123 test\n ");
- int value = s.nextInt();
- assertEquals(123, value);
-
- result = s.nextLine();
- assertEquals(" test", result);
-
- s = new Scanner("test\n ");
- result = s.nextLine();
- assertEquals("test", result);
- }
-
- /**
- * @tests java.util.Scanner#hasNextLine()
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "hasNextLine",
- args = {}
- )
- public void test_hasNextLine() {
-
- s = new Scanner("");
- s.close();
- try {
- s.hasNextLine();
- fail("Should throw IllegalStateException");
- } catch (IllegalStateException e) {
- // expected
- }
-
- s = new Scanner("test\r\ntest");
- boolean result = s.hasNextLine();
- assertTrue(result);
- MatchResult matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(6, matchResult.end());
-
- s = new Scanner("\u0085");
- result = s.hasNextLine();
- assertTrue(result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("\u2028");
- result = s.hasNextLine();
- assertTrue(result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("\u2029");
- result = s.hasNextLine();
- assertTrue(result);
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- s = new Scanner("test\n");
- assertTrue(s.hasNextLine());
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(5, matchResult.end());
-
- char[] chars = new char[2048];
- Arrays.fill(chars, 'a');
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(chars);
- s = new Scanner(stringBuilder.toString());
- result = s.hasNextLine();
- assertTrue(result);
-
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(2048, matchResult.end());
-
- s = new Scanner("\n\n\n");
- assertTrue(s.hasNextLine());
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
-
- // The scanner will not advance any input.
- assertTrue(s.hasNextLine());
- matchResult = s.match();
- assertEquals(0, matchResult.start());
- assertEquals(1, matchResult.end());
- }
-
- protected void setUp() throws Exception {
- super.setUp();
-
- server = new ServerSocket(0);
- address = new InetSocketAddress("127.0.0.1", server.getLocalPort());
-
- client = SocketChannel.open();
- client.connect(address);
- serverSocket = server.accept();
-
- os = serverSocket.getOutputStream();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
-
- try {
- serverSocket.close();
- } catch (Exception e) {
-
- }
- try {
- client.close();
- } catch (Exception e) {
- // do nothing
- }
- try {
- server.close();
- } catch (Exception e) {
- // do nothing
- }
- }
-
- /**
- * @tests java.util.Scanner#Scanner(ReadableByteChannel)
- */
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "Scanner",
- args = {java.nio.channels.ReadableByteChannel.class}
- )
- public void test_Constructor_LReadableByteChannel()
- throws IOException {
- InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
- Support_PortManager.getNextPort());
- ServerSocketChannel ssc = ServerSocketChannel.open();
- ssc.socket().bind(localAddr);
-
- SocketChannel sc = SocketChannel.open();
- sc.connect(localAddr);
- sc.configureBlocking(false);
- assertFalse(sc.isBlocking());
-
- ssc.accept().close();
- ssc.close();
- assertFalse(sc.isBlocking());
-
- Scanner s = new Scanner(sc);
- while (s.hasNextInt()) {
- s.nextInt();
- }
-
- sc.close();
- }
-}
diff --git a/luni/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java b/luni/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
index 121c123..253fed2 100644
--- a/luni/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
+++ b/luni/src/test/java/tests/api/javax/net/ssl/HostnameVerifierTest.java
@@ -121,9 +121,6 @@ public class HostnameVerifierTest extends TestCase implements
in = new ByteArrayInputStream(X509_WILD_CO_JP);
x509 = (X509Certificate) cf.generateCertificate(in);
session = new mySSLSession(new X509Certificate[] {x509});
- // Silly test because no-one would ever be able to lookup an IP address
- // using "*.co.jp".
- assertTrue(verifier.verify("*.co.jp", session));
assertFalse(verifier.verify("foo.co.jp", session));
assertFalse(verifier.verify("\u82b1\u5b50.co.jp", session));
@@ -159,11 +156,137 @@ public class HostnameVerifierTest extends TestCase implements
assertTrue(verifier.verify("localhost", session));
assertTrue(verifier.verify("localhost.localdomain", session));
- // TODO support IP addresses
- assertTrue(verifier.verify("127.0.0.1", session));
-
assertFalse(verifier.verify("local.host", session));
+ }
+
+ public void testVerifyIpAddress() throws Exception {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(X509_MULTIPLE_SUBJECT_ALT);
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
+ HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
+
+ assertTrue(verifier.verify("127.0.0.1", session));
assertFalse(verifier.verify("127.0.0.2", session));
+ }
+
+ public void testWildcardsCannotMatchIpAddresses() throws Exception {
+ // openssl req -x509 -nodes -days 36500 -subj '/CN=*.0.0.1' -newkey rsa:512 -out cert.pem
+ String cert = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIBkjCCATygAwIBAgIJAMdemqOwd/BEMA0GCSqGSIb3DQEBBQUAMBIxEDAOBgNV\n"
+ + "BAMUByouMC4wLjEwIBcNMTAxMjIwMTY0NDI1WhgPMjExMDExMjYxNjQ0MjVaMBIx\n"
+ + "EDAOBgNVBAMUByouMC4wLjEwXDANBgkqhkiG9w0BAQEFAANLADBIAkEAqY8c9Qrt\n"
+ + "YPWCvb7lclI+aDHM6fgbJcHsS9Zg8nUOh5dWrS7AgeA25wyaokFl4plBbbHQe2j+\n"
+ + "cCjsRiJIcQo9HwIDAQABo3MwcTAdBgNVHQ4EFgQUJ436TZPJvwCBKklZZqIvt1Yt\n"
+ + "JjEwQgYDVR0jBDswOYAUJ436TZPJvwCBKklZZqIvt1YtJjGhFqQUMBIxEDAOBgNV\n"
+ + "BAMUByouMC4wLjGCCQDHXpqjsHfwRDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEB\n"
+ + "BQUAA0EAk9i88xdjWoewqvE+iMC9tD2obMchgFDaHH0ogxxiRaIKeEly3g0uGxIt\n"
+ + "fl2WRY8hb4x+zRrwsFaLEpdEvqcjOQ==\n"
+ + "-----END CERTIFICATE-----";
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(cert.getBytes("UTF-8"));
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
+ HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
+
+ assertFalse(verifier.verify("127.0.0.1", session));
+ }
+
+ public void testWildcardsMustHaveTwoDots() throws Exception {
+ // openssl req -x509 -nodes -days 36500 -subj '/CN=*.com' -newkey rsa:512 -out cert.pem
+ String cert = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIBjDCCATagAwIBAgIJAOVulXCSu6HuMA0GCSqGSIb3DQEBBQUAMBAxDjAMBgNV\n"
+ + "BAMUBSouY29tMCAXDTEwMTIyMDE2NDkzOFoYDzIxMTAxMTI2MTY0OTM4WjAQMQ4w\n"
+ + "DAYDVQQDFAUqLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDJd8xqni+h7Iaz\n"
+ + "ypItivs9kPuiJUqVz+SuJ1C05SFc3PmlRCvwSIfhyD67fHcbMdl+A/LrIjhhKZJe\n"
+ + "1joO0+pFAgMBAAGjcTBvMB0GA1UdDgQWBBS4Iuzf5w8JdCp+EtBfdFNudf6+YzBA\n"
+ + "BgNVHSMEOTA3gBS4Iuzf5w8JdCp+EtBfdFNudf6+Y6EUpBIwEDEOMAwGA1UEAxQF\n"
+ + "Ki5jb22CCQDlbpVwkruh7jAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EA\n"
+ + "U6LFxmZr31lFyis2/T68PpjAppc0DpNQuA2m/Y7oTHBDi55Fw6HVHCw3lucuWZ5d\n"
+ + "qUYo4ES548JdpQtcLrW2sA==\n"
+ + "-----END CERTIFICATE-----";
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(cert.getBytes("UTF-8"));
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
+ HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
+
+ assertFalse(verifier.verify("google.com", session));
+ }
+
+ public void testSubjectAltName() throws Exception {
+ /*
+ * $ cat ./cert.cnf
+ * [req]
+ * distinguished_name=distinguished_name
+ * req_extensions=req_extensions
+ * x509_extensions=x509_extensions
+ * [distinguished_name]
+ * [req_extensions]
+ * [x509_extensions]
+ * subjectAltName=DNS:bar.com,DNS:baz.com
+ *
+ * $ openssl req -x509 -nodes -days 36500 -subj '/CN=foo.com' -config ./cert.cnf \
+ * -newkey rsa:512 -out cert.pem
+ */
+ String cert = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIBPTCB6KADAgECAgkA7zoHaaqNGHQwDQYJKoZIhvcNAQEFBQAwEjEQMA4GA1UE\n"
+ + "AxMHZm9vLmNvbTAgFw0xMDEyMjAxODM5MzZaGA8yMTEwMTEyNjE4MzkzNlowEjEQ\n"
+ + "MA4GA1UEAxMHZm9vLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC+gmoSxF+8\n"
+ + "hbV+rgRQqHIJd50216OWQJbU3BvdlPbca779NYO4+UZWTFdBM8BdQqs3H4B5Agvp\n"
+ + "y7HeSff1F7XRAgMBAAGjHzAdMBsGA1UdEQQUMBKCB2Jhci5jb22CB2Jhei5jb20w\n"
+ + "DQYJKoZIhvcNAQEFBQADQQBXpZZPOY2Dy1lGG81JTr8L4or9jpKacD7n51eS8iqI\n"
+ + "oTznPNuXHU5bFN0AAGX2ij47f/EahqTpo5RdS95P4sVm\n"
+ + "-----END CERTIFICATE-----";
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(cert.getBytes("UTF-8"));
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
+ HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
+
+ assertTrue(verifier.verify("foo.com", session));
+ assertTrue(verifier.verify("bar.com", session));
+ assertTrue(verifier.verify("baz.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ assertFalse(verifier.verify("quux.com", session));
+ }
+
+ public void testSubjectAltNameWithWildcard() throws Exception {
+ /*
+ * $ cat ./cert.cnf
+ * [req]
+ * distinguished_name=distinguished_name
+ * req_extensions=req_extensions
+ * x509_extensions=x509_extensions
+ * [distinguished_name]
+ * [req_extensions]
+ * [x509_extensions]
+ * subjectAltName=DNS:bar.com,DNS:*.baz.com
+ *
+ * $ openssl req -x509 -nodes -days 36500 -subj '/CN=foo.com' -config ./cert.cnf \
+ * -newkey rsa:512 -out cert.pem
+ */
+ String cert = "-----BEGIN CERTIFICATE-----\n"
+ + "MIIBPzCB6qADAgECAgkAnv/7Jv5r7pMwDQYJKoZIhvcNAQEFBQAwEjEQMA4GA1UE\n"
+ + "AxMHZm9vLmNvbTAgFw0xMDEyMjAxODQ2MDFaGA8yMTEwMTEyNjE4NDYwMVowEjEQ\n"
+ + "MA4GA1UEAxMHZm9vLmNvbTBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDAz2YXnyog\n"
+ + "YdYLSFr/OEgSumtwqtZKJTB4wqTW/eKbBCEzxnyUMxWZIqUGu353PzwfOuWp2re3\n"
+ + "nvVV+QDYQlh9AgMBAAGjITAfMB0GA1UdEQQWMBSCB2Jhci5jb22CCSouYmF6LmNv\n"
+ + "bTANBgkqhkiG9w0BAQUFAANBAB8yrSl8zqy07i0SNYx2B/FnvQY734pxioaqFWfO\n"
+ + "Bqo1ZZl/9aPHEWIwBrxYNVB0SGu/kkbt/vxqOjzzrkXukmI=\n"
+ + "-----END CERTIFICATE-----";
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ InputStream in = new ByteArrayInputStream(cert.getBytes("UTF-8"));
+ X509Certificate x509 = (X509Certificate) cf.generateCertificate(in);
+ mySSLSession session = new mySSLSession(new X509Certificate[] { x509 });
+ HostnameVerifier verifier = HttpsURLConnection.getDefaultHostnameVerifier();
+ assertTrue(verifier.verify("foo.com", session));
+ assertTrue(verifier.verify("bar.com", session));
+ assertTrue(verifier.verify("a.baz.com", session));
+ assertFalse(verifier.verify("baz.com", session));
+ assertFalse(verifier.verify("a.foo.com", session));
+ assertFalse(verifier.verify("a.bar.com", session));
+ assertFalse(verifier.verify("quux.com", session));
}
}
diff --git a/luni/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java b/luni/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
index 8bf48a2..4dddbc6 100644
--- a/luni/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
+++ b/luni/src/test/java/tests/api/javax/net/ssl/X509KeyManagerTest.java
@@ -9,32 +9,27 @@ import java.security.PrivateKey;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.security.spec.PKCS8EncodedKeySpec;
-
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.X509KeyManager;
-
import junit.framework.TestCase;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
/**
* Tests for <code>X509KeyManager</code> class constructors and methods.
*/
-@TestTargetClass(X509KeyManager.class)
public class X509KeyManagerTest extends TestCase {
private X509KeyManager manager;
private KeyManagerFactory factory;
+ private static final String CLIENT = "CLIENT";
+ private static final String SERVER = "SERVER";
+ private static final String TYPE_RSA = "RSA";
+ private static final char[] PASSWORD = "1234".toCharArray();
+
private String keyType;
- private String client = "CLIENT";
- private String server = "SERVER";
- private String type = "RSA";
private KeyStore keyTest;
- private X509Certificate[] cert = null;
- private PrivateKey[] keys = null;
- private String password = "1234";
+ private X509Certificate[] cert;
+ private PrivateKey[] keys;
/*
@@ -632,7 +627,7 @@ public class X509KeyManagerTest extends TestCase {
KeyFactory kf = KeyFactory.getInstance("RSA");
keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
keyTest.load(null, "1234".toCharArray());
- if (keyType.equals(client)) {
+ if (keyType.equals(CLIENT)) {
keys = new PrivateKey[3];
keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
keys[1] = kf.generatePrivate(new PKCS8EncodedKeySpec(key2Bytes));
@@ -641,18 +636,18 @@ public class X509KeyManagerTest extends TestCase {
cert[0] = (X509Certificate) cf.generateCertificate(certArray);
cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
cert[2] = (X509Certificate) cf.generateCertificate(certArray3);
- keyTest.setKeyEntry("clientKey_01", keys[0], password.toCharArray(), new X509Certificate[] {cert[0]});
- keyTest.setKeyEntry("clientKey_02", keys[1], password.toCharArray(), new X509Certificate[] {cert[0], cert[1]});
- keyTest.setKeyEntry("clientKey_03", keys[2], password.toCharArray(), new X509Certificate[] {cert[0], cert[2]});
+ keyTest.setKeyEntry("clientKey_01", keys[0], PASSWORD, new X509Certificate[] {cert[0]});
+ keyTest.setKeyEntry("clientKey_02", keys[1], PASSWORD, new X509Certificate[] {cert[0], cert[1]});
+ keyTest.setKeyEntry("clientKey_03", keys[2], PASSWORD, new X509Certificate[] {cert[0], cert[2]});
keyTest.setCertificateEntry("clientAlias_01", cert[0]);
keyTest.setCertificateEntry("clientAlias_02", cert[0]);
keyTest.setCertificateEntry("clientAlias_03", cert[1]);
- } else if (keyType.equals(server)) {
+ } else if (keyType.equals(SERVER)) {
keys = new PrivateKey[1];
keys[0] = kf.generatePrivate(new PKCS8EncodedKeySpec(keyBytes));
cert = new X509Certificate[1];
cert[0] = (X509Certificate) cf.generateCertificate(certArray3);
- keyTest.setKeyEntry("serverKey_00", keys[0], password.toCharArray(), new X509Certificate[] {cert[0]});
+ keyTest.setKeyEntry("serverKey_00", keys[0], PASSWORD, new X509Certificate[] {cert[0]});
keyTest.setCertificateEntry("serverAlias_00", cert[0]);
}
} catch (Exception ex) {
@@ -668,94 +663,64 @@ public class X509KeyManagerTest extends TestCase {
}
/**
- * @tests X509KeyManager#getClientAliases(String keyType, Principal[] issuers)
+ * X509KeyManager#getClientAliases(String keyType, Principal[] issuers)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getClientAliases",
- args = {java.lang.String.class, java.security.Principal[].class}
- )
public void test_getClientAliases() {
- init(client);
+ init(CLIENT);
assertNull(manager.getClientAliases(null, null));
assertNull(manager.getClientAliases("", null));
- String[] resArray = manager.getClientAliases(type, null);
+ String[] resArray = manager.getClientAliases(TYPE_RSA, null);
assertNotNull(resArray);
- assertTrue("Incorrect result", compareC(resArray));
+ assertEquals(3, resArray.length);
+ assertKnownAliases(resArray);
}
/**
- * @tests X509KeyManager#chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket)
+ * X509KeyManager#chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "chooseClientAlias",
- args = {java.lang.String[].class, java.security.Principal[].class, java.net.Socket.class}
- )
public void test_chooseClientAlias() {
- String[] ar = {client};
- init(client);
+ init(CLIENT);
assertNull(manager.chooseClientAlias(null, null, new Socket()));
assertNull(manager.chooseClientAlias(new String[0], null, new Socket()));
- assertNull(manager.chooseClientAlias(ar, null, new Socket()));
- String res = manager.chooseClientAlias(new String[]{type}, null, null);
+ assertNull(manager.chooseClientAlias(new String[]{"BOGUS"}, null, new Socket()));
+ String res = manager.chooseClientAlias(new String[]{TYPE_RSA}, null, null);
assertNotNull(res);
- assertEquals("clientkey_03", res.toLowerCase().toLowerCase());
+ assertKnownAlias(res);
}
/**
- * @tests X509KeyManager#getServerAliases(String keyType, Principal[] issuers)
+ * X509KeyManager#getServerAliases(String keyType, Principal[] issuers)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getServerAliases",
- args = {java.lang.String.class, java.security.Principal[].class}
- )
public void test_getServerAliases() {
- init(server);
+ init(SERVER);
assertNull(manager.getServerAliases(null, null));
assertNull(manager.getServerAliases("", null));
- String[] resArray = manager.getServerAliases(type, null);
+ String[] resArray = manager.getServerAliases(TYPE_RSA, null);
assertNotNull(resArray);
assertEquals("Incorrect length", 1, resArray.length);
assertEquals("Incorrect aliase", "serverkey_00", resArray[0].toLowerCase());
}
/**
- * @tests X509KeyManager#chooseServerAlias(String keyType, Principal[] issuers, Socket socket)
+ * X509KeyManager#chooseServerAlias(String keyType, Principal[] issuers, Socket socket)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "chooseServerAlias",
- args = {java.lang.String.class, java.security.Principal[].class, java.net.Socket.class}
- )
public void test_chooseServerAlias() {
- init(server);
+ init(SERVER);
assertNull(manager.chooseServerAlias(null, null, new Socket()));
assertNull(manager.chooseServerAlias("", null, new Socket()));
- String res = manager.chooseServerAlias(type, null, null);
+ String res = manager.chooseServerAlias(TYPE_RSA, null, null);
assertNotNull(res);
assertEquals("serverkey_00", res.toLowerCase());
- res = manager.chooseServerAlias(type, null, new Socket());
+ res = manager.chooseServerAlias(TYPE_RSA, null, new Socket());
assertNotNull(res);
assertEquals("serverkey_00", res.toLowerCase());
}
/**
- * @tests X509KeyManager#getCertificateChain(String alias)
+ * X509KeyManager#getCertificateChain(String alias)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getCertificateChain",
- args = {java.lang.String.class}
- )
public void test_getCertificateChain() {
- init(server);
+ init(SERVER);
assertNull("Not NULL for NULL parameter", manager.getCertificateChain(null));
assertNull("Not NULL for empty parameter",manager.getCertificateChain(""));
assertNull("Not NULL for clientAlias_01 parameter", manager.getCertificateChain("clientAlias_01"));
@@ -763,32 +728,26 @@ public class X509KeyManagerTest extends TestCase {
}
/**
- * @tests X509KeyManager#getPrivateKey(String alias)
+ * X509KeyManager#getPrivateKey(String alias)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getPrivateKey",
- args = {java.lang.String.class}
- )
public void test_getPrivateKey() {
- init(client);
+ init(CLIENT);
assertNull("Not NULL for NULL parameter", manager.getPrivateKey(null));
assertNull("Not NULL for serverAlias_00 parameter", manager.getPrivateKey("serverAlias_00"));
assertNull("Not NULL for clientAlias_02 parameter", manager.getPrivateKey("clientAlias_02"));
}
- private boolean compareC(String[] ar) {
- if (ar.length != 3) {
- return false;
+ private void assertKnownAliases(String[] aliases) {
+ for (String alias : aliases) {
+ assertKnownAlias(alias);
}
- for (int i = 0; i < ar.length; i++) {
- if (!ar[i].toLowerCase().equals("clientkey_01") && !ar[i].toLowerCase().equals("clientkey_02") && !ar[i].toLowerCase().equals("clientkey_03")) {
- return false;
- }
- }
- return true;
+ }
+
+ private void assertKnownAlias(String alias) {
+ String a = alias.toLowerCase();
+ boolean okay = a.equals("clientkey_01") || a.equals("clientkey_02") || a.equals("clientkey_03");
+ assertTrue("Expected one of clientkey_01, clientkey_02, clientkey_03. Received: " + alias, okay);
}
}
diff --git a/luni/src/test/java/tests/api/javax/xml/parsers/AllTests.java b/luni/src/test/java/tests/api/javax/xml/parsers/AllTests.java
index 282fd3e..6771ea5 100644
--- a/luni/src/test/java/tests/api/javax/xml/parsers/AllTests.java
+++ b/luni/src/test/java/tests/api/javax/xml/parsers/AllTests.java
@@ -18,7 +18,6 @@ package tests.api.javax.xml.parsers;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.harmony.xml.ExpatParserTest;
/**
* This is autogenerated source file. Includes tests for package tests.api.javax.xml.parsers;
@@ -35,8 +34,6 @@ public class AllTests {
suite.addTestSuite(ParserConfigurationExceptionTest.class);
suite.addTestSuite(SAXParserFactoryTest.class);
suite.addTestSuite(SAXParserTest.class);
- // TODO Move ExpatParser to impl tests package
- // suite.addTestSuite(ExpatParserTest.class);
// $JUnit-END$
return suite;
diff --git a/luni/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java b/luni/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
index 04e2c53..5bcc7ac 100644
--- a/luni/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
+++ b/luni/src/test/java/tests/api/javax/xml/parsers/SAXParserTest.java
@@ -15,22 +15,22 @@
*/
package tests.api.javax.xml.parsers;
+import dalvik.annotation.KnownFailure;
+import dalvik.annotation.TestLevel;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.OutputStream;
import java.util.HashMap;
import java.util.Vector;
-
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-
import junit.framework.TestCase;
-
import org.xml.sax.HandlerBase;
import org.xml.sax.InputSource;
import org.xml.sax.Parser;
@@ -40,18 +40,12 @@ import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.DefaultHandler;
-
import tests.api.javax.xml.parsers.SAXParserTestSupport.MyDefaultHandler;
import tests.api.javax.xml.parsers.SAXParserTestSupport.MyHandler;
import tests.api.org.xml.sax.support.BrokenInputStream;
import tests.api.org.xml.sax.support.MethodLogger;
import tests.api.org.xml.sax.support.MockHandler;
import tests.support.resource.Support_Resources;
-import dalvik.annotation.KnownFailure;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
@SuppressWarnings("deprecation")
@TestTargetClass(SAXParser.class)
@@ -454,10 +448,8 @@ public class SAXParserTest extends TestCase {
args = {org.xml.sax.InputSource.class, org.xml.sax.helpers.DefaultHandler.class}
)
public void test_parseLorg_xml_sax_InputSourceLorg_xml_sax_helpers_DefaultHandler()
- throws Exception {
-
+ throws Exception {
for(int i = 0; i < list_wf.length; i++) {
-
HashMap<String, String> hm = new SAXParserTestSupport().readFile(
list_out_dh[i].getPath());
MyDefaultHandler dh = new MyDefaultHandler();
@@ -466,15 +458,13 @@ public class SAXParserTest extends TestCase {
assertTrue(SAXParserTestSupport.equalsMaps(hm, dh.createData()));
}
- for(int i = 0; i < list_nwf.length; i++) {
+ for (File file : list_nwf) {
try {
MyDefaultHandler dh = new MyDefaultHandler();
- InputSource is = new InputSource(
- new FileInputStream(list_nwf[i]));
+ InputSource is = new InputSource(new FileInputStream(file));
parser.parse(is, dh);
fail("SAXException is not thrown");
- } catch(org.xml.sax.SAXException se) {
- //expected
+ } catch (SAXException expected) {
}
}
@@ -482,23 +472,21 @@ public class SAXParserTest extends TestCase {
MyDefaultHandler dh = new MyDefaultHandler();
parser.parse((InputSource) null, dh);
fail("java.lang.IllegalArgumentException is not thrown");
- } catch(java.lang.IllegalArgumentException iae) {
- //expected
+ } catch (IllegalArgumentException expected) {
}
- try {
- InputSource is = new InputSource(new FileInputStream(list_wf[0]));
- parser.parse(is, (DefaultHandler) null);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- }
+ InputSource is = new InputSource(new FileInputStream(list_wf[0]));
+ parser.parse(is, (DefaultHandler) null);
+ InputStream in = null;
try {
- InputSource is = new InputSource(new BrokenInputStream(new FileInputStream(list_wf[0]), 10));
+ in = new BrokenInputStream(new FileInputStream(list_wf[0]), 10);
+ is = new InputSource(in);
parser.parse(is, (DefaultHandler) null);
fail("IOException expected");
- } catch(IOException e) {
- // Expected
+ } catch(IOException expected) {
+ } finally {
+ in.close();
}
}
@@ -508,35 +496,22 @@ public class SAXParserTest extends TestCase {
method = "parse",
args = {org.xml.sax.InputSource.class, org.xml.sax.HandlerBase.class}
)
- public void testParseInputSourceHandlerBase() {
+ public void testParseInputSourceHandlerBase() throws Exception {
for(int i = 0; i < list_wf.length; i++) {
- try {
- HashMap<String, String> hm = sp.readFile(
- list_out_hb[i].getPath());
- MyHandler dh = new MyHandler();
- InputSource is = new InputSource(new FileInputStream(list_wf[i]));
- parser.parse(is, dh);
- assertTrue(SAXParserTestSupport.equalsMaps(hm,
- dh.createData()));
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch (SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ HashMap<String, String> hm = sp.readFile(list_out_hb[i].getPath());
+ MyHandler dh = new MyHandler();
+ InputSource is = new InputSource(new FileInputStream(list_wf[i]));
+ parser.parse(is, dh);
+ assertTrue(SAXParserTestSupport.equalsMaps(hm, dh.createData()));
}
- for(int i = 0; i < list_nwf.length; i++) {
+ for (File file : list_nwf) {
try {
MyHandler dh = new MyHandler();
- InputSource is = new InputSource(new FileInputStream(list_nwf[i]));
+ InputSource is = new InputSource(new FileInputStream(file));
parser.parse(is, dh);
fail("SAXException is not thrown");
- } catch(org.xml.sax.SAXException se) {
- //expected
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
+ } catch (SAXException expected) {
}
}
@@ -544,67 +519,29 @@ public class SAXParserTest extends TestCase {
MyHandler dh = new MyHandler();
parser.parse((InputSource) null, dh);
fail("java.lang.IllegalArgumentException is not thrown");
- } catch(java.lang.IllegalArgumentException iae) {
- //expected
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
+ } catch(IllegalArgumentException expected) {
}
- try {
- InputSource is = new InputSource(new FileInputStream(list_wf[0]));
- parser.parse(is, (HandlerBase) null);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch(IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ InputSource is = new InputSource(new FileInputStream(list_wf[0]));
+ parser.parse(is, (HandlerBase) null);
// Reader case
- try {
- InputSource is = new InputSource(new InputStreamReader(
- new FileInputStream(list_wf[0])));
- parser.parse(is, (HandlerBase) null);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch(IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ is = new InputSource(new InputStreamReader(new FileInputStream(list_wf[0])));
+ parser.parse(is, (HandlerBase) null);
// SystemID case
- try {
- InputSource is = new InputSource(list_wf[0].toURI().toString());
- parser.parse(is, (HandlerBase) null);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch(IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ is = new InputSource(list_wf[0].toURI().toString());
+ parser.parse(is, (HandlerBase) null);
// Inject IOException
+ InputStream in = null;
try {
- InputStream is = new BrokenInputStream(
- new FileInputStream(list_wf[0]), 10);
- parser.parse(is, (HandlerBase) null,
- SAXParserTestSupport.XML_SYSTEM_ID);
+ in = new BrokenInputStream(new FileInputStream(list_wf[0]), 10);
+ parser.parse(in, (HandlerBase) null, SAXParserTestSupport.XML_SYSTEM_ID);
fail("IOException expected");
- } catch(IOException e) {
- // Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
+ } catch(IOException expected) {
+ } finally {
+ in.close();
}
}
@@ -784,35 +721,22 @@ public class SAXParserTest extends TestCase {
method = "parse",
args = {java.io.InputStream.class, org.xml.sax.HandlerBase.class}
)
- public void testParseInputStreamHandlerBase() {
+ public void testParseInputStreamHandlerBase() throws Exception {
for(int i = 0; i < list_wf.length; i++) {
- try {
- HashMap<String, String> hm = sp.readFile(
- list_out_hb[i].getPath());
- MyHandler dh = new MyHandler();
- InputStream is = new FileInputStream(list_wf[i]);
- parser.parse(is, dh);
- assertTrue(SAXParserTestSupport.equalsMaps(hm,
- dh.createData()));
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch (SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ HashMap<String, String> hm = sp.readFile(list_out_hb[i].getPath());
+ MyHandler dh = new MyHandler();
+ InputStream is = new FileInputStream(list_wf[i]);
+ parser.parse(is, dh);
+ assertTrue(SAXParserTestSupport.equalsMaps(hm, dh.createData()));
}
- for(int i = 0; i < list_nwf.length; i++) {
+ for (File file : list_nwf) {
try {
MyHandler dh = new MyHandler();
- InputStream is = new FileInputStream(list_nwf[i]);
+ InputStream is = new FileInputStream(file);
parser.parse(is, dh);
fail("SAXException is not thrown");
- } catch(org.xml.sax.SAXException se) {
- //expected
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
+ } catch (SAXException expected) {
}
}
@@ -820,37 +744,21 @@ public class SAXParserTest extends TestCase {
MyHandler dh = new MyHandler();
parser.parse((InputStream) null, dh);
fail("java.lang.IllegalArgumentException is not thrown");
- } catch(java.lang.IllegalArgumentException iae) {
- //expected
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
+ } catch (IllegalArgumentException expected) {
}
- try {
- InputStream is = new FileInputStream(list_wf[0]);
- parser.parse(is, (HandlerBase) null);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch(IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ InputStream is = new FileInputStream(list_wf[0]);
+ parser.parse(is, (HandlerBase) null);
// Inject IOException
try {
- InputStream is = new BrokenInputStream(
- new FileInputStream(list_wf[0]), 10);
+ is = new BrokenInputStream(new FileInputStream(list_wf[0]), 10);
parser.parse(is, (HandlerBase) null);
fail("IOException expected");
} catch(IOException e) {
// Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
+ } finally {
+ is.close();
}
}
@@ -860,76 +768,43 @@ public class SAXParserTest extends TestCase {
method = "parse",
args = {java.io.InputStream.class, org.xml.sax.HandlerBase.class, java.lang.String.class}
)
- public void testParseInputStreamHandlerBaseString() {
+ public void testParseInputStreamHandlerBaseString() throws Exception {
for(int i = 0; i < list_wf.length; i++) {
- try {
- HashMap<String, String> hm = sp.readFile(
- list_out_hb[i].getPath());
- MyHandler dh = new MyHandler();
- InputStream is = new FileInputStream(list_wf[i]);
- parser.parse(is, dh, SAXParserTestSupport.XML_SYSTEM_ID);
- assertTrue(SAXParserTestSupport.equalsMaps(hm,
- dh.createData()));
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch (SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ HashMap<String, String> hm = sp.readFile(list_out_hb[i].getPath());
+ MyHandler dh = new MyHandler();
+ InputStream is = new FileInputStream(list_wf[i]);
+ parser.parse(is, dh, SAXParserTestSupport.XML_SYSTEM_ID);
+ assertTrue(SAXParserTestSupport.equalsMaps(hm, dh.createData()));
}
- for(int i = 0; i < list_nwf.length; i++) {
+ for (File file : list_nwf) {
try {
MyHandler dh = new MyHandler();
- InputStream is = new FileInputStream(list_nwf[i]);
+ InputStream is = new FileInputStream(file);
parser.parse(is, dh, SAXParserTestSupport.XML_SYSTEM_ID);
fail("SAXException is not thrown");
- } catch(org.xml.sax.SAXException se) {
- //expected
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
+ } catch (SAXException expected) {
}
}
try {
MyHandler dh = new MyHandler();
- parser.parse((InputStream) null, dh,
- SAXParserTestSupport.XML_SYSTEM_ID);
+ parser.parse(null, dh, SAXParserTestSupport.XML_SYSTEM_ID);
fail("java.lang.IllegalArgumentException is not thrown");
- } catch(java.lang.IllegalArgumentException iae) {
- //expected
- } catch (IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
+ } catch(IllegalArgumentException expected) {
}
- try {
- InputStream is = new FileInputStream(list_wf[0]);
- parser.parse(is, (HandlerBase) null,
- SAXParserTestSupport.XML_SYSTEM_ID);
- } catch(java.lang.IllegalArgumentException iae) {
- fail("java.lang.IllegalArgumentException is thrown");
- } catch (FileNotFoundException fne) {
- fail("Unexpected FileNotFoundException " + fne.toString());
- } catch(IOException ioe) {
- fail("Unexpected IOException " + ioe.toString());
- } catch(SAXException sax) {
- fail("Unexpected SAXException " + sax.toString());
- }
+ InputStream is = new FileInputStream(list_wf[0]);
+ parser.parse(is, (HandlerBase) null, SAXParserTestSupport.XML_SYSTEM_ID);
// Inject IOException
try {
- InputStream is = new BrokenInputStream(
- new FileInputStream(list_wf[0]), 10);
- parser.parse(is, (HandlerBase) null,
- SAXParserTestSupport.XML_SYSTEM_ID);
+ is = new BrokenInputStream(new FileInputStream(list_wf[0]), 10);
+ parser.parse(is, (HandlerBase) null, SAXParserTestSupport.XML_SYSTEM_ID);
fail("IOException expected");
- } catch(IOException e) {
- // Expected
- } catch (Exception e) {
- throw new RuntimeException("Unexpected exception", e);
+ } catch(IOException expected) {
+ } finally {
+ is.close();
}
}
diff --git a/luni/src/test/java/tests/api/org/xml/sax/support/BrokenInputStream.java b/luni/src/test/java/tests/api/org/xml/sax/support/BrokenInputStream.java
index 578fb60..8136b86 100644
--- a/luni/src/test/java/tests/api/org/xml/sax/support/BrokenInputStream.java
+++ b/luni/src/test/java/tests/api/org/xml/sax/support/BrokenInputStream.java
@@ -47,4 +47,8 @@ public class BrokenInputStream extends InputStream {
return stream.read();
}
+ @Override
+ public void close() throws IOException {
+ stream.close();
+ }
} \ No newline at end of file
diff --git a/luni/src/test/java/tests/archive/AllTests.java b/luni/src/test/java/tests/archive/AllTests.java
deleted file mode 100644
index 50800f4..0000000
--- a/luni/src/test/java/tests/archive/AllTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.archive;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All Archive test suites");
- // $JUnit-BEGIN$
- suite.addTest(org.apache.harmony.archive.tests.java.util.jar.AllTests
- .suite());
- suite.addTest(org.apache.harmony.archive.tests.java.util.zip.AllTests
- .suite());
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/java/security/SecureRandomTest.java b/luni/src/test/java/tests/java/security/SecureRandomTest.java
index 2620175..b44280f 100644
--- a/luni/src/test/java/tests/java/security/SecureRandomTest.java
+++ b/luni/src/test/java/tests/java/security/SecureRandomTest.java
@@ -22,21 +22,14 @@
package tests.java.security;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
-
+import junit.framework.TestCase;
import org.apache.harmony.security.tests.support.RandomImpl;
-import junit.framework.TestCase;
-@TestTargetClass(SecureRandom.class)
/**
* Tests for <code>SecureRandom</code> constructor and methods
*
@@ -65,12 +58,6 @@ public class SecureRandomTest extends TestCase {
Security.removeProvider(p.getName());
}
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Verification of negative and boundary parameters missed",
- method = "next",
- args = {int.class}
- )
public final void testNext() {
MySecureRandom sr = new MySecureRandom();
if (sr.nextElement(1) != 1 || sr.nextElement(2) != 3 || sr.nextElement(3) != 7) {
@@ -81,12 +68,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for void setSeed(long)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "setSeed",
- args = {long.class}
- )
public final void testSetSeedlong() {
SecureRandom sr = new SecureRandom();
sr.setSeed(12345);
@@ -95,12 +76,6 @@ public class SecureRandomTest extends TestCase {
}
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "",
- method = "nextBytes",
- args = {byte[].class}
- )
public final void testNextBytes() {
byte[] b = new byte[5];
SecureRandom sr = new SecureRandom();
@@ -122,12 +97,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for void SecureRandom()
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "SecureRandom",
- args = {}
- )
public final void testSecureRandom() {
SecureRandom sr = new SecureRandom();
if (!sr.getAlgorithm().equals("someRandom") ||
@@ -139,12 +108,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for void SecureRandom(byte[])
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Null parameter checking missed",
- method = "SecureRandom",
- args = {byte[].class}
- )
public final void testSecureRandombyteArray() {
byte[] b = {1,2,3};
new SecureRandom(b);
@@ -159,12 +122,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for SecureRandom getInstance(String)
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "NoSuchAlgorithmException checking missed",
- method = "getInstance",
- args = {java.lang.String.class}
- )
public final void testGetInstanceString() {
SecureRandom sr = null;
try {
@@ -180,12 +137,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for SecureRandom getInstance(String, String)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {java.lang.String.class, java.lang.String.class}
- )
public final void testGetInstanceStringString() throws Exception {
SecureRandom sr = SecureRandom.getInstance("someRandom", "SRProvider");
if (sr.getProvider() != p || !"someRandom".equals(sr.getAlgorithm())) {
@@ -248,12 +199,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for SecureRandom getInstance(String, Provider)
*/
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "getInstance",
- args = {java.lang.String.class, java.security.Provider.class}
- )
public final void testGetInstanceStringProvider() throws Exception {
Provider p = new SRProvider();
SecureRandom sr = SecureRandom.getInstance("someRandom", p);
@@ -301,12 +246,6 @@ public class SecureRandomTest extends TestCase {
/*
* Class under test for void setSeed(byte[])
*/
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verification with null parameter missed",
- method = "setSeed",
- args = {byte[].class}
- )
public final void testSetSeedbyteArray() {
byte[] b = {1,2,3};
SecureRandom sr = new SecureRandom();
@@ -317,12 +256,6 @@ public class SecureRandomTest extends TestCase {
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verification with invalid parameter missed",
- method = "getSeed",
- args = {int.class}
- )
public final void testGetSeed() {
byte[] b = SecureRandom.getSeed(4);
if( b.length != 4) {
@@ -330,12 +263,6 @@ public class SecureRandomTest extends TestCase {
}
}
- @TestTargetNew(
- level = TestLevel.PARTIAL_COMPLETE,
- notes = "Verification with invalid parameter missed",
- method = "generateSeed",
- args = {int.class}
- )
public final void testGenerateSeed() {
SecureRandom sr = new SecureRandom();
byte[] b = sr.generateSeed(4);
diff --git a/luni/src/test/java/tests/luni/AllTestsIo.java b/luni/src/test/java/tests/luni/AllTestsIo.java
index 010916c..41b4d51 100644
--- a/luni/src/test/java/tests/luni/AllTestsIo.java
+++ b/luni/src/test/java/tests/luni/AllTestsIo.java
@@ -30,13 +30,11 @@ public class AllTestsIo
TestRunner.main(new String[] { AllTestsIo.class.getName() });
}
- public static final Test suite() {
+ public static Test suite() {
TestSuite suite = new TestSuite("Tests for java.io");
suite.addTest(tests.api.java.io.AllTests.suite());
- suite.addTest(org.apache.harmony.luni.tests.java.io.AllTests.suite());
-
return suite;
}
}
diff --git a/luni/src/test/java/tests/luni/AllTestsLang.java b/luni/src/test/java/tests/luni/AllTestsLang.java
index 3da5bb4..a7a18a8 100644
--- a/luni/src/test/java/tests/luni/AllTestsLang.java
+++ b/luni/src/test/java/tests/luni/AllTestsLang.java
@@ -33,8 +33,6 @@ public class AllTestsLang
public static final Test suite() {
TestSuite suite = new TestSuite("Tests for java.lang");
- suite.addTest(org.apache.harmony.luni.tests.java.lang.AllTests.suite());
-
suite.addTest(tests.api.java.lang.AllTests.suite());
suite.addTest(tests.api.java.lang.ref.AllTests.suite());
diff --git a/luni/src/test/java/tests/nio/AllTests.java b/luni/src/test/java/tests/nio/AllTests.java
deleted file mode 100644
index 92de0ca..0000000
--- a/luni/src/test/java/tests/nio/AllTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.nio;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all tests for the Math project.
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All Math test suites");
- // $JUnit-BEGIN$
- suite.addTest(org.apache.harmony.nio.tests.java.nio.AllTests.suite());
- suite.addTest(org.apache.harmony.nio.tests.java.nio.channels.AllTests.suite());
- suite.addTest(org.apache.harmony.nio.tests.java.nio.channels.spi.AllTests.suite());
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/nio_char/AllTests.java b/luni/src/test/java/tests/nio_char/AllTests.java
deleted file mode 100644
index ba6b82c..0000000
--- a/luni/src/test/java/tests/nio_char/AllTests.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.nio_char;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all tests for the NIO_Char project.
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All NIO_Char test suites");
- // $JUnit-BEGIN$
- suite.addTest(org.apache.harmony.nio_char.tests.java.nio.charset.AllTests.suite());
- suite.addTest(org.apache.harmony.nio_char.tests.java.nio.charset.spi.AllTests.suite());
- suite.addTest(tests.api.java.nio.charset.AllTests.suite());
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/org/w3c/dom/GetElementsByTagNameNS.java b/luni/src/test/java/tests/org/w3c/dom/GetElementsByTagNameNS.java
index e7f9f6a..d93da93 100644
--- a/luni/src/test/java/tests/org/w3c/dom/GetElementsByTagNameNS.java
+++ b/luni/src/test/java/tests/org/w3c/dom/GetElementsByTagNameNS.java
@@ -233,7 +233,7 @@ public final class GetElementsByTagNameNS extends DOMTestCase {
doc = (Document) load("staffNS", builder);
docElem = doc.getDocumentElement();
newList = docElem.getElementsByTagNameNS("*", "*");
- assertEquals("listSize", 36, newList.getLength());
+ assertEquals("listSize", 35, newList.getLength());
}
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
diff --git a/luni/src/test/java/tests/prefs/AllTests.java b/luni/src/test/java/tests/prefs/AllTests.java
deleted file mode 100644
index 6fc05b6..0000000
--- a/luni/src/test/java/tests/prefs/AllTests.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.prefs;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * Test suite that includes all tests for the Prefs project.
- *
- */
-public class AllTests {
- public static Test suite() {
- TestSuite suite = new TestSuite("All Prefs test suites");
- // $JUnit-BEGIN$
- suite.addTest(org.apache.harmony.prefs.tests.java.util.prefs.AllTests.suite());
- // $JUnit-END$
- return suite;
- }
-}
diff --git a/luni/src/test/java/tests/security/AllTests.java b/luni/src/test/java/tests/security/AllTests.java
index 95501a1..6f348fe 100644
--- a/luni/src/test/java/tests/security/AllTests.java
+++ b/luni/src/test/java/tests/security/AllTests.java
@@ -27,7 +27,7 @@ public class AllTests {
TestSuite suite = new TestSuite("All security test suites");
// $JUnit-BEGIN$
suite.addTest(org.apache.harmony.security.tests.java.security.AllTests.suite());
- suite.addTest(org.bouncycastle.jce.provider.AllTests.suite());
+ suite.addTest(com.android.org.bouncycastle.jce.provider.AllTests.suite());
suite.addTest(tests.api.java.security.AllTests.suite());
suite.addTest(tests.java.security.AllTests.suite());
diff --git a/luni/src/test/java/tests/security/SecureRandomTest.java b/luni/src/test/java/tests/security/SecureRandomTest.java
index cf9c6dc..bb038e1 100644
--- a/luni/src/test/java/tests/security/SecureRandomTest.java
+++ b/luni/src/test/java/tests/security/SecureRandomTest.java
@@ -15,19 +15,20 @@
*/
package tests.security;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import junit.framework.TestCase;
-public abstract class SecureRandomTest extends TestCase {
+public abstract class SecureRandomTest extends TestCase {
private final String algorithmName;
- private int counter=0;
+ private int counter = 0;
protected SecureRandomTest(String name) {
this.algorithmName = name;
@@ -37,28 +38,6 @@ public abstract class SecureRandomTest extends TestCase {
super.setUp();
}
- @TestTargets({
- @TestTargetNew(
- level=TestLevel.ADDITIONAL,
- method="getInstance",
- args={String.class}
- ),
- @TestTargetNew(
- level=TestLevel.ADDITIONAL,
- method="setSeed",
- args={long.class}
- ),
- @TestTargetNew(
- level=TestLevel.ADDITIONAL,
- method="nextBytes",
- args={byte[].class}
- ),
- @TestTargetNew(
- level=TestLevel.COMPLETE,
- method="method",
- args={}
- )
- })
public void testSecureRandom() {
SecureRandom secureRandom1 = null;
try {
@@ -92,4 +71,26 @@ public abstract class SecureRandomTest extends TestCase {
return randomData;
}
+
+
+ public void testSecureRandomThreadSafety() throws Exception {
+ final SecureRandom secureRandom = SecureRandom.getInstance(algorithmName);
+ int threads = 2;
+ ExecutorService executor = Executors.newFixedThreadPool(threads);
+ ExecutorCompletionService ecs = new ExecutorCompletionService(executor);
+ for (int t = 0; t < threads; t++) {
+ ecs.submit(new Callable<Void>() {
+ public Void call () {
+ for (int i = 0; i < 1000; i++) {
+ secureRandom.generateSeed(1024);
+ }
+ return null;
+ }
+ });
+ }
+ executor.shutdown();
+ for (int i = 0; i < threads; i++) {
+ ecs.take().get();
+ }
+ }
}
diff --git a/luni/src/test/java/tests/sql/AllTests.java b/luni/src/test/java/tests/sql/AllTests.java
index 6db1a01..e782d84 100644
--- a/luni/src/test/java/tests/sql/AllTests.java
+++ b/luni/src/test/java/tests/sql/AllTests.java
@@ -26,8 +26,6 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("All SQL test suites");
// $JUnit-BEGIN$
- suite.addTest(org.apache.harmony.sql.tests.java.sql.AllTests.suite());
- suite.addTest(org.apache.harmony.sql.tests.javax.sql.AllTests.suite());
suite.addTest(tests.java.sql.AllTests.suite());
// These don't do blackbox testing *and* crash JUnit on the RI
diff --git a/luni/src/test/java/tests/targets/security/AllTests.java b/luni/src/test/java/tests/targets/security/AllTests.java
index 0a83332..6a896c8 100644
--- a/luni/src/test/java/tests/targets/security/AllTests.java
+++ b/luni/src/test/java/tests/targets/security/AllTests.java
@@ -32,13 +32,6 @@ public class AllTests {
suite.addTestSuite(MessageDigestTestSHA512.class);
suite.addTestSuite(SignatureTestMD2withRSA.class);
- suite.addTestSuite(SignatureTestMD5withRSA.class);
- suite.addTestSuite(SignatureTestNONEwithDSA.class);
- suite.addTestSuite(SignatureTestSHA1withDSA.class);
- suite.addTestSuite(SignatureTestSHA1withRSA.class);
- suite.addTestSuite(SignatureTestSHA256withRSA.class);
- suite.addTestSuite(SignatureTestSHA384withRSA.class);
- suite.addTestSuite(SignatureTestSHA512withRSA.class);
suite.addTestSuite(KeyStoreTestPKCS12.class);
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestMD5withRSA.java b/luni/src/test/java/tests/targets/security/SignatureTestMD5withRSA.java
deleted file mode 100644
index 7996b32..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestMD5withRSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestMD5withRSA extends SignatureTest {
-
- public SignatureTestMD5withRSA() {
- super("MD5withRSA", "RSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestNONEwithDSA.java b/luni/src/test/java/tests/targets/security/SignatureTestNONEwithDSA.java
deleted file mode 100644
index be19c3e..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestNONEwithDSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestNONEwithDSA extends SignatureTest {
-
- public SignatureTestNONEwithDSA() {
- super("NONEwithDSA", "DSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestSHA1withDSA.java b/luni/src/test/java/tests/targets/security/SignatureTestSHA1withDSA.java
deleted file mode 100644
index 117f8df..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestSHA1withDSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestSHA1withDSA extends SignatureTest {
-
- public SignatureTestSHA1withDSA() {
- super("SHA1withDSA", "DSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestSHA1withRSA.java b/luni/src/test/java/tests/targets/security/SignatureTestSHA1withRSA.java
deleted file mode 100644
index 7729fce..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestSHA1withRSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestSHA1withRSA extends SignatureTest {
-
- public SignatureTestSHA1withRSA() {
- super("SHA1withRSA", "RSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestSHA256withRSA.java b/luni/src/test/java/tests/targets/security/SignatureTestSHA256withRSA.java
deleted file mode 100644
index c7ed4aa..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestSHA256withRSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestSHA256withRSA extends SignatureTest {
-
- public SignatureTestSHA256withRSA() {
- super("SHA256withRSA", "RSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestSHA384withRSA.java b/luni/src/test/java/tests/targets/security/SignatureTestSHA384withRSA.java
deleted file mode 100644
index 32ea0ad..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestSHA384withRSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestSHA384withRSA extends SignatureTest {
-
- public SignatureTestSHA384withRSA() {
- super("SHA384withRSA", "RSA");
- }
-}
diff --git a/luni/src/test/java/tests/targets/security/SignatureTestSHA512withRSA.java b/luni/src/test/java/tests/targets/security/SignatureTestSHA512withRSA.java
deleted file mode 100644
index 530d751..0000000
--- a/luni/src/test/java/tests/targets/security/SignatureTestSHA512withRSA.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.targets.security;
-
-import tests.security.SignatureTest;
-
-public class SignatureTestSHA512withRSA extends SignatureTest {
-
- public SignatureTestSHA512withRSA() {
- super("SHA512withRSA", "RSA");
- }
-}
diff --git a/luni/src/test/java/tests/xml/AllTests.java b/luni/src/test/java/tests/xml/AllTests.java
index 2e12a59..8fd8096 100644
--- a/luni/src/test/java/tests/xml/AllTests.java
+++ b/luni/src/test/java/tests/xml/AllTests.java
@@ -40,7 +40,6 @@ public class AllTests {
// suite.addTest(tests.api.org.w3c.dom.AllTests.suite());
// END android-changed
suite.addTest(tests.org.w3c.dom.AllTests.suite());
- suite.addTest(org.apache.harmony.xml.AllTests.suite());
suite.addTest(org.kxml2.io.AllTests.suite());
return suite;
diff --git a/luni/src/test/java/tests/xml/DomTest.java b/luni/src/test/java/tests/xml/DomTest.java
index eb3a842..3f68d7c 100644
--- a/luni/src/test/java/tests/xml/DomTest.java
+++ b/luni/src/test/java/tests/xml/DomTest.java
@@ -17,6 +17,26 @@
package tests.xml;
import dalvik.annotation.KnownFailure;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.w3c.dom.Attr;
@@ -25,6 +45,7 @@ import org.w3c.dom.Comment;
import org.w3c.dom.DOMException;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Entity;
@@ -37,34 +58,12 @@ import org.w3c.dom.ProcessingInstruction;
import org.w3c.dom.Text;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
import static org.w3c.dom.UserDataHandler.NODE_ADOPTED;
import static org.w3c.dom.UserDataHandler.NODE_CLONED;
import static org.w3c.dom.UserDataHandler.NODE_IMPORTED;
import static org.w3c.dom.UserDataHandler.NODE_RENAMED;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* Construct a DOM and then interrogate it.
@@ -806,6 +805,60 @@ public class DomTest extends TestCase {
}
}
+ public void testValueOfNewAttributesIsEmptyString() {
+ assertEquals("", document.createAttribute("bar").getValue());
+ assertEquals("", document.createAttributeNS("http://foo", "bar").getValue());
+ }
+
+ public void testCloneNode() throws Exception {
+ document = builder.parse(new InputSource(new StringReader("<menu "
+ + "xmlns:f=\"http://food\" xmlns:a=\"http://addons\">"
+ + "<f:item a:standard=\"strawberry\" deluxe=\"yes\">Waffles</f:item></menu>")));
+ name = (Element) document.getFirstChild().getFirstChild();
+
+ Element clonedName = (Element) name.cloneNode(true);
+ assertNull(clonedName.getParentNode());
+ assertNull(clonedName.getNextSibling());
+ assertNull(clonedName.getPreviousSibling());
+ assertEquals("http://food", clonedName.getNamespaceURI());
+ assertEquals("f:item", clonedName.getNodeName());
+ assertEquals("item", clonedName.getLocalName());
+ assertEquals("http://food", clonedName.getNamespaceURI());
+ assertEquals("yes", clonedName.getAttribute("deluxe"));
+ assertEquals("strawberry", clonedName.getAttribute("a:standard"));
+ assertEquals("strawberry", clonedName.getAttributeNS("http://addons", "standard"));
+ assertEquals(1, name.getChildNodes().getLength());
+
+ Text clonedChild = (Text) clonedName.getFirstChild();
+ assertSame(clonedName, clonedChild.getParentNode());
+ assertNull(clonedChild.getNextSibling());
+ assertNull(clonedChild.getPreviousSibling());
+ assertEquals("Waffles", clonedChild.getTextContent());
+ }
+
+ /**
+ * We can't use the namespace-aware factory method for non-namespace-aware
+ * nodes. http://code.google.com/p/android/issues/detail?id=2735
+ */
+ public void testCloneNodeNotNamespaceAware() throws Exception {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(false);
+ builder = factory.newDocumentBuilder();
+ document = builder.parse(new InputSource(new StringReader("<menu "
+ + "xmlns:f=\"http://food\" xmlns:a=\"http://addons\">"
+ + "<f:item a:standard=\"strawberry\" deluxe=\"yes\">Waffles</f:item></menu>")));
+ name = (Element) document.getFirstChild().getFirstChild();
+
+ Element clonedName = (Element) name.cloneNode(true);
+ assertNull(clonedName.getNamespaceURI());
+ assertEquals("f:item", clonedName.getNodeName());
+ assertNull(clonedName.getLocalName());
+ assertNull(clonedName.getNamespaceURI());
+ assertEquals("yes", clonedName.getAttribute("deluxe"));
+ assertEquals("strawberry", clonedName.getAttribute("a:standard"));
+ assertEquals("", clonedName.getAttributeNS("http://addons", "standard"));
+ }
+
/**
* A shallow clone requires cloning the attributes but not the child nodes.
*/
@@ -1385,6 +1438,121 @@ public class DomTest extends TestCase {
assertEquals(root.getChildNodes().item(0), current);
}
+ public void testPublicIdAndSystemId() throws Exception {
+ document = builder.parse(new InputSource(new StringReader(
+ " <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\""
+ + " \"http://www.w3.org/TR/html4/strict.dtd\">"
+ + "<html></html>")));
+ doctype = document.getDoctype();
+ assertEquals("html", doctype.getName());
+ assertEquals("-//W3C//DTD HTML 4.01//EN", doctype.getPublicId());
+ assertEquals("http://www.w3.org/TR/html4/strict.dtd", doctype.getSystemId());
+ }
+
+ public void testSystemIdOnly() throws Exception {
+ document = builder.parse(new InputSource(new StringReader(
+ " <!DOCTYPE html SYSTEM \"http://www.w3.org/TR/html4/strict.dtd\">"
+ + "<html></html>")));
+ doctype = document.getDoctype();
+ assertEquals("html", doctype.getName());
+ assertNull(doctype.getPublicId());
+ assertEquals("http://www.w3.org/TR/html4/strict.dtd", doctype.getSystemId());
+ }
+
+ public void testSingleQuotedPublicIdAndSystemId() throws Exception {
+ document = builder.parse(new InputSource(new StringReader(
+ " <!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'"
+ + " 'http://www.w3.org/TR/html4/strict.dtd'>"
+ + "<html></html>")));
+ doctype = document.getDoctype();
+ assertEquals("html", doctype.getName());
+ assertEquals("-//W3C//DTD HTML 4.01//EN", doctype.getPublicId());
+ assertEquals("http://www.w3.org/TR/html4/strict.dtd", doctype.getSystemId());
+ }
+
+ public void testGetElementsByTagNameNs() {
+ NodeList elements = item.getElementsByTagNameNS("http://addons", "option");
+ assertEquals(option1, elements.item(0));
+ assertEquals(option2, elements.item(1));
+ assertEquals(2, elements.getLength());
+ }
+
+ public void testGetElementsByTagName() {
+ NodeList elements = item.getElementsByTagName("a:option");
+ assertEquals(option1, elements.item(0));
+ assertEquals(option2, elements.item(1));
+ assertEquals(2, elements.getLength());
+ }
+
+ public void testGetElementsByTagNameWithWildcard() {
+ NodeList elements = item.getElementsByTagName("*");
+ assertEquals(name, elements.item(0));
+ assertEquals(description, elements.item(1));
+ assertEquals(option1, elements.item(2));
+ assertEquals(option2, elements.item(3));
+ assertEquals(nutrition, elements.item(4));
+ assertEquals(vitamins, elements.item(5));
+ assertEquals(vitaminc, elements.item(6));
+ assertEquals(7, elements.getLength());
+ }
+
+ public void testGetElementsByTagNameNsWithWildcard() {
+ NodeList elements = item.getElementsByTagNameNS("*", "*");
+ assertEquals(name, elements.item(0));
+ assertEquals(description, elements.item(1));
+ assertEquals(option1, elements.item(2));
+ assertEquals(option2, elements.item(3));
+ assertEquals(nutrition, elements.item(4));
+ assertEquals(vitamins, elements.item(5));
+ assertEquals(vitaminc, elements.item(6));
+ assertEquals(7, elements.getLength());
+ }
+
+ /**
+ * Documents shouldn't contain document fragments.
+ * http://code.google.com/p/android/issues/detail?id=2735
+ */
+ public void testAddingADocumentFragmentAddsItsChildren() {
+ Element a = document.createElement("a");
+ Element b = document.createElement("b");
+ Element c = document.createElement("c");
+ DocumentFragment fragment = document.createDocumentFragment();
+ fragment.appendChild(a);
+ fragment.appendChild(b);
+ fragment.appendChild(c);
+
+ Node returned = menu.appendChild(fragment);
+ assertSame(fragment, returned);
+ NodeList children = menu.getChildNodes();
+ assertEquals(6, children.getLength());
+ assertTrue(children.item(0) instanceof Text); // whitespace
+ assertEquals(item, children.item(1));
+ assertTrue(children.item(2) instanceof Text); // whitespace
+ assertEquals(a, children.item(3));
+ assertEquals(b, children.item(4));
+ assertEquals(c, children.item(5));
+ }
+
+ public void testReplacingWithADocumentFragmentInsertsItsChildren() {
+ Element a = document.createElement("a");
+ Element b = document.createElement("b");
+ Element c = document.createElement("c");
+ DocumentFragment fragment = document.createDocumentFragment();
+ fragment.appendChild(a);
+ fragment.appendChild(b);
+ fragment.appendChild(c);
+
+ Node returned = menu.replaceChild(fragment, item);
+ assertSame(item, returned);
+ NodeList children = menu.getChildNodes();
+ assertEquals(5, children.getLength());
+ assertTrue(children.item(0) instanceof Text); // whitespace
+ assertEquals(a, children.item(1));
+ assertEquals(b, children.item(2));
+ assertEquals(c, children.item(3));
+ assertTrue(children.item(4) instanceof Text); // whitespace
+ }
+
private class RecordingHandler implements UserDataHandler {
final Set<String> calls = new HashSet<String>();
public void handle(short operation, String key, Object data, Node src, Node dst) {
diff --git a/luni/src/test/resources/META-INF/services/java.util.ServiceLoaderTestInterface b/luni/src/test/resources/META-INF/services/java.util.ServiceLoaderTestInterface
deleted file mode 100644
index b87e043..0000000
--- a/luni/src/test/resources/META-INF/services/java.util.ServiceLoaderTestInterface
+++ /dev/null
@@ -1,7 +0,0 @@
-# this is a comment
-# followed by a blank line
-
-java.util.ServiceLoaderTest$Impl1
-java.util.ServiceLoaderTest$Impl2 # this comment is valid
-java.util.ServiceLoaderTest$Impl2#as is this
-java.util.ServiceLoaderTest$Impl2 # and duplicates are allowed too
diff --git a/luni/src/test/resources/META-INF/services/libcore.java.util.ServiceLoaderTestInterface b/luni/src/test/resources/META-INF/services/libcore.java.util.ServiceLoaderTestInterface
new file mode 100644
index 0000000..8f8a9eb
--- /dev/null
+++ b/luni/src/test/resources/META-INF/services/libcore.java.util.ServiceLoaderTestInterface
@@ -0,0 +1,7 @@
+# this is a comment
+# followed by a blank line
+
+libcore.java.util.ServiceLoaderTest$Impl1
+libcore.java.util.ServiceLoaderTest$Impl2 # this comment is valid
+libcore.java.util.ServiceLoaderTest$Impl2#as is this
+libcore.java.util.ServiceLoaderTest$Impl2 # and duplicates are allowed too
diff --git a/luni/src/test/resources/dalvik/system/loading-test.dex b/luni/src/test/resources/dalvik/system/loading-test.dex
new file mode 100644
index 0000000..98fe21b
--- /dev/null
+++ b/luni/src/test/resources/dalvik/system/loading-test.dex
Binary files differ
diff --git a/luni/src/test/resources/dalvik/system/loading-test.jar b/luni/src/test/resources/dalvik/system/loading-test.jar
new file mode 100644
index 0000000..3edea4c
--- /dev/null
+++ b/luni/src/test/resources/dalvik/system/loading-test.jar
Binary files differ
diff --git a/luni/src/test/resources/dalvik/system/loading-test2.dex b/luni/src/test/resources/dalvik/system/loading-test2.dex
new file mode 100644
index 0000000..c50d984
--- /dev/null
+++ b/luni/src/test/resources/dalvik/system/loading-test2.dex
Binary files differ
diff --git a/luni/src/test/resources/dalvik/system/loading-test2.jar b/luni/src/test/resources/dalvik/system/loading-test2.jar
new file mode 100644
index 0000000..4155a37
--- /dev/null
+++ b/luni/src/test/resources/dalvik/system/loading-test2.jar
Binary files differ
diff --git a/luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt b/luni/src/test/resources/libcore/java/lang/HelloWorld.txt
index 349db2b..349db2b 100644
--- a/luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld.txt
+++ b/luni/src/test/resources/libcore/java/lang/HelloWorld.txt
diff --git a/luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld1.txt b/luni/src/test/resources/libcore/java/lang/HelloWorld1.txt
index 349db2b..349db2b 100644
--- a/luni/src/test/resources/org/apache/harmony/luni/tests/java/lang/HelloWorld1.txt
+++ b/luni/src/test/resources/libcore/java/lang/HelloWorld1.txt
diff --git a/luni/src/test/resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar b/luni/src/test/resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar
new file mode 100644
index 0000000..3b3029a
--- /dev/null
+++ b/luni/src/test/resources/org/apache/harmony/luni/tests/ObjectStreamClassTest.jar
Binary files differ
diff --git a/luni/src/test/resources/tests/api/java/net/file1.cache b/luni/src/test/resources/tests/api/java/net/file1.cache
deleted file mode 100644
index 9245960..0000000
--- a/luni/src/test/resources/tests/api/java/net/file1.cache
+++ /dev/null
@@ -1 +0,0 @@
-Cache test \ No newline at end of file